aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/Makefile2
-rw-r--r--drivers/acorn/char/pcf8583.c80
-rw-r--r--drivers/acpi/acpi_memhotplug.c5
-rw-r--r--drivers/acpi/processor_idle.c1
-rw-r--r--drivers/acpi/sleep/main.c8
-rw-r--r--drivers/base/Makefile1
-rw-r--r--drivers/base/attribute_container.c2
-rw-r--r--drivers/base/base.h12
-rw-r--r--drivers/base/class.c151
-rw-r--r--drivers/base/core.c21
-rw-r--r--drivers/base/cpu.c17
-rw-r--r--drivers/base/driver.c3
-rw-r--r--drivers/base/firmware.c3
-rw-r--r--drivers/base/firmware_class.c69
-rw-r--r--drivers/base/init.c12
-rw-r--r--drivers/base/memory.c452
-rw-r--r--drivers/base/platform.c23
-rw-r--r--drivers/base/power/main.c26
-rw-r--r--drivers/base/power/power.h13
-rw-r--r--drivers/base/power/runtime.c1
-rw-r--r--drivers/base/power/sysfs.c73
-rw-r--r--drivers/base/sys.c1
-rw-r--r--drivers/block/Kconfig.iosched28
-rw-r--r--drivers/block/aoe/aoe.h2
-rw-r--r--drivers/block/aoe/aoechr.c2
-rw-r--r--drivers/block/aoe/aoecmd.c15
-rw-r--r--drivers/block/as-iosched.c330
-rw-r--r--drivers/block/cciss_scsi.c10
-rw-r--r--drivers/block/cfq-iosched.c394
-rw-r--r--drivers/block/deadline-iosched.c125
-rw-r--r--drivers/block/elevator.c391
-rw-r--r--drivers/block/genhd.c25
-rw-r--r--drivers/block/ll_rw_blk.c193
-rw-r--r--drivers/block/loop.c2
-rw-r--r--drivers/block/noop-iosched.c48
-rw-r--r--drivers/block/paride/paride.c1
-rw-r--r--drivers/block/paride/pf.c4
-rw-r--r--drivers/block/paride/pg.c4
-rw-r--r--drivers/block/paride/pt.c5
-rw-r--r--drivers/block/rd.c2
-rw-r--r--drivers/block/sx8.c51
-rw-r--r--drivers/block/ub.c4
-rw-r--r--drivers/bluetooth/Kconfig8
-rw-r--r--drivers/bluetooth/bpa10x.c3
-rw-r--r--drivers/bluetooth/hci_bcsp.c160
-rw-r--r--drivers/bluetooth/hci_bcsp.h70
-rw-r--r--drivers/bluetooth/hci_h4.c101
-rw-r--r--drivers/bluetooth/hci_h4.h44
-rw-r--r--drivers/bluetooth/hci_ldisc.c134
-rw-r--r--drivers/bluetooth/hci_uart.h84
-rw-r--r--drivers/char/Kconfig16
-rw-r--r--drivers/char/Makefile1
-rw-r--r--drivers/char/agp/Kconfig16
-rw-r--r--drivers/char/agp/ali-agp.c1
-rw-r--r--drivers/char/agp/amd64-agp.c1
-rw-r--r--drivers/char/agp/ati-agp.c2
-rw-r--r--drivers/char/agp/i460-agp.c2
-rw-r--r--drivers/char/agp/isoch.c1
-rw-r--r--drivers/char/agp/sgi-agp.c1
-rw-r--r--drivers/char/agp/sworks-agp.c2
-rw-r--r--drivers/char/cyclades.c2
-rw-r--r--drivers/char/drm/drm_sysfs.c2
-rw-r--r--drivers/char/dsp56k.c2
-rw-r--r--drivers/char/epca.c1
-rw-r--r--drivers/char/ftape/zftape/zftape-init.c12
-rw-r--r--drivers/char/hangcheck-timer.c2
-rw-r--r--drivers/char/hpet.c168
-rw-r--r--drivers/char/ip2main.c10
-rw-r--r--drivers/char/ipmi/ipmi_devintf.c2
-rw-r--r--drivers/char/istallion.c3
-rw-r--r--drivers/char/lcd.c4
-rw-r--r--drivers/char/lcd.h2
-rw-r--r--drivers/char/lp.c2
-rw-r--r--drivers/char/mem.c3
-rw-r--r--drivers/char/misc.c2
-rw-r--r--drivers/char/mmtimer.c4
-rw-r--r--drivers/char/mwave/3780i.c2
-rw-r--r--drivers/char/n_tty.c2
-rw-r--r--drivers/char/nvram.c110
-rw-r--r--drivers/char/ppdev.c2
-rw-r--r--drivers/char/qtronix.c5
-rw-r--r--drivers/char/raw.c4
-rw-r--r--drivers/char/rocket.c10
-rw-r--r--drivers/char/s3c2410-rtc.c20
-rw-r--r--drivers/char/ser_a2232.c2
-rw-r--r--drivers/char/snsc.c6
-rw-r--r--drivers/char/sonypi.c106
-rw-r--r--drivers/char/specialix.c342
-rw-r--r--drivers/char/stallion.c4
-rw-r--r--drivers/char/synclink.c1
-rw-r--r--drivers/char/synclinkmp.c1
-rw-r--r--drivers/char/tipar.c2
-rw-r--r--drivers/char/tlclk.c896
-rw-r--r--drivers/char/tpm/tpm.c104
-rw-r--r--drivers/char/tpm/tpm.h11
-rw-r--r--drivers/char/tpm/tpm_atmel.c146
-rw-r--r--drivers/char/tpm/tpm_infineon.c179
-rw-r--r--drivers/char/tpm/tpm_nsc.c164
-rw-r--r--drivers/char/tty_io.c12
-rw-r--r--drivers/char/vc_screen.c10
-rw-r--r--drivers/char/viotape.c4
-rw-r--r--drivers/char/vt_ioctl.c3
-rw-r--r--drivers/char/watchdog/cpu5wdt.c1
-rw-r--r--drivers/char/watchdog/mixcomwd.c2
-rw-r--r--drivers/char/watchdog/pcwd.c2
-rw-r--r--drivers/char/watchdog/pcwd_pci.c1
-rw-r--r--drivers/char/watchdog/s3c2410_wdt.c30
-rw-r--r--drivers/char/watchdog/sc520_wdt.c1
-rw-r--r--drivers/char/watchdog/softdog.c2
-rw-r--r--drivers/char/watchdog/wdt_pci.c1
-rw-r--r--drivers/cpufreq/cpufreq.c85
-rw-r--r--drivers/cpufreq/cpufreq_stats.c42
-rw-r--r--drivers/crypto/Kconfig2
-rw-r--r--drivers/firmware/Kconfig3
-rw-r--r--drivers/hwmon/adm1021.c5
-rw-r--r--drivers/hwmon/adm1025.c3
-rw-r--r--drivers/hwmon/adm1026.c22
-rw-r--r--drivers/hwmon/adm1031.c3
-rw-r--r--drivers/hwmon/adm9240.c429
-rw-r--r--drivers/hwmon/asb100.c11
-rw-r--r--drivers/hwmon/atxp1.c5
-rw-r--r--drivers/hwmon/ds1621.c9
-rw-r--r--drivers/hwmon/fscher.c3
-rw-r--r--drivers/hwmon/fscpos.c5
-rw-r--r--drivers/hwmon/gl518sm.c3
-rw-r--r--drivers/hwmon/gl520sm.c3
-rw-r--r--drivers/hwmon/hdaps.c6
-rw-r--r--drivers/hwmon/hwmon.c2
-rw-r--r--drivers/hwmon/it87.c56
-rw-r--r--drivers/hwmon/lm63.c3
-rw-r--r--drivers/hwmon/lm75.c3
-rw-r--r--drivers/hwmon/lm77.c3
-rw-r--r--drivers/hwmon/lm78.c6
-rw-r--r--drivers/hwmon/lm80.c5
-rw-r--r--drivers/hwmon/lm83.c3
-rw-r--r--drivers/hwmon/lm85.c15
-rw-r--r--drivers/hwmon/lm87.c3
-rw-r--r--drivers/hwmon/lm90.c181
-rw-r--r--drivers/hwmon/lm92.c3
-rw-r--r--drivers/hwmon/max1619.c3
-rw-r--r--drivers/hwmon/pc87360.c3
-rw-r--r--drivers/hwmon/sis5595.c3
-rw-r--r--drivers/hwmon/smsc47b397.c10
-rw-r--r--drivers/hwmon/smsc47m1.c10
-rw-r--r--drivers/hwmon/via686a.c28
-rw-r--r--drivers/hwmon/w83627ehf.c16
-rw-r--r--drivers/hwmon/w83627hf.c32
-rw-r--r--drivers/hwmon/w83781d.c11
-rw-r--r--drivers/hwmon/w83792d.c7
-rw-r--r--drivers/hwmon/w83l785ts.c42
-rw-r--r--drivers/i2c/algos/i2c-algo-pca.c2
-rw-r--r--drivers/i2c/algos/i2c-algo-sibyte.c2
-rw-r--r--drivers/i2c/busses/Kconfig3
-rw-r--r--drivers/i2c/busses/i2c-ali1535.c7
-rw-r--r--drivers/i2c/busses/i2c-ali1563.c7
-rw-r--r--drivers/i2c/busses/i2c-ali15x3.c10
-rw-r--r--drivers/i2c/busses/i2c-amd756-s4882.c4
-rw-r--r--drivers/i2c/busses/i2c-amd756.c8
-rw-r--r--drivers/i2c/busses/i2c-amd8111.c16
-rw-r--r--drivers/i2c/busses/i2c-elektor.c138
-rw-r--r--drivers/i2c/busses/i2c-hydra.c1
-rw-r--r--drivers/i2c/busses/i2c-i801.c61
-rw-r--r--drivers/i2c/busses/i2c-i810.c2
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.c3
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.c9
-rw-r--r--drivers/i2c/busses/i2c-isa.c1
-rw-r--r--drivers/i2c/busses/i2c-ixp2000.c8
-rw-r--r--drivers/i2c/busses/i2c-ixp4xx.c8
-rw-r--r--drivers/i2c/busses/i2c-keywest.c5
-rw-r--r--drivers/i2c/busses/i2c-mpc.c4
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c6
-rw-r--r--drivers/i2c/busses/i2c-nforce2.c16
-rw-r--r--drivers/i2c/busses/i2c-parport.c11
-rw-r--r--drivers/i2c/busses/i2c-piix4.c13
-rw-r--r--drivers/i2c/busses/i2c-pmac-smu.c3
-rw-r--r--drivers/i2c/busses/i2c-prosavage.c10
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c10
-rw-r--r--drivers/i2c/busses/i2c-savage4.c1
-rw-r--r--drivers/i2c/busses/i2c-sis5595.c10
-rw-r--r--drivers/i2c/busses/i2c-sis630.c9
-rw-r--r--drivers/i2c/busses/i2c-sis96x.c8
-rw-r--r--drivers/i2c/busses/i2c-via.c7
-rw-r--r--drivers/i2c/busses/i2c-viapro.c271
-rw-r--r--drivers/i2c/busses/i2c-voodoo3.c1
-rw-r--r--drivers/i2c/busses/scx200_acb.c3
-rw-r--r--drivers/i2c/chips/Kconfig9
-rw-r--r--drivers/i2c/chips/Makefile1
-rw-r--r--drivers/i2c/chips/ds1337.c3
-rw-r--r--drivers/i2c/chips/ds1374.c7
-rw-r--r--drivers/i2c/chips/eeprom.c9
-rw-r--r--drivers/i2c/chips/isp1301_omap.c1
-rw-r--r--drivers/i2c/chips/m41t00.c4
-rw-r--r--drivers/i2c/chips/max6875.c6
-rw-r--r--drivers/i2c/chips/pca9539.c3
-rw-r--r--drivers/i2c/chips/pcf8574.c5
-rw-r--r--drivers/i2c/chips/pcf8591.c5
-rw-r--r--drivers/i2c/chips/rtc8564.c5
-rw-r--r--drivers/i2c/chips/tps65010.c3
-rw-r--r--drivers/i2c/chips/x1205.c698
-rw-r--r--drivers/i2c/i2c-core.c198
-rw-r--r--drivers/i2c/i2c-dev.c17
-rw-r--r--drivers/ide/Kconfig31
-rw-r--r--drivers/ide/ide-cd.c56
-rw-r--r--drivers/ide/ide-proc.c1
-rw-r--r--drivers/ide/ide-tape.c38
-rw-r--r--drivers/ide/mips/au1xxx-ide.c1250
-rw-r--r--drivers/ieee1394/dv1394.c2
-rw-r--r--drivers/ieee1394/eth1394.c2
-rw-r--r--drivers/ieee1394/nodemgr.c4
-rw-r--r--drivers/ieee1394/raw1394.c2
-rw-r--r--drivers/ieee1394/video1394.c2
-rw-r--r--drivers/infiniband/core/agent.c293
-rw-r--r--drivers/infiniband/core/agent.h14
-rw-r--r--drivers/infiniband/core/agent_priv.h62
-rw-r--r--drivers/infiniband/core/cache.c1
-rw-r--r--drivers/infiniband/core/cm.c217
-rw-r--r--drivers/infiniband/core/cm_msgs.h1
-rw-r--r--drivers/infiniband/core/device.c12
-rw-r--r--drivers/infiniband/core/mad.c335
-rw-r--r--drivers/infiniband/core/mad_priv.h8
-rw-r--r--drivers/infiniband/core/mad_rmpp.c114
-rw-r--r--drivers/infiniband/core/mad_rmpp.h2
-rw-r--r--drivers/infiniband/core/sa_query.c271
-rw-r--r--drivers/infiniband/core/smi.h2
-rw-r--r--drivers/infiniband/core/sysfs.c16
-rw-r--r--drivers/infiniband/core/ucm.c267
-rw-r--r--drivers/infiniband/core/ucm.h83
-rw-r--r--drivers/infiniband/core/user_mad.c399
-rw-r--r--drivers/infiniband/core/uverbs.h62
-rw-r--r--drivers/infiniband/core/uverbs_cmd.c858
-rw-r--r--drivers/infiniband/core/uverbs_main.c503
-rw-r--r--drivers/infiniband/core/verbs.c18
-rw-r--r--drivers/infiniband/hw/mthca/Makefile3
-rw-r--r--drivers/infiniband/hw/mthca/mthca_av.c2
-rw-r--r--drivers/infiniband/hw/mthca/mthca_catas.c153
-rw-r--r--drivers/infiniband/hw/mthca/mthca_cmd.c13
-rw-r--r--drivers/infiniband/hw/mthca/mthca_cmd.h2
-rw-r--r--drivers/infiniband/hw/mthca/mthca_dev.h22
-rw-r--r--drivers/infiniband/hw/mthca/mthca_eq.c21
-rw-r--r--drivers/infiniband/hw/mthca/mthca_mad.c75
-rw-r--r--drivers/infiniband/hw/mthca/mthca_main.c11
-rw-r--r--drivers/infiniband/hw/mthca/mthca_mcg.c13
-rw-r--r--drivers/infiniband/hw/mthca/mthca_memfree.c5
-rw-r--r--drivers/infiniband/hw/mthca/mthca_memfree.h5
-rw-r--r--drivers/infiniband/hw/mthca/mthca_profile.c2
-rw-r--r--drivers/infiniband/hw/mthca/mthca_provider.c49
-rw-r--r--drivers/infiniband/hw/mthca/mthca_qp.c18
-rw-r--r--drivers/infiniband/hw/mthca/mthca_reset.c1
-rw-r--r--drivers/infiniband/hw/mthca/mthca_srq.c43
-rw-r--r--drivers/infiniband/hw/mthca/mthca_uar.c2
-rw-r--r--drivers/infiniband/hw/mthca/mthca_user.h6
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib.h23
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_ib.c120
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_main.c15
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_verbs.c9
-rw-r--r--drivers/input/evdev.c16
-rw-r--r--drivers/input/gameport/gameport.c1
-rw-r--r--drivers/input/input.c445
-rw-r--r--drivers/input/joydev.c16
-rw-r--r--drivers/input/joystick/a3d.c1
-rw-r--r--drivers/input/joystick/adi.c94
-rw-r--r--drivers/input/joystick/amijoy.c85
-rw-r--r--drivers/input/joystick/analog.c97
-rw-r--r--drivers/input/joystick/cobra.c67
-rw-r--r--drivers/input/joystick/db9.c292
-rw-r--r--drivers/input/joystick/gamecon.c396
-rw-r--r--drivers/input/joystick/gf2k.c70
-rw-r--r--drivers/input/joystick/grip.c78
-rw-r--r--drivers/input/joystick/grip_mp.c150
-rw-r--r--drivers/input/joystick/guillemot.c52
-rw-r--r--drivers/input/joystick/iforce/iforce-main.c106
-rw-r--r--drivers/input/joystick/iforce/iforce-packets.c5
-rw-r--r--drivers/input/joystick/iforce/iforce-serio.c10
-rw-r--r--drivers/input/joystick/iforce/iforce-usb.c22
-rw-r--r--drivers/input/joystick/iforce/iforce.h2
-rw-r--r--drivers/input/joystick/interact.c54
-rw-r--r--drivers/input/joystick/joydump.c1
-rw-r--r--drivers/input/joystick/magellan.c71
-rw-r--r--drivers/input/joystick/sidewinder.c71
-rw-r--r--drivers/input/joystick/spaceball.c82
-rw-r--r--drivers/input/joystick/spaceorb.c78
-rw-r--r--drivers/input/joystick/stinger.c75
-rw-r--r--drivers/input/joystick/tmdc.c325
-rw-r--r--drivers/input/joystick/turbografx.c215
-rw-r--r--drivers/input/joystick/twidjoy.c120
-rw-r--r--drivers/input/joystick/warrior.c83
-rw-r--r--drivers/input/keyboard/amikbd.c59
-rw-r--r--drivers/input/keyboard/atkbd.c188
-rw-r--r--drivers/input/keyboard/corgikbd.c96
-rw-r--r--drivers/input/keyboard/hil_kbd.c28
-rw-r--r--drivers/input/keyboard/hilkbd.c8
-rw-r--r--drivers/input/keyboard/lkkbd.c128
-rw-r--r--drivers/input/keyboard/maple_keyb.c72
-rw-r--r--drivers/input/keyboard/newtonkbd.c83
-rw-r--r--drivers/input/keyboard/spitzkbd.c119
-rw-r--r--drivers/input/keyboard/sunkbd.c117
-rw-r--r--drivers/input/keyboard/xtkbd.c80
-rw-r--r--drivers/input/misc/Kconfig2
-rw-r--r--drivers/input/misc/m68kspkr.c36
-rw-r--r--drivers/input/misc/pcspkr.c30
-rw-r--r--drivers/input/misc/sparcspkr.c49
-rw-r--r--drivers/input/mouse/alps.c63
-rw-r--r--drivers/input/mouse/alps.h2
-rw-r--r--drivers/input/mouse/amimouse.c49
-rw-r--r--drivers/input/mouse/hil_ptr.c33
-rw-r--r--drivers/input/mouse/inport.c96
-rw-r--r--drivers/input/mouse/lifebook.c16
-rw-r--r--drivers/input/mouse/logibm.c88
-rw-r--r--drivers/input/mouse/logips2pp.c20
-rw-r--r--drivers/input/mouse/maplemouse.c10
-rw-r--r--drivers/input/mouse/pc110pad.c64
-rw-r--r--drivers/input/mouse/psmouse-base.c99
-rw-r--r--drivers/input/mouse/psmouse.h2
-rw-r--r--drivers/input/mouse/rpcmouse.c43
-rw-r--r--drivers/input/mouse/sermouse.c82
-rw-r--r--drivers/input/mouse/synaptics.c6
-rw-r--r--drivers/input/mouse/vsxxxaa.c84
-rw-r--r--drivers/input/mousedev.c25
-rw-r--r--drivers/input/serio/gscps2.c17
-rw-r--r--drivers/input/serio/hil_mlc.c14
-rw-r--r--drivers/input/serio/hp_sdc.c8
-rw-r--r--drivers/input/serio/hp_sdc_mlc.c1
-rw-r--r--drivers/input/serio/i8042.c13
-rw-r--r--drivers/input/touchscreen/corgi_ts.c127
-rw-r--r--drivers/input/touchscreen/elo.c89
-rw-r--r--drivers/input/touchscreen/gunze.c66
-rw-r--r--drivers/input/touchscreen/h3600_ts_input.c149
-rw-r--r--drivers/input/touchscreen/hp680_ts_input.c50
-rw-r--r--drivers/input/touchscreen/mk712.c80
-rw-r--r--drivers/input/touchscreen/mtouch.c64
-rw-r--r--drivers/input/tsdev.c19
-rw-r--r--drivers/isdn/capi/capi.c2
-rw-r--r--drivers/isdn/capi/capifs.c1
-rw-r--r--drivers/isdn/hisax/hfc4s8s_l1.c10
-rw-r--r--drivers/macintosh/adb.c2
-rw-r--r--drivers/macintosh/adbhid.c222
-rw-r--r--drivers/macintosh/mac_hid.c40
-rw-r--r--drivers/macintosh/macio_asic.c2
-rw-r--r--drivers/mca/mca-device.c1
-rw-r--r--drivers/md/bitmap.c2
-rw-r--r--drivers/md/dm-crypt.c14
-rw-r--r--drivers/media/common/ir-common.c2
-rw-r--r--drivers/media/dvb/cinergyT2/cinergyT2.c108
-rw-r--r--drivers/media/dvb/dvb-core/dvb_ca_en50221.c1
-rw-r--r--drivers/media/dvb/dvb-core/dvbdev.c2
-rw-r--r--drivers/media/dvb/dvb-usb/dtt200u.c4
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-remote.c50
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb.h3
-rw-r--r--drivers/media/dvb/dvb-usb/vp7045.c2
-rw-r--r--drivers/media/dvb/frontends/bcm3510.c3
-rw-r--r--drivers/media/dvb/frontends/dib3000mb.c2
-rw-r--r--drivers/media/dvb/frontends/dib3000mc.c2
-rw-r--r--drivers/media/dvb/frontends/dvb_dummy_fe.c2
-rw-r--r--drivers/media/dvb/frontends/lgdt330x.c2
-rw-r--r--drivers/media/dvb/frontends/mt312.c2
-rw-r--r--drivers/media/dvb/frontends/mt352.c2
-rw-r--r--drivers/media/dvb/frontends/nxt2002.c2
-rw-r--r--drivers/media/dvb/frontends/or51132.c2
-rw-r--r--drivers/media/dvb/frontends/or51211.c2
-rw-r--r--drivers/media/dvb/frontends/s5h1420.c2
-rw-r--r--drivers/media/dvb/frontends/sp8870.c2
-rw-r--r--drivers/media/dvb/frontends/sp887x.c2
-rw-r--r--drivers/media/dvb/frontends/stv0297.c2
-rw-r--r--drivers/media/dvb/frontends/stv0299.c1
-rw-r--r--drivers/media/dvb/frontends/tda1004x.c4
-rw-r--r--drivers/media/dvb/frontends/tda8083.c1
-rw-r--r--drivers/media/dvb/ttpci/av7110_ir.c37
-rw-r--r--drivers/media/dvb/ttpci/budget-ci.c24
-rw-r--r--drivers/media/dvb/ttusb-dec/ttusb_dec.c51
-rw-r--r--drivers/media/radio/miropcm20-rds.c1
-rw-r--r--drivers/media/video/bttvp.h2
-rw-r--r--drivers/media/video/cx88/cx88-input.c58
-rw-r--r--drivers/media/video/indycam.c10
-rw-r--r--drivers/media/video/ir-kbd-gpio.c52
-rw-r--r--drivers/media/video/ir-kbd-i2c.c33
-rw-r--r--drivers/media/video/msp3400.c8
-rw-r--r--drivers/media/video/saa7134/saa7134-input.c39
-rw-r--r--drivers/media/video/saa7134/saa7134.h2
-rw-r--r--drivers/media/video/saa7191.c14
-rw-r--r--drivers/media/video/tda9887.c4
-rw-r--r--drivers/media/video/tuner-core.c4
-rw-r--r--drivers/media/video/vino.c7
-rw-r--r--drivers/message/i2o/core.h3
-rw-r--r--drivers/message/i2o/debug.c2
-rw-r--r--drivers/message/i2o/device.c274
-rw-r--r--drivers/message/i2o/driver.c6
-rw-r--r--drivers/message/i2o/exec-osm.c4
-rw-r--r--drivers/message/i2o/iop.c33
-rw-r--r--drivers/mfd/mcp-sa11x0.c20
-rw-r--r--drivers/mfd/ucb1x00-ts.c117
-rw-r--r--drivers/mmc/Kconfig9
-rw-r--r--drivers/mmc/Makefile1
-rw-r--r--drivers/mmc/au1xmmc.c1026
-rw-r--r--drivers/mmc/au1xmmc.h96
-rw-r--r--drivers/mmc/mmc_block.c10
-rw-r--r--drivers/mmc/mmci.c1
-rw-r--r--drivers/mmc/pxamci.c9
-rw-r--r--drivers/mmc/wbsd.c123
-rw-r--r--drivers/mtd/chips/jedec.c1
-rw-r--r--drivers/mtd/devices/lart.c1
-rw-r--r--drivers/mtd/devices/phram.c1
-rw-r--r--drivers/mtd/maps/bast-flash.c1
-rw-r--r--drivers/mtd/maps/ceiva.c1
-rw-r--r--drivers/mtd/maps/dc21285.c1
-rw-r--r--drivers/mtd/maps/dilnetpc.c5
-rw-r--r--drivers/mtd/maps/epxa10db-flash.c5
-rw-r--r--drivers/mtd/maps/fortunet.c5
-rw-r--r--drivers/mtd/maps/ixp2000.c6
-rw-r--r--drivers/mtd/maps/ixp4xx.c7
-rw-r--r--drivers/mtd/maps/lubbock-flash.c3
-rw-r--r--drivers/mtd/maps/mainstone-flash.c3
-rw-r--r--drivers/mtd/maps/omap-toto-flash.c2
-rw-r--r--drivers/mtd/maps/omap_nor.c2
-rw-r--r--drivers/mtd/maps/pci.c1
-rw-r--r--drivers/mtd/maps/plat-ram.c1
-rw-r--r--drivers/mtd/maps/sa1100-flash.c75
-rw-r--r--drivers/mtd/maps/tqm8xxl.c4
-rw-r--r--drivers/mtd/mtdblock.c1
-rw-r--r--drivers/mtd/mtdchar.c5
-rw-r--r--drivers/mtd/mtdconcat.c2
-rw-r--r--drivers/mtd/nand/s3c2410.c1
-rw-r--r--drivers/net/8139cp.c5
-rw-r--r--drivers/net/8139too.c5
-rw-r--r--drivers/net/Kconfig102
-rw-r--r--drivers/net/Makefile7
-rw-r--r--drivers/net/acenic.c6
-rw-r--r--[-rwxr-xr-x]drivers/net/amd8111e.c0
-rw-r--r--[-rwxr-xr-x]drivers/net/amd8111e.h0
-rw-r--r--drivers/net/arm/am79c961a.c1
-rw-r--r--drivers/net/au1000_eth.c19
-rw-r--r--drivers/net/b44.c164
-rw-r--r--drivers/net/b44.h2
-rw-r--r--drivers/net/bmac.c6
-rw-r--r--drivers/net/bnx2.c12
-rw-r--r--drivers/net/bonding/bond_main.c57
-rw-r--r--drivers/net/cassini.c4
-rw-r--r--drivers/net/cs89x0.c14
-rw-r--r--drivers/net/cs89x0.h2
-rw-r--r--drivers/net/declance.c37
-rw-r--r--drivers/net/dm9000.c8
-rw-r--r--drivers/net/e100.c4
-rw-r--r--drivers/net/e1000/e1000.h74
-rw-r--r--drivers/net/e1000/e1000_ethtool.c102
-rw-r--r--drivers/net/e1000/e1000_hw.c220
-rw-r--r--drivers/net/e1000/e1000_hw.h96
-rw-r--r--drivers/net/e1000/e1000_main.c1087
-rw-r--r--drivers/net/e1000/e1000_param.c10
-rw-r--r--drivers/net/eepro.c57
-rw-r--r--drivers/net/epic100.c4
-rw-r--r--drivers/net/forcedeth.c310
-rw-r--r--drivers/net/fs_enet/Kconfig20
-rw-r--r--drivers/net/fs_enet/Makefile10
-rw-r--r--drivers/net/fs_enet/fs_enet-main.c1226
-rw-r--r--drivers/net/fs_enet/fs_enet-mii.c507
-rw-r--r--drivers/net/fs_enet/fs_enet.h245
-rw-r--r--drivers/net/fs_enet/mac-fcc.c578
-rw-r--r--drivers/net/fs_enet/mac-fec.c653
-rw-r--r--drivers/net/fs_enet/mac-scc.c524
-rw-r--r--drivers/net/fs_enet/mii-bitbang.c405
-rw-r--r--drivers/net/fs_enet/mii-fixed.c92
-rw-r--r--drivers/net/gianfar.c412
-rw-r--r--drivers/net/gianfar.h30
-rw-r--r--drivers/net/gianfar_ethtool.c100
-rw-r--r--drivers/net/gianfar_mii.c219
-rw-r--r--drivers/net/gianfar_mii.h45
-rw-r--r--drivers/net/gianfar_phy.c661
-rw-r--r--drivers/net/gianfar_phy.h213
-rw-r--r--drivers/net/hamradio/Kconfig1
-rw-r--r--drivers/net/hamradio/bpqether.c9
-rw-r--r--drivers/net/hamradio/mkiss.c188
-rw-r--r--drivers/net/hamradio/mkiss.h62
-rw-r--r--drivers/net/hp100.c48
-rw-r--r--drivers/net/ibm_emac/Makefile13
-rw-r--r--drivers/net/ibm_emac/ibm_emac.h408
-rw-r--r--drivers/net/ibm_emac/ibm_emac_core.c3396
-rw-r--r--drivers/net/ibm_emac/ibm_emac_core.h313
-rw-r--r--drivers/net/ibm_emac/ibm_emac_debug.c363
-rw-r--r--drivers/net/ibm_emac/ibm_emac_debug.h63
-rw-r--r--drivers/net/ibm_emac/ibm_emac_mal.c674
-rw-r--r--drivers/net/ibm_emac/ibm_emac_mal.h332
-rw-r--r--drivers/net/ibm_emac/ibm_emac_phy.c335
-rw-r--r--drivers/net/ibm_emac/ibm_emac_phy.h105
-rw-r--r--drivers/net/ibm_emac/ibm_emac_rgmii.c201
-rw-r--r--drivers/net/ibm_emac/ibm_emac_rgmii.h60
-rw-r--r--drivers/net/ibm_emac/ibm_emac_tah.c111
-rw-r--r--drivers/net/ibm_emac/ibm_emac_tah.h96
-rw-r--r--drivers/net/ibm_emac/ibm_emac_zmii.c255
-rw-r--r--drivers/net/ibm_emac/ibm_emac_zmii.h104
-rw-r--r--drivers/net/ibmveth.c186
-rw-r--r--drivers/net/ibmveth.h23
-rw-r--r--drivers/net/irda/Kconfig10
-rw-r--r--drivers/net/irda/Makefile1
-rw-r--r--drivers/net/irda/donauboe.c6
-rw-r--r--drivers/net/irda/irda-usb.c6
-rw-r--r--drivers/net/irda/irport.c3
-rw-r--r--drivers/net/irda/pxaficp_ir.c865
-rw-r--r--drivers/net/irda/sa1100_ir.c8
-rw-r--r--drivers/net/irda/sir_dev.c3
-rw-r--r--drivers/net/irda/smsc-ircc2.c139
-rw-r--r--drivers/net/irda/stir4200.c7
-rw-r--r--drivers/net/irda/vlsi_ir.c3
-rw-r--r--drivers/net/ixgb/ixgb_ethtool.c8
-rw-r--r--drivers/net/ixgb/ixgb_main.c3
-rw-r--r--drivers/net/lance.c4
-rw-r--r--drivers/net/lasi_82596.c30
-rw-r--r--drivers/net/lne390.c2
-rw-r--r--drivers/net/mace.c6
-rw-r--r--drivers/net/mii.c15
-rw-r--r--drivers/net/mipsnet.c371
-rw-r--r--drivers/net/mipsnet.h127
-rw-r--r--drivers/net/myri_sbus.c2
-rw-r--r--drivers/net/myri_sbus.h2
-rw-r--r--drivers/net/ne.c15
-rw-r--r--drivers/net/ne2k-pci.c3
-rw-r--r--drivers/net/ni65.c9
-rw-r--r--drivers/net/ns83820.c3
-rw-r--r--drivers/net/pcmcia/pcnet_cs.c6
-rw-r--r--drivers/net/pcnet32.c278
-rw-r--r--drivers/net/phy/Kconfig8
-rw-r--r--drivers/net/phy/mdio_bus.c20
-rw-r--r--drivers/net/phy/phy.c8
-rw-r--r--drivers/net/phy/phy_device.c3
-rw-r--r--drivers/net/ppp_generic.c2
-rw-r--r--drivers/net/r8169.c2
-rw-r--r--drivers/net/rionet.c574
-rw-r--r--drivers/net/rrunner.c6
-rw-r--r--drivers/net/s2io-regs.h11
-rw-r--r--drivers/net/s2io.c794
-rw-r--r--drivers/net/s2io.h50
-rw-r--r--drivers/net/saa9730.c8
-rw-r--r--drivers/net/sb1250-mac.c1384
-rw-r--r--drivers/net/sgiseeq.c37
-rw-r--r--drivers/net/sis190.c2
-rw-r--r--drivers/net/sis900.c16
-rw-r--r--drivers/net/skfp/smt.c2
-rw-r--r--drivers/net/skge.c2
-rw-r--r--drivers/net/smc91x.c12
-rw-r--r--drivers/net/smc91x.h12
-rw-r--r--drivers/net/starfire.c4
-rw-r--r--drivers/net/sunbmac.c3
-rw-r--r--drivers/net/sunbmac.h2
-rw-r--r--drivers/net/sundance.c111
-rw-r--r--drivers/net/tg3.c91
-rw-r--r--drivers/net/tg3.h12
-rw-r--r--drivers/net/tokenring/ibmtr.c9
-rw-r--r--drivers/net/tokenring/olympic.c2
-rw-r--r--drivers/net/tokenring/tms380tr.c3
-rw-r--r--drivers/net/tulip/de2104x.c11
-rw-r--r--drivers/net/tulip/tulip_core.c6
-rw-r--r--drivers/net/typhoon.c7
-rw-r--r--drivers/net/via-rhine.c38
-rw-r--r--drivers/net/via-velocity.c6
-rw-r--r--drivers/net/wan/cosa.c8
-rw-r--r--drivers/net/wan/cycx_drv.c7
-rw-r--r--drivers/net/wan/cycx_main.c2
-rw-r--r--drivers/net/wan/cycx_x25.c5
-rw-r--r--drivers/net/wan/dscc4.c23
-rw-r--r--drivers/net/wan/farsync.c27
-rw-r--r--drivers/net/wan/hdlc_fr.c2
-rw-r--r--drivers/net/wan/lmc/lmc_debug.c10
-rw-r--r--drivers/net/wan/lmc/lmc_media.c8
-rw-r--r--drivers/net/wan/pc300.h16
-rw-r--r--drivers/net/wan/pc300_drv.c87
-rw-r--r--drivers/net/wan/pc300_tty.c18
-rw-r--r--drivers/net/wan/sdla.c20
-rw-r--r--drivers/net/wan/sdla_fr.c4
-rw-r--r--drivers/net/wan/sdla_x25.c8
-rw-r--r--drivers/net/wan/sdladrv.c16
-rw-r--r--drivers/net/wan/syncppp.c10
-rw-r--r--drivers/net/wireless/airo.c92
-rw-r--r--drivers/net/wireless/airo_cs.c4
-rw-r--r--drivers/net/wireless/airport.c19
-rw-r--r--drivers/net/wireless/atmel.c30
-rw-r--r--drivers/net/wireless/atmel_cs.c3
-rw-r--r--drivers/net/wireless/hermes.c49
-rw-r--r--drivers/net/wireless/hermes.h113
-rw-r--r--drivers/net/wireless/hostap/hostap.c6
-rw-r--r--drivers/net/wireless/hostap/hostap_80211_rx.c43
-rw-r--r--drivers/net/wireless/hostap/hostap_80211_tx.c28
-rw-r--r--drivers/net/wireless/hostap/hostap_ap.c80
-rw-r--r--drivers/net/wireless/hostap/hostap_ap.h6
-rw-r--r--drivers/net/wireless/hostap/hostap_cs.c50
-rw-r--r--drivers/net/wireless/hostap/hostap_hw.c22
-rw-r--r--drivers/net/wireless/hostap/hostap_ioctl.c32
-rw-r--r--drivers/net/wireless/hostap/hostap_pci.c21
-rw-r--r--drivers/net/wireless/hostap/hostap_plx.c11
-rw-r--r--drivers/net/wireless/hostap/hostap_wlan.h2
-rw-r--r--drivers/net/wireless/ipw2100.c24
-rw-r--r--drivers/net/wireless/ipw2100.h2
-rw-r--r--drivers/net/wireless/ipw2200.c31
-rw-r--r--drivers/net/wireless/ipw2200.h4
-rw-r--r--drivers/net/wireless/netwave_cs.c185
-rw-r--r--drivers/net/wireless/orinoco.c248
-rw-r--r--drivers/net/wireless/orinoco.h16
-rw-r--r--drivers/net/wireless/orinoco_cs.c110
-rw-r--r--drivers/net/wireless/orinoco_nortel.c20
-rw-r--r--drivers/net/wireless/orinoco_pci.c18
-rw-r--r--drivers/net/wireless/orinoco_plx.c18
-rw-r--r--drivers/net/wireless/orinoco_tmd.c18
-rw-r--r--drivers/net/wireless/prism54/isl_ioctl.c10
-rw-r--r--drivers/net/wireless/prism54/islpci_dev.c13
-rw-r--r--drivers/net/wireless/prism54/islpci_dev.h2
-rw-r--r--drivers/net/wireless/prism54/islpci_eth.c13
-rw-r--r--drivers/net/wireless/prism54/islpci_mgt.c7
-rw-r--r--drivers/net/wireless/prism54/oid_mgt.c9
-rw-r--r--drivers/net/wireless/ray_cs.c46
-rw-r--r--drivers/net/wireless/spectrum_cs.c79
-rw-r--r--drivers/net/wireless/strip.c38
-rw-r--r--drivers/net/wireless/wavelan.c8
-rw-r--r--drivers/net/wireless/wavelan.p.h4
-rw-r--r--drivers/net/wireless/wavelan_cs.c8
-rw-r--r--drivers/net/wireless/wavelan_cs.p.h4
-rw-r--r--drivers/net/wireless/wl3501.h2
-rw-r--r--drivers/parisc/asp.c6
-rw-r--r--drivers/parisc/ccio-dma.c144
-rw-r--r--drivers/parisc/ccio-rm-dma.c2
-rw-r--r--drivers/parisc/dino.c42
-rw-r--r--drivers/parisc/eisa.c4
-rw-r--r--drivers/parisc/gsc.c11
-rw-r--r--drivers/parisc/hppb.c10
-rw-r--r--drivers/parisc/iosapic.c2
-rw-r--r--drivers/parisc/lasi.c4
-rw-r--r--drivers/parisc/lba_pci.c14
-rw-r--r--drivers/parisc/led.c225
-rw-r--r--drivers/parisc/pdc_stable.c2
-rw-r--r--drivers/parisc/sba_iommu.c166
-rw-r--r--drivers/parisc/superio.c3
-rw-r--r--drivers/parisc/wax.c2
-rw-r--r--drivers/parport/parport_gsc.c5
-rw-r--r--drivers/pci/access.c89
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c8
-rw-r--r--drivers/pci/hotplug/cpcihp_generic.c1
-rw-r--r--drivers/pci/hotplug/cpcihp_zt5550.c26
-rw-r--r--drivers/pci/hotplug/cpqphp_core.c24
-rw-r--r--drivers/pci/hotplug/fakephp.c2
-rw-r--r--drivers/pci/hotplug/ibmphp_core.c2
-rw-r--r--drivers/pci/hotplug/pciehp_pci.c2
-rw-r--r--drivers/pci/hotplug/pciehprm_nonacpi.c3
-rw-r--r--drivers/pci/hotplug/rpadlpar_core.c3
-rw-r--r--drivers/pci/hotplug/rpaphp.h3
-rw-r--r--drivers/pci/hotplug/rpaphp_core.c5
-rw-r--r--drivers/pci/hotplug/rpaphp_pci.c15
-rw-r--r--drivers/pci/hotplug/rpaphp_slot.c3
-rw-r--r--drivers/pci/hotplug/shpchp.h124
-rw-r--r--drivers/pci/hotplug/shpchp_core.c111
-rw-r--r--drivers/pci/hotplug/shpchp_ctrl.c2034
-rw-r--r--drivers/pci/hotplug/shpchp_hpc.c175
-rw-r--r--drivers/pci/hotplug/shpchp_pci.c861
-rw-r--r--drivers/pci/hotplug/shpchp_sysfs.c119
-rw-r--r--drivers/pci/hotplug/shpchprm.h55
-rw-r--r--drivers/pci/hotplug/shpchprm_acpi.c1649
-rw-r--r--drivers/pci/hotplug/shpchprm_legacy.c395
-rw-r--r--drivers/pci/hotplug/shpchprm_legacy.h113
-rw-r--r--drivers/pci/hotplug/shpchprm_nonacpi.c391
-rw-r--r--drivers/pci/hotplug/shpchprm_nonacpi.h56
-rw-r--r--drivers/pci/msi.c2
-rw-r--r--drivers/pci/pci-driver.c19
-rw-r--r--drivers/pci/pci-sysfs.c20
-rw-r--r--drivers/pci/pci.c22
-rw-r--r--drivers/pci/pci.h7
-rw-r--r--drivers/pci/pcie/portdrv_core.c6
-rw-r--r--drivers/pci/pcie/portdrv_pci.c1
-rw-r--r--drivers/pci/probe.c1
-rw-r--r--drivers/pci/proc.c28
-rw-r--r--drivers/pci/quirks.c294
-rw-r--r--drivers/pci/rom.c1
-rw-r--r--drivers/pci/syscall.c14
-rw-r--r--drivers/pcmcia/Makefile3
-rw-r--r--drivers/pcmcia/au1000_db1x00.c21
-rw-r--r--drivers/pcmcia/au1000_generic.c29
-rw-r--r--drivers/pcmcia/au1000_generic.h4
-rw-r--r--drivers/pcmcia/ds.c6
-rw-r--r--drivers/pcmcia/hd64465_ss.c20
-rw-r--r--drivers/pcmcia/i82365.c20
-rw-r--r--drivers/pcmcia/m32r_cfc.c21
-rw-r--r--drivers/pcmcia/m32r_pcc.c21
-rw-r--r--drivers/pcmcia/omap_cf.c18
-rw-r--r--drivers/pcmcia/pxa2xx_base.c26
-rw-r--r--drivers/pcmcia/pxa2xx_sharpsl.c31
-rw-r--r--drivers/pcmcia/rsrc_nonstatic.c8
-rw-r--r--drivers/pcmcia/sa1100_generic.c27
-rw-r--r--drivers/pcmcia/sa1111_generic.c2
-rw-r--r--drivers/pcmcia/socket_sysfs.c6
-rw-r--r--drivers/pcmcia/tcic.c20
-rw-r--r--drivers/pcmcia/vrc4171_card.c24
-rw-r--r--drivers/pcmcia/yenta_socket.c42
-rw-r--r--drivers/pnp/manager.c2
-rw-r--r--drivers/pnp/pnpbios/rsparser.c2
-rw-r--r--drivers/s390/char/con3270.c7
-rw-r--r--drivers/s390/char/fs3270.c234
-rw-r--r--drivers/s390/char/raw3270.c100
-rw-r--r--drivers/s390/char/raw3270.h7
-rw-r--r--drivers/s390/char/tape_class.c1
-rw-r--r--drivers/s390/char/tty3270.c27
-rw-r--r--drivers/s390/char/vmlogrdr.c1
-rw-r--r--drivers/s390/cio/cmf.c3
-rw-r--r--drivers/s390/cio/device.c20
-rw-r--r--drivers/s390/cio/device_fsm.c2
-rw-r--r--drivers/s390/net/fsm.c2
-rw-r--r--drivers/s390/net/fsm.h2
-rw-r--r--drivers/s390/net/qeth.h45
-rw-r--r--drivers/s390/net/qeth_fs.h12
-rw-r--r--drivers/s390/net/qeth_main.c419
-rw-r--r--drivers/s390/net/qeth_mpc.c6
-rw-r--r--drivers/s390/net/qeth_mpc.h15
-rw-r--r--drivers/s390/net/qeth_sys.c28
-rw-r--r--drivers/scsi/Kconfig22
-rw-r--r--drivers/scsi/Makefile2
-rw-r--r--drivers/scsi/ahci.c78
-rw-r--r--drivers/scsi/arm/scsi.h6
-rw-r--r--drivers/scsi/ata_piix.c19
-rw-r--r--drivers/scsi/ch.c2
-rw-r--r--drivers/scsi/dec_esp.c2
-rw-r--r--drivers/scsi/eata.c2
-rw-r--r--drivers/scsi/hosts.c3
-rw-r--r--drivers/scsi/ide-scsi.c38
-rw-r--r--drivers/scsi/ipr.c2
-rw-r--r--drivers/scsi/lasi700.c6
-rw-r--r--drivers/scsi/libata-core.c970
-rw-r--r--drivers/scsi/libata-scsi.c1506
-rw-r--r--drivers/scsi/libata.h22
-rw-r--r--drivers/scsi/lpfc/lpfc_mem.c2
-rw-r--r--drivers/scsi/megaraid/megaraid_mbox.c10
-rw-r--r--drivers/scsi/mesh.c2
-rw-r--r--drivers/scsi/osst.c8
-rw-r--r--drivers/scsi/pdc_adma.c741
-rw-r--r--drivers/scsi/qla2xxx/qla_gbl.h4
-rw-r--r--drivers/scsi/qla2xxx/qla_init.c2
-rw-r--r--drivers/scsi/qla2xxx/qla_rscn.c2
-rw-r--r--drivers/scsi/sata_mv.c1138
-rw-r--r--drivers/scsi/sata_nv.c11
-rw-r--r--drivers/scsi/sata_promise.c49
-rw-r--r--drivers/scsi/sata_qstor.c35
-rw-r--r--drivers/scsi/sata_sil.c13
-rw-r--r--drivers/scsi/sata_sil24.c871
-rw-r--r--drivers/scsi/sata_sis.c17
-rw-r--r--drivers/scsi/sata_svw.c29
-rw-r--r--drivers/scsi/sata_sx4.c42
-rw-r--r--drivers/scsi/sata_uli.c9
-rw-r--r--drivers/scsi/sata_via.c42
-rw-r--r--drivers/scsi/sata_vsc.c37
-rw-r--r--drivers/scsi/scsi.c8
-rw-r--r--drivers/scsi/scsi_ioctl.c3
-rw-r--r--drivers/scsi/scsi_lib.c2
-rw-r--r--drivers/scsi/scsi_transport_fc.c1
-rw-r--r--drivers/scsi/scsi_transport_iscsi.c3
-rw-r--r--drivers/scsi/sg.c29
-rw-r--r--drivers/scsi/st.c18
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_hipd.c3
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_hipd.h2
-rw-r--r--drivers/scsi/zalon.c4
-rw-r--r--drivers/serial/8250.c10
-rw-r--r--drivers/serial/8250_gsc.c6
-rw-r--r--drivers/serial/amba-pl010.c1
-rw-r--r--drivers/serial/amba-pl011.c1
-rw-r--r--drivers/serial/clps711x.c9
-rw-r--r--drivers/serial/imx.c8
-rw-r--r--drivers/serial/ioc4_serial.c80
-rw-r--r--drivers/serial/mpc52xx_uart.c8
-rw-r--r--drivers/serial/mpsc.c2
-rw-r--r--drivers/serial/mux.c11
-rw-r--r--drivers/serial/pxa.c29
-rw-r--r--drivers/serial/s3c2410.c9
-rw-r--r--drivers/serial/sa1100.c8
-rw-r--r--drivers/serial/serial_core.c3
-rw-r--r--drivers/serial/vr41xx_siu.c10
-rw-r--r--drivers/sh/superhyway/superhyway.c2
-rw-r--r--drivers/tc/tc.c89
-rw-r--r--drivers/tc/zs.c32
-rw-r--r--drivers/usb/Makefile2
-rw-r--r--drivers/usb/class/Kconfig23
-rw-r--r--drivers/usb/class/Makefile1
-rw-r--r--drivers/usb/class/bluetty.c1279
-rw-r--r--drivers/usb/class/cdc-acm.c5
-rw-r--r--drivers/usb/class/usblp.c3
-rw-r--r--drivers/usb/core/Kconfig11
-rw-r--r--drivers/usb/core/Makefile2
-rw-r--r--drivers/usb/core/buffer.c2
-rw-r--r--drivers/usb/core/config.c22
-rw-r--r--drivers/usb/core/devio.c192
-rw-r--r--drivers/usb/core/file.c23
-rw-r--r--drivers/usb/core/hcd-pci.c106
-rw-r--r--drivers/usb/core/hcd.c156
-rw-r--r--drivers/usb/core/hcd.h77
-rw-r--r--drivers/usb/core/hub.c426
-rw-r--r--drivers/usb/core/hub.h2
-rw-r--r--drivers/usb/core/inode.c44
-rw-r--r--drivers/usb/core/message.c90
-rw-r--r--drivers/usb/core/notify.c120
-rw-r--r--drivers/usb/core/sysfs.c319
-rw-r--r--drivers/usb/core/urb.c7
-rw-r--r--drivers/usb/core/usb.c167
-rw-r--r--drivers/usb/core/usb.h33
-rw-r--r--drivers/usb/gadget/dummy_hcd.c54
-rw-r--r--drivers/usb/gadget/ether.c23
-rw-r--r--drivers/usb/gadget/file_storage.c52
-rw-r--r--drivers/usb/gadget/goku_udc.c7
-rw-r--r--drivers/usb/gadget/lh7a40x_udc.c13
-rw-r--r--drivers/usb/gadget/net2280.c7
-rw-r--r--drivers/usb/gadget/omap_udc.c28
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.c26
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.h8
-rw-r--r--drivers/usb/gadget/serial.c16
-rw-r--r--drivers/usb/gadget/zero.c9
-rw-r--r--drivers/usb/host/Makefile5
-rw-r--r--drivers/usb/host/ehci-hcd.c545
-rw-r--r--drivers/usb/host/ehci-hub.c8
-rw-r--r--drivers/usb/host/ehci-mem.c6
-rw-r--r--drivers/usb/host/ehci-pci.c415
-rw-r--r--drivers/usb/host/ehci-q.c6
-rw-r--r--drivers/usb/host/ehci-sched.c14
-rw-r--r--drivers/usb/host/ehci.h1
-rw-r--r--drivers/usb/host/isp116x-hcd.c57
-rw-r--r--drivers/usb/host/isp116x.h1
-rw-r--r--drivers/usb/host/ohci-au1xxx.c6
-rw-r--r--drivers/usb/host/ohci-dbg.c4
-rw-r--r--drivers/usb/host/ohci-hcd.c6
-rw-r--r--drivers/usb/host/ohci-hub.c52
-rw-r--r--drivers/usb/host/ohci-lh7a404.c6
-rw-r--r--drivers/usb/host/ohci-mem.c5
-rw-r--r--drivers/usb/host/ohci-omap.c58
-rw-r--r--drivers/usb/host/ohci-pci.c49
-rw-r--r--drivers/usb/host/ohci-ppc-soc.c9
-rw-r--r--drivers/usb/host/ohci-pxa27x.c12
-rw-r--r--drivers/usb/host/ohci-s3c2410.c9
-rw-r--r--drivers/usb/host/ohci-sa1111.c7
-rw-r--r--drivers/usb/host/ohci.h1
-rw-r--r--drivers/usb/host/pci-quirks.c296
-rw-r--r--drivers/usb/host/sl811-hcd.c29
-rw-r--r--drivers/usb/host/uhci-debug.c5
-rw-r--r--drivers/usb/host/uhci-hcd.c178
-rw-r--r--drivers/usb/host/uhci-hcd.h98
-rw-r--r--drivers/usb/host/uhci-q.c64
-rw-r--r--drivers/usb/image/mdc800.c33
-rw-r--r--drivers/usb/image/microtek.c3
-rw-r--r--drivers/usb/input/acecad.c76
-rw-r--r--drivers/usb/input/aiptek.c209
-rw-r--r--drivers/usb/input/appletouch.c130
-rw-r--r--drivers/usb/input/ati_remote.c173
-rw-r--r--drivers/usb/input/hid-core.c56
-rw-r--r--drivers/usb/input/hid-input.c56
-rw-r--r--drivers/usb/input/hid-lgff.c17
-rw-r--r--drivers/usb/input/hid-tmff.c11
-rw-r--r--drivers/usb/input/hid.h2
-rw-r--r--drivers/usb/input/hiddev.c3
-rw-r--r--drivers/usb/input/itmtouch.c70
-rw-r--r--drivers/usb/input/kbtab.c82
-rw-r--r--drivers/usb/input/keyspan_remote.c210
-rw-r--r--drivers/usb/input/map_to_7segment.h2
-rw-r--r--drivers/usb/input/mtouchusb.c111
-rw-r--r--drivers/usb/input/pid.c14
-rw-r--r--drivers/usb/input/powermate.c136
-rw-r--r--drivers/usb/input/touchkitusb.c118
-rw-r--r--drivers/usb/input/usbkbd.c105
-rw-r--r--drivers/usb/input/usbmouse.c93
-rw-r--r--drivers/usb/input/wacom.c142
-rw-r--r--drivers/usb/input/xpad.c95
-rw-r--r--drivers/usb/input/yealink.c66
-rw-r--r--drivers/usb/media/dabusb.c3
-rw-r--r--drivers/usb/media/konicawc.c89
-rw-r--r--drivers/usb/misc/auerswald.c3
-rw-r--r--drivers/usb/misc/idmouse.c21
-rw-r--r--drivers/usb/misc/legousbtower.c5
-rw-r--r--drivers/usb/misc/rio500.c3
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb.c7
-rw-r--r--drivers/usb/misc/usblcd.c9
-rw-r--r--drivers/usb/misc/usbtest.c18
-rw-r--r--drivers/usb/misc/uss720.c6
-rw-r--r--drivers/usb/mon/mon_main.c23
-rw-r--r--drivers/usb/net/Kconfig2
-rw-r--r--drivers/usb/net/asix.c2
-rw-r--r--drivers/usb/net/gl620a.c2
-rw-r--r--drivers/usb/net/kaweth.c8
-rw-r--r--drivers/usb/net/net1080.c2
-rw-r--r--drivers/usb/net/pegasus.c2
-rw-r--r--drivers/usb/net/pegasus.h2
-rw-r--r--drivers/usb/net/rndis_host.c2
-rw-r--r--drivers/usb/net/rtl8150.c1
-rw-r--r--drivers/usb/net/usbnet.c4
-rw-r--r--drivers/usb/net/usbnet.h2
-rw-r--r--drivers/usb/net/zaurus.c2
-rw-r--r--drivers/usb/net/zd1201.c2
-rw-r--r--drivers/usb/serial/ChangeLog.old730
-rw-r--r--drivers/usb/serial/Kconfig9
-rw-r--r--drivers/usb/serial/Makefile1
-rw-r--r--drivers/usb/serial/airprime.c8
-rw-r--r--drivers/usb/serial/belkin_sa.c10
-rw-r--r--drivers/usb/serial/bus.c37
-rw-r--r--drivers/usb/serial/cp2101.c10
-rw-r--r--drivers/usb/serial/cyberjack.c10
-rw-r--r--drivers/usb/serial/cypress_m8.c20
-rw-r--r--drivers/usb/serial/digi_acceleport.c20
-rw-r--r--drivers/usb/serial/empeg.c8
-rw-r--r--drivers/usb/serial/ftdi_sio.c16
-rw-r--r--drivers/usb/serial/ftdi_sio.h16
-rw-r--r--drivers/usb/serial/garmin_gps.c15
-rw-r--r--drivers/usb/serial/generic.c9
-rw-r--r--drivers/usb/serial/hp4x.c10
-rw-r--r--drivers/usb/serial/io_edgeport.c219
-rw-r--r--drivers/usb/serial/io_tables.h30
-rw-r--r--drivers/usb/serial/io_ti.c20
-rw-r--r--drivers/usb/serial/ipaq.c247
-rw-r--r--drivers/usb/serial/ipw.c10
-rw-r--r--drivers/usb/serial/ir-usb.c9
-rw-r--r--drivers/usb/serial/keyspan.h40
-rw-r--r--drivers/usb/serial/keyspan_pda.c30
-rw-r--r--drivers/usb/serial/kl5kusb105.c10
-rw-r--r--drivers/usb/serial/kobil_sct.c9
-rw-r--r--drivers/usb/serial/mct_u232.c10
-rw-r--r--drivers/usb/serial/nokia_dku2.c142
-rw-r--r--drivers/usb/serial/omninet.c10
-rw-r--r--drivers/usb/serial/option.c10
-rw-r--r--drivers/usb/serial/pl2303.c35
-rw-r--r--drivers/usb/serial/safe_serial.c10
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c18
-rw-r--r--drivers/usb/serial/usb-serial.c378
-rw-r--r--drivers/usb/serial/usb-serial.h81
-rw-r--r--drivers/usb/serial/visor.c170
-rw-r--r--drivers/usb/serial/whiteheat.c42
-rw-r--r--drivers/usb/storage/Kconfig3
-rw-r--r--drivers/usb/storage/onetouch.c99
-rw-r--r--drivers/usb/storage/shuttle_usbat.c314
-rw-r--r--drivers/usb/storage/shuttle_usbat.h66
-rw-r--r--drivers/usb/storage/transport.c6
-rw-r--r--drivers/usb/storage/transport.h2
-rw-r--r--drivers/usb/storage/unusual_devs.h44
-rw-r--r--drivers/usb/storage/usb.c163
-rw-r--r--drivers/usb/storage/usb.h5
-rw-r--r--drivers/usb/usb-skeleton.c3
-rw-r--r--drivers/video/Kconfig14
-rw-r--r--drivers/video/Makefile2
-rw-r--r--drivers/video/amba-clcd.c1
-rw-r--r--drivers/video/au1100fb.c971
-rw-r--r--drivers/video/au1100fb.h614
-rw-r--r--drivers/video/backlight/corgi_bl.c10
-rw-r--r--drivers/video/cirrusfb.c24
-rw-r--r--drivers/video/console/Kconfig10
-rw-r--r--drivers/video/console/newport_con.c1
-rw-r--r--drivers/video/console/sticore.c126
-rw-r--r--drivers/video/console/vgacon.c2
-rw-r--r--drivers/video/fbmem.c2
-rw-r--r--drivers/video/gbefb.c20
-rw-r--r--drivers/video/imxfb.c10
-rw-r--r--drivers/video/pxafb.c10
-rw-r--r--drivers/video/s1d13xxxfb.c7
-rw-r--r--drivers/video/s3c2410fb.c27
-rw-r--r--drivers/video/sa1100fb.c10
-rw-r--r--drivers/video/w100fb.c46
-rw-r--r--drivers/w1/w1_family.c1
-rw-r--r--drivers/zorro/zorro-sysfs.c1
-rw-r--r--drivers/zorro/zorro.c2
951 files changed, 42625 insertions, 29865 deletions
diff --git a/drivers/Makefile b/drivers/Makefile
index 1a109a6dd953..65670be6ff1a 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -5,7 +5,7 @@
5# Rewritten to use lists instead of if-statements. 5# Rewritten to use lists instead of if-statements.
6# 6#
7 7
8obj-$(CONFIG_PCI) += pci/ 8obj-$(CONFIG_PCI) += pci/ usb/
9obj-$(CONFIG_PARISC) += parisc/ 9obj-$(CONFIG_PARISC) += parisc/
10obj-y += video/ 10obj-y += video/
11obj-$(CONFIG_ACPI) += acpi/ 11obj-$(CONFIG_ACPI) += acpi/
diff --git a/drivers/acorn/char/pcf8583.c b/drivers/acorn/char/pcf8583.c
index 2b850e5860a0..e26f007a1417 100644
--- a/drivers/acorn/char/pcf8583.c
+++ b/drivers/acorn/char/pcf8583.c
@@ -9,6 +9,7 @@
9 * 9 *
10 * Driver for PCF8583 RTC & RAM chip 10 * Driver for PCF8583 RTC & RAM chip
11 */ 11 */
12#include <linux/module.h>
12#include <linux/i2c.h> 13#include <linux/i2c.h>
13#include <linux/slab.h> 14#include <linux/slab.h>
14#include <linux/string.h> 15#include <linux/string.h>
@@ -32,7 +33,8 @@ static struct i2c_client_address_data addr_data = {
32 .forces = forces, 33 .forces = forces,
33}; 34};
34 35
35#define DAT(x) ((unsigned int)(x->dev.driver_data)) 36#define set_ctrl(x, v) i2c_set_clientdata(x, (void *)(unsigned int)(v))
37#define get_ctrl(x) ((unsigned int)i2c_get_clientdata(x))
36 38
37static int 39static int
38pcf8583_attach(struct i2c_adapter *adap, int addr, int kind) 40pcf8583_attach(struct i2c_adapter *adap, int addr, int kind)
@@ -40,8 +42,17 @@ pcf8583_attach(struct i2c_adapter *adap, int addr, int kind)
40 struct i2c_client *c; 42 struct i2c_client *c;
41 unsigned char buf[1], ad[1] = { 0 }; 43 unsigned char buf[1], ad[1] = { 0 };
42 struct i2c_msg msgs[2] = { 44 struct i2c_msg msgs[2] = {
43 { addr, 0, 1, ad }, 45 {
44 { addr, I2C_M_RD, 1, buf } 46 .addr = addr,
47 .flags = 0,
48 .len = 1,
49 .buf = ad,
50 }, {
51 .addr = addr,
52 .flags = I2C_M_RD,
53 .len = 1,
54 .buf = buf,
55 }
45 }; 56 };
46 57
47 c = kmalloc(sizeof(*c), GFP_KERNEL); 58 c = kmalloc(sizeof(*c), GFP_KERNEL);
@@ -54,7 +65,7 @@ pcf8583_attach(struct i2c_adapter *adap, int addr, int kind)
54 c->driver = &pcf8583_driver; 65 c->driver = &pcf8583_driver;
55 66
56 if (i2c_transfer(c->adapter, msgs, 2) == 2) 67 if (i2c_transfer(c->adapter, msgs, 2) == 2)
57 DAT(c) = buf[0]; 68 set_ctrl(c, buf[0]);
58 69
59 return i2c_attach_client(c); 70 return i2c_attach_client(c);
60} 71}
@@ -78,8 +89,17 @@ pcf8583_get_datetime(struct i2c_client *client, struct rtc_tm *dt)
78{ 89{
79 unsigned char buf[8], addr[1] = { 1 }; 90 unsigned char buf[8], addr[1] = { 1 };
80 struct i2c_msg msgs[2] = { 91 struct i2c_msg msgs[2] = {
81 { client->addr, 0, 1, addr }, 92 {
82 { client->addr, I2C_M_RD, 6, buf } 93 .addr = client->addr,
94 .flags = 0,
95 .len = 1,
96 .buf = addr,
97 }, {
98 .addr = client->addr,
99 .flags = I2C_M_RD,
100 .len = 6,
101 .buf = buf,
102 }
83 }; 103 };
84 int ret = -EIO; 104 int ret = -EIO;
85 105
@@ -113,7 +133,7 @@ pcf8583_set_datetime(struct i2c_client *client, struct rtc_tm *dt, int datetoo)
113 int ret, len = 6; 133 int ret, len = 6;
114 134
115 buf[0] = 0; 135 buf[0] = 0;
116 buf[1] = DAT(client) | 0x80; 136 buf[1] = get_ctrl(client) | 0x80;
117 buf[2] = BIN_TO_BCD(dt->cs); 137 buf[2] = BIN_TO_BCD(dt->cs);
118 buf[3] = BIN_TO_BCD(dt->secs); 138 buf[3] = BIN_TO_BCD(dt->secs);
119 buf[4] = BIN_TO_BCD(dt->mins); 139 buf[4] = BIN_TO_BCD(dt->mins);
@@ -129,7 +149,7 @@ pcf8583_set_datetime(struct i2c_client *client, struct rtc_tm *dt, int datetoo)
129 if (ret == len) 149 if (ret == len)
130 ret = 0; 150 ret = 0;
131 151
132 buf[1] = DAT(client); 152 buf[1] = get_ctrl(client);
133 i2c_master_send(client, (char *)buf, 2); 153 i2c_master_send(client, (char *)buf, 2);
134 154
135 return ret; 155 return ret;
@@ -138,7 +158,7 @@ pcf8583_set_datetime(struct i2c_client *client, struct rtc_tm *dt, int datetoo)
138static int 158static int
139pcf8583_get_ctrl(struct i2c_client *client, unsigned char *ctrl) 159pcf8583_get_ctrl(struct i2c_client *client, unsigned char *ctrl)
140{ 160{
141 *ctrl = DAT(client); 161 *ctrl = get_ctrl(client);
142 return 0; 162 return 0;
143} 163}
144 164
@@ -149,7 +169,7 @@ pcf8583_set_ctrl(struct i2c_client *client, unsigned char *ctrl)
149 169
150 buf[0] = 0; 170 buf[0] = 0;
151 buf[1] = *ctrl; 171 buf[1] = *ctrl;
152 DAT(client) = *ctrl; 172 set_ctrl(client, *ctrl);
153 173
154 return i2c_master_send(client, (char *)buf, 2); 174 return i2c_master_send(client, (char *)buf, 2);
155} 175}
@@ -159,15 +179,23 @@ pcf8583_read_mem(struct i2c_client *client, struct mem *mem)
159{ 179{
160 unsigned char addr[1]; 180 unsigned char addr[1];
161 struct i2c_msg msgs[2] = { 181 struct i2c_msg msgs[2] = {
162 { client->addr, 0, 1, addr }, 182 {
163 { client->addr, I2C_M_RD, 0, mem->data } 183 .addr = client->addr,
184 .flags = 0,
185 .len = 1,
186 .buf = addr,
187 }, {
188 .addr = client->addr,
189 .flags = I2C_M_RD,
190 .len = mem->nr,
191 .buf = mem->data,
192 }
164 }; 193 };
165 194
166 if (mem->loc < 8) 195 if (mem->loc < 8)
167 return -EINVAL; 196 return -EINVAL;
168 197
169 addr[0] = mem->loc; 198 addr[0] = mem->loc;
170 msgs[1].len = mem->nr;
171 199
172 return i2c_transfer(client->adapter, msgs, 2) == 2 ? 0 : -EIO; 200 return i2c_transfer(client->adapter, msgs, 2) == 2 ? 0 : -EIO;
173} 201}
@@ -177,15 +205,23 @@ pcf8583_write_mem(struct i2c_client *client, struct mem *mem)
177{ 205{
178 unsigned char addr[1]; 206 unsigned char addr[1];
179 struct i2c_msg msgs[2] = { 207 struct i2c_msg msgs[2] = {
180 { client->addr, 0, 1, addr }, 208 {
181 { client->addr, 0, 0, mem->data } 209 .addr = client->addr,
210 .flags = 0,
211 .len = 1,
212 .buf = addr,
213 }, {
214 .addr = client->addr,
215 .flags = I2C_M_NOSTART,
216 .len = mem->nr,
217 .buf = mem->data,
218 }
182 }; 219 };
183 220
184 if (mem->loc < 8) 221 if (mem->loc < 8)
185 return -EINVAL; 222 return -EINVAL;
186 223
187 addr[0] = mem->loc; 224 addr[0] = mem->loc;
188 msgs[1].len = mem->nr;
189 225
190 return i2c_transfer(client->adapter, msgs, 2) == 2 ? 0 : -EIO; 226 return i2c_transfer(client->adapter, msgs, 2) == 2 ? 0 : -EIO;
191} 227}
@@ -234,4 +270,14 @@ static __init int pcf8583_init(void)
234 return i2c_add_driver(&pcf8583_driver); 270 return i2c_add_driver(&pcf8583_driver);
235} 271}
236 272
237__initcall(pcf8583_init); 273static __exit void pcf8583_exit(void)
274{
275 i2c_del_driver(&pcf8583_driver);
276}
277
278module_init(pcf8583_init);
279module_exit(pcf8583_exit);
280
281MODULE_AUTHOR("Russell King");
282MODULE_DESCRIPTION("PCF8583 I2C RTC driver");
283MODULE_LICENSE("GPL");
diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c
index 01a1bd239263..2143609d2936 100644
--- a/drivers/acpi/acpi_memhotplug.c
+++ b/drivers/acpi/acpi_memhotplug.c
@@ -200,8 +200,7 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
200 * Note: Assume that this function returns zero on success 200 * Note: Assume that this function returns zero on success
201 */ 201 */
202 result = add_memory(mem_device->start_addr, 202 result = add_memory(mem_device->start_addr,
203 (mem_device->end_addr - mem_device->start_addr) + 1, 203 (mem_device->end_addr - mem_device->start_addr) + 1);
204 mem_device->read_write_attribute);
205 if (result) { 204 if (result) {
206 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "\nadd_memory failed\n")); 205 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "\nadd_memory failed\n"));
207 mem_device->state = MEMORY_INVALID_STATE; 206 mem_device->state = MEMORY_INVALID_STATE;
@@ -259,7 +258,7 @@ static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
259 * Ask the VM to offline this memory range. 258 * Ask the VM to offline this memory range.
260 * Note: Assume that this function returns zero on success 259 * Note: Assume that this function returns zero on success
261 */ 260 */
262 result = remove_memory(start, len, attr); 261 result = remove_memory(start, len);
263 if (result) { 262 if (result) {
264 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Hot-Remove failed.\n")); 263 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Hot-Remove failed.\n"));
265 return_VALUE(result); 264 return_VALUE(result);
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 26a3a4016115..161db4acfb91 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -37,6 +37,7 @@
37#include <linux/acpi.h> 37#include <linux/acpi.h>
38#include <linux/dmi.h> 38#include <linux/dmi.h>
39#include <linux/moduleparam.h> 39#include <linux/moduleparam.h>
40#include <linux/sched.h> /* need_resched() */
40 41
41#include <asm/io.h> 42#include <asm/io.h>
42#include <asm/uaccess.h> 43#include <asm/uaccess.h>
diff --git a/drivers/acpi/sleep/main.c b/drivers/acpi/sleep/main.c
index aee50b453265..930427fc0c4b 100644
--- a/drivers/acpi/sleep/main.c
+++ b/drivers/acpi/sleep/main.c
@@ -158,7 +158,15 @@ int acpi_suspend(u32 acpi_state)
158 return -EINVAL; 158 return -EINVAL;
159} 159}
160 160
161static int acpi_pm_state_valid(suspend_state_t pm_state)
162{
163 u32 acpi_state = acpi_suspend_states[pm_state];
164
165 return sleep_states[acpi_state];
166}
167
161static struct pm_ops acpi_pm_ops = { 168static struct pm_ops acpi_pm_ops = {
169 .valid = acpi_pm_state_valid,
162 .prepare = acpi_pm_prepare, 170 .prepare = acpi_pm_prepare,
163 .enter = acpi_pm_enter, 171 .enter = acpi_pm_enter,
164 .finish = acpi_pm_finish, 172 .finish = acpi_pm_finish,
diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index 66d9c4643fc1..f12898d53078 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -7,6 +7,7 @@ obj-y := core.o sys.o bus.o dd.o \
7obj-y += power/ 7obj-y += power/
8obj-$(CONFIG_FW_LOADER) += firmware_class.o 8obj-$(CONFIG_FW_LOADER) += firmware_class.o
9obj-$(CONFIG_NUMA) += node.o 9obj-$(CONFIG_NUMA) += node.o
10obj-$(CONFIG_MEMORY_HOTPLUG) += memory.o
10 11
11ifeq ($(CONFIG_DEBUG_DRIVER),y) 12ifeq ($(CONFIG_DEBUG_DRIVER),y)
12EXTRA_CFLAGS += -DDEBUG 13EXTRA_CFLAGS += -DDEBUG
diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
index 6b2eb6f39b4d..2a7d7ae83e1e 100644
--- a/drivers/base/attribute_container.c
+++ b/drivers/base/attribute_container.c
@@ -19,6 +19,8 @@
19#include <linux/list.h> 19#include <linux/list.h>
20#include <linux/module.h> 20#include <linux/module.h>
21 21
22#include "base.h"
23
22/* This is a private structure used to tie the classdev and the 24/* This is a private structure used to tie the classdev and the
23 * container .. it should never be visible outside this file */ 25 * container .. it should never be visible outside this file */
24struct internal_container { 26struct internal_container {
diff --git a/drivers/base/base.h b/drivers/base/base.h
index 783752b68a9a..e3b548d46cff 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -1,3 +1,15 @@
1
2/* initialisation functions */
3
4extern int devices_init(void);
5extern int buses_init(void);
6extern int classes_init(void);
7extern int firmware_init(void);
8extern int platform_bus_init(void);
9extern int system_bus_init(void);
10extern int cpu_dev_init(void);
11extern int attribute_container_init(void);
12
1extern int bus_add_device(struct device * dev); 13extern int bus_add_device(struct device * dev);
2extern void bus_remove_device(struct device * dev); 14extern void bus_remove_device(struct device * dev);
3 15
diff --git a/drivers/base/class.c b/drivers/base/class.c
index ce23dc8c18c5..db65fd0babe9 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -17,6 +17,7 @@
17#include <linux/string.h> 17#include <linux/string.h>
18#include <linux/kdev_t.h> 18#include <linux/kdev_t.h>
19#include <linux/err.h> 19#include <linux/err.h>
20#include <linux/slab.h>
20#include "base.h" 21#include "base.h"
21 22
22#define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr) 23#define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr)
@@ -99,7 +100,8 @@ struct class * class_get(struct class * cls)
99 100
100void class_put(struct class * cls) 101void class_put(struct class * cls)
101{ 102{
102 subsys_put(&cls->subsys); 103 if (cls)
104 subsys_put(&cls->subsys);
103} 105}
104 106
105 107
@@ -165,14 +167,25 @@ void class_unregister(struct class * cls)
165 167
166static void class_create_release(struct class *cls) 168static void class_create_release(struct class *cls)
167{ 169{
170 pr_debug("%s called for %s\n", __FUNCTION__, cls->name);
168 kfree(cls); 171 kfree(cls);
169} 172}
170 173
171static void class_device_create_release(struct class_device *class_dev) 174static void class_device_create_release(struct class_device *class_dev)
172{ 175{
176 pr_debug("%s called for %s\n", __FUNCTION__, class_dev->class_id);
173 kfree(class_dev); 177 kfree(class_dev);
174} 178}
175 179
180/* needed to allow these devices to have parent class devices */
181static int class_device_create_hotplug(struct class_device *class_dev,
182 char **envp, int num_envp,
183 char *buffer, int buffer_size)
184{
185 pr_debug("%s called for %s\n", __FUNCTION__, class_dev->class_id);
186 return 0;
187}
188
176/** 189/**
177 * class_create - create a struct class structure 190 * class_create - create a struct class structure
178 * @owner: pointer to the module that is to "own" this struct class 191 * @owner: pointer to the module that is to "own" this struct class
@@ -301,10 +314,12 @@ static void class_dev_release(struct kobject * kobj)
301 kfree(cd->devt_attr); 314 kfree(cd->devt_attr);
302 cd->devt_attr = NULL; 315 cd->devt_attr = NULL;
303 316
304 if (cls->release) 317 if (cd->release)
318 cd->release(cd);
319 else if (cls->release)
305 cls->release(cd); 320 cls->release(cd);
306 else { 321 else {
307 printk(KERN_ERR "Device class '%s' does not have a release() function, " 322 printk(KERN_ERR "Class Device '%s' does not have a release() function, "
308 "it is broken and must be fixed.\n", 323 "it is broken and must be fixed.\n",
309 cd->class_id); 324 cd->class_id);
310 WARN_ON(1); 325 WARN_ON(1);
@@ -382,14 +397,18 @@ static int class_hotplug(struct kset *kset, struct kobject *kobj, char **envp,
382 buffer = &buffer[length]; 397 buffer = &buffer[length];
383 buffer_size -= length; 398 buffer_size -= length;
384 399
385 if (class_dev->class->hotplug) { 400 if (class_dev->hotplug) {
386 /* have the bus specific function add its stuff */ 401 /* have the class device specific function add its stuff */
387 retval = class_dev->class->hotplug (class_dev, envp, num_envp, 402 retval = class_dev->hotplug(class_dev, envp, num_envp,
388 buffer, buffer_size); 403 buffer, buffer_size);
389 if (retval) { 404 if (retval)
390 pr_debug ("%s - hotplug() returned %d\n", 405 pr_debug("class_dev->hotplug() returned %d\n", retval);
391 __FUNCTION__, retval); 406 } else if (class_dev->class->hotplug) {
392 } 407 /* have the class specific function add its stuff */
408 retval = class_dev->class->hotplug(class_dev, envp, num_envp,
409 buffer, buffer_size);
410 if (retval)
411 pr_debug("class->hotplug() returned %d\n", retval);
393 } 412 }
394 413
395 return retval; 414 return retval;
@@ -442,6 +461,13 @@ static ssize_t show_dev(struct class_device *class_dev, char *buf)
442 return print_dev_t(buf, class_dev->devt); 461 return print_dev_t(buf, class_dev->devt);
443} 462}
444 463
464static ssize_t store_uevent(struct class_device *class_dev,
465 const char *buf, size_t count)
466{
467 kobject_hotplug(&class_dev->kobj, KOBJ_ADD);
468 return count;
469}
470
445void class_device_initialize(struct class_device *class_dev) 471void class_device_initialize(struct class_device *class_dev)
446{ 472{
447 kobj_set_kset_s(class_dev, class_obj_subsys); 473 kobj_set_kset_s(class_dev, class_obj_subsys);
@@ -469,34 +495,45 @@ static char *make_class_name(struct class_device *class_dev)
469 495
470int class_device_add(struct class_device *class_dev) 496int class_device_add(struct class_device *class_dev)
471{ 497{
472 struct class * parent = NULL; 498 struct class *parent_class = NULL;
473 struct class_interface * class_intf; 499 struct class_device *parent_class_dev = NULL;
500 struct class_interface *class_intf;
474 char *class_name = NULL; 501 char *class_name = NULL;
475 int error; 502 int error = -EINVAL;
476 503
477 class_dev = class_device_get(class_dev); 504 class_dev = class_device_get(class_dev);
478 if (!class_dev) 505 if (!class_dev)
479 return -EINVAL; 506 return -EINVAL;
480 507
481 if (!strlen(class_dev->class_id)) { 508 if (!strlen(class_dev->class_id))
482 error = -EINVAL;
483 goto register_done; 509 goto register_done;
484 }
485 510
486 parent = class_get(class_dev->class); 511 parent_class = class_get(class_dev->class);
512 if (!parent_class)
513 goto register_done;
514 parent_class_dev = class_device_get(class_dev->parent);
487 515
488 pr_debug("CLASS: registering class device: ID = '%s'\n", 516 pr_debug("CLASS: registering class device: ID = '%s'\n",
489 class_dev->class_id); 517 class_dev->class_id);
490 518
491 /* first, register with generic layer. */ 519 /* first, register with generic layer. */
492 kobject_set_name(&class_dev->kobj, "%s", class_dev->class_id); 520 kobject_set_name(&class_dev->kobj, "%s", class_dev->class_id);
493 if (parent) 521 if (parent_class_dev)
494 class_dev->kobj.parent = &parent->subsys.kset.kobj; 522 class_dev->kobj.parent = &parent_class_dev->kobj;
523 else
524 class_dev->kobj.parent = &parent_class->subsys.kset.kobj;
495 525
496 if ((error = kobject_add(&class_dev->kobj))) 526 error = kobject_add(&class_dev->kobj);
527 if (error)
497 goto register_done; 528 goto register_done;
498 529
499 /* add the needed attributes to this device */ 530 /* add the needed attributes to this device */
531 class_dev->uevent_attr.attr.name = "uevent";
532 class_dev->uevent_attr.attr.mode = S_IWUSR;
533 class_dev->uevent_attr.attr.owner = parent_class->owner;
534 class_dev->uevent_attr.store = store_uevent;
535 class_device_create_file(class_dev, &class_dev->uevent_attr);
536
500 if (MAJOR(class_dev->devt)) { 537 if (MAJOR(class_dev->devt)) {
501 struct class_device_attribute *attr; 538 struct class_device_attribute *attr;
502 attr = kzalloc(sizeof(*attr), GFP_KERNEL); 539 attr = kzalloc(sizeof(*attr), GFP_KERNEL);
@@ -505,12 +542,10 @@ int class_device_add(struct class_device *class_dev)
505 kobject_del(&class_dev->kobj); 542 kobject_del(&class_dev->kobj);
506 goto register_done; 543 goto register_done;
507 } 544 }
508
509 attr->attr.name = "dev"; 545 attr->attr.name = "dev";
510 attr->attr.mode = S_IRUGO; 546 attr->attr.mode = S_IRUGO;
511 attr->attr.owner = parent->owner; 547 attr->attr.owner = parent_class->owner;
512 attr->show = show_dev; 548 attr->show = show_dev;
513 attr->store = NULL;
514 class_device_create_file(class_dev, attr); 549 class_device_create_file(class_dev, attr);
515 class_dev->devt_attr = attr; 550 class_dev->devt_attr = attr;
516 } 551 }
@@ -524,20 +559,23 @@ int class_device_add(struct class_device *class_dev)
524 class_name); 559 class_name);
525 } 560 }
526 561
562 kobject_hotplug(&class_dev->kobj, KOBJ_ADD);
563
527 /* notify any interfaces this device is now here */ 564 /* notify any interfaces this device is now here */
528 if (parent) { 565 if (parent_class) {
529 down(&parent->sem); 566 down(&parent_class->sem);
530 list_add_tail(&class_dev->node, &parent->children); 567 list_add_tail(&class_dev->node, &parent_class->children);
531 list_for_each_entry(class_intf, &parent->interfaces, node) 568 list_for_each_entry(class_intf, &parent_class->interfaces, node)
532 if (class_intf->add) 569 if (class_intf->add)
533 class_intf->add(class_dev); 570 class_intf->add(class_dev, class_intf);
534 up(&parent->sem); 571 up(&parent_class->sem);
535 } 572 }
536 kobject_hotplug(&class_dev->kobj, KOBJ_ADD);
537 573
538 register_done: 574 register_done:
539 if (error && parent) 575 if (error) {
540 class_put(parent); 576 class_put(parent_class);
577 class_device_put(parent_class_dev);
578 }
541 class_device_put(class_dev); 579 class_device_put(class_dev);
542 kfree(class_name); 580 kfree(class_name);
543 return error; 581 return error;
@@ -552,21 +590,28 @@ int class_device_register(struct class_device *class_dev)
552/** 590/**
553 * class_device_create - creates a class device and registers it with sysfs 591 * class_device_create - creates a class device and registers it with sysfs
554 * @cs: pointer to the struct class that this device should be registered to. 592 * @cs: pointer to the struct class that this device should be registered to.
593 * @parent: pointer to the parent struct class_device of this new device, if any.
555 * @dev: the dev_t for the char device to be added. 594 * @dev: the dev_t for the char device to be added.
556 * @device: a pointer to a struct device that is assiociated with this class device. 595 * @device: a pointer to a struct device that is assiociated with this class device.
557 * @fmt: string for the class device's name 596 * @fmt: string for the class device's name
558 * 597 *
559 * This function can be used by char device classes. A struct 598 * This function can be used by char device classes. A struct
560 * class_device will be created in sysfs, registered to the specified 599 * class_device will be created in sysfs, registered to the specified
561 * class. A "dev" file will be created, showing the dev_t for the 600 * class.
562 * device. The pointer to the struct class_device will be returned from 601 * A "dev" file will be created, showing the dev_t for the device, if
563 * the call. Any further sysfs files that might be required can be 602 * the dev_t is not 0,0.
564 * created using this pointer. 603 * If a pointer to a parent struct class_device is passed in, the newly
604 * created struct class_device will be a child of that device in sysfs.
605 * The pointer to the struct class_device will be returned from the
606 * call. Any further sysfs files that might be required can be created
607 * using this pointer.
565 * 608 *
566 * Note: the struct class passed to this function must have previously 609 * Note: the struct class passed to this function must have previously
567 * been created with a call to class_create(). 610 * been created with a call to class_create().
568 */ 611 */
569struct class_device *class_device_create(struct class *cls, dev_t devt, 612struct class_device *class_device_create(struct class *cls,
613 struct class_device *parent,
614 dev_t devt,
570 struct device *device, char *fmt, ...) 615 struct device *device, char *fmt, ...)
571{ 616{
572 va_list args; 617 va_list args;
@@ -585,6 +630,9 @@ struct class_device *class_device_create(struct class *cls, dev_t devt,
585 class_dev->devt = devt; 630 class_dev->devt = devt;
586 class_dev->dev = device; 631 class_dev->dev = device;
587 class_dev->class = cls; 632 class_dev->class = cls;
633 class_dev->parent = parent;
634 class_dev->release = class_device_create_release;
635 class_dev->hotplug = class_device_create_hotplug;
588 636
589 va_start(args, fmt); 637 va_start(args, fmt);
590 vsnprintf(class_dev->class_id, BUS_ID_SIZE, fmt, args); 638 vsnprintf(class_dev->class_id, BUS_ID_SIZE, fmt, args);
@@ -602,17 +650,18 @@ error:
602 650
603void class_device_del(struct class_device *class_dev) 651void class_device_del(struct class_device *class_dev)
604{ 652{
605 struct class * parent = class_dev->class; 653 struct class *parent_class = class_dev->class;
606 struct class_interface * class_intf; 654 struct class_device *parent_device = class_dev->parent;
655 struct class_interface *class_intf;
607 char *class_name = NULL; 656 char *class_name = NULL;
608 657
609 if (parent) { 658 if (parent_class) {
610 down(&parent->sem); 659 down(&parent_class->sem);
611 list_del_init(&class_dev->node); 660 list_del_init(&class_dev->node);
612 list_for_each_entry(class_intf, &parent->interfaces, node) 661 list_for_each_entry(class_intf, &parent_class->interfaces, node)
613 if (class_intf->remove) 662 if (class_intf->remove)
614 class_intf->remove(class_dev); 663 class_intf->remove(class_dev, class_intf);
615 up(&parent->sem); 664 up(&parent_class->sem);
616 } 665 }
617 666
618 if (class_dev->dev) { 667 if (class_dev->dev) {
@@ -620,6 +669,7 @@ void class_device_del(struct class_device *class_dev)
620 sysfs_remove_link(&class_dev->kobj, "device"); 669 sysfs_remove_link(&class_dev->kobj, "device");
621 sysfs_remove_link(&class_dev->dev->kobj, class_name); 670 sysfs_remove_link(&class_dev->dev->kobj, class_name);
622 } 671 }
672 class_device_remove_file(class_dev, &class_dev->uevent_attr);
623 if (class_dev->devt_attr) 673 if (class_dev->devt_attr)
624 class_device_remove_file(class_dev, class_dev->devt_attr); 674 class_device_remove_file(class_dev, class_dev->devt_attr);
625 class_device_remove_attrs(class_dev); 675 class_device_remove_attrs(class_dev);
@@ -627,8 +677,8 @@ void class_device_del(struct class_device *class_dev)
627 kobject_hotplug(&class_dev->kobj, KOBJ_REMOVE); 677 kobject_hotplug(&class_dev->kobj, KOBJ_REMOVE);
628 kobject_del(&class_dev->kobj); 678 kobject_del(&class_dev->kobj);
629 679
630 if (parent) 680 class_device_put(parent_device);
631 class_put(parent); 681 class_put(parent_class);
632 kfree(class_name); 682 kfree(class_name);
633} 683}
634 684
@@ -708,7 +758,8 @@ struct class_device * class_device_get(struct class_device *class_dev)
708 758
709void class_device_put(struct class_device *class_dev) 759void class_device_put(struct class_device *class_dev)
710{ 760{
711 kobject_put(&class_dev->kobj); 761 if (class_dev)
762 kobject_put(&class_dev->kobj);
712} 763}
713 764
714 765
@@ -728,7 +779,7 @@ int class_interface_register(struct class_interface *class_intf)
728 list_add_tail(&class_intf->node, &parent->interfaces); 779 list_add_tail(&class_intf->node, &parent->interfaces);
729 if (class_intf->add) { 780 if (class_intf->add) {
730 list_for_each_entry(class_dev, &parent->children, node) 781 list_for_each_entry(class_dev, &parent->children, node)
731 class_intf->add(class_dev); 782 class_intf->add(class_dev, class_intf);
732 } 783 }
733 up(&parent->sem); 784 up(&parent->sem);
734 785
@@ -747,7 +798,7 @@ void class_interface_unregister(struct class_interface *class_intf)
747 list_del_init(&class_intf->node); 798 list_del_init(&class_intf->node);
748 if (class_intf->remove) { 799 if (class_intf->remove) {
749 list_for_each_entry(class_dev, &parent->children, node) 800 list_for_each_entry(class_dev, &parent->children, node)
750 class_intf->remove(class_dev); 801 class_intf->remove(class_dev, class_intf);
751 } 802 }
752 up(&parent->sem); 803 up(&parent->sem);
753 804
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 6ab73f5c799a..8615b42b517a 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -154,6 +154,13 @@ static struct kset_hotplug_ops device_hotplug_ops = {
154 .hotplug = dev_hotplug, 154 .hotplug = dev_hotplug,
155}; 155};
156 156
157static ssize_t store_uevent(struct device *dev, struct device_attribute *attr,
158 const char *buf, size_t count)
159{
160 kobject_hotplug(&dev->kobj, KOBJ_ADD);
161 return count;
162}
163
157/** 164/**
158 * device_subsys - structure to be registered with kobject core. 165 * device_subsys - structure to be registered with kobject core.
159 */ 166 */
@@ -225,6 +232,7 @@ void device_initialize(struct device *dev)
225 klist_children_put); 232 klist_children_put);
226 INIT_LIST_HEAD(&dev->dma_pools); 233 INIT_LIST_HEAD(&dev->dma_pools);
227 init_MUTEX(&dev->sem); 234 init_MUTEX(&dev->sem);
235 device_init_wakeup(dev, 0);
228} 236}
229 237
230/** 238/**
@@ -258,6 +266,14 @@ int device_add(struct device *dev)
258 266
259 if ((error = kobject_add(&dev->kobj))) 267 if ((error = kobject_add(&dev->kobj)))
260 goto Error; 268 goto Error;
269
270 dev->uevent_attr.attr.name = "uevent";
271 dev->uevent_attr.attr.mode = S_IWUSR;
272 if (dev->driver)
273 dev->uevent_attr.attr.owner = dev->driver->owner;
274 dev->uevent_attr.store = store_uevent;
275 device_create_file(dev, &dev->uevent_attr);
276
261 kobject_hotplug(&dev->kobj, KOBJ_ADD); 277 kobject_hotplug(&dev->kobj, KOBJ_ADD);
262 if ((error = device_pm_add(dev))) 278 if ((error = device_pm_add(dev)))
263 goto PMError; 279 goto PMError;
@@ -349,6 +365,7 @@ void device_del(struct device * dev)
349 365
350 if (parent) 366 if (parent)
351 klist_del(&dev->knode_parent); 367 klist_del(&dev->knode_parent);
368 device_remove_file(dev, &dev->uevent_attr);
352 369
353 /* Notify the platform of the removal, in case they 370 /* Notify the platform of the removal, in case they
354 * need to do anything... 371 * need to do anything...
@@ -390,11 +407,11 @@ static struct device * next_device(struct klist_iter * i)
390 407
391/** 408/**
392 * device_for_each_child - device child iterator. 409 * device_for_each_child - device child iterator.
393 * @dev: parent struct device. 410 * @parent: parent struct device.
394 * @data: data for the callback. 411 * @data: data for the callback.
395 * @fn: function to be called for each device. 412 * @fn: function to be called for each device.
396 * 413 *
397 * Iterate over @dev's child devices, and call @fn for each, 414 * Iterate over @parent's child devices, and call @fn for each,
398 * passing it @data. 415 * passing it @data.
399 * 416 *
400 * We check the return of @fn each time. If it returns anything 417 * We check the return of @fn each time. If it returns anything
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index b79badd0f158..a95844790f7b 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -9,12 +9,15 @@
9#include <linux/topology.h> 9#include <linux/topology.h>
10#include <linux/device.h> 10#include <linux/device.h>
11 11
12#include "base.h"
12 13
13struct sysdev_class cpu_sysdev_class = { 14struct sysdev_class cpu_sysdev_class = {
14 set_kset_name("cpu"), 15 set_kset_name("cpu"),
15}; 16};
16EXPORT_SYMBOL(cpu_sysdev_class); 17EXPORT_SYMBOL(cpu_sysdev_class);
17 18
19static struct sys_device *cpu_sys_devices[NR_CPUS];
20
18#ifdef CONFIG_HOTPLUG_CPU 21#ifdef CONFIG_HOTPLUG_CPU
19int __attribute__((weak)) smp_prepare_cpu (int cpu) 22int __attribute__((weak)) smp_prepare_cpu (int cpu)
20{ 23{
@@ -63,6 +66,7 @@ static void __devinit register_cpu_control(struct cpu *cpu)
63} 66}
64void unregister_cpu(struct cpu *cpu, struct node *root) 67void unregister_cpu(struct cpu *cpu, struct node *root)
65{ 68{
69 int logical_cpu = cpu->sysdev.id;
66 70
67 if (root) 71 if (root)
68 sysfs_remove_link(&root->sysdev.kobj, 72 sysfs_remove_link(&root->sysdev.kobj,
@@ -70,7 +74,7 @@ void unregister_cpu(struct cpu *cpu, struct node *root)
70 sysdev_remove_file(&cpu->sysdev, &attr_online); 74 sysdev_remove_file(&cpu->sysdev, &attr_online);
71 75
72 sysdev_unregister(&cpu->sysdev); 76 sysdev_unregister(&cpu->sysdev);
73 77 cpu_sys_devices[logical_cpu] = NULL;
74 return; 78 return;
75} 79}
76#else /* ... !CONFIG_HOTPLUG_CPU */ 80#else /* ... !CONFIG_HOTPLUG_CPU */
@@ -102,10 +106,19 @@ int __devinit register_cpu(struct cpu *cpu, int num, struct node *root)
102 kobject_name(&cpu->sysdev.kobj)); 106 kobject_name(&cpu->sysdev.kobj));
103 if (!error && !cpu->no_control) 107 if (!error && !cpu->no_control)
104 register_cpu_control(cpu); 108 register_cpu_control(cpu);
109 if (!error)
110 cpu_sys_devices[num] = &cpu->sysdev;
105 return error; 111 return error;
106} 112}
107 113
108 114struct sys_device *get_cpu_sysdev(int cpu)
115{
116 if (cpu < NR_CPUS)
117 return cpu_sys_devices[cpu];
118 else
119 return NULL;
120}
121EXPORT_SYMBOL_GPL(get_cpu_sysdev);
109 122
110int __init cpu_dev_init(void) 123int __init cpu_dev_init(void)
111{ 124{
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index ef3fe513e398..161f3a390d90 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -28,6 +28,7 @@ static struct device * next_device(struct klist_iter * i)
28/** 28/**
29 * driver_for_each_device - Iterator for devices bound to a driver. 29 * driver_for_each_device - Iterator for devices bound to a driver.
30 * @drv: Driver we're iterating. 30 * @drv: Driver we're iterating.
31 * @start: Device to begin with
31 * @data: Data to pass to the callback. 32 * @data: Data to pass to the callback.
32 * @fn: Function to call for each device. 33 * @fn: Function to call for each device.
33 * 34 *
@@ -57,7 +58,7 @@ EXPORT_SYMBOL_GPL(driver_for_each_device);
57 58
58/** 59/**
59 * driver_find_device - device iterator for locating a particular device. 60 * driver_find_device - device iterator for locating a particular device.
60 * @driver: The device's driver 61 * @drv: The device's driver
61 * @start: Device to begin with 62 * @start: Device to begin with
62 * @data: Data to pass to match function 63 * @data: Data to pass to match function
63 * @match: Callback function to check device 64 * @match: Callback function to check device
diff --git a/drivers/base/firmware.c b/drivers/base/firmware.c
index 88ab044932f2..cb1b98ae0d58 100644
--- a/drivers/base/firmware.c
+++ b/drivers/base/firmware.c
@@ -11,6 +11,9 @@
11#include <linux/kobject.h> 11#include <linux/kobject.h>
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/device.h>
15
16#include "base.h"
14 17
15static decl_subsys(firmware, NULL, NULL); 18static decl_subsys(firmware, NULL, NULL);
16 19
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 4acb2c5733c3..98f6c02d6790 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -62,14 +62,16 @@ firmware_timeout_show(struct class *class, char *buf)
62} 62}
63 63
64/** 64/**
65 * firmware_timeout_store: 65 * firmware_timeout_store - set number of seconds to wait for firmware
66 * Description: 66 * @class: device class pointer
67 * @buf: buffer to scan for timeout value
68 * @count: number of bytes in @buf
69 *
67 * Sets the number of seconds to wait for the firmware. Once 70 * Sets the number of seconds to wait for the firmware. Once
68 * this expires an error will be return to the driver and no 71 * this expires an error will be returned to the driver and no
69 * firmware will be provided. 72 * firmware will be provided.
70 * 73 *
71 * Note: zero means 'wait for ever' 74 * Note: zero means 'wait forever'.
72 *
73 **/ 75 **/
74static ssize_t 76static ssize_t
75firmware_timeout_store(struct class *class, const char *buf, size_t count) 77firmware_timeout_store(struct class *class, const char *buf, size_t count)
@@ -123,12 +125,15 @@ firmware_loading_show(struct class_device *class_dev, char *buf)
123} 125}
124 126
125/** 127/**
126 * firmware_loading_store: - loading control file 128 * firmware_loading_store - set value in the 'loading' control file
127 * Description: 129 * @class_dev: class_device pointer
130 * @buf: buffer to scan for loading control value
131 * @count: number of bytes in @buf
132 *
128 * The relevant values are: 133 * The relevant values are:
129 * 134 *
130 * 1: Start a load, discarding any previous partial load. 135 * 1: Start a load, discarding any previous partial load.
131 * 0: Conclude the load and handle the data to the driver code. 136 * 0: Conclude the load and hand the data to the driver code.
132 * -1: Conclude the load with an error and discard any written data. 137 * -1: Conclude the load with an error and discard any written data.
133 **/ 138 **/
134static ssize_t 139static ssize_t
@@ -201,6 +206,7 @@ out:
201 up(&fw_lock); 206 up(&fw_lock);
202 return ret_count; 207 return ret_count;
203} 208}
209
204static int 210static int
205fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size) 211fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size)
206{ 212{
@@ -227,11 +233,13 @@ fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size)
227} 233}
228 234
229/** 235/**
230 * firmware_data_write: 236 * firmware_data_write - write method for firmware
237 * @kobj: kobject for the class_device
238 * @buffer: buffer being written
239 * @offset: buffer offset for write in total data store area
240 * @count: buffer size
231 * 241 *
232 * Description: 242 * Data written to the 'data' attribute will be later handed to
233 *
234 * Data written to the 'data' attribute will be later handled to
235 * the driver as a firmware image. 243 * the driver as a firmware image.
236 **/ 244 **/
237static ssize_t 245static ssize_t
@@ -264,6 +272,7 @@ out:
264 up(&fw_lock); 272 up(&fw_lock);
265 return retval; 273 return retval;
266} 274}
275
267static struct bin_attribute firmware_attr_data_tmpl = { 276static struct bin_attribute firmware_attr_data_tmpl = {
268 .attr = {.name = "data", .mode = 0644, .owner = THIS_MODULE}, 277 .attr = {.name = "data", .mode = 0644, .owner = THIS_MODULE},
269 .size = 0, 278 .size = 0,
@@ -448,13 +457,16 @@ out:
448 457
449/** 458/**
450 * request_firmware: - request firmware to hotplug and wait for it 459 * request_firmware: - request firmware to hotplug and wait for it
451 * Description: 460 * @firmware_p: pointer to firmware image
452 * @firmware will be used to return a firmware image by the name 461 * @name: name of firmware file
462 * @device: device for which firmware is being loaded
463 *
464 * @firmware_p will be used to return a firmware image by the name
453 * of @name for device @device. 465 * of @name for device @device.
454 * 466 *
455 * Should be called from user context where sleeping is allowed. 467 * Should be called from user context where sleeping is allowed.
456 * 468 *
457 * @name will be use as $FIRMWARE in the hotplug environment and 469 * @name will be used as $FIRMWARE in the hotplug environment and
458 * should be distinctive enough not to be confused with any other 470 * should be distinctive enough not to be confused with any other
459 * firmware image for this or any other device. 471 * firmware image for this or any other device.
460 **/ 472 **/
@@ -468,6 +480,7 @@ request_firmware(const struct firmware **firmware_p, const char *name,
468 480
469/** 481/**
470 * release_firmware: - release the resource associated with a firmware image 482 * release_firmware: - release the resource associated with a firmware image
483 * @fw: firmware resource to release
471 **/ 484 **/
472void 485void
473release_firmware(const struct firmware *fw) 486release_firmware(const struct firmware *fw)
@@ -480,8 +493,10 @@ release_firmware(const struct firmware *fw)
480 493
481/** 494/**
482 * register_firmware: - provide a firmware image for later usage 495 * register_firmware: - provide a firmware image for later usage
496 * @name: name of firmware image file
497 * @data: buffer pointer for the firmware image
498 * @size: size of the data buffer area
483 * 499 *
484 * Description:
485 * Make sure that @data will be available by requesting firmware @name. 500 * Make sure that @data will be available by requesting firmware @name.
486 * 501 *
487 * Note: This will not be possible until some kind of persistence 502 * Note: This will not be possible until some kind of persistence
@@ -526,21 +541,19 @@ request_firmware_work_func(void *arg)
526} 541}
527 542
528/** 543/**
529 * request_firmware_nowait: 544 * request_firmware_nowait: asynchronous version of request_firmware
545 * @module: module requesting the firmware
546 * @hotplug: invokes hotplug event to copy the firmware image if this flag
547 * is non-zero else the firmware copy must be done manually.
548 * @name: name of firmware file
549 * @device: device for which firmware is being loaded
550 * @context: will be passed over to @cont, and
551 * @fw may be %NULL if firmware request fails.
552 * @cont: function will be called asynchronously when the firmware
553 * request is over.
530 * 554 *
531 * Description:
532 * Asynchronous variant of request_firmware() for contexts where 555 * Asynchronous variant of request_firmware() for contexts where
533 * it is not possible to sleep. 556 * it is not possible to sleep.
534 *
535 * @hotplug invokes hotplug event to copy the firmware image if this flag
536 * is non-zero else the firmware copy must be done manually.
537 *
538 * @cont will be called asynchronously when the firmware request is over.
539 *
540 * @context will be passed over to @cont.
541 *
542 * @fw may be %NULL if firmware request fails.
543 *
544 **/ 557 **/
545int 558int
546request_firmware_nowait( 559request_firmware_nowait(
diff --git a/drivers/base/init.c b/drivers/base/init.c
index a76ae5a221f3..c648914b9cde 100644
--- a/drivers/base/init.c
+++ b/drivers/base/init.c
@@ -9,15 +9,10 @@
9 9
10#include <linux/device.h> 10#include <linux/device.h>
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/memory.h>
13
14#include "base.h"
12 15
13extern int devices_init(void);
14extern int buses_init(void);
15extern int classes_init(void);
16extern int firmware_init(void);
17extern int platform_bus_init(void);
18extern int system_bus_init(void);
19extern int cpu_dev_init(void);
20extern int attribute_container_init(void);
21/** 16/**
22 * driver_init - initialize driver model. 17 * driver_init - initialize driver model.
23 * 18 *
@@ -39,5 +34,6 @@ void __init driver_init(void)
39 platform_bus_init(); 34 platform_bus_init();
40 system_bus_init(); 35 system_bus_init();
41 cpu_dev_init(); 36 cpu_dev_init();
37 memory_dev_init();
42 attribute_container_init(); 38 attribute_container_init();
43} 39}
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
new file mode 100644
index 000000000000..b7ddd651d664
--- /dev/null
+++ b/drivers/base/memory.c
@@ -0,0 +1,452 @@
1/*
2 * drivers/base/memory.c - basic Memory class support
3 *
4 * Written by Matt Tolentino <matthew.e.tolentino@intel.com>
5 * Dave Hansen <haveblue@us.ibm.com>
6 *
7 * This file provides the necessary infrastructure to represent
8 * a SPARSEMEM-memory-model system's physical memory in /sysfs.
9 * All arch-independent code that assumes MEMORY_HOTPLUG requires
10 * SPARSEMEM should be contained here, or in mm/memory_hotplug.c.
11 */
12
13#include <linux/sysdev.h>
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/sched.h> /* capable() */
17#include <linux/topology.h>
18#include <linux/device.h>
19#include <linux/memory.h>
20#include <linux/kobject.h>
21#include <linux/memory_hotplug.h>
22#include <linux/mm.h>
23#include <asm/atomic.h>
24#include <asm/uaccess.h>
25
26#define MEMORY_CLASS_NAME "memory"
27
28static struct sysdev_class memory_sysdev_class = {
29 set_kset_name(MEMORY_CLASS_NAME),
30};
31EXPORT_SYMBOL(memory_sysdev_class);
32
33static char *memory_hotplug_name(struct kset *kset, struct kobject *kobj)
34{
35 return MEMORY_CLASS_NAME;
36}
37
38static int memory_hotplug(struct kset *kset, struct kobject *kobj, char **envp,
39 int num_envp, char *buffer, int buffer_size)
40{
41 int retval = 0;
42
43 return retval;
44}
45
46static struct kset_hotplug_ops memory_hotplug_ops = {
47 .name = memory_hotplug_name,
48 .hotplug = memory_hotplug,
49};
50
51static struct notifier_block *memory_chain;
52
53static int register_memory_notifier(struct notifier_block *nb)
54{
55 return notifier_chain_register(&memory_chain, nb);
56}
57
58static void unregister_memory_notifier(struct notifier_block *nb)
59{
60 notifier_chain_unregister(&memory_chain, nb);
61}
62
63/*
64 * register_memory - Setup a sysfs device for a memory block
65 */
66static int
67register_memory(struct memory_block *memory, struct mem_section *section,
68 struct node *root)
69{
70 int error;
71
72 memory->sysdev.cls = &memory_sysdev_class;
73 memory->sysdev.id = __section_nr(section);
74
75 error = sysdev_register(&memory->sysdev);
76
77 if (root && !error)
78 error = sysfs_create_link(&root->sysdev.kobj,
79 &memory->sysdev.kobj,
80 kobject_name(&memory->sysdev.kobj));
81
82 return error;
83}
84
85static void
86unregister_memory(struct memory_block *memory, struct mem_section *section,
87 struct node *root)
88{
89 BUG_ON(memory->sysdev.cls != &memory_sysdev_class);
90 BUG_ON(memory->sysdev.id != __section_nr(section));
91
92 sysdev_unregister(&memory->sysdev);
93 if (root)
94 sysfs_remove_link(&root->sysdev.kobj,
95 kobject_name(&memory->sysdev.kobj));
96}
97
98/*
99 * use this as the physical section index that this memsection
100 * uses.
101 */
102
103static ssize_t show_mem_phys_index(struct sys_device *dev, char *buf)
104{
105 struct memory_block *mem =
106 container_of(dev, struct memory_block, sysdev);
107 return sprintf(buf, "%08lx\n", mem->phys_index);
108}
109
110/*
111 * online, offline, going offline, etc.
112 */
113static ssize_t show_mem_state(struct sys_device *dev, char *buf)
114{
115 struct memory_block *mem =
116 container_of(dev, struct memory_block, sysdev);
117 ssize_t len = 0;
118
119 /*
120 * We can probably put these states in a nice little array
121 * so that they're not open-coded
122 */
123 switch (mem->state) {
124 case MEM_ONLINE:
125 len = sprintf(buf, "online\n");
126 break;
127 case MEM_OFFLINE:
128 len = sprintf(buf, "offline\n");
129 break;
130 case MEM_GOING_OFFLINE:
131 len = sprintf(buf, "going-offline\n");
132 break;
133 default:
134 len = sprintf(buf, "ERROR-UNKNOWN-%ld\n",
135 mem->state);
136 WARN_ON(1);
137 break;
138 }
139
140 return len;
141}
142
143static inline int memory_notify(unsigned long val, void *v)
144{
145 return notifier_call_chain(&memory_chain, val, v);
146}
147
148/*
149 * MEMORY_HOTPLUG depends on SPARSEMEM in mm/Kconfig, so it is
150 * OK to have direct references to sparsemem variables in here.
151 */
152static int
153memory_block_action(struct memory_block *mem, unsigned long action)
154{
155 int i;
156 unsigned long psection;
157 unsigned long start_pfn, start_paddr;
158 struct page *first_page;
159 int ret;
160 int old_state = mem->state;
161
162 psection = mem->phys_index;
163 first_page = pfn_to_page(psection << PFN_SECTION_SHIFT);
164
165 /*
166 * The probe routines leave the pages reserved, just
167 * as the bootmem code does. Make sure they're still
168 * that way.
169 */
170 if (action == MEM_ONLINE) {
171 for (i = 0; i < PAGES_PER_SECTION; i++) {
172 if (PageReserved(first_page+i))
173 continue;
174
175 printk(KERN_WARNING "section number %ld page number %d "
176 "not reserved, was it already online? \n",
177 psection, i);
178 return -EBUSY;
179 }
180 }
181
182 switch (action) {
183 case MEM_ONLINE:
184 start_pfn = page_to_pfn(first_page);
185 ret = online_pages(start_pfn, PAGES_PER_SECTION);
186 break;
187 case MEM_OFFLINE:
188 mem->state = MEM_GOING_OFFLINE;
189 memory_notify(MEM_GOING_OFFLINE, NULL);
190 start_paddr = page_to_pfn(first_page) << PAGE_SHIFT;
191 ret = remove_memory(start_paddr,
192 PAGES_PER_SECTION << PAGE_SHIFT);
193 if (ret) {
194 mem->state = old_state;
195 break;
196 }
197 memory_notify(MEM_MAPPING_INVALID, NULL);
198 break;
199 default:
200 printk(KERN_WARNING "%s(%p, %ld) unknown action: %ld\n",
201 __FUNCTION__, mem, action, action);
202 WARN_ON(1);
203 ret = -EINVAL;
204 }
205 /*
206 * For now, only notify on successful memory operations
207 */
208 if (!ret)
209 memory_notify(action, NULL);
210
211 return ret;
212}
213
214static int memory_block_change_state(struct memory_block *mem,
215 unsigned long to_state, unsigned long from_state_req)
216{
217 int ret = 0;
218 down(&mem->state_sem);
219
220 if (mem->state != from_state_req) {
221 ret = -EINVAL;
222 goto out;
223 }
224
225 ret = memory_block_action(mem, to_state);
226 if (!ret)
227 mem->state = to_state;
228
229out:
230 up(&mem->state_sem);
231 return ret;
232}
233
234static ssize_t
235store_mem_state(struct sys_device *dev, const char *buf, size_t count)
236{
237 struct memory_block *mem;
238 unsigned int phys_section_nr;
239 int ret = -EINVAL;
240
241 mem = container_of(dev, struct memory_block, sysdev);
242 phys_section_nr = mem->phys_index;
243
244 if (!valid_section_nr(phys_section_nr))
245 goto out;
246
247 if (!strncmp(buf, "online", min((int)count, 6)))
248 ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE);
249 else if(!strncmp(buf, "offline", min((int)count, 7)))
250 ret = memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE);
251out:
252 if (ret)
253 return ret;
254 return count;
255}
256
257/*
258 * phys_device is a bad name for this. What I really want
259 * is a way to differentiate between memory ranges that
260 * are part of physical devices that constitute
261 * a complete removable unit or fru.
262 * i.e. do these ranges belong to the same physical device,
263 * s.t. if I offline all of these sections I can then
264 * remove the physical device?
265 */
266static ssize_t show_phys_device(struct sys_device *dev, char *buf)
267{
268 struct memory_block *mem =
269 container_of(dev, struct memory_block, sysdev);
270 return sprintf(buf, "%d\n", mem->phys_device);
271}
272
273static SYSDEV_ATTR(phys_index, 0444, show_mem_phys_index, NULL);
274static SYSDEV_ATTR(state, 0644, show_mem_state, store_mem_state);
275static SYSDEV_ATTR(phys_device, 0444, show_phys_device, NULL);
276
277#define mem_create_simple_file(mem, attr_name) \
278 sysdev_create_file(&mem->sysdev, &attr_##attr_name)
279#define mem_remove_simple_file(mem, attr_name) \
280 sysdev_remove_file(&mem->sysdev, &attr_##attr_name)
281
282/*
283 * Block size attribute stuff
284 */
285static ssize_t
286print_block_size(struct class *class, char *buf)
287{
288 return sprintf(buf, "%lx\n", (unsigned long)PAGES_PER_SECTION * PAGE_SIZE);
289}
290
291static CLASS_ATTR(block_size_bytes, 0444, print_block_size, NULL);
292
293static int block_size_init(void)
294{
295 sysfs_create_file(&memory_sysdev_class.kset.kobj,
296 &class_attr_block_size_bytes.attr);
297 return 0;
298}
299
300/*
301 * Some architectures will have custom drivers to do this, and
302 * will not need to do it from userspace. The fake hot-add code
303 * as well as ppc64 will do all of their discovery in userspace
304 * and will require this interface.
305 */
306#ifdef CONFIG_ARCH_MEMORY_PROBE
307static ssize_t
308memory_probe_store(struct class *class, const char __user *buf, size_t count)
309{
310 u64 phys_addr;
311 int ret;
312
313 phys_addr = simple_strtoull(buf, NULL, 0);
314
315 ret = add_memory(phys_addr, PAGES_PER_SECTION << PAGE_SHIFT);
316
317 if (ret)
318 count = ret;
319
320 return count;
321}
322static CLASS_ATTR(probe, 0700, NULL, memory_probe_store);
323
324static int memory_probe_init(void)
325{
326 sysfs_create_file(&memory_sysdev_class.kset.kobj,
327 &class_attr_probe.attr);
328 return 0;
329}
330#else
331#define memory_probe_init(...) do {} while (0)
332#endif
333
334/*
335 * Note that phys_device is optional. It is here to allow for
336 * differentiation between which *physical* devices each
337 * section belongs to...
338 */
339
340static int add_memory_block(unsigned long node_id, struct mem_section *section,
341 unsigned long state, int phys_device)
342{
343 struct memory_block *mem = kzalloc(sizeof(*mem), GFP_KERNEL);
344 int ret = 0;
345
346 if (!mem)
347 return -ENOMEM;
348
349 mem->phys_index = __section_nr(section);
350 mem->state = state;
351 init_MUTEX(&mem->state_sem);
352 mem->phys_device = phys_device;
353
354 ret = register_memory(mem, section, NULL);
355 if (!ret)
356 ret = mem_create_simple_file(mem, phys_index);
357 if (!ret)
358 ret = mem_create_simple_file(mem, state);
359 if (!ret)
360 ret = mem_create_simple_file(mem, phys_device);
361
362 return ret;
363}
364
365/*
366 * For now, we have a linear search to go find the appropriate
367 * memory_block corresponding to a particular phys_index. If
368 * this gets to be a real problem, we can always use a radix
369 * tree or something here.
370 *
371 * This could be made generic for all sysdev classes.
372 */
373static struct memory_block *find_memory_block(struct mem_section *section)
374{
375 struct kobject *kobj;
376 struct sys_device *sysdev;
377 struct memory_block *mem;
378 char name[sizeof(MEMORY_CLASS_NAME) + 9 + 1];
379
380 /*
381 * This only works because we know that section == sysdev->id
382 * slightly redundant with sysdev_register()
383 */
384 sprintf(&name[0], "%s%d", MEMORY_CLASS_NAME, __section_nr(section));
385
386 kobj = kset_find_obj(&memory_sysdev_class.kset, name);
387 if (!kobj)
388 return NULL;
389
390 sysdev = container_of(kobj, struct sys_device, kobj);
391 mem = container_of(sysdev, struct memory_block, sysdev);
392
393 return mem;
394}
395
396int remove_memory_block(unsigned long node_id, struct mem_section *section,
397 int phys_device)
398{
399 struct memory_block *mem;
400
401 mem = find_memory_block(section);
402 mem_remove_simple_file(mem, phys_index);
403 mem_remove_simple_file(mem, state);
404 mem_remove_simple_file(mem, phys_device);
405 unregister_memory(mem, section, NULL);
406
407 return 0;
408}
409
410/*
411 * need an interface for the VM to add new memory regions,
412 * but without onlining it.
413 */
414int register_new_memory(struct mem_section *section)
415{
416 return add_memory_block(0, section, MEM_OFFLINE, 0);
417}
418
419int unregister_memory_section(struct mem_section *section)
420{
421 if (!valid_section(section))
422 return -EINVAL;
423
424 return remove_memory_block(0, section, 0);
425}
426
427/*
428 * Initialize the sysfs support for memory devices...
429 */
430int __init memory_dev_init(void)
431{
432 unsigned int i;
433 int ret;
434
435 memory_sysdev_class.kset.hotplug_ops = &memory_hotplug_ops;
436 ret = sysdev_class_register(&memory_sysdev_class);
437
438 /*
439 * Create entries for memory sections that were found
440 * during boot and have been initialized
441 */
442 for (i = 0; i < NR_MEM_SECTIONS; i++) {
443 if (!valid_section_nr(i))
444 continue;
445 add_memory_block(0, __nr_to_section(i), MEM_ONLINE, 0);
446 }
447
448 memory_probe_init();
449 block_size_init();
450
451 return ret;
452}
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 361e204209eb..08d9cc99c7de 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -16,6 +16,9 @@
16#include <linux/dma-mapping.h> 16#include <linux/dma-mapping.h>
17#include <linux/bootmem.h> 17#include <linux/bootmem.h>
18#include <linux/err.h> 18#include <linux/err.h>
19#include <linux/slab.h>
20
21#include "base.h"
19 22
20struct device platform_bus = { 23struct device platform_bus = {
21 .bus_id = "platform", 24 .bus_id = "platform",
@@ -279,13 +282,9 @@ static int platform_suspend(struct device * dev, pm_message_t state)
279{ 282{
280 int ret = 0; 283 int ret = 0;
281 284
282 if (dev->driver && dev->driver->suspend) { 285 if (dev->driver && dev->driver->suspend)
283 ret = dev->driver->suspend(dev, state, SUSPEND_DISABLE); 286 ret = dev->driver->suspend(dev, state);
284 if (ret == 0) 287
285 ret = dev->driver->suspend(dev, state, SUSPEND_SAVE_STATE);
286 if (ret == 0)
287 ret = dev->driver->suspend(dev, state, SUSPEND_POWER_DOWN);
288 }
289 return ret; 288 return ret;
290} 289}
291 290
@@ -293,13 +292,9 @@ static int platform_resume(struct device * dev)
293{ 292{
294 int ret = 0; 293 int ret = 0;
295 294
296 if (dev->driver && dev->driver->resume) { 295 if (dev->driver && dev->driver->resume)
297 ret = dev->driver->resume(dev, RESUME_POWER_ON); 296 ret = dev->driver->resume(dev);
298 if (ret == 0) 297
299 ret = dev->driver->resume(dev, RESUME_RESTORE_STATE);
300 if (ret == 0)
301 ret = dev->driver->resume(dev, RESUME_ENABLE);
302 }
303 return ret; 298 return ret;
304} 299}
305 300
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 15e6a8f951f1..0d2e101e4f15 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -30,23 +30,6 @@ LIST_HEAD(dpm_off_irq);
30DECLARE_MUTEX(dpm_sem); 30DECLARE_MUTEX(dpm_sem);
31DECLARE_MUTEX(dpm_list_sem); 31DECLARE_MUTEX(dpm_list_sem);
32 32
33/*
34 * PM Reference Counting.
35 */
36
37static inline void device_pm_hold(struct device * dev)
38{
39 if (dev)
40 atomic_inc(&dev->power.pm_users);
41}
42
43static inline void device_pm_release(struct device * dev)
44{
45 if (dev)
46 atomic_dec(&dev->power.pm_users);
47}
48
49
50/** 33/**
51 * device_pm_set_parent - Specify power dependency. 34 * device_pm_set_parent - Specify power dependency.
52 * @dev: Device who needs power. 35 * @dev: Device who needs power.
@@ -62,10 +45,8 @@ static inline void device_pm_release(struct device * dev)
62 45
63void device_pm_set_parent(struct device * dev, struct device * parent) 46void device_pm_set_parent(struct device * dev, struct device * parent)
64{ 47{
65 struct device * old_parent = dev->power.pm_parent; 48 put_device(dev->power.pm_parent);
66 device_pm_release(old_parent); 49 dev->power.pm_parent = get_device(parent);
67 dev->power.pm_parent = parent;
68 device_pm_hold(parent);
69} 50}
70EXPORT_SYMBOL_GPL(device_pm_set_parent); 51EXPORT_SYMBOL_GPL(device_pm_set_parent);
71 52
@@ -75,7 +56,6 @@ int device_pm_add(struct device * dev)
75 56
76 pr_debug("PM: Adding info for %s:%s\n", 57 pr_debug("PM: Adding info for %s:%s\n",
77 dev->bus ? dev->bus->name : "No Bus", dev->kobj.name); 58 dev->bus ? dev->bus->name : "No Bus", dev->kobj.name);
78 atomic_set(&dev->power.pm_users, 0);
79 down(&dpm_list_sem); 59 down(&dpm_list_sem);
80 list_add_tail(&dev->power.entry, &dpm_active); 60 list_add_tail(&dev->power.entry, &dpm_active);
81 device_pm_set_parent(dev, dev->parent); 61 device_pm_set_parent(dev, dev->parent);
@@ -91,7 +71,7 @@ void device_pm_remove(struct device * dev)
91 dev->bus ? dev->bus->name : "No Bus", dev->kobj.name); 71 dev->bus ? dev->bus->name : "No Bus", dev->kobj.name);
92 down(&dpm_list_sem); 72 down(&dpm_list_sem);
93 dpm_sysfs_remove(dev); 73 dpm_sysfs_remove(dev);
94 device_pm_release(dev->power.pm_parent); 74 put_device(dev->power.pm_parent);
95 list_del_init(&dev->power.entry); 75 list_del_init(&dev->power.entry);
96 up(&dpm_list_sem); 76 up(&dpm_list_sem);
97} 77}
diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
index 2e700d795cf1..fb3d35a9e101 100644
--- a/drivers/base/power/power.h
+++ b/drivers/base/power/power.h
@@ -67,9 +67,6 @@ extern int suspend_device(struct device *, pm_message_t);
67 * runtime.c 67 * runtime.c
68 */ 68 */
69 69
70extern int dpm_runtime_suspend(struct device *, pm_message_t);
71extern void dpm_runtime_resume(struct device *);
72
73#else /* CONFIG_PM */ 70#else /* CONFIG_PM */
74 71
75 72
@@ -82,14 +79,4 @@ static inline void device_pm_remove(struct device * dev)
82 79
83} 80}
84 81
85static inline int dpm_runtime_suspend(struct device * dev, pm_message_t state)
86{
87 return 0;
88}
89
90static inline void dpm_runtime_resume(struct device * dev)
91{
92
93}
94
95#endif 82#endif
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index e8f0519f5dfa..adbc3148c039 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -36,6 +36,7 @@ void dpm_runtime_resume(struct device * dev)
36 runtime_resume(dev); 36 runtime_resume(dev);
37 up(&dpm_sem); 37 up(&dpm_sem);
38} 38}
39EXPORT_SYMBOL(dpm_runtime_resume);
39 40
40 41
41/** 42/**
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index 8d04fb435c17..89c57875f3e5 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -48,8 +48,81 @@ static ssize_t state_store(struct device * dev, struct device_attribute *attr, c
48static DEVICE_ATTR(state, 0644, state_show, state_store); 48static DEVICE_ATTR(state, 0644, state_show, state_store);
49 49
50 50
51/*
52 * wakeup - Report/change current wakeup option for device
53 *
54 * Some devices support "wakeup" events, which are hardware signals
55 * used to activate devices from suspended or low power states. Such
56 * devices have one of three values for the sysfs power/wakeup file:
57 *
58 * + "enabled\n" to issue the events;
59 * + "disabled\n" not to do so; or
60 * + "\n" for temporary or permanent inability to issue wakeup.
61 *
62 * (For example, unconfigured USB devices can't issue wakeups.)
63 *
64 * Familiar examples of devices that can issue wakeup events include
65 * keyboards and mice (both PS2 and USB styles), power buttons, modems,
66 * "Wake-On-LAN" Ethernet links, GPIO lines, and more. Some events
67 * will wake the entire system from a suspend state; others may just
68 * wake up the device (if the system as a whole is already active).
69 * Some wakeup events use normal IRQ lines; other use special out
70 * of band signaling.
71 *
72 * It is the responsibility of device drivers to enable (or disable)
73 * wakeup signaling as part of changing device power states, respecting
74 * the policy choices provided through the driver model.
75 *
76 * Devices may not be able to generate wakeup events from all power
77 * states. Also, the events may be ignored in some configurations;
78 * for example, they might need help from other devices that aren't
79 * active, or which may have wakeup disabled. Some drivers rely on
80 * wakeup events internally (unless they are disabled), keeping
81 * their hardware in low power modes whenever they're unused. This
82 * saves runtime power, without requiring system-wide sleep states.
83 */
84
85static const char enabled[] = "enabled";
86static const char disabled[] = "disabled";
87
88static ssize_t
89wake_show(struct device * dev, struct device_attribute *attr, char * buf)
90{
91 return sprintf(buf, "%s\n", device_can_wakeup(dev)
92 ? (device_may_wakeup(dev) ? enabled : disabled)
93 : "");
94}
95
96static ssize_t
97wake_store(struct device * dev, struct device_attribute *attr,
98 const char * buf, size_t n)
99{
100 char *cp;
101 int len = n;
102
103 if (!device_can_wakeup(dev))
104 return -EINVAL;
105
106 cp = memchr(buf, '\n', n);
107 if (cp)
108 len = cp - buf;
109 if (len == sizeof enabled - 1
110 && strncmp(buf, enabled, sizeof enabled - 1) == 0)
111 device_set_wakeup_enable(dev, 1);
112 else if (len == sizeof disabled - 1
113 && strncmp(buf, disabled, sizeof disabled - 1) == 0)
114 device_set_wakeup_enable(dev, 0);
115 else
116 return -EINVAL;
117 return n;
118}
119
120static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store);
121
122
51static struct attribute * power_attrs[] = { 123static struct attribute * power_attrs[] = {
52 &dev_attr_state.attr, 124 &dev_attr_state.attr,
125 &dev_attr_wakeup.attr,
53 NULL, 126 NULL,
54}; 127};
55static struct attribute_group pm_attr_group = { 128static struct attribute_group pm_attr_group = {
diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index 3431eb6004c3..66ed8f2fece5 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -21,6 +21,7 @@
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/string.h> 22#include <linux/string.h>
23#include <linux/pm.h> 23#include <linux/pm.h>
24#include <asm/semaphore.h>
24 25
25extern struct subsystem devices_subsys; 26extern struct subsystem devices_subsys;
26 27
diff --git a/drivers/block/Kconfig.iosched b/drivers/block/Kconfig.iosched
index 6070a480600b..5b90d2fa63b8 100644
--- a/drivers/block/Kconfig.iosched
+++ b/drivers/block/Kconfig.iosched
@@ -38,4 +38,32 @@ config IOSCHED_CFQ
38 among all processes in the system. It should provide a fair 38 among all processes in the system. It should provide a fair
39 working environment, suitable for desktop systems. 39 working environment, suitable for desktop systems.
40 40
41choice
42 prompt "Default I/O scheduler"
43 default DEFAULT_AS
44 help
45 Select the I/O scheduler which will be used by default for all
46 block devices.
47
48 config DEFAULT_AS
49 bool "Anticipatory" if IOSCHED_AS
50
51 config DEFAULT_DEADLINE
52 bool "Deadline" if IOSCHED_DEADLINE
53
54 config DEFAULT_CFQ
55 bool "CFQ" if IOSCHED_CFQ
56
57 config DEFAULT_NOOP
58 bool "No-op"
59
60endchoice
61
62config DEFAULT_IOSCHED
63 string
64 default "anticipatory" if DEFAULT_AS
65 default "deadline" if DEFAULT_DEADLINE
66 default "cfq" if DEFAULT_CFQ
67 default "noop" if DEFAULT_NOOP
68
41endmenu 69endmenu
diff --git a/drivers/block/aoe/aoe.h b/drivers/block/aoe/aoe.h
index 0e9e586e9ba3..881c48d941b7 100644
--- a/drivers/block/aoe/aoe.h
+++ b/drivers/block/aoe/aoe.h
@@ -1,5 +1,5 @@
1/* Copyright (c) 2004 Coraid, Inc. See COPYING for GPL terms. */ 1/* Copyright (c) 2004 Coraid, Inc. See COPYING for GPL terms. */
2#define VERSION "12" 2#define VERSION "14"
3#define AOE_MAJOR 152 3#define AOE_MAJOR 152
4#define DEVICE_NAME "aoe" 4#define DEVICE_NAME "aoe"
5 5
diff --git a/drivers/block/aoe/aoechr.c b/drivers/block/aoe/aoechr.c
index 45a243096187..41ae0ede619a 100644
--- a/drivers/block/aoe/aoechr.c
+++ b/drivers/block/aoe/aoechr.c
@@ -224,7 +224,7 @@ aoechr_init(void)
224 return PTR_ERR(aoe_class); 224 return PTR_ERR(aoe_class);
225 } 225 }
226 for (i = 0; i < ARRAY_SIZE(chardevs); ++i) 226 for (i = 0; i < ARRAY_SIZE(chardevs); ++i)
227 class_device_create(aoe_class, 227 class_device_create(aoe_class, NULL,
228 MKDEV(AOE_MAJOR, chardevs[i].minor), 228 MKDEV(AOE_MAJOR, chardevs[i].minor),
229 NULL, chardevs[i].name); 229 NULL, chardevs[i].name);
230 230
diff --git a/drivers/block/aoe/aoecmd.c b/drivers/block/aoe/aoecmd.c
index b5be4b7d7b5b..5c9c7c1a3d4c 100644
--- a/drivers/block/aoe/aoecmd.c
+++ b/drivers/block/aoe/aoecmd.c
@@ -8,6 +8,7 @@
8#include <linux/blkdev.h> 8#include <linux/blkdev.h>
9#include <linux/skbuff.h> 9#include <linux/skbuff.h>
10#include <linux/netdevice.h> 10#include <linux/netdevice.h>
11#include <asm/unaligned.h>
11#include "aoe.h" 12#include "aoe.h"
12 13
13#define TIMERTICK (HZ / 10) 14#define TIMERTICK (HZ / 10)
@@ -311,16 +312,16 @@ ataid_complete(struct aoedev *d, unsigned char *id)
311 u16 n; 312 u16 n;
312 313
313 /* word 83: command set supported */ 314 /* word 83: command set supported */
314 n = le16_to_cpup((__le16 *) &id[83<<1]); 315 n = le16_to_cpu(get_unaligned((__le16 *) &id[83<<1]));
315 316
316 /* word 86: command set/feature enabled */ 317 /* word 86: command set/feature enabled */
317 n |= le16_to_cpup((__le16 *) &id[86<<1]); 318 n |= le16_to_cpu(get_unaligned((__le16 *) &id[86<<1]));
318 319
319 if (n & (1<<10)) { /* bit 10: LBA 48 */ 320 if (n & (1<<10)) { /* bit 10: LBA 48 */
320 d->flags |= DEVFL_EXT; 321 d->flags |= DEVFL_EXT;
321 322
322 /* word 100: number lba48 sectors */ 323 /* word 100: number lba48 sectors */
323 ssize = le64_to_cpup((__le64 *) &id[100<<1]); 324 ssize = le64_to_cpu(get_unaligned((__le64 *) &id[100<<1]));
324 325
325 /* set as in ide-disk.c:init_idedisk_capacity */ 326 /* set as in ide-disk.c:init_idedisk_capacity */
326 d->geo.cylinders = ssize; 327 d->geo.cylinders = ssize;
@@ -331,12 +332,12 @@ ataid_complete(struct aoedev *d, unsigned char *id)
331 d->flags &= ~DEVFL_EXT; 332 d->flags &= ~DEVFL_EXT;
332 333
333 /* number lba28 sectors */ 334 /* number lba28 sectors */
334 ssize = le32_to_cpup((__le32 *) &id[60<<1]); 335 ssize = le32_to_cpu(get_unaligned((__le32 *) &id[60<<1]));
335 336
336 /* NOTE: obsolete in ATA 6 */ 337 /* NOTE: obsolete in ATA 6 */
337 d->geo.cylinders = le16_to_cpup((__le16 *) &id[54<<1]); 338 d->geo.cylinders = le16_to_cpu(get_unaligned((__le16 *) &id[54<<1]));
338 d->geo.heads = le16_to_cpup((__le16 *) &id[55<<1]); 339 d->geo.heads = le16_to_cpu(get_unaligned((__le16 *) &id[55<<1]));
339 d->geo.sectors = le16_to_cpup((__le16 *) &id[56<<1]); 340 d->geo.sectors = le16_to_cpu(get_unaligned((__le16 *) &id[56<<1]));
340 } 341 }
341 d->ssize = ssize; 342 d->ssize = ssize;
342 d->geo.start = 0; 343 d->geo.start = 0;
diff --git a/drivers/block/as-iosched.c b/drivers/block/as-iosched.c
index 95c0a3690b0f..c6744ff38294 100644
--- a/drivers/block/as-iosched.c
+++ b/drivers/block/as-iosched.c
@@ -98,7 +98,6 @@ struct as_data {
98 98
99 struct as_rq *next_arq[2]; /* next in sort order */ 99 struct as_rq *next_arq[2]; /* next in sort order */
100 sector_t last_sector[2]; /* last REQ_SYNC & REQ_ASYNC sectors */ 100 sector_t last_sector[2]; /* last REQ_SYNC & REQ_ASYNC sectors */
101 struct list_head *dispatch; /* driver dispatch queue */
102 struct list_head *hash; /* request hash */ 101 struct list_head *hash; /* request hash */
103 102
104 unsigned long exit_prob; /* probability a task will exit while 103 unsigned long exit_prob; /* probability a task will exit while
@@ -239,6 +238,25 @@ static struct io_context *as_get_io_context(void)
239 return ioc; 238 return ioc;
240} 239}
241 240
241static void as_put_io_context(struct as_rq *arq)
242{
243 struct as_io_context *aic;
244
245 if (unlikely(!arq->io_context))
246 return;
247
248 aic = arq->io_context->aic;
249
250 if (arq->is_sync == REQ_SYNC && aic) {
251 spin_lock(&aic->lock);
252 set_bit(AS_TASK_IORUNNING, &aic->state);
253 aic->last_end_request = jiffies;
254 spin_unlock(&aic->lock);
255 }
256
257 put_io_context(arq->io_context);
258}
259
242/* 260/*
243 * the back merge hash support functions 261 * the back merge hash support functions
244 */ 262 */
@@ -261,14 +279,6 @@ static inline void as_del_arq_hash(struct as_rq *arq)
261 __as_del_arq_hash(arq); 279 __as_del_arq_hash(arq);
262} 280}
263 281
264static void as_remove_merge_hints(request_queue_t *q, struct as_rq *arq)
265{
266 as_del_arq_hash(arq);
267
268 if (q->last_merge == arq->request)
269 q->last_merge = NULL;
270}
271
272static void as_add_arq_hash(struct as_data *ad, struct as_rq *arq) 282static void as_add_arq_hash(struct as_data *ad, struct as_rq *arq)
273{ 283{
274 struct request *rq = arq->request; 284 struct request *rq = arq->request;
@@ -312,7 +322,7 @@ static struct request *as_find_arq_hash(struct as_data *ad, sector_t offset)
312 BUG_ON(!arq->on_hash); 322 BUG_ON(!arq->on_hash);
313 323
314 if (!rq_mergeable(__rq)) { 324 if (!rq_mergeable(__rq)) {
315 as_remove_merge_hints(ad->q, arq); 325 as_del_arq_hash(arq);
316 continue; 326 continue;
317 } 327 }
318 328
@@ -950,23 +960,12 @@ static void as_completed_request(request_queue_t *q, struct request *rq)
950 960
951 WARN_ON(!list_empty(&rq->queuelist)); 961 WARN_ON(!list_empty(&rq->queuelist));
952 962
953 if (arq->state == AS_RQ_PRESCHED) {
954 WARN_ON(arq->io_context);
955 goto out;
956 }
957
958 if (arq->state == AS_RQ_MERGED)
959 goto out_ioc;
960
961 if (arq->state != AS_RQ_REMOVED) { 963 if (arq->state != AS_RQ_REMOVED) {
962 printk("arq->state %d\n", arq->state); 964 printk("arq->state %d\n", arq->state);
963 WARN_ON(1); 965 WARN_ON(1);
964 goto out; 966 goto out;
965 } 967 }
966 968
967 if (!blk_fs_request(rq))
968 goto out;
969
970 if (ad->changed_batch && ad->nr_dispatched == 1) { 969 if (ad->changed_batch && ad->nr_dispatched == 1) {
971 kblockd_schedule_work(&ad->antic_work); 970 kblockd_schedule_work(&ad->antic_work);
972 ad->changed_batch = 0; 971 ad->changed_batch = 0;
@@ -1001,21 +1000,7 @@ static void as_completed_request(request_queue_t *q, struct request *rq)
1001 } 1000 }
1002 } 1001 }
1003 1002
1004out_ioc: 1003 as_put_io_context(arq);
1005 if (!arq->io_context)
1006 goto out;
1007
1008 if (arq->is_sync == REQ_SYNC) {
1009 struct as_io_context *aic = arq->io_context->aic;
1010 if (aic) {
1011 spin_lock(&aic->lock);
1012 set_bit(AS_TASK_IORUNNING, &aic->state);
1013 aic->last_end_request = jiffies;
1014 spin_unlock(&aic->lock);
1015 }
1016 }
1017
1018 put_io_context(arq->io_context);
1019out: 1004out:
1020 arq->state = AS_RQ_POSTSCHED; 1005 arq->state = AS_RQ_POSTSCHED;
1021} 1006}
@@ -1047,73 +1032,11 @@ static void as_remove_queued_request(request_queue_t *q, struct request *rq)
1047 ad->next_arq[data_dir] = as_find_next_arq(ad, arq); 1032 ad->next_arq[data_dir] = as_find_next_arq(ad, arq);
1048 1033
1049 list_del_init(&arq->fifo); 1034 list_del_init(&arq->fifo);
1050 as_remove_merge_hints(q, arq); 1035 as_del_arq_hash(arq);
1051 as_del_arq_rb(ad, arq); 1036 as_del_arq_rb(ad, arq);
1052} 1037}
1053 1038
1054/* 1039/*
1055 * as_remove_dispatched_request is called to remove a request which has gone
1056 * to the dispatch list.
1057 */
1058static void as_remove_dispatched_request(request_queue_t *q, struct request *rq)
1059{
1060 struct as_rq *arq = RQ_DATA(rq);
1061 struct as_io_context *aic;
1062
1063 if (!arq) {
1064 WARN_ON(1);
1065 return;
1066 }
1067
1068 WARN_ON(arq->state != AS_RQ_DISPATCHED);
1069 WARN_ON(ON_RB(&arq->rb_node));
1070 if (arq->io_context && arq->io_context->aic) {
1071 aic = arq->io_context->aic;
1072 if (aic) {
1073 WARN_ON(!atomic_read(&aic->nr_dispatched));
1074 atomic_dec(&aic->nr_dispatched);
1075 }
1076 }
1077}
1078
1079/*
1080 * as_remove_request is called when a driver has finished with a request.
1081 * This should be only called for dispatched requests, but for some reason
1082 * a POWER4 box running hwscan it does not.
1083 */
1084static void as_remove_request(request_queue_t *q, struct request *rq)
1085{
1086 struct as_rq *arq = RQ_DATA(rq);
1087
1088 if (unlikely(arq->state == AS_RQ_NEW))
1089 goto out;
1090
1091 if (ON_RB(&arq->rb_node)) {
1092 if (arq->state != AS_RQ_QUEUED) {
1093 printk("arq->state %d\n", arq->state);
1094 WARN_ON(1);
1095 goto out;
1096 }
1097 /*
1098 * We'll lose the aliased request(s) here. I don't think this
1099 * will ever happen, but if it does, hopefully someone will
1100 * report it.
1101 */
1102 WARN_ON(!list_empty(&rq->queuelist));
1103 as_remove_queued_request(q, rq);
1104 } else {
1105 if (arq->state != AS_RQ_DISPATCHED) {
1106 printk("arq->state %d\n", arq->state);
1107 WARN_ON(1);
1108 goto out;
1109 }
1110 as_remove_dispatched_request(q, rq);
1111 }
1112out:
1113 arq->state = AS_RQ_REMOVED;
1114}
1115
1116/*
1117 * as_fifo_expired returns 0 if there are no expired reads on the fifo, 1040 * as_fifo_expired returns 0 if there are no expired reads on the fifo,
1118 * 1 otherwise. It is ratelimited so that we only perform the check once per 1041 * 1 otherwise. It is ratelimited so that we only perform the check once per
1119 * `fifo_expire' interval. Otherwise a large number of expired requests 1042 * `fifo_expire' interval. Otherwise a large number of expired requests
@@ -1165,7 +1088,6 @@ static inline int as_batch_expired(struct as_data *ad)
1165static void as_move_to_dispatch(struct as_data *ad, struct as_rq *arq) 1088static void as_move_to_dispatch(struct as_data *ad, struct as_rq *arq)
1166{ 1089{
1167 struct request *rq = arq->request; 1090 struct request *rq = arq->request;
1168 struct list_head *insert;
1169 const int data_dir = arq->is_sync; 1091 const int data_dir = arq->is_sync;
1170 1092
1171 BUG_ON(!ON_RB(&arq->rb_node)); 1093 BUG_ON(!ON_RB(&arq->rb_node));
@@ -1198,13 +1120,13 @@ static void as_move_to_dispatch(struct as_data *ad, struct as_rq *arq)
1198 /* 1120 /*
1199 * take it off the sort and fifo list, add to dispatch queue 1121 * take it off the sort and fifo list, add to dispatch queue
1200 */ 1122 */
1201 insert = ad->dispatch->prev;
1202
1203 while (!list_empty(&rq->queuelist)) { 1123 while (!list_empty(&rq->queuelist)) {
1204 struct request *__rq = list_entry_rq(rq->queuelist.next); 1124 struct request *__rq = list_entry_rq(rq->queuelist.next);
1205 struct as_rq *__arq = RQ_DATA(__rq); 1125 struct as_rq *__arq = RQ_DATA(__rq);
1206 1126
1207 list_move_tail(&__rq->queuelist, ad->dispatch); 1127 list_del(&__rq->queuelist);
1128
1129 elv_dispatch_add_tail(ad->q, __rq);
1208 1130
1209 if (__arq->io_context && __arq->io_context->aic) 1131 if (__arq->io_context && __arq->io_context->aic)
1210 atomic_inc(&__arq->io_context->aic->nr_dispatched); 1132 atomic_inc(&__arq->io_context->aic->nr_dispatched);
@@ -1218,7 +1140,8 @@ static void as_move_to_dispatch(struct as_data *ad, struct as_rq *arq)
1218 as_remove_queued_request(ad->q, rq); 1140 as_remove_queued_request(ad->q, rq);
1219 WARN_ON(arq->state != AS_RQ_QUEUED); 1141 WARN_ON(arq->state != AS_RQ_QUEUED);
1220 1142
1221 list_add(&rq->queuelist, insert); 1143 elv_dispatch_sort(ad->q, rq);
1144
1222 arq->state = AS_RQ_DISPATCHED; 1145 arq->state = AS_RQ_DISPATCHED;
1223 if (arq->io_context && arq->io_context->aic) 1146 if (arq->io_context && arq->io_context->aic)
1224 atomic_inc(&arq->io_context->aic->nr_dispatched); 1147 atomic_inc(&arq->io_context->aic->nr_dispatched);
@@ -1230,12 +1153,42 @@ static void as_move_to_dispatch(struct as_data *ad, struct as_rq *arq)
1230 * read/write expire, batch expire, etc, and moves it to the dispatch 1153 * read/write expire, batch expire, etc, and moves it to the dispatch
1231 * queue. Returns 1 if a request was found, 0 otherwise. 1154 * queue. Returns 1 if a request was found, 0 otherwise.
1232 */ 1155 */
1233static int as_dispatch_request(struct as_data *ad) 1156static int as_dispatch_request(request_queue_t *q, int force)
1234{ 1157{
1158 struct as_data *ad = q->elevator->elevator_data;
1235 struct as_rq *arq; 1159 struct as_rq *arq;
1236 const int reads = !list_empty(&ad->fifo_list[REQ_SYNC]); 1160 const int reads = !list_empty(&ad->fifo_list[REQ_SYNC]);
1237 const int writes = !list_empty(&ad->fifo_list[REQ_ASYNC]); 1161 const int writes = !list_empty(&ad->fifo_list[REQ_ASYNC]);
1238 1162
1163 if (unlikely(force)) {
1164 /*
1165 * Forced dispatch, accounting is useless. Reset
1166 * accounting states and dump fifo_lists. Note that
1167 * batch_data_dir is reset to REQ_SYNC to avoid
1168 * screwing write batch accounting as write batch
1169 * accounting occurs on W->R transition.
1170 */
1171 int dispatched = 0;
1172
1173 ad->batch_data_dir = REQ_SYNC;
1174 ad->changed_batch = 0;
1175 ad->new_batch = 0;
1176
1177 while (ad->next_arq[REQ_SYNC]) {
1178 as_move_to_dispatch(ad, ad->next_arq[REQ_SYNC]);
1179 dispatched++;
1180 }
1181 ad->last_check_fifo[REQ_SYNC] = jiffies;
1182
1183 while (ad->next_arq[REQ_ASYNC]) {
1184 as_move_to_dispatch(ad, ad->next_arq[REQ_ASYNC]);
1185 dispatched++;
1186 }
1187 ad->last_check_fifo[REQ_ASYNC] = jiffies;
1188
1189 return dispatched;
1190 }
1191
1239 /* Signal that the write batch was uncontended, so we can't time it */ 1192 /* Signal that the write batch was uncontended, so we can't time it */
1240 if (ad->batch_data_dir == REQ_ASYNC && !reads) { 1193 if (ad->batch_data_dir == REQ_ASYNC && !reads) {
1241 if (ad->current_write_count == 0 || !writes) 1194 if (ad->current_write_count == 0 || !writes)
@@ -1359,20 +1312,6 @@ fifo_expired:
1359 return 1; 1312 return 1;
1360} 1313}
1361 1314
1362static struct request *as_next_request(request_queue_t *q)
1363{
1364 struct as_data *ad = q->elevator->elevator_data;
1365 struct request *rq = NULL;
1366
1367 /*
1368 * if there are still requests on the dispatch queue, grab the first
1369 */
1370 if (!list_empty(ad->dispatch) || as_dispatch_request(ad))
1371 rq = list_entry_rq(ad->dispatch->next);
1372
1373 return rq;
1374}
1375
1376/* 1315/*
1377 * Add arq to a list behind alias 1316 * Add arq to a list behind alias
1378 */ 1317 */
@@ -1404,17 +1343,26 @@ as_add_aliased_request(struct as_data *ad, struct as_rq *arq, struct as_rq *alia
1404 /* 1343 /*
1405 * Don't want to have to handle merges. 1344 * Don't want to have to handle merges.
1406 */ 1345 */
1407 as_remove_merge_hints(ad->q, arq); 1346 as_del_arq_hash(arq);
1347 arq->request->flags |= REQ_NOMERGE;
1408} 1348}
1409 1349
1410/* 1350/*
1411 * add arq to rbtree and fifo 1351 * add arq to rbtree and fifo
1412 */ 1352 */
1413static void as_add_request(struct as_data *ad, struct as_rq *arq) 1353static void as_add_request(request_queue_t *q, struct request *rq)
1414{ 1354{
1355 struct as_data *ad = q->elevator->elevator_data;
1356 struct as_rq *arq = RQ_DATA(rq);
1415 struct as_rq *alias; 1357 struct as_rq *alias;
1416 int data_dir; 1358 int data_dir;
1417 1359
1360 if (arq->state != AS_RQ_PRESCHED) {
1361 printk("arq->state: %d\n", arq->state);
1362 WARN_ON(1);
1363 }
1364 arq->state = AS_RQ_NEW;
1365
1418 if (rq_data_dir(arq->request) == READ 1366 if (rq_data_dir(arq->request) == READ
1419 || current->flags&PF_SYNCWRITE) 1367 || current->flags&PF_SYNCWRITE)
1420 arq->is_sync = 1; 1368 arq->is_sync = 1;
@@ -1437,12 +1385,8 @@ static void as_add_request(struct as_data *ad, struct as_rq *arq)
1437 arq->expires = jiffies + ad->fifo_expire[data_dir]; 1385 arq->expires = jiffies + ad->fifo_expire[data_dir];
1438 list_add_tail(&arq->fifo, &ad->fifo_list[data_dir]); 1386 list_add_tail(&arq->fifo, &ad->fifo_list[data_dir]);
1439 1387
1440 if (rq_mergeable(arq->request)) { 1388 if (rq_mergeable(arq->request))
1441 as_add_arq_hash(ad, arq); 1389 as_add_arq_hash(ad, arq);
1442
1443 if (!ad->q->last_merge)
1444 ad->q->last_merge = arq->request;
1445 }
1446 as_update_arq(ad, arq); /* keep state machine up to date */ 1390 as_update_arq(ad, arq); /* keep state machine up to date */
1447 1391
1448 } else { 1392 } else {
@@ -1463,96 +1407,24 @@ static void as_add_request(struct as_data *ad, struct as_rq *arq)
1463 arq->state = AS_RQ_QUEUED; 1407 arq->state = AS_RQ_QUEUED;
1464} 1408}
1465 1409
1466static void as_deactivate_request(request_queue_t *q, struct request *rq) 1410static void as_activate_request(request_queue_t *q, struct request *rq)
1467{ 1411{
1468 struct as_data *ad = q->elevator->elevator_data;
1469 struct as_rq *arq = RQ_DATA(rq); 1412 struct as_rq *arq = RQ_DATA(rq);
1470 1413
1471 if (arq) { 1414 WARN_ON(arq->state != AS_RQ_DISPATCHED);
1472 if (arq->state == AS_RQ_REMOVED) { 1415 arq->state = AS_RQ_REMOVED;
1473 arq->state = AS_RQ_DISPATCHED; 1416 if (arq->io_context && arq->io_context->aic)
1474 if (arq->io_context && arq->io_context->aic) 1417 atomic_dec(&arq->io_context->aic->nr_dispatched);
1475 atomic_inc(&arq->io_context->aic->nr_dispatched);
1476 }
1477 } else
1478 WARN_ON(blk_fs_request(rq)
1479 && (!(rq->flags & (REQ_HARDBARRIER|REQ_SOFTBARRIER))) );
1480
1481 /* Stop anticipating - let this request get through */
1482 as_antic_stop(ad);
1483}
1484
1485/*
1486 * requeue the request. The request has not been completed, nor is it a
1487 * new request, so don't touch accounting.
1488 */
1489static void as_requeue_request(request_queue_t *q, struct request *rq)
1490{
1491 as_deactivate_request(q, rq);
1492 list_add(&rq->queuelist, &q->queue_head);
1493}
1494
1495/*
1496 * Account a request that is inserted directly onto the dispatch queue.
1497 * arq->io_context->aic->nr_dispatched should not need to be incremented
1498 * because only new requests should come through here: requeues go through
1499 * our explicit requeue handler.
1500 */
1501static void as_account_queued_request(struct as_data *ad, struct request *rq)
1502{
1503 if (blk_fs_request(rq)) {
1504 struct as_rq *arq = RQ_DATA(rq);
1505 arq->state = AS_RQ_DISPATCHED;
1506 ad->nr_dispatched++;
1507 }
1508} 1418}
1509 1419
1510static void 1420static void as_deactivate_request(request_queue_t *q, struct request *rq)
1511as_insert_request(request_queue_t *q, struct request *rq, int where)
1512{ 1421{
1513 struct as_data *ad = q->elevator->elevator_data;
1514 struct as_rq *arq = RQ_DATA(rq); 1422 struct as_rq *arq = RQ_DATA(rq);
1515 1423
1516 if (arq) { 1424 WARN_ON(arq->state != AS_RQ_REMOVED);
1517 if (arq->state != AS_RQ_PRESCHED) { 1425 arq->state = AS_RQ_DISPATCHED;
1518 printk("arq->state: %d\n", arq->state); 1426 if (arq->io_context && arq->io_context->aic)
1519 WARN_ON(1); 1427 atomic_inc(&arq->io_context->aic->nr_dispatched);
1520 }
1521 arq->state = AS_RQ_NEW;
1522 }
1523
1524 /* barriers must flush the reorder queue */
1525 if (unlikely(rq->flags & (REQ_SOFTBARRIER | REQ_HARDBARRIER)
1526 && where == ELEVATOR_INSERT_SORT)) {
1527 WARN_ON(1);
1528 where = ELEVATOR_INSERT_BACK;
1529 }
1530
1531 switch (where) {
1532 case ELEVATOR_INSERT_BACK:
1533 while (ad->next_arq[REQ_SYNC])
1534 as_move_to_dispatch(ad, ad->next_arq[REQ_SYNC]);
1535
1536 while (ad->next_arq[REQ_ASYNC])
1537 as_move_to_dispatch(ad, ad->next_arq[REQ_ASYNC]);
1538
1539 list_add_tail(&rq->queuelist, ad->dispatch);
1540 as_account_queued_request(ad, rq);
1541 as_antic_stop(ad);
1542 break;
1543 case ELEVATOR_INSERT_FRONT:
1544 list_add(&rq->queuelist, ad->dispatch);
1545 as_account_queued_request(ad, rq);
1546 as_antic_stop(ad);
1547 break;
1548 case ELEVATOR_INSERT_SORT:
1549 BUG_ON(!blk_fs_request(rq));
1550 as_add_request(ad, arq);
1551 break;
1552 default:
1553 BUG();
1554 return;
1555 }
1556} 1428}
1557 1429
1558/* 1430/*
@@ -1565,12 +1437,8 @@ static int as_queue_empty(request_queue_t *q)
1565{ 1437{
1566 struct as_data *ad = q->elevator->elevator_data; 1438 struct as_data *ad = q->elevator->elevator_data;
1567 1439
1568 if (!list_empty(&ad->fifo_list[REQ_ASYNC]) 1440 return list_empty(&ad->fifo_list[REQ_ASYNC])
1569 || !list_empty(&ad->fifo_list[REQ_SYNC]) 1441 && list_empty(&ad->fifo_list[REQ_SYNC]);
1570 || !list_empty(ad->dispatch))
1571 return 0;
1572
1573 return 1;
1574} 1442}
1575 1443
1576static struct request * 1444static struct request *
@@ -1608,15 +1476,6 @@ as_merge(request_queue_t *q, struct request **req, struct bio *bio)
1608 int ret; 1476 int ret;
1609 1477
1610 /* 1478 /*
1611 * try last_merge to avoid going to hash
1612 */
1613 ret = elv_try_last_merge(q, bio);
1614 if (ret != ELEVATOR_NO_MERGE) {
1615 __rq = q->last_merge;
1616 goto out_insert;
1617 }
1618
1619 /*
1620 * see if the merge hash can satisfy a back merge 1479 * see if the merge hash can satisfy a back merge
1621 */ 1480 */
1622 __rq = as_find_arq_hash(ad, bio->bi_sector); 1481 __rq = as_find_arq_hash(ad, bio->bi_sector);
@@ -1644,9 +1503,6 @@ as_merge(request_queue_t *q, struct request **req, struct bio *bio)
1644 1503
1645 return ELEVATOR_NO_MERGE; 1504 return ELEVATOR_NO_MERGE;
1646out: 1505out:
1647 if (rq_mergeable(__rq))
1648 q->last_merge = __rq;
1649out_insert:
1650 if (ret) { 1506 if (ret) {
1651 if (rq_mergeable(__rq)) 1507 if (rq_mergeable(__rq))
1652 as_hot_arq_hash(ad, RQ_DATA(__rq)); 1508 as_hot_arq_hash(ad, RQ_DATA(__rq));
@@ -1693,9 +1549,6 @@ static void as_merged_request(request_queue_t *q, struct request *req)
1693 * behind the disk head. We currently don't bother adjusting. 1549 * behind the disk head. We currently don't bother adjusting.
1694 */ 1550 */
1695 } 1551 }
1696
1697 if (arq->on_hash)
1698 q->last_merge = req;
1699} 1552}
1700 1553
1701static void 1554static void
@@ -1763,6 +1616,7 @@ as_merged_requests(request_queue_t *q, struct request *req,
1763 * kill knowledge of next, this one is a goner 1616 * kill knowledge of next, this one is a goner
1764 */ 1617 */
1765 as_remove_queued_request(q, next); 1618 as_remove_queued_request(q, next);
1619 as_put_io_context(anext);
1766 1620
1767 anext->state = AS_RQ_MERGED; 1621 anext->state = AS_RQ_MERGED;
1768} 1622}
@@ -1782,7 +1636,7 @@ static void as_work_handler(void *data)
1782 unsigned long flags; 1636 unsigned long flags;
1783 1637
1784 spin_lock_irqsave(q->queue_lock, flags); 1638 spin_lock_irqsave(q->queue_lock, flags);
1785 if (as_next_request(q)) 1639 if (!as_queue_empty(q))
1786 q->request_fn(q); 1640 q->request_fn(q);
1787 spin_unlock_irqrestore(q->queue_lock, flags); 1641 spin_unlock_irqrestore(q->queue_lock, flags);
1788} 1642}
@@ -1797,7 +1651,9 @@ static void as_put_request(request_queue_t *q, struct request *rq)
1797 return; 1651 return;
1798 } 1652 }
1799 1653
1800 if (arq->state != AS_RQ_POSTSCHED && arq->state != AS_RQ_PRESCHED) { 1654 if (unlikely(arq->state != AS_RQ_POSTSCHED &&
1655 arq->state != AS_RQ_PRESCHED &&
1656 arq->state != AS_RQ_MERGED)) {
1801 printk("arq->state %d\n", arq->state); 1657 printk("arq->state %d\n", arq->state);
1802 WARN_ON(1); 1658 WARN_ON(1);
1803 } 1659 }
@@ -1807,7 +1663,7 @@ static void as_put_request(request_queue_t *q, struct request *rq)
1807} 1663}
1808 1664
1809static int as_set_request(request_queue_t *q, struct request *rq, 1665static int as_set_request(request_queue_t *q, struct request *rq,
1810 struct bio *bio, int gfp_mask) 1666 struct bio *bio, gfp_t gfp_mask)
1811{ 1667{
1812 struct as_data *ad = q->elevator->elevator_data; 1668 struct as_data *ad = q->elevator->elevator_data;
1813 struct as_rq *arq = mempool_alloc(ad->arq_pool, gfp_mask); 1669 struct as_rq *arq = mempool_alloc(ad->arq_pool, gfp_mask);
@@ -1907,7 +1763,6 @@ static int as_init_queue(request_queue_t *q, elevator_t *e)
1907 INIT_LIST_HEAD(&ad->fifo_list[REQ_ASYNC]); 1763 INIT_LIST_HEAD(&ad->fifo_list[REQ_ASYNC]);
1908 ad->sort_list[REQ_SYNC] = RB_ROOT; 1764 ad->sort_list[REQ_SYNC] = RB_ROOT;
1909 ad->sort_list[REQ_ASYNC] = RB_ROOT; 1765 ad->sort_list[REQ_ASYNC] = RB_ROOT;
1910 ad->dispatch = &q->queue_head;
1911 ad->fifo_expire[REQ_SYNC] = default_read_expire; 1766 ad->fifo_expire[REQ_SYNC] = default_read_expire;
1912 ad->fifo_expire[REQ_ASYNC] = default_write_expire; 1767 ad->fifo_expire[REQ_ASYNC] = default_write_expire;
1913 ad->antic_expire = default_antic_expire; 1768 ad->antic_expire = default_antic_expire;
@@ -2072,10 +1927,9 @@ static struct elevator_type iosched_as = {
2072 .elevator_merge_fn = as_merge, 1927 .elevator_merge_fn = as_merge,
2073 .elevator_merged_fn = as_merged_request, 1928 .elevator_merged_fn = as_merged_request,
2074 .elevator_merge_req_fn = as_merged_requests, 1929 .elevator_merge_req_fn = as_merged_requests,
2075 .elevator_next_req_fn = as_next_request, 1930 .elevator_dispatch_fn = as_dispatch_request,
2076 .elevator_add_req_fn = as_insert_request, 1931 .elevator_add_req_fn = as_add_request,
2077 .elevator_remove_req_fn = as_remove_request, 1932 .elevator_activate_req_fn = as_activate_request,
2078 .elevator_requeue_req_fn = as_requeue_request,
2079 .elevator_deactivate_req_fn = as_deactivate_request, 1933 .elevator_deactivate_req_fn = as_deactivate_request,
2080 .elevator_queue_empty_fn = as_queue_empty, 1934 .elevator_queue_empty_fn = as_queue_empty,
2081 .elevator_completed_req_fn = as_completed_request, 1935 .elevator_completed_req_fn = as_completed_request,
@@ -2119,8 +1973,8 @@ static int __init as_init(void)
2119 1973
2120static void __exit as_exit(void) 1974static void __exit as_exit(void)
2121{ 1975{
2122 kmem_cache_destroy(arq_pool);
2123 elv_unregister(&iosched_as); 1976 elv_unregister(&iosched_as);
1977 kmem_cache_destroy(arq_pool);
2124} 1978}
2125 1979
2126module_init(as_init); 1980module_init(as_init);
diff --git a/drivers/block/cciss_scsi.c b/drivers/block/cciss_scsi.c
index e183a3ef7839..ec27976a57da 100644
--- a/drivers/block/cciss_scsi.c
+++ b/drivers/block/cciss_scsi.c
@@ -28,13 +28,17 @@
28 through the array controller. Note in particular, neither 28 through the array controller. Note in particular, neither
29 physical nor logical disks are presented through the scsi layer. */ 29 physical nor logical disks are presented through the scsi layer. */
30 30
31#include <linux/timer.h>
32#include <linux/completion.h>
33#include <linux/slab.h>
34#include <linux/string.h>
35
36#include <asm/atomic.h>
37
31#include <scsi/scsi.h> 38#include <scsi/scsi.h>
32#include <scsi/scsi_cmnd.h> 39#include <scsi/scsi_cmnd.h>
33#include <scsi/scsi_device.h> 40#include <scsi/scsi_device.h>
34#include <scsi/scsi_host.h> 41#include <scsi/scsi_host.h>
35#include <asm/atomic.h>
36#include <linux/timer.h>
37#include <linux/completion.h>
38 42
39#include "cciss_scsi.h" 43#include "cciss_scsi.h"
40 44
diff --git a/drivers/block/cfq-iosched.c b/drivers/block/cfq-iosched.c
index cd056e7e64ec..5281f8e70510 100644
--- a/drivers/block/cfq-iosched.c
+++ b/drivers/block/cfq-iosched.c
@@ -84,7 +84,6 @@ static int cfq_max_depth = 2;
84 (node)->rb_left = NULL; \ 84 (node)->rb_left = NULL; \
85} while (0) 85} while (0)
86#define RB_CLEAR_ROOT(root) ((root)->rb_node = NULL) 86#define RB_CLEAR_ROOT(root) ((root)->rb_node = NULL)
87#define ON_RB(node) ((node)->rb_color != RB_NONE)
88#define rb_entry_crq(node) rb_entry((node), struct cfq_rq, rb_node) 87#define rb_entry_crq(node) rb_entry((node), struct cfq_rq, rb_node)
89#define rq_rb_key(rq) (rq)->sector 88#define rq_rb_key(rq) (rq)->sector
90 89
@@ -271,10 +270,7 @@ CFQ_CFQQ_FNS(expired);
271#undef CFQ_CFQQ_FNS 270#undef CFQ_CFQQ_FNS
272 271
273enum cfq_rq_state_flags { 272enum cfq_rq_state_flags {
274 CFQ_CRQ_FLAG_in_flight = 0, 273 CFQ_CRQ_FLAG_is_sync = 0,
275 CFQ_CRQ_FLAG_in_driver,
276 CFQ_CRQ_FLAG_is_sync,
277 CFQ_CRQ_FLAG_requeued,
278}; 274};
279 275
280#define CFQ_CRQ_FNS(name) \ 276#define CFQ_CRQ_FNS(name) \
@@ -291,14 +287,11 @@ static inline int cfq_crq_##name(const struct cfq_rq *crq) \
291 return (crq->crq_flags & (1 << CFQ_CRQ_FLAG_##name)) != 0; \ 287 return (crq->crq_flags & (1 << CFQ_CRQ_FLAG_##name)) != 0; \
292} 288}
293 289
294CFQ_CRQ_FNS(in_flight);
295CFQ_CRQ_FNS(in_driver);
296CFQ_CRQ_FNS(is_sync); 290CFQ_CRQ_FNS(is_sync);
297CFQ_CRQ_FNS(requeued);
298#undef CFQ_CRQ_FNS 291#undef CFQ_CRQ_FNS
299 292
300static struct cfq_queue *cfq_find_cfq_hash(struct cfq_data *, unsigned int, unsigned short); 293static struct cfq_queue *cfq_find_cfq_hash(struct cfq_data *, unsigned int, unsigned short);
301static void cfq_dispatch_sort(request_queue_t *, struct cfq_rq *); 294static void cfq_dispatch_insert(request_queue_t *, struct cfq_rq *);
302static void cfq_put_cfqd(struct cfq_data *cfqd); 295static void cfq_put_cfqd(struct cfq_data *cfqd);
303 296
304#define process_sync(tsk) ((tsk)->flags & PF_SYNCWRITE) 297#define process_sync(tsk) ((tsk)->flags & PF_SYNCWRITE)
@@ -311,14 +304,6 @@ static inline void cfq_del_crq_hash(struct cfq_rq *crq)
311 hlist_del_init(&crq->hash); 304 hlist_del_init(&crq->hash);
312} 305}
313 306
314static void cfq_remove_merge_hints(request_queue_t *q, struct cfq_rq *crq)
315{
316 cfq_del_crq_hash(crq);
317
318 if (q->last_merge == crq->request)
319 q->last_merge = NULL;
320}
321
322static inline void cfq_add_crq_hash(struct cfq_data *cfqd, struct cfq_rq *crq) 307static inline void cfq_add_crq_hash(struct cfq_data *cfqd, struct cfq_rq *crq)
323{ 308{
324 const int hash_idx = CFQ_MHASH_FN(rq_hash_key(crq->request)); 309 const int hash_idx = CFQ_MHASH_FN(rq_hash_key(crq->request));
@@ -347,18 +332,13 @@ static struct request *cfq_find_rq_hash(struct cfq_data *cfqd, sector_t offset)
347 return NULL; 332 return NULL;
348} 333}
349 334
350static inline int cfq_pending_requests(struct cfq_data *cfqd)
351{
352 return !list_empty(&cfqd->queue->queue_head) || cfqd->busy_queues;
353}
354
355/* 335/*
356 * scheduler run of queue, if there are requests pending and no one in the 336 * scheduler run of queue, if there are requests pending and no one in the
357 * driver that will restart queueing 337 * driver that will restart queueing
358 */ 338 */
359static inline void cfq_schedule_dispatch(struct cfq_data *cfqd) 339static inline void cfq_schedule_dispatch(struct cfq_data *cfqd)
360{ 340{
361 if (!cfqd->rq_in_driver && cfq_pending_requests(cfqd)) 341 if (!cfqd->rq_in_driver && cfqd->busy_queues)
362 kblockd_schedule_work(&cfqd->unplug_work); 342 kblockd_schedule_work(&cfqd->unplug_work);
363} 343}
364 344
@@ -366,7 +346,7 @@ static int cfq_queue_empty(request_queue_t *q)
366{ 346{
367 struct cfq_data *cfqd = q->elevator->elevator_data; 347 struct cfq_data *cfqd = q->elevator->elevator_data;
368 348
369 return !cfq_pending_requests(cfqd); 349 return !cfqd->busy_queues;
370} 350}
371 351
372/* 352/*
@@ -386,11 +366,6 @@ cfq_choose_req(struct cfq_data *cfqd, struct cfq_rq *crq1, struct cfq_rq *crq2)
386 if (crq2 == NULL) 366 if (crq2 == NULL)
387 return crq1; 367 return crq1;
388 368
389 if (cfq_crq_requeued(crq1) && !cfq_crq_requeued(crq2))
390 return crq1;
391 else if (cfq_crq_requeued(crq2) && !cfq_crq_requeued(crq1))
392 return crq2;
393
394 if (cfq_crq_is_sync(crq1) && !cfq_crq_is_sync(crq2)) 369 if (cfq_crq_is_sync(crq1) && !cfq_crq_is_sync(crq2))
395 return crq1; 370 return crq1;
396 else if (cfq_crq_is_sync(crq2) && !cfq_crq_is_sync(crq1)) 371 else if (cfq_crq_is_sync(crq2) && !cfq_crq_is_sync(crq1))
@@ -461,10 +436,7 @@ cfq_find_next_crq(struct cfq_data *cfqd, struct cfq_queue *cfqq,
461 struct cfq_rq *crq_next = NULL, *crq_prev = NULL; 436 struct cfq_rq *crq_next = NULL, *crq_prev = NULL;
462 struct rb_node *rbnext, *rbprev; 437 struct rb_node *rbnext, *rbprev;
463 438
464 rbnext = NULL; 439 if (!(rbnext = rb_next(&last->rb_node))) {
465 if (ON_RB(&last->rb_node))
466 rbnext = rb_next(&last->rb_node);
467 if (!rbnext) {
468 rbnext = rb_first(&cfqq->sort_list); 440 rbnext = rb_first(&cfqq->sort_list);
469 if (rbnext == &last->rb_node) 441 if (rbnext == &last->rb_node)
470 rbnext = NULL; 442 rbnext = NULL;
@@ -545,13 +517,13 @@ static void cfq_resort_rr_list(struct cfq_queue *cfqq, int preempted)
545 * the pending list according to last request service 517 * the pending list according to last request service
546 */ 518 */
547static inline void 519static inline void
548cfq_add_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq, int requeue) 520cfq_add_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq)
549{ 521{
550 BUG_ON(cfq_cfqq_on_rr(cfqq)); 522 BUG_ON(cfq_cfqq_on_rr(cfqq));
551 cfq_mark_cfqq_on_rr(cfqq); 523 cfq_mark_cfqq_on_rr(cfqq);
552 cfqd->busy_queues++; 524 cfqd->busy_queues++;
553 525
554 cfq_resort_rr_list(cfqq, requeue); 526 cfq_resort_rr_list(cfqq, 0);
555} 527}
556 528
557static inline void 529static inline void
@@ -571,22 +543,19 @@ cfq_del_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq)
571static inline void cfq_del_crq_rb(struct cfq_rq *crq) 543static inline void cfq_del_crq_rb(struct cfq_rq *crq)
572{ 544{
573 struct cfq_queue *cfqq = crq->cfq_queue; 545 struct cfq_queue *cfqq = crq->cfq_queue;
546 struct cfq_data *cfqd = cfqq->cfqd;
547 const int sync = cfq_crq_is_sync(crq);
574 548
575 if (ON_RB(&crq->rb_node)) { 549 BUG_ON(!cfqq->queued[sync]);
576 struct cfq_data *cfqd = cfqq->cfqd; 550 cfqq->queued[sync]--;
577 const int sync = cfq_crq_is_sync(crq);
578
579 BUG_ON(!cfqq->queued[sync]);
580 cfqq->queued[sync]--;
581 551
582 cfq_update_next_crq(crq); 552 cfq_update_next_crq(crq);
583 553
584 rb_erase(&crq->rb_node, &cfqq->sort_list); 554 rb_erase(&crq->rb_node, &cfqq->sort_list);
585 RB_CLEAR_COLOR(&crq->rb_node); 555 RB_CLEAR_COLOR(&crq->rb_node);
586 556
587 if (cfq_cfqq_on_rr(cfqq) && RB_EMPTY(&cfqq->sort_list)) 557 if (cfq_cfqq_on_rr(cfqq) && RB_EMPTY(&cfqq->sort_list))
588 cfq_del_cfqq_rr(cfqd, cfqq); 558 cfq_del_cfqq_rr(cfqd, cfqq);
589 }
590} 559}
591 560
592static struct cfq_rq * 561static struct cfq_rq *
@@ -627,12 +596,12 @@ static void cfq_add_crq_rb(struct cfq_rq *crq)
627 * if that happens, put the alias on the dispatch list 596 * if that happens, put the alias on the dispatch list
628 */ 597 */
629 while ((__alias = __cfq_add_crq_rb(crq)) != NULL) 598 while ((__alias = __cfq_add_crq_rb(crq)) != NULL)
630 cfq_dispatch_sort(cfqd->queue, __alias); 599 cfq_dispatch_insert(cfqd->queue, __alias);
631 600
632 rb_insert_color(&crq->rb_node, &cfqq->sort_list); 601 rb_insert_color(&crq->rb_node, &cfqq->sort_list);
633 602
634 if (!cfq_cfqq_on_rr(cfqq)) 603 if (!cfq_cfqq_on_rr(cfqq))
635 cfq_add_cfqq_rr(cfqd, cfqq, cfq_crq_requeued(crq)); 604 cfq_add_cfqq_rr(cfqd, cfqq);
636 605
637 /* 606 /*
638 * check if this request is a better next-serve candidate 607 * check if this request is a better next-serve candidate
@@ -643,10 +612,8 @@ static void cfq_add_crq_rb(struct cfq_rq *crq)
643static inline void 612static inline void
644cfq_reposition_crq_rb(struct cfq_queue *cfqq, struct cfq_rq *crq) 613cfq_reposition_crq_rb(struct cfq_queue *cfqq, struct cfq_rq *crq)
645{ 614{
646 if (ON_RB(&crq->rb_node)) { 615 rb_erase(&crq->rb_node, &cfqq->sort_list);
647 rb_erase(&crq->rb_node, &cfqq->sort_list); 616 cfqq->queued[cfq_crq_is_sync(crq)]--;
648 cfqq->queued[cfq_crq_is_sync(crq)]--;
649 }
650 617
651 cfq_add_crq_rb(crq); 618 cfq_add_crq_rb(crq);
652} 619}
@@ -676,49 +643,28 @@ out:
676 return NULL; 643 return NULL;
677} 644}
678 645
679static void cfq_deactivate_request(request_queue_t *q, struct request *rq) 646static void cfq_activate_request(request_queue_t *q, struct request *rq)
680{ 647{
681 struct cfq_data *cfqd = q->elevator->elevator_data; 648 struct cfq_data *cfqd = q->elevator->elevator_data;
682 struct cfq_rq *crq = RQ_DATA(rq);
683
684 if (crq) {
685 struct cfq_queue *cfqq = crq->cfq_queue;
686 649
687 if (cfq_crq_in_driver(crq)) { 650 cfqd->rq_in_driver++;
688 cfq_clear_crq_in_driver(crq);
689 WARN_ON(!cfqd->rq_in_driver);
690 cfqd->rq_in_driver--;
691 }
692 if (cfq_crq_in_flight(crq)) {
693 const int sync = cfq_crq_is_sync(crq);
694
695 cfq_clear_crq_in_flight(crq);
696 WARN_ON(!cfqq->on_dispatch[sync]);
697 cfqq->on_dispatch[sync]--;
698 }
699 cfq_mark_crq_requeued(crq);
700 }
701} 651}
702 652
703/* 653static void cfq_deactivate_request(request_queue_t *q, struct request *rq)
704 * make sure the service time gets corrected on reissue of this request
705 */
706static void cfq_requeue_request(request_queue_t *q, struct request *rq)
707{ 654{
708 cfq_deactivate_request(q, rq); 655 struct cfq_data *cfqd = q->elevator->elevator_data;
709 list_add(&rq->queuelist, &q->queue_head); 656
657 WARN_ON(!cfqd->rq_in_driver);
658 cfqd->rq_in_driver--;
710} 659}
711 660
712static void cfq_remove_request(request_queue_t *q, struct request *rq) 661static void cfq_remove_request(struct request *rq)
713{ 662{
714 struct cfq_rq *crq = RQ_DATA(rq); 663 struct cfq_rq *crq = RQ_DATA(rq);
715 664
716 if (crq) { 665 list_del_init(&rq->queuelist);
717 list_del_init(&rq->queuelist); 666 cfq_del_crq_rb(crq);
718 cfq_del_crq_rb(crq); 667 cfq_del_crq_hash(crq);
719 cfq_remove_merge_hints(q, crq);
720
721 }
722} 668}
723 669
724static int 670static int
@@ -728,12 +674,6 @@ cfq_merge(request_queue_t *q, struct request **req, struct bio *bio)
728 struct request *__rq; 674 struct request *__rq;
729 int ret; 675 int ret;
730 676
731 ret = elv_try_last_merge(q, bio);
732 if (ret != ELEVATOR_NO_MERGE) {
733 __rq = q->last_merge;
734 goto out_insert;
735 }
736
737 __rq = cfq_find_rq_hash(cfqd, bio->bi_sector); 677 __rq = cfq_find_rq_hash(cfqd, bio->bi_sector);
738 if (__rq && elv_rq_merge_ok(__rq, bio)) { 678 if (__rq && elv_rq_merge_ok(__rq, bio)) {
739 ret = ELEVATOR_BACK_MERGE; 679 ret = ELEVATOR_BACK_MERGE;
@@ -748,8 +688,6 @@ cfq_merge(request_queue_t *q, struct request **req, struct bio *bio)
748 688
749 return ELEVATOR_NO_MERGE; 689 return ELEVATOR_NO_MERGE;
750out: 690out:
751 q->last_merge = __rq;
752out_insert:
753 *req = __rq; 691 *req = __rq;
754 return ret; 692 return ret;
755} 693}
@@ -762,14 +700,12 @@ static void cfq_merged_request(request_queue_t *q, struct request *req)
762 cfq_del_crq_hash(crq); 700 cfq_del_crq_hash(crq);
763 cfq_add_crq_hash(cfqd, crq); 701 cfq_add_crq_hash(cfqd, crq);
764 702
765 if (ON_RB(&crq->rb_node) && (rq_rb_key(req) != crq->rb_key)) { 703 if (rq_rb_key(req) != crq->rb_key) {
766 struct cfq_queue *cfqq = crq->cfq_queue; 704 struct cfq_queue *cfqq = crq->cfq_queue;
767 705
768 cfq_update_next_crq(crq); 706 cfq_update_next_crq(crq);
769 cfq_reposition_crq_rb(cfqq, crq); 707 cfq_reposition_crq_rb(cfqq, crq);
770 } 708 }
771
772 q->last_merge = req;
773} 709}
774 710
775static void 711static void
@@ -785,7 +721,7 @@ cfq_merged_requests(request_queue_t *q, struct request *rq,
785 time_before(next->start_time, rq->start_time)) 721 time_before(next->start_time, rq->start_time))
786 list_move(&rq->queuelist, &next->queuelist); 722 list_move(&rq->queuelist, &next->queuelist);
787 723
788 cfq_remove_request(q, next); 724 cfq_remove_request(next);
789} 725}
790 726
791static inline void 727static inline void
@@ -992,53 +928,15 @@ static int cfq_arm_slice_timer(struct cfq_data *cfqd, struct cfq_queue *cfqq)
992 return 1; 928 return 1;
993} 929}
994 930
995/* 931static void cfq_dispatch_insert(request_queue_t *q, struct cfq_rq *crq)
996 * we dispatch cfqd->cfq_quantum requests in total from the rr_list queues,
997 * this function sector sorts the selected request to minimize seeks. we start
998 * at cfqd->last_sector, not 0.
999 */
1000static void cfq_dispatch_sort(request_queue_t *q, struct cfq_rq *crq)
1001{ 932{
1002 struct cfq_data *cfqd = q->elevator->elevator_data; 933 struct cfq_data *cfqd = q->elevator->elevator_data;
1003 struct cfq_queue *cfqq = crq->cfq_queue; 934 struct cfq_queue *cfqq = crq->cfq_queue;
1004 struct list_head *head = &q->queue_head, *entry = head;
1005 struct request *__rq;
1006 sector_t last;
1007
1008 list_del(&crq->request->queuelist);
1009
1010 last = cfqd->last_sector;
1011 list_for_each_entry_reverse(__rq, head, queuelist) {
1012 struct cfq_rq *__crq = RQ_DATA(__rq);
1013
1014 if (blk_barrier_rq(__rq))
1015 break;
1016 if (!blk_fs_request(__rq))
1017 break;
1018 if (cfq_crq_requeued(__crq))
1019 break;
1020
1021 if (__rq->sector <= crq->request->sector)
1022 break;
1023 if (__rq->sector > last && crq->request->sector < last) {
1024 last = crq->request->sector + crq->request->nr_sectors;
1025 break;
1026 }
1027 entry = &__rq->queuelist;
1028 }
1029
1030 cfqd->last_sector = last;
1031 935
1032 cfqq->next_crq = cfq_find_next_crq(cfqd, cfqq, crq); 936 cfqq->next_crq = cfq_find_next_crq(cfqd, cfqq, crq);
1033 937 cfq_remove_request(crq->request);
1034 cfq_del_crq_rb(crq);
1035 cfq_remove_merge_hints(q, crq);
1036
1037 cfq_mark_crq_in_flight(crq);
1038 cfq_clear_crq_requeued(crq);
1039
1040 cfqq->on_dispatch[cfq_crq_is_sync(crq)]++; 938 cfqq->on_dispatch[cfq_crq_is_sync(crq)]++;
1041 list_add_tail(&crq->request->queuelist, entry); 939 elv_dispatch_sort(q, crq->request);
1042} 940}
1043 941
1044/* 942/*
@@ -1159,7 +1057,7 @@ __cfq_dispatch_requests(struct cfq_data *cfqd, struct cfq_queue *cfqq,
1159 /* 1057 /*
1160 * finally, insert request into driver dispatch list 1058 * finally, insert request into driver dispatch list
1161 */ 1059 */
1162 cfq_dispatch_sort(cfqd->queue, crq); 1060 cfq_dispatch_insert(cfqd->queue, crq);
1163 1061
1164 cfqd->dispatch_slice++; 1062 cfqd->dispatch_slice++;
1165 dispatched++; 1063 dispatched++;
@@ -1194,7 +1092,7 @@ __cfq_dispatch_requests(struct cfq_data *cfqd, struct cfq_queue *cfqq,
1194} 1092}
1195 1093
1196static int 1094static int
1197cfq_dispatch_requests(request_queue_t *q, int max_dispatch, int force) 1095cfq_dispatch_requests(request_queue_t *q, int force)
1198{ 1096{
1199 struct cfq_data *cfqd = q->elevator->elevator_data; 1097 struct cfq_data *cfqd = q->elevator->elevator_data;
1200 struct cfq_queue *cfqq; 1098 struct cfq_queue *cfqq;
@@ -1204,12 +1102,25 @@ cfq_dispatch_requests(request_queue_t *q, int max_dispatch, int force)
1204 1102
1205 cfqq = cfq_select_queue(cfqd, force); 1103 cfqq = cfq_select_queue(cfqd, force);
1206 if (cfqq) { 1104 if (cfqq) {
1105 int max_dispatch;
1106
1107 /*
1108 * if idle window is disabled, allow queue buildup
1109 */
1110 if (!cfq_cfqq_idle_window(cfqq) &&
1111 cfqd->rq_in_driver >= cfqd->cfq_max_depth)
1112 return 0;
1113
1207 cfq_clear_cfqq_must_dispatch(cfqq); 1114 cfq_clear_cfqq_must_dispatch(cfqq);
1208 cfq_clear_cfqq_wait_request(cfqq); 1115 cfq_clear_cfqq_wait_request(cfqq);
1209 del_timer(&cfqd->idle_slice_timer); 1116 del_timer(&cfqd->idle_slice_timer);
1210 1117
1211 if (cfq_class_idle(cfqq)) 1118 if (!force) {
1212 max_dispatch = 1; 1119 max_dispatch = cfqd->cfq_quantum;
1120 if (cfq_class_idle(cfqq))
1121 max_dispatch = 1;
1122 } else
1123 max_dispatch = INT_MAX;
1213 1124
1214 return __cfq_dispatch_requests(cfqd, cfqq, max_dispatch); 1125 return __cfq_dispatch_requests(cfqd, cfqq, max_dispatch);
1215 } 1126 }
@@ -1217,93 +1128,6 @@ cfq_dispatch_requests(request_queue_t *q, int max_dispatch, int force)
1217 return 0; 1128 return 0;
1218} 1129}
1219 1130
1220static inline void cfq_account_dispatch(struct cfq_rq *crq)
1221{
1222 struct cfq_queue *cfqq = crq->cfq_queue;
1223 struct cfq_data *cfqd = cfqq->cfqd;
1224
1225 if (unlikely(!blk_fs_request(crq->request)))
1226 return;
1227
1228 /*
1229 * accounted bit is necessary since some drivers will call
1230 * elv_next_request() many times for the same request (eg ide)
1231 */
1232 if (cfq_crq_in_driver(crq))
1233 return;
1234
1235 cfq_mark_crq_in_driver(crq);
1236 cfqd->rq_in_driver++;
1237}
1238
1239static inline void
1240cfq_account_completion(struct cfq_queue *cfqq, struct cfq_rq *crq)
1241{
1242 struct cfq_data *cfqd = cfqq->cfqd;
1243 unsigned long now;
1244
1245 if (!cfq_crq_in_driver(crq))
1246 return;
1247
1248 now = jiffies;
1249
1250 WARN_ON(!cfqd->rq_in_driver);
1251 cfqd->rq_in_driver--;
1252
1253 if (!cfq_class_idle(cfqq))
1254 cfqd->last_end_request = now;
1255
1256 if (!cfq_cfqq_dispatched(cfqq)) {
1257 if (cfq_cfqq_on_rr(cfqq)) {
1258 cfqq->service_last = now;
1259 cfq_resort_rr_list(cfqq, 0);
1260 }
1261 if (cfq_cfqq_expired(cfqq)) {
1262 __cfq_slice_expired(cfqd, cfqq, 0);
1263 cfq_schedule_dispatch(cfqd);
1264 }
1265 }
1266
1267 if (cfq_crq_is_sync(crq))
1268 crq->io_context->last_end_request = now;
1269}
1270
1271static struct request *cfq_next_request(request_queue_t *q)
1272{
1273 struct cfq_data *cfqd = q->elevator->elevator_data;
1274 struct request *rq;
1275
1276 if (!list_empty(&q->queue_head)) {
1277 struct cfq_rq *crq;
1278dispatch:
1279 rq = list_entry_rq(q->queue_head.next);
1280
1281 crq = RQ_DATA(rq);
1282 if (crq) {
1283 struct cfq_queue *cfqq = crq->cfq_queue;
1284
1285 /*
1286 * if idle window is disabled, allow queue buildup
1287 */
1288 if (!cfq_crq_in_driver(crq) &&
1289 !cfq_cfqq_idle_window(cfqq) &&
1290 !blk_barrier_rq(rq) &&
1291 cfqd->rq_in_driver >= cfqd->cfq_max_depth)
1292 return NULL;
1293
1294 cfq_remove_merge_hints(q, crq);
1295 cfq_account_dispatch(crq);
1296 }
1297
1298 return rq;
1299 }
1300
1301 if (cfq_dispatch_requests(q, cfqd->cfq_quantum, 0))
1302 goto dispatch;
1303
1304 return NULL;
1305}
1306
1307/* 1131/*
1308 * task holds one reference to the queue, dropped when task exits. each crq 1132 * task holds one reference to the queue, dropped when task exits. each crq
1309 * in-flight on this queue also holds a reference, dropped when crq is freed. 1133 * in-flight on this queue also holds a reference, dropped when crq is freed.
@@ -1422,7 +1246,7 @@ static void cfq_exit_io_context(struct cfq_io_context *cic)
1422} 1246}
1423 1247
1424static struct cfq_io_context * 1248static struct cfq_io_context *
1425cfq_alloc_io_context(struct cfq_data *cfqd, int gfp_mask) 1249cfq_alloc_io_context(struct cfq_data *cfqd, gfp_t gfp_mask)
1426{ 1250{
1427 struct cfq_io_context *cic = kmem_cache_alloc(cfq_ioc_pool, gfp_mask); 1251 struct cfq_io_context *cic = kmem_cache_alloc(cfq_ioc_pool, gfp_mask);
1428 1252
@@ -1517,7 +1341,7 @@ static int cfq_ioc_set_ioprio(struct io_context *ioc, unsigned int ioprio)
1517 1341
1518static struct cfq_queue * 1342static struct cfq_queue *
1519cfq_get_queue(struct cfq_data *cfqd, unsigned int key, unsigned short ioprio, 1343cfq_get_queue(struct cfq_data *cfqd, unsigned int key, unsigned short ioprio,
1520 int gfp_mask) 1344 gfp_t gfp_mask)
1521{ 1345{
1522 const int hashval = hash_long(key, CFQ_QHASH_SHIFT); 1346 const int hashval = hash_long(key, CFQ_QHASH_SHIFT);
1523 struct cfq_queue *cfqq, *new_cfqq = NULL; 1347 struct cfq_queue *cfqq, *new_cfqq = NULL;
@@ -1578,7 +1402,7 @@ out:
1578 * cfqq, so we don't need to worry about it disappearing 1402 * cfqq, so we don't need to worry about it disappearing
1579 */ 1403 */
1580static struct cfq_io_context * 1404static struct cfq_io_context *
1581cfq_get_io_context(struct cfq_data *cfqd, pid_t pid, int gfp_mask) 1405cfq_get_io_context(struct cfq_data *cfqd, pid_t pid, gfp_t gfp_mask)
1582{ 1406{
1583 struct io_context *ioc = NULL; 1407 struct io_context *ioc = NULL;
1584 struct cfq_io_context *cic; 1408 struct cfq_io_context *cic;
@@ -1816,8 +1640,9 @@ cfq_crq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq,
1816 } 1640 }
1817} 1641}
1818 1642
1819static void cfq_enqueue(struct cfq_data *cfqd, struct request *rq) 1643static void cfq_insert_request(request_queue_t *q, struct request *rq)
1820{ 1644{
1645 struct cfq_data *cfqd = q->elevator->elevator_data;
1821 struct cfq_rq *crq = RQ_DATA(rq); 1646 struct cfq_rq *crq = RQ_DATA(rq);
1822 struct cfq_queue *cfqq = crq->cfq_queue; 1647 struct cfq_queue *cfqq = crq->cfq_queue;
1823 1648
@@ -1827,66 +1652,43 @@ static void cfq_enqueue(struct cfq_data *cfqd, struct request *rq)
1827 1652
1828 list_add_tail(&rq->queuelist, &cfqq->fifo); 1653 list_add_tail(&rq->queuelist, &cfqq->fifo);
1829 1654
1830 if (rq_mergeable(rq)) { 1655 if (rq_mergeable(rq))
1831 cfq_add_crq_hash(cfqd, crq); 1656 cfq_add_crq_hash(cfqd, crq);
1832 1657
1833 if (!cfqd->queue->last_merge)
1834 cfqd->queue->last_merge = rq;
1835 }
1836
1837 cfq_crq_enqueued(cfqd, cfqq, crq); 1658 cfq_crq_enqueued(cfqd, cfqq, crq);
1838} 1659}
1839 1660
1840static void
1841cfq_insert_request(request_queue_t *q, struct request *rq, int where)
1842{
1843 struct cfq_data *cfqd = q->elevator->elevator_data;
1844
1845 switch (where) {
1846 case ELEVATOR_INSERT_BACK:
1847 while (cfq_dispatch_requests(q, INT_MAX, 1))
1848 ;
1849 list_add_tail(&rq->queuelist, &q->queue_head);
1850 /*
1851 * If we were idling with pending requests on
1852 * inactive cfqqs, force dispatching will
1853 * remove the idle timer and the queue won't
1854 * be kicked by __make_request() afterward.
1855 * Kick it here.
1856 */
1857 cfq_schedule_dispatch(cfqd);
1858 break;
1859 case ELEVATOR_INSERT_FRONT:
1860 list_add(&rq->queuelist, &q->queue_head);
1861 break;
1862 case ELEVATOR_INSERT_SORT:
1863 BUG_ON(!blk_fs_request(rq));
1864 cfq_enqueue(cfqd, rq);
1865 break;
1866 default:
1867 printk("%s: bad insert point %d\n", __FUNCTION__,where);
1868 return;
1869 }
1870}
1871
1872static void cfq_completed_request(request_queue_t *q, struct request *rq) 1661static void cfq_completed_request(request_queue_t *q, struct request *rq)
1873{ 1662{
1874 struct cfq_rq *crq = RQ_DATA(rq); 1663 struct cfq_rq *crq = RQ_DATA(rq);
1875 struct cfq_queue *cfqq; 1664 struct cfq_queue *cfqq = crq->cfq_queue;
1665 struct cfq_data *cfqd = cfqq->cfqd;
1666 const int sync = cfq_crq_is_sync(crq);
1667 unsigned long now;
1876 1668
1877 if (unlikely(!blk_fs_request(rq))) 1669 now = jiffies;
1878 return;
1879 1670
1880 cfqq = crq->cfq_queue; 1671 WARN_ON(!cfqd->rq_in_driver);
1672 WARN_ON(!cfqq->on_dispatch[sync]);
1673 cfqd->rq_in_driver--;
1674 cfqq->on_dispatch[sync]--;
1881 1675
1882 if (cfq_crq_in_flight(crq)) { 1676 if (!cfq_class_idle(cfqq))
1883 const int sync = cfq_crq_is_sync(crq); 1677 cfqd->last_end_request = now;
1884 1678
1885 WARN_ON(!cfqq->on_dispatch[sync]); 1679 if (!cfq_cfqq_dispatched(cfqq)) {
1886 cfqq->on_dispatch[sync]--; 1680 if (cfq_cfqq_on_rr(cfqq)) {
1681 cfqq->service_last = now;
1682 cfq_resort_rr_list(cfqq, 0);
1683 }
1684 if (cfq_cfqq_expired(cfqq)) {
1685 __cfq_slice_expired(cfqd, cfqq, 0);
1686 cfq_schedule_dispatch(cfqd);
1687 }
1887 } 1688 }
1888 1689
1889 cfq_account_completion(cfqq, crq); 1690 if (cfq_crq_is_sync(crq))
1691 crq->io_context->last_end_request = now;
1890} 1692}
1891 1693
1892static struct request * 1694static struct request *
@@ -2075,7 +1877,7 @@ static void cfq_put_request(request_queue_t *q, struct request *rq)
2075 */ 1877 */
2076static int 1878static int
2077cfq_set_request(request_queue_t *q, struct request *rq, struct bio *bio, 1879cfq_set_request(request_queue_t *q, struct request *rq, struct bio *bio,
2078 int gfp_mask) 1880 gfp_t gfp_mask)
2079{ 1881{
2080 struct cfq_data *cfqd = q->elevator->elevator_data; 1882 struct cfq_data *cfqd = q->elevator->elevator_data;
2081 struct task_struct *tsk = current; 1883 struct task_struct *tsk = current;
@@ -2118,9 +1920,6 @@ cfq_set_request(request_queue_t *q, struct request *rq, struct bio *bio,
2118 INIT_HLIST_NODE(&crq->hash); 1920 INIT_HLIST_NODE(&crq->hash);
2119 crq->cfq_queue = cfqq; 1921 crq->cfq_queue = cfqq;
2120 crq->io_context = cic; 1922 crq->io_context = cic;
2121 cfq_clear_crq_in_flight(crq);
2122 cfq_clear_crq_in_driver(crq);
2123 cfq_clear_crq_requeued(crq);
2124 1923
2125 if (rw == READ || process_sync(tsk)) 1924 if (rw == READ || process_sync(tsk))
2126 cfq_mark_crq_is_sync(crq); 1925 cfq_mark_crq_is_sync(crq);
@@ -2201,7 +2000,7 @@ static void cfq_idle_slice_timer(unsigned long data)
2201 * only expire and reinvoke request handler, if there are 2000 * only expire and reinvoke request handler, if there are
2202 * other queues with pending requests 2001 * other queues with pending requests
2203 */ 2002 */
2204 if (!cfq_pending_requests(cfqd)) { 2003 if (!cfqd->busy_queues) {
2205 cfqd->idle_slice_timer.expires = min(now + cfqd->cfq_slice_idle, cfqq->slice_end); 2004 cfqd->idle_slice_timer.expires = min(now + cfqd->cfq_slice_idle, cfqq->slice_end);
2206 add_timer(&cfqd->idle_slice_timer); 2005 add_timer(&cfqd->idle_slice_timer);
2207 goto out_cont; 2006 goto out_cont;
@@ -2576,10 +2375,9 @@ static struct elevator_type iosched_cfq = {
2576 .elevator_merge_fn = cfq_merge, 2375 .elevator_merge_fn = cfq_merge,
2577 .elevator_merged_fn = cfq_merged_request, 2376 .elevator_merged_fn = cfq_merged_request,
2578 .elevator_merge_req_fn = cfq_merged_requests, 2377 .elevator_merge_req_fn = cfq_merged_requests,
2579 .elevator_next_req_fn = cfq_next_request, 2378 .elevator_dispatch_fn = cfq_dispatch_requests,
2580 .elevator_add_req_fn = cfq_insert_request, 2379 .elevator_add_req_fn = cfq_insert_request,
2581 .elevator_remove_req_fn = cfq_remove_request, 2380 .elevator_activate_req_fn = cfq_activate_request,
2582 .elevator_requeue_req_fn = cfq_requeue_request,
2583 .elevator_deactivate_req_fn = cfq_deactivate_request, 2381 .elevator_deactivate_req_fn = cfq_deactivate_request,
2584 .elevator_queue_empty_fn = cfq_queue_empty, 2382 .elevator_queue_empty_fn = cfq_queue_empty,
2585 .elevator_completed_req_fn = cfq_completed_request, 2383 .elevator_completed_req_fn = cfq_completed_request,
@@ -2620,28 +2418,8 @@ static int __init cfq_init(void)
2620 2418
2621static void __exit cfq_exit(void) 2419static void __exit cfq_exit(void)
2622{ 2420{
2623 struct task_struct *g, *p;
2624 unsigned long flags;
2625
2626 read_lock_irqsave(&tasklist_lock, flags);
2627
2628 /*
2629 * iterate each process in the system, removing our io_context
2630 */
2631 do_each_thread(g, p) {
2632 struct io_context *ioc = p->io_context;
2633
2634 if (ioc && ioc->cic) {
2635 ioc->cic->exit(ioc->cic);
2636 cfq_free_io_context(ioc->cic);
2637 ioc->cic = NULL;
2638 }
2639 } while_each_thread(g, p);
2640
2641 read_unlock_irqrestore(&tasklist_lock, flags);
2642
2643 cfq_slab_kill();
2644 elv_unregister(&iosched_cfq); 2421 elv_unregister(&iosched_cfq);
2422 cfq_slab_kill();
2645} 2423}
2646 2424
2647module_init(cfq_init); 2425module_init(cfq_init);
diff --git a/drivers/block/deadline-iosched.c b/drivers/block/deadline-iosched.c
index 52a3ae5289a0..7929471d7df7 100644
--- a/drivers/block/deadline-iosched.c
+++ b/drivers/block/deadline-iosched.c
@@ -50,7 +50,6 @@ struct deadline_data {
50 * next in sort order. read, write or both are NULL 50 * next in sort order. read, write or both are NULL
51 */ 51 */
52 struct deadline_rq *next_drq[2]; 52 struct deadline_rq *next_drq[2];
53 struct list_head *dispatch; /* driver dispatch queue */
54 struct list_head *hash; /* request hash */ 53 struct list_head *hash; /* request hash */
55 unsigned int batching; /* number of sequential requests made */ 54 unsigned int batching; /* number of sequential requests made */
56 sector_t last_sector; /* head position */ 55 sector_t last_sector; /* head position */
@@ -113,15 +112,6 @@ static inline void deadline_del_drq_hash(struct deadline_rq *drq)
113 __deadline_del_drq_hash(drq); 112 __deadline_del_drq_hash(drq);
114} 113}
115 114
116static void
117deadline_remove_merge_hints(request_queue_t *q, struct deadline_rq *drq)
118{
119 deadline_del_drq_hash(drq);
120
121 if (q->last_merge == drq->request)
122 q->last_merge = NULL;
123}
124
125static inline void 115static inline void
126deadline_add_drq_hash(struct deadline_data *dd, struct deadline_rq *drq) 116deadline_add_drq_hash(struct deadline_data *dd, struct deadline_rq *drq)
127{ 117{
@@ -239,10 +229,9 @@ deadline_del_drq_rb(struct deadline_data *dd, struct deadline_rq *drq)
239 dd->next_drq[data_dir] = rb_entry_drq(rbnext); 229 dd->next_drq[data_dir] = rb_entry_drq(rbnext);
240 } 230 }
241 231
242 if (ON_RB(&drq->rb_node)) { 232 BUG_ON(!ON_RB(&drq->rb_node));
243 rb_erase(&drq->rb_node, DRQ_RB_ROOT(dd, drq)); 233 rb_erase(&drq->rb_node, DRQ_RB_ROOT(dd, drq));
244 RB_CLEAR(&drq->rb_node); 234 RB_CLEAR(&drq->rb_node);
245 }
246} 235}
247 236
248static struct request * 237static struct request *
@@ -286,7 +275,7 @@ deadline_find_first_drq(struct deadline_data *dd, int data_dir)
286/* 275/*
287 * add drq to rbtree and fifo 276 * add drq to rbtree and fifo
288 */ 277 */
289static inline void 278static void
290deadline_add_request(struct request_queue *q, struct request *rq) 279deadline_add_request(struct request_queue *q, struct request *rq)
291{ 280{
292 struct deadline_data *dd = q->elevator->elevator_data; 281 struct deadline_data *dd = q->elevator->elevator_data;
@@ -301,12 +290,8 @@ deadline_add_request(struct request_queue *q, struct request *rq)
301 drq->expires = jiffies + dd->fifo_expire[data_dir]; 290 drq->expires = jiffies + dd->fifo_expire[data_dir];
302 list_add_tail(&drq->fifo, &dd->fifo_list[data_dir]); 291 list_add_tail(&drq->fifo, &dd->fifo_list[data_dir]);
303 292
304 if (rq_mergeable(rq)) { 293 if (rq_mergeable(rq))
305 deadline_add_drq_hash(dd, drq); 294 deadline_add_drq_hash(dd, drq);
306
307 if (!q->last_merge)
308 q->last_merge = rq;
309 }
310} 295}
311 296
312/* 297/*
@@ -315,14 +300,11 @@ deadline_add_request(struct request_queue *q, struct request *rq)
315static void deadline_remove_request(request_queue_t *q, struct request *rq) 300static void deadline_remove_request(request_queue_t *q, struct request *rq)
316{ 301{
317 struct deadline_rq *drq = RQ_DATA(rq); 302 struct deadline_rq *drq = RQ_DATA(rq);
303 struct deadline_data *dd = q->elevator->elevator_data;
318 304
319 if (drq) { 305 list_del_init(&drq->fifo);
320 struct deadline_data *dd = q->elevator->elevator_data; 306 deadline_del_drq_rb(dd, drq);
321 307 deadline_del_drq_hash(drq);
322 list_del_init(&drq->fifo);
323 deadline_remove_merge_hints(q, drq);
324 deadline_del_drq_rb(dd, drq);
325 }
326} 308}
327 309
328static int 310static int
@@ -333,15 +315,6 @@ deadline_merge(request_queue_t *q, struct request **req, struct bio *bio)
333 int ret; 315 int ret;
334 316
335 /* 317 /*
336 * try last_merge to avoid going to hash
337 */
338 ret = elv_try_last_merge(q, bio);
339 if (ret != ELEVATOR_NO_MERGE) {
340 __rq = q->last_merge;
341 goto out_insert;
342 }
343
344 /*
345 * see if the merge hash can satisfy a back merge 318 * see if the merge hash can satisfy a back merge
346 */ 319 */
347 __rq = deadline_find_drq_hash(dd, bio->bi_sector); 320 __rq = deadline_find_drq_hash(dd, bio->bi_sector);
@@ -373,8 +346,6 @@ deadline_merge(request_queue_t *q, struct request **req, struct bio *bio)
373 346
374 return ELEVATOR_NO_MERGE; 347 return ELEVATOR_NO_MERGE;
375out: 348out:
376 q->last_merge = __rq;
377out_insert:
378 if (ret) 349 if (ret)
379 deadline_hot_drq_hash(dd, RQ_DATA(__rq)); 350 deadline_hot_drq_hash(dd, RQ_DATA(__rq));
380 *req = __rq; 351 *req = __rq;
@@ -399,8 +370,6 @@ static void deadline_merged_request(request_queue_t *q, struct request *req)
399 deadline_del_drq_rb(dd, drq); 370 deadline_del_drq_rb(dd, drq);
400 deadline_add_drq_rb(dd, drq); 371 deadline_add_drq_rb(dd, drq);
401 } 372 }
402
403 q->last_merge = req;
404} 373}
405 374
406static void 375static void
@@ -452,7 +421,7 @@ deadline_move_to_dispatch(struct deadline_data *dd, struct deadline_rq *drq)
452 request_queue_t *q = drq->request->q; 421 request_queue_t *q = drq->request->q;
453 422
454 deadline_remove_request(q, drq->request); 423 deadline_remove_request(q, drq->request);
455 list_add_tail(&drq->request->queuelist, dd->dispatch); 424 elv_dispatch_add_tail(q, drq->request);
456} 425}
457 426
458/* 427/*
@@ -502,8 +471,9 @@ static inline int deadline_check_fifo(struct deadline_data *dd, int ddir)
502 * deadline_dispatch_requests selects the best request according to 471 * deadline_dispatch_requests selects the best request according to
503 * read/write expire, fifo_batch, etc 472 * read/write expire, fifo_batch, etc
504 */ 473 */
505static int deadline_dispatch_requests(struct deadline_data *dd) 474static int deadline_dispatch_requests(request_queue_t *q, int force)
506{ 475{
476 struct deadline_data *dd = q->elevator->elevator_data;
507 const int reads = !list_empty(&dd->fifo_list[READ]); 477 const int reads = !list_empty(&dd->fifo_list[READ]);
508 const int writes = !list_empty(&dd->fifo_list[WRITE]); 478 const int writes = !list_empty(&dd->fifo_list[WRITE]);
509 struct deadline_rq *drq; 479 struct deadline_rq *drq;
@@ -597,65 +567,12 @@ dispatch_request:
597 return 1; 567 return 1;
598} 568}
599 569
600static struct request *deadline_next_request(request_queue_t *q)
601{
602 struct deadline_data *dd = q->elevator->elevator_data;
603 struct request *rq;
604
605 /*
606 * if there are still requests on the dispatch queue, grab the first one
607 */
608 if (!list_empty(dd->dispatch)) {
609dispatch:
610 rq = list_entry_rq(dd->dispatch->next);
611 return rq;
612 }
613
614 if (deadline_dispatch_requests(dd))
615 goto dispatch;
616
617 return NULL;
618}
619
620static void
621deadline_insert_request(request_queue_t *q, struct request *rq, int where)
622{
623 struct deadline_data *dd = q->elevator->elevator_data;
624
625 /* barriers must flush the reorder queue */
626 if (unlikely(rq->flags & (REQ_SOFTBARRIER | REQ_HARDBARRIER)
627 && where == ELEVATOR_INSERT_SORT))
628 where = ELEVATOR_INSERT_BACK;
629
630 switch (where) {
631 case ELEVATOR_INSERT_BACK:
632 while (deadline_dispatch_requests(dd))
633 ;
634 list_add_tail(&rq->queuelist, dd->dispatch);
635 break;
636 case ELEVATOR_INSERT_FRONT:
637 list_add(&rq->queuelist, dd->dispatch);
638 break;
639 case ELEVATOR_INSERT_SORT:
640 BUG_ON(!blk_fs_request(rq));
641 deadline_add_request(q, rq);
642 break;
643 default:
644 printk("%s: bad insert point %d\n", __FUNCTION__,where);
645 return;
646 }
647}
648
649static int deadline_queue_empty(request_queue_t *q) 570static int deadline_queue_empty(request_queue_t *q)
650{ 571{
651 struct deadline_data *dd = q->elevator->elevator_data; 572 struct deadline_data *dd = q->elevator->elevator_data;
652 573
653 if (!list_empty(&dd->fifo_list[WRITE]) 574 return list_empty(&dd->fifo_list[WRITE])
654 || !list_empty(&dd->fifo_list[READ]) 575 && list_empty(&dd->fifo_list[READ]);
655 || !list_empty(dd->dispatch))
656 return 0;
657
658 return 1;
659} 576}
660 577
661static struct request * 578static struct request *
@@ -733,7 +650,6 @@ static int deadline_init_queue(request_queue_t *q, elevator_t *e)
733 INIT_LIST_HEAD(&dd->fifo_list[WRITE]); 650 INIT_LIST_HEAD(&dd->fifo_list[WRITE]);
734 dd->sort_list[READ] = RB_ROOT; 651 dd->sort_list[READ] = RB_ROOT;
735 dd->sort_list[WRITE] = RB_ROOT; 652 dd->sort_list[WRITE] = RB_ROOT;
736 dd->dispatch = &q->queue_head;
737 dd->fifo_expire[READ] = read_expire; 653 dd->fifo_expire[READ] = read_expire;
738 dd->fifo_expire[WRITE] = write_expire; 654 dd->fifo_expire[WRITE] = write_expire;
739 dd->writes_starved = writes_starved; 655 dd->writes_starved = writes_starved;
@@ -748,15 +664,13 @@ static void deadline_put_request(request_queue_t *q, struct request *rq)
748 struct deadline_data *dd = q->elevator->elevator_data; 664 struct deadline_data *dd = q->elevator->elevator_data;
749 struct deadline_rq *drq = RQ_DATA(rq); 665 struct deadline_rq *drq = RQ_DATA(rq);
750 666
751 if (drq) { 667 mempool_free(drq, dd->drq_pool);
752 mempool_free(drq, dd->drq_pool); 668 rq->elevator_private = NULL;
753 rq->elevator_private = NULL;
754 }
755} 669}
756 670
757static int 671static int
758deadline_set_request(request_queue_t *q, struct request *rq, struct bio *bio, 672deadline_set_request(request_queue_t *q, struct request *rq, struct bio *bio,
759 int gfp_mask) 673 gfp_t gfp_mask)
760{ 674{
761 struct deadline_data *dd = q->elevator->elevator_data; 675 struct deadline_data *dd = q->elevator->elevator_data;
762 struct deadline_rq *drq; 676 struct deadline_rq *drq;
@@ -917,9 +831,8 @@ static struct elevator_type iosched_deadline = {
917 .elevator_merge_fn = deadline_merge, 831 .elevator_merge_fn = deadline_merge,
918 .elevator_merged_fn = deadline_merged_request, 832 .elevator_merged_fn = deadline_merged_request,
919 .elevator_merge_req_fn = deadline_merged_requests, 833 .elevator_merge_req_fn = deadline_merged_requests,
920 .elevator_next_req_fn = deadline_next_request, 834 .elevator_dispatch_fn = deadline_dispatch_requests,
921 .elevator_add_req_fn = deadline_insert_request, 835 .elevator_add_req_fn = deadline_add_request,
922 .elevator_remove_req_fn = deadline_remove_request,
923 .elevator_queue_empty_fn = deadline_queue_empty, 836 .elevator_queue_empty_fn = deadline_queue_empty,
924 .elevator_former_req_fn = deadline_former_request, 837 .elevator_former_req_fn = deadline_former_request,
925 .elevator_latter_req_fn = deadline_latter_request, 838 .elevator_latter_req_fn = deadline_latter_request,
diff --git a/drivers/block/elevator.c b/drivers/block/elevator.c
index 98f0126a2deb..36f1057084b0 100644
--- a/drivers/block/elevator.c
+++ b/drivers/block/elevator.c
@@ -34,6 +34,7 @@
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/compiler.h> 36#include <linux/compiler.h>
37#include <linux/delay.h>
37 38
38#include <asm/uaccess.h> 39#include <asm/uaccess.h>
39 40
@@ -83,21 +84,11 @@ inline int elv_try_merge(struct request *__rq, struct bio *bio)
83} 84}
84EXPORT_SYMBOL(elv_try_merge); 85EXPORT_SYMBOL(elv_try_merge);
85 86
86inline int elv_try_last_merge(request_queue_t *q, struct bio *bio)
87{
88 if (q->last_merge)
89 return elv_try_merge(q->last_merge, bio);
90
91 return ELEVATOR_NO_MERGE;
92}
93EXPORT_SYMBOL(elv_try_last_merge);
94
95static struct elevator_type *elevator_find(const char *name) 87static struct elevator_type *elevator_find(const char *name)
96{ 88{
97 struct elevator_type *e = NULL; 89 struct elevator_type *e = NULL;
98 struct list_head *entry; 90 struct list_head *entry;
99 91
100 spin_lock_irq(&elv_list_lock);
101 list_for_each(entry, &elv_list) { 92 list_for_each(entry, &elv_list) {
102 struct elevator_type *__e; 93 struct elevator_type *__e;
103 94
@@ -108,7 +99,6 @@ static struct elevator_type *elevator_find(const char *name)
108 break; 99 break;
109 } 100 }
110 } 101 }
111 spin_unlock_irq(&elv_list_lock);
112 102
113 return e; 103 return e;
114} 104}
@@ -120,12 +110,15 @@ static void elevator_put(struct elevator_type *e)
120 110
121static struct elevator_type *elevator_get(const char *name) 111static struct elevator_type *elevator_get(const char *name)
122{ 112{
123 struct elevator_type *e = elevator_find(name); 113 struct elevator_type *e;
124 114
125 if (!e) 115 spin_lock_irq(&elv_list_lock);
126 return NULL; 116
127 if (!try_module_get(e->elevator_owner)) 117 e = elevator_find(name);
128 return NULL; 118 if (e && !try_module_get(e->elevator_owner))
119 e = NULL;
120
121 spin_unlock_irq(&elv_list_lock);
129 122
130 return e; 123 return e;
131} 124}
@@ -139,8 +132,6 @@ static int elevator_attach(request_queue_t *q, struct elevator_type *e,
139 eq->ops = &e->ops; 132 eq->ops = &e->ops;
140 eq->elevator_type = e; 133 eq->elevator_type = e;
141 134
142 INIT_LIST_HEAD(&q->queue_head);
143 q->last_merge = NULL;
144 q->elevator = eq; 135 q->elevator = eq;
145 136
146 if (eq->ops->elevator_init_fn) 137 if (eq->ops->elevator_init_fn)
@@ -153,23 +144,20 @@ static char chosen_elevator[16];
153 144
154static void elevator_setup_default(void) 145static void elevator_setup_default(void)
155{ 146{
147 struct elevator_type *e;
148
156 /* 149 /*
157 * check if default is set and exists 150 * If default has not been set, use the compiled-in selection.
158 */ 151 */
159 if (chosen_elevator[0] && elevator_find(chosen_elevator)) 152 if (!chosen_elevator[0])
160 return; 153 strcpy(chosen_elevator, CONFIG_DEFAULT_IOSCHED);
161 154
162#if defined(CONFIG_IOSCHED_AS) 155 /*
163 strcpy(chosen_elevator, "anticipatory"); 156 * If the given scheduler is not available, fall back to no-op.
164#elif defined(CONFIG_IOSCHED_DEADLINE) 157 */
165 strcpy(chosen_elevator, "deadline"); 158 if (!(e = elevator_find(chosen_elevator)))
166#elif defined(CONFIG_IOSCHED_CFQ) 159 strcpy(chosen_elevator, "noop");
167 strcpy(chosen_elevator, "cfq"); 160 elevator_put(e);
168#elif defined(CONFIG_IOSCHED_NOOP)
169 strcpy(chosen_elevator, "noop");
170#else
171#error "You must build at least 1 IO scheduler into the kernel"
172#endif
173} 161}
174 162
175static int __init elevator_setup(char *str) 163static int __init elevator_setup(char *str)
@@ -186,6 +174,11 @@ int elevator_init(request_queue_t *q, char *name)
186 struct elevator_queue *eq; 174 struct elevator_queue *eq;
187 int ret = 0; 175 int ret = 0;
188 176
177 INIT_LIST_HEAD(&q->queue_head);
178 q->last_merge = NULL;
179 q->end_sector = 0;
180 q->boundary_rq = NULL;
181
189 elevator_setup_default(); 182 elevator_setup_default();
190 183
191 if (!name) 184 if (!name)
@@ -220,9 +213,52 @@ void elevator_exit(elevator_t *e)
220 kfree(e); 213 kfree(e);
221} 214}
222 215
216/*
217 * Insert rq into dispatch queue of q. Queue lock must be held on
218 * entry. If sort != 0, rq is sort-inserted; otherwise, rq will be
219 * appended to the dispatch queue. To be used by specific elevators.
220 */
221void elv_dispatch_sort(request_queue_t *q, struct request *rq)
222{
223 sector_t boundary;
224 struct list_head *entry;
225
226 if (q->last_merge == rq)
227 q->last_merge = NULL;
228
229 boundary = q->end_sector;
230
231 list_for_each_prev(entry, &q->queue_head) {
232 struct request *pos = list_entry_rq(entry);
233
234 if (pos->flags & (REQ_SOFTBARRIER|REQ_HARDBARRIER|REQ_STARTED))
235 break;
236 if (rq->sector >= boundary) {
237 if (pos->sector < boundary)
238 continue;
239 } else {
240 if (pos->sector >= boundary)
241 break;
242 }
243 if (rq->sector >= pos->sector)
244 break;
245 }
246
247 list_add(&rq->queuelist, entry);
248}
249
223int elv_merge(request_queue_t *q, struct request **req, struct bio *bio) 250int elv_merge(request_queue_t *q, struct request **req, struct bio *bio)
224{ 251{
225 elevator_t *e = q->elevator; 252 elevator_t *e = q->elevator;
253 int ret;
254
255 if (q->last_merge) {
256 ret = elv_try_merge(q->last_merge, bio);
257 if (ret != ELEVATOR_NO_MERGE) {
258 *req = q->last_merge;
259 return ret;
260 }
261 }
226 262
227 if (e->ops->elevator_merge_fn) 263 if (e->ops->elevator_merge_fn)
228 return e->ops->elevator_merge_fn(q, req, bio); 264 return e->ops->elevator_merge_fn(q, req, bio);
@@ -236,6 +272,8 @@ void elv_merged_request(request_queue_t *q, struct request *rq)
236 272
237 if (e->ops->elevator_merged_fn) 273 if (e->ops->elevator_merged_fn)
238 e->ops->elevator_merged_fn(q, rq); 274 e->ops->elevator_merged_fn(q, rq);
275
276 q->last_merge = rq;
239} 277}
240 278
241void elv_merge_requests(request_queue_t *q, struct request *rq, 279void elv_merge_requests(request_queue_t *q, struct request *rq,
@@ -243,20 +281,13 @@ void elv_merge_requests(request_queue_t *q, struct request *rq,
243{ 281{
244 elevator_t *e = q->elevator; 282 elevator_t *e = q->elevator;
245 283
246 if (q->last_merge == next)
247 q->last_merge = NULL;
248
249 if (e->ops->elevator_merge_req_fn) 284 if (e->ops->elevator_merge_req_fn)
250 e->ops->elevator_merge_req_fn(q, rq, next); 285 e->ops->elevator_merge_req_fn(q, rq, next);
286
287 q->last_merge = rq;
251} 288}
252 289
253/* 290void elv_requeue_request(request_queue_t *q, struct request *rq)
254 * For careful internal use by the block layer. Essentially the same as
255 * a requeue in that it tells the io scheduler that this request is not
256 * active in the driver or hardware anymore, but we don't want the request
257 * added back to the scheduler. Function is not exported.
258 */
259void elv_deactivate_request(request_queue_t *q, struct request *rq)
260{ 291{
261 elevator_t *e = q->elevator; 292 elevator_t *e = q->elevator;
262 293
@@ -264,19 +295,14 @@ void elv_deactivate_request(request_queue_t *q, struct request *rq)
264 * it already went through dequeue, we need to decrement the 295 * it already went through dequeue, we need to decrement the
265 * in_flight count again 296 * in_flight count again
266 */ 297 */
267 if (blk_account_rq(rq)) 298 if (blk_account_rq(rq)) {
268 q->in_flight--; 299 q->in_flight--;
300 if (blk_sorted_rq(rq) && e->ops->elevator_deactivate_req_fn)
301 e->ops->elevator_deactivate_req_fn(q, rq);
302 }
269 303
270 rq->flags &= ~REQ_STARTED; 304 rq->flags &= ~REQ_STARTED;
271 305
272 if (e->ops->elevator_deactivate_req_fn)
273 e->ops->elevator_deactivate_req_fn(q, rq);
274}
275
276void elv_requeue_request(request_queue_t *q, struct request *rq)
277{
278 elv_deactivate_request(q, rq);
279
280 /* 306 /*
281 * if this is the flush, requeue the original instead and drop the flush 307 * if this is the flush, requeue the original instead and drop the flush
282 */ 308 */
@@ -285,31 +311,27 @@ void elv_requeue_request(request_queue_t *q, struct request *rq)
285 rq = rq->end_io_data; 311 rq = rq->end_io_data;
286 } 312 }
287 313
288 /* 314 __elv_add_request(q, rq, ELEVATOR_INSERT_FRONT, 0);
289 * the request is prepped and may have some resources allocated.
290 * allowing unprepped requests to pass this one may cause resource
291 * deadlock. turn on softbarrier.
292 */
293 rq->flags |= REQ_SOFTBARRIER;
294
295 /*
296 * if iosched has an explicit requeue hook, then use that. otherwise
297 * just put the request at the front of the queue
298 */
299 if (q->elevator->ops->elevator_requeue_req_fn)
300 q->elevator->ops->elevator_requeue_req_fn(q, rq);
301 else
302 __elv_add_request(q, rq, ELEVATOR_INSERT_FRONT, 0);
303} 315}
304 316
305void __elv_add_request(request_queue_t *q, struct request *rq, int where, 317void __elv_add_request(request_queue_t *q, struct request *rq, int where,
306 int plug) 318 int plug)
307{ 319{
308 /* 320 if (rq->flags & (REQ_SOFTBARRIER | REQ_HARDBARRIER)) {
309 * barriers implicitly indicate back insertion 321 /*
310 */ 322 * barriers implicitly indicate back insertion
311 if (rq->flags & (REQ_SOFTBARRIER | REQ_HARDBARRIER) && 323 */
312 where == ELEVATOR_INSERT_SORT) 324 if (where == ELEVATOR_INSERT_SORT)
325 where = ELEVATOR_INSERT_BACK;
326
327 /*
328 * this request is scheduling boundary, update end_sector
329 */
330 if (blk_fs_request(rq)) {
331 q->end_sector = rq_end_sector(rq);
332 q->boundary_rq = rq;
333 }
334 } else if (!(rq->flags & REQ_ELVPRIV) && where == ELEVATOR_INSERT_SORT)
313 where = ELEVATOR_INSERT_BACK; 335 where = ELEVATOR_INSERT_BACK;
314 336
315 if (plug) 337 if (plug)
@@ -317,23 +339,54 @@ void __elv_add_request(request_queue_t *q, struct request *rq, int where,
317 339
318 rq->q = q; 340 rq->q = q;
319 341
320 if (!test_bit(QUEUE_FLAG_DRAIN, &q->queue_flags)) { 342 switch (where) {
321 q->elevator->ops->elevator_add_req_fn(q, rq, where); 343 case ELEVATOR_INSERT_FRONT:
344 rq->flags |= REQ_SOFTBARRIER;
322 345
323 if (blk_queue_plugged(q)) { 346 list_add(&rq->queuelist, &q->queue_head);
324 int nrq = q->rq.count[READ] + q->rq.count[WRITE] 347 break;
325 - q->in_flight;
326 348
327 if (nrq >= q->unplug_thresh) 349 case ELEVATOR_INSERT_BACK:
328 __generic_unplug_device(q); 350 rq->flags |= REQ_SOFTBARRIER;
329 } 351
330 } else 352 while (q->elevator->ops->elevator_dispatch_fn(q, 1))
353 ;
354 list_add_tail(&rq->queuelist, &q->queue_head);
331 /* 355 /*
332 * if drain is set, store the request "locally". when the drain 356 * We kick the queue here for the following reasons.
333 * is finished, the requests will be handed ordered to the io 357 * - The elevator might have returned NULL previously
334 * scheduler 358 * to delay requests and returned them now. As the
359 * queue wasn't empty before this request, ll_rw_blk
360 * won't run the queue on return, resulting in hang.
361 * - Usually, back inserted requests won't be merged
362 * with anything. There's no point in delaying queue
363 * processing.
335 */ 364 */
336 list_add_tail(&rq->queuelist, &q->drain_list); 365 blk_remove_plug(q);
366 q->request_fn(q);
367 break;
368
369 case ELEVATOR_INSERT_SORT:
370 BUG_ON(!blk_fs_request(rq));
371 rq->flags |= REQ_SORTED;
372 q->elevator->ops->elevator_add_req_fn(q, rq);
373 if (q->last_merge == NULL && rq_mergeable(rq))
374 q->last_merge = rq;
375 break;
376
377 default:
378 printk(KERN_ERR "%s: bad insertion point %d\n",
379 __FUNCTION__, where);
380 BUG();
381 }
382
383 if (blk_queue_plugged(q)) {
384 int nrq = q->rq.count[READ] + q->rq.count[WRITE]
385 - q->in_flight;
386
387 if (nrq >= q->unplug_thresh)
388 __generic_unplug_device(q);
389 }
337} 390}
338 391
339void elv_add_request(request_queue_t *q, struct request *rq, int where, 392void elv_add_request(request_queue_t *q, struct request *rq, int where,
@@ -348,13 +401,19 @@ void elv_add_request(request_queue_t *q, struct request *rq, int where,
348 401
349static inline struct request *__elv_next_request(request_queue_t *q) 402static inline struct request *__elv_next_request(request_queue_t *q)
350{ 403{
351 struct request *rq = q->elevator->ops->elevator_next_req_fn(q); 404 struct request *rq;
405
406 if (unlikely(list_empty(&q->queue_head) &&
407 !q->elevator->ops->elevator_dispatch_fn(q, 0)))
408 return NULL;
409
410 rq = list_entry_rq(q->queue_head.next);
352 411
353 /* 412 /*
354 * if this is a barrier write and the device has to issue a 413 * if this is a barrier write and the device has to issue a
355 * flush sequence to support it, check how far we are 414 * flush sequence to support it, check how far we are
356 */ 415 */
357 if (rq && blk_fs_request(rq) && blk_barrier_rq(rq)) { 416 if (blk_fs_request(rq) && blk_barrier_rq(rq)) {
358 BUG_ON(q->ordered == QUEUE_ORDERED_NONE); 417 BUG_ON(q->ordered == QUEUE_ORDERED_NONE);
359 418
360 if (q->ordered == QUEUE_ORDERED_FLUSH && 419 if (q->ordered == QUEUE_ORDERED_FLUSH &&
@@ -371,15 +430,30 @@ struct request *elv_next_request(request_queue_t *q)
371 int ret; 430 int ret;
372 431
373 while ((rq = __elv_next_request(q)) != NULL) { 432 while ((rq = __elv_next_request(q)) != NULL) {
374 /* 433 if (!(rq->flags & REQ_STARTED)) {
375 * just mark as started even if we don't start it, a request 434 elevator_t *e = q->elevator;
376 * that has been delayed should not be passed by new incoming 435
377 * requests 436 /*
378 */ 437 * This is the first time the device driver
379 rq->flags |= REQ_STARTED; 438 * sees this request (possibly after
439 * requeueing). Notify IO scheduler.
440 */
441 if (blk_sorted_rq(rq) &&
442 e->ops->elevator_activate_req_fn)
443 e->ops->elevator_activate_req_fn(q, rq);
444
445 /*
446 * just mark as started even if we don't start
447 * it, a request that has been delayed should
448 * not be passed by new incoming requests
449 */
450 rq->flags |= REQ_STARTED;
451 }
380 452
381 if (rq == q->last_merge) 453 if (!q->boundary_rq || q->boundary_rq == rq) {
382 q->last_merge = NULL; 454 q->end_sector = rq_end_sector(rq);
455 q->boundary_rq = NULL;
456 }
383 457
384 if ((rq->flags & REQ_DONTPREP) || !q->prep_rq_fn) 458 if ((rq->flags & REQ_DONTPREP) || !q->prep_rq_fn)
385 break; 459 break;
@@ -391,9 +465,9 @@ struct request *elv_next_request(request_queue_t *q)
391 /* 465 /*
392 * the request may have been (partially) prepped. 466 * the request may have been (partially) prepped.
393 * we need to keep this request in the front to 467 * we need to keep this request in the front to
394 * avoid resource deadlock. turn on softbarrier. 468 * avoid resource deadlock. REQ_STARTED will
469 * prevent other fs requests from passing this one.
395 */ 470 */
396 rq->flags |= REQ_SOFTBARRIER;
397 rq = NULL; 471 rq = NULL;
398 break; 472 break;
399 } else if (ret == BLKPREP_KILL) { 473 } else if (ret == BLKPREP_KILL) {
@@ -416,42 +490,32 @@ struct request *elv_next_request(request_queue_t *q)
416 return rq; 490 return rq;
417} 491}
418 492
419void elv_remove_request(request_queue_t *q, struct request *rq) 493void elv_dequeue_request(request_queue_t *q, struct request *rq)
420{ 494{
421 elevator_t *e = q->elevator; 495 BUG_ON(list_empty(&rq->queuelist));
496
497 list_del_init(&rq->queuelist);
422 498
423 /* 499 /*
424 * the time frame between a request being removed from the lists 500 * the time frame between a request being removed from the lists
425 * and to it is freed is accounted as io that is in progress at 501 * and to it is freed is accounted as io that is in progress at
426 * the driver side. note that we only account requests that the 502 * the driver side.
427 * driver has seen (REQ_STARTED set), to avoid false accounting
428 * for request-request merges
429 */ 503 */
430 if (blk_account_rq(rq)) 504 if (blk_account_rq(rq))
431 q->in_flight++; 505 q->in_flight++;
432
433 /*
434 * the main clearing point for q->last_merge is on retrieval of
435 * request by driver (it calls elv_next_request()), but it _can_
436 * also happen here if a request is added to the queue but later
437 * deleted without ever being given to driver (merged with another
438 * request).
439 */
440 if (rq == q->last_merge)
441 q->last_merge = NULL;
442
443 if (e->ops->elevator_remove_req_fn)
444 e->ops->elevator_remove_req_fn(q, rq);
445} 506}
446 507
447int elv_queue_empty(request_queue_t *q) 508int elv_queue_empty(request_queue_t *q)
448{ 509{
449 elevator_t *e = q->elevator; 510 elevator_t *e = q->elevator;
450 511
512 if (!list_empty(&q->queue_head))
513 return 0;
514
451 if (e->ops->elevator_queue_empty_fn) 515 if (e->ops->elevator_queue_empty_fn)
452 return e->ops->elevator_queue_empty_fn(q); 516 return e->ops->elevator_queue_empty_fn(q);
453 517
454 return list_empty(&q->queue_head); 518 return 1;
455} 519}
456 520
457struct request *elv_latter_request(request_queue_t *q, struct request *rq) 521struct request *elv_latter_request(request_queue_t *q, struct request *rq)
@@ -487,7 +551,7 @@ struct request *elv_former_request(request_queue_t *q, struct request *rq)
487} 551}
488 552
489int elv_set_request(request_queue_t *q, struct request *rq, struct bio *bio, 553int elv_set_request(request_queue_t *q, struct request *rq, struct bio *bio,
490 int gfp_mask) 554 gfp_t gfp_mask)
491{ 555{
492 elevator_t *e = q->elevator; 556 elevator_t *e = q->elevator;
493 557
@@ -523,11 +587,11 @@ void elv_completed_request(request_queue_t *q, struct request *rq)
523 /* 587 /*
524 * request is released from the driver, io must be done 588 * request is released from the driver, io must be done
525 */ 589 */
526 if (blk_account_rq(rq)) 590 if (blk_account_rq(rq)) {
527 q->in_flight--; 591 q->in_flight--;
528 592 if (blk_sorted_rq(rq) && e->ops->elevator_completed_req_fn)
529 if (e->ops->elevator_completed_req_fn) 593 e->ops->elevator_completed_req_fn(q, rq);
530 e->ops->elevator_completed_req_fn(q, rq); 594 }
531} 595}
532 596
533int elv_register_queue(struct request_queue *q) 597int elv_register_queue(struct request_queue *q)
@@ -555,10 +619,9 @@ void elv_unregister_queue(struct request_queue *q)
555 619
556int elv_register(struct elevator_type *e) 620int elv_register(struct elevator_type *e)
557{ 621{
622 spin_lock_irq(&elv_list_lock);
558 if (elevator_find(e->elevator_name)) 623 if (elevator_find(e->elevator_name))
559 BUG(); 624 BUG();
560
561 spin_lock_irq(&elv_list_lock);
562 list_add_tail(&e->list, &elv_list); 625 list_add_tail(&e->list, &elv_list);
563 spin_unlock_irq(&elv_list_lock); 626 spin_unlock_irq(&elv_list_lock);
564 627
@@ -572,6 +635,27 @@ EXPORT_SYMBOL_GPL(elv_register);
572 635
573void elv_unregister(struct elevator_type *e) 636void elv_unregister(struct elevator_type *e)
574{ 637{
638 struct task_struct *g, *p;
639
640 /*
641 * Iterate every thread in the process to remove the io contexts.
642 */
643 read_lock(&tasklist_lock);
644 do_each_thread(g, p) {
645 struct io_context *ioc = p->io_context;
646 if (ioc && ioc->cic) {
647 ioc->cic->exit(ioc->cic);
648 ioc->cic->dtor(ioc->cic);
649 ioc->cic = NULL;
650 }
651 if (ioc && ioc->aic) {
652 ioc->aic->exit(ioc->aic);
653 ioc->aic->dtor(ioc->aic);
654 ioc->aic = NULL;
655 }
656 } while_each_thread(g, p);
657 read_unlock(&tasklist_lock);
658
575 spin_lock_irq(&elv_list_lock); 659 spin_lock_irq(&elv_list_lock);
576 list_del_init(&e->list); 660 list_del_init(&e->list);
577 spin_unlock_irq(&elv_list_lock); 661 spin_unlock_irq(&elv_list_lock);
@@ -582,25 +666,36 @@ EXPORT_SYMBOL_GPL(elv_unregister);
582 * switch to new_e io scheduler. be careful not to introduce deadlocks - 666 * switch to new_e io scheduler. be careful not to introduce deadlocks -
583 * we don't free the old io scheduler, before we have allocated what we 667 * we don't free the old io scheduler, before we have allocated what we
584 * need for the new one. this way we have a chance of going back to the old 668 * need for the new one. this way we have a chance of going back to the old
585 * one, if the new one fails init for some reason. we also do an intermediate 669 * one, if the new one fails init for some reason.
586 * switch to noop to ensure safety with stack-allocated requests, since they
587 * don't originate from the block layer allocator. noop is safe here, because
588 * it never needs to touch the elevator itself for completion events. DRAIN
589 * flags will make sure we don't touch it for additions either.
590 */ 670 */
591static void elevator_switch(request_queue_t *q, struct elevator_type *new_e) 671static void elevator_switch(request_queue_t *q, struct elevator_type *new_e)
592{ 672{
593 elevator_t *e = kmalloc(sizeof(elevator_t), GFP_KERNEL); 673 elevator_t *old_elevator, *e;
594 struct elevator_type *noop_elevator = NULL;
595 elevator_t *old_elevator;
596 674
675 /*
676 * Allocate new elevator
677 */
678 e = kmalloc(sizeof(elevator_t), GFP_KERNEL);
597 if (!e) 679 if (!e)
598 goto error; 680 goto error;
599 681
600 /* 682 /*
601 * first step, drain requests from the block freelist 683 * Turn on BYPASS and drain all requests w/ elevator private data
602 */ 684 */
603 blk_wait_queue_drained(q, 0); 685 spin_lock_irq(q->queue_lock);
686
687 set_bit(QUEUE_FLAG_ELVSWITCH, &q->queue_flags);
688
689 while (q->elevator->ops->elevator_dispatch_fn(q, 1))
690 ;
691
692 while (q->rq.elvpriv) {
693 spin_unlock_irq(q->queue_lock);
694 msleep(10);
695 spin_lock_irq(q->queue_lock);
696 }
697
698 spin_unlock_irq(q->queue_lock);
604 699
605 /* 700 /*
606 * unregister old elevator data 701 * unregister old elevator data
@@ -609,18 +704,6 @@ static void elevator_switch(request_queue_t *q, struct elevator_type *new_e)
609 old_elevator = q->elevator; 704 old_elevator = q->elevator;
610 705
611 /* 706 /*
612 * next step, switch to noop since it uses no private rq structures
613 * and doesn't allocate any memory for anything. then wait for any
614 * non-fs requests in-flight
615 */
616 noop_elevator = elevator_get("noop");
617 spin_lock_irq(q->queue_lock);
618 elevator_attach(q, noop_elevator, e);
619 spin_unlock_irq(q->queue_lock);
620
621 blk_wait_queue_drained(q, 1);
622
623 /*
624 * attach and start new elevator 707 * attach and start new elevator
625 */ 708 */
626 if (elevator_attach(q, new_e, e)) 709 if (elevator_attach(q, new_e, e))
@@ -630,11 +713,10 @@ static void elevator_switch(request_queue_t *q, struct elevator_type *new_e)
630 goto fail_register; 713 goto fail_register;
631 714
632 /* 715 /*
633 * finally exit old elevator and start queue again 716 * finally exit old elevator and turn off BYPASS.
634 */ 717 */
635 elevator_exit(old_elevator); 718 elevator_exit(old_elevator);
636 blk_finish_queue_drain(q); 719 clear_bit(QUEUE_FLAG_ELVSWITCH, &q->queue_flags);
637 elevator_put(noop_elevator);
638 return; 720 return;
639 721
640fail_register: 722fail_register:
@@ -643,13 +725,13 @@ fail_register:
643 * one again (along with re-adding the sysfs dir) 725 * one again (along with re-adding the sysfs dir)
644 */ 726 */
645 elevator_exit(e); 727 elevator_exit(e);
728 e = NULL;
646fail: 729fail:
647 q->elevator = old_elevator; 730 q->elevator = old_elevator;
648 elv_register_queue(q); 731 elv_register_queue(q);
649 blk_finish_queue_drain(q); 732 clear_bit(QUEUE_FLAG_ELVSWITCH, &q->queue_flags);
733 kfree(e);
650error: 734error:
651 if (noop_elevator)
652 elevator_put(noop_elevator);
653 elevator_put(new_e); 735 elevator_put(new_e);
654 printk(KERN_ERR "elevator: switch to %s failed\n",new_e->elevator_name); 736 printk(KERN_ERR "elevator: switch to %s failed\n",new_e->elevator_name);
655} 737}
@@ -671,8 +753,10 @@ ssize_t elv_iosched_store(request_queue_t *q, const char *name, size_t count)
671 return -EINVAL; 753 return -EINVAL;
672 } 754 }
673 755
674 if (!strcmp(elevator_name, q->elevator->elevator_type->elevator_name)) 756 if (!strcmp(elevator_name, q->elevator->elevator_type->elevator_name)) {
757 elevator_put(e);
675 return count; 758 return count;
759 }
676 760
677 elevator_switch(q, e); 761 elevator_switch(q, e);
678 return count; 762 return count;
@@ -701,11 +785,12 @@ ssize_t elv_iosched_show(request_queue_t *q, char *name)
701 return len; 785 return len;
702} 786}
703 787
788EXPORT_SYMBOL(elv_dispatch_sort);
704EXPORT_SYMBOL(elv_add_request); 789EXPORT_SYMBOL(elv_add_request);
705EXPORT_SYMBOL(__elv_add_request); 790EXPORT_SYMBOL(__elv_add_request);
706EXPORT_SYMBOL(elv_requeue_request); 791EXPORT_SYMBOL(elv_requeue_request);
707EXPORT_SYMBOL(elv_next_request); 792EXPORT_SYMBOL(elv_next_request);
708EXPORT_SYMBOL(elv_remove_request); 793EXPORT_SYMBOL(elv_dequeue_request);
709EXPORT_SYMBOL(elv_queue_empty); 794EXPORT_SYMBOL(elv_queue_empty);
710EXPORT_SYMBOL(elv_completed_request); 795EXPORT_SYMBOL(elv_completed_request);
711EXPORT_SYMBOL(elevator_exit); 796EXPORT_SYMBOL(elevator_exit);
diff --git a/drivers/block/genhd.c b/drivers/block/genhd.c
index d42840cc0d1d..486ce1fdeb8c 100644
--- a/drivers/block/genhd.c
+++ b/drivers/block/genhd.c
@@ -337,10 +337,30 @@ static ssize_t disk_attr_show(struct kobject *kobj, struct attribute *attr,
337 return ret; 337 return ret;
338} 338}
339 339
340static ssize_t disk_attr_store(struct kobject * kobj, struct attribute * attr,
341 const char *page, size_t count)
342{
343 struct gendisk *disk = to_disk(kobj);
344 struct disk_attribute *disk_attr =
345 container_of(attr,struct disk_attribute,attr);
346 ssize_t ret = 0;
347
348 if (disk_attr->store)
349 ret = disk_attr->store(disk, page, count);
350 return ret;
351}
352
340static struct sysfs_ops disk_sysfs_ops = { 353static struct sysfs_ops disk_sysfs_ops = {
341 .show = &disk_attr_show, 354 .show = &disk_attr_show,
355 .store = &disk_attr_store,
342}; 356};
343 357
358static ssize_t disk_uevent_store(struct gendisk * disk,
359 const char *buf, size_t count)
360{
361 kobject_hotplug(&disk->kobj, KOBJ_ADD);
362 return count;
363}
344static ssize_t disk_dev_read(struct gendisk * disk, char *page) 364static ssize_t disk_dev_read(struct gendisk * disk, char *page)
345{ 365{
346 dev_t base = MKDEV(disk->major, disk->first_minor); 366 dev_t base = MKDEV(disk->major, disk->first_minor);
@@ -382,6 +402,10 @@ static ssize_t disk_stats_read(struct gendisk * disk, char *page)
382 jiffies_to_msecs(disk_stat_read(disk, io_ticks)), 402 jiffies_to_msecs(disk_stat_read(disk, io_ticks)),
383 jiffies_to_msecs(disk_stat_read(disk, time_in_queue))); 403 jiffies_to_msecs(disk_stat_read(disk, time_in_queue)));
384} 404}
405static struct disk_attribute disk_attr_uevent = {
406 .attr = {.name = "uevent", .mode = S_IWUSR },
407 .store = disk_uevent_store
408};
385static struct disk_attribute disk_attr_dev = { 409static struct disk_attribute disk_attr_dev = {
386 .attr = {.name = "dev", .mode = S_IRUGO }, 410 .attr = {.name = "dev", .mode = S_IRUGO },
387 .show = disk_dev_read 411 .show = disk_dev_read
@@ -404,6 +428,7 @@ static struct disk_attribute disk_attr_stat = {
404}; 428};
405 429
406static struct attribute * default_attrs[] = { 430static struct attribute * default_attrs[] = {
431 &disk_attr_uevent.attr,
407 &disk_attr_dev.attr, 432 &disk_attr_dev.attr,
408 &disk_attr_range.attr, 433 &disk_attr_range.attr,
409 &disk_attr_removable.attr, 434 &disk_attr_removable.attr,
diff --git a/drivers/block/ll_rw_blk.c b/drivers/block/ll_rw_blk.c
index baedac522945..0af73512b9a8 100644
--- a/drivers/block/ll_rw_blk.c
+++ b/drivers/block/ll_rw_blk.c
@@ -263,8 +263,6 @@ void blk_queue_make_request(request_queue_t * q, make_request_fn * mfn)
263 blk_queue_bounce_limit(q, BLK_BOUNCE_HIGH); 263 blk_queue_bounce_limit(q, BLK_BOUNCE_HIGH);
264 264
265 blk_queue_activity_fn(q, NULL, NULL); 265 blk_queue_activity_fn(q, NULL, NULL);
266
267 INIT_LIST_HEAD(&q->drain_list);
268} 266}
269 267
270EXPORT_SYMBOL(blk_queue_make_request); 268EXPORT_SYMBOL(blk_queue_make_request);
@@ -353,6 +351,8 @@ static void blk_pre_flush_end_io(struct request *flush_rq)
353 struct request *rq = flush_rq->end_io_data; 351 struct request *rq = flush_rq->end_io_data;
354 request_queue_t *q = rq->q; 352 request_queue_t *q = rq->q;
355 353
354 elv_completed_request(q, flush_rq);
355
356 rq->flags |= REQ_BAR_PREFLUSH; 356 rq->flags |= REQ_BAR_PREFLUSH;
357 357
358 if (!flush_rq->errors) 358 if (!flush_rq->errors)
@@ -369,6 +369,8 @@ static void blk_post_flush_end_io(struct request *flush_rq)
369 struct request *rq = flush_rq->end_io_data; 369 struct request *rq = flush_rq->end_io_data;
370 request_queue_t *q = rq->q; 370 request_queue_t *q = rq->q;
371 371
372 elv_completed_request(q, flush_rq);
373
372 rq->flags |= REQ_BAR_POSTFLUSH; 374 rq->flags |= REQ_BAR_POSTFLUSH;
373 375
374 q->end_flush_fn(q, flush_rq); 376 q->end_flush_fn(q, flush_rq);
@@ -408,8 +410,6 @@ struct request *blk_start_pre_flush(request_queue_t *q, struct request *rq)
408 if (!list_empty(&rq->queuelist)) 410 if (!list_empty(&rq->queuelist))
409 blkdev_dequeue_request(rq); 411 blkdev_dequeue_request(rq);
410 412
411 elv_deactivate_request(q, rq);
412
413 flush_rq->end_io_data = rq; 413 flush_rq->end_io_data = rq;
414 flush_rq->end_io = blk_pre_flush_end_io; 414 flush_rq->end_io = blk_pre_flush_end_io;
415 415
@@ -1040,6 +1040,7 @@ EXPORT_SYMBOL(blk_queue_invalidate_tags);
1040static char *rq_flags[] = { 1040static char *rq_flags[] = {
1041 "REQ_RW", 1041 "REQ_RW",
1042 "REQ_FAILFAST", 1042 "REQ_FAILFAST",
1043 "REQ_SORTED",
1043 "REQ_SOFTBARRIER", 1044 "REQ_SOFTBARRIER",
1044 "REQ_HARDBARRIER", 1045 "REQ_HARDBARRIER",
1045 "REQ_CMD", 1046 "REQ_CMD",
@@ -1047,6 +1048,7 @@ static char *rq_flags[] = {
1047 "REQ_STARTED", 1048 "REQ_STARTED",
1048 "REQ_DONTPREP", 1049 "REQ_DONTPREP",
1049 "REQ_QUEUED", 1050 "REQ_QUEUED",
1051 "REQ_ELVPRIV",
1050 "REQ_PC", 1052 "REQ_PC",
1051 "REQ_BLOCK_PC", 1053 "REQ_BLOCK_PC",
1052 "REQ_SENSE", 1054 "REQ_SENSE",
@@ -1637,9 +1639,9 @@ static int blk_init_free_list(request_queue_t *q)
1637 1639
1638 rl->count[READ] = rl->count[WRITE] = 0; 1640 rl->count[READ] = rl->count[WRITE] = 0;
1639 rl->starved[READ] = rl->starved[WRITE] = 0; 1641 rl->starved[READ] = rl->starved[WRITE] = 0;
1642 rl->elvpriv = 0;
1640 init_waitqueue_head(&rl->wait[READ]); 1643 init_waitqueue_head(&rl->wait[READ]);
1641 init_waitqueue_head(&rl->wait[WRITE]); 1644 init_waitqueue_head(&rl->wait[WRITE]);
1642 init_waitqueue_head(&rl->drain);
1643 1645
1644 rl->rq_pool = mempool_create_node(BLKDEV_MIN_RQ, mempool_alloc_slab, 1646 rl->rq_pool = mempool_create_node(BLKDEV_MIN_RQ, mempool_alloc_slab,
1645 mempool_free_slab, request_cachep, q->node); 1647 mempool_free_slab, request_cachep, q->node);
@@ -1652,13 +1654,13 @@ static int blk_init_free_list(request_queue_t *q)
1652 1654
1653static int __make_request(request_queue_t *, struct bio *); 1655static int __make_request(request_queue_t *, struct bio *);
1654 1656
1655request_queue_t *blk_alloc_queue(int gfp_mask) 1657request_queue_t *blk_alloc_queue(gfp_t gfp_mask)
1656{ 1658{
1657 return blk_alloc_queue_node(gfp_mask, -1); 1659 return blk_alloc_queue_node(gfp_mask, -1);
1658} 1660}
1659EXPORT_SYMBOL(blk_alloc_queue); 1661EXPORT_SYMBOL(blk_alloc_queue);
1660 1662
1661request_queue_t *blk_alloc_queue_node(int gfp_mask, int node_id) 1663request_queue_t *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
1662{ 1664{
1663 request_queue_t *q; 1665 request_queue_t *q;
1664 1666
@@ -1782,12 +1784,14 @@ EXPORT_SYMBOL(blk_get_queue);
1782 1784
1783static inline void blk_free_request(request_queue_t *q, struct request *rq) 1785static inline void blk_free_request(request_queue_t *q, struct request *rq)
1784{ 1786{
1785 elv_put_request(q, rq); 1787 if (rq->flags & REQ_ELVPRIV)
1788 elv_put_request(q, rq);
1786 mempool_free(rq, q->rq.rq_pool); 1789 mempool_free(rq, q->rq.rq_pool);
1787} 1790}
1788 1791
1789static inline struct request * 1792static inline struct request *
1790blk_alloc_request(request_queue_t *q, int rw, struct bio *bio, int gfp_mask) 1793blk_alloc_request(request_queue_t *q, int rw, struct bio *bio,
1794 int priv, gfp_t gfp_mask)
1791{ 1795{
1792 struct request *rq = mempool_alloc(q->rq.rq_pool, gfp_mask); 1796 struct request *rq = mempool_alloc(q->rq.rq_pool, gfp_mask);
1793 1797
@@ -1800,11 +1804,15 @@ blk_alloc_request(request_queue_t *q, int rw, struct bio *bio, int gfp_mask)
1800 */ 1804 */
1801 rq->flags = rw; 1805 rq->flags = rw;
1802 1806
1803 if (!elv_set_request(q, rq, bio, gfp_mask)) 1807 if (priv) {
1804 return rq; 1808 if (unlikely(elv_set_request(q, rq, bio, gfp_mask))) {
1809 mempool_free(rq, q->rq.rq_pool);
1810 return NULL;
1811 }
1812 rq->flags |= REQ_ELVPRIV;
1813 }
1805 1814
1806 mempool_free(rq, q->rq.rq_pool); 1815 return rq;
1807 return NULL;
1808} 1816}
1809 1817
1810/* 1818/*
@@ -1860,22 +1868,18 @@ static void __freed_request(request_queue_t *q, int rw)
1860 * A request has just been released. Account for it, update the full and 1868 * A request has just been released. Account for it, update the full and
1861 * congestion status, wake up any waiters. Called under q->queue_lock. 1869 * congestion status, wake up any waiters. Called under q->queue_lock.
1862 */ 1870 */
1863static void freed_request(request_queue_t *q, int rw) 1871static void freed_request(request_queue_t *q, int rw, int priv)
1864{ 1872{
1865 struct request_list *rl = &q->rq; 1873 struct request_list *rl = &q->rq;
1866 1874
1867 rl->count[rw]--; 1875 rl->count[rw]--;
1876 if (priv)
1877 rl->elvpriv--;
1868 1878
1869 __freed_request(q, rw); 1879 __freed_request(q, rw);
1870 1880
1871 if (unlikely(rl->starved[rw ^ 1])) 1881 if (unlikely(rl->starved[rw ^ 1]))
1872 __freed_request(q, rw ^ 1); 1882 __freed_request(q, rw ^ 1);
1873
1874 if (!rl->count[READ] && !rl->count[WRITE]) {
1875 smp_mb();
1876 if (unlikely(waitqueue_active(&rl->drain)))
1877 wake_up(&rl->drain);
1878 }
1879} 1883}
1880 1884
1881#define blkdev_free_rq(list) list_entry((list)->next, struct request, queuelist) 1885#define blkdev_free_rq(list) list_entry((list)->next, struct request, queuelist)
@@ -1885,14 +1889,12 @@ static void freed_request(request_queue_t *q, int rw)
1885 * Returns !NULL on success, with queue_lock *not held*. 1889 * Returns !NULL on success, with queue_lock *not held*.
1886 */ 1890 */
1887static struct request *get_request(request_queue_t *q, int rw, struct bio *bio, 1891static struct request *get_request(request_queue_t *q, int rw, struct bio *bio,
1888 int gfp_mask) 1892 gfp_t gfp_mask)
1889{ 1893{
1890 struct request *rq = NULL; 1894 struct request *rq = NULL;
1891 struct request_list *rl = &q->rq; 1895 struct request_list *rl = &q->rq;
1892 struct io_context *ioc = current_io_context(GFP_ATOMIC); 1896 struct io_context *ioc = current_io_context(GFP_ATOMIC);
1893 1897 int priv;
1894 if (unlikely(test_bit(QUEUE_FLAG_DRAIN, &q->queue_flags)))
1895 goto out;
1896 1898
1897 if (rl->count[rw]+1 >= q->nr_requests) { 1899 if (rl->count[rw]+1 >= q->nr_requests) {
1898 /* 1900 /*
@@ -1937,9 +1939,14 @@ get_rq:
1937 rl->starved[rw] = 0; 1939 rl->starved[rw] = 0;
1938 if (rl->count[rw] >= queue_congestion_on_threshold(q)) 1940 if (rl->count[rw] >= queue_congestion_on_threshold(q))
1939 set_queue_congested(q, rw); 1941 set_queue_congested(q, rw);
1942
1943 priv = !test_bit(QUEUE_FLAG_ELVSWITCH, &q->queue_flags);
1944 if (priv)
1945 rl->elvpriv++;
1946
1940 spin_unlock_irq(q->queue_lock); 1947 spin_unlock_irq(q->queue_lock);
1941 1948
1942 rq = blk_alloc_request(q, rw, bio, gfp_mask); 1949 rq = blk_alloc_request(q, rw, bio, priv, gfp_mask);
1943 if (!rq) { 1950 if (!rq) {
1944 /* 1951 /*
1945 * Allocation failed presumably due to memory. Undo anything 1952 * Allocation failed presumably due to memory. Undo anything
@@ -1949,7 +1956,7 @@ get_rq:
1949 * wait queue, but this is pretty rare. 1956 * wait queue, but this is pretty rare.
1950 */ 1957 */
1951 spin_lock_irq(q->queue_lock); 1958 spin_lock_irq(q->queue_lock);
1952 freed_request(q, rw); 1959 freed_request(q, rw, priv);
1953 1960
1954 /* 1961 /*
1955 * in the very unlikely event that allocation failed and no 1962 * in the very unlikely event that allocation failed and no
@@ -2019,7 +2026,7 @@ static struct request *get_request_wait(request_queue_t *q, int rw,
2019 return rq; 2026 return rq;
2020} 2027}
2021 2028
2022struct request *blk_get_request(request_queue_t *q, int rw, int gfp_mask) 2029struct request *blk_get_request(request_queue_t *q, int rw, gfp_t gfp_mask)
2023{ 2030{
2024 struct request *rq; 2031 struct request *rq;
2025 2032
@@ -2251,7 +2258,7 @@ EXPORT_SYMBOL(blk_rq_unmap_user);
2251 * @gfp_mask: memory allocation flags 2258 * @gfp_mask: memory allocation flags
2252 */ 2259 */
2253int blk_rq_map_kern(request_queue_t *q, struct request *rq, void *kbuf, 2260int blk_rq_map_kern(request_queue_t *q, struct request *rq, void *kbuf,
2254 unsigned int len, unsigned int gfp_mask) 2261 unsigned int len, gfp_t gfp_mask)
2255{ 2262{
2256 struct bio *bio; 2263 struct bio *bio;
2257 2264
@@ -2433,13 +2440,15 @@ void disk_round_stats(struct gendisk *disk)
2433{ 2440{
2434 unsigned long now = jiffies; 2441 unsigned long now = jiffies;
2435 2442
2436 __disk_stat_add(disk, time_in_queue, 2443 if (now == disk->stamp)
2437 disk->in_flight * (now - disk->stamp)); 2444 return;
2438 disk->stamp = now;
2439 2445
2440 if (disk->in_flight) 2446 if (disk->in_flight) {
2441 __disk_stat_add(disk, io_ticks, (now - disk->stamp_idle)); 2447 __disk_stat_add(disk, time_in_queue,
2442 disk->stamp_idle = now; 2448 disk->in_flight * (now - disk->stamp));
2449 __disk_stat_add(disk, io_ticks, (now - disk->stamp));
2450 }
2451 disk->stamp = now;
2443} 2452}
2444 2453
2445/* 2454/*
@@ -2454,6 +2463,8 @@ static void __blk_put_request(request_queue_t *q, struct request *req)
2454 if (unlikely(--req->ref_count)) 2463 if (unlikely(--req->ref_count))
2455 return; 2464 return;
2456 2465
2466 elv_completed_request(q, req);
2467
2457 req->rq_status = RQ_INACTIVE; 2468 req->rq_status = RQ_INACTIVE;
2458 req->rl = NULL; 2469 req->rl = NULL;
2459 2470
@@ -2463,26 +2474,25 @@ static void __blk_put_request(request_queue_t *q, struct request *req)
2463 */ 2474 */
2464 if (rl) { 2475 if (rl) {
2465 int rw = rq_data_dir(req); 2476 int rw = rq_data_dir(req);
2466 2477 int priv = req->flags & REQ_ELVPRIV;
2467 elv_completed_request(q, req);
2468 2478
2469 BUG_ON(!list_empty(&req->queuelist)); 2479 BUG_ON(!list_empty(&req->queuelist));
2470 2480
2471 blk_free_request(q, req); 2481 blk_free_request(q, req);
2472 freed_request(q, rw); 2482 freed_request(q, rw, priv);
2473 } 2483 }
2474} 2484}
2475 2485
2476void blk_put_request(struct request *req) 2486void blk_put_request(struct request *req)
2477{ 2487{
2488 unsigned long flags;
2489 request_queue_t *q = req->q;
2490
2478 /* 2491 /*
2479 * if req->rl isn't set, this request didnt originate from the 2492 * Gee, IDE calls in w/ NULL q. Fix IDE and remove the
2480 * block layer, so it's safe to just disregard it 2493 * following if (q) test.
2481 */ 2494 */
2482 if (req->rl) { 2495 if (q) {
2483 unsigned long flags;
2484 request_queue_t *q = req->q;
2485
2486 spin_lock_irqsave(q->queue_lock, flags); 2496 spin_lock_irqsave(q->queue_lock, flags);
2487 __blk_put_request(q, req); 2497 __blk_put_request(q, req);
2488 spin_unlock_irqrestore(q->queue_lock, flags); 2498 spin_unlock_irqrestore(q->queue_lock, flags);
@@ -2797,97 +2807,6 @@ static inline void blk_partition_remap(struct bio *bio)
2797 } 2807 }
2798} 2808}
2799 2809
2800void blk_finish_queue_drain(request_queue_t *q)
2801{
2802 struct request_list *rl = &q->rq;
2803 struct request *rq;
2804 int requeued = 0;
2805
2806 spin_lock_irq(q->queue_lock);
2807 clear_bit(QUEUE_FLAG_DRAIN, &q->queue_flags);
2808
2809 while (!list_empty(&q->drain_list)) {
2810 rq = list_entry_rq(q->drain_list.next);
2811
2812 list_del_init(&rq->queuelist);
2813 elv_requeue_request(q, rq);
2814 requeued++;
2815 }
2816
2817 if (requeued)
2818 q->request_fn(q);
2819
2820 spin_unlock_irq(q->queue_lock);
2821
2822 wake_up(&rl->wait[0]);
2823 wake_up(&rl->wait[1]);
2824 wake_up(&rl->drain);
2825}
2826
2827static int wait_drain(request_queue_t *q, struct request_list *rl, int dispatch)
2828{
2829 int wait = rl->count[READ] + rl->count[WRITE];
2830
2831 if (dispatch)
2832 wait += !list_empty(&q->queue_head);
2833
2834 return wait;
2835}
2836
2837/*
2838 * We rely on the fact that only requests allocated through blk_alloc_request()
2839 * have io scheduler private data structures associated with them. Any other
2840 * type of request (allocated on stack or through kmalloc()) should not go
2841 * to the io scheduler core, but be attached to the queue head instead.
2842 */
2843void blk_wait_queue_drained(request_queue_t *q, int wait_dispatch)
2844{
2845 struct request_list *rl = &q->rq;
2846 DEFINE_WAIT(wait);
2847
2848 spin_lock_irq(q->queue_lock);
2849 set_bit(QUEUE_FLAG_DRAIN, &q->queue_flags);
2850
2851 while (wait_drain(q, rl, wait_dispatch)) {
2852 prepare_to_wait(&rl->drain, &wait, TASK_UNINTERRUPTIBLE);
2853
2854 if (wait_drain(q, rl, wait_dispatch)) {
2855 __generic_unplug_device(q);
2856 spin_unlock_irq(q->queue_lock);
2857 io_schedule();
2858 spin_lock_irq(q->queue_lock);
2859 }
2860
2861 finish_wait(&rl->drain, &wait);
2862 }
2863
2864 spin_unlock_irq(q->queue_lock);
2865}
2866
2867/*
2868 * block waiting for the io scheduler being started again.
2869 */
2870static inline void block_wait_queue_running(request_queue_t *q)
2871{
2872 DEFINE_WAIT(wait);
2873
2874 while (unlikely(test_bit(QUEUE_FLAG_DRAIN, &q->queue_flags))) {
2875 struct request_list *rl = &q->rq;
2876
2877 prepare_to_wait_exclusive(&rl->drain, &wait,
2878 TASK_UNINTERRUPTIBLE);
2879
2880 /*
2881 * re-check the condition. avoids using prepare_to_wait()
2882 * in the fast path (queue is running)
2883 */
2884 if (test_bit(QUEUE_FLAG_DRAIN, &q->queue_flags))
2885 io_schedule();
2886
2887 finish_wait(&rl->drain, &wait);
2888 }
2889}
2890
2891static void handle_bad_sector(struct bio *bio) 2810static void handle_bad_sector(struct bio *bio)
2892{ 2811{
2893 char b[BDEVNAME_SIZE]; 2812 char b[BDEVNAME_SIZE];
@@ -2983,8 +2902,6 @@ end_io:
2983 if (unlikely(test_bit(QUEUE_FLAG_DEAD, &q->queue_flags))) 2902 if (unlikely(test_bit(QUEUE_FLAG_DEAD, &q->queue_flags)))
2984 goto end_io; 2903 goto end_io;
2985 2904
2986 block_wait_queue_running(q);
2987
2988 /* 2905 /*
2989 * If this device has partitions, remap block n 2906 * If this device has partitions, remap block n
2990 * of partition p to block n+start(p) of the disk. 2907 * of partition p to block n+start(p) of the disk.
@@ -3393,7 +3310,7 @@ void exit_io_context(void)
3393 * but since the current task itself holds a reference, the context can be 3310 * but since the current task itself holds a reference, the context can be
3394 * used in general code, so long as it stays within `current` context. 3311 * used in general code, so long as it stays within `current` context.
3395 */ 3312 */
3396struct io_context *current_io_context(int gfp_flags) 3313struct io_context *current_io_context(gfp_t gfp_flags)
3397{ 3314{
3398 struct task_struct *tsk = current; 3315 struct task_struct *tsk = current;
3399 struct io_context *ret; 3316 struct io_context *ret;
@@ -3424,7 +3341,7 @@ EXPORT_SYMBOL(current_io_context);
3424 * 3341 *
3425 * This is always called in the context of the task which submitted the I/O. 3342 * This is always called in the context of the task which submitted the I/O.
3426 */ 3343 */
3427struct io_context *get_io_context(int gfp_flags) 3344struct io_context *get_io_context(gfp_t gfp_flags)
3428{ 3345{
3429 struct io_context *ret; 3346 struct io_context *ret;
3430 ret = current_io_context(gfp_flags); 3347 ret = current_io_context(gfp_flags);
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index b35e08876dd4..96c664af8d06 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -881,7 +881,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
881static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev) 881static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev)
882{ 882{
883 struct file *filp = lo->lo_backing_file; 883 struct file *filp = lo->lo_backing_file;
884 int gfp = lo->old_gfp_mask; 884 gfp_t gfp = lo->old_gfp_mask;
885 885
886 if (lo->lo_state != Lo_bound) 886 if (lo->lo_state != Lo_bound)
887 return -ENXIO; 887 return -ENXIO;
diff --git a/drivers/block/noop-iosched.c b/drivers/block/noop-iosched.c
index b1730b62c37e..f56b8edb06e4 100644
--- a/drivers/block/noop-iosched.c
+++ b/drivers/block/noop-iosched.c
@@ -7,57 +7,19 @@
7#include <linux/module.h> 7#include <linux/module.h>
8#include <linux/init.h> 8#include <linux/init.h>
9 9
10/* 10static void elevator_noop_add_request(request_queue_t *q, struct request *rq)
11 * See if we can find a request that this buffer can be coalesced with.
12 */
13static int elevator_noop_merge(request_queue_t *q, struct request **req,
14 struct bio *bio)
15{
16 int ret;
17
18 ret = elv_try_last_merge(q, bio);
19 if (ret != ELEVATOR_NO_MERGE)
20 *req = q->last_merge;
21
22 return ret;
23}
24
25static void elevator_noop_merge_requests(request_queue_t *q, struct request *req,
26 struct request *next)
27{
28 list_del_init(&next->queuelist);
29}
30
31static void elevator_noop_add_request(request_queue_t *q, struct request *rq,
32 int where)
33{ 11{
34 if (where == ELEVATOR_INSERT_FRONT) 12 elv_dispatch_add_tail(q, rq);
35 list_add(&rq->queuelist, &q->queue_head);
36 else
37 list_add_tail(&rq->queuelist, &q->queue_head);
38
39 /*
40 * new merges must not precede this barrier
41 */
42 if (rq->flags & REQ_HARDBARRIER)
43 q->last_merge = NULL;
44 else if (!q->last_merge)
45 q->last_merge = rq;
46} 13}
47 14
48static struct request *elevator_noop_next_request(request_queue_t *q) 15static int elevator_noop_dispatch(request_queue_t *q, int force)
49{ 16{
50 if (!list_empty(&q->queue_head)) 17 return 0;
51 return list_entry_rq(q->queue_head.next);
52
53 return NULL;
54} 18}
55 19
56static struct elevator_type elevator_noop = { 20static struct elevator_type elevator_noop = {
57 .ops = { 21 .ops = {
58 .elevator_merge_fn = elevator_noop_merge, 22 .elevator_dispatch_fn = elevator_noop_dispatch,
59 .elevator_merge_req_fn = elevator_noop_merge_requests,
60 .elevator_next_req_fn = elevator_noop_next_request,
61 .elevator_add_req_fn = elevator_noop_add_request, 23 .elevator_add_req_fn = elevator_noop_add_request,
62 }, 24 },
63 .elevator_name = "noop", 25 .elevator_name = "noop",
diff --git a/drivers/block/paride/paride.c b/drivers/block/paride/paride.c
index 1fef136c0e41..ce94aa11f6a7 100644
--- a/drivers/block/paride/paride.c
+++ b/drivers/block/paride/paride.c
@@ -29,6 +29,7 @@
29#include <linux/string.h> 29#include <linux/string.h>
30#include <linux/spinlock.h> 30#include <linux/spinlock.h>
31#include <linux/wait.h> 31#include <linux/wait.h>
32#include <linux/sched.h> /* TASK_* */
32 33
33#ifdef CONFIG_PARPORT_MODULE 34#ifdef CONFIG_PARPORT_MODULE
34#define CONFIG_PARPORT 35#define CONFIG_PARPORT
diff --git a/drivers/block/paride/pf.c b/drivers/block/paride/pf.c
index 94af920465b5..e9746af29b9f 100644
--- a/drivers/block/paride/pf.c
+++ b/drivers/block/paride/pf.c
@@ -807,10 +807,6 @@ static int pf_next_buf(void)
807 return 1; 807 return 1;
808 spin_lock_irqsave(&pf_spin_lock, saved_flags); 808 spin_lock_irqsave(&pf_spin_lock, saved_flags);
809 pf_end_request(1); 809 pf_end_request(1);
810 if (pf_req) {
811 pf_count = pf_req->current_nr_sectors;
812 pf_buf = pf_req->buffer;
813 }
814 spin_unlock_irqrestore(&pf_spin_lock, saved_flags); 810 spin_unlock_irqrestore(&pf_spin_lock, saved_flags);
815 return 1; 811 return 1;
816} 812}
diff --git a/drivers/block/paride/pg.c b/drivers/block/paride/pg.c
index b3982395f22b..6f5df0fad703 100644
--- a/drivers/block/paride/pg.c
+++ b/drivers/block/paride/pg.c
@@ -162,6 +162,8 @@ enum {D_PRT, D_PRO, D_UNI, D_MOD, D_SLV, D_DLY};
162#include <linux/mtio.h> 162#include <linux/mtio.h>
163#include <linux/pg.h> 163#include <linux/pg.h>
164#include <linux/device.h> 164#include <linux/device.h>
165#include <linux/sched.h> /* current, TASK_* */
166#include <linux/jiffies.h>
165 167
166#include <asm/uaccess.h> 168#include <asm/uaccess.h>
167 169
@@ -674,7 +676,7 @@ static int __init pg_init(void)
674 for (unit = 0; unit < PG_UNITS; unit++) { 676 for (unit = 0; unit < PG_UNITS; unit++) {
675 struct pg *dev = &devices[unit]; 677 struct pg *dev = &devices[unit];
676 if (dev->present) { 678 if (dev->present) {
677 class_device_create(pg_class, MKDEV(major, unit), 679 class_device_create(pg_class, NULL, MKDEV(major, unit),
678 NULL, "pg%u", unit); 680 NULL, "pg%u", unit);
679 err = devfs_mk_cdev(MKDEV(major, unit), 681 err = devfs_mk_cdev(MKDEV(major, unit),
680 S_IFCHR | S_IRUSR | S_IWUSR, "pg/%u", 682 S_IFCHR | S_IRUSR | S_IWUSR, "pg/%u",
diff --git a/drivers/block/paride/pt.c b/drivers/block/paride/pt.c
index d8d35233cf49..715ae5dc88fb 100644
--- a/drivers/block/paride/pt.c
+++ b/drivers/block/paride/pt.c
@@ -146,6 +146,7 @@ static int (*drives[4])[6] = {&drive0, &drive1, &drive2, &drive3};
146#include <linux/slab.h> 146#include <linux/slab.h>
147#include <linux/mtio.h> 147#include <linux/mtio.h>
148#include <linux/device.h> 148#include <linux/device.h>
149#include <linux/sched.h> /* current, TASK_*, schedule_timeout() */
149 150
150#include <asm/uaccess.h> 151#include <asm/uaccess.h>
151 152
@@ -971,7 +972,7 @@ static int __init pt_init(void)
971 devfs_mk_dir("pt"); 972 devfs_mk_dir("pt");
972 for (unit = 0; unit < PT_UNITS; unit++) 973 for (unit = 0; unit < PT_UNITS; unit++)
973 if (pt[unit].present) { 974 if (pt[unit].present) {
974 class_device_create(pt_class, MKDEV(major, unit), 975 class_device_create(pt_class, NULL, MKDEV(major, unit),
975 NULL, "pt%d", unit); 976 NULL, "pt%d", unit);
976 err = devfs_mk_cdev(MKDEV(major, unit), 977 err = devfs_mk_cdev(MKDEV(major, unit),
977 S_IFCHR | S_IRUSR | S_IWUSR, 978 S_IFCHR | S_IRUSR | S_IWUSR,
@@ -980,7 +981,7 @@ static int __init pt_init(void)
980 class_device_destroy(pt_class, MKDEV(major, unit)); 981 class_device_destroy(pt_class, MKDEV(major, unit));
981 goto out_class; 982 goto out_class;
982 } 983 }
983 class_device_create(pt_class, MKDEV(major, unit + 128), 984 class_device_create(pt_class, NULL, MKDEV(major, unit + 128),
984 NULL, "pt%dn", unit); 985 NULL, "pt%dn", unit);
985 err = devfs_mk_cdev(MKDEV(major, unit + 128), 986 err = devfs_mk_cdev(MKDEV(major, unit + 128),
986 S_IFCHR | S_IRUSR | S_IWUSR, 987 S_IFCHR | S_IRUSR | S_IWUSR,
diff --git a/drivers/block/rd.c b/drivers/block/rd.c
index 145c1fbffe01..68c60a5bcdab 100644
--- a/drivers/block/rd.c
+++ b/drivers/block/rd.c
@@ -348,7 +348,7 @@ static int rd_open(struct inode *inode, struct file *filp)
348 struct block_device *bdev = inode->i_bdev; 348 struct block_device *bdev = inode->i_bdev;
349 struct address_space *mapping; 349 struct address_space *mapping;
350 unsigned bsize; 350 unsigned bsize;
351 int gfp_mask; 351 gfp_t gfp_mask;
352 352
353 inode = igrab(bdev->bd_inode); 353 inode = igrab(bdev->bd_inode);
354 rd_bdev[unit] = bdev; 354 rd_bdev[unit] = bdev;
diff --git a/drivers/block/sx8.c b/drivers/block/sx8.c
index d57007b92f77..1ded3b433459 100644
--- a/drivers/block/sx8.c
+++ b/drivers/block/sx8.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * sx8.c: Driver for Promise SATA SX8 looks-like-I2O hardware 2 * sx8.c: Driver for Promise SATA SX8 looks-like-I2O hardware
3 * 3 *
4 * Copyright 2004 Red Hat, Inc. 4 * Copyright 2004-2005 Red Hat, Inc.
5 * 5 *
6 * Author/maintainer: Jeff Garzik <jgarzik@pobox.com> 6 * Author/maintainer: Jeff Garzik <jgarzik@pobox.com>
7 * 7 *
@@ -31,10 +31,6 @@
31#include <asm/semaphore.h> 31#include <asm/semaphore.h>
32#include <asm/uaccess.h> 32#include <asm/uaccess.h>
33 33
34MODULE_AUTHOR("Jeff Garzik");
35MODULE_LICENSE("GPL");
36MODULE_DESCRIPTION("Promise SATA SX8 block driver");
37
38#if 0 34#if 0
39#define CARM_DEBUG 35#define CARM_DEBUG
40#define CARM_VERBOSE_DEBUG 36#define CARM_VERBOSE_DEBUG
@@ -45,9 +41,35 @@ MODULE_DESCRIPTION("Promise SATA SX8 block driver");
45#undef CARM_NDEBUG 41#undef CARM_NDEBUG
46 42
47#define DRV_NAME "sx8" 43#define DRV_NAME "sx8"
48#define DRV_VERSION "0.8" 44#define DRV_VERSION "1.0"
49#define PFX DRV_NAME ": " 45#define PFX DRV_NAME ": "
50 46
47MODULE_AUTHOR("Jeff Garzik");
48MODULE_LICENSE("GPL");
49MODULE_DESCRIPTION("Promise SATA SX8 block driver");
50MODULE_VERSION(DRV_VERSION);
51
52/*
53 * SX8 hardware has a single message queue for all ATA ports.
54 * When this driver was written, the hardware (firmware?) would
55 * corrupt data eventually, if more than one request was outstanding.
56 * As one can imagine, having 8 ports bottlenecking on a single
57 * command hurts performance.
58 *
59 * Based on user reports, later versions of the hardware (firmware?)
60 * seem to be able to survive with more than one command queued.
61 *
62 * Therefore, we default to the safe option -- 1 command -- but
63 * allow the user to increase this.
64 *
65 * SX8 should be able to support up to ~60 queued commands (CARM_MAX_REQ),
66 * but problems seem to occur when you exceed ~30, even on newer hardware.
67 */
68static int max_queue = 1;
69module_param(max_queue, int, 0444);
70MODULE_PARM_DESC(max_queue, "Maximum number of queued commands. (min==1, max==30, safe==1)");
71
72
51#define NEXT_RESP(idx) ((idx + 1) % RMSG_Q_LEN) 73#define NEXT_RESP(idx) ((idx + 1) % RMSG_Q_LEN)
52 74
53/* 0xf is just arbitrary, non-zero noise; this is sorta like poisoning */ 75/* 0xf is just arbitrary, non-zero noise; this is sorta like poisoning */
@@ -90,12 +112,10 @@ enum {
90 112
91 /* command message queue limits */ 113 /* command message queue limits */
92 CARM_MAX_REQ = 64, /* max command msgs per host */ 114 CARM_MAX_REQ = 64, /* max command msgs per host */
93 CARM_MAX_Q = 1, /* one command at a time */
94 CARM_MSG_LOW_WATER = (CARM_MAX_REQ / 4), /* refill mark */ 115 CARM_MSG_LOW_WATER = (CARM_MAX_REQ / 4), /* refill mark */
95 116
96 /* S/G limits, host-wide and per-request */ 117 /* S/G limits, host-wide and per-request */
97 CARM_MAX_REQ_SG = 32, /* max s/g entries per request */ 118 CARM_MAX_REQ_SG = 32, /* max s/g entries per request */
98 CARM_SG_BOUNDARY = 0xffffUL, /* s/g segment boundary */
99 CARM_MAX_HOST_SG = 600, /* max s/g entries per host */ 119 CARM_MAX_HOST_SG = 600, /* max s/g entries per host */
100 CARM_SG_LOW_WATER = (CARM_MAX_HOST_SG / 4), /* re-fill mark */ 120 CARM_SG_LOW_WATER = (CARM_MAX_HOST_SG / 4), /* re-fill mark */
101 121
@@ -181,6 +201,10 @@ enum {
181 FL_DYN_MAJOR = (1 << 17), 201 FL_DYN_MAJOR = (1 << 17),
182}; 202};
183 203
204enum {
205 CARM_SG_BOUNDARY = 0xffffUL, /* s/g segment boundary */
206};
207
184enum scatter_gather_types { 208enum scatter_gather_types {
185 SGT_32BIT = 0, 209 SGT_32BIT = 0,
186 SGT_64BIT = 1, 210 SGT_64BIT = 1,
@@ -218,7 +242,6 @@ static const char *state_name[] = {
218 242
219struct carm_port { 243struct carm_port {
220 unsigned int port_no; 244 unsigned int port_no;
221 unsigned int n_queued;
222 struct gendisk *disk; 245 struct gendisk *disk;
223 struct carm_host *host; 246 struct carm_host *host;
224 247
@@ -448,7 +471,7 @@ static inline int carm_lookup_bucket(u32 msg_size)
448 for (i = 0; i < ARRAY_SIZE(msg_sizes); i++) 471 for (i = 0; i < ARRAY_SIZE(msg_sizes); i++)
449 if (msg_size <= msg_sizes[i]) 472 if (msg_size <= msg_sizes[i])
450 return i; 473 return i;
451 474
452 return -ENOENT; 475 return -ENOENT;
453} 476}
454 477
@@ -509,7 +532,7 @@ static struct carm_request *carm_get_request(struct carm_host *host)
509 if (host->hw_sg_used >= (CARM_MAX_HOST_SG - CARM_MAX_REQ_SG)) 532 if (host->hw_sg_used >= (CARM_MAX_HOST_SG - CARM_MAX_REQ_SG))
510 return NULL; 533 return NULL;
511 534
512 for (i = 0; i < CARM_MAX_Q; i++) 535 for (i = 0; i < max_queue; i++)
513 if ((host->msg_alloc & (1ULL << i)) == 0) { 536 if ((host->msg_alloc & (1ULL << i)) == 0) {
514 struct carm_request *crq = &host->req[i]; 537 struct carm_request *crq = &host->req[i];
515 crq->port = NULL; 538 crq->port = NULL;
@@ -521,14 +544,14 @@ static struct carm_request *carm_get_request(struct carm_host *host)
521 assert(host->n_msgs <= CARM_MAX_REQ); 544 assert(host->n_msgs <= CARM_MAX_REQ);
522 return crq; 545 return crq;
523 } 546 }
524 547
525 DPRINTK("no request available, returning NULL\n"); 548 DPRINTK("no request available, returning NULL\n");
526 return NULL; 549 return NULL;
527} 550}
528 551
529static int carm_put_request(struct carm_host *host, struct carm_request *crq) 552static int carm_put_request(struct carm_host *host, struct carm_request *crq)
530{ 553{
531 assert(crq->tag < CARM_MAX_Q); 554 assert(crq->tag < max_queue);
532 555
533 if (unlikely((host->msg_alloc & (1ULL << crq->tag)) == 0)) 556 if (unlikely((host->msg_alloc & (1ULL << crq->tag)) == 0))
534 return -EINVAL; /* tried to clear a tag that was not active */ 557 return -EINVAL; /* tried to clear a tag that was not active */
@@ -791,7 +814,7 @@ static inline void carm_end_rq(struct carm_host *host, struct carm_request *crq,
791 int is_ok) 814 int is_ok)
792{ 815{
793 carm_end_request_queued(host, crq, is_ok); 816 carm_end_request_queued(host, crq, is_ok);
794 if (CARM_MAX_Q == 1) 817 if (max_queue == 1)
795 carm_round_robin(host); 818 carm_round_robin(host);
796 else if ((host->n_msgs <= CARM_MSG_LOW_WATER) && 819 else if ((host->n_msgs <= CARM_MSG_LOW_WATER) &&
797 (host->hw_sg_used <= CARM_SG_LOW_WATER)) { 820 (host->hw_sg_used <= CARM_SG_LOW_WATER)) {
diff --git a/drivers/block/ub.c b/drivers/block/ub.c
index ed4d5006fe62..bfb23d543ff7 100644
--- a/drivers/block/ub.c
+++ b/drivers/block/ub.c
@@ -1512,7 +1512,7 @@ static void ub_state_sense(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1512 scmd->nsg = 1; 1512 scmd->nsg = 1;
1513 sg = &scmd->sgv[0]; 1513 sg = &scmd->sgv[0];
1514 sg->page = virt_to_page(sc->top_sense); 1514 sg->page = virt_to_page(sc->top_sense);
1515 sg->offset = (unsigned int)sc->top_sense & (PAGE_SIZE-1); 1515 sg->offset = (unsigned long)sc->top_sense & (PAGE_SIZE-1);
1516 sg->length = UB_SENSE_SIZE; 1516 sg->length = UB_SENSE_SIZE;
1517 scmd->len = UB_SENSE_SIZE; 1517 scmd->len = UB_SENSE_SIZE;
1518 scmd->lun = cmd->lun; 1518 scmd->lun = cmd->lun;
@@ -1891,7 +1891,7 @@ static int ub_sync_read_cap(struct ub_dev *sc, struct ub_lun *lun,
1891 cmd->nsg = 1; 1891 cmd->nsg = 1;
1892 sg = &cmd->sgv[0]; 1892 sg = &cmd->sgv[0];
1893 sg->page = virt_to_page(p); 1893 sg->page = virt_to_page(p);
1894 sg->offset = (unsigned int)p & (PAGE_SIZE-1); 1894 sg->offset = (unsigned long)p & (PAGE_SIZE-1);
1895 sg->length = 8; 1895 sg->length = 8;
1896 cmd->len = 8; 1896 cmd->len = 8;
1897 cmd->lun = lun; 1897 cmd->lun = lun;
diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
index 543f93e0f23f..b9fbe6e7f9ae 100644
--- a/drivers/bluetooth/Kconfig
+++ b/drivers/bluetooth/Kconfig
@@ -55,14 +55,6 @@ config BT_HCIUART_BCSP
55 55
56 Say Y here to compile support for HCI BCSP protocol. 56 Say Y here to compile support for HCI BCSP protocol.
57 57
58config BT_HCIUART_BCSP_TXCRC
59 bool "Transmit CRC with every BCSP packet"
60 depends on BT_HCIUART_BCSP
61 help
62 If you say Y here, a 16-bit CRC checksum will be transmitted along with
63 every BCSP (BlueCore Serial Protocol) packet sent to the Bluetooth chip.
64 This increases reliability, but slightly reduces efficiency.
65
66config BT_HCIBCM203X 58config BT_HCIBCM203X
67 tristate "HCI BCM203x USB driver" 59 tristate "HCI BCM203x USB driver"
68 depends on USB 60 depends on USB
diff --git a/drivers/bluetooth/bpa10x.c b/drivers/bluetooth/bpa10x.c
index 4fa85234d8b5..0db0400519c9 100644
--- a/drivers/bluetooth/bpa10x.c
+++ b/drivers/bluetooth/bpa10x.c
@@ -550,6 +550,9 @@ static int bpa10x_probe(struct usb_interface *intf, const struct usb_device_id *
550 if (ignore) 550 if (ignore)
551 return -ENODEV; 551 return -ENODEV;
552 552
553 if (intf->cur_altsetting->desc.bInterfaceNumber > 0)
554 return -ENODEV;
555
553 data = kmalloc(sizeof(*data), GFP_KERNEL); 556 data = kmalloc(sizeof(*data), GFP_KERNEL);
554 if (!data) { 557 if (!data) {
555 BT_ERR("Can't allocate data structure"); 558 BT_ERR("Can't allocate data structure");
diff --git a/drivers/bluetooth/hci_bcsp.c b/drivers/bluetooth/hci_bcsp.c
index 0ee324e1265d..0a4761415ac3 100644
--- a/drivers/bluetooth/hci_bcsp.c
+++ b/drivers/bluetooth/hci_bcsp.c
@@ -1,35 +1,27 @@
1/*
2 BlueCore Serial Protocol (BCSP) for Linux Bluetooth stack (BlueZ).
3 Copyright 2002 by Fabrizio Gennari <fabrizio.gennari@philips.com>
4
5 Based on
6 hci_h4.c by Maxim Krasnyansky <maxk@qualcomm.com>
7 ABCSP by Carl Orsborn <cjo@csr.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 version 2 as
11 published by the Free Software Foundation;
12
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
16 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
17 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
18 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21
22 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
23 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
24 SOFTWARE IS DISCLAIMED.
25*/
26
27/* 1/*
28 * $Id: hci_bcsp.c,v 1.2 2002/09/26 05:05:14 maxk Exp $ 2 *
3 * Bluetooth HCI UART driver
4 *
5 * Copyright (C) 2002-2003 Fabrizio Gennari <fabrizio.gennari@philips.com>
6 * Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org>
7 *
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
29 */ 23 */
30 24
31#define VERSION "0.2"
32
33#include <linux/config.h> 25#include <linux/config.h>
34#include <linux/module.h> 26#include <linux/module.h>
35 27
@@ -52,16 +44,56 @@
52 44
53#include <net/bluetooth/bluetooth.h> 45#include <net/bluetooth/bluetooth.h>
54#include <net/bluetooth/hci_core.h> 46#include <net/bluetooth/hci_core.h>
47
55#include "hci_uart.h" 48#include "hci_uart.h"
56#include "hci_bcsp.h"
57 49
58#ifndef CONFIG_BT_HCIUART_DEBUG 50#ifndef CONFIG_BT_HCIUART_DEBUG
59#undef BT_DBG 51#undef BT_DBG
60#define BT_DBG( A... ) 52#define BT_DBG( A... )
61#endif 53#endif
62 54
55#define VERSION "0.3"
56
57static int txcrc = 1;
63static int hciextn = 1; 58static int hciextn = 1;
64 59
60#define BCSP_TXWINSIZE 4
61
62#define BCSP_ACK_PKT 0x05
63#define BCSP_LE_PKT 0x06
64
65struct bcsp_struct {
66 struct sk_buff_head unack; /* Unack'ed packets queue */
67 struct sk_buff_head rel; /* Reliable packets queue */
68 struct sk_buff_head unrel; /* Unreliable packets queue */
69
70 unsigned long rx_count;
71 struct sk_buff *rx_skb;
72 u8 rxseq_txack; /* rxseq == txack. */
73 u8 rxack; /* Last packet sent by us that the peer ack'ed */
74 struct timer_list tbcsp;
75
76 enum {
77 BCSP_W4_PKT_DELIMITER,
78 BCSP_W4_PKT_START,
79 BCSP_W4_BCSP_HDR,
80 BCSP_W4_DATA,
81 BCSP_W4_CRC
82 } rx_state;
83
84 enum {
85 BCSP_ESCSTATE_NOESC,
86 BCSP_ESCSTATE_ESC
87 } rx_esc_state;
88
89 u8 use_crc;
90 u16 message_crc;
91 u8 txack_req; /* Do we need to send ack's to the peer? */
92
93 /* Reliable packet sequence number - used to assign seq to each rel pkt. */
94 u8 msgq_txseq;
95};
96
65/* ---- BCSP CRC calculation ---- */ 97/* ---- BCSP CRC calculation ---- */
66 98
67/* Table for calculating CRC for polynomial 0x1021, LSB processed first, 99/* Table for calculating CRC for polynomial 0x1021, LSB processed first,
@@ -111,6 +143,7 @@ static u16 bcsp_crc_reverse(u16 crc)
111 rev |= (crc & 1); 143 rev |= (crc & 1);
112 crc = crc >> 1; 144 crc = crc >> 1;
113 } 145 }
146
114 return (rev); 147 return (rev);
115} 148}
116 149
@@ -119,6 +152,7 @@ static u16 bcsp_crc_reverse(u16 crc)
119static void bcsp_slip_msgdelim(struct sk_buff *skb) 152static void bcsp_slip_msgdelim(struct sk_buff *skb)
120{ 153{
121 const char pkt_delim = 0xc0; 154 const char pkt_delim = 0xc0;
155
122 memcpy(skb_put(skb, 1), &pkt_delim, 1); 156 memcpy(skb_put(skb, 1), &pkt_delim, 1);
123} 157}
124 158
@@ -173,11 +207,8 @@ static struct sk_buff *bcsp_prepare_pkt(struct bcsp_struct *bcsp, u8 *data,
173{ 207{
174 struct sk_buff *nskb; 208 struct sk_buff *nskb;
175 u8 hdr[4], chan; 209 u8 hdr[4], chan;
176 int rel, i;
177
178#ifdef CONFIG_BT_HCIUART_BCSP_TXCRC
179 u16 BCSP_CRC_INIT(bcsp_txmsg_crc); 210 u16 BCSP_CRC_INIT(bcsp_txmsg_crc);
180#endif 211 int rel, i;
181 212
182 switch (pkt_type) { 213 switch (pkt_type) {
183 case HCI_ACLDATA_PKT: 214 case HCI_ACLDATA_PKT:
@@ -240,9 +271,9 @@ static struct sk_buff *bcsp_prepare_pkt(struct bcsp_struct *bcsp, u8 *data,
240 BT_DBG("Sending packet with seqno %u", bcsp->msgq_txseq); 271 BT_DBG("Sending packet with seqno %u", bcsp->msgq_txseq);
241 bcsp->msgq_txseq = ++(bcsp->msgq_txseq) & 0x07; 272 bcsp->msgq_txseq = ++(bcsp->msgq_txseq) & 0x07;
242 } 273 }
243#ifdef CONFIG_BT_HCIUART_BCSP_TXCRC 274
244 hdr[0] |= 0x40; 275 if (bcsp->use_crc)
245#endif 276 hdr[0] |= 0x40;
246 277
247 hdr[1] = ((len << 4) & 0xff) | chan; 278 hdr[1] = ((len << 4) & 0xff) | chan;
248 hdr[2] = len >> 4; 279 hdr[2] = len >> 4;
@@ -251,25 +282,25 @@ static struct sk_buff *bcsp_prepare_pkt(struct bcsp_struct *bcsp, u8 *data,
251 /* Put BCSP header */ 282 /* Put BCSP header */
252 for (i = 0; i < 4; i++) { 283 for (i = 0; i < 4; i++) {
253 bcsp_slip_one_byte(nskb, hdr[i]); 284 bcsp_slip_one_byte(nskb, hdr[i]);
254#ifdef CONFIG_BT_HCIUART_BCSP_TXCRC 285
255 bcsp_crc_update(&bcsp_txmsg_crc, hdr[i]); 286 if (bcsp->use_crc)
256#endif 287 bcsp_crc_update(&bcsp_txmsg_crc, hdr[i]);
257 } 288 }
258 289
259 /* Put payload */ 290 /* Put payload */
260 for (i = 0; i < len; i++) { 291 for (i = 0; i < len; i++) {
261 bcsp_slip_one_byte(nskb, data[i]); 292 bcsp_slip_one_byte(nskb, data[i]);
262#ifdef CONFIG_BT_HCIUART_BCSP_TXCRC 293
263 bcsp_crc_update(&bcsp_txmsg_crc, data[i]); 294 if (bcsp->use_crc)
264#endif 295 bcsp_crc_update(&bcsp_txmsg_crc, data[i]);
265 } 296 }
266 297
267#ifdef CONFIG_BT_HCIUART_BCSP_TXCRC
268 /* Put CRC */ 298 /* Put CRC */
269 bcsp_txmsg_crc = bcsp_crc_reverse(bcsp_txmsg_crc); 299 if (bcsp->use_crc) {
270 bcsp_slip_one_byte(nskb, (u8) ((bcsp_txmsg_crc >> 8) & 0x00ff)); 300 bcsp_txmsg_crc = bcsp_crc_reverse(bcsp_txmsg_crc);
271 bcsp_slip_one_byte(nskb, (u8) (bcsp_txmsg_crc & 0x00ff)); 301 bcsp_slip_one_byte(nskb, (u8) ((bcsp_txmsg_crc >> 8) & 0x00ff));
272#endif 302 bcsp_slip_one_byte(nskb, (u8) (bcsp_txmsg_crc & 0x00ff));
303 }
273 304
274 bcsp_slip_msgdelim(nskb); 305 bcsp_slip_msgdelim(nskb);
275 return nskb; 306 return nskb;
@@ -317,7 +348,6 @@ static struct sk_buff *bcsp_dequeue(struct hci_uart *hu)
317 348
318 spin_unlock_irqrestore(&bcsp->unack.lock, flags); 349 spin_unlock_irqrestore(&bcsp->unack.lock, flags);
319 350
320
321 /* We could not send a reliable packet, either because there are 351 /* We could not send a reliable packet, either because there are
322 none or because there are too many unack'ed pkts. Did we receive 352 none or because there are too many unack'ed pkts. Did we receive
323 any packets we have not acknowledged yet ? */ 353 any packets we have not acknowledged yet ? */
@@ -363,7 +393,7 @@ static void bcsp_pkt_cull(struct bcsp_struct *bcsp)
363 BT_ERR("Peer acked invalid packet"); 393 BT_ERR("Peer acked invalid packet");
364 394
365 BT_DBG("Removing %u pkts out of %u, up to seqno %u", 395 BT_DBG("Removing %u pkts out of %u, up to seqno %u",
366 pkts_to_be_removed, bcsp->unack.qlen, (seqno - 1) & 0x07); 396 pkts_to_be_removed, bcsp->unack.qlen, (seqno - 1) & 0x07);
367 397
368 for (i = 0, skb = ((struct sk_buff *) &bcsp->unack)->next; i < pkts_to_be_removed 398 for (i = 0, skb = ((struct sk_buff *) &bcsp->unack)->next; i < pkts_to_be_removed
369 && skb != (struct sk_buff *) &bcsp->unack; i++) { 399 && skb != (struct sk_buff *) &bcsp->unack; i++) {
@@ -374,8 +404,10 @@ static void bcsp_pkt_cull(struct bcsp_struct *bcsp)
374 kfree_skb(skb); 404 kfree_skb(skb);
375 skb = nskb; 405 skb = nskb;
376 } 406 }
407
377 if (bcsp->unack.qlen == 0) 408 if (bcsp->unack.qlen == 0)
378 del_timer(&bcsp->tbcsp); 409 del_timer(&bcsp->tbcsp);
410
379 spin_unlock_irqrestore(&bcsp->unack.lock, flags); 411 spin_unlock_irqrestore(&bcsp->unack.lock, flags);
380 412
381 if (i != pkts_to_be_removed) 413 if (i != pkts_to_be_removed)
@@ -530,6 +562,7 @@ static inline void bcsp_complete_rx_pkt(struct hci_uart *hu)
530 562
531 hci_recv_frame(bcsp->rx_skb); 563 hci_recv_frame(bcsp->rx_skb);
532 } 564 }
565
533 bcsp->rx_state = BCSP_W4_PKT_DELIMITER; 566 bcsp->rx_state = BCSP_W4_PKT_DELIMITER;
534 bcsp->rx_skb = NULL; 567 bcsp->rx_skb = NULL;
535} 568}
@@ -598,8 +631,8 @@ static int bcsp_recv(struct hci_uart *hu, void *data, int count)
598 631
599 BT_ERR ("Checksum failed: computed %04x received %04x", 632 BT_ERR ("Checksum failed: computed %04x received %04x",
600 bcsp_crc_reverse(bcsp->message_crc), 633 bcsp_crc_reverse(bcsp->message_crc),
601 (bcsp->rx_skb-> data[bcsp->rx_skb->len - 2] << 8) + 634 (bcsp->rx_skb-> data[bcsp->rx_skb->len - 2] << 8) +
602 bcsp->rx_skb->data[bcsp->rx_skb->len - 1]); 635 bcsp->rx_skb->data[bcsp->rx_skb->len - 1]);
603 636
604 kfree_skb(bcsp->rx_skb); 637 kfree_skb(bcsp->rx_skb);
605 bcsp->rx_state = BCSP_W4_PKT_DELIMITER; 638 bcsp->rx_state = BCSP_W4_PKT_DELIMITER;
@@ -633,7 +666,7 @@ static int bcsp_recv(struct hci_uart *hu, void *data, int count)
633 bcsp->rx_count = 4; 666 bcsp->rx_count = 4;
634 bcsp->rx_esc_state = BCSP_ESCSTATE_NOESC; 667 bcsp->rx_esc_state = BCSP_ESCSTATE_NOESC;
635 BCSP_CRC_INIT(bcsp->message_crc); 668 BCSP_CRC_INIT(bcsp->message_crc);
636 669
637 /* Do not increment ptr or decrement count 670 /* Do not increment ptr or decrement count
638 * Allocate packet. Max len of a BCSP pkt= 671 * Allocate packet. Max len of a BCSP pkt=
639 * 0xFFF (payload) +4 (header) +2 (crc) */ 672 * 0xFFF (payload) +4 (header) +2 (crc) */
@@ -698,6 +731,9 @@ static int bcsp_open(struct hci_uart *hu)
698 731
699 bcsp->rx_state = BCSP_W4_PKT_DELIMITER; 732 bcsp->rx_state = BCSP_W4_PKT_DELIMITER;
700 733
734 if (txcrc)
735 bcsp->use_crc = 1;
736
701 return 0; 737 return 0;
702} 738}
703 739
@@ -718,18 +754,19 @@ static int bcsp_close(struct hci_uart *hu)
718} 754}
719 755
720static struct hci_uart_proto bcsp = { 756static struct hci_uart_proto bcsp = {
721 .id = HCI_UART_BCSP, 757 .id = HCI_UART_BCSP,
722 .open = bcsp_open, 758 .open = bcsp_open,
723 .close = bcsp_close, 759 .close = bcsp_close,
724 .enqueue = bcsp_enqueue, 760 .enqueue = bcsp_enqueue,
725 .dequeue = bcsp_dequeue, 761 .dequeue = bcsp_dequeue,
726 .recv = bcsp_recv, 762 .recv = bcsp_recv,
727 .flush = bcsp_flush 763 .flush = bcsp_flush
728}; 764};
729 765
730int bcsp_init(void) 766int bcsp_init(void)
731{ 767{
732 int err = hci_uart_register_proto(&bcsp); 768 int err = hci_uart_register_proto(&bcsp);
769
733 if (!err) 770 if (!err)
734 BT_INFO("HCI BCSP protocol initialized"); 771 BT_INFO("HCI BCSP protocol initialized");
735 else 772 else
@@ -743,5 +780,8 @@ int bcsp_deinit(void)
743 return hci_uart_unregister_proto(&bcsp); 780 return hci_uart_unregister_proto(&bcsp);
744} 781}
745 782
783module_param(txcrc, bool, 0644);
784MODULE_PARM_DESC(txcrc, "Transmit CRC with every BCSP packet");
785
746module_param(hciextn, bool, 0644); 786module_param(hciextn, bool, 0644);
747MODULE_PARM_DESC(hciextn, "Convert HCI Extensions into BCSP packets"); 787MODULE_PARM_DESC(hciextn, "Convert HCI Extensions into BCSP packets");
diff --git a/drivers/bluetooth/hci_bcsp.h b/drivers/bluetooth/hci_bcsp.h
deleted file mode 100644
index a2b3bb92274b..000000000000
--- a/drivers/bluetooth/hci_bcsp.h
+++ /dev/null
@@ -1,70 +0,0 @@
1/*
2 BlueCore Serial Protocol (BCSP) for Linux Bluetooth stack (BlueZ).
3 Copyright 2002 by Fabrizio Gennari <fabrizio.gennari@philips.com>
4
5 Based on
6 hci_h4.c by Maxim Krasnyansky <maxk@qualcomm.com>
7 ABCSP by Carl Orsborn <cjo@csr.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 version 2 as
11 published by the Free Software Foundation;
12
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
16 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
17 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
18 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21
22 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
23 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
24 SOFTWARE IS DISCLAIMED.
25*/
26
27/*
28 * $Id: hci_bcsp.h,v 1.2 2002/09/26 05:05:14 maxk Exp $
29 */
30
31#ifndef __HCI_BCSP_H__
32#define __HCI_BCSP_H__
33
34#define BCSP_TXWINSIZE 4
35
36#define BCSP_ACK_PKT 0x05
37#define BCSP_LE_PKT 0x06
38
39struct bcsp_struct {
40 struct sk_buff_head unack; /* Unack'ed packets queue */
41 struct sk_buff_head rel; /* Reliable packets queue */
42 struct sk_buff_head unrel; /* Unreliable packets queue */
43
44 unsigned long rx_count;
45 struct sk_buff *rx_skb;
46 u8 rxseq_txack; /* rxseq == txack. */
47 u8 rxack; /* Last packet sent by us that the peer ack'ed */
48 struct timer_list tbcsp;
49
50 enum {
51 BCSP_W4_PKT_DELIMITER,
52 BCSP_W4_PKT_START,
53 BCSP_W4_BCSP_HDR,
54 BCSP_W4_DATA,
55 BCSP_W4_CRC
56 } rx_state;
57
58 enum {
59 BCSP_ESCSTATE_NOESC,
60 BCSP_ESCSTATE_ESC
61 } rx_esc_state;
62
63 u16 message_crc;
64 u8 txack_req; /* Do we need to send ack's to the peer? */
65
66 /* Reliable packet sequence number - used to assign seq to each rel pkt. */
67 u8 msgq_txseq;
68};
69
70#endif /* __HCI_BCSP_H__ */
diff --git a/drivers/bluetooth/hci_h4.c b/drivers/bluetooth/hci_h4.c
index cf8a22d58d96..12e369a66fc2 100644
--- a/drivers/bluetooth/hci_h4.c
+++ b/drivers/bluetooth/hci_h4.c
@@ -1,33 +1,27 @@
1/*
2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (C) 2000-2001 Qualcomm Incorporated
4
5 Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.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 version 2 as
9 published by the Free Software Foundation;
10
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
12 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
14 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
15 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
16 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
22 SOFTWARE IS DISCLAIMED.
23*/
24
25/* 1/*
26 * Bluetooth HCI UART(H4) protocol.
27 * 2 *
28 * $Id: hci_h4.c,v 1.3 2002/09/09 01:17:32 maxk Exp $ 3 * Bluetooth HCI UART driver
4 *
5 * Copyright (C) 2000-2001 Qualcomm Incorporated
6 * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
7 * Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org>
8 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
29 */ 24 */
30#define VERSION "1.2"
31 25
32#include <linux/config.h> 26#include <linux/config.h>
33#include <linux/module.h> 27#include <linux/module.h>
@@ -51,24 +45,41 @@
51 45
52#include <net/bluetooth/bluetooth.h> 46#include <net/bluetooth/bluetooth.h>
53#include <net/bluetooth/hci_core.h> 47#include <net/bluetooth/hci_core.h>
48
54#include "hci_uart.h" 49#include "hci_uart.h"
55#include "hci_h4.h"
56 50
57#ifndef CONFIG_BT_HCIUART_DEBUG 51#ifndef CONFIG_BT_HCIUART_DEBUG
58#undef BT_DBG 52#undef BT_DBG
59#define BT_DBG( A... ) 53#define BT_DBG( A... )
60#endif 54#endif
61 55
56#define VERSION "1.2"
57
58struct h4_struct {
59 unsigned long rx_state;
60 unsigned long rx_count;
61 struct sk_buff *rx_skb;
62 struct sk_buff_head txq;
63};
64
65/* H4 receiver States */
66#define H4_W4_PACKET_TYPE 0
67#define H4_W4_EVENT_HDR 1
68#define H4_W4_ACL_HDR 2
69#define H4_W4_SCO_HDR 3
70#define H4_W4_DATA 4
71
62/* Initialize protocol */ 72/* Initialize protocol */
63static int h4_open(struct hci_uart *hu) 73static int h4_open(struct hci_uart *hu)
64{ 74{
65 struct h4_struct *h4; 75 struct h4_struct *h4;
66 76
67 BT_DBG("hu %p", hu); 77 BT_DBG("hu %p", hu);
68 78
69 h4 = kmalloc(sizeof(*h4), GFP_ATOMIC); 79 h4 = kmalloc(sizeof(*h4), GFP_ATOMIC);
70 if (!h4) 80 if (!h4)
71 return -ENOMEM; 81 return -ENOMEM;
82
72 memset(h4, 0, sizeof(*h4)); 83 memset(h4, 0, sizeof(*h4));
73 84
74 skb_queue_head_init(&h4->txq); 85 skb_queue_head_init(&h4->txq);
@@ -83,7 +94,9 @@ static int h4_flush(struct hci_uart *hu)
83 struct h4_struct *h4 = hu->priv; 94 struct h4_struct *h4 = hu->priv;
84 95
85 BT_DBG("hu %p", hu); 96 BT_DBG("hu %p", hu);
97
86 skb_queue_purge(&h4->txq); 98 skb_queue_purge(&h4->txq);
99
87 return 0; 100 return 0;
88} 101}
89 102
@@ -91,16 +104,19 @@ static int h4_flush(struct hci_uart *hu)
91static int h4_close(struct hci_uart *hu) 104static int h4_close(struct hci_uart *hu)
92{ 105{
93 struct h4_struct *h4 = hu->priv; 106 struct h4_struct *h4 = hu->priv;
107
94 hu->priv = NULL; 108 hu->priv = NULL;
95 109
96 BT_DBG("hu %p", hu); 110 BT_DBG("hu %p", hu);
97 111
98 skb_queue_purge(&h4->txq); 112 skb_queue_purge(&h4->txq);
113
99 if (h4->rx_skb) 114 if (h4->rx_skb)
100 kfree_skb(h4->rx_skb); 115 kfree_skb(h4->rx_skb);
101 116
102 hu->priv = NULL; 117 hu->priv = NULL;
103 kfree(h4); 118 kfree(h4);
119
104 return 0; 120 return 0;
105} 121}
106 122
@@ -114,6 +130,7 @@ static int h4_enqueue(struct hci_uart *hu, struct sk_buff *skb)
114 /* Prepend skb with frame type */ 130 /* Prepend skb with frame type */
115 memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1); 131 memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1);
116 skb_queue_tail(&h4->txq, skb); 132 skb_queue_tail(&h4->txq, skb);
133
117 return 0; 134 return 0;
118} 135}
119 136
@@ -122,6 +139,7 @@ static inline int h4_check_data_len(struct h4_struct *h4, int len)
122 register int room = skb_tailroom(h4->rx_skb); 139 register int room = skb_tailroom(h4->rx_skb);
123 140
124 BT_DBG("len %d room %d", len, room); 141 BT_DBG("len %d room %d", len, room);
142
125 if (!len) { 143 if (!len) {
126 hci_recv_frame(h4->rx_skb); 144 hci_recv_frame(h4->rx_skb);
127 } else if (len > room) { 145 } else if (len > room) {
@@ -136,6 +154,7 @@ static inline int h4_check_data_len(struct h4_struct *h4, int len)
136 h4->rx_state = H4_W4_PACKET_TYPE; 154 h4->rx_state = H4_W4_PACKET_TYPE;
137 h4->rx_skb = NULL; 155 h4->rx_skb = NULL;
138 h4->rx_count = 0; 156 h4->rx_count = 0;
157
139 return 0; 158 return 0;
140} 159}
141 160
@@ -228,6 +247,7 @@ static int h4_recv(struct hci_uart *hu, void *data, int count)
228 ptr++; count--; 247 ptr++; count--;
229 continue; 248 continue;
230 }; 249 };
250
231 ptr++; count--; 251 ptr++; count--;
232 252
233 /* Allocate packet */ 253 /* Allocate packet */
@@ -238,9 +258,11 @@ static int h4_recv(struct hci_uart *hu, void *data, int count)
238 h4->rx_count = 0; 258 h4->rx_count = 0;
239 return 0; 259 return 0;
240 } 260 }
261
241 h4->rx_skb->dev = (void *) hu->hdev; 262 h4->rx_skb->dev = (void *) hu->hdev;
242 bt_cb(h4->rx_skb)->pkt_type = type; 263 bt_cb(h4->rx_skb)->pkt_type = type;
243 } 264 }
265
244 return count; 266 return count;
245} 267}
246 268
@@ -251,23 +273,24 @@ static struct sk_buff *h4_dequeue(struct hci_uart *hu)
251} 273}
252 274
253static struct hci_uart_proto h4p = { 275static struct hci_uart_proto h4p = {
254 .id = HCI_UART_H4, 276 .id = HCI_UART_H4,
255 .open = h4_open, 277 .open = h4_open,
256 .close = h4_close, 278 .close = h4_close,
257 .recv = h4_recv, 279 .recv = h4_recv,
258 .enqueue = h4_enqueue, 280 .enqueue = h4_enqueue,
259 .dequeue = h4_dequeue, 281 .dequeue = h4_dequeue,
260 .flush = h4_flush, 282 .flush = h4_flush,
261}; 283};
262 284
263int h4_init(void) 285int h4_init(void)
264{ 286{
265 int err = hci_uart_register_proto(&h4p); 287 int err = hci_uart_register_proto(&h4p);
288
266 if (!err) 289 if (!err)
267 BT_INFO("HCI H4 protocol initialized"); 290 BT_INFO("HCI H4 protocol initialized");
268 else 291 else
269 BT_ERR("HCI H4 protocol registration failed"); 292 BT_ERR("HCI H4 protocol registration failed");
270 293
271 return err; 294 return err;
272} 295}
273 296
diff --git a/drivers/bluetooth/hci_h4.h b/drivers/bluetooth/hci_h4.h
deleted file mode 100644
index b95ff54bfd47..000000000000
--- a/drivers/bluetooth/hci_h4.h
+++ /dev/null
@@ -1,44 +0,0 @@
1/*
2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (C) 2000-2001 Qualcomm Incorporated
4
5 Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.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 version 2 as
9 published by the Free Software Foundation;
10
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
12 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
14 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
15 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
16 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
22 SOFTWARE IS DISCLAIMED.
23*/
24
25/*
26 * $Id: hci_h4.h,v 1.2 2002/09/09 01:17:32 maxk Exp $
27 */
28
29#ifdef __KERNEL__
30struct h4_struct {
31 unsigned long rx_state;
32 unsigned long rx_count;
33 struct sk_buff *rx_skb;
34 struct sk_buff_head txq;
35};
36
37/* H4 receiver States */
38#define H4_W4_PACKET_TYPE 0
39#define H4_W4_EVENT_HDR 1
40#define H4_W4_ACL_HDR 2
41#define H4_W4_SCO_HDR 3
42#define H4_W4_DATA 4
43
44#endif /* __KERNEL__ */
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index aed80cc22890..4a775f6ea390 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -1,33 +1,27 @@
1/*
2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (C) 2000-2001 Qualcomm Incorporated
4
5 Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.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 version 2 as
9 published by the Free Software Foundation;
10
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
12 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
14 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
15 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
16 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
22 SOFTWARE IS DISCLAIMED.
23*/
24
25/* 1/*
26 * Bluetooth HCI UART driver.
27 * 2 *
28 * $Id: hci_ldisc.c,v 1.5 2002/10/02 18:37:20 maxk Exp $ 3 * Bluetooth HCI UART driver
4 *
5 * Copyright (C) 2000-2001 Qualcomm Incorporated
6 * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
7 * Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org>
8 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
29 */ 24 */
30#define VERSION "2.1"
31 25
32#include <linux/config.h> 26#include <linux/config.h>
33#include <linux/module.h> 27#include <linux/module.h>
@@ -59,6 +53,8 @@
59#define BT_DBG( A... ) 53#define BT_DBG( A... )
60#endif 54#endif
61 55
56#define VERSION "2.2"
57
62static int reset = 0; 58static int reset = 0;
63 59
64static struct hci_uart_proto *hup[HCI_UART_MAX_PROTO]; 60static struct hci_uart_proto *hup[HCI_UART_MAX_PROTO];
@@ -72,6 +68,7 @@ int hci_uart_register_proto(struct hci_uart_proto *p)
72 return -EEXIST; 68 return -EEXIST;
73 69
74 hup[p->id] = p; 70 hup[p->id] = p;
71
75 return 0; 72 return 0;
76} 73}
77 74
@@ -84,6 +81,7 @@ int hci_uart_unregister_proto(struct hci_uart_proto *p)
84 return -EINVAL; 81 return -EINVAL;
85 82
86 hup[p->id] = NULL; 83 hup[p->id] = NULL;
84
87 return 0; 85 return 0;
88} 86}
89 87
@@ -91,13 +89,14 @@ static struct hci_uart_proto *hci_uart_get_proto(unsigned int id)
91{ 89{
92 if (id >= HCI_UART_MAX_PROTO) 90 if (id >= HCI_UART_MAX_PROTO)
93 return NULL; 91 return NULL;
92
94 return hup[id]; 93 return hup[id];
95} 94}
96 95
97static inline void hci_uart_tx_complete(struct hci_uart *hu, int pkt_type) 96static inline void hci_uart_tx_complete(struct hci_uart *hu, int pkt_type)
98{ 97{
99 struct hci_dev *hdev = hu->hdev; 98 struct hci_dev *hdev = hu->hdev;
100 99
101 /* Update HCI stat counters */ 100 /* Update HCI stat counters */
102 switch (pkt_type) { 101 switch (pkt_type) {
103 case HCI_COMMAND_PKT: 102 case HCI_COMMAND_PKT:
@@ -117,10 +116,12 @@ static inline void hci_uart_tx_complete(struct hci_uart *hu, int pkt_type)
117static inline struct sk_buff *hci_uart_dequeue(struct hci_uart *hu) 116static inline struct sk_buff *hci_uart_dequeue(struct hci_uart *hu)
118{ 117{
119 struct sk_buff *skb = hu->tx_skb; 118 struct sk_buff *skb = hu->tx_skb;
119
120 if (!skb) 120 if (!skb)
121 skb = hu->proto->dequeue(hu); 121 skb = hu->proto->dequeue(hu);
122 else 122 else
123 hu->tx_skb = NULL; 123 hu->tx_skb = NULL;
124
124 return skb; 125 return skb;
125} 126}
126 127
@@ -129,7 +130,7 @@ int hci_uart_tx_wakeup(struct hci_uart *hu)
129 struct tty_struct *tty = hu->tty; 130 struct tty_struct *tty = hu->tty;
130 struct hci_dev *hdev = hu->hdev; 131 struct hci_dev *hdev = hu->hdev;
131 struct sk_buff *skb; 132 struct sk_buff *skb;
132 133
133 if (test_and_set_bit(HCI_UART_SENDING, &hu->tx_state)) { 134 if (test_and_set_bit(HCI_UART_SENDING, &hu->tx_state)) {
134 set_bit(HCI_UART_TX_WAKEUP, &hu->tx_state); 135 set_bit(HCI_UART_TX_WAKEUP, &hu->tx_state);
135 return 0; 136 return 0;
@@ -142,7 +143,7 @@ restart:
142 143
143 while ((skb = hci_uart_dequeue(hu))) { 144 while ((skb = hci_uart_dequeue(hu))) {
144 int len; 145 int len;
145 146
146 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 147 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
147 len = tty->driver->write(tty, skb->data, skb->len); 148 len = tty->driver->write(tty, skb->data, skb->len);
148 hdev->stat.byte_tx += len; 149 hdev->stat.byte_tx += len;
@@ -152,11 +153,11 @@ restart:
152 hu->tx_skb = skb; 153 hu->tx_skb = skb;
153 break; 154 break;
154 } 155 }
155 156
156 hci_uart_tx_complete(hu, bt_cb(skb)->pkt_type); 157 hci_uart_tx_complete(hu, bt_cb(skb)->pkt_type);
157 kfree_skb(skb); 158 kfree_skb(skb);
158 } 159 }
159 160
160 if (test_bit(HCI_UART_TX_WAKEUP, &hu->tx_state)) 161 if (test_bit(HCI_UART_TX_WAKEUP, &hu->tx_state))
161 goto restart; 162 goto restart;
162 163
@@ -173,6 +174,7 @@ static int hci_uart_open(struct hci_dev *hdev)
173 /* Nothing to do for UART driver */ 174 /* Nothing to do for UART driver */
174 175
175 set_bit(HCI_RUNNING, &hdev->flags); 176 set_bit(HCI_RUNNING, &hdev->flags);
177
176 return 0; 178 return 0;
177} 179}
178 180
@@ -234,6 +236,7 @@ static int hci_uart_send_frame(struct sk_buff *skb)
234 hu->proto->enqueue(hu, skb); 236 hu->proto->enqueue(hu, skb);
235 237
236 hci_uart_tx_wakeup(hu); 238 hci_uart_tx_wakeup(hu);
239
237 return 0; 240 return 0;
238} 241}
239 242
@@ -241,7 +244,8 @@ static void hci_uart_destruct(struct hci_dev *hdev)
241{ 244{
242 struct hci_uart *hu; 245 struct hci_uart *hu;
243 246
244 if (!hdev) return; 247 if (!hdev)
248 return;
245 249
246 BT_DBG("%s", hdev->name); 250 BT_DBG("%s", hdev->name);
247 251
@@ -272,6 +276,7 @@ static int hci_uart_tty_open(struct tty_struct *tty)
272 BT_ERR("Can't allocate controll structure"); 276 BT_ERR("Can't allocate controll structure");
273 return -ENFILE; 277 return -ENFILE;
274 } 278 }
279
275 memset(hu, 0, sizeof(struct hci_uart)); 280 memset(hu, 0, sizeof(struct hci_uart));
276 281
277 tty->disc_data = hu; 282 tty->disc_data = hu;
@@ -280,8 +285,10 @@ static int hci_uart_tty_open(struct tty_struct *tty)
280 spin_lock_init(&hu->rx_lock); 285 spin_lock_init(&hu->rx_lock);
281 286
282 /* Flush any pending characters in the driver and line discipline. */ 287 /* Flush any pending characters in the driver and line discipline. */
288
283 /* FIXME: why is this needed. Note don't use ldisc_ref here as the 289 /* FIXME: why is this needed. Note don't use ldisc_ref here as the
284 open path is before the ldisc is referencable */ 290 open path is before the ldisc is referencable */
291
285 if (tty->ldisc.flush_buffer) 292 if (tty->ldisc.flush_buffer)
286 tty->ldisc.flush_buffer(tty); 293 tty->ldisc.flush_buffer(tty);
287 294
@@ -372,13 +379,13 @@ static int hci_uart_tty_room (struct tty_struct *tty)
372static void hci_uart_tty_receive(struct tty_struct *tty, const __u8 *data, char *flags, int count) 379static void hci_uart_tty_receive(struct tty_struct *tty, const __u8 *data, char *flags, int count)
373{ 380{
374 struct hci_uart *hu = (void *)tty->disc_data; 381 struct hci_uart *hu = (void *)tty->disc_data;
375 382
376 if (!hu || tty != hu->tty) 383 if (!hu || tty != hu->tty)
377 return; 384 return;
378 385
379 if (!test_bit(HCI_UART_PROTO_SET, &hu->flags)) 386 if (!test_bit(HCI_UART_PROTO_SET, &hu->flags))
380 return; 387 return;
381 388
382 spin_lock(&hu->rx_lock); 389 spin_lock(&hu->rx_lock);
383 hu->proto->recv(hu, (void *) data, count); 390 hu->proto->recv(hu, (void *) data, count);
384 hu->hdev->stat.byte_rx += count; 391 hu->hdev->stat.byte_rx += count;
@@ -429,8 +436,8 @@ static int hci_uart_register_dev(struct hci_uart *hu)
429static int hci_uart_set_proto(struct hci_uart *hu, int id) 436static int hci_uart_set_proto(struct hci_uart *hu, int id)
430{ 437{
431 struct hci_uart_proto *p; 438 struct hci_uart_proto *p;
432 int err; 439 int err;
433 440
434 p = hci_uart_get_proto(id); 441 p = hci_uart_get_proto(id);
435 if (!p) 442 if (!p)
436 return -EPROTONOSUPPORT; 443 return -EPROTONOSUPPORT;
@@ -446,6 +453,7 @@ static int hci_uart_set_proto(struct hci_uart *hu, int id)
446 p->close(hu); 453 p->close(hu);
447 return err; 454 return err;
448 } 455 }
456
449 return 0; 457 return 0;
450} 458}
451 459
@@ -463,7 +471,7 @@ static int hci_uart_set_proto(struct hci_uart *hu, int id)
463 * Return Value: Command dependent 471 * Return Value: Command dependent
464 */ 472 */
465static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file * file, 473static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file * file,
466 unsigned int cmd, unsigned long arg) 474 unsigned int cmd, unsigned long arg)
467{ 475{
468 struct hci_uart *hu = (void *)tty->disc_data; 476 struct hci_uart *hu = (void *)tty->disc_data;
469 int err = 0; 477 int err = 0;
@@ -483,14 +491,14 @@ static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file * file,
483 return err; 491 return err;
484 } 492 }
485 tty->low_latency = 1; 493 tty->low_latency = 1;
486 } else 494 } else
487 return -EBUSY; 495 return -EBUSY;
488 496
489 case HCIUARTGETPROTO: 497 case HCIUARTGETPROTO:
490 if (test_bit(HCI_UART_PROTO_SET, &hu->flags)) 498 if (test_bit(HCI_UART_PROTO_SET, &hu->flags))
491 return hu->proto->id; 499 return hu->proto->id;
492 return -EUNATCH; 500 return -EUNATCH;
493 501
494 default: 502 default:
495 err = n_tty_ioctl(tty, file, cmd, arg); 503 err = n_tty_ioctl(tty, file, cmd, arg);
496 break; 504 break;
@@ -502,28 +510,24 @@ static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file * file,
502/* 510/*
503 * We don't provide read/write/poll interface for user space. 511 * We don't provide read/write/poll interface for user space.
504 */ 512 */
505static ssize_t hci_uart_tty_read(struct tty_struct *tty, struct file *file, unsigned char __user *buf, size_t nr) 513static ssize_t hci_uart_tty_read(struct tty_struct *tty, struct file *file,
514 unsigned char __user *buf, size_t nr)
506{ 515{
507 return 0; 516 return 0;
508} 517}
509static ssize_t hci_uart_tty_write(struct tty_struct *tty, struct file *file, const unsigned char *data, size_t count) 518
519static ssize_t hci_uart_tty_write(struct tty_struct *tty, struct file *file,
520 const unsigned char *data, size_t count)
510{ 521{
511 return 0; 522 return 0;
512} 523}
513static unsigned int hci_uart_tty_poll(struct tty_struct *tty, struct file *filp, poll_table *wait) 524
525static unsigned int hci_uart_tty_poll(struct tty_struct *tty,
526 struct file *filp, poll_table *wait)
514{ 527{
515 return 0; 528 return 0;
516} 529}
517 530
518#ifdef CONFIG_BT_HCIUART_H4
519int h4_init(void);
520int h4_deinit(void);
521#endif
522#ifdef CONFIG_BT_HCIUART_BCSP
523int bcsp_init(void);
524int bcsp_deinit(void);
525#endif
526
527static int __init hci_uart_init(void) 531static int __init hci_uart_init(void)
528{ 532{
529 static struct tty_ldisc hci_uart_ldisc; 533 static struct tty_ldisc hci_uart_ldisc;
@@ -534,18 +538,18 @@ static int __init hci_uart_init(void)
534 /* Register the tty discipline */ 538 /* Register the tty discipline */
535 539
536 memset(&hci_uart_ldisc, 0, sizeof (hci_uart_ldisc)); 540 memset(&hci_uart_ldisc, 0, sizeof (hci_uart_ldisc));
537 hci_uart_ldisc.magic = TTY_LDISC_MAGIC; 541 hci_uart_ldisc.magic = TTY_LDISC_MAGIC;
538 hci_uart_ldisc.name = "n_hci"; 542 hci_uart_ldisc.name = "n_hci";
539 hci_uart_ldisc.open = hci_uart_tty_open; 543 hci_uart_ldisc.open = hci_uart_tty_open;
540 hci_uart_ldisc.close = hci_uart_tty_close; 544 hci_uart_ldisc.close = hci_uart_tty_close;
541 hci_uart_ldisc.read = hci_uart_tty_read; 545 hci_uart_ldisc.read = hci_uart_tty_read;
542 hci_uart_ldisc.write = hci_uart_tty_write; 546 hci_uart_ldisc.write = hci_uart_tty_write;
543 hci_uart_ldisc.ioctl = hci_uart_tty_ioctl; 547 hci_uart_ldisc.ioctl = hci_uart_tty_ioctl;
544 hci_uart_ldisc.poll = hci_uart_tty_poll; 548 hci_uart_ldisc.poll = hci_uart_tty_poll;
545 hci_uart_ldisc.receive_room= hci_uart_tty_room; 549 hci_uart_ldisc.receive_room = hci_uart_tty_room;
546 hci_uart_ldisc.receive_buf = hci_uart_tty_receive; 550 hci_uart_ldisc.receive_buf = hci_uart_tty_receive;
547 hci_uart_ldisc.write_wakeup= hci_uart_tty_wakeup; 551 hci_uart_ldisc.write_wakeup = hci_uart_tty_wakeup;
548 hci_uart_ldisc.owner = THIS_MODULE; 552 hci_uart_ldisc.owner = THIS_MODULE;
549 553
550 if ((err = tty_register_ldisc(N_HCI, &hci_uart_ldisc))) { 554 if ((err = tty_register_ldisc(N_HCI, &hci_uart_ldisc))) {
551 BT_ERR("HCI line discipline registration failed. (%d)", err); 555 BT_ERR("HCI line discipline registration failed. (%d)", err);
diff --git a/drivers/bluetooth/hci_uart.h b/drivers/bluetooth/hci_uart.h
index 0a57d72790ec..b250e6789dee 100644
--- a/drivers/bluetooth/hci_uart.h
+++ b/drivers/bluetooth/hci_uart.h
@@ -1,32 +1,29 @@
1/*
2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (C) 2000-2001 Qualcomm Incorporated
4
5 Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.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 version 2 as
9 published by the Free Software Foundation;
10
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
12 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
14 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
15 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
16 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
22 SOFTWARE IS DISCLAIMED.
23*/
24
25/* 1/*
26 * $Id: hci_uart.h,v 1.2 2002/09/09 01:17:32 maxk Exp $ 2 *
3 * Bluetooth HCI UART driver
4 *
5 * Copyright (C) 2000-2001 Qualcomm Incorporated
6 * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
7 * Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org>
8 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
27 */ 24 */
28 25
29#ifndef N_HCI 26#ifndef N_HCI
30#define N_HCI 15 27#define N_HCI 15
31#endif 28#endif
32 29
@@ -42,7 +39,6 @@
42#define HCI_UART_3WIRE 2 39#define HCI_UART_3WIRE 2
43#define HCI_UART_H4DS 3 40#define HCI_UART_H4DS 3
44 41
45#ifdef __KERNEL__
46struct hci_uart; 42struct hci_uart;
47 43
48struct hci_uart_proto { 44struct hci_uart_proto {
@@ -56,27 +52,35 @@ struct hci_uart_proto {
56}; 52};
57 53
58struct hci_uart { 54struct hci_uart {
59 struct tty_struct *tty; 55 struct tty_struct *tty;
60 struct hci_dev *hdev; 56 struct hci_dev *hdev;
61 unsigned long flags; 57 unsigned long flags;
62 58
63 struct hci_uart_proto *proto; 59 struct hci_uart_proto *proto;
64 void *priv; 60 void *priv;
65 61
66 struct sk_buff *tx_skb; 62 struct sk_buff *tx_skb;
67 unsigned long tx_state; 63 unsigned long tx_state;
68 spinlock_t rx_lock; 64 spinlock_t rx_lock;
69}; 65};
70 66
71/* HCI_UART flag bits */ 67/* HCI_UART flag bits */
72#define HCI_UART_PROTO_SET 0 68#define HCI_UART_PROTO_SET 0
73 69
74/* TX states */ 70/* TX states */
75#define HCI_UART_SENDING 1 71#define HCI_UART_SENDING 1
76#define HCI_UART_TX_WAKEUP 2 72#define HCI_UART_TX_WAKEUP 2
77 73
78int hci_uart_register_proto(struct hci_uart_proto *p); 74int hci_uart_register_proto(struct hci_uart_proto *p);
79int hci_uart_unregister_proto(struct hci_uart_proto *p); 75int hci_uart_unregister_proto(struct hci_uart_proto *p);
80int hci_uart_tx_wakeup(struct hci_uart *hu); 76int hci_uart_tx_wakeup(struct hci_uart *hu);
81 77
82#endif /* __KERNEL__ */ 78#ifdef CONFIG_BT_HCIUART_H4
79int h4_init(void);
80int h4_deinit(void);
81#endif
82
83#ifdef CONFIG_BT_HCIUART_BCSP
84int bcsp_init(void);
85int bcsp_deinit(void);
86#endif
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index c29365d5b524..fdf4370db994 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -661,7 +661,7 @@ config HW_RANDOM
661 661
662config NVRAM 662config NVRAM
663 tristate "/dev/nvram support" 663 tristate "/dev/nvram support"
664 depends on ATARI || X86 || X86_64 || ARM || GENERIC_NVRAM 664 depends on ATARI || X86 || ARM || GENERIC_NVRAM
665 ---help--- 665 ---help---
666 If you say Y here and create a character special file /dev/nvram 666 If you say Y here and create a character special file /dev/nvram
667 with major number 10 and minor number 144 using mknod ("man mknod"), 667 with major number 10 and minor number 144 using mknod ("man mknod"),
@@ -985,7 +985,7 @@ config MAX_RAW_DEVS
985 985
986config HANGCHECK_TIMER 986config HANGCHECK_TIMER
987 tristate "Hangcheck timer" 987 tristate "Hangcheck timer"
988 depends on X86_64 || X86 || IA64 || PPC64 || ARCH_S390 988 depends on X86 || IA64 || PPC64 || ARCH_S390
989 help 989 help
990 The hangcheck-timer module detects when the system has gone 990 The hangcheck-timer module detects when the system has gone
991 out to lunch past a certain margin. It can reboot the system 991 out to lunch past a certain margin. It can reboot the system
@@ -1001,5 +1001,17 @@ config MMTIMER
1001 1001
1002source "drivers/char/tpm/Kconfig" 1002source "drivers/char/tpm/Kconfig"
1003 1003
1004config TELCLOCK
1005 tristate "Telecom clock driver for MPBL0010 ATCA SBC"
1006 depends on EXPERIMENTAL
1007 default n
1008 help
1009 The telecom clock device is specific to the MPBL0010 ATCA computer and
1010 allows direct userspace access to the configuration of the telecom clock
1011 configuration settings. This device is used for hardware synchronization
1012 across the ATCA backplane fabric. Upon loading, the driver exports a
1013 sysfs directory, /sys/devices/platform/telco_clock, with a number of
1014 files for controlling the behavior of this hardware.
1015
1004endmenu 1016endmenu
1005 1017
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 08f69287ea36..4aeae687e88a 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -82,6 +82,7 @@ obj-$(CONFIG_NWFLASH) += nwflash.o
82obj-$(CONFIG_SCx200_GPIO) += scx200_gpio.o 82obj-$(CONFIG_SCx200_GPIO) += scx200_gpio.o
83obj-$(CONFIG_GPIO_VR41XX) += vr41xx_giu.o 83obj-$(CONFIG_GPIO_VR41XX) += vr41xx_giu.o
84obj-$(CONFIG_TANBAC_TB0219) += tb0219.o 84obj-$(CONFIG_TANBAC_TB0219) += tb0219.o
85obj-$(CONFIG_TELCLOCK) += tlclk.o
85 86
86obj-$(CONFIG_WATCHDOG) += watchdog/ 87obj-$(CONFIG_WATCHDOG) += watchdog/
87obj-$(CONFIG_MWAVE) += mwave/ 88obj-$(CONFIG_MWAVE) += mwave/
diff --git a/drivers/char/agp/Kconfig b/drivers/char/agp/Kconfig
index 7f8c1b53b754..486ed8a11b59 100644
--- a/drivers/char/agp/Kconfig
+++ b/drivers/char/agp/Kconfig
@@ -27,7 +27,7 @@ config AGP
27 27
28config AGP_ALI 28config AGP_ALI
29 tristate "ALI chipset support" 29 tristate "ALI chipset support"
30 depends on AGP && X86 && !X86_64 30 depends on AGP && X86_32
31 ---help--- 31 ---help---
32 This option gives you AGP support for the GLX component of 32 This option gives you AGP support for the GLX component of
33 XFree86 4.x on the following ALi chipsets. The supported chipsets 33 XFree86 4.x on the following ALi chipsets. The supported chipsets
@@ -45,7 +45,7 @@ config AGP_ALI
45 45
46config AGP_ATI 46config AGP_ATI
47 tristate "ATI chipset support" 47 tristate "ATI chipset support"
48 depends on AGP && X86 && !X86_64 48 depends on AGP && X86_32
49 ---help--- 49 ---help---
50 This option gives you AGP support for the GLX component of 50 This option gives you AGP support for the GLX component of
51 XFree86 4.x on the ATI RadeonIGP family of chipsets. 51 XFree86 4.x on the ATI RadeonIGP family of chipsets.
@@ -55,7 +55,7 @@ config AGP_ATI
55 55
56config AGP_AMD 56config AGP_AMD
57 tristate "AMD Irongate, 761, and 762 chipset support" 57 tristate "AMD Irongate, 761, and 762 chipset support"
58 depends on AGP && X86 && !X86_64 58 depends on AGP && X86_32
59 help 59 help
60 This option gives you AGP support for the GLX component of 60 This option gives you AGP support for the GLX component of
61 XFree86 4.x on AMD Irongate, 761, and 762 chipsets. 61 XFree86 4.x on AMD Irongate, 761, and 762 chipsets.
@@ -91,7 +91,7 @@ config AGP_INTEL
91 91
92config AGP_NVIDIA 92config AGP_NVIDIA
93 tristate "NVIDIA nForce/nForce2 chipset support" 93 tristate "NVIDIA nForce/nForce2 chipset support"
94 depends on AGP && X86 && !X86_64 94 depends on AGP && X86_32
95 help 95 help
96 This option gives you AGP support for the GLX component of 96 This option gives you AGP support for the GLX component of
97 XFree86 4.x on the following NVIDIA chipsets. The supported chipsets 97 XFree86 4.x on the following NVIDIA chipsets. The supported chipsets
@@ -99,7 +99,7 @@ config AGP_NVIDIA
99 99
100config AGP_SIS 100config AGP_SIS
101 tristate "SiS chipset support" 101 tristate "SiS chipset support"
102 depends on AGP && X86 && !X86_64 102 depends on AGP && X86_32
103 help 103 help
104 This option gives you AGP support for the GLX component of 104 This option gives you AGP support for the GLX component of
105 XFree86 4.x on Silicon Integrated Systems [SiS] chipsets. 105 XFree86 4.x on Silicon Integrated Systems [SiS] chipsets.
@@ -111,14 +111,14 @@ config AGP_SIS
111 111
112config AGP_SWORKS 112config AGP_SWORKS
113 tristate "Serverworks LE/HE chipset support" 113 tristate "Serverworks LE/HE chipset support"
114 depends on AGP && X86 && !X86_64 114 depends on AGP && X86_32
115 help 115 help
116 Say Y here to support the Serverworks AGP card. See 116 Say Y here to support the Serverworks AGP card. See
117 <http://www.serverworks.com/> for product descriptions and images. 117 <http://www.serverworks.com/> for product descriptions and images.
118 118
119config AGP_VIA 119config AGP_VIA
120 tristate "VIA chipset support" 120 tristate "VIA chipset support"
121 depends on AGP && X86 && !X86_64 121 depends on AGP && X86_32
122 help 122 help
123 This option gives you AGP support for the GLX component of 123 This option gives you AGP support for the GLX component of
124 XFree86 4.x on VIA MVP3/Apollo Pro chipsets. 124 XFree86 4.x on VIA MVP3/Apollo Pro chipsets.
@@ -154,7 +154,7 @@ config AGP_UNINORTH
154 154
155config AGP_EFFICEON 155config AGP_EFFICEON
156 tristate "Transmeta Efficeon support" 156 tristate "Transmeta Efficeon support"
157 depends on AGP && X86 && !X86_64 157 depends on AGP && X86_32
158 help 158 help
159 This option gives you AGP support for the Transmeta Efficeon 159 This option gives you AGP support for the Transmeta Efficeon
160 series processors with integrated northbridges. 160 series processors with integrated northbridges.
diff --git a/drivers/char/agp/ali-agp.c b/drivers/char/agp/ali-agp.c
index 9c9c9c2247ce..b02fc2267159 100644
--- a/drivers/char/agp/ali-agp.c
+++ b/drivers/char/agp/ali-agp.c
@@ -7,6 +7,7 @@
7#include <linux/pci.h> 7#include <linux/pci.h>
8#include <linux/init.h> 8#include <linux/init.h>
9#include <linux/agp_backend.h> 9#include <linux/agp_backend.h>
10#include <asm/page.h> /* PAGE_SIZE */
10#include "agp.h" 11#include "agp.h"
11 12
12#define ALI_AGPCTRL 0xb8 13#define ALI_AGPCTRL 0xb8
diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
index 0a7624a9b1c1..0e6c3a31d344 100644
--- a/drivers/char/agp/amd64-agp.c
+++ b/drivers/char/agp/amd64-agp.c
@@ -13,6 +13,7 @@
13#include <linux/pci.h> 13#include <linux/pci.h>
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/agp_backend.h> 15#include <linux/agp_backend.h>
16#include <asm/page.h> /* PAGE_SIZE */
16#include "agp.h" 17#include "agp.h"
17 18
18/* Will need to be increased if AMD64 ever goes >8-way. */ 19/* Will need to be increased if AMD64 ever goes >8-way. */
diff --git a/drivers/char/agp/ati-agp.c b/drivers/char/agp/ati-agp.c
index e572ced9100a..0b6e72642d6e 100644
--- a/drivers/char/agp/ati-agp.c
+++ b/drivers/char/agp/ati-agp.c
@@ -6,6 +6,8 @@
6#include <linux/module.h> 6#include <linux/module.h>
7#include <linux/pci.h> 7#include <linux/pci.h>
8#include <linux/init.h> 8#include <linux/init.h>
9#include <linux/string.h>
10#include <linux/slab.h>
9#include <linux/agp_backend.h> 11#include <linux/agp_backend.h>
10#include <asm/agp.h> 12#include <asm/agp.h>
11#include "agp.h" 13#include "agp.h"
diff --git a/drivers/char/agp/i460-agp.c b/drivers/char/agp/i460-agp.c
index 94943298c03e..a2d9e5e48bbe 100644
--- a/drivers/char/agp/i460-agp.c
+++ b/drivers/char/agp/i460-agp.c
@@ -10,6 +10,8 @@
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/pci.h> 11#include <linux/pci.h>
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/string.h>
14#include <linux/slab.h>
13#include <linux/agp_backend.h> 15#include <linux/agp_backend.h>
14 16
15#include "agp.h" 17#include "agp.h"
diff --git a/drivers/char/agp/isoch.c b/drivers/char/agp/isoch.c
index c9ac731504f2..40083241804e 100644
--- a/drivers/char/agp/isoch.c
+++ b/drivers/char/agp/isoch.c
@@ -6,6 +6,7 @@
6#include <linux/pci.h> 6#include <linux/pci.h>
7#include <linux/agp_backend.h> 7#include <linux/agp_backend.h>
8#include <linux/module.h> 8#include <linux/module.h>
9#include <linux/slab.h>
9 10
10#include "agp.h" 11#include "agp.h"
11 12
diff --git a/drivers/char/agp/sgi-agp.c b/drivers/char/agp/sgi-agp.c
index d3aa159c9dec..7957fc91f6ad 100644
--- a/drivers/char/agp/sgi-agp.c
+++ b/drivers/char/agp/sgi-agp.c
@@ -17,6 +17,7 @@
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/agp_backend.h> 18#include <linux/agp_backend.h>
19#include <asm/sn/addrs.h> 19#include <asm/sn/addrs.h>
20#include <asm/sn/io.h>
20#include <asm/sn/pcidev.h> 21#include <asm/sn/pcidev.h>
21#include <asm/sn/pcibus_provider_defs.h> 22#include <asm/sn/pcibus_provider_defs.h>
22#include <asm/sn/tioca_provider.h> 23#include <asm/sn/tioca_provider.h>
diff --git a/drivers/char/agp/sworks-agp.c b/drivers/char/agp/sworks-agp.c
index a9fb12c20eb7..71ea59a1dbeb 100644
--- a/drivers/char/agp/sworks-agp.c
+++ b/drivers/char/agp/sworks-agp.c
@@ -5,6 +5,8 @@
5#include <linux/module.h> 5#include <linux/module.h>
6#include <linux/pci.h> 6#include <linux/pci.h>
7#include <linux/init.h> 7#include <linux/init.h>
8#include <linux/string.h>
9#include <linux/slab.h>
8#include <linux/agp_backend.h> 10#include <linux/agp_backend.h>
9#include "agp.h" 11#include "agp.h"
10 12
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index cf4c3648463d..c7f818cd7b02 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -281,7 +281,7 @@ static char rcsid[] =
281 * make sure "cyc" appears in all kernel messages; all soft interrupts 281 * make sure "cyc" appears in all kernel messages; all soft interrupts
282 * handled by same routine; recognize out-of-band reception; comment 282 * handled by same routine; recognize out-of-band reception; comment
283 * out some diagnostic messages; leave RTS/CTS flow control to hardware; 283 * out some diagnostic messages; leave RTS/CTS flow control to hardware;
284 * fix race condition in -Z buffer management; only -Y needs to explictly 284 * fix race condition in -Z buffer management; only -Y needs to explicitly
285 * flush chars; tidy up some startup messages; 285 * flush chars; tidy up some startup messages;
286 * 286 *
287 * Revision 1.36.4.18 1996/07/25 18:57:31 bentson 287 * Revision 1.36.4.18 1996/07/25 18:57:31 bentson
diff --git a/drivers/char/drm/drm_sysfs.c b/drivers/char/drm/drm_sysfs.c
index 475cc5e555e1..6d3449761914 100644
--- a/drivers/char/drm/drm_sysfs.c
+++ b/drivers/char/drm/drm_sysfs.c
@@ -15,6 +15,8 @@
15#include <linux/device.h> 15#include <linux/device.h>
16#include <linux/kdev_t.h> 16#include <linux/kdev_t.h>
17#include <linux/err.h> 17#include <linux/err.h>
18#include <linux/slab.h>
19#include <linux/string.h>
18 20
19#include "drm_core.h" 21#include "drm_core.h"
20#include "drmP.h" 22#include "drmP.h"
diff --git a/drivers/char/dsp56k.c b/drivers/char/dsp56k.c
index 26271e3ca823..8693835cb2d5 100644
--- a/drivers/char/dsp56k.c
+++ b/drivers/char/dsp56k.c
@@ -515,7 +515,7 @@ static int __init dsp56k_init_driver(void)
515 err = PTR_ERR(dsp56k_class); 515 err = PTR_ERR(dsp56k_class);
516 goto out_chrdev; 516 goto out_chrdev;
517 } 517 }
518 class_device_create(dsp56k_class, MKDEV(DSP56K_MAJOR, 0), NULL, "dsp56k"); 518 class_device_create(dsp56k_class, NULL, MKDEV(DSP56K_MAJOR, 0), NULL, "dsp56k");
519 519
520 err = devfs_mk_cdev(MKDEV(DSP56K_MAJOR, 0), 520 err = devfs_mk_cdev(MKDEV(DSP56K_MAJOR, 0),
521 S_IFCHR | S_IRUSR | S_IWUSR, "dsp56k"); 521 S_IFCHR | S_IRUSR | S_IWUSR, "dsp56k");
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index 407708a001e4..b7a0e4d6b934 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -3113,6 +3113,7 @@ MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
3113int __init init_PCI (void) 3113int __init init_PCI (void)
3114{ /* Begin init_PCI */ 3114{ /* Begin init_PCI */
3115 memset (&epca_driver, 0, sizeof (epca_driver)); 3115 memset (&epca_driver, 0, sizeof (epca_driver));
3116 epca_driver.owner = THIS_MODULE;
3116 epca_driver.name = "epca"; 3117 epca_driver.name = "epca";
3117 epca_driver.id_table = epca_pci_tbl; 3118 epca_driver.id_table = epca_pci_tbl;
3118 epca_driver.probe = epca_init_one; 3119 epca_driver.probe = epca_init_one;
diff --git a/drivers/char/ftape/zftape/zftape-init.c b/drivers/char/ftape/zftape/zftape-init.c
index 5745b74044ec..821357ce7e0e 100644
--- a/drivers/char/ftape/zftape/zftape-init.c
+++ b/drivers/char/ftape/zftape/zftape-init.c
@@ -331,27 +331,27 @@ KERN_INFO
331 331
332 zft_class = class_create(THIS_MODULE, "zft"); 332 zft_class = class_create(THIS_MODULE, "zft");
333 for (i = 0; i < 4; i++) { 333 for (i = 0; i < 4; i++) {
334 class_device_create(zft_class, MKDEV(QIC117_TAPE_MAJOR, i), NULL, "qft%i", i); 334 class_device_create(zft_class, NULL, MKDEV(QIC117_TAPE_MAJOR, i), NULL, "qft%i", i);
335 devfs_mk_cdev(MKDEV(QIC117_TAPE_MAJOR, i), 335 devfs_mk_cdev(MKDEV(QIC117_TAPE_MAJOR, i),
336 S_IFCHR | S_IRUSR | S_IWUSR, 336 S_IFCHR | S_IRUSR | S_IWUSR,
337 "qft%i", i); 337 "qft%i", i);
338 class_device_create(zft_class, MKDEV(QIC117_TAPE_MAJOR, i + 4), NULL, "nqft%i", i); 338 class_device_create(zft_class, NULL, MKDEV(QIC117_TAPE_MAJOR, i + 4), NULL, "nqft%i", i);
339 devfs_mk_cdev(MKDEV(QIC117_TAPE_MAJOR, i + 4), 339 devfs_mk_cdev(MKDEV(QIC117_TAPE_MAJOR, i + 4),
340 S_IFCHR | S_IRUSR | S_IWUSR, 340 S_IFCHR | S_IRUSR | S_IWUSR,
341 "nqft%i", i); 341 "nqft%i", i);
342 class_device_create(zft_class, MKDEV(QIC117_TAPE_MAJOR, i + 16), NULL, "zqft%i", i); 342 class_device_create(zft_class, NULL, MKDEV(QIC117_TAPE_MAJOR, i + 16), NULL, "zqft%i", i);
343 devfs_mk_cdev(MKDEV(QIC117_TAPE_MAJOR, i + 16), 343 devfs_mk_cdev(MKDEV(QIC117_TAPE_MAJOR, i + 16),
344 S_IFCHR | S_IRUSR | S_IWUSR, 344 S_IFCHR | S_IRUSR | S_IWUSR,
345 "zqft%i", i); 345 "zqft%i", i);
346 class_device_create(zft_class, MKDEV(QIC117_TAPE_MAJOR, i + 20), NULL, "nzqft%i", i); 346 class_device_create(zft_class, NULL, MKDEV(QIC117_TAPE_MAJOR, i + 20), NULL, "nzqft%i", i);
347 devfs_mk_cdev(MKDEV(QIC117_TAPE_MAJOR, i + 20), 347 devfs_mk_cdev(MKDEV(QIC117_TAPE_MAJOR, i + 20),
348 S_IFCHR | S_IRUSR | S_IWUSR, 348 S_IFCHR | S_IRUSR | S_IWUSR,
349 "nzqft%i", i); 349 "nzqft%i", i);
350 class_device_create(zft_class, MKDEV(QIC117_TAPE_MAJOR, i + 32), NULL, "rawqft%i", i); 350 class_device_create(zft_class, NULL, MKDEV(QIC117_TAPE_MAJOR, i + 32), NULL, "rawqft%i", i);
351 devfs_mk_cdev(MKDEV(QIC117_TAPE_MAJOR, i + 32), 351 devfs_mk_cdev(MKDEV(QIC117_TAPE_MAJOR, i + 32),
352 S_IFCHR | S_IRUSR | S_IWUSR, 352 S_IFCHR | S_IRUSR | S_IWUSR,
353 "rawqft%i", i); 353 "rawqft%i", i);
354 class_device_create(zft_class, MKDEV(QIC117_TAPE_MAJOR, i + 36), NULL, "nrawrawqft%i", i); 354 class_device_create(zft_class, NULL, MKDEV(QIC117_TAPE_MAJOR, i + 36), NULL, "nrawrawqft%i", i);
355 devfs_mk_cdev(MKDEV(QIC117_TAPE_MAJOR, i + 36), 355 devfs_mk_cdev(MKDEV(QIC117_TAPE_MAJOR, i + 36),
356 S_IFCHR | S_IRUSR | S_IWUSR, 356 S_IFCHR | S_IRUSR | S_IWUSR,
357 "nrawqft%i", i); 357 "nrawqft%i", i);
diff --git a/drivers/char/hangcheck-timer.c b/drivers/char/hangcheck-timer.c
index a54bc93353af..66e53dd450ff 100644
--- a/drivers/char/hangcheck-timer.c
+++ b/drivers/char/hangcheck-timer.c
@@ -117,7 +117,7 @@ __setup("hcheck_reboot", hangcheck_parse_reboot);
117__setup("hcheck_dump_tasks", hangcheck_parse_dump_tasks); 117__setup("hcheck_dump_tasks", hangcheck_parse_dump_tasks);
118#endif /* not MODULE */ 118#endif /* not MODULE */
119 119
120#if defined(CONFIG_X86) || defined(CONFIG_X86_64) 120#if defined(CONFIG_X86)
121# define HAVE_MONOTONIC 121# define HAVE_MONOTONIC
122# define TIMER_FREQ 1000000000ULL 122# define TIMER_FREQ 1000000000ULL
123#elif defined(CONFIG_ARCH_S390) 123#elif defined(CONFIG_ARCH_S390)
diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index c055bb630ffc..3808d9572619 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -49,7 +49,9 @@
49#define HPET_USER_FREQ (64) 49#define HPET_USER_FREQ (64)
50#define HPET_DRIFT (500) 50#define HPET_DRIFT (500)
51 51
52static u32 hpet_ntimer, hpet_nhpet, hpet_max_freq = HPET_USER_FREQ; 52#define HPET_RANGE_SIZE 1024 /* from HPET spec */
53
54static u32 hpet_nhpet, hpet_max_freq = HPET_USER_FREQ;
53 55
54/* A lock for concurrent access by app and isr hpet activity. */ 56/* A lock for concurrent access by app and isr hpet activity. */
55static DEFINE_SPINLOCK(hpet_lock); 57static DEFINE_SPINLOCK(hpet_lock);
@@ -78,7 +80,7 @@ struct hpets {
78 struct hpet __iomem *hp_hpet; 80 struct hpet __iomem *hp_hpet;
79 unsigned long hp_hpet_phys; 81 unsigned long hp_hpet_phys;
80 struct time_interpolator *hp_interpolator; 82 struct time_interpolator *hp_interpolator;
81 unsigned long hp_period; 83 unsigned long long hp_tick_freq;
82 unsigned long hp_delta; 84 unsigned long hp_delta;
83 unsigned int hp_ntimer; 85 unsigned int hp_ntimer;
84 unsigned int hp_which; 86 unsigned int hp_which;
@@ -90,6 +92,7 @@ static struct hpets *hpets;
90#define HPET_OPEN 0x0001 92#define HPET_OPEN 0x0001
91#define HPET_IE 0x0002 /* interrupt enabled */ 93#define HPET_IE 0x0002 /* interrupt enabled */
92#define HPET_PERIODIC 0x0004 94#define HPET_PERIODIC 0x0004
95#define HPET_SHARED_IRQ 0x0008
93 96
94#if BITS_PER_LONG == 64 97#if BITS_PER_LONG == 64
95#define write_counter(V, MC) writeq(V, MC) 98#define write_counter(V, MC) writeq(V, MC)
@@ -120,6 +123,11 @@ static irqreturn_t hpet_interrupt(int irq, void *data, struct pt_regs *regs)
120 unsigned long isr; 123 unsigned long isr;
121 124
122 devp = data; 125 devp = data;
126 isr = 1 << (devp - devp->hd_hpets->hp_dev);
127
128 if ((devp->hd_flags & HPET_SHARED_IRQ) &&
129 !(isr & readl(&devp->hd_hpet->hpet_isr)))
130 return IRQ_NONE;
123 131
124 spin_lock(&hpet_lock); 132 spin_lock(&hpet_lock);
125 devp->hd_irqdata++; 133 devp->hd_irqdata++;
@@ -137,8 +145,8 @@ static irqreturn_t hpet_interrupt(int irq, void *data, struct pt_regs *regs)
137 &devp->hd_timer->hpet_compare); 145 &devp->hd_timer->hpet_compare);
138 } 146 }
139 147
140 isr = (1 << (devp - devp->hd_hpets->hp_dev)); 148 if (devp->hd_flags & HPET_SHARED_IRQ)
141 writeq(isr, &devp->hd_hpet->hpet_isr); 149 writel(isr, &devp->hd_hpet->hpet_isr);
142 spin_unlock(&hpet_lock); 150 spin_unlock(&hpet_lock);
143 151
144 spin_lock(&hpet_task_lock); 152 spin_lock(&hpet_task_lock);
@@ -276,7 +284,8 @@ static int hpet_mmap(struct file *file, struct vm_area_struct *vma)
276 284
277 if (io_remap_pfn_range(vma, vma->vm_start, addr >> PAGE_SHIFT, 285 if (io_remap_pfn_range(vma, vma->vm_start, addr >> PAGE_SHIFT,
278 PAGE_SIZE, vma->vm_page_prot)) { 286 PAGE_SIZE, vma->vm_page_prot)) {
279 printk(KERN_ERR "remap_pfn_range failed in hpet.c\n"); 287 printk(KERN_ERR "%s: io_remap_pfn_range failed\n",
288 __FUNCTION__);
280 return -EAGAIN; 289 return -EAGAIN;
281 } 290 }
282 291
@@ -364,7 +373,9 @@ static int hpet_ioctl_ieon(struct hpet_dev *devp)
364 hpet = devp->hd_hpet; 373 hpet = devp->hd_hpet;
365 hpetp = devp->hd_hpets; 374 hpetp = devp->hd_hpets;
366 375
367 v = readq(&timer->hpet_config); 376 if (!devp->hd_ireqfreq)
377 return -EIO;
378
368 spin_lock_irq(&hpet_lock); 379 spin_lock_irq(&hpet_lock);
369 380
370 if (devp->hd_flags & HPET_IE) { 381 if (devp->hd_flags & HPET_IE) {
@@ -373,16 +384,21 @@ static int hpet_ioctl_ieon(struct hpet_dev *devp)
373 } 384 }
374 385
375 devp->hd_flags |= HPET_IE; 386 devp->hd_flags |= HPET_IE;
387
388 if (readl(&timer->hpet_config) & Tn_INT_TYPE_CNF_MASK)
389 devp->hd_flags |= HPET_SHARED_IRQ;
376 spin_unlock_irq(&hpet_lock); 390 spin_unlock_irq(&hpet_lock);
377 391
378 t = readq(&timer->hpet_config);
379 irq = devp->hd_hdwirq; 392 irq = devp->hd_hdwirq;
380 393
381 if (irq) { 394 if (irq) {
382 sprintf(devp->hd_name, "hpet%d", (int)(devp - hpetp->hp_dev)); 395 unsigned long irq_flags;
383 396
384 if (request_irq 397 sprintf(devp->hd_name, "hpet%d", (int)(devp - hpetp->hp_dev));
385 (irq, hpet_interrupt, SA_INTERRUPT, devp->hd_name, (void *)devp)) { 398 irq_flags = devp->hd_flags & HPET_SHARED_IRQ
399 ? SA_SHIRQ : SA_INTERRUPT;
400 if (request_irq(irq, hpet_interrupt, irq_flags,
401 devp->hd_name, (void *)devp)) {
386 printk(KERN_ERR "hpet: IRQ %d is not free\n", irq); 402 printk(KERN_ERR "hpet: IRQ %d is not free\n", irq);
387 irq = 0; 403 irq = 0;
388 } 404 }
@@ -416,20 +432,24 @@ static int hpet_ioctl_ieon(struct hpet_dev *devp)
416 write_counter(t + m + hpetp->hp_delta, &timer->hpet_compare); 432 write_counter(t + m + hpetp->hp_delta, &timer->hpet_compare);
417 } 433 }
418 434
419 isr = (1 << (devp - hpets->hp_dev)); 435 if (devp->hd_flags & HPET_SHARED_IRQ) {
420 writeq(isr, &hpet->hpet_isr); 436 isr = 1 << (devp - devp->hd_hpets->hp_dev);
437 writel(isr, &hpet->hpet_isr);
438 }
421 writeq(g, &timer->hpet_config); 439 writeq(g, &timer->hpet_config);
422 local_irq_restore(flags); 440 local_irq_restore(flags);
423 441
424 return 0; 442 return 0;
425} 443}
426 444
427static inline unsigned long hpet_time_div(unsigned long dis) 445/* converts Hz to number of timer ticks */
446static inline unsigned long hpet_time_div(struct hpets *hpets,
447 unsigned long dis)
428{ 448{
429 unsigned long long m = 1000000000000000ULL; 449 unsigned long long m;
430 450
451 m = hpets->hp_tick_freq + (dis >> 1);
431 do_div(m, dis); 452 do_div(m, dis);
432
433 return (unsigned long)m; 453 return (unsigned long)m;
434} 454}
435 455
@@ -477,14 +497,21 @@ hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel)
477 { 497 {
478 struct hpet_info info; 498 struct hpet_info info;
479 499
480 info.hi_ireqfreq = hpet_time_div(hpetp->hp_period * 500 if (devp->hd_ireqfreq)
481 devp->hd_ireqfreq); 501 info.hi_ireqfreq =
502 hpet_time_div(hpetp, devp->hd_ireqfreq);
503 else
504 info.hi_ireqfreq = 0;
482 info.hi_flags = 505 info.hi_flags =
483 readq(&timer->hpet_config) & Tn_PER_INT_CAP_MASK; 506 readq(&timer->hpet_config) & Tn_PER_INT_CAP_MASK;
484 info.hi_hpet = devp->hd_hpets->hp_which; 507 info.hi_hpet = hpetp->hp_which;
485 info.hi_timer = devp - devp->hd_hpets->hp_dev; 508 info.hi_timer = devp - hpetp->hp_dev;
486 if (copy_to_user((void __user *)arg, &info, sizeof(info))) 509 if (kernel)
487 err = -EFAULT; 510 memcpy((void *)arg, &info, sizeof(info));
511 else
512 if (copy_to_user((void __user *)arg, &info,
513 sizeof(info)))
514 err = -EFAULT;
488 break; 515 break;
489 } 516 }
490 case HPET_EPI: 517 case HPET_EPI:
@@ -516,12 +543,12 @@ hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel)
516 break; 543 break;
517 } 544 }
518 545
519 if (arg & (arg - 1)) { 546 if (!arg) {
520 err = -EINVAL; 547 err = -EINVAL;
521 break; 548 break;
522 } 549 }
523 550
524 devp->hd_ireqfreq = hpet_time_div(hpetp->hp_period * arg); 551 devp->hd_ireqfreq = hpet_time_div(hpetp, arg);
525 } 552 }
526 553
527 return err; 554 return err;
@@ -539,6 +566,17 @@ static struct file_operations hpet_fops = {
539 .mmap = hpet_mmap, 566 .mmap = hpet_mmap,
540}; 567};
541 568
569static int hpet_is_known(struct hpet_data *hdp)
570{
571 struct hpets *hpetp;
572
573 for (hpetp = hpets; hpetp; hpetp = hpetp->hp_next)
574 if (hpetp->hp_hpet_phys == hdp->hd_phys_address)
575 return 1;
576
577 return 0;
578}
579
542EXPORT_SYMBOL(hpet_alloc); 580EXPORT_SYMBOL(hpet_alloc);
543EXPORT_SYMBOL(hpet_register); 581EXPORT_SYMBOL(hpet_register);
544EXPORT_SYMBOL(hpet_unregister); 582EXPORT_SYMBOL(hpet_unregister);
@@ -563,6 +601,8 @@ int hpet_register(struct hpet_task *tp, int periodic)
563 return -EINVAL; 601 return -EINVAL;
564 } 602 }
565 603
604 tp->ht_opaque = NULL;
605
566 spin_lock_irq(&hpet_task_lock); 606 spin_lock_irq(&hpet_task_lock);
567 spin_lock(&hpet_lock); 607 spin_lock(&hpet_lock);
568 608
@@ -702,15 +742,14 @@ static void hpet_register_interpolator(struct hpets *hpetp)
702#ifdef CONFIG_TIME_INTERPOLATION 742#ifdef CONFIG_TIME_INTERPOLATION
703 struct time_interpolator *ti; 743 struct time_interpolator *ti;
704 744
705 ti = kmalloc(sizeof(*ti), GFP_KERNEL); 745 ti = kzalloc(sizeof(*ti), GFP_KERNEL);
706 if (!ti) 746 if (!ti)
707 return; 747 return;
708 748
709 memset(ti, 0, sizeof(*ti));
710 ti->source = TIME_SOURCE_MMIO64; 749 ti->source = TIME_SOURCE_MMIO64;
711 ti->shift = 10; 750 ti->shift = 10;
712 ti->addr = &hpetp->hp_hpet->hpet_mc; 751 ti->addr = &hpetp->hp_hpet->hpet_mc;
713 ti->frequency = hpet_time_div(hpets->hp_period); 752 ti->frequency = hpetp->hp_tick_freq;
714 ti->drift = HPET_DRIFT; 753 ti->drift = HPET_DRIFT;
715 ti->mask = -1; 754 ti->mask = -1;
716 755
@@ -743,11 +782,11 @@ static unsigned long hpet_calibrate(struct hpets *hpetp)
743 if (!timer) 782 if (!timer)
744 return 0; 783 return 0;
745 784
746 hpet = hpets->hp_hpet; 785 hpet = hpetp->hp_hpet;
747 t = read_counter(&timer->hpet_compare); 786 t = read_counter(&timer->hpet_compare);
748 787
749 i = 0; 788 i = 0;
750 count = hpet_time_div(hpetp->hp_period * TICK_CALIBRATE); 789 count = hpet_time_div(hpetp, TICK_CALIBRATE);
751 790
752 local_irq_save(flags); 791 local_irq_save(flags);
753 792
@@ -771,28 +810,29 @@ int hpet_alloc(struct hpet_data *hdp)
771 struct hpets *hpetp; 810 struct hpets *hpetp;
772 size_t siz; 811 size_t siz;
773 struct hpet __iomem *hpet; 812 struct hpet __iomem *hpet;
774 static struct hpets *last = (struct hpets *)0; 813 static struct hpets *last = NULL;
775 unsigned long ns; 814 unsigned long period;
815 unsigned long long temp;
776 816
777 /* 817 /*
778 * hpet_alloc can be called by platform dependent code. 818 * hpet_alloc can be called by platform dependent code.
779 * if platform dependent code has allocated the hpet 819 * If platform dependent code has allocated the hpet that
780 * ACPI also reports hpet, then we catch it here. 820 * ACPI has also reported, then we catch it here.
781 */ 821 */
782 for (hpetp = hpets; hpetp; hpetp = hpetp->hp_next) 822 if (hpet_is_known(hdp)) {
783 if (hpetp->hp_hpet == hdp->hd_address) 823 printk(KERN_DEBUG "%s: duplicate HPET ignored\n",
784 return 0; 824 __FUNCTION__);
825 return 0;
826 }
785 827
786 siz = sizeof(struct hpets) + ((hdp->hd_nirqs - 1) * 828 siz = sizeof(struct hpets) + ((hdp->hd_nirqs - 1) *
787 sizeof(struct hpet_dev)); 829 sizeof(struct hpet_dev));
788 830
789 hpetp = kmalloc(siz, GFP_KERNEL); 831 hpetp = kzalloc(siz, GFP_KERNEL);
790 832
791 if (!hpetp) 833 if (!hpetp)
792 return -ENOMEM; 834 return -ENOMEM;
793 835
794 memset(hpetp, 0, siz);
795
796 hpetp->hp_which = hpet_nhpet++; 836 hpetp->hp_which = hpet_nhpet++;
797 hpetp->hp_hpet = hdp->hd_address; 837 hpetp->hp_hpet = hdp->hd_address;
798 hpetp->hp_hpet_phys = hdp->hd_phys_address; 838 hpetp->hp_hpet_phys = hdp->hd_phys_address;
@@ -822,21 +862,23 @@ int hpet_alloc(struct hpet_data *hdp)
822 862
823 last = hpetp; 863 last = hpetp;
824 864
825 hpetp->hp_period = (cap & HPET_COUNTER_CLK_PERIOD_MASK) >> 865 period = (cap & HPET_COUNTER_CLK_PERIOD_MASK) >>
826 HPET_COUNTER_CLK_PERIOD_SHIFT; 866 HPET_COUNTER_CLK_PERIOD_SHIFT; /* fs, 10^-15 */
867 temp = 1000000000000000uLL; /* 10^15 femtoseconds per second */
868 temp += period >> 1; /* round */
869 do_div(temp, period);
870 hpetp->hp_tick_freq = temp; /* ticks per second */
827 871
828 printk(KERN_INFO "hpet%d: at MMIO 0x%lx, IRQ%s", 872 printk(KERN_INFO "hpet%d: at MMIO 0x%lx (virtual 0x%p), IRQ%s",
829 hpetp->hp_which, hdp->hd_phys_address, 873 hpetp->hp_which, hdp->hd_phys_address, hdp->hd_address,
830 hpetp->hp_ntimer > 1 ? "s" : ""); 874 hpetp->hp_ntimer > 1 ? "s" : "");
831 for (i = 0; i < hpetp->hp_ntimer; i++) 875 for (i = 0; i < hpetp->hp_ntimer; i++)
832 printk("%s %d", i > 0 ? "," : "", hdp->hd_irq[i]); 876 printk("%s %d", i > 0 ? "," : "", hdp->hd_irq[i]);
833 printk("\n"); 877 printk("\n");
834 878
835 ns = hpetp->hp_period; /* femptoseconds, 10^-15 */ 879 printk(KERN_INFO "hpet%u: %u %d-bit timers, %Lu Hz\n",
836 ns /= 1000000; /* convert to nanoseconds, 10^-9 */ 880 hpetp->hp_which, hpetp->hp_ntimer,
837 printk(KERN_INFO "hpet%d: %ldns tick, %d %d-bit timers\n", 881 cap & HPET_COUNTER_SIZE_MASK ? 64 : 32, hpetp->hp_tick_freq);
838 hpetp->hp_which, ns, hpetp->hp_ntimer,
839 cap & HPET_COUNTER_SIZE_MASK ? 64 : 32);
840 882
841 mcfg = readq(&hpet->hpet_config); 883 mcfg = readq(&hpet->hpet_config);
842 if ((mcfg & HPET_ENABLE_CNF_MASK) == 0) { 884 if ((mcfg & HPET_ENABLE_CNF_MASK) == 0) {
@@ -845,13 +887,10 @@ int hpet_alloc(struct hpet_data *hdp)
845 writeq(mcfg, &hpet->hpet_config); 887 writeq(mcfg, &hpet->hpet_config);
846 } 888 }
847 889
848 for (i = 0, devp = hpetp->hp_dev; i < hpetp->hp_ntimer; 890 for (i = 0, devp = hpetp->hp_dev; i < hpetp->hp_ntimer; i++, devp++) {
849 i++, hpet_ntimer++, devp++) {
850 unsigned long v;
851 struct hpet_timer __iomem *timer; 891 struct hpet_timer __iomem *timer;
852 892
853 timer = &hpet->hpet_timers[devp - hpetp->hp_dev]; 893 timer = &hpet->hpet_timers[devp - hpetp->hp_dev];
854 v = readq(&timer->hpet_config);
855 894
856 devp->hd_hpets = hpetp; 895 devp->hd_hpets = hpetp;
857 devp->hd_hpet = hpet; 896 devp->hd_hpet = hpet;
@@ -880,7 +919,6 @@ static acpi_status hpet_resources(struct acpi_resource *res, void *data)
880 struct hpet_data *hdp; 919 struct hpet_data *hdp;
881 acpi_status status; 920 acpi_status status;
882 struct acpi_resource_address64 addr; 921 struct acpi_resource_address64 addr;
883 struct hpets *hpetp;
884 922
885 hdp = data; 923 hdp = data;
886 924
@@ -893,9 +931,29 @@ static acpi_status hpet_resources(struct acpi_resource *res, void *data)
893 hdp->hd_phys_address = addr.min_address_range; 931 hdp->hd_phys_address = addr.min_address_range;
894 hdp->hd_address = ioremap(addr.min_address_range, size); 932 hdp->hd_address = ioremap(addr.min_address_range, size);
895 933
896 for (hpetp = hpets; hpetp; hpetp = hpetp->hp_next) 934 if (hpet_is_known(hdp)) {
897 if (hpetp->hp_hpet == hdp->hd_address) 935 printk(KERN_DEBUG "%s: 0x%lx is busy\n",
898 return -EBUSY; 936 __FUNCTION__, hdp->hd_phys_address);
937 iounmap(hdp->hd_address);
938 return -EBUSY;
939 }
940 } else if (res->id == ACPI_RSTYPE_FIXED_MEM32) {
941 struct acpi_resource_fixed_mem32 *fixmem32;
942
943 fixmem32 = &res->data.fixed_memory32;
944 if (!fixmem32)
945 return -EINVAL;
946
947 hdp->hd_phys_address = fixmem32->range_base_address;
948 hdp->hd_address = ioremap(fixmem32->range_base_address,
949 HPET_RANGE_SIZE);
950
951 if (hpet_is_known(hdp)) {
952 printk(KERN_DEBUG "%s: 0x%lx is busy\n",
953 __FUNCTION__, hdp->hd_phys_address);
954 iounmap(hdp->hd_address);
955 return -EBUSY;
956 }
899 } else if (res->id == ACPI_RSTYPE_EXT_IRQ) { 957 } else if (res->id == ACPI_RSTYPE_EXT_IRQ) {
900 struct acpi_resource_ext_irq *irqp; 958 struct acpi_resource_ext_irq *irqp;
901 int i; 959 int i;
diff --git a/drivers/char/ip2main.c b/drivers/char/ip2main.c
index 9e4e26aef94e..d815d197dc3e 100644
--- a/drivers/char/ip2main.c
+++ b/drivers/char/ip2main.c
@@ -721,8 +721,9 @@ ip2_loadmain(int *iop, int *irqp, unsigned char *firmware, int firmsize)
721 } 721 }
722 722
723 if ( NULL != ( pB = i2BoardPtrTable[i] ) ) { 723 if ( NULL != ( pB = i2BoardPtrTable[i] ) ) {
724 class_device_create(ip2_class, MKDEV(IP2_IPL_MAJOR, 724 class_device_create(ip2_class, NULL,
725 4 * i), NULL, "ipl%d", i); 725 MKDEV(IP2_IPL_MAJOR, 4 * i),
726 NULL, "ipl%d", i);
726 err = devfs_mk_cdev(MKDEV(IP2_IPL_MAJOR, 4 * i), 727 err = devfs_mk_cdev(MKDEV(IP2_IPL_MAJOR, 4 * i),
727 S_IRUSR | S_IWUSR | S_IRGRP | S_IFCHR, 728 S_IRUSR | S_IWUSR | S_IRGRP | S_IFCHR,
728 "ip2/ipl%d", i); 729 "ip2/ipl%d", i);
@@ -732,8 +733,9 @@ ip2_loadmain(int *iop, int *irqp, unsigned char *firmware, int firmsize)
732 goto out_class; 733 goto out_class;
733 } 734 }
734 735
735 class_device_create(ip2_class, MKDEV(IP2_IPL_MAJOR, 736 class_device_create(ip2_class, NULL,
736 4 * i + 1), NULL, "stat%d", i); 737 MKDEV(IP2_IPL_MAJOR, 4 * i + 1),
738 NULL, "stat%d", i);
737 err = devfs_mk_cdev(MKDEV(IP2_IPL_MAJOR, 4 * i + 1), 739 err = devfs_mk_cdev(MKDEV(IP2_IPL_MAJOR, 4 * i + 1),
738 S_IRUSR | S_IWUSR | S_IRGRP | S_IFCHR, 740 S_IRUSR | S_IWUSR | S_IRGRP | S_IFCHR,
739 "ip2/stat%d", i); 741 "ip2/stat%d", i);
diff --git a/drivers/char/ipmi/ipmi_devintf.c b/drivers/char/ipmi/ipmi_devintf.c
index a09ff1080687..7c0684deea06 100644
--- a/drivers/char/ipmi/ipmi_devintf.c
+++ b/drivers/char/ipmi/ipmi_devintf.c
@@ -798,7 +798,7 @@ static void ipmi_new_smi(int if_num)
798 devfs_mk_cdev(dev, S_IFCHR | S_IRUSR | S_IWUSR, 798 devfs_mk_cdev(dev, S_IFCHR | S_IRUSR | S_IWUSR,
799 "ipmidev/%d", if_num); 799 "ipmidev/%d", if_num);
800 800
801 class_device_create(ipmi_class, dev, NULL, "ipmi%d", if_num); 801 class_device_create(ipmi_class, NULL, dev, NULL, "ipmi%d", if_num);
802} 802}
803 803
804static void ipmi_smi_gone(int if_num) 804static void ipmi_smi_gone(int if_num)
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index 9c19e5435a11..e3ddbdb85a2f 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -5246,7 +5246,8 @@ int __init stli_init(void)
5246 devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR, i), 5246 devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR, i),
5247 S_IFCHR | S_IRUSR | S_IWUSR, 5247 S_IFCHR | S_IRUSR | S_IWUSR,
5248 "staliomem/%d", i); 5248 "staliomem/%d", i);
5249 class_device_create(istallion_class, MKDEV(STL_SIOMEMMAJOR, i), 5249 class_device_create(istallion_class, NULL,
5250 MKDEV(STL_SIOMEMMAJOR, i),
5250 NULL, "staliomem%d", i); 5251 NULL, "staliomem%d", i);
5251 } 5252 }
5252 5253
diff --git a/drivers/char/lcd.c b/drivers/char/lcd.c
index b77161146144..29963d8be667 100644
--- a/drivers/char/lcd.c
+++ b/drivers/char/lcd.c
@@ -575,8 +575,8 @@ static inline int button_pressed(void)
575 575
576static int lcd_waiters = 0; 576static int lcd_waiters = 0;
577 577
578static long lcd_read(struct inode *inode, struct file *file, char *buf, 578static ssize_t lcd_read(struct file *file, char *buf,
579 unsigned long count) 579 size_t count, loff_t *ofs)
580{ 580{
581 long buttons_now; 581 long buttons_now;
582 582
diff --git a/drivers/char/lcd.h b/drivers/char/lcd.h
index 878a95280e87..a8d4ae737158 100644
--- a/drivers/char/lcd.h
+++ b/drivers/char/lcd.h
@@ -22,7 +22,7 @@ static int timeout(volatile unsigned long);
22#define MAX_IDLE_TIME 120 22#define MAX_IDLE_TIME 120
23 23
24struct lcd_display { 24struct lcd_display {
25 unsigned long buttons; 25 unsigned buttons;
26 int size1; 26 int size1;
27 int size2; 27 int size2;
28 unsigned char line1[LCD_CHARS_PER_LINE]; 28 unsigned char line1[LCD_CHARS_PER_LINE];
diff --git a/drivers/char/lp.c b/drivers/char/lp.c
index 2afb9038dbc5..e57260525293 100644
--- a/drivers/char/lp.c
+++ b/drivers/char/lp.c
@@ -805,7 +805,7 @@ static int lp_register(int nr, struct parport *port)
805 if (reset) 805 if (reset)
806 lp_reset(nr); 806 lp_reset(nr);
807 807
808 class_device_create(lp_class, MKDEV(LP_MAJOR, nr), NULL, 808 class_device_create(lp_class, NULL, MKDEV(LP_MAJOR, nr), NULL,
809 "lp%d", nr); 809 "lp%d", nr);
810 devfs_mk_cdev(MKDEV(LP_MAJOR, nr), S_IFCHR | S_IRUGO | S_IWUGO, 810 devfs_mk_cdev(MKDEV(LP_MAJOR, nr), S_IFCHR | S_IRUGO | S_IWUGO,
811 "printers/%d", nr); 811 "printers/%d", nr);
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 9df928d4f68d..91dd669273e0 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -918,7 +918,8 @@ static int __init chr_dev_init(void)
918 918
919 mem_class = class_create(THIS_MODULE, "mem"); 919 mem_class = class_create(THIS_MODULE, "mem");
920 for (i = 0; i < ARRAY_SIZE(devlist); i++) { 920 for (i = 0; i < ARRAY_SIZE(devlist); i++) {
921 class_device_create(mem_class, MKDEV(MEM_MAJOR, devlist[i].minor), 921 class_device_create(mem_class, NULL,
922 MKDEV(MEM_MAJOR, devlist[i].minor),
922 NULL, devlist[i].name); 923 NULL, devlist[i].name);
923 devfs_mk_cdev(MKDEV(MEM_MAJOR, devlist[i].minor), 924 devfs_mk_cdev(MKDEV(MEM_MAJOR, devlist[i].minor),
924 S_IFCHR | devlist[i].mode, devlist[i].name); 925 S_IFCHR | devlist[i].mode, devlist[i].name);
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 0c8375165e29..3e4c0414a01a 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -234,7 +234,7 @@ int misc_register(struct miscdevice * misc)
234 } 234 }
235 dev = MKDEV(MISC_MAJOR, misc->minor); 235 dev = MKDEV(MISC_MAJOR, misc->minor);
236 236
237 misc->class = class_device_create(misc_class, dev, misc->dev, 237 misc->class = class_device_create(misc_class, NULL, dev, misc->dev,
238 "%s", misc->name); 238 "%s", misc->name);
239 if (IS_ERR(misc->class)) { 239 if (IS_ERR(misc->class)) {
240 err = PTR_ERR(misc->class); 240 err = PTR_ERR(misc->class);
diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index 12006182f575..78c89a3e7825 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -441,7 +441,7 @@ static irqreturn_t
441mmtimer_interrupt(int irq, void *dev_id, struct pt_regs *regs) 441mmtimer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
442{ 442{
443 int i; 443 int i;
444 mmtimer_t *base = timers + cpuid_to_cnodeid(smp_processor_id()) * 444 mmtimer_t *base = timers + cpu_to_node(smp_processor_id()) *
445 NUM_COMPARATORS; 445 NUM_COMPARATORS;
446 unsigned long expires = 0; 446 unsigned long expires = 0;
447 int result = IRQ_NONE; 447 int result = IRQ_NONE;
@@ -608,7 +608,7 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
608 */ 608 */
609 preempt_disable(); 609 preempt_disable();
610 610
611 nodeid = cpuid_to_cnodeid(smp_processor_id()); 611 nodeid = cpu_to_node(smp_processor_id());
612 base = timers + nodeid * NUM_COMPARATORS; 612 base = timers + nodeid * NUM_COMPARATORS;
613retry: 613retry:
614 /* Don't use an allocated timer, or a deleted one that's pending */ 614 /* Don't use an allocated timer, or a deleted one that's pending */
diff --git a/drivers/char/mwave/3780i.c b/drivers/char/mwave/3780i.c
index 613aed9e1840..d1fe05e83882 100644
--- a/drivers/char/mwave/3780i.c
+++ b/drivers/char/mwave/3780i.c
@@ -53,6 +53,8 @@
53#include <linux/ioport.h> 53#include <linux/ioport.h>
54#include <linux/init.h> 54#include <linux/init.h>
55#include <linux/bitops.h> 55#include <linux/bitops.h>
56#include <linux/sched.h> /* cond_resched() */
57
56#include <asm/io.h> 58#include <asm/io.h>
57#include <asm/uaccess.h> 59#include <asm/uaccess.h>
58#include <asm/system.h> 60#include <asm/system.h>
diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c
index c9bdf544ed2c..c556f4d3ccd7 100644
--- a/drivers/char/n_tty.c
+++ b/drivers/char/n_tty.c
@@ -62,7 +62,7 @@
62 62
63static inline unsigned char *alloc_buf(void) 63static inline unsigned char *alloc_buf(void)
64{ 64{
65 unsigned int prio = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL; 65 gfp_t prio = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;
66 66
67 if (PAGE_SIZE != N_TTY_BUF_SIZE) 67 if (PAGE_SIZE != N_TTY_BUF_SIZE)
68 return kmalloc(N_TTY_BUF_SIZE, prio); 68 return kmalloc(N_TTY_BUF_SIZE, prio);
diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
index 1af733d07321..9e24bbd4090c 100644
--- a/drivers/char/nvram.c
+++ b/drivers/char/nvram.c
@@ -32,9 +32,11 @@
32 * added changelog 32 * added changelog
33 * 1.2 Erik Gilling: Cobalt Networks support 33 * 1.2 Erik Gilling: Cobalt Networks support
34 * Tim Hockin: general cleanup, Cobalt support 34 * Tim Hockin: general cleanup, Cobalt support
35 * 1.3 Jon Ringle: Comdial MP1000 support
36 *
35 */ 37 */
36 38
37#define NVRAM_VERSION "1.2" 39#define NVRAM_VERSION "1.3"
38 40
39#include <linux/module.h> 41#include <linux/module.h>
40#include <linux/config.h> 42#include <linux/config.h>
@@ -45,6 +47,7 @@
45#define PC 1 47#define PC 1
46#define ATARI 2 48#define ATARI 2
47#define COBALT 3 49#define COBALT 3
50#define MP1000 4
48 51
49/* select machine configuration */ 52/* select machine configuration */
50#if defined(CONFIG_ATARI) 53#if defined(CONFIG_ATARI)
@@ -54,6 +57,9 @@
54# if defined(CONFIG_COBALT) 57# if defined(CONFIG_COBALT)
55# include <linux/cobalt-nvram.h> 58# include <linux/cobalt-nvram.h>
56# define MACH COBALT 59# define MACH COBALT
60# elif defined(CONFIG_MACH_MP1000)
61# undef MACH
62# define MACH MP1000
57# else 63# else
58# define MACH PC 64# define MACH PC
59# endif 65# endif
@@ -112,6 +118,23 @@
112 118
113#endif 119#endif
114 120
121#if MACH == MP1000
122
123/* RTC in a MP1000 */
124#define CHECK_DRIVER_INIT() 1
125
126#define MP1000_CKS_RANGE_START 0
127#define MP1000_CKS_RANGE_END 111
128#define MP1000_CKS_LOC 112
129
130#define NVRAM_BYTES (128-NVRAM_FIRST_BYTE)
131
132#define mach_check_checksum mp1000_check_checksum
133#define mach_set_checksum mp1000_set_checksum
134#define mach_proc_infos mp1000_proc_infos
135
136#endif
137
115/* Note that *all* calls to CMOS_READ and CMOS_WRITE must be done with 138/* Note that *all* calls to CMOS_READ and CMOS_WRITE must be done with
116 * rtc_lock held. Due to the index-port/data-port design of the RTC, we 139 * rtc_lock held. Due to the index-port/data-port design of the RTC, we
117 * don't want two different things trying to get to it at once. (e.g. the 140 * don't want two different things trying to get to it at once. (e.g. the
@@ -915,6 +938,91 @@ atari_proc_infos(unsigned char *nvram, char *buffer, int *len,
915 938
916#endif /* MACH == ATARI */ 939#endif /* MACH == ATARI */
917 940
941#if MACH == MP1000
942
943static int
944mp1000_check_checksum(void)
945{
946 int i;
947 unsigned short sum = 0;
948 unsigned short expect;
949
950 for (i = MP1000_CKS_RANGE_START; i <= MP1000_CKS_RANGE_END; ++i)
951 sum += __nvram_read_byte(i);
952
953 expect = __nvram_read_byte(MP1000_CKS_LOC+1)<<8 |
954 __nvram_read_byte(MP1000_CKS_LOC);
955 return ((sum & 0xffff) == expect);
956}
957
958static void
959mp1000_set_checksum(void)
960{
961 int i;
962 unsigned short sum = 0;
963
964 for (i = MP1000_CKS_RANGE_START; i <= MP1000_CKS_RANGE_END; ++i)
965 sum += __nvram_read_byte(i);
966 __nvram_write_byte(sum >> 8, MP1000_CKS_LOC + 1);
967 __nvram_write_byte(sum & 0xff, MP1000_CKS_LOC);
968}
969
970#ifdef CONFIG_PROC_FS
971
972#define SERVER_N_LEN 32
973#define PATH_N_LEN 32
974#define FILE_N_LEN 32
975#define NVRAM_MAGIC_SIG 0xdead
976
977typedef struct NvRamImage
978{
979 unsigned short int magic;
980 unsigned short int mode;
981 char fname[FILE_N_LEN];
982 char path[PATH_N_LEN];
983 char server[SERVER_N_LEN];
984 char pad[12];
985} NvRam;
986
987static int
988mp1000_proc_infos(unsigned char *nvram, char *buffer, int *len,
989 off_t *begin, off_t offset, int size)
990{
991 int checksum;
992 NvRam* nv = (NvRam*)nvram;
993
994 spin_lock_irq(&rtc_lock);
995 checksum = __nvram_check_checksum();
996 spin_unlock_irq(&rtc_lock);
997
998 PRINT_PROC("Checksum status: %svalid\n", checksum ? "" : "not ");
999
1000 switch( nv->mode )
1001 {
1002 case 0 :
1003 PRINT_PROC( "\tMode 0, tftp prompt\n" );
1004 break;
1005 case 1 :
1006 PRINT_PROC( "\tMode 1, booting from disk\n" );
1007 break;
1008 case 2 :
1009 PRINT_PROC( "\tMode 2, Alternate boot from disk /boot/%s\n", nv->fname );
1010 break;
1011 case 3 :
1012 PRINT_PROC( "\tMode 3, Booting from net:\n" );
1013 PRINT_PROC( "\t\t%s:%s%s\n",nv->server, nv->path, nv->fname );
1014 break;
1015 default:
1016 PRINT_PROC( "\tInconsistant nvram?\n" );
1017 break;
1018 }
1019
1020 return 1;
1021}
1022#endif
1023
1024#endif /* MACH == MP1000 */
1025
918MODULE_LICENSE("GPL"); 1026MODULE_LICENSE("GPL");
919 1027
920EXPORT_SYMBOL(__nvram_read_byte); 1028EXPORT_SYMBOL(__nvram_read_byte);
diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index 0e22880432bc..306ee0f091a4 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -752,7 +752,7 @@ static struct file_operations pp_fops = {
752 752
753static void pp_attach(struct parport *port) 753static void pp_attach(struct parport *port)
754{ 754{
755 class_device_create(ppdev_class, MKDEV(PP_MAJOR, port->number), 755 class_device_create(ppdev_class, NULL, MKDEV(PP_MAJOR, port->number),
756 NULL, "parport%d", port->number); 756 NULL, "parport%d", port->number);
757} 757}
758 758
diff --git a/drivers/char/qtronix.c b/drivers/char/qtronix.c
index 40a3cf62e1a8..601d09baf9d7 100644
--- a/drivers/char/qtronix.c
+++ b/drivers/char/qtronix.c
@@ -591,6 +591,11 @@ static int __init psaux_init(void)
591 return retval; 591 return retval;
592 592
593 queue = (struct aux_queue *) kmalloc(sizeof(*queue), GFP_KERNEL); 593 queue = (struct aux_queue *) kmalloc(sizeof(*queue), GFP_KERNEL);
594 if (!queue) {
595 misc_deregister(&psaux_mouse);
596 return -ENOMEM;
597 }
598
594 memset(queue, 0, sizeof(*queue)); 599 memset(queue, 0, sizeof(*queue));
595 queue->head = queue->tail = 0; 600 queue->head = queue->tail = 0;
596 init_waitqueue_head(&queue->proc_list); 601 init_waitqueue_head(&queue->proc_list);
diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index f13e5de02207..30e4cbe16bb0 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -128,7 +128,7 @@ raw_ioctl(struct inode *inode, struct file *filp,
128static void bind_device(struct raw_config_request *rq) 128static void bind_device(struct raw_config_request *rq)
129{ 129{
130 class_device_destroy(raw_class, MKDEV(RAW_MAJOR, rq->raw_minor)); 130 class_device_destroy(raw_class, MKDEV(RAW_MAJOR, rq->raw_minor));
131 class_device_create(raw_class, MKDEV(RAW_MAJOR, rq->raw_minor), 131 class_device_create(raw_class, NULL, MKDEV(RAW_MAJOR, rq->raw_minor),
132 NULL, "raw%d", rq->raw_minor); 132 NULL, "raw%d", rq->raw_minor);
133} 133}
134 134
@@ -307,7 +307,7 @@ static int __init raw_init(void)
307 unregister_chrdev_region(dev, MAX_RAW_MINORS); 307 unregister_chrdev_region(dev, MAX_RAW_MINORS);
308 goto error; 308 goto error;
309 } 309 }
310 class_device_create(raw_class, MKDEV(RAW_MAJOR, 0), NULL, "rawctl"); 310 class_device_create(raw_class, NULL, MKDEV(RAW_MAJOR, 0), NULL, "rawctl");
311 311
312 devfs_mk_cdev(MKDEV(RAW_MAJOR, 0), 312 devfs_mk_cdev(MKDEV(RAW_MAJOR, 0),
313 S_IFCHR | S_IRUGO | S_IWUGO, 313 S_IFCHR | S_IRUGO | S_IWUGO,
diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
index 5b1d3680c8ab..928b850cc679 100644
--- a/drivers/char/rocket.c
+++ b/drivers/char/rocket.c
@@ -256,7 +256,6 @@ static int sInitController(CONTROLLER_T * CtlP, int CtlNum, ByteIO_t MudbacIO,
256static int sReadAiopID(ByteIO_t io); 256static int sReadAiopID(ByteIO_t io);
257static int sReadAiopNumChan(WordIO_t io); 257static int sReadAiopNumChan(WordIO_t io);
258 258
259#ifdef MODULE
260MODULE_AUTHOR("Theodore Ts'o"); 259MODULE_AUTHOR("Theodore Ts'o");
261MODULE_DESCRIPTION("Comtrol RocketPort driver"); 260MODULE_DESCRIPTION("Comtrol RocketPort driver");
262module_param(board1, ulong, 0); 261module_param(board1, ulong, 0);
@@ -288,17 +287,14 @@ MODULE_PARM_DESC(pc104_3, "set interface types for ISA(PC104) board #3 (e.g. pc1
288module_param_array(pc104_4, ulong, NULL, 0); 287module_param_array(pc104_4, ulong, NULL, 0);
289MODULE_PARM_DESC(pc104_4, "set interface types for ISA(PC104) board #4 (e.g. pc104_4=232,232,485,485,..."); 288MODULE_PARM_DESC(pc104_4, "set interface types for ISA(PC104) board #4 (e.g. pc104_4=232,232,485,485,...");
290 289
291int rp_init(void); 290static int rp_init(void);
292static void rp_cleanup_module(void); 291static void rp_cleanup_module(void);
293 292
294module_init(rp_init); 293module_init(rp_init);
295module_exit(rp_cleanup_module); 294module_exit(rp_cleanup_module);
296 295
297#endif
298 296
299#ifdef MODULE_LICENSE
300MODULE_LICENSE("Dual BSD/GPL"); 297MODULE_LICENSE("Dual BSD/GPL");
301#endif
302 298
303/*************************************************************************/ 299/*************************************************************************/
304/* Module code starts here */ 300/* Module code starts here */
@@ -2378,7 +2374,7 @@ static struct tty_operations rocket_ops = {
2378/* 2374/*
2379 * The module "startup" routine; it's run when the module is loaded. 2375 * The module "startup" routine; it's run when the module is loaded.
2380 */ 2376 */
2381int __init rp_init(void) 2377static int __init rp_init(void)
2382{ 2378{
2383 int retval, pci_boards_found, isa_boards_found, i; 2379 int retval, pci_boards_found, isa_boards_found, i;
2384 2380
@@ -2502,7 +2498,6 @@ int __init rp_init(void)
2502 return 0; 2498 return 0;
2503} 2499}
2504 2500
2505#ifdef MODULE
2506 2501
2507static void rp_cleanup_module(void) 2502static void rp_cleanup_module(void)
2508{ 2503{
@@ -2530,7 +2525,6 @@ static void rp_cleanup_module(void)
2530 if (controller) 2525 if (controller)
2531 release_region(controller, 4); 2526 release_region(controller, 4);
2532} 2527}
2533#endif
2534 2528
2535/*************************************************************************** 2529/***************************************************************************
2536Function: sInitController 2530Function: sInitController
diff --git a/drivers/char/s3c2410-rtc.c b/drivers/char/s3c2410-rtc.c
index e1a90d9a8756..887b8b2d7882 100644
--- a/drivers/char/s3c2410-rtc.c
+++ b/drivers/char/s3c2410-rtc.c
@@ -519,30 +519,28 @@ static struct timespec s3c2410_rtc_delta;
519 519
520static int ticnt_save; 520static int ticnt_save;
521 521
522static int s3c2410_rtc_suspend(struct device *dev, pm_message_t state, u32 level) 522static int s3c2410_rtc_suspend(struct device *dev, pm_message_t state)
523{ 523{
524 struct rtc_time tm; 524 struct rtc_time tm;
525 struct timespec time; 525 struct timespec time;
526 526
527 time.tv_nsec = 0; 527 time.tv_nsec = 0;
528 528
529 if (level == SUSPEND_POWER_DOWN) { 529 /* save TICNT for anyone using periodic interrupts */
530 /* save TICNT for anyone using periodic interrupts */
531 530
532 ticnt_save = readb(S3C2410_TICNT); 531 ticnt_save = readb(S3C2410_TICNT);
533 532
534 /* calculate time delta for suspend */ 533 /* calculate time delta for suspend */
535 534
536 s3c2410_rtc_gettime(&tm); 535 s3c2410_rtc_gettime(&tm);
537 rtc_tm_to_time(&tm, &time.tv_sec); 536 rtc_tm_to_time(&tm, &time.tv_sec);
538 save_time_delta(&s3c2410_rtc_delta, &time); 537 save_time_delta(&s3c2410_rtc_delta, &time);
539 s3c2410_rtc_enable(dev, 0); 538 s3c2410_rtc_enable(dev, 0);
540 }
541 539
542 return 0; 540 return 0;
543} 541}
544 542
545static int s3c2410_rtc_resume(struct device *dev, u32 level) 543static int s3c2410_rtc_resume(struct device *dev)
546{ 544{
547 struct rtc_time tm; 545 struct rtc_time tm;
548 struct timespec time; 546 struct timespec time;
diff --git a/drivers/char/ser_a2232.c b/drivers/char/ser_a2232.c
index 6b4e9d155f50..dda30e42ec79 100644
--- a/drivers/char/ser_a2232.c
+++ b/drivers/char/ser_a2232.c
@@ -790,7 +790,7 @@ static int __init a2232board_init(void)
790 790
791 } 791 }
792 792
793 printk("Total: %d A2232 boards initialized.\n.", nr_a2232); /* Some status report if no card was found */ 793 printk("Total: %d A2232 boards initialized.\n", nr_a2232); /* Some status report if no card was found */
794 794
795 a2232_init_portstructs(); 795 a2232_init_portstructs();
796 796
diff --git a/drivers/char/snsc.c b/drivers/char/snsc.c
index 261a41bf6d02..0e7d216e7eb0 100644
--- a/drivers/char/snsc.c
+++ b/drivers/char/snsc.c
@@ -377,7 +377,7 @@ scdrv_init(void)
377 dev_t first_dev, dev; 377 dev_t first_dev, dev;
378 nasid_t event_nasid = ia64_sn_get_console_nasid(); 378 nasid_t event_nasid = ia64_sn_get_console_nasid();
379 379
380 if (alloc_chrdev_region(&first_dev, 0, numionodes, 380 if (alloc_chrdev_region(&first_dev, 0, num_cnodes,
381 SYSCTL_BASENAME) < 0) { 381 SYSCTL_BASENAME) < 0) {
382 printk("%s: failed to register SN system controller device\n", 382 printk("%s: failed to register SN system controller device\n",
383 __FUNCTION__); 383 __FUNCTION__);
@@ -385,7 +385,7 @@ scdrv_init(void)
385 } 385 }
386 snsc_class = class_create(THIS_MODULE, SYSCTL_BASENAME); 386 snsc_class = class_create(THIS_MODULE, SYSCTL_BASENAME);
387 387
388 for (cnode = 0; cnode < numionodes; cnode++) { 388 for (cnode = 0; cnode < num_cnodes; cnode++) {
389 geoid = cnodeid_get_geoid(cnode); 389 geoid = cnodeid_get_geoid(cnode);
390 devnamep = devname; 390 devnamep = devname;
391 format_module_id(devnamep, geo_module(geoid), 391 format_module_id(devnamep, geo_module(geoid),
@@ -437,7 +437,7 @@ scdrv_init(void)
437 continue; 437 continue;
438 } 438 }
439 439
440 class_device_create(snsc_class, dev, NULL, 440 class_device_create(snsc_class, NULL, dev, NULL,
441 "%s", devname); 441 "%s", devname);
442 442
443 ia64_sn_irtr_intr_enable(scd->scd_nasid, 443 ia64_sn_irtr_intr_enable(scd->scd_nasid,
diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
index 36ae9ad2598c..f86c15587238 100644
--- a/drivers/char/sonypi.c
+++ b/drivers/char/sonypi.c
@@ -424,10 +424,6 @@ static struct sonypi_eventtypes {
424 424
425#define SONYPI_BUF_SIZE 128 425#define SONYPI_BUF_SIZE 128
426 426
427/* The name of the devices for the input device drivers */
428#define SONYPI_JOG_INPUTNAME "Sony Vaio Jogdial"
429#define SONYPI_KEY_INPUTNAME "Sony Vaio Keys"
430
431/* Correspondance table between sonypi events and input layer events */ 427/* Correspondance table between sonypi events and input layer events */
432static struct { 428static struct {
433 int sonypiev; 429 int sonypiev;
@@ -490,8 +486,8 @@ static struct sonypi_device {
490 struct fasync_struct *fifo_async; 486 struct fasync_struct *fifo_async;
491 int open_count; 487 int open_count;
492 int model; 488 int model;
493 struct input_dev input_jog_dev; 489 struct input_dev *input_jog_dev;
494 struct input_dev input_key_dev; 490 struct input_dev *input_key_dev;
495 struct work_struct input_work; 491 struct work_struct input_work;
496 struct kfifo *input_fifo; 492 struct kfifo *input_fifo;
497 spinlock_t input_fifo_lock; 493 spinlock_t input_fifo_lock;
@@ -779,8 +775,8 @@ static void input_keyrelease(void *data)
779 775
780static void sonypi_report_input_event(u8 event) 776static void sonypi_report_input_event(u8 event)
781{ 777{
782 struct input_dev *jog_dev = &sonypi_device.input_jog_dev; 778 struct input_dev *jog_dev = sonypi_device.input_jog_dev;
783 struct input_dev *key_dev = &sonypi_device.input_key_dev; 779 struct input_dev *key_dev = sonypi_device.input_key_dev;
784 struct sonypi_keypress kp = { NULL }; 780 struct sonypi_keypress kp = { NULL };
785 int i; 781 int i;
786 782
@@ -1171,19 +1167,17 @@ static int sonypi_disable(void)
1171#ifdef CONFIG_PM 1167#ifdef CONFIG_PM
1172static int old_camera_power; 1168static int old_camera_power;
1173 1169
1174static int sonypi_suspend(struct device *dev, pm_message_t state, u32 level) 1170static int sonypi_suspend(struct device *dev, pm_message_t state)
1175{ 1171{
1176 if (level == SUSPEND_DISABLE) { 1172 old_camera_power = sonypi_device.camera_power;
1177 old_camera_power = sonypi_device.camera_power; 1173 sonypi_disable();
1178 sonypi_disable(); 1174
1179 }
1180 return 0; 1175 return 0;
1181} 1176}
1182 1177
1183static int sonypi_resume(struct device *dev, u32 level) 1178static int sonypi_resume(struct device *dev)
1184{ 1179{
1185 if (level == RESUME_ENABLE) 1180 sonypi_enable(old_camera_power);
1186 sonypi_enable(old_camera_power);
1187 return 0; 1181 return 0;
1188} 1182}
1189#endif 1183#endif
@@ -1203,6 +1197,47 @@ static struct device_driver sonypi_driver = {
1203 .shutdown = sonypi_shutdown, 1197 .shutdown = sonypi_shutdown,
1204}; 1198};
1205 1199
1200static int __devinit sonypi_create_input_devices(void)
1201{
1202 struct input_dev *jog_dev;
1203 struct input_dev *key_dev;
1204 int i;
1205
1206 sonypi_device.input_jog_dev = jog_dev = input_allocate_device();
1207 if (!jog_dev)
1208 return -ENOMEM;
1209
1210 jog_dev->name = "Sony Vaio Jogdial";
1211 jog_dev->id.bustype = BUS_ISA;
1212 jog_dev->id.vendor = PCI_VENDOR_ID_SONY;
1213
1214 jog_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
1215 jog_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_MIDDLE);
1216 jog_dev->relbit[0] = BIT(REL_WHEEL);
1217
1218 sonypi_device.input_key_dev = key_dev = input_allocate_device();
1219 if (!key_dev) {
1220 input_free_device(jog_dev);
1221 sonypi_device.input_jog_dev = NULL;
1222 return -ENOMEM;
1223 }
1224
1225 key_dev->name = "Sony Vaio Keys";
1226 key_dev->id.bustype = BUS_ISA;
1227 key_dev->id.vendor = PCI_VENDOR_ID_SONY;
1228
1229 /* Initialize the Input Drivers: special keys */
1230 key_dev->evbit[0] = BIT(EV_KEY);
1231 for (i = 0; sonypi_inputkeys[i].sonypiev; i++)
1232 if (sonypi_inputkeys[i].inputev)
1233 set_bit(sonypi_inputkeys[i].inputev, key_dev->keybit);
1234
1235 input_register_device(jog_dev);
1236 input_register_device(key_dev);
1237
1238 return 0;
1239}
1240
1206static int __devinit sonypi_probe(void) 1241static int __devinit sonypi_probe(void)
1207{ 1242{
1208 int i, ret; 1243 int i, ret;
@@ -1298,34 +1333,10 @@ static int __devinit sonypi_probe(void)
1298 } 1333 }
1299 1334
1300 if (useinput) { 1335 if (useinput) {
1301 /* Initialize the Input Drivers: jogdial */
1302 int i;
1303 sonypi_device.input_jog_dev.evbit[0] =
1304 BIT(EV_KEY) | BIT(EV_REL);
1305 sonypi_device.input_jog_dev.keybit[LONG(BTN_MOUSE)] =
1306 BIT(BTN_MIDDLE);
1307 sonypi_device.input_jog_dev.relbit[0] = BIT(REL_WHEEL);
1308 sonypi_device.input_jog_dev.name = SONYPI_JOG_INPUTNAME;
1309 sonypi_device.input_jog_dev.id.bustype = BUS_ISA;
1310 sonypi_device.input_jog_dev.id.vendor = PCI_VENDOR_ID_SONY;
1311
1312 input_register_device(&sonypi_device.input_jog_dev);
1313 printk(KERN_INFO "%s input method installed.\n",
1314 sonypi_device.input_jog_dev.name);
1315
1316 /* Initialize the Input Drivers: special keys */
1317 sonypi_device.input_key_dev.evbit[0] = BIT(EV_KEY);
1318 for (i = 0; sonypi_inputkeys[i].sonypiev; i++)
1319 if (sonypi_inputkeys[i].inputev)
1320 set_bit(sonypi_inputkeys[i].inputev,
1321 sonypi_device.input_key_dev.keybit);
1322 sonypi_device.input_key_dev.name = SONYPI_KEY_INPUTNAME;
1323 sonypi_device.input_key_dev.id.bustype = BUS_ISA;
1324 sonypi_device.input_key_dev.id.vendor = PCI_VENDOR_ID_SONY;
1325 1336
1326 input_register_device(&sonypi_device.input_key_dev); 1337 ret = sonypi_create_input_devices();
1327 printk(KERN_INFO "%s input method installed.\n", 1338 if (ret)
1328 sonypi_device.input_key_dev.name); 1339 goto out_inputdevices;
1329 1340
1330 spin_lock_init(&sonypi_device.input_fifo_lock); 1341 spin_lock_init(&sonypi_device.input_fifo_lock);
1331 sonypi_device.input_fifo = 1342 sonypi_device.input_fifo =
@@ -1375,8 +1386,9 @@ static int __devinit sonypi_probe(void)
1375out_platformdev: 1386out_platformdev:
1376 kfifo_free(sonypi_device.input_fifo); 1387 kfifo_free(sonypi_device.input_fifo);
1377out_infifo: 1388out_infifo:
1378 input_unregister_device(&sonypi_device.input_key_dev); 1389 input_unregister_device(sonypi_device.input_key_dev);
1379 input_unregister_device(&sonypi_device.input_jog_dev); 1390 input_unregister_device(sonypi_device.input_jog_dev);
1391out_inputdevices:
1380 free_irq(sonypi_device.irq, sonypi_irq); 1392 free_irq(sonypi_device.irq, sonypi_irq);
1381out_reqirq: 1393out_reqirq:
1382 release_region(sonypi_device.ioport1, sonypi_device.region_size); 1394 release_region(sonypi_device.ioport1, sonypi_device.region_size);
@@ -1402,8 +1414,8 @@ static void __devexit sonypi_remove(void)
1402 platform_device_unregister(sonypi_device.pdev); 1414 platform_device_unregister(sonypi_device.pdev);
1403 1415
1404 if (useinput) { 1416 if (useinput) {
1405 input_unregister_device(&sonypi_device.input_key_dev); 1417 input_unregister_device(sonypi_device.input_key_dev);
1406 input_unregister_device(&sonypi_device.input_jog_dev); 1418 input_unregister_device(sonypi_device.input_jog_dev);
1407 kfifo_free(sonypi_device.input_fifo); 1419 kfifo_free(sonypi_device.input_fifo);
1408 } 1420 }
1409 1421
diff --git a/drivers/char/specialix.c b/drivers/char/specialix.c
index 50e0b612a8a2..352547eabf7b 100644
--- a/drivers/char/specialix.c
+++ b/drivers/char/specialix.c
@@ -38,19 +38,19 @@
38 * 38 *
39 * Revision 1.0: April 1st 1997. 39 * Revision 1.0: April 1st 1997.
40 * Initial release for alpha testing. 40 * Initial release for alpha testing.
41 * Revision 1.1: April 14th 1997. 41 * Revision 1.1: April 14th 1997.
42 * Incorporated Richard Hudsons suggestions, 42 * Incorporated Richard Hudsons suggestions,
43 * removed some debugging printk's. 43 * removed some debugging printk's.
44 * Revision 1.2: April 15th 1997. 44 * Revision 1.2: April 15th 1997.
45 * Ported to 2.1.x kernels. 45 * Ported to 2.1.x kernels.
46 * Revision 1.3: April 17th 1997 46 * Revision 1.3: April 17th 1997
47 * Backported to 2.0. (Compatibility macros). 47 * Backported to 2.0. (Compatibility macros).
48 * Revision 1.4: April 18th 1997 48 * Revision 1.4: April 18th 1997
49 * Fixed DTR/RTS bug that caused the card to indicate 49 * Fixed DTR/RTS bug that caused the card to indicate
50 * "don't send data" to a modem after the password prompt. 50 * "don't send data" to a modem after the password prompt.
51 * Fixed bug for premature (fake) interrupts. 51 * Fixed bug for premature (fake) interrupts.
52 * Revision 1.5: April 19th 1997 52 * Revision 1.5: April 19th 1997
53 * fixed a minor typo in the header file, cleanup a little. 53 * fixed a minor typo in the header file, cleanup a little.
54 * performance warnings are now MAXed at once per minute. 54 * performance warnings are now MAXed at once per minute.
55 * Revision 1.6: May 23 1997 55 * Revision 1.6: May 23 1997
56 * Changed the specialix=... format to include interrupt. 56 * Changed the specialix=... format to include interrupt.
@@ -60,10 +60,10 @@
60 * port to linux-2.1.43 kernel. 60 * port to linux-2.1.43 kernel.
61 * Revision 1.9: Oct 9 1998 61 * Revision 1.9: Oct 9 1998
62 * Added stuff for the IO8+/PCI version. 62 * Added stuff for the IO8+/PCI version.
63 * Revision 1.10: Oct 22 1999 / Jan 21 2000. 63 * Revision 1.10: Oct 22 1999 / Jan 21 2000.
64 * Added stuff for setserial. 64 * Added stuff for setserial.
65 * Nicolas Mailhot (Nicolas.Mailhot@email.enst.fr) 65 * Nicolas Mailhot (Nicolas.Mailhot@email.enst.fr)
66 * 66 *
67 */ 67 */
68 68
69#define VERSION "1.11" 69#define VERSION "1.11"
@@ -154,7 +154,7 @@ static int sx_poll = HZ;
154 154
155 155
156 156
157/* 157/*
158 * The following defines are mostly for testing purposes. But if you need 158 * The following defines are mostly for testing purposes. But if you need
159 * some nice reporting in your syslog, you can define them also. 159 * some nice reporting in your syslog, you can define them also.
160 */ 160 */
@@ -188,7 +188,7 @@ static DECLARE_MUTEX(tmp_buf_sem);
188 188
189static unsigned long baud_table[] = { 189static unsigned long baud_table[] = {
190 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 190 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
191 9600, 19200, 38400, 57600, 115200, 0, 191 9600, 19200, 38400, 57600, 115200, 0,
192}; 192};
193 193
194static struct specialix_board sx_board[SX_NBOARD] = { 194static struct specialix_board sx_board[SX_NBOARD] = {
@@ -216,7 +216,7 @@ static inline int sx_paranoia_check(struct specialix_port const * port,
216 KERN_ERR "sx: Warning: bad specialix port magic number for device %s in %s\n"; 216 KERN_ERR "sx: Warning: bad specialix port magic number for device %s in %s\n";
217 static const char *badinfo = 217 static const char *badinfo =
218 KERN_ERR "sx: Warning: null specialix port for device %s in %s\n"; 218 KERN_ERR "sx: Warning: null specialix port for device %s in %s\n";
219 219
220 if (!port) { 220 if (!port) {
221 printk(badinfo, name, routine); 221 printk(badinfo, name, routine);
222 return 1; 222 return 1;
@@ -231,9 +231,9 @@ static inline int sx_paranoia_check(struct specialix_port const * port,
231 231
232 232
233/* 233/*
234 * 234 *
235 * Service functions for specialix IO8+ driver. 235 * Service functions for specialix IO8+ driver.
236 * 236 *
237 */ 237 */
238 238
239/* Get board number from pointer */ 239/* Get board number from pointer */
@@ -246,7 +246,7 @@ static inline int board_No (struct specialix_board * bp)
246/* Get port number from pointer */ 246/* Get port number from pointer */
247static inline int port_No (struct specialix_port const * port) 247static inline int port_No (struct specialix_port const * port)
248{ 248{
249 return SX_PORT(port - sx_port); 249 return SX_PORT(port - sx_port);
250} 250}
251 251
252 252
@@ -309,7 +309,7 @@ static inline void sx_wait_CCR(struct specialix_board * bp)
309 return; 309 return;
310 udelay (1); 310 udelay (1);
311 } 311 }
312 312
313 printk(KERN_ERR "sx%d: Timeout waiting for CCR.\n", board_No(bp)); 313 printk(KERN_ERR "sx%d: Timeout waiting for CCR.\n", board_No(bp));
314} 314}
315 315
@@ -329,7 +329,7 @@ static inline void sx_wait_CCR_off(struct specialix_board * bp)
329 return; 329 return;
330 udelay (1); 330 udelay (1);
331 } 331 }
332 332
333 printk(KERN_ERR "sx%d: Timeout waiting for CCR.\n", board_No(bp)); 333 printk(KERN_ERR "sx%d: Timeout waiting for CCR.\n", board_No(bp));
334} 334}
335 335
@@ -338,34 +338,28 @@ static inline void sx_wait_CCR_off(struct specialix_board * bp)
338 * specialix IO8+ IO range functions. 338 * specialix IO8+ IO range functions.
339 */ 339 */
340 340
341static inline int sx_check_io_range(struct specialix_board * bp) 341static inline int sx_request_io_range(struct specialix_board * bp)
342{ 342{
343 return check_region (bp->base, SX_IO_SPACE); 343 return request_region(bp->base,
344} 344 bp->flags & SX_BOARD_IS_PCI ? SX_PCI_IO_SPACE : SX_IO_SPACE,
345 345 "specialix IO8+") == NULL;
346
347static inline void sx_request_io_range(struct specialix_board * bp)
348{
349 request_region(bp->base,
350 bp->flags&SX_BOARD_IS_PCI?SX_PCI_IO_SPACE:SX_IO_SPACE,
351 "specialix IO8+" );
352} 346}
353 347
354 348
355static inline void sx_release_io_range(struct specialix_board * bp) 349static inline void sx_release_io_range(struct specialix_board * bp)
356{ 350{
357 release_region(bp->base, 351 release_region(bp->base,
358 bp->flags&SX_BOARD_IS_PCI?SX_PCI_IO_SPACE:SX_IO_SPACE); 352 bp->flags&SX_BOARD_IS_PCI?SX_PCI_IO_SPACE:SX_IO_SPACE);
359} 353}
360 354
361 355
362/* Must be called with enabled interrupts */ 356/* Must be called with enabled interrupts */
363/* Ugly. Very ugly. Don't use this for anything else than initialization 357/* Ugly. Very ugly. Don't use this for anything else than initialization
364 code */ 358 code */
365static inline void sx_long_delay(unsigned long delay) 359static inline void sx_long_delay(unsigned long delay)
366{ 360{
367 unsigned long i; 361 unsigned long i;
368 362
369 for (i = jiffies + delay; time_after(i, jiffies); ) ; 363 for (i = jiffies + delay; time_after(i, jiffies); ) ;
370} 364}
371 365
@@ -378,7 +372,7 @@ static int sx_set_irq ( struct specialix_board *bp)
378 int i; 372 int i;
379 unsigned long flags; 373 unsigned long flags;
380 374
381 if (bp->flags & SX_BOARD_IS_PCI) 375 if (bp->flags & SX_BOARD_IS_PCI)
382 return 1; 376 return 1;
383 switch (bp->irq) { 377 switch (bp->irq) {
384 /* In the same order as in the docs... */ 378 /* In the same order as in the docs... */
@@ -420,7 +414,7 @@ static int sx_init_CD186x(struct specialix_board * bp)
420 sx_out_off(bp, CD186x_PILR3, SX_ACK_RINT); /* Prio for receiver intr */ 414 sx_out_off(bp, CD186x_PILR3, SX_ACK_RINT); /* Prio for receiver intr */
421 /* Set RegAckEn */ 415 /* Set RegAckEn */
422 sx_out_off(bp, CD186x_SRCR, sx_in (bp, CD186x_SRCR) | SRCR_REGACKEN); 416 sx_out_off(bp, CD186x_SRCR, sx_in (bp, CD186x_SRCR) | SRCR_REGACKEN);
423 417
424 /* Setting up prescaler. We need 4 ticks per 1 ms */ 418 /* Setting up prescaler. We need 4 ticks per 1 ms */
425 scaler = SX_OSCFREQ/SPECIALIX_TPS; 419 scaler = SX_OSCFREQ/SPECIALIX_TPS;
426 420
@@ -448,7 +442,7 @@ static int read_cross_byte (struct specialix_board *bp, int reg, int bit)
448 spin_lock_irqsave(&bp->lock, flags); 442 spin_lock_irqsave(&bp->lock, flags);
449 for (i=0, t=0;i<8;i++) { 443 for (i=0, t=0;i<8;i++) {
450 sx_out_off (bp, CD186x_CAR, i); 444 sx_out_off (bp, CD186x_CAR, i);
451 if (sx_in_off (bp, reg) & bit) 445 if (sx_in_off (bp, reg) & bit)
452 t |= 1 << i; 446 t |= 1 << i;
453 } 447 }
454 spin_unlock_irqrestore(&bp->lock, flags); 448 spin_unlock_irqrestore(&bp->lock, flags);
@@ -472,7 +466,7 @@ void missed_irq (unsigned long data)
472 spin_unlock_irqrestore(&bp->lock, flags); 466 spin_unlock_irqrestore(&bp->lock, flags);
473 if (irq) { 467 if (irq) {
474 printk (KERN_INFO "Missed interrupt... Calling int from timer. \n"); 468 printk (KERN_INFO "Missed interrupt... Calling int from timer. \n");
475 sx_interrupt (((struct specialix_board *)data)->irq, 469 sx_interrupt (((struct specialix_board *)data)->irq,
476 (void*)data, NULL); 470 (void*)data, NULL);
477 } 471 }
478 missed_irq_timer.expires = jiffies + sx_poll; 472 missed_irq_timer.expires = jiffies + sx_poll;
@@ -495,7 +489,7 @@ static int sx_probe(struct specialix_board *bp)
495 489
496 func_enter(); 490 func_enter();
497 491
498 if (sx_check_io_range(bp)) { 492 if (sx_request_io_range(bp)) {
499 func_exit(); 493 func_exit();
500 return 1; 494 return 1;
501 } 495 }
@@ -509,15 +503,16 @@ static int sx_probe(struct specialix_board *bp)
509 short_pause (); 503 short_pause ();
510 val2 = sx_in_off(bp, CD186x_PPRL); 504 val2 = sx_in_off(bp, CD186x_PPRL);
511 505
512 506
513 if ((val1 != 0x5a) || (val2 != 0xa5)) { 507 if ((val1 != 0x5a) || (val2 != 0xa5)) {
514 printk(KERN_INFO "sx%d: specialix IO8+ Board at 0x%03x not found.\n", 508 printk(KERN_INFO "sx%d: specialix IO8+ Board at 0x%03x not found.\n",
515 board_No(bp), bp->base); 509 board_No(bp), bp->base);
510 sx_release_io_range(bp);
516 func_exit(); 511 func_exit();
517 return 1; 512 return 1;
518 } 513 }
519 514
520 /* Check the DSR lines that Specialix uses as board 515 /* Check the DSR lines that Specialix uses as board
521 identification */ 516 identification */
522 val1 = read_cross_byte (bp, CD186x_MSVR, MSVR_DSR); 517 val1 = read_cross_byte (bp, CD186x_MSVR, MSVR_DSR);
523 val2 = read_cross_byte (bp, CD186x_MSVR, MSVR_RTS); 518 val2 = read_cross_byte (bp, CD186x_MSVR, MSVR_RTS);
@@ -532,6 +527,7 @@ static int sx_probe(struct specialix_board *bp)
532 if (val1 != val2) { 527 if (val1 != val2) {
533 printk(KERN_INFO "sx%d: specialix IO8+ ID %02x at 0x%03x not found (%02x).\n", 528 printk(KERN_INFO "sx%d: specialix IO8+ ID %02x at 0x%03x not found (%02x).\n",
534 board_No(bp), val2, bp->base, val1); 529 board_No(bp), val2, bp->base, val1);
530 sx_release_io_range(bp);
535 func_exit(); 531 func_exit();
536 return 1; 532 return 1;
537 } 533 }
@@ -546,7 +542,7 @@ static int sx_probe(struct specialix_board *bp)
546 sx_wait_CCR(bp); 542 sx_wait_CCR(bp);
547 sx_out(bp, CD186x_CCR, CCR_TXEN); /* Enable transmitter */ 543 sx_out(bp, CD186x_CCR, CCR_TXEN); /* Enable transmitter */
548 sx_out(bp, CD186x_IER, IER_TXRDY); /* Enable tx empty intr */ 544 sx_out(bp, CD186x_IER, IER_TXRDY); /* Enable tx empty intr */
549 sx_long_delay(HZ/20); 545 sx_long_delay(HZ/20);
550 irqs = probe_irq_off(irqs); 546 irqs = probe_irq_off(irqs);
551 547
552 dprintk (SX_DEBUG_INIT, "SRSR = %02x, ", sx_in(bp, CD186x_SRSR)); 548 dprintk (SX_DEBUG_INIT, "SRSR = %02x, ", sx_in(bp, CD186x_SRSR));
@@ -561,14 +557,15 @@ static int sx_probe(struct specialix_board *bp)
561 } 557 }
562 558
563 dprintk (SX_DEBUG_INIT "val1 = %02x, val2 = %02x, val3 = %02x.\n", 559 dprintk (SX_DEBUG_INIT "val1 = %02x, val2 = %02x, val3 = %02x.\n",
564 val1, val2, val3); 560 val1, val2, val3);
565 561
566 } 562 }
567 563
568#if 0 564#if 0
569 if (irqs <= 0) { 565 if (irqs <= 0) {
570 printk(KERN_ERR "sx%d: Can't find IRQ for specialix IO8+ board at 0x%03x.\n", 566 printk(KERN_ERR "sx%d: Can't find IRQ for specialix IO8+ board at 0x%03x.\n",
571 board_No(bp), bp->base); 567 board_No(bp), bp->base);
568 sx_release_io_range(bp);
572 func_exit(); 569 func_exit();
573 return 1; 570 return 1;
574 } 571 }
@@ -579,19 +576,20 @@ static int sx_probe(struct specialix_board *bp)
579#endif 576#endif
580 /* Reset CD186x again */ 577 /* Reset CD186x again */
581 if (!sx_init_CD186x(bp)) { 578 if (!sx_init_CD186x(bp)) {
579 sx_release_io_range(bp);
582 func_exit(); 580 func_exit();
583 return -EIO; 581 return 1;
584 } 582 }
585 583
586 sx_request_io_range(bp); 584 sx_request_io_range(bp);
587 bp->flags |= SX_BOARD_PRESENT; 585 bp->flags |= SX_BOARD_PRESENT;
588 586
589 /* Chip revcode pkgtype 587 /* Chip revcode pkgtype
590 GFRCR SRCR bit 7 588 GFRCR SRCR bit 7
591 CD180 rev B 0x81 0 589 CD180 rev B 0x81 0
592 CD180 rev C 0x82 0 590 CD180 rev C 0x82 0
593 CD1864 rev A 0x82 1 591 CD1864 rev A 0x82 1
594 CD1865 rev A 0x83 1 -- Do not use!!! Does not work. 592 CD1865 rev A 0x83 1 -- Do not use!!! Does not work.
595 CD1865 rev B 0x84 1 593 CD1865 rev B 0x84 1
596 -- Thanks to Gwen Wang, Cirrus Logic. 594 -- Thanks to Gwen Wang, Cirrus Logic.
597 */ 595 */
@@ -623,8 +621,8 @@ static int sx_probe(struct specialix_board *bp)
623 return 0; 621 return 0;
624} 622}
625 623
626/* 624/*
627 * 625 *
628 * Interrupt processing routines. 626 * Interrupt processing routines.
629 * */ 627 * */
630 628
@@ -657,7 +655,7 @@ static inline struct specialix_port * sx_get_port(struct specialix_board * bp,
657 return port; 655 return port;
658 } 656 }
659 } 657 }
660 printk(KERN_INFO "sx%d: %s interrupt from invalid port %d\n", 658 printk(KERN_INFO "sx%d: %s interrupt from invalid port %d\n",
661 board_No(bp), what, channel); 659 board_No(bp), what, channel);
662 return NULL; 660 return NULL;
663} 661}
@@ -681,7 +679,7 @@ static inline void sx_receive_exc(struct specialix_board * bp)
681 tty = port->tty; 679 tty = port->tty;
682 dprintk (SX_DEBUG_RX, "port: %p count: %d BUFF_SIZE: %d\n", 680 dprintk (SX_DEBUG_RX, "port: %p count: %d BUFF_SIZE: %d\n",
683 port, tty->flip.count, TTY_FLIPBUF_SIZE); 681 port, tty->flip.count, TTY_FLIPBUF_SIZE);
684 682
685 status = sx_in(bp, CD186x_RCSR); 683 status = sx_in(bp, CD186x_RCSR);
686 684
687 dprintk (SX_DEBUG_RX, "status: 0x%x\n", status); 685 dprintk (SX_DEBUG_RX, "status: 0x%x\n", status);
@@ -707,30 +705,30 @@ static inline void sx_receive_exc(struct specialix_board * bp)
707 return; 705 return;
708 } 706 }
709 if (status & RCSR_TOUT) { 707 if (status & RCSR_TOUT) {
710 printk(KERN_INFO "sx%d: port %d: Receiver timeout. Hardware problems ?\n", 708 printk(KERN_INFO "sx%d: port %d: Receiver timeout. Hardware problems ?\n",
711 board_No(bp), port_No(port)); 709 board_No(bp), port_No(port));
712 func_exit(); 710 func_exit();
713 return; 711 return;
714 712
715 } else if (status & RCSR_BREAK) { 713 } else if (status & RCSR_BREAK) {
716 dprintk(SX_DEBUG_RX, "sx%d: port %d: Handling break...\n", 714 dprintk(SX_DEBUG_RX, "sx%d: port %d: Handling break...\n",
717 board_No(bp), port_No(port)); 715 board_No(bp), port_No(port));
718 *tty->flip.flag_buf_ptr++ = TTY_BREAK; 716 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
719 if (port->flags & ASYNC_SAK) 717 if (port->flags & ASYNC_SAK)
720 do_SAK(tty); 718 do_SAK(tty);
721 719
722 } else if (status & RCSR_PE) 720 } else if (status & RCSR_PE)
723 *tty->flip.flag_buf_ptr++ = TTY_PARITY; 721 *tty->flip.flag_buf_ptr++ = TTY_PARITY;
724 722
725 else if (status & RCSR_FE) 723 else if (status & RCSR_FE)
726 *tty->flip.flag_buf_ptr++ = TTY_FRAME; 724 *tty->flip.flag_buf_ptr++ = TTY_FRAME;
727 725
728 else if (status & RCSR_OE) 726 else if (status & RCSR_OE)
729 *tty->flip.flag_buf_ptr++ = TTY_OVERRUN; 727 *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
730 728
731 else 729 else
732 *tty->flip.flag_buf_ptr++ = 0; 730 *tty->flip.flag_buf_ptr++ = 0;
733 731
734 *tty->flip.char_buf_ptr++ = ch; 732 *tty->flip.char_buf_ptr++ = ch;
735 tty->flip.count++; 733 tty->flip.count++;
736 schedule_delayed_work(&tty->flip.work, 1); 734 schedule_delayed_work(&tty->flip.work, 1);
@@ -746,18 +744,18 @@ static inline void sx_receive(struct specialix_board * bp)
746 unsigned char count; 744 unsigned char count;
747 745
748 func_enter(); 746 func_enter();
749 747
750 if (!(port = sx_get_port(bp, "Receive"))) { 748 if (!(port = sx_get_port(bp, "Receive"))) {
751 dprintk (SX_DEBUG_RX, "Hmm, couldn't find port.\n"); 749 dprintk (SX_DEBUG_RX, "Hmm, couldn't find port.\n");
752 func_exit(); 750 func_exit();
753 return; 751 return;
754 } 752 }
755 tty = port->tty; 753 tty = port->tty;
756 754
757 count = sx_in(bp, CD186x_RDCR); 755 count = sx_in(bp, CD186x_RDCR);
758 dprintk (SX_DEBUG_RX, "port: %p: count: %d\n", port, count); 756 dprintk (SX_DEBUG_RX, "port: %p: count: %d\n", port, count);
759 port->hits[count > 8 ? 9 : count]++; 757 port->hits[count > 8 ? 9 : count]++;
760 758
761 while (count--) { 759 while (count--) {
762 if (tty->flip.count >= TTY_FLIPBUF_SIZE) { 760 if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
763 printk(KERN_INFO "sx%d: port %d: Working around flip buffer overflow.\n", 761 printk(KERN_INFO "sx%d: port %d: Working around flip buffer overflow.\n",
@@ -787,7 +785,7 @@ static inline void sx_transmit(struct specialix_board * bp)
787 } 785 }
788 dprintk (SX_DEBUG_TX, "port: %p\n", port); 786 dprintk (SX_DEBUG_TX, "port: %p\n", port);
789 tty = port->tty; 787 tty = port->tty;
790 788
791 if (port->IER & IER_TXEMPTY) { 789 if (port->IER & IER_TXEMPTY) {
792 /* FIFO drained */ 790 /* FIFO drained */
793 sx_out(bp, CD186x_CAR, port_No(port)); 791 sx_out(bp, CD186x_CAR, port_No(port));
@@ -796,7 +794,7 @@ static inline void sx_transmit(struct specialix_board * bp)
796 func_exit(); 794 func_exit();
797 return; 795 return;
798 } 796 }
799 797
800 if ((port->xmit_cnt <= 0 && !port->break_length) 798 if ((port->xmit_cnt <= 0 && !port->break_length)
801 || tty->stopped || tty->hw_stopped) { 799 || tty->stopped || tty->hw_stopped) {
802 sx_out(bp, CD186x_CAR, port_No(port)); 800 sx_out(bp, CD186x_CAR, port_No(port));
@@ -805,7 +803,7 @@ static inline void sx_transmit(struct specialix_board * bp)
805 func_exit(); 803 func_exit();
806 return; 804 return;
807 } 805 }
808 806
809 if (port->break_length) { 807 if (port->break_length) {
810 if (port->break_length > 0) { 808 if (port->break_length > 0) {
811 if (port->COR2 & COR2_ETC) { 809 if (port->COR2 & COR2_ETC) {
@@ -831,7 +829,7 @@ static inline void sx_transmit(struct specialix_board * bp)
831 func_exit(); 829 func_exit();
832 return; 830 return;
833 } 831 }
834 832
835 count = CD186x_NFIFO; 833 count = CD186x_NFIFO;
836 do { 834 do {
837 sx_out(bp, CD186x_TDR, port->xmit_buf[port->xmit_tail++]); 835 sx_out(bp, CD186x_TDR, port->xmit_buf[port->xmit_tail++]);
@@ -839,7 +837,7 @@ static inline void sx_transmit(struct specialix_board * bp)
839 if (--port->xmit_cnt <= 0) 837 if (--port->xmit_cnt <= 0)
840 break; 838 break;
841 } while (--count > 0); 839 } while (--count > 0);
842 840
843 if (port->xmit_cnt <= 0) { 841 if (port->xmit_cnt <= 0) {
844 sx_out(bp, CD186x_CAR, port_No(port)); 842 sx_out(bp, CD186x_CAR, port_No(port));
845 port->IER &= ~IER_TXRDY; 843 port->IER &= ~IER_TXRDY;
@@ -862,9 +860,9 @@ static inline void sx_check_modem(struct specialix_board * bp)
862 dprintk (SX_DEBUG_SIGNALS, "Modem intr. "); 860 dprintk (SX_DEBUG_SIGNALS, "Modem intr. ");
863 if (!(port = sx_get_port(bp, "Modem"))) 861 if (!(port = sx_get_port(bp, "Modem")))
864 return; 862 return;
865 863
866 tty = port->tty; 864 tty = port->tty;
867 865
868 mcr = sx_in(bp, CD186x_MCR); 866 mcr = sx_in(bp, CD186x_MCR);
869 printk ("mcr = %02x.\n", mcr); 867 printk ("mcr = %02x.\n", mcr);
870 868
@@ -879,7 +877,7 @@ static inline void sx_check_modem(struct specialix_board * bp)
879 schedule_work(&port->tqueue_hangup); 877 schedule_work(&port->tqueue_hangup);
880 } 878 }
881 } 879 }
882 880
883#ifdef SPECIALIX_BRAIN_DAMAGED_CTS 881#ifdef SPECIALIX_BRAIN_DAMAGED_CTS
884 if (mcr & MCR_CTSCHG) { 882 if (mcr & MCR_CTSCHG) {
885 if (sx_in(bp, CD186x_MSVR) & MSVR_CTS) { 883 if (sx_in(bp, CD186x_MSVR) & MSVR_CTS) {
@@ -906,7 +904,7 @@ static inline void sx_check_modem(struct specialix_board * bp)
906 sx_out(bp, CD186x_IER, port->IER); 904 sx_out(bp, CD186x_IER, port->IER);
907 } 905 }
908#endif /* SPECIALIX_BRAIN_DAMAGED_CTS */ 906#endif /* SPECIALIX_BRAIN_DAMAGED_CTS */
909 907
910 /* Clear change bits */ 908 /* Clear change bits */
911 sx_out(bp, CD186x_MCR, 0); 909 sx_out(bp, CD186x_MCR, 0);
912} 910}
@@ -940,7 +938,7 @@ static irqreturn_t sx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
940 while ((++loop < 16) && (status = (sx_in(bp, CD186x_SRSR) & 938 while ((++loop < 16) && (status = (sx_in(bp, CD186x_SRSR) &
941 (SRSR_RREQint | 939 (SRSR_RREQint |
942 SRSR_TREQint | 940 SRSR_TREQint |
943 SRSR_MREQint)))) { 941 SRSR_MREQint)))) {
944 if (status & SRSR_RREQint) { 942 if (status & SRSR_RREQint) {
945 ack = sx_in(bp, CD186x_RRAR); 943 ack = sx_in(bp, CD186x_RRAR);
946 944
@@ -951,7 +949,7 @@ static irqreturn_t sx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
951 else 949 else
952 printk(KERN_ERR "sx%d: status: 0x%x Bad receive ack 0x%02x.\n", 950 printk(KERN_ERR "sx%d: status: 0x%x Bad receive ack 0x%02x.\n",
953 board_No(bp), status, ack); 951 board_No(bp), status, ack);
954 952
955 } else if (status & SRSR_TREQint) { 953 } else if (status & SRSR_TREQint) {
956 ack = sx_in(bp, CD186x_TRAR); 954 ack = sx_in(bp, CD186x_TRAR);
957 955
@@ -963,13 +961,13 @@ static irqreturn_t sx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
963 } else if (status & SRSR_MREQint) { 961 } else if (status & SRSR_MREQint) {
964 ack = sx_in(bp, CD186x_MRAR); 962 ack = sx_in(bp, CD186x_MRAR);
965 963
966 if (ack == (SX_ID | GIVR_IT_MODEM)) 964 if (ack == (SX_ID | GIVR_IT_MODEM))
967 sx_check_modem(bp); 965 sx_check_modem(bp);
968 else 966 else
969 printk(KERN_ERR "sx%d: status: 0x%x Bad modem ack 0x%02x.\n", 967 printk(KERN_ERR "sx%d: status: 0x%x Bad modem ack 0x%02x.\n",
970 board_No(bp), status, ack); 968 board_No(bp), status, ack);
971 969
972 } 970 }
973 971
974 sx_out(bp, CD186x_EOIR, 0); /* Mark end of interrupt */ 972 sx_out(bp, CD186x_EOIR, 0); /* Mark end of interrupt */
975 } 973 }
@@ -1026,7 +1024,7 @@ static inline int sx_setup_board(struct specialix_board * bp)
1026{ 1024{
1027 int error; 1025 int error;
1028 1026
1029 if (bp->flags & SX_BOARD_ACTIVE) 1027 if (bp->flags & SX_BOARD_ACTIVE)
1030 return 0; 1028 return 0;
1031 1029
1032 if (bp->flags & SX_BOARD_IS_PCI) 1030 if (bp->flags & SX_BOARD_IS_PCI)
@@ -1034,7 +1032,7 @@ static inline int sx_setup_board(struct specialix_board * bp)
1034 else 1032 else
1035 error = request_irq(bp->irq, sx_interrupt, SA_INTERRUPT, "specialix IO8+", bp); 1033 error = request_irq(bp->irq, sx_interrupt, SA_INTERRUPT, "specialix IO8+", bp);
1036 1034
1037 if (error) 1035 if (error)
1038 return error; 1036 return error;
1039 1037
1040 turn_ints_on (bp); 1038 turn_ints_on (bp);
@@ -1055,7 +1053,7 @@ static inline void sx_shutdown_board(struct specialix_board *bp)
1055 } 1053 }
1056 1054
1057 bp->flags &= ~SX_BOARD_ACTIVE; 1055 bp->flags &= ~SX_BOARD_ACTIVE;
1058 1056
1059 dprintk (SX_DEBUG_IRQ, "Freeing IRQ%d for board %d.\n", 1057 dprintk (SX_DEBUG_IRQ, "Freeing IRQ%d for board %d.\n",
1060 bp->irq, board_No (bp)); 1058 bp->irq, board_No (bp));
1061 free_irq(bp->irq, bp); 1059 free_irq(bp->irq, bp);
@@ -1068,7 +1066,7 @@ static inline void sx_shutdown_board(struct specialix_board *bp)
1068 1066
1069 1067
1070/* 1068/*
1071 * Setting up port characteristics. 1069 * Setting up port characteristics.
1072 * Must be called with disabled interrupts 1070 * Must be called with disabled interrupts
1073 */ 1071 */
1074static void sx_change_speed(struct specialix_board *bp, struct specialix_port *port) 1072static void sx_change_speed(struct specialix_board *bp, struct specialix_port *port)
@@ -1103,10 +1101,10 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1103 spin_unlock_irqrestore(&bp->lock, flags); 1101 spin_unlock_irqrestore(&bp->lock, flags);
1104 dprintk (SX_DEBUG_TERMIOS, "sx: got MSVR=%02x.\n", port->MSVR); 1102 dprintk (SX_DEBUG_TERMIOS, "sx: got MSVR=%02x.\n", port->MSVR);
1105 baud = C_BAUD(tty); 1103 baud = C_BAUD(tty);
1106 1104
1107 if (baud & CBAUDEX) { 1105 if (baud & CBAUDEX) {
1108 baud &= ~CBAUDEX; 1106 baud &= ~CBAUDEX;
1109 if (baud < 1 || baud > 2) 1107 if (baud < 1 || baud > 2)
1110 port->tty->termios->c_cflag &= ~CBAUDEX; 1108 port->tty->termios->c_cflag &= ~CBAUDEX;
1111 else 1109 else
1112 baud += 15; 1110 baud += 15;
@@ -1117,8 +1115,8 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1117 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) 1115 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
1118 baud += 2; 1116 baud += 2;
1119 } 1117 }
1120 1118
1121 1119
1122 if (!baud_table[baud]) { 1120 if (!baud_table[baud]) {
1123 /* Drop DTR & exit */ 1121 /* Drop DTR & exit */
1124 dprintk (SX_DEBUG_TERMIOS, "Dropping DTR... Hmm....\n"); 1122 dprintk (SX_DEBUG_TERMIOS, "Dropping DTR... Hmm....\n");
@@ -1127,7 +1125,7 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1127 spin_lock_irqsave(&bp->lock, flags); 1125 spin_lock_irqsave(&bp->lock, flags);
1128 sx_out(bp, CD186x_MSVR, port->MSVR ); 1126 sx_out(bp, CD186x_MSVR, port->MSVR );
1129 spin_unlock_irqrestore(&bp->lock, flags); 1127 spin_unlock_irqrestore(&bp->lock, flags);
1130 } 1128 }
1131 else 1129 else
1132 dprintk (SX_DEBUG_TERMIOS, "Can't drop DTR: no DTR.\n"); 1130 dprintk (SX_DEBUG_TERMIOS, "Can't drop DTR: no DTR.\n");
1133 return; 1131 return;
@@ -1137,9 +1135,9 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1137 port ->MSVR |= MSVR_DTR; 1135 port ->MSVR |= MSVR_DTR;
1138 } 1136 }
1139 } 1137 }
1140 1138
1141 /* 1139 /*
1142 * Now we must calculate some speed depended things 1140 * Now we must calculate some speed depended things
1143 */ 1141 */
1144 1142
1145 /* Set baud rate for port */ 1143 /* Set baud rate for port */
@@ -1152,7 +1150,7 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1152 tmp = (((SX_OSCFREQ + baud_table[baud]/2) / baud_table[baud] + 1150 tmp = (((SX_OSCFREQ + baud_table[baud]/2) / baud_table[baud] +
1153 CD186x_TPC/2) / CD186x_TPC); 1151 CD186x_TPC/2) / CD186x_TPC);
1154 1152
1155 if ((tmp < 0x10) && time_before(again, jiffies)) { 1153 if ((tmp < 0x10) && time_before(again, jiffies)) {
1156 again = jiffies + HZ * 60; 1154 again = jiffies + HZ * 60;
1157 /* Page 48 of version 2.0 of the CL-CD1865 databook */ 1155 /* Page 48 of version 2.0 of the CL-CD1865 databook */
1158 if (tmp >= 12) { 1156 if (tmp >= 12) {
@@ -1164,27 +1162,27 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1164 printk (KERN_INFO "sx%d: Baud rate divisor is %ld. \n" 1162 printk (KERN_INFO "sx%d: Baud rate divisor is %ld. \n"
1165 "Warning: overstressing Cirrus chip. " 1163 "Warning: overstressing Cirrus chip. "
1166 "This might not work.\n" 1164 "This might not work.\n"
1167 "Read specialix.txt for more info.\n", 1165 "Read specialix.txt for more info.\n",
1168 port_No (port), tmp); 1166 port_No (port), tmp);
1169 } 1167 }
1170 } 1168 }
1171 spin_lock_irqsave(&bp->lock, flags); 1169 spin_lock_irqsave(&bp->lock, flags);
1172 sx_out(bp, CD186x_RBPRH, (tmp >> 8) & 0xff); 1170 sx_out(bp, CD186x_RBPRH, (tmp >> 8) & 0xff);
1173 sx_out(bp, CD186x_TBPRH, (tmp >> 8) & 0xff); 1171 sx_out(bp, CD186x_TBPRH, (tmp >> 8) & 0xff);
1174 sx_out(bp, CD186x_RBPRL, tmp & 0xff); 1172 sx_out(bp, CD186x_RBPRL, tmp & 0xff);
1175 sx_out(bp, CD186x_TBPRL, tmp & 0xff); 1173 sx_out(bp, CD186x_TBPRL, tmp & 0xff);
1176 spin_unlock_irqrestore(&bp->lock, flags); 1174 spin_unlock_irqrestore(&bp->lock, flags);
1177 if (port->custom_divisor) { 1175 if (port->custom_divisor) {
1178 baud = (SX_OSCFREQ + port->custom_divisor/2) / port->custom_divisor; 1176 baud = (SX_OSCFREQ + port->custom_divisor/2) / port->custom_divisor;
1179 baud = ( baud + 5 ) / 10; 1177 baud = ( baud + 5 ) / 10;
1180 } else 1178 } else
1181 baud = (baud_table[baud] + 5) / 10; /* Estimated CPS */ 1179 baud = (baud_table[baud] + 5) / 10; /* Estimated CPS */
1182 1180
1183 /* Two timer ticks seems enough to wakeup something like SLIP driver */ 1181 /* Two timer ticks seems enough to wakeup something like SLIP driver */
1184 tmp = ((baud + HZ/2) / HZ) * 2 - CD186x_NFIFO; 1182 tmp = ((baud + HZ/2) / HZ) * 2 - CD186x_NFIFO;
1185 port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ? 1183 port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ?
1186 SERIAL_XMIT_SIZE - 1 : tmp); 1184 SERIAL_XMIT_SIZE - 1 : tmp);
1187 1185
1188 /* Receiver timeout will be transmission time for 1.5 chars */ 1186 /* Receiver timeout will be transmission time for 1.5 chars */
1189 tmp = (SPECIALIX_TPS + SPECIALIX_TPS/2 + baud/2) / baud; 1187 tmp = (SPECIALIX_TPS + SPECIALIX_TPS/2 + baud/2) / baud;
1190 tmp = (tmp > 0xff) ? 0xff : tmp; 1188 tmp = (tmp > 0xff) ? 0xff : tmp;
@@ -1205,29 +1203,29 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1205 cor1 |= COR1_8BITS; 1203 cor1 |= COR1_8BITS;
1206 break; 1204 break;
1207 } 1205 }
1208 1206
1209 if (C_CSTOPB(tty)) 1207 if (C_CSTOPB(tty))
1210 cor1 |= COR1_2SB; 1208 cor1 |= COR1_2SB;
1211 1209
1212 cor1 |= COR1_IGNORE; 1210 cor1 |= COR1_IGNORE;
1213 if (C_PARENB(tty)) { 1211 if (C_PARENB(tty)) {
1214 cor1 |= COR1_NORMPAR; 1212 cor1 |= COR1_NORMPAR;
1215 if (C_PARODD(tty)) 1213 if (C_PARODD(tty))
1216 cor1 |= COR1_ODDP; 1214 cor1 |= COR1_ODDP;
1217 if (I_INPCK(tty)) 1215 if (I_INPCK(tty))
1218 cor1 &= ~COR1_IGNORE; 1216 cor1 &= ~COR1_IGNORE;
1219 } 1217 }
1220 /* Set marking of some errors */ 1218 /* Set marking of some errors */
1221 port->mark_mask = RCSR_OE | RCSR_TOUT; 1219 port->mark_mask = RCSR_OE | RCSR_TOUT;
1222 if (I_INPCK(tty)) 1220 if (I_INPCK(tty))
1223 port->mark_mask |= RCSR_FE | RCSR_PE; 1221 port->mark_mask |= RCSR_FE | RCSR_PE;
1224 if (I_BRKINT(tty) || I_PARMRK(tty)) 1222 if (I_BRKINT(tty) || I_PARMRK(tty))
1225 port->mark_mask |= RCSR_BREAK; 1223 port->mark_mask |= RCSR_BREAK;
1226 if (I_IGNPAR(tty)) 1224 if (I_IGNPAR(tty))
1227 port->mark_mask &= ~(RCSR_FE | RCSR_PE); 1225 port->mark_mask &= ~(RCSR_FE | RCSR_PE);
1228 if (I_IGNBRK(tty)) { 1226 if (I_IGNBRK(tty)) {
1229 port->mark_mask &= ~RCSR_BREAK; 1227 port->mark_mask &= ~RCSR_BREAK;
1230 if (I_IGNPAR(tty)) 1228 if (I_IGNPAR(tty))
1231 /* Real raw mode. Ignore all */ 1229 /* Real raw mode. Ignore all */
1232 port->mark_mask &= ~RCSR_OE; 1230 port->mark_mask &= ~RCSR_OE;
1233 } 1231 }
@@ -1241,7 +1239,7 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1241 tty->hw_stopped = !(sx_in(bp, CD186x_MSVR) & (MSVR_CTS|MSVR_DSR)); 1239 tty->hw_stopped = !(sx_in(bp, CD186x_MSVR) & (MSVR_CTS|MSVR_DSR));
1242 spin_unlock_irqrestore(&bp->lock, flags); 1240 spin_unlock_irqrestore(&bp->lock, flags);
1243#else 1241#else
1244 port->COR2 |= COR2_CTSAE; 1242 port->COR2 |= COR2_CTSAE;
1245#endif 1243#endif
1246 } 1244 }
1247 /* Enable Software Flow Control. FIXME: I'm not sure about this */ 1245 /* Enable Software Flow Control. FIXME: I'm not sure about this */
@@ -1264,11 +1262,11 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p
1264 mcor1 |= MCOR1_CDZD; 1262 mcor1 |= MCOR1_CDZD;
1265 mcor2 |= MCOR2_CDOD; 1263 mcor2 |= MCOR2_CDOD;
1266 } 1264 }
1267 1265
1268 if (C_CREAD(tty)) 1266 if (C_CREAD(tty))
1269 /* Enable receiver */ 1267 /* Enable receiver */
1270 port->IER |= IER_RXD; 1268 port->IER |= IER_RXD;
1271 1269
1272 /* Set input FIFO size (1-8 bytes) */ 1270 /* Set input FIFO size (1-8 bytes) */
1273 cor3 |= sx_rxfifo; 1271 cor3 |= sx_rxfifo;
1274 /* Setting up CD186x channel registers */ 1272 /* Setting up CD186x channel registers */
@@ -1311,11 +1309,11 @@ static int sx_setup_port(struct specialix_board *bp, struct specialix_port *port
1311 func_exit(); 1309 func_exit();
1312 return 0; 1310 return 0;
1313 } 1311 }
1314 1312
1315 if (!port->xmit_buf) { 1313 if (!port->xmit_buf) {
1316 /* We may sleep in get_zeroed_page() */ 1314 /* We may sleep in get_zeroed_page() */
1317 unsigned long tmp; 1315 unsigned long tmp;
1318 1316
1319 if (!(tmp = get_zeroed_page(GFP_KERNEL))) { 1317 if (!(tmp = get_zeroed_page(GFP_KERNEL))) {
1320 func_exit(); 1318 func_exit();
1321 return -ENOMEM; 1319 return -ENOMEM;
@@ -1328,10 +1326,10 @@ static int sx_setup_port(struct specialix_board *bp, struct specialix_port *port
1328 } 1326 }
1329 port->xmit_buf = (unsigned char *) tmp; 1327 port->xmit_buf = (unsigned char *) tmp;
1330 } 1328 }
1331 1329
1332 spin_lock_irqsave(&port->lock, flags); 1330 spin_lock_irqsave(&port->lock, flags);
1333 1331
1334 if (port->tty) 1332 if (port->tty)
1335 clear_bit(TTY_IO_ERROR, &port->tty->flags); 1333 clear_bit(TTY_IO_ERROR, &port->tty->flags);
1336 1334
1337 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0; 1335 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
@@ -1340,7 +1338,7 @@ static int sx_setup_port(struct specialix_board *bp, struct specialix_port *port
1340 1338
1341 spin_unlock_irqrestore(&port->lock, flags); 1339 spin_unlock_irqrestore(&port->lock, flags);
1342 1340
1343 1341
1344 func_exit(); 1342 func_exit();
1345 return 0; 1343 return 0;
1346} 1344}
@@ -1352,14 +1350,14 @@ static void sx_shutdown_port(struct specialix_board *bp, struct specialix_port *
1352 struct tty_struct *tty; 1350 struct tty_struct *tty;
1353 int i; 1351 int i;
1354 unsigned long flags; 1352 unsigned long flags;
1355 1353
1356 func_enter(); 1354 func_enter();
1357 1355
1358 if (!(port->flags & ASYNC_INITIALIZED)) { 1356 if (!(port->flags & ASYNC_INITIALIZED)) {
1359 func_exit(); 1357 func_exit();
1360 return; 1358 return;
1361 } 1359 }
1362 1360
1363 if (sx_debug & SX_DEBUG_FIFO) { 1361 if (sx_debug & SX_DEBUG_FIFO) {
1364 dprintk(SX_DEBUG_FIFO, "sx%d: port %d: %ld overruns, FIFO hits [ ", 1362 dprintk(SX_DEBUG_FIFO, "sx%d: port %d: %ld overruns, FIFO hits [ ",
1365 board_No(bp), port_No(port), port->overrun); 1363 board_No(bp), port_No(port), port->overrun);
@@ -1394,13 +1392,13 @@ static void sx_shutdown_port(struct specialix_board *bp, struct specialix_port *
1394 if (tty) 1392 if (tty)
1395 set_bit(TTY_IO_ERROR, &tty->flags); 1393 set_bit(TTY_IO_ERROR, &tty->flags);
1396 port->flags &= ~ASYNC_INITIALIZED; 1394 port->flags &= ~ASYNC_INITIALIZED;
1397 1395
1398 if (!bp->count) 1396 if (!bp->count)
1399 sx_shutdown_board(bp); 1397 sx_shutdown_board(bp);
1400 func_exit(); 1398 func_exit();
1401} 1399}
1402 1400
1403 1401
1404static int block_til_ready(struct tty_struct *tty, struct file * filp, 1402static int block_til_ready(struct tty_struct *tty, struct file * filp,
1405 struct specialix_port *port) 1403 struct specialix_port *port)
1406{ 1404{
@@ -1427,7 +1425,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
1427 return -ERESTARTSYS; 1425 return -ERESTARTSYS;
1428 } 1426 }
1429 } 1427 }
1430 1428
1431 /* 1429 /*
1432 * If non-blocking mode is set, or the port is not enabled, 1430 * If non-blocking mode is set, or the port is not enabled,
1433 * then make the check up front and then exit. 1431 * then make the check up front and then exit.
@@ -1477,7 +1475,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
1477 if (port->flags & ASYNC_HUP_NOTIFY) 1475 if (port->flags & ASYNC_HUP_NOTIFY)
1478 retval = -EAGAIN; 1476 retval = -EAGAIN;
1479 else 1477 else
1480 retval = -ERESTARTSYS; 1478 retval = -ERESTARTSYS;
1481 break; 1479 break;
1482 } 1480 }
1483 if (!(port->flags & ASYNC_CLOSING) && 1481 if (!(port->flags & ASYNC_CLOSING) &&
@@ -1506,7 +1504,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
1506 port->flags |= ASYNC_NORMAL_ACTIVE; 1504 port->flags |= ASYNC_NORMAL_ACTIVE;
1507 func_exit(); 1505 func_exit();
1508 return 0; 1506 return 0;
1509} 1507}
1510 1508
1511 1509
1512static int sx_open(struct tty_struct * tty, struct file * filp) 1510static int sx_open(struct tty_struct * tty, struct file * filp)
@@ -1526,7 +1524,7 @@ static int sx_open(struct tty_struct * tty, struct file * filp)
1526 func_exit(); 1524 func_exit();
1527 return -ENODEV; 1525 return -ENODEV;
1528 } 1526 }
1529 1527
1530 bp = &sx_board[board]; 1528 bp = &sx_board[board];
1531 port = sx_port + board * SX_NPORT + SX_PORT(tty->index); 1529 port = sx_port + board * SX_NPORT + SX_PORT(tty->index);
1532 port->overrun = 0; 1530 port->overrun = 0;
@@ -1557,7 +1555,7 @@ static int sx_open(struct tty_struct * tty, struct file * filp)
1557 func_enter(); 1555 func_enter();
1558 return error; 1556 return error;
1559 } 1557 }
1560 1558
1561 if ((error = block_til_ready(tty, filp, port))) { 1559 if ((error = block_til_ready(tty, filp, port))) {
1562 func_enter(); 1560 func_enter();
1563 return error; 1561 return error;
@@ -1574,7 +1572,7 @@ static void sx_close(struct tty_struct * tty, struct file * filp)
1574 struct specialix_board *bp; 1572 struct specialix_board *bp;
1575 unsigned long flags; 1573 unsigned long flags;
1576 unsigned long timeout; 1574 unsigned long timeout;
1577 1575
1578 func_enter(); 1576 func_enter();
1579 if (!port || sx_paranoia_check(port, tty->name, "close")) { 1577 if (!port || sx_paranoia_check(port, tty->name, "close")) {
1580 func_exit(); 1578 func_exit();
@@ -1587,7 +1585,7 @@ static void sx_close(struct tty_struct * tty, struct file * filp)
1587 func_exit(); 1585 func_exit();
1588 return; 1586 return;
1589 } 1587 }
1590 1588
1591 bp = port_Board(port); 1589 bp = port_Board(port);
1592 if ((tty->count == 1) && (port->count != 1)) { 1590 if ((tty->count == 1) && (port->count != 1)) {
1593 printk(KERN_ERR "sx%d: sx_close: bad port count;" 1591 printk(KERN_ERR "sx%d: sx_close: bad port count;"
@@ -1607,7 +1605,7 @@ static void sx_close(struct tty_struct * tty, struct file * filp)
1607 } 1605 }
1608 port->flags |= ASYNC_CLOSING; 1606 port->flags |= ASYNC_CLOSING;
1609 /* 1607 /*
1610 * Now we wait for the transmit buffer to clear; and we notify 1608 * Now we wait for the transmit buffer to clear; and we notify
1611 * the line discipline to only process XON/XOFF characters. 1609 * the line discipline to only process XON/XOFF characters.
1612 */ 1610 */
1613 tty->closing = 1; 1611 tty->closing = 1;
@@ -1681,7 +1679,7 @@ static void sx_close(struct tty_struct * tty, struct file * filp)
1681} 1679}
1682 1680
1683 1681
1684static int sx_write(struct tty_struct * tty, 1682static int sx_write(struct tty_struct * tty,
1685 const unsigned char *buf, int count) 1683 const unsigned char *buf, int count)
1686{ 1684{
1687 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1685 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
@@ -1694,7 +1692,7 @@ static int sx_write(struct tty_struct * tty,
1694 func_exit(); 1692 func_exit();
1695 return 0; 1693 return 0;
1696 } 1694 }
1697 1695
1698 bp = port_Board(port); 1696 bp = port_Board(port);
1699 1697
1700 if (!tty || !port->xmit_buf || !tmp_buf) { 1698 if (!tty || !port->xmit_buf || !tmp_buf) {
@@ -1824,7 +1822,7 @@ static int sx_chars_in_buffer(struct tty_struct *tty)
1824 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1822 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1825 1823
1826 func_enter(); 1824 func_enter();
1827 1825
1828 if (sx_paranoia_check(port, tty->name, "sx_chars_in_buffer")) { 1826 if (sx_paranoia_check(port, tty->name, "sx_chars_in_buffer")) {
1829 func_exit(); 1827 func_exit();
1830 return 0; 1828 return 0;
@@ -1881,13 +1879,13 @@ static int sx_tiocmget(struct tty_struct *tty, struct file *file)
1881 port_No(port), status, sx_in (bp, CD186x_CAR)); 1879 port_No(port), status, sx_in (bp, CD186x_CAR));
1882 dprintk (SX_DEBUG_INIT, "sx_port = %p, port = %p\n", sx_port, port); 1880 dprintk (SX_DEBUG_INIT, "sx_port = %p, port = %p\n", sx_port, port);
1883 if (SX_CRTSCTS(port->tty)) { 1881 if (SX_CRTSCTS(port->tty)) {
1884 result = /* (status & MSVR_RTS) ? */ TIOCM_DTR /* : 0) */ 1882 result = /* (status & MSVR_RTS) ? */ TIOCM_DTR /* : 0) */
1885 | ((status & MSVR_DTR) ? TIOCM_RTS : 0) 1883 | ((status & MSVR_DTR) ? TIOCM_RTS : 0)
1886 | ((status & MSVR_CD) ? TIOCM_CAR : 0) 1884 | ((status & MSVR_CD) ? TIOCM_CAR : 0)
1887 |/* ((status & MSVR_DSR) ? */ TIOCM_DSR /* : 0) */ 1885 |/* ((status & MSVR_DSR) ? */ TIOCM_DSR /* : 0) */
1888 | ((status & MSVR_CTS) ? TIOCM_CTS : 0); 1886 | ((status & MSVR_CTS) ? TIOCM_CTS : 0);
1889 } else { 1887 } else {
1890 result = /* (status & MSVR_RTS) ? */ TIOCM_RTS /* : 0) */ 1888 result = /* (status & MSVR_RTS) ? */ TIOCM_RTS /* : 0) */
1891 | ((status & MSVR_DTR) ? TIOCM_DTR : 0) 1889 | ((status & MSVR_DTR) ? TIOCM_DTR : 0)
1892 | ((status & MSVR_CD) ? TIOCM_CAR : 0) 1890 | ((status & MSVR_CD) ? TIOCM_CAR : 0)
1893 |/* ((status & MSVR_DSR) ? */ TIOCM_DSR /* : 0) */ 1891 |/* ((status & MSVR_DSR) ? */ TIOCM_DSR /* : 0) */
@@ -1955,7 +1953,7 @@ static inline void sx_send_break(struct specialix_port * port, unsigned long len
1955{ 1953{
1956 struct specialix_board *bp = port_Board(port); 1954 struct specialix_board *bp = port_Board(port);
1957 unsigned long flags; 1955 unsigned long flags;
1958 1956
1959 func_enter(); 1957 func_enter();
1960 1958
1961 spin_lock_irqsave (&port->lock, flags); 1959 spin_lock_irqsave (&port->lock, flags);
@@ -1996,8 +1994,8 @@ static inline int sx_set_serial_info(struct specialix_port * port,
1996 func_enter(); 1994 func_enter();
1997 return -EFAULT; 1995 return -EFAULT;
1998 } 1996 }
1999 1997
2000#if 0 1998#if 0
2001 if ((tmp.irq != bp->irq) || 1999 if ((tmp.irq != bp->irq) ||
2002 (tmp.port != bp->base) || 2000 (tmp.port != bp->base) ||
2003 (tmp.type != PORT_CIRRUS) || 2001 (tmp.type != PORT_CIRRUS) ||
@@ -2008,12 +2006,12 @@ static inline int sx_set_serial_info(struct specialix_port * port,
2008 func_exit(); 2006 func_exit();
2009 return -EINVAL; 2007 return -EINVAL;
2010 } 2008 }
2011#endif 2009#endif
2012 2010
2013 change_speed = ((port->flags & ASYNC_SPD_MASK) != 2011 change_speed = ((port->flags & ASYNC_SPD_MASK) !=
2014 (tmp.flags & ASYNC_SPD_MASK)); 2012 (tmp.flags & ASYNC_SPD_MASK));
2015 change_speed |= (tmp.custom_divisor != port->custom_divisor); 2013 change_speed |= (tmp.custom_divisor != port->custom_divisor);
2016 2014
2017 if (!capable(CAP_SYS_ADMIN)) { 2015 if (!capable(CAP_SYS_ADMIN)) {
2018 if ((tmp.close_delay != port->close_delay) || 2016 if ((tmp.close_delay != port->close_delay) ||
2019 (tmp.closing_wait != port->closing_wait) || 2017 (tmp.closing_wait != port->closing_wait) ||
@@ -2045,7 +2043,7 @@ static inline int sx_get_serial_info(struct specialix_port * port,
2045{ 2043{
2046 struct serial_struct tmp; 2044 struct serial_struct tmp;
2047 struct specialix_board *bp = port_Board(port); 2045 struct specialix_board *bp = port_Board(port);
2048 2046
2049 func_enter(); 2047 func_enter();
2050 2048
2051 /* 2049 /*
@@ -2074,7 +2072,7 @@ static inline int sx_get_serial_info(struct specialix_port * port,
2074} 2072}
2075 2073
2076 2074
2077static int sx_ioctl(struct tty_struct * tty, struct file * filp, 2075static int sx_ioctl(struct tty_struct * tty, struct file * filp,
2078 unsigned int cmd, unsigned long arg) 2076 unsigned int cmd, unsigned long arg)
2079{ 2077{
2080 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 2078 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
@@ -2087,7 +2085,7 @@ static int sx_ioctl(struct tty_struct * tty, struct file * filp,
2087 func_exit(); 2085 func_exit();
2088 return -ENODEV; 2086 return -ENODEV;
2089 } 2087 }
2090 2088
2091 switch (cmd) { 2089 switch (cmd) {
2092 case TCSBRK: /* SVID version: non-zero arg --> no break */ 2090 case TCSBRK: /* SVID version: non-zero arg --> no break */
2093 retval = tty_check_change(tty); 2091 retval = tty_check_change(tty);
@@ -2129,7 +2127,7 @@ static int sx_ioctl(struct tty_struct * tty, struct file * filp,
2129 case TIOCGSERIAL: 2127 case TIOCGSERIAL:
2130 func_exit(); 2128 func_exit();
2131 return sx_get_serial_info(port, argp); 2129 return sx_get_serial_info(port, argp);
2132 case TIOCSSERIAL: 2130 case TIOCSSERIAL:
2133 func_exit(); 2131 func_exit();
2134 return sx_set_serial_info(port, argp); 2132 return sx_set_serial_info(port, argp);
2135 default: 2133 default:
@@ -2153,16 +2151,16 @@ static void sx_throttle(struct tty_struct * tty)
2153 func_exit(); 2151 func_exit();
2154 return; 2152 return;
2155 } 2153 }
2156 2154
2157 bp = port_Board(port); 2155 bp = port_Board(port);
2158 2156
2159 /* Use DTR instead of RTS ! */ 2157 /* Use DTR instead of RTS ! */
2160 if (SX_CRTSCTS (tty)) 2158 if (SX_CRTSCTS (tty))
2161 port->MSVR &= ~MSVR_DTR; 2159 port->MSVR &= ~MSVR_DTR;
2162 else { 2160 else {
2163 /* Auch!!! I think the system shouldn't call this then. */ 2161 /* Auch!!! I think the system shouldn't call this then. */
2164 /* Or maybe we're supposed (allowed?) to do our side of hw 2162 /* Or maybe we're supposed (allowed?) to do our side of hw
2165 handshake anyway, even when hardware handshake is off. 2163 handshake anyway, even when hardware handshake is off.
2166 When you see this in your logs, please report.... */ 2164 When you see this in your logs, please report.... */
2167 printk (KERN_ERR "sx%d: Need to throttle, but can't (hardware hs is off)\n", 2165 printk (KERN_ERR "sx%d: Need to throttle, but can't (hardware hs is off)\n",
2168 port_No (port)); 2166 port_No (port));
@@ -2193,14 +2191,14 @@ static void sx_unthrottle(struct tty_struct * tty)
2193 unsigned long flags; 2191 unsigned long flags;
2194 2192
2195 func_enter(); 2193 func_enter();
2196 2194
2197 if (sx_paranoia_check(port, tty->name, "sx_unthrottle")) { 2195 if (sx_paranoia_check(port, tty->name, "sx_unthrottle")) {
2198 func_exit(); 2196 func_exit();
2199 return; 2197 return;
2200 } 2198 }
2201 2199
2202 bp = port_Board(port); 2200 bp = port_Board(port);
2203 2201
2204 spin_lock_irqsave(&port->lock, flags); 2202 spin_lock_irqsave(&port->lock, flags);
2205 /* XXXX Use DTR INSTEAD???? */ 2203 /* XXXX Use DTR INSTEAD???? */
2206 if (SX_CRTSCTS(tty)) { 2204 if (SX_CRTSCTS(tty)) {
@@ -2234,14 +2232,14 @@ static void sx_stop(struct tty_struct * tty)
2234 unsigned long flags; 2232 unsigned long flags;
2235 2233
2236 func_enter(); 2234 func_enter();
2237 2235
2238 if (sx_paranoia_check(port, tty->name, "sx_stop")) { 2236 if (sx_paranoia_check(port, tty->name, "sx_stop")) {
2239 func_exit(); 2237 func_exit();
2240 return; 2238 return;
2241 } 2239 }
2242 2240
2243 bp = port_Board(port); 2241 bp = port_Board(port);
2244 2242
2245 spin_lock_irqsave(&port->lock, flags); 2243 spin_lock_irqsave(&port->lock, flags);
2246 port->IER &= ~IER_TXRDY; 2244 port->IER &= ~IER_TXRDY;
2247 spin_lock_irqsave(&bp->lock, flags); 2245 spin_lock_irqsave(&bp->lock, flags);
@@ -2261,14 +2259,14 @@ static void sx_start(struct tty_struct * tty)
2261 unsigned long flags; 2259 unsigned long flags;
2262 2260
2263 func_enter(); 2261 func_enter();
2264 2262
2265 if (sx_paranoia_check(port, tty->name, "sx_start")) { 2263 if (sx_paranoia_check(port, tty->name, "sx_start")) {
2266 func_exit(); 2264 func_exit();
2267 return; 2265 return;
2268 } 2266 }
2269 2267
2270 bp = port_Board(port); 2268 bp = port_Board(port);
2271 2269
2272 spin_lock_irqsave(&port->lock, flags); 2270 spin_lock_irqsave(&port->lock, flags);
2273 if (port->xmit_cnt && port->xmit_buf && !(port->IER & IER_TXRDY)) { 2271 if (port->xmit_cnt && port->xmit_buf && !(port->IER & IER_TXRDY)) {
2274 port->IER |= IER_TXRDY; 2272 port->IER |= IER_TXRDY;
@@ -2290,13 +2288,13 @@ static void sx_start(struct tty_struct * tty)
2290 * 2288 *
2291 * serial interrupt routine -> (workqueue) -> 2289 * serial interrupt routine -> (workqueue) ->
2292 * do_sx_hangup() -> tty->hangup() -> sx_hangup() 2290 * do_sx_hangup() -> tty->hangup() -> sx_hangup()
2293 * 2291 *
2294 */ 2292 */
2295static void do_sx_hangup(void *private_) 2293static void do_sx_hangup(void *private_)
2296{ 2294{
2297 struct specialix_port *port = (struct specialix_port *) private_; 2295 struct specialix_port *port = (struct specialix_port *) private_;
2298 struct tty_struct *tty; 2296 struct tty_struct *tty;
2299 2297
2300 func_enter(); 2298 func_enter();
2301 2299
2302 tty = port->tty; 2300 tty = port->tty;
@@ -2319,9 +2317,9 @@ static void sx_hangup(struct tty_struct * tty)
2319 func_exit(); 2317 func_exit();
2320 return; 2318 return;
2321 } 2319 }
2322 2320
2323 bp = port_Board(port); 2321 bp = port_Board(port);
2324 2322
2325 sx_shutdown_port(bp, port); 2323 sx_shutdown_port(bp, port);
2326 spin_lock_irqsave(&port->lock, flags); 2324 spin_lock_irqsave(&port->lock, flags);
2327 port->event = 0; 2325 port->event = 0;
@@ -2346,10 +2344,10 @@ static void sx_set_termios(struct tty_struct * tty, struct termios * old_termios
2346 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 2344 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
2347 unsigned long flags; 2345 unsigned long flags;
2348 struct specialix_board * bp; 2346 struct specialix_board * bp;
2349 2347
2350 if (sx_paranoia_check(port, tty->name, "sx_set_termios")) 2348 if (sx_paranoia_check(port, tty->name, "sx_set_termios"))
2351 return; 2349 return;
2352 2350
2353 if (tty->termios->c_cflag == old_termios->c_cflag && 2351 if (tty->termios->c_cflag == old_termios->c_cflag &&
2354 tty->termios->c_iflag == old_termios->c_iflag) 2352 tty->termios->c_iflag == old_termios->c_iflag)
2355 return; 2353 return;
@@ -2420,7 +2418,7 @@ static int sx_init_drivers(void)
2420 func_exit(); 2418 func_exit();
2421 return 1; 2419 return 1;
2422 } 2420 }
2423 2421
2424 if (!(tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL))) { 2422 if (!(tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL))) {
2425 printk(KERN_ERR "sx: Couldn't get free page.\n"); 2423 printk(KERN_ERR "sx: Couldn't get free page.\n");
2426 put_tty_driver(specialix_driver); 2424 put_tty_driver(specialix_driver);
@@ -2457,7 +2455,7 @@ static int sx_init_drivers(void)
2457 init_waitqueue_head(&sx_port[i].close_wait); 2455 init_waitqueue_head(&sx_port[i].close_wait);
2458 spin_lock_init(&sx_port[i].lock); 2456 spin_lock_init(&sx_port[i].lock);
2459 } 2457 }
2460 2458
2461 func_exit(); 2459 func_exit();
2462 return 0; 2460 return 0;
2463} 2461}
@@ -2472,8 +2470,8 @@ static void sx_release_drivers(void)
2472 func_exit(); 2470 func_exit();
2473} 2471}
2474 2472
2475/* 2473/*
2476 * This routine must be called by kernel at boot time 2474 * This routine must be called by kernel at boot time
2477 */ 2475 */
2478static int __init specialix_init(void) 2476static int __init specialix_init(void)
2479{ 2477{
@@ -2489,7 +2487,7 @@ static int __init specialix_init(void)
2489#else 2487#else
2490 printk (KERN_INFO "sx: DTR/RTS pin is RTS when CRTSCTS is on.\n"); 2488 printk (KERN_INFO "sx: DTR/RTS pin is RTS when CRTSCTS is on.\n");
2491#endif 2489#endif
2492 2490
2493 for (i = 0; i < SX_NBOARD; i++) 2491 for (i = 0; i < SX_NBOARD; i++)
2494 sx_board[i].lock = SPIN_LOCK_UNLOCKED; 2492 sx_board[i].lock = SPIN_LOCK_UNLOCKED;
2495 2493
@@ -2498,7 +2496,7 @@ static int __init specialix_init(void)
2498 return -EIO; 2496 return -EIO;
2499 } 2497 }
2500 2498
2501 for (i = 0; i < SX_NBOARD; i++) 2499 for (i = 0; i < SX_NBOARD; i++)
2502 if (sx_board[i].base && !sx_probe(&sx_board[i])) 2500 if (sx_board[i].base && !sx_probe(&sx_board[i]))
2503 found++; 2501 found++;
2504 2502
@@ -2512,8 +2510,8 @@ static int __init specialix_init(void)
2512 i++; 2510 i++;
2513 continue; 2511 continue;
2514 } 2512 }
2515 pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX, 2513 pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX,
2516 PCI_DEVICE_ID_SPECIALIX_IO8, 2514 PCI_DEVICE_ID_SPECIALIX_IO8,
2517 pdev); 2515 pdev);
2518 if (!pdev) break; 2516 if (!pdev) break;
2519 2517
@@ -2557,10 +2555,10 @@ module_param(sx_poll, int, 0);
2557/* 2555/*
2558 * You can setup up to 4 boards. 2556 * You can setup up to 4 boards.
2559 * by specifying "iobase=0xXXX,0xXXX ..." as insmod parameter. 2557 * by specifying "iobase=0xXXX,0xXXX ..." as insmod parameter.
2560 * You should specify the IRQs too in that case "irq=....,...". 2558 * You should specify the IRQs too in that case "irq=....,...".
2561 * 2559 *
2562 * More than 4 boards in one computer is not possible, as the card can 2560 * More than 4 boards in one computer is not possible, as the card can
2563 * only use 4 different interrupts. 2561 * only use 4 different interrupts.
2564 * 2562 *
2565 */ 2563 */
2566static int __init specialix_init_module(void) 2564static int __init specialix_init_module(void)
@@ -2583,16 +2581,16 @@ static int __init specialix_init_module(void)
2583 2581
2584 return specialix_init(); 2582 return specialix_init();
2585} 2583}
2586 2584
2587static void __exit specialix_exit_module(void) 2585static void __exit specialix_exit_module(void)
2588{ 2586{
2589 int i; 2587 int i;
2590 2588
2591 func_enter(); 2589 func_enter();
2592 2590
2593 sx_release_drivers(); 2591 sx_release_drivers();
2594 for (i = 0; i < SX_NBOARD; i++) 2592 for (i = 0; i < SX_NBOARD; i++)
2595 if (sx_board[i].flags & SX_BOARD_PRESENT) 2593 if (sx_board[i].flags & SX_BOARD_PRESENT)
2596 sx_release_io_range(&sx_board[i]); 2594 sx_release_io_range(&sx_board[i]);
2597#ifdef SPECIALIX_TIMER 2595#ifdef SPECIALIX_TIMER
2598 del_timer (&missed_irq_timer); 2596 del_timer (&missed_irq_timer);
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index 951545a6ef2d..1c686414e0a1 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -3095,7 +3095,9 @@ static int __init stl_init(void)
3095 devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR, i), 3095 devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR, i),
3096 S_IFCHR|S_IRUSR|S_IWUSR, 3096 S_IFCHR|S_IRUSR|S_IWUSR,
3097 "staliomem/%d", i); 3097 "staliomem/%d", i);
3098 class_device_create(stallion_class, MKDEV(STL_SIOMEMMAJOR, i), NULL, "staliomem%d", i); 3098 class_device_create(stallion_class, NULL,
3099 MKDEV(STL_SIOMEMMAJOR, i), NULL,
3100 "staliomem%d", i);
3099 } 3101 }
3100 3102
3101 stl_serial->owner = THIS_MODULE; 3103 stl_serial->owner = THIS_MODULE;
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c
index ea2d54be4843..0133dc0e25d0 100644
--- a/drivers/char/synclink.c
+++ b/drivers/char/synclink.c
@@ -912,6 +912,7 @@ MODULE_DEVICE_TABLE(pci, synclink_pci_tbl);
912MODULE_LICENSE("GPL"); 912MODULE_LICENSE("GPL");
913 913
914static struct pci_driver synclink_pci_driver = { 914static struct pci_driver synclink_pci_driver = {
915 .owner = THIS_MODULE,
915 .name = "synclink", 916 .name = "synclink",
916 .id_table = synclink_pci_tbl, 917 .id_table = synclink_pci_tbl,
917 .probe = synclink_init_one, 918 .probe = synclink_init_one,
diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c
index 6fb165cf8a61..f185724448b1 100644
--- a/drivers/char/synclinkmp.c
+++ b/drivers/char/synclinkmp.c
@@ -500,6 +500,7 @@ MODULE_DEVICE_TABLE(pci, synclinkmp_pci_tbl);
500MODULE_LICENSE("GPL"); 500MODULE_LICENSE("GPL");
501 501
502static struct pci_driver synclinkmp_pci_driver = { 502static struct pci_driver synclinkmp_pci_driver = {
503 .owner = THIS_MODULE,
503 .name = "synclinkmp", 504 .name = "synclinkmp",
504 .id_table = synclinkmp_pci_tbl, 505 .id_table = synclinkmp_pci_tbl,
505 .probe = synclinkmp_init_one, 506 .probe = synclinkmp_init_one,
diff --git a/drivers/char/tipar.c b/drivers/char/tipar.c
index ec78d2f161f7..41a94bc79f67 100644
--- a/drivers/char/tipar.c
+++ b/drivers/char/tipar.c
@@ -436,7 +436,7 @@ tipar_register(int nr, struct parport *port)
436 goto out; 436 goto out;
437 } 437 }
438 438
439 class_device_create(tipar_class, MKDEV(TIPAR_MAJOR, 439 class_device_create(tipar_class, NULL, MKDEV(TIPAR_MAJOR,
440 TIPAR_MINOR + nr), NULL, "par%d", nr); 440 TIPAR_MINOR + nr), NULL, "par%d", nr);
441 /* Use devfs, tree: /dev/ticables/par/[0..2] */ 441 /* Use devfs, tree: /dev/ticables/par/[0..2] */
442 err = devfs_mk_cdev(MKDEV(TIPAR_MAJOR, TIPAR_MINOR + nr), 442 err = devfs_mk_cdev(MKDEV(TIPAR_MAJOR, TIPAR_MINOR + nr),
diff --git a/drivers/char/tlclk.c b/drivers/char/tlclk.c
new file mode 100644
index 000000000000..18cdd4361dc6
--- /dev/null
+++ b/drivers/char/tlclk.c
@@ -0,0 +1,896 @@
1/*
2 * Telecom Clock driver for Intel NetStructure(tm) MPCBL0010
3 *
4 * Copyright (C) 2005 Kontron Canada
5 *
6 * All rights reserved.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
16 * NON INFRINGEMENT. See the GNU General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 * Send feedback to <sebastien.bouchard@ca.kontron.com> and the current
24 * Maintainer <mark.gross@intel.com>
25 *
26 * Description : This is the TELECOM CLOCK module driver for the ATCA
27 * MPCBL0010 ATCA computer.
28 */
29
30#include <linux/config.h>
31#include <linux/module.h>
32#include <linux/init.h>
33#include <linux/sched.h>
34#include <linux/kernel.h> /* printk() */
35#include <linux/fs.h> /* everything... */
36#include <linux/errno.h> /* error codes */
37#include <linux/delay.h> /* udelay */
38#include <linux/slab.h>
39#include <linux/ioport.h>
40#include <linux/interrupt.h>
41#include <linux/spinlock.h>
42#include <linux/timer.h>
43#include <linux/sysfs.h>
44#include <linux/device.h>
45#include <linux/miscdevice.h>
46#include <asm/io.h> /* inb/outb */
47#include <asm/uaccess.h>
48
49MODULE_AUTHOR("Sebastien Bouchard <sebastien.bouchard@ca.kontron.com>");
50MODULE_LICENSE("GPL");
51
52/*Hardware Reset of the PLL */
53#define RESET_ON 0x00
54#define RESET_OFF 0x01
55
56/* MODE SELECT */
57#define NORMAL_MODE 0x00
58#define HOLDOVER_MODE 0x10
59#define FREERUN_MODE 0x20
60
61/* FILTER SELECT */
62#define FILTER_6HZ 0x04
63#define FILTER_12HZ 0x00
64
65/* SELECT REFERENCE FREQUENCY */
66#define REF_CLK1_8kHz 0x00
67#define REF_CLK2_19_44MHz 0x02
68
69/* Select primary or secondary redundant clock */
70#define PRIMARY_CLOCK 0x00
71#define SECONDARY_CLOCK 0x01
72
73/* CLOCK TRANSMISSION DEFINE */
74#define CLK_8kHz 0xff
75#define CLK_16_384MHz 0xfb
76
77#define CLK_1_544MHz 0x00
78#define CLK_2_048MHz 0x01
79#define CLK_4_096MHz 0x02
80#define CLK_6_312MHz 0x03
81#define CLK_8_192MHz 0x04
82#define CLK_19_440MHz 0x06
83
84#define CLK_8_592MHz 0x08
85#define CLK_11_184MHz 0x09
86#define CLK_34_368MHz 0x0b
87#define CLK_44_736MHz 0x0a
88
89/* RECEIVED REFERENCE */
90#define AMC_B1 0
91#define AMC_B2 1
92
93/* HARDWARE SWITCHING DEFINE */
94#define HW_ENABLE 0x80
95#define HW_DISABLE 0x00
96
97/* HARDWARE SWITCHING MODE DEFINE */
98#define PLL_HOLDOVER 0x40
99#define LOST_CLOCK 0x00
100
101/* ALARMS DEFINE */
102#define UNLOCK_MASK 0x10
103#define HOLDOVER_MASK 0x20
104#define SEC_LOST_MASK 0x40
105#define PRI_LOST_MASK 0x80
106
107/* INTERRUPT CAUSE DEFINE */
108
109#define PRI_LOS_01_MASK 0x01
110#define PRI_LOS_10_MASK 0x02
111
112#define SEC_LOS_01_MASK 0x04
113#define SEC_LOS_10_MASK 0x08
114
115#define HOLDOVER_01_MASK 0x10
116#define HOLDOVER_10_MASK 0x20
117
118#define UNLOCK_01_MASK 0x40
119#define UNLOCK_10_MASK 0x80
120
121struct tlclk_alarms {
122 __u32 lost_clocks;
123 __u32 lost_primary_clock;
124 __u32 lost_secondary_clock;
125 __u32 primary_clock_back;
126 __u32 secondary_clock_back;
127 __u32 switchover_primary;
128 __u32 switchover_secondary;
129 __u32 pll_holdover;
130 __u32 pll_end_holdover;
131 __u32 pll_lost_sync;
132 __u32 pll_sync;
133};
134/* Telecom clock I/O register definition */
135#define TLCLK_BASE 0xa08
136#define TLCLK_REG0 TLCLK_BASE
137#define TLCLK_REG1 (TLCLK_BASE+1)
138#define TLCLK_REG2 (TLCLK_BASE+2)
139#define TLCLK_REG3 (TLCLK_BASE+3)
140#define TLCLK_REG4 (TLCLK_BASE+4)
141#define TLCLK_REG5 (TLCLK_BASE+5)
142#define TLCLK_REG6 (TLCLK_BASE+6)
143#define TLCLK_REG7 (TLCLK_BASE+7)
144
145#define SET_PORT_BITS(port, mask, val) outb(((inb(port) & mask) | val), port)
146
147/* 0 = Dynamic allocation of the major device number */
148#define TLCLK_MAJOR 0
149
150/* sysfs interface definition:
151Upon loading the driver will create a sysfs directory under
152/sys/devices/platform/telco_clock.
153
154This directory exports the following interfaces. There operation is
155documented in the MCPBL0010 TPS under the Telecom Clock API section, 11.4.
156alarms :
157current_ref :
158enable_clk3a_output :
159enable_clk3b_output :
160enable_clka0_output :
161enable_clka1_output :
162enable_clkb0_output :
163enable_clkb1_output :
164filter_select :
165hardware_switching :
166hardware_switching_mode :
167interrupt_switch :
168mode_select :
169refalign :
170reset :
171select_amcb1_transmit_clock :
172select_amcb2_transmit_clock :
173select_redundant_clock :
174select_ref_frequency :
175test_mode :
176
177All sysfs interfaces are integers in hex format, i.e echo 99 > refalign
178has the same effect as echo 0x99 > refalign.
179*/
180
181static unsigned int telclk_interrupt;
182
183static int int_events; /* Event that generate a interrupt */
184static int got_event; /* if events processing have been done */
185
186static void switchover_timeout(unsigned long data);
187static struct timer_list switchover_timer =
188 TIMER_INITIALIZER(switchover_timeout , 0, 0);
189
190static struct tlclk_alarms *alarm_events;
191
192static DEFINE_SPINLOCK(event_lock);
193
194static int tlclk_major = TLCLK_MAJOR;
195
196static irqreturn_t tlclk_interrupt(int irq, void *dev_id, struct pt_regs *regs);
197
198static DECLARE_WAIT_QUEUE_HEAD(wq);
199
200static int tlclk_open(struct inode *inode, struct file *filp)
201{
202 int result;
203
204 /* Make sure there is no interrupt pending while
205 * initialising interrupt handler */
206 inb(TLCLK_REG6);
207
208 /* This device is wired through the FPGA IO space of the ATCA blade
209 * we can't share this IRQ */
210 result = request_irq(telclk_interrupt, &tlclk_interrupt,
211 SA_INTERRUPT, "telco_clock", tlclk_interrupt);
212 if (result == -EBUSY) {
213 printk(KERN_ERR "telco_clock: Interrupt can't be reserved!\n");
214 return -EBUSY;
215 }
216 inb(TLCLK_REG6); /* Clear interrupt events */
217
218 return 0;
219}
220
221static int tlclk_release(struct inode *inode, struct file *filp)
222{
223 free_irq(telclk_interrupt, tlclk_interrupt);
224
225 return 0;
226}
227
228ssize_t tlclk_read(struct file *filp, char __user *buf, size_t count,
229 loff_t *f_pos)
230{
231 if (count < sizeof(struct tlclk_alarms))
232 return -EIO;
233
234 wait_event_interruptible(wq, got_event);
235 if (copy_to_user(buf, alarm_events, sizeof(struct tlclk_alarms)))
236 return -EFAULT;
237
238 memset(alarm_events, 0, sizeof(struct tlclk_alarms));
239 got_event = 0;
240
241 return sizeof(struct tlclk_alarms);
242}
243
244ssize_t tlclk_write(struct file *filp, const char __user *buf, size_t count,
245 loff_t *f_pos)
246{
247 return 0;
248}
249
250static struct file_operations tlclk_fops = {
251 .read = tlclk_read,
252 .write = tlclk_write,
253 .open = tlclk_open,
254 .release = tlclk_release,
255
256};
257
258static struct miscdevice tlclk_miscdev = {
259 .minor = MISC_DYNAMIC_MINOR,
260 .name = "telco_clock",
261 .fops = &tlclk_fops,
262};
263
264static ssize_t show_current_ref(struct device *d,
265 struct device_attribute *attr, char *buf)
266{
267 unsigned long ret_val;
268 unsigned long flags;
269
270 spin_lock_irqsave(&event_lock, flags);
271 ret_val = ((inb(TLCLK_REG1) & 0x08) >> 3);
272 spin_unlock_irqrestore(&event_lock, flags);
273
274 return sprintf(buf, "0x%lX\n", ret_val);
275}
276
277static DEVICE_ATTR(current_ref, S_IRUGO, show_current_ref, NULL);
278
279
280static ssize_t show_interrupt_switch(struct device *d,
281 struct device_attribute *attr, char *buf)
282{
283 unsigned long ret_val;
284 unsigned long flags;
285
286 spin_lock_irqsave(&event_lock, flags);
287 ret_val = inb(TLCLK_REG6);
288 spin_unlock_irqrestore(&event_lock, flags);
289
290 return sprintf(buf, "0x%lX\n", ret_val);
291}
292
293static DEVICE_ATTR(interrupt_switch, S_IRUGO,
294 show_interrupt_switch, NULL);
295
296static ssize_t show_alarms(struct device *d,
297 struct device_attribute *attr, char *buf)
298{
299 unsigned long ret_val;
300 unsigned long flags;
301
302 spin_lock_irqsave(&event_lock, flags);
303 ret_val = (inb(TLCLK_REG2) & 0xf0);
304 spin_unlock_irqrestore(&event_lock, flags);
305
306 return sprintf(buf, "0x%lX\n", ret_val);
307}
308
309static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
310
311static ssize_t store_enable_clk3b_output(struct device *d,
312 struct device_attribute *attr, const char *buf, size_t count)
313{
314 unsigned long tmp;
315 unsigned char val;
316 unsigned long flags;
317
318 sscanf(buf, "%lX", &tmp);
319 dev_dbg(d, ": tmp = 0x%lX\n", tmp);
320
321 val = (unsigned char)tmp;
322 spin_lock_irqsave(&event_lock, flags);
323 SET_PORT_BITS(TLCLK_REG3, 0x7f, val << 7);
324 spin_unlock_irqrestore(&event_lock, flags);
325
326 return strnlen(buf, count);
327}
328
329static DEVICE_ATTR(enable_clk3b_output, S_IWUGO, NULL,
330 store_enable_clk3b_output);
331
332static ssize_t store_enable_clk3a_output(struct device *d,
333 struct device_attribute *attr, const char *buf, size_t count)
334{
335 unsigned long flags;
336 unsigned long tmp;
337 unsigned char val;
338
339 sscanf(buf, "%lX", &tmp);
340 dev_dbg(d, "tmp = 0x%lX\n", tmp);
341
342 val = (unsigned char)tmp;
343 spin_lock_irqsave(&event_lock, flags);
344 SET_PORT_BITS(TLCLK_REG3, 0xbf, val << 6);
345 spin_unlock_irqrestore(&event_lock, flags);
346
347 return strnlen(buf, count);
348}
349
350static DEVICE_ATTR(enable_clk3a_output, S_IWUGO, NULL,
351 store_enable_clk3a_output);
352
353static ssize_t store_enable_clkb1_output(struct device *d,
354 struct device_attribute *attr, const char *buf, size_t count)
355{
356 unsigned long flags;
357 unsigned long tmp;
358 unsigned char val;
359
360 sscanf(buf, "%lX", &tmp);
361 dev_dbg(d, "tmp = 0x%lX\n", tmp);
362
363 val = (unsigned char)tmp;
364 spin_lock_irqsave(&event_lock, flags);
365 SET_PORT_BITS(TLCLK_REG2, 0xf7, val << 3);
366 spin_unlock_irqrestore(&event_lock, flags);
367
368 return strnlen(buf, count);
369}
370
371static DEVICE_ATTR(enable_clkb1_output, S_IWUGO, NULL,
372 store_enable_clkb1_output);
373
374
375static ssize_t store_enable_clka1_output(struct device *d,
376 struct device_attribute *attr, const char *buf, size_t count)
377{
378 unsigned long flags;
379 unsigned long tmp;
380 unsigned char val;
381
382 sscanf(buf, "%lX", &tmp);
383 dev_dbg(d, "tmp = 0x%lX\n", tmp);
384
385 val = (unsigned char)tmp;
386 spin_lock_irqsave(&event_lock, flags);
387 SET_PORT_BITS(TLCLK_REG2, 0xfb, val << 2);
388 spin_unlock_irqrestore(&event_lock, flags);
389
390 return strnlen(buf, count);
391}
392
393static DEVICE_ATTR(enable_clka1_output, S_IWUGO, NULL,
394 store_enable_clka1_output);
395
396static ssize_t store_enable_clkb0_output(struct device *d,
397 struct device_attribute *attr, const char *buf, size_t count)
398{
399 unsigned long flags;
400 unsigned long tmp;
401 unsigned char val;
402
403 sscanf(buf, "%lX", &tmp);
404 dev_dbg(d, "tmp = 0x%lX\n", tmp);
405
406 val = (unsigned char)tmp;
407 spin_lock_irqsave(&event_lock, flags);
408 SET_PORT_BITS(TLCLK_REG2, 0xfd, val << 1);
409 spin_unlock_irqrestore(&event_lock, flags);
410
411 return strnlen(buf, count);
412}
413
414static DEVICE_ATTR(enable_clkb0_output, S_IWUGO, NULL,
415 store_enable_clkb0_output);
416
417static ssize_t store_enable_clka0_output(struct device *d,
418 struct device_attribute *attr, const char *buf, size_t count)
419{
420 unsigned long flags;
421 unsigned long tmp;
422 unsigned char val;
423
424 sscanf(buf, "%lX", &tmp);
425 dev_dbg(d, "tmp = 0x%lX\n", tmp);
426
427 val = (unsigned char)tmp;
428 spin_lock_irqsave(&event_lock, flags);
429 SET_PORT_BITS(TLCLK_REG2, 0xfe, val);
430 spin_unlock_irqrestore(&event_lock, flags);
431
432 return strnlen(buf, count);
433}
434
435static DEVICE_ATTR(enable_clka0_output, S_IWUGO, NULL,
436 store_enable_clka0_output);
437
438static ssize_t store_test_mode(struct device *d,
439 struct device_attribute *attr, const char *buf, size_t count)
440{
441 unsigned long flags;
442 unsigned long tmp;
443 unsigned char val;
444
445 sscanf(buf, "%lX", &tmp);
446 dev_dbg(d, "tmp = 0x%lX\n", tmp);
447
448 val = (unsigned char)tmp;
449 spin_lock_irqsave(&event_lock, flags);
450 SET_PORT_BITS(TLCLK_REG4, 0xfd, 2);
451 spin_unlock_irqrestore(&event_lock, flags);
452
453 return strnlen(buf, count);
454}
455
456static DEVICE_ATTR(test_mode, S_IWUGO, NULL, store_test_mode);
457
458static ssize_t store_select_amcb2_transmit_clock(struct device *d,
459 struct device_attribute *attr, const char *buf, size_t count)
460{
461 unsigned long flags;
462 unsigned long tmp;
463 unsigned char val;
464
465 sscanf(buf, "%lX", &tmp);
466 dev_dbg(d, "tmp = 0x%lX\n", tmp);
467
468 val = (unsigned char)tmp;
469 spin_lock_irqsave(&event_lock, flags);
470 if ((val == CLK_8kHz) || (val == CLK_16_384MHz)) {
471 SET_PORT_BITS(TLCLK_REG3, 0xc7, 0x28);
472 SET_PORT_BITS(TLCLK_REG1, 0xfb, ~val);
473 } else if (val >= CLK_8_592MHz) {
474 SET_PORT_BITS(TLCLK_REG3, 0xc7, 0x38);
475 switch (val) {
476 case CLK_8_592MHz:
477 SET_PORT_BITS(TLCLK_REG0, 0xfc, 1);
478 break;
479 case CLK_11_184MHz:
480 SET_PORT_BITS(TLCLK_REG0, 0xfc, 0);
481 break;
482 case CLK_34_368MHz:
483 SET_PORT_BITS(TLCLK_REG0, 0xfc, 3);
484 break;
485 case CLK_44_736MHz:
486 SET_PORT_BITS(TLCLK_REG0, 0xfc, 2);
487 break;
488 }
489 } else
490 SET_PORT_BITS(TLCLK_REG3, 0xc7, val << 3);
491
492 spin_unlock_irqrestore(&event_lock, flags);
493
494 return strnlen(buf, count);
495}
496
497static DEVICE_ATTR(select_amcb2_transmit_clock, S_IWUGO, NULL,
498 store_select_amcb2_transmit_clock);
499
500static ssize_t store_select_amcb1_transmit_clock(struct device *d,
501 struct device_attribute *attr, const char *buf, size_t count)
502{
503 unsigned long tmp;
504 unsigned char val;
505 unsigned long flags;
506
507 sscanf(buf, "%lX", &tmp);
508 dev_dbg(d, "tmp = 0x%lX\n", tmp);
509
510 val = (unsigned char)tmp;
511 spin_lock_irqsave(&event_lock, flags);
512 if ((val == CLK_8kHz) || (val == CLK_16_384MHz)) {
513 SET_PORT_BITS(TLCLK_REG3, 0xf8, 0x5);
514 SET_PORT_BITS(TLCLK_REG1, 0xfb, ~val);
515 } else if (val >= CLK_8_592MHz) {
516 SET_PORT_BITS(TLCLK_REG3, 0xf8, 0x7);
517 switch (val) {
518 case CLK_8_592MHz:
519 SET_PORT_BITS(TLCLK_REG0, 0xfc, 1);
520 break;
521 case CLK_11_184MHz:
522 SET_PORT_BITS(TLCLK_REG0, 0xfc, 0);
523 break;
524 case CLK_34_368MHz:
525 SET_PORT_BITS(TLCLK_REG0, 0xfc, 3);
526 break;
527 case CLK_44_736MHz:
528 SET_PORT_BITS(TLCLK_REG0, 0xfc, 2);
529 break;
530 }
531 } else
532 SET_PORT_BITS(TLCLK_REG3, 0xf8, val);
533 spin_unlock_irqrestore(&event_lock, flags);
534
535 return strnlen(buf, count);
536}
537
538static DEVICE_ATTR(select_amcb1_transmit_clock, S_IWUGO, NULL,
539 store_select_amcb1_transmit_clock);
540
541static ssize_t store_select_redundant_clock(struct device *d,
542 struct device_attribute *attr, const char *buf, size_t count)
543{
544 unsigned long tmp;
545 unsigned char val;
546 unsigned long flags;
547
548 sscanf(buf, "%lX", &tmp);
549 dev_dbg(d, "tmp = 0x%lX\n", tmp);
550
551 val = (unsigned char)tmp;
552 spin_lock_irqsave(&event_lock, flags);
553 SET_PORT_BITS(TLCLK_REG1, 0xfe, val);
554 spin_unlock_irqrestore(&event_lock, flags);
555
556 return strnlen(buf, count);
557}
558
559static DEVICE_ATTR(select_redundant_clock, S_IWUGO, NULL,
560 store_select_redundant_clock);
561
562static ssize_t store_select_ref_frequency(struct device *d,
563 struct device_attribute *attr, const char *buf, size_t count)
564{
565 unsigned long tmp;
566 unsigned char val;
567 unsigned long flags;
568
569 sscanf(buf, "%lX", &tmp);
570 dev_dbg(d, "tmp = 0x%lX\n", tmp);
571
572 val = (unsigned char)tmp;
573 spin_lock_irqsave(&event_lock, flags);
574 SET_PORT_BITS(TLCLK_REG1, 0xfd, val);
575 spin_unlock_irqrestore(&event_lock, flags);
576
577 return strnlen(buf, count);
578}
579
580static DEVICE_ATTR(select_ref_frequency, S_IWUGO, NULL,
581 store_select_ref_frequency);
582
583static ssize_t store_filter_select(struct device *d,
584 struct device_attribute *attr, const char *buf, size_t count)
585{
586 unsigned long tmp;
587 unsigned char val;
588 unsigned long flags;
589
590 sscanf(buf, "%lX", &tmp);
591 dev_dbg(d, "tmp = 0x%lX\n", tmp);
592
593 val = (unsigned char)tmp;
594 spin_lock_irqsave(&event_lock, flags);
595 SET_PORT_BITS(TLCLK_REG0, 0xfb, val);
596 spin_unlock_irqrestore(&event_lock, flags);
597
598 return strnlen(buf, count);
599}
600
601static DEVICE_ATTR(filter_select, S_IWUGO, NULL, store_filter_select);
602
603static ssize_t store_hardware_switching_mode(struct device *d,
604 struct device_attribute *attr, const char *buf, size_t count)
605{
606 unsigned long tmp;
607 unsigned char val;
608 unsigned long flags;
609
610 sscanf(buf, "%lX", &tmp);
611 dev_dbg(d, "tmp = 0x%lX\n", tmp);
612
613 val = (unsigned char)tmp;
614 spin_lock_irqsave(&event_lock, flags);
615 SET_PORT_BITS(TLCLK_REG0, 0xbf, val);
616 spin_unlock_irqrestore(&event_lock, flags);
617
618 return strnlen(buf, count);
619}
620
621static DEVICE_ATTR(hardware_switching_mode, S_IWUGO, NULL,
622 store_hardware_switching_mode);
623
624static ssize_t store_hardware_switching(struct device *d,
625 struct device_attribute *attr, const char *buf, size_t count)
626{
627 unsigned long tmp;
628 unsigned char val;
629 unsigned long flags;
630
631 sscanf(buf, "%lX", &tmp);
632 dev_dbg(d, "tmp = 0x%lX\n", tmp);
633
634 val = (unsigned char)tmp;
635 spin_lock_irqsave(&event_lock, flags);
636 SET_PORT_BITS(TLCLK_REG0, 0x7f, val);
637 spin_unlock_irqrestore(&event_lock, flags);
638
639 return strnlen(buf, count);
640}
641
642static DEVICE_ATTR(hardware_switching, S_IWUGO, NULL,
643 store_hardware_switching);
644
645static ssize_t store_refalign (struct device *d,
646 struct device_attribute *attr, const char *buf, size_t count)
647{
648 unsigned long tmp;
649 unsigned long flags;
650
651 sscanf(buf, "%lX", &tmp);
652 dev_dbg(d, "tmp = 0x%lX\n", tmp);
653 spin_lock_irqsave(&event_lock, flags);
654 SET_PORT_BITS(TLCLK_REG0, 0xf7, 0);
655 udelay(2);
656 SET_PORT_BITS(TLCLK_REG0, 0xf7, 0x08);
657 udelay(2);
658 SET_PORT_BITS(TLCLK_REG0, 0xf7, 0);
659 spin_unlock_irqrestore(&event_lock, flags);
660
661 return strnlen(buf, count);
662}
663
664static DEVICE_ATTR(refalign, S_IWUGO, NULL, store_refalign);
665
666static ssize_t store_mode_select (struct device *d,
667 struct device_attribute *attr, const char *buf, size_t count)
668{
669 unsigned long tmp;
670 unsigned char val;
671 unsigned long flags;
672
673 sscanf(buf, "%lX", &tmp);
674 dev_dbg(d, "tmp = 0x%lX\n", tmp);
675
676 val = (unsigned char)tmp;
677 spin_lock_irqsave(&event_lock, flags);
678 SET_PORT_BITS(TLCLK_REG0, 0xcf, val);
679 spin_unlock_irqrestore(&event_lock, flags);
680
681 return strnlen(buf, count);
682}
683
684static DEVICE_ATTR(mode_select, S_IWUGO, NULL, store_mode_select);
685
686static ssize_t store_reset (struct device *d,
687 struct device_attribute *attr, const char *buf, size_t count)
688{
689 unsigned long tmp;
690 unsigned char val;
691 unsigned long flags;
692
693 sscanf(buf, "%lX", &tmp);
694 dev_dbg(d, "tmp = 0x%lX\n", tmp);
695
696 val = (unsigned char)tmp;
697 spin_lock_irqsave(&event_lock, flags);
698 SET_PORT_BITS(TLCLK_REG4, 0xfd, val);
699 spin_unlock_irqrestore(&event_lock, flags);
700
701 return strnlen(buf, count);
702}
703
704static DEVICE_ATTR(reset, S_IWUGO, NULL, store_reset);
705
706static struct attribute *tlclk_sysfs_entries[] = {
707 &dev_attr_current_ref.attr,
708 &dev_attr_interrupt_switch.attr,
709 &dev_attr_alarms.attr,
710 &dev_attr_enable_clk3a_output.attr,
711 &dev_attr_enable_clk3b_output.attr,
712 &dev_attr_enable_clkb1_output.attr,
713 &dev_attr_enable_clka1_output.attr,
714 &dev_attr_enable_clkb0_output.attr,
715 &dev_attr_enable_clka0_output.attr,
716 &dev_attr_test_mode.attr,
717 &dev_attr_select_amcb1_transmit_clock.attr,
718 &dev_attr_select_amcb2_transmit_clock.attr,
719 &dev_attr_select_redundant_clock.attr,
720 &dev_attr_select_ref_frequency.attr,
721 &dev_attr_filter_select.attr,
722 &dev_attr_hardware_switching_mode.attr,
723 &dev_attr_hardware_switching.attr,
724 &dev_attr_refalign.attr,
725 &dev_attr_mode_select.attr,
726 &dev_attr_reset.attr,
727 NULL
728};
729
730static struct attribute_group tlclk_attribute_group = {
731 .name = NULL, /* put in device directory */
732 .attrs = tlclk_sysfs_entries,
733};
734
735static struct platform_device *tlclk_device;
736
737static int __init tlclk_init(void)
738{
739 int ret;
740
741 ret = register_chrdev(tlclk_major, "telco_clock", &tlclk_fops);
742 if (ret < 0) {
743 printk(KERN_ERR "telco_clock: can't get major! %d\n", tlclk_major);
744 return ret;
745 }
746 alarm_events = kzalloc( sizeof(struct tlclk_alarms), GFP_KERNEL);
747 if (!alarm_events)
748 goto out1;
749
750 /* Read telecom clock IRQ number (Set by BIOS) */
751 if (!request_region(TLCLK_BASE, 8, "telco_clock")) {
752 printk(KERN_ERR "tlclk: request_region failed! 0x%X\n",
753 TLCLK_BASE);
754 ret = -EBUSY;
755 goto out2;
756 }
757 telclk_interrupt = (inb(TLCLK_REG7) & 0x0f);
758
759 if (0x0F == telclk_interrupt ) { /* not MCPBL0010 ? */
760 printk(KERN_ERR "telclk_interrup = 0x%x non-mcpbl0010 hw\n",
761 telclk_interrupt);
762 ret = -ENXIO;
763 goto out3;
764 }
765
766 init_timer(&switchover_timer);
767
768 ret = misc_register(&tlclk_miscdev);
769 if (ret < 0) {
770 printk(KERN_ERR " misc_register retruns %d\n", ret);
771 ret = -EBUSY;
772 goto out3;
773 }
774
775 tlclk_device = platform_device_register_simple("telco_clock",
776 -1, NULL, 0);
777 if (!tlclk_device) {
778 printk(KERN_ERR " platform_device_register retruns 0x%X\n",
779 (unsigned int) tlclk_device);
780 ret = -EBUSY;
781 goto out4;
782 }
783
784 ret = sysfs_create_group(&tlclk_device->dev.kobj,
785 &tlclk_attribute_group);
786 if (ret) {
787 printk(KERN_ERR "failed to create sysfs device attributes\n");
788 sysfs_remove_group(&tlclk_device->dev.kobj,
789 &tlclk_attribute_group);
790 goto out5;
791 }
792
793 return 0;
794out5:
795 platform_device_unregister(tlclk_device);
796out4:
797 misc_deregister(&tlclk_miscdev);
798out3:
799 release_region(TLCLK_BASE, 8);
800out2:
801 kfree(alarm_events);
802out1:
803 unregister_chrdev(tlclk_major, "telco_clock");
804 return ret;
805}
806
807static void __exit tlclk_cleanup(void)
808{
809 sysfs_remove_group(&tlclk_device->dev.kobj, &tlclk_attribute_group);
810 platform_device_unregister(tlclk_device);
811 misc_deregister(&tlclk_miscdev);
812 unregister_chrdev(tlclk_major, "telco_clock");
813
814 release_region(TLCLK_BASE, 8);
815 del_timer_sync(&switchover_timer);
816 kfree(alarm_events);
817
818}
819
820static void switchover_timeout(unsigned long data)
821{
822 if ((data & 1)) {
823 if ((inb(TLCLK_REG1) & 0x08) != (data & 0x08))
824 alarm_events->switchover_primary++;
825 } else {
826 if ((inb(TLCLK_REG1) & 0x08) != (data & 0x08))
827 alarm_events->switchover_secondary++;
828 }
829
830 /* Alarm processing is done, wake up read task */
831 del_timer(&switchover_timer);
832 got_event = 1;
833 wake_up(&wq);
834}
835
836static irqreturn_t tlclk_interrupt(int irq, void *dev_id, struct pt_regs *regs)
837{
838 unsigned long flags;
839
840 spin_lock_irqsave(&event_lock, flags);
841 /* Read and clear interrupt events */
842 int_events = inb(TLCLK_REG6);
843
844 /* Primary_Los changed from 0 to 1 ? */
845 if (int_events & PRI_LOS_01_MASK) {
846 if (inb(TLCLK_REG2) & SEC_LOST_MASK)
847 alarm_events->lost_clocks++;
848 else
849 alarm_events->lost_primary_clock++;
850 }
851
852 /* Primary_Los changed from 1 to 0 ? */
853 if (int_events & PRI_LOS_10_MASK) {
854 alarm_events->primary_clock_back++;
855 SET_PORT_BITS(TLCLK_REG1, 0xFE, 1);
856 }
857 /* Secondary_Los changed from 0 to 1 ? */
858 if (int_events & SEC_LOS_01_MASK) {
859 if (inb(TLCLK_REG2) & PRI_LOST_MASK)
860 alarm_events->lost_clocks++;
861 else
862 alarm_events->lost_secondary_clock++;
863 }
864 /* Secondary_Los changed from 1 to 0 ? */
865 if (int_events & SEC_LOS_10_MASK) {
866 alarm_events->secondary_clock_back++;
867 SET_PORT_BITS(TLCLK_REG1, 0xFE, 0);
868 }
869 if (int_events & HOLDOVER_10_MASK)
870 alarm_events->pll_end_holdover++;
871
872 if (int_events & UNLOCK_01_MASK)
873 alarm_events->pll_lost_sync++;
874
875 if (int_events & UNLOCK_10_MASK)
876 alarm_events->pll_sync++;
877
878 /* Holdover changed from 0 to 1 ? */
879 if (int_events & HOLDOVER_01_MASK) {
880 alarm_events->pll_holdover++;
881
882 /* TIMEOUT in ~10ms */
883 switchover_timer.expires = jiffies + msecs_to_jiffies(10);
884 switchover_timer.data = inb(TLCLK_REG1);
885 add_timer(&switchover_timer);
886 } else {
887 got_event = 1;
888 wake_up(&wq);
889 }
890 spin_unlock_irqrestore(&event_lock, flags);
891
892 return IRQ_HANDLED;
893}
894
895module_init(tlclk_init);
896module_exit(tlclk_cleanup);
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index 049d128ae7f0..303f15880466 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -64,7 +64,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
64 if (count == 0) 64 if (count == 0)
65 return -ENODATA; 65 return -ENODATA;
66 if (count > bufsiz) { 66 if (count > bufsiz) {
67 dev_err(&chip->pci_dev->dev, 67 dev_err(chip->dev,
68 "invalid count value %x %zx \n", count, bufsiz); 68 "invalid count value %x %zx \n", count, bufsiz);
69 return -E2BIG; 69 return -E2BIG;
70 } 70 }
@@ -72,21 +72,21 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
72 down(&chip->tpm_mutex); 72 down(&chip->tpm_mutex);
73 73
74 if ((rc = chip->vendor->send(chip, (u8 *) buf, count)) < 0) { 74 if ((rc = chip->vendor->send(chip, (u8 *) buf, count)) < 0) {
75 dev_err(&chip->pci_dev->dev, 75 dev_err(chip->dev,
76 "tpm_transmit: tpm_send: error %zd\n", rc); 76 "tpm_transmit: tpm_send: error %zd\n", rc);
77 goto out; 77 goto out;
78 } 78 }
79 79
80 stop = jiffies + 2 * 60 * HZ; 80 stop = jiffies + 2 * 60 * HZ;
81 do { 81 do {
82 u8 status = inb(chip->vendor->base + 1); 82 u8 status = chip->vendor->status(chip);
83 if ((status & chip->vendor->req_complete_mask) == 83 if ((status & chip->vendor->req_complete_mask) ==
84 chip->vendor->req_complete_val) { 84 chip->vendor->req_complete_val) {
85 goto out_recv; 85 goto out_recv;
86 } 86 }
87 87
88 if ((status == chip->vendor->req_canceled)) { 88 if ((status == chip->vendor->req_canceled)) {
89 dev_err(&chip->pci_dev->dev, "Operation Canceled\n"); 89 dev_err(chip->dev, "Operation Canceled\n");
90 rc = -ECANCELED; 90 rc = -ECANCELED;
91 goto out; 91 goto out;
92 } 92 }
@@ -97,14 +97,14 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
97 97
98 98
99 chip->vendor->cancel(chip); 99 chip->vendor->cancel(chip);
100 dev_err(&chip->pci_dev->dev, "Operation Timed out\n"); 100 dev_err(chip->dev, "Operation Timed out\n");
101 rc = -ETIME; 101 rc = -ETIME;
102 goto out; 102 goto out;
103 103
104out_recv: 104out_recv:
105 rc = chip->vendor->recv(chip, (u8 *) buf, bufsiz); 105 rc = chip->vendor->recv(chip, (u8 *) buf, bufsiz);
106 if (rc < 0) 106 if (rc < 0)
107 dev_err(&chip->pci_dev->dev, 107 dev_err(chip->dev,
108 "tpm_transmit: tpm_recv: error %zd\n", rc); 108 "tpm_transmit: tpm_recv: error %zd\n", rc);
109out: 109out:
110 up(&chip->tpm_mutex); 110 up(&chip->tpm_mutex);
@@ -139,15 +139,14 @@ ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr,
139 __be32 index; 139 __be32 index;
140 char *str = buf; 140 char *str = buf;
141 141
142 struct tpm_chip *chip = 142 struct tpm_chip *chip = dev_get_drvdata(dev);
143 pci_get_drvdata(to_pci_dev(dev));
144 if (chip == NULL) 143 if (chip == NULL)
145 return -ENODEV; 144 return -ENODEV;
146 145
147 memcpy(data, cap_pcr, sizeof(cap_pcr)); 146 memcpy(data, cap_pcr, sizeof(cap_pcr));
148 if ((len = tpm_transmit(chip, data, sizeof(data))) 147 if ((len = tpm_transmit(chip, data, sizeof(data)))
149 < CAP_PCR_RESULT_SIZE) { 148 < CAP_PCR_RESULT_SIZE) {
150 dev_dbg(&chip->pci_dev->dev, "A TPM error (%d) occurred " 149 dev_dbg(chip->dev, "A TPM error (%d) occurred "
151 "attempting to determine the number of PCRS\n", 150 "attempting to determine the number of PCRS\n",
152 be32_to_cpu(*((__be32 *) (data + 6)))); 151 be32_to_cpu(*((__be32 *) (data + 6))));
153 return 0; 152 return 0;
@@ -161,9 +160,10 @@ ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr,
161 memcpy(data + 10, &index, 4); 160 memcpy(data + 10, &index, 4);
162 if ((len = tpm_transmit(chip, data, sizeof(data))) 161 if ((len = tpm_transmit(chip, data, sizeof(data)))
163 < READ_PCR_RESULT_SIZE){ 162 < READ_PCR_RESULT_SIZE){
164 dev_dbg(&chip->pci_dev->dev, "A TPM error (%d) occurred" 163 dev_dbg(chip->dev, "A TPM error (%d) occurred"
165 " attempting to read PCR %d of %d\n", 164 " attempting to read PCR %d of %d\n",
166 be32_to_cpu(*((__be32 *) (data + 6))), i, num_pcrs); 165 be32_to_cpu(*((__be32 *) (data + 6))),
166 i, num_pcrs);
167 goto out; 167 goto out;
168 } 168 }
169 str += sprintf(str, "PCR-%02d: ", i); 169 str += sprintf(str, "PCR-%02d: ", i);
@@ -191,21 +191,19 @@ ssize_t tpm_show_pubek(struct device *dev, struct device_attribute *attr,
191 int i, rc; 191 int i, rc;
192 char *str = buf; 192 char *str = buf;
193 193
194 struct tpm_chip *chip = 194 struct tpm_chip *chip = dev_get_drvdata(dev);
195 pci_get_drvdata(to_pci_dev(dev));
196 if (chip == NULL) 195 if (chip == NULL)
197 return -ENODEV; 196 return -ENODEV;
198 197
199 data = kmalloc(READ_PUBEK_RESULT_SIZE, GFP_KERNEL); 198 data = kzalloc(READ_PUBEK_RESULT_SIZE, GFP_KERNEL);
200 if (!data) 199 if (!data)
201 return -ENOMEM; 200 return -ENOMEM;
202 201
203 memcpy(data, readpubek, sizeof(readpubek)); 202 memcpy(data, readpubek, sizeof(readpubek));
204 memset(data + sizeof(readpubek), 0, 20); /* zero nonce */
205 203
206 if ((len = tpm_transmit(chip, data, READ_PUBEK_RESULT_SIZE)) < 204 if ((len = tpm_transmit(chip, data, READ_PUBEK_RESULT_SIZE)) <
207 READ_PUBEK_RESULT_SIZE) { 205 READ_PUBEK_RESULT_SIZE) {
208 dev_dbg(&chip->pci_dev->dev, "A TPM error (%d) occurred " 206 dev_dbg(chip->dev, "A TPM error (%d) occurred "
209 "attempting to read the PUBEK\n", 207 "attempting to read the PUBEK\n",
210 be32_to_cpu(*((__be32 *) (data + 6)))); 208 be32_to_cpu(*((__be32 *) (data + 6))));
211 rc = 0; 209 rc = 0;
@@ -245,7 +243,6 @@ out:
245 kfree(data); 243 kfree(data);
246 return rc; 244 return rc;
247} 245}
248
249EXPORT_SYMBOL_GPL(tpm_show_pubek); 246EXPORT_SYMBOL_GPL(tpm_show_pubek);
250 247
251#define CAP_VER_RESULT_SIZE 18 248#define CAP_VER_RESULT_SIZE 18
@@ -274,8 +271,7 @@ ssize_t tpm_show_caps(struct device *dev, struct device_attribute *attr,
274 ssize_t len; 271 ssize_t len;
275 char *str = buf; 272 char *str = buf;
276 273
277 struct tpm_chip *chip = 274 struct tpm_chip *chip = dev_get_drvdata(dev);
278 pci_get_drvdata(to_pci_dev(dev));
279 if (chip == NULL) 275 if (chip == NULL)
280 return -ENODEV; 276 return -ENODEV;
281 277
@@ -315,7 +311,6 @@ ssize_t tpm_store_cancel(struct device *dev, struct device_attribute *attr,
315} 311}
316EXPORT_SYMBOL_GPL(tpm_store_cancel); 312EXPORT_SYMBOL_GPL(tpm_store_cancel);
317 313
318
319/* 314/*
320 * Device file system interface to the TPM 315 * Device file system interface to the TPM
321 */ 316 */
@@ -339,21 +334,20 @@ int tpm_open(struct inode *inode, struct file *file)
339 } 334 }
340 335
341 if (chip->num_opens) { 336 if (chip->num_opens) {
342 dev_dbg(&chip->pci_dev->dev, 337 dev_dbg(chip->dev, "Another process owns this TPM\n");
343 "Another process owns this TPM\n");
344 rc = -EBUSY; 338 rc = -EBUSY;
345 goto err_out; 339 goto err_out;
346 } 340 }
347 341
348 chip->num_opens++; 342 chip->num_opens++;
349 pci_dev_get(chip->pci_dev); 343 get_device(chip->dev);
350 344
351 spin_unlock(&driver_lock); 345 spin_unlock(&driver_lock);
352 346
353 chip->data_buffer = kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL); 347 chip->data_buffer = kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL);
354 if (chip->data_buffer == NULL) { 348 if (chip->data_buffer == NULL) {
355 chip->num_opens--; 349 chip->num_opens--;
356 pci_dev_put(chip->pci_dev); 350 put_device(chip->dev);
357 return -ENOMEM; 351 return -ENOMEM;
358 } 352 }
359 353
@@ -366,7 +360,6 @@ err_out:
366 spin_unlock(&driver_lock); 360 spin_unlock(&driver_lock);
367 return rc; 361 return rc;
368} 362}
369
370EXPORT_SYMBOL_GPL(tpm_open); 363EXPORT_SYMBOL_GPL(tpm_open);
371 364
372int tpm_release(struct inode *inode, struct file *file) 365int tpm_release(struct inode *inode, struct file *file)
@@ -378,15 +371,14 @@ int tpm_release(struct inode *inode, struct file *file)
378 chip->num_opens--; 371 chip->num_opens--;
379 del_singleshot_timer_sync(&chip->user_read_timer); 372 del_singleshot_timer_sync(&chip->user_read_timer);
380 atomic_set(&chip->data_pending, 0); 373 atomic_set(&chip->data_pending, 0);
381 pci_dev_put(chip->pci_dev); 374 put_device(chip->dev);
382 kfree(chip->data_buffer); 375 kfree(chip->data_buffer);
383 spin_unlock(&driver_lock); 376 spin_unlock(&driver_lock);
384 return 0; 377 return 0;
385} 378}
386
387EXPORT_SYMBOL_GPL(tpm_release); 379EXPORT_SYMBOL_GPL(tpm_release);
388 380
389ssize_t tpm_write(struct file * file, const char __user * buf, 381ssize_t tpm_write(struct file *file, const char __user *buf,
390 size_t size, loff_t * off) 382 size_t size, loff_t * off)
391{ 383{
392 struct tpm_chip *chip = file->private_data; 384 struct tpm_chip *chip = file->private_data;
@@ -422,7 +414,7 @@ ssize_t tpm_write(struct file * file, const char __user * buf,
422 414
423EXPORT_SYMBOL_GPL(tpm_write); 415EXPORT_SYMBOL_GPL(tpm_write);
424 416
425ssize_t tpm_read(struct file * file, char __user * buf, 417ssize_t tpm_read(struct file * file, char __user *buf,
426 size_t size, loff_t * off) 418 size_t size, loff_t * off)
427{ 419{
428 struct tpm_chip *chip = file->private_data; 420 struct tpm_chip *chip = file->private_data;
@@ -444,15 +436,14 @@ ssize_t tpm_read(struct file * file, char __user * buf,
444 436
445 return ret_size; 437 return ret_size;
446} 438}
447
448EXPORT_SYMBOL_GPL(tpm_read); 439EXPORT_SYMBOL_GPL(tpm_read);
449 440
450void __devexit tpm_remove(struct pci_dev *pci_dev) 441void tpm_remove_hardware(struct device *dev)
451{ 442{
452 struct tpm_chip *chip = pci_get_drvdata(pci_dev); 443 struct tpm_chip *chip = dev_get_drvdata(dev);
453 444
454 if (chip == NULL) { 445 if (chip == NULL) {
455 dev_err(&pci_dev->dev, "No device data found\n"); 446 dev_err(dev, "No device data found\n");
456 return; 447 return;
457 } 448 }
458 449
@@ -462,22 +453,20 @@ void __devexit tpm_remove(struct pci_dev *pci_dev)
462 453
463 spin_unlock(&driver_lock); 454 spin_unlock(&driver_lock);
464 455
465 pci_set_drvdata(pci_dev, NULL); 456 dev_set_drvdata(dev, NULL);
466 misc_deregister(&chip->vendor->miscdev); 457 misc_deregister(&chip->vendor->miscdev);
467 kfree(chip->vendor->miscdev.name); 458 kfree(chip->vendor->miscdev.name);
468 459
469 sysfs_remove_group(&pci_dev->dev.kobj, chip->vendor->attr_group); 460 sysfs_remove_group(&dev->kobj, chip->vendor->attr_group);
470 461
471 pci_disable_device(pci_dev); 462 dev_mask[chip->dev_num / TPM_NUM_MASK_ENTRIES ] &=
472 463 !(1 << (chip->dev_num % TPM_NUM_MASK_ENTRIES));
473 dev_mask[chip->dev_num / TPM_NUM_MASK_ENTRIES ] &= !(1 << (chip->dev_num % TPM_NUM_MASK_ENTRIES));
474 464
475 kfree(chip); 465 kfree(chip);
476 466
477 pci_dev_put(pci_dev); 467 put_device(dev);
478} 468}
479 469EXPORT_SYMBOL_GPL(tpm_remove_hardware);
480EXPORT_SYMBOL_GPL(tpm_remove);
481 470
482static u8 savestate[] = { 471static u8 savestate[] = {
483 0, 193, /* TPM_TAG_RQU_COMMAND */ 472 0, 193, /* TPM_TAG_RQU_COMMAND */
@@ -489,32 +478,30 @@ static u8 savestate[] = {
489 * We are about to suspend. Save the TPM state 478 * We are about to suspend. Save the TPM state
490 * so that it can be restored. 479 * so that it can be restored.
491 */ 480 */
492int tpm_pm_suspend(struct pci_dev *pci_dev, pm_message_t pm_state) 481int tpm_pm_suspend(struct device *dev, pm_message_t pm_state)
493{ 482{
494 struct tpm_chip *chip = pci_get_drvdata(pci_dev); 483 struct tpm_chip *chip = dev_get_drvdata(dev);
495 if (chip == NULL) 484 if (chip == NULL)
496 return -ENODEV; 485 return -ENODEV;
497 486
498 tpm_transmit(chip, savestate, sizeof(savestate)); 487 tpm_transmit(chip, savestate, sizeof(savestate));
499 return 0; 488 return 0;
500} 489}
501
502EXPORT_SYMBOL_GPL(tpm_pm_suspend); 490EXPORT_SYMBOL_GPL(tpm_pm_suspend);
503 491
504/* 492/*
505 * Resume from a power safe. The BIOS already restored 493 * Resume from a power safe. The BIOS already restored
506 * the TPM state. 494 * the TPM state.
507 */ 495 */
508int tpm_pm_resume(struct pci_dev *pci_dev) 496int tpm_pm_resume(struct device *dev)
509{ 497{
510 struct tpm_chip *chip = pci_get_drvdata(pci_dev); 498 struct tpm_chip *chip = dev_get_drvdata(dev);
511 499
512 if (chip == NULL) 500 if (chip == NULL)
513 return -ENODEV; 501 return -ENODEV;
514 502
515 return 0; 503 return 0;
516} 504}
517
518EXPORT_SYMBOL_GPL(tpm_pm_resume); 505EXPORT_SYMBOL_GPL(tpm_pm_resume);
519 506
520/* 507/*
@@ -524,8 +511,7 @@ EXPORT_SYMBOL_GPL(tpm_pm_resume);
524 * upon errant exit from this function specific probe function should call 511 * upon errant exit from this function specific probe function should call
525 * pci_disable_device 512 * pci_disable_device
526 */ 513 */
527int tpm_register_hardware(struct pci_dev *pci_dev, 514int tpm_register_hardware(struct device *dev, struct tpm_vendor_specific *entry)
528 struct tpm_vendor_specific *entry)
529{ 515{
530#define DEVNAME_SIZE 7 516#define DEVNAME_SIZE 7
531 517
@@ -534,12 +520,10 @@ int tpm_register_hardware(struct pci_dev *pci_dev,
534 int i, j; 520 int i, j;
535 521
536 /* Driver specific per-device data */ 522 /* Driver specific per-device data */
537 chip = kmalloc(sizeof(*chip), GFP_KERNEL); 523 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
538 if (chip == NULL) 524 if (chip == NULL)
539 return -ENOMEM; 525 return -ENOMEM;
540 526
541 memset(chip, 0, sizeof(struct tpm_chip));
542
543 init_MUTEX(&chip->buffer_mutex); 527 init_MUTEX(&chip->buffer_mutex);
544 init_MUTEX(&chip->tpm_mutex); 528 init_MUTEX(&chip->tpm_mutex);
545 INIT_LIST_HEAD(&chip->list); 529 INIT_LIST_HEAD(&chip->list);
@@ -563,8 +547,7 @@ int tpm_register_hardware(struct pci_dev *pci_dev,
563 547
564dev_num_search_complete: 548dev_num_search_complete:
565 if (chip->dev_num < 0) { 549 if (chip->dev_num < 0) {
566 dev_err(&pci_dev->dev, 550 dev_err(dev, "No available tpm device numbers\n");
567 "No available tpm device numbers\n");
568 kfree(chip); 551 kfree(chip);
569 return -ENODEV; 552 return -ENODEV;
570 } else if (chip->dev_num == 0) 553 } else if (chip->dev_num == 0)
@@ -576,15 +559,15 @@ dev_num_search_complete:
576 scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num); 559 scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num);
577 chip->vendor->miscdev.name = devname; 560 chip->vendor->miscdev.name = devname;
578 561
579 chip->vendor->miscdev.dev = &(pci_dev->dev); 562 chip->vendor->miscdev.dev = dev;
580 chip->pci_dev = pci_dev_get(pci_dev); 563 chip->dev = get_device(dev);
581 564
582 if (misc_register(&chip->vendor->miscdev)) { 565 if (misc_register(&chip->vendor->miscdev)) {
583 dev_err(&chip->pci_dev->dev, 566 dev_err(chip->dev,
584 "unable to misc_register %s, minor %d\n", 567 "unable to misc_register %s, minor %d\n",
585 chip->vendor->miscdev.name, 568 chip->vendor->miscdev.name,
586 chip->vendor->miscdev.minor); 569 chip->vendor->miscdev.minor);
587 pci_dev_put(pci_dev); 570 put_device(dev);
588 kfree(chip); 571 kfree(chip);
589 dev_mask[i] &= !(1 << j); 572 dev_mask[i] &= !(1 << j);
590 return -ENODEV; 573 return -ENODEV;
@@ -592,17 +575,16 @@ dev_num_search_complete:
592 575
593 spin_lock(&driver_lock); 576 spin_lock(&driver_lock);
594 577
595 pci_set_drvdata(pci_dev, chip); 578 dev_set_drvdata(dev, chip);
596 579
597 list_add(&chip->list, &tpm_chip_list); 580 list_add(&chip->list, &tpm_chip_list);
598 581
599 spin_unlock(&driver_lock); 582 spin_unlock(&driver_lock);
600 583
601 sysfs_create_group(&pci_dev->dev.kobj, chip->vendor->attr_group); 584 sysfs_create_group(&dev->kobj, chip->vendor->attr_group);
602 585
603 return 0; 586 return 0;
604} 587}
605
606EXPORT_SYMBOL_GPL(tpm_register_hardware); 588EXPORT_SYMBOL_GPL(tpm_register_hardware);
607 589
608MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)"); 590MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 373b41f6b460..024814b50c3c 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -55,12 +55,13 @@ struct tpm_vendor_specific {
55 int (*recv) (struct tpm_chip *, u8 *, size_t); 55 int (*recv) (struct tpm_chip *, u8 *, size_t);
56 int (*send) (struct tpm_chip *, u8 *, size_t); 56 int (*send) (struct tpm_chip *, u8 *, size_t);
57 void (*cancel) (struct tpm_chip *); 57 void (*cancel) (struct tpm_chip *);
58 u8 (*status) (struct tpm_chip *);
58 struct miscdevice miscdev; 59 struct miscdevice miscdev;
59 struct attribute_group *attr_group; 60 struct attribute_group *attr_group;
60}; 61};
61 62
62struct tpm_chip { 63struct tpm_chip {
63 struct pci_dev *pci_dev; /* PCI device stuff */ 64 struct device *dev; /* Device stuff */
64 65
65 int dev_num; /* /dev/tpm# */ 66 int dev_num; /* /dev/tpm# */
66 int num_opens; /* only one allowed */ 67 int num_opens; /* only one allowed */
@@ -91,13 +92,13 @@ static inline void tpm_write_index(int base, int index, int value)
91 outb(value & 0xFF, base+1); 92 outb(value & 0xFF, base+1);
92} 93}
93 94
94extern int tpm_register_hardware(struct pci_dev *, 95extern int tpm_register_hardware(struct device *,
95 struct tpm_vendor_specific *); 96 struct tpm_vendor_specific *);
96extern int tpm_open(struct inode *, struct file *); 97extern int tpm_open(struct inode *, struct file *);
97extern int tpm_release(struct inode *, struct file *); 98extern int tpm_release(struct inode *, struct file *);
98extern ssize_t tpm_write(struct file *, const char __user *, size_t, 99extern ssize_t tpm_write(struct file *, const char __user *, size_t,
99 loff_t *); 100 loff_t *);
100extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *); 101extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *);
101extern void __devexit tpm_remove(struct pci_dev *); 102extern void tpm_remove_hardware(struct device *);
102extern int tpm_pm_suspend(struct pci_dev *, pm_message_t); 103extern int tpm_pm_suspend(struct device *, pm_message_t);
103extern int tpm_pm_resume(struct pci_dev *); 104extern int tpm_pm_resume(struct device *);
diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c
index c0d64914595f..8cb42e84723c 100644
--- a/drivers/char/tpm/tpm_atmel.c
+++ b/drivers/char/tpm/tpm_atmel.c
@@ -40,7 +40,7 @@ enum tpm_atmel_read_status {
40 ATML_STATUS_READY = 0x08 40 ATML_STATUS_READY = 0x08
41}; 41};
42 42
43static int tpm_atml_recv(struct tpm_chip *chip, u8 * buf, size_t count) 43static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
44{ 44{
45 u8 status, *hdr = buf; 45 u8 status, *hdr = buf;
46 u32 size; 46 u32 size;
@@ -54,7 +54,7 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 * buf, size_t count)
54 for (i = 0; i < 6; i++) { 54 for (i = 0; i < 6; i++) {
55 status = inb(chip->vendor->base + 1); 55 status = inb(chip->vendor->base + 1);
56 if ((status & ATML_STATUS_DATA_AVAIL) == 0) { 56 if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
57 dev_err(&chip->pci_dev->dev, 57 dev_err(chip->dev,
58 "error reading header\n"); 58 "error reading header\n");
59 return -EIO; 59 return -EIO;
60 } 60 }
@@ -66,12 +66,12 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 * buf, size_t count)
66 size = be32_to_cpu(*native_size); 66 size = be32_to_cpu(*native_size);
67 67
68 if (count < size) { 68 if (count < size) {
69 dev_err(&chip->pci_dev->dev, 69 dev_err(chip->dev,
70 "Recv size(%d) less than available space\n", size); 70 "Recv size(%d) less than available space\n", size);
71 for (; i < size; i++) { /* clear the waiting data anyway */ 71 for (; i < size; i++) { /* clear the waiting data anyway */
72 status = inb(chip->vendor->base + 1); 72 status = inb(chip->vendor->base + 1);
73 if ((status & ATML_STATUS_DATA_AVAIL) == 0) { 73 if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
74 dev_err(&chip->pci_dev->dev, 74 dev_err(chip->dev,
75 "error reading data\n"); 75 "error reading data\n");
76 return -EIO; 76 return -EIO;
77 } 77 }
@@ -83,7 +83,7 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 * buf, size_t count)
83 for (; i < size; i++) { 83 for (; i < size; i++) {
84 status = inb(chip->vendor->base + 1); 84 status = inb(chip->vendor->base + 1);
85 if ((status & ATML_STATUS_DATA_AVAIL) == 0) { 85 if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
86 dev_err(&chip->pci_dev->dev, 86 dev_err(chip->dev,
87 "error reading data\n"); 87 "error reading data\n");
88 return -EIO; 88 return -EIO;
89 } 89 }
@@ -93,20 +93,20 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 * buf, size_t count)
93 /* make sure data available is gone */ 93 /* make sure data available is gone */
94 status = inb(chip->vendor->base + 1); 94 status = inb(chip->vendor->base + 1);
95 if (status & ATML_STATUS_DATA_AVAIL) { 95 if (status & ATML_STATUS_DATA_AVAIL) {
96 dev_err(&chip->pci_dev->dev, "data available is stuck\n"); 96 dev_err(chip->dev, "data available is stuck\n");
97 return -EIO; 97 return -EIO;
98 } 98 }
99 99
100 return size; 100 return size;
101} 101}
102 102
103static int tpm_atml_send(struct tpm_chip *chip, u8 * buf, size_t count) 103static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t count)
104{ 104{
105 int i; 105 int i;
106 106
107 dev_dbg(&chip->pci_dev->dev, "tpm_atml_send: "); 107 dev_dbg(chip->dev, "tpm_atml_send:\n");
108 for (i = 0; i < count; i++) { 108 for (i = 0; i < count; i++) {
109 dev_dbg(&chip->pci_dev->dev, "0x%x(%d) ", buf[i], buf[i]); 109 dev_dbg(chip->dev, "%d 0x%x(%d)\n", i, buf[i], buf[i]);
110 outb(buf[i], chip->vendor->base); 110 outb(buf[i], chip->vendor->base);
111 } 111 }
112 112
@@ -118,6 +118,11 @@ static void tpm_atml_cancel(struct tpm_chip *chip)
118 outb(ATML_STATUS_ABORT, chip->vendor->base + 1); 118 outb(ATML_STATUS_ABORT, chip->vendor->base + 1);
119} 119}
120 120
121static u8 tpm_atml_status(struct tpm_chip *chip)
122{
123 return inb(chip->vendor->base + 1);
124}
125
121static struct file_operations atmel_ops = { 126static struct file_operations atmel_ops = {
122 .owner = THIS_MODULE, 127 .owner = THIS_MODULE,
123 .llseek = no_llseek, 128 .llseek = no_llseek,
@@ -137,7 +142,7 @@ static struct attribute* atmel_attrs[] = {
137 &dev_attr_pcrs.attr, 142 &dev_attr_pcrs.attr,
138 &dev_attr_caps.attr, 143 &dev_attr_caps.attr,
139 &dev_attr_cancel.attr, 144 &dev_attr_cancel.attr,
140 0, 145 NULL,
141}; 146};
142 147
143static struct attribute_group atmel_attr_grp = { .attrs = atmel_attrs }; 148static struct attribute_group atmel_attr_grp = { .attrs = atmel_attrs };
@@ -146,6 +151,7 @@ static struct tpm_vendor_specific tpm_atmel = {
146 .recv = tpm_atml_recv, 151 .recv = tpm_atml_recv,
147 .send = tpm_atml_send, 152 .send = tpm_atml_send,
148 .cancel = tpm_atml_cancel, 153 .cancel = tpm_atml_cancel,
154 .status = tpm_atml_status,
149 .req_complete_mask = ATML_STATUS_BUSY | ATML_STATUS_DATA_AVAIL, 155 .req_complete_mask = ATML_STATUS_BUSY | ATML_STATUS_DATA_AVAIL,
150 .req_complete_val = ATML_STATUS_DATA_AVAIL, 156 .req_complete_val = ATML_STATUS_DATA_AVAIL,
151 .req_canceled = ATML_STATUS_READY, 157 .req_canceled = ATML_STATUS_READY,
@@ -153,86 +159,94 @@ static struct tpm_vendor_specific tpm_atmel = {
153 .miscdev = { .fops = &atmel_ops, }, 159 .miscdev = { .fops = &atmel_ops, },
154}; 160};
155 161
156static int __devinit tpm_atml_init(struct pci_dev *pci_dev, 162static struct platform_device *pdev;
157 const struct pci_device_id *pci_id) 163
164static void __devexit tpm_atml_remove(struct device *dev)
165{
166 struct tpm_chip *chip = dev_get_drvdata(dev);
167 if (chip) {
168 release_region(chip->vendor->base, 2);
169 tpm_remove_hardware(chip->dev);
170 }
171}
172
173static struct device_driver atml_drv = {
174 .name = "tpm_atmel",
175 .bus = &platform_bus_type,
176 .owner = THIS_MODULE,
177 .suspend = tpm_pm_suspend,
178 .resume = tpm_pm_resume,
179};
180
181static int __init init_atmel(void)
158{ 182{
159 u8 version[4];
160 int rc = 0; 183 int rc = 0;
161 int lo, hi; 184 int lo, hi;
162 185
163 if (pci_enable_device(pci_dev)) 186 driver_register(&atml_drv);
164 return -EIO;
165 187
166 lo = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_LO); 188 lo = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_LO);
167 hi = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_HI); 189 hi = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_HI);
168 190
169 tpm_atmel.base = (hi<<8)|lo; 191 tpm_atmel.base = (hi<<8)|lo;
170 dev_dbg( &pci_dev->dev, "Operating with base: 0x%x\n", tpm_atmel.base);
171 192
172 /* verify that it is an Atmel part */ 193 /* verify that it is an Atmel part */
173 if (tpm_read_index(TPM_ADDR, 4) != 'A' || tpm_read_index(TPM_ADDR, 5) != 'T' 194 if (tpm_read_index(TPM_ADDR, 4) != 'A' || tpm_read_index(TPM_ADDR, 5) != 'T'
174 || tpm_read_index(TPM_ADDR, 6) != 'M' || tpm_read_index(TPM_ADDR, 7) != 'L') { 195 || tpm_read_index(TPM_ADDR, 6) != 'M' || tpm_read_index(TPM_ADDR, 7) != 'L') {
175 rc = -ENODEV; 196 return -ENODEV;
176 goto out_err;
177 } 197 }
178 198
179 /* query chip for its version number */ 199 /* verify chip version number is 1.1 */
180 if ((version[0] = tpm_read_index(TPM_ADDR, 0x00)) != 0xFF) { 200 if ( (tpm_read_index(TPM_ADDR, 0x00) != 0x01) ||
181 version[1] = tpm_read_index(TPM_ADDR, 0x01); 201 (tpm_read_index(TPM_ADDR, 0x01) != 0x01 ))
182 version[2] = tpm_read_index(TPM_ADDR, 0x02); 202 return -ENODEV;
183 version[3] = tpm_read_index(TPM_ADDR, 0x03); 203
184 } else { 204 pdev = kzalloc(sizeof(struct platform_device), GFP_KERNEL);
185 dev_info(&pci_dev->dev, "version query failed\n"); 205 if ( !pdev )
186 rc = -ENODEV; 206 return -ENOMEM;
187 goto out_err; 207
208 pdev->name = "tpm_atmel0";
209 pdev->id = -1;
210 pdev->num_resources = 0;
211 pdev->dev.release = tpm_atml_remove;
212 pdev->dev.driver = &atml_drv;
213
214 if ((rc = platform_device_register(pdev)) < 0) {
215 kfree(pdev);
216 pdev = NULL;
217 return rc;
188 } 218 }
189 219
190 if ((rc = tpm_register_hardware(pci_dev, &tpm_atmel)) < 0) 220 if (request_region(tpm_atmel.base, 2, "tpm_atmel0") == NULL ) {
191 goto out_err; 221 platform_device_unregister(pdev);
222 kfree(pdev);
223 pdev = NULL;
224 return -EBUSY;
225 }
192 226
193 dev_info(&pci_dev->dev, 227 if ((rc = tpm_register_hardware(&pdev->dev, &tpm_atmel)) < 0) {
194 "Atmel TPM version %d.%d.%d.%d\n", version[0], version[1], 228 release_region(tpm_atmel.base, 2);
195 version[2], version[3]); 229 platform_device_unregister(pdev);
230 kfree(pdev);
231 pdev = NULL;
232 return rc;
233 }
196 234
235 dev_info(&pdev->dev, "Atmel TPM 1.1, Base Address: 0x%x\n",
236 tpm_atmel.base);
197 return 0; 237 return 0;
198out_err:
199 pci_disable_device(pci_dev);
200 return rc;
201}
202
203static struct pci_device_id tpm_pci_tbl[] __devinitdata = {
204 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0)},
205 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12)},
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)},
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)},
212 {PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_LPC)},
213 {PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6LPC)},
214 {0,}
215};
216
217MODULE_DEVICE_TABLE(pci, tpm_pci_tbl);
218
219static struct pci_driver atmel_pci_driver = {
220 .name = "tpm_atmel",
221 .id_table = tpm_pci_tbl,
222 .probe = tpm_atml_init,
223 .remove = __devexit_p(tpm_remove),
224 .suspend = tpm_pm_suspend,
225 .resume = tpm_pm_resume,
226};
227
228static int __init init_atmel(void)
229{
230 return pci_register_driver(&atmel_pci_driver);
231} 238}
232 239
233static void __exit cleanup_atmel(void) 240static void __exit cleanup_atmel(void)
234{ 241{
235 pci_unregister_driver(&atmel_pci_driver); 242 if (pdev) {
243 tpm_atml_remove(&pdev->dev);
244 platform_device_unregister(pdev);
245 kfree(pdev);
246 pdev = NULL;
247 }
248
249 driver_unregister(&atml_drv);
236} 250}
237 251
238module_init(init_atmel); 252module_init(init_atmel);
diff --git a/drivers/char/tpm/tpm_infineon.c b/drivers/char/tpm/tpm_infineon.c
index 939e51e119e6..8198dbb7370f 100644
--- a/drivers/char/tpm/tpm_infineon.c
+++ b/drivers/char/tpm/tpm_infineon.c
@@ -5,6 +5,7 @@
5 * Specifications at www.trustedcomputinggroup.org 5 * Specifications at www.trustedcomputinggroup.org
6 * 6 *
7 * Copyright (C) 2005, Marcel Selhorst <selhorst@crypto.rub.de> 7 * Copyright (C) 2005, Marcel Selhorst <selhorst@crypto.rub.de>
8 * Sirrix AG - security technologies, http://www.sirrix.com and
8 * Applied Data Security Group, Ruhr-University Bochum, Germany 9 * Applied Data Security Group, Ruhr-University Bochum, Germany
9 * Project-Homepage: http://www.prosec.rub.de/tpm 10 * Project-Homepage: http://www.prosec.rub.de/tpm
10 * 11 *
@@ -29,9 +30,10 @@
29#define TPM_INFINEON_DEV_VEN_VALUE 0x15D1 30#define TPM_INFINEON_DEV_VEN_VALUE 0x15D1
30 31
31/* These values will be filled after PnP-call */ 32/* These values will be filled after PnP-call */
32static int TPM_INF_DATA = 0; 33static int TPM_INF_DATA;
33static int TPM_INF_ADDR = 0; 34static int TPM_INF_ADDR;
34static int pnp_registered = 0; 35static int TPM_INF_BASE;
36static int TPM_INF_PORT_LEN;
35 37
36/* TPM header definitions */ 38/* TPM header definitions */
37enum infineon_tpm_header { 39enum infineon_tpm_header {
@@ -143,11 +145,9 @@ static int wait(struct tpm_chip *chip, int wait_for_bit)
143 } 145 }
144 if (i == TPM_MAX_TRIES) { /* timeout occurs */ 146 if (i == TPM_MAX_TRIES) { /* timeout occurs */
145 if (wait_for_bit == STAT_XFE) 147 if (wait_for_bit == STAT_XFE)
146 dev_err(&chip->pci_dev->dev, 148 dev_err(chip->dev, "Timeout in wait(STAT_XFE)\n");
147 "Timeout in wait(STAT_XFE)\n");
148 if (wait_for_bit == STAT_RDA) 149 if (wait_for_bit == STAT_RDA)
149 dev_err(&chip->pci_dev->dev, 150 dev_err(chip->dev, "Timeout in wait(STAT_RDA)\n");
150 "Timeout in wait(STAT_RDA)\n");
151 return -EIO; 151 return -EIO;
152 } 152 }
153 return 0; 153 return 0;
@@ -170,7 +170,7 @@ static void wait_and_send(struct tpm_chip *chip, u8 sendbyte)
170static void tpm_wtx(struct tpm_chip *chip) 170static void tpm_wtx(struct tpm_chip *chip)
171{ 171{
172 number_of_wtx++; 172 number_of_wtx++;
173 dev_info(&chip->pci_dev->dev, "Granting WTX (%02d / %02d)\n", 173 dev_info(chip->dev, "Granting WTX (%02d / %02d)\n",
174 number_of_wtx, TPM_MAX_WTX_PACKAGES); 174 number_of_wtx, TPM_MAX_WTX_PACKAGES);
175 wait_and_send(chip, TPM_VL_VER); 175 wait_and_send(chip, TPM_VL_VER);
176 wait_and_send(chip, TPM_CTRL_WTX); 176 wait_and_send(chip, TPM_CTRL_WTX);
@@ -181,7 +181,7 @@ static void tpm_wtx(struct tpm_chip *chip)
181 181
182static void tpm_wtx_abort(struct tpm_chip *chip) 182static void tpm_wtx_abort(struct tpm_chip *chip)
183{ 183{
184 dev_info(&chip->pci_dev->dev, "Aborting WTX\n"); 184 dev_info(chip->dev, "Aborting WTX\n");
185 wait_and_send(chip, TPM_VL_VER); 185 wait_and_send(chip, TPM_VL_VER);
186 wait_and_send(chip, TPM_CTRL_WTX_ABORT); 186 wait_and_send(chip, TPM_CTRL_WTX_ABORT);
187 wait_and_send(chip, 0x00); 187 wait_and_send(chip, 0x00);
@@ -206,7 +206,7 @@ recv_begin:
206 } 206 }
207 207
208 if (buf[0] != TPM_VL_VER) { 208 if (buf[0] != TPM_VL_VER) {
209 dev_err(&chip->pci_dev->dev, 209 dev_err(chip->dev,
210 "Wrong transport protocol implementation!\n"); 210 "Wrong transport protocol implementation!\n");
211 return -EIO; 211 return -EIO;
212 } 212 }
@@ -221,8 +221,7 @@ recv_begin:
221 } 221 }
222 222
223 if ((size == 0x6D00) && (buf[1] == 0x80)) { 223 if ((size == 0x6D00) && (buf[1] == 0x80)) {
224 dev_err(&chip->pci_dev->dev, 224 dev_err(chip->dev, "Error handling on vendor layer!\n");
225 "Error handling on vendor layer!\n");
226 return -EIO; 225 return -EIO;
227 } 226 }
228 227
@@ -234,7 +233,7 @@ recv_begin:
234 } 233 }
235 234
236 if (buf[1] == TPM_CTRL_WTX) { 235 if (buf[1] == TPM_CTRL_WTX) {
237 dev_info(&chip->pci_dev->dev, "WTX-package received\n"); 236 dev_info(chip->dev, "WTX-package received\n");
238 if (number_of_wtx < TPM_MAX_WTX_PACKAGES) { 237 if (number_of_wtx < TPM_MAX_WTX_PACKAGES) {
239 tpm_wtx(chip); 238 tpm_wtx(chip);
240 goto recv_begin; 239 goto recv_begin;
@@ -245,14 +244,14 @@ recv_begin:
245 } 244 }
246 245
247 if (buf[1] == TPM_CTRL_WTX_ABORT_ACK) { 246 if (buf[1] == TPM_CTRL_WTX_ABORT_ACK) {
248 dev_info(&chip->pci_dev->dev, "WTX-abort acknowledged\n"); 247 dev_info(chip->dev, "WTX-abort acknowledged\n");
249 return size; 248 return size;
250 } 249 }
251 250
252 if (buf[1] == TPM_CTRL_ERROR) { 251 if (buf[1] == TPM_CTRL_ERROR) {
253 dev_err(&chip->pci_dev->dev, "ERROR-package received:\n"); 252 dev_err(chip->dev, "ERROR-package received:\n");
254 if (buf[4] == TPM_INF_NAK) 253 if (buf[4] == TPM_INF_NAK)
255 dev_err(&chip->pci_dev->dev, 254 dev_err(chip->dev,
256 "-> Negative acknowledgement" 255 "-> Negative acknowledgement"
257 " - retransmit command!\n"); 256 " - retransmit command!\n");
258 return -EIO; 257 return -EIO;
@@ -271,7 +270,7 @@ static int tpm_inf_send(struct tpm_chip *chip, u8 * buf, size_t count)
271 270
272 ret = empty_fifo(chip, 1); 271 ret = empty_fifo(chip, 1);
273 if (ret) { 272 if (ret) {
274 dev_err(&chip->pci_dev->dev, "Timeout while clearing FIFO\n"); 273 dev_err(chip->dev, "Timeout while clearing FIFO\n");
275 return -EIO; 274 return -EIO;
276 } 275 }
277 276
@@ -316,6 +315,11 @@ static void tpm_inf_cancel(struct tpm_chip *chip)
316 */ 315 */
317} 316}
318 317
318static u8 tpm_inf_status(struct tpm_chip *chip)
319{
320 return inb(chip->vendor->base + STAT);
321}
322
319static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL); 323static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
320static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL); 324static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
321static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps, NULL); 325static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps, NULL);
@@ -344,6 +348,7 @@ static struct tpm_vendor_specific tpm_inf = {
344 .recv = tpm_inf_recv, 348 .recv = tpm_inf_recv,
345 .send = tpm_inf_send, 349 .send = tpm_inf_send,
346 .cancel = tpm_inf_cancel, 350 .cancel = tpm_inf_cancel,
351 .status = tpm_inf_status,
347 .req_complete_mask = 0, 352 .req_complete_mask = 0,
348 .req_complete_val = 0, 353 .req_complete_val = 0,
349 .attr_group = &inf_attr_grp, 354 .attr_group = &inf_attr_grp,
@@ -356,30 +361,11 @@ static const struct pnp_device_id tpm_pnp_tbl[] = {
356 {"IFX0102", 0}, 361 {"IFX0102", 0},
357 {"", 0} 362 {"", 0}
358}; 363};
364
359MODULE_DEVICE_TABLE(pnp, tpm_pnp_tbl); 365MODULE_DEVICE_TABLE(pnp, tpm_pnp_tbl);
360 366
361static int __devinit tpm_inf_pnp_probe(struct pnp_dev *dev, 367static int __devinit tpm_inf_pnp_probe(struct pnp_dev *dev,
362 const struct pnp_device_id *dev_id) 368 const struct pnp_device_id *dev_id)
363{
364 if (pnp_port_valid(dev, 0)) {
365 TPM_INF_ADDR = (pnp_port_start(dev, 0) & 0xff);
366 TPM_INF_DATA = ((TPM_INF_ADDR + 1) & 0xff);
367 tpm_inf.base = pnp_port_start(dev, 1);
368 dev_info(&dev->dev, "Found %s with ID %s\n",
369 dev->name, dev_id->id);
370 return 0;
371 }
372 return -ENODEV;
373}
374
375static struct pnp_driver tpm_inf_pnp = {
376 .name = "tpm_inf_pnp",
377 .id_table = tpm_pnp_tbl,
378 .probe = tpm_inf_pnp_probe,
379};
380
381static int __devinit tpm_inf_probe(struct pci_dev *pci_dev,
382 const struct pci_device_id *pci_id)
383{ 369{
384 int rc = 0; 370 int rc = 0;
385 u8 iol, ioh; 371 u8 iol, ioh;
@@ -388,30 +374,28 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev,
388 int productid[2]; 374 int productid[2];
389 char chipname[20]; 375 char chipname[20];
390 376
391 rc = pci_enable_device(pci_dev); 377 /* read IO-ports through PnP */
392 if (rc) 378 if (pnp_port_valid(dev, 0) && pnp_port_valid(dev, 1) &&
393 return rc; 379 !(pnp_port_flags(dev, 0) & IORESOURCE_DISABLED)) {
394 380 TPM_INF_ADDR = pnp_port_start(dev, 0);
395 dev_info(&pci_dev->dev, "LPC-bus found at 0x%x\n", pci_id->device); 381 TPM_INF_DATA = (TPM_INF_ADDR + 1);
396 382 TPM_INF_BASE = pnp_port_start(dev, 1);
397 /* read IO-ports from PnP */ 383 TPM_INF_PORT_LEN = pnp_port_len(dev, 1);
398 rc = pnp_register_driver(&tpm_inf_pnp); 384 if (!TPM_INF_PORT_LEN)
399 if (rc < 0) { 385 return -EINVAL;
400 dev_err(&pci_dev->dev, 386 dev_info(&dev->dev, "Found %s with ID %s\n",
401 "Error %x from pnp_register_driver!\n",rc); 387 dev->name, dev_id->id);
402 goto error2; 388 if (!((TPM_INF_BASE >> 8) & 0xff))
403 } 389 return -EINVAL;
404 if (!rc) { 390 /* publish my base address and request region */
405 dev_info(&pci_dev->dev, "No Infineon TPM found!\n"); 391 tpm_inf.base = TPM_INF_BASE;
406 goto error; 392 if (request_region
393 (tpm_inf.base, TPM_INF_PORT_LEN, "tpm_infineon0") == NULL) {
394 release_region(tpm_inf.base, TPM_INF_PORT_LEN);
395 return -EINVAL;
396 }
407 } else { 397 } else {
408 pnp_registered = 1; 398 return -EINVAL;
409 }
410
411 /* Make sure, we have received valid config ports */
412 if (!TPM_INF_ADDR) {
413 dev_err(&pci_dev->dev, "No valid IO-ports received!\n");
414 goto error;
415 } 399 }
416 400
417 /* query chip for its vendor, its version number a.s.o. */ 401 /* query chip for its vendor, its version number a.s.o. */
@@ -443,10 +427,6 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev,
443 427
444 if ((vendorid[0] << 8 | vendorid[1]) == (TPM_INFINEON_DEV_VEN_VALUE)) { 428 if ((vendorid[0] << 8 | vendorid[1]) == (TPM_INFINEON_DEV_VEN_VALUE)) {
445 429
446 if (tpm_inf.base == 0) {
447 dev_err(&pci_dev->dev, "No IO-ports found!\n");
448 goto error;
449 }
450 /* configure TPM with IO-ports */ 430 /* configure TPM with IO-ports */
451 outb(IOLIMH, TPM_INF_ADDR); 431 outb(IOLIMH, TPM_INF_ADDR);
452 outb(((tpm_inf.base >> 8) & 0xff), TPM_INF_DATA); 432 outb(((tpm_inf.base >> 8) & 0xff), TPM_INF_DATA);
@@ -460,10 +440,11 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev,
460 iol = inb(TPM_INF_DATA); 440 iol = inb(TPM_INF_DATA);
461 441
462 if ((ioh << 8 | iol) != tpm_inf.base) { 442 if ((ioh << 8 | iol) != tpm_inf.base) {
463 dev_err(&pci_dev->dev, 443 dev_err(&dev->dev,
464 "Could not set IO-ports to %04x\n", 444 "Could not set IO-ports to %04x\n",
465 tpm_inf.base); 445 tpm_inf.base);
466 goto error; 446 release_region(tpm_inf.base, TPM_INF_PORT_LEN);
447 return -EIO;
467 } 448 }
468 449
469 /* activate register */ 450 /* activate register */
@@ -475,7 +456,7 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev,
475 outb(RESET_LP_IRQC_DISABLE, tpm_inf.base + CMD); 456 outb(RESET_LP_IRQC_DISABLE, tpm_inf.base + CMD);
476 457
477 /* Finally, we're done, print some infos */ 458 /* Finally, we're done, print some infos */
478 dev_info(&pci_dev->dev, "TPM found: " 459 dev_info(&dev->dev, "TPM found: "
479 "config base 0x%x, " 460 "config base 0x%x, "
480 "io base 0x%x, " 461 "io base 0x%x, "
481 "chip version %02x%02x, " 462 "chip version %02x%02x, "
@@ -483,59 +464,53 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev,
483 "product id %02x%02x" 464 "product id %02x%02x"
484 "%s\n", 465 "%s\n",
485 TPM_INF_ADDR, 466 TPM_INF_ADDR,
486 tpm_inf.base, 467 TPM_INF_BASE,
487 version[0], version[1], 468 version[0], version[1],
488 vendorid[0], vendorid[1], 469 vendorid[0], vendorid[1],
489 productid[0], productid[1], chipname); 470 productid[0], productid[1], chipname);
490 471
491 rc = tpm_register_hardware(pci_dev, &tpm_inf); 472 rc = tpm_register_hardware(&dev->dev, &tpm_inf);
492 if (rc < 0) 473 if (rc < 0) {
493 goto error; 474 release_region(tpm_inf.base, TPM_INF_PORT_LEN);
475 return -ENODEV;
476 }
494 return 0; 477 return 0;
495 } else { 478 } else {
496 dev_info(&pci_dev->dev, "No Infineon TPM found!\n"); 479 dev_info(&dev->dev, "No Infineon TPM found!\n");
497error:
498 pnp_unregister_driver(&tpm_inf_pnp);
499error2:
500 pci_disable_device(pci_dev);
501 pnp_registered = 0;
502 return -ENODEV; 480 return -ENODEV;
503 } 481 }
504} 482}
505 483
506static struct pci_device_id tpm_pci_tbl[] __devinitdata = { 484static __devexit void tpm_inf_pnp_remove(struct pnp_dev *dev)
507 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0)}, 485{
508 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12)}, 486 struct tpm_chip *chip = pnp_get_drvdata(dev);
509 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0)},
510 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12)},
511 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0)},
512 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0)},
513 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1)},
514 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_2)},
515 {0,}
516};
517 487
518MODULE_DEVICE_TABLE(pci, tpm_pci_tbl); 488 if (chip) {
489 release_region(chip->vendor->base, TPM_INF_PORT_LEN);
490 tpm_remove_hardware(chip->dev);
491 }
492}
519 493
520static struct pci_driver inf_pci_driver = { 494static struct pnp_driver tpm_inf_pnp = {
521 .name = "tpm_inf", 495 .name = "tpm_inf_pnp",
522 .id_table = tpm_pci_tbl, 496 .driver = {
523 .probe = tpm_inf_probe, 497 .owner = THIS_MODULE,
524 .remove = __devexit_p(tpm_remove), 498 .suspend = tpm_pm_suspend,
525 .suspend = tpm_pm_suspend, 499 .resume = tpm_pm_resume,
526 .resume = tpm_pm_resume, 500 },
501 .id_table = tpm_pnp_tbl,
502 .probe = tpm_inf_pnp_probe,
503 .remove = tpm_inf_pnp_remove,
527}; 504};
528 505
529static int __init init_inf(void) 506static int __init init_inf(void)
530{ 507{
531 return pci_register_driver(&inf_pci_driver); 508 return pnp_register_driver(&tpm_inf_pnp);
532} 509}
533 510
534static void __exit cleanup_inf(void) 511static void __exit cleanup_inf(void)
535{ 512{
536 if (pnp_registered) 513 pnp_unregister_driver(&tpm_inf_pnp);
537 pnp_unregister_driver(&tpm_inf_pnp);
538 pci_unregister_driver(&inf_pci_driver);
539} 514}
540 515
541module_init(init_inf); 516module_init(init_inf);
@@ -543,5 +518,5 @@ module_exit(cleanup_inf);
543 518
544MODULE_AUTHOR("Marcel Selhorst <selhorst@crypto.rub.de>"); 519MODULE_AUTHOR("Marcel Selhorst <selhorst@crypto.rub.de>");
545MODULE_DESCRIPTION("Driver for Infineon TPM SLD 9630 TT 1.1 / SLB 9635 TT 1.2"); 520MODULE_DESCRIPTION("Driver for Infineon TPM SLD 9630 TT 1.1 / SLB 9635 TT 1.2");
546MODULE_VERSION("1.5"); 521MODULE_VERSION("1.6");
547MODULE_LICENSE("GPL"); 522MODULE_LICENSE("GPL");
diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c
index b4127348c063..253871b5b1e2 100644
--- a/drivers/char/tpm/tpm_nsc.c
+++ b/drivers/char/tpm/tpm_nsc.c
@@ -111,7 +111,7 @@ static int nsc_wait_for_ready(struct tpm_chip *chip)
111 } 111 }
112 while (time_before(jiffies, stop)); 112 while (time_before(jiffies, stop));
113 113
114 dev_info(&chip->pci_dev->dev, "wait for ready failed\n"); 114 dev_info(chip->dev, "wait for ready failed\n");
115 return -EBUSY; 115 return -EBUSY;
116} 116}
117 117
@@ -127,12 +127,12 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
127 return -EIO; 127 return -EIO;
128 128
129 if (wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0) { 129 if (wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0) {
130 dev_err(&chip->pci_dev->dev, "F0 timeout\n"); 130 dev_err(chip->dev, "F0 timeout\n");
131 return -EIO; 131 return -EIO;
132 } 132 }
133 if ((data = 133 if ((data =
134 inb(chip->vendor->base + NSC_DATA)) != NSC_COMMAND_NORMAL) { 134 inb(chip->vendor->base + NSC_DATA)) != NSC_COMMAND_NORMAL) {
135 dev_err(&chip->pci_dev->dev, "not in normal mode (0x%x)\n", 135 dev_err(chip->dev, "not in normal mode (0x%x)\n",
136 data); 136 data);
137 return -EIO; 137 return -EIO;
138 } 138 }
@@ -141,7 +141,7 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
141 for (p = buffer; p < &buffer[count]; p++) { 141 for (p = buffer; p < &buffer[count]; p++) {
142 if (wait_for_stat 142 if (wait_for_stat
143 (chip, NSC_STATUS_OBF, NSC_STATUS_OBF, &data) < 0) { 143 (chip, NSC_STATUS_OBF, NSC_STATUS_OBF, &data) < 0) {
144 dev_err(&chip->pci_dev->dev, 144 dev_err(chip->dev,
145 "OBF timeout (while reading data)\n"); 145 "OBF timeout (while reading data)\n");
146 return -EIO; 146 return -EIO;
147 } 147 }
@@ -152,11 +152,11 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
152 152
153 if ((data & NSC_STATUS_F0) == 0 && 153 if ((data & NSC_STATUS_F0) == 0 &&
154 (wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0)) { 154 (wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0)) {
155 dev_err(&chip->pci_dev->dev, "F0 not set\n"); 155 dev_err(chip->dev, "F0 not set\n");
156 return -EIO; 156 return -EIO;
157 } 157 }
158 if ((data = inb(chip->vendor->base + NSC_DATA)) != NSC_COMMAND_EOC) { 158 if ((data = inb(chip->vendor->base + NSC_DATA)) != NSC_COMMAND_EOC) {
159 dev_err(&chip->pci_dev->dev, 159 dev_err(chip->dev,
160 "expected end of command(0x%x)\n", data); 160 "expected end of command(0x%x)\n", data);
161 return -EIO; 161 return -EIO;
162 } 162 }
@@ -187,19 +187,19 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
187 return -EIO; 187 return -EIO;
188 188
189 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) { 189 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
190 dev_err(&chip->pci_dev->dev, "IBF timeout\n"); 190 dev_err(chip->dev, "IBF timeout\n");
191 return -EIO; 191 return -EIO;
192 } 192 }
193 193
194 outb(NSC_COMMAND_NORMAL, chip->vendor->base + NSC_COMMAND); 194 outb(NSC_COMMAND_NORMAL, chip->vendor->base + NSC_COMMAND);
195 if (wait_for_stat(chip, NSC_STATUS_IBR, NSC_STATUS_IBR, &data) < 0) { 195 if (wait_for_stat(chip, NSC_STATUS_IBR, NSC_STATUS_IBR, &data) < 0) {
196 dev_err(&chip->pci_dev->dev, "IBR timeout\n"); 196 dev_err(chip->dev, "IBR timeout\n");
197 return -EIO; 197 return -EIO;
198 } 198 }
199 199
200 for (i = 0; i < count; i++) { 200 for (i = 0; i < count; i++) {
201 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) { 201 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
202 dev_err(&chip->pci_dev->dev, 202 dev_err(chip->dev,
203 "IBF timeout (while writing data)\n"); 203 "IBF timeout (while writing data)\n");
204 return -EIO; 204 return -EIO;
205 } 205 }
@@ -207,7 +207,7 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
207 } 207 }
208 208
209 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) { 209 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
210 dev_err(&chip->pci_dev->dev, "IBF timeout\n"); 210 dev_err(chip->dev, "IBF timeout\n");
211 return -EIO; 211 return -EIO;
212 } 212 }
213 outb(NSC_COMMAND_EOC, chip->vendor->base + NSC_COMMAND); 213 outb(NSC_COMMAND_EOC, chip->vendor->base + NSC_COMMAND);
@@ -220,6 +220,11 @@ static void tpm_nsc_cancel(struct tpm_chip *chip)
220 outb(NSC_COMMAND_CANCEL, chip->vendor->base + NSC_COMMAND); 220 outb(NSC_COMMAND_CANCEL, chip->vendor->base + NSC_COMMAND);
221} 221}
222 222
223static u8 tpm_nsc_status(struct tpm_chip *chip)
224{
225 return inb(chip->vendor->base + NSC_STATUS);
226}
227
223static struct file_operations nsc_ops = { 228static struct file_operations nsc_ops = {
224 .owner = THIS_MODULE, 229 .owner = THIS_MODULE,
225 .llseek = no_llseek, 230 .llseek = no_llseek,
@@ -239,7 +244,7 @@ static struct attribute * nsc_attrs[] = {
239 &dev_attr_pcrs.attr, 244 &dev_attr_pcrs.attr,
240 &dev_attr_caps.attr, 245 &dev_attr_caps.attr,
241 &dev_attr_cancel.attr, 246 &dev_attr_cancel.attr,
242 0, 247 NULL,
243}; 248};
244 249
245static struct attribute_group nsc_attr_grp = { .attrs = nsc_attrs }; 250static struct attribute_group nsc_attr_grp = { .attrs = nsc_attrs };
@@ -248,6 +253,7 @@ static struct tpm_vendor_specific tpm_nsc = {
248 .recv = tpm_nsc_recv, 253 .recv = tpm_nsc_recv,
249 .send = tpm_nsc_send, 254 .send = tpm_nsc_send,
250 .cancel = tpm_nsc_cancel, 255 .cancel = tpm_nsc_cancel,
256 .status = tpm_nsc_status,
251 .req_complete_mask = NSC_STATUS_OBF, 257 .req_complete_mask = NSC_STATUS_OBF,
252 .req_complete_val = NSC_STATUS_OBF, 258 .req_complete_val = NSC_STATUS_OBF,
253 .req_canceled = NSC_STATUS_RDY, 259 .req_canceled = NSC_STATUS_RDY,
@@ -255,16 +261,32 @@ static struct tpm_vendor_specific tpm_nsc = {
255 .miscdev = { .fops = &nsc_ops, }, 261 .miscdev = { .fops = &nsc_ops, },
256}; 262};
257 263
258static int __devinit tpm_nsc_init(struct pci_dev *pci_dev, 264static struct platform_device *pdev = NULL;
259 const struct pci_device_id *pci_id) 265
266static void __devexit tpm_nsc_remove(struct device *dev)
267{
268 struct tpm_chip *chip = dev_get_drvdata(dev);
269 if ( chip ) {
270 release_region(chip->vendor->base, 2);
271 tpm_remove_hardware(chip->dev);
272 }
273}
274
275static struct device_driver nsc_drv = {
276 .name = "tpm_nsc",
277 .bus = &platform_bus_type,
278 .owner = THIS_MODULE,
279 .suspend = tpm_pm_suspend,
280 .resume = tpm_pm_resume,
281};
282
283static int __init init_nsc(void)
260{ 284{
261 int rc = 0; 285 int rc = 0;
262 int lo, hi; 286 int lo, hi;
263 int nscAddrBase = TPM_ADDR; 287 int nscAddrBase = TPM_ADDR;
264 288
265 289 driver_register(&nsc_drv);
266 if (pci_enable_device(pci_dev))
267 return -EIO;
268 290
269 /* select PM channel 1 */ 291 /* select PM channel 1 */
270 tpm_write_index(nscAddrBase,NSC_LDN_INDEX, 0x12); 292 tpm_write_index(nscAddrBase,NSC_LDN_INDEX, 0x12);
@@ -273,37 +295,71 @@ static int __devinit tpm_nsc_init(struct pci_dev *pci_dev,
273 if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) { 295 if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) {
274 nscAddrBase = (tpm_read_index(TPM_SUPERIO_ADDR, 0x2C)<<8)| 296 nscAddrBase = (tpm_read_index(TPM_SUPERIO_ADDR, 0x2C)<<8)|
275 (tpm_read_index(TPM_SUPERIO_ADDR, 0x2B)&0xFE); 297 (tpm_read_index(TPM_SUPERIO_ADDR, 0x2B)&0xFE);
276 if (tpm_read_index(nscAddrBase, NSC_SID_INDEX) != 0xF6) { 298 if (tpm_read_index(nscAddrBase, NSC_SID_INDEX) != 0xF6)
277 rc = -ENODEV; 299 return -ENODEV;
278 goto out_err;
279 }
280 } 300 }
281 301
282 hi = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_HI); 302 hi = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_HI);
283 lo = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_LO); 303 lo = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_LO);
284 tpm_nsc.base = (hi<<8) | lo; 304 tpm_nsc.base = (hi<<8) | lo;
285 305
286 dev_dbg(&pci_dev->dev, "NSC TPM detected\n"); 306 /* enable the DPM module */
287 dev_dbg(&pci_dev->dev, 307 tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01);
308
309 pdev = kmalloc(sizeof(struct platform_device), GFP_KERNEL);
310 if ( !pdev )
311 return -ENOMEM;
312
313 memset(pdev, 0, sizeof(struct platform_device));
314
315 pdev->name = "tpm_nscl0";
316 pdev->id = -1;
317 pdev->num_resources = 0;
318 pdev->dev.release = tpm_nsc_remove;
319 pdev->dev.driver = &nsc_drv;
320
321 if ((rc=platform_device_register(pdev)) < 0) {
322 kfree(pdev);
323 pdev = NULL;
324 return rc;
325 }
326
327 if (request_region(tpm_nsc.base, 2, "tpm_nsc0") == NULL ) {
328 platform_device_unregister(pdev);
329 kfree(pdev);
330 pdev = NULL;
331 return -EBUSY;
332 }
333
334 if ((rc = tpm_register_hardware(&pdev->dev, &tpm_nsc)) < 0) {
335 release_region(tpm_nsc.base, 2);
336 platform_device_unregister(pdev);
337 kfree(pdev);
338 pdev = NULL;
339 return rc;
340 }
341
342 dev_dbg(&pdev->dev, "NSC TPM detected\n");
343 dev_dbg(&pdev->dev,
288 "NSC LDN 0x%x, SID 0x%x, SRID 0x%x\n", 344 "NSC LDN 0x%x, SID 0x%x, SRID 0x%x\n",
289 tpm_read_index(nscAddrBase,0x07), tpm_read_index(nscAddrBase,0x20), 345 tpm_read_index(nscAddrBase,0x07), tpm_read_index(nscAddrBase,0x20),
290 tpm_read_index(nscAddrBase,0x27)); 346 tpm_read_index(nscAddrBase,0x27));
291 dev_dbg(&pci_dev->dev, 347 dev_dbg(&pdev->dev,
292 "NSC SIOCF1 0x%x SIOCF5 0x%x SIOCF6 0x%x SIOCF8 0x%x\n", 348 "NSC SIOCF1 0x%x SIOCF5 0x%x SIOCF6 0x%x SIOCF8 0x%x\n",
293 tpm_read_index(nscAddrBase,0x21), tpm_read_index(nscAddrBase,0x25), 349 tpm_read_index(nscAddrBase,0x21), tpm_read_index(nscAddrBase,0x25),
294 tpm_read_index(nscAddrBase,0x26), tpm_read_index(nscAddrBase,0x28)); 350 tpm_read_index(nscAddrBase,0x26), tpm_read_index(nscAddrBase,0x28));
295 dev_dbg(&pci_dev->dev, "NSC IO Base0 0x%x\n", 351 dev_dbg(&pdev->dev, "NSC IO Base0 0x%x\n",
296 (tpm_read_index(nscAddrBase,0x60) << 8) | tpm_read_index(nscAddrBase,0x61)); 352 (tpm_read_index(nscAddrBase,0x60) << 8) | tpm_read_index(nscAddrBase,0x61));
297 dev_dbg(&pci_dev->dev, "NSC IO Base1 0x%x\n", 353 dev_dbg(&pdev->dev, "NSC IO Base1 0x%x\n",
298 (tpm_read_index(nscAddrBase,0x62) << 8) | tpm_read_index(nscAddrBase,0x63)); 354 (tpm_read_index(nscAddrBase,0x62) << 8) | tpm_read_index(nscAddrBase,0x63));
299 dev_dbg(&pci_dev->dev, "NSC Interrupt number and wakeup 0x%x\n", 355 dev_dbg(&pdev->dev, "NSC Interrupt number and wakeup 0x%x\n",
300 tpm_read_index(nscAddrBase,0x70)); 356 tpm_read_index(nscAddrBase,0x70));
301 dev_dbg(&pci_dev->dev, "NSC IRQ type select 0x%x\n", 357 dev_dbg(&pdev->dev, "NSC IRQ type select 0x%x\n",
302 tpm_read_index(nscAddrBase,0x71)); 358 tpm_read_index(nscAddrBase,0x71));
303 dev_dbg(&pci_dev->dev, 359 dev_dbg(&pdev->dev,
304 "NSC DMA channel select0 0x%x, select1 0x%x\n", 360 "NSC DMA channel select0 0x%x, select1 0x%x\n",
305 tpm_read_index(nscAddrBase,0x74), tpm_read_index(nscAddrBase,0x75)); 361 tpm_read_index(nscAddrBase,0x74), tpm_read_index(nscAddrBase,0x75));
306 dev_dbg(&pci_dev->dev, 362 dev_dbg(&pdev->dev,
307 "NSC Config " 363 "NSC Config "
308 "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", 364 "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
309 tpm_read_index(nscAddrBase,0xF0), tpm_read_index(nscAddrBase,0xF1), 365 tpm_read_index(nscAddrBase,0xF0), tpm_read_index(nscAddrBase,0xF1),
@@ -312,55 +368,23 @@ static int __devinit tpm_nsc_init(struct pci_dev *pci_dev,
312 tpm_read_index(nscAddrBase,0xF6), tpm_read_index(nscAddrBase,0xF7), 368 tpm_read_index(nscAddrBase,0xF6), tpm_read_index(nscAddrBase,0xF7),
313 tpm_read_index(nscAddrBase,0xF8), tpm_read_index(nscAddrBase,0xF9)); 369 tpm_read_index(nscAddrBase,0xF8), tpm_read_index(nscAddrBase,0xF9));
314 370
315 dev_info(&pci_dev->dev, 371 dev_info(&pdev->dev,
316 "NSC TPM revision %d\n", 372 "NSC TPM revision %d\n",
317 tpm_read_index(nscAddrBase, 0x27) & 0x1F); 373 tpm_read_index(nscAddrBase, 0x27) & 0x1F);
318 374
319 /* enable the DPM module */
320 tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01);
321
322 if ((rc = tpm_register_hardware(pci_dev, &tpm_nsc)) < 0)
323 goto out_err;
324
325 return 0; 375 return 0;
326
327out_err:
328 pci_disable_device(pci_dev);
329 return rc;
330}
331
332static struct pci_device_id tpm_pci_tbl[] __devinitdata = {
333 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0)},
334 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12)},
335 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0)},
336 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12)},
337 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0)},
338 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0)},
339 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1)},
340 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_0)},
341 {PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_LPC)},
342 {0,}
343};
344
345MODULE_DEVICE_TABLE(pci, tpm_pci_tbl);
346
347static struct pci_driver nsc_pci_driver = {
348 .name = "tpm_nsc",
349 .id_table = tpm_pci_tbl,
350 .probe = tpm_nsc_init,
351 .remove = __devexit_p(tpm_remove),
352 .suspend = tpm_pm_suspend,
353 .resume = tpm_pm_resume,
354};
355
356static int __init init_nsc(void)
357{
358 return pci_register_driver(&nsc_pci_driver);
359} 376}
360 377
361static void __exit cleanup_nsc(void) 378static void __exit cleanup_nsc(void)
362{ 379{
363 pci_unregister_driver(&nsc_pci_driver); 380 if (pdev) {
381 tpm_nsc_remove(&pdev->dev);
382 platform_device_unregister(pdev);
383 kfree(pdev);
384 pdev = NULL;
385 }
386
387 driver_unregister(&nsc_drv);
364} 388}
365 389
366module_init(init_nsc); 390module_init(init_nsc);
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index e5953f3433f3..c586bfa852ee 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -809,7 +809,7 @@ static void do_tty_hangup(void *data)
809 check_tty_count(tty, "do_tty_hangup"); 809 check_tty_count(tty, "do_tty_hangup");
810 file_list_lock(); 810 file_list_lock();
811 /* This breaks for file handles being sent over AF_UNIX sockets ? */ 811 /* This breaks for file handles being sent over AF_UNIX sockets ? */
812 list_for_each_entry(filp, &tty->tty_files, f_list) { 812 list_for_each_entry(filp, &tty->tty_files, f_u.fu_list) {
813 if (filp->f_op->write == redirected_tty_write) 813 if (filp->f_op->write == redirected_tty_write)
814 cons_filp = filp; 814 cons_filp = filp;
815 if (filp->f_op->write != tty_write) 815 if (filp->f_op->write != tty_write)
@@ -2728,7 +2728,7 @@ void tty_register_device(struct tty_driver *driver, unsigned index,
2728 pty_line_name(driver, index, name); 2728 pty_line_name(driver, index, name);
2729 else 2729 else
2730 tty_line_name(driver, index, name); 2730 tty_line_name(driver, index, name);
2731 class_device_create(tty_class, dev, device, name); 2731 class_device_create(tty_class, NULL, dev, device, "%s", name);
2732} 2732}
2733 2733
2734/** 2734/**
@@ -2983,14 +2983,14 @@ static int __init tty_init(void)
2983 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0) 2983 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0)
2984 panic("Couldn't register /dev/tty driver\n"); 2984 panic("Couldn't register /dev/tty driver\n");
2985 devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 0), S_IFCHR|S_IRUGO|S_IWUGO, "tty"); 2985 devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 0), S_IFCHR|S_IRUGO|S_IWUGO, "tty");
2986 class_device_create(tty_class, MKDEV(TTYAUX_MAJOR, 0), NULL, "tty"); 2986 class_device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), NULL, "tty");
2987 2987
2988 cdev_init(&console_cdev, &console_fops); 2988 cdev_init(&console_cdev, &console_fops);
2989 if (cdev_add(&console_cdev, MKDEV(TTYAUX_MAJOR, 1), 1) || 2989 if (cdev_add(&console_cdev, MKDEV(TTYAUX_MAJOR, 1), 1) ||
2990 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0) 2990 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0)
2991 panic("Couldn't register /dev/console driver\n"); 2991 panic("Couldn't register /dev/console driver\n");
2992 devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 1), S_IFCHR|S_IRUSR|S_IWUSR, "console"); 2992 devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 1), S_IFCHR|S_IRUSR|S_IWUSR, "console");
2993 class_device_create(tty_class, MKDEV(TTYAUX_MAJOR, 1), NULL, "console"); 2993 class_device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 1), NULL, "console");
2994 2994
2995#ifdef CONFIG_UNIX98_PTYS 2995#ifdef CONFIG_UNIX98_PTYS
2996 cdev_init(&ptmx_cdev, &ptmx_fops); 2996 cdev_init(&ptmx_cdev, &ptmx_fops);
@@ -2998,7 +2998,7 @@ static int __init tty_init(void)
2998 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0) 2998 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
2999 panic("Couldn't register /dev/ptmx driver\n"); 2999 panic("Couldn't register /dev/ptmx driver\n");
3000 devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 2), S_IFCHR|S_IRUGO|S_IWUGO, "ptmx"); 3000 devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 2), S_IFCHR|S_IRUGO|S_IWUGO, "ptmx");
3001 class_device_create(tty_class, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptmx"); 3001 class_device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptmx");
3002#endif 3002#endif
3003 3003
3004#ifdef CONFIG_VT 3004#ifdef CONFIG_VT
@@ -3007,7 +3007,7 @@ static int __init tty_init(void)
3007 register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0) 3007 register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0)
3008 panic("Couldn't register /dev/tty0 driver\n"); 3008 panic("Couldn't register /dev/tty0 driver\n");
3009 devfs_mk_cdev(MKDEV(TTY_MAJOR, 0), S_IFCHR|S_IRUSR|S_IWUSR, "vc/0"); 3009 devfs_mk_cdev(MKDEV(TTY_MAJOR, 0), S_IFCHR|S_IRUSR|S_IWUSR, "vc/0");
3010 class_device_create(tty_class, MKDEV(TTY_MAJOR, 0), NULL, "tty0"); 3010 class_device_create(tty_class, NULL, MKDEV(TTY_MAJOR, 0), NULL, "tty0");
3011 3011
3012 vty_init(); 3012 vty_init();
3013#endif 3013#endif
diff --git a/drivers/char/vc_screen.c b/drivers/char/vc_screen.c
index 79c2928a8817..f66c7ad6fd38 100644
--- a/drivers/char/vc_screen.c
+++ b/drivers/char/vc_screen.c
@@ -484,8 +484,10 @@ void vcs_make_devfs(struct tty_struct *tty)
484 devfs_mk_cdev(MKDEV(VCS_MAJOR, tty->index + 129), 484 devfs_mk_cdev(MKDEV(VCS_MAJOR, tty->index + 129),
485 S_IFCHR|S_IRUSR|S_IWUSR, 485 S_IFCHR|S_IRUSR|S_IWUSR,
486 "vcc/a%u", tty->index + 1); 486 "vcc/a%u", tty->index + 1);
487 class_device_create(vc_class, MKDEV(VCS_MAJOR, tty->index + 1), NULL, "vcs%u", tty->index + 1); 487 class_device_create(vc_class, NULL, MKDEV(VCS_MAJOR, tty->index + 1),
488 class_device_create(vc_class, MKDEV(VCS_MAJOR, tty->index + 129), NULL, "vcsa%u", tty->index + 1); 488 NULL, "vcs%u", tty->index + 1);
489 class_device_create(vc_class, NULL, MKDEV(VCS_MAJOR, tty->index + 129),
490 NULL, "vcsa%u", tty->index + 1);
489} 491}
490void vcs_remove_devfs(struct tty_struct *tty) 492void vcs_remove_devfs(struct tty_struct *tty)
491{ 493{
@@ -503,7 +505,7 @@ int __init vcs_init(void)
503 505
504 devfs_mk_cdev(MKDEV(VCS_MAJOR, 0), S_IFCHR|S_IRUSR|S_IWUSR, "vcc/0"); 506 devfs_mk_cdev(MKDEV(VCS_MAJOR, 0), S_IFCHR|S_IRUSR|S_IWUSR, "vcc/0");
505 devfs_mk_cdev(MKDEV(VCS_MAJOR, 128), S_IFCHR|S_IRUSR|S_IWUSR, "vcc/a0"); 507 devfs_mk_cdev(MKDEV(VCS_MAJOR, 128), S_IFCHR|S_IRUSR|S_IWUSR, "vcc/a0");
506 class_device_create(vc_class, MKDEV(VCS_MAJOR, 0), NULL, "vcs"); 508 class_device_create(vc_class, NULL, MKDEV(VCS_MAJOR, 0), NULL, "vcs");
507 class_device_create(vc_class, MKDEV(VCS_MAJOR, 128), NULL, "vcsa"); 509 class_device_create(vc_class, NULL, MKDEV(VCS_MAJOR, 128), NULL, "vcsa");
508 return 0; 510 return 0;
509} 511}
diff --git a/drivers/char/viotape.c b/drivers/char/viotape.c
index d92a05645007..51abd3defc1c 100644
--- a/drivers/char/viotape.c
+++ b/drivers/char/viotape.c
@@ -956,9 +956,9 @@ static int viotape_probe(struct vio_dev *vdev, const struct vio_device_id *id)
956 state[i].cur_part = 0; 956 state[i].cur_part = 0;
957 for (j = 0; j < MAX_PARTITIONS; ++j) 957 for (j = 0; j < MAX_PARTITIONS; ++j)
958 state[i].part_stat_rwi[j] = VIOT_IDLE; 958 state[i].part_stat_rwi[j] = VIOT_IDLE;
959 class_device_create(tape_class, MKDEV(VIOTAPE_MAJOR, i), NULL, 959 class_device_create(tape_class, NULL, MKDEV(VIOTAPE_MAJOR, i), NULL,
960 "iseries!vt%d", i); 960 "iseries!vt%d", i);
961 class_device_create(tape_class, MKDEV(VIOTAPE_MAJOR, i | 0x80), 961 class_device_create(tape_class, NULL, MKDEV(VIOTAPE_MAJOR, i | 0x80),
962 NULL, "iseries!nvt%d", i); 962 NULL, "iseries!nvt%d", i);
963 devfs_mk_cdev(MKDEV(VIOTAPE_MAJOR, i), S_IFCHR | S_IRUSR | S_IWUSR, 963 devfs_mk_cdev(MKDEV(VIOTAPE_MAJOR, i), S_IFCHR | S_IRUSR | S_IWUSR,
964 "iseries/vt%d", i); 964 "iseries/vt%d", i);
diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
index 1d44f69e1fda..003dda147cd0 100644
--- a/drivers/char/vt_ioctl.c
+++ b/drivers/char/vt_ioctl.c
@@ -192,6 +192,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
192 int i, j, k; 192 int i, j, k;
193 int ret; 193 int ret;
194 194
195 if (!capable(CAP_SYS_TTY_CONFIG))
196 return -EPERM;
197
195 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL); 198 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
196 if (!kbs) { 199 if (!kbs) {
197 ret = -ENOMEM; 200 ret = -ENOMEM;
diff --git a/drivers/char/watchdog/cpu5wdt.c b/drivers/char/watchdog/cpu5wdt.c
index 2865dac0a813..e75045fe2641 100644
--- a/drivers/char/watchdog/cpu5wdt.c
+++ b/drivers/char/watchdog/cpu5wdt.c
@@ -28,6 +28,7 @@
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/ioport.h> 29#include <linux/ioport.h>
30#include <linux/timer.h> 30#include <linux/timer.h>
31#include <linux/jiffies.h>
31#include <asm/io.h> 32#include <asm/io.h>
32#include <asm/uaccess.h> 33#include <asm/uaccess.h>
33 34
diff --git a/drivers/char/watchdog/mixcomwd.c b/drivers/char/watchdog/mixcomwd.c
index 7fc2188386d9..d8dede575402 100644
--- a/drivers/char/watchdog/mixcomwd.c
+++ b/drivers/char/watchdog/mixcomwd.c
@@ -45,6 +45,8 @@
45#include <linux/fs.h> 45#include <linux/fs.h>
46#include <linux/reboot.h> 46#include <linux/reboot.h>
47#include <linux/init.h> 47#include <linux/init.h>
48#include <linux/jiffies.h>
49#include <linux/timer.h>
48#include <asm/uaccess.h> 50#include <asm/uaccess.h>
49#include <asm/io.h> 51#include <asm/io.h>
50 52
diff --git a/drivers/char/watchdog/pcwd.c b/drivers/char/watchdog/pcwd.c
index 427ad51b7a35..37c9e13ad3ac 100644
--- a/drivers/char/watchdog/pcwd.c
+++ b/drivers/char/watchdog/pcwd.c
@@ -66,7 +66,7 @@
66#include <linux/init.h> 66#include <linux/init.h>
67#include <linux/spinlock.h> 67#include <linux/spinlock.h>
68#include <linux/reboot.h> 68#include <linux/reboot.h>
69 69#include <linux/sched.h> /* TASK_INTERRUPTIBLE, set_current_state() and friends */
70#include <asm/uaccess.h> 70#include <asm/uaccess.h>
71#include <asm/io.h> 71#include <asm/io.h>
72 72
diff --git a/drivers/char/watchdog/pcwd_pci.c b/drivers/char/watchdog/pcwd_pci.c
index 0b8e493be045..5308e5c8f29a 100644
--- a/drivers/char/watchdog/pcwd_pci.c
+++ b/drivers/char/watchdog/pcwd_pci.c
@@ -753,6 +753,7 @@ static struct pci_device_id pcipcwd_pci_tbl[] = {
753MODULE_DEVICE_TABLE(pci, pcipcwd_pci_tbl); 753MODULE_DEVICE_TABLE(pci, pcipcwd_pci_tbl);
754 754
755static struct pci_driver pcipcwd_driver = { 755static struct pci_driver pcipcwd_driver = {
756 .owner = THIS_MODULE,
756 .name = WATCHDOG_NAME, 757 .name = WATCHDOG_NAME,
757 .id_table = pcipcwd_pci_tbl, 758 .id_table = pcipcwd_pci_tbl,
758 .probe = pcipcwd_card_init, 759 .probe = pcipcwd_card_init,
diff --git a/drivers/char/watchdog/s3c2410_wdt.c b/drivers/char/watchdog/s3c2410_wdt.c
index 3625b2601b42..b732020acadb 100644
--- a/drivers/char/watchdog/s3c2410_wdt.c
+++ b/drivers/char/watchdog/s3c2410_wdt.c
@@ -464,32 +464,28 @@ static void s3c2410wdt_shutdown(struct device *dev)
464static unsigned long wtcon_save; 464static unsigned long wtcon_save;
465static unsigned long wtdat_save; 465static unsigned long wtdat_save;
466 466
467static int s3c2410wdt_suspend(struct device *dev, pm_message_t state, u32 level) 467static int s3c2410wdt_suspend(struct device *dev, pm_message_t state)
468{ 468{
469 if (level == SUSPEND_POWER_DOWN) { 469 /* Save watchdog state, and turn it off. */
470 /* Save watchdog state, and turn it off. */ 470 wtcon_save = readl(wdt_base + S3C2410_WTCON);
471 wtcon_save = readl(wdt_base + S3C2410_WTCON); 471 wtdat_save = readl(wdt_base + S3C2410_WTDAT);
472 wtdat_save = readl(wdt_base + S3C2410_WTDAT);
473 472
474 /* Note that WTCNT doesn't need to be saved. */ 473 /* Note that WTCNT doesn't need to be saved. */
475 s3c2410wdt_stop(); 474 s3c2410wdt_stop();
476 }
477 475
478 return 0; 476 return 0;
479} 477}
480 478
481static int s3c2410wdt_resume(struct device *dev, u32 level) 479static int s3c2410wdt_resume(struct device *dev)
482{ 480{
483 if (level == RESUME_POWER_ON) { 481 /* Restore watchdog state. */
484 /* Restore watchdog state. */
485 482
486 writel(wtdat_save, wdt_base + S3C2410_WTDAT); 483 writel(wtdat_save, wdt_base + S3C2410_WTDAT);
487 writel(wtdat_save, wdt_base + S3C2410_WTCNT); /* Reset count */ 484 writel(wtdat_save, wdt_base + S3C2410_WTCNT); /* Reset count */
488 writel(wtcon_save, wdt_base + S3C2410_WTCON); 485 writel(wtcon_save, wdt_base + S3C2410_WTCON);
489 486
490 printk(KERN_INFO PFX "watchdog %sabled\n", 487 printk(KERN_INFO PFX "watchdog %sabled\n",
491 (wtcon_save & S3C2410_WTCON_ENABLE) ? "en" : "dis"); 488 (wtcon_save & S3C2410_WTCON_ENABLE) ? "en" : "dis");
492 }
493 489
494 return 0; 490 return 0;
495} 491}
diff --git a/drivers/char/watchdog/sc520_wdt.c b/drivers/char/watchdog/sc520_wdt.c
index 72501be79b0c..4ee9974ad8cb 100644
--- a/drivers/char/watchdog/sc520_wdt.c
+++ b/drivers/char/watchdog/sc520_wdt.c
@@ -63,6 +63,7 @@
63#include <linux/notifier.h> 63#include <linux/notifier.h>
64#include <linux/reboot.h> 64#include <linux/reboot.h>
65#include <linux/init.h> 65#include <linux/init.h>
66#include <linux/jiffies.h>
66 67
67#include <asm/io.h> 68#include <asm/io.h>
68#include <asm/uaccess.h> 69#include <asm/uaccess.h>
diff --git a/drivers/char/watchdog/softdog.c b/drivers/char/watchdog/softdog.c
index 20e5eb8667f2..a91edaf3a350 100644
--- a/drivers/char/watchdog/softdog.c
+++ b/drivers/char/watchdog/softdog.c
@@ -47,6 +47,8 @@
47#include <linux/notifier.h> 47#include <linux/notifier.h>
48#include <linux/reboot.h> 48#include <linux/reboot.h>
49#include <linux/init.h> 49#include <linux/init.h>
50#include <linux/jiffies.h>
51
50#include <asm/uaccess.h> 52#include <asm/uaccess.h>
51 53
52#define PFX "SoftDog: " 54#define PFX "SoftDog: "
diff --git a/drivers/char/watchdog/wdt_pci.c b/drivers/char/watchdog/wdt_pci.c
index 4b3311993d48..dc9370f6c348 100644
--- a/drivers/char/watchdog/wdt_pci.c
+++ b/drivers/char/watchdog/wdt_pci.c
@@ -711,6 +711,7 @@ MODULE_DEVICE_TABLE(pci, wdtpci_pci_tbl);
711 711
712 712
713static struct pci_driver wdtpci_driver = { 713static struct pci_driver wdtpci_driver = {
714 .owner = THIS_MODULE,
714 .name = "wdt_pci", 715 .name = "wdt_pci",
715 .id_table = wdtpci_pci_tbl, 716 .id_table = wdtpci_pci_tbl,
716 .probe = wdtpci_init_one, 717 .probe = wdtpci_init_one,
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 109d62ccf651..6c6121b85a54 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -4,6 +4,9 @@
4 * Copyright (C) 2001 Russell King 4 * Copyright (C) 2001 Russell King
5 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> 5 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
6 * 6 *
7 * Oct 2005 - Ashok Raj <ashok.raj@intel.com>
8 * Added handling for CPU hotplug
9 *
7 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as 11 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation. 12 * published by the Free Software Foundation.
@@ -36,13 +39,6 @@ static struct cpufreq_policy *cpufreq_cpu_data[NR_CPUS];
36static DEFINE_SPINLOCK(cpufreq_driver_lock); 39static DEFINE_SPINLOCK(cpufreq_driver_lock);
37 40
38 41
39/* we keep a copy of all ->add'ed CPU's struct sys_device here;
40 * as it is only accessed in ->add and ->remove, no lock or reference
41 * count is necessary.
42 */
43static struct sys_device *cpu_sys_devices[NR_CPUS];
44
45
46/* internal prototypes */ 42/* internal prototypes */
47static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event); 43static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event);
48static void handle_update(void *data); 44static void handle_update(void *data);
@@ -574,6 +570,9 @@ static int cpufreq_add_dev (struct sys_device * sys_dev)
574 unsigned long flags; 570 unsigned long flags;
575 unsigned int j; 571 unsigned int j;
576 572
573 if (cpu_is_offline(cpu))
574 return 0;
575
577 cpufreq_debug_disable_ratelimit(); 576 cpufreq_debug_disable_ratelimit();
578 dprintk("adding CPU %u\n", cpu); 577 dprintk("adding CPU %u\n", cpu);
579 578
@@ -582,7 +581,6 @@ static int cpufreq_add_dev (struct sys_device * sys_dev)
582 * CPU because it is in the same boat. */ 581 * CPU because it is in the same boat. */
583 policy = cpufreq_cpu_get(cpu); 582 policy = cpufreq_cpu_get(cpu);
584 if (unlikely(policy)) { 583 if (unlikely(policy)) {
585 cpu_sys_devices[cpu] = sys_dev;
586 dprintk("CPU already managed, adding link\n"); 584 dprintk("CPU already managed, adding link\n");
587 sysfs_create_link(&sys_dev->kobj, &policy->kobj, "cpufreq"); 585 sysfs_create_link(&sys_dev->kobj, &policy->kobj, "cpufreq");
588 cpufreq_debug_enable_ratelimit(); 586 cpufreq_debug_enable_ratelimit();
@@ -657,7 +655,6 @@ static int cpufreq_add_dev (struct sys_device * sys_dev)
657 } 655 }
658 656
659 module_put(cpufreq_driver->owner); 657 module_put(cpufreq_driver->owner);
660 cpu_sys_devices[cpu] = sys_dev;
661 dprintk("initialization complete\n"); 658 dprintk("initialization complete\n");
662 cpufreq_debug_enable_ratelimit(); 659 cpufreq_debug_enable_ratelimit();
663 660
@@ -682,7 +679,7 @@ err_out:
682 679
683nomem_out: 680nomem_out:
684 module_put(cpufreq_driver->owner); 681 module_put(cpufreq_driver->owner);
685 module_out: 682module_out:
686 cpufreq_debug_enable_ratelimit(); 683 cpufreq_debug_enable_ratelimit();
687 return ret; 684 return ret;
688} 685}
@@ -698,6 +695,7 @@ static int cpufreq_remove_dev (struct sys_device * sys_dev)
698 unsigned int cpu = sys_dev->id; 695 unsigned int cpu = sys_dev->id;
699 unsigned long flags; 696 unsigned long flags;
700 struct cpufreq_policy *data; 697 struct cpufreq_policy *data;
698 struct sys_device *cpu_sys_dev;
701#ifdef CONFIG_SMP 699#ifdef CONFIG_SMP
702 unsigned int j; 700 unsigned int j;
703#endif 701#endif
@@ -710,7 +708,6 @@ static int cpufreq_remove_dev (struct sys_device * sys_dev)
710 708
711 if (!data) { 709 if (!data) {
712 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 710 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
713 cpu_sys_devices[cpu] = NULL;
714 cpufreq_debug_enable_ratelimit(); 711 cpufreq_debug_enable_ratelimit();
715 return -EINVAL; 712 return -EINVAL;
716 } 713 }
@@ -725,14 +722,12 @@ static int cpufreq_remove_dev (struct sys_device * sys_dev)
725 dprintk("removing link\n"); 722 dprintk("removing link\n");
726 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 723 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
727 sysfs_remove_link(&sys_dev->kobj, "cpufreq"); 724 sysfs_remove_link(&sys_dev->kobj, "cpufreq");
728 cpu_sys_devices[cpu] = NULL;
729 cpufreq_cpu_put(data); 725 cpufreq_cpu_put(data);
730 cpufreq_debug_enable_ratelimit(); 726 cpufreq_debug_enable_ratelimit();
731 return 0; 727 return 0;
732 } 728 }
733#endif 729#endif
734 730
735 cpu_sys_devices[cpu] = NULL;
736 731
737 if (!kobject_get(&data->kobj)) { 732 if (!kobject_get(&data->kobj)) {
738 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 733 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
@@ -761,7 +756,8 @@ static int cpufreq_remove_dev (struct sys_device * sys_dev)
761 if (j == cpu) 756 if (j == cpu)
762 continue; 757 continue;
763 dprintk("removing link for cpu %u\n", j); 758 dprintk("removing link for cpu %u\n", j);
764 sysfs_remove_link(&cpu_sys_devices[j]->kobj, "cpufreq"); 759 cpu_sys_dev = get_cpu_sysdev(j);
760 sysfs_remove_link(&cpu_sys_dev->kobj, "cpufreq");
765 cpufreq_cpu_put(data); 761 cpufreq_cpu_put(data);
766 } 762 }
767 } 763 }
@@ -772,7 +768,6 @@ static int cpufreq_remove_dev (struct sys_device * sys_dev)
772 down(&data->lock); 768 down(&data->lock);
773 if (cpufreq_driver->target) 769 if (cpufreq_driver->target)
774 __cpufreq_governor(data, CPUFREQ_GOV_STOP); 770 __cpufreq_governor(data, CPUFREQ_GOV_STOP);
775 cpufreq_driver->target = NULL;
776 up(&data->lock); 771 up(&data->lock);
777 772
778 kobject_unregister(&data->kobj); 773 kobject_unregister(&data->kobj);
@@ -1119,17 +1114,30 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
1119 unsigned int relation) 1114 unsigned int relation)
1120{ 1115{
1121 int retval = -EINVAL; 1116 int retval = -EINVAL;
1122 lock_cpu_hotplug(); 1117
1118 /*
1119 * Converted the lock_cpu_hotplug to preempt_disable()
1120 * and preempt_enable(). This is a bit kludgy and relies on how cpu
1121 * hotplug works. All we need is a guarantee that cpu hotplug won't make
1122 * progress on any cpu. Once we do preempt_disable(), this would ensure
1123 * that hotplug threads don't get onto this cpu, thereby delaying
1124 * the cpu remove process.
1125 *
1126 * We removed the lock_cpu_hotplug since we need to call this function
1127 * via cpu hotplug callbacks, which result in locking the cpu hotplug
1128 * thread itself. Agree this is not very clean, cpufreq community
1129 * could improve this if required. - Ashok Raj <ashok.raj@intel.com>
1130 */
1131 preempt_disable();
1123 dprintk("target for CPU %u: %u kHz, relation %u\n", policy->cpu, 1132 dprintk("target for CPU %u: %u kHz, relation %u\n", policy->cpu,
1124 target_freq, relation); 1133 target_freq, relation);
1125 if (cpu_online(policy->cpu) && cpufreq_driver->target) 1134 if (cpu_online(policy->cpu) && cpufreq_driver->target)
1126 retval = cpufreq_driver->target(policy, target_freq, relation); 1135 retval = cpufreq_driver->target(policy, target_freq, relation);
1127 unlock_cpu_hotplug(); 1136 preempt_enable();
1128 return retval; 1137 return retval;
1129} 1138}
1130EXPORT_SYMBOL_GPL(__cpufreq_driver_target); 1139EXPORT_SYMBOL_GPL(__cpufreq_driver_target);
1131 1140
1132
1133int cpufreq_driver_target(struct cpufreq_policy *policy, 1141int cpufreq_driver_target(struct cpufreq_policy *policy,
1134 unsigned int target_freq, 1142 unsigned int target_freq,
1135 unsigned int relation) 1143 unsigned int relation)
@@ -1416,6 +1424,45 @@ int cpufreq_update_policy(unsigned int cpu)
1416} 1424}
1417EXPORT_SYMBOL(cpufreq_update_policy); 1425EXPORT_SYMBOL(cpufreq_update_policy);
1418 1426
1427static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
1428 unsigned long action, void *hcpu)
1429{
1430 unsigned int cpu = (unsigned long)hcpu;
1431 struct cpufreq_policy *policy;
1432 struct sys_device *sys_dev;
1433
1434 sys_dev = get_cpu_sysdev(cpu);
1435
1436 if (sys_dev) {
1437 switch (action) {
1438 case CPU_ONLINE:
1439 cpufreq_add_dev(sys_dev);
1440 break;
1441 case CPU_DOWN_PREPARE:
1442 /*
1443 * We attempt to put this cpu in lowest frequency
1444 * possible before going down. This will permit
1445 * hardware-managed P-State to switch other related
1446 * threads to min or higher speeds if possible.
1447 */
1448 policy = cpufreq_cpu_data[cpu];
1449 if (policy) {
1450 cpufreq_driver_target(policy, policy->min,
1451 CPUFREQ_RELATION_H);
1452 }
1453 break;
1454 case CPU_DEAD:
1455 cpufreq_remove_dev(sys_dev);
1456 break;
1457 }
1458 }
1459 return NOTIFY_OK;
1460}
1461
1462static struct notifier_block cpufreq_cpu_notifier =
1463{
1464 .notifier_call = cpufreq_cpu_callback,
1465};
1419 1466
1420/********************************************************************* 1467/*********************************************************************
1421 * REGISTER / UNREGISTER CPUFREQ DRIVER * 1468 * REGISTER / UNREGISTER CPUFREQ DRIVER *
@@ -1476,6 +1523,7 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
1476 } 1523 }
1477 1524
1478 if (!ret) { 1525 if (!ret) {
1526 register_cpu_notifier(&cpufreq_cpu_notifier);
1479 dprintk("driver %s up and running\n", driver_data->name); 1527 dprintk("driver %s up and running\n", driver_data->name);
1480 cpufreq_debug_enable_ratelimit(); 1528 cpufreq_debug_enable_ratelimit();
1481 } 1529 }
@@ -1507,6 +1555,7 @@ int cpufreq_unregister_driver(struct cpufreq_driver *driver)
1507 dprintk("unregistering driver %s\n", driver->name); 1555 dprintk("unregistering driver %s\n", driver->name);
1508 1556
1509 sysdev_driver_unregister(&cpu_sysdev_class, &cpufreq_sysdev_driver); 1557 sysdev_driver_unregister(&cpu_sysdev_class, &cpufreq_sysdev_driver);
1558 unregister_cpu_notifier(&cpufreq_cpu_notifier);
1510 1559
1511 spin_lock_irqsave(&cpufreq_driver_lock, flags); 1560 spin_lock_irqsave(&cpufreq_driver_lock, flags);
1512 cpufreq_driver = NULL; 1561 cpufreq_driver = NULL;
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index 741b6b191e6a..3597f25d5efa 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -19,6 +19,7 @@
19#include <linux/percpu.h> 19#include <linux/percpu.h>
20#include <linux/kobject.h> 20#include <linux/kobject.h>
21#include <linux/spinlock.h> 21#include <linux/spinlock.h>
22#include <linux/notifier.h>
22#include <asm/cputime.h> 23#include <asm/cputime.h>
23 24
24static spinlock_t cpufreq_stats_lock; 25static spinlock_t cpufreq_stats_lock;
@@ -298,6 +299,27 @@ cpufreq_stat_notifier_trans (struct notifier_block *nb, unsigned long val,
298 return 0; 299 return 0;
299} 300}
300 301
302static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
303 unsigned long action, void *hcpu)
304{
305 unsigned int cpu = (unsigned long)hcpu;
306
307 switch (action) {
308 case CPU_ONLINE:
309 cpufreq_update_policy(cpu);
310 break;
311 case CPU_DEAD:
312 cpufreq_stats_free_table(cpu);
313 break;
314 }
315 return NOTIFY_OK;
316}
317
318static struct notifier_block cpufreq_stat_cpu_notifier =
319{
320 .notifier_call = cpufreq_stat_cpu_callback,
321};
322
301static struct notifier_block notifier_policy_block = { 323static struct notifier_block notifier_policy_block = {
302 .notifier_call = cpufreq_stat_notifier_policy 324 .notifier_call = cpufreq_stat_notifier_policy
303}; 325};
@@ -311,6 +333,7 @@ __init cpufreq_stats_init(void)
311{ 333{
312 int ret; 334 int ret;
313 unsigned int cpu; 335 unsigned int cpu;
336
314 spin_lock_init(&cpufreq_stats_lock); 337 spin_lock_init(&cpufreq_stats_lock);
315 if ((ret = cpufreq_register_notifier(&notifier_policy_block, 338 if ((ret = cpufreq_register_notifier(&notifier_policy_block,
316 CPUFREQ_POLICY_NOTIFIER))) 339 CPUFREQ_POLICY_NOTIFIER)))
@@ -323,20 +346,31 @@ __init cpufreq_stats_init(void)
323 return ret; 346 return ret;
324 } 347 }
325 348
326 for_each_cpu(cpu) 349 register_cpu_notifier(&cpufreq_stat_cpu_notifier);
327 cpufreq_update_policy(cpu); 350 lock_cpu_hotplug();
351 for_each_online_cpu(cpu) {
352 cpufreq_stat_cpu_callback(&cpufreq_stat_cpu_notifier, CPU_ONLINE,
353 (void *)(long)cpu);
354 }
355 unlock_cpu_hotplug();
328 return 0; 356 return 0;
329} 357}
330static void 358static void
331__exit cpufreq_stats_exit(void) 359__exit cpufreq_stats_exit(void)
332{ 360{
333 unsigned int cpu; 361 unsigned int cpu;
362
334 cpufreq_unregister_notifier(&notifier_policy_block, 363 cpufreq_unregister_notifier(&notifier_policy_block,
335 CPUFREQ_POLICY_NOTIFIER); 364 CPUFREQ_POLICY_NOTIFIER);
336 cpufreq_unregister_notifier(&notifier_trans_block, 365 cpufreq_unregister_notifier(&notifier_trans_block,
337 CPUFREQ_TRANSITION_NOTIFIER); 366 CPUFREQ_TRANSITION_NOTIFIER);
338 for_each_cpu(cpu) 367 unregister_cpu_notifier(&cpufreq_stat_cpu_notifier);
339 cpufreq_stats_free_table(cpu); 368 lock_cpu_hotplug();
369 for_each_online_cpu(cpu) {
370 cpufreq_stat_cpu_callback(&cpufreq_stat_cpu_notifier, CPU_DEAD,
371 (void *)(long)cpu);
372 }
373 unlock_cpu_hotplug();
340} 374}
341 375
342MODULE_AUTHOR ("Zou Nan hai <nanhai.zou@intel.com>"); 376MODULE_AUTHOR ("Zou Nan hai <nanhai.zou@intel.com>");
diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index 094835cce321..4263935443cc 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -2,7 +2,7 @@ menu "Hardware crypto devices"
2 2
3config CRYPTO_DEV_PADLOCK 3config CRYPTO_DEV_PADLOCK
4 tristate "Support for VIA PadLock ACE" 4 tristate "Support for VIA PadLock ACE"
5 depends on CRYPTO && X86 && !X86_64 5 depends on CRYPTO && X86_32
6 help 6 help
7 Some VIA processors come with an integrated crypto engine 7 Some VIA processors come with an integrated crypto engine
8 (so called VIA PadLock ACE, Advanced Cryptography Engine) 8 (so called VIA PadLock ACE, Advanced Cryptography Engine)
diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig
index 327b58e64875..b6815c6c29a2 100644
--- a/drivers/firmware/Kconfig
+++ b/drivers/firmware/Kconfig
@@ -70,8 +70,7 @@ config DELL_RBU
70 70
71config DCDBAS 71config DCDBAS
72 tristate "Dell Systems Management Base Driver" 72 tristate "Dell Systems Management Base Driver"
73 depends on X86 || X86_64 73 depends on X86
74 default m
75 help 74 help
76 The Dell Systems Management Base Driver provides a sysfs interface 75 The Dell Systems Management Base Driver provides a sysfs interface
77 for systems management software to perform System Management 76 for systems management software to perform System Management
diff --git a/drivers/hwmon/adm1021.c b/drivers/hwmon/adm1021.c
index e928cdb041cb..8102876c7c3f 100644
--- a/drivers/hwmon/adm1021.c
+++ b/drivers/hwmon/adm1021.c
@@ -121,7 +121,7 @@ static int adm1021_write_value(struct i2c_client *client, u8 reg,
121static struct adm1021_data *adm1021_update_device(struct device *dev); 121static struct adm1021_data *adm1021_update_device(struct device *dev);
122 122
123/* (amalysh) read only mode, otherwise any limit's writing confuse BIOS */ 123/* (amalysh) read only mode, otherwise any limit's writing confuse BIOS */
124static int read_only = 0; 124static int read_only;
125 125
126 126
127/* This is the driver that will be inserted */ 127/* This is the driver that will be inserted */
@@ -204,11 +204,10 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)
204 client structure, even though we cannot fill it completely yet. 204 client structure, even though we cannot fill it completely yet.
205 But it allows us to access adm1021_{read,write}_value. */ 205 But it allows us to access adm1021_{read,write}_value. */
206 206
207 if (!(data = kmalloc(sizeof(struct adm1021_data), GFP_KERNEL))) { 207 if (!(data = kzalloc(sizeof(struct adm1021_data), GFP_KERNEL))) {
208 err = -ENOMEM; 208 err = -ENOMEM;
209 goto error0; 209 goto error0;
210 } 210 }
211 memset(data, 0, sizeof(struct adm1021_data));
212 211
213 new_client = &data->client; 212 new_client = &data->client;
214 i2c_set_clientdata(new_client, data); 213 i2c_set_clientdata(new_client, data);
diff --git a/drivers/hwmon/adm1025.c b/drivers/hwmon/adm1025.c
index 526b7ff179eb..3ec12421694f 100644
--- a/drivers/hwmon/adm1025.c
+++ b/drivers/hwmon/adm1025.c
@@ -331,11 +331,10 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
331 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 331 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
332 goto exit; 332 goto exit;
333 333
334 if (!(data = kmalloc(sizeof(struct adm1025_data), GFP_KERNEL))) { 334 if (!(data = kzalloc(sizeof(struct adm1025_data), GFP_KERNEL))) {
335 err = -ENOMEM; 335 err = -ENOMEM;
336 goto exit; 336 goto exit;
337 } 337 }
338 memset(data, 0, sizeof(struct adm1025_data));
339 338
340 /* The common I2C client data is placed right before the 339 /* The common I2C client data is placed right before the
341 ADM1025-specific data. */ 340 ADM1025-specific data. */
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c
index 625158110fd4..e0f56549d1d8 100644
--- a/drivers/hwmon/adm1026.c
+++ b/drivers/hwmon/adm1026.c
@@ -315,7 +315,7 @@ static struct i2c_driver adm1026_driver = {
315 .detach_client = adm1026_detach_client, 315 .detach_client = adm1026_detach_client,
316}; 316};
317 317
318int adm1026_attach_adapter(struct i2c_adapter *adapter) 318static int adm1026_attach_adapter(struct i2c_adapter *adapter)
319{ 319{
320 if (!(adapter->class & I2C_CLASS_HWMON)) { 320 if (!(adapter->class & I2C_CLASS_HWMON)) {
321 return 0; 321 return 0;
@@ -323,7 +323,7 @@ int adm1026_attach_adapter(struct i2c_adapter *adapter)
323 return i2c_probe(adapter, &addr_data, adm1026_detect); 323 return i2c_probe(adapter, &addr_data, adm1026_detect);
324} 324}
325 325
326int adm1026_detach_client(struct i2c_client *client) 326static int adm1026_detach_client(struct i2c_client *client)
327{ 327{
328 struct adm1026_data *data = i2c_get_clientdata(client); 328 struct adm1026_data *data = i2c_get_clientdata(client);
329 hwmon_device_unregister(data->class_dev); 329 hwmon_device_unregister(data->class_dev);
@@ -332,7 +332,7 @@ int adm1026_detach_client(struct i2c_client *client)
332 return 0; 332 return 0;
333} 333}
334 334
335int adm1026_read_value(struct i2c_client *client, u8 reg) 335static int adm1026_read_value(struct i2c_client *client, u8 reg)
336{ 336{
337 int res; 337 int res;
338 338
@@ -346,7 +346,7 @@ int adm1026_read_value(struct i2c_client *client, u8 reg)
346 return res; 346 return res;
347} 347}
348 348
349int adm1026_write_value(struct i2c_client *client, u8 reg, int value) 349static int adm1026_write_value(struct i2c_client *client, u8 reg, int value)
350{ 350{
351 int res; 351 int res;
352 352
@@ -360,7 +360,7 @@ int adm1026_write_value(struct i2c_client *client, u8 reg, int value)
360 return res; 360 return res;
361} 361}
362 362
363void adm1026_init_client(struct i2c_client *client) 363static void adm1026_init_client(struct i2c_client *client)
364{ 364{
365 int value, i; 365 int value, i;
366 struct adm1026_data *data = i2c_get_clientdata(client); 366 struct adm1026_data *data = i2c_get_clientdata(client);
@@ -460,7 +460,7 @@ void adm1026_init_client(struct i2c_client *client)
460 } 460 }
461} 461}
462 462
463void adm1026_print_gpio(struct i2c_client *client) 463static void adm1026_print_gpio(struct i2c_client *client)
464{ 464{
465 struct adm1026_data *data = i2c_get_clientdata(client); 465 struct adm1026_data *data = i2c_get_clientdata(client);
466 int i; 466 int i;
@@ -492,7 +492,7 @@ void adm1026_print_gpio(struct i2c_client *client)
492 } 492 }
493} 493}
494 494
495void adm1026_fixup_gpio(struct i2c_client *client) 495static void adm1026_fixup_gpio(struct i2c_client *client)
496{ 496{
497 struct adm1026_data *data = i2c_get_clientdata(client); 497 struct adm1026_data *data = i2c_get_clientdata(client);
498 int i; 498 int i;
@@ -1452,8 +1452,8 @@ static DEVICE_ATTR(temp1_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
1452static DEVICE_ATTR(temp2_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL); 1452static DEVICE_ATTR(temp2_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
1453static DEVICE_ATTR(temp3_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL); 1453static DEVICE_ATTR(temp3_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
1454 1454
1455int adm1026_detect(struct i2c_adapter *adapter, int address, 1455static int adm1026_detect(struct i2c_adapter *adapter, int address,
1456 int kind) 1456 int kind)
1457{ 1457{
1458 int company, verstep; 1458 int company, verstep;
1459 struct i2c_client *new_client; 1459 struct i2c_client *new_client;
@@ -1470,13 +1470,11 @@ int adm1026_detect(struct i2c_adapter *adapter, int address,
1470 client structure, even though we cannot fill it completely yet. 1470 client structure, even though we cannot fill it completely yet.
1471 But it allows us to access adm1026_{read,write}_value. */ 1471 But it allows us to access adm1026_{read,write}_value. */
1472 1472
1473 if (!(data = kmalloc(sizeof(struct adm1026_data), GFP_KERNEL))) { 1473 if (!(data = kzalloc(sizeof(struct adm1026_data), GFP_KERNEL))) {
1474 err = -ENOMEM; 1474 err = -ENOMEM;
1475 goto exit; 1475 goto exit;
1476 } 1476 }
1477 1477
1478 memset(data, 0, sizeof(struct adm1026_data));
1479
1480 new_client = &data->client; 1478 new_client = &data->client;
1481 i2c_set_clientdata(new_client, data); 1479 i2c_set_clientdata(new_client, data);
1482 new_client->addr = address; 1480 new_client->addr = address;
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c
index 58338ed7c8a1..7c545d5eee45 100644
--- a/drivers/hwmon/adm1031.c
+++ b/drivers/hwmon/adm1031.c
@@ -740,11 +740,10 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
740 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 740 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
741 goto exit; 741 goto exit;
742 742
743 if (!(data = kmalloc(sizeof(struct adm1031_data), GFP_KERNEL))) { 743 if (!(data = kzalloc(sizeof(struct adm1031_data), GFP_KERNEL))) {
744 err = -ENOMEM; 744 err = -ENOMEM;
745 goto exit; 745 goto exit;
746 } 746 }
747 memset(data, 0, sizeof(struct adm1031_data));
748 747
749 new_client = &data->client; 748 new_client = &data->client;
750 i2c_set_clientdata(new_client, data); 749 i2c_set_clientdata(new_client, data);
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c
index bc7faef162f7..11dc95f8a17e 100644
--- a/drivers/hwmon/adm9240.c
+++ b/drivers/hwmon/adm9240.c
@@ -45,6 +45,7 @@
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/hwmon-sysfs.h>
48#include <linux/hwmon.h> 49#include <linux/hwmon.h>
49#include <linux/hwmon-vid.h> 50#include <linux/hwmon-vid.h>
50#include <linux/err.h> 51#include <linux/err.h>
@@ -69,8 +70,7 @@ I2C_CLIENT_INSMOD_3(adm9240, ds1780, lm81);
69#define ADM9240_REG_INT(nr) (0x41 + (nr)) 70#define ADM9240_REG_INT(nr) (0x41 + (nr))
70#define ADM9240_REG_INT_MASK(nr) (0x43 + (nr)) 71#define ADM9240_REG_INT_MASK(nr) (0x43 + (nr))
71#define ADM9240_REG_TEMP 0x27 72#define ADM9240_REG_TEMP 0x27
72#define ADM9240_REG_TEMP_HIGH 0x39 73#define ADM9240_REG_TEMP_MAX(nr) (0x39 + (nr)) /* 0, 1 = high, hyst */
73#define ADM9240_REG_TEMP_HYST 0x3a
74#define ADM9240_REG_ANALOG_OUT 0x19 74#define ADM9240_REG_ANALOG_OUT 0x19
75#define ADM9240_REG_CHASSIS_CLEAR 0x46 75#define ADM9240_REG_CHASSIS_CLEAR 0x46
76#define ADM9240_REG_VID_FAN_DIV 0x47 76#define ADM9240_REG_VID_FAN_DIV 0x47
@@ -162,177 +162,155 @@ struct adm9240_data {
162 u8 fan_min[2]; /* rw fan1_min */ 162 u8 fan_min[2]; /* rw fan1_min */
163 u8 fan_div[2]; /* rw fan1_div, read-only accessor */ 163 u8 fan_div[2]; /* rw fan1_div, read-only accessor */
164 s16 temp; /* ro temp1_input, 9-bit sign-extended */ 164 s16 temp; /* ro temp1_input, 9-bit sign-extended */
165 s8 temp_high; /* rw temp1_max */ 165 s8 temp_max[2]; /* rw 0 -> temp_max, 1 -> temp_max_hyst */
166 s8 temp_hyst; /* rw temp1_max_hyst */
167 u16 alarms; /* ro alarms */ 166 u16 alarms; /* ro alarms */
168 u8 aout; /* rw aout_output */ 167 u8 aout; /* rw aout_output */
169 u8 vid; /* ro vid */ 168 u8 vid; /* ro vid */
170 u8 vrm; /* -- vrm set on startup, no accessor */ 169 u8 vrm; /* -- vrm set on startup, no accessor */
171}; 170};
172 171
173/* i2c byte read/write interface */ 172/*** sysfs accessors ***/
174static int adm9240_read_value(struct i2c_client *client, u8 reg) 173
174/* temperature */
175static ssize_t show_temp(struct device *dev, struct device_attribute *dummy,
176 char *buf)
175{ 177{
176 return i2c_smbus_read_byte_data(client, reg); 178 struct adm9240_data *data = adm9240_update_device(dev);
179 return sprintf(buf, "%d\n", data->temp * 500); /* 9-bit value */
177} 180}
178 181
179static int adm9240_write_value(struct i2c_client *client, u8 reg, u8 value) 182static ssize_t show_max(struct device *dev, struct device_attribute *devattr,
183 char *buf)
180{ 184{
181 return i2c_smbus_write_byte_data(client, reg, value); 185 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
186 struct adm9240_data *data = adm9240_update_device(dev);
187 return sprintf(buf, "%d\n", data->temp_max[attr->index] * 1000);
182} 188}
183 189
184/*** sysfs accessors ***/ 190static ssize_t set_max(struct device *dev, struct device_attribute *devattr,
191 const char *buf, size_t count)
192{
193 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
194 struct i2c_client *client = to_i2c_client(dev);
195 struct adm9240_data *data = i2c_get_clientdata(client);
196 long val = simple_strtol(buf, NULL, 10);
197
198 down(&data->update_lock);
199 data->temp_max[attr->index] = TEMP_TO_REG(val);
200 i2c_smbus_write_byte_data(client, ADM9240_REG_TEMP_MAX(attr->index),
201 data->temp_max[attr->index]);
202 up(&data->update_lock);
203 return count;
204}
185 205
186/* temperature */
187#define show_temp(value, scale) \
188static ssize_t show_##value(struct device *dev, \
189 struct device_attribute *attr, \
190 char *buf) \
191{ \
192 struct adm9240_data *data = adm9240_update_device(dev); \
193 return sprintf(buf, "%d\n", data->value * scale); \
194}
195show_temp(temp_high, 1000);
196show_temp(temp_hyst, 1000);
197show_temp(temp, 500); /* 0.5'C per bit */
198
199#define set_temp(value, reg) \
200static ssize_t set_##value(struct device *dev, \
201 struct device_attribute *attr, \
202 const char *buf, size_t count) \
203{ \
204 struct i2c_client *client = to_i2c_client(dev); \
205 struct adm9240_data *data = adm9240_update_device(dev); \
206 long temp = simple_strtoul(buf, NULL, 10); \
207 \
208 down(&data->update_lock); \
209 data->value = TEMP_TO_REG(temp); \
210 adm9240_write_value(client, reg, data->value); \
211 up(&data->update_lock); \
212 return count; \
213}
214
215set_temp(temp_high, ADM9240_REG_TEMP_HIGH);
216set_temp(temp_hyst, ADM9240_REG_TEMP_HYST);
217
218static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO,
219 show_temp_high, set_temp_high);
220static DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO,
221 show_temp_hyst, set_temp_hyst);
222static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL); 206static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL);
207static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO,
208 show_max, set_max, 0);
209static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO,
210 show_max, set_max, 1);
223 211
224/* voltage */ 212/* voltage */
225static ssize_t show_in(struct device *dev, char *buf, int nr) 213static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
214 char *buf)
226{ 215{
216 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
227 struct adm9240_data *data = adm9240_update_device(dev); 217 struct adm9240_data *data = adm9240_update_device(dev);
228 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr], nr)); 218 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[attr->index],
219 attr->index));
229} 220}
230 221
231static ssize_t show_in_min(struct device *dev, char *buf, int nr) 222static ssize_t show_in_min(struct device *dev,
223 struct device_attribute *devattr, char *buf)
232{ 224{
225 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
233 struct adm9240_data *data = adm9240_update_device(dev); 226 struct adm9240_data *data = adm9240_update_device(dev);
234 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr], nr)); 227 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[attr->index],
228 attr->index));
235} 229}
236 230
237static ssize_t show_in_max(struct device *dev, char *buf, int nr) 231static ssize_t show_in_max(struct device *dev,
232 struct device_attribute *devattr, char *buf)
238{ 233{
234 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
239 struct adm9240_data *data = adm9240_update_device(dev); 235 struct adm9240_data *data = adm9240_update_device(dev);
240 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr], nr)); 236 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[attr->index],
237 attr->index));
241} 238}
242 239
243static ssize_t set_in_min(struct device *dev, const char *buf, 240static ssize_t set_in_min(struct device *dev,
244 size_t count, int nr) 241 struct device_attribute *devattr,
242 const char *buf, size_t count)
245{ 243{
244 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
246 struct i2c_client *client = to_i2c_client(dev); 245 struct i2c_client *client = to_i2c_client(dev);
247 struct adm9240_data *data = i2c_get_clientdata(client); 246 struct adm9240_data *data = i2c_get_clientdata(client);
248 unsigned long val = simple_strtoul(buf, NULL, 10); 247 unsigned long val = simple_strtoul(buf, NULL, 10);
249 248
250 down(&data->update_lock); 249 down(&data->update_lock);
251 data->in_min[nr] = IN_TO_REG(val, nr); 250 data->in_min[attr->index] = IN_TO_REG(val, attr->index);
252 adm9240_write_value(client, ADM9240_REG_IN_MIN(nr), data->in_min[nr]); 251 i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MIN(attr->index),
252 data->in_min[attr->index]);
253 up(&data->update_lock); 253 up(&data->update_lock);
254 return count; 254 return count;
255} 255}
256 256
257static ssize_t set_in_max(struct device *dev, const char *buf, 257static ssize_t set_in_max(struct device *dev,
258 size_t count, int nr) 258 struct device_attribute *devattr,
259 const char *buf, size_t count)
259{ 260{
261 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
260 struct i2c_client *client = to_i2c_client(dev); 262 struct i2c_client *client = to_i2c_client(dev);
261 struct adm9240_data *data = i2c_get_clientdata(client); 263 struct adm9240_data *data = i2c_get_clientdata(client);
262 unsigned long val = simple_strtoul(buf, NULL, 10); 264 unsigned long val = simple_strtoul(buf, NULL, 10);
263 265
264 down(&data->update_lock); 266 down(&data->update_lock);
265 data->in_max[nr] = IN_TO_REG(val, nr); 267 data->in_max[attr->index] = IN_TO_REG(val, attr->index);
266 adm9240_write_value(client, ADM9240_REG_IN_MAX(nr), data->in_max[nr]); 268 i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MAX(attr->index),
269 data->in_max[attr->index]);
267 up(&data->update_lock); 270 up(&data->update_lock);
268 return count; 271 return count;
269} 272}
270 273
271#define show_in_offset(offset) \ 274#define vin(nr) \
272static ssize_t show_in##offset(struct device *dev, \ 275static SENSOR_DEVICE_ATTR(in##nr##_input, S_IRUGO, \
273 struct device_attribute *attr, \ 276 show_in, NULL, nr); \
274 char *buf) \ 277static SENSOR_DEVICE_ATTR(in##nr##_min, S_IRUGO | S_IWUSR, \
275{ \ 278 show_in_min, set_in_min, nr); \
276 return show_in(dev, buf, offset); \ 279static SENSOR_DEVICE_ATTR(in##nr##_max, S_IRUGO | S_IWUSR, \
277} \ 280 show_in_max, set_in_max, nr);
278static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL); \ 281
279static ssize_t show_in##offset##_min(struct device *dev, \ 282vin(0);
280 struct device_attribute *attr, \ 283vin(1);
281 char *buf) \ 284vin(2);
282{ \ 285vin(3);
283 return show_in_min(dev, buf, offset); \ 286vin(4);
284} \ 287vin(5);
285static ssize_t show_in##offset##_max(struct device *dev, \
286 struct device_attribute *attr, \
287 char *buf) \
288{ \
289 return show_in_max(dev, buf, offset); \
290} \
291static ssize_t \
292set_in##offset##_min(struct device *dev, \
293 struct device_attribute *attr, const char *buf, \
294 size_t count) \
295{ \
296 return set_in_min(dev, buf, count, offset); \
297} \
298static ssize_t \
299set_in##offset##_max(struct device *dev, \
300 struct device_attribute *attr, const char *buf, \
301 size_t count) \
302{ \
303 return set_in_max(dev, buf, count, offset); \
304} \
305static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
306 show_in##offset##_min, set_in##offset##_min); \
307static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
308 show_in##offset##_max, set_in##offset##_max);
309
310show_in_offset(0);
311show_in_offset(1);
312show_in_offset(2);
313show_in_offset(3);
314show_in_offset(4);
315show_in_offset(5);
316 288
317/* fans */ 289/* fans */
318static ssize_t show_fan(struct device *dev, char *buf, int nr) 290static ssize_t show_fan(struct device *dev,
291 struct device_attribute *devattr, char *buf)
319{ 292{
293 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
320 struct adm9240_data *data = adm9240_update_device(dev); 294 struct adm9240_data *data = adm9240_update_device(dev);
321 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], 295 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[attr->index],
322 1 << data->fan_div[nr])); 296 1 << data->fan_div[attr->index]));
323} 297}
324 298
325static ssize_t show_fan_min(struct device *dev, char *buf, int nr) 299static ssize_t show_fan_min(struct device *dev,
300 struct device_attribute *devattr, char *buf)
326{ 301{
302 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
327 struct adm9240_data *data = adm9240_update_device(dev); 303 struct adm9240_data *data = adm9240_update_device(dev);
328 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr], 304 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[attr->index],
329 1 << data->fan_div[nr])); 305 1 << data->fan_div[attr->index]));
330} 306}
331 307
332static ssize_t show_fan_div(struct device *dev, char *buf, int nr) 308static ssize_t show_fan_div(struct device *dev,
309 struct device_attribute *devattr, char *buf)
333{ 310{
311 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
334 struct adm9240_data *data = adm9240_update_device(dev); 312 struct adm9240_data *data = adm9240_update_device(dev);
335 return sprintf(buf, "%d\n", 1 << data->fan_div[nr]); 313 return sprintf(buf, "%d\n", 1 << data->fan_div[attr->index]);
336} 314}
337 315
338/* write new fan div, callers must hold data->update_lock */ 316/* write new fan div, callers must hold data->update_lock */
@@ -341,16 +319,16 @@ static void adm9240_write_fan_div(struct i2c_client *client, int nr,
341{ 319{
342 u8 reg, old, shift = (nr + 2) * 2; 320 u8 reg, old, shift = (nr + 2) * 2;
343 321
344 reg = adm9240_read_value(client, ADM9240_REG_VID_FAN_DIV); 322 reg = i2c_smbus_read_byte_data(client, ADM9240_REG_VID_FAN_DIV);
345 old = (reg >> shift) & 3; 323 old = (reg >> shift) & 3;
346 reg &= ~(3 << shift); 324 reg &= ~(3 << shift);
347 reg |= (fan_div << shift); 325 reg |= (fan_div << shift);
348 adm9240_write_value(client, ADM9240_REG_VID_FAN_DIV, reg); 326 i2c_smbus_write_byte_data(client, ADM9240_REG_VID_FAN_DIV, reg);
349 dev_dbg(&client->dev, "fan%d clock divider changed from %u " 327 dev_dbg(&client->dev, "fan%d clock divider changed from %u "
350 "to %u\n", nr + 1, 1 << old, 1 << fan_div); 328 "to %u\n", nr + 1, 1 << old, 1 << fan_div);
351} 329}
352 330
353/* 331/*
354 * set fan speed low limit: 332 * set fan speed low limit:
355 * 333 *
356 * - value is zero: disable fan speed low limit alarm 334 * - value is zero: disable fan speed low limit alarm
@@ -361,12 +339,15 @@ static void adm9240_write_fan_div(struct i2c_client *client, int nr,
361 * - otherwise: select fan clock divider to suit fan speed low limit, 339 * - otherwise: select fan clock divider to suit fan speed low limit,
362 * measurement code may adjust registers to ensure fan speed reading 340 * measurement code may adjust registers to ensure fan speed reading
363 */ 341 */
364static ssize_t set_fan_min(struct device *dev, const char *buf, 342static ssize_t set_fan_min(struct device *dev,
365 size_t count, int nr) 343 struct device_attribute *devattr,
344 const char *buf, size_t count)
366{ 345{
346 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
367 struct i2c_client *client = to_i2c_client(dev); 347 struct i2c_client *client = to_i2c_client(dev);
368 struct adm9240_data *data = i2c_get_clientdata(client); 348 struct adm9240_data *data = i2c_get_clientdata(client);
369 unsigned long val = simple_strtoul(buf, NULL, 10); 349 unsigned long val = simple_strtoul(buf, NULL, 10);
350 int nr = attr->index;
370 u8 new_div; 351 u8 new_div;
371 352
372 down(&data->update_lock); 353 down(&data->update_lock);
@@ -406,50 +387,27 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
406 data->fan_div[nr] = new_div; 387 data->fan_div[nr] = new_div;
407 adm9240_write_fan_div(client, nr, new_div); 388 adm9240_write_fan_div(client, nr, new_div);
408 } 389 }
409 adm9240_write_value(client, ADM9240_REG_FAN_MIN(nr), 390 i2c_smbus_write_byte_data(client, ADM9240_REG_FAN_MIN(nr),
410 data->fan_min[nr]); 391 data->fan_min[nr]);
411 392
412 up(&data->update_lock); 393 up(&data->update_lock);
413 return count; 394 return count;
414} 395}
415 396
416#define show_fan_offset(offset) \ 397#define fan(nr) \
417static ssize_t show_fan_##offset (struct device *dev, \ 398static SENSOR_DEVICE_ATTR(fan##nr##_input, S_IRUGO, \
418 struct device_attribute *attr, \ 399 show_fan, NULL, nr - 1); \
419 char *buf) \ 400static SENSOR_DEVICE_ATTR(fan##nr##_div, S_IRUGO, \
420{ \ 401 show_fan_div, NULL, nr - 1); \
421return show_fan(dev, buf, offset - 1); \ 402static SENSOR_DEVICE_ATTR(fan##nr##_min, S_IRUGO | S_IWUSR, \
422} \ 403 show_fan_min, set_fan_min, nr - 1);
423static ssize_t show_fan_##offset##_div (struct device *dev, \ 404
424 struct device_attribute *attr, \ 405fan(1);
425 char *buf) \ 406fan(2);
426{ \
427return show_fan_div(dev, buf, offset - 1); \
428} \
429static ssize_t show_fan_##offset##_min (struct device *dev, \
430 struct device_attribute *attr, \
431 char *buf) \
432{ \
433return show_fan_min(dev, buf, offset - 1); \
434} \
435static ssize_t set_fan_##offset##_min (struct device *dev, \
436 struct device_attribute *attr, \
437 const char *buf, size_t count) \
438{ \
439return set_fan_min(dev, buf, count, offset - 1); \
440} \
441static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
442 show_fan_##offset, NULL); \
443static DEVICE_ATTR(fan##offset##_div, S_IRUGO, \
444 show_fan_##offset##_div, NULL); \
445static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
446 show_fan_##offset##_min, set_fan_##offset##_min);
447
448show_fan_offset(1);
449show_fan_offset(2);
450 407
451/* alarms */ 408/* alarms */
452static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 409static ssize_t show_alarms(struct device *dev,
410 struct device_attribute *attr, char *buf)
453{ 411{
454 struct adm9240_data *data = adm9240_update_device(dev); 412 struct adm9240_data *data = adm9240_update_device(dev);
455 return sprintf(buf, "%u\n", data->alarms); 413 return sprintf(buf, "%u\n", data->alarms);
@@ -457,7 +415,8 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch
457static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 415static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
458 416
459/* vid */ 417/* vid */
460static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) 418static ssize_t show_vid(struct device *dev,
419 struct device_attribute *attr, char *buf)
461{ 420{
462 struct adm9240_data *data = adm9240_update_device(dev); 421 struct adm9240_data *data = adm9240_update_device(dev);
463 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); 422 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
@@ -465,13 +424,16 @@ static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char
465static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 424static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
466 425
467/* analog output */ 426/* analog output */
468static ssize_t show_aout(struct device *dev, struct device_attribute *attr, char *buf) 427static ssize_t show_aout(struct device *dev,
428 struct device_attribute *attr, char *buf)
469{ 429{
470 struct adm9240_data *data = adm9240_update_device(dev); 430 struct adm9240_data *data = adm9240_update_device(dev);
471 return sprintf(buf, "%d\n", AOUT_FROM_REG(data->aout)); 431 return sprintf(buf, "%d\n", AOUT_FROM_REG(data->aout));
472} 432}
473 433
474static ssize_t set_aout(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 434static ssize_t set_aout(struct device *dev,
435 struct device_attribute *attr,
436 const char *buf, size_t count)
475{ 437{
476 struct i2c_client *client = to_i2c_client(dev); 438 struct i2c_client *client = to_i2c_client(dev);
477 struct adm9240_data *data = i2c_get_clientdata(client); 439 struct adm9240_data *data = i2c_get_clientdata(client);
@@ -479,20 +441,23 @@ static ssize_t set_aout(struct device *dev, struct device_attribute *attr, const
479 441
480 down(&data->update_lock); 442 down(&data->update_lock);
481 data->aout = AOUT_TO_REG(val); 443 data->aout = AOUT_TO_REG(val);
482 adm9240_write_value(client, ADM9240_REG_ANALOG_OUT, data->aout); 444 i2c_smbus_write_byte_data(client, ADM9240_REG_ANALOG_OUT, data->aout);
483 up(&data->update_lock); 445 up(&data->update_lock);
484 return count; 446 return count;
485} 447}
486static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout); 448static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout);
487 449
488/* chassis_clear */ 450/* chassis_clear */
489static ssize_t chassis_clear(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 451static ssize_t chassis_clear(struct device *dev,
452 struct device_attribute *attr,
453 const char *buf, size_t count)
490{ 454{
491 struct i2c_client *client = to_i2c_client(dev); 455 struct i2c_client *client = to_i2c_client(dev);
492 unsigned long val = simple_strtol(buf, NULL, 10); 456 unsigned long val = simple_strtol(buf, NULL, 10);
493 457
494 if (val == 1) { 458 if (val == 1) {
495 adm9240_write_value(client, ADM9240_REG_CHASSIS_CLEAR, 0x80); 459 i2c_smbus_write_byte_data(client,
460 ADM9240_REG_CHASSIS_CLEAR, 0x80);
496 dev_dbg(&client->dev, "chassis intrusion latch cleared\n"); 461 dev_dbg(&client->dev, "chassis intrusion latch cleared\n");
497 } 462 }
498 return count; 463 return count;
@@ -513,11 +478,10 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind)
513 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 478 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
514 goto exit; 479 goto exit;
515 480
516 if (!(data = kmalloc(sizeof(struct adm9240_data), GFP_KERNEL))) { 481 if (!(data = kzalloc(sizeof(*data), GFP_KERNEL))) {
517 err = -ENOMEM; 482 err = -ENOMEM;
518 goto exit; 483 goto exit;
519 } 484 }
520 memset(data, 0, sizeof(struct adm9240_data));
521 485
522 new_client = &data->client; 486 new_client = &data->client;
523 i2c_set_clientdata(new_client, data); 487 i2c_set_clientdata(new_client, data);
@@ -533,7 +497,7 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind)
533 if (kind < 0) { 497 if (kind < 0) {
534 498
535 /* verify chip: reg address should match i2c address */ 499 /* verify chip: reg address should match i2c address */
536 if (adm9240_read_value(new_client, ADM9240_REG_I2C_ADDR) 500 if (i2c_smbus_read_byte_data(new_client, ADM9240_REG_I2C_ADDR)
537 != address) { 501 != address) {
538 dev_err(&adapter->dev, "detect fail: address match, " 502 dev_err(&adapter->dev, "detect fail: address match, "
539 "0x%02x\n", address); 503 "0x%02x\n", address);
@@ -541,8 +505,8 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind)
541 } 505 }
542 506
543 /* check known chip manufacturer */ 507 /* check known chip manufacturer */
544 man_id = adm9240_read_value(new_client, ADM9240_REG_MAN_ID); 508 man_id = i2c_smbus_read_byte_data(new_client,
545 509 ADM9240_REG_MAN_ID);
546 if (man_id == 0x23) { 510 if (man_id == 0x23) {
547 kind = adm9240; 511 kind = adm9240;
548 } else if (man_id == 0xda) { 512 } else if (man_id == 0xda) {
@@ -556,7 +520,8 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind)
556 } 520 }
557 521
558 /* successful detect, print chip info */ 522 /* successful detect, print chip info */
559 die_rev = adm9240_read_value(new_client, ADM9240_REG_DIE_REV); 523 die_rev = i2c_smbus_read_byte_data(new_client,
524 ADM9240_REG_DIE_REV);
560 dev_info(&adapter->dev, "found %s revision %u\n", 525 dev_info(&adapter->dev, "found %s revision %u\n",
561 man_id == 0x23 ? "ADM9240" : 526 man_id == 0x23 ? "ADM9240" :
562 man_id == 0xda ? "DS1780" : "LM81", die_rev); 527 man_id == 0xda ? "DS1780" : "LM81", die_rev);
@@ -588,33 +553,59 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind)
588 goto exit_detach; 553 goto exit_detach;
589 } 554 }
590 555
591 device_create_file(&new_client->dev, &dev_attr_in0_input); 556 device_create_file(&new_client->dev,
592 device_create_file(&new_client->dev, &dev_attr_in0_min); 557 &sensor_dev_attr_in0_input.dev_attr);
593 device_create_file(&new_client->dev, &dev_attr_in0_max); 558 device_create_file(&new_client->dev,
594 device_create_file(&new_client->dev, &dev_attr_in1_input); 559 &sensor_dev_attr_in0_min.dev_attr);
595 device_create_file(&new_client->dev, &dev_attr_in1_min); 560 device_create_file(&new_client->dev,
596 device_create_file(&new_client->dev, &dev_attr_in1_max); 561 &sensor_dev_attr_in0_max.dev_attr);
597 device_create_file(&new_client->dev, &dev_attr_in2_input); 562 device_create_file(&new_client->dev,
598 device_create_file(&new_client->dev, &dev_attr_in2_min); 563 &sensor_dev_attr_in1_input.dev_attr);
599 device_create_file(&new_client->dev, &dev_attr_in2_max); 564 device_create_file(&new_client->dev,
600 device_create_file(&new_client->dev, &dev_attr_in3_input); 565 &sensor_dev_attr_in1_min.dev_attr);
601 device_create_file(&new_client->dev, &dev_attr_in3_min); 566 device_create_file(&new_client->dev,
602 device_create_file(&new_client->dev, &dev_attr_in3_max); 567 &sensor_dev_attr_in1_max.dev_attr);
603 device_create_file(&new_client->dev, &dev_attr_in4_input); 568 device_create_file(&new_client->dev,
604 device_create_file(&new_client->dev, &dev_attr_in4_min); 569 &sensor_dev_attr_in2_input.dev_attr);
605 device_create_file(&new_client->dev, &dev_attr_in4_max); 570 device_create_file(&new_client->dev,
606 device_create_file(&new_client->dev, &dev_attr_in5_input); 571 &sensor_dev_attr_in2_min.dev_attr);
607 device_create_file(&new_client->dev, &dev_attr_in5_min); 572 device_create_file(&new_client->dev,
608 device_create_file(&new_client->dev, &dev_attr_in5_max); 573 &sensor_dev_attr_in2_max.dev_attr);
609 device_create_file(&new_client->dev, &dev_attr_temp1_max); 574 device_create_file(&new_client->dev,
610 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst); 575 &sensor_dev_attr_in3_input.dev_attr);
576 device_create_file(&new_client->dev,
577 &sensor_dev_attr_in3_min.dev_attr);
578 device_create_file(&new_client->dev,
579 &sensor_dev_attr_in3_max.dev_attr);
580 device_create_file(&new_client->dev,
581 &sensor_dev_attr_in4_input.dev_attr);
582 device_create_file(&new_client->dev,
583 &sensor_dev_attr_in4_min.dev_attr);
584 device_create_file(&new_client->dev,
585 &sensor_dev_attr_in4_max.dev_attr);
586 device_create_file(&new_client->dev,
587 &sensor_dev_attr_in5_input.dev_attr);
588 device_create_file(&new_client->dev,
589 &sensor_dev_attr_in5_min.dev_attr);
590 device_create_file(&new_client->dev,
591 &sensor_dev_attr_in5_max.dev_attr);
611 device_create_file(&new_client->dev, &dev_attr_temp1_input); 592 device_create_file(&new_client->dev, &dev_attr_temp1_input);
612 device_create_file(&new_client->dev, &dev_attr_fan1_input); 593 device_create_file(&new_client->dev,
613 device_create_file(&new_client->dev, &dev_attr_fan1_div); 594 &sensor_dev_attr_temp1_max.dev_attr);
614 device_create_file(&new_client->dev, &dev_attr_fan1_min); 595 device_create_file(&new_client->dev,
615 device_create_file(&new_client->dev, &dev_attr_fan2_input); 596 &sensor_dev_attr_temp1_max_hyst.dev_attr);
616 device_create_file(&new_client->dev, &dev_attr_fan2_div); 597 device_create_file(&new_client->dev,
617 device_create_file(&new_client->dev, &dev_attr_fan2_min); 598 &sensor_dev_attr_fan1_input.dev_attr);
599 device_create_file(&new_client->dev,
600 &sensor_dev_attr_fan1_div.dev_attr);
601 device_create_file(&new_client->dev,
602 &sensor_dev_attr_fan1_min.dev_attr);
603 device_create_file(&new_client->dev,
604 &sensor_dev_attr_fan2_input.dev_attr);
605 device_create_file(&new_client->dev,
606 &sensor_dev_attr_fan2_div.dev_attr);
607 device_create_file(&new_client->dev,
608 &sensor_dev_attr_fan2_min.dev_attr);
618 device_create_file(&new_client->dev, &dev_attr_alarms); 609 device_create_file(&new_client->dev, &dev_attr_alarms);
619 device_create_file(&new_client->dev, &dev_attr_aout_output); 610 device_create_file(&new_client->dev, &dev_attr_aout_output);
620 device_create_file(&new_client->dev, &dev_attr_chassis_clear); 611 device_create_file(&new_client->dev, &dev_attr_chassis_clear);
@@ -654,8 +645,8 @@ static int adm9240_detach_client(struct i2c_client *client)
654static void adm9240_init_client(struct i2c_client *client) 645static void adm9240_init_client(struct i2c_client *client)
655{ 646{
656 struct adm9240_data *data = i2c_get_clientdata(client); 647 struct adm9240_data *data = i2c_get_clientdata(client);
657 u8 conf = adm9240_read_value(client, ADM9240_REG_CONFIG); 648 u8 conf = i2c_smbus_read_byte_data(client, ADM9240_REG_CONFIG);
658 u8 mode = adm9240_read_value(client, ADM9240_REG_TEMP_CONF) & 3; 649 u8 mode = i2c_smbus_read_byte_data(client, ADM9240_REG_TEMP_CONF) & 3;
659 650
660 data->vrm = vid_which_vrm(); /* need this to report vid as mV */ 651 data->vrm = vid_which_vrm(); /* need this to report vid as mV */
661 652
@@ -672,18 +663,22 @@ static void adm9240_init_client(struct i2c_client *client)
672 663
673 for (i = 0; i < 6; i++) 664 for (i = 0; i < 6; i++)
674 { 665 {
675 adm9240_write_value(client, 666 i2c_smbus_write_byte_data(client,
676 ADM9240_REG_IN_MIN(i), 0); 667 ADM9240_REG_IN_MIN(i), 0);
677 adm9240_write_value(client, 668 i2c_smbus_write_byte_data(client,
678 ADM9240_REG_IN_MAX(i), 255); 669 ADM9240_REG_IN_MAX(i), 255);
679 } 670 }
680 adm9240_write_value(client, ADM9240_REG_FAN_MIN(0), 255); 671 i2c_smbus_write_byte_data(client,
681 adm9240_write_value(client, ADM9240_REG_FAN_MIN(1), 255); 672 ADM9240_REG_FAN_MIN(0), 255);
682 adm9240_write_value(client, ADM9240_REG_TEMP_HIGH, 127); 673 i2c_smbus_write_byte_data(client,
683 adm9240_write_value(client, ADM9240_REG_TEMP_HYST, 127); 674 ADM9240_REG_FAN_MIN(1), 255);
675 i2c_smbus_write_byte_data(client,
676 ADM9240_REG_TEMP_MAX(0), 127);
677 i2c_smbus_write_byte_data(client,
678 ADM9240_REG_TEMP_MAX(1), 127);
684 679
685 /* start measurement cycle */ 680 /* start measurement cycle */
686 adm9240_write_value(client, ADM9240_REG_CONFIG, 1); 681 i2c_smbus_write_byte_data(client, ADM9240_REG_CONFIG, 1);
687 682
688 dev_info(&client->dev, "cold start: config was 0x%02x " 683 dev_info(&client->dev, "cold start: config was 0x%02x "
689 "mode %u\n", conf, mode); 684 "mode %u\n", conf, mode);
@@ -704,25 +699,25 @@ static struct adm9240_data *adm9240_update_device(struct device *dev)
704 699
705 for (i = 0; i < 6; i++) /* read voltages */ 700 for (i = 0; i < 6; i++) /* read voltages */
706 { 701 {
707 data->in[i] = adm9240_read_value(client, 702 data->in[i] = i2c_smbus_read_byte_data(client,
708 ADM9240_REG_IN(i)); 703 ADM9240_REG_IN(i));
709 } 704 }
710 data->alarms = adm9240_read_value(client, 705 data->alarms = i2c_smbus_read_byte_data(client,
711 ADM9240_REG_INT(0)) | 706 ADM9240_REG_INT(0)) |
712 adm9240_read_value(client, 707 i2c_smbus_read_byte_data(client,
713 ADM9240_REG_INT(1)) << 8; 708 ADM9240_REG_INT(1)) << 8;
714 709
715 /* read temperature: assume temperature changes less than 710 /* read temperature: assume temperature changes less than
716 * 0.5'C per two measurement cycles thus ignore possible 711 * 0.5'C per two measurement cycles thus ignore possible
717 * but unlikely aliasing error on lsb reading. --Grant */ 712 * but unlikely aliasing error on lsb reading. --Grant */
718 data->temp = ((adm9240_read_value(client, 713 data->temp = ((i2c_smbus_read_byte_data(client,
719 ADM9240_REG_TEMP) << 8) | 714 ADM9240_REG_TEMP) << 8) |
720 adm9240_read_value(client, 715 i2c_smbus_read_byte_data(client,
721 ADM9240_REG_TEMP_CONF)) / 128; 716 ADM9240_REG_TEMP_CONF)) / 128;
722 717
723 for (i = 0; i < 2; i++) /* read fans */ 718 for (i = 0; i < 2; i++) /* read fans */
724 { 719 {
725 data->fan[i] = adm9240_read_value(client, 720 data->fan[i] = i2c_smbus_read_byte_data(client,
726 ADM9240_REG_FAN(i)); 721 ADM9240_REG_FAN(i));
727 722
728 /* adjust fan clock divider on overflow */ 723 /* adjust fan clock divider on overflow */
@@ -747,30 +742,30 @@ static struct adm9240_data *adm9240_update_device(struct device *dev)
747 742
748 for (i = 0; i < 6; i++) 743 for (i = 0; i < 6; i++)
749 { 744 {
750 data->in_min[i] = adm9240_read_value(client, 745 data->in_min[i] = i2c_smbus_read_byte_data(client,
751 ADM9240_REG_IN_MIN(i)); 746 ADM9240_REG_IN_MIN(i));
752 data->in_max[i] = adm9240_read_value(client, 747 data->in_max[i] = i2c_smbus_read_byte_data(client,
753 ADM9240_REG_IN_MAX(i)); 748 ADM9240_REG_IN_MAX(i));
754 } 749 }
755 for (i = 0; i < 2; i++) 750 for (i = 0; i < 2; i++)
756 { 751 {
757 data->fan_min[i] = adm9240_read_value(client, 752 data->fan_min[i] = i2c_smbus_read_byte_data(client,
758 ADM9240_REG_FAN_MIN(i)); 753 ADM9240_REG_FAN_MIN(i));
759 } 754 }
760 data->temp_high = adm9240_read_value(client, 755 data->temp_max[0] = i2c_smbus_read_byte_data(client,
761 ADM9240_REG_TEMP_HIGH); 756 ADM9240_REG_TEMP_MAX(0));
762 data->temp_hyst = adm9240_read_value(client, 757 data->temp_max[1] = i2c_smbus_read_byte_data(client,
763 ADM9240_REG_TEMP_HYST); 758 ADM9240_REG_TEMP_MAX(1));
764 759
765 /* read fan divs and 5-bit VID */ 760 /* read fan divs and 5-bit VID */
766 i = adm9240_read_value(client, ADM9240_REG_VID_FAN_DIV); 761 i = i2c_smbus_read_byte_data(client, ADM9240_REG_VID_FAN_DIV);
767 data->fan_div[0] = (i >> 4) & 3; 762 data->fan_div[0] = (i >> 4) & 3;
768 data->fan_div[1] = (i >> 6) & 3; 763 data->fan_div[1] = (i >> 6) & 3;
769 data->vid = i & 0x0f; 764 data->vid = i & 0x0f;
770 data->vid |= (adm9240_read_value(client, 765 data->vid |= (i2c_smbus_read_byte_data(client,
771 ADM9240_REG_VID4) & 1) << 4; 766 ADM9240_REG_VID4) & 1) << 4;
772 /* read analog out */ 767 /* read analog out */
773 data->aout = adm9240_read_value(client, 768 data->aout = i2c_smbus_read_byte_data(client,
774 ADM9240_REG_ANALOG_OUT); 769 ADM9240_REG_ANALOG_OUT);
775 770
776 data->last_updated_config = jiffies; 771 data->last_updated_config = jiffies;
diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c
index 8e34855a6274..52c469722a65 100644
--- a/drivers/hwmon/asb100.c
+++ b/drivers/hwmon/asb100.c
@@ -629,19 +629,17 @@ static int asb100_detect_subclients(struct i2c_adapter *adapter, int address,
629 int i, id, err; 629 int i, id, err;
630 struct asb100_data *data = i2c_get_clientdata(new_client); 630 struct asb100_data *data = i2c_get_clientdata(new_client);
631 631
632 data->lm75[0] = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); 632 data->lm75[0] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
633 if (!(data->lm75[0])) { 633 if (!(data->lm75[0])) {
634 err = -ENOMEM; 634 err = -ENOMEM;
635 goto ERROR_SC_0; 635 goto ERROR_SC_0;
636 } 636 }
637 memset(data->lm75[0], 0x00, sizeof(struct i2c_client));
638 637
639 data->lm75[1] = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); 638 data->lm75[1] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
640 if (!(data->lm75[1])) { 639 if (!(data->lm75[1])) {
641 err = -ENOMEM; 640 err = -ENOMEM;
642 goto ERROR_SC_1; 641 goto ERROR_SC_1;
643 } 642 }
644 memset(data->lm75[1], 0x00, sizeof(struct i2c_client));
645 643
646 id = i2c_adapter_id(adapter); 644 id = i2c_adapter_id(adapter);
647 645
@@ -724,12 +722,11 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
724 client structure, even though we cannot fill it completely yet. 722 client structure, even though we cannot fill it completely yet.
725 But it allows us to access asb100_{read,write}_value. */ 723 But it allows us to access asb100_{read,write}_value. */
726 724
727 if (!(data = kmalloc(sizeof(struct asb100_data), GFP_KERNEL))) { 725 if (!(data = kzalloc(sizeof(struct asb100_data), GFP_KERNEL))) {
728 pr_debug("asb100.o: detect failed, kmalloc failed!\n"); 726 pr_debug("asb100.o: detect failed, kzalloc failed!\n");
729 err = -ENOMEM; 727 err = -ENOMEM;
730 goto ERROR0; 728 goto ERROR0;
731 } 729 }
732 memset(data, 0, sizeof(struct asb100_data));
733 730
734 new_client = &data->client; 731 new_client = &data->client;
735 init_MUTEX(&data->lock); 732 init_MUTEX(&data->lock);
diff --git a/drivers/hwmon/atxp1.c b/drivers/hwmon/atxp1.c
index deb4d34c9539..53324f56404e 100644
--- a/drivers/hwmon/atxp1.c
+++ b/drivers/hwmon/atxp1.c
@@ -253,6 +253,8 @@ static DEVICE_ATTR(gpio2, S_IRUGO | S_IWUSR, atxp1_showgpio2, atxp1_storegpio2);
253 253
254static int atxp1_attach_adapter(struct i2c_adapter *adapter) 254static int atxp1_attach_adapter(struct i2c_adapter *adapter)
255{ 255{
256 if (!(adapter->class & I2C_CLASS_HWMON))
257 return 0;
256 return i2c_probe(adapter, &addr_data, &atxp1_detect); 258 return i2c_probe(adapter, &addr_data, &atxp1_detect);
257}; 259};
258 260
@@ -266,12 +268,11 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind)
266 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 268 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
267 goto exit; 269 goto exit;
268 270
269 if (!(data = kmalloc(sizeof(struct atxp1_data), GFP_KERNEL))) { 271 if (!(data = kzalloc(sizeof(struct atxp1_data), GFP_KERNEL))) {
270 err = -ENOMEM; 272 err = -ENOMEM;
271 goto exit; 273 goto exit;
272 } 274 }
273 275
274 memset(data, 0, sizeof(struct atxp1_data));
275 new_client = &data->client; 276 new_client = &data->client;
276 i2c_set_clientdata(new_client, data); 277 i2c_set_clientdata(new_client, data);
277 278
diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c
index b0199e063d0e..34f71b7c7f37 100644
--- a/drivers/hwmon/ds1621.c
+++ b/drivers/hwmon/ds1621.c
@@ -180,12 +180,14 @@ static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max);
180 180
181static int ds1621_attach_adapter(struct i2c_adapter *adapter) 181static int ds1621_attach_adapter(struct i2c_adapter *adapter)
182{ 182{
183 if (!(adapter->class & I2C_CLASS_HWMON))
184 return 0;
183 return i2c_probe(adapter, &addr_data, ds1621_detect); 185 return i2c_probe(adapter, &addr_data, ds1621_detect);
184} 186}
185 187
186/* This function is called by i2c_probe */ 188/* This function is called by i2c_probe */
187int ds1621_detect(struct i2c_adapter *adapter, int address, 189static int ds1621_detect(struct i2c_adapter *adapter, int address,
188 int kind) 190 int kind)
189{ 191{
190 int conf, temp; 192 int conf, temp;
191 struct i2c_client *new_client; 193 struct i2c_client *new_client;
@@ -200,11 +202,10 @@ int ds1621_detect(struct i2c_adapter *adapter, int address,
200 /* OK. For now, we presume we have a valid client. We now create the 202 /* OK. For now, we presume we have a valid client. We now create the
201 client structure, even though we cannot fill it completely yet. 203 client structure, even though we cannot fill it completely yet.
202 But it allows us to access ds1621_{read,write}_value. */ 204 But it allows us to access ds1621_{read,write}_value. */
203 if (!(data = kmalloc(sizeof(struct ds1621_data), GFP_KERNEL))) { 205 if (!(data = kzalloc(sizeof(struct ds1621_data), GFP_KERNEL))) {
204 err = -ENOMEM; 206 err = -ENOMEM;
205 goto exit; 207 goto exit;
206 } 208 }
207 memset(data, 0, sizeof(struct ds1621_data));
208 209
209 new_client = &data->client; 210 new_client = &data->client;
210 i2c_set_clientdata(new_client, data); 211 i2c_set_clientdata(new_client, data);
diff --git a/drivers/hwmon/fscher.c b/drivers/hwmon/fscher.c
index eef6061d786b..a02e1c34c757 100644
--- a/drivers/hwmon/fscher.c
+++ b/drivers/hwmon/fscher.c
@@ -303,11 +303,10 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
303 /* OK. For now, we presume we have a valid client. We now create the 303 /* OK. For now, we presume we have a valid client. We now create the
304 * client structure, even though we cannot fill it completely yet. 304 * client structure, even though we cannot fill it completely yet.
305 * But it allows us to access i2c_smbus_read_byte_data. */ 305 * But it allows us to access i2c_smbus_read_byte_data. */
306 if (!(data = kmalloc(sizeof(struct fscher_data), GFP_KERNEL))) { 306 if (!(data = kzalloc(sizeof(struct fscher_data), GFP_KERNEL))) {
307 err = -ENOMEM; 307 err = -ENOMEM;
308 goto exit; 308 goto exit;
309 } 309 }
310 memset(data, 0, sizeof(struct fscher_data));
311 310
312 /* The common I2C client data is placed right before the 311 /* The common I2C client data is placed right before the
313 * Hermes-specific data. */ 312 * Hermes-specific data. */
diff --git a/drivers/hwmon/fscpos.c b/drivers/hwmon/fscpos.c
index 5fc77a5fed07..64e4edc64f8d 100644
--- a/drivers/hwmon/fscpos.c
+++ b/drivers/hwmon/fscpos.c
@@ -438,7 +438,7 @@ static int fscpos_attach_adapter(struct i2c_adapter *adapter)
438 return i2c_probe(adapter, &addr_data, fscpos_detect); 438 return i2c_probe(adapter, &addr_data, fscpos_detect);
439} 439}
440 440
441int fscpos_detect(struct i2c_adapter *adapter, int address, int kind) 441static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind)
442{ 442{
443 struct i2c_client *new_client; 443 struct i2c_client *new_client;
444 struct fscpos_data *data; 444 struct fscpos_data *data;
@@ -453,11 +453,10 @@ int fscpos_detect(struct i2c_adapter *adapter, int address, int kind)
453 * But it allows us to access fscpos_{read,write}_value. 453 * But it allows us to access fscpos_{read,write}_value.
454 */ 454 */
455 455
456 if (!(data = kmalloc(sizeof(struct fscpos_data), GFP_KERNEL))) { 456 if (!(data = kzalloc(sizeof(struct fscpos_data), GFP_KERNEL))) {
457 err = -ENOMEM; 457 err = -ENOMEM;
458 goto exit; 458 goto exit;
459 } 459 }
460 memset(data, 0, sizeof(struct fscpos_data));
461 460
462 new_client = &data->client; 461 new_client = &data->client;
463 i2c_set_clientdata(new_client, data); 462 i2c_set_clientdata(new_client, data);
diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c
index 256b9323c84b..2f178dbe3d87 100644
--- a/drivers/hwmon/gl518sm.c
+++ b/drivers/hwmon/gl518sm.c
@@ -365,11 +365,10 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind)
365 client structure, even though we cannot fill it completely yet. 365 client structure, even though we cannot fill it completely yet.
366 But it allows us to access gl518_{read,write}_value. */ 366 But it allows us to access gl518_{read,write}_value. */
367 367
368 if (!(data = kmalloc(sizeof(struct gl518_data), GFP_KERNEL))) { 368 if (!(data = kzalloc(sizeof(struct gl518_data), GFP_KERNEL))) {
369 err = -ENOMEM; 369 err = -ENOMEM;
370 goto exit; 370 goto exit;
371 } 371 }
372 memset(data, 0, sizeof(struct gl518_data));
373 372
374 new_client = &data->client; 373 new_client = &data->client;
375 i2c_set_clientdata(new_client, data); 374 i2c_set_clientdata(new_client, data);
diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c
index 12fd757066fc..c39ba1239426 100644
--- a/drivers/hwmon/gl520sm.c
+++ b/drivers/hwmon/gl520sm.c
@@ -536,11 +536,10 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
536 client structure, even though we cannot fill it completely yet. 536 client structure, even though we cannot fill it completely yet.
537 But it allows us to access gl520_{read,write}_value. */ 537 But it allows us to access gl520_{read,write}_value. */
538 538
539 if (!(data = kmalloc(sizeof(struct gl520_data), GFP_KERNEL))) { 539 if (!(data = kzalloc(sizeof(struct gl520_data), GFP_KERNEL))) {
540 err = -ENOMEM; 540 err = -ENOMEM;
541 goto exit; 541 goto exit;
542 } 542 }
543 memset(data, 0, sizeof(struct gl520_data));
544 543
545 new_client = &data->client; 544 new_client = &data->client;
546 i2c_set_clientdata(new_client, data); 545 i2c_set_clientdata(new_client, data);
diff --git a/drivers/hwmon/hdaps.c b/drivers/hwmon/hdaps.c
index 7f0107613827..0015da5668a1 100644
--- a/drivers/hwmon/hdaps.c
+++ b/drivers/hwmon/hdaps.c
@@ -296,11 +296,9 @@ static int hdaps_probe(struct device *dev)
296 return 0; 296 return 0;
297} 297}
298 298
299static int hdaps_resume(struct device *dev, u32 level) 299static int hdaps_resume(struct device *dev)
300{ 300{
301 if (level == RESUME_ENABLE) 301 return hdaps_device_init();
302 return hdaps_device_init();
303 return 0;
304} 302}
305 303
306static struct device_driver hdaps_driver = { 304static struct device_driver hdaps_driver = {
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 9b41c9bd805f..6f48579799b5 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -45,7 +45,7 @@ struct class_device *hwmon_device_register(struct device *dev)
45 return ERR_PTR(-ENOMEM); 45 return ERR_PTR(-ENOMEM);
46 46
47 id = id & MAX_ID_MASK; 47 id = id & MAX_ID_MASK;
48 cdev = class_device_create(hwmon_class, MKDEV(0,0), dev, 48 cdev = class_device_create(hwmon_class, NULL, MKDEV(0,0), dev,
49 HWMON_ID_FORMAT, id); 49 HWMON_ID_FORMAT, id);
50 50
51 if (IS_ERR(cdev)) 51 if (IS_ERR(cdev))
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index 53cc2b6d6385..6c41e25e670b 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -2,7 +2,7 @@
2 it87.c - Part of lm_sensors, Linux kernel modules for hardware 2 it87.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring. 3 monitoring.
4 4
5 Supports: IT8705F Super I/O chip w/LPC interface & SMBus 5 Supports: IT8705F Super I/O chip w/LPC interface
6 IT8712F Super I/O chip w/LPC interface & SMBus 6 IT8712F Super I/O chip w/LPC interface & SMBus
7 Sis950 A clone of the IT8705F 7 Sis950 A clone of the IT8705F
8 8
@@ -47,7 +47,7 @@
47/* Addresses to scan */ 47/* Addresses to scan */
48static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 48static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
49 0x2e, 0x2f, I2C_CLIENT_END }; 49 0x2e, 0x2f, I2C_CLIENT_END };
50static unsigned short isa_address = 0x290; 50static unsigned short isa_address;
51 51
52/* Insmod parameters */ 52/* Insmod parameters */
53I2C_CLIENT_INSMOD_2(it87, it8712); 53I2C_CLIENT_INSMOD_2(it87, it8712);
@@ -706,7 +706,7 @@ static int it87_isa_attach_adapter(struct i2c_adapter *adapter)
706} 706}
707 707
708/* SuperIO detection - will change isa_address if a chip is found */ 708/* SuperIO detection - will change isa_address if a chip is found */
709static int __init it87_find(int *address) 709static int __init it87_find(unsigned short *address)
710{ 710{
711 int err = -ENODEV; 711 int err = -ENODEV;
712 712
@@ -738,7 +738,7 @@ exit:
738} 738}
739 739
740/* This function is called by i2c_probe */ 740/* This function is called by i2c_probe */
741int it87_detect(struct i2c_adapter *adapter, int address, int kind) 741static int it87_detect(struct i2c_adapter *adapter, int address, int kind)
742{ 742{
743 int i; 743 int i;
744 struct i2c_client *new_client; 744 struct i2c_client *new_client;
@@ -757,42 +757,14 @@ int it87_detect(struct i2c_adapter *adapter, int address, int kind)
757 if (!request_region(address, IT87_EXTENT, it87_isa_driver.name)) 757 if (!request_region(address, IT87_EXTENT, it87_isa_driver.name))
758 goto ERROR0; 758 goto ERROR0;
759 759
760 /* Probe whether there is anything available on this address. Already 760 /* For now, we presume we have a valid client. We create the
761 done for SMBus and Super-I/O clients */
762 if (kind < 0) {
763 if (is_isa && !chip_type) {
764#define REALLY_SLOW_IO
765 /* We need the timeouts for at least some IT87-like chips. But only
766 if we read 'undefined' registers. */
767 i = inb_p(address + 1);
768 if (inb_p(address + 2) != i
769 || inb_p(address + 3) != i
770 || inb_p(address + 7) != i) {
771 err = -ENODEV;
772 goto ERROR1;
773 }
774#undef REALLY_SLOW_IO
775
776 /* Let's just hope nothing breaks here */
777 i = inb_p(address + 5) & 0x7f;
778 outb_p(~i & 0x7f, address + 5);
779 if ((inb_p(address + 5) & 0x7f) != (~i & 0x7f)) {
780 outb_p(i, address + 5);
781 err = -ENODEV;
782 goto ERROR1;
783 }
784 }
785 }
786
787 /* OK. For now, we presume we have a valid client. We now create the
788 client structure, even though we cannot fill it completely yet. 761 client structure, even though we cannot fill it completely yet.
789 But it allows us to access it87_{read,write}_value. */ 762 But it allows us to access it87_{read,write}_value. */
790 763
791 if (!(data = kmalloc(sizeof(struct it87_data), GFP_KERNEL))) { 764 if (!(data = kzalloc(sizeof(struct it87_data), GFP_KERNEL))) {
792 err = -ENOMEM; 765 err = -ENOMEM;
793 goto ERROR1; 766 goto ERROR1;
794 } 767 }
795 memset(data, 0, sizeof(struct it87_data));
796 768
797 new_client = &data->client; 769 new_client = &data->client;
798 if (is_isa) 770 if (is_isa)
@@ -1182,20 +1154,18 @@ static struct it87_data *it87_update_device(struct device *dev)
1182 1154
1183static int __init sm_it87_init(void) 1155static int __init sm_it87_init(void)
1184{ 1156{
1185 int addr, res; 1157 int res;
1186
1187 if (!it87_find(&addr)) {
1188 isa_address = addr;
1189 }
1190 1158
1191 res = i2c_add_driver(&it87_driver); 1159 res = i2c_add_driver(&it87_driver);
1192 if (res) 1160 if (res)
1193 return res; 1161 return res;
1194 1162
1195 res = i2c_isa_add_driver(&it87_isa_driver); 1163 if (!it87_find(&isa_address)) {
1196 if (res) { 1164 res = i2c_isa_add_driver(&it87_isa_driver);
1197 i2c_del_driver(&it87_driver); 1165 if (res) {
1198 return res; 1166 i2c_del_driver(&it87_driver);
1167 return res;
1168 }
1199 } 1169 }
1200 1170
1201 return 0; 1171 return 0;
diff --git a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c
index be5c7095ecbb..954ec2497249 100644
--- a/drivers/hwmon/lm63.c
+++ b/drivers/hwmon/lm63.c
@@ -375,11 +375,10 @@ static int lm63_detect(struct i2c_adapter *adapter, int address, int kind)
375 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 375 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
376 goto exit; 376 goto exit;
377 377
378 if (!(data = kmalloc(sizeof(struct lm63_data), GFP_KERNEL))) { 378 if (!(data = kzalloc(sizeof(struct lm63_data), GFP_KERNEL))) {
379 err = -ENOMEM; 379 err = -ENOMEM;
380 goto exit; 380 goto exit;
381 } 381 }
382 memset(data, 0, sizeof(struct lm63_data));
383 382
384 /* The common I2C client data is placed right before the 383 /* The common I2C client data is placed right before the
385 LM63-specific data. */ 384 LM63-specific data. */
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index 9a3ebdf583f4..d70f4c8fc1e6 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -127,11 +127,10 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
127 /* OK. For now, we presume we have a valid client. We now create the 127 /* OK. For now, we presume we have a valid client. We now create the
128 client structure, even though we cannot fill it completely yet. 128 client structure, even though we cannot fill it completely yet.
129 But it allows us to access lm75_{read,write}_value. */ 129 But it allows us to access lm75_{read,write}_value. */
130 if (!(data = kmalloc(sizeof(struct lm75_data), GFP_KERNEL))) { 130 if (!(data = kzalloc(sizeof(struct lm75_data), GFP_KERNEL))) {
131 err = -ENOMEM; 131 err = -ENOMEM;
132 goto exit; 132 goto exit;
133 } 133 }
134 memset(data, 0, sizeof(struct lm75_data));
135 134
136 new_client = &data->client; 135 new_client = &data->client;
137 i2c_set_clientdata(new_client, data); 136 i2c_set_clientdata(new_client, data);
diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c
index 866eab96a6f6..9380fda7dcd1 100644
--- a/drivers/hwmon/lm77.c
+++ b/drivers/hwmon/lm77.c
@@ -226,11 +226,10 @@ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind)
226 /* OK. For now, we presume we have a valid client. We now create the 226 /* OK. For now, we presume we have a valid client. We now create the
227 client structure, even though we cannot fill it completely yet. 227 client structure, even though we cannot fill it completely yet.
228 But it allows us to access lm77_{read,write}_value. */ 228 But it allows us to access lm77_{read,write}_value. */
229 if (!(data = kmalloc(sizeof(struct lm77_data), GFP_KERNEL))) { 229 if (!(data = kzalloc(sizeof(struct lm77_data), GFP_KERNEL))) {
230 err = -ENOMEM; 230 err = -ENOMEM;
231 goto exit; 231 goto exit;
232 } 232 }
233 memset(data, 0, sizeof(struct lm77_data));
234 233
235 new_client = &data->client; 234 new_client = &data->client;
236 i2c_set_clientdata(new_client, data); 235 i2c_set_clientdata(new_client, data);
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
index f6730dc3573b..bde0cda9477e 100644
--- a/drivers/hwmon/lm78.c
+++ b/drivers/hwmon/lm78.c
@@ -480,7 +480,7 @@ static int lm78_isa_attach_adapter(struct i2c_adapter *adapter)
480} 480}
481 481
482/* This function is called by i2c_probe */ 482/* This function is called by i2c_probe */
483int lm78_detect(struct i2c_adapter *adapter, int address, int kind) 483static int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
484{ 484{
485 int i, err; 485 int i, err;
486 struct i2c_client *new_client; 486 struct i2c_client *new_client;
@@ -540,11 +540,10 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
540 client structure, even though we cannot fill it completely yet. 540 client structure, even though we cannot fill it completely yet.
541 But it allows us to access lm78_{read,write}_value. */ 541 But it allows us to access lm78_{read,write}_value. */
542 542
543 if (!(data = kmalloc(sizeof(struct lm78_data), GFP_KERNEL))) { 543 if (!(data = kzalloc(sizeof(struct lm78_data), GFP_KERNEL))) {
544 err = -ENOMEM; 544 err = -ENOMEM;
545 goto ERROR1; 545 goto ERROR1;
546 } 546 }
547 memset(data, 0, sizeof(struct lm78_data));
548 547
549 new_client = &data->client; 548 new_client = &data->client;
550 if (is_isa) 549 if (is_isa)
@@ -726,7 +725,6 @@ static int lm78_write_value(struct i2c_client *client, u8 reg, u8 value)
726 return i2c_smbus_write_byte_data(client, reg, value); 725 return i2c_smbus_write_byte_data(client, reg, value);
727} 726}
728 727
729/* Called when we have found a new LM78. It should set limits, etc. */
730static void lm78_init_client(struct i2c_client *client) 728static void lm78_init_client(struct i2c_client *client)
731{ 729{
732 u8 config = lm78_read_value(client, LM78_REG_CONFIG); 730 u8 config = lm78_read_value(client, LM78_REG_CONFIG);
diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c
index 83af8b3a0cac..c359fdea211e 100644
--- a/drivers/hwmon/lm80.c
+++ b/drivers/hwmon/lm80.c
@@ -393,7 +393,7 @@ static int lm80_attach_adapter(struct i2c_adapter *adapter)
393 return i2c_probe(adapter, &addr_data, lm80_detect); 393 return i2c_probe(adapter, &addr_data, lm80_detect);
394} 394}
395 395
396int lm80_detect(struct i2c_adapter *adapter, int address, int kind) 396static int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
397{ 397{
398 int i, cur; 398 int i, cur;
399 struct i2c_client *new_client; 399 struct i2c_client *new_client;
@@ -407,11 +407,10 @@ int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
407 /* OK. For now, we presume we have a valid client. We now create the 407 /* OK. For now, we presume we have a valid client. We now create the
408 client structure, even though we cannot fill it completely yet. 408 client structure, even though we cannot fill it completely yet.
409 But it allows us to access lm80_{read,write}_value. */ 409 But it allows us to access lm80_{read,write}_value. */
410 if (!(data = kmalloc(sizeof(struct lm80_data), GFP_KERNEL))) { 410 if (!(data = kzalloc(sizeof(struct lm80_data), GFP_KERNEL))) {
411 err = -ENOMEM; 411 err = -ENOMEM;
412 goto exit; 412 goto exit;
413 } 413 }
414 memset(data, 0, sizeof(struct lm80_data));
415 414
416 new_client = &data->client; 415 new_client = &data->client;
417 i2c_set_clientdata(new_client, data); 416 i2c_set_clientdata(new_client, data);
diff --git a/drivers/hwmon/lm83.c b/drivers/hwmon/lm83.c
index d74b2c20c719..9a70611a9f69 100644
--- a/drivers/hwmon/lm83.c
+++ b/drivers/hwmon/lm83.c
@@ -230,11 +230,10 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind)
230 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 230 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
231 goto exit; 231 goto exit;
232 232
233 if (!(data = kmalloc(sizeof(struct lm83_data), GFP_KERNEL))) { 233 if (!(data = kzalloc(sizeof(struct lm83_data), GFP_KERNEL))) {
234 err = -ENOMEM; 234 err = -ENOMEM;
235 goto exit; 235 goto exit;
236 } 236 }
237 memset(data, 0, sizeof(struct lm83_data));
238 237
239 /* The common I2C client data is placed right after the 238 /* The common I2C client data is placed right after the
240 * LM83-specific data. */ 239 * LM83-specific data. */
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index ab214df9624b..d1070ed2bee6 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -1007,14 +1007,14 @@ temp_auto(1);
1007temp_auto(2); 1007temp_auto(2);
1008temp_auto(3); 1008temp_auto(3);
1009 1009
1010int lm85_attach_adapter(struct i2c_adapter *adapter) 1010static int lm85_attach_adapter(struct i2c_adapter *adapter)
1011{ 1011{
1012 if (!(adapter->class & I2C_CLASS_HWMON)) 1012 if (!(adapter->class & I2C_CLASS_HWMON))
1013 return 0; 1013 return 0;
1014 return i2c_probe(adapter, &addr_data, lm85_detect); 1014 return i2c_probe(adapter, &addr_data, lm85_detect);
1015} 1015}
1016 1016
1017int lm85_detect(struct i2c_adapter *adapter, int address, 1017static int lm85_detect(struct i2c_adapter *adapter, int address,
1018 int kind) 1018 int kind)
1019{ 1019{
1020 int company, verstep ; 1020 int company, verstep ;
@@ -1033,11 +1033,10 @@ int lm85_detect(struct i2c_adapter *adapter, int address,
1033 client structure, even though we cannot fill it completely yet. 1033 client structure, even though we cannot fill it completely yet.
1034 But it allows us to access lm85_{read,write}_value. */ 1034 But it allows us to access lm85_{read,write}_value. */
1035 1035
1036 if (!(data = kmalloc(sizeof(struct lm85_data), GFP_KERNEL))) { 1036 if (!(data = kzalloc(sizeof(struct lm85_data), GFP_KERNEL))) {
1037 err = -ENOMEM; 1037 err = -ENOMEM;
1038 goto ERROR0; 1038 goto ERROR0;
1039 } 1039 }
1040 memset(data, 0, sizeof(struct lm85_data));
1041 1040
1042 new_client = &data->client; 1041 new_client = &data->client;
1043 i2c_set_clientdata(new_client, data); 1042 i2c_set_clientdata(new_client, data);
@@ -1236,7 +1235,7 @@ int lm85_detect(struct i2c_adapter *adapter, int address,
1236 return err; 1235 return err;
1237} 1236}
1238 1237
1239int lm85_detach_client(struct i2c_client *client) 1238static int lm85_detach_client(struct i2c_client *client)
1240{ 1239{
1241 struct lm85_data *data = i2c_get_clientdata(client); 1240 struct lm85_data *data = i2c_get_clientdata(client);
1242 hwmon_device_unregister(data->class_dev); 1241 hwmon_device_unregister(data->class_dev);
@@ -1246,7 +1245,7 @@ int lm85_detach_client(struct i2c_client *client)
1246} 1245}
1247 1246
1248 1247
1249int lm85_read_value(struct i2c_client *client, u8 reg) 1248static int lm85_read_value(struct i2c_client *client, u8 reg)
1250{ 1249{
1251 int res; 1250 int res;
1252 1251
@@ -1276,7 +1275,7 @@ int lm85_read_value(struct i2c_client *client, u8 reg)
1276 return res ; 1275 return res ;
1277} 1276}
1278 1277
1279int lm85_write_value(struct i2c_client *client, u8 reg, int value) 1278static int lm85_write_value(struct i2c_client *client, u8 reg, int value)
1280{ 1279{
1281 int res ; 1280 int res ;
1282 1281
@@ -1305,7 +1304,7 @@ int lm85_write_value(struct i2c_client *client, u8 reg, int value)
1305 return res ; 1304 return res ;
1306} 1305}
1307 1306
1308void lm85_init_client(struct i2c_client *client) 1307static void lm85_init_client(struct i2c_client *client)
1309{ 1308{
1310 int value; 1309 int value;
1311 struct lm85_data *data = i2c_get_clientdata(client); 1310 struct lm85_data *data = i2c_get_clientdata(client);
diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
index dca996de4c33..eeec18177861 100644
--- a/drivers/hwmon/lm87.c
+++ b/drivers/hwmon/lm87.c
@@ -554,11 +554,10 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind)
554 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 554 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
555 goto exit; 555 goto exit;
556 556
557 if (!(data = kmalloc(sizeof(struct lm87_data), GFP_KERNEL))) { 557 if (!(data = kzalloc(sizeof(struct lm87_data), GFP_KERNEL))) {
558 err = -ENOMEM; 558 err = -ENOMEM;
559 goto exit; 559 goto exit;
560 } 560 }
561 memset(data, 0, sizeof(struct lm87_data));
562 561
563 /* The common I2C client data is placed right before the 562 /* The common I2C client data is placed right before the
564 LM87-specific data. */ 563 LM87-specific data. */
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index 14de05fcd431..83cf2e1b09f5 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -31,7 +31,7 @@
31 * Devices. That chip is similar to the LM90, with a few differences 31 * Devices. That chip is similar to the LM90, with a few differences
32 * that are not handled by this driver. Complete datasheet can be 32 * that are not handled by this driver. Complete datasheet can be
33 * obtained from Analog's website at: 33 * obtained from Analog's website at:
34 * http://products.analog.com/products/info.asp?product=ADM1032 34 * http://www.analog.com/en/prod/0,2877,ADM1032,00.html
35 * Among others, it has a higher accuracy than the LM90, much like the 35 * Among others, it has a higher accuracy than the LM90, much like the
36 * LM86 does. 36 * LM86 does.
37 * 37 *
@@ -49,7 +49,7 @@
49 * register values are decoded differently) it is ignored by this 49 * register values are decoded differently) it is ignored by this
50 * driver. Complete datasheet can be obtained from Analog's website 50 * driver. Complete datasheet can be obtained from Analog's website
51 * at: 51 * at:
52 * http://products.analog.com/products/info.asp?product=ADT7461 52 * http://www.analog.com/en/prod/0,2877,ADT7461,00.html
53 * 53 *
54 * Since the LM90 was the first chipset supported by this driver, most 54 * Since the LM90 was the first chipset supported by this driver, most
55 * comments will refer to this chipset, but are actually general and 55 * comments will refer to this chipset, but are actually general and
@@ -83,10 +83,10 @@
83 * Addresses to scan 83 * Addresses to scan
84 * Address is fully defined internally and cannot be changed except for 84 * Address is fully defined internally and cannot be changed except for
85 * MAX6659. 85 * MAX6659.
86 * LM86, LM89, LM90, LM99, ADM1032, MAX6657 and MAX6658 have address 0x4c. 86 * LM86, LM89, LM90, LM99, ADM1032, ADM1032-1, ADT7461, MAX6657 and MAX6658
87 * LM89-1, and LM99-1 have address 0x4d. 87 * have address 0x4c.
88 * ADM1032-2, ADT7461-2, LM89-1, and LM99-1 have address 0x4d.
88 * MAX6659 can have address 0x4c, 0x4d or 0x4e (unsupported). 89 * MAX6659 can have address 0x4c, 0x4d or 0x4e (unsupported).
89 * ADT7461 always has address 0x4c.
90 */ 90 */
91 91
92static unsigned short normal_i2c[] = { 0x4c, 0x4d, I2C_CLIENT_END }; 92static unsigned short normal_i2c[] = { 0x4c, 0x4d, I2C_CLIENT_END };
@@ -345,10 +345,74 @@ static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temphyst,
345static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 4); 345static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 4);
346static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 346static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
347 347
348/* pec used for ADM1032 only */
349static ssize_t show_pec(struct device *dev, struct device_attribute *dummy,
350 char *buf)
351{
352 struct i2c_client *client = to_i2c_client(dev);
353 return sprintf(buf, "%d\n", !!(client->flags & I2C_CLIENT_PEC));
354}
355
356static ssize_t set_pec(struct device *dev, struct device_attribute *dummy,
357 const char *buf, size_t count)
358{
359 struct i2c_client *client = to_i2c_client(dev);
360 long val = simple_strtol(buf, NULL, 10);
361
362 switch (val) {
363 case 0:
364 client->flags &= ~I2C_CLIENT_PEC;
365 break;
366 case 1:
367 client->flags |= I2C_CLIENT_PEC;
368 break;
369 default:
370 return -EINVAL;
371 }
372
373 return count;
374}
375
376static DEVICE_ATTR(pec, S_IWUSR | S_IRUGO, show_pec, set_pec);
377
348/* 378/*
349 * Real code 379 * Real code
350 */ 380 */
351 381
382/* The ADM1032 supports PEC but not on write byte transactions, so we need
383 to explicitely ask for a transaction without PEC. */
384static inline s32 adm1032_write_byte(struct i2c_client *client, u8 value)
385{
386 return i2c_smbus_xfer(client->adapter, client->addr,
387 client->flags & ~I2C_CLIENT_PEC,
388 I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL);
389}
390
391/* It is assumed that client->update_lock is held (unless we are in
392 detection or initialization steps). This matters when PEC is enabled,
393 because we don't want the address pointer to change between the write
394 byte and the read byte transactions. */
395static int lm90_read_reg(struct i2c_client* client, u8 reg, u8 *value)
396{
397 int err;
398
399 if (client->flags & I2C_CLIENT_PEC) {
400 err = adm1032_write_byte(client, reg);
401 if (err >= 0)
402 err = i2c_smbus_read_byte(client);
403 } else
404 err = i2c_smbus_read_byte_data(client, reg);
405
406 if (err < 0) {
407 dev_warn(&client->dev, "Register %#02x read failed (%d)\n",
408 reg, err);
409 return err;
410 }
411 *value = err;
412
413 return 0;
414}
415
352static int lm90_attach_adapter(struct i2c_adapter *adapter) 416static int lm90_attach_adapter(struct i2c_adapter *adapter)
353{ 417{
354 if (!(adapter->class & I2C_CLASS_HWMON)) 418 if (!(adapter->class & I2C_CLASS_HWMON))
@@ -370,11 +434,10 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind)
370 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 434 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
371 goto exit; 435 goto exit;
372 436
373 if (!(data = kmalloc(sizeof(struct lm90_data), GFP_KERNEL))) { 437 if (!(data = kzalloc(sizeof(struct lm90_data), GFP_KERNEL))) {
374 err = -ENOMEM; 438 err = -ENOMEM;
375 goto exit; 439 goto exit;
376 } 440 }
377 memset(data, 0, sizeof(struct lm90_data));
378 441
379 /* The common I2C client data is placed right before the 442 /* The common I2C client data is placed right before the
380 LM90-specific data. */ 443 LM90-specific data. */
@@ -403,20 +466,22 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind)
403 if (kind < 0) { /* detection and identification */ 466 if (kind < 0) { /* detection and identification */
404 u8 man_id, chip_id, reg_config1, reg_convrate; 467 u8 man_id, chip_id, reg_config1, reg_convrate;
405 468
406 man_id = i2c_smbus_read_byte_data(new_client, 469 if (lm90_read_reg(new_client, LM90_REG_R_MAN_ID,
407 LM90_REG_R_MAN_ID); 470 &man_id) < 0
408 chip_id = i2c_smbus_read_byte_data(new_client, 471 || lm90_read_reg(new_client, LM90_REG_R_CHIP_ID,
409 LM90_REG_R_CHIP_ID); 472 &chip_id) < 0
410 reg_config1 = i2c_smbus_read_byte_data(new_client, 473 || lm90_read_reg(new_client, LM90_REG_R_CONFIG1,
411 LM90_REG_R_CONFIG1); 474 &reg_config1) < 0
412 reg_convrate = i2c_smbus_read_byte_data(new_client, 475 || lm90_read_reg(new_client, LM90_REG_R_CONVRATE,
413 LM90_REG_R_CONVRATE); 476 &reg_convrate) < 0)
477 goto exit_free;
414 478
415 if (man_id == 0x01) { /* National Semiconductor */ 479 if (man_id == 0x01) { /* National Semiconductor */
416 u8 reg_config2; 480 u8 reg_config2;
417 481
418 reg_config2 = i2c_smbus_read_byte_data(new_client, 482 if (lm90_read_reg(new_client, LM90_REG_R_CONFIG2,
419 LM90_REG_R_CONFIG2); 483 &reg_config2) < 0)
484 goto exit_free;
420 485
421 if ((reg_config1 & 0x2A) == 0x00 486 if ((reg_config1 & 0x2A) == 0x00
422 && (reg_config2 & 0xF8) == 0x00 487 && (reg_config2 & 0xF8) == 0x00
@@ -435,14 +500,12 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind)
435 } 500 }
436 } else 501 } else
437 if (man_id == 0x41) { /* Analog Devices */ 502 if (man_id == 0x41) { /* Analog Devices */
438 if (address == 0x4C 503 if ((chip_id & 0xF0) == 0x40 /* ADM1032 */
439 && (chip_id & 0xF0) == 0x40 /* ADM1032 */
440 && (reg_config1 & 0x3F) == 0x00 504 && (reg_config1 & 0x3F) == 0x00
441 && reg_convrate <= 0x0A) { 505 && reg_convrate <= 0x0A) {
442 kind = adm1032; 506 kind = adm1032;
443 } else 507 } else
444 if (address == 0x4c 508 if (chip_id == 0x51 /* ADT7461 */
445 && chip_id == 0x51 /* ADT7461 */
446 && (reg_config1 & 0x1F) == 0x00 /* check compat mode */ 509 && (reg_config1 & 0x1F) == 0x00 /* check compat mode */
447 && reg_convrate <= 0x0A) { 510 && reg_convrate <= 0x0A) {
448 kind = adt7461; 511 kind = adt7461;
@@ -477,6 +540,10 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind)
477 name = "lm90"; 540 name = "lm90";
478 } else if (kind == adm1032) { 541 } else if (kind == adm1032) {
479 name = "adm1032"; 542 name = "adm1032";
543 /* The ADM1032 supports PEC, but only if combined
544 transactions are not used. */
545 if (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
546 new_client->flags |= I2C_CLIENT_PEC;
480 } else if (kind == lm99) { 547 } else if (kind == lm99) {
481 name = "lm99"; 548 name = "lm99";
482 } else if (kind == lm86) { 549 } else if (kind == lm86) {
@@ -529,6 +596,9 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind)
529 &sensor_dev_attr_temp2_crit_hyst.dev_attr); 596 &sensor_dev_attr_temp2_crit_hyst.dev_attr);
530 device_create_file(&new_client->dev, &dev_attr_alarms); 597 device_create_file(&new_client->dev, &dev_attr_alarms);
531 598
599 if (new_client->flags & I2C_CLIENT_PEC)
600 device_create_file(&new_client->dev, &dev_attr_pec);
601
532 return 0; 602 return 0;
533 603
534exit_detach: 604exit_detach:
@@ -548,7 +618,10 @@ static void lm90_init_client(struct i2c_client *client)
548 */ 618 */
549 i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, 619 i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE,
550 5); /* 2 Hz */ 620 5); /* 2 Hz */
551 config = i2c_smbus_read_byte_data(client, LM90_REG_R_CONFIG1); 621 if (lm90_read_reg(client, LM90_REG_R_CONFIG1, &config) < 0) {
622 dev_warn(&client->dev, "Initialization failed!\n");
623 return;
624 }
552 if (config & 0x40) 625 if (config & 0x40)
553 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, 626 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
554 config & 0xBF); /* run */ 627 config & 0xBF); /* run */
@@ -576,21 +649,15 @@ static struct lm90_data *lm90_update_device(struct device *dev)
576 down(&data->update_lock); 649 down(&data->update_lock);
577 650
578 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { 651 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
579 u8 oldh, newh; 652 u8 oldh, newh, l;
580 653
581 dev_dbg(&client->dev, "Updating lm90 data.\n"); 654 dev_dbg(&client->dev, "Updating lm90 data.\n");
582 data->temp8[0] = i2c_smbus_read_byte_data(client, 655 lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP, &data->temp8[0]);
583 LM90_REG_R_LOCAL_TEMP); 656 lm90_read_reg(client, LM90_REG_R_LOCAL_LOW, &data->temp8[1]);
584 data->temp8[1] = i2c_smbus_read_byte_data(client, 657 lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH, &data->temp8[2]);
585 LM90_REG_R_LOCAL_LOW); 658 lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT, &data->temp8[3]);
586 data->temp8[2] = i2c_smbus_read_byte_data(client, 659 lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, &data->temp8[4]);
587 LM90_REG_R_LOCAL_HIGH); 660 lm90_read_reg(client, LM90_REG_R_TCRIT_HYST, &data->temp_hyst);
588 data->temp8[3] = i2c_smbus_read_byte_data(client,
589 LM90_REG_R_LOCAL_CRIT);
590 data->temp8[4] = i2c_smbus_read_byte_data(client,
591 LM90_REG_R_REMOTE_CRIT);
592 data->temp_hyst = i2c_smbus_read_byte_data(client,
593 LM90_REG_R_TCRIT_HYST);
594 661
595 /* 662 /*
596 * There is a trick here. We have to read two registers to 663 * There is a trick here. We have to read two registers to
@@ -606,36 +673,20 @@ static struct lm90_data *lm90_update_device(struct device *dev)
606 * then we have a valid reading. Else we have to read the low 673 * then we have a valid reading. Else we have to read the low
607 * byte again, and now we believe we have a correct reading. 674 * byte again, and now we believe we have a correct reading.
608 */ 675 */
609 oldh = i2c_smbus_read_byte_data(client, 676 if (lm90_read_reg(client, LM90_REG_R_REMOTE_TEMPH, &oldh) == 0
610 LM90_REG_R_REMOTE_TEMPH); 677 && lm90_read_reg(client, LM90_REG_R_REMOTE_TEMPL, &l) == 0
611 data->temp11[0] = i2c_smbus_read_byte_data(client, 678 && lm90_read_reg(client, LM90_REG_R_REMOTE_TEMPH, &newh) == 0
612 LM90_REG_R_REMOTE_TEMPL); 679 && (newh == oldh
613 newh = i2c_smbus_read_byte_data(client, 680 || lm90_read_reg(client, LM90_REG_R_REMOTE_TEMPL, &l) == 0))
614 LM90_REG_R_REMOTE_TEMPH); 681 data->temp11[0] = (newh << 8) | l;
615 if (newh != oldh) { 682
616 data->temp11[0] = i2c_smbus_read_byte_data(client, 683 if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &newh) == 0
617 LM90_REG_R_REMOTE_TEMPL); 684 && lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL, &l) == 0)
618#ifdef DEBUG 685 data->temp11[1] = (newh << 8) | l;
619 oldh = i2c_smbus_read_byte_data(client, 686 if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &newh) == 0
620 LM90_REG_R_REMOTE_TEMPH); 687 && lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL, &l) == 0)
621 /* oldh is actually newer */ 688 data->temp11[2] = (newh << 8) | l;
622 if (newh != oldh) 689 lm90_read_reg(client, LM90_REG_R_STATUS, &data->alarms);
623 dev_warn(&client->dev, "Remote temperature may be "
624 "wrong.\n");
625#endif
626 }
627 data->temp11[0] |= (newh << 8);
628
629 data->temp11[1] = (i2c_smbus_read_byte_data(client,
630 LM90_REG_R_REMOTE_LOWH) << 8) +
631 i2c_smbus_read_byte_data(client,
632 LM90_REG_R_REMOTE_LOWL);
633 data->temp11[2] = (i2c_smbus_read_byte_data(client,
634 LM90_REG_R_REMOTE_HIGHH) << 8) +
635 i2c_smbus_read_byte_data(client,
636 LM90_REG_R_REMOTE_HIGHL);
637 data->alarms = i2c_smbus_read_byte_data(client,
638 LM90_REG_R_STATUS);
639 690
640 data->last_updated = jiffies; 691 data->last_updated = jiffies;
641 data->valid = 1; 692 data->valid = 1;
diff --git a/drivers/hwmon/lm92.c b/drivers/hwmon/lm92.c
index 647b7c7cd575..7a4b3701ed1a 100644
--- a/drivers/hwmon/lm92.c
+++ b/drivers/hwmon/lm92.c
@@ -300,11 +300,10 @@ static int lm92_detect(struct i2c_adapter *adapter, int address, int kind)
300 | I2C_FUNC_SMBUS_WORD_DATA)) 300 | I2C_FUNC_SMBUS_WORD_DATA))
301 goto exit; 301 goto exit;
302 302
303 if (!(data = kmalloc(sizeof(struct lm92_data), GFP_KERNEL))) { 303 if (!(data = kzalloc(sizeof(struct lm92_data), GFP_KERNEL))) {
304 err = -ENOMEM; 304 err = -ENOMEM;
305 goto exit; 305 goto exit;
306 } 306 }
307 memset(data, 0, sizeof(struct lm92_data));
308 307
309 /* Fill in enough client fields so that we can read from the chip, 308 /* Fill in enough client fields so that we can read from the chip,
310 which is required for identication */ 309 which is required for identication */
diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c
index 16bf71f3a04d..6a82ffae1bfd 100644
--- a/drivers/hwmon/max1619.c
+++ b/drivers/hwmon/max1619.c
@@ -197,11 +197,10 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind)
197 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 197 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
198 goto exit; 198 goto exit;
199 199
200 if (!(data = kmalloc(sizeof(struct max1619_data), GFP_KERNEL))) { 200 if (!(data = kzalloc(sizeof(struct max1619_data), GFP_KERNEL))) {
201 err = -ENOMEM; 201 err = -ENOMEM;
202 goto exit; 202 goto exit;
203 } 203 }
204 memset(data, 0, sizeof(struct max1619_data));
205 204
206 /* The common I2C client data is placed right before the 205 /* The common I2C client data is placed right before the
207 MAX1619-specific data. */ 206 MAX1619-specific data. */
diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c
index cf2a35799c7c..17f745a23d04 100644
--- a/drivers/hwmon/pc87360.c
+++ b/drivers/hwmon/pc87360.c
@@ -754,9 +754,8 @@ static int pc87360_detect(struct i2c_adapter *adapter)
754 const char *name = "pc87360"; 754 const char *name = "pc87360";
755 int use_thermistors = 0; 755 int use_thermistors = 0;
756 756
757 if (!(data = kmalloc(sizeof(struct pc87360_data), GFP_KERNEL))) 757 if (!(data = kzalloc(sizeof(struct pc87360_data), GFP_KERNEL)))
758 return -ENOMEM; 758 return -ENOMEM;
759 memset(data, 0x00, sizeof(struct pc87360_data));
760 759
761 new_client = &data->client; 760 new_client = &data->client;
762 i2c_set_clientdata(new_client, data); 761 i2c_set_clientdata(new_client, data);
diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c
index 21aa9a41f62c..9c6cadec1087 100644
--- a/drivers/hwmon/sis5595.c
+++ b/drivers/hwmon/sis5595.c
@@ -518,11 +518,10 @@ static int sis5595_detect(struct i2c_adapter *adapter)
518 goto exit_release; 518 goto exit_release;
519 } 519 }
520 520
521 if (!(data = kmalloc(sizeof(struct sis5595_data), GFP_KERNEL))) { 521 if (!(data = kzalloc(sizeof(struct sis5595_data), GFP_KERNEL))) {
522 err = -ENOMEM; 522 err = -ENOMEM;
523 goto exit_release; 523 goto exit_release;
524 } 524 }
525 memset(data, 0, sizeof(struct sis5595_data));
526 525
527 new_client = &data->client; 526 new_client = &data->client;
528 new_client->addr = address; 527 new_client->addr = address;
diff --git a/drivers/hwmon/smsc47b397.c b/drivers/hwmon/smsc47b397.c
index 7fe71576dea4..2a3e21b5b6b4 100644
--- a/drivers/hwmon/smsc47b397.c
+++ b/drivers/hwmon/smsc47b397.c
@@ -244,11 +244,10 @@ static int smsc47b397_detect(struct i2c_adapter *adapter)
244 return -EBUSY; 244 return -EBUSY;
245 } 245 }
246 246
247 if (!(data = kmalloc(sizeof(struct smsc47b397_data), GFP_KERNEL))) { 247 if (!(data = kzalloc(sizeof(struct smsc47b397_data), GFP_KERNEL))) {
248 err = -ENOMEM; 248 err = -ENOMEM;
249 goto error_release; 249 goto error_release;
250 } 250 }
251 memset(data, 0x00, sizeof(struct smsc47b397_data));
252 251
253 new_client = &data->client; 252 new_client = &data->client;
254 i2c_set_clientdata(new_client, data); 253 i2c_set_clientdata(new_client, data);
@@ -299,7 +298,7 @@ static int __init smsc47b397_find(unsigned short *addr)
299 superio_enter(); 298 superio_enter();
300 id = superio_inb(SUPERIO_REG_DEVID); 299 id = superio_inb(SUPERIO_REG_DEVID);
301 300
302 if (id != 0x6f) { 301 if ((id != 0x6f) && (id != 0x81)) {
303 superio_exit(); 302 superio_exit();
304 return -ENODEV; 303 return -ENODEV;
305 } 304 }
@@ -310,8 +309,9 @@ static int __init smsc47b397_find(unsigned short *addr)
310 *addr = (superio_inb(SUPERIO_REG_BASE_MSB) << 8) 309 *addr = (superio_inb(SUPERIO_REG_BASE_MSB) << 8)
311 | superio_inb(SUPERIO_REG_BASE_LSB); 310 | superio_inb(SUPERIO_REG_BASE_LSB);
312 311
313 printk(KERN_INFO "smsc47b397: found SMSC LPC47B397-NC " 312 printk(KERN_INFO "smsc47b397: found SMSC %s "
314 "(base address 0x%04x, revision %u)\n", *addr, rev); 313 "(base address 0x%04x, revision %u)\n",
314 id == 0x81 ? "SCH5307-NS" : "LPC47B397-NC", *addr, rev);
315 315
316 superio_exit(); 316 superio_exit();
317 return 0; 317 return 0;
diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c
index c9cc683eba4a..5905c1af88f2 100644
--- a/drivers/hwmon/smsc47m1.c
+++ b/drivers/hwmon/smsc47m1.c
@@ -3,7 +3,7 @@
3 for hardware monitoring 3 for hardware monitoring
4 4
5 Supports the SMSC LPC47B27x, LPC47M10x, LPC47M13x, LPC47M14x, 5 Supports the SMSC LPC47B27x, LPC47M10x, LPC47M13x, LPC47M14x,
6 LPC47M15x and LPC47M192 Super-I/O chips. 6 LPC47M15x, LPC47M192 and LPC47M997 Super-I/O chips.
7 7
8 Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com> 8 Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com>
9 Copyright (C) 2004 Jean Delvare <khali@linux-fr.org> 9 Copyright (C) 2004 Jean Delvare <khali@linux-fr.org>
@@ -356,6 +356,8 @@ static int __init smsc47m1_find(unsigned short *addr)
356 * 0x5F) and LPC47B27x (device id 0x51) have fan control. 356 * 0x5F) and LPC47B27x (device id 0x51) have fan control.
357 * The LPC47M15x and LPC47M192 chips "with hardware monitoring block" 357 * The LPC47M15x and LPC47M192 chips "with hardware monitoring block"
358 * can do much more besides (device id 0x60). 358 * can do much more besides (device id 0x60).
359 * The LPC47M997 is undocumented, but seems to be compatible with
360 * the LPC47M192, and has the same device id.
359 */ 361 */
360 if (val == 0x51) 362 if (val == 0x51)
361 printk(KERN_INFO "smsc47m1: Found SMSC LPC47B27x\n"); 363 printk(KERN_INFO "smsc47m1: Found SMSC LPC47B27x\n");
@@ -364,7 +366,8 @@ static int __init smsc47m1_find(unsigned short *addr)
364 else if (val == 0x5F) 366 else if (val == 0x5F)
365 printk(KERN_INFO "smsc47m1: Found SMSC LPC47M14x\n"); 367 printk(KERN_INFO "smsc47m1: Found SMSC LPC47M14x\n");
366 else if (val == 0x60) 368 else if (val == 0x60)
367 printk(KERN_INFO "smsc47m1: Found SMSC LPC47M15x/LPC47M192\n"); 369 printk(KERN_INFO "smsc47m1: Found SMSC "
370 "LPC47M15x/LPC47M192/LPC47M997\n");
368 else { 371 else {
369 superio_exit(); 372 superio_exit();
370 return -ENODEV; 373 return -ENODEV;
@@ -396,11 +399,10 @@ static int smsc47m1_detect(struct i2c_adapter *adapter)
396 return -EBUSY; 399 return -EBUSY;
397 } 400 }
398 401
399 if (!(data = kmalloc(sizeof(struct smsc47m1_data), GFP_KERNEL))) { 402 if (!(data = kzalloc(sizeof(struct smsc47m1_data), GFP_KERNEL))) {
400 err = -ENOMEM; 403 err = -ENOMEM;
401 goto error_release; 404 goto error_release;
402 } 405 }
403 memset(data, 0x00, sizeof(struct smsc47m1_data));
404 406
405 new_client = &data->client; 407 new_client = &data->client;
406 i2c_set_clientdata(new_client, data); 408 i2c_set_clientdata(new_client, data);
diff --git a/drivers/hwmon/via686a.c b/drivers/hwmon/via686a.c
index 05ddc88e7dd2..6f696f897176 100644
--- a/drivers/hwmon/via686a.c
+++ b/drivers/hwmon/via686a.c
@@ -44,7 +44,7 @@
44 44
45/* If force_addr is set to anything different from 0, we forcibly enable 45/* If force_addr is set to anything different from 0, we forcibly enable
46 the device at the given address. */ 46 the device at the given address. */
47static unsigned short force_addr = 0; 47static unsigned short force_addr;
48module_param(force_addr, ushort, 0); 48module_param(force_addr, ushort, 0);
49MODULE_PARM_DESC(force_addr, 49MODULE_PARM_DESC(force_addr,
50 "Initialize the base address of the sensors"); 50 "Initialize the base address of the sensors");
@@ -198,7 +198,7 @@ static inline u8 FAN_TO_REG(long rpm, int div)
198 but the function is very linear in the useful range (0-80 deg C), so 198 but the function is very linear in the useful range (0-80 deg C), so
199 we'll just use linear interpolation for 10-bit readings.) So, tempLUT 199 we'll just use linear interpolation for 10-bit readings.) So, tempLUT
200 is the temp at via register values 0-255: */ 200 is the temp at via register values 0-255: */
201static const long tempLUT[] = 201static const s16 tempLUT[] =
202{ -709, -688, -667, -646, -627, -607, -589, -570, -553, -536, -519, 202{ -709, -688, -667, -646, -627, -607, -589, -570, -553, -536, -519,
203 -503, -487, -471, -456, -442, -428, -414, -400, -387, -375, 203 -503, -487, -471, -456, -442, -428, -414, -400, -387, -375,
204 -362, -350, -339, -327, -316, -305, -295, -285, -275, -265, 204 -362, -350, -339, -327, -316, -305, -295, -285, -275, -265,
@@ -270,7 +270,7 @@ static inline u8 TEMP_TO_REG(long val)
270} 270}
271 271
272/* for 8-bit temperature hyst and over registers */ 272/* for 8-bit temperature hyst and over registers */
273#define TEMP_FROM_REG(val) (tempLUT[(val)] * 100) 273#define TEMP_FROM_REG(val) ((long)tempLUT[val] * 100)
274 274
275/* for 10-bit temperature readings */ 275/* for 10-bit temperature readings */
276static inline long TEMP_FROM_REG10(u16 val) 276static inline long TEMP_FROM_REG10(u16 val)
@@ -589,10 +589,8 @@ static int via686a_detect(struct i2c_adapter *adapter)
589 u16 val; 589 u16 val;
590 590
591 /* 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 */
592 if (force_addr)
593 address = force_addr & 0xFF00;
594
595 if (force_addr) { 592 if (force_addr) {
593 address = force_addr & 0xFF00;
596 dev_warn(&adapter->dev, "forcing ISA address 0x%04X\n", 594 dev_warn(&adapter->dev, "forcing ISA address 0x%04X\n",
597 address); 595 address);
598 if (PCIBIOS_SUCCESSFUL != 596 if (PCIBIOS_SUCCESSFUL !=
@@ -603,11 +601,17 @@ static int via686a_detect(struct i2c_adapter *adapter)
603 pci_read_config_word(s_bridge, VIA686A_ENABLE_REG, &val)) 601 pci_read_config_word(s_bridge, VIA686A_ENABLE_REG, &val))
604 return -ENODEV; 602 return -ENODEV;
605 if (!(val & 0x0001)) { 603 if (!(val & 0x0001)) {
606 dev_warn(&adapter->dev, "enabling sensors\n"); 604 if (force_addr) {
607 if (PCIBIOS_SUCCESSFUL != 605 dev_info(&adapter->dev, "enabling sensors\n");
608 pci_write_config_word(s_bridge, VIA686A_ENABLE_REG, 606 if (PCIBIOS_SUCCESSFUL !=
609 val | 0x0001)) 607 pci_write_config_word(s_bridge, VIA686A_ENABLE_REG,
608 val | 0x0001))
609 return -ENODEV;
610 } else {
611 dev_warn(&adapter->dev, "sensors disabled - enable "
612 "with force_addr=0x%x\n", address);
610 return -ENODEV; 613 return -ENODEV;
614 }
611 } 615 }
612 616
613 /* Reserve the ISA region */ 617 /* Reserve the ISA region */
@@ -617,11 +621,10 @@ static int via686a_detect(struct i2c_adapter *adapter)
617 return -ENODEV; 621 return -ENODEV;
618 } 622 }
619 623
620 if (!(data = kmalloc(sizeof(struct via686a_data), GFP_KERNEL))) { 624 if (!(data = kzalloc(sizeof(struct via686a_data), GFP_KERNEL))) {
621 err = -ENOMEM; 625 err = -ENOMEM;
622 goto exit_release; 626 goto exit_release;
623 } 627 }
624 memset(data, 0, sizeof(struct via686a_data));
625 628
626 new_client = &data->client; 629 new_client = &data->client;
627 i2c_set_clientdata(new_client, data); 630 i2c_set_clientdata(new_client, data);
@@ -708,7 +711,6 @@ static int via686a_detach_client(struct i2c_client *client)
708 return 0; 711 return 0;
709} 712}
710 713
711/* Called when we have found a new VIA686A. Set limits, etc. */
712static void via686a_init_client(struct i2c_client *client) 714static void via686a_init_client(struct i2c_client *client)
713{ 715{
714 u8 reg; 716 u8 reg;
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index b60efe8f8b26..eee22a57e929 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -105,7 +105,9 @@ superio_exit(void)
105 * ISA constants 105 * ISA constants
106 */ 106 */
107 107
108#define REGION_LENGTH 8 108#define REGION_ALIGNMENT ~7
109#define REGION_OFFSET 5
110#define REGION_LENGTH 2
109#define ADDR_REG_OFFSET 5 111#define ADDR_REG_OFFSET 5
110#define DATA_REG_OFFSET 6 112#define DATA_REG_OFFSET 6
111 113
@@ -673,16 +675,16 @@ static int w83627ehf_detect(struct i2c_adapter *adapter)
673 struct w83627ehf_data *data; 675 struct w83627ehf_data *data;
674 int i, err = 0; 676 int i, err = 0;
675 677
676 if (!request_region(address, REGION_LENGTH, w83627ehf_driver.name)) { 678 if (!request_region(address + REGION_OFFSET, REGION_LENGTH,
679 w83627ehf_driver.name)) {
677 err = -EBUSY; 680 err = -EBUSY;
678 goto exit; 681 goto exit;
679 } 682 }
680 683
681 if (!(data = kmalloc(sizeof(struct w83627ehf_data), GFP_KERNEL))) { 684 if (!(data = kzalloc(sizeof(struct w83627ehf_data), GFP_KERNEL))) {
682 err = -ENOMEM; 685 err = -ENOMEM;
683 goto exit_release; 686 goto exit_release;
684 } 687 }
685 memset(data, 0, sizeof(struct w83627ehf_data));
686 688
687 client = &data->client; 689 client = &data->client;
688 i2c_set_clientdata(client, data); 690 i2c_set_clientdata(client, data);
@@ -762,7 +764,7 @@ exit_detach:
762exit_free: 764exit_free:
763 kfree(data); 765 kfree(data);
764exit_release: 766exit_release:
765 release_region(address, REGION_LENGTH); 767 release_region(address + REGION_OFFSET, REGION_LENGTH);
766exit: 768exit:
767 return err; 769 return err;
768} 770}
@@ -776,7 +778,7 @@ static int w83627ehf_detach_client(struct i2c_client *client)
776 778
777 if ((err = i2c_detach_client(client))) 779 if ((err = i2c_detach_client(client)))
778 return err; 780 return err;
779 release_region(client->addr, REGION_LENGTH); 781 release_region(client->addr + REGION_OFFSET, REGION_LENGTH);
780 kfree(data); 782 kfree(data);
781 783
782 return 0; 784 return 0;
@@ -807,7 +809,7 @@ static int __init w83627ehf_find(int sioaddr, unsigned short *addr)
807 superio_select(W83627EHF_LD_HWM); 809 superio_select(W83627EHF_LD_HWM);
808 val = (superio_inb(SIO_REG_ADDR) << 8) 810 val = (superio_inb(SIO_REG_ADDR) << 8)
809 | superio_inb(SIO_REG_ADDR + 1); 811 | superio_inb(SIO_REG_ADDR + 1);
810 *addr = val & ~(REGION_LENGTH - 1); 812 *addr = val & REGION_ALIGNMENT;
811 if (*addr == 0) { 813 if (*addr == 0) {
812 superio_exit(); 814 superio_exit();
813 return -ENODEV; 815 return -ENODEV;
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c
index 3479dc5208e2..70ef926c3bd8 100644
--- a/drivers/hwmon/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
@@ -142,10 +142,14 @@ superio_exit(void)
142#define WINB_BASE_REG 0x60 142#define WINB_BASE_REG 0x60
143/* Constants specified below */ 143/* Constants specified below */
144 144
145/* Length of ISA address segment */ 145/* Alignment of the base address */
146#define WINB_EXTENT 8 146#define WINB_ALIGNMENT ~7
147 147
148/* Where are the ISA address/data registers relative to the base address */ 148/* Offset & size of I/O region we are interested in */
149#define WINB_REGION_OFFSET 5
150#define WINB_REGION_SIZE 2
151
152/* Where are the sensors address/data registers relative to the base address */
149#define W83781D_ADDR_REG_OFFSET 5 153#define W83781D_ADDR_REG_OFFSET 5
150#define W83781D_DATA_REG_OFFSET 6 154#define W83781D_DATA_REG_OFFSET 6
151 155
@@ -197,7 +201,6 @@ superio_exit(void)
197 201
198#define W83627HF_REG_PWM1 0x5A 202#define W83627HF_REG_PWM1 0x5A
199#define W83627HF_REG_PWM2 0x5B 203#define W83627HF_REG_PWM2 0x5B
200#define W83627HF_REG_PWMCLK12 0x5C
201 204
202#define W83627THF_REG_PWM1 0x01 /* 697HF and 637HF too */ 205#define W83627THF_REG_PWM1 0x01 /* 697HF and 637HF too */
203#define W83627THF_REG_PWM2 0x03 /* 697HF and 637HF too */ 206#define W83627THF_REG_PWM2 0x03 /* 697HF and 637HF too */
@@ -981,7 +984,7 @@ static int __init w83627hf_find(int sioaddr, unsigned short *addr)
981 superio_select(W83627HF_LD_HWM); 984 superio_select(W83627HF_LD_HWM);
982 val = (superio_inb(WINB_BASE_REG) << 8) | 985 val = (superio_inb(WINB_BASE_REG) << 8) |
983 superio_inb(WINB_BASE_REG + 1); 986 superio_inb(WINB_BASE_REG + 1);
984 *addr = val & ~(WINB_EXTENT - 1); 987 *addr = val & WINB_ALIGNMENT;
985 if (*addr == 0 && force_addr == 0) { 988 if (*addr == 0 && force_addr == 0) {
986 superio_exit(); 989 superio_exit();
987 return -ENODEV; 990 return -ENODEV;
@@ -1000,9 +1003,10 @@ static int w83627hf_detect(struct i2c_adapter *adapter)
1000 const char *client_name = ""; 1003 const char *client_name = "";
1001 1004
1002 if(force_addr) 1005 if(force_addr)
1003 address = force_addr & ~(WINB_EXTENT - 1); 1006 address = force_addr & WINB_ALIGNMENT;
1004 1007
1005 if (!request_region(address, WINB_EXTENT, w83627hf_driver.name)) { 1008 if (!request_region(address + WINB_REGION_OFFSET, WINB_REGION_SIZE,
1009 w83627hf_driver.name)) {
1006 err = -EBUSY; 1010 err = -EBUSY;
1007 goto ERROR0; 1011 goto ERROR0;
1008 } 1012 }
@@ -1041,11 +1045,10 @@ static int w83627hf_detect(struct i2c_adapter *adapter)
1041 client structure, even though we cannot fill it completely yet. 1045 client structure, even though we cannot fill it completely yet.
1042 But it allows us to access w83627hf_{read,write}_value. */ 1046 But it allows us to access w83627hf_{read,write}_value. */
1043 1047
1044 if (!(data = kmalloc(sizeof(struct w83627hf_data), GFP_KERNEL))) { 1048 if (!(data = kzalloc(sizeof(struct w83627hf_data), GFP_KERNEL))) {
1045 err = -ENOMEM; 1049 err = -ENOMEM;
1046 goto ERROR1; 1050 goto ERROR1;
1047 } 1051 }
1048 memset(data, 0, sizeof(struct w83627hf_data));
1049 1052
1050 new_client = &data->client; 1053 new_client = &data->client;
1051 i2c_set_clientdata(new_client, data); 1054 i2c_set_clientdata(new_client, data);
@@ -1148,7 +1151,7 @@ static int w83627hf_detect(struct i2c_adapter *adapter)
1148 ERROR2: 1151 ERROR2:
1149 kfree(data); 1152 kfree(data);
1150 ERROR1: 1153 ERROR1:
1151 release_region(address, WINB_EXTENT); 1154 release_region(address + WINB_REGION_OFFSET, WINB_REGION_SIZE);
1152 ERROR0: 1155 ERROR0:
1153 return err; 1156 return err;
1154} 1157}
@@ -1163,7 +1166,7 @@ static int w83627hf_detach_client(struct i2c_client *client)
1163 if ((err = i2c_detach_client(client))) 1166 if ((err = i2c_detach_client(client)))
1164 return err; 1167 return err;
1165 1168
1166 release_region(client->addr, WINB_EXTENT); 1169 release_region(client->addr + WINB_REGION_OFFSET, WINB_REGION_SIZE);
1167 kfree(data); 1170 kfree(data);
1168 1171
1169 return 0; 1172 return 0;
@@ -1275,7 +1278,6 @@ static int w83627hf_write_value(struct i2c_client *client, u16 reg, u16 value)
1275 return 0; 1278 return 0;
1276} 1279}
1277 1280
1278/* Called when we have found a new W83781D. It should set limits, etc. */
1279static void w83627hf_init_client(struct i2c_client *client) 1281static void w83627hf_init_client(struct i2c_client *client)
1280{ 1282{
1281 struct w83627hf_data *data = i2c_get_clientdata(client); 1283 struct w83627hf_data *data = i2c_get_clientdata(client);
@@ -1369,12 +1371,6 @@ static void w83627hf_init_client(struct i2c_client *client)
1369 } 1371 }
1370 } 1372 }
1371 1373
1372 if (type == w83627hf) {
1373 /* enable PWM2 control (can't hurt since PWM reg
1374 should have been reset to 0xff) */
1375 w83627hf_write_value(client, W83627HF_REG_PWMCLK12,
1376 0x19);
1377 }
1378 /* enable comparator mode for temp2 and temp3 so 1374 /* enable comparator mode for temp2 and temp3 so
1379 alarm indication will work correctly */ 1375 alarm indication will work correctly */
1380 i = w83627hf_read_value(client, W83781D_REG_IRQ); 1376 i = w83627hf_read_value(client, W83781D_REG_IRQ);
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index 4c43337ca780..9265f32122fa 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -889,12 +889,11 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind,
889 const char *client_name = ""; 889 const char *client_name = "";
890 struct w83781d_data *data = i2c_get_clientdata(new_client); 890 struct w83781d_data *data = i2c_get_clientdata(new_client);
891 891
892 data->lm75[0] = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); 892 data->lm75[0] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
893 if (!(data->lm75[0])) { 893 if (!(data->lm75[0])) {
894 err = -ENOMEM; 894 err = -ENOMEM;
895 goto ERROR_SC_0; 895 goto ERROR_SC_0;
896 } 896 }
897 memset(data->lm75[0], 0x00, sizeof (struct i2c_client));
898 897
899 id = i2c_adapter_id(adapter); 898 id = i2c_adapter_id(adapter);
900 899
@@ -919,13 +918,11 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind,
919 } 918 }
920 919
921 if (kind != w83783s) { 920 if (kind != w83783s) {
922 921 data->lm75[1] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
923 data->lm75[1] = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
924 if (!(data->lm75[1])) { 922 if (!(data->lm75[1])) {
925 err = -ENOMEM; 923 err = -ENOMEM;
926 goto ERROR_SC_1; 924 goto ERROR_SC_1;
927 } 925 }
928 memset(data->lm75[1], 0x0, sizeof(struct i2c_client));
929 926
930 if (force_subclients[0] == id && 927 if (force_subclients[0] == id &&
931 force_subclients[1] == address) { 928 force_subclients[1] == address) {
@@ -1064,11 +1061,10 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1064 client structure, even though we cannot fill it completely yet. 1061 client structure, even though we cannot fill it completely yet.
1065 But it allows us to access w83781d_{read,write}_value. */ 1062 But it allows us to access w83781d_{read,write}_value. */
1066 1063
1067 if (!(data = kmalloc(sizeof(struct w83781d_data), GFP_KERNEL))) { 1064 if (!(data = kzalloc(sizeof(struct w83781d_data), GFP_KERNEL))) {
1068 err = -ENOMEM; 1065 err = -ENOMEM;
1069 goto ERROR1; 1066 goto ERROR1;
1070 } 1067 }
1071 memset(data, 0, sizeof(struct w83781d_data));
1072 1068
1073 new_client = &data->client; 1069 new_client = &data->client;
1074 i2c_set_clientdata(new_client, data); 1070 i2c_set_clientdata(new_client, data);
@@ -1451,7 +1447,6 @@ w83781d_write_value(struct i2c_client *client, u16 reg, u16 value)
1451 return 0; 1447 return 0;
1452} 1448}
1453 1449
1454/* Called when we have found a new W83781D. It should set limits, etc. */
1455static void 1450static void
1456w83781d_init_client(struct i2c_client *client) 1451w83781d_init_client(struct i2c_client *client)
1457{ 1452{
diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c
index ba0c28015f6a..4be59dbb78c4 100644
--- a/drivers/hwmon/w83792d.c
+++ b/drivers/hwmon/w83792d.c
@@ -1086,11 +1086,10 @@ w83792d_create_subclient(struct i2c_adapter *adapter,
1086 int err; 1086 int err;
1087 struct i2c_client *sub_client; 1087 struct i2c_client *sub_client;
1088 1088
1089 (*sub_cli) = sub_client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); 1089 (*sub_cli) = sub_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
1090 if (!(sub_client)) { 1090 if (!(sub_client)) {
1091 return -ENOMEM; 1091 return -ENOMEM;
1092 } 1092 }
1093 memset(sub_client, 0x00, sizeof(struct i2c_client));
1094 sub_client->addr = 0x48 + addr; 1093 sub_client->addr = 0x48 + addr;
1095 i2c_set_clientdata(sub_client, NULL); 1094 i2c_set_clientdata(sub_client, NULL);
1096 sub_client->adapter = adapter; 1095 sub_client->adapter = adapter;
@@ -1184,11 +1183,10 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind)
1184 client structure, even though we cannot fill it completely yet. 1183 client structure, even though we cannot fill it completely yet.
1185 But it allows us to access w83792d_{read,write}_value. */ 1184 But it allows us to access w83792d_{read,write}_value. */
1186 1185
1187 if (!(data = kmalloc(sizeof(struct w83792d_data), GFP_KERNEL))) { 1186 if (!(data = kzalloc(sizeof(struct w83792d_data), GFP_KERNEL))) {
1188 err = -ENOMEM; 1187 err = -ENOMEM;
1189 goto ERROR0; 1188 goto ERROR0;
1190 } 1189 }
1191 memset(data, 0, sizeof(struct w83792d_data));
1192 1190
1193 new_client = &data->client; 1191 new_client = &data->client;
1194 i2c_set_clientdata(new_client, data); 1192 i2c_set_clientdata(new_client, data);
@@ -1429,7 +1427,6 @@ w83792d_write_value(struct i2c_client *client, u8 reg, u8 value)
1429 return 0; 1427 return 0;
1430} 1428}
1431 1429
1432/* Called when we have found a new W83792D. It should set limits, etc. */
1433static void 1430static void
1434w83792d_init_client(struct i2c_client *client) 1431w83792d_init_client(struct i2c_client *client)
1435{ 1432{
diff --git a/drivers/hwmon/w83l785ts.c b/drivers/hwmon/w83l785ts.c
index 133e34ab1d0a..f495b6378668 100644
--- a/drivers/hwmon/w83l785ts.c
+++ b/drivers/hwmon/w83l785ts.c
@@ -37,6 +37,7 @@
37#include <linux/jiffies.h> 37#include <linux/jiffies.h>
38#include <linux/i2c.h> 38#include <linux/i2c.h>
39#include <linux/hwmon.h> 39#include <linux/hwmon.h>
40#include <linux/hwmon-sysfs.h>
40#include <linux/err.h> 41#include <linux/err.h>
41 42
42/* How many retries on register read error */ 43/* How many retries on register read error */
@@ -73,7 +74,7 @@ I2C_CLIENT_INSMOD_1(w83l785ts);
73 * The W83L785TS-S uses signed 8-bit values. 74 * The W83L785TS-S uses signed 8-bit values.
74 */ 75 */
75 76
76#define TEMP_FROM_REG(val) ((val & 0x80 ? val-0x100 : val) * 1000) 77#define TEMP_FROM_REG(val) ((val) * 1000)
77 78
78/* 79/*
79 * Functions declaration 80 * Functions declaration
@@ -111,27 +112,24 @@ struct w83l785ts_data {
111 unsigned long last_updated; /* in jiffies */ 112 unsigned long last_updated; /* in jiffies */
112 113
113 /* registers values */ 114 /* registers values */
114 u8 temp, temp_over; 115 s8 temp[2]; /* 0: input
116 1: critical limit */
115}; 117};
116 118
117/* 119/*
118 * Sysfs stuff 120 * Sysfs stuff
119 */ 121 */
120 122
121static ssize_t show_temp(struct device *dev, struct device_attribute *attr, char *buf) 123static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
124 char *buf)
122{ 125{
126 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
123 struct w83l785ts_data *data = w83l785ts_update_device(dev); 127 struct w83l785ts_data *data = w83l785ts_update_device(dev);
124 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp)); 128 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index]));
125} 129}
126 130
127static ssize_t show_temp_over(struct device *dev, struct device_attribute *attr, char *buf) 131static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
128{ 132static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, show_temp, NULL, 1);
129 struct w83l785ts_data *data = w83l785ts_update_device(dev);
130 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over));
131}
132
133static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL);
134static DEVICE_ATTR(temp1_max, S_IRUGO, show_temp_over, NULL);
135 133
136/* 134/*
137 * Real code 135 * Real code
@@ -158,12 +156,10 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind)
158 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 156 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
159 goto exit; 157 goto exit;
160 158
161 if (!(data = kmalloc(sizeof(struct w83l785ts_data), GFP_KERNEL))) { 159 if (!(data = kzalloc(sizeof(struct w83l785ts_data), GFP_KERNEL))) {
162 err = -ENOMEM; 160 err = -ENOMEM;
163 goto exit; 161 goto exit;
164 } 162 }
165 memset(data, 0, sizeof(struct w83l785ts_data));
166
167 163
168 /* The common I2C client data is placed right before the 164 /* The common I2C client data is placed right before the
169 * W83L785TS-specific data. */ 165 * W83L785TS-specific data. */
@@ -228,7 +224,7 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind)
228 init_MUTEX(&data->update_lock); 224 init_MUTEX(&data->update_lock);
229 225
230 /* Default values in case the first read fails (unlikely). */ 226 /* Default values in case the first read fails (unlikely). */
231 data->temp_over = data->temp = 0; 227 data->temp[1] = data->temp[0] = 0;
232 228
233 /* Tell the I2C layer a new client has arrived. */ 229 /* Tell the I2C layer a new client has arrived. */
234 if ((err = i2c_attach_client(new_client))) 230 if ((err = i2c_attach_client(new_client)))
@@ -246,8 +242,10 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind)
246 goto exit_detach; 242 goto exit_detach;
247 } 243 }
248 244
249 device_create_file(&new_client->dev, &dev_attr_temp1_input); 245 device_create_file(&new_client->dev,
250 device_create_file(&new_client->dev, &dev_attr_temp1_max); 246 &sensor_dev_attr_temp1_input.dev_attr);
247 device_create_file(&new_client->dev,
248 &sensor_dev_attr_temp1_max.dev_attr);
251 249
252 return 0; 250 return 0;
253 251
@@ -305,10 +303,10 @@ static struct w83l785ts_data *w83l785ts_update_device(struct device *dev)
305 303
306 if (!data->valid || time_after(jiffies, data->last_updated + HZ * 2)) { 304 if (!data->valid || time_after(jiffies, data->last_updated + HZ * 2)) {
307 dev_dbg(&client->dev, "Updating w83l785ts data.\n"); 305 dev_dbg(&client->dev, "Updating w83l785ts data.\n");
308 data->temp = w83l785ts_read_value(client, 306 data->temp[0] = w83l785ts_read_value(client,
309 W83L785TS_REG_TEMP, data->temp); 307 W83L785TS_REG_TEMP, data->temp[0]);
310 data->temp_over = w83l785ts_read_value(client, 308 data->temp[1] = w83l785ts_read_value(client,
311 W83L785TS_REG_TEMP_OVER, data->temp_over); 309 W83L785TS_REG_TEMP_OVER, data->temp[1]);
312 310
313 data->last_updated = jiffies; 311 data->last_updated = jiffies;
314 data->valid = 1; 312 data->valid = 1;
diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c
index beb10edfe9c1..82946acab4c7 100644
--- a/drivers/i2c/algos/i2c-algo-pca.c
+++ b/drivers/i2c/algos/i2c-algo-pca.c
@@ -34,7 +34,7 @@
34#define DEB2(fmt, args...) do { if (i2c_debug>=2) printk(fmt, ## args); } while(0) 34#define DEB2(fmt, args...) do { if (i2c_debug>=2) printk(fmt, ## args); } while(0)
35#define DEB3(fmt, args...) do { if (i2c_debug>=3) printk(fmt, ## args); } while(0) 35#define DEB3(fmt, args...) do { if (i2c_debug>=3) printk(fmt, ## args); } while(0)
36 36
37static int i2c_debug=0; 37static int i2c_debug;
38 38
39#define pca_outw(adap, reg, val) adap->write_byte(adap, reg, val) 39#define pca_outw(adap, reg, val) adap->write_byte(adap, reg, val)
40#define pca_inw(adap, reg) adap->read_byte(adap, reg) 40#define pca_inw(adap, reg) adap->read_byte(adap, reg)
diff --git a/drivers/i2c/algos/i2c-algo-sibyte.c b/drivers/i2c/algos/i2c-algo-sibyte.c
index 8ed5ad12552f..938848ae162d 100644
--- a/drivers/i2c/algos/i2c-algo-sibyte.c
+++ b/drivers/i2c/algos/i2c-algo-sibyte.c
@@ -42,7 +42,7 @@
42 42
43/* module parameters: 43/* module parameters:
44 */ 44 */
45static int bit_scan=0; /* have a look at what's hanging 'round */ 45static int bit_scan; /* have a look at what's hanging 'round */
46 46
47 47
48static int smbus_xfer(struct i2c_adapter *i2c_adap, u16 addr, 48static int smbus_xfer(struct i2c_adapter *i2c_adap, u16 addr,
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 3badfec75b1c..4010fe92e72b 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -135,11 +135,12 @@ config I2C_I810
135 help 135 help
136 If you say yes to this option, support will be included for the Intel 136 If you say yes to this option, support will be included for the Intel
137 810/815 family of mainboard I2C interfaces. Specifically, the 137 810/815 family of mainboard I2C interfaces. Specifically, the
138 following versions of the chipset is supported: 138 following versions of the chipset are supported:
139 i810AA 139 i810AA
140 i810AB 140 i810AB
141 i810E 141 i810E
142 i815 142 i815
143 i845G
143 144
144 This driver can also be built as a module. If so, the module 145 This driver can also be built as a module. If so, the module
145 will be called i2c-i810. 146 will be called i2c-i810.
diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c
index f021acd2674e..ba90f5140af6 100644
--- a/drivers/i2c/busses/i2c-ali1535.c
+++ b/drivers/i2c/busses/i2c-ali1535.c
@@ -134,7 +134,7 @@
134 /* -> Read = 1 */ 134 /* -> Read = 1 */
135#define ALI1535_SMBIO_EN 0x04 /* SMB I/O Space enable */ 135#define ALI1535_SMBIO_EN 0x04 /* SMB I/O Space enable */
136 136
137 137static struct pci_driver ali1535_driver;
138static unsigned short ali1535_smba; 138static unsigned short ali1535_smba;
139static DECLARE_MUTEX(i2c_ali1535_sem); 139static DECLARE_MUTEX(i2c_ali1535_sem);
140 140
@@ -162,7 +162,8 @@ static int ali1535_setup(struct pci_dev *dev)
162 goto exit; 162 goto exit;
163 } 163 }
164 164
165 if (!request_region(ali1535_smba, ALI1535_SMB_IOSIZE, "ali1535-smb")) { 165 if (!request_region(ali1535_smba, ALI1535_SMB_IOSIZE,
166 ali1535_driver.name)) {
166 dev_err(&dev->dev, "ALI1535_smb region 0x%x already in use!\n", 167 dev_err(&dev->dev, "ALI1535_smb region 0x%x already in use!\n",
167 ali1535_smba); 168 ali1535_smba);
168 goto exit; 169 goto exit;
@@ -480,7 +481,6 @@ static struct i2c_adapter ali1535_adapter = {
480 .owner = THIS_MODULE, 481 .owner = THIS_MODULE,
481 .class = I2C_CLASS_HWMON, 482 .class = I2C_CLASS_HWMON,
482 .algo = &smbus_algorithm, 483 .algo = &smbus_algorithm,
483 .name = "unset",
484}; 484};
485 485
486static struct pci_device_id ali1535_ids[] = { 486static struct pci_device_id ali1535_ids[] = {
@@ -513,6 +513,7 @@ static void __devexit ali1535_remove(struct pci_dev *dev)
513} 513}
514 514
515static struct pci_driver ali1535_driver = { 515static struct pci_driver ali1535_driver = {
516 .owner = THIS_MODULE,
516 .name = "ali1535_smbus", 517 .name = "ali1535_smbus",
517 .id_table = ali1535_ids, 518 .id_table = ali1535_ids,
518 .probe = ali1535_probe, 519 .probe = ali1535_probe,
diff --git a/drivers/i2c/busses/i2c-ali1563.c b/drivers/i2c/busses/i2c-ali1563.c
index 86947504aea1..f1a62d892425 100644
--- a/drivers/i2c/busses/i2c-ali1563.c
+++ b/drivers/i2c/busses/i2c-ali1563.c
@@ -60,6 +60,7 @@
60 60
61#define HST_CNTL2_SIZEMASK 0x38 61#define HST_CNTL2_SIZEMASK 0x38
62 62
63static struct pci_driver ali1563_pci_driver;
63static unsigned short ali1563_smba; 64static unsigned short ali1563_smba;
64 65
65static int ali1563_transaction(struct i2c_adapter * a, int size) 66static int ali1563_transaction(struct i2c_adapter * a, int size)
@@ -350,7 +351,8 @@ static int __devinit ali1563_setup(struct pci_dev * dev)
350 dev_warn(&dev->dev,"ali1563_smba Uninitialized\n"); 351 dev_warn(&dev->dev,"ali1563_smba Uninitialized\n");
351 goto Err; 352 goto Err;
352 } 353 }
353 if (!request_region(ali1563_smba,ALI1563_SMB_IOSIZE,"i2c-ali1563")) { 354 if (!request_region(ali1563_smba, ALI1563_SMB_IOSIZE,
355 ali1563_pci_driver.name)) {
354 dev_warn(&dev->dev,"Could not allocate I/O space"); 356 dev_warn(&dev->dev,"Could not allocate I/O space");
355 goto Err; 357 goto Err;
356 } 358 }
@@ -406,7 +408,8 @@ static struct pci_device_id __devinitdata ali1563_id_table[] = {
406MODULE_DEVICE_TABLE (pci, ali1563_id_table); 408MODULE_DEVICE_TABLE (pci, ali1563_id_table);
407 409
408static struct pci_driver ali1563_pci_driver = { 410static struct pci_driver ali1563_pci_driver = {
409 .name = "ali1563_i2c", 411 .owner = THIS_MODULE,
412 .name = "ali1563_smbus",
410 .id_table = ali1563_id_table, 413 .id_table = ali1563_id_table,
411 .probe = ali1563_probe, 414 .probe = ali1563_probe,
412 .remove = __devexit_p(ali1563_remove), 415 .remove = __devexit_p(ali1563_remove),
diff --git a/drivers/i2c/busses/i2c-ali15x3.c b/drivers/i2c/busses/i2c-ali15x3.c
index b3f50bff39a0..400b08ed4299 100644
--- a/drivers/i2c/busses/i2c-ali15x3.c
+++ b/drivers/i2c/busses/i2c-ali15x3.c
@@ -125,12 +125,13 @@
125 125
126/* If force_addr is set to anything different from 0, we forcibly enable 126/* If force_addr is set to anything different from 0, we forcibly enable
127 the device at the given address. */ 127 the device at the given address. */
128static u16 force_addr = 0; 128static u16 force_addr;
129module_param(force_addr, ushort, 0); 129module_param(force_addr, ushort, 0);
130MODULE_PARM_DESC(force_addr, 130MODULE_PARM_DESC(force_addr,
131 "Initialize the base address of the i2c controller"); 131 "Initialize the base address of the i2c controller");
132 132
133static unsigned short ali15x3_smba = 0; 133static struct pci_driver ali15x3_driver;
134static unsigned short ali15x3_smba;
134 135
135static int ali15x3_setup(struct pci_dev *ALI15X3_dev) 136static int ali15x3_setup(struct pci_dev *ALI15X3_dev)
136{ 137{
@@ -166,7 +167,8 @@ static int ali15x3_setup(struct pci_dev *ALI15X3_dev)
166 if(force_addr) 167 if(force_addr)
167 ali15x3_smba = force_addr & ~(ALI15X3_SMB_IOSIZE - 1); 168 ali15x3_smba = force_addr & ~(ALI15X3_SMB_IOSIZE - 1);
168 169
169 if (!request_region(ali15x3_smba, ALI15X3_SMB_IOSIZE, "ali15x3-smb")) { 170 if (!request_region(ali15x3_smba, ALI15X3_SMB_IOSIZE,
171 ali15x3_driver.name)) {
170 dev_err(&ALI15X3_dev->dev, 172 dev_err(&ALI15X3_dev->dev,
171 "ALI15X3_smb region 0x%x already in use!\n", 173 "ALI15X3_smb region 0x%x already in use!\n",
172 ali15x3_smba); 174 ali15x3_smba);
@@ -470,7 +472,6 @@ static struct i2c_adapter ali15x3_adapter = {
470 .owner = THIS_MODULE, 472 .owner = THIS_MODULE,
471 .class = I2C_CLASS_HWMON, 473 .class = I2C_CLASS_HWMON,
472 .algo = &smbus_algorithm, 474 .algo = &smbus_algorithm,
473 .name = "unset",
474}; 475};
475 476
476static struct pci_device_id ali15x3_ids[] = { 477static struct pci_device_id ali15x3_ids[] = {
@@ -503,6 +504,7 @@ static void __devexit ali15x3_remove(struct pci_dev *dev)
503} 504}
504 505
505static struct pci_driver ali15x3_driver = { 506static struct pci_driver ali15x3_driver = {
507 .owner = THIS_MODULE,
506 .name = "ali15x3_smbus", 508 .name = "ali15x3_smbus",
507 .id_table = ali15x3_ids, 509 .id_table = ali15x3_ids,
508 .probe = ali15x3_probe, 510 .probe = ali15x3_probe,
diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
index 4e553e8c5cba..f51ab652300a 100644
--- a/drivers/i2c/busses/i2c-amd756-s4882.c
+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
@@ -169,12 +169,12 @@ static int __init amd756_s4882_init(void)
169 init_MUTEX(&amd756_lock); 169 init_MUTEX(&amd756_lock);
170 170
171 /* Define the 5 virtual adapters and algorithms structures */ 171 /* Define the 5 virtual adapters and algorithms structures */
172 if (!(s4882_adapter = kmalloc(5 * sizeof(struct i2c_adapter), 172 if (!(s4882_adapter = kzalloc(5 * sizeof(struct i2c_adapter),
173 GFP_KERNEL))) { 173 GFP_KERNEL))) {
174 error = -ENOMEM; 174 error = -ENOMEM;
175 goto ERROR1; 175 goto ERROR1;
176 } 176 }
177 if (!(s4882_algo = kmalloc(5 * sizeof(struct i2c_algorithm), 177 if (!(s4882_algo = kzalloc(5 * sizeof(struct i2c_algorithm),
178 GFP_KERNEL))) { 178 GFP_KERNEL))) {
179 error = -ENOMEM; 179 error = -ENOMEM;
180 goto ERROR2; 180 goto ERROR2;
diff --git a/drivers/i2c/busses/i2c-amd756.c b/drivers/i2c/busses/i2c-amd756.c
index 6ad0603384b8..de035d137c3f 100644
--- a/drivers/i2c/busses/i2c-amd756.c
+++ b/drivers/i2c/busses/i2c-amd756.c
@@ -85,8 +85,8 @@
85#define AMD756_PROCESS_CALL 0x04 85#define AMD756_PROCESS_CALL 0x04
86#define AMD756_BLOCK_DATA 0x05 86#define AMD756_BLOCK_DATA 0x05
87 87
88 88static struct pci_driver amd756_driver;
89static unsigned short amd756_ioport = 0; 89static unsigned short amd756_ioport;
90 90
91/* 91/*
92 SMBUS event = I/O 28-29 bit 11 92 SMBUS event = I/O 28-29 bit 11
@@ -303,7 +303,6 @@ struct i2c_adapter amd756_smbus = {
303 .owner = THIS_MODULE, 303 .owner = THIS_MODULE,
304 .class = I2C_CLASS_HWMON, 304 .class = I2C_CLASS_HWMON,
305 .algo = &smbus_algorithm, 305 .algo = &smbus_algorithm,
306 .name = "unset",
307}; 306};
308 307
309enum chiptype { AMD756, AMD766, AMD768, NFORCE, AMD8111 }; 308enum chiptype { AMD756, AMD766, AMD768, NFORCE, AMD8111 };
@@ -365,7 +364,7 @@ static int __devinit amd756_probe(struct pci_dev *pdev,
365 amd756_ioport += SMB_ADDR_OFFSET; 364 amd756_ioport += SMB_ADDR_OFFSET;
366 } 365 }
367 366
368 if (!request_region(amd756_ioport, SMB_IOSIZE, "amd756-smbus")) { 367 if (!request_region(amd756_ioport, SMB_IOSIZE, amd756_driver.name)) {
369 dev_err(&pdev->dev, "SMB region 0x%x already in use!\n", 368 dev_err(&pdev->dev, "SMB region 0x%x already in use!\n",
370 amd756_ioport); 369 amd756_ioport);
371 return -ENODEV; 370 return -ENODEV;
@@ -402,6 +401,7 @@ static void __devexit amd756_remove(struct pci_dev *dev)
402} 401}
403 402
404static struct pci_driver amd756_driver = { 403static struct pci_driver amd756_driver = {
404 .owner = THIS_MODULE,
405 .name = "amd756_smbus", 405 .name = "amd756_smbus",
406 .id_table = amd756_ids, 406 .id_table = amd756_ids,
407 .probe = amd756_probe, 407 .probe = amd756_probe,
diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c
index 45ea24ba14d5..f3b79a68dbec 100644
--- a/drivers/i2c/busses/i2c-amd8111.c
+++ b/drivers/i2c/busses/i2c-amd8111.c
@@ -30,6 +30,8 @@ struct amd_smbus {
30 int size; 30 int size;
31}; 31};
32 32
33static struct pci_driver amd8111_driver;
34
33/* 35/*
34 * AMD PCI control registers definitions. 36 * AMD PCI control registers definitions.
35 */ 37 */
@@ -242,7 +244,6 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr, unsigned short fl
242 break; 244 break;
243 245
244 case I2C_SMBUS_BLOCK_PROC_CALL: 246 case I2C_SMBUS_BLOCK_PROC_CALL:
245 protocol |= pec;
246 len = min_t(u8, data->block[0], 31); 247 len = min_t(u8, data->block[0], 31);
247 amd_ec_write(smbus, AMD_SMB_CMD, command); 248 amd_ec_write(smbus, AMD_SMB_CMD, command);
248 amd_ec_write(smbus, AMD_SMB_BCNT, len); 249 amd_ec_write(smbus, AMD_SMB_BCNT, len);
@@ -252,13 +253,6 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr, unsigned short fl
252 read_write = I2C_SMBUS_READ; 253 read_write = I2C_SMBUS_READ;
253 break; 254 break;
254 255
255 case I2C_SMBUS_WORD_DATA_PEC:
256 case I2C_SMBUS_BLOCK_DATA_PEC:
257 case I2C_SMBUS_PROC_CALL_PEC:
258 case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
259 dev_warn(&adap->dev, "Unexpected software PEC transaction %d\n.", size);
260 return -1;
261
262 default: 256 default:
263 dev_warn(&adap->dev, "Unsupported transaction %d\n", size); 257 dev_warn(&adap->dev, "Unsupported transaction %d\n", size);
264 return -1; 258 return -1;
@@ -343,16 +337,15 @@ static int __devinit amd8111_probe(struct pci_dev *dev, const struct pci_device_
343 if (~pci_resource_flags(dev, 0) & IORESOURCE_IO) 337 if (~pci_resource_flags(dev, 0) & IORESOURCE_IO)
344 return -ENODEV; 338 return -ENODEV;
345 339
346 smbus = kmalloc(sizeof(struct amd_smbus), GFP_KERNEL); 340 smbus = kzalloc(sizeof(struct amd_smbus), GFP_KERNEL);
347 if (!smbus) 341 if (!smbus)
348 return -ENOMEM; 342 return -ENOMEM;
349 memset(smbus, 0, sizeof(struct amd_smbus));
350 343
351 smbus->dev = dev; 344 smbus->dev = dev;
352 smbus->base = pci_resource_start(dev, 0); 345 smbus->base = pci_resource_start(dev, 0);
353 smbus->size = pci_resource_len(dev, 0); 346 smbus->size = pci_resource_len(dev, 0);
354 347
355 if (!request_region(smbus->base, smbus->size, "amd8111 SMBus 2.0")) 348 if (!request_region(smbus->base, smbus->size, amd8111_driver.name))
356 goto out_kfree; 349 goto out_kfree;
357 350
358 smbus->adapter.owner = THIS_MODULE; 351 smbus->adapter.owner = THIS_MODULE;
@@ -391,6 +384,7 @@ static void __devexit amd8111_remove(struct pci_dev *dev)
391} 384}
392 385
393static struct pci_driver amd8111_driver = { 386static struct pci_driver amd8111_driver = {
387 .owner = THIS_MODULE,
394 .name = "amd8111_smbus2", 388 .name = "amd8111_smbus2",
395 .id_table = amd8111_ids, 389 .id_table = amd8111_ids,
396 .probe = amd8111_probe, 390 .probe = amd8111_probe,
diff --git a/drivers/i2c/busses/i2c-elektor.c b/drivers/i2c/busses/i2c-elektor.c
index 6930b660e508..59f8308c2356 100644
--- a/drivers/i2c/busses/i2c-elektor.c
+++ b/drivers/i2c/busses/i2c-elektor.c
@@ -22,7 +22,7 @@
22/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even 22/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
23 Frodo Looijaard <frodol@dds.nl> */ 23 Frodo Looijaard <frodol@dds.nl> */
24 24
25/* Partialy rewriten by Oleg I. Vdovikin for mmapped support of 25/* Partialy rewriten by Oleg I. Vdovikin for mmapped support of
26 for Alpha Processor Inc. UP-2000(+) boards */ 26 for Alpha Processor Inc. UP-2000(+) boards */
27 27
28#include <linux/kernel.h> 28#include <linux/kernel.h>
@@ -46,12 +46,14 @@
46#define DEFAULT_BASE 0x330 46#define DEFAULT_BASE 0x330
47 47
48static int base; 48static int base;
49static u8 __iomem *base_iomem;
50
49static int irq; 51static int irq;
50static int clock = 0x1c; 52static int clock = 0x1c;
51static int own = 0x55; 53static int own = 0x55;
52static int mmapped; 54static int mmapped;
53 55
54/* vdovikin: removed static struct i2c_pcf_isa gpi; code - 56/* vdovikin: removed static struct i2c_pcf_isa gpi; code -
55 this module in real supports only one device, due to missing arguments 57 this module in real supports only one device, due to missing arguments
56 in some functions, called from the algo-pcf module. Sometimes it's 58 in some functions, called from the algo-pcf module. Sometimes it's
57 need to be rewriten - but for now just remove this for simpler reading */ 59 need to be rewriten - but for now just remove this for simpler reading */
@@ -60,40 +62,33 @@ static wait_queue_head_t pcf_wait;
60static int pcf_pending; 62static int pcf_pending;
61static spinlock_t lock; 63static spinlock_t lock;
62 64
65static struct i2c_adapter pcf_isa_ops;
66
63/* ----- local functions ---------------------------------------------- */ 67/* ----- local functions ---------------------------------------------- */
64 68
65static void pcf_isa_setbyte(void *data, int ctl, int val) 69static void pcf_isa_setbyte(void *data, int ctl, int val)
66{ 70{
67 int address = ctl ? (base + 1) : base; 71 u8 __iomem *address = ctl ? (base_iomem + 1) : base_iomem;
68 72
69 /* enable irq if any specified for serial operation */ 73 /* enable irq if any specified for serial operation */
70 if (ctl && irq && (val & I2C_PCF_ESO)) { 74 if (ctl && irq && (val & I2C_PCF_ESO)) {
71 val |= I2C_PCF_ENI; 75 val |= I2C_PCF_ENI;
72 } 76 }
73 77
74 pr_debug("i2c-elektor: Write 0x%X 0x%02X\n", address, val & 255); 78 pr_debug("%s: Write %p 0x%02X\n", pcf_isa_ops.name, address, val);
75 79 iowrite8(val, address);
76 switch (mmapped) { 80#ifdef __alpha__
77 case 0: /* regular I/O */ 81 /* API UP2000 needs some hardware fudging to make the write stick */
78 outb(val, address); 82 iowrite8(val, address);
79 break; 83#endif
80 case 2: /* double mapped I/O needed for UP2000 board,
81 I don't know why this... */
82 writeb(val, (void *)address);
83 /* fall */
84 case 1: /* memory mapped I/O */
85 writeb(val, (void *)address);
86 break;
87 }
88} 84}
89 85
90static int pcf_isa_getbyte(void *data, int ctl) 86static int pcf_isa_getbyte(void *data, int ctl)
91{ 87{
92 int address = ctl ? (base + 1) : base; 88 u8 __iomem *address = ctl ? (base_iomem + 1) : base_iomem;
93 int val = mmapped ? readb((void *)address) : inb(address); 89 int val = ioread8(address);
94
95 pr_debug("i2c-elektor: Read 0x%X 0x%02X\n", address, val);
96 90
91 pr_debug("%s: Read %p 0x%02X\n", pcf_isa_ops.name, address, val);
97 return (val); 92 return (val);
98} 93}
99 94
@@ -149,16 +144,40 @@ static int pcf_isa_init(void)
149{ 144{
150 spin_lock_init(&lock); 145 spin_lock_init(&lock);
151 if (!mmapped) { 146 if (!mmapped) {
152 if (!request_region(base, 2, "i2c (isa bus adapter)")) { 147 if (!request_region(base, 2, pcf_isa_ops.name)) {
153 printk(KERN_ERR 148 printk(KERN_ERR "%s: requested I/O region (%#x:2) is "
154 "i2c-elektor: requested I/O region (0x%X:2) " 149 "in use\n", pcf_isa_ops.name, base);
155 "is in use.\n", base); 150 return -ENODEV;
151 }
152 base_iomem = ioport_map(base, 2);
153 if (!base_iomem) {
154 printk(KERN_ERR "%s: remap of I/O region %#x failed\n",
155 pcf_isa_ops.name, base);
156 release_region(base, 2);
157 return -ENODEV;
158 }
159 } else {
160 if (!request_mem_region(base, 2, pcf_isa_ops.name)) {
161 printk(KERN_ERR "%s: requested memory region (%#x:2) "
162 "is in use\n", pcf_isa_ops.name, base);
163 return -ENODEV;
164 }
165 base_iomem = ioremap(base, 2);
166 if (base_iomem == NULL) {
167 printk(KERN_ERR "%s: remap of memory region %#x "
168 "failed\n", pcf_isa_ops.name, base);
169 release_mem_region(base, 2);
156 return -ENODEV; 170 return -ENODEV;
157 } 171 }
158 } 172 }
173 pr_debug("%s: registers %#x remapped to %p\n", pcf_isa_ops.name, base,
174 base_iomem);
175
159 if (irq > 0) { 176 if (irq > 0) {
160 if (request_irq(irq, pcf_isa_handler, 0, "PCF8584", NULL) < 0) { 177 if (request_irq(irq, pcf_isa_handler, 0, pcf_isa_ops.name,
161 printk(KERN_ERR "i2c-elektor: Request irq%d failed\n", irq); 178 NULL) < 0) {
179 printk(KERN_ERR "%s: Request irq%d failed\n",
180 pcf_isa_ops.name, irq);
162 irq = 0; 181 irq = 0;
163 } else 182 } else
164 enable_irq(irq); 183 enable_irq(irq);
@@ -186,47 +205,49 @@ static struct i2c_adapter pcf_isa_ops = {
186 .class = I2C_CLASS_HWMON, 205 .class = I2C_CLASS_HWMON,
187 .id = I2C_HW_P_ELEK, 206 .id = I2C_HW_P_ELEK,
188 .algo_data = &pcf_isa_data, 207 .algo_data = &pcf_isa_data,
189 .name = "PCF8584 ISA adapter", 208 .name = "i2c-elektor",
190}; 209};
191 210
192static int __init i2c_pcfisa_init(void) 211static int __init i2c_pcfisa_init(void)
193{ 212{
194#ifdef __alpha__ 213#ifdef __alpha__
195 /* check to see we have memory mapped PCF8584 connected to the 214 /* check to see we have memory mapped PCF8584 connected to the
196 Cypress cy82c693 PCI-ISA bridge as on UP2000 board */ 215 Cypress cy82c693 PCI-ISA bridge as on UP2000 board */
197 if (base == 0) { 216 if (base == 0) {
198 struct pci_dev *cy693_dev; 217 struct pci_dev *cy693_dev;
199 218
200 cy693_dev = pci_get_device(PCI_VENDOR_ID_CONTAQ, 219 cy693_dev = pci_get_device(PCI_VENDOR_ID_CONTAQ,
201 PCI_DEVICE_ID_CONTAQ_82C693, NULL); 220 PCI_DEVICE_ID_CONTAQ_82C693, NULL);
202 if (cy693_dev) { 221 if (cy693_dev) {
203 char config; 222 unsigned char config;
204 /* yeap, we've found cypress, let's check config */ 223 /* yeap, we've found cypress, let's check config */
205 if (!pci_read_config_byte(cy693_dev, 0x47, &config)) { 224 if (!pci_read_config_byte(cy693_dev, 0x47, &config)) {
206 225
207 pr_debug("i2c-elektor: found cy82c693, config register 0x47 = 0x%02x.\n", config); 226 pr_debug("%s: found cy82c693, config "
227 "register 0x47 = 0x%02x\n",
228 pcf_isa_ops.name, config);
208 229
209 /* UP2000 board has this register set to 0xe1, 230 /* UP2000 board has this register set to 0xe1,
210 but the most significant bit as seems can be 231 but the most significant bit as seems can be
211 reset during the proper initialisation 232 reset during the proper initialisation
212 sequence if guys from API decides to do that 233 sequence if guys from API decides to do that
213 (so, we can even enable Tsunami Pchip 234 (so, we can even enable Tsunami Pchip
214 window for the upper 1 Gb) */ 235 window for the upper 1 Gb) */
215 236
216 /* so just check for ROMCS at 0xe0000, 237 /* so just check for ROMCS at 0xe0000,
217 ROMCS enabled for writes 238 ROMCS enabled for writes
218 and external XD Bus buffer in use. */ 239 and external XD Bus buffer in use. */
219 if ((config & 0x7f) == 0x61) { 240 if ((config & 0x7f) == 0x61) {
220 /* seems to be UP2000 like board */ 241 /* seems to be UP2000 like board */
221 base = 0xe0000; 242 base = 0xe0000;
222 /* I don't know why we need to 243 mmapped = 1;
223 write twice */ 244 /* UP2000 drives ISA with
224 mmapped = 2;
225 /* UP2000 drives ISA with
226 8.25 MHz (PCI/4) clock 245 8.25 MHz (PCI/4) clock
227 (this can be read from cypress) */ 246 (this can be read from cypress) */
228 clock = I2C_PCF_CLK | I2C_PCF_TRNS90; 247 clock = I2C_PCF_CLK | I2C_PCF_TRNS90;
229 printk(KERN_INFO "i2c-elektor: found API UP2000 like board, will probe PCF8584 later.\n"); 248 pr_info("%s: found API UP2000 like "
249 "board, will probe PCF8584 "
250 "later\n", pcf_isa_ops.name);
230 } 251 }
231 } 252 }
232 pci_dev_put(cy693_dev); 253 pci_dev_put(cy693_dev);
@@ -236,12 +257,11 @@ static int __init i2c_pcfisa_init(void)
236 257
237 /* sanity checks for mmapped I/O */ 258 /* sanity checks for mmapped I/O */
238 if (mmapped && base < 0xc8000) { 259 if (mmapped && base < 0xc8000) {
239 printk(KERN_ERR "i2c-elektor: incorrect base address (0x%0X) specified for mmapped I/O.\n", base); 260 printk(KERN_ERR "%s: incorrect base address (%#x) specified "
261 "for mmapped I/O\n", pcf_isa_ops.name, base);
240 return -ENODEV; 262 return -ENODEV;
241 } 263 }
242 264
243 printk(KERN_INFO "i2c-elektor: i2c pcf8584-isa adapter driver\n");
244
245 if (base == 0) { 265 if (base == 0) {
246 base = DEFAULT_BASE; 266 base = DEFAULT_BASE;
247 } 267 }
@@ -251,8 +271,8 @@ static int __init i2c_pcfisa_init(void)
251 return -ENODEV; 271 return -ENODEV;
252 if (i2c_pcf_add_bus(&pcf_isa_ops) < 0) 272 if (i2c_pcf_add_bus(&pcf_isa_ops) < 0)
253 goto fail; 273 goto fail;
254 274
255 printk(KERN_ERR "i2c-elektor: found device at %#x.\n", base); 275 dev_info(&pcf_isa_ops.dev, "found device at %#x\n", base);
256 276
257 return 0; 277 return 0;
258 278
@@ -262,8 +282,13 @@ static int __init i2c_pcfisa_init(void)
262 free_irq(irq, NULL); 282 free_irq(irq, NULL);
263 } 283 }
264 284
265 if (!mmapped) 285 if (!mmapped) {
266 release_region(base , 2); 286 ioport_unmap(base_iomem);
287 release_region(base, 2);
288 } else {
289 iounmap(base_iomem);
290 release_mem_region(base, 2);
291 }
267 return -ENODEV; 292 return -ENODEV;
268} 293}
269 294
@@ -276,8 +301,13 @@ static void i2c_pcfisa_exit(void)
276 free_irq(irq, NULL); 301 free_irq(irq, NULL);
277 } 302 }
278 303
279 if (!mmapped) 304 if (!mmapped) {
280 release_region(base , 2); 305 ioport_unmap(base_iomem);
306 release_region(base, 2);
307 } else {
308 iounmap(base_iomem);
309 release_mem_region(base, 2);
310 }
281} 311}
282 312
283MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>"); 313MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
diff --git a/drivers/i2c/busses/i2c-hydra.c b/drivers/i2c/busses/i2c-hydra.c
index e0cb3b0f92fa..1b5354e24bf5 100644
--- a/drivers/i2c/busses/i2c-hydra.c
+++ b/drivers/i2c/busses/i2c-hydra.c
@@ -155,6 +155,7 @@ static void __devexit hydra_remove(struct pci_dev *dev)
155 155
156 156
157static struct pci_driver hydra_driver = { 157static struct pci_driver hydra_driver = {
158 .owner = THIS_MODULE,
158 .name = "hydra_smbus", 159 .name = "hydra_smbus",
159 .id_table = hydra_ids, 160 .id_table = hydra_ids,
160 .probe = hydra_probe, 161 .probe = hydra_probe,
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 709beab76609..4f63195069da 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -52,10 +52,6 @@
52#include <linux/i2c.h> 52#include <linux/i2c.h>
53#include <asm/io.h> 53#include <asm/io.h>
54 54
55#ifdef I2C_FUNC_SMBUS_BLOCK_DATA_PEC
56#define HAVE_PEC
57#endif
58
59/* I801 SMBus address offsets */ 55/* I801 SMBus address offsets */
60#define SMBHSTSTS (0 + i801_smba) 56#define SMBHSTSTS (0 + i801_smba)
61#define SMBHSTCNT (2 + i801_smba) 57#define SMBHSTCNT (2 + i801_smba)
@@ -106,10 +102,11 @@ MODULE_PARM_DESC(force_addr,
106 "EXTREMELY DANGEROUS!"); 102 "EXTREMELY DANGEROUS!");
107 103
108static int i801_transaction(void); 104static int i801_transaction(void);
109static int i801_block_transaction(union i2c_smbus_data *data, 105static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
110 char read_write, int command); 106 int command, int hwpec);
111 107
112static unsigned short i801_smba; 108static unsigned short i801_smba;
109static struct pci_driver i801_driver;
113static struct pci_dev *I801_dev; 110static struct pci_dev *I801_dev;
114static int isich4; 111static int isich4;
115 112
@@ -143,7 +140,7 @@ static int i801_setup(struct pci_dev *dev)
143 } 140 }
144 } 141 }
145 142
146 if (!request_region(i801_smba, (isich4 ? 16 : 8), "i801-smbus")) { 143 if (!request_region(i801_smba, (isich4 ? 16 : 8), i801_driver.name)) {
147 dev_err(&dev->dev, "I801_smb region 0x%x already in use!\n", 144 dev_err(&dev->dev, "I801_smb region 0x%x already in use!\n",
148 i801_smba); 145 i801_smba);
149 error_return = -EBUSY; 146 error_return = -EBUSY;
@@ -252,7 +249,7 @@ static int i801_transaction(void)
252 249
253/* All-inclusive block transaction function */ 250/* All-inclusive block transaction function */
254static int i801_block_transaction(union i2c_smbus_data *data, char read_write, 251static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
255 int command) 252 int command, int hwpec)
256{ 253{
257 int i, len; 254 int i, len;
258 int smbcmd; 255 int smbcmd;
@@ -391,8 +388,7 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
391 goto END; 388 goto END;
392 } 389 }
393 390
394#ifdef HAVE_PEC 391 if (hwpec) {
395 if(isich4 && command == I2C_SMBUS_BLOCK_DATA_PEC) {
396 /* wait for INTR bit as advised by Intel */ 392 /* wait for INTR bit as advised by Intel */
397 timeout = 0; 393 timeout = 0;
398 do { 394 do {
@@ -406,7 +402,6 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
406 } 402 }
407 outb_p(temp, SMBHSTSTS); 403 outb_p(temp, SMBHSTSTS);
408 } 404 }
409#endif
410 result = 0; 405 result = 0;
411END: 406END:
412 if (command == I2C_SMBUS_I2C_BLOCK_DATA) { 407 if (command == I2C_SMBUS_I2C_BLOCK_DATA) {
@@ -421,14 +416,13 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr,
421 unsigned short flags, char read_write, u8 command, 416 unsigned short flags, char read_write, u8 command,
422 int size, union i2c_smbus_data * data) 417 int size, union i2c_smbus_data * data)
423{ 418{
424 int hwpec = 0; 419 int hwpec;
425 int block = 0; 420 int block = 0;
426 int ret, xact = 0; 421 int ret, xact = 0;
427 422
428#ifdef HAVE_PEC 423 hwpec = isich4 && (flags & I2C_CLIENT_PEC)
429 if(isich4) 424 && size != I2C_SMBUS_QUICK
430 hwpec = (flags & I2C_CLIENT_PEC) != 0; 425 && size != I2C_SMBUS_I2C_BLOCK_DATA;
431#endif
432 426
433 switch (size) { 427 switch (size) {
434 case I2C_SMBUS_QUICK: 428 case I2C_SMBUS_QUICK:
@@ -463,11 +457,6 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr,
463 break; 457 break;
464 case I2C_SMBUS_BLOCK_DATA: 458 case I2C_SMBUS_BLOCK_DATA:
465 case I2C_SMBUS_I2C_BLOCK_DATA: 459 case I2C_SMBUS_I2C_BLOCK_DATA:
466#ifdef HAVE_PEC
467 case I2C_SMBUS_BLOCK_DATA_PEC:
468 if(hwpec && size == I2C_SMBUS_BLOCK_DATA)
469 size = I2C_SMBUS_BLOCK_DATA_PEC;
470#endif
471 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 460 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
472 SMBHSTADD); 461 SMBHSTADD);
473 outb_p(command, SMBHSTCMD); 462 outb_p(command, SMBHSTCMD);
@@ -479,27 +468,18 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr,
479 return -1; 468 return -1;
480 } 469 }
481 470
482#ifdef HAVE_PEC 471 if (hwpec)
483 if(isich4 && hwpec) { 472 outb_p(1, SMBAUXCTL); /* enable hardware PEC */
484 if(size != I2C_SMBUS_QUICK && 473
485 size != I2C_SMBUS_I2C_BLOCK_DATA)
486 outb_p(1, SMBAUXCTL); /* enable HW PEC */
487 }
488#endif
489 if(block) 474 if(block)
490 ret = i801_block_transaction(data, read_write, size); 475 ret = i801_block_transaction(data, read_write, size, hwpec);
491 else { 476 else {
492 outb_p(xact | ENABLE_INT9, SMBHSTCNT); 477 outb_p(xact | ENABLE_INT9, SMBHSTCNT);
493 ret = i801_transaction(); 478 ret = i801_transaction();
494 } 479 }
495 480
496#ifdef HAVE_PEC 481 if (hwpec)
497 if(isich4 && hwpec) { 482 outb_p(0, SMBAUXCTL); /* disable hardware PEC */
498 if(size != I2C_SMBUS_QUICK &&
499 size != I2C_SMBUS_I2C_BLOCK_DATA)
500 outb_p(0, SMBAUXCTL);
501 }
502#endif
503 483
504 if(block) 484 if(block)
505 return ret; 485 return ret;
@@ -526,12 +506,7 @@ static u32 i801_func(struct i2c_adapter *adapter)
526 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 506 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
527 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 507 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
528 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 508 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK
529#ifdef HAVE_PEC 509 | (isich4 ? I2C_FUNC_SMBUS_HWPEC_CALC : 0);
530 | (isich4 ? I2C_FUNC_SMBUS_BLOCK_DATA_PEC |
531 I2C_FUNC_SMBUS_HWPEC_CALC
532 : 0)
533#endif
534 ;
535} 510}
536 511
537static struct i2c_algorithm smbus_algorithm = { 512static struct i2c_algorithm smbus_algorithm = {
@@ -543,7 +518,6 @@ static struct i2c_adapter i801_adapter = {
543 .owner = THIS_MODULE, 518 .owner = THIS_MODULE,
544 .class = I2C_CLASS_HWMON, 519 .class = I2C_CLASS_HWMON,
545 .algo = &smbus_algorithm, 520 .algo = &smbus_algorithm,
546 .name = "unset",
547}; 521};
548 522
549static struct pci_device_id i801_ids[] = { 523static struct pci_device_id i801_ids[] = {
@@ -586,6 +560,7 @@ static void __devexit i801_remove(struct pci_dev *dev)
586} 560}
587 561
588static struct pci_driver i801_driver = { 562static struct pci_driver i801_driver = {
563 .owner = THIS_MODULE,
589 .name = "i801_smbus", 564 .name = "i801_smbus",
590 .id_table = i801_ids, 565 .id_table = i801_ids,
591 .probe = i801_probe, 566 .probe = i801_probe,
diff --git a/drivers/i2c/busses/i2c-i810.c b/drivers/i2c/busses/i2c-i810.c
index 0ff7016e0629..52bc30593bd7 100644
--- a/drivers/i2c/busses/i2c-i810.c
+++ b/drivers/i2c/busses/i2c-i810.c
@@ -32,6 +32,7 @@
32 i810AB 7123 32 i810AB 7123
33 i810E 7125 33 i810E 7125
34 i815 1132 34 i815 1132
35 i845G 2562
35*/ 36*/
36 37
37#include <linux/kernel.h> 38#include <linux/kernel.h>
@@ -232,6 +233,7 @@ static void __devexit i810_remove(struct pci_dev *dev)
232} 233}
233 234
234static struct pci_driver i810_driver = { 235static struct pci_driver i810_driver = {
236 .owner = THIS_MODULE,
235 .name = "i810_smbus", 237 .name = "i810_smbus",
236 .id_table = i810_ids, 238 .id_table = i810_ids,
237 .probe = i810_probe, 239 .probe = i810_probe,
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index a3ed9590f028..1a587253d716 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -672,13 +672,12 @@ static int __devinit iic_probe(struct ocp_device *ocp){
672 printk(KERN_WARNING"ibm-iic%d: missing additional data!\n", 672 printk(KERN_WARNING"ibm-iic%d: missing additional data!\n",
673 ocp->def->index); 673 ocp->def->index);
674 674
675 if (!(dev = kmalloc(sizeof(*dev), GFP_KERNEL))){ 675 if (!(dev = kzalloc(sizeof(*dev), GFP_KERNEL))) {
676 printk(KERN_CRIT "ibm-iic%d: failed to allocate device data\n", 676 printk(KERN_CRIT "ibm-iic%d: failed to allocate device data\n",
677 ocp->def->index); 677 ocp->def->index);
678 return -ENOMEM; 678 return -ENOMEM;
679 } 679 }
680 680
681 memset(dev, 0, sizeof(*dev));
682 dev->idx = ocp->def->index; 681 dev->idx = ocp->def->index;
683 ocp_set_drvdata(ocp, dev); 682 ocp_set_drvdata(ocp, dev);
684 683
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c
index 7bd9102db701..9888fae1f37a 100644
--- a/drivers/i2c/busses/i2c-iop3xx.c
+++ b/drivers/i2c/busses/i2c-iop3xx.c
@@ -43,7 +43,7 @@
43#include "i2c-iop3xx.h" 43#include "i2c-iop3xx.h"
44 44
45/* global unit counter */ 45/* global unit counter */
46static int i2c_id = 0; 46static int i2c_id;
47 47
48static inline unsigned char 48static inline unsigned char
49iic_cook_addr(struct i2c_msg *msg) 49iic_cook_addr(struct i2c_msg *msg)
@@ -440,19 +440,17 @@ iop3xx_i2c_probe(struct device *dev)
440 struct i2c_adapter *new_adapter; 440 struct i2c_adapter *new_adapter;
441 struct i2c_algo_iop3xx_data *adapter_data; 441 struct i2c_algo_iop3xx_data *adapter_data;
442 442
443 new_adapter = kmalloc(sizeof(struct i2c_adapter), GFP_KERNEL); 443 new_adapter = kzalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
444 if (!new_adapter) { 444 if (!new_adapter) {
445 ret = -ENOMEM; 445 ret = -ENOMEM;
446 goto out; 446 goto out;
447 } 447 }
448 memset((void*)new_adapter, 0, sizeof(*new_adapter));
449 448
450 adapter_data = kmalloc(sizeof(struct i2c_algo_iop3xx_data), GFP_KERNEL); 449 adapter_data = kzalloc(sizeof(struct i2c_algo_iop3xx_data), GFP_KERNEL);
451 if (!adapter_data) { 450 if (!adapter_data) {
452 ret = -ENOMEM; 451 ret = -ENOMEM;
453 goto free_adapter; 452 goto free_adapter;
454 } 453 }
455 memset((void*)adapter_data, 0, sizeof(*adapter_data));
456 454
457 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 455 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
458 if (!res) { 456 if (!res) {
@@ -525,6 +523,7 @@ out:
525 523
526 524
527static struct device_driver iop3xx_i2c_driver = { 525static struct device_driver iop3xx_i2c_driver = {
526 .owner = THIS_MODULE,
528 .name = "IOP3xx-I2C", 527 .name = "IOP3xx-I2C",
529 .bus = &platform_bus_type, 528 .bus = &platform_bus_type,
530 .probe = iop3xx_i2c_probe, 529 .probe = iop3xx_i2c_probe,
diff --git a/drivers/i2c/busses/i2c-isa.c b/drivers/i2c/busses/i2c-isa.c
index bdc6806dafae..4fdc02411609 100644
--- a/drivers/i2c/busses/i2c-isa.c
+++ b/drivers/i2c/busses/i2c-isa.c
@@ -92,6 +92,7 @@ int i2c_isa_add_driver(struct i2c_driver *driver)
92 92
93 /* Add the driver to the list of i2c drivers in the driver core */ 93 /* Add the driver to the list of i2c drivers in the driver core */
94 driver->driver.name = driver->name; 94 driver->driver.name = driver->name;
95 driver->driver.owner = driver->owner;
95 driver->driver.bus = &i2c_bus_type; 96 driver->driver.bus = &i2c_bus_type;
96 driver->driver.probe = i2c_isa_device_probe; 97 driver->driver.probe = i2c_isa_device_probe;
97 driver->driver.remove = i2c_isa_device_remove; 98 driver->driver.remove = i2c_isa_device_remove;
diff --git a/drivers/i2c/busses/i2c-ixp2000.c b/drivers/i2c/busses/i2c-ixp2000.c
index 1956af382cd8..42016ee6ef13 100644
--- a/drivers/i2c/busses/i2c-ixp2000.c
+++ b/drivers/i2c/busses/i2c-ixp2000.c
@@ -36,6 +36,8 @@
36#include <asm/hardware.h> /* Pick up IXP2000-specific bits */ 36#include <asm/hardware.h> /* Pick up IXP2000-specific bits */
37#include <asm/arch/gpio.h> 37#include <asm/arch/gpio.h>
38 38
39static struct device_driver ixp2000_i2c_driver;
40
39static inline int ixp2000_scl_pin(void *data) 41static inline int ixp2000_scl_pin(void *data)
40{ 42{
41 return ((struct ixp2000_i2c_pins*)data)->scl_pin; 43 return ((struct ixp2000_i2c_pins*)data)->scl_pin;
@@ -104,11 +106,10 @@ static int ixp2000_i2c_probe(struct device *dev)
104 struct platform_device *plat_dev = to_platform_device(dev); 106 struct platform_device *plat_dev = to_platform_device(dev);
105 struct ixp2000_i2c_pins *gpio = plat_dev->dev.platform_data; 107 struct ixp2000_i2c_pins *gpio = plat_dev->dev.platform_data;
106 struct ixp2000_i2c_data *drv_data = 108 struct ixp2000_i2c_data *drv_data =
107 kmalloc(sizeof(struct ixp2000_i2c_data), GFP_KERNEL); 109 kzalloc(sizeof(struct ixp2000_i2c_data), GFP_KERNEL);
108 110
109 if (!drv_data) 111 if (!drv_data)
110 return -ENOMEM; 112 return -ENOMEM;
111 memzero(drv_data, sizeof(*drv_data));
112 drv_data->gpio_pins = gpio; 113 drv_data->gpio_pins = gpio;
113 114
114 drv_data->algo_data.data = gpio; 115 drv_data->algo_data.data = gpio;
@@ -121,6 +122,8 @@ static int ixp2000_i2c_probe(struct device *dev)
121 drv_data->algo_data.timeout = 100; 122 drv_data->algo_data.timeout = 100;
122 123
123 drv_data->adapter.id = I2C_HW_B_IXP2000, 124 drv_data->adapter.id = I2C_HW_B_IXP2000,
125 strlcpy(drv_data->adapter.name, ixp2000_i2c_driver.name,
126 I2C_NAME_SIZE);
124 drv_data->adapter.algo_data = &drv_data->algo_data, 127 drv_data->adapter.algo_data = &drv_data->algo_data,
125 128
126 drv_data->adapter.dev.parent = &plat_dev->dev; 129 drv_data->adapter.dev.parent = &plat_dev->dev;
@@ -142,6 +145,7 @@ static int ixp2000_i2c_probe(struct device *dev)
142} 145}
143 146
144static struct device_driver ixp2000_i2c_driver = { 147static struct device_driver ixp2000_i2c_driver = {
148 .owner = THIS_MODULE,
145 .name = "IXP2000-I2C", 149 .name = "IXP2000-I2C",
146 .bus = &platform_bus_type, 150 .bus = &platform_bus_type,
147 .probe = ixp2000_i2c_probe, 151 .probe = ixp2000_i2c_probe,
diff --git a/drivers/i2c/busses/i2c-ixp4xx.c b/drivers/i2c/busses/i2c-ixp4xx.c
index f6f5ca31fdba..69303ab65e04 100644
--- a/drivers/i2c/busses/i2c-ixp4xx.c
+++ b/drivers/i2c/busses/i2c-ixp4xx.c
@@ -35,6 +35,8 @@
35 35
36#include <asm/hardware.h> /* Pick up IXP4xx-specific bits */ 36#include <asm/hardware.h> /* Pick up IXP4xx-specific bits */
37 37
38static struct device_driver ixp4xx_i2c_driver;
39
38static inline int ixp4xx_scl_pin(void *data) 40static inline int ixp4xx_scl_pin(void *data)
39{ 41{
40 return ((struct ixp4xx_i2c_pins*)data)->scl_pin; 42 return ((struct ixp4xx_i2c_pins*)data)->scl_pin;
@@ -105,12 +107,11 @@ static int ixp4xx_i2c_probe(struct device *dev)
105 struct platform_device *plat_dev = to_platform_device(dev); 107 struct platform_device *plat_dev = to_platform_device(dev);
106 struct ixp4xx_i2c_pins *gpio = plat_dev->dev.platform_data; 108 struct ixp4xx_i2c_pins *gpio = plat_dev->dev.platform_data;
107 struct ixp4xx_i2c_data *drv_data = 109 struct ixp4xx_i2c_data *drv_data =
108 kmalloc(sizeof(struct ixp4xx_i2c_data), GFP_KERNEL); 110 kzalloc(sizeof(struct ixp4xx_i2c_data), GFP_KERNEL);
109 111
110 if(!drv_data) 112 if(!drv_data)
111 return -ENOMEM; 113 return -ENOMEM;
112 114
113 memzero(drv_data, sizeof(struct ixp4xx_i2c_data));
114 drv_data->gpio_pins = gpio; 115 drv_data->gpio_pins = gpio;
115 116
116 /* 117 /*
@@ -129,6 +130,8 @@ static int ixp4xx_i2c_probe(struct device *dev)
129 drv_data->algo_data.timeout = 100; 130 drv_data->algo_data.timeout = 100;
130 131
131 drv_data->adapter.id = I2C_HW_B_IXP4XX; 132 drv_data->adapter.id = I2C_HW_B_IXP4XX;
133 strlcpy(drv_data->adapter.name, ixp4xx_i2c_driver.name,
134 I2C_NAME_SIZE);
132 drv_data->adapter.algo_data = &drv_data->algo_data; 135 drv_data->adapter.algo_data = &drv_data->algo_data;
133 136
134 drv_data->adapter.dev.parent = &plat_dev->dev; 137 drv_data->adapter.dev.parent = &plat_dev->dev;
@@ -151,6 +154,7 @@ static int ixp4xx_i2c_probe(struct device *dev)
151} 154}
152 155
153static struct device_driver ixp4xx_i2c_driver = { 156static struct device_driver ixp4xx_i2c_driver = {
157 .owner = THIS_MODULE,
154 .name = "IXP4XX-I2C", 158 .name = "IXP4XX-I2C",
155 .bus = &platform_bus_type, 159 .bus = &platform_bus_type,
156 .probe = ixp4xx_i2c_probe, 160 .probe = ixp4xx_i2c_probe,
diff --git a/drivers/i2c/busses/i2c-keywest.c b/drivers/i2c/busses/i2c-keywest.c
index eff5896ce865..d61f748278fc 100644
--- a/drivers/i2c/busses/i2c-keywest.c
+++ b/drivers/i2c/busses/i2c-keywest.c
@@ -535,13 +535,12 @@ create_iface(struct device_node *np, struct device *dev)
535 535
536 tsize = sizeof(struct keywest_iface) + 536 tsize = sizeof(struct keywest_iface) +
537 (sizeof(struct keywest_chan) + 4) * nchan; 537 (sizeof(struct keywest_chan) + 4) * nchan;
538 iface = (struct keywest_iface *) kmalloc(tsize, GFP_KERNEL); 538 iface = kzalloc(tsize, GFP_KERNEL);
539 if (iface == NULL) { 539 if (iface == NULL) {
540 printk(KERN_ERR "i2c-keywest: can't allocate inteface !\n"); 540 printk(KERN_ERR "i2c-keywest: can't allocate inteface !\n");
541 pmac_low_i2c_unlock(np); 541 pmac_low_i2c_unlock(np);
542 return -ENOMEM; 542 return -ENOMEM;
543 } 543 }
544 memset(iface, 0, tsize);
545 spin_lock_init(&iface->lock); 544 spin_lock_init(&iface->lock);
546 init_completion(&iface->complete); 545 init_completion(&iface->complete);
547 iface->node = of_node_get(np); 546 iface->node = of_node_get(np);
@@ -716,6 +715,7 @@ static struct of_device_id i2c_keywest_match[] =
716 715
717static struct macio_driver i2c_keywest_macio_driver = 716static struct macio_driver i2c_keywest_macio_driver =
718{ 717{
718 .owner = THIS_MODULE,
719 .name = "i2c-keywest", 719 .name = "i2c-keywest",
720 .match_table = i2c_keywest_match, 720 .match_table = i2c_keywest_match,
721 .probe = create_iface_macio, 721 .probe = create_iface_macio,
@@ -724,6 +724,7 @@ static struct macio_driver i2c_keywest_macio_driver =
724 724
725static struct of_platform_driver i2c_keywest_of_platform_driver = 725static struct of_platform_driver i2c_keywest_of_platform_driver =
726{ 726{
727 .owner = THIS_MODULE,
727 .name = "i2c-keywest", 728 .name = "i2c-keywest",
728 .match_table = i2c_keywest_match, 729 .match_table = i2c_keywest_match,
729 .probe = create_iface_of_platform, 730 .probe = create_iface_of_platform,
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index f065583ddcf1..8491633005b8 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -296,10 +296,9 @@ static int fsl_i2c_probe(struct device *device)
296 296
297 pdata = (struct fsl_i2c_platform_data *) pdev->dev.platform_data; 297 pdata = (struct fsl_i2c_platform_data *) pdev->dev.platform_data;
298 298
299 if (!(i2c = kmalloc(sizeof(*i2c), GFP_KERNEL))) { 299 if (!(i2c = kzalloc(sizeof(*i2c), GFP_KERNEL))) {
300 return -ENOMEM; 300 return -ENOMEM;
301 } 301 }
302 memset(i2c, 0, sizeof(*i2c));
303 302
304 i2c->irq = platform_get_irq(pdev, 0); 303 i2c->irq = platform_get_irq(pdev, 0);
305 i2c->flags = pdata->device_flags; 304 i2c->flags = pdata->device_flags;
@@ -361,6 +360,7 @@ static int fsl_i2c_remove(struct device *device)
361 360
362/* Structure for a device driver */ 361/* Structure for a device driver */
363static struct device_driver fsl_i2c_driver = { 362static struct device_driver fsl_i2c_driver = {
363 .owner = THIS_MODULE,
364 .name = "fsl-i2c", 364 .name = "fsl-i2c",
365 .bus = &platform_bus_type, 365 .bus = &platform_bus_type,
366 .probe = fsl_i2c_probe, 366 .probe = fsl_i2c_probe,
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index 99abca45fece..d0d2a6f1386e 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -500,13 +500,10 @@ mv64xxx_i2c_probe(struct device *dev)
500 if ((pd->id != 0) || !pdata) 500 if ((pd->id != 0) || !pdata)
501 return -ENODEV; 501 return -ENODEV;
502 502
503 drv_data = kmalloc(sizeof(struct mv64xxx_i2c_data), GFP_KERNEL); 503 drv_data = kzalloc(sizeof(struct mv64xxx_i2c_data), GFP_KERNEL);
504
505 if (!drv_data) 504 if (!drv_data)
506 return -ENOMEM; 505 return -ENOMEM;
507 506
508 memset(drv_data, 0, sizeof(struct mv64xxx_i2c_data));
509
510 if (mv64xxx_i2c_map_regs(pd, drv_data)) { 507 if (mv64xxx_i2c_map_regs(pd, drv_data)) {
511 rc = -ENODEV; 508 rc = -ENODEV;
512 goto exit_kfree; 509 goto exit_kfree;
@@ -570,6 +567,7 @@ mv64xxx_i2c_remove(struct device *dev)
570} 567}
571 568
572static struct device_driver mv64xxx_i2c_driver = { 569static struct device_driver mv64xxx_i2c_driver = {
570 .owner = THIS_MODULE,
573 .name = MV64XXX_I2C_CTLR_NAME, 571 .name = MV64XXX_I2C_CTLR_NAME,
574 .bus = &platform_bus_type, 572 .bus = &platform_bus_type,
575 .probe = mv64xxx_i2c_probe, 573 .probe = mv64xxx_i2c_probe,
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c
index fe9c0f42a2b7..fd26036e68a3 100644
--- a/drivers/i2c/busses/i2c-nforce2.c
+++ b/drivers/i2c/busses/i2c-nforce2.c
@@ -97,6 +97,7 @@ struct nforce2_smbus {
97#define NVIDIA_SMB_PRTCL_I2C_BLOCK_DATA 0x4a 97#define NVIDIA_SMB_PRTCL_I2C_BLOCK_DATA 0x4a
98#define NVIDIA_SMB_PRTCL_PEC 0x80 98#define NVIDIA_SMB_PRTCL_PEC 0x80
99 99
100static struct pci_driver nforce2_driver;
100 101
101static s32 nforce2_access(struct i2c_adapter *adap, u16 addr, 102static s32 nforce2_access(struct i2c_adapter *adap, u16 addr,
102 unsigned short flags, char read_write, 103 unsigned short flags, char read_write,
@@ -113,7 +114,6 @@ static struct i2c_adapter nforce2_adapter = {
113 .owner = THIS_MODULE, 114 .owner = THIS_MODULE,
114 .class = I2C_CLASS_HWMON, 115 .class = I2C_CLASS_HWMON,
115 .algo = &smbus_algorithm, 116 .algo = &smbus_algorithm,
116 .name = "unset",
117}; 117};
118 118
119/* Return -1 on error. See smbus.h for more information */ 119/* Return -1 on error. See smbus.h for more information */
@@ -188,13 +188,6 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
188 dev_err(&adap->dev, "I2C_SMBUS_BLOCK_PROC_CALL not supported!\n"); 188 dev_err(&adap->dev, "I2C_SMBUS_BLOCK_PROC_CALL not supported!\n");
189 return -1; 189 return -1;
190 190
191 case I2C_SMBUS_WORD_DATA_PEC:
192 case I2C_SMBUS_BLOCK_DATA_PEC:
193 case I2C_SMBUS_PROC_CALL_PEC:
194 case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
195 dev_err(&adap->dev, "Unexpected software PEC transaction %d\n.", size);
196 return -1;
197
198 default: 191 default:
199 dev_err(&adap->dev, "Unsupported transaction %d\n", size); 192 dev_err(&adap->dev, "Unsupported transaction %d\n", size);
200 return -1; 193 return -1;
@@ -285,7 +278,7 @@ static int __devinit nforce2_probe_smb (struct pci_dev *dev, int reg,
285 smbus->base = iobase & 0xfffc; 278 smbus->base = iobase & 0xfffc;
286 smbus->size = 8; 279 smbus->size = 8;
287 280
288 if (!request_region(smbus->base, smbus->size, "nForce2 SMBus")) { 281 if (!request_region(smbus->base, smbus->size, nforce2_driver.name)) {
289 dev_err(&smbus->adapter.dev, "Error requesting region %02x .. %02X for %s\n", 282 dev_err(&smbus->adapter.dev, "Error requesting region %02x .. %02X for %s\n",
290 smbus->base, smbus->base+smbus->size-1, name); 283 smbus->base, smbus->base+smbus->size-1, name);
291 return -1; 284 return -1;
@@ -313,10 +306,8 @@ static int __devinit nforce2_probe(struct pci_dev *dev, const struct pci_device_
313 int res1, res2; 306 int res1, res2;
314 307
315 /* we support 2 SMBus adapters */ 308 /* we support 2 SMBus adapters */
316 if (!(smbuses = (void *)kmalloc(2*sizeof(struct nforce2_smbus), 309 if (!(smbuses = kzalloc(2*sizeof(struct nforce2_smbus), GFP_KERNEL)))
317 GFP_KERNEL)))
318 return -ENOMEM; 310 return -ENOMEM;
319 memset (smbuses, 0, 2*sizeof(struct nforce2_smbus));
320 pci_set_drvdata(dev, smbuses); 311 pci_set_drvdata(dev, smbuses);
321 312
322 /* SMBus adapter 1 */ 313 /* SMBus adapter 1 */
@@ -356,6 +347,7 @@ static void __devexit nforce2_remove(struct pci_dev *dev)
356} 347}
357 348
358static struct pci_driver nforce2_driver = { 349static struct pci_driver nforce2_driver = {
350 .owner = THIS_MODULE,
359 .name = "nForce2_smbus", 351 .name = "nForce2_smbus",
360 .id_table = nforce2_ids, 352 .id_table = nforce2_ids,
361 .probe = nforce2_probe, 353 .probe = nforce2_probe,
diff --git a/drivers/i2c/busses/i2c-parport.c b/drivers/i2c/busses/i2c-parport.c
index 71a2502fe069..2854d858fc9b 100644
--- a/drivers/i2c/busses/i2c-parport.c
+++ b/drivers/i2c/busses/i2c-parport.c
@@ -155,12 +155,11 @@ static void i2c_parport_attach (struct parport *port)
155{ 155{
156 struct i2c_par *adapter; 156 struct i2c_par *adapter;
157 157
158 adapter = kmalloc(sizeof(struct i2c_par), GFP_KERNEL); 158 adapter = kzalloc(sizeof(struct i2c_par), GFP_KERNEL);
159 if (adapter == NULL) { 159 if (adapter == NULL) {
160 printk(KERN_ERR "i2c-parport: Failed to kmalloc\n"); 160 printk(KERN_ERR "i2c-parport: Failed to kzalloc\n");
161 return; 161 return;
162 } 162 }
163 memset(adapter, 0x00, sizeof(struct i2c_par));
164 163
165 pr_debug("i2c-parport: attaching to %s\n", port->name); 164 pr_debug("i2c-parport: attaching to %s\n", port->name);
166 adapter->pdev = parport_register_device(port, "i2c-parport", 165 adapter->pdev = parport_register_device(port, "i2c-parport",
@@ -232,7 +231,7 @@ static void i2c_parport_detach (struct parport *port)
232 } 231 }
233} 232}
234 233
235static struct parport_driver i2c_driver = { 234static struct parport_driver i2c_parport_driver = {
236 .name = "i2c-parport", 235 .name = "i2c-parport",
237 .attach = i2c_parport_attach, 236 .attach = i2c_parport_attach,
238 .detach = i2c_parport_detach, 237 .detach = i2c_parport_detach,
@@ -250,12 +249,12 @@ static int __init i2c_parport_init(void)
250 type = 0; 249 type = 0;
251 } 250 }
252 251
253 return parport_register_driver(&i2c_driver); 252 return parport_register_driver(&i2c_parport_driver);
254} 253}
255 254
256static void __exit i2c_parport_exit(void) 255static void __exit i2c_parport_exit(void)
257{ 256{
258 parport_unregister_driver(&i2c_driver); 257 parport_unregister_driver(&i2c_parport_driver);
259} 258}
260 259
261MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); 260MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 6d48a4da7bed..7d63eec423fe 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -90,13 +90,13 @@ struct sd {
90 90
91/* If force is set to anything different from 0, we forcibly enable the 91/* If force is set to anything different from 0, we forcibly enable the
92 PIIX4. DANGEROUS! */ 92 PIIX4. DANGEROUS! */
93static int force = 0; 93static int force;
94module_param (force, int, 0); 94module_param (force, int, 0);
95MODULE_PARM_DESC(force, "Forcibly enable the PIIX4. DANGEROUS!"); 95MODULE_PARM_DESC(force, "Forcibly enable the PIIX4. DANGEROUS!");
96 96
97/* If force_addr is set to anything different from 0, we forcibly enable 97/* If force_addr is set to anything different from 0, we forcibly enable
98 the PIIX4 at the given address. VERY DANGEROUS! */ 98 the PIIX4 at the given address. VERY DANGEROUS! */
99static int force_addr = 0; 99static int force_addr;
100module_param (force_addr, int, 0); 100module_param (force_addr, int, 0);
101MODULE_PARM_DESC(force_addr, 101MODULE_PARM_DESC(force_addr,
102 "Forcibly enable the PIIX4 at the given address. " 102 "Forcibly enable the PIIX4 at the given address. "
@@ -104,14 +104,15 @@ MODULE_PARM_DESC(force_addr,
104 104
105/* If fix_hstcfg is set to anything different from 0, we reset one of the 105/* If fix_hstcfg is set to anything different from 0, we reset one of the
106 registers to be a valid value. */ 106 registers to be a valid value. */
107static int fix_hstcfg = 0; 107static int fix_hstcfg;
108module_param (fix_hstcfg, int, 0); 108module_param (fix_hstcfg, int, 0);
109MODULE_PARM_DESC(fix_hstcfg, 109MODULE_PARM_DESC(fix_hstcfg,
110 "Fix config register. Needed on some boards (Force CPCI735)."); 110 "Fix config register. Needed on some boards (Force CPCI735).");
111 111
112static int piix4_transaction(void); 112static int piix4_transaction(void);
113 113
114static unsigned short piix4_smba = 0; 114static unsigned short piix4_smba;
115static struct pci_driver piix4_driver;
115static struct i2c_adapter piix4_adapter; 116static struct i2c_adapter piix4_adapter;
116 117
117static struct dmi_system_id __devinitdata piix4_dmi_table[] = { 118static struct dmi_system_id __devinitdata piix4_dmi_table[] = {
@@ -157,7 +158,7 @@ static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
157 } 158 }
158 } 159 }
159 160
160 if (!request_region(piix4_smba, SMBIOSIZE, "piix4-smbus")) { 161 if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) {
161 dev_err(&PIIX4_dev->dev, "SMB region 0x%x already in use!\n", 162 dev_err(&PIIX4_dev->dev, "SMB region 0x%x already in use!\n",
162 piix4_smba); 163 piix4_smba);
163 return -ENODEV; 164 return -ENODEV;
@@ -407,7 +408,6 @@ static struct i2c_adapter piix4_adapter = {
407 .owner = THIS_MODULE, 408 .owner = THIS_MODULE,
408 .class = I2C_CLASS_HWMON, 409 .class = I2C_CLASS_HWMON,
409 .algo = &smbus_algorithm, 410 .algo = &smbus_algorithm,
410 .name = "unset",
411}; 411};
412 412
413static struct pci_device_id piix4_ids[] = { 413static struct pci_device_id piix4_ids[] = {
@@ -462,6 +462,7 @@ static void __devexit piix4_remove(struct pci_dev *dev)
462} 462}
463 463
464static struct pci_driver piix4_driver = { 464static struct pci_driver piix4_driver = {
465 .owner = THIS_MODULE,
465 .name = "piix4_smbus", 466 .name = "piix4_smbus",
466 .id_table = piix4_ids, 467 .id_table = piix4_ids,
467 .probe = piix4_probe, 468 .probe = piix4_probe,
diff --git a/drivers/i2c/busses/i2c-pmac-smu.c b/drivers/i2c/busses/i2c-pmac-smu.c
index 8a9f5648a23d..bfefe7f7a53d 100644
--- a/drivers/i2c/busses/i2c-pmac-smu.c
+++ b/drivers/i2c/busses/i2c-pmac-smu.c
@@ -211,12 +211,11 @@ static int create_iface(struct device_node *np, struct device *dev)
211 } 211 }
212 busid = *reg; 212 busid = *reg;
213 213
214 iface = kmalloc(sizeof(struct smu_iface), GFP_KERNEL); 214 iface = kzalloc(sizeof(struct smu_iface), GFP_KERNEL);
215 if (iface == NULL) { 215 if (iface == NULL) {
216 printk(KERN_ERR "i2c-pmac-smu: can't allocate inteface !\n"); 216 printk(KERN_ERR "i2c-pmac-smu: can't allocate inteface !\n");
217 return -ENOMEM; 217 return -ENOMEM;
218 } 218 }
219 memset(iface, 0, sizeof(struct smu_iface));
220 init_completion(&iface->complete); 219 init_completion(&iface->complete);
221 iface->busid = busid; 220 iface->busid = busid;
222 221
diff --git a/drivers/i2c/busses/i2c-prosavage.c b/drivers/i2c/busses/i2c-prosavage.c
index 83fd16d61ce5..42cb1d8ca659 100644
--- a/drivers/i2c/busses/i2c-prosavage.c
+++ b/drivers/i2c/busses/i2c-prosavage.c
@@ -83,11 +83,6 @@ struct s_i2c_chip {
83/* 83/*
84 * i2c configuration 84 * i2c configuration
85 */ 85 */
86#ifndef I2C_HW_B_S3VIA
87#define I2C_HW_B_S3VIA 0x18 /* S3VIA ProSavage adapter */
88#endif
89
90/* delays */
91#define CYCLE_DELAY 10 86#define CYCLE_DELAY 10
92#define TIMEOUT (HZ / 2) 87#define TIMEOUT (HZ / 2)
93 88
@@ -241,14 +236,12 @@ static int __devinit prosavage_probe(struct pci_dev *dev, const struct pci_devic
241 struct s_i2c_chip *chip; 236 struct s_i2c_chip *chip;
242 struct s_i2c_bus *bus; 237 struct s_i2c_bus *bus;
243 238
244 pci_set_drvdata(dev, kmalloc(sizeof(struct s_i2c_chip), GFP_KERNEL)); 239 pci_set_drvdata(dev, kzalloc(sizeof(struct s_i2c_chip), GFP_KERNEL));
245 chip = (struct s_i2c_chip *)pci_get_drvdata(dev); 240 chip = (struct s_i2c_chip *)pci_get_drvdata(dev);
246 if (chip == NULL) { 241 if (chip == NULL) {
247 return -ENOMEM; 242 return -ENOMEM;
248 } 243 }
249 244
250 memset(chip, 0, sizeof(struct s_i2c_chip));
251
252 base = dev->resource[0].start & PCI_BASE_ADDRESS_MEM_MASK; 245 base = dev->resource[0].start & PCI_BASE_ADDRESS_MEM_MASK;
253 len = dev->resource[0].end - base + 1; 246 len = dev->resource[0].end - base + 1;
254 chip->mmio = ioremap_nocache(base, len); 247 chip->mmio = ioremap_nocache(base, len);
@@ -308,6 +301,7 @@ static struct pci_device_id prosavage_pci_tbl[] = {
308MODULE_DEVICE_TABLE (pci, prosavage_pci_tbl); 301MODULE_DEVICE_TABLE (pci, prosavage_pci_tbl);
309 302
310static struct pci_driver prosavage_driver = { 303static struct pci_driver prosavage_driver = {
304 .owner = THIS_MODULE,
311 .name = "prosavage_smbus", 305 .name = "prosavage_smbus",
312 .id_table = prosavage_pci_tbl, 306 .id_table = prosavage_pci_tbl,
313 .probe = prosavage_probe, 307 .probe = prosavage_probe,
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 73a092fb0e7e..6ced28e90070 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -879,14 +879,12 @@ static int s3c24xx_i2c_remove(struct device *dev)
879} 879}
880 880
881#ifdef CONFIG_PM 881#ifdef CONFIG_PM
882static int s3c24xx_i2c_resume(struct device *dev, u32 level) 882static int s3c24xx_i2c_resume(struct device *dev)
883{ 883{
884 struct s3c24xx_i2c *i2c = dev_get_drvdata(dev); 884 struct s3c24xx_i2c *i2c = dev_get_drvdata(dev);
885 885
886 if (i2c != NULL && level == RESUME_ENABLE) { 886 if (i2c != NULL)
887 dev_dbg(dev, "resume: level %d\n", level);
888 s3c24xx_i2c_init(i2c); 887 s3c24xx_i2c_init(i2c);
889 }
890 888
891 return 0; 889 return 0;
892} 890}
@@ -898,6 +896,7 @@ static int s3c24xx_i2c_resume(struct device *dev, u32 level)
898/* device driver for platform bus bits */ 896/* device driver for platform bus bits */
899 897
900static struct device_driver s3c2410_i2c_driver = { 898static struct device_driver s3c2410_i2c_driver = {
899 .owner = THIS_MODULE,
901 .name = "s3c2410-i2c", 900 .name = "s3c2410-i2c",
902 .bus = &platform_bus_type, 901 .bus = &platform_bus_type,
903 .probe = s3c24xx_i2c_probe, 902 .probe = s3c24xx_i2c_probe,
@@ -906,6 +905,7 @@ static struct device_driver s3c2410_i2c_driver = {
906}; 905};
907 906
908static struct device_driver s3c2440_i2c_driver = { 907static struct device_driver s3c2440_i2c_driver = {
908 .owner = THIS_MODULE,
909 .name = "s3c2440-i2c", 909 .name = "s3c2440-i2c",
910 .bus = &platform_bus_type, 910 .bus = &platform_bus_type,
911 .probe = s3c24xx_i2c_probe, 911 .probe = s3c24xx_i2c_probe,
diff --git a/drivers/i2c/busses/i2c-savage4.c b/drivers/i2c/busses/i2c-savage4.c
index 0c8518298e4d..aebe87ba4033 100644
--- a/drivers/i2c/busses/i2c-savage4.c
+++ b/drivers/i2c/busses/i2c-savage4.c
@@ -179,6 +179,7 @@ static void __devexit savage4_remove(struct pci_dev *dev)
179} 179}
180 180
181static struct pci_driver savage4_driver = { 181static struct pci_driver savage4_driver = {
182 .owner = THIS_MODULE,
182 .name = "savage4_smbus", 183 .name = "savage4_smbus",
183 .id_table = savage4_ids, 184 .id_table = savage4_ids,
184 .probe = savage4_probe, 185 .probe = savage4_probe,
diff --git a/drivers/i2c/busses/i2c-sis5595.c b/drivers/i2c/busses/i2c-sis5595.c
index 080318d6f54b..3ad27c3ba15b 100644
--- a/drivers/i2c/busses/i2c-sis5595.c
+++ b/drivers/i2c/busses/i2c-sis5595.c
@@ -123,11 +123,12 @@ static int blacklist[] = {
123 123
124/* If force_addr is set to anything different from 0, we forcibly enable 124/* If force_addr is set to anything different from 0, we forcibly enable
125 the device at the given address. */ 125 the device at the given address. */
126static u16 force_addr = 0; 126static u16 force_addr;
127module_param(force_addr, ushort, 0); 127module_param(force_addr, ushort, 0);
128MODULE_PARM_DESC(force_addr, "Initialize the base address of the i2c controller"); 128MODULE_PARM_DESC(force_addr, "Initialize the base address of the i2c controller");
129 129
130static unsigned short sis5595_base = 0; 130static struct pci_driver sis5595_driver;
131static unsigned short sis5595_base;
131 132
132static u8 sis5595_read(u8 reg) 133static u8 sis5595_read(u8 reg)
133{ 134{
@@ -172,7 +173,8 @@ static int sis5595_setup(struct pci_dev *SIS5595_dev)
172 173
173 /* NB: We grab just the two SMBus registers here, but this may still 174 /* NB: We grab just the two SMBus registers here, but this may still
174 * interfere with ACPI :-( */ 175 * interfere with ACPI :-( */
175 if (!request_region(sis5595_base + SMB_INDEX, 2, "sis5595-smbus")) { 176 if (!request_region(sis5595_base + SMB_INDEX, 2,
177 sis5595_driver.name)) {
176 dev_err(&SIS5595_dev->dev, "SMBus registers 0x%04x-0x%04x already in use!\n", 178 dev_err(&SIS5595_dev->dev, "SMBus registers 0x%04x-0x%04x already in use!\n",
177 sis5595_base + SMB_INDEX, sis5595_base + SMB_INDEX + 1); 179 sis5595_base + SMB_INDEX, sis5595_base + SMB_INDEX + 1);
178 return -ENODEV; 180 return -ENODEV;
@@ -364,7 +366,6 @@ static struct i2c_algorithm smbus_algorithm = {
364static struct i2c_adapter sis5595_adapter = { 366static struct i2c_adapter sis5595_adapter = {
365 .owner = THIS_MODULE, 367 .owner = THIS_MODULE,
366 .class = I2C_CLASS_HWMON, 368 .class = I2C_CLASS_HWMON,
367 .name = "unset",
368 .algo = &smbus_algorithm, 369 .algo = &smbus_algorithm,
369}; 370};
370 371
@@ -397,6 +398,7 @@ static void __devexit sis5595_remove(struct pci_dev *dev)
397} 398}
398 399
399static struct pci_driver sis5595_driver = { 400static struct pci_driver sis5595_driver = {
401 .owner = THIS_MODULE,
400 .name = "sis5595_smbus", 402 .name = "sis5595_smbus",
401 .id_table = sis5595_ids, 403 .id_table = sis5595_ids,
402 .probe = sis5595_probe, 404 .probe = sis5595_probe,
diff --git a/drivers/i2c/busses/i2c-sis630.c b/drivers/i2c/busses/i2c-sis630.c
index 86f0f448fa0b..7f49e5fd3ff0 100644
--- a/drivers/i2c/busses/i2c-sis630.c
+++ b/drivers/i2c/busses/i2c-sis630.c
@@ -92,6 +92,8 @@
92#define SIS630_PCALL 0x04 92#define SIS630_PCALL 0x04
93#define SIS630_BLOCK_DATA 0x05 93#define SIS630_BLOCK_DATA 0x05
94 94
95static struct pci_driver sis630_driver;
96
95/* insmod parameters */ 97/* insmod parameters */
96static int high_clock; 98static int high_clock;
97static int force; 99static int force;
@@ -101,7 +103,7 @@ module_param(force, bool, 0);
101MODULE_PARM_DESC(force, "Forcibly enable the SIS630. DANGEROUS!"); 103MODULE_PARM_DESC(force, "Forcibly enable the SIS630. DANGEROUS!");
102 104
103/* acpi base address */ 105/* acpi base address */
104static unsigned short acpi_base = 0; 106static unsigned short acpi_base;
105 107
106/* supported chips */ 108/* supported chips */
107static int supported[] = { 109static int supported[] = {
@@ -432,7 +434,8 @@ static int sis630_setup(struct pci_dev *sis630_dev)
432 dev_dbg(&sis630_dev->dev, "ACPI base at 0x%04x\n", acpi_base); 434 dev_dbg(&sis630_dev->dev, "ACPI base at 0x%04x\n", acpi_base);
433 435
434 /* Everything is happy, let's grab the memory and set things up. */ 436 /* Everything is happy, let's grab the memory and set things up. */
435 if (!request_region(acpi_base + SMB_STS, SIS630_SMB_IOREGION, "sis630-smbus")) { 437 if (!request_region(acpi_base + SMB_STS, SIS630_SMB_IOREGION,
438 sis630_driver.name)) {
436 dev_err(&sis630_dev->dev, "SMBus registers 0x%04x-0x%04x already " 439 dev_err(&sis630_dev->dev, "SMBus registers 0x%04x-0x%04x already "
437 "in use!\n", acpi_base + SMB_STS, acpi_base + SMB_SAA); 440 "in use!\n", acpi_base + SMB_STS, acpi_base + SMB_SAA);
438 goto exit; 441 goto exit;
@@ -455,7 +458,6 @@ static struct i2c_algorithm smbus_algorithm = {
455static struct i2c_adapter sis630_adapter = { 458static struct i2c_adapter sis630_adapter = {
456 .owner = THIS_MODULE, 459 .owner = THIS_MODULE,
457 .class = I2C_CLASS_HWMON, 460 .class = I2C_CLASS_HWMON,
458 .name = "unset",
459 .algo = &smbus_algorithm, 461 .algo = &smbus_algorithm,
460}; 462};
461 463
@@ -494,6 +496,7 @@ static void __devexit sis630_remove(struct pci_dev *dev)
494 496
495 497
496static struct pci_driver sis630_driver = { 498static struct pci_driver sis630_driver = {
499 .owner = THIS_MODULE,
497 .name = "sis630_smbus", 500 .name = "sis630_smbus",
498 .id_table = sis630_ids, 501 .id_table = sis630_ids,
499 .probe = sis630_probe, 502 .probe = sis630_probe,
diff --git a/drivers/i2c/busses/i2c-sis96x.c b/drivers/i2c/busses/i2c-sis96x.c
index ead2ff3cf60e..6a134c091324 100644
--- a/drivers/i2c/busses/i2c-sis96x.c
+++ b/drivers/i2c/busses/i2c-sis96x.c
@@ -82,8 +82,9 @@
82#define SIS96x_PROC_CALL 0x04 82#define SIS96x_PROC_CALL 0x04
83#define SIS96x_BLOCK_DATA 0x05 83#define SIS96x_BLOCK_DATA 0x05
84 84
85static struct pci_driver sis96x_driver;
85static struct i2c_adapter sis96x_adapter; 86static struct i2c_adapter sis96x_adapter;
86static u16 sis96x_smbus_base = 0; 87static u16 sis96x_smbus_base;
87 88
88static inline u8 sis96x_read(u8 reg) 89static inline u8 sis96x_read(u8 reg)
89{ 90{
@@ -257,7 +258,6 @@ static struct i2c_adapter sis96x_adapter = {
257 .owner = THIS_MODULE, 258 .owner = THIS_MODULE,
258 .class = I2C_CLASS_HWMON, 259 .class = I2C_CLASS_HWMON,
259 .algo = &smbus_algorithm, 260 .algo = &smbus_algorithm,
260 .name = "unset",
261}; 261};
262 262
263static struct pci_device_id sis96x_ids[] = { 263static struct pci_device_id sis96x_ids[] = {
@@ -294,7 +294,8 @@ static int __devinit sis96x_probe(struct pci_dev *dev,
294 sis96x_smbus_base); 294 sis96x_smbus_base);
295 295
296 /* Everything is happy, let's grab the memory and set things up. */ 296 /* Everything is happy, let's grab the memory and set things up. */
297 if (!request_region(sis96x_smbus_base, SMB_IOSIZE, "sis96x-smbus")) { 297 if (!request_region(sis96x_smbus_base, SMB_IOSIZE,
298 sis96x_driver.name)) {
298 dev_err(&dev->dev, "SMBus registers 0x%04x-0x%04x " 299 dev_err(&dev->dev, "SMBus registers 0x%04x-0x%04x "
299 "already in use!\n", sis96x_smbus_base, 300 "already in use!\n", sis96x_smbus_base,
300 sis96x_smbus_base + SMB_IOSIZE - 1); 301 sis96x_smbus_base + SMB_IOSIZE - 1);
@@ -328,6 +329,7 @@ static void __devexit sis96x_remove(struct pci_dev *dev)
328} 329}
329 330
330static struct pci_driver sis96x_driver = { 331static struct pci_driver sis96x_driver = {
332 .owner = THIS_MODULE,
331 .name = "sis96x_smbus", 333 .name = "sis96x_smbus",
332 .id_table = sis96x_ids, 334 .id_table = sis96x_ids,
333 .probe = sis96x_probe, 335 .probe = sis96x_probe,
diff --git a/drivers/i2c/busses/i2c-via.c b/drivers/i2c/busses/i2c-via.c
index 040b8abeabba..544a38e64394 100644
--- a/drivers/i2c/busses/i2c-via.c
+++ b/drivers/i2c/busses/i2c-via.c
@@ -43,9 +43,9 @@
43 43
44/* io-region reservation */ 44/* io-region reservation */
45#define IOSPACE 0x06 45#define IOSPACE 0x06
46#define IOTEXT "via-i2c"
47 46
48static u16 pm_io_base = 0; 47static struct pci_driver vt586b_driver;
48static u16 pm_io_base;
49 49
50/* 50/*
51 It does not appear from the datasheet that the GPIO pins are 51 It does not appear from the datasheet that the GPIO pins are
@@ -130,7 +130,7 @@ static int __devinit vt586b_probe(struct pci_dev *dev, const struct pci_device_i
130 pci_read_config_word(dev, base, &pm_io_base); 130 pci_read_config_word(dev, base, &pm_io_base);
131 pm_io_base &= (0xff << 8); 131 pm_io_base &= (0xff << 8);
132 132
133 if (!request_region(I2C_DIR, IOSPACE, IOTEXT)) { 133 if (!request_region(I2C_DIR, IOSPACE, vt586b_driver.name)) {
134 dev_err(&dev->dev, "IO 0x%x-0x%x already in use\n", I2C_DIR, I2C_DIR + IOSPACE); 134 dev_err(&dev->dev, "IO 0x%x-0x%x already in use\n", I2C_DIR, I2C_DIR + IOSPACE);
135 return -ENODEV; 135 return -ENODEV;
136 } 136 }
@@ -159,6 +159,7 @@ static void __devexit vt586b_remove(struct pci_dev *dev)
159 159
160 160
161static struct pci_driver vt586b_driver = { 161static struct pci_driver vt586b_driver = {
162 .owner = THIS_MODULE,
162 .name = "vt586b_smbus", 163 .name = "vt586b_smbus",
163 .id_table = vt586b_ids, 164 .id_table = vt586b_ids,
164 .probe = vt586b_probe, 165 .probe = vt586b_probe,
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c
index 99d209e0485a..c9366b504833 100644
--- a/drivers/i2c/busses/i2c-viapro.c
+++ b/drivers/i2c/busses/i2c-viapro.c
@@ -1,9 +1,10 @@
1/* 1/*
2 i2c-viapro.c - Part of lm_sensors, Linux kernel modules for hardware 2 i2c-viapro.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 monitoring
4 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>, 4 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>,
5 Philip Edelbrock <phil@netroedge.com>, Kyösti Mälkki <kmalkki@cc.hut.fi>, 5 Philip Edelbrock <phil@netroedge.com>, Kyösti Mälkki <kmalkki@cc.hut.fi>,
6 Mark D. Studebaker <mdsxyz123@yahoo.com> 6 Mark D. Studebaker <mdsxyz123@yahoo.com>
7 Copyright (C) 2005 Jean Delvare <khali@linux-fr.org>
7 8
8 This program is free software; you can redistribute it and/or modify 9 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
@@ -21,15 +22,19 @@
21*/ 22*/
22 23
23/* 24/*
24 Supports Via devices: 25 Supports the following VIA south bridges:
25 82C596A/B (0x3050) 26
26 82C596B (0x3051) 27 Chip name PCI ID REV I2C block
27 82C686A/B 28 VT82C596A 0x3050 no
28 8231 29 VT82C596B 0x3051 no
29 8233 30 VT82C686A 0x3057 0x30 no
30 8233A (0x3147 and 0x3177) 31 VT82C686B 0x3057 0x40 yes
31 8235 32 VT8231 0x8235 no?
32 8237 33 VT8233 0x3074 yes
34 VT8233A 0x3147 yes?
35 VT8235 0x3177 yes
36 VT8237R 0x3227 yes
37
33 Note: we assume there can only be one device, with one SMBus interface. 38 Note: we assume there can only be one device, with one SMBus interface.
34*/ 39*/
35 40
@@ -38,7 +43,6 @@
38#include <linux/pci.h> 43#include <linux/pci.h>
39#include <linux/kernel.h> 44#include <linux/kernel.h>
40#include <linux/stddef.h> 45#include <linux/stddef.h>
41#include <linux/sched.h>
42#include <linux/ioport.h> 46#include <linux/ioport.h>
43#include <linux/i2c.h> 47#include <linux/i2c.h>
44#include <linux/init.h> 48#include <linux/init.h>
@@ -46,48 +50,37 @@
46 50
47static struct pci_dev *vt596_pdev; 51static struct pci_dev *vt596_pdev;
48 52
49#define SMBBA1 0x90 53#define SMBBA1 0x90
50#define SMBBA2 0x80 54#define SMBBA2 0x80
51#define SMBBA3 0xD0 55#define SMBBA3 0xD0
52 56
53/* SMBus address offsets */ 57/* SMBus address offsets */
54static unsigned short vt596_smba; 58static unsigned short vt596_smba;
55#define SMBHSTSTS (vt596_smba + 0) 59#define SMBHSTSTS (vt596_smba + 0)
56#define SMBHSLVSTS (vt596_smba + 1)
57#define SMBHSTCNT (vt596_smba + 2) 60#define SMBHSTCNT (vt596_smba + 2)
58#define SMBHSTCMD (vt596_smba + 3) 61#define SMBHSTCMD (vt596_smba + 3)
59#define SMBHSTADD (vt596_smba + 4) 62#define SMBHSTADD (vt596_smba + 4)
60#define SMBHSTDAT0 (vt596_smba + 5) 63#define SMBHSTDAT0 (vt596_smba + 5)
61#define SMBHSTDAT1 (vt596_smba + 6) 64#define SMBHSTDAT1 (vt596_smba + 6)
62#define SMBBLKDAT (vt596_smba + 7) 65#define SMBBLKDAT (vt596_smba + 7)
63#define SMBSLVCNT (vt596_smba + 8)
64#define SMBSHDWCMD (vt596_smba + 9)
65#define SMBSLVEVT (vt596_smba + 0xA)
66#define SMBSLVDAT (vt596_smba + 0xC)
67 66
68/* PCI Address Constants */ 67/* PCI Address Constants */
69 68
70/* SMBus data in configuration space can be found in two places, 69/* SMBus data in configuration space can be found in two places,
71 We try to select the better one*/ 70 We try to select the better one */
72
73static unsigned short smb_cf_hstcfg = 0xD2;
74 71
75#define SMBHSTCFG (smb_cf_hstcfg) 72static unsigned short SMBHSTCFG = 0xD2;
76#define SMBSLVC (smb_cf_hstcfg + 1)
77#define SMBSHDW1 (smb_cf_hstcfg + 2)
78#define SMBSHDW2 (smb_cf_hstcfg + 3)
79#define SMBREV (smb_cf_hstcfg + 4)
80 73
81/* Other settings */ 74/* Other settings */
82#define MAX_TIMEOUT 500 75#define MAX_TIMEOUT 500
83#define ENABLE_INT9 0
84 76
85/* VT82C596 constants */ 77/* VT82C596 constants */
86#define VT596_QUICK 0x00 78#define VT596_QUICK 0x00
87#define VT596_BYTE 0x04 79#define VT596_BYTE 0x04
88#define VT596_BYTE_DATA 0x08 80#define VT596_BYTE_DATA 0x08
89#define VT596_WORD_DATA 0x0C 81#define VT596_WORD_DATA 0x0C
90#define VT596_BLOCK_DATA 0x14 82#define VT596_BLOCK_DATA 0x14
83#define VT596_I2C_BLOCK_DATA 0x34
91 84
92 85
93/* If force is set to anything different from 0, we forcibly enable the 86/* If force is set to anything different from 0, we forcibly enable the
@@ -105,40 +98,65 @@ MODULE_PARM_DESC(force_addr,
105 "EXTREMELY DANGEROUS!"); 98 "EXTREMELY DANGEROUS!");
106 99
107 100
101static struct pci_driver vt596_driver;
108static struct i2c_adapter vt596_adapter; 102static struct i2c_adapter vt596_adapter;
109 103
110/* Another internally used function */ 104#define FEATURE_I2CBLOCK (1<<0)
111static int vt596_transaction(void) 105static unsigned int vt596_features;
106
107#ifdef DEBUG
108static void vt596_dump_regs(const char *msg, u8 size)
109{
110 dev_dbg(&vt596_adapter.dev, "%s: STS=%02x CNT=%02x CMD=%02x ADD=%02x "
111 "DAT=%02x,%02x\n", msg, inb_p(SMBHSTSTS), inb_p(SMBHSTCNT),
112 inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
113 inb_p(SMBHSTDAT1));
114
115 if (size == VT596_BLOCK_DATA
116 || size == VT596_I2C_BLOCK_DATA) {
117 int i;
118
119 dev_dbg(&vt596_adapter.dev, "BLK=");
120 for (i = 0; i < I2C_SMBUS_BLOCK_MAX / 2; i++)
121 printk("%02x,", inb_p(SMBBLKDAT));
122 printk("\n");
123 dev_dbg(&vt596_adapter.dev, " ");
124 for (; i < I2C_SMBUS_BLOCK_MAX - 1; i++)
125 printk("%02x,", inb_p(SMBBLKDAT));
126 printk("%02x\n", inb_p(SMBBLKDAT));
127 }
128}
129#else
130static inline void vt596_dump_regs(const char *msg, u8 size) { }
131#endif
132
133/* Return -1 on error, 0 on success */
134static int vt596_transaction(u8 size)
112{ 135{
113 int temp; 136 int temp;
114 int result = 0; 137 int result = 0;
115 int timeout = 0; 138 int timeout = 0;
116 139
117 dev_dbg(&vt596_adapter.dev, "Transaction (pre): CNT=%02x, CMD=%02x, " 140 vt596_dump_regs("Transaction (pre)", size);
118 "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT),
119 inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
120 inb_p(SMBHSTDAT1));
121 141
122 /* Make sure the SMBus host is ready to start transmitting */ 142 /* Make sure the SMBus host is ready to start transmitting */
123 if ((temp = inb_p(SMBHSTSTS)) & 0x1F) { 143 if ((temp = inb_p(SMBHSTSTS)) & 0x1F) {
124 dev_dbg(&vt596_adapter.dev, "SMBus busy (0x%02x). " 144 dev_dbg(&vt596_adapter.dev, "SMBus busy (0x%02x). "
125 "Resetting...\n", temp); 145 "Resetting... ", temp);
126 146
127 outb_p(temp, SMBHSTSTS); 147 outb_p(temp, SMBHSTSTS);
128 if ((temp = inb_p(SMBHSTSTS)) & 0x1F) { 148 if ((temp = inb_p(SMBHSTSTS)) & 0x1F) {
129 dev_dbg(&vt596_adapter.dev, "Failed! (0x%02x)\n", temp); 149 printk("Failed! (0x%02x)\n", temp);
130
131 return -1; 150 return -1;
132 } else { 151 } else {
133 dev_dbg(&vt596_adapter.dev, "Successfull!\n"); 152 printk("Successful!\n");
134 } 153 }
135 } 154 }
136 155
137 /* start the transaction by setting bit 6 */ 156 /* Start the transaction by setting bit 6 */
138 outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT); 157 outb_p(0x40 | (size & 0x3C), SMBHSTCNT);
139 158
140 /* We will always wait for a fraction of a second! 159 /* We will always wait for a fraction of a second */
141 I don't know if VIA needs this, Intel did */
142 do { 160 do {
143 msleep(1); 161 msleep(1);
144 temp = inb_p(SMBHSTSTS); 162 temp = inb_p(SMBHSTSTS);
@@ -147,77 +165,61 @@ static int vt596_transaction(void)
147 /* If the SMBus is still busy, we give up */ 165 /* If the SMBus is still busy, we give up */
148 if (timeout >= MAX_TIMEOUT) { 166 if (timeout >= MAX_TIMEOUT) {
149 result = -1; 167 result = -1;
150 dev_dbg(&vt596_adapter.dev, "SMBus Timeout!\n"); 168 dev_err(&vt596_adapter.dev, "SMBus timeout!\n");
151 } 169 }
152 170
153 if (temp & 0x10) { 171 if (temp & 0x10) {
154 result = -1; 172 result = -1;
155 dev_dbg(&vt596_adapter.dev, "Error: Failed bus transaction\n"); 173 dev_err(&vt596_adapter.dev, "Transaction failed (0x%02x)\n",
174 inb_p(SMBHSTCNT) & 0x3C);
156 } 175 }
157 176
158 if (temp & 0x08) { 177 if (temp & 0x08) {
159 result = -1; 178 result = -1;
160 dev_info(&vt596_adapter.dev, "Bus collision! SMBus may be " 179 dev_err(&vt596_adapter.dev, "SMBus collision!\n");
161 "locked until next hard\nreset. (sorry!)\n");
162 /* Clock stops and slave is stuck in mid-transmission */
163 } 180 }
164 181
165 if (temp & 0x04) { 182 if (temp & 0x04) {
166 result = -1; 183 result = -1;
167 dev_dbg(&vt596_adapter.dev, "Error: no response!\n"); 184 /* Quick commands are used to probe for chips, so
185 errors are expected, and we don't want to frighten the
186 user. */
187 if ((inb_p(SMBHSTCNT) & 0x3C) != VT596_QUICK)
188 dev_err(&vt596_adapter.dev, "Transaction error!\n");
168 } 189 }
169 190
170 if ((temp = inb_p(SMBHSTSTS)) & 0x1F) { 191 /* Resetting status register */
192 if (temp & 0x1F)
171 outb_p(temp, SMBHSTSTS); 193 outb_p(temp, SMBHSTSTS);
172 if ((temp = inb_p(SMBHSTSTS)) & 0x1F) {
173 dev_warn(&vt596_adapter.dev, "Failed reset at end "
174 "of transaction (%02x)\n", temp);
175 }
176 }
177 194
178 dev_dbg(&vt596_adapter.dev, "Transaction (post): CNT=%02x, CMD=%02x, " 195 vt596_dump_regs("Transaction (post)", size);
179 "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), 196
180 inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
181 inb_p(SMBHSTDAT1));
182
183 return result; 197 return result;
184} 198}
185 199
186/* Return -1 on error. */ 200/* Return -1 on error, 0 on success */
187static s32 vt596_access(struct i2c_adapter *adap, u16 addr, 201static s32 vt596_access(struct i2c_adapter *adap, u16 addr,
188 unsigned short flags, char read_write, u8 command, 202 unsigned short flags, char read_write, u8 command,
189 int size, union i2c_smbus_data *data) 203 int size, union i2c_smbus_data *data)
190{ 204{
191 int i, len; 205 int i;
192 206
193 switch (size) { 207 switch (size) {
194 case I2C_SMBUS_PROC_CALL:
195 dev_info(&vt596_adapter.dev,
196 "I2C_SMBUS_PROC_CALL not supported!\n");
197 return -1;
198 case I2C_SMBUS_QUICK: 208 case I2C_SMBUS_QUICK:
199 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
200 SMBHSTADD);
201 size = VT596_QUICK; 209 size = VT596_QUICK;
202 break; 210 break;
203 case I2C_SMBUS_BYTE: 211 case I2C_SMBUS_BYTE:
204 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
205 SMBHSTADD);
206 if (read_write == I2C_SMBUS_WRITE) 212 if (read_write == I2C_SMBUS_WRITE)
207 outb_p(command, SMBHSTCMD); 213 outb_p(command, SMBHSTCMD);
208 size = VT596_BYTE; 214 size = VT596_BYTE;
209 break; 215 break;
210 case I2C_SMBUS_BYTE_DATA: 216 case I2C_SMBUS_BYTE_DATA:
211 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
212 SMBHSTADD);
213 outb_p(command, SMBHSTCMD); 217 outb_p(command, SMBHSTCMD);
214 if (read_write == I2C_SMBUS_WRITE) 218 if (read_write == I2C_SMBUS_WRITE)
215 outb_p(data->byte, SMBHSTDAT0); 219 outb_p(data->byte, SMBHSTDAT0);
216 size = VT596_BYTE_DATA; 220 size = VT596_BYTE_DATA;
217 break; 221 break;
218 case I2C_SMBUS_WORD_DATA: 222 case I2C_SMBUS_WORD_DATA:
219 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
220 SMBHSTADD);
221 outb_p(command, SMBHSTCMD); 223 outb_p(command, SMBHSTCMD);
222 if (read_write == I2C_SMBUS_WRITE) { 224 if (read_write == I2C_SMBUS_WRITE) {
223 outb_p(data->word & 0xff, SMBHSTDAT0); 225 outb_p(data->word & 0xff, SMBHSTDAT0);
@@ -225,28 +227,33 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr,
225 } 227 }
226 size = VT596_WORD_DATA; 228 size = VT596_WORD_DATA;
227 break; 229 break;
230 case I2C_SMBUS_I2C_BLOCK_DATA:
231 if (!(vt596_features & FEATURE_I2CBLOCK))
232 goto exit_unsupported;
233 if (read_write == I2C_SMBUS_READ)
234 outb_p(I2C_SMBUS_BLOCK_MAX, SMBHSTDAT0);
235 /* Fall through */
228 case I2C_SMBUS_BLOCK_DATA: 236 case I2C_SMBUS_BLOCK_DATA:
229 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
230 SMBHSTADD);
231 outb_p(command, SMBHSTCMD); 237 outb_p(command, SMBHSTCMD);
232 if (read_write == I2C_SMBUS_WRITE) { 238 if (read_write == I2C_SMBUS_WRITE) {
233 len = data->block[0]; 239 u8 len = data->block[0];
234 if (len < 0)
235 len = 0;
236 if (len > I2C_SMBUS_BLOCK_MAX) 240 if (len > I2C_SMBUS_BLOCK_MAX)
237 len = I2C_SMBUS_BLOCK_MAX; 241 len = I2C_SMBUS_BLOCK_MAX;
238 outb_p(len, SMBHSTDAT0); 242 outb_p(len, SMBHSTDAT0);
239 i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ 243 inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */
240 for (i = 1; i <= len; i++) 244 for (i = 1; i <= len; i++)
241 outb_p(data->block[i], SMBBLKDAT); 245 outb_p(data->block[i], SMBBLKDAT);
242 } 246 }
243 size = VT596_BLOCK_DATA; 247 size = (size == I2C_SMBUS_I2C_BLOCK_DATA) ?
248 VT596_I2C_BLOCK_DATA : VT596_BLOCK_DATA;
244 break; 249 break;
250 default:
251 goto exit_unsupported;
245 } 252 }
246 253
247 outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT); 254 outb_p(((addr & 0x7f) << 1) | read_write, SMBHSTADD);
248 255
249 if (vt596_transaction()) /* Error in transaction */ 256 if (vt596_transaction(size)) /* Error in transaction */
250 return -1; 257 return -1;
251 258
252 if ((read_write == I2C_SMBUS_WRITE) || (size == VT596_QUICK)) 259 if ((read_write == I2C_SMBUS_WRITE) || (size == VT596_QUICK))
@@ -254,35 +261,39 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr,
254 261
255 switch (size) { 262 switch (size) {
256 case VT596_BYTE: 263 case VT596_BYTE:
257 /* Where is the result put? I assume here it is in
258 * SMBHSTDAT0 but it might just as well be in the
259 * SMBHSTCMD. No clue in the docs
260 */
261 data->byte = inb_p(SMBHSTDAT0);
262 break;
263 case VT596_BYTE_DATA: 264 case VT596_BYTE_DATA:
264 data->byte = inb_p(SMBHSTDAT0); 265 data->byte = inb_p(SMBHSTDAT0);
265 break; 266 break;
266 case VT596_WORD_DATA: 267 case VT596_WORD_DATA:
267 data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); 268 data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8);
268 break; 269 break;
270 case VT596_I2C_BLOCK_DATA:
269 case VT596_BLOCK_DATA: 271 case VT596_BLOCK_DATA:
270 data->block[0] = inb_p(SMBHSTDAT0); 272 data->block[0] = inb_p(SMBHSTDAT0);
271 if (data->block[0] > I2C_SMBUS_BLOCK_MAX) 273 if (data->block[0] > I2C_SMBUS_BLOCK_MAX)
272 data->block[0] = I2C_SMBUS_BLOCK_MAX; 274 data->block[0] = I2C_SMBUS_BLOCK_MAX;
273 i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ 275 inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */
274 for (i = 1; i <= data->block[0]; i++) 276 for (i = 1; i <= data->block[0]; i++)
275 data->block[i] = inb_p(SMBBLKDAT); 277 data->block[i] = inb_p(SMBBLKDAT);
276 break; 278 break;
277 } 279 }
278 return 0; 280 return 0;
281
282exit_unsupported:
283 dev_warn(&vt596_adapter.dev, "Unsupported command invoked! (0x%02x)\n",
284 size);
285 return -1;
279} 286}
280 287
281static u32 vt596_func(struct i2c_adapter *adapter) 288static u32 vt596_func(struct i2c_adapter *adapter)
282{ 289{
283 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 290 u32 func = I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
284 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 291 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
285 I2C_FUNC_SMBUS_BLOCK_DATA; 292 I2C_FUNC_SMBUS_BLOCK_DATA;
293
294 if (vt596_features & FEATURE_I2CBLOCK)
295 func |= I2C_FUNC_SMBUS_I2C_BLOCK;
296 return func;
286} 297}
287 298
288static struct i2c_algorithm smbus_algorithm = { 299static struct i2c_algorithm smbus_algorithm = {
@@ -294,7 +305,6 @@ static struct i2c_adapter vt596_adapter = {
294 .owner = THIS_MODULE, 305 .owner = THIS_MODULE,
295 .class = I2C_CLASS_HWMON, 306 .class = I2C_CLASS_HWMON,
296 .algo = &smbus_algorithm, 307 .algo = &smbus_algorithm,
297 .name = "unset",
298}; 308};
299 309
300static int __devinit vt596_probe(struct pci_dev *pdev, 310static int __devinit vt596_probe(struct pci_dev *pdev,
@@ -302,7 +312,7 @@ static int __devinit vt596_probe(struct pci_dev *pdev,
302{ 312{
303 unsigned char temp; 313 unsigned char temp;
304 int error = -ENODEV; 314 int error = -ENODEV;
305 315
306 /* Determine the address of the SMBus areas */ 316 /* Determine the address of the SMBus areas */
307 if (force_addr) { 317 if (force_addr) {
308 vt596_smba = force_addr & 0xfff0; 318 vt596_smba = force_addr & 0xfff0;
@@ -311,12 +321,12 @@ static int __devinit vt596_probe(struct pci_dev *pdev,
311 } 321 }
312 322
313 if ((pci_read_config_word(pdev, id->driver_data, &vt596_smba)) || 323 if ((pci_read_config_word(pdev, id->driver_data, &vt596_smba)) ||
314 !(vt596_smba & 0x1)) { 324 !(vt596_smba & 0x0001)) {
315 /* try 2nd address and config reg. for 596 */ 325 /* try 2nd address and config reg. for 596 */
316 if (id->device == PCI_DEVICE_ID_VIA_82C596_3 && 326 if (id->device == PCI_DEVICE_ID_VIA_82C596_3 &&
317 !pci_read_config_word(pdev, SMBBA2, &vt596_smba) && 327 !pci_read_config_word(pdev, SMBBA2, &vt596_smba) &&
318 (vt596_smba & 0x1)) { 328 (vt596_smba & 0x0001)) {
319 smb_cf_hstcfg = 0x84; 329 SMBHSTCFG = 0x84;
320 } else { 330 } else {
321 /* no matches at all */ 331 /* no matches at all */
322 dev_err(&pdev->dev, "Cannot configure " 332 dev_err(&pdev->dev, "Cannot configure "
@@ -333,10 +343,10 @@ static int __devinit vt596_probe(struct pci_dev *pdev,
333 return -ENODEV; 343 return -ENODEV;
334 } 344 }
335 345
336 found: 346found:
337 if (!request_region(vt596_smba, 8, "viapro-smbus")) { 347 if (!request_region(vt596_smba, 8, vt596_driver.name)) {
338 dev_err(&pdev->dev, "SMBus region 0x%x already in use!\n", 348 dev_err(&pdev->dev, "SMBus region 0x%x already in use!\n",
339 vt596_smba); 349 vt596_smba);
340 return -ENODEV; 350 return -ENODEV;
341 } 351 }
342 352
@@ -348,16 +358,16 @@ static int __devinit vt596_probe(struct pci_dev *pdev,
348 pci_write_config_word(pdev, id->driver_data, vt596_smba); 358 pci_write_config_word(pdev, id->driver_data, vt596_smba);
349 pci_write_config_byte(pdev, SMBHSTCFG, temp | 0x01); 359 pci_write_config_byte(pdev, SMBHSTCFG, temp | 0x01);
350 dev_warn(&pdev->dev, "WARNING: SMBus interface set to new " 360 dev_warn(&pdev->dev, "WARNING: SMBus interface set to new "
351 "address 0x%04x!\n", vt596_smba); 361 "address 0x%04x!\n", vt596_smba);
352 } else if ((temp & 1) == 0) { 362 } else if (!(temp & 0x01)) {
353 if (force) { 363 if (force) {
354 /* NOTE: This assumes I/O space and other allocations 364 /* NOTE: This assumes I/O space and other allocations
355 * WERE done by the Bios! Don't complain if your 365 * WERE done by the Bios! Don't complain if your
356 * hardware does weird things after enabling this. 366 * hardware does weird things after enabling this.
357 * :') Check for Bios updates before resorting to 367 * :') Check for Bios updates before resorting to
358 * this. 368 * this.
359 */ 369 */
360 pci_write_config_byte(pdev, SMBHSTCFG, temp | 1); 370 pci_write_config_byte(pdev, SMBHSTCFG, temp | 0x01);
361 dev_info(&pdev->dev, "Enabling SMBus device\n"); 371 dev_info(&pdev->dev, "Enabling SMBus device\n");
362 } else { 372 } else {
363 dev_err(&pdev->dev, "SMBUS: Error: Host SMBus " 373 dev_err(&pdev->dev, "SMBUS: Error: Host SMBus "
@@ -367,22 +377,28 @@ static int __devinit vt596_probe(struct pci_dev *pdev,
367 } 377 }
368 } 378 }
369 379
370 if ((temp & 0x0E) == 8)
371 dev_dbg(&pdev->dev, "using Interrupt 9 for SMBus.\n");
372 else if ((temp & 0x0E) == 0)
373 dev_dbg(&pdev->dev, "using Interrupt SMI# for SMBus.\n");
374 else
375 dev_dbg(&pdev->dev, "Illegal Interrupt configuration "
376 "(or code out of date)!\n");
377
378 pci_read_config_byte(pdev, SMBREV, &temp);
379 dev_dbg(&pdev->dev, "SMBREV = 0x%X\n", temp);
380 dev_dbg(&pdev->dev, "VT596_smba = 0x%X\n", vt596_smba); 380 dev_dbg(&pdev->dev, "VT596_smba = 0x%X\n", vt596_smba);
381 381
382 switch (pdev->device) {
383 case PCI_DEVICE_ID_VIA_8237:
384 case PCI_DEVICE_ID_VIA_8235:
385 case PCI_DEVICE_ID_VIA_8233A:
386 case PCI_DEVICE_ID_VIA_8233_0:
387 vt596_features |= FEATURE_I2CBLOCK;
388 break;
389 case PCI_DEVICE_ID_VIA_82C686_4:
390 /* The VT82C686B (rev 0x40) does support I2C block
391 transactions, but the VT82C686A (rev 0x30) doesn't */
392 if (!pci_read_config_byte(pdev, PCI_REVISION_ID, &temp)
393 && temp >= 0x40)
394 vt596_features |= FEATURE_I2CBLOCK;
395 break;
396 }
397
382 vt596_adapter.dev.parent = &pdev->dev; 398 vt596_adapter.dev.parent = &pdev->dev;
383 snprintf(vt596_adapter.name, I2C_NAME_SIZE, 399 snprintf(vt596_adapter.name, I2C_NAME_SIZE,
384 "SMBus Via Pro adapter at %04x", vt596_smba); 400 "SMBus Via Pro adapter at %04x", vt596_smba);
385 401
386 vt596_pdev = pci_dev_get(pdev); 402 vt596_pdev = pci_dev_get(pdev);
387 if (i2c_add_adapter(&vt596_adapter)) { 403 if (i2c_add_adapter(&vt596_adapter)) {
388 pci_dev_put(vt596_pdev); 404 pci_dev_put(vt596_pdev);
@@ -395,7 +411,7 @@ static int __devinit vt596_probe(struct pci_dev *pdev,
395 */ 411 */
396 return -ENODEV; 412 return -ENODEV;
397 413
398 release_region: 414release_region:
399 release_region(vt596_smba, 8); 415 release_region(vt596_smba, 8);
400 return error; 416 return error;
401} 417}
@@ -420,9 +436,10 @@ static struct pci_device_id vt596_ids[] = {
420 { 0, } 436 { 0, }
421}; 437};
422 438
423MODULE_DEVICE_TABLE (pci, vt596_ids); 439MODULE_DEVICE_TABLE(pci, vt596_ids);
424 440
425static struct pci_driver vt596_driver = { 441static struct pci_driver vt596_driver = {
442 .owner = THIS_MODULE,
426 .name = "vt596_smbus", 443 .name = "vt596_smbus",
427 .id_table = vt596_ids, 444 .id_table = vt596_ids,
428 .probe = vt596_probe, 445 .probe = vt596_probe,
diff --git a/drivers/i2c/busses/i2c-voodoo3.c b/drivers/i2c/busses/i2c-voodoo3.c
index b675773b0cc1..650c3ebde84c 100644
--- a/drivers/i2c/busses/i2c-voodoo3.c
+++ b/drivers/i2c/busses/i2c-voodoo3.c
@@ -225,6 +225,7 @@ static void __devexit voodoo3_remove(struct pci_dev *dev)
225} 225}
226 226
227static struct pci_driver voodoo3_driver = { 227static struct pci_driver voodoo3_driver = {
228 .owner = THIS_MODULE,
228 .name = "voodoo3_smbus", 229 .name = "voodoo3_smbus",
229 .id_table = voodoo3_ids, 230 .id_table = voodoo3_ids,
230 .probe = voodoo3_probe, 231 .probe = voodoo3_probe,
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index a1d580e05361..d3478e084522 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -442,14 +442,13 @@ static int __init scx200_acb_create(int base, int index)
442 int rc = 0; 442 int rc = 0;
443 char description[64]; 443 char description[64];
444 444
445 iface = kmalloc(sizeof(*iface), GFP_KERNEL); 445 iface = kzalloc(sizeof(*iface), GFP_KERNEL);
446 if (!iface) { 446 if (!iface) {
447 printk(KERN_ERR NAME ": can't allocate memory\n"); 447 printk(KERN_ERR NAME ": can't allocate memory\n");
448 rc = -ENOMEM; 448 rc = -ENOMEM;
449 goto errout; 449 goto errout;
450 } 450 }
451 451
452 memset(iface, 0, sizeof(*iface));
453 adapter = &iface->adapter; 452 adapter = &iface->adapter;
454 i2c_set_adapdata(adapter, iface); 453 i2c_set_adapdata(adapter, iface);
455 snprintf(adapter->name, I2C_NAME_SIZE, "SCx200 ACB%d", index); 454 snprintf(adapter->name, I2C_NAME_SIZE, "SCx200 ACB%d", index);
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
index 6bd44a44cd28..f9fae28f5612 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -126,4 +126,13 @@ config SENSORS_MAX6875
126 This driver can also be built as a module. If so, the module 126 This driver can also be built as a module. If so, the module
127 will be called max6875. 127 will be called max6875.
128 128
129config RTC_X1205_I2C
130 tristate "Xicor X1205 RTC chip"
131 depends on I2C && EXPERIMENTAL
132 help
133 If you say yes here you get support for the Xicor X1205 RTC chip.
134
135 This driver can also be built as a module. If so, the module
136 will be called x1205.
137
129endmenu 138endmenu
diff --git a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile
index a876dd42b860..46178b57b1f1 100644
--- a/drivers/i2c/chips/Makefile
+++ b/drivers/i2c/chips/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o
13obj-$(CONFIG_SENSORS_RTC8564) += rtc8564.o 13obj-$(CONFIG_SENSORS_RTC8564) += rtc8564.o
14obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o 14obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o
15obj-$(CONFIG_TPS65010) += tps65010.o 15obj-$(CONFIG_TPS65010) += tps65010.o
16obj-$(CONFIG_RTC_X1205_I2C) += x1205.o
16 17
17ifeq ($(CONFIG_I2C_DEBUG_CHIP),y) 18ifeq ($(CONFIG_I2C_DEBUG_CHIP),y)
18EXTRA_CFLAGS += -DDEBUG 19EXTRA_CFLAGS += -DDEBUG
diff --git a/drivers/i2c/chips/ds1337.c b/drivers/i2c/chips/ds1337.c
index 9d3175c03395..01b037007410 100644
--- a/drivers/i2c/chips/ds1337.c
+++ b/drivers/i2c/chips/ds1337.c
@@ -243,11 +243,10 @@ static int ds1337_detect(struct i2c_adapter *adapter, int address, int kind)
243 I2C_FUNC_I2C)) 243 I2C_FUNC_I2C))
244 goto exit; 244 goto exit;
245 245
246 if (!(data = kmalloc(sizeof(struct ds1337_data), GFP_KERNEL))) { 246 if (!(data = kzalloc(sizeof(struct ds1337_data), GFP_KERNEL))) {
247 err = -ENOMEM; 247 err = -ENOMEM;
248 goto exit; 248 goto exit;
249 } 249 }
250 memset(data, 0, sizeof(struct ds1337_data));
251 INIT_LIST_HEAD(&data->list); 250 INIT_LIST_HEAD(&data->list);
252 251
253 /* The common I2C client data is placed right before the 252 /* The common I2C client data is placed right before the
diff --git a/drivers/i2c/chips/ds1374.c b/drivers/i2c/chips/ds1374.c
index 0936327a946d..da488b735abf 100644
--- a/drivers/i2c/chips/ds1374.c
+++ b/drivers/i2c/chips/ds1374.c
@@ -167,7 +167,8 @@ static void ds1374_set_tlet(ulong arg)
167 167
168static ulong new_time; 168static ulong new_time;
169 169
170DECLARE_TASKLET_DISABLED(ds1374_tasklet, ds1374_set_tlet, (ulong) & new_time); 170static DECLARE_TASKLET_DISABLED(ds1374_tasklet, ds1374_set_tlet,
171 (ulong) & new_time);
171 172
172int ds1374_set_rtc_time(ulong nowtime) 173int ds1374_set_rtc_time(ulong nowtime)
173{ 174{
@@ -193,13 +194,11 @@ static int ds1374_probe(struct i2c_adapter *adap, int addr, int kind)
193 struct i2c_client *client; 194 struct i2c_client *client;
194 int rc; 195 int rc;
195 196
196 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); 197 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
197 if (!client) 198 if (!client)
198 return -ENOMEM; 199 return -ENOMEM;
199 200
200 memset(client, 0, sizeof(struct i2c_client));
201 strncpy(client->name, DS1374_DRV_NAME, I2C_NAME_SIZE); 201 strncpy(client->name, DS1374_DRV_NAME, I2C_NAME_SIZE);
202 client->flags = I2C_DF_NOTIFY;
203 client->addr = addr; 202 client->addr = addr;
204 client->adapter = adap; 203 client->adapter = adap;
205 client->driver = &ds1374_driver; 204 client->driver = &ds1374_driver;
diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c
index d58403a47908..4baf573fa04f 100644
--- a/drivers/i2c/chips/eeprom.c
+++ b/drivers/i2c/chips/eeprom.c
@@ -88,8 +88,8 @@ static void eeprom_update_client(struct i2c_client *client, u8 slice)
88 dev_dbg(&client->dev, "Starting eeprom update, slice %u\n", slice); 88 dev_dbg(&client->dev, "Starting eeprom update, slice %u\n", slice);
89 89
90 if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { 90 if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
91 for (i = slice << 5; i < (slice + 1) << 5; i += I2C_SMBUS_I2C_BLOCK_MAX) 91 for (i = slice << 5; i < (slice + 1) << 5; i += I2C_SMBUS_BLOCK_MAX)
92 if (i2c_smbus_read_i2c_block_data(client, i, data->data + i) != I2C_SMBUS_I2C_BLOCK_MAX) 92 if (i2c_smbus_read_i2c_block_data(client, i, data->data + i) != I2C_SMBUS_BLOCK_MAX)
93 goto exit; 93 goto exit;
94 } else { 94 } else {
95 if (i2c_smbus_write_byte(client, slice << 5)) { 95 if (i2c_smbus_write_byte(client, slice << 5)) {
@@ -155,7 +155,7 @@ static int eeprom_attach_adapter(struct i2c_adapter *adapter)
155} 155}
156 156
157/* This function is called by i2c_probe */ 157/* This function is called by i2c_probe */
158int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) 158static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
159{ 159{
160 struct i2c_client *new_client; 160 struct i2c_client *new_client;
161 struct eeprom_data *data; 161 struct eeprom_data *data;
@@ -171,11 +171,10 @@ int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
171 | I2C_FUNC_SMBUS_BYTE)) 171 | I2C_FUNC_SMBUS_BYTE))
172 goto exit; 172 goto exit;
173 173
174 if (!(data = kmalloc(sizeof(struct eeprom_data), GFP_KERNEL))) { 174 if (!(data = kzalloc(sizeof(struct eeprom_data), GFP_KERNEL))) {
175 err = -ENOMEM; 175 err = -ENOMEM;
176 goto exit; 176 goto exit;
177 } 177 }
178 memset(data, 0, sizeof(struct eeprom_data));
179 178
180 new_client = &data->client; 179 new_client = &data->client;
181 memset(data->data, 0xff, EEPROM_SIZE); 180 memset(data->data, 0xff, EEPROM_SIZE);
diff --git a/drivers/i2c/chips/isp1301_omap.c b/drivers/i2c/chips/isp1301_omap.c
index 8ee56d4b3891..eaa4742e04fa 100644
--- a/drivers/i2c/chips/isp1301_omap.c
+++ b/drivers/i2c/chips/isp1301_omap.c
@@ -888,6 +888,7 @@ static int otg_remove(struct device *dev)
888} 888}
889 889
890struct device_driver omap_otg_driver = { 890struct device_driver omap_otg_driver = {
891 .owner = THIS_MODULE,
891 .name = "omap_otg", 892 .name = "omap_otg",
892 .bus = &platform_bus_type, 893 .bus = &platform_bus_type,
893 .probe = otg_probe, 894 .probe = otg_probe,
diff --git a/drivers/i2c/chips/m41t00.c b/drivers/i2c/chips/m41t00.c
index 3f14528a52a9..3df309ae44a6 100644
--- a/drivers/i2c/chips/m41t00.c
+++ b/drivers/i2c/chips/m41t00.c
@@ -174,13 +174,11 @@ m41t00_probe(struct i2c_adapter *adap, int addr, int kind)
174 struct i2c_client *client; 174 struct i2c_client *client;
175 int rc; 175 int rc;
176 176
177 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); 177 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
178 if (!client) 178 if (!client)
179 return -ENOMEM; 179 return -ENOMEM;
180 180
181 memset(client, 0, sizeof(struct i2c_client));
182 strncpy(client->name, M41T00_DRV_NAME, I2C_NAME_SIZE); 181 strncpy(client->name, M41T00_DRV_NAME, I2C_NAME_SIZE);
183 client->flags = I2C_DF_NOTIFY;
184 client->addr = addr; 182 client->addr = addr;
185 client->adapter = adap; 183 client->adapter = adap;
186 client->driver = &m41t00_driver; 184 client->driver = &m41t00_driver;
diff --git a/drivers/i2c/chips/max6875.c b/drivers/i2c/chips/max6875.c
index 9e1aeb69abf9..b376a006883c 100644
--- a/drivers/i2c/chips/max6875.c
+++ b/drivers/i2c/chips/max6875.c
@@ -179,16 +179,14 @@ static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
179 if (address & 1) 179 if (address & 1)
180 return 0; 180 return 0;
181 181
182 if (!(data = kmalloc(sizeof(struct max6875_data), GFP_KERNEL))) 182 if (!(data = kzalloc(sizeof(struct max6875_data), GFP_KERNEL)))
183 return -ENOMEM; 183 return -ENOMEM;
184 memset(data, 0, sizeof(struct max6875_data));
185 184
186 /* A fake client is created on the odd address */ 185 /* A fake client is created on the odd address */
187 if (!(fake_client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL))) { 186 if (!(fake_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
188 err = -ENOMEM; 187 err = -ENOMEM;
189 goto exit_kfree1; 188 goto exit_kfree1;
190 } 189 }
191 memset(fake_client, 0, sizeof(struct i2c_client));
192 190
193 /* Init real i2c_client */ 191 /* Init real i2c_client */
194 real_client = &data->client; 192 real_client = &data->client;
diff --git a/drivers/i2c/chips/pca9539.c b/drivers/i2c/chips/pca9539.c
index 225577fdda4d..59a930346229 100644
--- a/drivers/i2c/chips/pca9539.c
+++ b/drivers/i2c/chips/pca9539.c
@@ -122,11 +122,10 @@ static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind)
122 122
123 /* OK. For now, we presume we have a valid client. We now create the 123 /* OK. For now, we presume we have a valid client. We now create the
124 client structure, even though we cannot fill it completely yet. */ 124 client structure, even though we cannot fill it completely yet. */
125 if (!(data = kmalloc(sizeof(struct pca9539_data), GFP_KERNEL))) { 125 if (!(data = kzalloc(sizeof(struct pca9539_data), GFP_KERNEL))) {
126 err = -ENOMEM; 126 err = -ENOMEM;
127 goto exit; 127 goto exit;
128 } 128 }
129 memset(data, 0, sizeof(struct pca9539_data));
130 129
131 new_client = &data->client; 130 new_client = &data->client;
132 i2c_set_clientdata(new_client, data); 131 i2c_set_clientdata(new_client, data);
diff --git a/drivers/i2c/chips/pcf8574.c b/drivers/i2c/chips/pcf8574.c
index 6525743ff9fd..c323c2de236c 100644
--- a/drivers/i2c/chips/pcf8574.c
+++ b/drivers/i2c/chips/pcf8574.c
@@ -115,7 +115,7 @@ static int pcf8574_attach_adapter(struct i2c_adapter *adapter)
115} 115}
116 116
117/* This function is called by i2c_probe */ 117/* This function is called by i2c_probe */
118int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind) 118static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
119{ 119{
120 struct i2c_client *new_client; 120 struct i2c_client *new_client;
121 struct pcf8574_data *data; 121 struct pcf8574_data *data;
@@ -127,11 +127,10 @@ int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
127 127
128 /* OK. For now, we presume we have a valid client. We now create the 128 /* OK. For now, we presume we have a valid client. We now create the
129 client structure, even though we cannot fill it completely yet. */ 129 client structure, even though we cannot fill it completely yet. */
130 if (!(data = kmalloc(sizeof(struct pcf8574_data), GFP_KERNEL))) { 130 if (!(data = kzalloc(sizeof(struct pcf8574_data), GFP_KERNEL))) {
131 err = -ENOMEM; 131 err = -ENOMEM;
132 goto exit; 132 goto exit;
133 } 133 }
134 memset(data, 0, sizeof(struct pcf8574_data));
135 134
136 new_client = &data->client; 135 new_client = &data->client;
137 i2c_set_clientdata(new_client, data); 136 i2c_set_clientdata(new_client, data);
diff --git a/drivers/i2c/chips/pcf8591.c b/drivers/i2c/chips/pcf8591.c
index 80f1df9a4500..ce420a67560b 100644
--- a/drivers/i2c/chips/pcf8591.c
+++ b/drivers/i2c/chips/pcf8591.c
@@ -166,7 +166,7 @@ static int pcf8591_attach_adapter(struct i2c_adapter *adapter)
166} 166}
167 167
168/* This function is called by i2c_probe */ 168/* This function is called by i2c_probe */
169int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind) 169static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind)
170{ 170{
171 struct i2c_client *new_client; 171 struct i2c_client *new_client;
172 struct pcf8591_data *data; 172 struct pcf8591_data *data;
@@ -178,11 +178,10 @@ int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind)
178 178
179 /* OK. For now, we presume we have a valid client. We now create the 179 /* OK. For now, we presume we have a valid client. We now create the
180 client structure, even though we cannot fill it completely yet. */ 180 client structure, even though we cannot fill it completely yet. */
181 if (!(data = kmalloc(sizeof(struct pcf8591_data), GFP_KERNEL))) { 181 if (!(data = kzalloc(sizeof(struct pcf8591_data), GFP_KERNEL))) {
182 err = -ENOMEM; 182 err = -ENOMEM;
183 goto exit; 183 goto exit;
184 } 184 }
185 memset(data, 0, sizeof(struct pcf8591_data));
186 185
187 new_client = &data->client; 186 new_client = &data->client;
188 i2c_set_clientdata(new_client, data); 187 i2c_set_clientdata(new_client, data);
diff --git a/drivers/i2c/chips/rtc8564.c b/drivers/i2c/chips/rtc8564.c
index 0b5385c892b1..916cdc1af23c 100644
--- a/drivers/i2c/chips/rtc8564.c
+++ b/drivers/i2c/chips/rtc8564.c
@@ -148,17 +148,16 @@ static int rtc8564_attach(struct i2c_adapter *adap, int addr, int kind)
148 {addr, I2C_M_RD, 2, data} 148 {addr, I2C_M_RD, 2, data}
149 }; 149 };
150 150
151 d = kmalloc(sizeof(struct rtc8564_data), GFP_KERNEL); 151 d = kzalloc(sizeof(struct rtc8564_data), GFP_KERNEL);
152 if (!d) { 152 if (!d) {
153 ret = -ENOMEM; 153 ret = -ENOMEM;
154 goto done; 154 goto done;
155 } 155 }
156 memset(d, 0, sizeof(struct rtc8564_data));
157 new_client = &d->client; 156 new_client = &d->client;
158 157
159 strlcpy(new_client->name, "RTC8564", I2C_NAME_SIZE); 158 strlcpy(new_client->name, "RTC8564", I2C_NAME_SIZE);
160 i2c_set_clientdata(new_client, d); 159 i2c_set_clientdata(new_client, d);
161 new_client->flags = I2C_CLIENT_ALLOW_USE | I2C_DF_NOTIFY; 160 new_client->flags = I2C_CLIENT_ALLOW_USE;
162 new_client->addr = addr; 161 new_client->addr = addr;
163 new_client->adapter = adap; 162 new_client->adapter = adap;
164 new_client->driver = &rtc8564_driver; 163 new_client->driver = &rtc8564_driver;
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c
index 280e9638c0f8..280dd7a45db6 100644
--- a/drivers/i2c/chips/tps65010.c
+++ b/drivers/i2c/chips/tps65010.c
@@ -500,11 +500,10 @@ tps65010_probe(struct i2c_adapter *bus, int address, int kind)
500 return 0; 500 return 0;
501 } 501 }
502 502
503 tps = kmalloc(sizeof *tps, GFP_KERNEL); 503 tps = kzalloc(sizeof *tps, GFP_KERNEL);
504 if (!tps) 504 if (!tps)
505 return 0; 505 return 0;
506 506
507 memset(tps, 0, sizeof *tps);
508 init_MUTEX(&tps->lock); 507 init_MUTEX(&tps->lock);
509 INIT_WORK(&tps->work, tps65010_work, tps); 508 INIT_WORK(&tps->work, tps65010_work, tps);
510 tps->irq = -1; 509 tps->irq = -1;
diff --git a/drivers/i2c/chips/x1205.c b/drivers/i2c/chips/x1205.c
new file mode 100644
index 000000000000..7da366cdc18c
--- /dev/null
+++ b/drivers/i2c/chips/x1205.c
@@ -0,0 +1,698 @@
1/*
2 * x1205.c - An i2c driver for the Xicor X1205 RTC
3 * Copyright 2004 Karen Spearel
4 * Copyright 2005 Alessandro Zummo
5 *
6 * please send all reports to:
7 * kas11 at tampabay dot rr dot com
8 * a dot zummo at towertech dot it
9 *
10 * based on the other drivers in this same directory.
11 *
12 * 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
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 */
17
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/slab.h>
21#include <linux/i2c.h>
22#include <linux/string.h>
23#include <linux/bcd.h>
24#include <linux/rtc.h>
25#include <linux/list.h>
26
27#include <linux/x1205.h>
28
29#define DRV_VERSION "0.9.9"
30
31/* Addresses to scan: none. This chip is located at
32 * 0x6f and uses a two bytes register addressing.
33 * Two bytes need to be written to read a single register,
34 * while most other chips just require one and take the second
35 * one as the data to be written. To prevent corrupting
36 * unknown chips, the user must explicitely set the probe parameter.
37 */
38
39static unsigned short normal_i2c[] = { I2C_CLIENT_END };
40
41/* Insmod parameters */
42I2C_CLIENT_INSMOD;
43I2C_CLIENT_MODULE_PARM(hctosys,
44 "Set the system time from the hardware clock upon initialization");
45
46/* offsets into CCR area */
47
48#define CCR_SEC 0
49#define CCR_MIN 1
50#define CCR_HOUR 2
51#define CCR_MDAY 3
52#define CCR_MONTH 4
53#define CCR_YEAR 5
54#define CCR_WDAY 6
55#define CCR_Y2K 7
56
57#define X1205_REG_SR 0x3F /* status register */
58#define X1205_REG_Y2K 0x37
59#define X1205_REG_DW 0x36
60#define X1205_REG_YR 0x35
61#define X1205_REG_MO 0x34
62#define X1205_REG_DT 0x33
63#define X1205_REG_HR 0x32
64#define X1205_REG_MN 0x31
65#define X1205_REG_SC 0x30
66#define X1205_REG_DTR 0x13
67#define X1205_REG_ATR 0x12
68#define X1205_REG_INT 0x11
69#define X1205_REG_0 0x10
70#define X1205_REG_Y2K1 0x0F
71#define X1205_REG_DWA1 0x0E
72#define X1205_REG_YRA1 0x0D
73#define X1205_REG_MOA1 0x0C
74#define X1205_REG_DTA1 0x0B
75#define X1205_REG_HRA1 0x0A
76#define X1205_REG_MNA1 0x09
77#define X1205_REG_SCA1 0x08
78#define X1205_REG_Y2K0 0x07
79#define X1205_REG_DWA0 0x06
80#define X1205_REG_YRA0 0x05
81#define X1205_REG_MOA0 0x04
82#define X1205_REG_DTA0 0x03
83#define X1205_REG_HRA0 0x02
84#define X1205_REG_MNA0 0x01
85#define X1205_REG_SCA0 0x00
86
87#define X1205_CCR_BASE 0x30 /* Base address of CCR */
88#define X1205_ALM0_BASE 0x00 /* Base address of ALARM0 */
89
90#define X1205_SR_RTCF 0x01 /* Clock failure */
91#define X1205_SR_WEL 0x02 /* Write Enable Latch */
92#define X1205_SR_RWEL 0x04 /* Register Write Enable */
93
94#define X1205_DTR_DTR0 0x01
95#define X1205_DTR_DTR1 0x02
96#define X1205_DTR_DTR2 0x04
97
98#define X1205_HR_MIL 0x80 /* Set in ccr.hour for 24 hr mode */
99
100/* Prototypes */
101static int x1205_attach(struct i2c_adapter *adapter);
102static int x1205_detach(struct i2c_client *client);
103static int x1205_probe(struct i2c_adapter *adapter, int address, int kind);
104static int x1205_command(struct i2c_client *client, unsigned int cmd,
105 void *arg);
106
107static struct i2c_driver x1205_driver = {
108 .owner = THIS_MODULE,
109 .name = "x1205",
110 .flags = I2C_DF_NOTIFY,
111 .attach_adapter = &x1205_attach,
112 .detach_client = &x1205_detach,
113};
114
115struct x1205_data {
116 struct i2c_client client;
117 struct list_head list;
118 unsigned int epoch;
119};
120
121static const unsigned char days_in_mo[] =
122 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
123
124static LIST_HEAD(x1205_clients);
125
126/* Workaround until the I2C subsytem will allow to send
127 * commands to a specific client. This function will send the command
128 * to the first client.
129 */
130int x1205_do_command(unsigned int cmd, void *arg)
131{
132 struct list_head *walk;
133 struct list_head *tmp;
134 struct x1205_data *data;
135
136 list_for_each_safe(walk, tmp, &x1205_clients) {
137 data = list_entry(walk, struct x1205_data, list);
138 return x1205_command(&data->client, cmd, arg);
139 }
140
141 return -ENODEV;
142}
143
144#define is_leap(year) \
145 ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
146
147/* make sure the rtc_time values are in bounds */
148static int x1205_validate_tm(struct rtc_time *tm)
149{
150 int year = tm->tm_year + 1900;
151
152 if ((tm->tm_year < 70) || (tm->tm_year > 255))
153 return -EINVAL;
154
155 if ((tm->tm_mon > 11) || (tm->tm_mday == 0))
156 return -EINVAL;
157
158 if (tm->tm_mday > days_in_mo[tm->tm_mon]
159 + ((tm->tm_mon == 1) && is_leap(year)))
160 return -EINVAL;
161
162 if ((tm->tm_hour >= 24) || (tm->tm_min >= 60) || (tm->tm_sec >= 60))
163 return -EINVAL;
164
165 return 0;
166}
167
168/*
169 * In the routines that deal directly with the x1205 hardware, we use
170 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch
171 * Epoch is initialized as 2000. Time is set to UTC.
172 */
173static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm,
174 u8 reg_base)
175{
176 unsigned char dt_addr[2] = { 0, reg_base };
177 static unsigned char sr_addr[2] = { 0, X1205_REG_SR };
178
179 unsigned char buf[8], sr;
180
181 struct i2c_msg msgs[] = {
182 { client->addr, 0, 2, sr_addr }, /* setup read ptr */
183 { client->addr, I2C_M_RD, 1, &sr }, /* read status */
184 { client->addr, 0, 2, dt_addr }, /* setup read ptr */
185 { client->addr, I2C_M_RD, 8, buf }, /* read date */
186 };
187
188 struct x1205_data *data = i2c_get_clientdata(client);
189
190 /* read status register */
191 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
192 dev_err(&client->dev, "%s: read error\n", __FUNCTION__);
193 return -EIO;
194 }
195
196 /* check for battery failure */
197 if (sr & X1205_SR_RTCF) {
198 dev_warn(&client->dev,
199 "Clock had a power failure, you must set the date.\n");
200 return -EINVAL;
201 }
202
203 /* read date registers */
204 if ((i2c_transfer(client->adapter, &msgs[2], 2)) != 2) {
205 dev_err(&client->dev, "%s: read error\n", __FUNCTION__);
206 return -EIO;
207 }
208
209 dev_dbg(&client->dev,
210 "%s: raw read data - sec=%02x, min=%02x, hr=%02x, "
211 "mday=%02x, mon=%02x, year=%02x, wday=%02x, y2k=%02x\n",
212 __FUNCTION__,
213 buf[0], buf[1], buf[2], buf[3],
214 buf[4], buf[5], buf[6], buf[7]);
215
216 tm->tm_sec = BCD2BIN(buf[CCR_SEC]);
217 tm->tm_min = BCD2BIN(buf[CCR_MIN]);
218 tm->tm_hour = BCD2BIN(buf[CCR_HOUR] & 0x3F); /* hr is 0-23 */
219 tm->tm_mday = BCD2BIN(buf[CCR_MDAY]);
220 tm->tm_mon = BCD2BIN(buf[CCR_MONTH]);
221 data->epoch = BCD2BIN(buf[CCR_Y2K]) * 100;
222 tm->tm_year = BCD2BIN(buf[CCR_YEAR]) + data->epoch - 1900;
223 tm->tm_wday = buf[CCR_WDAY];
224
225 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
226 "mday=%d, mon=%d, year=%d, wday=%d\n",
227 __FUNCTION__,
228 tm->tm_sec, tm->tm_min, tm->tm_hour,
229 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
230
231 return 0;
232}
233
234static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
235 int datetoo, u8 reg_base)
236{
237 int i, err, xfer;
238
239 unsigned char buf[8];
240
241 static const unsigned char wel[3] = { 0, X1205_REG_SR,
242 X1205_SR_WEL };
243
244 static const unsigned char rwel[3] = { 0, X1205_REG_SR,
245 X1205_SR_WEL | X1205_SR_RWEL };
246
247 static const unsigned char diswe[3] = { 0, X1205_REG_SR, 0 };
248
249 struct x1205_data *data = i2c_get_clientdata(client);
250
251 /* check if all values in the tm struct are correct */
252 if ((err = x1205_validate_tm(tm)) < 0)
253 return err;
254
255 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
256 "mday=%d, mon=%d, year=%d, wday=%d\n",
257 __FUNCTION__,
258 tm->tm_sec, tm->tm_min, tm->tm_hour,
259 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
260
261 buf[CCR_SEC] = BIN2BCD(tm->tm_sec);
262 buf[CCR_MIN] = BIN2BCD(tm->tm_min);
263
264 /* set hour and 24hr bit */
265 buf[CCR_HOUR] = BIN2BCD(tm->tm_hour) | X1205_HR_MIL;
266
267 /* should we also set the date? */
268 if (datetoo) {
269 buf[CCR_MDAY] = BIN2BCD(tm->tm_mday);
270
271 /* month, 0 - 11 */
272 buf[CCR_MONTH] = BIN2BCD(tm->tm_mon);
273
274 /* year, since 1900 */
275 buf[CCR_YEAR] = BIN2BCD(tm->tm_year + 1900 - data->epoch);
276 buf[CCR_WDAY] = tm->tm_wday & 0x07;
277 buf[CCR_Y2K] = BIN2BCD(data->epoch / 100);
278 }
279
280 /* this sequence is required to unlock the chip */
281 xfer = i2c_master_send(client, wel, 3);
282 if (xfer != 3) {
283 dev_err(&client->dev, "%s: wel - %d\n", __FUNCTION__, xfer);
284 return -EIO;
285 }
286
287 xfer = i2c_master_send(client, rwel, 3);
288 if (xfer != 3) {
289 dev_err(&client->dev, "%s: rwel - %d\n", __FUNCTION__, xfer);
290 return -EIO;
291 }
292
293 /* write register's data */
294 for (i = 0; i < (datetoo ? 8 : 3); i++) {
295 unsigned char rdata[3] = { 0, reg_base + i, buf[i] };
296
297 xfer = i2c_master_send(client, rdata, 3);
298 if (xfer != 3) {
299 dev_err(&client->dev,
300 "%s: xfer=%d addr=%02x, data=%02x\n",
301 __FUNCTION__,
302 xfer, rdata[1], rdata[2]);
303 return -EIO;
304 }
305 };
306
307 /* disable further writes */
308 xfer = i2c_master_send(client, diswe, 3);
309 if (xfer != 3) {
310 dev_err(&client->dev, "%s: diswe - %d\n", __FUNCTION__, xfer);
311 return -EIO;
312 }
313
314 return 0;
315}
316
317static int x1205_get_dtrim(struct i2c_client *client, int *trim)
318{
319 unsigned char dtr;
320 static unsigned char dtr_addr[2] = { 0, X1205_REG_DTR };
321
322 struct i2c_msg msgs[] = {
323 { client->addr, 0, 2, dtr_addr }, /* setup read ptr */
324 { client->addr, I2C_M_RD, 1, &dtr }, /* read dtr */
325 };
326
327 /* read dtr register */
328 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
329 dev_err(&client->dev, "%s: read error\n", __FUNCTION__);
330 return -EIO;
331 }
332
333 dev_dbg(&client->dev, "%s: raw dtr=%x\n", __FUNCTION__, dtr);
334
335 *trim = 0;
336
337 if (dtr & X1205_DTR_DTR0)
338 *trim += 20;
339
340 if (dtr & X1205_DTR_DTR1)
341 *trim += 10;
342
343 if (dtr & X1205_DTR_DTR2)
344 *trim = -*trim;
345
346 return 0;
347}
348
349static int x1205_get_atrim(struct i2c_client *client, int *trim)
350{
351 s8 atr;
352 static unsigned char atr_addr[2] = { 0, X1205_REG_ATR };
353
354 struct i2c_msg msgs[] = {
355 { client->addr, 0, 2, atr_addr }, /* setup read ptr */
356 { client->addr, I2C_M_RD, 1, &atr }, /* read atr */
357 };
358
359 /* read atr register */
360 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
361 dev_err(&client->dev, "%s: read error\n", __FUNCTION__);
362 return -EIO;
363 }
364
365 dev_dbg(&client->dev, "%s: raw atr=%x\n", __FUNCTION__, atr);
366
367 /* atr is a two's complement value on 6 bits,
368 * perform sign extension. The formula is
369 * Catr = (atr * 0.25pF) + 11.00pF.
370 */
371 if (atr & 0x20)
372 atr |= 0xC0;
373
374 dev_dbg(&client->dev, "%s: raw atr=%x (%d)\n", __FUNCTION__, atr, atr);
375
376 *trim = (atr * 250) + 11000;
377
378 dev_dbg(&client->dev, "%s: real=%d\n", __FUNCTION__, *trim);
379
380 return 0;
381}
382
383static int x1205_hctosys(struct i2c_client *client)
384{
385 int err;
386
387 struct rtc_time tm;
388 struct timespec tv;
389
390 err = x1205_command(client, X1205_CMD_GETDATETIME, &tm);
391
392 if (err) {
393 dev_err(&client->dev,
394 "Unable to set the system clock\n");
395 return err;
396 }
397
398 /* IMPORTANT: the RTC only stores whole seconds. It is arbitrary
399 * whether it stores the most close value or the value with partial
400 * seconds truncated. However, it is important that we use it to store
401 * the truncated value. This is because otherwise it is necessary,
402 * in an rtc sync function, to read both xtime.tv_sec and
403 * xtime.tv_nsec. On some processors (i.e. ARM), an atomic read
404 * of >32bits is not possible. So storing the most close value would
405 * slow down the sync API. So here we have the truncated value and
406 * the best guess is to add 0.5s.
407 */
408
409 tv.tv_nsec = NSEC_PER_SEC >> 1;
410
411 /* WARNING: this is not the C library 'mktime' call, it is a built in
412 * inline function from include/linux/time.h. It expects (requires)
413 * the month to be in the range 1-12
414 */
415
416 tv.tv_sec = mktime(tm.tm_year + 1900, tm.tm_mon + 1,
417 tm.tm_mday, tm.tm_hour,
418 tm.tm_min, tm.tm_sec);
419
420 do_settimeofday(&tv);
421
422 dev_info(&client->dev,
423 "setting the system clock to %d-%d-%d %d:%d:%d\n",
424 tm.tm_year + 1900, tm.tm_mon + 1,
425 tm.tm_mday, tm.tm_hour, tm.tm_min,
426 tm.tm_sec);
427
428 return 0;
429}
430
431struct x1205_limit
432{
433 unsigned char reg;
434 unsigned char mask;
435 unsigned char min;
436 unsigned char max;
437};
438
439static int x1205_validate_client(struct i2c_client *client)
440{
441 int i, xfer;
442
443 /* Probe array. We will read the register at the specified
444 * address and check if the given bits are zero.
445 */
446 static const unsigned char probe_zero_pattern[] = {
447 /* register, mask */
448 X1205_REG_SR, 0x18,
449 X1205_REG_DTR, 0xF8,
450 X1205_REG_ATR, 0xC0,
451 X1205_REG_INT, 0x18,
452 X1205_REG_0, 0xFF,
453 };
454
455 static const struct x1205_limit probe_limits_pattern[] = {
456 /* register, mask, min, max */
457 { X1205_REG_Y2K, 0xFF, 19, 20 },
458 { X1205_REG_DW, 0xFF, 0, 6 },
459 { X1205_REG_YR, 0xFF, 0, 99 },
460 { X1205_REG_MO, 0xFF, 0, 12 },
461 { X1205_REG_DT, 0xFF, 0, 31 },
462 { X1205_REG_HR, 0x7F, 0, 23 },
463 { X1205_REG_MN, 0xFF, 0, 59 },
464 { X1205_REG_SC, 0xFF, 0, 59 },
465 { X1205_REG_Y2K1, 0xFF, 19, 20 },
466 { X1205_REG_Y2K0, 0xFF, 19, 20 },
467 };
468
469 /* check that registers have bits a 0 where expected */
470 for (i = 0; i < ARRAY_SIZE(probe_zero_pattern); i += 2) {
471 unsigned char buf;
472
473 unsigned char addr[2] = { 0, probe_zero_pattern[i] };
474
475 struct i2c_msg msgs[2] = {
476 { client->addr, 0, 2, addr },
477 { client->addr, I2C_M_RD, 1, &buf },
478 };
479
480 xfer = i2c_transfer(client->adapter, msgs, 2);
481 if (xfer != 2) {
482 dev_err(&client->adapter->dev,
483 "%s: could not read register %x\n",
484 __FUNCTION__, addr[1]);
485
486 return -EIO;
487 }
488
489 if ((buf & probe_zero_pattern[i+1]) != 0) {
490 dev_err(&client->adapter->dev,
491 "%s: register=%02x, zero pattern=%d, value=%x\n",
492 __FUNCTION__, addr[1], i, buf);
493
494 return -ENODEV;
495 }
496 }
497
498 /* check limits (only registers with bcd values) */
499 for (i = 0; i < ARRAY_SIZE(probe_limits_pattern); i++) {
500 unsigned char reg, value;
501
502 unsigned char addr[2] = { 0, probe_limits_pattern[i].reg };
503
504 struct i2c_msg msgs[2] = {
505 { client->addr, 0, 2, addr },
506 { client->addr, I2C_M_RD, 1, &reg },
507 };
508
509 xfer = i2c_transfer(client->adapter, msgs, 2);
510
511 if (xfer != 2) {
512 dev_err(&client->adapter->dev,
513 "%s: could not read register %x\n",
514 __FUNCTION__, addr[1]);
515
516 return -EIO;
517 }
518
519 value = BCD2BIN(reg & probe_limits_pattern[i].mask);
520
521 if (value > probe_limits_pattern[i].max ||
522 value < probe_limits_pattern[i].min) {
523 dev_dbg(&client->adapter->dev,
524 "%s: register=%x, lim pattern=%d, value=%d\n",
525 __FUNCTION__, addr[1], i, value);
526
527 return -ENODEV;
528 }
529 }
530
531 return 0;
532}
533
534static int x1205_attach(struct i2c_adapter *adapter)
535{
536 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
537
538 return i2c_probe(adapter, &addr_data, x1205_probe);
539}
540
541int x1205_direct_attach(int adapter_id,
542 struct i2c_client_address_data *address_data)
543{
544 int err;
545 struct i2c_adapter *adapter = i2c_get_adapter(adapter_id);
546
547 if (adapter) {
548 err = i2c_probe(adapter,
549 address_data, x1205_probe);
550
551 i2c_put_adapter(adapter);
552
553 return err;
554 }
555
556 return -ENODEV;
557}
558
559static int x1205_probe(struct i2c_adapter *adapter, int address, int kind)
560{
561 struct i2c_client *client;
562 struct x1205_data *data;
563
564 int err = 0;
565
566 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
567
568 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
569 err = -ENODEV;
570 goto exit;
571 }
572
573 if (!(data = kzalloc(sizeof(struct x1205_data), GFP_KERNEL))) {
574 err = -ENOMEM;
575 goto exit;
576 }
577
578 /* Initialize our structures */
579 data->epoch = 2000;
580
581 client = &data->client;
582 client->addr = address;
583 client->driver = &x1205_driver;
584 client->adapter = adapter;
585
586 strlcpy(client->name, "x1205", I2C_NAME_SIZE);
587
588 i2c_set_clientdata(client, data);
589
590 /* Verify the chip is really an X1205 */
591 if (kind < 0) {
592 if (x1205_validate_client(client) < 0) {
593 err = -ENODEV;
594 goto exit_kfree;
595 }
596 }
597
598 /* Inform the i2c layer */
599 if ((err = i2c_attach_client(client)))
600 goto exit_kfree;
601
602 list_add(&data->list, &x1205_clients);
603
604 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
605
606 /* If requested, set the system time */
607 if (hctosys)
608 x1205_hctosys(client);
609
610 return 0;
611
612exit_kfree:
613 kfree(data);
614
615exit:
616 return err;
617}
618
619static int x1205_detach(struct i2c_client *client)
620{
621 int err;
622 struct x1205_data *data = i2c_get_clientdata(client);
623
624 dev_dbg(&client->dev, "%s\n", __FUNCTION__);
625
626 if ((err = i2c_detach_client(client)))
627 return err;
628
629 list_del(&data->list);
630
631 kfree(data);
632
633 return 0;
634}
635
636static int x1205_command(struct i2c_client *client, unsigned int cmd,
637 void *param)
638{
639 if (param == NULL)
640 return -EINVAL;
641
642 if (!capable(CAP_SYS_TIME))
643 return -EACCES;
644
645 dev_dbg(&client->dev, "%s: cmd=%d\n", __FUNCTION__, cmd);
646
647 switch (cmd) {
648 case X1205_CMD_GETDATETIME:
649 return x1205_get_datetime(client, param, X1205_CCR_BASE);
650
651 case X1205_CMD_SETTIME:
652 return x1205_set_datetime(client, param, 0,
653 X1205_CCR_BASE);
654
655 case X1205_CMD_SETDATETIME:
656 return x1205_set_datetime(client, param, 1,
657 X1205_CCR_BASE);
658
659 case X1205_CMD_GETALARM:
660 return x1205_get_datetime(client, param, X1205_ALM0_BASE);
661
662 case X1205_CMD_SETALARM:
663 return x1205_set_datetime(client, param, 1,
664 X1205_ALM0_BASE);
665
666 case X1205_CMD_GETDTRIM:
667 return x1205_get_dtrim(client, param);
668
669 case X1205_CMD_GETATRIM:
670 return x1205_get_atrim(client, param);
671
672 default:
673 return -EINVAL;
674 }
675}
676
677static int __init x1205_init(void)
678{
679 return i2c_add_driver(&x1205_driver);
680}
681
682static void __exit x1205_exit(void)
683{
684 i2c_del_driver(&x1205_driver);
685}
686
687MODULE_AUTHOR(
688 "Karen Spearel <kas11@tampabay.rr.com>, "
689 "Alessandro Zummo <a.zummo@towertech.it>");
690MODULE_DESCRIPTION("Xicor X1205 RTC driver");
691MODULE_LICENSE("GPL");
692MODULE_VERSION(DRV_VERSION);
693
694EXPORT_SYMBOL_GPL(x1205_do_command);
695EXPORT_SYMBOL_GPL(x1205_direct_attach);
696
697module_init(x1205_init);
698module_exit(x1205_exit);
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index dda472e5e8be..02e335a04f09 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -19,7 +19,8 @@
19 19
20/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>. 20/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>.
21 All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl> 21 All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl>
22 SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com> */ 22 SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com> and
23 Jean Delvare <khali@linux-fr.org> */
23 24
24#include <linux/module.h> 25#include <linux/module.h>
25#include <linux/kernel.h> 26#include <linux/kernel.h>
@@ -48,7 +49,7 @@ static int i2c_bus_suspend(struct device * dev, pm_message_t state)
48 int rc = 0; 49 int rc = 0;
49 50
50 if (dev->driver && dev->driver->suspend) 51 if (dev->driver && dev->driver->suspend)
51 rc = dev->driver->suspend(dev,state,0); 52 rc = dev->driver->suspend(dev, state);
52 return rc; 53 return rc;
53} 54}
54 55
@@ -57,7 +58,7 @@ static int i2c_bus_resume(struct device * dev)
57 int rc = 0; 58 int rc = 0;
58 59
59 if (dev->driver && dev->driver->resume) 60 if (dev->driver && dev->driver->resume)
60 rc = dev->driver->resume(dev,0); 61 rc = dev->driver->resume(dev);
61 return rc; 62 return rc;
62} 63}
63 64
@@ -85,6 +86,7 @@ void i2c_adapter_dev_release(struct device *dev)
85} 86}
86 87
87struct device_driver i2c_adapter_driver = { 88struct device_driver i2c_adapter_driver = {
89 .owner = THIS_MODULE,
88 .name = "i2c_adapter", 90 .name = "i2c_adapter",
89 .bus = &i2c_bus_type, 91 .bus = &i2c_bus_type,
90 .probe = i2c_device_probe, 92 .probe = i2c_device_probe,
@@ -98,6 +100,7 @@ static void i2c_adapter_class_dev_release(struct class_device *dev)
98} 100}
99 101
100struct class i2c_adapter_class = { 102struct class i2c_adapter_class = {
103 .owner = THIS_MODULE,
101 .name = "i2c-adapter", 104 .name = "i2c-adapter",
102 .release = &i2c_adapter_class_dev_release, 105 .release = &i2c_adapter_class_dev_release,
103}; 106};
@@ -291,6 +294,7 @@ int i2c_add_driver(struct i2c_driver *driver)
291 down(&core_lists); 294 down(&core_lists);
292 295
293 /* add the driver to the list of i2c drivers in the driver core */ 296 /* add the driver to the list of i2c drivers in the driver core */
297 driver->driver.owner = driver->owner;
294 driver->driver.name = driver->name; 298 driver->driver.name = driver->name;
295 driver->driver.bus = &i2c_bus_type; 299 driver->driver.bus = &i2c_bus_type;
296 driver->driver.probe = i2c_device_probe; 300 driver->driver.probe = i2c_device_probe;
@@ -706,10 +710,6 @@ int i2c_probe(struct i2c_adapter *adapter,
706 int i, err; 710 int i, err;
707 int adap_id = i2c_adapter_id(adapter); 711 int adap_id = i2c_adapter_id(adapter);
708 712
709 /* Forget it if we can't probe using SMBUS_QUICK */
710 if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_QUICK))
711 return -1;
712
713 /* Force entries are done first, and are not affected by ignore 713 /* Force entries are done first, and are not affected by ignore
714 entries */ 714 entries */
715 if (address_data->forces) { 715 if (address_data->forces) {
@@ -736,6 +736,17 @@ int i2c_probe(struct i2c_adapter *adapter,
736 } 736 }
737 } 737 }
738 738
739 /* Stop here if we can't use SMBUS_QUICK */
740 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_QUICK)) {
741 if (address_data->probe[0] == I2C_CLIENT_END
742 && address_data->normal_i2c[0] == I2C_CLIENT_END)
743 return 0;
744
745 dev_warn(&adapter->dev, "SMBus Quick command not supported, "
746 "can't probe for chips\n");
747 return -1;
748 }
749
739 /* Probe entries are done second, and are not affected by ignore 750 /* Probe entries are done second, and are not affected by ignore
740 entries either */ 751 entries either */
741 for (i = 0; address_data->probe[i] != I2C_CLIENT_END; i += 2) { 752 for (i = 0; address_data->probe[i] != I2C_CLIENT_END; i += 2) {
@@ -820,101 +831,44 @@ crc8(u16 data)
820 return (u8)(data >> 8); 831 return (u8)(data >> 8);
821} 832}
822 833
823/* CRC over count bytes in the first array plus the bytes in the rest 834/* Incremental CRC8 over count bytes in the array pointed to by p */
824 array if it is non-null. rest[0] is the (length of rest) - 1 835static u8 i2c_smbus_pec(u8 crc, u8 *p, size_t count)
825 and is included. */
826static u8 i2c_smbus_partial_pec(u8 crc, int count, u8 *first, u8 *rest)
827{ 836{
828 int i; 837 int i;
829 838
830 for(i = 0; i < count; i++) 839 for(i = 0; i < count; i++)
831 crc = crc8((crc ^ first[i]) << 8); 840 crc = crc8((crc ^ p[i]) << 8);
832 if(rest != NULL)
833 for(i = 0; i <= rest[0]; i++)
834 crc = crc8((crc ^ rest[i]) << 8);
835 return crc; 841 return crc;
836} 842}
837 843
838static u8 i2c_smbus_pec(int count, u8 *first, u8 *rest) 844/* Assume a 7-bit address, which is reasonable for SMBus */
845static u8 i2c_smbus_msg_pec(u8 pec, struct i2c_msg *msg)
839{ 846{
840 return i2c_smbus_partial_pec(0, count, first, rest); 847 /* The address will be sent first */
848 u8 addr = (msg->addr << 1) | !!(msg->flags & I2C_M_RD);
849 pec = i2c_smbus_pec(pec, &addr, 1);
850
851 /* The data buffer follows */
852 return i2c_smbus_pec(pec, msg->buf, msg->len);
841} 853}
842 854
843/* Returns new "size" (transaction type) 855/* Used for write only transactions */
844 Note that we convert byte to byte_data and byte_data to word_data 856static inline void i2c_smbus_add_pec(struct i2c_msg *msg)
845 rather than invent new xxx_PEC transactions. */
846static int i2c_smbus_add_pec(u16 addr, u8 command, int size,
847 union i2c_smbus_data *data)
848{ 857{
849 u8 buf[3]; 858 msg->buf[msg->len] = i2c_smbus_msg_pec(0, msg);
850 859 msg->len++;
851 buf[0] = addr << 1;
852 buf[1] = command;
853 switch(size) {
854 case I2C_SMBUS_BYTE:
855 data->byte = i2c_smbus_pec(2, buf, NULL);
856 size = I2C_SMBUS_BYTE_DATA;
857 break;
858 case I2C_SMBUS_BYTE_DATA:
859 buf[2] = data->byte;
860 data->word = buf[2] ||
861 (i2c_smbus_pec(3, buf, NULL) << 8);
862 size = I2C_SMBUS_WORD_DATA;
863 break;
864 case I2C_SMBUS_WORD_DATA:
865 /* unsupported */
866 break;
867 case I2C_SMBUS_BLOCK_DATA:
868 data->block[data->block[0] + 1] =
869 i2c_smbus_pec(2, buf, data->block);
870 size = I2C_SMBUS_BLOCK_DATA_PEC;
871 break;
872 }
873 return size;
874} 860}
875 861
876static int i2c_smbus_check_pec(u16 addr, u8 command, int size, u8 partial, 862/* Return <0 on CRC error
877 union i2c_smbus_data *data) 863 If there was a write before this read (most cases) we need to take the
864 partial CRC from the write part into account.
865 Note that this function does modify the message (we need to decrease the
866 message length to hide the CRC byte from the caller). */
867static int i2c_smbus_check_pec(u8 cpec, struct i2c_msg *msg)
878{ 868{
879 u8 buf[3], rpec, cpec; 869 u8 rpec = msg->buf[--msg->len];
870 cpec = i2c_smbus_msg_pec(cpec, msg);
880 871
881 buf[1] = command;
882 switch(size) {
883 case I2C_SMBUS_BYTE_DATA:
884 buf[0] = (addr << 1) | 1;
885 cpec = i2c_smbus_pec(2, buf, NULL);
886 rpec = data->byte;
887 break;
888 case I2C_SMBUS_WORD_DATA:
889 buf[0] = (addr << 1) | 1;
890 buf[2] = data->word & 0xff;
891 cpec = i2c_smbus_pec(3, buf, NULL);
892 rpec = data->word >> 8;
893 break;
894 case I2C_SMBUS_WORD_DATA_PEC:
895 /* unsupported */
896 cpec = rpec = 0;
897 break;
898 case I2C_SMBUS_PROC_CALL_PEC:
899 /* unsupported */
900 cpec = rpec = 0;
901 break;
902 case I2C_SMBUS_BLOCK_DATA_PEC:
903 buf[0] = (addr << 1);
904 buf[2] = (addr << 1) | 1;
905 cpec = i2c_smbus_pec(3, buf, data->block);
906 rpec = data->block[data->block[0] + 1];
907 break;
908 case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
909 buf[0] = (addr << 1) | 1;
910 rpec = i2c_smbus_partial_pec(partial, 1,
911 buf, data->block);
912 cpec = data->block[data->block[0] + 1];
913 break;
914 default:
915 cpec = rpec = 0;
916 break;
917 }
918 if (rpec != cpec) { 872 if (rpec != cpec) {
919 pr_debug("i2c-core: Bad PEC 0x%02x vs. 0x%02x\n", 873 pr_debug("i2c-core: Bad PEC 0x%02x vs. 0x%02x\n",
920 rpec, cpec); 874 rpec, cpec);
@@ -941,9 +895,8 @@ s32 i2c_smbus_read_byte(struct i2c_client *client)
941 895
942s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value) 896s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value)
943{ 897{
944 union i2c_smbus_data data; /* only for PEC */
945 return i2c_smbus_xfer(client->adapter,client->addr,client->flags, 898 return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
946 I2C_SMBUS_WRITE,value, I2C_SMBUS_BYTE,&data); 899 I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL);
947} 900}
948 901
949s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command) 902s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command)
@@ -1026,13 +979,14 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1026 need to use only one message; when reading, we need two. We initialize 979 need to use only one message; when reading, we need two. We initialize
1027 most things with sane defaults, to keep the code below somewhat 980 most things with sane defaults, to keep the code below somewhat
1028 simpler. */ 981 simpler. */
1029 unsigned char msgbuf0[34]; 982 unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3];
1030 unsigned char msgbuf1[34]; 983 unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2];
1031 int num = read_write == I2C_SMBUS_READ?2:1; 984 int num = read_write == I2C_SMBUS_READ?2:1;
1032 struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 }, 985 struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 },
1033 { addr, flags | I2C_M_RD, 0, msgbuf1 } 986 { addr, flags | I2C_M_RD, 0, msgbuf1 }
1034 }; 987 };
1035 int i; 988 int i;
989 u8 partial_pec = 0;
1036 990
1037 msgbuf0[0] = command; 991 msgbuf0[0] = command;
1038 switch(size) { 992 switch(size) {
@@ -1075,7 +1029,6 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1075 msgbuf0[2] = (data->word >> 8) & 0xff; 1029 msgbuf0[2] = (data->word >> 8) & 0xff;
1076 break; 1030 break;
1077 case I2C_SMBUS_BLOCK_DATA: 1031 case I2C_SMBUS_BLOCK_DATA:
1078 case I2C_SMBUS_BLOCK_DATA_PEC:
1079 if (read_write == I2C_SMBUS_READ) { 1032 if (read_write == I2C_SMBUS_READ) {
1080 dev_err(&adapter->dev, "Block read not supported " 1033 dev_err(&adapter->dev, "Block read not supported "
1081 "under I2C emulation!\n"); 1034 "under I2C emulation!\n");
@@ -1088,23 +1041,20 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1088 data->block[0]); 1041 data->block[0]);
1089 return -1; 1042 return -1;
1090 } 1043 }
1091 if(size == I2C_SMBUS_BLOCK_DATA_PEC) 1044 for (i = 1; i < msg[0].len; i++)
1092 (msg[0].len)++;
1093 for (i = 1; i <= msg[0].len; i++)
1094 msgbuf0[i] = data->block[i-1]; 1045 msgbuf0[i] = data->block[i-1];
1095 } 1046 }
1096 break; 1047 break;
1097 case I2C_SMBUS_BLOCK_PROC_CALL: 1048 case I2C_SMBUS_BLOCK_PROC_CALL:
1098 case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
1099 dev_dbg(&adapter->dev, "Block process call not supported " 1049 dev_dbg(&adapter->dev, "Block process call not supported "
1100 "under I2C emulation!\n"); 1050 "under I2C emulation!\n");
1101 return -1; 1051 return -1;
1102 case I2C_SMBUS_I2C_BLOCK_DATA: 1052 case I2C_SMBUS_I2C_BLOCK_DATA:
1103 if (read_write == I2C_SMBUS_READ) { 1053 if (read_write == I2C_SMBUS_READ) {
1104 msg[1].len = I2C_SMBUS_I2C_BLOCK_MAX; 1054 msg[1].len = I2C_SMBUS_BLOCK_MAX;
1105 } else { 1055 } else {
1106 msg[0].len = data->block[0] + 1; 1056 msg[0].len = data->block[0] + 1;
1107 if (msg[0].len > I2C_SMBUS_I2C_BLOCK_MAX + 1) { 1057 if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 1) {
1108 dev_err(&adapter->dev, "i2c_smbus_xfer_emulated called with " 1058 dev_err(&adapter->dev, "i2c_smbus_xfer_emulated called with "
1109 "invalid block write size (%d)\n", 1059 "invalid block write size (%d)\n",
1110 data->block[0]); 1060 data->block[0]);
@@ -1120,9 +1070,30 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1120 return -1; 1070 return -1;
1121 } 1071 }
1122 1072
1073 i = ((flags & I2C_CLIENT_PEC) && size != I2C_SMBUS_QUICK
1074 && size != I2C_SMBUS_I2C_BLOCK_DATA);
1075 if (i) {
1076 /* Compute PEC if first message is a write */
1077 if (!(msg[0].flags & I2C_M_RD)) {
1078 if (num == 1) /* Write only */
1079 i2c_smbus_add_pec(&msg[0]);
1080 else /* Write followed by read */
1081 partial_pec = i2c_smbus_msg_pec(0, &msg[0]);
1082 }
1083 /* Ask for PEC if last message is a read */
1084 if (msg[num-1].flags & I2C_M_RD)
1085 msg[num-1].len++;
1086 }
1087
1123 if (i2c_transfer(adapter, msg, num) < 0) 1088 if (i2c_transfer(adapter, msg, num) < 0)
1124 return -1; 1089 return -1;
1125 1090
1091 /* Check PEC if last message is a read */
1092 if (i && (msg[num-1].flags & I2C_M_RD)) {
1093 if (i2c_smbus_check_pec(partial_pec, &msg[num-1]) < 0)
1094 return -1;
1095 }
1096
1126 if (read_write == I2C_SMBUS_READ) 1097 if (read_write == I2C_SMBUS_READ)
1127 switch(size) { 1098 switch(size) {
1128 case I2C_SMBUS_BYTE: 1099 case I2C_SMBUS_BYTE:
@@ -1137,8 +1108,8 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1137 break; 1108 break;
1138 case I2C_SMBUS_I2C_BLOCK_DATA: 1109 case I2C_SMBUS_I2C_BLOCK_DATA:
1139 /* fixed at 32 for now */ 1110 /* fixed at 32 for now */
1140 data->block[0] = I2C_SMBUS_I2C_BLOCK_MAX; 1111 data->block[0] = I2C_SMBUS_BLOCK_MAX;
1141 for (i = 0; i < I2C_SMBUS_I2C_BLOCK_MAX; i++) 1112 for (i = 0; i < I2C_SMBUS_BLOCK_MAX; i++)
1142 data->block[i+1] = msgbuf1[i]; 1113 data->block[i+1] = msgbuf1[i];
1143 break; 1114 break;
1144 } 1115 }
@@ -1151,28 +1122,8 @@ s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
1151 union i2c_smbus_data * data) 1122 union i2c_smbus_data * data)
1152{ 1123{
1153 s32 res; 1124 s32 res;
1154 int swpec = 0;
1155 u8 partial = 0;
1156 1125
1157 flags &= I2C_M_TEN | I2C_CLIENT_PEC; 1126 flags &= I2C_M_TEN | I2C_CLIENT_PEC;
1158 if((flags & I2C_CLIENT_PEC) &&
1159 !(i2c_check_functionality(adapter, I2C_FUNC_SMBUS_HWPEC_CALC))) {
1160 swpec = 1;
1161 if(read_write == I2C_SMBUS_READ &&
1162 size == I2C_SMBUS_BLOCK_DATA)
1163 size = I2C_SMBUS_BLOCK_DATA_PEC;
1164 else if(size == I2C_SMBUS_PROC_CALL)
1165 size = I2C_SMBUS_PROC_CALL_PEC;
1166 else if(size == I2C_SMBUS_BLOCK_PROC_CALL) {
1167 i2c_smbus_add_pec(addr, command,
1168 I2C_SMBUS_BLOCK_DATA, data);
1169 partial = data->block[data->block[0] + 1];
1170 size = I2C_SMBUS_BLOCK_PROC_CALL_PEC;
1171 } else if(read_write == I2C_SMBUS_WRITE &&
1172 size != I2C_SMBUS_QUICK &&
1173 size != I2C_SMBUS_I2C_BLOCK_DATA)
1174 size = i2c_smbus_add_pec(addr, command, size, data);
1175 }
1176 1127
1177 if (adapter->algo->smbus_xfer) { 1128 if (adapter->algo->smbus_xfer) {
1178 down(&adapter->bus_lock); 1129 down(&adapter->bus_lock);
@@ -1183,13 +1134,6 @@ s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
1183 res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write, 1134 res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write,
1184 command,size,data); 1135 command,size,data);
1185 1136
1186 if(res >= 0 && swpec &&
1187 size != I2C_SMBUS_QUICK && size != I2C_SMBUS_I2C_BLOCK_DATA &&
1188 (read_write == I2C_SMBUS_READ || size == I2C_SMBUS_PROC_CALL_PEC ||
1189 size == I2C_SMBUS_BLOCK_PROC_CALL_PEC)) {
1190 if(i2c_smbus_check_pec(addr, command, size, partial, data))
1191 return -1;
1192 }
1193 return res; 1137 return res;
1194} 1138}
1195 1139
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index aa7a4fadef64..ea14c8f1c82b 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -26,15 +26,11 @@
26 26
27/* The I2C_RDWR ioctl code is written by Kolja Waschk <waschk@telos.de> */ 27/* The I2C_RDWR ioctl code is written by Kolja Waschk <waschk@telos.de> */
28 28
29/* The devfs code is contributed by Philipp Matthias Hahn
30 <pmhahn@titan.lahn.de> */
31
32#include <linux/kernel.h> 29#include <linux/kernel.h>
33#include <linux/module.h> 30#include <linux/module.h>
34#include <linux/fs.h> 31#include <linux/fs.h>
35#include <linux/slab.h> 32#include <linux/slab.h>
36#include <linux/smp_lock.h> 33#include <linux/smp_lock.h>
37#include <linux/devfs_fs_kernel.h>
38#include <linux/init.h> 34#include <linux/init.h>
39#include <linux/i2c.h> 35#include <linux/i2c.h>
40#include <linux/i2c-dev.h> 36#include <linux/i2c-dev.h>
@@ -80,10 +76,9 @@ static struct i2c_dev *get_free_i2c_dev(struct i2c_adapter *adap)
80{ 76{
81 struct i2c_dev *i2c_dev; 77 struct i2c_dev *i2c_dev;
82 78
83 i2c_dev = kmalloc(sizeof(*i2c_dev), GFP_KERNEL); 79 i2c_dev = kzalloc(sizeof(*i2c_dev), GFP_KERNEL);
84 if (!i2c_dev) 80 if (!i2c_dev)
85 return ERR_PTR(-ENOMEM); 81 return ERR_PTR(-ENOMEM);
86 memset(i2c_dev, 0x00, sizeof(*i2c_dev));
87 82
88 spin_lock(&i2c_dev_array_lock); 83 spin_lock(&i2c_dev_array_lock);
89 if (i2c_dev_array[adap->nr]) { 84 if (i2c_dev_array[adap->nr]) {
@@ -177,8 +172,8 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file,
177 int i,datasize,res; 172 int i,datasize,res;
178 unsigned long funcs; 173 unsigned long funcs;
179 174
180 dev_dbg(&client->adapter->dev, "i2c-%d ioctl, cmd: 0x%x, arg: %lx.\n", 175 dev_dbg(&client->adapter->dev, "ioctl, cmd=0x%02x, arg=0x%02lx\n",
181 iminor(inode),cmd, arg); 176 cmd, arg);
182 177
183 switch ( cmd ) { 178 switch ( cmd ) {
184 case I2C_SLAVE: 179 case I2C_SLAVE:
@@ -432,8 +427,6 @@ static int i2cdev_attach_adapter(struct i2c_adapter *adap)
432 if (IS_ERR(i2c_dev)) 427 if (IS_ERR(i2c_dev))
433 return PTR_ERR(i2c_dev); 428 return PTR_ERR(i2c_dev);
434 429
435 devfs_mk_cdev(MKDEV(I2C_MAJOR, i2c_dev->minor),
436 S_IFCHR|S_IRUSR|S_IWUSR, "i2c/%d", i2c_dev->minor);
437 pr_debug("i2c-dev: adapter [%s] registered as minor %d\n", 430 pr_debug("i2c-dev: adapter [%s] registered as minor %d\n",
438 adap->name, i2c_dev->minor); 431 adap->name, i2c_dev->minor);
439 432
@@ -466,7 +459,6 @@ static int i2cdev_detach_adapter(struct i2c_adapter *adap)
466 return -ENODEV; 459 return -ENODEV;
467 460
468 init_completion(&i2c_dev->released); 461 init_completion(&i2c_dev->released);
469 devfs_remove("i2c/%d", i2c_dev->minor);
470 return_i2c_dev(i2c_dev); 462 return_i2c_dev(i2c_dev);
471 class_device_unregister(&i2c_dev->class_dev); 463 class_device_unregister(&i2c_dev->class_dev);
472 wait_for_completion(&i2c_dev->released); 464 wait_for_completion(&i2c_dev->released);
@@ -522,8 +514,6 @@ static int __init i2c_dev_init(void)
522 if (res) 514 if (res)
523 goto out_unreg_class; 515 goto out_unreg_class;
524 516
525 devfs_mk_dir("i2c");
526
527 return 0; 517 return 0;
528 518
529out_unreg_class: 519out_unreg_class:
@@ -539,7 +529,6 @@ static void __exit i2c_dev_exit(void)
539{ 529{
540 i2c_del_driver(&i2cdev_driver); 530 i2c_del_driver(&i2cdev_driver);
541 class_unregister(&i2c_dev_class); 531 class_unregister(&i2c_dev_class);
542 devfs_remove("i2c");
543 unregister_chrdev(I2C_MAJOR,"i2c"); 532 unregister_chrdev(I2C_MAJOR,"i2c");
544} 533}
545 534
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index 1cadd2c3cadd..a737886e39d1 100644
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -778,6 +778,35 @@ config BLK_DEV_IDE_PMAC_BLINK
778 This option enables the use of the sleep LED as a hard drive 778 This option enables the use of the sleep LED as a hard drive
779 activity LED. 779 activity LED.
780 780
781config BLK_DEV_IDE_AU1XXX
782 bool "IDE for AMD Alchemy Au1200"
783 depends on SOC_AU1200
784choice
785 prompt "IDE Mode for AMD Alchemy Au1200"
786 default CONFIG_BLK_DEV_IDE_AU1XXX_PIO_DBDMA
787 depends on SOC_AU1200 && BLK_DEV_IDE_AU1XXX
788
789config BLK_DEV_IDE_AU1XXX_PIO_DBDMA
790 bool "PIO+DbDMA IDE for AMD Alchemy Au1200"
791
792config BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
793 bool "MDMA2+DbDMA IDE for AMD Alchemy Au1200"
794 depends on SOC_AU1200 && BLK_DEV_IDE_AU1XXX
795endchoice
796
797config BLK_DEV_IDE_AU1XXX_BURSTABLE_ON
798 bool "Enable burstable Mode on DbDMA"
799 default false
800 depends BLK_DEV_IDE_AU1XXX
801 help
802 This option enable the burstable Flag on DbDMA controller
803 (cf. "AMD Alchemy 'Au1200' Processor Data Book - PRELIMINARY").
804
805config BLK_DEV_IDE_AU1XXX_SEQTS_PER_RQ
806 int "Maximum transfer size (KB) per request (up to 128)"
807 default "128"
808 depends BLK_DEV_IDE_AU1XXX
809
781config IDE_ARM 810config IDE_ARM
782 def_bool ARM && (ARCH_A5K || ARCH_CLPS7500 || ARCH_RPC || ARCH_SHARK) 811 def_bool ARM && (ARCH_A5K || ARCH_CLPS7500 || ARCH_RPC || ARCH_SHARK)
783 812
@@ -1013,7 +1042,7 @@ config BLK_DEV_UMC8672
1013endif 1042endif
1014 1043
1015config BLK_DEV_IDEDMA 1044config BLK_DEV_IDEDMA
1016 def_bool BLK_DEV_IDEDMA_PCI || BLK_DEV_IDEDMA_PMAC || BLK_DEV_IDEDMA_ICS 1045 def_bool BLK_DEV_IDEDMA_PCI || BLK_DEV_IDEDMA_PMAC || BLK_DEV_IDEDMA_ICS || BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
1017 1046
1018config IDEDMA_IVB 1047config IDEDMA_IVB
1019 bool "IGNORE word93 Validation BITS" 1048 bool "IGNORE word93 Validation BITS"
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 74af7e074868..8b9d85526596 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -2211,13 +2211,12 @@ static int cdrom_read_toc(ide_drive_t *drive, struct request_sense *sense)
2211 2211
2212 if (toc == NULL) { 2212 if (toc == NULL) {
2213 /* Try to allocate space. */ 2213 /* Try to allocate space. */
2214 toc = (struct atapi_toc *) kmalloc (sizeof (struct atapi_toc), 2214 toc = kmalloc(sizeof(struct atapi_toc), GFP_KERNEL);
2215 GFP_KERNEL);
2216 info->toc = toc;
2217 if (toc == NULL) { 2215 if (toc == NULL) {
2218 printk (KERN_ERR "%s: No cdrom TOC buffer!\n", drive->name); 2216 printk (KERN_ERR "%s: No cdrom TOC buffer!\n", drive->name);
2219 return -ENOMEM; 2217 return -ENOMEM;
2220 } 2218 }
2219 info->toc = toc;
2221 } 2220 }
2222 2221
2223 /* Check to see if the existing data is still valid. 2222 /* Check to see if the existing data is still valid.
@@ -2240,7 +2239,8 @@ static int cdrom_read_toc(ide_drive_t *drive, struct request_sense *sense)
2240 /* First read just the header, so we know how long the TOC is. */ 2239 /* First read just the header, so we know how long the TOC is. */
2241 stat = cdrom_read_tocentry(drive, 0, 1, 0, (char *) &toc->hdr, 2240 stat = cdrom_read_tocentry(drive, 0, 1, 0, (char *) &toc->hdr,
2242 sizeof(struct atapi_toc_header), sense); 2241 sizeof(struct atapi_toc_header), sense);
2243 if (stat) return stat; 2242 if (stat)
2243 return stat;
2244 2244
2245#if ! STANDARD_ATAPI 2245#if ! STANDARD_ATAPI
2246 if (CDROM_CONFIG_FLAGS(drive)->toctracks_as_bcd) { 2246 if (CDROM_CONFIG_FLAGS(drive)->toctracks_as_bcd) {
@@ -2324,7 +2324,8 @@ static int cdrom_read_toc(ide_drive_t *drive, struct request_sense *sense)
2324 /* Read the multisession information. */ 2324 /* Read the multisession information. */
2325 stat = cdrom_read_tocentry(drive, 0, 0, 1, (char *)&ms_tmp, 2325 stat = cdrom_read_tocentry(drive, 0, 0, 1, (char *)&ms_tmp,
2326 sizeof(ms_tmp), sense); 2326 sizeof(ms_tmp), sense);
2327 if (stat) return stat; 2327 if (stat)
2328 return stat;
2328 2329
2329 toc->last_session_lba = be32_to_cpu(ms_tmp.ent.addr.lba); 2330 toc->last_session_lba = be32_to_cpu(ms_tmp.ent.addr.lba);
2330 } else { 2331 } else {
@@ -2460,7 +2461,7 @@ static int ide_cdrom_packet(struct cdrom_device_info *cdi,
2460 struct packet_command *cgc) 2461 struct packet_command *cgc)
2461{ 2462{
2462 struct request req; 2463 struct request req;
2463 ide_drive_t *drive = (ide_drive_t*) cdi->handle; 2464 ide_drive_t *drive = cdi->handle;
2464 2465
2465 if (cgc->timeout <= 0) 2466 if (cgc->timeout <= 0)
2466 cgc->timeout = ATAPI_WAIT_PC; 2467 cgc->timeout = ATAPI_WAIT_PC;
@@ -2537,7 +2538,7 @@ int ide_cdrom_audio_ioctl (struct cdrom_device_info *cdi,
2537 unsigned int cmd, void *arg) 2538 unsigned int cmd, void *arg)
2538 2539
2539{ 2540{
2540 ide_drive_t *drive = (ide_drive_t*) cdi->handle; 2541 ide_drive_t *drive = cdi->handle;
2541 struct cdrom_info *info = drive->driver_data; 2542 struct cdrom_info *info = drive->driver_data;
2542 int stat; 2543 int stat;
2543 2544
@@ -2548,7 +2549,7 @@ int ide_cdrom_audio_ioctl (struct cdrom_device_info *cdi,
2548 */ 2549 */
2549 case CDROMPLAYTRKIND: { 2550 case CDROMPLAYTRKIND: {
2550 unsigned long lba_start, lba_end; 2551 unsigned long lba_start, lba_end;
2551 struct cdrom_ti *ti = (struct cdrom_ti *)arg; 2552 struct cdrom_ti *ti = arg;
2552 struct atapi_toc_entry *first_toc, *last_toc; 2553 struct atapi_toc_entry *first_toc, *last_toc;
2553 2554
2554 stat = cdrom_get_toc_entry(drive, ti->cdti_trk0, &first_toc); 2555 stat = cdrom_get_toc_entry(drive, ti->cdti_trk0, &first_toc);
@@ -2571,12 +2572,13 @@ int ide_cdrom_audio_ioctl (struct cdrom_device_info *cdi,
2571 } 2572 }
2572 2573
2573 case CDROMREADTOCHDR: { 2574 case CDROMREADTOCHDR: {
2574 struct cdrom_tochdr *tochdr = (struct cdrom_tochdr *) arg; 2575 struct cdrom_tochdr *tochdr = arg;
2575 struct atapi_toc *toc; 2576 struct atapi_toc *toc;
2576 2577
2577 /* Make sure our saved TOC is valid. */ 2578 /* Make sure our saved TOC is valid. */
2578 stat = cdrom_read_toc(drive, NULL); 2579 stat = cdrom_read_toc(drive, NULL);
2579 if (stat) return stat; 2580 if (stat)
2581 return stat;
2580 2582
2581 toc = info->toc; 2583 toc = info->toc;
2582 tochdr->cdth_trk0 = toc->hdr.first_track; 2584 tochdr->cdth_trk0 = toc->hdr.first_track;
@@ -2586,11 +2588,12 @@ int ide_cdrom_audio_ioctl (struct cdrom_device_info *cdi,
2586 } 2588 }
2587 2589
2588 case CDROMREADTOCENTRY: { 2590 case CDROMREADTOCENTRY: {
2589 struct cdrom_tocentry *tocentry = (struct cdrom_tocentry*) arg; 2591 struct cdrom_tocentry *tocentry = arg;
2590 struct atapi_toc_entry *toce; 2592 struct atapi_toc_entry *toce;
2591 2593
2592 stat = cdrom_get_toc_entry(drive, tocentry->cdte_track, &toce); 2594 stat = cdrom_get_toc_entry(drive, tocentry->cdte_track, &toce);
2593 if (stat) return stat; 2595 if (stat)
2596 return stat;
2594 2597
2595 tocentry->cdte_ctrl = toce->control; 2598 tocentry->cdte_ctrl = toce->control;
2596 tocentry->cdte_adr = toce->adr; 2599 tocentry->cdte_adr = toce->adr;
@@ -2613,7 +2616,7 @@ int ide_cdrom_audio_ioctl (struct cdrom_device_info *cdi,
2613static 2616static
2614int ide_cdrom_reset (struct cdrom_device_info *cdi) 2617int ide_cdrom_reset (struct cdrom_device_info *cdi)
2615{ 2618{
2616 ide_drive_t *drive = (ide_drive_t*) cdi->handle; 2619 ide_drive_t *drive = cdi->handle;
2617 struct request_sense sense; 2620 struct request_sense sense;
2618 struct request req; 2621 struct request req;
2619 int ret; 2622 int ret;
@@ -2636,12 +2639,13 @@ int ide_cdrom_reset (struct cdrom_device_info *cdi)
2636static 2639static
2637int ide_cdrom_tray_move (struct cdrom_device_info *cdi, int position) 2640int ide_cdrom_tray_move (struct cdrom_device_info *cdi, int position)
2638{ 2641{
2639 ide_drive_t *drive = (ide_drive_t*) cdi->handle; 2642 ide_drive_t *drive = cdi->handle;
2640 struct request_sense sense; 2643 struct request_sense sense;
2641 2644
2642 if (position) { 2645 if (position) {
2643 int stat = cdrom_lockdoor(drive, 0, &sense); 2646 int stat = cdrom_lockdoor(drive, 0, &sense);
2644 if (stat) return stat; 2647 if (stat)
2648 return stat;
2645 } 2649 }
2646 2650
2647 return cdrom_eject(drive, !position, &sense); 2651 return cdrom_eject(drive, !position, &sense);
@@ -2650,7 +2654,7 @@ int ide_cdrom_tray_move (struct cdrom_device_info *cdi, int position)
2650static 2654static
2651int ide_cdrom_lock_door (struct cdrom_device_info *cdi, int lock) 2655int ide_cdrom_lock_door (struct cdrom_device_info *cdi, int lock)
2652{ 2656{
2653 ide_drive_t *drive = (ide_drive_t*) cdi->handle; 2657 ide_drive_t *drive = cdi->handle;
2654 return cdrom_lockdoor(drive, lock, NULL); 2658 return cdrom_lockdoor(drive, lock, NULL);
2655} 2659}
2656 2660
@@ -2700,7 +2704,7 @@ void ide_cdrom_update_speed (ide_drive_t *drive, struct atapi_capabilities_page
2700static 2704static
2701int ide_cdrom_select_speed (struct cdrom_device_info *cdi, int speed) 2705int ide_cdrom_select_speed (struct cdrom_device_info *cdi, int speed)
2702{ 2706{
2703 ide_drive_t *drive = (ide_drive_t*) cdi->handle; 2707 ide_drive_t *drive = cdi->handle;
2704 struct request_sense sense; 2708 struct request_sense sense;
2705 struct atapi_capabilities_page cap; 2709 struct atapi_capabilities_page cap;
2706 int stat; 2710 int stat;
@@ -2723,7 +2727,7 @@ int ide_cdrom_select_speed (struct cdrom_device_info *cdi, int speed)
2723static 2727static
2724int ide_cdrom_drive_status (struct cdrom_device_info *cdi, int slot_nr) 2728int ide_cdrom_drive_status (struct cdrom_device_info *cdi, int slot_nr)
2725{ 2729{
2726 ide_drive_t *drive = (ide_drive_t*) cdi->handle; 2730 ide_drive_t *drive = cdi->handle;
2727 struct media_event_desc med; 2731 struct media_event_desc med;
2728 struct request_sense sense; 2732 struct request_sense sense;
2729 int stat; 2733 int stat;
@@ -2769,7 +2773,7 @@ int ide_cdrom_get_last_session (struct cdrom_device_info *cdi,
2769 struct cdrom_multisession *ms_info) 2773 struct cdrom_multisession *ms_info)
2770{ 2774{
2771 struct atapi_toc *toc; 2775 struct atapi_toc *toc;
2772 ide_drive_t *drive = (ide_drive_t*) cdi->handle; 2776 ide_drive_t *drive = cdi->handle;
2773 struct cdrom_info *info = drive->driver_data; 2777 struct cdrom_info *info = drive->driver_data;
2774 struct request_sense sense; 2778 struct request_sense sense;
2775 int ret; 2779 int ret;
@@ -2791,7 +2795,7 @@ int ide_cdrom_get_mcn (struct cdrom_device_info *cdi,
2791{ 2795{
2792 int stat; 2796 int stat;
2793 char mcnbuf[24]; 2797 char mcnbuf[24];
2794 ide_drive_t *drive = (ide_drive_t*) cdi->handle; 2798 ide_drive_t *drive = cdi->handle;
2795 2799
2796/* get MCN */ 2800/* get MCN */
2797 if ((stat = cdrom_read_subchannel(drive, 2, mcnbuf, sizeof (mcnbuf), NULL))) 2801 if ((stat = cdrom_read_subchannel(drive, 2, mcnbuf, sizeof (mcnbuf), NULL)))
@@ -2815,7 +2819,7 @@ static
2815int ide_cdrom_check_media_change_real (struct cdrom_device_info *cdi, 2819int ide_cdrom_check_media_change_real (struct cdrom_device_info *cdi,
2816 int slot_nr) 2820 int slot_nr)
2817{ 2821{
2818 ide_drive_t *drive = (ide_drive_t*) cdi->handle; 2822 ide_drive_t *drive = cdi->handle;
2819 int retval; 2823 int retval;
2820 2824
2821 if (slot_nr == CDSL_CURRENT) { 2825 if (slot_nr == CDSL_CURRENT) {
@@ -2886,7 +2890,7 @@ static int ide_cdrom_register (ide_drive_t *drive, int nslots)
2886 devinfo->mask = 0; 2890 devinfo->mask = 0;
2887 devinfo->speed = CDROM_STATE_FLAGS(drive)->current_speed; 2891 devinfo->speed = CDROM_STATE_FLAGS(drive)->current_speed;
2888 devinfo->capacity = nslots; 2892 devinfo->capacity = nslots;
2889 devinfo->handle = (void *) drive; 2893 devinfo->handle = drive;
2890 strcpy(devinfo->name, drive->name); 2894 strcpy(devinfo->name, drive->name);
2891 2895
2892 /* set capability mask to match the probe. */ 2896 /* set capability mask to match the probe. */
@@ -2942,7 +2946,7 @@ int ide_cdrom_probe_capabilities (ide_drive_t *drive)
2942 * registered with the Uniform layer yet, it can't do this. 2946 * registered with the Uniform layer yet, it can't do this.
2943 * Same goes for cdi->ops. 2947 * Same goes for cdi->ops.
2944 */ 2948 */
2945 cdi->handle = (ide_drive_t *) drive; 2949 cdi->handle = drive;
2946 cdi->ops = &ide_cdrom_dops; 2950 cdi->ops = &ide_cdrom_dops;
2947 2951
2948 if (ide_cdrom_get_capabilities(drive, &cap)) 2952 if (ide_cdrom_get_capabilities(drive, &cap))
@@ -3254,6 +3258,7 @@ int ide_cdrom_setup (ide_drive_t *drive)
3254 return 0; 3258 return 0;
3255} 3259}
3256 3260
3261#ifdef CONFIG_PROC_FS
3257static 3262static
3258sector_t ide_cdrom_capacity (ide_drive_t *drive) 3263sector_t ide_cdrom_capacity (ide_drive_t *drive)
3259{ 3264{
@@ -3264,6 +3269,7 @@ sector_t ide_cdrom_capacity (ide_drive_t *drive)
3264 3269
3265 return capacity * sectors_per_frame; 3270 return capacity * sectors_per_frame;
3266} 3271}
3272#endif
3267 3273
3268static int ide_cd_remove(struct device *dev) 3274static int ide_cd_remove(struct device *dev)
3269{ 3275{
@@ -3309,7 +3315,7 @@ static int ide_cd_probe(struct device *);
3309static int proc_idecd_read_capacity 3315static int proc_idecd_read_capacity
3310 (char *page, char **start, off_t off, int count, int *eof, void *data) 3316 (char *page, char **start, off_t off, int count, int *eof, void *data)
3311{ 3317{
3312 ide_drive_t*drive = (ide_drive_t *)data; 3318 ide_drive_t *drive = data;
3313 int len; 3319 int len;
3314 3320
3315 len = sprintf(page,"%llu\n", (long long)ide_cdrom_capacity(drive)); 3321 len = sprintf(page,"%llu\n", (long long)ide_cdrom_capacity(drive));
@@ -3449,7 +3455,7 @@ static int ide_cd_probe(struct device *dev)
3449 printk(KERN_INFO "ide-cd: passing drive %s to ide-scsi emulation.\n", drive->name); 3455 printk(KERN_INFO "ide-cd: passing drive %s to ide-scsi emulation.\n", drive->name);
3450 goto failed; 3456 goto failed;
3451 } 3457 }
3452 info = (struct cdrom_info *) kmalloc (sizeof (struct cdrom_info), GFP_KERNEL); 3458 info = kmalloc(sizeof(struct cdrom_info), GFP_KERNEL);
3453 if (info == NULL) { 3459 if (info == NULL) {
3454 printk(KERN_ERR "%s: Can't allocate a cdrom structure\n", drive->name); 3460 printk(KERN_ERR "%s: Can't allocate a cdrom structure\n", drive->name);
3455 goto failed; 3461 goto failed;
diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c
index 4063d2c34e3d..84665e2ba3c8 100644
--- a/drivers/ide/ide-proc.c
+++ b/drivers/ide/ide-proc.c
@@ -64,6 +64,7 @@ static int proc_ide_read_imodel
64 case ide_cy82c693: name = "cy82c693"; break; 64 case ide_cy82c693: name = "cy82c693"; break;
65 case ide_4drives: name = "4drives"; break; 65 case ide_4drives: name = "4drives"; break;
66 case ide_pmac: name = "mac-io"; break; 66 case ide_pmac: name = "mac-io"; break;
67 case ide_au1xxx: name = "au1xxx"; break;
67 default: name = "(unknown)"; break; 68 default: name = "(unknown)"; break;
68 } 69 }
69 len = sprintf(page, "%s\n", name); 70 len = sprintf(page, "%s\n", name);
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index ee38e6b143a4..47f2b832555f 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -1013,6 +1013,8 @@ typedef struct ide_tape_obj {
1013 1013
1014static DECLARE_MUTEX(idetape_ref_sem); 1014static DECLARE_MUTEX(idetape_ref_sem);
1015 1015
1016static struct class *idetape_sysfs_class;
1017
1016#define to_ide_tape(obj) container_of(obj, struct ide_tape_obj, kref) 1018#define to_ide_tape(obj) container_of(obj, struct ide_tape_obj, kref)
1017 1019
1018#define ide_tape_g(disk) \ 1020#define ide_tape_g(disk) \
@@ -4704,6 +4706,10 @@ static void ide_tape_release(struct kref *kref)
4704 4706
4705 drive->dsc_overlap = 0; 4707 drive->dsc_overlap = 0;
4706 drive->driver_data = NULL; 4708 drive->driver_data = NULL;
4709 class_device_destroy(idetape_sysfs_class,
4710 MKDEV(IDETAPE_MAJOR, tape->minor));
4711 class_device_destroy(idetape_sysfs_class,
4712 MKDEV(IDETAPE_MAJOR, tape->minor + 128));
4707 devfs_remove("%s/mt", drive->devfs_name); 4713 devfs_remove("%s/mt", drive->devfs_name);
4708 devfs_remove("%s/mtn", drive->devfs_name); 4714 devfs_remove("%s/mtn", drive->devfs_name);
4709 devfs_unregister_tape(g->number); 4715 devfs_unregister_tape(g->number);
@@ -4878,6 +4884,11 @@ static int ide_tape_probe(struct device *dev)
4878 4884
4879 idetape_setup(drive, tape, minor); 4885 idetape_setup(drive, tape, minor);
4880 4886
4887 class_device_create(idetape_sysfs_class, NULL,
4888 MKDEV(IDETAPE_MAJOR, minor), dev, "%s", tape->name);
4889 class_device_create(idetape_sysfs_class, NULL,
4890 MKDEV(IDETAPE_MAJOR, minor + 128), dev, "n%s", tape->name);
4891
4881 devfs_mk_cdev(MKDEV(HWIF(drive)->major, minor), 4892 devfs_mk_cdev(MKDEV(HWIF(drive)->major, minor),
4882 S_IFCHR | S_IRUGO | S_IWUGO, 4893 S_IFCHR | S_IRUGO | S_IWUGO,
4883 "%s/mt", drive->devfs_name); 4894 "%s/mt", drive->devfs_name);
@@ -4903,6 +4914,7 @@ MODULE_LICENSE("GPL");
4903static void __exit idetape_exit (void) 4914static void __exit idetape_exit (void)
4904{ 4915{
4905 driver_unregister(&idetape_driver.gen_driver); 4916 driver_unregister(&idetape_driver.gen_driver);
4917 class_destroy(idetape_sysfs_class);
4906 unregister_chrdev(IDETAPE_MAJOR, "ht"); 4918 unregister_chrdev(IDETAPE_MAJOR, "ht");
4907} 4919}
4908 4920
@@ -4911,11 +4923,33 @@ static void __exit idetape_exit (void)
4911 */ 4923 */
4912static int idetape_init (void) 4924static int idetape_init (void)
4913{ 4925{
4926 int error = 1;
4927 idetape_sysfs_class = class_create(THIS_MODULE, "ide_tape");
4928 if (IS_ERR(idetape_sysfs_class)) {
4929 idetape_sysfs_class = NULL;
4930 printk(KERN_ERR "Unable to create sysfs class for ide tapes\n");
4931 error = -EBUSY;
4932 goto out;
4933 }
4934
4914 if (register_chrdev(IDETAPE_MAJOR, "ht", &idetape_fops)) { 4935 if (register_chrdev(IDETAPE_MAJOR, "ht", &idetape_fops)) {
4915 printk(KERN_ERR "ide-tape: Failed to register character device interface\n"); 4936 printk(KERN_ERR "ide-tape: Failed to register character device interface\n");
4916 return -EBUSY; 4937 error = -EBUSY;
4938 goto out_free_class;
4917 } 4939 }
4918 return driver_register(&idetape_driver.gen_driver); 4940
4941 error = driver_register(&idetape_driver.gen_driver);
4942 if (error)
4943 goto out_free_driver;
4944
4945 return 0;
4946
4947out_free_driver:
4948 driver_unregister(&idetape_driver.gen_driver);
4949out_free_class:
4950 class_destroy(idetape_sysfs_class);
4951out:
4952 return error;
4919} 4953}
4920 4954
4921module_init(idetape_init); 4955module_init(idetape_init);
diff --git a/drivers/ide/mips/au1xxx-ide.c b/drivers/ide/mips/au1xxx-ide.c
new file mode 100644
index 000000000000..2b6327c576b9
--- /dev/null
+++ b/drivers/ide/mips/au1xxx-ide.c
@@ -0,0 +1,1250 @@
1/*
2 * linux/drivers/ide/mips/au1xxx-ide.c version 01.30.00 Aug. 02 2005
3 *
4 * BRIEF MODULE DESCRIPTION
5 * AMD Alchemy Au1xxx IDE interface routines over the Static Bus
6 *
7 * Copyright (c) 2003-2005 AMD, Personal Connectivity Solutions
8 *
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the License, or (at your option) any later
12 * version.
13 *
14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23 * POSSIBILITY OF SUCH DAMAGE.
24 *
25 * You should have received a copy of the GNU General Public License along with
26 * this program; if not, write to the Free Software Foundation, Inc.,
27 * 675 Mass Ave, Cambridge, MA 02139, USA.
28 *
29 * Note: for more information, please refer "AMD Alchemy Au1200/Au1550 IDE
30 * Interface and Linux Device Driver" Application Note.
31 */
32#undef REALLY_SLOW_IO /* most systems can safely undef this */
33
34#include <linux/config.h> /* for CONFIG_BLK_DEV_IDEPCI */
35#include <linux/types.h>
36#include <linux/module.h>
37#include <linux/kernel.h>
38#include <linux/delay.h>
39#include <linux/timer.h>
40#include <linux/mm.h>
41#include <linux/ioport.h>
42#include <linux/hdreg.h>
43#include <linux/init.h>
44#include <linux/ide.h>
45#include <linux/sysdev.h>
46
47#include <linux/dma-mapping.h>
48
49#include <asm/io.h>
50#include <asm/mach-au1x00/au1xxx.h>
51#include <asm/mach-au1x00/au1xxx_dbdma.h>
52
53#if CONFIG_PM
54#include <asm/mach-au1x00/au1xxx_pm.h>
55#endif
56
57#include <asm/mach-au1x00/au1xxx_ide.h>
58
59#define DRV_NAME "au1200-ide"
60#define DRV_VERSION "1.0"
61#define DRV_AUTHOR "AMD PCS / Pete Popov <ppopov@embeddedalley.com>"
62#define DRV_DESC "Au1200 IDE"
63
64static _auide_hwif auide_hwif;
65static spinlock_t ide_tune_drive_spin_lock = SPIN_LOCK_UNLOCKED;
66static spinlock_t ide_tune_chipset_spin_lock = SPIN_LOCK_UNLOCKED;
67static int dbdma_init_done = 0;
68
69/*
70 * local I/O functions
71 */
72u8 auide_inb(unsigned long port)
73{
74 return (au_readb(port));
75}
76
77u16 auide_inw(unsigned long port)
78{
79 return (au_readw(port));
80}
81
82u32 auide_inl(unsigned long port)
83{
84 return (au_readl(port));
85}
86
87void auide_insw(unsigned long port, void *addr, u32 count)
88{
89#if defined(CONFIG_BLK_DEV_IDE_AU1XXX_PIO_DBDMA)
90
91 _auide_hwif *ahwif = &auide_hwif;
92 chan_tab_t *ctp;
93 au1x_ddma_desc_t *dp;
94
95 if(!put_dest_flags(ahwif->rx_chan, (void*)addr, count << 1,
96 DDMA_FLAGS_NOIE)) {
97 printk(KERN_ERR "%s failed %d\n", __FUNCTION__, __LINE__);
98 return;
99 }
100 ctp = *((chan_tab_t **)ahwif->rx_chan);
101 dp = ctp->cur_ptr;
102 while (dp->dscr_cmd0 & DSCR_CMD0_V)
103 ;
104 ctp->cur_ptr = au1xxx_ddma_get_nextptr_virt(dp);
105#else
106 while (count--)
107 {
108 *(u16 *)addr = au_readw(port);
109 addr +=2 ;
110 }
111#endif
112}
113
114void auide_insl(unsigned long port, void *addr, u32 count)
115{
116 while (count--)
117 {
118 *(u32 *)addr = au_readl(port);
119 /* NOTE: For IDE interfaces over PCMCIA,
120 * 32-bit access does not work
121 */
122 addr += 4;
123 }
124}
125
126void auide_outb(u8 addr, unsigned long port)
127{
128 return (au_writeb(addr, port));
129}
130
131void auide_outbsync(ide_drive_t *drive, u8 addr, unsigned long port)
132{
133 return (au_writeb(addr, port));
134}
135
136void auide_outw(u16 addr, unsigned long port)
137{
138 return (au_writew(addr, port));
139}
140
141void auide_outl(u32 addr, unsigned long port)
142{
143 return (au_writel(addr, port));
144}
145
146void auide_outsw(unsigned long port, void *addr, u32 count)
147{
148#if defined(CONFIG_BLK_DEV_IDE_AU1XXX_PIO_DBDMA)
149 _auide_hwif *ahwif = &auide_hwif;
150 chan_tab_t *ctp;
151 au1x_ddma_desc_t *dp;
152
153 if(!put_source_flags(ahwif->tx_chan, (void*)addr,
154 count << 1, DDMA_FLAGS_NOIE)) {
155 printk(KERN_ERR "%s failed %d\n", __FUNCTION__, __LINE__);
156 return;
157 }
158 ctp = *((chan_tab_t **)ahwif->tx_chan);
159 dp = ctp->cur_ptr;
160 while (dp->dscr_cmd0 & DSCR_CMD0_V)
161 ;
162 ctp->cur_ptr = au1xxx_ddma_get_nextptr_virt(dp);
163#else
164 while (count--)
165 {
166 au_writew(*(u16 *)addr, port);
167 addr += 2;
168 }
169#endif
170}
171
172void auide_outsl(unsigned long port, void *addr, u32 count)
173{
174 while (count--)
175 {
176 au_writel(*(u32 *)addr, port);
177 /* NOTE: For IDE interfaces over PCMCIA,
178 * 32-bit access does not work
179 */
180 addr += 4;
181 }
182}
183
184static void auide_tune_drive(ide_drive_t *drive, byte pio)
185{
186 int mem_sttime;
187 int mem_stcfg;
188 unsigned long flags;
189 u8 speed;
190
191 /* get the best pio mode for the drive */
192 pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
193
194 printk("%s: setting Au1XXX IDE to PIO mode%d\n",
195 drive->name, pio);
196
197 spin_lock_irqsave(&ide_tune_drive_spin_lock, flags);
198
199 mem_sttime = 0;
200 mem_stcfg = au_readl(MEM_STCFG2);
201
202 /* set pio mode! */
203 switch(pio) {
204 case 0:
205 /* set timing parameters for RCS2# */
206 mem_sttime = SBC_IDE_PIO0_TWCS
207 | SBC_IDE_PIO0_TCSH
208 | SBC_IDE_PIO0_TCSOFF
209 | SBC_IDE_PIO0_TWP
210 | SBC_IDE_PIO0_TCSW
211 | SBC_IDE_PIO0_TPM
212 | SBC_IDE_PIO0_TA;
213 /* set configuration for RCS2# */
214 mem_stcfg |= TS_MASK;
215 mem_stcfg &= ~TCSOE_MASK;
216 mem_stcfg &= ~TOECS_MASK;
217 mem_stcfg |= SBC_IDE_PIO0_TCSOE | SBC_IDE_PIO0_TOECS;
218
219 au_writel(mem_sttime,MEM_STTIME2);
220 au_writel(mem_stcfg,MEM_STCFG2);
221 break;
222
223 case 1:
224 /* set timing parameters for RCS2# */
225 mem_sttime = SBC_IDE_PIO1_TWCS
226 | SBC_IDE_PIO1_TCSH
227 | SBC_IDE_PIO1_TCSOFF
228 | SBC_IDE_PIO1_TWP
229 | SBC_IDE_PIO1_TCSW
230 | SBC_IDE_PIO1_TPM
231 | SBC_IDE_PIO1_TA;
232 /* set configuration for RCS2# */
233 mem_stcfg |= TS_MASK;
234 mem_stcfg &= ~TCSOE_MASK;
235 mem_stcfg &= ~TOECS_MASK;
236 mem_stcfg |= SBC_IDE_PIO1_TCSOE | SBC_IDE_PIO1_TOECS;
237 break;
238
239 case 2:
240 /* set timing parameters for RCS2# */
241 mem_sttime = SBC_IDE_PIO2_TWCS
242 | SBC_IDE_PIO2_TCSH
243 | SBC_IDE_PIO2_TCSOFF
244 | SBC_IDE_PIO2_TWP
245 | SBC_IDE_PIO2_TCSW
246 | SBC_IDE_PIO2_TPM
247 | SBC_IDE_PIO2_TA;
248 /* set configuration for RCS2# */
249 mem_stcfg &= ~TS_MASK;
250 mem_stcfg &= ~TCSOE_MASK;
251 mem_stcfg &= ~TOECS_MASK;
252 mem_stcfg |= SBC_IDE_PIO2_TCSOE | SBC_IDE_PIO2_TOECS;
253 break;
254
255 case 3:
256 /* set timing parameters for RCS2# */
257 mem_sttime = SBC_IDE_PIO3_TWCS
258 | SBC_IDE_PIO3_TCSH
259 | SBC_IDE_PIO3_TCSOFF
260 | SBC_IDE_PIO3_TWP
261 | SBC_IDE_PIO3_TCSW
262 | SBC_IDE_PIO3_TPM
263 | SBC_IDE_PIO3_TA;
264 /* set configuration for RCS2# */
265 mem_stcfg |= TS_MASK;
266 mem_stcfg &= ~TS_MASK;
267 mem_stcfg &= ~TCSOE_MASK;
268 mem_stcfg &= ~TOECS_MASK;
269 mem_stcfg |= SBC_IDE_PIO3_TCSOE | SBC_IDE_PIO3_TOECS;
270
271 break;
272
273 case 4:
274 /* set timing parameters for RCS2# */
275 mem_sttime = SBC_IDE_PIO4_TWCS
276 | SBC_IDE_PIO4_TCSH
277 | SBC_IDE_PIO4_TCSOFF
278 | SBC_IDE_PIO4_TWP
279 | SBC_IDE_PIO4_TCSW
280 | SBC_IDE_PIO4_TPM
281 | SBC_IDE_PIO4_TA;
282 /* set configuration for RCS2# */
283 mem_stcfg &= ~TS_MASK;
284 mem_stcfg &= ~TCSOE_MASK;
285 mem_stcfg &= ~TOECS_MASK;
286 mem_stcfg |= SBC_IDE_PIO4_TCSOE | SBC_IDE_PIO4_TOECS;
287 break;
288 }
289
290 au_writel(mem_sttime,MEM_STTIME2);
291 au_writel(mem_stcfg,MEM_STCFG2);
292
293 spin_unlock_irqrestore(&ide_tune_drive_spin_lock, flags);
294
295 speed = pio + XFER_PIO_0;
296 ide_config_drive_speed(drive, speed);
297}
298
299static int auide_tune_chipset (ide_drive_t *drive, u8 speed)
300{
301 u8 mode = 0;
302 int mem_sttime;
303 int mem_stcfg;
304 unsigned long flags;
305#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
306 struct hd_driveid *id = drive->id;
307
308 /*
309 * Now see what the current drive is capable of,
310 * selecting UDMA only if the mate said it was ok.
311 */
312 if (id && (id->capability & 1) && drive->autodma &&
313 !__ide_dma_bad_drive(drive)) {
314 if (!mode && (id->field_valid & 2) && (id->dma_mword & 7)) {
315 if (id->dma_mword & 4)
316 mode = XFER_MW_DMA_2;
317 else if (id->dma_mword & 2)
318 mode = XFER_MW_DMA_1;
319 else if (id->dma_mword & 1)
320 mode = XFER_MW_DMA_0;
321 }
322 }
323#endif
324
325 spin_lock_irqsave(&ide_tune_chipset_spin_lock, flags);
326
327 mem_sttime = 0;
328 mem_stcfg = au_readl(MEM_STCFG2);
329
330 switch(speed) {
331 case XFER_PIO_4:
332 case XFER_PIO_3:
333 case XFER_PIO_2:
334 case XFER_PIO_1:
335 case XFER_PIO_0:
336 auide_tune_drive(drive, (speed - XFER_PIO_0));
337 break;
338#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
339 case XFER_MW_DMA_2:
340 /* set timing parameters for RCS2# */
341 mem_sttime = SBC_IDE_MDMA2_TWCS
342 | SBC_IDE_MDMA2_TCSH
343 | SBC_IDE_MDMA2_TCSOFF
344 | SBC_IDE_MDMA2_TWP
345 | SBC_IDE_MDMA2_TCSW
346 | SBC_IDE_MDMA2_TPM
347 | SBC_IDE_MDMA2_TA;
348 /* set configuration for RCS2# */
349 mem_stcfg &= ~TS_MASK;
350 mem_stcfg &= ~TCSOE_MASK;
351 mem_stcfg &= ~TOECS_MASK;
352 mem_stcfg |= SBC_IDE_MDMA2_TCSOE | SBC_IDE_MDMA2_TOECS;
353
354 mode = XFER_MW_DMA_2;
355 break;
356 case XFER_MW_DMA_1:
357 /* set timing parameters for RCS2# */
358 mem_sttime = SBC_IDE_MDMA1_TWCS
359 | SBC_IDE_MDMA1_TCSH
360 | SBC_IDE_MDMA1_TCSOFF
361 | SBC_IDE_MDMA1_TWP
362 | SBC_IDE_MDMA1_TCSW
363 | SBC_IDE_MDMA1_TPM
364 | SBC_IDE_MDMA1_TA;
365 /* set configuration for RCS2# */
366 mem_stcfg &= ~TS_MASK;
367 mem_stcfg &= ~TCSOE_MASK;
368 mem_stcfg &= ~TOECS_MASK;
369 mem_stcfg |= SBC_IDE_MDMA1_TCSOE | SBC_IDE_MDMA1_TOECS;
370
371 mode = XFER_MW_DMA_1;
372 break;
373 case XFER_MW_DMA_0:
374 /* set timing parameters for RCS2# */
375 mem_sttime = SBC_IDE_MDMA0_TWCS
376 | SBC_IDE_MDMA0_TCSH
377 | SBC_IDE_MDMA0_TCSOFF
378 | SBC_IDE_MDMA0_TWP
379 | SBC_IDE_MDMA0_TCSW
380 | SBC_IDE_MDMA0_TPM
381 | SBC_IDE_MDMA0_TA;
382 /* set configuration for RCS2# */
383 mem_stcfg |= TS_MASK;
384 mem_stcfg &= ~TCSOE_MASK;
385 mem_stcfg &= ~TOECS_MASK;
386 mem_stcfg |= SBC_IDE_MDMA0_TCSOE | SBC_IDE_MDMA0_TOECS;
387
388 mode = XFER_MW_DMA_0;
389 break;
390#endif
391 default:
392 return 1;
393 }
394
395 /*
396 * Tell the drive to switch to the new mode; abort on failure.
397 */
398 if (!mode || ide_config_drive_speed(drive, mode))
399 {
400 return 1; /* failure */
401 }
402
403
404 au_writel(mem_sttime,MEM_STTIME2);
405 au_writel(mem_stcfg,MEM_STCFG2);
406
407 spin_unlock_irqrestore(&ide_tune_chipset_spin_lock, flags);
408
409 return 0;
410}
411
412/*
413 * Multi-Word DMA + DbDMA functions
414 */
415#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
416
417static int in_drive_list(struct hd_driveid *id,
418 const struct drive_list_entry *drive_table)
419{
420 for ( ; drive_table->id_model ; drive_table++){
421 if ((!strcmp(drive_table->id_model, id->model)) &&
422 ((strstr(drive_table->id_firmware, id->fw_rev)) ||
423 (!strcmp(drive_table->id_firmware, "ALL")))
424 )
425 return 1;
426 }
427 return 0;
428}
429
430static int auide_build_sglist(ide_drive_t *drive, struct request *rq)
431{
432 ide_hwif_t *hwif = drive->hwif;
433 _auide_hwif *ahwif = (_auide_hwif*)hwif->hwif_data;
434 struct scatterlist *sg = hwif->sg_table;
435
436 ide_map_sg(drive, rq);
437
438 if (rq_data_dir(rq) == READ)
439 hwif->sg_dma_direction = DMA_FROM_DEVICE;
440 else
441 hwif->sg_dma_direction = DMA_TO_DEVICE;
442
443 return dma_map_sg(ahwif->dev, sg, hwif->sg_nents,
444 hwif->sg_dma_direction);
445}
446
447static int auide_build_dmatable(ide_drive_t *drive)
448{
449 int i, iswrite, count = 0;
450 ide_hwif_t *hwif = HWIF(drive);
451
452 struct request *rq = HWGROUP(drive)->rq;
453
454 _auide_hwif *ahwif = (_auide_hwif*)hwif->hwif_data;
455 struct scatterlist *sg;
456
457 iswrite = (rq_data_dir(rq) == WRITE);
458 /* Save for interrupt context */
459 ahwif->drive = drive;
460
461 /* Build sglist */
462 hwif->sg_nents = i = auide_build_sglist(drive, rq);
463
464 if (!i)
465 return 0;
466
467 /* fill the descriptors */
468 sg = hwif->sg_table;
469 while (i && sg_dma_len(sg)) {
470 u32 cur_addr;
471 u32 cur_len;
472
473 cur_addr = sg_dma_address(sg);
474 cur_len = sg_dma_len(sg);
475
476 while (cur_len) {
477 u32 flags = DDMA_FLAGS_NOIE;
478 unsigned int tc = (cur_len < 0xfe00)? cur_len: 0xfe00;
479
480 if (++count >= PRD_ENTRIES) {
481 printk(KERN_WARNING "%s: DMA table too small\n",
482 drive->name);
483 goto use_pio_instead;
484 }
485
486 /* Lets enable intr for the last descriptor only */
487 if (1==i)
488 flags = DDMA_FLAGS_IE;
489 else
490 flags = DDMA_FLAGS_NOIE;
491
492 if (iswrite) {
493 if(!put_source_flags(ahwif->tx_chan,
494 (void*)(page_address(sg->page)
495 + sg->offset),
496 tc, flags)) {
497 printk(KERN_ERR "%s failed %d\n",
498 __FUNCTION__, __LINE__);
499 }
500 } else
501 {
502 if(!put_dest_flags(ahwif->rx_chan,
503 (void*)(page_address(sg->page)
504 + sg->offset),
505 tc, flags)) {
506 printk(KERN_ERR "%s failed %d\n",
507 __FUNCTION__, __LINE__);
508 }
509 }
510
511 cur_addr += tc;
512 cur_len -= tc;
513 }
514 sg++;
515 i--;
516 }
517
518 if (count)
519 return 1;
520
521use_pio_instead:
522 dma_unmap_sg(ahwif->dev,
523 hwif->sg_table,
524 hwif->sg_nents,
525 hwif->sg_dma_direction);
526
527 return 0; /* revert to PIO for this request */
528}
529
530static int auide_dma_end(ide_drive_t *drive)
531{
532 ide_hwif_t *hwif = HWIF(drive);
533 _auide_hwif *ahwif = (_auide_hwif*)hwif->hwif_data;
534
535 if (hwif->sg_nents) {
536 dma_unmap_sg(ahwif->dev, hwif->sg_table, hwif->sg_nents,
537 hwif->sg_dma_direction);
538 hwif->sg_nents = 0;
539 }
540
541 return 0;
542}
543
544static void auide_dma_start(ide_drive_t *drive )
545{
546// printk("%s\n", __FUNCTION__);
547}
548
549ide_startstop_t auide_dma_intr(ide_drive_t *drive)
550{
551 //printk("%s\n", __FUNCTION__);
552
553 u8 stat = 0, dma_stat = 0;
554
555 dma_stat = HWIF(drive)->ide_dma_end(drive);
556 stat = HWIF(drive)->INB(IDE_STATUS_REG); /* get drive status */
557 if (OK_STAT(stat,DRIVE_READY,drive->bad_wstat|DRQ_STAT)) {
558 if (!dma_stat) {
559 struct request *rq = HWGROUP(drive)->rq;
560
561 ide_end_request(drive, 1, rq->nr_sectors);
562 return ide_stopped;
563 }
564 printk(KERN_ERR "%s: dma_intr: bad DMA status (dma_stat=%x)\n",
565 drive->name, dma_stat);
566 }
567 return ide_error(drive, "dma_intr", stat);
568}
569
570static void auide_dma_exec_cmd(ide_drive_t *drive, u8 command)
571{
572 //printk("%s\n", __FUNCTION__);
573
574 /* issue cmd to drive */
575 ide_execute_command(drive, command, &auide_dma_intr,
576 (2*WAIT_CMD), NULL);
577}
578
579static int auide_dma_setup(ide_drive_t *drive)
580{
581// printk("%s\n", __FUNCTION__);
582
583 if (drive->media != ide_disk)
584 return 1;
585
586 if (!auide_build_dmatable(drive))
587 /* try PIO instead of DMA */
588 return 1;
589
590 drive->waiting_for_dma = 1;
591
592 return 0;
593}
594
595static int auide_dma_check(ide_drive_t *drive)
596{
597// printk("%s\n", __FUNCTION__);
598
599#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
600 if( !dbdma_init_done ){
601 auide_hwif.white_list = in_drive_list(drive->id,
602 dma_white_list);
603 auide_hwif.black_list = in_drive_list(drive->id,
604 dma_black_list);
605 auide_hwif.drive = drive;
606 auide_ddma_init(&auide_hwif);
607 dbdma_init_done = 1;
608 }
609#endif
610
611 /* Is the drive in our DMA black list? */
612 if ( auide_hwif.black_list ) {
613 drive->using_dma = 0;
614 printk("%s found in dma_blacklist[]! Disabling DMA.\n",
615 drive->id->model);
616 }
617 else
618 drive->using_dma = 1;
619
620 return HWIF(drive)->ide_dma_host_on(drive);
621}
622
623static int auide_dma_test_irq(ide_drive_t *drive)
624{
625// printk("%s\n", __FUNCTION__);
626
627 if (!drive->waiting_for_dma)
628 printk(KERN_WARNING "%s: ide_dma_test_irq \
629 called while not waiting\n", drive->name);
630
631 /* If dbdma didn't execute the STOP command yet, the
632 * active bit is still set
633 */
634 drive->waiting_for_dma++;
635 if (drive->waiting_for_dma >= DMA_WAIT_TIMEOUT) {
636 printk(KERN_WARNING "%s: timeout waiting for ddma to \
637 complete\n", drive->name);
638 return 1;
639 }
640 udelay(10);
641 return 0;
642}
643
644static int auide_dma_host_on(ide_drive_t *drive)
645{
646// printk("%s\n", __FUNCTION__);
647 return 0;
648}
649
650static int auide_dma_on(ide_drive_t *drive)
651{
652// printk("%s\n", __FUNCTION__);
653 drive->using_dma = 1;
654 return auide_dma_host_on(drive);
655}
656
657
658static int auide_dma_host_off(ide_drive_t *drive)
659{
660// printk("%s\n", __FUNCTION__);
661 return 0;
662}
663
664static int auide_dma_off_quietly(ide_drive_t *drive)
665{
666// printk("%s\n", __FUNCTION__);
667 drive->using_dma = 0;
668 return auide_dma_host_off(drive);
669}
670
671static int auide_dma_lostirq(ide_drive_t *drive)
672{
673// printk("%s\n", __FUNCTION__);
674
675 printk(KERN_ERR "%s: IRQ lost\n", drive->name);
676 return 0;
677}
678
679static void auide_ddma_tx_callback(int irq, void *param, struct pt_regs *regs)
680{
681// printk("%s\n", __FUNCTION__);
682
683 _auide_hwif *ahwif = (_auide_hwif*)param;
684 ahwif->drive->waiting_for_dma = 0;
685 return;
686}
687
688static void auide_ddma_rx_callback(int irq, void *param, struct pt_regs *regs)
689{
690// printk("%s\n", __FUNCTION__);
691
692 _auide_hwif *ahwif = (_auide_hwif*)param;
693 ahwif->drive->waiting_for_dma = 0;
694 return;
695}
696
697static int auide_dma_timeout(ide_drive_t *drive)
698{
699// printk("%s\n", __FUNCTION__);
700
701 printk(KERN_ERR "%s: DMA timeout occurred: ", drive->name);
702
703 if (HWIF(drive)->ide_dma_test_irq(drive))
704 return 0;
705
706 return HWIF(drive)->ide_dma_end(drive);
707}
708#endif /* end CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA */
709
710
711static int auide_ddma_init( _auide_hwif *auide )
712{
713// printk("%s\n", __FUNCTION__);
714
715 dbdev_tab_t source_dev_tab;
716#if defined(CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA)
717 dbdev_tab_t target_dev_tab;
718 ide_hwif_t *hwif = auide->hwif;
719 char warning_output [2][80];
720 int i;
721#endif
722
723 /* Add our custom device to DDMA device table */
724 /* Create our new device entries in the table */
725#if defined(CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA)
726 source_dev_tab.dev_id = AU1XXX_ATA_DDMA_REQ;
727
728 if( auide->white_list || auide->black_list ){
729 source_dev_tab.dev_tsize = 8;
730 source_dev_tab.dev_devwidth = 32;
731 source_dev_tab.dev_physaddr = (u32)AU1XXX_ATA_PHYS_ADDR;
732 source_dev_tab.dev_intlevel = 0;
733 source_dev_tab.dev_intpolarity = 0;
734
735 /* init device table for target - static bus controller - */
736 target_dev_tab.dev_id = DSCR_CMD0_ALWAYS;
737 target_dev_tab.dev_tsize = 8;
738 target_dev_tab.dev_devwidth = 32;
739 target_dev_tab.dev_physaddr = (u32)AU1XXX_ATA_PHYS_ADDR;
740 target_dev_tab.dev_intlevel = 0;
741 target_dev_tab.dev_intpolarity = 0;
742 target_dev_tab.dev_flags = DEV_FLAGS_ANYUSE;
743 }
744 else{
745 source_dev_tab.dev_tsize = 1;
746 source_dev_tab.dev_devwidth = 16;
747 source_dev_tab.dev_physaddr = (u32)AU1XXX_ATA_PHYS_ADDR;
748 source_dev_tab.dev_intlevel = 0;
749 source_dev_tab.dev_intpolarity = 0;
750
751 /* init device table for target - static bus controller - */
752 target_dev_tab.dev_id = DSCR_CMD0_ALWAYS;
753 target_dev_tab.dev_tsize = 1;
754 target_dev_tab.dev_devwidth = 16;
755 target_dev_tab.dev_physaddr = (u32)AU1XXX_ATA_PHYS_ADDR;
756 target_dev_tab.dev_intlevel = 0;
757 target_dev_tab.dev_intpolarity = 0;
758 target_dev_tab.dev_flags = DEV_FLAGS_ANYUSE;
759
760 sprintf(&warning_output[0][0],
761 "%s is not on ide driver white list.",
762 auide_hwif.drive->id->model);
763 for ( i=strlen(&warning_output[0][0]) ; i<76; i++ ){
764 sprintf(&warning_output[0][i]," ");
765 }
766
767 sprintf(&warning_output[1][0],
768 "To add %s please read 'Documentation/mips/AU1xxx_IDE.README'.",
769 auide_hwif.drive->id->model);
770 for ( i=strlen(&warning_output[1][0]) ; i<76; i++ ){
771 sprintf(&warning_output[1][i]," ");
772 }
773
774 printk("\n****************************************");
775 printk("****************************************\n");
776 printk("* %s *\n",&warning_output[0][0]);
777 printk("* Switch to safe MWDMA Mode! ");
778 printk(" *\n");
779 printk("* %s *\n",&warning_output[1][0]);
780 printk("****************************************");
781 printk("****************************************\n\n");
782 }
783#else
784 source_dev_tab.dev_id = DSCR_CMD0_ALWAYS;
785 source_dev_tab.dev_tsize = 8;
786 source_dev_tab.dev_devwidth = 32;
787 source_dev_tab.dev_physaddr = (u32)AU1XXX_ATA_PHYS_ADDR;
788 source_dev_tab.dev_intlevel = 0;
789 source_dev_tab.dev_intpolarity = 0;
790#endif
791
792#if CONFIG_BLK_DEV_IDE_AU1XXX_BURSTABLE_ON
793 /* set flags for tx channel */
794 source_dev_tab.dev_flags = DEV_FLAGS_OUT
795 | DEV_FLAGS_SYNC
796 | DEV_FLAGS_BURSTABLE;
797 auide->tx_dev_id = au1xxx_ddma_add_device( &source_dev_tab );
798 /* set flags for rx channel */
799 source_dev_tab.dev_flags = DEV_FLAGS_IN
800 | DEV_FLAGS_SYNC
801 | DEV_FLAGS_BURSTABLE;
802 auide->rx_dev_id = au1xxx_ddma_add_device( &source_dev_tab );
803#else
804 /* set flags for tx channel */
805 source_dev_tab.dev_flags = DEV_FLAGS_OUT | DEV_FLAGS_SYNC;
806 auide->tx_dev_id = au1xxx_ddma_add_device( &source_dev_tab );
807 /* set flags for rx channel */
808 source_dev_tab.dev_flags = DEV_FLAGS_IN | DEV_FLAGS_SYNC;
809 auide->rx_dev_id = au1xxx_ddma_add_device( &source_dev_tab );
810#endif
811
812#if defined(CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA)
813
814 auide->target_dev_id = au1xxx_ddma_add_device(&target_dev_tab);
815
816 /* Get a channel for TX */
817 auide->tx_chan = au1xxx_dbdma_chan_alloc(auide->target_dev_id,
818 auide->tx_dev_id,
819 auide_ddma_tx_callback,
820 (void*)auide);
821 /* Get a channel for RX */
822 auide->rx_chan = au1xxx_dbdma_chan_alloc(auide->rx_dev_id,
823 auide->target_dev_id,
824 auide_ddma_rx_callback,
825 (void*)auide);
826#else /* CONFIG_BLK_DEV_IDE_AU1XXX_PIO_DBDMA */
827 /*
828 * Note: if call back is not enabled, update ctp->cur_ptr manually
829 */
830 auide->tx_chan = au1xxx_dbdma_chan_alloc(DSCR_CMD0_ALWAYS,
831 auide->tx_dev_id,
832 NULL,
833 (void*)auide);
834 auide->rx_chan = au1xxx_dbdma_chan_alloc(auide->rx_dev_id,
835 DSCR_CMD0_ALWAYS,
836 NULL,
837 (void*)auide);
838#endif
839 auide->tx_desc_head = (void*)au1xxx_dbdma_ring_alloc(auide->tx_chan,
840 NUM_DESCRIPTORS);
841 auide->rx_desc_head = (void*)au1xxx_dbdma_ring_alloc(auide->rx_chan,
842 NUM_DESCRIPTORS);
843
844#if defined(CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA)
845 hwif->dmatable_cpu = dma_alloc_coherent(auide->dev,
846 PRD_ENTRIES * PRD_BYTES, /* 1 Page */
847 &hwif->dmatable_dma, GFP_KERNEL);
848
849 auide->sg_table = kmalloc(sizeof(struct scatterlist) * PRD_ENTRIES,
850 GFP_KERNEL|GFP_DMA);
851 if (auide->sg_table == NULL) {
852 return -ENOMEM;
853 }
854#endif
855 au1xxx_dbdma_start( auide->tx_chan );
856 au1xxx_dbdma_start( auide->rx_chan );
857 return 0;
858}
859
860static void auide_setup_ports(hw_regs_t *hw, _auide_hwif *ahwif)
861{
862 int i;
863#define ide_ioreg_t unsigned long
864 ide_ioreg_t *ata_regs = hw->io_ports;
865
866 /* fixme */
867 for (i = 0; i < IDE_CONTROL_OFFSET; i++) {
868 *ata_regs++ = (ide_ioreg_t) ahwif->regbase
869 + (ide_ioreg_t)(i << AU1XXX_ATA_REG_OFFSET);
870 }
871
872 /* set the Alternative Status register */
873 *ata_regs = (ide_ioreg_t) ahwif->regbase
874 + (ide_ioreg_t)(14 << AU1XXX_ATA_REG_OFFSET);
875}
876
877static int au_ide_probe(struct device *dev)
878{
879 struct platform_device *pdev = to_platform_device(dev);
880 _auide_hwif *ahwif = &auide_hwif;
881 ide_hwif_t *hwif;
882 struct resource *res;
883 int ret = 0;
884
885#if defined(CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA)
886 char *mode = "MWDMA2";
887#elif defined(CONFIG_BLK_DEV_IDE_AU1XXX_PIO_DBDMA)
888 char *mode = "PIO+DDMA(offload)";
889#endif
890
891 memset(&auide_hwif, 0, sizeof(_auide_hwif));
892 auide_hwif.dev = 0;
893
894 ahwif->dev = dev;
895 ahwif->irq = platform_get_irq(pdev, 0);
896
897 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
898
899 if (res == NULL) {
900 pr_debug("%s %d: no base address\n", DRV_NAME, pdev->id);
901 ret = -ENODEV;
902 goto out;
903 }
904
905 if (!request_mem_region (res->start, res->end-res->start, pdev->name)) {
906 pr_debug("%s: request_mem_region failed\n", DRV_NAME);
907 ret = -EBUSY;
908 goto out;
909 }
910
911 ahwif->regbase = (u32)ioremap(res->start, res->end-res->start);
912 if (ahwif->regbase == 0) {
913 ret = -ENOMEM;
914 goto out;
915 }
916
917 hwif = &ide_hwifs[pdev->id];
918 hw_regs_t *hw = &hwif->hw;
919 hwif->irq = hw->irq = ahwif->irq;
920 hwif->chipset = ide_au1xxx;
921
922 auide_setup_ports(hw, ahwif);
923 memcpy(hwif->io_ports, hw->io_ports, sizeof(hwif->io_ports));
924
925#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_SEQTS_PER_RQ
926 hwif->rqsize = CONFIG_BLK_DEV_IDE_AU1XXX_SEQTS_PER_RQ;
927 hwif->rqsize = ((hwif->rqsize > AU1XXX_ATA_RQSIZE)
928 || (hwif->rqsize < 32)) ? AU1XXX_ATA_RQSIZE : hwif->rqsize;
929#else /* if kernel config is not set */
930 hwif->rqsize = AU1XXX_ATA_RQSIZE;
931#endif
932
933 hwif->ultra_mask = 0x0; /* Disable Ultra DMA */
934#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
935 hwif->mwdma_mask = 0x07; /* Multimode-2 DMA */
936 hwif->swdma_mask = 0x07;
937#else
938 hwif->mwdma_mask = 0x0;
939 hwif->swdma_mask = 0x0;
940#endif
941 //hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET];
942 hwif->noprobe = 0;
943 hwif->drives[0].unmask = 1;
944 hwif->drives[1].unmask = 1;
945
946 /* hold should be on in all cases */
947 hwif->hold = 1;
948 hwif->mmio = 2;
949
950 /* set up local I/O function entry points */
951 hwif->INB = auide_inb;
952 hwif->INW = auide_inw;
953 hwif->INL = auide_inl;
954 hwif->INSW = auide_insw;
955 hwif->INSL = auide_insl;
956 hwif->OUTB = auide_outb;
957 hwif->OUTBSYNC = auide_outbsync;
958 hwif->OUTW = auide_outw;
959 hwif->OUTL = auide_outl;
960 hwif->OUTSW = auide_outsw;
961 hwif->OUTSL = auide_outsl;
962
963 hwif->tuneproc = &auide_tune_drive;
964 hwif->speedproc = &auide_tune_chipset;
965
966#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
967 hwif->ide_dma_off_quietly = &auide_dma_off_quietly;
968 hwif->ide_dma_timeout = &auide_dma_timeout;
969
970 hwif->ide_dma_check = &auide_dma_check;
971 hwif->dma_exec_cmd = &auide_dma_exec_cmd;
972 hwif->dma_start = &auide_dma_start;
973 hwif->ide_dma_end = &auide_dma_end;
974 hwif->dma_setup = &auide_dma_setup;
975 hwif->ide_dma_test_irq = &auide_dma_test_irq;
976 hwif->ide_dma_host_off = &auide_dma_host_off;
977 hwif->ide_dma_host_on = &auide_dma_host_on;
978 hwif->ide_dma_lostirq = &auide_dma_lostirq;
979 hwif->ide_dma_on = &auide_dma_on;
980
981 hwif->autodma = 1;
982 hwif->drives[0].autodma = hwif->autodma;
983 hwif->drives[1].autodma = hwif->autodma;
984 hwif->atapi_dma = 1;
985 hwif->drives[0].using_dma = 1;
986 hwif->drives[1].using_dma = 1;
987#else /* !CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA */
988 hwif->autodma = 0;
989 hwif->channel = 0;
990 hwif->hold = 1;
991 hwif->select_data = 0; /* no chipset-specific code */
992 hwif->config_data = 0; /* no chipset-specific code */
993
994 hwif->drives[0].autodma = 0;
995 hwif->drives[0].drive_data = 0; /* no drive data */
996 hwif->drives[0].using_dma = 0;
997 hwif->drives[0].waiting_for_dma = 0;
998 hwif->drives[0].autotune = 1; /* 1=autotune, 2=noautotune, 0=default */
999 /* secondary hdd not supported */
1000 hwif->drives[1].autodma = 0;
1001
1002 hwif->drives[1].drive_data = 0;
1003 hwif->drives[1].using_dma = 0;
1004 hwif->drives[1].waiting_for_dma = 0;
1005 hwif->drives[1].autotune = 2; /* 1=autotune, 2=noautotune, 0=default */
1006#endif
1007 hwif->drives[0].io_32bit = 0; /* 0=16-bit, 1=32-bit, 2/3=32bit+sync */
1008 hwif->drives[1].io_32bit = 0; /* 0=16-bit, 1=32-bit, 2/3=32bit+sync */
1009
1010 /*Register Driver with PM Framework*/
1011#ifdef CONFIG_PM
1012 auide_hwif.pm.lock = SPIN_LOCK_UNLOCKED;
1013 auide_hwif.pm.stopped = 0;
1014
1015 auide_hwif.pm.dev = new_au1xxx_power_device( "ide",
1016 &au1200ide_pm_callback,
1017 NULL);
1018 if ( auide_hwif.pm.dev == NULL )
1019 printk(KERN_INFO "Unable to create a power management \
1020 device entry for the au1200-IDE.\n");
1021 else
1022 printk(KERN_INFO "Power management device entry for the \
1023 au1200-IDE loaded.\n");
1024#endif
1025
1026 auide_hwif.hwif = hwif;
1027 hwif->hwif_data = &auide_hwif;
1028
1029#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_PIO_DBDMA
1030 auide_ddma_init(&auide_hwif);
1031 dbdma_init_done = 1;
1032#endif
1033
1034 probe_hwif_init(hwif);
1035 dev_set_drvdata(dev, hwif);
1036
1037 printk(KERN_INFO "Au1xxx IDE(builtin) configured for %s\n", mode );
1038
1039out:
1040 return ret;
1041}
1042
1043static int au_ide_remove(struct device *dev)
1044{
1045 struct platform_device *pdev = to_platform_device(dev);
1046 struct resource *res;
1047 ide_hwif_t *hwif = dev_get_drvdata(dev);
1048 _auide_hwif *ahwif = &auide_hwif;
1049
1050 ide_unregister(hwif - ide_hwifs);
1051
1052 iounmap((void *)ahwif->regbase);
1053
1054 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1055 release_mem_region(res->start, res->end - res->start);
1056
1057 return 0;
1058}
1059
1060static struct device_driver au1200_ide_driver = {
1061 .name = "au1200-ide",
1062 .bus = &platform_bus_type,
1063 .probe = au_ide_probe,
1064 .remove = au_ide_remove,
1065};
1066
1067static int __init au_ide_init(void)
1068{
1069 return driver_register(&au1200_ide_driver);
1070}
1071
1072static void __init au_ide_exit(void)
1073{
1074 driver_unregister(&au1200_ide_driver);
1075}
1076
1077#ifdef CONFIG_PM
1078int au1200ide_pm_callback( au1xxx_power_dev_t *dev,\
1079 au1xxx_request_t request, void *data) {
1080
1081 unsigned int d, err = 0;
1082 unsigned long flags;
1083
1084 spin_lock_irqsave(auide_hwif.pm.lock, flags);
1085
1086 switch (request){
1087 case AU1XXX_PM_SLEEP:
1088 err = au1xxxide_pm_sleep(dev);
1089 break;
1090 case AU1XXX_PM_WAKEUP:
1091 d = *((unsigned int*)data);
1092 if ( d > 0 && d <= 99) {
1093 err = au1xxxide_pm_standby(dev);
1094 }
1095 else {
1096 err = au1xxxide_pm_resume(dev);
1097 }
1098 break;
1099 case AU1XXX_PM_GETSTATUS:
1100 err = au1xxxide_pm_getstatus(dev);
1101 break;
1102 case AU1XXX_PM_ACCESS:
1103 err = au1xxxide_pm_access(dev);
1104 break;
1105 case AU1XXX_PM_IDLE:
1106 err = au1xxxide_pm_idle(dev);
1107 break;
1108 case AU1XXX_PM_CLEANUP:
1109 err = au1xxxide_pm_cleanup(dev);
1110 break;
1111 default:
1112 err = -1;
1113 break;
1114 }
1115
1116 spin_unlock_irqrestore(auide_hwif.pm.lock, flags);
1117
1118 return err;
1119}
1120
1121static int au1xxxide_pm_standby( au1xxx_power_dev_t *dev ) {
1122 return 0;
1123}
1124
1125static int au1xxxide_pm_sleep( au1xxx_power_dev_t *dev ) {
1126
1127 int retval;
1128 ide_hwif_t *hwif = auide_hwif.hwif;
1129 struct request rq;
1130 struct request_pm_state rqpm;
1131 ide_task_t args;
1132
1133 if(auide_hwif.pm.stopped)
1134 return -1;
1135
1136 /*
1137 * wait until hard disc is ready
1138 */
1139 if ( wait_for_ready(&hwif->drives[0], 35000) ) {
1140 printk("Wait for drive sleep timeout!\n");
1141 retval = -1;
1142 }
1143
1144 /*
1145 * sequenz to tell the high level ide driver that pm is resuming
1146 */
1147 memset(&rq, 0, sizeof(rq));
1148 memset(&rqpm, 0, sizeof(rqpm));
1149 memset(&args, 0, sizeof(args));
1150 rq.flags = REQ_PM_SUSPEND;
1151 rq.special = &args;
1152 rq.pm = &rqpm;
1153 rqpm.pm_step = ide_pm_state_start_suspend;
1154 rqpm.pm_state = PMSG_SUSPEND;
1155
1156 retval = ide_do_drive_cmd(&hwif->drives[0], &rq, ide_wait);
1157
1158 if (wait_for_ready (&hwif->drives[0], 35000)) {
1159 printk("Wait for drive sleep timeout!\n");
1160 retval = -1;
1161 }
1162
1163 /*
1164 * stop dbdma channels
1165 */
1166 au1xxx_dbdma_reset(auide_hwif.tx_chan);
1167 au1xxx_dbdma_reset(auide_hwif.rx_chan);
1168
1169 auide_hwif.pm.stopped = 1;
1170
1171 return retval;
1172}
1173
1174static int au1xxxide_pm_resume( au1xxx_power_dev_t *dev ) {
1175
1176 int retval;
1177 ide_hwif_t *hwif = auide_hwif.hwif;
1178 struct request rq;
1179 struct request_pm_state rqpm;
1180 ide_task_t args;
1181
1182 if(!auide_hwif.pm.stopped)
1183 return -1;
1184
1185 /*
1186 * start dbdma channels
1187 */
1188 au1xxx_dbdma_start(auide_hwif.tx_chan);
1189 au1xxx_dbdma_start(auide_hwif.rx_chan);
1190
1191 /*
1192 * wait until hard disc is ready
1193 */
1194 if (wait_for_ready ( &hwif->drives[0], 35000)) {
1195 printk("Wait for drive wake up timeout!\n");
1196 retval = -1;
1197 }
1198
1199 /*
1200 * sequenz to tell the high level ide driver that pm is resuming
1201 */
1202 memset(&rq, 0, sizeof(rq));
1203 memset(&rqpm, 0, sizeof(rqpm));
1204 memset(&args, 0, sizeof(args));
1205 rq.flags = REQ_PM_RESUME;
1206 rq.special = &args;
1207 rq.pm = &rqpm;
1208 rqpm.pm_step = ide_pm_state_start_resume;
1209 rqpm.pm_state = PMSG_ON;
1210
1211 retval = ide_do_drive_cmd(&hwif->drives[0], &rq, ide_head_wait);
1212
1213 /*
1214 * wait for hard disc
1215 */
1216 if ( wait_for_ready(&hwif->drives[0], 35000) ) {
1217 printk("Wait for drive wake up timeout!\n");
1218 retval = -1;
1219 }
1220
1221 auide_hwif.pm.stopped = 0;
1222
1223 return retval;
1224}
1225
1226static int au1xxxide_pm_getstatus( au1xxx_power_dev_t *dev ) {
1227 return dev->cur_state;
1228}
1229
1230static int au1xxxide_pm_access( au1xxx_power_dev_t *dev ) {
1231 if (dev->cur_state != AWAKE_STATE)
1232 return 0;
1233 else
1234 return -1;
1235}
1236
1237static int au1xxxide_pm_idle( au1xxx_power_dev_t *dev ) {
1238 return 0;
1239}
1240
1241static int au1xxxide_pm_cleanup( au1xxx_power_dev_t *dev ) {
1242 return 0;
1243}
1244#endif /* CONFIG_PM */
1245
1246MODULE_LICENSE("GPL");
1247MODULE_DESCRIPTION("AU1200 IDE driver");
1248
1249module_init(au_ide_init);
1250module_exit(au_ide_exit);
diff --git a/drivers/ieee1394/dv1394.c b/drivers/ieee1394/dv1394.c
index e34730c7a874..cbbbe14b8849 100644
--- a/drivers/ieee1394/dv1394.c
+++ b/drivers/ieee1394/dv1394.c
@@ -2361,7 +2361,7 @@ static void dv1394_add_host (struct hpsb_host *host)
2361 2361
2362 ohci = (struct ti_ohci *)host->hostdata; 2362 ohci = (struct ti_ohci *)host->hostdata;
2363 2363
2364 class_device_create(hpsb_protocol_class, MKDEV( 2364 class_device_create(hpsb_protocol_class, NULL, MKDEV(
2365 IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_DV1394 * 16 + (id<<2)), 2365 IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_DV1394 * 16 + (id<<2)),
2366 NULL, "dv1394-%d", id); 2366 NULL, "dv1394-%d", id);
2367 devfs_mk_dir("ieee1394/dv/host%d", id); 2367 devfs_mk_dir("ieee1394/dv/host%d", id);
diff --git a/drivers/ieee1394/eth1394.c b/drivers/ieee1394/eth1394.c
index 4802bbbb6dc9..c9e92d85c893 100644
--- a/drivers/ieee1394/eth1394.c
+++ b/drivers/ieee1394/eth1394.c
@@ -1630,7 +1630,7 @@ static void ether1394_complete_cb(void *__ptask)
1630/* Transmit a packet (called by kernel) */ 1630/* Transmit a packet (called by kernel) */
1631static int ether1394_tx (struct sk_buff *skb, struct net_device *dev) 1631static int ether1394_tx (struct sk_buff *skb, struct net_device *dev)
1632{ 1632{
1633 int kmflags = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL; 1633 gfp_t kmflags = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;
1634 struct eth1394hdr *eth; 1634 struct eth1394hdr *eth;
1635 struct eth1394_priv *priv = netdev_priv(dev); 1635 struct eth1394_priv *priv = netdev_priv(dev);
1636 int proto; 1636 int proto;
diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c
index 347ece6b583c..7fff5a1d2ea4 100644
--- a/drivers/ieee1394/nodemgr.c
+++ b/drivers/ieee1394/nodemgr.c
@@ -1292,7 +1292,7 @@ static void nodemgr_suspend_ne(struct node_entry *ne)
1292 1292
1293 if (ud->device.driver && 1293 if (ud->device.driver &&
1294 (!ud->device.driver->suspend || 1294 (!ud->device.driver->suspend ||
1295 ud->device.driver->suspend(&ud->device, PMSG_SUSPEND, 0))) 1295 ud->device.driver->suspend(&ud->device, PMSG_SUSPEND)))
1296 device_release_driver(&ud->device); 1296 device_release_driver(&ud->device);
1297 } 1297 }
1298 up_write(&ne->device.bus->subsys.rwsem); 1298 up_write(&ne->device.bus->subsys.rwsem);
@@ -1315,7 +1315,7 @@ static void nodemgr_resume_ne(struct node_entry *ne)
1315 continue; 1315 continue;
1316 1316
1317 if (ud->device.driver && ud->device.driver->resume) 1317 if (ud->device.driver && ud->device.driver->resume)
1318 ud->device.driver->resume(&ud->device, 0); 1318 ud->device.driver->resume(&ud->device);
1319 } 1319 }
1320 up_read(&ne->device.bus->subsys.rwsem); 1320 up_read(&ne->device.bus->subsys.rwsem);
1321 1321
diff --git a/drivers/ieee1394/raw1394.c b/drivers/ieee1394/raw1394.c
index 0470f77a9cd1..24411e666b21 100644
--- a/drivers/ieee1394/raw1394.c
+++ b/drivers/ieee1394/raw1394.c
@@ -2912,7 +2912,7 @@ static int __init init_raw1394(void)
2912 2912
2913 hpsb_register_highlevel(&raw1394_highlevel); 2913 hpsb_register_highlevel(&raw1394_highlevel);
2914 2914
2915 if (IS_ERR(class_device_create(hpsb_protocol_class, MKDEV( 2915 if (IS_ERR(class_device_create(hpsb_protocol_class, NULL, MKDEV(
2916 IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16), 2916 IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16),
2917 NULL, RAW1394_DEVICE_NAME))) { 2917 NULL, RAW1394_DEVICE_NAME))) {
2918 ret = -EFAULT; 2918 ret = -EFAULT;
diff --git a/drivers/ieee1394/video1394.c b/drivers/ieee1394/video1394.c
index 11be9c9c82a8..23911da50154 100644
--- a/drivers/ieee1394/video1394.c
+++ b/drivers/ieee1394/video1394.c
@@ -1370,7 +1370,7 @@ static void video1394_add_host (struct hpsb_host *host)
1370 hpsb_set_hostinfo_key(&video1394_highlevel, host, ohci->host->id); 1370 hpsb_set_hostinfo_key(&video1394_highlevel, host, ohci->host->id);
1371 1371
1372 minor = IEEE1394_MINOR_BLOCK_VIDEO1394 * 16 + ohci->host->id; 1372 minor = IEEE1394_MINOR_BLOCK_VIDEO1394 * 16 + ohci->host->id;
1373 class_device_create(hpsb_protocol_class, MKDEV( 1373 class_device_create(hpsb_protocol_class, NULL, MKDEV(
1374 IEEE1394_MAJOR, minor), 1374 IEEE1394_MAJOR, minor),
1375 NULL, "%s-%d", VIDEO1394_DRIVER_NAME, ohci->host->id); 1375 NULL, "%s-%d", VIDEO1394_DRIVER_NAME, ohci->host->id);
1376 devfs_mk_cdev(MKDEV(IEEE1394_MAJOR, minor), 1376 devfs_mk_cdev(MKDEV(IEEE1394_MAJOR, minor),
diff --git a/drivers/infiniband/core/agent.c b/drivers/infiniband/core/agent.c
index 5ac86f566dc0..0c3c6952faae 100644
--- a/drivers/infiniband/core/agent.c
+++ b/drivers/infiniband/core/agent.c
@@ -37,58 +37,41 @@
37 * $Id: agent.c 1389 2004-12-27 22:56:47Z roland $ 37 * $Id: agent.c 1389 2004-12-27 22:56:47Z roland $
38 */ 38 */
39 39
40#include <linux/dma-mapping.h> 40#include "agent.h"
41 41#include "smi.h"
42#include <asm/bug.h>
43 42
44#include <rdma/ib_smi.h> 43#define SPFX "ib_agent: "
45 44
46#include "smi.h" 45struct ib_agent_port_private {
47#include "agent_priv.h" 46 struct list_head port_list;
48#include "mad_priv.h" 47 struct ib_mad_agent *agent[2];
49#include "agent.h" 48};
50 49
51spinlock_t ib_agent_port_list_lock; 50static DEFINE_SPINLOCK(ib_agent_port_list_lock);
52static LIST_HEAD(ib_agent_port_list); 51static LIST_HEAD(ib_agent_port_list);
53 52
54/* 53static struct ib_agent_port_private *
55 * Caller must hold ib_agent_port_list_lock 54__ib_get_agent_port(struct ib_device *device, int port_num)
56 */
57static inline struct ib_agent_port_private *
58__ib_get_agent_port(struct ib_device *device, int port_num,
59 struct ib_mad_agent *mad_agent)
60{ 55{
61 struct ib_agent_port_private *entry; 56 struct ib_agent_port_private *entry;
62 57
63 BUG_ON(!(!!device ^ !!mad_agent)); /* Exactly one MUST be (!NULL) */ 58 list_for_each_entry(entry, &ib_agent_port_list, port_list) {
64 59 if (entry->agent[0]->device == device &&
65 if (device) { 60 entry->agent[0]->port_num == port_num)
66 list_for_each_entry(entry, &ib_agent_port_list, port_list) { 61 return entry;
67 if (entry->smp_agent->device == device &&
68 entry->port_num == port_num)
69 return entry;
70 }
71 } else {
72 list_for_each_entry(entry, &ib_agent_port_list, port_list) {
73 if ((entry->smp_agent == mad_agent) ||
74 (entry->perf_mgmt_agent == mad_agent))
75 return entry;
76 }
77 } 62 }
78 return NULL; 63 return NULL;
79} 64}
80 65
81static inline struct ib_agent_port_private * 66static struct ib_agent_port_private *
82ib_get_agent_port(struct ib_device *device, int port_num, 67ib_get_agent_port(struct ib_device *device, int port_num)
83 struct ib_mad_agent *mad_agent)
84{ 68{
85 struct ib_agent_port_private *entry; 69 struct ib_agent_port_private *entry;
86 unsigned long flags; 70 unsigned long flags;
87 71
88 spin_lock_irqsave(&ib_agent_port_list_lock, flags); 72 spin_lock_irqsave(&ib_agent_port_list_lock, flags);
89 entry = __ib_get_agent_port(device, port_num, mad_agent); 73 entry = __ib_get_agent_port(device, port_num);
90 spin_unlock_irqrestore(&ib_agent_port_list_lock, flags); 74 spin_unlock_irqrestore(&ib_agent_port_list_lock, flags);
91
92 return entry; 75 return entry;
93} 76}
94 77
@@ -100,192 +83,76 @@ int smi_check_local_dr_smp(struct ib_smp *smp,
100 83
101 if (smp->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) 84 if (smp->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
102 return 1; 85 return 1;
103 port_priv = ib_get_agent_port(device, port_num, NULL); 86
87 port_priv = ib_get_agent_port(device, port_num);
104 if (!port_priv) { 88 if (!port_priv) {
105 printk(KERN_DEBUG SPFX "smi_check_local_dr_smp %s port %d " 89 printk(KERN_DEBUG SPFX "smi_check_local_dr_smp %s port %d "
106 "not open\n", 90 "not open\n", device->name, port_num);
107 device->name, port_num);
108 return 1; 91 return 1;
109 } 92 }
110 93
111 return smi_check_local_smp(port_priv->smp_agent, smp); 94 return smi_check_local_smp(port_priv->agent[0], smp);
112} 95}
113 96
114static int agent_mad_send(struct ib_mad_agent *mad_agent, 97int agent_send_response(struct ib_mad *mad, struct ib_grh *grh,
115 struct ib_agent_port_private *port_priv, 98 struct ib_wc *wc, struct ib_device *device,
116 struct ib_mad_private *mad_priv, 99 int port_num, int qpn)
117 struct ib_grh *grh,
118 struct ib_wc *wc)
119{ 100{
120 struct ib_agent_send_wr *agent_send_wr; 101 struct ib_agent_port_private *port_priv;
121 struct ib_sge gather_list; 102 struct ib_mad_agent *agent;
122 struct ib_send_wr send_wr; 103 struct ib_mad_send_buf *send_buf;
123 struct ib_send_wr *bad_send_wr; 104 struct ib_ah *ah;
124 struct ib_ah_attr ah_attr; 105 int ret;
125 unsigned long flags;
126 int ret = 1;
127
128 agent_send_wr = kmalloc(sizeof(*agent_send_wr), GFP_KERNEL);
129 if (!agent_send_wr)
130 goto out;
131 agent_send_wr->mad = mad_priv;
132
133 gather_list.addr = dma_map_single(mad_agent->device->dma_device,
134 &mad_priv->mad,
135 sizeof(mad_priv->mad),
136 DMA_TO_DEVICE);
137 gather_list.length = sizeof(mad_priv->mad);
138 gather_list.lkey = mad_agent->mr->lkey;
139
140 send_wr.next = NULL;
141 send_wr.opcode = IB_WR_SEND;
142 send_wr.sg_list = &gather_list;
143 send_wr.num_sge = 1;
144 send_wr.wr.ud.remote_qpn = wc->src_qp; /* DQPN */
145 send_wr.wr.ud.timeout_ms = 0;
146 send_wr.send_flags = IB_SEND_SIGNALED | IB_SEND_SOLICITED;
147 106
148 ah_attr.dlid = wc->slid; 107 port_priv = ib_get_agent_port(device, port_num);
149 ah_attr.port_num = mad_agent->port_num; 108 if (!port_priv) {
150 ah_attr.src_path_bits = wc->dlid_path_bits; 109 printk(KERN_ERR SPFX "Unable to find port agent\n");
151 ah_attr.sl = wc->sl; 110 return -ENODEV;
152 ah_attr.static_rate = 0;
153 ah_attr.ah_flags = 0; /* No GRH */
154 if (mad_priv->mad.mad.mad_hdr.mgmt_class == IB_MGMT_CLASS_PERF_MGMT) {
155 if (wc->wc_flags & IB_WC_GRH) {
156 ah_attr.ah_flags = IB_AH_GRH;
157 /* Should sgid be looked up ? */
158 ah_attr.grh.sgid_index = 0;
159 ah_attr.grh.hop_limit = grh->hop_limit;
160 ah_attr.grh.flow_label = be32_to_cpu(
161 grh->version_tclass_flow) & 0xfffff;
162 ah_attr.grh.traffic_class = (be32_to_cpu(
163 grh->version_tclass_flow) >> 20) & 0xff;
164 memcpy(ah_attr.grh.dgid.raw,
165 grh->sgid.raw,
166 sizeof(ah_attr.grh.dgid));
167 }
168 } 111 }
169 112
170 agent_send_wr->ah = ib_create_ah(mad_agent->qp->pd, &ah_attr); 113 agent = port_priv->agent[qpn];
171 if (IS_ERR(agent_send_wr->ah)) { 114 ah = ib_create_ah_from_wc(agent->qp->pd, wc, grh, port_num);
172 printk(KERN_ERR SPFX "No memory for address handle\n"); 115 if (IS_ERR(ah)) {
173 kfree(agent_send_wr); 116 ret = PTR_ERR(ah);
174 goto out; 117 printk(KERN_ERR SPFX "ib_create_ah_from_wc error:%d\n", ret);
118 return ret;
175 } 119 }
176 120
177 send_wr.wr.ud.ah = agent_send_wr->ah; 121 send_buf = ib_create_send_mad(agent, wc->src_qp, wc->pkey_index, 0,
178 if (mad_priv->mad.mad.mad_hdr.mgmt_class == IB_MGMT_CLASS_PERF_MGMT) { 122 IB_MGMT_MAD_HDR, IB_MGMT_MAD_DATA,
179 send_wr.wr.ud.pkey_index = wc->pkey_index; 123 GFP_KERNEL);
180 send_wr.wr.ud.remote_qkey = IB_QP1_QKEY; 124 if (IS_ERR(send_buf)) {
181 } else { /* for SMPs */ 125 ret = PTR_ERR(send_buf);
182 send_wr.wr.ud.pkey_index = 0; 126 printk(KERN_ERR SPFX "ib_create_send_mad error:%d\n", ret);
183 send_wr.wr.ud.remote_qkey = 0; 127 goto err1;
184 } 128 }
185 send_wr.wr.ud.mad_hdr = &mad_priv->mad.mad.mad_hdr;
186 send_wr.wr_id = (unsigned long)agent_send_wr;
187 129
188 pci_unmap_addr_set(agent_send_wr, mapping, gather_list.addr); 130 memcpy(send_buf->mad, mad, sizeof *mad);
189 131 send_buf->ah = ah;
190 /* Send */ 132 if ((ret = ib_post_send_mad(send_buf, NULL))) {
191 spin_lock_irqsave(&port_priv->send_list_lock, flags); 133 printk(KERN_ERR SPFX "ib_post_send_mad error:%d\n", ret);
192 if (ib_post_send_mad(mad_agent, &send_wr, &bad_send_wr)) { 134 goto err2;
193 spin_unlock_irqrestore(&port_priv->send_list_lock, flags);
194 dma_unmap_single(mad_agent->device->dma_device,
195 pci_unmap_addr(agent_send_wr, mapping),
196 sizeof(mad_priv->mad),
197 DMA_TO_DEVICE);
198 ib_destroy_ah(agent_send_wr->ah);
199 kfree(agent_send_wr);
200 } else {
201 list_add_tail(&agent_send_wr->send_list,
202 &port_priv->send_posted_list);
203 spin_unlock_irqrestore(&port_priv->send_list_lock, flags);
204 ret = 0;
205 } 135 }
206 136 return 0;
207out: 137err2:
138 ib_free_send_mad(send_buf);
139err1:
140 ib_destroy_ah(ah);
208 return ret; 141 return ret;
209} 142}
210 143
211int agent_send(struct ib_mad_private *mad,
212 struct ib_grh *grh,
213 struct ib_wc *wc,
214 struct ib_device *device,
215 int port_num)
216{
217 struct ib_agent_port_private *port_priv;
218 struct ib_mad_agent *mad_agent;
219
220 port_priv = ib_get_agent_port(device, port_num, NULL);
221 if (!port_priv) {
222 printk(KERN_DEBUG SPFX "agent_send %s port %d not open\n",
223 device->name, port_num);
224 return 1;
225 }
226
227 /* Get mad agent based on mgmt_class in MAD */
228 switch (mad->mad.mad.mad_hdr.mgmt_class) {
229 case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
230 case IB_MGMT_CLASS_SUBN_LID_ROUTED:
231 mad_agent = port_priv->smp_agent;
232 break;
233 case IB_MGMT_CLASS_PERF_MGMT:
234 mad_agent = port_priv->perf_mgmt_agent;
235 break;
236 default:
237 return 1;
238 }
239
240 return agent_mad_send(mad_agent, port_priv, mad, grh, wc);
241}
242
243static void agent_send_handler(struct ib_mad_agent *mad_agent, 144static void agent_send_handler(struct ib_mad_agent *mad_agent,
244 struct ib_mad_send_wc *mad_send_wc) 145 struct ib_mad_send_wc *mad_send_wc)
245{ 146{
246 struct ib_agent_port_private *port_priv; 147 ib_destroy_ah(mad_send_wc->send_buf->ah);
247 struct ib_agent_send_wr *agent_send_wr; 148 ib_free_send_mad(mad_send_wc->send_buf);
248 unsigned long flags;
249
250 /* Find matching MAD agent */
251 port_priv = ib_get_agent_port(NULL, 0, mad_agent);
252 if (!port_priv) {
253 printk(KERN_ERR SPFX "agent_send_handler: no matching MAD "
254 "agent %p\n", mad_agent);
255 return;
256 }
257
258 agent_send_wr = (struct ib_agent_send_wr *)(unsigned long)mad_send_wc->wr_id;
259 spin_lock_irqsave(&port_priv->send_list_lock, flags);
260 /* Remove completed send from posted send MAD list */
261 list_del(&agent_send_wr->send_list);
262 spin_unlock_irqrestore(&port_priv->send_list_lock, flags);
263
264 dma_unmap_single(mad_agent->device->dma_device,
265 pci_unmap_addr(agent_send_wr, mapping),
266 sizeof(agent_send_wr->mad->mad),
267 DMA_TO_DEVICE);
268
269 ib_destroy_ah(agent_send_wr->ah);
270
271 /* Release allocated memory */
272 kmem_cache_free(ib_mad_cache, agent_send_wr->mad);
273 kfree(agent_send_wr);
274} 149}
275 150
276int ib_agent_port_open(struct ib_device *device, int port_num) 151int ib_agent_port_open(struct ib_device *device, int port_num)
277{ 152{
278 int ret;
279 struct ib_agent_port_private *port_priv; 153 struct ib_agent_port_private *port_priv;
280 unsigned long flags; 154 unsigned long flags;
281 155 int ret;
282 /* First, check if port already open for SMI */
283 port_priv = ib_get_agent_port(device, port_num, NULL);
284 if (port_priv) {
285 printk(KERN_DEBUG SPFX "%s port %d already open\n",
286 device->name, port_num);
287 return 0;
288 }
289 156
290 /* Create new device info */ 157 /* Create new device info */
291 port_priv = kmalloc(sizeof *port_priv, GFP_KERNEL); 158 port_priv = kmalloc(sizeof *port_priv, GFP_KERNEL);
@@ -294,32 +161,25 @@ int ib_agent_port_open(struct ib_device *device, int port_num)
294 ret = -ENOMEM; 161 ret = -ENOMEM;
295 goto error1; 162 goto error1;
296 } 163 }
297
298 memset(port_priv, 0, sizeof *port_priv); 164 memset(port_priv, 0, sizeof *port_priv);
299 port_priv->port_num = port_num;
300 spin_lock_init(&port_priv->send_list_lock);
301 INIT_LIST_HEAD(&port_priv->send_posted_list);
302 165
303 /* Obtain send only MAD agent for SM class (SMI QP) */ 166 /* Obtain send only MAD agent for SMI QP */
304 port_priv->smp_agent = ib_register_mad_agent(device, port_num, 167 port_priv->agent[0] = ib_register_mad_agent(device, port_num,
305 IB_QPT_SMI, 168 IB_QPT_SMI, NULL, 0,
306 NULL, 0,
307 &agent_send_handler, 169 &agent_send_handler,
308 NULL, NULL); 170 NULL, NULL);
309 171 if (IS_ERR(port_priv->agent[0])) {
310 if (IS_ERR(port_priv->smp_agent)) { 172 ret = PTR_ERR(port_priv->agent[0]);
311 ret = PTR_ERR(port_priv->smp_agent);
312 goto error2; 173 goto error2;
313 } 174 }
314 175
315 /* Obtain send only MAD agent for PerfMgmt class (GSI QP) */ 176 /* Obtain send only MAD agent for GSI QP */
316 port_priv->perf_mgmt_agent = ib_register_mad_agent(device, port_num, 177 port_priv->agent[1] = ib_register_mad_agent(device, port_num,
317 IB_QPT_GSI, 178 IB_QPT_GSI, NULL, 0,
318 NULL, 0, 179 &agent_send_handler,
319 &agent_send_handler, 180 NULL, NULL);
320 NULL, NULL); 181 if (IS_ERR(port_priv->agent[1])) {
321 if (IS_ERR(port_priv->perf_mgmt_agent)) { 182 ret = PTR_ERR(port_priv->agent[1]);
322 ret = PTR_ERR(port_priv->perf_mgmt_agent);
323 goto error3; 183 goto error3;
324 } 184 }
325 185
@@ -330,7 +190,7 @@ int ib_agent_port_open(struct ib_device *device, int port_num)
330 return 0; 190 return 0;
331 191
332error3: 192error3:
333 ib_unregister_mad_agent(port_priv->smp_agent); 193 ib_unregister_mad_agent(port_priv->agent[0]);
334error2: 194error2:
335 kfree(port_priv); 195 kfree(port_priv);
336error1: 196error1:
@@ -343,7 +203,7 @@ int ib_agent_port_close(struct ib_device *device, int port_num)
343 unsigned long flags; 203 unsigned long flags;
344 204
345 spin_lock_irqsave(&ib_agent_port_list_lock, flags); 205 spin_lock_irqsave(&ib_agent_port_list_lock, flags);
346 port_priv = __ib_get_agent_port(device, port_num, NULL); 206 port_priv = __ib_get_agent_port(device, port_num);
347 if (port_priv == NULL) { 207 if (port_priv == NULL) {
348 spin_unlock_irqrestore(&ib_agent_port_list_lock, flags); 208 spin_unlock_irqrestore(&ib_agent_port_list_lock, flags);
349 printk(KERN_ERR SPFX "Port %d not found\n", port_num); 209 printk(KERN_ERR SPFX "Port %d not found\n", port_num);
@@ -352,9 +212,8 @@ int ib_agent_port_close(struct ib_device *device, int port_num)
352 list_del(&port_priv->port_list); 212 list_del(&port_priv->port_list);
353 spin_unlock_irqrestore(&ib_agent_port_list_lock, flags); 213 spin_unlock_irqrestore(&ib_agent_port_list_lock, flags);
354 214
355 ib_unregister_mad_agent(port_priv->perf_mgmt_agent); 215 ib_unregister_mad_agent(port_priv->agent[1]);
356 ib_unregister_mad_agent(port_priv->smp_agent); 216 ib_unregister_mad_agent(port_priv->agent[0]);
357 kfree(port_priv); 217 kfree(port_priv);
358
359 return 0; 218 return 0;
360} 219}
diff --git a/drivers/infiniband/core/agent.h b/drivers/infiniband/core/agent.h
index d9426842254a..86d72fab37b0 100644
--- a/drivers/infiniband/core/agent.h
+++ b/drivers/infiniband/core/agent.h
@@ -39,17 +39,15 @@
39#ifndef __AGENT_H_ 39#ifndef __AGENT_H_
40#define __AGENT_H_ 40#define __AGENT_H_
41 41
42extern spinlock_t ib_agent_port_list_lock; 42#include <linux/err.h>
43#include <rdma/ib_mad.h>
43 44
44extern int ib_agent_port_open(struct ib_device *device, 45extern int ib_agent_port_open(struct ib_device *device, int port_num);
45 int port_num);
46 46
47extern int ib_agent_port_close(struct ib_device *device, int port_num); 47extern int ib_agent_port_close(struct ib_device *device, int port_num);
48 48
49extern int agent_send(struct ib_mad_private *mad, 49extern int agent_send_response(struct ib_mad *mad, struct ib_grh *grh,
50 struct ib_grh *grh, 50 struct ib_wc *wc, struct ib_device *device,
51 struct ib_wc *wc, 51 int port_num, int qpn);
52 struct ib_device *device,
53 int port_num);
54 52
55#endif /* __AGENT_H_ */ 53#endif /* __AGENT_H_ */
diff --git a/drivers/infiniband/core/agent_priv.h b/drivers/infiniband/core/agent_priv.h
deleted file mode 100644
index 2ec6d7f1b7d0..000000000000
--- a/drivers/infiniband/core/agent_priv.h
+++ /dev/null
@@ -1,62 +0,0 @@
1/*
2 * Copyright (c) 2004, 2005 Mellanox Technologies Ltd. All rights reserved.
3 * Copyright (c) 2004, 2005 Infinicon Corporation. All rights reserved.
4 * Copyright (c) 2004, 2005 Intel Corporation. All rights reserved.
5 * Copyright (c) 2004, 2005 Topspin Corporation. All rights reserved.
6 * Copyright (c) 2004, 2005 Voltaire Corporation. All rights reserved.
7 *
8 * This software is available to you under a choice of one of two
9 * licenses. You may choose to be licensed under the terms of the GNU
10 * General Public License (GPL) Version 2, available from the file
11 * COPYING in the main directory of this source tree, or the
12 * OpenIB.org BSD license below:
13 *
14 * Redistribution and use in source and binary forms, with or
15 * without modification, are permitted provided that the following
16 * conditions are met:
17 *
18 * - Redistributions of source code must retain the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer.
21 *
22 * - Redistributions in binary form must reproduce the above
23 * copyright notice, this list of conditions and the following
24 * disclaimer in the documentation and/or other materials
25 * provided with the distribution.
26 *
27 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
31 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
32 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
33 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 * SOFTWARE.
35 *
36 * $Id: agent_priv.h 1640 2005-01-24 22:39:02Z halr $
37 */
38
39#ifndef __IB_AGENT_PRIV_H__
40#define __IB_AGENT_PRIV_H__
41
42#include <linux/pci.h>
43
44#define SPFX "ib_agent: "
45
46struct ib_agent_send_wr {
47 struct list_head send_list;
48 struct ib_ah *ah;
49 struct ib_mad_private *mad;
50 DECLARE_PCI_UNMAP_ADDR(mapping)
51};
52
53struct ib_agent_port_private {
54 struct list_head port_list;
55 struct list_head send_posted_list;
56 spinlock_t send_list_lock;
57 int port_num;
58 struct ib_mad_agent *smp_agent; /* SM class */
59 struct ib_mad_agent *perf_mgmt_agent; /* PerfMgmt class */
60};
61
62#endif /* __IB_AGENT_PRIV_H__ */
diff --git a/drivers/infiniband/core/cache.c b/drivers/infiniband/core/cache.c
index f014e639088c..c57a3871184c 100644
--- a/drivers/infiniband/core/cache.c
+++ b/drivers/infiniband/core/cache.c
@@ -38,6 +38,7 @@
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/errno.h> 39#include <linux/errno.h>
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/sched.h> /* INIT_WORK, schedule_work(), flush_scheduled_work() */
41 42
42#include <rdma/ib_cache.h> 43#include <rdma/ib_cache.h>
43 44
diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index 54db6d4831f1..580c3a2bb102 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -135,6 +135,7 @@ struct cm_id_private {
135 __be64 tid; 135 __be64 tid;
136 __be32 local_qpn; 136 __be32 local_qpn;
137 __be32 remote_qpn; 137 __be32 remote_qpn;
138 enum ib_qp_type qp_type;
138 __be32 sq_psn; 139 __be32 sq_psn;
139 __be32 rq_psn; 140 __be32 rq_psn;
140 int timeout_ms; 141 int timeout_ms;
@@ -175,8 +176,7 @@ static int cm_alloc_msg(struct cm_id_private *cm_id_priv,
175 176
176 m = ib_create_send_mad(mad_agent, cm_id_priv->id.remote_cm_qpn, 177 m = ib_create_send_mad(mad_agent, cm_id_priv->id.remote_cm_qpn,
177 cm_id_priv->av.pkey_index, 178 cm_id_priv->av.pkey_index,
178 ah, 0, sizeof(struct ib_mad_hdr), 179 0, IB_MGMT_MAD_HDR, IB_MGMT_MAD_DATA,
179 sizeof(struct ib_mad)-sizeof(struct ib_mad_hdr),
180 GFP_ATOMIC); 180 GFP_ATOMIC);
181 if (IS_ERR(m)) { 181 if (IS_ERR(m)) {
182 ib_destroy_ah(ah); 182 ib_destroy_ah(ah);
@@ -184,7 +184,8 @@ static int cm_alloc_msg(struct cm_id_private *cm_id_priv,
184 } 184 }
185 185
186 /* Timeout set by caller if response is expected. */ 186 /* Timeout set by caller if response is expected. */
187 m->send_wr.wr.ud.retries = cm_id_priv->max_cm_retries; 187 m->ah = ah;
188 m->retries = cm_id_priv->max_cm_retries;
188 189
189 atomic_inc(&cm_id_priv->refcount); 190 atomic_inc(&cm_id_priv->refcount);
190 m->context[0] = cm_id_priv; 191 m->context[0] = cm_id_priv;
@@ -205,20 +206,20 @@ static int cm_alloc_response_msg(struct cm_port *port,
205 return PTR_ERR(ah); 206 return PTR_ERR(ah);
206 207
207 m = ib_create_send_mad(port->mad_agent, 1, mad_recv_wc->wc->pkey_index, 208 m = ib_create_send_mad(port->mad_agent, 1, mad_recv_wc->wc->pkey_index,
208 ah, 0, sizeof(struct ib_mad_hdr), 209 0, IB_MGMT_MAD_HDR, IB_MGMT_MAD_DATA,
209 sizeof(struct ib_mad)-sizeof(struct ib_mad_hdr),
210 GFP_ATOMIC); 210 GFP_ATOMIC);
211 if (IS_ERR(m)) { 211 if (IS_ERR(m)) {
212 ib_destroy_ah(ah); 212 ib_destroy_ah(ah);
213 return PTR_ERR(m); 213 return PTR_ERR(m);
214 } 214 }
215 m->ah = ah;
215 *msg = m; 216 *msg = m;
216 return 0; 217 return 0;
217} 218}
218 219
219static void cm_free_msg(struct ib_mad_send_buf *msg) 220static void cm_free_msg(struct ib_mad_send_buf *msg)
220{ 221{
221 ib_destroy_ah(msg->send_wr.wr.ud.ah); 222 ib_destroy_ah(msg->ah);
222 if (msg->context[0]) 223 if (msg->context[0])
223 cm_deref_id(msg->context[0]); 224 cm_deref_id(msg->context[0]);
224 ib_free_send_mad(msg); 225 ib_free_send_mad(msg);
@@ -366,9 +367,15 @@ static struct cm_id_private * cm_insert_listen(struct cm_id_private *cm_id_priv)
366 cur_cm_id_priv = rb_entry(parent, struct cm_id_private, 367 cur_cm_id_priv = rb_entry(parent, struct cm_id_private,
367 service_node); 368 service_node);
368 if ((cur_cm_id_priv->id.service_mask & service_id) == 369 if ((cur_cm_id_priv->id.service_mask & service_id) ==
369 (service_mask & cur_cm_id_priv->id.service_id)) 370 (service_mask & cur_cm_id_priv->id.service_id) &&
370 return cm_id_priv; 371 (cm_id_priv->id.device == cur_cm_id_priv->id.device))
371 if (service_id < cur_cm_id_priv->id.service_id) 372 return cur_cm_id_priv;
373
374 if (cm_id_priv->id.device < cur_cm_id_priv->id.device)
375 link = &(*link)->rb_left;
376 else if (cm_id_priv->id.device > cur_cm_id_priv->id.device)
377 link = &(*link)->rb_right;
378 else if (service_id < cur_cm_id_priv->id.service_id)
372 link = &(*link)->rb_left; 379 link = &(*link)->rb_left;
373 else 380 else
374 link = &(*link)->rb_right; 381 link = &(*link)->rb_right;
@@ -378,7 +385,8 @@ static struct cm_id_private * cm_insert_listen(struct cm_id_private *cm_id_priv)
378 return NULL; 385 return NULL;
379} 386}
380 387
381static struct cm_id_private * cm_find_listen(__be64 service_id) 388static struct cm_id_private * cm_find_listen(struct ib_device *device,
389 __be64 service_id)
382{ 390{
383 struct rb_node *node = cm.listen_service_table.rb_node; 391 struct rb_node *node = cm.listen_service_table.rb_node;
384 struct cm_id_private *cm_id_priv; 392 struct cm_id_private *cm_id_priv;
@@ -386,9 +394,15 @@ static struct cm_id_private * cm_find_listen(__be64 service_id)
386 while (node) { 394 while (node) {
387 cm_id_priv = rb_entry(node, struct cm_id_private, service_node); 395 cm_id_priv = rb_entry(node, struct cm_id_private, service_node);
388 if ((cm_id_priv->id.service_mask & service_id) == 396 if ((cm_id_priv->id.service_mask & service_id) ==
389 (cm_id_priv->id.service_mask & cm_id_priv->id.service_id)) 397 cm_id_priv->id.service_id &&
398 (cm_id_priv->id.device == device))
390 return cm_id_priv; 399 return cm_id_priv;
391 if (service_id < cm_id_priv->id.service_id) 400
401 if (device < cm_id_priv->id.device)
402 node = node->rb_left;
403 else if (device > cm_id_priv->id.device)
404 node = node->rb_right;
405 else if (service_id < cm_id_priv->id.service_id)
392 node = node->rb_left; 406 node = node->rb_left;
393 else 407 else
394 node = node->rb_right; 408 node = node->rb_right;
@@ -523,7 +537,8 @@ static void cm_reject_sidr_req(struct cm_id_private *cm_id_priv,
523 ib_send_cm_sidr_rep(&cm_id_priv->id, &param); 537 ib_send_cm_sidr_rep(&cm_id_priv->id, &param);
524} 538}
525 539
526struct ib_cm_id *ib_create_cm_id(ib_cm_handler cm_handler, 540struct ib_cm_id *ib_create_cm_id(struct ib_device *device,
541 ib_cm_handler cm_handler,
527 void *context) 542 void *context)
528{ 543{
529 struct cm_id_private *cm_id_priv; 544 struct cm_id_private *cm_id_priv;
@@ -535,6 +550,7 @@ struct ib_cm_id *ib_create_cm_id(ib_cm_handler cm_handler,
535 550
536 memset(cm_id_priv, 0, sizeof *cm_id_priv); 551 memset(cm_id_priv, 0, sizeof *cm_id_priv);
537 cm_id_priv->id.state = IB_CM_IDLE; 552 cm_id_priv->id.state = IB_CM_IDLE;
553 cm_id_priv->id.device = device;
538 cm_id_priv->id.cm_handler = cm_handler; 554 cm_id_priv->id.cm_handler = cm_handler;
539 cm_id_priv->id.context = context; 555 cm_id_priv->id.context = context;
540 cm_id_priv->id.remote_cm_qpn = 1; 556 cm_id_priv->id.remote_cm_qpn = 1;
@@ -662,8 +678,7 @@ retest:
662 break; 678 break;
663 case IB_CM_SIDR_REQ_SENT: 679 case IB_CM_SIDR_REQ_SENT:
664 cm_id->state = IB_CM_IDLE; 680 cm_id->state = IB_CM_IDLE;
665 ib_cancel_mad(cm_id_priv->av.port->mad_agent, 681 ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
666 (unsigned long) cm_id_priv->msg);
667 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 682 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
668 break; 683 break;
669 case IB_CM_SIDR_REQ_RCVD: 684 case IB_CM_SIDR_REQ_RCVD:
@@ -674,8 +689,7 @@ retest:
674 case IB_CM_MRA_REQ_RCVD: 689 case IB_CM_MRA_REQ_RCVD:
675 case IB_CM_REP_SENT: 690 case IB_CM_REP_SENT:
676 case IB_CM_MRA_REP_RCVD: 691 case IB_CM_MRA_REP_RCVD:
677 ib_cancel_mad(cm_id_priv->av.port->mad_agent, 692 ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
678 (unsigned long) cm_id_priv->msg);
679 /* Fall through */ 693 /* Fall through */
680 case IB_CM_REQ_RCVD: 694 case IB_CM_REQ_RCVD:
681 case IB_CM_MRA_REQ_SENT: 695 case IB_CM_MRA_REQ_SENT:
@@ -692,8 +706,7 @@ retest:
692 ib_send_cm_dreq(cm_id, NULL, 0); 706 ib_send_cm_dreq(cm_id, NULL, 0);
693 goto retest; 707 goto retest;
694 case IB_CM_DREQ_SENT: 708 case IB_CM_DREQ_SENT:
695 ib_cancel_mad(cm_id_priv->av.port->mad_agent, 709 ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
696 (unsigned long) cm_id_priv->msg);
697 cm_enter_timewait(cm_id_priv); 710 cm_enter_timewait(cm_id_priv);
698 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 711 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
699 break; 712 break;
@@ -867,7 +880,6 @@ int ib_send_cm_req(struct ib_cm_id *cm_id,
867 struct ib_cm_req_param *param) 880 struct ib_cm_req_param *param)
868{ 881{
869 struct cm_id_private *cm_id_priv; 882 struct cm_id_private *cm_id_priv;
870 struct ib_send_wr *bad_send_wr;
871 struct cm_req_msg *req_msg; 883 struct cm_req_msg *req_msg;
872 unsigned long flags; 884 unsigned long flags;
873 int ret; 885 int ret;
@@ -911,6 +923,7 @@ int ib_send_cm_req(struct ib_cm_id *cm_id,
911 cm_id_priv->responder_resources = param->responder_resources; 923 cm_id_priv->responder_resources = param->responder_resources;
912 cm_id_priv->retry_count = param->retry_count; 924 cm_id_priv->retry_count = param->retry_count;
913 cm_id_priv->path_mtu = param->primary_path->mtu; 925 cm_id_priv->path_mtu = param->primary_path->mtu;
926 cm_id_priv->qp_type = param->qp_type;
914 927
915 ret = cm_alloc_msg(cm_id_priv, &cm_id_priv->msg); 928 ret = cm_alloc_msg(cm_id_priv, &cm_id_priv->msg);
916 if (ret) 929 if (ret)
@@ -919,7 +932,7 @@ int ib_send_cm_req(struct ib_cm_id *cm_id,
919 req_msg = (struct cm_req_msg *) cm_id_priv->msg->mad; 932 req_msg = (struct cm_req_msg *) cm_id_priv->msg->mad;
920 cm_format_req(req_msg, cm_id_priv, param); 933 cm_format_req(req_msg, cm_id_priv, param);
921 cm_id_priv->tid = req_msg->hdr.tid; 934 cm_id_priv->tid = req_msg->hdr.tid;
922 cm_id_priv->msg->send_wr.wr.ud.timeout_ms = cm_id_priv->timeout_ms; 935 cm_id_priv->msg->timeout_ms = cm_id_priv->timeout_ms;
923 cm_id_priv->msg->context[1] = (void *) (unsigned long) IB_CM_REQ_SENT; 936 cm_id_priv->msg->context[1] = (void *) (unsigned long) IB_CM_REQ_SENT;
924 937
925 cm_id_priv->local_qpn = cm_req_get_local_qpn(req_msg); 938 cm_id_priv->local_qpn = cm_req_get_local_qpn(req_msg);
@@ -928,8 +941,7 @@ int ib_send_cm_req(struct ib_cm_id *cm_id,
928 cm_req_get_primary_local_ack_timeout(req_msg); 941 cm_req_get_primary_local_ack_timeout(req_msg);
929 942
930 spin_lock_irqsave(&cm_id_priv->lock, flags); 943 spin_lock_irqsave(&cm_id_priv->lock, flags);
931 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 944 ret = ib_post_send_mad(cm_id_priv->msg, NULL);
932 &cm_id_priv->msg->send_wr, &bad_send_wr);
933 if (ret) { 945 if (ret) {
934 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 946 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
935 goto error2; 947 goto error2;
@@ -952,7 +964,6 @@ static int cm_issue_rej(struct cm_port *port,
952 void *ari, u8 ari_length) 964 void *ari, u8 ari_length)
953{ 965{
954 struct ib_mad_send_buf *msg = NULL; 966 struct ib_mad_send_buf *msg = NULL;
955 struct ib_send_wr *bad_send_wr;
956 struct cm_rej_msg *rej_msg, *rcv_msg; 967 struct cm_rej_msg *rej_msg, *rcv_msg;
957 int ret; 968 int ret;
958 969
@@ -975,7 +986,7 @@ static int cm_issue_rej(struct cm_port *port,
975 memcpy(rej_msg->ari, ari, ari_length); 986 memcpy(rej_msg->ari, ari, ari_length);
976 } 987 }
977 988
978 ret = ib_post_send_mad(port->mad_agent, &msg->send_wr, &bad_send_wr); 989 ret = ib_post_send_mad(msg, NULL);
979 if (ret) 990 if (ret)
980 cm_free_msg(msg); 991 cm_free_msg(msg);
981 992
@@ -1047,7 +1058,6 @@ static void cm_format_req_event(struct cm_work *work,
1047 req_msg = (struct cm_req_msg *)work->mad_recv_wc->recv_buf.mad; 1058 req_msg = (struct cm_req_msg *)work->mad_recv_wc->recv_buf.mad;
1048 param = &work->cm_event.param.req_rcvd; 1059 param = &work->cm_event.param.req_rcvd;
1049 param->listen_id = listen_id; 1060 param->listen_id = listen_id;
1050 param->device = cm_id_priv->av.port->mad_agent->device;
1051 param->port = cm_id_priv->av.port->port_num; 1061 param->port = cm_id_priv->av.port->port_num;
1052 param->primary_path = &work->path[0]; 1062 param->primary_path = &work->path[0];
1053 if (req_msg->alt_local_lid) 1063 if (req_msg->alt_local_lid)
@@ -1156,7 +1166,6 @@ static void cm_dup_req_handler(struct cm_work *work,
1156 struct cm_id_private *cm_id_priv) 1166 struct cm_id_private *cm_id_priv)
1157{ 1167{
1158 struct ib_mad_send_buf *msg = NULL; 1168 struct ib_mad_send_buf *msg = NULL;
1159 struct ib_send_wr *bad_send_wr;
1160 unsigned long flags; 1169 unsigned long flags;
1161 int ret; 1170 int ret;
1162 1171
@@ -1185,8 +1194,7 @@ static void cm_dup_req_handler(struct cm_work *work,
1185 } 1194 }
1186 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 1195 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1187 1196
1188 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, &msg->send_wr, 1197 ret = ib_post_send_mad(msg, NULL);
1189 &bad_send_wr);
1190 if (ret) 1198 if (ret)
1191 goto free; 1199 goto free;
1192 return; 1200 return;
@@ -1226,7 +1234,8 @@ static struct cm_id_private * cm_match_req(struct cm_work *work,
1226 } 1234 }
1227 1235
1228 /* Find matching listen request. */ 1236 /* Find matching listen request. */
1229 listen_cm_id_priv = cm_find_listen(req_msg->service_id); 1237 listen_cm_id_priv = cm_find_listen(cm_id_priv->id.device,
1238 req_msg->service_id);
1230 if (!listen_cm_id_priv) { 1239 if (!listen_cm_id_priv) {
1231 spin_unlock_irqrestore(&cm.lock, flags); 1240 spin_unlock_irqrestore(&cm.lock, flags);
1232 cm_issue_rej(work->port, work->mad_recv_wc, 1241 cm_issue_rej(work->port, work->mad_recv_wc,
@@ -1254,7 +1263,7 @@ static int cm_req_handler(struct cm_work *work)
1254 1263
1255 req_msg = (struct cm_req_msg *)work->mad_recv_wc->recv_buf.mad; 1264 req_msg = (struct cm_req_msg *)work->mad_recv_wc->recv_buf.mad;
1256 1265
1257 cm_id = ib_create_cm_id(NULL, NULL); 1266 cm_id = ib_create_cm_id(work->port->cm_dev->device, NULL, NULL);
1258 if (IS_ERR(cm_id)) 1267 if (IS_ERR(cm_id))
1259 return PTR_ERR(cm_id); 1268 return PTR_ERR(cm_id);
1260 1269
@@ -1305,6 +1314,7 @@ static int cm_req_handler(struct cm_work *work)
1305 cm_req_get_primary_local_ack_timeout(req_msg); 1314 cm_req_get_primary_local_ack_timeout(req_msg);
1306 cm_id_priv->retry_count = cm_req_get_retry_count(req_msg); 1315 cm_id_priv->retry_count = cm_req_get_retry_count(req_msg);
1307 cm_id_priv->rnr_retry_count = cm_req_get_rnr_retry_count(req_msg); 1316 cm_id_priv->rnr_retry_count = cm_req_get_rnr_retry_count(req_msg);
1317 cm_id_priv->qp_type = cm_req_get_qp_type(req_msg);
1308 1318
1309 cm_format_req_event(work, cm_id_priv, &listen_cm_id_priv->id); 1319 cm_format_req_event(work, cm_id_priv, &listen_cm_id_priv->id);
1310 cm_process_work(cm_id_priv, work); 1320 cm_process_work(cm_id_priv, work);
@@ -1349,7 +1359,6 @@ int ib_send_cm_rep(struct ib_cm_id *cm_id,
1349 struct cm_id_private *cm_id_priv; 1359 struct cm_id_private *cm_id_priv;
1350 struct ib_mad_send_buf *msg; 1360 struct ib_mad_send_buf *msg;
1351 struct cm_rep_msg *rep_msg; 1361 struct cm_rep_msg *rep_msg;
1352 struct ib_send_wr *bad_send_wr;
1353 unsigned long flags; 1362 unsigned long flags;
1354 int ret; 1363 int ret;
1355 1364
@@ -1371,11 +1380,10 @@ int ib_send_cm_rep(struct ib_cm_id *cm_id,
1371 1380
1372 rep_msg = (struct cm_rep_msg *) msg->mad; 1381 rep_msg = (struct cm_rep_msg *) msg->mad;
1373 cm_format_rep(rep_msg, cm_id_priv, param); 1382 cm_format_rep(rep_msg, cm_id_priv, param);
1374 msg->send_wr.wr.ud.timeout_ms = cm_id_priv->timeout_ms; 1383 msg->timeout_ms = cm_id_priv->timeout_ms;
1375 msg->context[1] = (void *) (unsigned long) IB_CM_REP_SENT; 1384 msg->context[1] = (void *) (unsigned long) IB_CM_REP_SENT;
1376 1385
1377 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 1386 ret = ib_post_send_mad(msg, NULL);
1378 &msg->send_wr, &bad_send_wr);
1379 if (ret) { 1387 if (ret) {
1380 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 1388 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1381 cm_free_msg(msg); 1389 cm_free_msg(msg);
@@ -1413,7 +1421,6 @@ int ib_send_cm_rtu(struct ib_cm_id *cm_id,
1413{ 1421{
1414 struct cm_id_private *cm_id_priv; 1422 struct cm_id_private *cm_id_priv;
1415 struct ib_mad_send_buf *msg; 1423 struct ib_mad_send_buf *msg;
1416 struct ib_send_wr *bad_send_wr;
1417 unsigned long flags; 1424 unsigned long flags;
1418 void *data; 1425 void *data;
1419 int ret; 1426 int ret;
@@ -1440,8 +1447,7 @@ int ib_send_cm_rtu(struct ib_cm_id *cm_id,
1440 cm_format_rtu((struct cm_rtu_msg *) msg->mad, cm_id_priv, 1447 cm_format_rtu((struct cm_rtu_msg *) msg->mad, cm_id_priv,
1441 private_data, private_data_len); 1448 private_data, private_data_len);
1442 1449
1443 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 1450 ret = ib_post_send_mad(msg, NULL);
1444 &msg->send_wr, &bad_send_wr);
1445 if (ret) { 1451 if (ret) {
1446 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 1452 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1447 cm_free_msg(msg); 1453 cm_free_msg(msg);
@@ -1486,7 +1492,6 @@ static void cm_dup_rep_handler(struct cm_work *work)
1486 struct cm_id_private *cm_id_priv; 1492 struct cm_id_private *cm_id_priv;
1487 struct cm_rep_msg *rep_msg; 1493 struct cm_rep_msg *rep_msg;
1488 struct ib_mad_send_buf *msg = NULL; 1494 struct ib_mad_send_buf *msg = NULL;
1489 struct ib_send_wr *bad_send_wr;
1490 unsigned long flags; 1495 unsigned long flags;
1491 int ret; 1496 int ret;
1492 1497
@@ -1514,8 +1519,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
1514 goto unlock; 1519 goto unlock;
1515 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 1520 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1516 1521
1517 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, &msg->send_wr, 1522 ret = ib_post_send_mad(msg, NULL);
1518 &bad_send_wr);
1519 if (ret) 1523 if (ret)
1520 goto free; 1524 goto free;
1521 goto deref; 1525 goto deref;
@@ -1583,8 +1587,7 @@ static int cm_rep_handler(struct cm_work *work)
1583 1587
1584 /* todo: handle peer_to_peer */ 1588 /* todo: handle peer_to_peer */
1585 1589
1586 ib_cancel_mad(cm_id_priv->av.port->mad_agent, 1590 ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
1587 (unsigned long) cm_id_priv->msg);
1588 ret = atomic_inc_and_test(&cm_id_priv->work_count); 1591 ret = atomic_inc_and_test(&cm_id_priv->work_count);
1589 if (!ret) 1592 if (!ret)
1590 list_add_tail(&work->list, &cm_id_priv->work_list); 1593 list_add_tail(&work->list, &cm_id_priv->work_list);
@@ -1618,8 +1621,7 @@ static int cm_establish_handler(struct cm_work *work)
1618 goto out; 1621 goto out;
1619 } 1622 }
1620 1623
1621 ib_cancel_mad(cm_id_priv->av.port->mad_agent, 1624 ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
1622 (unsigned long) cm_id_priv->msg);
1623 ret = atomic_inc_and_test(&cm_id_priv->work_count); 1625 ret = atomic_inc_and_test(&cm_id_priv->work_count);
1624 if (!ret) 1626 if (!ret)
1625 list_add_tail(&work->list, &cm_id_priv->work_list); 1627 list_add_tail(&work->list, &cm_id_priv->work_list);
@@ -1658,8 +1660,7 @@ static int cm_rtu_handler(struct cm_work *work)
1658 } 1660 }
1659 cm_id_priv->id.state = IB_CM_ESTABLISHED; 1661 cm_id_priv->id.state = IB_CM_ESTABLISHED;
1660 1662
1661 ib_cancel_mad(cm_id_priv->av.port->mad_agent, 1663 ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
1662 (unsigned long) cm_id_priv->msg);
1663 ret = atomic_inc_and_test(&cm_id_priv->work_count); 1664 ret = atomic_inc_and_test(&cm_id_priv->work_count);
1664 if (!ret) 1665 if (!ret)
1665 list_add_tail(&work->list, &cm_id_priv->work_list); 1666 list_add_tail(&work->list, &cm_id_priv->work_list);
@@ -1696,7 +1697,6 @@ int ib_send_cm_dreq(struct ib_cm_id *cm_id,
1696{ 1697{
1697 struct cm_id_private *cm_id_priv; 1698 struct cm_id_private *cm_id_priv;
1698 struct ib_mad_send_buf *msg; 1699 struct ib_mad_send_buf *msg;
1699 struct ib_send_wr *bad_send_wr;
1700 unsigned long flags; 1700 unsigned long flags;
1701 int ret; 1701 int ret;
1702 1702
@@ -1718,11 +1718,10 @@ int ib_send_cm_dreq(struct ib_cm_id *cm_id,
1718 1718
1719 cm_format_dreq((struct cm_dreq_msg *) msg->mad, cm_id_priv, 1719 cm_format_dreq((struct cm_dreq_msg *) msg->mad, cm_id_priv,
1720 private_data, private_data_len); 1720 private_data, private_data_len);
1721 msg->send_wr.wr.ud.timeout_ms = cm_id_priv->timeout_ms; 1721 msg->timeout_ms = cm_id_priv->timeout_ms;
1722 msg->context[1] = (void *) (unsigned long) IB_CM_DREQ_SENT; 1722 msg->context[1] = (void *) (unsigned long) IB_CM_DREQ_SENT;
1723 1723
1724 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 1724 ret = ib_post_send_mad(msg, NULL);
1725 &msg->send_wr, &bad_send_wr);
1726 if (ret) { 1725 if (ret) {
1727 cm_enter_timewait(cm_id_priv); 1726 cm_enter_timewait(cm_id_priv);
1728 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 1727 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
@@ -1756,7 +1755,6 @@ int ib_send_cm_drep(struct ib_cm_id *cm_id,
1756{ 1755{
1757 struct cm_id_private *cm_id_priv; 1756 struct cm_id_private *cm_id_priv;
1758 struct ib_mad_send_buf *msg; 1757 struct ib_mad_send_buf *msg;
1759 struct ib_send_wr *bad_send_wr;
1760 unsigned long flags; 1758 unsigned long flags;
1761 void *data; 1759 void *data;
1762 int ret; 1760 int ret;
@@ -1786,8 +1784,7 @@ int ib_send_cm_drep(struct ib_cm_id *cm_id,
1786 cm_format_drep((struct cm_drep_msg *) msg->mad, cm_id_priv, 1784 cm_format_drep((struct cm_drep_msg *) msg->mad, cm_id_priv,
1787 private_data, private_data_len); 1785 private_data, private_data_len);
1788 1786
1789 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, &msg->send_wr, 1787 ret = ib_post_send_mad(msg, NULL);
1790 &bad_send_wr);
1791 if (ret) { 1788 if (ret) {
1792 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 1789 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1793 cm_free_msg(msg); 1790 cm_free_msg(msg);
@@ -1804,7 +1801,6 @@ static int cm_dreq_handler(struct cm_work *work)
1804 struct cm_id_private *cm_id_priv; 1801 struct cm_id_private *cm_id_priv;
1805 struct cm_dreq_msg *dreq_msg; 1802 struct cm_dreq_msg *dreq_msg;
1806 struct ib_mad_send_buf *msg = NULL; 1803 struct ib_mad_send_buf *msg = NULL;
1807 struct ib_send_wr *bad_send_wr;
1808 unsigned long flags; 1804 unsigned long flags;
1809 int ret; 1805 int ret;
1810 1806
@@ -1823,8 +1819,7 @@ static int cm_dreq_handler(struct cm_work *work)
1823 switch (cm_id_priv->id.state) { 1819 switch (cm_id_priv->id.state) {
1824 case IB_CM_REP_SENT: 1820 case IB_CM_REP_SENT:
1825 case IB_CM_DREQ_SENT: 1821 case IB_CM_DREQ_SENT:
1826 ib_cancel_mad(cm_id_priv->av.port->mad_agent, 1822 ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
1827 (unsigned long) cm_id_priv->msg);
1828 break; 1823 break;
1829 case IB_CM_ESTABLISHED: 1824 case IB_CM_ESTABLISHED:
1830 case IB_CM_MRA_REP_RCVD: 1825 case IB_CM_MRA_REP_RCVD:
@@ -1838,8 +1833,7 @@ static int cm_dreq_handler(struct cm_work *work)
1838 cm_id_priv->private_data_len); 1833 cm_id_priv->private_data_len);
1839 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 1834 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1840 1835
1841 if (ib_post_send_mad(cm_id_priv->av.port->mad_agent, 1836 if (ib_post_send_mad(msg, NULL))
1842 &msg->send_wr, &bad_send_wr))
1843 cm_free_msg(msg); 1837 cm_free_msg(msg);
1844 goto deref; 1838 goto deref;
1845 default: 1839 default:
@@ -1886,8 +1880,7 @@ static int cm_drep_handler(struct cm_work *work)
1886 } 1880 }
1887 cm_enter_timewait(cm_id_priv); 1881 cm_enter_timewait(cm_id_priv);
1888 1882
1889 ib_cancel_mad(cm_id_priv->av.port->mad_agent, 1883 ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
1890 (unsigned long) cm_id_priv->msg);
1891 ret = atomic_inc_and_test(&cm_id_priv->work_count); 1884 ret = atomic_inc_and_test(&cm_id_priv->work_count);
1892 if (!ret) 1885 if (!ret)
1893 list_add_tail(&work->list, &cm_id_priv->work_list); 1886 list_add_tail(&work->list, &cm_id_priv->work_list);
@@ -1912,7 +1905,6 @@ int ib_send_cm_rej(struct ib_cm_id *cm_id,
1912{ 1905{
1913 struct cm_id_private *cm_id_priv; 1906 struct cm_id_private *cm_id_priv;
1914 struct ib_mad_send_buf *msg; 1907 struct ib_mad_send_buf *msg;
1915 struct ib_send_wr *bad_send_wr;
1916 unsigned long flags; 1908 unsigned long flags;
1917 int ret; 1909 int ret;
1918 1910
@@ -1956,8 +1948,7 @@ int ib_send_cm_rej(struct ib_cm_id *cm_id,
1956 if (ret) 1948 if (ret)
1957 goto out; 1949 goto out;
1958 1950
1959 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 1951 ret = ib_post_send_mad(msg, NULL);
1960 &msg->send_wr, &bad_send_wr);
1961 if (ret) 1952 if (ret)
1962 cm_free_msg(msg); 1953 cm_free_msg(msg);
1963 1954
@@ -2033,8 +2024,7 @@ static int cm_rej_handler(struct cm_work *work)
2033 case IB_CM_MRA_REQ_RCVD: 2024 case IB_CM_MRA_REQ_RCVD:
2034 case IB_CM_REP_SENT: 2025 case IB_CM_REP_SENT:
2035 case IB_CM_MRA_REP_RCVD: 2026 case IB_CM_MRA_REP_RCVD:
2036 ib_cancel_mad(cm_id_priv->av.port->mad_agent, 2027 ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
2037 (unsigned long) cm_id_priv->msg);
2038 /* fall through */ 2028 /* fall through */
2039 case IB_CM_REQ_RCVD: 2029 case IB_CM_REQ_RCVD:
2040 case IB_CM_MRA_REQ_SENT: 2030 case IB_CM_MRA_REQ_SENT:
@@ -2044,8 +2034,7 @@ static int cm_rej_handler(struct cm_work *work)
2044 cm_reset_to_idle(cm_id_priv); 2034 cm_reset_to_idle(cm_id_priv);
2045 break; 2035 break;
2046 case IB_CM_DREQ_SENT: 2036 case IB_CM_DREQ_SENT:
2047 ib_cancel_mad(cm_id_priv->av.port->mad_agent, 2037 ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
2048 (unsigned long) cm_id_priv->msg);
2049 /* fall through */ 2038 /* fall through */
2050 case IB_CM_REP_RCVD: 2039 case IB_CM_REP_RCVD:
2051 case IB_CM_MRA_REP_SENT: 2040 case IB_CM_MRA_REP_SENT:
@@ -2080,7 +2069,6 @@ int ib_send_cm_mra(struct ib_cm_id *cm_id,
2080{ 2069{
2081 struct cm_id_private *cm_id_priv; 2070 struct cm_id_private *cm_id_priv;
2082 struct ib_mad_send_buf *msg; 2071 struct ib_mad_send_buf *msg;
2083 struct ib_send_wr *bad_send_wr;
2084 void *data; 2072 void *data;
2085 unsigned long flags; 2073 unsigned long flags;
2086 int ret; 2074 int ret;
@@ -2104,8 +2092,7 @@ int ib_send_cm_mra(struct ib_cm_id *cm_id,
2104 cm_format_mra((struct cm_mra_msg *) msg->mad, cm_id_priv, 2092 cm_format_mra((struct cm_mra_msg *) msg->mad, cm_id_priv,
2105 CM_MSG_RESPONSE_REQ, service_timeout, 2093 CM_MSG_RESPONSE_REQ, service_timeout,
2106 private_data, private_data_len); 2094 private_data, private_data_len);
2107 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 2095 ret = ib_post_send_mad(msg, NULL);
2108 &msg->send_wr, &bad_send_wr);
2109 if (ret) 2096 if (ret)
2110 goto error2; 2097 goto error2;
2111 cm_id->state = IB_CM_MRA_REQ_SENT; 2098 cm_id->state = IB_CM_MRA_REQ_SENT;
@@ -2118,8 +2105,7 @@ int ib_send_cm_mra(struct ib_cm_id *cm_id,
2118 cm_format_mra((struct cm_mra_msg *) msg->mad, cm_id_priv, 2105 cm_format_mra((struct cm_mra_msg *) msg->mad, cm_id_priv,
2119 CM_MSG_RESPONSE_REP, service_timeout, 2106 CM_MSG_RESPONSE_REP, service_timeout,
2120 private_data, private_data_len); 2107 private_data, private_data_len);
2121 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 2108 ret = ib_post_send_mad(msg, NULL);
2122 &msg->send_wr, &bad_send_wr);
2123 if (ret) 2109 if (ret)
2124 goto error2; 2110 goto error2;
2125 cm_id->state = IB_CM_MRA_REP_SENT; 2111 cm_id->state = IB_CM_MRA_REP_SENT;
@@ -2132,8 +2118,7 @@ int ib_send_cm_mra(struct ib_cm_id *cm_id,
2132 cm_format_mra((struct cm_mra_msg *) msg->mad, cm_id_priv, 2118 cm_format_mra((struct cm_mra_msg *) msg->mad, cm_id_priv,
2133 CM_MSG_RESPONSE_OTHER, service_timeout, 2119 CM_MSG_RESPONSE_OTHER, service_timeout,
2134 private_data, private_data_len); 2120 private_data, private_data_len);
2135 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 2121 ret = ib_post_send_mad(msg, NULL);
2136 &msg->send_wr, &bad_send_wr);
2137 if (ret) 2122 if (ret)
2138 goto error2; 2123 goto error2;
2139 cm_id->lap_state = IB_CM_MRA_LAP_SENT; 2124 cm_id->lap_state = IB_CM_MRA_LAP_SENT;
@@ -2195,14 +2180,14 @@ static int cm_mra_handler(struct cm_work *work)
2195 case IB_CM_REQ_SENT: 2180 case IB_CM_REQ_SENT:
2196 if (cm_mra_get_msg_mraed(mra_msg) != CM_MSG_RESPONSE_REQ || 2181 if (cm_mra_get_msg_mraed(mra_msg) != CM_MSG_RESPONSE_REQ ||
2197 ib_modify_mad(cm_id_priv->av.port->mad_agent, 2182 ib_modify_mad(cm_id_priv->av.port->mad_agent,
2198 (unsigned long) cm_id_priv->msg, timeout)) 2183 cm_id_priv->msg, timeout))
2199 goto out; 2184 goto out;
2200 cm_id_priv->id.state = IB_CM_MRA_REQ_RCVD; 2185 cm_id_priv->id.state = IB_CM_MRA_REQ_RCVD;
2201 break; 2186 break;
2202 case IB_CM_REP_SENT: 2187 case IB_CM_REP_SENT:
2203 if (cm_mra_get_msg_mraed(mra_msg) != CM_MSG_RESPONSE_REP || 2188 if (cm_mra_get_msg_mraed(mra_msg) != CM_MSG_RESPONSE_REP ||
2204 ib_modify_mad(cm_id_priv->av.port->mad_agent, 2189 ib_modify_mad(cm_id_priv->av.port->mad_agent,
2205 (unsigned long) cm_id_priv->msg, timeout)) 2190 cm_id_priv->msg, timeout))
2206 goto out; 2191 goto out;
2207 cm_id_priv->id.state = IB_CM_MRA_REP_RCVD; 2192 cm_id_priv->id.state = IB_CM_MRA_REP_RCVD;
2208 break; 2193 break;
@@ -2210,7 +2195,7 @@ static int cm_mra_handler(struct cm_work *work)
2210 if (cm_mra_get_msg_mraed(mra_msg) != CM_MSG_RESPONSE_OTHER || 2195 if (cm_mra_get_msg_mraed(mra_msg) != CM_MSG_RESPONSE_OTHER ||
2211 cm_id_priv->id.lap_state != IB_CM_LAP_SENT || 2196 cm_id_priv->id.lap_state != IB_CM_LAP_SENT ||
2212 ib_modify_mad(cm_id_priv->av.port->mad_agent, 2197 ib_modify_mad(cm_id_priv->av.port->mad_agent,
2213 (unsigned long) cm_id_priv->msg, timeout)) 2198 cm_id_priv->msg, timeout))
2214 goto out; 2199 goto out;
2215 cm_id_priv->id.lap_state = IB_CM_MRA_LAP_RCVD; 2200 cm_id_priv->id.lap_state = IB_CM_MRA_LAP_RCVD;
2216 break; 2201 break;
@@ -2273,7 +2258,6 @@ int ib_send_cm_lap(struct ib_cm_id *cm_id,
2273{ 2258{
2274 struct cm_id_private *cm_id_priv; 2259 struct cm_id_private *cm_id_priv;
2275 struct ib_mad_send_buf *msg; 2260 struct ib_mad_send_buf *msg;
2276 struct ib_send_wr *bad_send_wr;
2277 unsigned long flags; 2261 unsigned long flags;
2278 int ret; 2262 int ret;
2279 2263
@@ -2294,11 +2278,10 @@ int ib_send_cm_lap(struct ib_cm_id *cm_id,
2294 2278
2295 cm_format_lap((struct cm_lap_msg *) msg->mad, cm_id_priv, 2279 cm_format_lap((struct cm_lap_msg *) msg->mad, cm_id_priv,
2296 alternate_path, private_data, private_data_len); 2280 alternate_path, private_data, private_data_len);
2297 msg->send_wr.wr.ud.timeout_ms = cm_id_priv->timeout_ms; 2281 msg->timeout_ms = cm_id_priv->timeout_ms;
2298 msg->context[1] = (void *) (unsigned long) IB_CM_ESTABLISHED; 2282 msg->context[1] = (void *) (unsigned long) IB_CM_ESTABLISHED;
2299 2283
2300 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 2284 ret = ib_post_send_mad(msg, NULL);
2301 &msg->send_wr, &bad_send_wr);
2302 if (ret) { 2285 if (ret) {
2303 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 2286 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2304 cm_free_msg(msg); 2287 cm_free_msg(msg);
@@ -2342,7 +2325,6 @@ static int cm_lap_handler(struct cm_work *work)
2342 struct cm_lap_msg *lap_msg; 2325 struct cm_lap_msg *lap_msg;
2343 struct ib_cm_lap_event_param *param; 2326 struct ib_cm_lap_event_param *param;
2344 struct ib_mad_send_buf *msg = NULL; 2327 struct ib_mad_send_buf *msg = NULL;
2345 struct ib_send_wr *bad_send_wr;
2346 unsigned long flags; 2328 unsigned long flags;
2347 int ret; 2329 int ret;
2348 2330
@@ -2376,8 +2358,7 @@ static int cm_lap_handler(struct cm_work *work)
2376 cm_id_priv->private_data_len); 2358 cm_id_priv->private_data_len);
2377 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 2359 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2378 2360
2379 if (ib_post_send_mad(cm_id_priv->av.port->mad_agent, 2361 if (ib_post_send_mad(msg, NULL))
2380 &msg->send_wr, &bad_send_wr))
2381 cm_free_msg(msg); 2362 cm_free_msg(msg);
2382 goto deref; 2363 goto deref;
2383 default: 2364 default:
@@ -2433,7 +2414,6 @@ int ib_send_cm_apr(struct ib_cm_id *cm_id,
2433{ 2414{
2434 struct cm_id_private *cm_id_priv; 2415 struct cm_id_private *cm_id_priv;
2435 struct ib_mad_send_buf *msg; 2416 struct ib_mad_send_buf *msg;
2436 struct ib_send_wr *bad_send_wr;
2437 unsigned long flags; 2417 unsigned long flags;
2438 int ret; 2418 int ret;
2439 2419
@@ -2456,8 +2436,7 @@ int ib_send_cm_apr(struct ib_cm_id *cm_id,
2456 2436
2457 cm_format_apr((struct cm_apr_msg *) msg->mad, cm_id_priv, status, 2437 cm_format_apr((struct cm_apr_msg *) msg->mad, cm_id_priv, status,
2458 info, info_length, private_data, private_data_len); 2438 info, info_length, private_data, private_data_len);
2459 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 2439 ret = ib_post_send_mad(msg, NULL);
2460 &msg->send_wr, &bad_send_wr);
2461 if (ret) { 2440 if (ret) {
2462 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 2441 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2463 cm_free_msg(msg); 2442 cm_free_msg(msg);
@@ -2496,8 +2475,7 @@ static int cm_apr_handler(struct cm_work *work)
2496 goto out; 2475 goto out;
2497 } 2476 }
2498 cm_id_priv->id.lap_state = IB_CM_LAP_IDLE; 2477 cm_id_priv->id.lap_state = IB_CM_LAP_IDLE;
2499 ib_cancel_mad(cm_id_priv->av.port->mad_agent, 2478 ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
2500 (unsigned long) cm_id_priv->msg);
2501 cm_id_priv->msg = NULL; 2479 cm_id_priv->msg = NULL;
2502 2480
2503 ret = atomic_inc_and_test(&cm_id_priv->work_count); 2481 ret = atomic_inc_and_test(&cm_id_priv->work_count);
@@ -2572,7 +2550,6 @@ int ib_send_cm_sidr_req(struct ib_cm_id *cm_id,
2572{ 2550{
2573 struct cm_id_private *cm_id_priv; 2551 struct cm_id_private *cm_id_priv;
2574 struct ib_mad_send_buf *msg; 2552 struct ib_mad_send_buf *msg;
2575 struct ib_send_wr *bad_send_wr;
2576 unsigned long flags; 2553 unsigned long flags;
2577 int ret; 2554 int ret;
2578 2555
@@ -2595,13 +2572,12 @@ int ib_send_cm_sidr_req(struct ib_cm_id *cm_id,
2595 2572
2596 cm_format_sidr_req((struct cm_sidr_req_msg *) msg->mad, cm_id_priv, 2573 cm_format_sidr_req((struct cm_sidr_req_msg *) msg->mad, cm_id_priv,
2597 param); 2574 param);
2598 msg->send_wr.wr.ud.timeout_ms = cm_id_priv->timeout_ms; 2575 msg->timeout_ms = cm_id_priv->timeout_ms;
2599 msg->context[1] = (void *) (unsigned long) IB_CM_SIDR_REQ_SENT; 2576 msg->context[1] = (void *) (unsigned long) IB_CM_SIDR_REQ_SENT;
2600 2577
2601 spin_lock_irqsave(&cm_id_priv->lock, flags); 2578 spin_lock_irqsave(&cm_id_priv->lock, flags);
2602 if (cm_id->state == IB_CM_IDLE) 2579 if (cm_id->state == IB_CM_IDLE)
2603 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 2580 ret = ib_post_send_mad(msg, NULL);
2604 &msg->send_wr, &bad_send_wr);
2605 else 2581 else
2606 ret = -EINVAL; 2582 ret = -EINVAL;
2607 2583
@@ -2629,7 +2605,6 @@ static void cm_format_sidr_req_event(struct cm_work *work,
2629 param = &work->cm_event.param.sidr_req_rcvd; 2605 param = &work->cm_event.param.sidr_req_rcvd;
2630 param->pkey = __be16_to_cpu(sidr_req_msg->pkey); 2606 param->pkey = __be16_to_cpu(sidr_req_msg->pkey);
2631 param->listen_id = listen_id; 2607 param->listen_id = listen_id;
2632 param->device = work->port->mad_agent->device;
2633 param->port = work->port->port_num; 2608 param->port = work->port->port_num;
2634 work->cm_event.private_data = &sidr_req_msg->private_data; 2609 work->cm_event.private_data = &sidr_req_msg->private_data;
2635} 2610}
@@ -2642,7 +2617,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
2642 struct ib_wc *wc; 2617 struct ib_wc *wc;
2643 unsigned long flags; 2618 unsigned long flags;
2644 2619
2645 cm_id = ib_create_cm_id(NULL, NULL); 2620 cm_id = ib_create_cm_id(work->port->cm_dev->device, NULL, NULL);
2646 if (IS_ERR(cm_id)) 2621 if (IS_ERR(cm_id))
2647 return PTR_ERR(cm_id); 2622 return PTR_ERR(cm_id);
2648 cm_id_priv = container_of(cm_id, struct cm_id_private, id); 2623 cm_id_priv = container_of(cm_id, struct cm_id_private, id);
@@ -2666,7 +2641,8 @@ static int cm_sidr_req_handler(struct cm_work *work)
2666 spin_unlock_irqrestore(&cm.lock, flags); 2641 spin_unlock_irqrestore(&cm.lock, flags);
2667 goto out; /* Duplicate message. */ 2642 goto out; /* Duplicate message. */
2668 } 2643 }
2669 cur_cm_id_priv = cm_find_listen(sidr_req_msg->service_id); 2644 cur_cm_id_priv = cm_find_listen(cm_id->device,
2645 sidr_req_msg->service_id);
2670 if (!cur_cm_id_priv) { 2646 if (!cur_cm_id_priv) {
2671 rb_erase(&cm_id_priv->sidr_id_node, &cm.remote_sidr_table); 2647 rb_erase(&cm_id_priv->sidr_id_node, &cm.remote_sidr_table);
2672 spin_unlock_irqrestore(&cm.lock, flags); 2648 spin_unlock_irqrestore(&cm.lock, flags);
@@ -2715,7 +2691,6 @@ int ib_send_cm_sidr_rep(struct ib_cm_id *cm_id,
2715{ 2691{
2716 struct cm_id_private *cm_id_priv; 2692 struct cm_id_private *cm_id_priv;
2717 struct ib_mad_send_buf *msg; 2693 struct ib_mad_send_buf *msg;
2718 struct ib_send_wr *bad_send_wr;
2719 unsigned long flags; 2694 unsigned long flags;
2720 int ret; 2695 int ret;
2721 2696
@@ -2737,8 +2712,7 @@ int ib_send_cm_sidr_rep(struct ib_cm_id *cm_id,
2737 2712
2738 cm_format_sidr_rep((struct cm_sidr_rep_msg *) msg->mad, cm_id_priv, 2713 cm_format_sidr_rep((struct cm_sidr_rep_msg *) msg->mad, cm_id_priv,
2739 param); 2714 param);
2740 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, 2715 ret = ib_post_send_mad(msg, NULL);
2741 &msg->send_wr, &bad_send_wr);
2742 if (ret) { 2716 if (ret) {
2743 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 2717 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2744 cm_free_msg(msg); 2718 cm_free_msg(msg);
@@ -2791,8 +2765,7 @@ static int cm_sidr_rep_handler(struct cm_work *work)
2791 goto out; 2765 goto out;
2792 } 2766 }
2793 cm_id_priv->id.state = IB_CM_IDLE; 2767 cm_id_priv->id.state = IB_CM_IDLE;
2794 ib_cancel_mad(cm_id_priv->av.port->mad_agent, 2768 ib_cancel_mad(cm_id_priv->av.port->mad_agent, cm_id_priv->msg);
2795 (unsigned long) cm_id_priv->msg);
2796 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 2769 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2797 2770
2798 cm_format_sidr_rep_event(work); 2771 cm_format_sidr_rep_event(work);
@@ -2860,9 +2833,7 @@ discard:
2860static void cm_send_handler(struct ib_mad_agent *mad_agent, 2833static void cm_send_handler(struct ib_mad_agent *mad_agent,
2861 struct ib_mad_send_wc *mad_send_wc) 2834 struct ib_mad_send_wc *mad_send_wc)
2862{ 2835{
2863 struct ib_mad_send_buf *msg; 2836 struct ib_mad_send_buf *msg = mad_send_wc->send_buf;
2864
2865 msg = (struct ib_mad_send_buf *)(unsigned long)mad_send_wc->wr_id;
2866 2837
2867 switch (mad_send_wc->status) { 2838 switch (mad_send_wc->status) {
2868 case IB_WC_SUCCESS: 2839 case IB_WC_SUCCESS:
@@ -3064,10 +3035,10 @@ static int cm_init_qp_init_attr(struct cm_id_private *cm_id_priv,
3064 case IB_CM_ESTABLISHED: 3035 case IB_CM_ESTABLISHED:
3065 *qp_attr_mask = IB_QP_STATE | IB_QP_ACCESS_FLAGS | 3036 *qp_attr_mask = IB_QP_STATE | IB_QP_ACCESS_FLAGS |
3066 IB_QP_PKEY_INDEX | IB_QP_PORT; 3037 IB_QP_PKEY_INDEX | IB_QP_PORT;
3067 qp_attr->qp_access_flags = IB_ACCESS_LOCAL_WRITE; 3038 qp_attr->qp_access_flags = IB_ACCESS_LOCAL_WRITE |
3039 IB_ACCESS_REMOTE_WRITE;
3068 if (cm_id_priv->responder_resources) 3040 if (cm_id_priv->responder_resources)
3069 qp_attr->qp_access_flags |= IB_ACCESS_REMOTE_WRITE | 3041 qp_attr->qp_access_flags |= IB_ACCESS_REMOTE_READ;
3070 IB_ACCESS_REMOTE_READ;
3071 qp_attr->pkey_index = cm_id_priv->av.pkey_index; 3042 qp_attr->pkey_index = cm_id_priv->av.pkey_index;
3072 qp_attr->port_num = cm_id_priv->av.port->port_num; 3043 qp_attr->port_num = cm_id_priv->av.port->port_num;
3073 ret = 0; 3044 ret = 0;
@@ -3097,14 +3068,18 @@ static int cm_init_qp_rtr_attr(struct cm_id_private *cm_id_priv,
3097 case IB_CM_MRA_REP_RCVD: 3068 case IB_CM_MRA_REP_RCVD:
3098 case IB_CM_ESTABLISHED: 3069 case IB_CM_ESTABLISHED:
3099 *qp_attr_mask = IB_QP_STATE | IB_QP_AV | IB_QP_PATH_MTU | 3070 *qp_attr_mask = IB_QP_STATE | IB_QP_AV | IB_QP_PATH_MTU |
3100 IB_QP_DEST_QPN | IB_QP_RQ_PSN | 3071 IB_QP_DEST_QPN | IB_QP_RQ_PSN;
3101 IB_QP_MAX_DEST_RD_ATOMIC | IB_QP_MIN_RNR_TIMER;
3102 qp_attr->ah_attr = cm_id_priv->av.ah_attr; 3072 qp_attr->ah_attr = cm_id_priv->av.ah_attr;
3103 qp_attr->path_mtu = cm_id_priv->path_mtu; 3073 qp_attr->path_mtu = cm_id_priv->path_mtu;
3104 qp_attr->dest_qp_num = be32_to_cpu(cm_id_priv->remote_qpn); 3074 qp_attr->dest_qp_num = be32_to_cpu(cm_id_priv->remote_qpn);
3105 qp_attr->rq_psn = be32_to_cpu(cm_id_priv->rq_psn); 3075 qp_attr->rq_psn = be32_to_cpu(cm_id_priv->rq_psn);
3106 qp_attr->max_dest_rd_atomic = cm_id_priv->responder_resources; 3076 if (cm_id_priv->qp_type == IB_QPT_RC) {
3107 qp_attr->min_rnr_timer = 0; 3077 *qp_attr_mask |= IB_QP_MAX_DEST_RD_ATOMIC |
3078 IB_QP_MIN_RNR_TIMER;
3079 qp_attr->max_dest_rd_atomic =
3080 cm_id_priv->responder_resources;
3081 qp_attr->min_rnr_timer = 0;
3082 }
3108 if (cm_id_priv->alt_av.ah_attr.dlid) { 3083 if (cm_id_priv->alt_av.ah_attr.dlid) {
3109 *qp_attr_mask |= IB_QP_ALT_PATH; 3084 *qp_attr_mask |= IB_QP_ALT_PATH;
3110 qp_attr->alt_ah_attr = cm_id_priv->alt_av.ah_attr; 3085 qp_attr->alt_ah_attr = cm_id_priv->alt_av.ah_attr;
@@ -3133,14 +3108,17 @@ static int cm_init_qp_rts_attr(struct cm_id_private *cm_id_priv,
3133 case IB_CM_REP_SENT: 3108 case IB_CM_REP_SENT:
3134 case IB_CM_MRA_REP_RCVD: 3109 case IB_CM_MRA_REP_RCVD:
3135 case IB_CM_ESTABLISHED: 3110 case IB_CM_ESTABLISHED:
3136 *qp_attr_mask = IB_QP_STATE | IB_QP_TIMEOUT | IB_QP_RETRY_CNT | 3111 *qp_attr_mask = IB_QP_STATE | IB_QP_SQ_PSN;
3137 IB_QP_RNR_RETRY | IB_QP_SQ_PSN |
3138 IB_QP_MAX_QP_RD_ATOMIC;
3139 qp_attr->timeout = cm_id_priv->local_ack_timeout;
3140 qp_attr->retry_cnt = cm_id_priv->retry_count;
3141 qp_attr->rnr_retry = cm_id_priv->rnr_retry_count;
3142 qp_attr->sq_psn = be32_to_cpu(cm_id_priv->sq_psn); 3112 qp_attr->sq_psn = be32_to_cpu(cm_id_priv->sq_psn);
3143 qp_attr->max_rd_atomic = cm_id_priv->initiator_depth; 3113 if (cm_id_priv->qp_type == IB_QPT_RC) {
3114 *qp_attr_mask |= IB_QP_TIMEOUT | IB_QP_RETRY_CNT |
3115 IB_QP_RNR_RETRY |
3116 IB_QP_MAX_QP_RD_ATOMIC;
3117 qp_attr->timeout = cm_id_priv->local_ack_timeout;
3118 qp_attr->retry_cnt = cm_id_priv->retry_count;
3119 qp_attr->rnr_retry = cm_id_priv->rnr_retry_count;
3120 qp_attr->max_rd_atomic = cm_id_priv->initiator_depth;
3121 }
3144 if (cm_id_priv->alt_av.ah_attr.dlid) { 3122 if (cm_id_priv->alt_av.ah_attr.dlid) {
3145 *qp_attr_mask |= IB_QP_PATH_MIG_STATE; 3123 *qp_attr_mask |= IB_QP_PATH_MIG_STATE;
3146 qp_attr->path_mig_state = IB_MIG_REARM; 3124 qp_attr->path_mig_state = IB_MIG_REARM;
@@ -3323,6 +3301,7 @@ static void __exit ib_cm_cleanup(void)
3323 flush_workqueue(cm.wq); 3301 flush_workqueue(cm.wq);
3324 destroy_workqueue(cm.wq); 3302 destroy_workqueue(cm.wq);
3325 ib_unregister_client(&cm_client); 3303 ib_unregister_client(&cm_client);
3304 idr_destroy(&cm.local_id_table);
3326} 3305}
3327 3306
3328module_init(ib_cm_init); 3307module_init(ib_cm_init);
diff --git a/drivers/infiniband/core/cm_msgs.h b/drivers/infiniband/core/cm_msgs.h
index 813ab70bf6d5..4d3aee90c249 100644
--- a/drivers/infiniband/core/cm_msgs.h
+++ b/drivers/infiniband/core/cm_msgs.h
@@ -186,6 +186,7 @@ static inline void cm_req_set_qp_type(struct cm_req_msg *req_msg,
186 req_msg->offset40 = cpu_to_be32((be32_to_cpu( 186 req_msg->offset40 = cpu_to_be32((be32_to_cpu(
187 req_msg->offset40) & 187 req_msg->offset40) &
188 0xFFFFFFF9) | 0x2); 188 0xFFFFFFF9) | 0x2);
189 break;
189 default: 190 default:
190 req_msg->offset40 = cpu_to_be32(be32_to_cpu( 191 req_msg->offset40 = cpu_to_be32(be32_to_cpu(
191 req_msg->offset40) & 192 req_msg->offset40) &
diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index d3cf84e01587..5a6e44976405 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -514,6 +514,12 @@ int ib_query_port(struct ib_device *device,
514 u8 port_num, 514 u8 port_num,
515 struct ib_port_attr *port_attr) 515 struct ib_port_attr *port_attr)
516{ 516{
517 if (device->node_type == IB_NODE_SWITCH) {
518 if (port_num)
519 return -EINVAL;
520 } else if (port_num < 1 || port_num > device->phys_port_cnt)
521 return -EINVAL;
522
517 return device->query_port(device, port_num, port_attr); 523 return device->query_port(device, port_num, port_attr);
518} 524}
519EXPORT_SYMBOL(ib_query_port); 525EXPORT_SYMBOL(ib_query_port);
@@ -583,6 +589,12 @@ int ib_modify_port(struct ib_device *device,
583 u8 port_num, int port_modify_mask, 589 u8 port_num, int port_modify_mask,
584 struct ib_port_modify *port_modify) 590 struct ib_port_modify *port_modify)
585{ 591{
592 if (device->node_type == IB_NODE_SWITCH) {
593 if (port_num)
594 return -EINVAL;
595 } else if (port_num < 1 || port_num > device->phys_port_cnt)
596 return -EINVAL;
597
586 return device->modify_port(device, port_num, port_modify_mask, 598 return device->modify_port(device, port_num, port_modify_mask,
587 port_modify); 599 port_modify);
588} 600}
diff --git a/drivers/infiniband/core/mad.c b/drivers/infiniband/core/mad.c
index a14ca87fda18..88f9f8c9eacc 100644
--- a/drivers/infiniband/core/mad.c
+++ b/drivers/infiniband/core/mad.c
@@ -579,7 +579,7 @@ static void dequeue_mad(struct ib_mad_list_head *mad_list)
579} 579}
580 580
581static void snoop_send(struct ib_mad_qp_info *qp_info, 581static void snoop_send(struct ib_mad_qp_info *qp_info,
582 struct ib_send_wr *send_wr, 582 struct ib_mad_send_buf *send_buf,
583 struct ib_mad_send_wc *mad_send_wc, 583 struct ib_mad_send_wc *mad_send_wc,
584 int mad_snoop_flags) 584 int mad_snoop_flags)
585{ 585{
@@ -597,7 +597,7 @@ static void snoop_send(struct ib_mad_qp_info *qp_info,
597 atomic_inc(&mad_snoop_priv->refcount); 597 atomic_inc(&mad_snoop_priv->refcount);
598 spin_unlock_irqrestore(&qp_info->snoop_lock, flags); 598 spin_unlock_irqrestore(&qp_info->snoop_lock, flags);
599 mad_snoop_priv->agent.snoop_handler(&mad_snoop_priv->agent, 599 mad_snoop_priv->agent.snoop_handler(&mad_snoop_priv->agent,
600 send_wr, mad_send_wc); 600 send_buf, mad_send_wc);
601 if (atomic_dec_and_test(&mad_snoop_priv->refcount)) 601 if (atomic_dec_and_test(&mad_snoop_priv->refcount))
602 wake_up(&mad_snoop_priv->wait); 602 wake_up(&mad_snoop_priv->wait);
603 spin_lock_irqsave(&qp_info->snoop_lock, flags); 603 spin_lock_irqsave(&qp_info->snoop_lock, flags);
@@ -654,10 +654,10 @@ static void build_smp_wc(u64 wr_id, u16 slid, u16 pkey_index, u8 port_num,
654 * Return < 0 if error 654 * Return < 0 if error
655 */ 655 */
656static int handle_outgoing_dr_smp(struct ib_mad_agent_private *mad_agent_priv, 656static int handle_outgoing_dr_smp(struct ib_mad_agent_private *mad_agent_priv,
657 struct ib_smp *smp, 657 struct ib_mad_send_wr_private *mad_send_wr)
658 struct ib_send_wr *send_wr)
659{ 658{
660 int ret; 659 int ret;
660 struct ib_smp *smp = mad_send_wr->send_buf.mad;
661 unsigned long flags; 661 unsigned long flags;
662 struct ib_mad_local_private *local; 662 struct ib_mad_local_private *local;
663 struct ib_mad_private *mad_priv; 663 struct ib_mad_private *mad_priv;
@@ -666,6 +666,7 @@ static int handle_outgoing_dr_smp(struct ib_mad_agent_private *mad_agent_priv,
666 struct ib_device *device = mad_agent_priv->agent.device; 666 struct ib_device *device = mad_agent_priv->agent.device;
667 u8 port_num = mad_agent_priv->agent.port_num; 667 u8 port_num = mad_agent_priv->agent.port_num;
668 struct ib_wc mad_wc; 668 struct ib_wc mad_wc;
669 struct ib_send_wr *send_wr = &mad_send_wr->send_wr;
669 670
670 if (!smi_handle_dr_smp_send(smp, device->node_type, port_num)) { 671 if (!smi_handle_dr_smp_send(smp, device->node_type, port_num)) {
671 ret = -EINVAL; 672 ret = -EINVAL;
@@ -745,13 +746,7 @@ static int handle_outgoing_dr_smp(struct ib_mad_agent_private *mad_agent_priv,
745 goto out; 746 goto out;
746 } 747 }
747 748
748 local->send_wr = *send_wr; 749 local->mad_send_wr = mad_send_wr;
749 local->send_wr.sg_list = local->sg_list;
750 memcpy(local->sg_list, send_wr->sg_list,
751 sizeof *send_wr->sg_list * send_wr->num_sge);
752 local->send_wr.next = NULL;
753 local->tid = send_wr->wr.ud.mad_hdr->tid;
754 local->wr_id = send_wr->wr_id;
755 /* Reference MAD agent until send side of local completion handled */ 750 /* Reference MAD agent until send side of local completion handled */
756 atomic_inc(&mad_agent_priv->refcount); 751 atomic_inc(&mad_agent_priv->refcount);
757 /* Queue local completion to local list */ 752 /* Queue local completion to local list */
@@ -781,17 +776,17 @@ static int get_buf_length(int hdr_len, int data_len)
781 776
782struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent, 777struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent,
783 u32 remote_qpn, u16 pkey_index, 778 u32 remote_qpn, u16 pkey_index,
784 struct ib_ah *ah, int rmpp_active, 779 int rmpp_active,
785 int hdr_len, int data_len, 780 int hdr_len, int data_len,
786 gfp_t gfp_mask) 781 gfp_t gfp_mask)
787{ 782{
788 struct ib_mad_agent_private *mad_agent_priv; 783 struct ib_mad_agent_private *mad_agent_priv;
789 struct ib_mad_send_buf *send_buf; 784 struct ib_mad_send_wr_private *mad_send_wr;
790 int buf_size; 785 int buf_size;
791 void *buf; 786 void *buf;
792 787
793 mad_agent_priv = container_of(mad_agent, 788 mad_agent_priv = container_of(mad_agent, struct ib_mad_agent_private,
794 struct ib_mad_agent_private, agent); 789 agent);
795 buf_size = get_buf_length(hdr_len, data_len); 790 buf_size = get_buf_length(hdr_len, data_len);
796 791
797 if ((!mad_agent->rmpp_version && 792 if ((!mad_agent->rmpp_version &&
@@ -799,45 +794,40 @@ struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent,
799 (!rmpp_active && buf_size > sizeof(struct ib_mad))) 794 (!rmpp_active && buf_size > sizeof(struct ib_mad)))
800 return ERR_PTR(-EINVAL); 795 return ERR_PTR(-EINVAL);
801 796
802 buf = kmalloc(sizeof *send_buf + buf_size, gfp_mask); 797 buf = kmalloc(sizeof *mad_send_wr + buf_size, gfp_mask);
803 if (!buf) 798 if (!buf)
804 return ERR_PTR(-ENOMEM); 799 return ERR_PTR(-ENOMEM);
805 memset(buf, 0, sizeof *send_buf + buf_size); 800 memset(buf, 0, sizeof *mad_send_wr + buf_size);
806 801
807 send_buf = buf + buf_size; 802 mad_send_wr = buf + buf_size;
808 send_buf->mad = buf; 803 mad_send_wr->send_buf.mad = buf;
809 804
810 send_buf->sge.addr = dma_map_single(mad_agent->device->dma_device, 805 mad_send_wr->mad_agent_priv = mad_agent_priv;
811 buf, buf_size, DMA_TO_DEVICE); 806 mad_send_wr->sg_list[0].length = buf_size;
812 pci_unmap_addr_set(send_buf, mapping, send_buf->sge.addr); 807 mad_send_wr->sg_list[0].lkey = mad_agent->mr->lkey;
813 send_buf->sge.length = buf_size; 808
814 send_buf->sge.lkey = mad_agent->mr->lkey; 809 mad_send_wr->send_wr.wr_id = (unsigned long) mad_send_wr;
815 810 mad_send_wr->send_wr.sg_list = mad_send_wr->sg_list;
816 send_buf->send_wr.wr_id = (unsigned long) send_buf; 811 mad_send_wr->send_wr.num_sge = 1;
817 send_buf->send_wr.sg_list = &send_buf->sge; 812 mad_send_wr->send_wr.opcode = IB_WR_SEND;
818 send_buf->send_wr.num_sge = 1; 813 mad_send_wr->send_wr.send_flags = IB_SEND_SIGNALED;
819 send_buf->send_wr.opcode = IB_WR_SEND; 814 mad_send_wr->send_wr.wr.ud.remote_qpn = remote_qpn;
820 send_buf->send_wr.send_flags = IB_SEND_SIGNALED; 815 mad_send_wr->send_wr.wr.ud.remote_qkey = IB_QP_SET_QKEY;
821 send_buf->send_wr.wr.ud.ah = ah; 816 mad_send_wr->send_wr.wr.ud.pkey_index = pkey_index;
822 send_buf->send_wr.wr.ud.mad_hdr = &send_buf->mad->mad_hdr;
823 send_buf->send_wr.wr.ud.remote_qpn = remote_qpn;
824 send_buf->send_wr.wr.ud.remote_qkey = IB_QP_SET_QKEY;
825 send_buf->send_wr.wr.ud.pkey_index = pkey_index;
826 817
827 if (rmpp_active) { 818 if (rmpp_active) {
828 struct ib_rmpp_mad *rmpp_mad; 819 struct ib_rmpp_mad *rmpp_mad = mad_send_wr->send_buf.mad;
829 rmpp_mad = (struct ib_rmpp_mad *)send_buf->mad;
830 rmpp_mad->rmpp_hdr.paylen_newwin = cpu_to_be32(hdr_len - 820 rmpp_mad->rmpp_hdr.paylen_newwin = cpu_to_be32(hdr_len -
831 offsetof(struct ib_rmpp_mad, data) + data_len); 821 IB_MGMT_RMPP_HDR + data_len);
832 rmpp_mad->rmpp_hdr.rmpp_version = mad_agent->rmpp_version; 822 rmpp_mad->rmpp_hdr.rmpp_version = mad_agent->rmpp_version;
833 rmpp_mad->rmpp_hdr.rmpp_type = IB_MGMT_RMPP_TYPE_DATA; 823 rmpp_mad->rmpp_hdr.rmpp_type = IB_MGMT_RMPP_TYPE_DATA;
834 ib_set_rmpp_flags(&rmpp_mad->rmpp_hdr, 824 ib_set_rmpp_flags(&rmpp_mad->rmpp_hdr,
835 IB_MGMT_RMPP_FLAG_ACTIVE); 825 IB_MGMT_RMPP_FLAG_ACTIVE);
836 } 826 }
837 827
838 send_buf->mad_agent = mad_agent; 828 mad_send_wr->send_buf.mad_agent = mad_agent;
839 atomic_inc(&mad_agent_priv->refcount); 829 atomic_inc(&mad_agent_priv->refcount);
840 return send_buf; 830 return &mad_send_wr->send_buf;
841} 831}
842EXPORT_SYMBOL(ib_create_send_mad); 832EXPORT_SYMBOL(ib_create_send_mad);
843 833
@@ -847,10 +837,6 @@ void ib_free_send_mad(struct ib_mad_send_buf *send_buf)
847 837
848 mad_agent_priv = container_of(send_buf->mad_agent, 838 mad_agent_priv = container_of(send_buf->mad_agent,
849 struct ib_mad_agent_private, agent); 839 struct ib_mad_agent_private, agent);
850
851 dma_unmap_single(send_buf->mad_agent->device->dma_device,
852 pci_unmap_addr(send_buf, mapping),
853 send_buf->sge.length, DMA_TO_DEVICE);
854 kfree(send_buf->mad); 840 kfree(send_buf->mad);
855 841
856 if (atomic_dec_and_test(&mad_agent_priv->refcount)) 842 if (atomic_dec_and_test(&mad_agent_priv->refcount))
@@ -861,8 +847,10 @@ EXPORT_SYMBOL(ib_free_send_mad);
861int ib_send_mad(struct ib_mad_send_wr_private *mad_send_wr) 847int ib_send_mad(struct ib_mad_send_wr_private *mad_send_wr)
862{ 848{
863 struct ib_mad_qp_info *qp_info; 849 struct ib_mad_qp_info *qp_info;
864 struct ib_send_wr *bad_send_wr;
865 struct list_head *list; 850 struct list_head *list;
851 struct ib_send_wr *bad_send_wr;
852 struct ib_mad_agent *mad_agent;
853 struct ib_sge *sge;
866 unsigned long flags; 854 unsigned long flags;
867 int ret; 855 int ret;
868 856
@@ -871,10 +859,17 @@ int ib_send_mad(struct ib_mad_send_wr_private *mad_send_wr)
871 mad_send_wr->send_wr.wr_id = (unsigned long)&mad_send_wr->mad_list; 859 mad_send_wr->send_wr.wr_id = (unsigned long)&mad_send_wr->mad_list;
872 mad_send_wr->mad_list.mad_queue = &qp_info->send_queue; 860 mad_send_wr->mad_list.mad_queue = &qp_info->send_queue;
873 861
862 mad_agent = mad_send_wr->send_buf.mad_agent;
863 sge = mad_send_wr->sg_list;
864 sge->addr = dma_map_single(mad_agent->device->dma_device,
865 mad_send_wr->send_buf.mad, sge->length,
866 DMA_TO_DEVICE);
867 pci_unmap_addr_set(mad_send_wr, mapping, sge->addr);
868
874 spin_lock_irqsave(&qp_info->send_queue.lock, flags); 869 spin_lock_irqsave(&qp_info->send_queue.lock, flags);
875 if (qp_info->send_queue.count < qp_info->send_queue.max_active) { 870 if (qp_info->send_queue.count < qp_info->send_queue.max_active) {
876 ret = ib_post_send(mad_send_wr->mad_agent_priv->agent.qp, 871 ret = ib_post_send(mad_agent->qp, &mad_send_wr->send_wr,
877 &mad_send_wr->send_wr, &bad_send_wr); 872 &bad_send_wr);
878 list = &qp_info->send_queue.list; 873 list = &qp_info->send_queue.list;
879 } else { 874 } else {
880 ret = 0; 875 ret = 0;
@@ -886,6 +881,11 @@ int ib_send_mad(struct ib_mad_send_wr_private *mad_send_wr)
886 list_add_tail(&mad_send_wr->mad_list.list, list); 881 list_add_tail(&mad_send_wr->mad_list.list, list);
887 } 882 }
888 spin_unlock_irqrestore(&qp_info->send_queue.lock, flags); 883 spin_unlock_irqrestore(&qp_info->send_queue.lock, flags);
884 if (ret)
885 dma_unmap_single(mad_agent->device->dma_device,
886 pci_unmap_addr(mad_send_wr, mapping),
887 sge->length, DMA_TO_DEVICE);
888
889 return ret; 889 return ret;
890} 890}
891 891
@@ -893,45 +893,28 @@ int ib_send_mad(struct ib_mad_send_wr_private *mad_send_wr)
893 * ib_post_send_mad - Posts MAD(s) to the send queue of the QP associated 893 * ib_post_send_mad - Posts MAD(s) to the send queue of the QP associated
894 * with the registered client 894 * with the registered client
895 */ 895 */
896int ib_post_send_mad(struct ib_mad_agent *mad_agent, 896int ib_post_send_mad(struct ib_mad_send_buf *send_buf,
897 struct ib_send_wr *send_wr, 897 struct ib_mad_send_buf **bad_send_buf)
898 struct ib_send_wr **bad_send_wr)
899{ 898{
900 int ret = -EINVAL;
901 struct ib_mad_agent_private *mad_agent_priv; 899 struct ib_mad_agent_private *mad_agent_priv;
902 900 struct ib_mad_send_buf *next_send_buf;
903 /* Validate supplied parameters */ 901 struct ib_mad_send_wr_private *mad_send_wr;
904 if (!bad_send_wr) 902 unsigned long flags;
905 goto error1; 903 int ret = -EINVAL;
906
907 if (!mad_agent || !send_wr)
908 goto error2;
909
910 if (!mad_agent->send_handler)
911 goto error2;
912
913 mad_agent_priv = container_of(mad_agent,
914 struct ib_mad_agent_private,
915 agent);
916 904
917 /* Walk list of send WRs and post each on send list */ 905 /* Walk list of send WRs and post each on send list */
918 while (send_wr) { 906 for (; send_buf; send_buf = next_send_buf) {
919 unsigned long flags;
920 struct ib_send_wr *next_send_wr;
921 struct ib_mad_send_wr_private *mad_send_wr;
922 struct ib_smp *smp;
923
924 /* Validate more parameters */
925 if (send_wr->num_sge > IB_MAD_SEND_REQ_MAX_SG)
926 goto error2;
927 907
928 if (send_wr->wr.ud.timeout_ms && !mad_agent->recv_handler) 908 mad_send_wr = container_of(send_buf,
929 goto error2; 909 struct ib_mad_send_wr_private,
930 910 send_buf);
931 if (!send_wr->wr.ud.mad_hdr) { 911 mad_agent_priv = mad_send_wr->mad_agent_priv;
932 printk(KERN_ERR PFX "MAD header must be supplied " 912
933 "in WR %p\n", send_wr); 913 if (!send_buf->mad_agent->send_handler ||
934 goto error2; 914 (send_buf->timeout_ms &&
915 !send_buf->mad_agent->recv_handler)) {
916 ret = -EINVAL;
917 goto error;
935 } 918 }
936 919
937 /* 920 /*
@@ -939,40 +922,24 @@ int ib_post_send_mad(struct ib_mad_agent *mad_agent,
939 * current one completes, and the user modifies the work 922 * current one completes, and the user modifies the work
940 * request associated with the completion 923 * request associated with the completion
941 */ 924 */
942 next_send_wr = (struct ib_send_wr *)send_wr->next; 925 next_send_buf = send_buf->next;
926 mad_send_wr->send_wr.wr.ud.ah = send_buf->ah;
943 927
944 smp = (struct ib_smp *)send_wr->wr.ud.mad_hdr; 928 if (((struct ib_mad_hdr *) send_buf->mad)->mgmt_class ==
945 if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) { 929 IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) {
946 ret = handle_outgoing_dr_smp(mad_agent_priv, smp, 930 ret = handle_outgoing_dr_smp(mad_agent_priv,
947 send_wr); 931 mad_send_wr);
948 if (ret < 0) /* error */ 932 if (ret < 0) /* error */
949 goto error2; 933 goto error;
950 else if (ret == 1) /* locally consumed */ 934 else if (ret == 1) /* locally consumed */
951 goto next; 935 continue;
952 } 936 }
953 937
954 /* Allocate MAD send WR tracking structure */ 938 mad_send_wr->tid = ((struct ib_mad_hdr *) send_buf->mad)->tid;
955 mad_send_wr = kmalloc(sizeof *mad_send_wr, GFP_ATOMIC);
956 if (!mad_send_wr) {
957 printk(KERN_ERR PFX "No memory for "
958 "ib_mad_send_wr_private\n");
959 ret = -ENOMEM;
960 goto error2;
961 }
962 memset(mad_send_wr, 0, sizeof *mad_send_wr);
963
964 mad_send_wr->send_wr = *send_wr;
965 mad_send_wr->send_wr.sg_list = mad_send_wr->sg_list;
966 memcpy(mad_send_wr->sg_list, send_wr->sg_list,
967 sizeof *send_wr->sg_list * send_wr->num_sge);
968 mad_send_wr->wr_id = send_wr->wr_id;
969 mad_send_wr->tid = send_wr->wr.ud.mad_hdr->tid;
970 mad_send_wr->mad_agent_priv = mad_agent_priv;
971 /* Timeout will be updated after send completes */ 939 /* Timeout will be updated after send completes */
972 mad_send_wr->timeout = msecs_to_jiffies(send_wr->wr. 940 mad_send_wr->timeout = msecs_to_jiffies(send_buf->timeout_ms);
973 ud.timeout_ms); 941 mad_send_wr->retries = send_buf->retries;
974 mad_send_wr->retries = mad_send_wr->send_wr.wr.ud.retries; 942 /* Reference for work request to QP + response */
975 /* One reference for each work request to QP + response */
976 mad_send_wr->refcount = 1 + (mad_send_wr->timeout > 0); 943 mad_send_wr->refcount = 1 + (mad_send_wr->timeout > 0);
977 mad_send_wr->status = IB_WC_SUCCESS; 944 mad_send_wr->status = IB_WC_SUCCESS;
978 945
@@ -995,16 +962,13 @@ int ib_post_send_mad(struct ib_mad_agent *mad_agent,
995 list_del(&mad_send_wr->agent_list); 962 list_del(&mad_send_wr->agent_list);
996 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); 963 spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
997 atomic_dec(&mad_agent_priv->refcount); 964 atomic_dec(&mad_agent_priv->refcount);
998 goto error2; 965 goto error;
999 } 966 }
1000next:
1001 send_wr = next_send_wr;
1002 } 967 }
1003 return 0; 968 return 0;
1004 969error:
1005error2: 970 if (bad_send_buf)
1006 *bad_send_wr = send_wr; 971 *bad_send_buf = send_buf;
1007error1:
1008 return ret; 972 return ret;
1009} 973}
1010EXPORT_SYMBOL(ib_post_send_mad); 974EXPORT_SYMBOL(ib_post_send_mad);
@@ -1447,8 +1411,7 @@ find_mad_agent(struct ib_mad_port_private *port_priv,
1447 * of MAD. 1411 * of MAD.
1448 */ 1412 */
1449 hi_tid = be64_to_cpu(mad->mad_hdr.tid) >> 32; 1413 hi_tid = be64_to_cpu(mad->mad_hdr.tid) >> 32;
1450 list_for_each_entry(entry, &port_priv->agent_list, 1414 list_for_each_entry(entry, &port_priv->agent_list, agent_list) {
1451 agent_list) {
1452 if (entry->agent.hi_tid == hi_tid) { 1415 if (entry->agent.hi_tid == hi_tid) {
1453 mad_agent = entry; 1416 mad_agent = entry;
1454 break; 1417 break;
@@ -1571,8 +1534,7 @@ ib_find_send_mad(struct ib_mad_agent_private *mad_agent_priv, __be64 tid)
1571 */ 1534 */
1572 list_for_each_entry(mad_send_wr, &mad_agent_priv->send_list, 1535 list_for_each_entry(mad_send_wr, &mad_agent_priv->send_list,
1573 agent_list) { 1536 agent_list) {
1574 if (is_data_mad(mad_agent_priv, 1537 if (is_data_mad(mad_agent_priv, mad_send_wr->send_buf.mad) &&
1575 mad_send_wr->send_wr.wr.ud.mad_hdr) &&
1576 mad_send_wr->tid == tid && mad_send_wr->timeout) { 1538 mad_send_wr->tid == tid && mad_send_wr->timeout) {
1577 /* Verify request has not been canceled */ 1539 /* Verify request has not been canceled */
1578 return (mad_send_wr->status == IB_WC_SUCCESS) ? 1540 return (mad_send_wr->status == IB_WC_SUCCESS) ?
@@ -1628,14 +1590,14 @@ static void ib_mad_complete_recv(struct ib_mad_agent_private *mad_agent_priv,
1628 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); 1590 spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
1629 1591
1630 /* Defined behavior is to complete response before request */ 1592 /* Defined behavior is to complete response before request */
1631 mad_recv_wc->wc->wr_id = mad_send_wr->wr_id; 1593 mad_recv_wc->wc->wr_id = (unsigned long) &mad_send_wr->send_buf;
1632 mad_agent_priv->agent.recv_handler(&mad_agent_priv->agent, 1594 mad_agent_priv->agent.recv_handler(&mad_agent_priv->agent,
1633 mad_recv_wc); 1595 mad_recv_wc);
1634 atomic_dec(&mad_agent_priv->refcount); 1596 atomic_dec(&mad_agent_priv->refcount);
1635 1597
1636 mad_send_wc.status = IB_WC_SUCCESS; 1598 mad_send_wc.status = IB_WC_SUCCESS;
1637 mad_send_wc.vendor_err = 0; 1599 mad_send_wc.vendor_err = 0;
1638 mad_send_wc.wr_id = mad_send_wr->wr_id; 1600 mad_send_wc.send_buf = &mad_send_wr->send_buf;
1639 ib_mad_complete_send_wr(mad_send_wr, &mad_send_wc); 1601 ib_mad_complete_send_wr(mad_send_wr, &mad_send_wc);
1640 } else { 1602 } else {
1641 mad_agent_priv->agent.recv_handler(&mad_agent_priv->agent, 1603 mad_agent_priv->agent.recv_handler(&mad_agent_priv->agent,
@@ -1728,11 +1690,11 @@ local:
1728 if (ret & IB_MAD_RESULT_CONSUMED) 1690 if (ret & IB_MAD_RESULT_CONSUMED)
1729 goto out; 1691 goto out;
1730 if (ret & IB_MAD_RESULT_REPLY) { 1692 if (ret & IB_MAD_RESULT_REPLY) {
1731 /* Send response */ 1693 agent_send_response(&response->mad.mad,
1732 if (!agent_send(response, &recv->grh, wc, 1694 &recv->grh, wc,
1733 port_priv->device, 1695 port_priv->device,
1734 port_priv->port_num)) 1696 port_priv->port_num,
1735 response = NULL; 1697 qp_info->qp->qp_num);
1736 goto out; 1698 goto out;
1737 } 1699 }
1738 } 1700 }
@@ -1866,15 +1828,15 @@ void ib_mad_complete_send_wr(struct ib_mad_send_wr_private *mad_send_wr,
1866 1828
1867 if (mad_send_wr->status != IB_WC_SUCCESS ) 1829 if (mad_send_wr->status != IB_WC_SUCCESS )
1868 mad_send_wc->status = mad_send_wr->status; 1830 mad_send_wc->status = mad_send_wr->status;
1869 if (ret != IB_RMPP_RESULT_INTERNAL) 1831 if (ret == IB_RMPP_RESULT_INTERNAL)
1832 ib_rmpp_send_handler(mad_send_wc);
1833 else
1870 mad_agent_priv->agent.send_handler(&mad_agent_priv->agent, 1834 mad_agent_priv->agent.send_handler(&mad_agent_priv->agent,
1871 mad_send_wc); 1835 mad_send_wc);
1872 1836
1873 /* Release reference on agent taken when sending */ 1837 /* Release reference on agent taken when sending */
1874 if (atomic_dec_and_test(&mad_agent_priv->refcount)) 1838 if (atomic_dec_and_test(&mad_agent_priv->refcount))
1875 wake_up(&mad_agent_priv->wait); 1839 wake_up(&mad_agent_priv->wait);
1876
1877 kfree(mad_send_wr);
1878 return; 1840 return;
1879done: 1841done:
1880 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); 1842 spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
@@ -1888,6 +1850,7 @@ static void ib_mad_send_done_handler(struct ib_mad_port_private *port_priv,
1888 struct ib_mad_qp_info *qp_info; 1850 struct ib_mad_qp_info *qp_info;
1889 struct ib_mad_queue *send_queue; 1851 struct ib_mad_queue *send_queue;
1890 struct ib_send_wr *bad_send_wr; 1852 struct ib_send_wr *bad_send_wr;
1853 struct ib_mad_send_wc mad_send_wc;
1891 unsigned long flags; 1854 unsigned long flags;
1892 int ret; 1855 int ret;
1893 1856
@@ -1898,6 +1861,9 @@ static void ib_mad_send_done_handler(struct ib_mad_port_private *port_priv,
1898 qp_info = send_queue->qp_info; 1861 qp_info = send_queue->qp_info;
1899 1862
1900retry: 1863retry:
1864 dma_unmap_single(mad_send_wr->send_buf.mad_agent->device->dma_device,
1865 pci_unmap_addr(mad_send_wr, mapping),
1866 mad_send_wr->sg_list[0].length, DMA_TO_DEVICE);
1901 queued_send_wr = NULL; 1867 queued_send_wr = NULL;
1902 spin_lock_irqsave(&send_queue->lock, flags); 1868 spin_lock_irqsave(&send_queue->lock, flags);
1903 list_del(&mad_list->list); 1869 list_del(&mad_list->list);
@@ -1914,17 +1880,17 @@ retry:
1914 } 1880 }
1915 spin_unlock_irqrestore(&send_queue->lock, flags); 1881 spin_unlock_irqrestore(&send_queue->lock, flags);
1916 1882
1917 /* Restore client wr_id in WC and complete send */ 1883 mad_send_wc.send_buf = &mad_send_wr->send_buf;
1918 wc->wr_id = mad_send_wr->wr_id; 1884 mad_send_wc.status = wc->status;
1885 mad_send_wc.vendor_err = wc->vendor_err;
1919 if (atomic_read(&qp_info->snoop_count)) 1886 if (atomic_read(&qp_info->snoop_count))
1920 snoop_send(qp_info, &mad_send_wr->send_wr, 1887 snoop_send(qp_info, &mad_send_wr->send_buf, &mad_send_wc,
1921 (struct ib_mad_send_wc *)wc,
1922 IB_MAD_SNOOP_SEND_COMPLETIONS); 1888 IB_MAD_SNOOP_SEND_COMPLETIONS);
1923 ib_mad_complete_send_wr(mad_send_wr, (struct ib_mad_send_wc *)wc); 1889 ib_mad_complete_send_wr(mad_send_wr, &mad_send_wc);
1924 1890
1925 if (queued_send_wr) { 1891 if (queued_send_wr) {
1926 ret = ib_post_send(qp_info->qp, &queued_send_wr->send_wr, 1892 ret = ib_post_send(qp_info->qp, &queued_send_wr->send_wr,
1927 &bad_send_wr); 1893 &bad_send_wr);
1928 if (ret) { 1894 if (ret) {
1929 printk(KERN_ERR PFX "ib_post_send failed: %d\n", ret); 1895 printk(KERN_ERR PFX "ib_post_send failed: %d\n", ret);
1930 mad_send_wr = queued_send_wr; 1896 mad_send_wr = queued_send_wr;
@@ -2066,38 +2032,37 @@ static void cancel_mads(struct ib_mad_agent_private *mad_agent_priv)
2066 2032
2067 list_for_each_entry_safe(mad_send_wr, temp_mad_send_wr, 2033 list_for_each_entry_safe(mad_send_wr, temp_mad_send_wr,
2068 &cancel_list, agent_list) { 2034 &cancel_list, agent_list) {
2069 mad_send_wc.wr_id = mad_send_wr->wr_id; 2035 mad_send_wc.send_buf = &mad_send_wr->send_buf;
2036 list_del(&mad_send_wr->agent_list);
2070 mad_agent_priv->agent.send_handler(&mad_agent_priv->agent, 2037 mad_agent_priv->agent.send_handler(&mad_agent_priv->agent,
2071 &mad_send_wc); 2038 &mad_send_wc);
2072
2073 list_del(&mad_send_wr->agent_list);
2074 kfree(mad_send_wr);
2075 atomic_dec(&mad_agent_priv->refcount); 2039 atomic_dec(&mad_agent_priv->refcount);
2076 } 2040 }
2077} 2041}
2078 2042
2079static struct ib_mad_send_wr_private* 2043static struct ib_mad_send_wr_private*
2080find_send_by_wr_id(struct ib_mad_agent_private *mad_agent_priv, u64 wr_id) 2044find_send_wr(struct ib_mad_agent_private *mad_agent_priv,
2045 struct ib_mad_send_buf *send_buf)
2081{ 2046{
2082 struct ib_mad_send_wr_private *mad_send_wr; 2047 struct ib_mad_send_wr_private *mad_send_wr;
2083 2048
2084 list_for_each_entry(mad_send_wr, &mad_agent_priv->wait_list, 2049 list_for_each_entry(mad_send_wr, &mad_agent_priv->wait_list,
2085 agent_list) { 2050 agent_list) {
2086 if (mad_send_wr->wr_id == wr_id) 2051 if (&mad_send_wr->send_buf == send_buf)
2087 return mad_send_wr; 2052 return mad_send_wr;
2088 } 2053 }
2089 2054
2090 list_for_each_entry(mad_send_wr, &mad_agent_priv->send_list, 2055 list_for_each_entry(mad_send_wr, &mad_agent_priv->send_list,
2091 agent_list) { 2056 agent_list) {
2092 if (is_data_mad(mad_agent_priv, 2057 if (is_data_mad(mad_agent_priv, mad_send_wr->send_buf.mad) &&
2093 mad_send_wr->send_wr.wr.ud.mad_hdr) && 2058 &mad_send_wr->send_buf == send_buf)
2094 mad_send_wr->wr_id == wr_id)
2095 return mad_send_wr; 2059 return mad_send_wr;
2096 } 2060 }
2097 return NULL; 2061 return NULL;
2098} 2062}
2099 2063
2100int ib_modify_mad(struct ib_mad_agent *mad_agent, u64 wr_id, u32 timeout_ms) 2064int ib_modify_mad(struct ib_mad_agent *mad_agent,
2065 struct ib_mad_send_buf *send_buf, u32 timeout_ms)
2101{ 2066{
2102 struct ib_mad_agent_private *mad_agent_priv; 2067 struct ib_mad_agent_private *mad_agent_priv;
2103 struct ib_mad_send_wr_private *mad_send_wr; 2068 struct ib_mad_send_wr_private *mad_send_wr;
@@ -2107,7 +2072,7 @@ int ib_modify_mad(struct ib_mad_agent *mad_agent, u64 wr_id, u32 timeout_ms)
2107 mad_agent_priv = container_of(mad_agent, struct ib_mad_agent_private, 2072 mad_agent_priv = container_of(mad_agent, struct ib_mad_agent_private,
2108 agent); 2073 agent);
2109 spin_lock_irqsave(&mad_agent_priv->lock, flags); 2074 spin_lock_irqsave(&mad_agent_priv->lock, flags);
2110 mad_send_wr = find_send_by_wr_id(mad_agent_priv, wr_id); 2075 mad_send_wr = find_send_wr(mad_agent_priv, send_buf);
2111 if (!mad_send_wr || mad_send_wr->status != IB_WC_SUCCESS) { 2076 if (!mad_send_wr || mad_send_wr->status != IB_WC_SUCCESS) {
2112 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); 2077 spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
2113 return -EINVAL; 2078 return -EINVAL;
@@ -2119,7 +2084,7 @@ int ib_modify_mad(struct ib_mad_agent *mad_agent, u64 wr_id, u32 timeout_ms)
2119 mad_send_wr->refcount -= (mad_send_wr->timeout > 0); 2084 mad_send_wr->refcount -= (mad_send_wr->timeout > 0);
2120 } 2085 }
2121 2086
2122 mad_send_wr->send_wr.wr.ud.timeout_ms = timeout_ms; 2087 mad_send_wr->send_buf.timeout_ms = timeout_ms;
2123 if (active) 2088 if (active)
2124 mad_send_wr->timeout = msecs_to_jiffies(timeout_ms); 2089 mad_send_wr->timeout = msecs_to_jiffies(timeout_ms);
2125 else 2090 else
@@ -2130,9 +2095,10 @@ int ib_modify_mad(struct ib_mad_agent *mad_agent, u64 wr_id, u32 timeout_ms)
2130} 2095}
2131EXPORT_SYMBOL(ib_modify_mad); 2096EXPORT_SYMBOL(ib_modify_mad);
2132 2097
2133void ib_cancel_mad(struct ib_mad_agent *mad_agent, u64 wr_id) 2098void ib_cancel_mad(struct ib_mad_agent *mad_agent,
2099 struct ib_mad_send_buf *send_buf)
2134{ 2100{
2135 ib_modify_mad(mad_agent, wr_id, 0); 2101 ib_modify_mad(mad_agent, send_buf, 0);
2136} 2102}
2137EXPORT_SYMBOL(ib_cancel_mad); 2103EXPORT_SYMBOL(ib_cancel_mad);
2138 2104
@@ -2166,10 +2132,9 @@ static void local_completions(void *data)
2166 * Defined behavior is to complete response 2132 * Defined behavior is to complete response
2167 * before request 2133 * before request
2168 */ 2134 */
2169 build_smp_wc(local->wr_id, 2135 build_smp_wc((unsigned long) local->mad_send_wr,
2170 be16_to_cpu(IB_LID_PERMISSIVE), 2136 be16_to_cpu(IB_LID_PERMISSIVE),
2171 0 /* pkey index */, 2137 0, recv_mad_agent->agent.port_num, &wc);
2172 recv_mad_agent->agent.port_num, &wc);
2173 2138
2174 local->mad_priv->header.recv_wc.wc = &wc; 2139 local->mad_priv->header.recv_wc.wc = &wc;
2175 local->mad_priv->header.recv_wc.mad_len = 2140 local->mad_priv->header.recv_wc.mad_len =
@@ -2196,11 +2161,11 @@ local_send_completion:
2196 /* Complete send */ 2161 /* Complete send */
2197 mad_send_wc.status = IB_WC_SUCCESS; 2162 mad_send_wc.status = IB_WC_SUCCESS;
2198 mad_send_wc.vendor_err = 0; 2163 mad_send_wc.vendor_err = 0;
2199 mad_send_wc.wr_id = local->wr_id; 2164 mad_send_wc.send_buf = &local->mad_send_wr->send_buf;
2200 if (atomic_read(&mad_agent_priv->qp_info->snoop_count)) 2165 if (atomic_read(&mad_agent_priv->qp_info->snoop_count))
2201 snoop_send(mad_agent_priv->qp_info, &local->send_wr, 2166 snoop_send(mad_agent_priv->qp_info,
2202 &mad_send_wc, 2167 &local->mad_send_wr->send_buf,
2203 IB_MAD_SNOOP_SEND_COMPLETIONS); 2168 &mad_send_wc, IB_MAD_SNOOP_SEND_COMPLETIONS);
2204 mad_agent_priv->agent.send_handler(&mad_agent_priv->agent, 2169 mad_agent_priv->agent.send_handler(&mad_agent_priv->agent,
2205 &mad_send_wc); 2170 &mad_send_wc);
2206 2171
@@ -2221,8 +2186,7 @@ static int retry_send(struct ib_mad_send_wr_private *mad_send_wr)
2221 if (!mad_send_wr->retries--) 2186 if (!mad_send_wr->retries--)
2222 return -ETIMEDOUT; 2187 return -ETIMEDOUT;
2223 2188
2224 mad_send_wr->timeout = msecs_to_jiffies(mad_send_wr->send_wr. 2189 mad_send_wr->timeout = msecs_to_jiffies(mad_send_wr->send_buf.timeout_ms);
2225 wr.ud.timeout_ms);
2226 2190
2227 if (mad_send_wr->mad_agent_priv->agent.rmpp_version) { 2191 if (mad_send_wr->mad_agent_priv->agent.rmpp_version) {
2228 ret = ib_retry_rmpp(mad_send_wr); 2192 ret = ib_retry_rmpp(mad_send_wr);
@@ -2285,11 +2249,10 @@ static void timeout_sends(void *data)
2285 mad_send_wc.status = IB_WC_RESP_TIMEOUT_ERR; 2249 mad_send_wc.status = IB_WC_RESP_TIMEOUT_ERR;
2286 else 2250 else
2287 mad_send_wc.status = mad_send_wr->status; 2251 mad_send_wc.status = mad_send_wr->status;
2288 mad_send_wc.wr_id = mad_send_wr->wr_id; 2252 mad_send_wc.send_buf = &mad_send_wr->send_buf;
2289 mad_agent_priv->agent.send_handler(&mad_agent_priv->agent, 2253 mad_agent_priv->agent.send_handler(&mad_agent_priv->agent,
2290 &mad_send_wc); 2254 &mad_send_wc);
2291 2255
2292 kfree(mad_send_wr);
2293 atomic_dec(&mad_agent_priv->refcount); 2256 atomic_dec(&mad_agent_priv->refcount);
2294 spin_lock_irqsave(&mad_agent_priv->lock, flags); 2257 spin_lock_irqsave(&mad_agent_priv->lock, flags);
2295 } 2258 }
@@ -2683,40 +2646,47 @@ static int ib_mad_port_close(struct ib_device *device, int port_num)
2683 2646
2684static void ib_mad_init_device(struct ib_device *device) 2647static void ib_mad_init_device(struct ib_device *device)
2685{ 2648{
2686 int num_ports, cur_port, i; 2649 int start, end, i;
2687 2650
2688 if (device->node_type == IB_NODE_SWITCH) { 2651 if (device->node_type == IB_NODE_SWITCH) {
2689 num_ports = 1; 2652 start = 0;
2690 cur_port = 0; 2653 end = 0;
2691 } else { 2654 } else {
2692 num_ports = device->phys_port_cnt; 2655 start = 1;
2693 cur_port = 1; 2656 end = device->phys_port_cnt;
2694 } 2657 }
2695 for (i = 0; i < num_ports; i++, cur_port++) { 2658
2696 if (ib_mad_port_open(device, cur_port)) { 2659 for (i = start; i <= end; i++) {
2660 if (ib_mad_port_open(device, i)) {
2697 printk(KERN_ERR PFX "Couldn't open %s port %d\n", 2661 printk(KERN_ERR PFX "Couldn't open %s port %d\n",
2698 device->name, cur_port); 2662 device->name, i);
2699 goto error_device_open; 2663 goto error;
2700 } 2664 }
2701 if (ib_agent_port_open(device, cur_port)) { 2665 if (ib_agent_port_open(device, i)) {
2702 printk(KERN_ERR PFX "Couldn't open %s port %d " 2666 printk(KERN_ERR PFX "Couldn't open %s port %d "
2703 "for agents\n", 2667 "for agents\n",
2704 device->name, cur_port); 2668 device->name, i);
2705 goto error_device_open; 2669 goto error_agent;
2706 } 2670 }
2707 } 2671 }
2708 return; 2672 return;
2709 2673
2710error_device_open: 2674error_agent:
2711 while (i > 0) { 2675 if (ib_mad_port_close(device, i))
2712 cur_port--; 2676 printk(KERN_ERR PFX "Couldn't close %s port %d\n",
2713 if (ib_agent_port_close(device, cur_port)) 2677 device->name, i);
2678
2679error:
2680 i--;
2681
2682 while (i >= start) {
2683 if (ib_agent_port_close(device, i))
2714 printk(KERN_ERR PFX "Couldn't close %s port %d " 2684 printk(KERN_ERR PFX "Couldn't close %s port %d "
2715 "for agents\n", 2685 "for agents\n",
2716 device->name, cur_port); 2686 device->name, i);
2717 if (ib_mad_port_close(device, cur_port)) 2687 if (ib_mad_port_close(device, i))
2718 printk(KERN_ERR PFX "Couldn't close %s port %d\n", 2688 printk(KERN_ERR PFX "Couldn't close %s port %d\n",
2719 device->name, cur_port); 2689 device->name, i);
2720 i--; 2690 i--;
2721 } 2691 }
2722} 2692}
@@ -2754,7 +2724,6 @@ static int __init ib_mad_init_module(void)
2754 int ret; 2724 int ret;
2755 2725
2756 spin_lock_init(&ib_mad_port_list_lock); 2726 spin_lock_init(&ib_mad_port_list_lock);
2757 spin_lock_init(&ib_agent_port_list_lock);
2758 2727
2759 ib_mad_cache = kmem_cache_create("ib_mad", 2728 ib_mad_cache = kmem_cache_create("ib_mad",
2760 sizeof(struct ib_mad_private), 2729 sizeof(struct ib_mad_private),
diff --git a/drivers/infiniband/core/mad_priv.h b/drivers/infiniband/core/mad_priv.h
index f1ba794e0daa..570f78682af3 100644
--- a/drivers/infiniband/core/mad_priv.h
+++ b/drivers/infiniband/core/mad_priv.h
@@ -118,9 +118,10 @@ struct ib_mad_send_wr_private {
118 struct ib_mad_list_head mad_list; 118 struct ib_mad_list_head mad_list;
119 struct list_head agent_list; 119 struct list_head agent_list;
120 struct ib_mad_agent_private *mad_agent_priv; 120 struct ib_mad_agent_private *mad_agent_priv;
121 struct ib_mad_send_buf send_buf;
122 DECLARE_PCI_UNMAP_ADDR(mapping)
121 struct ib_send_wr send_wr; 123 struct ib_send_wr send_wr;
122 struct ib_sge sg_list[IB_MAD_SEND_REQ_MAX_SG]; 124 struct ib_sge sg_list[IB_MAD_SEND_REQ_MAX_SG];
123 u64 wr_id; /* client WR ID */
124 __be64 tid; 125 __be64 tid;
125 unsigned long timeout; 126 unsigned long timeout;
126 int retries; 127 int retries;
@@ -141,10 +142,7 @@ struct ib_mad_local_private {
141 struct list_head completion_list; 142 struct list_head completion_list;
142 struct ib_mad_private *mad_priv; 143 struct ib_mad_private *mad_priv;
143 struct ib_mad_agent_private *recv_mad_agent; 144 struct ib_mad_agent_private *recv_mad_agent;
144 struct ib_send_wr send_wr; 145 struct ib_mad_send_wr_private *mad_send_wr;
145 struct ib_sge sg_list[IB_MAD_SEND_REQ_MAX_SG];
146 u64 wr_id; /* client WR ID */
147 __be64 tid;
148}; 146};
149 147
150struct ib_mad_mgmt_method_table { 148struct ib_mad_mgmt_method_table {
diff --git a/drivers/infiniband/core/mad_rmpp.c b/drivers/infiniband/core/mad_rmpp.c
index e23836d0e21b..3249e1d8c07b 100644
--- a/drivers/infiniband/core/mad_rmpp.c
+++ b/drivers/infiniband/core/mad_rmpp.c
@@ -103,12 +103,12 @@ void ib_cancel_rmpp_recvs(struct ib_mad_agent_private *agent)
103static int data_offset(u8 mgmt_class) 103static int data_offset(u8 mgmt_class)
104{ 104{
105 if (mgmt_class == IB_MGMT_CLASS_SUBN_ADM) 105 if (mgmt_class == IB_MGMT_CLASS_SUBN_ADM)
106 return offsetof(struct ib_sa_mad, data); 106 return IB_MGMT_SA_HDR;
107 else if ((mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START) && 107 else if ((mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START) &&
108 (mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END)) 108 (mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END))
109 return offsetof(struct ib_vendor_mad, data); 109 return IB_MGMT_VENDOR_HDR;
110 else 110 else
111 return offsetof(struct ib_rmpp_mad, data); 111 return IB_MGMT_RMPP_HDR;
112} 112}
113 113
114static void format_ack(struct ib_rmpp_mad *ack, 114static void format_ack(struct ib_rmpp_mad *ack,
@@ -135,55 +135,52 @@ static void ack_recv(struct mad_rmpp_recv *rmpp_recv,
135 struct ib_mad_recv_wc *recv_wc) 135 struct ib_mad_recv_wc *recv_wc)
136{ 136{
137 struct ib_mad_send_buf *msg; 137 struct ib_mad_send_buf *msg;
138 struct ib_send_wr *bad_send_wr; 138 int ret;
139 int hdr_len, ret;
140 139
141 hdr_len = sizeof(struct ib_mad_hdr) + sizeof(struct ib_rmpp_hdr);
142 msg = ib_create_send_mad(&rmpp_recv->agent->agent, recv_wc->wc->src_qp, 140 msg = ib_create_send_mad(&rmpp_recv->agent->agent, recv_wc->wc->src_qp,
143 recv_wc->wc->pkey_index, rmpp_recv->ah, 1, 141 recv_wc->wc->pkey_index, 1, IB_MGMT_RMPP_HDR,
144 hdr_len, sizeof(struct ib_rmpp_mad) - hdr_len, 142 IB_MGMT_RMPP_DATA, GFP_KERNEL);
145 GFP_KERNEL);
146 if (!msg) 143 if (!msg)
147 return; 144 return;
148 145
149 format_ack((struct ib_rmpp_mad *) msg->mad, 146 format_ack(msg->mad, (struct ib_rmpp_mad *) recv_wc->recv_buf.mad,
150 (struct ib_rmpp_mad *) recv_wc->recv_buf.mad, rmpp_recv); 147 rmpp_recv);
151 ret = ib_post_send_mad(&rmpp_recv->agent->agent, &msg->send_wr, 148 msg->ah = rmpp_recv->ah;
152 &bad_send_wr); 149 ret = ib_post_send_mad(msg, NULL);
153 if (ret) 150 if (ret)
154 ib_free_send_mad(msg); 151 ib_free_send_mad(msg);
155} 152}
156 153
157static int alloc_response_msg(struct ib_mad_agent *agent, 154static struct ib_mad_send_buf *alloc_response_msg(struct ib_mad_agent *agent,
158 struct ib_mad_recv_wc *recv_wc, 155 struct ib_mad_recv_wc *recv_wc)
159 struct ib_mad_send_buf **msg)
160{ 156{
161 struct ib_mad_send_buf *m; 157 struct ib_mad_send_buf *msg;
162 struct ib_ah *ah; 158 struct ib_ah *ah;
163 int hdr_len;
164 159
165 ah = ib_create_ah_from_wc(agent->qp->pd, recv_wc->wc, 160 ah = ib_create_ah_from_wc(agent->qp->pd, recv_wc->wc,
166 recv_wc->recv_buf.grh, agent->port_num); 161 recv_wc->recv_buf.grh, agent->port_num);
167 if (IS_ERR(ah)) 162 if (IS_ERR(ah))
168 return PTR_ERR(ah); 163 return (void *) ah;
169 164
170 hdr_len = sizeof(struct ib_mad_hdr) + sizeof(struct ib_rmpp_hdr); 165 msg = ib_create_send_mad(agent, recv_wc->wc->src_qp,
171 m = ib_create_send_mad(agent, recv_wc->wc->src_qp, 166 recv_wc->wc->pkey_index, 1,
172 recv_wc->wc->pkey_index, ah, 1, hdr_len, 167 IB_MGMT_RMPP_HDR, IB_MGMT_RMPP_DATA,
173 sizeof(struct ib_rmpp_mad) - hdr_len, 168 GFP_KERNEL);
174 GFP_KERNEL); 169 if (IS_ERR(msg))
175 if (IS_ERR(m)) {
176 ib_destroy_ah(ah); 170 ib_destroy_ah(ah);
177 return PTR_ERR(m); 171 else
178 } 172 msg->ah = ah;
179 *msg = m; 173
180 return 0; 174 return msg;
181} 175}
182 176
183static void free_msg(struct ib_mad_send_buf *msg) 177void ib_rmpp_send_handler(struct ib_mad_send_wc *mad_send_wc)
184{ 178{
185 ib_destroy_ah(msg->send_wr.wr.ud.ah); 179 struct ib_rmpp_mad *rmpp_mad = mad_send_wc->send_buf->mad;
186 ib_free_send_mad(msg); 180
181 if (rmpp_mad->rmpp_hdr.rmpp_type != IB_MGMT_RMPP_TYPE_ACK)
182 ib_destroy_ah(mad_send_wc->send_buf->ah);
183 ib_free_send_mad(mad_send_wc->send_buf);
187} 184}
188 185
189static void nack_recv(struct ib_mad_agent_private *agent, 186static void nack_recv(struct ib_mad_agent_private *agent,
@@ -191,14 +188,13 @@ static void nack_recv(struct ib_mad_agent_private *agent,
191{ 188{
192 struct ib_mad_send_buf *msg; 189 struct ib_mad_send_buf *msg;
193 struct ib_rmpp_mad *rmpp_mad; 190 struct ib_rmpp_mad *rmpp_mad;
194 struct ib_send_wr *bad_send_wr;
195 int ret; 191 int ret;
196 192
197 ret = alloc_response_msg(&agent->agent, recv_wc, &msg); 193 msg = alloc_response_msg(&agent->agent, recv_wc);
198 if (ret) 194 if (IS_ERR(msg))
199 return; 195 return;
200 196
201 rmpp_mad = (struct ib_rmpp_mad *) msg->mad; 197 rmpp_mad = msg->mad;
202 memcpy(rmpp_mad, recv_wc->recv_buf.mad, 198 memcpy(rmpp_mad, recv_wc->recv_buf.mad,
203 data_offset(recv_wc->recv_buf.mad->mad_hdr.mgmt_class)); 199 data_offset(recv_wc->recv_buf.mad->mad_hdr.mgmt_class));
204 200
@@ -210,9 +206,11 @@ static void nack_recv(struct ib_mad_agent_private *agent,
210 rmpp_mad->rmpp_hdr.seg_num = 0; 206 rmpp_mad->rmpp_hdr.seg_num = 0;
211 rmpp_mad->rmpp_hdr.paylen_newwin = 0; 207 rmpp_mad->rmpp_hdr.paylen_newwin = 0;
212 208
213 ret = ib_post_send_mad(&agent->agent, &msg->send_wr, &bad_send_wr); 209 ret = ib_post_send_mad(msg, NULL);
214 if (ret) 210 if (ret) {
215 free_msg(msg); 211 ib_destroy_ah(msg->ah);
212 ib_free_send_mad(msg);
213 }
216} 214}
217 215
218static void recv_timeout_handler(void *data) 216static void recv_timeout_handler(void *data)
@@ -585,7 +583,7 @@ static int send_next_seg(struct ib_mad_send_wr_private *mad_send_wr)
585 int timeout; 583 int timeout;
586 u32 paylen; 584 u32 paylen;
587 585
588 rmpp_mad = (struct ib_rmpp_mad *)mad_send_wr->send_wr.wr.ud.mad_hdr; 586 rmpp_mad = mad_send_wr->send_buf.mad;
589 ib_set_rmpp_flags(&rmpp_mad->rmpp_hdr, IB_MGMT_RMPP_FLAG_ACTIVE); 587 ib_set_rmpp_flags(&rmpp_mad->rmpp_hdr, IB_MGMT_RMPP_FLAG_ACTIVE);
590 rmpp_mad->rmpp_hdr.seg_num = cpu_to_be32(mad_send_wr->seg_num); 588 rmpp_mad->rmpp_hdr.seg_num = cpu_to_be32(mad_send_wr->seg_num);
591 589
@@ -612,7 +610,7 @@ static int send_next_seg(struct ib_mad_send_wr_private *mad_send_wr)
612 } 610 }
613 611
614 /* 2 seconds for an ACK until we can find the packet lifetime */ 612 /* 2 seconds for an ACK until we can find the packet lifetime */
615 timeout = mad_send_wr->send_wr.wr.ud.timeout_ms; 613 timeout = mad_send_wr->send_buf.timeout_ms;
616 if (!timeout || timeout > 2000) 614 if (!timeout || timeout > 2000)
617 mad_send_wr->timeout = msecs_to_jiffies(2000); 615 mad_send_wr->timeout = msecs_to_jiffies(2000);
618 mad_send_wr->seg_num++; 616 mad_send_wr->seg_num++;
@@ -640,7 +638,7 @@ static void abort_send(struct ib_mad_agent_private *agent, __be64 tid,
640 638
641 wc.status = IB_WC_REM_ABORT_ERR; 639 wc.status = IB_WC_REM_ABORT_ERR;
642 wc.vendor_err = rmpp_status; 640 wc.vendor_err = rmpp_status;
643 wc.wr_id = mad_send_wr->wr_id; 641 wc.send_buf = &mad_send_wr->send_buf;
644 ib_mad_complete_send_wr(mad_send_wr, &wc); 642 ib_mad_complete_send_wr(mad_send_wr, &wc);
645 return; 643 return;
646out: 644out:
@@ -694,12 +692,12 @@ static void process_rmpp_ack(struct ib_mad_agent_private *agent,
694 692
695 if (seg_num > mad_send_wr->last_ack) { 693 if (seg_num > mad_send_wr->last_ack) {
696 mad_send_wr->last_ack = seg_num; 694 mad_send_wr->last_ack = seg_num;
697 mad_send_wr->retries = mad_send_wr->send_wr.wr.ud.retries; 695 mad_send_wr->retries = mad_send_wr->send_buf.retries;
698 } 696 }
699 mad_send_wr->newwin = newwin; 697 mad_send_wr->newwin = newwin;
700 if (mad_send_wr->last_ack == mad_send_wr->total_seg) { 698 if (mad_send_wr->last_ack == mad_send_wr->total_seg) {
701 /* If no response is expected, the ACK completes the send */ 699 /* If no response is expected, the ACK completes the send */
702 if (!mad_send_wr->send_wr.wr.ud.timeout_ms) { 700 if (!mad_send_wr->send_buf.timeout_ms) {
703 struct ib_mad_send_wc wc; 701 struct ib_mad_send_wc wc;
704 702
705 ib_mark_mad_done(mad_send_wr); 703 ib_mark_mad_done(mad_send_wr);
@@ -707,13 +705,13 @@ static void process_rmpp_ack(struct ib_mad_agent_private *agent,
707 705
708 wc.status = IB_WC_SUCCESS; 706 wc.status = IB_WC_SUCCESS;
709 wc.vendor_err = 0; 707 wc.vendor_err = 0;
710 wc.wr_id = mad_send_wr->wr_id; 708 wc.send_buf = &mad_send_wr->send_buf;
711 ib_mad_complete_send_wr(mad_send_wr, &wc); 709 ib_mad_complete_send_wr(mad_send_wr, &wc);
712 return; 710 return;
713 } 711 }
714 if (mad_send_wr->refcount == 1) 712 if (mad_send_wr->refcount == 1)
715 ib_reset_mad_timeout(mad_send_wr, mad_send_wr-> 713 ib_reset_mad_timeout(mad_send_wr,
716 send_wr.wr.ud.timeout_ms); 714 mad_send_wr->send_buf.timeout_ms);
717 } else if (mad_send_wr->refcount == 1 && 715 } else if (mad_send_wr->refcount == 1 &&
718 mad_send_wr->seg_num < mad_send_wr->newwin && 716 mad_send_wr->seg_num < mad_send_wr->newwin &&
719 mad_send_wr->seg_num <= mad_send_wr->total_seg) { 717 mad_send_wr->seg_num <= mad_send_wr->total_seg) {
@@ -842,7 +840,7 @@ int ib_send_rmpp_mad(struct ib_mad_send_wr_private *mad_send_wr)
842 struct ib_rmpp_mad *rmpp_mad; 840 struct ib_rmpp_mad *rmpp_mad;
843 int i, total_len, ret; 841 int i, total_len, ret;
844 842
845 rmpp_mad = (struct ib_rmpp_mad *)mad_send_wr->send_wr.wr.ud.mad_hdr; 843 rmpp_mad = mad_send_wr->send_buf.mad;
846 if (!(ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) & 844 if (!(ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) &
847 IB_MGMT_RMPP_FLAG_ACTIVE)) 845 IB_MGMT_RMPP_FLAG_ACTIVE))
848 return IB_RMPP_RESULT_UNHANDLED; 846 return IB_RMPP_RESULT_UNHANDLED;
@@ -863,7 +861,7 @@ int ib_send_rmpp_mad(struct ib_mad_send_wr_private *mad_send_wr)
863 861
864 mad_send_wr->total_seg = (total_len - mad_send_wr->data_offset) / 862 mad_send_wr->total_seg = (total_len - mad_send_wr->data_offset) /
865 (sizeof(struct ib_rmpp_mad) - mad_send_wr->data_offset); 863 (sizeof(struct ib_rmpp_mad) - mad_send_wr->data_offset);
866 mad_send_wr->pad = total_len - offsetof(struct ib_rmpp_mad, data) - 864 mad_send_wr->pad = total_len - IB_MGMT_RMPP_HDR -
867 be32_to_cpu(rmpp_mad->rmpp_hdr.paylen_newwin); 865 be32_to_cpu(rmpp_mad->rmpp_hdr.paylen_newwin);
868 866
869 /* We need to wait for the final ACK even if there isn't a response */ 867 /* We need to wait for the final ACK even if there isn't a response */
@@ -878,23 +876,15 @@ int ib_process_rmpp_send_wc(struct ib_mad_send_wr_private *mad_send_wr,
878 struct ib_mad_send_wc *mad_send_wc) 876 struct ib_mad_send_wc *mad_send_wc)
879{ 877{
880 struct ib_rmpp_mad *rmpp_mad; 878 struct ib_rmpp_mad *rmpp_mad;
881 struct ib_mad_send_buf *msg;
882 int ret; 879 int ret;
883 880
884 rmpp_mad = (struct ib_rmpp_mad *)mad_send_wr->send_wr.wr.ud.mad_hdr; 881 rmpp_mad = mad_send_wr->send_buf.mad;
885 if (!(ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) & 882 if (!(ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) &
886 IB_MGMT_RMPP_FLAG_ACTIVE)) 883 IB_MGMT_RMPP_FLAG_ACTIVE))
887 return IB_RMPP_RESULT_UNHANDLED; /* RMPP not active */ 884 return IB_RMPP_RESULT_UNHANDLED; /* RMPP not active */
888 885
889 if (rmpp_mad->rmpp_hdr.rmpp_type != IB_MGMT_RMPP_TYPE_DATA) { 886 if (rmpp_mad->rmpp_hdr.rmpp_type != IB_MGMT_RMPP_TYPE_DATA)
890 msg = (struct ib_mad_send_buf *) (unsigned long)
891 mad_send_wc->wr_id;
892 if (rmpp_mad->rmpp_hdr.rmpp_type == IB_MGMT_RMPP_TYPE_ACK)
893 ib_free_send_mad(msg);
894 else
895 free_msg(msg);
896 return IB_RMPP_RESULT_INTERNAL; /* ACK, STOP, or ABORT */ 887 return IB_RMPP_RESULT_INTERNAL; /* ACK, STOP, or ABORT */
897 }
898 888
899 if (mad_send_wc->status != IB_WC_SUCCESS || 889 if (mad_send_wc->status != IB_WC_SUCCESS ||
900 mad_send_wr->status != IB_WC_SUCCESS) 890 mad_send_wr->status != IB_WC_SUCCESS)
@@ -905,7 +895,7 @@ int ib_process_rmpp_send_wc(struct ib_mad_send_wr_private *mad_send_wr,
905 895
906 if (mad_send_wr->last_ack == mad_send_wr->total_seg) { 896 if (mad_send_wr->last_ack == mad_send_wr->total_seg) {
907 mad_send_wr->timeout = 897 mad_send_wr->timeout =
908 msecs_to_jiffies(mad_send_wr->send_wr.wr.ud.timeout_ms); 898 msecs_to_jiffies(mad_send_wr->send_buf.timeout_ms);
909 return IB_RMPP_RESULT_PROCESSED; /* Send done */ 899 return IB_RMPP_RESULT_PROCESSED; /* Send done */
910 } 900 }
911 901
@@ -926,7 +916,7 @@ int ib_retry_rmpp(struct ib_mad_send_wr_private *mad_send_wr)
926 struct ib_rmpp_mad *rmpp_mad; 916 struct ib_rmpp_mad *rmpp_mad;
927 int ret; 917 int ret;
928 918
929 rmpp_mad = (struct ib_rmpp_mad *)mad_send_wr->send_wr.wr.ud.mad_hdr; 919 rmpp_mad = mad_send_wr->send_buf.mad;
930 if (!(ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) & 920 if (!(ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) &
931 IB_MGMT_RMPP_FLAG_ACTIVE)) 921 IB_MGMT_RMPP_FLAG_ACTIVE))
932 return IB_RMPP_RESULT_UNHANDLED; /* RMPP not active */ 922 return IB_RMPP_RESULT_UNHANDLED; /* RMPP not active */
diff --git a/drivers/infiniband/core/mad_rmpp.h b/drivers/infiniband/core/mad_rmpp.h
index c4924dfb8e75..f0616fd22494 100644
--- a/drivers/infiniband/core/mad_rmpp.h
+++ b/drivers/infiniband/core/mad_rmpp.h
@@ -51,6 +51,8 @@ ib_process_rmpp_recv_wc(struct ib_mad_agent_private *agent,
51int ib_process_rmpp_send_wc(struct ib_mad_send_wr_private *mad_send_wr, 51int ib_process_rmpp_send_wc(struct ib_mad_send_wr_private *mad_send_wr,
52 struct ib_mad_send_wc *mad_send_wc); 52 struct ib_mad_send_wc *mad_send_wc);
53 53
54void ib_rmpp_send_handler(struct ib_mad_send_wc *mad_send_wc);
55
54void ib_cancel_rmpp_recvs(struct ib_mad_agent_private *agent); 56void ib_cancel_rmpp_recvs(struct ib_mad_agent_private *agent);
55 57
56int ib_retry_rmpp(struct ib_mad_send_wr_private *mad_send_wr); 58int ib_retry_rmpp(struct ib_mad_send_wr_private *mad_send_wr);
diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c
index 262618210c1c..acda7d63d6fe 100644
--- a/drivers/infiniband/core/sa_query.c
+++ b/drivers/infiniband/core/sa_query.c
@@ -43,6 +43,7 @@
43#include <linux/dma-mapping.h> 43#include <linux/dma-mapping.h>
44#include <linux/kref.h> 44#include <linux/kref.h>
45#include <linux/idr.h> 45#include <linux/idr.h>
46#include <linux/workqueue.h>
46 47
47#include <rdma/ib_pack.h> 48#include <rdma/ib_pack.h>
48#include <rdma/ib_sa.h> 49#include <rdma/ib_sa.h>
@@ -73,11 +74,10 @@ struct ib_sa_device {
73struct ib_sa_query { 74struct ib_sa_query {
74 void (*callback)(struct ib_sa_query *, int, struct ib_sa_mad *); 75 void (*callback)(struct ib_sa_query *, int, struct ib_sa_mad *);
75 void (*release)(struct ib_sa_query *); 76 void (*release)(struct ib_sa_query *);
76 struct ib_sa_port *port; 77 struct ib_sa_port *port;
77 struct ib_sa_mad *mad; 78 struct ib_mad_send_buf *mad_buf;
78 struct ib_sa_sm_ah *sm_ah; 79 struct ib_sa_sm_ah *sm_ah;
79 DECLARE_PCI_UNMAP_ADDR(mapping) 80 int id;
80 int id;
81}; 81};
82 82
83struct ib_sa_service_query { 83struct ib_sa_service_query {
@@ -426,6 +426,7 @@ void ib_sa_cancel_query(int id, struct ib_sa_query *query)
426{ 426{
427 unsigned long flags; 427 unsigned long flags;
428 struct ib_mad_agent *agent; 428 struct ib_mad_agent *agent;
429 struct ib_mad_send_buf *mad_buf;
429 430
430 spin_lock_irqsave(&idr_lock, flags); 431 spin_lock_irqsave(&idr_lock, flags);
431 if (idr_find(&query_idr, id) != query) { 432 if (idr_find(&query_idr, id) != query) {
@@ -433,9 +434,10 @@ void ib_sa_cancel_query(int id, struct ib_sa_query *query)
433 return; 434 return;
434 } 435 }
435 agent = query->port->agent; 436 agent = query->port->agent;
437 mad_buf = query->mad_buf;
436 spin_unlock_irqrestore(&idr_lock, flags); 438 spin_unlock_irqrestore(&idr_lock, flags);
437 439
438 ib_cancel_mad(agent, id); 440 ib_cancel_mad(agent, mad_buf);
439} 441}
440EXPORT_SYMBOL(ib_sa_cancel_query); 442EXPORT_SYMBOL(ib_sa_cancel_query);
441 443
@@ -457,71 +459,46 @@ static void init_mad(struct ib_sa_mad *mad, struct ib_mad_agent *agent)
457 459
458static int send_mad(struct ib_sa_query *query, int timeout_ms) 460static int send_mad(struct ib_sa_query *query, int timeout_ms)
459{ 461{
460 struct ib_sa_port *port = query->port;
461 unsigned long flags; 462 unsigned long flags;
462 int ret; 463 int ret, id;
463 struct ib_sge gather_list;
464 struct ib_send_wr *bad_wr, wr = {
465 .opcode = IB_WR_SEND,
466 .sg_list = &gather_list,
467 .num_sge = 1,
468 .send_flags = IB_SEND_SIGNALED,
469 .wr = {
470 .ud = {
471 .mad_hdr = &query->mad->mad_hdr,
472 .remote_qpn = 1,
473 .remote_qkey = IB_QP1_QKEY,
474 .timeout_ms = timeout_ms,
475 }
476 }
477 };
478 464
479retry: 465retry:
480 if (!idr_pre_get(&query_idr, GFP_ATOMIC)) 466 if (!idr_pre_get(&query_idr, GFP_ATOMIC))
481 return -ENOMEM; 467 return -ENOMEM;
482 spin_lock_irqsave(&idr_lock, flags); 468 spin_lock_irqsave(&idr_lock, flags);
483 ret = idr_get_new(&query_idr, query, &query->id); 469 ret = idr_get_new(&query_idr, query, &id);
484 spin_unlock_irqrestore(&idr_lock, flags); 470 spin_unlock_irqrestore(&idr_lock, flags);
485 if (ret == -EAGAIN) 471 if (ret == -EAGAIN)
486 goto retry; 472 goto retry;
487 if (ret) 473 if (ret)
488 return ret; 474 return ret;
489 475
490 wr.wr_id = query->id; 476 query->mad_buf->timeout_ms = timeout_ms;
477 query->mad_buf->context[0] = query;
478 query->id = id;
491 479
492 spin_lock_irqsave(&port->ah_lock, flags); 480 spin_lock_irqsave(&query->port->ah_lock, flags);
493 kref_get(&port->sm_ah->ref); 481 kref_get(&query->port->sm_ah->ref);
494 query->sm_ah = port->sm_ah; 482 query->sm_ah = query->port->sm_ah;
495 wr.wr.ud.ah = port->sm_ah->ah; 483 spin_unlock_irqrestore(&query->port->ah_lock, flags);
496 spin_unlock_irqrestore(&port->ah_lock, flags);
497 484
498 gather_list.addr = dma_map_single(port->agent->device->dma_device, 485 query->mad_buf->ah = query->sm_ah->ah;
499 query->mad,
500 sizeof (struct ib_sa_mad),
501 DMA_TO_DEVICE);
502 gather_list.length = sizeof (struct ib_sa_mad);
503 gather_list.lkey = port->agent->mr->lkey;
504 pci_unmap_addr_set(query, mapping, gather_list.addr);
505 486
506 ret = ib_post_send_mad(port->agent, &wr, &bad_wr); 487 ret = ib_post_send_mad(query->mad_buf, NULL);
507 if (ret) { 488 if (ret) {
508 dma_unmap_single(port->agent->device->dma_device,
509 pci_unmap_addr(query, mapping),
510 sizeof (struct ib_sa_mad),
511 DMA_TO_DEVICE);
512 kref_put(&query->sm_ah->ref, free_sm_ah);
513 spin_lock_irqsave(&idr_lock, flags); 489 spin_lock_irqsave(&idr_lock, flags);
514 idr_remove(&query_idr, query->id); 490 idr_remove(&query_idr, id);
515 spin_unlock_irqrestore(&idr_lock, flags); 491 spin_unlock_irqrestore(&idr_lock, flags);
492
493 kref_put(&query->sm_ah->ref, free_sm_ah);
516 } 494 }
517 495
518 /* 496 /*
519 * It's not safe to dereference query any more, because the 497 * It's not safe to dereference query any more, because the
520 * send may already have completed and freed the query in 498 * send may already have completed and freed the query in
521 * another context. So use wr.wr_id, which has a copy of the 499 * another context.
522 * query's id.
523 */ 500 */
524 return ret ? ret : wr.wr_id; 501 return ret ? ret : id;
525} 502}
526 503
527static void ib_sa_path_rec_callback(struct ib_sa_query *sa_query, 504static void ib_sa_path_rec_callback(struct ib_sa_query *sa_query,
@@ -543,7 +520,6 @@ static void ib_sa_path_rec_callback(struct ib_sa_query *sa_query,
543 520
544static void ib_sa_path_rec_release(struct ib_sa_query *sa_query) 521static void ib_sa_path_rec_release(struct ib_sa_query *sa_query)
545{ 522{
546 kfree(sa_query->mad);
547 kfree(container_of(sa_query, struct ib_sa_path_query, sa_query)); 523 kfree(container_of(sa_query, struct ib_sa_path_query, sa_query));
548} 524}
549 525
@@ -583,43 +559,58 @@ int ib_sa_path_rec_get(struct ib_device *device, u8 port_num,
583{ 559{
584 struct ib_sa_path_query *query; 560 struct ib_sa_path_query *query;
585 struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client); 561 struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
586 struct ib_sa_port *port = &sa_dev->port[port_num - sa_dev->start_port]; 562 struct ib_sa_port *port;
587 struct ib_mad_agent *agent = port->agent; 563 struct ib_mad_agent *agent;
564 struct ib_sa_mad *mad;
588 int ret; 565 int ret;
589 566
567 if (!sa_dev)
568 return -ENODEV;
569
570 port = &sa_dev->port[port_num - sa_dev->start_port];
571 agent = port->agent;
572
590 query = kmalloc(sizeof *query, gfp_mask); 573 query = kmalloc(sizeof *query, gfp_mask);
591 if (!query) 574 if (!query)
592 return -ENOMEM; 575 return -ENOMEM;
593 query->sa_query.mad = kmalloc(sizeof *query->sa_query.mad, gfp_mask); 576
594 if (!query->sa_query.mad) { 577 query->sa_query.mad_buf = ib_create_send_mad(agent, 1, 0,
595 kfree(query); 578 0, IB_MGMT_SA_HDR,
596 return -ENOMEM; 579 IB_MGMT_SA_DATA, gfp_mask);
580 if (!query->sa_query.mad_buf) {
581 ret = -ENOMEM;
582 goto err1;
597 } 583 }
598 584
599 query->callback = callback; 585 query->callback = callback;
600 query->context = context; 586 query->context = context;
601 587
602 init_mad(query->sa_query.mad, agent); 588 mad = query->sa_query.mad_buf->mad;
589 init_mad(mad, agent);
603 590
604 query->sa_query.callback = callback ? ib_sa_path_rec_callback : NULL; 591 query->sa_query.callback = callback ? ib_sa_path_rec_callback : NULL;
605 query->sa_query.release = ib_sa_path_rec_release; 592 query->sa_query.release = ib_sa_path_rec_release;
606 query->sa_query.port = port; 593 query->sa_query.port = port;
607 query->sa_query.mad->mad_hdr.method = IB_MGMT_METHOD_GET; 594 mad->mad_hdr.method = IB_MGMT_METHOD_GET;
608 query->sa_query.mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_PATH_REC); 595 mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_PATH_REC);
609 query->sa_query.mad->sa_hdr.comp_mask = comp_mask; 596 mad->sa_hdr.comp_mask = comp_mask;
610 597
611 ib_pack(path_rec_table, ARRAY_SIZE(path_rec_table), 598 ib_pack(path_rec_table, ARRAY_SIZE(path_rec_table), rec, mad->data);
612 rec, query->sa_query.mad->data);
613 599
614 *sa_query = &query->sa_query; 600 *sa_query = &query->sa_query;
615 601
616 ret = send_mad(&query->sa_query, timeout_ms); 602 ret = send_mad(&query->sa_query, timeout_ms);
617 if (ret < 0) { 603 if (ret < 0)
618 *sa_query = NULL; 604 goto err2;
619 kfree(query->sa_query.mad); 605
620 kfree(query); 606 return ret;
621 }
622 607
608err2:
609 *sa_query = NULL;
610 ib_free_send_mad(query->sa_query.mad_buf);
611
612err1:
613 kfree(query);
623 return ret; 614 return ret;
624} 615}
625EXPORT_SYMBOL(ib_sa_path_rec_get); 616EXPORT_SYMBOL(ib_sa_path_rec_get);
@@ -643,7 +634,6 @@ static void ib_sa_service_rec_callback(struct ib_sa_query *sa_query,
643 634
644static void ib_sa_service_rec_release(struct ib_sa_query *sa_query) 635static void ib_sa_service_rec_release(struct ib_sa_query *sa_query)
645{ 636{
646 kfree(sa_query->mad);
647 kfree(container_of(sa_query, struct ib_sa_service_query, sa_query)); 637 kfree(container_of(sa_query, struct ib_sa_service_query, sa_query));
648} 638}
649 639
@@ -685,10 +675,17 @@ int ib_sa_service_rec_query(struct ib_device *device, u8 port_num, u8 method,
685{ 675{
686 struct ib_sa_service_query *query; 676 struct ib_sa_service_query *query;
687 struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client); 677 struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
688 struct ib_sa_port *port = &sa_dev->port[port_num - sa_dev->start_port]; 678 struct ib_sa_port *port;
689 struct ib_mad_agent *agent = port->agent; 679 struct ib_mad_agent *agent;
680 struct ib_sa_mad *mad;
690 int ret; 681 int ret;
691 682
683 if (!sa_dev)
684 return -ENODEV;
685
686 port = &sa_dev->port[port_num - sa_dev->start_port];
687 agent = port->agent;
688
692 if (method != IB_MGMT_METHOD_GET && 689 if (method != IB_MGMT_METHOD_GET &&
693 method != IB_MGMT_METHOD_SET && 690 method != IB_MGMT_METHOD_SET &&
694 method != IB_SA_METHOD_DELETE) 691 method != IB_SA_METHOD_DELETE)
@@ -697,37 +694,45 @@ int ib_sa_service_rec_query(struct ib_device *device, u8 port_num, u8 method,
697 query = kmalloc(sizeof *query, gfp_mask); 694 query = kmalloc(sizeof *query, gfp_mask);
698 if (!query) 695 if (!query)
699 return -ENOMEM; 696 return -ENOMEM;
700 query->sa_query.mad = kmalloc(sizeof *query->sa_query.mad, gfp_mask); 697
701 if (!query->sa_query.mad) { 698 query->sa_query.mad_buf = ib_create_send_mad(agent, 1, 0,
702 kfree(query); 699 0, IB_MGMT_SA_HDR,
703 return -ENOMEM; 700 IB_MGMT_SA_DATA, gfp_mask);
701 if (!query->sa_query.mad_buf) {
702 ret = -ENOMEM;
703 goto err1;
704 } 704 }
705 705
706 query->callback = callback; 706 query->callback = callback;
707 query->context = context; 707 query->context = context;
708 708
709 init_mad(query->sa_query.mad, agent); 709 mad = query->sa_query.mad_buf->mad;
710 init_mad(mad, agent);
710 711
711 query->sa_query.callback = callback ? ib_sa_service_rec_callback : NULL; 712 query->sa_query.callback = callback ? ib_sa_service_rec_callback : NULL;
712 query->sa_query.release = ib_sa_service_rec_release; 713 query->sa_query.release = ib_sa_service_rec_release;
713 query->sa_query.port = port; 714 query->sa_query.port = port;
714 query->sa_query.mad->mad_hdr.method = method; 715 mad->mad_hdr.method = method;
715 query->sa_query.mad->mad_hdr.attr_id = 716 mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_SERVICE_REC);
716 cpu_to_be16(IB_SA_ATTR_SERVICE_REC); 717 mad->sa_hdr.comp_mask = comp_mask;
717 query->sa_query.mad->sa_hdr.comp_mask = comp_mask;
718 718
719 ib_pack(service_rec_table, ARRAY_SIZE(service_rec_table), 719 ib_pack(service_rec_table, ARRAY_SIZE(service_rec_table),
720 rec, query->sa_query.mad->data); 720 rec, mad->data);
721 721
722 *sa_query = &query->sa_query; 722 *sa_query = &query->sa_query;
723 723
724 ret = send_mad(&query->sa_query, timeout_ms); 724 ret = send_mad(&query->sa_query, timeout_ms);
725 if (ret < 0) { 725 if (ret < 0)
726 *sa_query = NULL; 726 goto err2;
727 kfree(query->sa_query.mad); 727
728 kfree(query); 728 return ret;
729 }
730 729
730err2:
731 *sa_query = NULL;
732 ib_free_send_mad(query->sa_query.mad_buf);
733
734err1:
735 kfree(query);
731 return ret; 736 return ret;
732} 737}
733EXPORT_SYMBOL(ib_sa_service_rec_query); 738EXPORT_SYMBOL(ib_sa_service_rec_query);
@@ -751,7 +756,6 @@ static void ib_sa_mcmember_rec_callback(struct ib_sa_query *sa_query,
751 756
752static void ib_sa_mcmember_rec_release(struct ib_sa_query *sa_query) 757static void ib_sa_mcmember_rec_release(struct ib_sa_query *sa_query)
753{ 758{
754 kfree(sa_query->mad);
755 kfree(container_of(sa_query, struct ib_sa_mcmember_query, sa_query)); 759 kfree(container_of(sa_query, struct ib_sa_mcmember_query, sa_query));
756} 760}
757 761
@@ -768,60 +772,69 @@ int ib_sa_mcmember_rec_query(struct ib_device *device, u8 port_num,
768{ 772{
769 struct ib_sa_mcmember_query *query; 773 struct ib_sa_mcmember_query *query;
770 struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client); 774 struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
771 struct ib_sa_port *port = &sa_dev->port[port_num - sa_dev->start_port]; 775 struct ib_sa_port *port;
772 struct ib_mad_agent *agent = port->agent; 776 struct ib_mad_agent *agent;
777 struct ib_sa_mad *mad;
773 int ret; 778 int ret;
774 779
780 if (!sa_dev)
781 return -ENODEV;
782
783 port = &sa_dev->port[port_num - sa_dev->start_port];
784 agent = port->agent;
785
775 query = kmalloc(sizeof *query, gfp_mask); 786 query = kmalloc(sizeof *query, gfp_mask);
776 if (!query) 787 if (!query)
777 return -ENOMEM; 788 return -ENOMEM;
778 query->sa_query.mad = kmalloc(sizeof *query->sa_query.mad, gfp_mask); 789
779 if (!query->sa_query.mad) { 790 query->sa_query.mad_buf = ib_create_send_mad(agent, 1, 0,
780 kfree(query); 791 0, IB_MGMT_SA_HDR,
781 return -ENOMEM; 792 IB_MGMT_SA_DATA, gfp_mask);
793 if (!query->sa_query.mad_buf) {
794 ret = -ENOMEM;
795 goto err1;
782 } 796 }
783 797
784 query->callback = callback; 798 query->callback = callback;
785 query->context = context; 799 query->context = context;
786 800
787 init_mad(query->sa_query.mad, agent); 801 mad = query->sa_query.mad_buf->mad;
802 init_mad(mad, agent);
788 803
789 query->sa_query.callback = callback ? ib_sa_mcmember_rec_callback : NULL; 804 query->sa_query.callback = callback ? ib_sa_mcmember_rec_callback : NULL;
790 query->sa_query.release = ib_sa_mcmember_rec_release; 805 query->sa_query.release = ib_sa_mcmember_rec_release;
791 query->sa_query.port = port; 806 query->sa_query.port = port;
792 query->sa_query.mad->mad_hdr.method = method; 807 mad->mad_hdr.method = method;
793 query->sa_query.mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_MC_MEMBER_REC); 808 mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_MC_MEMBER_REC);
794 query->sa_query.mad->sa_hdr.comp_mask = comp_mask; 809 mad->sa_hdr.comp_mask = comp_mask;
795 810
796 ib_pack(mcmember_rec_table, ARRAY_SIZE(mcmember_rec_table), 811 ib_pack(mcmember_rec_table, ARRAY_SIZE(mcmember_rec_table),
797 rec, query->sa_query.mad->data); 812 rec, mad->data);
798 813
799 *sa_query = &query->sa_query; 814 *sa_query = &query->sa_query;
800 815
801 ret = send_mad(&query->sa_query, timeout_ms); 816 ret = send_mad(&query->sa_query, timeout_ms);
802 if (ret < 0) { 817 if (ret < 0)
803 *sa_query = NULL; 818 goto err2;
804 kfree(query->sa_query.mad);
805 kfree(query);
806 }
807 819
808 return ret; 820 return ret;
821
822err2:
823 *sa_query = NULL;
824 ib_free_send_mad(query->sa_query.mad_buf);
825
826err1:
827 kfree(query);
828 return ret;
809} 829}
810EXPORT_SYMBOL(ib_sa_mcmember_rec_query); 830EXPORT_SYMBOL(ib_sa_mcmember_rec_query);
811 831
812static void send_handler(struct ib_mad_agent *agent, 832static void send_handler(struct ib_mad_agent *agent,
813 struct ib_mad_send_wc *mad_send_wc) 833 struct ib_mad_send_wc *mad_send_wc)
814{ 834{
815 struct ib_sa_query *query; 835 struct ib_sa_query *query = mad_send_wc->send_buf->context[0];
816 unsigned long flags; 836 unsigned long flags;
817 837
818 spin_lock_irqsave(&idr_lock, flags);
819 query = idr_find(&query_idr, mad_send_wc->wr_id);
820 spin_unlock_irqrestore(&idr_lock, flags);
821
822 if (!query)
823 return;
824
825 if (query->callback) 838 if (query->callback)
826 switch (mad_send_wc->status) { 839 switch (mad_send_wc->status) {
827 case IB_WC_SUCCESS: 840 case IB_WC_SUCCESS:
@@ -838,30 +851,25 @@ static void send_handler(struct ib_mad_agent *agent,
838 break; 851 break;
839 } 852 }
840 853
841 dma_unmap_single(agent->device->dma_device,
842 pci_unmap_addr(query, mapping),
843 sizeof (struct ib_sa_mad),
844 DMA_TO_DEVICE);
845 kref_put(&query->sm_ah->ref, free_sm_ah);
846
847 query->release(query);
848
849 spin_lock_irqsave(&idr_lock, flags); 854 spin_lock_irqsave(&idr_lock, flags);
850 idr_remove(&query_idr, mad_send_wc->wr_id); 855 idr_remove(&query_idr, query->id);
851 spin_unlock_irqrestore(&idr_lock, flags); 856 spin_unlock_irqrestore(&idr_lock, flags);
857
858 ib_free_send_mad(mad_send_wc->send_buf);
859 kref_put(&query->sm_ah->ref, free_sm_ah);
860 query->release(query);
852} 861}
853 862
854static void recv_handler(struct ib_mad_agent *mad_agent, 863static void recv_handler(struct ib_mad_agent *mad_agent,
855 struct ib_mad_recv_wc *mad_recv_wc) 864 struct ib_mad_recv_wc *mad_recv_wc)
856{ 865{
857 struct ib_sa_query *query; 866 struct ib_sa_query *query;
858 unsigned long flags; 867 struct ib_mad_send_buf *mad_buf;
859 868
860 spin_lock_irqsave(&idr_lock, flags); 869 mad_buf = (void *) (unsigned long) mad_recv_wc->wc->wr_id;
861 query = idr_find(&query_idr, mad_recv_wc->wc->wr_id); 870 query = mad_buf->context[0];
862 spin_unlock_irqrestore(&idr_lock, flags);
863 871
864 if (query && query->callback) { 872 if (query->callback) {
865 if (mad_recv_wc->wc->status == IB_WC_SUCCESS) 873 if (mad_recv_wc->wc->status == IB_WC_SUCCESS)
866 query->callback(query, 874 query->callback(query,
867 mad_recv_wc->recv_buf.mad->mad_hdr.status ? 875 mad_recv_wc->recv_buf.mad->mad_hdr.status ?
@@ -975,6 +983,7 @@ static int __init ib_sa_init(void)
975static void __exit ib_sa_cleanup(void) 983static void __exit ib_sa_cleanup(void)
976{ 984{
977 ib_unregister_client(&sa_client); 985 ib_unregister_client(&sa_client);
986 idr_destroy(&query_idr);
978} 987}
979 988
980module_init(ib_sa_init); 989module_init(ib_sa_init);
diff --git a/drivers/infiniband/core/smi.h b/drivers/infiniband/core/smi.h
index db25503a0736..2b3c40198f81 100644
--- a/drivers/infiniband/core/smi.h
+++ b/drivers/infiniband/core/smi.h
@@ -39,6 +39,8 @@
39#ifndef __SMI_H_ 39#ifndef __SMI_H_
40#define __SMI_H_ 40#define __SMI_H_
41 41
42#include <rdma/ib_smi.h>
43
42int smi_handle_dr_smp_recv(struct ib_smp *smp, 44int smi_handle_dr_smp_recv(struct ib_smp *smp,
43 u8 node_type, 45 u8 node_type,
44 int port_num, 46 int port_num,
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index 211ba3223f65..7ce7a6c782fa 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -65,6 +65,11 @@ struct port_table_attribute {
65 int index; 65 int index;
66}; 66};
67 67
68static inline int ibdev_is_alive(const struct ib_device *dev)
69{
70 return dev->reg_state == IB_DEV_REGISTERED;
71}
72
68static ssize_t port_attr_show(struct kobject *kobj, 73static ssize_t port_attr_show(struct kobject *kobj,
69 struct attribute *attr, char *buf) 74 struct attribute *attr, char *buf)
70{ 75{
@@ -74,6 +79,8 @@ static ssize_t port_attr_show(struct kobject *kobj,
74 79
75 if (!port_attr->show) 80 if (!port_attr->show)
76 return -EIO; 81 return -EIO;
82 if (!ibdev_is_alive(p->ibdev))
83 return -ENODEV;
77 84
78 return port_attr->show(p, port_attr, buf); 85 return port_attr->show(p, port_attr, buf);
79} 86}
@@ -581,6 +588,9 @@ static ssize_t show_node_type(struct class_device *cdev, char *buf)
581{ 588{
582 struct ib_device *dev = container_of(cdev, struct ib_device, class_dev); 589 struct ib_device *dev = container_of(cdev, struct ib_device, class_dev);
583 590
591 if (!ibdev_is_alive(dev))
592 return -ENODEV;
593
584 switch (dev->node_type) { 594 switch (dev->node_type) {
585 case IB_NODE_CA: return sprintf(buf, "%d: CA\n", dev->node_type); 595 case IB_NODE_CA: return sprintf(buf, "%d: CA\n", dev->node_type);
586 case IB_NODE_SWITCH: return sprintf(buf, "%d: switch\n", dev->node_type); 596 case IB_NODE_SWITCH: return sprintf(buf, "%d: switch\n", dev->node_type);
@@ -595,6 +605,9 @@ static ssize_t show_sys_image_guid(struct class_device *cdev, char *buf)
595 struct ib_device_attr attr; 605 struct ib_device_attr attr;
596 ssize_t ret; 606 ssize_t ret;
597 607
608 if (!ibdev_is_alive(dev))
609 return -ENODEV;
610
598 ret = ib_query_device(dev, &attr); 611 ret = ib_query_device(dev, &attr);
599 if (ret) 612 if (ret)
600 return ret; 613 return ret;
@@ -612,6 +625,9 @@ static ssize_t show_node_guid(struct class_device *cdev, char *buf)
612 struct ib_device_attr attr; 625 struct ib_device_attr attr;
613 ssize_t ret; 626 ssize_t ret;
614 627
628 if (!ibdev_is_alive(dev))
629 return -ENODEV;
630
615 ret = ib_query_device(dev, &attr); 631 ret = ib_query_device(dev, &attr);
616 if (ret) 632 if (ret)
617 return ret; 633 return ret;
diff --git a/drivers/infiniband/core/ucm.c b/drivers/infiniband/core/ucm.c
index d0f0b0a2edd3..28477565ecba 100644
--- a/drivers/infiniband/core/ucm.c
+++ b/drivers/infiniband/core/ucm.c
@@ -41,37 +41,81 @@
41#include <linux/file.h> 41#include <linux/file.h>
42#include <linux/mount.h> 42#include <linux/mount.h>
43#include <linux/cdev.h> 43#include <linux/cdev.h>
44#include <linux/idr.h>
44 45
45#include <asm/uaccess.h> 46#include <asm/uaccess.h>
46 47
47#include "ucm.h" 48#include <rdma/ib_cm.h>
49#include <rdma/ib_user_cm.h>
48 50
49MODULE_AUTHOR("Libor Michalek"); 51MODULE_AUTHOR("Libor Michalek");
50MODULE_DESCRIPTION("InfiniBand userspace Connection Manager access"); 52MODULE_DESCRIPTION("InfiniBand userspace Connection Manager access");
51MODULE_LICENSE("Dual BSD/GPL"); 53MODULE_LICENSE("Dual BSD/GPL");
52 54
53static int ucm_debug_level; 55struct ib_ucm_device {
56 int devnum;
57 struct cdev dev;
58 struct class_device class_dev;
59 struct ib_device *ib_dev;
60};
61
62struct ib_ucm_file {
63 struct semaphore mutex;
64 struct file *filp;
65 struct ib_ucm_device *device;
66
67 struct list_head ctxs;
68 struct list_head events;
69 wait_queue_head_t poll_wait;
70};
71
72struct ib_ucm_context {
73 int id;
74 wait_queue_head_t wait;
75 atomic_t ref;
76 int events_reported;
77
78 struct ib_ucm_file *file;
79 struct ib_cm_id *cm_id;
80 __u64 uid;
81
82 struct list_head events; /* list of pending events. */
83 struct list_head file_list; /* member in file ctx list */
84};
85
86struct ib_ucm_event {
87 struct ib_ucm_context *ctx;
88 struct list_head file_list; /* member in file event list */
89 struct list_head ctx_list; /* member in ctx event list */
54 90
55module_param_named(debug_level, ucm_debug_level, int, 0644); 91 struct ib_cm_id *cm_id;
56MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0"); 92 struct ib_ucm_event_resp resp;
93 void *data;
94 void *info;
95 int data_len;
96 int info_len;
97};
57 98
58enum { 99enum {
59 IB_UCM_MAJOR = 231, 100 IB_UCM_MAJOR = 231,
60 IB_UCM_MINOR = 255 101 IB_UCM_BASE_MINOR = 224,
102 IB_UCM_MAX_DEVICES = 32
61}; 103};
62 104
63#define IB_UCM_DEV MKDEV(IB_UCM_MAJOR, IB_UCM_MINOR) 105#define IB_UCM_BASE_DEV MKDEV(IB_UCM_MAJOR, IB_UCM_BASE_MINOR)
64 106
65#define PFX "UCM: " 107static void ib_ucm_add_one(struct ib_device *device);
108static void ib_ucm_remove_one(struct ib_device *device);
66 109
67#define ucm_dbg(format, arg...) \ 110static struct ib_client ucm_client = {
68 do { \ 111 .name = "ucm",
69 if (ucm_debug_level > 0) \ 112 .add = ib_ucm_add_one,
70 printk(KERN_DEBUG PFX format, ## arg); \ 113 .remove = ib_ucm_remove_one
71 } while (0) 114};
72 115
73static struct semaphore ctx_id_mutex; 116static DECLARE_MUTEX(ctx_id_mutex);
74static struct idr ctx_id_table; 117static DEFINE_IDR(ctx_id_table);
118static DECLARE_BITMAP(dev_map, IB_UCM_MAX_DEVICES);
75 119
76static struct ib_ucm_context *ib_ucm_ctx_get(struct ib_ucm_file *file, int id) 120static struct ib_ucm_context *ib_ucm_ctx_get(struct ib_ucm_file *file, int id)
77{ 121{
@@ -152,17 +196,13 @@ static struct ib_ucm_context *ib_ucm_ctx_alloc(struct ib_ucm_file *file)
152 goto error; 196 goto error;
153 197
154 list_add_tail(&ctx->file_list, &file->ctxs); 198 list_add_tail(&ctx->file_list, &file->ctxs);
155 ucm_dbg("Allocated CM ID <%d>\n", ctx->id);
156 return ctx; 199 return ctx;
157 200
158error: 201error:
159 kfree(ctx); 202 kfree(ctx);
160 return NULL; 203 return NULL;
161} 204}
162/* 205
163 * Event portion of the API, handle CM events
164 * and allow event polling.
165 */
166static void ib_ucm_event_path_get(struct ib_ucm_path_rec *upath, 206static void ib_ucm_event_path_get(struct ib_ucm_path_rec *upath,
167 struct ib_sa_path_rec *kpath) 207 struct ib_sa_path_rec *kpath)
168{ 208{
@@ -209,6 +249,7 @@ static void ib_ucm_event_req_get(struct ib_ucm_req_event_resp *ureq,
209 ureq->retry_count = kreq->retry_count; 249 ureq->retry_count = kreq->retry_count;
210 ureq->rnr_retry_count = kreq->rnr_retry_count; 250 ureq->rnr_retry_count = kreq->rnr_retry_count;
211 ureq->srq = kreq->srq; 251 ureq->srq = kreq->srq;
252 ureq->port = kreq->port;
212 253
213 ib_ucm_event_path_get(&ureq->primary_path, kreq->primary_path); 254 ib_ucm_event_path_get(&ureq->primary_path, kreq->primary_path);
214 ib_ucm_event_path_get(&ureq->alternate_path, kreq->alternate_path); 255 ib_ucm_event_path_get(&ureq->alternate_path, kreq->alternate_path);
@@ -295,6 +336,8 @@ static int ib_ucm_event_process(struct ib_cm_event *evt,
295 case IB_CM_SIDR_REQ_RECEIVED: 336 case IB_CM_SIDR_REQ_RECEIVED:
296 uvt->resp.u.sidr_req_resp.pkey = 337 uvt->resp.u.sidr_req_resp.pkey =
297 evt->param.sidr_req_rcvd.pkey; 338 evt->param.sidr_req_rcvd.pkey;
339 uvt->resp.u.sidr_req_resp.port =
340 evt->param.sidr_req_rcvd.port;
298 uvt->data_len = IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE; 341 uvt->data_len = IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE;
299 break; 342 break;
300 case IB_CM_SIDR_REP_RECEIVED: 343 case IB_CM_SIDR_REP_RECEIVED:
@@ -387,9 +430,7 @@ static ssize_t ib_ucm_event(struct ib_ucm_file *file,
387 430
388 if (copy_from_user(&cmd, inbuf, sizeof(cmd))) 431 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
389 return -EFAULT; 432 return -EFAULT;
390 /* 433
391 * wait
392 */
393 down(&file->mutex); 434 down(&file->mutex);
394 while (list_empty(&file->events)) { 435 while (list_empty(&file->events)) {
395 436
@@ -471,7 +512,6 @@ done:
471 return result; 512 return result;
472} 513}
473 514
474
475static ssize_t ib_ucm_create_id(struct ib_ucm_file *file, 515static ssize_t ib_ucm_create_id(struct ib_ucm_file *file,
476 const char __user *inbuf, 516 const char __user *inbuf,
477 int in_len, int out_len) 517 int in_len, int out_len)
@@ -494,29 +534,27 @@ static ssize_t ib_ucm_create_id(struct ib_ucm_file *file,
494 return -ENOMEM; 534 return -ENOMEM;
495 535
496 ctx->uid = cmd.uid; 536 ctx->uid = cmd.uid;
497 ctx->cm_id = ib_create_cm_id(ib_ucm_event_handler, ctx); 537 ctx->cm_id = ib_create_cm_id(file->device->ib_dev,
538 ib_ucm_event_handler, ctx);
498 if (IS_ERR(ctx->cm_id)) { 539 if (IS_ERR(ctx->cm_id)) {
499 result = PTR_ERR(ctx->cm_id); 540 result = PTR_ERR(ctx->cm_id);
500 goto err; 541 goto err1;
501 } 542 }
502 543
503 resp.id = ctx->id; 544 resp.id = ctx->id;
504 if (copy_to_user((void __user *)(unsigned long)cmd.response, 545 if (copy_to_user((void __user *)(unsigned long)cmd.response,
505 &resp, sizeof(resp))) { 546 &resp, sizeof(resp))) {
506 result = -EFAULT; 547 result = -EFAULT;
507 goto err; 548 goto err2;
508 } 549 }
509
510 return 0; 550 return 0;
511 551
512err: 552err2:
553 ib_destroy_cm_id(ctx->cm_id);
554err1:
513 down(&ctx_id_mutex); 555 down(&ctx_id_mutex);
514 idr_remove(&ctx_id_table, ctx->id); 556 idr_remove(&ctx_id_table, ctx->id);
515 up(&ctx_id_mutex); 557 up(&ctx_id_mutex);
516
517 if (!IS_ERR(ctx->cm_id))
518 ib_destroy_cm_id(ctx->cm_id);
519
520 kfree(ctx); 558 kfree(ctx);
521 return result; 559 return result;
522} 560}
@@ -1184,9 +1222,6 @@ static ssize_t ib_ucm_write(struct file *filp, const char __user *buf,
1184 if (copy_from_user(&hdr, buf, sizeof(hdr))) 1222 if (copy_from_user(&hdr, buf, sizeof(hdr)))
1185 return -EFAULT; 1223 return -EFAULT;
1186 1224
1187 ucm_dbg("Write. cmd <%d> in <%d> out <%d> len <%Zu>\n",
1188 hdr.cmd, hdr.in, hdr.out, len);
1189
1190 if (hdr.cmd < 0 || hdr.cmd >= ARRAY_SIZE(ucm_cmd_table)) 1225 if (hdr.cmd < 0 || hdr.cmd >= ARRAY_SIZE(ucm_cmd_table))
1191 return -EINVAL; 1226 return -EINVAL;
1192 1227
@@ -1231,8 +1266,7 @@ static int ib_ucm_open(struct inode *inode, struct file *filp)
1231 1266
1232 filp->private_data = file; 1267 filp->private_data = file;
1233 file->filp = filp; 1268 file->filp = filp;
1234 1269 file->device = container_of(inode->i_cdev, struct ib_ucm_device, dev);
1235 ucm_dbg("Created struct\n");
1236 1270
1237 return 0; 1271 return 0;
1238} 1272}
@@ -1263,7 +1297,17 @@ static int ib_ucm_close(struct inode *inode, struct file *filp)
1263 return 0; 1297 return 0;
1264} 1298}
1265 1299
1266static struct file_operations ib_ucm_fops = { 1300static void ib_ucm_release_class_dev(struct class_device *class_dev)
1301{
1302 struct ib_ucm_device *dev;
1303
1304 dev = container_of(class_dev, struct ib_ucm_device, class_dev);
1305 cdev_del(&dev->dev);
1306 clear_bit(dev->devnum, dev_map);
1307 kfree(dev);
1308}
1309
1310static struct file_operations ucm_fops = {
1267 .owner = THIS_MODULE, 1311 .owner = THIS_MODULE,
1268 .open = ib_ucm_open, 1312 .open = ib_ucm_open,
1269 .release = ib_ucm_close, 1313 .release = ib_ucm_close,
@@ -1271,55 +1315,142 @@ static struct file_operations ib_ucm_fops = {
1271 .poll = ib_ucm_poll, 1315 .poll = ib_ucm_poll,
1272}; 1316};
1273 1317
1318static struct class ucm_class = {
1319 .name = "infiniband_cm",
1320 .release = ib_ucm_release_class_dev
1321};
1274 1322
1275static struct class *ib_ucm_class; 1323static ssize_t show_dev(struct class_device *class_dev, char *buf)
1276static struct cdev ib_ucm_cdev; 1324{
1325 struct ib_ucm_device *dev;
1326
1327 dev = container_of(class_dev, struct ib_ucm_device, class_dev);
1328 return print_dev_t(buf, dev->dev.dev);
1329}
1330static CLASS_DEVICE_ATTR(dev, S_IRUGO, show_dev, NULL);
1277 1331
1278static int __init ib_ucm_init(void) 1332static ssize_t show_ibdev(struct class_device *class_dev, char *buf)
1279{ 1333{
1280 int result; 1334 struct ib_ucm_device *dev;
1335
1336 dev = container_of(class_dev, struct ib_ucm_device, class_dev);
1337 return sprintf(buf, "%s\n", dev->ib_dev->name);
1338}
1339static CLASS_DEVICE_ATTR(ibdev, S_IRUGO, show_ibdev, NULL);
1281 1340
1282 result = register_chrdev_region(IB_UCM_DEV, 1, "infiniband_cm"); 1341static void ib_ucm_add_one(struct ib_device *device)
1283 if (result) { 1342{
1284 ucm_dbg("Error <%d> registering dev\n", result); 1343 struct ib_ucm_device *ucm_dev;
1285 goto err_chr; 1344
1286 } 1345 if (!device->alloc_ucontext)
1346 return;
1347
1348 ucm_dev = kmalloc(sizeof *ucm_dev, GFP_KERNEL);
1349 if (!ucm_dev)
1350 return;
1287 1351
1288 cdev_init(&ib_ucm_cdev, &ib_ucm_fops); 1352 memset(ucm_dev, 0, sizeof *ucm_dev);
1353 ucm_dev->ib_dev = device;
1354
1355 ucm_dev->devnum = find_first_zero_bit(dev_map, IB_UCM_MAX_DEVICES);
1356 if (ucm_dev->devnum >= IB_UCM_MAX_DEVICES)
1357 goto err;
1358
1359 set_bit(ucm_dev->devnum, dev_map);
1360
1361 cdev_init(&ucm_dev->dev, &ucm_fops);
1362 ucm_dev->dev.owner = THIS_MODULE;
1363 kobject_set_name(&ucm_dev->dev.kobj, "ucm%d", ucm_dev->devnum);
1364 if (cdev_add(&ucm_dev->dev, IB_UCM_BASE_DEV + ucm_dev->devnum, 1))
1365 goto err;
1289 1366
1290 result = cdev_add(&ib_ucm_cdev, IB_UCM_DEV, 1); 1367 ucm_dev->class_dev.class = &ucm_class;
1291 if (result) { 1368 ucm_dev->class_dev.dev = device->dma_device;
1292 ucm_dbg("Error <%d> adding cdev\n", result); 1369 snprintf(ucm_dev->class_dev.class_id, BUS_ID_SIZE, "ucm%d",
1370 ucm_dev->devnum);
1371 if (class_device_register(&ucm_dev->class_dev))
1293 goto err_cdev; 1372 goto err_cdev;
1294 }
1295 1373
1296 ib_ucm_class = class_create(THIS_MODULE, "infiniband_cm"); 1374 if (class_device_create_file(&ucm_dev->class_dev,
1297 if (IS_ERR(ib_ucm_class)) { 1375 &class_device_attr_dev))
1298 result = PTR_ERR(ib_ucm_class); 1376 goto err_class;
1299 ucm_dbg("Error <%d> creating class\n", result); 1377 if (class_device_create_file(&ucm_dev->class_dev,
1378 &class_device_attr_ibdev))
1300 goto err_class; 1379 goto err_class;
1380
1381 ib_set_client_data(device, &ucm_client, ucm_dev);
1382 return;
1383
1384err_class:
1385 class_device_unregister(&ucm_dev->class_dev);
1386err_cdev:
1387 cdev_del(&ucm_dev->dev);
1388 clear_bit(ucm_dev->devnum, dev_map);
1389err:
1390 kfree(ucm_dev);
1391 return;
1392}
1393
1394static void ib_ucm_remove_one(struct ib_device *device)
1395{
1396 struct ib_ucm_device *ucm_dev = ib_get_client_data(device, &ucm_client);
1397
1398 if (!ucm_dev)
1399 return;
1400
1401 class_device_unregister(&ucm_dev->class_dev);
1402}
1403
1404static ssize_t show_abi_version(struct class *class, char *buf)
1405{
1406 return sprintf(buf, "%d\n", IB_USER_CM_ABI_VERSION);
1407}
1408static CLASS_ATTR(abi_version, S_IRUGO, show_abi_version, NULL);
1409
1410static int __init ib_ucm_init(void)
1411{
1412 int ret;
1413
1414 ret = register_chrdev_region(IB_UCM_BASE_DEV, IB_UCM_MAX_DEVICES,
1415 "infiniband_cm");
1416 if (ret) {
1417 printk(KERN_ERR "ucm: couldn't register device number\n");
1418 goto err;
1301 } 1419 }
1302 1420
1303 class_device_create(ib_ucm_class, IB_UCM_DEV, NULL, "ucm"); 1421 ret = class_register(&ucm_class);
1422 if (ret) {
1423 printk(KERN_ERR "ucm: couldn't create class infiniband_cm\n");
1424 goto err_chrdev;
1425 }
1304 1426
1305 idr_init(&ctx_id_table); 1427 ret = class_create_file(&ucm_class, &class_attr_abi_version);
1306 init_MUTEX(&ctx_id_mutex); 1428 if (ret) {
1429 printk(KERN_ERR "ucm: couldn't create abi_version attribute\n");
1430 goto err_class;
1431 }
1307 1432
1433 ret = ib_register_client(&ucm_client);
1434 if (ret) {
1435 printk(KERN_ERR "ucm: couldn't register client\n");
1436 goto err_class;
1437 }
1308 return 0; 1438 return 0;
1439
1309err_class: 1440err_class:
1310 cdev_del(&ib_ucm_cdev); 1441 class_unregister(&ucm_class);
1311err_cdev: 1442err_chrdev:
1312 unregister_chrdev_region(IB_UCM_DEV, 1); 1443 unregister_chrdev_region(IB_UCM_BASE_DEV, IB_UCM_MAX_DEVICES);
1313err_chr: 1444err:
1314 return result; 1445 return ret;
1315} 1446}
1316 1447
1317static void __exit ib_ucm_cleanup(void) 1448static void __exit ib_ucm_cleanup(void)
1318{ 1449{
1319 class_device_destroy(ib_ucm_class, IB_UCM_DEV); 1450 ib_unregister_client(&ucm_client);
1320 class_destroy(ib_ucm_class); 1451 class_unregister(&ucm_class);
1321 cdev_del(&ib_ucm_cdev); 1452 unregister_chrdev_region(IB_UCM_BASE_DEV, IB_UCM_MAX_DEVICES);
1322 unregister_chrdev_region(IB_UCM_DEV, 1); 1453 idr_destroy(&ctx_id_table);
1323} 1454}
1324 1455
1325module_init(ib_ucm_init); 1456module_init(ib_ucm_init);
diff --git a/drivers/infiniband/core/ucm.h b/drivers/infiniband/core/ucm.h
deleted file mode 100644
index f46f37bc1201..000000000000
--- a/drivers/infiniband/core/ucm.h
+++ /dev/null
@@ -1,83 +0,0 @@
1/*
2 * Copyright (c) 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Intel Corporation. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 *
33 * $Id: ucm.h 2208 2005-04-22 23:24:31Z libor $
34 */
35
36#ifndef UCM_H
37#define UCM_H
38
39#include <linux/fs.h>
40#include <linux/device.h>
41#include <linux/cdev.h>
42#include <linux/idr.h>
43
44#include <rdma/ib_cm.h>
45#include <rdma/ib_user_cm.h>
46
47struct ib_ucm_file {
48 struct semaphore mutex;
49 struct file *filp;
50
51 struct list_head ctxs; /* list of active connections */
52 struct list_head events; /* list of pending events */
53 wait_queue_head_t poll_wait;
54};
55
56struct ib_ucm_context {
57 int id;
58 wait_queue_head_t wait;
59 atomic_t ref;
60 int events_reported;
61
62 struct ib_ucm_file *file;
63 struct ib_cm_id *cm_id;
64 __u64 uid;
65
66 struct list_head events; /* list of pending events. */
67 struct list_head file_list; /* member in file ctx list */
68};
69
70struct ib_ucm_event {
71 struct ib_ucm_context *ctx;
72 struct list_head file_list; /* member in file event list */
73 struct list_head ctx_list; /* member in ctx event list */
74
75 struct ib_cm_id *cm_id;
76 struct ib_ucm_event_resp resp;
77 void *data;
78 void *info;
79 int data_len;
80 int info_len;
81};
82
83#endif /* UCM_H */
diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c
index a64d6b4dcc16..97128e25f78b 100644
--- a/drivers/infiniband/core/user_mad.c
+++ b/drivers/infiniband/core/user_mad.c
@@ -64,18 +64,39 @@ enum {
64 IB_UMAD_MINOR_BASE = 0 64 IB_UMAD_MINOR_BASE = 0
65}; 65};
66 66
67/*
68 * Our lifetime rules for these structs are the following: each time a
69 * device special file is opened, we look up the corresponding struct
70 * ib_umad_port by minor in the umad_port[] table while holding the
71 * port_lock. If this lookup succeeds, we take a reference on the
72 * ib_umad_port's struct ib_umad_device while still holding the
73 * port_lock; if the lookup fails, we fail the open(). We drop these
74 * references in the corresponding close().
75 *
76 * In addition to references coming from open character devices, there
77 * is one more reference to each ib_umad_device representing the
78 * module's reference taken when allocating the ib_umad_device in
79 * ib_umad_add_one().
80 *
81 * When destroying an ib_umad_device, we clear all of its
82 * ib_umad_ports from umad_port[] while holding port_lock before
83 * dropping the module's reference to the ib_umad_device. This is
84 * always safe because any open() calls will either succeed and obtain
85 * a reference before we clear the umad_port[] entries, or fail after
86 * we clear the umad_port[] entries.
87 */
88
67struct ib_umad_port { 89struct ib_umad_port {
68 int devnum; 90 struct cdev *dev;
69 struct cdev dev; 91 struct class_device *class_dev;
70 struct class_device class_dev;
71 92
72 int sm_devnum; 93 struct cdev *sm_dev;
73 struct cdev sm_dev; 94 struct class_device *sm_class_dev;
74 struct class_device sm_class_dev;
75 struct semaphore sm_sem; 95 struct semaphore sm_sem;
76 96
77 struct ib_device *ib_dev; 97 struct ib_device *ib_dev;
78 struct ib_umad_device *umad_dev; 98 struct ib_umad_device *umad_dev;
99 int dev_num;
79 u8 port_num; 100 u8 port_num;
80}; 101};
81 102
@@ -96,21 +117,31 @@ struct ib_umad_file {
96}; 117};
97 118
98struct ib_umad_packet { 119struct ib_umad_packet {
99 struct ib_ah *ah;
100 struct ib_mad_send_buf *msg; 120 struct ib_mad_send_buf *msg;
101 struct list_head list; 121 struct list_head list;
102 int length; 122 int length;
103 DECLARE_PCI_UNMAP_ADDR(mapping)
104 struct ib_user_mad mad; 123 struct ib_user_mad mad;
105}; 124};
106 125
126static struct class *umad_class;
127
107static const dev_t base_dev = MKDEV(IB_UMAD_MAJOR, IB_UMAD_MINOR_BASE); 128static const dev_t base_dev = MKDEV(IB_UMAD_MAJOR, IB_UMAD_MINOR_BASE);
108static spinlock_t map_lock; 129
130static DEFINE_SPINLOCK(port_lock);
131static struct ib_umad_port *umad_port[IB_UMAD_MAX_PORTS];
109static DECLARE_BITMAP(dev_map, IB_UMAD_MAX_PORTS * 2); 132static DECLARE_BITMAP(dev_map, IB_UMAD_MAX_PORTS * 2);
110 133
111static void ib_umad_add_one(struct ib_device *device); 134static void ib_umad_add_one(struct ib_device *device);
112static void ib_umad_remove_one(struct ib_device *device); 135static void ib_umad_remove_one(struct ib_device *device);
113 136
137static void ib_umad_release_dev(struct kref *ref)
138{
139 struct ib_umad_device *dev =
140 container_of(ref, struct ib_umad_device, ref);
141
142 kfree(dev);
143}
144
114static int queue_packet(struct ib_umad_file *file, 145static int queue_packet(struct ib_umad_file *file,
115 struct ib_mad_agent *agent, 146 struct ib_mad_agent *agent,
116 struct ib_umad_packet *packet) 147 struct ib_umad_packet *packet)
@@ -139,22 +170,19 @@ static void send_handler(struct ib_mad_agent *agent,
139 struct ib_mad_send_wc *send_wc) 170 struct ib_mad_send_wc *send_wc)
140{ 171{
141 struct ib_umad_file *file = agent->context; 172 struct ib_umad_file *file = agent->context;
142 struct ib_umad_packet *timeout, *packet = 173 struct ib_umad_packet *timeout;
143 (void *) (unsigned long) send_wc->wr_id; 174 struct ib_umad_packet *packet = send_wc->send_buf->context[0];
144 175
145 ib_destroy_ah(packet->msg->send_wr.wr.ud.ah); 176 ib_destroy_ah(packet->msg->ah);
146 ib_free_send_mad(packet->msg); 177 ib_free_send_mad(packet->msg);
147 178
148 if (send_wc->status == IB_WC_RESP_TIMEOUT_ERR) { 179 if (send_wc->status == IB_WC_RESP_TIMEOUT_ERR) {
149 timeout = kmalloc(sizeof *timeout + sizeof (struct ib_mad_hdr), 180 timeout = kzalloc(sizeof *timeout + IB_MGMT_MAD_HDR, GFP_KERNEL);
150 GFP_KERNEL);
151 if (!timeout) 181 if (!timeout)
152 goto out; 182 goto out;
153 183
154 memset(timeout, 0, sizeof *timeout + sizeof (struct ib_mad_hdr)); 184 timeout->length = IB_MGMT_MAD_HDR;
155 185 timeout->mad.hdr.id = packet->mad.hdr.id;
156 timeout->length = sizeof (struct ib_mad_hdr);
157 timeout->mad.hdr.id = packet->mad.hdr.id;
158 timeout->mad.hdr.status = ETIMEDOUT; 186 timeout->mad.hdr.status = ETIMEDOUT;
159 memcpy(timeout->mad.data, packet->mad.data, 187 memcpy(timeout->mad.data, packet->mad.data,
160 sizeof (struct ib_mad_hdr)); 188 sizeof (struct ib_mad_hdr));
@@ -177,11 +205,10 @@ static void recv_handler(struct ib_mad_agent *agent,
177 goto out; 205 goto out;
178 206
179 length = mad_recv_wc->mad_len; 207 length = mad_recv_wc->mad_len;
180 packet = kmalloc(sizeof *packet + length, GFP_KERNEL); 208 packet = kzalloc(sizeof *packet + length, GFP_KERNEL);
181 if (!packet) 209 if (!packet)
182 goto out; 210 goto out;
183 211
184 memset(packet, 0, sizeof *packet + length);
185 packet->length = length; 212 packet->length = length;
186 213
187 ib_coalesce_recv_mad(mad_recv_wc, packet->mad.data); 214 ib_coalesce_recv_mad(mad_recv_wc, packet->mad.data);
@@ -247,7 +274,7 @@ static ssize_t ib_umad_read(struct file *filp, char __user *buf,
247 else 274 else
248 ret = -ENOSPC; 275 ret = -ENOSPC;
249 } else if (copy_to_user(buf, &packet->mad, 276 } else if (copy_to_user(buf, &packet->mad,
250 packet->length + sizeof (struct ib_user_mad))) 277 packet->length + sizeof (struct ib_user_mad)))
251 ret = -EFAULT; 278 ret = -EFAULT;
252 else 279 else
253 ret = packet->length + sizeof (struct ib_user_mad); 280 ret = packet->length + sizeof (struct ib_user_mad);
@@ -268,26 +295,23 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
268 struct ib_umad_packet *packet; 295 struct ib_umad_packet *packet;
269 struct ib_mad_agent *agent; 296 struct ib_mad_agent *agent;
270 struct ib_ah_attr ah_attr; 297 struct ib_ah_attr ah_attr;
271 struct ib_send_wr *bad_wr; 298 struct ib_ah *ah;
272 struct ib_rmpp_mad *rmpp_mad; 299 struct ib_rmpp_mad *rmpp_mad;
273 u8 method; 300 u8 method;
274 __be64 *tid; 301 __be64 *tid;
275 int ret, length, hdr_len, data_len, rmpp_hdr_size; 302 int ret, length, hdr_len, copy_offset;
276 int rmpp_active = 0; 303 int rmpp_active = 0;
277 304
278 if (count < sizeof (struct ib_user_mad)) 305 if (count < sizeof (struct ib_user_mad))
279 return -EINVAL; 306 return -EINVAL;
280 307
281 length = count - sizeof (struct ib_user_mad); 308 length = count - sizeof (struct ib_user_mad);
282 packet = kmalloc(sizeof *packet + sizeof(struct ib_mad_hdr) + 309 packet = kmalloc(sizeof *packet + IB_MGMT_RMPP_HDR, GFP_KERNEL);
283 sizeof(struct ib_rmpp_hdr), GFP_KERNEL);
284 if (!packet) 310 if (!packet)
285 return -ENOMEM; 311 return -ENOMEM;
286 312
287 if (copy_from_user(&packet->mad, buf, 313 if (copy_from_user(&packet->mad, buf,
288 sizeof (struct ib_user_mad) + 314 sizeof (struct ib_user_mad) + IB_MGMT_RMPP_HDR)) {
289 sizeof(struct ib_mad_hdr) +
290 sizeof(struct ib_rmpp_hdr))) {
291 ret = -EFAULT; 315 ret = -EFAULT;
292 goto err; 316 goto err;
293 } 317 }
@@ -298,8 +322,6 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
298 goto err; 322 goto err;
299 } 323 }
300 324
301 packet->length = length;
302
303 down_read(&file->agent_mutex); 325 down_read(&file->agent_mutex);
304 326
305 agent = file->agent[packet->mad.hdr.id]; 327 agent = file->agent[packet->mad.hdr.id];
@@ -321,9 +343,9 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
321 ah_attr.grh.traffic_class = packet->mad.hdr.traffic_class; 343 ah_attr.grh.traffic_class = packet->mad.hdr.traffic_class;
322 } 344 }
323 345
324 packet->ah = ib_create_ah(agent->qp->pd, &ah_attr); 346 ah = ib_create_ah(agent->qp->pd, &ah_attr);
325 if (IS_ERR(packet->ah)) { 347 if (IS_ERR(ah)) {
326 ret = PTR_ERR(packet->ah); 348 ret = PTR_ERR(ah);
327 goto err_up; 349 goto err_up;
328 } 350 }
329 351
@@ -337,64 +359,44 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
337 359
338 /* Validate that the management class can support RMPP */ 360 /* Validate that the management class can support RMPP */
339 if (rmpp_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_ADM) { 361 if (rmpp_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_ADM) {
340 hdr_len = offsetof(struct ib_sa_mad, data); 362 hdr_len = IB_MGMT_SA_HDR;
341 data_len = length - hdr_len;
342 } else if ((rmpp_mad->mad_hdr.mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START) && 363 } else if ((rmpp_mad->mad_hdr.mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START) &&
343 (rmpp_mad->mad_hdr.mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END)) { 364 (rmpp_mad->mad_hdr.mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END)) {
344 hdr_len = offsetof(struct ib_vendor_mad, data); 365 hdr_len = IB_MGMT_VENDOR_HDR;
345 data_len = length - hdr_len;
346 } else { 366 } else {
347 ret = -EINVAL; 367 ret = -EINVAL;
348 goto err_ah; 368 goto err_ah;
349 } 369 }
350 rmpp_active = 1; 370 rmpp_active = 1;
371 copy_offset = IB_MGMT_RMPP_HDR;
351 } else { 372 } else {
352 if (length > sizeof(struct ib_mad)) { 373 hdr_len = IB_MGMT_MAD_HDR;
353 ret = -EINVAL; 374 copy_offset = IB_MGMT_MAD_HDR;
354 goto err_ah;
355 }
356 hdr_len = offsetof(struct ib_mad, data);
357 data_len = length - hdr_len;
358 } 375 }
359 376
360 packet->msg = ib_create_send_mad(agent, 377 packet->msg = ib_create_send_mad(agent,
361 be32_to_cpu(packet->mad.hdr.qpn), 378 be32_to_cpu(packet->mad.hdr.qpn),
362 0, packet->ah, rmpp_active, 379 0, rmpp_active,
363 hdr_len, data_len, 380 hdr_len, length - hdr_len,
364 GFP_KERNEL); 381 GFP_KERNEL);
365 if (IS_ERR(packet->msg)) { 382 if (IS_ERR(packet->msg)) {
366 ret = PTR_ERR(packet->msg); 383 ret = PTR_ERR(packet->msg);
367 goto err_ah; 384 goto err_ah;
368 } 385 }
369 386
370 packet->msg->send_wr.wr.ud.timeout_ms = packet->mad.hdr.timeout_ms; 387 packet->msg->ah = ah;
371 packet->msg->send_wr.wr.ud.retries = packet->mad.hdr.retries; 388 packet->msg->timeout_ms = packet->mad.hdr.timeout_ms;
372 389 packet->msg->retries = packet->mad.hdr.retries;
373 /* Override send WR WRID initialized in ib_create_send_mad */ 390 packet->msg->context[0] = packet;
374 packet->msg->send_wr.wr_id = (unsigned long) packet;
375
376 if (!rmpp_active) {
377 /* Copy message from user into send buffer */
378 if (copy_from_user(packet->msg->mad,
379 buf + sizeof(struct ib_user_mad), length)) {
380 ret = -EFAULT;
381 goto err_msg;
382 }
383 } else {
384 rmpp_hdr_size = sizeof(struct ib_mad_hdr) +
385 sizeof(struct ib_rmpp_hdr);
386 391
387 /* Only copy MAD headers (RMPP header in place) */ 392 /* Copy MAD headers (RMPP header in place) */
388 memcpy(packet->msg->mad, packet->mad.data, 393 memcpy(packet->msg->mad, packet->mad.data, IB_MGMT_MAD_HDR);
389 sizeof(struct ib_mad_hdr)); 394 /* Now, copy rest of message from user into send buffer */
390 395 if (copy_from_user(packet->msg->mad + copy_offset,
391 /* Now, copy rest of message from user into send buffer */ 396 buf + sizeof (struct ib_user_mad) + copy_offset,
392 if (copy_from_user(((struct ib_rmpp_mad *) packet->msg->mad)->data, 397 length - copy_offset)) {
393 buf + sizeof (struct ib_user_mad) + rmpp_hdr_size, 398 ret = -EFAULT;
394 length - rmpp_hdr_size)) { 399 goto err_msg;
395 ret = -EFAULT;
396 goto err_msg;
397 }
398 } 400 }
399 401
400 /* 402 /*
@@ -403,29 +405,29 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
403 * transaction ID matches the agent being used to send the 405 * transaction ID matches the agent being used to send the
404 * MAD. 406 * MAD.
405 */ 407 */
406 method = packet->msg->mad->mad_hdr.method; 408 method = ((struct ib_mad_hdr *) packet->msg->mad)->method;
407 409
408 if (!(method & IB_MGMT_METHOD_RESP) && 410 if (!(method & IB_MGMT_METHOD_RESP) &&
409 method != IB_MGMT_METHOD_TRAP_REPRESS && 411 method != IB_MGMT_METHOD_TRAP_REPRESS &&
410 method != IB_MGMT_METHOD_SEND) { 412 method != IB_MGMT_METHOD_SEND) {
411 tid = &packet->msg->mad->mad_hdr.tid; 413 tid = &((struct ib_mad_hdr *) packet->msg->mad)->tid;
412 *tid = cpu_to_be64(((u64) agent->hi_tid) << 32 | 414 *tid = cpu_to_be64(((u64) agent->hi_tid) << 32 |
413 (be64_to_cpup(tid) & 0xffffffff)); 415 (be64_to_cpup(tid) & 0xffffffff));
414 } 416 }
415 417
416 ret = ib_post_send_mad(agent, &packet->msg->send_wr, &bad_wr); 418 ret = ib_post_send_mad(packet->msg, NULL);
417 if (ret) 419 if (ret)
418 goto err_msg; 420 goto err_msg;
419 421
420 up_read(&file->agent_mutex); 422 up_read(&file->agent_mutex);
421 423
422 return sizeof (struct ib_user_mad_hdr) + packet->length; 424 return count;
423 425
424err_msg: 426err_msg:
425 ib_free_send_mad(packet->msg); 427 ib_free_send_mad(packet->msg);
426 428
427err_ah: 429err_ah:
428 ib_destroy_ah(packet->ah); 430 ib_destroy_ah(ah);
429 431
430err_up: 432err_up:
431 up_read(&file->agent_mutex); 433 up_read(&file->agent_mutex);
@@ -565,15 +567,23 @@ static long ib_umad_ioctl(struct file *filp, unsigned int cmd,
565 567
566static int ib_umad_open(struct inode *inode, struct file *filp) 568static int ib_umad_open(struct inode *inode, struct file *filp)
567{ 569{
568 struct ib_umad_port *port = 570 struct ib_umad_port *port;
569 container_of(inode->i_cdev, struct ib_umad_port, dev);
570 struct ib_umad_file *file; 571 struct ib_umad_file *file;
571 572
572 file = kmalloc(sizeof *file, GFP_KERNEL); 573 spin_lock(&port_lock);
573 if (!file) 574 port = umad_port[iminor(inode) - IB_UMAD_MINOR_BASE];
574 return -ENOMEM; 575 if (port)
576 kref_get(&port->umad_dev->ref);
577 spin_unlock(&port_lock);
575 578
576 memset(file, 0, sizeof *file); 579 if (!port)
580 return -ENXIO;
581
582 file = kzalloc(sizeof *file, GFP_KERNEL);
583 if (!file) {
584 kref_put(&port->umad_dev->ref, ib_umad_release_dev);
585 return -ENOMEM;
586 }
577 587
578 spin_lock_init(&file->recv_lock); 588 spin_lock_init(&file->recv_lock);
579 init_rwsem(&file->agent_mutex); 589 init_rwsem(&file->agent_mutex);
@@ -589,6 +599,7 @@ static int ib_umad_open(struct inode *inode, struct file *filp)
589static int ib_umad_close(struct inode *inode, struct file *filp) 599static int ib_umad_close(struct inode *inode, struct file *filp)
590{ 600{
591 struct ib_umad_file *file = filp->private_data; 601 struct ib_umad_file *file = filp->private_data;
602 struct ib_umad_device *dev = file->port->umad_dev;
592 struct ib_umad_packet *packet, *tmp; 603 struct ib_umad_packet *packet, *tmp;
593 int i; 604 int i;
594 605
@@ -603,6 +614,8 @@ static int ib_umad_close(struct inode *inode, struct file *filp)
603 614
604 kfree(file); 615 kfree(file);
605 616
617 kref_put(&dev->ref, ib_umad_release_dev);
618
606 return 0; 619 return 0;
607} 620}
608 621
@@ -619,30 +632,46 @@ static struct file_operations umad_fops = {
619 632
620static int ib_umad_sm_open(struct inode *inode, struct file *filp) 633static int ib_umad_sm_open(struct inode *inode, struct file *filp)
621{ 634{
622 struct ib_umad_port *port = 635 struct ib_umad_port *port;
623 container_of(inode->i_cdev, struct ib_umad_port, sm_dev);
624 struct ib_port_modify props = { 636 struct ib_port_modify props = {
625 .set_port_cap_mask = IB_PORT_SM 637 .set_port_cap_mask = IB_PORT_SM
626 }; 638 };
627 int ret; 639 int ret;
628 640
641 spin_lock(&port_lock);
642 port = umad_port[iminor(inode) - IB_UMAD_MINOR_BASE - IB_UMAD_MAX_PORTS];
643 if (port)
644 kref_get(&port->umad_dev->ref);
645 spin_unlock(&port_lock);
646
647 if (!port)
648 return -ENXIO;
649
629 if (filp->f_flags & O_NONBLOCK) { 650 if (filp->f_flags & O_NONBLOCK) {
630 if (down_trylock(&port->sm_sem)) 651 if (down_trylock(&port->sm_sem)) {
631 return -EAGAIN; 652 ret = -EAGAIN;
653 goto fail;
654 }
632 } else { 655 } else {
633 if (down_interruptible(&port->sm_sem)) 656 if (down_interruptible(&port->sm_sem)) {
634 return -ERESTARTSYS; 657 ret = -ERESTARTSYS;
658 goto fail;
659 }
635 } 660 }
636 661
637 ret = ib_modify_port(port->ib_dev, port->port_num, 0, &props); 662 ret = ib_modify_port(port->ib_dev, port->port_num, 0, &props);
638 if (ret) { 663 if (ret) {
639 up(&port->sm_sem); 664 up(&port->sm_sem);
640 return ret; 665 goto fail;
641 } 666 }
642 667
643 filp->private_data = port; 668 filp->private_data = port;
644 669
645 return 0; 670 return 0;
671
672fail:
673 kref_put(&port->umad_dev->ref, ib_umad_release_dev);
674 return ret;
646} 675}
647 676
648static int ib_umad_sm_close(struct inode *inode, struct file *filp) 677static int ib_umad_sm_close(struct inode *inode, struct file *filp)
@@ -656,6 +685,8 @@ static int ib_umad_sm_close(struct inode *inode, struct file *filp)
656 ret = ib_modify_port(port->ib_dev, port->port_num, 0, &props); 685 ret = ib_modify_port(port->ib_dev, port->port_num, 0, &props);
657 up(&port->sm_sem); 686 up(&port->sm_sem);
658 687
688 kref_put(&port->umad_dev->ref, ib_umad_release_dev);
689
659 return ret; 690 return ret;
660} 691}
661 692
@@ -671,21 +702,13 @@ static struct ib_client umad_client = {
671 .remove = ib_umad_remove_one 702 .remove = ib_umad_remove_one
672}; 703};
673 704
674static ssize_t show_dev(struct class_device *class_dev, char *buf)
675{
676 struct ib_umad_port *port = class_get_devdata(class_dev);
677
678 if (class_dev == &port->class_dev)
679 return print_dev_t(buf, port->dev.dev);
680 else
681 return print_dev_t(buf, port->sm_dev.dev);
682}
683static CLASS_DEVICE_ATTR(dev, S_IRUGO, show_dev, NULL);
684
685static ssize_t show_ibdev(struct class_device *class_dev, char *buf) 705static ssize_t show_ibdev(struct class_device *class_dev, char *buf)
686{ 706{
687 struct ib_umad_port *port = class_get_devdata(class_dev); 707 struct ib_umad_port *port = class_get_devdata(class_dev);
688 708
709 if (!port)
710 return -ENODEV;
711
689 return sprintf(buf, "%s\n", port->ib_dev->name); 712 return sprintf(buf, "%s\n", port->ib_dev->name);
690} 713}
691static CLASS_DEVICE_ATTR(ibdev, S_IRUGO, show_ibdev, NULL); 714static CLASS_DEVICE_ATTR(ibdev, S_IRUGO, show_ibdev, NULL);
@@ -694,38 +717,13 @@ static ssize_t show_port(struct class_device *class_dev, char *buf)
694{ 717{
695 struct ib_umad_port *port = class_get_devdata(class_dev); 718 struct ib_umad_port *port = class_get_devdata(class_dev);
696 719
720 if (!port)
721 return -ENODEV;
722
697 return sprintf(buf, "%d\n", port->port_num); 723 return sprintf(buf, "%d\n", port->port_num);
698} 724}
699static CLASS_DEVICE_ATTR(port, S_IRUGO, show_port, NULL); 725static CLASS_DEVICE_ATTR(port, S_IRUGO, show_port, NULL);
700 726
701static void ib_umad_release_dev(struct kref *ref)
702{
703 struct ib_umad_device *dev =
704 container_of(ref, struct ib_umad_device, ref);
705
706 kfree(dev);
707}
708
709static void ib_umad_release_port(struct class_device *class_dev)
710{
711 struct ib_umad_port *port = class_get_devdata(class_dev);
712
713 if (class_dev == &port->class_dev) {
714 cdev_del(&port->dev);
715 clear_bit(port->devnum, dev_map);
716 } else {
717 cdev_del(&port->sm_dev);
718 clear_bit(port->sm_devnum, dev_map);
719 }
720
721 kref_put(&port->umad_dev->ref, ib_umad_release_dev);
722}
723
724static struct class umad_class = {
725 .name = "infiniband_mad",
726 .release = ib_umad_release_port
727};
728
729static ssize_t show_abi_version(struct class *class, char *buf) 727static ssize_t show_abi_version(struct class *class, char *buf)
730{ 728{
731 return sprintf(buf, "%d\n", IB_USER_MAD_ABI_VERSION); 729 return sprintf(buf, "%d\n", IB_USER_MAD_ABI_VERSION);
@@ -735,91 +733,102 @@ static CLASS_ATTR(abi_version, S_IRUGO, show_abi_version, NULL);
735static int ib_umad_init_port(struct ib_device *device, int port_num, 733static int ib_umad_init_port(struct ib_device *device, int port_num,
736 struct ib_umad_port *port) 734 struct ib_umad_port *port)
737{ 735{
738 spin_lock(&map_lock); 736 spin_lock(&port_lock);
739 port->devnum = find_first_zero_bit(dev_map, IB_UMAD_MAX_PORTS); 737 port->dev_num = find_first_zero_bit(dev_map, IB_UMAD_MAX_PORTS);
740 if (port->devnum >= IB_UMAD_MAX_PORTS) { 738 if (port->dev_num >= IB_UMAD_MAX_PORTS) {
741 spin_unlock(&map_lock); 739 spin_unlock(&port_lock);
742 return -1; 740 return -1;
743 } 741 }
744 port->sm_devnum = find_next_zero_bit(dev_map, IB_UMAD_MAX_PORTS * 2, IB_UMAD_MAX_PORTS); 742 set_bit(port->dev_num, dev_map);
745 if (port->sm_devnum >= IB_UMAD_MAX_PORTS * 2) { 743 spin_unlock(&port_lock);
746 spin_unlock(&map_lock);
747 return -1;
748 }
749 set_bit(port->devnum, dev_map);
750 set_bit(port->sm_devnum, dev_map);
751 spin_unlock(&map_lock);
752 744
753 port->ib_dev = device; 745 port->ib_dev = device;
754 port->port_num = port_num; 746 port->port_num = port_num;
755 init_MUTEX(&port->sm_sem); 747 init_MUTEX(&port->sm_sem);
756 748
757 cdev_init(&port->dev, &umad_fops); 749 port->dev = cdev_alloc();
758 port->dev.owner = THIS_MODULE; 750 if (!port->dev)
759 kobject_set_name(&port->dev.kobj, "umad%d", port->devnum);
760 if (cdev_add(&port->dev, base_dev + port->devnum, 1))
761 return -1; 751 return -1;
762 752 port->dev->owner = THIS_MODULE;
763 port->class_dev.class = &umad_class; 753 port->dev->ops = &umad_fops;
764 port->class_dev.dev = device->dma_device; 754 kobject_set_name(&port->dev->kobj, "umad%d", port->dev_num);
765 755 if (cdev_add(port->dev, base_dev + port->dev_num, 1))
766 snprintf(port->class_dev.class_id, BUS_ID_SIZE, "umad%d", port->devnum);
767
768 if (class_device_register(&port->class_dev))
769 goto err_cdev; 756 goto err_cdev;
770 757
771 class_set_devdata(&port->class_dev, port); 758 port->class_dev = class_device_create(umad_class, NULL, port->dev->dev,
772 kref_get(&port->umad_dev->ref); 759 device->dma_device,
760 "umad%d", port->dev_num);
761 if (IS_ERR(port->class_dev))
762 goto err_cdev;
773 763
774 if (class_device_create_file(&port->class_dev, &class_device_attr_dev)) 764 if (class_device_create_file(port->class_dev, &class_device_attr_ibdev))
775 goto err_class;
776 if (class_device_create_file(&port->class_dev, &class_device_attr_ibdev))
777 goto err_class; 765 goto err_class;
778 if (class_device_create_file(&port->class_dev, &class_device_attr_port)) 766 if (class_device_create_file(port->class_dev, &class_device_attr_port))
779 goto err_class; 767 goto err_class;
780 768
781 cdev_init(&port->sm_dev, &umad_sm_fops); 769 port->sm_dev = cdev_alloc();
782 port->sm_dev.owner = THIS_MODULE; 770 if (!port->sm_dev)
783 kobject_set_name(&port->dev.kobj, "issm%d", port->sm_devnum - IB_UMAD_MAX_PORTS); 771 goto err_class;
784 if (cdev_add(&port->sm_dev, base_dev + port->sm_devnum, 1)) 772 port->sm_dev->owner = THIS_MODULE;
785 return -1; 773 port->sm_dev->ops = &umad_sm_fops;
786 774 kobject_set_name(&port->dev->kobj, "issm%d", port->dev_num);
787 port->sm_class_dev.class = &umad_class; 775 if (cdev_add(port->sm_dev, base_dev + port->dev_num + IB_UMAD_MAX_PORTS, 1))
788 port->sm_class_dev.dev = device->dma_device; 776 goto err_sm_cdev;
789
790 snprintf(port->sm_class_dev.class_id, BUS_ID_SIZE, "issm%d", port->sm_devnum - IB_UMAD_MAX_PORTS);
791 777
792 if (class_device_register(&port->sm_class_dev)) 778 port->sm_class_dev = class_device_create(umad_class, NULL, port->sm_dev->dev,
779 device->dma_device,
780 "issm%d", port->dev_num);
781 if (IS_ERR(port->sm_class_dev))
793 goto err_sm_cdev; 782 goto err_sm_cdev;
794 783
795 class_set_devdata(&port->sm_class_dev, port); 784 class_set_devdata(port->class_dev, port);
796 kref_get(&port->umad_dev->ref); 785 class_set_devdata(port->sm_class_dev, port);
797 786
798 if (class_device_create_file(&port->sm_class_dev, &class_device_attr_dev)) 787 if (class_device_create_file(port->sm_class_dev, &class_device_attr_ibdev))
799 goto err_sm_class;
800 if (class_device_create_file(&port->sm_class_dev, &class_device_attr_ibdev))
801 goto err_sm_class; 788 goto err_sm_class;
802 if (class_device_create_file(&port->sm_class_dev, &class_device_attr_port)) 789 if (class_device_create_file(port->sm_class_dev, &class_device_attr_port))
803 goto err_sm_class; 790 goto err_sm_class;
804 791
792 spin_lock(&port_lock);
793 umad_port[port->dev_num] = port;
794 spin_unlock(&port_lock);
795
805 return 0; 796 return 0;
806 797
807err_sm_class: 798err_sm_class:
808 class_device_unregister(&port->sm_class_dev); 799 class_device_destroy(umad_class, port->sm_dev->dev);
809 800
810err_sm_cdev: 801err_sm_cdev:
811 cdev_del(&port->sm_dev); 802 cdev_del(port->sm_dev);
812 803
813err_class: 804err_class:
814 class_device_unregister(&port->class_dev); 805 class_device_destroy(umad_class, port->dev->dev);
815 806
816err_cdev: 807err_cdev:
817 cdev_del(&port->dev); 808 cdev_del(port->dev);
818 clear_bit(port->devnum, dev_map); 809 clear_bit(port->dev_num, dev_map);
819 810
820 return -1; 811 return -1;
821} 812}
822 813
814static void ib_umad_kill_port(struct ib_umad_port *port)
815{
816 class_set_devdata(port->class_dev, NULL);
817 class_set_devdata(port->sm_class_dev, NULL);
818
819 class_device_destroy(umad_class, port->dev->dev);
820 class_device_destroy(umad_class, port->sm_dev->dev);
821
822 cdev_del(port->dev);
823 cdev_del(port->sm_dev);
824
825 spin_lock(&port_lock);
826 umad_port[port->dev_num] = NULL;
827 spin_unlock(&port_lock);
828
829 clear_bit(port->dev_num, dev_map);
830}
831
823static void ib_umad_add_one(struct ib_device *device) 832static void ib_umad_add_one(struct ib_device *device)
824{ 833{
825 struct ib_umad_device *umad_dev; 834 struct ib_umad_device *umad_dev;
@@ -832,15 +841,12 @@ static void ib_umad_add_one(struct ib_device *device)
832 e = device->phys_port_cnt; 841 e = device->phys_port_cnt;
833 } 842 }
834 843
835 umad_dev = kmalloc(sizeof *umad_dev + 844 umad_dev = kzalloc(sizeof *umad_dev +
836 (e - s + 1) * sizeof (struct ib_umad_port), 845 (e - s + 1) * sizeof (struct ib_umad_port),
837 GFP_KERNEL); 846 GFP_KERNEL);
838 if (!umad_dev) 847 if (!umad_dev)
839 return; 848 return;
840 849
841 memset(umad_dev, 0, sizeof *umad_dev +
842 (e - s + 1) * sizeof (struct ib_umad_port));
843
844 kref_init(&umad_dev->ref); 850 kref_init(&umad_dev->ref);
845 851
846 umad_dev->start_port = s; 852 umad_dev->start_port = s;
@@ -858,10 +864,8 @@ static void ib_umad_add_one(struct ib_device *device)
858 return; 864 return;
859 865
860err: 866err:
861 while (--i >= s) { 867 while (--i >= s)
862 class_device_unregister(&umad_dev->port[i - s].class_dev); 868 ib_umad_kill_port(&umad_dev->port[i]);
863 class_device_unregister(&umad_dev->port[i - s].sm_class_dev);
864 }
865 869
866 kref_put(&umad_dev->ref, ib_umad_release_dev); 870 kref_put(&umad_dev->ref, ib_umad_release_dev);
867} 871}
@@ -874,10 +878,8 @@ static void ib_umad_remove_one(struct ib_device *device)
874 if (!umad_dev) 878 if (!umad_dev)
875 return; 879 return;
876 880
877 for (i = 0; i <= umad_dev->end_port - umad_dev->start_port; ++i) { 881 for (i = 0; i <= umad_dev->end_port - umad_dev->start_port; ++i)
878 class_device_unregister(&umad_dev->port[i].class_dev); 882 ib_umad_kill_port(&umad_dev->port[i]);
879 class_device_unregister(&umad_dev->port[i].sm_class_dev);
880 }
881 883
882 kref_put(&umad_dev->ref, ib_umad_release_dev); 884 kref_put(&umad_dev->ref, ib_umad_release_dev);
883} 885}
@@ -886,8 +888,6 @@ static int __init ib_umad_init(void)
886{ 888{
887 int ret; 889 int ret;
888 890
889 spin_lock_init(&map_lock);
890
891 ret = register_chrdev_region(base_dev, IB_UMAD_MAX_PORTS * 2, 891 ret = register_chrdev_region(base_dev, IB_UMAD_MAX_PORTS * 2,
892 "infiniband_mad"); 892 "infiniband_mad");
893 if (ret) { 893 if (ret) {
@@ -895,13 +895,14 @@ static int __init ib_umad_init(void)
895 goto out; 895 goto out;
896 } 896 }
897 897
898 ret = class_register(&umad_class); 898 umad_class = class_create(THIS_MODULE, "infiniband_mad");
899 if (ret) { 899 if (IS_ERR(umad_class)) {
900 ret = PTR_ERR(umad_class);
900 printk(KERN_ERR "user_mad: couldn't create class infiniband_mad\n"); 901 printk(KERN_ERR "user_mad: couldn't create class infiniband_mad\n");
901 goto out_chrdev; 902 goto out_chrdev;
902 } 903 }
903 904
904 ret = class_create_file(&umad_class, &class_attr_abi_version); 905 ret = class_create_file(umad_class, &class_attr_abi_version);
905 if (ret) { 906 if (ret) {
906 printk(KERN_ERR "user_mad: couldn't create abi_version attribute\n"); 907 printk(KERN_ERR "user_mad: couldn't create abi_version attribute\n");
907 goto out_class; 908 goto out_class;
@@ -916,7 +917,7 @@ static int __init ib_umad_init(void)
916 return 0; 917 return 0;
917 918
918out_class: 919out_class:
919 class_unregister(&umad_class); 920 class_destroy(umad_class);
920 921
921out_chrdev: 922out_chrdev:
922 unregister_chrdev_region(base_dev, IB_UMAD_MAX_PORTS * 2); 923 unregister_chrdev_region(base_dev, IB_UMAD_MAX_PORTS * 2);
@@ -928,7 +929,7 @@ out:
928static void __exit ib_umad_cleanup(void) 929static void __exit ib_umad_cleanup(void)
929{ 930{
930 ib_unregister_client(&umad_client); 931 ib_unregister_client(&umad_client);
931 class_unregister(&umad_class); 932 class_destroy(umad_class);
932 unregister_chrdev_region(base_dev, IB_UMAD_MAX_PORTS * 2); 933 unregister_chrdev_region(base_dev, IB_UMAD_MAX_PORTS * 2);
933} 934}
934 935
diff --git a/drivers/infiniband/core/uverbs.h b/drivers/infiniband/core/uverbs.h
index cc124344dd2c..031cdf3c066d 100644
--- a/drivers/infiniband/core/uverbs.h
+++ b/drivers/infiniband/core/uverbs.h
@@ -3,6 +3,7 @@
3 * Copyright (c) 2005 Cisco Systems. All rights reserved. 3 * Copyright (c) 2005 Cisco Systems. All rights reserved.
4 * Copyright (c) 2005 Mellanox Technologies. All rights reserved. 4 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
5 * Copyright (c) 2005 Voltaire, Inc. All rights reserved. 5 * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
6 * Copyright (c) 2005 PathScale, Inc. All rights reserved.
6 * 7 *
7 * This software is available to you under a choice of one of two 8 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU 9 * licenses. You may choose to be licensed under the terms of the GNU
@@ -38,29 +39,47 @@
38#ifndef UVERBS_H 39#ifndef UVERBS_H
39#define UVERBS_H 40#define UVERBS_H
40 41
41/* Include device.h and fs.h until cdev.h is self-sufficient */
42#include <linux/fs.h>
43#include <linux/device.h>
44#include <linux/cdev.h>
45#include <linux/kref.h> 42#include <linux/kref.h>
46#include <linux/idr.h> 43#include <linux/idr.h>
47 44
48#include <rdma/ib_verbs.h> 45#include <rdma/ib_verbs.h>
49#include <rdma/ib_user_verbs.h> 46#include <rdma/ib_user_verbs.h>
50 47
48/*
49 * Our lifetime rules for these structs are the following:
50 *
51 * struct ib_uverbs_device: One reference is held by the module and
52 * released in ib_uverbs_remove_one(). Another reference is taken by
53 * ib_uverbs_open() each time the character special file is opened,
54 * and released in ib_uverbs_release_file() when the file is released.
55 *
56 * struct ib_uverbs_file: One reference is held by the VFS and
57 * released when the file is closed. Another reference is taken when
58 * an asynchronous event queue file is created and released when the
59 * event file is closed.
60 *
61 * struct ib_uverbs_event_file: One reference is held by the VFS and
62 * released when the file is closed. For asynchronous event files,
63 * another reference is held by the corresponding main context file
64 * and released when that file is closed. For completion event files,
65 * a reference is taken when a CQ is created that uses the file, and
66 * released when the CQ is destroyed.
67 */
68
51struct ib_uverbs_device { 69struct ib_uverbs_device {
70 struct kref ref;
52 int devnum; 71 int devnum;
53 struct cdev dev; 72 struct cdev *dev;
54 struct class_device class_dev; 73 struct class_device *class_dev;
55 struct ib_device *ib_dev; 74 struct ib_device *ib_dev;
56 int num_comp; 75 int num_comp_vectors;
57}; 76};
58 77
59struct ib_uverbs_event_file { 78struct ib_uverbs_event_file {
60 struct kref ref; 79 struct kref ref;
80 struct file *file;
61 struct ib_uverbs_file *uverbs_file; 81 struct ib_uverbs_file *uverbs_file;
62 spinlock_t lock; 82 spinlock_t lock;
63 int fd;
64 int is_async; 83 int is_async;
65 wait_queue_head_t poll_wait; 84 wait_queue_head_t poll_wait;
66 struct fasync_struct *async_queue; 85 struct fasync_struct *async_queue;
@@ -73,8 +92,7 @@ struct ib_uverbs_file {
73 struct ib_uverbs_device *device; 92 struct ib_uverbs_device *device;
74 struct ib_ucontext *ucontext; 93 struct ib_ucontext *ucontext;
75 struct ib_event_handler event_handler; 94 struct ib_event_handler event_handler;
76 struct ib_uverbs_event_file async_file; 95 struct ib_uverbs_event_file *async_file;
77 struct ib_uverbs_event_file comp_file[1];
78}; 96};
79 97
80struct ib_uverbs_event { 98struct ib_uverbs_event {
@@ -110,10 +128,23 @@ extern struct idr ib_uverbs_cq_idr;
110extern struct idr ib_uverbs_qp_idr; 128extern struct idr ib_uverbs_qp_idr;
111extern struct idr ib_uverbs_srq_idr; 129extern struct idr ib_uverbs_srq_idr;
112 130
131struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file,
132 int is_async, int *fd);
133void ib_uverbs_release_event_file(struct kref *ref);
134struct ib_uverbs_event_file *ib_uverbs_lookup_comp_file(int fd);
135
136void ib_uverbs_release_ucq(struct ib_uverbs_file *file,
137 struct ib_uverbs_event_file *ev_file,
138 struct ib_ucq_object *uobj);
139void ib_uverbs_release_uevent(struct ib_uverbs_file *file,
140 struct ib_uevent_object *uobj);
141
113void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context); 142void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context);
114void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr); 143void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr);
115void ib_uverbs_qp_event_handler(struct ib_event *event, void *context_ptr); 144void ib_uverbs_qp_event_handler(struct ib_event *event, void *context_ptr);
116void ib_uverbs_srq_event_handler(struct ib_event *event, void *context_ptr); 145void ib_uverbs_srq_event_handler(struct ib_event *event, void *context_ptr);
146void ib_uverbs_event_handler(struct ib_event_handler *handler,
147 struct ib_event *event);
117 148
118int ib_umem_get(struct ib_device *dev, struct ib_umem *mem, 149int ib_umem_get(struct ib_device *dev, struct ib_umem *mem,
119 void *addr, size_t size, int write); 150 void *addr, size_t size, int write);
@@ -125,21 +156,26 @@ void ib_umem_release_on_close(struct ib_device *dev, struct ib_umem *umem);
125 const char __user *buf, int in_len, \ 156 const char __user *buf, int in_len, \
126 int out_len) 157 int out_len)
127 158
128IB_UVERBS_DECLARE_CMD(query_params);
129IB_UVERBS_DECLARE_CMD(get_context); 159IB_UVERBS_DECLARE_CMD(get_context);
130IB_UVERBS_DECLARE_CMD(query_device); 160IB_UVERBS_DECLARE_CMD(query_device);
131IB_UVERBS_DECLARE_CMD(query_port); 161IB_UVERBS_DECLARE_CMD(query_port);
132IB_UVERBS_DECLARE_CMD(query_gid);
133IB_UVERBS_DECLARE_CMD(query_pkey);
134IB_UVERBS_DECLARE_CMD(alloc_pd); 162IB_UVERBS_DECLARE_CMD(alloc_pd);
135IB_UVERBS_DECLARE_CMD(dealloc_pd); 163IB_UVERBS_DECLARE_CMD(dealloc_pd);
136IB_UVERBS_DECLARE_CMD(reg_mr); 164IB_UVERBS_DECLARE_CMD(reg_mr);
137IB_UVERBS_DECLARE_CMD(dereg_mr); 165IB_UVERBS_DECLARE_CMD(dereg_mr);
166IB_UVERBS_DECLARE_CMD(create_comp_channel);
138IB_UVERBS_DECLARE_CMD(create_cq); 167IB_UVERBS_DECLARE_CMD(create_cq);
168IB_UVERBS_DECLARE_CMD(poll_cq);
169IB_UVERBS_DECLARE_CMD(req_notify_cq);
139IB_UVERBS_DECLARE_CMD(destroy_cq); 170IB_UVERBS_DECLARE_CMD(destroy_cq);
140IB_UVERBS_DECLARE_CMD(create_qp); 171IB_UVERBS_DECLARE_CMD(create_qp);
141IB_UVERBS_DECLARE_CMD(modify_qp); 172IB_UVERBS_DECLARE_CMD(modify_qp);
142IB_UVERBS_DECLARE_CMD(destroy_qp); 173IB_UVERBS_DECLARE_CMD(destroy_qp);
174IB_UVERBS_DECLARE_CMD(post_send);
175IB_UVERBS_DECLARE_CMD(post_recv);
176IB_UVERBS_DECLARE_CMD(post_srq_recv);
177IB_UVERBS_DECLARE_CMD(create_ah);
178IB_UVERBS_DECLARE_CMD(destroy_ah);
143IB_UVERBS_DECLARE_CMD(attach_mcast); 179IB_UVERBS_DECLARE_CMD(attach_mcast);
144IB_UVERBS_DECLARE_CMD(detach_mcast); 180IB_UVERBS_DECLARE_CMD(detach_mcast);
145IB_UVERBS_DECLARE_CMD(create_srq); 181IB_UVERBS_DECLARE_CMD(create_srq);
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index 562445165d2b..8c89abc8c764 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * Copyright (c) 2005 Topspin Communications. All rights reserved. 2 * Copyright (c) 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved. 3 * Copyright (c) 2005 Cisco Systems. All rights reserved.
4 * Copyright (c) 2005 PathScale, Inc. All rights reserved.
4 * 5 *
5 * This software is available to you under a choice of one of two 6 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 7 * licenses. You may choose to be licensed under the terms of the GNU
@@ -33,6 +34,9 @@
33 * $Id: uverbs_cmd.c 2708 2005-06-24 17:27:21Z roland $ 34 * $Id: uverbs_cmd.c 2708 2005-06-24 17:27:21Z roland $
34 */ 35 */
35 36
37#include <linux/file.h>
38#include <linux/fs.h>
39
36#include <asm/uaccess.h> 40#include <asm/uaccess.h>
37 41
38#include "uverbs.h" 42#include "uverbs.h"
@@ -45,29 +49,6 @@
45 (udata)->outlen = (olen); \ 49 (udata)->outlen = (olen); \
46 } while (0) 50 } while (0)
47 51
48ssize_t ib_uverbs_query_params(struct ib_uverbs_file *file,
49 const char __user *buf,
50 int in_len, int out_len)
51{
52 struct ib_uverbs_query_params cmd;
53 struct ib_uverbs_query_params_resp resp;
54
55 if (out_len < sizeof resp)
56 return -ENOSPC;
57
58 if (copy_from_user(&cmd, buf, sizeof cmd))
59 return -EFAULT;
60
61 memset(&resp, 0, sizeof resp);
62
63 resp.num_cq_events = file->device->num_comp;
64
65 if (copy_to_user((void __user *) (unsigned long) cmd.response, &resp, sizeof resp))
66 return -EFAULT;
67
68 return in_len;
69}
70
71ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file, 52ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file,
72 const char __user *buf, 53 const char __user *buf,
73 int in_len, int out_len) 54 int in_len, int out_len)
@@ -77,7 +58,7 @@ ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file,
77 struct ib_udata udata; 58 struct ib_udata udata;
78 struct ib_device *ibdev = file->device->ib_dev; 59 struct ib_device *ibdev = file->device->ib_dev;
79 struct ib_ucontext *ucontext; 60 struct ib_ucontext *ucontext;
80 int i; 61 struct file *filp;
81 int ret; 62 int ret;
82 63
83 if (out_len < sizeof resp) 64 if (out_len < sizeof resp)
@@ -110,26 +91,42 @@ ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file,
110 INIT_LIST_HEAD(&ucontext->srq_list); 91 INIT_LIST_HEAD(&ucontext->srq_list);
111 INIT_LIST_HEAD(&ucontext->ah_list); 92 INIT_LIST_HEAD(&ucontext->ah_list);
112 93
113 resp.async_fd = file->async_file.fd; 94 resp.num_comp_vectors = file->device->num_comp_vectors;
114 for (i = 0; i < file->device->num_comp; ++i) 95
115 if (copy_to_user((void __user *) (unsigned long) cmd.cq_fd_tab + 96 filp = ib_uverbs_alloc_event_file(file, 1, &resp.async_fd);
116 i * sizeof (__u32), 97 if (IS_ERR(filp)) {
117 &file->comp_file[i].fd, sizeof (__u32))) { 98 ret = PTR_ERR(filp);
118 ret = -EFAULT; 99 goto err_free;
119 goto err_free; 100 }
120 }
121 101
122 if (copy_to_user((void __user *) (unsigned long) cmd.response, 102 if (copy_to_user((void __user *) (unsigned long) cmd.response,
123 &resp, sizeof resp)) { 103 &resp, sizeof resp)) {
124 ret = -EFAULT; 104 ret = -EFAULT;
125 goto err_free; 105 goto err_file;
126 } 106 }
127 107
108 file->async_file = filp->private_data;
109
110 INIT_IB_EVENT_HANDLER(&file->event_handler, file->device->ib_dev,
111 ib_uverbs_event_handler);
112 ret = ib_register_event_handler(&file->event_handler);
113 if (ret)
114 goto err_file;
115
116 kref_get(&file->async_file->ref);
117 kref_get(&file->ref);
128 file->ucontext = ucontext; 118 file->ucontext = ucontext;
119
120 fd_install(resp.async_fd, filp);
121
129 up(&file->mutex); 122 up(&file->mutex);
130 123
131 return in_len; 124 return in_len;
132 125
126err_file:
127 put_unused_fd(resp.async_fd);
128 fput(filp);
129
133err_free: 130err_free:
134 ibdev->dealloc_ucontext(ucontext); 131 ibdev->dealloc_ucontext(ucontext);
135 132
@@ -255,62 +252,6 @@ ssize_t ib_uverbs_query_port(struct ib_uverbs_file *file,
255 return in_len; 252 return in_len;
256} 253}
257 254
258ssize_t ib_uverbs_query_gid(struct ib_uverbs_file *file,
259 const char __user *buf,
260 int in_len, int out_len)
261{
262 struct ib_uverbs_query_gid cmd;
263 struct ib_uverbs_query_gid_resp resp;
264 int ret;
265
266 if (out_len < sizeof resp)
267 return -ENOSPC;
268
269 if (copy_from_user(&cmd, buf, sizeof cmd))
270 return -EFAULT;
271
272 memset(&resp, 0, sizeof resp);
273
274 ret = ib_query_gid(file->device->ib_dev, cmd.port_num, cmd.index,
275 (union ib_gid *) resp.gid);
276 if (ret)
277 return ret;
278
279 if (copy_to_user((void __user *) (unsigned long) cmd.response,
280 &resp, sizeof resp))
281 return -EFAULT;
282
283 return in_len;
284}
285
286ssize_t ib_uverbs_query_pkey(struct ib_uverbs_file *file,
287 const char __user *buf,
288 int in_len, int out_len)
289{
290 struct ib_uverbs_query_pkey cmd;
291 struct ib_uverbs_query_pkey_resp resp;
292 int ret;
293
294 if (out_len < sizeof resp)
295 return -ENOSPC;
296
297 if (copy_from_user(&cmd, buf, sizeof cmd))
298 return -EFAULT;
299
300 memset(&resp, 0, sizeof resp);
301
302 ret = ib_query_pkey(file->device->ib_dev, cmd.port_num, cmd.index,
303 &resp.pkey);
304 if (ret)
305 return ret;
306
307 if (copy_to_user((void __user *) (unsigned long) cmd.response,
308 &resp, sizeof resp))
309 return -EFAULT;
310
311 return in_len;
312}
313
314ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file, 255ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file,
315 const char __user *buf, 256 const char __user *buf,
316 int in_len, int out_len) 257 int in_len, int out_len)
@@ -349,24 +290,20 @@ ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file,
349 pd->uobject = uobj; 290 pd->uobject = uobj;
350 atomic_set(&pd->usecnt, 0); 291 atomic_set(&pd->usecnt, 0);
351 292
293 down(&ib_uverbs_idr_mutex);
294
352retry: 295retry:
353 if (!idr_pre_get(&ib_uverbs_pd_idr, GFP_KERNEL)) { 296 if (!idr_pre_get(&ib_uverbs_pd_idr, GFP_KERNEL)) {
354 ret = -ENOMEM; 297 ret = -ENOMEM;
355 goto err_pd; 298 goto err_up;
356 } 299 }
357 300
358 down(&ib_uverbs_idr_mutex);
359 ret = idr_get_new(&ib_uverbs_pd_idr, pd, &uobj->id); 301 ret = idr_get_new(&ib_uverbs_pd_idr, pd, &uobj->id);
360 up(&ib_uverbs_idr_mutex);
361 302
362 if (ret == -EAGAIN) 303 if (ret == -EAGAIN)
363 goto retry; 304 goto retry;
364 if (ret) 305 if (ret)
365 goto err_pd; 306 goto err_up;
366
367 down(&file->mutex);
368 list_add_tail(&uobj->list, &file->ucontext->pd_list);
369 up(&file->mutex);
370 307
371 memset(&resp, 0, sizeof resp); 308 memset(&resp, 0, sizeof resp);
372 resp.pd_handle = uobj->id; 309 resp.pd_handle = uobj->id;
@@ -374,21 +311,22 @@ retry:
374 if (copy_to_user((void __user *) (unsigned long) cmd.response, 311 if (copy_to_user((void __user *) (unsigned long) cmd.response,
375 &resp, sizeof resp)) { 312 &resp, sizeof resp)) {
376 ret = -EFAULT; 313 ret = -EFAULT;
377 goto err_list; 314 goto err_idr;
378 } 315 }
379 316
380 return in_len; 317 down(&file->mutex);
381 318 list_add_tail(&uobj->list, &file->ucontext->pd_list);
382err_list:
383 down(&file->mutex);
384 list_del(&uobj->list);
385 up(&file->mutex); 319 up(&file->mutex);
386 320
387 down(&ib_uverbs_idr_mutex);
388 idr_remove(&ib_uverbs_pd_idr, uobj->id);
389 up(&ib_uverbs_idr_mutex); 321 up(&ib_uverbs_idr_mutex);
390 322
391err_pd: 323 return in_len;
324
325err_idr:
326 idr_remove(&ib_uverbs_pd_idr, uobj->id);
327
328err_up:
329 up(&ib_uverbs_idr_mutex);
392 ib_dealloc_pd(pd); 330 ib_dealloc_pd(pd);
393 331
394err: 332err:
@@ -459,6 +397,14 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
459 if ((cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK)) 397 if ((cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK))
460 return -EINVAL; 398 return -EINVAL;
461 399
400 /*
401 * Local write permission is required if remote write or
402 * remote atomic permission is also requested.
403 */
404 if (cmd.access_flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
405 !(cmd.access_flags & IB_ACCESS_LOCAL_WRITE))
406 return -EINVAL;
407
462 obj = kmalloc(sizeof *obj, GFP_KERNEL); 408 obj = kmalloc(sizeof *obj, GFP_KERNEL);
463 if (!obj) 409 if (!obj)
464 return -ENOMEM; 410 return -ENOMEM;
@@ -524,24 +470,22 @@ retry:
524 470
525 resp.mr_handle = obj->uobject.id; 471 resp.mr_handle = obj->uobject.id;
526 472
527 down(&file->mutex);
528 list_add_tail(&obj->uobject.list, &file->ucontext->mr_list);
529 up(&file->mutex);
530
531 if (copy_to_user((void __user *) (unsigned long) cmd.response, 473 if (copy_to_user((void __user *) (unsigned long) cmd.response,
532 &resp, sizeof resp)) { 474 &resp, sizeof resp)) {
533 ret = -EFAULT; 475 ret = -EFAULT;
534 goto err_list; 476 goto err_idr;
535 } 477 }
536 478
479 down(&file->mutex);
480 list_add_tail(&obj->uobject.list, &file->ucontext->mr_list);
481 up(&file->mutex);
482
537 up(&ib_uverbs_idr_mutex); 483 up(&ib_uverbs_idr_mutex);
538 484
539 return in_len; 485 return in_len;
540 486
541err_list: 487err_idr:
542 down(&file->mutex); 488 idr_remove(&ib_uverbs_mr_idr, obj->uobject.id);
543 list_del(&obj->uobject.list);
544 up(&file->mutex);
545 489
546err_unreg: 490err_unreg:
547 ib_dereg_mr(mr); 491 ib_dereg_mr(mr);
@@ -595,6 +539,35 @@ out:
595 return ret ? ret : in_len; 539 return ret ? ret : in_len;
596} 540}
597 541
542ssize_t ib_uverbs_create_comp_channel(struct ib_uverbs_file *file,
543 const char __user *buf, int in_len,
544 int out_len)
545{
546 struct ib_uverbs_create_comp_channel cmd;
547 struct ib_uverbs_create_comp_channel_resp resp;
548 struct file *filp;
549
550 if (out_len < sizeof resp)
551 return -ENOSPC;
552
553 if (copy_from_user(&cmd, buf, sizeof cmd))
554 return -EFAULT;
555
556 filp = ib_uverbs_alloc_event_file(file, 0, &resp.fd);
557 if (IS_ERR(filp))
558 return PTR_ERR(filp);
559
560 if (copy_to_user((void __user *) (unsigned long) cmd.response,
561 &resp, sizeof resp)) {
562 put_unused_fd(resp.fd);
563 fput(filp);
564 return -EFAULT;
565 }
566
567 fd_install(resp.fd, filp);
568 return in_len;
569}
570
598ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file, 571ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file,
599 const char __user *buf, int in_len, 572 const char __user *buf, int in_len,
600 int out_len) 573 int out_len)
@@ -603,6 +576,7 @@ ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file,
603 struct ib_uverbs_create_cq_resp resp; 576 struct ib_uverbs_create_cq_resp resp;
604 struct ib_udata udata; 577 struct ib_udata udata;
605 struct ib_ucq_object *uobj; 578 struct ib_ucq_object *uobj;
579 struct ib_uverbs_event_file *ev_file = NULL;
606 struct ib_cq *cq; 580 struct ib_cq *cq;
607 int ret; 581 int ret;
608 582
@@ -616,9 +590,12 @@ ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file,
616 (unsigned long) cmd.response + sizeof resp, 590 (unsigned long) cmd.response + sizeof resp,
617 in_len - sizeof cmd, out_len - sizeof resp); 591 in_len - sizeof cmd, out_len - sizeof resp);
618 592
619 if (cmd.event_handler >= file->device->num_comp) 593 if (cmd.comp_vector >= file->device->num_comp_vectors)
620 return -EINVAL; 594 return -EINVAL;
621 595
596 if (cmd.comp_channel >= 0)
597 ev_file = ib_uverbs_lookup_comp_file(cmd.comp_channel);
598
622 uobj = kmalloc(sizeof *uobj, GFP_KERNEL); 599 uobj = kmalloc(sizeof *uobj, GFP_KERNEL);
623 if (!uobj) 600 if (!uobj)
624 return -ENOMEM; 601 return -ENOMEM;
@@ -641,27 +618,23 @@ ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file,
641 cq->uobject = &uobj->uobject; 618 cq->uobject = &uobj->uobject;
642 cq->comp_handler = ib_uverbs_comp_handler; 619 cq->comp_handler = ib_uverbs_comp_handler;
643 cq->event_handler = ib_uverbs_cq_event_handler; 620 cq->event_handler = ib_uverbs_cq_event_handler;
644 cq->cq_context = file; 621 cq->cq_context = ev_file;
645 atomic_set(&cq->usecnt, 0); 622 atomic_set(&cq->usecnt, 0);
646 623
624 down(&ib_uverbs_idr_mutex);
625
647retry: 626retry:
648 if (!idr_pre_get(&ib_uverbs_cq_idr, GFP_KERNEL)) { 627 if (!idr_pre_get(&ib_uverbs_cq_idr, GFP_KERNEL)) {
649 ret = -ENOMEM; 628 ret = -ENOMEM;
650 goto err_cq; 629 goto err_up;
651 } 630 }
652 631
653 down(&ib_uverbs_idr_mutex);
654 ret = idr_get_new(&ib_uverbs_cq_idr, cq, &uobj->uobject.id); 632 ret = idr_get_new(&ib_uverbs_cq_idr, cq, &uobj->uobject.id);
655 up(&ib_uverbs_idr_mutex);
656 633
657 if (ret == -EAGAIN) 634 if (ret == -EAGAIN)
658 goto retry; 635 goto retry;
659 if (ret) 636 if (ret)
660 goto err_cq; 637 goto err_up;
661
662 down(&file->mutex);
663 list_add_tail(&uobj->uobject.list, &file->ucontext->cq_list);
664 up(&file->mutex);
665 638
666 memset(&resp, 0, sizeof resp); 639 memset(&resp, 0, sizeof resp);
667 resp.cq_handle = uobj->uobject.id; 640 resp.cq_handle = uobj->uobject.id;
@@ -670,21 +643,22 @@ retry:
670 if (copy_to_user((void __user *) (unsigned long) cmd.response, 643 if (copy_to_user((void __user *) (unsigned long) cmd.response,
671 &resp, sizeof resp)) { 644 &resp, sizeof resp)) {
672 ret = -EFAULT; 645 ret = -EFAULT;
673 goto err_list; 646 goto err_idr;
674 } 647 }
675 648
676 return in_len; 649 down(&file->mutex);
677 650 list_add_tail(&uobj->uobject.list, &file->ucontext->cq_list);
678err_list:
679 down(&file->mutex);
680 list_del(&uobj->uobject.list);
681 up(&file->mutex); 651 up(&file->mutex);
682 652
683 down(&ib_uverbs_idr_mutex);
684 idr_remove(&ib_uverbs_cq_idr, uobj->uobject.id);
685 up(&ib_uverbs_idr_mutex); 653 up(&ib_uverbs_idr_mutex);
686 654
687err_cq: 655 return in_len;
656
657err_idr:
658 idr_remove(&ib_uverbs_cq_idr, uobj->uobject.id);
659
660err_up:
661 up(&ib_uverbs_idr_mutex);
688 ib_destroy_cq(cq); 662 ib_destroy_cq(cq);
689 663
690err: 664err:
@@ -692,6 +666,93 @@ err:
692 return ret; 666 return ret;
693} 667}
694 668
669ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file,
670 const char __user *buf, int in_len,
671 int out_len)
672{
673 struct ib_uverbs_poll_cq cmd;
674 struct ib_uverbs_poll_cq_resp *resp;
675 struct ib_cq *cq;
676 struct ib_wc *wc;
677 int ret = 0;
678 int i;
679 int rsize;
680
681 if (copy_from_user(&cmd, buf, sizeof cmd))
682 return -EFAULT;
683
684 wc = kmalloc(cmd.ne * sizeof *wc, GFP_KERNEL);
685 if (!wc)
686 return -ENOMEM;
687
688 rsize = sizeof *resp + cmd.ne * sizeof(struct ib_uverbs_wc);
689 resp = kmalloc(rsize, GFP_KERNEL);
690 if (!resp) {
691 ret = -ENOMEM;
692 goto out_wc;
693 }
694
695 down(&ib_uverbs_idr_mutex);
696 cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle);
697 if (!cq || cq->uobject->context != file->ucontext) {
698 ret = -EINVAL;
699 goto out;
700 }
701
702 resp->count = ib_poll_cq(cq, cmd.ne, wc);
703
704 for (i = 0; i < resp->count; i++) {
705 resp->wc[i].wr_id = wc[i].wr_id;
706 resp->wc[i].status = wc[i].status;
707 resp->wc[i].opcode = wc[i].opcode;
708 resp->wc[i].vendor_err = wc[i].vendor_err;
709 resp->wc[i].byte_len = wc[i].byte_len;
710 resp->wc[i].imm_data = wc[i].imm_data;
711 resp->wc[i].qp_num = wc[i].qp_num;
712 resp->wc[i].src_qp = wc[i].src_qp;
713 resp->wc[i].wc_flags = wc[i].wc_flags;
714 resp->wc[i].pkey_index = wc[i].pkey_index;
715 resp->wc[i].slid = wc[i].slid;
716 resp->wc[i].sl = wc[i].sl;
717 resp->wc[i].dlid_path_bits = wc[i].dlid_path_bits;
718 resp->wc[i].port_num = wc[i].port_num;
719 }
720
721 if (copy_to_user((void __user *) (unsigned long) cmd.response, resp, rsize))
722 ret = -EFAULT;
723
724out:
725 up(&ib_uverbs_idr_mutex);
726 kfree(resp);
727
728out_wc:
729 kfree(wc);
730 return ret ? ret : in_len;
731}
732
733ssize_t ib_uverbs_req_notify_cq(struct ib_uverbs_file *file,
734 const char __user *buf, int in_len,
735 int out_len)
736{
737 struct ib_uverbs_req_notify_cq cmd;
738 struct ib_cq *cq;
739 int ret = -EINVAL;
740
741 if (copy_from_user(&cmd, buf, sizeof cmd))
742 return -EFAULT;
743
744 down(&ib_uverbs_idr_mutex);
745 cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle);
746 if (cq && cq->uobject->context == file->ucontext) {
747 ib_req_notify_cq(cq, cmd.solicited_only ?
748 IB_CQ_SOLICITED : IB_CQ_NEXT_COMP);
749 ret = in_len;
750 }
751 up(&ib_uverbs_idr_mutex);
752
753 return ret;
754}
755
695ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file, 756ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file,
696 const char __user *buf, int in_len, 757 const char __user *buf, int in_len,
697 int out_len) 758 int out_len)
@@ -700,7 +761,7 @@ ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file,
700 struct ib_uverbs_destroy_cq_resp resp; 761 struct ib_uverbs_destroy_cq_resp resp;
701 struct ib_cq *cq; 762 struct ib_cq *cq;
702 struct ib_ucq_object *uobj; 763 struct ib_ucq_object *uobj;
703 struct ib_uverbs_event *evt, *tmp; 764 struct ib_uverbs_event_file *ev_file;
704 u64 user_handle; 765 u64 user_handle;
705 int ret = -EINVAL; 766 int ret = -EINVAL;
706 767
@@ -716,7 +777,8 @@ ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file,
716 goto out; 777 goto out;
717 778
718 user_handle = cq->uobject->user_handle; 779 user_handle = cq->uobject->user_handle;
719 uobj = container_of(cq->uobject, struct ib_ucq_object, uobject); 780 uobj = container_of(cq->uobject, struct ib_ucq_object, uobject);
781 ev_file = cq->cq_context;
720 782
721 ret = ib_destroy_cq(cq); 783 ret = ib_destroy_cq(cq);
722 if (ret) 784 if (ret)
@@ -728,19 +790,7 @@ ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file,
728 list_del(&uobj->uobject.list); 790 list_del(&uobj->uobject.list);
729 up(&file->mutex); 791 up(&file->mutex);
730 792
731 spin_lock_irq(&file->comp_file[0].lock); 793 ib_uverbs_release_ucq(file, ev_file, uobj);
732 list_for_each_entry_safe(evt, tmp, &uobj->comp_list, obj_list) {
733 list_del(&evt->list);
734 kfree(evt);
735 }
736 spin_unlock_irq(&file->comp_file[0].lock);
737
738 spin_lock_irq(&file->async_file.lock);
739 list_for_each_entry_safe(evt, tmp, &uobj->async_list, obj_list) {
740 list_del(&evt->list);
741 kfree(evt);
742 }
743 spin_unlock_irq(&file->async_file.lock);
744 794
745 resp.comp_events_reported = uobj->comp_events_reported; 795 resp.comp_events_reported = uobj->comp_events_reported;
746 resp.async_events_reported = uobj->async_events_reported; 796 resp.async_events_reported = uobj->async_events_reported;
@@ -859,24 +909,22 @@ retry:
859 909
860 resp.qp_handle = uobj->uobject.id; 910 resp.qp_handle = uobj->uobject.id;
861 911
862 down(&file->mutex);
863 list_add_tail(&uobj->uobject.list, &file->ucontext->qp_list);
864 up(&file->mutex);
865
866 if (copy_to_user((void __user *) (unsigned long) cmd.response, 912 if (copy_to_user((void __user *) (unsigned long) cmd.response,
867 &resp, sizeof resp)) { 913 &resp, sizeof resp)) {
868 ret = -EFAULT; 914 ret = -EFAULT;
869 goto err_list; 915 goto err_idr;
870 } 916 }
871 917
918 down(&file->mutex);
919 list_add_tail(&uobj->uobject.list, &file->ucontext->qp_list);
920 up(&file->mutex);
921
872 up(&ib_uverbs_idr_mutex); 922 up(&ib_uverbs_idr_mutex);
873 923
874 return in_len; 924 return in_len;
875 925
876err_list: 926err_idr:
877 down(&file->mutex); 927 idr_remove(&ib_uverbs_qp_idr, uobj->uobject.id);
878 list_del(&uobj->uobject.list);
879 up(&file->mutex);
880 928
881err_destroy: 929err_destroy:
882 ib_destroy_qp(qp); 930 ib_destroy_qp(qp);
@@ -979,7 +1027,6 @@ ssize_t ib_uverbs_destroy_qp(struct ib_uverbs_file *file,
979 struct ib_uverbs_destroy_qp_resp resp; 1027 struct ib_uverbs_destroy_qp_resp resp;
980 struct ib_qp *qp; 1028 struct ib_qp *qp;
981 struct ib_uevent_object *uobj; 1029 struct ib_uevent_object *uobj;
982 struct ib_uverbs_event *evt, *tmp;
983 int ret = -EINVAL; 1030 int ret = -EINVAL;
984 1031
985 if (copy_from_user(&cmd, buf, sizeof cmd)) 1032 if (copy_from_user(&cmd, buf, sizeof cmd))
@@ -1005,12 +1052,7 @@ ssize_t ib_uverbs_destroy_qp(struct ib_uverbs_file *file,
1005 list_del(&uobj->uobject.list); 1052 list_del(&uobj->uobject.list);
1006 up(&file->mutex); 1053 up(&file->mutex);
1007 1054
1008 spin_lock_irq(&file->async_file.lock); 1055 ib_uverbs_release_uevent(file, uobj);
1009 list_for_each_entry_safe(evt, tmp, &uobj->event_list, obj_list) {
1010 list_del(&evt->list);
1011 kfree(evt);
1012 }
1013 spin_unlock_irq(&file->async_file.lock);
1014 1056
1015 resp.events_reported = uobj->events_reported; 1057 resp.events_reported = uobj->events_reported;
1016 1058
@@ -1026,6 +1068,468 @@ out:
1026 return ret ? ret : in_len; 1068 return ret ? ret : in_len;
1027} 1069}
1028 1070
1071ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file,
1072 const char __user *buf, int in_len,
1073 int out_len)
1074{
1075 struct ib_uverbs_post_send cmd;
1076 struct ib_uverbs_post_send_resp resp;
1077 struct ib_uverbs_send_wr *user_wr;
1078 struct ib_send_wr *wr = NULL, *last, *next, *bad_wr;
1079 struct ib_qp *qp;
1080 int i, sg_ind;
1081 ssize_t ret = -EINVAL;
1082
1083 if (copy_from_user(&cmd, buf, sizeof cmd))
1084 return -EFAULT;
1085
1086 if (in_len < sizeof cmd + cmd.wqe_size * cmd.wr_count +
1087 cmd.sge_count * sizeof (struct ib_uverbs_sge))
1088 return -EINVAL;
1089
1090 if (cmd.wqe_size < sizeof (struct ib_uverbs_send_wr))
1091 return -EINVAL;
1092
1093 user_wr = kmalloc(cmd.wqe_size, GFP_KERNEL);
1094 if (!user_wr)
1095 return -ENOMEM;
1096
1097 down(&ib_uverbs_idr_mutex);
1098
1099 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
1100 if (!qp || qp->uobject->context != file->ucontext)
1101 goto out;
1102
1103 sg_ind = 0;
1104 last = NULL;
1105 for (i = 0; i < cmd.wr_count; ++i) {
1106 if (copy_from_user(user_wr,
1107 buf + sizeof cmd + i * cmd.wqe_size,
1108 cmd.wqe_size)) {
1109 ret = -EFAULT;
1110 goto out;
1111 }
1112
1113 if (user_wr->num_sge + sg_ind > cmd.sge_count) {
1114 ret = -EINVAL;
1115 goto out;
1116 }
1117
1118 next = kmalloc(ALIGN(sizeof *next, sizeof (struct ib_sge)) +
1119 user_wr->num_sge * sizeof (struct ib_sge),
1120 GFP_KERNEL);
1121 if (!next) {
1122 ret = -ENOMEM;
1123 goto out;
1124 }
1125
1126 if (!last)
1127 wr = next;
1128 else
1129 last->next = next;
1130 last = next;
1131
1132 next->next = NULL;
1133 next->wr_id = user_wr->wr_id;
1134 next->num_sge = user_wr->num_sge;
1135 next->opcode = user_wr->opcode;
1136 next->send_flags = user_wr->send_flags;
1137 next->imm_data = user_wr->imm_data;
1138
1139 if (qp->qp_type == IB_QPT_UD) {
1140 next->wr.ud.ah = idr_find(&ib_uverbs_ah_idr,
1141 user_wr->wr.ud.ah);
1142 if (!next->wr.ud.ah) {
1143 ret = -EINVAL;
1144 goto out;
1145 }
1146 next->wr.ud.remote_qpn = user_wr->wr.ud.remote_qpn;
1147 next->wr.ud.remote_qkey = user_wr->wr.ud.remote_qkey;
1148 } else {
1149 switch (next->opcode) {
1150 case IB_WR_RDMA_WRITE:
1151 case IB_WR_RDMA_WRITE_WITH_IMM:
1152 case IB_WR_RDMA_READ:
1153 next->wr.rdma.remote_addr =
1154 user_wr->wr.rdma.remote_addr;
1155 next->wr.rdma.rkey =
1156 user_wr->wr.rdma.rkey;
1157 break;
1158 case IB_WR_ATOMIC_CMP_AND_SWP:
1159 case IB_WR_ATOMIC_FETCH_AND_ADD:
1160 next->wr.atomic.remote_addr =
1161 user_wr->wr.atomic.remote_addr;
1162 next->wr.atomic.compare_add =
1163 user_wr->wr.atomic.compare_add;
1164 next->wr.atomic.swap = user_wr->wr.atomic.swap;
1165 next->wr.atomic.rkey = user_wr->wr.atomic.rkey;
1166 break;
1167 default:
1168 break;
1169 }
1170 }
1171
1172 if (next->num_sge) {
1173 next->sg_list = (void *) next +
1174 ALIGN(sizeof *next, sizeof (struct ib_sge));
1175 if (copy_from_user(next->sg_list,
1176 buf + sizeof cmd +
1177 cmd.wr_count * cmd.wqe_size +
1178 sg_ind * sizeof (struct ib_sge),
1179 next->num_sge * sizeof (struct ib_sge))) {
1180 ret = -EFAULT;
1181 goto out;
1182 }
1183 sg_ind += next->num_sge;
1184 } else
1185 next->sg_list = NULL;
1186 }
1187
1188 resp.bad_wr = 0;
1189 ret = qp->device->post_send(qp, wr, &bad_wr);
1190 if (ret)
1191 for (next = wr; next; next = next->next) {
1192 ++resp.bad_wr;
1193 if (next == bad_wr)
1194 break;
1195 }
1196
1197 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1198 &resp, sizeof resp))
1199 ret = -EFAULT;
1200
1201out:
1202 up(&ib_uverbs_idr_mutex);
1203
1204 while (wr) {
1205 next = wr->next;
1206 kfree(wr);
1207 wr = next;
1208 }
1209
1210 kfree(user_wr);
1211
1212 return ret ? ret : in_len;
1213}
1214
1215static struct ib_recv_wr *ib_uverbs_unmarshall_recv(const char __user *buf,
1216 int in_len,
1217 u32 wr_count,
1218 u32 sge_count,
1219 u32 wqe_size)
1220{
1221 struct ib_uverbs_recv_wr *user_wr;
1222 struct ib_recv_wr *wr = NULL, *last, *next;
1223 int sg_ind;
1224 int i;
1225 int ret;
1226
1227 if (in_len < wqe_size * wr_count +
1228 sge_count * sizeof (struct ib_uverbs_sge))
1229 return ERR_PTR(-EINVAL);
1230
1231 if (wqe_size < sizeof (struct ib_uverbs_recv_wr))
1232 return ERR_PTR(-EINVAL);
1233
1234 user_wr = kmalloc(wqe_size, GFP_KERNEL);
1235 if (!user_wr)
1236 return ERR_PTR(-ENOMEM);
1237
1238 sg_ind = 0;
1239 last = NULL;
1240 for (i = 0; i < wr_count; ++i) {
1241 if (copy_from_user(user_wr, buf + i * wqe_size,
1242 wqe_size)) {
1243 ret = -EFAULT;
1244 goto err;
1245 }
1246
1247 if (user_wr->num_sge + sg_ind > sge_count) {
1248 ret = -EINVAL;
1249 goto err;
1250 }
1251
1252 next = kmalloc(ALIGN(sizeof *next, sizeof (struct ib_sge)) +
1253 user_wr->num_sge * sizeof (struct ib_sge),
1254 GFP_KERNEL);
1255 if (!next) {
1256 ret = -ENOMEM;
1257 goto err;
1258 }
1259
1260 if (!last)
1261 wr = next;
1262 else
1263 last->next = next;
1264 last = next;
1265
1266 next->next = NULL;
1267 next->wr_id = user_wr->wr_id;
1268 next->num_sge = user_wr->num_sge;
1269
1270 if (next->num_sge) {
1271 next->sg_list = (void *) next +
1272 ALIGN(sizeof *next, sizeof (struct ib_sge));
1273 if (copy_from_user(next->sg_list,
1274 buf + wr_count * wqe_size +
1275 sg_ind * sizeof (struct ib_sge),
1276 next->num_sge * sizeof (struct ib_sge))) {
1277 ret = -EFAULT;
1278 goto err;
1279 }
1280 sg_ind += next->num_sge;
1281 } else
1282 next->sg_list = NULL;
1283 }
1284
1285 kfree(user_wr);
1286 return wr;
1287
1288err:
1289 kfree(user_wr);
1290
1291 while (wr) {
1292 next = wr->next;
1293 kfree(wr);
1294 wr = next;
1295 }
1296
1297 return ERR_PTR(ret);
1298}
1299
1300ssize_t ib_uverbs_post_recv(struct ib_uverbs_file *file,
1301 const char __user *buf, int in_len,
1302 int out_len)
1303{
1304 struct ib_uverbs_post_recv cmd;
1305 struct ib_uverbs_post_recv_resp resp;
1306 struct ib_recv_wr *wr, *next, *bad_wr;
1307 struct ib_qp *qp;
1308 ssize_t ret = -EINVAL;
1309
1310 if (copy_from_user(&cmd, buf, sizeof cmd))
1311 return -EFAULT;
1312
1313 wr = ib_uverbs_unmarshall_recv(buf + sizeof cmd,
1314 in_len - sizeof cmd, cmd.wr_count,
1315 cmd.sge_count, cmd.wqe_size);
1316 if (IS_ERR(wr))
1317 return PTR_ERR(wr);
1318
1319 down(&ib_uverbs_idr_mutex);
1320
1321 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
1322 if (!qp || qp->uobject->context != file->ucontext)
1323 goto out;
1324
1325 resp.bad_wr = 0;
1326 ret = qp->device->post_recv(qp, wr, &bad_wr);
1327 if (ret)
1328 for (next = wr; next; next = next->next) {
1329 ++resp.bad_wr;
1330 if (next == bad_wr)
1331 break;
1332 }
1333
1334
1335 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1336 &resp, sizeof resp))
1337 ret = -EFAULT;
1338
1339out:
1340 up(&ib_uverbs_idr_mutex);
1341
1342 while (wr) {
1343 next = wr->next;
1344 kfree(wr);
1345 wr = next;
1346 }
1347
1348 return ret ? ret : in_len;
1349}
1350
1351ssize_t ib_uverbs_post_srq_recv(struct ib_uverbs_file *file,
1352 const char __user *buf, int in_len,
1353 int out_len)
1354{
1355 struct ib_uverbs_post_srq_recv cmd;
1356 struct ib_uverbs_post_srq_recv_resp resp;
1357 struct ib_recv_wr *wr, *next, *bad_wr;
1358 struct ib_srq *srq;
1359 ssize_t ret = -EINVAL;
1360
1361 if (copy_from_user(&cmd, buf, sizeof cmd))
1362 return -EFAULT;
1363
1364 wr = ib_uverbs_unmarshall_recv(buf + sizeof cmd,
1365 in_len - sizeof cmd, cmd.wr_count,
1366 cmd.sge_count, cmd.wqe_size);
1367 if (IS_ERR(wr))
1368 return PTR_ERR(wr);
1369
1370 down(&ib_uverbs_idr_mutex);
1371
1372 srq = idr_find(&ib_uverbs_srq_idr, cmd.srq_handle);
1373 if (!srq || srq->uobject->context != file->ucontext)
1374 goto out;
1375
1376 resp.bad_wr = 0;
1377 ret = srq->device->post_srq_recv(srq, wr, &bad_wr);
1378 if (ret)
1379 for (next = wr; next; next = next->next) {
1380 ++resp.bad_wr;
1381 if (next == bad_wr)
1382 break;
1383 }
1384
1385
1386 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1387 &resp, sizeof resp))
1388 ret = -EFAULT;
1389
1390out:
1391 up(&ib_uverbs_idr_mutex);
1392
1393 while (wr) {
1394 next = wr->next;
1395 kfree(wr);
1396 wr = next;
1397 }
1398
1399 return ret ? ret : in_len;
1400}
1401
1402ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file,
1403 const char __user *buf, int in_len,
1404 int out_len)
1405{
1406 struct ib_uverbs_create_ah cmd;
1407 struct ib_uverbs_create_ah_resp resp;
1408 struct ib_uobject *uobj;
1409 struct ib_pd *pd;
1410 struct ib_ah *ah;
1411 struct ib_ah_attr attr;
1412 int ret;
1413
1414 if (out_len < sizeof resp)
1415 return -ENOSPC;
1416
1417 if (copy_from_user(&cmd, buf, sizeof cmd))
1418 return -EFAULT;
1419
1420 uobj = kmalloc(sizeof *uobj, GFP_KERNEL);
1421 if (!uobj)
1422 return -ENOMEM;
1423
1424 down(&ib_uverbs_idr_mutex);
1425
1426 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle);
1427 if (!pd || pd->uobject->context != file->ucontext) {
1428 ret = -EINVAL;
1429 goto err_up;
1430 }
1431
1432 uobj->user_handle = cmd.user_handle;
1433 uobj->context = file->ucontext;
1434
1435 attr.dlid = cmd.attr.dlid;
1436 attr.sl = cmd.attr.sl;
1437 attr.src_path_bits = cmd.attr.src_path_bits;
1438 attr.static_rate = cmd.attr.static_rate;
1439 attr.port_num = cmd.attr.port_num;
1440 attr.grh.flow_label = cmd.attr.grh.flow_label;
1441 attr.grh.sgid_index = cmd.attr.grh.sgid_index;
1442 attr.grh.hop_limit = cmd.attr.grh.hop_limit;
1443 attr.grh.traffic_class = cmd.attr.grh.traffic_class;
1444 memcpy(attr.grh.dgid.raw, cmd.attr.grh.dgid, 16);
1445
1446 ah = ib_create_ah(pd, &attr);
1447 if (IS_ERR(ah)) {
1448 ret = PTR_ERR(ah);
1449 goto err_up;
1450 }
1451
1452 ah->uobject = uobj;
1453
1454retry:
1455 if (!idr_pre_get(&ib_uverbs_ah_idr, GFP_KERNEL)) {
1456 ret = -ENOMEM;
1457 goto err_destroy;
1458 }
1459
1460 ret = idr_get_new(&ib_uverbs_ah_idr, ah, &uobj->id);
1461
1462 if (ret == -EAGAIN)
1463 goto retry;
1464 if (ret)
1465 goto err_destroy;
1466
1467 resp.ah_handle = uobj->id;
1468
1469 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1470 &resp, sizeof resp)) {
1471 ret = -EFAULT;
1472 goto err_idr;
1473 }
1474
1475 down(&file->mutex);
1476 list_add_tail(&uobj->list, &file->ucontext->ah_list);
1477 up(&file->mutex);
1478
1479 up(&ib_uverbs_idr_mutex);
1480
1481 return in_len;
1482
1483err_idr:
1484 idr_remove(&ib_uverbs_ah_idr, uobj->id);
1485
1486err_destroy:
1487 ib_destroy_ah(ah);
1488
1489err_up:
1490 up(&ib_uverbs_idr_mutex);
1491
1492 kfree(uobj);
1493 return ret;
1494}
1495
1496ssize_t ib_uverbs_destroy_ah(struct ib_uverbs_file *file,
1497 const char __user *buf, int in_len, int out_len)
1498{
1499 struct ib_uverbs_destroy_ah cmd;
1500 struct ib_ah *ah;
1501 struct ib_uobject *uobj;
1502 int ret = -EINVAL;
1503
1504 if (copy_from_user(&cmd, buf, sizeof cmd))
1505 return -EFAULT;
1506
1507 down(&ib_uverbs_idr_mutex);
1508
1509 ah = idr_find(&ib_uverbs_ah_idr, cmd.ah_handle);
1510 if (!ah || ah->uobject->context != file->ucontext)
1511 goto out;
1512
1513 uobj = ah->uobject;
1514
1515 ret = ib_destroy_ah(ah);
1516 if (ret)
1517 goto out;
1518
1519 idr_remove(&ib_uverbs_ah_idr, cmd.ah_handle);
1520
1521 down(&file->mutex);
1522 list_del(&uobj->list);
1523 up(&file->mutex);
1524
1525 kfree(uobj);
1526
1527out:
1528 up(&ib_uverbs_idr_mutex);
1529
1530 return ret ? ret : in_len;
1531}
1532
1029ssize_t ib_uverbs_attach_mcast(struct ib_uverbs_file *file, 1533ssize_t ib_uverbs_attach_mcast(struct ib_uverbs_file *file,
1030 const char __user *buf, int in_len, 1534 const char __user *buf, int in_len,
1031 int out_len) 1535 int out_len)
@@ -1148,24 +1652,22 @@ retry:
1148 1652
1149 resp.srq_handle = uobj->uobject.id; 1653 resp.srq_handle = uobj->uobject.id;
1150 1654
1151 down(&file->mutex);
1152 list_add_tail(&uobj->uobject.list, &file->ucontext->srq_list);
1153 up(&file->mutex);
1154
1155 if (copy_to_user((void __user *) (unsigned long) cmd.response, 1655 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1156 &resp, sizeof resp)) { 1656 &resp, sizeof resp)) {
1157 ret = -EFAULT; 1657 ret = -EFAULT;
1158 goto err_list; 1658 goto err_idr;
1159 } 1659 }
1160 1660
1661 down(&file->mutex);
1662 list_add_tail(&uobj->uobject.list, &file->ucontext->srq_list);
1663 up(&file->mutex);
1664
1161 up(&ib_uverbs_idr_mutex); 1665 up(&ib_uverbs_idr_mutex);
1162 1666
1163 return in_len; 1667 return in_len;
1164 1668
1165err_list: 1669err_idr:
1166 down(&file->mutex); 1670 idr_remove(&ib_uverbs_srq_idr, uobj->uobject.id);
1167 list_del(&uobj->uobject.list);
1168 up(&file->mutex);
1169 1671
1170err_destroy: 1672err_destroy:
1171 ib_destroy_srq(srq); 1673 ib_destroy_srq(srq);
@@ -1217,7 +1719,6 @@ ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file,
1217 struct ib_uverbs_destroy_srq_resp resp; 1719 struct ib_uverbs_destroy_srq_resp resp;
1218 struct ib_srq *srq; 1720 struct ib_srq *srq;
1219 struct ib_uevent_object *uobj; 1721 struct ib_uevent_object *uobj;
1220 struct ib_uverbs_event *evt, *tmp;
1221 int ret = -EINVAL; 1722 int ret = -EINVAL;
1222 1723
1223 if (copy_from_user(&cmd, buf, sizeof cmd)) 1724 if (copy_from_user(&cmd, buf, sizeof cmd))
@@ -1243,12 +1744,7 @@ ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file,
1243 list_del(&uobj->uobject.list); 1744 list_del(&uobj->uobject.list);
1244 up(&file->mutex); 1745 up(&file->mutex);
1245 1746
1246 spin_lock_irq(&file->async_file.lock); 1747 ib_uverbs_release_uevent(file, uobj);
1247 list_for_each_entry_safe(evt, tmp, &uobj->event_list, obj_list) {
1248 list_del(&evt->list);
1249 kfree(evt);
1250 }
1251 spin_unlock_irq(&file->async_file.lock);
1252 1748
1253 resp.events_reported = uobj->events_reported; 1749 resp.events_reported = uobj->events_reported;
1254 1750
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index 12511808de21..0eb38f479b39 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -3,6 +3,7 @@
3 * Copyright (c) 2005 Cisco Systems. All rights reserved. 3 * Copyright (c) 2005 Cisco Systems. All rights reserved.
4 * Copyright (c) 2005 Mellanox Technologies. All rights reserved. 4 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
5 * Copyright (c) 2005 Voltaire, Inc. All rights reserved. 5 * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
6 * Copyright (c) 2005 PathScale, Inc. All rights reserved.
6 * 7 *
7 * This software is available to you under a choice of one of two 8 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU 9 * licenses. You may choose to be licensed under the terms of the GNU
@@ -43,6 +44,7 @@
43#include <linux/poll.h> 44#include <linux/poll.h>
44#include <linux/file.h> 45#include <linux/file.h>
45#include <linux/mount.h> 46#include <linux/mount.h>
47#include <linux/cdev.h>
46 48
47#include <asm/uaccess.h> 49#include <asm/uaccess.h>
48 50
@@ -62,6 +64,8 @@ enum {
62 64
63#define IB_UVERBS_BASE_DEV MKDEV(IB_UVERBS_MAJOR, IB_UVERBS_BASE_MINOR) 65#define IB_UVERBS_BASE_DEV MKDEV(IB_UVERBS_MAJOR, IB_UVERBS_BASE_MINOR)
64 66
67static struct class *uverbs_class;
68
65DECLARE_MUTEX(ib_uverbs_idr_mutex); 69DECLARE_MUTEX(ib_uverbs_idr_mutex);
66DEFINE_IDR(ib_uverbs_pd_idr); 70DEFINE_IDR(ib_uverbs_pd_idr);
67DEFINE_IDR(ib_uverbs_mr_idr); 71DEFINE_IDR(ib_uverbs_mr_idr);
@@ -72,31 +76,37 @@ DEFINE_IDR(ib_uverbs_qp_idr);
72DEFINE_IDR(ib_uverbs_srq_idr); 76DEFINE_IDR(ib_uverbs_srq_idr);
73 77
74static spinlock_t map_lock; 78static spinlock_t map_lock;
79static struct ib_uverbs_device *dev_table[IB_UVERBS_MAX_DEVICES];
75static DECLARE_BITMAP(dev_map, IB_UVERBS_MAX_DEVICES); 80static DECLARE_BITMAP(dev_map, IB_UVERBS_MAX_DEVICES);
76 81
77static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file, 82static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file,
78 const char __user *buf, int in_len, 83 const char __user *buf, int in_len,
79 int out_len) = { 84 int out_len) = {
80 [IB_USER_VERBS_CMD_QUERY_PARAMS] = ib_uverbs_query_params, 85 [IB_USER_VERBS_CMD_GET_CONTEXT] = ib_uverbs_get_context,
81 [IB_USER_VERBS_CMD_GET_CONTEXT] = ib_uverbs_get_context, 86 [IB_USER_VERBS_CMD_QUERY_DEVICE] = ib_uverbs_query_device,
82 [IB_USER_VERBS_CMD_QUERY_DEVICE] = ib_uverbs_query_device, 87 [IB_USER_VERBS_CMD_QUERY_PORT] = ib_uverbs_query_port,
83 [IB_USER_VERBS_CMD_QUERY_PORT] = ib_uverbs_query_port, 88 [IB_USER_VERBS_CMD_ALLOC_PD] = ib_uverbs_alloc_pd,
84 [IB_USER_VERBS_CMD_QUERY_GID] = ib_uverbs_query_gid, 89 [IB_USER_VERBS_CMD_DEALLOC_PD] = ib_uverbs_dealloc_pd,
85 [IB_USER_VERBS_CMD_QUERY_PKEY] = ib_uverbs_query_pkey, 90 [IB_USER_VERBS_CMD_REG_MR] = ib_uverbs_reg_mr,
86 [IB_USER_VERBS_CMD_ALLOC_PD] = ib_uverbs_alloc_pd, 91 [IB_USER_VERBS_CMD_DEREG_MR] = ib_uverbs_dereg_mr,
87 [IB_USER_VERBS_CMD_DEALLOC_PD] = ib_uverbs_dealloc_pd, 92 [IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL] = ib_uverbs_create_comp_channel,
88 [IB_USER_VERBS_CMD_REG_MR] = ib_uverbs_reg_mr, 93 [IB_USER_VERBS_CMD_CREATE_CQ] = ib_uverbs_create_cq,
89 [IB_USER_VERBS_CMD_DEREG_MR] = ib_uverbs_dereg_mr, 94 [IB_USER_VERBS_CMD_POLL_CQ] = ib_uverbs_poll_cq,
90 [IB_USER_VERBS_CMD_CREATE_CQ] = ib_uverbs_create_cq, 95 [IB_USER_VERBS_CMD_REQ_NOTIFY_CQ] = ib_uverbs_req_notify_cq,
91 [IB_USER_VERBS_CMD_DESTROY_CQ] = ib_uverbs_destroy_cq, 96 [IB_USER_VERBS_CMD_DESTROY_CQ] = ib_uverbs_destroy_cq,
92 [IB_USER_VERBS_CMD_CREATE_QP] = ib_uverbs_create_qp, 97 [IB_USER_VERBS_CMD_CREATE_QP] = ib_uverbs_create_qp,
93 [IB_USER_VERBS_CMD_MODIFY_QP] = ib_uverbs_modify_qp, 98 [IB_USER_VERBS_CMD_MODIFY_QP] = ib_uverbs_modify_qp,
94 [IB_USER_VERBS_CMD_DESTROY_QP] = ib_uverbs_destroy_qp, 99 [IB_USER_VERBS_CMD_DESTROY_QP] = ib_uverbs_destroy_qp,
95 [IB_USER_VERBS_CMD_ATTACH_MCAST] = ib_uverbs_attach_mcast, 100 [IB_USER_VERBS_CMD_POST_SEND] = ib_uverbs_post_send,
96 [IB_USER_VERBS_CMD_DETACH_MCAST] = ib_uverbs_detach_mcast, 101 [IB_USER_VERBS_CMD_POST_RECV] = ib_uverbs_post_recv,
97 [IB_USER_VERBS_CMD_CREATE_SRQ] = ib_uverbs_create_srq, 102 [IB_USER_VERBS_CMD_POST_SRQ_RECV] = ib_uverbs_post_srq_recv,
98 [IB_USER_VERBS_CMD_MODIFY_SRQ] = ib_uverbs_modify_srq, 103 [IB_USER_VERBS_CMD_CREATE_AH] = ib_uverbs_create_ah,
99 [IB_USER_VERBS_CMD_DESTROY_SRQ] = ib_uverbs_destroy_srq, 104 [IB_USER_VERBS_CMD_DESTROY_AH] = ib_uverbs_destroy_ah,
105 [IB_USER_VERBS_CMD_ATTACH_MCAST] = ib_uverbs_attach_mcast,
106 [IB_USER_VERBS_CMD_DETACH_MCAST] = ib_uverbs_detach_mcast,
107 [IB_USER_VERBS_CMD_CREATE_SRQ] = ib_uverbs_create_srq,
108 [IB_USER_VERBS_CMD_MODIFY_SRQ] = ib_uverbs_modify_srq,
109 [IB_USER_VERBS_CMD_DESTROY_SRQ] = ib_uverbs_destroy_srq,
100}; 110};
101 111
102static struct vfsmount *uverbs_event_mnt; 112static struct vfsmount *uverbs_event_mnt;
@@ -104,7 +114,54 @@ static struct vfsmount *uverbs_event_mnt;
104static void ib_uverbs_add_one(struct ib_device *device); 114static void ib_uverbs_add_one(struct ib_device *device);
105static void ib_uverbs_remove_one(struct ib_device *device); 115static void ib_uverbs_remove_one(struct ib_device *device);
106 116
107static int ib_dealloc_ucontext(struct ib_ucontext *context) 117static void ib_uverbs_release_dev(struct kref *ref)
118{
119 struct ib_uverbs_device *dev =
120 container_of(ref, struct ib_uverbs_device, ref);
121
122 kfree(dev);
123}
124
125void ib_uverbs_release_ucq(struct ib_uverbs_file *file,
126 struct ib_uverbs_event_file *ev_file,
127 struct ib_ucq_object *uobj)
128{
129 struct ib_uverbs_event *evt, *tmp;
130
131 if (ev_file) {
132 spin_lock_irq(&ev_file->lock);
133 list_for_each_entry_safe(evt, tmp, &uobj->comp_list, obj_list) {
134 list_del(&evt->list);
135 kfree(evt);
136 }
137 spin_unlock_irq(&ev_file->lock);
138
139 kref_put(&ev_file->ref, ib_uverbs_release_event_file);
140 }
141
142 spin_lock_irq(&file->async_file->lock);
143 list_for_each_entry_safe(evt, tmp, &uobj->async_list, obj_list) {
144 list_del(&evt->list);
145 kfree(evt);
146 }
147 spin_unlock_irq(&file->async_file->lock);
148}
149
150void ib_uverbs_release_uevent(struct ib_uverbs_file *file,
151 struct ib_uevent_object *uobj)
152{
153 struct ib_uverbs_event *evt, *tmp;
154
155 spin_lock_irq(&file->async_file->lock);
156 list_for_each_entry_safe(evt, tmp, &uobj->event_list, obj_list) {
157 list_del(&evt->list);
158 kfree(evt);
159 }
160 spin_unlock_irq(&file->async_file->lock);
161}
162
163static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
164 struct ib_ucontext *context)
108{ 165{
109 struct ib_uobject *uobj, *tmp; 166 struct ib_uobject *uobj, *tmp;
110 167
@@ -113,30 +170,46 @@ static int ib_dealloc_ucontext(struct ib_ucontext *context)
113 170
114 down(&ib_uverbs_idr_mutex); 171 down(&ib_uverbs_idr_mutex);
115 172
116 /* XXX Free AHs */ 173 list_for_each_entry_safe(uobj, tmp, &context->ah_list, list) {
174 struct ib_ah *ah = idr_find(&ib_uverbs_ah_idr, uobj->id);
175 idr_remove(&ib_uverbs_ah_idr, uobj->id);
176 ib_destroy_ah(ah);
177 list_del(&uobj->list);
178 kfree(uobj);
179 }
117 180
118 list_for_each_entry_safe(uobj, tmp, &context->qp_list, list) { 181 list_for_each_entry_safe(uobj, tmp, &context->qp_list, list) {
119 struct ib_qp *qp = idr_find(&ib_uverbs_qp_idr, uobj->id); 182 struct ib_qp *qp = idr_find(&ib_uverbs_qp_idr, uobj->id);
183 struct ib_uevent_object *uevent =
184 container_of(uobj, struct ib_uevent_object, uobject);
120 idr_remove(&ib_uverbs_qp_idr, uobj->id); 185 idr_remove(&ib_uverbs_qp_idr, uobj->id);
121 ib_destroy_qp(qp); 186 ib_destroy_qp(qp);
122 list_del(&uobj->list); 187 list_del(&uobj->list);
123 kfree(container_of(uobj, struct ib_uevent_object, uobject)); 188 ib_uverbs_release_uevent(file, uevent);
189 kfree(uevent);
124 } 190 }
125 191
126 list_for_each_entry_safe(uobj, tmp, &context->cq_list, list) { 192 list_for_each_entry_safe(uobj, tmp, &context->cq_list, list) {
127 struct ib_cq *cq = idr_find(&ib_uverbs_cq_idr, uobj->id); 193 struct ib_cq *cq = idr_find(&ib_uverbs_cq_idr, uobj->id);
194 struct ib_uverbs_event_file *ev_file = cq->cq_context;
195 struct ib_ucq_object *ucq =
196 container_of(uobj, struct ib_ucq_object, uobject);
128 idr_remove(&ib_uverbs_cq_idr, uobj->id); 197 idr_remove(&ib_uverbs_cq_idr, uobj->id);
129 ib_destroy_cq(cq); 198 ib_destroy_cq(cq);
130 list_del(&uobj->list); 199 list_del(&uobj->list);
131 kfree(container_of(uobj, struct ib_ucq_object, uobject)); 200 ib_uverbs_release_ucq(file, ev_file, ucq);
201 kfree(ucq);
132 } 202 }
133 203
134 list_for_each_entry_safe(uobj, tmp, &context->srq_list, list) { 204 list_for_each_entry_safe(uobj, tmp, &context->srq_list, list) {
135 struct ib_srq *srq = idr_find(&ib_uverbs_srq_idr, uobj->id); 205 struct ib_srq *srq = idr_find(&ib_uverbs_srq_idr, uobj->id);
206 struct ib_uevent_object *uevent =
207 container_of(uobj, struct ib_uevent_object, uobject);
136 idr_remove(&ib_uverbs_srq_idr, uobj->id); 208 idr_remove(&ib_uverbs_srq_idr, uobj->id);
137 ib_destroy_srq(srq); 209 ib_destroy_srq(srq);
138 list_del(&uobj->list); 210 list_del(&uobj->list);
139 kfree(container_of(uobj, struct ib_uevent_object, uobject)); 211 ib_uverbs_release_uevent(file, uevent);
212 kfree(uevent);
140 } 213 }
141 214
142 /* XXX Free MWs */ 215 /* XXX Free MWs */
@@ -175,6 +248,8 @@ static void ib_uverbs_release_file(struct kref *ref)
175 container_of(ref, struct ib_uverbs_file, ref); 248 container_of(ref, struct ib_uverbs_file, ref);
176 249
177 module_put(file->device->ib_dev->owner); 250 module_put(file->device->ib_dev->owner);
251 kref_put(&file->device->ref, ib_uverbs_release_dev);
252
178 kfree(file); 253 kfree(file);
179} 254}
180 255
@@ -188,25 +263,19 @@ static ssize_t ib_uverbs_event_read(struct file *filp, char __user *buf,
188 263
189 spin_lock_irq(&file->lock); 264 spin_lock_irq(&file->lock);
190 265
191 while (list_empty(&file->event_list) && file->fd >= 0) { 266 while (list_empty(&file->event_list)) {
192 spin_unlock_irq(&file->lock); 267 spin_unlock_irq(&file->lock);
193 268
194 if (filp->f_flags & O_NONBLOCK) 269 if (filp->f_flags & O_NONBLOCK)
195 return -EAGAIN; 270 return -EAGAIN;
196 271
197 if (wait_event_interruptible(file->poll_wait, 272 if (wait_event_interruptible(file->poll_wait,
198 !list_empty(&file->event_list) || 273 !list_empty(&file->event_list)))
199 file->fd < 0))
200 return -ERESTARTSYS; 274 return -ERESTARTSYS;
201 275
202 spin_lock_irq(&file->lock); 276 spin_lock_irq(&file->lock);
203 } 277 }
204 278
205 if (file->fd < 0) {
206 spin_unlock_irq(&file->lock);
207 return -ENODEV;
208 }
209
210 event = list_entry(file->event_list.next, struct ib_uverbs_event, list); 279 event = list_entry(file->event_list.next, struct ib_uverbs_event, list);
211 280
212 if (file->is_async) 281 if (file->is_async)
@@ -248,26 +317,19 @@ static unsigned int ib_uverbs_event_poll(struct file *filp,
248 poll_wait(filp, &file->poll_wait, wait); 317 poll_wait(filp, &file->poll_wait, wait);
249 318
250 spin_lock_irq(&file->lock); 319 spin_lock_irq(&file->lock);
251 if (file->fd < 0) 320 if (!list_empty(&file->event_list))
252 pollflags = POLLERR;
253 else if (!list_empty(&file->event_list))
254 pollflags = POLLIN | POLLRDNORM; 321 pollflags = POLLIN | POLLRDNORM;
255 spin_unlock_irq(&file->lock); 322 spin_unlock_irq(&file->lock);
256 323
257 return pollflags; 324 return pollflags;
258} 325}
259 326
260static void ib_uverbs_event_release(struct ib_uverbs_event_file *file) 327void ib_uverbs_release_event_file(struct kref *ref)
261{ 328{
262 struct ib_uverbs_event *entry, *tmp; 329 struct ib_uverbs_event_file *file =
330 container_of(ref, struct ib_uverbs_event_file, ref);
263 331
264 spin_lock_irq(&file->lock); 332 kfree(file);
265 if (file->fd != -1) {
266 file->fd = -1;
267 list_for_each_entry_safe(entry, tmp, &file->event_list, list)
268 kfree(entry);
269 }
270 spin_unlock_irq(&file->lock);
271} 333}
272 334
273static int ib_uverbs_event_fasync(int fd, struct file *filp, int on) 335static int ib_uverbs_event_fasync(int fd, struct file *filp, int on)
@@ -280,21 +342,30 @@ static int ib_uverbs_event_fasync(int fd, struct file *filp, int on)
280static int ib_uverbs_event_close(struct inode *inode, struct file *filp) 342static int ib_uverbs_event_close(struct inode *inode, struct file *filp)
281{ 343{
282 struct ib_uverbs_event_file *file = filp->private_data; 344 struct ib_uverbs_event_file *file = filp->private_data;
345 struct ib_uverbs_event *entry, *tmp;
346
347 spin_lock_irq(&file->lock);
348 file->file = NULL;
349 list_for_each_entry_safe(entry, tmp, &file->event_list, list) {
350 if (entry->counter)
351 list_del(&entry->obj_list);
352 kfree(entry);
353 }
354 spin_unlock_irq(&file->lock);
283 355
284 ib_uverbs_event_release(file);
285 ib_uverbs_event_fasync(-1, filp, 0); 356 ib_uverbs_event_fasync(-1, filp, 0);
286 kref_put(&file->uverbs_file->ref, ib_uverbs_release_file); 357
358 if (file->is_async) {
359 ib_unregister_event_handler(&file->uverbs_file->event_handler);
360 kref_put(&file->uverbs_file->ref, ib_uverbs_release_file);
361 }
362 kref_put(&file->ref, ib_uverbs_release_event_file);
287 363
288 return 0; 364 return 0;
289} 365}
290 366
291static struct file_operations uverbs_event_fops = { 367static struct file_operations uverbs_event_fops = {
292 /* 368 .owner = THIS_MODULE,
293 * No .owner field since we artificially create event files,
294 * so there is no increment to the module reference count in
295 * the open path. All event files come from a uverbs command
296 * file, which already takes a module reference, so this is OK.
297 */
298 .read = ib_uverbs_event_read, 369 .read = ib_uverbs_event_read,
299 .poll = ib_uverbs_event_poll, 370 .poll = ib_uverbs_event_poll,
300 .release = ib_uverbs_event_close, 371 .release = ib_uverbs_event_close,
@@ -303,27 +374,37 @@ static struct file_operations uverbs_event_fops = {
303 374
304void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context) 375void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context)
305{ 376{
306 struct ib_uverbs_file *file = cq_context; 377 struct ib_uverbs_event_file *file = cq_context;
307 struct ib_ucq_object *uobj; 378 struct ib_ucq_object *uobj;
308 struct ib_uverbs_event *entry; 379 struct ib_uverbs_event *entry;
309 unsigned long flags; 380 unsigned long flags;
381
382 if (!file)
383 return;
384
385 spin_lock_irqsave(&file->lock, flags);
386 if (!file->file) {
387 spin_unlock_irqrestore(&file->lock, flags);
388 return;
389 }
310 390
311 entry = kmalloc(sizeof *entry, GFP_ATOMIC); 391 entry = kmalloc(sizeof *entry, GFP_ATOMIC);
312 if (!entry) 392 if (!entry) {
393 spin_unlock_irqrestore(&file->lock, flags);
313 return; 394 return;
395 }
314 396
315 uobj = container_of(cq->uobject, struct ib_ucq_object, uobject); 397 uobj = container_of(cq->uobject, struct ib_ucq_object, uobject);
316 398
317 entry->desc.comp.cq_handle = cq->uobject->user_handle; 399 entry->desc.comp.cq_handle = cq->uobject->user_handle;
318 entry->counter = &uobj->comp_events_reported; 400 entry->counter = &uobj->comp_events_reported;
319 401
320 spin_lock_irqsave(&file->comp_file[0].lock, flags); 402 list_add_tail(&entry->list, &file->event_list);
321 list_add_tail(&entry->list, &file->comp_file[0].event_list);
322 list_add_tail(&entry->obj_list, &uobj->comp_list); 403 list_add_tail(&entry->obj_list, &uobj->comp_list);
323 spin_unlock_irqrestore(&file->comp_file[0].lock, flags); 404 spin_unlock_irqrestore(&file->lock, flags);
324 405
325 wake_up_interruptible(&file->comp_file[0].poll_wait); 406 wake_up_interruptible(&file->poll_wait);
326 kill_fasync(&file->comp_file[0].async_queue, SIGIO, POLL_IN); 407 kill_fasync(&file->async_queue, SIGIO, POLL_IN);
327} 408}
328 409
329static void ib_uverbs_async_handler(struct ib_uverbs_file *file, 410static void ib_uverbs_async_handler(struct ib_uverbs_file *file,
@@ -334,32 +415,40 @@ static void ib_uverbs_async_handler(struct ib_uverbs_file *file,
334 struct ib_uverbs_event *entry; 415 struct ib_uverbs_event *entry;
335 unsigned long flags; 416 unsigned long flags;
336 417
418 spin_lock_irqsave(&file->async_file->lock, flags);
419 if (!file->async_file->file) {
420 spin_unlock_irqrestore(&file->async_file->lock, flags);
421 return;
422 }
423
337 entry = kmalloc(sizeof *entry, GFP_ATOMIC); 424 entry = kmalloc(sizeof *entry, GFP_ATOMIC);
338 if (!entry) 425 if (!entry) {
426 spin_unlock_irqrestore(&file->async_file->lock, flags);
339 return; 427 return;
428 }
340 429
341 entry->desc.async.element = element; 430 entry->desc.async.element = element;
342 entry->desc.async.event_type = event; 431 entry->desc.async.event_type = event;
343 entry->counter = counter; 432 entry->counter = counter;
344 433
345 spin_lock_irqsave(&file->async_file.lock, flags); 434 list_add_tail(&entry->list, &file->async_file->event_list);
346 list_add_tail(&entry->list, &file->async_file.event_list);
347 if (obj_list) 435 if (obj_list)
348 list_add_tail(&entry->obj_list, obj_list); 436 list_add_tail(&entry->obj_list, obj_list);
349 spin_unlock_irqrestore(&file->async_file.lock, flags); 437 spin_unlock_irqrestore(&file->async_file->lock, flags);
350 438
351 wake_up_interruptible(&file->async_file.poll_wait); 439 wake_up_interruptible(&file->async_file->poll_wait);
352 kill_fasync(&file->async_file.async_queue, SIGIO, POLL_IN); 440 kill_fasync(&file->async_file->async_queue, SIGIO, POLL_IN);
353} 441}
354 442
355void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr) 443void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr)
356{ 444{
445 struct ib_uverbs_event_file *ev_file = context_ptr;
357 struct ib_ucq_object *uobj; 446 struct ib_ucq_object *uobj;
358 447
359 uobj = container_of(event->element.cq->uobject, 448 uobj = container_of(event->element.cq->uobject,
360 struct ib_ucq_object, uobject); 449 struct ib_ucq_object, uobject);
361 450
362 ib_uverbs_async_handler(context_ptr, uobj->uobject.user_handle, 451 ib_uverbs_async_handler(ev_file->uverbs_file, uobj->uobject.user_handle,
363 event->event, &uobj->async_list, 452 event->event, &uobj->async_list,
364 &uobj->async_events_reported); 453 &uobj->async_events_reported);
365 454
@@ -389,8 +478,8 @@ void ib_uverbs_srq_event_handler(struct ib_event *event, void *context_ptr)
389 &uobj->events_reported); 478 &uobj->events_reported);
390} 479}
391 480
392static void ib_uverbs_event_handler(struct ib_event_handler *handler, 481void ib_uverbs_event_handler(struct ib_event_handler *handler,
393 struct ib_event *event) 482 struct ib_event *event)
394{ 483{
395 struct ib_uverbs_file *file = 484 struct ib_uverbs_file *file =
396 container_of(handler, struct ib_uverbs_file, event_handler); 485 container_of(handler, struct ib_uverbs_file, event_handler);
@@ -399,38 +488,90 @@ static void ib_uverbs_event_handler(struct ib_event_handler *handler,
399 NULL, NULL); 488 NULL, NULL);
400} 489}
401 490
402static int ib_uverbs_event_init(struct ib_uverbs_event_file *file, 491struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file,
403 struct ib_uverbs_file *uverbs_file) 492 int is_async, int *fd)
404{ 493{
494 struct ib_uverbs_event_file *ev_file;
405 struct file *filp; 495 struct file *filp;
496 int ret;
406 497
407 spin_lock_init(&file->lock); 498 ev_file = kmalloc(sizeof *ev_file, GFP_KERNEL);
408 INIT_LIST_HEAD(&file->event_list); 499 if (!ev_file)
409 init_waitqueue_head(&file->poll_wait); 500 return ERR_PTR(-ENOMEM);
410 file->uverbs_file = uverbs_file; 501
411 file->async_queue = NULL; 502 kref_init(&ev_file->ref);
412 503 spin_lock_init(&ev_file->lock);
413 file->fd = get_unused_fd(); 504 INIT_LIST_HEAD(&ev_file->event_list);
414 if (file->fd < 0) 505 init_waitqueue_head(&ev_file->poll_wait);
415 return file->fd; 506 ev_file->uverbs_file = uverbs_file;
507 ev_file->async_queue = NULL;
508 ev_file->is_async = is_async;
509
510 *fd = get_unused_fd();
511 if (*fd < 0) {
512 ret = *fd;
513 goto err;
514 }
416 515
417 filp = get_empty_filp(); 516 filp = get_empty_filp();
418 if (!filp) { 517 if (!filp) {
419 put_unused_fd(file->fd); 518 ret = -ENFILE;
420 return -ENFILE; 519 goto err_fd;
421 } 520 }
422 521
423 filp->f_op = &uverbs_event_fops; 522 ev_file->file = filp;
523
524 /*
525 * fops_get() can't fail here, because we're coming from a
526 * system call on a uverbs file, which will already have a
527 * module reference.
528 */
529 filp->f_op = fops_get(&uverbs_event_fops);
424 filp->f_vfsmnt = mntget(uverbs_event_mnt); 530 filp->f_vfsmnt = mntget(uverbs_event_mnt);
425 filp->f_dentry = dget(uverbs_event_mnt->mnt_root); 531 filp->f_dentry = dget(uverbs_event_mnt->mnt_root);
426 filp->f_mapping = filp->f_dentry->d_inode->i_mapping; 532 filp->f_mapping = filp->f_dentry->d_inode->i_mapping;
427 filp->f_flags = O_RDONLY; 533 filp->f_flags = O_RDONLY;
428 filp->f_mode = FMODE_READ; 534 filp->f_mode = FMODE_READ;
429 filp->private_data = file; 535 filp->private_data = ev_file;
430 536
431 fd_install(file->fd, filp); 537 return filp;
432 538
433 return 0; 539err_fd:
540 put_unused_fd(*fd);
541
542err:
543 kfree(ev_file);
544 return ERR_PTR(ret);
545}
546
547/*
548 * Look up a completion event file by FD. If lookup is successful,
549 * takes a ref to the event file struct that it returns; if
550 * unsuccessful, returns NULL.
551 */
552struct ib_uverbs_event_file *ib_uverbs_lookup_comp_file(int fd)
553{
554 struct ib_uverbs_event_file *ev_file = NULL;
555 struct file *filp;
556
557 filp = fget(fd);
558 if (!filp)
559 return NULL;
560
561 if (filp->f_op != &uverbs_event_fops)
562 goto out;
563
564 ev_file = filp->private_data;
565 if (ev_file->is_async) {
566 ev_file = NULL;
567 goto out;
568 }
569
570 kref_get(&ev_file->ref);
571
572out:
573 fput(filp);
574 return ev_file;
434} 575}
435 576
436static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, 577static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
@@ -450,11 +591,11 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
450 591
451 if (hdr.command < 0 || 592 if (hdr.command < 0 ||
452 hdr.command >= ARRAY_SIZE(uverbs_cmd_table) || 593 hdr.command >= ARRAY_SIZE(uverbs_cmd_table) ||
453 !uverbs_cmd_table[hdr.command]) 594 !uverbs_cmd_table[hdr.command] ||
595 !(file->device->ib_dev->uverbs_cmd_mask & (1ull << hdr.command)))
454 return -EINVAL; 596 return -EINVAL;
455 597
456 if (!file->ucontext && 598 if (!file->ucontext &&
457 hdr.command != IB_USER_VERBS_CMD_QUERY_PARAMS &&
458 hdr.command != IB_USER_VERBS_CMD_GET_CONTEXT) 599 hdr.command != IB_USER_VERBS_CMD_GET_CONTEXT)
459 return -EINVAL; 600 return -EINVAL;
460 601
@@ -474,84 +615,57 @@ static int ib_uverbs_mmap(struct file *filp, struct vm_area_struct *vma)
474 615
475static int ib_uverbs_open(struct inode *inode, struct file *filp) 616static int ib_uverbs_open(struct inode *inode, struct file *filp)
476{ 617{
477 struct ib_uverbs_device *dev = 618 struct ib_uverbs_device *dev;
478 container_of(inode->i_cdev, struct ib_uverbs_device, dev);
479 struct ib_uverbs_file *file; 619 struct ib_uverbs_file *file;
480 int i = 0;
481 int ret; 620 int ret;
482 621
483 if (!try_module_get(dev->ib_dev->owner)) 622 spin_lock(&map_lock);
484 return -ENODEV; 623 dev = dev_table[iminor(inode) - IB_UVERBS_BASE_MINOR];
624 if (dev)
625 kref_get(&dev->ref);
626 spin_unlock(&map_lock);
627
628 if (!dev)
629 return -ENXIO;
630
631 if (!try_module_get(dev->ib_dev->owner)) {
632 ret = -ENODEV;
633 goto err;
634 }
485 635
486 file = kmalloc(sizeof *file + 636 file = kmalloc(sizeof *file, GFP_KERNEL);
487 (dev->num_comp - 1) * sizeof (struct ib_uverbs_event_file),
488 GFP_KERNEL);
489 if (!file) { 637 if (!file) {
490 ret = -ENOMEM; 638 ret = -ENOMEM;
491 goto err; 639 goto err_module;
492 } 640 }
493 641
494 file->device = dev; 642 file->device = dev;
643 file->ucontext = NULL;
644 file->async_file = NULL;
495 kref_init(&file->ref); 645 kref_init(&file->ref);
496 init_MUTEX(&file->mutex); 646 init_MUTEX(&file->mutex);
497 647
498 file->ucontext = NULL;
499
500 kref_get(&file->ref);
501 ret = ib_uverbs_event_init(&file->async_file, file);
502 if (ret)
503 goto err_kref;
504
505 file->async_file.is_async = 1;
506
507 for (i = 0; i < dev->num_comp; ++i) {
508 kref_get(&file->ref);
509 ret = ib_uverbs_event_init(&file->comp_file[i], file);
510 if (ret)
511 goto err_async;
512 file->comp_file[i].is_async = 0;
513 }
514
515
516 filp->private_data = file; 648 filp->private_data = file;
517 649
518 INIT_IB_EVENT_HANDLER(&file->event_handler, dev->ib_dev,
519 ib_uverbs_event_handler);
520 if (ib_register_event_handler(&file->event_handler))
521 goto err_async;
522
523 return 0; 650 return 0;
524 651
525err_async: 652err_module:
526 while (i--) 653 module_put(dev->ib_dev->owner);
527 ib_uverbs_event_release(&file->comp_file[i]);
528
529 ib_uverbs_event_release(&file->async_file);
530
531err_kref:
532 /*
533 * One extra kref_put() because we took a reference before the
534 * event file creation that failed and got us here.
535 */
536 kref_put(&file->ref, ib_uverbs_release_file);
537 kref_put(&file->ref, ib_uverbs_release_file);
538 654
539err: 655err:
540 module_put(dev->ib_dev->owner); 656 kref_put(&dev->ref, ib_uverbs_release_dev);
657
541 return ret; 658 return ret;
542} 659}
543 660
544static int ib_uverbs_close(struct inode *inode, struct file *filp) 661static int ib_uverbs_close(struct inode *inode, struct file *filp)
545{ 662{
546 struct ib_uverbs_file *file = filp->private_data; 663 struct ib_uverbs_file *file = filp->private_data;
547 int i;
548 664
549 ib_unregister_event_handler(&file->event_handler); 665 ib_uverbs_cleanup_ucontext(file, file->ucontext);
550 ib_uverbs_event_release(&file->async_file);
551 ib_dealloc_ucontext(file->ucontext);
552 666
553 for (i = 0; i < file->device->num_comp; ++i) 667 if (file->async_file)
554 ib_uverbs_event_release(&file->comp_file[i]); 668 kref_put(&file->async_file->ref, ib_uverbs_release_event_file);
555 669
556 kref_put(&file->ref, ib_uverbs_release_file); 670 kref_put(&file->ref, ib_uverbs_release_file);
557 671
@@ -581,27 +695,25 @@ static struct ib_client uverbs_client = {
581 695
582static ssize_t show_ibdev(struct class_device *class_dev, char *buf) 696static ssize_t show_ibdev(struct class_device *class_dev, char *buf)
583{ 697{
584 struct ib_uverbs_device *dev = 698 struct ib_uverbs_device *dev = class_get_devdata(class_dev);
585 container_of(class_dev, struct ib_uverbs_device, class_dev); 699
700 if (!dev)
701 return -ENODEV;
586 702
587 return sprintf(buf, "%s\n", dev->ib_dev->name); 703 return sprintf(buf, "%s\n", dev->ib_dev->name);
588} 704}
589static CLASS_DEVICE_ATTR(ibdev, S_IRUGO, show_ibdev, NULL); 705static CLASS_DEVICE_ATTR(ibdev, S_IRUGO, show_ibdev, NULL);
590 706
591static void ib_uverbs_release_class_dev(struct class_device *class_dev) 707static ssize_t show_dev_abi_version(struct class_device *class_dev, char *buf)
592{ 708{
593 struct ib_uverbs_device *dev = 709 struct ib_uverbs_device *dev = class_get_devdata(class_dev);
594 container_of(class_dev, struct ib_uverbs_device, class_dev);
595 710
596 cdev_del(&dev->dev); 711 if (!dev)
597 clear_bit(dev->devnum, dev_map); 712 return -ENODEV;
598 kfree(dev);
599}
600 713
601static struct class uverbs_class = { 714 return sprintf(buf, "%d\n", dev->ib_dev->uverbs_abi_ver);
602 .name = "infiniband_verbs", 715}
603 .release = ib_uverbs_release_class_dev 716static CLASS_DEVICE_ATTR(abi_version, S_IRUGO, show_dev_abi_version, NULL);
604};
605 717
606static ssize_t show_abi_version(struct class *class, char *buf) 718static ssize_t show_abi_version(struct class *class, char *buf)
607{ 719{
@@ -622,6 +734,8 @@ static void ib_uverbs_add_one(struct ib_device *device)
622 734
623 memset(uverbs_dev, 0, sizeof *uverbs_dev); 735 memset(uverbs_dev, 0, sizeof *uverbs_dev);
624 736
737 kref_init(&uverbs_dev->ref);
738
625 spin_lock(&map_lock); 739 spin_lock(&map_lock);
626 uverbs_dev->devnum = find_first_zero_bit(dev_map, IB_UVERBS_MAX_DEVICES); 740 uverbs_dev->devnum = find_first_zero_bit(dev_map, IB_UVERBS_MAX_DEVICES);
627 if (uverbs_dev->devnum >= IB_UVERBS_MAX_DEVICES) { 741 if (uverbs_dev->devnum >= IB_UVERBS_MAX_DEVICES) {
@@ -631,41 +745,49 @@ static void ib_uverbs_add_one(struct ib_device *device)
631 set_bit(uverbs_dev->devnum, dev_map); 745 set_bit(uverbs_dev->devnum, dev_map);
632 spin_unlock(&map_lock); 746 spin_unlock(&map_lock);
633 747
634 uverbs_dev->ib_dev = device; 748 uverbs_dev->ib_dev = device;
635 uverbs_dev->num_comp = 1; 749 uverbs_dev->num_comp_vectors = 1;
636 750
637 if (device->mmap) 751 uverbs_dev->dev = cdev_alloc();
638 cdev_init(&uverbs_dev->dev, &uverbs_mmap_fops); 752 if (!uverbs_dev->dev)
639 else
640 cdev_init(&uverbs_dev->dev, &uverbs_fops);
641 uverbs_dev->dev.owner = THIS_MODULE;
642 kobject_set_name(&uverbs_dev->dev.kobj, "uverbs%d", uverbs_dev->devnum);
643 if (cdev_add(&uverbs_dev->dev, IB_UVERBS_BASE_DEV + uverbs_dev->devnum, 1))
644 goto err; 753 goto err;
754 uverbs_dev->dev->owner = THIS_MODULE;
755 uverbs_dev->dev->ops = device->mmap ? &uverbs_mmap_fops : &uverbs_fops;
756 kobject_set_name(&uverbs_dev->dev->kobj, "uverbs%d", uverbs_dev->devnum);
757 if (cdev_add(uverbs_dev->dev, IB_UVERBS_BASE_DEV + uverbs_dev->devnum, 1))
758 goto err_cdev;
645 759
646 uverbs_dev->class_dev.class = &uverbs_class; 760 uverbs_dev->class_dev = class_device_create(uverbs_class, NULL,
647 uverbs_dev->class_dev.dev = device->dma_device; 761 uverbs_dev->dev->dev,
648 uverbs_dev->class_dev.devt = uverbs_dev->dev.dev; 762 device->dma_device,
649 snprintf(uverbs_dev->class_dev.class_id, BUS_ID_SIZE, "uverbs%d", uverbs_dev->devnum); 763 "uverbs%d", uverbs_dev->devnum);
650 if (class_device_register(&uverbs_dev->class_dev)) 764 if (IS_ERR(uverbs_dev->class_dev))
651 goto err_cdev; 765 goto err_cdev;
652 766
653 if (class_device_create_file(&uverbs_dev->class_dev, &class_device_attr_ibdev)) 767 class_set_devdata(uverbs_dev->class_dev, uverbs_dev);
768
769 if (class_device_create_file(uverbs_dev->class_dev, &class_device_attr_ibdev))
654 goto err_class; 770 goto err_class;
771 if (class_device_create_file(uverbs_dev->class_dev, &class_device_attr_abi_version))
772 goto err_class;
773
774 spin_lock(&map_lock);
775 dev_table[uverbs_dev->devnum] = uverbs_dev;
776 spin_unlock(&map_lock);
655 777
656 ib_set_client_data(device, &uverbs_client, uverbs_dev); 778 ib_set_client_data(device, &uverbs_client, uverbs_dev);
657 779
658 return; 780 return;
659 781
660err_class: 782err_class:
661 class_device_unregister(&uverbs_dev->class_dev); 783 class_device_destroy(uverbs_class, uverbs_dev->dev->dev);
662 784
663err_cdev: 785err_cdev:
664 cdev_del(&uverbs_dev->dev); 786 cdev_del(uverbs_dev->dev);
665 clear_bit(uverbs_dev->devnum, dev_map); 787 clear_bit(uverbs_dev->devnum, dev_map);
666 788
667err: 789err:
668 kfree(uverbs_dev); 790 kref_put(&uverbs_dev->ref, ib_uverbs_release_dev);
669 return; 791 return;
670} 792}
671 793
@@ -676,7 +798,16 @@ static void ib_uverbs_remove_one(struct ib_device *device)
676 if (!uverbs_dev) 798 if (!uverbs_dev)
677 return; 799 return;
678 800
679 class_device_unregister(&uverbs_dev->class_dev); 801 class_set_devdata(uverbs_dev->class_dev, NULL);
802 class_device_destroy(uverbs_class, uverbs_dev->dev->dev);
803 cdev_del(uverbs_dev->dev);
804
805 spin_lock(&map_lock);
806 dev_table[uverbs_dev->devnum] = NULL;
807 spin_unlock(&map_lock);
808
809 clear_bit(uverbs_dev->devnum, dev_map);
810 kref_put(&uverbs_dev->ref, ib_uverbs_release_dev);
680} 811}
681 812
682static struct super_block *uverbs_event_get_sb(struct file_system_type *fs_type, int flags, 813static struct super_block *uverbs_event_get_sb(struct file_system_type *fs_type, int flags,
@@ -706,13 +837,14 @@ static int __init ib_uverbs_init(void)
706 goto out; 837 goto out;
707 } 838 }
708 839
709 ret = class_register(&uverbs_class); 840 uverbs_class = class_create(THIS_MODULE, "infiniband_verbs");
710 if (ret) { 841 if (IS_ERR(uverbs_class)) {
842 ret = PTR_ERR(uverbs_class);
711 printk(KERN_ERR "user_verbs: couldn't create class infiniband_verbs\n"); 843 printk(KERN_ERR "user_verbs: couldn't create class infiniband_verbs\n");
712 goto out_chrdev; 844 goto out_chrdev;
713 } 845 }
714 846
715 ret = class_create_file(&uverbs_class, &class_attr_abi_version); 847 ret = class_create_file(uverbs_class, &class_attr_abi_version);
716 if (ret) { 848 if (ret) {
717 printk(KERN_ERR "user_verbs: couldn't create abi_version attribute\n"); 849 printk(KERN_ERR "user_verbs: couldn't create abi_version attribute\n");
718 goto out_class; 850 goto out_class;
@@ -746,7 +878,7 @@ out_fs:
746 unregister_filesystem(&uverbs_event_fs); 878 unregister_filesystem(&uverbs_event_fs);
747 879
748out_class: 880out_class:
749 class_unregister(&uverbs_class); 881 class_destroy(uverbs_class);
750 882
751out_chrdev: 883out_chrdev:
752 unregister_chrdev_region(IB_UVERBS_BASE_DEV, IB_UVERBS_MAX_DEVICES); 884 unregister_chrdev_region(IB_UVERBS_BASE_DEV, IB_UVERBS_MAX_DEVICES);
@@ -760,8 +892,15 @@ static void __exit ib_uverbs_cleanup(void)
760 ib_unregister_client(&uverbs_client); 892 ib_unregister_client(&uverbs_client);
761 mntput(uverbs_event_mnt); 893 mntput(uverbs_event_mnt);
762 unregister_filesystem(&uverbs_event_fs); 894 unregister_filesystem(&uverbs_event_fs);
763 class_unregister(&uverbs_class); 895 class_destroy(uverbs_class);
764 unregister_chrdev_region(IB_UVERBS_BASE_DEV, IB_UVERBS_MAX_DEVICES); 896 unregister_chrdev_region(IB_UVERBS_BASE_DEV, IB_UVERBS_MAX_DEVICES);
897 idr_destroy(&ib_uverbs_pd_idr);
898 idr_destroy(&ib_uverbs_mr_idr);
899 idr_destroy(&ib_uverbs_mw_idr);
900 idr_destroy(&ib_uverbs_ah_idr);
901 idr_destroy(&ib_uverbs_cq_idr);
902 idr_destroy(&ib_uverbs_qp_idr);
903 idr_destroy(&ib_uverbs_srq_idr);
765} 904}
766 905
767module_init(ib_uverbs_init); 906module_init(ib_uverbs_init);
diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
index 5081d903e561..72d3ef786db5 100644
--- a/drivers/infiniband/core/verbs.c
+++ b/drivers/infiniband/core/verbs.c
@@ -523,16 +523,22 @@ EXPORT_SYMBOL(ib_dealloc_fmr);
523 523
524int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid) 524int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid)
525{ 525{
526 return qp->device->attach_mcast ? 526 if (!qp->device->attach_mcast)
527 qp->device->attach_mcast(qp, gid, lid) : 527 return -ENOSYS;
528 -ENOSYS; 528 if (gid->raw[0] != 0xff || qp->qp_type != IB_QPT_UD)
529 return -EINVAL;
530
531 return qp->device->attach_mcast(qp, gid, lid);
529} 532}
530EXPORT_SYMBOL(ib_attach_mcast); 533EXPORT_SYMBOL(ib_attach_mcast);
531 534
532int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid) 535int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid)
533{ 536{
534 return qp->device->detach_mcast ? 537 if (!qp->device->detach_mcast)
535 qp->device->detach_mcast(qp, gid, lid) : 538 return -ENOSYS;
536 -ENOSYS; 539 if (gid->raw[0] != 0xff || qp->qp_type != IB_QPT_UD)
540 return -EINVAL;
541
542 return qp->device->detach_mcast(qp, gid, lid);
537} 543}
538EXPORT_SYMBOL(ib_detach_mcast); 544EXPORT_SYMBOL(ib_detach_mcast);
diff --git a/drivers/infiniband/hw/mthca/Makefile b/drivers/infiniband/hw/mthca/Makefile
index c44f7bae5424..47ec5a7cba0b 100644
--- a/drivers/infiniband/hw/mthca/Makefile
+++ b/drivers/infiniband/hw/mthca/Makefile
@@ -7,4 +7,5 @@ obj-$(CONFIG_INFINIBAND_MTHCA) += ib_mthca.o
7ib_mthca-y := mthca_main.o mthca_cmd.o mthca_profile.o mthca_reset.o \ 7ib_mthca-y := mthca_main.o mthca_cmd.o mthca_profile.o mthca_reset.o \
8 mthca_allocator.o mthca_eq.o mthca_pd.o mthca_cq.o \ 8 mthca_allocator.o mthca_eq.o mthca_pd.o mthca_cq.o \
9 mthca_mr.o mthca_qp.o mthca_av.o mthca_mcg.o mthca_mad.o \ 9 mthca_mr.o mthca_qp.o mthca_av.o mthca_mcg.o mthca_mad.o \
10 mthca_provider.o mthca_memfree.o mthca_uar.o mthca_srq.o 10 mthca_provider.o mthca_memfree.o mthca_uar.o mthca_srq.o \
11 mthca_catas.o
diff --git a/drivers/infiniband/hw/mthca/mthca_av.c b/drivers/infiniband/hw/mthca/mthca_av.c
index 889e85096736..22fdc446f25c 100644
--- a/drivers/infiniband/hw/mthca/mthca_av.c
+++ b/drivers/infiniband/hw/mthca/mthca_av.c
@@ -34,6 +34,8 @@
34 */ 34 */
35 35
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/string.h>
38#include <linux/slab.h>
37 39
38#include <rdma/ib_verbs.h> 40#include <rdma/ib_verbs.h>
39#include <rdma/ib_cache.h> 41#include <rdma/ib_cache.h>
diff --git a/drivers/infiniband/hw/mthca/mthca_catas.c b/drivers/infiniband/hw/mthca/mthca_catas.c
new file mode 100644
index 000000000000..7ac52af43b99
--- /dev/null
+++ b/drivers/infiniband/hw/mthca/mthca_catas.c
@@ -0,0 +1,153 @@
1/*
2 * Copyright (c) 2005 Cisco Systems. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 *
32 * $Id$
33 */
34
35#include "mthca_dev.h"
36
37enum {
38 MTHCA_CATAS_POLL_INTERVAL = 5 * HZ,
39
40 MTHCA_CATAS_TYPE_INTERNAL = 0,
41 MTHCA_CATAS_TYPE_UPLINK = 3,
42 MTHCA_CATAS_TYPE_DDR = 4,
43 MTHCA_CATAS_TYPE_PARITY = 5,
44};
45
46static DEFINE_SPINLOCK(catas_lock);
47
48static void handle_catas(struct mthca_dev *dev)
49{
50 struct ib_event event;
51 const char *type;
52 int i;
53
54 event.device = &dev->ib_dev;
55 event.event = IB_EVENT_DEVICE_FATAL;
56 event.element.port_num = 0;
57
58 ib_dispatch_event(&event);
59
60 switch (swab32(readl(dev->catas_err.map)) >> 24) {
61 case MTHCA_CATAS_TYPE_INTERNAL:
62 type = "internal error";
63 break;
64 case MTHCA_CATAS_TYPE_UPLINK:
65 type = "uplink bus error";
66 break;
67 case MTHCA_CATAS_TYPE_DDR:
68 type = "DDR data error";
69 break;
70 case MTHCA_CATAS_TYPE_PARITY:
71 type = "internal parity error";
72 break;
73 default:
74 type = "unknown error";
75 break;
76 }
77
78 mthca_err(dev, "Catastrophic error detected: %s\n", type);
79 for (i = 0; i < dev->catas_err.size; ++i)
80 mthca_err(dev, " buf[%02x]: %08x\n",
81 i, swab32(readl(dev->catas_err.map + i)));
82}
83
84static void poll_catas(unsigned long dev_ptr)
85{
86 struct mthca_dev *dev = (struct mthca_dev *) dev_ptr;
87 unsigned long flags;
88 int i;
89
90 for (i = 0; i < dev->catas_err.size; ++i)
91 if (readl(dev->catas_err.map + i)) {
92 handle_catas(dev);
93 return;
94 }
95
96 spin_lock_irqsave(&catas_lock, flags);
97 if (dev->catas_err.stop)
98 mod_timer(&dev->catas_err.timer,
99 jiffies + MTHCA_CATAS_POLL_INTERVAL);
100 spin_unlock_irqrestore(&catas_lock, flags);
101
102 return;
103}
104
105void mthca_start_catas_poll(struct mthca_dev *dev)
106{
107 unsigned long addr;
108
109 init_timer(&dev->catas_err.timer);
110 dev->catas_err.stop = 0;
111 dev->catas_err.map = NULL;
112
113 addr = pci_resource_start(dev->pdev, 0) +
114 ((pci_resource_len(dev->pdev, 0) - 1) &
115 dev->catas_err.addr);
116
117 if (!request_mem_region(addr, dev->catas_err.size * 4,
118 DRV_NAME)) {
119 mthca_warn(dev, "couldn't request catastrophic error region "
120 "at 0x%lx/0x%x\n", addr, dev->catas_err.size * 4);
121 return;
122 }
123
124 dev->catas_err.map = ioremap(addr, dev->catas_err.size * 4);
125 if (!dev->catas_err.map) {
126 mthca_warn(dev, "couldn't map catastrophic error region "
127 "at 0x%lx/0x%x\n", addr, dev->catas_err.size * 4);
128 release_mem_region(addr, dev->catas_err.size * 4);
129 return;
130 }
131
132 dev->catas_err.timer.data = (unsigned long) dev;
133 dev->catas_err.timer.function = poll_catas;
134 dev->catas_err.timer.expires = jiffies + MTHCA_CATAS_POLL_INTERVAL;
135 add_timer(&dev->catas_err.timer);
136}
137
138void mthca_stop_catas_poll(struct mthca_dev *dev)
139{
140 spin_lock_irq(&catas_lock);
141 dev->catas_err.stop = 1;
142 spin_unlock_irq(&catas_lock);
143
144 del_timer_sync(&dev->catas_err.timer);
145
146 if (dev->catas_err.map) {
147 iounmap(dev->catas_err.map);
148 release_mem_region(pci_resource_start(dev->pdev, 0) +
149 ((pci_resource_len(dev->pdev, 0) - 1) &
150 dev->catas_err.addr),
151 dev->catas_err.size * 4);
152 }
153}
diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
index f6a8ac026557..49f211d55df7 100644
--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Mellanox Technologies. All rights reserved. 3 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
4 * Copyright (c) 2005 Cisco Systems. All rights reserved.
4 * 5 *
5 * This software is available to you under a choice of one of two 6 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 7 * licenses. You may choose to be licensed under the terms of the GNU
@@ -524,7 +525,7 @@ void mthca_cmd_use_polling(struct mthca_dev *dev)
524} 525}
525 526
526struct mthca_mailbox *mthca_alloc_mailbox(struct mthca_dev *dev, 527struct mthca_mailbox *mthca_alloc_mailbox(struct mthca_dev *dev,
527 unsigned int gfp_mask) 528 gfp_t gfp_mask)
528{ 529{
529 struct mthca_mailbox *mailbox; 530 struct mthca_mailbox *mailbox;
530 531
@@ -706,9 +707,13 @@ int mthca_QUERY_FW(struct mthca_dev *dev, u8 *status)
706 707
707 MTHCA_GET(lg, outbox, QUERY_FW_MAX_CMD_OFFSET); 708 MTHCA_GET(lg, outbox, QUERY_FW_MAX_CMD_OFFSET);
708 dev->cmd.max_cmds = 1 << lg; 709 dev->cmd.max_cmds = 1 << lg;
710 MTHCA_GET(dev->catas_err.addr, outbox, QUERY_FW_ERR_START_OFFSET);
711 MTHCA_GET(dev->catas_err.size, outbox, QUERY_FW_ERR_SIZE_OFFSET);
709 712
710 mthca_dbg(dev, "FW version %012llx, max commands %d\n", 713 mthca_dbg(dev, "FW version %012llx, max commands %d\n",
711 (unsigned long long) dev->fw_ver, dev->cmd.max_cmds); 714 (unsigned long long) dev->fw_ver, dev->cmd.max_cmds);
715 mthca_dbg(dev, "Catastrophic error buffer at 0x%llx, size 0x%x\n",
716 (unsigned long long) dev->catas_err.addr, dev->catas_err.size);
712 717
713 if (mthca_is_memfree(dev)) { 718 if (mthca_is_memfree(dev)) {
714 MTHCA_GET(dev->fw.arbel.fw_pages, outbox, QUERY_FW_SIZE_OFFSET); 719 MTHCA_GET(dev->fw.arbel.fw_pages, outbox, QUERY_FW_SIZE_OFFSET);
@@ -933,9 +938,9 @@ int mthca_QUERY_DEV_LIM(struct mthca_dev *dev,
933 goto out; 938 goto out;
934 939
935 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_SRQ_SZ_OFFSET); 940 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_SRQ_SZ_OFFSET);
936 dev_lim->max_srq_sz = 1 << field; 941 dev_lim->max_srq_sz = (1 << field) - 1;
937 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_QP_SZ_OFFSET); 942 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_QP_SZ_OFFSET);
938 dev_lim->max_qp_sz = 1 << field; 943 dev_lim->max_qp_sz = (1 << field) - 1;
939 MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_QP_OFFSET); 944 MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSVD_QP_OFFSET);
940 dev_lim->reserved_qps = 1 << (field & 0xf); 945 dev_lim->reserved_qps = 1 << (field & 0xf);
941 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_QP_OFFSET); 946 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_QP_OFFSET);
@@ -1045,6 +1050,8 @@ int mthca_QUERY_DEV_LIM(struct mthca_dev *dev,
1045 dev_lim->max_pds, dev_lim->reserved_pds, dev_lim->reserved_uars); 1050 dev_lim->max_pds, dev_lim->reserved_pds, dev_lim->reserved_uars);
1046 mthca_dbg(dev, "Max QP/MCG: %d, reserved MGMs: %d\n", 1051 mthca_dbg(dev, "Max QP/MCG: %d, reserved MGMs: %d\n",
1047 dev_lim->max_pds, dev_lim->reserved_mgms); 1052 dev_lim->max_pds, dev_lim->reserved_mgms);
1053 mthca_dbg(dev, "Max CQEs: %d, max WQEs: %d, max SRQ WQEs: %d\n",
1054 dev_lim->max_cq_sz, dev_lim->max_qp_sz, dev_lim->max_srq_sz);
1048 1055
1049 mthca_dbg(dev, "Flags: %08x\n", dev_lim->flags); 1056 mthca_dbg(dev, "Flags: %08x\n", dev_lim->flags);
1050 1057
diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.h b/drivers/infiniband/hw/mthca/mthca_cmd.h
index 65f976a13e02..18175bec84c2 100644
--- a/drivers/infiniband/hw/mthca/mthca_cmd.h
+++ b/drivers/infiniband/hw/mthca/mthca_cmd.h
@@ -248,7 +248,7 @@ void mthca_cmd_event(struct mthca_dev *dev, u16 token,
248 u8 status, u64 out_param); 248 u8 status, u64 out_param);
249 249
250struct mthca_mailbox *mthca_alloc_mailbox(struct mthca_dev *dev, 250struct mthca_mailbox *mthca_alloc_mailbox(struct mthca_dev *dev,
251 unsigned int gfp_mask); 251 gfp_t gfp_mask);
252void mthca_free_mailbox(struct mthca_dev *dev, struct mthca_mailbox *mailbox); 252void mthca_free_mailbox(struct mthca_dev *dev, struct mthca_mailbox *mailbox);
253 253
254int mthca_SYS_EN(struct mthca_dev *dev, u8 *status); 254int mthca_SYS_EN(struct mthca_dev *dev, u8 *status);
diff --git a/drivers/infiniband/hw/mthca/mthca_dev.h b/drivers/infiniband/hw/mthca/mthca_dev.h
index 7bff5a8425f4..7e68bd4a3780 100644
--- a/drivers/infiniband/hw/mthca/mthca_dev.h
+++ b/drivers/infiniband/hw/mthca/mthca_dev.h
@@ -83,6 +83,8 @@ enum {
83 /* Arbel FW gives us these, but we need them for Tavor */ 83 /* Arbel FW gives us these, but we need them for Tavor */
84 MTHCA_MPT_ENTRY_SIZE = 0x40, 84 MTHCA_MPT_ENTRY_SIZE = 0x40,
85 MTHCA_MTT_SEG_SIZE = 0x40, 85 MTHCA_MTT_SEG_SIZE = 0x40,
86
87 MTHCA_QP_PER_MGM = 4 * (MTHCA_MGM_ENTRY_SIZE / 16 - 2)
86}; 88};
87 89
88enum { 90enum {
@@ -128,12 +130,16 @@ struct mthca_limits {
128 int num_uars; 130 int num_uars;
129 int max_sg; 131 int max_sg;
130 int num_qps; 132 int num_qps;
133 int max_wqes;
134 int max_qp_init_rdma;
131 int reserved_qps; 135 int reserved_qps;
132 int num_srqs; 136 int num_srqs;
137 int max_srq_wqes;
133 int reserved_srqs; 138 int reserved_srqs;
134 int num_eecs; 139 int num_eecs;
135 int reserved_eecs; 140 int reserved_eecs;
136 int num_cqs; 141 int num_cqs;
142 int max_cqes;
137 int reserved_cqs; 143 int reserved_cqs;
138 int num_eqs; 144 int num_eqs;
139 int reserved_eqs; 145 int reserved_eqs;
@@ -148,6 +154,7 @@ struct mthca_limits {
148 int reserved_mcgs; 154 int reserved_mcgs;
149 int num_pds; 155 int num_pds;
150 int reserved_pds; 156 int reserved_pds;
157 u32 flags;
151 u8 port_width_cap; 158 u8 port_width_cap;
152}; 159};
153 160
@@ -251,6 +258,14 @@ struct mthca_mcg_table {
251 struct mthca_icm_table *table; 258 struct mthca_icm_table *table;
252}; 259};
253 260
261struct mthca_catas_err {
262 u64 addr;
263 u32 __iomem *map;
264 unsigned long stop;
265 u32 size;
266 struct timer_list timer;
267};
268
254struct mthca_dev { 269struct mthca_dev {
255 struct ib_device ib_dev; 270 struct ib_device ib_dev;
256 struct pci_dev *pdev; 271 struct pci_dev *pdev;
@@ -311,6 +326,8 @@ struct mthca_dev {
311 struct mthca_av_table av_table; 326 struct mthca_av_table av_table;
312 struct mthca_mcg_table mcg_table; 327 struct mthca_mcg_table mcg_table;
313 328
329 struct mthca_catas_err catas_err;
330
314 struct mthca_uar driver_uar; 331 struct mthca_uar driver_uar;
315 struct mthca_db_table *db_tab; 332 struct mthca_db_table *db_tab;
316 struct mthca_pd driver_pd; 333 struct mthca_pd driver_pd;
@@ -398,6 +415,9 @@ void mthca_cleanup_mcg_table(struct mthca_dev *dev);
398int mthca_register_device(struct mthca_dev *dev); 415int mthca_register_device(struct mthca_dev *dev);
399void mthca_unregister_device(struct mthca_dev *dev); 416void mthca_unregister_device(struct mthca_dev *dev);
400 417
418void mthca_start_catas_poll(struct mthca_dev *dev);
419void mthca_stop_catas_poll(struct mthca_dev *dev);
420
401int mthca_uar_alloc(struct mthca_dev *dev, struct mthca_uar *uar); 421int mthca_uar_alloc(struct mthca_dev *dev, struct mthca_uar *uar);
402void mthca_uar_free(struct mthca_dev *dev, struct mthca_uar *uar); 422void mthca_uar_free(struct mthca_dev *dev, struct mthca_uar *uar);
403 423
@@ -447,6 +467,8 @@ void mthca_cq_clean(struct mthca_dev *dev, u32 cqn, u32 qpn,
447int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd, 467int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,
448 struct ib_srq_attr *attr, struct mthca_srq *srq); 468 struct ib_srq_attr *attr, struct mthca_srq *srq);
449void mthca_free_srq(struct mthca_dev *dev, struct mthca_srq *srq); 469void mthca_free_srq(struct mthca_dev *dev, struct mthca_srq *srq);
470int mthca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
471 enum ib_srq_attr_mask attr_mask);
450void mthca_srq_event(struct mthca_dev *dev, u32 srqn, 472void mthca_srq_event(struct mthca_dev *dev, u32 srqn,
451 enum ib_event_type event_type); 473 enum ib_event_type event_type);
452void mthca_free_srq_wqe(struct mthca_srq *srq, u32 wqe_addr); 474void mthca_free_srq_wqe(struct mthca_srq *srq, u32 wqe_addr);
diff --git a/drivers/infiniband/hw/mthca/mthca_eq.c b/drivers/infiniband/hw/mthca/mthca_eq.c
index 8dfafda5ed24..e5a047a6dbeb 100644
--- a/drivers/infiniband/hw/mthca/mthca_eq.c
+++ b/drivers/infiniband/hw/mthca/mthca_eq.c
@@ -83,7 +83,8 @@ enum {
83 MTHCA_EVENT_TYPE_PATH_MIG = 0x01, 83 MTHCA_EVENT_TYPE_PATH_MIG = 0x01,
84 MTHCA_EVENT_TYPE_COMM_EST = 0x02, 84 MTHCA_EVENT_TYPE_COMM_EST = 0x02,
85 MTHCA_EVENT_TYPE_SQ_DRAINED = 0x03, 85 MTHCA_EVENT_TYPE_SQ_DRAINED = 0x03,
86 MTHCA_EVENT_TYPE_SRQ_LAST_WQE = 0x13, 86 MTHCA_EVENT_TYPE_SRQ_QP_LAST_WQE = 0x13,
87 MTHCA_EVENT_TYPE_SRQ_LIMIT = 0x14,
87 MTHCA_EVENT_TYPE_CQ_ERROR = 0x04, 88 MTHCA_EVENT_TYPE_CQ_ERROR = 0x04,
88 MTHCA_EVENT_TYPE_WQ_CATAS_ERROR = 0x05, 89 MTHCA_EVENT_TYPE_WQ_CATAS_ERROR = 0x05,
89 MTHCA_EVENT_TYPE_EEC_CATAS_ERROR = 0x06, 90 MTHCA_EVENT_TYPE_EEC_CATAS_ERROR = 0x06,
@@ -110,8 +111,9 @@ enum {
110 (1ULL << MTHCA_EVENT_TYPE_LOCAL_CATAS_ERROR) | \ 111 (1ULL << MTHCA_EVENT_TYPE_LOCAL_CATAS_ERROR) | \
111 (1ULL << MTHCA_EVENT_TYPE_PORT_CHANGE) | \ 112 (1ULL << MTHCA_EVENT_TYPE_PORT_CHANGE) | \
112 (1ULL << MTHCA_EVENT_TYPE_ECC_DETECT)) 113 (1ULL << MTHCA_EVENT_TYPE_ECC_DETECT))
113#define MTHCA_SRQ_EVENT_MASK (1ULL << MTHCA_EVENT_TYPE_SRQ_CATAS_ERROR) | \ 114#define MTHCA_SRQ_EVENT_MASK ((1ULL << MTHCA_EVENT_TYPE_SRQ_CATAS_ERROR) | \
114 (1ULL << MTHCA_EVENT_TYPE_SRQ_LAST_WQE) 115 (1ULL << MTHCA_EVENT_TYPE_SRQ_QP_LAST_WQE) | \
116 (1ULL << MTHCA_EVENT_TYPE_SRQ_LIMIT))
115#define MTHCA_CMD_EVENT_MASK (1ULL << MTHCA_EVENT_TYPE_CMD) 117#define MTHCA_CMD_EVENT_MASK (1ULL << MTHCA_EVENT_TYPE_CMD)
116 118
117#define MTHCA_EQ_DB_INC_CI (1 << 24) 119#define MTHCA_EQ_DB_INC_CI (1 << 24)
@@ -142,6 +144,9 @@ struct mthca_eqe {
142 __be32 qpn; 144 __be32 qpn;
143 } __attribute__((packed)) qp; 145 } __attribute__((packed)) qp;
144 struct { 146 struct {
147 __be32 srqn;
148 } __attribute__((packed)) srq;
149 struct {
145 __be32 cqn; 150 __be32 cqn;
146 u32 reserved1; 151 u32 reserved1;
147 u8 reserved2[3]; 152 u8 reserved2[3];
@@ -305,6 +310,16 @@ static int mthca_eq_int(struct mthca_dev *dev, struct mthca_eq *eq)
305 IB_EVENT_SQ_DRAINED); 310 IB_EVENT_SQ_DRAINED);
306 break; 311 break;
307 312
313 case MTHCA_EVENT_TYPE_SRQ_QP_LAST_WQE:
314 mthca_qp_event(dev, be32_to_cpu(eqe->event.qp.qpn) & 0xffffff,
315 IB_EVENT_QP_LAST_WQE_REACHED);
316 break;
317
318 case MTHCA_EVENT_TYPE_SRQ_LIMIT:
319 mthca_srq_event(dev, be32_to_cpu(eqe->event.srq.srqn) & 0xffffff,
320 IB_EVENT_SRQ_LIMIT_REACHED);
321 break;
322
308 case MTHCA_EVENT_TYPE_WQ_CATAS_ERROR: 323 case MTHCA_EVENT_TYPE_WQ_CATAS_ERROR:
309 mthca_qp_event(dev, be32_to_cpu(eqe->event.qp.qpn) & 0xffffff, 324 mthca_qp_event(dev, be32_to_cpu(eqe->event.qp.qpn) & 0xffffff,
310 IB_EVENT_QP_FATAL); 325 IB_EVENT_QP_FATAL);
diff --git a/drivers/infiniband/hw/mthca/mthca_mad.c b/drivers/infiniband/hw/mthca/mthca_mad.c
index 9804174f7f3c..1229c604c6e0 100644
--- a/drivers/infiniband/hw/mthca/mthca_mad.c
+++ b/drivers/infiniband/hw/mthca/mthca_mad.c
@@ -34,6 +34,9 @@
34 * $Id: mthca_mad.c 1349 2004-12-16 21:09:43Z roland $ 34 * $Id: mthca_mad.c 1349 2004-12-16 21:09:43Z roland $
35 */ 35 */
36 36
37#include <linux/string.h>
38#include <linux/slab.h>
39
37#include <rdma/ib_verbs.h> 40#include <rdma/ib_verbs.h>
38#include <rdma/ib_mad.h> 41#include <rdma/ib_mad.h>
39#include <rdma/ib_smi.h> 42#include <rdma/ib_smi.h>
@@ -46,11 +49,6 @@ enum {
46 MTHCA_VENDOR_CLASS2 = 0xa 49 MTHCA_VENDOR_CLASS2 = 0xa
47}; 50};
48 51
49struct mthca_trap_mad {
50 struct ib_mad *mad;
51 DECLARE_PCI_UNMAP_ADDR(mapping)
52};
53
54static void update_sm_ah(struct mthca_dev *dev, 52static void update_sm_ah(struct mthca_dev *dev,
55 u8 port_num, u16 lid, u8 sl) 53 u8 port_num, u16 lid, u8 sl)
56{ 54{
@@ -116,49 +114,14 @@ static void forward_trap(struct mthca_dev *dev,
116 struct ib_mad *mad) 114 struct ib_mad *mad)
117{ 115{
118 int qpn = mad->mad_hdr.mgmt_class != IB_MGMT_CLASS_SUBN_LID_ROUTED; 116 int qpn = mad->mad_hdr.mgmt_class != IB_MGMT_CLASS_SUBN_LID_ROUTED;
119 struct mthca_trap_mad *tmad; 117 struct ib_mad_send_buf *send_buf;
120 struct ib_sge gather_list;
121 struct ib_send_wr *bad_wr, wr = {
122 .opcode = IB_WR_SEND,
123 .sg_list = &gather_list,
124 .num_sge = 1,
125 .send_flags = IB_SEND_SIGNALED,
126 .wr = {
127 .ud = {
128 .remote_qpn = qpn,
129 .remote_qkey = qpn ? IB_QP1_QKEY : 0,
130 .timeout_ms = 0
131 }
132 }
133 };
134 struct ib_mad_agent *agent = dev->send_agent[port_num - 1][qpn]; 118 struct ib_mad_agent *agent = dev->send_agent[port_num - 1][qpn];
135 int ret; 119 int ret;
136 unsigned long flags; 120 unsigned long flags;
137 121
138 if (agent) { 122 if (agent) {
139 tmad = kmalloc(sizeof *tmad, GFP_KERNEL); 123 send_buf = ib_create_send_mad(agent, qpn, 0, 0, IB_MGMT_MAD_HDR,
140 if (!tmad) 124 IB_MGMT_MAD_DATA, GFP_ATOMIC);
141 return;
142
143 tmad->mad = kmalloc(sizeof *tmad->mad, GFP_KERNEL);
144 if (!tmad->mad) {
145 kfree(tmad);
146 return;
147 }
148
149 memcpy(tmad->mad, mad, sizeof *mad);
150
151 wr.wr.ud.mad_hdr = &tmad->mad->mad_hdr;
152 wr.wr_id = (unsigned long) tmad;
153
154 gather_list.addr = dma_map_single(agent->device->dma_device,
155 tmad->mad,
156 sizeof *tmad->mad,
157 DMA_TO_DEVICE);
158 gather_list.length = sizeof *tmad->mad;
159 gather_list.lkey = to_mpd(agent->qp->pd)->ntmr.ibmr.lkey;
160 pci_unmap_addr_set(tmad, mapping, gather_list.addr);
161
162 /* 125 /*
163 * We rely here on the fact that MLX QPs don't use the 126 * We rely here on the fact that MLX QPs don't use the
164 * address handle after the send is posted (this is 127 * address handle after the send is posted (this is
@@ -166,21 +129,15 @@ static void forward_trap(struct mthca_dev *dev,
166 * it's OK for our devices). 129 * it's OK for our devices).
167 */ 130 */
168 spin_lock_irqsave(&dev->sm_lock, flags); 131 spin_lock_irqsave(&dev->sm_lock, flags);
169 wr.wr.ud.ah = dev->sm_ah[port_num - 1]; 132 memcpy(send_buf->mad, mad, sizeof *mad);
170 if (wr.wr.ud.ah) 133 if ((send_buf->ah = dev->sm_ah[port_num - 1]))
171 ret = ib_post_send_mad(agent, &wr, &bad_wr); 134 ret = ib_post_send_mad(send_buf, NULL);
172 else 135 else
173 ret = -EINVAL; 136 ret = -EINVAL;
174 spin_unlock_irqrestore(&dev->sm_lock, flags); 137 spin_unlock_irqrestore(&dev->sm_lock, flags);
175 138
176 if (ret) { 139 if (ret)
177 dma_unmap_single(agent->device->dma_device, 140 ib_free_send_mad(send_buf);
178 pci_unmap_addr(tmad, mapping),
179 sizeof *tmad->mad,
180 DMA_TO_DEVICE);
181 kfree(tmad->mad);
182 kfree(tmad);
183 }
184 } 141 }
185} 142}
186 143
@@ -267,15 +224,7 @@ int mthca_process_mad(struct ib_device *ibdev,
267static void send_handler(struct ib_mad_agent *agent, 224static void send_handler(struct ib_mad_agent *agent,
268 struct ib_mad_send_wc *mad_send_wc) 225 struct ib_mad_send_wc *mad_send_wc)
269{ 226{
270 struct mthca_trap_mad *tmad = 227 ib_free_send_mad(mad_send_wc->send_buf);
271 (void *) (unsigned long) mad_send_wc->wr_id;
272
273 dma_unmap_single(agent->device->dma_device,
274 pci_unmap_addr(tmad, mapping),
275 sizeof *tmad->mad,
276 DMA_TO_DEVICE);
277 kfree(tmad->mad);
278 kfree(tmad);
279} 228}
280 229
281int mthca_create_agents(struct mthca_dev *dev) 230int mthca_create_agents(struct mthca_dev *dev)
diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
index 23a3f56c7899..883d1e5a79bc 100644
--- a/drivers/infiniband/hw/mthca/mthca_main.c
+++ b/drivers/infiniband/hw/mthca/mthca_main.c
@@ -162,9 +162,18 @@ static int __devinit mthca_dev_lim(struct mthca_dev *mdev, struct mthca_dev_lim
162 mdev->limits.pkey_table_len = dev_lim->max_pkeys; 162 mdev->limits.pkey_table_len = dev_lim->max_pkeys;
163 mdev->limits.local_ca_ack_delay = dev_lim->local_ca_ack_delay; 163 mdev->limits.local_ca_ack_delay = dev_lim->local_ca_ack_delay;
164 mdev->limits.max_sg = dev_lim->max_sg; 164 mdev->limits.max_sg = dev_lim->max_sg;
165 mdev->limits.max_wqes = dev_lim->max_qp_sz;
166 mdev->limits.max_qp_init_rdma = dev_lim->max_requester_per_qp;
165 mdev->limits.reserved_qps = dev_lim->reserved_qps; 167 mdev->limits.reserved_qps = dev_lim->reserved_qps;
168 mdev->limits.max_srq_wqes = dev_lim->max_srq_sz;
166 mdev->limits.reserved_srqs = dev_lim->reserved_srqs; 169 mdev->limits.reserved_srqs = dev_lim->reserved_srqs;
167 mdev->limits.reserved_eecs = dev_lim->reserved_eecs; 170 mdev->limits.reserved_eecs = dev_lim->reserved_eecs;
171 /*
172 * Subtract 1 from the limit because we need to allocate a
173 * spare CQE so the HCA HW can tell the difference between an
174 * empty CQ and a full CQ.
175 */
176 mdev->limits.max_cqes = dev_lim->max_cq_sz - 1;
168 mdev->limits.reserved_cqs = dev_lim->reserved_cqs; 177 mdev->limits.reserved_cqs = dev_lim->reserved_cqs;
169 mdev->limits.reserved_eqs = dev_lim->reserved_eqs; 178 mdev->limits.reserved_eqs = dev_lim->reserved_eqs;
170 mdev->limits.reserved_mtts = dev_lim->reserved_mtts; 179 mdev->limits.reserved_mtts = dev_lim->reserved_mtts;
@@ -172,6 +181,7 @@ static int __devinit mthca_dev_lim(struct mthca_dev *mdev, struct mthca_dev_lim
172 mdev->limits.reserved_uars = dev_lim->reserved_uars; 181 mdev->limits.reserved_uars = dev_lim->reserved_uars;
173 mdev->limits.reserved_pds = dev_lim->reserved_pds; 182 mdev->limits.reserved_pds = dev_lim->reserved_pds;
174 mdev->limits.port_width_cap = dev_lim->max_port_width; 183 mdev->limits.port_width_cap = dev_lim->max_port_width;
184 mdev->limits.flags = dev_lim->flags;
175 185
176 /* IB_DEVICE_RESIZE_MAX_WR not supported by driver. 186 /* IB_DEVICE_RESIZE_MAX_WR not supported by driver.
177 May be doable since hardware supports it for SRQ. 187 May be doable since hardware supports it for SRQ.
@@ -1186,6 +1196,7 @@ MODULE_DEVICE_TABLE(pci, mthca_pci_table);
1186 1196
1187static struct pci_driver mthca_driver = { 1197static struct pci_driver mthca_driver = {
1188 .name = DRV_NAME, 1198 .name = DRV_NAME,
1199 .owner = THIS_MODULE,
1189 .id_table = mthca_pci_table, 1200 .id_table = mthca_pci_table,
1190 .probe = mthca_init_one, 1201 .probe = mthca_init_one,
1191 .remove = __devexit_p(mthca_remove_one) 1202 .remove = __devexit_p(mthca_remove_one)
diff --git a/drivers/infiniband/hw/mthca/mthca_mcg.c b/drivers/infiniband/hw/mthca/mthca_mcg.c
index a2707605f4c8..2fc449da418d 100644
--- a/drivers/infiniband/hw/mthca/mthca_mcg.c
+++ b/drivers/infiniband/hw/mthca/mthca_mcg.c
@@ -33,14 +33,12 @@
33 */ 33 */
34 34
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/string.h>
37#include <linux/slab.h>
36 38
37#include "mthca_dev.h" 39#include "mthca_dev.h"
38#include "mthca_cmd.h" 40#include "mthca_cmd.h"
39 41
40enum {
41 MTHCA_QP_PER_MGM = 4 * (MTHCA_MGM_ENTRY_SIZE / 16 - 2)
42};
43
44struct mthca_mgm { 42struct mthca_mgm {
45 __be32 next_gid_index; 43 __be32 next_gid_index;
46 u32 reserved[3]; 44 u32 reserved[3];
@@ -189,7 +187,12 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
189 } 187 }
190 188
191 for (i = 0; i < MTHCA_QP_PER_MGM; ++i) 189 for (i = 0; i < MTHCA_QP_PER_MGM; ++i)
192 if (!(mgm->qp[i] & cpu_to_be32(1 << 31))) { 190 if (mgm->qp[i] == cpu_to_be32(ibqp->qp_num | (1 << 31))) {
191 mthca_dbg(dev, "QP %06x already a member of MGM\n",
192 ibqp->qp_num);
193 err = 0;
194 goto out;
195 } else if (!(mgm->qp[i] & cpu_to_be32(1 << 31))) {
193 mgm->qp[i] = cpu_to_be32(ibqp->qp_num | (1 << 31)); 196 mgm->qp[i] = cpu_to_be32(ibqp->qp_num | (1 << 31));
194 break; 197 break;
195 } 198 }
diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.c b/drivers/infiniband/hw/mthca/mthca_memfree.c
index 7bd7a4bec7b4..d72fe95cba08 100644
--- a/drivers/infiniband/hw/mthca/mthca_memfree.c
+++ b/drivers/infiniband/hw/mthca/mthca_memfree.c
@@ -82,7 +82,7 @@ void mthca_free_icm(struct mthca_dev *dev, struct mthca_icm *icm)
82} 82}
83 83
84struct mthca_icm *mthca_alloc_icm(struct mthca_dev *dev, int npages, 84struct mthca_icm *mthca_alloc_icm(struct mthca_dev *dev, int npages,
85 unsigned int gfp_mask) 85 gfp_t gfp_mask)
86{ 86{
87 struct mthca_icm *icm; 87 struct mthca_icm *icm;
88 struct mthca_icm_chunk *chunk = NULL; 88 struct mthca_icm_chunk *chunk = NULL;
@@ -487,7 +487,8 @@ void mthca_cleanup_user_db_tab(struct mthca_dev *dev, struct mthca_uar *uar,
487 } 487 }
488} 488}
489 489
490int mthca_alloc_db(struct mthca_dev *dev, int type, u32 qn, __be32 **db) 490int mthca_alloc_db(struct mthca_dev *dev, enum mthca_db_type type,
491 u32 qn, __be32 **db)
491{ 492{
492 int group; 493 int group;
493 int start, end, dir; 494 int start, end, dir;
diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.h b/drivers/infiniband/hw/mthca/mthca_memfree.h
index bafa51544aa3..4fdca26eea85 100644
--- a/drivers/infiniband/hw/mthca/mthca_memfree.h
+++ b/drivers/infiniband/hw/mthca/mthca_memfree.h
@@ -77,7 +77,7 @@ struct mthca_icm_iter {
77struct mthca_dev; 77struct mthca_dev;
78 78
79struct mthca_icm *mthca_alloc_icm(struct mthca_dev *dev, int npages, 79struct mthca_icm *mthca_alloc_icm(struct mthca_dev *dev, int npages,
80 unsigned int gfp_mask); 80 gfp_t gfp_mask);
81void mthca_free_icm(struct mthca_dev *dev, struct mthca_icm *icm); 81void mthca_free_icm(struct mthca_dev *dev, struct mthca_icm *icm);
82 82
83struct mthca_icm_table *mthca_alloc_icm_table(struct mthca_dev *dev, 83struct mthca_icm_table *mthca_alloc_icm_table(struct mthca_dev *dev,
@@ -173,7 +173,8 @@ void mthca_cleanup_user_db_tab(struct mthca_dev *dev, struct mthca_uar *uar,
173 173
174int mthca_init_db_tab(struct mthca_dev *dev); 174int mthca_init_db_tab(struct mthca_dev *dev);
175void mthca_cleanup_db_tab(struct mthca_dev *dev); 175void mthca_cleanup_db_tab(struct mthca_dev *dev);
176int mthca_alloc_db(struct mthca_dev *dev, int type, u32 qn, __be32 **db); 176int mthca_alloc_db(struct mthca_dev *dev, enum mthca_db_type type,
177 u32 qn, __be32 **db);
177void mthca_free_db(struct mthca_dev *dev, int type, int db_index); 178void mthca_free_db(struct mthca_dev *dev, int type, int db_index);
178 179
179#endif /* MTHCA_MEMFREE_H */ 180#endif /* MTHCA_MEMFREE_H */
diff --git a/drivers/infiniband/hw/mthca/mthca_profile.c b/drivers/infiniband/hw/mthca/mthca_profile.c
index 0576056b34f4..bd1338682074 100644
--- a/drivers/infiniband/hw/mthca/mthca_profile.c
+++ b/drivers/infiniband/hw/mthca/mthca_profile.c
@@ -35,6 +35,8 @@
35 35
36#include <linux/module.h> 36#include <linux/module.h>
37#include <linux/moduleparam.h> 37#include <linux/moduleparam.h>
38#include <linux/string.h>
39#include <linux/slab.h>
38 40
39#include "mthca_profile.h" 41#include "mthca_profile.h"
40 42
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
index 3f5319a46577..1b9477edbd7b 100644
--- a/drivers/infiniband/hw/mthca/mthca_provider.c
+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
@@ -37,6 +37,7 @@
37 */ 37 */
38 38
39#include <rdma/ib_smi.h> 39#include <rdma/ib_smi.h>
40#include <rdma/ib_user_verbs.h>
40#include <linux/mm.h> 41#include <linux/mm.h>
41 42
42#include "mthca_dev.h" 43#include "mthca_dev.h"
@@ -90,15 +91,26 @@ static int mthca_query_device(struct ib_device *ibdev,
90 91
91 props->max_mr_size = ~0ull; 92 props->max_mr_size = ~0ull;
92 props->max_qp = mdev->limits.num_qps - mdev->limits.reserved_qps; 93 props->max_qp = mdev->limits.num_qps - mdev->limits.reserved_qps;
93 props->max_qp_wr = 0xffff; 94 props->max_qp_wr = mdev->limits.max_wqes;
94 props->max_sge = mdev->limits.max_sg; 95 props->max_sge = mdev->limits.max_sg;
95 props->max_cq = mdev->limits.num_cqs - mdev->limits.reserved_cqs; 96 props->max_cq = mdev->limits.num_cqs - mdev->limits.reserved_cqs;
96 props->max_cqe = 0xffff; 97 props->max_cqe = mdev->limits.max_cqes;
97 props->max_mr = mdev->limits.num_mpts - mdev->limits.reserved_mrws; 98 props->max_mr = mdev->limits.num_mpts - mdev->limits.reserved_mrws;
98 props->max_pd = mdev->limits.num_pds - mdev->limits.reserved_pds; 99 props->max_pd = mdev->limits.num_pds - mdev->limits.reserved_pds;
99 props->max_qp_rd_atom = 1 << mdev->qp_table.rdb_shift; 100 props->max_qp_rd_atom = 1 << mdev->qp_table.rdb_shift;
100 props->max_qp_init_rd_atom = 1 << mdev->qp_table.rdb_shift; 101 props->max_qp_init_rd_atom = mdev->limits.max_qp_init_rdma;
102 props->max_res_rd_atom = props->max_qp_rd_atom * props->max_qp;
103 props->max_srq = mdev->limits.num_srqs - mdev->limits.reserved_srqs;
104 props->max_srq_wr = mdev->limits.max_srq_wqes;
105 props->max_srq_sge = mdev->limits.max_sg;
101 props->local_ca_ack_delay = mdev->limits.local_ca_ack_delay; 106 props->local_ca_ack_delay = mdev->limits.local_ca_ack_delay;
107 props->atomic_cap = mdev->limits.flags & DEV_LIM_FLAG_ATOMIC ?
108 IB_ATOMIC_HCA : IB_ATOMIC_NONE;
109 props->max_pkeys = mdev->limits.pkey_table_len;
110 props->max_mcast_grp = mdev->limits.num_mgms + mdev->limits.num_amgms;
111 props->max_mcast_qp_attach = MTHCA_QP_PER_MGM;
112 props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
113 props->max_mcast_grp;
102 114
103 err = 0; 115 err = 0;
104 out: 116 out:
@@ -150,9 +162,13 @@ static int mthca_query_port(struct ib_device *ibdev,
150 props->gid_tbl_len = to_mdev(ibdev)->limits.gid_table_len; 162 props->gid_tbl_len = to_mdev(ibdev)->limits.gid_table_len;
151 props->max_msg_sz = 0x80000000; 163 props->max_msg_sz = 0x80000000;
152 props->pkey_tbl_len = to_mdev(ibdev)->limits.pkey_table_len; 164 props->pkey_tbl_len = to_mdev(ibdev)->limits.pkey_table_len;
165 props->bad_pkey_cntr = be16_to_cpup((__be16 *) (out_mad->data + 46));
153 props->qkey_viol_cntr = be16_to_cpup((__be16 *) (out_mad->data + 48)); 166 props->qkey_viol_cntr = be16_to_cpup((__be16 *) (out_mad->data + 48));
154 props->active_width = out_mad->data[31] & 0xf; 167 props->active_width = out_mad->data[31] & 0xf;
155 props->active_speed = out_mad->data[35] >> 4; 168 props->active_speed = out_mad->data[35] >> 4;
169 props->max_mtu = out_mad->data[41] & 0xf;
170 props->active_mtu = out_mad->data[36] >> 4;
171 props->subnet_timeout = out_mad->data[51] & 0x1f;
156 172
157 out: 173 out:
158 kfree(in_mad); 174 kfree(in_mad);
@@ -634,6 +650,9 @@ static struct ib_cq *mthca_create_cq(struct ib_device *ibdev, int entries,
634 int nent; 650 int nent;
635 int err; 651 int err;
636 652
653 if (entries < 1 || entries > to_mdev(ibdev)->limits.max_cqes)
654 return ERR_PTR(-EINVAL);
655
637 if (context) { 656 if (context) {
638 if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd)) 657 if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd))
639 return ERR_PTR(-EFAULT); 658 return ERR_PTR(-EFAULT);
@@ -1058,6 +1077,26 @@ int mthca_register_device(struct mthca_dev *dev)
1058 strlcpy(dev->ib_dev.name, "mthca%d", IB_DEVICE_NAME_MAX); 1077 strlcpy(dev->ib_dev.name, "mthca%d", IB_DEVICE_NAME_MAX);
1059 dev->ib_dev.owner = THIS_MODULE; 1078 dev->ib_dev.owner = THIS_MODULE;
1060 1079
1080 dev->ib_dev.uverbs_abi_ver = MTHCA_UVERBS_ABI_VERSION;
1081 dev->ib_dev.uverbs_cmd_mask =
1082 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
1083 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
1084 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
1085 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
1086 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
1087 (1ull << IB_USER_VERBS_CMD_REG_MR) |
1088 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
1089 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
1090 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
1091 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
1092 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
1093 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
1094 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
1095 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
1096 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
1097 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
1098 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
1099 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ);
1061 dev->ib_dev.node_type = IB_NODE_CA; 1100 dev->ib_dev.node_type = IB_NODE_CA;
1062 dev->ib_dev.phys_port_cnt = dev->limits.num_ports; 1101 dev->ib_dev.phys_port_cnt = dev->limits.num_ports;
1063 dev->ib_dev.dma_device = &dev->pdev->dev; 1102 dev->ib_dev.dma_device = &dev->pdev->dev;
@@ -1077,6 +1116,7 @@ int mthca_register_device(struct mthca_dev *dev)
1077 1116
1078 if (dev->mthca_flags & MTHCA_FLAG_SRQ) { 1117 if (dev->mthca_flags & MTHCA_FLAG_SRQ) {
1079 dev->ib_dev.create_srq = mthca_create_srq; 1118 dev->ib_dev.create_srq = mthca_create_srq;
1119 dev->ib_dev.modify_srq = mthca_modify_srq;
1080 dev->ib_dev.destroy_srq = mthca_destroy_srq; 1120 dev->ib_dev.destroy_srq = mthca_destroy_srq;
1081 1121
1082 if (mthca_is_memfree(dev)) 1122 if (mthca_is_memfree(dev))
@@ -1135,10 +1175,13 @@ int mthca_register_device(struct mthca_dev *dev)
1135 } 1175 }
1136 } 1176 }
1137 1177
1178 mthca_start_catas_poll(dev);
1179
1138 return 0; 1180 return 0;
1139} 1181}
1140 1182
1141void mthca_unregister_device(struct mthca_dev *dev) 1183void mthca_unregister_device(struct mthca_dev *dev)
1142{ 1184{
1185 mthca_stop_catas_poll(dev);
1143 ib_unregister_device(&dev->ib_dev); 1186 ib_unregister_device(&dev->ib_dev);
1144} 1187}
diff --git a/drivers/infiniband/hw/mthca/mthca_qp.c b/drivers/infiniband/hw/mthca/mthca_qp.c
index 5fa00669f9b8..7c9afde5ace5 100644
--- a/drivers/infiniband/hw/mthca/mthca_qp.c
+++ b/drivers/infiniband/hw/mthca/mthca_qp.c
@@ -36,6 +36,8 @@
36 */ 36 */
37 37
38#include <linux/init.h> 38#include <linux/init.h>
39#include <linux/string.h>
40#include <linux/slab.h>
39 41
40#include <rdma/ib_verbs.h> 42#include <rdma/ib_verbs.h>
41#include <rdma/ib_cache.h> 43#include <rdma/ib_cache.h>
@@ -338,8 +340,7 @@ static const struct {
338 [UC] = (IB_QP_AV | 340 [UC] = (IB_QP_AV |
339 IB_QP_PATH_MTU | 341 IB_QP_PATH_MTU |
340 IB_QP_DEST_QPN | 342 IB_QP_DEST_QPN |
341 IB_QP_RQ_PSN | 343 IB_QP_RQ_PSN),
342 IB_QP_MAX_DEST_RD_ATOMIC),
343 [RC] = (IB_QP_AV | 344 [RC] = (IB_QP_AV |
344 IB_QP_PATH_MTU | 345 IB_QP_PATH_MTU |
345 IB_QP_DEST_QPN | 346 IB_QP_DEST_QPN |
@@ -368,8 +369,7 @@ static const struct {
368 .trans = MTHCA_TRANS_RTR2RTS, 369 .trans = MTHCA_TRANS_RTR2RTS,
369 .req_param = { 370 .req_param = {
370 [UD] = IB_QP_SQ_PSN, 371 [UD] = IB_QP_SQ_PSN,
371 [UC] = (IB_QP_SQ_PSN | 372 [UC] = IB_QP_SQ_PSN,
372 IB_QP_MAX_QP_RD_ATOMIC),
373 [RC] = (IB_QP_TIMEOUT | 373 [RC] = (IB_QP_TIMEOUT |
374 IB_QP_RETRY_CNT | 374 IB_QP_RETRY_CNT |
375 IB_QP_RNR_RETRY | 375 IB_QP_RNR_RETRY |
@@ -446,8 +446,6 @@ static const struct {
446 [UD] = (IB_QP_PKEY_INDEX | 446 [UD] = (IB_QP_PKEY_INDEX |
447 IB_QP_QKEY), 447 IB_QP_QKEY),
448 [UC] = (IB_QP_AV | 448 [UC] = (IB_QP_AV |
449 IB_QP_MAX_QP_RD_ATOMIC |
450 IB_QP_MAX_DEST_RD_ATOMIC |
451 IB_QP_CUR_STATE | 449 IB_QP_CUR_STATE |
452 IB_QP_ALT_PATH | 450 IB_QP_ALT_PATH |
453 IB_QP_ACCESS_FLAGS | 451 IB_QP_ACCESS_FLAGS |
@@ -478,7 +476,7 @@ static const struct {
478 .opt_param = { 476 .opt_param = {
479 [UD] = (IB_QP_CUR_STATE | 477 [UD] = (IB_QP_CUR_STATE |
480 IB_QP_QKEY), 478 IB_QP_QKEY),
481 [UC] = (IB_QP_CUR_STATE), 479 [UC] = IB_QP_CUR_STATE,
482 [RC] = (IB_QP_CUR_STATE | 480 [RC] = (IB_QP_CUR_STATE |
483 IB_QP_MIN_RNR_TIMER), 481 IB_QP_MIN_RNR_TIMER),
484 [MLX] = (IB_QP_CUR_STATE | 482 [MLX] = (IB_QP_CUR_STATE |
@@ -1112,8 +1110,10 @@ static int mthca_set_qp_size(struct mthca_dev *dev, struct ib_qp_cap *cap,
1112 struct mthca_qp *qp) 1110 struct mthca_qp *qp)
1113{ 1111{
1114 /* Sanity check QP size before proceeding */ 1112 /* Sanity check QP size before proceeding */
1115 if (cap->max_send_wr > 65536 || cap->max_recv_wr > 65536 || 1113 if (cap->max_send_wr > dev->limits.max_wqes ||
1116 cap->max_send_sge > 64 || cap->max_recv_sge > 64) 1114 cap->max_recv_wr > dev->limits.max_wqes ||
1115 cap->max_send_sge > dev->limits.max_sg ||
1116 cap->max_recv_sge > dev->limits.max_sg)
1117 return -EINVAL; 1117 return -EINVAL;
1118 1118
1119 if (mthca_is_memfree(dev)) { 1119 if (mthca_is_memfree(dev)) {
diff --git a/drivers/infiniband/hw/mthca/mthca_reset.c b/drivers/infiniband/hw/mthca/mthca_reset.c
index 4f995391dd1d..df5e494a9d38 100644
--- a/drivers/infiniband/hw/mthca/mthca_reset.c
+++ b/drivers/infiniband/hw/mthca/mthca_reset.c
@@ -37,6 +37,7 @@
37#include <linux/errno.h> 37#include <linux/errno.h>
38#include <linux/pci.h> 38#include <linux/pci.h>
39#include <linux/delay.h> 39#include <linux/delay.h>
40#include <linux/slab.h>
40 41
41#include "mthca_dev.h" 42#include "mthca_dev.h"
42#include "mthca_cmd.h" 43#include "mthca_cmd.h"
diff --git a/drivers/infiniband/hw/mthca/mthca_srq.c b/drivers/infiniband/hw/mthca/mthca_srq.c
index 18998d48c53e..64f70aa1b3c0 100644
--- a/drivers/infiniband/hw/mthca/mthca_srq.c
+++ b/drivers/infiniband/hw/mthca/mthca_srq.c
@@ -186,7 +186,8 @@ int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,
186 int err; 186 int err;
187 187
188 /* Sanity check SRQ size before proceeding */ 188 /* Sanity check SRQ size before proceeding */
189 if (attr->max_wr > 16 << 20 || attr->max_sge > 64) 189 if (attr->max_wr > dev->limits.max_srq_wqes ||
190 attr->max_sge > dev->limits.max_sg)
190 return -EINVAL; 191 return -EINVAL;
191 192
192 srq->max = attr->max_wr; 193 srq->max = attr->max_wr;
@@ -332,6 +333,29 @@ void mthca_free_srq(struct mthca_dev *dev, struct mthca_srq *srq)
332 mthca_free_mailbox(dev, mailbox); 333 mthca_free_mailbox(dev, mailbox);
333} 334}
334 335
336int mthca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
337 enum ib_srq_attr_mask attr_mask)
338{
339 struct mthca_dev *dev = to_mdev(ibsrq->device);
340 struct mthca_srq *srq = to_msrq(ibsrq);
341 int ret;
342 u8 status;
343
344 /* We don't support resizing SRQs (yet?) */
345 if (attr_mask & IB_SRQ_MAX_WR)
346 return -EINVAL;
347
348 if (attr_mask & IB_SRQ_LIMIT) {
349 ret = mthca_ARM_SRQ(dev, srq->srqn, attr->srq_limit, &status);
350 if (ret)
351 return ret;
352 if (status)
353 return -EINVAL;
354 }
355
356 return 0;
357}
358
335void mthca_srq_event(struct mthca_dev *dev, u32 srqn, 359void mthca_srq_event(struct mthca_dev *dev, u32 srqn,
336 enum ib_event_type event_type) 360 enum ib_event_type event_type)
337{ 361{
@@ -354,7 +378,7 @@ void mthca_srq_event(struct mthca_dev *dev, u32 srqn,
354 378
355 event.device = &dev->ib_dev; 379 event.device = &dev->ib_dev;
356 event.event = event_type; 380 event.event = event_type;
357 event.element.srq = &srq->ibsrq; 381 event.element.srq = &srq->ibsrq;
358 srq->ibsrq.event_handler(&event, srq->ibsrq.srq_context); 382 srq->ibsrq.event_handler(&event, srq->ibsrq.srq_context);
359 383
360out: 384out:
@@ -415,6 +439,14 @@ int mthca_tavor_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
415 439
416 wqe = get_wqe(srq, ind); 440 wqe = get_wqe(srq, ind);
417 next_ind = *wqe_to_link(wqe); 441 next_ind = *wqe_to_link(wqe);
442
443 if (next_ind < 0) {
444 mthca_err(dev, "SRQ %06x full\n", srq->srqn);
445 err = -ENOMEM;
446 *bad_wr = wr;
447 break;
448 }
449
418 prev_wqe = srq->last; 450 prev_wqe = srq->last;
419 srq->last = wqe; 451 srq->last = wqe;
420 452
@@ -506,6 +538,13 @@ int mthca_arbel_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
506 wqe = get_wqe(srq, ind); 538 wqe = get_wqe(srq, ind);
507 next_ind = *wqe_to_link(wqe); 539 next_ind = *wqe_to_link(wqe);
508 540
541 if (next_ind < 0) {
542 mthca_err(dev, "SRQ %06x full\n", srq->srqn);
543 err = -ENOMEM;
544 *bad_wr = wr;
545 break;
546 }
547
509 ((struct mthca_next_seg *) wqe)->nda_op = 548 ((struct mthca_next_seg *) wqe)->nda_op =
510 cpu_to_be32((next_ind << srq->wqe_shift) | 1); 549 cpu_to_be32((next_ind << srq->wqe_shift) | 1);
511 ((struct mthca_next_seg *) wqe)->ee_nds = 0; 550 ((struct mthca_next_seg *) wqe)->ee_nds = 0;
diff --git a/drivers/infiniband/hw/mthca/mthca_uar.c b/drivers/infiniband/hw/mthca/mthca_uar.c
index 1c8791ded6ff..8e9219842be4 100644
--- a/drivers/infiniband/hw/mthca/mthca_uar.c
+++ b/drivers/infiniband/hw/mthca/mthca_uar.c
@@ -32,6 +32,8 @@
32 * $Id$ 32 * $Id$
33 */ 33 */
34 34
35#include <asm/page.h> /* PAGE_SHIFT */
36
35#include "mthca_dev.h" 37#include "mthca_dev.h"
36#include "mthca_memfree.h" 38#include "mthca_memfree.h"
37 39
diff --git a/drivers/infiniband/hw/mthca/mthca_user.h b/drivers/infiniband/hw/mthca/mthca_user.h
index 41613ec8a04e..bb015c6494c4 100644
--- a/drivers/infiniband/hw/mthca/mthca_user.h
+++ b/drivers/infiniband/hw/mthca/mthca_user.h
@@ -38,6 +38,12 @@
38#include <linux/types.h> 38#include <linux/types.h>
39 39
40/* 40/*
41 * Increment this value if any changes that break userspace ABI
42 * compatibility are made.
43 */
44#define MTHCA_UVERBS_ABI_VERSION 1
45
46/*
41 * Make sure that all structs defined in this file remain laid out so 47 * Make sure that all structs defined in this file remain laid out so
42 * that they pack the same way on 32-bit and 64-bit architectures (to 48 * that they pack the same way on 32-bit and 64-bit architectures (to
43 * avoid incompatibility between 32-bit userspace and 64-bit kernels). 49 * avoid incompatibility between 32-bit userspace and 64-bit kernels).
diff --git a/drivers/infiniband/ulp/ipoib/ipoib.h b/drivers/infiniband/ulp/ipoib/ipoib.h
index 4ea1c1ca85bc..c994a916a58a 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib.h
+++ b/drivers/infiniband/ulp/ipoib/ipoib.h
@@ -100,7 +100,12 @@ struct ipoib_pseudoheader {
100 100
101struct ipoib_mcast; 101struct ipoib_mcast;
102 102
103struct ipoib_buf { 103struct ipoib_rx_buf {
104 struct sk_buff *skb;
105 dma_addr_t mapping;
106};
107
108struct ipoib_tx_buf {
104 struct sk_buff *skb; 109 struct sk_buff *skb;
105 DECLARE_PCI_UNMAP_ADDR(mapping) 110 DECLARE_PCI_UNMAP_ADDR(mapping)
106}; 111};
@@ -150,14 +155,14 @@ struct ipoib_dev_priv {
150 unsigned int admin_mtu; 155 unsigned int admin_mtu;
151 unsigned int mcast_mtu; 156 unsigned int mcast_mtu;
152 157
153 struct ipoib_buf *rx_ring; 158 struct ipoib_rx_buf *rx_ring;
154 159
155 spinlock_t tx_lock; 160 spinlock_t tx_lock;
156 struct ipoib_buf *tx_ring; 161 struct ipoib_tx_buf *tx_ring;
157 unsigned tx_head; 162 unsigned tx_head;
158 unsigned tx_tail; 163 unsigned tx_tail;
159 struct ib_sge tx_sge; 164 struct ib_sge tx_sge;
160 struct ib_send_wr tx_wr; 165 struct ib_send_wr tx_wr;
161 166
162 struct ib_wc ibwc[IPOIB_NUM_WC]; 167 struct ib_wc ibwc[IPOIB_NUM_WC];
163 168
@@ -277,7 +282,7 @@ int ipoib_mcast_attach(struct net_device *dev, u16 mlid,
277int ipoib_mcast_detach(struct net_device *dev, u16 mlid, 282int ipoib_mcast_detach(struct net_device *dev, u16 mlid,
278 union ib_gid *mgid); 283 union ib_gid *mgid);
279 284
280int ipoib_qp_create(struct net_device *dev); 285int ipoib_init_qp(struct net_device *dev);
281int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca); 286int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca);
282void ipoib_transport_dev_cleanup(struct net_device *dev); 287void ipoib_transport_dev_cleanup(struct net_device *dev);
283 288
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_ib.c b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
index f7440096b5ed..192fef884e21 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_ib.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
@@ -95,57 +95,65 @@ void ipoib_free_ah(struct kref *kref)
95 } 95 }
96} 96}
97 97
98static inline int ipoib_ib_receive(struct ipoib_dev_priv *priv, 98static int ipoib_ib_post_receive(struct net_device *dev, int id)
99 unsigned int wr_id,
100 dma_addr_t addr)
101{ 99{
102 struct ib_sge list = { 100 struct ipoib_dev_priv *priv = netdev_priv(dev);
103 .addr = addr, 101 struct ib_sge list;
104 .length = IPOIB_BUF_SIZE, 102 struct ib_recv_wr param;
105 .lkey = priv->mr->lkey,
106 };
107 struct ib_recv_wr param = {
108 .wr_id = wr_id | IPOIB_OP_RECV,
109 .sg_list = &list,
110 .num_sge = 1,
111 };
112 struct ib_recv_wr *bad_wr; 103 struct ib_recv_wr *bad_wr;
104 int ret;
105
106 list.addr = priv->rx_ring[id].mapping;
107 list.length = IPOIB_BUF_SIZE;
108 list.lkey = priv->mr->lkey;
109
110 param.next = NULL;
111 param.wr_id = id | IPOIB_OP_RECV;
112 param.sg_list = &list;
113 param.num_sge = 1;
114
115 ret = ib_post_recv(priv->qp, &param, &bad_wr);
116 if (unlikely(ret)) {
117 ipoib_warn(priv, "receive failed for buf %d (%d)\n", id, ret);
118 dma_unmap_single(priv->ca->dma_device,
119 priv->rx_ring[id].mapping,
120 IPOIB_BUF_SIZE, DMA_FROM_DEVICE);
121 dev_kfree_skb_any(priv->rx_ring[id].skb);
122 priv->rx_ring[id].skb = NULL;
123 }
113 124
114 return ib_post_recv(priv->qp, &param, &bad_wr); 125 return ret;
115} 126}
116 127
117static int ipoib_ib_post_receive(struct net_device *dev, int id) 128static int ipoib_alloc_rx_skb(struct net_device *dev, int id)
118{ 129{
119 struct ipoib_dev_priv *priv = netdev_priv(dev); 130 struct ipoib_dev_priv *priv = netdev_priv(dev);
120 struct sk_buff *skb; 131 struct sk_buff *skb;
121 dma_addr_t addr; 132 dma_addr_t addr;
122 int ret;
123 133
124 skb = dev_alloc_skb(IPOIB_BUF_SIZE + 4); 134 skb = dev_alloc_skb(IPOIB_BUF_SIZE + 4);
125 if (!skb) { 135 if (!skb)
126 ipoib_warn(priv, "failed to allocate receive buffer\n");
127
128 priv->rx_ring[id].skb = NULL;
129 return -ENOMEM; 136 return -ENOMEM;
130 } 137
131 skb_reserve(skb, 4); /* 16 byte align IP header */ 138 /*
132 priv->rx_ring[id].skb = skb; 139 * IB will leave a 40 byte gap for a GRH and IPoIB adds a 4 byte
140 * header. So we need 4 more bytes to get to 48 and align the
141 * IP header to a multiple of 16.
142 */
143 skb_reserve(skb, 4);
144
133 addr = dma_map_single(priv->ca->dma_device, 145 addr = dma_map_single(priv->ca->dma_device,
134 skb->data, IPOIB_BUF_SIZE, 146 skb->data, IPOIB_BUF_SIZE,
135 DMA_FROM_DEVICE); 147 DMA_FROM_DEVICE);
136 pci_unmap_addr_set(&priv->rx_ring[id], mapping, addr); 148 if (unlikely(dma_mapping_error(addr))) {
137
138 ret = ipoib_ib_receive(priv, id, addr);
139 if (ret) {
140 ipoib_warn(priv, "ipoib_ib_receive failed for buf %d (%d)\n",
141 id, ret);
142 dma_unmap_single(priv->ca->dma_device, addr,
143 IPOIB_BUF_SIZE, DMA_FROM_DEVICE);
144 dev_kfree_skb_any(skb); 149 dev_kfree_skb_any(skb);
145 priv->rx_ring[id].skb = NULL; 150 return -EIO;
146 } 151 }
147 152
148 return ret; 153 priv->rx_ring[id].skb = skb;
154 priv->rx_ring[id].mapping = addr;
155
156 return 0;
149} 157}
150 158
151static int ipoib_ib_post_receives(struct net_device *dev) 159static int ipoib_ib_post_receives(struct net_device *dev)
@@ -154,6 +162,10 @@ static int ipoib_ib_post_receives(struct net_device *dev)
154 int i; 162 int i;
155 163
156 for (i = 0; i < IPOIB_RX_RING_SIZE; ++i) { 164 for (i = 0; i < IPOIB_RX_RING_SIZE; ++i) {
165 if (ipoib_alloc_rx_skb(dev, i)) {
166 ipoib_warn(priv, "failed to allocate receive buffer %d\n", i);
167 return -ENOMEM;
168 }
157 if (ipoib_ib_post_receive(dev, i)) { 169 if (ipoib_ib_post_receive(dev, i)) {
158 ipoib_warn(priv, "ipoib_ib_post_receive failed for buf %d\n", i); 170 ipoib_warn(priv, "ipoib_ib_post_receive failed for buf %d\n", i);
159 return -EIO; 171 return -EIO;
@@ -176,28 +188,36 @@ static void ipoib_ib_handle_wc(struct net_device *dev,
176 wr_id &= ~IPOIB_OP_RECV; 188 wr_id &= ~IPOIB_OP_RECV;
177 189
178 if (wr_id < IPOIB_RX_RING_SIZE) { 190 if (wr_id < IPOIB_RX_RING_SIZE) {
179 struct sk_buff *skb = priv->rx_ring[wr_id].skb; 191 struct sk_buff *skb = priv->rx_ring[wr_id].skb;
180 192 dma_addr_t addr = priv->rx_ring[wr_id].mapping;
181 priv->rx_ring[wr_id].skb = NULL;
182 193
183 dma_unmap_single(priv->ca->dma_device, 194 if (unlikely(wc->status != IB_WC_SUCCESS)) {
184 pci_unmap_addr(&priv->rx_ring[wr_id],
185 mapping),
186 IPOIB_BUF_SIZE,
187 DMA_FROM_DEVICE);
188
189 if (wc->status != IB_WC_SUCCESS) {
190 if (wc->status != IB_WC_WR_FLUSH_ERR) 195 if (wc->status != IB_WC_WR_FLUSH_ERR)
191 ipoib_warn(priv, "failed recv event " 196 ipoib_warn(priv, "failed recv event "
192 "(status=%d, wrid=%d vend_err %x)\n", 197 "(status=%d, wrid=%d vend_err %x)\n",
193 wc->status, wr_id, wc->vendor_err); 198 wc->status, wr_id, wc->vendor_err);
199 dma_unmap_single(priv->ca->dma_device, addr,
200 IPOIB_BUF_SIZE, DMA_FROM_DEVICE);
194 dev_kfree_skb_any(skb); 201 dev_kfree_skb_any(skb);
202 priv->rx_ring[wr_id].skb = NULL;
195 return; 203 return;
196 } 204 }
197 205
206 /*
207 * If we can't allocate a new RX buffer, dump
208 * this packet and reuse the old buffer.
209 */
210 if (unlikely(ipoib_alloc_rx_skb(dev, wr_id))) {
211 ++priv->stats.rx_dropped;
212 goto repost;
213 }
214
198 ipoib_dbg_data(priv, "received %d bytes, SLID 0x%04x\n", 215 ipoib_dbg_data(priv, "received %d bytes, SLID 0x%04x\n",
199 wc->byte_len, wc->slid); 216 wc->byte_len, wc->slid);
200 217
218 dma_unmap_single(priv->ca->dma_device, addr,
219 IPOIB_BUF_SIZE, DMA_FROM_DEVICE);
220
201 skb_put(skb, wc->byte_len); 221 skb_put(skb, wc->byte_len);
202 skb_pull(skb, IB_GRH_BYTES); 222 skb_pull(skb, IB_GRH_BYTES);
203 223
@@ -220,8 +240,8 @@ static void ipoib_ib_handle_wc(struct net_device *dev,
220 dev_kfree_skb_any(skb); 240 dev_kfree_skb_any(skb);
221 } 241 }
222 242
223 /* repost receive */ 243 repost:
224 if (ipoib_ib_post_receive(dev, wr_id)) 244 if (unlikely(ipoib_ib_post_receive(dev, wr_id)))
225 ipoib_warn(priv, "ipoib_ib_post_receive failed " 245 ipoib_warn(priv, "ipoib_ib_post_receive failed "
226 "for buf %d\n", wr_id); 246 "for buf %d\n", wr_id);
227 } else 247 } else
@@ -229,7 +249,7 @@ static void ipoib_ib_handle_wc(struct net_device *dev,
229 wr_id); 249 wr_id);
230 250
231 } else { 251 } else {
232 struct ipoib_buf *tx_req; 252 struct ipoib_tx_buf *tx_req;
233 unsigned long flags; 253 unsigned long flags;
234 254
235 if (wr_id >= IPOIB_TX_RING_SIZE) { 255 if (wr_id >= IPOIB_TX_RING_SIZE) {
@@ -302,7 +322,7 @@ void ipoib_send(struct net_device *dev, struct sk_buff *skb,
302 struct ipoib_ah *address, u32 qpn) 322 struct ipoib_ah *address, u32 qpn)
303{ 323{
304 struct ipoib_dev_priv *priv = netdev_priv(dev); 324 struct ipoib_dev_priv *priv = netdev_priv(dev);
305 struct ipoib_buf *tx_req; 325 struct ipoib_tx_buf *tx_req;
306 dma_addr_t addr; 326 dma_addr_t addr;
307 327
308 if (skb->len > dev->mtu + INFINIBAND_ALEN) { 328 if (skb->len > dev->mtu + INFINIBAND_ALEN) {
@@ -387,9 +407,9 @@ int ipoib_ib_dev_open(struct net_device *dev)
387 struct ipoib_dev_priv *priv = netdev_priv(dev); 407 struct ipoib_dev_priv *priv = netdev_priv(dev);
388 int ret; 408 int ret;
389 409
390 ret = ipoib_qp_create(dev); 410 ret = ipoib_init_qp(dev);
391 if (ret) { 411 if (ret) {
392 ipoib_warn(priv, "ipoib_qp_create returned %d\n", ret); 412 ipoib_warn(priv, "ipoib_init_qp returned %d\n", ret);
393 return -1; 413 return -1;
394 } 414 }
395 415
@@ -468,7 +488,7 @@ int ipoib_ib_dev_stop(struct net_device *dev)
468 struct ib_qp_attr qp_attr; 488 struct ib_qp_attr qp_attr;
469 int attr_mask; 489 int attr_mask;
470 unsigned long begin; 490 unsigned long begin;
471 struct ipoib_buf *tx_req; 491 struct ipoib_tx_buf *tx_req;
472 int i; 492 int i;
473 493
474 /* Kill the existing QP and allocate a new one */ 494 /* Kill the existing QP and allocate a new one */
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index 6c5bf07489f4..cd4f42328dbe 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -637,8 +637,11 @@ static void ipoib_timeout(struct net_device *dev)
637{ 637{
638 struct ipoib_dev_priv *priv = netdev_priv(dev); 638 struct ipoib_dev_priv *priv = netdev_priv(dev);
639 639
640 ipoib_warn(priv, "transmit timeout: latency %ld\n", 640 ipoib_warn(priv, "transmit timeout: latency %d msecs\n",
641 jiffies - dev->trans_start); 641 jiffies_to_msecs(jiffies - dev->trans_start));
642 ipoib_warn(priv, "queue stopped %d, tx_head %u, tx_tail %u\n",
643 netif_queue_stopped(dev),
644 priv->tx_head, priv->tx_tail);
642 /* XXX reset QP, etc. */ 645 /* XXX reset QP, etc. */
643} 646}
644 647
@@ -729,7 +732,7 @@ int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port)
729 732
730 /* Allocate RX/TX "rings" to hold queued skbs */ 733 /* Allocate RX/TX "rings" to hold queued skbs */
731 734
732 priv->rx_ring = kmalloc(IPOIB_RX_RING_SIZE * sizeof (struct ipoib_buf), 735 priv->rx_ring = kmalloc(IPOIB_RX_RING_SIZE * sizeof (struct ipoib_rx_buf),
733 GFP_KERNEL); 736 GFP_KERNEL);
734 if (!priv->rx_ring) { 737 if (!priv->rx_ring) {
735 printk(KERN_WARNING "%s: failed to allocate RX ring (%d entries)\n", 738 printk(KERN_WARNING "%s: failed to allocate RX ring (%d entries)\n",
@@ -737,9 +740,9 @@ int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port)
737 goto out; 740 goto out;
738 } 741 }
739 memset(priv->rx_ring, 0, 742 memset(priv->rx_ring, 0,
740 IPOIB_RX_RING_SIZE * sizeof (struct ipoib_buf)); 743 IPOIB_RX_RING_SIZE * sizeof (struct ipoib_rx_buf));
741 744
742 priv->tx_ring = kmalloc(IPOIB_TX_RING_SIZE * sizeof (struct ipoib_buf), 745 priv->tx_ring = kmalloc(IPOIB_TX_RING_SIZE * sizeof (struct ipoib_tx_buf),
743 GFP_KERNEL); 746 GFP_KERNEL);
744 if (!priv->tx_ring) { 747 if (!priv->tx_ring) {
745 printk(KERN_WARNING "%s: failed to allocate TX ring (%d entries)\n", 748 printk(KERN_WARNING "%s: failed to allocate TX ring (%d entries)\n",
@@ -747,7 +750,7 @@ int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port)
747 goto out_rx_ring_cleanup; 750 goto out_rx_ring_cleanup;
748 } 751 }
749 memset(priv->tx_ring, 0, 752 memset(priv->tx_ring, 0,
750 IPOIB_TX_RING_SIZE * sizeof (struct ipoib_buf)); 753 IPOIB_TX_RING_SIZE * sizeof (struct ipoib_tx_buf));
751 754
752 /* priv->tx_head & tx_tail are already 0 */ 755 /* priv->tx_head & tx_tail are already 0 */
753 756
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_verbs.c b/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
index 79f59d0563ed..b5902a7ec240 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
@@ -92,7 +92,7 @@ int ipoib_mcast_detach(struct net_device *dev, u16 mlid, union ib_gid *mgid)
92 return ret; 92 return ret;
93} 93}
94 94
95int ipoib_qp_create(struct net_device *dev) 95int ipoib_init_qp(struct net_device *dev)
96{ 96{
97 struct ipoib_dev_priv *priv = netdev_priv(dev); 97 struct ipoib_dev_priv *priv = netdev_priv(dev);
98 int ret; 98 int ret;
@@ -149,10 +149,11 @@ int ipoib_qp_create(struct net_device *dev)
149 return 0; 149 return 0;
150 150
151out_fail: 151out_fail:
152 ib_destroy_qp(priv->qp); 152 qp_attr.qp_state = IB_QPS_RESET;
153 priv->qp = NULL; 153 if (ib_modify_qp(priv->qp, &qp_attr, IB_QP_STATE))
154 ipoib_warn(priv, "Failed to modify QP to RESET state\n");
154 155
155 return -EINVAL; 156 return ret;
156} 157}
157 158
158int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca) 159int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca)
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 3738d173f9a6..a4696cd0978c 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -20,7 +20,6 @@
20#include <linux/major.h> 20#include <linux/major.h>
21#include <linux/smp_lock.h> 21#include <linux/smp_lock.h>
22#include <linux/device.h> 22#include <linux/device.h>
23#include <linux/devfs_fs_kernel.h>
24#include <linux/compat.h> 23#include <linux/compat.h>
25 24
26struct evdev { 25struct evdev {
@@ -662,6 +661,7 @@ static struct file_operations evdev_fops = {
662static struct input_handle *evdev_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id) 661static struct input_handle *evdev_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id)
663{ 662{
664 struct evdev *evdev; 663 struct evdev *evdev;
664 struct class_device *cdev;
665 int minor; 665 int minor;
666 666
667 for (minor = 0; minor < EVDEV_MINORS && evdev_table[minor]; minor++); 667 for (minor = 0; minor < EVDEV_MINORS && evdev_table[minor]; minor++);
@@ -687,11 +687,13 @@ static struct input_handle *evdev_connect(struct input_handler *handler, struct
687 687
688 evdev_table[minor] = evdev; 688 evdev_table[minor] = evdev;
689 689
690 devfs_mk_cdev(MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + minor), 690 cdev = class_device_create(&input_class, &dev->cdev,
691 S_IFCHR|S_IRUGO|S_IWUSR, "input/event%d", minor);
692 class_device_create(input_class,
693 MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + minor), 691 MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + minor),
694 dev->dev, "event%d", minor); 692 dev->cdev.dev, evdev->name);
693
694 /* temporary symlink to keep userspace happy */
695 sysfs_create_link(&input_class.subsys.kset.kobj, &cdev->kobj,
696 evdev->name);
695 697
696 return &evdev->handle; 698 return &evdev->handle;
697} 699}
@@ -701,9 +703,9 @@ static void evdev_disconnect(struct input_handle *handle)
701 struct evdev *evdev = handle->private; 703 struct evdev *evdev = handle->private;
702 struct evdev_list *list; 704 struct evdev_list *list;
703 705
704 class_device_destroy(input_class, 706 sysfs_remove_link(&input_class.subsys.kset.kobj, evdev->name);
707 class_device_destroy(&input_class,
705 MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + evdev->minor)); 708 MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + evdev->minor));
706 devfs_remove("input/event%d", evdev->minor);
707 evdev->exist = 0; 709 evdev->exist = 0;
708 710
709 if (evdev->open) { 711 if (evdev->open) {
diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
index ab09cf4093e3..0506934244f0 100644
--- a/drivers/input/gameport/gameport.c
+++ b/drivers/input/gameport/gameport.c
@@ -21,6 +21,7 @@
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/kthread.h> 23#include <linux/kthread.h>
24#include <linux/sched.h> /* HZ */
24 25
25/*#include <asm/io.h>*/ 26/*#include <asm/io.h>*/
26 27
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 14ae5583e198..3b1685ff9d10 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -22,12 +22,12 @@
22#include <linux/interrupt.h> 22#include <linux/interrupt.h>
23#include <linux/poll.h> 23#include <linux/poll.h>
24#include <linux/device.h> 24#include <linux/device.h>
25#include <linux/devfs_fs_kernel.h>
26 25
27MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>"); 26MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
28MODULE_DESCRIPTION("Input core"); 27MODULE_DESCRIPTION("Input core");
29MODULE_LICENSE("GPL"); 28MODULE_LICENSE("GPL");
30 29
30EXPORT_SYMBOL(input_allocate_device);
31EXPORT_SYMBOL(input_register_device); 31EXPORT_SYMBOL(input_register_device);
32EXPORT_SYMBOL(input_unregister_device); 32EXPORT_SYMBOL(input_unregister_device);
33EXPORT_SYMBOL(input_register_handler); 33EXPORT_SYMBOL(input_register_handler);
@@ -39,7 +39,7 @@ EXPORT_SYMBOL(input_close_device);
39EXPORT_SYMBOL(input_accept_process); 39EXPORT_SYMBOL(input_accept_process);
40EXPORT_SYMBOL(input_flush_device); 40EXPORT_SYMBOL(input_flush_device);
41EXPORT_SYMBOL(input_event); 41EXPORT_SYMBOL(input_event);
42EXPORT_SYMBOL(input_class); 42EXPORT_SYMBOL_GPL(input_class);
43 43
44#define INPUT_DEVICES 256 44#define INPUT_DEVICES 256
45 45
@@ -316,124 +316,21 @@ static struct input_device_id *input_match_device(struct input_device_id *id, st
316 return NULL; 316 return NULL;
317} 317}
318 318
319 319static int input_print_bitmap(char *buf, int buf_size, unsigned long *bitmap, int max)
320/*
321 * Input hotplugging interface - loading event handlers based on
322 * device bitfields.
323 */
324
325#ifdef CONFIG_HOTPLUG
326
327/*
328 * Input hotplugging invokes what /proc/sys/kernel/hotplug says
329 * (normally /sbin/hotplug) when input devices get added or removed.
330 *
331 * This invokes a user mode policy agent, typically helping to load driver
332 * or other modules, configure the device, and more. Drivers can provide
333 * a MODULE_DEVICE_TABLE to help with module loading subtasks.
334 *
335 */
336
337#define SPRINTF_BIT_A(bit, name, max) \
338 do { \
339 envp[i++] = scratch; \
340 scratch += sprintf(scratch, name); \
341 for (j = NBITS(max) - 1; j >= 0; j--) \
342 if (dev->bit[j]) break; \
343 for (; j >= 0; j--) \
344 scratch += sprintf(scratch, "%lx ", dev->bit[j]); \
345 scratch++; \
346 } while (0)
347
348#define SPRINTF_BIT_A2(bit, name, max, ev) \
349 do { \
350 if (test_bit(ev, dev->evbit)) \
351 SPRINTF_BIT_A(bit, name, max); \
352 } while (0)
353
354static void input_call_hotplug(char *verb, struct input_dev *dev)
355{ 320{
356 char *argv[3], **envp, *buf, *scratch; 321 int i;
357 int i = 0, j, value; 322 int len = 0;
358
359 if (!hotplug_path[0]) {
360 printk(KERN_ERR "input.c: calling hotplug without a hotplug agent defined\n");
361 return;
362 }
363 if (in_interrupt()) {
364 printk(KERN_ERR "input.c: calling hotplug from interrupt\n");
365 return;
366 }
367 if (!current->fs->root) {
368 printk(KERN_WARNING "input.c: calling hotplug without valid filesystem\n");
369 return;
370 }
371 if (!(envp = (char **) kmalloc(20 * sizeof(char *), GFP_KERNEL))) {
372 printk(KERN_ERR "input.c: not enough memory allocating hotplug environment\n");
373 return;
374 }
375 if (!(buf = kmalloc(1024, GFP_KERNEL))) {
376 kfree (envp);
377 printk(KERN_ERR "input.c: not enough memory allocating hotplug environment\n");
378 return;
379 }
380
381 argv[0] = hotplug_path;
382 argv[1] = "input";
383 argv[2] = NULL;
384
385 envp[i++] = "HOME=/";
386 envp[i++] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
387
388 scratch = buf;
389
390 envp[i++] = scratch;
391 scratch += sprintf(scratch, "ACTION=%s", verb) + 1;
392
393 envp[i++] = scratch;
394 scratch += sprintf(scratch, "PRODUCT=%x/%x/%x/%x",
395 dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version) + 1;
396
397 if (dev->name) {
398 envp[i++] = scratch;
399 scratch += sprintf(scratch, "NAME=%s", dev->name) + 1;
400 }
401
402 if (dev->phys) {
403 envp[i++] = scratch;
404 scratch += sprintf(scratch, "PHYS=%s", dev->phys) + 1;
405 }
406
407 SPRINTF_BIT_A(evbit, "EV=", EV_MAX);
408 SPRINTF_BIT_A2(keybit, "KEY=", KEY_MAX, EV_KEY);
409 SPRINTF_BIT_A2(relbit, "REL=", REL_MAX, EV_REL);
410 SPRINTF_BIT_A2(absbit, "ABS=", ABS_MAX, EV_ABS);
411 SPRINTF_BIT_A2(mscbit, "MSC=", MSC_MAX, EV_MSC);
412 SPRINTF_BIT_A2(ledbit, "LED=", LED_MAX, EV_LED);
413 SPRINTF_BIT_A2(sndbit, "SND=", SND_MAX, EV_SND);
414 SPRINTF_BIT_A2(ffbit, "FF=", FF_MAX, EV_FF);
415 SPRINTF_BIT_A2(swbit, "SW=", SW_MAX, EV_SW);
416
417 envp[i++] = NULL;
418
419#ifdef INPUT_DEBUG
420 printk(KERN_DEBUG "input.c: calling %s %s [%s %s %s %s %s]\n",
421 argv[0], argv[1], envp[0], envp[1], envp[2], envp[3], envp[4]);
422#endif
423
424 value = call_usermodehelper(argv [0], argv, envp, 0);
425 323
426 kfree(buf); 324 for (i = NBITS(max) - 1; i > 0; i--)
427 kfree(envp); 325 if (bitmap[i])
326 break;
428 327
429#ifdef INPUT_DEBUG 328 for (; i >= 0; i--)
430 if (value != 0) 329 len += snprintf(buf + len, max(buf_size - len, 0),
431 printk(KERN_DEBUG "input.c: hotplug returned %d\n", value); 330 "%lx%s", bitmap[i], i > 0 ? " " : "");
432#endif 331 return len;
433} 332}
434 333
435#endif
436
437#ifdef CONFIG_PROC_FS 334#ifdef CONFIG_PROC_FS
438 335
439static struct proc_dir_entry *proc_bus_input_dir; 336static struct proc_dir_entry *proc_bus_input_dir;
@@ -455,37 +352,39 @@ static unsigned int input_devices_poll(struct file *file, poll_table *wait)
455 return 0; 352 return 0;
456} 353}
457 354
458#define SPRINTF_BIT_B(bit, name, max) \ 355#define SPRINTF_BIT(ev, bm) \
459 do { \ 356 do { \
460 len += sprintf(buf + len, "B: %s", name); \ 357 len += sprintf(buf + len, "B: %s=", #ev); \
461 for (i = NBITS(max) - 1; i >= 0; i--) \ 358 len += input_print_bitmap(buf + len, INT_MAX, \
462 if (dev->bit[i]) break; \ 359 dev->bm##bit, ev##_MAX); \
463 for (; i >= 0; i--) \ 360 len += sprintf(buf + len, "\n"); \
464 len += sprintf(buf + len, "%lx ", dev->bit[i]); \
465 len += sprintf(buf + len, "\n"); \
466 } while (0) 361 } while (0)
467 362
468#define SPRINTF_BIT_B2(bit, name, max, ev) \ 363#define TEST_AND_SPRINTF_BIT(ev, bm) \
469 do { \ 364 do { \
470 if (test_bit(ev, dev->evbit)) \ 365 if (test_bit(EV_##ev, dev->evbit)) \
471 SPRINTF_BIT_B(bit, name, max); \ 366 SPRINTF_BIT(ev, bm); \
472 } while (0) 367 } while (0)
473 368
474static int input_devices_read(char *buf, char **start, off_t pos, int count, int *eof, void *data) 369static int input_devices_read(char *buf, char **start, off_t pos, int count, int *eof, void *data)
475{ 370{
476 struct input_dev *dev; 371 struct input_dev *dev;
477 struct input_handle *handle; 372 struct input_handle *handle;
373 const char *path;
478 374
479 off_t at = 0; 375 off_t at = 0;
480 int i, len, cnt = 0; 376 int len, cnt = 0;
481 377
482 list_for_each_entry(dev, &input_dev_list, node) { 378 list_for_each_entry(dev, &input_dev_list, node) {
483 379
380 path = dev->dynalloc ? kobject_get_path(&dev->cdev.kobj, GFP_KERNEL) : NULL;
381
484 len = sprintf(buf, "I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n", 382 len = sprintf(buf, "I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n",
485 dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version); 383 dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version);
486 384
487 len += sprintf(buf + len, "N: Name=\"%s\"\n", dev->name ? dev->name : ""); 385 len += sprintf(buf + len, "N: Name=\"%s\"\n", dev->name ? dev->name : "");
488 len += sprintf(buf + len, "P: Phys=%s\n", dev->phys ? dev->phys : ""); 386 len += sprintf(buf + len, "P: Phys=%s\n", dev->phys ? dev->phys : "");
387 len += sprintf(buf + len, "S: Sysfs=%s\n", path ? path : "");
489 len += sprintf(buf + len, "H: Handlers="); 388 len += sprintf(buf + len, "H: Handlers=");
490 389
491 list_for_each_entry(handle, &dev->h_list, d_node) 390 list_for_each_entry(handle, &dev->h_list, d_node)
@@ -493,15 +392,15 @@ static int input_devices_read(char *buf, char **start, off_t pos, int count, int
493 392
494 len += sprintf(buf + len, "\n"); 393 len += sprintf(buf + len, "\n");
495 394
496 SPRINTF_BIT_B(evbit, "EV=", EV_MAX); 395 SPRINTF_BIT(EV, ev);
497 SPRINTF_BIT_B2(keybit, "KEY=", KEY_MAX, EV_KEY); 396 TEST_AND_SPRINTF_BIT(KEY, key);
498 SPRINTF_BIT_B2(relbit, "REL=", REL_MAX, EV_REL); 397 TEST_AND_SPRINTF_BIT(REL, rel);
499 SPRINTF_BIT_B2(absbit, "ABS=", ABS_MAX, EV_ABS); 398 TEST_AND_SPRINTF_BIT(ABS, abs);
500 SPRINTF_BIT_B2(mscbit, "MSC=", MSC_MAX, EV_MSC); 399 TEST_AND_SPRINTF_BIT(MSC, msc);
501 SPRINTF_BIT_B2(ledbit, "LED=", LED_MAX, EV_LED); 400 TEST_AND_SPRINTF_BIT(LED, led);
502 SPRINTF_BIT_B2(sndbit, "SND=", SND_MAX, EV_SND); 401 TEST_AND_SPRINTF_BIT(SND, snd);
503 SPRINTF_BIT_B2(ffbit, "FF=", FF_MAX, EV_FF); 402 TEST_AND_SPRINTF_BIT(FF, ff);
504 SPRINTF_BIT_B2(swbit, "SW=", SW_MAX, EV_SW); 403 TEST_AND_SPRINTF_BIT(SW, sw);
505 404
506 len += sprintf(buf + len, "\n"); 405 len += sprintf(buf + len, "\n");
507 406
@@ -516,6 +415,8 @@ static int input_devices_read(char *buf, char **start, off_t pos, int count, int
516 if (cnt >= count) 415 if (cnt >= count)
517 break; 416 break;
518 } 417 }
418
419 kfree(path);
519 } 420 }
520 421
521 if (&dev->node == &input_dev_list) 422 if (&dev->node == &input_dev_list)
@@ -606,6 +507,240 @@ static inline int input_proc_init(void) { return 0; }
606static inline void input_proc_exit(void) { } 507static inline void input_proc_exit(void) { }
607#endif 508#endif
608 509
510#define INPUT_DEV_STRING_ATTR_SHOW(name) \
511static ssize_t input_dev_show_##name(struct class_device *dev, char *buf) \
512{ \
513 struct input_dev *input_dev = to_input_dev(dev); \
514 int retval; \
515 \
516 retval = down_interruptible(&input_dev->sem); \
517 if (retval) \
518 return retval; \
519 \
520 retval = sprintf(buf, "%s\n", input_dev->name ? input_dev->name : ""); \
521 \
522 up(&input_dev->sem); \
523 \
524 return retval; \
525} \
526static CLASS_DEVICE_ATTR(name, S_IRUGO, input_dev_show_##name, NULL);
527
528INPUT_DEV_STRING_ATTR_SHOW(name);
529INPUT_DEV_STRING_ATTR_SHOW(phys);
530INPUT_DEV_STRING_ATTR_SHOW(uniq);
531
532static struct attribute *input_dev_attrs[] = {
533 &class_device_attr_name.attr,
534 &class_device_attr_phys.attr,
535 &class_device_attr_uniq.attr,
536 NULL
537};
538
539static struct attribute_group input_dev_group = {
540 .attrs = input_dev_attrs,
541};
542
543#define INPUT_DEV_ID_ATTR(name) \
544static ssize_t input_dev_show_id_##name(struct class_device *dev, char *buf) \
545{ \
546 struct input_dev *input_dev = to_input_dev(dev); \
547 return sprintf(buf, "%04x\n", input_dev->id.name); \
548} \
549static CLASS_DEVICE_ATTR(name, S_IRUGO, input_dev_show_id_##name, NULL);
550
551INPUT_DEV_ID_ATTR(bustype);
552INPUT_DEV_ID_ATTR(vendor);
553INPUT_DEV_ID_ATTR(product);
554INPUT_DEV_ID_ATTR(version);
555
556static struct attribute *input_dev_id_attrs[] = {
557 &class_device_attr_bustype.attr,
558 &class_device_attr_vendor.attr,
559 &class_device_attr_product.attr,
560 &class_device_attr_version.attr,
561 NULL
562};
563
564static struct attribute_group input_dev_id_attr_group = {
565 .name = "id",
566 .attrs = input_dev_id_attrs,
567};
568
569#define INPUT_DEV_CAP_ATTR(ev, bm) \
570static ssize_t input_dev_show_cap_##bm(struct class_device *dev, char *buf) \
571{ \
572 struct input_dev *input_dev = to_input_dev(dev); \
573 return input_print_bitmap(buf, PAGE_SIZE, input_dev->bm##bit, ev##_MAX);\
574} \
575static CLASS_DEVICE_ATTR(bm, S_IRUGO, input_dev_show_cap_##bm, NULL);
576
577INPUT_DEV_CAP_ATTR(EV, ev);
578INPUT_DEV_CAP_ATTR(KEY, key);
579INPUT_DEV_CAP_ATTR(REL, rel);
580INPUT_DEV_CAP_ATTR(ABS, abs);
581INPUT_DEV_CAP_ATTR(MSC, msc);
582INPUT_DEV_CAP_ATTR(LED, led);
583INPUT_DEV_CAP_ATTR(SND, snd);
584INPUT_DEV_CAP_ATTR(FF, ff);
585INPUT_DEV_CAP_ATTR(SW, sw);
586
587static struct attribute *input_dev_caps_attrs[] = {
588 &class_device_attr_ev.attr,
589 &class_device_attr_key.attr,
590 &class_device_attr_rel.attr,
591 &class_device_attr_abs.attr,
592 &class_device_attr_msc.attr,
593 &class_device_attr_led.attr,
594 &class_device_attr_snd.attr,
595 &class_device_attr_ff.attr,
596 &class_device_attr_sw.attr,
597 NULL
598};
599
600static struct attribute_group input_dev_caps_attr_group = {
601 .name = "capabilities",
602 .attrs = input_dev_caps_attrs,
603};
604
605static void input_dev_release(struct class_device *class_dev)
606{
607 struct input_dev *dev = to_input_dev(class_dev);
608
609 kfree(dev);
610 module_put(THIS_MODULE);
611}
612
613/*
614 * Input hotplugging interface - loading event handlers based on
615 * device bitfields.
616 */
617static int input_add_hotplug_bm_var(char **envp, int num_envp, int *cur_index,
618 char *buffer, int buffer_size, int *cur_len,
619 const char *name, unsigned long *bitmap, int max)
620{
621 if (*cur_index >= num_envp - 1)
622 return -ENOMEM;
623
624 envp[*cur_index] = buffer + *cur_len;
625
626 *cur_len += snprintf(buffer + *cur_len, max(buffer_size - *cur_len, 0), name);
627 if (*cur_len > buffer_size)
628 return -ENOMEM;
629
630 *cur_len += input_print_bitmap(buffer + *cur_len,
631 max(buffer_size - *cur_len, 0),
632 bitmap, max) + 1;
633 if (*cur_len > buffer_size)
634 return -ENOMEM;
635
636 (*cur_index)++;
637 return 0;
638}
639
640#define INPUT_ADD_HOTPLUG_VAR(fmt, val...) \
641 do { \
642 int err = add_hotplug_env_var(envp, num_envp, &i, \
643 buffer, buffer_size, &len, \
644 fmt, val); \
645 if (err) \
646 return err; \
647 } while (0)
648
649#define INPUT_ADD_HOTPLUG_BM_VAR(name, bm, max) \
650 do { \
651 int err = input_add_hotplug_bm_var(envp, num_envp, &i, \
652 buffer, buffer_size, &len, \
653 name, bm, max); \
654 if (err) \
655 return err; \
656 } while (0)
657
658static int input_dev_hotplug(struct class_device *cdev, char **envp,
659 int num_envp, char *buffer, int buffer_size)
660{
661 struct input_dev *dev = to_input_dev(cdev);
662 int i = 0;
663 int len = 0;
664
665 INPUT_ADD_HOTPLUG_VAR("PRODUCT=%x/%x/%x/%x",
666 dev->id.bustype, dev->id.vendor,
667 dev->id.product, dev->id.version);
668 if (dev->name)
669 INPUT_ADD_HOTPLUG_VAR("NAME=\"%s\"", dev->name);
670 if (dev->phys)
671 INPUT_ADD_HOTPLUG_VAR("PHYS=\"%s\"", dev->phys);
672 if (dev->phys)
673 INPUT_ADD_HOTPLUG_VAR("UNIQ=\"%s\"", dev->uniq);
674
675 INPUT_ADD_HOTPLUG_BM_VAR("EV=", dev->evbit, EV_MAX);
676 if (test_bit(EV_KEY, dev->evbit))
677 INPUT_ADD_HOTPLUG_BM_VAR("KEY=", dev->keybit, KEY_MAX);
678 if (test_bit(EV_REL, dev->evbit))
679 INPUT_ADD_HOTPLUG_BM_VAR("REL=", dev->relbit, REL_MAX);
680 if (test_bit(EV_ABS, dev->evbit))
681 INPUT_ADD_HOTPLUG_BM_VAR("ABS=", dev->absbit, ABS_MAX);
682 if (test_bit(EV_MSC, dev->evbit))
683 INPUT_ADD_HOTPLUG_BM_VAR("MSC=", dev->mscbit, MSC_MAX);
684 if (test_bit(EV_LED, dev->evbit))
685 INPUT_ADD_HOTPLUG_BM_VAR("LED=", dev->ledbit, LED_MAX);
686 if (test_bit(EV_SND, dev->evbit))
687 INPUT_ADD_HOTPLUG_BM_VAR("SND=", dev->sndbit, SND_MAX);
688 if (test_bit(EV_FF, dev->evbit))
689 INPUT_ADD_HOTPLUG_BM_VAR("FF=", dev->ffbit, FF_MAX);
690 if (test_bit(EV_SW, dev->evbit))
691 INPUT_ADD_HOTPLUG_BM_VAR("SW=", dev->swbit, SW_MAX);
692
693 envp[i] = NULL;
694
695 return 0;
696}
697
698struct class input_class = {
699 .name = "input",
700 .release = input_dev_release,
701 .hotplug = input_dev_hotplug,
702};
703
704struct input_dev *input_allocate_device(void)
705{
706 struct input_dev *dev;
707
708 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
709 if (dev) {
710 dev->dynalloc = 1;
711 dev->cdev.class = &input_class;
712 class_device_initialize(&dev->cdev);
713 INIT_LIST_HEAD(&dev->h_list);
714 INIT_LIST_HEAD(&dev->node);
715 }
716
717 return dev;
718}
719
720static void input_register_classdevice(struct input_dev *dev)
721{
722 static atomic_t input_no = ATOMIC_INIT(0);
723 const char *path;
724
725 __module_get(THIS_MODULE);
726
727 dev->dev = dev->cdev.dev;
728
729 snprintf(dev->cdev.class_id, sizeof(dev->cdev.class_id),
730 "input%ld", (unsigned long) atomic_inc_return(&input_no) - 1);
731
732 path = kobject_get_path(&dev->cdev.class->subsys.kset.kobj, GFP_KERNEL);
733 printk(KERN_INFO "input: %s/%s as %s\n",
734 dev->name ? dev->name : "Unspecified device",
735 path ? path : "", dev->cdev.class_id);
736 kfree(path);
737
738 class_device_add(&dev->cdev);
739 sysfs_create_group(&dev->cdev.kobj, &input_dev_group);
740 sysfs_create_group(&dev->cdev.kobj, &input_dev_id_attr_group);
741 sysfs_create_group(&dev->cdev.kobj, &input_dev_caps_attr_group);
742}
743
609void input_register_device(struct input_dev *dev) 744void input_register_device(struct input_dev *dev)
610{ 745{
611 struct input_handle *handle; 746 struct input_handle *handle;
@@ -632,15 +767,15 @@ void input_register_device(struct input_dev *dev)
632 INIT_LIST_HEAD(&dev->h_list); 767 INIT_LIST_HEAD(&dev->h_list);
633 list_add_tail(&dev->node, &input_dev_list); 768 list_add_tail(&dev->node, &input_dev_list);
634 769
770 if (dev->dynalloc)
771 input_register_classdevice(dev);
772
635 list_for_each_entry(handler, &input_handler_list, node) 773 list_for_each_entry(handler, &input_handler_list, node)
636 if (!handler->blacklist || !input_match_device(handler->blacklist, dev)) 774 if (!handler->blacklist || !input_match_device(handler->blacklist, dev))
637 if ((id = input_match_device(handler->id_table, dev))) 775 if ((id = input_match_device(handler->id_table, dev)))
638 if ((handle = handler->connect(handler, dev, id))) 776 if ((handle = handler->connect(handler, dev, id)))
639 input_link_handle(handle); 777 input_link_handle(handle);
640 778
641#ifdef CONFIG_HOTPLUG
642 input_call_hotplug("add", dev);
643#endif
644 779
645 input_wakeup_procfs_readers(); 780 input_wakeup_procfs_readers();
646} 781}
@@ -660,12 +795,14 @@ void input_unregister_device(struct input_dev *dev)
660 handle->handler->disconnect(handle); 795 handle->handler->disconnect(handle);
661 } 796 }
662 797
663#ifdef CONFIG_HOTPLUG
664 input_call_hotplug("remove", dev);
665#endif
666
667 list_del_init(&dev->node); 798 list_del_init(&dev->node);
668 799
800 if (dev->dynalloc) {
801 sysfs_remove_group(&dev->cdev.kobj, &input_dev_caps_attr_group);
802 sysfs_remove_group(&dev->cdev.kobj, &input_dev_id_attr_group);
803 class_device_unregister(&dev->cdev);
804 }
805
669 input_wakeup_procfs_readers(); 806 input_wakeup_procfs_readers();
670} 807}
671 808
@@ -748,16 +885,14 @@ static struct file_operations input_fops = {
748 .open = input_open_file, 885 .open = input_open_file,
749}; 886};
750 887
751struct class *input_class;
752
753static int __init input_init(void) 888static int __init input_init(void)
754{ 889{
755 int err; 890 int err;
756 891
757 input_class = class_create(THIS_MODULE, "input"); 892 err = class_register(&input_class);
758 if (IS_ERR(input_class)) { 893 if (err) {
759 printk(KERN_ERR "input: unable to register input class\n"); 894 printk(KERN_ERR "input: unable to register input_dev class\n");
760 return PTR_ERR(input_class); 895 return err;
761 } 896 }
762 897
763 err = input_proc_init(); 898 err = input_proc_init();
@@ -770,24 +905,18 @@ static int __init input_init(void)
770 goto fail2; 905 goto fail2;
771 } 906 }
772 907
773 err = devfs_mk_dir("input");
774 if (err)
775 goto fail3;
776
777 return 0; 908 return 0;
778 909
779 fail3: unregister_chrdev(INPUT_MAJOR, "input");
780 fail2: input_proc_exit(); 910 fail2: input_proc_exit();
781 fail1: class_destroy(input_class); 911 fail1: class_unregister(&input_class);
782 return err; 912 return err;
783} 913}
784 914
785static void __exit input_exit(void) 915static void __exit input_exit(void)
786{ 916{
787 input_proc_exit(); 917 input_proc_exit();
788 devfs_remove("input");
789 unregister_chrdev(INPUT_MAJOR, "input"); 918 unregister_chrdev(INPUT_MAJOR, "input");
790 class_destroy(input_class); 919 class_unregister(&input_class);
791} 920}
792 921
793subsys_initcall(input_init); 922subsys_initcall(input_init);
diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
index e0938d1d3ad7..20e2972b9204 100644
--- a/drivers/input/joydev.c
+++ b/drivers/input/joydev.c
@@ -26,7 +26,6 @@
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/smp_lock.h> 27#include <linux/smp_lock.h>
28#include <linux/device.h> 28#include <linux/device.h>
29#include <linux/devfs_fs_kernel.h>
30 29
31MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); 30MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
32MODULE_DESCRIPTION("Joystick device interfaces"); 31MODULE_DESCRIPTION("Joystick device interfaces");
@@ -449,6 +448,7 @@ static struct file_operations joydev_fops = {
449static struct input_handle *joydev_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id) 448static struct input_handle *joydev_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id)
450{ 449{
451 struct joydev *joydev; 450 struct joydev *joydev;
451 struct class_device *cdev;
452 int i, j, t, minor; 452 int i, j, t, minor;
453 453
454 for (minor = 0; minor < JOYDEV_MINORS && joydev_table[minor]; minor++); 454 for (minor = 0; minor < JOYDEV_MINORS && joydev_table[minor]; minor++);
@@ -514,11 +514,13 @@ static struct input_handle *joydev_connect(struct input_handler *handler, struct
514 514
515 joydev_table[minor] = joydev; 515 joydev_table[minor] = joydev;
516 516
517 devfs_mk_cdev(MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + minor), 517 cdev = class_device_create(&input_class, &dev->cdev,
518 S_IFCHR|S_IRUGO|S_IWUSR, "input/js%d", minor);
519 class_device_create(input_class,
520 MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + minor), 518 MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + minor),
521 dev->dev, "js%d", minor); 519 dev->cdev.dev, joydev->name);
520
521 /* temporary symlink to keep userspace happy */
522 sysfs_create_link(&input_class.subsys.kset.kobj, &cdev->kobj,
523 joydev->name);
522 524
523 return &joydev->handle; 525 return &joydev->handle;
524} 526}
@@ -528,8 +530,8 @@ static void joydev_disconnect(struct input_handle *handle)
528 struct joydev *joydev = handle->private; 530 struct joydev *joydev = handle->private;
529 struct joydev_list *list; 531 struct joydev_list *list;
530 532
531 class_device_destroy(input_class, MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + joydev->minor)); 533 sysfs_remove_link(&input_class.subsys.kset.kobj, joydev->name);
532 devfs_remove("input/js%d", joydev->minor); 534 class_device_destroy(&input_class, MKDEV(INPUT_MAJOR, JOYDEV_MINOR_BASE + joydev->minor));
533 joydev->exist = 0; 535 joydev->exist = 0;
534 536
535 if (joydev->open) { 537 if (joydev->open) {
diff --git a/drivers/input/joystick/a3d.c b/drivers/input/joystick/a3d.c
index bf65430181fa..4571ea3a4b92 100644
--- a/drivers/input/joystick/a3d.c
+++ b/drivers/input/joystick/a3d.c
@@ -34,6 +34,7 @@
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/gameport.h> 35#include <linux/gameport.h>
36#include <linux/input.h> 36#include <linux/input.h>
37#include <linux/jiffies.h>
37 38
38#define DRIVER_DESC "FP-Gaming Assasin 3D joystick driver" 39#define DRIVER_DESC "FP-Gaming Assasin 3D joystick driver"
39 40
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index cf35ae638a0d..704bf70f1db7 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -34,6 +34,7 @@
34#include <linux/input.h> 34#include <linux/input.h>
35#include <linux/gameport.h> 35#include <linux/gameport.h>
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/jiffies.h>
37 38
38#define DRIVER_DESC "Logitech ADI joystick family driver" 39#define DRIVER_DESC "Logitech ADI joystick family driver"
39 40
@@ -54,7 +55,7 @@ MODULE_LICENSE("GPL");
54#define ADI_MIN_LENGTH 8 55#define ADI_MIN_LENGTH 8
55#define ADI_MIN_LEN_LENGTH 10 56#define ADI_MIN_LEN_LENGTH 10
56#define ADI_MIN_ID_LENGTH 66 57#define ADI_MIN_ID_LENGTH 66
57#define ADI_MAX_NAME_LENGTH 48 58#define ADI_MAX_NAME_LENGTH 64
58#define ADI_MAX_CNAME_LENGTH 16 59#define ADI_MAX_CNAME_LENGTH 16
59#define ADI_MAX_PHYS_LENGTH 64 60#define ADI_MAX_PHYS_LENGTH 64
60 61
@@ -106,7 +107,7 @@ static struct {
106 */ 107 */
107 108
108struct adi { 109struct adi {
109 struct input_dev dev; 110 struct input_dev *dev;
110 int length; 111 int length;
111 int ret; 112 int ret;
112 int idx; 113 int idx;
@@ -215,7 +216,7 @@ static inline int adi_get_bits(struct adi *adi, int count)
215 216
216static int adi_decode(struct adi *adi) 217static int adi_decode(struct adi *adi)
217{ 218{
218 struct input_dev *dev = &adi->dev; 219 struct input_dev *dev = adi->dev;
219 char *abs = adi->abs; 220 char *abs = adi->abs;
220 short *key = adi->key; 221 short *key = adi->key;
221 int i, t; 222 int i, t;
@@ -318,7 +319,8 @@ static void adi_init_digital(struct gameport *gameport)
318 319
319 for (i = 0; seq[i]; i++) { 320 for (i = 0; seq[i]; i++) {
320 gameport_trigger(gameport); 321 gameport_trigger(gameport);
321 if (seq[i] > 0) msleep(seq[i]); 322 if (seq[i] > 0)
323 msleep(seq[i]);
322 if (seq[i] < 0) { 324 if (seq[i] < 0) {
323 mdelay(-seq[i]); 325 mdelay(-seq[i]);
324 udelay(-seq[i]*14); /* It looks like mdelay() is off by approx 1.4% */ 326 udelay(-seq[i]*14); /* It looks like mdelay() is off by approx 1.4% */
@@ -397,42 +399,46 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port)
397 } 399 }
398} 400}
399 401
400static void adi_init_input(struct adi *adi, struct adi_port *port, int half) 402static int adi_init_input(struct adi *adi, struct adi_port *port, int half)
401{ 403{
402 int i, t; 404 struct input_dev *input_dev;
403 char buf[ADI_MAX_NAME_LENGTH]; 405 char buf[ADI_MAX_NAME_LENGTH];
406 int i, t;
404 407
405 if (!adi->length) return; 408 adi->dev = input_dev = input_allocate_device();
406 409 if (!input_dev)
407 init_input_dev(&adi->dev); 410 return -ENOMEM;
408 411
409 t = adi->id < ADI_ID_MAX ? adi->id : ADI_ID_MAX; 412 t = adi->id < ADI_ID_MAX ? adi->id : ADI_ID_MAX;
410 413
411 snprintf(buf, ADI_MAX_PHYS_LENGTH, adi_names[t], adi->id); 414 snprintf(buf, ADI_MAX_PHYS_LENGTH, adi_names[t], adi->id);
412 snprintf(adi->name, ADI_MAX_NAME_LENGTH, "Logitech %s", buf); 415 snprintf(adi->name, ADI_MAX_NAME_LENGTH, "Logitech %s [%s]", buf, adi->cname);
413 snprintf(adi->phys, ADI_MAX_PHYS_LENGTH, "%s/input%d", port->gameport->phys, half); 416 snprintf(adi->phys, ADI_MAX_PHYS_LENGTH, "%s/input%d", port->gameport->phys, half);
414 417
415 adi->abs = adi_abs[t]; 418 adi->abs = adi_abs[t];
416 adi->key = adi_key[t]; 419 adi->key = adi_key[t];
417 420
418 adi->dev.open = adi_open; 421 input_dev->name = adi->name;
419 adi->dev.close = adi_close; 422 input_dev->phys = adi->phys;
423 input_dev->id.bustype = BUS_GAMEPORT;
424 input_dev->id.vendor = GAMEPORT_ID_VENDOR_LOGITECH;
425 input_dev->id.product = adi->id;
426 input_dev->id.version = 0x0100;
427 input_dev->cdev.dev = &port->gameport->dev;
428 input_dev->private = port;
420 429
421 adi->dev.name = adi->name; 430 input_dev->open = adi_open;
422 adi->dev.phys = adi->phys; 431 input_dev->close = adi_close;
423 adi->dev.id.bustype = BUS_GAMEPORT;
424 adi->dev.id.vendor = GAMEPORT_ID_VENDOR_LOGITECH;
425 adi->dev.id.product = adi->id;
426 adi->dev.id.version = 0x0100;
427 432
428 adi->dev.private = port; 433 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
429 adi->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
430 434
431 for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++) 435 for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++)
432 set_bit(adi->abs[i], adi->dev.absbit); 436 set_bit(adi->abs[i], input_dev->absbit);
433 437
434 for (i = 0; i < adi->buttons; i++) 438 for (i = 0; i < adi->buttons; i++)
435 set_bit(adi->key[i], adi->dev.keybit); 439 set_bit(adi->key[i], input_dev->keybit);
440
441 return 0;
436} 442}
437 443
438static void adi_init_center(struct adi *adi) 444static void adi_init_center(struct adi *adi)
@@ -445,17 +451,17 @@ static void adi_init_center(struct adi *adi)
445 for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++) { 451 for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++) {
446 452
447 t = adi->abs[i]; 453 t = adi->abs[i];
448 x = adi->dev.abs[t]; 454 x = adi->dev->abs[t];
449 455
450 if (t == ABS_THROTTLE || t == ABS_RUDDER || adi->id == ADI_ID_WGPE) 456 if (t == ABS_THROTTLE || t == ABS_RUDDER || adi->id == ADI_ID_WGPE)
451 x = i < adi->axes10 ? 512 : 128; 457 x = i < adi->axes10 ? 512 : 128;
452 458
453 if (i < adi->axes10) 459 if (i < adi->axes10)
454 input_set_abs_params(&adi->dev, t, 64, x * 2 - 64, 2, 16); 460 input_set_abs_params(adi->dev, t, 64, x * 2 - 64, 2, 16);
455 else if (i < adi->axes10 + adi->axes8) 461 else if (i < adi->axes10 + adi->axes8)
456 input_set_abs_params(&adi->dev, t, 48, x * 2 - 48, 1, 16); 462 input_set_abs_params(adi->dev, t, 48, x * 2 - 48, 1, 16);
457 else 463 else
458 input_set_abs_params(&adi->dev, t, -1, 1, 0, 0); 464 input_set_abs_params(adi->dev, t, -1, 1, 0, 0);
459 } 465 }
460} 466}
461 467
@@ -469,7 +475,8 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv)
469 int i; 475 int i;
470 int err; 476 int err;
471 477
472 if (!(port = kzalloc(sizeof(struct adi_port), GFP_KERNEL))) 478 port = kzalloc(sizeof(struct adi_port), GFP_KERNEL);
479 if (!port)
473 return -ENOMEM; 480 return -ENOMEM;
474 481
475 port->gameport = gameport; 482 port->gameport = gameport;
@@ -477,10 +484,8 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv)
477 gameport_set_drvdata(gameport, port); 484 gameport_set_drvdata(gameport, port);
478 485
479 err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW); 486 err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW);
480 if (err) { 487 if (err)
481 kfree(port); 488 goto fail1;
482 return err;
483 }
484 489
485 adi_init_digital(gameport); 490 adi_init_digital(gameport);
486 adi_read_packet(port); 491 adi_read_packet(port);
@@ -490,13 +495,18 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv)
490 495
491 for (i = 0; i < 2; i++) { 496 for (i = 0; i < 2; i++) {
492 adi_id_decode(port->adi + i, port); 497 adi_id_decode(port->adi + i, port);
493 adi_init_input(port->adi + i, port, i); 498
499 if (!port->adi[i].length)
500 continue;
501
502 err = adi_init_input(port->adi + i, port, i);
503 if (err)
504 goto fail2;
494 } 505 }
495 506
496 if (!port->adi[0].length && !port->adi[1].length) { 507 if (!port->adi[0].length && !port->adi[1].length) {
497 gameport_close(gameport); 508 err = -ENODEV;
498 kfree(port); 509 goto fail2;
499 return -ENODEV;
500 } 510 }
501 511
502 gameport_set_poll_handler(gameport, adi_poll); 512 gameport_set_poll_handler(gameport, adi_poll);
@@ -511,12 +521,18 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv)
511 for (i = 0; i < 2; i++) 521 for (i = 0; i < 2; i++)
512 if (port->adi[i].length > 0) { 522 if (port->adi[i].length > 0) {
513 adi_init_center(port->adi + i); 523 adi_init_center(port->adi + i);
514 input_register_device(&port->adi[i].dev); 524 input_register_device(port->adi[i].dev);
515 printk(KERN_INFO "input: %s [%s] on %s\n",
516 port->adi[i].name, port->adi[i].cname, gameport->phys);
517 } 525 }
518 526
519 return 0; 527 return 0;
528
529 fail2: for (i = 0; i < 2; i++)
530 if (port->adi[i].dev)
531 input_free_device(port->adi[i].dev);
532 gameport_close(gameport);
533 fail1: gameport_set_drvdata(gameport, NULL);
534 kfree(port);
535 return err;
520} 536}
521 537
522static void adi_disconnect(struct gameport *gameport) 538static void adi_disconnect(struct gameport *gameport)
@@ -526,7 +542,7 @@ static void adi_disconnect(struct gameport *gameport)
526 542
527 for (i = 0; i < 2; i++) 543 for (i = 0; i < 2; i++)
528 if (port->adi[i].length > 0) 544 if (port->adi[i].length > 0)
529 input_unregister_device(&port->adi[i].dev); 545 input_unregister_device(port->adi[i].dev);
530 gameport_close(gameport); 546 gameport_close(gameport);
531 gameport_set_drvdata(gameport, NULL); 547 gameport_set_drvdata(gameport, NULL);
532 kfree(port); 548 kfree(port);
diff --git a/drivers/input/joystick/amijoy.c b/drivers/input/joystick/amijoy.c
index e996183c5b06..8558a99f6635 100644
--- a/drivers/input/joystick/amijoy.c
+++ b/drivers/input/joystick/amijoy.c
@@ -53,11 +53,9 @@ __obsolete_setup("amijoy=");
53 53
54static int amijoy_used; 54static int amijoy_used;
55static DECLARE_MUTEX(amijoy_sem); 55static DECLARE_MUTEX(amijoy_sem);
56static struct input_dev amijoy_dev[2]; 56static struct input_dev *amijoy_dev[2];
57static char *amijoy_phys[2] = { "amijoy/input0", "amijoy/input1" }; 57static char *amijoy_phys[2] = { "amijoy/input0", "amijoy/input1" };
58 58
59static char *amijoy_name = "Amiga joystick";
60
61static irqreturn_t amijoy_interrupt(int irq, void *dummy, struct pt_regs *fp) 59static irqreturn_t amijoy_interrupt(int irq, void *dummy, struct pt_regs *fp)
62{ 60{
63 int i, data = 0, button = 0; 61 int i, data = 0, button = 0;
@@ -70,15 +68,15 @@ static irqreturn_t amijoy_interrupt(int irq, void *dummy, struct pt_regs *fp)
70 case 1: data = ~custom.joy1dat; button = (~ciaa.pra >> 7) & 1; break; 68 case 1: data = ~custom.joy1dat; button = (~ciaa.pra >> 7) & 1; break;
71 } 69 }
72 70
73 input_regs(amijoy_dev + i, fp); 71 input_regs(amijoy_dev[i], fp);
74 72
75 input_report_key(amijoy_dev + i, BTN_TRIGGER, button); 73 input_report_key(amijoy_dev[i], BTN_TRIGGER, button);
76 74
77 input_report_abs(amijoy_dev + i, ABS_X, ((data >> 1) & 1) - ((data >> 9) & 1)); 75 input_report_abs(amijoy_dev[i], ABS_X, ((data >> 1) & 1) - ((data >> 9) & 1));
78 data = ~(data ^ (data << 1)); 76 data = ~(data ^ (data << 1));
79 input_report_abs(amijoy_dev + i, ABS_Y, ((data >> 1) & 1) - ((data >> 9) & 1)); 77 input_report_abs(amijoy_dev[i], ABS_Y, ((data >> 1) & 1) - ((data >> 9) & 1));
80 78
81 input_sync(amijoy_dev + i); 79 input_sync(amijoy_dev[i]);
82 } 80 }
83 return IRQ_HANDLED; 81 return IRQ_HANDLED;
84} 82}
@@ -114,39 +112,52 @@ static void amijoy_close(struct input_dev *dev)
114static int __init amijoy_init(void) 112static int __init amijoy_init(void)
115{ 113{
116 int i, j; 114 int i, j;
115 int err;
117 116
118 for (i = 0; i < 2; i++) 117 for (i = 0; i < 2; i++) {
119 if (amijoy[i]) { 118 if (!amijoy[i])
120 if (!request_mem_region(CUSTOM_PHYSADDR+10+i*2, 2, 119 continue;
121 "amijoy [Denise]")) {
122 if (i == 1 && amijoy[0]) {
123 input_unregister_device(amijoy_dev);
124 release_mem_region(CUSTOM_PHYSADDR+10, 2);
125 }
126 return -EBUSY;
127 }
128 120
129 amijoy_dev[i].open = amijoy_open; 121 amijoy_dev[i] = input_allocate_device();
130 amijoy_dev[i].close = amijoy_close; 122 if (!amijoy_dev[i]) {
131 amijoy_dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 123 err = -ENOMEM;
132 amijoy_dev[i].absbit[0] = BIT(ABS_X) | BIT(ABS_Y); 124 goto fail;
133 amijoy_dev[i].keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT); 125 }
134 for (j = 0; j < 2; j++) {
135 amijoy_dev[i].absmin[ABS_X + j] = -1;
136 amijoy_dev[i].absmax[ABS_X + j] = 1;
137 }
138 126
139 amijoy_dev[i].name = amijoy_name; 127 if (!request_mem_region(CUSTOM_PHYSADDR + 10 + i * 2, 2, "amijoy [Denise]")) {
140 amijoy_dev[i].phys = amijoy_phys[i]; 128 input_free_device(amijoy_dev[i]);
141 amijoy_dev[i].id.bustype = BUS_AMIGA; 129 err = -EBUSY;
142 amijoy_dev[i].id.vendor = 0x0001; 130 goto fail;
143 amijoy_dev[i].id.product = 0x0003; 131 }
144 amijoy_dev[i].id.version = 0x0100;
145 132
146 input_register_device(amijoy_dev + i); 133 amijoy_dev[i]->name = "Amiga joystick";
147 printk(KERN_INFO "input: %s at joy%ddat\n", amijoy_name, i); 134 amijoy_dev[i]->phys = amijoy_phys[i];
135 amijoy_dev[i]->id.bustype = BUS_AMIGA;
136 amijoy_dev[i]->id.vendor = 0x0001;
137 amijoy_dev[i]->id.product = 0x0003;
138 amijoy_dev[i]->id.version = 0x0100;
139
140 amijoy_dev[i]->open = amijoy_open;
141 amijoy_dev[i]->close = amijoy_close;
142
143 amijoy_dev[i]->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
144 amijoy_dev[i]->absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
145 amijoy_dev[i]->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
146 for (j = 0; j < 2; j++) {
147 amijoy_dev[i]->absmin[ABS_X + j] = -1;
148 amijoy_dev[i]->absmax[ABS_X + j] = 1;
148 } 149 }
150
151 input_register_device(amijoy_dev[i]);
152 }
149 return 0; 153 return 0;
154
155 fail: while (--i >= 0)
156 if (amijoy[i]) {
157 input_unregister_device(amijoy_dev[i]);
158 release_mem_region(CUSTOM_PHYSADDR + 10 + i * 2, 2);
159 }
160 return err;
150} 161}
151 162
152static void __exit amijoy_exit(void) 163static void __exit amijoy_exit(void)
@@ -155,8 +166,8 @@ static void __exit amijoy_exit(void)
155 166
156 for (i = 0; i < 2; i++) 167 for (i = 0; i < 2; i++)
157 if (amijoy[i]) { 168 if (amijoy[i]) {
158 input_unregister_device(amijoy_dev + i); 169 input_unregister_device(amijoy_dev[i]);
159 release_mem_region(CUSTOM_PHYSADDR+10+i*2, 2); 170 release_mem_region(CUSTOM_PHYSADDR + 10 + i * 2, 2);
160 } 171 }
161} 172}
162 173
diff --git a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c
index 64b1313a3c66..3121961e3e7c 100644
--- a/drivers/input/joystick/analog.c
+++ b/drivers/input/joystick/analog.c
@@ -38,6 +38,7 @@
38#include <linux/init.h> 38#include <linux/init.h>
39#include <linux/input.h> 39#include <linux/input.h>
40#include <linux/gameport.h> 40#include <linux/gameport.h>
41#include <linux/jiffies.h>
41#include <asm/timex.h> 42#include <asm/timex.h>
42 43
43#define DRIVER_DESC "Analog joystick and gamepad driver" 44#define DRIVER_DESC "Analog joystick and gamepad driver"
@@ -111,7 +112,7 @@ static short analog_joy_btn[] = { BTN_TRIGGER, BTN_THUMB, BTN_TOP, BTN_TOP2, BTN
111static unsigned char analog_chf[] = { 0xf, 0x0, 0x1, 0x9, 0x2, 0x4, 0xc, 0x8, 0x3, 0x5, 0xb, 0x7, 0xd, 0xe, 0xa, 0x6 }; 112static unsigned char analog_chf[] = { 0xf, 0x0, 0x1, 0x9, 0x2, 0x4, 0xc, 0x8, 0x3, 0x5, 0xb, 0x7, 0xd, 0xe, 0xa, 0x6 };
112 113
113struct analog { 114struct analog {
114 struct input_dev dev; 115 struct input_dev *dev;
115 int mask; 116 int mask;
116 short *buttons; 117 short *buttons;
117 char name[ANALOG_MAX_NAME_LENGTH]; 118 char name[ANALOG_MAX_NAME_LENGTH];
@@ -182,7 +183,7 @@ static unsigned long analog_faketime = 0;
182 183
183static void analog_decode(struct analog *analog, int *axes, int *initial, int buttons) 184static void analog_decode(struct analog *analog, int *axes, int *initial, int buttons)
184{ 185{
185 struct input_dev *dev = &analog->dev; 186 struct input_dev *dev = analog->dev;
186 int i, j; 187 int i, j;
187 188
188 if (analog->mask & ANALOG_HAT_FCS) 189 if (analog->mask & ANALOG_HAT_FCS)
@@ -428,27 +429,30 @@ static void analog_name(struct analog *analog)
428 * analog_init_device() 429 * analog_init_device()
429 */ 430 */
430 431
431static void analog_init_device(struct analog_port *port, struct analog *analog, int index) 432static int analog_init_device(struct analog_port *port, struct analog *analog, int index)
432{ 433{
434 struct input_dev *input_dev;
433 int i, j, t, v, w, x, y, z; 435 int i, j, t, v, w, x, y, z;
434 436
435 analog_name(analog); 437 analog_name(analog);
436 sprintf(analog->phys, "%s/input%d", port->gameport->phys, index); 438 sprintf(analog->phys, "%s/input%d", port->gameport->phys, index);
437 analog->buttons = (analog->mask & ANALOG_GAMEPAD) ? analog_pad_btn : analog_joy_btn; 439 analog->buttons = (analog->mask & ANALOG_GAMEPAD) ? analog_pad_btn : analog_joy_btn;
438 440
439 init_input_dev(&analog->dev); 441 analog->dev = input_dev = input_allocate_device();
442 if (!input_dev)
443 return -ENOMEM;
440 444
441 analog->dev.name = analog->name; 445 input_dev->name = analog->name;
442 analog->dev.phys = analog->phys; 446 input_dev->phys = analog->phys;
443 analog->dev.id.bustype = BUS_GAMEPORT; 447 input_dev->id.bustype = BUS_GAMEPORT;
444 analog->dev.id.vendor = GAMEPORT_ID_VENDOR_ANALOG; 448 input_dev->id.vendor = GAMEPORT_ID_VENDOR_ANALOG;
445 analog->dev.id.product = analog->mask >> 4; 449 input_dev->id.product = analog->mask >> 4;
446 analog->dev.id.version = 0x0100; 450 input_dev->id.version = 0x0100;
447 451
448 analog->dev.open = analog_open; 452 input_dev->open = analog_open;
449 analog->dev.close = analog_close; 453 input_dev->close = analog_close;
450 analog->dev.private = port; 454 input_dev->private = port;
451 analog->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 455 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
452 456
453 for (i = j = 0; i < 4; i++) 457 for (i = j = 0; i < 4; i++)
454 if (analog->mask & (1 << i)) { 458 if (analog->mask & (1 << i)) {
@@ -461,8 +465,6 @@ static void analog_init_device(struct analog_port *port, struct analog *analog,
461 v = (x >> 3); 465 v = (x >> 3);
462 w = (x >> 3); 466 w = (x >> 3);
463 467
464 set_bit(t, analog->dev.absbit);
465
466 if ((i == 2 || i == 3) && (j == 2 || j == 3) && (z > (y >> 3))) 468 if ((i == 2 || i == 3) && (j == 2 || j == 3) && (z > (y >> 3)))
467 x = y; 469 x = y;
468 470
@@ -472,11 +474,7 @@ static void analog_init_device(struct analog_port *port, struct analog *analog,
472 w = (x >> 4); 474 w = (x >> 4);
473 } 475 }
474 476
475 analog->dev.absmax[t] = (x << 1) - v; 477 input_set_abs_params(input_dev, t, v, (x << 1) - v, port->fuzz, w);
476 analog->dev.absmin[t] = v;
477 analog->dev.absfuzz[t] = port->fuzz;
478 analog->dev.absflat[t] = w;
479
480 j++; 478 j++;
481 } 479 }
482 480
@@ -484,41 +482,30 @@ static void analog_init_device(struct analog_port *port, struct analog *analog,
484 if (analog->mask & analog_exts[i]) 482 if (analog->mask & analog_exts[i])
485 for (x = 0; x < 2; x++) { 483 for (x = 0; x < 2; x++) {
486 t = analog_hats[j++]; 484 t = analog_hats[j++];
487 set_bit(t, analog->dev.absbit); 485 input_set_abs_params(input_dev, t, -1, 1, 0, 0);
488 analog->dev.absmax[t] = 1;
489 analog->dev.absmin[t] = -1;
490 } 486 }
491 487
492 for (i = j = 0; i < 4; i++) 488 for (i = j = 0; i < 4; i++)
493 if (analog->mask & (0x10 << i)) 489 if (analog->mask & (0x10 << i))
494 set_bit(analog->buttons[j++], analog->dev.keybit); 490 set_bit(analog->buttons[j++], input_dev->keybit);
495 491
496 if (analog->mask & ANALOG_BTNS_CHF) 492 if (analog->mask & ANALOG_BTNS_CHF)
497 for (i = 0; i < 2; i++) 493 for (i = 0; i < 2; i++)
498 set_bit(analog->buttons[j++], analog->dev.keybit); 494 set_bit(analog->buttons[j++], input_dev->keybit);
499 495
500 if (analog->mask & ANALOG_HBTN_CHF) 496 if (analog->mask & ANALOG_HBTN_CHF)
501 for (i = 0; i < 4; i++) 497 for (i = 0; i < 4; i++)
502 set_bit(analog->buttons[j++], analog->dev.keybit); 498 set_bit(analog->buttons[j++], input_dev->keybit);
503 499
504 for (i = 0; i < 4; i++) 500 for (i = 0; i < 4; i++)
505 if (analog->mask & (ANALOG_BTN_TL << i)) 501 if (analog->mask & (ANALOG_BTN_TL << i))
506 set_bit(analog_pads[i], analog->dev.keybit); 502 set_bit(analog_pads[i], input_dev->keybit);
507 503
508 analog_decode(analog, port->axes, port->initial, port->buttons); 504 analog_decode(analog, port->axes, port->initial, port->buttons);
509 505
510 input_register_device(&analog->dev); 506 input_register_device(analog->dev);
511 507
512 printk(KERN_INFO "input: %s at %s", analog->name, port->gameport->phys); 508 return 0;
513
514 if (port->cooked)
515 printk(" [ADC port]\n");
516 else
517 printk(" [%s timer, %d %sHz clock, %d ns res]\n", TIME_NAME,
518 port->speed > 10000 ? (port->speed + 800) / 1000 : port->speed,
519 port->speed > 10000 ? "M" : "k",
520 port->speed > 10000 ? (port->loop * 1000) / (port->speed / 1000)
521 : (port->loop * 1000000) / port->speed);
522} 509}
523 510
524/* 511/*
@@ -659,37 +646,41 @@ static int analog_connect(struct gameport *gameport, struct gameport_driver *drv
659 return - ENOMEM; 646 return - ENOMEM;
660 647
661 err = analog_init_port(gameport, drv, port); 648 err = analog_init_port(gameport, drv, port);
662 if (err) { 649 if (err)
663 kfree(port); 650 goto fail1;
664 return err;
665 }
666 651
667 err = analog_init_masks(port); 652 err = analog_init_masks(port);
668 if (err) { 653 if (err)
669 gameport_close(gameport); 654 goto fail2;
670 gameport_set_drvdata(gameport, NULL);
671 kfree(port);
672 return err;
673 }
674 655
675 gameport_set_poll_handler(gameport, analog_poll); 656 gameport_set_poll_handler(gameport, analog_poll);
676 gameport_set_poll_interval(gameport, 10); 657 gameport_set_poll_interval(gameport, 10);
677 658
678 for (i = 0; i < 2; i++) 659 for (i = 0; i < 2; i++)
679 if (port->analog[i].mask) 660 if (port->analog[i].mask) {
680 analog_init_device(port, port->analog + i, i); 661 err = analog_init_device(port, port->analog + i, i);
662 if (err)
663 goto fail3;
664 }
681 665
682 return 0; 666 return 0;
667
668 fail3: while (--i >= 0)
669 input_unregister_device(port->analog[i].dev);
670 fail2: gameport_close(gameport);
671 fail1: gameport_set_drvdata(gameport, NULL);
672 kfree(port);
673 return err;
683} 674}
684 675
685static void analog_disconnect(struct gameport *gameport) 676static void analog_disconnect(struct gameport *gameport)
686{ 677{
687 int i;
688 struct analog_port *port = gameport_get_drvdata(gameport); 678 struct analog_port *port = gameport_get_drvdata(gameport);
679 int i;
689 680
690 for (i = 0; i < 2; i++) 681 for (i = 0; i < 2; i++)
691 if (port->analog[i].mask) 682 if (port->analog[i].mask)
692 input_unregister_device(&port->analog[i].dev); 683 input_unregister_device(port->analog[i].dev);
693 gameport_close(gameport); 684 gameport_close(gameport);
694 gameport_set_drvdata(gameport, NULL); 685 gameport_set_drvdata(gameport, NULL);
695 printk(KERN_INFO "analog.c: %d out of %d reads (%d%%) on %s failed\n", 686 printk(KERN_INFO "analog.c: %d out of %d reads (%d%%) on %s failed\n",
diff --git a/drivers/input/joystick/cobra.c b/drivers/input/joystick/cobra.c
index 0b2e9fa26579..1909f7ef340c 100644
--- a/drivers/input/joystick/cobra.c
+++ b/drivers/input/joystick/cobra.c
@@ -34,6 +34,7 @@
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/gameport.h> 35#include <linux/gameport.h>
36#include <linux/input.h> 36#include <linux/input.h>
37#include <linux/jiffies.h>
37 38
38#define DRIVER_DESC "Creative Labs Blaster GamePad Cobra driver" 39#define DRIVER_DESC "Creative Labs Blaster GamePad Cobra driver"
39 40
@@ -44,13 +45,11 @@ MODULE_LICENSE("GPL");
44#define COBRA_MAX_STROBE 45 /* 45 us max wait for first strobe */ 45#define COBRA_MAX_STROBE 45 /* 45 us max wait for first strobe */
45#define COBRA_LENGTH 36 46#define COBRA_LENGTH 36
46 47
47static char* cobra_name = "Creative Labs Blaster GamePad Cobra";
48
49static int cobra_btn[] = { BTN_START, BTN_SELECT, BTN_TL, BTN_TR, BTN_X, BTN_Y, BTN_Z, BTN_A, BTN_B, BTN_C, BTN_TL2, BTN_TR2, 0 }; 48static int cobra_btn[] = { BTN_START, BTN_SELECT, BTN_TL, BTN_TR, BTN_X, BTN_Y, BTN_Z, BTN_A, BTN_B, BTN_C, BTN_TL2, BTN_TR2, 0 };
50 49
51struct cobra { 50struct cobra {
52 struct gameport *gameport; 51 struct gameport *gameport;
53 struct input_dev dev[2]; 52 struct input_dev *dev[2];
54 int reads; 53 int reads;
55 int bads; 54 int bads;
56 unsigned char exists; 55 unsigned char exists;
@@ -128,7 +127,7 @@ static void cobra_poll(struct gameport *gameport)
128 for (i = 0; i < 2; i++) 127 for (i = 0; i < 2; i++)
129 if (cobra->exists & r & (1 << i)) { 128 if (cobra->exists & r & (1 << i)) {
130 129
131 dev = cobra->dev + i; 130 dev = cobra->dev[i];
132 131
133 input_report_abs(dev, ABS_X, ((data[i] >> 4) & 1) - ((data[i] >> 3) & 1)); 132 input_report_abs(dev, ABS_X, ((data[i] >> 4) & 1) - ((data[i] >> 3) & 1));
134 input_report_abs(dev, ABS_Y, ((data[i] >> 2) & 1) - ((data[i] >> 1) & 1)); 133 input_report_abs(dev, ABS_Y, ((data[i] >> 2) & 1) - ((data[i] >> 1) & 1));
@@ -159,11 +158,13 @@ static void cobra_close(struct input_dev *dev)
159static int cobra_connect(struct gameport *gameport, struct gameport_driver *drv) 158static int cobra_connect(struct gameport *gameport, struct gameport_driver *drv)
160{ 159{
161 struct cobra *cobra; 160 struct cobra *cobra;
161 struct input_dev *input_dev;
162 unsigned int data[2]; 162 unsigned int data[2];
163 int i, j; 163 int i, j;
164 int err; 164 int err;
165 165
166 if (!(cobra = kzalloc(sizeof(struct cobra), GFP_KERNEL))) 166 cobra = kzalloc(sizeof(struct cobra), GFP_KERNEL);
167 if (!cobra)
167 return -ENOMEM; 168 return -ENOMEM;
168 169
169 cobra->gameport = gameport; 170 cobra->gameport = gameport;
@@ -191,38 +192,46 @@ static int cobra_connect(struct gameport *gameport, struct gameport_driver *drv)
191 gameport_set_poll_handler(gameport, cobra_poll); 192 gameport_set_poll_handler(gameport, cobra_poll);
192 gameport_set_poll_interval(gameport, 20); 193 gameport_set_poll_interval(gameport, 20);
193 194
194 for (i = 0; i < 2; i++) 195 for (i = 0; i < 2; i++) {
195 if ((cobra->exists >> i) & 1) { 196 if (~(cobra->exists >> i) & 1)
196 197 continue;
197 sprintf(cobra->phys[i], "%s/input%d", gameport->phys, i);
198 198
199 cobra->dev[i].private = cobra; 199 cobra->dev[i] = input_dev = input_allocate_device();
200 cobra->dev[i].open = cobra_open; 200 if (!input_dev) {
201 cobra->dev[i].close = cobra_close; 201 err = -ENOMEM;
202 goto fail3;
203 }
202 204
203 cobra->dev[i].name = cobra_name; 205 sprintf(cobra->phys[i], "%s/input%d", gameport->phys, i);
204 cobra->dev[i].phys = cobra->phys[i];
205 cobra->dev[i].id.bustype = BUS_GAMEPORT;
206 cobra->dev[i].id.vendor = GAMEPORT_ID_VENDOR_CREATIVE;
207 cobra->dev[i].id.product = 0x0008;
208 cobra->dev[i].id.version = 0x0100;
209 206
210 cobra->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 207 input_dev->name = "Creative Labs Blaster GamePad Cobra";
208 input_dev->phys = cobra->phys[i];
209 input_dev->id.bustype = BUS_GAMEPORT;
210 input_dev->id.vendor = GAMEPORT_ID_VENDOR_CREATIVE;
211 input_dev->id.product = 0x0008;
212 input_dev->id.version = 0x0100;
213 input_dev->cdev.dev = &gameport->dev;
214 input_dev->private = cobra;
211 215
212 input_set_abs_params(&cobra->dev[i], ABS_X, -1, 1, 0, 0); 216 input_dev->open = cobra_open;
213 input_set_abs_params(&cobra->dev[i], ABS_Y, -1, 1, 0, 0); 217 input_dev->close = cobra_close;
214 218
215 for (j = 0; cobra_btn[j]; j++) 219 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
216 set_bit(cobra_btn[j], cobra->dev[i].keybit); 220 input_set_abs_params(input_dev, ABS_X, -1, 1, 0, 0);
221 input_set_abs_params(input_dev, ABS_Y, -1, 1, 0, 0);
222 for (j = 0; cobra_btn[j]; j++)
223 set_bit(cobra_btn[j], input_dev->keybit);
217 224
218 input_register_device(&cobra->dev[i]); 225 input_register_device(cobra->dev[i]);
219 printk(KERN_INFO "input: %s on %s\n", cobra_name, gameport->phys); 226 }
220 }
221 227
222 return 0; 228 return 0;
223 229
224fail2: gameport_close(gameport); 230 fail3: for (i = 0; i < 2; i++)
225fail1: gameport_set_drvdata(gameport, NULL); 231 if (cobra->dev[i])
232 input_unregister_device(cobra->dev[i]);
233 fail2: gameport_close(gameport);
234 fail1: gameport_set_drvdata(gameport, NULL);
226 kfree(cobra); 235 kfree(cobra);
227 return err; 236 return err;
228} 237}
@@ -234,7 +243,7 @@ static void cobra_disconnect(struct gameport *gameport)
234 243
235 for (i = 0; i < 2; i++) 244 for (i = 0; i < 2; i++)
236 if ((cobra->exists >> i) & 1) 245 if ((cobra->exists >> i) & 1)
237 input_unregister_device(cobra->dev + i); 246 input_unregister_device(cobra->dev[i]);
238 gameport_close(gameport); 247 gameport_close(gameport);
239 gameport_set_drvdata(gameport, NULL); 248 gameport_set_drvdata(gameport, NULL);
240 kfree(cobra); 249 kfree(cobra);
diff --git a/drivers/input/joystick/db9.c b/drivers/input/joystick/db9.c
index 2a3e4bb2da50..499344c72756 100644
--- a/drivers/input/joystick/db9.c
+++ b/drivers/input/joystick/db9.c
@@ -43,25 +43,28 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
43MODULE_DESCRIPTION("Atari, Amstrad, Commodore, Amiga, Sega, etc. joystick driver"); 43MODULE_DESCRIPTION("Atari, Amstrad, Commodore, Amiga, Sega, etc. joystick driver");
44MODULE_LICENSE("GPL"); 44MODULE_LICENSE("GPL");
45 45
46static int db9[] __initdata = { -1, 0 }; 46struct db9_config {
47static int db9_nargs __initdata = 0; 47 int args[2];
48module_param_array_named(dev, db9, int, &db9_nargs, 0); 48 int nargs;
49MODULE_PARM_DESC(dev, "Describes first attached device (<parport#>,<type>)"); 49};
50 50
51static int db9_2[] __initdata = { -1, 0 }; 51#define DB9_MAX_PORTS 3
52static int db9_nargs_2 __initdata = 0; 52static struct db9_config db9[DB9_MAX_PORTS] __initdata;
53module_param_array_named(dev2, db9_2, int, &db9_nargs_2, 0);
54MODULE_PARM_DESC(dev2, "Describes second attached device (<parport#>,<type>)");
55 53
56static int db9_3[] __initdata = { -1, 0 }; 54module_param_array_named(dev, db9[0].args, int, &db9[0].nargs, 0);
57static int db9_nargs_3 __initdata = 0; 55MODULE_PARM_DESC(dev, "Describes first attached device (<parport#>,<type>)");
58module_param_array_named(dev3, db9_3, int, &db9_nargs_3, 0); 56module_param_array_named(dev2, db9[1].args, int, &db9[0].nargs, 0);
57MODULE_PARM_DESC(dev2, "Describes second attached device (<parport#>,<type>)");
58module_param_array_named(dev3, db9[2].args, int, &db9[2].nargs, 0);
59MODULE_PARM_DESC(dev3, "Describes third attached device (<parport#>,<type>)"); 59MODULE_PARM_DESC(dev3, "Describes third attached device (<parport#>,<type>)");
60 60
61__obsolete_setup("db9="); 61__obsolete_setup("db9=");
62__obsolete_setup("db9_2="); 62__obsolete_setup("db9_2=");
63__obsolete_setup("db9_3="); 63__obsolete_setup("db9_3=");
64 64
65#define DB9_ARG_PARPORT 0
66#define DB9_ARG_MODE 1
67
65#define DB9_MULTI_STICK 0x01 68#define DB9_MULTI_STICK 0x01
66#define DB9_MULTI2_STICK 0x02 69#define DB9_MULTI2_STICK 0x02
67#define DB9_GENESIS_PAD 0x03 70#define DB9_GENESIS_PAD 0x03
@@ -87,40 +90,53 @@ __obsolete_setup("db9_3=");
87#define DB9_NORMAL 0x0a 90#define DB9_NORMAL 0x0a
88#define DB9_NOSELECT 0x08 91#define DB9_NOSELECT 0x08
89 92
90#define DB9_MAX_DEVICES 2
91
92#define DB9_GENESIS6_DELAY 14 93#define DB9_GENESIS6_DELAY 14
93#define DB9_REFRESH_TIME HZ/100 94#define DB9_REFRESH_TIME HZ/100
94 95
96#define DB9_MAX_DEVICES 2
97
98struct db9_mode_data {
99 const char *name;
100 const short *buttons;
101 int n_buttons;
102 int n_pads;
103 int n_axis;
104 int bidirectional;
105 int reverse;
106};
107
95struct db9 { 108struct db9 {
96 struct input_dev dev[DB9_MAX_DEVICES]; 109 struct input_dev *dev[DB9_MAX_DEVICES];
97 struct timer_list timer; 110 struct timer_list timer;
98 struct pardevice *pd; 111 struct pardevice *pd;
99 int mode; 112 int mode;
100 int used; 113 int used;
101 struct semaphore sem; 114 struct semaphore sem;
102 char phys[2][32]; 115 char phys[DB9_MAX_DEVICES][32];
103}; 116};
104 117
105static struct db9 *db9_base[3]; 118static struct db9 *db9_base[3];
106 119
107static short db9_multi_btn[] = { BTN_TRIGGER, BTN_THUMB }; 120static const short db9_multi_btn[] = { BTN_TRIGGER, BTN_THUMB };
108static short db9_genesis_btn[] = { BTN_START, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_MODE }; 121static const short db9_genesis_btn[] = { BTN_START, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_MODE };
109static short db9_cd32_btn[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_START }; 122static const short db9_cd32_btn[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_START };
110
111static char db9_buttons[DB9_MAX_PAD] = { 0, 1, 2, 4, 0, 6, 8, 9, 1, 1, 7, 9, 9 };
112static short *db9_btn[DB9_MAX_PAD] = { NULL, db9_multi_btn, db9_multi_btn, db9_genesis_btn, NULL, db9_genesis_btn,
113 db9_genesis_btn, db9_cd32_btn, db9_multi_btn, db9_multi_btn, db9_cd32_btn,
114 db9_cd32_btn, db9_cd32_btn };
115static char *db9_name[DB9_MAX_PAD] = { NULL, "Multisystem joystick", "Multisystem joystick (2 fire)", "Genesis pad",
116 NULL, "Genesis 5 pad", "Genesis 6 pad", "Saturn pad", "Multisystem (0.8.0.2) joystick",
117 "Multisystem (0.8.0.2-dual) joystick", "Amiga CD-32 pad", "Saturn dpp", "Saturn dpp dual" };
118
119static const int db9_max_pads[DB9_MAX_PAD] = { 0, 1, 1, 1, 0, 1, 1, 6, 1, 2, 1, 6, 12 };
120static const int db9_num_axis[DB9_MAX_PAD] = { 0, 2, 2, 2, 0, 2, 2, 7, 2, 2, 2 ,7, 7 };
121static const short db9_abs[] = { ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_RZ, ABS_Z, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y }; 123static const short db9_abs[] = { ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_RZ, ABS_Z, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y };
122static const int db9_bidirectional[DB9_MAX_PAD] = { 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0 }; 124
123static const int db9_reverse[DB9_MAX_PAD] = { 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0 }; 125static const struct db9_mode_data db9_modes[] = {
126 { NULL, NULL, 0, 0, 0, 0, 0 },
127 { "Multisystem joystick", db9_multi_btn, 1, 1, 2, 1, 1 },
128 { "Multisystem joystick (2 fire)", db9_multi_btn, 2, 1, 2, 1, 1 },
129 { "Genesis pad", db9_genesis_btn, 4, 1, 2, 1, 1 },
130 { NULL, NULL, 0, 0, 0, 0, 0 },
131 { "Genesis 5 pad", db9_genesis_btn, 6, 1, 2, 1, 1 },
132 { "Genesis 6 pad", db9_genesis_btn, 8, 1, 2, 1, 1 },
133 { "Saturn pad", db9_cd32_btn, 9, 6, 7, 0, 1 },
134 { "Multisystem (0.8.0.2) joystick", db9_multi_btn, 1, 1, 2, 1, 1 },
135 { "Multisystem (0.8.0.2-dual) joystick", db9_multi_btn, 1, 2, 2, 1, 1 },
136 { "Amiga CD-32 pad", db9_cd32_btn, 7, 1, 2, 1, 1 },
137 { "Saturn dpp", db9_cd32_btn, 9, 6, 7, 0, 0 },
138 { "Saturn dpp dual", db9_cd32_btn, 9, 12, 7, 0, 0 },
139};
124 140
125/* 141/*
126 * Saturn controllers 142 * Saturn controllers
@@ -342,7 +358,7 @@ static int db9_saturn(int mode, struct parport *port, struct input_dev *dev)
342 default: 358 default:
343 return -1; 359 return -1;
344 } 360 }
345 max_pads = min(db9_max_pads[mode], DB9_MAX_DEVICES); 361 max_pads = min(db9_modes[mode].n_pads, DB9_MAX_DEVICES);
346 for (tmp = 0, i = 0; i < n; i++) { 362 for (tmp = 0, i = 0; i < n; i++) {
347 id = db9_saturn_read_packet(port, data, type + i, 1); 363 id = db9_saturn_read_packet(port, data, type + i, 1);
348 tmp = db9_saturn_report(id, data, dev, tmp, max_pads); 364 tmp = db9_saturn_report(id, data, dev, tmp, max_pads);
@@ -354,17 +370,18 @@ static void db9_timer(unsigned long private)
354{ 370{
355 struct db9 *db9 = (void *) private; 371 struct db9 *db9 = (void *) private;
356 struct parport *port = db9->pd->port; 372 struct parport *port = db9->pd->port;
357 struct input_dev *dev = db9->dev; 373 struct input_dev *dev = db9->dev[0];
374 struct input_dev *dev2 = db9->dev[1];
358 int data, i; 375 int data, i;
359 376
360 switch(db9->mode) { 377 switch (db9->mode) {
361 case DB9_MULTI_0802_2: 378 case DB9_MULTI_0802_2:
362 379
363 data = parport_read_data(port) >> 3; 380 data = parport_read_data(port) >> 3;
364 381
365 input_report_abs(dev + 1, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); 382 input_report_abs(dev2, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1));
366 input_report_abs(dev + 1, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); 383 input_report_abs(dev2, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1));
367 input_report_key(dev + 1, BTN_TRIGGER, ~data & DB9_FIRE1); 384 input_report_key(dev2, BTN_TRIGGER, ~data & DB9_FIRE1);
368 385
369 case DB9_MULTI_0802: 386 case DB9_MULTI_0802:
370 387
@@ -405,7 +422,7 @@ static void db9_timer(unsigned long private)
405 input_report_key(dev, BTN_C, ~data & DB9_FIRE2); 422 input_report_key(dev, BTN_C, ~data & DB9_FIRE2);
406 423
407 parport_write_control(port, DB9_NORMAL); 424 parport_write_control(port, DB9_NORMAL);
408 data=parport_read_data(port); 425 data = parport_read_data(port);
409 426
410 input_report_key(dev, BTN_A, ~data & DB9_FIRE1); 427 input_report_key(dev, BTN_A, ~data & DB9_FIRE1);
411 input_report_key(dev, BTN_START, ~data & DB9_FIRE2); 428 input_report_key(dev, BTN_START, ~data & DB9_FIRE2);
@@ -414,7 +431,7 @@ static void db9_timer(unsigned long private)
414 case DB9_GENESIS5_PAD: 431 case DB9_GENESIS5_PAD:
415 432
416 parport_write_control(port, DB9_NOSELECT); 433 parport_write_control(port, DB9_NOSELECT);
417 data=parport_read_data(port); 434 data = parport_read_data(port);
418 435
419 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); 436 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1));
420 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); 437 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1));
@@ -422,7 +439,7 @@ static void db9_timer(unsigned long private)
422 input_report_key(dev, BTN_C, ~data & DB9_FIRE2); 439 input_report_key(dev, BTN_C, ~data & DB9_FIRE2);
423 440
424 parport_write_control(port, DB9_NORMAL); 441 parport_write_control(port, DB9_NORMAL);
425 data=parport_read_data(port); 442 data = parport_read_data(port);
426 443
427 input_report_key(dev, BTN_A, ~data & DB9_FIRE1); 444 input_report_key(dev, BTN_A, ~data & DB9_FIRE1);
428 input_report_key(dev, BTN_X, ~data & DB9_FIRE2); 445 input_report_key(dev, BTN_X, ~data & DB9_FIRE2);
@@ -434,7 +451,7 @@ static void db9_timer(unsigned long private)
434 451
435 parport_write_control(port, DB9_NOSELECT); /* 1 */ 452 parport_write_control(port, DB9_NOSELECT); /* 1 */
436 udelay(DB9_GENESIS6_DELAY); 453 udelay(DB9_GENESIS6_DELAY);
437 data=parport_read_data(port); 454 data = parport_read_data(port);
438 455
439 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); 456 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1));
440 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); 457 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1));
@@ -443,7 +460,7 @@ static void db9_timer(unsigned long private)
443 460
444 parport_write_control(port, DB9_NORMAL); 461 parport_write_control(port, DB9_NORMAL);
445 udelay(DB9_GENESIS6_DELAY); 462 udelay(DB9_GENESIS6_DELAY);
446 data=parport_read_data(port); 463 data = parport_read_data(port);
447 464
448 input_report_key(dev, BTN_A, ~data & DB9_FIRE1); 465 input_report_key(dev, BTN_A, ~data & DB9_FIRE1);
449 input_report_key(dev, BTN_START, ~data & DB9_FIRE2); 466 input_report_key(dev, BTN_START, ~data & DB9_FIRE2);
@@ -477,7 +494,7 @@ static void db9_timer(unsigned long private)
477 494
478 case DB9_CD32_PAD: 495 case DB9_CD32_PAD:
479 496
480 data=parport_read_data(port); 497 data = parport_read_data(port);
481 498
482 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); 499 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1));
483 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); 500 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1));
@@ -489,7 +506,7 @@ static void db9_timer(unsigned long private)
489 parport_write_control(port, 0x02); 506 parport_write_control(port, 0x02);
490 parport_write_control(port, 0x0a); 507 parport_write_control(port, 0x0a);
491 input_report_key(dev, db9_cd32_btn[i], ~data & DB9_FIRE2); 508 input_report_key(dev, db9_cd32_btn[i], ~data & DB9_FIRE2);
492 } 509 }
493 510
494 parport_write_control(port, 0x00); 511 parport_write_control(port, 0x00);
495 break; 512 break;
@@ -513,7 +530,7 @@ static int db9_open(struct input_dev *dev)
513 if (!db9->used++) { 530 if (!db9->used++) {
514 parport_claim(db9->pd); 531 parport_claim(db9->pd);
515 parport_write_data(port, 0xff); 532 parport_write_data(port, 0xff);
516 if (db9_reverse[db9->mode]) { 533 if (db9_modes[db9->mode].reverse) {
517 parport_data_reverse(port); 534 parport_data_reverse(port);
518 parport_write_control(port, DB9_NORMAL); 535 parport_write_control(port, DB9_NORMAL);
519 } 536 }
@@ -539,117 +556,160 @@ static void db9_close(struct input_dev *dev)
539 up(&db9->sem); 556 up(&db9->sem);
540} 557}
541 558
542static struct db9 __init *db9_probe(int *config, int nargs) 559static struct db9 __init *db9_probe(int parport, int mode)
543{ 560{
544 struct db9 *db9; 561 struct db9 *db9;
562 const struct db9_mode_data *db9_mode;
545 struct parport *pp; 563 struct parport *pp;
564 struct pardevice *pd;
565 struct input_dev *input_dev;
546 int i, j; 566 int i, j;
567 int err;
547 568
548 if (config[0] < 0) 569 if (mode < 1 || mode >= DB9_MAX_PAD || !db9_modes[mode].n_buttons) {
549 return NULL; 570 printk(KERN_ERR "db9.c: Bad device type %d\n", mode);
550 571 err = -EINVAL;
551 if (nargs < 2) { 572 goto err_out;
552 printk(KERN_ERR "db9.c: Device type must be specified.\n");
553 return NULL;
554 } 573 }
555 574
556 if (config[1] < 1 || config[1] >= DB9_MAX_PAD || !db9_buttons[config[1]]) { 575 db9_mode = &db9_modes[mode];
557 printk(KERN_ERR "db9.c: bad config\n");
558 return NULL;
559 }
560 576
561 pp = parport_find_number(config[0]); 577 pp = parport_find_number(parport);
562 if (!pp) { 578 if (!pp) {
563 printk(KERN_ERR "db9.c: no such parport\n"); 579 printk(KERN_ERR "db9.c: no such parport\n");
564 return NULL; 580 err = -ENODEV;
581 goto err_out;
565 } 582 }
566 583
567 if (db9_bidirectional[config[1]]) { 584 if (db9_mode[mode].bidirectional && !(pp->modes & PARPORT_MODE_TRISTATE)) {
568 if (!(pp->modes & PARPORT_MODE_TRISTATE)) { 585 printk(KERN_ERR "db9.c: specified parport is not bidirectional\n");
569 printk(KERN_ERR "db9.c: specified parport is not bidirectional\n"); 586 err = -EINVAL;
570 parport_put_port(pp); 587 goto err_put_pp;
571 return NULL; 588 }
572 } 589
590 pd = parport_register_device(pp, "db9", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
591 if (!pd) {
592 printk(KERN_ERR "db9.c: parport busy already - lp.o loaded?\n");
593 err = -EBUSY;
594 goto err_put_pp;
573 } 595 }
574 596
575 if (!(db9 = kzalloc(sizeof(struct db9), GFP_KERNEL))) { 597 db9 = kzalloc(sizeof(struct db9), GFP_KERNEL);
576 parport_put_port(pp); 598 if (!db9) {
577 return NULL; 599 printk(KERN_ERR "db9.c: Not enough memory\n");
600 err = -ENOMEM;
601 goto err_unreg_pardev;
578 } 602 }
579 603
580 init_MUTEX(&db9->sem); 604 init_MUTEX(&db9->sem);
581 db9->mode = config[1]; 605 db9->pd = pd;
606 db9->mode = mode;
582 init_timer(&db9->timer); 607 init_timer(&db9->timer);
583 db9->timer.data = (long) db9; 608 db9->timer.data = (long) db9;
584 db9->timer.function = db9_timer; 609 db9->timer.function = db9_timer;
585 610
586 db9->pd = parport_register_device(pp, "db9", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL); 611 for (i = 0; i < (min(db9_mode->n_pads, DB9_MAX_DEVICES)); i++) {
587 parport_put_port(pp);
588
589 if (!db9->pd) {
590 printk(KERN_ERR "db9.c: parport busy already - lp.o loaded?\n");
591 kfree(db9);
592 return NULL;
593 }
594 612
595 for (i = 0; i < (min(db9_max_pads[db9->mode], DB9_MAX_DEVICES)); i++) { 613 db9->dev[i] = input_dev = input_allocate_device();
614 if (!input_dev) {
615 printk(KERN_ERR "db9.c: Not enough memory for input device\n");
616 err = -ENOMEM;
617 goto err_free_devs;
618 }
596 619
597 sprintf(db9->phys[i], "%s/input%d", db9->pd->port->name, i); 620 sprintf(db9->phys[i], "%s/input%d", db9->pd->port->name, i);
598 621
599 db9->dev[i].private = db9; 622 input_dev->name = db9_mode->name;
600 db9->dev[i].open = db9_open; 623 input_dev->phys = db9->phys[i];
601 db9->dev[i].close = db9_close; 624 input_dev->id.bustype = BUS_PARPORT;
602 625 input_dev->id.vendor = 0x0002;
603 db9->dev[i].name = db9_name[db9->mode]; 626 input_dev->id.product = mode;
604 db9->dev[i].phys = db9->phys[i]; 627 input_dev->id.version = 0x0100;
605 db9->dev[i].id.bustype = BUS_PARPORT; 628 input_dev->private = db9;
606 db9->dev[i].id.vendor = 0x0002; 629
607 db9->dev[i].id.product = config[1]; 630 input_dev->open = db9_open;
608 db9->dev[i].id.version = 0x0100; 631 input_dev->close = db9_close;
609 632
610 db9->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 633 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
611 for (j = 0; j < db9_buttons[db9->mode]; j++) 634 for (j = 0; j < db9_mode->n_buttons; j++)
612 set_bit(db9_btn[db9->mode][j], db9->dev[i].keybit); 635 set_bit(db9_mode->buttons[j], input_dev->keybit);
613 for (j = 0; j < db9_num_axis[db9->mode]; j++) { 636 for (j = 0; j < db9_mode->n_axis; j++) {
614 set_bit(db9_abs[j], db9->dev[i].absbit); 637 if (j < 2)
615 if (j < 2) { 638 input_set_abs_params(input_dev, db9_abs[j], -1, 1, 0, 0);
616 db9->dev[i].absmin[db9_abs[j]] = -1; 639 else
617 db9->dev[i].absmax[db9_abs[j]] = 1; 640 input_set_abs_params(input_dev, db9_abs[j], 1, 255, 0, 0);
618 } else {
619 db9->dev[i].absmin[db9_abs[j]] = 1;
620 db9->dev[i].absmax[db9_abs[j]] = 255;
621 db9->dev[i].absflat[db9_abs[j]] = 0;
622 }
623 } 641 }
624 input_register_device(db9->dev + i); 642
625 printk(KERN_INFO "input: %s on %s\n", db9->dev[i].name, db9->pd->port->name); 643 input_register_device(input_dev);
626 } 644 }
627 645
646 parport_put_port(pp);
628 return db9; 647 return db9;
648
649 err_free_devs:
650 while (--i >= 0)
651 input_unregister_device(db9->dev[i]);
652 kfree(db9);
653 err_unreg_pardev:
654 parport_unregister_device(pd);
655 err_put_pp:
656 parport_put_port(pp);
657 err_out:
658 return ERR_PTR(err);
659}
660
661static void __exit db9_remove(struct db9 *db9)
662{
663 int i;
664
665 for (i = 0; i < min(db9_modes[db9->mode].n_pads, DB9_MAX_DEVICES); i++)
666 input_unregister_device(db9->dev[i]);
667 parport_unregister_device(db9->pd);
668 kfree(db9);
629} 669}
630 670
631static int __init db9_init(void) 671static int __init db9_init(void)
632{ 672{
633 db9_base[0] = db9_probe(db9, db9_nargs); 673 int i;
634 db9_base[1] = db9_probe(db9_2, db9_nargs_2); 674 int have_dev = 0;
635 db9_base[2] = db9_probe(db9_3, db9_nargs_3); 675 int err = 0;
676
677 for (i = 0; i < DB9_MAX_PORTS; i++) {
678 if (db9[i].nargs == 0 || db9[i].args[DB9_ARG_PARPORT] < 0)
679 continue;
680
681 if (db9[i].nargs < 2) {
682 printk(KERN_ERR "db9.c: Device type must be specified.\n");
683 err = -EINVAL;
684 break;
685 }
686
687 db9_base[i] = db9_probe(db9[i].args[DB9_ARG_PARPORT],
688 db9[i].args[DB9_ARG_MODE]);
689 if (IS_ERR(db9_base[i])) {
690 err = PTR_ERR(db9_base[i]);
691 break;
692 }
693
694 have_dev = 1;
695 }
636 696
637 if (db9_base[0] || db9_base[1] || db9_base[2]) 697 if (err) {
638 return 0; 698 while (--i >= 0)
699 db9_remove(db9_base[i]);
700 return err;
701 }
639 702
640 return -ENODEV; 703 return have_dev ? 0 : -ENODEV;
641} 704}
642 705
643static void __exit db9_exit(void) 706static void __exit db9_exit(void)
644{ 707{
645 int i, j; 708 int i;
646 709
647 for (i = 0; i < 3; i++) 710 for (i = 0; i < DB9_MAX_PORTS; i++)
648 if (db9_base[i]) { 711 if (db9_base[i])
649 for (j = 0; j < min(db9_max_pads[db9_base[i]->mode], DB9_MAX_DEVICES); j++) 712 db9_remove(db9_base[i]);
650 input_unregister_device(db9_base[i]->dev + j);
651 parport_unregister_device(db9_base[i]->pd);
652 }
653} 713}
654 714
655module_init(db9_init); 715module_init(db9_init);
diff --git a/drivers/input/joystick/gamecon.c b/drivers/input/joystick/gamecon.c
index 5427bf9fc862..7df2d82f2c83 100644
--- a/drivers/input/joystick/gamecon.c
+++ b/drivers/input/joystick/gamecon.c
@@ -41,20 +41,22 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
41MODULE_DESCRIPTION("NES, SNES, N64, MultiSystem, PSX gamepad driver"); 41MODULE_DESCRIPTION("NES, SNES, N64, MultiSystem, PSX gamepad driver");
42MODULE_LICENSE("GPL"); 42MODULE_LICENSE("GPL");
43 43
44static int gc[] __initdata = { -1, 0, 0, 0, 0, 0 }; 44#define GC_MAX_PORTS 3
45static int gc_nargs __initdata = 0; 45#define GC_MAX_DEVICES 5
46module_param_array_named(map, gc, int, &gc_nargs, 0);
47MODULE_PARM_DESC(map, "Describers first set of devices (<parport#>,<pad1>,<pad2>,..<pad5>)");
48 46
49static int gc_2[] __initdata = { -1, 0, 0, 0, 0, 0 }; 47struct gc_config {
50static int gc_nargs_2 __initdata = 0; 48 int args[GC_MAX_DEVICES + 1];
51module_param_array_named(map2, gc_2, int, &gc_nargs_2, 0); 49 int nargs;
52MODULE_PARM_DESC(map2, "Describers second set of devices"); 50};
51
52static struct gc_config gc[GC_MAX_PORTS] __initdata;
53 53
54static int gc_3[] __initdata = { -1, 0, 0, 0, 0, 0 }; 54module_param_array_named(map, gc[0].args, int, &gc[0].nargs, 0);
55static int gc_nargs_3 __initdata = 0; 55MODULE_PARM_DESC(map, "Describes first set of devices (<parport#>,<pad1>,<pad2>,..<pad5>)");
56module_param_array_named(map3, gc_3, int, &gc_nargs_3, 0); 56module_param_array_named(map2, gc[1].args, int, &gc[1].nargs, 0);
57MODULE_PARM_DESC(map3, "Describers third set of devices"); 57MODULE_PARM_DESC(map2, "Describes second set of devices");
58module_param_array_named(map3, gc[2].args, int, &gc[2].nargs, 0);
59MODULE_PARM_DESC(map3, "Describes third set of devices");
58 60
59__obsolete_setup("gc="); 61__obsolete_setup("gc=");
60__obsolete_setup("gc_2="); 62__obsolete_setup("gc_2=");
@@ -77,12 +79,12 @@ __obsolete_setup("gc_3=");
77 79
78struct gc { 80struct gc {
79 struct pardevice *pd; 81 struct pardevice *pd;
80 struct input_dev dev[5]; 82 struct input_dev *dev[GC_MAX_DEVICES];
81 struct timer_list timer; 83 struct timer_list timer;
82 unsigned char pads[GC_MAX + 1]; 84 unsigned char pads[GC_MAX + 1];
83 int used; 85 int used;
84 struct semaphore sem; 86 struct semaphore sem;
85 char phys[5][32]; 87 char phys[GC_MAX_DEVICES][32];
86}; 88};
87 89
88static struct gc *gc_base[3]; 90static struct gc *gc_base[3];
@@ -330,7 +332,6 @@ static void gc_psx_read_packet(struct gc *gc, unsigned char data[5][GC_PSX_BYTES
330static void gc_timer(unsigned long private) 332static void gc_timer(unsigned long private)
331{ 333{
332 struct gc *gc = (void *) private; 334 struct gc *gc = (void *) private;
333 struct input_dev *dev = gc->dev;
334 unsigned char data[GC_MAX_LENGTH]; 335 unsigned char data[GC_MAX_LENGTH];
335 unsigned char data_psx[5][GC_PSX_BYTES]; 336 unsigned char data_psx[5][GC_PSX_BYTES];
336 int i, j, s; 337 int i, j, s;
@@ -357,16 +358,16 @@ static void gc_timer(unsigned long private)
357 if (data[31 - j] & s) axes[1] |= 1 << j; 358 if (data[31 - j] & s) axes[1] |= 1 << j;
358 } 359 }
359 360
360 input_report_abs(dev + i, ABS_X, axes[0]); 361 input_report_abs(gc->dev[i], ABS_X, axes[0]);
361 input_report_abs(dev + i, ABS_Y, -axes[1]); 362 input_report_abs(gc->dev[i], ABS_Y, -axes[1]);
362 363
363 input_report_abs(dev + i, ABS_HAT0X, !(s & data[6]) - !(s & data[7])); 364 input_report_abs(gc->dev[i], ABS_HAT0X, !(s & data[6]) - !(s & data[7]));
364 input_report_abs(dev + i, ABS_HAT0Y, !(s & data[4]) - !(s & data[5])); 365 input_report_abs(gc->dev[i], ABS_HAT0Y, !(s & data[4]) - !(s & data[5]));
365 366
366 for (j = 0; j < 10; j++) 367 for (j = 0; j < 10; j++)
367 input_report_key(dev + i, gc_n64_btn[j], s & data[gc_n64_bytes[j]]); 368 input_report_key(gc->dev[i], gc_n64_btn[j], s & data[gc_n64_bytes[j]]);
368 369
369 input_sync(dev + i); 370 input_sync(gc->dev[i]);
370 } 371 }
371 } 372 }
372 } 373 }
@@ -384,19 +385,19 @@ static void gc_timer(unsigned long private)
384 s = gc_status_bit[i]; 385 s = gc_status_bit[i];
385 386
386 if (s & (gc->pads[GC_NES] | gc->pads[GC_SNES])) { 387 if (s & (gc->pads[GC_NES] | gc->pads[GC_SNES])) {
387 input_report_abs(dev + i, ABS_X, !(s & data[6]) - !(s & data[7])); 388 input_report_abs(gc->dev[i], ABS_X, !(s & data[6]) - !(s & data[7]));
388 input_report_abs(dev + i, ABS_Y, !(s & data[4]) - !(s & data[5])); 389 input_report_abs(gc->dev[i], ABS_Y, !(s & data[4]) - !(s & data[5]));
389 } 390 }
390 391
391 if (s & gc->pads[GC_NES]) 392 if (s & gc->pads[GC_NES])
392 for (j = 0; j < 4; j++) 393 for (j = 0; j < 4; j++)
393 input_report_key(dev + i, gc_snes_btn[j], s & data[gc_nes_bytes[j]]); 394 input_report_key(gc->dev[i], gc_snes_btn[j], s & data[gc_nes_bytes[j]]);
394 395
395 if (s & gc->pads[GC_SNES]) 396 if (s & gc->pads[GC_SNES])
396 for (j = 0; j < 8; j++) 397 for (j = 0; j < 8; j++)
397 input_report_key(dev + i, gc_snes_btn[j], s & data[gc_snes_bytes[j]]); 398 input_report_key(gc->dev[i], gc_snes_btn[j], s & data[gc_snes_bytes[j]]);
398 399
399 input_sync(dev + i); 400 input_sync(gc->dev[i]);
400 } 401 }
401 } 402 }
402 403
@@ -413,15 +414,15 @@ static void gc_timer(unsigned long private)
413 s = gc_status_bit[i]; 414 s = gc_status_bit[i];
414 415
415 if (s & (gc->pads[GC_MULTI] | gc->pads[GC_MULTI2])) { 416 if (s & (gc->pads[GC_MULTI] | gc->pads[GC_MULTI2])) {
416 input_report_abs(dev + i, ABS_X, !(s & data[2]) - !(s & data[3])); 417 input_report_abs(gc->dev[i], ABS_X, !(s & data[2]) - !(s & data[3]));
417 input_report_abs(dev + i, ABS_Y, !(s & data[0]) - !(s & data[1])); 418 input_report_abs(gc->dev[i], ABS_Y, !(s & data[0]) - !(s & data[1]));
418 input_report_key(dev + i, BTN_TRIGGER, s & data[4]); 419 input_report_key(gc->dev[i], BTN_TRIGGER, s & data[4]);
419 } 420 }
420 421
421 if (s & gc->pads[GC_MULTI2]) 422 if (s & gc->pads[GC_MULTI2])
422 input_report_key(dev + i, BTN_THUMB, s & data[5]); 423 input_report_key(gc->dev[i], BTN_THUMB, s & data[5]);
423 424
424 input_sync(dev + i); 425 input_sync(gc->dev[i]);
425 } 426 }
426 } 427 }
427 428
@@ -438,44 +439,44 @@ static void gc_timer(unsigned long private)
438 439
439 case GC_PSX_RUMBLE: 440 case GC_PSX_RUMBLE:
440 441
441 input_report_key(dev + i, BTN_THUMBL, ~data_psx[i][0] & 0x04); 442 input_report_key(gc->dev[i], BTN_THUMBL, ~data_psx[i][0] & 0x04);
442 input_report_key(dev + i, BTN_THUMBR, ~data_psx[i][0] & 0x02); 443 input_report_key(gc->dev[i], BTN_THUMBR, ~data_psx[i][0] & 0x02);
443 444
444 case GC_PSX_NEGCON: 445 case GC_PSX_NEGCON:
445 case GC_PSX_ANALOG: 446 case GC_PSX_ANALOG:
446 447
447 if(gc->pads[GC_DDR] & gc_status_bit[i]) { 448 if (gc->pads[GC_DDR] & gc_status_bit[i]) {
448 for(j = 0; j < 4; j++) 449 for(j = 0; j < 4; j++)
449 input_report_key(dev + i, gc_psx_ddr_btn[j], ~data_psx[i][0] & (0x10 << j)); 450 input_report_key(gc->dev[i], gc_psx_ddr_btn[j], ~data_psx[i][0] & (0x10 << j));
450 } else { 451 } else {
451 for (j = 0; j < 4; j++) 452 for (j = 0; j < 4; j++)
452 input_report_abs(dev + i, gc_psx_abs[j+2], data_psx[i][j + 2]); 453 input_report_abs(gc->dev[i], gc_psx_abs[j+2], data_psx[i][j + 2]);
453 454
454 input_report_abs(dev + i, ABS_X, 128 + !(data_psx[i][0] & 0x20) * 127 - !(data_psx[i][0] & 0x80) * 128); 455 input_report_abs(gc->dev[i], ABS_X, 128 + !(data_psx[i][0] & 0x20) * 127 - !(data_psx[i][0] & 0x80) * 128);
455 input_report_abs(dev + i, ABS_Y, 128 + !(data_psx[i][0] & 0x40) * 127 - !(data_psx[i][0] & 0x10) * 128); 456 input_report_abs(gc->dev[i], ABS_Y, 128 + !(data_psx[i][0] & 0x40) * 127 - !(data_psx[i][0] & 0x10) * 128);
456 } 457 }
457 458
458 for (j = 0; j < 8; j++) 459 for (j = 0; j < 8; j++)
459 input_report_key(dev + i, gc_psx_btn[j], ~data_psx[i][1] & (1 << j)); 460 input_report_key(gc->dev[i], gc_psx_btn[j], ~data_psx[i][1] & (1 << j));
460 461
461 input_report_key(dev + i, BTN_START, ~data_psx[i][0] & 0x08); 462 input_report_key(gc->dev[i], BTN_START, ~data_psx[i][0] & 0x08);
462 input_report_key(dev + i, BTN_SELECT, ~data_psx[i][0] & 0x01); 463 input_report_key(gc->dev[i], BTN_SELECT, ~data_psx[i][0] & 0x01);
463 464
464 input_sync(dev + i); 465 input_sync(gc->dev[i]);
465 466
466 break; 467 break;
467 468
468 case GC_PSX_NORMAL: 469 case GC_PSX_NORMAL:
469 if(gc->pads[GC_DDR] & gc_status_bit[i]) { 470 if (gc->pads[GC_DDR] & gc_status_bit[i]) {
470 for(j = 0; j < 4; j++) 471 for(j = 0; j < 4; j++)
471 input_report_key(dev + i, gc_psx_ddr_btn[j], ~data_psx[i][0] & (0x10 << j)); 472 input_report_key(gc->dev[i], gc_psx_ddr_btn[j], ~data_psx[i][0] & (0x10 << j));
472 } else { 473 } else {
473 input_report_abs(dev + i, ABS_X, 128 + !(data_psx[i][0] & 0x20) * 127 - !(data_psx[i][0] & 0x80) * 128); 474 input_report_abs(gc->dev[i], ABS_X, 128 + !(data_psx[i][0] & 0x20) * 127 - !(data_psx[i][0] & 0x80) * 128);
474 input_report_abs(dev + i, ABS_Y, 128 + !(data_psx[i][0] & 0x40) * 127 - !(data_psx[i][0] & 0x10) * 128); 475 input_report_abs(gc->dev[i], ABS_Y, 128 + !(data_psx[i][0] & 0x40) * 127 - !(data_psx[i][0] & 0x10) * 128);
475 476
476 /* for some reason if the extra axes are left unset they drift */ 477 /* for some reason if the extra axes are left unset they drift */
477 /* for (j = 0; j < 4; j++) 478 /* for (j = 0; j < 4; j++)
478 input_report_abs(dev + i, gc_psx_abs[j+2], 128); 479 input_report_abs(gc->dev[i], gc_psx_abs[j+2], 128);
479 * This needs to be debugged properly, 480 * This needs to be debugged properly,
480 * maybe fuzz processing needs to be done in input_sync() 481 * maybe fuzz processing needs to be done in input_sync()
481 * --vojtech 482 * --vojtech
@@ -483,12 +484,12 @@ static void gc_timer(unsigned long private)
483 } 484 }
484 485
485 for (j = 0; j < 8; j++) 486 for (j = 0; j < 8; j++)
486 input_report_key(dev + i, gc_psx_btn[j], ~data_psx[i][1] & (1 << j)); 487 input_report_key(gc->dev[i], gc_psx_btn[j], ~data_psx[i][1] & (1 << j));
487 488
488 input_report_key(dev + i, BTN_START, ~data_psx[i][0] & 0x08); 489 input_report_key(gc->dev[i], BTN_START, ~data_psx[i][0] & 0x08);
489 input_report_key(dev + i, BTN_SELECT, ~data_psx[i][0] & 0x01); 490 input_report_key(gc->dev[i], BTN_SELECT, ~data_psx[i][0] & 0x01);
490 491
491 input_sync(dev + i); 492 input_sync(gc->dev[i]);
492 493
493 break; 494 break;
494 495
@@ -533,177 +534,212 @@ static void gc_close(struct input_dev *dev)
533 up(&gc->sem); 534 up(&gc->sem);
534} 535}
535 536
536static struct gc __init *gc_probe(int *config, int nargs) 537static int __init gc_setup_pad(struct gc *gc, int idx, int pad_type)
537{ 538{
538 struct gc *gc; 539 struct input_dev *input_dev;
539 struct parport *pp; 540 int i;
540 int i, j;
541 541
542 if (config[0] < 0) 542 if (!pad_type)
543 return NULL; 543 return 0;
544 544
545 if (nargs < 2) { 545 if (pad_type < 1 || pad_type > GC_MAX) {
546 printk(KERN_ERR "gamecon.c: at least one device must be specified\n"); 546 printk(KERN_WARNING "gamecon.c: Pad type %d unknown\n", pad_type);
547 return NULL; 547 return -EINVAL;
548 } 548 }
549 549
550 pp = parport_find_number(config[0]); 550 gc->dev[idx] = input_dev = input_allocate_device();
551 551 if (!input_dev) {
552 if (!pp) { 552 printk(KERN_ERR "gamecon.c: Not enough memory for input device\n");
553 printk(KERN_ERR "gamecon.c: no such parport\n"); 553 return -ENOMEM;
554 return NULL;
555 } 554 }
556 555
557 if (!(gc = kzalloc(sizeof(struct gc), GFP_KERNEL))) { 556 input_dev->name = gc_names[pad_type];
558 parport_put_port(pp); 557 input_dev->phys = gc->phys[idx];
559 return NULL; 558 input_dev->id.bustype = BUS_PARPORT;
559 input_dev->id.vendor = 0x0001;
560 input_dev->id.product = pad_type;
561 input_dev->id.version = 0x0100;
562 input_dev->private = gc;
563
564 input_dev->open = gc_open;
565 input_dev->close = gc_close;
566
567 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
568
569 for (i = 0; i < 2; i++)
570 input_set_abs_params(input_dev, ABS_X + i, -1, 1, 0, 0);
571
572 gc->pads[0] |= gc_status_bit[idx];
573 gc->pads[pad_type] |= gc_status_bit[idx];
574
575 switch (pad_type) {
576
577 case GC_N64:
578 for (i = 0; i < 10; i++)
579 set_bit(gc_n64_btn[i], input_dev->keybit);
580
581 for (i = 0; i < 2; i++) {
582 input_set_abs_params(input_dev, ABS_X + i, -127, 126, 0, 2);
583 input_set_abs_params(input_dev, ABS_HAT0X + i, -1, 1, 0, 0);
584 }
585
586 break;
587
588 case GC_SNES:
589 for (i = 4; i < 8; i++)
590 set_bit(gc_snes_btn[i], input_dev->keybit);
591 case GC_NES:
592 for (i = 0; i < 4; i++)
593 set_bit(gc_snes_btn[i], input_dev->keybit);
594 break;
595
596 case GC_MULTI2:
597 set_bit(BTN_THUMB, input_dev->keybit);
598 case GC_MULTI:
599 set_bit(BTN_TRIGGER, input_dev->keybit);
600 break;
601
602 case GC_PSX:
603 for (i = 0; i < 6; i++)
604 input_set_abs_params(input_dev, gc_psx_abs[i], 4, 252, 0, 2);
605 for (i = 0; i < 12; i++)
606 set_bit(gc_psx_btn[i], input_dev->keybit);
607
608 break;
609
610 case GC_DDR:
611 for (i = 0; i < 4; i++)
612 set_bit(gc_psx_ddr_btn[i], input_dev->keybit);
613 for (i = 0; i < 12; i++)
614 set_bit(gc_psx_btn[i], input_dev->keybit);
615
616 break;
560 } 617 }
561 618
562 init_MUTEX(&gc->sem); 619 return 0;
620}
563 621
564 gc->pd = parport_register_device(pp, "gamecon", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL); 622static struct gc __init *gc_probe(int parport, int *pads, int n_pads)
623{
624 struct gc *gc;
625 struct parport *pp;
626 struct pardevice *pd;
627 int i;
628 int err;
565 629
566 parport_put_port(pp); 630 pp = parport_find_number(parport);
631 if (!pp) {
632 printk(KERN_ERR "gamecon.c: no such parport\n");
633 err = -EINVAL;
634 goto err_out;
635 }
567 636
568 if (!gc->pd) { 637 pd = parport_register_device(pp, "gamecon", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
638 if (!pd) {
569 printk(KERN_ERR "gamecon.c: parport busy already - lp.o loaded?\n"); 639 printk(KERN_ERR "gamecon.c: parport busy already - lp.o loaded?\n");
570 kfree(gc); 640 err = -EBUSY;
571 return NULL; 641 goto err_put_pp;
572 } 642 }
573 643
574 parport_claim(gc->pd); 644 gc = kzalloc(sizeof(struct gc), GFP_KERNEL);
645 if (!gc) {
646 printk(KERN_ERR "gamecon.c: Not enough memory\n");
647 err = -ENOMEM;
648 goto err_unreg_pardev;
649 }
575 650
651 init_MUTEX(&gc->sem);
652 gc->pd = pd;
576 init_timer(&gc->timer); 653 init_timer(&gc->timer);
577 gc->timer.data = (long) gc; 654 gc->timer.data = (long) gc;
578 gc->timer.function = gc_timer; 655 gc->timer.function = gc_timer;
579 656
580 for (i = 0; i < nargs - 1; i++) { 657 for (i = 0; i < n_pads; i++) {
581 658 if (!pads[i])
582 if (!config[i + 1])
583 continue; 659 continue;
584 660
585 if (config[i + 1] < 1 || config[i + 1] > GC_MAX) { 661 sprintf(gc->phys[i], "%s/input%d", gc->pd->port->name, i);
586 printk(KERN_WARNING "gamecon.c: Pad type %d unknown\n", config[i + 1]); 662 err = gc_setup_pad(gc, i, pads[i]);
587 continue; 663 if (err)
588 } 664 goto err_free_devs;
589
590 gc->dev[i].private = gc;
591 gc->dev[i].open = gc_open;
592 gc->dev[i].close = gc_close;
593 665
594 gc->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 666 input_register_device(gc->dev[i]);
667 }
595 668
596 for (j = 0; j < 2; j++) { 669 if (!gc->pads[0]) {
597 set_bit(ABS_X + j, gc->dev[i].absbit); 670 printk(KERN_ERR "gamecon.c: No valid devices specified\n");
598 gc->dev[i].absmin[ABS_X + j] = -1; 671 err = -EINVAL;
599 gc->dev[i].absmax[ABS_X + j] = 1; 672 goto err_free_gc;
600 } 673 }
601 674
602 gc->pads[0] |= gc_status_bit[i]; 675 parport_put_port(pp);
603 gc->pads[config[i + 1]] |= gc_status_bit[i]; 676 return gc;
604 677
605 switch(config[i + 1]) { 678 err_free_devs:
679 while (--i >= 0)
680 input_unregister_device(gc->dev[i]);
681 err_free_gc:
682 kfree(gc);
683 err_unreg_pardev:
684 parport_unregister_device(pd);
685 err_put_pp:
686 parport_put_port(pp);
687 err_out:
688 return ERR_PTR(err);
689}
606 690
607 case GC_N64: 691static void __exit gc_remove(struct gc *gc)
608 for (j = 0; j < 10; j++) 692{
609 set_bit(gc_n64_btn[j], gc->dev[i].keybit); 693 int i;
610
611 for (j = 0; j < 2; j++) {
612 set_bit(ABS_X + j, gc->dev[i].absbit);
613 gc->dev[i].absmin[ABS_X + j] = -127;
614 gc->dev[i].absmax[ABS_X + j] = 126;
615 gc->dev[i].absflat[ABS_X + j] = 2;
616 set_bit(ABS_HAT0X + j, gc->dev[i].absbit);
617 gc->dev[i].absmin[ABS_HAT0X + j] = -1;
618 gc->dev[i].absmax[ABS_HAT0X + j] = 1;
619 }
620 694
621 break; 695 for (i = 0; i < GC_MAX_DEVICES; i++)
696 if (gc->dev[i])
697 input_unregister_device(gc->dev[i]);
698 parport_unregister_device(gc->pd);
699 kfree(gc);
700}
622 701
623 case GC_SNES: 702static int __init gc_init(void)
624 for (j = 4; j < 8; j++) 703{
625 set_bit(gc_snes_btn[j], gc->dev[i].keybit); 704 int i;
626 case GC_NES: 705 int have_dev = 0;
627 for (j = 0; j < 4; j++) 706 int err = 0;
628 set_bit(gc_snes_btn[j], gc->dev[i].keybit);
629 break;
630
631 case GC_MULTI2:
632 set_bit(BTN_THUMB, gc->dev[i].keybit);
633 case GC_MULTI:
634 set_bit(BTN_TRIGGER, gc->dev[i].keybit);
635 break;
636
637 case GC_PSX:
638 case GC_DDR:
639 if(config[i + 1] == GC_DDR) {
640 for (j = 0; j < 4; j++)
641 set_bit(gc_psx_ddr_btn[j], gc->dev[i].keybit);
642 } else {
643 for (j = 0; j < 6; j++) {
644 set_bit(gc_psx_abs[j], gc->dev[i].absbit);
645 gc->dev[i].absmin[gc_psx_abs[j]] = 4;
646 gc->dev[i].absmax[gc_psx_abs[j]] = 252;
647 gc->dev[i].absflat[gc_psx_abs[j]] = 2;
648 }
649 }
650 707
651 for (j = 0; j < 12; j++) 708 for (i = 0; i < GC_MAX_PORTS; i++) {
652 set_bit(gc_psx_btn[j], gc->dev[i].keybit); 709 if (gc[i].nargs == 0 || gc[i].args[0] < 0)
710 continue;
653 711
654 break; 712 if (gc[i].nargs < 2) {
713 printk(KERN_ERR "gamecon.c: at least one device must be specified\n");
714 err = -EINVAL;
715 break;
655 } 716 }
656 717
657 sprintf(gc->phys[i], "%s/input%d", gc->pd->port->name, i); 718 gc_base[i] = gc_probe(gc[i].args[0], gc[i].args + 1, gc[i].nargs - 1);
719 if (IS_ERR(gc_base[i])) {
720 err = PTR_ERR(gc_base[i]);
721 break;
722 }
658 723
659 gc->dev[i].name = gc_names[config[i + 1]]; 724 have_dev = 1;
660 gc->dev[i].phys = gc->phys[i];
661 gc->dev[i].id.bustype = BUS_PARPORT;
662 gc->dev[i].id.vendor = 0x0001;
663 gc->dev[i].id.product = config[i + 1];
664 gc->dev[i].id.version = 0x0100;
665 } 725 }
666 726
667 parport_release(gc->pd); 727 if (err) {
668 728 while (--i >= 0)
669 if (!gc->pads[0]) { 729 gc_remove(gc_base[i]);
670 parport_unregister_device(gc->pd); 730 return err;
671 kfree(gc);
672 return NULL;
673 } 731 }
674 732
675 for (i = 0; i < 5; i++) 733 return have_dev ? 0 : -ENODEV;
676 if (gc->pads[0] & gc_status_bit[i]) {
677 input_register_device(gc->dev + i);
678 printk(KERN_INFO "input: %s on %s\n", gc->dev[i].name, gc->pd->port->name);
679 }
680
681 return gc;
682}
683
684static int __init gc_init(void)
685{
686 gc_base[0] = gc_probe(gc, gc_nargs);
687 gc_base[1] = gc_probe(gc_2, gc_nargs_2);
688 gc_base[2] = gc_probe(gc_3, gc_nargs_3);
689
690 if (gc_base[0] || gc_base[1] || gc_base[2])
691 return 0;
692
693 return -ENODEV;
694} 734}
695 735
696static void __exit gc_exit(void) 736static void __exit gc_exit(void)
697{ 737{
698 int i, j; 738 int i;
699 739
700 for (i = 0; i < 3; i++) 740 for (i = 0; i < GC_MAX_PORTS; i++)
701 if (gc_base[i]) { 741 if (gc_base[i])
702 for (j = 0; j < 5; j++) 742 gc_remove(gc_base[i]);
703 if (gc_base[i]->pads[0] & gc_status_bit[j])
704 input_unregister_device(gc_base[i]->dev + j);
705 parport_unregister_device(gc_base[i]->pd);
706 }
707} 743}
708 744
709module_init(gc_init); 745module_init(gc_init);
diff --git a/drivers/input/joystick/gf2k.c b/drivers/input/joystick/gf2k.c
index 8e4f92b115e6..8a3ad455eb38 100644
--- a/drivers/input/joystick/gf2k.c
+++ b/drivers/input/joystick/gf2k.c
@@ -35,6 +35,7 @@
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/input.h> 36#include <linux/input.h>
37#include <linux/gameport.h> 37#include <linux/gameport.h>
38#include <linux/jiffies.h>
38 39
39#define DRIVER_DESC "Genius Flight 2000 joystick driver" 40#define DRIVER_DESC "Genius Flight 2000 joystick driver"
40 41
@@ -81,7 +82,7 @@ static short gf2k_seq_digital[] = { 590, 320, 860, 0 };
81 82
82struct gf2k { 83struct gf2k {
83 struct gameport *gameport; 84 struct gameport *gameport;
84 struct input_dev dev; 85 struct input_dev *dev;
85 int reads; 86 int reads;
86 int bads; 87 int bads;
87 unsigned char id; 88 unsigned char id;
@@ -175,7 +176,7 @@ static int gf2k_get_bits(unsigned char *buf, int pos, int num, int shift)
175 176
176static void gf2k_read(struct gf2k *gf2k, unsigned char *data) 177static void gf2k_read(struct gf2k *gf2k, unsigned char *data)
177{ 178{
178 struct input_dev *dev = &gf2k->dev; 179 struct input_dev *dev = gf2k->dev;
179 int i, t; 180 int i, t;
180 181
181 for (i = 0; i < 4 && i < gf2k_axes[gf2k->id]; i++) 182 for (i = 0; i < 4 && i < gf2k_axes[gf2k->id]; i++)
@@ -239,13 +240,19 @@ static void gf2k_close(struct input_dev *dev)
239static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv) 240static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
240{ 241{
241 struct gf2k *gf2k; 242 struct gf2k *gf2k;
243 struct input_dev *input_dev;
242 unsigned char data[GF2K_LENGTH]; 244 unsigned char data[GF2K_LENGTH];
243 int i, err; 245 int i, err;
244 246
245 if (!(gf2k = kzalloc(sizeof(struct gf2k), GFP_KERNEL))) 247 gf2k = kzalloc(sizeof(struct gf2k), GFP_KERNEL);
246 return -ENOMEM; 248 input_dev = input_allocate_device();
249 if (!gf2k || !input_dev) {
250 err = -ENOMEM;
251 goto fail1;
252 }
247 253
248 gf2k->gameport = gameport; 254 gf2k->gameport = gameport;
255 gf2k->dev = input_dev;
249 256
250 gameport_set_drvdata(gameport, gf2k); 257 gameport_set_drvdata(gameport, gf2k);
251 258
@@ -295,53 +302,52 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
295 302
296 gf2k->length = gf2k_lens[gf2k->id]; 303 gf2k->length = gf2k_lens[gf2k->id];
297 304
298 init_input_dev(&gf2k->dev); 305 input_dev->name = gf2k_names[gf2k->id];
299 306 input_dev->phys = gf2k->phys;
300 gf2k->dev.private = gf2k; 307 input_dev->id.bustype = BUS_GAMEPORT;
301 gf2k->dev.open = gf2k_open; 308 input_dev->id.vendor = GAMEPORT_ID_VENDOR_GENIUS;
302 gf2k->dev.close = gf2k_close; 309 input_dev->id.product = gf2k->id;
303 gf2k->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 310 input_dev->id.version = 0x0100;
311 input_dev->cdev.dev = &gameport->dev;
312 input_dev->private = gf2k;
304 313
305 gf2k->dev.name = gf2k_names[gf2k->id]; 314 input_dev->open = gf2k_open;
306 gf2k->dev.phys = gf2k->phys; 315 input_dev->close = gf2k_close;
307 gf2k->dev.id.bustype = BUS_GAMEPORT; 316 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
308 gf2k->dev.id.vendor = GAMEPORT_ID_VENDOR_GENIUS;
309 gf2k->dev.id.product = gf2k->id;
310 gf2k->dev.id.version = 0x0100;
311 317
312 for (i = 0; i < gf2k_axes[gf2k->id]; i++) 318 for (i = 0; i < gf2k_axes[gf2k->id]; i++)
313 set_bit(gf2k_abs[i], gf2k->dev.absbit); 319 set_bit(gf2k_abs[i], input_dev->absbit);
314 320
315 for (i = 0; i < gf2k_hats[gf2k->id]; i++) { 321 for (i = 0; i < gf2k_hats[gf2k->id]; i++) {
316 set_bit(ABS_HAT0X + i, gf2k->dev.absbit); 322 set_bit(ABS_HAT0X + i, input_dev->absbit);
317 gf2k->dev.absmin[ABS_HAT0X + i] = -1; 323 input_dev->absmin[ABS_HAT0X + i] = -1;
318 gf2k->dev.absmax[ABS_HAT0X + i] = 1; 324 input_dev->absmax[ABS_HAT0X + i] = 1;
319 } 325 }
320 326
321 for (i = 0; i < gf2k_joys[gf2k->id]; i++) 327 for (i = 0; i < gf2k_joys[gf2k->id]; i++)
322 set_bit(gf2k_btn_joy[i], gf2k->dev.keybit); 328 set_bit(gf2k_btn_joy[i], input_dev->keybit);
323 329
324 for (i = 0; i < gf2k_pads[gf2k->id]; i++) 330 for (i = 0; i < gf2k_pads[gf2k->id]; i++)
325 set_bit(gf2k_btn_pad[i], gf2k->dev.keybit); 331 set_bit(gf2k_btn_pad[i], input_dev->keybit);
326 332
327 gf2k_read_packet(gameport, gf2k->length, data); 333 gf2k_read_packet(gameport, gf2k->length, data);
328 gf2k_read(gf2k, data); 334 gf2k_read(gf2k, data);
329 335
330 for (i = 0; i < gf2k_axes[gf2k->id]; i++) { 336 for (i = 0; i < gf2k_axes[gf2k->id]; i++) {
331 gf2k->dev.absmax[gf2k_abs[i]] = (i < 2) ? gf2k->dev.abs[gf2k_abs[i]] * 2 - 32 : 337 input_dev->absmax[gf2k_abs[i]] = (i < 2) ? input_dev->abs[gf2k_abs[i]] * 2 - 32 :
332 gf2k->dev.abs[gf2k_abs[0]] + gf2k->dev.abs[gf2k_abs[1]] - 32; 338 input_dev->abs[gf2k_abs[0]] + input_dev->abs[gf2k_abs[1]] - 32;
333 gf2k->dev.absmin[gf2k_abs[i]] = 32; 339 input_dev->absmin[gf2k_abs[i]] = 32;
334 gf2k->dev.absfuzz[gf2k_abs[i]] = 8; 340 input_dev->absfuzz[gf2k_abs[i]] = 8;
335 gf2k->dev.absflat[gf2k_abs[i]] = (i < 2) ? 24 : 0; 341 input_dev->absflat[gf2k_abs[i]] = (i < 2) ? 24 : 0;
336 } 342 }
337 343
338 input_register_device(&gf2k->dev); 344 input_register_device(gf2k->dev);
339 printk(KERN_INFO "input: %s on %s\n", gf2k_names[gf2k->id], gameport->phys);
340 345
341 return 0; 346 return 0;
342 347
343fail2: gameport_close(gameport); 348 fail2: gameport_close(gameport);
344fail1: gameport_set_drvdata(gameport, NULL); 349 fail1: gameport_set_drvdata(gameport, NULL);
350 input_free_device(input_dev);
345 kfree(gf2k); 351 kfree(gf2k);
346 return err; 352 return err;
347} 353}
@@ -350,7 +356,7 @@ static void gf2k_disconnect(struct gameport *gameport)
350{ 356{
351 struct gf2k *gf2k = gameport_get_drvdata(gameport); 357 struct gf2k *gf2k = gameport_get_drvdata(gameport);
352 358
353 input_unregister_device(&gf2k->dev); 359 input_unregister_device(gf2k->dev);
354 gameport_close(gameport); 360 gameport_close(gameport);
355 gameport_set_drvdata(gameport, NULL); 361 gameport_set_drvdata(gameport, NULL);
356 kfree(gf2k); 362 kfree(gf2k);
diff --git a/drivers/input/joystick/grip.c b/drivers/input/joystick/grip.c
index 9d3f910dd568..a936e7aedb10 100644
--- a/drivers/input/joystick/grip.c
+++ b/drivers/input/joystick/grip.c
@@ -34,6 +34,7 @@
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/gameport.h> 35#include <linux/gameport.h>
36#include <linux/input.h> 36#include <linux/input.h>
37#include <linux/jiffies.h>
37 38
38#define DRIVER_DESC "Gravis GrIP protocol joystick driver" 39#define DRIVER_DESC "Gravis GrIP protocol joystick driver"
39 40
@@ -55,7 +56,7 @@ MODULE_LICENSE("GPL");
55 56
56struct grip { 57struct grip {
57 struct gameport *gameport; 58 struct gameport *gameport;
58 struct input_dev dev[2]; 59 struct input_dev *dev[2];
59 unsigned char mode[2]; 60 unsigned char mode[2];
60 int reads; 61 int reads;
61 int bads; 62 int bads;
@@ -190,7 +191,7 @@ static void grip_poll(struct gameport *gameport)
190 191
191 for (i = 0; i < 2; i++) { 192 for (i = 0; i < 2; i++) {
192 193
193 dev = grip->dev + i; 194 dev = grip->dev[i];
194 grip->reads++; 195 grip->reads++;
195 196
196 switch (grip->mode[i]) { 197 switch (grip->mode[i]) {
@@ -297,6 +298,7 @@ static void grip_close(struct input_dev *dev)
297static int grip_connect(struct gameport *gameport, struct gameport_driver *drv) 298static int grip_connect(struct gameport *gameport, struct gameport_driver *drv)
298{ 299{
299 struct grip *grip; 300 struct grip *grip;
301 struct input_dev *input_dev;
300 unsigned int data[GRIP_LENGTH_XT]; 302 unsigned int data[GRIP_LENGTH_XT];
301 int i, j, t; 303 int i, j, t;
302 int err; 304 int err;
@@ -339,48 +341,56 @@ static int grip_connect(struct gameport *gameport, struct gameport_driver *drv)
339 gameport_set_poll_handler(gameport, grip_poll); 341 gameport_set_poll_handler(gameport, grip_poll);
340 gameport_set_poll_interval(gameport, 20); 342 gameport_set_poll_interval(gameport, 20);
341 343
342 for (i = 0; i < 2; i++) 344 for (i = 0; i < 2; i++) {
343 if (grip->mode[i]) { 345 if (!grip->mode[i])
346 continue;
344 347
345 sprintf(grip->phys[i], "%s/input%d", gameport->phys, i); 348 grip->dev[i] = input_dev = input_allocate_device();
349 if (!input_dev) {
350 err = -ENOMEM;
351 goto fail3;
352 }
346 353
347 grip->dev[i].private = grip; 354 sprintf(grip->phys[i], "%s/input%d", gameport->phys, i);
348 355
349 grip->dev[i].open = grip_open; 356 input_dev->name = grip_name[grip->mode[i]];
350 grip->dev[i].close = grip_close; 357 input_dev->phys = grip->phys[i];
358 input_dev->id.bustype = BUS_GAMEPORT;
359 input_dev->id.vendor = GAMEPORT_ID_VENDOR_GRAVIS;
360 input_dev->id.product = grip->mode[i];
361 input_dev->id.version = 0x0100;
362 input_dev->cdev.dev = &gameport->dev;
363 input_dev->private = grip;
351 364
352 grip->dev[i].name = grip_name[grip->mode[i]]; 365 input_dev->open = grip_open;
353 grip->dev[i].phys = grip->phys[i]; 366 input_dev->close = grip_close;
354 grip->dev[i].id.bustype = BUS_GAMEPORT;
355 grip->dev[i].id.vendor = GAMEPORT_ID_VENDOR_GRAVIS;
356 grip->dev[i].id.product = grip->mode[i];
357 grip->dev[i].id.version = 0x0100;
358 367
359 grip->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 368 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
360 369
361 for (j = 0; (t = grip_abs[grip->mode[i]][j]) >= 0; j++) { 370 for (j = 0; (t = grip_abs[grip->mode[i]][j]) >= 0; j++) {
362 371
363 if (j < grip_cen[grip->mode[i]]) 372 if (j < grip_cen[grip->mode[i]])
364 input_set_abs_params(&grip->dev[i], t, 14, 52, 1, 2); 373 input_set_abs_params(input_dev, t, 14, 52, 1, 2);
365 else if (j < grip_anx[grip->mode[i]]) 374 else if (j < grip_anx[grip->mode[i]])
366 input_set_abs_params(&grip->dev[i], t, 3, 57, 1, 0); 375 input_set_abs_params(input_dev, t, 3, 57, 1, 0);
367 else 376 else
368 input_set_abs_params(&grip->dev[i], t, -1, 1, 0, 0); 377 input_set_abs_params(input_dev, t, -1, 1, 0, 0);
369 } 378 }
370 379
371 for (j = 0; (t = grip_btn[grip->mode[i]][j]) >= 0; j++) 380 for (j = 0; (t = grip_btn[grip->mode[i]][j]) >= 0; j++)
372 if (t > 0) 381 if (t > 0)
373 set_bit(t, grip->dev[i].keybit); 382 set_bit(t, input_dev->keybit);
374 383
375 printk(KERN_INFO "input: %s on %s\n", 384 input_register_device(grip->dev[i]);
376 grip_name[grip->mode[i]], gameport->phys); 385 }
377 input_register_device(grip->dev + i);
378 }
379 386
380 return 0; 387 return 0;
381 388
382fail2: gameport_close(gameport); 389 fail3: for (i = 0; i < 2; i++)
383fail1: gameport_set_drvdata(gameport, NULL); 390 if (grip->dev[i])
391 input_unregister_device(grip->dev[i]);
392 fail2: gameport_close(gameport);
393 fail1: gameport_set_drvdata(gameport, NULL);
384 kfree(grip); 394 kfree(grip);
385 return err; 395 return err;
386} 396}
@@ -391,8 +401,8 @@ static void grip_disconnect(struct gameport *gameport)
391 int i; 401 int i;
392 402
393 for (i = 0; i < 2; i++) 403 for (i = 0; i < 2; i++)
394 if (grip->mode[i]) 404 if (grip->dev[i])
395 input_unregister_device(grip->dev + i); 405 input_unregister_device(grip->dev[i]);
396 gameport_close(gameport); 406 gameport_close(gameport);
397 gameport_set_drvdata(gameport, NULL); 407 gameport_set_drvdata(gameport, NULL);
398 kfree(grip); 408 kfree(grip);
diff --git a/drivers/input/joystick/grip_mp.c b/drivers/input/joystick/grip_mp.c
index da17eee6f574..51a912222e85 100644
--- a/drivers/input/joystick/grip_mp.c
+++ b/drivers/input/joystick/grip_mp.c
@@ -19,6 +19,7 @@
19#include <linux/input.h> 19#include <linux/input.h>
20#include <linux/delay.h> 20#include <linux/delay.h>
21#include <linux/proc_fs.h> 21#include <linux/proc_fs.h>
22#include <linux/jiffies.h>
22 23
23#define DRIVER_DESC "Gravis Grip Multiport driver" 24#define DRIVER_DESC "Gravis Grip Multiport driver"
24 25
@@ -32,23 +33,37 @@ MODULE_LICENSE("GPL");
32#define dbg(format, arg...) do {} while (0) 33#define dbg(format, arg...) do {} while (0)
33#endif 34#endif
34 35
36#define GRIP_MAX_PORTS 4
35/* 37/*
36 * Grip multiport state 38 * Grip multiport state
37 */ 39 */
38 40
41struct grip_port {
42 struct input_dev *dev;
43 int mode;
44 int registered;
45
46 /* individual gamepad states */
47 int buttons;
48 int xaxes;
49 int yaxes;
50 int dirty; /* has the state been updated? */
51};
52
39struct grip_mp { 53struct grip_mp {
40 struct gameport *gameport; 54 struct gameport *gameport;
41 struct input_dev dev[4]; 55 struct grip_port *port[GRIP_MAX_PORTS];
42 int mode[4]; 56// struct input_dev *dev[4];
43 int registered[4]; 57// int mode[4];
58// int registered[4];
44 int reads; 59 int reads;
45 int bads; 60 int bads;
46 61
47 /* individual gamepad states */ 62 /* individual gamepad states */
48 int buttons[4]; 63// int buttons[4];
49 int xaxes[4]; 64// int xaxes[4];
50 int yaxes[4]; 65// int yaxes[4];
51 int dirty[4]; /* has the state been updated? */ 66// int dirty[4]; /* has the state been updated? */
52}; 67};
53 68
54/* 69/*
@@ -85,16 +100,16 @@ struct grip_mp {
85#define GRIP_MODE_GP 2 100#define GRIP_MODE_GP 2
86#define GRIP_MODE_C64 3 101#define GRIP_MODE_C64 3
87 102
88static int grip_btn_gp[] = { BTN_TR, BTN_TL, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, -1 }; 103static const int grip_btn_gp[] = { BTN_TR, BTN_TL, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, -1 };
89static int grip_btn_c64[] = { BTN_JOYSTICK, -1 }; 104static const int grip_btn_c64[] = { BTN_JOYSTICK, -1 };
90 105
91static int grip_abs_gp[] = { ABS_X, ABS_Y, -1 }; 106static const int grip_abs_gp[] = { ABS_X, ABS_Y, -1 };
92static int grip_abs_c64[] = { ABS_X, ABS_Y, -1 }; 107static const int grip_abs_c64[] = { ABS_X, ABS_Y, -1 };
93 108
94static int *grip_abs[] = { NULL, NULL, grip_abs_gp, grip_abs_c64 }; 109static const int *grip_abs[] = { NULL, NULL, grip_abs_gp, grip_abs_c64 };
95static int *grip_btn[] = { NULL, NULL, grip_btn_gp, grip_btn_c64 }; 110static const int *grip_btn[] = { NULL, NULL, grip_btn_gp, grip_btn_c64 };
96 111
97static char *grip_name[] = { NULL, NULL, "Gravis Grip Pad", "Commodore 64 Joystick" }; 112static const char *grip_name[] = { NULL, NULL, "Gravis Grip Pad", "Commodore 64 Joystick" };
98 113
99static const int init_seq[] = { 114static const int init_seq[] = {
100 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 115 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1,
@@ -104,9 +119,9 @@ static const int init_seq[] = {
104 119
105/* Maps multiport directional values to X,Y axis values (each axis encoded in 3 bits) */ 120/* Maps multiport directional values to X,Y axis values (each axis encoded in 3 bits) */
106 121
107static int axis_map[] = { 5, 9, 1, 5, 6, 10, 2, 6, 4, 8, 0, 4, 5, 9, 1, 5 }; 122static const int axis_map[] = { 5, 9, 1, 5, 6, 10, 2, 6, 4, 8, 0, 4, 5, 9, 1, 5 };
108 123
109static void register_slot(int i, struct grip_mp *grip); 124static int register_slot(int i, struct grip_mp *grip);
110 125
111/* 126/*
112 * Returns whether an odd or even number of bits are on in pkt. 127 * Returns whether an odd or even number of bits are on in pkt.
@@ -353,9 +368,10 @@ static int dig_mode_start(struct gameport *gameport, u32 *packet)
353 368
354static int get_and_decode_packet(struct grip_mp *grip, int flags) 369static int get_and_decode_packet(struct grip_mp *grip, int flags)
355{ 370{
371 struct grip_port *port;
356 u32 packet; 372 u32 packet;
357 int joytype = 0; 373 int joytype = 0;
358 int slot = 0; 374 int slot;
359 375
360 /* Get a packet and check for validity */ 376 /* Get a packet and check for validity */
361 377
@@ -377,6 +393,8 @@ static int get_and_decode_packet(struct grip_mp *grip, int flags)
377 if ((slot < 0) || (slot > 3)) 393 if ((slot < 0) || (slot > 3))
378 return flags; 394 return flags;
379 395
396 port = grip->port[slot];
397
380 /* 398 /*
381 * Handle "reset" packets, which occur at startup, and when gamepads 399 * Handle "reset" packets, which occur at startup, and when gamepads
382 * are removed or plugged in. May contain configuration of a new gamepad. 400 * are removed or plugged in. May contain configuration of a new gamepad.
@@ -385,14 +403,14 @@ static int get_and_decode_packet(struct grip_mp *grip, int flags)
385 joytype = (packet >> 16) & 0x1f; 403 joytype = (packet >> 16) & 0x1f;
386 if (!joytype) { 404 if (!joytype) {
387 405
388 if (grip->registered[slot]) { 406 if (port->registered) {
389 printk(KERN_INFO "grip_mp: removing %s, slot %d\n", 407 printk(KERN_INFO "grip_mp: removing %s, slot %d\n",
390 grip_name[grip->mode[slot]], slot); 408 grip_name[port->mode], slot);
391 input_unregister_device(grip->dev + slot); 409 input_unregister_device(port->dev);
392 grip->registered[slot] = 0; 410 port->registered = 0;
393 } 411 }
394 dbg("Reset: grip multiport slot %d\n", slot); 412 dbg("Reset: grip multiport slot %d\n", slot);
395 grip->mode[slot] = GRIP_MODE_RESET; 413 port->mode = GRIP_MODE_RESET;
396 flags |= IO_SLOT_CHANGE; 414 flags |= IO_SLOT_CHANGE;
397 return flags; 415 return flags;
398 } 416 }
@@ -402,17 +420,17 @@ static int get_and_decode_packet(struct grip_mp *grip, int flags)
402 if (joytype == 0x1f) { 420 if (joytype == 0x1f) {
403 421
404 int dir = (packet >> 8) & 0xf; /* eight way directional value */ 422 int dir = (packet >> 8) & 0xf; /* eight way directional value */
405 grip->buttons[slot] = (~packet) & 0xff; 423 port->buttons = (~packet) & 0xff;
406 grip->yaxes[slot] = ((axis_map[dir] >> 2) & 3) - 1; 424 port->yaxes = ((axis_map[dir] >> 2) & 3) - 1;
407 grip->xaxes[slot] = (axis_map[dir] & 3) - 1; 425 port->xaxes = (axis_map[dir] & 3) - 1;
408 grip->dirty[slot] = 1; 426 port->dirty = 1;
409 427
410 if (grip->mode[slot] == GRIP_MODE_RESET) 428 if (port->mode == GRIP_MODE_RESET)
411 flags |= IO_SLOT_CHANGE; 429 flags |= IO_SLOT_CHANGE;
412 430
413 grip->mode[slot] = GRIP_MODE_GP; 431 port->mode = GRIP_MODE_GP;
414 432
415 if (!grip->registered[slot]) { 433 if (!port->registered) {
416 dbg("New Grip pad in multiport slot %d.\n", slot); 434 dbg("New Grip pad in multiport slot %d.\n", slot);
417 register_slot(slot, grip); 435 register_slot(slot, grip);
418 } 436 }
@@ -445,9 +463,9 @@ static int slots_valid(struct grip_mp *grip)
445 return 0; 463 return 0;
446 464
447 for (slot = 0; slot < 4; slot++) { 465 for (slot = 0; slot < 4; slot++) {
448 if (grip->mode[slot] == GRIP_MODE_RESET) 466 if (grip->port[slot]->mode == GRIP_MODE_RESET)
449 invalid = 1; 467 invalid = 1;
450 if (grip->mode[slot] != GRIP_MODE_NONE) 468 if (grip->port[slot]->mode != GRIP_MODE_NONE)
451 active = 1; 469 active = 1;
452 } 470 }
453 471
@@ -484,7 +502,7 @@ static int multiport_init(struct grip_mp *grip)
484 502
485 /* Get packets, store multiport state, and check state's validity */ 503 /* Get packets, store multiport state, and check state's validity */
486 for (tries = 0; tries < 4096; tries++) { 504 for (tries = 0; tries < 4096; tries++) {
487 if ( slots_valid(grip) ) { 505 if (slots_valid(grip)) {
488 initialized = 1; 506 initialized = 1;
489 break; 507 break;
490 } 508 }
@@ -499,24 +517,24 @@ static int multiport_init(struct grip_mp *grip)
499 517
500static void report_slot(struct grip_mp *grip, int slot) 518static void report_slot(struct grip_mp *grip, int slot)
501{ 519{
502 struct input_dev *dev = &(grip->dev[slot]); 520 struct grip_port *port = grip->port[slot];
503 int i, buttons = grip->buttons[slot]; 521 int i;
504 522
505 /* Store button states with linux input driver */ 523 /* Store button states with linux input driver */
506 524
507 for (i = 0; i < 8; i++) 525 for (i = 0; i < 8; i++)
508 input_report_key(dev, grip_btn_gp[i], (buttons >> i) & 1); 526 input_report_key(port->dev, grip_btn_gp[i], (port->buttons >> i) & 1);
509 527
510 /* Store axis states with linux driver */ 528 /* Store axis states with linux driver */
511 529
512 input_report_abs(dev, ABS_X, grip->xaxes[slot]); 530 input_report_abs(port->dev, ABS_X, port->xaxes);
513 input_report_abs(dev, ABS_Y, grip->yaxes[slot]); 531 input_report_abs(port->dev, ABS_Y, port->yaxes);
514 532
515 /* Tell the receiver of the events to process them */ 533 /* Tell the receiver of the events to process them */
516 534
517 input_sync(dev); 535 input_sync(port->dev);
518 536
519 grip->dirty[slot] = 0; 537 port->dirty = 0;
520} 538}
521 539
522/* 540/*
@@ -540,7 +558,7 @@ static void grip_poll(struct gameport *gameport)
540 } 558 }
541 559
542 for (i = 0; i < 4; i++) 560 for (i = 0; i < 4; i++)
543 if (grip->dirty[i]) 561 if (grip->port[i]->dirty)
544 report_slot(grip, i); 562 report_slot(grip, i);
545} 563}
546 564
@@ -571,35 +589,43 @@ static void grip_close(struct input_dev *dev)
571 * Tell the linux input layer about a newly plugged-in gamepad. 589 * Tell the linux input layer about a newly plugged-in gamepad.
572 */ 590 */
573 591
574static void register_slot(int slot, struct grip_mp *grip) 592static int register_slot(int slot, struct grip_mp *grip)
575{ 593{
594 struct grip_port *port = grip->port[slot];
595 struct input_dev *input_dev;
576 int j, t; 596 int j, t;
577 597
578 grip->dev[slot].private = grip; 598 port->dev = input_dev = input_allocate_device();
579 grip->dev[slot].open = grip_open; 599 if (!input_dev)
580 grip->dev[slot].close = grip_close; 600 return -ENOMEM;
581 grip->dev[slot].name = grip_name[grip->mode[slot]]; 601
582 grip->dev[slot].id.bustype = BUS_GAMEPORT; 602 input_dev->name = grip_name[port->mode];
583 grip->dev[slot].id.vendor = GAMEPORT_ID_VENDOR_GRAVIS; 603 input_dev->id.bustype = BUS_GAMEPORT;
584 grip->dev[slot].id.product = 0x0100 + grip->mode[slot]; 604 input_dev->id.vendor = GAMEPORT_ID_VENDOR_GRAVIS;
585 grip->dev[slot].id.version = 0x0100; 605 input_dev->id.product = 0x0100 + port->mode;
586 grip->dev[slot].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 606 input_dev->id.version = 0x0100;
607 input_dev->cdev.dev = &grip->gameport->dev;
608 input_dev->private = grip;
609
610 input_dev->open = grip_open;
611 input_dev->close = grip_close;
587 612
588 for (j = 0; (t = grip_abs[grip->mode[slot]][j]) >= 0; j++) 613 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
589 input_set_abs_params(&grip->dev[slot], t, -1, 1, 0, 0);
590 614
591 for (j = 0; (t = grip_btn[grip->mode[slot]][j]) >= 0; j++) 615 for (j = 0; (t = grip_abs[port->mode][j]) >= 0; j++)
616 input_set_abs_params(input_dev, t, -1, 1, 0, 0);
617
618 for (j = 0; (t = grip_btn[port->mode][j]) >= 0; j++)
592 if (t > 0) 619 if (t > 0)
593 set_bit(t, grip->dev[slot].keybit); 620 set_bit(t, input_dev->keybit);
594 621
595 input_register_device(grip->dev + slot); 622 input_register_device(port->dev);
596 grip->registered[slot] = 1; 623 port->registered = 1;
597 624
598 if (grip->dirty[slot]) /* report initial state, if any */ 625 if (port->dirty) /* report initial state, if any */
599 report_slot(grip, slot); 626 report_slot(grip, slot);
600 627
601 printk(KERN_INFO "grip_mp: added %s, slot %d\n", 628 return 0;
602 grip_name[grip->mode[slot]], slot);
603} 629}
604 630
605static int grip_connect(struct gameport *gameport, struct gameport_driver *drv) 631static int grip_connect(struct gameport *gameport, struct gameport_driver *drv)
@@ -626,7 +652,7 @@ static int grip_connect(struct gameport *gameport, struct gameport_driver *drv)
626 goto fail2; 652 goto fail2;
627 } 653 }
628 654
629 if (!grip->mode[0] && !grip->mode[1] && !grip->mode[2] && !grip->mode[3]) { 655 if (!grip->port[0]->mode && !grip->port[1]->mode && !grip->port[2]->mode && !grip->port[3]->mode) {
630 /* nothing plugged in */ 656 /* nothing plugged in */
631 err = -ENODEV; 657 err = -ENODEV;
632 goto fail2; 658 goto fail2;
@@ -646,8 +672,8 @@ static void grip_disconnect(struct gameport *gameport)
646 int i; 672 int i;
647 673
648 for (i = 0; i < 4; i++) 674 for (i = 0; i < 4; i++)
649 if (grip->registered[i]) 675 if (grip->port[i]->registered)
650 input_unregister_device(grip->dev + i); 676 input_unregister_device(grip->port[i]->dev);
651 gameport_close(gameport); 677 gameport_close(gameport);
652 gameport_set_drvdata(gameport, NULL); 678 gameport_set_drvdata(gameport, NULL);
653 kfree(grip); 679 kfree(grip);
diff --git a/drivers/input/joystick/guillemot.c b/drivers/input/joystick/guillemot.c
index 6a70ec429f06..6e2c721c26ba 100644
--- a/drivers/input/joystick/guillemot.c
+++ b/drivers/input/joystick/guillemot.c
@@ -35,6 +35,7 @@
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/gameport.h> 36#include <linux/gameport.h>
37#include <linux/input.h> 37#include <linux/input.h>
38#include <linux/jiffies.h>
38 39
39#define DRIVER_DESC "Guillemot Digital joystick driver" 40#define DRIVER_DESC "Guillemot Digital joystick driver"
40 41
@@ -67,7 +68,7 @@ struct guillemot_type {
67 68
68struct guillemot { 69struct guillemot {
69 struct gameport *gameport; 70 struct gameport *gameport;
70 struct input_dev dev; 71 struct input_dev *dev;
71 int bads; 72 int bads;
72 int reads; 73 int reads;
73 struct guillemot_type *type; 74 struct guillemot_type *type;
@@ -123,7 +124,7 @@ static int guillemot_read_packet(struct gameport *gameport, u8 *data)
123static void guillemot_poll(struct gameport *gameport) 124static void guillemot_poll(struct gameport *gameport)
124{ 125{
125 struct guillemot *guillemot = gameport_get_drvdata(gameport); 126 struct guillemot *guillemot = gameport_get_drvdata(gameport);
126 struct input_dev *dev = &guillemot->dev; 127 struct input_dev *dev = guillemot->dev;
127 u8 data[GUILLEMOT_MAX_LENGTH]; 128 u8 data[GUILLEMOT_MAX_LENGTH];
128 int i; 129 int i;
129 130
@@ -179,14 +180,20 @@ static void guillemot_close(struct input_dev *dev)
179static int guillemot_connect(struct gameport *gameport, struct gameport_driver *drv) 180static int guillemot_connect(struct gameport *gameport, struct gameport_driver *drv)
180{ 181{
181 struct guillemot *guillemot; 182 struct guillemot *guillemot;
183 struct input_dev *input_dev;
182 u8 data[GUILLEMOT_MAX_LENGTH]; 184 u8 data[GUILLEMOT_MAX_LENGTH];
183 int i, t; 185 int i, t;
184 int err; 186 int err;
185 187
186 if (!(guillemot = kzalloc(sizeof(struct guillemot), GFP_KERNEL))) 188 guillemot = kzalloc(sizeof(struct guillemot), GFP_KERNEL);
187 return -ENOMEM; 189 input_dev = input_allocate_device();
190 if (!guillemot || !input_dev) {
191 err = -ENOMEM;
192 goto fail1;
193 }
188 194
189 guillemot->gameport = gameport; 195 guillemot->gameport = gameport;
196 guillemot->dev = input_dev;
190 197
191 gameport_set_drvdata(gameport, guillemot); 198 gameport_set_drvdata(gameport, guillemot);
192 199
@@ -216,41 +223,40 @@ static int guillemot_connect(struct gameport *gameport, struct gameport_driver *
216 gameport_set_poll_interval(gameport, 20); 223 gameport_set_poll_interval(gameport, 20);
217 224
218 sprintf(guillemot->phys, "%s/input0", gameport->phys); 225 sprintf(guillemot->phys, "%s/input0", gameport->phys);
219
220 guillemot->type = guillemot_type + i; 226 guillemot->type = guillemot_type + i;
221 227
222 guillemot->dev.private = guillemot; 228 input_dev->name = guillemot_type[i].name;
223 guillemot->dev.open = guillemot_open; 229 input_dev->phys = guillemot->phys;
224 guillemot->dev.close = guillemot_close; 230 input_dev->id.bustype = BUS_GAMEPORT;
231 input_dev->id.vendor = GAMEPORT_ID_VENDOR_GUILLEMOT;
232 input_dev->id.product = guillemot_type[i].id;
233 input_dev->id.version = (int)data[14] << 8 | data[15];
234 input_dev->cdev.dev = &gameport->dev;
235 input_dev->private = guillemot;
225 236
226 guillemot->dev.name = guillemot_type[i].name; 237 input_dev->open = guillemot_open;
227 guillemot->dev.phys = guillemot->phys; 238 input_dev->close = guillemot_close;
228 guillemot->dev.id.bustype = BUS_GAMEPORT;
229 guillemot->dev.id.vendor = GAMEPORT_ID_VENDOR_GUILLEMOT;
230 guillemot->dev.id.product = guillemot_type[i].id;
231 guillemot->dev.id.version = (int)data[14] << 8 | data[15];
232 239
233 guillemot->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 240 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
234 241
235 for (i = 0; (t = guillemot->type->abs[i]) >= 0; i++) 242 for (i = 0; (t = guillemot->type->abs[i]) >= 0; i++)
236 input_set_abs_params(&guillemot->dev, t, 0, 255, 0, 0); 243 input_set_abs_params(input_dev, t, 0, 255, 0, 0);
237 244
238 if (guillemot->type->hat) { 245 if (guillemot->type->hat) {
239 input_set_abs_params(&guillemot->dev, ABS_HAT0X, -1, 1, 0, 0); 246 input_set_abs_params(input_dev, ABS_HAT0X, -1, 1, 0, 0);
240 input_set_abs_params(&guillemot->dev, ABS_HAT0Y, -1, 1, 0, 0); 247 input_set_abs_params(input_dev, ABS_HAT0Y, -1, 1, 0, 0);
241 } 248 }
242 249
243 for (i = 0; (t = guillemot->type->btn[i]) >= 0; i++) 250 for (i = 0; (t = guillemot->type->btn[i]) >= 0; i++)
244 set_bit(t, guillemot->dev.keybit); 251 set_bit(t, input_dev->keybit);
245 252
246 input_register_device(&guillemot->dev); 253 input_register_device(guillemot->dev);
247 printk(KERN_INFO "input: %s ver %d.%02d on %s\n",
248 guillemot->type->name, data[14], data[15], gameport->phys);
249 254
250 return 0; 255 return 0;
251 256
252fail2: gameport_close(gameport); 257fail2: gameport_close(gameport);
253fail1: gameport_set_drvdata(gameport, NULL); 258fail1: gameport_set_drvdata(gameport, NULL);
259 input_free_device(input_dev);
254 kfree(guillemot); 260 kfree(guillemot);
255 return err; 261 return err;
256} 262}
@@ -260,7 +266,7 @@ static void guillemot_disconnect(struct gameport *gameport)
260 struct guillemot *guillemot = gameport_get_drvdata(gameport); 266 struct guillemot *guillemot = gameport_get_drvdata(gameport);
261 267
262 printk(KERN_INFO "guillemot.c: Failed %d reads out of %d on %s\n", guillemot->reads, guillemot->bads, guillemot->phys); 268 printk(KERN_INFO "guillemot.c: Failed %d reads out of %d on %s\n", guillemot->reads, guillemot->bads, guillemot->phys);
263 input_unregister_device(&guillemot->dev); 269 input_unregister_device(guillemot->dev);
264 gameport_close(gameport); 270 gameport_close(gameport);
265 kfree(guillemot); 271 kfree(guillemot);
266} 272}
diff --git a/drivers/input/joystick/iforce/iforce-main.c b/drivers/input/joystick/iforce/iforce-main.c
index e31b7b93fde2..64b9c31c47fc 100644
--- a/drivers/input/joystick/iforce/iforce-main.c
+++ b/drivers/input/joystick/iforce/iforce-main.c
@@ -144,7 +144,7 @@ static int iforce_upload_effect(struct input_dev *dev, struct ff_effect *effect)
144 int is_update; 144 int is_update;
145 145
146/* Check this effect type is supported by this device */ 146/* Check this effect type is supported by this device */
147 if (!test_bit(effect->type, iforce->dev.ffbit)) 147 if (!test_bit(effect->type, iforce->dev->ffbit))
148 return -EINVAL; 148 return -EINVAL;
149 149
150/* 150/*
@@ -152,30 +152,31 @@ static int iforce_upload_effect(struct input_dev *dev, struct ff_effect *effect)
152 */ 152 */
153 if (effect->id == -1) { 153 if (effect->id == -1) {
154 154
155 for (id=0; id < FF_EFFECTS_MAX; ++id) 155 for (id = 0; id < FF_EFFECTS_MAX; ++id)
156 if (!test_and_set_bit(FF_CORE_IS_USED, iforce->core_effects[id].flags)) break; 156 if (!test_and_set_bit(FF_CORE_IS_USED, iforce->core_effects[id].flags))
157 break;
157 158
158 if ( id == FF_EFFECTS_MAX || id >= iforce->dev.ff_effects_max) 159 if (id == FF_EFFECTS_MAX || id >= iforce->dev->ff_effects_max)
159 return -ENOMEM; 160 return -ENOMEM;
160 161
161 effect->id = id; 162 effect->id = id;
162 iforce->core_effects[id].owner = current->pid; 163 iforce->core_effects[id].owner = current->pid;
163 iforce->core_effects[id].flags[0] = (1<<FF_CORE_IS_USED); /* Only IS_USED bit must be set */ 164 iforce->core_effects[id].flags[0] = (1 << FF_CORE_IS_USED); /* Only IS_USED bit must be set */
164 165
165 is_update = FALSE; 166 is_update = FALSE;
166 } 167 }
167 else { 168 else {
168 /* We want to update an effect */ 169 /* We want to update an effect */
169 if (!CHECK_OWNERSHIP(effect->id, iforce)) return -EACCES; 170 if (!CHECK_OWNERSHIP(effect->id, iforce))
171 return -EACCES;
170 172
171 /* Parameter type cannot be updated */ 173 /* Parameter type cannot be updated */
172 if (effect->type != iforce->core_effects[effect->id].effect.type) 174 if (effect->type != iforce->core_effects[effect->id].effect.type)
173 return -EINVAL; 175 return -EINVAL;
174 176
175 /* Check the effect is not already being updated */ 177 /* Check the effect is not already being updated */
176 if (test_bit(FF_CORE_UPDATE, iforce->core_effects[effect->id].flags)) { 178 if (test_bit(FF_CORE_UPDATE, iforce->core_effects[effect->id].flags))
177 return -EAGAIN; 179 return -EAGAIN;
178 }
179 180
180 is_update = TRUE; 181 is_update = TRUE;
181 } 182 }
@@ -339,15 +340,19 @@ void iforce_delete_device(struct iforce *iforce)
339 340
340int iforce_init_device(struct iforce *iforce) 341int iforce_init_device(struct iforce *iforce)
341{ 342{
343 struct input_dev *input_dev;
342 unsigned char c[] = "CEOV"; 344 unsigned char c[] = "CEOV";
343 int i; 345 int i;
344 346
347 input_dev = input_allocate_device();
348 if (input_dev)
349 return -ENOMEM;
350
345 init_waitqueue_head(&iforce->wait); 351 init_waitqueue_head(&iforce->wait);
346 spin_lock_init(&iforce->xmit_lock); 352 spin_lock_init(&iforce->xmit_lock);
347 init_MUTEX(&iforce->mem_mutex); 353 init_MUTEX(&iforce->mem_mutex);
348 iforce->xmit.buf = iforce->xmit_data; 354 iforce->xmit.buf = iforce->xmit_data;
349 355 iforce->dev = input_dev;
350 iforce->dev.ff_effects_max = 10;
351 356
352/* 357/*
353 * Input device fields. 358 * Input device fields.
@@ -356,26 +361,27 @@ int iforce_init_device(struct iforce *iforce)
356 switch (iforce->bus) { 361 switch (iforce->bus) {
357#ifdef CONFIG_JOYSTICK_IFORCE_USB 362#ifdef CONFIG_JOYSTICK_IFORCE_USB
358 case IFORCE_USB: 363 case IFORCE_USB:
359 iforce->dev.id.bustype = BUS_USB; 364 input_dev->id.bustype = BUS_USB;
360 iforce->dev.dev = &iforce->usbdev->dev; 365 input_dev->cdev.dev = &iforce->usbdev->dev;
361 break; 366 break;
362#endif 367#endif
363#ifdef CONFIG_JOYSTICK_IFORCE_232 368#ifdef CONFIG_JOYSTICK_IFORCE_232
364 case IFORCE_232: 369 case IFORCE_232:
365 iforce->dev.id.bustype = BUS_RS232; 370 input_dev->id.bustype = BUS_RS232;
366 iforce->dev.dev = &iforce->serio->dev; 371 input_dev->cdev.dev = &iforce->serio->dev;
367 break; 372 break;
368#endif 373#endif
369 } 374 }
370 375
371 iforce->dev.private = iforce; 376 input_dev->private = iforce;
372 iforce->dev.name = "Unknown I-Force device"; 377 input_dev->name = "Unknown I-Force device";
373 iforce->dev.open = iforce_open; 378 input_dev->open = iforce_open;
374 iforce->dev.close = iforce_release; 379 input_dev->close = iforce_release;
375 iforce->dev.flush = iforce_flush; 380 input_dev->flush = iforce_flush;
376 iforce->dev.event = iforce_input_event; 381 input_dev->event = iforce_input_event;
377 iforce->dev.upload_effect = iforce_upload_effect; 382 input_dev->upload_effect = iforce_upload_effect;
378 iforce->dev.erase_effect = iforce_erase_effect; 383 input_dev->erase_effect = iforce_erase_effect;
384 input_dev->ff_effects_max = 10;
379 385
380/* 386/*
381 * On-device memory allocation. 387 * On-device memory allocation.
@@ -399,7 +405,8 @@ int iforce_init_device(struct iforce *iforce)
399 405
400 if (i == 20) { /* 5 seconds */ 406 if (i == 20) { /* 5 seconds */
401 printk(KERN_ERR "iforce-main.c: Timeout waiting for response from device.\n"); 407 printk(KERN_ERR "iforce-main.c: Timeout waiting for response from device.\n");
402 return -1; 408 input_free_device(input_dev);
409 return -ENODEV;
403 } 410 }
404 411
405/* 412/*
@@ -407,12 +414,12 @@ int iforce_init_device(struct iforce *iforce)
407 */ 414 */
408 415
409 if (!iforce_get_id_packet(iforce, "M")) 416 if (!iforce_get_id_packet(iforce, "M"))
410 iforce->dev.id.vendor = (iforce->edata[2] << 8) | iforce->edata[1]; 417 input_dev->id.vendor = (iforce->edata[2] << 8) | iforce->edata[1];
411 else 418 else
412 printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet M\n"); 419 printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet M\n");
413 420
414 if (!iforce_get_id_packet(iforce, "P")) 421 if (!iforce_get_id_packet(iforce, "P"))
415 iforce->dev.id.product = (iforce->edata[2] << 8) | iforce->edata[1]; 422 input_dev->id.product = (iforce->edata[2] << 8) | iforce->edata[1];
416 else 423 else
417 printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet P\n"); 424 printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet P\n");
418 425
@@ -422,15 +429,15 @@ int iforce_init_device(struct iforce *iforce)
422 printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet B\n"); 429 printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet B\n");
423 430
424 if (!iforce_get_id_packet(iforce, "N")) 431 if (!iforce_get_id_packet(iforce, "N"))
425 iforce->dev.ff_effects_max = iforce->edata[1]; 432 iforce->dev->ff_effects_max = iforce->edata[1];
426 else 433 else
427 printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet N\n"); 434 printk(KERN_WARNING "iforce-main.c: Device does not respond to id packet N\n");
428 435
429 /* Check if the device can store more effects than the driver can really handle */ 436 /* Check if the device can store more effects than the driver can really handle */
430 if (iforce->dev.ff_effects_max > FF_EFFECTS_MAX) { 437 if (iforce->dev->ff_effects_max > FF_EFFECTS_MAX) {
431 printk(KERN_WARNING "input??: Device can handle %d effects, but N_EFFECTS_MAX is set to %d in iforce.h\n", 438 printk(KERN_WARNING "input??: Device can handle %d effects, but N_EFFECTS_MAX is set to %d in iforce.h\n",
432 iforce->dev.ff_effects_max, FF_EFFECTS_MAX); 439 iforce->dev->ff_effects_max, FF_EFFECTS_MAX);
433 iforce->dev.ff_effects_max = FF_EFFECTS_MAX; 440 iforce->dev->ff_effects_max = FF_EFFECTS_MAX;
434 } 441 }
435 442
436/* 443/*
@@ -453,29 +460,28 @@ int iforce_init_device(struct iforce *iforce)
453 */ 460 */
454 461
455 for (i = 0; iforce_device[i].idvendor; i++) 462 for (i = 0; iforce_device[i].idvendor; i++)
456 if (iforce_device[i].idvendor == iforce->dev.id.vendor && 463 if (iforce_device[i].idvendor == input_dev->id.vendor &&
457 iforce_device[i].idproduct == iforce->dev.id.product) 464 iforce_device[i].idproduct == input_dev->id.product)
458 break; 465 break;
459 466
460 iforce->type = iforce_device + i; 467 iforce->type = iforce_device + i;
461 iforce->dev.name = iforce->type->name; 468 input_dev->name = iforce->type->name;
462 469
463/* 470/*
464 * Set input device bitfields and ranges. 471 * Set input device bitfields and ranges.
465 */ 472 */
466 473
467 iforce->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_FF) | BIT(EV_FF_STATUS); 474 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_FF) | BIT(EV_FF_STATUS);
468 475
469 for (i = 0; iforce->type->btn[i] >= 0; i++) { 476 for (i = 0; iforce->type->btn[i] >= 0; i++) {
470 signed short t = iforce->type->btn[i]; 477 signed short t = iforce->type->btn[i];
471 set_bit(t, iforce->dev.keybit); 478 set_bit(t, input_dev->keybit);
472 } 479 }
473 set_bit(BTN_DEAD, iforce->dev.keybit); 480 set_bit(BTN_DEAD, input_dev->keybit);
474 481
475 for (i = 0; iforce->type->abs[i] >= 0; i++) { 482 for (i = 0; iforce->type->abs[i] >= 0; i++) {
476 483
477 signed short t = iforce->type->abs[i]; 484 signed short t = iforce->type->abs[i];
478 set_bit(t, iforce->dev.absbit);
479 485
480 switch (t) { 486 switch (t) {
481 487
@@ -483,52 +489,42 @@ int iforce_init_device(struct iforce *iforce)
483 case ABS_Y: 489 case ABS_Y:
484 case ABS_WHEEL: 490 case ABS_WHEEL:
485 491
486 iforce->dev.absmax[t] = 1920; 492 input_set_abs_params(input_dev, t, -1920, 1920, 16, 128);
487 iforce->dev.absmin[t] = -1920; 493 set_bit(t, input_dev->ffbit);
488 iforce->dev.absflat[t] = 128;
489 iforce->dev.absfuzz[t] = 16;
490
491 set_bit(t, iforce->dev.ffbit);
492 break; 494 break;
493 495
494 case ABS_THROTTLE: 496 case ABS_THROTTLE:
495 case ABS_GAS: 497 case ABS_GAS:
496 case ABS_BRAKE: 498 case ABS_BRAKE:
497 499
498 iforce->dev.absmax[t] = 255; 500 input_set_abs_params(input_dev, t, 0, 255, 0, 0);
499 iforce->dev.absmin[t] = 0;
500 break; 501 break;
501 502
502 case ABS_RUDDER: 503 case ABS_RUDDER:
503 504
504 iforce->dev.absmax[t] = 127; 505 input_set_abs_params(input_dev, t, -128, 127, 0, 0);
505 iforce->dev.absmin[t] = -128;
506 break; 506 break;
507 507
508 case ABS_HAT0X: 508 case ABS_HAT0X:
509 case ABS_HAT0Y: 509 case ABS_HAT0Y:
510 case ABS_HAT1X: 510 case ABS_HAT1X:
511 case ABS_HAT1Y: 511 case ABS_HAT1Y:
512 iforce->dev.absmax[t] = 1; 512
513 iforce->dev.absmin[t] = -1; 513 input_set_abs_params(input_dev, t, -1, 1, 0, 0);
514 break; 514 break;
515 } 515 }
516 } 516 }
517 517
518 for (i = 0; iforce->type->ff[i] >= 0; i++) 518 for (i = 0; iforce->type->ff[i] >= 0; i++)
519 set_bit(iforce->type->ff[i], iforce->dev.ffbit); 519 set_bit(iforce->type->ff[i], input_dev->ffbit);
520 520
521/* 521/*
522 * Register input device. 522 * Register input device.
523 */ 523 */
524 524
525 input_register_device(&iforce->dev); 525 input_register_device(iforce->dev);
526
527 printk(KERN_DEBUG "iforce->dev.open = %p\n", iforce->dev.open);
528 526
529 printk(KERN_INFO "input: %s [%d effects, %ld bytes memory]\n", 527 printk(KERN_DEBUG "iforce->dev->open = %p\n", iforce->dev->open);
530 iforce->dev.name, iforce->dev.ff_effects_max,
531 iforce->device_memory.end);
532 528
533 return 0; 529 return 0;
534} 530}
diff --git a/drivers/input/joystick/iforce/iforce-packets.c b/drivers/input/joystick/iforce/iforce-packets.c
index e5a31e55d3e2..4a2629243e19 100644
--- a/drivers/input/joystick/iforce/iforce-packets.c
+++ b/drivers/input/joystick/iforce/iforce-packets.c
@@ -139,7 +139,8 @@ printk(KERN_DEBUG "iforce-packets.c: control_playback %d %d\n", id, value);
139static int mark_core_as_ready(struct iforce *iforce, unsigned short addr) 139static int mark_core_as_ready(struct iforce *iforce, unsigned short addr)
140{ 140{
141 int i; 141 int i;
142 for (i=0; i<iforce->dev.ff_effects_max; ++i) { 142
143 for (i = 0; i < iforce->dev->ff_effects_max; ++i) {
143 if (test_bit(FF_CORE_IS_USED, iforce->core_effects[i].flags) && 144 if (test_bit(FF_CORE_IS_USED, iforce->core_effects[i].flags) &&
144 (iforce->core_effects[i].mod1_chunk.start == addr || 145 (iforce->core_effects[i].mod1_chunk.start == addr ||
145 iforce->core_effects[i].mod2_chunk.start == addr)) { 146 iforce->core_effects[i].mod2_chunk.start == addr)) {
@@ -153,7 +154,7 @@ static int mark_core_as_ready(struct iforce *iforce, unsigned short addr)
153 154
154void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data, struct pt_regs *regs) 155void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data, struct pt_regs *regs)
155{ 156{
156 struct input_dev *dev = &iforce->dev; 157 struct input_dev *dev = iforce->dev;
157 int i; 158 int i;
158 static int being_used = 0; 159 static int being_used = 0;
159 160
diff --git a/drivers/input/joystick/iforce/iforce-serio.c b/drivers/input/joystick/iforce/iforce-serio.c
index 11f51905cba7..64a78c515484 100644
--- a/drivers/input/joystick/iforce/iforce-serio.c
+++ b/drivers/input/joystick/iforce/iforce-serio.c
@@ -131,11 +131,10 @@ static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv)
131 struct iforce *iforce; 131 struct iforce *iforce;
132 int err; 132 int err;
133 133
134 if (!(iforce = kmalloc(sizeof(struct iforce), GFP_KERNEL))) 134 iforce = kzalloc(sizeof(struct iforce), GFP_KERNEL);
135 if (!iforce)
135 return -ENOMEM; 136 return -ENOMEM;
136 137
137 memset(iforce, 0, sizeof(struct iforce));
138
139 iforce->bus = IFORCE_232; 138 iforce->bus = IFORCE_232;
140 iforce->serio = serio; 139 iforce->serio = serio;
141 140
@@ -148,7 +147,8 @@ static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv)
148 return err; 147 return err;
149 } 148 }
150 149
151 if (iforce_init_device(iforce)) { 150 err = iforce_init_device(iforce);
151 if (err) {
152 serio_close(serio); 152 serio_close(serio);
153 serio_set_drvdata(serio, NULL); 153 serio_set_drvdata(serio, NULL);
154 kfree(iforce); 154 kfree(iforce);
@@ -162,7 +162,7 @@ static void iforce_serio_disconnect(struct serio *serio)
162{ 162{
163 struct iforce *iforce = serio_get_drvdata(serio); 163 struct iforce *iforce = serio_get_drvdata(serio);
164 164
165 input_unregister_device(&iforce->dev); 165 input_unregister_device(iforce->dev);
166 serio_close(serio); 166 serio_close(serio);
167 serio_set_drvdata(serio, NULL); 167 serio_set_drvdata(serio, NULL);
168 kfree(iforce); 168 kfree(iforce);
diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c
index 58600f91eff5..64b4a3080985 100644
--- a/drivers/input/joystick/iforce/iforce-usb.c
+++ b/drivers/input/joystick/iforce/iforce-usb.c
@@ -135,28 +135,24 @@ static int iforce_usb_probe(struct usb_interface *intf,
135 struct usb_host_interface *interface; 135 struct usb_host_interface *interface;
136 struct usb_endpoint_descriptor *epirq, *epout; 136 struct usb_endpoint_descriptor *epirq, *epout;
137 struct iforce *iforce; 137 struct iforce *iforce;
138 int err = -ENOMEM;
138 139
139 interface = intf->cur_altsetting; 140 interface = intf->cur_altsetting;
140 141
141 epirq = &interface->endpoint[0].desc; 142 epirq = &interface->endpoint[0].desc;
142 epout = &interface->endpoint[1].desc; 143 epout = &interface->endpoint[1].desc;
143 144
144 if (!(iforce = kmalloc(sizeof(struct iforce) + 32, GFP_KERNEL))) 145 if (!(iforce = kzalloc(sizeof(struct iforce) + 32, GFP_KERNEL)))
145 goto fail; 146 goto fail;
146 147
147 memset(iforce, 0, sizeof(struct iforce)); 148 if (!(iforce->irq = usb_alloc_urb(0, GFP_KERNEL)))
148
149 if (!(iforce->irq = usb_alloc_urb(0, GFP_KERNEL))) {
150 goto fail; 149 goto fail;
151 }
152 150
153 if (!(iforce->out = usb_alloc_urb(0, GFP_KERNEL))) { 151 if (!(iforce->out = usb_alloc_urb(0, GFP_KERNEL)))
154 goto fail; 152 goto fail;
155 }
156 153
157 if (!(iforce->ctrl = usb_alloc_urb(0, GFP_KERNEL))) { 154 if (!(iforce->ctrl = usb_alloc_urb(0, GFP_KERNEL)))
158 goto fail; 155 goto fail;
159 }
160 156
161 iforce->bus = IFORCE_USB; 157 iforce->bus = IFORCE_USB;
162 iforce->usbdev = dev; 158 iforce->usbdev = dev;
@@ -174,7 +170,9 @@ static int iforce_usb_probe(struct usb_interface *intf,
174 usb_fill_control_urb(iforce->ctrl, dev, usb_rcvctrlpipe(dev, 0), 170 usb_fill_control_urb(iforce->ctrl, dev, usb_rcvctrlpipe(dev, 0),
175 (void*) &iforce->cr, iforce->edata, 16, iforce_usb_ctrl, iforce); 171 (void*) &iforce->cr, iforce->edata, 16, iforce_usb_ctrl, iforce);
176 172
177 if (iforce_init_device(iforce)) goto fail; 173 err = iforce_init_device(iforce);
174 if (err)
175 goto fail;
178 176
179 usb_set_intfdata(intf, iforce); 177 usb_set_intfdata(intf, iforce);
180 return 0; 178 return 0;
@@ -187,7 +185,7 @@ fail:
187 kfree(iforce); 185 kfree(iforce);
188 } 186 }
189 187
190 return -ENODEV; 188 return err;
191} 189}
192 190
193/* Called by iforce_delete() */ 191/* Called by iforce_delete() */
@@ -211,7 +209,7 @@ static void iforce_usb_disconnect(struct usb_interface *intf)
211 usb_set_intfdata(intf, NULL); 209 usb_set_intfdata(intf, NULL);
212 if (iforce) { 210 if (iforce) {
213 iforce->usbdev = NULL; 211 iforce->usbdev = NULL;
214 input_unregister_device(&iforce->dev); 212 input_unregister_device(iforce->dev);
215 213
216 if (!open) { 214 if (!open) {
217 iforce_delete_device(iforce); 215 iforce_delete_device(iforce);
diff --git a/drivers/input/joystick/iforce/iforce.h b/drivers/input/joystick/iforce/iforce.h
index bce247bc300b..146f406b8f8a 100644
--- a/drivers/input/joystick/iforce/iforce.h
+++ b/drivers/input/joystick/iforce/iforce.h
@@ -117,7 +117,7 @@ struct iforce_device {
117}; 117};
118 118
119struct iforce { 119struct iforce {
120 struct input_dev dev; /* Input device interface */ 120 struct input_dev *dev; /* Input device interface */
121 struct iforce_device *type; 121 struct iforce_device *type;
122 int bus; 122 int bus;
123 123
diff --git a/drivers/input/joystick/interact.c b/drivers/input/joystick/interact.c
index d7b3472bd686..c4ed01758226 100644
--- a/drivers/input/joystick/interact.c
+++ b/drivers/input/joystick/interact.c
@@ -38,6 +38,7 @@
38#include <linux/init.h> 38#include <linux/init.h>
39#include <linux/gameport.h> 39#include <linux/gameport.h>
40#include <linux/input.h> 40#include <linux/input.h>
41#include <linux/jiffies.h>
41 42
42#define DRIVER_DESC "InterAct digital joystick driver" 43#define DRIVER_DESC "InterAct digital joystick driver"
43 44
@@ -54,7 +55,7 @@ MODULE_LICENSE("GPL");
54 55
55struct interact { 56struct interact {
56 struct gameport *gameport; 57 struct gameport *gameport;
57 struct input_dev dev; 58 struct input_dev *dev;
58 int bads; 59 int bads;
59 int reads; 60 int reads;
60 unsigned char type; 61 unsigned char type;
@@ -130,7 +131,7 @@ static int interact_read_packet(struct gameport *gameport, int length, u32 *data
130static void interact_poll(struct gameport *gameport) 131static void interact_poll(struct gameport *gameport)
131{ 132{
132 struct interact *interact = gameport_get_drvdata(gameport); 133 struct interact *interact = gameport_get_drvdata(gameport);
133 struct input_dev *dev = &interact->dev; 134 struct input_dev *dev = interact->dev;
134 u32 data[3]; 135 u32 data[3];
135 int i; 136 int i;
136 137
@@ -208,14 +209,20 @@ static void interact_close(struct input_dev *dev)
208static int interact_connect(struct gameport *gameport, struct gameport_driver *drv) 209static int interact_connect(struct gameport *gameport, struct gameport_driver *drv)
209{ 210{
210 struct interact *interact; 211 struct interact *interact;
212 struct input_dev *input_dev;
211 __u32 data[3]; 213 __u32 data[3];
212 int i, t; 214 int i, t;
213 int err; 215 int err;
214 216
215 if (!(interact = kzalloc(sizeof(struct interact), GFP_KERNEL))) 217 interact = kzalloc(sizeof(struct interact), GFP_KERNEL);
216 return -ENOMEM; 218 input_dev = input_allocate_device();
219 if (!interact || !input_dev) {
220 err = -ENOMEM;
221 goto fail1;
222 }
217 223
218 interact->gameport = gameport; 224 interact->gameport = gameport;
225 interact->dev = input_dev;
219 226
220 gameport_set_drvdata(gameport, interact); 227 gameport_set_drvdata(gameport, interact);
221 228
@@ -249,41 +256,40 @@ static int interact_connect(struct gameport *gameport, struct gameport_driver *d
249 interact->type = i; 256 interact->type = i;
250 interact->length = interact_type[i].length; 257 interact->length = interact_type[i].length;
251 258
252 interact->dev.private = interact; 259 input_dev->name = interact_type[i].name;
253 interact->dev.open = interact_open; 260 input_dev->phys = interact->phys;
254 interact->dev.close = interact_close; 261 input_dev->id.bustype = BUS_GAMEPORT;
262 input_dev->id.vendor = GAMEPORT_ID_VENDOR_INTERACT;
263 input_dev->id.product = interact_type[i].id;
264 input_dev->id.version = 0x0100;
265 input_dev->private = interact;
255 266
256 interact->dev.name = interact_type[i].name; 267 input_dev->open = interact_open;
257 interact->dev.phys = interact->phys; 268 input_dev->close = interact_close;
258 interact->dev.id.bustype = BUS_GAMEPORT;
259 interact->dev.id.vendor = GAMEPORT_ID_VENDOR_INTERACT;
260 interact->dev.id.product = interact_type[i].id;
261 interact->dev.id.version = 0x0100;
262 269
263 interact->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 270 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
264 271
265 for (i = 0; (t = interact_type[interact->type].abs[i]) >= 0; i++) { 272 for (i = 0; (t = interact_type[interact->type].abs[i]) >= 0; i++) {
266 set_bit(t, interact->dev.absbit); 273 set_bit(t, input_dev->absbit);
267 if (i < interact_type[interact->type].b8) { 274 if (i < interact_type[interact->type].b8) {
268 interact->dev.absmin[t] = 0; 275 input_dev->absmin[t] = 0;
269 interact->dev.absmax[t] = 255; 276 input_dev->absmax[t] = 255;
270 } else { 277 } else {
271 interact->dev.absmin[t] = -1; 278 input_dev->absmin[t] = -1;
272 interact->dev.absmax[t] = 1; 279 input_dev->absmax[t] = 1;
273 } 280 }
274 } 281 }
275 282
276 for (i = 0; (t = interact_type[interact->type].btn[i]) >= 0; i++) 283 for (i = 0; (t = interact_type[interact->type].btn[i]) >= 0; i++)
277 set_bit(t, interact->dev.keybit); 284 set_bit(t, input_dev->keybit);
278 285
279 input_register_device(&interact->dev); 286 input_register_device(interact->dev);
280 printk(KERN_INFO "input: %s on %s\n",
281 interact_type[interact->type].name, gameport->phys);
282 287
283 return 0; 288 return 0;
284 289
285fail2: gameport_close(gameport); 290fail2: gameport_close(gameport);
286fail1: gameport_set_drvdata(gameport, NULL); 291fail1: gameport_set_drvdata(gameport, NULL);
292 input_free_device(input_dev);
287 kfree(interact); 293 kfree(interact);
288 return err; 294 return err;
289} 295}
@@ -292,7 +298,7 @@ static void interact_disconnect(struct gameport *gameport)
292{ 298{
293 struct interact *interact = gameport_get_drvdata(gameport); 299 struct interact *interact = gameport_get_drvdata(gameport);
294 300
295 input_unregister_device(&interact->dev); 301 input_unregister_device(interact->dev);
296 gameport_close(gameport); 302 gameport_close(gameport);
297 gameport_set_drvdata(gameport, NULL); 303 gameport_set_drvdata(gameport, NULL);
298 kfree(interact); 304 kfree(interact);
diff --git a/drivers/input/joystick/joydump.c b/drivers/input/joystick/joydump.c
index 4234ccaf9146..88ec5a918f2e 100644
--- a/drivers/input/joystick/joydump.c
+++ b/drivers/input/joystick/joydump.c
@@ -34,6 +34,7 @@
34#include <linux/kernel.h> 34#include <linux/kernel.h>
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/slab.h>
37 38
38#define DRIVER_DESC "Gameport data dumper module" 39#define DRIVER_DESC "Gameport data dumper module"
39 40
diff --git a/drivers/input/joystick/magellan.c b/drivers/input/joystick/magellan.c
index 1ba503627242..ca3cc2319d6a 100644
--- a/drivers/input/joystick/magellan.c
+++ b/drivers/input/joystick/magellan.c
@@ -49,14 +49,13 @@ MODULE_LICENSE("GPL");
49 49
50static int magellan_buttons[] = { BTN_0, BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7, BTN_8 }; 50static int magellan_buttons[] = { BTN_0, BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7, BTN_8 };
51static int magellan_axes[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ }; 51static int magellan_axes[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ };
52static char *magellan_name = "LogiCad3D Magellan / SpaceMouse";
53 52
54/* 53/*
55 * Per-Magellan data. 54 * Per-Magellan data.
56 */ 55 */
57 56
58struct magellan { 57struct magellan {
59 struct input_dev dev; 58 struct input_dev *dev;
60 int idx; 59 int idx;
61 unsigned char data[MAGELLAN_MAX_LENGTH]; 60 unsigned char data[MAGELLAN_MAX_LENGTH];
62 char phys[32]; 61 char phys[32];
@@ -85,7 +84,7 @@ static int magellan_crunch_nibbles(unsigned char *data, int count)
85 84
86static void magellan_process_packet(struct magellan* magellan, struct pt_regs *regs) 85static void magellan_process_packet(struct magellan* magellan, struct pt_regs *regs)
87{ 86{
88 struct input_dev *dev = &magellan->dev; 87 struct input_dev *dev = magellan->dev;
89 unsigned char *data = magellan->data; 88 unsigned char *data = magellan->data;
90 int i, t; 89 int i, t;
91 90
@@ -138,9 +137,9 @@ static void magellan_disconnect(struct serio *serio)
138{ 137{
139 struct magellan* magellan = serio_get_drvdata(serio); 138 struct magellan* magellan = serio_get_drvdata(serio);
140 139
141 input_unregister_device(&magellan->dev);
142 serio_close(serio); 140 serio_close(serio);
143 serio_set_drvdata(serio, NULL); 141 serio_set_drvdata(serio, NULL);
142 input_unregister_device(magellan->dev);
144 kfree(magellan); 143 kfree(magellan);
145} 144}
146 145
@@ -153,52 +152,48 @@ static void magellan_disconnect(struct serio *serio)
153static int magellan_connect(struct serio *serio, struct serio_driver *drv) 152static int magellan_connect(struct serio *serio, struct serio_driver *drv)
154{ 153{
155 struct magellan *magellan; 154 struct magellan *magellan;
156 int i, t; 155 struct input_dev *input_dev;
157 int err; 156 int err = -ENOMEM;
158 157 int i;
159 if (!(magellan = kmalloc(sizeof(struct magellan), GFP_KERNEL)))
160 return -ENOMEM;
161 158
162 memset(magellan, 0, sizeof(struct magellan)); 159 magellan = kzalloc(sizeof(struct magellan), GFP_KERNEL);
160 input_dev = input_allocate_device();
161 if (!magellan || !input_dev)
162 goto fail;
163 163
164 magellan->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 164 magellan->dev = input_dev;
165 sprintf(magellan->phys, "%s/input0", serio->phys);
165 166
166 for (i = 0; i < 9; i++) 167 input_dev->name = "LogiCad3D Magellan / SpaceMouse";
167 set_bit(magellan_buttons[i], magellan->dev.keybit); 168 input_dev->phys = magellan->phys;
169 input_dev->id.bustype = BUS_RS232;
170 input_dev->id.vendor = SERIO_MAGELLAN;
171 input_dev->id.product = 0x0001;
172 input_dev->id.version = 0x0100;
173 input_dev->cdev.dev = &serio->dev;
174 input_dev->private = magellan;
168 175
169 for (i = 0; i < 6; i++) { 176 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
170 t = magellan_axes[i];
171 set_bit(t, magellan->dev.absbit);
172 magellan->dev.absmin[t] = -360;
173 magellan->dev.absmax[t] = 360;
174 }
175 177
176 sprintf(magellan->phys, "%s/input0", serio->phys); 178 for (i = 0; i < 9; i++)
179 set_bit(magellan_buttons[i], input_dev->keybit);
177 180
178 init_input_dev(&magellan->dev); 181 for (i = 0; i < 6; i++)
179 magellan->dev.private = magellan; 182 input_set_abs_params(input_dev, magellan_axes[i], -360, 360, 0, 0);
180 magellan->dev.name = magellan_name;
181 magellan->dev.phys = magellan->phys;
182 magellan->dev.id.bustype = BUS_RS232;
183 magellan->dev.id.vendor = SERIO_MAGELLAN;
184 magellan->dev.id.product = 0x0001;
185 magellan->dev.id.version = 0x0100;
186 magellan->dev.dev = &serio->dev;
187 183
188 serio_set_drvdata(serio, magellan); 184 serio_set_drvdata(serio, magellan);
189 185
190 err = serio_open(serio, drv); 186 err = serio_open(serio, drv);
191 if (err) { 187 if (err)
192 serio_set_drvdata(serio, NULL); 188 goto fail;
193 kfree(magellan);
194 return err;
195 }
196
197 input_register_device(&magellan->dev);
198
199 printk(KERN_INFO "input: %s on %s\n", magellan_name, serio->phys);
200 189
190 input_register_device(magellan->dev);
201 return 0; 191 return 0;
192
193 fail: serio_set_drvdata(serio, NULL);
194 input_free_device(input_dev);
195 kfree(magellan);
196 return err;
202} 197}
203 198
204/* 199/*
diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
index 9e0353721a35..78dd163cd702 100644
--- a/drivers/input/joystick/sidewinder.c
+++ b/drivers/input/joystick/sidewinder.c
@@ -33,6 +33,7 @@
33#include <linux/init.h> 33#include <linux/init.h>
34#include <linux/input.h> 34#include <linux/input.h>
35#include <linux/gameport.h> 35#include <linux/gameport.h>
36#include <linux/jiffies.h>
36 37
37#define DRIVER_DESC "Microsoft SideWinder joystick family driver" 38#define DRIVER_DESC "Microsoft SideWinder joystick family driver"
38 39
@@ -113,7 +114,7 @@ static struct {
113 114
114struct sw { 115struct sw {
115 struct gameport *gameport; 116 struct gameport *gameport;
116 struct input_dev dev[4]; 117 struct input_dev *dev[4];
117 char name[64]; 118 char name[64];
118 char phys[4][32]; 119 char phys[4][32];
119 int length; 120 int length;
@@ -301,7 +302,7 @@ static int sw_check(__u64 t)
301static int sw_parse(unsigned char *buf, struct sw *sw) 302static int sw_parse(unsigned char *buf, struct sw *sw)
302{ 303{
303 int hat, i, j; 304 int hat, i, j;
304 struct input_dev *dev = sw->dev; 305 struct input_dev *dev;
305 306
306 switch (sw->type) { 307 switch (sw->type) {
307 308
@@ -310,6 +311,8 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
310 if (sw_check(GB(0,64)) || (hat = (GB(6,1) << 3) | GB(60,3)) > 8) 311 if (sw_check(GB(0,64)) || (hat = (GB(6,1) << 3) | GB(60,3)) > 8)
311 return -1; 312 return -1;
312 313
314 dev = sw->dev[0];
315
313 input_report_abs(dev, ABS_X, (GB( 3,3) << 7) | GB(16,7)); 316 input_report_abs(dev, ABS_X, (GB( 3,3) << 7) | GB(16,7));
314 input_report_abs(dev, ABS_Y, (GB( 0,3) << 7) | GB(24,7)); 317 input_report_abs(dev, ABS_Y, (GB( 0,3) << 7) | GB(24,7));
315 input_report_abs(dev, ABS_RZ, (GB(35,2) << 7) | GB(40,7)); 318 input_report_abs(dev, ABS_RZ, (GB(35,2) << 7) | GB(40,7));
@@ -335,13 +338,13 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
335 if (sw_parity(GB(i*15,15))) 338 if (sw_parity(GB(i*15,15)))
336 return -1; 339 return -1;
337 340
338 input_report_abs(dev + i, ABS_X, GB(i*15+3,1) - GB(i*15+2,1)); 341 input_report_abs(sw->dev[i], ABS_X, GB(i*15+3,1) - GB(i*15+2,1));
339 input_report_abs(dev + i, ABS_Y, GB(i*15+0,1) - GB(i*15+1,1)); 342 input_report_abs(sw->dev[i], ABS_Y, GB(i*15+0,1) - GB(i*15+1,1));
340 343
341 for (j = 0; j < 10; j++) 344 for (j = 0; j < 10; j++)
342 input_report_key(dev + i, sw_btn[SW_ID_GP][j], !GB(i*15+j+4,1)); 345 input_report_key(sw->dev[i], sw_btn[SW_ID_GP][j], !GB(i*15+j+4,1));
343 346
344 input_sync(dev + i); 347 input_sync(sw->dev[i]);
345 } 348 }
346 349
347 return 0; 350 return 0;
@@ -352,6 +355,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
352 if (!sw_parity(GB(0,48)) || (hat = GB(42,4)) > 8) 355 if (!sw_parity(GB(0,48)) || (hat = GB(42,4)) > 8)
353 return -1; 356 return -1;
354 357
358 dev = sw->dev[0];
355 input_report_abs(dev, ABS_X, GB( 9,10)); 359 input_report_abs(dev, ABS_X, GB( 9,10));
356 input_report_abs(dev, ABS_Y, GB(19,10)); 360 input_report_abs(dev, ABS_Y, GB(19,10));
357 input_report_abs(dev, ABS_RZ, GB(36, 6)); 361 input_report_abs(dev, ABS_RZ, GB(36, 6));
@@ -372,6 +376,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
372 if (!sw_parity(GB(0,43)) || (hat = GB(28,4)) > 8) 376 if (!sw_parity(GB(0,43)) || (hat = GB(28,4)) > 8)
373 return -1; 377 return -1;
374 378
379 dev = sw->dev[0];
375 input_report_abs(dev, ABS_X, GB( 0,10)); 380 input_report_abs(dev, ABS_X, GB( 0,10));
376 input_report_abs(dev, ABS_Y, GB(16,10)); 381 input_report_abs(dev, ABS_Y, GB(16,10));
377 input_report_abs(dev, ABS_THROTTLE, GB(32, 6)); 382 input_report_abs(dev, ABS_THROTTLE, GB(32, 6));
@@ -396,6 +401,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
396 if (!sw_parity(GB(0,33))) 401 if (!sw_parity(GB(0,33)))
397 return -1; 402 return -1;
398 403
404 dev = sw->dev[0];
399 input_report_abs(dev, ABS_RX, GB( 0,10)); 405 input_report_abs(dev, ABS_RX, GB( 0,10));
400 input_report_abs(dev, ABS_RUDDER, GB(10, 6)); 406 input_report_abs(dev, ABS_RUDDER, GB(10, 6));
401 input_report_abs(dev, ABS_THROTTLE, GB(16, 6)); 407 input_report_abs(dev, ABS_THROTTLE, GB(16, 6));
@@ -581,6 +587,7 @@ static int sw_guess_mode(unsigned char *buf, int len)
581static int sw_connect(struct gameport *gameport, struct gameport_driver *drv) 587static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
582{ 588{
583 struct sw *sw; 589 struct sw *sw;
590 struct input_dev *input_dev;
584 int i, j, k, l; 591 int i, j, k, l;
585 int err; 592 int err;
586 unsigned char *buf = NULL; /* [SW_LENGTH] */ 593 unsigned char *buf = NULL; /* [SW_LENGTH] */
@@ -729,42 +736,50 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
729 sprintf(sw->name, "Microsoft SideWinder %s", sw_name[sw->type]); 736 sprintf(sw->name, "Microsoft SideWinder %s", sw_name[sw->type]);
730 sprintf(sw->phys[i], "%s/input%d", gameport->phys, i); 737 sprintf(sw->phys[i], "%s/input%d", gameport->phys, i);
731 738
732 sw->dev[i].private = sw; 739 input_dev = input_allocate_device();
740 if (!input_dev) {
741 err = -ENOMEM;
742 goto fail3;
743 }
733 744
734 sw->dev[i].open = sw_open; 745 input_dev->name = sw->name;
735 sw->dev[i].close = sw_close; 746 input_dev->phys = sw->phys[i];
747 input_dev->id.bustype = BUS_GAMEPORT;
748 input_dev->id.vendor = GAMEPORT_ID_VENDOR_MICROSOFT;
749 input_dev->id.product = sw->type;
750 input_dev->id.version = 0x0100;
751 input_dev->cdev.dev = &gameport->dev;
752 input_dev->private = sw;
736 753
737 sw->dev[i].name = sw->name; 754 input_dev->open = sw_open;
738 sw->dev[i].phys = sw->phys[i]; 755 input_dev->close = sw_close;
739 sw->dev[i].id.bustype = BUS_GAMEPORT;
740 sw->dev[i].id.vendor = GAMEPORT_ID_VENDOR_MICROSOFT;
741 sw->dev[i].id.product = sw->type;
742 sw->dev[i].id.version = 0x0100;
743 756
744 sw->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 757 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
745 758
746 for (j = 0; (bits = sw_bit[sw->type][j]); j++) { 759 for (j = 0; (bits = sw_bit[sw->type][j]); j++) {
747 code = sw_abs[sw->type][j]; 760 code = sw_abs[sw->type][j];
748 set_bit(code, sw->dev[i].absbit); 761 set_bit(code, input_dev->absbit);
749 sw->dev[i].absmax[code] = (1 << bits) - 1; 762 input_dev->absmax[code] = (1 << bits) - 1;
750 sw->dev[i].absmin[code] = (bits == 1) ? -1 : 0; 763 input_dev->absmin[code] = (bits == 1) ? -1 : 0;
751 sw->dev[i].absfuzz[code] = ((bits >> 1) >= 2) ? (1 << ((bits >> 1) - 2)) : 0; 764 input_dev->absfuzz[code] = ((bits >> 1) >= 2) ? (1 << ((bits >> 1) - 2)) : 0;
752 if (code != ABS_THROTTLE) 765 if (code != ABS_THROTTLE)
753 sw->dev[i].absflat[code] = (bits >= 5) ? (1 << (bits - 5)) : 0; 766 input_dev->absflat[code] = (bits >= 5) ? (1 << (bits - 5)) : 0;
754 } 767 }
755 768
756 for (j = 0; (code = sw_btn[sw->type][j]); j++) 769 for (j = 0; (code = sw_btn[sw->type][j]); j++)
757 set_bit(code, sw->dev[i].keybit); 770 set_bit(code, input_dev->keybit);
771
772 dbg("%s%s [%d-bit id %d data %d]\n", sw->name, comment, m, l, k);
758 773
759 input_register_device(sw->dev + i); 774 input_register_device(sw->dev[i]);
760 printk(KERN_INFO "input: %s%s on %s [%d-bit id %d data %d]\n",
761 sw->name, comment, gameport->phys, m, l, k);
762 } 775 }
763 776
764 return 0; 777 return 0;
765 778
766fail2: gameport_close(gameport); 779 fail3: while (--i >= 0)
767fail1: gameport_set_drvdata(gameport, NULL); 780 input_unregister_device(sw->dev[i]);
781 fail2: gameport_close(gameport);
782 fail1: gameport_set_drvdata(gameport, NULL);
768 kfree(sw); 783 kfree(sw);
769 kfree(buf); 784 kfree(buf);
770 kfree(idbuf); 785 kfree(idbuf);
@@ -777,7 +792,7 @@ static void sw_disconnect(struct gameport *gameport)
777 int i; 792 int i;
778 793
779 for (i = 0; i < sw->number; i++) 794 for (i = 0; i < sw->number; i++)
780 input_unregister_device(sw->dev + i); 795 input_unregister_device(sw->dev[i]);
781 gameport_close(gameport); 796 gameport_close(gameport);
782 gameport_set_drvdata(gameport, NULL); 797 gameport_set_drvdata(gameport, NULL);
783 kfree(sw); 798 kfree(sw);
diff --git a/drivers/input/joystick/spaceball.c b/drivers/input/joystick/spaceball.c
index a436f2220856..d6f8db8ec3fd 100644
--- a/drivers/input/joystick/spaceball.c
+++ b/drivers/input/joystick/spaceball.c
@@ -70,8 +70,7 @@ static char *spaceball_names[] = {
70 */ 70 */
71 71
72struct spaceball { 72struct spaceball {
73 struct input_dev dev; 73 struct input_dev *dev;
74 struct serio *serio;
75 int idx; 74 int idx;
76 int escape; 75 int escape;
77 unsigned char data[SPACEBALL_MAX_LENGTH]; 76 unsigned char data[SPACEBALL_MAX_LENGTH];
@@ -85,7 +84,7 @@ struct spaceball {
85 84
86static void spaceball_process_packet(struct spaceball* spaceball, struct pt_regs *regs) 85static void spaceball_process_packet(struct spaceball* spaceball, struct pt_regs *regs)
87{ 86{
88 struct input_dev *dev = &spaceball->dev; 87 struct input_dev *dev = spaceball->dev;
89 unsigned char *data = spaceball->data; 88 unsigned char *data = spaceball->data;
90 int i; 89 int i;
91 90
@@ -193,9 +192,9 @@ static void spaceball_disconnect(struct serio *serio)
193{ 192{
194 struct spaceball* spaceball = serio_get_drvdata(serio); 193 struct spaceball* spaceball = serio_get_drvdata(serio);
195 194
196 input_unregister_device(&spaceball->dev);
197 serio_close(serio); 195 serio_close(serio);
198 serio_set_drvdata(serio, NULL); 196 serio_set_drvdata(serio, NULL);
197 input_unregister_device(spaceball->dev);
199 kfree(spaceball); 198 kfree(spaceball);
200} 199}
201 200
@@ -208,69 +207,62 @@ static void spaceball_disconnect(struct serio *serio)
208static int spaceball_connect(struct serio *serio, struct serio_driver *drv) 207static int spaceball_connect(struct serio *serio, struct serio_driver *drv)
209{ 208{
210 struct spaceball *spaceball; 209 struct spaceball *spaceball;
211 int i, t, id; 210 struct input_dev *input_dev;
212 int err; 211 int err = -ENOMEM;
212 int i, id;
213 213
214 if ((id = serio->id.id) > SPACEBALL_MAX_ID) 214 if ((id = serio->id.id) > SPACEBALL_MAX_ID)
215 return -ENODEV; 215 return -ENODEV;
216 216
217 if (!(spaceball = kmalloc(sizeof(struct spaceball), GFP_KERNEL))) 217 spaceball = kmalloc(sizeof(struct spaceball), GFP_KERNEL);
218 return - ENOMEM; 218 input_dev = input_allocate_device();
219 if (!spaceball || !input_dev)
220 goto fail;
219 221
220 memset(spaceball, 0, sizeof(struct spaceball)); 222 spaceball->dev = input_dev;
223 sprintf(spaceball->phys, "%s/input0", serio->phys);
224
225 input_dev->name = spaceball_names[id];
226 input_dev->phys = spaceball->phys;
227 input_dev->id.bustype = BUS_RS232;
228 input_dev->id.vendor = SERIO_SPACEBALL;
229 input_dev->id.product = id;
230 input_dev->id.version = 0x0100;
231 input_dev->cdev.dev = &serio->dev;
232 input_dev->private = spaceball;
221 233
222 spaceball->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 234 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
223 235
224 switch (id) { 236 switch (id) {
225 case SPACEBALL_4000FLX: 237 case SPACEBALL_4000FLX:
226 case SPACEBALL_4000FLX_L: 238 case SPACEBALL_4000FLX_L:
227 spaceball->dev.keybit[LONG(BTN_0)] |= BIT(BTN_9); 239 input_dev->keybit[LONG(BTN_0)] |= BIT(BTN_9);
228 spaceball->dev.keybit[LONG(BTN_A)] |= BIT(BTN_A) | BIT(BTN_B) | BIT(BTN_C) | BIT(BTN_MODE); 240 input_dev->keybit[LONG(BTN_A)] |= BIT(BTN_A) | BIT(BTN_B) | BIT(BTN_C) | BIT(BTN_MODE);
229 default: 241 default:
230 spaceball->dev.keybit[LONG(BTN_0)] |= BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4) 242 input_dev->keybit[LONG(BTN_0)] |= BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4)
231 | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7) | BIT(BTN_8); 243 | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7) | BIT(BTN_8);
232 case SPACEBALL_3003C: 244 case SPACEBALL_3003C:
233 spaceball->dev.keybit[LONG(BTN_0)] |= BIT(BTN_1) | BIT(BTN_8); 245 input_dev->keybit[LONG(BTN_0)] |= BIT(BTN_1) | BIT(BTN_8);
234 } 246 }
235 247
236 for (i = 0; i < 6; i++) { 248 for (i = 0; i < 3; i++) {
237 t = spaceball_axes[i]; 249 input_set_abs_params(input_dev, ABS_X + i, -8000, 8000, 8, 40);
238 set_bit(t, spaceball->dev.absbit); 250 input_set_abs_params(input_dev, ABS_RX + i, -1600, 1600, 2, 8);
239 spaceball->dev.absmin[t] = i < 3 ? -8000 : -1600;
240 spaceball->dev.absmax[t] = i < 3 ? 8000 : 1600;
241 spaceball->dev.absflat[t] = i < 3 ? 40 : 8;
242 spaceball->dev.absfuzz[t] = i < 3 ? 8 : 2;
243 } 251 }
244 252
245 spaceball->serio = serio;
246 spaceball->dev.private = spaceball;
247
248 sprintf(spaceball->phys, "%s/input0", serio->phys);
249
250 init_input_dev(&spaceball->dev);
251 spaceball->dev.name = spaceball_names[id];
252 spaceball->dev.phys = spaceball->phys;
253 spaceball->dev.id.bustype = BUS_RS232;
254 spaceball->dev.id.vendor = SERIO_SPACEBALL;
255 spaceball->dev.id.product = id;
256 spaceball->dev.id.version = 0x0100;
257 spaceball->dev.dev = &serio->dev;
258
259 serio_set_drvdata(serio, spaceball); 253 serio_set_drvdata(serio, spaceball);
260 254
261 err = serio_open(serio, drv); 255 err = serio_open(serio, drv);
262 if (err) { 256 if (err)
263 serio_set_drvdata(serio, NULL); 257 goto fail;
264 kfree(spaceball);
265 return err;
266 }
267
268 input_register_device(&spaceball->dev);
269
270 printk(KERN_INFO "input: %s on serio%s\n",
271 spaceball_names[id], serio->phys);
272 258
259 input_register_device(spaceball->dev);
273 return 0; 260 return 0;
261
262 fail: serio_set_drvdata(serio, NULL);
263 input_free_device(input_dev);
264 kfree(spaceball);
265 return err;
274} 266}
275 267
276/* 268/*
diff --git a/drivers/input/joystick/spaceorb.c b/drivers/input/joystick/spaceorb.c
index 01fd2e4791ae..7c123a01c58e 100644
--- a/drivers/input/joystick/spaceorb.c
+++ b/drivers/input/joystick/spaceorb.c
@@ -52,15 +52,13 @@ MODULE_LICENSE("GPL");
52 52
53static int spaceorb_buttons[] = { BTN_TL, BTN_TR, BTN_Y, BTN_X, BTN_B, BTN_A }; 53static int spaceorb_buttons[] = { BTN_TL, BTN_TR, BTN_Y, BTN_X, BTN_B, BTN_A };
54static int spaceorb_axes[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ }; 54static int spaceorb_axes[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ };
55static char *spaceorb_name = "SpaceTec SpaceOrb 360 / Avenger";
56 55
57/* 56/*
58 * Per-Orb data. 57 * Per-Orb data.
59 */ 58 */
60 59
61struct spaceorb { 60struct spaceorb {
62 struct input_dev dev; 61 struct input_dev *dev;
63 struct serio *serio;
64 int idx; 62 int idx;
65 unsigned char data[SPACEORB_MAX_LENGTH]; 63 unsigned char data[SPACEORB_MAX_LENGTH];
66 char phys[32]; 64 char phys[32];
@@ -78,7 +76,7 @@ static unsigned char *spaceorb_errors[] = { "EEPROM storing 0 failed", "Receive
78 76
79static void spaceorb_process_packet(struct spaceorb *spaceorb, struct pt_regs *regs) 77static void spaceorb_process_packet(struct spaceorb *spaceorb, struct pt_regs *regs)
80{ 78{
81 struct input_dev *dev = &spaceorb->dev; 79 struct input_dev *dev = spaceorb->dev;
82 unsigned char *data = spaceorb->data; 80 unsigned char *data = spaceorb->data;
83 unsigned char c = 0; 81 unsigned char c = 0;
84 int axes[6]; 82 int axes[6];
@@ -95,8 +93,8 @@ static void spaceorb_process_packet(struct spaceorb *spaceorb, struct pt_regs *r
95 case 'R': /* Reset packet */ 93 case 'R': /* Reset packet */
96 spaceorb->data[spaceorb->idx - 1] = 0; 94 spaceorb->data[spaceorb->idx - 1] = 0;
97 for (i = 1; i < spaceorb->idx && spaceorb->data[i] == ' '; i++); 95 for (i = 1; i < spaceorb->idx && spaceorb->data[i] == ' '; i++);
98 printk(KERN_INFO "input: %s [%s] on %s\n", 96 printk(KERN_INFO "input: %s [%s] is %s\n",
99 spaceorb_name, spaceorb->data + i, spaceorb->serio->phys); 97 dev->name, spaceorb->data + i, spaceorb->phys);
100 break; 98 break;
101 99
102 case 'D': /* Ball + button data */ 100 case 'D': /* Ball + button data */
@@ -123,7 +121,7 @@ static void spaceorb_process_packet(struct spaceorb *spaceorb, struct pt_regs *r
123 121
124 case 'E': /* Error packet */ 122 case 'E': /* Error packet */
125 if (spaceorb->idx != 4) return; 123 if (spaceorb->idx != 4) return;
126 printk(KERN_ERR "joy-spaceorb: Device error. [ "); 124 printk(KERN_ERR "spaceorb: Device error. [ ");
127 for (i = 0; i < 7; i++) if (data[1] & (1 << i)) printk("%s ", spaceorb_errors[i]); 125 for (i = 0; i < 7; i++) if (data[1] & (1 << i)) printk("%s ", spaceorb_errors[i]);
128 printk("]\n"); 126 printk("]\n");
129 break; 127 break;
@@ -154,9 +152,9 @@ static void spaceorb_disconnect(struct serio *serio)
154{ 152{
155 struct spaceorb* spaceorb = serio_get_drvdata(serio); 153 struct spaceorb* spaceorb = serio_get_drvdata(serio);
156 154
157 input_unregister_device(&spaceorb->dev);
158 serio_close(serio); 155 serio_close(serio);
159 serio_set_drvdata(serio, NULL); 156 serio_set_drvdata(serio, NULL);
157 input_unregister_device(spaceorb->dev);
160 kfree(spaceorb); 158 kfree(spaceorb);
161} 159}
162 160
@@ -169,52 +167,48 @@ static void spaceorb_disconnect(struct serio *serio)
169static int spaceorb_connect(struct serio *serio, struct serio_driver *drv) 167static int spaceorb_connect(struct serio *serio, struct serio_driver *drv)
170{ 168{
171 struct spaceorb *spaceorb; 169 struct spaceorb *spaceorb;
172 int i, t; 170 struct input_dev *input_dev;
173 int err; 171 int err = -ENOMEM;
174 172 int i;
175 if (!(spaceorb = kmalloc(sizeof(struct spaceorb), GFP_KERNEL)))
176 return -ENOMEM;
177
178 memset(spaceorb, 0, sizeof(struct spaceorb));
179 173
180 spaceorb->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 174 spaceorb = kzalloc(sizeof(struct spaceorb), GFP_KERNEL);
175 input_dev = input_allocate_device();
176 if (!spaceorb || !input_dev)
177 goto fail;
181 178
182 for (i = 0; i < 6; i++) 179 spaceorb->dev = input_dev;
183 set_bit(spaceorb_buttons[i], spaceorb->dev.keybit); 180 sprintf(spaceorb->phys, "%s/input0", serio->phys);
184 181
185 for (i = 0; i < 6; i++) { 182 input_dev->name = "SpaceTec SpaceOrb 360 / Avenger";
186 t = spaceorb_axes[i]; 183 input_dev->phys = spaceorb->phys;
187 set_bit(t, spaceorb->dev.absbit); 184 input_dev->id.bustype = BUS_RS232;
188 spaceorb->dev.absmin[t] = -508; 185 input_dev->id.vendor = SERIO_SPACEORB;
189 spaceorb->dev.absmax[t] = 508; 186 input_dev->id.product = 0x0001;
190 } 187 input_dev->id.version = 0x0100;
188 input_dev->cdev.dev = &serio->dev;
189 input_dev->private = spaceorb;
191 190
192 spaceorb->serio = serio; 191 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
193 spaceorb->dev.private = spaceorb;
194 192
195 sprintf(spaceorb->phys, "%s/input0", serio->phys); 193 for (i = 0; i < 6; i++)
194 set_bit(spaceorb_buttons[i], input_dev->keybit);
196 195
197 init_input_dev(&spaceorb->dev); 196 for (i = 0; i < 6; i++)
198 spaceorb->dev.name = spaceorb_name; 197 input_set_abs_params(input_dev, spaceorb_axes[i], -508, 508, 0, 0);
199 spaceorb->dev.phys = spaceorb->phys;
200 spaceorb->dev.id.bustype = BUS_RS232;
201 spaceorb->dev.id.vendor = SERIO_SPACEORB;
202 spaceorb->dev.id.product = 0x0001;
203 spaceorb->dev.id.version = 0x0100;
204 spaceorb->dev.dev = &serio->dev;
205 198
206 serio_set_drvdata(serio, spaceorb); 199 serio_set_drvdata(serio, spaceorb);
207 200
208 err = serio_open(serio, drv); 201 err = serio_open(serio, drv);
209 if (err) { 202 if (err)
210 serio_set_drvdata(serio, NULL); 203 goto fail;
211 kfree(spaceorb);
212 return err;
213 }
214
215 input_register_device(&spaceorb->dev);
216 204
205 input_register_device(spaceorb->dev);
217 return 0; 206 return 0;
207
208 fail: serio_set_drvdata(serio, NULL);
209 input_free_device(input_dev);
210 kfree(spaceorb);
211 return err;
218} 212}
219 213
220/* 214/*
diff --git a/drivers/input/joystick/stinger.c b/drivers/input/joystick/stinger.c
index 6f6e6753d590..0a9ed1d30636 100644
--- a/drivers/input/joystick/stinger.c
+++ b/drivers/input/joystick/stinger.c
@@ -48,14 +48,12 @@ MODULE_LICENSE("GPL");
48 48
49#define STINGER_MAX_LENGTH 8 49#define STINGER_MAX_LENGTH 8
50 50
51static char *stinger_name = "Gravis Stinger";
52
53/* 51/*
54 * Per-Stinger data. 52 * Per-Stinger data.
55 */ 53 */
56 54
57struct stinger { 55struct stinger {
58 struct input_dev dev; 56 struct input_dev *dev;
59 int idx; 57 int idx;
60 unsigned char data[STINGER_MAX_LENGTH]; 58 unsigned char data[STINGER_MAX_LENGTH];
61 char phys[32]; 59 char phys[32];
@@ -68,7 +66,7 @@ struct stinger {
68 66
69static void stinger_process_packet(struct stinger *stinger, struct pt_regs *regs) 67static void stinger_process_packet(struct stinger *stinger, struct pt_regs *regs)
70{ 68{
71 struct input_dev *dev = &stinger->dev; 69 struct input_dev *dev = stinger->dev;
72 unsigned char *data = stinger->data; 70 unsigned char *data = stinger->data;
73 71
74 if (!stinger->idx) return; 72 if (!stinger->idx) return;
@@ -126,9 +124,9 @@ static void stinger_disconnect(struct serio *serio)
126{ 124{
127 struct stinger *stinger = serio_get_drvdata(serio); 125 struct stinger *stinger = serio_get_drvdata(serio);
128 126
129 input_unregister_device(&stinger->dev);
130 serio_close(serio); 127 serio_close(serio);
131 serio_set_drvdata(serio, NULL); 128 serio_set_drvdata(serio, NULL);
129 input_unregister_device(stinger->dev);
132 kfree(stinger); 130 kfree(stinger);
133} 131}
134 132
@@ -141,53 +139,46 @@ static void stinger_disconnect(struct serio *serio)
141static int stinger_connect(struct serio *serio, struct serio_driver *drv) 139static int stinger_connect(struct serio *serio, struct serio_driver *drv)
142{ 140{
143 struct stinger *stinger; 141 struct stinger *stinger;
144 int i; 142 struct input_dev *input_dev;
145 int err; 143 int err = -ENOMEM;
146
147 if (!(stinger = kmalloc(sizeof(struct stinger), GFP_KERNEL)))
148 return -ENOMEM;
149
150 memset(stinger, 0, sizeof(struct stinger));
151 144
152 stinger->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 145 stinger = kmalloc(sizeof(struct stinger), GFP_KERNEL);
153 stinger->dev.keybit[LONG(BTN_A)] = BIT(BTN_A) | BIT(BTN_B) | BIT(BTN_C) | BIT(BTN_X) | \ 146 input_dev = input_allocate_device();
154 BIT(BTN_Y) | BIT(BTN_Z) | BIT(BTN_TL) | BIT(BTN_TR) | \ 147 if (!stinger || !input_dev)
155 BIT(BTN_START) | BIT(BTN_SELECT); 148 goto fail;
156 stinger->dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
157 149
150 stinger->dev = input_dev;
158 sprintf(stinger->phys, "%s/serio0", serio->phys); 151 sprintf(stinger->phys, "%s/serio0", serio->phys);
159 152
160 init_input_dev(&stinger->dev); 153 input_dev->name = "Gravis Stinger";
161 stinger->dev.name = stinger_name; 154 input_dev->phys = stinger->phys;
162 stinger->dev.phys = stinger->phys; 155 input_dev->id.bustype = BUS_RS232;
163 stinger->dev.id.bustype = BUS_RS232; 156 input_dev->id.vendor = SERIO_STINGER;
164 stinger->dev.id.vendor = SERIO_STINGER; 157 input_dev->id.product = 0x0001;
165 stinger->dev.id.product = 0x0001; 158 input_dev->id.version = 0x0100;
166 stinger->dev.id.version = 0x0100; 159 input_dev->cdev.dev = &serio->dev;
167 stinger->dev.dev = &serio->dev; 160 input_dev->private = stinger;
168 161
169 for (i = 0; i < 2; i++) { 162 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
170 stinger->dev.absmax[ABS_X+i] = 64; 163 input_dev->keybit[LONG(BTN_A)] = BIT(BTN_A) | BIT(BTN_B) | BIT(BTN_C) | BIT(BTN_X) |
171 stinger->dev.absmin[ABS_X+i] = -64; 164 BIT(BTN_Y) | BIT(BTN_Z) | BIT(BTN_TL) | BIT(BTN_TR) |
172 stinger->dev.absflat[ABS_X+i] = 4; 165 BIT(BTN_START) | BIT(BTN_SELECT);
173 } 166 input_set_abs_params(input_dev, ABS_X, -64, 64, 0, 4);
174 167 input_set_abs_params(input_dev, ABS_Y, -64, 64, 0, 4);
175 stinger->dev.private = stinger;
176 168
177 serio_set_drvdata(serio, stinger); 169 serio_set_drvdata(serio, stinger);
178 170
179 err = serio_open(serio, drv); 171 err = serio_open(serio, drv);
180 if (err) { 172 if (err)
181 serio_set_drvdata(serio, NULL); 173 goto fail;
182 kfree(stinger);
183 return err;
184 }
185
186 input_register_device(&stinger->dev);
187
188 printk(KERN_INFO "input: %s on %s\n", stinger_name, serio->phys);
189 174
175 input_register_device(stinger->dev);
190 return 0; 176 return 0;
177
178 fail: serio_set_drvdata(serio, NULL);
179 input_free_device(input_dev);
180 kfree(stinger);
181 return err;
191} 182}
192 183
193/* 184/*
diff --git a/drivers/input/joystick/tmdc.c b/drivers/input/joystick/tmdc.c
index 7431efc4330e..60e2aac7d06e 100644
--- a/drivers/input/joystick/tmdc.c
+++ b/drivers/input/joystick/tmdc.c
@@ -38,6 +38,7 @@
38#include <linux/init.h> 38#include <linux/init.h>
39#include <linux/gameport.h> 39#include <linux/gameport.h>
40#include <linux/input.h> 40#include <linux/input.h>
41#include <linux/jiffies.h>
41 42
42#define DRIVER_DESC "ThrustMaster DirectConnect joystick driver" 43#define DRIVER_DESC "ThrustMaster DirectConnect joystick driver"
43 44
@@ -63,37 +64,70 @@ MODULE_LICENSE("GPL");
63#define TMDC_ABS_HAT 4 64#define TMDC_ABS_HAT 4
64#define TMDC_BTN 16 65#define TMDC_BTN 16
65 66
66static unsigned char tmdc_byte_a[16] = { 0, 1, 3, 4, 6, 7 }; 67static const unsigned char tmdc_byte_a[16] = { 0, 1, 3, 4, 6, 7 };
67static unsigned char tmdc_byte_d[16] = { 2, 5, 8, 9 }; 68static const unsigned char tmdc_byte_d[16] = { 2, 5, 8, 9 };
68 69
69static signed char tmdc_abs[TMDC_ABS] = 70static const signed char tmdc_abs[TMDC_ABS] =
70 { ABS_X, ABS_Y, ABS_RUDDER, ABS_THROTTLE, ABS_RX, ABS_RY, ABS_RZ }; 71 { ABS_X, ABS_Y, ABS_RUDDER, ABS_THROTTLE, ABS_RX, ABS_RY, ABS_RZ };
71static signed char tmdc_abs_hat[TMDC_ABS_HAT] = 72static const signed char tmdc_abs_hat[TMDC_ABS_HAT] =
72 { ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y }; 73 { ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y };
73static signed char tmdc_abs_at[TMDC_ABS] = 74static const signed char tmdc_abs_at[TMDC_ABS] =
74 { ABS_X, ABS_Y, ABS_RUDDER, -1, ABS_THROTTLE }; 75 { ABS_X, ABS_Y, ABS_RUDDER, -1, ABS_THROTTLE };
75static signed char tmdc_abs_fm[TMDC_ABS] = 76static const signed char tmdc_abs_fm[TMDC_ABS] =
76 { ABS_RX, ABS_RY, ABS_X, ABS_Y }; 77 { ABS_RX, ABS_RY, ABS_X, ABS_Y };
77 78
78static short tmdc_btn_pad[TMDC_BTN] = 79static const short tmdc_btn_pad[TMDC_BTN] =
79 { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_START, BTN_SELECT, BTN_TL, BTN_TR }; 80 { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_START, BTN_SELECT, BTN_TL, BTN_TR };
80static short tmdc_btn_joy[TMDC_BTN] = 81static const short tmdc_btn_joy[TMDC_BTN] =
81 { BTN_TRIGGER, BTN_THUMB, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2, BTN_THUMB2, BTN_PINKIE, 82 { BTN_TRIGGER, BTN_THUMB, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2, BTN_THUMB2, BTN_PINKIE,
82 BTN_BASE3, BTN_BASE4, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z }; 83 BTN_BASE3, BTN_BASE4, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z };
83static short tmdc_btn_fm[TMDC_BTN] = 84static const short tmdc_btn_fm[TMDC_BTN] =
84 { BTN_TRIGGER, BTN_C, BTN_B, BTN_A, BTN_THUMB, BTN_X, BTN_Y, BTN_Z, BTN_TOP, BTN_TOP2 }; 85 { BTN_TRIGGER, BTN_C, BTN_B, BTN_A, BTN_THUMB, BTN_X, BTN_Y, BTN_Z, BTN_TOP, BTN_TOP2 };
85static short tmdc_btn_at[TMDC_BTN] = 86static const short tmdc_btn_at[TMDC_BTN] =
86 { BTN_TRIGGER, BTN_THUMB2, BTN_PINKIE, BTN_THUMB, BTN_BASE6, BTN_BASE5, BTN_BASE4, 87 { BTN_TRIGGER, BTN_THUMB2, BTN_PINKIE, BTN_THUMB, BTN_BASE6, BTN_BASE5, BTN_BASE4,
87 BTN_BASE3, BTN_BASE2, BTN_BASE }; 88 BTN_BASE3, BTN_BASE2, BTN_BASE };
88 89
89static struct { 90static const struct {
90 int x; 91 int x;
91 int y; 92 int y;
92} tmdc_hat_to_axis[] = {{ 0, 0}, { 1, 0}, { 0,-1}, {-1, 0}, { 0, 1}}; 93} tmdc_hat_to_axis[] = {{ 0, 0}, { 1, 0}, { 0,-1}, {-1, 0}, { 0, 1}};
93 94
95static const struct tmdc_model {
96 unsigned char id;
97 const char *name;
98 char abs;
99 char hats;
100 char btnc[4];
101 char btno[4];
102 const signed char *axes;
103 const short *buttons;
104} tmdc_models[] = {
105 { 1, "ThrustMaster Millenium 3D Inceptor", 6, 2, { 4, 2 }, { 4, 6 }, tmdc_abs, tmdc_btn_joy },
106 { 3, "ThrustMaster Rage 3D Gamepad", 2, 0, { 8, 2 }, { 0, 0 }, tmdc_abs, tmdc_btn_pad },
107 { 4, "ThrustMaster Attack Throttle", 5, 2, { 4, 6 }, { 4, 2 }, tmdc_abs_at, tmdc_btn_at },
108 { 8, "ThrustMaster FragMaster", 4, 0, { 8, 2 }, { 0, 0 }, tmdc_abs_fm, tmdc_btn_fm },
109 { 163, "Thrustmaster Fusion GamePad", 2, 0, { 8, 2 }, { 0, 0 }, tmdc_abs, tmdc_btn_pad },
110 { 0, "Unknown %d-axis, %d-button TM device %d", 0, 0, { 0, 0 }, { 0, 0 }, tmdc_abs, tmdc_btn_joy }
111};
112
113
114struct tmdc_port {
115 struct input_dev *dev;
116 char name[64];
117 char phys[32];
118 int mode;
119 const signed char *abs;
120 const short *btn;
121 unsigned char absc;
122 unsigned char btnc[4];
123 unsigned char btno[4];
124};
125
94struct tmdc { 126struct tmdc {
95 struct gameport *gameport; 127 struct gameport *gameport;
96 struct input_dev dev[2]; 128 struct tmdc_port *port[2];
129#if 0
130 struct input_dev *dev[2];
97 char name[2][64]; 131 char name[2][64];
98 char phys[2][32]; 132 char phys[2][32];
99 int mode[2]; 133 int mode[2];
@@ -102,6 +136,7 @@ struct tmdc {
102 unsigned char absc[2]; 136 unsigned char absc[2];
103 unsigned char btnc[2][4]; 137 unsigned char btnc[2][4];
104 unsigned char btno[2][4]; 138 unsigned char btno[2][4];
139#endif
105 int reads; 140 int reads;
106 int bads; 141 int bads;
107 unsigned char exists; 142 unsigned char exists;
@@ -156,6 +191,50 @@ static int tmdc_read_packet(struct gameport *gameport, unsigned char data[2][TMD
156 return (i[0] == TMDC_MAX_LENGTH) | ((i[1] == TMDC_MAX_LENGTH) << 1); 191 return (i[0] == TMDC_MAX_LENGTH) | ((i[1] == TMDC_MAX_LENGTH) << 1);
157} 192}
158 193
194static int tmdc_parse_packet(struct tmdc_port *port, unsigned char *data)
195{
196 int i, k, l;
197
198 if (data[TMDC_BYTE_ID] != port->mode)
199 return -1;
200
201 for (i = 0; i < port->absc; i++) {
202 if (port->abs[i] < 0)
203 return 0;
204
205 input_report_abs(port->dev, port->abs[i], data[tmdc_byte_a[i]]);
206 }
207
208 switch (port->mode) {
209
210 case TMDC_MODE_M3DI:
211
212 i = tmdc_byte_d[0];
213 input_report_abs(port->dev, ABS_HAT0X, ((data[i] >> 3) & 1) - ((data[i] >> 1) & 1));
214 input_report_abs(port->dev, ABS_HAT0Y, ((data[i] >> 2) & 1) - ( data[i] & 1));
215 break;
216
217 case TMDC_MODE_AT:
218
219 i = tmdc_byte_a[3];
220 input_report_abs(port->dev, ABS_HAT0X, tmdc_hat_to_axis[(data[i] - 141) / 25].x);
221 input_report_abs(port->dev, ABS_HAT0Y, tmdc_hat_to_axis[(data[i] - 141) / 25].y);
222 break;
223
224 }
225
226 for (k = l = 0; k < 4; k++) {
227 for (i = 0; i < port->btnc[k]; i++)
228 input_report_key(port->dev, port->btn[i + l],
229 ((data[tmdc_byte_d[k]] >> (i + port->btno[k])) & 1));
230 l += port->btnc[k];
231 }
232
233 input_sync(port->dev);
234
235 return 0;
236}
237
159/* 238/*
160 * tmdc_poll() reads and analyzes ThrustMaster joystick data. 239 * tmdc_poll() reads and analyzes ThrustMaster joystick data.
161 */ 240 */
@@ -164,57 +243,21 @@ static void tmdc_poll(struct gameport *gameport)
164{ 243{
165 unsigned char data[2][TMDC_MAX_LENGTH]; 244 unsigned char data[2][TMDC_MAX_LENGTH];
166 struct tmdc *tmdc = gameport_get_drvdata(gameport); 245 struct tmdc *tmdc = gameport_get_drvdata(gameport);
167 struct input_dev *dev;
168 unsigned char r, bad = 0; 246 unsigned char r, bad = 0;
169 int i, j, k, l; 247 int i;
170 248
171 tmdc->reads++; 249 tmdc->reads++;
172 250
173 if ((r = tmdc_read_packet(tmdc->gameport, data)) != tmdc->exists) 251 if ((r = tmdc_read_packet(tmdc->gameport, data)) != tmdc->exists)
174 bad = 1; 252 bad = 1;
175 else 253 else {
176 254 for (i = 0; i < 2; i++) {
177 for (j = 0; j < 2; j++) 255 if (r & (1 << i) & tmdc->exists) {
178 if (r & (1 << j) & tmdc->exists) {
179
180 if (data[j][TMDC_BYTE_ID] != tmdc->mode[j]) {
181 bad = 1;
182 continue;
183 }
184
185 dev = tmdc->dev + j;
186
187 for (i = 0; i < tmdc->absc[j]; i++) {
188 if (tmdc->abs[j][i] < 0) continue;
189 input_report_abs(dev, tmdc->abs[j][i], data[j][tmdc_byte_a[i]]);
190 }
191
192 switch (tmdc->mode[j]) {
193 256
194 case TMDC_MODE_M3DI: 257 if (tmdc_parse_packet(tmdc->port[i], data[i]))
195 258 bad = 1;
196 i = tmdc_byte_d[0];
197 input_report_abs(dev, ABS_HAT0X, ((data[j][i] >> 3) & 1) - ((data[j][i] >> 1) & 1));
198 input_report_abs(dev, ABS_HAT0Y, ((data[j][i] >> 2) & 1) - ( data[j][i] & 1));
199 break;
200
201 case TMDC_MODE_AT:
202
203 i = tmdc_byte_a[3];
204 input_report_abs(dev, ABS_HAT0X, tmdc_hat_to_axis[(data[j][i] - 141) / 25].x);
205 input_report_abs(dev, ABS_HAT0Y, tmdc_hat_to_axis[(data[j][i] - 141) / 25].y);
206 break;
207
208 }
209
210 for (k = l = 0; k < 4; k++) {
211 for (i = 0; i < tmdc->btnc[j][k]; i++)
212 input_report_key(dev, tmdc->btn[j][i + l],
213 ((data[j][tmdc_byte_d[k]] >> (i + tmdc->btno[j][k])) & 1));
214 l += tmdc->btnc[j][k];
215 } 259 }
216 260 }
217 input_sync(dev);
218 } 261 }
219 262
220 tmdc->bads += bad; 263 tmdc->bads += bad;
@@ -235,31 +278,89 @@ static void tmdc_close(struct input_dev *dev)
235 gameport_stop_polling(tmdc->gameport); 278 gameport_stop_polling(tmdc->gameport);
236} 279}
237 280
281static int tmdc_setup_port(struct tmdc *tmdc, int idx, unsigned char *data)
282{
283 const struct tmdc_model *model;
284 struct tmdc_port *port;
285 struct input_dev *input_dev;
286 int i, j, b = 0;
287
288 tmdc->port[idx] = port = kzalloc(sizeof (struct tmdc_port), GFP_KERNEL);
289 input_dev = input_allocate_device();
290 if (!port || !input_dev) {
291 kfree(port);
292 input_free_device(input_dev);
293 return -ENOMEM;
294 }
295
296 port->mode = data[TMDC_BYTE_ID];
297
298 for (model = tmdc_models; model->id && model->id != port->mode; model++)
299 /* empty */;
300
301 port->abs = model->axes;
302 port->btn = model->buttons;
303
304 if (!model->id) {
305 port->absc = data[TMDC_BYTE_DEF] >> 4;
306 for (i = 0; i < 4; i++)
307 port->btnc[i] = i < (data[TMDC_BYTE_DEF] & 0xf) ? 8 : 0;
308 } else {
309 port->absc = model->abs;
310 for (i = 0; i < 4; i++)
311 port->btnc[i] = model->btnc[i];
312 }
313
314 for (i = 0; i < 4; i++)
315 port->btno[i] = model->btno[i];
316
317 snprintf(port->name, sizeof(port->name), model->name,
318 port->absc, (data[TMDC_BYTE_DEF] & 0xf) << 3, port->mode);
319 snprintf(port->phys, sizeof(port->phys), "%s/input%d", tmdc->gameport->phys, i);
320
321 port->dev = input_dev;
322
323 input_dev->name = port->name;
324 input_dev->phys = port->phys;
325 input_dev->id.bustype = BUS_GAMEPORT;
326 input_dev->id.vendor = GAMEPORT_ID_VENDOR_THRUSTMASTER;
327 input_dev->id.product = model->id;
328 input_dev->id.version = 0x0100;
329 input_dev->cdev.dev = &tmdc->gameport->dev;
330 input_dev->private = tmdc;
331
332 input_dev->open = tmdc_open;
333 input_dev->close = tmdc_close;
334
335 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
336
337 for (i = 0; i < port->absc && i < TMDC_ABS; i++)
338 if (port->abs[i] >= 0)
339 input_set_abs_params(input_dev, port->abs[i], 8, 248, 2, 4);
340
341 for (i = 0; i < model->hats && i < TMDC_ABS_HAT; i++)
342 input_set_abs_params(input_dev, tmdc_abs_hat[i], -1, 1, 0, 0);
343
344 for (i = 0; i < 4; i++) {
345 for (j = 0; j < port->btnc[i] && j < TMDC_BTN; j++)
346 set_bit(port->btn[j + b], input_dev->keybit);
347 b += port->btnc[i];
348 }
349
350 input_register_device(port->dev);
351
352 return 0;
353}
354
238/* 355/*
239 * tmdc_probe() probes for ThrustMaster type joysticks. 356 * tmdc_probe() probes for ThrustMaster type joysticks.
240 */ 357 */
241 358
242static int tmdc_connect(struct gameport *gameport, struct gameport_driver *drv) 359static int tmdc_connect(struct gameport *gameport, struct gameport_driver *drv)
243{ 360{
244 static struct models {
245 unsigned char id;
246 char *name;
247 char abs;
248 char hats;
249 char btnc[4];
250 char btno[4];
251 signed char *axes;
252 short *buttons;
253 } models[] = { { 1, "ThrustMaster Millenium 3D Inceptor", 6, 2, { 4, 2 }, { 4, 6 }, tmdc_abs, tmdc_btn_joy },
254 { 3, "ThrustMaster Rage 3D Gamepad", 2, 0, { 8, 2 }, { 0, 0 }, tmdc_abs, tmdc_btn_pad },
255 { 4, "ThrustMaster Attack Throttle", 5, 2, { 4, 6 }, { 4, 2 }, tmdc_abs_at, tmdc_btn_at },
256 { 8, "ThrustMaster FragMaster", 4, 0, { 8, 2 }, { 0, 0 }, tmdc_abs_fm, tmdc_btn_fm },
257 { 163, "Thrustmaster Fusion GamePad", 2, 0, { 8, 2 }, { 0, 0 }, tmdc_abs, tmdc_btn_pad },
258 { 0, "Unknown %d-axis, %d-button TM device %d", 0, 0, { 0, 0 }, { 0, 0 }, tmdc_abs, tmdc_btn_joy }};
259
260 unsigned char data[2][TMDC_MAX_LENGTH]; 361 unsigned char data[2][TMDC_MAX_LENGTH];
261 struct tmdc *tmdc; 362 struct tmdc *tmdc;
262 int i, j, k, l, m; 363 int i;
263 int err; 364 int err;
264 365
265 if (!(tmdc = kzalloc(sizeof(struct tmdc), GFP_KERNEL))) 366 if (!(tmdc = kzalloc(sizeof(struct tmdc), GFP_KERNEL)))
@@ -281,68 +382,25 @@ static int tmdc_connect(struct gameport *gameport, struct gameport_driver *drv)
281 gameport_set_poll_handler(gameport, tmdc_poll); 382 gameport_set_poll_handler(gameport, tmdc_poll);
282 gameport_set_poll_interval(gameport, 20); 383 gameport_set_poll_interval(gameport, 20);
283 384
284 for (j = 0; j < 2; j++) 385 for (i = 0; i < 2; i++) {
285 if (tmdc->exists & (1 << j)) { 386 if (tmdc->exists & (1 << i)) {
286 387
287 tmdc->mode[j] = data[j][TMDC_BYTE_ID]; 388 err = tmdc_setup_port(tmdc, i, data[i]);
288 389 if (err)
289 for (m = 0; models[m].id && models[m].id != tmdc->mode[j]; m++); 390 goto fail3;
290
291 tmdc->abs[j] = models[m].axes;
292 tmdc->btn[j] = models[m].buttons;
293
294 if (!models[m].id) {
295 models[m].abs = data[j][TMDC_BYTE_DEF] >> 4;
296 for (k = 0; k < 4; k++)
297 models[m].btnc[k] = k < (data[j][TMDC_BYTE_DEF] & 0xf) ? 8 : 0;
298 }
299
300 tmdc->absc[j] = models[m].abs;
301 for (k = 0; k < 4; k++) {
302 tmdc->btnc[j][k] = models[m].btnc[k];
303 tmdc->btno[j][k] = models[m].btno[k];
304 }
305
306 sprintf(tmdc->name[j], models[m].name, models[m].abs,
307 (data[j][TMDC_BYTE_DEF] & 0xf) << 3, tmdc->mode[j]);
308
309 sprintf(tmdc->phys[j], "%s/input%d", gameport->phys, j);
310
311 tmdc->dev[j].private = tmdc;
312 tmdc->dev[j].open = tmdc_open;
313 tmdc->dev[j].close = tmdc_close;
314
315 tmdc->dev[j].name = tmdc->name[j];
316 tmdc->dev[j].phys = tmdc->phys[j];
317 tmdc->dev[j].id.bustype = BUS_GAMEPORT;
318 tmdc->dev[j].id.vendor = GAMEPORT_ID_VENDOR_THRUSTMASTER;
319 tmdc->dev[j].id.product = models[m].id;
320 tmdc->dev[j].id.version = 0x0100;
321
322 tmdc->dev[j].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
323
324 for (i = 0; i < models[m].abs && i < TMDC_ABS; i++)
325 if (tmdc->abs[j][i] >= 0)
326 input_set_abs_params(&tmdc->dev[j], tmdc->abs[j][i], 8, 248, 2, 4);
327
328 for (i = 0; i < models[m].hats && i < TMDC_ABS_HAT; i++)
329 input_set_abs_params(&tmdc->dev[j], tmdc_abs_hat[i], -1, 1, 0, 0);
330
331
332 for (k = l = 0; k < 4; k++) {
333 for (i = 0; i < models[m].btnc[k] && i < TMDC_BTN; i++)
334 set_bit(tmdc->btn[j][i + l], tmdc->dev[j].keybit);
335 l += models[m].btnc[k];
336 }
337
338 input_register_device(tmdc->dev + j);
339 printk(KERN_INFO "input: %s on %s\n", tmdc->name[j], gameport->phys);
340 } 391 }
392 }
341 393
342 return 0; 394 return 0;
343 395
344fail2: gameport_close(gameport); 396 fail3: while (--i >= 0) {
345fail1: gameport_set_drvdata(gameport, NULL); 397 if (tmdc->port[i]) {
398 input_unregister_device(tmdc->port[i]->dev);
399 kfree(tmdc->port[i]);
400 }
401 }
402 fail2: gameport_close(gameport);
403 fail1: gameport_set_drvdata(gameport, NULL);
346 kfree(tmdc); 404 kfree(tmdc);
347 return err; 405 return err;
348} 406}
@@ -352,9 +410,12 @@ static void tmdc_disconnect(struct gameport *gameport)
352 struct tmdc *tmdc = gameport_get_drvdata(gameport); 410 struct tmdc *tmdc = gameport_get_drvdata(gameport);
353 int i; 411 int i;
354 412
355 for (i = 0; i < 2; i++) 413 for (i = 0; i < 2; i++) {
356 if (tmdc->exists & (1 << i)) 414 if (tmdc->port[i]) {
357 input_unregister_device(tmdc->dev + i); 415 input_unregister_device(tmdc->port[i]->dev);
416 kfree(tmdc->port[i]);
417 }
418 }
358 gameport_close(gameport); 419 gameport_close(gameport);
359 gameport_set_drvdata(gameport, NULL); 420 gameport_set_drvdata(gameport, NULL);
360 kfree(tmdc); 421 kfree(tmdc);
diff --git a/drivers/input/joystick/turbografx.c b/drivers/input/joystick/turbografx.c
index 0c5b9c8297cd..7e9764937d06 100644
--- a/drivers/input/joystick/turbografx.c
+++ b/drivers/input/joystick/turbografx.c
@@ -42,19 +42,21 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
42MODULE_DESCRIPTION("TurboGraFX parallel port interface driver"); 42MODULE_DESCRIPTION("TurboGraFX parallel port interface driver");
43MODULE_LICENSE("GPL"); 43MODULE_LICENSE("GPL");
44 44
45static int tgfx[] __initdata = { -1, 0, 0, 0, 0, 0, 0, 0 }; 45#define TGFX_MAX_PORTS 3
46static int tgfx_nargs __initdata = 0; 46#define TGFX_MAX_DEVICES 7
47module_param_array_named(map, tgfx, int, &tgfx_nargs, 0);
48MODULE_PARM_DESC(map, "Describes first set of devices (<parport#>,<js1>,<js2>,..<js7>");
49 47
50static int tgfx_2[] __initdata = { -1, 0, 0, 0, 0, 0, 0, 0 }; 48struct tgfx_config {
51static int tgfx_nargs_2 __initdata = 0; 49 int args[TGFX_MAX_DEVICES + 1];
52module_param_array_named(map2, tgfx_2, int, &tgfx_nargs_2, 0); 50 int nargs;
53MODULE_PARM_DESC(map2, "Describes second set of devices"); 51};
52
53static struct tgfx_config tgfx[TGFX_MAX_PORTS] __initdata;
54 54
55static int tgfx_3[] __initdata = { -1, 0, 0, 0, 0, 0, 0, 0 }; 55module_param_array_named(map, tgfx[0].args, int, &tgfx[0].nargs, 0);
56static int tgfx_nargs_3 __initdata = 0; 56MODULE_PARM_DESC(map, "Describes first set of devices (<parport#>,<js1>,<js2>,..<js7>");
57module_param_array_named(map3, tgfx_3, int, &tgfx_nargs_3, 0); 57module_param_array_named(map2, tgfx[1].args, int, &tgfx[1].nargs, 0);
58MODULE_PARM_DESC(map2, "Describes second set of devices");
59module_param_array_named(map3, tgfx[2].args, int, &tgfx[2].nargs, 0);
58MODULE_PARM_DESC(map3, "Describes third set of devices"); 60MODULE_PARM_DESC(map3, "Describes third set of devices");
59 61
60__obsolete_setup("tgfx="); 62__obsolete_setup("tgfx=");
@@ -75,17 +77,17 @@ __obsolete_setup("tgfx_3=");
75#define TGFX_TOP2 0x08 77#define TGFX_TOP2 0x08
76 78
77static int tgfx_buttons[] = { BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2 }; 79static int tgfx_buttons[] = { BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2 };
78static char *tgfx_name = "TurboGraFX Multisystem joystick";
79 80
80static struct tgfx { 81static struct tgfx {
81 struct pardevice *pd; 82 struct pardevice *pd;
82 struct timer_list timer; 83 struct timer_list timer;
83 struct input_dev dev[7]; 84 struct input_dev *dev[TGFX_MAX_DEVICES];
84 char phys[7][32]; 85 char name[TGFX_MAX_DEVICES][64];
86 char phys[TGFX_MAX_DEVICES][32];
85 int sticks; 87 int sticks;
86 int used; 88 int used;
87 struct semaphore sem; 89 struct semaphore sem;
88} *tgfx_base[3]; 90} *tgfx_base[TGFX_MAX_PORTS];
89 91
90/* 92/*
91 * tgfx_timer() reads and analyzes TurboGraFX joystick data. 93 * tgfx_timer() reads and analyzes TurboGraFX joystick data.
@@ -100,7 +102,7 @@ static void tgfx_timer(unsigned long private)
100 for (i = 0; i < 7; i++) 102 for (i = 0; i < 7; i++)
101 if (tgfx->sticks & (1 << i)) { 103 if (tgfx->sticks & (1 << i)) {
102 104
103 dev = tgfx->dev + i; 105 dev = tgfx->dev[i];
104 106
105 parport_write_data(tgfx->pd->port, ~(1 << i)); 107 parport_write_data(tgfx->pd->port, ~(1 << i));
106 data1 = parport_read_status(tgfx->pd->port) ^ 0x7f; 108 data1 = parport_read_status(tgfx->pd->port) ^ 0x7f;
@@ -153,118 +155,165 @@ static void tgfx_close(struct input_dev *dev)
153 up(&tgfx->sem); 155 up(&tgfx->sem);
154} 156}
155 157
158
159
156/* 160/*
157 * tgfx_probe() probes for tg gamepads. 161 * tgfx_probe() probes for tg gamepads.
158 */ 162 */
159 163
160static struct tgfx __init *tgfx_probe(int *config, int nargs) 164static struct tgfx __init *tgfx_probe(int parport, int *n_buttons, int n_devs)
161{ 165{
162 struct tgfx *tgfx; 166 struct tgfx *tgfx;
167 struct input_dev *input_dev;
163 struct parport *pp; 168 struct parport *pp;
169 struct pardevice *pd;
164 int i, j; 170 int i, j;
171 int err;
165 172
166 if (config[0] < 0) 173 pp = parport_find_number(parport);
167 return NULL;
168
169 if (nargs < 2) {
170 printk(KERN_ERR "turbografx.c: at least one joystick must be specified\n");
171 return NULL;
172 }
173
174 pp = parport_find_number(config[0]);
175
176 if (!pp) { 174 if (!pp) {
177 printk(KERN_ERR "turbografx.c: no such parport\n"); 175 printk(KERN_ERR "turbografx.c: no such parport\n");
178 return NULL; 176 err = -EINVAL;
177 goto err_out;
179 } 178 }
180 179
181 if (!(tgfx = kzalloc(sizeof(struct tgfx), GFP_KERNEL))) { 180 pd = parport_register_device(pp, "turbografx", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
182 parport_put_port(pp); 181 if (!pd) {
183 return NULL; 182 printk(KERN_ERR "turbografx.c: parport busy already - lp.o loaded?\n");
183 err = -EBUSY;
184 goto err_put_pp;
184 } 185 }
185 186
186 init_MUTEX(&tgfx->sem); 187 tgfx = kzalloc(sizeof(struct tgfx), GFP_KERNEL);
187 188 if (!tgfx) {
188 tgfx->pd = parport_register_device(pp, "turbografx", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL); 189 printk(KERN_ERR "turbografx.c: Not enough memory\n");
189 190 err = -ENOMEM;
190 parport_put_port(pp); 191 goto err_unreg_pardev;
191
192 if (!tgfx->pd) {
193 printk(KERN_ERR "turbografx.c: parport busy already - lp.o loaded?\n");
194 kfree(tgfx);
195 return NULL;
196 } 192 }
197 193
194 init_MUTEX(&tgfx->sem);
195 tgfx->pd = pd;
198 init_timer(&tgfx->timer); 196 init_timer(&tgfx->timer);
199 tgfx->timer.data = (long) tgfx; 197 tgfx->timer.data = (long) tgfx;
200 tgfx->timer.function = tgfx_timer; 198 tgfx->timer.function = tgfx_timer;
201 199
202 tgfx->sticks = 0; 200 for (i = 0; i < n_devs; i++) {
201 if (n_buttons[i] < 1)
202 continue;
203 203
204 for (i = 0; i < nargs - 1; i++) 204 if (n_buttons[i] > 6) {
205 if (config[i+1] > 0 && config[i+1] < 6) { 205 printk(KERN_ERR "turbografx.c: Invalid number of buttons %d\n", n_buttons[i]);
206 206 err = -EINVAL;
207 tgfx->sticks |= (1 << i); 207 goto err_free_devs;
208 }
208 209
209 tgfx->dev[i].private = tgfx; 210 tgfx->dev[i] = input_dev = input_allocate_device();
210 tgfx->dev[i].open = tgfx_open; 211 if (!input_dev) {
211 tgfx->dev[i].close = tgfx_close; 212 printk(KERN_ERR "turbografx.c: Not enough memory for input device\n");
213 err = -ENOMEM;
214 goto err_free_devs;
215 }
212 216
213 sprintf(tgfx->phys[i], "%s/input0", tgfx->pd->port->name); 217 tgfx->sticks |= (1 << i);
218 snprintf(tgfx->name[i], sizeof(tgfx->name[i]),
219 "TurboGraFX %d-button Multisystem joystick", n_buttons[i]);
220 snprintf(tgfx->phys[i], sizeof(tgfx->phys[i]),
221 "%s/input%d", tgfx->pd->port->name, i);
214 222
215 tgfx->dev[i].name = tgfx_name; 223 input_dev->name = tgfx->name[i];
216 tgfx->dev[i].phys = tgfx->phys[i]; 224 input_dev->phys = tgfx->phys[i];
217 tgfx->dev[i].id.bustype = BUS_PARPORT; 225 input_dev->id.bustype = BUS_PARPORT;
218 tgfx->dev[i].id.vendor = 0x0003; 226 input_dev->id.vendor = 0x0003;
219 tgfx->dev[i].id.product = config[i+1]; 227 input_dev->id.product = n_buttons[i];
220 tgfx->dev[i].id.version = 0x0100; 228 input_dev->id.version = 0x0100;
221 229
222 tgfx->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 230 input_dev->private = tgfx;
223 tgfx->dev[i].absbit[0] = BIT(ABS_X) | BIT(ABS_Y); 231 input_dev->open = tgfx_open;
232 input_dev->close = tgfx_close;
224 233
225 for (j = 0; j < config[i+1]; j++) 234 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
226 set_bit(tgfx_buttons[j], tgfx->dev[i].keybit); 235 input_set_abs_params(input_dev, ABS_X, -1, 1, 0, 0);
236 input_set_abs_params(input_dev, ABS_Y, -1, 1, 0, 0);
227 237
228 tgfx->dev[i].absmin[ABS_X] = -1; tgfx->dev[i].absmax[ABS_X] = 1; 238 for (j = 0; j < n_buttons[i]; j++)
229 tgfx->dev[i].absmin[ABS_Y] = -1; tgfx->dev[i].absmax[ABS_Y] = 1; 239 set_bit(tgfx_buttons[j], input_dev->keybit);
230 240
231 input_register_device(tgfx->dev + i); 241 input_register_device(tgfx->dev[i]);
232 printk(KERN_INFO "input: %d-button Multisystem joystick on %s\n", 242 }
233 config[i+1], tgfx->pd->port->name);
234 }
235 243
236 if (!tgfx->sticks) { 244 if (!tgfx->sticks) {
237 parport_unregister_device(tgfx->pd); 245 printk(KERN_ERR "turbografx.c: No valid devices specified\n");
238 kfree(tgfx); 246 err = -EINVAL;
239 return NULL; 247 goto err_free_tgfx;
240 } 248 }
241 249
242 return tgfx; 250 return tgfx;
251
252 err_free_devs:
253 while (--i >= 0)
254 input_unregister_device(tgfx->dev[i]);
255 err_free_tgfx:
256 kfree(tgfx);
257 err_unreg_pardev:
258 parport_unregister_device(pd);
259 err_put_pp:
260 parport_put_port(pp);
261 err_out:
262 return ERR_PTR(err);
263}
264
265static void __exit tgfx_remove(struct tgfx *tgfx)
266{
267 int i;
268
269 for (i = 0; i < TGFX_MAX_DEVICES; i++)
270 if (tgfx->dev[i])
271 input_unregister_device(tgfx->dev[i]);
272 parport_unregister_device(tgfx->pd);
273 kfree(tgfx);
243} 274}
244 275
245static int __init tgfx_init(void) 276static int __init tgfx_init(void)
246{ 277{
247 tgfx_base[0] = tgfx_probe(tgfx, tgfx_nargs); 278 int i;
248 tgfx_base[1] = tgfx_probe(tgfx_2, tgfx_nargs_2); 279 int have_dev = 0;
249 tgfx_base[2] = tgfx_probe(tgfx_3, tgfx_nargs_3); 280 int err = 0;
281
282 for (i = 0; i < TGFX_MAX_PORTS; i++) {
283 if (tgfx[i].nargs == 0 || tgfx[i].args[0] < 0)
284 continue;
285
286 if (tgfx[i].nargs < 2) {
287 printk(KERN_ERR "turbografx.c: at least one joystick must be specified\n");
288 err = -EINVAL;
289 break;
290 }
291
292 tgfx_base[i] = tgfx_probe(tgfx[i].args[0], tgfx[i].args + 1, tgfx[i].nargs - 1);
293 if (IS_ERR(tgfx_base[i])) {
294 err = PTR_ERR(tgfx_base[i]);
295 break;
296 }
297
298 have_dev = 1;
299 }
250 300
251 if (tgfx_base[0] || tgfx_base[1] || tgfx_base[2]) 301 if (err) {
252 return 0; 302 while (--i >= 0)
303 tgfx_remove(tgfx_base[i]);
304 return err;
305 }
253 306
254 return -ENODEV; 307 return have_dev ? 0 : -ENODEV;
255} 308}
256 309
257static void __exit tgfx_exit(void) 310static void __exit tgfx_exit(void)
258{ 311{
259 int i, j; 312 int i;
260 313
261 for (i = 0; i < 3; i++) 314 for (i = 0; i < TGFX_MAX_PORTS; i++)
262 if (tgfx_base[i]) { 315 if (tgfx_base[i])
263 for (j = 0; j < 7; j++) 316 tgfx_remove(tgfx_base[i]);
264 if (tgfx_base[i]->sticks & (1 << j))
265 input_unregister_device(tgfx_base[i]->dev + j);
266 parport_unregister_device(tgfx_base[i]->pd);
267 }
268} 317}
269 318
270module_init(tgfx_init); 319module_init(tgfx_init);
diff --git a/drivers/input/joystick/twidjoy.c b/drivers/input/joystick/twidjoy.c
index 0379bc166525..cd3a1e742a30 100644
--- a/drivers/input/joystick/twidjoy.c
+++ b/drivers/input/joystick/twidjoy.c
@@ -69,8 +69,6 @@ MODULE_LICENSE("GPL");
69 69
70#define TWIDJOY_MAX_LENGTH 5 70#define TWIDJOY_MAX_LENGTH 5
71 71
72static char *twidjoy_name = "Handykey Twiddler";
73
74static struct twidjoy_button_spec { 72static struct twidjoy_button_spec {
75 int bitshift; 73 int bitshift;
76 int bitmask; 74 int bitmask;
@@ -95,7 +93,7 @@ twidjoy_buttons[] = {
95 */ 93 */
96 94
97struct twidjoy { 95struct twidjoy {
98 struct input_dev dev; 96 struct input_dev *dev;
99 int idx; 97 int idx;
100 unsigned char data[TWIDJOY_MAX_LENGTH]; 98 unsigned char data[TWIDJOY_MAX_LENGTH];
101 char phys[32]; 99 char phys[32];
@@ -108,37 +106,33 @@ struct twidjoy {
108 106
109static void twidjoy_process_packet(struct twidjoy *twidjoy, struct pt_regs *regs) 107static void twidjoy_process_packet(struct twidjoy *twidjoy, struct pt_regs *regs)
110{ 108{
111 if (twidjoy->idx == TWIDJOY_MAX_LENGTH) { 109 struct input_dev *dev = twidjoy->dev;
112 struct input_dev *dev = &twidjoy->dev; 110 unsigned char *data = twidjoy->data;
113 unsigned char *data = twidjoy->data; 111 struct twidjoy_button_spec *bp;
114 struct twidjoy_button_spec *bp; 112 int button_bits, abs_x, abs_y;
115 int button_bits, abs_x, abs_y;
116
117 button_bits = ((data[1] & 0x7f) << 7) | (data[0] & 0x7f);
118 113
119 input_regs(dev, regs); 114 button_bits = ((data[1] & 0x7f) << 7) | (data[0] & 0x7f);
120 115
121 for (bp = twidjoy_buttons; bp->bitmask; bp++) { 116 input_regs(dev, regs);
122 int value = (button_bits & (bp->bitmask << bp->bitshift)) >> bp->bitshift;
123 int i;
124 117
125 for (i = 0; i < bp->bitmask; i++) 118 for (bp = twidjoy_buttons; bp->bitmask; bp++) {
126 input_report_key(dev, bp->buttons[i], i+1 == value); 119 int value = (button_bits & (bp->bitmask << bp->bitshift)) >> bp->bitshift;
127 } 120 int i;
128 121
129 abs_x = ((data[4] & 0x07) << 5) | ((data[3] & 0x7C) >> 2); 122 for (i = 0; i < bp->bitmask; i++)
130 if (data[4] & 0x08) abs_x -= 256; 123 input_report_key(dev, bp->buttons[i], i+1 == value);
124 }
131 125
132 abs_y = ((data[3] & 0x01) << 7) | ((data[2] & 0x7F) >> 0); 126 abs_x = ((data[4] & 0x07) << 5) | ((data[3] & 0x7C) >> 2);
133 if (data[3] & 0x02) abs_y -= 256; 127 if (data[4] & 0x08) abs_x -= 256;
134 128
135 input_report_abs(dev, ABS_X, -abs_x); 129 abs_y = ((data[3] & 0x01) << 7) | ((data[2] & 0x7F) >> 0);
136 input_report_abs(dev, ABS_Y, +abs_y); 130 if (data[3] & 0x02) abs_y -= 256;
137 131
138 input_sync(dev); 132 input_report_abs(dev, ABS_X, -abs_x);
139 } 133 input_report_abs(dev, ABS_Y, +abs_y);
140 134
141 return; 135 input_sync(dev);
142} 136}
143 137
144/* 138/*
@@ -179,9 +173,9 @@ static void twidjoy_disconnect(struct serio *serio)
179{ 173{
180 struct twidjoy *twidjoy = serio_get_drvdata(serio); 174 struct twidjoy *twidjoy = serio_get_drvdata(serio);
181 175
182 input_unregister_device(&twidjoy->dev);
183 serio_close(serio); 176 serio_close(serio);
184 serio_set_drvdata(serio, NULL); 177 serio_set_drvdata(serio, NULL);
178 input_unregister_device(twidjoy->dev);
185 kfree(twidjoy); 179 kfree(twidjoy);
186} 180}
187 181
@@ -195,59 +189,49 @@ static int twidjoy_connect(struct serio *serio, struct serio_driver *drv)
195{ 189{
196 struct twidjoy_button_spec *bp; 190 struct twidjoy_button_spec *bp;
197 struct twidjoy *twidjoy; 191 struct twidjoy *twidjoy;
192 struct input_dev *input_dev;
193 int err = -ENOMEM;
198 int i; 194 int i;
199 int err;
200
201 if (!(twidjoy = kmalloc(sizeof(struct twidjoy), GFP_KERNEL)))
202 return -ENOMEM;
203 195
204 memset(twidjoy, 0, sizeof(struct twidjoy)); 196 twidjoy = kzalloc(sizeof(struct twidjoy), GFP_KERNEL);
197 input_dev = input_allocate_device();
198 if (!twidjoy || !input_dev)
199 goto fail;
205 200
201 twidjoy->dev = input_dev;
206 sprintf(twidjoy->phys, "%s/input0", serio->phys); 202 sprintf(twidjoy->phys, "%s/input0", serio->phys);
207 203
208 init_input_dev(&twidjoy->dev); 204 input_dev->name = "Handykey Twiddler";
209 twidjoy->dev.name = twidjoy_name; 205 input_dev->phys = twidjoy->phys;
210 twidjoy->dev.phys = twidjoy->phys; 206 input_dev->id.bustype = BUS_RS232;
211 twidjoy->dev.id.bustype = BUS_RS232; 207 input_dev->id.vendor = SERIO_TWIDJOY;
212 twidjoy->dev.id.vendor = SERIO_TWIDJOY; 208 input_dev->id.product = 0x0001;
213 twidjoy->dev.id.product = 0x0001; 209 input_dev->id.version = 0x0100;
214 twidjoy->dev.id.version = 0x0100; 210 input_dev->cdev.dev = &serio->dev;
215 twidjoy->dev.dev = &serio->dev; 211 input_dev->private = twidjoy;
216 212
217 twidjoy->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 213 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
218 214 input_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
219 for (bp = twidjoy_buttons; bp->bitmask; bp++) { 215 input_set_abs_params(input_dev, ABS_X, -50, 50, 4, 4);
216 input_set_abs_params(input_dev, ABS_Y, -50, 50, 4, 4);
217
218 for (bp = twidjoy_buttons; bp->bitmask; bp++)
220 for (i = 0; i < bp->bitmask; i++) 219 for (i = 0; i < bp->bitmask; i++)
221 set_bit(bp->buttons[i], twidjoy->dev.keybit); 220 set_bit(bp->buttons[i], input_dev->keybit);
222 }
223
224 twidjoy->dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
225
226 for (i = 0; i < 2; i++) {
227 twidjoy->dev.absmax[ABS_X+i] = 50;
228 twidjoy->dev.absmin[ABS_X+i] = -50;
229
230 /* TODO: arndt 20010708: Are these values appropriate? */
231 twidjoy->dev.absfuzz[ABS_X+i] = 4;
232 twidjoy->dev.absflat[ABS_X+i] = 4;
233 }
234
235 twidjoy->dev.private = twidjoy;
236 221
237 serio_set_drvdata(serio, twidjoy); 222 serio_set_drvdata(serio, twidjoy);
238 223
239 err = serio_open(serio, drv); 224 err = serio_open(serio, drv);
240 if (err) { 225 if (err)
241 serio_set_drvdata(serio, NULL); 226 goto fail;
242 kfree(twidjoy);
243 return err;
244 }
245
246 input_register_device(&twidjoy->dev);
247
248 printk(KERN_INFO "input: %s on %s\n", twidjoy_name, serio->phys);
249 227
228 input_register_device(twidjoy->dev);
250 return 0; 229 return 0;
230
231 fail: serio_set_drvdata(serio, NULL);
232 input_free_device(input_dev);
233 kfree(twidjoy);
234 return err;
251} 235}
252 236
253/* 237/*
diff --git a/drivers/input/joystick/warrior.c b/drivers/input/joystick/warrior.c
index 6976a219504c..99a642d2a1fe 100644
--- a/drivers/input/joystick/warrior.c
+++ b/drivers/input/joystick/warrior.c
@@ -47,14 +47,13 @@ MODULE_LICENSE("GPL");
47 47
48#define WARRIOR_MAX_LENGTH 16 48#define WARRIOR_MAX_LENGTH 16
49static char warrior_lengths[] = { 0, 4, 12, 3, 4, 4, 0, 0 }; 49static char warrior_lengths[] = { 0, 4, 12, 3, 4, 4, 0, 0 };
50static char *warrior_name = "Logitech WingMan Warrior";
51 50
52/* 51/*
53 * Per-Warrior data. 52 * Per-Warrior data.
54 */ 53 */
55 54
56struct warrior { 55struct warrior {
57 struct input_dev dev; 56 struct input_dev *dev;
58 int idx, len; 57 int idx, len;
59 unsigned char data[WARRIOR_MAX_LENGTH]; 58 unsigned char data[WARRIOR_MAX_LENGTH];
60 char phys[32]; 59 char phys[32];
@@ -67,7 +66,7 @@ struct warrior {
67 66
68static void warrior_process_packet(struct warrior *warrior, struct pt_regs *regs) 67static void warrior_process_packet(struct warrior *warrior, struct pt_regs *regs)
69{ 68{
70 struct input_dev *dev = &warrior->dev; 69 struct input_dev *dev = warrior->dev;
71 unsigned char *data = warrior->data; 70 unsigned char *data = warrior->data;
72 71
73 if (!warrior->idx) return; 72 if (!warrior->idx) return;
@@ -131,9 +130,9 @@ static void warrior_disconnect(struct serio *serio)
131{ 130{
132 struct warrior *warrior = serio_get_drvdata(serio); 131 struct warrior *warrior = serio_get_drvdata(serio);
133 132
134 input_unregister_device(&warrior->dev);
135 serio_close(serio); 133 serio_close(serio);
136 serio_set_drvdata(serio, NULL); 134 serio_set_drvdata(serio, NULL);
135 input_unregister_device(warrior->dev);
137 kfree(warrior); 136 kfree(warrior);
138} 137}
139 138
@@ -146,60 +145,48 @@ static void warrior_disconnect(struct serio *serio)
146static int warrior_connect(struct serio *serio, struct serio_driver *drv) 145static int warrior_connect(struct serio *serio, struct serio_driver *drv)
147{ 146{
148 struct warrior *warrior; 147 struct warrior *warrior;
149 int i; 148 struct input_dev *input_dev;
150 int err; 149 int err = -ENOMEM;
151 150
152 if (!(warrior = kmalloc(sizeof(struct warrior), GFP_KERNEL))) 151 warrior = kzalloc(sizeof(struct warrior), GFP_KERNEL);
153 return -ENOMEM; 152 input_dev = input_allocate_device();
154 153 if (!warrior || !input_dev)
155 memset(warrior, 0, sizeof(struct warrior)); 154 goto fail;
156
157 warrior->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL) | BIT(EV_ABS);
158 warrior->dev.keybit[LONG(BTN_TRIGGER)] = BIT(BTN_TRIGGER) | BIT(BTN_THUMB) | BIT(BTN_TOP) | BIT(BTN_TOP2);
159 warrior->dev.relbit[0] = BIT(REL_DIAL);
160 warrior->dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_THROTTLE) | BIT(ABS_HAT0X) | BIT(ABS_HAT0Y);
161 155
156 warrior->dev = input_dev;
162 sprintf(warrior->phys, "%s/input0", serio->phys); 157 sprintf(warrior->phys, "%s/input0", serio->phys);
163 158
164 init_input_dev(&warrior->dev); 159 input_dev->name = "Logitech WingMan Warrior";
165 warrior->dev.name = warrior_name; 160 input_dev->phys = warrior->phys;
166 warrior->dev.phys = warrior->phys; 161 input_dev->id.bustype = BUS_RS232;
167 warrior->dev.id.bustype = BUS_RS232; 162 input_dev->id.vendor = SERIO_WARRIOR;
168 warrior->dev.id.vendor = SERIO_WARRIOR; 163 input_dev->id.product = 0x0001;
169 warrior->dev.id.product = 0x0001; 164 input_dev->id.version = 0x0100;
170 warrior->dev.id.version = 0x0100; 165 input_dev->cdev.dev = &serio->dev;
171 warrior->dev.dev = &serio->dev; 166 input_dev->private = warrior;
172 167
173 for (i = 0; i < 2; i++) { 168 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL) | BIT(EV_ABS);
174 warrior->dev.absmax[ABS_X+i] = -64; 169 input_dev->keybit[LONG(BTN_TRIGGER)] = BIT(BTN_TRIGGER) | BIT(BTN_THUMB) | BIT(BTN_TOP) | BIT(BTN_TOP2);
175 warrior->dev.absmin[ABS_X+i] = 64; 170 input_dev->relbit[0] = BIT(REL_DIAL);
176 warrior->dev.absflat[ABS_X+i] = 8; 171 input_set_abs_params(input_dev, ABS_X, -64, 64, 0, 8);
177 } 172 input_set_abs_params(input_dev, ABS_Y, -64, 64, 0, 8);
178 173 input_set_abs_params(input_dev, ABS_THROTTLE, -112, 112, 0, 0);
179 warrior->dev.absmax[ABS_THROTTLE] = -112; 174 input_set_abs_params(input_dev, ABS_HAT0X, -1, 1, 0, 0);
180 warrior->dev.absmin[ABS_THROTTLE] = 112; 175 input_set_abs_params(input_dev, ABS_HAT0X, -1, 1, 0, 0);
181
182 for (i = 0; i < 2; i++) {
183 warrior->dev.absmax[ABS_HAT0X+i] = -1;
184 warrior->dev.absmin[ABS_HAT0X+i] = 1;
185 }
186
187 warrior->dev.private = warrior;
188 176
189 serio_set_drvdata(serio, warrior); 177 serio_set_drvdata(serio, warrior);
190 178
191 err = serio_open(serio, drv); 179 err = serio_open(serio, drv);
192 if (err) { 180 if (err)
193 serio_set_drvdata(serio, NULL); 181 goto fail;
194 kfree(warrior);
195 return err;
196 }
197
198 input_register_device(&warrior->dev);
199
200 printk(KERN_INFO "input: Logitech WingMan Warrior on %s\n", serio->phys);
201 182
183 input_register_device(warrior->dev);
202 return 0; 184 return 0;
185
186 fail: serio_set_drvdata(serio, NULL);
187 input_free_device(input_dev);
188 kfree(warrior);
189 return err;
203} 190}
204 191
205/* 192/*
diff --git a/drivers/input/keyboard/amikbd.c b/drivers/input/keyboard/amikbd.c
index 4e8e8ea214ab..4c8fb1f8631f 100644
--- a/drivers/input/keyboard/amikbd.c
+++ b/drivers/input/keyboard/amikbd.c
@@ -155,10 +155,7 @@ static const char *amikbd_messages[8] = {
155 [7] = KERN_WARNING "amikbd: keyboard interrupt\n" 155 [7] = KERN_WARNING "amikbd: keyboard interrupt\n"
156}; 156};
157 157
158static struct input_dev amikbd_dev; 158static struct input_dev *amikbd_dev;
159
160static char *amikbd_name = "Amiga keyboard";
161static char *amikbd_phys = "amikbd/input0";
162 159
163static irqreturn_t amikbd_interrupt(int irq, void *dummy, struct pt_regs *fp) 160static irqreturn_t amikbd_interrupt(int irq, void *dummy, struct pt_regs *fp)
164{ 161{
@@ -176,16 +173,16 @@ static irqreturn_t amikbd_interrupt(int irq, void *dummy, struct pt_regs *fp)
176 173
177 scancode = amikbd_keycode[scancode]; 174 scancode = amikbd_keycode[scancode];
178 175
179 input_regs(&amikbd_dev, fp); 176 input_regs(amikbd_dev, fp);
180 177
181 if (scancode == KEY_CAPSLOCK) { /* CapsLock is a toggle switch key on Amiga */ 178 if (scancode == KEY_CAPSLOCK) { /* CapsLock is a toggle switch key on Amiga */
182 input_report_key(&amikbd_dev, scancode, 1); 179 input_report_key(amikbd_dev, scancode, 1);
183 input_report_key(&amikbd_dev, scancode, 0); 180 input_report_key(amikbd_dev, scancode, 0);
184 input_sync(&amikbd_dev);
185 } else { 181 } else {
186 input_report_key(&amikbd_dev, scancode, down); 182 input_report_key(amikbd_dev, scancode, down);
187 input_sync(&amikbd_dev);
188 } 183 }
184
185 input_sync(amikbd_dev);
189 } else /* scancodes >= 0x78 are error codes */ 186 } else /* scancodes >= 0x78 are error codes */
190 printk(amikbd_messages[scancode - 0x78]); 187 printk(amikbd_messages[scancode - 0x78]);
191 188
@@ -202,39 +199,41 @@ static int __init amikbd_init(void)
202 if (!request_mem_region(CIAA_PHYSADDR-1+0xb00, 0x100, "amikeyb")) 199 if (!request_mem_region(CIAA_PHYSADDR-1+0xb00, 0x100, "amikeyb"))
203 return -EBUSY; 200 return -EBUSY;
204 201
205 init_input_dev(&amikbd_dev); 202 amikbd_dev = input_allocate_device();
206 203 if (!amikbd_dev) {
207 amikbd_dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP); 204 printk(KERN_ERR "amikbd: not enough memory for input device\n");
208 amikbd_dev.keycode = amikbd_keycode; 205 release_mem_region(CIAA_PHYSADDR - 1 + 0xb00, 0x100);
209 amikbd_dev.keycodesize = sizeof(unsigned char); 206 return -ENOMEM;
210 amikbd_dev.keycodemax = ARRAY_SIZE(amikbd_keycode); 207 }
208
209 amikbd_dev->name = "Amiga Keyboard";
210 amikbd_dev->phys = "amikbd/input0";
211 amikbd_dev->id.bustype = BUS_AMIGA;
212 amikbd_dev->id.vendor = 0x0001;
213 amikbd_dev->id.product = 0x0001;
214 amikbd_dev->id.version = 0x0100;
215
216 amikbd_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
217 amikbd_dev->keycode = amikbd_keycode;
218 amikbd_dev->keycodesize = sizeof(unsigned char);
219 amikbd_dev->keycodemax = ARRAY_SIZE(amikbd_keycode);
211 220
212 for (i = 0; i < 0x78; i++) 221 for (i = 0; i < 0x78; i++)
213 if (amikbd_keycode[i]) 222 if (amikbd_keycode[i])
214 set_bit(amikbd_keycode[i], amikbd_dev.keybit); 223 set_bit(amikbd_keycode[i], amikbd_dev->keybit);
215 224
216 ciaa.cra &= ~0x41; /* serial data in, turn off TA */ 225 ciaa.cra &= ~0x41; /* serial data in, turn off TA */
217 request_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd", amikbd_interrupt); 226 request_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd", amikbd_interrupt);
218 227
219 amikbd_dev.name = amikbd_name; 228 input_register_device(amikbd_dev);
220 amikbd_dev.phys = amikbd_phys;
221 amikbd_dev.id.bustype = BUS_AMIGA;
222 amikbd_dev.id.vendor = 0x0001;
223 amikbd_dev.id.product = 0x0001;
224 amikbd_dev.id.version = 0x0100;
225
226 input_register_device(&amikbd_dev);
227
228 printk(KERN_INFO "input: %s\n", amikbd_name);
229
230 return 0; 229 return 0;
231} 230}
232 231
233static void __exit amikbd_exit(void) 232static void __exit amikbd_exit(void)
234{ 233{
235 input_unregister_device(&amikbd_dev);
236 free_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt); 234 free_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt);
237 release_mem_region(CIAA_PHYSADDR-1+0xb00, 0x100); 235 input_unregister_device(amikbd_dev);
236 release_mem_region(CIAA_PHYSADDR - 1 + 0xb00, 0x100);
238} 237}
239 238
240module_init(amikbd_init); 239module_init(amikbd_init);
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index 1ad8c2ee7dbf..820c7fd9a604 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -185,12 +185,12 @@ static struct {
185 185
186struct atkbd { 186struct atkbd {
187 187
188 struct ps2dev ps2dev; 188 struct ps2dev ps2dev;
189 struct input_dev *dev;
189 190
190 /* Written only during init */ 191 /* Written only during init */
191 char name[64]; 192 char name[64];
192 char phys[32]; 193 char phys[32];
193 struct input_dev dev;
194 194
195 unsigned short id; 195 unsigned short id;
196 unsigned char keycode[512]; 196 unsigned char keycode[512];
@@ -290,7 +290,7 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
290 if (!atkbd->enabled) 290 if (!atkbd->enabled)
291 goto out; 291 goto out;
292 292
293 input_event(&atkbd->dev, EV_MSC, MSC_RAW, code); 293 input_event(atkbd->dev, EV_MSC, MSC_RAW, code);
294 294
295 if (atkbd->translated) { 295 if (atkbd->translated) {
296 296
@@ -326,10 +326,10 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
326 atkbd->release = 1; 326 atkbd->release = 1;
327 goto out; 327 goto out;
328 case ATKBD_RET_HANGUEL: 328 case ATKBD_RET_HANGUEL:
329 atkbd_report_key(&atkbd->dev, regs, KEY_HANGUEL, 3); 329 atkbd_report_key(atkbd->dev, regs, KEY_HANGUEL, 3);
330 goto out; 330 goto out;
331 case ATKBD_RET_HANJA: 331 case ATKBD_RET_HANJA:
332 atkbd_report_key(&atkbd->dev, regs, KEY_HANJA, 3); 332 atkbd_report_key(atkbd->dev, regs, KEY_HANJA, 3);
333 goto out; 333 goto out;
334 case ATKBD_RET_ERR: 334 case ATKBD_RET_ERR:
335 printk(KERN_DEBUG "atkbd.c: Keyboard on %s reports too many keys pressed.\n", serio->phys); 335 printk(KERN_DEBUG "atkbd.c: Keyboard on %s reports too many keys pressed.\n", serio->phys);
@@ -345,7 +345,7 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
345 } 345 }
346 346
347 if (atkbd->keycode[code] != ATKBD_KEY_NULL) 347 if (atkbd->keycode[code] != ATKBD_KEY_NULL)
348 input_event(&atkbd->dev, EV_MSC, MSC_SCAN, code); 348 input_event(atkbd->dev, EV_MSC, MSC_SCAN, code);
349 349
350 switch (atkbd->keycode[code]) { 350 switch (atkbd->keycode[code]) {
351 case ATKBD_KEY_NULL: 351 case ATKBD_KEY_NULL:
@@ -365,7 +365,7 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
365 "to make it known.\n", 365 "to make it known.\n",
366 code & 0x80 ? "e0" : "", code & 0x7f); 366 code & 0x80 ? "e0" : "", code & 0x7f);
367 } 367 }
368 input_sync(&atkbd->dev); 368 input_sync(atkbd->dev);
369 break; 369 break;
370 case ATKBD_SCR_1: 370 case ATKBD_SCR_1:
371 scroll = 1 - atkbd->release * 2; 371 scroll = 1 - atkbd->release * 2;
@@ -390,7 +390,7 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
390 break; 390 break;
391 default: 391 default:
392 value = atkbd->release ? 0 : 392 value = atkbd->release ? 0 :
393 (1 + (!atkbd->softrepeat && test_bit(atkbd->keycode[code], atkbd->dev.key))); 393 (1 + (!atkbd->softrepeat && test_bit(atkbd->keycode[code], atkbd->dev->key)));
394 394
395 switch (value) { /* Workaround Toshiba laptop multiple keypress */ 395 switch (value) { /* Workaround Toshiba laptop multiple keypress */
396 case 0: 396 case 0:
@@ -398,7 +398,7 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
398 break; 398 break;
399 case 1: 399 case 1:
400 atkbd->last = code; 400 atkbd->last = code;
401 atkbd->time = jiffies + msecs_to_jiffies(atkbd->dev.rep[REP_DELAY]) / 2; 401 atkbd->time = jiffies + msecs_to_jiffies(atkbd->dev->rep[REP_DELAY]) / 2;
402 break; 402 break;
403 case 2: 403 case 2:
404 if (!time_after(jiffies, atkbd->time) && atkbd->last == code) 404 if (!time_after(jiffies, atkbd->time) && atkbd->last == code)
@@ -406,16 +406,16 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
406 break; 406 break;
407 } 407 }
408 408
409 atkbd_report_key(&atkbd->dev, regs, atkbd->keycode[code], value); 409 atkbd_report_key(atkbd->dev, regs, atkbd->keycode[code], value);
410 } 410 }
411 411
412 if (atkbd->scroll) { 412 if (atkbd->scroll) {
413 input_regs(&atkbd->dev, regs); 413 input_regs(atkbd->dev, regs);
414 if (click != -1) 414 if (click != -1)
415 input_report_key(&atkbd->dev, BTN_MIDDLE, click); 415 input_report_key(atkbd->dev, BTN_MIDDLE, click);
416 input_report_rel(&atkbd->dev, REL_WHEEL, scroll); 416 input_report_rel(atkbd->dev, REL_WHEEL, scroll);
417 input_report_rel(&atkbd->dev, REL_HWHEEL, hscroll); 417 input_report_rel(atkbd->dev, REL_HWHEEL, hscroll);
418 input_sync(&atkbd->dev); 418 input_sync(atkbd->dev);
419 } 419 }
420 420
421 atkbd->release = 0; 421 atkbd->release = 0;
@@ -463,7 +463,6 @@ static int atkbd_event(struct input_dev *dev, unsigned int type, unsigned int co
463 463
464 return 0; 464 return 0;
465 465
466
467 case EV_REP: 466 case EV_REP:
468 467
469 if (atkbd->softrepeat) return 0; 468 if (atkbd->softrepeat) return 0;
@@ -693,7 +692,7 @@ static void atkbd_disconnect(struct serio *serio)
693 device_remove_file(&serio->dev, &atkbd_attr_softrepeat); 692 device_remove_file(&serio->dev, &atkbd_attr_softrepeat);
694 device_remove_file(&serio->dev, &atkbd_attr_softraw); 693 device_remove_file(&serio->dev, &atkbd_attr_softraw);
695 694
696 input_unregister_device(&atkbd->dev); 695 input_unregister_device(atkbd->dev);
697 serio_close(serio); 696 serio_close(serio);
698 serio_set_drvdata(serio, NULL); 697 serio_set_drvdata(serio, NULL);
699 kfree(atkbd); 698 kfree(atkbd);
@@ -701,7 +700,7 @@ static void atkbd_disconnect(struct serio *serio)
701 700
702 701
703/* 702/*
704 * atkbd_set_device_attrs() initializes keyboard's keycode table 703 * atkbd_set_keycode_table() initializes keyboard's keycode table
705 * according to the selected scancode set 704 * according to the selected scancode set
706 */ 705 */
707 706
@@ -737,53 +736,58 @@ static void atkbd_set_keycode_table(struct atkbd *atkbd)
737 736
738static void atkbd_set_device_attrs(struct atkbd *atkbd) 737static void atkbd_set_device_attrs(struct atkbd *atkbd)
739{ 738{
739 struct input_dev *input_dev = atkbd->dev;
740 int i; 740 int i;
741 741
742 memset(&atkbd->dev, 0, sizeof(struct input_dev)); 742 if (atkbd->extra)
743 sprintf(atkbd->name, "AT Set 2 Extra keyboard");
744 else
745 sprintf(atkbd->name, "AT %s Set %d keyboard",
746 atkbd->translated ? "Translated" : "Raw", atkbd->set);
743 747
744 init_input_dev(&atkbd->dev); 748 sprintf(atkbd->phys, "%s/input0", atkbd->ps2dev.serio->phys);
745 749
746 atkbd->dev.name = atkbd->name; 750 input_dev->name = atkbd->name;
747 atkbd->dev.phys = atkbd->phys; 751 input_dev->phys = atkbd->phys;
748 atkbd->dev.id.bustype = BUS_I8042; 752 input_dev->id.bustype = BUS_I8042;
749 atkbd->dev.id.vendor = 0x0001; 753 input_dev->id.vendor = 0x0001;
750 atkbd->dev.id.product = atkbd->translated ? 1 : atkbd->set; 754 input_dev->id.product = atkbd->translated ? 1 : atkbd->set;
751 atkbd->dev.id.version = atkbd->id; 755 input_dev->id.version = atkbd->id;
752 atkbd->dev.event = atkbd_event; 756 input_dev->event = atkbd_event;
753 atkbd->dev.private = atkbd; 757 input_dev->private = atkbd;
754 atkbd->dev.dev = &atkbd->ps2dev.serio->dev; 758 input_dev->cdev.dev = &atkbd->ps2dev.serio->dev;
755 759
756 atkbd->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_MSC); 760 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_MSC);
757 761
758 if (atkbd->write) { 762 if (atkbd->write) {
759 atkbd->dev.evbit[0] |= BIT(EV_LED); 763 input_dev->evbit[0] |= BIT(EV_LED);
760 atkbd->dev.ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL); 764 input_dev->ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL);
761 } 765 }
762 766
763 if (atkbd->extra) 767 if (atkbd->extra)
764 atkbd->dev.ledbit[0] |= BIT(LED_COMPOSE) | BIT(LED_SUSPEND) | 768 input_dev->ledbit[0] |= BIT(LED_COMPOSE) | BIT(LED_SUSPEND) |
765 BIT(LED_SLEEP) | BIT(LED_MUTE) | BIT(LED_MISC); 769 BIT(LED_SLEEP) | BIT(LED_MUTE) | BIT(LED_MISC);
766 770
767 if (!atkbd->softrepeat) { 771 if (!atkbd->softrepeat) {
768 atkbd->dev.rep[REP_DELAY] = 250; 772 input_dev->rep[REP_DELAY] = 250;
769 atkbd->dev.rep[REP_PERIOD] = 33; 773 input_dev->rep[REP_PERIOD] = 33;
770 } 774 }
771 775
772 atkbd->dev.mscbit[0] = atkbd->softraw ? BIT(MSC_SCAN) : BIT(MSC_RAW) | BIT(MSC_SCAN); 776 input_dev->mscbit[0] = atkbd->softraw ? BIT(MSC_SCAN) : BIT(MSC_RAW) | BIT(MSC_SCAN);
773 777
774 if (atkbd->scroll) { 778 if (atkbd->scroll) {
775 atkbd->dev.evbit[0] |= BIT(EV_REL); 779 input_dev->evbit[0] |= BIT(EV_REL);
776 atkbd->dev.relbit[0] = BIT(REL_WHEEL) | BIT(REL_HWHEEL); 780 input_dev->relbit[0] = BIT(REL_WHEEL) | BIT(REL_HWHEEL);
777 set_bit(BTN_MIDDLE, atkbd->dev.keybit); 781 set_bit(BTN_MIDDLE, input_dev->keybit);
778 } 782 }
779 783
780 atkbd->dev.keycode = atkbd->keycode; 784 input_dev->keycode = atkbd->keycode;
781 atkbd->dev.keycodesize = sizeof(unsigned char); 785 input_dev->keycodesize = sizeof(unsigned char);
782 atkbd->dev.keycodemax = ARRAY_SIZE(atkbd_set2_keycode); 786 input_dev->keycodemax = ARRAY_SIZE(atkbd_set2_keycode);
783 787
784 for (i = 0; i < 512; i++) 788 for (i = 0; i < 512; i++)
785 if (atkbd->keycode[i] && atkbd->keycode[i] < ATKBD_SPECIAL) 789 if (atkbd->keycode[i] && atkbd->keycode[i] < ATKBD_SPECIAL)
786 set_bit(atkbd->keycode[i], atkbd->dev.keybit); 790 set_bit(atkbd->keycode[i], input_dev->keybit);
787} 791}
788 792
789/* 793/*
@@ -796,13 +800,15 @@ static void atkbd_set_device_attrs(struct atkbd *atkbd)
796static int atkbd_connect(struct serio *serio, struct serio_driver *drv) 800static int atkbd_connect(struct serio *serio, struct serio_driver *drv)
797{ 801{
798 struct atkbd *atkbd; 802 struct atkbd *atkbd;
799 int err; 803 struct input_dev *dev;
800 804 int err = -ENOMEM;
801 if (!(atkbd = kmalloc(sizeof(struct atkbd), GFP_KERNEL)))
802 return - ENOMEM;
803 805
804 memset(atkbd, 0, sizeof(struct atkbd)); 806 atkbd = kzalloc(sizeof(struct atkbd), GFP_KERNEL);
807 dev = input_allocate_device();
808 if (!atkbd || !dev)
809 goto fail;
805 810
811 atkbd->dev = dev;
806 ps2_init(&atkbd->ps2dev, serio); 812 ps2_init(&atkbd->ps2dev, serio);
807 813
808 switch (serio->id.type) { 814 switch (serio->id.type) {
@@ -828,19 +834,15 @@ static int atkbd_connect(struct serio *serio, struct serio_driver *drv)
828 serio_set_drvdata(serio, atkbd); 834 serio_set_drvdata(serio, atkbd);
829 835
830 err = serio_open(serio, drv); 836 err = serio_open(serio, drv);
831 if (err) { 837 if (err)
832 serio_set_drvdata(serio, NULL); 838 goto fail;
833 kfree(atkbd);
834 return err;
835 }
836 839
837 if (atkbd->write) { 840 if (atkbd->write) {
838 841
839 if (atkbd_probe(atkbd)) { 842 if (atkbd_probe(atkbd)) {
840 serio_close(serio); 843 serio_close(serio);
841 serio_set_drvdata(serio, NULL); 844 err = -ENODEV;
842 kfree(atkbd); 845 goto fail;
843 return -ENODEV;
844 } 846 }
845 847
846 atkbd->set = atkbd_select_set(atkbd, atkbd_set, atkbd_extra); 848 atkbd->set = atkbd_select_set(atkbd, atkbd_set, atkbd_extra);
@@ -851,19 +853,9 @@ static int atkbd_connect(struct serio *serio, struct serio_driver *drv)
851 atkbd->id = 0xab00; 853 atkbd->id = 0xab00;
852 } 854 }
853 855
854 if (atkbd->extra)
855 sprintf(atkbd->name, "AT Set 2 Extra keyboard");
856 else
857 sprintf(atkbd->name, "AT %s Set %d keyboard",
858 atkbd->translated ? "Translated" : "Raw", atkbd->set);
859
860 sprintf(atkbd->phys, "%s/input0", serio->phys);
861
862 atkbd_set_keycode_table(atkbd); 856 atkbd_set_keycode_table(atkbd);
863 atkbd_set_device_attrs(atkbd); 857 atkbd_set_device_attrs(atkbd);
864 858
865 input_register_device(&atkbd->dev);
866
867 device_create_file(&serio->dev, &atkbd_attr_extra); 859 device_create_file(&serio->dev, &atkbd_attr_extra);
868 device_create_file(&serio->dev, &atkbd_attr_scroll); 860 device_create_file(&serio->dev, &atkbd_attr_scroll);
869 device_create_file(&serio->dev, &atkbd_attr_set); 861 device_create_file(&serio->dev, &atkbd_attr_set);
@@ -872,9 +864,14 @@ static int atkbd_connect(struct serio *serio, struct serio_driver *drv)
872 864
873 atkbd_enable(atkbd); 865 atkbd_enable(atkbd);
874 866
875 printk(KERN_INFO "input: %s on %s\n", atkbd->name, serio->phys); 867 input_register_device(atkbd->dev);
876 868
877 return 0; 869 return 0;
870
871 fail: serio_set_drvdata(serio, NULL);
872 input_free_device(dev);
873 kfree(atkbd);
874 return err;
878} 875}
879 876
880/* 877/*
@@ -896,9 +893,9 @@ static int atkbd_reconnect(struct serio *serio)
896 atkbd_disable(atkbd); 893 atkbd_disable(atkbd);
897 894
898 if (atkbd->write) { 895 if (atkbd->write) {
899 param[0] = (test_bit(LED_SCROLLL, atkbd->dev.led) ? 1 : 0) 896 param[0] = (test_bit(LED_SCROLLL, atkbd->dev->led) ? 1 : 0)
900 | (test_bit(LED_NUML, atkbd->dev.led) ? 2 : 0) 897 | (test_bit(LED_NUML, atkbd->dev->led) ? 2 : 0)
901 | (test_bit(LED_CAPSL, atkbd->dev.led) ? 4 : 0); 898 | (test_bit(LED_CAPSL, atkbd->dev->led) ? 4 : 0);
902 899
903 if (atkbd_probe(atkbd)) 900 if (atkbd_probe(atkbd))
904 return -1; 901 return -1;
@@ -1008,6 +1005,7 @@ static ssize_t atkbd_show_extra(struct atkbd *atkbd, char *buf)
1008 1005
1009static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t count) 1006static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t count)
1010{ 1007{
1008 struct input_dev *new_dev;
1011 unsigned long value; 1009 unsigned long value;
1012 char *rest; 1010 char *rest;
1013 1011
@@ -1019,12 +1017,19 @@ static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t coun
1019 return -EINVAL; 1017 return -EINVAL;
1020 1018
1021 if (atkbd->extra != value) { 1019 if (atkbd->extra != value) {
1022 /* unregister device as it's properties will change */ 1020 /*
1023 input_unregister_device(&atkbd->dev); 1021 * Since device's properties will change we need to
1022 * unregister old device. But allocate new one first
1023 * to make sure we have it.
1024 */
1025 if (!(new_dev = input_allocate_device()))
1026 return -ENOMEM;
1027 input_unregister_device(atkbd->dev);
1028 atkbd->dev = new_dev;
1024 atkbd->set = atkbd_select_set(atkbd, atkbd->set, value); 1029 atkbd->set = atkbd_select_set(atkbd, atkbd->set, value);
1025 atkbd_activate(atkbd); 1030 atkbd_activate(atkbd);
1026 atkbd_set_device_attrs(atkbd); 1031 atkbd_set_device_attrs(atkbd);
1027 input_register_device(&atkbd->dev); 1032 input_register_device(atkbd->dev);
1028 } 1033 }
1029 return count; 1034 return count;
1030} 1035}
@@ -1036,6 +1041,7 @@ static ssize_t atkbd_show_scroll(struct atkbd *atkbd, char *buf)
1036 1041
1037static ssize_t atkbd_set_scroll(struct atkbd *atkbd, const char *buf, size_t count) 1042static ssize_t atkbd_set_scroll(struct atkbd *atkbd, const char *buf, size_t count)
1038{ 1043{
1044 struct input_dev *new_dev;
1039 unsigned long value; 1045 unsigned long value;
1040 char *rest; 1046 char *rest;
1041 1047
@@ -1044,12 +1050,14 @@ static ssize_t atkbd_set_scroll(struct atkbd *atkbd, const char *buf, size_t cou
1044 return -EINVAL; 1050 return -EINVAL;
1045 1051
1046 if (atkbd->scroll != value) { 1052 if (atkbd->scroll != value) {
1047 /* unregister device as it's properties will change */ 1053 if (!(new_dev = input_allocate_device()))
1048 input_unregister_device(&atkbd->dev); 1054 return -ENOMEM;
1055 input_unregister_device(atkbd->dev);
1056 atkbd->dev = new_dev;
1049 atkbd->scroll = value; 1057 atkbd->scroll = value;
1050 atkbd_set_keycode_table(atkbd); 1058 atkbd_set_keycode_table(atkbd);
1051 atkbd_set_device_attrs(atkbd); 1059 atkbd_set_device_attrs(atkbd);
1052 input_register_device(&atkbd->dev); 1060 input_register_device(atkbd->dev);
1053 } 1061 }
1054 return count; 1062 return count;
1055} 1063}
@@ -1061,6 +1069,7 @@ static ssize_t atkbd_show_set(struct atkbd *atkbd, char *buf)
1061 1069
1062static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count) 1070static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count)
1063{ 1071{
1072 struct input_dev *new_dev;
1064 unsigned long value; 1073 unsigned long value;
1065 char *rest; 1074 char *rest;
1066 1075
@@ -1072,13 +1081,15 @@ static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count)
1072 return -EINVAL; 1081 return -EINVAL;
1073 1082
1074 if (atkbd->set != value) { 1083 if (atkbd->set != value) {
1075 /* unregister device as it's properties will change */ 1084 if (!(new_dev = input_allocate_device()))
1076 input_unregister_device(&atkbd->dev); 1085 return -ENOMEM;
1086 input_unregister_device(atkbd->dev);
1087 atkbd->dev = new_dev;
1077 atkbd->set = atkbd_select_set(atkbd, value, atkbd->extra); 1088 atkbd->set = atkbd_select_set(atkbd, value, atkbd->extra);
1078 atkbd_activate(atkbd); 1089 atkbd_activate(atkbd);
1079 atkbd_set_keycode_table(atkbd); 1090 atkbd_set_keycode_table(atkbd);
1080 atkbd_set_device_attrs(atkbd); 1091 atkbd_set_device_attrs(atkbd);
1081 input_register_device(&atkbd->dev); 1092 input_register_device(atkbd->dev);
1082 } 1093 }
1083 return count; 1094 return count;
1084} 1095}
@@ -1090,6 +1101,7 @@ static ssize_t atkbd_show_softrepeat(struct atkbd *atkbd, char *buf)
1090 1101
1091static ssize_t atkbd_set_softrepeat(struct atkbd *atkbd, const char *buf, size_t count) 1102static ssize_t atkbd_set_softrepeat(struct atkbd *atkbd, const char *buf, size_t count)
1092{ 1103{
1104 struct input_dev *new_dev;
1093 unsigned long value; 1105 unsigned long value;
1094 char *rest; 1106 char *rest;
1095 1107
@@ -1101,15 +1113,16 @@ static ssize_t atkbd_set_softrepeat(struct atkbd *atkbd, const char *buf, size_t
1101 return -EINVAL; 1113 return -EINVAL;
1102 1114
1103 if (atkbd->softrepeat != value) { 1115 if (atkbd->softrepeat != value) {
1104 /* unregister device as it's properties will change */ 1116 if (!(new_dev = input_allocate_device()))
1105 input_unregister_device(&atkbd->dev); 1117 return -ENOMEM;
1118 input_unregister_device(atkbd->dev);
1119 atkbd->dev = new_dev;
1106 atkbd->softrepeat = value; 1120 atkbd->softrepeat = value;
1107 if (atkbd->softrepeat) 1121 if (atkbd->softrepeat)
1108 atkbd->softraw = 1; 1122 atkbd->softraw = 1;
1109 atkbd_set_device_attrs(atkbd); 1123 atkbd_set_device_attrs(atkbd);
1110 input_register_device(&atkbd->dev); 1124 input_register_device(atkbd->dev);
1111 } 1125 }
1112
1113 return count; 1126 return count;
1114} 1127}
1115 1128
@@ -1121,6 +1134,7 @@ static ssize_t atkbd_show_softraw(struct atkbd *atkbd, char *buf)
1121 1134
1122static ssize_t atkbd_set_softraw(struct atkbd *atkbd, const char *buf, size_t count) 1135static ssize_t atkbd_set_softraw(struct atkbd *atkbd, const char *buf, size_t count)
1123{ 1136{
1137 struct input_dev *new_dev;
1124 unsigned long value; 1138 unsigned long value;
1125 char *rest; 1139 char *rest;
1126 1140
@@ -1129,11 +1143,13 @@ static ssize_t atkbd_set_softraw(struct atkbd *atkbd, const char *buf, size_t co
1129 return -EINVAL; 1143 return -EINVAL;
1130 1144
1131 if (atkbd->softraw != value) { 1145 if (atkbd->softraw != value) {
1132 /* unregister device as it's properties will change */ 1146 if (!(new_dev = input_allocate_device()))
1133 input_unregister_device(&atkbd->dev); 1147 return -ENOMEM;
1148 input_unregister_device(atkbd->dev);
1149 atkbd->dev = new_dev;
1134 atkbd->softraw = value; 1150 atkbd->softraw = value;
1135 atkbd_set_device_attrs(atkbd); 1151 atkbd_set_device_attrs(atkbd);
1136 input_register_device(&atkbd->dev); 1152 input_register_device(atkbd->dev);
1137 } 1153 }
1138 return count; 1154 return count;
1139} 1155}
diff --git a/drivers/input/keyboard/corgikbd.c b/drivers/input/keyboard/corgikbd.c
index cd4b6e795013..3210d298b3bc 100644
--- a/drivers/input/keyboard/corgikbd.c
+++ b/drivers/input/keyboard/corgikbd.c
@@ -70,8 +70,7 @@ static unsigned char corgikbd_keycode[NR_SCANCODES] = {
70 70
71struct corgikbd { 71struct corgikbd {
72 unsigned char keycode[ARRAY_SIZE(corgikbd_keycode)]; 72 unsigned char keycode[ARRAY_SIZE(corgikbd_keycode)];
73 struct input_dev input; 73 struct input_dev *input;
74 char phys[32];
75 74
76 spinlock_t lock; 75 spinlock_t lock;
77 struct timer_list timer; 76 struct timer_list timer;
@@ -147,7 +146,7 @@ static void corgikbd_scankeyboard(struct corgikbd *corgikbd_data, struct pt_regs
147 spin_lock_irqsave(&corgikbd_data->lock, flags); 146 spin_lock_irqsave(&corgikbd_data->lock, flags);
148 147
149 if (regs) 148 if (regs)
150 input_regs(&corgikbd_data->input, regs); 149 input_regs(corgikbd_data->input, regs);
151 150
152 num_pressed = 0; 151 num_pressed = 0;
153 for (col = 0; col < KB_COLS; col++) { 152 for (col = 0; col < KB_COLS; col++) {
@@ -169,14 +168,14 @@ static void corgikbd_scankeyboard(struct corgikbd *corgikbd_data, struct pt_regs
169 scancode = SCANCODE(row, col); 168 scancode = SCANCODE(row, col);
170 pressed = rowd & KB_ROWMASK(row); 169 pressed = rowd & KB_ROWMASK(row);
171 170
172 input_report_key(&corgikbd_data->input, corgikbd_data->keycode[scancode], pressed); 171 input_report_key(corgikbd_data->input, corgikbd_data->keycode[scancode], pressed);
173 172
174 if (pressed) 173 if (pressed)
175 num_pressed++; 174 num_pressed++;
176 175
177 if (pressed && (corgikbd_data->keycode[scancode] == CORGI_KEY_OFF) 176 if (pressed && (corgikbd_data->keycode[scancode] == CORGI_KEY_OFF)
178 && time_after(jiffies, corgikbd_data->suspend_jiffies + HZ)) { 177 && time_after(jiffies, corgikbd_data->suspend_jiffies + HZ)) {
179 input_event(&corgikbd_data->input, EV_PWR, CORGI_KEY_OFF, 1); 178 input_event(corgikbd_data->input, EV_PWR, CORGI_KEY_OFF, 1);
180 corgikbd_data->suspend_jiffies=jiffies; 179 corgikbd_data->suspend_jiffies=jiffies;
181 } 180 }
182 } 181 }
@@ -185,7 +184,7 @@ static void corgikbd_scankeyboard(struct corgikbd *corgikbd_data, struct pt_regs
185 184
186 corgikbd_activate_all(); 185 corgikbd_activate_all();
187 186
188 input_sync(&corgikbd_data->input); 187 input_sync(corgikbd_data->input);
189 188
190 /* if any keys are pressed, enable the timer */ 189 /* if any keys are pressed, enable the timer */
191 if (num_pressed) 190 if (num_pressed)
@@ -249,9 +248,9 @@ static void corgikbd_hinge_timer(unsigned long data)
249 if (hinge_count >= HINGE_STABLE_COUNT) { 248 if (hinge_count >= HINGE_STABLE_COUNT) {
250 spin_lock_irqsave(&corgikbd_data->lock, flags); 249 spin_lock_irqsave(&corgikbd_data->lock, flags);
251 250
252 input_report_switch(&corgikbd_data->input, SW_0, ((sharpsl_hinge_state & CORGI_SCP_SWA) != 0)); 251 input_report_switch(corgikbd_data->input, SW_0, ((sharpsl_hinge_state & CORGI_SCP_SWA) != 0));
253 input_report_switch(&corgikbd_data->input, SW_1, ((sharpsl_hinge_state & CORGI_SCP_SWB) != 0)); 252 input_report_switch(corgikbd_data->input, SW_1, ((sharpsl_hinge_state & CORGI_SCP_SWB) != 0));
254 input_sync(&corgikbd_data->input); 253 input_sync(corgikbd_data->input);
255 254
256 spin_unlock_irqrestore(&corgikbd_data->lock, flags); 255 spin_unlock_irqrestore(&corgikbd_data->lock, flags);
257 } 256 }
@@ -260,24 +259,22 @@ static void corgikbd_hinge_timer(unsigned long data)
260} 259}
261 260
262#ifdef CONFIG_PM 261#ifdef CONFIG_PM
263static int corgikbd_suspend(struct device *dev, pm_message_t state, uint32_t level) 262static int corgikbd_suspend(struct device *dev, pm_message_t state)
264{ 263{
265 if (level == SUSPEND_POWER_DOWN) { 264 struct corgikbd *corgikbd = dev_get_drvdata(dev);
266 struct corgikbd *corgikbd = dev_get_drvdata(dev); 265 corgikbd->suspended = 1;
267 corgikbd->suspended = 1; 266
268 }
269 return 0; 267 return 0;
270} 268}
271 269
272static int corgikbd_resume(struct device *dev, uint32_t level) 270static int corgikbd_resume(struct device *dev)
273{ 271{
274 if (level == RESUME_POWER_ON) { 272 struct corgikbd *corgikbd = dev_get_drvdata(dev);
275 struct corgikbd *corgikbd = dev_get_drvdata(dev); 273
274 /* Upon resume, ignore the suspend key for a short while */
275 corgikbd->suspend_jiffies=jiffies;
276 corgikbd->suspended = 0;
276 277
277 /* Upon resume, ignore the suspend key for a short while */
278 corgikbd->suspend_jiffies=jiffies;
279 corgikbd->suspended = 0;
280 }
281 return 0; 278 return 0;
282} 279}
283#else 280#else
@@ -287,16 +284,21 @@ static int corgikbd_resume(struct device *dev, uint32_t level)
287 284
288static int __init corgikbd_probe(struct device *dev) 285static int __init corgikbd_probe(struct device *dev)
289{ 286{
290 int i;
291 struct corgikbd *corgikbd; 287 struct corgikbd *corgikbd;
288 struct input_dev *input_dev;
289 int i;
292 290
293 corgikbd = kzalloc(sizeof(struct corgikbd), GFP_KERNEL); 291 corgikbd = kzalloc(sizeof(struct corgikbd), GFP_KERNEL);
294 if (!corgikbd) 292 input_dev = input_allocate_device();
293 if (!corgikbd || !input_dev) {
294 kfree(corgikbd);
295 input_free_device(input_dev);
295 return -ENOMEM; 296 return -ENOMEM;
297 }
296 298
297 dev_set_drvdata(dev,corgikbd); 299 dev_set_drvdata(dev, corgikbd);
298 strcpy(corgikbd->phys, "corgikbd/input0");
299 300
301 corgikbd->input = input_dev;
300 spin_lock_init(&corgikbd->lock); 302 spin_lock_init(&corgikbd->lock);
301 303
302 /* Init Keyboard rescan timer */ 304 /* Init Keyboard rescan timer */
@@ -311,28 +313,30 @@ static int __init corgikbd_probe(struct device *dev)
311 313
312 corgikbd->suspend_jiffies=jiffies; 314 corgikbd->suspend_jiffies=jiffies;
313 315
314 init_input_dev(&corgikbd->input);
315 corgikbd->input.private = corgikbd;
316 corgikbd->input.name = "Corgi Keyboard";
317 corgikbd->input.dev = dev;
318 corgikbd->input.phys = corgikbd->phys;
319 corgikbd->input.id.bustype = BUS_HOST;
320 corgikbd->input.id.vendor = 0x0001;
321 corgikbd->input.id.product = 0x0001;
322 corgikbd->input.id.version = 0x0100;
323 corgikbd->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_PWR) | BIT(EV_SW);
324 corgikbd->input.keycode = corgikbd->keycode;
325 corgikbd->input.keycodesize = sizeof(unsigned char);
326 corgikbd->input.keycodemax = ARRAY_SIZE(corgikbd_keycode);
327
328 memcpy(corgikbd->keycode, corgikbd_keycode, sizeof(corgikbd->keycode)); 316 memcpy(corgikbd->keycode, corgikbd_keycode, sizeof(corgikbd->keycode));
317
318 input_dev->name = "Corgi Keyboard";
319 input_dev->phys = "corgikbd/input0";
320 input_dev->id.bustype = BUS_HOST;
321 input_dev->id.vendor = 0x0001;
322 input_dev->id.product = 0x0001;
323 input_dev->id.version = 0x0100;
324 input_dev->cdev.dev = dev;
325 input_dev->private = corgikbd;
326
327 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_PWR) | BIT(EV_SW);
328 input_dev->keycode = corgikbd->keycode;
329 input_dev->keycodesize = sizeof(unsigned char);
330 input_dev->keycodemax = ARRAY_SIZE(corgikbd_keycode);
331
329 for (i = 0; i < ARRAY_SIZE(corgikbd_keycode); i++) 332 for (i = 0; i < ARRAY_SIZE(corgikbd_keycode); i++)
330 set_bit(corgikbd->keycode[i], corgikbd->input.keybit); 333 set_bit(corgikbd->keycode[i], input_dev->keybit);
331 clear_bit(0, corgikbd->input.keybit); 334 clear_bit(0, input_dev->keybit);
332 set_bit(SW_0, corgikbd->input.swbit); 335 set_bit(SW_0, input_dev->swbit);
333 set_bit(SW_1, corgikbd->input.swbit); 336 set_bit(SW_1, input_dev->swbit);
337
338 input_register_device(corgikbd->input);
334 339
335 input_register_device(&corgikbd->input);
336 mod_timer(&corgikbd->htimer, jiffies + HINGE_SCAN_INTERVAL); 340 mod_timer(&corgikbd->htimer, jiffies + HINGE_SCAN_INTERVAL);
337 341
338 /* Setup sense interrupts - RisingEdge Detect, sense lines as inputs */ 342 /* Setup sense interrupts - RisingEdge Detect, sense lines as inputs */
@@ -349,8 +353,6 @@ static int __init corgikbd_probe(struct device *dev)
349 for (i = 0; i < CORGI_KEY_STROBE_NUM; i++) 353 for (i = 0; i < CORGI_KEY_STROBE_NUM; i++)
350 pxa_gpio_mode(CORGI_GPIO_KEY_STROBE(i) | GPIO_OUT | GPIO_DFLT_HIGH); 354 pxa_gpio_mode(CORGI_GPIO_KEY_STROBE(i) | GPIO_OUT | GPIO_DFLT_HIGH);
351 355
352 printk(KERN_INFO "input: Corgi Keyboard Registered\n");
353
354 return 0; 356 return 0;
355} 357}
356 358
@@ -365,7 +367,7 @@ static int corgikbd_remove(struct device *dev)
365 del_timer_sync(&corgikbd->htimer); 367 del_timer_sync(&corgikbd->htimer);
366 del_timer_sync(&corgikbd->timer); 368 del_timer_sync(&corgikbd->timer);
367 369
368 input_unregister_device(&corgikbd->input); 370 input_unregister_device(corgikbd->input);
369 371
370 kfree(corgikbd); 372 kfree(corgikbd);
371 373
diff --git a/drivers/input/keyboard/hil_kbd.c b/drivers/input/keyboard/hil_kbd.c
index ef78bffed5e7..0a90962c38e7 100644
--- a/drivers/input/keyboard/hil_kbd.c
+++ b/drivers/input/keyboard/hil_kbd.c
@@ -204,7 +204,7 @@ static irqreturn_t hil_kbd_interrupt(struct serio *serio,
204 hil_packet packet; 204 hil_packet packet;
205 int idx; 205 int idx;
206 206
207 kbd = (struct hil_kbd *)serio->private; 207 kbd = serio_get_drvdata(serio);
208 if (kbd == NULL) { 208 if (kbd == NULL) {
209 BUG(); 209 BUG();
210 return IRQ_HANDLED; 210 return IRQ_HANDLED;
@@ -234,7 +234,7 @@ static void hil_kbd_disconnect(struct serio *serio)
234{ 234{
235 struct hil_kbd *kbd; 235 struct hil_kbd *kbd;
236 236
237 kbd = (struct hil_kbd *)serio->private; 237 kbd = serio_get_drvdata(serio);
238 if (kbd == NULL) { 238 if (kbd == NULL) {
239 BUG(); 239 BUG();
240 return; 240 return;
@@ -245,20 +245,20 @@ static void hil_kbd_disconnect(struct serio *serio)
245 kfree(kbd); 245 kfree(kbd);
246} 246}
247 247
248static void hil_kbd_connect(struct serio *serio, struct serio_driver *drv) 248static int hil_kbd_connect(struct serio *serio, struct serio_driver *drv)
249{ 249{
250 struct hil_kbd *kbd; 250 struct hil_kbd *kbd;
251 uint8_t did, *idd; 251 uint8_t did, *idd;
252 int i; 252 int i;
253 253
254 if (serio->type != (SERIO_HIL_MLC | SERIO_HIL)) return; 254 kbd = kmalloc(sizeof(*kbd), GFP_KERNEL);
255 255 if (!kbd)
256 if (!(kbd = kmalloc(sizeof(struct hil_kbd), GFP_KERNEL))) return; 256 return -ENOMEM;
257 memset(kbd, 0, sizeof(struct hil_kbd)); 257 memset(kbd, 0, sizeof(struct hil_kbd));
258 258
259 if (serio_open(serio, drv)) goto bail0; 259 if (serio_open(serio, drv)) goto bail0;
260 260
261 serio->private = kbd; 261 serio_set_drvdata(serio, kbd);
262 kbd->serio = serio; 262 kbd->serio = serio;
263 kbd->dev.private = kbd; 263 kbd->dev.private = kbd;
264 264
@@ -342,19 +342,31 @@ static void hil_kbd_connect(struct serio *serio, struct serio_driver *drv)
342 down(&(kbd->sem)); 342 down(&(kbd->sem));
343 up(&(kbd->sem)); 343 up(&(kbd->sem));
344 344
345 return; 345 return 0;
346 bail1: 346 bail1:
347 serio_close(serio); 347 serio_close(serio);
348 bail0: 348 bail0:
349 kfree(kbd); 349 kfree(kbd);
350 serio_set_drvdata(serio, NULL);
351 return -EIO;
350} 352}
351 353
354static struct serio_device_id hil_kbd_ids[] = {
355 {
356 .type = SERIO_HIL_MLC,
357 .proto = SERIO_HIL,
358 .id = SERIO_ANY,
359 .extra = SERIO_ANY,
360 },
361 { 0 }
362};
352 363
353struct serio_driver hil_kbd_serio_drv = { 364struct serio_driver hil_kbd_serio_drv = {
354 .driver = { 365 .driver = {
355 .name = "hil_kbd", 366 .name = "hil_kbd",
356 }, 367 },
357 .description = "HP HIL keyboard driver", 368 .description = "HP HIL keyboard driver",
369 .id_table = hil_kbd_ids,
358 .connect = hil_kbd_connect, 370 .connect = hil_kbd_connect,
359 .disconnect = hil_kbd_disconnect, 371 .disconnect = hil_kbd_disconnect,
360 .interrupt = hil_kbd_interrupt 372 .interrupt = hil_kbd_interrupt
diff --git a/drivers/input/keyboard/hilkbd.c b/drivers/input/keyboard/hilkbd.c
index eecb77db0847..e95bc052e32a 100644
--- a/drivers/input/keyboard/hilkbd.c
+++ b/drivers/input/keyboard/hilkbd.c
@@ -22,7 +22,7 @@
22#include <linux/errno.h> 22#include <linux/errno.h>
23#include <linux/input.h> 23#include <linux/input.h>
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/irq.h> 25#include <linux/interrupt.h>
26#include <linux/hil.h> 26#include <linux/hil.h>
27#include <linux/spinlock.h> 27#include <linux/spinlock.h>
28 28
@@ -278,11 +278,11 @@ static int __init
278hil_init_chip(struct parisc_device *dev) 278hil_init_chip(struct parisc_device *dev)
279{ 279{
280 if (!dev->irq) { 280 if (!dev->irq) {
281 printk(KERN_WARNING "HIL: IRQ not found for HIL bus at 0x%08lx\n", dev->hpa); 281 printk(KERN_WARNING "HIL: IRQ not found for HIL bus at 0x%08lx\n", dev->hpa.start);
282 return -ENODEV; 282 return -ENODEV;
283 } 283 }
284 284
285 hil_base = dev->hpa; 285 hil_base = dev->hpa.start;
286 hil_irq = dev->irq; 286 hil_irq = dev->irq;
287 hil_dev.dev_id = dev; 287 hil_dev.dev_id = dev;
288 288
@@ -299,7 +299,7 @@ static struct parisc_device_id hil_tbl[] = {
299MODULE_DEVICE_TABLE(parisc, hil_tbl); 299MODULE_DEVICE_TABLE(parisc, hil_tbl);
300 300
301static struct parisc_driver hil_driver = { 301static struct parisc_driver hil_driver = {
302 .name = "HIL", 302 .name = "hil",
303 .id_table = hil_tbl, 303 .id_table = hil_tbl,
304 .probe = hil_init_chip, 304 .probe = hil_init_chip,
305}; 305};
diff --git a/drivers/input/keyboard/lkkbd.c b/drivers/input/keyboard/lkkbd.c
index 098963c7cdd6..7f06780a437f 100644
--- a/drivers/input/keyboard/lkkbd.c
+++ b/drivers/input/keyboard/lkkbd.c
@@ -102,7 +102,7 @@ static int ctrlclick_volume = 100; /* % */
102module_param (ctrlclick_volume, int, 0); 102module_param (ctrlclick_volume, int, 0);
103MODULE_PARM_DESC (ctrlclick_volume, "Ctrlclick volume (in %), default is 100%"); 103MODULE_PARM_DESC (ctrlclick_volume, "Ctrlclick volume (in %), default is 100%");
104 104
105static int lk201_compose_is_alt = 0; 105static int lk201_compose_is_alt;
106module_param (lk201_compose_is_alt, int, 0); 106module_param (lk201_compose_is_alt, int, 0);
107MODULE_PARM_DESC (lk201_compose_is_alt, "If set non-zero, LK201' Compose key " 107MODULE_PARM_DESC (lk201_compose_is_alt, "If set non-zero, LK201' Compose key "
108 "will act as an Alt key"); 108 "will act as an Alt key");
@@ -274,7 +274,7 @@ static lk_keycode_t lkkbd_keycode[LK_NUM_KEYCODES] = {
274}; 274};
275 275
276#define CHECK_LED(LED, BITS) do { \ 276#define CHECK_LED(LED, BITS) do { \
277 if (test_bit (LED, lk->dev.led)) \ 277 if (test_bit (LED, lk->dev->led)) \
278 leds_on |= BITS; \ 278 leds_on |= BITS; \
279 else \ 279 else \
280 leds_off |= BITS; \ 280 leds_off |= BITS; \
@@ -287,7 +287,7 @@ struct lkkbd {
287 lk_keycode_t keycode[LK_NUM_KEYCODES]; 287 lk_keycode_t keycode[LK_NUM_KEYCODES];
288 int ignore_bytes; 288 int ignore_bytes;
289 unsigned char id[LK_NUM_IGNORE_BYTES]; 289 unsigned char id[LK_NUM_IGNORE_BYTES];
290 struct input_dev dev; 290 struct input_dev *dev;
291 struct serio *serio; 291 struct serio *serio;
292 struct work_struct tq; 292 struct work_struct tq;
293 char name[64]; 293 char name[64];
@@ -423,8 +423,7 @@ lkkbd_interrupt (struct serio *serio, unsigned char data, unsigned int flags,
423 DBG (KERN_INFO "Got byte 0x%02x\n", data); 423 DBG (KERN_INFO "Got byte 0x%02x\n", data);
424 424
425 if (lk->ignore_bytes > 0) { 425 if (lk->ignore_bytes > 0) {
426 DBG (KERN_INFO "Ignoring a byte on %s\n", 426 DBG (KERN_INFO "Ignoring a byte on %s\n", lk->name);
427 lk->name);
428 lk->id[LK_NUM_IGNORE_BYTES - lk->ignore_bytes--] = data; 427 lk->id[LK_NUM_IGNORE_BYTES - lk->ignore_bytes--] = data;
429 428
430 if (lk->ignore_bytes == 0) 429 if (lk->ignore_bytes == 0)
@@ -435,14 +434,14 @@ lkkbd_interrupt (struct serio *serio, unsigned char data, unsigned int flags,
435 434
436 switch (data) { 435 switch (data) {
437 case LK_ALL_KEYS_UP: 436 case LK_ALL_KEYS_UP:
438 input_regs (&lk->dev, regs); 437 input_regs (lk->dev, regs);
439 for (i = 0; i < ARRAY_SIZE (lkkbd_keycode); i++) 438 for (i = 0; i < ARRAY_SIZE (lkkbd_keycode); i++)
440 if (lk->keycode[i] != KEY_RESERVED) 439 if (lk->keycode[i] != KEY_RESERVED)
441 input_report_key (&lk->dev, lk->keycode[i], 0); 440 input_report_key (lk->dev, lk->keycode[i], 0);
442 input_sync (&lk->dev); 441 input_sync (lk->dev);
443 break; 442 break;
444 case LK_METRONOME: 443 case LK_METRONOME:
445 DBG (KERN_INFO "Got LK_METRONOME and don't " 444 DBG (KERN_INFO "Got %#d and don't "
446 "know how to handle...\n"); 445 "know how to handle...\n");
447 break; 446 break;
448 case LK_OUTPUT_ERROR: 447 case LK_OUTPUT_ERROR:
@@ -482,12 +481,12 @@ lkkbd_interrupt (struct serio *serio, unsigned char data, unsigned int flags,
482 481
483 default: 482 default:
484 if (lk->keycode[data] != KEY_RESERVED) { 483 if (lk->keycode[data] != KEY_RESERVED) {
485 input_regs (&lk->dev, regs); 484 input_regs (lk->dev, regs);
486 if (!test_bit (lk->keycode[data], lk->dev.key)) 485 if (!test_bit (lk->keycode[data], lk->dev->key))
487 input_report_key (&lk->dev, lk->keycode[data], 1); 486 input_report_key (lk->dev, lk->keycode[data], 1);
488 else 487 else
489 input_report_key (&lk->dev, lk->keycode[data], 0); 488 input_report_key (lk->dev, lk->keycode[data], 0);
490 input_sync (&lk->dev); 489 input_sync (lk->dev);
491 } else 490 } else
492 printk (KERN_WARNING "%s: Unknown key with " 491 printk (KERN_WARNING "%s: Unknown key with "
493 "scancode 0x%02x on %s.\n", 492 "scancode 0x%02x on %s.\n",
@@ -605,7 +604,7 @@ lkkbd_reinit (void *data)
605 lk->serio->write (lk->serio, volume_to_hw (lk->bell_volume)); 604 lk->serio->write (lk->serio, volume_to_hw (lk->bell_volume));
606 605
607 /* Enable/disable keyclick (and possibly set volume) */ 606 /* Enable/disable keyclick (and possibly set volume) */
608 if (test_bit (SND_CLICK, lk->dev.snd)) { 607 if (test_bit (SND_CLICK, lk->dev->snd)) {
609 lk->serio->write (lk->serio, LK_CMD_ENABLE_KEYCLICK); 608 lk->serio->write (lk->serio, LK_CMD_ENABLE_KEYCLICK);
610 lk->serio->write (lk->serio, volume_to_hw (lk->keyclick_volume)); 609 lk->serio->write (lk->serio, volume_to_hw (lk->keyclick_volume));
611 lk->serio->write (lk->serio, LK_CMD_ENABLE_CTRCLICK); 610 lk->serio->write (lk->serio, LK_CMD_ENABLE_CTRCLICK);
@@ -616,7 +615,7 @@ lkkbd_reinit (void *data)
616 } 615 }
617 616
618 /* Sound the bell if needed */ 617 /* Sound the bell if needed */
619 if (test_bit (SND_BELL, lk->dev.snd)) 618 if (test_bit (SND_BELL, lk->dev->snd))
620 lk->serio->write (lk->serio, LK_CMD_SOUND_BELL); 619 lk->serio->write (lk->serio, LK_CMD_SOUND_BELL);
621} 620}
622 621
@@ -627,71 +626,70 @@ static int
627lkkbd_connect (struct serio *serio, struct serio_driver *drv) 626lkkbd_connect (struct serio *serio, struct serio_driver *drv)
628{ 627{
629 struct lkkbd *lk; 628 struct lkkbd *lk;
629 struct input_dev *input_dev;
630 int i; 630 int i;
631 int err; 631 int err;
632 632
633 if (!(lk = kmalloc (sizeof (struct lkkbd), GFP_KERNEL))) 633 lk = kzalloc (sizeof (struct lkkbd), GFP_KERNEL);
634 return -ENOMEM; 634 input_dev = input_allocate_device ();
635 635 if (!lk || !input_dev) {
636 memset (lk, 0, sizeof (struct lkkbd)); 636 err = -ENOMEM;
637 637 goto fail;
638 init_input_dev (&lk->dev); 638 }
639 set_bit (EV_KEY, lk->dev.evbit);
640 set_bit (EV_LED, lk->dev.evbit);
641 set_bit (EV_SND, lk->dev.evbit);
642 set_bit (EV_REP, lk->dev.evbit);
643 set_bit (LED_CAPSL, lk->dev.ledbit);
644 set_bit (LED_SLEEP, lk->dev.ledbit);
645 set_bit (LED_COMPOSE, lk->dev.ledbit);
646 set_bit (LED_SCROLLL, lk->dev.ledbit);
647 set_bit (SND_BELL, lk->dev.sndbit);
648 set_bit (SND_CLICK, lk->dev.sndbit);
649 639
650 lk->serio = serio; 640 lk->serio = serio;
651 641 lk->dev = input_dev;
652 INIT_WORK (&lk->tq, lkkbd_reinit, lk); 642 INIT_WORK (&lk->tq, lkkbd_reinit, lk);
653
654 lk->bell_volume = bell_volume; 643 lk->bell_volume = bell_volume;
655 lk->keyclick_volume = keyclick_volume; 644 lk->keyclick_volume = keyclick_volume;
656 lk->ctrlclick_volume = ctrlclick_volume; 645 lk->ctrlclick_volume = ctrlclick_volume;
646 memcpy (lk->keycode, lkkbd_keycode, sizeof (lk_keycode_t) * LK_NUM_KEYCODES);
657 647
658 lk->dev.keycode = lk->keycode; 648 strlcpy (lk->name, "DEC LK keyboard", sizeof(lk->name));
659 lk->dev.keycodesize = sizeof (lk_keycode_t); 649 snprintf (lk->phys, sizeof(lk->phys), "%s/input0", serio->phys);
660 lk->dev.keycodemax = LK_NUM_KEYCODES; 650
661 651 input_dev->name = lk->name;
662 lk->dev.event = lkkbd_event; 652 input_dev->phys = lk->phys;
663 lk->dev.private = lk; 653 input_dev->id.bustype = BUS_RS232;
654 input_dev->id.vendor = SERIO_LKKBD;
655 input_dev->id.product = 0;
656 input_dev->id.version = 0x0100;
657 input_dev->cdev.dev = &serio->dev;
658 input_dev->event = lkkbd_event;
659 input_dev->private = lk;
660
661 set_bit (EV_KEY, input_dev->evbit);
662 set_bit (EV_LED, input_dev->evbit);
663 set_bit (EV_SND, input_dev->evbit);
664 set_bit (EV_REP, input_dev->evbit);
665 set_bit (LED_CAPSL, input_dev->ledbit);
666 set_bit (LED_SLEEP, input_dev->ledbit);
667 set_bit (LED_COMPOSE, input_dev->ledbit);
668 set_bit (LED_SCROLLL, input_dev->ledbit);
669 set_bit (SND_BELL, input_dev->sndbit);
670 set_bit (SND_CLICK, input_dev->sndbit);
671
672 input_dev->keycode = lk->keycode;
673 input_dev->keycodesize = sizeof (lk_keycode_t);
674 input_dev->keycodemax = LK_NUM_KEYCODES;
675 for (i = 0; i < LK_NUM_KEYCODES; i++)
676 set_bit (lk->keycode[i], input_dev->keybit);
664 677
665 serio_set_drvdata (serio, lk); 678 serio_set_drvdata (serio, lk);
666 679
667 err = serio_open (serio, drv); 680 err = serio_open (serio, drv);
668 if (err) { 681 if (err)
669 serio_set_drvdata (serio, NULL); 682 goto fail;
670 kfree (lk);
671 return err;
672 }
673 683
674 sprintf (lk->name, "DEC LK keyboard"); 684 input_register_device (lk->dev);
675 sprintf (lk->phys, "%s/input0", serio->phys);
676
677 memcpy (lk->keycode, lkkbd_keycode, sizeof (lk_keycode_t) * LK_NUM_KEYCODES);
678 for (i = 0; i < LK_NUM_KEYCODES; i++)
679 set_bit (lk->keycode[i], lk->dev.keybit);
680
681 lk->dev.name = lk->name;
682 lk->dev.phys = lk->phys;
683 lk->dev.id.bustype = BUS_RS232;
684 lk->dev.id.vendor = SERIO_LKKBD;
685 lk->dev.id.product = 0;
686 lk->dev.id.version = 0x0100;
687 lk->dev.dev = &serio->dev;
688
689 input_register_device (&lk->dev);
690
691 printk (KERN_INFO "input: %s on %s, initiating reset\n", lk->name, serio->phys);
692 lk->serio->write (lk->serio, LK_CMD_POWERCYCLE_RESET); 685 lk->serio->write (lk->serio, LK_CMD_POWERCYCLE_RESET);
693 686
694 return 0; 687 return 0;
688
689 fail: serio_set_drvdata (serio, NULL);
690 input_free_device (input_dev);
691 kfree (lk);
692 return err;
695} 693}
696 694
697/* 695/*
@@ -702,9 +700,11 @@ lkkbd_disconnect (struct serio *serio)
702{ 700{
703 struct lkkbd *lk = serio_get_drvdata (serio); 701 struct lkkbd *lk = serio_get_drvdata (serio);
704 702
705 input_unregister_device (&lk->dev); 703 input_get_device (lk->dev);
704 input_unregister_device (lk->dev);
706 serio_close (serio); 705 serio_close (serio);
707 serio_set_drvdata (serio, NULL); 706 serio_set_drvdata (serio, NULL);
707 input_put_device (lk->dev);
708 kfree (lk); 708 kfree (lk);
709} 709}
710 710
diff --git a/drivers/input/keyboard/maple_keyb.c b/drivers/input/keyboard/maple_keyb.c
index eecbde294f1f..cc6aaf9e85be 100644
--- a/drivers/input/keyboard/maple_keyb.c
+++ b/drivers/input/keyboard/maple_keyb.c
@@ -37,7 +37,7 @@ static unsigned char dc_kbd_keycode[256] = {
37 37
38 38
39struct dc_kbd { 39struct dc_kbd {
40 struct input_dev dev; 40 struct input_dev *dev;
41 unsigned char new[8]; 41 unsigned char new[8];
42 unsigned char old[8]; 42 unsigned char old[8];
43}; 43};
@@ -46,30 +46,24 @@ struct dc_kbd {
46static void dc_scan_kbd(struct dc_kbd *kbd) 46static void dc_scan_kbd(struct dc_kbd *kbd)
47{ 47{
48 int i; 48 int i;
49 struct input_dev *dev = &kbd->dev; 49 struct input_dev *dev = kbd->dev;
50 50
51 for(i=0; i<8; i++) 51 for (i = 0; i < 8; i++)
52 input_report_key(dev, 52 input_report_key(dev, dc_kbd_keycode[i + 224], (kbd->new[0] >> i) & 1);
53 dc_kbd_keycode[i+224],
54 (kbd->new[0]>>i)&1);
55 53
56 for(i=2; i<8; i++) { 54 for (i = 2; i < 8; i++) {
57 55
58 if(kbd->old[i]>3&&memscan(kbd->new+2, kbd->old[i], 6)==NULL) { 56 if (kbd->old[i] > 3 && memscan(kbd->new + 2, kbd->old[i], 6) == NULL) {
59 if(dc_kbd_keycode[kbd->old[i]]) 57 if (dc_kbd_keycode[kbd->old[i]])
60 input_report_key(dev, 58 input_report_key(dev, dc_kbd_keycode[kbd->old[i]], 0);
61 dc_kbd_keycode[kbd->old[i]],
62 0);
63 else 59 else
64 printk("Unknown key (scancode %#x) released.", 60 printk("Unknown key (scancode %#x) released.",
65 kbd->old[i]); 61 kbd->old[i]);
66 } 62 }
67 63
68 if(kbd->new[i]>3&&memscan(kbd->old+2, kbd->new[i], 6)!=NULL) { 64 if (kbd->new[i] > 3 && memscan(kbd->old + 2, kbd->new[i], 6) != NULL) {
69 if(dc_kbd_keycode[kbd->new[i]]) 65 if(dc_kbd_keycode[kbd->new[i]])
70 input_report_key(dev, 66 input_report_key(dev, dc_kbd_keycode[kbd->new[i]], 1);
71 dc_kbd_keycode[kbd->new[i]],
72 1);
73 else 67 else
74 printk("Unknown key (scancode %#x) pressed.", 68 printk("Unknown key (scancode %#x) pressed.",
75 kbd->new[i]); 69 kbd->new[i]);
@@ -89,43 +83,39 @@ static void dc_kbd_callback(struct mapleq *mq)
89 unsigned long *buf = mq->recvbuf; 83 unsigned long *buf = mq->recvbuf;
90 84
91 if (buf[1] == mapledev->function) { 85 if (buf[1] == mapledev->function) {
92 memcpy(kbd->new, buf+2, 8); 86 memcpy(kbd->new, buf + 2, 8);
93 dc_scan_kbd(kbd); 87 dc_scan_kbd(kbd);
94 } 88 }
95} 89}
96 90
97static int dc_kbd_connect(struct maple_device *dev) 91static int dc_kbd_connect(struct maple_device *dev)
98{ 92{
99 int i;
100 unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]);
101 struct dc_kbd *kbd; 93 struct dc_kbd *kbd;
94 struct input_dev *input_dev;
95 unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]);
96 int i;
102 97
103 if (!(kbd = kmalloc(sizeof(struct dc_kbd), GFP_KERNEL))) 98 dev->private_data = kbd = kzalloc(sizeof(struct dc_kbd), GFP_KERNEL);
104 return -1; 99 input_dev = input_allocate_device();
105 memset(kbd, 0, sizeof(struct dc_kbd)); 100 if (!kbd || !input_dev) {
106 101 kfree(kbd);
107 dev->private_data = kbd; 102 input_free_device(input_dev);
108 103 return -ENOMEM;
109 kbd->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP); 104 }
110
111 init_input_dev(&kbd->dev);
112
113 for (i=0; i<255; i++)
114 set_bit(dc_kbd_keycode[i], kbd->dev.keybit);
115
116 clear_bit(0, kbd->dev.keybit);
117 105
118 kbd->dev.private = kbd; 106 kbd->dev = input_dev;
119 107
120 kbd->dev.name = dev->product_name; 108 input_dev->name = dev->product_name;
121 kbd->dev.id.bustype = BUS_MAPLE; 109 input_dev->id.bustype = BUS_MAPLE;
110 input_dev->private = kbd;
111 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
112 for (i = 0; i < 255; i++)
113 set_bit(dc_kbd_keycode[i], input_dev->keybit);
114 clear_bit(0, input_dev->keybit);
122 115
123 input_register_device(&kbd->dev); 116 input_register_device(kbd->dev);
124 117
125 maple_getcond_callback(dev, dc_kbd_callback, 1, MAPLE_FUNC_KEYBOARD); 118 maple_getcond_callback(dev, dc_kbd_callback, 1, MAPLE_FUNC_KEYBOARD);
126
127 printk(KERN_INFO "input: keyboard(0x%lx): %s\n", data, kbd->dev.name);
128
129 return 0; 119 return 0;
130} 120}
131 121
@@ -134,7 +124,7 @@ static void dc_kbd_disconnect(struct maple_device *dev)
134{ 124{
135 struct dc_kbd *kbd = dev->private_data; 125 struct dc_kbd *kbd = dev->private_data;
136 126
137 input_unregister_device(&kbd->dev); 127 input_unregister_device(kbd->dev);
138 kfree(kbd); 128 kfree(kbd);
139} 129}
140 130
diff --git a/drivers/input/keyboard/newtonkbd.c b/drivers/input/keyboard/newtonkbd.c
index 2e8ce1613eec..d10983c521e6 100644
--- a/drivers/input/keyboard/newtonkbd.c
+++ b/drivers/input/keyboard/newtonkbd.c
@@ -57,11 +57,9 @@ static unsigned char nkbd_keycode[128] = {
57 KEY_LEFT, KEY_RIGHT, KEY_DOWN, KEY_UP, 0 57 KEY_LEFT, KEY_RIGHT, KEY_DOWN, KEY_UP, 0
58}; 58};
59 59
60static char *nkbd_name = "Newton Keyboard";
61
62struct nkbd { 60struct nkbd {
63 unsigned char keycode[128]; 61 unsigned char keycode[128];
64 struct input_dev dev; 62 struct input_dev *dev;
65 struct serio *serio; 63 struct serio *serio;
66 char phys[32]; 64 char phys[32];
67}; 65};
@@ -73,13 +71,13 @@ static irqreturn_t nkbd_interrupt(struct serio *serio,
73 71
74 /* invalid scan codes are probably the init sequence, so we ignore them */ 72 /* invalid scan codes are probably the init sequence, so we ignore them */
75 if (nkbd->keycode[data & NKBD_KEY]) { 73 if (nkbd->keycode[data & NKBD_KEY]) {
76 input_regs(&nkbd->dev, regs); 74 input_regs(nkbd->dev, regs);
77 input_report_key(&nkbd->dev, nkbd->keycode[data & NKBD_KEY], data & NKBD_PRESS); 75 input_report_key(nkbd->dev, nkbd->keycode[data & NKBD_KEY], data & NKBD_PRESS);
78 input_sync(&nkbd->dev); 76 input_sync(nkbd->dev);
79 } 77 }
80 78
81 else if (data == 0xe7) /* end of init sequence */ 79 else if (data == 0xe7) /* end of init sequence */
82 printk(KERN_INFO "input: %s on %s\n", nkbd_name, serio->phys); 80 printk(KERN_INFO "input: %s on %s\n", nkbd->dev->name, serio->phys);
83 return IRQ_HANDLED; 81 return IRQ_HANDLED;
84 82
85} 83}
@@ -87,62 +85,59 @@ static irqreturn_t nkbd_interrupt(struct serio *serio,
87static int nkbd_connect(struct serio *serio, struct serio_driver *drv) 85static int nkbd_connect(struct serio *serio, struct serio_driver *drv)
88{ 86{
89 struct nkbd *nkbd; 87 struct nkbd *nkbd;
88 struct input_dev *input_dev;
89 int err = -ENOMEM;
90 int i; 90 int i;
91 int err;
92
93 if (!(nkbd = kmalloc(sizeof(struct nkbd), GFP_KERNEL)))
94 return -ENOMEM;
95
96 memset(nkbd, 0, sizeof(struct nkbd));
97 91
98 nkbd->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP); 92 nkbd = kzalloc(sizeof(struct nkbd), GFP_KERNEL);
93 input_dev = input_allocate_device();
94 if (!nkbd || !input_dev)
95 goto fail;
99 96
100 nkbd->serio = serio; 97 nkbd->serio = serio;
98 nkbd->dev = input_dev;
99 sprintf(nkbd->phys, "%s/input0", serio->phys);
100 memcpy(nkbd->keycode, nkbd_keycode, sizeof(nkbd->keycode));
101 101
102 init_input_dev(&nkbd->dev); 102 input_dev->name = "Newton Keyboard";
103 nkbd->dev.keycode = nkbd->keycode; 103 input_dev->phys = nkbd->phys;
104 nkbd->dev.keycodesize = sizeof(unsigned char); 104 input_dev->id.bustype = BUS_RS232;
105 nkbd->dev.keycodemax = ARRAY_SIZE(nkbd_keycode); 105 input_dev->id.vendor = SERIO_NEWTON;
106 nkbd->dev.private = nkbd; 106 input_dev->id.product = 0x0001;
107 input_dev->id.version = 0x0100;
108 input_dev->cdev.dev = &serio->dev;
109 input_dev->private = nkbd;
110
111 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
112 input_dev->keycode = nkbd->keycode;
113 input_dev->keycodesize = sizeof(unsigned char);
114 input_dev->keycodemax = ARRAY_SIZE(nkbd_keycode);
115 for (i = 0; i < 128; i++)
116 set_bit(nkbd->keycode[i], input_dev->keybit);
117 clear_bit(0, input_dev->keybit);
107 118
108 serio_set_drvdata(serio, nkbd); 119 serio_set_drvdata(serio, nkbd);
109 120
110 err = serio_open(serio, drv); 121 err = serio_open(serio, drv);
111 if (err) { 122 if (err)
112 serio_set_drvdata(serio, NULL); 123 goto fail;
113 kfree(nkbd);
114 return err;
115 }
116
117 memcpy(nkbd->keycode, nkbd_keycode, sizeof(nkbd->keycode));
118 for (i = 0; i < 128; i++)
119 set_bit(nkbd->keycode[i], nkbd->dev.keybit);
120 clear_bit(0, nkbd->dev.keybit);
121
122 sprintf(nkbd->phys, "%s/input0", serio->phys);
123
124 nkbd->dev.name = nkbd_name;
125 nkbd->dev.phys = nkbd->phys;
126 nkbd->dev.id.bustype = BUS_RS232;
127 nkbd->dev.id.vendor = SERIO_NEWTON;
128 nkbd->dev.id.product = 0x0001;
129 nkbd->dev.id.version = 0x0100;
130 nkbd->dev.dev = &serio->dev;
131
132 input_register_device(&nkbd->dev);
133
134 printk(KERN_INFO "input: %s on %s\n", nkbd_name, serio->phys);
135 124
125 input_register_device(nkbd->dev);
136 return 0; 126 return 0;
127
128 fail: serio_set_drvdata(serio, NULL);
129 input_free_device(input_dev);
130 kfree(nkbd);
131 return err;
137} 132}
138 133
139static void nkbd_disconnect(struct serio *serio) 134static void nkbd_disconnect(struct serio *serio)
140{ 135{
141 struct nkbd *nkbd = serio_get_drvdata(serio); 136 struct nkbd *nkbd = serio_get_drvdata(serio);
142 137
143 input_unregister_device(&nkbd->dev);
144 serio_close(serio); 138 serio_close(serio);
145 serio_set_drvdata(serio, NULL); 139 serio_set_drvdata(serio, NULL);
140 input_unregister_device(nkbd->dev);
146 kfree(nkbd); 141 kfree(nkbd);
147} 142}
148 143
diff --git a/drivers/input/keyboard/spitzkbd.c b/drivers/input/keyboard/spitzkbd.c
index 344f46005401..cee9c734a048 100644
--- a/drivers/input/keyboard/spitzkbd.c
+++ b/drivers/input/keyboard/spitzkbd.c
@@ -85,7 +85,7 @@ static int spitz_senses[] = {
85 85
86struct spitzkbd { 86struct spitzkbd {
87 unsigned char keycode[ARRAY_SIZE(spitzkbd_keycode)]; 87 unsigned char keycode[ARRAY_SIZE(spitzkbd_keycode)];
88 struct input_dev input; 88 struct input_dev *input;
89 char phys[32]; 89 char phys[32];
90 90
91 spinlock_t lock; 91 spinlock_t lock;
@@ -187,8 +187,7 @@ static void spitzkbd_scankeyboard(struct spitzkbd *spitzkbd_data, struct pt_regs
187 187
188 spin_lock_irqsave(&spitzkbd_data->lock, flags); 188 spin_lock_irqsave(&spitzkbd_data->lock, flags);
189 189
190 if (regs) 190 input_regs(spitzkbd_data->input, regs);
191 input_regs(&spitzkbd_data->input, regs);
192 191
193 num_pressed = 0; 192 num_pressed = 0;
194 for (col = 0; col < KB_COLS; col++) { 193 for (col = 0; col < KB_COLS; col++) {
@@ -210,7 +209,7 @@ static void spitzkbd_scankeyboard(struct spitzkbd *spitzkbd_data, struct pt_regs
210 scancode = SCANCODE(row, col); 209 scancode = SCANCODE(row, col);
211 pressed = rowd & KB_ROWMASK(row); 210 pressed = rowd & KB_ROWMASK(row);
212 211
213 input_report_key(&spitzkbd_data->input, spitzkbd_data->keycode[scancode], pressed); 212 input_report_key(spitzkbd_data->input, spitzkbd_data->keycode[scancode], pressed);
214 213
215 if (pressed) 214 if (pressed)
216 num_pressed++; 215 num_pressed++;
@@ -220,15 +219,15 @@ static void spitzkbd_scankeyboard(struct spitzkbd *spitzkbd_data, struct pt_regs
220 219
221 spitzkbd_activate_all(); 220 spitzkbd_activate_all();
222 221
223 input_report_key(&spitzkbd_data->input, SPITZ_KEY_SYNC, (GPLR(SPITZ_GPIO_SYNC) & GPIO_bit(SPITZ_GPIO_SYNC)) != 0 ); 222 input_report_key(spitzkbd_data->input, SPITZ_KEY_SYNC, (GPLR(SPITZ_GPIO_SYNC) & GPIO_bit(SPITZ_GPIO_SYNC)) != 0 );
224 input_report_key(&spitzkbd_data->input, KEY_SUSPEND, pwrkey); 223 input_report_key(spitzkbd_data->input, KEY_SUSPEND, pwrkey);
225 224
226 if (pwrkey && time_after(jiffies, spitzkbd_data->suspend_jiffies + msecs_to_jiffies(1000))) { 225 if (pwrkey && time_after(jiffies, spitzkbd_data->suspend_jiffies + msecs_to_jiffies(1000))) {
227 input_event(&spitzkbd_data->input, EV_PWR, KEY_SUSPEND, 1); 226 input_event(spitzkbd_data->input, EV_PWR, KEY_SUSPEND, 1);
228 spitzkbd_data->suspend_jiffies = jiffies; 227 spitzkbd_data->suspend_jiffies = jiffies;
229 } 228 }
230 229
231 input_sync(&spitzkbd_data->input); 230 input_sync(spitzkbd_data->input);
232 231
233 /* if any keys are pressed, enable the timer */ 232 /* if any keys are pressed, enable the timer */
234 if (num_pressed) 233 if (num_pressed)
@@ -259,6 +258,7 @@ static irqreturn_t spitzkbd_interrupt(int irq, void *dev_id, struct pt_regs *reg
259static void spitzkbd_timer_callback(unsigned long data) 258static void spitzkbd_timer_callback(unsigned long data)
260{ 259{
261 struct spitzkbd *spitzkbd_data = (struct spitzkbd *) data; 260 struct spitzkbd *spitzkbd_data = (struct spitzkbd *) data;
261
262 spitzkbd_scankeyboard(spitzkbd_data, NULL); 262 spitzkbd_scankeyboard(spitzkbd_data, NULL);
263} 263}
264 264
@@ -298,9 +298,9 @@ static void spitzkbd_hinge_timer(unsigned long data)
298 if (hinge_count >= HINGE_STABLE_COUNT) { 298 if (hinge_count >= HINGE_STABLE_COUNT) {
299 spin_lock_irqsave(&spitzkbd_data->lock, flags); 299 spin_lock_irqsave(&spitzkbd_data->lock, flags);
300 300
301 input_report_switch(&spitzkbd_data->input, SW_0, ((GPLR(SPITZ_GPIO_SWA) & GPIO_bit(SPITZ_GPIO_SWA)) != 0)); 301 input_report_switch(spitzkbd_data->input, SW_0, ((GPLR(SPITZ_GPIO_SWA) & GPIO_bit(SPITZ_GPIO_SWA)) != 0));
302 input_report_switch(&spitzkbd_data->input, SW_1, ((GPLR(SPITZ_GPIO_SWB) & GPIO_bit(SPITZ_GPIO_SWB)) != 0)); 302 input_report_switch(spitzkbd_data->input, SW_1, ((GPLR(SPITZ_GPIO_SWB) & GPIO_bit(SPITZ_GPIO_SWB)) != 0));
303 input_sync(&spitzkbd_data->input); 303 input_sync(spitzkbd_data->input);
304 304
305 spin_unlock_irqrestore(&spitzkbd_data->lock, flags); 305 spin_unlock_irqrestore(&spitzkbd_data->lock, flags);
306 } else { 306 } else {
@@ -309,34 +309,32 @@ static void spitzkbd_hinge_timer(unsigned long data)
309} 309}
310 310
311#ifdef CONFIG_PM 311#ifdef CONFIG_PM
312static int spitzkbd_suspend(struct device *dev, pm_message_t state, uint32_t level) 312static int spitzkbd_suspend(struct device *dev, pm_message_t state)
313{ 313{
314 if (level == SUSPEND_POWER_DOWN) { 314 int i;
315 int i; 315 struct spitzkbd *spitzkbd = dev_get_drvdata(dev);
316 struct spitzkbd *spitzkbd = dev_get_drvdata(dev); 316 spitzkbd->suspended = 1;
317 spitzkbd->suspended = 1; 317
318 318 /* Set Strobe lines as inputs - *except* strobe line 0 leave this
319 /* Set Strobe lines as inputs - *except* strobe line 0 leave this 319 enabled so we can detect a power button press for resume */
320 enabled so we can detect a power button press for resume */ 320 for (i = 1; i < SPITZ_KEY_STROBE_NUM; i++)
321 for (i = 1; i < SPITZ_KEY_STROBE_NUM; i++) 321 pxa_gpio_mode(spitz_strobes[i] | GPIO_IN);
322 pxa_gpio_mode(spitz_strobes[i] | GPIO_IN); 322
323 }
324 return 0; 323 return 0;
325} 324}
326 325
327static int spitzkbd_resume(struct device *dev, uint32_t level) 326static int spitzkbd_resume(struct device *dev)
328{ 327{
329 if (level == RESUME_POWER_ON) { 328 int i;
330 int i; 329 struct spitzkbd *spitzkbd = dev_get_drvdata(dev);
331 struct spitzkbd *spitzkbd = dev_get_drvdata(dev);
332 330
333 for (i = 0; i < SPITZ_KEY_STROBE_NUM; i++) 331 for (i = 0; i < SPITZ_KEY_STROBE_NUM; i++)
334 pxa_gpio_mode(spitz_strobes[i] | GPIO_OUT | GPIO_DFLT_HIGH); 332 pxa_gpio_mode(spitz_strobes[i] | GPIO_OUT | GPIO_DFLT_HIGH);
333
334 /* Upon resume, ignore the suspend key for a short while */
335 spitzkbd->suspend_jiffies = jiffies;
336 spitzkbd->suspended = 0;
335 337
336 /* Upon resume, ignore the suspend key for a short while */
337 spitzkbd->suspend_jiffies = jiffies;
338 spitzkbd->suspended = 0;
339 }
340 return 0; 338 return 0;
341} 339}
342#else 340#else
@@ -346,14 +344,21 @@ static int spitzkbd_resume(struct device *dev, uint32_t level)
346 344
347static int __init spitzkbd_probe(struct device *dev) 345static int __init spitzkbd_probe(struct device *dev)
348{ 346{
349 int i;
350 struct spitzkbd *spitzkbd; 347 struct spitzkbd *spitzkbd;
348 struct input_dev *input_dev;
349 int i;
351 350
352 spitzkbd = kzalloc(sizeof(struct spitzkbd), GFP_KERNEL); 351 spitzkbd = kzalloc(sizeof(struct spitzkbd), GFP_KERNEL);
353 if (!spitzkbd) 352 if (!spitzkbd)
354 return -ENOMEM; 353 return -ENOMEM;
355 354
356 dev_set_drvdata(dev,spitzkbd); 355 input_dev = input_allocate_device();
356 if (!input_dev) {
357 kfree(spitzkbd);
358 return -ENOMEM;
359 }
360
361 dev_set_drvdata(dev, spitzkbd);
357 strcpy(spitzkbd->phys, "spitzkbd/input0"); 362 strcpy(spitzkbd->phys, "spitzkbd/input0");
358 363
359 spin_lock_init(&spitzkbd->lock); 364 spin_lock_init(&spitzkbd->lock);
@@ -368,30 +373,34 @@ static int __init spitzkbd_probe(struct device *dev)
368 spitzkbd->htimer.function = spitzkbd_hinge_timer; 373 spitzkbd->htimer.function = spitzkbd_hinge_timer;
369 spitzkbd->htimer.data = (unsigned long) spitzkbd; 374 spitzkbd->htimer.data = (unsigned long) spitzkbd;
370 375
371 spitzkbd->suspend_jiffies=jiffies; 376 spitzkbd->suspend_jiffies = jiffies;
372 377
373 init_input_dev(&spitzkbd->input); 378 spitzkbd->input = input_dev;
374 spitzkbd->input.private = spitzkbd; 379
375 spitzkbd->input.name = "Spitz Keyboard"; 380 input_dev->private = spitzkbd;
376 spitzkbd->input.dev = dev; 381 input_dev->name = "Spitz Keyboard";
377 spitzkbd->input.phys = spitzkbd->phys; 382 input_dev->phys = spitzkbd->phys;
378 spitzkbd->input.id.bustype = BUS_HOST; 383 input_dev->cdev.dev = dev;
379 spitzkbd->input.id.vendor = 0x0001; 384
380 spitzkbd->input.id.product = 0x0001; 385 input_dev->id.bustype = BUS_HOST;
381 spitzkbd->input.id.version = 0x0100; 386 input_dev->id.vendor = 0x0001;
382 spitzkbd->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_PWR) | BIT(EV_SW); 387 input_dev->id.product = 0x0001;
383 spitzkbd->input.keycode = spitzkbd->keycode; 388 input_dev->id.version = 0x0100;
384 spitzkbd->input.keycodesize = sizeof(unsigned char); 389
385 spitzkbd->input.keycodemax = ARRAY_SIZE(spitzkbd_keycode); 390 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_PWR) | BIT(EV_SW);
391 input_dev->keycode = spitzkbd->keycode;
392 input_dev->keycodesize = sizeof(unsigned char);
393 input_dev->keycodemax = ARRAY_SIZE(spitzkbd_keycode);
386 394
387 memcpy(spitzkbd->keycode, spitzkbd_keycode, sizeof(spitzkbd->keycode)); 395 memcpy(spitzkbd->keycode, spitzkbd_keycode, sizeof(spitzkbd->keycode));
388 for (i = 0; i < ARRAY_SIZE(spitzkbd_keycode); i++) 396 for (i = 0; i < ARRAY_SIZE(spitzkbd_keycode); i++)
389 set_bit(spitzkbd->keycode[i], spitzkbd->input.keybit); 397 set_bit(spitzkbd->keycode[i], input_dev->keybit);
390 clear_bit(0, spitzkbd->input.keybit); 398 clear_bit(0, input_dev->keybit);
391 set_bit(SW_0, spitzkbd->input.swbit); 399 set_bit(SW_0, input_dev->swbit);
392 set_bit(SW_1, spitzkbd->input.swbit); 400 set_bit(SW_1, input_dev->swbit);
401
402 input_register_device(input_dev);
393 403
394 input_register_device(&spitzkbd->input);
395 mod_timer(&spitzkbd->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL)); 404 mod_timer(&spitzkbd->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL));
396 405
397 /* Setup sense interrupts - RisingEdge Detect, sense lines as inputs */ 406 /* Setup sense interrupts - RisingEdge Detect, sense lines as inputs */
@@ -444,7 +453,7 @@ static int spitzkbd_remove(struct device *dev)
444 del_timer_sync(&spitzkbd->htimer); 453 del_timer_sync(&spitzkbd->htimer);
445 del_timer_sync(&spitzkbd->timer); 454 del_timer_sync(&spitzkbd->timer);
446 455
447 input_unregister_device(&spitzkbd->input); 456 input_unregister_device(spitzkbd->input);
448 457
449 kfree(spitzkbd); 458 kfree(spitzkbd);
450 459
diff --git a/drivers/input/keyboard/sunkbd.c b/drivers/input/keyboard/sunkbd.c
index 4bae5d89348d..b15b6d8d4f83 100644
--- a/drivers/input/keyboard/sunkbd.c
+++ b/drivers/input/keyboard/sunkbd.c
@@ -76,13 +76,14 @@ static unsigned char sunkbd_keycode[128] = {
76 76
77struct sunkbd { 77struct sunkbd {
78 unsigned char keycode[128]; 78 unsigned char keycode[128];
79 struct input_dev dev; 79 struct input_dev *dev;
80 struct serio *serio; 80 struct serio *serio;
81 struct work_struct tq; 81 struct work_struct tq;
82 wait_queue_head_t wait; 82 wait_queue_head_t wait;
83 char name[64]; 83 char name[64];
84 char phys[32]; 84 char phys[32];
85 char type; 85 char type;
86 unsigned char enabled;
86 volatile s8 reset; 87 volatile s8 reset;
87 volatile s8 layout; 88 volatile s8 layout;
88}; 89};
@@ -124,10 +125,13 @@ static irqreturn_t sunkbd_interrupt(struct serio *serio,
124 break; 125 break;
125 126
126 default: 127 default:
128 if (!sunkbd->enabled)
129 break;
130
127 if (sunkbd->keycode[data & SUNKBD_KEY]) { 131 if (sunkbd->keycode[data & SUNKBD_KEY]) {
128 input_regs(&sunkbd->dev, regs); 132 input_regs(sunkbd->dev, regs);
129 input_report_key(&sunkbd->dev, sunkbd->keycode[data & SUNKBD_KEY], !(data & SUNKBD_RELEASE)); 133 input_report_key(sunkbd->dev, sunkbd->keycode[data & SUNKBD_KEY], !(data & SUNKBD_RELEASE));
130 input_sync(&sunkbd->dev); 134 input_sync(sunkbd->dev);
131 } else { 135 } else {
132 printk(KERN_WARNING "sunkbd.c: Unknown key (scancode %#x) %s.\n", 136 printk(KERN_WARNING "sunkbd.c: Unknown key (scancode %#x) %s.\n",
133 data & SUNKBD_KEY, data & SUNKBD_RELEASE ? "released" : "pressed"); 137 data & SUNKBD_KEY, data & SUNKBD_RELEASE ? "released" : "pressed");
@@ -184,7 +188,7 @@ static int sunkbd_initialize(struct sunkbd *sunkbd)
184 sunkbd->reset = -2; 188 sunkbd->reset = -2;
185 sunkbd->serio->write(sunkbd->serio, SUNKBD_CMD_RESET); 189 sunkbd->serio->write(sunkbd->serio, SUNKBD_CMD_RESET);
186 wait_event_interruptible_timeout(sunkbd->wait, sunkbd->reset >= 0, HZ); 190 wait_event_interruptible_timeout(sunkbd->wait, sunkbd->reset >= 0, HZ);
187 if (sunkbd->reset <0) 191 if (sunkbd->reset < 0)
188 return -1; 192 return -1;
189 193
190 sunkbd->type = sunkbd->reset; 194 sunkbd->type = sunkbd->reset;
@@ -213,10 +217,17 @@ static void sunkbd_reinit(void *data)
213 217
214 sunkbd->serio->write(sunkbd->serio, SUNKBD_CMD_SETLED); 218 sunkbd->serio->write(sunkbd->serio, SUNKBD_CMD_SETLED);
215 sunkbd->serio->write(sunkbd->serio, 219 sunkbd->serio->write(sunkbd->serio,
216 (!!test_bit(LED_CAPSL, sunkbd->dev.led) << 3) | (!!test_bit(LED_SCROLLL, sunkbd->dev.led) << 2) | 220 (!!test_bit(LED_CAPSL, sunkbd->dev->led) << 3) | (!!test_bit(LED_SCROLLL, sunkbd->dev->led) << 2) |
217 (!!test_bit(LED_COMPOSE, sunkbd->dev.led) << 1) | !!test_bit(LED_NUML, sunkbd->dev.led)); 221 (!!test_bit(LED_COMPOSE, sunkbd->dev->led) << 1) | !!test_bit(LED_NUML, sunkbd->dev->led));
218 sunkbd->serio->write(sunkbd->serio, SUNKBD_CMD_NOCLICK - !!test_bit(SND_CLICK, sunkbd->dev.snd)); 222 sunkbd->serio->write(sunkbd->serio, SUNKBD_CMD_NOCLICK - !!test_bit(SND_CLICK, sunkbd->dev->snd));
219 sunkbd->serio->write(sunkbd->serio, SUNKBD_CMD_BELLOFF - !!test_bit(SND_BELL, sunkbd->dev.snd)); 223 sunkbd->serio->write(sunkbd->serio, SUNKBD_CMD_BELLOFF - !!test_bit(SND_BELL, sunkbd->dev->snd));
224}
225
226static void sunkbd_enable(struct sunkbd *sunkbd, int enable)
227{
228 serio_pause_rx(sunkbd->serio);
229 sunkbd->enabled = 1;
230 serio_continue_rx(sunkbd->serio);
220} 231}
221 232
222/* 233/*
@@ -226,70 +237,64 @@ static void sunkbd_reinit(void *data)
226static int sunkbd_connect(struct serio *serio, struct serio_driver *drv) 237static int sunkbd_connect(struct serio *serio, struct serio_driver *drv)
227{ 238{
228 struct sunkbd *sunkbd; 239 struct sunkbd *sunkbd;
240 struct input_dev *input_dev;
241 int err = -ENOMEM;
229 int i; 242 int i;
230 int err;
231
232 if (!(sunkbd = kmalloc(sizeof(struct sunkbd), GFP_KERNEL)))
233 return -ENOMEM;
234 243
235 memset(sunkbd, 0, sizeof(struct sunkbd)); 244 sunkbd = kzalloc(sizeof(struct sunkbd), GFP_KERNEL);
236 245 input_dev = input_allocate_device();
237 init_input_dev(&sunkbd->dev); 246 if (!sunkbd || !input_dev)
238 init_waitqueue_head(&sunkbd->wait); 247 goto fail;
239
240 sunkbd->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_SND) | BIT(EV_REP);
241 sunkbd->dev.ledbit[0] = BIT(LED_CAPSL) | BIT(LED_COMPOSE) | BIT(LED_SCROLLL) | BIT(LED_NUML);
242 sunkbd->dev.sndbit[0] = BIT(SND_CLICK) | BIT(SND_BELL);
243 248
244 sunkbd->serio = serio; 249 sunkbd->serio = serio;
245 250 sunkbd->dev = input_dev;
251 init_waitqueue_head(&sunkbd->wait);
246 INIT_WORK(&sunkbd->tq, sunkbd_reinit, sunkbd); 252 INIT_WORK(&sunkbd->tq, sunkbd_reinit, sunkbd);
247 253 snprintf(sunkbd->phys, sizeof(sunkbd->phys), "%s/input0", serio->phys);
248 sunkbd->dev.keycode = sunkbd->keycode;
249 sunkbd->dev.keycodesize = sizeof(unsigned char);
250 sunkbd->dev.keycodemax = ARRAY_SIZE(sunkbd_keycode);
251
252 sunkbd->dev.event = sunkbd_event;
253 sunkbd->dev.private = sunkbd;
254 254
255 serio_set_drvdata(serio, sunkbd); 255 serio_set_drvdata(serio, sunkbd);
256 256
257 err = serio_open(serio, drv); 257 err = serio_open(serio, drv);
258 if (err) { 258 if (err)
259 serio_set_drvdata(serio, NULL); 259 goto fail;
260 kfree(sunkbd);
261 return err;
262 }
263 260
264 if (sunkbd_initialize(sunkbd) < 0) { 261 if (sunkbd_initialize(sunkbd) < 0) {
265 serio_close(serio); 262 serio_close(serio);
266 serio_set_drvdata(serio, NULL); 263 goto fail;
267 kfree(sunkbd);
268 return -ENODEV;
269 } 264 }
270 265
271 sprintf(sunkbd->name, "Sun Type %d keyboard", sunkbd->type); 266 sprintf(sunkbd->name, "Sun Type %d keyboard", sunkbd->type);
272
273 memcpy(sunkbd->keycode, sunkbd_keycode, sizeof(sunkbd->keycode)); 267 memcpy(sunkbd->keycode, sunkbd_keycode, sizeof(sunkbd->keycode));
274 for (i = 0; i < 128; i++)
275 set_bit(sunkbd->keycode[i], sunkbd->dev.keybit);
276 clear_bit(0, sunkbd->dev.keybit);
277
278 sprintf(sunkbd->phys, "%s/input0", serio->phys);
279
280 sunkbd->dev.name = sunkbd->name;
281 sunkbd->dev.phys = sunkbd->phys;
282 sunkbd->dev.id.bustype = BUS_RS232;
283 sunkbd->dev.id.vendor = SERIO_SUNKBD;
284 sunkbd->dev.id.product = sunkbd->type;
285 sunkbd->dev.id.version = 0x0100;
286 sunkbd->dev.dev = &serio->dev;
287 268
288 input_register_device(&sunkbd->dev); 269 input_dev->name = sunkbd->name;
289 270 input_dev->phys = sunkbd->phys;
290 printk(KERN_INFO "input: %s on %s\n", sunkbd->name, serio->phys); 271 input_dev->id.bustype = BUS_RS232;
272 input_dev->id.vendor = SERIO_SUNKBD;
273 input_dev->id.product = sunkbd->type;
274 input_dev->id.version = 0x0100;
275 input_dev->cdev.dev = &serio->dev;
276 input_dev->private = sunkbd;
277 input_dev->event = sunkbd_event;
278
279 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_SND) | BIT(EV_REP);
280 input_dev->ledbit[0] = BIT(LED_CAPSL) | BIT(LED_COMPOSE) | BIT(LED_SCROLLL) | BIT(LED_NUML);
281 input_dev->sndbit[0] = BIT(SND_CLICK) | BIT(SND_BELL);
282
283 input_dev->keycode = sunkbd->keycode;
284 input_dev->keycodesize = sizeof(unsigned char);
285 input_dev->keycodemax = ARRAY_SIZE(sunkbd_keycode);
286 for (i = 0; i < 128; i++)
287 set_bit(sunkbd->keycode[i], input_dev->keybit);
288 clear_bit(0, input_dev->keybit);
291 289
290 sunkbd_enable(sunkbd, 1);
291 input_register_device(sunkbd->dev);
292 return 0; 292 return 0;
293
294 fail: serio_set_drvdata(serio, NULL);
295 input_free_device(input_dev);
296 kfree(sunkbd);
297 return err;
293} 298}
294 299
295/* 300/*
@@ -299,7 +304,9 @@ static int sunkbd_connect(struct serio *serio, struct serio_driver *drv)
299static void sunkbd_disconnect(struct serio *serio) 304static void sunkbd_disconnect(struct serio *serio)
300{ 305{
301 struct sunkbd *sunkbd = serio_get_drvdata(serio); 306 struct sunkbd *sunkbd = serio_get_drvdata(serio);
302 input_unregister_device(&sunkbd->dev); 307
308 sunkbd_enable(sunkbd, 0);
309 input_unregister_device(sunkbd->dev);
303 serio_close(serio); 310 serio_close(serio);
304 serio_set_drvdata(serio, NULL); 311 serio_set_drvdata(serio, NULL);
305 kfree(sunkbd); 312 kfree(sunkbd);
diff --git a/drivers/input/keyboard/xtkbd.c b/drivers/input/keyboard/xtkbd.c
index 19eaec7789d1..4135e3e16c51 100644
--- a/drivers/input/keyboard/xtkbd.c
+++ b/drivers/input/keyboard/xtkbd.c
@@ -56,11 +56,9 @@ static unsigned char xtkbd_keycode[256] = {
56 106 56 106
57}; 57};
58 58
59static char *xtkbd_name = "XT Keyboard";
60
61struct xtkbd { 59struct xtkbd {
62 unsigned char keycode[256]; 60 unsigned char keycode[256];
63 struct input_dev dev; 61 struct input_dev *dev;
64 struct serio *serio; 62 struct serio *serio;
65 char phys[32]; 63 char phys[32];
66}; 64};
@@ -77,9 +75,9 @@ static irqreturn_t xtkbd_interrupt(struct serio *serio,
77 default: 75 default:
78 76
79 if (xtkbd->keycode[data & XTKBD_KEY]) { 77 if (xtkbd->keycode[data & XTKBD_KEY]) {
80 input_regs(&xtkbd->dev, regs); 78 input_regs(xtkbd->dev, regs);
81 input_report_key(&xtkbd->dev, xtkbd->keycode[data & XTKBD_KEY], !(data & XTKBD_RELEASE)); 79 input_report_key(xtkbd->dev, xtkbd->keycode[data & XTKBD_KEY], !(data & XTKBD_RELEASE));
82 input_sync(&xtkbd->dev); 80 input_sync(xtkbd->dev);
83 } else { 81 } else {
84 printk(KERN_WARNING "xtkbd.c: Unknown key (scancode %#x) %s.\n", 82 printk(KERN_WARNING "xtkbd.c: Unknown key (scancode %#x) %s.\n",
85 data & XTKBD_KEY, data & XTKBD_RELEASE ? "released" : "pressed"); 83 data & XTKBD_KEY, data & XTKBD_RELEASE ? "released" : "pressed");
@@ -91,62 +89,60 @@ static irqreturn_t xtkbd_interrupt(struct serio *serio,
91static int xtkbd_connect(struct serio *serio, struct serio_driver *drv) 89static int xtkbd_connect(struct serio *serio, struct serio_driver *drv)
92{ 90{
93 struct xtkbd *xtkbd; 91 struct xtkbd *xtkbd;
92 struct input_dev *input_dev;
93 int err = -ENOMEM;
94 int i; 94 int i;
95 int err;
96
97 if (!(xtkbd = kmalloc(sizeof(struct xtkbd), GFP_KERNEL)))
98 return -ENOMEM;
99
100 memset(xtkbd, 0, sizeof(struct xtkbd));
101 95
102 xtkbd->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP); 96 xtkbd = kmalloc(sizeof(struct xtkbd), GFP_KERNEL);
97 input_dev = input_allocate_device();
98 if (!xtkbd || !input_dev)
99 goto fail;
103 100
104 xtkbd->serio = serio; 101 xtkbd->serio = serio;
102 xtkbd->dev = input_dev;
103 sprintf(xtkbd->phys, "%s/input0", serio->phys);
104 memcpy(xtkbd->keycode, xtkbd_keycode, sizeof(xtkbd->keycode));
105 105
106 init_input_dev(&xtkbd->dev); 106 input_dev->name = "XT Keyboard";
107 xtkbd->dev.keycode = xtkbd->keycode; 107 input_dev->phys = xtkbd->phys;
108 xtkbd->dev.keycodesize = sizeof(unsigned char); 108 input_dev->id.bustype = BUS_XTKBD;
109 xtkbd->dev.keycodemax = ARRAY_SIZE(xtkbd_keycode); 109 input_dev->id.vendor = 0x0001;
110 xtkbd->dev.private = xtkbd; 110 input_dev->id.product = 0x0001;
111 111 input_dev->id.version = 0x0100;
112 serio_set_drvdata(serio, xtkbd); 112 input_dev->cdev.dev = &serio->dev;
113 input_dev->private = xtkbd;
113 114
114 err = serio_open(serio, drv); 115 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
115 if (err) { 116 input_dev->keycode = xtkbd->keycode;
116 serio_set_drvdata(serio, NULL); 117 input_dev->keycodesize = sizeof(unsigned char);
117 kfree(xtkbd); 118 input_dev->keycodemax = ARRAY_SIZE(xtkbd_keycode);
118 return err;
119 }
120 119
121 memcpy(xtkbd->keycode, xtkbd_keycode, sizeof(xtkbd->keycode));
122 for (i = 0; i < 255; i++) 120 for (i = 0; i < 255; i++)
123 set_bit(xtkbd->keycode[i], xtkbd->dev.keybit); 121 set_bit(xtkbd->keycode[i], input_dev->keybit);
124 clear_bit(0, xtkbd->dev.keybit); 122 clear_bit(0, input_dev->keybit);
125
126 sprintf(xtkbd->phys, "%s/input0", serio->phys);
127
128 xtkbd->dev.name = xtkbd_name;
129 xtkbd->dev.phys = xtkbd->phys;
130 xtkbd->dev.id.bustype = BUS_XTKBD;
131 xtkbd->dev.id.vendor = 0x0001;
132 xtkbd->dev.id.product = 0x0001;
133 xtkbd->dev.id.version = 0x0100;
134 xtkbd->dev.dev = &serio->dev;
135 123
136 input_register_device(&xtkbd->dev); 124 serio_set_drvdata(serio, xtkbd);
137 125
138 printk(KERN_INFO "input: %s on %s\n", xtkbd_name, serio->phys); 126 err = serio_open(serio, drv);
127 if (err)
128 goto fail;
139 129
130 input_register_device(xtkbd->dev);
140 return 0; 131 return 0;
132
133 fail: serio_set_drvdata(serio, NULL);
134 input_free_device(input_dev);
135 kfree(xtkbd);
136 return err;
141} 137}
142 138
143static void xtkbd_disconnect(struct serio *serio) 139static void xtkbd_disconnect(struct serio *serio)
144{ 140{
145 struct xtkbd *xtkbd = serio_get_drvdata(serio); 141 struct xtkbd *xtkbd = serio_get_drvdata(serio);
146 142
147 input_unregister_device(&xtkbd->dev);
148 serio_close(serio); 143 serio_close(serio);
149 serio_set_drvdata(serio, NULL); 144 serio_set_drvdata(serio, NULL);
145 input_unregister_device(xtkbd->dev);
150 kfree(xtkbd); 146 kfree(xtkbd);
151} 147}
152 148
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index bb934e6d9636..b3eaac1b35b6 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -14,7 +14,7 @@ if INPUT_MISC
14 14
15config INPUT_PCSPKR 15config INPUT_PCSPKR
16 tristate "PC Speaker support" 16 tristate "PC Speaker support"
17 depends on ALPHA || X86 || X86_64 || MIPS || PPC_PREP || PPC_CHRP || PPC_PSERIES 17 depends on ALPHA || X86 || MIPS || PPC_PREP || PPC_CHRP || PPC_PSERIES
18 help 18 help
19 Say Y here if you want the standard PC Speaker to be used for 19 Say Y here if you want the standard PC Speaker to be used for
20 bells and whistles. 20 bells and whistles.
diff --git a/drivers/input/misc/m68kspkr.c b/drivers/input/misc/m68kspkr.c
index 64abdd98d482..04489ad7702a 100644
--- a/drivers/input/misc/m68kspkr.c
+++ b/drivers/input/misc/m68kspkr.c
@@ -24,9 +24,7 @@ MODULE_AUTHOR("Richard Zidlicky <rz@linux-m68k.org>");
24MODULE_DESCRIPTION("m68k beeper driver"); 24MODULE_DESCRIPTION("m68k beeper driver");
25MODULE_LICENSE("GPL"); 25MODULE_LICENSE("GPL");
26 26
27static char m68kspkr_name[] = "m68k beeper"; 27static struct input_dev *m68kspkr_dev;
28static char m68kspkr_phys[] = "m68k/generic";
29static struct input_dev m68kspkr_dev;
30 28
31static int m68kspkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) 29static int m68kspkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
32{ 30{
@@ -51,32 +49,34 @@ static int m68kspkr_event(struct input_dev *dev, unsigned int type, unsigned int
51 49
52static int __init m68kspkr_init(void) 50static int __init m68kspkr_init(void)
53{ 51{
54 if (!mach_beep){ 52 if (!mach_beep) {
55 printk("%s: no lowlevel beep support\n", m68kspkr_name); 53 printk(KERN_INFO "m68kspkr: no lowlevel beep support\n");
56 return -1; 54 return -ENODEV;
57 } 55 }
58 56
59 m68kspkr_dev.evbit[0] = BIT(EV_SND); 57 m68kspkr_dev = input_allocate_device();
60 m68kspkr_dev.sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE); 58 if (!m68kspkr_dev)
61 m68kspkr_dev.event = m68kspkr_event; 59 return -ENOMEM;
62 60
63 m68kspkr_dev.name = m68kspkr_name; 61 m68kspkr_dev->name = "m68k beeper";
64 m68kspkr_dev.phys = m68kspkr_phys; 62 m68kspkr_dev->phys = "m68k/generic";
65 m68kspkr_dev.id.bustype = BUS_HOST; 63 m68kspkr_dev->id.bustype = BUS_HOST;
66 m68kspkr_dev.id.vendor = 0x001f; 64 m68kspkr_dev->id.vendor = 0x001f;
67 m68kspkr_dev.id.product = 0x0001; 65 m68kspkr_dev->id.product = 0x0001;
68 m68kspkr_dev.id.version = 0x0100; 66 m68kspkr_dev->id.version = 0x0100;
69 67
70 input_register_device(&m68kspkr_dev); 68 m68kspkr_dev->evbit[0] = BIT(EV_SND);
69 m68kspkr_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE);
70 m68kspkr_dev->event = m68kspkr_event;
71 71
72 printk(KERN_INFO "input: %s\n", m68kspkr_name); 72 input_register_device(m68kspkr_dev);
73 73
74 return 0; 74 return 0;
75} 75}
76 76
77static void __exit m68kspkr_exit(void) 77static void __exit m68kspkr_exit(void)
78{ 78{
79 input_unregister_device(&m68kspkr_dev); 79 input_unregister_device(m68kspkr_dev);
80} 80}
81 81
82module_init(m68kspkr_init); 82module_init(m68kspkr_init);
diff --git a/drivers/input/misc/pcspkr.c b/drivers/input/misc/pcspkr.c
index 3013194f462b..e34633c37fdd 100644
--- a/drivers/input/misc/pcspkr.c
+++ b/drivers/input/misc/pcspkr.c
@@ -23,9 +23,7 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
23MODULE_DESCRIPTION("PC Speaker beeper driver"); 23MODULE_DESCRIPTION("PC Speaker beeper driver");
24MODULE_LICENSE("GPL"); 24MODULE_LICENSE("GPL");
25 25
26static char pcspkr_name[] = "PC Speaker"; 26static struct input_dev *pcspkr_dev;
27static char pcspkr_phys[] = "isa0061/input0";
28static struct input_dev pcspkr_dev;
29 27
30static DEFINE_SPINLOCK(i8253_beep_lock); 28static DEFINE_SPINLOCK(i8253_beep_lock);
31 29
@@ -68,27 +66,29 @@ static int pcspkr_event(struct input_dev *dev, unsigned int type, unsigned int c
68 66
69static int __init pcspkr_init(void) 67static int __init pcspkr_init(void)
70{ 68{
71 pcspkr_dev.evbit[0] = BIT(EV_SND); 69 pcspkr_dev = input_allocate_device();
72 pcspkr_dev.sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE); 70 if (!pcspkr_dev)
73 pcspkr_dev.event = pcspkr_event; 71 return -ENOMEM;
74 72
75 pcspkr_dev.name = pcspkr_name; 73 pcspkr_dev->name = "PC Speaker";
76 pcspkr_dev.phys = pcspkr_phys; 74 pcspkr_dev->name = "isa0061/input0";
77 pcspkr_dev.id.bustype = BUS_ISA; 75 pcspkr_dev->id.bustype = BUS_ISA;
78 pcspkr_dev.id.vendor = 0x001f; 76 pcspkr_dev->id.vendor = 0x001f;
79 pcspkr_dev.id.product = 0x0001; 77 pcspkr_dev->id.product = 0x0001;
80 pcspkr_dev.id.version = 0x0100; 78 pcspkr_dev->id.version = 0x0100;
81 79
82 input_register_device(&pcspkr_dev); 80 pcspkr_dev->evbit[0] = BIT(EV_SND);
81 pcspkr_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE);
82 pcspkr_dev->event = pcspkr_event;
83 83
84 printk(KERN_INFO "input: %s\n", pcspkr_name); 84 input_register_device(pcspkr_dev);
85 85
86 return 0; 86 return 0;
87} 87}
88 88
89static void __exit pcspkr_exit(void) 89static void __exit pcspkr_exit(void)
90{ 90{
91 input_unregister_device(&pcspkr_dev); 91 input_unregister_device(pcspkr_dev);
92 /* turn off the speaker */ 92 /* turn off the speaker */
93 pcspkr_event(NULL, EV_SND, SND_BELL, 0); 93 pcspkr_event(NULL, EV_SND, SND_BELL, 0);
94} 94}
diff --git a/drivers/input/misc/sparcspkr.c b/drivers/input/misc/sparcspkr.c
index cdc3fb3d5f46..29d97b12be7a 100644
--- a/drivers/input/misc/sparcspkr.c
+++ b/drivers/input/misc/sparcspkr.c
@@ -17,28 +17,24 @@
17#endif 17#endif
18 18
19MODULE_AUTHOR("David S. Miller <davem@redhat.com>"); 19MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
20MODULE_DESCRIPTION("PC Speaker beeper driver"); 20MODULE_DESCRIPTION("Sparc Speaker beeper driver");
21MODULE_LICENSE("GPL"); 21MODULE_LICENSE("GPL");
22 22
23static unsigned long beep_iobase; 23static unsigned long beep_iobase;
24 24static struct input_dev *sparcspkr_dev;
25static char *sparcspkr_isa_name = "Sparc ISA Speaker";
26static char *sparcspkr_ebus_name = "Sparc EBUS Speaker";
27static char *sparcspkr_phys = "sparc/input0";
28static struct input_dev sparcspkr_dev;
29 25
30DEFINE_SPINLOCK(beep_lock); 26DEFINE_SPINLOCK(beep_lock);
31 27
32static void __init init_sparcspkr_struct(void) 28static void __init init_sparcspkr_struct(void)
33{ 29{
34 sparcspkr_dev.evbit[0] = BIT(EV_SND); 30 sparcspkr_dev->evbit[0] = BIT(EV_SND);
35 sparcspkr_dev.sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE); 31 sparcspkr_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE);
36 32
37 sparcspkr_dev.phys = sparcspkr_phys; 33 sparcspkr_dev->phys = "sparc/input0";
38 sparcspkr_dev.id.bustype = BUS_ISA; 34 sparcspkr_dev->id.bustype = BUS_ISA;
39 sparcspkr_dev.id.vendor = 0x001f; 35 sparcspkr_dev->id.vendor = 0x001f;
40 sparcspkr_dev.id.product = 0x0001; 36 sparcspkr_dev->id.product = 0x0001;
41 sparcspkr_dev.id.version = 0x0100; 37 sparcspkr_dev->id.version = 0x0100;
42} 38}
43 39
44static int ebus_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) 40static int ebus_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
@@ -84,14 +80,15 @@ static int __init init_ebus_beep(struct linux_ebus_device *edev)
84{ 80{
85 beep_iobase = edev->resource[0].start; 81 beep_iobase = edev->resource[0].start;
86 82
87 init_sparcspkr_struct(); 83 sparcspkr_dev = input_allocate_device();
84 if (!sparcspkr_dev)
85 return -ENOMEM;
88 86
89 sparcspkr_dev.name = sparcspkr_ebus_name; 87 sparcspkr_dev->name = "Sparc EBUS Speaker";
90 sparcspkr_dev.event = ebus_spkr_event; 88 sparcspkr_dev->event = ebus_spkr_event;
91 89
92 input_register_device(&sparcspkr_dev); 90 input_register_device(sparcspkr_dev);
93 91
94 printk(KERN_INFO "input: %s\n", sparcspkr_ebus_name);
95 return 0; 92 return 0;
96} 93}
97 94
@@ -137,15 +134,17 @@ static int __init init_isa_beep(struct sparc_isa_device *isa_dev)
137{ 134{
138 beep_iobase = isa_dev->resource.start; 135 beep_iobase = isa_dev->resource.start;
139 136
137 sparcspkr_dev = input_allocate_device();
138 if (!sparcspkr_dev)
139 return -ENOMEM;
140
140 init_sparcspkr_struct(); 141 init_sparcspkr_struct();
141 142
142 sparcspkr_dev.name = sparcspkr_isa_name; 143 sparcspkr_dev->name = "Sparc ISA Speaker";
143 sparcspkr_dev.event = isa_spkr_event; 144 sparcspkr_dev->event = isa_spkr_event;
144 sparcspkr_dev.id.bustype = BUS_ISA;
145 145
146 input_register_device(&sparcspkr_dev); 146 input_register_device(sparcspkr_dev);
147 147
148 printk(KERN_INFO "input: %s\n", sparcspkr_isa_name);
149 return 0; 148 return 0;
150} 149}
151#endif 150#endif
@@ -182,7 +181,7 @@ static int __init sparcspkr_init(void)
182 181
183static void __exit sparcspkr_exit(void) 182static void __exit sparcspkr_exit(void)
184{ 183{
185 input_unregister_device(&sparcspkr_dev); 184 input_unregister_device(sparcspkr_dev);
186} 185}
187 186
188module_init(sparcspkr_init); 187module_init(sparcspkr_init);
diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index b20783f9748a..4acc7fd4cd0f 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -79,8 +79,8 @@ static void alps_process_packet(struct psmouse *psmouse, struct pt_regs *regs)
79{ 79{
80 struct alps_data *priv = psmouse->private; 80 struct alps_data *priv = psmouse->private;
81 unsigned char *packet = psmouse->packet; 81 unsigned char *packet = psmouse->packet;
82 struct input_dev *dev = &psmouse->dev; 82 struct input_dev *dev = psmouse->dev;
83 struct input_dev *dev2 = &priv->dev2; 83 struct input_dev *dev2 = priv->dev2;
84 int x, y, z, ges, fin, left, right, middle; 84 int x, y, z, ges, fin, left, right, middle;
85 int back = 0, forward = 0; 85 int back = 0, forward = 0;
86 86
@@ -379,20 +379,24 @@ static int alps_reconnect(struct psmouse *psmouse)
379static void alps_disconnect(struct psmouse *psmouse) 379static void alps_disconnect(struct psmouse *psmouse)
380{ 380{
381 struct alps_data *priv = psmouse->private; 381 struct alps_data *priv = psmouse->private;
382
382 psmouse_reset(psmouse); 383 psmouse_reset(psmouse);
383 input_unregister_device(&priv->dev2); 384 input_unregister_device(priv->dev2);
384 kfree(priv); 385 kfree(priv);
385} 386}
386 387
387int alps_init(struct psmouse *psmouse) 388int alps_init(struct psmouse *psmouse)
388{ 389{
389 struct alps_data *priv; 390 struct alps_data *priv;
391 struct input_dev *dev1 = psmouse->dev, *dev2;
390 int version; 392 int version;
391 393
392 psmouse->private = priv = kmalloc(sizeof(struct alps_data), GFP_KERNEL); 394 psmouse->private = priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL);
393 if (!priv) 395 dev2 = input_allocate_device();
396 if (!priv || !dev2)
394 goto init_fail; 397 goto init_fail;
395 memset(priv, 0, sizeof(struct alps_data)); 398
399 priv->dev2 = dev2;
396 400
397 if (!(priv->i = alps_get_model(psmouse, &version))) 401 if (!(priv->i = alps_get_model(psmouse, &version)))
398 goto init_fail; 402 goto init_fail;
@@ -411,41 +415,39 @@ int alps_init(struct psmouse *psmouse)
411 if ((priv->i->flags & ALPS_PASS) && alps_passthrough_mode(psmouse, 0)) 415 if ((priv->i->flags & ALPS_PASS) && alps_passthrough_mode(psmouse, 0))
412 goto init_fail; 416 goto init_fail;
413 417
414 psmouse->dev.evbit[LONG(EV_KEY)] |= BIT(EV_KEY); 418 dev1->evbit[LONG(EV_KEY)] |= BIT(EV_KEY);
415 psmouse->dev.keybit[LONG(BTN_TOUCH)] |= BIT(BTN_TOUCH); 419 dev1->keybit[LONG(BTN_TOUCH)] |= BIT(BTN_TOUCH);
416 psmouse->dev.keybit[LONG(BTN_TOOL_FINGER)] |= BIT(BTN_TOOL_FINGER); 420 dev1->keybit[LONG(BTN_TOOL_FINGER)] |= BIT(BTN_TOOL_FINGER);
417 psmouse->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT); 421 dev1->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
418 422
419 psmouse->dev.evbit[LONG(EV_ABS)] |= BIT(EV_ABS); 423 dev1->evbit[LONG(EV_ABS)] |= BIT(EV_ABS);
420 input_set_abs_params(&psmouse->dev, ABS_X, 0, 1023, 0, 0); 424 input_set_abs_params(dev1, ABS_X, 0, 1023, 0, 0);
421 input_set_abs_params(&psmouse->dev, ABS_Y, 0, 767, 0, 0); 425 input_set_abs_params(dev1, ABS_Y, 0, 767, 0, 0);
422 input_set_abs_params(&psmouse->dev, ABS_PRESSURE, 0, 127, 0, 0); 426 input_set_abs_params(dev1, ABS_PRESSURE, 0, 127, 0, 0);
423 427
424 if (priv->i->flags & ALPS_WHEEL) { 428 if (priv->i->flags & ALPS_WHEEL) {
425 psmouse->dev.evbit[LONG(EV_REL)] |= BIT(EV_REL); 429 dev1->evbit[LONG(EV_REL)] |= BIT(EV_REL);
426 psmouse->dev.relbit[LONG(REL_WHEEL)] |= BIT(REL_WHEEL); 430 dev1->relbit[LONG(REL_WHEEL)] |= BIT(REL_WHEEL);
427 } 431 }
428 432
429 if (priv->i->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) { 433 if (priv->i->flags & (ALPS_FW_BK_1 | ALPS_FW_BK_2)) {
430 psmouse->dev.keybit[LONG(BTN_FORWARD)] |= BIT(BTN_FORWARD); 434 dev1->keybit[LONG(BTN_FORWARD)] |= BIT(BTN_FORWARD);
431 psmouse->dev.keybit[LONG(BTN_BACK)] |= BIT(BTN_BACK); 435 dev1->keybit[LONG(BTN_BACK)] |= BIT(BTN_BACK);
432 } 436 }
433 437
434 sprintf(priv->phys, "%s/input1", psmouse->ps2dev.serio->phys); 438 sprintf(priv->phys, "%s/input1", psmouse->ps2dev.serio->phys);
435 priv->dev2.phys = priv->phys; 439 dev2->phys = priv->phys;
436 priv->dev2.name = (priv->i->flags & ALPS_DUALPOINT) ? "DualPoint Stick" : "PS/2 Mouse"; 440 dev2->name = (priv->i->flags & ALPS_DUALPOINT) ? "DualPoint Stick" : "PS/2 Mouse";
437 priv->dev2.id.bustype = BUS_I8042; 441 dev2->id.bustype = BUS_I8042;
438 priv->dev2.id.vendor = 0x0002; 442 dev2->id.vendor = 0x0002;
439 priv->dev2.id.product = PSMOUSE_ALPS; 443 dev2->id.product = PSMOUSE_ALPS;
440 priv->dev2.id.version = 0x0000; 444 dev2->id.version = 0x0000;
441
442 priv->dev2.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
443 priv->dev2.relbit[LONG(REL_X)] |= BIT(REL_X) | BIT(REL_Y);
444 priv->dev2.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
445 445
446 input_register_device(&priv->dev2); 446 dev2->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
447 dev2->relbit[LONG(REL_X)] |= BIT(REL_X) | BIT(REL_Y);
448 dev2->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
447 449
448 printk(KERN_INFO "input: %s on %s\n", priv->dev2.name, psmouse->ps2dev.serio->phys); 450 input_register_device(priv->dev2);
449 451
450 psmouse->protocol_handler = alps_process_byte; 452 psmouse->protocol_handler = alps_process_byte;
451 psmouse->disconnect = alps_disconnect; 453 psmouse->disconnect = alps_disconnect;
@@ -455,6 +457,7 @@ int alps_init(struct psmouse *psmouse)
455 return 0; 457 return 0;
456 458
457init_fail: 459init_fail:
460 input_free_device(dev2);
458 kfree(priv); 461 kfree(priv);
459 return -1; 462 return -1;
460} 463}
diff --git a/drivers/input/mouse/alps.h b/drivers/input/mouse/alps.h
index aba103dd65b7..e428f8d5d12e 100644
--- a/drivers/input/mouse/alps.h
+++ b/drivers/input/mouse/alps.h
@@ -22,7 +22,7 @@ struct alps_model_info {
22}; 22};
23 23
24struct alps_data { 24struct alps_data {
25 struct input_dev dev2; /* Relative device */ 25 struct input_dev *dev2; /* Relative device */
26 char name[32]; /* Name */ 26 char name[32]; /* Name */
27 char phys[32]; /* Phys */ 27 char phys[32]; /* Phys */
28 struct alps_model_info *i; /* Info */ 28 struct alps_model_info *i; /* Info */
diff --git a/drivers/input/mouse/amimouse.c b/drivers/input/mouse/amimouse.c
index e994849efb8f..d13d4c8fe3c5 100644
--- a/drivers/input/mouse/amimouse.c
+++ b/drivers/input/mouse/amimouse.c
@@ -34,10 +34,7 @@ MODULE_DESCRIPTION("Amiga mouse driver");
34MODULE_LICENSE("GPL"); 34MODULE_LICENSE("GPL");
35 35
36static int amimouse_lastx, amimouse_lasty; 36static int amimouse_lastx, amimouse_lasty;
37static struct input_dev amimouse_dev; 37static struct input_dev *amimouse_dev;
38
39static char *amimouse_name = "Amiga mouse";
40static char *amimouse_phys = "amimouse/input0";
41 38
42static irqreturn_t amimouse_interrupt(int irq, void *dummy, struct pt_regs *fp) 39static irqreturn_t amimouse_interrupt(int irq, void *dummy, struct pt_regs *fp)
43{ 40{
@@ -62,16 +59,16 @@ static irqreturn_t amimouse_interrupt(int irq, void *dummy, struct pt_regs *fp)
62 59
63 potgor = custom.potgor; 60 potgor = custom.potgor;
64 61
65 input_regs(&amimouse_dev, fp); 62 input_regs(amimouse_dev, fp);
66 63
67 input_report_rel(&amimouse_dev, REL_X, dx); 64 input_report_rel(amimouse_dev, REL_X, dx);
68 input_report_rel(&amimouse_dev, REL_Y, dy); 65 input_report_rel(amimouse_dev, REL_Y, dy);
69 66
70 input_report_key(&amimouse_dev, BTN_LEFT, ciaa.pra & 0x40); 67 input_report_key(amimouse_dev, BTN_LEFT, ciaa.pra & 0x40);
71 input_report_key(&amimouse_dev, BTN_MIDDLE, potgor & 0x0100); 68 input_report_key(amimouse_dev, BTN_MIDDLE, potgor & 0x0100);
72 input_report_key(&amimouse_dev, BTN_RIGHT, potgor & 0x0400); 69 input_report_key(amimouse_dev, BTN_RIGHT, potgor & 0x0400);
73 70
74 input_sync(&amimouse_dev); 71 input_sync(amimouse_dev);
75 72
76 return IRQ_HANDLED; 73 return IRQ_HANDLED;
77} 74}
@@ -103,28 +100,30 @@ static int __init amimouse_init(void)
103 if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(AMI_MOUSE)) 100 if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(AMI_MOUSE))
104 return -ENODEV; 101 return -ENODEV;
105 102
106 amimouse_dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL); 103 if (!(amimouse_dev = input_allocate_device()))
107 amimouse_dev.relbit[0] = BIT(REL_X) | BIT(REL_Y); 104 return -ENOMEM;
108 amimouse_dev.keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT); 105
109 amimouse_dev.open = amimouse_open; 106 amimouse_dev->name = "Amiga mouse";
110 amimouse_dev.close = amimouse_close; 107 amimouse_dev->phys = "amimouse/input0";
108 amimouse_dev->id.bustype = BUS_AMIGA;
109 amimouse_dev->id.vendor = 0x0001;
110 amimouse_dev->id.product = 0x0002;
111 amimouse_dev->id.version = 0x0100;
111 112
112 amimouse_dev.name = amimouse_name; 113 amimouse_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
113 amimouse_dev.phys = amimouse_phys; 114 amimouse_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
114 amimouse_dev.id.bustype = BUS_AMIGA; 115 amimouse_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
115 amimouse_dev.id.vendor = 0x0001; 116 amimouse_dev->open = amimouse_open;
116 amimouse_dev.id.product = 0x0002; 117 amimouse_dev->close = amimouse_close;
117 amimouse_dev.id.version = 0x0100;
118 118
119 input_register_device(&amimouse_dev); 119 input_register_device(amimouse_dev);
120 120
121 printk(KERN_INFO "input: %s at joy0dat\n", amimouse_name);
122 return 0; 121 return 0;
123} 122}
124 123
125static void __exit amimouse_exit(void) 124static void __exit amimouse_exit(void)
126{ 125{
127 input_unregister_device(&amimouse_dev); 126 input_unregister_device(amimouse_dev);
128} 127}
129 128
130module_init(amimouse_init); 129module_init(amimouse_init);
diff --git a/drivers/input/mouse/hil_ptr.c b/drivers/input/mouse/hil_ptr.c
index bc22849c6c79..c2bf2ed07dc6 100644
--- a/drivers/input/mouse/hil_ptr.c
+++ b/drivers/input/mouse/hil_ptr.c
@@ -196,7 +196,7 @@ static irqreturn_t hil_ptr_interrupt(struct serio *serio,
196 hil_packet packet; 196 hil_packet packet;
197 int idx; 197 int idx;
198 198
199 ptr = (struct hil_ptr *)serio->private; 199 ptr = serio_get_drvdata(serio);
200 if (ptr == NULL) { 200 if (ptr == NULL) {
201 BUG(); 201 BUG();
202 return IRQ_HANDLED; 202 return IRQ_HANDLED;
@@ -227,7 +227,7 @@ static void hil_ptr_disconnect(struct serio *serio)
227{ 227{
228 struct hil_ptr *ptr; 228 struct hil_ptr *ptr;
229 229
230 ptr = (struct hil_ptr *)serio->private; 230 ptr = serio_get_drvdata(serio);
231 if (ptr == NULL) { 231 if (ptr == NULL) {
232 BUG(); 232 BUG();
233 return; 233 return;
@@ -238,21 +238,19 @@ static void hil_ptr_disconnect(struct serio *serio)
238 kfree(ptr); 238 kfree(ptr);
239} 239}
240 240
241static void hil_ptr_connect(struct serio *serio, struct serio_driver *driver) 241static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
242{ 242{
243 struct hil_ptr *ptr; 243 struct hil_ptr *ptr;
244 char *txt; 244 char *txt;
245 unsigned int i, naxsets, btntype; 245 unsigned int i, naxsets, btntype;
246 uint8_t did, *idd; 246 uint8_t did, *idd;
247 247
248 if (serio->type != (SERIO_HIL_MLC | SERIO_HIL)) return; 248 if (!(ptr = kmalloc(sizeof(struct hil_ptr), GFP_KERNEL))) return -ENOMEM;
249
250 if (!(ptr = kmalloc(sizeof(struct hil_ptr), GFP_KERNEL))) return;
251 memset(ptr, 0, sizeof(struct hil_ptr)); 249 memset(ptr, 0, sizeof(struct hil_ptr));
252 250
253 if (serio_open(serio, driver)) goto bail0; 251 if (serio_open(serio, driver)) goto bail0;
254 252
255 serio->private = ptr; 253 serio_set_drvdata(serio, ptr);
256 ptr->serio = serio; 254 ptr->serio = serio;
257 ptr->dev.private = ptr; 255 ptr->dev.private = ptr;
258 256
@@ -380,23 +378,34 @@ static void hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
380 (btntype == BTN_MOUSE) ? "HIL mouse":"HIL tablet or touchpad", 378 (btntype == BTN_MOUSE) ? "HIL mouse":"HIL tablet or touchpad",
381 did); 379 did);
382 380
383 return; 381 return 0;
384 bail1: 382 bail1:
385 serio_close(serio); 383 serio_close(serio);
386 bail0: 384 bail0:
387 kfree(ptr); 385 kfree(ptr);
388 return; 386 serio_set_drvdata(serio, NULL);
387 return -ENODEV;
389} 388}
390 389
390static struct serio_device_id hil_ptr_ids[] = {
391 {
392 .type = SERIO_HIL_MLC,
393 .proto = SERIO_HIL,
394 .id = SERIO_ANY,
395 .extra = SERIO_ANY,
396 },
397 { 0 }
398};
391 399
392static struct serio_driver hil_ptr_serio_driver = { 400static struct serio_driver hil_ptr_serio_driver = {
393 .driver = { 401 .driver = {
394 .name = "hil_ptr", 402 .name = "hil_ptr",
395 }, 403 },
396 .description = "HP HIL mouse/tablet driver", 404 .description = "HP HIL mouse/tablet driver",
397 .connect = hil_ptr_connect, 405 .id_table = hil_ptr_ids,
398 .disconnect = hil_ptr_disconnect, 406 .connect = hil_ptr_connect,
399 .interrupt = hil_ptr_interrupt 407 .disconnect = hil_ptr_disconnect,
408 .interrupt = hil_ptr_interrupt
400}; 409};
401 410
402static int __init hil_ptr_init(void) 411static int __init hil_ptr_init(void)
diff --git a/drivers/input/mouse/inport.c b/drivers/input/mouse/inport.c
index 1f62c0134010..afc66f56df43 100644
--- a/drivers/input/mouse/inport.c
+++ b/drivers/input/mouse/inport.c
@@ -87,40 +87,7 @@ MODULE_PARM_DESC(irq, "IRQ number (5=default)");
87 87
88__obsolete_setup("inport_irq="); 88__obsolete_setup("inport_irq=");
89 89
90static irqreturn_t inport_interrupt(int irq, void *dev_id, struct pt_regs *regs); 90static struct input_dev *inport_dev;
91
92static int inport_open(struct input_dev *dev)
93{
94 if (request_irq(inport_irq, inport_interrupt, 0, "inport", NULL))
95 return -EBUSY;
96 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
97 outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
98
99 return 0;
100}
101
102static void inport_close(struct input_dev *dev)
103{
104 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
105 outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
106 free_irq(inport_irq, NULL);
107}
108
109static struct input_dev inport_dev = {
110 .evbit = { BIT(EV_KEY) | BIT(EV_REL) },
111 .keybit = { [LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT) },
112 .relbit = { BIT(REL_X) | BIT(REL_Y) },
113 .open = inport_open,
114 .close = inport_close,
115 .name = INPORT_NAME,
116 .phys = "isa023c/input0",
117 .id = {
118 .bustype = BUS_ISA,
119 .vendor = INPORT_VENDOR,
120 .product = 0x0001,
121 .version = 0x0100,
122 },
123};
124 91
125static irqreturn_t inport_interrupt(int irq, void *dev_id, struct pt_regs *regs) 92static irqreturn_t inport_interrupt(int irq, void *dev_id, struct pt_regs *regs)
126{ 93{
@@ -129,31 +96,48 @@ static irqreturn_t inport_interrupt(int irq, void *dev_id, struct pt_regs *regs)
129 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); 96 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
130 outb(INPORT_MODE_HOLD | INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT); 97 outb(INPORT_MODE_HOLD | INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
131 98
132 input_regs(&inport_dev, regs); 99 input_regs(inport_dev, regs);
133 100
134 outb(INPORT_REG_X, INPORT_CONTROL_PORT); 101 outb(INPORT_REG_X, INPORT_CONTROL_PORT);
135 input_report_rel(&inport_dev, REL_X, inb(INPORT_DATA_PORT)); 102 input_report_rel(inport_dev, REL_X, inb(INPORT_DATA_PORT));
136 103
137 outb(INPORT_REG_Y, INPORT_CONTROL_PORT); 104 outb(INPORT_REG_Y, INPORT_CONTROL_PORT);
138 input_report_rel(&inport_dev, REL_Y, inb(INPORT_DATA_PORT)); 105 input_report_rel(inport_dev, REL_Y, inb(INPORT_DATA_PORT));
139 106
140 outb(INPORT_REG_BTNS, INPORT_CONTROL_PORT); 107 outb(INPORT_REG_BTNS, INPORT_CONTROL_PORT);
141 buttons = inb(INPORT_DATA_PORT); 108 buttons = inb(INPORT_DATA_PORT);
142 109
143 input_report_key(&inport_dev, BTN_MIDDLE, buttons & 1); 110 input_report_key(inport_dev, BTN_MIDDLE, buttons & 1);
144 input_report_key(&inport_dev, BTN_LEFT, buttons & 2); 111 input_report_key(inport_dev, BTN_LEFT, buttons & 2);
145 input_report_key(&inport_dev, BTN_RIGHT, buttons & 4); 112 input_report_key(inport_dev, BTN_RIGHT, buttons & 4);
146 113
147 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); 114 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
148 outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT); 115 outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
149 116
150 input_sync(&inport_dev); 117 input_sync(inport_dev);
151 return IRQ_HANDLED; 118 return IRQ_HANDLED;
152} 119}
153 120
121static int inport_open(struct input_dev *dev)
122{
123 if (request_irq(inport_irq, inport_interrupt, 0, "inport", NULL))
124 return -EBUSY;
125 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
126 outb(INPORT_MODE_IRQ | INPORT_MODE_BASE, INPORT_DATA_PORT);
127
128 return 0;
129}
130
131static void inport_close(struct input_dev *dev)
132{
133 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
134 outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
135 free_irq(inport_irq, NULL);
136}
137
154static int __init inport_init(void) 138static int __init inport_init(void)
155{ 139{
156 unsigned char a,b,c; 140 unsigned char a, b, c;
157 141
158 if (!request_region(INPORT_BASE, INPORT_EXTENT, "inport")) { 142 if (!request_region(INPORT_BASE, INPORT_EXTENT, "inport")) {
159 printk(KERN_ERR "inport.c: Can't allocate ports at %#x\n", INPORT_BASE); 143 printk(KERN_ERR "inport.c: Can't allocate ports at %#x\n", INPORT_BASE);
@@ -163,26 +147,44 @@ static int __init inport_init(void)
163 a = inb(INPORT_SIGNATURE_PORT); 147 a = inb(INPORT_SIGNATURE_PORT);
164 b = inb(INPORT_SIGNATURE_PORT); 148 b = inb(INPORT_SIGNATURE_PORT);
165 c = inb(INPORT_SIGNATURE_PORT); 149 c = inb(INPORT_SIGNATURE_PORT);
166 if (( a == b ) || ( a != c )) { 150 if (a == b || a != c) {
167 release_region(INPORT_BASE, INPORT_EXTENT); 151 release_region(INPORT_BASE, INPORT_EXTENT);
168 printk(KERN_ERR "inport.c: Didn't find InPort mouse at %#x\n", INPORT_BASE); 152 printk(KERN_ERR "inport.c: Didn't find InPort mouse at %#x\n", INPORT_BASE);
169 return -ENODEV; 153 return -ENODEV;
170 } 154 }
171 155
156 if (!(inport_dev = input_allocate_device())) {
157 printk(KERN_ERR "inport.c: Not enough memory for input device\n");
158 release_region(INPORT_BASE, INPORT_EXTENT);
159 return -ENOMEM;
160 }
161
162 inport_dev->name = INPORT_NAME;
163 inport_dev->phys = "isa023c/input0";
164 inport_dev->id.bustype = BUS_ISA;
165 inport_dev->id.vendor = INPORT_VENDOR;
166 inport_dev->id.product = 0x0001;
167 inport_dev->id.version = 0x0100;
168
169 inport_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
170 inport_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
171 inport_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
172
173 inport_dev->open = inport_open;
174 inport_dev->close = inport_close;
175
172 outb(INPORT_RESET, INPORT_CONTROL_PORT); 176 outb(INPORT_RESET, INPORT_CONTROL_PORT);
173 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); 177 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
174 outb(INPORT_MODE_BASE, INPORT_DATA_PORT); 178 outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
175 179
176 input_register_device(&inport_dev); 180 input_register_device(inport_dev);
177
178 printk(KERN_INFO "input: " INPORT_NAME " at %#x irq %d\n", INPORT_BASE, inport_irq);
179 181
180 return 0; 182 return 0;
181} 183}
182 184
183static void __exit inport_exit(void) 185static void __exit inport_exit(void)
184{ 186{
185 input_unregister_device(&inport_dev); 187 input_unregister_device(inport_dev);
186 release_region(INPORT_BASE, INPORT_EXTENT); 188 release_region(INPORT_BASE, INPORT_EXTENT);
187} 189}
188 190
diff --git a/drivers/input/mouse/lifebook.c b/drivers/input/mouse/lifebook.c
index bd9df9b28325..55991424ac91 100644
--- a/drivers/input/mouse/lifebook.c
+++ b/drivers/input/mouse/lifebook.c
@@ -34,7 +34,7 @@ static struct dmi_system_id lifebook_dmi_table[] = {
34static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse, struct pt_regs *regs) 34static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse, struct pt_regs *regs)
35{ 35{
36 unsigned char *packet = psmouse->packet; 36 unsigned char *packet = psmouse->packet;
37 struct input_dev *dev = &psmouse->dev; 37 struct input_dev *dev = psmouse->dev;
38 38
39 if (psmouse->pktcnt != 3) 39 if (psmouse->pktcnt != 3)
40 return PSMOUSE_GOOD_DATA; 40 return PSMOUSE_GOOD_DATA;
@@ -113,15 +113,17 @@ int lifebook_detect(struct psmouse *psmouse, int set_properties)
113 113
114int lifebook_init(struct psmouse *psmouse) 114int lifebook_init(struct psmouse *psmouse)
115{ 115{
116 struct input_dev *input_dev = psmouse->dev;
117
116 if (lifebook_absolute_mode(psmouse)) 118 if (lifebook_absolute_mode(psmouse))
117 return -1; 119 return -1;
118 120
119 psmouse->dev.evbit[0] = BIT(EV_ABS) | BIT(EV_KEY) | BIT(EV_REL); 121 input_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY) | BIT(EV_REL);
120 psmouse->dev.keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT); 122 input_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
121 psmouse->dev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); 123 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
122 psmouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y); 124 input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
123 input_set_abs_params(&psmouse->dev, ABS_X, 0, 1024, 0, 0); 125 input_set_abs_params(input_dev, ABS_X, 0, 1024, 0, 0);
124 input_set_abs_params(&psmouse->dev, ABS_Y, 0, 1024, 0, 0); 126 input_set_abs_params(input_dev, ABS_Y, 0, 1024, 0, 0);
125 127
126 psmouse->protocol_handler = lifebook_process_byte; 128 psmouse->protocol_handler = lifebook_process_byte;
127 psmouse->set_resolution = lifebook_set_resolution; 129 psmouse->set_resolution = lifebook_set_resolution;
diff --git a/drivers/input/mouse/logibm.c b/drivers/input/mouse/logibm.c
index 8b5243167227..9c7ce38806d7 100644
--- a/drivers/input/mouse/logibm.c
+++ b/drivers/input/mouse/logibm.c
@@ -77,39 +77,7 @@ MODULE_PARM_DESC(irq, "IRQ number (5=default)");
77 77
78__obsolete_setup("logibm_irq="); 78__obsolete_setup("logibm_irq=");
79 79
80static irqreturn_t logibm_interrupt(int irq, void *dev_id, struct pt_regs *regs); 80static struct input_dev *logibm_dev;
81
82static int logibm_open(struct input_dev *dev)
83{
84 if (request_irq(logibm_irq, logibm_interrupt, 0, "logibm", NULL)) {
85 printk(KERN_ERR "logibm.c: Can't allocate irq %d\n", logibm_irq);
86 return -EBUSY;
87 }
88 outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT);
89 return 0;
90}
91
92static void logibm_close(struct input_dev *dev)
93{
94 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
95 free_irq(logibm_irq, NULL);
96}
97
98static struct input_dev logibm_dev = {
99 .evbit = { BIT(EV_KEY) | BIT(EV_REL) },
100 .keybit = { [LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT) },
101 .relbit = { BIT(REL_X) | BIT(REL_Y) },
102 .open = logibm_open,
103 .close = logibm_close,
104 .name = "Logitech bus mouse",
105 .phys = "isa023c/input0",
106 .id = {
107 .bustype = BUS_ISA,
108 .vendor = 0x0003,
109 .product = 0x0001,
110 .version = 0x0100,
111 },
112};
113 81
114static irqreturn_t logibm_interrupt(int irq, void *dev_id, struct pt_regs *regs) 82static irqreturn_t logibm_interrupt(int irq, void *dev_id, struct pt_regs *regs)
115{ 83{
@@ -127,18 +95,34 @@ static irqreturn_t logibm_interrupt(int irq, void *dev_id, struct pt_regs *regs)
127 dy |= (buttons & 0xf) << 4; 95 dy |= (buttons & 0xf) << 4;
128 buttons = ~buttons >> 5; 96 buttons = ~buttons >> 5;
129 97
130 input_regs(&logibm_dev, regs); 98 input_regs(logibm_dev, regs);
131 input_report_rel(&logibm_dev, REL_X, dx); 99 input_report_rel(logibm_dev, REL_X, dx);
132 input_report_rel(&logibm_dev, REL_Y, dy); 100 input_report_rel(logibm_dev, REL_Y, dy);
133 input_report_key(&logibm_dev, BTN_RIGHT, buttons & 1); 101 input_report_key(logibm_dev, BTN_RIGHT, buttons & 1);
134 input_report_key(&logibm_dev, BTN_MIDDLE, buttons & 2); 102 input_report_key(logibm_dev, BTN_MIDDLE, buttons & 2);
135 input_report_key(&logibm_dev, BTN_LEFT, buttons & 4); 103 input_report_key(logibm_dev, BTN_LEFT, buttons & 4);
136 input_sync(&logibm_dev); 104 input_sync(logibm_dev);
137 105
138 outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT); 106 outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT);
139 return IRQ_HANDLED; 107 return IRQ_HANDLED;
140} 108}
141 109
110static int logibm_open(struct input_dev *dev)
111{
112 if (request_irq(logibm_irq, logibm_interrupt, 0, "logibm", NULL)) {
113 printk(KERN_ERR "logibm.c: Can't allocate irq %d\n", logibm_irq);
114 return -EBUSY;
115 }
116 outb(LOGIBM_ENABLE_IRQ, LOGIBM_CONTROL_PORT);
117 return 0;
118}
119
120static void logibm_close(struct input_dev *dev)
121{
122 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
123 free_irq(logibm_irq, NULL);
124}
125
142static int __init logibm_init(void) 126static int __init logibm_init(void)
143{ 127{
144 if (!request_region(LOGIBM_BASE, LOGIBM_EXTENT, "logibm")) { 128 if (!request_region(LOGIBM_BASE, LOGIBM_EXTENT, "logibm")) {
@@ -159,16 +143,34 @@ static int __init logibm_init(void)
159 outb(LOGIBM_DEFAULT_MODE, LOGIBM_CONFIG_PORT); 143 outb(LOGIBM_DEFAULT_MODE, LOGIBM_CONFIG_PORT);
160 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT); 144 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
161 145
162 input_register_device(&logibm_dev); 146 if (!(logibm_dev = input_allocate_device())) {
147 printk(KERN_ERR "logibm.c: Not enough memory for input device\n");
148 release_region(LOGIBM_BASE, LOGIBM_EXTENT);
149 return -ENOMEM;
150 }
151
152 logibm_dev->name = "Logitech bus mouse";
153 logibm_dev->phys = "isa023c/input0";
154 logibm_dev->id.bustype = BUS_ISA;
155 logibm_dev->id.vendor = 0x0003;
156 logibm_dev->id.product = 0x0001;
157 logibm_dev->id.version = 0x0100;
158
159 logibm_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
160 logibm_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
161 logibm_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
162
163 logibm_dev->open = logibm_open;
164 logibm_dev->close = logibm_close;
163 165
164 printk(KERN_INFO "input: Logitech bus mouse at %#x irq %d\n", LOGIBM_BASE, logibm_irq); 166 input_register_device(logibm_dev);
165 167
166 return 0; 168 return 0;
167} 169}
168 170
169static void __exit logibm_exit(void) 171static void __exit logibm_exit(void)
170{ 172{
171 input_unregister_device(&logibm_dev); 173 input_unregister_device(logibm_dev);
172 release_region(LOGIBM_BASE, LOGIBM_EXTENT); 174 release_region(LOGIBM_BASE, LOGIBM_EXTENT);
173} 175}
174 176
diff --git a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
index 7df96525222e..0f69ff46c1ae 100644
--- a/drivers/input/mouse/logips2pp.c
+++ b/drivers/input/mouse/logips2pp.c
@@ -40,7 +40,7 @@ struct ps2pp_info {
40 40
41static psmouse_ret_t ps2pp_process_byte(struct psmouse *psmouse, struct pt_regs *regs) 41static psmouse_ret_t ps2pp_process_byte(struct psmouse *psmouse, struct pt_regs *regs)
42{ 42{
43 struct input_dev *dev = &psmouse->dev; 43 struct input_dev *dev = psmouse->dev;
44 unsigned char *packet = psmouse->packet; 44 unsigned char *packet = psmouse->packet;
45 45
46 if (psmouse->pktcnt < 3) 46 if (psmouse->pktcnt < 3)
@@ -257,25 +257,27 @@ static struct ps2pp_info *get_model_info(unsigned char model)
257static void ps2pp_set_model_properties(struct psmouse *psmouse, struct ps2pp_info *model_info, 257static void ps2pp_set_model_properties(struct psmouse *psmouse, struct ps2pp_info *model_info,
258 int using_ps2pp) 258 int using_ps2pp)
259{ 259{
260 struct input_dev *input_dev = psmouse->dev;
261
260 if (model_info->features & PS2PP_SIDE_BTN) 262 if (model_info->features & PS2PP_SIDE_BTN)
261 set_bit(BTN_SIDE, psmouse->dev.keybit); 263 set_bit(BTN_SIDE, input_dev->keybit);
262 264
263 if (model_info->features & PS2PP_EXTRA_BTN) 265 if (model_info->features & PS2PP_EXTRA_BTN)
264 set_bit(BTN_EXTRA, psmouse->dev.keybit); 266 set_bit(BTN_EXTRA, input_dev->keybit);
265 267
266 if (model_info->features & PS2PP_TASK_BTN) 268 if (model_info->features & PS2PP_TASK_BTN)
267 set_bit(BTN_TASK, psmouse->dev.keybit); 269 set_bit(BTN_TASK, input_dev->keybit);
268 270
269 if (model_info->features & PS2PP_NAV_BTN) { 271 if (model_info->features & PS2PP_NAV_BTN) {
270 set_bit(BTN_FORWARD, psmouse->dev.keybit); 272 set_bit(BTN_FORWARD, input_dev->keybit);
271 set_bit(BTN_BACK, psmouse->dev.keybit); 273 set_bit(BTN_BACK, input_dev->keybit);
272 } 274 }
273 275
274 if (model_info->features & PS2PP_WHEEL) 276 if (model_info->features & PS2PP_WHEEL)
275 set_bit(REL_WHEEL, psmouse->dev.relbit); 277 set_bit(REL_WHEEL, input_dev->relbit);
276 278
277 if (model_info->features & PS2PP_HWHEEL) 279 if (model_info->features & PS2PP_HWHEEL)
278 set_bit(REL_HWHEEL, psmouse->dev.relbit); 280 set_bit(REL_HWHEEL, input_dev->relbit);
279 281
280 switch (model_info->kind) { 282 switch (model_info->kind) {
281 case PS2PP_KIND_WHEEL: 283 case PS2PP_KIND_WHEEL:
@@ -387,7 +389,7 @@ int ps2pp_init(struct psmouse *psmouse, int set_properties)
387 } 389 }
388 390
389 if (buttons < 3) 391 if (buttons < 3)
390 clear_bit(BTN_MIDDLE, psmouse->dev.keybit); 392 clear_bit(BTN_MIDDLE, psmouse->dev->keybit);
391 393
392 if (model_info) 394 if (model_info)
393 ps2pp_set_model_properties(psmouse, model_info, use_ps2pp); 395 ps2pp_set_model_properties(psmouse, model_info, use_ps2pp);
diff --git a/drivers/input/mouse/maplemouse.c b/drivers/input/mouse/maplemouse.c
index e90c60cbbf05..b5b34fe4fee8 100644
--- a/drivers/input/mouse/maplemouse.c
+++ b/drivers/input/mouse/maplemouse.c
@@ -41,13 +41,12 @@ static int dc_mouse_connect(struct maple_device *dev)
41 unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]); 41 unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]);
42 struct input_dev *input_dev; 42 struct input_dev *input_dev;
43 43
44 if (!(input_dev = kmalloc(sizeof(struct input_dev), GFP_KERNEL))) 44 dev->private_data = input_dev = input_allocate_device();
45 return -1; 45 if (!input_dev)
46 return -ENOMEM;
46 47
47 dev->private_data = input_dev; 48 dev->private_data = input_dev;
48 49
49 memset(input_dev, 0, sizeof(struct dc_mouse));
50 init_input_dev(input_dev);
51 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL); 50 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
52 input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); 51 input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
53 input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL); 52 input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL);
@@ -59,8 +58,6 @@ static int dc_mouse_connect(struct maple_device *dev)
59 58
60 maple_getcond_callback(dev, dc_mouse_callback, 1, MAPLE_FUNC_MOUSE); 59 maple_getcond_callback(dev, dc_mouse_callback, 1, MAPLE_FUNC_MOUSE);
61 60
62 printk(KERN_INFO "input: mouse(0x%lx): %s\n", data, input_dev->name);
63
64 return 0; 61 return 0;
65} 62}
66 63
@@ -70,7 +67,6 @@ static void dc_mouse_disconnect(struct maple_device *dev)
70 struct input_dev *input_dev = dev->private_data; 67 struct input_dev *input_dev = dev->private_data;
71 68
72 input_unregister_device(input_dev); 69 input_unregister_device(input_dev);
73 kfree(input_dev);
74} 70}
75 71
76 72
diff --git a/drivers/input/mouse/pc110pad.c b/drivers/input/mouse/pc110pad.c
index 93393d5c0078..d284ea712151 100644
--- a/drivers/input/mouse/pc110pad.c
+++ b/drivers/input/mouse/pc110pad.c
@@ -53,13 +53,10 @@ MODULE_LICENSE("GPL");
53static int pc110pad_irq = 10; 53static int pc110pad_irq = 10;
54static int pc110pad_io = 0x15e0; 54static int pc110pad_io = 0x15e0;
55 55
56static struct input_dev pc110pad_dev; 56static struct input_dev *pc110pad_dev;
57static int pc110pad_data[3]; 57static int pc110pad_data[3];
58static int pc110pad_count; 58static int pc110pad_count;
59 59
60static char *pc110pad_name = "IBM PC110 TouchPad";
61static char *pc110pad_phys = "isa15e0/input0";
62
63static irqreturn_t pc110pad_interrupt(int irq, void *ptr, struct pt_regs *regs) 60static irqreturn_t pc110pad_interrupt(int irq, void *ptr, struct pt_regs *regs)
64{ 61{
65 int value = inb_p(pc110pad_io); 62 int value = inb_p(pc110pad_io);
@@ -74,14 +71,14 @@ static irqreturn_t pc110pad_interrupt(int irq, void *ptr, struct pt_regs *regs)
74 if (pc110pad_count < 3) 71 if (pc110pad_count < 3)
75 return IRQ_HANDLED; 72 return IRQ_HANDLED;
76 73
77 input_regs(&pc110pad_dev, regs); 74 input_regs(pc110pad_dev, regs);
78 input_report_key(&pc110pad_dev, BTN_TOUCH, 75 input_report_key(pc110pad_dev, BTN_TOUCH,
79 pc110pad_data[0] & 0x01); 76 pc110pad_data[0] & 0x01);
80 input_report_abs(&pc110pad_dev, ABS_X, 77 input_report_abs(pc110pad_dev, ABS_X,
81 pc110pad_data[1] | ((pc110pad_data[0] << 3) & 0x80) | ((pc110pad_data[0] << 1) & 0x100)); 78 pc110pad_data[1] | ((pc110pad_data[0] << 3) & 0x80) | ((pc110pad_data[0] << 1) & 0x100));
82 input_report_abs(&pc110pad_dev, ABS_Y, 79 input_report_abs(pc110pad_dev, ABS_Y,
83 pc110pad_data[2] | ((pc110pad_data[0] << 4) & 0x80)); 80 pc110pad_data[2] | ((pc110pad_data[0] << 4) & 0x80));
84 input_sync(&pc110pad_dev); 81 input_sync(pc110pad_dev);
85 82
86 pc110pad_count = 0; 83 pc110pad_count = 0;
87 return IRQ_HANDLED; 84 return IRQ_HANDLED;
@@ -94,9 +91,9 @@ static void pc110pad_close(struct input_dev *dev)
94 91
95static int pc110pad_open(struct input_dev *dev) 92static int pc110pad_open(struct input_dev *dev)
96{ 93{
97 pc110pad_interrupt(0,NULL,NULL); 94 pc110pad_interrupt(0, NULL, NULL);
98 pc110pad_interrupt(0,NULL,NULL); 95 pc110pad_interrupt(0, NULL, NULL);
99 pc110pad_interrupt(0,NULL,NULL); 96 pc110pad_interrupt(0, NULL, NULL);
100 outb(PC110PAD_ON, pc110pad_io + 2); 97 outb(PC110PAD_ON, pc110pad_io + 2);
101 pc110pad_count = 0; 98 pc110pad_count = 0;
102 99
@@ -127,45 +124,46 @@ static int __init pc110pad_init(void)
127 124
128 outb(PC110PAD_OFF, pc110pad_io + 2); 125 outb(PC110PAD_OFF, pc110pad_io + 2);
129 126
130 if (request_irq(pc110pad_irq, pc110pad_interrupt, 0, "pc110pad", NULL)) 127 if (request_irq(pc110pad_irq, pc110pad_interrupt, 0, "pc110pad", NULL)) {
131 {
132 release_region(pc110pad_io, 4); 128 release_region(pc110pad_io, 4);
133 printk(KERN_ERR "pc110pad: Unable to get irq %d.\n", pc110pad_irq); 129 printk(KERN_ERR "pc110pad: Unable to get irq %d.\n", pc110pad_irq);
134 return -EBUSY; 130 return -EBUSY;
135 } 131 }
136 132
137 pc110pad_dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 133 if (!(pc110pad_dev = input_allocate_device())) {
138 pc110pad_dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y); 134 free_irq(pc110pad_irq, NULL);
139 pc110pad_dev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); 135 release_region(pc110pad_io, 4);
136 printk(KERN_ERR "pc110pad: Not enough memory.\n");
137 return -ENOMEM;
138 }
140 139
141 pc110pad_dev.absmax[ABS_X] = 0x1ff; 140 pc110pad_dev->name = "IBM PC110 TouchPad";
142 pc110pad_dev.absmax[ABS_Y] = 0x0ff; 141 pc110pad_dev->phys = "isa15e0/input0";
142 pc110pad_dev->id.bustype = BUS_ISA;
143 pc110pad_dev->id.vendor = 0x0003;
144 pc110pad_dev->id.product = 0x0001;
145 pc110pad_dev->id.version = 0x0100;
143 146
144 pc110pad_dev.open = pc110pad_open; 147 pc110pad_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
145 pc110pad_dev.close = pc110pad_close; 148 pc110pad_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
149 pc110pad_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
146 150
147 pc110pad_dev.name = pc110pad_name; 151 pc110pad_dev->absmax[ABS_X] = 0x1ff;
148 pc110pad_dev.phys = pc110pad_phys; 152 pc110pad_dev->absmax[ABS_Y] = 0x0ff;
149 pc110pad_dev.id.bustype = BUS_ISA;
150 pc110pad_dev.id.vendor = 0x0003;
151 pc110pad_dev.id.product = 0x0001;
152 pc110pad_dev.id.version = 0x0100;
153 153
154 input_register_device(&pc110pad_dev); 154 pc110pad_dev->open = pc110pad_open;
155 pc110pad_dev->close = pc110pad_close;
155 156
156 printk(KERN_INFO "input: %s at %#x irq %d\n", 157 input_register_device(pc110pad_dev);
157 pc110pad_name, pc110pad_io, pc110pad_irq);
158 158
159 return 0; 159 return 0;
160} 160}
161 161
162static void __exit pc110pad_exit(void) 162static void __exit pc110pad_exit(void)
163{ 163{
164 input_unregister_device(&pc110pad_dev);
165
166 outb(PC110PAD_OFF, pc110pad_io + 2); 164 outb(PC110PAD_OFF, pc110pad_io + 2);
167
168 free_irq(pc110pad_irq, NULL); 165 free_irq(pc110pad_irq, NULL);
166 input_unregister_device(pc110pad_dev);
169 release_region(pc110pad_io, 4); 167 release_region(pc110pad_io, 4);
170} 168}
171 169
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index af24313ff5bb..6ee9999a2eaa 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -114,7 +114,7 @@ struct psmouse_protocol {
114 114
115static psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse, struct pt_regs *regs) 115static psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse, struct pt_regs *regs)
116{ 116{
117 struct input_dev *dev = &psmouse->dev; 117 struct input_dev *dev = psmouse->dev;
118 unsigned char *packet = psmouse->packet; 118 unsigned char *packet = psmouse->packet;
119 119
120 if (psmouse->pktcnt < psmouse->pktsize) 120 if (psmouse->pktcnt < psmouse->pktsize)
@@ -333,12 +333,11 @@ static int genius_detect(struct psmouse *psmouse, int set_properties)
333 return -1; 333 return -1;
334 334
335 if (set_properties) { 335 if (set_properties) {
336 set_bit(BTN_EXTRA, psmouse->dev.keybit); 336 set_bit(BTN_EXTRA, psmouse->dev->keybit);
337 set_bit(BTN_SIDE, psmouse->dev.keybit); 337 set_bit(BTN_SIDE, psmouse->dev->keybit);
338 set_bit(REL_WHEEL, psmouse->dev.relbit); 338 set_bit(REL_WHEEL, psmouse->dev->relbit);
339 339
340 psmouse->vendor = "Genius"; 340 psmouse->vendor = "Genius";
341 psmouse->name = "Wheel Mouse";
342 psmouse->pktsize = 4; 341 psmouse->pktsize = 4;
343 } 342 }
344 343
@@ -365,8 +364,8 @@ static int intellimouse_detect(struct psmouse *psmouse, int set_properties)
365 return -1; 364 return -1;
366 365
367 if (set_properties) { 366 if (set_properties) {
368 set_bit(BTN_MIDDLE, psmouse->dev.keybit); 367 set_bit(BTN_MIDDLE, psmouse->dev->keybit);
369 set_bit(REL_WHEEL, psmouse->dev.relbit); 368 set_bit(REL_WHEEL, psmouse->dev->relbit);
370 369
371 if (!psmouse->vendor) psmouse->vendor = "Generic"; 370 if (!psmouse->vendor) psmouse->vendor = "Generic";
372 if (!psmouse->name) psmouse->name = "Wheel Mouse"; 371 if (!psmouse->name) psmouse->name = "Wheel Mouse";
@@ -398,10 +397,10 @@ static int im_explorer_detect(struct psmouse *psmouse, int set_properties)
398 return -1; 397 return -1;
399 398
400 if (set_properties) { 399 if (set_properties) {
401 set_bit(BTN_MIDDLE, psmouse->dev.keybit); 400 set_bit(BTN_MIDDLE, psmouse->dev->keybit);
402 set_bit(REL_WHEEL, psmouse->dev.relbit); 401 set_bit(REL_WHEEL, psmouse->dev->relbit);
403 set_bit(BTN_SIDE, psmouse->dev.keybit); 402 set_bit(BTN_SIDE, psmouse->dev->keybit);
404 set_bit(BTN_EXTRA, psmouse->dev.keybit); 403 set_bit(BTN_EXTRA, psmouse->dev->keybit);
405 404
406 if (!psmouse->vendor) psmouse->vendor = "Generic"; 405 if (!psmouse->vendor) psmouse->vendor = "Generic";
407 if (!psmouse->name) psmouse->name = "Explorer Mouse"; 406 if (!psmouse->name) psmouse->name = "Explorer Mouse";
@@ -433,7 +432,7 @@ static int thinking_detect(struct psmouse *psmouse, int set_properties)
433 return -1; 432 return -1;
434 433
435 if (set_properties) { 434 if (set_properties) {
436 set_bit(BTN_EXTRA, psmouse->dev.keybit); 435 set_bit(BTN_EXTRA, psmouse->dev->keybit);
437 436
438 psmouse->vendor = "Kensington"; 437 psmouse->vendor = "Kensington";
439 psmouse->name = "ThinkingMouse"; 438 psmouse->name = "ThinkingMouse";
@@ -839,9 +838,9 @@ static void psmouse_disconnect(struct serio *serio)
839 838
840 psmouse_set_state(psmouse, PSMOUSE_IGNORE); 839 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
841 840
842 input_unregister_device(&psmouse->dev);
843 serio_close(serio); 841 serio_close(serio);
844 serio_set_drvdata(serio, NULL); 842 serio_set_drvdata(serio, NULL);
843 input_unregister_device(psmouse->dev);
845 kfree(psmouse); 844 kfree(psmouse);
846 845
847 if (parent) 846 if (parent)
@@ -852,16 +851,14 @@ static void psmouse_disconnect(struct serio *serio)
852 851
853static int psmouse_switch_protocol(struct psmouse *psmouse, struct psmouse_protocol *proto) 852static int psmouse_switch_protocol(struct psmouse *psmouse, struct psmouse_protocol *proto)
854{ 853{
855 memset(&psmouse->dev, 0, sizeof(struct input_dev)); 854 struct input_dev *input_dev = psmouse->dev;
856 855
857 init_input_dev(&psmouse->dev); 856 input_dev->private = psmouse;
857 input_dev->cdev.dev = &psmouse->ps2dev.serio->dev;
858 858
859 psmouse->dev.private = psmouse; 859 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
860 psmouse->dev.dev = &psmouse->ps2dev.serio->dev; 860 input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
861 861 input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
862 psmouse->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
863 psmouse->dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
864 psmouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y);
865 862
866 psmouse->set_rate = psmouse_set_rate; 863 psmouse->set_rate = psmouse_set_rate;
867 psmouse->set_resolution = psmouse_set_resolution; 864 psmouse->set_resolution = psmouse_set_resolution;
@@ -883,12 +880,12 @@ static int psmouse_switch_protocol(struct psmouse *psmouse, struct psmouse_proto
883 sprintf(psmouse->devname, "%s %s %s", 880 sprintf(psmouse->devname, "%s %s %s",
884 psmouse_protocol_by_type(psmouse->type)->name, psmouse->vendor, psmouse->name); 881 psmouse_protocol_by_type(psmouse->type)->name, psmouse->vendor, psmouse->name);
885 882
886 psmouse->dev.name = psmouse->devname; 883 input_dev->name = psmouse->devname;
887 psmouse->dev.phys = psmouse->phys; 884 input_dev->phys = psmouse->phys;
888 psmouse->dev.id.bustype = BUS_I8042; 885 input_dev->id.bustype = BUS_I8042;
889 psmouse->dev.id.vendor = 0x0002; 886 input_dev->id.vendor = 0x0002;
890 psmouse->dev.id.product = psmouse->type; 887 input_dev->id.product = psmouse->type;
891 psmouse->dev.id.version = psmouse->model; 888 input_dev->id.version = psmouse->model;
892 889
893 return 0; 890 return 0;
894} 891}
@@ -900,7 +897,8 @@ static int psmouse_switch_protocol(struct psmouse *psmouse, struct psmouse_proto
900static int psmouse_connect(struct serio *serio, struct serio_driver *drv) 897static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
901{ 898{
902 struct psmouse *psmouse, *parent = NULL; 899 struct psmouse *psmouse, *parent = NULL;
903 int retval; 900 struct input_dev *input_dev;
901 int retval = -ENOMEM;
904 902
905 down(&psmouse_sem); 903 down(&psmouse_sem);
906 904
@@ -913,12 +911,13 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
913 psmouse_deactivate(parent); 911 psmouse_deactivate(parent);
914 } 912 }
915 913
916 if (!(psmouse = kzalloc(sizeof(struct psmouse), GFP_KERNEL))) { 914 psmouse = kzalloc(sizeof(struct psmouse), GFP_KERNEL);
917 retval = -ENOMEM; 915 input_dev = input_allocate_device();
916 if (!psmouse || !input_dev)
918 goto out; 917 goto out;
919 }
920 918
921 ps2_init(&psmouse->ps2dev, serio); 919 ps2_init(&psmouse->ps2dev, serio);
920 psmouse->dev = input_dev;
922 sprintf(psmouse->phys, "%s/input0", serio->phys); 921 sprintf(psmouse->phys, "%s/input0", serio->phys);
923 922
924 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING); 923 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
@@ -926,16 +925,11 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
926 serio_set_drvdata(serio, psmouse); 925 serio_set_drvdata(serio, psmouse);
927 926
928 retval = serio_open(serio, drv); 927 retval = serio_open(serio, drv);
929 if (retval) { 928 if (retval)
930 serio_set_drvdata(serio, NULL);
931 kfree(psmouse);
932 goto out; 929 goto out;
933 }
934 930
935 if (psmouse_probe(psmouse) < 0) { 931 if (psmouse_probe(psmouse) < 0) {
936 serio_close(serio); 932 serio_close(serio);
937 serio_set_drvdata(serio, NULL);
938 kfree(psmouse);
939 retval = -ENODEV; 933 retval = -ENODEV;
940 goto out; 934 goto out;
941 } 935 }
@@ -947,13 +941,11 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
947 941
948 psmouse_switch_protocol(psmouse, NULL); 942 psmouse_switch_protocol(psmouse, NULL);
949 943
950 input_register_device(&psmouse->dev);
951 printk(KERN_INFO "input: %s on %s\n", psmouse->devname, serio->phys);
952
953 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); 944 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
954
955 psmouse_initialize(psmouse); 945 psmouse_initialize(psmouse);
956 946
947 input_register_device(psmouse->dev);
948
957 if (parent && parent->pt_activate) 949 if (parent && parent->pt_activate)
958 parent->pt_activate(parent); 950 parent->pt_activate(parent);
959 951
@@ -964,6 +956,12 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
964 retval = 0; 956 retval = 0;
965 957
966out: 958out:
959 if (retval) {
960 serio_set_drvdata(serio, NULL);
961 input_free_device(input_dev);
962 kfree(psmouse);
963 }
964
967 /* If this is a pass-through port the parent needs to be re-activated */ 965 /* If this is a pass-through port the parent needs to be re-activated */
968 if (parent) 966 if (parent)
969 psmouse_activate(parent); 967 psmouse_activate(parent);
@@ -1161,6 +1159,7 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
1161{ 1159{
1162 struct serio *serio = psmouse->ps2dev.serio; 1160 struct serio *serio = psmouse->ps2dev.serio;
1163 struct psmouse *parent = NULL; 1161 struct psmouse *parent = NULL;
1162 struct input_dev *new_dev;
1164 struct psmouse_protocol *proto; 1163 struct psmouse_protocol *proto;
1165 int retry = 0; 1164 int retry = 0;
1166 1165
@@ -1170,9 +1169,13 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
1170 if (psmouse->type == proto->type) 1169 if (psmouse->type == proto->type)
1171 return count; 1170 return count;
1172 1171
1172 if (!(new_dev = input_allocate_device()))
1173 return -ENOMEM;
1174
1173 while (serio->child) { 1175 while (serio->child) {
1174 if (++retry > 3) { 1176 if (++retry > 3) {
1175 printk(KERN_WARNING "psmouse: failed to destroy child port, protocol change aborted.\n"); 1177 printk(KERN_WARNING "psmouse: failed to destroy child port, protocol change aborted.\n");
1178 input_free_device(new_dev);
1176 return -EIO; 1179 return -EIO;
1177 } 1180 }
1178 1181
@@ -1182,11 +1185,15 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
1182 serio_pin_driver_uninterruptible(serio); 1185 serio_pin_driver_uninterruptible(serio);
1183 down(&psmouse_sem); 1186 down(&psmouse_sem);
1184 1187
1185 if (serio->drv != &psmouse_drv) 1188 if (serio->drv != &psmouse_drv) {
1189 input_free_device(new_dev);
1186 return -ENODEV; 1190 return -ENODEV;
1191 }
1187 1192
1188 if (psmouse->type == proto->type) 1193 if (psmouse->type == proto->type) {
1194 input_free_device(new_dev);
1189 return count; /* switched by other thread */ 1195 return count; /* switched by other thread */
1196 }
1190 } 1197 }
1191 1198
1192 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { 1199 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
@@ -1199,8 +1206,9 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
1199 psmouse->disconnect(psmouse); 1206 psmouse->disconnect(psmouse);
1200 1207
1201 psmouse_set_state(psmouse, PSMOUSE_IGNORE); 1208 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
1202 input_unregister_device(&psmouse->dev); 1209 input_unregister_device(psmouse->dev);
1203 1210
1211 psmouse->dev = new_dev;
1204 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING); 1212 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
1205 1213
1206 if (psmouse_switch_protocol(psmouse, proto) < 0) { 1214 if (psmouse_switch_protocol(psmouse, proto) < 0) {
@@ -1212,8 +1220,7 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
1212 psmouse_initialize(psmouse); 1220 psmouse_initialize(psmouse);
1213 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); 1221 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
1214 1222
1215 input_register_device(&psmouse->dev); 1223 input_register_device(psmouse->dev);
1216 printk(KERN_INFO "input: %s on %s\n", psmouse->devname, serio->phys);
1217 1224
1218 if (parent && parent->pt_activate) 1225 if (parent && parent->pt_activate)
1219 parent->pt_activate(parent); 1226 parent->pt_activate(parent);
diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
index 45d2bd774f00..7c4192bd1279 100644
--- a/drivers/input/mouse/psmouse.h
+++ b/drivers/input/mouse/psmouse.h
@@ -36,7 +36,7 @@ typedef enum {
36 36
37struct psmouse { 37struct psmouse {
38 void *private; 38 void *private;
39 struct input_dev dev; 39 struct input_dev *dev;
40 struct ps2dev ps2dev; 40 struct ps2dev ps2dev;
41 char *vendor; 41 char *vendor;
42 char *name; 42 char *name;
diff --git a/drivers/input/mouse/rpcmouse.c b/drivers/input/mouse/rpcmouse.c
index 8fe1212b8fd7..09b6ffdb7582 100644
--- a/drivers/input/mouse/rpcmouse.c
+++ b/drivers/input/mouse/rpcmouse.c
@@ -34,20 +34,7 @@ MODULE_DESCRIPTION("Acorn RiscPC mouse driver");
34MODULE_LICENSE("GPL"); 34MODULE_LICENSE("GPL");
35 35
36static short rpcmouse_lastx, rpcmouse_lasty; 36static short rpcmouse_lastx, rpcmouse_lasty;
37 37static struct input_dev *rpcmouse_dev;
38static struct input_dev rpcmouse_dev = {
39 .evbit = { BIT(EV_KEY) | BIT(EV_REL) },
40 .keybit = { [LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT) },
41 .relbit = { BIT(REL_X) | BIT(REL_Y) },
42 .name = "Acorn RiscPC Mouse",
43 .phys = "rpcmouse/input0",
44 .id = {
45 .bustype = BUS_HOST,
46 .vendor = 0x0005,
47 .product = 0x0001,
48 .version = 0x0100,
49 },
50};
51 38
52static irqreturn_t rpcmouse_irq(int irq, void *dev_id, struct pt_regs *regs) 39static irqreturn_t rpcmouse_irq(int irq, void *dev_id, struct pt_regs *regs)
53{ 40{
@@ -78,29 +65,41 @@ static irqreturn_t rpcmouse_irq(int irq, void *dev_id, struct pt_regs *regs)
78 return IRQ_HANDLED; 65 return IRQ_HANDLED;
79} 66}
80 67
68
81static int __init rpcmouse_init(void) 69static int __init rpcmouse_init(void)
82{ 70{
83 init_input_dev(&rpcmouse_dev); 71 if (!(rpcmouse_dev = input_allocate_device()))
72 return -ENOMEM;
73
74 rpcmouse_dev->name = "Acorn RiscPC Mouse";
75 rpcmouse_dev->phys = "rpcmouse/input0";
76 rpcmouse_dev->id.bustype = BUS_HOST;
77 rpcmouse_dev->id.vendor = 0x0005;
78 rpcmouse_dev->id.product = 0x0001;
79 rpcmouse_dev->id.version = 0x0100;
80
81 rpcmouse_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
82 rpcmouse_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
83 rpcmouse_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
84 84
85 rpcmouse_lastx = (short) iomd_readl(IOMD_MOUSEX); 85 rpcmouse_lastx = (short) iomd_readl(IOMD_MOUSEX);
86 rpcmouse_lasty = (short) iomd_readl(IOMD_MOUSEY); 86 rpcmouse_lasty = (short) iomd_readl(IOMD_MOUSEY);
87 87
88 if (request_irq(IRQ_VSYNCPULSE, rpcmouse_irq, SA_SHIRQ, "rpcmouse", &rpcmouse_dev)) { 88 if (request_irq(IRQ_VSYNCPULSE, rpcmouse_irq, SA_SHIRQ, "rpcmouse", rpcmouse_dev)) {
89 printk(KERN_ERR "rpcmouse: unable to allocate VSYNC interrupt\n"); 89 printk(KERN_ERR "rpcmouse: unable to allocate VSYNC interrupt\n");
90 return -1; 90 input_free_device(rpcmouse_dev);
91 return -EBUSY;
91 } 92 }
92 93
93 input_register_device(&rpcmouse_dev); 94 input_register_device(rpcmouse_dev);
94
95 printk(KERN_INFO "input: Acorn RiscPC mouse\n");
96 95
97 return 0; 96 return 0;
98} 97}
99 98
100static void __exit rpcmouse_exit(void) 99static void __exit rpcmouse_exit(void)
101{ 100{
102 input_unregister_device(&rpcmouse_dev); 101 free_irq(IRQ_VSYNCPULSE, rpcmouse_dev);
103 free_irq(IRQ_VSYNCPULSE, &rpcmouse_dev); 102 input_unregister_device(rpcmouse_dev);
104} 103}
105 104
106module_init(rpcmouse_init); 105module_init(rpcmouse_init);
diff --git a/drivers/input/mouse/sermouse.c b/drivers/input/mouse/sermouse.c
index d12b93ae3900..4bf584364d28 100644
--- a/drivers/input/mouse/sermouse.c
+++ b/drivers/input/mouse/sermouse.c
@@ -48,7 +48,7 @@ static char *sermouse_protocols[] = { "None", "Mouse Systems Mouse", "Sun Mouse"
48 "Logitech MZ++ Mouse"}; 48 "Logitech MZ++ Mouse"};
49 49
50struct sermouse { 50struct sermouse {
51 struct input_dev dev; 51 struct input_dev *dev;
52 signed char buf[8]; 52 signed char buf[8];
53 unsigned char count; 53 unsigned char count;
54 unsigned char type; 54 unsigned char type;
@@ -64,7 +64,7 @@ struct sermouse {
64 64
65static void sermouse_process_msc(struct sermouse *sermouse, signed char data, struct pt_regs *regs) 65static void sermouse_process_msc(struct sermouse *sermouse, signed char data, struct pt_regs *regs)
66{ 66{
67 struct input_dev *dev = &sermouse->dev; 67 struct input_dev *dev = sermouse->dev;
68 signed char *buf = sermouse->buf; 68 signed char *buf = sermouse->buf;
69 69
70 input_regs(dev, regs); 70 input_regs(dev, regs);
@@ -107,7 +107,7 @@ static void sermouse_process_msc(struct sermouse *sermouse, signed char data, st
107 107
108static void sermouse_process_ms(struct sermouse *sermouse, signed char data, struct pt_regs *regs) 108static void sermouse_process_ms(struct sermouse *sermouse, signed char data, struct pt_regs *regs)
109{ 109{
110 struct input_dev *dev = &sermouse->dev; 110 struct input_dev *dev = sermouse->dev;
111 signed char *buf = sermouse->buf; 111 signed char *buf = sermouse->buf;
112 112
113 if (data & 0x40) sermouse->count = 0; 113 if (data & 0x40) sermouse->count = 0;
@@ -230,9 +230,9 @@ static void sermouse_disconnect(struct serio *serio)
230{ 230{
231 struct sermouse *sermouse = serio_get_drvdata(serio); 231 struct sermouse *sermouse = serio_get_drvdata(serio);
232 232
233 input_unregister_device(&sermouse->dev);
234 serio_close(serio); 233 serio_close(serio);
235 serio_set_drvdata(serio, NULL); 234 serio_set_drvdata(serio, NULL);
235 input_unregister_device(sermouse->dev);
236 kfree(sermouse); 236 kfree(sermouse);
237} 237}
238 238
@@ -244,56 +244,52 @@ static void sermouse_disconnect(struct serio *serio)
244static int sermouse_connect(struct serio *serio, struct serio_driver *drv) 244static int sermouse_connect(struct serio *serio, struct serio_driver *drv)
245{ 245{
246 struct sermouse *sermouse; 246 struct sermouse *sermouse;
247 unsigned char c; 247 struct input_dev *input_dev;
248 int err; 248 unsigned char c = serio->id.extra;
249 int err = -ENOMEM;
249 250
250 if (!serio->id.proto || serio->id.proto > SERIO_MZPP) 251 sermouse = kzalloc(sizeof(struct sermouse), GFP_KERNEL);
251 return -ENODEV; 252 input_dev = input_allocate_device();
252 253 if (!sermouse || !input_dev)
253 if (!(sermouse = kmalloc(sizeof(struct sermouse), GFP_KERNEL))) 254 goto fail;
254 return -ENOMEM;
255
256 memset(sermouse, 0, sizeof(struct sermouse));
257
258 init_input_dev(&sermouse->dev);
259 sermouse->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
260 sermouse->dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT);
261 sermouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y);
262 sermouse->dev.private = sermouse;
263
264 sermouse->type = serio->id.proto;
265 c = serio->id.extra;
266
267 if (c & 0x01) set_bit(BTN_MIDDLE, sermouse->dev.keybit);
268 if (c & 0x02) set_bit(BTN_SIDE, sermouse->dev.keybit);
269 if (c & 0x04) set_bit(BTN_EXTRA, sermouse->dev.keybit);
270 if (c & 0x10) set_bit(REL_WHEEL, sermouse->dev.relbit);
271 if (c & 0x20) set_bit(REL_HWHEEL, sermouse->dev.relbit);
272 255
256 sermouse->dev = input_dev;
273 sprintf(sermouse->phys, "%s/input0", serio->phys); 257 sprintf(sermouse->phys, "%s/input0", serio->phys);
258 sermouse->type = serio->id.proto;
274 259
275 sermouse->dev.name = sermouse_protocols[sermouse->type]; 260 input_dev->name = sermouse_protocols[sermouse->type];
276 sermouse->dev.phys = sermouse->phys; 261 input_dev->phys = sermouse->phys;
277 sermouse->dev.id.bustype = BUS_RS232; 262 input_dev->id.bustype = BUS_RS232;
278 sermouse->dev.id.vendor = sermouse->type; 263 input_dev->id.vendor = sermouse->type;
279 sermouse->dev.id.product = c; 264 input_dev->id.product = c;
280 sermouse->dev.id.version = 0x0100; 265 input_dev->id.version = 0x0100;
281 sermouse->dev.dev = &serio->dev; 266 input_dev->cdev.dev = &serio->dev;
267
268 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
269 input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT);
270 input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
271 input_dev->private = sermouse;
272
273 if (c & 0x01) set_bit(BTN_MIDDLE, input_dev->keybit);
274 if (c & 0x02) set_bit(BTN_SIDE, input_dev->keybit);
275 if (c & 0x04) set_bit(BTN_EXTRA, input_dev->keybit);
276 if (c & 0x10) set_bit(REL_WHEEL, input_dev->relbit);
277 if (c & 0x20) set_bit(REL_HWHEEL, input_dev->relbit);
282 278
283 serio_set_drvdata(serio, sermouse); 279 serio_set_drvdata(serio, sermouse);
284 280
285 err = serio_open(serio, drv); 281 err = serio_open(serio, drv);
286 if (err) { 282 if (err)
287 serio_set_drvdata(serio, NULL); 283 goto fail;
288 kfree(sermouse);
289 return err;
290 }
291
292 input_register_device(&sermouse->dev);
293 284
294 printk(KERN_INFO "input: %s on %s\n", sermouse_protocols[sermouse->type], serio->phys); 285 input_register_device(sermouse->dev);
295 286
296 return 0; 287 return 0;
288
289 fail: serio_set_drvdata(serio, NULL);
290 input_free_device(input_dev);
291 kfree(sermouse);
292 return err;
297} 293}
298 294
299static struct serio_device_id sermouse_serio_ids[] = { 295static struct serio_device_id sermouse_serio_ids[] = {
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index 029309422409..97cdfd6acaca 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -342,7 +342,7 @@ static void synaptics_parse_hw_state(unsigned char buf[], struct synaptics_data
342 */ 342 */
343static void synaptics_process_packet(struct psmouse *psmouse) 343static void synaptics_process_packet(struct psmouse *psmouse)
344{ 344{
345 struct input_dev *dev = &psmouse->dev; 345 struct input_dev *dev = psmouse->dev;
346 struct synaptics_data *priv = psmouse->private; 346 struct synaptics_data *priv = psmouse->private;
347 struct synaptics_hw_state hw; 347 struct synaptics_hw_state hw;
348 int num_fingers; 348 int num_fingers;
@@ -473,7 +473,7 @@ static unsigned char synaptics_detect_pkt_type(struct psmouse *psmouse)
473 473
474static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse, struct pt_regs *regs) 474static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse, struct pt_regs *regs)
475{ 475{
476 struct input_dev *dev = &psmouse->dev; 476 struct input_dev *dev = psmouse->dev;
477 struct synaptics_data *priv = psmouse->private; 477 struct synaptics_data *priv = psmouse->private;
478 478
479 input_regs(dev, regs); 479 input_regs(dev, regs);
@@ -645,7 +645,7 @@ int synaptics_init(struct psmouse *psmouse)
645 SYN_ID_MAJOR(priv->identity), SYN_ID_MINOR(priv->identity), 645 SYN_ID_MAJOR(priv->identity), SYN_ID_MINOR(priv->identity),
646 priv->model_id, priv->capabilities, priv->ext_cap); 646 priv->model_id, priv->capabilities, priv->ext_cap);
647 647
648 set_input_params(&psmouse->dev, priv); 648 set_input_params(psmouse->dev, priv);
649 649
650 psmouse->protocol_handler = synaptics_process_byte; 650 psmouse->protocol_handler = synaptics_process_byte;
651 psmouse->set_rate = synaptics_set_rate; 651 psmouse->set_rate = synaptics_set_rate;
diff --git a/drivers/input/mouse/vsxxxaa.c b/drivers/input/mouse/vsxxxaa.c
index f024be9b44d2..36e9442a16b2 100644
--- a/drivers/input/mouse/vsxxxaa.c
+++ b/drivers/input/mouse/vsxxxaa.c
@@ -112,7 +112,7 @@ MODULE_LICENSE ("GPL");
112 112
113 113
114struct vsxxxaa { 114struct vsxxxaa {
115 struct input_dev dev; 115 struct input_dev *dev;
116 struct serio *serio; 116 struct serio *serio;
117#define BUFLEN 15 /* At least 5 is needed for a full tablet packet */ 117#define BUFLEN 15 /* At least 5 is needed for a full tablet packet */
118 unsigned char buf[BUFLEN]; 118 unsigned char buf[BUFLEN];
@@ -211,7 +211,7 @@ vsxxxaa_smells_like_packet (struct vsxxxaa *mouse, unsigned char type, size_t le
211static void 211static void
212vsxxxaa_handle_REL_packet (struct vsxxxaa *mouse, struct pt_regs *regs) 212vsxxxaa_handle_REL_packet (struct vsxxxaa *mouse, struct pt_regs *regs)
213{ 213{
214 struct input_dev *dev = &mouse->dev; 214 struct input_dev *dev = mouse->dev;
215 unsigned char *buf = mouse->buf; 215 unsigned char *buf = mouse->buf;
216 int left, middle, right; 216 int left, middle, right;
217 int dx, dy; 217 int dx, dy;
@@ -269,7 +269,7 @@ vsxxxaa_handle_REL_packet (struct vsxxxaa *mouse, struct pt_regs *regs)
269static void 269static void
270vsxxxaa_handle_ABS_packet (struct vsxxxaa *mouse, struct pt_regs *regs) 270vsxxxaa_handle_ABS_packet (struct vsxxxaa *mouse, struct pt_regs *regs)
271{ 271{
272 struct input_dev *dev = &mouse->dev; 272 struct input_dev *dev = mouse->dev;
273 unsigned char *buf = mouse->buf; 273 unsigned char *buf = mouse->buf;
274 int left, middle, right, touch; 274 int left, middle, right, touch;
275 int x, y; 275 int x, y;
@@ -323,7 +323,7 @@ vsxxxaa_handle_ABS_packet (struct vsxxxaa *mouse, struct pt_regs *regs)
323static void 323static void
324vsxxxaa_handle_POR_packet (struct vsxxxaa *mouse, struct pt_regs *regs) 324vsxxxaa_handle_POR_packet (struct vsxxxaa *mouse, struct pt_regs *regs)
325{ 325{
326 struct input_dev *dev = &mouse->dev; 326 struct input_dev *dev = mouse->dev;
327 unsigned char *buf = mouse->buf; 327 unsigned char *buf = mouse->buf;
328 int left, middle, right; 328 int left, middle, right;
329 unsigned char error; 329 unsigned char error;
@@ -483,9 +483,9 @@ vsxxxaa_disconnect (struct serio *serio)
483{ 483{
484 struct vsxxxaa *mouse = serio_get_drvdata (serio); 484 struct vsxxxaa *mouse = serio_get_drvdata (serio);
485 485
486 input_unregister_device (&mouse->dev);
487 serio_close (serio); 486 serio_close (serio);
488 serio_set_drvdata (serio, NULL); 487 serio_set_drvdata (serio, NULL);
488 input_unregister_device (mouse->dev);
489 kfree (mouse); 489 kfree (mouse);
490} 490}
491 491
@@ -493,61 +493,57 @@ static int
493vsxxxaa_connect (struct serio *serio, struct serio_driver *drv) 493vsxxxaa_connect (struct serio *serio, struct serio_driver *drv)
494{ 494{
495 struct vsxxxaa *mouse; 495 struct vsxxxaa *mouse;
496 int err; 496 struct input_dev *input_dev;
497 int err = -ENOMEM;
497 498
498 if (!(mouse = kmalloc (sizeof (struct vsxxxaa), GFP_KERNEL))) 499 mouse = kzalloc (sizeof (struct vsxxxaa), GFP_KERNEL);
499 return -ENOMEM; 500 input_dev = input_allocate_device ();
500 501 if (!mouse || !input_dev)
501 memset (mouse, 0, sizeof (struct vsxxxaa)); 502 goto fail;
502
503 init_input_dev (&mouse->dev);
504 set_bit (EV_KEY, mouse->dev.evbit); /* We have buttons */
505 set_bit (EV_REL, mouse->dev.evbit);
506 set_bit (EV_ABS, mouse->dev.evbit);
507 set_bit (BTN_LEFT, mouse->dev.keybit); /* We have 3 buttons */
508 set_bit (BTN_MIDDLE, mouse->dev.keybit);
509 set_bit (BTN_RIGHT, mouse->dev.keybit);
510 set_bit (BTN_TOUCH, mouse->dev.keybit); /* ...and Tablet */
511 set_bit (REL_X, mouse->dev.relbit);
512 set_bit (REL_Y, mouse->dev.relbit);
513 set_bit (ABS_X, mouse->dev.absbit);
514 set_bit (ABS_Y, mouse->dev.absbit);
515
516 mouse->dev.absmin[ABS_X] = 0;
517 mouse->dev.absmax[ABS_X] = 1023;
518 mouse->dev.absmin[ABS_Y] = 0;
519 mouse->dev.absmax[ABS_Y] = 1023;
520
521 mouse->dev.private = mouse;
522 503
504 mouse->dev = input_dev;
505 mouse->serio = serio;
523 sprintf (mouse->name, "DEC VSXXX-AA/-GA mouse or VSXXX-AB digitizer"); 506 sprintf (mouse->name, "DEC VSXXX-AA/-GA mouse or VSXXX-AB digitizer");
524 sprintf (mouse->phys, "%s/input0", serio->phys); 507 sprintf (mouse->phys, "%s/input0", serio->phys);
525 mouse->dev.name = mouse->name; 508
526 mouse->dev.phys = mouse->phys; 509 input_dev->name = mouse->name;
527 mouse->dev.id.bustype = BUS_RS232; 510 input_dev->phys = mouse->phys;
528 mouse->dev.dev = &serio->dev; 511 input_dev->id.bustype = BUS_RS232;
529 mouse->serio = serio; 512 input_dev->cdev.dev = &serio->dev;
513 input_dev->private = mouse;
514
515 set_bit (EV_KEY, input_dev->evbit); /* We have buttons */
516 set_bit (EV_REL, input_dev->evbit);
517 set_bit (EV_ABS, input_dev->evbit);
518 set_bit (BTN_LEFT, input_dev->keybit); /* We have 3 buttons */
519 set_bit (BTN_MIDDLE, input_dev->keybit);
520 set_bit (BTN_RIGHT, input_dev->keybit);
521 set_bit (BTN_TOUCH, input_dev->keybit); /* ...and Tablet */
522 set_bit (REL_X, input_dev->relbit);
523 set_bit (REL_Y, input_dev->relbit);
524 input_set_abs_params (input_dev, ABS_X, 0, 1023, 0, 0);
525 input_set_abs_params (input_dev, ABS_Y, 0, 1023, 0, 0);
530 526
531 serio_set_drvdata (serio, mouse); 527 serio_set_drvdata (serio, mouse);
532 528
533 err = serio_open (serio, drv); 529 err = serio_open (serio, drv);
534 if (err) { 530 if (err)
535 serio_set_drvdata (serio, NULL); 531 goto fail;
536 kfree (mouse);
537 return err;
538 }
539 532
540 /* 533 /*
541 * Request selftest. Standard packet format and differential 534 * Request selftest. Standard packet format and differential
542 * mode will be requested after the device ID'ed successfully. 535 * mode will be requested after the device ID'ed successfully.
543 */ 536 */
544 mouse->serio->write (mouse->serio, 'T'); /* Test */ 537 serio->write (serio, 'T'); /* Test */
545
546 input_register_device (&mouse->dev);
547 538
548 printk (KERN_INFO "input: %s on %s\n", mouse->name, mouse->phys); 539 input_register_device (input_dev);
549 540
550 return 0; 541 return 0;
542
543 fail: serio_set_drvdata (serio, NULL);
544 input_free_device (input_dev);
545 kfree (mouse);
546 return err;
551} 547}
552 548
553static struct serio_device_id vsxxaa_serio_ids[] = { 549static struct serio_device_id vsxxaa_serio_ids[] = {
diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
index c6194a9dd174..2d0af44ac4b9 100644
--- a/drivers/input/mousedev.c
+++ b/drivers/input/mousedev.c
@@ -9,7 +9,7 @@
9 * the Free Software Foundation. 9 * the Free Software Foundation.
10 */ 10 */
11 11
12#define MOUSEDEV_MINOR_BASE 32 12#define MOUSEDEV_MINOR_BASE 32
13#define MOUSEDEV_MINORS 32 13#define MOUSEDEV_MINORS 32
14#define MOUSEDEV_MIX 31 14#define MOUSEDEV_MIX 31
15 15
@@ -24,7 +24,6 @@
24#include <linux/random.h> 24#include <linux/random.h>
25#include <linux/major.h> 25#include <linux/major.h>
26#include <linux/device.h> 26#include <linux/device.h>
27#include <linux/devfs_fs_kernel.h>
28#ifdef CONFIG_INPUT_MOUSEDEV_PSAUX 27#ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
29#include <linux/miscdevice.h> 28#include <linux/miscdevice.h>
30#endif 29#endif
@@ -621,6 +620,7 @@ static struct file_operations mousedev_fops = {
621static struct input_handle *mousedev_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id) 620static struct input_handle *mousedev_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id)
622{ 621{
623 struct mousedev *mousedev; 622 struct mousedev *mousedev;
623 struct class_device *cdev;
624 int minor = 0; 624 int minor = 0;
625 625
626 for (minor = 0; minor < MOUSEDEV_MINORS && mousedev_table[minor]; minor++); 626 for (minor = 0; minor < MOUSEDEV_MINORS && mousedev_table[minor]; minor++);
@@ -649,11 +649,13 @@ static struct input_handle *mousedev_connect(struct input_handler *handler, stru
649 649
650 mousedev_table[minor] = mousedev; 650 mousedev_table[minor] = mousedev;
651 651
652 devfs_mk_cdev(MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + minor), 652 cdev = class_device_create(&input_class, &dev->cdev,
653 S_IFCHR|S_IRUGO|S_IWUSR, "input/mouse%d", minor);
654 class_device_create(input_class,
655 MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + minor), 653 MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + minor),
656 dev->dev, "mouse%d", minor); 654 dev->cdev.dev, mousedev->name);
655
656 /* temporary symlink to keep userspace happy */
657 sysfs_create_link(&input_class.subsys.kset.kobj, &cdev->kobj,
658 mousedev->name);
657 659
658 return &mousedev->handle; 660 return &mousedev->handle;
659} 661}
@@ -663,9 +665,9 @@ static void mousedev_disconnect(struct input_handle *handle)
663 struct mousedev *mousedev = handle->private; 665 struct mousedev *mousedev = handle->private;
664 struct mousedev_list *list; 666 struct mousedev_list *list;
665 667
666 class_device_destroy(input_class, 668 sysfs_remove_link(&input_class.subsys.kset.kobj, mousedev->name);
669 class_device_destroy(&input_class,
667 MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + mousedev->minor)); 670 MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + mousedev->minor));
668 devfs_remove("input/mouse%d", mousedev->minor);
669 mousedev->exist = 0; 671 mousedev->exist = 0;
670 672
671 if (mousedev->open) { 673 if (mousedev->open) {
@@ -738,9 +740,7 @@ static int __init mousedev_init(void)
738 mousedev_mix.exist = 1; 740 mousedev_mix.exist = 1;
739 mousedev_mix.minor = MOUSEDEV_MIX; 741 mousedev_mix.minor = MOUSEDEV_MIX;
740 742
741 devfs_mk_cdev(MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + MOUSEDEV_MIX), 743 class_device_create(&input_class, NULL,
742 S_IFCHR|S_IRUGO|S_IWUSR, "input/mice");
743 class_device_create(input_class,
744 MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + MOUSEDEV_MIX), NULL, "mice"); 744 MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + MOUSEDEV_MIX), NULL, "mice");
745 745
746#ifdef CONFIG_INPUT_MOUSEDEV_PSAUX 746#ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
@@ -759,8 +759,7 @@ static void __exit mousedev_exit(void)
759 if (psaux_registered) 759 if (psaux_registered)
760 misc_deregister(&psaux_mouse); 760 misc_deregister(&psaux_mouse);
761#endif 761#endif
762 devfs_remove("input/mice"); 762 class_device_destroy(&input_class,
763 class_device_destroy(input_class,
764 MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + MOUSEDEV_MIX)); 763 MKDEV(INPUT_MAJOR, MOUSEDEV_MINOR_BASE + MOUSEDEV_MIX));
765 input_unregister_handler(&mousedev_handler); 764 input_unregister_handler(&mousedev_handler);
766} 765}
diff --git a/drivers/input/serio/gscps2.c b/drivers/input/serio/gscps2.c
index 897e4c12b642..a7b0de0f92b2 100644
--- a/drivers/input/serio/gscps2.c
+++ b/drivers/input/serio/gscps2.c
@@ -211,9 +211,6 @@ static void gscps2_reset(struct gscps2port *ps2port)
211 writeb(0xff, addr+GSC_RESET); 211 writeb(0xff, addr+GSC_RESET);
212 gscps2_flush(ps2port); 212 gscps2_flush(ps2port);
213 spin_unlock_irqrestore(&ps2port->lock, flags); 213 spin_unlock_irqrestore(&ps2port->lock, flags);
214
215 /* enable it */
216 gscps2_enable(ps2port, ENABLE);
217} 214}
218 215
219static LIST_HEAD(ps2port_list); 216static LIST_HEAD(ps2port_list);
@@ -307,6 +304,9 @@ static int gscps2_open(struct serio *port)
307 304
308 gscps2_reset(ps2port); 305 gscps2_reset(ps2port);
309 306
307 /* enable it */
308 gscps2_enable(ps2port, ENABLE);
309
310 gscps2_interrupt(0, NULL, NULL); 310 gscps2_interrupt(0, NULL, NULL);
311 311
312 return 0; 312 return 0;
@@ -331,7 +331,7 @@ static int __init gscps2_probe(struct parisc_device *dev)
331{ 331{
332 struct gscps2port *ps2port; 332 struct gscps2port *ps2port;
333 struct serio *serio; 333 struct serio *serio;
334 unsigned long hpa = dev->hpa; 334 unsigned long hpa = dev->hpa.start;
335 int ret; 335 int ret;
336 336
337 if (!dev->irq) 337 if (!dev->irq)
@@ -370,8 +370,6 @@ static int __init gscps2_probe(struct parisc_device *dev)
370 serio->port_data = ps2port; 370 serio->port_data = ps2port;
371 serio->dev.parent = &dev->dev; 371 serio->dev.parent = &dev->dev;
372 372
373 list_add_tail(&ps2port->node, &ps2port_list);
374
375 ret = -EBUSY; 373 ret = -EBUSY;
376 if (request_irq(dev->irq, gscps2_interrupt, SA_SHIRQ, ps2port->port->name, ps2port)) 374 if (request_irq(dev->irq, gscps2_interrupt, SA_SHIRQ, ps2port->port->name, ps2port))
377 goto fail_miserably; 375 goto fail_miserably;
@@ -396,15 +394,16 @@ static int __init gscps2_probe(struct parisc_device *dev)
396 394
397 serio_register_port(ps2port->port); 395 serio_register_port(ps2port->port);
398 396
397 list_add_tail(&ps2port->node, &ps2port_list);
398
399 return 0; 399 return 0;
400 400
401fail: 401fail:
402 free_irq(dev->irq, ps2port); 402 free_irq(dev->irq, ps2port);
403 403
404fail_miserably: 404fail_miserably:
405 list_del(&ps2port->node);
406 iounmap(ps2port->addr); 405 iounmap(ps2port->addr);
407 release_mem_region(dev->hpa, GSC_STATUS + 4); 406 release_mem_region(dev->hpa.start, GSC_STATUS + 4);
408 407
409fail_nomem: 408fail_nomem:
410 kfree(ps2port); 409 kfree(ps2port);
@@ -444,7 +443,7 @@ static struct parisc_device_id gscps2_device_tbl[] = {
444}; 443};
445 444
446static struct parisc_driver parisc_ps2_driver = { 445static struct parisc_driver parisc_ps2_driver = {
447 .name = "GSC PS2", 446 .name = "gsc_ps2",
448 .id_table = gscps2_device_tbl, 447 .id_table = gscps2_device_tbl,
449 .probe = gscps2_probe, 448 .probe = gscps2_probe,
450 .remove = gscps2_remove, 449 .remove = gscps2_remove,
diff --git a/drivers/input/serio/hil_mlc.c b/drivers/input/serio/hil_mlc.c
index c243cb6fdfc4..5704204964a3 100644
--- a/drivers/input/serio/hil_mlc.c
+++ b/drivers/input/serio/hil_mlc.c
@@ -801,7 +801,8 @@ static int hil_mlc_serio_open(struct serio *serio) {
801 struct hil_mlc_serio_map *map; 801 struct hil_mlc_serio_map *map;
802 struct hil_mlc *mlc; 802 struct hil_mlc *mlc;
803 803
804 if (serio->private != NULL) return -EBUSY; 804 if (serio_get_drvdata(serio) != NULL)
805 return -EBUSY;
805 806
806 map = serio->port_data; 807 map = serio->port_data;
807 if (map == NULL) { 808 if (map == NULL) {
@@ -832,11 +833,18 @@ static void hil_mlc_serio_close(struct serio *serio) {
832 return; 833 return;
833 } 834 }
834 835
835 serio->private = NULL; 836 serio_set_drvdata(serio, NULL);
836 serio->drv = NULL; 837 serio->drv = NULL;
837 /* TODO wake up interruptable */ 838 /* TODO wake up interruptable */
838} 839}
839 840
841static struct serio_device_id hil_mlc_serio_id = {
842 .type = SERIO_HIL_MLC,
843 .proto = SERIO_HIL,
844 .extra = SERIO_ANY,
845 .id = SERIO_ANY,
846};
847
840int hil_mlc_register(hil_mlc *mlc) { 848int hil_mlc_register(hil_mlc *mlc) {
841 int i; 849 int i;
842 unsigned long flags; 850 unsigned long flags;
@@ -867,7 +875,7 @@ int hil_mlc_register(hil_mlc *mlc) {
867 mlc_serio = kmalloc(sizeof(*mlc_serio), GFP_KERNEL); 875 mlc_serio = kmalloc(sizeof(*mlc_serio), GFP_KERNEL);
868 mlc->serio[i] = mlc_serio; 876 mlc->serio[i] = mlc_serio;
869 memset(mlc_serio, 0, sizeof(*mlc_serio)); 877 memset(mlc_serio, 0, sizeof(*mlc_serio));
870 mlc_serio->type = SERIO_HIL | SERIO_HIL_MLC; 878 mlc_serio->id = hil_mlc_serio_id;
871 mlc_serio->write = hil_mlc_serio_write; 879 mlc_serio->write = hil_mlc_serio_write;
872 mlc_serio->open = hil_mlc_serio_open; 880 mlc_serio->open = hil_mlc_serio_open;
873 mlc_serio->close = hil_mlc_serio_close; 881 mlc_serio->close = hil_mlc_serio_close;
diff --git a/drivers/input/serio/hp_sdc.c b/drivers/input/serio/hp_sdc.c
index 7629452dd64b..a10348bb25e9 100644
--- a/drivers/input/serio/hp_sdc.c
+++ b/drivers/input/serio/hp_sdc.c
@@ -764,7 +764,7 @@ MODULE_DEVICE_TABLE(parisc, hp_sdc_tbl);
764static int __init hp_sdc_init_hppa(struct parisc_device *d); 764static int __init hp_sdc_init_hppa(struct parisc_device *d);
765 765
766static struct parisc_driver hp_sdc_driver = { 766static struct parisc_driver hp_sdc_driver = {
767 .name = "HP SDC", 767 .name = "hp_sdc",
768 .id_table = hp_sdc_tbl, 768 .id_table = hp_sdc_tbl,
769 .probe = hp_sdc_init_hppa, 769 .probe = hp_sdc_init_hppa,
770}; 770};
@@ -875,9 +875,9 @@ static int __init hp_sdc_init_hppa(struct parisc_device *d)
875 hp_sdc.dev = d; 875 hp_sdc.dev = d;
876 hp_sdc.irq = d->irq; 876 hp_sdc.irq = d->irq;
877 hp_sdc.nmi = d->aux_irq; 877 hp_sdc.nmi = d->aux_irq;
878 hp_sdc.base_io = d->hpa; 878 hp_sdc.base_io = d->hpa.start;
879 hp_sdc.data_io = d->hpa + 0x800; 879 hp_sdc.data_io = d->hpa.start + 0x800;
880 hp_sdc.status_io = d->hpa + 0x801; 880 hp_sdc.status_io = d->hpa.start + 0x801;
881 881
882 return hp_sdc_init(); 882 return hp_sdc_init();
883} 883}
diff --git a/drivers/input/serio/hp_sdc_mlc.c b/drivers/input/serio/hp_sdc_mlc.c
index e3c44ffae674..1c9426fd5205 100644
--- a/drivers/input/serio/hp_sdc_mlc.c
+++ b/drivers/input/serio/hp_sdc_mlc.c
@@ -40,6 +40,7 @@
40#include <linux/module.h> 40#include <linux/module.h>
41#include <linux/init.h> 41#include <linux/init.h>
42#include <linux/string.h> 42#include <linux/string.h>
43#include <asm/semaphore.h>
43 44
44#define PREFIX "HP SDC MLC: " 45#define PREFIX "HP SDC MLC: "
45 46
diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
index 40d451ce07ff..4bc40f159996 100644
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -911,12 +911,10 @@ static long i8042_panic_blink(long count)
911 * Here we try to restore the original BIOS settings 911 * Here we try to restore the original BIOS settings
912 */ 912 */
913 913
914static int i8042_suspend(struct device *dev, pm_message_t state, u32 level) 914static int i8042_suspend(struct device *dev, pm_message_t state)
915{ 915{
916 if (level == SUSPEND_DISABLE) { 916 del_timer_sync(&i8042_timer);
917 del_timer_sync(&i8042_timer); 917 i8042_controller_reset();
918 i8042_controller_reset();
919 }
920 918
921 return 0; 919 return 0;
922} 920}
@@ -926,13 +924,10 @@ static int i8042_suspend(struct device *dev, pm_message_t state, u32 level)
926 * Here we try to reset everything back to a state in which suspended 924 * Here we try to reset everything back to a state in which suspended
927 */ 925 */
928 926
929static int i8042_resume(struct device *dev, u32 level) 927static int i8042_resume(struct device *dev)
930{ 928{
931 int i; 929 int i;
932 930
933 if (level != RESUME_ENABLE)
934 return 0;
935
936 if (i8042_ctl_test()) 931 if (i8042_ctl_test())
937 return -1; 932 return -1;
938 933
diff --git a/drivers/input/touchscreen/corgi_ts.c b/drivers/input/touchscreen/corgi_ts.c
index 4c7fbe550365..0ba3e6562bff 100644
--- a/drivers/input/touchscreen/corgi_ts.c
+++ b/drivers/input/touchscreen/corgi_ts.c
@@ -41,8 +41,7 @@ struct ts_event {
41}; 41};
42 42
43struct corgi_ts { 43struct corgi_ts {
44 char phys[32]; 44 struct input_dev *input;
45 struct input_dev input;
46 struct timer_list timer; 45 struct timer_list timer;
47 struct ts_event tc; 46 struct ts_event tc;
48 int pendown; 47 int pendown;
@@ -182,14 +181,12 @@ static void new_data(struct corgi_ts *corgi_ts, struct pt_regs *regs)
182 if (!corgi_ts->tc.pressure && corgi_ts->pendown == 0) 181 if (!corgi_ts->tc.pressure && corgi_ts->pendown == 0)
183 return; 182 return;
184 183
185 if (regs) 184 input_regs(corgi_ts->input, regs);
186 input_regs(&corgi_ts->input, regs); 185 input_report_abs(corgi_ts->input, ABS_X, corgi_ts->tc.x);
187 186 input_report_abs(corgi_ts->input, ABS_Y, corgi_ts->tc.y);
188 input_report_abs(&corgi_ts->input, ABS_X, corgi_ts->tc.x); 187 input_report_abs(corgi_ts->input, ABS_PRESSURE, corgi_ts->tc.pressure);
189 input_report_abs(&corgi_ts->input, ABS_Y, corgi_ts->tc.y); 188 input_report_key(corgi_ts->input, BTN_TOUCH, (corgi_ts->pendown != 0));
190 input_report_abs(&corgi_ts->input, ABS_PRESSURE, corgi_ts->tc.pressure); 189 input_sync(corgi_ts->input);
191 input_report_key(&corgi_ts->input, BTN_TOUCH, (corgi_ts->pendown != 0));
192 input_sync(&corgi_ts->input);
193} 190}
194 191
195static void ts_interrupt_main(struct corgi_ts *corgi_ts, int isTimer, struct pt_regs *regs) 192static void ts_interrupt_main(struct corgi_ts *corgi_ts, int isTimer, struct pt_regs *regs)
@@ -234,34 +231,32 @@ static irqreturn_t ts_interrupt(int irq, void *dev_id, struct pt_regs *regs)
234} 231}
235 232
236#ifdef CONFIG_PM 233#ifdef CONFIG_PM
237static int corgits_suspend(struct device *dev, pm_message_t state, uint32_t level) 234static int corgits_suspend(struct device *dev, pm_message_t state)
238{ 235{
239 if (level == SUSPEND_POWER_DOWN) { 236 struct corgi_ts *corgi_ts = dev_get_drvdata(dev);
240 struct corgi_ts *corgi_ts = dev_get_drvdata(dev);
241
242 if (corgi_ts->pendown) {
243 del_timer_sync(&corgi_ts->timer);
244 corgi_ts->tc.pressure = 0;
245 new_data(corgi_ts, NULL);
246 corgi_ts->pendown = 0;
247 }
248 corgi_ts->power_mode = PWR_MODE_SUSPEND;
249 237
250 corgi_ssp_ads7846_putget((1u << ADSCTRL_ADR_SH) | ADSCTRL_STS); 238 if (corgi_ts->pendown) {
239 del_timer_sync(&corgi_ts->timer);
240 corgi_ts->tc.pressure = 0;
241 new_data(corgi_ts, NULL);
242 corgi_ts->pendown = 0;
251 } 243 }
244 corgi_ts->power_mode = PWR_MODE_SUSPEND;
245
246 corgi_ssp_ads7846_putget((1u << ADSCTRL_ADR_SH) | ADSCTRL_STS);
247
252 return 0; 248 return 0;
253} 249}
254 250
255static int corgits_resume(struct device *dev, uint32_t level) 251static int corgits_resume(struct device *dev)
256{ 252{
257 if (level == RESUME_POWER_ON) { 253 struct corgi_ts *corgi_ts = dev_get_drvdata(dev);
258 struct corgi_ts *corgi_ts = dev_get_drvdata(dev); 254
255 corgi_ssp_ads7846_putget((4u << ADSCTRL_ADR_SH) | ADSCTRL_STS);
256 /* Enable Falling Edge */
257 set_irq_type(corgi_ts->irq_gpio, IRQT_FALLING);
258 corgi_ts->power_mode = PWR_MODE_ACTIVE;
259 259
260 corgi_ssp_ads7846_putget((4u << ADSCTRL_ADR_SH) | ADSCTRL_STS);
261 /* Enable Falling Edge */
262 set_irq_type(corgi_ts->irq_gpio, IRQT_FALLING);
263 corgi_ts->power_mode = PWR_MODE_ACTIVE;
264 }
265 return 0; 260 return 0;
266} 261}
267#else 262#else
@@ -273,39 +268,44 @@ static int __init corgits_probe(struct device *dev)
273{ 268{
274 struct corgi_ts *corgi_ts; 269 struct corgi_ts *corgi_ts;
275 struct platform_device *pdev = to_platform_device(dev); 270 struct platform_device *pdev = to_platform_device(dev);
271 struct input_dev *input_dev;
272 int err = -ENOMEM;
276 273
277 if (!(corgi_ts = kmalloc(sizeof(struct corgi_ts), GFP_KERNEL))) 274 corgi_ts = kzalloc(sizeof(struct corgi_ts), GFP_KERNEL);
278 return -ENOMEM; 275 input_dev = input_allocate_device();
276 if (!corgi_ts || !input_dev)
277 goto fail;
279 278
280 dev_set_drvdata(dev, corgi_ts); 279 dev_set_drvdata(dev, corgi_ts);
281 280
282 memset(corgi_ts, 0, sizeof(struct corgi_ts));
283
284 corgi_ts->machinfo = dev->platform_data; 281 corgi_ts->machinfo = dev->platform_data;
285 corgi_ts->irq_gpio = platform_get_irq(pdev, 0); 282 corgi_ts->irq_gpio = platform_get_irq(pdev, 0);
286 283
287 if (corgi_ts->irq_gpio < 0) { 284 if (corgi_ts->irq_gpio < 0) {
288 kfree(corgi_ts); 285 err = -ENODEV;
289 return -ENODEV; 286 goto fail;
290 } 287 }
291 288
292 init_input_dev(&corgi_ts->input); 289 corgi_ts->input = input_dev;
293 corgi_ts->input.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
294 corgi_ts->input.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
295 input_set_abs_params(&corgi_ts->input, ABS_X, X_AXIS_MIN, X_AXIS_MAX, 0, 0);
296 input_set_abs_params(&corgi_ts->input, ABS_Y, Y_AXIS_MIN, Y_AXIS_MAX, 0, 0);
297 input_set_abs_params(&corgi_ts->input, ABS_PRESSURE, PRESSURE_MIN, PRESSURE_MAX, 0, 0);
298 290
299 strcpy(corgi_ts->phys, "corgits/input0"); 291 init_timer(&corgi_ts->timer);
292 corgi_ts->timer.data = (unsigned long) corgi_ts;
293 corgi_ts->timer.function = corgi_ts_timer;
300 294
301 corgi_ts->input.private = corgi_ts; 295 input_dev->name = "Corgi Touchscreen";
302 corgi_ts->input.name = "Corgi Touchscreen"; 296 input_dev->phys = "corgits/input0";
303 corgi_ts->input.dev = dev; 297 input_dev->id.bustype = BUS_HOST;
304 corgi_ts->input.phys = corgi_ts->phys; 298 input_dev->id.vendor = 0x0001;
305 corgi_ts->input.id.bustype = BUS_HOST; 299 input_dev->id.product = 0x0002;
306 corgi_ts->input.id.vendor = 0x0001; 300 input_dev->id.version = 0x0100;
307 corgi_ts->input.id.product = 0x0002; 301 input_dev->cdev.dev = dev;
308 corgi_ts->input.id.version = 0x0100; 302 input_dev->private = corgi_ts;
303
304 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
305 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
306 input_set_abs_params(input_dev, ABS_X, X_AXIS_MIN, X_AXIS_MAX, 0, 0);
307 input_set_abs_params(input_dev, ABS_Y, Y_AXIS_MIN, Y_AXIS_MAX, 0, 0);
308 input_set_abs_params(input_dev, ABS_PRESSURE, PRESSURE_MIN, PRESSURE_MAX, 0, 0);
309 309
310 pxa_gpio_mode(IRQ_TO_GPIO(corgi_ts->irq_gpio) | GPIO_IN); 310 pxa_gpio_mode(IRQ_TO_GPIO(corgi_ts->irq_gpio) | GPIO_IN);
311 311
@@ -319,25 +319,24 @@ static int __init corgits_probe(struct device *dev)
319 corgi_ssp_ads7846_putget((5u << ADSCTRL_ADR_SH) | ADSCTRL_STS); 319 corgi_ssp_ads7846_putget((5u << ADSCTRL_ADR_SH) | ADSCTRL_STS);
320 mdelay(5); 320 mdelay(5);
321 321
322 init_timer(&corgi_ts->timer);
323 corgi_ts->timer.data = (unsigned long) corgi_ts;
324 corgi_ts->timer.function = corgi_ts_timer;
325
326 input_register_device(&corgi_ts->input);
327 corgi_ts->power_mode = PWR_MODE_ACTIVE;
328
329 if (request_irq(corgi_ts->irq_gpio, ts_interrupt, SA_INTERRUPT, "ts", corgi_ts)) { 322 if (request_irq(corgi_ts->irq_gpio, ts_interrupt, SA_INTERRUPT, "ts", corgi_ts)) {
330 input_unregister_device(&corgi_ts->input); 323 err = -EBUSY;
331 kfree(corgi_ts); 324 goto fail;
332 return -EBUSY;
333 } 325 }
334 326
327 input_register_device(corgi_ts->input);
328
329 corgi_ts->power_mode = PWR_MODE_ACTIVE;
330
335 /* Enable Falling Edge */ 331 /* Enable Falling Edge */
336 set_irq_type(corgi_ts->irq_gpio, IRQT_FALLING); 332 set_irq_type(corgi_ts->irq_gpio, IRQT_FALLING);
337 333
338 printk(KERN_INFO "input: Corgi Touchscreen Registered\n");
339
340 return 0; 334 return 0;
335
336 fail: input_free_device(input_dev);
337 kfree(corgi_ts);
338 return err;
339
341} 340}
342 341
343static int corgits_remove(struct device *dev) 342static int corgits_remove(struct device *dev)
@@ -347,7 +346,7 @@ static int corgits_remove(struct device *dev)
347 free_irq(corgi_ts->irq_gpio, NULL); 346 free_irq(corgi_ts->irq_gpio, NULL);
348 del_timer_sync(&corgi_ts->timer); 347 del_timer_sync(&corgi_ts->timer);
349 corgi_ts->machinfo->put_hsync(); 348 corgi_ts->machinfo->put_hsync();
350 input_unregister_device(&corgi_ts->input); 349 input_unregister_device(corgi_ts->input);
351 kfree(corgi_ts); 350 kfree(corgi_ts);
352 return 0; 351 return 0;
353} 352}
diff --git a/drivers/input/touchscreen/elo.c b/drivers/input/touchscreen/elo.c
index 3cdc9cab688d..c86a2eb310fd 100644
--- a/drivers/input/touchscreen/elo.c
+++ b/drivers/input/touchscreen/elo.c
@@ -36,14 +36,12 @@ MODULE_LICENSE("GPL");
36 36
37#define ELO_MAX_LENGTH 10 37#define ELO_MAX_LENGTH 10
38 38
39static char *elo_name = "Elo Serial TouchScreen";
40
41/* 39/*
42 * Per-touchscreen data. 40 * Per-touchscreen data.
43 */ 41 */
44 42
45struct elo { 43struct elo {
46 struct input_dev dev; 44 struct input_dev *dev;
47 struct serio *serio; 45 struct serio *serio;
48 int id; 46 int id;
49 int idx; 47 int idx;
@@ -54,7 +52,7 @@ struct elo {
54 52
55static void elo_process_data_10(struct elo* elo, unsigned char data, struct pt_regs *regs) 53static void elo_process_data_10(struct elo* elo, unsigned char data, struct pt_regs *regs)
56{ 54{
57 struct input_dev *dev = &elo->dev; 55 struct input_dev *dev = elo->dev;
58 56
59 elo->csum += elo->data[elo->idx] = data; 57 elo->csum += elo->data[elo->idx] = data;
60 58
@@ -80,7 +78,7 @@ static void elo_process_data_10(struct elo* elo, unsigned char data, struct pt_r
80 input_report_abs(dev, ABS_X, (elo->data[4] << 8) | elo->data[3]); 78 input_report_abs(dev, ABS_X, (elo->data[4] << 8) | elo->data[3]);
81 input_report_abs(dev, ABS_Y, (elo->data[6] << 8) | elo->data[5]); 79 input_report_abs(dev, ABS_Y, (elo->data[6] << 8) | elo->data[5]);
82 input_report_abs(dev, ABS_PRESSURE, (elo->data[8] << 8) | elo->data[7]); 80 input_report_abs(dev, ABS_PRESSURE, (elo->data[8] << 8) | elo->data[7]);
83 input_report_key(dev, BTN_TOUCH, elo->data[2] & 3); 81 input_report_key(dev, BTN_TOUCH, elo->data[8] || elo->data[7]);
84 input_sync(dev); 82 input_sync(dev);
85 } 83 }
86 elo->idx = 0; 84 elo->idx = 0;
@@ -91,7 +89,7 @@ static void elo_process_data_10(struct elo* elo, unsigned char data, struct pt_r
91 89
92static void elo_process_data_6(struct elo* elo, unsigned char data, struct pt_regs *regs) 90static void elo_process_data_6(struct elo* elo, unsigned char data, struct pt_regs *regs)
93{ 91{
94 struct input_dev *dev = &elo->dev; 92 struct input_dev *dev = elo->dev;
95 93
96 elo->data[elo->idx] = data; 94 elo->data[elo->idx] = data;
97 95
@@ -129,7 +127,7 @@ static void elo_process_data_6(struct elo* elo, unsigned char data, struct pt_re
129 case 5: 127 case 5:
130 if ((data & 0xf0) == 0) { 128 if ((data & 0xf0) == 0) {
131 input_report_abs(dev, ABS_PRESSURE, elo->data[5]); 129 input_report_abs(dev, ABS_PRESSURE, elo->data[5]);
132 input_report_key(dev, BTN_TOUCH, elo->data[5]); 130 input_report_key(dev, BTN_TOUCH, !!elo->data[5]);
133 } 131 }
134 input_sync(dev); 132 input_sync(dev);
135 elo->idx = 0; 133 elo->idx = 0;
@@ -139,7 +137,7 @@ static void elo_process_data_6(struct elo* elo, unsigned char data, struct pt_re
139 137
140static void elo_process_data_3(struct elo* elo, unsigned char data, struct pt_regs *regs) 138static void elo_process_data_3(struct elo* elo, unsigned char data, struct pt_regs *regs)
141{ 139{
142 struct input_dev *dev = &elo->dev; 140 struct input_dev *dev = elo->dev;
143 141
144 elo->data[elo->idx] = data; 142 elo->data[elo->idx] = data;
145 143
@@ -191,7 +189,7 @@ static void elo_disconnect(struct serio *serio)
191{ 189{
192 struct elo* elo = serio_get_drvdata(serio); 190 struct elo* elo = serio_get_drvdata(serio);
193 191
194 input_unregister_device(&elo->dev); 192 input_unregister_device(elo->dev);
195 serio_close(serio); 193 serio_close(serio);
196 serio_set_drvdata(serio, NULL); 194 serio_set_drvdata(serio, NULL);
197 kfree(elo); 195 kfree(elo);
@@ -206,67 +204,68 @@ static void elo_disconnect(struct serio *serio)
206static int elo_connect(struct serio *serio, struct serio_driver *drv) 204static int elo_connect(struct serio *serio, struct serio_driver *drv)
207{ 205{
208 struct elo *elo; 206 struct elo *elo;
207 struct input_dev *input_dev;
209 int err; 208 int err;
210 209
211 if (!(elo = kmalloc(sizeof(struct elo), GFP_KERNEL))) 210 elo = kzalloc(sizeof(struct elo), GFP_KERNEL);
212 return -ENOMEM; 211 input_dev = input_allocate_device();
212 if (!elo || !input_dev) {
213 err = -ENOMEM;
214 goto fail;
215 }
213 216
214 memset(elo, 0, sizeof(struct elo)); 217 elo->serio = serio;
218 elo->id = serio->id.id;
219 elo->dev = input_dev;
220 snprintf(elo->phys, sizeof(elo->phys), "%s/input0", serio->phys);
215 221
216 init_input_dev(&elo->dev); 222 input_dev->private = elo;
217 elo->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 223 input_dev->name = "Elo Serial TouchScreen";
218 elo->dev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); 224 input_dev->phys = elo->phys;
225 input_dev->id.bustype = BUS_RS232;
226 input_dev->id.vendor = SERIO_ELO;
227 input_dev->id.product = elo->id;
228 input_dev->id.version = 0x0100;
229 input_dev->cdev.dev = &serio->dev;
219 230
220 elo->id = serio->id.id; 231 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
232 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
221 233
222 switch (elo->id) { 234 switch (elo->id) {
223 235
224 case 0: /* 10-byte protocol */ 236 case 0: /* 10-byte protocol */
225 input_set_abs_params(&elo->dev, ABS_X, 96, 4000, 0, 0); 237 input_set_abs_params(input_dev, ABS_X, 96, 4000, 0, 0);
226 input_set_abs_params(&elo->dev, ABS_Y, 96, 4000, 0, 0); 238 input_set_abs_params(input_dev, ABS_Y, 96, 4000, 0, 0);
227 input_set_abs_params(&elo->dev, ABS_PRESSURE, 0, 255, 0, 0); 239 input_set_abs_params(input_dev, ABS_PRESSURE, 0, 255, 0, 0);
228 break; 240 break;
229 241
230 case 1: /* 6-byte protocol */ 242 case 1: /* 6-byte protocol */
231 input_set_abs_params(&elo->dev, ABS_PRESSURE, 0, 15, 0, 0); 243 input_set_abs_params(input_dev, ABS_PRESSURE, 0, 15, 0, 0);
232 244
233 case 2: /* 4-byte protocol */ 245 case 2: /* 4-byte protocol */
234 input_set_abs_params(&elo->dev, ABS_X, 96, 4000, 0, 0); 246 input_set_abs_params(input_dev, ABS_X, 96, 4000, 0, 0);
235 input_set_abs_params(&elo->dev, ABS_Y, 96, 4000, 0, 0); 247 input_set_abs_params(input_dev, ABS_Y, 96, 4000, 0, 0);
236 break; 248 break;
237 249
238 case 3: /* 3-byte protocol */ 250 case 3: /* 3-byte protocol */
239 input_set_abs_params(&elo->dev, ABS_X, 0, 255, 0, 0); 251 input_set_abs_params(input_dev, ABS_X, 0, 255, 0, 0);
240 input_set_abs_params(&elo->dev, ABS_Y, 0, 255, 0, 0); 252 input_set_abs_params(input_dev, ABS_Y, 0, 255, 0, 0);
241 break; 253 break;
242 } 254 }
243 255
244 elo->serio = serio;
245
246 sprintf(elo->phys, "%s/input0", serio->phys);
247
248 elo->dev.private = elo;
249 elo->dev.name = elo_name;
250 elo->dev.phys = elo->phys;
251 elo->dev.id.bustype = BUS_RS232;
252 elo->dev.id.vendor = SERIO_ELO;
253 elo->dev.id.product = elo->id;
254 elo->dev.id.version = 0x0100;
255
256 serio_set_drvdata(serio, elo); 256 serio_set_drvdata(serio, elo);
257 257
258 err = serio_open(serio, drv); 258 err = serio_open(serio, drv);
259 if (err) { 259 if (err)
260 serio_set_drvdata(serio, NULL); 260 goto fail;
261 kfree(elo);
262 return err;
263 }
264
265 input_register_device(&elo->dev);
266
267 printk(KERN_INFO "input: %s on %s\n", elo_name, serio->phys);
268 261
262 input_register_device(elo->dev);
269 return 0; 263 return 0;
264
265 fail: serio_set_drvdata(serio, NULL);
266 input_free_device(input_dev);
267 kfree(elo);
268 return err;
270} 269}
271 270
272/* 271/*
diff --git a/drivers/input/touchscreen/gunze.c b/drivers/input/touchscreen/gunze.c
index 53a27e43dd23..466da190ceec 100644
--- a/drivers/input/touchscreen/gunze.c
+++ b/drivers/input/touchscreen/gunze.c
@@ -48,14 +48,12 @@ MODULE_LICENSE("GPL");
48 48
49#define GUNZE_MAX_LENGTH 10 49#define GUNZE_MAX_LENGTH 10
50 50
51static char *gunze_name = "Gunze AHL-51S TouchScreen";
52
53/* 51/*
54 * Per-touchscreen data. 52 * Per-touchscreen data.
55 */ 53 */
56 54
57struct gunze { 55struct gunze {
58 struct input_dev dev; 56 struct input_dev *dev;
59 struct serio *serio; 57 struct serio *serio;
60 int idx; 58 int idx;
61 unsigned char data[GUNZE_MAX_LENGTH]; 59 unsigned char data[GUNZE_MAX_LENGTH];
@@ -64,7 +62,7 @@ struct gunze {
64 62
65static void gunze_process_packet(struct gunze* gunze, struct pt_regs *regs) 63static void gunze_process_packet(struct gunze* gunze, struct pt_regs *regs)
66{ 64{
67 struct input_dev *dev = &gunze->dev; 65 struct input_dev *dev = gunze->dev;
68 66
69 if (gunze->idx != GUNZE_MAX_LENGTH || gunze->data[5] != ',' || 67 if (gunze->idx != GUNZE_MAX_LENGTH || gunze->data[5] != ',' ||
70 (gunze->data[0] != 'T' && gunze->data[0] != 'R')) { 68 (gunze->data[0] != 'T' && gunze->data[0] != 'R')) {
@@ -100,11 +98,13 @@ static irqreturn_t gunze_interrupt(struct serio *serio,
100 98
101static void gunze_disconnect(struct serio *serio) 99static void gunze_disconnect(struct serio *serio)
102{ 100{
103 struct gunze* gunze = serio_get_drvdata(serio); 101 struct gunze *gunze = serio_get_drvdata(serio);
104 102
105 input_unregister_device(&gunze->dev); 103 input_get_device(gunze->dev);
104 input_unregister_device(gunze->dev);
106 serio_close(serio); 105 serio_close(serio);
107 serio_set_drvdata(serio, NULL); 106 serio_set_drvdata(serio, NULL);
107 input_put_device(gunze->dev);
108 kfree(gunze); 108 kfree(gunze);
109} 109}
110 110
@@ -117,45 +117,45 @@ static void gunze_disconnect(struct serio *serio)
117static int gunze_connect(struct serio *serio, struct serio_driver *drv) 117static int gunze_connect(struct serio *serio, struct serio_driver *drv)
118{ 118{
119 struct gunze *gunze; 119 struct gunze *gunze;
120 struct input_dev *input_dev;
120 int err; 121 int err;
121 122
122 if (!(gunze = kmalloc(sizeof(struct gunze), GFP_KERNEL))) 123 gunze = kzalloc(sizeof(struct gunze), GFP_KERNEL);
123 return -ENOMEM; 124 input_dev = input_allocate_device();
124 125 if (!gunze || !input_dev) {
125 memset(gunze, 0, sizeof(struct gunze)); 126 err = -ENOMEM;
126 127 goto fail;
127 init_input_dev(&gunze->dev); 128 }
128 gunze->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
129 gunze->dev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
130 input_set_abs_params(&gunze->dev, ABS_X, 24, 1000, 0, 0);
131 input_set_abs_params(&gunze->dev, ABS_Y, 24, 1000, 0, 0);
132 129
133 gunze->serio = serio; 130 gunze->serio = serio;
134 131 gunze->dev = input_dev;
135 sprintf(gunze->phys, "%s/input0", serio->phys); 132 sprintf(gunze->phys, "%s/input0", serio->phys);
136 133
137 gunze->dev.private = gunze; 134 input_dev->private = gunze;
138 gunze->dev.name = gunze_name; 135 input_dev->name = "Gunze AHL-51S TouchScreen";
139 gunze->dev.phys = gunze->phys; 136 input_dev->phys = gunze->phys;
140 gunze->dev.id.bustype = BUS_RS232; 137 input_dev->id.bustype = BUS_RS232;
141 gunze->dev.id.vendor = SERIO_GUNZE; 138 input_dev->id.vendor = SERIO_GUNZE;
142 gunze->dev.id.product = 0x0051; 139 input_dev->id.product = 0x0051;
143 gunze->dev.id.version = 0x0100; 140 input_dev->id.version = 0x0100;
141 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
142 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
143 input_set_abs_params(input_dev, ABS_X, 24, 1000, 0, 0);
144 input_set_abs_params(input_dev, ABS_Y, 24, 1000, 0, 0);
144 145
145 serio_set_drvdata(serio, gunze); 146 serio_set_drvdata(serio, gunze);
146 147
147 err = serio_open(serio, drv); 148 err = serio_open(serio, drv);
148 if (err) { 149 if (err)
149 serio_set_drvdata(serio, NULL); 150 goto fail;
150 kfree(gunze);
151 return err;
152 }
153
154 input_register_device(&gunze->dev);
155
156 printk(KERN_INFO "input: %s on %s\n", gunze_name, serio->phys);
157 151
152 input_register_device(gunze->dev);
158 return 0; 153 return 0;
154
155 fail: serio_set_drvdata(serio, NULL);
156 input_free_device(input_dev);
157 kfree(gunze);
158 return err;
159} 159}
160 160
161/* 161/*
diff --git a/drivers/input/touchscreen/h3600_ts_input.c b/drivers/input/touchscreen/h3600_ts_input.c
index bcfa1e36f957..a18d56bdafd9 100644
--- a/drivers/input/touchscreen/h3600_ts_input.c
+++ b/drivers/input/touchscreen/h3600_ts_input.c
@@ -39,7 +39,6 @@
39#include <linux/serio.h> 39#include <linux/serio.h>
40#include <linux/init.h> 40#include <linux/init.h>
41#include <linux/delay.h> 41#include <linux/delay.h>
42#include <linux/pm.h>
43 42
44/* SA1100 serial defines */ 43/* SA1100 serial defines */
45#include <asm/arch/hardware.h> 44#include <asm/arch/hardware.h>
@@ -93,16 +92,12 @@ MODULE_LICENSE("GPL");
93#define H3600_SCANCODE_LEFT 8 /* 8 -> left */ 92#define H3600_SCANCODE_LEFT 8 /* 8 -> left */
94#define H3600_SCANCODE_DOWN 9 /* 9 -> down */ 93#define H3600_SCANCODE_DOWN 9 /* 9 -> down */
95 94
96static char *h3600_name = "H3600 TouchScreen";
97
98/* 95/*
99 * Per-touchscreen data. 96 * Per-touchscreen data.
100 */ 97 */
101struct h3600_dev { 98struct h3600_dev {
102 struct input_dev dev; 99 struct input_dev *dev;
103 struct pm_dev *pm_dev;
104 struct serio *serio; 100 struct serio *serio;
105 struct pm_dev *pm_dev;
106 unsigned char event; /* event ID from packet */ 101 unsigned char event; /* event ID from packet */
107 unsigned char chksum; 102 unsigned char chksum;
108 unsigned char len; 103 unsigned char len;
@@ -163,33 +158,6 @@ unsigned int h3600_flite_power(struct input_dev *dev, enum flite_pwr pwr)
163 return 0; 158 return 0;
164} 159}
165 160
166static int suspended = 0;
167static int h3600ts_pm_callback(struct pm_dev *pm_dev, pm_request_t req,
168 void *data)
169{
170 struct input_dev *dev = (struct input_dev *) data;
171
172 switch (req) {
173 case PM_SUSPEND: /* enter D1-D3 */
174 suspended = 1;
175 h3600_flite_power(dev, FLITE_PWR_OFF);
176 break;
177 case PM_BLANK:
178 if (!suspended)
179 h3600_flite_power(dev, FLITE_PWR_OFF);
180 break;
181 case PM_RESUME: /* enter D0 */
182 /* same as unblank */
183 case PM_UNBLANK:
184 if (suspended) {
185 //initSerial();
186 suspended = 0;
187 }
188 h3600_flite_power(dev, FLITE_PWR_ON);
189 break;
190 }
191 return 0;
192}
193#endif 161#endif
194 162
195/* 163/*
@@ -199,7 +167,7 @@ static int h3600ts_pm_callback(struct pm_dev *pm_dev, pm_request_t req,
199 */ 167 */
200static void h3600ts_process_packet(struct h3600_dev *ts, struct pt_regs *regs) 168static void h3600ts_process_packet(struct h3600_dev *ts, struct pt_regs *regs)
201{ 169{
202 struct input_dev *dev = &ts->dev; 170 struct input_dev *dev = ts->dev;
203 static int touched = 0; 171 static int touched = 0;
204 int key, down = 0; 172 int key, down = 0;
205 173
@@ -295,6 +263,7 @@ static void h3600ts_process_packet(struct h3600_dev *ts, struct pt_regs *regs)
295static int h3600ts_event(struct input_dev *dev, unsigned int type, 263static int h3600ts_event(struct input_dev *dev, unsigned int type,
296 unsigned int code, int value) 264 unsigned int code, int value)
297{ 265{
266#if 0
298 struct h3600_dev *ts = dev->private; 267 struct h3600_dev *ts = dev->private;
299 268
300 switch (type) { 269 switch (type) {
@@ -304,6 +273,8 @@ static int h3600ts_event(struct input_dev *dev, unsigned int type,
304 } 273 }
305 } 274 }
306 return -1; 275 return -1;
276#endif
277 return 0;
307} 278}
308 279
309/* 280/*
@@ -380,14 +351,48 @@ static irqreturn_t h3600ts_interrupt(struct serio *serio, unsigned char data,
380static int h3600ts_connect(struct serio *serio, struct serio_driver *drv) 351static int h3600ts_connect(struct serio *serio, struct serio_driver *drv)
381{ 352{
382 struct h3600_dev *ts; 353 struct h3600_dev *ts;
354 struct input_dev *input_dev;
383 int err; 355 int err;
384 356
385 if (!(ts = kmalloc(sizeof(struct h3600_dev), GFP_KERNEL))) 357 ts = kzalloc(sizeof(struct h3600_dev), GFP_KERNEL);
386 return -ENOMEM; 358 input_dev = input_allocate_device();
359 if (!ts || !input_dev) {
360 err = -ENOMEM;
361 goto fail1;
362 }
387 363
388 memset(ts, 0, sizeof(struct h3600_dev)); 364 ts->serio = serio;
365 ts->dev = input_dev;
366 sprintf(ts->phys, "%s/input0", serio->phys);
389 367
390 init_input_dev(&ts->dev); 368 input_dev->name = "H3600 TouchScreen";
369 input_dev->phys = ts->phys;
370 input_dev->id.bustype = BUS_RS232;
371 input_dev->id.vendor = SERIO_H3600;
372 input_dev->id.product = 0x0666; /* FIXME !!! We can ask the hardware */
373 input_dev->id.version = 0x0100;
374 input_dev->cdev.dev = &serio->dev;
375 input_dev->private = ts;
376
377 input_dev->event = h3600ts_event;
378
379 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_LED) | BIT(EV_PWR);
380 input_dev->ledbit[0] = BIT(LED_SLEEP);
381 input_set_abs_params(input_dev, ABS_X, 60, 985, 0, 0);
382 input_set_abs_params(input_dev, ABS_Y, 35, 1024, 0, 0);
383
384 set_bit(KEY_RECORD, input_dev->keybit);
385 set_bit(KEY_Q, input_dev->keybit);
386 set_bit(KEY_PROG1, input_dev->keybit);
387 set_bit(KEY_PROG2, input_dev->keybit);
388 set_bit(KEY_PROG3, input_dev->keybit);
389 set_bit(KEY_UP, input_dev->keybit);
390 set_bit(KEY_RIGHT, input_dev->keybit);
391 set_bit(KEY_LEFT, input_dev->keybit);
392 set_bit(KEY_DOWN, input_dev->keybit);
393 set_bit(KEY_ENTER, input_dev->keybit);
394 set_bit(KEY_SUSPEND, input_dev->keybit);
395 set_bit(BTN_TOUCH, input_dev->keybit);
391 396
392 /* Device specific stuff */ 397 /* Device specific stuff */
393 set_GPIO_IRQ_edge(GPIO_BITSY_ACTION_BUTTON, GPIO_BOTH_EDGES); 398 set_GPIO_IRQ_edge(GPIO_BITSY_ACTION_BUTTON, GPIO_BOTH_EDGES);
@@ -397,73 +402,35 @@ static int h3600ts_connect(struct serio *serio, struct serio_driver *drv)
397 SA_SHIRQ | SA_INTERRUPT | SA_SAMPLE_RANDOM, 402 SA_SHIRQ | SA_INTERRUPT | SA_SAMPLE_RANDOM,
398 "h3600_action", &ts->dev)) { 403 "h3600_action", &ts->dev)) {
399 printk(KERN_ERR "h3600ts.c: Could not allocate Action Button IRQ!\n"); 404 printk(KERN_ERR "h3600ts.c: Could not allocate Action Button IRQ!\n");
400 kfree(ts); 405 err = -EBUSY;
401 return -EBUSY; 406 goto fail2;
402 } 407 }
403 408
404 if (request_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, npower_button_handler, 409 if (request_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, npower_button_handler,
405 SA_SHIRQ | SA_INTERRUPT | SA_SAMPLE_RANDOM, 410 SA_SHIRQ | SA_INTERRUPT | SA_SAMPLE_RANDOM,
406 "h3600_suspend", &ts->dev)) { 411 "h3600_suspend", &ts->dev)) {
407 free_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, &ts->dev);
408 printk(KERN_ERR "h3600ts.c: Could not allocate Power Button IRQ!\n"); 412 printk(KERN_ERR "h3600ts.c: Could not allocate Power Button IRQ!\n");
409 kfree(ts); 413 err = -EBUSY;
410 return -EBUSY; 414 goto fail3;
411 } 415 }
412 416
413 /* Now we have things going we setup our input device */
414 ts->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_LED) | BIT(EV_PWR);
415 ts->dev.ledbit[0] = BIT(LED_SLEEP);
416 input_set_abs_params(&ts->dev, ABS_X, 60, 985, 0, 0);
417 input_set_abs_params(&ts->dev, ABS_Y, 35, 1024, 0, 0);
418
419 set_bit(KEY_RECORD, ts->dev.keybit);
420 set_bit(KEY_Q, ts->dev.keybit);
421 set_bit(KEY_PROG1, ts->dev.keybit);
422 set_bit(KEY_PROG2, ts->dev.keybit);
423 set_bit(KEY_PROG3, ts->dev.keybit);
424 set_bit(KEY_UP, ts->dev.keybit);
425 set_bit(KEY_RIGHT, ts->dev.keybit);
426 set_bit(KEY_LEFT, ts->dev.keybit);
427 set_bit(KEY_DOWN, ts->dev.keybit);
428 set_bit(KEY_ENTER, ts->dev.keybit);
429 ts->dev.keybit[LONG(BTN_TOUCH)] |= BIT(BTN_TOUCH);
430 ts->dev.keybit[LONG(KEY_SUSPEND)] |= BIT(KEY_SUSPEND);
431
432 ts->serio = serio;
433
434 sprintf(ts->phys, "%s/input0", serio->phys);
435
436 ts->dev.event = h3600ts_event;
437 ts->dev.private = ts;
438 ts->dev.name = h3600_name;
439 ts->dev.phys = ts->phys;
440 ts->dev.id.bustype = BUS_RS232;
441 ts->dev.id.vendor = SERIO_H3600;
442 ts->dev.id.product = 0x0666; /* FIXME !!! We can ask the hardware */
443 ts->dev.id.version = 0x0100;
444
445 serio_set_drvdata(serio, ts); 417 serio_set_drvdata(serio, ts);
446 418
447 err = serio_open(serio, drv); 419 err = serio_open(serio, drv);
448 if (err) { 420 if (err)
449 free_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, ts);
450 free_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, ts);
451 serio_set_drvdata(serio, NULL);
452 kfree(ts);
453 return err; 421 return err;
454 }
455 422
456 //h3600_flite_control(1, 25); /* default brightness */ 423 //h3600_flite_control(1, 25); /* default brightness */
457#ifdef CONFIG_PM 424 input_register_device(ts->dev);
458 ts->pm_dev = pm_register(PM_ILLUMINATION_DEV, PM_SYS_LIGHT,
459 h3600ts_pm_callback);
460 printk("registered pm callback\n");
461#endif
462 input_register_device(&ts->dev);
463
464 printk(KERN_INFO "input: %s on %s\n", h3600_name, serio->phys);
465 425
466 return 0; 426 return 0;
427
428fail3: free_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, ts->dev);
429fail2: free_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, ts->dev);
430fail1: serio_set_drvdata(serio, NULL);
431 input_free_device(input_dev);
432 kfree(ts);
433 return err;
467} 434}
468 435
469/* 436/*
@@ -476,9 +443,11 @@ static void h3600ts_disconnect(struct serio *serio)
476 443
477 free_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, &ts->dev); 444 free_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, &ts->dev);
478 free_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, &ts->dev); 445 free_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, &ts->dev);
479 input_unregister_device(&ts->dev); 446 input_get_device(ts->dev);
447 input_unregister_device(ts->dev);
480 serio_close(serio); 448 serio_close(serio);
481 serio_set_drvdata(serio, NULL); 449 serio_set_drvdata(serio, NULL);
450 input_put_device(ts->dev);
482 kfree(ts); 451 kfree(ts);
483} 452}
484 453
diff --git a/drivers/input/touchscreen/hp680_ts_input.c b/drivers/input/touchscreen/hp680_ts_input.c
index 7e1404441eca..957dd5a1b15e 100644
--- a/drivers/input/touchscreen/hp680_ts_input.c
+++ b/drivers/input/touchscreen/hp680_ts_input.c
@@ -21,10 +21,8 @@
21 21
22static void do_softint(void *data); 22static void do_softint(void *data);
23 23
24static struct input_dev hp680_ts_dev; 24static struct input_dev *hp680_ts_dev;
25static DECLARE_WORK(work, do_softint, 0); 25static DECLARE_WORK(work, do_softint, 0);
26static char *hp680_ts_name = "HP Jornada touchscreen";
27static char *hp680_ts_phys = "input0";
28 26
29static void do_softint(void *data) 27static void do_softint(void *data)
30{ 28{
@@ -58,14 +56,14 @@ static void do_softint(void *data)
58 } 56 }
59 57
60 if (touched) { 58 if (touched) {
61 input_report_key(&hp680_ts_dev, BTN_TOUCH, 1); 59 input_report_key(hp680_ts_dev, BTN_TOUCH, 1);
62 input_report_abs(&hp680_ts_dev, ABS_X, absx); 60 input_report_abs(hp680_ts_dev, ABS_X, absx);
63 input_report_abs(&hp680_ts_dev, ABS_Y, absy); 61 input_report_abs(hp680_ts_dev, ABS_Y, absy);
64 } else { 62 } else {
65 input_report_key(&hp680_ts_dev, BTN_TOUCH, 0); 63 input_report_key(hp680_ts_dev, BTN_TOUCH, 0);
66 } 64 }
67 65
68 input_sync(&hp680_ts_dev); 66 input_sync(hp680_ts_dev);
69 enable_irq(HP680_TS_IRQ); 67 enable_irq(HP680_TS_IRQ);
70} 68}
71 69
@@ -92,27 +90,29 @@ static int __init hp680_ts_init(void)
92 scpcr |= SCPCR_TS_ENABLE; 90 scpcr |= SCPCR_TS_ENABLE;
93 ctrl_outw(scpcr, SCPCR); 91 ctrl_outw(scpcr, SCPCR);
94 92
95 memset(&hp680_ts_dev, 0, sizeof(hp680_ts_dev)); 93 hp680_ts_dev = input_allocate_device();
96 init_input_dev(&hp680_ts_dev); 94 if (!hp680_ts_dev)
95 return -ENOMEM;
97 96
98 hp680_ts_dev.evbit[0] = BIT(EV_ABS) | BIT(EV_KEY); 97 hp680_ts_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY);
99 hp680_ts_dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y); 98 hp680_ts_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
100 hp680_ts_dev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); 99 hp680_ts_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
101 100
102 hp680_ts_dev.absmin[ABS_X] = HP680_TS_ABS_X_MIN; 101 hp680_ts_dev->absmin[ABS_X] = HP680_TS_ABS_X_MIN;
103 hp680_ts_dev.absmin[ABS_Y] = HP680_TS_ABS_Y_MIN; 102 hp680_ts_dev->absmin[ABS_Y] = HP680_TS_ABS_Y_MIN;
104 hp680_ts_dev.absmax[ABS_X] = HP680_TS_ABS_X_MAX; 103 hp680_ts_dev->absmax[ABS_X] = HP680_TS_ABS_X_MAX;
105 hp680_ts_dev.absmax[ABS_Y] = HP680_TS_ABS_Y_MAX; 104 hp680_ts_dev->absmax[ABS_Y] = HP680_TS_ABS_Y_MAX;
106 105
107 hp680_ts_dev.name = hp680_ts_name; 106 hp680_ts_dev->name = "HP Jornada touchscreen";
108 hp680_ts_dev.phys = hp680_ts_phys; 107 hp680_ts_dev->phys = "hp680_ts/input0";
109 input_register_device(&hp680_ts_dev);
110 108
111 if (request_irq 109 input_register_device(hp680_ts_dev);
112 (HP680_TS_IRQ, hp680_ts_interrupt, SA_INTERRUPT, MODNAME, 0) < 0) { 110
113 printk(KERN_ERR "hp680_touchscreen.c : Can't allocate irq %d\n", 111 if (request_irq(HP680_TS_IRQ, hp680_ts_interrupt,
112 SA_INTERRUPT, MODNAME, 0) < 0) {
113 printk(KERN_ERR "hp680_touchscreen.c: Can't allocate irq %d\n",
114 HP680_TS_IRQ); 114 HP680_TS_IRQ);
115 input_unregister_device(&hp680_ts_dev); 115 input_unregister_device(hp680_ts_dev);
116 return -EBUSY; 116 return -EBUSY;
117 } 117 }
118 118
@@ -124,7 +124,7 @@ static void __exit hp680_ts_exit(void)
124 free_irq(HP680_TS_IRQ, 0); 124 free_irq(HP680_TS_IRQ, 0);
125 cancel_delayed_work(&work); 125 cancel_delayed_work(&work);
126 flush_scheduled_work(); 126 flush_scheduled_work();
127 input_unregister_device(&hp680_ts_dev); 127 input_unregister_device(hp680_ts_dev);
128} 128}
129 129
130module_init(hp680_ts_init); 130module_init(hp680_ts_init);
diff --git a/drivers/input/touchscreen/mk712.c b/drivers/input/touchscreen/mk712.c
index afaaebe5225b..4844d250a5eb 100644
--- a/drivers/input/touchscreen/mk712.c
+++ b/drivers/input/touchscreen/mk712.c
@@ -77,7 +77,7 @@ MODULE_PARM_DESC(irq, "IRQ of MK712 touchscreen controller");
77#define MK712_READ_ONE_POINT 0x20 77#define MK712_READ_ONE_POINT 0x20
78#define MK712_POWERUP 0x40 78#define MK712_POWERUP 0x40
79 79
80static struct input_dev mk712_dev; 80static struct input_dev *mk712_dev;
81static DEFINE_SPINLOCK(mk712_lock); 81static DEFINE_SPINLOCK(mk712_lock);
82 82
83static irqreturn_t mk712_interrupt(int irq, void *dev_id, struct pt_regs *regs) 83static irqreturn_t mk712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
@@ -88,7 +88,7 @@ static irqreturn_t mk712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
88 static unsigned short last_y; 88 static unsigned short last_y;
89 89
90 spin_lock(&mk712_lock); 90 spin_lock(&mk712_lock);
91 input_regs(&mk712_dev, regs); 91 input_regs(mk712_dev, regs);
92 92
93 status = inb(mk712_io + MK712_STATUS); 93 status = inb(mk712_io + MK712_STATUS);
94 94
@@ -100,7 +100,7 @@ static irqreturn_t mk712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
100 if (~status & MK712_STATUS_TOUCH) 100 if (~status & MK712_STATUS_TOUCH)
101 { 101 {
102 debounce = 1; 102 debounce = 1;
103 input_report_key(&mk712_dev, BTN_TOUCH, 0); 103 input_report_key(mk712_dev, BTN_TOUCH, 0);
104 goto end; 104 goto end;
105 } 105 }
106 106
@@ -110,15 +110,15 @@ static irqreturn_t mk712_interrupt(int irq, void *dev_id, struct pt_regs *regs)
110 goto end; 110 goto end;
111 } 111 }
112 112
113 input_report_key(&mk712_dev, BTN_TOUCH, 1); 113 input_report_key(mk712_dev, BTN_TOUCH, 1);
114 input_report_abs(&mk712_dev, ABS_X, last_x); 114 input_report_abs(mk712_dev, ABS_X, last_x);
115 input_report_abs(&mk712_dev, ABS_Y, last_y); 115 input_report_abs(mk712_dev, ABS_Y, last_y);
116 116
117end: 117end:
118 118
119 last_x = inw(mk712_io + MK712_X) & 0x0fff; 119 last_x = inw(mk712_io + MK712_X) & 0x0fff;
120 last_y = inw(mk712_io + MK712_Y) & 0x0fff; 120 last_y = inw(mk712_io + MK712_Y) & 0x0fff;
121 input_sync(&mk712_dev); 121 input_sync(mk712_dev);
122 spin_unlock(&mk712_lock); 122 spin_unlock(&mk712_lock);
123 return IRQ_HANDLED; 123 return IRQ_HANDLED;
124} 124}
@@ -154,30 +154,11 @@ static void mk712_close(struct input_dev *dev)
154 spin_unlock_irqrestore(&mk712_lock, flags); 154 spin_unlock_irqrestore(&mk712_lock, flags);
155} 155}
156 156
157static struct input_dev mk712_dev = {
158 .evbit = { BIT(EV_KEY) | BIT(EV_ABS) },
159 .keybit = { [LONG(BTN_TOUCH)] = BIT(BTN_TOUCH) },
160 .absbit = { BIT(ABS_X) | BIT(ABS_Y) },
161 .open = mk712_open,
162 .close = mk712_close,
163 .name = "ICS MicroClock MK712 TouchScreen",
164 .phys = "isa0260/input0",
165 .absmin = { [ABS_X] = 0, [ABS_Y] = 0 },
166 .absmax = { [ABS_X] = 0xfff, [ABS_Y] = 0xfff },
167 .absfuzz = { [ABS_X] = 88, [ABS_Y] = 88 },
168 .id = {
169 .bustype = BUS_ISA,
170 .vendor = 0x0005,
171 .product = 0x0001,
172 .version = 0x0100,
173 },
174};
175
176int __init mk712_init(void) 157int __init mk712_init(void)
177{ 158{
159 int err;
178 160
179 if(!request_region(mk712_io, 8, "mk712")) 161 if (!request_region(mk712_io, 8, "mk712")) {
180 {
181 printk(KERN_WARNING "mk712: unable to get IO region\n"); 162 printk(KERN_WARNING "mk712: unable to get IO region\n");
182 return -ENODEV; 163 return -ENODEV;
183 } 164 }
@@ -188,28 +169,49 @@ int __init mk712_init(void)
188 (inw(mk712_io + MK712_Y) & 0xf000) || 169 (inw(mk712_io + MK712_Y) & 0xf000) ||
189 (inw(mk712_io + MK712_STATUS) & 0xf333)) { 170 (inw(mk712_io + MK712_STATUS) & 0xf333)) {
190 printk(KERN_WARNING "mk712: device not present\n"); 171 printk(KERN_WARNING "mk712: device not present\n");
191 release_region(mk712_io, 8); 172 err = -ENODEV;
192 return -ENODEV; 173 goto fail;
193 } 174 }
194 175
195 if(request_irq(mk712_irq, mk712_interrupt, 0, "mk712", &mk712_dev)) 176 if (!(mk712_dev = input_allocate_device())) {
196 { 177 printk(KERN_ERR "mk712: not enough memory\n");
197 printk(KERN_WARNING "mk712: unable to get IRQ\n"); 178 err = -ENOMEM;
198 release_region(mk712_io, 8); 179 goto fail;
199 return -EBUSY;
200 } 180 }
201 181
202 input_register_device(&mk712_dev); 182 mk712_dev->name = "ICS MicroClock MK712 TouchScreen";
183 mk712_dev->phys = "isa0260/input0";
184 mk712_dev->id.bustype = BUS_ISA;
185 mk712_dev->id.vendor = 0x0005;
186 mk712_dev->id.product = 0x0001;
187 mk712_dev->id.version = 0x0100;
188
189 mk712_dev->open = mk712_open;
190 mk712_dev->close = mk712_close;
203 191
204 printk(KERN_INFO "input: ICS MicroClock MK712 TouchScreen at %#x irq %d\n", mk712_io, mk712_irq); 192 mk712_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
193 mk712_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
194 input_set_abs_params(mk712_dev, ABS_X, 0, 0xfff, 88, 0);
195 input_set_abs_params(mk712_dev, ABS_Y, 0, 0xfff, 88, 0);
205 196
197 if (request_irq(mk712_irq, mk712_interrupt, 0, "mk712", mk712_dev)) {
198 printk(KERN_WARNING "mk712: unable to get IRQ\n");
199 err = -EBUSY;
200 goto fail;
201 }
202
203 input_register_device(mk712_dev);
206 return 0; 204 return 0;
205
206 fail: input_free_device(mk712_dev);
207 release_region(mk712_io, 8);
208 return err;
207} 209}
208 210
209static void __exit mk712_exit(void) 211static void __exit mk712_exit(void)
210{ 212{
211 input_unregister_device(&mk712_dev); 213 input_unregister_device(mk712_dev);
212 free_irq(mk712_irq, &mk712_dev); 214 free_irq(mk712_irq, mk712_dev);
213 release_region(mk712_io, 8); 215 release_region(mk712_io, 8);
214} 216}
215 217
diff --git a/drivers/input/touchscreen/mtouch.c b/drivers/input/touchscreen/mtouch.c
index aa8ee7842179..1d0d37eeef6e 100644
--- a/drivers/input/touchscreen/mtouch.c
+++ b/drivers/input/touchscreen/mtouch.c
@@ -51,14 +51,12 @@ MODULE_LICENSE("GPL");
51#define MTOUCH_GET_YC(data) (((data[4])<<7) | data[3]) 51#define MTOUCH_GET_YC(data) (((data[4])<<7) | data[3])
52#define MTOUCH_GET_TOUCHED(data) (MTOUCH_FORMAT_TABLET_TOUCH_BIT & data[0]) 52#define MTOUCH_GET_TOUCHED(data) (MTOUCH_FORMAT_TABLET_TOUCH_BIT & data[0])
53 53
54static char *mtouch_name = "MicroTouch Serial TouchScreen";
55
56/* 54/*
57 * Per-touchscreen data. 55 * Per-touchscreen data.
58 */ 56 */
59 57
60struct mtouch { 58struct mtouch {
61 struct input_dev dev; 59 struct input_dev *dev;
62 struct serio *serio; 60 struct serio *serio;
63 int idx; 61 int idx;
64 unsigned char data[MTOUCH_MAX_LENGTH]; 62 unsigned char data[MTOUCH_MAX_LENGTH];
@@ -67,7 +65,7 @@ struct mtouch {
67 65
68static void mtouch_process_format_tablet(struct mtouch *mtouch, struct pt_regs *regs) 66static void mtouch_process_format_tablet(struct mtouch *mtouch, struct pt_regs *regs)
69{ 67{
70 struct input_dev *dev = &mtouch->dev; 68 struct input_dev *dev = mtouch->dev;
71 69
72 if (MTOUCH_FORMAT_TABLET_LENGTH == ++mtouch->idx) { 70 if (MTOUCH_FORMAT_TABLET_LENGTH == ++mtouch->idx) {
73 input_regs(dev, regs); 71 input_regs(dev, regs);
@@ -116,9 +114,11 @@ static void mtouch_disconnect(struct serio *serio)
116{ 114{
117 struct mtouch* mtouch = serio_get_drvdata(serio); 115 struct mtouch* mtouch = serio_get_drvdata(serio);
118 116
119 input_unregister_device(&mtouch->dev); 117 input_get_device(mtouch->dev);
118 input_unregister_device(mtouch->dev);
120 serio_close(serio); 119 serio_close(serio);
121 serio_set_drvdata(serio, NULL); 120 serio_set_drvdata(serio, NULL);
121 input_put_device(mtouch->dev);
122 kfree(mtouch); 122 kfree(mtouch);
123} 123}
124 124
@@ -131,46 +131,46 @@ static void mtouch_disconnect(struct serio *serio)
131static int mtouch_connect(struct serio *serio, struct serio_driver *drv) 131static int mtouch_connect(struct serio *serio, struct serio_driver *drv)
132{ 132{
133 struct mtouch *mtouch; 133 struct mtouch *mtouch;
134 struct input_dev *input_dev;
134 int err; 135 int err;
135 136
136 if (!(mtouch = kmalloc(sizeof(*mtouch), GFP_KERNEL))) 137 mtouch = kzalloc(sizeof(struct mtouch), GFP_KERNEL);
137 return -ENOMEM; 138 input_dev = input_allocate_device();
138 139 if (!mtouch || !input_dev) {
139 memset(mtouch, 0, sizeof(*mtouch)); 140 err = -ENOMEM;
140 141 goto fail;
141 init_input_dev(&mtouch->dev); 142 }
142 mtouch->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
143 mtouch->dev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
144
145 input_set_abs_params(&mtouch->dev, ABS_X, MTOUCH_MIN_XC, MTOUCH_MAX_XC, 0, 0);
146 input_set_abs_params(&mtouch->dev, ABS_Y, MTOUCH_MIN_YC, MTOUCH_MAX_YC, 0, 0);
147 143
148 mtouch->serio = serio; 144 mtouch->serio = serio;
149 145 mtouch->dev = input_dev;
150 sprintf(mtouch->phys, "%s/input0", serio->phys); 146 sprintf(mtouch->phys, "%s/input0", serio->phys);
151 147
152 mtouch->dev.private = mtouch; 148 input_dev->private = mtouch;
153 mtouch->dev.name = mtouch_name; 149 input_dev->name = "MicroTouch Serial TouchScreen";
154 mtouch->dev.phys = mtouch->phys; 150 input_dev->phys = mtouch->phys;
155 mtouch->dev.id.bustype = BUS_RS232; 151 input_dev->id.bustype = BUS_RS232;
156 mtouch->dev.id.vendor = SERIO_MICROTOUCH; 152 input_dev->id.vendor = SERIO_MICROTOUCH;
157 mtouch->dev.id.product = 0; 153 input_dev->id.product = 0;
158 mtouch->dev.id.version = 0x0100; 154 input_dev->id.version = 0x0100;
155 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
156 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
157 input_set_abs_params(mtouch->dev, ABS_X, MTOUCH_MIN_XC, MTOUCH_MAX_XC, 0, 0);
158 input_set_abs_params(mtouch->dev, ABS_Y, MTOUCH_MIN_YC, MTOUCH_MAX_YC, 0, 0);
159 159
160 serio_set_drvdata(serio, mtouch); 160 serio_set_drvdata(serio, mtouch);
161 161
162 err = serio_open(serio, drv); 162 err = serio_open(serio, drv);
163 if (err) { 163 if (err)
164 serio_set_drvdata(serio, NULL); 164 goto fail;
165 kfree(mtouch);
166 return err;
167 }
168
169 input_register_device(&mtouch->dev);
170 165
171 printk(KERN_INFO "input: %s on %s\n", mtouch->dev.name, serio->phys); 166 input_register_device(mtouch->dev);
172 167
173 return 0; 168 return 0;
169
170 fail: serio_set_drvdata(serio, NULL);
171 input_free_device(input_dev);
172 kfree(mtouch);
173 return err;
174} 174}
175 175
176/* 176/*
diff --git a/drivers/input/tsdev.c b/drivers/input/tsdev.c
index 50c63a155156..ca1547929d62 100644
--- a/drivers/input/tsdev.c
+++ b/drivers/input/tsdev.c
@@ -53,7 +53,6 @@
53#include <linux/random.h> 53#include <linux/random.h>
54#include <linux/time.h> 54#include <linux/time.h>
55#include <linux/device.h> 55#include <linux/device.h>
56#include <linux/devfs_fs_kernel.h>
57 56
58#ifndef CONFIG_INPUT_TSDEV_SCREEN_X 57#ifndef CONFIG_INPUT_TSDEV_SCREEN_X
59#define CONFIG_INPUT_TSDEV_SCREEN_X 240 58#define CONFIG_INPUT_TSDEV_SCREEN_X 240
@@ -369,6 +368,7 @@ static struct input_handle *tsdev_connect(struct input_handler *handler,
369 struct input_device_id *id) 368 struct input_device_id *id)
370{ 369{
371 struct tsdev *tsdev; 370 struct tsdev *tsdev;
371 struct class_device *cdev;
372 int minor, delta; 372 int minor, delta;
373 373
374 for (minor = 0; minor < TSDEV_MINORS/2 && tsdev_table[minor]; 374 for (minor = 0; minor < TSDEV_MINORS/2 && tsdev_table[minor];
@@ -410,13 +410,13 @@ static struct input_handle *tsdev_connect(struct input_handler *handler,
410 410
411 tsdev_table[minor] = tsdev; 411 tsdev_table[minor] = tsdev;
412 412
413 devfs_mk_cdev(MKDEV(INPUT_MAJOR, TSDEV_MINOR_BASE + minor), 413 cdev = class_device_create(&input_class, &dev->cdev,
414 S_IFCHR|S_IRUGO|S_IWUSR, "input/ts%d", minor);
415 devfs_mk_cdev(MKDEV(INPUT_MAJOR, TSDEV_MINOR_BASE + minor + TSDEV_MINORS/2),
416 S_IFCHR|S_IRUGO|S_IWUSR, "input/tsraw%d", minor);
417 class_device_create(input_class,
418 MKDEV(INPUT_MAJOR, TSDEV_MINOR_BASE + minor), 414 MKDEV(INPUT_MAJOR, TSDEV_MINOR_BASE + minor),
419 dev->dev, "ts%d", minor); 415 dev->cdev.dev, tsdev->name);
416
417 /* temporary symlink to keep userspace happy */
418 sysfs_create_link(&input_class.subsys.kset.kobj, &cdev->kobj,
419 tsdev->name);
420 420
421 return &tsdev->handle; 421 return &tsdev->handle;
422} 422}
@@ -426,10 +426,9 @@ static void tsdev_disconnect(struct input_handle *handle)
426 struct tsdev *tsdev = handle->private; 426 struct tsdev *tsdev = handle->private;
427 struct tsdev_list *list; 427 struct tsdev_list *list;
428 428
429 class_device_destroy(input_class, 429 sysfs_remove_link(&input_class.subsys.kset.kobj, tsdev->name);
430 class_device_destroy(&input_class,
430 MKDEV(INPUT_MAJOR, TSDEV_MINOR_BASE + tsdev->minor)); 431 MKDEV(INPUT_MAJOR, TSDEV_MINOR_BASE + tsdev->minor));
431 devfs_remove("input/ts%d", tsdev->minor);
432 devfs_remove("input/tsraw%d", tsdev->minor);
433 tsdev->exist = 0; 432 tsdev->exist = 0;
434 433
435 if (tsdev->open) { 434 if (tsdev->open) {
diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index 04fb606b5ddd..11ae0fddea04 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1505,7 +1505,7 @@ static int __init capi_init(void)
1505 return PTR_ERR(capi_class); 1505 return PTR_ERR(capi_class);
1506 } 1506 }
1507 1507
1508 class_device_create(capi_class, MKDEV(capi_major, 0), NULL, "capi"); 1508 class_device_create(capi_class, NULL, MKDEV(capi_major, 0), NULL, "capi");
1509 devfs_mk_cdev(MKDEV(capi_major, 0), S_IFCHR | S_IRUSR | S_IWUSR, 1509 devfs_mk_cdev(MKDEV(capi_major, 0), S_IFCHR | S_IRUSR | S_IWUSR,
1510 "isdn/capi20"); 1510 "isdn/capi20");
1511 1511
diff --git a/drivers/isdn/capi/capifs.c b/drivers/isdn/capi/capifs.c
index 3abd7fc6e5ef..7b564c0dd996 100644
--- a/drivers/isdn/capi/capifs.c
+++ b/drivers/isdn/capi/capifs.c
@@ -15,6 +15,7 @@
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/ctype.h> 17#include <linux/ctype.h>
18#include <linux/sched.h> /* current */
18 19
19MODULE_DESCRIPTION("CAPI4Linux: /dev/capi/ filesystem"); 20MODULE_DESCRIPTION("CAPI4Linux: /dev/capi/ filesystem");
20MODULE_AUTHOR("Carsten Paeth"); 21MODULE_AUTHOR("Carsten Paeth");
diff --git a/drivers/isdn/hisax/hfc4s8s_l1.c b/drivers/isdn/hisax/hfc4s8s_l1.c
index 7333377ab31d..e3866b0a97fd 100644
--- a/drivers/isdn/hisax/hfc4s8s_l1.c
+++ b/drivers/isdn/hisax/hfc4s8s_l1.c
@@ -1063,7 +1063,7 @@ tx_b_frame(struct hfc4s8s_btype *bch)
1063 Write_hfc8(l1->hw, A_INC_RES_FIFO, 1); 1063 Write_hfc8(l1->hw, A_INC_RES_FIFO, 1);
1064 } 1064 }
1065 ack_len += skb->truesize; 1065 ack_len += skb->truesize;
1066 bch->tx_skb = 0; 1066 bch->tx_skb = NULL;
1067 bch->tx_cnt = 0; 1067 bch->tx_cnt = 0;
1068 dev_kfree_skb(skb); 1068 dev_kfree_skb(skb);
1069 } else 1069 } else
@@ -1659,10 +1659,10 @@ hfc4s8s_remove(struct pci_dev *pdev)
1659} 1659}
1660 1660
1661static struct pci_driver hfc4s8s_driver = { 1661static struct pci_driver hfc4s8s_driver = {
1662 name:"hfc4s8s_l1", 1662 .name = "hfc4s8s_l1",
1663 probe:hfc4s8s_probe, 1663 .probe = hfc4s8s_probe,
1664 remove:__devexit_p(hfc4s8s_remove), 1664 .remove = __devexit_p(hfc4s8s_remove),
1665 id_table:hfc4s8s_ids, 1665 .id_table = hfc4s8s_ids,
1666}; 1666};
1667 1667
1668/**********************/ 1668/**********************/
diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
index c0dc1e3fa58b..d2ead1776c16 100644
--- a/drivers/macintosh/adb.c
+++ b/drivers/macintosh/adb.c
@@ -905,5 +905,5 @@ adbdev_init(void)
905 adb_dev_class = class_create(THIS_MODULE, "adb"); 905 adb_dev_class = class_create(THIS_MODULE, "adb");
906 if (IS_ERR(adb_dev_class)) 906 if (IS_ERR(adb_dev_class))
907 return; 907 return;
908 class_device_create(adb_dev_class, MKDEV(ADB_MAJOR, 0), NULL, "adb"); 908 class_device_create(adb_dev_class, NULL, MKDEV(ADB_MAJOR, 0), NULL, "adb");
909} 909}
diff --git a/drivers/macintosh/adbhid.c b/drivers/macintosh/adbhid.c
index db654e8bd67e..cdb6d0283195 100644
--- a/drivers/macintosh/adbhid.c
+++ b/drivers/macintosh/adbhid.c
@@ -206,7 +206,7 @@ u8 adb_to_linux_keycodes[128] = {
206}; 206};
207 207
208struct adbhid { 208struct adbhid {
209 struct input_dev input; 209 struct input_dev *input;
210 int id; 210 int id;
211 int default_id; 211 int default_id;
212 int original_handler_id; 212 int original_handler_id;
@@ -291,10 +291,10 @@ adbhid_input_keycode(int id, int keycode, int repeat, struct pt_regs *regs)
291 291
292 switch (keycode) { 292 switch (keycode) {
293 case ADB_KEY_CAPSLOCK: /* Generate down/up events for CapsLock everytime. */ 293 case ADB_KEY_CAPSLOCK: /* Generate down/up events for CapsLock everytime. */
294 input_regs(&ahid->input, regs); 294 input_regs(ahid->input, regs);
295 input_report_key(&ahid->input, KEY_CAPSLOCK, 1); 295 input_report_key(ahid->input, KEY_CAPSLOCK, 1);
296 input_report_key(&ahid->input, KEY_CAPSLOCK, 0); 296 input_report_key(ahid->input, KEY_CAPSLOCK, 0);
297 input_sync(&ahid->input); 297 input_sync(ahid->input);
298 return; 298 return;
299#ifdef CONFIG_PPC_PMAC 299#ifdef CONFIG_PPC_PMAC
300 case ADB_KEY_POWER_OLD: /* Power key on PBook 3400 needs remapping */ 300 case ADB_KEY_POWER_OLD: /* Power key on PBook 3400 needs remapping */
@@ -347,10 +347,10 @@ adbhid_input_keycode(int id, int keycode, int repeat, struct pt_regs *regs)
347 } 347 }
348 348
349 if (adbhid[id]->keycode[keycode]) { 349 if (adbhid[id]->keycode[keycode]) {
350 input_regs(&adbhid[id]->input, regs); 350 input_regs(adbhid[id]->input, regs);
351 input_report_key(&adbhid[id]->input, 351 input_report_key(adbhid[id]->input,
352 adbhid[id]->keycode[keycode], !up_flag); 352 adbhid[id]->keycode[keycode], !up_flag);
353 input_sync(&adbhid[id]->input); 353 input_sync(adbhid[id]->input);
354 } else 354 } else
355 printk(KERN_INFO "Unhandled ADB key (scancode %#02x) %s.\n", keycode, 355 printk(KERN_INFO "Unhandled ADB key (scancode %#02x) %s.\n", keycode,
356 up_flag ? "released" : "pressed"); 356 up_flag ? "released" : "pressed");
@@ -441,20 +441,20 @@ adbhid_mouse_input(unsigned char *data, int nb, struct pt_regs *regs, int autopo
441 break; 441 break;
442 } 442 }
443 443
444 input_regs(&adbhid[id]->input, regs); 444 input_regs(adbhid[id]->input, regs);
445 445
446 input_report_key(&adbhid[id]->input, BTN_LEFT, !((data[1] >> 7) & 1)); 446 input_report_key(adbhid[id]->input, BTN_LEFT, !((data[1] >> 7) & 1));
447 input_report_key(&adbhid[id]->input, BTN_MIDDLE, !((data[2] >> 7) & 1)); 447 input_report_key(adbhid[id]->input, BTN_MIDDLE, !((data[2] >> 7) & 1));
448 448
449 if (nb >= 4 && adbhid[id]->mouse_kind != ADBMOUSE_TRACKPAD) 449 if (nb >= 4 && adbhid[id]->mouse_kind != ADBMOUSE_TRACKPAD)
450 input_report_key(&adbhid[id]->input, BTN_RIGHT, !((data[3] >> 7) & 1)); 450 input_report_key(adbhid[id]->input, BTN_RIGHT, !((data[3] >> 7) & 1));
451 451
452 input_report_rel(&adbhid[id]->input, REL_X, 452 input_report_rel(adbhid[id]->input, REL_X,
453 ((data[2]&0x7f) < 64 ? (data[2]&0x7f) : (data[2]&0x7f)-128 )); 453 ((data[2]&0x7f) < 64 ? (data[2]&0x7f) : (data[2]&0x7f)-128 ));
454 input_report_rel(&adbhid[id]->input, REL_Y, 454 input_report_rel(adbhid[id]->input, REL_Y,
455 ((data[1]&0x7f) < 64 ? (data[1]&0x7f) : (data[1]&0x7f)-128 )); 455 ((data[1]&0x7f) < 64 ? (data[1]&0x7f) : (data[1]&0x7f)-128 ));
456 456
457 input_sync(&adbhid[id]->input); 457 input_sync(adbhid[id]->input);
458} 458}
459 459
460static void 460static void
@@ -467,7 +467,7 @@ adbhid_buttons_input(unsigned char *data, int nb, struct pt_regs *regs, int auto
467 return; 467 return;
468 } 468 }
469 469
470 input_regs(&adbhid[id]->input, regs); 470 input_regs(adbhid[id]->input, regs);
471 471
472 switch (adbhid[id]->original_handler_id) { 472 switch (adbhid[id]->original_handler_id) {
473 default: 473 default:
@@ -477,19 +477,19 @@ adbhid_buttons_input(unsigned char *data, int nb, struct pt_regs *regs, int auto
477 477
478 switch (data[1] & 0x0f) { 478 switch (data[1] & 0x0f) {
479 case 0x0: /* microphone */ 479 case 0x0: /* microphone */
480 input_report_key(&adbhid[id]->input, KEY_SOUND, down); 480 input_report_key(adbhid[id]->input, KEY_SOUND, down);
481 break; 481 break;
482 482
483 case 0x1: /* mute */ 483 case 0x1: /* mute */
484 input_report_key(&adbhid[id]->input, KEY_MUTE, down); 484 input_report_key(adbhid[id]->input, KEY_MUTE, down);
485 break; 485 break;
486 486
487 case 0x2: /* volume decrease */ 487 case 0x2: /* volume decrease */
488 input_report_key(&adbhid[id]->input, KEY_VOLUMEDOWN, down); 488 input_report_key(adbhid[id]->input, KEY_VOLUMEDOWN, down);
489 break; 489 break;
490 490
491 case 0x3: /* volume increase */ 491 case 0x3: /* volume increase */
492 input_report_key(&adbhid[id]->input, KEY_VOLUMEUP, down); 492 input_report_key(adbhid[id]->input, KEY_VOLUMEUP, down);
493 break; 493 break;
494 494
495 default: 495 default:
@@ -513,19 +513,19 @@ adbhid_buttons_input(unsigned char *data, int nb, struct pt_regs *regs, int auto
513 513
514 switch (data[1] & 0x0f) { 514 switch (data[1] & 0x0f) {
515 case 0x8: /* mute */ 515 case 0x8: /* mute */
516 input_report_key(&adbhid[id]->input, KEY_MUTE, down); 516 input_report_key(adbhid[id]->input, KEY_MUTE, down);
517 break; 517 break;
518 518
519 case 0x7: /* volume decrease */ 519 case 0x7: /* volume decrease */
520 input_report_key(&adbhid[id]->input, KEY_VOLUMEDOWN, down); 520 input_report_key(adbhid[id]->input, KEY_VOLUMEDOWN, down);
521 break; 521 break;
522 522
523 case 0x6: /* volume increase */ 523 case 0x6: /* volume increase */
524 input_report_key(&adbhid[id]->input, KEY_VOLUMEUP, down); 524 input_report_key(adbhid[id]->input, KEY_VOLUMEUP, down);
525 break; 525 break;
526 526
527 case 0xb: /* eject */ 527 case 0xb: /* eject */
528 input_report_key(&adbhid[id]->input, KEY_EJECTCD, down); 528 input_report_key(adbhid[id]->input, KEY_EJECTCD, down);
529 break; 529 break;
530 530
531 case 0xa: /* brightness decrease */ 531 case 0xa: /* brightness decrease */
@@ -539,7 +539,7 @@ adbhid_buttons_input(unsigned char *data, int nb, struct pt_regs *regs, int auto
539 } 539 }
540 } 540 }
541#endif /* CONFIG_PMAC_BACKLIGHT */ 541#endif /* CONFIG_PMAC_BACKLIGHT */
542 input_report_key(&adbhid[id]->input, KEY_BRIGHTNESSDOWN, down); 542 input_report_key(adbhid[id]->input, KEY_BRIGHTNESSDOWN, down);
543 break; 543 break;
544 544
545 case 0x9: /* brightness increase */ 545 case 0x9: /* brightness increase */
@@ -553,19 +553,19 @@ adbhid_buttons_input(unsigned char *data, int nb, struct pt_regs *regs, int auto
553 } 553 }
554 } 554 }
555#endif /* CONFIG_PMAC_BACKLIGHT */ 555#endif /* CONFIG_PMAC_BACKLIGHT */
556 input_report_key(&adbhid[id]->input, KEY_BRIGHTNESSUP, down); 556 input_report_key(adbhid[id]->input, KEY_BRIGHTNESSUP, down);
557 break; 557 break;
558 558
559 case 0xc: /* videomode switch */ 559 case 0xc: /* videomode switch */
560 input_report_key(&adbhid[id]->input, KEY_SWITCHVIDEOMODE, down); 560 input_report_key(adbhid[id]->input, KEY_SWITCHVIDEOMODE, down);
561 break; 561 break;
562 562
563 case 0xd: /* keyboard illumination toggle */ 563 case 0xd: /* keyboard illumination toggle */
564 input_report_key(&adbhid[id]->input, KEY_KBDILLUMTOGGLE, down); 564 input_report_key(adbhid[id]->input, KEY_KBDILLUMTOGGLE, down);
565 break; 565 break;
566 566
567 case 0xe: /* keyboard illumination decrease */ 567 case 0xe: /* keyboard illumination decrease */
568 input_report_key(&adbhid[id]->input, KEY_KBDILLUMDOWN, down); 568 input_report_key(adbhid[id]->input, KEY_KBDILLUMDOWN, down);
569 break; 569 break;
570 570
571 case 0xf: 571 case 0xf:
@@ -573,7 +573,7 @@ adbhid_buttons_input(unsigned char *data, int nb, struct pt_regs *regs, int auto
573 case 0x8f: 573 case 0x8f:
574 case 0x0f: 574 case 0x0f:
575 /* keyboard illumination increase */ 575 /* keyboard illumination increase */
576 input_report_key(&adbhid[id]->input, KEY_KBDILLUMUP, down); 576 input_report_key(adbhid[id]->input, KEY_KBDILLUMUP, down);
577 break; 577 break;
578 578
579 case 0x7f: 579 case 0x7f:
@@ -596,7 +596,7 @@ adbhid_buttons_input(unsigned char *data, int nb, struct pt_regs *regs, int auto
596 break; 596 break;
597 } 597 }
598 598
599 input_sync(&adbhid[id]->input); 599 input_sync(adbhid[id]->input);
600} 600}
601 601
602static struct adb_request led_request; 602static struct adb_request led_request;
@@ -683,7 +683,7 @@ adb_message_handler(struct notifier_block *this, unsigned long code, void *x)
683 int i; 683 int i;
684 for (i = 1; i < 16; i++) { 684 for (i = 1; i < 16; i++) {
685 if (adbhid[i]) 685 if (adbhid[i])
686 del_timer_sync(&adbhid[i]->input.timer); 686 del_timer_sync(&adbhid[i]->input->timer);
687 } 687 }
688 } 688 }
689 689
@@ -699,153 +699,163 @@ adb_message_handler(struct notifier_block *this, unsigned long code, void *x)
699 return NOTIFY_DONE; 699 return NOTIFY_DONE;
700} 700}
701 701
702static void 702static int
703adbhid_input_register(int id, int default_id, int original_handler_id, 703adbhid_input_register(int id, int default_id, int original_handler_id,
704 int current_handler_id, int mouse_kind) 704 int current_handler_id, int mouse_kind)
705{ 705{
706 struct adbhid *hid;
707 struct input_dev *input_dev;
708 int err;
706 int i; 709 int i;
707 710
708 if (adbhid[id]) { 711 if (adbhid[id]) {
709 printk(KERN_ERR "Trying to reregister ADB HID on ID %d\n", id); 712 printk(KERN_ERR "Trying to reregister ADB HID on ID %d\n", id);
710 return; 713 return -EEXIST;
711 } 714 }
712 715
713 if (!(adbhid[id] = kmalloc(sizeof(struct adbhid), GFP_KERNEL))) 716 adbhid[id] = hid = kzalloc(sizeof(struct adbhid), GFP_KERNEL);
714 return; 717 input_dev = input_allocate_device();
715 718 if (!hid || !input_dev) {
716 memset(adbhid[id], 0, sizeof(struct adbhid)); 719 err = -ENOMEM;
717 sprintf(adbhid[id]->phys, "adb%d:%d.%02x/input", id, default_id, original_handler_id); 720 goto fail;
718 721
719 init_input_dev(&adbhid[id]->input); 722 }
720 723
721 adbhid[id]->id = default_id; 724 sprintf(hid->phys, "adb%d:%d.%02x/input", id, default_id, original_handler_id);
722 adbhid[id]->original_handler_id = original_handler_id; 725
723 adbhid[id]->current_handler_id = current_handler_id; 726 hid->id = default_id;
724 adbhid[id]->mouse_kind = mouse_kind; 727 hid->original_handler_id = original_handler_id;
725 adbhid[id]->flags = 0; 728 hid->current_handler_id = current_handler_id;
726 adbhid[id]->input.private = adbhid[id]; 729 hid->mouse_kind = mouse_kind;
727 adbhid[id]->input.name = adbhid[id]->name; 730 hid->flags = 0;
728 adbhid[id]->input.phys = adbhid[id]->phys; 731 input_dev->private = hid;
729 adbhid[id]->input.id.bustype = BUS_ADB; 732 input_dev->name = hid->name;
730 adbhid[id]->input.id.vendor = 0x0001; 733 input_dev->phys = hid->phys;
731 adbhid[id]->input.id.product = (id << 12) | (default_id << 8) | original_handler_id; 734 input_dev->id.bustype = BUS_ADB;
732 adbhid[id]->input.id.version = 0x0100; 735 input_dev->id.vendor = 0x0001;
736 input_dev->id.product = (id << 12) | (default_id << 8) | original_handler_id;
737 input_dev->id.version = 0x0100;
733 738
734 switch (default_id) { 739 switch (default_id) {
735 case ADB_KEYBOARD: 740 case ADB_KEYBOARD:
736 if (!(adbhid[id]->keycode = kmalloc(sizeof(adb_to_linux_keycodes), GFP_KERNEL))) { 741 hid->keycode = kmalloc(sizeof(adb_to_linux_keycodes), GFP_KERNEL);
737 kfree(adbhid[id]); 742 if (!hid->keycode) {
738 return; 743 err = -ENOMEM;
744 goto fail;
739 } 745 }
740 746
741 sprintf(adbhid[id]->name, "ADB keyboard"); 747 sprintf(hid->name, "ADB keyboard");
742 748
743 memcpy(adbhid[id]->keycode, adb_to_linux_keycodes, sizeof(adb_to_linux_keycodes)); 749 memcpy(hid->keycode, adb_to_linux_keycodes, sizeof(adb_to_linux_keycodes));
744 750
745 printk(KERN_INFO "Detected ADB keyboard, type "); 751 printk(KERN_INFO "Detected ADB keyboard, type ");
746 switch (original_handler_id) { 752 switch (original_handler_id) {
747 default: 753 default:
748 printk("<unknown>.\n"); 754 printk("<unknown>.\n");
749 adbhid[id]->input.id.version = ADB_KEYBOARD_UNKNOWN; 755 input_dev->id.version = ADB_KEYBOARD_UNKNOWN;
750 break; 756 break;
751 757
752 case 0x01: case 0x02: case 0x03: case 0x06: case 0x08: 758 case 0x01: case 0x02: case 0x03: case 0x06: case 0x08:
753 case 0x0C: case 0x10: case 0x18: case 0x1B: case 0x1C: 759 case 0x0C: case 0x10: case 0x18: case 0x1B: case 0x1C:
754 case 0xC0: case 0xC3: case 0xC6: 760 case 0xC0: case 0xC3: case 0xC6:
755 printk("ANSI.\n"); 761 printk("ANSI.\n");
756 adbhid[id]->input.id.version = ADB_KEYBOARD_ANSI; 762 input_dev->id.version = ADB_KEYBOARD_ANSI;
757 break; 763 break;
758 764
759 case 0x04: case 0x05: case 0x07: case 0x09: case 0x0D: 765 case 0x04: case 0x05: case 0x07: case 0x09: case 0x0D:
760 case 0x11: case 0x14: case 0x19: case 0x1D: case 0xC1: 766 case 0x11: case 0x14: case 0x19: case 0x1D: case 0xC1:
761 case 0xC4: case 0xC7: 767 case 0xC4: case 0xC7:
762 printk("ISO, swapping keys.\n"); 768 printk("ISO, swapping keys.\n");
763 adbhid[id]->input.id.version = ADB_KEYBOARD_ISO; 769 input_dev->id.version = ADB_KEYBOARD_ISO;
764 i = adbhid[id]->keycode[10]; 770 i = hid->keycode[10];
765 adbhid[id]->keycode[10] = adbhid[id]->keycode[50]; 771 hid->keycode[10] = hid->keycode[50];
766 adbhid[id]->keycode[50] = i; 772 hid->keycode[50] = i;
767 break; 773 break;
768 774
769 case 0x12: case 0x15: case 0x16: case 0x17: case 0x1A: 775 case 0x12: case 0x15: case 0x16: case 0x17: case 0x1A:
770 case 0x1E: case 0xC2: case 0xC5: case 0xC8: case 0xC9: 776 case 0x1E: case 0xC2: case 0xC5: case 0xC8: case 0xC9:
771 printk("JIS.\n"); 777 printk("JIS.\n");
772 adbhid[id]->input.id.version = ADB_KEYBOARD_JIS; 778 input_dev->id.version = ADB_KEYBOARD_JIS;
773 break; 779 break;
774 } 780 }
775 781
776 for (i = 0; i < 128; i++) 782 for (i = 0; i < 128; i++)
777 if (adbhid[id]->keycode[i]) 783 if (hid->keycode[i])
778 set_bit(adbhid[id]->keycode[i], adbhid[id]->input.keybit); 784 set_bit(hid->keycode[i], input_dev->keybit);
779 785
780 adbhid[id]->input.evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_REP); 786 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_REP);
781 adbhid[id]->input.ledbit[0] = BIT(LED_SCROLLL) | BIT(LED_CAPSL) | BIT(LED_NUML); 787 input_dev->ledbit[0] = BIT(LED_SCROLLL) | BIT(LED_CAPSL) | BIT(LED_NUML);
782 adbhid[id]->input.event = adbhid_kbd_event; 788 input_dev->event = adbhid_kbd_event;
783 adbhid[id]->input.keycodemax = 127; 789 input_dev->keycodemax = 127;
784 adbhid[id]->input.keycodesize = 1; 790 input_dev->keycodesize = 1;
785 break; 791 break;
786 792
787 case ADB_MOUSE: 793 case ADB_MOUSE:
788 sprintf(adbhid[id]->name, "ADB mouse"); 794 sprintf(hid->name, "ADB mouse");
789 795
790 adbhid[id]->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REL); 796 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
791 adbhid[id]->input.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT); 797 input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
792 adbhid[id]->input.relbit[0] = BIT(REL_X) | BIT(REL_Y); 798 input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
793 break; 799 break;
794 800
795 case ADB_MISC: 801 case ADB_MISC:
796 switch (original_handler_id) { 802 switch (original_handler_id) {
797 case 0x02: /* Adjustable keyboard button device */ 803 case 0x02: /* Adjustable keyboard button device */
798 sprintf(adbhid[id]->name, "ADB adjustable keyboard buttons"); 804 sprintf(hid->name, "ADB adjustable keyboard buttons");
799 adbhid[id]->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP); 805 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
800 set_bit(KEY_SOUND, adbhid[id]->input.keybit); 806 set_bit(KEY_SOUND, input_dev->keybit);
801 set_bit(KEY_MUTE, adbhid[id]->input.keybit); 807 set_bit(KEY_MUTE, input_dev->keybit);
802 set_bit(KEY_VOLUMEUP, adbhid[id]->input.keybit); 808 set_bit(KEY_VOLUMEUP, input_dev->keybit);
803 set_bit(KEY_VOLUMEDOWN, adbhid[id]->input.keybit); 809 set_bit(KEY_VOLUMEDOWN, input_dev->keybit);
804 break; 810 break;
805 case 0x1f: /* Powerbook button device */ 811 case 0x1f: /* Powerbook button device */
806 sprintf(adbhid[id]->name, "ADB Powerbook buttons"); 812 sprintf(hid->name, "ADB Powerbook buttons");
807 adbhid[id]->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP); 813 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
808 set_bit(KEY_MUTE, adbhid[id]->input.keybit); 814 set_bit(KEY_MUTE, input_dev->keybit);
809 set_bit(KEY_VOLUMEUP, adbhid[id]->input.keybit); 815 set_bit(KEY_VOLUMEUP, input_dev->keybit);
810 set_bit(KEY_VOLUMEDOWN, adbhid[id]->input.keybit); 816 set_bit(KEY_VOLUMEDOWN, input_dev->keybit);
811 set_bit(KEY_BRIGHTNESSUP, adbhid[id]->input.keybit); 817 set_bit(KEY_BRIGHTNESSUP, input_dev->keybit);
812 set_bit(KEY_BRIGHTNESSDOWN, adbhid[id]->input.keybit); 818 set_bit(KEY_BRIGHTNESSDOWN, input_dev->keybit);
813 set_bit(KEY_EJECTCD, adbhid[id]->input.keybit); 819 set_bit(KEY_EJECTCD, input_dev->keybit);
814 set_bit(KEY_SWITCHVIDEOMODE, adbhid[id]->input.keybit); 820 set_bit(KEY_SWITCHVIDEOMODE, input_dev->keybit);
815 set_bit(KEY_KBDILLUMTOGGLE, adbhid[id]->input.keybit); 821 set_bit(KEY_KBDILLUMTOGGLE, input_dev->keybit);
816 set_bit(KEY_KBDILLUMDOWN, adbhid[id]->input.keybit); 822 set_bit(KEY_KBDILLUMDOWN, input_dev->keybit);
817 set_bit(KEY_KBDILLUMUP, adbhid[id]->input.keybit); 823 set_bit(KEY_KBDILLUMUP, input_dev->keybit);
818 break; 824 break;
819 } 825 }
820 if (adbhid[id]->name[0]) 826 if (hid->name[0])
821 break; 827 break;
822 /* else fall through */ 828 /* else fall through */
823 829
824 default: 830 default:
825 printk(KERN_INFO "Trying to register unknown ADB device to input layer.\n"); 831 printk(KERN_INFO "Trying to register unknown ADB device to input layer.\n");
826 kfree(adbhid[id]); 832 err = -ENODEV;
827 return; 833 goto fail;
828 } 834 }
829 835
830 adbhid[id]->input.keycode = adbhid[id]->keycode; 836 input_dev->keycode = hid->keycode;
831
832 input_register_device(&adbhid[id]->input);
833 837
834 printk(KERN_INFO "input: %s on %s\n", 838 input_register_device(input_dev);
835 adbhid[id]->name, adbhid[id]->phys);
836 839
837 if (default_id == ADB_KEYBOARD) { 840 if (default_id == ADB_KEYBOARD) {
838 /* HACK WARNING!! This should go away as soon there is an utility 841 /* HACK WARNING!! This should go away as soon there is an utility
839 * to control that for event devices. 842 * to control that for event devices.
840 */ 843 */
841 adbhid[id]->input.rep[REP_DELAY] = 500; /* input layer default: 250 */ 844 input_dev->rep[REP_DELAY] = 500; /* input layer default: 250 */
842 adbhid[id]->input.rep[REP_PERIOD] = 66; /* input layer default: 33 */ 845 input_dev->rep[REP_PERIOD] = 66; /* input layer default: 33 */
843 } 846 }
847
848 return 0;
849
850 fail: input_free_device(input_dev);
851 kfree(hid);
852 adbhid[id] = NULL;
853 return err;
844} 854}
845 855
846static void adbhid_input_unregister(int id) 856static void adbhid_input_unregister(int id)
847{ 857{
848 input_unregister_device(&adbhid[id]->input); 858 input_unregister_device(adbhid[id]->input);
849 if (adbhid[id]->keycode) 859 if (adbhid[id]->keycode)
850 kfree(adbhid[id]->keycode); 860 kfree(adbhid[id]->keycode);
851 kfree(adbhid[id]); 861 kfree(adbhid[id]);
@@ -858,7 +868,7 @@ adbhid_input_reregister(int id, int default_id, int org_handler_id,
858 int cur_handler_id, int mk) 868 int cur_handler_id, int mk)
859{ 869{
860 if (adbhid[id]) { 870 if (adbhid[id]) {
861 if (adbhid[id]->input.id.product != 871 if (adbhid[id]->input->id.product !=
862 ((id << 12)|(default_id << 8)|org_handler_id)) { 872 ((id << 12)|(default_id << 8)|org_handler_id)) {
863 adbhid_input_unregister(id); 873 adbhid_input_unregister(id);
864 adbhid_input_register(id, default_id, org_handler_id, 874 adbhid_input_register(id, default_id, org_handler_id,
diff --git a/drivers/macintosh/mac_hid.c b/drivers/macintosh/mac_hid.c
index 5ad3a5a9eb7f..a66636116f0b 100644
--- a/drivers/macintosh/mac_hid.c
+++ b/drivers/macintosh/mac_hid.c
@@ -16,8 +16,8 @@
16#include <linux/module.h> 16#include <linux/module.h>
17 17
18 18
19static struct input_dev emumousebtn; 19static struct input_dev *emumousebtn;
20static void emumousebtn_input_register(void); 20static int emumousebtn_input_register(void);
21static int mouse_emulate_buttons = 0; 21static int mouse_emulate_buttons = 0;
22static int mouse_button2_keycode = KEY_RIGHTCTRL; /* right control key */ 22static int mouse_button2_keycode = KEY_RIGHTCTRL; /* right control key */
23static int mouse_button3_keycode = KEY_RIGHTALT; /* right option key */ 23static int mouse_button3_keycode = KEY_RIGHTALT; /* right option key */
@@ -90,10 +90,10 @@ int mac_hid_mouse_emulate_buttons(int caller, unsigned int keycode, int down)
90 && (keycode == mouse_button2_keycode 90 && (keycode == mouse_button2_keycode
91 || keycode == mouse_button3_keycode)) { 91 || keycode == mouse_button3_keycode)) {
92 if (mouse_emulate_buttons == 1) { 92 if (mouse_emulate_buttons == 1) {
93 input_report_key(&emumousebtn, 93 input_report_key(emumousebtn,
94 keycode == mouse_button2_keycode ? BTN_MIDDLE : BTN_RIGHT, 94 keycode == mouse_button2_keycode ? BTN_MIDDLE : BTN_RIGHT,
95 down); 95 down);
96 input_sync(&emumousebtn); 96 input_sync(emumousebtn);
97 return 1; 97 return 1;
98 } 98 }
99 mouse_last_keycode = down ? keycode : 0; 99 mouse_last_keycode = down ? keycode : 0;
@@ -105,30 +105,34 @@ int mac_hid_mouse_emulate_buttons(int caller, unsigned int keycode, int down)
105 105
106EXPORT_SYMBOL(mac_hid_mouse_emulate_buttons); 106EXPORT_SYMBOL(mac_hid_mouse_emulate_buttons);
107 107
108static void emumousebtn_input_register(void) 108static int emumousebtn_input_register(void)
109{ 109{
110 emumousebtn.name = "Macintosh mouse button emulation"; 110 emumousebtn = input_allocate_device();
111 if (!emumousebtn)
112 return -ENOMEM;
111 113
112 init_input_dev(&emumousebtn); 114 emumousebtn->name = "Macintosh mouse button emulation";
115 emumousebtn->id.bustype = BUS_ADB;
116 emumousebtn->id.vendor = 0x0001;
117 emumousebtn->id.product = 0x0001;
118 emumousebtn->id.version = 0x0100;
113 119
114 emumousebtn.evbit[0] = BIT(EV_KEY) | BIT(EV_REL); 120 emumousebtn->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
115 emumousebtn.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT); 121 emumousebtn->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
116 emumousebtn.relbit[0] = BIT(REL_X) | BIT(REL_Y); 122 emumousebtn->relbit[0] = BIT(REL_X) | BIT(REL_Y);
117 123
118 emumousebtn.id.bustype = BUS_ADB; 124 input_register_device(emumousebtn);
119 emumousebtn.id.vendor = 0x0001;
120 emumousebtn.id.product = 0x0001;
121 emumousebtn.id.version = 0x0100;
122 125
123 input_register_device(&emumousebtn); 126 return 0;
124
125 printk(KERN_INFO "input: Macintosh mouse button emulation\n");
126} 127}
127 128
128int __init mac_hid_init(void) 129int __init mac_hid_init(void)
129{ 130{
131 int err;
130 132
131 emumousebtn_input_register(); 133 err = emumousebtn_input_register();
134 if (err)
135 return err;
132 136
133#if defined(CONFIG_SYSCTL) 137#if defined(CONFIG_SYSCTL)
134 mac_hid_sysctl_header = register_sysctl_table(mac_hid_root_dir, 1); 138 mac_hid_sysctl_header = register_sysctl_table(mac_hid_root_dir, 1);
diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
index 1ee003346923..c34c96d18907 100644
--- a/drivers/macintosh/macio_asic.c
+++ b/drivers/macintosh/macio_asic.c
@@ -17,6 +17,8 @@
17#include <linux/pci_ids.h> 17#include <linux/pci_ids.h>
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/slab.h>
21
20#include <asm/machdep.h> 22#include <asm/machdep.h>
21#include <asm/macio.h> 23#include <asm/macio.h>
22#include <asm/pmac_feature.h> 24#include <asm/pmac_feature.h>
diff --git a/drivers/mca/mca-device.c b/drivers/mca/mca-device.c
index 76d430aa243f..e7adf89fae41 100644
--- a/drivers/mca/mca-device.c
+++ b/drivers/mca/mca-device.c
@@ -29,6 +29,7 @@
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/device.h> 30#include <linux/device.h>
31#include <linux/mca.h> 31#include <linux/mca.h>
32#include <linux/string.h>
32 33
33/** 34/**
34 * mca_device_read_stored_pos - read POS register from stored data 35 * mca_device_read_stored_pos - read POS register from stored data
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 2fba2bbe72d8..01654fcabc52 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -91,7 +91,7 @@ int bitmap_active(struct bitmap *bitmap)
91 91
92#define WRITE_POOL_SIZE 256 92#define WRITE_POOL_SIZE 256
93/* mempool for queueing pending writes on the bitmap file */ 93/* mempool for queueing pending writes on the bitmap file */
94static void *write_pool_alloc(unsigned int gfp_flags, void *data) 94static void *write_pool_alloc(gfp_t gfp_flags, void *data)
95{ 95{
96 return kmalloc(sizeof(struct page_list), gfp_flags); 96 return kmalloc(sizeof(struct page_list), gfp_flags);
97} 97}
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index b6148f6f7836..cf6631056683 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -15,7 +15,7 @@
15#include <linux/crypto.h> 15#include <linux/crypto.h>
16#include <linux/workqueue.h> 16#include <linux/workqueue.h>
17#include <asm/atomic.h> 17#include <asm/atomic.h>
18#include <asm/scatterlist.h> 18#include <linux/scatterlist.h>
19#include <asm/page.h> 19#include <asm/page.h>
20 20
21#include "dm.h" 21#include "dm.h"
@@ -164,9 +164,7 @@ static int crypt_iv_essiv_ctr(struct crypt_config *cc, struct dm_target *ti,
164 return -ENOMEM; 164 return -ENOMEM;
165 } 165 }
166 166
167 sg.page = virt_to_page(cc->key); 167 sg_set_buf(&sg, cc->key, cc->key_size);
168 sg.offset = offset_in_page(cc->key);
169 sg.length = cc->key_size;
170 crypto_digest_digest(hash_tfm, &sg, 1, salt); 168 crypto_digest_digest(hash_tfm, &sg, 1, salt);
171 crypto_free_tfm(hash_tfm); 169 crypto_free_tfm(hash_tfm);
172 170
@@ -207,14 +205,12 @@ static void crypt_iv_essiv_dtr(struct crypt_config *cc)
207 205
208static int crypt_iv_essiv_gen(struct crypt_config *cc, u8 *iv, sector_t sector) 206static int crypt_iv_essiv_gen(struct crypt_config *cc, u8 *iv, sector_t sector)
209{ 207{
210 struct scatterlist sg = { NULL, }; 208 struct scatterlist sg;
211 209
212 memset(iv, 0, cc->iv_size); 210 memset(iv, 0, cc->iv_size);
213 *(u64 *)iv = cpu_to_le64(sector); 211 *(u64 *)iv = cpu_to_le64(sector);
214 212
215 sg.page = virt_to_page(iv); 213 sg_set_buf(&sg, iv, cc->iv_size);
216 sg.offset = offset_in_page(iv);
217 sg.length = cc->iv_size;
218 crypto_cipher_encrypt((struct crypto_tfm *)cc->iv_gen_private, 214 crypto_cipher_encrypt((struct crypto_tfm *)cc->iv_gen_private,
219 &sg, &sg, cc->iv_size); 215 &sg, &sg, cc->iv_size);
220 216
@@ -331,7 +327,7 @@ crypt_alloc_buffer(struct crypt_config *cc, unsigned int size,
331{ 327{
332 struct bio *bio; 328 struct bio *bio;
333 unsigned int nr_iovecs = (size + PAGE_SIZE - 1) >> PAGE_SHIFT; 329 unsigned int nr_iovecs = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
334 int gfp_mask = GFP_NOIO | __GFP_HIGHMEM; 330 gfp_t gfp_mask = GFP_NOIO | __GFP_HIGHMEM;
335 unsigned int i; 331 unsigned int i;
336 332
337 /* 333 /*
diff --git a/drivers/media/common/ir-common.c b/drivers/media/common/ir-common.c
index a0e700d7a4a4..31fccb4f05d6 100644
--- a/drivers/media/common/ir-common.c
+++ b/drivers/media/common/ir-common.c
@@ -22,6 +22,7 @@
22 22
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/moduleparam.h> 24#include <linux/moduleparam.h>
25#include <linux/string.h>
25#include <media/ir-common.h> 26#include <media/ir-common.h>
26 27
27/* -------------------------------------------------------------------------- */ 28/* -------------------------------------------------------------------------- */
@@ -252,7 +253,6 @@ void ir_input_init(struct input_dev *dev, struct ir_input_state *ir,
252 if (ir_codes) 253 if (ir_codes)
253 memcpy(ir->ir_codes, ir_codes, sizeof(ir->ir_codes)); 254 memcpy(ir->ir_codes, ir_codes, sizeof(ir->ir_codes));
254 255
255 init_input_dev(dev);
256 dev->keycode = ir->ir_codes; 256 dev->keycode = ir->ir_codes;
257 dev->keycodesize = sizeof(IR_KEYTAB_TYPE); 257 dev->keycodesize = sizeof(IR_KEYTAB_TYPE);
258 dev->keycodemax = IR_KEYTAB_SIZE; 258 dev->keycodemax = IR_KEYTAB_SIZE;
diff --git a/drivers/media/dvb/cinergyT2/cinergyT2.c b/drivers/media/dvb/cinergyT2/cinergyT2.c
index 6db0929ef53d..a1607e7d6d6b 100644
--- a/drivers/media/dvb/cinergyT2/cinergyT2.c
+++ b/drivers/media/dvb/cinergyT2/cinergyT2.c
@@ -137,7 +137,8 @@ struct cinergyt2 {
137 struct urb *stream_urb [STREAM_URB_COUNT]; 137 struct urb *stream_urb [STREAM_URB_COUNT];
138 138
139#ifdef ENABLE_RC 139#ifdef ENABLE_RC
140 struct input_dev rc_input_dev; 140 struct input_dev *rc_input_dev;
141 char phys[64];
141 struct work_struct rc_query_work; 142 struct work_struct rc_query_work;
142 int rc_input_event; 143 int rc_input_event;
143 u32 rc_last_code; 144 u32 rc_last_code;
@@ -683,6 +684,7 @@ static struct dvb_device cinergyt2_fe_template = {
683}; 684};
684 685
685#ifdef ENABLE_RC 686#ifdef ENABLE_RC
687
686static void cinergyt2_query_rc (void *data) 688static void cinergyt2_query_rc (void *data)
687{ 689{
688 struct cinergyt2 *cinergyt2 = data; 690 struct cinergyt2 *cinergyt2 = data;
@@ -703,7 +705,7 @@ static void cinergyt2_query_rc (void *data)
703 /* stop key repeat */ 705 /* stop key repeat */
704 if (cinergyt2->rc_input_event != KEY_MAX) { 706 if (cinergyt2->rc_input_event != KEY_MAX) {
705 dprintk(1, "rc_input_event=%d Up\n", cinergyt2->rc_input_event); 707 dprintk(1, "rc_input_event=%d Up\n", cinergyt2->rc_input_event);
706 input_report_key(&cinergyt2->rc_input_dev, 708 input_report_key(cinergyt2->rc_input_dev,
707 cinergyt2->rc_input_event, 0); 709 cinergyt2->rc_input_event, 0);
708 cinergyt2->rc_input_event = KEY_MAX; 710 cinergyt2->rc_input_event = KEY_MAX;
709 } 711 }
@@ -722,7 +724,7 @@ static void cinergyt2_query_rc (void *data)
722 /* keyrepeat bit -> just repeat last rc_input_event */ 724 /* keyrepeat bit -> just repeat last rc_input_event */
723 } else { 725 } else {
724 cinergyt2->rc_input_event = KEY_MAX; 726 cinergyt2->rc_input_event = KEY_MAX;
725 for (i = 0; i < sizeof(rc_keys) / sizeof(rc_keys[0]); i += 3) { 727 for (i = 0; i < ARRAY_SIZE(rc_keys); i += 3) {
726 if (rc_keys[i + 0] == rc_events[n].type && 728 if (rc_keys[i + 0] == rc_events[n].type &&
727 rc_keys[i + 1] == le32_to_cpu(rc_events[n].value)) { 729 rc_keys[i + 1] == le32_to_cpu(rc_events[n].value)) {
728 cinergyt2->rc_input_event = rc_keys[i + 2]; 730 cinergyt2->rc_input_event = rc_keys[i + 2];
@@ -736,11 +738,11 @@ static void cinergyt2_query_rc (void *data)
736 cinergyt2->rc_last_code != ~0) { 738 cinergyt2->rc_last_code != ~0) {
737 /* emit a key-up so the double event is recognized */ 739 /* emit a key-up so the double event is recognized */
738 dprintk(1, "rc_input_event=%d UP\n", cinergyt2->rc_input_event); 740 dprintk(1, "rc_input_event=%d UP\n", cinergyt2->rc_input_event);
739 input_report_key(&cinergyt2->rc_input_dev, 741 input_report_key(cinergyt2->rc_input_dev,
740 cinergyt2->rc_input_event, 0); 742 cinergyt2->rc_input_event, 0);
741 } 743 }
742 dprintk(1, "rc_input_event=%d\n", cinergyt2->rc_input_event); 744 dprintk(1, "rc_input_event=%d\n", cinergyt2->rc_input_event);
743 input_report_key(&cinergyt2->rc_input_dev, 745 input_report_key(cinergyt2->rc_input_dev,
744 cinergyt2->rc_input_event, 1); 746 cinergyt2->rc_input_event, 1);
745 cinergyt2->rc_last_code = rc_events[n].value; 747 cinergyt2->rc_last_code = rc_events[n].value;
746 } 748 }
@@ -752,7 +754,59 @@ out:
752 754
753 up(&cinergyt2->sem); 755 up(&cinergyt2->sem);
754} 756}
755#endif 757
758static int cinergyt2_register_rc(struct cinergyt2 *cinergyt2)
759{
760 struct input_dev *input_dev;
761 int i;
762
763 cinergyt2->rc_input_dev = input_dev = input_allocate_device();
764 if (!input_dev)
765 return -ENOMEM;
766
767 usb_make_path(cinergyt2->udev, cinergyt2->phys, sizeof(cinergyt2->phys));
768 strlcat(cinergyt2->phys, "/input0", sizeof(cinergyt2->phys));
769 cinergyt2->rc_input_event = KEY_MAX;
770 cinergyt2->rc_last_code = ~0;
771 INIT_WORK(&cinergyt2->rc_query_work, cinergyt2_query_rc, cinergyt2);
772
773 input_dev->name = DRIVER_NAME " remote control";
774 input_dev->phys = cinergyt2->phys;
775 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
776 for (i = 0; ARRAY_SIZE(rc_keys); i += 3)
777 set_bit(rc_keys[i + 2], input_dev->keybit);
778 input_dev->keycodesize = 0;
779 input_dev->keycodemax = 0;
780
781 input_register_device(cinergyt2->rc_input_dev);
782 schedule_delayed_work(&cinergyt2->rc_query_work, HZ/2);
783}
784
785static void cinergyt2_unregister_rc(struct cinergyt2 *cinergyt2)
786{
787 cancel_delayed_work(&cinergyt2->rc_query_work);
788 flush_scheduled_work();
789 input_unregister_device(cinergyt2->rc_input_dev);
790}
791
792static inline void cinergyt2_suspend_rc(struct cinergyt2 *cinergyt2)
793{
794 cancel_delayed_work(&cinergyt2->rc_query_work);
795}
796
797static inline void cinergyt2_resume_rc(struct cinergyt2 *cinergyt2)
798{
799 schedule_delayed_work(&cinergyt2->rc_query_work, HZ/2);
800}
801
802#else
803
804static inline int cinergyt2_register_rc(struct cinergyt2 *cinergyt2) { return 0; }
805static inline void cinergyt2_unregister_rc(struct cinergyt2 *cinergyt2) { }
806static inline void cinergyt2_suspend_rc(struct cinergyt2 *cinergyt2) { }
807static inline void cinergyt2_resume_rc(struct cinergyt2 *cinergyt2) { }
808
809#endif /* ENABLE_RC */
756 810
757static void cinergyt2_query (void *data) 811static void cinergyt2_query (void *data)
758{ 812{
@@ -789,9 +843,6 @@ static int cinergyt2_probe (struct usb_interface *intf,
789{ 843{
790 struct cinergyt2 *cinergyt2; 844 struct cinergyt2 *cinergyt2;
791 int err; 845 int err;
792#ifdef ENABLE_RC
793 int i;
794#endif
795 846
796 if (!(cinergyt2 = kmalloc (sizeof(struct cinergyt2), GFP_KERNEL))) { 847 if (!(cinergyt2 = kmalloc (sizeof(struct cinergyt2), GFP_KERNEL))) {
797 dprintk(1, "out of memory?!?\n"); 848 dprintk(1, "out of memory?!?\n");
@@ -846,30 +897,17 @@ static int cinergyt2_probe (struct usb_interface *intf,
846 &cinergyt2_fe_template, cinergyt2, 897 &cinergyt2_fe_template, cinergyt2,
847 DVB_DEVICE_FRONTEND); 898 DVB_DEVICE_FRONTEND);
848 899
849#ifdef ENABLE_RC 900 err = cinergyt2_register_rc(cinergyt2);
850 cinergyt2->rc_input_dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP); 901 if (err)
851 cinergyt2->rc_input_dev.keycodesize = 0; 902 goto bailout;
852 cinergyt2->rc_input_dev.keycodemax = 0;
853 cinergyt2->rc_input_dev.name = DRIVER_NAME " remote control";
854
855 for (i = 0; i < sizeof(rc_keys) / sizeof(rc_keys[0]); i += 3)
856 set_bit(rc_keys[i + 2], cinergyt2->rc_input_dev.keybit);
857
858 input_register_device(&cinergyt2->rc_input_dev);
859
860 cinergyt2->rc_input_event = KEY_MAX;
861 cinergyt2->rc_last_code = ~0;
862 903
863 INIT_WORK(&cinergyt2->rc_query_work, cinergyt2_query_rc, cinergyt2);
864 schedule_delayed_work(&cinergyt2->rc_query_work, HZ/2);
865#endif
866 return 0; 904 return 0;
867 905
868bailout: 906bailout:
869 dvb_dmxdev_release(&cinergyt2->dmxdev); 907 dvb_dmxdev_release(&cinergyt2->dmxdev);
870 dvb_dmx_release(&cinergyt2->demux); 908 dvb_dmx_release(&cinergyt2->demux);
871 dvb_unregister_adapter (&cinergyt2->adapter); 909 dvb_unregister_adapter(&cinergyt2->adapter);
872 cinergyt2_free_stream_urbs (cinergyt2); 910 cinergyt2_free_stream_urbs(cinergyt2);
873 kfree(cinergyt2); 911 kfree(cinergyt2);
874 return -ENOMEM; 912 return -ENOMEM;
875} 913}
@@ -881,11 +919,7 @@ static void cinergyt2_disconnect (struct usb_interface *intf)
881 if (down_interruptible(&cinergyt2->sem)) 919 if (down_interruptible(&cinergyt2->sem))
882 return; 920 return;
883 921
884#ifdef ENABLE_RC 922 cinergyt2_unregister_rc(cinergyt2);
885 cancel_delayed_work(&cinergyt2->rc_query_work);
886 flush_scheduled_work();
887 input_unregister_device(&cinergyt2->rc_input_dev);
888#endif
889 923
890 cinergyt2->demux.dmx.close(&cinergyt2->demux.dmx); 924 cinergyt2->demux.dmx.close(&cinergyt2->demux.dmx);
891 dvb_net_release(&cinergyt2->dvbnet); 925 dvb_net_release(&cinergyt2->dvbnet);
@@ -908,9 +942,8 @@ static int cinergyt2_suspend (struct usb_interface *intf, pm_message_t state)
908 942
909 if (state.event > PM_EVENT_ON) { 943 if (state.event > PM_EVENT_ON) {
910 struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf); 944 struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf);
911#ifdef ENABLE_RC 945
912 cancel_delayed_work(&cinergyt2->rc_query_work); 946 cinergyt2_suspend_rc(cinergyt2);
913#endif
914 cancel_delayed_work(&cinergyt2->query_work); 947 cancel_delayed_work(&cinergyt2->query_work);
915 if (cinergyt2->streaming) 948 if (cinergyt2->streaming)
916 cinergyt2_stop_stream_xfer(cinergyt2); 949 cinergyt2_stop_stream_xfer(cinergyt2);
@@ -938,9 +971,8 @@ static int cinergyt2_resume (struct usb_interface *intf)
938 schedule_delayed_work(&cinergyt2->query_work, HZ/2); 971 schedule_delayed_work(&cinergyt2->query_work, HZ/2);
939 } 972 }
940 973
941#ifdef ENABLE_RC 974 cinergyt2_resume_rc(cinergyt2);
942 schedule_delayed_work(&cinergyt2->rc_query_work, HZ/2); 975
943#endif
944 up(&cinergyt2->sem); 976 up(&cinergyt2->sem);
945 return 0; 977 return 0;
946} 978}
diff --git a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
index 88757e2634e5..2aa767f9bd7d 100644
--- a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
+++ b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
@@ -36,6 +36,7 @@
36#include <linux/vmalloc.h> 36#include <linux/vmalloc.h>
37#include <linux/delay.h> 37#include <linux/delay.h>
38#include <linux/rwsem.h> 38#include <linux/rwsem.h>
39#include <linux/sched.h>
39 40
40#include "dvb_ca_en50221.h" 41#include "dvb_ca_en50221.h"
41#include "dvb_ringbuffer.h" 42#include "dvb_ringbuffer.h"
diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
index 4b7adca3e286..477b4fa56430 100644
--- a/drivers/media/dvb/dvb-core/dvbdev.c
+++ b/drivers/media/dvb/dvb-core/dvbdev.c
@@ -235,7 +235,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
235 S_IFCHR | S_IRUSR | S_IWUSR, 235 S_IFCHR | S_IRUSR | S_IWUSR,
236 "dvb/adapter%d/%s%d", adap->num, dnames[type], id); 236 "dvb/adapter%d/%s%d", adap->num, dnames[type], id);
237 237
238 class_device_create(dvb_class, MKDEV(DVB_MAJOR, nums2minor(adap->num, type, id)), 238 class_device_create(dvb_class, NULL, MKDEV(DVB_MAJOR, nums2minor(adap->num, type, id)),
239 NULL, "dvb%d.%s%d", adap->num, dnames[type], id); 239 NULL, "dvb%d.%s%d", adap->num, dnames[type], id);
240 240
241 dprintk("DVB: register adapter%d/%s%d @ minor: %i (0x%02x)\n", 241 dprintk("DVB: register adapter%d/%s%d @ minor: %i (0x%02x)\n",
diff --git a/drivers/media/dvb/dvb-usb/dtt200u.c b/drivers/media/dvb/dvb-usb/dtt200u.c
index 5aa12ebab34f..b595476332cd 100644
--- a/drivers/media/dvb/dvb-usb/dtt200u.c
+++ b/drivers/media/dvb/dvb-usb/dtt200u.c
@@ -151,7 +151,7 @@ static struct dvb_usb_properties dtt200u_properties = {
151 .cold_ids = { &dtt200u_usb_table[0], NULL }, 151 .cold_ids = { &dtt200u_usb_table[0], NULL },
152 .warm_ids = { &dtt200u_usb_table[1], NULL }, 152 .warm_ids = { &dtt200u_usb_table[1], NULL },
153 }, 153 },
154 { 0 }, 154 { NULL },
155 } 155 }
156}; 156};
157 157
@@ -192,7 +192,7 @@ static struct dvb_usb_properties wt220u_properties = {
192 .cold_ids = { &dtt200u_usb_table[2], NULL }, 192 .cold_ids = { &dtt200u_usb_table[2], NULL },
193 .warm_ids = { &dtt200u_usb_table[3], NULL }, 193 .warm_ids = { &dtt200u_usb_table[3], NULL },
194 }, 194 },
195 { 0 }, 195 { NULL },
196 } 196 }
197}; 197};
198 198
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
index fc7800f1743e..e5c6d9835e06 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
@@ -39,9 +39,9 @@ static void dvb_usb_read_remote_control(void *data)
39 d->last_event = event; 39 d->last_event = event;
40 case REMOTE_KEY_REPEAT: 40 case REMOTE_KEY_REPEAT:
41 deb_rc("key repeated\n"); 41 deb_rc("key repeated\n");
42 input_event(&d->rc_input_dev, EV_KEY, d->last_event, 1); 42 input_event(d->rc_input_dev, EV_KEY, event, 1);
43 input_event(&d->rc_input_dev, EV_KEY, d->last_event, 0); 43 input_event(d->rc_input_dev, EV_KEY, d->last_event, 0);
44 input_sync(&d->rc_input_dev); 44 input_sync(d->rc_input_dev);
45 break; 45 break;
46 default: 46 default:
47 break; 47 break;
@@ -53,8 +53,8 @@ static void dvb_usb_read_remote_control(void *data)
53 deb_rc("NO KEY PRESSED\n"); 53 deb_rc("NO KEY PRESSED\n");
54 if (d->last_state != REMOTE_NO_KEY_PRESSED) { 54 if (d->last_state != REMOTE_NO_KEY_PRESSED) {
55 deb_rc("releasing event %d\n",d->last_event); 55 deb_rc("releasing event %d\n",d->last_event);
56 input_event(&d->rc_input_dev, EV_KEY, d->last_event, 0); 56 input_event(d->rc_input_dev, EV_KEY, d->last_event, 0);
57 input_sync(&d->rc_input_dev); 57 input_sync(d->rc_input_dev);
58 } 58 }
59 d->last_state = REMOTE_NO_KEY_PRESSED; 59 d->last_state = REMOTE_NO_KEY_PRESSED;
60 d->last_event = 0; 60 d->last_event = 0;
@@ -63,8 +63,8 @@ static void dvb_usb_read_remote_control(void *data)
63 deb_rc("KEY PRESSED\n"); 63 deb_rc("KEY PRESSED\n");
64 deb_rc("pressing event %d\n",event); 64 deb_rc("pressing event %d\n",event);
65 65
66 input_event(&d->rc_input_dev, EV_KEY, event, 1); 66 input_event(d->rc_input_dev, EV_KEY, event, 1);
67 input_sync(&d->rc_input_dev); 67 input_sync(d->rc_input_dev);
68 68
69 d->last_event = event; 69 d->last_event = event;
70 d->last_state = REMOTE_KEY_PRESSED; 70 d->last_state = REMOTE_KEY_PRESSED;
@@ -73,8 +73,8 @@ static void dvb_usb_read_remote_control(void *data)
73 deb_rc("KEY_REPEAT\n"); 73 deb_rc("KEY_REPEAT\n");
74 if (d->last_state != REMOTE_NO_KEY_PRESSED) { 74 if (d->last_state != REMOTE_NO_KEY_PRESSED) {
75 deb_rc("repeating event %d\n",d->last_event); 75 deb_rc("repeating event %d\n",d->last_event);
76 input_event(&d->rc_input_dev, EV_KEY, d->last_event, 2); 76 input_event(d->rc_input_dev, EV_KEY, d->last_event, 2);
77 input_sync(&d->rc_input_dev); 77 input_sync(d->rc_input_dev);
78 d->last_state = REMOTE_KEY_REPEAT; 78 d->last_state = REMOTE_KEY_REPEAT;
79 } 79 }
80 default: 80 default:
@@ -89,24 +89,30 @@ schedule:
89int dvb_usb_remote_init(struct dvb_usb_device *d) 89int dvb_usb_remote_init(struct dvb_usb_device *d)
90{ 90{
91 int i; 91 int i;
92
92 if (d->props.rc_key_map == NULL || 93 if (d->props.rc_key_map == NULL ||
93 d->props.rc_query == NULL || 94 d->props.rc_query == NULL ||
94 dvb_usb_disable_rc_polling) 95 dvb_usb_disable_rc_polling)
95 return 0; 96 return 0;
96 97
97 /* Initialise the remote-control structures.*/ 98 usb_make_path(d->udev, d->rc_phys, sizeof(d->rc_phys));
98 init_input_dev(&d->rc_input_dev); 99 strlcpy(d->rc_phys, "/ir0", sizeof(d->rc_phys));
100
101 d->rc_input_dev = input_allocate_device();
102 if (!d->rc_input_dev)
103 return -ENOMEM;
99 104
100 d->rc_input_dev.evbit[0] = BIT(EV_KEY); 105 d->rc_input_dev->evbit[0] = BIT(EV_KEY);
101 d->rc_input_dev.keycodesize = sizeof(unsigned char); 106 d->rc_input_dev->keycodesize = sizeof(unsigned char);
102 d->rc_input_dev.keycodemax = KEY_MAX; 107 d->rc_input_dev->keycodemax = KEY_MAX;
103 d->rc_input_dev.name = "IR-receiver inside an USB DVB receiver"; 108 d->rc_input_dev->name = "IR-receiver inside an USB DVB receiver";
109 d->rc_input_dev->phys = d->rc_phys;
104 110
105 /* set the bits for the keys */ 111 /* set the bits for the keys */
106 deb_rc("key map size: %d\n",d->props.rc_key_map_size); 112 deb_rc("key map size: %d\n", d->props.rc_key_map_size);
107 for (i = 0; i < d->props.rc_key_map_size; i++) { 113 for (i = 0; i < d->props.rc_key_map_size; i++) {
108 deb_rc("setting bit for event %d item %d\n",d->props.rc_key_map[i].event, i); 114 deb_rc("setting bit for event %d item %d\n",d->props.rc_key_map[i].event, i);
109 set_bit(d->props.rc_key_map[i].event, d->rc_input_dev.keybit); 115 set_bit(d->props.rc_key_map[i].event, d->rc_input_dev->keybit);
110 } 116 }
111 117
112 /* Start the remote-control polling. */ 118 /* Start the remote-control polling. */
@@ -114,14 +120,14 @@ int dvb_usb_remote_init(struct dvb_usb_device *d)
114 d->props.rc_interval = 100; /* default */ 120 d->props.rc_interval = 100; /* default */
115 121
116 /* setting these two values to non-zero, we have to manage key repeats */ 122 /* setting these two values to non-zero, we have to manage key repeats */
117 d->rc_input_dev.rep[REP_PERIOD] = d->props.rc_interval; 123 d->rc_input_dev->rep[REP_PERIOD] = d->props.rc_interval;
118 d->rc_input_dev.rep[REP_DELAY] = d->props.rc_interval + 150; 124 d->rc_input_dev->rep[REP_DELAY] = d->props.rc_interval + 150;
119 125
120 input_register_device(&d->rc_input_dev); 126 input_register_device(d->rc_input_dev);
121 127
122 INIT_WORK(&d->rc_query_work, dvb_usb_read_remote_control, d); 128 INIT_WORK(&d->rc_query_work, dvb_usb_read_remote_control, d);
123 129
124 info("schedule remote query interval to %d msecs.",d->props.rc_interval); 130 info("schedule remote query interval to %d msecs.", d->props.rc_interval);
125 schedule_delayed_work(&d->rc_query_work,msecs_to_jiffies(d->props.rc_interval)); 131 schedule_delayed_work(&d->rc_query_work,msecs_to_jiffies(d->props.rc_interval));
126 132
127 d->state |= DVB_USB_STATE_REMOTE; 133 d->state |= DVB_USB_STATE_REMOTE;
@@ -134,7 +140,7 @@ int dvb_usb_remote_exit(struct dvb_usb_device *d)
134 if (d->state & DVB_USB_STATE_REMOTE) { 140 if (d->state & DVB_USB_STATE_REMOTE) {
135 cancel_delayed_work(&d->rc_query_work); 141 cancel_delayed_work(&d->rc_query_work);
136 flush_scheduled_work(); 142 flush_scheduled_work();
137 input_unregister_device(&d->rc_input_dev); 143 input_unregister_device(d->rc_input_dev);
138 } 144 }
139 d->state &= ~DVB_USB_STATE_REMOTE; 145 d->state &= ~DVB_USB_STATE_REMOTE;
140 return 0; 146 return 0;
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb.h b/drivers/media/dvb/dvb-usb/dvb-usb.h
index 0e4f1035b0dd..b4a1a98006c7 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb.h
@@ -300,7 +300,8 @@ struct dvb_usb_device {
300 int (*fe_init) (struct dvb_frontend *); 300 int (*fe_init) (struct dvb_frontend *);
301 301
302 /* remote control */ 302 /* remote control */
303 struct input_dev rc_input_dev; 303 struct input_dev *rc_input_dev;
304 char rc_phys[64];
304 struct work_struct rc_query_work; 305 struct work_struct rc_query_work;
305 u32 last_event; 306 u32 last_event;
306 int last_state; 307 int last_state;
diff --git a/drivers/media/dvb/dvb-usb/vp7045.c b/drivers/media/dvb/dvb-usb/vp7045.c
index 0f57abeb6d6b..75765e3a569c 100644
--- a/drivers/media/dvb/dvb-usb/vp7045.c
+++ b/drivers/media/dvb/dvb-usb/vp7045.c
@@ -247,7 +247,7 @@ static struct dvb_usb_properties vp7045_properties = {
247 .cold_ids = { &vp7045_usb_table[2], NULL }, 247 .cold_ids = { &vp7045_usb_table[2], NULL },
248 .warm_ids = { &vp7045_usb_table[3], NULL }, 248 .warm_ids = { &vp7045_usb_table[3], NULL },
249 }, 249 },
250 { 0 }, 250 { NULL },
251 } 251 }
252}; 252};
253 253
diff --git a/drivers/media/dvb/frontends/bcm3510.c b/drivers/media/dvb/frontends/bcm3510.c
index f5fdc5c3e605..f6d4ee78bdd4 100644
--- a/drivers/media/dvb/frontends/bcm3510.c
+++ b/drivers/media/dvb/frontends/bcm3510.c
@@ -36,6 +36,9 @@
36#include <linux/moduleparam.h> 36#include <linux/moduleparam.h>
37#include <linux/device.h> 37#include <linux/device.h>
38#include <linux/firmware.h> 38#include <linux/firmware.h>
39#include <linux/jiffies.h>
40#include <linux/string.h>
41#include <linux/slab.h>
39 42
40#include "dvb_frontend.h" 43#include "dvb_frontend.h"
41#include "bcm3510.h" 44#include "bcm3510.h"
diff --git a/drivers/media/dvb/frontends/dib3000mb.c b/drivers/media/dvb/frontends/dib3000mb.c
index 21433e1831e7..6b0553608610 100644
--- a/drivers/media/dvb/frontends/dib3000mb.c
+++ b/drivers/media/dvb/frontends/dib3000mb.c
@@ -27,6 +27,8 @@
27#include <linux/moduleparam.h> 27#include <linux/moduleparam.h>
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/delay.h> 29#include <linux/delay.h>
30#include <linux/string.h>
31#include <linux/slab.h>
30 32
31#include "dib3000-common.h" 33#include "dib3000-common.h"
32#include "dib3000mb_priv.h" 34#include "dib3000mb_priv.h"
diff --git a/drivers/media/dvb/frontends/dib3000mc.c b/drivers/media/dvb/frontends/dib3000mc.c
index 441de665fec3..c024fad17337 100644
--- a/drivers/media/dvb/frontends/dib3000mc.c
+++ b/drivers/media/dvb/frontends/dib3000mc.c
@@ -26,6 +26,8 @@
26#include <linux/moduleparam.h> 26#include <linux/moduleparam.h>
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/string.h>
30#include <linux/slab.h>
29 31
30#include "dib3000-common.h" 32#include "dib3000-common.h"
31#include "dib3000mc_priv.h" 33#include "dib3000mc_priv.h"
diff --git a/drivers/media/dvb/frontends/dvb_dummy_fe.c b/drivers/media/dvb/frontends/dvb_dummy_fe.c
index cff93b9d8ab2..794be520d590 100644
--- a/drivers/media/dvb/frontends/dvb_dummy_fe.c
+++ b/drivers/media/dvb/frontends/dvb_dummy_fe.c
@@ -22,6 +22,8 @@
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/moduleparam.h> 23#include <linux/moduleparam.h>
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/string.h>
26#include <linux/slab.h>
25 27
26#include "dvb_frontend.h" 28#include "dvb_frontend.h"
27#include "dvb_dummy_fe.h" 29#include "dvb_dummy_fe.h"
diff --git a/drivers/media/dvb/frontends/lgdt330x.c b/drivers/media/dvb/frontends/lgdt330x.c
index 7142b9c51dd2..8dde72bd1046 100644
--- a/drivers/media/dvb/frontends/lgdt330x.c
+++ b/drivers/media/dvb/frontends/lgdt330x.c
@@ -37,6 +37,8 @@
37#include <linux/moduleparam.h> 37#include <linux/moduleparam.h>
38#include <linux/init.h> 38#include <linux/init.h>
39#include <linux/delay.h> 39#include <linux/delay.h>
40#include <linux/string.h>
41#include <linux/slab.h>
40#include <asm/byteorder.h> 42#include <asm/byteorder.h>
41 43
42#include "dvb_frontend.h" 44#include "dvb_frontend.h"
diff --git a/drivers/media/dvb/frontends/mt312.c b/drivers/media/dvb/frontends/mt312.c
index e455aecd76b2..e38454901dd1 100644
--- a/drivers/media/dvb/frontends/mt312.c
+++ b/drivers/media/dvb/frontends/mt312.c
@@ -29,6 +29,8 @@
29#include <linux/kernel.h> 29#include <linux/kernel.h>
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/moduleparam.h> 31#include <linux/moduleparam.h>
32#include <linux/string.h>
33#include <linux/slab.h>
32 34
33#include "dvb_frontend.h" 35#include "dvb_frontend.h"
34#include "mt312_priv.h" 36#include "mt312_priv.h"
diff --git a/drivers/media/dvb/frontends/mt352.c b/drivers/media/dvb/frontends/mt352.c
index cc1bc0edd65e..f0c610f2c2df 100644
--- a/drivers/media/dvb/frontends/mt352.c
+++ b/drivers/media/dvb/frontends/mt352.c
@@ -35,6 +35,8 @@
35#include <linux/moduleparam.h> 35#include <linux/moduleparam.h>
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/delay.h> 37#include <linux/delay.h>
38#include <linux/string.h>
39#include <linux/slab.h>
38 40
39#include "dvb_frontend.h" 41#include "dvb_frontend.h"
40#include "mt352_priv.h" 42#include "mt352_priv.h"
diff --git a/drivers/media/dvb/frontends/nxt2002.c b/drivers/media/dvb/frontends/nxt2002.c
index 35a1d60f1927..30786b1911bd 100644
--- a/drivers/media/dvb/frontends/nxt2002.c
+++ b/drivers/media/dvb/frontends/nxt2002.c
@@ -32,6 +32,8 @@
32#include <linux/moduleparam.h> 32#include <linux/moduleparam.h>
33#include <linux/device.h> 33#include <linux/device.h>
34#include <linux/firmware.h> 34#include <linux/firmware.h>
35#include <linux/string.h>
36#include <linux/slab.h>
35 37
36#include "dvb_frontend.h" 38#include "dvb_frontend.h"
37#include "nxt2002.h" 39#include "nxt2002.h"
diff --git a/drivers/media/dvb/frontends/or51132.c b/drivers/media/dvb/frontends/or51132.c
index b6d0eecc59eb..817b044c7fd1 100644
--- a/drivers/media/dvb/frontends/or51132.c
+++ b/drivers/media/dvb/frontends/or51132.c
@@ -36,6 +36,8 @@
36#include <linux/moduleparam.h> 36#include <linux/moduleparam.h>
37#include <linux/init.h> 37#include <linux/init.h>
38#include <linux/delay.h> 38#include <linux/delay.h>
39#include <linux/string.h>
40#include <linux/slab.h>
39#include <asm/byteorder.h> 41#include <asm/byteorder.h>
40 42
41#include "dvb_frontend.h" 43#include "dvb_frontend.h"
diff --git a/drivers/media/dvb/frontends/or51211.c b/drivers/media/dvb/frontends/or51211.c
index ad56a9958404..8a9db23dd1b7 100644
--- a/drivers/media/dvb/frontends/or51211.c
+++ b/drivers/media/dvb/frontends/or51211.c
@@ -34,6 +34,8 @@
34#include <linux/moduleparam.h> 34#include <linux/moduleparam.h>
35#include <linux/device.h> 35#include <linux/device.h>
36#include <linux/firmware.h> 36#include <linux/firmware.h>
37#include <linux/string.h>
38#include <linux/slab.h>
37#include <asm/byteorder.h> 39#include <asm/byteorder.h>
38 40
39#include "dvb_frontend.h" 41#include "dvb_frontend.h"
diff --git a/drivers/media/dvb/frontends/s5h1420.c b/drivers/media/dvb/frontends/s5h1420.c
index c7fe27fd530c..f265418e3261 100644
--- a/drivers/media/dvb/frontends/s5h1420.c
+++ b/drivers/media/dvb/frontends/s5h1420.c
@@ -26,6 +26,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26#include <linux/string.h> 26#include <linux/string.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/jiffies.h>
30#include <asm/div64.h>
29 31
30#include "dvb_frontend.h" 32#include "dvb_frontend.h"
31#include "s5h1420.h" 33#include "s5h1420.h"
diff --git a/drivers/media/dvb/frontends/sp8870.c b/drivers/media/dvb/frontends/sp8870.c
index 764a95a2e212..1c6b2e9264bc 100644
--- a/drivers/media/dvb/frontends/sp8870.c
+++ b/drivers/media/dvb/frontends/sp8870.c
@@ -32,6 +32,8 @@
32#include <linux/device.h> 32#include <linux/device.h>
33#include <linux/firmware.h> 33#include <linux/firmware.h>
34#include <linux/delay.h> 34#include <linux/delay.h>
35#include <linux/string.h>
36#include <linux/slab.h>
35 37
36#include "dvb_frontend.h" 38#include "dvb_frontend.h"
37#include "sp8870.h" 39#include "sp8870.h"
diff --git a/drivers/media/dvb/frontends/sp887x.c b/drivers/media/dvb/frontends/sp887x.c
index d868a6927a16..73384e75625e 100644
--- a/drivers/media/dvb/frontends/sp887x.c
+++ b/drivers/media/dvb/frontends/sp887x.c
@@ -14,6 +14,8 @@
14#include <linux/moduleparam.h> 14#include <linux/moduleparam.h>
15#include <linux/device.h> 15#include <linux/device.h>
16#include <linux/firmware.h> 16#include <linux/firmware.h>
17#include <linux/string.h>
18#include <linux/slab.h>
17 19
18#include "dvb_frontend.h" 20#include "dvb_frontend.h"
19#include "sp887x.h" 21#include "sp887x.h"
diff --git a/drivers/media/dvb/frontends/stv0297.c b/drivers/media/dvb/frontends/stv0297.c
index 8d09afd7545d..6122ba754bc5 100644
--- a/drivers/media/dvb/frontends/stv0297.c
+++ b/drivers/media/dvb/frontends/stv0297.c
@@ -24,6 +24,8 @@
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/string.h> 25#include <linux/string.h>
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/jiffies.h>
28#include <linux/slab.h>
27 29
28#include "dvb_frontend.h" 30#include "dvb_frontend.h"
29#include "stv0297.h" 31#include "stv0297.h"
diff --git a/drivers/media/dvb/frontends/stv0299.c b/drivers/media/dvb/frontends/stv0299.c
index 2d62931f20b5..889d9257215d 100644
--- a/drivers/media/dvb/frontends/stv0299.c
+++ b/drivers/media/dvb/frontends/stv0299.c
@@ -48,6 +48,7 @@
48#include <linux/moduleparam.h> 48#include <linux/moduleparam.h>
49#include <linux/string.h> 49#include <linux/string.h>
50#include <linux/slab.h> 50#include <linux/slab.h>
51#include <linux/jiffies.h>
51#include <asm/div64.h> 52#include <asm/div64.h>
52 53
53#include "dvb_frontend.h" 54#include "dvb_frontend.h"
diff --git a/drivers/media/dvb/frontends/tda1004x.c b/drivers/media/dvb/frontends/tda1004x.c
index 74cea9f8d721..3529c618f828 100644
--- a/drivers/media/dvb/frontends/tda1004x.c
+++ b/drivers/media/dvb/frontends/tda1004x.c
@@ -32,6 +32,10 @@
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/moduleparam.h> 33#include <linux/moduleparam.h>
34#include <linux/device.h> 34#include <linux/device.h>
35#include <linux/jiffies.h>
36#include <linux/string.h>
37#include <linux/slab.h>
38
35#include "dvb_frontend.h" 39#include "dvb_frontend.h"
36#include "tda1004x.h" 40#include "tda1004x.h"
37 41
diff --git a/drivers/media/dvb/frontends/tda8083.c b/drivers/media/dvb/frontends/tda8083.c
index 168e013d23bd..c05cf1861051 100644
--- a/drivers/media/dvb/frontends/tda8083.c
+++ b/drivers/media/dvb/frontends/tda8083.c
@@ -30,6 +30,7 @@
30#include <linux/moduleparam.h> 30#include <linux/moduleparam.h>
31#include <linux/string.h> 31#include <linux/string.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/jiffies.h>
33#include "dvb_frontend.h" 34#include "dvb_frontend.h"
34#include "tda8083.h" 35#include "tda8083.h"
35 36
diff --git a/drivers/media/dvb/ttpci/av7110_ir.c b/drivers/media/dvb/ttpci/av7110_ir.c
index 357a3728ec68..f5e59fc924af 100644
--- a/drivers/media/dvb/ttpci/av7110_ir.c
+++ b/drivers/media/dvb/ttpci/av7110_ir.c
@@ -15,7 +15,7 @@
15 15
16static int av_cnt; 16static int av_cnt;
17static struct av7110 *av_list[4]; 17static struct av7110 *av_list[4];
18static struct input_dev input_dev; 18static struct input_dev *input_dev;
19 19
20static u16 key_map [256] = { 20static u16 key_map [256] = {
21 KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, 21 KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7,
@@ -43,10 +43,10 @@ static u16 key_map [256] = {
43 43
44static void av7110_emit_keyup(unsigned long data) 44static void av7110_emit_keyup(unsigned long data)
45{ 45{
46 if (!data || !test_bit(data, input_dev.key)) 46 if (!data || !test_bit(data, input_dev->key))
47 return; 47 return;
48 48
49 input_event(&input_dev, EV_KEY, data, !!0); 49 input_event(input_dev, EV_KEY, data, !!0);
50} 50}
51 51
52 52
@@ -112,13 +112,13 @@ static void av7110_emit_key(unsigned long parm)
112 if (timer_pending(&keyup_timer)) { 112 if (timer_pending(&keyup_timer)) {
113 del_timer(&keyup_timer); 113 del_timer(&keyup_timer);
114 if (keyup_timer.data != keycode || new_toggle != old_toggle) { 114 if (keyup_timer.data != keycode || new_toggle != old_toggle) {
115 input_event(&input_dev, EV_KEY, keyup_timer.data, !!0); 115 input_event(input_dev, EV_KEY, keyup_timer.data, !!0);
116 input_event(&input_dev, EV_KEY, keycode, !0); 116 input_event(input_dev, EV_KEY, keycode, !0);
117 } else 117 } else
118 input_event(&input_dev, EV_KEY, keycode, 2); 118 input_event(input_dev, EV_KEY, keycode, 2);
119 119
120 } else 120 } else
121 input_event(&input_dev, EV_KEY, keycode, !0); 121 input_event(input_dev, EV_KEY, keycode, !0);
122 122
123 keyup_timer.expires = jiffies + UP_TIMEOUT; 123 keyup_timer.expires = jiffies + UP_TIMEOUT;
124 keyup_timer.data = keycode; 124 keyup_timer.data = keycode;
@@ -132,13 +132,13 @@ static void input_register_keys(void)
132{ 132{
133 int i; 133 int i;
134 134
135 memset(input_dev.keybit, 0, sizeof(input_dev.keybit)); 135 memset(input_dev->keybit, 0, sizeof(input_dev->keybit));
136 136
137 for (i = 0; i < sizeof(key_map) / sizeof(key_map[0]); i++) { 137 for (i = 0; i < ARRAY_SIZE(key_map); i++) {
138 if (key_map[i] > KEY_MAX) 138 if (key_map[i] > KEY_MAX)
139 key_map[i] = 0; 139 key_map[i] = 0;
140 else if (key_map[i] > KEY_RESERVED) 140 else if (key_map[i] > KEY_RESERVED)
141 set_bit(key_map[i], input_dev.keybit); 141 set_bit(key_map[i], input_dev->keybit);
142 } 142 }
143} 143}
144 144
@@ -216,12 +216,17 @@ int __init av7110_ir_init(struct av7110 *av7110)
216 init_timer(&keyup_timer); 216 init_timer(&keyup_timer);
217 keyup_timer.data = 0; 217 keyup_timer.data = 0;
218 218
219 input_dev.name = "DVB on-card IR receiver"; 219 input_dev = input_allocate_device();
220 set_bit(EV_KEY, input_dev.evbit); 220 if (!input_dev)
221 set_bit(EV_REP, input_dev.evbit); 221 return -ENOMEM;
222
223 input_dev->name = "DVB on-card IR receiver";
224
225 set_bit(EV_KEY, input_dev->evbit);
226 set_bit(EV_REP, input_dev->evbit);
222 input_register_keys(); 227 input_register_keys();
223 input_register_device(&input_dev); 228 input_register_device(input_dev);
224 input_dev.timer.function = input_repeat_key; 229 input_dev->timer.function = input_repeat_key;
225 230
226 e = create_proc_entry("av7110_ir", S_IFREG | S_IRUGO | S_IWUSR, NULL); 231 e = create_proc_entry("av7110_ir", S_IFREG | S_IRUGO | S_IWUSR, NULL);
227 if (e) { 232 if (e) {
@@ -256,7 +261,7 @@ void __exit av7110_ir_exit(struct av7110 *av7110)
256 if (av_cnt == 1) { 261 if (av_cnt == 1) {
257 del_timer_sync(&keyup_timer); 262 del_timer_sync(&keyup_timer);
258 remove_proc_entry("av7110_ir", NULL); 263 remove_proc_entry("av7110_ir", NULL);
259 input_unregister_device(&input_dev); 264 input_unregister_device(input_dev);
260 } 265 }
261 266
262 av_cnt--; 267 av_cnt--;
diff --git a/drivers/media/dvb/ttpci/budget-ci.c b/drivers/media/dvb/ttpci/budget-ci.c
index 2980db3ef22f..51c30ba68140 100644
--- a/drivers/media/dvb/ttpci/budget-ci.c
+++ b/drivers/media/dvb/ttpci/budget-ci.c
@@ -64,7 +64,7 @@
64 64
65struct budget_ci { 65struct budget_ci {
66 struct budget budget; 66 struct budget budget;
67 struct input_dev input_dev; 67 struct input_dev *input_dev;
68 struct tasklet_struct msp430_irq_tasklet; 68 struct tasklet_struct msp430_irq_tasklet;
69 struct tasklet_struct ciintf_irq_tasklet; 69 struct tasklet_struct ciintf_irq_tasklet;
70 int slot_status; 70 int slot_status;
@@ -145,7 +145,7 @@ static void msp430_ir_debounce(unsigned long data)
145static void msp430_ir_interrupt(unsigned long data) 145static void msp430_ir_interrupt(unsigned long data)
146{ 146{
147 struct budget_ci *budget_ci = (struct budget_ci *) data; 147 struct budget_ci *budget_ci = (struct budget_ci *) data;
148 struct input_dev *dev = &budget_ci->input_dev; 148 struct input_dev *dev = budget_ci->input_dev;
149 unsigned int code = 149 unsigned int code =
150 ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8; 150 ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8;
151 151
@@ -181,25 +181,27 @@ static void msp430_ir_interrupt(unsigned long data)
181static int msp430_ir_init(struct budget_ci *budget_ci) 181static int msp430_ir_init(struct budget_ci *budget_ci)
182{ 182{
183 struct saa7146_dev *saa = budget_ci->budget.dev; 183 struct saa7146_dev *saa = budget_ci->budget.dev;
184 struct input_dev *input_dev;
184 int i; 185 int i;
185 186
186 memset(&budget_ci->input_dev, 0, sizeof(struct input_dev)); 187 budget_ci->input_dev = input_dev = input_allocate_device();
188 if (!input_dev)
189 return -ENOMEM;
187 190
188 sprintf(budget_ci->ir_dev_name, "Budget-CI dvb ir receiver %s", saa->name); 191 sprintf(budget_ci->ir_dev_name, "Budget-CI dvb ir receiver %s", saa->name);
189 budget_ci->input_dev.name = budget_ci->ir_dev_name;
190 192
191 set_bit(EV_KEY, budget_ci->input_dev.evbit); 193 input_dev->name = budget_ci->ir_dev_name;
192 194
193 for (i = 0; i < sizeof(key_map) / sizeof(*key_map); i++) 195 set_bit(EV_KEY, input_dev->evbit);
196 for (i = 0; i < ARRAY_SIZE(key_map); i++)
194 if (key_map[i]) 197 if (key_map[i])
195 set_bit(key_map[i], budget_ci->input_dev.keybit); 198 set_bit(key_map[i], input_dev->keybit);
196 199
197 input_register_device(&budget_ci->input_dev); 200 input_register_device(budget_ci->input_dev);
198 201
199 budget_ci->input_dev.timer.function = msp430_ir_debounce; 202 input_dev->timer.function = msp430_ir_debounce;
200 203
201 saa7146_write(saa, IER, saa7146_read(saa, IER) | MASK_06); 204 saa7146_write(saa, IER, saa7146_read(saa, IER) | MASK_06);
202
203 saa7146_setgpio(saa, 3, SAA7146_GPIO_IRQHI); 205 saa7146_setgpio(saa, 3, SAA7146_GPIO_IRQHI);
204 206
205 return 0; 207 return 0;
@@ -208,7 +210,7 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
208static void msp430_ir_deinit(struct budget_ci *budget_ci) 210static void msp430_ir_deinit(struct budget_ci *budget_ci)
209{ 211{
210 struct saa7146_dev *saa = budget_ci->budget.dev; 212 struct saa7146_dev *saa = budget_ci->budget.dev;
211 struct input_dev *dev = &budget_ci->input_dev; 213 struct input_dev *dev = budget_ci->input_dev;
212 214
213 saa7146_write(saa, IER, saa7146_read(saa, IER) & ~MASK_06); 215 saa7146_write(saa, IER, saa7146_read(saa, IER) & ~MASK_06);
214 saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT); 216 saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT);
diff --git a/drivers/media/dvb/ttusb-dec/ttusb_dec.c b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
index 3d08fc83a754..832d179f26fa 100644
--- a/drivers/media/dvb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
@@ -152,7 +152,8 @@ struct ttusb_dec {
152 struct list_head filter_info_list; 152 struct list_head filter_info_list;
153 spinlock_t filter_info_list_lock; 153 spinlock_t filter_info_list_lock;
154 154
155 struct input_dev rc_input_dev; 155 struct input_dev *rc_input_dev;
156 char rc_phys[64];
156 157
157 int active; /* Loaded successfully */ 158 int active; /* Loaded successfully */
158}; 159};
@@ -235,9 +236,9 @@ static void ttusb_dec_handle_irq( struct urb *urb, struct pt_regs *regs)
235 * this should/could be added later ... 236 * this should/could be added later ...
236 * for now lets report each signal as a key down and up*/ 237 * for now lets report each signal as a key down and up*/
237 dprintk("%s:rc signal:%d\n", __FUNCTION__, buffer[4]); 238 dprintk("%s:rc signal:%d\n", __FUNCTION__, buffer[4]);
238 input_report_key(&dec->rc_input_dev,rc_keys[buffer[4]-1],1); 239 input_report_key(dec->rc_input_dev, rc_keys[buffer[4] - 1], 1);
239 input_report_key(&dec->rc_input_dev,rc_keys[buffer[4]-1],0); 240 input_report_key(dec->rc_input_dev, rc_keys[buffer[4] - 1], 0);
240 input_sync(&dec->rc_input_dev); 241 input_sync(dec->rc_input_dev);
241 } 242 }
242 243
243exit: retval = usb_submit_urb(urb, GFP_ATOMIC); 244exit: retval = usb_submit_urb(urb, GFP_ATOMIC);
@@ -1181,29 +1182,38 @@ static void ttusb_dec_init_tasklet(struct ttusb_dec *dec)
1181 (unsigned long)dec); 1182 (unsigned long)dec);
1182} 1183}
1183 1184
1184static void ttusb_init_rc( struct ttusb_dec *dec) 1185static int ttusb_init_rc(struct ttusb_dec *dec)
1185{ 1186{
1187 struct input_dev *input_dev;
1186 u8 b[] = { 0x00, 0x01 }; 1188 u8 b[] = { 0x00, 0x01 };
1187 int i; 1189 int i;
1188 1190
1189 init_input_dev(&dec->rc_input_dev); 1191 usb_make_path(dec->udev, dec->rc_phys, sizeof(dec->rc_phys));
1192 strlcpy(dec->rc_phys, "/input0", sizeof(dec->rc_phys));
1190 1193
1191 dec->rc_input_dev.name = "ttusb_dec remote control"; 1194 dec->rc_input_dev = input_dev = input_allocate_device();
1192 dec->rc_input_dev.evbit[0] = BIT(EV_KEY); 1195 if (!input_dev)
1193 dec->rc_input_dev.keycodesize = sizeof(u16); 1196 return -ENOMEM;
1194 dec->rc_input_dev.keycodemax = 0x1a; 1197
1195 dec->rc_input_dev.keycode = rc_keys; 1198 input_dev->name = "ttusb_dec remote control";
1199 input_dev->phys = dec->rc_phys;
1200 input_dev->evbit[0] = BIT(EV_KEY);
1201 input_dev->keycodesize = sizeof(u16);
1202 input_dev->keycodemax = 0x1a;
1203 input_dev->keycode = rc_keys;
1196 1204
1197 for (i = 0; i < sizeof(rc_keys)/sizeof(rc_keys[0]); i++) 1205 for (i = 0; i < ARRAY_SIZE(rc_keys); i++)
1198 set_bit(rc_keys[i], dec->rc_input_dev.keybit); 1206 set_bit(rc_keys[i], input_dev->keybit);
1199 1207
1200 input_register_device(&dec->rc_input_dev); 1208 input_register_device(input_dev);
1201 1209
1202 if(usb_submit_urb(dec->irq_urb,GFP_KERNEL)) { 1210 if (usb_submit_urb(dec->irq_urb, GFP_KERNEL))
1203 printk("%s: usb_submit_urb failed\n",__FUNCTION__); 1211 printk("%s: usb_submit_urb failed\n",__FUNCTION__);
1204 } 1212
1205 /* enable irq pipe */ 1213 /* enable irq pipe */
1206 ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL); 1214 ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL);
1215
1216 return 0;
1207} 1217}
1208 1218
1209static void ttusb_dec_init_v_pes(struct ttusb_dec *dec) 1219static void ttusb_dec_init_v_pes(struct ttusb_dec *dec)
@@ -1513,7 +1523,7 @@ static void ttusb_dec_exit_rc(struct ttusb_dec *dec)
1513 * As the irq is submitted after the interface is changed, 1523 * As the irq is submitted after the interface is changed,
1514 * this is the best method i figured out. 1524 * this is the best method i figured out.
1515 * Any others?*/ 1525 * Any others?*/
1516 if(dec->interface == TTUSB_DEC_INTERFACE_IN) 1526 if (dec->interface == TTUSB_DEC_INTERFACE_IN)
1517 usb_kill_urb(dec->irq_urb); 1527 usb_kill_urb(dec->irq_urb);
1518 1528
1519 usb_free_urb(dec->irq_urb); 1529 usb_free_urb(dec->irq_urb);
@@ -1521,7 +1531,10 @@ static void ttusb_dec_exit_rc(struct ttusb_dec *dec)
1521 usb_buffer_free(dec->udev,IRQ_PACKET_SIZE, 1531 usb_buffer_free(dec->udev,IRQ_PACKET_SIZE,
1522 dec->irq_buffer, dec->irq_dma_handle); 1532 dec->irq_buffer, dec->irq_dma_handle);
1523 1533
1524 input_unregister_device(&dec->rc_input_dev); 1534 if (dec->rc_input_dev) {
1535 input_unregister_device(dec->rc_input_dev);
1536 dec->rc_input_dev = NULL;
1537 }
1525} 1538}
1526 1539
1527 1540
@@ -1659,7 +1672,7 @@ static int ttusb_dec_probe(struct usb_interface *intf,
1659 1672
1660 ttusb_dec_set_interface(dec, TTUSB_DEC_INTERFACE_IN); 1673 ttusb_dec_set_interface(dec, TTUSB_DEC_INTERFACE_IN);
1661 1674
1662 if(enable_rc) 1675 if (enable_rc)
1663 ttusb_init_rc(dec); 1676 ttusb_init_rc(dec);
1664 1677
1665 return 0; 1678 return 0;
diff --git a/drivers/media/radio/miropcm20-rds.c b/drivers/media/radio/miropcm20-rds.c
index df79d5e0aaed..e09214082e01 100644
--- a/drivers/media/radio/miropcm20-rds.c
+++ b/drivers/media/radio/miropcm20-rds.c
@@ -14,6 +14,7 @@
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/fs.h> 15#include <linux/fs.h>
16#include <linux/miscdevice.h> 16#include <linux/miscdevice.h>
17#include <linux/sched.h> /* current, TASK_*, schedule_timeout() */
17#include <linux/delay.h> 18#include <linux/delay.h>
18#include <asm/uaccess.h> 19#include <asm/uaccess.h>
19#include "miropcm20-rds-core.h" 20#include "miropcm20-rds-core.h"
diff --git a/drivers/media/video/bttvp.h b/drivers/media/video/bttvp.h
index 7a312f79340a..e0e7c7a84bc5 100644
--- a/drivers/media/video/bttvp.h
+++ b/drivers/media/video/bttvp.h
@@ -240,7 +240,7 @@ struct bttv_pll_info {
240 240
241/* for gpio-connected remote control */ 241/* for gpio-connected remote control */
242struct bttv_input { 242struct bttv_input {
243 struct input_dev dev; 243 struct input_dev *dev;
244 struct ir_input_state ir; 244 struct ir_input_state ir;
245 char name[32]; 245 char name[32];
246 char phys[32]; 246 char phys[32];
diff --git a/drivers/media/video/cx88/cx88-input.c b/drivers/media/video/cx88/cx88-input.c
index d81b21d6e05d..c27fe4c36f69 100644
--- a/drivers/media/video/cx88/cx88-input.c
+++ b/drivers/media/video/cx88/cx88-input.c
@@ -260,7 +260,7 @@ static IR_KEYTAB_TYPE ir_codes_cinergy_1400[IR_KEYTAB_SIZE] = {
260 260
261struct cx88_IR { 261struct cx88_IR {
262 struct cx88_core *core; 262 struct cx88_core *core;
263 struct input_dev input; 263 struct input_dev *input;
264 struct ir_input_state ir; 264 struct ir_input_state ir;
265 char name[32]; 265 char name[32];
266 char phys[32]; 266 char phys[32];
@@ -315,23 +315,23 @@ static void cx88_ir_handle_key(struct cx88_IR *ir)
315 if (ir->mask_keydown) { 315 if (ir->mask_keydown) {
316 /* bit set on keydown */ 316 /* bit set on keydown */
317 if (gpio & ir->mask_keydown) { 317 if (gpio & ir->mask_keydown) {
318 ir_input_keydown(&ir->input, &ir->ir, data, data); 318 ir_input_keydown(ir->input, &ir->ir, data, data);
319 } else { 319 } else {
320 ir_input_nokey(&ir->input, &ir->ir); 320 ir_input_nokey(ir->input, &ir->ir);
321 } 321 }
322 322
323 } else if (ir->mask_keyup) { 323 } else if (ir->mask_keyup) {
324 /* bit cleared on keydown */ 324 /* bit cleared on keydown */
325 if (0 == (gpio & ir->mask_keyup)) { 325 if (0 == (gpio & ir->mask_keyup)) {
326 ir_input_keydown(&ir->input, &ir->ir, data, data); 326 ir_input_keydown(ir->input, &ir->ir, data, data);
327 } else { 327 } else {
328 ir_input_nokey(&ir->input, &ir->ir); 328 ir_input_nokey(ir->input, &ir->ir);
329 } 329 }
330 330
331 } else { 331 } else {
332 /* can't distinguish keydown/up :-/ */ 332 /* can't distinguish keydown/up :-/ */
333 ir_input_keydown(&ir->input, &ir->ir, data, data); 333 ir_input_keydown(ir->input, &ir->ir, data, data);
334 ir_input_nokey(&ir->input, &ir->ir); 334 ir_input_nokey(ir->input, &ir->ir);
335 } 335 }
336} 336}
337 337
@@ -357,13 +357,19 @@ static void cx88_ir_work(void *data)
357int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci) 357int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
358{ 358{
359 struct cx88_IR *ir; 359 struct cx88_IR *ir;
360 struct input_dev *input_dev;
360 IR_KEYTAB_TYPE *ir_codes = NULL; 361 IR_KEYTAB_TYPE *ir_codes = NULL;
361 int ir_type = IR_TYPE_OTHER; 362 int ir_type = IR_TYPE_OTHER;
362 363
363 ir = kmalloc(sizeof(*ir), GFP_KERNEL); 364 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
364 if (NULL == ir) 365 input_dev = input_allocate_device();
366 if (!ir || !input_dev) {
367 kfree(ir);
368 input_free_device(input_dev);
365 return -ENOMEM; 369 return -ENOMEM;
366 memset(ir, 0, sizeof(*ir)); 370 }
371
372 ir->input = input_dev;
367 373
368 /* detect & configure */ 374 /* detect & configure */
369 switch (core->board) { 375 switch (core->board) {
@@ -425,6 +431,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
425 431
426 if (NULL == ir_codes) { 432 if (NULL == ir_codes) {
427 kfree(ir); 433 kfree(ir);
434 input_free_device(input_dev);
428 return -ENODEV; 435 return -ENODEV;
429 } 436 }
430 437
@@ -433,19 +440,19 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
433 cx88_boards[core->board].name); 440 cx88_boards[core->board].name);
434 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(pci)); 441 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(pci));
435 442
436 ir_input_init(&ir->input, &ir->ir, ir_type, ir_codes); 443 ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
437 ir->input.name = ir->name; 444 input_dev->name = ir->name;
438 ir->input.phys = ir->phys; 445 input_dev->phys = ir->phys;
439 ir->input.id.bustype = BUS_PCI; 446 input_dev->id.bustype = BUS_PCI;
440 ir->input.id.version = 1; 447 input_dev->id.version = 1;
441 if (pci->subsystem_vendor) { 448 if (pci->subsystem_vendor) {
442 ir->input.id.vendor = pci->subsystem_vendor; 449 input_dev->id.vendor = pci->subsystem_vendor;
443 ir->input.id.product = pci->subsystem_device; 450 input_dev->id.product = pci->subsystem_device;
444 } else { 451 } else {
445 ir->input.id.vendor = pci->vendor; 452 input_dev->id.vendor = pci->vendor;
446 ir->input.id.product = pci->device; 453 input_dev->id.product = pci->device;
447 } 454 }
448 ir->input.dev = &pci->dev; 455 input_dev->cdev.dev = &pci->dev;
449 456
450 /* record handles to ourself */ 457 /* record handles to ourself */
451 ir->core = core; 458 ir->core = core;
@@ -465,8 +472,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
465 } 472 }
466 473
467 /* all done */ 474 /* all done */
468 input_register_device(&ir->input); 475 input_register_device(ir->input);
469 printk("%s: registered IR remote control\n", core->name);
470 476
471 return 0; 477 return 0;
472} 478}
@@ -484,7 +490,7 @@ int cx88_ir_fini(struct cx88_core *core)
484 flush_scheduled_work(); 490 flush_scheduled_work();
485 } 491 }
486 492
487 input_unregister_device(&ir->input); 493 input_unregister_device(ir->input);
488 kfree(ir); 494 kfree(ir);
489 495
490 /* done */ 496 /* done */
@@ -515,7 +521,7 @@ void cx88_ir_irq(struct cx88_core *core)
515 if (!ir->scount) { 521 if (!ir->scount) {
516 /* nothing to sample */ 522 /* nothing to sample */
517 if (ir->ir.keypressed && time_after(jiffies, ir->release)) 523 if (ir->ir.keypressed && time_after(jiffies, ir->release))
518 ir_input_nokey(&ir->input, &ir->ir); 524 ir_input_nokey(ir->input, &ir->ir);
519 return; 525 return;
520 } 526 }
521 527
@@ -557,7 +563,7 @@ void cx88_ir_irq(struct cx88_core *core)
557 563
558 ir_dprintk("Key Code: %x\n", (ircode >> 16) & 0x7f); 564 ir_dprintk("Key Code: %x\n", (ircode >> 16) & 0x7f);
559 565
560 ir_input_keydown(&ir->input, &ir->ir, (ircode >> 16) & 0x7f, (ircode >> 16) & 0xff); 566 ir_input_keydown(ir->input, &ir->ir, (ircode >> 16) & 0x7f, (ircode >> 16) & 0xff);
561 ir->release = jiffies + msecs_to_jiffies(120); 567 ir->release = jiffies + msecs_to_jiffies(120);
562 break; 568 break;
563 case CX88_BOARD_HAUPPAUGE: 569 case CX88_BOARD_HAUPPAUGE:
@@ -566,7 +572,7 @@ void cx88_ir_irq(struct cx88_core *core)
566 ir_dprintk("biphase decoded: %x\n", ircode); 572 ir_dprintk("biphase decoded: %x\n", ircode);
567 if ((ircode & 0xfffff000) != 0x3000) 573 if ((ircode & 0xfffff000) != 0x3000)
568 break; 574 break;
569 ir_input_keydown(&ir->input, &ir->ir, ircode & 0x3f, ircode); 575 ir_input_keydown(ir->input, &ir->ir, ircode & 0x3f, ircode);
570 ir->release = jiffies + msecs_to_jiffies(120); 576 ir->release = jiffies + msecs_to_jiffies(120);
571 break; 577 break;
572 } 578 }
diff --git a/drivers/media/video/indycam.c b/drivers/media/video/indycam.c
index b2b0384cd4b9..26dd06ec89a2 100644
--- a/drivers/media/video/indycam.c
+++ b/drivers/media/video/indycam.c
@@ -9,16 +9,16 @@
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 */ 10 */
11 11
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/delay.h> 12#include <linux/delay.h>
15#include <linux/errno.h> 13#include <linux/errno.h>
16#include <linux/fs.h> 14#include <linux/fs.h>
15#include <linux/init.h>
17#include <linux/kernel.h> 16#include <linux/kernel.h>
18#include <linux/major.h> 17#include <linux/major.h>
19#include <linux/slab.h> 18#include <linux/module.h>
20#include <linux/mm.h> 19#include <linux/mm.h>
21#include <linux/sched.h> 20#include <linux/sched.h>
21#include <linux/slab.h>
22 22
23#include <linux/videodev.h> 23#include <linux/videodev.h>
24/* IndyCam decodes stream of photons into digital image representation ;-) */ 24/* IndyCam decodes stream of photons into digital image representation ;-) */
@@ -44,8 +44,6 @@ MODULE_LICENSE("GPL");
44#define indycam_regdump(client) 44#define indycam_regdump(client)
45#endif 45#endif
46 46
47#define VINO_ADAPTER (I2C_ALGO_SGI | I2C_HW_SGI_VINO)
48
49struct indycam { 47struct indycam {
50 struct i2c_client *client; 48 struct i2c_client *client;
51 int version; 49 int version;
@@ -300,7 +298,7 @@ out_free_client:
300static int indycam_probe(struct i2c_adapter *adap) 298static int indycam_probe(struct i2c_adapter *adap)
301{ 299{
302 /* Indy specific crap */ 300 /* Indy specific crap */
303 if (adap->id == VINO_ADAPTER) 301 if (adap->id == I2C_HW_SGI_VINO)
304 return indycam_attach(adap, INDYCAM_ADDR, 0); 302 return indycam_attach(adap, INDYCAM_ADDR, 0);
305 /* Feel free to add probe here :-) */ 303 /* Feel free to add probe here :-) */
306 return -ENODEV; 304 return -ENODEV;
diff --git a/drivers/media/video/ir-kbd-gpio.c b/drivers/media/video/ir-kbd-gpio.c
index cf292da8fdd5..234151e48edc 100644
--- a/drivers/media/video/ir-kbd-gpio.c
+++ b/drivers/media/video/ir-kbd-gpio.c
@@ -158,7 +158,7 @@ static IR_KEYTAB_TYPE ir_codes_apac_viewcomp[IR_KEYTAB_SIZE] = {
158 158
159struct IR { 159struct IR {
160 struct bttv_sub_device *sub; 160 struct bttv_sub_device *sub;
161 struct input_dev input; 161 struct input_dev *input;
162 struct ir_input_state ir; 162 struct ir_input_state ir;
163 char name[32]; 163 char name[32];
164 char phys[32]; 164 char phys[32];
@@ -217,23 +217,23 @@ static void ir_handle_key(struct IR *ir)
217 if (ir->mask_keydown) { 217 if (ir->mask_keydown) {
218 /* bit set on keydown */ 218 /* bit set on keydown */
219 if (gpio & ir->mask_keydown) { 219 if (gpio & ir->mask_keydown) {
220 ir_input_keydown(&ir->input,&ir->ir,data,data); 220 ir_input_keydown(ir->input, &ir->ir, data, data);
221 } else { 221 } else {
222 ir_input_nokey(&ir->input,&ir->ir); 222 ir_input_nokey(ir->input, &ir->ir);
223 } 223 }
224 224
225 } else if (ir->mask_keyup) { 225 } else if (ir->mask_keyup) {
226 /* bit cleared on keydown */ 226 /* bit cleared on keydown */
227 if (0 == (gpio & ir->mask_keyup)) { 227 if (0 == (gpio & ir->mask_keyup)) {
228 ir_input_keydown(&ir->input,&ir->ir,data,data); 228 ir_input_keydown(ir->input, &ir->ir, data, data);
229 } else { 229 } else {
230 ir_input_nokey(&ir->input,&ir->ir); 230 ir_input_nokey(ir->input, &ir->ir);
231 } 231 }
232 232
233 } else { 233 } else {
234 /* can't disturgissh keydown/up :-/ */ 234 /* can't disturgissh keydown/up :-/ */
235 ir_input_keydown(&ir->input,&ir->ir,data,data); 235 ir_input_keydown(ir->input, &ir->ir, data, data);
236 ir_input_nokey(&ir->input,&ir->ir); 236 ir_input_nokey(ir->input, &ir->ir);
237 } 237 }
238} 238}
239 239
@@ -268,13 +268,17 @@ static int ir_probe(struct device *dev)
268{ 268{
269 struct bttv_sub_device *sub = to_bttv_sub_dev(dev); 269 struct bttv_sub_device *sub = to_bttv_sub_dev(dev);
270 struct IR *ir; 270 struct IR *ir;
271 struct input_dev *input_dev;
271 IR_KEYTAB_TYPE *ir_codes = NULL; 272 IR_KEYTAB_TYPE *ir_codes = NULL;
272 int ir_type = IR_TYPE_OTHER; 273 int ir_type = IR_TYPE_OTHER;
273 274
274 ir = kmalloc(sizeof(*ir),GFP_KERNEL); 275 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
275 if (NULL == ir) 276 input_dev = input_allocate_device();
277 if (!ir || !input_dev) {
278 kfree(ir);
279 input_free_device(input_dev);
276 return -ENOMEM; 280 return -ENOMEM;
277 memset(ir,0,sizeof(*ir)); 281 }
278 282
279 /* detect & configure */ 283 /* detect & configure */
280 switch (sub->core->type) { 284 switch (sub->core->type) {
@@ -328,6 +332,7 @@ static int ir_probe(struct device *dev)
328 } 332 }
329 if (NULL == ir_codes) { 333 if (NULL == ir_codes) {
330 kfree(ir); 334 kfree(ir);
335 input_free_device(input_dev);
331 return -ENODEV; 336 return -ENODEV;
332 } 337 }
333 338
@@ -341,19 +346,19 @@ static int ir_probe(struct device *dev)
341 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", 346 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
342 pci_name(sub->core->pci)); 347 pci_name(sub->core->pci));
343 348
344 ir_input_init(&ir->input, &ir->ir, ir_type, ir_codes); 349 ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
345 ir->input.name = ir->name; 350 input_dev->name = ir->name;
346 ir->input.phys = ir->phys; 351 input_dev->phys = ir->phys;
347 ir->input.id.bustype = BUS_PCI; 352 input_dev->id.bustype = BUS_PCI;
348 ir->input.id.version = 1; 353 input_dev->id.version = 1;
349 if (sub->core->pci->subsystem_vendor) { 354 if (sub->core->pci->subsystem_vendor) {
350 ir->input.id.vendor = sub->core->pci->subsystem_vendor; 355 input_dev->id.vendor = sub->core->pci->subsystem_vendor;
351 ir->input.id.product = sub->core->pci->subsystem_device; 356 input_dev->id.product = sub->core->pci->subsystem_device;
352 } else { 357 } else {
353 ir->input.id.vendor = sub->core->pci->vendor; 358 input_dev->id.vendor = sub->core->pci->vendor;
354 ir->input.id.product = sub->core->pci->device; 359 input_dev->id.product = sub->core->pci->device;
355 } 360 }
356 ir->input.dev = &sub->core->pci->dev; 361 input_dev->cdev.dev = &sub->core->pci->dev;
357 362
358 if (ir->polling) { 363 if (ir->polling) {
359 INIT_WORK(&ir->work, ir_work, ir); 364 INIT_WORK(&ir->work, ir_work, ir);
@@ -364,9 +369,8 @@ static int ir_probe(struct device *dev)
364 } 369 }
365 370
366 /* all done */ 371 /* all done */
367 dev_set_drvdata(dev,ir); 372 dev_set_drvdata(dev, ir);
368 input_register_device(&ir->input); 373 input_register_device(ir->input);
369 printk(DEVNAME ": %s detected at %s\n",ir->input.name,ir->input.phys);
370 374
371 return 0; 375 return 0;
372} 376}
@@ -380,7 +384,7 @@ static int ir_remove(struct device *dev)
380 flush_scheduled_work(); 384 flush_scheduled_work();
381 } 385 }
382 386
383 input_unregister_device(&ir->input); 387 input_unregister_device(ir->input);
384 kfree(ir); 388 kfree(ir);
385 return 0; 389 return 0;
386} 390}
diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c
index 67105b9804a2..9703d3d351f9 100644
--- a/drivers/media/video/ir-kbd-i2c.c
+++ b/drivers/media/video/ir-kbd-i2c.c
@@ -121,10 +121,9 @@ static IR_KEYTAB_TYPE ir_codes_purpletv[IR_KEYTAB_SIZE] = {
121 121
122}; 122};
123 123
124struct IR;
125struct IR { 124struct IR {
126 struct i2c_client c; 125 struct i2c_client c;
127 struct input_dev input; 126 struct input_dev *input;
128 struct ir_input_state ir; 127 struct ir_input_state ir;
129 128
130 struct work_struct work; 129 struct work_struct work;
@@ -271,9 +270,9 @@ static void ir_key_poll(struct IR *ir)
271 } 270 }
272 271
273 if (0 == rc) { 272 if (0 == rc) {
274 ir_input_nokey(&ir->input,&ir->ir); 273 ir_input_nokey(ir->input, &ir->ir);
275 } else { 274 } else {
276 ir_input_keydown(&ir->input,&ir->ir, ir_key, ir_raw); 275 ir_input_keydown(ir->input, &ir->ir, ir_key, ir_raw);
277 } 276 }
278} 277}
279 278
@@ -318,11 +317,18 @@ static int ir_attach(struct i2c_adapter *adap, int addr,
318 char *name; 317 char *name;
319 int ir_type; 318 int ir_type;
320 struct IR *ir; 319 struct IR *ir;
320 struct input_dev *input_dev;
321 321
322 if (NULL == (ir = kmalloc(sizeof(struct IR),GFP_KERNEL))) 322 ir = kzalloc(sizeof(struct IR), GFP_KERNEL);
323 input_dev = input_allocate_device();
324 if (!ir || !input_dev) {
325 kfree(ir);
326 input_free_device(input_dev);
323 return -ENOMEM; 327 return -ENOMEM;
324 memset(ir,0,sizeof(*ir)); 328 }
329
325 ir->c = client_template; 330 ir->c = client_template;
331 ir->input = input_dev;
326 332
327 i2c_set_clientdata(&ir->c, ir); 333 i2c_set_clientdata(&ir->c, ir);
328 ir->c.adapter = adap; 334 ir->c.adapter = adap;
@@ -375,13 +381,12 @@ static int ir_attach(struct i2c_adapter *adap, int addr,
375 ir->c.dev.bus_id); 381 ir->c.dev.bus_id);
376 382
377 /* init + register input device */ 383 /* init + register input device */
378 ir_input_init(&ir->input,&ir->ir,ir_type,ir_codes); 384 ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
379 ir->input.id.bustype = BUS_I2C; 385 input_dev->id.bustype = BUS_I2C;
380 ir->input.name = ir->c.name; 386 input_dev->name = ir->c.name;
381 ir->input.phys = ir->phys; 387 input_dev->phys = ir->phys;
382 input_register_device(&ir->input); 388
383 printk(DEVNAME ": %s detected at %s [%s]\n", 389 input_register_device(ir->input);
384 ir->input.name,ir->input.phys,adap->name);
385 390
386 /* start polling via eventd */ 391 /* start polling via eventd */
387 INIT_WORK(&ir->work, ir_work, ir); 392 INIT_WORK(&ir->work, ir_work, ir);
@@ -402,7 +407,7 @@ static int ir_detach(struct i2c_client *client)
402 flush_scheduled_work(); 407 flush_scheduled_work();
403 408
404 /* unregister devices */ 409 /* unregister devices */
405 input_unregister_device(&ir->input); 410 input_unregister_device(ir->input);
406 i2c_detach_client(&ir->c); 411 i2c_detach_client(&ir->c);
407 412
408 /* free memory */ 413 /* free memory */
diff --git a/drivers/media/video/msp3400.c b/drivers/media/video/msp3400.c
index f0d43fc2632f..262890cb20a7 100644
--- a/drivers/media/video/msp3400.c
+++ b/drivers/media/video/msp3400.c
@@ -1420,8 +1420,8 @@ static int msp_detach(struct i2c_client *client);
1420static int msp_probe(struct i2c_adapter *adap); 1420static int msp_probe(struct i2c_adapter *adap);
1421static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg); 1421static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg);
1422 1422
1423static int msp_suspend(struct device * dev, pm_message_t state, u32 level); 1423static int msp_suspend(struct device * dev, pm_message_t state);
1424static int msp_resume(struct device * dev, u32 level); 1424static int msp_resume(struct device * dev);
1425 1425
1426static void msp_wake_thread(struct i2c_client *client); 1426static void msp_wake_thread(struct i2c_client *client);
1427 1427
@@ -1821,7 +1821,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
1821 return 0; 1821 return 0;
1822} 1822}
1823 1823
1824static int msp_suspend(struct device * dev, pm_message_t state, u32 level) 1824static int msp_suspend(struct device * dev, pm_message_t state)
1825{ 1825{
1826 struct i2c_client *c = container_of(dev, struct i2c_client, dev); 1826 struct i2c_client *c = container_of(dev, struct i2c_client, dev);
1827 1827
@@ -1830,7 +1830,7 @@ static int msp_suspend(struct device * dev, pm_message_t state, u32 level)
1830 return 0; 1830 return 0;
1831} 1831}
1832 1832
1833static int msp_resume(struct device * dev, u32 level) 1833static int msp_resume(struct device * dev)
1834{ 1834{
1835 struct i2c_client *c = container_of(dev, struct i2c_client, dev); 1835 struct i2c_client *c = container_of(dev, struct i2c_client, dev);
1836 1836
diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c
index 1f456c4d76f2..242cb235cf92 100644
--- a/drivers/media/video/saa7134/saa7134-input.c
+++ b/drivers/media/video/saa7134/saa7134-input.c
@@ -425,9 +425,9 @@ static int build_key(struct saa7134_dev *dev)
425 425
426 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) || 426 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
427 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) { 427 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
428 ir_input_keydown(&ir->dev,&ir->ir,data,data); 428 ir_input_keydown(ir->dev, &ir->ir, data, data);
429 } else { 429 } else {
430 ir_input_nokey(&ir->dev,&ir->ir); 430 ir_input_nokey(ir->dev, &ir->ir);
431 } 431 }
432 return 0; 432 return 0;
433} 433}
@@ -456,6 +456,7 @@ static void saa7134_input_timer(unsigned long data)
456int saa7134_input_init1(struct saa7134_dev *dev) 456int saa7134_input_init1(struct saa7134_dev *dev)
457{ 457{
458 struct saa7134_ir *ir; 458 struct saa7134_ir *ir;
459 struct input_dev *input_dev;
459 IR_KEYTAB_TYPE *ir_codes = NULL; 460 IR_KEYTAB_TYPE *ir_codes = NULL;
460 u32 mask_keycode = 0; 461 u32 mask_keycode = 0;
461 u32 mask_keydown = 0; 462 u32 mask_keydown = 0;
@@ -535,10 +536,13 @@ int saa7134_input_init1(struct saa7134_dev *dev)
535 return -ENODEV; 536 return -ENODEV;
536 } 537 }
537 538
538 ir = kmalloc(sizeof(*ir),GFP_KERNEL); 539 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
539 if (NULL == ir) 540 input_dev = input_allocate_device();
541 if (!ir || !input_dev) {
542 kfree(ir);
543 input_free_device(input_dev);
540 return -ENOMEM; 544 return -ENOMEM;
541 memset(ir,0,sizeof(*ir)); 545 }
542 546
543 /* init hardware-specific stuff */ 547 /* init hardware-specific stuff */
544 ir->mask_keycode = mask_keycode; 548 ir->mask_keycode = mask_keycode;
@@ -552,19 +556,19 @@ int saa7134_input_init1(struct saa7134_dev *dev)
552 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", 556 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
553 pci_name(dev->pci)); 557 pci_name(dev->pci));
554 558
555 ir_input_init(&ir->dev, &ir->ir, ir_type, ir_codes); 559 ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
556 ir->dev.name = ir->name; 560 input_dev->name = ir->name;
557 ir->dev.phys = ir->phys; 561 input_dev->phys = ir->phys;
558 ir->dev.id.bustype = BUS_PCI; 562 input_dev->id.bustype = BUS_PCI;
559 ir->dev.id.version = 1; 563 input_dev->id.version = 1;
560 if (dev->pci->subsystem_vendor) { 564 if (dev->pci->subsystem_vendor) {
561 ir->dev.id.vendor = dev->pci->subsystem_vendor; 565 input_dev->id.vendor = dev->pci->subsystem_vendor;
562 ir->dev.id.product = dev->pci->subsystem_device; 566 input_dev->id.product = dev->pci->subsystem_device;
563 } else { 567 } else {
564 ir->dev.id.vendor = dev->pci->vendor; 568 input_dev->id.vendor = dev->pci->vendor;
565 ir->dev.id.product = dev->pci->device; 569 input_dev->id.product = dev->pci->device;
566 } 570 }
567 ir->dev.dev = &dev->pci->dev; 571 input_dev->cdev.dev = &dev->pci->dev;
568 572
569 /* all done */ 573 /* all done */
570 dev->remote = ir; 574 dev->remote = ir;
@@ -576,8 +580,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
576 add_timer(&ir->timer); 580 add_timer(&ir->timer);
577 } 581 }
578 582
579 input_register_device(&dev->remote->dev); 583 input_register_device(ir->dev);
580 printk("%s: registered input device for IR\n",dev->name);
581 return 0; 584 return 0;
582} 585}
583 586
@@ -586,9 +589,9 @@ void saa7134_input_fini(struct saa7134_dev *dev)
586 if (NULL == dev->remote) 589 if (NULL == dev->remote)
587 return; 590 return;
588 591
589 input_unregister_device(&dev->remote->dev);
590 if (dev->remote->polling) 592 if (dev->remote->polling)
591 del_timer_sync(&dev->remote->timer); 593 del_timer_sync(&dev->remote->timer);
594 input_unregister_device(dev->remote->dev);
592 kfree(dev->remote); 595 kfree(dev->remote);
593 dev->remote = NULL; 596 dev->remote = NULL;
594} 597}
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index 3ea09142ec9c..860b89530e2a 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -351,7 +351,7 @@ struct saa7134_oss {
351 351
352/* IR input */ 352/* IR input */
353struct saa7134_ir { 353struct saa7134_ir {
354 struct input_dev dev; 354 struct input_dev *dev;
355 struct ir_input_state ir; 355 struct ir_input_state ir;
356 char name[32]; 356 char name[32];
357 char phys[32]; 357 char phys[32];
diff --git a/drivers/media/video/saa7191.c b/drivers/media/video/saa7191.c
index 454f5c1199b4..3ddbb62312be 100644
--- a/drivers/media/video/saa7191.c
+++ b/drivers/media/video/saa7191.c
@@ -9,16 +9,16 @@
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 */ 10 */
11 11
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/delay.h> 12#include <linux/delay.h>
15#include <linux/errno.h> 13#include <linux/errno.h>
16#include <linux/fs.h> 14#include <linux/fs.h>
15#include <linux/init.h>
17#include <linux/kernel.h> 16#include <linux/kernel.h>
18#include <linux/major.h> 17#include <linux/major.h>
19#include <linux/slab.h> 18#include <linux/module.h>
20#include <linux/mm.h> 19#include <linux/mm.h>
21#include <linux/sched.h> 20#include <linux/sched.h>
21#include <linux/slab.h>
22 22
23#include <linux/videodev.h> 23#include <linux/videodev.h>
24#include <linux/video_decoder.h> 24#include <linux/video_decoder.h>
@@ -33,8 +33,6 @@ MODULE_VERSION(SAA7191_MODULE_VERSION);
33MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>"); 33MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>");
34MODULE_LICENSE("GPL"); 34MODULE_LICENSE("GPL");
35 35
36#define VINO_ADAPTER (I2C_ALGO_SGI | I2C_HW_SGI_VINO)
37
38struct saa7191 { 36struct saa7191 {
39 struct i2c_client *client; 37 struct i2c_client *client;
40 38
@@ -337,7 +335,7 @@ out_free_client:
337static int saa7191_probe(struct i2c_adapter *adap) 335static int saa7191_probe(struct i2c_adapter *adap)
338{ 336{
339 /* Always connected to VINO */ 337 /* Always connected to VINO */
340 if (adap->id == VINO_ADAPTER) 338 if (adap->id == I2C_HW_SGI_VINO)
341 return saa7191_attach(adap, SAA7191_ADDR, 0); 339 return saa7191_attach(adap, SAA7191_ADDR, 0);
342 /* Feel free to add probe here :-) */ 340 /* Feel free to add probe here :-) */
343 return -ENODEV; 341 return -ENODEV;
@@ -364,7 +362,7 @@ static int saa7191_command(struct i2c_client *client, unsigned int cmd,
364 362
365 cap->flags = VIDEO_DECODER_PAL | VIDEO_DECODER_NTSC | 363 cap->flags = VIDEO_DECODER_PAL | VIDEO_DECODER_NTSC |
366 VIDEO_DECODER_SECAM | VIDEO_DECODER_AUTO; 364 VIDEO_DECODER_SECAM | VIDEO_DECODER_AUTO;
367 cap->inputs = (client->adapter->id == VINO_ADAPTER) ? 2 : 1; 365 cap->inputs = (client->adapter->id == I2C_HW_SGI_VINO) ? 2 : 1;
368 cap->outputs = 1; 366 cap->outputs = 1;
369 break; 367 break;
370 } 368 }
@@ -422,7 +420,7 @@ static int saa7191_command(struct i2c_client *client, unsigned int cmd,
422 int *iarg = arg; 420 int *iarg = arg;
423 421
424 switch (client->adapter->id) { 422 switch (client->adapter->id) {
425 case VINO_ADAPTER: 423 case I2C_HW_SGI_VINO:
426 return saa7191_set_input(client, *iarg); 424 return saa7191_set_input(client, *iarg);
427 default: 425 default:
428 if (*iarg != 0) 426 if (*iarg != 0)
diff --git a/drivers/media/video/tda9887.c b/drivers/media/video/tda9887.c
index 0456dda2624d..94053f149ddf 100644
--- a/drivers/media/video/tda9887.c
+++ b/drivers/media/video/tda9887.c
@@ -784,13 +784,13 @@ tda9887_command(struct i2c_client *client, unsigned int cmd, void *arg)
784 return 0; 784 return 0;
785} 785}
786 786
787static int tda9887_suspend(struct device * dev, pm_message_t state, u32 level) 787static int tda9887_suspend(struct device * dev, pm_message_t state)
788{ 788{
789 dprintk("tda9887: suspend\n"); 789 dprintk("tda9887: suspend\n");
790 return 0; 790 return 0;
791} 791}
792 792
793static int tda9887_resume(struct device * dev, u32 level) 793static int tda9887_resume(struct device * dev)
794{ 794{
795 struct i2c_client *c = container_of(dev, struct i2c_client, dev); 795 struct i2c_client *c = container_of(dev, struct i2c_client, dev);
796 struct tda9887 *t = i2c_get_clientdata(c); 796 struct tda9887 *t = i2c_get_clientdata(c);
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index 05572020af4d..ad85bef1c3d5 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -697,7 +697,7 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
697 return 0; 697 return 0;
698} 698}
699 699
700static int tuner_suspend(struct device *dev, pm_message_t state, u32 level) 700static int tuner_suspend(struct device *dev, pm_message_t state)
701{ 701{
702 struct i2c_client *c = container_of (dev, struct i2c_client, dev); 702 struct i2c_client *c = container_of (dev, struct i2c_client, dev);
703 struct tuner *t = i2c_get_clientdata (c); 703 struct tuner *t = i2c_get_clientdata (c);
@@ -707,7 +707,7 @@ static int tuner_suspend(struct device *dev, pm_message_t state, u32 level)
707 return 0; 707 return 0;
708} 708}
709 709
710static int tuner_resume(struct device *dev, u32 level) 710static int tuner_resume(struct device *dev)
711{ 711{
712 struct i2c_client *c = container_of (dev, struct i2c_client, dev); 712 struct i2c_client *c = container_of (dev, struct i2c_client, dev);
713 struct tuner *t = i2c_get_clientdata (c); 713 struct tuner *t = i2c_get_clientdata (c);
diff --git a/drivers/media/video/vino.c b/drivers/media/video/vino.c
index d8a0f763ca10..ed4394e854ab 100644
--- a/drivers/media/video/vino.c
+++ b/drivers/media/video/vino.c
@@ -26,14 +26,15 @@
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/dma-mapping.h>
29#include <linux/errno.h> 30#include <linux/errno.h>
30#include <linux/fs.h> 31#include <linux/fs.h>
32#include <linux/interrupt.h>
31#include <linux/kernel.h> 33#include <linux/kernel.h>
32#include <linux/mm.h> 34#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> 35#include <linux/moduleparam.h>
36#include <linux/time.h>
37#include <linux/version.h>
37 38
38#ifdef CONFIG_KMOD 39#ifdef CONFIG_KMOD
39#include <linux/kmod.h> 40#include <linux/kmod.h>
diff --git a/drivers/message/i2o/core.h b/drivers/message/i2o/core.h
index c5bcfd70f711..9eefedb16211 100644
--- a/drivers/message/i2o/core.h
+++ b/drivers/message/i2o/core.h
@@ -36,9 +36,6 @@ extern void __exit i2o_pci_exit(void);
36extern void i2o_device_remove(struct i2o_device *); 36extern void i2o_device_remove(struct i2o_device *);
37extern int i2o_device_parse_lct(struct i2o_controller *); 37extern int i2o_device_parse_lct(struct i2o_controller *);
38 38
39extern int i2o_device_init(void);
40extern void i2o_device_exit(void);
41
42/* IOP */ 39/* IOP */
43extern struct i2o_controller *i2o_iop_alloc(void); 40extern struct i2o_controller *i2o_iop_alloc(void);
44extern void i2o_iop_free(struct i2o_controller *); 41extern void i2o_iop_free(struct i2o_controller *);
diff --git a/drivers/message/i2o/debug.c b/drivers/message/i2o/debug.c
index 018ca887ca85..40d4ea898dbc 100644
--- a/drivers/message/i2o/debug.c
+++ b/drivers/message/i2o/debug.c
@@ -90,7 +90,7 @@ static void i2o_report_fail_status(u8 req_status, u32 * msg)
90 }; 90 };
91 91
92 if (req_status == I2O_FSC_TRANSPORT_UNKNOWN_FAILURE) 92 if (req_status == I2O_FSC_TRANSPORT_UNKNOWN_FAILURE)
93 printk(KERN_DEBUG "TRANSPORT_UNKNOWN_FAILURE (%0#2x)\n.", 93 printk(KERN_DEBUG "TRANSPORT_UNKNOWN_FAILURE (%0#2x).\n",
94 req_status); 94 req_status);
95 else 95 else
96 printk(KERN_DEBUG "TRANSPORT_%s.\n", 96 printk(KERN_DEBUG "TRANSPORT_%s.\n",
diff --git a/drivers/message/i2o/device.c b/drivers/message/i2o/device.c
index 21f16ba3ac38..8eb50cdb8ae1 100644
--- a/drivers/message/i2o/device.c
+++ b/drivers/message/i2o/device.c
@@ -16,6 +16,8 @@
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/i2o.h> 17#include <linux/i2o.h>
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/string.h>
20#include <linux/slab.h>
19#include "core.h" 21#include "core.h"
20 22
21/** 23/**
@@ -45,10 +47,10 @@ static inline int i2o_device_issue_claim(struct i2o_device *dev, u32 cmd,
45 writel(type, &msg->body[0]); 47 writel(type, &msg->body[0]);
46 48
47 return i2o_msg_post_wait(dev->iop, m, 60); 49 return i2o_msg_post_wait(dev->iop, m, 60);
48}; 50}
49 51
50/** 52/**
51 * i2o_device_claim - claim a device for use by an OSM 53 * i2o_device_claim - claim a device for use by an OSM
52 * @dev: I2O device to claim 54 * @dev: I2O device to claim
53 * @drv: I2O driver which wants to claim the device 55 * @drv: I2O driver which wants to claim the device
54 * 56 *
@@ -73,7 +75,7 @@ int i2o_device_claim(struct i2o_device *dev)
73 up(&dev->lock); 75 up(&dev->lock);
74 76
75 return rc; 77 return rc;
76}; 78}
77 79
78/** 80/**
79 * i2o_device_claim_release - release a device that the OSM is using 81 * i2o_device_claim_release - release a device that the OSM is using
@@ -119,7 +121,8 @@ int i2o_device_claim_release(struct i2o_device *dev)
119 up(&dev->lock); 121 up(&dev->lock);
120 122
121 return rc; 123 return rc;
122}; 124}
125
123 126
124/** 127/**
125 * i2o_device_release - release the memory for a I2O device 128 * i2o_device_release - release the memory for a I2O device
@@ -135,39 +138,47 @@ static void i2o_device_release(struct device *dev)
135 pr_debug("i2o: device %s released\n", dev->bus_id); 138 pr_debug("i2o: device %s released\n", dev->bus_id);
136 139
137 kfree(i2o_dev); 140 kfree(i2o_dev);
138}; 141}
142
139 143
140/** 144/**
141 * i2o_device_class_release - Remove I2O device attributes 145 * i2o_device_class_show_class_id - Displays class id of I2O device
142 * @cd: I2O class device which is added to the I2O device class 146 * @cd: class device of which the class id should be displayed
147 * @buf: buffer into which the class id should be printed
143 * 148 *
144 * Removes attributes from the I2O device again. Also search each device 149 * Returns the number of bytes which are printed into the buffer.
145 * on the controller for I2O devices which refert to this device as parent
146 * or user and remove this links also.
147 */ 150 */
148static void i2o_device_class_release(struct class_device *cd) 151static ssize_t i2o_device_show_class_id(struct device *dev,
152 struct device_attribute *attr,
153 char *buf)
149{ 154{
150 struct i2o_device *i2o_dev, *tmp; 155 struct i2o_device *i2o_dev = to_i2o_device(dev);
151 struct i2o_controller *c;
152 156
153 i2o_dev = to_i2o_device(cd->dev); 157 sprintf(buf, "0x%03x\n", i2o_dev->lct_data.class_id);
154 c = i2o_dev->iop; 158 return strlen(buf) + 1;
159}
155 160
156 sysfs_remove_link(&i2o_dev->device.kobj, "parent"); 161/**
157 sysfs_remove_link(&i2o_dev->device.kobj, "user"); 162 * i2o_device_class_show_tid - Displays TID of I2O device
163 * @cd: class device of which the TID should be displayed
164 * @buf: buffer into which the class id should be printed
165 *
166 * Returns the number of bytes which are printed into the buffer.
167 */
168static ssize_t i2o_device_show_tid(struct device *dev,
169 struct device_attribute *attr,
170 char *buf)
171{
172 struct i2o_device *i2o_dev = to_i2o_device(dev);
158 173
159 list_for_each_entry(tmp, &c->devices, list) { 174 sprintf(buf, "0x%03x\n", i2o_dev->lct_data.tid);
160 if (tmp->lct_data.parent_tid == i2o_dev->lct_data.tid) 175 return strlen(buf) + 1;
161 sysfs_remove_link(&tmp->device.kobj, "parent"); 176}
162 if (tmp->lct_data.user_tid == i2o_dev->lct_data.tid)
163 sysfs_remove_link(&tmp->device.kobj, "user");
164 }
165};
166 177
167/* I2O device class */ 178struct device_attribute i2o_device_attrs[] = {
168static struct class i2o_device_class = { 179 __ATTR(class_id, S_IRUGO, i2o_device_show_class_id, NULL),
169 .name = "i2o_device", 180 __ATTR(tid, S_IRUGO, i2o_device_show_tid, NULL),
170 .release = i2o_device_class_release 181 __ATTR_NULL
171}; 182};
172 183
173/** 184/**
@@ -193,11 +204,69 @@ static struct i2o_device *i2o_device_alloc(void)
193 204
194 dev->device.bus = &i2o_bus_type; 205 dev->device.bus = &i2o_bus_type;
195 dev->device.release = &i2o_device_release; 206 dev->device.release = &i2o_device_release;
196 dev->classdev.class = &i2o_device_class;
197 dev->classdev.dev = &dev->device;
198 207
199 return dev; 208 return dev;
200}; 209}
210
211/**
212 * i2o_setup_sysfs_links - Adds attributes to the I2O device
213 * @cd: I2O class device which is added to the I2O device class
214 *
215 * This function get called when a I2O device is added to the class. It
216 * creates the attributes for each device and creates user/parent symlink
217 * if necessary.
218 *
219 * Returns 0 on success or negative error code on failure.
220 */
221static void i2o_setup_sysfs_links(struct i2o_device *i2o_dev)
222{
223 struct i2o_controller *c = i2o_dev->iop;
224 struct i2o_device *tmp;
225
226 /* create user entries for this device */
227 tmp = i2o_iop_find_device(i2o_dev->iop, i2o_dev->lct_data.user_tid);
228 if (tmp && tmp != i2o_dev)
229 sysfs_create_link(&i2o_dev->device.kobj,
230 &tmp->device.kobj, "user");
231
232 /* create user entries refering to this device */
233 list_for_each_entry(tmp, &c->devices, list)
234 if (tmp->lct_data.user_tid == i2o_dev->lct_data.tid &&
235 tmp != i2o_dev)
236 sysfs_create_link(&tmp->device.kobj,
237 &i2o_dev->device.kobj, "user");
238
239 /* create parent entries for this device */
240 tmp = i2o_iop_find_device(i2o_dev->iop, i2o_dev->lct_data.parent_tid);
241 if (tmp && tmp != i2o_dev)
242 sysfs_create_link(&i2o_dev->device.kobj,
243 &tmp->device.kobj, "parent");
244
245 /* create parent entries refering to this device */
246 list_for_each_entry(tmp, &c->devices, list)
247 if (tmp->lct_data.parent_tid == i2o_dev->lct_data.tid &&
248 tmp != i2o_dev)
249 sysfs_create_link(&tmp->device.kobj,
250 &i2o_dev->device.kobj, "parent");
251}
252
253static void i2o_remove_sysfs_links(struct i2o_device *i2o_dev)
254{
255 struct i2o_controller *c = i2o_dev->iop;
256 struct i2o_device *tmp;
257
258 sysfs_remove_link(&i2o_dev->device.kobj, "parent");
259 sysfs_remove_link(&i2o_dev->device.kobj, "user");
260
261 list_for_each_entry(tmp, &c->devices, list) {
262 if (tmp->lct_data.parent_tid == i2o_dev->lct_data.tid)
263 sysfs_remove_link(&tmp->device.kobj, "parent");
264 if (tmp->lct_data.user_tid == i2o_dev->lct_data.tid)
265 sysfs_remove_link(&tmp->device.kobj, "user");
266 }
267}
268
269
201 270
202/** 271/**
203 * i2o_device_add - allocate a new I2O device and add it to the IOP 272 * i2o_device_add - allocate a new I2O device and add it to the IOP
@@ -222,28 +291,25 @@ static struct i2o_device *i2o_device_add(struct i2o_controller *c,
222 } 291 }
223 292
224 dev->lct_data = *entry; 293 dev->lct_data = *entry;
294 dev->iop = c;
225 295
226 snprintf(dev->device.bus_id, BUS_ID_SIZE, "%d:%03x", c->unit, 296 snprintf(dev->device.bus_id, BUS_ID_SIZE, "%d:%03x", c->unit,
227 dev->lct_data.tid); 297 dev->lct_data.tid);
228 298
229 snprintf(dev->classdev.class_id, BUS_ID_SIZE, "%d:%03x", c->unit,
230 dev->lct_data.tid);
231
232 dev->iop = c;
233 dev->device.parent = &c->device; 299 dev->device.parent = &c->device;
234 300
235 device_register(&dev->device); 301 device_register(&dev->device);
236 302
237 list_add_tail(&dev->list, &c->devices); 303 list_add_tail(&dev->list, &c->devices);
238 304
239 class_device_register(&dev->classdev); 305 i2o_setup_sysfs_links(dev);
240 306
241 i2o_driver_notify_device_add_all(dev); 307 i2o_driver_notify_device_add_all(dev);
242 308
243 pr_debug("i2o: device %s added\n", dev->device.bus_id); 309 pr_debug("i2o: device %s added\n", dev->device.bus_id);
244 310
245 return dev; 311 return dev;
246}; 312}
247 313
248/** 314/**
249 * i2o_device_remove - remove an I2O device from the I2O core 315 * i2o_device_remove - remove an I2O device from the I2O core
@@ -256,10 +322,10 @@ static struct i2o_device *i2o_device_add(struct i2o_controller *c,
256void i2o_device_remove(struct i2o_device *i2o_dev) 322void i2o_device_remove(struct i2o_device *i2o_dev)
257{ 323{
258 i2o_driver_notify_device_remove_all(i2o_dev); 324 i2o_driver_notify_device_remove_all(i2o_dev);
259 class_device_unregister(&i2o_dev->classdev); 325 i2o_remove_sysfs_links(i2o_dev);
260 list_del(&i2o_dev->list); 326 list_del(&i2o_dev->list);
261 device_unregister(&i2o_dev->device); 327 device_unregister(&i2o_dev->device);
262}; 328}
263 329
264/** 330/**
265 * i2o_device_parse_lct - Parse a previously fetched LCT and create devices 331 * i2o_device_parse_lct - Parse a previously fetched LCT and create devices
@@ -337,99 +403,8 @@ int i2o_device_parse_lct(struct i2o_controller *c)
337 up(&c->lct_lock); 403 up(&c->lct_lock);
338 404
339 return 0; 405 return 0;
340}; 406}
341
342/**
343 * i2o_device_class_show_class_id - Displays class id of I2O device
344 * @cd: class device of which the class id should be displayed
345 * @buf: buffer into which the class id should be printed
346 *
347 * Returns the number of bytes which are printed into the buffer.
348 */
349static ssize_t i2o_device_class_show_class_id(struct class_device *cd,
350 char *buf)
351{
352 struct i2o_device *dev = to_i2o_device(cd->dev);
353
354 sprintf(buf, "0x%03x\n", dev->lct_data.class_id);
355 return strlen(buf) + 1;
356};
357
358/**
359 * i2o_device_class_show_tid - Displays TID of I2O device
360 * @cd: class device of which the TID should be displayed
361 * @buf: buffer into which the class id should be printed
362 *
363 * Returns the number of bytes which are printed into the buffer.
364 */
365static ssize_t i2o_device_class_show_tid(struct class_device *cd, char *buf)
366{
367 struct i2o_device *dev = to_i2o_device(cd->dev);
368
369 sprintf(buf, "0x%03x\n", dev->lct_data.tid);
370 return strlen(buf) + 1;
371};
372
373/* I2O device class attributes */
374static CLASS_DEVICE_ATTR(class_id, S_IRUGO, i2o_device_class_show_class_id,
375 NULL);
376static CLASS_DEVICE_ATTR(tid, S_IRUGO, i2o_device_class_show_tid, NULL);
377
378/**
379 * i2o_device_class_add - Adds attributes to the I2O device
380 * @cd: I2O class device which is added to the I2O device class
381 *
382 * This function get called when a I2O device is added to the class. It
383 * creates the attributes for each device and creates user/parent symlink
384 * if necessary.
385 *
386 * Returns 0 on success or negative error code on failure.
387 */
388static int i2o_device_class_add(struct class_device *cd)
389{
390 struct i2o_device *i2o_dev, *tmp;
391 struct i2o_controller *c;
392
393 i2o_dev = to_i2o_device(cd->dev);
394 c = i2o_dev->iop;
395
396 class_device_create_file(cd, &class_device_attr_class_id);
397 class_device_create_file(cd, &class_device_attr_tid);
398
399 /* create user entries for this device */
400 tmp = i2o_iop_find_device(i2o_dev->iop, i2o_dev->lct_data.user_tid);
401 if (tmp && (tmp != i2o_dev))
402 sysfs_create_link(&i2o_dev->device.kobj, &tmp->device.kobj,
403 "user");
404
405 /* create user entries refering to this device */
406 list_for_each_entry(tmp, &c->devices, list)
407 if ((tmp->lct_data.user_tid == i2o_dev->lct_data.tid)
408 && (tmp != i2o_dev))
409 sysfs_create_link(&tmp->device.kobj,
410 &i2o_dev->device.kobj, "user");
411
412 /* create parent entries for this device */
413 tmp = i2o_iop_find_device(i2o_dev->iop, i2o_dev->lct_data.parent_tid);
414 if (tmp && (tmp != i2o_dev))
415 sysfs_create_link(&i2o_dev->device.kobj, &tmp->device.kobj,
416 "parent");
417
418 /* create parent entries refering to this device */
419 list_for_each_entry(tmp, &c->devices, list)
420 if ((tmp->lct_data.parent_tid == i2o_dev->lct_data.tid)
421 && (tmp != i2o_dev))
422 sysfs_create_link(&tmp->device.kobj,
423 &i2o_dev->device.kobj, "parent");
424
425 return 0;
426};
427 407
428/* I2O device class interface */
429static struct class_interface i2o_device_class_interface = {
430 .class = &i2o_device_class,
431 .add = i2o_device_class_add
432};
433 408
434/* 409/*
435 * Run time support routines 410 * Run time support routines
@@ -553,11 +528,11 @@ int i2o_parm_field_get(struct i2o_device *i2o_dev, int group, int field,
553} 528}
554 529
555/* 530/*
556 * if oper == I2O_PARAMS_TABLE_GET, get from all rows 531 * if oper == I2O_PARAMS_TABLE_GET, get from all rows
557 * if fieldcount == -1 return all fields 532 * if fieldcount == -1 return all fields
558 * ibuf and ibuflen are unused (use NULL, 0) 533 * ibuf and ibuflen are unused (use NULL, 0)
559 * else return specific fields 534 * else return specific fields
560 * ibuf contains fieldindexes 535 * ibuf contains fieldindexes
561 * 536 *
562 * if oper == I2O_PARAMS_LIST_GET, get from specific rows 537 * if oper == I2O_PARAMS_LIST_GET, get from specific rows
563 * if fieldcount == -1 return all fields 538 * if fieldcount == -1 return all fields
@@ -602,35 +577,6 @@ int i2o_parm_table_get(struct i2o_device *dev, int oper, int group,
602 return size; 577 return size;
603} 578}
604 579
605/**
606 * i2o_device_init - Initialize I2O devices
607 *
608 * Registers the I2O device class.
609 *
610 * Returns 0 on success or negative error code on failure.
611 */
612int i2o_device_init(void)
613{
614 int rc;
615
616 rc = class_register(&i2o_device_class);
617 if (rc)
618 return rc;
619
620 return class_interface_register(&i2o_device_class_interface);
621};
622
623/**
624 * i2o_device_exit - I2O devices exit function
625 *
626 * Unregisters the I2O device class.
627 */
628void i2o_device_exit(void)
629{
630 class_interface_register(&i2o_device_class_interface);
631 class_unregister(&i2o_device_class);
632};
633
634EXPORT_SYMBOL(i2o_device_claim); 580EXPORT_SYMBOL(i2o_device_claim);
635EXPORT_SYMBOL(i2o_device_claim_release); 581EXPORT_SYMBOL(i2o_device_claim_release);
636EXPORT_SYMBOL(i2o_parm_field_get); 582EXPORT_SYMBOL(i2o_parm_field_get);
diff --git a/drivers/message/i2o/driver.c b/drivers/message/i2o/driver.c
index 739bfdef0c6d..0fb9c4e2ad4c 100644
--- a/drivers/message/i2o/driver.c
+++ b/drivers/message/i2o/driver.c
@@ -17,6 +17,9 @@
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/rwsem.h> 18#include <linux/rwsem.h>
19#include <linux/i2o.h> 19#include <linux/i2o.h>
20#include <linux/workqueue.h>
21#include <linux/string.h>
22#include <linux/slab.h>
20#include "core.h" 23#include "core.h"
21 24
22#define OSM_NAME "i2o" 25#define OSM_NAME "i2o"
@@ -58,9 +61,12 @@ static int i2o_bus_match(struct device *dev, struct device_driver *drv)
58}; 61};
59 62
60/* I2O bus type */ 63/* I2O bus type */
64extern struct device_attribute i2o_device_attrs[];
65
61struct bus_type i2o_bus_type = { 66struct bus_type i2o_bus_type = {
62 .name = "i2o", 67 .name = "i2o",
63 .match = i2o_bus_match, 68 .match = i2o_bus_match,
69 .dev_attrs = i2o_device_attrs,
64}; 70};
65 71
66/** 72/**
diff --git a/drivers/message/i2o/exec-osm.c b/drivers/message/i2o/exec-osm.c
index bda2c62648ba..b675b4ebbebd 100644
--- a/drivers/message/i2o/exec-osm.c
+++ b/drivers/message/i2o/exec-osm.c
@@ -30,6 +30,10 @@
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/i2o.h> 31#include <linux/i2o.h>
32#include <linux/delay.h> 32#include <linux/delay.h>
33#include <linux/workqueue.h>
34#include <linux/string.h>
35#include <linux/slab.h>
36#include <asm/param.h> /* HZ */
33#include "core.h" 37#include "core.h"
34 38
35#define OSM_NAME "exec-osm" 39#define OSM_NAME "exec-osm"
diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
index 42f8b810d6e5..61b837de4b6a 100644
--- a/drivers/message/i2o/iop.c
+++ b/drivers/message/i2o/iop.c
@@ -28,6 +28,7 @@
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/i2o.h> 29#include <linux/i2o.h>
30#include <linux/delay.h> 30#include <linux/delay.h>
31#include <linux/sched.h>
31#include "core.h" 32#include "core.h"
32 33
33#define OSM_NAME "i2o" 34#define OSM_NAME "i2o"
@@ -833,6 +834,7 @@ void i2o_iop_remove(struct i2o_controller *c)
833 list_for_each_entry_safe(dev, tmp, &c->devices, list) 834 list_for_each_entry_safe(dev, tmp, &c->devices, list)
834 i2o_device_remove(dev); 835 i2o_device_remove(dev);
835 836
837 class_device_unregister(c->classdev);
836 device_del(&c->device); 838 device_del(&c->device);
837 839
838 /* Ask the IOP to switch to RESET state */ 840 /* Ask the IOP to switch to RESET state */
@@ -1077,9 +1079,7 @@ static void i2o_iop_release(struct device *dev)
1077}; 1079};
1078 1080
1079/* I2O controller class */ 1081/* I2O controller class */
1080static struct class i2o_controller_class = { 1082static struct class *i2o_controller_class;
1081 .name = "i2o_controller",
1082};
1083 1083
1084/** 1084/**
1085 * i2o_iop_alloc - Allocate and initialize a i2o_controller struct 1085 * i2o_iop_alloc - Allocate and initialize a i2o_controller struct
@@ -1110,14 +1110,10 @@ struct i2o_controller *i2o_iop_alloc(void)
1110 sprintf(c->name, "iop%d", c->unit); 1110 sprintf(c->name, "iop%d", c->unit);
1111 1111
1112 device_initialize(&c->device); 1112 device_initialize(&c->device);
1113 class_device_initialize(&c->classdev);
1114 1113
1115 c->device.release = &i2o_iop_release; 1114 c->device.release = &i2o_iop_release;
1116 c->classdev.class = &i2o_controller_class;
1117 c->classdev.dev = &c->device;
1118 1115
1119 snprintf(c->device.bus_id, BUS_ID_SIZE, "iop%d", c->unit); 1116 snprintf(c->device.bus_id, BUS_ID_SIZE, "iop%d", c->unit);
1120 snprintf(c->classdev.class_id, BUS_ID_SIZE, "iop%d", c->unit);
1121 1117
1122#if BITS_PER_LONG == 64 1118#if BITS_PER_LONG == 64
1123 spin_lock_init(&c->context_list_lock); 1119 spin_lock_init(&c->context_list_lock);
@@ -1146,7 +1142,9 @@ int i2o_iop_add(struct i2o_controller *c)
1146 goto iop_reset; 1142 goto iop_reset;
1147 } 1143 }
1148 1144
1149 if ((rc = class_device_add(&c->classdev))) { 1145 c->classdev = class_device_create(i2o_controller_class, NULL, MKDEV(0,0),
1146 &c->device, "iop%d", c->unit);
1147 if (IS_ERR(c->classdev)) {
1150 osm_err("%s: could not add controller class\n", c->name); 1148 osm_err("%s: could not add controller class\n", c->name);
1151 goto device_del; 1149 goto device_del;
1152 } 1150 }
@@ -1184,7 +1182,7 @@ int i2o_iop_add(struct i2o_controller *c)
1184 return 0; 1182 return 0;
1185 1183
1186 class_del: 1184 class_del:
1187 class_device_del(&c->classdev); 1185 class_device_unregister(c->classdev);
1188 1186
1189 device_del: 1187 device_del:
1190 device_del(&c->device); 1188 device_del(&c->device);
@@ -1246,13 +1244,10 @@ static int __init i2o_iop_init(void)
1246 1244
1247 printk(KERN_INFO OSM_DESCRIPTION " v" OSM_VERSION "\n"); 1245 printk(KERN_INFO OSM_DESCRIPTION " v" OSM_VERSION "\n");
1248 1246
1249 rc = i2o_device_init(); 1247 i2o_controller_class = class_create(THIS_MODULE, "i2o_controller");
1250 if (rc) 1248 if (IS_ERR(i2o_controller_class)) {
1251 goto exit;
1252
1253 if ((rc = class_register(&i2o_controller_class))) {
1254 osm_err("can't register class i2o_controller\n"); 1249 osm_err("can't register class i2o_controller\n");
1255 goto device_exit; 1250 goto exit;
1256 } 1251 }
1257 1252
1258 if ((rc = i2o_driver_init())) 1253 if ((rc = i2o_driver_init()))
@@ -1273,10 +1268,7 @@ static int __init i2o_iop_init(void)
1273 i2o_driver_exit(); 1268 i2o_driver_exit();
1274 1269
1275 class_exit: 1270 class_exit:
1276 class_unregister(&i2o_controller_class); 1271 class_destroy(i2o_controller_class);
1277
1278 device_exit:
1279 i2o_device_exit();
1280 1272
1281 exit: 1273 exit:
1282 return rc; 1274 return rc;
@@ -1292,8 +1284,7 @@ static void __exit i2o_iop_exit(void)
1292 i2o_pci_exit(); 1284 i2o_pci_exit();
1293 i2o_exec_exit(); 1285 i2o_exec_exit();
1294 i2o_driver_exit(); 1286 i2o_driver_exit();
1295 class_unregister(&i2o_controller_class); 1287 class_destroy(i2o_controller_class);
1296 i2o_device_exit();
1297}; 1288};
1298 1289
1299module_init(i2o_iop_init); 1290module_init(i2o_iop_init);
diff --git a/drivers/mfd/mcp-sa11x0.c b/drivers/mfd/mcp-sa11x0.c
index e9806fbbe696..720e7a326308 100644
--- a/drivers/mfd/mcp-sa11x0.c
+++ b/drivers/mfd/mcp-sa11x0.c
@@ -219,26 +219,24 @@ static int mcp_sa11x0_remove(struct device *dev)
219 return 0; 219 return 0;
220} 220}
221 221
222static int mcp_sa11x0_suspend(struct device *dev, pm_message_t state, u32 level) 222static int mcp_sa11x0_suspend(struct device *dev, pm_message_t state)
223{ 223{
224 struct mcp *mcp = dev_get_drvdata(dev); 224 struct mcp *mcp = dev_get_drvdata(dev);
225 225
226 if (level == SUSPEND_DISABLE) { 226 priv(mcp)->mccr0 = Ser4MCCR0;
227 priv(mcp)->mccr0 = Ser4MCCR0; 227 priv(mcp)->mccr1 = Ser4MCCR1;
228 priv(mcp)->mccr1 = Ser4MCCR1; 228 Ser4MCCR0 &= ~MCCR0_MCE;
229 Ser4MCCR0 &= ~MCCR0_MCE; 229
230 }
231 return 0; 230 return 0;
232} 231}
233 232
234static int mcp_sa11x0_resume(struct device *dev, u32 level) 233static int mcp_sa11x0_resume(struct device *dev)
235{ 234{
236 struct mcp *mcp = dev_get_drvdata(dev); 235 struct mcp *mcp = dev_get_drvdata(dev);
237 236
238 if (level == RESUME_RESTORE_STATE) { 237 Ser4MCCR1 = priv(mcp)->mccr1;
239 Ser4MCCR1 = priv(mcp)->mccr1; 238 Ser4MCCR0 = priv(mcp)->mccr0;
240 Ser4MCCR0 = priv(mcp)->mccr0; 239
241 }
242 return 0; 240 return 0;
243} 241}
244 242
diff --git a/drivers/mfd/ucb1x00-ts.c b/drivers/mfd/ucb1x00-ts.c
index a260f83bcb02..a984c0efabf0 100644
--- a/drivers/mfd/ucb1x00-ts.c
+++ b/drivers/mfd/ucb1x00-ts.c
@@ -32,15 +32,18 @@
32#include <linux/suspend.h> 32#include <linux/suspend.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/kthread.h> 34#include <linux/kthread.h>
35#include <linux/delay.h>
35 36
36#include <asm/dma.h> 37#include <asm/dma.h>
37#include <asm/semaphore.h> 38#include <asm/semaphore.h>
39#include <asm/arch/collie.h>
40#include <asm/mach-types.h>
38 41
39#include "ucb1x00.h" 42#include "ucb1x00.h"
40 43
41 44
42struct ucb1x00_ts { 45struct ucb1x00_ts {
43 struct input_dev idev; 46 struct input_dev *idev;
44 struct ucb1x00 *ucb; 47 struct ucb1x00 *ucb;
45 48
46 wait_queue_head_t irq_wait; 49 wait_queue_head_t irq_wait;
@@ -56,16 +59,16 @@ static int adcsync;
56 59
57static inline void ucb1x00_ts_evt_add(struct ucb1x00_ts *ts, u16 pressure, u16 x, u16 y) 60static inline void ucb1x00_ts_evt_add(struct ucb1x00_ts *ts, u16 pressure, u16 x, u16 y)
58{ 61{
59 input_report_abs(&ts->idev, ABS_X, x); 62 input_report_abs(ts->idev, ABS_X, x);
60 input_report_abs(&ts->idev, ABS_Y, y); 63 input_report_abs(ts->idev, ABS_Y, y);
61 input_report_abs(&ts->idev, ABS_PRESSURE, pressure); 64 input_report_abs(ts->idev, ABS_PRESSURE, pressure);
62 input_sync(&ts->idev); 65 input_sync(ts->idev);
63} 66}
64 67
65static inline void ucb1x00_ts_event_release(struct ucb1x00_ts *ts) 68static inline void ucb1x00_ts_event_release(struct ucb1x00_ts *ts)
66{ 69{
67 input_report_abs(&ts->idev, ABS_PRESSURE, 0); 70 input_report_abs(ts->idev, ABS_PRESSURE, 0);
68 input_sync(&ts->idev); 71 input_sync(ts->idev);
69} 72}
70 73
71/* 74/*
@@ -85,12 +88,23 @@ static inline void ucb1x00_ts_mode_int(struct ucb1x00_ts *ts)
85 */ 88 */
86static inline unsigned int ucb1x00_ts_read_pressure(struct ucb1x00_ts *ts) 89static inline unsigned int ucb1x00_ts_read_pressure(struct ucb1x00_ts *ts)
87{ 90{
88 ucb1x00_reg_write(ts->ucb, UCB_TS_CR, 91 if (machine_is_collie()) {
89 UCB_TS_CR_TSMX_POW | UCB_TS_CR_TSPX_POW | 92 ucb1x00_io_write(ts->ucb, COLLIE_TC35143_GPIO_TBL_CHK, 0);
90 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_GND | 93 ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
91 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA); 94 UCB_TS_CR_TSPX_POW | UCB_TS_CR_TSMX_POW |
95 UCB_TS_CR_MODE_POS | UCB_TS_CR_BIAS_ENA);
92 96
93 return ucb1x00_adc_read(ts->ucb, UCB_ADC_INP_TSPY, ts->adcsync); 97 udelay(55);
98
99 return ucb1x00_adc_read(ts->ucb, UCB_ADC_INP_AD2, ts->adcsync);
100 } else {
101 ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
102 UCB_TS_CR_TSMX_POW | UCB_TS_CR_TSPX_POW |
103 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_GND |
104 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
105
106 return ucb1x00_adc_read(ts->ucb, UCB_ADC_INP_TSPY, ts->adcsync);
107 }
94} 108}
95 109
96/* 110/*
@@ -101,12 +115,16 @@ static inline unsigned int ucb1x00_ts_read_pressure(struct ucb1x00_ts *ts)
101 */ 115 */
102static inline unsigned int ucb1x00_ts_read_xpos(struct ucb1x00_ts *ts) 116static inline unsigned int ucb1x00_ts_read_xpos(struct ucb1x00_ts *ts)
103{ 117{
104 ucb1x00_reg_write(ts->ucb, UCB_TS_CR, 118 if (machine_is_collie())
105 UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW | 119 ucb1x00_io_write(ts->ucb, 0, COLLIE_TC35143_GPIO_TBL_CHK);
106 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA); 120 else {
107 ucb1x00_reg_write(ts->ucb, UCB_TS_CR, 121 ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
108 UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW | 122 UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW |
109 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA); 123 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
124 ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
125 UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW |
126 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
127 }
110 ucb1x00_reg_write(ts->ucb, UCB_TS_CR, 128 ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
111 UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW | 129 UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW |
112 UCB_TS_CR_MODE_POS | UCB_TS_CR_BIAS_ENA); 130 UCB_TS_CR_MODE_POS | UCB_TS_CR_BIAS_ENA);
@@ -124,12 +142,17 @@ static inline unsigned int ucb1x00_ts_read_xpos(struct ucb1x00_ts *ts)
124 */ 142 */
125static inline unsigned int ucb1x00_ts_read_ypos(struct ucb1x00_ts *ts) 143static inline unsigned int ucb1x00_ts_read_ypos(struct ucb1x00_ts *ts)
126{ 144{
127 ucb1x00_reg_write(ts->ucb, UCB_TS_CR, 145 if (machine_is_collie())
128 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW | 146 ucb1x00_io_write(ts->ucb, 0, COLLIE_TC35143_GPIO_TBL_CHK);
129 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA); 147 else {
130 ucb1x00_reg_write(ts->ucb, UCB_TS_CR, 148 ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
131 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW | 149 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW |
132 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA); 150 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
151 ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
152 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW |
153 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
154 }
155
133 ucb1x00_reg_write(ts->ucb, UCB_TS_CR, 156 ucb1x00_reg_write(ts->ucb, UCB_TS_CR,
134 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW | 157 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW |
135 UCB_TS_CR_MODE_POS | UCB_TS_CR_BIAS_ENA); 158 UCB_TS_CR_MODE_POS | UCB_TS_CR_BIAS_ENA);
@@ -163,6 +186,15 @@ static inline unsigned int ucb1x00_ts_read_yres(struct ucb1x00_ts *ts)
163 return ucb1x00_adc_read(ts->ucb, 0, ts->adcsync); 186 return ucb1x00_adc_read(ts->ucb, 0, ts->adcsync);
164} 187}
165 188
189static inline int ucb1x00_ts_pen_down(struct ucb1x00_ts *ts)
190{
191 unsigned int val = ucb1x00_reg_read(ts->ucb, UCB_TS_CR);
192 if (machine_is_collie())
193 return (!(val & (UCB_TS_CR_TSPX_LOW)));
194 else
195 return (val & (UCB_TS_CR_TSPX_LOW | UCB_TS_CR_TSMX_LOW));
196}
197
166/* 198/*
167 * This is a RT kernel thread that handles the ADC accesses 199 * This is a RT kernel thread that handles the ADC accesses
168 * (mainly so we can use semaphores in the UCB1200 core code 200 * (mainly so we can use semaphores in the UCB1200 core code
@@ -186,7 +218,7 @@ static int ucb1x00_thread(void *_ts)
186 218
187 add_wait_queue(&ts->irq_wait, &wait); 219 add_wait_queue(&ts->irq_wait, &wait);
188 while (!kthread_should_stop()) { 220 while (!kthread_should_stop()) {
189 unsigned int x, y, p, val; 221 unsigned int x, y, p;
190 signed long timeout; 222 signed long timeout;
191 223
192 ts->restart = 0; 224 ts->restart = 0;
@@ -206,12 +238,12 @@ static int ucb1x00_thread(void *_ts)
206 msleep(10); 238 msleep(10);
207 239
208 ucb1x00_enable(ts->ucb); 240 ucb1x00_enable(ts->ucb);
209 val = ucb1x00_reg_read(ts->ucb, UCB_TS_CR);
210 241
211 if (val & (UCB_TS_CR_TSPX_LOW | UCB_TS_CR_TSMX_LOW)) { 242
243 if (ucb1x00_ts_pen_down(ts)) {
212 set_task_state(tsk, TASK_INTERRUPTIBLE); 244 set_task_state(tsk, TASK_INTERRUPTIBLE);
213 245
214 ucb1x00_enable_irq(ts->ucb, UCB_IRQ_TSPX, UCB_FALLING); 246 ucb1x00_enable_irq(ts->ucb, UCB_IRQ_TSPX, machine_is_collie() ? UCB_RISING : UCB_FALLING);
215 ucb1x00_disable(ts->ucb); 247 ucb1x00_disable(ts->ucb);
216 248
217 /* 249 /*
@@ -341,26 +373,30 @@ static int ucb1x00_ts_add(struct ucb1x00_dev *dev)
341{ 373{
342 struct ucb1x00_ts *ts; 374 struct ucb1x00_ts *ts;
343 375
344 ts = kmalloc(sizeof(struct ucb1x00_ts), GFP_KERNEL); 376 ts = kzalloc(sizeof(struct ucb1x00_ts), GFP_KERNEL);
345 if (!ts) 377 if (!ts)
346 return -ENOMEM; 378 return -ENOMEM;
347 379
348 memset(ts, 0, sizeof(struct ucb1x00_ts)); 380 ts->idev = input_allocate_device();
381 if (!ts->idev) {
382 kfree(ts);
383 return -ENOMEM;
384 }
349 385
350 ts->ucb = dev->ucb; 386 ts->ucb = dev->ucb;
351 ts->adcsync = adcsync ? UCB_SYNC : UCB_NOSYNC; 387 ts->adcsync = adcsync ? UCB_SYNC : UCB_NOSYNC;
352 388
353 ts->idev.name = "Touchscreen panel"; 389 ts->idev->name = "Touchscreen panel";
354 ts->idev.id.product = ts->ucb->id; 390 ts->idev->id.product = ts->ucb->id;
355 ts->idev.open = ucb1x00_ts_open; 391 ts->idev->open = ucb1x00_ts_open;
356 ts->idev.close = ucb1x00_ts_close; 392 ts->idev->close = ucb1x00_ts_close;
357 393
358 __set_bit(EV_ABS, ts->idev.evbit); 394 __set_bit(EV_ABS, ts->idev->evbit);
359 __set_bit(ABS_X, ts->idev.absbit); 395 __set_bit(ABS_X, ts->idev->absbit);
360 __set_bit(ABS_Y, ts->idev.absbit); 396 __set_bit(ABS_Y, ts->idev->absbit);
361 __set_bit(ABS_PRESSURE, ts->idev.absbit); 397 __set_bit(ABS_PRESSURE, ts->idev->absbit);
362 398
363 input_register_device(&ts->idev); 399 input_register_device(ts->idev);
364 400
365 dev->priv = ts; 401 dev->priv = ts;
366 402
@@ -370,7 +406,8 @@ static int ucb1x00_ts_add(struct ucb1x00_dev *dev)
370static void ucb1x00_ts_remove(struct ucb1x00_dev *dev) 406static void ucb1x00_ts_remove(struct ucb1x00_dev *dev)
371{ 407{
372 struct ucb1x00_ts *ts = dev->priv; 408 struct ucb1x00_ts *ts = dev->priv;
373 input_unregister_device(&ts->idev); 409
410 input_unregister_device(ts->idev);
374 kfree(ts); 411 kfree(ts);
375} 412}
376 413
diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
index 4991bbd054f3..c483a863b116 100644
--- a/drivers/mmc/Kconfig
+++ b/drivers/mmc/Kconfig
@@ -60,4 +60,13 @@ config MMC_WBSD
60 60
61 If unsure, say N. 61 If unsure, say N.
62 62
63config MMC_AU1X
64 tristate "Alchemy AU1XX0 MMC Card Interface support"
65 depends on SOC_AU1X00 && MMC
66 help
67 This selects the AMD Alchemy(R) Multimedia card interface.
68 iIf you have a Alchemy platform with a MMC slot, say Y or M here.
69
70 If unsure, say N.
71
63endmenu 72endmenu
diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
index 89510c2086c7..e351e71146e9 100644
--- a/drivers/mmc/Makefile
+++ b/drivers/mmc/Makefile
@@ -18,5 +18,6 @@ obj-$(CONFIG_MMC_BLOCK) += mmc_block.o
18obj-$(CONFIG_MMC_ARMMMCI) += mmci.o 18obj-$(CONFIG_MMC_ARMMMCI) += mmci.o
19obj-$(CONFIG_MMC_PXA) += pxamci.o 19obj-$(CONFIG_MMC_PXA) += pxamci.o
20obj-$(CONFIG_MMC_WBSD) += wbsd.o 20obj-$(CONFIG_MMC_WBSD) += wbsd.o
21obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
21 22
22mmc_core-y := mmc.o mmc_queue.o mmc_sysfs.o 23mmc_core-y := mmc.o mmc_queue.o mmc_sysfs.o
diff --git a/drivers/mmc/au1xmmc.c b/drivers/mmc/au1xmmc.c
new file mode 100644
index 000000000000..aaf04638054e
--- /dev/null
+++ b/drivers/mmc/au1xmmc.c
@@ -0,0 +1,1026 @@
1/*
2 * linux/drivers/mmc/au1xmmc.c - AU1XX0 MMC driver
3 *
4 * Copyright (c) 2005, Advanced Micro Devices, Inc.
5 *
6 * Developed with help from the 2.4.30 MMC AU1XXX controller including
7 * the following copyright notices:
8 * Copyright (c) 2003-2004 Embedded Edge, LLC.
9 * Portions Copyright (C) 2002 Embedix, Inc
10 * Copyright 2002 Hewlett-Packard Company
11
12 * 2.6 version of this driver inspired by:
13 * (drivers/mmc/wbsd.c) Copyright (C) 2004-2005 Pierre Ossman,
14 * All Rights Reserved.
15 * (drivers/mmc/pxa.c) Copyright (C) 2003 Russell King,
16 * All Rights Reserved.
17 *
18
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License version 2 as
21 * published by the Free Software Foundation.
22 */
23
24/* Why is a timer used to detect insert events?
25 *
26 * From the AU1100 MMC application guide:
27 * If the Au1100-based design is intended to support both MultiMediaCards
28 * and 1- or 4-data bit SecureDigital cards, then the solution is to
29 * connect a weak (560KOhm) pull-up resistor to connector pin 1.
30 * In doing so, a MMC card never enters SPI-mode communications,
31 * but now the SecureDigital card-detect feature of CD/DAT3 is ineffective
32 * (the low to high transition will not occur).
33 *
34 * So we use the timer to check the status manually.
35 */
36
37#include <linux/config.h>
38#include <linux/module.h>
39#include <linux/init.h>
40#include <linux/device.h>
41#include <linux/mm.h>
42#include <linux/interrupt.h>
43#include <linux/dma-mapping.h>
44
45#include <linux/mmc/host.h>
46#include <linux/mmc/protocol.h>
47#include <asm/io.h>
48#include <asm/mach-au1x00/au1000.h>
49#include <asm/mach-au1x00/au1xxx_dbdma.h>
50#include <asm/mach-au1x00/au1100_mmc.h>
51#include <asm/scatterlist.h>
52
53#include <au1xxx.h>
54#include "au1xmmc.h"
55
56#define DRIVER_NAME "au1xxx-mmc"
57
58/* Set this to enable special debugging macros */
59/* #define MMC_DEBUG */
60
61#ifdef MMC_DEBUG
62#define DEBUG(fmt, idx, args...) printk("au1xx(%d): DEBUG: " fmt, idx, ##args)
63#else
64#define DEBUG(fmt, idx, args...)
65#endif
66
67const struct {
68 u32 iobase;
69 u32 tx_devid, rx_devid;
70 u16 bcsrpwr;
71 u16 bcsrstatus;
72 u16 wpstatus;
73} au1xmmc_card_table[] = {
74 { SD0_BASE, DSCR_CMD0_SDMS_TX0, DSCR_CMD0_SDMS_RX0,
75 BCSR_BOARD_SD0PWR, BCSR_INT_SD0INSERT, BCSR_STATUS_SD0WP },
76#ifndef CONFIG_MIPS_DB1200
77 { SD1_BASE, DSCR_CMD0_SDMS_TX1, DSCR_CMD0_SDMS_RX1,
78 BCSR_BOARD_DS1PWR, BCSR_INT_SD1INSERT, BCSR_STATUS_SD1WP }
79#endif
80};
81
82#define AU1XMMC_CONTROLLER_COUNT \
83 (sizeof(au1xmmc_card_table) / sizeof(au1xmmc_card_table[0]))
84
85/* This array stores pointers for the hosts (used by the IRQ handler) */
86struct au1xmmc_host *au1xmmc_hosts[AU1XMMC_CONTROLLER_COUNT];
87static int dma = 1;
88
89#ifdef MODULE
90MODULE_PARM(dma, "i");
91MODULE_PARM_DESC(dma, "Use DMA engine for data transfers (0 = disabled)");
92#endif
93
94static inline void IRQ_ON(struct au1xmmc_host *host, u32 mask)
95{
96 u32 val = au_readl(HOST_CONFIG(host));
97 val |= mask;
98 au_writel(val, HOST_CONFIG(host));
99 au_sync();
100}
101
102static inline void FLUSH_FIFO(struct au1xmmc_host *host)
103{
104 u32 val = au_readl(HOST_CONFIG2(host));
105
106 au_writel(val | SD_CONFIG2_FF, HOST_CONFIG2(host));
107 au_sync_delay(1);
108
109 /* SEND_STOP will turn off clock control - this re-enables it */
110 val &= ~SD_CONFIG2_DF;
111
112 au_writel(val, HOST_CONFIG2(host));
113 au_sync();
114}
115
116static inline void IRQ_OFF(struct au1xmmc_host *host, u32 mask)
117{
118 u32 val = au_readl(HOST_CONFIG(host));
119 val &= ~mask;
120 au_writel(val, HOST_CONFIG(host));
121 au_sync();
122}
123
124static inline void SEND_STOP(struct au1xmmc_host *host)
125{
126
127 /* We know the value of CONFIG2, so avoid a read we don't need */
128 u32 mask = SD_CONFIG2_EN;
129
130 WARN_ON(host->status != HOST_S_DATA);
131 host->status = HOST_S_STOP;
132
133 au_writel(mask | SD_CONFIG2_DF, HOST_CONFIG2(host));
134 au_sync();
135
136 /* Send the stop commmand */
137 au_writel(STOP_CMD, HOST_CMD(host));
138}
139
140static void au1xmmc_set_power(struct au1xmmc_host *host, int state)
141{
142
143 u32 val = au1xmmc_card_table[host->id].bcsrpwr;
144
145 bcsr->board &= ~val;
146 if (state) bcsr->board |= val;
147
148 au_sync_delay(1);
149}
150
151static inline int au1xmmc_card_inserted(struct au1xmmc_host *host)
152{
153 return (bcsr->sig_status & au1xmmc_card_table[host->id].bcsrstatus)
154 ? 1 : 0;
155}
156
157static inline int au1xmmc_card_readonly(struct au1xmmc_host *host)
158{
159 return (bcsr->status & au1xmmc_card_table[host->id].wpstatus)
160 ? 1 : 0;
161}
162
163static void au1xmmc_finish_request(struct au1xmmc_host *host)
164{
165
166 struct mmc_request *mrq = host->mrq;
167
168 host->mrq = NULL;
169 host->flags &= HOST_F_ACTIVE;
170
171 host->dma.len = 0;
172 host->dma.dir = 0;
173
174 host->pio.index = 0;
175 host->pio.offset = 0;
176 host->pio.len = 0;
177
178 host->status = HOST_S_IDLE;
179
180 bcsr->disk_leds |= (1 << 8);
181
182 mmc_request_done(host->mmc, mrq);
183}
184
185static void au1xmmc_tasklet_finish(unsigned long param)
186{
187 struct au1xmmc_host *host = (struct au1xmmc_host *) param;
188 au1xmmc_finish_request(host);
189}
190
191static int au1xmmc_send_command(struct au1xmmc_host *host, int wait,
192 struct mmc_command *cmd)
193{
194
195 u32 mmccmd = (cmd->opcode << SD_CMD_CI_SHIFT);
196
197 switch(cmd->flags) {
198 case MMC_RSP_R1:
199 mmccmd |= SD_CMD_RT_1;
200 break;
201 case MMC_RSP_R1B:
202 mmccmd |= SD_CMD_RT_1B;
203 break;
204 case MMC_RSP_R2:
205 mmccmd |= SD_CMD_RT_2;
206 break;
207 case MMC_RSP_R3:
208 mmccmd |= SD_CMD_RT_3;
209 break;
210 }
211
212 switch(cmd->opcode) {
213 case MMC_READ_SINGLE_BLOCK:
214 case SD_APP_SEND_SCR:
215 mmccmd |= SD_CMD_CT_2;
216 break;
217 case MMC_READ_MULTIPLE_BLOCK:
218 mmccmd |= SD_CMD_CT_4;
219 break;
220 case MMC_WRITE_BLOCK:
221 mmccmd |= SD_CMD_CT_1;
222 break;
223
224 case MMC_WRITE_MULTIPLE_BLOCK:
225 mmccmd |= SD_CMD_CT_3;
226 break;
227 case MMC_STOP_TRANSMISSION:
228 mmccmd |= SD_CMD_CT_7;
229 break;
230 }
231
232 au_writel(cmd->arg, HOST_CMDARG(host));
233 au_sync();
234
235 if (wait)
236 IRQ_OFF(host, SD_CONFIG_CR);
237
238 au_writel((mmccmd | SD_CMD_GO), HOST_CMD(host));
239 au_sync();
240
241 /* Wait for the command to go on the line */
242
243 while(1) {
244 if (!(au_readl(HOST_CMD(host)) & SD_CMD_GO))
245 break;
246 }
247
248 /* Wait for the command to come back */
249
250 if (wait) {
251 u32 status = au_readl(HOST_STATUS(host));
252
253 while(!(status & SD_STATUS_CR))
254 status = au_readl(HOST_STATUS(host));
255
256 /* Clear the CR status */
257 au_writel(SD_STATUS_CR, HOST_STATUS(host));
258
259 IRQ_ON(host, SD_CONFIG_CR);
260 }
261
262 return MMC_ERR_NONE;
263}
264
265static void au1xmmc_data_complete(struct au1xmmc_host *host, u32 status)
266{
267
268 struct mmc_request *mrq = host->mrq;
269 struct mmc_data *data;
270 u32 crc;
271
272 WARN_ON(host->status != HOST_S_DATA && host->status != HOST_S_STOP);
273
274 if (host->mrq == NULL)
275 return;
276
277 data = mrq->cmd->data;
278
279 if (status == 0)
280 status = au_readl(HOST_STATUS(host));
281
282 /* The transaction is really over when the SD_STATUS_DB bit is clear */
283
284 while((host->flags & HOST_F_XMIT) && (status & SD_STATUS_DB))
285 status = au_readl(HOST_STATUS(host));
286
287 data->error = MMC_ERR_NONE;
288 dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, host->dma.dir);
289
290 /* Process any errors */
291
292 crc = (status & (SD_STATUS_WC | SD_STATUS_RC));
293 if (host->flags & HOST_F_XMIT)
294 crc |= ((status & 0x07) == 0x02) ? 0 : 1;
295
296 if (crc)
297 data->error = MMC_ERR_BADCRC;
298
299 /* Clear the CRC bits */
300 au_writel(SD_STATUS_WC | SD_STATUS_RC, HOST_STATUS(host));
301
302 data->bytes_xfered = 0;
303
304 if (data->error == MMC_ERR_NONE) {
305 if (host->flags & HOST_F_DMA) {
306 u32 chan = DMA_CHANNEL(host);
307
308 chan_tab_t *c = *((chan_tab_t **) chan);
309 au1x_dma_chan_t *cp = c->chan_ptr;
310 data->bytes_xfered = cp->ddma_bytecnt;
311 }
312 else
313 data->bytes_xfered =
314 (data->blocks * (1 << data->blksz_bits)) -
315 host->pio.len;
316 }
317
318 au1xmmc_finish_request(host);
319}
320
321static void au1xmmc_tasklet_data(unsigned long param)
322{
323 struct au1xmmc_host *host = (struct au1xmmc_host *) param;
324
325 u32 status = au_readl(HOST_STATUS(host));
326 au1xmmc_data_complete(host, status);
327}
328
329#define AU1XMMC_MAX_TRANSFER 8
330
331static void au1xmmc_send_pio(struct au1xmmc_host *host)
332{
333
334 struct mmc_data *data = 0;
335 int sg_len, max, count = 0;
336 unsigned char *sg_ptr;
337 u32 status = 0;
338 struct scatterlist *sg;
339
340 data = host->mrq->data;
341
342 if (!(host->flags & HOST_F_XMIT))
343 return;
344
345 /* This is the pointer to the data buffer */
346 sg = &data->sg[host->pio.index];
347 sg_ptr = page_address(sg->page) + sg->offset + host->pio.offset;
348
349 /* This is the space left inside the buffer */
350 sg_len = data->sg[host->pio.index].length - host->pio.offset;
351
352 /* Check to if we need less then the size of the sg_buffer */
353
354 max = (sg_len > host->pio.len) ? host->pio.len : sg_len;
355 if (max > AU1XMMC_MAX_TRANSFER) max = AU1XMMC_MAX_TRANSFER;
356
357 for(count = 0; count < max; count++ ) {
358 unsigned char val;
359
360 status = au_readl(HOST_STATUS(host));
361
362 if (!(status & SD_STATUS_TH))
363 break;
364
365 val = *sg_ptr++;
366
367 au_writel((unsigned long) val, HOST_TXPORT(host));
368 au_sync();
369 }
370
371 host->pio.len -= count;
372 host->pio.offset += count;
373
374 if (count == sg_len) {
375 host->pio.index++;
376 host->pio.offset = 0;
377 }
378
379 if (host->pio.len == 0) {
380 IRQ_OFF(host, SD_CONFIG_TH);
381
382 if (host->flags & HOST_F_STOP)
383 SEND_STOP(host);
384
385 tasklet_schedule(&host->data_task);
386 }
387}
388
389static void au1xmmc_receive_pio(struct au1xmmc_host *host)
390{
391
392 struct mmc_data *data = 0;
393 int sg_len = 0, max = 0, count = 0;
394 unsigned char *sg_ptr = 0;
395 u32 status = 0;
396 struct scatterlist *sg;
397
398 data = host->mrq->data;
399
400 if (!(host->flags & HOST_F_RECV))
401 return;
402
403 max = host->pio.len;
404
405 if (host->pio.index < host->dma.len) {
406 sg = &data->sg[host->pio.index];
407 sg_ptr = page_address(sg->page) + sg->offset + host->pio.offset;
408
409 /* This is the space left inside the buffer */
410 sg_len = sg_dma_len(&data->sg[host->pio.index]) - host->pio.offset;
411
412 /* Check to if we need less then the size of the sg_buffer */
413 if (sg_len < max) max = sg_len;
414 }
415
416 if (max > AU1XMMC_MAX_TRANSFER)
417 max = AU1XMMC_MAX_TRANSFER;
418
419 for(count = 0; count < max; count++ ) {
420 u32 val;
421 status = au_readl(HOST_STATUS(host));
422
423 if (!(status & SD_STATUS_NE))
424 break;
425
426 if (status & SD_STATUS_RC) {
427 DEBUG("RX CRC Error [%d + %d].\n", host->id,
428 host->pio.len, count);
429 break;
430 }
431
432 if (status & SD_STATUS_RO) {
433 DEBUG("RX Overrun [%d + %d]\n", host->id,
434 host->pio.len, count);
435 break;
436 }
437 else if (status & SD_STATUS_RU) {
438 DEBUG("RX Underrun [%d + %d]\n", host->id,
439 host->pio.len, count);
440 break;
441 }
442
443 val = au_readl(HOST_RXPORT(host));
444
445 if (sg_ptr)
446 *sg_ptr++ = (unsigned char) (val & 0xFF);
447 }
448
449 host->pio.len -= count;
450 host->pio.offset += count;
451
452 if (sg_len && count == sg_len) {
453 host->pio.index++;
454 host->pio.offset = 0;
455 }
456
457 if (host->pio.len == 0) {
458 //IRQ_OFF(host, SD_CONFIG_RA | SD_CONFIG_RF);
459 IRQ_OFF(host, SD_CONFIG_NE);
460
461 if (host->flags & HOST_F_STOP)
462 SEND_STOP(host);
463
464 tasklet_schedule(&host->data_task);
465 }
466}
467
468/* static void au1xmmc_cmd_complete
469 This is called when a command has been completed - grab the response
470 and check for errors. Then start the data transfer if it is indicated.
471*/
472
473static void au1xmmc_cmd_complete(struct au1xmmc_host *host, u32 status)
474{
475
476 struct mmc_request *mrq = host->mrq;
477 struct mmc_command *cmd;
478 int trans;
479
480 if (!host->mrq)
481 return;
482
483 cmd = mrq->cmd;
484 cmd->error = MMC_ERR_NONE;
485
486 if ((cmd->flags & MMC_RSP_MASK) == MMC_RSP_SHORT) {
487
488 /* Techincally, we should be getting all 48 bits of the response
489 * (SD_RESP1 + SD_RESP2), but because our response omits the CRC,
490 * our data ends up being shifted 8 bits to the right. In this case,
491 * that means that the OSR data starts at bit 31, so we can just
492 * read RESP0 and return that
493 */
494
495 cmd->resp[0] = au_readl(host->iobase + SD_RESP0);
496 }
497 else if ((cmd->flags & MMC_RSP_MASK) == MMC_RSP_LONG) {
498 u32 r[4];
499 int i;
500
501 r[0] = au_readl(host->iobase + SD_RESP3);
502 r[1] = au_readl(host->iobase + SD_RESP2);
503 r[2] = au_readl(host->iobase + SD_RESP1);
504 r[3] = au_readl(host->iobase + SD_RESP0);
505
506 /* The CRC is omitted from the response, so really we only got
507 * 120 bytes, but the engine expects 128 bits, so we have to shift
508 * things up
509 */
510
511 for(i = 0; i < 4; i++) {
512 cmd->resp[i] = (r[i] & 0x00FFFFFF) << 8;
513 if (i != 3) cmd->resp[i] |= (r[i + 1] & 0xFF000000) >> 24;
514 }
515 }
516
517 /* Figure out errors */
518
519 if (status & (SD_STATUS_SC | SD_STATUS_WC | SD_STATUS_RC))
520 cmd->error = MMC_ERR_BADCRC;
521
522 trans = host->flags & (HOST_F_XMIT | HOST_F_RECV);
523
524 if (!trans || cmd->error != MMC_ERR_NONE) {
525
526 IRQ_OFF(host, SD_CONFIG_TH | SD_CONFIG_RA|SD_CONFIG_RF);
527 tasklet_schedule(&host->finish_task);
528 return;
529 }
530
531 host->status = HOST_S_DATA;
532
533 if (host->flags & HOST_F_DMA) {
534 u32 channel = DMA_CHANNEL(host);
535
536 /* Start the DMA as soon as the buffer gets something in it */
537
538 if (host->flags & HOST_F_RECV) {
539 u32 mask = SD_STATUS_DB | SD_STATUS_NE;
540
541 while((status & mask) != mask)
542 status = au_readl(HOST_STATUS(host));
543 }
544
545 au1xxx_dbdma_start(channel);
546 }
547}
548
549static void au1xmmc_set_clock(struct au1xmmc_host *host, int rate)
550{
551
552 unsigned int pbus = get_au1x00_speed();
553 unsigned int divisor;
554 u32 config;
555
556 /* From databook:
557 divisor = ((((cpuclock / sbus_divisor) / 2) / mmcclock) / 2) - 1
558 */
559
560 pbus /= ((au_readl(SYS_POWERCTRL) & 0x3) + 2);
561 pbus /= 2;
562
563 divisor = ((pbus / rate) / 2) - 1;
564
565 config = au_readl(HOST_CONFIG(host));
566
567 config &= ~(SD_CONFIG_DIV);
568 config |= (divisor & SD_CONFIG_DIV) | SD_CONFIG_DE;
569
570 au_writel(config, HOST_CONFIG(host));
571 au_sync();
572}
573
574static int
575au1xmmc_prepare_data(struct au1xmmc_host *host, struct mmc_data *data)
576{
577
578 int datalen = data->blocks * (1 << data->blksz_bits);
579
580 if (dma != 0)
581 host->flags |= HOST_F_DMA;
582
583 if (data->flags & MMC_DATA_READ)
584 host->flags |= HOST_F_RECV;
585 else
586 host->flags |= HOST_F_XMIT;
587
588 if (host->mrq->stop)
589 host->flags |= HOST_F_STOP;
590
591 host->dma.dir = DMA_BIDIRECTIONAL;
592
593 host->dma.len = dma_map_sg(mmc_dev(host->mmc), data->sg,
594 data->sg_len, host->dma.dir);
595
596 if (host->dma.len == 0)
597 return MMC_ERR_TIMEOUT;
598
599 au_writel((1 << data->blksz_bits) - 1, HOST_BLKSIZE(host));
600
601 if (host->flags & HOST_F_DMA) {
602 int i;
603 u32 channel = DMA_CHANNEL(host);
604
605 au1xxx_dbdma_stop(channel);
606
607 for(i = 0; i < host->dma.len; i++) {
608 u32 ret = 0, flags = DDMA_FLAGS_NOIE;
609 struct scatterlist *sg = &data->sg[i];
610 int sg_len = sg->length;
611
612 int len = (datalen > sg_len) ? sg_len : datalen;
613
614 if (i == host->dma.len - 1)
615 flags = DDMA_FLAGS_IE;
616
617 if (host->flags & HOST_F_XMIT){
618 ret = au1xxx_dbdma_put_source_flags(channel,
619 (void *) (page_address(sg->page) +
620 sg->offset),
621 len, flags);
622 }
623 else {
624 ret = au1xxx_dbdma_put_dest_flags(channel,
625 (void *) (page_address(sg->page) +
626 sg->offset),
627 len, flags);
628 }
629
630 if (!ret)
631 goto dataerr;
632
633 datalen -= len;
634 }
635 }
636 else {
637 host->pio.index = 0;
638 host->pio.offset = 0;
639 host->pio.len = datalen;
640
641 if (host->flags & HOST_F_XMIT)
642 IRQ_ON(host, SD_CONFIG_TH);
643 else
644 IRQ_ON(host, SD_CONFIG_NE);
645 //IRQ_ON(host, SD_CONFIG_RA|SD_CONFIG_RF);
646 }
647
648 return MMC_ERR_NONE;
649
650 dataerr:
651 dma_unmap_sg(mmc_dev(host->mmc),data->sg,data->sg_len,host->dma.dir);
652 return MMC_ERR_TIMEOUT;
653}
654
655/* static void au1xmmc_request
656 This actually starts a command or data transaction
657*/
658
659static void au1xmmc_request(struct mmc_host* mmc, struct mmc_request* mrq)
660{
661
662 struct au1xmmc_host *host = mmc_priv(mmc);
663 int ret = MMC_ERR_NONE;
664
665 WARN_ON(irqs_disabled());
666 WARN_ON(host->status != HOST_S_IDLE);
667
668 host->mrq = mrq;
669 host->status = HOST_S_CMD;
670
671 bcsr->disk_leds &= ~(1 << 8);
672
673 if (mrq->data) {
674 FLUSH_FIFO(host);
675 ret = au1xmmc_prepare_data(host, mrq->data);
676 }
677
678 if (ret == MMC_ERR_NONE)
679 ret = au1xmmc_send_command(host, 0, mrq->cmd);
680
681 if (ret != MMC_ERR_NONE) {
682 mrq->cmd->error = ret;
683 au1xmmc_finish_request(host);
684 }
685}
686
687static void au1xmmc_reset_controller(struct au1xmmc_host *host)
688{
689
690 /* Apply the clock */
691 au_writel(SD_ENABLE_CE, HOST_ENABLE(host));
692 au_sync_delay(1);
693
694 au_writel(SD_ENABLE_R | SD_ENABLE_CE, HOST_ENABLE(host));
695 au_sync_delay(5);
696
697 au_writel(~0, HOST_STATUS(host));
698 au_sync();
699
700 au_writel(0, HOST_BLKSIZE(host));
701 au_writel(0x001fffff, HOST_TIMEOUT(host));
702 au_sync();
703
704 au_writel(SD_CONFIG2_EN, HOST_CONFIG2(host));
705 au_sync();
706
707 au_writel(SD_CONFIG2_EN | SD_CONFIG2_FF, HOST_CONFIG2(host));
708 au_sync_delay(1);
709
710 au_writel(SD_CONFIG2_EN, HOST_CONFIG2(host));
711 au_sync();
712
713 /* Configure interrupts */
714 au_writel(AU1XMMC_INTERRUPTS, HOST_CONFIG(host));
715 au_sync();
716}
717
718
719static void au1xmmc_set_ios(struct mmc_host* mmc, struct mmc_ios* ios)
720{
721 struct au1xmmc_host *host = mmc_priv(mmc);
722
723 DEBUG("set_ios (power=%u, clock=%uHz, vdd=%u, mode=%u)\n",
724 host->id, ios->power_mode, ios->clock, ios->vdd,
725 ios->bus_mode);
726
727 if (ios->power_mode == MMC_POWER_OFF)
728 au1xmmc_set_power(host, 0);
729 else if (ios->power_mode == MMC_POWER_ON) {
730 au1xmmc_set_power(host, 1);
731 }
732
733 if (ios->clock && ios->clock != host->clock) {
734 au1xmmc_set_clock(host, ios->clock);
735 host->clock = ios->clock;
736 }
737}
738
739static void au1xmmc_dma_callback(int irq, void *dev_id, struct pt_regs *regs)
740{
741 struct au1xmmc_host *host = (struct au1xmmc_host *) dev_id;
742 u32 status;
743
744 /* Avoid spurious interrupts */
745
746 if (!host->mrq)
747 return;
748
749 if (host->flags & HOST_F_STOP)
750 SEND_STOP(host);
751
752 tasklet_schedule(&host->data_task);
753}
754
755#define STATUS_TIMEOUT (SD_STATUS_RAT | SD_STATUS_DT)
756#define STATUS_DATA_IN (SD_STATUS_NE)
757#define STATUS_DATA_OUT (SD_STATUS_TH)
758
759static irqreturn_t au1xmmc_irq(int irq, void *dev_id, struct pt_regs *regs)
760{
761
762 u32 status;
763 int i, ret = 0;
764
765 disable_irq(AU1100_SD_IRQ);
766
767 for(i = 0; i < AU1XMMC_CONTROLLER_COUNT; i++) {
768 struct au1xmmc_host * host = au1xmmc_hosts[i];
769 u32 handled = 1;
770
771 status = au_readl(HOST_STATUS(host));
772
773 if (host->mrq && (status & STATUS_TIMEOUT)) {
774 if (status & SD_STATUS_RAT)
775 host->mrq->cmd->error = MMC_ERR_TIMEOUT;
776
777 else if (status & SD_STATUS_DT)
778 host->mrq->data->error = MMC_ERR_TIMEOUT;
779
780 /* In PIO mode, interrupts might still be enabled */
781 IRQ_OFF(host, SD_CONFIG_NE | SD_CONFIG_TH);
782
783 //IRQ_OFF(host, SD_CONFIG_TH|SD_CONFIG_RA|SD_CONFIG_RF);
784 tasklet_schedule(&host->finish_task);
785 }
786#if 0
787 else if (status & SD_STATUS_DD) {
788
789 /* Sometimes we get a DD before a NE in PIO mode */
790
791 if (!(host->flags & HOST_F_DMA) &&
792 (status & SD_STATUS_NE))
793 au1xmmc_receive_pio(host);
794 else {
795 au1xmmc_data_complete(host, status);
796 //tasklet_schedule(&host->data_task);
797 }
798 }
799#endif
800 else if (status & (SD_STATUS_CR)) {
801 if (host->status == HOST_S_CMD)
802 au1xmmc_cmd_complete(host,status);
803 }
804 else if (!(host->flags & HOST_F_DMA)) {
805 if ((host->flags & HOST_F_XMIT) &&
806 (status & STATUS_DATA_OUT))
807 au1xmmc_send_pio(host);
808 else if ((host->flags & HOST_F_RECV) &&
809 (status & STATUS_DATA_IN))
810 au1xmmc_receive_pio(host);
811 }
812 else if (status & 0x203FBC70) {
813 DEBUG("Unhandled status %8.8x\n", host->id, status);
814 handled = 0;
815 }
816
817 au_writel(status, HOST_STATUS(host));
818 au_sync();
819
820 ret |= handled;
821 }
822
823 enable_irq(AU1100_SD_IRQ);
824 return ret;
825}
826
827static void au1xmmc_poll_event(unsigned long arg)
828{
829 struct au1xmmc_host *host = (struct au1xmmc_host *) arg;
830
831 int card = au1xmmc_card_inserted(host);
832 int controller = (host->flags & HOST_F_ACTIVE) ? 1 : 0;
833
834 if (card != controller) {
835 host->flags &= ~HOST_F_ACTIVE;
836 if (card) host->flags |= HOST_F_ACTIVE;
837 mmc_detect_change(host->mmc, 0);
838 }
839
840 if (host->mrq != NULL) {
841 u32 status = au_readl(HOST_STATUS(host));
842 DEBUG("PENDING - %8.8x\n", host->id, status);
843 }
844
845 mod_timer(&host->timer, jiffies + AU1XMMC_DETECT_TIMEOUT);
846}
847
848static dbdev_tab_t au1xmmc_mem_dbdev =
849{
850 DSCR_CMD0_ALWAYS, DEV_FLAGS_ANYUSE, 0, 8, 0x00000000, 0, 0
851};
852
853static void au1xmmc_init_dma(struct au1xmmc_host *host)
854{
855
856 u32 rxchan, txchan;
857
858 int txid = au1xmmc_card_table[host->id].tx_devid;
859 int rxid = au1xmmc_card_table[host->id].rx_devid;
860
861 /* DSCR_CMD0_ALWAYS has a stride of 32 bits, we need a stride
862 of 8 bits. And since devices are shared, we need to create
863 our own to avoid freaking out other devices
864 */
865
866 int memid = au1xxx_ddma_add_device(&au1xmmc_mem_dbdev);
867
868 txchan = au1xxx_dbdma_chan_alloc(memid, txid,
869 au1xmmc_dma_callback, (void *) host);
870
871 rxchan = au1xxx_dbdma_chan_alloc(rxid, memid,
872 au1xmmc_dma_callback, (void *) host);
873
874 au1xxx_dbdma_set_devwidth(txchan, 8);
875 au1xxx_dbdma_set_devwidth(rxchan, 8);
876
877 au1xxx_dbdma_ring_alloc(txchan, AU1XMMC_DESCRIPTOR_COUNT);
878 au1xxx_dbdma_ring_alloc(rxchan, AU1XMMC_DESCRIPTOR_COUNT);
879
880 host->tx_chan = txchan;
881 host->rx_chan = rxchan;
882}
883
884struct mmc_host_ops au1xmmc_ops = {
885 .request = au1xmmc_request,
886 .set_ios = au1xmmc_set_ios,
887};
888
889static int au1xmmc_probe(struct device *dev)
890{
891
892 int i, ret = 0;
893
894 /* THe interrupt is shared among all controllers */
895 ret = request_irq(AU1100_SD_IRQ, au1xmmc_irq, SA_INTERRUPT, "MMC", 0);
896
897 if (ret) {
898 printk(DRIVER_NAME "ERROR: Couldn't get int %d: %d\n",
899 AU1100_SD_IRQ, ret);
900 return -ENXIO;
901 }
902
903 disable_irq(AU1100_SD_IRQ);
904
905 for(i = 0; i < AU1XMMC_CONTROLLER_COUNT; i++) {
906 struct mmc_host *mmc = mmc_alloc_host(sizeof(struct au1xmmc_host), dev);
907 struct au1xmmc_host *host = 0;
908
909 if (!mmc) {
910 printk(DRIVER_NAME "ERROR: no mem for host %d\n", i);
911 au1xmmc_hosts[i] = 0;
912 continue;
913 }
914
915 mmc->ops = &au1xmmc_ops;
916
917 mmc->f_min = 450000;
918 mmc->f_max = 24000000;
919
920 mmc->max_seg_size = AU1XMMC_DESCRIPTOR_SIZE;
921 mmc->max_phys_segs = AU1XMMC_DESCRIPTOR_COUNT;
922
923 mmc->ocr_avail = AU1XMMC_OCR;
924
925 host = mmc_priv(mmc);
926 host->mmc = mmc;
927
928 host->id = i;
929 host->iobase = au1xmmc_card_table[host->id].iobase;
930 host->clock = 0;
931 host->power_mode = MMC_POWER_OFF;
932
933 host->flags = au1xmmc_card_inserted(host) ? HOST_F_ACTIVE : 0;
934 host->status = HOST_S_IDLE;
935
936 init_timer(&host->timer);
937
938 host->timer.function = au1xmmc_poll_event;
939 host->timer.data = (unsigned long) host;
940 host->timer.expires = jiffies + AU1XMMC_DETECT_TIMEOUT;
941
942 tasklet_init(&host->data_task, au1xmmc_tasklet_data,
943 (unsigned long) host);
944
945 tasklet_init(&host->finish_task, au1xmmc_tasklet_finish,
946 (unsigned long) host);
947
948 spin_lock_init(&host->lock);
949
950 if (dma != 0)
951 au1xmmc_init_dma(host);
952
953 au1xmmc_reset_controller(host);
954
955 mmc_add_host(mmc);
956 au1xmmc_hosts[i] = host;
957
958 add_timer(&host->timer);
959
960 printk(KERN_INFO DRIVER_NAME ": MMC Controller %d set up at %8.8X (mode=%s)\n",
961 host->id, host->iobase, dma ? "dma" : "pio");
962 }
963
964 enable_irq(AU1100_SD_IRQ);
965
966 return 0;
967}
968
969static int au1xmmc_remove(struct device *dev)
970{
971
972 int i;
973
974 disable_irq(AU1100_SD_IRQ);
975
976 for(i = 0; i < AU1XMMC_CONTROLLER_COUNT; i++) {
977 struct au1xmmc_host *host = au1xmmc_hosts[i];
978 if (!host) continue;
979
980 tasklet_kill(&host->data_task);
981 tasklet_kill(&host->finish_task);
982
983 del_timer_sync(&host->timer);
984 au1xmmc_set_power(host, 0);
985
986 mmc_remove_host(host->mmc);
987
988 au1xxx_dbdma_chan_free(host->tx_chan);
989 au1xxx_dbdma_chan_free(host->rx_chan);
990
991 au_writel(0x0, HOST_ENABLE(host));
992 au_sync();
993 }
994
995 free_irq(AU1100_SD_IRQ, 0);
996 return 0;
997}
998
999static struct device_driver au1xmmc_driver = {
1000 .name = DRIVER_NAME,
1001 .bus = &platform_bus_type,
1002 .probe = au1xmmc_probe,
1003 .remove = au1xmmc_remove,
1004 .suspend = NULL,
1005 .resume = NULL
1006};
1007
1008static int __init au1xmmc_init(void)
1009{
1010 return driver_register(&au1xmmc_driver);
1011}
1012
1013static void __exit au1xmmc_exit(void)
1014{
1015 driver_unregister(&au1xmmc_driver);
1016}
1017
1018module_init(au1xmmc_init);
1019module_exit(au1xmmc_exit);
1020
1021#ifdef MODULE
1022MODULE_AUTHOR("Advanced Micro Devices, Inc");
1023MODULE_DESCRIPTION("MMC/SD driver for the Alchemy Au1XXX");
1024MODULE_LICENSE("GPL");
1025#endif
1026
diff --git a/drivers/mmc/au1xmmc.h b/drivers/mmc/au1xmmc.h
new file mode 100644
index 000000000000..341cbdf0baca
--- /dev/null
+++ b/drivers/mmc/au1xmmc.h
@@ -0,0 +1,96 @@
1#ifndef _AU1XMMC_H_
2#define _AU1XMMC_H_
3
4/* Hardware definitions */
5
6#define AU1XMMC_DESCRIPTOR_COUNT 1
7#define AU1XMMC_DESCRIPTOR_SIZE 2048
8
9#define AU1XMMC_OCR ( MMC_VDD_27_28 | MMC_VDD_28_29 | MMC_VDD_29_30 | \
10 MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 | \
11 MMC_VDD_33_34 | MMC_VDD_34_35 | MMC_VDD_35_36)
12
13/* Easy access macros */
14
15#define HOST_STATUS(h) ((h)->iobase + SD_STATUS)
16#define HOST_CONFIG(h) ((h)->iobase + SD_CONFIG)
17#define HOST_ENABLE(h) ((h)->iobase + SD_ENABLE)
18#define HOST_TXPORT(h) ((h)->iobase + SD_TXPORT)
19#define HOST_RXPORT(h) ((h)->iobase + SD_RXPORT)
20#define HOST_CMDARG(h) ((h)->iobase + SD_CMDARG)
21#define HOST_BLKSIZE(h) ((h)->iobase + SD_BLKSIZE)
22#define HOST_CMD(h) ((h)->iobase + SD_CMD)
23#define HOST_CONFIG2(h) ((h)->iobase + SD_CONFIG2)
24#define HOST_TIMEOUT(h) ((h)->iobase + SD_TIMEOUT)
25#define HOST_DEBUG(h) ((h)->iobase + SD_DEBUG)
26
27#define DMA_CHANNEL(h) \
28 ( ((h)->flags & HOST_F_XMIT) ? (h)->tx_chan : (h)->rx_chan)
29
30/* This gives us a hard value for the stop command that we can write directly
31 * to the command register
32 */
33
34#define STOP_CMD (SD_CMD_RT_1B|SD_CMD_CT_7|(0xC << SD_CMD_CI_SHIFT)|SD_CMD_GO)
35
36/* This is the set of interrupts that we configure by default */
37
38#if 0
39#define AU1XMMC_INTERRUPTS (SD_CONFIG_SC | SD_CONFIG_DT | SD_CONFIG_DD | \
40 SD_CONFIG_RAT | SD_CONFIG_CR | SD_CONFIG_I)
41#endif
42
43#define AU1XMMC_INTERRUPTS (SD_CONFIG_SC | SD_CONFIG_DT | \
44 SD_CONFIG_RAT | SD_CONFIG_CR | SD_CONFIG_I)
45/* The poll event (looking for insert/remove events runs twice a second */
46#define AU1XMMC_DETECT_TIMEOUT (HZ/2)
47
48struct au1xmmc_host {
49 struct mmc_host *mmc;
50 struct mmc_request *mrq;
51
52 u32 id;
53
54 u32 flags;
55 u32 iobase;
56 u32 clock;
57 u32 bus_width;
58 u32 power_mode;
59
60 int status;
61
62 struct {
63 int len;
64 int dir;
65 } dma;
66
67 struct {
68 int index;
69 int offset;
70 int len;
71 } pio;
72
73 u32 tx_chan;
74 u32 rx_chan;
75
76 struct timer_list timer;
77 struct tasklet_struct finish_task;
78 struct tasklet_struct data_task;
79
80 spinlock_t lock;
81};
82
83/* Status flags used by the host structure */
84
85#define HOST_F_XMIT 0x0001
86#define HOST_F_RECV 0x0002
87#define HOST_F_DMA 0x0010
88#define HOST_F_ACTIVE 0x0100
89#define HOST_F_STOP 0x1000
90
91#define HOST_S_IDLE 0x0001
92#define HOST_S_CMD 0x0002
93#define HOST_S_DATA 0x0003
94#define HOST_S_STOP 0x0004
95
96#endif
diff --git a/drivers/mmc/mmc_block.c b/drivers/mmc/mmc_block.c
index fa83f15fdf16..9b629856c735 100644
--- a/drivers/mmc/mmc_block.c
+++ b/drivers/mmc/mmc_block.c
@@ -85,6 +85,12 @@ static void mmc_blk_put(struct mmc_blk_data *md)
85 up(&open_lock); 85 up(&open_lock);
86} 86}
87 87
88static inline int mmc_blk_readonly(struct mmc_card *card)
89{
90 return mmc_card_readonly(card) ||
91 !(card->csd.cmdclass & CCC_BLOCK_WRITE);
92}
93
88static int mmc_blk_open(struct inode *inode, struct file *filp) 94static int mmc_blk_open(struct inode *inode, struct file *filp)
89{ 95{
90 struct mmc_blk_data *md; 96 struct mmc_blk_data *md;
@@ -97,7 +103,7 @@ static int mmc_blk_open(struct inode *inode, struct file *filp)
97 ret = 0; 103 ret = 0;
98 104
99 if ((filp->f_mode & FMODE_WRITE) && 105 if ((filp->f_mode & FMODE_WRITE) &&
100 mmc_card_readonly(md->queue.card)) 106 mmc_blk_readonly(md->queue.card))
101 ret = -EROFS; 107 ret = -EROFS;
102 } 108 }
103 109
@@ -410,7 +416,7 @@ static int mmc_blk_probe(struct mmc_card *card)
410 printk(KERN_INFO "%s: %s %s %dKiB %s\n", 416 printk(KERN_INFO "%s: %s %s %dKiB %s\n",
411 md->disk->disk_name, mmc_card_id(card), mmc_card_name(card), 417 md->disk->disk_name, mmc_card_id(card), mmc_card_name(card),
412 (card->csd.capacity << card->csd.read_blkbits) / 1024, 418 (card->csd.capacity << card->csd.read_blkbits) / 1024,
413 mmc_card_readonly(card)?"(ro)":""); 419 mmc_blk_readonly(card)?"(ro)":"");
414 420
415 mmc_set_drvdata(card, md); 421 mmc_set_drvdata(card, md);
416 add_disk(md->disk); 422 add_disk(md->disk);
diff --git a/drivers/mmc/mmci.c b/drivers/mmc/mmci.c
index 91c74843dc0d..1e6bdba26756 100644
--- a/drivers/mmc/mmci.c
+++ b/drivers/mmc/mmci.c
@@ -24,6 +24,7 @@
24#include <asm/io.h> 24#include <asm/io.h>
25#include <asm/irq.h> 25#include <asm/irq.h>
26#include <asm/scatterlist.h> 26#include <asm/scatterlist.h>
27#include <asm/sizes.h>
27#include <asm/hardware/amba.h> 28#include <asm/hardware/amba.h>
28#include <asm/hardware/clock.h> 29#include <asm/hardware/clock.h>
29#include <asm/mach/mmc.h> 30#include <asm/mach/mmc.h>
diff --git a/drivers/mmc/pxamci.c b/drivers/mmc/pxamci.c
index b53af57074e3..d575e3a018bc 100644
--- a/drivers/mmc/pxamci.c
+++ b/drivers/mmc/pxamci.c
@@ -29,7 +29,6 @@
29 29
30#include <asm/dma.h> 30#include <asm/dma.h>
31#include <asm/io.h> 31#include <asm/io.h>
32#include <asm/irq.h>
33#include <asm/scatterlist.h> 32#include <asm/scatterlist.h>
34#include <asm/sizes.h> 33#include <asm/sizes.h>
35 34
@@ -571,23 +570,23 @@ static int pxamci_remove(struct device *dev)
571} 570}
572 571
573#ifdef CONFIG_PM 572#ifdef CONFIG_PM
574static int pxamci_suspend(struct device *dev, pm_message_t state, u32 level) 573static int pxamci_suspend(struct device *dev, pm_message_t state)
575{ 574{
576 struct mmc_host *mmc = dev_get_drvdata(dev); 575 struct mmc_host *mmc = dev_get_drvdata(dev);
577 int ret = 0; 576 int ret = 0;
578 577
579 if (mmc && level == SUSPEND_DISABLE) 578 if (mmc)
580 ret = mmc_suspend_host(mmc, state); 579 ret = mmc_suspend_host(mmc, state);
581 580
582 return ret; 581 return ret;
583} 582}
584 583
585static int pxamci_resume(struct device *dev, u32 level) 584static int pxamci_resume(struct device *dev)
586{ 585{
587 struct mmc_host *mmc = dev_get_drvdata(dev); 586 struct mmc_host *mmc = dev_get_drvdata(dev);
588 int ret = 0; 587 int ret = 0;
589 588
590 if (mmc && level == RESUME_ENABLE) 589 if (mmc)
591 ret = mmc_resume_host(mmc); 590 ret = mmc_resume_host(mmc);
592 591
593 return ret; 592 return ret;
diff --git a/drivers/mmc/wbsd.c b/drivers/mmc/wbsd.c
index 3cbca7cbea80..3ace875decc4 100644
--- a/drivers/mmc/wbsd.c
+++ b/drivers/mmc/wbsd.c
@@ -1033,13 +1033,16 @@ static void wbsd_set_ios(struct mmc_host* mmc, struct mmc_ios* ios)
1033 } 1033 }
1034 else 1034 else
1035 { 1035 {
1036 setup &= ~WBSD_DAT3_H; 1036 if (setup & WBSD_DAT3_H)
1037 {
1038 setup &= ~WBSD_DAT3_H;
1037 1039
1038 /* 1040 /*
1039 * We cannot resume card detection immediatly 1041 * We cannot resume card detection immediatly
1040 * because of capacitance and delays in the chip. 1042 * because of capacitance and delays in the chip.
1041 */ 1043 */
1042 mod_timer(&host->ignore_timer, jiffies + HZ/100); 1044 mod_timer(&host->ignore_timer, jiffies + HZ/100);
1045 }
1043 } 1046 }
1044 wbsd_write_index(host, WBSD_IDX_SETUP, setup); 1047 wbsd_write_index(host, WBSD_IDX_SETUP, setup);
1045 1048
@@ -1461,8 +1464,10 @@ static int __devinit wbsd_scan(struct wbsd_host* host)
1461 { 1464 {
1462 id = 0xFFFF; 1465 id = 0xFFFF;
1463 1466
1464 outb(unlock_codes[j], config_ports[i]); 1467 host->config = config_ports[i];
1465 outb(unlock_codes[j], config_ports[i]); 1468 host->unlock_code = unlock_codes[j];
1469
1470 wbsd_unlock_config(host);
1466 1471
1467 outb(WBSD_CONF_ID_HI, config_ports[i]); 1472 outb(WBSD_CONF_ID_HI, config_ports[i]);
1468 id = inb(config_ports[i] + 1) << 8; 1473 id = inb(config_ports[i] + 1) << 8;
@@ -1470,13 +1475,13 @@ static int __devinit wbsd_scan(struct wbsd_host* host)
1470 outb(WBSD_CONF_ID_LO, config_ports[i]); 1475 outb(WBSD_CONF_ID_LO, config_ports[i]);
1471 id |= inb(config_ports[i] + 1); 1476 id |= inb(config_ports[i] + 1);
1472 1477
1478 wbsd_lock_config(host);
1479
1473 for (k = 0;k < sizeof(valid_ids)/sizeof(int);k++) 1480 for (k = 0;k < sizeof(valid_ids)/sizeof(int);k++)
1474 { 1481 {
1475 if (id == valid_ids[k]) 1482 if (id == valid_ids[k])
1476 { 1483 {
1477 host->chip_id = id; 1484 host->chip_id = id;
1478 host->config = config_ports[i];
1479 host->unlock_code = unlock_codes[i];
1480 1485
1481 return 0; 1486 return 0;
1482 } 1487 }
@@ -1487,13 +1492,14 @@ static int __devinit wbsd_scan(struct wbsd_host* host)
1487 DBG("Unknown hardware (id %x) found at %x\n", 1492 DBG("Unknown hardware (id %x) found at %x\n",
1488 id, config_ports[i]); 1493 id, config_ports[i]);
1489 } 1494 }
1490
1491 outb(LOCK_CODE, config_ports[i]);
1492 } 1495 }
1493 1496
1494 release_region(config_ports[i], 2); 1497 release_region(config_ports[i], 2);
1495 } 1498 }
1496 1499
1500 host->config = 0;
1501 host->unlock_code = 0;
1502
1497 return -ENODEV; 1503 return -ENODEV;
1498} 1504}
1499 1505
@@ -1699,8 +1705,10 @@ static void __devexit wbsd_release_resources(struct wbsd_host* host)
1699 * Configure the resources the chip should use. 1705 * Configure the resources the chip should use.
1700 */ 1706 */
1701 1707
1702static void __devinit wbsd_chip_config(struct wbsd_host* host) 1708static void wbsd_chip_config(struct wbsd_host* host)
1703{ 1709{
1710 wbsd_unlock_config(host);
1711
1704 /* 1712 /*
1705 * Reset the chip. 1713 * Reset the chip.
1706 */ 1714 */
@@ -1733,16 +1741,20 @@ static void __devinit wbsd_chip_config(struct wbsd_host* host)
1733 */ 1741 */
1734 wbsd_write_config(host, WBSD_CONF_ENABLE, 1); 1742 wbsd_write_config(host, WBSD_CONF_ENABLE, 1);
1735 wbsd_write_config(host, WBSD_CONF_POWER, 0x20); 1743 wbsd_write_config(host, WBSD_CONF_POWER, 0x20);
1744
1745 wbsd_lock_config(host);
1736} 1746}
1737 1747
1738/* 1748/*
1739 * Check that configured resources are correct. 1749 * Check that configured resources are correct.
1740 */ 1750 */
1741 1751
1742static int __devinit wbsd_chip_validate(struct wbsd_host* host) 1752static int wbsd_chip_validate(struct wbsd_host* host)
1743{ 1753{
1744 int base, irq, dma; 1754 int base, irq, dma;
1745 1755
1756 wbsd_unlock_config(host);
1757
1746 /* 1758 /*
1747 * Select SD/MMC function. 1759 * Select SD/MMC function.
1748 */ 1760 */
@@ -1758,6 +1770,8 @@ static int __devinit wbsd_chip_validate(struct wbsd_host* host)
1758 1770
1759 dma = wbsd_read_config(host, WBSD_CONF_DRQ); 1771 dma = wbsd_read_config(host, WBSD_CONF_DRQ);
1760 1772
1773 wbsd_lock_config(host);
1774
1761 /* 1775 /*
1762 * Validate against given configuration. 1776 * Validate against given configuration.
1763 */ 1777 */
@@ -1771,6 +1785,20 @@ static int __devinit wbsd_chip_validate(struct wbsd_host* host)
1771 return 1; 1785 return 1;
1772} 1786}
1773 1787
1788/*
1789 * Powers down the SD function
1790 */
1791
1792static void wbsd_chip_poweroff(struct wbsd_host* host)
1793{
1794 wbsd_unlock_config(host);
1795
1796 wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD);
1797 wbsd_write_config(host, WBSD_CONF_ENABLE, 0);
1798
1799 wbsd_lock_config(host);
1800}
1801
1774/*****************************************************************************\ 1802/*****************************************************************************\
1775 * * 1803 * *
1776 * Devices setup and shutdown * 1804 * Devices setup and shutdown *
@@ -1844,7 +1872,11 @@ static int __devinit wbsd_init(struct device* dev, int base, int irq, int dma,
1844 */ 1872 */
1845#ifdef CONFIG_PM 1873#ifdef CONFIG_PM
1846 if (host->config) 1874 if (host->config)
1875 {
1876 wbsd_unlock_config(host);
1847 wbsd_write_config(host, WBSD_CONF_PME, 0xA0); 1877 wbsd_write_config(host, WBSD_CONF_PME, 0xA0);
1878 wbsd_lock_config(host);
1879 }
1848#endif 1880#endif
1849 /* 1881 /*
1850 * Allow device to initialise itself properly. 1882 * Allow device to initialise itself properly.
@@ -1885,16 +1917,11 @@ static void __devexit wbsd_shutdown(struct device* dev, int pnp)
1885 1917
1886 mmc_remove_host(mmc); 1918 mmc_remove_host(mmc);
1887 1919
1920 /*
1921 * Power down the SD/MMC function.
1922 */
1888 if (!pnp) 1923 if (!pnp)
1889 { 1924 wbsd_chip_poweroff(host);
1890 /*
1891 * Power down the SD/MMC function.
1892 */
1893 wbsd_unlock_config(host);
1894 wbsd_write_config(host, WBSD_CONF_DEVICE, DEVICE_SD);
1895 wbsd_write_config(host, WBSD_CONF_ENABLE, 0);
1896 wbsd_lock_config(host);
1897 }
1898 1925
1899 wbsd_release_resources(host); 1926 wbsd_release_resources(host);
1900 1927
@@ -1955,23 +1982,59 @@ static void __devexit wbsd_pnp_remove(struct pnp_dev * dev)
1955 */ 1982 */
1956 1983
1957#ifdef CONFIG_PM 1984#ifdef CONFIG_PM
1958static int wbsd_suspend(struct device *dev, pm_message_t state, u32 level) 1985
1986static int wbsd_suspend(struct device *dev, pm_message_t state)
1959{ 1987{
1960 DBGF("Not yet supported\n"); 1988 struct mmc_host *mmc = dev_get_drvdata(dev);
1989 struct wbsd_host *host;
1990 int ret;
1991
1992 if (!mmc)
1993 return 0;
1994
1995 DBG("Suspending...\n");
1996
1997 ret = mmc_suspend_host(mmc, state);
1998 if (!ret)
1999 return ret;
2000
2001 host = mmc_priv(mmc);
2002
2003 wbsd_chip_poweroff(host);
1961 2004
1962 return 0; 2005 return 0;
1963} 2006}
1964 2007
1965static int wbsd_resume(struct device *dev, u32 level) 2008static int wbsd_resume(struct device *dev)
1966{ 2009{
1967 DBGF("Not yet supported\n"); 2010 struct mmc_host *mmc = dev_get_drvdata(dev);
2011 struct wbsd_host *host;
1968 2012
1969 return 0; 2013 if (!mmc)
2014 return 0;
2015
2016 DBG("Resuming...\n");
2017
2018 host = mmc_priv(mmc);
2019
2020 wbsd_chip_config(host);
2021
2022 /*
2023 * Allow device to initialise itself properly.
2024 */
2025 mdelay(5);
2026
2027 wbsd_init_device(host);
2028
2029 return mmc_resume_host(mmc);
1970} 2030}
1971#else 2031
2032#else /* CONFIG_PM */
2033
1972#define wbsd_suspend NULL 2034#define wbsd_suspend NULL
1973#define wbsd_resume NULL 2035#define wbsd_resume NULL
1974#endif 2036
2037#endif /* CONFIG_PM */
1975 2038
1976static struct platform_device *wbsd_device; 2039static struct platform_device *wbsd_device;
1977 2040
diff --git a/drivers/mtd/chips/jedec.c b/drivers/mtd/chips/jedec.c
index 62d235a9a4e2..4f6778f3ee3e 100644
--- a/drivers/mtd/chips/jedec.c
+++ b/drivers/mtd/chips/jedec.c
@@ -17,6 +17,7 @@
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/slab.h>
20#include <linux/mtd/jedec.h> 21#include <linux/mtd/jedec.h>
21#include <linux/mtd/map.h> 22#include <linux/mtd/map.h>
22#include <linux/mtd/mtd.h> 23#include <linux/mtd/mtd.h>
diff --git a/drivers/mtd/devices/lart.c b/drivers/mtd/devices/lart.c
index dfd335e4a2a8..df987a53ed9c 100644
--- a/drivers/mtd/devices/lart.c
+++ b/drivers/mtd/devices/lart.c
@@ -44,6 +44,7 @@
44#include <linux/types.h> 44#include <linux/types.h>
45#include <linux/init.h> 45#include <linux/init.h>
46#include <linux/errno.h> 46#include <linux/errno.h>
47#include <linux/string.h>
47#include <linux/mtd/mtd.h> 48#include <linux/mtd/mtd.h>
48#ifdef HAVE_PARTITIONS 49#ifdef HAVE_PARTITIONS
49#include <linux/mtd/partitions.h> 50#include <linux/mtd/partitions.h>
diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c
index a423a382095a..765c0179c8df 100644
--- a/drivers/mtd/devices/phram.c
+++ b/drivers/mtd/devices/phram.c
@@ -22,6 +22,7 @@
22#include <linux/list.h> 22#include <linux/list.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/moduleparam.h> 24#include <linux/moduleparam.h>
25#include <linux/slab.h>
25#include <linux/mtd/mtd.h> 26#include <linux/mtd/mtd.h>
26 27
27#define ERROR(fmt, args...) printk(KERN_ERR "phram: " fmt , ## args) 28#define ERROR(fmt, args...) printk(KERN_ERR "phram: " fmt , ## args)
diff --git a/drivers/mtd/maps/bast-flash.c b/drivers/mtd/maps/bast-flash.c
index 0ba0ff7d43b9..63104c73ca3c 100644
--- a/drivers/mtd/maps/bast-flash.c
+++ b/drivers/mtd/maps/bast-flash.c
@@ -33,6 +33,7 @@
33#include <linux/string.h> 33#include <linux/string.h>
34#include <linux/ioport.h> 34#include <linux/ioport.h>
35#include <linux/device.h> 35#include <linux/device.h>
36#include <linux/slab.h>
36 37
37#include <linux/mtd/mtd.h> 38#include <linux/mtd/mtd.h>
38#include <linux/mtd/map.h> 39#include <linux/mtd/map.h>
diff --git a/drivers/mtd/maps/ceiva.c b/drivers/mtd/maps/ceiva.c
index da8584a662f4..c68b31dc7e6d 100644
--- a/drivers/mtd/maps/ceiva.c
+++ b/drivers/mtd/maps/ceiva.c
@@ -20,6 +20,7 @@
20#include <linux/ioport.h> 20#include <linux/ioport.h>
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/slab.h>
23 24
24#include <linux/mtd/mtd.h> 25#include <linux/mtd/mtd.h>
25#include <linux/mtd/map.h> 26#include <linux/mtd/map.h>
diff --git a/drivers/mtd/maps/dc21285.c b/drivers/mtd/maps/dc21285.c
index 938c41f2f056..e5b74169fde6 100644
--- a/drivers/mtd/maps/dc21285.c
+++ b/drivers/mtd/maps/dc21285.c
@@ -13,6 +13,7 @@
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/slab.h>
16 17
17#include <linux/mtd/mtd.h> 18#include <linux/mtd/mtd.h>
18#include <linux/mtd/map.h> 19#include <linux/mtd/map.h>
diff --git a/drivers/mtd/maps/dilnetpc.c b/drivers/mtd/maps/dilnetpc.c
index 0bc79c93a584..f99519692cb7 100644
--- a/drivers/mtd/maps/dilnetpc.c
+++ b/drivers/mtd/maps/dilnetpc.c
@@ -30,12 +30,15 @@
30#include <linux/types.h> 30#include <linux/types.h>
31#include <linux/kernel.h> 31#include <linux/kernel.h>
32#include <linux/init.h> 32#include <linux/init.h>
33#include <asm/io.h> 33#include <linux/string.h>
34
34#include <linux/mtd/mtd.h> 35#include <linux/mtd/mtd.h>
35#include <linux/mtd/map.h> 36#include <linux/mtd/map.h>
36#include <linux/mtd/partitions.h> 37#include <linux/mtd/partitions.h>
37#include <linux/mtd/concat.h> 38#include <linux/mtd/concat.h>
38 39
40#include <asm/io.h>
41
39/* 42/*
40** The DIL/NetPC keeps its BIOS in two distinct flash blocks. 43** The DIL/NetPC keeps its BIOS in two distinct flash blocks.
41** Destroying any of these blocks transforms the DNPC into 44** Destroying any of these blocks transforms the DNPC into
diff --git a/drivers/mtd/maps/epxa10db-flash.c b/drivers/mtd/maps/epxa10db-flash.c
index ab6dbe2b8cce..1df6188926b3 100644
--- a/drivers/mtd/maps/epxa10db-flash.c
+++ b/drivers/mtd/maps/epxa10db-flash.c
@@ -27,12 +27,15 @@
27#include <linux/types.h> 27#include <linux/types.h>
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/init.h> 29#include <linux/init.h>
30#include <asm/io.h> 30#include <linux/slab.h>
31
31#include <linux/mtd/mtd.h> 32#include <linux/mtd/mtd.h>
32#include <linux/mtd/map.h> 33#include <linux/mtd/map.h>
33#include <linux/mtd/partitions.h> 34#include <linux/mtd/partitions.h>
34 35
36#include <asm/io.h>
35#include <asm/hardware.h> 37#include <asm/hardware.h>
38
36#ifdef CONFIG_EPXA10DB 39#ifdef CONFIG_EPXA10DB
37#define BOARD_NAME "EPXA10DB" 40#define BOARD_NAME "EPXA10DB"
38#else 41#else
diff --git a/drivers/mtd/maps/fortunet.c b/drivers/mtd/maps/fortunet.c
index 068bb6a54520..00f7bbe5479e 100644
--- a/drivers/mtd/maps/fortunet.c
+++ b/drivers/mtd/maps/fortunet.c
@@ -7,11 +7,14 @@
7#include <linux/types.h> 7#include <linux/types.h>
8#include <linux/kernel.h> 8#include <linux/kernel.h>
9#include <linux/init.h> 9#include <linux/init.h>
10#include <asm/io.h> 10#include <linux/string.h>
11
11#include <linux/mtd/mtd.h> 12#include <linux/mtd/mtd.h>
12#include <linux/mtd/map.h> 13#include <linux/mtd/map.h>
13#include <linux/mtd/partitions.h> 14#include <linux/mtd/partitions.h>
14 15
16#include <asm/io.h>
17
15#define MAX_NUM_REGIONS 4 18#define MAX_NUM_REGIONS 4
16#define MAX_NUM_PARTITIONS 8 19#define MAX_NUM_PARTITIONS 8
17 20
diff --git a/drivers/mtd/maps/ixp2000.c b/drivers/mtd/maps/ixp2000.c
index a9f86c7fbd52..1e5d6e1d05f3 100644
--- a/drivers/mtd/maps/ixp2000.c
+++ b/drivers/mtd/maps/ixp2000.c
@@ -22,11 +22,13 @@
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/string.h> 24#include <linux/string.h>
25#include <linux/slab.h>
26#include <linux/ioport.h>
27#include <linux/device.h>
28
25#include <linux/mtd/mtd.h> 29#include <linux/mtd/mtd.h>
26#include <linux/mtd/map.h> 30#include <linux/mtd/map.h>
27#include <linux/mtd/partitions.h> 31#include <linux/mtd/partitions.h>
28#include <linux/ioport.h>
29#include <linux/device.h>
30 32
31#include <asm/io.h> 33#include <asm/io.h>
32#include <asm/hardware.h> 34#include <asm/hardware.h>
diff --git a/drivers/mtd/maps/ixp4xx.c b/drivers/mtd/maps/ixp4xx.c
index 3fcc32884074..da316e543237 100644
--- a/drivers/mtd/maps/ixp4xx.c
+++ b/drivers/mtd/maps/ixp4xx.c
@@ -20,11 +20,14 @@
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/string.h> 22#include <linux/string.h>
23#include <linux/slab.h>
24#include <linux/ioport.h>
25#include <linux/device.h>
26
23#include <linux/mtd/mtd.h> 27#include <linux/mtd/mtd.h>
24#include <linux/mtd/map.h> 28#include <linux/mtd/map.h>
25#include <linux/mtd/partitions.h> 29#include <linux/mtd/partitions.h>
26#include <linux/ioport.h> 30
27#include <linux/device.h>
28#include <asm/io.h> 31#include <asm/io.h>
29#include <asm/mach/flash.h> 32#include <asm/mach/flash.h>
30 33
diff --git a/drivers/mtd/maps/lubbock-flash.c b/drivers/mtd/maps/lubbock-flash.c
index 1298de475c9a..2337e0c46750 100644
--- a/drivers/mtd/maps/lubbock-flash.c
+++ b/drivers/mtd/maps/lubbock-flash.c
@@ -15,10 +15,13 @@
15#include <linux/types.h> 15#include <linux/types.h>
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/slab.h>
19
18#include <linux/dma-mapping.h> 20#include <linux/dma-mapping.h>
19#include <linux/mtd/mtd.h> 21#include <linux/mtd/mtd.h>
20#include <linux/mtd/map.h> 22#include <linux/mtd/map.h>
21#include <linux/mtd/partitions.h> 23#include <linux/mtd/partitions.h>
24
22#include <asm/io.h> 25#include <asm/io.h>
23#include <asm/hardware.h> 26#include <asm/hardware.h>
24#include <asm/arch/pxa-regs.h> 27#include <asm/arch/pxa-regs.h>
diff --git a/drivers/mtd/maps/mainstone-flash.c b/drivers/mtd/maps/mainstone-flash.c
index 87e93fa60588..da0f8a692628 100644
--- a/drivers/mtd/maps/mainstone-flash.c
+++ b/drivers/mtd/maps/mainstone-flash.c
@@ -16,9 +16,12 @@
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/dma-mapping.h> 18#include <linux/dma-mapping.h>
19#include <linux/slab.h>
20
19#include <linux/mtd/mtd.h> 21#include <linux/mtd/mtd.h>
20#include <linux/mtd/map.h> 22#include <linux/mtd/map.h>
21#include <linux/mtd/partitions.h> 23#include <linux/mtd/partitions.h>
24
22#include <asm/io.h> 25#include <asm/io.h>
23#include <asm/hardware.h> 26#include <asm/hardware.h>
24#include <asm/arch/pxa-regs.h> 27#include <asm/arch/pxa-regs.h>
diff --git a/drivers/mtd/maps/omap-toto-flash.c b/drivers/mtd/maps/omap-toto-flash.c
index 496109071cb1..da36e8dddd17 100644
--- a/drivers/mtd/maps/omap-toto-flash.c
+++ b/drivers/mtd/maps/omap-toto-flash.c
@@ -12,9 +12,9 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/types.h> 13#include <linux/types.h>
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15
16#include <linux/errno.h> 15#include <linux/errno.h>
17#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/slab.h>
18 18
19#include <linux/mtd/mtd.h> 19#include <linux/mtd/mtd.h>
20#include <linux/mtd/map.h> 20#include <linux/mtd/map.h>
diff --git a/drivers/mtd/maps/omap_nor.c b/drivers/mtd/maps/omap_nor.c
index b17bca657daf..fa84566245a7 100644
--- a/drivers/mtd/maps/omap_nor.c
+++ b/drivers/mtd/maps/omap_nor.c
@@ -36,6 +36,8 @@
36#include <linux/kernel.h> 36#include <linux/kernel.h>
37#include <linux/init.h> 37#include <linux/init.h>
38#include <linux/ioport.h> 38#include <linux/ioport.h>
39#include <linux/slab.h>
40
39#include <linux/mtd/mtd.h> 41#include <linux/mtd/mtd.h>
40#include <linux/mtd/map.h> 42#include <linux/mtd/map.h>
41#include <linux/mtd/partitions.h> 43#include <linux/mtd/partitions.h>
diff --git a/drivers/mtd/maps/pci.c b/drivers/mtd/maps/pci.c
index 18dbd3af1eaa..d9c64e99ee32 100644
--- a/drivers/mtd/maps/pci.c
+++ b/drivers/mtd/maps/pci.c
@@ -17,6 +17,7 @@
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/pci.h> 18#include <linux/pci.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/slab.h>
20 21
21#include <linux/mtd/mtd.h> 22#include <linux/mtd/mtd.h>
22#include <linux/mtd/map.h> 23#include <linux/mtd/map.h>
diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c
index 118b04544cad..a0577ea00c3c 100644
--- a/drivers/mtd/maps/plat-ram.c
+++ b/drivers/mtd/maps/plat-ram.c
@@ -30,6 +30,7 @@
30#include <linux/string.h> 30#include <linux/string.h>
31#include <linux/ioport.h> 31#include <linux/ioport.h>
32#include <linux/device.h> 32#include <linux/device.h>
33#include <linux/slab.h>
33 34
34#include <linux/mtd/mtd.h> 35#include <linux/mtd/mtd.h>
35#include <linux/mtd/map.h> 36#include <linux/mtd/map.h>
diff --git a/drivers/mtd/maps/sa1100-flash.c b/drivers/mtd/maps/sa1100-flash.c
index 8dcaa357b4bb..c81bec7b14d5 100644
--- a/drivers/mtd/maps/sa1100-flash.c
+++ b/drivers/mtd/maps/sa1100-flash.c
@@ -21,6 +21,7 @@
21#include <linux/mtd/partitions.h> 21#include <linux/mtd/partitions.h>
22#include <linux/mtd/concat.h> 22#include <linux/mtd/concat.h>
23 23
24#include <asm/hardware.h>
24#include <asm/io.h> 25#include <asm/io.h>
25#include <asm/sizes.h> 26#include <asm/sizes.h>
26#include <asm/mach/flash.h> 27#include <asm/mach/flash.h>
@@ -129,20 +130,21 @@ struct sa_subdev_info {
129 char name[16]; 130 char name[16];
130 struct map_info map; 131 struct map_info map;
131 struct mtd_info *mtd; 132 struct mtd_info *mtd;
132 struct flash_platform_data *data; 133 struct flash_platform_data *plat;
133}; 134};
134 135
135struct sa_info { 136struct sa_info {
136 struct mtd_partition *parts; 137 struct mtd_partition *parts;
137 struct mtd_info *mtd; 138 struct mtd_info *mtd;
138 int num_subdev; 139 int num_subdev;
140 unsigned int nr_parts;
139 struct sa_subdev_info subdev[0]; 141 struct sa_subdev_info subdev[0];
140}; 142};
141 143
142static void sa1100_set_vpp(struct map_info *map, int on) 144static void sa1100_set_vpp(struct map_info *map, int on)
143{ 145{
144 struct sa_subdev_info *subdev = container_of(map, struct sa_subdev_info, map); 146 struct sa_subdev_info *subdev = container_of(map, struct sa_subdev_info, map);
145 subdev->data->set_vpp(on); 147 subdev->plat->set_vpp(on);
146} 148}
147 149
148static void sa1100_destroy_subdev(struct sa_subdev_info *subdev) 150static void sa1100_destroy_subdev(struct sa_subdev_info *subdev)
@@ -186,7 +188,7 @@ static int sa1100_probe_subdev(struct sa_subdev_info *subdev, struct resource *r
186 goto out; 188 goto out;
187 } 189 }
188 190
189 if (subdev->data->set_vpp) 191 if (subdev->plat->set_vpp)
190 subdev->map.set_vpp = sa1100_set_vpp; 192 subdev->map.set_vpp = sa1100_set_vpp;
191 193
192 subdev->map.phys = phys; 194 subdev->map.phys = phys;
@@ -203,7 +205,7 @@ static int sa1100_probe_subdev(struct sa_subdev_info *subdev, struct resource *r
203 * Now let's probe for the actual flash. Do it here since 205 * Now let's probe for the actual flash. Do it here since
204 * specific machine settings might have been set above. 206 * specific machine settings might have been set above.
205 */ 207 */
206 subdev->mtd = do_map_probe(subdev->data->map_name, &subdev->map); 208 subdev->mtd = do_map_probe(subdev->plat->map_name, &subdev->map);
207 if (subdev->mtd == NULL) { 209 if (subdev->mtd == NULL) {
208 ret = -ENXIO; 210 ret = -ENXIO;
209 goto err; 211 goto err;
@@ -222,13 +224,17 @@ static int sa1100_probe_subdev(struct sa_subdev_info *subdev, struct resource *r
222 return ret; 224 return ret;
223} 225}
224 226
225static void sa1100_destroy(struct sa_info *info) 227static void sa1100_destroy(struct sa_info *info, struct flash_platform_data *plat)
226{ 228{
227 int i; 229 int i;
228 230
229 if (info->mtd) { 231 if (info->mtd) {
230 del_mtd_partitions(info->mtd); 232 if (info->nr_parts == 0)
231 233 del_mtd_device(info->mtd);
234#ifdef CONFIG_MTD_PARTITIONS
235 else
236 del_mtd_partitions(info->mtd);
237#endif
232#ifdef CONFIG_MTD_CONCAT 238#ifdef CONFIG_MTD_CONCAT
233 if (info->mtd != info->subdev[0].mtd) 239 if (info->mtd != info->subdev[0].mtd)
234 mtd_concat_destroy(info->mtd); 240 mtd_concat_destroy(info->mtd);
@@ -241,10 +247,13 @@ static void sa1100_destroy(struct sa_info *info)
241 for (i = info->num_subdev - 1; i >= 0; i--) 247 for (i = info->num_subdev - 1; i >= 0; i--)
242 sa1100_destroy_subdev(&info->subdev[i]); 248 sa1100_destroy_subdev(&info->subdev[i]);
243 kfree(info); 249 kfree(info);
250
251 if (plat->exit)
252 plat->exit();
244} 253}
245 254
246static struct sa_info *__init 255static struct sa_info *__init
247sa1100_setup_mtd(struct platform_device *pdev, struct flash_platform_data *flash) 256sa1100_setup_mtd(struct platform_device *pdev, struct flash_platform_data *plat)
248{ 257{
249 struct sa_info *info; 258 struct sa_info *info;
250 int nr, size, i, ret = 0; 259 int nr, size, i, ret = 0;
@@ -274,6 +283,12 @@ sa1100_setup_mtd(struct platform_device *pdev, struct flash_platform_data *flash
274 283
275 memset(info, 0, size); 284 memset(info, 0, size);
276 285
286 if (plat->init) {
287 ret = plat->init();
288 if (ret)
289 goto err;
290 }
291
277 /* 292 /*
278 * Claim and then map the memory regions. 293 * Claim and then map the memory regions.
279 */ 294 */
@@ -286,8 +301,8 @@ sa1100_setup_mtd(struct platform_device *pdev, struct flash_platform_data *flash
286 break; 301 break;
287 302
288 subdev->map.name = subdev->name; 303 subdev->map.name = subdev->name;
289 sprintf(subdev->name, "sa1100-%d", i); 304 sprintf(subdev->name, "%s-%d", plat->name, i);
290 subdev->data = flash; 305 subdev->plat = plat;
291 306
292 ret = sa1100_probe_subdev(subdev, res); 307 ret = sa1100_probe_subdev(subdev, res);
293 if (ret) 308 if (ret)
@@ -308,7 +323,7 @@ sa1100_setup_mtd(struct platform_device *pdev, struct flash_platform_data *flash
308 * otherwise fail. Either way, it'll be called "sa1100". 323 * otherwise fail. Either way, it'll be called "sa1100".
309 */ 324 */
310 if (info->num_subdev == 1) { 325 if (info->num_subdev == 1) {
311 strcpy(info->subdev[0].name, "sa1100"); 326 strcpy(info->subdev[0].name, plat->name);
312 info->mtd = info->subdev[0].mtd; 327 info->mtd = info->subdev[0].mtd;
313 ret = 0; 328 ret = 0;
314 } else if (info->num_subdev > 1) { 329 } else if (info->num_subdev > 1) {
@@ -321,7 +336,7 @@ sa1100_setup_mtd(struct platform_device *pdev, struct flash_platform_data *flash
321 cdev[i] = info->subdev[i].mtd; 336 cdev[i] = info->subdev[i].mtd;
322 337
323 info->mtd = mtd_concat_create(cdev, info->num_subdev, 338 info->mtd = mtd_concat_create(cdev, info->num_subdev,
324 "sa1100"); 339 plat->name);
325 if (info->mtd == NULL) 340 if (info->mtd == NULL)
326 ret = -ENXIO; 341 ret = -ENXIO;
327#else 342#else
@@ -335,7 +350,7 @@ sa1100_setup_mtd(struct platform_device *pdev, struct flash_platform_data *flash
335 return info; 350 return info;
336 351
337 err: 352 err:
338 sa1100_destroy(info); 353 sa1100_destroy(info, plat);
339 out: 354 out:
340 return ERR_PTR(ret); 355 return ERR_PTR(ret);
341} 356}
@@ -345,16 +360,16 @@ static const char *part_probes[] = { "cmdlinepart", "RedBoot", NULL };
345static int __init sa1100_mtd_probe(struct device *dev) 360static int __init sa1100_mtd_probe(struct device *dev)
346{ 361{
347 struct platform_device *pdev = to_platform_device(dev); 362 struct platform_device *pdev = to_platform_device(dev);
348 struct flash_platform_data *flash = pdev->dev.platform_data; 363 struct flash_platform_data *plat = pdev->dev.platform_data;
349 struct mtd_partition *parts; 364 struct mtd_partition *parts;
350 const char *part_type = NULL; 365 const char *part_type = NULL;
351 struct sa_info *info; 366 struct sa_info *info;
352 int err, nr_parts = 0; 367 int err, nr_parts = 0;
353 368
354 if (!flash) 369 if (!plat)
355 return -ENODEV; 370 return -ENODEV;
356 371
357 info = sa1100_setup_mtd(pdev, flash); 372 info = sa1100_setup_mtd(pdev, plat);
358 if (IS_ERR(info)) { 373 if (IS_ERR(info)) {
359 err = PTR_ERR(info); 374 err = PTR_ERR(info);
360 goto out; 375 goto out;
@@ -371,8 +386,8 @@ static int __init sa1100_mtd_probe(struct device *dev)
371 } else 386 } else
372#endif 387#endif
373 { 388 {
374 parts = flash->parts; 389 parts = plat->parts;
375 nr_parts = flash->nr_parts; 390 nr_parts = plat->nr_parts;
376 part_type = "static"; 391 part_type = "static";
377 } 392 }
378 393
@@ -386,6 +401,8 @@ static int __init sa1100_mtd_probe(struct device *dev)
386 add_mtd_partitions(info->mtd, parts, nr_parts); 401 add_mtd_partitions(info->mtd, parts, nr_parts);
387 } 402 }
388 403
404 info->nr_parts = nr_parts;
405
389 dev_set_drvdata(dev, info); 406 dev_set_drvdata(dev, info);
390 err = 0; 407 err = 0;
391 408
@@ -396,33 +413,44 @@ static int __init sa1100_mtd_probe(struct device *dev)
396static int __exit sa1100_mtd_remove(struct device *dev) 413static int __exit sa1100_mtd_remove(struct device *dev)
397{ 414{
398 struct sa_info *info = dev_get_drvdata(dev); 415 struct sa_info *info = dev_get_drvdata(dev);
416 struct flash_platform_data *plat = dev->platform_data;
417
399 dev_set_drvdata(dev, NULL); 418 dev_set_drvdata(dev, NULL);
400 sa1100_destroy(info); 419 sa1100_destroy(info, plat);
420
401 return 0; 421 return 0;
402} 422}
403 423
404#ifdef CONFIG_PM 424#ifdef CONFIG_PM
405static int sa1100_mtd_suspend(struct device *dev, pm_message_t state, u32 level) 425static int sa1100_mtd_suspend(struct device *dev, pm_message_t state)
406{ 426{
407 struct sa_info *info = dev_get_drvdata(dev); 427 struct sa_info *info = dev_get_drvdata(dev);
408 int ret = 0; 428 int ret = 0;
409 429
410 if (info && level == SUSPEND_SAVE_STATE) 430 if (info)
411 ret = info->mtd->suspend(info->mtd); 431 ret = info->mtd->suspend(info->mtd);
412 432
413 return ret; 433 return ret;
414} 434}
415 435
416static int sa1100_mtd_resume(struct device *dev, u32 level) 436static int sa1100_mtd_resume(struct device *dev)
417{ 437{
418 struct sa_info *info = dev_get_drvdata(dev); 438 struct sa_info *info = dev_get_drvdata(dev);
419 if (info && level == RESUME_RESTORE_STATE) 439 if (info)
420 info->mtd->resume(info->mtd); 440 info->mtd->resume(info->mtd);
421 return 0; 441 return 0;
422} 442}
443
444static void sa1100_mtd_shutdown(struct device *dev)
445{
446 struct sa_info *info = dev_get_drvdata(dev);
447 if (info && info->mtd->suspend(info->mtd) == 0)
448 info->mtd->resume(info->mtd);
449}
423#else 450#else
424#define sa1100_mtd_suspend NULL 451#define sa1100_mtd_suspend NULL
425#define sa1100_mtd_resume NULL 452#define sa1100_mtd_resume NULL
453#define sa1100_mtd_shutdown NULL
426#endif 454#endif
427 455
428static struct device_driver sa1100_mtd_driver = { 456static struct device_driver sa1100_mtd_driver = {
@@ -432,6 +460,7 @@ static struct device_driver sa1100_mtd_driver = {
432 .remove = __exit_p(sa1100_mtd_remove), 460 .remove = __exit_p(sa1100_mtd_remove),
433 .suspend = sa1100_mtd_suspend, 461 .suspend = sa1100_mtd_suspend,
434 .resume = sa1100_mtd_resume, 462 .resume = sa1100_mtd_resume,
463 .shutdown = sa1100_mtd_shutdown,
435}; 464};
436 465
437static int __init sa1100_mtd_init(void) 466static int __init sa1100_mtd_init(void)
diff --git a/drivers/mtd/maps/tqm8xxl.c b/drivers/mtd/maps/tqm8xxl.c
index 995e9991cb8d..4e28b977f224 100644
--- a/drivers/mtd/maps/tqm8xxl.c
+++ b/drivers/mtd/maps/tqm8xxl.c
@@ -27,12 +27,14 @@
27#include <linux/types.h> 27#include <linux/types.h>
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/init.h> 29#include <linux/init.h>
30#include <asm/io.h> 30#include <linux/slab.h>
31 31
32#include <linux/mtd/mtd.h> 32#include <linux/mtd/mtd.h>
33#include <linux/mtd/map.h> 33#include <linux/mtd/map.h>
34#include <linux/mtd/partitions.h> 34#include <linux/mtd/partitions.h>
35 35
36#include <asm/io.h>
37
36#define FLASH_ADDR 0x40000000 38#define FLASH_ADDR 0x40000000
37#define FLASH_SIZE 0x00800000 39#define FLASH_SIZE 0x00800000
38#define FLASH_BANK_MAX 4 40#define FLASH_BANK_MAX 4
diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
index b7c32c242bc7..400dd9c89883 100644
--- a/drivers/mtd/mtdblock.c
+++ b/drivers/mtd/mtdblock.c
@@ -15,6 +15,7 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/vmalloc.h> 17#include <linux/vmalloc.h>
18#include <linux/sched.h> /* TASK_* */
18#include <linux/mtd/mtd.h> 19#include <linux/mtd/mtd.h>
19#include <linux/mtd/blktrans.h> 20#include <linux/mtd/blktrans.h>
20 21
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 1ed602a0f24c..16df1e4fb0e9 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -13,6 +13,7 @@
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/fs.h> 15#include <linux/fs.h>
16#include <linux/sched.h> /* TASK_* */
16#include <asm/uaccess.h> 17#include <asm/uaccess.h>
17 18
18#include <linux/device.h> 19#include <linux/device.h>
@@ -24,10 +25,10 @@ static void mtd_notify_add(struct mtd_info* mtd)
24 if (!mtd) 25 if (!mtd)
25 return; 26 return;
26 27
27 class_device_create(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2), 28 class_device_create(mtd_class, NULL, MKDEV(MTD_CHAR_MAJOR, mtd->index*2),
28 NULL, "mtd%d", mtd->index); 29 NULL, "mtd%d", mtd->index);
29 30
30 class_device_create(mtd_class, 31 class_device_create(mtd_class, NULL,
31 MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1), 32 MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1),
32 NULL, "mtd%dro", mtd->index); 33 NULL, "mtd%dro", mtd->index);
33} 34}
diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index 8f66d093c80d..f3e65af33a9c 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -14,7 +14,7 @@
14#include <linux/types.h> 14#include <linux/types.h>
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17 17#include <linux/sched.h> /* TASK_* */
18#include <linux/mtd/mtd.h> 18#include <linux/mtd/mtd.h>
19#include <linux/mtd/concat.h> 19#include <linux/mtd/concat.h>
20 20
diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
index b47ebcb31e0f..b58ba236a9eb 100644
--- a/drivers/mtd/nand/s3c2410.c
+++ b/drivers/mtd/nand/s3c2410.c
@@ -51,6 +51,7 @@
51#include <linux/device.h> 51#include <linux/device.h>
52#include <linux/delay.h> 52#include <linux/delay.h>
53#include <linux/err.h> 53#include <linux/err.h>
54#include <linux/slab.h>
54 55
55#include <linux/mtd/mtd.h> 56#include <linux/mtd/mtd.h>
56#include <linux/mtd/nand.h> 57#include <linux/mtd/nand.h>
diff --git a/drivers/net/8139cp.c b/drivers/net/8139cp.c
index bc537440ca02..f822cd3025ff 100644
--- a/drivers/net/8139cp.c
+++ b/drivers/net/8139cp.c
@@ -1027,8 +1027,7 @@ static void cp_reset_hw (struct cp_private *cp)
1027 if (!(cpr8(Cmd) & CmdReset)) 1027 if (!(cpr8(Cmd) & CmdReset))
1028 return; 1028 return;
1029 1029
1030 set_current_state(TASK_UNINTERRUPTIBLE); 1030 schedule_timeout_uninterruptible(10);
1031 schedule_timeout(10);
1032 } 1031 }
1033 1032
1034 printk(KERN_ERR "%s: hardware reset timeout\n", cp->dev->name); 1033 printk(KERN_ERR "%s: hardware reset timeout\n", cp->dev->name);
@@ -1575,6 +1574,7 @@ static struct ethtool_ops cp_ethtool_ops = {
1575 .set_wol = cp_set_wol, 1574 .set_wol = cp_set_wol,
1576 .get_strings = cp_get_strings, 1575 .get_strings = cp_get_strings,
1577 .get_ethtool_stats = cp_get_ethtool_stats, 1576 .get_ethtool_stats = cp_get_ethtool_stats,
1577 .get_perm_addr = ethtool_op_get_perm_addr,
1578}; 1578};
1579 1579
1580static int cp_ioctl (struct net_device *dev, struct ifreq *rq, int cmd) 1580static int cp_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
@@ -1773,6 +1773,7 @@ static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1773 for (i = 0; i < 3; i++) 1773 for (i = 0; i < 3; i++)
1774 ((u16 *) (dev->dev_addr))[i] = 1774 ((u16 *) (dev->dev_addr))[i] =
1775 le16_to_cpu (read_eeprom (regs, i + 7, addr_len)); 1775 le16_to_cpu (read_eeprom (regs, i + 7, addr_len));
1776 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
1776 1777
1777 dev->open = cp_open; 1778 dev->open = cp_open;
1778 dev->stop = cp_close; 1779 dev->stop = cp_close;
diff --git a/drivers/net/8139too.c b/drivers/net/8139too.c
index 4c2cf7bbd252..30bee11c48bd 100644
--- a/drivers/net/8139too.c
+++ b/drivers/net/8139too.c
@@ -552,7 +552,8 @@ const static struct {
552 552
553 { "RTL-8100B/8139D", 553 { "RTL-8100B/8139D",
554 HW_REVID(1, 1, 1, 0, 1, 0, 1), 554 HW_REVID(1, 1, 1, 0, 1, 0, 1),
555 HasLWake, 555 HasHltClk /* XXX undocumented? */
556 | HasLWake,
556 }, 557 },
557 558
558 { "RTL-8101", 559 { "RTL-8101",
@@ -970,6 +971,7 @@ static int __devinit rtl8139_init_one (struct pci_dev *pdev,
970 for (i = 0; i < 3; i++) 971 for (i = 0; i < 3; i++)
971 ((u16 *) (dev->dev_addr))[i] = 972 ((u16 *) (dev->dev_addr))[i] =
972 le16_to_cpu (read_eeprom (ioaddr, i + 7, addr_len)); 973 le16_to_cpu (read_eeprom (ioaddr, i + 7, addr_len));
974 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
973 975
974 /* The Rtl8139-specific entries in the device structure. */ 976 /* The Rtl8139-specific entries in the device structure. */
975 dev->open = rtl8139_open; 977 dev->open = rtl8139_open;
@@ -2465,6 +2467,7 @@ static struct ethtool_ops rtl8139_ethtool_ops = {
2465 .get_strings = rtl8139_get_strings, 2467 .get_strings = rtl8139_get_strings,
2466 .get_stats_count = rtl8139_get_stats_count, 2468 .get_stats_count = rtl8139_get_stats_count,
2467 .get_ethtool_stats = rtl8139_get_ethtool_stats, 2469 .get_ethtool_stats = rtl8139_get_ethtool_stats,
2470 .get_perm_addr = ethtool_op_get_perm_addr,
2468}; 2471};
2469 2472
2470static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 2473static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index c748b0e16419..6d4f9ceb0a32 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -475,6 +475,14 @@ config SGI_IOC3_ETH_HW_TX_CSUM
475 the moment only acceleration of IPv4 is supported. This option 475 the moment only acceleration of IPv4 is supported. This option
476 enables offloading for checksums on transmit. If unsure, say Y. 476 enables offloading for checksums on transmit. If unsure, say Y.
477 477
478config MIPS_SIM_NET
479 tristate "MIPS simulator Network device (EXPERIMENTAL)"
480 depends on NETDEVICES && MIPS_SIM && EXPERIMENTAL
481 help
482 The MIPSNET device is a simple Ethernet network device which is
483 emulated by the MIPS Simulator.
484 If you are not using a MIPSsim or are unsure, say N.
485
478config SGI_O2MACE_ETH 486config SGI_O2MACE_ETH
479 tristate "SGI O2 MACE Fast Ethernet support" 487 tristate "SGI O2 MACE Fast Ethernet support"
480 depends on NET_ETHERNET && SGI_IP32=y 488 depends on NET_ETHERNET && SGI_IP32=y
@@ -1155,38 +1163,74 @@ config IBMVETH
1155 be called ibmveth. 1163 be called ibmveth.
1156 1164
1157config IBM_EMAC 1165config IBM_EMAC
1158 bool "IBM PPC4xx EMAC driver support" 1166 tristate "PowerPC 4xx on-chip Ethernet support"
1159 depends on 4xx 1167 depends on 4xx
1160 select CRC32 1168 help
1161 ---help--- 1169 This driver supports the PowerPC 4xx EMAC family of on-chip
1162 This driver supports the IBM PPC4xx EMAC family of on-chip 1170 Ethernet controllers.
1163 Ethernet controllers.
1164
1165config IBM_EMAC_ERRMSG
1166 bool "Verbose error messages"
1167 depends on IBM_EMAC && BROKEN
1168 1171
1169config IBM_EMAC_RXB 1172config IBM_EMAC_RXB
1170 int "Number of receive buffers" 1173 int "Number of receive buffers"
1171 depends on IBM_EMAC 1174 depends on IBM_EMAC
1172 default "128" if IBM_EMAC4 1175 default "128"
1173 default "64"
1174 1176
1175config IBM_EMAC_TXB 1177config IBM_EMAC_TXB
1176 int "Number of transmit buffers" 1178 int "Number of transmit buffers"
1177 depends on IBM_EMAC 1179 depends on IBM_EMAC
1178 default "128" if IBM_EMAC4 1180 default "64"
1179 default "8" 1181
1182config IBM_EMAC_POLL_WEIGHT
1183 int "MAL NAPI polling weight"
1184 depends on IBM_EMAC
1185 default "32"
1180 1186
1181config IBM_EMAC_FGAP 1187config IBM_EMAC_RX_COPY_THRESHOLD
1182 int "Frame gap" 1188 int "RX skb copy threshold (bytes)"
1183 depends on IBM_EMAC 1189 depends on IBM_EMAC
1184 default "8" 1190 default "256"
1185 1191
1186config IBM_EMAC_SKBRES 1192config IBM_EMAC_RX_SKB_HEADROOM
1187 int "Skb reserve amount" 1193 int "Additional RX skb headroom (bytes)"
1188 depends on IBM_EMAC 1194 depends on IBM_EMAC
1189 default "0" 1195 default "0"
1196 help
1197 Additional receive skb headroom. Note, that driver
1198 will always reserve at least 2 bytes to make IP header
1199 aligned, so usualy there is no need to add any additional
1200 headroom.
1201
1202 If unsure, set to 0.
1203
1204config IBM_EMAC_PHY_RX_CLK_FIX
1205 bool "PHY Rx clock workaround"
1206 depends on IBM_EMAC && (405EP || 440GX || 440EP)
1207 help
1208 Enable this if EMAC attached to a PHY which doesn't generate
1209 RX clock if there is no link, if this is the case, you will
1210 see "TX disable timeout" or "RX disable timeout" in the system
1211 log.
1212
1213 If unsure, say N.
1214
1215config IBM_EMAC_DEBUG
1216 bool "Debugging"
1217 depends on IBM_EMAC
1218 default n
1219
1220config IBM_EMAC_ZMII
1221 bool
1222 depends on IBM_EMAC && (NP405H || NP405L || 44x)
1223 default y
1224
1225config IBM_EMAC_RGMII
1226 bool
1227 depends on IBM_EMAC && 440GX
1228 default y
1229
1230config IBM_EMAC_TAH
1231 bool
1232 depends on IBM_EMAC && 440GX
1233 default y
1190 1234
1191config NET_PCI 1235config NET_PCI
1192 bool "EISA, VLB, PCI and on board controllers" 1236 bool "EISA, VLB, PCI and on board controllers"
@@ -1330,7 +1374,7 @@ config FORCEDETH
1330 1374
1331config CS89x0 1375config CS89x0
1332 tristate "CS89x0 support" 1376 tristate "CS89x0 support"
1333 depends on (NET_PCI && (ISA || ARCH_IXDP2X01)) || ARCH_PNX0105 1377 depends on (NET_PCI && (ISA || ARCH_IXDP2X01)) || ARCH_PNX0105 || MACH_MP1000
1334 ---help--- 1378 ---help---
1335 Support for CS89x0 chipset based Ethernet cards. If you have a 1379 Support for CS89x0 chipset based Ethernet cards. If you have a
1336 network (Ethernet) card of this type, say Y and read the 1380 network (Ethernet) card of this type, say Y and read the
@@ -1767,6 +1811,7 @@ config NE_H8300
1767 controller on the Renesas H8/300 processor. 1811 controller on the Renesas H8/300 processor.
1768 1812
1769source "drivers/net/fec_8xx/Kconfig" 1813source "drivers/net/fec_8xx/Kconfig"
1814source "drivers/net/fs_enet/Kconfig"
1770 1815
1771endmenu 1816endmenu
1772 1817
@@ -2083,6 +2128,7 @@ config SPIDER_NET
2083config GIANFAR 2128config GIANFAR
2084 tristate "Gianfar Ethernet" 2129 tristate "Gianfar Ethernet"
2085 depends on 85xx || 83xx 2130 depends on 85xx || 83xx
2131 select PHYLIB
2086 help 2132 help
2087 This driver supports the Gigabit TSEC on the MPC85xx 2133 This driver supports the Gigabit TSEC on the MPC85xx
2088 family of chips, and the FEC on the 8540 2134 family of chips, and the FEC on the 8540
@@ -2192,8 +2238,8 @@ config S2IO
2192 depends on PCI 2238 depends on PCI
2193 ---help--- 2239 ---help---
2194 This driver supports the 10Gbe XFrame NIC of S2IO. 2240 This driver supports the 10Gbe XFrame NIC of S2IO.
2195 For help regarding driver compilation, installation and 2241 More specific information on configuring the driver is in
2196 tuning please look into ~/drivers/net/s2io/README.txt. 2242 <file:Documentation/networking/s2io.txt>.
2197 2243
2198config S2IO_NAPI 2244config S2IO_NAPI
2199 bool "Use Rx Polling (NAPI) (EXPERIMENTAL)" 2245 bool "Use Rx Polling (NAPI) (EXPERIMENTAL)"
@@ -2243,6 +2289,20 @@ config ISERIES_VETH
2243 tristate "iSeries Virtual Ethernet driver support" 2289 tristate "iSeries Virtual Ethernet driver support"
2244 depends on PPC_ISERIES 2290 depends on PPC_ISERIES
2245 2291
2292config RIONET
2293 tristate "RapidIO Ethernet over messaging driver support"
2294 depends on NETDEVICES && RAPIDIO
2295
2296config RIONET_TX_SIZE
2297 int "Number of outbound queue entries"
2298 depends on RIONET
2299 default "128"
2300
2301config RIONET_RX_SIZE
2302 int "Number of inbound queue entries"
2303 depends on RIONET
2304 default "128"
2305
2246config FDDI 2306config FDDI
2247 bool "FDDI driver support" 2307 bool "FDDI driver support"
2248 depends on (PCI || EISA) 2308 depends on (PCI || EISA)
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index 8aeec9f2495b..7c313cb341b8 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -13,7 +13,7 @@ obj-$(CONFIG_CHELSIO_T1) += chelsio/
13obj-$(CONFIG_BONDING) += bonding/ 13obj-$(CONFIG_BONDING) += bonding/
14obj-$(CONFIG_GIANFAR) += gianfar_driver.o 14obj-$(CONFIG_GIANFAR) += gianfar_driver.o
15 15
16gianfar_driver-objs := gianfar.o gianfar_ethtool.o gianfar_phy.o 16gianfar_driver-objs := gianfar.o gianfar_ethtool.o gianfar_mii.o
17 17
18# 18#
19# link order important here 19# link order important here
@@ -64,6 +64,7 @@ obj-$(CONFIG_SKFP) += skfp/
64obj-$(CONFIG_VIA_RHINE) += via-rhine.o 64obj-$(CONFIG_VIA_RHINE) += via-rhine.o
65obj-$(CONFIG_VIA_VELOCITY) += via-velocity.o 65obj-$(CONFIG_VIA_VELOCITY) += via-velocity.o
66obj-$(CONFIG_ADAPTEC_STARFIRE) += starfire.o 66obj-$(CONFIG_ADAPTEC_STARFIRE) += starfire.o
67obj-$(CONFIG_RIONET) += rionet.o
67 68
68# 69#
69# end link order section 70# end link order section
@@ -166,6 +167,7 @@ obj-$(CONFIG_EQUALIZER) += eql.o
166obj-$(CONFIG_MIPS_JAZZ_SONIC) += jazzsonic.o 167obj-$(CONFIG_MIPS_JAZZ_SONIC) += jazzsonic.o
167obj-$(CONFIG_MIPS_GT96100ETH) += gt96100eth.o 168obj-$(CONFIG_MIPS_GT96100ETH) += gt96100eth.o
168obj-$(CONFIG_MIPS_AU1X00_ENET) += au1000_eth.o 169obj-$(CONFIG_MIPS_AU1X00_ENET) += au1000_eth.o
170obj-$(CONFIG_MIPS_SIM_NET) += mipsnet.o
169obj-$(CONFIG_SGI_IOC3_ETH) += ioc3-eth.o 171obj-$(CONFIG_SGI_IOC3_ETH) += ioc3-eth.o
170obj-$(CONFIG_DECLANCE) += declance.o 172obj-$(CONFIG_DECLANCE) += declance.o
171obj-$(CONFIG_ATARILANCE) += atarilance.o 173obj-$(CONFIG_ATARILANCE) += atarilance.o
@@ -201,3 +203,6 @@ obj-$(CONFIG_IRDA) += irda/
201obj-$(CONFIG_ETRAX_ETHERNET) += cris/ 203obj-$(CONFIG_ETRAX_ETHERNET) += cris/
202 204
203obj-$(CONFIG_NETCONSOLE) += netconsole.o 205obj-$(CONFIG_NETCONSOLE) += netconsole.o
206
207obj-$(CONFIG_FS_ENET) += fs_enet/
208
diff --git a/drivers/net/acenic.c b/drivers/net/acenic.c
index dbecc6bf7851..b8953de5664a 100644
--- a/drivers/net/acenic.c
+++ b/drivers/net/acenic.c
@@ -871,10 +871,8 @@ static void ace_init_cleanup(struct net_device *dev)
871 if (ap->info) 871 if (ap->info)
872 pci_free_consistent(ap->pdev, sizeof(struct ace_info), 872 pci_free_consistent(ap->pdev, sizeof(struct ace_info),
873 ap->info, ap->info_dma); 873 ap->info, ap->info_dma);
874 if (ap->skb) 874 kfree(ap->skb);
875 kfree(ap->skb); 875 kfree(ap->trace_buf);
876 if (ap->trace_buf)
877 kfree(ap->trace_buf);
878 876
879 if (dev->irq) 877 if (dev->irq)
880 free_irq(dev->irq, dev); 878 free_irq(dev->irq, dev);
diff --git a/drivers/net/amd8111e.c b/drivers/net/amd8111e.c
index d9ba8be72af8..d9ba8be72af8 100755..100644
--- a/drivers/net/amd8111e.c
+++ b/drivers/net/amd8111e.c
diff --git a/drivers/net/amd8111e.h b/drivers/net/amd8111e.h
index cfe3a4298822..cfe3a4298822 100755..100644
--- a/drivers/net/amd8111e.h
+++ b/drivers/net/amd8111e.h
diff --git a/drivers/net/arm/am79c961a.c b/drivers/net/arm/am79c961a.c
index c56d86d371a9..3d50e953faaa 100644
--- a/drivers/net/arm/am79c961a.c
+++ b/drivers/net/arm/am79c961a.c
@@ -29,6 +29,7 @@
29 29
30#include <asm/system.h> 30#include <asm/system.h>
31#include <asm/irq.h> 31#include <asm/irq.h>
32#include <asm/hardware.h>
32#include <asm/io.h> 33#include <asm/io.h>
33 34
34#define TX_BUFFERS 15 35#define TX_BUFFERS 15
diff --git a/drivers/net/au1000_eth.c b/drivers/net/au1000_eth.c
index c82b9cd1c924..332e9953c55c 100644
--- a/drivers/net/au1000_eth.c
+++ b/drivers/net/au1000_eth.c
@@ -151,13 +151,6 @@ struct au1000_private *au_macs[NUM_ETH_INTERFACES];
151 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full | \ 151 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full | \
152 SUPPORTED_Autoneg 152 SUPPORTED_Autoneg
153 153
154static char *phy_link[] =
155{ "unknown",
156 "10Base2", "10BaseT",
157 "AUI",
158 "100BaseT", "100BaseTX", "100BaseFX"
159};
160
161int bcm_5201_init(struct net_device *dev, int phy_addr) 154int bcm_5201_init(struct net_device *dev, int phy_addr)
162{ 155{
163 s16 data; 156 s16 data;
@@ -785,6 +778,7 @@ static struct mii_chip_info {
785 {"Broadcom BCM5201 10/100 BaseT PHY",0x0040,0x6212, &bcm_5201_ops,0}, 778 {"Broadcom BCM5201 10/100 BaseT PHY",0x0040,0x6212, &bcm_5201_ops,0},
786 {"Broadcom BCM5221 10/100 BaseT PHY",0x0040,0x61e4, &bcm_5201_ops,0}, 779 {"Broadcom BCM5221 10/100 BaseT PHY",0x0040,0x61e4, &bcm_5201_ops,0},
787 {"Broadcom BCM5222 10/100 BaseT PHY",0x0040,0x6322, &bcm_5201_ops,1}, 780 {"Broadcom BCM5222 10/100 BaseT PHY",0x0040,0x6322, &bcm_5201_ops,1},
781 {"NS DP83847 PHY", 0x2000, 0x5c30, &bcm_5201_ops ,0},
788 {"AMD 79C901 HomePNA PHY",0x0000,0x35c8, &am79c901_ops,0}, 782 {"AMD 79C901 HomePNA PHY",0x0000,0x35c8, &am79c901_ops,0},
789 {"AMD 79C874 10/100 BaseT PHY",0x0022,0x561b, &am79c874_ops,0}, 783 {"AMD 79C874 10/100 BaseT PHY",0x0022,0x561b, &am79c874_ops,0},
790 {"LSI 80227 10/100 BaseT PHY",0x0016,0xf840, &lsi_80227_ops,0}, 784 {"LSI 80227 10/100 BaseT PHY",0x0016,0xf840, &lsi_80227_ops,0},
@@ -1045,7 +1039,7 @@ found:
1045#endif 1039#endif
1046 1040
1047 if (aup->mii->chip_info == NULL) { 1041 if (aup->mii->chip_info == NULL) {
1048 printk(KERN_ERR "%s: Au1x No MII transceivers found!\n", 1042 printk(KERN_ERR "%s: Au1x No known MII transceivers found!\n",
1049 dev->name); 1043 dev->name);
1050 return -1; 1044 return -1;
1051 } 1045 }
@@ -1546,6 +1540,9 @@ au1000_probe(u32 ioaddr, int irq, int port_num)
1546 printk(KERN_ERR "%s: out of memory\n", dev->name); 1540 printk(KERN_ERR "%s: out of memory\n", dev->name);
1547 goto err_out; 1541 goto err_out;
1548 } 1542 }
1543 aup->mii->next = NULL;
1544 aup->mii->chip_info = NULL;
1545 aup->mii->status = 0;
1549 aup->mii->mii_control_reg = 0; 1546 aup->mii->mii_control_reg = 0;
1550 aup->mii->mii_data_reg = 0; 1547 aup->mii->mii_data_reg = 0;
1551 1548
@@ -1609,8 +1606,7 @@ err_out:
1609 /* here we should have a valid dev plus aup-> register addresses 1606 /* here we should have a valid dev plus aup-> register addresses
1610 * so we can reset the mac properly.*/ 1607 * so we can reset the mac properly.*/
1611 reset_mac(dev); 1608 reset_mac(dev);
1612 if (aup->mii) 1609 kfree(aup->mii);
1613 kfree(aup->mii);
1614 for (i = 0; i < NUM_RX_DMA; i++) { 1610 for (i = 0; i < NUM_RX_DMA; i++) {
1615 if (aup->rx_db_inuse[i]) 1611 if (aup->rx_db_inuse[i])
1616 ReleaseDB(aup, aup->rx_db_inuse[i]); 1612 ReleaseDB(aup, aup->rx_db_inuse[i]);
@@ -1809,8 +1805,7 @@ static void __exit au1000_cleanup_module(void)
1809 if (dev) { 1805 if (dev) {
1810 aup = (struct au1000_private *) dev->priv; 1806 aup = (struct au1000_private *) dev->priv;
1811 unregister_netdev(dev); 1807 unregister_netdev(dev);
1812 if (aup->mii) 1808 kfree(aup->mii);
1813 kfree(aup->mii);
1814 for (j = 0; j < NUM_RX_DMA; j++) { 1809 for (j = 0; j < NUM_RX_DMA; j++) {
1815 if (aup->rx_db_inuse[j]) 1810 if (aup->rx_db_inuse[j])
1816 ReleaseDB(aup, aup->rx_db_inuse[j]); 1811 ReleaseDB(aup, aup->rx_db_inuse[j]);
diff --git a/drivers/net/b44.c b/drivers/net/b44.c
index 94939f570f78..0ee3e27969c6 100644
--- a/drivers/net/b44.c
+++ b/drivers/net/b44.c
@@ -19,6 +19,7 @@
19#include <linux/delay.h> 19#include <linux/delay.h>
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/version.h> 21#include <linux/version.h>
22#include <linux/dma-mapping.h>
22 23
23#include <asm/uaccess.h> 24#include <asm/uaccess.h>
24#include <asm/io.h> 25#include <asm/io.h>
@@ -106,6 +107,29 @@ static int b44_poll(struct net_device *dev, int *budget);
106static void b44_poll_controller(struct net_device *dev); 107static void b44_poll_controller(struct net_device *dev);
107#endif 108#endif
108 109
110static int dma_desc_align_mask;
111static int dma_desc_sync_size;
112
113static inline void b44_sync_dma_desc_for_device(struct pci_dev *pdev,
114 dma_addr_t dma_base,
115 unsigned long offset,
116 enum dma_data_direction dir)
117{
118 dma_sync_single_range_for_device(&pdev->dev, dma_base,
119 offset & dma_desc_align_mask,
120 dma_desc_sync_size, dir);
121}
122
123static inline void b44_sync_dma_desc_for_cpu(struct pci_dev *pdev,
124 dma_addr_t dma_base,
125 unsigned long offset,
126 enum dma_data_direction dir)
127{
128 dma_sync_single_range_for_cpu(&pdev->dev, dma_base,
129 offset & dma_desc_align_mask,
130 dma_desc_sync_size, dir);
131}
132
109static inline unsigned long br32(const struct b44 *bp, unsigned long reg) 133static inline unsigned long br32(const struct b44 *bp, unsigned long reg)
110{ 134{
111 return readl(bp->regs + reg); 135 return readl(bp->regs + reg);
@@ -668,6 +692,11 @@ static int b44_alloc_rx_skb(struct b44 *bp, int src_idx, u32 dest_idx_unmasked)
668 dp->ctrl = cpu_to_le32(ctrl); 692 dp->ctrl = cpu_to_le32(ctrl);
669 dp->addr = cpu_to_le32((u32) mapping + bp->rx_offset + bp->dma_offset); 693 dp->addr = cpu_to_le32((u32) mapping + bp->rx_offset + bp->dma_offset);
670 694
695 if (bp->flags & B44_FLAG_RX_RING_HACK)
696 b44_sync_dma_desc_for_device(bp->pdev, bp->rx_ring_dma,
697 dest_idx * sizeof(dp),
698 DMA_BIDIRECTIONAL);
699
671 return RX_PKT_BUF_SZ; 700 return RX_PKT_BUF_SZ;
672} 701}
673 702
@@ -692,6 +721,11 @@ static void b44_recycle_rx(struct b44 *bp, int src_idx, u32 dest_idx_unmasked)
692 pci_unmap_addr_set(dest_map, mapping, 721 pci_unmap_addr_set(dest_map, mapping,
693 pci_unmap_addr(src_map, mapping)); 722 pci_unmap_addr(src_map, mapping));
694 723
724 if (bp->flags & B44_FLAG_RX_RING_HACK)
725 b44_sync_dma_desc_for_cpu(bp->pdev, bp->rx_ring_dma,
726 src_idx * sizeof(src_desc),
727 DMA_BIDIRECTIONAL);
728
695 ctrl = src_desc->ctrl; 729 ctrl = src_desc->ctrl;
696 if (dest_idx == (B44_RX_RING_SIZE - 1)) 730 if (dest_idx == (B44_RX_RING_SIZE - 1))
697 ctrl |= cpu_to_le32(DESC_CTRL_EOT); 731 ctrl |= cpu_to_le32(DESC_CTRL_EOT);
@@ -700,8 +734,14 @@ static void b44_recycle_rx(struct b44 *bp, int src_idx, u32 dest_idx_unmasked)
700 734
701 dest_desc->ctrl = ctrl; 735 dest_desc->ctrl = ctrl;
702 dest_desc->addr = src_desc->addr; 736 dest_desc->addr = src_desc->addr;
737
703 src_map->skb = NULL; 738 src_map->skb = NULL;
704 739
740 if (bp->flags & B44_FLAG_RX_RING_HACK)
741 b44_sync_dma_desc_for_device(bp->pdev, bp->rx_ring_dma,
742 dest_idx * sizeof(dest_desc),
743 DMA_BIDIRECTIONAL);
744
705 pci_dma_sync_single_for_device(bp->pdev, src_desc->addr, 745 pci_dma_sync_single_for_device(bp->pdev, src_desc->addr,
706 RX_PKT_BUF_SZ, 746 RX_PKT_BUF_SZ,
707 PCI_DMA_FROMDEVICE); 747 PCI_DMA_FROMDEVICE);
@@ -959,6 +999,11 @@ static int b44_start_xmit(struct sk_buff *skb, struct net_device *dev)
959 bp->tx_ring[entry].ctrl = cpu_to_le32(ctrl); 999 bp->tx_ring[entry].ctrl = cpu_to_le32(ctrl);
960 bp->tx_ring[entry].addr = cpu_to_le32((u32) mapping+bp->dma_offset); 1000 bp->tx_ring[entry].addr = cpu_to_le32((u32) mapping+bp->dma_offset);
961 1001
1002 if (bp->flags & B44_FLAG_TX_RING_HACK)
1003 b44_sync_dma_desc_for_device(bp->pdev, bp->tx_ring_dma,
1004 entry * sizeof(bp->tx_ring[0]),
1005 DMA_TO_DEVICE);
1006
962 entry = NEXT_TX(entry); 1007 entry = NEXT_TX(entry);
963 1008
964 bp->tx_prod = entry; 1009 bp->tx_prod = entry;
@@ -1064,6 +1109,16 @@ static void b44_init_rings(struct b44 *bp)
1064 memset(bp->rx_ring, 0, B44_RX_RING_BYTES); 1109 memset(bp->rx_ring, 0, B44_RX_RING_BYTES);
1065 memset(bp->tx_ring, 0, B44_TX_RING_BYTES); 1110 memset(bp->tx_ring, 0, B44_TX_RING_BYTES);
1066 1111
1112 if (bp->flags & B44_FLAG_RX_RING_HACK)
1113 dma_sync_single_for_device(&bp->pdev->dev, bp->rx_ring_dma,
1114 DMA_TABLE_BYTES,
1115 PCI_DMA_BIDIRECTIONAL);
1116
1117 if (bp->flags & B44_FLAG_TX_RING_HACK)
1118 dma_sync_single_for_device(&bp->pdev->dev, bp->tx_ring_dma,
1119 DMA_TABLE_BYTES,
1120 PCI_DMA_TODEVICE);
1121
1067 for (i = 0; i < bp->rx_pending; i++) { 1122 for (i = 0; i < bp->rx_pending; i++) {
1068 if (b44_alloc_rx_skb(bp, -1, i) < 0) 1123 if (b44_alloc_rx_skb(bp, -1, i) < 0)
1069 break; 1124 break;
@@ -1076,23 +1131,33 @@ static void b44_init_rings(struct b44 *bp)
1076 */ 1131 */
1077static void b44_free_consistent(struct b44 *bp) 1132static void b44_free_consistent(struct b44 *bp)
1078{ 1133{
1079 if (bp->rx_buffers) { 1134 kfree(bp->rx_buffers);
1080 kfree(bp->rx_buffers); 1135 bp->rx_buffers = NULL;
1081 bp->rx_buffers = NULL; 1136 kfree(bp->tx_buffers);
1082 } 1137 bp->tx_buffers = NULL;
1083 if (bp->tx_buffers) {
1084 kfree(bp->tx_buffers);
1085 bp->tx_buffers = NULL;
1086 }
1087 if (bp->rx_ring) { 1138 if (bp->rx_ring) {
1088 pci_free_consistent(bp->pdev, DMA_TABLE_BYTES, 1139 if (bp->flags & B44_FLAG_RX_RING_HACK) {
1089 bp->rx_ring, bp->rx_ring_dma); 1140 dma_unmap_single(&bp->pdev->dev, bp->rx_ring_dma,
1141 DMA_TABLE_BYTES,
1142 DMA_BIDIRECTIONAL);
1143 kfree(bp->rx_ring);
1144 } else
1145 pci_free_consistent(bp->pdev, DMA_TABLE_BYTES,
1146 bp->rx_ring, bp->rx_ring_dma);
1090 bp->rx_ring = NULL; 1147 bp->rx_ring = NULL;
1148 bp->flags &= ~B44_FLAG_RX_RING_HACK;
1091 } 1149 }
1092 if (bp->tx_ring) { 1150 if (bp->tx_ring) {
1093 pci_free_consistent(bp->pdev, DMA_TABLE_BYTES, 1151 if (bp->flags & B44_FLAG_TX_RING_HACK) {
1094 bp->tx_ring, bp->tx_ring_dma); 1152 dma_unmap_single(&bp->pdev->dev, bp->tx_ring_dma,
1153 DMA_TABLE_BYTES,
1154 DMA_TO_DEVICE);
1155 kfree(bp->tx_ring);
1156 } else
1157 pci_free_consistent(bp->pdev, DMA_TABLE_BYTES,
1158 bp->tx_ring, bp->tx_ring_dma);
1095 bp->tx_ring = NULL; 1159 bp->tx_ring = NULL;
1160 bp->flags &= ~B44_FLAG_TX_RING_HACK;
1096 } 1161 }
1097} 1162}
1098 1163
@@ -1118,12 +1183,56 @@ static int b44_alloc_consistent(struct b44 *bp)
1118 1183
1119 size = DMA_TABLE_BYTES; 1184 size = DMA_TABLE_BYTES;
1120 bp->rx_ring = pci_alloc_consistent(bp->pdev, size, &bp->rx_ring_dma); 1185 bp->rx_ring = pci_alloc_consistent(bp->pdev, size, &bp->rx_ring_dma);
1121 if (!bp->rx_ring) 1186 if (!bp->rx_ring) {
1122 goto out_err; 1187 /* Allocation may have failed due to pci_alloc_consistent
1188 insisting on use of GFP_DMA, which is more restrictive
1189 than necessary... */
1190 struct dma_desc *rx_ring;
1191 dma_addr_t rx_ring_dma;
1192
1193 if (!(rx_ring = (struct dma_desc *)kmalloc(size, GFP_KERNEL)))
1194 goto out_err;
1195
1196 memset(rx_ring, 0, size);
1197 rx_ring_dma = dma_map_single(&bp->pdev->dev, rx_ring,
1198 DMA_TABLE_BYTES,
1199 DMA_BIDIRECTIONAL);
1200
1201 if (rx_ring_dma + size > B44_DMA_MASK) {
1202 kfree(rx_ring);
1203 goto out_err;
1204 }
1205
1206 bp->rx_ring = rx_ring;
1207 bp->rx_ring_dma = rx_ring_dma;
1208 bp->flags |= B44_FLAG_RX_RING_HACK;
1209 }
1123 1210
1124 bp->tx_ring = pci_alloc_consistent(bp->pdev, size, &bp->tx_ring_dma); 1211 bp->tx_ring = pci_alloc_consistent(bp->pdev, size, &bp->tx_ring_dma);
1125 if (!bp->tx_ring) 1212 if (!bp->tx_ring) {
1126 goto out_err; 1213 /* Allocation may have failed due to pci_alloc_consistent
1214 insisting on use of GFP_DMA, which is more restrictive
1215 than necessary... */
1216 struct dma_desc *tx_ring;
1217 dma_addr_t tx_ring_dma;
1218
1219 if (!(tx_ring = (struct dma_desc *)kmalloc(size, GFP_KERNEL)))
1220 goto out_err;
1221
1222 memset(tx_ring, 0, size);
1223 tx_ring_dma = dma_map_single(&bp->pdev->dev, tx_ring,
1224 DMA_TABLE_BYTES,
1225 DMA_TO_DEVICE);
1226
1227 if (tx_ring_dma + size > B44_DMA_MASK) {
1228 kfree(tx_ring);
1229 goto out_err;
1230 }
1231
1232 bp->tx_ring = tx_ring;
1233 bp->tx_ring_dma = tx_ring_dma;
1234 bp->flags |= B44_FLAG_TX_RING_HACK;
1235 }
1127 1236
1128 return 0; 1237 return 0;
1129 1238
@@ -1507,14 +1616,14 @@ static int b44_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
1507 1616
1508 cmd->advertising = 0; 1617 cmd->advertising = 0;
1509 if (bp->flags & B44_FLAG_ADV_10HALF) 1618 if (bp->flags & B44_FLAG_ADV_10HALF)
1510 cmd->advertising |= ADVERTISE_10HALF; 1619 cmd->advertising |= ADVERTISED_10baseT_Half;
1511 if (bp->flags & B44_FLAG_ADV_10FULL) 1620 if (bp->flags & B44_FLAG_ADV_10FULL)
1512 cmd->advertising |= ADVERTISE_10FULL; 1621 cmd->advertising |= ADVERTISED_10baseT_Full;
1513 if (bp->flags & B44_FLAG_ADV_100HALF) 1622 if (bp->flags & B44_FLAG_ADV_100HALF)
1514 cmd->advertising |= ADVERTISE_100HALF; 1623 cmd->advertising |= ADVERTISED_100baseT_Half;
1515 if (bp->flags & B44_FLAG_ADV_100FULL) 1624 if (bp->flags & B44_FLAG_ADV_100FULL)
1516 cmd->advertising |= ADVERTISE_100FULL; 1625 cmd->advertising |= ADVERTISED_100baseT_Full;
1517 cmd->advertising |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; 1626 cmd->advertising |= ADVERTISED_Pause | ADVERTISED_Asym_Pause;
1518 cmd->speed = (bp->flags & B44_FLAG_100_BASE_T) ? 1627 cmd->speed = (bp->flags & B44_FLAG_100_BASE_T) ?
1519 SPEED_100 : SPEED_10; 1628 SPEED_100 : SPEED_10;
1520 cmd->duplex = (bp->flags & B44_FLAG_FULL_DUPLEX) ? 1629 cmd->duplex = (bp->flags & B44_FLAG_FULL_DUPLEX) ?
@@ -1676,6 +1785,7 @@ static struct ethtool_ops b44_ethtool_ops = {
1676 .set_pauseparam = b44_set_pauseparam, 1785 .set_pauseparam = b44_set_pauseparam,
1677 .get_msglevel = b44_get_msglevel, 1786 .get_msglevel = b44_get_msglevel,
1678 .set_msglevel = b44_set_msglevel, 1787 .set_msglevel = b44_set_msglevel,
1788 .get_perm_addr = ethtool_op_get_perm_addr,
1679}; 1789};
1680 1790
1681static int b44_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) 1791static int b44_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
@@ -1718,6 +1828,7 @@ static int __devinit b44_get_invariants(struct b44 *bp)
1718 bp->dev->dev_addr[3] = eeprom[80]; 1828 bp->dev->dev_addr[3] = eeprom[80];
1719 bp->dev->dev_addr[4] = eeprom[83]; 1829 bp->dev->dev_addr[4] = eeprom[83];
1720 bp->dev->dev_addr[5] = eeprom[82]; 1830 bp->dev->dev_addr[5] = eeprom[82];
1831 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, bp->dev->addr_len);
1721 1832
1722 bp->phy_addr = eeprom[90] & 0x1f; 1833 bp->phy_addr = eeprom[90] & 0x1f;
1723 1834
@@ -1930,6 +2041,8 @@ static int b44_suspend(struct pci_dev *pdev, pm_message_t state)
1930 b44_free_rings(bp); 2041 b44_free_rings(bp);
1931 2042
1932 spin_unlock_irq(&bp->lock); 2043 spin_unlock_irq(&bp->lock);
2044
2045 free_irq(dev->irq, dev);
1933 pci_disable_device(pdev); 2046 pci_disable_device(pdev);
1934 return 0; 2047 return 0;
1935} 2048}
@@ -1946,6 +2059,9 @@ static int b44_resume(struct pci_dev *pdev)
1946 if (!netif_running(dev)) 2059 if (!netif_running(dev))
1947 return 0; 2060 return 0;
1948 2061
2062 if (request_irq(dev->irq, b44_interrupt, SA_SHIRQ, dev->name, dev))
2063 printk(KERN_ERR PFX "%s: request_irq failed\n", dev->name);
2064
1949 spin_lock_irq(&bp->lock); 2065 spin_lock_irq(&bp->lock);
1950 2066
1951 b44_init_rings(bp); 2067 b44_init_rings(bp);
@@ -1971,6 +2087,12 @@ static struct pci_driver b44_driver = {
1971 2087
1972static int __init b44_init(void) 2088static int __init b44_init(void)
1973{ 2089{
2090 unsigned int dma_desc_align_size = dma_get_cache_alignment();
2091
2092 /* Setup paramaters for syncing RX/TX DMA descriptors */
2093 dma_desc_align_mask = ~(dma_desc_align_size - 1);
2094 dma_desc_sync_size = max(dma_desc_align_size, sizeof(struct dma_desc));
2095
1974 return pci_module_init(&b44_driver); 2096 return pci_module_init(&b44_driver);
1975} 2097}
1976 2098
diff --git a/drivers/net/b44.h b/drivers/net/b44.h
index 11c40a2e71c7..593cb0ad4100 100644
--- a/drivers/net/b44.h
+++ b/drivers/net/b44.h
@@ -400,6 +400,8 @@ struct b44 {
400#define B44_FLAG_ADV_100HALF 0x04000000 400#define B44_FLAG_ADV_100HALF 0x04000000
401#define B44_FLAG_ADV_100FULL 0x08000000 401#define B44_FLAG_ADV_100FULL 0x08000000
402#define B44_FLAG_INTERNAL_PHY 0x10000000 402#define B44_FLAG_INTERNAL_PHY 0x10000000
403#define B44_FLAG_RX_RING_HACK 0x20000000
404#define B44_FLAG_TX_RING_HACK 0x40000000
403 405
404 u32 rx_offset; 406 u32 rx_offset;
405 407
diff --git a/drivers/net/bmac.c b/drivers/net/bmac.c
index 0ee28899fb8d..bbca8ae8018c 100644
--- a/drivers/net/bmac.c
+++ b/drivers/net/bmac.c
@@ -1690,10 +1690,8 @@ static void __exit bmac_exit(void)
1690{ 1690{
1691 macio_unregister_driver(&bmac_driver); 1691 macio_unregister_driver(&bmac_driver);
1692 1692
1693 if (bmac_emergency_rxbuf != NULL) { 1693 kfree(bmac_emergency_rxbuf);
1694 kfree(bmac_emergency_rxbuf); 1694 bmac_emergency_rxbuf = NULL;
1695 bmac_emergency_rxbuf = NULL;
1696 }
1697} 1695}
1698 1696
1699MODULE_AUTHOR("Randy Gobbel/Paul Mackerras"); 1697MODULE_AUTHOR("Randy Gobbel/Paul Mackerras");
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index 3a2ace01e444..11d252318221 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -314,20 +314,16 @@ bnx2_free_mem(struct bnx2 *bp)
314 bp->tx_desc_ring, bp->tx_desc_mapping); 314 bp->tx_desc_ring, bp->tx_desc_mapping);
315 bp->tx_desc_ring = NULL; 315 bp->tx_desc_ring = NULL;
316 } 316 }
317 if (bp->tx_buf_ring) { 317 kfree(bp->tx_buf_ring);
318 kfree(bp->tx_buf_ring); 318 bp->tx_buf_ring = NULL;
319 bp->tx_buf_ring = NULL;
320 }
321 if (bp->rx_desc_ring) { 319 if (bp->rx_desc_ring) {
322 pci_free_consistent(bp->pdev, 320 pci_free_consistent(bp->pdev,
323 sizeof(struct rx_bd) * RX_DESC_CNT, 321 sizeof(struct rx_bd) * RX_DESC_CNT,
324 bp->rx_desc_ring, bp->rx_desc_mapping); 322 bp->rx_desc_ring, bp->rx_desc_mapping);
325 bp->rx_desc_ring = NULL; 323 bp->rx_desc_ring = NULL;
326 } 324 }
327 if (bp->rx_buf_ring) { 325 kfree(bp->rx_buf_ring);
328 kfree(bp->rx_buf_ring); 326 bp->rx_buf_ring = NULL;
329 bp->rx_buf_ring = NULL;
330 }
331} 327}
332 328
333static int 329static int
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index f264ff162979..8032126fd589 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -4241,6 +4241,43 @@ out:
4241 return 0; 4241 return 0;
4242} 4242}
4243 4243
4244static void bond_activebackup_xmit_copy(struct sk_buff *skb,
4245 struct bonding *bond,
4246 struct slave *slave)
4247{
4248 struct sk_buff *skb2 = skb_copy(skb, GFP_ATOMIC);
4249 struct ethhdr *eth_data;
4250 u8 *hwaddr;
4251 int res;
4252
4253 if (!skb2) {
4254 printk(KERN_ERR DRV_NAME ": Error: "
4255 "bond_activebackup_xmit_copy(): skb_copy() failed\n");
4256 return;
4257 }
4258
4259 skb2->mac.raw = (unsigned char *)skb2->data;
4260 eth_data = eth_hdr(skb2);
4261
4262 /* Pick an appropriate source MAC address
4263 * -- use slave's perm MAC addr, unless used by bond
4264 * -- otherwise, borrow active slave's perm MAC addr
4265 * since that will not be used
4266 */
4267 hwaddr = slave->perm_hwaddr;
4268 if (!memcmp(eth_data->h_source, hwaddr, ETH_ALEN))
4269 hwaddr = bond->curr_active_slave->perm_hwaddr;
4270
4271 /* Set source MAC address appropriately */
4272 memcpy(eth_data->h_source, hwaddr, ETH_ALEN);
4273
4274 res = bond_dev_queue_xmit(bond, skb2, slave->dev);
4275 if (res)
4276 dev_kfree_skb(skb2);
4277
4278 return;
4279}
4280
4244/* 4281/*
4245 * in active-backup mode, we know that bond->curr_active_slave is always valid if 4282 * in active-backup mode, we know that bond->curr_active_slave is always valid if
4246 * the bond has a usable interface. 4283 * the bond has a usable interface.
@@ -4257,10 +4294,26 @@ static int bond_xmit_activebackup(struct sk_buff *skb, struct net_device *bond_d
4257 goto out; 4294 goto out;
4258 } 4295 }
4259 4296
4260 if (bond->curr_active_slave) { /* one usable interface */ 4297 if (!bond->curr_active_slave)
4261 res = bond_dev_queue_xmit(bond, skb, bond->curr_active_slave->dev); 4298 goto out;
4299
4300 /* Xmit IGMP frames on all slaves to ensure rapid fail-over
4301 for multicast traffic on snooping switches */
4302 if (skb->protocol == __constant_htons(ETH_P_IP) &&
4303 skb->nh.iph->protocol == IPPROTO_IGMP) {
4304 struct slave *slave, *active_slave;
4305 int i;
4306
4307 active_slave = bond->curr_active_slave;
4308 bond_for_each_slave_from_to(bond, slave, i, active_slave->next,
4309 active_slave->prev)
4310 if (IS_UP(slave->dev) &&
4311 (slave->link == BOND_LINK_UP))
4312 bond_activebackup_xmit_copy(skb, bond, slave);
4262 } 4313 }
4263 4314
4315 res = bond_dev_queue_xmit(bond, skb, bond->curr_active_slave->dev);
4316
4264out: 4317out:
4265 if (res) { 4318 if (res) {
4266 /* no suitable interface, frame not sent */ 4319 /* no suitable interface, frame not sent */
diff --git a/drivers/net/cassini.c b/drivers/net/cassini.c
index 2e617424d3fb..50f43dbf31ae 100644
--- a/drivers/net/cassini.c
+++ b/drivers/net/cassini.c
@@ -489,7 +489,7 @@ static int cas_page_free(struct cas *cp, cas_page_t *page)
489/* local page allocation routines for the receive buffers. jumbo pages 489/* local page allocation routines for the receive buffers. jumbo pages
490 * require at least 8K contiguous and 8K aligned buffers. 490 * require at least 8K contiguous and 8K aligned buffers.
491 */ 491 */
492static cas_page_t *cas_page_alloc(struct cas *cp, const int flags) 492static cas_page_t *cas_page_alloc(struct cas *cp, const gfp_t flags)
493{ 493{
494 cas_page_t *page; 494 cas_page_t *page;
495 495
@@ -561,7 +561,7 @@ static void cas_spare_free(struct cas *cp)
561} 561}
562 562
563/* replenish spares if needed */ 563/* replenish spares if needed */
564static void cas_spare_recover(struct cas *cp, const int flags) 564static void cas_spare_recover(struct cas *cp, const gfp_t flags)
565{ 565{
566 struct list_head list, *elem, *tmp; 566 struct list_head list, *elem, *tmp;
567 int needed, i; 567 int needed, i;
diff --git a/drivers/net/cs89x0.c b/drivers/net/cs89x0.c
index a6078ad9b654..bfdae10036ed 100644
--- a/drivers/net/cs89x0.c
+++ b/drivers/net/cs89x0.c
@@ -182,6 +182,10 @@ static unsigned int cs8900_irq_map[] = {IRQ_IXDP2X01_CS8900, 0, 0, 0};
182#define CIRRUS_DEFAULT_IRQ VH_INTC_INT_NUM_CASCADED_INTERRUPT_1 /* Event inputs bank 1 - ID 35/bit 3 */ 182#define CIRRUS_DEFAULT_IRQ VH_INTC_INT_NUM_CASCADED_INTERRUPT_1 /* Event inputs bank 1 - ID 35/bit 3 */
183static unsigned int netcard_portlist[] __initdata = {CIRRUS_DEFAULT_BASE, 0}; 183static unsigned int netcard_portlist[] __initdata = {CIRRUS_DEFAULT_BASE, 0};
184static unsigned int cs8900_irq_map[] = {CIRRUS_DEFAULT_IRQ, 0, 0, 0}; 184static unsigned int cs8900_irq_map[] = {CIRRUS_DEFAULT_IRQ, 0, 0, 0};
185#elif defined(CONFIG_MACH_MP1000)
186#include <asm/arch/mp1000-seprom.h>
187static unsigned int netcard_portlist[] __initdata = {MP1000_EIO_BASE+0x300, 0};
188static unsigned int cs8900_irq_map[] = {IRQ_EINT3,0,0,0};
185#else 189#else
186static unsigned int netcard_portlist[] __initdata = 190static unsigned int netcard_portlist[] __initdata =
187 { 0x300, 0x320, 0x340, 0x360, 0x200, 0x220, 0x240, 0x260, 0x280, 0x2a0, 0x2c0, 0x2e0, 0}; 191 { 0x300, 0x320, 0x340, 0x360, 0x200, 0x220, 0x240, 0x260, 0x280, 0x2a0, 0x2c0, 0x2e0, 0};
@@ -590,6 +594,10 @@ cs89x0_probe1(struct net_device *dev, int ioaddr, int modular)
590 cnt -= j; 594 cnt -= j;
591 } 595 }
592 } else 596 } else
597#elif defined(CONFIG_MACH_MP1000)
598 if (1) {
599 memcpy(dev->dev_addr, get_eeprom_mac_address(), ETH_ALEN);
600 } else
593#endif 601#endif
594 602
595 if ((readreg(dev, PP_SelfST) & (EEPROM_OK | EEPROM_PRESENT)) == 603 if ((readreg(dev, PP_SelfST) & (EEPROM_OK | EEPROM_PRESENT)) ==
@@ -649,6 +657,10 @@ cs89x0_probe1(struct net_device *dev, int ioaddr, int modular)
649 if (1) { 657 if (1) {
650 printk(KERN_NOTICE "cs89x0: No EEPROM on HiCO.SH4\n"); 658 printk(KERN_NOTICE "cs89x0: No EEPROM on HiCO.SH4\n");
651 } else 659 } else
660#elif defined(CONFIG_MACH_MP1000)
661 if (1) {
662 lp->force |= FORCE_RJ45;
663 } else
652#endif 664#endif
653 if ((readreg(dev, PP_SelfST) & EEPROM_PRESENT) == 0) 665 if ((readreg(dev, PP_SelfST) & EEPROM_PRESENT) == 0)
654 printk(KERN_WARNING "cs89x0: No EEPROM, relying on command line....\n"); 666 printk(KERN_WARNING "cs89x0: No EEPROM, relying on command line....\n");
@@ -1231,7 +1243,7 @@ net_open(struct net_device *dev)
1231 else 1243 else
1232#endif 1244#endif
1233 { 1245 {
1234#if !defined(CONFIG_ARCH_IXDP2X01) && !defined(CONFIG_ARCH_PNX0105) 1246#if !defined(CONFIG_ARCH_IXDP2X01) && !defined(CONFIG_ARCH_PNX0105) && !defined(CONFIG_MACH_MP1000)
1235 if (((1 << dev->irq) & lp->irq_map) == 0) { 1247 if (((1 << dev->irq) & lp->irq_map) == 0) {
1236 printk(KERN_ERR "%s: IRQ %d is not in our map of allowable IRQs, which is %x\n", 1248 printk(KERN_ERR "%s: IRQ %d is not in our map of allowable IRQs, which is %x\n",
1237 dev->name, dev->irq, lp->irq_map); 1249 dev->name, dev->irq, lp->irq_map);
diff --git a/drivers/net/cs89x0.h b/drivers/net/cs89x0.h
index decea264f121..f19d1ebe0183 100644
--- a/drivers/net/cs89x0.h
+++ b/drivers/net/cs89x0.h
@@ -16,7 +16,7 @@
16 16
17#include <linux/config.h> 17#include <linux/config.h>
18 18
19#if defined(CONFIG_ARCH_IXDP2X01) || defined(CONFIG_ARCH_PNX0105) 19#if defined(CONFIG_ARCH_IXDP2X01) || defined(CONFIG_ARCH_PNX0105) || defined (CONFIG_MACH_MP1000)
20/* IXDP2401/IXDP2801 uses dword-aligned register addressing */ 20/* IXDP2401/IXDP2801 uses dword-aligned register addressing */
21#define CS89x0_PORT(reg) ((reg) * 2) 21#define CS89x0_PORT(reg) ((reg) * 2)
22#else 22#else
diff --git a/drivers/net/declance.c b/drivers/net/declance.c
index 521c83137bf6..f130bdab3fd3 100644
--- a/drivers/net/declance.c
+++ b/drivers/net/declance.c
@@ -5,7 +5,7 @@
5 * 5 *
6 * adopted from sunlance.c by Richard van den Berg 6 * adopted from sunlance.c by Richard van den Berg
7 * 7 *
8 * Copyright (C) 2002, 2003 Maciej W. Rozycki 8 * Copyright (C) 2002, 2003, 2005 Maciej W. Rozycki
9 * 9 *
10 * additional sources: 10 * additional sources:
11 * - PMAD-AA TURBOchannel Ethernet Module Functional Specification, 11 * - PMAD-AA TURBOchannel Ethernet Module Functional Specification,
@@ -57,13 +57,15 @@
57#include <linux/string.h> 57#include <linux/string.h>
58 58
59#include <asm/addrspace.h> 59#include <asm/addrspace.h>
60#include <asm/system.h>
61
60#include <asm/dec/interrupts.h> 62#include <asm/dec/interrupts.h>
61#include <asm/dec/ioasic.h> 63#include <asm/dec/ioasic.h>
62#include <asm/dec/ioasic_addrs.h> 64#include <asm/dec/ioasic_addrs.h>
63#include <asm/dec/kn01.h> 65#include <asm/dec/kn01.h>
64#include <asm/dec/machtype.h> 66#include <asm/dec/machtype.h>
67#include <asm/dec/system.h>
65#include <asm/dec/tc.h> 68#include <asm/dec/tc.h>
66#include <asm/system.h>
67 69
68static char version[] __devinitdata = 70static char version[] __devinitdata =
69"declance.c: v0.009 by Linux MIPS DECstation task force\n"; 71"declance.c: v0.009 by Linux MIPS DECstation task force\n";
@@ -79,10 +81,6 @@ MODULE_LICENSE("GPL");
79#define PMAD_LANCE 2 81#define PMAD_LANCE 2
80#define PMAX_LANCE 3 82#define PMAX_LANCE 3
81 83
82#ifndef CONFIG_TC
83unsigned long system_base;
84unsigned long dmaptr;
85#endif
86 84
87#define LE_CSR0 0 85#define LE_CSR0 0
88#define LE_CSR1 1 86#define LE_CSR1 1
@@ -237,7 +235,7 @@ struct lance_init_block {
237/* 235/*
238 * This works *only* for the ring descriptors 236 * This works *only* for the ring descriptors
239 */ 237 */
240#define LANCE_ADDR(x) (PHYSADDR(x) >> 1) 238#define LANCE_ADDR(x) (CPHYSADDR(x) >> 1)
241 239
242struct lance_private { 240struct lance_private {
243 struct net_device *next; 241 struct net_device *next;
@@ -697,12 +695,13 @@ out:
697 spin_unlock(&lp->lock); 695 spin_unlock(&lp->lock);
698} 696}
699 697
700static void lance_dma_merr_int(const int irq, void *dev_id, 698static irqreturn_t lance_dma_merr_int(const int irq, void *dev_id,
701 struct pt_regs *regs) 699 struct pt_regs *regs)
702{ 700{
703 struct net_device *dev = (struct net_device *) dev_id; 701 struct net_device *dev = (struct net_device *) dev_id;
704 702
705 printk("%s: DMA error\n", dev->name); 703 printk("%s: DMA error\n", dev->name);
704 return IRQ_HANDLED;
706} 705}
707 706
708static irqreturn_t 707static irqreturn_t
@@ -1026,10 +1025,6 @@ static int __init dec_lance_init(const int type, const int slot)
1026 unsigned long esar_base; 1025 unsigned long esar_base;
1027 unsigned char *esar; 1026 unsigned char *esar;
1028 1027
1029#ifndef CONFIG_TC
1030 system_base = KN01_LANCE_BASE;
1031#endif
1032
1033 if (dec_lance_debug && version_printed++ == 0) 1028 if (dec_lance_debug && version_printed++ == 0)
1034 printk(version); 1029 printk(version);
1035 1030
@@ -1062,16 +1057,16 @@ static int __init dec_lance_init(const int type, const int slot)
1062 switch (type) { 1057 switch (type) {
1063#ifdef CONFIG_TC 1058#ifdef CONFIG_TC
1064 case ASIC_LANCE: 1059 case ASIC_LANCE:
1065 dev->base_addr = system_base + IOASIC_LANCE; 1060 dev->base_addr = CKSEG1ADDR(dec_kn_slot_base + IOASIC_LANCE);
1066 1061
1067 /* buffer space for the on-board LANCE shared memory */ 1062 /* buffer space for the on-board LANCE shared memory */
1068 /* 1063 /*
1069 * FIXME: ugly hack! 1064 * FIXME: ugly hack!
1070 */ 1065 */
1071 dev->mem_start = KSEG1ADDR(0x00020000); 1066 dev->mem_start = CKSEG1ADDR(0x00020000);
1072 dev->mem_end = dev->mem_start + 0x00020000; 1067 dev->mem_end = dev->mem_start + 0x00020000;
1073 dev->irq = dec_interrupt[DEC_IRQ_LANCE]; 1068 dev->irq = dec_interrupt[DEC_IRQ_LANCE];
1074 esar_base = system_base + IOASIC_ESAR; 1069 esar_base = CKSEG1ADDR(dec_kn_slot_base + IOASIC_ESAR);
1075 1070
1076 /* Workaround crash with booting KN04 2.1k from Disk */ 1071 /* Workaround crash with booting KN04 2.1k from Disk */
1077 memset((void *)dev->mem_start, 0, 1072 memset((void *)dev->mem_start, 0,
@@ -1101,14 +1096,14 @@ static int __init dec_lance_init(const int type, const int slot)
1101 /* Setup I/O ASIC LANCE DMA. */ 1096 /* Setup I/O ASIC LANCE DMA. */
1102 lp->dma_irq = dec_interrupt[DEC_IRQ_LANCE_MERR]; 1097 lp->dma_irq = dec_interrupt[DEC_IRQ_LANCE_MERR];
1103 ioasic_write(IO_REG_LANCE_DMA_P, 1098 ioasic_write(IO_REG_LANCE_DMA_P,
1104 PHYSADDR(dev->mem_start) << 3); 1099 CPHYSADDR(dev->mem_start) << 3);
1105 1100
1106 break; 1101 break;
1107 1102
1108 case PMAD_LANCE: 1103 case PMAD_LANCE:
1109 claim_tc_card(slot); 1104 claim_tc_card(slot);
1110 1105
1111 dev->mem_start = get_tc_base_addr(slot); 1106 dev->mem_start = CKSEG1ADDR(get_tc_base_addr(slot));
1112 dev->base_addr = dev->mem_start + 0x100000; 1107 dev->base_addr = dev->mem_start + 0x100000;
1113 dev->irq = get_tc_irq_nr(slot); 1108 dev->irq = get_tc_irq_nr(slot);
1114 esar_base = dev->mem_start + 0x1c0002; 1109 esar_base = dev->mem_start + 0x1c0002;
@@ -1137,9 +1132,9 @@ static int __init dec_lance_init(const int type, const int slot)
1137 1132
1138 case PMAX_LANCE: 1133 case PMAX_LANCE:
1139 dev->irq = dec_interrupt[DEC_IRQ_LANCE]; 1134 dev->irq = dec_interrupt[DEC_IRQ_LANCE];
1140 dev->base_addr = KN01_LANCE_BASE; 1135 dev->base_addr = CKSEG1ADDR(KN01_SLOT_BASE + KN01_LANCE);
1141 dev->mem_start = KN01_LANCE_BASE + 0x01000000; 1136 dev->mem_start = CKSEG1ADDR(KN01_SLOT_BASE + KN01_LANCE_MEM);
1142 esar_base = KN01_RTC_BASE + 1; 1137 esar_base = CKSEG1ADDR(KN01_SLOT_BASE + KN01_ESAR + 1);
1143 lp->dma_irq = -1; 1138 lp->dma_irq = -1;
1144 1139
1145 /* 1140 /*
diff --git a/drivers/net/dm9000.c b/drivers/net/dm9000.c
index e54fc10f6846..abce1f730d00 100644
--- a/drivers/net/dm9000.c
+++ b/drivers/net/dm9000.c
@@ -1140,11 +1140,11 @@ 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, pm_message_t state, u32 level) 1143dm9000_drv_suspend(struct device *dev, pm_message_t state)
1144{ 1144{
1145 struct net_device *ndev = dev_get_drvdata(dev); 1145 struct net_device *ndev = dev_get_drvdata(dev);
1146 1146
1147 if (ndev && level == SUSPEND_DISABLE) { 1147 if (ndev) {
1148 if (netif_running(ndev)) { 1148 if (netif_running(ndev)) {
1149 netif_device_detach(ndev); 1149 netif_device_detach(ndev);
1150 dm9000_shutdown(ndev); 1150 dm9000_shutdown(ndev);
@@ -1154,12 +1154,12 @@ dm9000_drv_suspend(struct device *dev, pm_message_t state, u32 level)
1154} 1154}
1155 1155
1156static int 1156static int
1157dm9000_drv_resume(struct device *dev, u32 level) 1157dm9000_drv_resume(struct device *dev)
1158{ 1158{
1159 struct net_device *ndev = dev_get_drvdata(dev); 1159 struct net_device *ndev = dev_get_drvdata(dev);
1160 board_info_t *db = (board_info_t *) ndev->priv; 1160 board_info_t *db = (board_info_t *) ndev->priv;
1161 1161
1162 if (ndev && level == RESUME_ENABLE) { 1162 if (ndev) {
1163 1163
1164 if (netif_running(ndev)) { 1164 if (netif_running(ndev)) {
1165 dm9000_reset(db); 1165 dm9000_reset(db);
diff --git a/drivers/net/e100.c b/drivers/net/e100.c
index 40887f09b681..eb169a8e8773 100644
--- a/drivers/net/e100.c
+++ b/drivers/net/e100.c
@@ -2201,6 +2201,7 @@ static struct ethtool_ops e100_ethtool_ops = {
2201 .phys_id = e100_phys_id, 2201 .phys_id = e100_phys_id,
2202 .get_stats_count = e100_get_stats_count, 2202 .get_stats_count = e100_get_stats_count,
2203 .get_ethtool_stats = e100_get_ethtool_stats, 2203 .get_ethtool_stats = e100_get_ethtool_stats,
2204 .get_perm_addr = ethtool_op_get_perm_addr,
2204}; 2205};
2205 2206
2206static int e100_do_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) 2207static int e100_do_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
@@ -2351,7 +2352,8 @@ static int __devinit e100_probe(struct pci_dev *pdev,
2351 e100_phy_init(nic); 2352 e100_phy_init(nic);
2352 2353
2353 memcpy(netdev->dev_addr, nic->eeprom, ETH_ALEN); 2354 memcpy(netdev->dev_addr, nic->eeprom, ETH_ALEN);
2354 if(!is_valid_ether_addr(netdev->dev_addr)) { 2355 memcpy(netdev->perm_addr, nic->eeprom, ETH_ALEN);
2356 if(!is_valid_ether_addr(netdev->perm_addr)) {
2355 DPRINTK(PROBE, ERR, "Invalid MAC address from " 2357 DPRINTK(PROBE, ERR, "Invalid MAC address from "
2356 "EEPROM, aborting.\n"); 2358 "EEPROM, aborting.\n");
2357 err = -EAGAIN; 2359 err = -EAGAIN;
diff --git a/drivers/net/e1000/e1000.h b/drivers/net/e1000/e1000.h
index 092757bc721f..3f653a93e1bc 100644
--- a/drivers/net/e1000/e1000.h
+++ b/drivers/net/e1000/e1000.h
@@ -72,6 +72,10 @@
72#include <linux/mii.h> 72#include <linux/mii.h>
73#include <linux/ethtool.h> 73#include <linux/ethtool.h>
74#include <linux/if_vlan.h> 74#include <linux/if_vlan.h>
75#ifdef CONFIG_E1000_MQ
76#include <linux/cpu.h>
77#include <linux/smp.h>
78#endif
75 79
76#define BAR_0 0 80#define BAR_0 0
77#define BAR_1 1 81#define BAR_1 1
@@ -165,10 +169,33 @@ struct e1000_buffer {
165 uint16_t next_to_watch; 169 uint16_t next_to_watch;
166}; 170};
167 171
168struct e1000_ps_page { struct page *ps_page[MAX_PS_BUFFERS]; }; 172struct e1000_ps_page { struct page *ps_page[PS_PAGE_BUFFERS]; };
169struct e1000_ps_page_dma { uint64_t ps_page_dma[MAX_PS_BUFFERS]; }; 173struct e1000_ps_page_dma { uint64_t ps_page_dma[PS_PAGE_BUFFERS]; };
174
175struct e1000_tx_ring {
176 /* pointer to the descriptor ring memory */
177 void *desc;
178 /* physical address of the descriptor ring */
179 dma_addr_t dma;
180 /* length of descriptor ring in bytes */
181 unsigned int size;
182 /* number of descriptors in the ring */
183 unsigned int count;
184 /* next descriptor to associate a buffer with */
185 unsigned int next_to_use;
186 /* next descriptor to check for DD status bit */
187 unsigned int next_to_clean;
188 /* array of buffer information structs */
189 struct e1000_buffer *buffer_info;
190
191 struct e1000_buffer previous_buffer_info;
192 spinlock_t tx_lock;
193 uint16_t tdh;
194 uint16_t tdt;
195 uint64_t pkt;
196};
170 197
171struct e1000_desc_ring { 198struct e1000_rx_ring {
172 /* pointer to the descriptor ring memory */ 199 /* pointer to the descriptor ring memory */
173 void *desc; 200 void *desc;
174 /* physical address of the descriptor ring */ 201 /* physical address of the descriptor ring */
@@ -186,6 +213,10 @@ struct e1000_desc_ring {
186 /* arrays of page information for packet split */ 213 /* arrays of page information for packet split */
187 struct e1000_ps_page *ps_page; 214 struct e1000_ps_page *ps_page;
188 struct e1000_ps_page_dma *ps_page_dma; 215 struct e1000_ps_page_dma *ps_page_dma;
216
217 uint16_t rdh;
218 uint16_t rdt;
219 uint64_t pkt;
189}; 220};
190 221
191#define E1000_DESC_UNUSED(R) \ 222#define E1000_DESC_UNUSED(R) \
@@ -227,9 +258,10 @@ struct e1000_adapter {
227 unsigned long led_status; 258 unsigned long led_status;
228 259
229 /* TX */ 260 /* TX */
230 struct e1000_desc_ring tx_ring; 261 struct e1000_tx_ring *tx_ring; /* One per active queue */
231 struct e1000_buffer previous_buffer_info; 262#ifdef CONFIG_E1000_MQ
232 spinlock_t tx_lock; 263 struct e1000_tx_ring **cpu_tx_ring; /* per-cpu */
264#endif
233 uint32_t txd_cmd; 265 uint32_t txd_cmd;
234 uint32_t tx_int_delay; 266 uint32_t tx_int_delay;
235 uint32_t tx_abs_int_delay; 267 uint32_t tx_abs_int_delay;
@@ -246,19 +278,33 @@ struct e1000_adapter {
246 278
247 /* RX */ 279 /* RX */
248#ifdef CONFIG_E1000_NAPI 280#ifdef CONFIG_E1000_NAPI
249 boolean_t (*clean_rx) (struct e1000_adapter *adapter, int *work_done, 281 boolean_t (*clean_rx) (struct e1000_adapter *adapter,
250 int work_to_do); 282 struct e1000_rx_ring *rx_ring,
283 int *work_done, int work_to_do);
251#else 284#else
252 boolean_t (*clean_rx) (struct e1000_adapter *adapter); 285 boolean_t (*clean_rx) (struct e1000_adapter *adapter,
286 struct e1000_rx_ring *rx_ring);
253#endif 287#endif
254 void (*alloc_rx_buf) (struct e1000_adapter *adapter); 288 void (*alloc_rx_buf) (struct e1000_adapter *adapter,
255 struct e1000_desc_ring rx_ring; 289 struct e1000_rx_ring *rx_ring);
290 struct e1000_rx_ring *rx_ring; /* One per active queue */
291#ifdef CONFIG_E1000_NAPI
292 struct net_device *polling_netdev; /* One per active queue */
293#endif
294#ifdef CONFIG_E1000_MQ
295 struct net_device **cpu_netdev; /* per-cpu */
296 struct call_async_data_struct rx_sched_call_data;
297 int cpu_for_queue[4];
298#endif
299 int num_queues;
300
256 uint64_t hw_csum_err; 301 uint64_t hw_csum_err;
257 uint64_t hw_csum_good; 302 uint64_t hw_csum_good;
303 uint64_t rx_hdr_split;
258 uint32_t rx_int_delay; 304 uint32_t rx_int_delay;
259 uint32_t rx_abs_int_delay; 305 uint32_t rx_abs_int_delay;
260 boolean_t rx_csum; 306 boolean_t rx_csum;
261 boolean_t rx_ps; 307 unsigned int rx_ps_pages;
262 uint32_t gorcl; 308 uint32_t gorcl;
263 uint64_t gorcl_old; 309 uint64_t gorcl_old;
264 uint16_t rx_ps_bsize0; 310 uint16_t rx_ps_bsize0;
@@ -278,8 +324,8 @@ struct e1000_adapter {
278 struct e1000_phy_stats phy_stats; 324 struct e1000_phy_stats phy_stats;
279 325
280 uint32_t test_icr; 326 uint32_t test_icr;
281 struct e1000_desc_ring test_tx_ring; 327 struct e1000_tx_ring test_tx_ring;
282 struct e1000_desc_ring test_rx_ring; 328 struct e1000_rx_ring test_rx_ring;
283 329
284 330
285 int msg_enable; 331 int msg_enable;
diff --git a/drivers/net/e1000/e1000_ethtool.c b/drivers/net/e1000/e1000_ethtool.c
index f133ff0b0b94..9c7feaeaa6a4 100644
--- a/drivers/net/e1000/e1000_ethtool.c
+++ b/drivers/net/e1000/e1000_ethtool.c
@@ -39,10 +39,10 @@ extern int e1000_up(struct e1000_adapter *adapter);
39extern void e1000_down(struct e1000_adapter *adapter); 39extern void e1000_down(struct e1000_adapter *adapter);
40extern void e1000_reset(struct e1000_adapter *adapter); 40extern void e1000_reset(struct e1000_adapter *adapter);
41extern int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx); 41extern int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
42extern int e1000_setup_rx_resources(struct e1000_adapter *adapter); 42extern int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
43extern int e1000_setup_tx_resources(struct e1000_adapter *adapter); 43extern int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
44extern void e1000_free_rx_resources(struct e1000_adapter *adapter); 44extern void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
45extern void e1000_free_tx_resources(struct e1000_adapter *adapter); 45extern void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
46extern void e1000_update_stats(struct e1000_adapter *adapter); 46extern void e1000_update_stats(struct e1000_adapter *adapter);
47 47
48struct e1000_stats { 48struct e1000_stats {
@@ -91,7 +91,8 @@ static const struct e1000_stats e1000_gstrings_stats[] = {
91 { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) }, 91 { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
92 { "rx_long_byte_count", E1000_STAT(stats.gorcl) }, 92 { "rx_long_byte_count", E1000_STAT(stats.gorcl) },
93 { "rx_csum_offload_good", E1000_STAT(hw_csum_good) }, 93 { "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
94 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) } 94 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
95 { "rx_header_split", E1000_STAT(rx_hdr_split) },
95}; 96};
96#define E1000_STATS_LEN \ 97#define E1000_STATS_LEN \
97 sizeof(e1000_gstrings_stats) / sizeof(struct e1000_stats) 98 sizeof(e1000_gstrings_stats) / sizeof(struct e1000_stats)
@@ -546,8 +547,10 @@ e1000_set_eeprom(struct net_device *netdev,
546 ret_val = e1000_write_eeprom(hw, first_word, 547 ret_val = e1000_write_eeprom(hw, first_word,
547 last_word - first_word + 1, eeprom_buff); 548 last_word - first_word + 1, eeprom_buff);
548 549
549 /* Update the checksum over the first part of the EEPROM if needed */ 550 /* Update the checksum over the first part of the EEPROM if needed
550 if((ret_val == 0) && first_word <= EEPROM_CHECKSUM_REG) 551 * and flush shadow RAM for 82573 conrollers */
552 if((ret_val == 0) && ((first_word <= EEPROM_CHECKSUM_REG) ||
553 (hw->mac_type == e1000_82573)))
551 e1000_update_eeprom_checksum(hw); 554 e1000_update_eeprom_checksum(hw);
552 555
553 kfree(eeprom_buff); 556 kfree(eeprom_buff);
@@ -576,8 +579,8 @@ e1000_get_ringparam(struct net_device *netdev,
576{ 579{
577 struct e1000_adapter *adapter = netdev_priv(netdev); 580 struct e1000_adapter *adapter = netdev_priv(netdev);
578 e1000_mac_type mac_type = adapter->hw.mac_type; 581 e1000_mac_type mac_type = adapter->hw.mac_type;
579 struct e1000_desc_ring *txdr = &adapter->tx_ring; 582 struct e1000_tx_ring *txdr = adapter->tx_ring;
580 struct e1000_desc_ring *rxdr = &adapter->rx_ring; 583 struct e1000_rx_ring *rxdr = adapter->rx_ring;
581 584
582 ring->rx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_RXD : 585 ring->rx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_RXD :
583 E1000_MAX_82544_RXD; 586 E1000_MAX_82544_RXD;
@@ -597,20 +600,40 @@ e1000_set_ringparam(struct net_device *netdev,
597{ 600{
598 struct e1000_adapter *adapter = netdev_priv(netdev); 601 struct e1000_adapter *adapter = netdev_priv(netdev);
599 e1000_mac_type mac_type = adapter->hw.mac_type; 602 e1000_mac_type mac_type = adapter->hw.mac_type;
600 struct e1000_desc_ring *txdr = &adapter->tx_ring; 603 struct e1000_tx_ring *txdr, *tx_old, *tx_new;
601 struct e1000_desc_ring *rxdr = &adapter->rx_ring; 604 struct e1000_rx_ring *rxdr, *rx_old, *rx_new;
602 struct e1000_desc_ring tx_old, tx_new, rx_old, rx_new; 605 int i, err, tx_ring_size, rx_ring_size;
603 int err; 606
607 tx_ring_size = sizeof(struct e1000_tx_ring) * adapter->num_queues;
608 rx_ring_size = sizeof(struct e1000_rx_ring) * adapter->num_queues;
609
610 if (netif_running(adapter->netdev))
611 e1000_down(adapter);
604 612
605 tx_old = adapter->tx_ring; 613 tx_old = adapter->tx_ring;
606 rx_old = adapter->rx_ring; 614 rx_old = adapter->rx_ring;
607 615
616 adapter->tx_ring = kmalloc(tx_ring_size, GFP_KERNEL);
617 if (!adapter->tx_ring) {
618 err = -ENOMEM;
619 goto err_setup_rx;
620 }
621 memset(adapter->tx_ring, 0, tx_ring_size);
622
623 adapter->rx_ring = kmalloc(rx_ring_size, GFP_KERNEL);
624 if (!adapter->rx_ring) {
625 kfree(adapter->tx_ring);
626 err = -ENOMEM;
627 goto err_setup_rx;
628 }
629 memset(adapter->rx_ring, 0, rx_ring_size);
630
631 txdr = adapter->tx_ring;
632 rxdr = adapter->rx_ring;
633
608 if((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) 634 if((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
609 return -EINVAL; 635 return -EINVAL;
610 636
611 if(netif_running(adapter->netdev))
612 e1000_down(adapter);
613
614 rxdr->count = max(ring->rx_pending,(uint32_t)E1000_MIN_RXD); 637 rxdr->count = max(ring->rx_pending,(uint32_t)E1000_MIN_RXD);
615 rxdr->count = min(rxdr->count,(uint32_t)(mac_type < e1000_82544 ? 638 rxdr->count = min(rxdr->count,(uint32_t)(mac_type < e1000_82544 ?
616 E1000_MAX_RXD : E1000_MAX_82544_RXD)); 639 E1000_MAX_RXD : E1000_MAX_82544_RXD));
@@ -621,11 +644,16 @@ e1000_set_ringparam(struct net_device *netdev,
621 E1000_MAX_TXD : E1000_MAX_82544_TXD)); 644 E1000_MAX_TXD : E1000_MAX_82544_TXD));
622 E1000_ROUNDUP(txdr->count, REQ_TX_DESCRIPTOR_MULTIPLE); 645 E1000_ROUNDUP(txdr->count, REQ_TX_DESCRIPTOR_MULTIPLE);
623 646
647 for (i = 0; i < adapter->num_queues; i++) {
648 txdr[i].count = txdr->count;
649 rxdr[i].count = rxdr->count;
650 }
651
624 if(netif_running(adapter->netdev)) { 652 if(netif_running(adapter->netdev)) {
625 /* Try to get new resources before deleting old */ 653 /* Try to get new resources before deleting old */
626 if((err = e1000_setup_rx_resources(adapter))) 654 if ((err = e1000_setup_all_rx_resources(adapter)))
627 goto err_setup_rx; 655 goto err_setup_rx;
628 if((err = e1000_setup_tx_resources(adapter))) 656 if ((err = e1000_setup_all_tx_resources(adapter)))
629 goto err_setup_tx; 657 goto err_setup_tx;
630 658
631 /* save the new, restore the old in order to free it, 659 /* save the new, restore the old in order to free it,
@@ -635,8 +663,10 @@ e1000_set_ringparam(struct net_device *netdev,
635 tx_new = adapter->tx_ring; 663 tx_new = adapter->tx_ring;
636 adapter->rx_ring = rx_old; 664 adapter->rx_ring = rx_old;
637 adapter->tx_ring = tx_old; 665 adapter->tx_ring = tx_old;
638 e1000_free_rx_resources(adapter); 666 e1000_free_all_rx_resources(adapter);
639 e1000_free_tx_resources(adapter); 667 e1000_free_all_tx_resources(adapter);
668 kfree(tx_old);
669 kfree(rx_old);
640 adapter->rx_ring = rx_new; 670 adapter->rx_ring = rx_new;
641 adapter->tx_ring = tx_new; 671 adapter->tx_ring = tx_new;
642 if((err = e1000_up(adapter))) 672 if((err = e1000_up(adapter)))
@@ -645,7 +675,7 @@ e1000_set_ringparam(struct net_device *netdev,
645 675
646 return 0; 676 return 0;
647err_setup_tx: 677err_setup_tx:
648 e1000_free_rx_resources(adapter); 678 e1000_free_all_rx_resources(adapter);
649err_setup_rx: 679err_setup_rx:
650 adapter->rx_ring = rx_old; 680 adapter->rx_ring = rx_old;
651 adapter->tx_ring = tx_old; 681 adapter->tx_ring = tx_old;
@@ -696,6 +726,11 @@ e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data)
696 * Some bits that get toggled are ignored. 726 * Some bits that get toggled are ignored.
697 */ 727 */
698 switch (adapter->hw.mac_type) { 728 switch (adapter->hw.mac_type) {
729 /* there are several bits on newer hardware that are r/w */
730 case e1000_82571:
731 case e1000_82572:
732 toggle = 0x7FFFF3FF;
733 break;
699 case e1000_82573: 734 case e1000_82573:
700 toggle = 0x7FFFF033; 735 toggle = 0x7FFFF033;
701 break; 736 break;
@@ -898,8 +933,8 @@ e1000_intr_test(struct e1000_adapter *adapter, uint64_t *data)
898static void 933static void
899e1000_free_desc_rings(struct e1000_adapter *adapter) 934e1000_free_desc_rings(struct e1000_adapter *adapter)
900{ 935{
901 struct e1000_desc_ring *txdr = &adapter->test_tx_ring; 936 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
902 struct e1000_desc_ring *rxdr = &adapter->test_rx_ring; 937 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
903 struct pci_dev *pdev = adapter->pdev; 938 struct pci_dev *pdev = adapter->pdev;
904 int i; 939 int i;
905 940
@@ -930,19 +965,16 @@ e1000_free_desc_rings(struct e1000_adapter *adapter)
930 if(rxdr->desc) 965 if(rxdr->desc)
931 pci_free_consistent(pdev, rxdr->size, rxdr->desc, rxdr->dma); 966 pci_free_consistent(pdev, rxdr->size, rxdr->desc, rxdr->dma);
932 967
933 if(txdr->buffer_info) 968 kfree(txdr->buffer_info);
934 kfree(txdr->buffer_info); 969 kfree(rxdr->buffer_info);
935 if(rxdr->buffer_info)
936 kfree(rxdr->buffer_info);
937
938 return; 970 return;
939} 971}
940 972
941static int 973static int
942e1000_setup_desc_rings(struct e1000_adapter *adapter) 974e1000_setup_desc_rings(struct e1000_adapter *adapter)
943{ 975{
944 struct e1000_desc_ring *txdr = &adapter->test_tx_ring; 976 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
945 struct e1000_desc_ring *rxdr = &adapter->test_rx_ring; 977 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
946 struct pci_dev *pdev = adapter->pdev; 978 struct pci_dev *pdev = adapter->pdev;
947 uint32_t rctl; 979 uint32_t rctl;
948 int size, i, ret_val; 980 int size, i, ret_val;
@@ -1245,6 +1277,8 @@ e1000_set_phy_loopback(struct e1000_adapter *adapter)
1245 case e1000_82541_rev_2: 1277 case e1000_82541_rev_2:
1246 case e1000_82547: 1278 case e1000_82547:
1247 case e1000_82547_rev_2: 1279 case e1000_82547_rev_2:
1280 case e1000_82571:
1281 case e1000_82572:
1248 case e1000_82573: 1282 case e1000_82573:
1249 return e1000_integrated_phy_loopback(adapter); 1283 return e1000_integrated_phy_loopback(adapter);
1250 break; 1284 break;
@@ -1340,8 +1374,8 @@ e1000_check_lbtest_frame(struct sk_buff *skb, unsigned int frame_size)
1340static int 1374static int
1341e1000_run_loopback_test(struct e1000_adapter *adapter) 1375e1000_run_loopback_test(struct e1000_adapter *adapter)
1342{ 1376{
1343 struct e1000_desc_ring *txdr = &adapter->test_tx_ring; 1377 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1344 struct e1000_desc_ring *rxdr = &adapter->test_rx_ring; 1378 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
1345 struct pci_dev *pdev = adapter->pdev; 1379 struct pci_dev *pdev = adapter->pdev;
1346 int i, j, k, l, lc, good_cnt, ret_val=0; 1380 int i, j, k, l, lc, good_cnt, ret_val=0;
1347 unsigned long time; 1381 unsigned long time;
@@ -1509,6 +1543,7 @@ e1000_diag_test(struct net_device *netdev,
1509 data[2] = 0; 1543 data[2] = 0;
1510 data[3] = 0; 1544 data[3] = 0;
1511 } 1545 }
1546 msleep_interruptible(4 * 1000);
1512} 1547}
1513 1548
1514static void 1549static void
@@ -1625,7 +1660,7 @@ e1000_phys_id(struct net_device *netdev, uint32_t data)
1625 if(!data || data > (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ)) 1660 if(!data || data > (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ))
1626 data = (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ); 1661 data = (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ);
1627 1662
1628 if(adapter->hw.mac_type < e1000_82573) { 1663 if(adapter->hw.mac_type < e1000_82571) {
1629 if(!adapter->blink_timer.function) { 1664 if(!adapter->blink_timer.function) {
1630 init_timer(&adapter->blink_timer); 1665 init_timer(&adapter->blink_timer);
1631 adapter->blink_timer.function = e1000_led_blink_callback; 1666 adapter->blink_timer.function = e1000_led_blink_callback;
@@ -1739,6 +1774,7 @@ struct ethtool_ops e1000_ethtool_ops = {
1739 .phys_id = e1000_phys_id, 1774 .phys_id = e1000_phys_id,
1740 .get_stats_count = e1000_get_stats_count, 1775 .get_stats_count = e1000_get_stats_count,
1741 .get_ethtool_stats = e1000_get_ethtool_stats, 1776 .get_ethtool_stats = e1000_get_ethtool_stats,
1777 .get_perm_addr = ethtool_op_get_perm_addr,
1742}; 1778};
1743 1779
1744void e1000_set_ethtool_ops(struct net_device *netdev) 1780void e1000_set_ethtool_ops(struct net_device *netdev)
diff --git a/drivers/net/e1000/e1000_hw.c b/drivers/net/e1000/e1000_hw.c
index 045f5426ab9a..8fc876da43b4 100644
--- a/drivers/net/e1000/e1000_hw.c
+++ b/drivers/net/e1000/e1000_hw.c
@@ -83,14 +83,14 @@ uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
83 83
84static const 84static const
85uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] = 85uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
86 { 8, 13, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 86 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
87 22, 24, 27, 30, 32, 35, 37, 40, 42, 44, 47, 49, 51, 54, 56, 58, 87 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
88 32, 35, 38, 41, 44, 47, 50, 53, 55, 58, 61, 63, 66, 69, 71, 74, 88 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
89 43, 47, 51, 54, 58, 61, 64, 67, 71, 74, 77, 80, 82, 85, 88, 90, 89 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
90 57, 62, 66, 70, 74, 77, 81, 85, 88, 91, 94, 97, 100, 103, 106, 108, 90 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
91 73, 78, 82, 87, 91, 95, 98, 102, 105, 109, 112, 114, 117, 119, 122, 124, 91 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
92 91, 96, 101, 105, 109, 113, 116, 119, 122, 125, 127, 128, 128, 128, 128, 128, 92 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
93 108, 113, 117, 121, 124, 127, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128}; 93 104, 109, 114, 118, 121, 124};
94 94
95 95
96/****************************************************************************** 96/******************************************************************************
@@ -286,7 +286,6 @@ e1000_set_mac_type(struct e1000_hw *hw)
286 case E1000_DEV_ID_82546GB_FIBER: 286 case E1000_DEV_ID_82546GB_FIBER:
287 case E1000_DEV_ID_82546GB_SERDES: 287 case E1000_DEV_ID_82546GB_SERDES:
288 case E1000_DEV_ID_82546GB_PCIE: 288 case E1000_DEV_ID_82546GB_PCIE:
289 case E1000_DEV_ID_82546GB_QUAD_COPPER:
290 hw->mac_type = e1000_82546_rev_3; 289 hw->mac_type = e1000_82546_rev_3;
291 break; 290 break;
292 case E1000_DEV_ID_82541EI: 291 case E1000_DEV_ID_82541EI:
@@ -305,8 +304,19 @@ e1000_set_mac_type(struct e1000_hw *hw)
305 case E1000_DEV_ID_82547GI: 304 case E1000_DEV_ID_82547GI:
306 hw->mac_type = e1000_82547_rev_2; 305 hw->mac_type = e1000_82547_rev_2;
307 break; 306 break;
307 case E1000_DEV_ID_82571EB_COPPER:
308 case E1000_DEV_ID_82571EB_FIBER:
309 case E1000_DEV_ID_82571EB_SERDES:
310 hw->mac_type = e1000_82571;
311 break;
312 case E1000_DEV_ID_82572EI_COPPER:
313 case E1000_DEV_ID_82572EI_FIBER:
314 case E1000_DEV_ID_82572EI_SERDES:
315 hw->mac_type = e1000_82572;
316 break;
308 case E1000_DEV_ID_82573E: 317 case E1000_DEV_ID_82573E:
309 case E1000_DEV_ID_82573E_IAMT: 318 case E1000_DEV_ID_82573E_IAMT:
319 case E1000_DEV_ID_82573L:
310 hw->mac_type = e1000_82573; 320 hw->mac_type = e1000_82573;
311 break; 321 break;
312 default: 322 default:
@@ -315,6 +325,8 @@ e1000_set_mac_type(struct e1000_hw *hw)
315 } 325 }
316 326
317 switch(hw->mac_type) { 327 switch(hw->mac_type) {
328 case e1000_82571:
329 case e1000_82572:
318 case e1000_82573: 330 case e1000_82573:
319 hw->eeprom_semaphore_present = TRUE; 331 hw->eeprom_semaphore_present = TRUE;
320 /* fall through */ 332 /* fall through */
@@ -351,6 +363,8 @@ e1000_set_media_type(struct e1000_hw *hw)
351 switch (hw->device_id) { 363 switch (hw->device_id) {
352 case E1000_DEV_ID_82545GM_SERDES: 364 case E1000_DEV_ID_82545GM_SERDES:
353 case E1000_DEV_ID_82546GB_SERDES: 365 case E1000_DEV_ID_82546GB_SERDES:
366 case E1000_DEV_ID_82571EB_SERDES:
367 case E1000_DEV_ID_82572EI_SERDES:
354 hw->media_type = e1000_media_type_internal_serdes; 368 hw->media_type = e1000_media_type_internal_serdes;
355 break; 369 break;
356 default: 370 default:
@@ -523,6 +537,8 @@ e1000_reset_hw(struct e1000_hw *hw)
523 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); 537 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
524 E1000_WRITE_FLUSH(hw); 538 E1000_WRITE_FLUSH(hw);
525 /* fall through */ 539 /* fall through */
540 case e1000_82571:
541 case e1000_82572:
526 ret_val = e1000_get_auto_rd_done(hw); 542 ret_val = e1000_get_auto_rd_done(hw);
527 if(ret_val) 543 if(ret_val)
528 /* We don't want to continue accessing MAC registers. */ 544 /* We don't want to continue accessing MAC registers. */
@@ -683,6 +699,9 @@ e1000_init_hw(struct e1000_hw *hw)
683 switch (hw->mac_type) { 699 switch (hw->mac_type) {
684 default: 700 default:
685 break; 701 break;
702 case e1000_82571:
703 case e1000_82572:
704 ctrl |= (1 << 22);
686 case e1000_82573: 705 case e1000_82573:
687 ctrl |= E1000_TXDCTL_COUNT_DESC; 706 ctrl |= E1000_TXDCTL_COUNT_DESC;
688 break; 707 break;
@@ -694,6 +713,26 @@ e1000_init_hw(struct e1000_hw *hw)
694 e1000_enable_tx_pkt_filtering(hw); 713 e1000_enable_tx_pkt_filtering(hw);
695 } 714 }
696 715
716 switch (hw->mac_type) {
717 default:
718 break;
719 case e1000_82571:
720 case e1000_82572:
721 ctrl = E1000_READ_REG(hw, TXDCTL1);
722 ctrl &= ~E1000_TXDCTL_WTHRESH;
723 ctrl |= E1000_TXDCTL_COUNT_DESC | E1000_TXDCTL_FULL_TX_DESC_WB;
724 ctrl |= (1 << 22);
725 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
726 break;
727 }
728
729
730
731 if (hw->mac_type == e1000_82573) {
732 uint32_t gcr = E1000_READ_REG(hw, GCR);
733 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
734 E1000_WRITE_REG(hw, GCR, gcr);
735 }
697 736
698 /* Clear all of the statistics registers (clear on read). It is 737 /* Clear all of the statistics registers (clear on read). It is
699 * important that we do this after we have tried to establish link 738 * important that we do this after we have tried to establish link
@@ -878,6 +917,14 @@ e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
878 917
879 DEBUGFUNC("e1000_setup_fiber_serdes_link"); 918 DEBUGFUNC("e1000_setup_fiber_serdes_link");
880 919
920 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
921 * until explicitly turned off or a power cycle is performed. A read to
922 * the register does not indicate its status. Therefore, we ensure
923 * loopback mode is disabled during initialization.
924 */
925 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
926 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
927
881 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be 928 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
882 * set when the optics detect a signal. On older adapters, it will be 929 * set when the optics detect a signal. On older adapters, it will be
883 * cleared when there is a signal. This applies to fiber media only. 930 * cleared when there is a signal. This applies to fiber media only.
@@ -2943,6 +2990,8 @@ e1000_phy_reset(struct e1000_hw *hw)
2943 2990
2944 switch (hw->mac_type) { 2991 switch (hw->mac_type) {
2945 case e1000_82541_rev_2: 2992 case e1000_82541_rev_2:
2993 case e1000_82571:
2994 case e1000_82572:
2946 ret_val = e1000_phy_hw_reset(hw); 2995 ret_val = e1000_phy_hw_reset(hw);
2947 if(ret_val) 2996 if(ret_val)
2948 return ret_val; 2997 return ret_val;
@@ -2981,6 +3030,16 @@ e1000_detect_gig_phy(struct e1000_hw *hw)
2981 3030
2982 DEBUGFUNC("e1000_detect_gig_phy"); 3031 DEBUGFUNC("e1000_detect_gig_phy");
2983 3032
3033 /* The 82571 firmware may still be configuring the PHY. In this
3034 * case, we cannot access the PHY until the configuration is done. So
3035 * we explicitly set the PHY values. */
3036 if(hw->mac_type == e1000_82571 ||
3037 hw->mac_type == e1000_82572) {
3038 hw->phy_id = IGP01E1000_I_PHY_ID;
3039 hw->phy_type = e1000_phy_igp_2;
3040 return E1000_SUCCESS;
3041 }
3042
2984 /* Read the PHY ID Registers to identify which PHY is onboard. */ 3043 /* Read the PHY ID Registers to identify which PHY is onboard. */
2985 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high); 3044 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
2986 if(ret_val) 3045 if(ret_val)
@@ -3334,6 +3393,21 @@ e1000_init_eeprom_params(struct e1000_hw *hw)
3334 eeprom->use_eerd = FALSE; 3393 eeprom->use_eerd = FALSE;
3335 eeprom->use_eewr = FALSE; 3394 eeprom->use_eewr = FALSE;
3336 break; 3395 break;
3396 case e1000_82571:
3397 case e1000_82572:
3398 eeprom->type = e1000_eeprom_spi;
3399 eeprom->opcode_bits = 8;
3400 eeprom->delay_usec = 1;
3401 if (eecd & E1000_EECD_ADDR_BITS) {
3402 eeprom->page_size = 32;
3403 eeprom->address_bits = 16;
3404 } else {
3405 eeprom->page_size = 8;
3406 eeprom->address_bits = 8;
3407 }
3408 eeprom->use_eerd = FALSE;
3409 eeprom->use_eewr = FALSE;
3410 break;
3337 case e1000_82573: 3411 case e1000_82573:
3338 eeprom->type = e1000_eeprom_spi; 3412 eeprom->type = e1000_eeprom_spi;
3339 eeprom->opcode_bits = 8; 3413 eeprom->opcode_bits = 8;
@@ -3543,25 +3617,26 @@ e1000_acquire_eeprom(struct e1000_hw *hw)
3543 eecd = E1000_READ_REG(hw, EECD); 3617 eecd = E1000_READ_REG(hw, EECD);
3544 3618
3545 if (hw->mac_type != e1000_82573) { 3619 if (hw->mac_type != e1000_82573) {
3546 /* Request EEPROM Access */ 3620 /* Request EEPROM Access */
3547 if(hw->mac_type > e1000_82544) { 3621 if(hw->mac_type > e1000_82544) {
3548 eecd |= E1000_EECD_REQ; 3622 eecd |= E1000_EECD_REQ;
3549 E1000_WRITE_REG(hw, EECD, eecd);
3550 eecd = E1000_READ_REG(hw, EECD);
3551 while((!(eecd & E1000_EECD_GNT)) &&
3552 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3553 i++;
3554 udelay(5);
3555 eecd = E1000_READ_REG(hw, EECD);
3556 }
3557 if(!(eecd & E1000_EECD_GNT)) {
3558 eecd &= ~E1000_EECD_REQ;
3559 E1000_WRITE_REG(hw, EECD, eecd); 3623 E1000_WRITE_REG(hw, EECD, eecd);
3560 DEBUGOUT("Could not acquire EEPROM grant\n"); 3624 eecd = E1000_READ_REG(hw, EECD);
3561 return -E1000_ERR_EEPROM; 3625 while((!(eecd & E1000_EECD_GNT)) &&
3626 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3627 i++;
3628 udelay(5);
3629 eecd = E1000_READ_REG(hw, EECD);
3630 }
3631 if(!(eecd & E1000_EECD_GNT)) {
3632 eecd &= ~E1000_EECD_REQ;
3633 E1000_WRITE_REG(hw, EECD, eecd);
3634 DEBUGOUT("Could not acquire EEPROM grant\n");
3635 e1000_put_hw_eeprom_semaphore(hw);
3636 return -E1000_ERR_EEPROM;
3637 }
3562 } 3638 }
3563 } 3639 }
3564 }
3565 3640
3566 /* Setup EEPROM for Read/Write */ 3641 /* Setup EEPROM for Read/Write */
3567 3642
@@ -4064,7 +4139,7 @@ e1000_write_eeprom(struct e1000_hw *hw,
4064 return -E1000_ERR_EEPROM; 4139 return -E1000_ERR_EEPROM;
4065 } 4140 }
4066 4141
4067 /* 82573 reads only through eerd */ 4142 /* 82573 writes only through eewr */
4068 if(eeprom->use_eewr == TRUE) 4143 if(eeprom->use_eewr == TRUE)
4069 return e1000_write_eeprom_eewr(hw, offset, words, data); 4144 return e1000_write_eeprom_eewr(hw, offset, words, data);
4070 4145
@@ -4353,9 +4428,16 @@ e1000_read_mac_addr(struct e1000_hw * hw)
4353 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF); 4428 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
4354 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8); 4429 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
4355 } 4430 }
4356 if(((hw->mac_type == e1000_82546) || (hw->mac_type == e1000_82546_rev_3)) && 4431 switch (hw->mac_type) {
4357 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) 4432 default:
4433 break;
4434 case e1000_82546:
4435 case e1000_82546_rev_3:
4436 case e1000_82571:
4437 if(E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
4358 hw->perm_mac_addr[5] ^= 0x01; 4438 hw->perm_mac_addr[5] ^= 0x01;
4439 break;
4440 }
4359 4441
4360 for(i = 0; i < NODE_ADDRESS_SIZE; i++) 4442 for(i = 0; i < NODE_ADDRESS_SIZE; i++)
4361 hw->mac_addr[i] = hw->perm_mac_addr[i]; 4443 hw->mac_addr[i] = hw->perm_mac_addr[i];
@@ -4385,6 +4467,12 @@ e1000_init_rx_addrs(struct e1000_hw *hw)
4385 e1000_rar_set(hw, hw->mac_addr, 0); 4467 e1000_rar_set(hw, hw->mac_addr, 0);
4386 4468
4387 rar_num = E1000_RAR_ENTRIES; 4469 rar_num = E1000_RAR_ENTRIES;
4470
4471 /* Reserve a spot for the Locally Administered Address to work around
4472 * an 82571 issue in which a reset on one port will reload the MAC on
4473 * the other port. */
4474 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
4475 rar_num -= 1;
4388 /* Zero out the other 15 receive addresses. */ 4476 /* Zero out the other 15 receive addresses. */
4389 DEBUGOUT("Clearing RAR[1-15]\n"); 4477 DEBUGOUT("Clearing RAR[1-15]\n");
4390 for(i = 1; i < rar_num; i++) { 4478 for(i = 1; i < rar_num; i++) {
@@ -4427,6 +4515,12 @@ e1000_mc_addr_list_update(struct e1000_hw *hw,
4427 /* Clear RAR[1-15] */ 4515 /* Clear RAR[1-15] */
4428 DEBUGOUT(" Clearing RAR[1-15]\n"); 4516 DEBUGOUT(" Clearing RAR[1-15]\n");
4429 num_rar_entry = E1000_RAR_ENTRIES; 4517 num_rar_entry = E1000_RAR_ENTRIES;
4518 /* Reserve a spot for the Locally Administered Address to work around
4519 * an 82571 issue in which a reset on one port will reload the MAC on
4520 * the other port. */
4521 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
4522 num_rar_entry -= 1;
4523
4430 for(i = rar_used_count; i < num_rar_entry; i++) { 4524 for(i = rar_used_count; i < num_rar_entry; i++) {
4431 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0); 4525 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
4432 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0); 4526 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
@@ -4984,7 +5078,6 @@ e1000_clear_hw_cntrs(struct e1000_hw *hw)
4984 temp = E1000_READ_REG(hw, ICTXQEC); 5078 temp = E1000_READ_REG(hw, ICTXQEC);
4985 temp = E1000_READ_REG(hw, ICTXQMTC); 5079 temp = E1000_READ_REG(hw, ICTXQMTC);
4986 temp = E1000_READ_REG(hw, ICRXDMTC); 5080 temp = E1000_READ_REG(hw, ICRXDMTC);
4987
4988} 5081}
4989 5082
4990/****************************************************************************** 5083/******************************************************************************
@@ -5151,6 +5244,8 @@ e1000_get_bus_info(struct e1000_hw *hw)
5151 hw->bus_speed = e1000_bus_speed_unknown; 5244 hw->bus_speed = e1000_bus_speed_unknown;
5152 hw->bus_width = e1000_bus_width_unknown; 5245 hw->bus_width = e1000_bus_width_unknown;
5153 break; 5246 break;
5247 case e1000_82571:
5248 case e1000_82572:
5154 case e1000_82573: 5249 case e1000_82573:
5155 hw->bus_type = e1000_bus_type_pci_express; 5250 hw->bus_type = e1000_bus_type_pci_express;
5156 hw->bus_speed = e1000_bus_speed_2500; 5251 hw->bus_speed = e1000_bus_speed_2500;
@@ -5250,6 +5345,7 @@ e1000_get_cable_length(struct e1000_hw *hw,
5250 int32_t ret_val; 5345 int32_t ret_val;
5251 uint16_t agc_value = 0; 5346 uint16_t agc_value = 0;
5252 uint16_t cur_agc, min_agc = IGP01E1000_AGC_LENGTH_TABLE_SIZE; 5347 uint16_t cur_agc, min_agc = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
5348 uint16_t max_agc = 0;
5253 uint16_t i, phy_data; 5349 uint16_t i, phy_data;
5254 uint16_t cable_length; 5350 uint16_t cable_length;
5255 5351
@@ -5338,6 +5434,40 @@ e1000_get_cable_length(struct e1000_hw *hw,
5338 IGP01E1000_AGC_RANGE) : 0; 5434 IGP01E1000_AGC_RANGE) : 0;
5339 *max_length = e1000_igp_cable_length_table[agc_value] + 5435 *max_length = e1000_igp_cable_length_table[agc_value] +
5340 IGP01E1000_AGC_RANGE; 5436 IGP01E1000_AGC_RANGE;
5437 } else if (hw->phy_type == e1000_phy_igp_2) {
5438 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
5439 {IGP02E1000_PHY_AGC_A,
5440 IGP02E1000_PHY_AGC_B,
5441 IGP02E1000_PHY_AGC_C,
5442 IGP02E1000_PHY_AGC_D};
5443 /* Read the AGC registers for all channels */
5444 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
5445 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
5446 if (ret_val)
5447 return ret_val;
5448
5449 /* Getting bits 15:9, which represent the combination of course and
5450 * fine gain values. The result is a number that can be put into
5451 * the lookup table to obtain the approximate cable length. */
5452 cur_agc = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
5453 IGP02E1000_AGC_LENGTH_MASK;
5454
5455 /* Remove min & max AGC values from calculation. */
5456 if (e1000_igp_2_cable_length_table[min_agc] > e1000_igp_2_cable_length_table[cur_agc])
5457 min_agc = cur_agc;
5458 if (e1000_igp_2_cable_length_table[max_agc] < e1000_igp_2_cable_length_table[cur_agc])
5459 max_agc = cur_agc;
5460
5461 agc_value += e1000_igp_2_cable_length_table[cur_agc];
5462 }
5463
5464 agc_value -= (e1000_igp_2_cable_length_table[min_agc] + e1000_igp_2_cable_length_table[max_agc]);
5465 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
5466
5467 /* Calculate cable length with the error range of +/- 10 meters. */
5468 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
5469 (agc_value - IGP02E1000_AGC_RANGE) : 0;
5470 *max_length = agc_value + IGP02E1000_AGC_RANGE;
5341 } 5471 }
5342 5472
5343 return E1000_SUCCESS; 5473 return E1000_SUCCESS;
@@ -6465,6 +6595,8 @@ e1000_get_auto_rd_done(struct e1000_hw *hw)
6465 default: 6595 default:
6466 msec_delay(5); 6596 msec_delay(5);
6467 break; 6597 break;
6598 case e1000_82571:
6599 case e1000_82572:
6468 case e1000_82573: 6600 case e1000_82573:
6469 while(timeout) { 6601 while(timeout) {
6470 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD) break; 6602 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD) break;
@@ -6494,10 +6626,31 @@ e1000_get_auto_rd_done(struct e1000_hw *hw)
6494int32_t 6626int32_t
6495e1000_get_phy_cfg_done(struct e1000_hw *hw) 6627e1000_get_phy_cfg_done(struct e1000_hw *hw)
6496{ 6628{
6629 int32_t timeout = PHY_CFG_TIMEOUT;
6630 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
6631
6497 DEBUGFUNC("e1000_get_phy_cfg_done"); 6632 DEBUGFUNC("e1000_get_phy_cfg_done");
6498 6633
6499 /* Simply wait for 10ms */ 6634 switch (hw->mac_type) {
6500 msec_delay(10); 6635 default:
6636 msec_delay(10);
6637 break;
6638 case e1000_82571:
6639 case e1000_82572:
6640 while (timeout) {
6641 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
6642 break;
6643 else
6644 msec_delay(1);
6645 timeout--;
6646 }
6647
6648 if (!timeout) {
6649 DEBUGOUT("MNG configuration cycle has not completed.\n");
6650 return -E1000_ERR_RESET;
6651 }
6652 break;
6653 }
6501 6654
6502 return E1000_SUCCESS; 6655 return E1000_SUCCESS;
6503} 6656}
@@ -6569,8 +6722,7 @@ e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
6569 return; 6722 return;
6570 6723
6571 swsm = E1000_READ_REG(hw, SWSM); 6724 swsm = E1000_READ_REG(hw, SWSM);
6572 /* Release both semaphores. */ 6725 swsm &= ~(E1000_SWSM_SWESMBI);
6573 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
6574 E1000_WRITE_REG(hw, SWSM, swsm); 6726 E1000_WRITE_REG(hw, SWSM, swsm);
6575} 6727}
6576 6728
@@ -6606,6 +6758,8 @@ e1000_arc_subsystem_valid(struct e1000_hw *hw)
6606 * if this is the case. We read FWSM to determine the manageability mode. 6758 * if this is the case. We read FWSM to determine the manageability mode.
6607 */ 6759 */
6608 switch (hw->mac_type) { 6760 switch (hw->mac_type) {
6761 case e1000_82571:
6762 case e1000_82572:
6609 case e1000_82573: 6763 case e1000_82573:
6610 fwsm = E1000_READ_REG(hw, FWSM); 6764 fwsm = E1000_READ_REG(hw, FWSM);
6611 if((fwsm & E1000_FWSM_MODE_MASK) != 0) 6765 if((fwsm & E1000_FWSM_MODE_MASK) != 0)
diff --git a/drivers/net/e1000/e1000_hw.h b/drivers/net/e1000/e1000_hw.h
index 51c2b3a18b6f..4f2c196dc314 100644
--- a/drivers/net/e1000/e1000_hw.h
+++ b/drivers/net/e1000/e1000_hw.h
@@ -57,6 +57,8 @@ typedef enum {
57 e1000_82541_rev_2, 57 e1000_82541_rev_2,
58 e1000_82547, 58 e1000_82547,
59 e1000_82547_rev_2, 59 e1000_82547_rev_2,
60 e1000_82571,
61 e1000_82572,
60 e1000_82573, 62 e1000_82573,
61 e1000_num_macs 63 e1000_num_macs
62} e1000_mac_type; 64} e1000_mac_type;
@@ -478,10 +480,16 @@ uint8_t e1000_arc_subsystem_valid(struct e1000_hw *hw);
478#define E1000_DEV_ID_82546GB_SERDES 0x107B 480#define E1000_DEV_ID_82546GB_SERDES 0x107B
479#define E1000_DEV_ID_82546GB_PCIE 0x108A 481#define E1000_DEV_ID_82546GB_PCIE 0x108A
480#define E1000_DEV_ID_82547EI 0x1019 482#define E1000_DEV_ID_82547EI 0x1019
483#define E1000_DEV_ID_82571EB_COPPER 0x105E
484#define E1000_DEV_ID_82571EB_FIBER 0x105F
485#define E1000_DEV_ID_82571EB_SERDES 0x1060
486#define E1000_DEV_ID_82572EI_COPPER 0x107D
487#define E1000_DEV_ID_82572EI_FIBER 0x107E
488#define E1000_DEV_ID_82572EI_SERDES 0x107F
481#define E1000_DEV_ID_82573E 0x108B 489#define E1000_DEV_ID_82573E 0x108B
482#define E1000_DEV_ID_82573E_IAMT 0x108C 490#define E1000_DEV_ID_82573E_IAMT 0x108C
491#define E1000_DEV_ID_82573L 0x109A
483 492
484#define E1000_DEV_ID_82546GB_QUAD_COPPER 0x1099
485 493
486#define NODE_ADDRESS_SIZE 6 494#define NODE_ADDRESS_SIZE 6
487#define ETH_LENGTH_OF_ADDRESS 6 495#define ETH_LENGTH_OF_ADDRESS 6
@@ -833,6 +841,8 @@ struct e1000_ffvt_entry {
833#define E1000_FFMT_SIZE E1000_FLEXIBLE_FILTER_SIZE_MAX 841#define E1000_FFMT_SIZE E1000_FLEXIBLE_FILTER_SIZE_MAX
834#define E1000_FFVT_SIZE E1000_FLEXIBLE_FILTER_SIZE_MAX 842#define E1000_FFVT_SIZE E1000_FLEXIBLE_FILTER_SIZE_MAX
835 843
844#define E1000_DISABLE_SERDES_LOOPBACK 0x0400
845
836/* Register Set. (82543, 82544) 846/* Register Set. (82543, 82544)
837 * 847 *
838 * Registers are defined to be 32 bits and should be accessed as 32 bit values. 848 * Registers are defined to be 32 bits and should be accessed as 32 bit values.
@@ -853,6 +863,7 @@ struct e1000_ffvt_entry {
853#define E1000_CTRL_EXT 0x00018 /* Extended Device Control - RW */ 863#define E1000_CTRL_EXT 0x00018 /* Extended Device Control - RW */
854#define E1000_FLA 0x0001C /* Flash Access - RW */ 864#define E1000_FLA 0x0001C /* Flash Access - RW */
855#define E1000_MDIC 0x00020 /* MDI Control - RW */ 865#define E1000_MDIC 0x00020 /* MDI Control - RW */
866#define E1000_SCTL 0x00024 /* SerDes Control - RW */
856#define E1000_FCAL 0x00028 /* Flow Control Address Low - RW */ 867#define E1000_FCAL 0x00028 /* Flow Control Address Low - RW */
857#define E1000_FCAH 0x0002C /* Flow Control Address High -RW */ 868#define E1000_FCAH 0x0002C /* Flow Control Address High -RW */
858#define E1000_FCT 0x00030 /* Flow Control Type - RW */ 869#define E1000_FCT 0x00030 /* Flow Control Type - RW */
@@ -864,6 +875,12 @@ struct e1000_ffvt_entry {
864#define E1000_IMC 0x000D8 /* Interrupt Mask Clear - WO */ 875#define E1000_IMC 0x000D8 /* Interrupt Mask Clear - WO */
865#define E1000_IAM 0x000E0 /* Interrupt Acknowledge Auto Mask */ 876#define E1000_IAM 0x000E0 /* Interrupt Acknowledge Auto Mask */
866#define E1000_RCTL 0x00100 /* RX Control - RW */ 877#define E1000_RCTL 0x00100 /* RX Control - RW */
878#define E1000_RDTR1 0x02820 /* RX Delay Timer (1) - RW */
879#define E1000_RDBAL1 0x02900 /* RX Descriptor Base Address Low (1) - RW */
880#define E1000_RDBAH1 0x02904 /* RX Descriptor Base Address High (1) - RW */
881#define E1000_RDLEN1 0x02908 /* RX Descriptor Length (1) - RW */
882#define E1000_RDH1 0x02910 /* RX Descriptor Head (1) - RW */
883#define E1000_RDT1 0x02918 /* RX Descriptor Tail (1) - RW */
867#define E1000_FCTTV 0x00170 /* Flow Control Transmit Timer Value - RW */ 884#define E1000_FCTTV 0x00170 /* Flow Control Transmit Timer Value - RW */
868#define E1000_TXCW 0x00178 /* TX Configuration Word - RW */ 885#define E1000_TXCW 0x00178 /* TX Configuration Word - RW */
869#define E1000_RXCW 0x00180 /* RX Configuration Word - RO */ 886#define E1000_RXCW 0x00180 /* RX Configuration Word - RO */
@@ -895,6 +912,12 @@ struct e1000_ffvt_entry {
895#define E1000_RDH 0x02810 /* RX Descriptor Head - RW */ 912#define E1000_RDH 0x02810 /* RX Descriptor Head - RW */
896#define E1000_RDT 0x02818 /* RX Descriptor Tail - RW */ 913#define E1000_RDT 0x02818 /* RX Descriptor Tail - RW */
897#define E1000_RDTR 0x02820 /* RX Delay Timer - RW */ 914#define E1000_RDTR 0x02820 /* RX Delay Timer - RW */
915#define E1000_RDBAL0 E1000_RDBAL /* RX Desc Base Address Low (0) - RW */
916#define E1000_RDBAH0 E1000_RDBAH /* RX Desc Base Address High (0) - RW */
917#define E1000_RDLEN0 E1000_RDLEN /* RX Desc Length (0) - RW */
918#define E1000_RDH0 E1000_RDH /* RX Desc Head (0) - RW */
919#define E1000_RDT0 E1000_RDT /* RX Desc Tail (0) - RW */
920#define E1000_RDTR0 E1000_RDTR /* RX Delay Timer (0) - RW */
898#define E1000_RXDCTL 0x02828 /* RX Descriptor Control - RW */ 921#define E1000_RXDCTL 0x02828 /* RX Descriptor Control - RW */
899#define E1000_RADV 0x0282C /* RX Interrupt Absolute Delay Timer - RW */ 922#define E1000_RADV 0x0282C /* RX Interrupt Absolute Delay Timer - RW */
900#define E1000_RSRPD 0x02C00 /* RX Small Packet Detect - RW */ 923#define E1000_RSRPD 0x02C00 /* RX Small Packet Detect - RW */
@@ -980,15 +1003,15 @@ struct e1000_ffvt_entry {
980#define E1000_BPTC 0x040F4 /* Broadcast Packets TX Count - R/clr */ 1003#define E1000_BPTC 0x040F4 /* Broadcast Packets TX Count - R/clr */
981#define E1000_TSCTC 0x040F8 /* TCP Segmentation Context TX - R/clr */ 1004#define E1000_TSCTC 0x040F8 /* TCP Segmentation Context TX - R/clr */
982#define E1000_TSCTFC 0x040FC /* TCP Segmentation Context TX Fail - R/clr */ 1005#define E1000_TSCTFC 0x040FC /* TCP Segmentation Context TX Fail - R/clr */
983#define E1000_IAC 0x4100 /* Interrupt Assertion Count */ 1006#define E1000_IAC 0x04100 /* Interrupt Assertion Count */
984#define E1000_ICRXPTC 0x4104 /* Interrupt Cause Rx Packet Timer Expire Count */ 1007#define E1000_ICRXPTC 0x04104 /* Interrupt Cause Rx Packet Timer Expire Count */
985#define E1000_ICRXATC 0x4108 /* Interrupt Cause Rx Absolute Timer Expire Count */ 1008#define E1000_ICRXATC 0x04108 /* Interrupt Cause Rx Absolute Timer Expire Count */
986#define E1000_ICTXPTC 0x410C /* Interrupt Cause Tx Packet Timer Expire Count */ 1009#define E1000_ICTXPTC 0x0410C /* Interrupt Cause Tx Packet Timer Expire Count */
987#define E1000_ICTXATC 0x4110 /* Interrupt Cause Tx Absolute Timer Expire Count */ 1010#define E1000_ICTXATC 0x04110 /* Interrupt Cause Tx Absolute Timer Expire Count */
988#define E1000_ICTXQEC 0x4118 /* Interrupt Cause Tx Queue Empty Count */ 1011#define E1000_ICTXQEC 0x04118 /* Interrupt Cause Tx Queue Empty Count */
989#define E1000_ICTXQMTC 0x411C /* Interrupt Cause Tx Queue Minimum Threshold Count */ 1012#define E1000_ICTXQMTC 0x0411C /* Interrupt Cause Tx Queue Minimum Threshold Count */
990#define E1000_ICRXDMTC 0x4120 /* Interrupt Cause Rx Descriptor Minimum Threshold Count */ 1013#define E1000_ICRXDMTC 0x04120 /* Interrupt Cause Rx Descriptor Minimum Threshold Count */
991#define E1000_ICRXOC 0x4124 /* Interrupt Cause Receiver Overrun Count */ 1014#define E1000_ICRXOC 0x04124 /* Interrupt Cause Receiver Overrun Count */
992#define E1000_RXCSUM 0x05000 /* RX Checksum Control - RW */ 1015#define E1000_RXCSUM 0x05000 /* RX Checksum Control - RW */
993#define E1000_RFCTL 0x05008 /* Receive Filter Control*/ 1016#define E1000_RFCTL 0x05008 /* Receive Filter Control*/
994#define E1000_MTA 0x05200 /* Multicast Table Array - RW Array */ 1017#define E1000_MTA 0x05200 /* Multicast Table Array - RW Array */
@@ -1018,6 +1041,14 @@ struct e1000_ffvt_entry {
1018#define E1000_FWSM 0x05B54 /* FW Semaphore */ 1041#define E1000_FWSM 0x05B54 /* FW Semaphore */
1019#define E1000_FFLT_DBG 0x05F04 /* Debug Register */ 1042#define E1000_FFLT_DBG 0x05F04 /* Debug Register */
1020#define E1000_HICR 0x08F00 /* Host Inteface Control */ 1043#define E1000_HICR 0x08F00 /* Host Inteface Control */
1044
1045/* RSS registers */
1046#define E1000_CPUVEC 0x02C10 /* CPU Vector Register - RW */
1047#define E1000_MRQC 0x05818 /* Multiple Receive Control - RW */
1048#define E1000_RETA 0x05C00 /* Redirection Table - RW Array */
1049#define E1000_RSSRK 0x05C80 /* RSS Random Key - RW Array */
1050#define E1000_RSSIM 0x05864 /* RSS Interrupt Mask */
1051#define E1000_RSSIR 0x05868 /* RSS Interrupt Request */
1021/* Register Set (82542) 1052/* Register Set (82542)
1022 * 1053 *
1023 * Some of the 82542 registers are located at different offsets than they are 1054 * Some of the 82542 registers are located at different offsets than they are
@@ -1032,6 +1063,7 @@ struct e1000_ffvt_entry {
1032#define E1000_82542_CTRL_EXT E1000_CTRL_EXT 1063#define E1000_82542_CTRL_EXT E1000_CTRL_EXT
1033#define E1000_82542_FLA E1000_FLA 1064#define E1000_82542_FLA E1000_FLA
1034#define E1000_82542_MDIC E1000_MDIC 1065#define E1000_82542_MDIC E1000_MDIC
1066#define E1000_82542_SCTL E1000_SCTL
1035#define E1000_82542_FCAL E1000_FCAL 1067#define E1000_82542_FCAL E1000_FCAL
1036#define E1000_82542_FCAH E1000_FCAH 1068#define E1000_82542_FCAH E1000_FCAH
1037#define E1000_82542_FCT E1000_FCT 1069#define E1000_82542_FCT E1000_FCT
@@ -1049,6 +1081,18 @@ struct e1000_ffvt_entry {
1049#define E1000_82542_RDLEN 0x00118 1081#define E1000_82542_RDLEN 0x00118
1050#define E1000_82542_RDH 0x00120 1082#define E1000_82542_RDH 0x00120
1051#define E1000_82542_RDT 0x00128 1083#define E1000_82542_RDT 0x00128
1084#define E1000_82542_RDTR0 E1000_82542_RDTR
1085#define E1000_82542_RDBAL0 E1000_82542_RDBAL
1086#define E1000_82542_RDBAH0 E1000_82542_RDBAH
1087#define E1000_82542_RDLEN0 E1000_82542_RDLEN
1088#define E1000_82542_RDH0 E1000_82542_RDH
1089#define E1000_82542_RDT0 E1000_82542_RDT
1090#define E1000_82542_RDTR1 0x00130
1091#define E1000_82542_RDBAL1 0x00138
1092#define E1000_82542_RDBAH1 0x0013C
1093#define E1000_82542_RDLEN1 0x00140
1094#define E1000_82542_RDH1 0x00148
1095#define E1000_82542_RDT1 0x00150
1052#define E1000_82542_FCRTH 0x00160 1096#define E1000_82542_FCRTH 0x00160
1053#define E1000_82542_FCRTL 0x00168 1097#define E1000_82542_FCRTL 0x00168
1054#define E1000_82542_FCTTV E1000_FCTTV 1098#define E1000_82542_FCTTV E1000_FCTTV
@@ -1197,6 +1241,13 @@ struct e1000_ffvt_entry {
1197#define E1000_82542_ICRXOC E1000_ICRXOC 1241#define E1000_82542_ICRXOC E1000_ICRXOC
1198#define E1000_82542_HICR E1000_HICR 1242#define E1000_82542_HICR E1000_HICR
1199 1243
1244#define E1000_82542_CPUVEC E1000_CPUVEC
1245#define E1000_82542_MRQC E1000_MRQC
1246#define E1000_82542_RETA E1000_RETA
1247#define E1000_82542_RSSRK E1000_RSSRK
1248#define E1000_82542_RSSIM E1000_RSSIM
1249#define E1000_82542_RSSIR E1000_RSSIR
1250
1200/* Statistics counters collected by the MAC */ 1251/* Statistics counters collected by the MAC */
1201struct e1000_hw_stats { 1252struct e1000_hw_stats {
1202 uint64_t crcerrs; 1253 uint64_t crcerrs;
@@ -1336,6 +1387,7 @@ struct e1000_hw {
1336 boolean_t serdes_link_down; 1387 boolean_t serdes_link_down;
1337 boolean_t tbi_compatibility_en; 1388 boolean_t tbi_compatibility_en;
1338 boolean_t tbi_compatibility_on; 1389 boolean_t tbi_compatibility_on;
1390 boolean_t laa_is_present;
1339 boolean_t phy_reset_disable; 1391 boolean_t phy_reset_disable;
1340 boolean_t fc_send_xon; 1392 boolean_t fc_send_xon;
1341 boolean_t fc_strict_ieee; 1393 boolean_t fc_strict_ieee;
@@ -1374,6 +1426,7 @@ struct e1000_hw {
1374#define E1000_CTRL_BEM32 0x00000400 /* Big Endian 32 mode */ 1426#define E1000_CTRL_BEM32 0x00000400 /* Big Endian 32 mode */
1375#define E1000_CTRL_FRCSPD 0x00000800 /* Force Speed */ 1427#define E1000_CTRL_FRCSPD 0x00000800 /* Force Speed */
1376#define E1000_CTRL_FRCDPX 0x00001000 /* Force Duplex */ 1428#define E1000_CTRL_FRCDPX 0x00001000 /* Force Duplex */
1429#define E1000_CTRL_D_UD_EN 0x00002000 /* Dock/Undock enable */
1377#define E1000_CTRL_D_UD_POLARITY 0x00004000 /* Defined polarity of Dock/Undock indication in SDP[0] */ 1430#define E1000_CTRL_D_UD_POLARITY 0x00004000 /* Defined polarity of Dock/Undock indication in SDP[0] */
1378#define E1000_CTRL_SWDPIN0 0x00040000 /* SWDPIN 0 value */ 1431#define E1000_CTRL_SWDPIN0 0x00040000 /* SWDPIN 0 value */
1379#define E1000_CTRL_SWDPIN1 0x00080000 /* SWDPIN 1 value */ 1432#define E1000_CTRL_SWDPIN1 0x00080000 /* SWDPIN 1 value */
@@ -1491,6 +1544,8 @@ struct e1000_hw {
1491#define E1000_CTRL_EXT_WR_WMARK_320 0x01000000 1544#define E1000_CTRL_EXT_WR_WMARK_320 0x01000000
1492#define E1000_CTRL_EXT_WR_WMARK_384 0x02000000 1545#define E1000_CTRL_EXT_WR_WMARK_384 0x02000000
1493#define E1000_CTRL_EXT_WR_WMARK_448 0x03000000 1546#define E1000_CTRL_EXT_WR_WMARK_448 0x03000000
1547#define E1000_CTRL_EXT_CANC 0x04000000 /* Interrupt delay cancellation */
1548#define E1000_CTRL_EXT_DRV_LOAD 0x10000000 /* Driver loaded bit for FW */
1494#define E1000_CTRL_EXT_IAME 0x08000000 /* Interrupt acknowledge Auto-mask */ 1549#define E1000_CTRL_EXT_IAME 0x08000000 /* Interrupt acknowledge Auto-mask */
1495#define E1000_CTRL_EXT_INT_TIMER_CLR 0x20000000 /* Clear Interrupt timers after IMS clear */ 1550#define E1000_CTRL_EXT_INT_TIMER_CLR 0x20000000 /* Clear Interrupt timers after IMS clear */
1496 1551
@@ -1524,6 +1579,7 @@ struct e1000_hw {
1524#define E1000_LEDCTL_LED2_BLINK 0x00800000 1579#define E1000_LEDCTL_LED2_BLINK 0x00800000
1525#define E1000_LEDCTL_LED3_MODE_MASK 0x0F000000 1580#define E1000_LEDCTL_LED3_MODE_MASK 0x0F000000
1526#define E1000_LEDCTL_LED3_MODE_SHIFT 24 1581#define E1000_LEDCTL_LED3_MODE_SHIFT 24
1582#define E1000_LEDCTL_LED3_BLINK_RATE 0x20000000
1527#define E1000_LEDCTL_LED3_IVRT 0x40000000 1583#define E1000_LEDCTL_LED3_IVRT 0x40000000
1528#define E1000_LEDCTL_LED3_BLINK 0x80000000 1584#define E1000_LEDCTL_LED3_BLINK 0x80000000
1529 1585
@@ -1784,6 +1840,16 @@ struct e1000_hw {
1784#define E1000_RXCSUM_IPPCSE 0x00001000 /* IP payload checksum enable */ 1840#define E1000_RXCSUM_IPPCSE 0x00001000 /* IP payload checksum enable */
1785#define E1000_RXCSUM_PCSD 0x00002000 /* packet checksum disabled */ 1841#define E1000_RXCSUM_PCSD 0x00002000 /* packet checksum disabled */
1786 1842
1843/* Multiple Receive Queue Control */
1844#define E1000_MRQC_ENABLE_MASK 0x00000003
1845#define E1000_MRQC_ENABLE_RSS_2Q 0x00000001
1846#define E1000_MRQC_ENABLE_RSS_INT 0x00000004
1847#define E1000_MRQC_RSS_FIELD_MASK 0xFFFF0000
1848#define E1000_MRQC_RSS_FIELD_IPV4_TCP 0x00010000
1849#define E1000_MRQC_RSS_FIELD_IPV4 0x00020000
1850#define E1000_MRQC_RSS_FIELD_IPV6_TCP 0x00040000
1851#define E1000_MRQC_RSS_FIELD_IPV6_EX 0x00080000
1852#define E1000_MRQC_RSS_FIELD_IPV6 0x00100000
1787 1853
1788/* Definitions for power management and wakeup registers */ 1854/* Definitions for power management and wakeup registers */
1789/* Wake Up Control */ 1855/* Wake Up Control */
@@ -1928,6 +1994,7 @@ struct e1000_host_command_info {
1928#define E1000_MDALIGN 4096 1994#define E1000_MDALIGN 4096
1929 1995
1930#define E1000_GCR_BEM32 0x00400000 1996#define E1000_GCR_BEM32 0x00400000
1997#define E1000_GCR_L1_ACT_WITHOUT_L0S_RX 0x08000000
1931/* Function Active and Power State to MNG */ 1998/* Function Active and Power State to MNG */
1932#define E1000_FACTPS_FUNC0_POWER_STATE_MASK 0x00000003 1999#define E1000_FACTPS_FUNC0_POWER_STATE_MASK 0x00000003
1933#define E1000_FACTPS_LAN0_VALID 0x00000004 2000#define E1000_FACTPS_LAN0_VALID 0x00000004
@@ -1980,6 +2047,7 @@ struct e1000_host_command_info {
1980/* EEPROM Word Offsets */ 2047/* EEPROM Word Offsets */
1981#define EEPROM_COMPAT 0x0003 2048#define EEPROM_COMPAT 0x0003
1982#define EEPROM_ID_LED_SETTINGS 0x0004 2049#define EEPROM_ID_LED_SETTINGS 0x0004
2050#define EEPROM_VERSION 0x0005
1983#define EEPROM_SERDES_AMPLITUDE 0x0006 /* For SERDES output amplitude adjustment. */ 2051#define EEPROM_SERDES_AMPLITUDE 0x0006 /* For SERDES output amplitude adjustment. */
1984#define EEPROM_PHY_CLASS_WORD 0x0007 2052#define EEPROM_PHY_CLASS_WORD 0x0007
1985#define EEPROM_INIT_CONTROL1_REG 0x000A 2053#define EEPROM_INIT_CONTROL1_REG 0x000A
@@ -1990,6 +2058,8 @@ struct e1000_host_command_info {
1990#define EEPROM_FLASH_VERSION 0x0032 2058#define EEPROM_FLASH_VERSION 0x0032
1991#define EEPROM_CHECKSUM_REG 0x003F 2059#define EEPROM_CHECKSUM_REG 0x003F
1992 2060
2061#define E1000_EEPROM_CFG_DONE 0x00040000 /* MNG config cycle done */
2062
1993/* Word definitions for ID LED Settings */ 2063/* Word definitions for ID LED Settings */
1994#define ID_LED_RESERVED_0000 0x0000 2064#define ID_LED_RESERVED_0000 0x0000
1995#define ID_LED_RESERVED_FFFF 0xFFFF 2065#define ID_LED_RESERVED_FFFF 0xFFFF
@@ -2108,6 +2178,8 @@ struct e1000_host_command_info {
2108#define E1000_PBA_22K 0x0016 2178#define E1000_PBA_22K 0x0016
2109#define E1000_PBA_24K 0x0018 2179#define E1000_PBA_24K 0x0018
2110#define E1000_PBA_30K 0x001E 2180#define E1000_PBA_30K 0x001E
2181#define E1000_PBA_32K 0x0020
2182#define E1000_PBA_38K 0x0026
2111#define E1000_PBA_40K 0x0028 2183#define E1000_PBA_40K 0x0028
2112#define E1000_PBA_48K 0x0030 /* 48KB, default RX allocation */ 2184#define E1000_PBA_48K 0x0030 /* 48KB, default RX allocation */
2113 2185
@@ -2592,11 +2664,11 @@ struct e1000_host_command_info {
2592 2664
2593/* 7 bits (3 Coarse + 4 Fine) --> 128 optional values */ 2665/* 7 bits (3 Coarse + 4 Fine) --> 128 optional values */
2594#define IGP01E1000_AGC_LENGTH_TABLE_SIZE 128 2666#define IGP01E1000_AGC_LENGTH_TABLE_SIZE 128
2595#define IGP02E1000_AGC_LENGTH_TABLE_SIZE 128 2667#define IGP02E1000_AGC_LENGTH_TABLE_SIZE 113
2596 2668
2597/* The precision error of the cable length is +/- 10 meters */ 2669/* The precision error of the cable length is +/- 10 meters */
2598#define IGP01E1000_AGC_RANGE 10 2670#define IGP01E1000_AGC_RANGE 10
2599#define IGP02E1000_AGC_RANGE 10 2671#define IGP02E1000_AGC_RANGE 15
2600 2672
2601/* IGP01E1000 PCS Initialization register */ 2673/* IGP01E1000 PCS Initialization register */
2602/* bits 3:6 in the PCS registers stores the channels polarity */ 2674/* bits 3:6 in the PCS registers stores the channels polarity */
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index ee687c902a20..efbbda7cbcbf 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -43,7 +43,7 @@ char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
43#else 43#else
44#define DRIVERNAPI "-NAPI" 44#define DRIVERNAPI "-NAPI"
45#endif 45#endif
46#define DRV_VERSION "6.0.60-k2"DRIVERNAPI 46#define DRV_VERSION "6.1.16-k2"DRIVERNAPI
47char e1000_driver_version[] = DRV_VERSION; 47char e1000_driver_version[] = DRV_VERSION;
48char e1000_copyright[] = "Copyright (c) 1999-2005 Intel Corporation."; 48char e1000_copyright[] = "Copyright (c) 1999-2005 Intel Corporation.";
49 49
@@ -80,6 +80,9 @@ static struct pci_device_id e1000_pci_tbl[] = {
80 INTEL_E1000_ETHERNET_DEVICE(0x1026), 80 INTEL_E1000_ETHERNET_DEVICE(0x1026),
81 INTEL_E1000_ETHERNET_DEVICE(0x1027), 81 INTEL_E1000_ETHERNET_DEVICE(0x1027),
82 INTEL_E1000_ETHERNET_DEVICE(0x1028), 82 INTEL_E1000_ETHERNET_DEVICE(0x1028),
83 INTEL_E1000_ETHERNET_DEVICE(0x105E),
84 INTEL_E1000_ETHERNET_DEVICE(0x105F),
85 INTEL_E1000_ETHERNET_DEVICE(0x1060),
83 INTEL_E1000_ETHERNET_DEVICE(0x1075), 86 INTEL_E1000_ETHERNET_DEVICE(0x1075),
84 INTEL_E1000_ETHERNET_DEVICE(0x1076), 87 INTEL_E1000_ETHERNET_DEVICE(0x1076),
85 INTEL_E1000_ETHERNET_DEVICE(0x1077), 88 INTEL_E1000_ETHERNET_DEVICE(0x1077),
@@ -88,10 +91,13 @@ static struct pci_device_id e1000_pci_tbl[] = {
88 INTEL_E1000_ETHERNET_DEVICE(0x107A), 91 INTEL_E1000_ETHERNET_DEVICE(0x107A),
89 INTEL_E1000_ETHERNET_DEVICE(0x107B), 92 INTEL_E1000_ETHERNET_DEVICE(0x107B),
90 INTEL_E1000_ETHERNET_DEVICE(0x107C), 93 INTEL_E1000_ETHERNET_DEVICE(0x107C),
94 INTEL_E1000_ETHERNET_DEVICE(0x107D),
95 INTEL_E1000_ETHERNET_DEVICE(0x107E),
96 INTEL_E1000_ETHERNET_DEVICE(0x107F),
91 INTEL_E1000_ETHERNET_DEVICE(0x108A), 97 INTEL_E1000_ETHERNET_DEVICE(0x108A),
92 INTEL_E1000_ETHERNET_DEVICE(0x108B), 98 INTEL_E1000_ETHERNET_DEVICE(0x108B),
93 INTEL_E1000_ETHERNET_DEVICE(0x108C), 99 INTEL_E1000_ETHERNET_DEVICE(0x108C),
94 INTEL_E1000_ETHERNET_DEVICE(0x1099), 100 INTEL_E1000_ETHERNET_DEVICE(0x109A),
95 /* required last entry */ 101 /* required last entry */
96 {0,} 102 {0,}
97}; 103};
@@ -102,10 +108,18 @@ int e1000_up(struct e1000_adapter *adapter);
102void e1000_down(struct e1000_adapter *adapter); 108void e1000_down(struct e1000_adapter *adapter);
103void e1000_reset(struct e1000_adapter *adapter); 109void e1000_reset(struct e1000_adapter *adapter);
104int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx); 110int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
105int e1000_setup_tx_resources(struct e1000_adapter *adapter); 111int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
106int e1000_setup_rx_resources(struct e1000_adapter *adapter); 112int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
107void e1000_free_tx_resources(struct e1000_adapter *adapter); 113void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
108void e1000_free_rx_resources(struct e1000_adapter *adapter); 114void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
115int e1000_setup_tx_resources(struct e1000_adapter *adapter,
116 struct e1000_tx_ring *txdr);
117int e1000_setup_rx_resources(struct e1000_adapter *adapter,
118 struct e1000_rx_ring *rxdr);
119void e1000_free_tx_resources(struct e1000_adapter *adapter,
120 struct e1000_tx_ring *tx_ring);
121void e1000_free_rx_resources(struct e1000_adapter *adapter,
122 struct e1000_rx_ring *rx_ring);
109void e1000_update_stats(struct e1000_adapter *adapter); 123void e1000_update_stats(struct e1000_adapter *adapter);
110 124
111/* Local Function Prototypes */ 125/* Local Function Prototypes */
@@ -114,14 +128,22 @@ static int e1000_init_module(void);
114static void e1000_exit_module(void); 128static void e1000_exit_module(void);
115static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent); 129static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
116static void __devexit e1000_remove(struct pci_dev *pdev); 130static void __devexit e1000_remove(struct pci_dev *pdev);
131static int e1000_alloc_queues(struct e1000_adapter *adapter);
132#ifdef CONFIG_E1000_MQ
133static void e1000_setup_queue_mapping(struct e1000_adapter *adapter);
134#endif
117static int e1000_sw_init(struct e1000_adapter *adapter); 135static int e1000_sw_init(struct e1000_adapter *adapter);
118static int e1000_open(struct net_device *netdev); 136static int e1000_open(struct net_device *netdev);
119static int e1000_close(struct net_device *netdev); 137static int e1000_close(struct net_device *netdev);
120static void e1000_configure_tx(struct e1000_adapter *adapter); 138static void e1000_configure_tx(struct e1000_adapter *adapter);
121static void e1000_configure_rx(struct e1000_adapter *adapter); 139static void e1000_configure_rx(struct e1000_adapter *adapter);
122static void e1000_setup_rctl(struct e1000_adapter *adapter); 140static void e1000_setup_rctl(struct e1000_adapter *adapter);
123static void e1000_clean_tx_ring(struct e1000_adapter *adapter); 141static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
124static void e1000_clean_rx_ring(struct e1000_adapter *adapter); 142static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
143static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
144 struct e1000_tx_ring *tx_ring);
145static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
146 struct e1000_rx_ring *rx_ring);
125static void e1000_set_multi(struct net_device *netdev); 147static void e1000_set_multi(struct net_device *netdev);
126static void e1000_update_phy_info(unsigned long data); 148static void e1000_update_phy_info(unsigned long data);
127static void e1000_watchdog(unsigned long data); 149static void e1000_watchdog(unsigned long data);
@@ -132,19 +154,26 @@ static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
132static int e1000_change_mtu(struct net_device *netdev, int new_mtu); 154static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
133static int e1000_set_mac(struct net_device *netdev, void *p); 155static int e1000_set_mac(struct net_device *netdev, void *p);
134static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs); 156static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
135static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter); 157static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
158 struct e1000_tx_ring *tx_ring);
136#ifdef CONFIG_E1000_NAPI 159#ifdef CONFIG_E1000_NAPI
137static int e1000_clean(struct net_device *netdev, int *budget); 160static int e1000_clean(struct net_device *poll_dev, int *budget);
138static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter, 161static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
162 struct e1000_rx_ring *rx_ring,
139 int *work_done, int work_to_do); 163 int *work_done, int work_to_do);
140static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, 164static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
165 struct e1000_rx_ring *rx_ring,
141 int *work_done, int work_to_do); 166 int *work_done, int work_to_do);
142#else 167#else
143static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter); 168static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
144static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter); 169 struct e1000_rx_ring *rx_ring);
170static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
171 struct e1000_rx_ring *rx_ring);
145#endif 172#endif
146static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter); 173static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
147static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter); 174 struct e1000_rx_ring *rx_ring);
175static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
176 struct e1000_rx_ring *rx_ring);
148static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd); 177static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
149static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, 178static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
150 int cmd); 179 int cmd);
@@ -162,8 +191,8 @@ 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); 191static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
163static void e1000_restore_vlan(struct e1000_adapter *adapter); 192static void e1000_restore_vlan(struct e1000_adapter *adapter);
164 193
165static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
166#ifdef CONFIG_PM 194#ifdef CONFIG_PM
195static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
167static int e1000_resume(struct pci_dev *pdev); 196static int e1000_resume(struct pci_dev *pdev);
168#endif 197#endif
169 198
@@ -172,6 +201,11 @@ static int e1000_resume(struct pci_dev *pdev);
172static void e1000_netpoll (struct net_device *netdev); 201static void e1000_netpoll (struct net_device *netdev);
173#endif 202#endif
174 203
204#ifdef CONFIG_E1000_MQ
205/* for multiple Rx queues */
206void e1000_rx_schedule(void *data);
207#endif
208
175/* Exported from other modules */ 209/* Exported from other modules */
176 210
177extern void e1000_check_options(struct e1000_adapter *adapter); 211extern void e1000_check_options(struct e1000_adapter *adapter);
@@ -289,7 +323,7 @@ int
289e1000_up(struct e1000_adapter *adapter) 323e1000_up(struct e1000_adapter *adapter)
290{ 324{
291 struct net_device *netdev = adapter->netdev; 325 struct net_device *netdev = adapter->netdev;
292 int err; 326 int i, err;
293 327
294 /* hardware has been reset, we need to reload some things */ 328 /* hardware has been reset, we need to reload some things */
295 329
@@ -308,7 +342,8 @@ e1000_up(struct e1000_adapter *adapter)
308 e1000_configure_tx(adapter); 342 e1000_configure_tx(adapter);
309 e1000_setup_rctl(adapter); 343 e1000_setup_rctl(adapter);
310 e1000_configure_rx(adapter); 344 e1000_configure_rx(adapter);
311 adapter->alloc_rx_buf(adapter); 345 for (i = 0; i < adapter->num_queues; i++)
346 adapter->alloc_rx_buf(adapter, &adapter->rx_ring[i]);
312 347
313#ifdef CONFIG_PCI_MSI 348#ifdef CONFIG_PCI_MSI
314 if(adapter->hw.mac_type > e1000_82547_rev_2) { 349 if(adapter->hw.mac_type > e1000_82547_rev_2) {
@@ -344,6 +379,9 @@ e1000_down(struct e1000_adapter *adapter)
344 struct net_device *netdev = adapter->netdev; 379 struct net_device *netdev = adapter->netdev;
345 380
346 e1000_irq_disable(adapter); 381 e1000_irq_disable(adapter);
382#ifdef CONFIG_E1000_MQ
383 while (atomic_read(&adapter->rx_sched_call_data.count) != 0);
384#endif
347 free_irq(adapter->pdev->irq, netdev); 385 free_irq(adapter->pdev->irq, netdev);
348#ifdef CONFIG_PCI_MSI 386#ifdef CONFIG_PCI_MSI
349 if(adapter->hw.mac_type > e1000_82547_rev_2 && 387 if(adapter->hw.mac_type > e1000_82547_rev_2 &&
@@ -363,11 +401,10 @@ e1000_down(struct e1000_adapter *adapter)
363 netif_stop_queue(netdev); 401 netif_stop_queue(netdev);
364 402
365 e1000_reset(adapter); 403 e1000_reset(adapter);
366 e1000_clean_tx_ring(adapter); 404 e1000_clean_all_tx_rings(adapter);
367 e1000_clean_rx_ring(adapter); 405 e1000_clean_all_rx_rings(adapter);
368 406
369 /* If WoL is not enabled 407 /* If WoL is not enabled and management mode is not IAMT
370 * and management mode is not IAMT
371 * Power down the PHY so no link is implied when interface is down */ 408 * Power down the PHY so no link is implied when interface is down */
372 if(!adapter->wol && adapter->hw.mac_type >= e1000_82540 && 409 if(!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
373 adapter->hw.media_type == e1000_media_type_copper && 410 adapter->hw.media_type == e1000_media_type_copper &&
@@ -398,6 +435,10 @@ e1000_reset(struct e1000_adapter *adapter)
398 case e1000_82547_rev_2: 435 case e1000_82547_rev_2:
399 pba = E1000_PBA_30K; 436 pba = E1000_PBA_30K;
400 break; 437 break;
438 case e1000_82571:
439 case e1000_82572:
440 pba = E1000_PBA_38K;
441 break;
401 case e1000_82573: 442 case e1000_82573:
402 pba = E1000_PBA_12K; 443 pba = E1000_PBA_12K;
403 break; 444 break;
@@ -475,6 +516,7 @@ e1000_probe(struct pci_dev *pdev,
475 struct net_device *netdev; 516 struct net_device *netdev;
476 struct e1000_adapter *adapter; 517 struct e1000_adapter *adapter;
477 unsigned long mmio_start, mmio_len; 518 unsigned long mmio_start, mmio_len;
519 uint32_t ctrl_ext;
478 uint32_t swsm; 520 uint32_t swsm;
479 521
480 static int cards_found = 0; 522 static int cards_found = 0;
@@ -614,8 +656,9 @@ e1000_probe(struct pci_dev *pdev,
614 if(e1000_read_mac_addr(&adapter->hw)) 656 if(e1000_read_mac_addr(&adapter->hw))
615 DPRINTK(PROBE, ERR, "EEPROM Read Error\n"); 657 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
616 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len); 658 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
659 memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
617 660
618 if(!is_valid_ether_addr(netdev->dev_addr)) { 661 if(!is_valid_ether_addr(netdev->perm_addr)) {
619 DPRINTK(PROBE, ERR, "Invalid MAC Address\n"); 662 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
620 err = -EIO; 663 err = -EIO;
621 goto err_eeprom; 664 goto err_eeprom;
@@ -687,6 +730,12 @@ e1000_probe(struct pci_dev *pdev,
687 730
688 /* Let firmware know the driver has taken over */ 731 /* Let firmware know the driver has taken over */
689 switch(adapter->hw.mac_type) { 732 switch(adapter->hw.mac_type) {
733 case e1000_82571:
734 case e1000_82572:
735 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
736 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
737 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
738 break;
690 case e1000_82573: 739 case e1000_82573:
691 swsm = E1000_READ_REG(&adapter->hw, SWSM); 740 swsm = E1000_READ_REG(&adapter->hw, SWSM);
692 E1000_WRITE_REG(&adapter->hw, SWSM, 741 E1000_WRITE_REG(&adapter->hw, SWSM,
@@ -731,7 +780,11 @@ e1000_remove(struct pci_dev *pdev)
731{ 780{
732 struct net_device *netdev = pci_get_drvdata(pdev); 781 struct net_device *netdev = pci_get_drvdata(pdev);
733 struct e1000_adapter *adapter = netdev_priv(netdev); 782 struct e1000_adapter *adapter = netdev_priv(netdev);
783 uint32_t ctrl_ext;
734 uint32_t manc, swsm; 784 uint32_t manc, swsm;
785#ifdef CONFIG_E1000_NAPI
786 int i;
787#endif
735 788
736 flush_scheduled_work(); 789 flush_scheduled_work();
737 790
@@ -745,6 +798,12 @@ e1000_remove(struct pci_dev *pdev)
745 } 798 }
746 799
747 switch(adapter->hw.mac_type) { 800 switch(adapter->hw.mac_type) {
801 case e1000_82571:
802 case e1000_82572:
803 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
804 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
805 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
806 break;
748 case e1000_82573: 807 case e1000_82573:
749 swsm = E1000_READ_REG(&adapter->hw, SWSM); 808 swsm = E1000_READ_REG(&adapter->hw, SWSM);
750 E1000_WRITE_REG(&adapter->hw, SWSM, 809 E1000_WRITE_REG(&adapter->hw, SWSM,
@@ -756,13 +815,27 @@ e1000_remove(struct pci_dev *pdev)
756 } 815 }
757 816
758 unregister_netdev(netdev); 817 unregister_netdev(netdev);
818#ifdef CONFIG_E1000_NAPI
819 for (i = 0; i < adapter->num_queues; i++)
820 __dev_put(&adapter->polling_netdev[i]);
821#endif
759 822
760 if(!e1000_check_phy_reset_block(&adapter->hw)) 823 if(!e1000_check_phy_reset_block(&adapter->hw))
761 e1000_phy_hw_reset(&adapter->hw); 824 e1000_phy_hw_reset(&adapter->hw);
762 825
826 kfree(adapter->tx_ring);
827 kfree(adapter->rx_ring);
828#ifdef CONFIG_E1000_NAPI
829 kfree(adapter->polling_netdev);
830#endif
831
763 iounmap(adapter->hw.hw_addr); 832 iounmap(adapter->hw.hw_addr);
764 pci_release_regions(pdev); 833 pci_release_regions(pdev);
765 834
835#ifdef CONFIG_E1000_MQ
836 free_percpu(adapter->cpu_netdev);
837 free_percpu(adapter->cpu_tx_ring);
838#endif
766 free_netdev(netdev); 839 free_netdev(netdev);
767 840
768 pci_disable_device(pdev); 841 pci_disable_device(pdev);
@@ -783,6 +856,9 @@ e1000_sw_init(struct e1000_adapter *adapter)
783 struct e1000_hw *hw = &adapter->hw; 856 struct e1000_hw *hw = &adapter->hw;
784 struct net_device *netdev = adapter->netdev; 857 struct net_device *netdev = adapter->netdev;
785 struct pci_dev *pdev = adapter->pdev; 858 struct pci_dev *pdev = adapter->pdev;
859#ifdef CONFIG_E1000_NAPI
860 int i;
861#endif
786 862
787 /* PCI config space info */ 863 /* PCI config space info */
788 864
@@ -840,14 +916,123 @@ e1000_sw_init(struct e1000_adapter *adapter)
840 hw->master_slave = E1000_MASTER_SLAVE; 916 hw->master_slave = E1000_MASTER_SLAVE;
841 } 917 }
842 918
919#ifdef CONFIG_E1000_MQ
920 /* Number of supported queues */
921 switch (hw->mac_type) {
922 case e1000_82571:
923 case e1000_82572:
924 adapter->num_queues = 2;
925 break;
926 default:
927 adapter->num_queues = 1;
928 break;
929 }
930 adapter->num_queues = min(adapter->num_queues, num_online_cpus());
931#else
932 adapter->num_queues = 1;
933#endif
934
935 if (e1000_alloc_queues(adapter)) {
936 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
937 return -ENOMEM;
938 }
939
940#ifdef CONFIG_E1000_NAPI
941 for (i = 0; i < adapter->num_queues; i++) {
942 adapter->polling_netdev[i].priv = adapter;
943 adapter->polling_netdev[i].poll = &e1000_clean;
944 adapter->polling_netdev[i].weight = 64;
945 dev_hold(&adapter->polling_netdev[i]);
946 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
947 }
948#endif
949
950#ifdef CONFIG_E1000_MQ
951 e1000_setup_queue_mapping(adapter);
952#endif
953
843 atomic_set(&adapter->irq_sem, 1); 954 atomic_set(&adapter->irq_sem, 1);
844 spin_lock_init(&adapter->stats_lock); 955 spin_lock_init(&adapter->stats_lock);
845 spin_lock_init(&adapter->tx_lock);
846 956
847 return 0; 957 return 0;
848} 958}
849 959
850/** 960/**
961 * e1000_alloc_queues - Allocate memory for all rings
962 * @adapter: board private structure to initialize
963 *
964 * We allocate one ring per queue at run-time since we don't know the
965 * number of queues at compile-time. The polling_netdev array is
966 * intended for Multiqueue, but should work fine with a single queue.
967 **/
968
969static int __devinit
970e1000_alloc_queues(struct e1000_adapter *adapter)
971{
972 int size;
973
974 size = sizeof(struct e1000_tx_ring) * adapter->num_queues;
975 adapter->tx_ring = kmalloc(size, GFP_KERNEL);
976 if (!adapter->tx_ring)
977 return -ENOMEM;
978 memset(adapter->tx_ring, 0, size);
979
980 size = sizeof(struct e1000_rx_ring) * adapter->num_queues;
981 adapter->rx_ring = kmalloc(size, GFP_KERNEL);
982 if (!adapter->rx_ring) {
983 kfree(adapter->tx_ring);
984 return -ENOMEM;
985 }
986 memset(adapter->rx_ring, 0, size);
987
988#ifdef CONFIG_E1000_NAPI
989 size = sizeof(struct net_device) * adapter->num_queues;
990 adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
991 if (!adapter->polling_netdev) {
992 kfree(adapter->tx_ring);
993 kfree(adapter->rx_ring);
994 return -ENOMEM;
995 }
996 memset(adapter->polling_netdev, 0, size);
997#endif
998
999 return E1000_SUCCESS;
1000}
1001
1002#ifdef CONFIG_E1000_MQ
1003static void __devinit
1004e1000_setup_queue_mapping(struct e1000_adapter *adapter)
1005{
1006 int i, cpu;
1007
1008 adapter->rx_sched_call_data.func = e1000_rx_schedule;
1009 adapter->rx_sched_call_data.info = adapter->netdev;
1010 cpus_clear(adapter->rx_sched_call_data.cpumask);
1011
1012 adapter->cpu_netdev = alloc_percpu(struct net_device *);
1013 adapter->cpu_tx_ring = alloc_percpu(struct e1000_tx_ring *);
1014
1015 lock_cpu_hotplug();
1016 i = 0;
1017 for_each_online_cpu(cpu) {
1018 *per_cpu_ptr(adapter->cpu_tx_ring, cpu) = &adapter->tx_ring[i % adapter->num_queues];
1019 /* This is incomplete because we'd like to assign separate
1020 * physical cpus to these netdev polling structures and
1021 * avoid saturating a subset of cpus.
1022 */
1023 if (i < adapter->num_queues) {
1024 *per_cpu_ptr(adapter->cpu_netdev, cpu) = &adapter->polling_netdev[i];
1025 adapter->cpu_for_queue[i] = cpu;
1026 } else
1027 *per_cpu_ptr(adapter->cpu_netdev, cpu) = NULL;
1028
1029 i++;
1030 }
1031 unlock_cpu_hotplug();
1032}
1033#endif
1034
1035/**
851 * e1000_open - Called when a network interface is made active 1036 * e1000_open - Called when a network interface is made active
852 * @netdev: network interface device structure 1037 * @netdev: network interface device structure
853 * 1038 *
@@ -868,12 +1053,12 @@ e1000_open(struct net_device *netdev)
868 1053
869 /* allocate transmit descriptors */ 1054 /* allocate transmit descriptors */
870 1055
871 if((err = e1000_setup_tx_resources(adapter))) 1056 if ((err = e1000_setup_all_tx_resources(adapter)))
872 goto err_setup_tx; 1057 goto err_setup_tx;
873 1058
874 /* allocate receive descriptors */ 1059 /* allocate receive descriptors */
875 1060
876 if((err = e1000_setup_rx_resources(adapter))) 1061 if ((err = e1000_setup_all_rx_resources(adapter)))
877 goto err_setup_rx; 1062 goto err_setup_rx;
878 1063
879 if((err = e1000_up(adapter))) 1064 if((err = e1000_up(adapter)))
@@ -887,9 +1072,9 @@ e1000_open(struct net_device *netdev)
887 return E1000_SUCCESS; 1072 return E1000_SUCCESS;
888 1073
889err_up: 1074err_up:
890 e1000_free_rx_resources(adapter); 1075 e1000_free_all_rx_resources(adapter);
891err_setup_rx: 1076err_setup_rx:
892 e1000_free_tx_resources(adapter); 1077 e1000_free_all_tx_resources(adapter);
893err_setup_tx: 1078err_setup_tx:
894 e1000_reset(adapter); 1079 e1000_reset(adapter);
895 1080
@@ -915,8 +1100,8 @@ e1000_close(struct net_device *netdev)
915 1100
916 e1000_down(adapter); 1101 e1000_down(adapter);
917 1102
918 e1000_free_tx_resources(adapter); 1103 e1000_free_all_tx_resources(adapter);
919 e1000_free_rx_resources(adapter); 1104 e1000_free_all_rx_resources(adapter);
920 1105
921 if((adapter->hw.mng_cookie.status & 1106 if((adapter->hw.mng_cookie.status &
922 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) { 1107 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
@@ -951,25 +1136,28 @@ e1000_check_64k_bound(struct e1000_adapter *adapter,
951/** 1136/**
952 * e1000_setup_tx_resources - allocate Tx resources (Descriptors) 1137 * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
953 * @adapter: board private structure 1138 * @adapter: board private structure
1139 * @txdr: tx descriptor ring (for a specific queue) to setup
954 * 1140 *
955 * Return 0 on success, negative on failure 1141 * Return 0 on success, negative on failure
956 **/ 1142 **/
957 1143
958int 1144int
959e1000_setup_tx_resources(struct e1000_adapter *adapter) 1145e1000_setup_tx_resources(struct e1000_adapter *adapter,
1146 struct e1000_tx_ring *txdr)
960{ 1147{
961 struct e1000_desc_ring *txdr = &adapter->tx_ring;
962 struct pci_dev *pdev = adapter->pdev; 1148 struct pci_dev *pdev = adapter->pdev;
963 int size; 1149 int size;
964 1150
965 size = sizeof(struct e1000_buffer) * txdr->count; 1151 size = sizeof(struct e1000_buffer) * txdr->count;
966 txdr->buffer_info = vmalloc(size); 1152
1153 txdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
967 if(!txdr->buffer_info) { 1154 if(!txdr->buffer_info) {
968 DPRINTK(PROBE, ERR, 1155 DPRINTK(PROBE, ERR,
969 "Unable to allocate memory for the transmit descriptor ring\n"); 1156 "Unable to allocate memory for the transmit descriptor ring\n");
970 return -ENOMEM; 1157 return -ENOMEM;
971 } 1158 }
972 memset(txdr->buffer_info, 0, size); 1159 memset(txdr->buffer_info, 0, size);
1160 memset(&txdr->previous_buffer_info, 0, sizeof(struct e1000_buffer));
973 1161
974 /* round up to nearest 4K */ 1162 /* round up to nearest 4K */
975 1163
@@ -1018,11 +1206,41 @@ setup_tx_desc_die:
1018 1206
1019 txdr->next_to_use = 0; 1207 txdr->next_to_use = 0;
1020 txdr->next_to_clean = 0; 1208 txdr->next_to_clean = 0;
1209 spin_lock_init(&txdr->tx_lock);
1021 1210
1022 return 0; 1211 return 0;
1023} 1212}
1024 1213
1025/** 1214/**
1215 * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1216 * (Descriptors) for all queues
1217 * @adapter: board private structure
1218 *
1219 * If this function returns with an error, then it's possible one or
1220 * more of the rings is populated (while the rest are not). It is the
1221 * callers duty to clean those orphaned rings.
1222 *
1223 * Return 0 on success, negative on failure
1224 **/
1225
1226int
1227e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1228{
1229 int i, err = 0;
1230
1231 for (i = 0; i < adapter->num_queues; i++) {
1232 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1233 if (err) {
1234 DPRINTK(PROBE, ERR,
1235 "Allocation for Tx Queue %u failed\n", i);
1236 break;
1237 }
1238 }
1239
1240 return err;
1241}
1242
1243/**
1026 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset 1244 * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1027 * @adapter: board private structure 1245 * @adapter: board private structure
1028 * 1246 *
@@ -1032,23 +1250,43 @@ setup_tx_desc_die:
1032static void 1250static void
1033e1000_configure_tx(struct e1000_adapter *adapter) 1251e1000_configure_tx(struct e1000_adapter *adapter)
1034{ 1252{
1035 uint64_t tdba = adapter->tx_ring.dma; 1253 uint64_t tdba;
1036 uint32_t tdlen = adapter->tx_ring.count * sizeof(struct e1000_tx_desc); 1254 struct e1000_hw *hw = &adapter->hw;
1037 uint32_t tctl, tipg; 1255 uint32_t tdlen, tctl, tipg, tarc;
1038
1039 E1000_WRITE_REG(&adapter->hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1040 E1000_WRITE_REG(&adapter->hw, TDBAH, (tdba >> 32));
1041
1042 E1000_WRITE_REG(&adapter->hw, TDLEN, tdlen);
1043 1256
1044 /* Setup the HW Tx Head and Tail descriptor pointers */ 1257 /* Setup the HW Tx Head and Tail descriptor pointers */
1045 1258
1046 E1000_WRITE_REG(&adapter->hw, TDH, 0); 1259 switch (adapter->num_queues) {
1047 E1000_WRITE_REG(&adapter->hw, TDT, 0); 1260 case 2:
1261 tdba = adapter->tx_ring[1].dma;
1262 tdlen = adapter->tx_ring[1].count *
1263 sizeof(struct e1000_tx_desc);
1264 E1000_WRITE_REG(hw, TDBAL1, (tdba & 0x00000000ffffffffULL));
1265 E1000_WRITE_REG(hw, TDBAH1, (tdba >> 32));
1266 E1000_WRITE_REG(hw, TDLEN1, tdlen);
1267 E1000_WRITE_REG(hw, TDH1, 0);
1268 E1000_WRITE_REG(hw, TDT1, 0);
1269 adapter->tx_ring[1].tdh = E1000_TDH1;
1270 adapter->tx_ring[1].tdt = E1000_TDT1;
1271 /* Fall Through */
1272 case 1:
1273 default:
1274 tdba = adapter->tx_ring[0].dma;
1275 tdlen = adapter->tx_ring[0].count *
1276 sizeof(struct e1000_tx_desc);
1277 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1278 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1279 E1000_WRITE_REG(hw, TDLEN, tdlen);
1280 E1000_WRITE_REG(hw, TDH, 0);
1281 E1000_WRITE_REG(hw, TDT, 0);
1282 adapter->tx_ring[0].tdh = E1000_TDH;
1283 adapter->tx_ring[0].tdt = E1000_TDT;
1284 break;
1285 }
1048 1286
1049 /* Set the default values for the Tx Inter Packet Gap timer */ 1287 /* Set the default values for the Tx Inter Packet Gap timer */
1050 1288
1051 switch (adapter->hw.mac_type) { 1289 switch (hw->mac_type) {
1052 case e1000_82542_rev2_0: 1290 case e1000_82542_rev2_0:
1053 case e1000_82542_rev2_1: 1291 case e1000_82542_rev2_1:
1054 tipg = DEFAULT_82542_TIPG_IPGT; 1292 tipg = DEFAULT_82542_TIPG_IPGT;
@@ -1056,67 +1294,81 @@ e1000_configure_tx(struct e1000_adapter *adapter)
1056 tipg |= DEFAULT_82542_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT; 1294 tipg |= DEFAULT_82542_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
1057 break; 1295 break;
1058 default: 1296 default:
1059 if(adapter->hw.media_type == e1000_media_type_fiber || 1297 if (hw->media_type == e1000_media_type_fiber ||
1060 adapter->hw.media_type == e1000_media_type_internal_serdes) 1298 hw->media_type == e1000_media_type_internal_serdes)
1061 tipg = DEFAULT_82543_TIPG_IPGT_FIBER; 1299 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1062 else 1300 else
1063 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; 1301 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1064 tipg |= DEFAULT_82543_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT; 1302 tipg |= DEFAULT_82543_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT;
1065 tipg |= DEFAULT_82543_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT; 1303 tipg |= DEFAULT_82543_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT;
1066 } 1304 }
1067 E1000_WRITE_REG(&adapter->hw, TIPG, tipg); 1305 E1000_WRITE_REG(hw, TIPG, tipg);
1068 1306
1069 /* Set the Tx Interrupt Delay register */ 1307 /* Set the Tx Interrupt Delay register */
1070 1308
1071 E1000_WRITE_REG(&adapter->hw, TIDV, adapter->tx_int_delay); 1309 E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1072 if(adapter->hw.mac_type >= e1000_82540) 1310 if (hw->mac_type >= e1000_82540)
1073 E1000_WRITE_REG(&adapter->hw, TADV, adapter->tx_abs_int_delay); 1311 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
1074 1312
1075 /* Program the Transmit Control Register */ 1313 /* Program the Transmit Control Register */
1076 1314
1077 tctl = E1000_READ_REG(&adapter->hw, TCTL); 1315 tctl = E1000_READ_REG(hw, TCTL);
1078 1316
1079 tctl &= ~E1000_TCTL_CT; 1317 tctl &= ~E1000_TCTL_CT;
1080 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP | 1318 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP | E1000_TCTL_RTLC |
1081 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); 1319 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1082 1320
1083 E1000_WRITE_REG(&adapter->hw, TCTL, tctl); 1321 E1000_WRITE_REG(hw, TCTL, tctl);
1322
1323 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1324 tarc = E1000_READ_REG(hw, TARC0);
1325 tarc |= ((1 << 25) | (1 << 21));
1326 E1000_WRITE_REG(hw, TARC0, tarc);
1327 tarc = E1000_READ_REG(hw, TARC1);
1328 tarc |= (1 << 25);
1329 if (tctl & E1000_TCTL_MULR)
1330 tarc &= ~(1 << 28);
1331 else
1332 tarc |= (1 << 28);
1333 E1000_WRITE_REG(hw, TARC1, tarc);
1334 }
1084 1335
1085 e1000_config_collision_dist(&adapter->hw); 1336 e1000_config_collision_dist(hw);
1086 1337
1087 /* Setup Transmit Descriptor Settings for eop descriptor */ 1338 /* Setup Transmit Descriptor Settings for eop descriptor */
1088 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP | 1339 adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1089 E1000_TXD_CMD_IFCS; 1340 E1000_TXD_CMD_IFCS;
1090 1341
1091 if(adapter->hw.mac_type < e1000_82543) 1342 if (hw->mac_type < e1000_82543)
1092 adapter->txd_cmd |= E1000_TXD_CMD_RPS; 1343 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1093 else 1344 else
1094 adapter->txd_cmd |= E1000_TXD_CMD_RS; 1345 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1095 1346
1096 /* Cache if we're 82544 running in PCI-X because we'll 1347 /* Cache if we're 82544 running in PCI-X because we'll
1097 * need this to apply a workaround later in the send path. */ 1348 * need this to apply a workaround later in the send path. */
1098 if(adapter->hw.mac_type == e1000_82544 && 1349 if (hw->mac_type == e1000_82544 &&
1099 adapter->hw.bus_type == e1000_bus_type_pcix) 1350 hw->bus_type == e1000_bus_type_pcix)
1100 adapter->pcix_82544 = 1; 1351 adapter->pcix_82544 = 1;
1101} 1352}
1102 1353
1103/** 1354/**
1104 * e1000_setup_rx_resources - allocate Rx resources (Descriptors) 1355 * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1105 * @adapter: board private structure 1356 * @adapter: board private structure
1357 * @rxdr: rx descriptor ring (for a specific queue) to setup
1106 * 1358 *
1107 * Returns 0 on success, negative on failure 1359 * Returns 0 on success, negative on failure
1108 **/ 1360 **/
1109 1361
1110int 1362int
1111e1000_setup_rx_resources(struct e1000_adapter *adapter) 1363e1000_setup_rx_resources(struct e1000_adapter *adapter,
1364 struct e1000_rx_ring *rxdr)
1112{ 1365{
1113 struct e1000_desc_ring *rxdr = &adapter->rx_ring;
1114 struct pci_dev *pdev = adapter->pdev; 1366 struct pci_dev *pdev = adapter->pdev;
1115 int size, desc_len; 1367 int size, desc_len;
1116 1368
1117 size = sizeof(struct e1000_buffer) * rxdr->count; 1369 size = sizeof(struct e1000_buffer) * rxdr->count;
1118 rxdr->buffer_info = vmalloc(size); 1370 rxdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
1119 if(!rxdr->buffer_info) { 1371 if (!rxdr->buffer_info) {
1120 DPRINTK(PROBE, ERR, 1372 DPRINTK(PROBE, ERR,
1121 "Unable to allocate memory for the receive descriptor ring\n"); 1373 "Unable to allocate memory for the receive descriptor ring\n");
1122 return -ENOMEM; 1374 return -ENOMEM;
@@ -1156,13 +1408,13 @@ e1000_setup_rx_resources(struct e1000_adapter *adapter)
1156 1408
1157 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); 1409 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1158 1410
1159 if(!rxdr->desc) { 1411 if (!rxdr->desc) {
1412 DPRINTK(PROBE, ERR,
1413 "Unable to allocate memory for the receive descriptor ring\n");
1160setup_rx_desc_die: 1414setup_rx_desc_die:
1161 vfree(rxdr->buffer_info); 1415 vfree(rxdr->buffer_info);
1162 kfree(rxdr->ps_page); 1416 kfree(rxdr->ps_page);
1163 kfree(rxdr->ps_page_dma); 1417 kfree(rxdr->ps_page_dma);
1164 DPRINTK(PROBE, ERR,
1165 "Unable to allocate memory for the receive descriptor ring\n");
1166 return -ENOMEM; 1418 return -ENOMEM;
1167 } 1419 }
1168 1420
@@ -1174,9 +1426,12 @@ setup_rx_desc_die:
1174 "at %p\n", rxdr->size, rxdr->desc); 1426 "at %p\n", rxdr->size, rxdr->desc);
1175 /* Try again, without freeing the previous */ 1427 /* Try again, without freeing the previous */
1176 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); 1428 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1177 if(!rxdr->desc) {
1178 /* Failed allocation, critical failure */ 1429 /* Failed allocation, critical failure */
1430 if (!rxdr->desc) {
1179 pci_free_consistent(pdev, rxdr->size, olddesc, olddma); 1431 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1432 DPRINTK(PROBE, ERR,
1433 "Unable to allocate memory "
1434 "for the receive descriptor ring\n");
1180 goto setup_rx_desc_die; 1435 goto setup_rx_desc_die;
1181 } 1436 }
1182 1437
@@ -1188,10 +1443,7 @@ setup_rx_desc_die:
1188 DPRINTK(PROBE, ERR, 1443 DPRINTK(PROBE, ERR,
1189 "Unable to allocate aligned memory " 1444 "Unable to allocate aligned memory "
1190 "for the receive descriptor ring\n"); 1445 "for the receive descriptor ring\n");
1191 vfree(rxdr->buffer_info); 1446 goto setup_rx_desc_die;
1192 kfree(rxdr->ps_page);
1193 kfree(rxdr->ps_page_dma);
1194 return -ENOMEM;
1195 } else { 1447 } else {
1196 /* Free old allocation, new allocation was successful */ 1448 /* Free old allocation, new allocation was successful */
1197 pci_free_consistent(pdev, rxdr->size, olddesc, olddma); 1449 pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
@@ -1206,15 +1458,48 @@ setup_rx_desc_die:
1206} 1458}
1207 1459
1208/** 1460/**
1461 * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1462 * (Descriptors) for all queues
1463 * @adapter: board private structure
1464 *
1465 * If this function returns with an error, then it's possible one or
1466 * more of the rings is populated (while the rest are not). It is the
1467 * callers duty to clean those orphaned rings.
1468 *
1469 * Return 0 on success, negative on failure
1470 **/
1471
1472int
1473e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1474{
1475 int i, err = 0;
1476
1477 for (i = 0; i < adapter->num_queues; i++) {
1478 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1479 if (err) {
1480 DPRINTK(PROBE, ERR,
1481 "Allocation for Rx Queue %u failed\n", i);
1482 break;
1483 }
1484 }
1485
1486 return err;
1487}
1488
1489/**
1209 * e1000_setup_rctl - configure the receive control registers 1490 * e1000_setup_rctl - configure the receive control registers
1210 * @adapter: Board private structure 1491 * @adapter: Board private structure
1211 **/ 1492 **/
1212 1493#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1494 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1213static void 1495static void
1214e1000_setup_rctl(struct e1000_adapter *adapter) 1496e1000_setup_rctl(struct e1000_adapter *adapter)
1215{ 1497{
1216 uint32_t rctl, rfctl; 1498 uint32_t rctl, rfctl;
1217 uint32_t psrctl = 0; 1499 uint32_t psrctl = 0;
1500#ifdef CONFIG_E1000_PACKET_SPLIT
1501 uint32_t pages = 0;
1502#endif
1218 1503
1219 rctl = E1000_READ_REG(&adapter->hw, RCTL); 1504 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1220 1505
@@ -1235,7 +1520,7 @@ e1000_setup_rctl(struct e1000_adapter *adapter)
1235 rctl |= E1000_RCTL_LPE; 1520 rctl |= E1000_RCTL_LPE;
1236 1521
1237 /* Setup buffer sizes */ 1522 /* Setup buffer sizes */
1238 if(adapter->hw.mac_type == e1000_82573) { 1523 if(adapter->hw.mac_type >= e1000_82571) {
1239 /* We can now specify buffers in 1K increments. 1524 /* We can now specify buffers in 1K increments.
1240 * BSIZE and BSEX are ignored in this case. */ 1525 * BSIZE and BSEX are ignored in this case. */
1241 rctl |= adapter->rx_buffer_len << 0x11; 1526 rctl |= adapter->rx_buffer_len << 0x11;
@@ -1268,11 +1553,14 @@ e1000_setup_rctl(struct e1000_adapter *adapter)
1268 * followed by the page buffers. Therefore, skb->data is 1553 * followed by the page buffers. Therefore, skb->data is
1269 * sized to hold the largest protocol header. 1554 * sized to hold the largest protocol header.
1270 */ 1555 */
1271 adapter->rx_ps = (adapter->hw.mac_type > e1000_82547_rev_2) 1556 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1272 && (adapter->netdev->mtu 1557 if ((adapter->hw.mac_type > e1000_82547_rev_2) && (pages <= 3) &&
1273 < ((3 * PAGE_SIZE) + adapter->rx_ps_bsize0)); 1558 PAGE_SIZE <= 16384)
1559 adapter->rx_ps_pages = pages;
1560 else
1561 adapter->rx_ps_pages = 0;
1274#endif 1562#endif
1275 if(adapter->rx_ps) { 1563 if (adapter->rx_ps_pages) {
1276 /* Configure extra packet-split registers */ 1564 /* Configure extra packet-split registers */
1277 rfctl = E1000_READ_REG(&adapter->hw, RFCTL); 1565 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1278 rfctl |= E1000_RFCTL_EXTEN; 1566 rfctl |= E1000_RFCTL_EXTEN;
@@ -1284,12 +1572,19 @@ e1000_setup_rctl(struct e1000_adapter *adapter)
1284 1572
1285 psrctl |= adapter->rx_ps_bsize0 >> 1573 psrctl |= adapter->rx_ps_bsize0 >>
1286 E1000_PSRCTL_BSIZE0_SHIFT; 1574 E1000_PSRCTL_BSIZE0_SHIFT;
1287 psrctl |= PAGE_SIZE >> 1575
1288 E1000_PSRCTL_BSIZE1_SHIFT; 1576 switch (adapter->rx_ps_pages) {
1289 psrctl |= PAGE_SIZE << 1577 case 3:
1290 E1000_PSRCTL_BSIZE2_SHIFT; 1578 psrctl |= PAGE_SIZE <<
1291 psrctl |= PAGE_SIZE << 1579 E1000_PSRCTL_BSIZE3_SHIFT;
1292 E1000_PSRCTL_BSIZE3_SHIFT; 1580 case 2:
1581 psrctl |= PAGE_SIZE <<
1582 E1000_PSRCTL_BSIZE2_SHIFT;
1583 case 1:
1584 psrctl |= PAGE_SIZE >>
1585 E1000_PSRCTL_BSIZE1_SHIFT;
1586 break;
1587 }
1293 1588
1294 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl); 1589 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
1295 } 1590 }
@@ -1307,91 +1602,181 @@ e1000_setup_rctl(struct e1000_adapter *adapter)
1307static void 1602static void
1308e1000_configure_rx(struct e1000_adapter *adapter) 1603e1000_configure_rx(struct e1000_adapter *adapter)
1309{ 1604{
1310 uint64_t rdba = adapter->rx_ring.dma; 1605 uint64_t rdba;
1311 uint32_t rdlen, rctl, rxcsum; 1606 struct e1000_hw *hw = &adapter->hw;
1607 uint32_t rdlen, rctl, rxcsum, ctrl_ext;
1608#ifdef CONFIG_E1000_MQ
1609 uint32_t reta, mrqc;
1610 int i;
1611#endif
1312 1612
1313 if(adapter->rx_ps) { 1613 if (adapter->rx_ps_pages) {
1314 rdlen = adapter->rx_ring.count * 1614 rdlen = adapter->rx_ring[0].count *
1315 sizeof(union e1000_rx_desc_packet_split); 1615 sizeof(union e1000_rx_desc_packet_split);
1316 adapter->clean_rx = e1000_clean_rx_irq_ps; 1616 adapter->clean_rx = e1000_clean_rx_irq_ps;
1317 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps; 1617 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1318 } else { 1618 } else {
1319 rdlen = adapter->rx_ring.count * sizeof(struct e1000_rx_desc); 1619 rdlen = adapter->rx_ring[0].count *
1620 sizeof(struct e1000_rx_desc);
1320 adapter->clean_rx = e1000_clean_rx_irq; 1621 adapter->clean_rx = e1000_clean_rx_irq;
1321 adapter->alloc_rx_buf = e1000_alloc_rx_buffers; 1622 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1322 } 1623 }
1323 1624
1324 /* disable receives while setting up the descriptors */ 1625 /* disable receives while setting up the descriptors */
1325 rctl = E1000_READ_REG(&adapter->hw, RCTL); 1626 rctl = E1000_READ_REG(hw, RCTL);
1326 E1000_WRITE_REG(&adapter->hw, RCTL, rctl & ~E1000_RCTL_EN); 1627 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
1327 1628
1328 /* set the Receive Delay Timer Register */ 1629 /* set the Receive Delay Timer Register */
1329 E1000_WRITE_REG(&adapter->hw, RDTR, adapter->rx_int_delay); 1630 E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
1330 1631
1331 if(adapter->hw.mac_type >= e1000_82540) { 1632 if (hw->mac_type >= e1000_82540) {
1332 E1000_WRITE_REG(&adapter->hw, RADV, adapter->rx_abs_int_delay); 1633 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
1333 if(adapter->itr > 1) 1634 if(adapter->itr > 1)
1334 E1000_WRITE_REG(&adapter->hw, ITR, 1635 E1000_WRITE_REG(hw, ITR,
1335 1000000000 / (adapter->itr * 256)); 1636 1000000000 / (adapter->itr * 256));
1336 } 1637 }
1337 1638
1338 /* Setup the Base and Length of the Rx Descriptor Ring */ 1639 if (hw->mac_type >= e1000_82571) {
1339 E1000_WRITE_REG(&adapter->hw, RDBAL, (rdba & 0x00000000ffffffffULL)); 1640 /* Reset delay timers after every interrupt */
1340 E1000_WRITE_REG(&adapter->hw, RDBAH, (rdba >> 32)); 1641 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1642 ctrl_ext |= E1000_CTRL_EXT_CANC;
1643 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1644 E1000_WRITE_FLUSH(hw);
1645 }
1646
1647 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1648 * the Base and Length of the Rx Descriptor Ring */
1649 switch (adapter->num_queues) {
1650#ifdef CONFIG_E1000_MQ
1651 case 2:
1652 rdba = adapter->rx_ring[1].dma;
1653 E1000_WRITE_REG(hw, RDBAL1, (rdba & 0x00000000ffffffffULL));
1654 E1000_WRITE_REG(hw, RDBAH1, (rdba >> 32));
1655 E1000_WRITE_REG(hw, RDLEN1, rdlen);
1656 E1000_WRITE_REG(hw, RDH1, 0);
1657 E1000_WRITE_REG(hw, RDT1, 0);
1658 adapter->rx_ring[1].rdh = E1000_RDH1;
1659 adapter->rx_ring[1].rdt = E1000_RDT1;
1660 /* Fall Through */
1661#endif
1662 case 1:
1663 default:
1664 rdba = adapter->rx_ring[0].dma;
1665 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1666 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1667 E1000_WRITE_REG(hw, RDLEN, rdlen);
1668 E1000_WRITE_REG(hw, RDH, 0);
1669 E1000_WRITE_REG(hw, RDT, 0);
1670 adapter->rx_ring[0].rdh = E1000_RDH;
1671 adapter->rx_ring[0].rdt = E1000_RDT;
1672 break;
1673 }
1674
1675#ifdef CONFIG_E1000_MQ
1676 if (adapter->num_queues > 1) {
1677 uint32_t random[10];
1678
1679 get_random_bytes(&random[0], 40);
1341 1680
1342 E1000_WRITE_REG(&adapter->hw, RDLEN, rdlen); 1681 if (hw->mac_type <= e1000_82572) {
1682 E1000_WRITE_REG(hw, RSSIR, 0);
1683 E1000_WRITE_REG(hw, RSSIM, 0);
1684 }
1685
1686 switch (adapter->num_queues) {
1687 case 2:
1688 default:
1689 reta = 0x00800080;
1690 mrqc = E1000_MRQC_ENABLE_RSS_2Q;
1691 break;
1692 }
1343 1693
1344 /* Setup the HW Rx Head and Tail Descriptor Pointers */ 1694 /* Fill out redirection table */
1345 E1000_WRITE_REG(&adapter->hw, RDH, 0); 1695 for (i = 0; i < 32; i++)
1346 E1000_WRITE_REG(&adapter->hw, RDT, 0); 1696 E1000_WRITE_REG_ARRAY(hw, RETA, i, reta);
1697 /* Fill out hash function seeds */
1698 for (i = 0; i < 10; i++)
1699 E1000_WRITE_REG_ARRAY(hw, RSSRK, i, random[i]);
1700
1701 mrqc |= (E1000_MRQC_RSS_FIELD_IPV4 |
1702 E1000_MRQC_RSS_FIELD_IPV4_TCP);
1703 E1000_WRITE_REG(hw, MRQC, mrqc);
1704 }
1705
1706 /* Multiqueue and packet checksumming are mutually exclusive. */
1707 if (hw->mac_type >= e1000_82571) {
1708 rxcsum = E1000_READ_REG(hw, RXCSUM);
1709 rxcsum |= E1000_RXCSUM_PCSD;
1710 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
1711 }
1712
1713#else
1347 1714
1348 /* Enable 82543 Receive Checksum Offload for TCP and UDP */ 1715 /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1349 if(adapter->hw.mac_type >= e1000_82543) { 1716 if (hw->mac_type >= e1000_82543) {
1350 rxcsum = E1000_READ_REG(&adapter->hw, RXCSUM); 1717 rxcsum = E1000_READ_REG(hw, RXCSUM);
1351 if(adapter->rx_csum == TRUE) { 1718 if(adapter->rx_csum == TRUE) {
1352 rxcsum |= E1000_RXCSUM_TUOFL; 1719 rxcsum |= E1000_RXCSUM_TUOFL;
1353 1720
1354 /* Enable 82573 IPv4 payload checksum for UDP fragments 1721 /* Enable 82571 IPv4 payload checksum for UDP fragments
1355 * Must be used in conjunction with packet-split. */ 1722 * Must be used in conjunction with packet-split. */
1356 if((adapter->hw.mac_type > e1000_82547_rev_2) && 1723 if ((hw->mac_type >= e1000_82571) &&
1357 (adapter->rx_ps)) { 1724 (adapter->rx_ps_pages)) {
1358 rxcsum |= E1000_RXCSUM_IPPCSE; 1725 rxcsum |= E1000_RXCSUM_IPPCSE;
1359 } 1726 }
1360 } else { 1727 } else {
1361 rxcsum &= ~E1000_RXCSUM_TUOFL; 1728 rxcsum &= ~E1000_RXCSUM_TUOFL;
1362 /* don't need to clear IPPCSE as it defaults to 0 */ 1729 /* don't need to clear IPPCSE as it defaults to 0 */
1363 } 1730 }
1364 E1000_WRITE_REG(&adapter->hw, RXCSUM, rxcsum); 1731 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
1365 } 1732 }
1733#endif /* CONFIG_E1000_MQ */
1366 1734
1367 if (adapter->hw.mac_type == e1000_82573) 1735 if (hw->mac_type == e1000_82573)
1368 E1000_WRITE_REG(&adapter->hw, ERT, 0x0100); 1736 E1000_WRITE_REG(hw, ERT, 0x0100);
1369 1737
1370 /* Enable Receives */ 1738 /* Enable Receives */
1371 E1000_WRITE_REG(&adapter->hw, RCTL, rctl); 1739 E1000_WRITE_REG(hw, RCTL, rctl);
1372} 1740}
1373 1741
1374/** 1742/**
1375 * e1000_free_tx_resources - Free Tx Resources 1743 * e1000_free_tx_resources - Free Tx Resources per Queue
1376 * @adapter: board private structure 1744 * @adapter: board private structure
1745 * @tx_ring: Tx descriptor ring for a specific queue
1377 * 1746 *
1378 * Free all transmit software resources 1747 * Free all transmit software resources
1379 **/ 1748 **/
1380 1749
1381void 1750void
1382e1000_free_tx_resources(struct e1000_adapter *adapter) 1751e1000_free_tx_resources(struct e1000_adapter *adapter,
1752 struct e1000_tx_ring *tx_ring)
1383{ 1753{
1384 struct pci_dev *pdev = adapter->pdev; 1754 struct pci_dev *pdev = adapter->pdev;
1385 1755
1386 e1000_clean_tx_ring(adapter); 1756 e1000_clean_tx_ring(adapter, tx_ring);
1387 1757
1388 vfree(adapter->tx_ring.buffer_info); 1758 vfree(tx_ring->buffer_info);
1389 adapter->tx_ring.buffer_info = NULL; 1759 tx_ring->buffer_info = NULL;
1390 1760
1391 pci_free_consistent(pdev, adapter->tx_ring.size, 1761 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1392 adapter->tx_ring.desc, adapter->tx_ring.dma); 1762
1763 tx_ring->desc = NULL;
1764}
1765
1766/**
1767 * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1768 * @adapter: board private structure
1769 *
1770 * Free all transmit software resources
1771 **/
1772
1773void
1774e1000_free_all_tx_resources(struct e1000_adapter *adapter)
1775{
1776 int i;
1393 1777
1394 adapter->tx_ring.desc = NULL; 1778 for (i = 0; i < adapter->num_queues; i++)
1779 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
1395} 1780}
1396 1781
1397static inline void 1782static inline void
@@ -1414,21 +1799,22 @@ e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1414/** 1799/**
1415 * e1000_clean_tx_ring - Free Tx Buffers 1800 * e1000_clean_tx_ring - Free Tx Buffers
1416 * @adapter: board private structure 1801 * @adapter: board private structure
1802 * @tx_ring: ring to be cleaned
1417 **/ 1803 **/
1418 1804
1419static void 1805static void
1420e1000_clean_tx_ring(struct e1000_adapter *adapter) 1806e1000_clean_tx_ring(struct e1000_adapter *adapter,
1807 struct e1000_tx_ring *tx_ring)
1421{ 1808{
1422 struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
1423 struct e1000_buffer *buffer_info; 1809 struct e1000_buffer *buffer_info;
1424 unsigned long size; 1810 unsigned long size;
1425 unsigned int i; 1811 unsigned int i;
1426 1812
1427 /* Free all the Tx ring sk_buffs */ 1813 /* Free all the Tx ring sk_buffs */
1428 1814
1429 if (likely(adapter->previous_buffer_info.skb != NULL)) { 1815 if (likely(tx_ring->previous_buffer_info.skb != NULL)) {
1430 e1000_unmap_and_free_tx_resource(adapter, 1816 e1000_unmap_and_free_tx_resource(adapter,
1431 &adapter->previous_buffer_info); 1817 &tx_ring->previous_buffer_info);
1432 } 1818 }
1433 1819
1434 for(i = 0; i < tx_ring->count; i++) { 1820 for(i = 0; i < tx_ring->count; i++) {
@@ -1446,24 +1832,39 @@ e1000_clean_tx_ring(struct e1000_adapter *adapter)
1446 tx_ring->next_to_use = 0; 1832 tx_ring->next_to_use = 0;
1447 tx_ring->next_to_clean = 0; 1833 tx_ring->next_to_clean = 0;
1448 1834
1449 E1000_WRITE_REG(&adapter->hw, TDH, 0); 1835 writel(0, adapter->hw.hw_addr + tx_ring->tdh);
1450 E1000_WRITE_REG(&adapter->hw, TDT, 0); 1836 writel(0, adapter->hw.hw_addr + tx_ring->tdt);
1837}
1838
1839/**
1840 * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1841 * @adapter: board private structure
1842 **/
1843
1844static void
1845e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
1846{
1847 int i;
1848
1849 for (i = 0; i < adapter->num_queues; i++)
1850 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
1451} 1851}
1452 1852
1453/** 1853/**
1454 * e1000_free_rx_resources - Free Rx Resources 1854 * e1000_free_rx_resources - Free Rx Resources
1455 * @adapter: board private structure 1855 * @adapter: board private structure
1856 * @rx_ring: ring to clean the resources from
1456 * 1857 *
1457 * Free all receive software resources 1858 * Free all receive software resources
1458 **/ 1859 **/
1459 1860
1460void 1861void
1461e1000_free_rx_resources(struct e1000_adapter *adapter) 1862e1000_free_rx_resources(struct e1000_adapter *adapter,
1863 struct e1000_rx_ring *rx_ring)
1462{ 1864{
1463 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
1464 struct pci_dev *pdev = adapter->pdev; 1865 struct pci_dev *pdev = adapter->pdev;
1465 1866
1466 e1000_clean_rx_ring(adapter); 1867 e1000_clean_rx_ring(adapter, rx_ring);
1467 1868
1468 vfree(rx_ring->buffer_info); 1869 vfree(rx_ring->buffer_info);
1469 rx_ring->buffer_info = NULL; 1870 rx_ring->buffer_info = NULL;
@@ -1478,14 +1879,31 @@ e1000_free_rx_resources(struct e1000_adapter *adapter)
1478} 1879}
1479 1880
1480/** 1881/**
1481 * e1000_clean_rx_ring - Free Rx Buffers 1882 * e1000_free_all_rx_resources - Free Rx Resources for All Queues
1883 * @adapter: board private structure
1884 *
1885 * Free all receive software resources
1886 **/
1887
1888void
1889e1000_free_all_rx_resources(struct e1000_adapter *adapter)
1890{
1891 int i;
1892
1893 for (i = 0; i < adapter->num_queues; i++)
1894 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
1895}
1896
1897/**
1898 * e1000_clean_rx_ring - Free Rx Buffers per Queue
1482 * @adapter: board private structure 1899 * @adapter: board private structure
1900 * @rx_ring: ring to free buffers from
1483 **/ 1901 **/
1484 1902
1485static void 1903static void
1486e1000_clean_rx_ring(struct e1000_adapter *adapter) 1904e1000_clean_rx_ring(struct e1000_adapter *adapter,
1905 struct e1000_rx_ring *rx_ring)
1487{ 1906{
1488 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
1489 struct e1000_buffer *buffer_info; 1907 struct e1000_buffer *buffer_info;
1490 struct e1000_ps_page *ps_page; 1908 struct e1000_ps_page *ps_page;
1491 struct e1000_ps_page_dma *ps_page_dma; 1909 struct e1000_ps_page_dma *ps_page_dma;
@@ -1508,7 +1926,7 @@ e1000_clean_rx_ring(struct e1000_adapter *adapter)
1508 dev_kfree_skb(buffer_info->skb); 1926 dev_kfree_skb(buffer_info->skb);
1509 buffer_info->skb = NULL; 1927 buffer_info->skb = NULL;
1510 1928
1511 for(j = 0; j < PS_PAGE_BUFFERS; j++) { 1929 for(j = 0; j < adapter->rx_ps_pages; j++) {
1512 if(!ps_page->ps_page[j]) break; 1930 if(!ps_page->ps_page[j]) break;
1513 pci_unmap_single(pdev, 1931 pci_unmap_single(pdev,
1514 ps_page_dma->ps_page_dma[j], 1932 ps_page_dma->ps_page_dma[j],
@@ -1534,8 +1952,22 @@ e1000_clean_rx_ring(struct e1000_adapter *adapter)
1534 rx_ring->next_to_clean = 0; 1952 rx_ring->next_to_clean = 0;
1535 rx_ring->next_to_use = 0; 1953 rx_ring->next_to_use = 0;
1536 1954
1537 E1000_WRITE_REG(&adapter->hw, RDH, 0); 1955 writel(0, adapter->hw.hw_addr + rx_ring->rdh);
1538 E1000_WRITE_REG(&adapter->hw, RDT, 0); 1956 writel(0, adapter->hw.hw_addr + rx_ring->rdt);
1957}
1958
1959/**
1960 * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
1961 * @adapter: board private structure
1962 **/
1963
1964static void
1965e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
1966{
1967 int i;
1968
1969 for (i = 0; i < adapter->num_queues; i++)
1970 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
1539} 1971}
1540 1972
1541/* The 82542 2.0 (revision 2) needs to have the receive unit in reset 1973/* The 82542 2.0 (revision 2) needs to have the receive unit in reset
@@ -1556,7 +1988,7 @@ e1000_enter_82542_rst(struct e1000_adapter *adapter)
1556 mdelay(5); 1988 mdelay(5);
1557 1989
1558 if(netif_running(netdev)) 1990 if(netif_running(netdev))
1559 e1000_clean_rx_ring(adapter); 1991 e1000_clean_all_rx_rings(adapter);
1560} 1992}
1561 1993
1562static void 1994static void
@@ -1576,7 +2008,7 @@ e1000_leave_82542_rst(struct e1000_adapter *adapter)
1576 2008
1577 if(netif_running(netdev)) { 2009 if(netif_running(netdev)) {
1578 e1000_configure_rx(adapter); 2010 e1000_configure_rx(adapter);
1579 e1000_alloc_rx_buffers(adapter); 2011 e1000_alloc_rx_buffers(adapter, &adapter->rx_ring[0]);
1580 } 2012 }
1581} 2013}
1582 2014
@@ -1607,6 +2039,22 @@ e1000_set_mac(struct net_device *netdev, void *p)
1607 2039
1608 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0); 2040 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
1609 2041
2042 /* With 82571 controllers, LAA may be overwritten (with the default)
2043 * due to controller reset from the other port. */
2044 if (adapter->hw.mac_type == e1000_82571) {
2045 /* activate the work around */
2046 adapter->hw.laa_is_present = 1;
2047
2048 /* Hold a copy of the LAA in RAR[14] This is done so that
2049 * between the time RAR[0] gets clobbered and the time it
2050 * gets fixed (in e1000_watchdog), the actual LAA is in one
2051 * of the RARs and no incoming packets directed to this port
2052 * are dropped. Eventaully the LAA will be in RAR[0] and
2053 * RAR[14] */
2054 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
2055 E1000_RAR_ENTRIES - 1);
2056 }
2057
1610 if(adapter->hw.mac_type == e1000_82542_rev2_0) 2058 if(adapter->hw.mac_type == e1000_82542_rev2_0)
1611 e1000_leave_82542_rst(adapter); 2059 e1000_leave_82542_rst(adapter);
1612 2060
@@ -1629,12 +2077,13 @@ e1000_set_multi(struct net_device *netdev)
1629 struct e1000_adapter *adapter = netdev_priv(netdev); 2077 struct e1000_adapter *adapter = netdev_priv(netdev);
1630 struct e1000_hw *hw = &adapter->hw; 2078 struct e1000_hw *hw = &adapter->hw;
1631 struct dev_mc_list *mc_ptr; 2079 struct dev_mc_list *mc_ptr;
1632 unsigned long flags;
1633 uint32_t rctl; 2080 uint32_t rctl;
1634 uint32_t hash_value; 2081 uint32_t hash_value;
1635 int i; 2082 int i, rar_entries = E1000_RAR_ENTRIES;
1636 2083
1637 spin_lock_irqsave(&adapter->tx_lock, flags); 2084 /* reserve RAR[14] for LAA over-write work-around */
2085 if (adapter->hw.mac_type == e1000_82571)
2086 rar_entries--;
1638 2087
1639 /* Check for Promiscuous and All Multicast modes */ 2088 /* Check for Promiscuous and All Multicast modes */
1640 2089
@@ -1659,11 +2108,12 @@ e1000_set_multi(struct net_device *netdev)
1659 /* load the first 14 multicast address into the exact filters 1-14 2108 /* load the first 14 multicast address into the exact filters 1-14
1660 * RAR 0 is used for the station MAC adddress 2109 * RAR 0 is used for the station MAC adddress
1661 * if there are not 14 addresses, go ahead and clear the filters 2110 * if there are not 14 addresses, go ahead and clear the filters
2111 * -- with 82571 controllers only 0-13 entries are filled here
1662 */ 2112 */
1663 mc_ptr = netdev->mc_list; 2113 mc_ptr = netdev->mc_list;
1664 2114
1665 for(i = 1; i < E1000_RAR_ENTRIES; i++) { 2115 for(i = 1; i < rar_entries; i++) {
1666 if(mc_ptr) { 2116 if (mc_ptr) {
1667 e1000_rar_set(hw, mc_ptr->dmi_addr, i); 2117 e1000_rar_set(hw, mc_ptr->dmi_addr, i);
1668 mc_ptr = mc_ptr->next; 2118 mc_ptr = mc_ptr->next;
1669 } else { 2119 } else {
@@ -1686,8 +2136,6 @@ e1000_set_multi(struct net_device *netdev)
1686 2136
1687 if(hw->mac_type == e1000_82542_rev2_0) 2137 if(hw->mac_type == e1000_82542_rev2_0)
1688 e1000_leave_82542_rst(adapter); 2138 e1000_leave_82542_rst(adapter);
1689
1690 spin_unlock_irqrestore(&adapter->tx_lock, flags);
1691} 2139}
1692 2140
1693/* Need to wait a few seconds after link up to get diagnostic information from 2141/* Need to wait a few seconds after link up to get diagnostic information from
@@ -1759,7 +2207,7 @@ static void
1759e1000_watchdog_task(struct e1000_adapter *adapter) 2207e1000_watchdog_task(struct e1000_adapter *adapter)
1760{ 2208{
1761 struct net_device *netdev = adapter->netdev; 2209 struct net_device *netdev = adapter->netdev;
1762 struct e1000_desc_ring *txdr = &adapter->tx_ring; 2210 struct e1000_tx_ring *txdr = &adapter->tx_ring[0];
1763 uint32_t link; 2211 uint32_t link;
1764 2212
1765 e1000_check_for_link(&adapter->hw); 2213 e1000_check_for_link(&adapter->hw);
@@ -1818,8 +2266,8 @@ e1000_watchdog_task(struct e1000_adapter *adapter)
1818 2266
1819 e1000_update_adaptive(&adapter->hw); 2267 e1000_update_adaptive(&adapter->hw);
1820 2268
1821 if(!netif_carrier_ok(netdev)) { 2269 if (adapter->num_queues == 1 && !netif_carrier_ok(netdev)) {
1822 if(E1000_DESC_UNUSED(txdr) + 1 < txdr->count) { 2270 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
1823 /* We've lost link, so the controller stops DMA, 2271 /* We've lost link, so the controller stops DMA,
1824 * but we've got queued Tx work that's never going 2272 * but we've got queued Tx work that's never going
1825 * to get done, so reset controller to flush Tx. 2273 * to get done, so reset controller to flush Tx.
@@ -1847,6 +2295,11 @@ e1000_watchdog_task(struct e1000_adapter *adapter)
1847 /* Force detection of hung controller every watchdog period */ 2295 /* Force detection of hung controller every watchdog period */
1848 adapter->detect_tx_hung = TRUE; 2296 adapter->detect_tx_hung = TRUE;
1849 2297
2298 /* With 82571 controllers, LAA may be overwritten due to controller
2299 * reset from the other port. Set the appropriate LAA in RAR[0] */
2300 if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2301 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2302
1850 /* Reset the timer */ 2303 /* Reset the timer */
1851 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ); 2304 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
1852} 2305}
@@ -1859,7 +2312,8 @@ e1000_watchdog_task(struct e1000_adapter *adapter)
1859#define E1000_TX_FLAGS_VLAN_SHIFT 16 2312#define E1000_TX_FLAGS_VLAN_SHIFT 16
1860 2313
1861static inline int 2314static inline int
1862e1000_tso(struct e1000_adapter *adapter, struct sk_buff *skb) 2315e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2316 struct sk_buff *skb)
1863{ 2317{
1864#ifdef NETIF_F_TSO 2318#ifdef NETIF_F_TSO
1865 struct e1000_context_desc *context_desc; 2319 struct e1000_context_desc *context_desc;
@@ -1910,8 +2364,8 @@ e1000_tso(struct e1000_adapter *adapter, struct sk_buff *skb)
1910 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | 2364 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
1911 E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); 2365 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
1912 2366
1913 i = adapter->tx_ring.next_to_use; 2367 i = tx_ring->next_to_use;
1914 context_desc = E1000_CONTEXT_DESC(adapter->tx_ring, i); 2368 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
1915 2369
1916 context_desc->lower_setup.ip_fields.ipcss = ipcss; 2370 context_desc->lower_setup.ip_fields.ipcss = ipcss;
1917 context_desc->lower_setup.ip_fields.ipcso = ipcso; 2371 context_desc->lower_setup.ip_fields.ipcso = ipcso;
@@ -1923,8 +2377,8 @@ e1000_tso(struct e1000_adapter *adapter, struct sk_buff *skb)
1923 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; 2377 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
1924 context_desc->cmd_and_length = cpu_to_le32(cmd_length); 2378 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
1925 2379
1926 if(++i == adapter->tx_ring.count) i = 0; 2380 if (++i == tx_ring->count) i = 0;
1927 adapter->tx_ring.next_to_use = i; 2381 tx_ring->next_to_use = i;
1928 2382
1929 return 1; 2383 return 1;
1930 } 2384 }
@@ -1934,7 +2388,8 @@ e1000_tso(struct e1000_adapter *adapter, struct sk_buff *skb)
1934} 2388}
1935 2389
1936static inline boolean_t 2390static inline boolean_t
1937e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb) 2391e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2392 struct sk_buff *skb)
1938{ 2393{
1939 struct e1000_context_desc *context_desc; 2394 struct e1000_context_desc *context_desc;
1940 unsigned int i; 2395 unsigned int i;
@@ -1943,8 +2398,8 @@ e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
1943 if(likely(skb->ip_summed == CHECKSUM_HW)) { 2398 if(likely(skb->ip_summed == CHECKSUM_HW)) {
1944 css = skb->h.raw - skb->data; 2399 css = skb->h.raw - skb->data;
1945 2400
1946 i = adapter->tx_ring.next_to_use; 2401 i = tx_ring->next_to_use;
1947 context_desc = E1000_CONTEXT_DESC(adapter->tx_ring, i); 2402 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
1948 2403
1949 context_desc->upper_setup.tcp_fields.tucss = css; 2404 context_desc->upper_setup.tcp_fields.tucss = css;
1950 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum; 2405 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
@@ -1952,8 +2407,8 @@ e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
1952 context_desc->tcp_seg_setup.data = 0; 2407 context_desc->tcp_seg_setup.data = 0;
1953 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT); 2408 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
1954 2409
1955 if(unlikely(++i == adapter->tx_ring.count)) i = 0; 2410 if (unlikely(++i == tx_ring->count)) i = 0;
1956 adapter->tx_ring.next_to_use = i; 2411 tx_ring->next_to_use = i;
1957 2412
1958 return TRUE; 2413 return TRUE;
1959 } 2414 }
@@ -1965,11 +2420,10 @@ e1000_tx_csum(struct e1000_adapter *adapter, struct sk_buff *skb)
1965#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR) 2420#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
1966 2421
1967static inline int 2422static inline int
1968e1000_tx_map(struct e1000_adapter *adapter, struct sk_buff *skb, 2423e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
1969 unsigned int first, unsigned int max_per_txd, 2424 struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
1970 unsigned int nr_frags, unsigned int mss) 2425 unsigned int nr_frags, unsigned int mss)
1971{ 2426{
1972 struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
1973 struct e1000_buffer *buffer_info; 2427 struct e1000_buffer *buffer_info;
1974 unsigned int len = skb->len; 2428 unsigned int len = skb->len;
1975 unsigned int offset = 0, size, count = 0, i; 2429 unsigned int offset = 0, size, count = 0, i;
@@ -2065,9 +2519,9 @@ e1000_tx_map(struct e1000_adapter *adapter, struct sk_buff *skb,
2065} 2519}
2066 2520
2067static inline void 2521static inline void
2068e1000_tx_queue(struct e1000_adapter *adapter, int count, int tx_flags) 2522e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2523 int tx_flags, int count)
2069{ 2524{
2070 struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
2071 struct e1000_tx_desc *tx_desc = NULL; 2525 struct e1000_tx_desc *tx_desc = NULL;
2072 struct e1000_buffer *buffer_info; 2526 struct e1000_buffer *buffer_info;
2073 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; 2527 uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
@@ -2113,7 +2567,7 @@ e1000_tx_queue(struct e1000_adapter *adapter, int count, int tx_flags)
2113 wmb(); 2567 wmb();
2114 2568
2115 tx_ring->next_to_use = i; 2569 tx_ring->next_to_use = i;
2116 E1000_WRITE_REG(&adapter->hw, TDT, i); 2570 writel(i, adapter->hw.hw_addr + tx_ring->tdt);
2117} 2571}
2118 2572
2119/** 2573/**
@@ -2206,6 +2660,7 @@ static int
2206e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev) 2660e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2207{ 2661{
2208 struct e1000_adapter *adapter = netdev_priv(netdev); 2662 struct e1000_adapter *adapter = netdev_priv(netdev);
2663 struct e1000_tx_ring *tx_ring;
2209 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD; 2664 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2210 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; 2665 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2211 unsigned int tx_flags = 0; 2666 unsigned int tx_flags = 0;
@@ -2218,7 +2673,13 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2218 unsigned int f; 2673 unsigned int f;
2219 len -= skb->data_len; 2674 len -= skb->data_len;
2220 2675
2221 if(unlikely(skb->len <= 0)) { 2676#ifdef CONFIG_E1000_MQ
2677 tx_ring = *per_cpu_ptr(adapter->cpu_tx_ring, smp_processor_id());
2678#else
2679 tx_ring = adapter->tx_ring;
2680#endif
2681
2682 if (unlikely(skb->len <= 0)) {
2222 dev_kfree_skb_any(skb); 2683 dev_kfree_skb_any(skb);
2223 return NETDEV_TX_OK; 2684 return NETDEV_TX_OK;
2224 } 2685 }
@@ -2262,21 +2723,42 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2262 if(adapter->pcix_82544) 2723 if(adapter->pcix_82544)
2263 count += nr_frags; 2724 count += nr_frags;
2264 2725
2265 local_irq_save(flags); 2726#ifdef NETIF_F_TSO
2266 if (!spin_trylock(&adapter->tx_lock)) { 2727 /* TSO Workaround for 82571/2 Controllers -- if skb->data
2267 /* Collision - tell upper layer to requeue */ 2728 * points to just header, pull a few bytes of payload from
2268 local_irq_restore(flags); 2729 * frags into skb->data */
2269 return NETDEV_TX_LOCKED; 2730 if (skb_shinfo(skb)->tso_size) {
2270 } 2731 uint8_t hdr_len;
2732 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2733 if (skb->data_len && (hdr_len < (skb->len - skb->data_len)) &&
2734 (adapter->hw.mac_type == e1000_82571 ||
2735 adapter->hw.mac_type == e1000_82572)) {
2736 unsigned int pull_size;
2737 pull_size = min((unsigned int)4, skb->data_len);
2738 if (!__pskb_pull_tail(skb, pull_size)) {
2739 printk(KERN_ERR "__pskb_pull_tail failed.\n");
2740 dev_kfree_skb_any(skb);
2741 return -EFAULT;
2742 }
2743 }
2744 }
2745#endif
2746
2271 if(adapter->hw.tx_pkt_filtering && (adapter->hw.mac_type == e1000_82573) ) 2747 if(adapter->hw.tx_pkt_filtering && (adapter->hw.mac_type == e1000_82573) )
2272 e1000_transfer_dhcp_info(adapter, skb); 2748 e1000_transfer_dhcp_info(adapter, skb);
2273 2749
2750 local_irq_save(flags);
2751 if (!spin_trylock(&tx_ring->tx_lock)) {
2752 /* Collision - tell upper layer to requeue */
2753 local_irq_restore(flags);
2754 return NETDEV_TX_LOCKED;
2755 }
2274 2756
2275 /* need: count + 2 desc gap to keep tail from touching 2757 /* need: count + 2 desc gap to keep tail from touching
2276 * head, otherwise try next time */ 2758 * head, otherwise try next time */
2277 if(unlikely(E1000_DESC_UNUSED(&adapter->tx_ring) < count + 2)) { 2759 if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) {
2278 netif_stop_queue(netdev); 2760 netif_stop_queue(netdev);
2279 spin_unlock_irqrestore(&adapter->tx_lock, flags); 2761 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2280 return NETDEV_TX_BUSY; 2762 return NETDEV_TX_BUSY;
2281 } 2763 }
2282 2764
@@ -2284,7 +2766,7 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2284 if(unlikely(e1000_82547_fifo_workaround(adapter, skb))) { 2766 if(unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
2285 netif_stop_queue(netdev); 2767 netif_stop_queue(netdev);
2286 mod_timer(&adapter->tx_fifo_stall_timer, jiffies); 2768 mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
2287 spin_unlock_irqrestore(&adapter->tx_lock, flags); 2769 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2288 return NETDEV_TX_BUSY; 2770 return NETDEV_TX_BUSY;
2289 } 2771 }
2290 } 2772 }
@@ -2294,37 +2776,37 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2294 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); 2776 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
2295 } 2777 }
2296 2778
2297 first = adapter->tx_ring.next_to_use; 2779 first = tx_ring->next_to_use;
2298 2780
2299 tso = e1000_tso(adapter, skb); 2781 tso = e1000_tso(adapter, tx_ring, skb);
2300 if (tso < 0) { 2782 if (tso < 0) {
2301 dev_kfree_skb_any(skb); 2783 dev_kfree_skb_any(skb);
2302 spin_unlock_irqrestore(&adapter->tx_lock, flags); 2784 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2303 return NETDEV_TX_OK; 2785 return NETDEV_TX_OK;
2304 } 2786 }
2305 2787
2306 if (likely(tso)) 2788 if (likely(tso))
2307 tx_flags |= E1000_TX_FLAGS_TSO; 2789 tx_flags |= E1000_TX_FLAGS_TSO;
2308 else if(likely(e1000_tx_csum(adapter, skb))) 2790 else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
2309 tx_flags |= E1000_TX_FLAGS_CSUM; 2791 tx_flags |= E1000_TX_FLAGS_CSUM;
2310 2792
2311 /* Old method was to assume IPv4 packet by default if TSO was enabled. 2793 /* Old method was to assume IPv4 packet by default if TSO was enabled.
2312 * 82573 hardware supports TSO capabilities for IPv6 as well... 2794 * 82571 hardware supports TSO capabilities for IPv6 as well...
2313 * no longer assume, we must. */ 2795 * no longer assume, we must. */
2314 if(likely(skb->protocol == ntohs(ETH_P_IP))) 2796 if (likely(skb->protocol == ntohs(ETH_P_IP)))
2315 tx_flags |= E1000_TX_FLAGS_IPV4; 2797 tx_flags |= E1000_TX_FLAGS_IPV4;
2316 2798
2317 e1000_tx_queue(adapter, 2799 e1000_tx_queue(adapter, tx_ring, tx_flags,
2318 e1000_tx_map(adapter, skb, first, max_per_txd, nr_frags, mss), 2800 e1000_tx_map(adapter, tx_ring, skb, first,
2319 tx_flags); 2801 max_per_txd, nr_frags, mss));
2320 2802
2321 netdev->trans_start = jiffies; 2803 netdev->trans_start = jiffies;
2322 2804
2323 /* Make sure there is space in the ring for the next send. */ 2805 /* Make sure there is space in the ring for the next send. */
2324 if(unlikely(E1000_DESC_UNUSED(&adapter->tx_ring) < MAX_SKB_FRAGS + 2)) 2806 if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2))
2325 netif_stop_queue(netdev); 2807 netif_stop_queue(netdev);
2326 2808
2327 spin_unlock_irqrestore(&adapter->tx_lock, flags); 2809 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2328 return NETDEV_TX_OK; 2810 return NETDEV_TX_OK;
2329} 2811}
2330 2812
@@ -2388,9 +2870,18 @@ e1000_change_mtu(struct net_device *netdev, int new_mtu)
2388 return -EINVAL; 2870 return -EINVAL;
2389 } 2871 }
2390 2872
2391#define MAX_STD_JUMBO_FRAME_SIZE 9216 2873#define MAX_STD_JUMBO_FRAME_SIZE 9234
2392 /* might want this to be bigger enum check... */ 2874 /* might want this to be bigger enum check... */
2393 if (adapter->hw.mac_type == e1000_82573 && 2875 /* 82571 controllers limit jumbo frame size to 10500 bytes */
2876 if ((adapter->hw.mac_type == e1000_82571 ||
2877 adapter->hw.mac_type == e1000_82572) &&
2878 max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
2879 DPRINTK(PROBE, ERR, "MTU > 9216 bytes not supported "
2880 "on 82571 and 82572 controllers.\n");
2881 return -EINVAL;
2882 }
2883
2884 if(adapter->hw.mac_type == e1000_82573 &&
2394 max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { 2885 max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
2395 DPRINTK(PROBE, ERR, "Jumbo Frames not supported " 2886 DPRINTK(PROBE, ERR, "Jumbo Frames not supported "
2396 "on 82573\n"); 2887 "on 82573\n");
@@ -2578,6 +3069,29 @@ e1000_update_stats(struct e1000_adapter *adapter)
2578 spin_unlock_irqrestore(&adapter->stats_lock, flags); 3069 spin_unlock_irqrestore(&adapter->stats_lock, flags);
2579} 3070}
2580 3071
3072#ifdef CONFIG_E1000_MQ
3073void
3074e1000_rx_schedule(void *data)
3075{
3076 struct net_device *poll_dev, *netdev = data;
3077 struct e1000_adapter *adapter = netdev->priv;
3078 int this_cpu = get_cpu();
3079
3080 poll_dev = *per_cpu_ptr(adapter->cpu_netdev, this_cpu);
3081 if (poll_dev == NULL) {
3082 put_cpu();
3083 return;
3084 }
3085
3086 if (likely(netif_rx_schedule_prep(poll_dev)))
3087 __netif_rx_schedule(poll_dev);
3088 else
3089 e1000_irq_enable(adapter);
3090
3091 put_cpu();
3092}
3093#endif
3094
2581/** 3095/**
2582 * e1000_intr - Interrupt Handler 3096 * e1000_intr - Interrupt Handler
2583 * @irq: interrupt number 3097 * @irq: interrupt number
@@ -2592,8 +3106,8 @@ e1000_intr(int irq, void *data, struct pt_regs *regs)
2592 struct e1000_adapter *adapter = netdev_priv(netdev); 3106 struct e1000_adapter *adapter = netdev_priv(netdev);
2593 struct e1000_hw *hw = &adapter->hw; 3107 struct e1000_hw *hw = &adapter->hw;
2594 uint32_t icr = E1000_READ_REG(hw, ICR); 3108 uint32_t icr = E1000_READ_REG(hw, ICR);
2595#ifndef CONFIG_E1000_NAPI 3109#if defined(CONFIG_E1000_NAPI) && defined(CONFIG_E1000_MQ) || !defined(CONFIG_E1000_NAPI)
2596 unsigned int i; 3110 int i;
2597#endif 3111#endif
2598 3112
2599 if(unlikely(!icr)) 3113 if(unlikely(!icr))
@@ -2605,17 +3119,31 @@ e1000_intr(int irq, void *data, struct pt_regs *regs)
2605 } 3119 }
2606 3120
2607#ifdef CONFIG_E1000_NAPI 3121#ifdef CONFIG_E1000_NAPI
2608 if(likely(netif_rx_schedule_prep(netdev))) { 3122 atomic_inc(&adapter->irq_sem);
2609 3123 E1000_WRITE_REG(hw, IMC, ~0);
2610 /* Disable interrupts and register for poll. The flush 3124 E1000_WRITE_FLUSH(hw);
2611 of the posted write is intentionally left out. 3125#ifdef CONFIG_E1000_MQ
2612 */ 3126 if (atomic_read(&adapter->rx_sched_call_data.count) == 0) {
2613 3127 cpu_set(adapter->cpu_for_queue[0],
2614 atomic_inc(&adapter->irq_sem); 3128 adapter->rx_sched_call_data.cpumask);
2615 E1000_WRITE_REG(hw, IMC, ~0); 3129 for (i = 1; i < adapter->num_queues; i++) {
2616 __netif_rx_schedule(netdev); 3130 cpu_set(adapter->cpu_for_queue[i],
3131 adapter->rx_sched_call_data.cpumask);
3132 atomic_inc(&adapter->irq_sem);
3133 }
3134 atomic_set(&adapter->rx_sched_call_data.count, i);
3135 smp_call_async_mask(&adapter->rx_sched_call_data);
3136 } else {
3137 printk("call_data.count == %u\n", atomic_read(&adapter->rx_sched_call_data.count));
2617 } 3138 }
2618#else 3139#else /* if !CONFIG_E1000_MQ */
3140 if (likely(netif_rx_schedule_prep(&adapter->polling_netdev[0])))
3141 __netif_rx_schedule(&adapter->polling_netdev[0]);
3142 else
3143 e1000_irq_enable(adapter);
3144#endif /* CONFIG_E1000_MQ */
3145
3146#else /* if !CONFIG_E1000_NAPI */
2619 /* Writing IMC and IMS is needed for 82547. 3147 /* Writing IMC and IMS is needed for 82547.
2620 Due to Hub Link bus being occupied, an interrupt 3148 Due to Hub Link bus being occupied, an interrupt
2621 de-assertion message is not able to be sent. 3149 de-assertion message is not able to be sent.
@@ -2632,13 +3160,14 @@ e1000_intr(int irq, void *data, struct pt_regs *regs)
2632 } 3160 }
2633 3161
2634 for(i = 0; i < E1000_MAX_INTR; i++) 3162 for(i = 0; i < E1000_MAX_INTR; i++)
2635 if(unlikely(!adapter->clean_rx(adapter) & 3163 if(unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
2636 !e1000_clean_tx_irq(adapter))) 3164 !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
2637 break; 3165 break;
2638 3166
2639 if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) 3167 if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
2640 e1000_irq_enable(adapter); 3168 e1000_irq_enable(adapter);
2641#endif 3169
3170#endif /* CONFIG_E1000_NAPI */
2642 3171
2643 return IRQ_HANDLED; 3172 return IRQ_HANDLED;
2644} 3173}
@@ -2650,22 +3179,37 @@ e1000_intr(int irq, void *data, struct pt_regs *regs)
2650 **/ 3179 **/
2651 3180
2652static int 3181static int
2653e1000_clean(struct net_device *netdev, int *budget) 3182e1000_clean(struct net_device *poll_dev, int *budget)
2654{ 3183{
2655 struct e1000_adapter *adapter = netdev_priv(netdev); 3184 struct e1000_adapter *adapter;
2656 int work_to_do = min(*budget, netdev->quota); 3185 int work_to_do = min(*budget, poll_dev->quota);
2657 int tx_cleaned; 3186 int tx_cleaned, i = 0, work_done = 0;
2658 int work_done = 0; 3187
3188 /* Must NOT use netdev_priv macro here. */
3189 adapter = poll_dev->priv;
2659 3190
2660 tx_cleaned = e1000_clean_tx_irq(adapter); 3191 /* Keep link state information with original netdev */
2661 adapter->clean_rx(adapter, &work_done, work_to_do); 3192 if (!netif_carrier_ok(adapter->netdev))
3193 goto quit_polling;
3194
3195 while (poll_dev != &adapter->polling_netdev[i]) {
3196 i++;
3197 if (unlikely(i == adapter->num_queues))
3198 BUG();
3199 }
3200
3201 tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[i]);
3202 adapter->clean_rx(adapter, &adapter->rx_ring[i],
3203 &work_done, work_to_do);
2662 3204
2663 *budget -= work_done; 3205 *budget -= work_done;
2664 netdev->quota -= work_done; 3206 poll_dev->quota -= work_done;
2665 3207
2666 if ((!tx_cleaned && (work_done == 0)) || !netif_running(netdev)) {
2667 /* If no Tx and not enough Rx work done, exit the polling mode */ 3208 /* If no Tx and not enough Rx work done, exit the polling mode */
2668 netif_rx_complete(netdev); 3209 if((!tx_cleaned && (work_done == 0)) ||
3210 !netif_running(adapter->netdev)) {
3211quit_polling:
3212 netif_rx_complete(poll_dev);
2669 e1000_irq_enable(adapter); 3213 e1000_irq_enable(adapter);
2670 return 0; 3214 return 0;
2671 } 3215 }
@@ -2680,9 +3224,9 @@ e1000_clean(struct net_device *netdev, int *budget)
2680 **/ 3224 **/
2681 3225
2682static boolean_t 3226static boolean_t
2683e1000_clean_tx_irq(struct e1000_adapter *adapter) 3227e1000_clean_tx_irq(struct e1000_adapter *adapter,
3228 struct e1000_tx_ring *tx_ring)
2684{ 3229{
2685 struct e1000_desc_ring *tx_ring = &adapter->tx_ring;
2686 struct net_device *netdev = adapter->netdev; 3230 struct net_device *netdev = adapter->netdev;
2687 struct e1000_tx_desc *tx_desc, *eop_desc; 3231 struct e1000_tx_desc *tx_desc, *eop_desc;
2688 struct e1000_buffer *buffer_info; 3232 struct e1000_buffer *buffer_info;
@@ -2693,12 +3237,12 @@ e1000_clean_tx_irq(struct e1000_adapter *adapter)
2693 eop = tx_ring->buffer_info[i].next_to_watch; 3237 eop = tx_ring->buffer_info[i].next_to_watch;
2694 eop_desc = E1000_TX_DESC(*tx_ring, eop); 3238 eop_desc = E1000_TX_DESC(*tx_ring, eop);
2695 3239
2696 while(eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) { 3240 while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
2697 /* Premature writeback of Tx descriptors clear (free buffers 3241 /* Premature writeback of Tx descriptors clear (free buffers
2698 * and unmap pci_mapping) previous_buffer_info */ 3242 * and unmap pci_mapping) previous_buffer_info */
2699 if (likely(adapter->previous_buffer_info.skb != NULL)) { 3243 if (likely(tx_ring->previous_buffer_info.skb != NULL)) {
2700 e1000_unmap_and_free_tx_resource(adapter, 3244 e1000_unmap_and_free_tx_resource(adapter,
2701 &adapter->previous_buffer_info); 3245 &tx_ring->previous_buffer_info);
2702 } 3246 }
2703 3247
2704 for(cleaned = FALSE; !cleaned; ) { 3248 for(cleaned = FALSE; !cleaned; ) {
@@ -2714,7 +3258,7 @@ e1000_clean_tx_irq(struct e1000_adapter *adapter)
2714#ifdef NETIF_F_TSO 3258#ifdef NETIF_F_TSO
2715 } else { 3259 } else {
2716 if (cleaned) { 3260 if (cleaned) {
2717 memcpy(&adapter->previous_buffer_info, 3261 memcpy(&tx_ring->previous_buffer_info,
2718 buffer_info, 3262 buffer_info,
2719 sizeof(struct e1000_buffer)); 3263 sizeof(struct e1000_buffer));
2720 memset(buffer_info, 0, 3264 memset(buffer_info, 0,
@@ -2732,6 +3276,8 @@ e1000_clean_tx_irq(struct e1000_adapter *adapter)
2732 3276
2733 if(unlikely(++i == tx_ring->count)) i = 0; 3277 if(unlikely(++i == tx_ring->count)) i = 0;
2734 } 3278 }
3279
3280 tx_ring->pkt++;
2735 3281
2736 eop = tx_ring->buffer_info[i].next_to_watch; 3282 eop = tx_ring->buffer_info[i].next_to_watch;
2737 eop_desc = E1000_TX_DESC(*tx_ring, eop); 3283 eop_desc = E1000_TX_DESC(*tx_ring, eop);
@@ -2739,15 +3285,15 @@ e1000_clean_tx_irq(struct e1000_adapter *adapter)
2739 3285
2740 tx_ring->next_to_clean = i; 3286 tx_ring->next_to_clean = i;
2741 3287
2742 spin_lock(&adapter->tx_lock); 3288 spin_lock(&tx_ring->tx_lock);
2743 3289
2744 if(unlikely(cleaned && netif_queue_stopped(netdev) && 3290 if(unlikely(cleaned && netif_queue_stopped(netdev) &&
2745 netif_carrier_ok(netdev))) 3291 netif_carrier_ok(netdev)))
2746 netif_wake_queue(netdev); 3292 netif_wake_queue(netdev);
2747 3293
2748 spin_unlock(&adapter->tx_lock); 3294 spin_unlock(&tx_ring->tx_lock);
2749 if(adapter->detect_tx_hung) {
2750 3295
3296 if (adapter->detect_tx_hung) {
2751 /* Detect a transmit hang in hardware, this serializes the 3297 /* Detect a transmit hang in hardware, this serializes the
2752 * check with the clearing of time_stamp and movement of i */ 3298 * check with the clearing of time_stamp and movement of i */
2753 adapter->detect_tx_hung = FALSE; 3299 adapter->detect_tx_hung = FALSE;
@@ -2771,8 +3317,8 @@ e1000_clean_tx_irq(struct e1000_adapter *adapter)
2771 " next_to_watch <%x>\n" 3317 " next_to_watch <%x>\n"
2772 " jiffies <%lx>\n" 3318 " jiffies <%lx>\n"
2773 " next_to_watch.status <%x>\n", 3319 " next_to_watch.status <%x>\n",
2774 E1000_READ_REG(&adapter->hw, TDH), 3320 readl(adapter->hw.hw_addr + tx_ring->tdh),
2775 E1000_READ_REG(&adapter->hw, TDT), 3321 readl(adapter->hw.hw_addr + tx_ring->tdt),
2776 tx_ring->next_to_use, 3322 tx_ring->next_to_use,
2777 i, 3323 i,
2778 (unsigned long long)tx_ring->buffer_info[i].dma, 3324 (unsigned long long)tx_ring->buffer_info[i].dma,
@@ -2784,12 +3330,10 @@ e1000_clean_tx_irq(struct e1000_adapter *adapter)
2784 } 3330 }
2785 } 3331 }
2786#ifdef NETIF_F_TSO 3332#ifdef NETIF_F_TSO
2787 3333 if (unlikely(!(eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
2788 if( unlikely(!(eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) && 3334 time_after(jiffies, tx_ring->previous_buffer_info.time_stamp + HZ)))
2789 time_after(jiffies, adapter->previous_buffer_info.time_stamp + HZ)))
2790 e1000_unmap_and_free_tx_resource( 3335 e1000_unmap_and_free_tx_resource(
2791 adapter, &adapter->previous_buffer_info); 3336 adapter, &tx_ring->previous_buffer_info);
2792
2793#endif 3337#endif
2794 return cleaned; 3338 return cleaned;
2795} 3339}
@@ -2852,13 +3396,14 @@ e1000_rx_checksum(struct e1000_adapter *adapter,
2852 3396
2853static boolean_t 3397static boolean_t
2854#ifdef CONFIG_E1000_NAPI 3398#ifdef CONFIG_E1000_NAPI
2855e1000_clean_rx_irq(struct e1000_adapter *adapter, int *work_done, 3399e1000_clean_rx_irq(struct e1000_adapter *adapter,
2856 int work_to_do) 3400 struct e1000_rx_ring *rx_ring,
3401 int *work_done, int work_to_do)
2857#else 3402#else
2858e1000_clean_rx_irq(struct e1000_adapter *adapter) 3403e1000_clean_rx_irq(struct e1000_adapter *adapter,
3404 struct e1000_rx_ring *rx_ring)
2859#endif 3405#endif
2860{ 3406{
2861 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
2862 struct net_device *netdev = adapter->netdev; 3407 struct net_device *netdev = adapter->netdev;
2863 struct pci_dev *pdev = adapter->pdev; 3408 struct pci_dev *pdev = adapter->pdev;
2864 struct e1000_rx_desc *rx_desc; 3409 struct e1000_rx_desc *rx_desc;
@@ -2944,6 +3489,7 @@ e1000_clean_rx_irq(struct e1000_adapter *adapter)
2944 } 3489 }
2945#endif /* CONFIG_E1000_NAPI */ 3490#endif /* CONFIG_E1000_NAPI */
2946 netdev->last_rx = jiffies; 3491 netdev->last_rx = jiffies;
3492 rx_ring->pkt++;
2947 3493
2948next_desc: 3494next_desc:
2949 rx_desc->status = 0; 3495 rx_desc->status = 0;
@@ -2953,7 +3499,7 @@ next_desc:
2953 rx_desc = E1000_RX_DESC(*rx_ring, i); 3499 rx_desc = E1000_RX_DESC(*rx_ring, i);
2954 } 3500 }
2955 rx_ring->next_to_clean = i; 3501 rx_ring->next_to_clean = i;
2956 adapter->alloc_rx_buf(adapter); 3502 adapter->alloc_rx_buf(adapter, rx_ring);
2957 3503
2958 return cleaned; 3504 return cleaned;
2959} 3505}
@@ -2965,13 +3511,14 @@ next_desc:
2965 3511
2966static boolean_t 3512static boolean_t
2967#ifdef CONFIG_E1000_NAPI 3513#ifdef CONFIG_E1000_NAPI
2968e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, int *work_done, 3514e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
2969 int work_to_do) 3515 struct e1000_rx_ring *rx_ring,
3516 int *work_done, int work_to_do)
2970#else 3517#else
2971e1000_clean_rx_irq_ps(struct e1000_adapter *adapter) 3518e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3519 struct e1000_rx_ring *rx_ring)
2972#endif 3520#endif
2973{ 3521{
2974 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
2975 union e1000_rx_desc_packet_split *rx_desc; 3522 union e1000_rx_desc_packet_split *rx_desc;
2976 struct net_device *netdev = adapter->netdev; 3523 struct net_device *netdev = adapter->netdev;
2977 struct pci_dev *pdev = adapter->pdev; 3524 struct pci_dev *pdev = adapter->pdev;
@@ -3027,7 +3574,7 @@ e1000_clean_rx_irq_ps(struct e1000_adapter *adapter)
3027 /* Good Receive */ 3574 /* Good Receive */
3028 skb_put(skb, length); 3575 skb_put(skb, length);
3029 3576
3030 for(j = 0; j < PS_PAGE_BUFFERS; j++) { 3577 for(j = 0; j < adapter->rx_ps_pages; j++) {
3031 if(!(length = le16_to_cpu(rx_desc->wb.upper.length[j]))) 3578 if(!(length = le16_to_cpu(rx_desc->wb.upper.length[j])))
3032 break; 3579 break;
3033 3580
@@ -3048,11 +3595,13 @@ e1000_clean_rx_irq_ps(struct e1000_adapter *adapter)
3048 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb); 3595 rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
3049 skb->protocol = eth_type_trans(skb, netdev); 3596 skb->protocol = eth_type_trans(skb, netdev);
3050 3597
3051#ifdef HAVE_RX_ZERO_COPY
3052 if(likely(rx_desc->wb.upper.header_status & 3598 if(likely(rx_desc->wb.upper.header_status &
3053 E1000_RXDPS_HDRSTAT_HDRSP)) 3599 E1000_RXDPS_HDRSTAT_HDRSP)) {
3600 adapter->rx_hdr_split++;
3601#ifdef HAVE_RX_ZERO_COPY
3054 skb_shinfo(skb)->zero_copy = TRUE; 3602 skb_shinfo(skb)->zero_copy = TRUE;
3055#endif 3603#endif
3604 }
3056#ifdef CONFIG_E1000_NAPI 3605#ifdef CONFIG_E1000_NAPI
3057 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) { 3606 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3058 vlan_hwaccel_receive_skb(skb, adapter->vlgrp, 3607 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
@@ -3071,6 +3620,7 @@ e1000_clean_rx_irq_ps(struct e1000_adapter *adapter)
3071 } 3620 }
3072#endif /* CONFIG_E1000_NAPI */ 3621#endif /* CONFIG_E1000_NAPI */
3073 netdev->last_rx = jiffies; 3622 netdev->last_rx = jiffies;
3623 rx_ring->pkt++;
3074 3624
3075next_desc: 3625next_desc:
3076 rx_desc->wb.middle.status_error &= ~0xFF; 3626 rx_desc->wb.middle.status_error &= ~0xFF;
@@ -3081,7 +3631,7 @@ next_desc:
3081 staterr = le32_to_cpu(rx_desc->wb.middle.status_error); 3631 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3082 } 3632 }
3083 rx_ring->next_to_clean = i; 3633 rx_ring->next_to_clean = i;
3084 adapter->alloc_rx_buf(adapter); 3634 adapter->alloc_rx_buf(adapter, rx_ring);
3085 3635
3086 return cleaned; 3636 return cleaned;
3087} 3637}
@@ -3092,9 +3642,9 @@ next_desc:
3092 **/ 3642 **/
3093 3643
3094static void 3644static void
3095e1000_alloc_rx_buffers(struct e1000_adapter *adapter) 3645e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
3646 struct e1000_rx_ring *rx_ring)
3096{ 3647{
3097 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
3098 struct net_device *netdev = adapter->netdev; 3648 struct net_device *netdev = adapter->netdev;
3099 struct pci_dev *pdev = adapter->pdev; 3649 struct pci_dev *pdev = adapter->pdev;
3100 struct e1000_rx_desc *rx_desc; 3650 struct e1000_rx_desc *rx_desc;
@@ -3178,7 +3728,7 @@ e1000_alloc_rx_buffers(struct e1000_adapter *adapter)
3178 * applicable for weak-ordered memory model archs, 3728 * applicable for weak-ordered memory model archs,
3179 * such as IA-64). */ 3729 * such as IA-64). */
3180 wmb(); 3730 wmb();
3181 E1000_WRITE_REG(&adapter->hw, RDT, i); 3731 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
3182 } 3732 }
3183 3733
3184 if(unlikely(++i == rx_ring->count)) i = 0; 3734 if(unlikely(++i == rx_ring->count)) i = 0;
@@ -3194,9 +3744,9 @@ e1000_alloc_rx_buffers(struct e1000_adapter *adapter)
3194 **/ 3744 **/
3195 3745
3196static void 3746static void
3197e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter) 3747e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
3748 struct e1000_rx_ring *rx_ring)
3198{ 3749{
3199 struct e1000_desc_ring *rx_ring = &adapter->rx_ring;
3200 struct net_device *netdev = adapter->netdev; 3750 struct net_device *netdev = adapter->netdev;
3201 struct pci_dev *pdev = adapter->pdev; 3751 struct pci_dev *pdev = adapter->pdev;
3202 union e1000_rx_desc_packet_split *rx_desc; 3752 union e1000_rx_desc_packet_split *rx_desc;
@@ -3215,22 +3765,26 @@ e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter)
3215 rx_desc = E1000_RX_DESC_PS(*rx_ring, i); 3765 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3216 3766
3217 for(j = 0; j < PS_PAGE_BUFFERS; j++) { 3767 for(j = 0; j < PS_PAGE_BUFFERS; j++) {
3218 if(unlikely(!ps_page->ps_page[j])) { 3768 if (j < adapter->rx_ps_pages) {
3219 ps_page->ps_page[j] = 3769 if (likely(!ps_page->ps_page[j])) {
3220 alloc_page(GFP_ATOMIC); 3770 ps_page->ps_page[j] =
3221 if(unlikely(!ps_page->ps_page[j])) 3771 alloc_page(GFP_ATOMIC);
3222 goto no_buffers; 3772 if (unlikely(!ps_page->ps_page[j]))
3223 ps_page_dma->ps_page_dma[j] = 3773 goto no_buffers;
3224 pci_map_page(pdev, 3774 ps_page_dma->ps_page_dma[j] =
3225 ps_page->ps_page[j], 3775 pci_map_page(pdev,
3226 0, PAGE_SIZE, 3776 ps_page->ps_page[j],
3227 PCI_DMA_FROMDEVICE); 3777 0, PAGE_SIZE,
3228 } 3778 PCI_DMA_FROMDEVICE);
3229 /* Refresh the desc even if buffer_addrs didn't 3779 }
3230 * change because each write-back erases this info. 3780 /* Refresh the desc even if buffer_addrs didn't
3231 */ 3781 * change because each write-back erases
3232 rx_desc->read.buffer_addr[j+1] = 3782 * this info.
3233 cpu_to_le64(ps_page_dma->ps_page_dma[j]); 3783 */
3784 rx_desc->read.buffer_addr[j+1] =
3785 cpu_to_le64(ps_page_dma->ps_page_dma[j]);
3786 } else
3787 rx_desc->read.buffer_addr[j+1] = ~0;
3234 } 3788 }
3235 3789
3236 skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN); 3790 skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
@@ -3264,7 +3818,7 @@ e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter)
3264 * descriptors are 32 bytes...so we increment tail 3818 * descriptors are 32 bytes...so we increment tail
3265 * twice as much. 3819 * twice as much.
3266 */ 3820 */
3267 E1000_WRITE_REG(&adapter->hw, RDT, i<<1); 3821 writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
3268 } 3822 }
3269 3823
3270 if(unlikely(++i == rx_ring->count)) i = 0; 3824 if(unlikely(++i == rx_ring->count)) i = 0;
@@ -3640,6 +4194,7 @@ e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
3640 return 0; 4194 return 0;
3641} 4195}
3642 4196
4197#ifdef CONFIG_PM
3643static int 4198static int
3644e1000_suspend(struct pci_dev *pdev, pm_message_t state) 4199e1000_suspend(struct pci_dev *pdev, pm_message_t state)
3645{ 4200{
@@ -3715,6 +4270,12 @@ e1000_suspend(struct pci_dev *pdev, pm_message_t state)
3715 } 4270 }
3716 4271
3717 switch(adapter->hw.mac_type) { 4272 switch(adapter->hw.mac_type) {
4273 case e1000_82571:
4274 case e1000_82572:
4275 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4276 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
4277 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
4278 break;
3718 case e1000_82573: 4279 case e1000_82573:
3719 swsm = E1000_READ_REG(&adapter->hw, SWSM); 4280 swsm = E1000_READ_REG(&adapter->hw, SWSM);
3720 E1000_WRITE_REG(&adapter->hw, SWSM, 4281 E1000_WRITE_REG(&adapter->hw, SWSM,
@@ -3730,13 +4291,13 @@ e1000_suspend(struct pci_dev *pdev, pm_message_t state)
3730 return 0; 4291 return 0;
3731} 4292}
3732 4293
3733#ifdef CONFIG_PM
3734static int 4294static int
3735e1000_resume(struct pci_dev *pdev) 4295e1000_resume(struct pci_dev *pdev)
3736{ 4296{
3737 struct net_device *netdev = pci_get_drvdata(pdev); 4297 struct net_device *netdev = pci_get_drvdata(pdev);
3738 struct e1000_adapter *adapter = netdev_priv(netdev); 4298 struct e1000_adapter *adapter = netdev_priv(netdev);
3739 uint32_t manc, ret_val, swsm; 4299 uint32_t manc, ret_val, swsm;
4300 uint32_t ctrl_ext;
3740 4301
3741 pci_set_power_state(pdev, PCI_D0); 4302 pci_set_power_state(pdev, PCI_D0);
3742 pci_restore_state(pdev); 4303 pci_restore_state(pdev);
@@ -3762,6 +4323,12 @@ e1000_resume(struct pci_dev *pdev)
3762 } 4323 }
3763 4324
3764 switch(adapter->hw.mac_type) { 4325 switch(adapter->hw.mac_type) {
4326 case e1000_82571:
4327 case e1000_82572:
4328 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4329 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
4330 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
4331 break;
3765 case e1000_82573: 4332 case e1000_82573:
3766 swsm = E1000_READ_REG(&adapter->hw, SWSM); 4333 swsm = E1000_READ_REG(&adapter->hw, SWSM);
3767 E1000_WRITE_REG(&adapter->hw, SWSM, 4334 E1000_WRITE_REG(&adapter->hw, SWSM,
@@ -3786,7 +4353,7 @@ e1000_netpoll(struct net_device *netdev)
3786 struct e1000_adapter *adapter = netdev_priv(netdev); 4353 struct e1000_adapter *adapter = netdev_priv(netdev);
3787 disable_irq(adapter->pdev->irq); 4354 disable_irq(adapter->pdev->irq);
3788 e1000_intr(adapter->pdev->irq, netdev, NULL); 4355 e1000_intr(adapter->pdev->irq, netdev, NULL);
3789 e1000_clean_tx_irq(adapter); 4356 e1000_clean_tx_irq(adapter, adapter->tx_ring);
3790 enable_irq(adapter->pdev->irq); 4357 enable_irq(adapter->pdev->irq);
3791} 4358}
3792#endif 4359#endif
diff --git a/drivers/net/e1000/e1000_param.c b/drivers/net/e1000/e1000_param.c
index 676247f9f1cc..38695d5b4637 100644
--- a/drivers/net/e1000/e1000_param.c
+++ b/drivers/net/e1000/e1000_param.c
@@ -306,7 +306,8 @@ e1000_check_options(struct e1000_adapter *adapter)
306 .def = E1000_DEFAULT_TXD, 306 .def = E1000_DEFAULT_TXD,
307 .arg = { .r = { .min = E1000_MIN_TXD }} 307 .arg = { .r = { .min = E1000_MIN_TXD }}
308 }; 308 };
309 struct e1000_desc_ring *tx_ring = &adapter->tx_ring; 309 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
310 int i;
310 e1000_mac_type mac_type = adapter->hw.mac_type; 311 e1000_mac_type mac_type = adapter->hw.mac_type;
311 opt.arg.r.max = mac_type < e1000_82544 ? 312 opt.arg.r.max = mac_type < e1000_82544 ?
312 E1000_MAX_TXD : E1000_MAX_82544_TXD; 313 E1000_MAX_TXD : E1000_MAX_82544_TXD;
@@ -319,6 +320,8 @@ e1000_check_options(struct e1000_adapter *adapter)
319 } else { 320 } else {
320 tx_ring->count = opt.def; 321 tx_ring->count = opt.def;
321 } 322 }
323 for (i = 0; i < adapter->num_queues; i++)
324 tx_ring[i].count = tx_ring->count;
322 } 325 }
323 { /* Receive Descriptor Count */ 326 { /* Receive Descriptor Count */
324 struct e1000_option opt = { 327 struct e1000_option opt = {
@@ -329,7 +332,8 @@ e1000_check_options(struct e1000_adapter *adapter)
329 .def = E1000_DEFAULT_RXD, 332 .def = E1000_DEFAULT_RXD,
330 .arg = { .r = { .min = E1000_MIN_RXD }} 333 .arg = { .r = { .min = E1000_MIN_RXD }}
331 }; 334 };
332 struct e1000_desc_ring *rx_ring = &adapter->rx_ring; 335 struct e1000_rx_ring *rx_ring = adapter->rx_ring;
336 int i;
333 e1000_mac_type mac_type = adapter->hw.mac_type; 337 e1000_mac_type mac_type = adapter->hw.mac_type;
334 opt.arg.r.max = mac_type < e1000_82544 ? E1000_MAX_RXD : 338 opt.arg.r.max = mac_type < e1000_82544 ? E1000_MAX_RXD :
335 E1000_MAX_82544_RXD; 339 E1000_MAX_82544_RXD;
@@ -342,6 +346,8 @@ e1000_check_options(struct e1000_adapter *adapter)
342 } else { 346 } else {
343 rx_ring->count = opt.def; 347 rx_ring->count = opt.def;
344 } 348 }
349 for (i = 0; i < adapter->num_queues; i++)
350 rx_ring[i].count = rx_ring->count;
345 } 351 }
346 { /* Checksum Offload Enable/Disable */ 352 { /* Checksum Offload Enable/Disable */
347 struct e1000_option opt = { 353 struct e1000_option opt = {
diff --git a/drivers/net/eepro.c b/drivers/net/eepro.c
index dcb3028bb60f..a806dfe54d23 100644
--- a/drivers/net/eepro.c
+++ b/drivers/net/eepro.c
@@ -552,8 +552,7 @@ static int __init do_eepro_probe(struct net_device *dev)
552 { 552 {
553 unsigned short int WS[32]=WakeupSeq; 553 unsigned short int WS[32]=WakeupSeq;
554 554
555 if (check_region(WakeupPort, 2)==0) { 555 if (request_region(WakeupPort, 2, "eepro wakeup")) {
556
557 if (net_debug>5) 556 if (net_debug>5)
558 printk(KERN_DEBUG "Waking UP\n"); 557 printk(KERN_DEBUG "Waking UP\n");
559 558
@@ -563,7 +562,10 @@ static int __init do_eepro_probe(struct net_device *dev)
563 outb_p(WS[i],WakeupPort); 562 outb_p(WS[i],WakeupPort);
564 if (net_debug>5) printk(KERN_DEBUG ": %#x ",WS[i]); 563 if (net_debug>5) printk(KERN_DEBUG ": %#x ",WS[i]);
565 } 564 }
566 } else printk(KERN_WARNING "Checkregion Failed!\n"); 565
566 release_region(WakeupPort, 2);
567 } else
568 printk(KERN_WARNING "PnP wakeup region busy!\n");
567 } 569 }
568#endif 570#endif
569 571
@@ -705,7 +707,7 @@ static void __init eepro_print_info (struct net_device *dev)
705 dev->name, (unsigned)dev->base_addr); 707 dev->name, (unsigned)dev->base_addr);
706 break; 708 break;
707 case LAN595FX: 709 case LAN595FX:
708 printk("%s: Intel EtherExpress Pro/10+ ISA\n at %#x,", 710 printk("%s: Intel EtherExpress Pro/10+ ISA\n at %#x,",
709 dev->name, (unsigned)dev->base_addr); 711 dev->name, (unsigned)dev->base_addr);
710 break; 712 break;
711 case LAN595TX: 713 case LAN595TX:
@@ -713,7 +715,7 @@ static void __init eepro_print_info (struct net_device *dev)
713 dev->name, (unsigned)dev->base_addr); 715 dev->name, (unsigned)dev->base_addr);
714 break; 716 break;
715 case LAN595: 717 case LAN595:
716 printk("%s: Intel 82595-based lan card at %#x,", 718 printk("%s: Intel 82595-based lan card at %#x,",
717 dev->name, (unsigned)dev->base_addr); 719 dev->name, (unsigned)dev->base_addr);
718 } 720 }
719 721
@@ -726,7 +728,7 @@ static void __init eepro_print_info (struct net_device *dev)
726 728
727 if (dev->irq > 2) 729 if (dev->irq > 2)
728 printk(", IRQ %d, %s.\n", dev->irq, ifmap[dev->if_port]); 730 printk(", IRQ %d, %s.\n", dev->irq, ifmap[dev->if_port]);
729 else 731 else
730 printk(", %s.\n", ifmap[dev->if_port]); 732 printk(", %s.\n", ifmap[dev->if_port]);
731 733
732 if (net_debug > 3) { 734 if (net_debug > 3) {
@@ -756,7 +758,7 @@ static int __init eepro_probe1(struct net_device *dev, int autoprobe)
756 int err; 758 int err;
757 759
758 /* Grab the region so we can find another board if autoIRQ fails. */ 760 /* Grab the region so we can find another board if autoIRQ fails. */
759 if (!request_region(ioaddr, EEPRO_IO_EXTENT, DRV_NAME)) { 761 if (!request_region(ioaddr, EEPRO_IO_EXTENT, DRV_NAME)) {
760 if (!autoprobe) 762 if (!autoprobe)
761 printk(KERN_WARNING "EEPRO: io-port 0x%04x in use \n", 763 printk(KERN_WARNING "EEPRO: io-port 0x%04x in use \n",
762 ioaddr); 764 ioaddr);
@@ -838,15 +840,15 @@ static int __init eepro_probe1(struct net_device *dev, int autoprobe)
838 /* Mask off INT number */ 840 /* Mask off INT number */
839 int count = lp->word[1] & 7; 841 int count = lp->word[1] & 7;
840 unsigned irqMask = lp->word[7]; 842 unsigned irqMask = lp->word[7];
841 843
842 while (count--) 844 while (count--)
843 irqMask &= irqMask - 1; 845 irqMask &= irqMask - 1;
844 846
845 count = ffs(irqMask); 847 count = ffs(irqMask);
846 848
847 if (count) 849 if (count)
848 dev->irq = count - 1; 850 dev->irq = count - 1;
849 851
850 if (dev->irq < 2) { 852 if (dev->irq < 2) {
851 printk(KERN_ERR " Duh! illegal interrupt vector stored in EEPROM.\n"); 853 printk(KERN_ERR " Duh! illegal interrupt vector stored in EEPROM.\n");
852 goto exit; 854 goto exit;
@@ -854,7 +856,7 @@ static int __init eepro_probe1(struct net_device *dev, int autoprobe)
854 dev->irq = 9; 856 dev->irq = 9;
855 } 857 }
856 } 858 }
857 859
858 dev->open = eepro_open; 860 dev->open = eepro_open;
859 dev->stop = eepro_close; 861 dev->stop = eepro_close;
860 dev->hard_start_xmit = eepro_send_packet; 862 dev->hard_start_xmit = eepro_send_packet;
@@ -863,7 +865,7 @@ static int __init eepro_probe1(struct net_device *dev, int autoprobe)
863 dev->tx_timeout = eepro_tx_timeout; 865 dev->tx_timeout = eepro_tx_timeout;
864 dev->watchdog_timeo = TX_TIMEOUT; 866 dev->watchdog_timeo = TX_TIMEOUT;
865 dev->ethtool_ops = &eepro_ethtool_ops; 867 dev->ethtool_ops = &eepro_ethtool_ops;
866 868
867 /* print boot time info */ 869 /* print boot time info */
868 eepro_print_info(dev); 870 eepro_print_info(dev);
869 871
@@ -1047,8 +1049,8 @@ static int eepro_open(struct net_device *dev)
1047 1049
1048 1050
1049 /* Initialize the RCV and XMT upper and lower limits */ 1051 /* Initialize the RCV and XMT upper and lower limits */
1050 outb(lp->rcv_lower_limit >> 8, ioaddr + RCV_LOWER_LIMIT_REG); 1052 outb(lp->rcv_lower_limit >> 8, ioaddr + RCV_LOWER_LIMIT_REG);
1051 outb(lp->rcv_upper_limit >> 8, ioaddr + RCV_UPPER_LIMIT_REG); 1053 outb(lp->rcv_upper_limit >> 8, ioaddr + RCV_UPPER_LIMIT_REG);
1052 outb(lp->xmt_lower_limit >> 8, ioaddr + lp->xmt_lower_limit_reg); 1054 outb(lp->xmt_lower_limit >> 8, ioaddr + lp->xmt_lower_limit_reg);
1053 outb(lp->xmt_upper_limit >> 8, ioaddr + lp->xmt_upper_limit_reg); 1055 outb(lp->xmt_upper_limit >> 8, ioaddr + lp->xmt_upper_limit_reg);
1054 1056
@@ -1065,12 +1067,12 @@ static int eepro_open(struct net_device *dev)
1065 eepro_clear_int(ioaddr); 1067 eepro_clear_int(ioaddr);
1066 1068
1067 /* Initialize RCV */ 1069 /* Initialize RCV */
1068 outw(lp->rcv_lower_limit, ioaddr + RCV_BAR); 1070 outw(lp->rcv_lower_limit, ioaddr + RCV_BAR);
1069 lp->rx_start = lp->rcv_lower_limit; 1071 lp->rx_start = lp->rcv_lower_limit;
1070 outw(lp->rcv_upper_limit | 0xfe, ioaddr + RCV_STOP); 1072 outw(lp->rcv_upper_limit | 0xfe, ioaddr + RCV_STOP);
1071 1073
1072 /* Initialize XMT */ 1074 /* Initialize XMT */
1073 outw(lp->xmt_lower_limit, ioaddr + lp->xmt_bar); 1075 outw(lp->xmt_lower_limit, ioaddr + lp->xmt_bar);
1074 lp->tx_start = lp->tx_end = lp->xmt_lower_limit; 1076 lp->tx_start = lp->tx_end = lp->xmt_lower_limit;
1075 lp->tx_last = 0; 1077 lp->tx_last = 0;
1076 1078
@@ -1411,7 +1413,7 @@ set_multicast_list(struct net_device *dev)
1411 outb(0x08, ioaddr + STATUS_REG); 1413 outb(0x08, ioaddr + STATUS_REG);
1412 1414
1413 if (i & 0x20) { /* command ABORTed */ 1415 if (i & 0x20) { /* command ABORTed */
1414 printk(KERN_NOTICE "%s: multicast setup failed.\n", 1416 printk(KERN_NOTICE "%s: multicast setup failed.\n",
1415 dev->name); 1417 dev->name);
1416 break; 1418 break;
1417 } else if ((i & 0x0f) == 0x03) { /* MC-Done */ 1419 } else if ((i & 0x0f) == 0x03) { /* MC-Done */
@@ -1512,7 +1514,7 @@ hardware_send_packet(struct net_device *dev, void *buf, short length)
1512 end = last + (((length + 3) >> 1) << 1) + XMT_HEADER; 1514 end = last + (((length + 3) >> 1) << 1) + XMT_HEADER;
1513 1515
1514 if (end >= lp->xmt_upper_limit + 2) { /* the transmit buffer is wrapped around */ 1516 if (end >= lp->xmt_upper_limit + 2) { /* the transmit buffer is wrapped around */
1515 if ((lp->xmt_upper_limit + 2 - last) <= XMT_HEADER) { 1517 if ((lp->xmt_upper_limit + 2 - last) <= XMT_HEADER) {
1516 /* Arrrr!!!, must keep the xmt header together, 1518 /* Arrrr!!!, must keep the xmt header together,
1517 several days were lost to chase this one down. */ 1519 several days were lost to chase this one down. */
1518 last = lp->xmt_lower_limit; 1520 last = lp->xmt_lower_limit;
@@ -1643,7 +1645,7 @@ eepro_rx(struct net_device *dev)
1643 else if (rcv_status & 0x0800) 1645 else if (rcv_status & 0x0800)
1644 lp->stats.rx_crc_errors++; 1646 lp->stats.rx_crc_errors++;
1645 1647
1646 printk(KERN_DEBUG "%s: event = %#x, status = %#x, next = %#x, size = %#x\n", 1648 printk(KERN_DEBUG "%s: event = %#x, status = %#x, next = %#x, size = %#x\n",
1647 dev->name, rcv_event, rcv_status, rcv_next_frame, rcv_size); 1649 dev->name, rcv_event, rcv_status, rcv_next_frame, rcv_size);
1648 } 1650 }
1649 1651
@@ -1674,10 +1676,10 @@ eepro_transmit_interrupt(struct net_device *dev)
1674{ 1676{
1675 struct eepro_local *lp = netdev_priv(dev); 1677 struct eepro_local *lp = netdev_priv(dev);
1676 short ioaddr = dev->base_addr; 1678 short ioaddr = dev->base_addr;
1677 short boguscount = 25; 1679 short boguscount = 25;
1678 short xmt_status; 1680 short xmt_status;
1679 1681
1680 while ((lp->tx_start != lp->tx_end) && boguscount--) { 1682 while ((lp->tx_start != lp->tx_end) && boguscount--) {
1681 1683
1682 outw(lp->tx_start, ioaddr + HOST_ADDRESS_REG); 1684 outw(lp->tx_start, ioaddr + HOST_ADDRESS_REG);
1683 xmt_status = inw(ioaddr+IO_PORT); 1685 xmt_status = inw(ioaddr+IO_PORT);
@@ -1723,7 +1725,7 @@ static int eepro_ethtool_get_settings(struct net_device *dev,
1723{ 1725{
1724 struct eepro_local *lp = (struct eepro_local *)dev->priv; 1726 struct eepro_local *lp = (struct eepro_local *)dev->priv;
1725 1727
1726 cmd->supported = SUPPORTED_10baseT_Half | 1728 cmd->supported = SUPPORTED_10baseT_Half |
1727 SUPPORTED_10baseT_Full | 1729 SUPPORTED_10baseT_Full |
1728 SUPPORTED_Autoneg; 1730 SUPPORTED_Autoneg;
1729 cmd->advertising = ADVERTISED_10baseT_Half | 1731 cmd->advertising = ADVERTISED_10baseT_Half |
@@ -1797,10 +1799,9 @@ MODULE_AUTHOR("Pascal Dupuis and others");
1797MODULE_DESCRIPTION("Intel i82595 ISA EtherExpressPro10/10+ driver"); 1799MODULE_DESCRIPTION("Intel i82595 ISA EtherExpressPro10/10+ driver");
1798MODULE_LICENSE("GPL"); 1800MODULE_LICENSE("GPL");
1799 1801
1800static int num_params; 1802module_param_array(io, int, NULL, 0);
1801module_param_array(io, int, &num_params, 0); 1803module_param_array(irq, int, NULL, 0);
1802module_param_array(irq, int, &num_params, 0); 1804module_param_array(mem, int, NULL, 0);
1803module_param_array(mem, int, &num_params, 0);
1804module_param(autodetect, int, 0); 1805module_param(autodetect, int, 0);
1805MODULE_PARM_DESC(io, "EtherExpress Pro/10 I/O base addres(es)"); 1806MODULE_PARM_DESC(io, "EtherExpress Pro/10 I/O base addres(es)");
1806MODULE_PARM_DESC(irq, "EtherExpress Pro/10 IRQ number(s)"); 1807MODULE_PARM_DESC(irq, "EtherExpress Pro/10 IRQ number(s)");
diff --git a/drivers/net/epic100.c b/drivers/net/epic100.c
index 87f522738bfc..f119ec4e89ea 100644
--- a/drivers/net/epic100.c
+++ b/drivers/net/epic100.c
@@ -1334,7 +1334,7 @@ static void epic_rx_err(struct net_device *dev, struct epic_private *ep)
1334static int epic_poll(struct net_device *dev, int *budget) 1334static int epic_poll(struct net_device *dev, int *budget)
1335{ 1335{
1336 struct epic_private *ep = dev->priv; 1336 struct epic_private *ep = dev->priv;
1337 int work_done, orig_budget; 1337 int work_done = 0, orig_budget;
1338 long ioaddr = dev->base_addr; 1338 long ioaddr = dev->base_addr;
1339 1339
1340 orig_budget = (*budget > dev->quota) ? dev->quota : *budget; 1340 orig_budget = (*budget > dev->quota) ? dev->quota : *budget;
@@ -1343,7 +1343,7 @@ rx_action:
1343 1343
1344 epic_tx(dev, ep); 1344 epic_tx(dev, ep);
1345 1345
1346 work_done = epic_rx(dev, *budget); 1346 work_done += epic_rx(dev, *budget);
1347 1347
1348 epic_rx_err(dev, ep); 1348 epic_rx_err(dev, ep);
1349 1349
diff --git a/drivers/net/forcedeth.c b/drivers/net/forcedeth.c
index d6eefdb71c17..22aec6ed80f5 100644
--- a/drivers/net/forcedeth.c
+++ b/drivers/net/forcedeth.c
@@ -95,6 +95,8 @@
95 * of nv_remove 95 * of nv_remove
96 * 0.42: 06 Aug 2005: Fix lack of link speed initialization 96 * 0.42: 06 Aug 2005: Fix lack of link speed initialization
97 * in the second (and later) nv_open call 97 * in the second (and later) nv_open call
98 * 0.43: 10 Aug 2005: Add support for tx checksum.
99 * 0.44: 20 Aug 2005: Add support for scatter gather and segmentation.
98 * 100 *
99 * Known bugs: 101 * Known bugs:
100 * We suspect that on some hardware no TX done interrupts are generated. 102 * We suspect that on some hardware no TX done interrupts are generated.
@@ -106,7 +108,7 @@
106 * DEV_NEED_TIMERIRQ will not harm you on sane hardware, only generating a few 108 * DEV_NEED_TIMERIRQ will not harm you on sane hardware, only generating a few
107 * superfluous timer interrupts from the nic. 109 * superfluous timer interrupts from the nic.
108 */ 110 */
109#define FORCEDETH_VERSION "0.41" 111#define FORCEDETH_VERSION "0.44"
110#define DRV_NAME "forcedeth" 112#define DRV_NAME "forcedeth"
111 113
112#include <linux/module.h> 114#include <linux/module.h>
@@ -145,6 +147,7 @@
145#define DEV_NEED_LINKTIMER 0x0002 /* poll link settings. Relies on the timer irq */ 147#define DEV_NEED_LINKTIMER 0x0002 /* poll link settings. Relies on the timer irq */
146#define DEV_HAS_LARGEDESC 0x0004 /* device supports jumbo frames and needs packet format 2 */ 148#define DEV_HAS_LARGEDESC 0x0004 /* device supports jumbo frames and needs packet format 2 */
147#define DEV_HAS_HIGH_DMA 0x0008 /* device supports 64bit dma */ 149#define DEV_HAS_HIGH_DMA 0x0008 /* device supports 64bit dma */
150#define DEV_HAS_CHECKSUM 0x0010 /* device supports tx and rx checksum offloads */
148 151
149enum { 152enum {
150 NvRegIrqStatus = 0x000, 153 NvRegIrqStatus = 0x000,
@@ -241,6 +244,9 @@ enum {
241#define NVREG_TXRXCTL_IDLE 0x0008 244#define NVREG_TXRXCTL_IDLE 0x0008
242#define NVREG_TXRXCTL_RESET 0x0010 245#define NVREG_TXRXCTL_RESET 0x0010
243#define NVREG_TXRXCTL_RXCHECK 0x0400 246#define NVREG_TXRXCTL_RXCHECK 0x0400
247#define NVREG_TXRXCTL_DESC_1 0
248#define NVREG_TXRXCTL_DESC_2 0x02100
249#define NVREG_TXRXCTL_DESC_3 0x02200
244 NvRegMIIStatus = 0x180, 250 NvRegMIIStatus = 0x180,
245#define NVREG_MIISTAT_ERROR 0x0001 251#define NVREG_MIISTAT_ERROR 0x0001
246#define NVREG_MIISTAT_LINKCHANGE 0x0008 252#define NVREG_MIISTAT_LINKCHANGE 0x0008
@@ -335,6 +341,10 @@ typedef union _ring_type {
335/* error and valid are the same for both */ 341/* error and valid are the same for both */
336#define NV_TX2_ERROR (1<<30) 342#define NV_TX2_ERROR (1<<30)
337#define NV_TX2_VALID (1<<31) 343#define NV_TX2_VALID (1<<31)
344#define NV_TX2_TSO (1<<28)
345#define NV_TX2_TSO_SHIFT 14
346#define NV_TX2_CHECKSUM_L3 (1<<27)
347#define NV_TX2_CHECKSUM_L4 (1<<26)
338 348
339#define NV_RX_DESCRIPTORVALID (1<<16) 349#define NV_RX_DESCRIPTORVALID (1<<16)
340#define NV_RX_MISSEDFRAME (1<<17) 350#define NV_RX_MISSEDFRAME (1<<17)
@@ -417,14 +427,14 @@ typedef union _ring_type {
417 427
418/* 428/*
419 * desc_ver values: 429 * desc_ver values:
420 * This field has two purposes: 430 * The nic supports three different descriptor types:
421 * - Newer nics uses a different ring layout. The layout is selected by 431 * - DESC_VER_1: Original
422 * comparing np->desc_ver with DESC_VER_xy. 432 * - DESC_VER_2: support for jumbo frames.
423 * - It contains bits that are forced on when writing to NvRegTxRxControl. 433 * - DESC_VER_3: 64-bit format.
424 */ 434 */
425#define DESC_VER_1 0x0 435#define DESC_VER_1 1
426#define DESC_VER_2 (0x02100|NVREG_TXRXCTL_RXCHECK) 436#define DESC_VER_2 2
427#define DESC_VER_3 (0x02200|NVREG_TXRXCTL_RXCHECK) 437#define DESC_VER_3 3
428 438
429/* PHY defines */ 439/* PHY defines */
430#define PHY_OUI_MARVELL 0x5043 440#define PHY_OUI_MARVELL 0x5043
@@ -491,6 +501,7 @@ struct fe_priv {
491 u32 orig_mac[2]; 501 u32 orig_mac[2];
492 u32 irqmask; 502 u32 irqmask;
493 u32 desc_ver; 503 u32 desc_ver;
504 u32 txrxctl_bits;
494 505
495 void __iomem *base; 506 void __iomem *base;
496 507
@@ -534,7 +545,7 @@ static inline struct fe_priv *get_nvpriv(struct net_device *dev)
534 545
535static inline u8 __iomem *get_hwbase(struct net_device *dev) 546static inline u8 __iomem *get_hwbase(struct net_device *dev)
536{ 547{
537 return get_nvpriv(dev)->base; 548 return ((struct fe_priv *)netdev_priv(dev))->base;
538} 549}
539 550
540static inline void pci_push(u8 __iomem *base) 551static inline void pci_push(u8 __iomem *base)
@@ -623,7 +634,7 @@ static int mii_rw(struct net_device *dev, int addr, int miireg, int value)
623 634
624static int phy_reset(struct net_device *dev) 635static int phy_reset(struct net_device *dev)
625{ 636{
626 struct fe_priv *np = get_nvpriv(dev); 637 struct fe_priv *np = netdev_priv(dev);
627 u32 miicontrol; 638 u32 miicontrol;
628 unsigned int tries = 0; 639 unsigned int tries = 0;
629 640
@@ -726,7 +737,7 @@ static int phy_init(struct net_device *dev)
726 737
727static void nv_start_rx(struct net_device *dev) 738static void nv_start_rx(struct net_device *dev)
728{ 739{
729 struct fe_priv *np = get_nvpriv(dev); 740 struct fe_priv *np = netdev_priv(dev);
730 u8 __iomem *base = get_hwbase(dev); 741 u8 __iomem *base = get_hwbase(dev);
731 742
732 dprintk(KERN_DEBUG "%s: nv_start_rx\n", dev->name); 743 dprintk(KERN_DEBUG "%s: nv_start_rx\n", dev->name);
@@ -782,14 +793,14 @@ static void nv_stop_tx(struct net_device *dev)
782 793
783static void nv_txrx_reset(struct net_device *dev) 794static void nv_txrx_reset(struct net_device *dev)
784{ 795{
785 struct fe_priv *np = get_nvpriv(dev); 796 struct fe_priv *np = netdev_priv(dev);
786 u8 __iomem *base = get_hwbase(dev); 797 u8 __iomem *base = get_hwbase(dev);
787 798
788 dprintk(KERN_DEBUG "%s: nv_txrx_reset\n", dev->name); 799 dprintk(KERN_DEBUG "%s: nv_txrx_reset\n", dev->name);
789 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->desc_ver, base + NvRegTxRxControl); 800 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
790 pci_push(base); 801 pci_push(base);
791 udelay(NV_TXRX_RESET_DELAY); 802 udelay(NV_TXRX_RESET_DELAY);
792 writel(NVREG_TXRXCTL_BIT2 | np->desc_ver, base + NvRegTxRxControl); 803 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
793 pci_push(base); 804 pci_push(base);
794} 805}
795 806
@@ -801,7 +812,7 @@ static void nv_txrx_reset(struct net_device *dev)
801 */ 812 */
802static struct net_device_stats *nv_get_stats(struct net_device *dev) 813static struct net_device_stats *nv_get_stats(struct net_device *dev)
803{ 814{
804 struct fe_priv *np = get_nvpriv(dev); 815 struct fe_priv *np = netdev_priv(dev);
805 816
806 /* It seems that the nic always generates interrupts and doesn't 817 /* It seems that the nic always generates interrupts and doesn't
807 * accumulate errors internally. Thus the current values in np->stats 818 * accumulate errors internally. Thus the current values in np->stats
@@ -817,7 +828,7 @@ static struct net_device_stats *nv_get_stats(struct net_device *dev)
817 */ 828 */
818static int nv_alloc_rx(struct net_device *dev) 829static int nv_alloc_rx(struct net_device *dev)
819{ 830{
820 struct fe_priv *np = get_nvpriv(dev); 831 struct fe_priv *np = netdev_priv(dev);
821 unsigned int refill_rx = np->refill_rx; 832 unsigned int refill_rx = np->refill_rx;
822 int nr; 833 int nr;
823 834
@@ -861,7 +872,7 @@ static int nv_alloc_rx(struct net_device *dev)
861static void nv_do_rx_refill(unsigned long data) 872static void nv_do_rx_refill(unsigned long data)
862{ 873{
863 struct net_device *dev = (struct net_device *) data; 874 struct net_device *dev = (struct net_device *) data;
864 struct fe_priv *np = get_nvpriv(dev); 875 struct fe_priv *np = netdev_priv(dev);
865 876
866 disable_irq(dev->irq); 877 disable_irq(dev->irq);
867 if (nv_alloc_rx(dev)) { 878 if (nv_alloc_rx(dev)) {
@@ -875,7 +886,7 @@ static void nv_do_rx_refill(unsigned long data)
875 886
876static void nv_init_rx(struct net_device *dev) 887static void nv_init_rx(struct net_device *dev)
877{ 888{
878 struct fe_priv *np = get_nvpriv(dev); 889 struct fe_priv *np = netdev_priv(dev);
879 int i; 890 int i;
880 891
881 np->cur_rx = RX_RING; 892 np->cur_rx = RX_RING;
@@ -889,15 +900,17 @@ static void nv_init_rx(struct net_device *dev)
889 900
890static void nv_init_tx(struct net_device *dev) 901static void nv_init_tx(struct net_device *dev)
891{ 902{
892 struct fe_priv *np = get_nvpriv(dev); 903 struct fe_priv *np = netdev_priv(dev);
893 int i; 904 int i;
894 905
895 np->next_tx = np->nic_tx = 0; 906 np->next_tx = np->nic_tx = 0;
896 for (i = 0; i < TX_RING; i++) 907 for (i = 0; i < TX_RING; i++) {
897 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) 908 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
898 np->tx_ring.orig[i].FlagLen = 0; 909 np->tx_ring.orig[i].FlagLen = 0;
899 else 910 else
900 np->tx_ring.ex[i].FlagLen = 0; 911 np->tx_ring.ex[i].FlagLen = 0;
912 np->tx_skbuff[i] = NULL;
913 }
901} 914}
902 915
903static int nv_init_ring(struct net_device *dev) 916static int nv_init_ring(struct net_device *dev)
@@ -907,21 +920,44 @@ static int nv_init_ring(struct net_device *dev)
907 return nv_alloc_rx(dev); 920 return nv_alloc_rx(dev);
908} 921}
909 922
923static void nv_release_txskb(struct net_device *dev, unsigned int skbnr)
924{
925 struct fe_priv *np = netdev_priv(dev);
926 struct sk_buff *skb = np->tx_skbuff[skbnr];
927 unsigned int j, entry, fragments;
928
929 dprintk(KERN_INFO "%s: nv_release_txskb for skbnr %d, skb %p\n",
930 dev->name, skbnr, np->tx_skbuff[skbnr]);
931
932 entry = skbnr;
933 if ((fragments = skb_shinfo(skb)->nr_frags) != 0) {
934 for (j = fragments; j >= 1; j--) {
935 skb_frag_t *frag = &skb_shinfo(skb)->frags[j-1];
936 pci_unmap_page(np->pci_dev, np->tx_dma[entry],
937 frag->size,
938 PCI_DMA_TODEVICE);
939 entry = (entry - 1) % TX_RING;
940 }
941 }
942 pci_unmap_single(np->pci_dev, np->tx_dma[entry],
943 skb->len - skb->data_len,
944 PCI_DMA_TODEVICE);
945 dev_kfree_skb_irq(skb);
946 np->tx_skbuff[skbnr] = NULL;
947}
948
910static void nv_drain_tx(struct net_device *dev) 949static void nv_drain_tx(struct net_device *dev)
911{ 950{
912 struct fe_priv *np = get_nvpriv(dev); 951 struct fe_priv *np = netdev_priv(dev);
913 int i; 952 unsigned int i;
953
914 for (i = 0; i < TX_RING; i++) { 954 for (i = 0; i < TX_RING; i++) {
915 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) 955 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
916 np->tx_ring.orig[i].FlagLen = 0; 956 np->tx_ring.orig[i].FlagLen = 0;
917 else 957 else
918 np->tx_ring.ex[i].FlagLen = 0; 958 np->tx_ring.ex[i].FlagLen = 0;
919 if (np->tx_skbuff[i]) { 959 if (np->tx_skbuff[i]) {
920 pci_unmap_single(np->pci_dev, np->tx_dma[i], 960 nv_release_txskb(dev, i);
921 np->tx_skbuff[i]->len,
922 PCI_DMA_TODEVICE);
923 dev_kfree_skb(np->tx_skbuff[i]);
924 np->tx_skbuff[i] = NULL;
925 np->stats.tx_dropped++; 961 np->stats.tx_dropped++;
926 } 962 }
927 } 963 }
@@ -929,7 +965,7 @@ static void nv_drain_tx(struct net_device *dev)
929 965
930static void nv_drain_rx(struct net_device *dev) 966static void nv_drain_rx(struct net_device *dev)
931{ 967{
932 struct fe_priv *np = get_nvpriv(dev); 968 struct fe_priv *np = netdev_priv(dev);
933 int i; 969 int i;
934 for (i = 0; i < RX_RING; i++) { 970 for (i = 0; i < RX_RING; i++) {
935 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) 971 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
@@ -959,28 +995,69 @@ static void drain_ring(struct net_device *dev)
959 */ 995 */
960static int nv_start_xmit(struct sk_buff *skb, struct net_device *dev) 996static int nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
961{ 997{
962 struct fe_priv *np = get_nvpriv(dev); 998 struct fe_priv *np = netdev_priv(dev);
963 int nr = np->next_tx % TX_RING; 999 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
1000 unsigned int fragments = skb_shinfo(skb)->nr_frags;
1001 unsigned int nr = (np->next_tx + fragments) % TX_RING;
1002 unsigned int i;
1003
1004 spin_lock_irq(&np->lock);
1005
1006 if ((np->next_tx - np->nic_tx + fragments) > TX_LIMIT_STOP) {
1007 spin_unlock_irq(&np->lock);
1008 netif_stop_queue(dev);
1009 return NETDEV_TX_BUSY;
1010 }
964 1011
965 np->tx_skbuff[nr] = skb; 1012 np->tx_skbuff[nr] = skb;
966 np->tx_dma[nr] = pci_map_single(np->pci_dev, skb->data,skb->len, 1013
967 PCI_DMA_TODEVICE); 1014 if (fragments) {
1015 dprintk(KERN_DEBUG "%s: nv_start_xmit: buffer contains %d fragments\n", dev->name, fragments);
1016 /* setup descriptors in reverse order */
1017 for (i = fragments; i >= 1; i--) {
1018 skb_frag_t *frag = &skb_shinfo(skb)->frags[i-1];
1019 np->tx_dma[nr] = pci_map_page(np->pci_dev, frag->page, frag->page_offset, frag->size,
1020 PCI_DMA_TODEVICE);
968 1021
969 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) 1022 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
1023 np->tx_ring.orig[nr].PacketBuffer = cpu_to_le32(np->tx_dma[nr]);
1024 np->tx_ring.orig[nr].FlagLen = cpu_to_le32( (frag->size-1) | np->tx_flags | tx_flags_extra);
1025 } else {
1026 np->tx_ring.ex[nr].PacketBufferHigh = cpu_to_le64(np->tx_dma[nr]) >> 32;
1027 np->tx_ring.ex[nr].PacketBufferLow = cpu_to_le64(np->tx_dma[nr]) & 0x0FFFFFFFF;
1028 np->tx_ring.ex[nr].FlagLen = cpu_to_le32( (frag->size-1) | np->tx_flags | tx_flags_extra);
1029 }
1030
1031 nr = (nr - 1) % TX_RING;
1032
1033 if (np->desc_ver == DESC_VER_1)
1034 tx_flags_extra &= ~NV_TX_LASTPACKET;
1035 else
1036 tx_flags_extra &= ~NV_TX2_LASTPACKET;
1037 }
1038 }
1039
1040#ifdef NETIF_F_TSO
1041 if (skb_shinfo(skb)->tso_size)
1042 tx_flags_extra |= NV_TX2_TSO | (skb_shinfo(skb)->tso_size << NV_TX2_TSO_SHIFT);
1043 else
1044#endif
1045 tx_flags_extra |= (skb->ip_summed == CHECKSUM_HW ? (NV_TX2_CHECKSUM_L3|NV_TX2_CHECKSUM_L4) : 0);
1046
1047 np->tx_dma[nr] = pci_map_single(np->pci_dev, skb->data, skb->len-skb->data_len,
1048 PCI_DMA_TODEVICE);
1049
1050 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
970 np->tx_ring.orig[nr].PacketBuffer = cpu_to_le32(np->tx_dma[nr]); 1051 np->tx_ring.orig[nr].PacketBuffer = cpu_to_le32(np->tx_dma[nr]);
971 else { 1052 np->tx_ring.orig[nr].FlagLen = cpu_to_le32( (skb->len-skb->data_len-1) | np->tx_flags | tx_flags_extra);
1053 } else {
972 np->tx_ring.ex[nr].PacketBufferHigh = cpu_to_le64(np->tx_dma[nr]) >> 32; 1054 np->tx_ring.ex[nr].PacketBufferHigh = cpu_to_le64(np->tx_dma[nr]) >> 32;
973 np->tx_ring.ex[nr].PacketBufferLow = cpu_to_le64(np->tx_dma[nr]) & 0x0FFFFFFFF; 1055 np->tx_ring.ex[nr].PacketBufferLow = cpu_to_le64(np->tx_dma[nr]) & 0x0FFFFFFFF;
974 } 1056 np->tx_ring.ex[nr].FlagLen = cpu_to_le32( (skb->len-skb->data_len-1) | np->tx_flags | tx_flags_extra);
1057 }
975 1058
976 spin_lock_irq(&np->lock); 1059 dprintk(KERN_DEBUG "%s: nv_start_xmit: packet packet %d queued for transmission. tx_flags_extra: %x\n",
977 wmb(); 1060 dev->name, np->next_tx, tx_flags_extra);
978 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
979 np->tx_ring.orig[nr].FlagLen = cpu_to_le32( (skb->len-1) | np->tx_flags );
980 else
981 np->tx_ring.ex[nr].FlagLen = cpu_to_le32( (skb->len-1) | np->tx_flags );
982 dprintk(KERN_DEBUG "%s: nv_start_xmit: packet packet %d queued for transmission.\n",
983 dev->name, np->next_tx);
984 { 1061 {
985 int j; 1062 int j;
986 for (j=0; j<64; j++) { 1063 for (j=0; j<64; j++) {
@@ -991,15 +1068,13 @@ static int nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
991 dprintk("\n"); 1068 dprintk("\n");
992 } 1069 }
993 1070
994 np->next_tx++; 1071 np->next_tx += 1 + fragments;
995 1072
996 dev->trans_start = jiffies; 1073 dev->trans_start = jiffies;
997 if (np->next_tx - np->nic_tx >= TX_LIMIT_STOP)
998 netif_stop_queue(dev);
999 spin_unlock_irq(&np->lock); 1074 spin_unlock_irq(&np->lock);
1000 writel(NVREG_TXRXCTL_KICK|np->desc_ver, get_hwbase(dev) + NvRegTxRxControl); 1075 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
1001 pci_push(get_hwbase(dev)); 1076 pci_push(get_hwbase(dev));
1002 return 0; 1077 return NETDEV_TX_OK;
1003} 1078}
1004 1079
1005/* 1080/*
@@ -1009,9 +1084,10 @@ static int nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
1009 */ 1084 */
1010static void nv_tx_done(struct net_device *dev) 1085static void nv_tx_done(struct net_device *dev)
1011{ 1086{
1012 struct fe_priv *np = get_nvpriv(dev); 1087 struct fe_priv *np = netdev_priv(dev);
1013 u32 Flags; 1088 u32 Flags;
1014 int i; 1089 unsigned int i;
1090 struct sk_buff *skb;
1015 1091
1016 while (np->nic_tx != np->next_tx) { 1092 while (np->nic_tx != np->next_tx) {
1017 i = np->nic_tx % TX_RING; 1093 i = np->nic_tx % TX_RING;
@@ -1026,35 +1102,38 @@ static void nv_tx_done(struct net_device *dev)
1026 if (Flags & NV_TX_VALID) 1102 if (Flags & NV_TX_VALID)
1027 break; 1103 break;
1028 if (np->desc_ver == DESC_VER_1) { 1104 if (np->desc_ver == DESC_VER_1) {
1029 if (Flags & (NV_TX_RETRYERROR|NV_TX_CARRIERLOST|NV_TX_LATECOLLISION| 1105 if (Flags & NV_TX_LASTPACKET) {
1030 NV_TX_UNDERFLOW|NV_TX_ERROR)) { 1106 skb = np->tx_skbuff[i];
1031 if (Flags & NV_TX_UNDERFLOW) 1107 if (Flags & (NV_TX_RETRYERROR|NV_TX_CARRIERLOST|NV_TX_LATECOLLISION|
1032 np->stats.tx_fifo_errors++; 1108 NV_TX_UNDERFLOW|NV_TX_ERROR)) {
1033 if (Flags & NV_TX_CARRIERLOST) 1109 if (Flags & NV_TX_UNDERFLOW)
1034 np->stats.tx_carrier_errors++; 1110 np->stats.tx_fifo_errors++;
1035 np->stats.tx_errors++; 1111 if (Flags & NV_TX_CARRIERLOST)
1036 } else { 1112 np->stats.tx_carrier_errors++;
1037 np->stats.tx_packets++; 1113 np->stats.tx_errors++;
1038 np->stats.tx_bytes += np->tx_skbuff[i]->len; 1114 } else {
1115 np->stats.tx_packets++;
1116 np->stats.tx_bytes += skb->len;
1117 }
1118 nv_release_txskb(dev, i);
1039 } 1119 }
1040 } else { 1120 } else {
1041 if (Flags & (NV_TX2_RETRYERROR|NV_TX2_CARRIERLOST|NV_TX2_LATECOLLISION| 1121 if (Flags & NV_TX2_LASTPACKET) {
1042 NV_TX2_UNDERFLOW|NV_TX2_ERROR)) { 1122 skb = np->tx_skbuff[i];
1043 if (Flags & NV_TX2_UNDERFLOW) 1123 if (Flags & (NV_TX2_RETRYERROR|NV_TX2_CARRIERLOST|NV_TX2_LATECOLLISION|
1044 np->stats.tx_fifo_errors++; 1124 NV_TX2_UNDERFLOW|NV_TX2_ERROR)) {
1045 if (Flags & NV_TX2_CARRIERLOST) 1125 if (Flags & NV_TX2_UNDERFLOW)
1046 np->stats.tx_carrier_errors++; 1126 np->stats.tx_fifo_errors++;
1047 np->stats.tx_errors++; 1127 if (Flags & NV_TX2_CARRIERLOST)
1048 } else { 1128 np->stats.tx_carrier_errors++;
1049 np->stats.tx_packets++; 1129 np->stats.tx_errors++;
1050 np->stats.tx_bytes += np->tx_skbuff[i]->len; 1130 } else {
1131 np->stats.tx_packets++;
1132 np->stats.tx_bytes += skb->len;
1133 }
1134 nv_release_txskb(dev, i);
1051 } 1135 }
1052 } 1136 }
1053 pci_unmap_single(np->pci_dev, np->tx_dma[i],
1054 np->tx_skbuff[i]->len,
1055 PCI_DMA_TODEVICE);
1056 dev_kfree_skb_irq(np->tx_skbuff[i]);
1057 np->tx_skbuff[i] = NULL;
1058 np->nic_tx++; 1137 np->nic_tx++;
1059 } 1138 }
1060 if (np->next_tx - np->nic_tx < TX_LIMIT_START) 1139 if (np->next_tx - np->nic_tx < TX_LIMIT_START)
@@ -1067,7 +1146,7 @@ static void nv_tx_done(struct net_device *dev)
1067 */ 1146 */
1068static void nv_tx_timeout(struct net_device *dev) 1147static void nv_tx_timeout(struct net_device *dev)
1069{ 1148{
1070 struct fe_priv *np = get_nvpriv(dev); 1149 struct fe_priv *np = netdev_priv(dev);
1071 u8 __iomem *base = get_hwbase(dev); 1150 u8 __iomem *base = get_hwbase(dev);
1072 1151
1073 printk(KERN_INFO "%s: Got tx_timeout. irq: %08x\n", dev->name, 1152 printk(KERN_INFO "%s: Got tx_timeout. irq: %08x\n", dev->name,
@@ -1200,7 +1279,7 @@ static int nv_getlen(struct net_device *dev, void *packet, int datalen)
1200 1279
1201static void nv_rx_process(struct net_device *dev) 1280static void nv_rx_process(struct net_device *dev)
1202{ 1281{
1203 struct fe_priv *np = get_nvpriv(dev); 1282 struct fe_priv *np = netdev_priv(dev);
1204 u32 Flags; 1283 u32 Flags;
1205 1284
1206 for (;;) { 1285 for (;;) {
@@ -1355,7 +1434,7 @@ static void set_bufsize(struct net_device *dev)
1355 */ 1434 */
1356static int nv_change_mtu(struct net_device *dev, int new_mtu) 1435static int nv_change_mtu(struct net_device *dev, int new_mtu)
1357{ 1436{
1358 struct fe_priv *np = get_nvpriv(dev); 1437 struct fe_priv *np = netdev_priv(dev);
1359 int old_mtu; 1438 int old_mtu;
1360 1439
1361 if (new_mtu < 64 || new_mtu > np->pkt_limit) 1440 if (new_mtu < 64 || new_mtu > np->pkt_limit)
@@ -1408,7 +1487,7 @@ static int nv_change_mtu(struct net_device *dev, int new_mtu)
1408 writel( ((RX_RING-1) << NVREG_RINGSZ_RXSHIFT) + ((TX_RING-1) << NVREG_RINGSZ_TXSHIFT), 1487 writel( ((RX_RING-1) << NVREG_RINGSZ_RXSHIFT) + ((TX_RING-1) << NVREG_RINGSZ_TXSHIFT),
1409 base + NvRegRingSizes); 1488 base + NvRegRingSizes);
1410 pci_push(base); 1489 pci_push(base);
1411 writel(NVREG_TXRXCTL_KICK|np->desc_ver, get_hwbase(dev) + NvRegTxRxControl); 1490 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
1412 pci_push(base); 1491 pci_push(base);
1413 1492
1414 /* restart rx engine */ 1493 /* restart rx engine */
@@ -1440,7 +1519,7 @@ static void nv_copy_mac_to_hw(struct net_device *dev)
1440 */ 1519 */
1441static int nv_set_mac_address(struct net_device *dev, void *addr) 1520static int nv_set_mac_address(struct net_device *dev, void *addr)
1442{ 1521{
1443 struct fe_priv *np = get_nvpriv(dev); 1522 struct fe_priv *np = netdev_priv(dev);
1444 struct sockaddr *macaddr = (struct sockaddr*)addr; 1523 struct sockaddr *macaddr = (struct sockaddr*)addr;
1445 1524
1446 if(!is_valid_ether_addr(macaddr->sa_data)) 1525 if(!is_valid_ether_addr(macaddr->sa_data))
@@ -1475,7 +1554,7 @@ static int nv_set_mac_address(struct net_device *dev, void *addr)
1475 */ 1554 */
1476static void nv_set_multicast(struct net_device *dev) 1555static void nv_set_multicast(struct net_device *dev)
1477{ 1556{
1478 struct fe_priv *np = get_nvpriv(dev); 1557 struct fe_priv *np = netdev_priv(dev);
1479 u8 __iomem *base = get_hwbase(dev); 1558 u8 __iomem *base = get_hwbase(dev);
1480 u32 addr[2]; 1559 u32 addr[2];
1481 u32 mask[2]; 1560 u32 mask[2];
@@ -1535,7 +1614,7 @@ static void nv_set_multicast(struct net_device *dev)
1535 1614
1536static int nv_update_linkspeed(struct net_device *dev) 1615static int nv_update_linkspeed(struct net_device *dev)
1537{ 1616{
1538 struct fe_priv *np = get_nvpriv(dev); 1617 struct fe_priv *np = netdev_priv(dev);
1539 u8 __iomem *base = get_hwbase(dev); 1618 u8 __iomem *base = get_hwbase(dev);
1540 int adv, lpa; 1619 int adv, lpa;
1541 int newls = np->linkspeed; 1620 int newls = np->linkspeed;
@@ -1705,7 +1784,7 @@ static void nv_link_irq(struct net_device *dev)
1705static irqreturn_t nv_nic_irq(int foo, void *data, struct pt_regs *regs) 1784static irqreturn_t nv_nic_irq(int foo, void *data, struct pt_regs *regs)
1706{ 1785{
1707 struct net_device *dev = (struct net_device *) data; 1786 struct net_device *dev = (struct net_device *) data;
1708 struct fe_priv *np = get_nvpriv(dev); 1787 struct fe_priv *np = netdev_priv(dev);
1709 u8 __iomem *base = get_hwbase(dev); 1788 u8 __iomem *base = get_hwbase(dev);
1710 u32 events; 1789 u32 events;
1711 int i; 1790 int i;
@@ -1777,7 +1856,7 @@ static irqreturn_t nv_nic_irq(int foo, void *data, struct pt_regs *regs)
1777static void nv_do_nic_poll(unsigned long data) 1856static void nv_do_nic_poll(unsigned long data)
1778{ 1857{
1779 struct net_device *dev = (struct net_device *) data; 1858 struct net_device *dev = (struct net_device *) data;
1780 struct fe_priv *np = get_nvpriv(dev); 1859 struct fe_priv *np = netdev_priv(dev);
1781 u8 __iomem *base = get_hwbase(dev); 1860 u8 __iomem *base = get_hwbase(dev);
1782 1861
1783 disable_irq(dev->irq); 1862 disable_irq(dev->irq);
@@ -1801,7 +1880,7 @@ static void nv_poll_controller(struct net_device *dev)
1801 1880
1802static void nv_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) 1881static void nv_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
1803{ 1882{
1804 struct fe_priv *np = get_nvpriv(dev); 1883 struct fe_priv *np = netdev_priv(dev);
1805 strcpy(info->driver, "forcedeth"); 1884 strcpy(info->driver, "forcedeth");
1806 strcpy(info->version, FORCEDETH_VERSION); 1885 strcpy(info->version, FORCEDETH_VERSION);
1807 strcpy(info->bus_info, pci_name(np->pci_dev)); 1886 strcpy(info->bus_info, pci_name(np->pci_dev));
@@ -1809,7 +1888,7 @@ static void nv_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
1809 1888
1810static void nv_get_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo) 1889static void nv_get_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
1811{ 1890{
1812 struct fe_priv *np = get_nvpriv(dev); 1891 struct fe_priv *np = netdev_priv(dev);
1813 wolinfo->supported = WAKE_MAGIC; 1892 wolinfo->supported = WAKE_MAGIC;
1814 1893
1815 spin_lock_irq(&np->lock); 1894 spin_lock_irq(&np->lock);
@@ -1820,7 +1899,7 @@ static void nv_get_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
1820 1899
1821static int nv_set_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo) 1900static int nv_set_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
1822{ 1901{
1823 struct fe_priv *np = get_nvpriv(dev); 1902 struct fe_priv *np = netdev_priv(dev);
1824 u8 __iomem *base = get_hwbase(dev); 1903 u8 __iomem *base = get_hwbase(dev);
1825 1904
1826 spin_lock_irq(&np->lock); 1905 spin_lock_irq(&np->lock);
@@ -2021,7 +2100,7 @@ static int nv_get_regs_len(struct net_device *dev)
2021 2100
2022static void nv_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *buf) 2101static void nv_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *buf)
2023{ 2102{
2024 struct fe_priv *np = get_nvpriv(dev); 2103 struct fe_priv *np = netdev_priv(dev);
2025 u8 __iomem *base = get_hwbase(dev); 2104 u8 __iomem *base = get_hwbase(dev);
2026 u32 *rbuf = buf; 2105 u32 *rbuf = buf;
2027 int i; 2106 int i;
@@ -2035,7 +2114,7 @@ static void nv_get_regs(struct net_device *dev, struct ethtool_regs *regs, void
2035 2114
2036static int nv_nway_reset(struct net_device *dev) 2115static int nv_nway_reset(struct net_device *dev)
2037{ 2116{
2038 struct fe_priv *np = get_nvpriv(dev); 2117 struct fe_priv *np = netdev_priv(dev);
2039 int ret; 2118 int ret;
2040 2119
2041 spin_lock_irq(&np->lock); 2120 spin_lock_irq(&np->lock);
@@ -2065,11 +2144,12 @@ static struct ethtool_ops ops = {
2065 .get_regs_len = nv_get_regs_len, 2144 .get_regs_len = nv_get_regs_len,
2066 .get_regs = nv_get_regs, 2145 .get_regs = nv_get_regs,
2067 .nway_reset = nv_nway_reset, 2146 .nway_reset = nv_nway_reset,
2147 .get_perm_addr = ethtool_op_get_perm_addr,
2068}; 2148};
2069 2149
2070static int nv_open(struct net_device *dev) 2150static int nv_open(struct net_device *dev)
2071{ 2151{
2072 struct fe_priv *np = get_nvpriv(dev); 2152 struct fe_priv *np = netdev_priv(dev);
2073 u8 __iomem *base = get_hwbase(dev); 2153 u8 __iomem *base = get_hwbase(dev);
2074 int ret, oom, i; 2154 int ret, oom, i;
2075 2155
@@ -2114,9 +2194,9 @@ static int nv_open(struct net_device *dev)
2114 /* 5) continue setup */ 2194 /* 5) continue setup */
2115 writel(np->linkspeed, base + NvRegLinkSpeed); 2195 writel(np->linkspeed, base + NvRegLinkSpeed);
2116 writel(NVREG_UNKSETUP3_VAL1, base + NvRegUnknownSetupReg3); 2196 writel(NVREG_UNKSETUP3_VAL1, base + NvRegUnknownSetupReg3);
2117 writel(np->desc_ver, base + NvRegTxRxControl); 2197 writel(np->txrxctl_bits, base + NvRegTxRxControl);
2118 pci_push(base); 2198 pci_push(base);
2119 writel(NVREG_TXRXCTL_BIT1|np->desc_ver, base + NvRegTxRxControl); 2199 writel(NVREG_TXRXCTL_BIT1|np->txrxctl_bits, base + NvRegTxRxControl);
2120 reg_delay(dev, NvRegUnknownSetupReg5, NVREG_UNKSETUP5_BIT31, NVREG_UNKSETUP5_BIT31, 2200 reg_delay(dev, NvRegUnknownSetupReg5, NVREG_UNKSETUP5_BIT31, NVREG_UNKSETUP5_BIT31,
2121 NV_SETUP5_DELAY, NV_SETUP5_DELAYMAX, 2201 NV_SETUP5_DELAY, NV_SETUP5_DELAYMAX,
2122 KERN_INFO "open: SetupReg5, Bit 31 remained off\n"); 2202 KERN_INFO "open: SetupReg5, Bit 31 remained off\n");
@@ -2205,7 +2285,7 @@ out_drain:
2205 2285
2206static int nv_close(struct net_device *dev) 2286static int nv_close(struct net_device *dev)
2207{ 2287{
2208 struct fe_priv *np = get_nvpriv(dev); 2288 struct fe_priv *np = netdev_priv(dev);
2209 u8 __iomem *base; 2289 u8 __iomem *base;
2210 2290
2211 spin_lock_irq(&np->lock); 2291 spin_lock_irq(&np->lock);
@@ -2261,7 +2341,7 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
2261 if (!dev) 2341 if (!dev)
2262 goto out; 2342 goto out;
2263 2343
2264 np = get_nvpriv(dev); 2344 np = netdev_priv(dev);
2265 np->pci_dev = pci_dev; 2345 np->pci_dev = pci_dev;
2266 spin_lock_init(&np->lock); 2346 spin_lock_init(&np->lock);
2267 SET_MODULE_OWNER(dev); 2347 SET_MODULE_OWNER(dev);
@@ -2313,19 +2393,32 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
2313 if (pci_set_dma_mask(pci_dev, 0x0000007fffffffffULL)) { 2393 if (pci_set_dma_mask(pci_dev, 0x0000007fffffffffULL)) {
2314 printk(KERN_INFO "forcedeth: 64-bit DMA failed, using 32-bit addressing for device %s.\n", 2394 printk(KERN_INFO "forcedeth: 64-bit DMA failed, using 32-bit addressing for device %s.\n",
2315 pci_name(pci_dev)); 2395 pci_name(pci_dev));
2396 } else {
2397 dev->features |= NETIF_F_HIGHDMA;
2316 } 2398 }
2399 np->txrxctl_bits = NVREG_TXRXCTL_DESC_3;
2317 } else if (id->driver_data & DEV_HAS_LARGEDESC) { 2400 } else if (id->driver_data & DEV_HAS_LARGEDESC) {
2318 /* packet format 2: supports jumbo frames */ 2401 /* packet format 2: supports jumbo frames */
2319 np->desc_ver = DESC_VER_2; 2402 np->desc_ver = DESC_VER_2;
2403 np->txrxctl_bits = NVREG_TXRXCTL_DESC_2;
2320 } else { 2404 } else {
2321 /* original packet format */ 2405 /* original packet format */
2322 np->desc_ver = DESC_VER_1; 2406 np->desc_ver = DESC_VER_1;
2407 np->txrxctl_bits = NVREG_TXRXCTL_DESC_1;
2323 } 2408 }
2324 2409
2325 np->pkt_limit = NV_PKTLIMIT_1; 2410 np->pkt_limit = NV_PKTLIMIT_1;
2326 if (id->driver_data & DEV_HAS_LARGEDESC) 2411 if (id->driver_data & DEV_HAS_LARGEDESC)
2327 np->pkt_limit = NV_PKTLIMIT_2; 2412 np->pkt_limit = NV_PKTLIMIT_2;
2328 2413
2414 if (id->driver_data & DEV_HAS_CHECKSUM) {
2415 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
2416 dev->features |= NETIF_F_HW_CSUM | NETIF_F_SG;
2417#ifdef NETIF_F_TSO
2418 dev->features |= NETIF_F_TSO;
2419#endif
2420 }
2421
2329 err = -ENOMEM; 2422 err = -ENOMEM;
2330 np->base = ioremap(addr, NV_PCI_REGSZ); 2423 np->base = ioremap(addr, NV_PCI_REGSZ);
2331 if (!np->base) 2424 if (!np->base)
@@ -2377,8 +2470,9 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
2377 dev->dev_addr[3] = (np->orig_mac[0] >> 16) & 0xff; 2470 dev->dev_addr[3] = (np->orig_mac[0] >> 16) & 0xff;
2378 dev->dev_addr[4] = (np->orig_mac[0] >> 8) & 0xff; 2471 dev->dev_addr[4] = (np->orig_mac[0] >> 8) & 0xff;
2379 dev->dev_addr[5] = (np->orig_mac[0] >> 0) & 0xff; 2472 dev->dev_addr[5] = (np->orig_mac[0] >> 0) & 0xff;
2473 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
2380 2474
2381 if (!is_valid_ether_addr(dev->dev_addr)) { 2475 if (!is_valid_ether_addr(dev->perm_addr)) {
2382 /* 2476 /*
2383 * Bad mac address. At least one bios sets the mac address 2477 * Bad mac address. At least one bios sets the mac address
2384 * to 01:23:45:67:89:ab 2478 * to 01:23:45:67:89:ab
@@ -2403,9 +2497,9 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
2403 np->wolenabled = 0; 2497 np->wolenabled = 0;
2404 2498
2405 if (np->desc_ver == DESC_VER_1) { 2499 if (np->desc_ver == DESC_VER_1) {
2406 np->tx_flags = NV_TX_LASTPACKET|NV_TX_VALID; 2500 np->tx_flags = NV_TX_VALID;
2407 } else { 2501 } else {
2408 np->tx_flags = NV_TX2_LASTPACKET|NV_TX2_VALID; 2502 np->tx_flags = NV_TX2_VALID;
2409 } 2503 }
2410 np->irqmask = NVREG_IRQMASK_WANTED; 2504 np->irqmask = NVREG_IRQMASK_WANTED;
2411 if (id->driver_data & DEV_NEED_TIMERIRQ) 2505 if (id->driver_data & DEV_NEED_TIMERIRQ)
@@ -2494,7 +2588,7 @@ out:
2494static void __devexit nv_remove(struct pci_dev *pci_dev) 2588static void __devexit nv_remove(struct pci_dev *pci_dev)
2495{ 2589{
2496 struct net_device *dev = pci_get_drvdata(pci_dev); 2590 struct net_device *dev = pci_get_drvdata(pci_dev);
2497 struct fe_priv *np = get_nvpriv(dev); 2591 struct fe_priv *np = netdev_priv(dev);
2498 2592
2499 unregister_netdev(dev); 2593 unregister_netdev(dev);
2500 2594
@@ -2525,35 +2619,35 @@ static struct pci_device_id pci_tbl[] = {
2525 }, 2619 },
2526 { /* nForce3 Ethernet Controller */ 2620 { /* nForce3 Ethernet Controller */
2527 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_4), 2621 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_4),
2528 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC, 2622 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
2529 }, 2623 },
2530 { /* nForce3 Ethernet Controller */ 2624 { /* nForce3 Ethernet Controller */
2531 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_5), 2625 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_5),
2532 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC, 2626 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
2533 }, 2627 },
2534 { /* nForce3 Ethernet Controller */ 2628 { /* nForce3 Ethernet Controller */
2535 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_6), 2629 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_6),
2536 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC, 2630 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
2537 }, 2631 },
2538 { /* nForce3 Ethernet Controller */ 2632 { /* nForce3 Ethernet Controller */
2539 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_7), 2633 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_7),
2540 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC, 2634 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
2541 }, 2635 },
2542 { /* CK804 Ethernet Controller */ 2636 { /* CK804 Ethernet Controller */
2543 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_8), 2637 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_8),
2544 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA, 2638 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
2545 }, 2639 },
2546 { /* CK804 Ethernet Controller */ 2640 { /* CK804 Ethernet Controller */
2547 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_9), 2641 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_9),
2548 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA, 2642 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
2549 }, 2643 },
2550 { /* MCP04 Ethernet Controller */ 2644 { /* MCP04 Ethernet Controller */
2551 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_10), 2645 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_10),
2552 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA, 2646 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
2553 }, 2647 },
2554 { /* MCP04 Ethernet Controller */ 2648 { /* MCP04 Ethernet Controller */
2555 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_11), 2649 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_11),
2556 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA, 2650 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
2557 }, 2651 },
2558 { /* MCP51 Ethernet Controller */ 2652 { /* MCP51 Ethernet Controller */
2559 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_12), 2653 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_12),
@@ -2565,11 +2659,11 @@ static struct pci_device_id pci_tbl[] = {
2565 }, 2659 },
2566 { /* MCP55 Ethernet Controller */ 2660 { /* MCP55 Ethernet Controller */
2567 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_14), 2661 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_14),
2568 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA, 2662 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
2569 }, 2663 },
2570 { /* MCP55 Ethernet Controller */ 2664 { /* MCP55 Ethernet Controller */
2571 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_15), 2665 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_15),
2572 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA, 2666 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
2573 }, 2667 },
2574 {0,}, 2668 {0,},
2575}; 2669};
diff --git a/drivers/net/fs_enet/Kconfig b/drivers/net/fs_enet/Kconfig
new file mode 100644
index 000000000000..6aaee67dd4b7
--- /dev/null
+++ b/drivers/net/fs_enet/Kconfig
@@ -0,0 +1,20 @@
1config FS_ENET
2 tristate "Freescale Ethernet Driver"
3 depends on NET_ETHERNET && (CPM1 || CPM2)
4 select MII
5
6config FS_ENET_HAS_SCC
7 bool "Chip has an SCC usable for ethernet"
8 depends on FS_ENET && (CPM1 || CPM2)
9 default y
10
11config FS_ENET_HAS_FCC
12 bool "Chip has an FCC usable for ethernet"
13 depends on FS_ENET && CPM2
14 default y
15
16config FS_ENET_HAS_FEC
17 bool "Chip has an FEC usable for ethernet"
18 depends on FS_ENET && CPM1
19 default y
20
diff --git a/drivers/net/fs_enet/Makefile b/drivers/net/fs_enet/Makefile
new file mode 100644
index 000000000000..d6dd3f2fb43e
--- /dev/null
+++ b/drivers/net/fs_enet/Makefile
@@ -0,0 +1,10 @@
1#
2# Makefile for the Freescale Ethernet controllers
3#
4
5obj-$(CONFIG_FS_ENET) += fs_enet.o
6
7obj-$(CONFIG_8xx) += mac-fec.o mac-scc.o
8obj-$(CONFIG_8260) += mac-fcc.o
9
10fs_enet-objs := fs_enet-main.o fs_enet-mii.o mii-bitbang.o mii-fixed.o
diff --git a/drivers/net/fs_enet/fs_enet-main.c b/drivers/net/fs_enet/fs_enet-main.c
new file mode 100644
index 000000000000..44fac7373289
--- /dev/null
+++ b/drivers/net/fs_enet/fs_enet-main.c
@@ -0,0 +1,1226 @@
1/*
2 * Combined Ethernet driver for Motorola MPC8xx and MPC82xx.
3 *
4 * Copyright (c) 2003 Intracom S.A.
5 * by Pantelis Antoniou <panto@intracom.gr>
6 *
7 * 2005 (c) MontaVista Software, Inc.
8 * Vitaly Bordug <vbordug@ru.mvista.com>
9 *
10 * Heavily based on original FEC driver by Dan Malek <dan@embeddededge.com>
11 * and modifications by Joakim Tjernlund <joakim.tjernlund@lumentis.se>
12 *
13 * This file is licensed under the terms of the GNU General Public License
14 * version 2. This program is licensed "as is" without any warranty of any
15 * kind, whether express or implied.
16 */
17
18#include <linux/config.h>
19#include <linux/module.h>
20#include <linux/kernel.h>
21#include <linux/types.h>
22#include <linux/sched.h>
23#include <linux/string.h>
24#include <linux/ptrace.h>
25#include <linux/errno.h>
26#include <linux/ioport.h>
27#include <linux/slab.h>
28#include <linux/interrupt.h>
29#include <linux/pci.h>
30#include <linux/init.h>
31#include <linux/delay.h>
32#include <linux/netdevice.h>
33#include <linux/etherdevice.h>
34#include <linux/skbuff.h>
35#include <linux/spinlock.h>
36#include <linux/mii.h>
37#include <linux/ethtool.h>
38#include <linux/bitops.h>
39#include <linux/fs.h>
40
41#include <linux/vmalloc.h>
42#include <asm/pgtable.h>
43
44#include <asm/pgtable.h>
45#include <asm/irq.h>
46#include <asm/uaccess.h>
47
48#include "fs_enet.h"
49
50/*************************************************/
51
52static char version[] __devinitdata =
53 DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")" "\n";
54
55MODULE_AUTHOR("Pantelis Antoniou <panto@intracom.gr>");
56MODULE_DESCRIPTION("Freescale Ethernet Driver");
57MODULE_LICENSE("GPL");
58MODULE_VERSION(DRV_MODULE_VERSION);
59
60MODULE_PARM(fs_enet_debug, "i");
61MODULE_PARM_DESC(fs_enet_debug,
62 "Freescale bitmapped debugging message enable value");
63
64int fs_enet_debug = -1; /* -1 == use FS_ENET_DEF_MSG_ENABLE as value */
65
66static void fs_set_multicast_list(struct net_device *dev)
67{
68 struct fs_enet_private *fep = netdev_priv(dev);
69
70 (*fep->ops->set_multicast_list)(dev);
71}
72
73/* NAPI receive function */
74static int fs_enet_rx_napi(struct net_device *dev, int *budget)
75{
76 struct fs_enet_private *fep = netdev_priv(dev);
77 const struct fs_platform_info *fpi = fep->fpi;
78 cbd_t *bdp;
79 struct sk_buff *skb, *skbn, *skbt;
80 int received = 0;
81 u16 pkt_len, sc;
82 int curidx;
83 int rx_work_limit = 0; /* pacify gcc */
84
85 rx_work_limit = min(dev->quota, *budget);
86
87 if (!netif_running(dev))
88 return 0;
89
90 /*
91 * First, grab all of the stats for the incoming packet.
92 * These get messed up if we get called due to a busy condition.
93 */
94 bdp = fep->cur_rx;
95
96 /* clear RX status bits for napi*/
97 (*fep->ops->napi_clear_rx_event)(dev);
98
99 while (((sc = CBDR_SC(bdp)) & BD_ENET_RX_EMPTY) == 0) {
100
101 curidx = bdp - fep->rx_bd_base;
102
103 /*
104 * Since we have allocated space to hold a complete frame,
105 * the last indicator should be set.
106 */
107 if ((sc & BD_ENET_RX_LAST) == 0)
108 printk(KERN_WARNING DRV_MODULE_NAME
109 ": %s rcv is not +last\n",
110 dev->name);
111
112 /*
113 * Check for errors.
114 */
115 if (sc & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_CL |
116 BD_ENET_RX_NO | BD_ENET_RX_CR | BD_ENET_RX_OV)) {
117 fep->stats.rx_errors++;
118 /* Frame too long or too short. */
119 if (sc & (BD_ENET_RX_LG | BD_ENET_RX_SH))
120 fep->stats.rx_length_errors++;
121 /* Frame alignment */
122 if (sc & (BD_ENET_RX_NO | BD_ENET_RX_CL))
123 fep->stats.rx_frame_errors++;
124 /* CRC Error */
125 if (sc & BD_ENET_RX_CR)
126 fep->stats.rx_crc_errors++;
127 /* FIFO overrun */
128 if (sc & BD_ENET_RX_OV)
129 fep->stats.rx_crc_errors++;
130
131 skb = fep->rx_skbuff[curidx];
132
133 dma_unmap_single(fep->dev, skb->data,
134 L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
135 DMA_FROM_DEVICE);
136
137 skbn = skb;
138
139 } else {
140
141 /* napi, got packet but no quota */
142 if (--rx_work_limit < 0)
143 break;
144
145 skb = fep->rx_skbuff[curidx];
146
147 dma_unmap_single(fep->dev, skb->data,
148 L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
149 DMA_FROM_DEVICE);
150
151 /*
152 * Process the incoming frame.
153 */
154 fep->stats.rx_packets++;
155 pkt_len = CBDR_DATLEN(bdp) - 4; /* remove CRC */
156 fep->stats.rx_bytes += pkt_len + 4;
157
158 if (pkt_len <= fpi->rx_copybreak) {
159 /* +2 to make IP header L1 cache aligned */
160 skbn = dev_alloc_skb(pkt_len + 2);
161 if (skbn != NULL) {
162 skb_reserve(skbn, 2); /* align IP header */
163 memcpy(skbn->data, skb->data, pkt_len);
164 /* swap */
165 skbt = skb;
166 skb = skbn;
167 skbn = skbt;
168 }
169 } else
170 skbn = dev_alloc_skb(ENET_RX_FRSIZE);
171
172 if (skbn != NULL) {
173 skb->dev = dev;
174 skb_put(skb, pkt_len); /* Make room */
175 skb->protocol = eth_type_trans(skb, dev);
176 received++;
177 netif_receive_skb(skb);
178 } else {
179 printk(KERN_WARNING DRV_MODULE_NAME
180 ": %s Memory squeeze, dropping packet.\n",
181 dev->name);
182 fep->stats.rx_dropped++;
183 skbn = skb;
184 }
185 }
186
187 fep->rx_skbuff[curidx] = skbn;
188 CBDW_BUFADDR(bdp, dma_map_single(fep->dev, skbn->data,
189 L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
190 DMA_FROM_DEVICE));
191 CBDW_DATLEN(bdp, 0);
192 CBDW_SC(bdp, (sc & ~BD_ENET_RX_STATS) | BD_ENET_RX_EMPTY);
193
194 /*
195 * Update BD pointer to next entry.
196 */
197 if ((sc & BD_ENET_RX_WRAP) == 0)
198 bdp++;
199 else
200 bdp = fep->rx_bd_base;
201
202 (*fep->ops->rx_bd_done)(dev);
203 }
204
205 fep->cur_rx = bdp;
206
207 dev->quota -= received;
208 *budget -= received;
209
210 if (rx_work_limit < 0)
211 return 1; /* not done */
212
213 /* done */
214 netif_rx_complete(dev);
215
216 (*fep->ops->napi_enable_rx)(dev);
217
218 return 0;
219}
220
221/* non NAPI receive function */
222static int fs_enet_rx_non_napi(struct net_device *dev)
223{
224 struct fs_enet_private *fep = netdev_priv(dev);
225 const struct fs_platform_info *fpi = fep->fpi;
226 cbd_t *bdp;
227 struct sk_buff *skb, *skbn, *skbt;
228 int received = 0;
229 u16 pkt_len, sc;
230 int curidx;
231 /*
232 * First, grab all of the stats for the incoming packet.
233 * These get messed up if we get called due to a busy condition.
234 */
235 bdp = fep->cur_rx;
236
237 while (((sc = CBDR_SC(bdp)) & BD_ENET_RX_EMPTY) == 0) {
238
239 curidx = bdp - fep->rx_bd_base;
240
241 /*
242 * Since we have allocated space to hold a complete frame,
243 * the last indicator should be set.
244 */
245 if ((sc & BD_ENET_RX_LAST) == 0)
246 printk(KERN_WARNING DRV_MODULE_NAME
247 ": %s rcv is not +last\n",
248 dev->name);
249
250 /*
251 * Check for errors.
252 */
253 if (sc & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_CL |
254 BD_ENET_RX_NO | BD_ENET_RX_CR | BD_ENET_RX_OV)) {
255 fep->stats.rx_errors++;
256 /* Frame too long or too short. */
257 if (sc & (BD_ENET_RX_LG | BD_ENET_RX_SH))
258 fep->stats.rx_length_errors++;
259 /* Frame alignment */
260 if (sc & (BD_ENET_RX_NO | BD_ENET_RX_CL))
261 fep->stats.rx_frame_errors++;
262 /* CRC Error */
263 if (sc & BD_ENET_RX_CR)
264 fep->stats.rx_crc_errors++;
265 /* FIFO overrun */
266 if (sc & BD_ENET_RX_OV)
267 fep->stats.rx_crc_errors++;
268
269 skb = fep->rx_skbuff[curidx];
270
271 dma_unmap_single(fep->dev, skb->data,
272 L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
273 DMA_FROM_DEVICE);
274
275 skbn = skb;
276
277 } else {
278
279 skb = fep->rx_skbuff[curidx];
280
281 dma_unmap_single(fep->dev, skb->data,
282 L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
283 DMA_FROM_DEVICE);
284
285 /*
286 * Process the incoming frame.
287 */
288 fep->stats.rx_packets++;
289 pkt_len = CBDR_DATLEN(bdp) - 4; /* remove CRC */
290 fep->stats.rx_bytes += pkt_len + 4;
291
292 if (pkt_len <= fpi->rx_copybreak) {
293 /* +2 to make IP header L1 cache aligned */
294 skbn = dev_alloc_skb(pkt_len + 2);
295 if (skbn != NULL) {
296 skb_reserve(skbn, 2); /* align IP header */
297 memcpy(skbn->data, skb->data, pkt_len);
298 /* swap */
299 skbt = skb;
300 skb = skbn;
301 skbn = skbt;
302 }
303 } else
304 skbn = dev_alloc_skb(ENET_RX_FRSIZE);
305
306 if (skbn != NULL) {
307 skb->dev = dev;
308 skb_put(skb, pkt_len); /* Make room */
309 skb->protocol = eth_type_trans(skb, dev);
310 received++;
311 netif_rx(skb);
312 } else {
313 printk(KERN_WARNING DRV_MODULE_NAME
314 ": %s Memory squeeze, dropping packet.\n",
315 dev->name);
316 fep->stats.rx_dropped++;
317 skbn = skb;
318 }
319 }
320
321 fep->rx_skbuff[curidx] = skbn;
322 CBDW_BUFADDR(bdp, dma_map_single(fep->dev, skbn->data,
323 L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
324 DMA_FROM_DEVICE));
325 CBDW_DATLEN(bdp, 0);
326 CBDW_SC(bdp, (sc & ~BD_ENET_RX_STATS) | BD_ENET_RX_EMPTY);
327
328 /*
329 * Update BD pointer to next entry.
330 */
331 if ((sc & BD_ENET_RX_WRAP) == 0)
332 bdp++;
333 else
334 bdp = fep->rx_bd_base;
335
336 (*fep->ops->rx_bd_done)(dev);
337 }
338
339 fep->cur_rx = bdp;
340
341 return 0;
342}
343
344static void fs_enet_tx(struct net_device *dev)
345{
346 struct fs_enet_private *fep = netdev_priv(dev);
347 cbd_t *bdp;
348 struct sk_buff *skb;
349 int dirtyidx, do_wake, do_restart;
350 u16 sc;
351
352 spin_lock(&fep->lock);
353 bdp = fep->dirty_tx;
354
355 do_wake = do_restart = 0;
356 while (((sc = CBDR_SC(bdp)) & BD_ENET_TX_READY) == 0) {
357
358 dirtyidx = bdp - fep->tx_bd_base;
359
360 if (fep->tx_free == fep->tx_ring)
361 break;
362
363 skb = fep->tx_skbuff[dirtyidx];
364
365 /*
366 * Check for errors.
367 */
368 if (sc & (BD_ENET_TX_HB | BD_ENET_TX_LC |
369 BD_ENET_TX_RL | BD_ENET_TX_UN | BD_ENET_TX_CSL)) {
370
371 if (sc & BD_ENET_TX_HB) /* No heartbeat */
372 fep->stats.tx_heartbeat_errors++;
373 if (sc & BD_ENET_TX_LC) /* Late collision */
374 fep->stats.tx_window_errors++;
375 if (sc & BD_ENET_TX_RL) /* Retrans limit */
376 fep->stats.tx_aborted_errors++;
377 if (sc & BD_ENET_TX_UN) /* Underrun */
378 fep->stats.tx_fifo_errors++;
379 if (sc & BD_ENET_TX_CSL) /* Carrier lost */
380 fep->stats.tx_carrier_errors++;
381
382 if (sc & (BD_ENET_TX_LC | BD_ENET_TX_RL | BD_ENET_TX_UN)) {
383 fep->stats.tx_errors++;
384 do_restart = 1;
385 }
386 } else
387 fep->stats.tx_packets++;
388
389 if (sc & BD_ENET_TX_READY)
390 printk(KERN_WARNING DRV_MODULE_NAME
391 ": %s HEY! Enet xmit interrupt and TX_READY.\n",
392 dev->name);
393
394 /*
395 * Deferred means some collisions occurred during transmit,
396 * but we eventually sent the packet OK.
397 */
398 if (sc & BD_ENET_TX_DEF)
399 fep->stats.collisions++;
400
401 /* unmap */
402 dma_unmap_single(fep->dev, skb->data, skb->len, DMA_TO_DEVICE);
403
404 /*
405 * Free the sk buffer associated with this last transmit.
406 */
407 dev_kfree_skb_irq(skb);
408 fep->tx_skbuff[dirtyidx] = NULL;
409
410 /*
411 * Update pointer to next buffer descriptor to be transmitted.
412 */
413 if ((sc & BD_ENET_TX_WRAP) == 0)
414 bdp++;
415 else
416 bdp = fep->tx_bd_base;
417
418 /*
419 * Since we have freed up a buffer, the ring is no longer
420 * full.
421 */
422 if (!fep->tx_free++)
423 do_wake = 1;
424 }
425
426 fep->dirty_tx = bdp;
427
428 if (do_restart)
429 (*fep->ops->tx_restart)(dev);
430
431 spin_unlock(&fep->lock);
432
433 if (do_wake)
434 netif_wake_queue(dev);
435}
436
437/*
438 * The interrupt handler.
439 * This is called from the MPC core interrupt.
440 */
441static irqreturn_t
442fs_enet_interrupt(int irq, void *dev_id, struct pt_regs *regs)
443{
444 struct net_device *dev = dev_id;
445 struct fs_enet_private *fep;
446 const struct fs_platform_info *fpi;
447 u32 int_events;
448 u32 int_clr_events;
449 int nr, napi_ok;
450 int handled;
451
452 fep = netdev_priv(dev);
453 fpi = fep->fpi;
454
455 nr = 0;
456 while ((int_events = (*fep->ops->get_int_events)(dev)) != 0) {
457
458 nr++;
459
460 int_clr_events = int_events;
461 if (fpi->use_napi)
462 int_clr_events &= ~fep->ev_napi_rx;
463
464 (*fep->ops->clear_int_events)(dev, int_clr_events);
465
466 if (int_events & fep->ev_err)
467 (*fep->ops->ev_error)(dev, int_events);
468
469 if (int_events & fep->ev_rx) {
470 if (!fpi->use_napi)
471 fs_enet_rx_non_napi(dev);
472 else {
473 napi_ok = netif_rx_schedule_prep(dev);
474
475 (*fep->ops->napi_disable_rx)(dev);
476 (*fep->ops->clear_int_events)(dev, fep->ev_napi_rx);
477
478 /* NOTE: it is possible for FCCs in NAPI mode */
479 /* to submit a spurious interrupt while in poll */
480 if (napi_ok)
481 __netif_rx_schedule(dev);
482 }
483 }
484
485 if (int_events & fep->ev_tx)
486 fs_enet_tx(dev);
487 }
488
489 handled = nr > 0;
490 return IRQ_RETVAL(handled);
491}
492
493void fs_init_bds(struct net_device *dev)
494{
495 struct fs_enet_private *fep = netdev_priv(dev);
496 cbd_t *bdp;
497 struct sk_buff *skb;
498 int i;
499
500 fs_cleanup_bds(dev);
501
502 fep->dirty_tx = fep->cur_tx = fep->tx_bd_base;
503 fep->tx_free = fep->tx_ring;
504 fep->cur_rx = fep->rx_bd_base;
505
506 /*
507 * Initialize the receive buffer descriptors.
508 */
509 for (i = 0, bdp = fep->rx_bd_base; i < fep->rx_ring; i++, bdp++) {
510 skb = dev_alloc_skb(ENET_RX_FRSIZE);
511 if (skb == NULL) {
512 printk(KERN_WARNING DRV_MODULE_NAME
513 ": %s Memory squeeze, unable to allocate skb\n",
514 dev->name);
515 break;
516 }
517 fep->rx_skbuff[i] = skb;
518 skb->dev = dev;
519 CBDW_BUFADDR(bdp,
520 dma_map_single(fep->dev, skb->data,
521 L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
522 DMA_FROM_DEVICE));
523 CBDW_DATLEN(bdp, 0); /* zero */
524 CBDW_SC(bdp, BD_ENET_RX_EMPTY |
525 ((i < fep->rx_ring - 1) ? 0 : BD_SC_WRAP));
526 }
527 /*
528 * if we failed, fillup remainder
529 */
530 for (; i < fep->rx_ring; i++, bdp++) {
531 fep->rx_skbuff[i] = NULL;
532 CBDW_SC(bdp, (i < fep->rx_ring - 1) ? 0 : BD_SC_WRAP);
533 }
534
535 /*
536 * ...and the same for transmit.
537 */
538 for (i = 0, bdp = fep->tx_bd_base; i < fep->tx_ring; i++, bdp++) {
539 fep->tx_skbuff[i] = NULL;
540 CBDW_BUFADDR(bdp, 0);
541 CBDW_DATLEN(bdp, 0);
542 CBDW_SC(bdp, (i < fep->tx_ring - 1) ? 0 : BD_SC_WRAP);
543 }
544}
545
546void fs_cleanup_bds(struct net_device *dev)
547{
548 struct fs_enet_private *fep = netdev_priv(dev);
549 struct sk_buff *skb;
550 int i;
551
552 /*
553 * Reset SKB transmit buffers.
554 */
555 for (i = 0; i < fep->tx_ring; i++) {
556 if ((skb = fep->tx_skbuff[i]) == NULL)
557 continue;
558
559 /* unmap */
560 dma_unmap_single(fep->dev, skb->data, skb->len, DMA_TO_DEVICE);
561
562 fep->tx_skbuff[i] = NULL;
563 dev_kfree_skb(skb);
564 }
565
566 /*
567 * Reset SKB receive buffers
568 */
569 for (i = 0; i < fep->rx_ring; i++) {
570 if ((skb = fep->rx_skbuff[i]) == NULL)
571 continue;
572
573 /* unmap */
574 dma_unmap_single(fep->dev, skb->data,
575 L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
576 DMA_FROM_DEVICE);
577
578 fep->rx_skbuff[i] = NULL;
579
580 dev_kfree_skb(skb);
581 }
582}
583
584/**********************************************************************************/
585
586static int fs_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
587{
588 struct fs_enet_private *fep = netdev_priv(dev);
589 cbd_t *bdp;
590 int curidx;
591 u16 sc;
592 unsigned long flags;
593
594 spin_lock_irqsave(&fep->tx_lock, flags);
595
596 /*
597 * Fill in a Tx ring entry
598 */
599 bdp = fep->cur_tx;
600
601 if (!fep->tx_free || (CBDR_SC(bdp) & BD_ENET_TX_READY)) {
602 netif_stop_queue(dev);
603 spin_unlock_irqrestore(&fep->tx_lock, flags);
604
605 /*
606 * Ooops. All transmit buffers are full. Bail out.
607 * This should not happen, since the tx queue should be stopped.
608 */
609 printk(KERN_WARNING DRV_MODULE_NAME
610 ": %s tx queue full!.\n", dev->name);
611 return NETDEV_TX_BUSY;
612 }
613
614 curidx = bdp - fep->tx_bd_base;
615 /*
616 * Clear all of the status flags.
617 */
618 CBDC_SC(bdp, BD_ENET_TX_STATS);
619
620 /*
621 * Save skb pointer.
622 */
623 fep->tx_skbuff[curidx] = skb;
624
625 fep->stats.tx_bytes += skb->len;
626
627 /*
628 * Push the data cache so the CPM does not get stale memory data.
629 */
630 CBDW_BUFADDR(bdp, dma_map_single(fep->dev,
631 skb->data, skb->len, DMA_TO_DEVICE));
632 CBDW_DATLEN(bdp, skb->len);
633
634 dev->trans_start = jiffies;
635
636 /*
637 * If this was the last BD in the ring, start at the beginning again.
638 */
639 if ((CBDR_SC(bdp) & BD_ENET_TX_WRAP) == 0)
640 fep->cur_tx++;
641 else
642 fep->cur_tx = fep->tx_bd_base;
643
644 if (!--fep->tx_free)
645 netif_stop_queue(dev);
646
647 /* Trigger transmission start */
648 sc = BD_ENET_TX_READY | BD_ENET_TX_INTR |
649 BD_ENET_TX_LAST | BD_ENET_TX_TC;
650
651 /* note that while FEC does not have this bit
652 * it marks it as available for software use
653 * yay for hw reuse :) */
654 if (skb->len <= 60)
655 sc |= BD_ENET_TX_PAD;
656 CBDS_SC(bdp, sc);
657
658 (*fep->ops->tx_kickstart)(dev);
659
660 spin_unlock_irqrestore(&fep->tx_lock, flags);
661
662 return NETDEV_TX_OK;
663}
664
665static int fs_request_irq(struct net_device *dev, int irq, const char *name,
666 irqreturn_t (*irqf)(int irq, void *dev_id, struct pt_regs *regs))
667{
668 struct fs_enet_private *fep = netdev_priv(dev);
669
670 (*fep->ops->pre_request_irq)(dev, irq);
671 return request_irq(irq, irqf, SA_SHIRQ, name, dev);
672}
673
674static void fs_free_irq(struct net_device *dev, int irq)
675{
676 struct fs_enet_private *fep = netdev_priv(dev);
677
678 free_irq(irq, dev);
679 (*fep->ops->post_free_irq)(dev, irq);
680}
681
682/**********************************************************************************/
683
684/* This interrupt occurs when the PHY detects a link change. */
685static irqreturn_t
686fs_mii_link_interrupt(int irq, void *dev_id, struct pt_regs *regs)
687{
688 struct net_device *dev = dev_id;
689 struct fs_enet_private *fep;
690 const struct fs_platform_info *fpi;
691
692 fep = netdev_priv(dev);
693 fpi = fep->fpi;
694
695 /*
696 * Acknowledge the interrupt if possible. If we have not
697 * found the PHY yet we can't process or acknowledge the
698 * interrupt now. Instead we ignore this interrupt for now,
699 * which we can do since it is edge triggered. It will be
700 * acknowledged later by fs_enet_open().
701 */
702 if (!fep->phy)
703 return IRQ_NONE;
704
705 fs_mii_ack_int(dev);
706 fs_mii_link_status_change_check(dev, 0);
707
708 return IRQ_HANDLED;
709}
710
711static void fs_timeout(struct net_device *dev)
712{
713 struct fs_enet_private *fep = netdev_priv(dev);
714 unsigned long flags;
715 int wake = 0;
716
717 fep->stats.tx_errors++;
718
719 spin_lock_irqsave(&fep->lock, flags);
720
721 if (dev->flags & IFF_UP) {
722 (*fep->ops->stop)(dev);
723 (*fep->ops->restart)(dev);
724 }
725
726 wake = fep->tx_free && !(CBDR_SC(fep->cur_tx) & BD_ENET_TX_READY);
727 spin_unlock_irqrestore(&fep->lock, flags);
728
729 if (wake)
730 netif_wake_queue(dev);
731}
732
733static int fs_enet_open(struct net_device *dev)
734{
735 struct fs_enet_private *fep = netdev_priv(dev);
736 const struct fs_platform_info *fpi = fep->fpi;
737 int r;
738
739 /* Install our interrupt handler. */
740 r = fs_request_irq(dev, fep->interrupt, "fs_enet-mac", fs_enet_interrupt);
741 if (r != 0) {
742 printk(KERN_ERR DRV_MODULE_NAME
743 ": %s Could not allocate FEC IRQ!", dev->name);
744 return -EINVAL;
745 }
746
747 /* Install our phy interrupt handler */
748 if (fpi->phy_irq != -1) {
749
750 r = fs_request_irq(dev, fpi->phy_irq, "fs_enet-phy", fs_mii_link_interrupt);
751 if (r != 0) {
752 printk(KERN_ERR DRV_MODULE_NAME
753 ": %s Could not allocate PHY IRQ!", dev->name);
754 fs_free_irq(dev, fep->interrupt);
755 return -EINVAL;
756 }
757 }
758
759 fs_mii_startup(dev);
760 netif_carrier_off(dev);
761 fs_mii_link_status_change_check(dev, 1);
762
763 return 0;
764}
765
766static int fs_enet_close(struct net_device *dev)
767{
768 struct fs_enet_private *fep = netdev_priv(dev);
769 const struct fs_platform_info *fpi = fep->fpi;
770 unsigned long flags;
771
772 netif_stop_queue(dev);
773 netif_carrier_off(dev);
774 fs_mii_shutdown(dev);
775
776 spin_lock_irqsave(&fep->lock, flags);
777 (*fep->ops->stop)(dev);
778 spin_unlock_irqrestore(&fep->lock, flags);
779
780 /* release any irqs */
781 if (fpi->phy_irq != -1)
782 fs_free_irq(dev, fpi->phy_irq);
783 fs_free_irq(dev, fep->interrupt);
784
785 return 0;
786}
787
788static struct net_device_stats *fs_enet_get_stats(struct net_device *dev)
789{
790 struct fs_enet_private *fep = netdev_priv(dev);
791 return &fep->stats;
792}
793
794/*************************************************************************/
795
796static void fs_get_drvinfo(struct net_device *dev,
797 struct ethtool_drvinfo *info)
798{
799 strcpy(info->driver, DRV_MODULE_NAME);
800 strcpy(info->version, DRV_MODULE_VERSION);
801}
802
803static int fs_get_regs_len(struct net_device *dev)
804{
805 struct fs_enet_private *fep = netdev_priv(dev);
806
807 return (*fep->ops->get_regs_len)(dev);
808}
809
810static void fs_get_regs(struct net_device *dev, struct ethtool_regs *regs,
811 void *p)
812{
813 struct fs_enet_private *fep = netdev_priv(dev);
814 unsigned long flags;
815 int r, len;
816
817 len = regs->len;
818
819 spin_lock_irqsave(&fep->lock, flags);
820 r = (*fep->ops->get_regs)(dev, p, &len);
821 spin_unlock_irqrestore(&fep->lock, flags);
822
823 if (r == 0)
824 regs->version = 0;
825}
826
827static int fs_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
828{
829 struct fs_enet_private *fep = netdev_priv(dev);
830 unsigned long flags;
831 int rc;
832
833 spin_lock_irqsave(&fep->lock, flags);
834 rc = mii_ethtool_gset(&fep->mii_if, cmd);
835 spin_unlock_irqrestore(&fep->lock, flags);
836
837 return rc;
838}
839
840static int fs_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
841{
842 struct fs_enet_private *fep = netdev_priv(dev);
843 unsigned long flags;
844 int rc;
845
846 spin_lock_irqsave(&fep->lock, flags);
847 rc = mii_ethtool_sset(&fep->mii_if, cmd);
848 spin_unlock_irqrestore(&fep->lock, flags);
849
850 return rc;
851}
852
853static int fs_nway_reset(struct net_device *dev)
854{
855 struct fs_enet_private *fep = netdev_priv(dev);
856 return mii_nway_restart(&fep->mii_if);
857}
858
859static u32 fs_get_msglevel(struct net_device *dev)
860{
861 struct fs_enet_private *fep = netdev_priv(dev);
862 return fep->msg_enable;
863}
864
865static void fs_set_msglevel(struct net_device *dev, u32 value)
866{
867 struct fs_enet_private *fep = netdev_priv(dev);
868 fep->msg_enable = value;
869}
870
871static struct ethtool_ops fs_ethtool_ops = {
872 .get_drvinfo = fs_get_drvinfo,
873 .get_regs_len = fs_get_regs_len,
874 .get_settings = fs_get_settings,
875 .set_settings = fs_set_settings,
876 .nway_reset = fs_nway_reset,
877 .get_link = ethtool_op_get_link,
878 .get_msglevel = fs_get_msglevel,
879 .set_msglevel = fs_set_msglevel,
880 .get_tx_csum = ethtool_op_get_tx_csum,
881 .set_tx_csum = ethtool_op_set_tx_csum, /* local! */
882 .get_sg = ethtool_op_get_sg,
883 .set_sg = ethtool_op_set_sg,
884 .get_regs = fs_get_regs,
885};
886
887static int fs_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
888{
889 struct fs_enet_private *fep = netdev_priv(dev);
890 struct mii_ioctl_data *mii = (struct mii_ioctl_data *)&rq->ifr_data;
891 unsigned long flags;
892 int rc;
893
894 if (!netif_running(dev))
895 return -EINVAL;
896
897 spin_lock_irqsave(&fep->lock, flags);
898 rc = generic_mii_ioctl(&fep->mii_if, mii, cmd, NULL);
899 spin_unlock_irqrestore(&fep->lock, flags);
900 return rc;
901}
902
903extern int fs_mii_connect(struct net_device *dev);
904extern void fs_mii_disconnect(struct net_device *dev);
905
906static struct net_device *fs_init_instance(struct device *dev,
907 const struct fs_platform_info *fpi)
908{
909 struct net_device *ndev = NULL;
910 struct fs_enet_private *fep = NULL;
911 int privsize, i, r, err = 0, registered = 0;
912
913 /* guard */
914 if ((unsigned int)fpi->fs_no >= FS_MAX_INDEX)
915 return ERR_PTR(-EINVAL);
916
917 privsize = sizeof(*fep) + (sizeof(struct sk_buff **) *
918 (fpi->rx_ring + fpi->tx_ring));
919
920 ndev = alloc_etherdev(privsize);
921 if (!ndev) {
922 err = -ENOMEM;
923 goto err;
924 }
925 SET_MODULE_OWNER(ndev);
926
927 fep = netdev_priv(ndev);
928 memset(fep, 0, privsize); /* clear everything */
929
930 fep->dev = dev;
931 dev_set_drvdata(dev, ndev);
932 fep->fpi = fpi;
933 if (fpi->init_ioports)
934 fpi->init_ioports();
935
936#ifdef CONFIG_FS_ENET_HAS_FEC
937 if (fs_get_fec_index(fpi->fs_no) >= 0)
938 fep->ops = &fs_fec_ops;
939#endif
940
941#ifdef CONFIG_FS_ENET_HAS_SCC
942 if (fs_get_scc_index(fpi->fs_no) >=0 )
943 fep->ops = &fs_scc_ops;
944#endif
945
946#ifdef CONFIG_FS_ENET_HAS_FCC
947 if (fs_get_fcc_index(fpi->fs_no) >= 0)
948 fep->ops = &fs_fcc_ops;
949#endif
950
951 if (fep->ops == NULL) {
952 printk(KERN_ERR DRV_MODULE_NAME
953 ": %s No matching ops found (%d).\n",
954 ndev->name, fpi->fs_no);
955 err = -EINVAL;
956 goto err;
957 }
958
959 r = (*fep->ops->setup_data)(ndev);
960 if (r != 0) {
961 printk(KERN_ERR DRV_MODULE_NAME
962 ": %s setup_data failed\n",
963 ndev->name);
964 err = r;
965 goto err;
966 }
967
968 /* point rx_skbuff, tx_skbuff */
969 fep->rx_skbuff = (struct sk_buff **)&fep[1];
970 fep->tx_skbuff = fep->rx_skbuff + fpi->rx_ring;
971
972 /* init locks */
973 spin_lock_init(&fep->lock);
974 spin_lock_init(&fep->tx_lock);
975
976 /*
977 * Set the Ethernet address.
978 */
979 for (i = 0; i < 6; i++)
980 ndev->dev_addr[i] = fpi->macaddr[i];
981
982 r = (*fep->ops->allocate_bd)(ndev);
983
984 if (fep->ring_base == NULL) {
985 printk(KERN_ERR DRV_MODULE_NAME
986 ": %s buffer descriptor alloc failed (%d).\n", ndev->name, r);
987 err = r;
988 goto err;
989 }
990
991 /*
992 * Set receive and transmit descriptor base.
993 */
994 fep->rx_bd_base = fep->ring_base;
995 fep->tx_bd_base = fep->rx_bd_base + fpi->rx_ring;
996
997 /* initialize ring size variables */
998 fep->tx_ring = fpi->tx_ring;
999 fep->rx_ring = fpi->rx_ring;
1000
1001 /*
1002 * The FEC Ethernet specific entries in the device structure.
1003 */
1004 ndev->open = fs_enet_open;
1005 ndev->hard_start_xmit = fs_enet_start_xmit;
1006 ndev->tx_timeout = fs_timeout;
1007 ndev->watchdog_timeo = 2 * HZ;
1008 ndev->stop = fs_enet_close;
1009 ndev->get_stats = fs_enet_get_stats;
1010 ndev->set_multicast_list = fs_set_multicast_list;
1011 if (fpi->use_napi) {
1012 ndev->poll = fs_enet_rx_napi;
1013 ndev->weight = fpi->napi_weight;
1014 }
1015 ndev->ethtool_ops = &fs_ethtool_ops;
1016 ndev->do_ioctl = fs_ioctl;
1017
1018 init_timer(&fep->phy_timer_list);
1019
1020 netif_carrier_off(ndev);
1021
1022 err = register_netdev(ndev);
1023 if (err != 0) {
1024 printk(KERN_ERR DRV_MODULE_NAME
1025 ": %s register_netdev failed.\n", ndev->name);
1026 goto err;
1027 }
1028 registered = 1;
1029
1030 err = fs_mii_connect(ndev);
1031 if (err != 0) {
1032 printk(KERN_ERR DRV_MODULE_NAME
1033 ": %s fs_mii_connect failed.\n", ndev->name);
1034 goto err;
1035 }
1036
1037 return ndev;
1038
1039 err:
1040 if (ndev != NULL) {
1041
1042 if (registered)
1043 unregister_netdev(ndev);
1044
1045 if (fep != NULL) {
1046 (*fep->ops->free_bd)(ndev);
1047 (*fep->ops->cleanup_data)(ndev);
1048 }
1049
1050 free_netdev(ndev);
1051 }
1052
1053 dev_set_drvdata(dev, NULL);
1054
1055 return ERR_PTR(err);
1056}
1057
1058static int fs_cleanup_instance(struct net_device *ndev)
1059{
1060 struct fs_enet_private *fep;
1061 const struct fs_platform_info *fpi;
1062 struct device *dev;
1063
1064 if (ndev == NULL)
1065 return -EINVAL;
1066
1067 fep = netdev_priv(ndev);
1068 if (fep == NULL)
1069 return -EINVAL;
1070
1071 fpi = fep->fpi;
1072
1073 fs_mii_disconnect(ndev);
1074
1075 unregister_netdev(ndev);
1076
1077 dma_free_coherent(fep->dev, (fpi->tx_ring + fpi->rx_ring) * sizeof(cbd_t),
1078 fep->ring_base, fep->ring_mem_addr);
1079
1080 /* reset it */
1081 (*fep->ops->cleanup_data)(ndev);
1082
1083 dev = fep->dev;
1084 if (dev != NULL) {
1085 dev_set_drvdata(dev, NULL);
1086 fep->dev = NULL;
1087 }
1088
1089 free_netdev(ndev);
1090
1091 return 0;
1092}
1093
1094/**************************************************************************************/
1095
1096/* handy pointer to the immap */
1097void *fs_enet_immap = NULL;
1098
1099static int setup_immap(void)
1100{
1101 phys_addr_t paddr = 0;
1102 unsigned long size = 0;
1103
1104#ifdef CONFIG_CPM1
1105 paddr = IMAP_ADDR;
1106 size = 0x10000; /* map 64K */
1107#endif
1108
1109#ifdef CONFIG_CPM2
1110 paddr = CPM_MAP_ADDR;
1111 size = 0x40000; /* map 256 K */
1112#endif
1113 fs_enet_immap = ioremap(paddr, size);
1114 if (fs_enet_immap == NULL)
1115 return -EBADF; /* XXX ahem; maybe just BUG_ON? */
1116
1117 return 0;
1118}
1119
1120static void cleanup_immap(void)
1121{
1122 if (fs_enet_immap != NULL) {
1123 iounmap(fs_enet_immap);
1124 fs_enet_immap = NULL;
1125 }
1126}
1127
1128/**************************************************************************************/
1129
1130static int __devinit fs_enet_probe(struct device *dev)
1131{
1132 struct net_device *ndev;
1133
1134 /* no fixup - no device */
1135 if (dev->platform_data == NULL) {
1136 printk(KERN_INFO "fs_enet: "
1137 "probe called with no platform data; "
1138 "remove unused devices\n");
1139 return -ENODEV;
1140 }
1141
1142 ndev = fs_init_instance(dev, dev->platform_data);
1143 if (IS_ERR(ndev))
1144 return PTR_ERR(ndev);
1145 return 0;
1146}
1147
1148static int fs_enet_remove(struct device *dev)
1149{
1150 return fs_cleanup_instance(dev_get_drvdata(dev));
1151}
1152
1153static struct device_driver fs_enet_fec_driver = {
1154 .name = "fsl-cpm-fec",
1155 .bus = &platform_bus_type,
1156 .probe = fs_enet_probe,
1157 .remove = fs_enet_remove,
1158#ifdef CONFIG_PM
1159/* .suspend = fs_enet_suspend, TODO */
1160/* .resume = fs_enet_resume, TODO */
1161#endif
1162};
1163
1164static struct device_driver fs_enet_scc_driver = {
1165 .name = "fsl-cpm-scc",
1166 .bus = &platform_bus_type,
1167 .probe = fs_enet_probe,
1168 .remove = fs_enet_remove,
1169#ifdef CONFIG_PM
1170/* .suspend = fs_enet_suspend, TODO */
1171/* .resume = fs_enet_resume, TODO */
1172#endif
1173};
1174
1175static struct device_driver fs_enet_fcc_driver = {
1176 .name = "fsl-cpm-fcc",
1177 .bus = &platform_bus_type,
1178 .probe = fs_enet_probe,
1179 .remove = fs_enet_remove,
1180#ifdef CONFIG_PM
1181/* .suspend = fs_enet_suspend, TODO */
1182/* .resume = fs_enet_resume, TODO */
1183#endif
1184};
1185
1186static int __init fs_init(void)
1187{
1188 int r;
1189
1190 printk(KERN_INFO
1191 "%s", version);
1192
1193 r = setup_immap();
1194 if (r != 0)
1195 return r;
1196 r = driver_register(&fs_enet_fec_driver);
1197 if (r != 0)
1198 goto err;
1199
1200 r = driver_register(&fs_enet_fcc_driver);
1201 if (r != 0)
1202 goto err;
1203
1204 r = driver_register(&fs_enet_scc_driver);
1205 if (r != 0)
1206 goto err;
1207
1208 return 0;
1209err:
1210 cleanup_immap();
1211 return r;
1212
1213}
1214
1215static void __exit fs_cleanup(void)
1216{
1217 driver_unregister(&fs_enet_fec_driver);
1218 driver_unregister(&fs_enet_fcc_driver);
1219 driver_unregister(&fs_enet_scc_driver);
1220 cleanup_immap();
1221}
1222
1223/**************************************************************************************/
1224
1225module_init(fs_init);
1226module_exit(fs_cleanup);
diff --git a/drivers/net/fs_enet/fs_enet-mii.c b/drivers/net/fs_enet/fs_enet-mii.c
new file mode 100644
index 000000000000..c6770377ef87
--- /dev/null
+++ b/drivers/net/fs_enet/fs_enet-mii.c
@@ -0,0 +1,507 @@
1/*
2 * Combined Ethernet driver for Motorola MPC8xx and MPC82xx.
3 *
4 * Copyright (c) 2003 Intracom S.A.
5 * by Pantelis Antoniou <panto@intracom.gr>
6 *
7 * 2005 (c) MontaVista Software, Inc.
8 * Vitaly Bordug <vbordug@ru.mvista.com>
9 *
10 * Heavily based on original FEC driver by Dan Malek <dan@embeddededge.com>
11 * and modifications by Joakim Tjernlund <joakim.tjernlund@lumentis.se>
12 *
13 * This file is licensed under the terms of the GNU General Public License
14 * version 2. This program is licensed "as is" without any warranty of any
15 * kind, whether express or implied.
16 */
17
18
19#include <linux/config.h>
20#include <linux/module.h>
21#include <linux/types.h>
22#include <linux/kernel.h>
23#include <linux/sched.h>
24#include <linux/string.h>
25#include <linux/ptrace.h>
26#include <linux/errno.h>
27#include <linux/ioport.h>
28#include <linux/slab.h>
29#include <linux/interrupt.h>
30#include <linux/pci.h>
31#include <linux/init.h>
32#include <linux/delay.h>
33#include <linux/netdevice.h>
34#include <linux/etherdevice.h>
35#include <linux/skbuff.h>
36#include <linux/spinlock.h>
37#include <linux/mii.h>
38#include <linux/ethtool.h>
39#include <linux/bitops.h>
40
41#include <asm/pgtable.h>
42#include <asm/irq.h>
43#include <asm/uaccess.h>
44
45#include "fs_enet.h"
46
47/*************************************************/
48
49/*
50 * Generic PHY support.
51 * Should work for all PHYs, but link change is detected by polling
52 */
53
54static void generic_timer_callback(unsigned long data)
55{
56 struct net_device *dev = (struct net_device *)data;
57 struct fs_enet_private *fep = netdev_priv(dev);
58
59 fep->phy_timer_list.expires = jiffies + HZ / 2;
60
61 add_timer(&fep->phy_timer_list);
62
63 fs_mii_link_status_change_check(dev, 0);
64}
65
66static void generic_startup(struct net_device *dev)
67{
68 struct fs_enet_private *fep = netdev_priv(dev);
69
70 fep->phy_timer_list.expires = jiffies + HZ / 2; /* every 500ms */
71 fep->phy_timer_list.data = (unsigned long)dev;
72 fep->phy_timer_list.function = generic_timer_callback;
73 add_timer(&fep->phy_timer_list);
74}
75
76static void generic_shutdown(struct net_device *dev)
77{
78 struct fs_enet_private *fep = netdev_priv(dev);
79
80 del_timer_sync(&fep->phy_timer_list);
81}
82
83/* ------------------------------------------------------------------------- */
84/* The Davicom DM9161 is used on the NETTA board */
85
86/* register definitions */
87
88#define MII_DM9161_ANAR 4 /* Aux. Config Register */
89#define MII_DM9161_ACR 16 /* Aux. Config Register */
90#define MII_DM9161_ACSR 17 /* Aux. Config/Status Register */
91#define MII_DM9161_10TCSR 18 /* 10BaseT Config/Status Reg. */
92#define MII_DM9161_INTR 21 /* Interrupt Register */
93#define MII_DM9161_RECR 22 /* Receive Error Counter Reg. */
94#define MII_DM9161_DISCR 23 /* Disconnect Counter Register */
95
96static void dm9161_startup(struct net_device *dev)
97{
98 struct fs_enet_private *fep = netdev_priv(dev);
99
100 fs_mii_write(dev, fep->mii_if.phy_id, MII_DM9161_INTR, 0x0000);
101 /* Start autonegotiation */
102 fs_mii_write(dev, fep->mii_if.phy_id, MII_BMCR, 0x1200);
103
104 set_current_state(TASK_UNINTERRUPTIBLE);
105 schedule_timeout(HZ*8);
106}
107
108static void dm9161_ack_int(struct net_device *dev)
109{
110 struct fs_enet_private *fep = netdev_priv(dev);
111
112 fs_mii_read(dev, fep->mii_if.phy_id, MII_DM9161_INTR);
113}
114
115static void dm9161_shutdown(struct net_device *dev)
116{
117 struct fs_enet_private *fep = netdev_priv(dev);
118
119 fs_mii_write(dev, fep->mii_if.phy_id, MII_DM9161_INTR, 0x0f00);
120}
121
122/**********************************************************************************/
123
124static const struct phy_info phy_info[] = {
125 {
126 .id = 0x00181b88,
127 .name = "DM9161",
128 .startup = dm9161_startup,
129 .ack_int = dm9161_ack_int,
130 .shutdown = dm9161_shutdown,
131 }, {
132 .id = 0,
133 .name = "GENERIC",
134 .startup = generic_startup,
135 .shutdown = generic_shutdown,
136 },
137};
138
139/**********************************************************************************/
140
141static int phy_id_detect(struct net_device *dev)
142{
143 struct fs_enet_private *fep = netdev_priv(dev);
144 const struct fs_platform_info *fpi = fep->fpi;
145 struct fs_enet_mii_bus *bus = fep->mii_bus;
146 int i, r, start, end, phytype, physubtype;
147 const struct phy_info *phy;
148 int phy_hwid, phy_id;
149
150 phy_hwid = -1;
151 fep->phy = NULL;
152
153 /* auto-detect? */
154 if (fpi->phy_addr == -1) {
155 start = 1;
156 end = 32;
157 } else { /* direct */
158 start = fpi->phy_addr;
159 end = start + 1;
160 }
161
162 for (phy_id = start; phy_id < end; phy_id++) {
163 /* skip already used phy addresses on this bus */
164 if (bus->usage_map & (1 << phy_id))
165 continue;
166 r = fs_mii_read(dev, phy_id, MII_PHYSID1);
167 if (r == -1 || (phytype = (r & 0xffff)) == 0xffff)
168 continue;
169 r = fs_mii_read(dev, phy_id, MII_PHYSID2);
170 if (r == -1 || (physubtype = (r & 0xffff)) == 0xffff)
171 continue;
172 phy_hwid = (phytype << 16) | physubtype;
173 if (phy_hwid != -1)
174 break;
175 }
176
177 if (phy_hwid == -1) {
178 printk(KERN_ERR DRV_MODULE_NAME
179 ": %s No PHY detected! range=0x%02x-0x%02x\n",
180 dev->name, start, end);
181 return -1;
182 }
183
184 for (i = 0, phy = phy_info; i < ARRAY_SIZE(phy_info); i++, phy++)
185 if (phy->id == (phy_hwid >> 4) || phy->id == 0)
186 break;
187
188 if (i >= ARRAY_SIZE(phy_info)) {
189 printk(KERN_ERR DRV_MODULE_NAME
190 ": %s PHY id 0x%08x is not supported!\n",
191 dev->name, phy_hwid);
192 return -1;
193 }
194
195 fep->phy = phy;
196
197 /* mark this address as used */
198 bus->usage_map |= (1 << phy_id);
199
200 printk(KERN_INFO DRV_MODULE_NAME
201 ": %s Phy @ 0x%x, type %s (0x%08x)%s\n",
202 dev->name, phy_id, fep->phy->name, phy_hwid,
203 fpi->phy_addr == -1 ? " (auto-detected)" : "");
204
205 return phy_id;
206}
207
208void fs_mii_startup(struct net_device *dev)
209{
210 struct fs_enet_private *fep = netdev_priv(dev);
211
212 if (fep->phy->startup)
213 (*fep->phy->startup) (dev);
214}
215
216void fs_mii_shutdown(struct net_device *dev)
217{
218 struct fs_enet_private *fep = netdev_priv(dev);
219
220 if (fep->phy->shutdown)
221 (*fep->phy->shutdown) (dev);
222}
223
224void fs_mii_ack_int(struct net_device *dev)
225{
226 struct fs_enet_private *fep = netdev_priv(dev);
227
228 if (fep->phy->ack_int)
229 (*fep->phy->ack_int) (dev);
230}
231
232#define MII_LINK 0x0001
233#define MII_HALF 0x0002
234#define MII_FULL 0x0004
235#define MII_BASE4 0x0008
236#define MII_10M 0x0010
237#define MII_100M 0x0020
238#define MII_1G 0x0040
239#define MII_10G 0x0080
240
241/* return full mii info at one gulp, with a usable form */
242static unsigned int mii_full_status(struct mii_if_info *mii)
243{
244 unsigned int status;
245 int bmsr, adv, lpa, neg;
246 struct fs_enet_private* fep = netdev_priv(mii->dev);
247
248 /* first, a dummy read, needed to latch some MII phys */
249 (void)mii->mdio_read(mii->dev, mii->phy_id, MII_BMSR);
250 bmsr = mii->mdio_read(mii->dev, mii->phy_id, MII_BMSR);
251
252 /* no link */
253 if ((bmsr & BMSR_LSTATUS) == 0)
254 return 0;
255
256 status = MII_LINK;
257
258 /* Lets look what ANEG says if it's supported - otherwize we shall
259 take the right values from the platform info*/
260 if(!mii->force_media) {
261 /* autoneg not completed; don't bother */
262 if ((bmsr & BMSR_ANEGCOMPLETE) == 0)
263 return 0;
264
265 adv = (*mii->mdio_read)(mii->dev, mii->phy_id, MII_ADVERTISE);
266 lpa = (*mii->mdio_read)(mii->dev, mii->phy_id, MII_LPA);
267
268 neg = lpa & adv;
269 } else {
270 neg = fep->fpi->bus_info->lpa;
271 }
272
273 if (neg & LPA_100FULL)
274 status |= MII_FULL | MII_100M;
275 else if (neg & LPA_100BASE4)
276 status |= MII_FULL | MII_BASE4 | MII_100M;
277 else if (neg & LPA_100HALF)
278 status |= MII_HALF | MII_100M;
279 else if (neg & LPA_10FULL)
280 status |= MII_FULL | MII_10M;
281 else
282 status |= MII_HALF | MII_10M;
283
284 return status;
285}
286
287void fs_mii_link_status_change_check(struct net_device *dev, int init_media)
288{
289 struct fs_enet_private *fep = netdev_priv(dev);
290 struct mii_if_info *mii = &fep->mii_if;
291 unsigned int mii_status;
292 int ok_to_print, link, duplex, speed;
293 unsigned long flags;
294
295 ok_to_print = netif_msg_link(fep);
296
297 mii_status = mii_full_status(mii);
298
299 if (!init_media && mii_status == fep->last_mii_status)
300 return;
301
302 fep->last_mii_status = mii_status;
303
304 link = !!(mii_status & MII_LINK);
305 duplex = !!(mii_status & MII_FULL);
306 speed = (mii_status & MII_100M) ? 100 : 10;
307
308 if (link == 0) {
309 netif_carrier_off(mii->dev);
310 netif_stop_queue(dev);
311 if (!init_media) {
312 spin_lock_irqsave(&fep->lock, flags);
313 (*fep->ops->stop)(dev);
314 spin_unlock_irqrestore(&fep->lock, flags);
315 }
316
317 if (ok_to_print)
318 printk(KERN_INFO "%s: link down\n", mii->dev->name);
319
320 } else {
321
322 mii->full_duplex = duplex;
323
324 netif_carrier_on(mii->dev);
325
326 spin_lock_irqsave(&fep->lock, flags);
327 fep->duplex = duplex;
328 fep->speed = speed;
329 (*fep->ops->restart)(dev);
330 spin_unlock_irqrestore(&fep->lock, flags);
331
332 netif_start_queue(dev);
333
334 if (ok_to_print)
335 printk(KERN_INFO "%s: link up, %dMbps, %s-duplex\n",
336 dev->name, speed, duplex ? "full" : "half");
337 }
338}
339
340/**********************************************************************************/
341
342int fs_mii_read(struct net_device *dev, int phy_id, int location)
343{
344 struct fs_enet_private *fep = netdev_priv(dev);
345 struct fs_enet_mii_bus *bus = fep->mii_bus;
346
347 unsigned long flags;
348 int ret;
349
350 spin_lock_irqsave(&bus->mii_lock, flags);
351 ret = (*bus->mii_read)(bus, phy_id, location);
352 spin_unlock_irqrestore(&bus->mii_lock, flags);
353
354 return ret;
355}
356
357void fs_mii_write(struct net_device *dev, int phy_id, int location, int value)
358{
359 struct fs_enet_private *fep = netdev_priv(dev);
360 struct fs_enet_mii_bus *bus = fep->mii_bus;
361 unsigned long flags;
362
363 spin_lock_irqsave(&bus->mii_lock, flags);
364 (*bus->mii_write)(bus, phy_id, location, value);
365 spin_unlock_irqrestore(&bus->mii_lock, flags);
366}
367
368/*****************************************************************************/
369
370/* list of all registered mii buses */
371static LIST_HEAD(fs_mii_bus_list);
372
373static struct fs_enet_mii_bus *lookup_bus(int method, int id)
374{
375 struct list_head *ptr;
376 struct fs_enet_mii_bus *bus;
377
378 list_for_each(ptr, &fs_mii_bus_list) {
379 bus = list_entry(ptr, struct fs_enet_mii_bus, list);
380 if (bus->bus_info->method == method &&
381 bus->bus_info->id == id)
382 return bus;
383 }
384 return NULL;
385}
386
387static struct fs_enet_mii_bus *create_bus(const struct fs_mii_bus_info *bi)
388{
389 struct fs_enet_mii_bus *bus;
390 int ret = 0;
391
392 bus = kmalloc(sizeof(*bus), GFP_KERNEL);
393 if (bus == NULL) {
394 ret = -ENOMEM;
395 goto err;
396 }
397 memset(bus, 0, sizeof(*bus));
398 spin_lock_init(&bus->mii_lock);
399 bus->bus_info = bi;
400 bus->refs = 0;
401 bus->usage_map = 0;
402
403 /* perform initialization */
404 switch (bi->method) {
405
406 case fsmii_fixed:
407 ret = fs_mii_fixed_init(bus);
408 if (ret != 0)
409 goto err;
410 break;
411
412 case fsmii_bitbang:
413 ret = fs_mii_bitbang_init(bus);
414 if (ret != 0)
415 goto err;
416 break;
417#ifdef CONFIG_FS_ENET_HAS_FEC
418 case fsmii_fec:
419 ret = fs_mii_fec_init(bus);
420 if (ret != 0)
421 goto err;
422 break;
423#endif
424 default:
425 ret = -EINVAL;
426 goto err;
427 }
428
429 list_add(&bus->list, &fs_mii_bus_list);
430
431 return bus;
432
433err:
434 if (bus)
435 kfree(bus);
436 return ERR_PTR(ret);
437}
438
439static void destroy_bus(struct fs_enet_mii_bus *bus)
440{
441 /* remove from bus list */
442 list_del(&bus->list);
443
444 /* nothing more needed */
445 kfree(bus);
446}
447
448int fs_mii_connect(struct net_device *dev)
449{
450 struct fs_enet_private *fep = netdev_priv(dev);
451 const struct fs_platform_info *fpi = fep->fpi;
452 struct fs_enet_mii_bus *bus = NULL;
453
454 /* check method validity */
455 switch (fpi->bus_info->method) {
456 case fsmii_fixed:
457 case fsmii_bitbang:
458 break;
459#ifdef CONFIG_FS_ENET_HAS_FEC
460 case fsmii_fec:
461 break;
462#endif
463 default:
464 printk(KERN_ERR DRV_MODULE_NAME
465 ": %s Unknown MII bus method (%d)!\n",
466 dev->name, fpi->bus_info->method);
467 return -EINVAL;
468 }
469
470 bus = lookup_bus(fpi->bus_info->method, fpi->bus_info->id);
471
472 /* if not found create new bus */
473 if (bus == NULL) {
474 bus = create_bus(fpi->bus_info);
475 if (IS_ERR(bus)) {
476 printk(KERN_ERR DRV_MODULE_NAME
477 ": %s MII bus creation failure!\n", dev->name);
478 return PTR_ERR(bus);
479 }
480 }
481
482 bus->refs++;
483
484 fep->mii_bus = bus;
485
486 fep->mii_if.dev = dev;
487 fep->mii_if.phy_id_mask = 0x1f;
488 fep->mii_if.reg_num_mask = 0x1f;
489 fep->mii_if.mdio_read = fs_mii_read;
490 fep->mii_if.mdio_write = fs_mii_write;
491 fep->mii_if.force_media = fpi->bus_info->disable_aneg;
492 fep->mii_if.phy_id = phy_id_detect(dev);
493
494 return 0;
495}
496
497void fs_mii_disconnect(struct net_device *dev)
498{
499 struct fs_enet_private *fep = netdev_priv(dev);
500 struct fs_enet_mii_bus *bus = NULL;
501
502 bus = fep->mii_bus;
503 fep->mii_bus = NULL;
504
505 if (--bus->refs <= 0)
506 destroy_bus(bus);
507}
diff --git a/drivers/net/fs_enet/fs_enet.h b/drivers/net/fs_enet/fs_enet.h
new file mode 100644
index 000000000000..1105543b9d88
--- /dev/null
+++ b/drivers/net/fs_enet/fs_enet.h
@@ -0,0 +1,245 @@
1#ifndef FS_ENET_H
2#define FS_ENET_H
3
4#include <linux/mii.h>
5#include <linux/netdevice.h>
6#include <linux/types.h>
7#include <linux/version.h>
8#include <linux/list.h>
9
10#include <linux/fs_enet_pd.h>
11
12#include <asm/dma-mapping.h>
13
14#ifdef CONFIG_CPM1
15#include <asm/commproc.h>
16#endif
17
18#ifdef CONFIG_CPM2
19#include <asm/cpm2.h>
20#endif
21
22/* hw driver ops */
23struct fs_ops {
24 int (*setup_data)(struct net_device *dev);
25 int (*allocate_bd)(struct net_device *dev);
26 void (*free_bd)(struct net_device *dev);
27 void (*cleanup_data)(struct net_device *dev);
28 void (*set_multicast_list)(struct net_device *dev);
29 void (*restart)(struct net_device *dev);
30 void (*stop)(struct net_device *dev);
31 void (*pre_request_irq)(struct net_device *dev, int irq);
32 void (*post_free_irq)(struct net_device *dev, int irq);
33 void (*napi_clear_rx_event)(struct net_device *dev);
34 void (*napi_enable_rx)(struct net_device *dev);
35 void (*napi_disable_rx)(struct net_device *dev);
36 void (*rx_bd_done)(struct net_device *dev);
37 void (*tx_kickstart)(struct net_device *dev);
38 u32 (*get_int_events)(struct net_device *dev);
39 void (*clear_int_events)(struct net_device *dev, u32 int_events);
40 void (*ev_error)(struct net_device *dev, u32 int_events);
41 int (*get_regs)(struct net_device *dev, void *p, int *sizep);
42 int (*get_regs_len)(struct net_device *dev);
43 void (*tx_restart)(struct net_device *dev);
44};
45
46struct phy_info {
47 unsigned int id;
48 const char *name;
49 void (*startup) (struct net_device * dev);
50 void (*shutdown) (struct net_device * dev);
51 void (*ack_int) (struct net_device * dev);
52};
53
54/* The FEC stores dest/src/type, data, and checksum for receive packets.
55 */
56#define MAX_MTU 1508 /* Allow fullsized pppoe packets over VLAN */
57#define MIN_MTU 46 /* this is data size */
58#define CRC_LEN 4
59
60#define PKT_MAXBUF_SIZE (MAX_MTU+ETH_HLEN+CRC_LEN)
61#define PKT_MINBUF_SIZE (MIN_MTU+ETH_HLEN+CRC_LEN)
62
63/* Must be a multiple of 32 (to cover both FEC & FCC) */
64#define PKT_MAXBLR_SIZE ((PKT_MAXBUF_SIZE + 31) & ~31)
65/* This is needed so that invalidate_xxx wont invalidate too much */
66#define ENET_RX_FRSIZE L1_CACHE_ALIGN(PKT_MAXBUF_SIZE)
67
68struct fs_enet_mii_bus {
69 struct list_head list;
70 spinlock_t mii_lock;
71 const struct fs_mii_bus_info *bus_info;
72 int refs;
73 u32 usage_map;
74
75 int (*mii_read)(struct fs_enet_mii_bus *bus,
76 int phy_id, int location);
77
78 void (*mii_write)(struct fs_enet_mii_bus *bus,
79 int phy_id, int location, int value);
80
81 union {
82 struct {
83 unsigned int mii_speed;
84 void *fecp;
85 } fec;
86
87 struct {
88 /* note that the actual port size may */
89 /* be different; cpm(s) handle it OK */
90 u8 mdio_msk;
91 u8 *mdio_dir;
92 u8 *mdio_dat;
93 u8 mdc_msk;
94 u8 *mdc_dir;
95 u8 *mdc_dat;
96 } bitbang;
97
98 struct {
99 u16 lpa;
100 } fixed;
101 };
102};
103
104int fs_mii_bitbang_init(struct fs_enet_mii_bus *bus);
105int fs_mii_fixed_init(struct fs_enet_mii_bus *bus);
106int fs_mii_fec_init(struct fs_enet_mii_bus *bus);
107
108struct fs_enet_private {
109 struct device *dev; /* pointer back to the device (must be initialized first) */
110 spinlock_t lock; /* during all ops except TX pckt processing */
111 spinlock_t tx_lock; /* during fs_start_xmit and fs_tx */
112 const struct fs_platform_info *fpi;
113 const struct fs_ops *ops;
114 int rx_ring, tx_ring;
115 dma_addr_t ring_mem_addr;
116 void *ring_base;
117 struct sk_buff **rx_skbuff;
118 struct sk_buff **tx_skbuff;
119 cbd_t *rx_bd_base; /* Address of Rx and Tx buffers. */
120 cbd_t *tx_bd_base;
121 cbd_t *dirty_tx; /* ring entries to be free()ed. */
122 cbd_t *cur_rx;
123 cbd_t *cur_tx;
124 int tx_free;
125 struct net_device_stats stats;
126 struct timer_list phy_timer_list;
127 const struct phy_info *phy;
128 u32 msg_enable;
129 struct mii_if_info mii_if;
130 unsigned int last_mii_status;
131 struct fs_enet_mii_bus *mii_bus;
132 int interrupt;
133
134 int duplex, speed; /* current settings */
135
136 /* event masks */
137 u32 ev_napi_rx; /* mask of NAPI rx events */
138 u32 ev_rx; /* rx event mask */
139 u32 ev_tx; /* tx event mask */
140 u32 ev_err; /* error event mask */
141
142 u16 bd_rx_empty; /* mask of BD rx empty */
143 u16 bd_rx_err; /* mask of BD rx errors */
144
145 union {
146 struct {
147 int idx; /* FEC1 = 0, FEC2 = 1 */
148 void *fecp; /* hw registers */
149 u32 hthi, htlo; /* state for multicast */
150 } fec;
151
152 struct {
153 int idx; /* FCC1-3 = 0-2 */
154 void *fccp; /* hw registers */
155 void *ep; /* parameter ram */
156 void *fcccp; /* hw registers cont. */
157 void *mem; /* FCC DPRAM */
158 u32 gaddrh, gaddrl; /* group address */
159 } fcc;
160
161 struct {
162 int idx; /* FEC1 = 0, FEC2 = 1 */
163 void *sccp; /* hw registers */
164 void *ep; /* parameter ram */
165 u32 hthi, htlo; /* state for multicast */
166 } scc;
167
168 };
169};
170
171/***************************************************************************/
172
173int fs_mii_read(struct net_device *dev, int phy_id, int location);
174void fs_mii_write(struct net_device *dev, int phy_id, int location, int value);
175
176void fs_mii_startup(struct net_device *dev);
177void fs_mii_shutdown(struct net_device *dev);
178void fs_mii_ack_int(struct net_device *dev);
179
180void fs_mii_link_status_change_check(struct net_device *dev, int init_media);
181
182void fs_init_bds(struct net_device *dev);
183void fs_cleanup_bds(struct net_device *dev);
184
185/***************************************************************************/
186
187#define DRV_MODULE_NAME "fs_enet"
188#define PFX DRV_MODULE_NAME ": "
189#define DRV_MODULE_VERSION "1.0"
190#define DRV_MODULE_RELDATE "Aug 8, 2005"
191
192/***************************************************************************/
193
194int fs_enet_platform_init(void);
195void fs_enet_platform_cleanup(void);
196
197/***************************************************************************/
198
199/* buffer descriptor access macros */
200
201/* access macros */
202#if defined(CONFIG_CPM1)
203/* for a a CPM1 __raw_xxx's are sufficient */
204#define __cbd_out32(addr, x) __raw_writel(x, addr)
205#define __cbd_out16(addr, x) __raw_writew(x, addr)
206#define __cbd_in32(addr) __raw_readl(addr)
207#define __cbd_in16(addr) __raw_readw(addr)
208#else
209/* for others play it safe */
210#define __cbd_out32(addr, x) out_be32(addr, x)
211#define __cbd_out16(addr, x) out_be16(addr, x)
212#define __cbd_in32(addr) in_be32(addr)
213#define __cbd_in16(addr) in_be16(addr)
214#endif
215
216/* write */
217#define CBDW_SC(_cbd, _sc) __cbd_out16(&(_cbd)->cbd_sc, (_sc))
218#define CBDW_DATLEN(_cbd, _datlen) __cbd_out16(&(_cbd)->cbd_datlen, (_datlen))
219#define CBDW_BUFADDR(_cbd, _bufaddr) __cbd_out32(&(_cbd)->cbd_bufaddr, (_bufaddr))
220
221/* read */
222#define CBDR_SC(_cbd) __cbd_in16(&(_cbd)->cbd_sc)
223#define CBDR_DATLEN(_cbd) __cbd_in16(&(_cbd)->cbd_datlen)
224#define CBDR_BUFADDR(_cbd) __cbd_in32(&(_cbd)->cbd_bufaddr)
225
226/* set bits */
227#define CBDS_SC(_cbd, _sc) CBDW_SC(_cbd, CBDR_SC(_cbd) | (_sc))
228
229/* clear bits */
230#define CBDC_SC(_cbd, _sc) CBDW_SC(_cbd, CBDR_SC(_cbd) & ~(_sc))
231
232/*******************************************************************/
233
234extern const struct fs_ops fs_fec_ops;
235extern const struct fs_ops fs_fcc_ops;
236extern const struct fs_ops fs_scc_ops;
237
238/*******************************************************************/
239
240/* handy pointer to the immap */
241extern void *fs_enet_immap;
242
243/*******************************************************************/
244
245#endif
diff --git a/drivers/net/fs_enet/mac-fcc.c b/drivers/net/fs_enet/mac-fcc.c
new file mode 100644
index 000000000000..a940b96433c7
--- /dev/null
+++ b/drivers/net/fs_enet/mac-fcc.c
@@ -0,0 +1,578 @@
1/*
2 * FCC driver for Motorola MPC82xx (PQ2).
3 *
4 * Copyright (c) 2003 Intracom S.A.
5 * by Pantelis Antoniou <panto@intracom.gr>
6 *
7 * 2005 (c) MontaVista Software, Inc.
8 * Vitaly Bordug <vbordug@ru.mvista.com>
9 *
10 * This file is licensed under the terms of the GNU General Public License
11 * version 2. This program is licensed "as is" without any warranty of any
12 * kind, whether express or implied.
13 */
14
15#include <linux/config.h>
16#include <linux/module.h>
17#include <linux/kernel.h>
18#include <linux/types.h>
19#include <linux/sched.h>
20#include <linux/string.h>
21#include <linux/ptrace.h>
22#include <linux/errno.h>
23#include <linux/ioport.h>
24#include <linux/slab.h>
25#include <linux/interrupt.h>
26#include <linux/pci.h>
27#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/netdevice.h>
30#include <linux/etherdevice.h>
31#include <linux/skbuff.h>
32#include <linux/spinlock.h>
33#include <linux/mii.h>
34#include <linux/ethtool.h>
35#include <linux/bitops.h>
36#include <linux/fs.h>
37
38#include <asm/immap_cpm2.h>
39#include <asm/mpc8260.h>
40#include <asm/cpm2.h>
41
42#include <asm/pgtable.h>
43#include <asm/irq.h>
44#include <asm/uaccess.h>
45
46#include "fs_enet.h"
47
48/*************************************************/
49
50/* FCC access macros */
51
52#define __fcc_out32(addr, x) out_be32((unsigned *)addr, x)
53#define __fcc_out16(addr, x) out_be16((unsigned short *)addr, x)
54#define __fcc_out8(addr, x) out_8((unsigned char *)addr, x)
55#define __fcc_in32(addr) in_be32((unsigned *)addr)
56#define __fcc_in16(addr) in_be16((unsigned short *)addr)
57#define __fcc_in8(addr) in_8((unsigned char *)addr)
58
59/* parameter space */
60
61/* write, read, set bits, clear bits */
62#define W32(_p, _m, _v) __fcc_out32(&(_p)->_m, (_v))
63#define R32(_p, _m) __fcc_in32(&(_p)->_m)
64#define S32(_p, _m, _v) W32(_p, _m, R32(_p, _m) | (_v))
65#define C32(_p, _m, _v) W32(_p, _m, R32(_p, _m) & ~(_v))
66
67#define W16(_p, _m, _v) __fcc_out16(&(_p)->_m, (_v))
68#define R16(_p, _m) __fcc_in16(&(_p)->_m)
69#define S16(_p, _m, _v) W16(_p, _m, R16(_p, _m) | (_v))
70#define C16(_p, _m, _v) W16(_p, _m, R16(_p, _m) & ~(_v))
71
72#define W8(_p, _m, _v) __fcc_out8(&(_p)->_m, (_v))
73#define R8(_p, _m) __fcc_in8(&(_p)->_m)
74#define S8(_p, _m, _v) W8(_p, _m, R8(_p, _m) | (_v))
75#define C8(_p, _m, _v) W8(_p, _m, R8(_p, _m) & ~(_v))
76
77/*************************************************/
78
79#define FCC_MAX_MULTICAST_ADDRS 64
80
81#define mk_mii_read(REG) (0x60020000 | ((REG & 0x1f) << 18))
82#define mk_mii_write(REG, VAL) (0x50020000 | ((REG & 0x1f) << 18) | (VAL & 0xffff))
83#define mk_mii_end 0
84
85#define MAX_CR_CMD_LOOPS 10000
86
87static inline int fcc_cr_cmd(struct fs_enet_private *fep, u32 mcn, u32 op)
88{
89 const struct fs_platform_info *fpi = fep->fpi;
90
91 cpm2_map_t *immap = fs_enet_immap;
92 cpm_cpm2_t *cpmp = &immap->im_cpm;
93 u32 v;
94 int i;
95
96 /* Currently I don't know what feature call will look like. But
97 I guess there'd be something like do_cpm_cmd() which will require page & sblock */
98 v = mk_cr_cmd(fpi->cp_page, fpi->cp_block, mcn, op);
99 W32(cpmp, cp_cpcr, v | CPM_CR_FLG);
100 for (i = 0; i < MAX_CR_CMD_LOOPS; i++)
101 if ((R32(cpmp, cp_cpcr) & CPM_CR_FLG) == 0)
102 break;
103
104 if (i >= MAX_CR_CMD_LOOPS) {
105 printk(KERN_ERR "%s(): Not able to issue CPM command\n",
106 __FUNCTION__);
107 return 1;
108 }
109
110 return 0;
111}
112
113static int do_pd_setup(struct fs_enet_private *fep)
114{
115 struct platform_device *pdev = to_platform_device(fep->dev);
116 struct resource *r;
117
118 /* Fill out IRQ field */
119 fep->interrupt = platform_get_irq(pdev, 0);
120
121 /* Attach the memory for the FCC Parameter RAM */
122 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fcc_pram");
123 fep->fcc.ep = (void *)r->start;
124
125 if (fep->fcc.ep == NULL)
126 return -EINVAL;
127
128 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fcc_regs");
129 fep->fcc.fccp = (void *)r->start;
130
131 if (fep->fcc.fccp == NULL)
132 return -EINVAL;
133
134 fep->fcc.fcccp = (void *)fep->fpi->fcc_regs_c;
135
136 if (fep->fcc.fcccp == NULL)
137 return -EINVAL;
138
139 return 0;
140}
141
142#define FCC_NAPI_RX_EVENT_MSK (FCC_ENET_RXF | FCC_ENET_RXB)
143#define FCC_RX_EVENT (FCC_ENET_RXF)
144#define FCC_TX_EVENT (FCC_ENET_TXB)
145#define FCC_ERR_EVENT_MSK (FCC_ENET_TXE | FCC_ENET_BSY)
146
147static int setup_data(struct net_device *dev)
148{
149 struct fs_enet_private *fep = netdev_priv(dev);
150 const struct fs_platform_info *fpi = fep->fpi;
151
152 fep->fcc.idx = fs_get_fcc_index(fpi->fs_no);
153 if ((unsigned int)fep->fcc.idx >= 3) /* max 3 FCCs */
154 return -EINVAL;
155
156 fep->fcc.mem = (void *)fpi->mem_offset;
157
158 if (do_pd_setup(fep) != 0)
159 return -EINVAL;
160
161 fep->ev_napi_rx = FCC_NAPI_RX_EVENT_MSK;
162 fep->ev_rx = FCC_RX_EVENT;
163 fep->ev_tx = FCC_TX_EVENT;
164 fep->ev_err = FCC_ERR_EVENT_MSK;
165
166 return 0;
167}
168
169static int allocate_bd(struct net_device *dev)
170{
171 struct fs_enet_private *fep = netdev_priv(dev);
172 const struct fs_platform_info *fpi = fep->fpi;
173
174 fep->ring_base = dma_alloc_coherent(fep->dev,
175 (fpi->tx_ring + fpi->rx_ring) *
176 sizeof(cbd_t), &fep->ring_mem_addr,
177 GFP_KERNEL);
178 if (fep->ring_base == NULL)
179 return -ENOMEM;
180
181 return 0;
182}
183
184static void free_bd(struct net_device *dev)
185{
186 struct fs_enet_private *fep = netdev_priv(dev);
187 const struct fs_platform_info *fpi = fep->fpi;
188
189 if (fep->ring_base)
190 dma_free_coherent(fep->dev,
191 (fpi->tx_ring + fpi->rx_ring) * sizeof(cbd_t),
192 fep->ring_base, fep->ring_mem_addr);
193}
194
195static void cleanup_data(struct net_device *dev)
196{
197 /* nothing */
198}
199
200static void set_promiscuous_mode(struct net_device *dev)
201{
202 struct fs_enet_private *fep = netdev_priv(dev);
203 fcc_t *fccp = fep->fcc.fccp;
204
205 S32(fccp, fcc_fpsmr, FCC_PSMR_PRO);
206}
207
208static void set_multicast_start(struct net_device *dev)
209{
210 struct fs_enet_private *fep = netdev_priv(dev);
211 fcc_enet_t *ep = fep->fcc.ep;
212
213 W32(ep, fen_gaddrh, 0);
214 W32(ep, fen_gaddrl, 0);
215}
216
217static void set_multicast_one(struct net_device *dev, const u8 *mac)
218{
219 struct fs_enet_private *fep = netdev_priv(dev);
220 fcc_enet_t *ep = fep->fcc.ep;
221 u16 taddrh, taddrm, taddrl;
222
223 taddrh = ((u16)mac[5] << 8) | mac[4];
224 taddrm = ((u16)mac[3] << 8) | mac[2];
225 taddrl = ((u16)mac[1] << 8) | mac[0];
226
227 W16(ep, fen_taddrh, taddrh);
228 W16(ep, fen_taddrm, taddrm);
229 W16(ep, fen_taddrl, taddrl);
230 fcc_cr_cmd(fep, 0x0C, CPM_CR_SET_GADDR);
231}
232
233static void set_multicast_finish(struct net_device *dev)
234{
235 struct fs_enet_private *fep = netdev_priv(dev);
236 fcc_t *fccp = fep->fcc.fccp;
237 fcc_enet_t *ep = fep->fcc.ep;
238
239 /* clear promiscuous always */
240 C32(fccp, fcc_fpsmr, FCC_PSMR_PRO);
241
242 /* if all multi or too many multicasts; just enable all */
243 if ((dev->flags & IFF_ALLMULTI) != 0 ||
244 dev->mc_count > FCC_MAX_MULTICAST_ADDRS) {
245
246 W32(ep, fen_gaddrh, 0xffffffff);
247 W32(ep, fen_gaddrl, 0xffffffff);
248 }
249
250 /* read back */
251 fep->fcc.gaddrh = R32(ep, fen_gaddrh);
252 fep->fcc.gaddrl = R32(ep, fen_gaddrl);
253}
254
255static void set_multicast_list(struct net_device *dev)
256{
257 struct dev_mc_list *pmc;
258
259 if ((dev->flags & IFF_PROMISC) == 0) {
260 set_multicast_start(dev);
261 for (pmc = dev->mc_list; pmc != NULL; pmc = pmc->next)
262 set_multicast_one(dev, pmc->dmi_addr);
263 set_multicast_finish(dev);
264 } else
265 set_promiscuous_mode(dev);
266}
267
268static void restart(struct net_device *dev)
269{
270 struct fs_enet_private *fep = netdev_priv(dev);
271 const struct fs_platform_info *fpi = fep->fpi;
272 fcc_t *fccp = fep->fcc.fccp;
273 fcc_c_t *fcccp = fep->fcc.fcccp;
274 fcc_enet_t *ep = fep->fcc.ep;
275 dma_addr_t rx_bd_base_phys, tx_bd_base_phys;
276 u16 paddrh, paddrm, paddrl;
277 u16 mem_addr;
278 const unsigned char *mac;
279 int i;
280
281 C32(fccp, fcc_gfmr, FCC_GFMR_ENR | FCC_GFMR_ENT);
282
283 /* clear everything (slow & steady does it) */
284 for (i = 0; i < sizeof(*ep); i++)
285 __fcc_out8((char *)ep + i, 0);
286
287 /* get physical address */
288 rx_bd_base_phys = fep->ring_mem_addr;
289 tx_bd_base_phys = rx_bd_base_phys + sizeof(cbd_t) * fpi->rx_ring;
290
291 /* point to bds */
292 W32(ep, fen_genfcc.fcc_rbase, rx_bd_base_phys);
293 W32(ep, fen_genfcc.fcc_tbase, tx_bd_base_phys);
294
295 /* Set maximum bytes per receive buffer.
296 * It must be a multiple of 32.
297 */
298 W16(ep, fen_genfcc.fcc_mrblr, PKT_MAXBLR_SIZE);
299
300 W32(ep, fen_genfcc.fcc_rstate, (CPMFCR_GBL | CPMFCR_EB) << 24);
301 W32(ep, fen_genfcc.fcc_tstate, (CPMFCR_GBL | CPMFCR_EB) << 24);
302
303 /* Allocate space in the reserved FCC area of DPRAM for the
304 * internal buffers. No one uses this space (yet), so we
305 * can do this. Later, we will add resource management for
306 * this area.
307 */
308
309 mem_addr = (u32) fep->fcc.mem; /* de-fixup dpram offset */
310
311 W16(ep, fen_genfcc.fcc_riptr, (mem_addr & 0xffff));
312 W16(ep, fen_genfcc.fcc_tiptr, ((mem_addr + 32) & 0xffff));
313 W16(ep, fen_padptr, mem_addr + 64);
314
315 /* fill with special symbol... */
316 memset(fep->fcc.mem + fpi->dpram_offset + 64, 0x88, 32);
317
318 W32(ep, fen_genfcc.fcc_rbptr, 0);
319 W32(ep, fen_genfcc.fcc_tbptr, 0);
320 W32(ep, fen_genfcc.fcc_rcrc, 0);
321 W32(ep, fen_genfcc.fcc_tcrc, 0);
322 W16(ep, fen_genfcc.fcc_res1, 0);
323 W32(ep, fen_genfcc.fcc_res2, 0);
324
325 /* no CAM */
326 W32(ep, fen_camptr, 0);
327
328 /* Set CRC preset and mask */
329 W32(ep, fen_cmask, 0xdebb20e3);
330 W32(ep, fen_cpres, 0xffffffff);
331
332 W32(ep, fen_crcec, 0); /* CRC Error counter */
333 W32(ep, fen_alec, 0); /* alignment error counter */
334 W32(ep, fen_disfc, 0); /* discard frame counter */
335 W16(ep, fen_retlim, 15); /* Retry limit threshold */
336 W16(ep, fen_pper, 0); /* Normal persistence */
337
338 /* set group address */
339 W32(ep, fen_gaddrh, fep->fcc.gaddrh);
340 W32(ep, fen_gaddrl, fep->fcc.gaddrh);
341
342 /* Clear hash filter tables */
343 W32(ep, fen_iaddrh, 0);
344 W32(ep, fen_iaddrl, 0);
345
346 /* Clear the Out-of-sequence TxBD */
347 W16(ep, fen_tfcstat, 0);
348 W16(ep, fen_tfclen, 0);
349 W32(ep, fen_tfcptr, 0);
350
351 W16(ep, fen_mflr, PKT_MAXBUF_SIZE); /* maximum frame length register */
352 W16(ep, fen_minflr, PKT_MINBUF_SIZE); /* minimum frame length register */
353
354 /* set address */
355 mac = dev->dev_addr;
356 paddrh = ((u16)mac[5] << 8) | mac[4];
357 paddrm = ((u16)mac[3] << 8) | mac[2];
358 paddrl = ((u16)mac[1] << 8) | mac[0];
359
360 W16(ep, fen_paddrh, paddrh);
361 W16(ep, fen_paddrm, paddrm);
362 W16(ep, fen_paddrl, paddrl);
363
364 W16(ep, fen_taddrh, 0);
365 W16(ep, fen_taddrm, 0);
366 W16(ep, fen_taddrl, 0);
367
368 W16(ep, fen_maxd1, 1520); /* maximum DMA1 length */
369 W16(ep, fen_maxd2, 1520); /* maximum DMA2 length */
370
371 /* Clear stat counters, in case we ever enable RMON */
372 W32(ep, fen_octc, 0);
373 W32(ep, fen_colc, 0);
374 W32(ep, fen_broc, 0);
375 W32(ep, fen_mulc, 0);
376 W32(ep, fen_uspc, 0);
377 W32(ep, fen_frgc, 0);
378 W32(ep, fen_ospc, 0);
379 W32(ep, fen_jbrc, 0);
380 W32(ep, fen_p64c, 0);
381 W32(ep, fen_p65c, 0);
382 W32(ep, fen_p128c, 0);
383 W32(ep, fen_p256c, 0);
384 W32(ep, fen_p512c, 0);
385 W32(ep, fen_p1024c, 0);
386
387 W16(ep, fen_rfthr, 0); /* Suggested by manual */
388 W16(ep, fen_rfcnt, 0);
389 W16(ep, fen_cftype, 0);
390
391 fs_init_bds(dev);
392
393 /* adjust to speed (for RMII mode) */
394 if (fpi->use_rmii) {
395 if (fep->speed == 100)
396 C8(fcccp, fcc_gfemr, 0x20);
397 else
398 S8(fcccp, fcc_gfemr, 0x20);
399 }
400
401 fcc_cr_cmd(fep, 0x0c, CPM_CR_INIT_TRX);
402
403 /* clear events */
404 W16(fccp, fcc_fcce, 0xffff);
405
406 /* Enable interrupts we wish to service */
407 W16(fccp, fcc_fccm, FCC_ENET_TXE | FCC_ENET_RXF | FCC_ENET_TXB);
408
409 /* Set GFMR to enable Ethernet operating mode */
410 W32(fccp, fcc_gfmr, FCC_GFMR_TCI | FCC_GFMR_MODE_ENET);
411
412 /* set sync/delimiters */
413 W16(fccp, fcc_fdsr, 0xd555);
414
415 W32(fccp, fcc_fpsmr, FCC_PSMR_ENCRC);
416
417 if (fpi->use_rmii)
418 S32(fccp, fcc_fpsmr, FCC_PSMR_RMII);
419
420 /* adjust to duplex mode */
421 if (fep->duplex)
422 S32(fccp, fcc_fpsmr, FCC_PSMR_FDE | FCC_PSMR_LPB);
423 else
424 C32(fccp, fcc_fpsmr, FCC_PSMR_FDE | FCC_PSMR_LPB);
425
426 S32(fccp, fcc_gfmr, FCC_GFMR_ENR | FCC_GFMR_ENT);
427}
428
429static void stop(struct net_device *dev)
430{
431 struct fs_enet_private *fep = netdev_priv(dev);
432 fcc_t *fccp = fep->fcc.fccp;
433
434 /* stop ethernet */
435 C32(fccp, fcc_gfmr, FCC_GFMR_ENR | FCC_GFMR_ENT);
436
437 /* clear events */
438 W16(fccp, fcc_fcce, 0xffff);
439
440 /* clear interrupt mask */
441 W16(fccp, fcc_fccm, 0);
442
443 fs_cleanup_bds(dev);
444}
445
446static void pre_request_irq(struct net_device *dev, int irq)
447{
448 /* nothing */
449}
450
451static void post_free_irq(struct net_device *dev, int irq)
452{
453 /* nothing */
454}
455
456static void napi_clear_rx_event(struct net_device *dev)
457{
458 struct fs_enet_private *fep = netdev_priv(dev);
459 fcc_t *fccp = fep->fcc.fccp;
460
461 W16(fccp, fcc_fcce, FCC_NAPI_RX_EVENT_MSK);
462}
463
464static void napi_enable_rx(struct net_device *dev)
465{
466 struct fs_enet_private *fep = netdev_priv(dev);
467 fcc_t *fccp = fep->fcc.fccp;
468
469 S16(fccp, fcc_fccm, FCC_NAPI_RX_EVENT_MSK);
470}
471
472static void napi_disable_rx(struct net_device *dev)
473{
474 struct fs_enet_private *fep = netdev_priv(dev);
475 fcc_t *fccp = fep->fcc.fccp;
476
477 C16(fccp, fcc_fccm, FCC_NAPI_RX_EVENT_MSK);
478}
479
480static void rx_bd_done(struct net_device *dev)
481{
482 /* nothing */
483}
484
485static void tx_kickstart(struct net_device *dev)
486{
487 /* nothing */
488}
489
490static u32 get_int_events(struct net_device *dev)
491{
492 struct fs_enet_private *fep = netdev_priv(dev);
493 fcc_t *fccp = fep->fcc.fccp;
494
495 return (u32)R16(fccp, fcc_fcce);
496}
497
498static void clear_int_events(struct net_device *dev, u32 int_events)
499{
500 struct fs_enet_private *fep = netdev_priv(dev);
501 fcc_t *fccp = fep->fcc.fccp;
502
503 W16(fccp, fcc_fcce, int_events & 0xffff);
504}
505
506static void ev_error(struct net_device *dev, u32 int_events)
507{
508 printk(KERN_WARNING DRV_MODULE_NAME
509 ": %s FS_ENET ERROR(s) 0x%x\n", dev->name, int_events);
510}
511
512int get_regs(struct net_device *dev, void *p, int *sizep)
513{
514 struct fs_enet_private *fep = netdev_priv(dev);
515
516 if (*sizep < sizeof(fcc_t) + sizeof(fcc_c_t) + sizeof(fcc_enet_t))
517 return -EINVAL;
518
519 memcpy_fromio(p, fep->fcc.fccp, sizeof(fcc_t));
520 p = (char *)p + sizeof(fcc_t);
521
522 memcpy_fromio(p, fep->fcc.fcccp, sizeof(fcc_c_t));
523 p = (char *)p + sizeof(fcc_c_t);
524
525 memcpy_fromio(p, fep->fcc.ep, sizeof(fcc_enet_t));
526
527 return 0;
528}
529
530int get_regs_len(struct net_device *dev)
531{
532 return sizeof(fcc_t) + sizeof(fcc_c_t) + sizeof(fcc_enet_t);
533}
534
535/* Some transmit errors cause the transmitter to shut
536 * down. We now issue a restart transmit. Since the
537 * errors close the BD and update the pointers, the restart
538 * _should_ pick up without having to reset any of our
539 * pointers either. Also, To workaround 8260 device erratum
540 * CPM37, we must disable and then re-enable the transmitter
541 * following a Late Collision, Underrun, or Retry Limit error.
542 */
543void tx_restart(struct net_device *dev)
544{
545 struct fs_enet_private *fep = netdev_priv(dev);
546 fcc_t *fccp = fep->fcc.fccp;
547
548 C32(fccp, fcc_gfmr, FCC_GFMR_ENT);
549 udelay(10);
550 S32(fccp, fcc_gfmr, FCC_GFMR_ENT);
551
552 fcc_cr_cmd(fep, 0x0C, CPM_CR_RESTART_TX);
553}
554
555/*************************************************************************/
556
557const struct fs_ops fs_fcc_ops = {
558 .setup_data = setup_data,
559 .cleanup_data = cleanup_data,
560 .set_multicast_list = set_multicast_list,
561 .restart = restart,
562 .stop = stop,
563 .pre_request_irq = pre_request_irq,
564 .post_free_irq = post_free_irq,
565 .napi_clear_rx_event = napi_clear_rx_event,
566 .napi_enable_rx = napi_enable_rx,
567 .napi_disable_rx = napi_disable_rx,
568 .rx_bd_done = rx_bd_done,
569 .tx_kickstart = tx_kickstart,
570 .get_int_events = get_int_events,
571 .clear_int_events = clear_int_events,
572 .ev_error = ev_error,
573 .get_regs = get_regs,
574 .get_regs_len = get_regs_len,
575 .tx_restart = tx_restart,
576 .allocate_bd = allocate_bd,
577 .free_bd = free_bd,
578};
diff --git a/drivers/net/fs_enet/mac-fec.c b/drivers/net/fs_enet/mac-fec.c
new file mode 100644
index 000000000000..5ef4e845a387
--- /dev/null
+++ b/drivers/net/fs_enet/mac-fec.c
@@ -0,0 +1,653 @@
1/*
2 * Freescale Ethernet controllers
3 *
4 * Copyright (c) 2005 Intracom S.A.
5 * by Pantelis Antoniou <panto@intracom.gr>
6 *
7 * 2005 (c) MontaVista Software, Inc.
8 * Vitaly Bordug <vbordug@ru.mvista.com>
9 *
10 * This file is licensed under the terms of the GNU General Public License
11 * version 2. This program is licensed "as is" without any warranty of any
12 * kind, whether express or implied.
13 */
14
15#include <linux/config.h>
16#include <linux/module.h>
17#include <linux/kernel.h>
18#include <linux/types.h>
19#include <linux/sched.h>
20#include <linux/string.h>
21#include <linux/ptrace.h>
22#include <linux/errno.h>
23#include <linux/ioport.h>
24#include <linux/slab.h>
25#include <linux/interrupt.h>
26#include <linux/pci.h>
27#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/netdevice.h>
30#include <linux/etherdevice.h>
31#include <linux/skbuff.h>
32#include <linux/spinlock.h>
33#include <linux/mii.h>
34#include <linux/ethtool.h>
35#include <linux/bitops.h>
36#include <linux/fs.h>
37
38#include <asm/irq.h>
39#include <asm/uaccess.h>
40
41#ifdef CONFIG_8xx
42#include <asm/8xx_immap.h>
43#include <asm/pgtable.h>
44#include <asm/mpc8xx.h>
45#include <asm/commproc.h>
46#endif
47
48#include "fs_enet.h"
49
50/*************************************************/
51
52#if defined(CONFIG_CPM1)
53/* for a CPM1 __raw_xxx's are sufficient */
54#define __fs_out32(addr, x) __raw_writel(x, addr)
55#define __fs_out16(addr, x) __raw_writew(x, addr)
56#define __fs_in32(addr) __raw_readl(addr)
57#define __fs_in16(addr) __raw_readw(addr)
58#else
59/* for others play it safe */
60#define __fs_out32(addr, x) out_be32(addr, x)
61#define __fs_out16(addr, x) out_be16(addr, x)
62#define __fs_in32(addr) in_be32(addr)
63#define __fs_in16(addr) in_be16(addr)
64#endif
65
66/* write */
67#define FW(_fecp, _reg, _v) __fs_out32(&(_fecp)->fec_ ## _reg, (_v))
68
69/* read */
70#define FR(_fecp, _reg) __fs_in32(&(_fecp)->fec_ ## _reg)
71
72/* set bits */
73#define FS(_fecp, _reg, _v) FW(_fecp, _reg, FR(_fecp, _reg) | (_v))
74
75/* clear bits */
76#define FC(_fecp, _reg, _v) FW(_fecp, _reg, FR(_fecp, _reg) & ~(_v))
77
78
79/* CRC polynomium used by the FEC for the multicast group filtering */
80#define FEC_CRC_POLY 0x04C11DB7
81
82#define FEC_MAX_MULTICAST_ADDRS 64
83
84/* Interrupt events/masks.
85*/
86#define FEC_ENET_HBERR 0x80000000U /* Heartbeat error */
87#define FEC_ENET_BABR 0x40000000U /* Babbling receiver */
88#define FEC_ENET_BABT 0x20000000U /* Babbling transmitter */
89#define FEC_ENET_GRA 0x10000000U /* Graceful stop complete */
90#define FEC_ENET_TXF 0x08000000U /* Full frame transmitted */
91#define FEC_ENET_TXB 0x04000000U /* A buffer was transmitted */
92#define FEC_ENET_RXF 0x02000000U /* Full frame received */
93#define FEC_ENET_RXB 0x01000000U /* A buffer was received */
94#define FEC_ENET_MII 0x00800000U /* MII interrupt */
95#define FEC_ENET_EBERR 0x00400000U /* SDMA bus error */
96
97#define FEC_ECNTRL_PINMUX 0x00000004
98#define FEC_ECNTRL_ETHER_EN 0x00000002
99#define FEC_ECNTRL_RESET 0x00000001
100
101#define FEC_RCNTRL_BC_REJ 0x00000010
102#define FEC_RCNTRL_PROM 0x00000008
103#define FEC_RCNTRL_MII_MODE 0x00000004
104#define FEC_RCNTRL_DRT 0x00000002
105#define FEC_RCNTRL_LOOP 0x00000001
106
107#define FEC_TCNTRL_FDEN 0x00000004
108#define FEC_TCNTRL_HBC 0x00000002
109#define FEC_TCNTRL_GTS 0x00000001
110
111
112/* Make MII read/write commands for the FEC.
113*/
114#define mk_mii_read(REG) (0x60020000 | ((REG & 0x1f) << 18))
115#define mk_mii_write(REG, VAL) (0x50020000 | ((REG & 0x1f) << 18) | (VAL & 0xffff))
116#define mk_mii_end 0
117
118#define FEC_MII_LOOPS 10000
119
120/*
121 * Delay to wait for FEC reset command to complete (in us)
122 */
123#define FEC_RESET_DELAY 50
124
125static int whack_reset(fec_t * fecp)
126{
127 int i;
128
129 FW(fecp, ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_RESET);
130 for (i = 0; i < FEC_RESET_DELAY; i++) {
131 if ((FR(fecp, ecntrl) & FEC_ECNTRL_RESET) == 0)
132 return 0; /* OK */
133 udelay(1);
134 }
135
136 return -1;
137}
138
139static int do_pd_setup(struct fs_enet_private *fep)
140{
141 struct platform_device *pdev = to_platform_device(fep->dev);
142 struct resource *r;
143
144 /* Fill out IRQ field */
145 fep->interrupt = platform_get_irq_byname(pdev,"interrupt");
146
147 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
148 fep->fec.fecp =(void*)r->start;
149
150 if(fep->fec.fecp == NULL)
151 return -EINVAL;
152
153 return 0;
154
155}
156
157#define FEC_NAPI_RX_EVENT_MSK (FEC_ENET_RXF | FEC_ENET_RXB)
158#define FEC_RX_EVENT (FEC_ENET_RXF)
159#define FEC_TX_EVENT (FEC_ENET_TXF)
160#define FEC_ERR_EVENT_MSK (FEC_ENET_HBERR | FEC_ENET_BABR | \
161 FEC_ENET_BABT | FEC_ENET_EBERR)
162
163static int setup_data(struct net_device *dev)
164{
165 struct fs_enet_private *fep = netdev_priv(dev);
166
167 if (do_pd_setup(fep) != 0)
168 return -EINVAL;
169
170 fep->fec.hthi = 0;
171 fep->fec.htlo = 0;
172
173 fep->ev_napi_rx = FEC_NAPI_RX_EVENT_MSK;
174 fep->ev_rx = FEC_RX_EVENT;
175 fep->ev_tx = FEC_TX_EVENT;
176 fep->ev_err = FEC_ERR_EVENT_MSK;
177
178 return 0;
179}
180
181static int allocate_bd(struct net_device *dev)
182{
183 struct fs_enet_private *fep = netdev_priv(dev);
184 const struct fs_platform_info *fpi = fep->fpi;
185
186 fep->ring_base = dma_alloc_coherent(fep->dev,
187 (fpi->tx_ring + fpi->rx_ring) *
188 sizeof(cbd_t), &fep->ring_mem_addr,
189 GFP_KERNEL);
190 if (fep->ring_base == NULL)
191 return -ENOMEM;
192
193 return 0;
194}
195
196static void free_bd(struct net_device *dev)
197{
198 struct fs_enet_private *fep = netdev_priv(dev);
199 const struct fs_platform_info *fpi = fep->fpi;
200
201 if(fep->ring_base)
202 dma_free_coherent(fep->dev, (fpi->tx_ring + fpi->rx_ring)
203 * sizeof(cbd_t),
204 fep->ring_base,
205 fep->ring_mem_addr);
206}
207
208static void cleanup_data(struct net_device *dev)
209{
210 /* nothing */
211}
212
213static void set_promiscuous_mode(struct net_device *dev)
214{
215 struct fs_enet_private *fep = netdev_priv(dev);
216 fec_t *fecp = fep->fec.fecp;
217
218 FS(fecp, r_cntrl, FEC_RCNTRL_PROM);
219}
220
221static void set_multicast_start(struct net_device *dev)
222{
223 struct fs_enet_private *fep = netdev_priv(dev);
224
225 fep->fec.hthi = 0;
226 fep->fec.htlo = 0;
227}
228
229static void set_multicast_one(struct net_device *dev, const u8 *mac)
230{
231 struct fs_enet_private *fep = netdev_priv(dev);
232 int temp, hash_index, i, j;
233 u32 crc, csrVal;
234 u8 byte, msb;
235
236 crc = 0xffffffff;
237 for (i = 0; i < 6; i++) {
238 byte = mac[i];
239 for (j = 0; j < 8; j++) {
240 msb = crc >> 31;
241 crc <<= 1;
242 if (msb ^ (byte & 0x1))
243 crc ^= FEC_CRC_POLY;
244 byte >>= 1;
245 }
246 }
247
248 temp = (crc & 0x3f) >> 1;
249 hash_index = ((temp & 0x01) << 4) |
250 ((temp & 0x02) << 2) |
251 ((temp & 0x04)) |
252 ((temp & 0x08) >> 2) |
253 ((temp & 0x10) >> 4);
254 csrVal = 1 << hash_index;
255 if (crc & 1)
256 fep->fec.hthi |= csrVal;
257 else
258 fep->fec.htlo |= csrVal;
259}
260
261static void set_multicast_finish(struct net_device *dev)
262{
263 struct fs_enet_private *fep = netdev_priv(dev);
264 fec_t *fecp = fep->fec.fecp;
265
266 /* if all multi or too many multicasts; just enable all */
267 if ((dev->flags & IFF_ALLMULTI) != 0 ||
268 dev->mc_count > FEC_MAX_MULTICAST_ADDRS) {
269 fep->fec.hthi = 0xffffffffU;
270 fep->fec.htlo = 0xffffffffU;
271 }
272
273 FC(fecp, r_cntrl, FEC_RCNTRL_PROM);
274 FW(fecp, hash_table_high, fep->fec.hthi);
275 FW(fecp, hash_table_low, fep->fec.htlo);
276}
277
278static void set_multicast_list(struct net_device *dev)
279{
280 struct dev_mc_list *pmc;
281
282 if ((dev->flags & IFF_PROMISC) == 0) {
283 set_multicast_start(dev);
284 for (pmc = dev->mc_list; pmc != NULL; pmc = pmc->next)
285 set_multicast_one(dev, pmc->dmi_addr);
286 set_multicast_finish(dev);
287 } else
288 set_promiscuous_mode(dev);
289}
290
291static void restart(struct net_device *dev)
292{
293#ifdef CONFIG_DUET
294 immap_t *immap = fs_enet_immap;
295 u32 cptr;
296#endif
297 struct fs_enet_private *fep = netdev_priv(dev);
298 fec_t *fecp = fep->fec.fecp;
299 const struct fs_platform_info *fpi = fep->fpi;
300 dma_addr_t rx_bd_base_phys, tx_bd_base_phys;
301 int r;
302 u32 addrhi, addrlo;
303
304 r = whack_reset(fep->fec.fecp);
305 if (r != 0)
306 printk(KERN_ERR DRV_MODULE_NAME
307 ": %s FEC Reset FAILED!\n", dev->name);
308
309 /*
310 * Set station address.
311 */
312 addrhi = ((u32) dev->dev_addr[0] << 24) |
313 ((u32) dev->dev_addr[1] << 16) |
314 ((u32) dev->dev_addr[2] << 8) |
315 (u32) dev->dev_addr[3];
316 addrlo = ((u32) dev->dev_addr[4] << 24) |
317 ((u32) dev->dev_addr[5] << 16);
318 FW(fecp, addr_low, addrhi);
319 FW(fecp, addr_high, addrlo);
320
321 /*
322 * Reset all multicast.
323 */
324 FW(fecp, hash_table_high, fep->fec.hthi);
325 FW(fecp, hash_table_low, fep->fec.htlo);
326
327 /*
328 * Set maximum receive buffer size.
329 */
330 FW(fecp, r_buff_size, PKT_MAXBLR_SIZE);
331 FW(fecp, r_hash, PKT_MAXBUF_SIZE);
332
333 /* get physical address */
334 rx_bd_base_phys = fep->ring_mem_addr;
335 tx_bd_base_phys = rx_bd_base_phys + sizeof(cbd_t) * fpi->rx_ring;
336
337 /*
338 * Set receive and transmit descriptor base.
339 */
340 FW(fecp, r_des_start, rx_bd_base_phys);
341 FW(fecp, x_des_start, tx_bd_base_phys);
342
343 fs_init_bds(dev);
344
345 /*
346 * Enable big endian and don't care about SDMA FC.
347 */
348 FW(fecp, fun_code, 0x78000000);
349
350 /*
351 * Set MII speed.
352 */
353 FW(fecp, mii_speed, fep->mii_bus->fec.mii_speed);
354
355 /*
356 * Clear any outstanding interrupt.
357 */
358 FW(fecp, ievent, 0xffc0);
359 FW(fecp, ivec, (fep->interrupt / 2) << 29);
360
361
362 /*
363 * adjust to speed (only for DUET & RMII)
364 */
365#ifdef CONFIG_DUET
366 if (fpi->use_rmii) {
367 cptr = in_be32(&immap->im_cpm.cp_cptr);
368 switch (fs_get_fec_index(fpi->fs_no)) {
369 case 0:
370 cptr |= 0x100;
371 if (fep->speed == 10)
372 cptr |= 0x0000010;
373 else if (fep->speed == 100)
374 cptr &= ~0x0000010;
375 break;
376 case 1:
377 cptr |= 0x80;
378 if (fep->speed == 10)
379 cptr |= 0x0000008;
380 else if (fep->speed == 100)
381 cptr &= ~0x0000008;
382 break;
383 default:
384 BUG(); /* should never happen */
385 break;
386 }
387 out_be32(&immap->im_cpm.cp_cptr, cptr);
388 }
389#endif
390
391 FW(fecp, r_cntrl, FEC_RCNTRL_MII_MODE); /* MII enable */
392 /*
393 * adjust to duplex mode
394 */
395 if (fep->duplex) {
396 FC(fecp, r_cntrl, FEC_RCNTRL_DRT);
397 FS(fecp, x_cntrl, FEC_TCNTRL_FDEN); /* FD enable */
398 } else {
399 FS(fecp, r_cntrl, FEC_RCNTRL_DRT);
400 FC(fecp, x_cntrl, FEC_TCNTRL_FDEN); /* FD disable */
401 }
402
403 /*
404 * Enable interrupts we wish to service.
405 */
406 FW(fecp, imask, FEC_ENET_TXF | FEC_ENET_TXB |
407 FEC_ENET_RXF | FEC_ENET_RXB);
408
409 /*
410 * And last, enable the transmit and receive processing.
411 */
412 FW(fecp, ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN);
413 FW(fecp, r_des_active, 0x01000000);
414}
415
416static void stop(struct net_device *dev)
417{
418 struct fs_enet_private *fep = netdev_priv(dev);
419 fec_t *fecp = fep->fec.fecp;
420 struct fs_enet_mii_bus *bus = fep->mii_bus;
421 const struct fs_mii_bus_info *bi = bus->bus_info;
422 int i;
423
424 if ((FR(fecp, ecntrl) & FEC_ECNTRL_ETHER_EN) == 0)
425 return; /* already down */
426
427 FW(fecp, x_cntrl, 0x01); /* Graceful transmit stop */
428 for (i = 0; ((FR(fecp, ievent) & 0x10000000) == 0) &&
429 i < FEC_RESET_DELAY; i++)
430 udelay(1);
431
432 if (i == FEC_RESET_DELAY)
433 printk(KERN_WARNING DRV_MODULE_NAME
434 ": %s FEC timeout on graceful transmit stop\n",
435 dev->name);
436 /*
437 * Disable FEC. Let only MII interrupts.
438 */
439 FW(fecp, imask, 0);
440 FC(fecp, ecntrl, FEC_ECNTRL_ETHER_EN);
441
442 fs_cleanup_bds(dev);
443
444 /* shut down FEC1? that's where the mii bus is */
445 if (fep->fec.idx == 0 && bus->refs > 1 && bi->method == fsmii_fec) {
446 FS(fecp, r_cntrl, FEC_RCNTRL_MII_MODE); /* MII enable */
447 FS(fecp, ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN);
448 FW(fecp, ievent, FEC_ENET_MII);
449 FW(fecp, mii_speed, bus->fec.mii_speed);
450 }
451}
452
453static void pre_request_irq(struct net_device *dev, int irq)
454{
455 immap_t *immap = fs_enet_immap;
456 u32 siel;
457
458 /* SIU interrupt */
459 if (irq >= SIU_IRQ0 && irq < SIU_LEVEL7) {
460
461 siel = in_be32(&immap->im_siu_conf.sc_siel);
462 if ((irq & 1) == 0)
463 siel |= (0x80000000 >> irq);
464 else
465 siel &= ~(0x80000000 >> (irq & ~1));
466 out_be32(&immap->im_siu_conf.sc_siel, siel);
467 }
468}
469
470static void post_free_irq(struct net_device *dev, int irq)
471{
472 /* nothing */
473}
474
475static void napi_clear_rx_event(struct net_device *dev)
476{
477 struct fs_enet_private *fep = netdev_priv(dev);
478 fec_t *fecp = fep->fec.fecp;
479
480 FW(fecp, ievent, FEC_NAPI_RX_EVENT_MSK);
481}
482
483static void napi_enable_rx(struct net_device *dev)
484{
485 struct fs_enet_private *fep = netdev_priv(dev);
486 fec_t *fecp = fep->fec.fecp;
487
488 FS(fecp, imask, FEC_NAPI_RX_EVENT_MSK);
489}
490
491static void napi_disable_rx(struct net_device *dev)
492{
493 struct fs_enet_private *fep = netdev_priv(dev);
494 fec_t *fecp = fep->fec.fecp;
495
496 FC(fecp, imask, FEC_NAPI_RX_EVENT_MSK);
497}
498
499static void rx_bd_done(struct net_device *dev)
500{
501 struct fs_enet_private *fep = netdev_priv(dev);
502 fec_t *fecp = fep->fec.fecp;
503
504 FW(fecp, r_des_active, 0x01000000);
505}
506
507static void tx_kickstart(struct net_device *dev)
508{
509 struct fs_enet_private *fep = netdev_priv(dev);
510 fec_t *fecp = fep->fec.fecp;
511
512 FW(fecp, x_des_active, 0x01000000);
513}
514
515static u32 get_int_events(struct net_device *dev)
516{
517 struct fs_enet_private *fep = netdev_priv(dev);
518 fec_t *fecp = fep->fec.fecp;
519
520 return FR(fecp, ievent) & FR(fecp, imask);
521}
522
523static void clear_int_events(struct net_device *dev, u32 int_events)
524{
525 struct fs_enet_private *fep = netdev_priv(dev);
526 fec_t *fecp = fep->fec.fecp;
527
528 FW(fecp, ievent, int_events);
529}
530
531static void ev_error(struct net_device *dev, u32 int_events)
532{
533 printk(KERN_WARNING DRV_MODULE_NAME
534 ": %s FEC ERROR(s) 0x%x\n", dev->name, int_events);
535}
536
537int get_regs(struct net_device *dev, void *p, int *sizep)
538{
539 struct fs_enet_private *fep = netdev_priv(dev);
540
541 if (*sizep < sizeof(fec_t))
542 return -EINVAL;
543
544 memcpy_fromio(p, fep->fec.fecp, sizeof(fec_t));
545
546 return 0;
547}
548
549int get_regs_len(struct net_device *dev)
550{
551 return sizeof(fec_t);
552}
553
554void tx_restart(struct net_device *dev)
555{
556 /* nothing */
557}
558
559/*************************************************************************/
560
561const struct fs_ops fs_fec_ops = {
562 .setup_data = setup_data,
563 .cleanup_data = cleanup_data,
564 .set_multicast_list = set_multicast_list,
565 .restart = restart,
566 .stop = stop,
567 .pre_request_irq = pre_request_irq,
568 .post_free_irq = post_free_irq,
569 .napi_clear_rx_event = napi_clear_rx_event,
570 .napi_enable_rx = napi_enable_rx,
571 .napi_disable_rx = napi_disable_rx,
572 .rx_bd_done = rx_bd_done,
573 .tx_kickstart = tx_kickstart,
574 .get_int_events = get_int_events,
575 .clear_int_events = clear_int_events,
576 .ev_error = ev_error,
577 .get_regs = get_regs,
578 .get_regs_len = get_regs_len,
579 .tx_restart = tx_restart,
580 .allocate_bd = allocate_bd,
581 .free_bd = free_bd,
582};
583
584/***********************************************************************/
585
586static int mii_read(struct fs_enet_mii_bus *bus, int phy_id, int location)
587{
588 fec_t *fecp = bus->fec.fecp;
589 int i, ret = -1;
590
591 if ((FR(fecp, r_cntrl) & FEC_RCNTRL_MII_MODE) == 0)
592 BUG();
593
594 /* Add PHY address to register command. */
595 FW(fecp, mii_data, (phy_id << 23) | mk_mii_read(location));
596
597 for (i = 0; i < FEC_MII_LOOPS; i++)
598 if ((FR(fecp, ievent) & FEC_ENET_MII) != 0)
599 break;
600
601 if (i < FEC_MII_LOOPS) {
602 FW(fecp, ievent, FEC_ENET_MII);
603 ret = FR(fecp, mii_data) & 0xffff;
604 }
605
606 return ret;
607}
608
609static void mii_write(struct fs_enet_mii_bus *bus, int phy_id, int location, int value)
610{
611 fec_t *fecp = bus->fec.fecp;
612 int i;
613
614 /* this must never happen */
615 if ((FR(fecp, r_cntrl) & FEC_RCNTRL_MII_MODE) == 0)
616 BUG();
617
618 /* Add PHY address to register command. */
619 FW(fecp, mii_data, (phy_id << 23) | mk_mii_write(location, value));
620
621 for (i = 0; i < FEC_MII_LOOPS; i++)
622 if ((FR(fecp, ievent) & FEC_ENET_MII) != 0)
623 break;
624
625 if (i < FEC_MII_LOOPS)
626 FW(fecp, ievent, FEC_ENET_MII);
627}
628
629int fs_mii_fec_init(struct fs_enet_mii_bus *bus)
630{
631 bd_t *bd = (bd_t *)__res;
632 const struct fs_mii_bus_info *bi = bus->bus_info;
633 fec_t *fecp;
634
635 if (bi->id != 0)
636 return -1;
637
638 bus->fec.fecp = &((immap_t *)fs_enet_immap)->im_cpm.cp_fec;
639 bus->fec.mii_speed = ((((bd->bi_intfreq + 4999999) / 2500000) / 2)
640 & 0x3F) << 1;
641
642 fecp = bus->fec.fecp;
643
644 FS(fecp, r_cntrl, FEC_RCNTRL_MII_MODE); /* MII enable */
645 FS(fecp, ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN);
646 FW(fecp, ievent, FEC_ENET_MII);
647 FW(fecp, mii_speed, bus->fec.mii_speed);
648
649 bus->mii_read = mii_read;
650 bus->mii_write = mii_write;
651
652 return 0;
653}
diff --git a/drivers/net/fs_enet/mac-scc.c b/drivers/net/fs_enet/mac-scc.c
new file mode 100644
index 000000000000..d8c6e9cadcf5
--- /dev/null
+++ b/drivers/net/fs_enet/mac-scc.c
@@ -0,0 +1,524 @@
1/*
2 * Ethernet on Serial Communications Controller (SCC) driver for Motorola MPC8xx and MPC82xx.
3 *
4 * Copyright (c) 2003 Intracom S.A.
5 * by Pantelis Antoniou <panto@intracom.gr>
6 *
7 * 2005 (c) MontaVista Software, Inc.
8 * Vitaly Bordug <vbordug@ru.mvista.com>
9 *
10 * This file is licensed under the terms of the GNU General Public License
11 * version 2. This program is licensed "as is" without any warranty of any
12 * kind, whether express or implied.
13 */
14
15#include <linux/config.h>
16#include <linux/module.h>
17#include <linux/kernel.h>
18#include <linux/types.h>
19#include <linux/sched.h>
20#include <linux/string.h>
21#include <linux/ptrace.h>
22#include <linux/errno.h>
23#include <linux/ioport.h>
24#include <linux/slab.h>
25#include <linux/interrupt.h>
26#include <linux/pci.h>
27#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/netdevice.h>
30#include <linux/etherdevice.h>
31#include <linux/skbuff.h>
32#include <linux/spinlock.h>
33#include <linux/mii.h>
34#include <linux/ethtool.h>
35#include <linux/bitops.h>
36#include <linux/fs.h>
37
38#include <asm/irq.h>
39#include <asm/uaccess.h>
40
41#ifdef CONFIG_8xx
42#include <asm/8xx_immap.h>
43#include <asm/pgtable.h>
44#include <asm/mpc8xx.h>
45#include <asm/commproc.h>
46#endif
47
48#include "fs_enet.h"
49
50/*************************************************/
51
52#if defined(CONFIG_CPM1)
53/* for a 8xx __raw_xxx's are sufficient */
54#define __fs_out32(addr, x) __raw_writel(x, addr)
55#define __fs_out16(addr, x) __raw_writew(x, addr)
56#define __fs_out8(addr, x) __raw_writeb(x, addr)
57#define __fs_in32(addr) __raw_readl(addr)
58#define __fs_in16(addr) __raw_readw(addr)
59#define __fs_in8(addr) __raw_readb(addr)
60#else
61/* for others play it safe */
62#define __fs_out32(addr, x) out_be32(addr, x)
63#define __fs_out16(addr, x) out_be16(addr, x)
64#define __fs_in32(addr) in_be32(addr)
65#define __fs_in16(addr) in_be16(addr)
66#endif
67
68/* write, read, set bits, clear bits */
69#define W32(_p, _m, _v) __fs_out32(&(_p)->_m, (_v))
70#define R32(_p, _m) __fs_in32(&(_p)->_m)
71#define S32(_p, _m, _v) W32(_p, _m, R32(_p, _m) | (_v))
72#define C32(_p, _m, _v) W32(_p, _m, R32(_p, _m) & ~(_v))
73
74#define W16(_p, _m, _v) __fs_out16(&(_p)->_m, (_v))
75#define R16(_p, _m) __fs_in16(&(_p)->_m)
76#define S16(_p, _m, _v) W16(_p, _m, R16(_p, _m) | (_v))
77#define C16(_p, _m, _v) W16(_p, _m, R16(_p, _m) & ~(_v))
78
79#define W8(_p, _m, _v) __fs_out8(&(_p)->_m, (_v))
80#define R8(_p, _m) __fs_in8(&(_p)->_m)
81#define S8(_p, _m, _v) W8(_p, _m, R8(_p, _m) | (_v))
82#define C8(_p, _m, _v) W8(_p, _m, R8(_p, _m) & ~(_v))
83
84#define SCC_MAX_MULTICAST_ADDRS 64
85
86/*
87 * Delay to wait for SCC reset command to complete (in us)
88 */
89#define SCC_RESET_DELAY 50
90#define MAX_CR_CMD_LOOPS 10000
91
92static inline int scc_cr_cmd(struct fs_enet_private *fep, u32 op)
93{
94 cpm8xx_t *cpmp = &((immap_t *)fs_enet_immap)->im_cpm;
95 u32 v, ch;
96 int i = 0;
97
98 ch = fep->scc.idx << 2;
99 v = mk_cr_cmd(ch, op);
100 W16(cpmp, cp_cpcr, v | CPM_CR_FLG);
101 for (i = 0; i < MAX_CR_CMD_LOOPS; i++)
102 if ((R16(cpmp, cp_cpcr) & CPM_CR_FLG) == 0)
103 break;
104
105 if (i >= MAX_CR_CMD_LOOPS) {
106 printk(KERN_ERR "%s(): Not able to issue CPM command\n",
107 __FUNCTION__);
108 return 1;
109 }
110 return 0;
111}
112
113static int do_pd_setup(struct fs_enet_private *fep)
114{
115 struct platform_device *pdev = to_platform_device(fep->dev);
116 struct resource *r;
117
118 /* Fill out IRQ field */
119 fep->interrupt = platform_get_irq_byname(pdev, "interrupt");
120
121 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
122 fep->scc.sccp = (void *)r->start;
123
124 if (fep->scc.sccp == NULL)
125 return -EINVAL;
126
127 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pram");
128 fep->scc.ep = (void *)r->start;
129
130 if (fep->scc.ep == NULL)
131 return -EINVAL;
132
133 return 0;
134}
135
136#define SCC_NAPI_RX_EVENT_MSK (SCCE_ENET_RXF | SCCE_ENET_RXB)
137#define SCC_RX_EVENT (SCCE_ENET_RXF)
138#define SCC_TX_EVENT (SCCE_ENET_TXB)
139#define SCC_ERR_EVENT_MSK (SCCE_ENET_TXE | SCCE_ENET_BSY)
140
141static int setup_data(struct net_device *dev)
142{
143 struct fs_enet_private *fep = netdev_priv(dev);
144 const struct fs_platform_info *fpi = fep->fpi;
145
146 fep->scc.idx = fs_get_scc_index(fpi->fs_no);
147 if ((unsigned int)fep->fcc.idx > 4) /* max 4 SCCs */
148 return -EINVAL;
149
150 do_pd_setup(fep);
151
152 fep->scc.hthi = 0;
153 fep->scc.htlo = 0;
154
155 fep->ev_napi_rx = SCC_NAPI_RX_EVENT_MSK;
156 fep->ev_rx = SCC_RX_EVENT;
157 fep->ev_tx = SCC_TX_EVENT;
158 fep->ev_err = SCC_ERR_EVENT_MSK;
159
160 return 0;
161}
162
163static int allocate_bd(struct net_device *dev)
164{
165 struct fs_enet_private *fep = netdev_priv(dev);
166 const struct fs_platform_info *fpi = fep->fpi;
167
168 fep->ring_mem_addr = cpm_dpalloc((fpi->tx_ring + fpi->rx_ring) *
169 sizeof(cbd_t), 8);
170 if (IS_DPERR(fep->ring_mem_addr))
171 return -ENOMEM;
172
173 fep->ring_base = cpm_dpram_addr(fep->ring_mem_addr);
174
175 return 0;
176}
177
178static void free_bd(struct net_device *dev)
179{
180 struct fs_enet_private *fep = netdev_priv(dev);
181
182 if (fep->ring_base)
183 cpm_dpfree(fep->ring_mem_addr);
184}
185
186static void cleanup_data(struct net_device *dev)
187{
188 /* nothing */
189}
190
191static void set_promiscuous_mode(struct net_device *dev)
192{
193 struct fs_enet_private *fep = netdev_priv(dev);
194 scc_t *sccp = fep->scc.sccp;
195
196 S16(sccp, scc_psmr, SCC_PSMR_PRO);
197}
198
199static void set_multicast_start(struct net_device *dev)
200{
201 struct fs_enet_private *fep = netdev_priv(dev);
202 scc_enet_t *ep = fep->scc.ep;
203
204 W16(ep, sen_gaddr1, 0);
205 W16(ep, sen_gaddr2, 0);
206 W16(ep, sen_gaddr3, 0);
207 W16(ep, sen_gaddr4, 0);
208}
209
210static void set_multicast_one(struct net_device *dev, const u8 * mac)
211{
212 struct fs_enet_private *fep = netdev_priv(dev);
213 scc_enet_t *ep = fep->scc.ep;
214 u16 taddrh, taddrm, taddrl;
215
216 taddrh = ((u16) mac[5] << 8) | mac[4];
217 taddrm = ((u16) mac[3] << 8) | mac[2];
218 taddrl = ((u16) mac[1] << 8) | mac[0];
219
220 W16(ep, sen_taddrh, taddrh);
221 W16(ep, sen_taddrm, taddrm);
222 W16(ep, sen_taddrl, taddrl);
223 scc_cr_cmd(fep, CPM_CR_SET_GADDR);
224}
225
226static void set_multicast_finish(struct net_device *dev)
227{
228 struct fs_enet_private *fep = netdev_priv(dev);
229 scc_t *sccp = fep->scc.sccp;
230 scc_enet_t *ep = fep->scc.ep;
231
232 /* clear promiscuous always */
233 C16(sccp, scc_psmr, SCC_PSMR_PRO);
234
235 /* if all multi or too many multicasts; just enable all */
236 if ((dev->flags & IFF_ALLMULTI) != 0 ||
237 dev->mc_count > SCC_MAX_MULTICAST_ADDRS) {
238
239 W16(ep, sen_gaddr1, 0xffff);
240 W16(ep, sen_gaddr2, 0xffff);
241 W16(ep, sen_gaddr3, 0xffff);
242 W16(ep, sen_gaddr4, 0xffff);
243 }
244}
245
246static void set_multicast_list(struct net_device *dev)
247{
248 struct dev_mc_list *pmc;
249
250 if ((dev->flags & IFF_PROMISC) == 0) {
251 set_multicast_start(dev);
252 for (pmc = dev->mc_list; pmc != NULL; pmc = pmc->next)
253 set_multicast_one(dev, pmc->dmi_addr);
254 set_multicast_finish(dev);
255 } else
256 set_promiscuous_mode(dev);
257}
258
259/*
260 * This function is called to start or restart the FEC during a link
261 * change. This only happens when switching between half and full
262 * duplex.
263 */
264static void restart(struct net_device *dev)
265{
266 struct fs_enet_private *fep = netdev_priv(dev);
267 scc_t *sccp = fep->scc.sccp;
268 scc_enet_t *ep = fep->scc.ep;
269 const struct fs_platform_info *fpi = fep->fpi;
270 u16 paddrh, paddrm, paddrl;
271 const unsigned char *mac;
272 int i;
273
274 C32(sccp, scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT);
275
276 /* clear everything (slow & steady does it) */
277 for (i = 0; i < sizeof(*ep); i++)
278 __fs_out8((char *)ep + i, 0);
279
280 /* point to bds */
281 W16(ep, sen_genscc.scc_rbase, fep->ring_mem_addr);
282 W16(ep, sen_genscc.scc_tbase,
283 fep->ring_mem_addr + sizeof(cbd_t) * fpi->rx_ring);
284
285 /* Initialize function code registers for big-endian.
286 */
287 W8(ep, sen_genscc.scc_rfcr, SCC_EB);
288 W8(ep, sen_genscc.scc_tfcr, SCC_EB);
289
290 /* Set maximum bytes per receive buffer.
291 * This appears to be an Ethernet frame size, not the buffer
292 * fragment size. It must be a multiple of four.
293 */
294 W16(ep, sen_genscc.scc_mrblr, 0x5f0);
295
296 /* Set CRC preset and mask.
297 */
298 W32(ep, sen_cpres, 0xffffffff);
299 W32(ep, sen_cmask, 0xdebb20e3);
300
301 W32(ep, sen_crcec, 0); /* CRC Error counter */
302 W32(ep, sen_alec, 0); /* alignment error counter */
303 W32(ep, sen_disfc, 0); /* discard frame counter */
304
305 W16(ep, sen_pads, 0x8888); /* Tx short frame pad character */
306 W16(ep, sen_retlim, 15); /* Retry limit threshold */
307
308 W16(ep, sen_maxflr, 0x5ee); /* maximum frame length register */
309
310 W16(ep, sen_minflr, PKT_MINBUF_SIZE); /* minimum frame length register */
311
312 W16(ep, sen_maxd1, 0x000005f0); /* maximum DMA1 length */
313 W16(ep, sen_maxd2, 0x000005f0); /* maximum DMA2 length */
314
315 /* Clear hash tables.
316 */
317 W16(ep, sen_gaddr1, 0);
318 W16(ep, sen_gaddr2, 0);
319 W16(ep, sen_gaddr3, 0);
320 W16(ep, sen_gaddr4, 0);
321 W16(ep, sen_iaddr1, 0);
322 W16(ep, sen_iaddr2, 0);
323 W16(ep, sen_iaddr3, 0);
324 W16(ep, sen_iaddr4, 0);
325
326 /* set address
327 */
328 mac = dev->dev_addr;
329 paddrh = ((u16) mac[5] << 8) | mac[4];
330 paddrm = ((u16) mac[3] << 8) | mac[2];
331 paddrl = ((u16) mac[1] << 8) | mac[0];
332
333 W16(ep, sen_paddrh, paddrh);
334 W16(ep, sen_paddrm, paddrm);
335 W16(ep, sen_paddrl, paddrl);
336
337 W16(ep, sen_pper, 0);
338 W16(ep, sen_taddrl, 0);
339 W16(ep, sen_taddrm, 0);
340 W16(ep, sen_taddrh, 0);
341
342 fs_init_bds(dev);
343
344 scc_cr_cmd(fep, CPM_CR_INIT_TRX);
345
346 W16(sccp, scc_scce, 0xffff);
347
348 /* Enable interrupts we wish to service.
349 */
350 W16(sccp, scc_sccm, SCCE_ENET_TXE | SCCE_ENET_RXF | SCCE_ENET_TXB);
351
352 /* Set GSMR_H to enable all normal operating modes.
353 * Set GSMR_L to enable Ethernet to MC68160.
354 */
355 W32(sccp, scc_gsmrh, 0);
356 W32(sccp, scc_gsmrl,
357 SCC_GSMRL_TCI | SCC_GSMRL_TPL_48 | SCC_GSMRL_TPP_10 |
358 SCC_GSMRL_MODE_ENET);
359
360 /* Set sync/delimiters.
361 */
362 W16(sccp, scc_dsr, 0xd555);
363
364 /* Set processing mode. Use Ethernet CRC, catch broadcast, and
365 * start frame search 22 bit times after RENA.
366 */
367 W16(sccp, scc_psmr, SCC_PSMR_ENCRC | SCC_PSMR_NIB22);
368
369 /* Set full duplex mode if needed */
370 if (fep->duplex)
371 S16(sccp, scc_psmr, SCC_PSMR_LPB | SCC_PSMR_FDE);
372
373 S32(sccp, scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT);
374}
375
376static void stop(struct net_device *dev)
377{
378 struct fs_enet_private *fep = netdev_priv(dev);
379 scc_t *sccp = fep->scc.sccp;
380 int i;
381
382 for (i = 0; (R16(sccp, scc_sccm) == 0) && i < SCC_RESET_DELAY; i++)
383 udelay(1);
384
385 if (i == SCC_RESET_DELAY)
386 printk(KERN_WARNING DRV_MODULE_NAME
387 ": %s SCC timeout on graceful transmit stop\n",
388 dev->name);
389
390 W16(sccp, scc_sccm, 0);
391 C32(sccp, scc_gsmrl, SCC_GSMRL_ENR | SCC_GSMRL_ENT);
392
393 fs_cleanup_bds(dev);
394}
395
396static void pre_request_irq(struct net_device *dev, int irq)
397{
398 immap_t *immap = fs_enet_immap;
399 u32 siel;
400
401 /* SIU interrupt */
402 if (irq >= SIU_IRQ0 && irq < SIU_LEVEL7) {
403
404 siel = in_be32(&immap->im_siu_conf.sc_siel);
405 if ((irq & 1) == 0)
406 siel |= (0x80000000 >> irq);
407 else
408 siel &= ~(0x80000000 >> (irq & ~1));
409 out_be32(&immap->im_siu_conf.sc_siel, siel);
410 }
411}
412
413static void post_free_irq(struct net_device *dev, int irq)
414{
415 /* nothing */
416}
417
418static void napi_clear_rx_event(struct net_device *dev)
419{
420 struct fs_enet_private *fep = netdev_priv(dev);
421 scc_t *sccp = fep->scc.sccp;
422
423 W16(sccp, scc_scce, SCC_NAPI_RX_EVENT_MSK);
424}
425
426static void napi_enable_rx(struct net_device *dev)
427{
428 struct fs_enet_private *fep = netdev_priv(dev);
429 scc_t *sccp = fep->scc.sccp;
430
431 S16(sccp, scc_sccm, SCC_NAPI_RX_EVENT_MSK);
432}
433
434static void napi_disable_rx(struct net_device *dev)
435{
436 struct fs_enet_private *fep = netdev_priv(dev);
437 scc_t *sccp = fep->scc.sccp;
438
439 C16(sccp, scc_sccm, SCC_NAPI_RX_EVENT_MSK);
440}
441
442static void rx_bd_done(struct net_device *dev)
443{
444 /* nothing */
445}
446
447static void tx_kickstart(struct net_device *dev)
448{
449 /* nothing */
450}
451
452static u32 get_int_events(struct net_device *dev)
453{
454 struct fs_enet_private *fep = netdev_priv(dev);
455 scc_t *sccp = fep->scc.sccp;
456
457 return (u32) R16(sccp, scc_scce);
458}
459
460static void clear_int_events(struct net_device *dev, u32 int_events)
461{
462 struct fs_enet_private *fep = netdev_priv(dev);
463 scc_t *sccp = fep->scc.sccp;
464
465 W16(sccp, scc_scce, int_events & 0xffff);
466}
467
468static void ev_error(struct net_device *dev, u32 int_events)
469{
470 printk(KERN_WARNING DRV_MODULE_NAME
471 ": %s SCC ERROR(s) 0x%x\n", dev->name, int_events);
472}
473
474static int get_regs(struct net_device *dev, void *p, int *sizep)
475{
476 struct fs_enet_private *fep = netdev_priv(dev);
477
478 if (*sizep < sizeof(scc_t) + sizeof(scc_enet_t))
479 return -EINVAL;
480
481 memcpy_fromio(p, fep->scc.sccp, sizeof(scc_t));
482 p = (char *)p + sizeof(scc_t);
483
484 memcpy_fromio(p, fep->scc.ep, sizeof(scc_enet_t));
485
486 return 0;
487}
488
489static int get_regs_len(struct net_device *dev)
490{
491 return sizeof(scc_t) + sizeof(scc_enet_t);
492}
493
494static void tx_restart(struct net_device *dev)
495{
496 struct fs_enet_private *fep = netdev_priv(dev);
497
498 scc_cr_cmd(fep, CPM_CR_RESTART_TX);
499}
500
501/*************************************************************************/
502
503const struct fs_ops fs_scc_ops = {
504 .setup_data = setup_data,
505 .cleanup_data = cleanup_data,
506 .set_multicast_list = set_multicast_list,
507 .restart = restart,
508 .stop = stop,
509 .pre_request_irq = pre_request_irq,
510 .post_free_irq = post_free_irq,
511 .napi_clear_rx_event = napi_clear_rx_event,
512 .napi_enable_rx = napi_enable_rx,
513 .napi_disable_rx = napi_disable_rx,
514 .rx_bd_done = rx_bd_done,
515 .tx_kickstart = tx_kickstart,
516 .get_int_events = get_int_events,
517 .clear_int_events = clear_int_events,
518 .ev_error = ev_error,
519 .get_regs = get_regs,
520 .get_regs_len = get_regs_len,
521 .tx_restart = tx_restart,
522 .allocate_bd = allocate_bd,
523 .free_bd = free_bd,
524};
diff --git a/drivers/net/fs_enet/mii-bitbang.c b/drivers/net/fs_enet/mii-bitbang.c
new file mode 100644
index 000000000000..24a5e2e23d18
--- /dev/null
+++ b/drivers/net/fs_enet/mii-bitbang.c
@@ -0,0 +1,405 @@
1/*
2 * Combined Ethernet driver for Motorola MPC8xx and MPC82xx.
3 *
4 * Copyright (c) 2003 Intracom S.A.
5 * by Pantelis Antoniou <panto@intracom.gr>
6 *
7 * 2005 (c) MontaVista Software, Inc.
8 * Vitaly Bordug <vbordug@ru.mvista.com>
9 *
10 * This file is licensed under the terms of the GNU General Public License
11 * version 2. This program is licensed "as is" without any warranty of any
12 * kind, whether express or implied.
13 */
14
15
16#include <linux/config.h>
17#include <linux/module.h>
18#include <linux/types.h>
19#include <linux/kernel.h>
20#include <linux/sched.h>
21#include <linux/string.h>
22#include <linux/ptrace.h>
23#include <linux/errno.h>
24#include <linux/ioport.h>
25#include <linux/slab.h>
26#include <linux/interrupt.h>
27#include <linux/pci.h>
28#include <linux/init.h>
29#include <linux/delay.h>
30#include <linux/netdevice.h>
31#include <linux/etherdevice.h>
32#include <linux/skbuff.h>
33#include <linux/spinlock.h>
34#include <linux/mii.h>
35#include <linux/ethtool.h>
36#include <linux/bitops.h>
37
38#include <asm/pgtable.h>
39#include <asm/irq.h>
40#include <asm/uaccess.h>
41
42#include "fs_enet.h"
43
44#ifdef CONFIG_8xx
45static int bitbang_prep_bit(u8 **dirp, u8 **datp, u8 *mskp, int port, int bit)
46{
47 immap_t *im = (immap_t *)fs_enet_immap;
48 void *dir, *dat, *ppar;
49 int adv;
50 u8 msk;
51
52 switch (port) {
53 case fsiop_porta:
54 dir = &im->im_ioport.iop_padir;
55 dat = &im->im_ioport.iop_padat;
56 ppar = &im->im_ioport.iop_papar;
57 break;
58
59 case fsiop_portb:
60 dir = &im->im_cpm.cp_pbdir;
61 dat = &im->im_cpm.cp_pbdat;
62 ppar = &im->im_cpm.cp_pbpar;
63 break;
64
65 case fsiop_portc:
66 dir = &im->im_ioport.iop_pcdir;
67 dat = &im->im_ioport.iop_pcdat;
68 ppar = &im->im_ioport.iop_pcpar;
69 break;
70
71 case fsiop_portd:
72 dir = &im->im_ioport.iop_pddir;
73 dat = &im->im_ioport.iop_pddat;
74 ppar = &im->im_ioport.iop_pdpar;
75 break;
76
77 case fsiop_porte:
78 dir = &im->im_cpm.cp_pedir;
79 dat = &im->im_cpm.cp_pedat;
80 ppar = &im->im_cpm.cp_pepar;
81 break;
82
83 default:
84 printk(KERN_ERR DRV_MODULE_NAME
85 "Illegal port value %d!\n", port);
86 return -EINVAL;
87 }
88
89 adv = bit >> 3;
90 dir = (char *)dir + adv;
91 dat = (char *)dat + adv;
92 ppar = (char *)ppar + adv;
93
94 msk = 1 << (7 - (bit & 7));
95 if ((in_8(ppar) & msk) != 0) {
96 printk(KERN_ERR DRV_MODULE_NAME
97 "pin %d on port %d is not general purpose!\n", bit, port);
98 return -EINVAL;
99 }
100
101 *dirp = dir;
102 *datp = dat;
103 *mskp = msk;
104
105 return 0;
106}
107#endif
108
109#ifdef CONFIG_8260
110static int bitbang_prep_bit(u8 **dirp, u8 **datp, u8 *mskp, int port, int bit)
111{
112 iop_cpm2_t *io = &((cpm2_map_t *)fs_enet_immap)->im_ioport;
113 void *dir, *dat, *ppar;
114 int adv;
115 u8 msk;
116
117 switch (port) {
118 case fsiop_porta:
119 dir = &io->iop_pdira;
120 dat = &io->iop_pdata;
121 ppar = &io->iop_ppara;
122 break;
123
124 case fsiop_portb:
125 dir = &io->iop_pdirb;
126 dat = &io->iop_pdatb;
127 ppar = &io->iop_pparb;
128 break;
129
130 case fsiop_portc:
131 dir = &io->iop_pdirc;
132 dat = &io->iop_pdatc;
133 ppar = &io->iop_pparc;
134 break;
135
136 case fsiop_portd:
137 dir = &io->iop_pdird;
138 dat = &io->iop_pdatd;
139 ppar = &io->iop_ppard;
140 break;
141
142 default:
143 printk(KERN_ERR DRV_MODULE_NAME
144 "Illegal port value %d!\n", port);
145 return -EINVAL;
146 }
147
148 adv = bit >> 3;
149 dir = (char *)dir + adv;
150 dat = (char *)dat + adv;
151 ppar = (char *)ppar + adv;
152
153 msk = 1 << (7 - (bit & 7));
154 if ((in_8(ppar) & msk) != 0) {
155 printk(KERN_ERR DRV_MODULE_NAME
156 "pin %d on port %d is not general purpose!\n", bit, port);
157 return -EINVAL;
158 }
159
160 *dirp = dir;
161 *datp = dat;
162 *mskp = msk;
163
164 return 0;
165}
166#endif
167
168static inline void bb_set(u8 *p, u8 m)
169{
170 out_8(p, in_8(p) | m);
171}
172
173static inline void bb_clr(u8 *p, u8 m)
174{
175 out_8(p, in_8(p) & ~m);
176}
177
178static inline int bb_read(u8 *p, u8 m)
179{
180 return (in_8(p) & m) != 0;
181}
182
183static inline void mdio_active(struct fs_enet_mii_bus *bus)
184{
185 bb_set(bus->bitbang.mdio_dir, bus->bitbang.mdio_msk);
186}
187
188static inline void mdio_tristate(struct fs_enet_mii_bus *bus)
189{
190 bb_clr(bus->bitbang.mdio_dir, bus->bitbang.mdio_msk);
191}
192
193static inline int mdio_read(struct fs_enet_mii_bus *bus)
194{
195 return bb_read(bus->bitbang.mdio_dat, bus->bitbang.mdio_msk);
196}
197
198static inline void mdio(struct fs_enet_mii_bus *bus, int what)
199{
200 if (what)
201 bb_set(bus->bitbang.mdio_dat, bus->bitbang.mdio_msk);
202 else
203 bb_clr(bus->bitbang.mdio_dat, bus->bitbang.mdio_msk);
204}
205
206static inline void mdc(struct fs_enet_mii_bus *bus, int what)
207{
208 if (what)
209 bb_set(bus->bitbang.mdc_dat, bus->bitbang.mdc_msk);
210 else
211 bb_clr(bus->bitbang.mdc_dat, bus->bitbang.mdc_msk);
212}
213
214static inline void mii_delay(struct fs_enet_mii_bus *bus)
215{
216 udelay(bus->bus_info->i.bitbang.delay);
217}
218
219/* Utility to send the preamble, address, and register (common to read and write). */
220static void bitbang_pre(struct fs_enet_mii_bus *bus, int read, u8 addr, u8 reg)
221{
222 int j;
223
224 /*
225 * Send a 32 bit preamble ('1's) with an extra '1' bit for good measure.
226 * The IEEE spec says this is a PHY optional requirement. The AMD
227 * 79C874 requires one after power up and one after a MII communications
228 * error. This means that we are doing more preambles than we need,
229 * but it is safer and will be much more robust.
230 */
231
232 mdio_active(bus);
233 mdio(bus, 1);
234 for (j = 0; j < 32; j++) {
235 mdc(bus, 0);
236 mii_delay(bus);
237 mdc(bus, 1);
238 mii_delay(bus);
239 }
240
241 /* send the start bit (01) and the read opcode (10) or write (10) */
242 mdc(bus, 0);
243 mdio(bus, 0);
244 mii_delay(bus);
245 mdc(bus, 1);
246 mii_delay(bus);
247 mdc(bus, 0);
248 mdio(bus, 1);
249 mii_delay(bus);
250 mdc(bus, 1);
251 mii_delay(bus);
252 mdc(bus, 0);
253 mdio(bus, read);
254 mii_delay(bus);
255 mdc(bus, 1);
256 mii_delay(bus);
257 mdc(bus, 0);
258 mdio(bus, !read);
259 mii_delay(bus);
260 mdc(bus, 1);
261 mii_delay(bus);
262
263 /* send the PHY address */
264 for (j = 0; j < 5; j++) {
265 mdc(bus, 0);
266 mdio(bus, (addr & 0x10) != 0);
267 mii_delay(bus);
268 mdc(bus, 1);
269 mii_delay(bus);
270 addr <<= 1;
271 }
272
273 /* send the register address */
274 for (j = 0; j < 5; j++) {
275 mdc(bus, 0);
276 mdio(bus, (reg & 0x10) != 0);
277 mii_delay(bus);
278 mdc(bus, 1);
279 mii_delay(bus);
280 reg <<= 1;
281 }
282}
283
284static int mii_read(struct fs_enet_mii_bus *bus, int phy_id, int location)
285{
286 u16 rdreg;
287 int ret, j;
288 u8 addr = phy_id & 0xff;
289 u8 reg = location & 0xff;
290
291 bitbang_pre(bus, 1, addr, reg);
292
293 /* tri-state our MDIO I/O pin so we can read */
294 mdc(bus, 0);
295 mdio_tristate(bus);
296 mii_delay(bus);
297 mdc(bus, 1);
298 mii_delay(bus);
299
300 /* check the turnaround bit: the PHY should be driving it to zero */
301 if (mdio_read(bus) != 0) {
302 /* PHY didn't drive TA low */
303 for (j = 0; j < 32; j++) {
304 mdc(bus, 0);
305 mii_delay(bus);
306 mdc(bus, 1);
307 mii_delay(bus);
308 }
309 ret = -1;
310 goto out;
311 }
312
313 mdc(bus, 0);
314 mii_delay(bus);
315
316 /* read 16 bits of register data, MSB first */
317 rdreg = 0;
318 for (j = 0; j < 16; j++) {
319 mdc(bus, 1);
320 mii_delay(bus);
321 rdreg <<= 1;
322 rdreg |= mdio_read(bus);
323 mdc(bus, 0);
324 mii_delay(bus);
325 }
326
327 mdc(bus, 1);
328 mii_delay(bus);
329 mdc(bus, 0);
330 mii_delay(bus);
331 mdc(bus, 1);
332 mii_delay(bus);
333
334 ret = rdreg;
335out:
336 return ret;
337}
338
339static void mii_write(struct fs_enet_mii_bus *bus, int phy_id, int location, int val)
340{
341 int j;
342 u8 addr = phy_id & 0xff;
343 u8 reg = location & 0xff;
344 u16 value = val & 0xffff;
345
346 bitbang_pre(bus, 0, addr, reg);
347
348 /* send the turnaround (10) */
349 mdc(bus, 0);
350 mdio(bus, 1);
351 mii_delay(bus);
352 mdc(bus, 1);
353 mii_delay(bus);
354 mdc(bus, 0);
355 mdio(bus, 0);
356 mii_delay(bus);
357 mdc(bus, 1);
358 mii_delay(bus);
359
360 /* write 16 bits of register data, MSB first */
361 for (j = 0; j < 16; j++) {
362 mdc(bus, 0);
363 mdio(bus, (value & 0x8000) != 0);
364 mii_delay(bus);
365 mdc(bus, 1);
366 mii_delay(bus);
367 value <<= 1;
368 }
369
370 /*
371 * Tri-state the MDIO line.
372 */
373 mdio_tristate(bus);
374 mdc(bus, 0);
375 mii_delay(bus);
376 mdc(bus, 1);
377 mii_delay(bus);
378}
379
380int fs_mii_bitbang_init(struct fs_enet_mii_bus *bus)
381{
382 const struct fs_mii_bus_info *bi = bus->bus_info;
383 int r;
384
385 r = bitbang_prep_bit(&bus->bitbang.mdio_dir,
386 &bus->bitbang.mdio_dat,
387 &bus->bitbang.mdio_msk,
388 bi->i.bitbang.mdio_port,
389 bi->i.bitbang.mdio_bit);
390 if (r != 0)
391 return r;
392
393 r = bitbang_prep_bit(&bus->bitbang.mdc_dir,
394 &bus->bitbang.mdc_dat,
395 &bus->bitbang.mdc_msk,
396 bi->i.bitbang.mdc_port,
397 bi->i.bitbang.mdc_bit);
398 if (r != 0)
399 return r;
400
401 bus->mii_read = mii_read;
402 bus->mii_write = mii_write;
403
404 return 0;
405}
diff --git a/drivers/net/fs_enet/mii-fixed.c b/drivers/net/fs_enet/mii-fixed.c
new file mode 100644
index 000000000000..b3e192d612e5
--- /dev/null
+++ b/drivers/net/fs_enet/mii-fixed.c
@@ -0,0 +1,92 @@
1/*
2 * Combined Ethernet driver for Motorola MPC8xx and MPC82xx.
3 *
4 * Copyright (c) 2003 Intracom S.A.
5 * by Pantelis Antoniou <panto@intracom.gr>
6 *
7 * 2005 (c) MontaVista Software, Inc.
8 * Vitaly Bordug <vbordug@ru.mvista.com>
9 *
10 * This file is licensed under the terms of the GNU General Public License
11 * version 2. This program is licensed "as is" without any warranty of any
12 * kind, whether express or implied.
13 */
14
15
16#include <linux/config.h>
17#include <linux/module.h>
18#include <linux/types.h>
19#include <linux/kernel.h>
20#include <linux/sched.h>
21#include <linux/string.h>
22#include <linux/ptrace.h>
23#include <linux/errno.h>
24#include <linux/ioport.h>
25#include <linux/slab.h>
26#include <linux/interrupt.h>
27#include <linux/pci.h>
28#include <linux/init.h>
29#include <linux/delay.h>
30#include <linux/netdevice.h>
31#include <linux/etherdevice.h>
32#include <linux/skbuff.h>
33#include <linux/spinlock.h>
34#include <linux/mii.h>
35#include <linux/ethtool.h>
36#include <linux/bitops.h>
37
38#include <asm/pgtable.h>
39#include <asm/irq.h>
40#include <asm/uaccess.h>
41
42#include "fs_enet.h"
43
44static const u16 mii_regs[7] = {
45 0x3100,
46 0x786d,
47 0x0fff,
48 0x0fff,
49 0x01e1,
50 0x45e1,
51 0x0003,
52};
53
54static int mii_read(struct fs_enet_mii_bus *bus, int phy_id, int location)
55{
56 int ret = 0;
57
58 if ((unsigned int)location >= ARRAY_SIZE(mii_regs))
59 return -1;
60
61 if (location != 5)
62 ret = mii_regs[location];
63 else
64 ret = bus->fixed.lpa;
65
66 return ret;
67}
68
69static void mii_write(struct fs_enet_mii_bus *bus, int phy_id, int location, int val)
70{
71 /* do nothing */
72}
73
74int fs_mii_fixed_init(struct fs_enet_mii_bus *bus)
75{
76 const struct fs_mii_bus_info *bi = bus->bus_info;
77
78 bus->fixed.lpa = 0x45e1; /* default 100Mb, full duplex */
79
80 /* if speed is fixed at 10Mb, remove 100Mb modes */
81 if (bi->i.fixed.speed == 10)
82 bus->fixed.lpa &= ~LPA_100;
83
84 /* if duplex is half, remove full duplex modes */
85 if (bi->i.fixed.duplex == 0)
86 bus->fixed.lpa &= ~LPA_DUPLEX;
87
88 bus->mii_read = mii_read;
89 bus->mii_write = mii_write;
90
91 return 0;
92}
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index 6518334b9280..ae5a2ed3b264 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -29,12 +29,7 @@
29 * define the configuration needed by the board are defined in a 29 * define the configuration needed by the board are defined in a
30 * board structure in arch/ppc/platforms (though I do not 30 * board structure in arch/ppc/platforms (though I do not
31 * discount the possibility that other architectures could one 31 * discount the possibility that other architectures could one
32 * day be supported. One assumption the driver currently makes 32 * day be supported.
33 * is that the PHY is configured in such a way to advertise all
34 * capabilities. This is a sensible default, and on certain
35 * PHYs, changing this default encounters substantial errata
36 * issues. Future versions may remove this requirement, but for
37 * now, it is best for the firmware to ensure this is the case.
38 * 33 *
39 * The Gianfar Ethernet Controller uses a ring of buffer 34 * The Gianfar Ethernet Controller uses a ring of buffer
40 * descriptors. The beginning is indicated by a register 35 * descriptors. The beginning is indicated by a register
@@ -47,7 +42,7 @@
47 * corresponding bit in the IMASK register is also set (if 42 * corresponding bit in the IMASK register is also set (if
48 * interrupt coalescing is active, then the interrupt may not 43 * interrupt coalescing is active, then the interrupt may not
49 * happen immediately, but will wait until either a set number 44 * happen immediately, but will wait until either a set number
50 * of frames or amount of time have passed.). In NAPI, the 45 * of frames or amount of time have passed). In NAPI, the
51 * interrupt handler will signal there is work to be done, and 46 * interrupt handler will signal there is work to be done, and
52 * exit. Without NAPI, the packet(s) will be handled 47 * exit. Without NAPI, the packet(s) will be handled
53 * immediately. Both methods will start at the last known empty 48 * immediately. Both methods will start at the last known empty
@@ -75,6 +70,7 @@
75#include <linux/sched.h> 70#include <linux/sched.h>
76#include <linux/string.h> 71#include <linux/string.h>
77#include <linux/errno.h> 72#include <linux/errno.h>
73#include <linux/unistd.h>
78#include <linux/slab.h> 74#include <linux/slab.h>
79#include <linux/interrupt.h> 75#include <linux/interrupt.h>
80#include <linux/init.h> 76#include <linux/init.h>
@@ -97,9 +93,11 @@
97#include <linux/version.h> 93#include <linux/version.h>
98#include <linux/dma-mapping.h> 94#include <linux/dma-mapping.h>
99#include <linux/crc32.h> 95#include <linux/crc32.h>
96#include <linux/mii.h>
97#include <linux/phy.h>
100 98
101#include "gianfar.h" 99#include "gianfar.h"
102#include "gianfar_phy.h" 100#include "gianfar_mii.h"
103 101
104#define TX_TIMEOUT (1*HZ) 102#define TX_TIMEOUT (1*HZ)
105#define SKB_ALLOC_TIMEOUT 1000000 103#define SKB_ALLOC_TIMEOUT 1000000
@@ -113,9 +111,8 @@
113#endif 111#endif
114 112
115const char gfar_driver_name[] = "Gianfar Ethernet"; 113const char gfar_driver_name[] = "Gianfar Ethernet";
116const char gfar_driver_version[] = "1.1"; 114const char gfar_driver_version[] = "1.2";
117 115
118int startup_gfar(struct net_device *dev);
119static int gfar_enet_open(struct net_device *dev); 116static int gfar_enet_open(struct net_device *dev);
120static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev); 117static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev);
121static void gfar_timeout(struct net_device *dev); 118static void gfar_timeout(struct net_device *dev);
@@ -126,17 +123,13 @@ static int gfar_set_mac_address(struct net_device *dev);
126static int gfar_change_mtu(struct net_device *dev, int new_mtu); 123static int gfar_change_mtu(struct net_device *dev, int new_mtu);
127static irqreturn_t gfar_error(int irq, void *dev_id, struct pt_regs *regs); 124static irqreturn_t gfar_error(int irq, void *dev_id, struct pt_regs *regs);
128static irqreturn_t gfar_transmit(int irq, void *dev_id, struct pt_regs *regs); 125static irqreturn_t gfar_transmit(int irq, void *dev_id, struct pt_regs *regs);
129static irqreturn_t gfar_receive(int irq, void *dev_id, struct pt_regs *regs);
130static irqreturn_t gfar_interrupt(int irq, void *dev_id, struct pt_regs *regs); 126static irqreturn_t gfar_interrupt(int irq, void *dev_id, struct pt_regs *regs);
131static irqreturn_t phy_interrupt(int irq, void *dev_id, struct pt_regs *regs);
132static void gfar_phy_change(void *data);
133static void gfar_phy_timer(unsigned long data);
134static void adjust_link(struct net_device *dev); 127static void adjust_link(struct net_device *dev);
135static void init_registers(struct net_device *dev); 128static void init_registers(struct net_device *dev);
136static int init_phy(struct net_device *dev); 129static int init_phy(struct net_device *dev);
137static int gfar_probe(struct device *device); 130static int gfar_probe(struct device *device);
138static int gfar_remove(struct device *device); 131static int gfar_remove(struct device *device);
139void free_skb_resources(struct gfar_private *priv); 132static void free_skb_resources(struct gfar_private *priv);
140static void gfar_set_multi(struct net_device *dev); 133static void gfar_set_multi(struct net_device *dev);
141static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr); 134static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr);
142#ifdef CONFIG_GFAR_NAPI 135#ifdef CONFIG_GFAR_NAPI
@@ -144,7 +137,6 @@ static int gfar_poll(struct net_device *dev, int *budget);
144#endif 137#endif
145int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit); 138int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit);
146static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb, int length); 139static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb, int length);
147static void gfar_phy_startup_timer(unsigned long data);
148static void gfar_vlan_rx_register(struct net_device *netdev, 140static void gfar_vlan_rx_register(struct net_device *netdev,
149 struct vlan_group *grp); 141 struct vlan_group *grp);
150static void gfar_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid); 142static void gfar_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
@@ -162,6 +154,9 @@ int gfar_uses_fcb(struct gfar_private *priv)
162 else 154 else
163 return 0; 155 return 0;
164} 156}
157
158/* Set up the ethernet device structure, private data,
159 * and anything else we need before we start */
165static int gfar_probe(struct device *device) 160static int gfar_probe(struct device *device)
166{ 161{
167 u32 tempval; 162 u32 tempval;
@@ -175,7 +170,7 @@ static int gfar_probe(struct device *device)
175 170
176 einfo = (struct gianfar_platform_data *) pdev->dev.platform_data; 171 einfo = (struct gianfar_platform_data *) pdev->dev.platform_data;
177 172
178 if (einfo == NULL) { 173 if (NULL == einfo) {
179 printk(KERN_ERR "gfar %d: Missing additional data!\n", 174 printk(KERN_ERR "gfar %d: Missing additional data!\n",
180 pdev->id); 175 pdev->id);
181 176
@@ -185,7 +180,7 @@ static int gfar_probe(struct device *device)
185 /* Create an ethernet device instance */ 180 /* Create an ethernet device instance */
186 dev = alloc_etherdev(sizeof (*priv)); 181 dev = alloc_etherdev(sizeof (*priv));
187 182
188 if (dev == NULL) 183 if (NULL == dev)
189 return -ENOMEM; 184 return -ENOMEM;
190 185
191 priv = netdev_priv(dev); 186 priv = netdev_priv(dev);
@@ -207,20 +202,11 @@ static int gfar_probe(struct device *device)
207 priv->regs = (struct gfar *) 202 priv->regs = (struct gfar *)
208 ioremap(r->start, sizeof (struct gfar)); 203 ioremap(r->start, sizeof (struct gfar));
209 204
210 if (priv->regs == NULL) { 205 if (NULL == priv->regs) {
211 err = -ENOMEM; 206 err = -ENOMEM;
212 goto regs_fail; 207 goto regs_fail;
213 } 208 }
214 209
215 /* Set the PHY base address */
216 priv->phyregs = (struct gfar *)
217 ioremap(einfo->phy_reg_addr, sizeof (struct gfar));
218
219 if (priv->phyregs == NULL) {
220 err = -ENOMEM;
221 goto phy_regs_fail;
222 }
223
224 spin_lock_init(&priv->lock); 210 spin_lock_init(&priv->lock);
225 211
226 dev_set_drvdata(device, dev); 212 dev_set_drvdata(device, dev);
@@ -386,12 +372,10 @@ static int gfar_probe(struct device *device)
386 return 0; 372 return 0;
387 373
388register_fail: 374register_fail:
389 iounmap((void *) priv->phyregs);
390phy_regs_fail:
391 iounmap((void *) priv->regs); 375 iounmap((void *) priv->regs);
392regs_fail: 376regs_fail:
393 free_netdev(dev); 377 free_netdev(dev);
394 return -ENOMEM; 378 return err;
395} 379}
396 380
397static int gfar_remove(struct device *device) 381static int gfar_remove(struct device *device)
@@ -402,108 +386,41 @@ static int gfar_remove(struct device *device)
402 dev_set_drvdata(device, NULL); 386 dev_set_drvdata(device, NULL);
403 387
404 iounmap((void *) priv->regs); 388 iounmap((void *) priv->regs);
405 iounmap((void *) priv->phyregs);
406 free_netdev(dev); 389 free_netdev(dev);
407 390
408 return 0; 391 return 0;
409} 392}
410 393
411 394
412/* Configure the PHY for dev. 395/* Initializes driver's PHY state, and attaches to the PHY.
413 * returns 0 if success. -1 if failure 396 * Returns 0 on success.
414 */ 397 */
415static int init_phy(struct net_device *dev) 398static int init_phy(struct net_device *dev)
416{ 399{
417 struct gfar_private *priv = netdev_priv(dev); 400 struct gfar_private *priv = netdev_priv(dev);
418 struct phy_info *curphy; 401 uint gigabit_support =
419 unsigned int timeout = PHY_INIT_TIMEOUT; 402 priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT ?
420 struct gfar *phyregs = priv->phyregs; 403 SUPPORTED_1000baseT_Full : 0;
421 struct gfar_mii_info *mii_info; 404 struct phy_device *phydev;
422 int err;
423 405
424 priv->oldlink = 0; 406 priv->oldlink = 0;
425 priv->oldspeed = 0; 407 priv->oldspeed = 0;
426 priv->oldduplex = -1; 408 priv->oldduplex = -1;
427 409
428 mii_info = kmalloc(sizeof(struct gfar_mii_info), 410 phydev = phy_connect(dev, priv->einfo->bus_id, &adjust_link, 0);
429 GFP_KERNEL);
430
431 if(NULL == mii_info) {
432 if (netif_msg_ifup(priv))
433 printk(KERN_ERR "%s: Could not allocate mii_info\n",
434 dev->name);
435 return -ENOMEM;
436 }
437
438 mii_info->speed = SPEED_1000;
439 mii_info->duplex = DUPLEX_FULL;
440 mii_info->pause = 0;
441 mii_info->link = 1;
442
443 mii_info->advertising = (ADVERTISED_10baseT_Half |
444 ADVERTISED_10baseT_Full |
445 ADVERTISED_100baseT_Half |
446 ADVERTISED_100baseT_Full |
447 ADVERTISED_1000baseT_Full);
448 mii_info->autoneg = 1;
449 411
450 spin_lock_init(&mii_info->mdio_lock); 412 if (IS_ERR(phydev)) {
451 413 printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
452 mii_info->mii_id = priv->einfo->phyid; 414 return PTR_ERR(phydev);
453
454 mii_info->dev = dev;
455
456 mii_info->mdio_read = &read_phy_reg;
457 mii_info->mdio_write = &write_phy_reg;
458
459 priv->mii_info = mii_info;
460
461 /* Reset the management interface */
462 gfar_write(&phyregs->miimcfg, MIIMCFG_RESET);
463
464 /* Setup the MII Mgmt clock speed */
465 gfar_write(&phyregs->miimcfg, MIIMCFG_INIT_VALUE);
466
467 /* Wait until the bus is free */
468 while ((gfar_read(&phyregs->miimind) & MIIMIND_BUSY) &&
469 timeout--)
470 cpu_relax();
471
472 if(timeout <= 0) {
473 printk(KERN_ERR "%s: The MII Bus is stuck!\n",
474 dev->name);
475 err = -1;
476 goto bus_fail;
477 }
478
479 /* get info for this PHY */
480 curphy = get_phy_info(priv->mii_info);
481
482 if (curphy == NULL) {
483 if (netif_msg_ifup(priv))
484 printk(KERN_ERR "%s: No PHY found\n", dev->name);
485 err = -1;
486 goto no_phy;
487 } 415 }
488 416
489 mii_info->phyinfo = curphy; 417 /* Remove any features not supported by the controller */
418 phydev->supported &= (GFAR_SUPPORTED | gigabit_support);
419 phydev->advertising = phydev->supported;
490 420
491 /* Run the commands which initialize the PHY */ 421 priv->phydev = phydev;
492 if(curphy->init) {
493 err = curphy->init(priv->mii_info);
494
495 if (err)
496 goto phy_init_fail;
497 }
498 422
499 return 0; 423 return 0;
500
501phy_init_fail:
502no_phy:
503bus_fail:
504 kfree(mii_info);
505
506 return err;
507} 424}
508 425
509static void init_registers(struct net_device *dev) 426static void init_registers(struct net_device *dev)
@@ -603,24 +520,13 @@ void stop_gfar(struct net_device *dev)
603 struct gfar *regs = priv->regs; 520 struct gfar *regs = priv->regs;
604 unsigned long flags; 521 unsigned long flags;
605 522
523 phy_stop(priv->phydev);
524
606 /* Lock it down */ 525 /* Lock it down */
607 spin_lock_irqsave(&priv->lock, flags); 526 spin_lock_irqsave(&priv->lock, flags);
608 527
609 /* Tell the kernel the link is down */
610 priv->mii_info->link = 0;
611 adjust_link(dev);
612
613 gfar_halt(dev); 528 gfar_halt(dev);
614 529
615 if (priv->einfo->board_flags & FSL_GIANFAR_BRD_HAS_PHY_INTR) {
616 /* Clear any pending interrupts */
617 mii_clear_phy_interrupt(priv->mii_info);
618
619 /* Disable PHY Interrupts */
620 mii_configure_phy_interrupt(priv->mii_info,
621 MII_INTERRUPT_DISABLED);
622 }
623
624 spin_unlock_irqrestore(&priv->lock, flags); 530 spin_unlock_irqrestore(&priv->lock, flags);
625 531
626 /* Free the IRQs */ 532 /* Free the IRQs */
@@ -629,13 +535,7 @@ void stop_gfar(struct net_device *dev)
629 free_irq(priv->interruptTransmit, dev); 535 free_irq(priv->interruptTransmit, dev);
630 free_irq(priv->interruptReceive, dev); 536 free_irq(priv->interruptReceive, dev);
631 } else { 537 } else {
632 free_irq(priv->interruptTransmit, dev); 538 free_irq(priv->interruptTransmit, dev);
633 }
634
635 if (priv->einfo->board_flags & FSL_GIANFAR_BRD_HAS_PHY_INTR) {
636 free_irq(priv->einfo->interruptPHY, dev);
637 } else {
638 del_timer_sync(&priv->phy_info_timer);
639 } 539 }
640 540
641 free_skb_resources(priv); 541 free_skb_resources(priv);
@@ -649,7 +549,7 @@ void stop_gfar(struct net_device *dev)
649 549
650/* If there are any tx skbs or rx skbs still around, free them. 550/* If there are any tx skbs or rx skbs still around, free them.
651 * Then free tx_skbuff and rx_skbuff */ 551 * Then free tx_skbuff and rx_skbuff */
652void free_skb_resources(struct gfar_private *priv) 552static void free_skb_resources(struct gfar_private *priv)
653{ 553{
654 struct rxbd8 *rxbdp; 554 struct rxbd8 *rxbdp;
655 struct txbd8 *txbdp; 555 struct txbd8 *txbdp;
@@ -770,7 +670,7 @@ int startup_gfar(struct net_device *dev)
770 (struct sk_buff **) kmalloc(sizeof (struct sk_buff *) * 670 (struct sk_buff **) kmalloc(sizeof (struct sk_buff *) *
771 priv->tx_ring_size, GFP_KERNEL); 671 priv->tx_ring_size, GFP_KERNEL);
772 672
773 if (priv->tx_skbuff == NULL) { 673 if (NULL == priv->tx_skbuff) {
774 if (netif_msg_ifup(priv)) 674 if (netif_msg_ifup(priv))
775 printk(KERN_ERR "%s: Could not allocate tx_skbuff\n", 675 printk(KERN_ERR "%s: Could not allocate tx_skbuff\n",
776 dev->name); 676 dev->name);
@@ -785,7 +685,7 @@ int startup_gfar(struct net_device *dev)
785 (struct sk_buff **) kmalloc(sizeof (struct sk_buff *) * 685 (struct sk_buff **) kmalloc(sizeof (struct sk_buff *) *
786 priv->rx_ring_size, GFP_KERNEL); 686 priv->rx_ring_size, GFP_KERNEL);
787 687
788 if (priv->rx_skbuff == NULL) { 688 if (NULL == priv->rx_skbuff) {
789 if (netif_msg_ifup(priv)) 689 if (netif_msg_ifup(priv))
790 printk(KERN_ERR "%s: Could not allocate rx_skbuff\n", 690 printk(KERN_ERR "%s: Could not allocate rx_skbuff\n",
791 dev->name); 691 dev->name);
@@ -879,13 +779,7 @@ int startup_gfar(struct net_device *dev)
879 } 779 }
880 } 780 }
881 781
882 /* Set up the PHY change work queue */ 782 phy_start(priv->phydev);
883 INIT_WORK(&priv->tq, gfar_phy_change, dev);
884
885 init_timer(&priv->phy_info_timer);
886 priv->phy_info_timer.function = &gfar_phy_startup_timer;
887 priv->phy_info_timer.data = (unsigned long) priv->mii_info;
888 mod_timer(&priv->phy_info_timer, jiffies + HZ);
889 783
890 /* Configure the coalescing support */ 784 /* Configure the coalescing support */
891 if (priv->txcoalescing) 785 if (priv->txcoalescing)
@@ -933,11 +827,6 @@ tx_skb_fail:
933 priv->tx_bd_base, 827 priv->tx_bd_base,
934 gfar_read(&regs->tbase0)); 828 gfar_read(&regs->tbase0));
935 829
936 if (priv->mii_info->phyinfo->close)
937 priv->mii_info->phyinfo->close(priv->mii_info);
938
939 kfree(priv->mii_info);
940
941 return err; 830 return err;
942} 831}
943 832
@@ -1035,7 +924,7 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
1035 txbdp->status &= TXBD_WRAP; 924 txbdp->status &= TXBD_WRAP;
1036 925
1037 /* Set up checksumming */ 926 /* Set up checksumming */
1038 if ((dev->features & NETIF_F_IP_CSUM) 927 if ((dev->features & NETIF_F_IP_CSUM)
1039 && (CHECKSUM_HW == skb->ip_summed)) { 928 && (CHECKSUM_HW == skb->ip_summed)) {
1040 fcb = gfar_add_fcb(skb, txbdp); 929 fcb = gfar_add_fcb(skb, txbdp);
1041 gfar_tx_checksum(skb, fcb); 930 gfar_tx_checksum(skb, fcb);
@@ -1103,11 +992,9 @@ static int gfar_close(struct net_device *dev)
1103 struct gfar_private *priv = netdev_priv(dev); 992 struct gfar_private *priv = netdev_priv(dev);
1104 stop_gfar(dev); 993 stop_gfar(dev);
1105 994
1106 /* Shutdown the PHY */ 995 /* Disconnect from the PHY */
1107 if (priv->mii_info->phyinfo->close) 996 phy_disconnect(priv->phydev);
1108 priv->mii_info->phyinfo->close(priv->mii_info); 997 priv->phydev = NULL;
1109
1110 kfree(priv->mii_info);
1111 998
1112 netif_stop_queue(dev); 999 netif_stop_queue(dev);
1113 1000
@@ -1343,7 +1230,7 @@ struct sk_buff * gfar_new_skb(struct net_device *dev, struct rxbd8 *bdp)
1343 while ((!skb) && timeout--) 1230 while ((!skb) && timeout--)
1344 skb = dev_alloc_skb(priv->rx_buffer_size + RXBUF_ALIGNMENT); 1231 skb = dev_alloc_skb(priv->rx_buffer_size + RXBUF_ALIGNMENT);
1345 1232
1346 if (skb == NULL) 1233 if (NULL == skb)
1347 return NULL; 1234 return NULL;
1348 1235
1349 /* We need the data buffer to be aligned properly. We will reserve 1236 /* We need the data buffer to be aligned properly. We will reserve
@@ -1490,7 +1377,7 @@ static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb,
1490 struct gfar_private *priv = netdev_priv(dev); 1377 struct gfar_private *priv = netdev_priv(dev);
1491 struct rxfcb *fcb = NULL; 1378 struct rxfcb *fcb = NULL;
1492 1379
1493 if (skb == NULL) { 1380 if (NULL == skb) {
1494 if (netif_msg_rx_err(priv)) 1381 if (netif_msg_rx_err(priv))
1495 printk(KERN_WARNING "%s: Missing skb!!.\n", dev->name); 1382 printk(KERN_WARNING "%s: Missing skb!!.\n", dev->name);
1496 priv->stats.rx_dropped++; 1383 priv->stats.rx_dropped++;
@@ -1718,131 +1605,9 @@ static irqreturn_t gfar_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1718 return IRQ_HANDLED; 1605 return IRQ_HANDLED;
1719} 1606}
1720 1607
1721static irqreturn_t phy_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1722{
1723 struct net_device *dev = (struct net_device *) dev_id;
1724 struct gfar_private *priv = netdev_priv(dev);
1725
1726 /* Clear the interrupt */
1727 mii_clear_phy_interrupt(priv->mii_info);
1728
1729 /* Disable PHY interrupts */
1730 mii_configure_phy_interrupt(priv->mii_info,
1731 MII_INTERRUPT_DISABLED);
1732
1733 /* Schedule the phy change */
1734 schedule_work(&priv->tq);
1735
1736 return IRQ_HANDLED;
1737}
1738
1739/* Scheduled by the phy_interrupt/timer to handle PHY changes */
1740static void gfar_phy_change(void *data)
1741{
1742 struct net_device *dev = (struct net_device *) data;
1743 struct gfar_private *priv = netdev_priv(dev);
1744 int result = 0;
1745
1746 /* Delay to give the PHY a chance to change the
1747 * register state */
1748 msleep(1);
1749
1750 /* Update the link, speed, duplex */
1751 result = priv->mii_info->phyinfo->read_status(priv->mii_info);
1752
1753 /* Adjust the known status as long as the link
1754 * isn't still coming up */
1755 if((0 == result) || (priv->mii_info->link == 0))
1756 adjust_link(dev);
1757
1758 /* Reenable interrupts, if needed */
1759 if (priv->einfo->board_flags & FSL_GIANFAR_BRD_HAS_PHY_INTR)
1760 mii_configure_phy_interrupt(priv->mii_info,
1761 MII_INTERRUPT_ENABLED);
1762}
1763
1764/* Called every so often on systems that don't interrupt
1765 * the core for PHY changes */
1766static void gfar_phy_timer(unsigned long data)
1767{
1768 struct net_device *dev = (struct net_device *) data;
1769 struct gfar_private *priv = netdev_priv(dev);
1770
1771 schedule_work(&priv->tq);
1772
1773 mod_timer(&priv->phy_info_timer, jiffies +
1774 GFAR_PHY_CHANGE_TIME * HZ);
1775}
1776
1777/* Keep trying aneg for some time
1778 * If, after GFAR_AN_TIMEOUT seconds, it has not
1779 * finished, we switch to forced.
1780 * Either way, once the process has completed, we either
1781 * request the interrupt, or switch the timer over to
1782 * using gfar_phy_timer to check status */
1783static void gfar_phy_startup_timer(unsigned long data)
1784{
1785 int result;
1786 static int secondary = GFAR_AN_TIMEOUT;
1787 struct gfar_mii_info *mii_info = (struct gfar_mii_info *)data;
1788 struct gfar_private *priv = netdev_priv(mii_info->dev);
1789
1790 /* Configure the Auto-negotiation */
1791 result = mii_info->phyinfo->config_aneg(mii_info);
1792
1793 /* If autonegotiation failed to start, and
1794 * we haven't timed out, reset the timer, and return */
1795 if (result && secondary--) {
1796 mod_timer(&priv->phy_info_timer, jiffies + HZ);
1797 return;
1798 } else if (result) {
1799 /* Couldn't start autonegotiation.
1800 * Try switching to forced */
1801 mii_info->autoneg = 0;
1802 result = mii_info->phyinfo->config_aneg(mii_info);
1803
1804 /* Forcing failed! Give up */
1805 if(result) {
1806 if (netif_msg_link(priv))
1807 printk(KERN_ERR "%s: Forcing failed!\n",
1808 mii_info->dev->name);
1809 return;
1810 }
1811 }
1812
1813 /* Kill the timer so it can be restarted */
1814 del_timer_sync(&priv->phy_info_timer);
1815
1816 /* Grab the PHY interrupt, if necessary/possible */
1817 if (priv->einfo->board_flags & FSL_GIANFAR_BRD_HAS_PHY_INTR) {
1818 if (request_irq(priv->einfo->interruptPHY,
1819 phy_interrupt,
1820 SA_SHIRQ,
1821 "phy_interrupt",
1822 mii_info->dev) < 0) {
1823 if (netif_msg_intr(priv))
1824 printk(KERN_ERR "%s: Can't get IRQ %d (PHY)\n",
1825 mii_info->dev->name,
1826 priv->einfo->interruptPHY);
1827 } else {
1828 mii_configure_phy_interrupt(priv->mii_info,
1829 MII_INTERRUPT_ENABLED);
1830 return;
1831 }
1832 }
1833
1834 /* Start the timer again, this time in order to
1835 * handle a change in status */
1836 init_timer(&priv->phy_info_timer);
1837 priv->phy_info_timer.function = &gfar_phy_timer;
1838 priv->phy_info_timer.data = (unsigned long) mii_info->dev;
1839 mod_timer(&priv->phy_info_timer, jiffies +
1840 GFAR_PHY_CHANGE_TIME * HZ);
1841}
1842
1843/* Called every time the controller might need to be made 1608/* Called every time the controller might need to be made
1844 * aware of new link state. The PHY code conveys this 1609 * aware of new link state. The PHY code conveys this
1845 * information through variables in the priv structure, and this 1610 * information through variables in the phydev structure, and this
1846 * function converts those variables into the appropriate 1611 * function converts those variables into the appropriate
1847 * register values, and can bring down the device if needed. 1612 * register values, and can bring down the device if needed.
1848 */ 1613 */
@@ -1850,84 +1615,68 @@ static void adjust_link(struct net_device *dev)
1850{ 1615{
1851 struct gfar_private *priv = netdev_priv(dev); 1616 struct gfar_private *priv = netdev_priv(dev);
1852 struct gfar *regs = priv->regs; 1617 struct gfar *regs = priv->regs;
1853 u32 tempval; 1618 unsigned long flags;
1854 struct gfar_mii_info *mii_info = priv->mii_info; 1619 struct phy_device *phydev = priv->phydev;
1620 int new_state = 0;
1621
1622 spin_lock_irqsave(&priv->lock, flags);
1623 if (phydev->link) {
1624 u32 tempval = gfar_read(&regs->maccfg2);
1855 1625
1856 if (mii_info->link) {
1857 /* Now we make sure that we can be in full duplex mode. 1626 /* Now we make sure that we can be in full duplex mode.
1858 * If not, we operate in half-duplex mode. */ 1627 * If not, we operate in half-duplex mode. */
1859 if (mii_info->duplex != priv->oldduplex) { 1628 if (phydev->duplex != priv->oldduplex) {
1860 if (!(mii_info->duplex)) { 1629 new_state = 1;
1861 tempval = gfar_read(&regs->maccfg2); 1630 if (!(phydev->duplex))
1862 tempval &= ~(MACCFG2_FULL_DUPLEX); 1631 tempval &= ~(MACCFG2_FULL_DUPLEX);
1863 gfar_write(&regs->maccfg2, tempval); 1632 else
1864
1865 if (netif_msg_link(priv))
1866 printk(KERN_INFO "%s: Half Duplex\n",
1867 dev->name);
1868 } else {
1869 tempval = gfar_read(&regs->maccfg2);
1870 tempval |= MACCFG2_FULL_DUPLEX; 1633 tempval |= MACCFG2_FULL_DUPLEX;
1871 gfar_write(&regs->maccfg2, tempval);
1872 1634
1873 if (netif_msg_link(priv)) 1635 priv->oldduplex = phydev->duplex;
1874 printk(KERN_INFO "%s: Full Duplex\n",
1875 dev->name);
1876 }
1877
1878 priv->oldduplex = mii_info->duplex;
1879 } 1636 }
1880 1637
1881 if (mii_info->speed != priv->oldspeed) { 1638 if (phydev->speed != priv->oldspeed) {
1882 switch (mii_info->speed) { 1639 new_state = 1;
1640 switch (phydev->speed) {
1883 case 1000: 1641 case 1000:
1884 tempval = gfar_read(&regs->maccfg2);
1885 tempval = 1642 tempval =
1886 ((tempval & ~(MACCFG2_IF)) | MACCFG2_GMII); 1643 ((tempval & ~(MACCFG2_IF)) | MACCFG2_GMII);
1887 gfar_write(&regs->maccfg2, tempval);
1888 break; 1644 break;
1889 case 100: 1645 case 100:
1890 case 10: 1646 case 10:
1891 tempval = gfar_read(&regs->maccfg2);
1892 tempval = 1647 tempval =
1893 ((tempval & ~(MACCFG2_IF)) | MACCFG2_MII); 1648 ((tempval & ~(MACCFG2_IF)) | MACCFG2_MII);
1894 gfar_write(&regs->maccfg2, tempval);
1895 break; 1649 break;
1896 default: 1650 default:
1897 if (netif_msg_link(priv)) 1651 if (netif_msg_link(priv))
1898 printk(KERN_WARNING 1652 printk(KERN_WARNING
1899 "%s: Ack! Speed (%d) is not 10/100/1000!\n", 1653 "%s: Ack! Speed (%d) is not 10/100/1000!\n",
1900 dev->name, mii_info->speed); 1654 dev->name, phydev->speed);
1901 break; 1655 break;
1902 } 1656 }
1903 1657
1904 if (netif_msg_link(priv)) 1658 priv->oldspeed = phydev->speed;
1905 printk(KERN_INFO "%s: Speed %dBT\n", dev->name,
1906 mii_info->speed);
1907
1908 priv->oldspeed = mii_info->speed;
1909 } 1659 }
1910 1660
1661 gfar_write(&regs->maccfg2, tempval);
1662
1911 if (!priv->oldlink) { 1663 if (!priv->oldlink) {
1912 if (netif_msg_link(priv)) 1664 new_state = 1;
1913 printk(KERN_INFO "%s: Link is up\n", dev->name);
1914 priv->oldlink = 1; 1665 priv->oldlink = 1;
1915 netif_carrier_on(dev);
1916 netif_schedule(dev); 1666 netif_schedule(dev);
1917 } 1667 }
1918 } else { 1668 } else if (priv->oldlink) {
1919 if (priv->oldlink) { 1669 new_state = 1;
1920 if (netif_msg_link(priv)) 1670 priv->oldlink = 0;
1921 printk(KERN_INFO "%s: Link is down\n", 1671 priv->oldspeed = 0;
1922 dev->name); 1672 priv->oldduplex = -1;
1923 priv->oldlink = 0;
1924 priv->oldspeed = 0;
1925 priv->oldduplex = -1;
1926 netif_carrier_off(dev);
1927 }
1928 } 1673 }
1929}
1930 1674
1675 if (new_state && netif_msg_link(priv))
1676 phy_print_status(phydev);
1677
1678 spin_unlock_irqrestore(&priv->lock, flags);
1679}
1931 1680
1932/* Update the hash table based on the current list of multicast 1681/* Update the hash table based on the current list of multicast
1933 * addresses we subscribe to. Also, change the promiscuity of 1682 * addresses we subscribe to. Also, change the promiscuity of
@@ -2122,12 +1871,23 @@ static struct device_driver gfar_driver = {
2122 1871
2123static int __init gfar_init(void) 1872static int __init gfar_init(void)
2124{ 1873{
2125 return driver_register(&gfar_driver); 1874 int err = gfar_mdio_init();
1875
1876 if (err)
1877 return err;
1878
1879 err = driver_register(&gfar_driver);
1880
1881 if (err)
1882 gfar_mdio_exit();
1883
1884 return err;
2126} 1885}
2127 1886
2128static void __exit gfar_exit(void) 1887static void __exit gfar_exit(void)
2129{ 1888{
2130 driver_unregister(&gfar_driver); 1889 driver_unregister(&gfar_driver);
1890 gfar_mdio_exit();
2131} 1891}
2132 1892
2133module_init(gfar_init); 1893module_init(gfar_init);
diff --git a/drivers/net/gianfar.h b/drivers/net/gianfar.h
index 28af087d9fbb..c77ca6c0d04a 100644
--- a/drivers/net/gianfar.h
+++ b/drivers/net/gianfar.h
@@ -17,7 +17,6 @@
17 * 17 *
18 * Still left to do: 18 * Still left to do:
19 * -Add support for module parameters 19 * -Add support for module parameters
20 * -Add support for ethtool -s
21 * -Add patch for ethtool phys id 20 * -Add patch for ethtool phys id
22 */ 21 */
23#ifndef __GIANFAR_H 22#ifndef __GIANFAR_H
@@ -37,7 +36,8 @@
37#include <linux/skbuff.h> 36#include <linux/skbuff.h>
38#include <linux/spinlock.h> 37#include <linux/spinlock.h>
39#include <linux/mm.h> 38#include <linux/mm.h>
40#include <linux/fsl_devices.h> 39#include <linux/mii.h>
40#include <linux/phy.h>
41 41
42#include <asm/io.h> 42#include <asm/io.h>
43#include <asm/irq.h> 43#include <asm/irq.h>
@@ -48,7 +48,8 @@
48#include <linux/workqueue.h> 48#include <linux/workqueue.h>
49#include <linux/ethtool.h> 49#include <linux/ethtool.h>
50#include <linux/netdevice.h> 50#include <linux/netdevice.h>
51#include "gianfar_phy.h" 51#include <linux/fsl_devices.h>
52#include "gianfar_mii.h"
52 53
53/* The maximum number of packets to be handled in one call of gfar_poll */ 54/* The maximum number of packets to be handled in one call of gfar_poll */
54#define GFAR_DEV_WEIGHT 64 55#define GFAR_DEV_WEIGHT 64
@@ -73,7 +74,7 @@
73#define PHY_INIT_TIMEOUT 100000 74#define PHY_INIT_TIMEOUT 100000
74#define GFAR_PHY_CHANGE_TIME 2 75#define GFAR_PHY_CHANGE_TIME 2
75 76
76#define DEVICE_NAME "%s: Gianfar Ethernet Controller Version 1.1, " 77#define DEVICE_NAME "%s: Gianfar Ethernet Controller Version 1.2, "
77#define DRV_NAME "gfar-enet" 78#define DRV_NAME "gfar-enet"
78extern const char gfar_driver_name[]; 79extern const char gfar_driver_name[];
79extern const char gfar_driver_version[]; 80extern const char gfar_driver_version[];
@@ -578,12 +579,7 @@ struct gfar {
578 u32 hafdup; /* 0x.50c - Half Duplex Register */ 579 u32 hafdup; /* 0x.50c - Half Duplex Register */
579 u32 maxfrm; /* 0x.510 - Maximum Frame Length Register */ 580 u32 maxfrm; /* 0x.510 - Maximum Frame Length Register */
580 u8 res18[12]; 581 u8 res18[12];
581 u32 miimcfg; /* 0x.520 - MII Management Configuration Register */ 582 u8 gfar_mii_regs[24]; /* See gianfar_phy.h */
582 u32 miimcom; /* 0x.524 - MII Management Command Register */
583 u32 miimadd; /* 0x.528 - MII Management Address Register */
584 u32 miimcon; /* 0x.52c - MII Management Control Register */
585 u32 miimstat; /* 0x.530 - MII Management Status Register */
586 u32 miimind; /* 0x.534 - MII Management Indicator Register */
587 u8 res19[4]; 583 u8 res19[4];
588 u32 ifstat; /* 0x.53c - Interface Status Register */ 584 u32 ifstat; /* 0x.53c - Interface Status Register */
589 u32 macstnaddr1; /* 0x.540 - Station Address Part 1 Register */ 585 u32 macstnaddr1; /* 0x.540 - Station Address Part 1 Register */
@@ -688,9 +684,6 @@ struct gfar_private {
688 struct gfar *regs; /* Pointer to the GFAR memory mapped Registers */ 684 struct gfar *regs; /* Pointer to the GFAR memory mapped Registers */
689 u32 *hash_regs[16]; 685 u32 *hash_regs[16];
690 int hash_width; 686 int hash_width;
691 struct gfar *phyregs;
692 struct work_struct tq;
693 struct timer_list phy_info_timer;
694 struct net_device_stats stats; /* linux network statistics */ 687 struct net_device_stats stats; /* linux network statistics */
695 struct gfar_extra_stats extra_stats; 688 struct gfar_extra_stats extra_stats;
696 spinlock_t lock; 689 spinlock_t lock;
@@ -710,7 +703,8 @@ struct gfar_private {
710 unsigned int interruptError; 703 unsigned int interruptError;
711 struct gianfar_platform_data *einfo; 704 struct gianfar_platform_data *einfo;
712 705
713 struct gfar_mii_info *mii_info; 706 struct phy_device *phydev;
707 struct mii_bus *mii_bus;
714 int oldspeed; 708 int oldspeed;
715 int oldduplex; 709 int oldduplex;
716 int oldlink; 710 int oldlink;
@@ -732,4 +726,12 @@ extern inline void gfar_write(volatile unsigned *addr, u32 val)
732 726
733extern struct ethtool_ops *gfar_op_array[]; 727extern struct ethtool_ops *gfar_op_array[];
734 728
729extern irqreturn_t gfar_receive(int irq, void *dev_id, struct pt_regs *regs);
730extern int startup_gfar(struct net_device *dev);
731extern void stop_gfar(struct net_device *dev);
732extern void gfar_halt(struct net_device *dev);
733extern void gfar_phy_test(struct mii_bus *bus, struct phy_device *phydev,
734 int enable, u32 regnum, u32 read);
735void gfar_setup_stashing(struct net_device *dev);
736
735#endif /* __GIANFAR_H */ 737#endif /* __GIANFAR_H */
diff --git a/drivers/net/gianfar_ethtool.c b/drivers/net/gianfar_ethtool.c
index a451de629197..68e3578e7613 100644
--- a/drivers/net/gianfar_ethtool.c
+++ b/drivers/net/gianfar_ethtool.c
@@ -39,17 +39,18 @@
39#include <asm/types.h> 39#include <asm/types.h>
40#include <asm/uaccess.h> 40#include <asm/uaccess.h>
41#include <linux/ethtool.h> 41#include <linux/ethtool.h>
42#include <linux/mii.h>
43#include <linux/phy.h>
42 44
43#include "gianfar.h" 45#include "gianfar.h"
44 46
45#define is_power_of_2(x) ((x) != 0 && (((x) & ((x) - 1)) == 0)) 47#define is_power_of_2(x) ((x) != 0 && (((x) & ((x) - 1)) == 0))
46 48
47extern int startup_gfar(struct net_device *dev);
48extern void stop_gfar(struct net_device *dev);
49extern void gfar_halt(struct net_device *dev);
50extern void gfar_start(struct net_device *dev); 49extern void gfar_start(struct net_device *dev);
51extern int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit); 50extern int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit);
52 51
52#define GFAR_MAX_COAL_USECS 0xffff
53#define GFAR_MAX_COAL_FRAMES 0xff
53static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy, 54static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy,
54 u64 * buf); 55 u64 * buf);
55static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf); 56static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf);
@@ -182,38 +183,32 @@ static void gfar_gdrvinfo(struct net_device *dev, struct
182 drvinfo->eedump_len = 0; 183 drvinfo->eedump_len = 0;
183} 184}
184 185
186
187static int gfar_ssettings(struct net_device *dev, struct ethtool_cmd *cmd)
188{
189 struct gfar_private *priv = netdev_priv(dev);
190 struct phy_device *phydev = priv->phydev;
191
192 if (NULL == phydev)
193 return -ENODEV;
194
195 return phy_ethtool_sset(phydev, cmd);
196}
197
198
185/* Return the current settings in the ethtool_cmd structure */ 199/* Return the current settings in the ethtool_cmd structure */
186static int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd) 200static int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd)
187{ 201{
188 struct gfar_private *priv = netdev_priv(dev); 202 struct gfar_private *priv = netdev_priv(dev);
189 uint gigabit_support = 203 struct phy_device *phydev = priv->phydev;
190 priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT ? 204
191 SUPPORTED_1000baseT_Full : 0; 205 if (NULL == phydev)
192 uint gigabit_advert = 206 return -ENODEV;
193 priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT ? 207
194 ADVERTISED_1000baseT_Full: 0;
195
196 cmd->supported = (SUPPORTED_10baseT_Half
197 | SUPPORTED_100baseT_Half
198 | SUPPORTED_100baseT_Full
199 | gigabit_support | SUPPORTED_Autoneg);
200
201 /* For now, we always advertise everything */
202 cmd->advertising = (ADVERTISED_10baseT_Half
203 | ADVERTISED_100baseT_Half
204 | ADVERTISED_100baseT_Full
205 | gigabit_advert | ADVERTISED_Autoneg);
206
207 cmd->speed = priv->mii_info->speed;
208 cmd->duplex = priv->mii_info->duplex;
209 cmd->port = PORT_MII;
210 cmd->phy_address = priv->mii_info->mii_id;
211 cmd->transceiver = XCVR_EXTERNAL;
212 cmd->autoneg = AUTONEG_ENABLE;
213 cmd->maxtxpkt = priv->txcount; 208 cmd->maxtxpkt = priv->txcount;
214 cmd->maxrxpkt = priv->rxcount; 209 cmd->maxrxpkt = priv->rxcount;
215 210
216 return 0; 211 return phy_ethtool_gset(phydev, cmd);
217} 212}
218 213
219/* Return the length of the register structure */ 214/* Return the length of the register structure */
@@ -241,14 +236,14 @@ static unsigned int gfar_usecs2ticks(struct gfar_private *priv, unsigned int use
241 unsigned int count; 236 unsigned int count;
242 237
243 /* The timer is different, depending on the interface speed */ 238 /* The timer is different, depending on the interface speed */
244 switch (priv->mii_info->speed) { 239 switch (priv->phydev->speed) {
245 case 1000: 240 case SPEED_1000:
246 count = GFAR_GBIT_TIME; 241 count = GFAR_GBIT_TIME;
247 break; 242 break;
248 case 100: 243 case SPEED_100:
249 count = GFAR_100_TIME; 244 count = GFAR_100_TIME;
250 break; 245 break;
251 case 10: 246 case SPEED_10:
252 default: 247 default:
253 count = GFAR_10_TIME; 248 count = GFAR_10_TIME;
254 break; 249 break;
@@ -265,14 +260,14 @@ static unsigned int gfar_ticks2usecs(struct gfar_private *priv, unsigned int tic
265 unsigned int count; 260 unsigned int count;
266 261
267 /* The timer is different, depending on the interface speed */ 262 /* The timer is different, depending on the interface speed */
268 switch (priv->mii_info->speed) { 263 switch (priv->phydev->speed) {
269 case 1000: 264 case SPEED_1000:
270 count = GFAR_GBIT_TIME; 265 count = GFAR_GBIT_TIME;
271 break; 266 break;
272 case 100: 267 case SPEED_100:
273 count = GFAR_100_TIME; 268 count = GFAR_100_TIME;
274 break; 269 break;
275 case 10: 270 case SPEED_10:
276 default: 271 default:
277 count = GFAR_10_TIME; 272 count = GFAR_10_TIME;
278 break; 273 break;
@@ -292,6 +287,9 @@ static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals
292 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE)) 287 if (!(priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE))
293 return -EOPNOTSUPP; 288 return -EOPNOTSUPP;
294 289
290 if (NULL == priv->phydev)
291 return -ENODEV;
292
295 cvals->rx_coalesce_usecs = gfar_ticks2usecs(priv, priv->rxtime); 293 cvals->rx_coalesce_usecs = gfar_ticks2usecs(priv, priv->rxtime);
296 cvals->rx_max_coalesced_frames = priv->rxcount; 294 cvals->rx_max_coalesced_frames = priv->rxcount;
297 295
@@ -348,6 +346,22 @@ static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals
348 else 346 else
349 priv->rxcoalescing = 1; 347 priv->rxcoalescing = 1;
350 348
349 if (NULL == priv->phydev)
350 return -ENODEV;
351
352 /* Check the bounds of the values */
353 if (cvals->rx_coalesce_usecs > GFAR_MAX_COAL_USECS) {
354 pr_info("Coalescing is limited to %d microseconds\n",
355 GFAR_MAX_COAL_USECS);
356 return -EINVAL;
357 }
358
359 if (cvals->rx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) {
360 pr_info("Coalescing is limited to %d frames\n",
361 GFAR_MAX_COAL_FRAMES);
362 return -EINVAL;
363 }
364
351 priv->rxtime = gfar_usecs2ticks(priv, cvals->rx_coalesce_usecs); 365 priv->rxtime = gfar_usecs2ticks(priv, cvals->rx_coalesce_usecs);
352 priv->rxcount = cvals->rx_max_coalesced_frames; 366 priv->rxcount = cvals->rx_max_coalesced_frames;
353 367
@@ -358,6 +372,19 @@ static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals
358 else 372 else
359 priv->txcoalescing = 1; 373 priv->txcoalescing = 1;
360 374
375 /* Check the bounds of the values */
376 if (cvals->tx_coalesce_usecs > GFAR_MAX_COAL_USECS) {
377 pr_info("Coalescing is limited to %d microseconds\n",
378 GFAR_MAX_COAL_USECS);
379 return -EINVAL;
380 }
381
382 if (cvals->tx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) {
383 pr_info("Coalescing is limited to %d frames\n",
384 GFAR_MAX_COAL_FRAMES);
385 return -EINVAL;
386 }
387
361 priv->txtime = gfar_usecs2ticks(priv, cvals->tx_coalesce_usecs); 388 priv->txtime = gfar_usecs2ticks(priv, cvals->tx_coalesce_usecs);
362 priv->txcount = cvals->tx_max_coalesced_frames; 389 priv->txcount = cvals->tx_max_coalesced_frames;
363 390
@@ -536,6 +563,7 @@ static void gfar_set_msglevel(struct net_device *dev, uint32_t data)
536 563
537struct ethtool_ops gfar_ethtool_ops = { 564struct ethtool_ops gfar_ethtool_ops = {
538 .get_settings = gfar_gsettings, 565 .get_settings = gfar_gsettings,
566 .set_settings = gfar_ssettings,
539 .get_drvinfo = gfar_gdrvinfo, 567 .get_drvinfo = gfar_gdrvinfo,
540 .get_regs_len = gfar_reglen, 568 .get_regs_len = gfar_reglen,
541 .get_regs = gfar_get_regs, 569 .get_regs = gfar_get_regs,
diff --git a/drivers/net/gianfar_mii.c b/drivers/net/gianfar_mii.c
new file mode 100644
index 000000000000..1eca1dbca7f1
--- /dev/null
+++ b/drivers/net/gianfar_mii.c
@@ -0,0 +1,219 @@
1/*
2 * drivers/net/gianfar_mii.c
3 *
4 * Gianfar Ethernet Driver -- MIIM bus implementation
5 * Provides Bus interface for MIIM regs
6 *
7 * Author: Andy Fleming
8 * Maintainer: Kumar Gala (kumar.gala@freescale.com)
9 *
10 * Copyright (c) 2002-2004 Freescale Semiconductor, Inc.
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 *
17 */
18
19#include <linux/config.h>
20#include <linux/kernel.h>
21#include <linux/sched.h>
22#include <linux/string.h>
23#include <linux/errno.h>
24#include <linux/unistd.h>
25#include <linux/slab.h>
26#include <linux/interrupt.h>
27#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/netdevice.h>
30#include <linux/etherdevice.h>
31#include <linux/skbuff.h>
32#include <linux/spinlock.h>
33#include <linux/mm.h>
34#include <linux/module.h>
35#include <linux/version.h>
36#include <asm/ocp.h>
37#include <linux/crc32.h>
38#include <linux/mii.h>
39#include <linux/phy.h>
40
41#include <asm/io.h>
42#include <asm/irq.h>
43#include <asm/uaccess.h>
44
45#include "gianfar.h"
46#include "gianfar_mii.h"
47
48/* Write value to the PHY at mii_id at register regnum,
49 * on the bus, waiting until the write is done before returning.
50 * All PHY configuration is done through the TSEC1 MIIM regs */
51int gfar_mdio_write(struct mii_bus *bus, int mii_id, int regnum, u16 value)
52{
53 struct gfar_mii *regs = bus->priv;
54
55 /* Set the PHY address and the register address we want to write */
56 gfar_write(&regs->miimadd, (mii_id << 8) | regnum);
57
58 /* Write out the value we want */
59 gfar_write(&regs->miimcon, value);
60
61 /* Wait for the transaction to finish */
62 while (gfar_read(&regs->miimind) & MIIMIND_BUSY)
63 cpu_relax();
64
65 return 0;
66}
67
68/* Read the bus for PHY at addr mii_id, register regnum, and
69 * return the value. Clears miimcom first. All PHY
70 * configuration has to be done through the TSEC1 MIIM regs */
71int gfar_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
72{
73 struct gfar_mii *regs = bus->priv;
74 u16 value;
75
76 /* Set the PHY address and the register address we want to read */
77 gfar_write(&regs->miimadd, (mii_id << 8) | regnum);
78
79 /* Clear miimcom, and then initiate a read */
80 gfar_write(&regs->miimcom, 0);
81 gfar_write(&regs->miimcom, MII_READ_COMMAND);
82
83 /* Wait for the transaction to finish */
84 while (gfar_read(&regs->miimind) & (MIIMIND_NOTVALID | MIIMIND_BUSY))
85 cpu_relax();
86
87 /* Grab the value of the register from miimstat */
88 value = gfar_read(&regs->miimstat);
89
90 return value;
91}
92
93
94/* Reset the MIIM registers, and wait for the bus to free */
95int gfar_mdio_reset(struct mii_bus *bus)
96{
97 struct gfar_mii *regs = bus->priv;
98 unsigned int timeout = PHY_INIT_TIMEOUT;
99
100 spin_lock_bh(&bus->mdio_lock);
101
102 /* Reset the management interface */
103 gfar_write(&regs->miimcfg, MIIMCFG_RESET);
104
105 /* Setup the MII Mgmt clock speed */
106 gfar_write(&regs->miimcfg, MIIMCFG_INIT_VALUE);
107
108 /* Wait until the bus is free */
109 while ((gfar_read(&regs->miimind) & MIIMIND_BUSY) &&
110 timeout--)
111 cpu_relax();
112
113 spin_unlock_bh(&bus->mdio_lock);
114
115 if(timeout <= 0) {
116 printk(KERN_ERR "%s: The MII Bus is stuck!\n",
117 bus->name);
118 return -EBUSY;
119 }
120
121 return 0;
122}
123
124
125int gfar_mdio_probe(struct device *dev)
126{
127 struct platform_device *pdev = to_platform_device(dev);
128 struct gianfar_mdio_data *pdata;
129 struct gfar_mii *regs;
130 struct mii_bus *new_bus;
131 int err = 0;
132
133 if (NULL == dev)
134 return -EINVAL;
135
136 new_bus = kmalloc(sizeof(struct mii_bus), GFP_KERNEL);
137
138 if (NULL == new_bus)
139 return -ENOMEM;
140
141 new_bus->name = "Gianfar MII Bus",
142 new_bus->read = &gfar_mdio_read,
143 new_bus->write = &gfar_mdio_write,
144 new_bus->reset = &gfar_mdio_reset,
145 new_bus->id = pdev->id;
146
147 pdata = (struct gianfar_mdio_data *)pdev->dev.platform_data;
148
149 if (NULL == pdata) {
150 printk(KERN_ERR "gfar mdio %d: Missing platform data!\n", pdev->id);
151 return -ENODEV;
152 }
153
154 /* Set the PHY base address */
155 regs = (struct gfar_mii *) ioremap(pdata->paddr,
156 sizeof (struct gfar_mii));
157
158 if (NULL == regs) {
159 err = -ENOMEM;
160 goto reg_map_fail;
161 }
162
163 new_bus->priv = regs;
164
165 new_bus->irq = pdata->irq;
166
167 new_bus->dev = dev;
168 dev_set_drvdata(dev, new_bus);
169
170 err = mdiobus_register(new_bus);
171
172 if (0 != err) {
173 printk (KERN_ERR "%s: Cannot register as MDIO bus\n",
174 new_bus->name);
175 goto bus_register_fail;
176 }
177
178 return 0;
179
180bus_register_fail:
181 iounmap((void *) regs);
182reg_map_fail:
183 kfree(new_bus);
184
185 return err;
186}
187
188
189int gfar_mdio_remove(struct device *dev)
190{
191 struct mii_bus *bus = dev_get_drvdata(dev);
192
193 mdiobus_unregister(bus);
194
195 dev_set_drvdata(dev, NULL);
196
197 iounmap((void *) (&bus->priv));
198 bus->priv = NULL;
199 kfree(bus);
200
201 return 0;
202}
203
204static struct device_driver gianfar_mdio_driver = {
205 .name = "fsl-gianfar_mdio",
206 .bus = &platform_bus_type,
207 .probe = gfar_mdio_probe,
208 .remove = gfar_mdio_remove,
209};
210
211int __init gfar_mdio_init(void)
212{
213 return driver_register(&gianfar_mdio_driver);
214}
215
216void __exit gfar_mdio_exit(void)
217{
218 driver_unregister(&gianfar_mdio_driver);
219}
diff --git a/drivers/net/gianfar_mii.h b/drivers/net/gianfar_mii.h
new file mode 100644
index 000000000000..56e5665d5c9b
--- /dev/null
+++ b/drivers/net/gianfar_mii.h
@@ -0,0 +1,45 @@
1/*
2 * drivers/net/gianfar_mii.h
3 *
4 * Gianfar Ethernet Driver -- MII Management Bus Implementation
5 * Driver for the MDIO bus controller in the Gianfar register space
6 *
7 * Author: Andy Fleming
8 * Maintainer: Kumar Gala (kumar.gala@freescale.com)
9 *
10 * Copyright (c) 2002-2004 Freescale Semiconductor, Inc.
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 *
17 */
18#ifndef __GIANFAR_MII_H
19#define __GIANFAR_MII_H
20
21#define MIIMIND_BUSY 0x00000001
22#define MIIMIND_NOTVALID 0x00000004
23
24#define MII_READ_COMMAND 0x00000001
25
26#define GFAR_SUPPORTED (SUPPORTED_10baseT_Half \
27 | SUPPORTED_100baseT_Half \
28 | SUPPORTED_100baseT_Full \
29 | SUPPORTED_Autoneg \
30 | SUPPORTED_MII)
31
32struct gfar_mii {
33 u32 miimcfg; /* 0x.520 - MII Management Config Register */
34 u32 miimcom; /* 0x.524 - MII Management Command Register */
35 u32 miimadd; /* 0x.528 - MII Management Address Register */
36 u32 miimcon; /* 0x.52c - MII Management Control Register */
37 u32 miimstat; /* 0x.530 - MII Management Status Register */
38 u32 miimind; /* 0x.534 - MII Management Indicator Register */
39};
40
41int gfar_mdio_read(struct mii_bus *bus, int mii_id, int regnum);
42int gfar_mdio_write(struct mii_bus *bus, int mii_id, int regnum, u16 value);
43int __init gfar_mdio_init(void);
44void __exit gfar_mdio_exit(void);
45#endif /* GIANFAR_PHY_H */
diff --git a/drivers/net/gianfar_phy.c b/drivers/net/gianfar_phy.c
deleted file mode 100644
index 7c965f268a82..000000000000
--- a/drivers/net/gianfar_phy.c
+++ /dev/null
@@ -1,661 +0,0 @@
1/*
2 * drivers/net/gianfar_phy.c
3 *
4 * Gianfar Ethernet Driver -- PHY handling
5 * Driver for FEC on MPC8540 and TSEC on MPC8540/MPC8560
6 * Based on 8260_io/fcc_enet.c
7 *
8 * Author: Andy Fleming
9 * Maintainer: Kumar Gala (kumar.gala@freescale.com)
10 *
11 * Copyright (c) 2002-2004 Freescale Semiconductor, Inc.
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 *
18 */
19
20#include <linux/config.h>
21#include <linux/kernel.h>
22#include <linux/sched.h>
23#include <linux/string.h>
24#include <linux/errno.h>
25#include <linux/slab.h>
26#include <linux/interrupt.h>
27#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/netdevice.h>
30#include <linux/etherdevice.h>
31#include <linux/skbuff.h>
32#include <linux/spinlock.h>
33#include <linux/mm.h>
34
35#include <asm/io.h>
36#include <asm/irq.h>
37#include <asm/uaccess.h>
38#include <linux/module.h>
39#include <linux/version.h>
40#include <linux/crc32.h>
41#include <linux/mii.h>
42
43#include "gianfar.h"
44#include "gianfar_phy.h"
45
46static void config_genmii_advert(struct gfar_mii_info *mii_info);
47static void genmii_setup_forced(struct gfar_mii_info *mii_info);
48static void genmii_restart_aneg(struct gfar_mii_info *mii_info);
49static int gbit_config_aneg(struct gfar_mii_info *mii_info);
50static int genmii_config_aneg(struct gfar_mii_info *mii_info);
51static int genmii_update_link(struct gfar_mii_info *mii_info);
52static int genmii_read_status(struct gfar_mii_info *mii_info);
53u16 phy_read(struct gfar_mii_info *mii_info, u16 regnum);
54void phy_write(struct gfar_mii_info *mii_info, u16 regnum, u16 val);
55
56/* Write value to the PHY for this device to the register at regnum, */
57/* waiting until the write is done before it returns. All PHY */
58/* configuration has to be done through the TSEC1 MIIM regs */
59void write_phy_reg(struct net_device *dev, int mii_id, int regnum, int value)
60{
61 struct gfar_private *priv = netdev_priv(dev);
62 struct gfar *regbase = priv->phyregs;
63
64 /* Set the PHY address and the register address we want to write */
65 gfar_write(&regbase->miimadd, (mii_id << 8) | regnum);
66
67 /* Write out the value we want */
68 gfar_write(&regbase->miimcon, value);
69
70 /* Wait for the transaction to finish */
71 while (gfar_read(&regbase->miimind) & MIIMIND_BUSY)
72 cpu_relax();
73}
74
75/* Reads from register regnum in the PHY for device dev, */
76/* returning the value. Clears miimcom first. All PHY */
77/* configuration has to be done through the TSEC1 MIIM regs */
78int read_phy_reg(struct net_device *dev, int mii_id, int regnum)
79{
80 struct gfar_private *priv = netdev_priv(dev);
81 struct gfar *regbase = priv->phyregs;
82 u16 value;
83
84 /* Set the PHY address and the register address we want to read */
85 gfar_write(&regbase->miimadd, (mii_id << 8) | regnum);
86
87 /* Clear miimcom, and then initiate a read */
88 gfar_write(&regbase->miimcom, 0);
89 gfar_write(&regbase->miimcom, MII_READ_COMMAND);
90
91 /* Wait for the transaction to finish */
92 while (gfar_read(&regbase->miimind) & (MIIMIND_NOTVALID | MIIMIND_BUSY))
93 cpu_relax();
94
95 /* Grab the value of the register from miimstat */
96 value = gfar_read(&regbase->miimstat);
97
98 return value;
99}
100
101void mii_clear_phy_interrupt(struct gfar_mii_info *mii_info)
102{
103 if(mii_info->phyinfo->ack_interrupt)
104 mii_info->phyinfo->ack_interrupt(mii_info);
105}
106
107
108void mii_configure_phy_interrupt(struct gfar_mii_info *mii_info, u32 interrupts)
109{
110 mii_info->interrupts = interrupts;
111 if(mii_info->phyinfo->config_intr)
112 mii_info->phyinfo->config_intr(mii_info);
113}
114
115
116/* Writes MII_ADVERTISE with the appropriate values, after
117 * sanitizing advertise to make sure only supported features
118 * are advertised
119 */
120static void config_genmii_advert(struct gfar_mii_info *mii_info)
121{
122 u32 advertise;
123 u16 adv;
124
125 /* Only allow advertising what this PHY supports */
126 mii_info->advertising &= mii_info->phyinfo->features;
127 advertise = mii_info->advertising;
128
129 /* Setup standard advertisement */
130 adv = phy_read(mii_info, MII_ADVERTISE);
131 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4);
132 if (advertise & ADVERTISED_10baseT_Half)
133 adv |= ADVERTISE_10HALF;
134 if (advertise & ADVERTISED_10baseT_Full)
135 adv |= ADVERTISE_10FULL;
136 if (advertise & ADVERTISED_100baseT_Half)
137 adv |= ADVERTISE_100HALF;
138 if (advertise & ADVERTISED_100baseT_Full)
139 adv |= ADVERTISE_100FULL;
140 phy_write(mii_info, MII_ADVERTISE, adv);
141}
142
143static void genmii_setup_forced(struct gfar_mii_info *mii_info)
144{
145 u16 ctrl;
146 u32 features = mii_info->phyinfo->features;
147
148 ctrl = phy_read(mii_info, MII_BMCR);
149
150 ctrl &= ~(BMCR_FULLDPLX|BMCR_SPEED100|BMCR_SPEED1000|BMCR_ANENABLE);
151 ctrl |= BMCR_RESET;
152
153 switch(mii_info->speed) {
154 case SPEED_1000:
155 if(features & (SUPPORTED_1000baseT_Half
156 | SUPPORTED_1000baseT_Full)) {
157 ctrl |= BMCR_SPEED1000;
158 break;
159 }
160 mii_info->speed = SPEED_100;
161 case SPEED_100:
162 if (features & (SUPPORTED_100baseT_Half
163 | SUPPORTED_100baseT_Full)) {
164 ctrl |= BMCR_SPEED100;
165 break;
166 }
167 mii_info->speed = SPEED_10;
168 case SPEED_10:
169 if (features & (SUPPORTED_10baseT_Half
170 | SUPPORTED_10baseT_Full))
171 break;
172 default: /* Unsupported speed! */
173 printk(KERN_ERR "%s: Bad speed!\n",
174 mii_info->dev->name);
175 break;
176 }
177
178 phy_write(mii_info, MII_BMCR, ctrl);
179}
180
181
182/* Enable and Restart Autonegotiation */
183static void genmii_restart_aneg(struct gfar_mii_info *mii_info)
184{
185 u16 ctl;
186
187 ctl = phy_read(mii_info, MII_BMCR);
188 ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
189 phy_write(mii_info, MII_BMCR, ctl);
190}
191
192
193static int gbit_config_aneg(struct gfar_mii_info *mii_info)
194{
195 u16 adv;
196 u32 advertise;
197
198 if(mii_info->autoneg) {
199 /* Configure the ADVERTISE register */
200 config_genmii_advert(mii_info);
201 advertise = mii_info->advertising;
202
203 adv = phy_read(mii_info, MII_1000BASETCONTROL);
204 adv &= ~(MII_1000BASETCONTROL_FULLDUPLEXCAP |
205 MII_1000BASETCONTROL_HALFDUPLEXCAP);
206 if (advertise & SUPPORTED_1000baseT_Half)
207 adv |= MII_1000BASETCONTROL_HALFDUPLEXCAP;
208 if (advertise & SUPPORTED_1000baseT_Full)
209 adv |= MII_1000BASETCONTROL_FULLDUPLEXCAP;
210 phy_write(mii_info, MII_1000BASETCONTROL, adv);
211
212 /* Start/Restart aneg */
213 genmii_restart_aneg(mii_info);
214 } else
215 genmii_setup_forced(mii_info);
216
217 return 0;
218}
219
220static int marvell_config_aneg(struct gfar_mii_info *mii_info)
221{
222 /* The Marvell PHY has an errata which requires
223 * that certain registers get written in order
224 * to restart autonegotiation */
225 phy_write(mii_info, MII_BMCR, BMCR_RESET);
226
227 phy_write(mii_info, 0x1d, 0x1f);
228 phy_write(mii_info, 0x1e, 0x200c);
229 phy_write(mii_info, 0x1d, 0x5);
230 phy_write(mii_info, 0x1e, 0);
231 phy_write(mii_info, 0x1e, 0x100);
232
233 gbit_config_aneg(mii_info);
234
235 return 0;
236}
237static int genmii_config_aneg(struct gfar_mii_info *mii_info)
238{
239 if (mii_info->autoneg) {
240 config_genmii_advert(mii_info);
241 genmii_restart_aneg(mii_info);
242 } else
243 genmii_setup_forced(mii_info);
244
245 return 0;
246}
247
248
249static int genmii_update_link(struct gfar_mii_info *mii_info)
250{
251 u16 status;
252
253 /* Do a fake read */
254 phy_read(mii_info, MII_BMSR);
255
256 /* Read link and autonegotiation status */
257 status = phy_read(mii_info, MII_BMSR);
258 if ((status & BMSR_LSTATUS) == 0)
259 mii_info->link = 0;
260 else
261 mii_info->link = 1;
262
263 /* If we are autonegotiating, and not done,
264 * return an error */
265 if (mii_info->autoneg && !(status & BMSR_ANEGCOMPLETE))
266 return -EAGAIN;
267
268 return 0;
269}
270
271static int genmii_read_status(struct gfar_mii_info *mii_info)
272{
273 u16 status;
274 int err;
275
276 /* Update the link, but return if there
277 * was an error */
278 err = genmii_update_link(mii_info);
279 if (err)
280 return err;
281
282 if (mii_info->autoneg) {
283 status = phy_read(mii_info, MII_LPA);
284
285 if (status & (LPA_10FULL | LPA_100FULL))
286 mii_info->duplex = DUPLEX_FULL;
287 else
288 mii_info->duplex = DUPLEX_HALF;
289 if (status & (LPA_100FULL | LPA_100HALF))
290 mii_info->speed = SPEED_100;
291 else
292 mii_info->speed = SPEED_10;
293 mii_info->pause = 0;
294 }
295 /* On non-aneg, we assume what we put in BMCR is the speed,
296 * though magic-aneg shouldn't prevent this case from occurring
297 */
298
299 return 0;
300}
301static int marvell_read_status(struct gfar_mii_info *mii_info)
302{
303 u16 status;
304 int err;
305
306 /* Update the link, but return if there
307 * was an error */
308 err = genmii_update_link(mii_info);
309 if (err)
310 return err;
311
312 /* If the link is up, read the speed and duplex */
313 /* If we aren't autonegotiating, assume speeds
314 * are as set */
315 if (mii_info->autoneg && mii_info->link) {
316 int speed;
317 status = phy_read(mii_info, MII_M1011_PHY_SPEC_STATUS);
318
319#if 0
320 /* If speed and duplex aren't resolved,
321 * return an error. Isn't this handled
322 * by checking aneg?
323 */
324 if ((status & MII_M1011_PHY_SPEC_STATUS_RESOLVED) == 0)
325 return -EAGAIN;
326#endif
327
328 /* Get the duplexity */
329 if (status & MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX)
330 mii_info->duplex = DUPLEX_FULL;
331 else
332 mii_info->duplex = DUPLEX_HALF;
333
334 /* Get the speed */
335 speed = status & MII_M1011_PHY_SPEC_STATUS_SPD_MASK;
336 switch(speed) {
337 case MII_M1011_PHY_SPEC_STATUS_1000:
338 mii_info->speed = SPEED_1000;
339 break;
340 case MII_M1011_PHY_SPEC_STATUS_100:
341 mii_info->speed = SPEED_100;
342 break;
343 default:
344 mii_info->speed = SPEED_10;
345 break;
346 }
347 mii_info->pause = 0;
348 }
349
350 return 0;
351}
352
353
354static int cis820x_read_status(struct gfar_mii_info *mii_info)
355{
356 u16 status;
357 int err;
358
359 /* Update the link, but return if there
360 * was an error */
361 err = genmii_update_link(mii_info);
362 if (err)
363 return err;
364
365 /* If the link is up, read the speed and duplex */
366 /* If we aren't autonegotiating, assume speeds
367 * are as set */
368 if (mii_info->autoneg && mii_info->link) {
369 int speed;
370
371 status = phy_read(mii_info, MII_CIS8201_AUX_CONSTAT);
372 if (status & MII_CIS8201_AUXCONSTAT_DUPLEX)
373 mii_info->duplex = DUPLEX_FULL;
374 else
375 mii_info->duplex = DUPLEX_HALF;
376
377 speed = status & MII_CIS8201_AUXCONSTAT_SPEED;
378
379 switch (speed) {
380 case MII_CIS8201_AUXCONSTAT_GBIT:
381 mii_info->speed = SPEED_1000;
382 break;
383 case MII_CIS8201_AUXCONSTAT_100:
384 mii_info->speed = SPEED_100;
385 break;
386 default:
387 mii_info->speed = SPEED_10;
388 break;
389 }
390 }
391
392 return 0;
393}
394
395static int marvell_ack_interrupt(struct gfar_mii_info *mii_info)
396{
397 /* Clear the interrupts by reading the reg */
398 phy_read(mii_info, MII_M1011_IEVENT);
399
400 return 0;
401}
402
403static int marvell_config_intr(struct gfar_mii_info *mii_info)
404{
405 if(mii_info->interrupts == MII_INTERRUPT_ENABLED)
406 phy_write(mii_info, MII_M1011_IMASK, MII_M1011_IMASK_INIT);
407 else
408 phy_write(mii_info, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR);
409
410 return 0;
411}
412
413static int cis820x_init(struct gfar_mii_info *mii_info)
414{
415 phy_write(mii_info, MII_CIS8201_AUX_CONSTAT,
416 MII_CIS8201_AUXCONSTAT_INIT);
417 phy_write(mii_info, MII_CIS8201_EXT_CON1,
418 MII_CIS8201_EXTCON1_INIT);
419
420 return 0;
421}
422
423static int cis820x_ack_interrupt(struct gfar_mii_info *mii_info)
424{
425 phy_read(mii_info, MII_CIS8201_ISTAT);
426
427 return 0;
428}
429
430static int cis820x_config_intr(struct gfar_mii_info *mii_info)
431{
432 if(mii_info->interrupts == MII_INTERRUPT_ENABLED)
433 phy_write(mii_info, MII_CIS8201_IMASK, MII_CIS8201_IMASK_MASK);
434 else
435 phy_write(mii_info, MII_CIS8201_IMASK, 0);
436
437 return 0;
438}
439
440#define DM9161_DELAY 10
441
442static int dm9161_read_status(struct gfar_mii_info *mii_info)
443{
444 u16 status;
445 int err;
446
447 /* Update the link, but return if there
448 * was an error */
449 err = genmii_update_link(mii_info);
450 if (err)
451 return err;
452
453 /* If the link is up, read the speed and duplex */
454 /* If we aren't autonegotiating, assume speeds
455 * are as set */
456 if (mii_info->autoneg && mii_info->link) {
457 status = phy_read(mii_info, MII_DM9161_SCSR);
458 if (status & (MII_DM9161_SCSR_100F | MII_DM9161_SCSR_100H))
459 mii_info->speed = SPEED_100;
460 else
461 mii_info->speed = SPEED_10;
462
463 if (status & (MII_DM9161_SCSR_100F | MII_DM9161_SCSR_10F))
464 mii_info->duplex = DUPLEX_FULL;
465 else
466 mii_info->duplex = DUPLEX_HALF;
467 }
468
469 return 0;
470}
471
472
473static int dm9161_config_aneg(struct gfar_mii_info *mii_info)
474{
475 struct dm9161_private *priv = mii_info->priv;
476
477 if(0 == priv->resetdone)
478 return -EAGAIN;
479
480 return 0;
481}
482
483static void dm9161_timer(unsigned long data)
484{
485 struct gfar_mii_info *mii_info = (struct gfar_mii_info *)data;
486 struct dm9161_private *priv = mii_info->priv;
487 u16 status = phy_read(mii_info, MII_BMSR);
488
489 if (status & BMSR_ANEGCOMPLETE) {
490 priv->resetdone = 1;
491 } else
492 mod_timer(&priv->timer, jiffies + DM9161_DELAY * HZ);
493}
494
495static int dm9161_init(struct gfar_mii_info *mii_info)
496{
497 struct dm9161_private *priv;
498
499 /* Allocate the private data structure */
500 priv = kmalloc(sizeof(struct dm9161_private), GFP_KERNEL);
501
502 if (NULL == priv)
503 return -ENOMEM;
504
505 mii_info->priv = priv;
506
507 /* Reset is not done yet */
508 priv->resetdone = 0;
509
510 /* Isolate the PHY */
511 phy_write(mii_info, MII_BMCR, BMCR_ISOLATE);
512
513 /* Do not bypass the scrambler/descrambler */
514 phy_write(mii_info, MII_DM9161_SCR, MII_DM9161_SCR_INIT);
515
516 /* Clear 10BTCSR to default */
517 phy_write(mii_info, MII_DM9161_10BTCSR, MII_DM9161_10BTCSR_INIT);
518
519 /* Reconnect the PHY, and enable Autonegotiation */
520 phy_write(mii_info, MII_BMCR, BMCR_ANENABLE);
521
522 /* Start a timer for DM9161_DELAY seconds to wait
523 * for the PHY to be ready */
524 init_timer(&priv->timer);
525 priv->timer.function = &dm9161_timer;
526 priv->timer.data = (unsigned long) mii_info;
527 mod_timer(&priv->timer, jiffies + DM9161_DELAY * HZ);
528
529 return 0;
530}
531
532static void dm9161_close(struct gfar_mii_info *mii_info)
533{
534 struct dm9161_private *priv = mii_info->priv;
535
536 del_timer_sync(&priv->timer);
537 kfree(priv);
538}
539
540#if 0
541static int dm9161_ack_interrupt(struct gfar_mii_info *mii_info)
542{
543 phy_read(mii_info, MII_DM9161_INTR);
544
545 return 0;
546}
547#endif
548
549/* Cicada 820x */
550static struct phy_info phy_info_cis820x = {
551 0x000fc440,
552 "Cicada Cis8204",
553 0x000fffc0,
554 .features = MII_GBIT_FEATURES,
555 .init = &cis820x_init,
556 .config_aneg = &gbit_config_aneg,
557 .read_status = &cis820x_read_status,
558 .ack_interrupt = &cis820x_ack_interrupt,
559 .config_intr = &cis820x_config_intr,
560};
561
562static struct phy_info phy_info_dm9161 = {
563 .phy_id = 0x0181b880,
564 .name = "Davicom DM9161E",
565 .phy_id_mask = 0x0ffffff0,
566 .init = dm9161_init,
567 .config_aneg = dm9161_config_aneg,
568 .read_status = dm9161_read_status,
569 .close = dm9161_close,
570};
571
572static struct phy_info phy_info_marvell = {
573 .phy_id = 0x01410c00,
574 .phy_id_mask = 0xffffff00,
575 .name = "Marvell 88E1101/88E1111",
576 .features = MII_GBIT_FEATURES,
577 .config_aneg = &marvell_config_aneg,
578 .read_status = &marvell_read_status,
579 .ack_interrupt = &marvell_ack_interrupt,
580 .config_intr = &marvell_config_intr,
581};
582
583static struct phy_info phy_info_genmii= {
584 .phy_id = 0x00000000,
585 .phy_id_mask = 0x00000000,
586 .name = "Generic MII",
587 .features = MII_BASIC_FEATURES,
588 .config_aneg = genmii_config_aneg,
589 .read_status = genmii_read_status,
590};
591
592static struct phy_info *phy_info[] = {
593 &phy_info_cis820x,
594 &phy_info_marvell,
595 &phy_info_dm9161,
596 &phy_info_genmii,
597 NULL
598};
599
600u16 phy_read(struct gfar_mii_info *mii_info, u16 regnum)
601{
602 u16 retval;
603 unsigned long flags;
604
605 spin_lock_irqsave(&mii_info->mdio_lock, flags);
606 retval = mii_info->mdio_read(mii_info->dev, mii_info->mii_id, regnum);
607 spin_unlock_irqrestore(&mii_info->mdio_lock, flags);
608
609 return retval;
610}
611
612void phy_write(struct gfar_mii_info *mii_info, u16 regnum, u16 val)
613{
614 unsigned long flags;
615
616 spin_lock_irqsave(&mii_info->mdio_lock, flags);
617 mii_info->mdio_write(mii_info->dev,
618 mii_info->mii_id,
619 regnum, val);
620 spin_unlock_irqrestore(&mii_info->mdio_lock, flags);
621}
622
623/* Use the PHY ID registers to determine what type of PHY is attached
624 * to device dev. return a struct phy_info structure describing that PHY
625 */
626struct phy_info * get_phy_info(struct gfar_mii_info *mii_info)
627{
628 u16 phy_reg;
629 u32 phy_ID;
630 int i;
631 struct phy_info *theInfo = NULL;
632 struct net_device *dev = mii_info->dev;
633
634 /* Grab the bits from PHYIR1, and put them in the upper half */
635 phy_reg = phy_read(mii_info, MII_PHYSID1);
636 phy_ID = (phy_reg & 0xffff) << 16;
637
638 /* Grab the bits from PHYIR2, and put them in the lower half */
639 phy_reg = phy_read(mii_info, MII_PHYSID2);
640 phy_ID |= (phy_reg & 0xffff);
641
642 /* loop through all the known PHY types, and find one that */
643 /* matches the ID we read from the PHY. */
644 for (i = 0; phy_info[i]; i++)
645 if (phy_info[i]->phy_id ==
646 (phy_ID & phy_info[i]->phy_id_mask)) {
647 theInfo = phy_info[i];
648 break;
649 }
650
651 /* This shouldn't happen, as we have generic PHY support */
652 if (theInfo == NULL) {
653 printk("%s: PHY id %x is not supported!\n", dev->name, phy_ID);
654 return NULL;
655 } else {
656 printk("%s: PHY is %s (%x)\n", dev->name, theInfo->name,
657 phy_ID);
658 }
659
660 return theInfo;
661}
diff --git a/drivers/net/gianfar_phy.h b/drivers/net/gianfar_phy.h
deleted file mode 100644
index 1e9b3abf1e6d..000000000000
--- a/drivers/net/gianfar_phy.h
+++ /dev/null
@@ -1,213 +0,0 @@
1/*
2 * drivers/net/gianfar_phy.h
3 *
4 * Gianfar Ethernet Driver -- PHY handling
5 * Driver for FEC on MPC8540 and TSEC on MPC8540/MPC8560
6 * Based on 8260_io/fcc_enet.c
7 *
8 * Author: Andy Fleming
9 * Maintainer: Kumar Gala (kumar.gala@freescale.com)
10 *
11 * Copyright (c) 2002-2004 Freescale Semiconductor, Inc.
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 *
18 */
19#ifndef __GIANFAR_PHY_H
20#define __GIANFAR_PHY_H
21
22#define MII_end ((u32)-2)
23#define MII_read ((u32)-1)
24
25#define MIIMIND_BUSY 0x00000001
26#define MIIMIND_NOTVALID 0x00000004
27
28#define GFAR_AN_TIMEOUT 2000
29
30/* 1000BT control (Marvell & BCM54xx at least) */
31#define MII_1000BASETCONTROL 0x09
32#define MII_1000BASETCONTROL_FULLDUPLEXCAP 0x0200
33#define MII_1000BASETCONTROL_HALFDUPLEXCAP 0x0100
34
35/* Cicada Extended Control Register 1 */
36#define MII_CIS8201_EXT_CON1 0x17
37#define MII_CIS8201_EXTCON1_INIT 0x0000
38
39/* Cicada Interrupt Mask Register */
40#define MII_CIS8201_IMASK 0x19
41#define MII_CIS8201_IMASK_IEN 0x8000
42#define MII_CIS8201_IMASK_SPEED 0x4000
43#define MII_CIS8201_IMASK_LINK 0x2000
44#define MII_CIS8201_IMASK_DUPLEX 0x1000
45#define MII_CIS8201_IMASK_MASK 0xf000
46
47/* Cicada Interrupt Status Register */
48#define MII_CIS8201_ISTAT 0x1a
49#define MII_CIS8201_ISTAT_STATUS 0x8000
50#define MII_CIS8201_ISTAT_SPEED 0x4000
51#define MII_CIS8201_ISTAT_LINK 0x2000
52#define MII_CIS8201_ISTAT_DUPLEX 0x1000
53
54/* Cicada Auxiliary Control/Status Register */
55#define MII_CIS8201_AUX_CONSTAT 0x1c
56#define MII_CIS8201_AUXCONSTAT_INIT 0x0004
57#define MII_CIS8201_AUXCONSTAT_DUPLEX 0x0020
58#define MII_CIS8201_AUXCONSTAT_SPEED 0x0018
59#define MII_CIS8201_AUXCONSTAT_GBIT 0x0010
60#define MII_CIS8201_AUXCONSTAT_100 0x0008
61
62/* 88E1011 PHY Status Register */
63#define MII_M1011_PHY_SPEC_STATUS 0x11
64#define MII_M1011_PHY_SPEC_STATUS_1000 0x8000
65#define MII_M1011_PHY_SPEC_STATUS_100 0x4000
66#define MII_M1011_PHY_SPEC_STATUS_SPD_MASK 0xc000
67#define MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX 0x2000
68#define MII_M1011_PHY_SPEC_STATUS_RESOLVED 0x0800
69#define MII_M1011_PHY_SPEC_STATUS_LINK 0x0400
70
71#define MII_M1011_IEVENT 0x13
72#define MII_M1011_IEVENT_CLEAR 0x0000
73
74#define MII_M1011_IMASK 0x12
75#define MII_M1011_IMASK_INIT 0x6400
76#define MII_M1011_IMASK_CLEAR 0x0000
77
78#define MII_DM9161_SCR 0x10
79#define MII_DM9161_SCR_INIT 0x0610
80
81/* DM9161 Specified Configuration and Status Register */
82#define MII_DM9161_SCSR 0x11
83#define MII_DM9161_SCSR_100F 0x8000
84#define MII_DM9161_SCSR_100H 0x4000
85#define MII_DM9161_SCSR_10F 0x2000
86#define MII_DM9161_SCSR_10H 0x1000
87
88/* DM9161 Interrupt Register */
89#define MII_DM9161_INTR 0x15
90#define MII_DM9161_INTR_PEND 0x8000
91#define MII_DM9161_INTR_DPLX_MASK 0x0800
92#define MII_DM9161_INTR_SPD_MASK 0x0400
93#define MII_DM9161_INTR_LINK_MASK 0x0200
94#define MII_DM9161_INTR_MASK 0x0100
95#define MII_DM9161_INTR_DPLX_CHANGE 0x0010
96#define MII_DM9161_INTR_SPD_CHANGE 0x0008
97#define MII_DM9161_INTR_LINK_CHANGE 0x0004
98#define MII_DM9161_INTR_INIT 0x0000
99#define MII_DM9161_INTR_STOP \
100(MII_DM9161_INTR_DPLX_MASK | MII_DM9161_INTR_SPD_MASK \
101 | MII_DM9161_INTR_LINK_MASK | MII_DM9161_INTR_MASK)
102
103/* DM9161 10BT Configuration/Status */
104#define MII_DM9161_10BTCSR 0x12
105#define MII_DM9161_10BTCSR_INIT 0x7800
106
107#define MII_BASIC_FEATURES (SUPPORTED_10baseT_Half | \
108 SUPPORTED_10baseT_Full | \
109 SUPPORTED_100baseT_Half | \
110 SUPPORTED_100baseT_Full | \
111 SUPPORTED_Autoneg | \
112 SUPPORTED_TP | \
113 SUPPORTED_MII)
114
115#define MII_GBIT_FEATURES (MII_BASIC_FEATURES | \
116 SUPPORTED_1000baseT_Half | \
117 SUPPORTED_1000baseT_Full)
118
119#define MII_READ_COMMAND 0x00000001
120
121#define MII_INTERRUPT_DISABLED 0x0
122#define MII_INTERRUPT_ENABLED 0x1
123/* Taken from mii_if_info and sungem_phy.h */
124struct gfar_mii_info {
125 /* Information about the PHY type */
126 /* And management functions */
127 struct phy_info *phyinfo;
128
129 /* forced speed & duplex (no autoneg)
130 * partner speed & duplex & pause (autoneg)
131 */
132 int speed;
133 int duplex;
134 int pause;
135
136 /* The most recently read link state */
137 int link;
138
139 /* Enabled Interrupts */
140 u32 interrupts;
141
142 u32 advertising;
143 int autoneg;
144 int mii_id;
145
146 /* private data pointer */
147 /* For use by PHYs to maintain extra state */
148 void *priv;
149
150 /* Provided by host chip */
151 struct net_device *dev;
152
153 /* A lock to ensure that only one thing can read/write
154 * the MDIO bus at a time */
155 spinlock_t mdio_lock;
156
157 /* Provided by ethernet driver */
158 int (*mdio_read) (struct net_device *dev, int mii_id, int reg);
159 void (*mdio_write) (struct net_device *dev, int mii_id, int reg, int val);
160};
161
162/* struct phy_info: a structure which defines attributes for a PHY
163 *
164 * id will contain a number which represents the PHY. During
165 * startup, the driver will poll the PHY to find out what its
166 * UID--as defined by registers 2 and 3--is. The 32-bit result
167 * gotten from the PHY will be ANDed with phy_id_mask to
168 * discard any bits which may change based on revision numbers
169 * unimportant to functionality
170 *
171 * There are 6 commands which take a gfar_mii_info structure.
172 * Each PHY must declare config_aneg, and read_status.
173 */
174struct phy_info {
175 u32 phy_id;
176 char *name;
177 unsigned int phy_id_mask;
178 u32 features;
179
180 /* Called to initialize the PHY */
181 int (*init)(struct gfar_mii_info *mii_info);
182
183 /* Called to suspend the PHY for power */
184 int (*suspend)(struct gfar_mii_info *mii_info);
185
186 /* Reconfigures autonegotiation (or disables it) */
187 int (*config_aneg)(struct gfar_mii_info *mii_info);
188
189 /* Determines the negotiated speed and duplex */
190 int (*read_status)(struct gfar_mii_info *mii_info);
191
192 /* Clears any pending interrupts */
193 int (*ack_interrupt)(struct gfar_mii_info *mii_info);
194
195 /* Enables or disables interrupts */
196 int (*config_intr)(struct gfar_mii_info *mii_info);
197
198 /* Clears up any memory if needed */
199 void (*close)(struct gfar_mii_info *mii_info);
200};
201
202struct phy_info *get_phy_info(struct gfar_mii_info *mii_info);
203int read_phy_reg(struct net_device *dev, int mii_id, int regnum);
204void write_phy_reg(struct net_device *dev, int mii_id, int regnum, int value);
205void mii_clear_phy_interrupt(struct gfar_mii_info *mii_info);
206void mii_configure_phy_interrupt(struct gfar_mii_info *mii_info, u32 interrupts);
207
208struct dm9161_private {
209 struct timer_list timer;
210 int resetdone;
211};
212
213#endif /* GIANFAR_PHY_H */
diff --git a/drivers/net/hamradio/Kconfig b/drivers/net/hamradio/Kconfig
index de087cd609d9..896aa02000d7 100644
--- a/drivers/net/hamradio/Kconfig
+++ b/drivers/net/hamradio/Kconfig
@@ -1,6 +1,7 @@
1config MKISS 1config MKISS
2 tristate "Serial port KISS driver" 2 tristate "Serial port KISS driver"
3 depends on AX25 3 depends on AX25
4 select CRC16
4 ---help--- 5 ---help---
5 KISS is a protocol used for the exchange of data between a computer 6 KISS is a protocol used for the exchange of data between a computer
6 and a Terminal Node Controller (a small embedded system commonly 7 and a Terminal Node Controller (a small embedded system commonly
diff --git a/drivers/net/hamradio/bpqether.c b/drivers/net/hamradio/bpqether.c
index 1756f0ed54cc..cb43a9d28774 100644
--- a/drivers/net/hamradio/bpqether.c
+++ b/drivers/net/hamradio/bpqether.c
@@ -144,7 +144,7 @@ static inline struct net_device *bpq_get_ax25_dev(struct net_device *dev)
144{ 144{
145 struct bpqdev *bpq; 145 struct bpqdev *bpq;
146 146
147 list_for_each_entry(bpq, &bpq_devices, bpq_list) { 147 list_for_each_entry_rcu(bpq, &bpq_devices, bpq_list) {
148 if (bpq->ethdev == dev) 148 if (bpq->ethdev == dev)
149 return bpq->axdev; 149 return bpq->axdev;
150 } 150 }
@@ -399,7 +399,7 @@ static void *bpq_seq_start(struct seq_file *seq, loff_t *pos)
399 if (*pos == 0) 399 if (*pos == 0)
400 return SEQ_START_TOKEN; 400 return SEQ_START_TOKEN;
401 401
402 list_for_each_entry(bpqdev, &bpq_devices, bpq_list) { 402 list_for_each_entry_rcu(bpqdev, &bpq_devices, bpq_list) {
403 if (i == *pos) 403 if (i == *pos)
404 return bpqdev; 404 return bpqdev;
405 } 405 }
@@ -418,7 +418,7 @@ static void *bpq_seq_next(struct seq_file *seq, void *v, loff_t *pos)
418 p = ((struct bpqdev *)v)->bpq_list.next; 418 p = ((struct bpqdev *)v)->bpq_list.next;
419 419
420 return (p == &bpq_devices) ? NULL 420 return (p == &bpq_devices) ? NULL
421 : list_entry(p, struct bpqdev, bpq_list); 421 : rcu_dereference(list_entry(p, struct bpqdev, bpq_list));
422} 422}
423 423
424static void bpq_seq_stop(struct seq_file *seq, void *v) 424static void bpq_seq_stop(struct seq_file *seq, void *v)
@@ -561,8 +561,6 @@ static int bpq_device_event(struct notifier_block *this,unsigned long event, voi
561 if (!dev_is_ethdev(dev)) 561 if (!dev_is_ethdev(dev))
562 return NOTIFY_DONE; 562 return NOTIFY_DONE;
563 563
564 rcu_read_lock();
565
566 switch (event) { 564 switch (event) {
567 case NETDEV_UP: /* new ethernet device -> new BPQ interface */ 565 case NETDEV_UP: /* new ethernet device -> new BPQ interface */
568 if (bpq_get_ax25_dev(dev) == NULL) 566 if (bpq_get_ax25_dev(dev) == NULL)
@@ -581,7 +579,6 @@ static int bpq_device_event(struct notifier_block *this,unsigned long event, voi
581 default: 579 default:
582 break; 580 break;
583 } 581 }
584 rcu_read_unlock();
585 582
586 return NOTIFY_DONE; 583 return NOTIFY_DONE;
587} 584}
diff --git a/drivers/net/hamradio/mkiss.c b/drivers/net/hamradio/mkiss.c
index d9fe64b46f4b..3e9accf137e7 100644
--- a/drivers/net/hamradio/mkiss.c
+++ b/drivers/net/hamradio/mkiss.c
@@ -14,13 +14,14 @@
14 * 14 *
15 * Copyright (C) Hans Alblas PE1AYX <hans@esrac.ele.tue.nl> 15 * Copyright (C) Hans Alblas PE1AYX <hans@esrac.ele.tue.nl>
16 * Copyright (C) 2004, 05 Ralf Baechle DL5RB <ralf@linux-mips.org> 16 * Copyright (C) 2004, 05 Ralf Baechle DL5RB <ralf@linux-mips.org>
17 * Copyright (C) 2004, 05 Thomas Osterried DL9SAU <thomas@x-berg.in-berlin.de>
17 */ 18 */
18
19#include <linux/config.h> 19#include <linux/config.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <asm/system.h> 21#include <asm/system.h>
22#include <linux/bitops.h> 22#include <linux/bitops.h>
23#include <asm/uaccess.h> 23#include <asm/uaccess.h>
24#include <linux/crc16.h>
24#include <linux/string.h> 25#include <linux/string.h>
25#include <linux/mm.h> 26#include <linux/mm.h>
26#include <linux/interrupt.h> 27#include <linux/interrupt.h>
@@ -39,11 +40,6 @@
39 40
40#include <net/ax25.h> 41#include <net/ax25.h>
41 42
42#ifdef CONFIG_INET
43#include <linux/ip.h>
44#include <linux/tcp.h>
45#endif
46
47#define AX_MTU 236 43#define AX_MTU 236
48 44
49/* SLIP/KISS protocol characters. */ 45/* SLIP/KISS protocol characters. */
@@ -80,9 +76,13 @@ struct mkiss {
80 76
81 int mode; 77 int mode;
82 int crcmode; /* MW: for FlexNet, SMACK etc. */ 78 int crcmode; /* MW: for FlexNet, SMACK etc. */
83#define CRC_MODE_NONE 0 79 int crcauto; /* CRC auto mode */
84#define CRC_MODE_FLEX 1 80
85#define CRC_MODE_SMACK 2 81#define CRC_MODE_NONE 0
82#define CRC_MODE_FLEX 1
83#define CRC_MODE_SMACK 2
84#define CRC_MODE_FLEX_TEST 3
85#define CRC_MODE_SMACK_TEST 4
86 86
87 atomic_t refcnt; 87 atomic_t refcnt;
88 struct semaphore dead_sem; 88 struct semaphore dead_sem;
@@ -151,6 +151,21 @@ static int check_crc_flex(unsigned char *cp, int size)
151 return 0; 151 return 0;
152} 152}
153 153
154static int check_crc_16(unsigned char *cp, int size)
155{
156 unsigned short crc = 0x0000;
157
158 if (size < 3)
159 return -1;
160
161 crc = crc16(0, cp, size);
162
163 if (crc != 0x0000)
164 return -1;
165
166 return 0;
167}
168
154/* 169/*
155 * Standard encapsulation 170 * Standard encapsulation
156 */ 171 */
@@ -237,19 +252,42 @@ static void ax_bump(struct mkiss *ax)
237 252
238 spin_lock_bh(&ax->buflock); 253 spin_lock_bh(&ax->buflock);
239 if (ax->rbuff[0] > 0x0f) { 254 if (ax->rbuff[0] > 0x0f) {
240 if (ax->rbuff[0] & 0x20) { 255 if (ax->rbuff[0] & 0x80) {
241 ax->crcmode = CRC_MODE_FLEX; 256 if (check_crc_16(ax->rbuff, ax->rcount) < 0) {
257 ax->stats.rx_errors++;
258 spin_unlock_bh(&ax->buflock);
259
260 return;
261 }
262 if (ax->crcmode != CRC_MODE_SMACK && ax->crcauto) {
263 printk(KERN_INFO
264 "mkiss: %s: Switchting to crc-smack\n",
265 ax->dev->name);
266 ax->crcmode = CRC_MODE_SMACK;
267 }
268 ax->rcount -= 2;
269 *ax->rbuff &= ~0x80;
270 } else if (ax->rbuff[0] & 0x20) {
242 if (check_crc_flex(ax->rbuff, ax->rcount) < 0) { 271 if (check_crc_flex(ax->rbuff, ax->rcount) < 0) {
243 ax->stats.rx_errors++; 272 ax->stats.rx_errors++;
273 spin_unlock_bh(&ax->buflock);
244 return; 274 return;
245 } 275 }
276 if (ax->crcmode != CRC_MODE_FLEX && ax->crcauto) {
277 printk(KERN_INFO
278 "mkiss: %s: Switchting to crc-flexnet\n",
279 ax->dev->name);
280 ax->crcmode = CRC_MODE_FLEX;
281 }
246 ax->rcount -= 2; 282 ax->rcount -= 2;
247 /* dl9sau bugfix: the trailling two bytes flexnet crc 283
248 * will not be passed to the kernel. thus we have 284 /*
249 * to correct the kissparm signature, because it 285 * dl9sau bugfix: the trailling two bytes flexnet crc
250 * indicates a crc but there's none 286 * will not be passed to the kernel. thus we have to
287 * correct the kissparm signature, because it indicates
288 * a crc but there's none
251 */ 289 */
252 *ax->rbuff &= ~0x20; 290 *ax->rbuff &= ~0x20;
253 } 291 }
254 } 292 }
255 spin_unlock_bh(&ax->buflock); 293 spin_unlock_bh(&ax->buflock);
@@ -352,10 +390,8 @@ static void ax_changedmtu(struct mkiss *ax)
352 "MTU change cancelled.\n", 390 "MTU change cancelled.\n",
353 ax->dev->name); 391 ax->dev->name);
354 dev->mtu = ax->mtu; 392 dev->mtu = ax->mtu;
355 if (xbuff != NULL) 393 kfree(xbuff);
356 kfree(xbuff); 394 kfree(rbuff);
357 if (rbuff != NULL)
358 kfree(rbuff);
359 return; 395 return;
360 } 396 }
361 397
@@ -417,20 +453,69 @@ static void ax_encaps(struct net_device *dev, unsigned char *icp, int len)
417 p = icp; 453 p = icp;
418 454
419 spin_lock_bh(&ax->buflock); 455 spin_lock_bh(&ax->buflock);
420 switch (ax->crcmode) { 456 if ((*p & 0x0f) != 0) {
421 unsigned short crc; 457 /* Configuration Command (kissparms(1).
458 * Protocol spec says: never append CRC.
459 * This fixes a very old bug in the linux
460 * kiss driver. -- dl9sau */
461 switch (*p & 0xff) {
462 case 0x85:
463 /* command from userspace especially for us,
464 * not for delivery to the tnc */
465 if (len > 1) {
466 int cmd = (p[1] & 0xff);
467 switch(cmd) {
468 case 3:
469 ax->crcmode = CRC_MODE_SMACK;
470 break;
471 case 2:
472 ax->crcmode = CRC_MODE_FLEX;
473 break;
474 case 1:
475 ax->crcmode = CRC_MODE_NONE;
476 break;
477 case 0:
478 default:
479 ax->crcmode = CRC_MODE_SMACK_TEST;
480 cmd = 0;
481 }
482 ax->crcauto = (cmd ? 0 : 1);
483 printk(KERN_INFO "mkiss: %s: crc mode %s %d\n", ax->dev->name, (len) ? "set to" : "is", cmd);
484 }
485 spin_unlock_bh(&ax->buflock);
486 netif_start_queue(dev);
422 487
423 case CRC_MODE_FLEX: 488 return;
424 *p |= 0x20; 489 default:
425 crc = calc_crc_flex(p, len); 490 count = kiss_esc(p, (unsigned char *)ax->xbuff, len);
426 count = kiss_esc_crc(p, (unsigned char *)ax->xbuff, crc, len+2); 491 }
427 break; 492 } else {
493 unsigned short crc;
494 switch (ax->crcmode) {
495 case CRC_MODE_SMACK_TEST:
496 ax->crcmode = CRC_MODE_FLEX_TEST;
497 printk(KERN_INFO "mkiss: %s: Trying crc-smack\n", ax->dev->name);
498 // fall through
499 case CRC_MODE_SMACK:
500 *p |= 0x80;
501 crc = swab16(crc16(0, p, len));
502 count = kiss_esc_crc(p, (unsigned char *)ax->xbuff, crc, len+2);
503 break;
504 case CRC_MODE_FLEX_TEST:
505 ax->crcmode = CRC_MODE_NONE;
506 printk(KERN_INFO "mkiss: %s: Trying crc-flexnet\n", ax->dev->name);
507 // fall through
508 case CRC_MODE_FLEX:
509 *p |= 0x20;
510 crc = calc_crc_flex(p, len);
511 count = kiss_esc_crc(p, (unsigned char *)ax->xbuff, crc, len+2);
512 break;
513
514 default:
515 count = kiss_esc(p, (unsigned char *)ax->xbuff, len);
516 }
517 }
428 518
429 default:
430 count = kiss_esc(p, (unsigned char *)ax->xbuff, len);
431 break;
432 }
433
434 set_bit(TTY_DO_WRITE_WAKEUP, &ax->tty->flags); 519 set_bit(TTY_DO_WRITE_WAKEUP, &ax->tty->flags);
435 actual = ax->tty->driver->write(ax->tty, ax->xbuff, count); 520 actual = ax->tty->driver->write(ax->tty, ax->xbuff, count);
436 ax->stats.tx_packets++; 521 ax->stats.tx_packets++;
@@ -439,8 +524,6 @@ static void ax_encaps(struct net_device *dev, unsigned char *icp, int len)
439 ax->dev->trans_start = jiffies; 524 ax->dev->trans_start = jiffies;
440 ax->xleft = count - actual; 525 ax->xleft = count - actual;
441 ax->xhead = ax->xbuff + actual; 526 ax->xhead = ax->xbuff + actual;
442
443 spin_unlock_bh(&ax->buflock);
444} 527}
445 528
446/* Encapsulate an AX.25 packet and kick it into a TTY queue. */ 529/* Encapsulate an AX.25 packet and kick it into a TTY queue. */
@@ -622,7 +705,7 @@ static void ax_setup(struct net_device *dev)
622 * best way to fix this is to use a rwlock in the tty struct, but for now we 705 * best way to fix this is to use a rwlock in the tty struct, but for now we
623 * use a single global rwlock for all ttys in ppp line discipline. 706 * use a single global rwlock for all ttys in ppp line discipline.
624 */ 707 */
625static rwlock_t disc_data_lock = RW_LOCK_UNLOCKED; 708static DEFINE_RWLOCK(disc_data_lock);
626 709
627static struct mkiss *mkiss_get(struct tty_struct *tty) 710static struct mkiss *mkiss_get(struct tty_struct *tty)
628{ 711{
@@ -643,6 +726,8 @@ static void mkiss_put(struct mkiss *ax)
643 up(&ax->dead_sem); 726 up(&ax->dead_sem);
644} 727}
645 728
729static int crc_force = 0; /* Can be overridden with insmod */
730
646static int mkiss_open(struct tty_struct *tty) 731static int mkiss_open(struct tty_struct *tty)
647{ 732{
648 struct net_device *dev; 733 struct net_device *dev;
@@ -682,6 +767,33 @@ static int mkiss_open(struct tty_struct *tty)
682 if (register_netdev(dev)) 767 if (register_netdev(dev))
683 goto out_free_buffers; 768 goto out_free_buffers;
684 769
770 /* after register_netdev() - because else printk smashes the kernel */
771 switch (crc_force) {
772 case 3:
773 ax->crcmode = CRC_MODE_SMACK;
774 printk(KERN_INFO "mkiss: %s: crc mode smack forced.\n",
775 ax->dev->name);
776 break;
777 case 2:
778 ax->crcmode = CRC_MODE_FLEX;
779 printk(KERN_INFO "mkiss: %s: crc mode flexnet forced.\n",
780 ax->dev->name);
781 break;
782 case 1:
783 ax->crcmode = CRC_MODE_NONE;
784 printk(KERN_INFO "mkiss: %s: crc mode disabled.\n",
785 ax->dev->name);
786 break;
787 case 0:
788 /* fall through */
789 default:
790 crc_force = 0;
791 printk(KERN_INFO "mkiss: %s: crc mode is auto.\n",
792 ax->dev->name);
793 ax->crcmode = CRC_MODE_SMACK_TEST;
794 }
795 ax->crcauto = (crc_force ? 0 : 1);
796
685 netif_start_queue(dev); 797 netif_start_queue(dev);
686 798
687 /* Done. We have linked the TTY line to a channel. */ 799 /* Done. We have linked the TTY line to a channel. */
@@ -765,7 +877,6 @@ static int mkiss_ioctl(struct tty_struct *tty, struct file *file,
765 877
766 case SIOCSIFHWADDR: { 878 case SIOCSIFHWADDR: {
767 char addr[AX25_ADDR_LEN]; 879 char addr[AX25_ADDR_LEN];
768printk(KERN_INFO "In SIOCSIFHWADDR");
769 880
770 if (copy_from_user(&addr, 881 if (copy_from_user(&addr,
771 (void __user *) arg, AX25_ADDR_LEN)) { 882 (void __user *) arg, AX25_ADDR_LEN)) {
@@ -864,6 +975,7 @@ out:
864} 975}
865 976
866static struct tty_ldisc ax_ldisc = { 977static struct tty_ldisc ax_ldisc = {
978 .owner = THIS_MODULE,
867 .magic = TTY_LDISC_MAGIC, 979 .magic = TTY_LDISC_MAGIC,
868 .name = "mkiss", 980 .name = "mkiss",
869 .open = mkiss_open, 981 .open = mkiss_open,
@@ -904,6 +1016,8 @@ static void __exit mkiss_exit_driver(void)
904 1016
905MODULE_AUTHOR("Ralf Baechle DL5RB <ralf@linux-mips.org>"); 1017MODULE_AUTHOR("Ralf Baechle DL5RB <ralf@linux-mips.org>");
906MODULE_DESCRIPTION("KISS driver for AX.25 over TTYs"); 1018MODULE_DESCRIPTION("KISS driver for AX.25 over TTYs");
1019MODULE_PARM(crc_force, "i");
1020MODULE_PARM_DESC(crc_force, "crc [0 = auto | 1 = none | 2 = flexnet | 3 = smack]");
907MODULE_LICENSE("GPL"); 1021MODULE_LICENSE("GPL");
908MODULE_ALIAS_LDISC(N_AX25); 1022MODULE_ALIAS_LDISC(N_AX25);
909 1023
diff --git a/drivers/net/hamradio/mkiss.h b/drivers/net/hamradio/mkiss.h
deleted file mode 100644
index 4ab700478598..000000000000
--- a/drivers/net/hamradio/mkiss.h
+++ /dev/null
@@ -1,62 +0,0 @@
1/****************************************************************************
2 * Defines for the Multi-KISS driver.
3 ****************************************************************************/
4
5#define AX25_MAXDEV 16 /* MAX number of AX25 channels;
6 This can be overridden with
7 insmod -oax25_maxdev=nnn */
8#define AX_MTU 236
9
10/* SLIP/KISS protocol characters. */
11#define END 0300 /* indicates end of frame */
12#define ESC 0333 /* indicates byte stuffing */
13#define ESC_END 0334 /* ESC ESC_END means END 'data' */
14#define ESC_ESC 0335 /* ESC ESC_ESC means ESC 'data' */
15
16struct ax_disp {
17 int magic;
18
19 /* Various fields. */
20 struct tty_struct *tty; /* ptr to TTY structure */
21 struct net_device *dev; /* easy for intr handling */
22
23 /* These are pointers to the malloc()ed frame buffers. */
24 unsigned char *rbuff; /* receiver buffer */
25 int rcount; /* received chars counter */
26 unsigned char *xbuff; /* transmitter buffer */
27 unsigned char *xhead; /* pointer to next byte to XMIT */
28 int xleft; /* bytes left in XMIT queue */
29
30 /* SLIP interface statistics. */
31 unsigned long rx_packets; /* inbound frames counter */
32 unsigned long tx_packets; /* outbound frames counter */
33 unsigned long rx_bytes; /* inbound bytes counter */
34 unsigned long tx_bytes; /* outbound bytes counter */
35 unsigned long rx_errors; /* Parity, etc. errors */
36 unsigned long tx_errors; /* Planned stuff */
37 unsigned long rx_dropped; /* No memory for skb */
38 unsigned long tx_dropped; /* When MTU change */
39 unsigned long rx_over_errors; /* Frame bigger then SLIP buf. */
40
41 /* Detailed SLIP statistics. */
42 int mtu; /* Our mtu (to spot changes!) */
43 int buffsize; /* Max buffers sizes */
44
45
46 unsigned long flags; /* Flag values/ mode etc */
47 /* long req'd: used by set_bit --RR */
48#define AXF_INUSE 0 /* Channel in use */
49#define AXF_ESCAPE 1 /* ESC received */
50#define AXF_ERROR 2 /* Parity, etc. error */
51#define AXF_KEEPTEST 3 /* Keepalive test flag */
52#define AXF_OUTWAIT 4 /* is outpacket was flag */
53
54 int mode;
55 int crcmode; /* MW: for FlexNet, SMACK etc. */
56#define CRC_MODE_NONE 0
57#define CRC_MODE_FLEX 1
58#define CRC_MODE_SMACK 2
59 spinlock_t buflock; /* lock for rbuf and xbuf */
60};
61
62#define AX25_MAGIC 0x5316
diff --git a/drivers/net/hp100.c b/drivers/net/hp100.c
index cf0ac6fda1a1..b71fab6e34f4 100644
--- a/drivers/net/hp100.c
+++ b/drivers/net/hp100.c
@@ -2517,10 +2517,8 @@ static int hp100_down_vg_link(struct net_device *dev)
2517 do { 2517 do {
2518 if (hp100_inb(VG_LAN_CFG_1) & HP100_LINK_CABLE_ST) 2518 if (hp100_inb(VG_LAN_CFG_1) & HP100_LINK_CABLE_ST)
2519 break; 2519 break;
2520 if (!in_interrupt()) { 2520 if (!in_interrupt())
2521 set_current_state(TASK_INTERRUPTIBLE); 2521 schedule_timeout_interruptible(1);
2522 schedule_timeout(1);
2523 }
2524 } while (time_after(time, jiffies)); 2522 } while (time_after(time, jiffies));
2525 2523
2526 if (time_after_eq(jiffies, time)) /* no signal->no logout */ 2524 if (time_after_eq(jiffies, time)) /* no signal->no logout */
@@ -2536,10 +2534,8 @@ static int hp100_down_vg_link(struct net_device *dev)
2536 do { 2534 do {
2537 if (!(hp100_inb(VG_LAN_CFG_1) & HP100_LINK_UP_ST)) 2535 if (!(hp100_inb(VG_LAN_CFG_1) & HP100_LINK_UP_ST))
2538 break; 2536 break;
2539 if (!in_interrupt()) { 2537 if (!in_interrupt())
2540 set_current_state(TASK_INTERRUPTIBLE); 2538 schedule_timeout_interruptible(1);
2541 schedule_timeout(1);
2542 }
2543 } while (time_after(time, jiffies)); 2539 } while (time_after(time, jiffies));
2544 2540
2545#ifdef HP100_DEBUG 2541#ifdef HP100_DEBUG
@@ -2577,10 +2573,8 @@ static int hp100_down_vg_link(struct net_device *dev)
2577 do { 2573 do {
2578 if (!(hp100_inb(MAC_CFG_4) & HP100_MAC_SEL_ST)) 2574 if (!(hp100_inb(MAC_CFG_4) & HP100_MAC_SEL_ST))
2579 break; 2575 break;
2580 if (!in_interrupt()) { 2576 if (!in_interrupt())
2581 set_current_state(TASK_INTERRUPTIBLE); 2577 schedule_timeout_interruptible(1);
2582 schedule_timeout(1);
2583 }
2584 } while (time_after(time, jiffies)); 2578 } while (time_after(time, jiffies));
2585 2579
2586 hp100_orb(HP100_AUTO_MODE, MAC_CFG_3); /* Autosel back on */ 2580 hp100_orb(HP100_AUTO_MODE, MAC_CFG_3); /* Autosel back on */
@@ -2591,10 +2585,8 @@ static int hp100_down_vg_link(struct net_device *dev)
2591 do { 2585 do {
2592 if ((hp100_inb(VG_LAN_CFG_1) & HP100_LINK_CABLE_ST) == 0) 2586 if ((hp100_inb(VG_LAN_CFG_1) & HP100_LINK_CABLE_ST) == 0)
2593 break; 2587 break;
2594 if (!in_interrupt()) { 2588 if (!in_interrupt())
2595 set_current_state(TASK_INTERRUPTIBLE); 2589 schedule_timeout_interruptible(1);
2596 schedule_timeout(1);
2597 }
2598 } while (time_after(time, jiffies)); 2590 } while (time_after(time, jiffies));
2599 2591
2600 if (time_before_eq(time, jiffies)) { 2592 if (time_before_eq(time, jiffies)) {
@@ -2606,10 +2598,8 @@ static int hp100_down_vg_link(struct net_device *dev)
2606 2598
2607 time = jiffies + (2 * HZ); /* This seems to take a while.... */ 2599 time = jiffies + (2 * HZ); /* This seems to take a while.... */
2608 do { 2600 do {
2609 if (!in_interrupt()) { 2601 if (!in_interrupt())
2610 set_current_state(TASK_INTERRUPTIBLE); 2602 schedule_timeout_interruptible(1);
2611 schedule_timeout(1);
2612 }
2613 } while (time_after(time, jiffies)); 2603 } while (time_after(time, jiffies));
2614 2604
2615 return 0; 2605 return 0;
@@ -2659,10 +2649,8 @@ static int hp100_login_to_vg_hub(struct net_device *dev, u_short force_relogin)
2659 do { 2649 do {
2660 if (~(hp100_inb(VG_LAN_CFG_1) & HP100_LINK_UP_ST)) 2650 if (~(hp100_inb(VG_LAN_CFG_1) & HP100_LINK_UP_ST))
2661 break; 2651 break;
2662 if (!in_interrupt()) { 2652 if (!in_interrupt())
2663 set_current_state(TASK_INTERRUPTIBLE); 2653 schedule_timeout_interruptible(1);
2664 schedule_timeout(1);
2665 }
2666 } while (time_after(time, jiffies)); 2654 } while (time_after(time, jiffies));
2667 2655
2668 /* Start an addressed training and optionally request promiscuous port */ 2656 /* Start an addressed training and optionally request promiscuous port */
@@ -2697,10 +2685,8 @@ static int hp100_login_to_vg_hub(struct net_device *dev, u_short force_relogin)
2697 do { 2685 do {
2698 if (hp100_inb(VG_LAN_CFG_1) & HP100_LINK_CABLE_ST) 2686 if (hp100_inb(VG_LAN_CFG_1) & HP100_LINK_CABLE_ST)
2699 break; 2687 break;
2700 if (!in_interrupt()) { 2688 if (!in_interrupt())
2701 set_current_state(TASK_INTERRUPTIBLE); 2689 schedule_timeout_interruptible(1);
2702 schedule_timeout(1);
2703 }
2704 } while (time_before(jiffies, time)); 2690 } while (time_before(jiffies, time));
2705 2691
2706 if (time_after_eq(jiffies, time)) { 2692 if (time_after_eq(jiffies, time)) {
@@ -2723,10 +2709,8 @@ static int hp100_login_to_vg_hub(struct net_device *dev, u_short force_relogin)
2723#endif 2709#endif
2724 break; 2710 break;
2725 } 2711 }
2726 if (!in_interrupt()) { 2712 if (!in_interrupt())
2727 set_current_state(TASK_INTERRUPTIBLE); 2713 schedule_timeout_interruptible(1);
2728 schedule_timeout(1);
2729 }
2730 } while (time_after(time, jiffies)); 2714 } while (time_after(time, jiffies));
2731 } 2715 }
2732 2716
diff --git a/drivers/net/ibm_emac/Makefile b/drivers/net/ibm_emac/Makefile
index 7f583a333c24..f98ddf0e807a 100644
--- a/drivers/net/ibm_emac/Makefile
+++ b/drivers/net/ibm_emac/Makefile
@@ -1,12 +1,11 @@
1# 1#
2# Makefile for the IBM PPC4xx EMAC controllers 2# Makefile for the PowerPC 4xx on-chip ethernet driver
3# 3#
4 4
5obj-$(CONFIG_IBM_EMAC) += ibm_emac.o 5obj-$(CONFIG_IBM_EMAC) += ibm_emac.o
6 6
7ibm_emac-objs := ibm_emac_mal.o ibm_emac_core.o ibm_emac_phy.o 7ibm_emac-objs := ibm_emac_mal.o ibm_emac_core.o ibm_emac_phy.o
8 8ibm_emac-$(CONFIG_IBM_EMAC_ZMII) += ibm_emac_zmii.o
9# Only need this if you want to see additional debug messages 9ibm_emac-$(CONFIG_IBM_EMAC_RGMII) += ibm_emac_rgmii.o
10ifeq ($(CONFIG_IBM_EMAC_ERRMSG), y) 10ibm_emac-$(CONFIG_IBM_EMAC_TAH) += ibm_emac_tah.o
11ibm_emac-objs += ibm_emac_debug.o 11ibm_emac-$(CONFIG_IBM_EMAC_DEBUG) += ibm_emac_debug.o
12endif
diff --git a/drivers/net/ibm_emac/ibm_emac.h b/drivers/net/ibm_emac/ibm_emac.h
index 15d5a0e82862..28c476f28c20 100644
--- a/drivers/net/ibm_emac/ibm_emac.h
+++ b/drivers/net/ibm_emac/ibm_emac.h
@@ -1,110 +1,142 @@
1/* 1/*
2 * ibm_emac.h 2 * drivers/net/ibm_emac/ibm_emac.h
3 * 3 *
4 * Register definitions for PowerPC 4xx on-chip ethernet contoller
4 * 5 *
5 * Armin Kuster akuster@mvista.com 6 * Copyright (c) 2004, 2005 Zultys Technologies.
6 * June, 2002 7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
7 * 8 *
8 * Copyright 2002 MontaVista Softare Inc. 9 * Based on original work by
10 * Matt Porter <mporter@kernel.crashing.org>
11 * Armin Kuster <akuster@mvista.com>
12 * Copyright 2002-2004 MontaVista Software Inc.
9 * 13 *
10 * This program is free software; you can redistribute it and/or modify it 14 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the 15 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your 16 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version. 17 * option) any later version.
18 *
14 */ 19 */
20#ifndef __IBM_EMAC_H_
21#define __IBM_EMAC_H_
22
23#include <linux/config.h>
24#include <linux/types.h>
25
26/* This is a simple check to prevent use of this driver on non-tested SoCs */
27#if !defined(CONFIG_405GP) && !defined(CONFIG_405GPR) && !defined(CONFIG_405EP) && \
28 !defined(CONFIG_440GP) && !defined(CONFIG_440GX) && !defined(CONFIG_440SP) && \
29 !defined(CONFIG_440EP) && !defined(CONFIG_NP405H)
30#error "Unknown SoC. Please, check chip user manual and make sure EMAC defines are OK"
31#endif
32
33/* EMAC registers Write Access rules */
34struct emac_regs {
35 u32 mr0; /* special */
36 u32 mr1; /* Reset */
37 u32 tmr0; /* special */
38 u32 tmr1; /* special */
39 u32 rmr; /* Reset */
40 u32 isr; /* Always */
41 u32 iser; /* Reset */
42 u32 iahr; /* Reset, R, T */
43 u32 ialr; /* Reset, R, T */
44 u32 vtpid; /* Reset, R, T */
45 u32 vtci; /* Reset, R, T */
46 u32 ptr; /* Reset, T */
47 u32 iaht1; /* Reset, R */
48 u32 iaht2; /* Reset, R */
49 u32 iaht3; /* Reset, R */
50 u32 iaht4; /* Reset, R */
51 u32 gaht1; /* Reset, R */
52 u32 gaht2; /* Reset, R */
53 u32 gaht3; /* Reset, R */
54 u32 gaht4; /* Reset, R */
55 u32 lsah;
56 u32 lsal;
57 u32 ipgvr; /* Reset, T */
58 u32 stacr; /* special */
59 u32 trtr; /* special */
60 u32 rwmr; /* Reset */
61 u32 octx;
62 u32 ocrx;
63 u32 ipcr;
64};
65
66#if !defined(CONFIG_IBM_EMAC4)
67#define EMAC_ETHTOOL_REGS_VER 0
68#define EMAC_ETHTOOL_REGS_SIZE (sizeof(struct emac_regs) - sizeof(u32))
69#else
70#define EMAC_ETHTOOL_REGS_VER 1
71#define EMAC_ETHTOOL_REGS_SIZE sizeof(struct emac_regs)
72#endif
15 73
16#ifndef _IBM_EMAC_H_ 74/* EMACx_MR0 */
17#define _IBM_EMAC_H_ 75#define EMAC_MR0_RXI 0x80000000
18/* General defines needed for the driver */ 76#define EMAC_MR0_TXI 0x40000000
77#define EMAC_MR0_SRST 0x20000000
78#define EMAC_MR0_TXE 0x10000000
79#define EMAC_MR0_RXE 0x08000000
80#define EMAC_MR0_WKE 0x04000000
19 81
20/* Emac */ 82/* EMACx_MR1 */
21typedef struct emac_regs { 83#define EMAC_MR1_FDE 0x80000000
22 u32 em0mr0; 84#define EMAC_MR1_ILE 0x40000000
23 u32 em0mr1; 85#define EMAC_MR1_VLE 0x20000000
24 u32 em0tmr0; 86#define EMAC_MR1_EIFC 0x10000000
25 u32 em0tmr1; 87#define EMAC_MR1_APP 0x08000000
26 u32 em0rmr; 88#define EMAC_MR1_IST 0x01000000
27 u32 em0isr;
28 u32 em0iser;
29 u32 em0iahr;
30 u32 em0ialr;
31 u32 em0vtpid;
32 u32 em0vtci;
33 u32 em0ptr;
34 u32 em0iaht1;
35 u32 em0iaht2;
36 u32 em0iaht3;
37 u32 em0iaht4;
38 u32 em0gaht1;
39 u32 em0gaht2;
40 u32 em0gaht3;
41 u32 em0gaht4;
42 u32 em0lsah;
43 u32 em0lsal;
44 u32 em0ipgvr;
45 u32 em0stacr;
46 u32 em0trtr;
47 u32 em0rwmr;
48} emac_t;
49 89
50/* MODE REG 0 */ 90#define EMAC_MR1_MF_MASK 0x00c00000
51#define EMAC_M0_RXI 0x80000000 91#define EMAC_MR1_MF_10 0x00000000
52#define EMAC_M0_TXI 0x40000000 92#define EMAC_MR1_MF_100 0x00400000
53#define EMAC_M0_SRST 0x20000000 93#if !defined(CONFIG_IBM_EMAC4)
54#define EMAC_M0_TXE 0x10000000 94#define EMAC_MR1_MF_1000 0x00000000
55#define EMAC_M0_RXE 0x08000000 95#define EMAC_MR1_MF_1000GPCS 0x00000000
56#define EMAC_M0_WKE 0x04000000 96#define EMAC_MR1_MF_IPPA(id) 0x00000000
97#else
98#define EMAC_MR1_MF_1000 0x00800000
99#define EMAC_MR1_MF_1000GPCS 0x00c00000
100#define EMAC_MR1_MF_IPPA(id) (((id) & 0x1f) << 6)
101#endif
57 102
58/* MODE Reg 1 */ 103#define EMAC_TX_FIFO_SIZE 2048
59#define EMAC_M1_FDE 0x80000000
60#define EMAC_M1_ILE 0x40000000
61#define EMAC_M1_VLE 0x20000000
62#define EMAC_M1_EIFC 0x10000000
63#define EMAC_M1_APP 0x08000000
64#define EMAC_M1_AEMI 0x02000000
65#define EMAC_M1_IST 0x01000000
66#define EMAC_M1_MF_1000GPCS 0x00c00000 /* Internal GPCS */
67#define EMAC_M1_MF_1000MBPS 0x00800000 /* External GPCS */
68#define EMAC_M1_MF_100MBPS 0x00400000
69#define EMAC_M1_RFS_16K 0x00280000 /* 000 for 512 byte */
70#define EMAC_M1_TR 0x00008000
71#ifdef CONFIG_IBM_EMAC4
72#define EMAC_M1_RFS_8K 0x00200000
73#define EMAC_M1_RFS_4K 0x00180000
74#define EMAC_M1_RFS_2K 0x00100000
75#define EMAC_M1_RFS_1K 0x00080000
76#define EMAC_M1_TX_FIFO_16K 0x00050000 /* 0's for 512 byte */
77#define EMAC_M1_TX_FIFO_8K 0x00040000
78#define EMAC_M1_TX_FIFO_4K 0x00030000
79#define EMAC_M1_TX_FIFO_2K 0x00020000
80#define EMAC_M1_TX_FIFO_1K 0x00010000
81#define EMAC_M1_TX_TR 0x00008000
82#define EMAC_M1_TX_MWSW 0x00001000 /* 0 wait for status */
83#define EMAC_M1_JUMBO_ENABLE 0x00000800 /* Upt to 9Kr status */
84#define EMAC_M1_OPB_CLK_66 0x00000008 /* 66Mhz */
85#define EMAC_M1_OPB_CLK_83 0x00000010 /* 83Mhz */
86#define EMAC_M1_OPB_CLK_100 0x00000018 /* 100Mhz */
87#define EMAC_M1_OPB_CLK_100P 0x00000020 /* 100Mhz+ */
88#else /* CONFIG_IBM_EMAC4 */
89#define EMAC_M1_RFS_4K 0x00300000 /* ~4k for 512 byte */
90#define EMAC_M1_RFS_2K 0x00200000
91#define EMAC_M1_RFS_1K 0x00100000
92#define EMAC_M1_TX_FIFO_2K 0x00080000 /* 0's for 512 byte */
93#define EMAC_M1_TX_FIFO_1K 0x00040000
94#define EMAC_M1_TR0_DEPEND 0x00010000 /* 0'x for single packet */
95#define EMAC_M1_TR1_DEPEND 0x00004000
96#define EMAC_M1_TR1_MULTI 0x00002000
97#define EMAC_M1_JUMBO_ENABLE 0x00001000
98#endif /* CONFIG_IBM_EMAC4 */
99#define EMAC_M1_BASE (EMAC_M1_TX_FIFO_2K | \
100 EMAC_M1_APP | \
101 EMAC_M1_TR | EMAC_M1_VLE)
102 104
103/* Transmit Mode Register 0 */ 105#if !defined(CONFIG_IBM_EMAC4)
104#define EMAC_TMR0_GNP0 0x80000000 106#define EMAC_MR1_RFS_4K 0x00300000
105#define EMAC_TMR0_GNP1 0x40000000 107#define EMAC_MR1_RFS_16K 0x00000000
106#define EMAC_TMR0_GNPD 0x20000000 108#define EMAC_RX_FIFO_SIZE(gige) 4096
107#define EMAC_TMR0_FC 0x10000000 109#define EMAC_MR1_TFS_2K 0x00080000
110#define EMAC_MR1_TR0_MULT 0x00008000
111#define EMAC_MR1_JPSM 0x00000000
112#define EMAC_MR1_BASE(opb) (EMAC_MR1_TFS_2K | EMAC_MR1_TR0_MULT)
113#else
114#define EMAC_MR1_RFS_4K 0x00180000
115#define EMAC_MR1_RFS_16K 0x00280000
116#define EMAC_RX_FIFO_SIZE(gige) ((gige) ? 16384 : 4096)
117#define EMAC_MR1_TFS_2K 0x00020000
118#define EMAC_MR1_TR 0x00008000
119#define EMAC_MR1_MWSW_001 0x00001000
120#define EMAC_MR1_JPSM 0x00000800
121#define EMAC_MR1_OBCI_MASK 0x00000038
122#define EMAC_MR1_OBCI_50 0x00000000
123#define EMAC_MR1_OBCI_66 0x00000008
124#define EMAC_MR1_OBCI_83 0x00000010
125#define EMAC_MR1_OBCI_100 0x00000018
126#define EMAC_MR1_OBCI_100P 0x00000020
127#define EMAC_MR1_OBCI(freq) ((freq) <= 50 ? EMAC_MR1_OBCI_50 : \
128 (freq) <= 66 ? EMAC_MR1_OBCI_66 : \
129 (freq) <= 83 ? EMAC_MR1_OBCI_83 : \
130 (freq) <= 100 ? EMAC_MR1_OBCI_100 : EMAC_MR1_OBCI_100P)
131#define EMAC_MR1_BASE(opb) (EMAC_MR1_TFS_2K | EMAC_MR1_TR | \
132 EMAC_MR1_MWSW_001 | EMAC_MR1_OBCI(opb))
133#endif
134
135/* EMACx_TMR0 */
136#define EMAC_TMR0_GNP 0x80000000
137#if !defined(CONFIG_IBM_EMAC4)
138#define EMAC_TMR0_DEFAULT 0x00000000
139#else
108#define EMAC_TMR0_TFAE_2_32 0x00000001 140#define EMAC_TMR0_TFAE_2_32 0x00000001
109#define EMAC_TMR0_TFAE_4_64 0x00000002 141#define EMAC_TMR0_TFAE_4_64 0x00000002
110#define EMAC_TMR0_TFAE_8_128 0x00000003 142#define EMAC_TMR0_TFAE_8_128 0x00000003
@@ -112,14 +144,36 @@ typedef struct emac_regs {
112#define EMAC_TMR0_TFAE_32_512 0x00000005 144#define EMAC_TMR0_TFAE_32_512 0x00000005
113#define EMAC_TMR0_TFAE_64_1024 0x00000006 145#define EMAC_TMR0_TFAE_64_1024 0x00000006
114#define EMAC_TMR0_TFAE_128_2048 0x00000007 146#define EMAC_TMR0_TFAE_128_2048 0x00000007
147#define EMAC_TMR0_DEFAULT EMAC_TMR0_TFAE_2_32
148#endif
149#define EMAC_TMR0_XMIT (EMAC_TMR0_GNP | EMAC_TMR0_DEFAULT)
150
151/* EMACx_TMR1 */
152
153/* IBM manuals are not very clear here.
154 * This is my interpretation of how things are. --ebs
155 */
156#if defined(CONFIG_40x)
157#define EMAC_FIFO_ENTRY_SIZE 8
158#define EMAC_MAL_BURST_SIZE (16 * 4)
159#else
160#define EMAC_FIFO_ENTRY_SIZE 16
161#define EMAC_MAL_BURST_SIZE (64 * 4)
162#endif
163
164#if !defined(CONFIG_IBM_EMAC4)
165#define EMAC_TMR1(l,h) (((l) << 27) | (((h) & 0xff) << 16))
166#else
167#define EMAC_TMR1(l,h) (((l) << 27) | (((h) & 0x3ff) << 14))
168#endif
115 169
116/* Receive Mode Register */ 170/* EMACx_RMR */
117#define EMAC_RMR_SP 0x80000000 171#define EMAC_RMR_SP 0x80000000
118#define EMAC_RMR_SFCS 0x40000000 172#define EMAC_RMR_SFCS 0x40000000
119#define EMAC_RMR_ARRP 0x20000000 173#define EMAC_RMR_RRP 0x20000000
120#define EMAC_RMR_ARP 0x10000000 174#define EMAC_RMR_RFP 0x10000000
121#define EMAC_RMR_AROP 0x08000000 175#define EMAC_RMR_ROP 0x08000000
122#define EMAC_RMR_ARPI 0x04000000 176#define EMAC_RMR_RPIR 0x04000000
123#define EMAC_RMR_PPP 0x02000000 177#define EMAC_RMR_PPP 0x02000000
124#define EMAC_RMR_PME 0x01000000 178#define EMAC_RMR_PME 0x01000000
125#define EMAC_RMR_PMME 0x00800000 179#define EMAC_RMR_PMME 0x00800000
@@ -127,6 +181,9 @@ typedef struct emac_regs {
127#define EMAC_RMR_MIAE 0x00200000 181#define EMAC_RMR_MIAE 0x00200000
128#define EMAC_RMR_BAE 0x00100000 182#define EMAC_RMR_BAE 0x00100000
129#define EMAC_RMR_MAE 0x00080000 183#define EMAC_RMR_MAE 0x00080000
184#if !defined(CONFIG_IBM_EMAC4)
185#define EMAC_RMR_BASE 0x00000000
186#else
130#define EMAC_RMR_RFAF_2_32 0x00000001 187#define EMAC_RMR_RFAF_2_32 0x00000001
131#define EMAC_RMR_RFAF_4_64 0x00000002 188#define EMAC_RMR_RFAF_4_64 0x00000002
132#define EMAC_RMR_RFAF_8_128 0x00000003 189#define EMAC_RMR_RFAF_8_128 0x00000003
@@ -134,9 +191,21 @@ typedef struct emac_regs {
134#define EMAC_RMR_RFAF_32_512 0x00000005 191#define EMAC_RMR_RFAF_32_512 0x00000005
135#define EMAC_RMR_RFAF_64_1024 0x00000006 192#define EMAC_RMR_RFAF_64_1024 0x00000006
136#define EMAC_RMR_RFAF_128_2048 0x00000007 193#define EMAC_RMR_RFAF_128_2048 0x00000007
137#define EMAC_RMR_BASE (EMAC_RMR_IAE | EMAC_RMR_BAE) 194#define EMAC_RMR_BASE EMAC_RMR_RFAF_128_2048
195#endif
138 196
139/* Interrupt Status & enable Regs */ 197/* EMACx_ISR & EMACx_ISER */
198#if !defined(CONFIG_IBM_EMAC4)
199#define EMAC_ISR_TXPE 0x00000000
200#define EMAC_ISR_RXPE 0x00000000
201#define EMAC_ISR_TXUE 0x00000000
202#define EMAC_ISR_RXOE 0x00000000
203#else
204#define EMAC_ISR_TXPE 0x20000000
205#define EMAC_ISR_RXPE 0x10000000
206#define EMAC_ISR_TXUE 0x08000000
207#define EMAC_ISR_RXOE 0x04000000
208#endif
140#define EMAC_ISR_OVR 0x02000000 209#define EMAC_ISR_OVR 0x02000000
141#define EMAC_ISR_PP 0x01000000 210#define EMAC_ISR_PP 0x01000000
142#define EMAC_ISR_BP 0x00800000 211#define EMAC_ISR_BP 0x00800000
@@ -147,53 +216,62 @@ typedef struct emac_regs {
147#define EMAC_ISR_PTLE 0x00040000 216#define EMAC_ISR_PTLE 0x00040000
148#define EMAC_ISR_ORE 0x00020000 217#define EMAC_ISR_ORE 0x00020000
149#define EMAC_ISR_IRE 0x00010000 218#define EMAC_ISR_IRE 0x00010000
150#define EMAC_ISR_DBDM 0x00000200 219#define EMAC_ISR_SQE 0x00000080
151#define EMAC_ISR_DB0 0x00000100 220#define EMAC_ISR_TE 0x00000040
152#define EMAC_ISR_SE0 0x00000080
153#define EMAC_ISR_TE0 0x00000040
154#define EMAC_ISR_DB1 0x00000020
155#define EMAC_ISR_SE1 0x00000010
156#define EMAC_ISR_TE1 0x00000008
157#define EMAC_ISR_MOS 0x00000002 221#define EMAC_ISR_MOS 0x00000002
158#define EMAC_ISR_MOF 0x00000001 222#define EMAC_ISR_MOF 0x00000001
159 223
160/* STA CONTROL REG */ 224/* EMACx_STACR */
225#define EMAC_STACR_PHYD_MASK 0xffff
226#define EMAC_STACR_PHYD_SHIFT 16
161#define EMAC_STACR_OC 0x00008000 227#define EMAC_STACR_OC 0x00008000
162#define EMAC_STACR_PHYE 0x00004000 228#define EMAC_STACR_PHYE 0x00004000
163#define EMAC_STACR_WRITE 0x00002000 229#define EMAC_STACR_STAC_MASK 0x00003000
164#define EMAC_STACR_READ 0x00001000 230#define EMAC_STACR_STAC_READ 0x00001000
165#define EMAC_STACR_CLK_83MHZ 0x00000800 /* 0's for 50Mhz */ 231#define EMAC_STACR_STAC_WRITE 0x00002000
166#define EMAC_STACR_CLK_66MHZ 0x00000400 232#if !defined(CONFIG_IBM_EMAC4)
167#define EMAC_STACR_CLK_100MHZ 0x00000C00 233#define EMAC_STACR_OPBC_MASK 0x00000C00
234#define EMAC_STACR_OPBC_50 0x00000000
235#define EMAC_STACR_OPBC_66 0x00000400
236#define EMAC_STACR_OPBC_83 0x00000800
237#define EMAC_STACR_OPBC_100 0x00000C00
238#define EMAC_STACR_OPBC(freq) ((freq) <= 50 ? EMAC_STACR_OPBC_50 : \
239 (freq) <= 66 ? EMAC_STACR_OPBC_66 : \
240 (freq) <= 83 ? EMAC_STACR_OPBC_83 : EMAC_STACR_OPBC_100)
241#define EMAC_STACR_BASE(opb) EMAC_STACR_OPBC(opb)
242#else
243#define EMAC_STACR_BASE(opb) 0x00000000
244#endif
245#define EMAC_STACR_PCDA_MASK 0x1f
246#define EMAC_STACR_PCDA_SHIFT 5
247#define EMAC_STACR_PRA_MASK 0x1f
248
249/* EMACx_TRTR */
250#if !defined(CONFIG_IBM_EMAC4)
251#define EMAC_TRTR_SHIFT 27
252#else
253#define EMAC_TRTR_SHIFT 24
254#endif
255#define EMAC_TRTR(size) ((((size) >> 6) - 1) << EMAC_TRTR_SHIFT)
168 256
169/* Transmit Request Threshold Register */ 257/* EMACx_RWMR */
170#define EMAC_TRTR_1600 0x18000000 /* 0's for 64 Bytes */ 258#if !defined(CONFIG_IBM_EMAC4)
171#define EMAC_TRTR_1024 0x0f000000 259#define EMAC_RWMR(l,h) (((l) << 23) | ( ((h) & 0x1ff) << 7))
172#define EMAC_TRTR_512 0x07000000 260#else
173#define EMAC_TRTR_256 0x03000000 261#define EMAC_RWMR(l,h) (((l) << 22) | ( ((h) & 0x3ff) << 6))
174#define EMAC_TRTR_192 0x10000000 262#endif
175#define EMAC_TRTR_128 0x01000000
176 263
264/* EMAC specific TX descriptor control fields (write access) */
177#define EMAC_TX_CTRL_GFCS 0x0200 265#define EMAC_TX_CTRL_GFCS 0x0200
178#define EMAC_TX_CTRL_GP 0x0100 266#define EMAC_TX_CTRL_GP 0x0100
179#define EMAC_TX_CTRL_ISA 0x0080 267#define EMAC_TX_CTRL_ISA 0x0080
180#define EMAC_TX_CTRL_RSA 0x0040 268#define EMAC_TX_CTRL_RSA 0x0040
181#define EMAC_TX_CTRL_IVT 0x0020 269#define EMAC_TX_CTRL_IVT 0x0020
182#define EMAC_TX_CTRL_RVT 0x0010 270#define EMAC_TX_CTRL_RVT 0x0010
183#define EMAC_TX_CTRL_TAH_CSUM 0x000e /* TAH only */ 271#define EMAC_TX_CTRL_TAH_CSUM 0x000e
184#define EMAC_TX_CTRL_TAH_SEG4 0x000a /* TAH only */
185#define EMAC_TX_CTRL_TAH_SEG3 0x0008 /* TAH only */
186#define EMAC_TX_CTRL_TAH_SEG2 0x0006 /* TAH only */
187#define EMAC_TX_CTRL_TAH_SEG1 0x0004 /* TAH only */
188#define EMAC_TX_CTRL_TAH_SEG0 0x0002 /* TAH only */
189#define EMAC_TX_CTRL_TAH_DIS 0x0000 /* TAH only */
190 272
191#define EMAC_TX_CTRL_DFLT ( \ 273/* EMAC specific TX descriptor status fields (read access) */
192 MAL_TX_CTRL_INTR | EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP )
193
194/* madmal transmit status / Control bits */
195#define EMAC_TX_ST_BFCS 0x0200 274#define EMAC_TX_ST_BFCS 0x0200
196#define EMAC_TX_ST_BPP 0x0100
197#define EMAC_TX_ST_LCS 0x0080 275#define EMAC_TX_ST_LCS 0x0080
198#define EMAC_TX_ST_ED 0x0040 276#define EMAC_TX_ST_ED 0x0040
199#define EMAC_TX_ST_EC 0x0020 277#define EMAC_TX_ST_EC 0x0020
@@ -202,8 +280,16 @@ typedef struct emac_regs {
202#define EMAC_TX_ST_SC 0x0004 280#define EMAC_TX_ST_SC 0x0004
203#define EMAC_TX_ST_UR 0x0002 281#define EMAC_TX_ST_UR 0x0002
204#define EMAC_TX_ST_SQE 0x0001 282#define EMAC_TX_ST_SQE 0x0001
283#if !defined(CONFIG_IBM_EMAC_TAH)
284#define EMAC_IS_BAD_TX(v) ((v) & (EMAC_TX_ST_LCS | EMAC_TX_ST_ED | \
285 EMAC_TX_ST_EC | EMAC_TX_ST_LC | \
286 EMAC_TX_ST_MC | EMAC_TX_ST_UR))
287#else
288#define EMAC_IS_BAD_TX(v) ((v) & (EMAC_TX_ST_LCS | EMAC_TX_ST_ED | \
289 EMAC_TX_ST_EC | EMAC_TX_ST_LC))
290#endif
205 291
206/* madmal receive status / Control bits */ 292/* EMAC specific RX descriptor status fields (read access) */
207#define EMAC_RX_ST_OE 0x0200 293#define EMAC_RX_ST_OE 0x0200
208#define EMAC_RX_ST_PP 0x0100 294#define EMAC_RX_ST_PP 0x0100
209#define EMAC_RX_ST_BP 0x0080 295#define EMAC_RX_ST_BP 0x0080
@@ -214,54 +300,10 @@ typedef struct emac_regs {
214#define EMAC_RX_ST_PTL 0x0004 300#define EMAC_RX_ST_PTL 0x0004
215#define EMAC_RX_ST_ORE 0x0002 301#define EMAC_RX_ST_ORE 0x0002
216#define EMAC_RX_ST_IRE 0x0001 302#define EMAC_RX_ST_IRE 0x0001
217#define EMAC_BAD_RX_PACKET 0x02ff 303#define EMAC_RX_TAH_BAD_CSUM 0x0003
218#define EMAC_CSUM_VER_ERROR 0x0003 304#define EMAC_BAD_RX_MASK (EMAC_RX_ST_OE | EMAC_RX_ST_BP | \
219 305 EMAC_RX_ST_RP | EMAC_RX_ST_SE | \
220/* identify a bad rx packet dependent on emac features */ 306 EMAC_RX_ST_AE | EMAC_RX_ST_BFCS | \
221#ifdef CONFIG_IBM_EMAC4 307 EMAC_RX_ST_PTL | EMAC_RX_ST_ORE | \
222#define EMAC_IS_BAD_RX_PACKET(desc) \ 308 EMAC_RX_ST_IRE )
223 (((desc & (EMAC_BAD_RX_PACKET & ~EMAC_CSUM_VER_ERROR)) || \ 309#endif /* __IBM_EMAC_H_ */
224 ((desc & EMAC_CSUM_VER_ERROR) == EMAC_RX_ST_ORE) || \
225 ((desc & EMAC_CSUM_VER_ERROR) == EMAC_RX_ST_IRE)))
226#else
227#define EMAC_IS_BAD_RX_PACKET(desc) \
228 (desc & EMAC_BAD_RX_PACKET)
229#endif
230
231/* SoC implementation specific EMAC register defaults */
232#if defined(CONFIG_440GP)
233#define EMAC_RWMR_DEFAULT 0x80009000
234#define EMAC_TMR0_DEFAULT 0x00000000
235#define EMAC_TMR1_DEFAULT 0xf8640000
236#elif defined(CONFIG_440GX)
237#define EMAC_RWMR_DEFAULT 0x1000a200
238#define EMAC_TMR0_DEFAULT EMAC_TMR0_TFAE_2_32
239#define EMAC_TMR1_DEFAULT 0xa00f0000
240#elif defined(CONFIG_440SP)
241#define EMAC_RWMR_DEFAULT 0x08002000
242#define EMAC_TMR0_DEFAULT EMAC_TMR0_TFAE_128_2048
243#define EMAC_TMR1_DEFAULT 0xf8200000
244#else
245#define EMAC_RWMR_DEFAULT 0x0f002000
246#define EMAC_TMR0_DEFAULT 0x00000000
247#define EMAC_TMR1_DEFAULT 0x380f0000
248#endif /* CONFIG_440GP */
249
250/* Revision specific EMAC register defaults */
251#ifdef CONFIG_IBM_EMAC4
252#define EMAC_M1_DEFAULT (EMAC_M1_BASE | \
253 EMAC_M1_OPB_CLK_83 | \
254 EMAC_M1_TX_MWSW)
255#define EMAC_RMR_DEFAULT (EMAC_RMR_BASE | \
256 EMAC_RMR_RFAF_128_2048)
257#define EMAC_TMR0_XMIT (EMAC_TMR0_GNP0 | \
258 EMAC_TMR0_DEFAULT)
259#define EMAC_TRTR_DEFAULT EMAC_TRTR_1024
260#else /* !CONFIG_IBM_EMAC4 */
261#define EMAC_M1_DEFAULT EMAC_M1_BASE
262#define EMAC_RMR_DEFAULT EMAC_RMR_BASE
263#define EMAC_TMR0_XMIT EMAC_TMR0_GNP0
264#define EMAC_TRTR_DEFAULT EMAC_TRTR_1600
265#endif /* CONFIG_IBM_EMAC4 */
266
267#endif
diff --git a/drivers/net/ibm_emac/ibm_emac_core.c b/drivers/net/ibm_emac/ibm_emac_core.c
index 14e9b6315f20..943fbd1546ff 100644
--- a/drivers/net/ibm_emac/ibm_emac_core.c
+++ b/drivers/net/ibm_emac/ibm_emac_core.c
@@ -1,13 +1,14 @@
1/* 1/*
2 * ibm_emac_core.c 2 * drivers/net/ibm_emac/ibm_emac_core.c
3 * 3 *
4 * Ethernet driver for the built in ethernet on the IBM 4xx PowerPC 4 * Driver for PowerPC 4xx on-chip ethernet controller.
5 * processors.
6 *
7 * (c) 2003 Benjamin Herrenschmidt <benh@kernel.crashing.org>
8 * 5 *
9 * Based on original work by 6 * Copyright (c) 2004, 2005 Zultys Technologies.
7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
10 * 8 *
9 * Based on original work by
10 * Matt Porter <mporter@kernel.crashing.org>
11 * (c) 2003 Benjamin Herrenschmidt <benh@kernel.crashing.org>
11 * Armin Kuster <akuster@mvista.com> 12 * Armin Kuster <akuster@mvista.com>
12 * Johnnie Peters <jpeters@mvista.com> 13 * Johnnie Peters <jpeters@mvista.com>
13 * 14 *
@@ -15,29 +16,24 @@
15 * under the terms of the GNU General Public License as published by the 16 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your 17 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version. 18 * option) any later version.
18 * TODO 19 *
19 * - Check for races in the "remove" code path
20 * - Add some Power Management to the MAC and the PHY
21 * - Audit remaining of non-rewritten code (--BenH)
22 * - Cleanup message display using msglevel mecanism
23 * - Address all errata
24 * - Audit all register update paths to ensure they
25 * are being written post soft reset if required.
26 */ 20 */
21
22#include <linux/config.h>
27#include <linux/module.h> 23#include <linux/module.h>
28#include <linux/kernel.h> 24#include <linux/kernel.h>
29#include <linux/sched.h> 25#include <linux/sched.h>
30#include <linux/string.h> 26#include <linux/string.h>
31#include <linux/timer.h>
32#include <linux/ptrace.h>
33#include <linux/errno.h> 27#include <linux/errno.h>
34#include <linux/ioport.h>
35#include <linux/slab.h>
36#include <linux/interrupt.h> 28#include <linux/interrupt.h>
37#include <linux/delay.h> 29#include <linux/delay.h>
38#include <linux/init.h> 30#include <linux/init.h>
39#include <linux/types.h> 31#include <linux/types.h>
40#include <linux/dma-mapping.h> 32#include <linux/pci.h>
33#include <linux/netdevice.h>
34#include <linux/etherdevice.h>
35#include <linux/skbuff.h>
36#include <linux/crc32.h>
41#include <linux/ethtool.h> 37#include <linux/ethtool.h>
42#include <linux/mii.h> 38#include <linux/mii.h>
43#include <linux/bitops.h> 39#include <linux/bitops.h>
@@ -45,1691 +41,1893 @@
45#include <asm/processor.h> 41#include <asm/processor.h>
46#include <asm/io.h> 42#include <asm/io.h>
47#include <asm/dma.h> 43#include <asm/dma.h>
48#include <asm/irq.h>
49#include <asm/uaccess.h> 44#include <asm/uaccess.h>
50#include <asm/ocp.h> 45#include <asm/ocp.h>
51 46
52#include <linux/netdevice.h>
53#include <linux/etherdevice.h>
54#include <linux/skbuff.h>
55#include <linux/crc32.h>
56
57#include "ibm_emac_core.h" 47#include "ibm_emac_core.h"
58 48#include "ibm_emac_debug.h"
59//#define MDIO_DEBUG(fmt) printk fmt
60#define MDIO_DEBUG(fmt)
61
62//#define LINK_DEBUG(fmt) printk fmt
63#define LINK_DEBUG(fmt)
64
65//#define PKT_DEBUG(fmt) printk fmt
66#define PKT_DEBUG(fmt)
67
68#define DRV_NAME "emac"
69#define DRV_VERSION "2.0"
70#define DRV_AUTHOR "Benjamin Herrenschmidt <benh@kernel.crashing.org>"
71#define DRV_DESC "IBM EMAC Ethernet driver"
72 49
73/* 50/*
74 * When mdio_idx >= 0, contains a list of emac ocp_devs 51 * Lack of dma_unmap_???? calls is intentional.
75 * that have had their initialization deferred until the 52 *
76 * common MDIO controller has been initialized. 53 * API-correct usage requires additional support state information to be
54 * maintained for every RX and TX buffer descriptor (BD). Unfortunately, due to
55 * EMAC design (e.g. TX buffer passed from network stack can be split into
56 * several BDs, dma_map_single/dma_map_page can be used to map particular BD),
57 * maintaining such information will add additional overhead.
58 * Current DMA API implementation for 4xx processors only ensures cache coherency
59 * and dma_unmap_???? routines are empty and are likely to stay this way.
60 * I decided to omit dma_unmap_??? calls because I don't want to add additional
61 * complexity just for the sake of following some abstract API, when it doesn't
62 * add any real benefit to the driver. I understand that this decision maybe
63 * controversial, but I really tried to make code API-correct and efficient
64 * at the same time and didn't come up with code I liked :(. --ebs
77 */ 65 */
78LIST_HEAD(emac_init_list);
79 66
80MODULE_AUTHOR(DRV_AUTHOR); 67#define DRV_NAME "emac"
68#define DRV_VERSION "3.53"
69#define DRV_DESC "PPC 4xx OCP EMAC driver"
70
81MODULE_DESCRIPTION(DRV_DESC); 71MODULE_DESCRIPTION(DRV_DESC);
72MODULE_AUTHOR
73 ("Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>");
82MODULE_LICENSE("GPL"); 74MODULE_LICENSE("GPL");
83 75
84static int skb_res = SKB_RES; 76/* minimum number of free TX descriptors required to wake up TX process */
85module_param(skb_res, int, 0444); 77#define EMAC_TX_WAKEUP_THRESH (NUM_TX_BUFF / 4)
86MODULE_PARM_DESC(skb_res, "Amount of data to reserve on skb buffs\n"
87 "The 405 handles a misaligned IP header fine but\n"
88 "this can help if you are routing to a tunnel or a\n"
89 "device that needs aligned data. 0..2");
90
91#define RGMII_PRIV(ocpdev) ((struct ibm_ocp_rgmii*)ocp_get_drvdata(ocpdev))
92 78
93static unsigned int rgmii_enable[] = { 79/* If packet size is less than this number, we allocate small skb and copy packet
94 RGMII_RTBI, 80 * contents into it instead of just sending original big skb up
95 RGMII_RGMII, 81 */
96 RGMII_TBI, 82#define EMAC_RX_COPY_THRESH CONFIG_IBM_EMAC_RX_COPY_THRESHOLD
97 RGMII_GMII
98};
99 83
100static unsigned int rgmii_speed_mask[] = { 84/* Since multiple EMACs share MDIO lines in various ways, we need
101 RGMII_MII2_SPDMASK, 85 * to avoid re-using the same PHY ID in cases where the arch didn't
102 RGMII_MII3_SPDMASK 86 * setup precise phy_map entries
103}; 87 */
88static u32 busy_phy_map;
104 89
105static unsigned int rgmii_speed100[] = { 90#if defined(CONFIG_IBM_EMAC_PHY_RX_CLK_FIX) && (defined(CONFIG_405EP) || defined(CONFIG_440EP))
106 RGMII_MII2_100MB, 91/* 405EP has "EMAC to PHY Control Register" (CPC0_EPCTL) which can help us
107 RGMII_MII3_100MB 92 * with PHY RX clock problem.
108}; 93 * 440EP has more sane SDR0_MFR register implementation than 440GX, which
94 * also allows controlling each EMAC clock
95 */
96static inline void EMAC_RX_CLK_TX(int idx)
97{
98 unsigned long flags;
99 local_irq_save(flags);
109 100
110static unsigned int rgmii_speed1000[] = { 101#if defined(CONFIG_405EP)
111 RGMII_MII2_1000MB, 102 mtdcr(0xf3, mfdcr(0xf3) | (1 << idx));
112 RGMII_MII3_1000MB 103#else /* CONFIG_440EP */
113}; 104 SDR_WRITE(DCRN_SDR_MFR, SDR_READ(DCRN_SDR_MFR) | (0x08000000 >> idx));
105#endif
114 106
115#define ZMII_PRIV(ocpdev) ((struct ibm_ocp_zmii*)ocp_get_drvdata(ocpdev)) 107 local_irq_restore(flags);
108}
116 109
117static unsigned int zmii_enable[][4] = { 110static inline void EMAC_RX_CLK_DEFAULT(int idx)
118 {ZMII_SMII0, ZMII_RMII0, ZMII_MII0, 111{
119 ~(ZMII_MDI1 | ZMII_MDI2 | ZMII_MDI3)}, 112 unsigned long flags;
120 {ZMII_SMII1, ZMII_RMII1, ZMII_MII1, 113 local_irq_save(flags);
121 ~(ZMII_MDI0 | ZMII_MDI2 | ZMII_MDI3)},
122 {ZMII_SMII2, ZMII_RMII2, ZMII_MII2,
123 ~(ZMII_MDI0 | ZMII_MDI1 | ZMII_MDI3)},
124 {ZMII_SMII3, ZMII_RMII3, ZMII_MII3, ~(ZMII_MDI0 | ZMII_MDI1 | ZMII_MDI2)}
125};
126 114
127static unsigned int mdi_enable[] = { 115#if defined(CONFIG_405EP)
128 ZMII_MDI0, 116 mtdcr(0xf3, mfdcr(0xf3) & ~(1 << idx));
129 ZMII_MDI1, 117#else /* CONFIG_440EP */
130 ZMII_MDI2, 118 SDR_WRITE(DCRN_SDR_MFR, SDR_READ(DCRN_SDR_MFR) & ~(0x08000000 >> idx));
131 ZMII_MDI3 119#endif
132};
133 120
134static unsigned int zmii_speed = 0x0; 121 local_irq_restore(flags);
135static unsigned int zmii_speed100[] = { 122}
136 ZMII_MII0_100MB, 123#else
137 ZMII_MII1_100MB, 124#define EMAC_RX_CLK_TX(idx) ((void)0)
138 ZMII_MII2_100MB, 125#define EMAC_RX_CLK_DEFAULT(idx) ((void)0)
139 ZMII_MII3_100MB 126#endif
140};
141 127
142/* Since multiple EMACs share MDIO lines in various ways, we need 128#if defined(CONFIG_IBM_EMAC_PHY_RX_CLK_FIX) && defined(CONFIG_440GX)
143 * to avoid re-using the same PHY ID in cases where the arch didn't 129/* We can switch Ethernet clock to the internal source through SDR0_MFR[ECS],
144 * setup precise phy_map entries 130 * unfortunately this is less flexible than 440EP case, because it's a global
131 * setting for all EMACs, therefore we do this clock trick only during probe.
145 */ 132 */
146static u32 busy_phy_map = 0; 133#define EMAC_CLK_INTERNAL SDR_WRITE(DCRN_SDR_MFR, \
134 SDR_READ(DCRN_SDR_MFR) | 0x08000000)
135#define EMAC_CLK_EXTERNAL SDR_WRITE(DCRN_SDR_MFR, \
136 SDR_READ(DCRN_SDR_MFR) & ~0x08000000)
137#else
138#define EMAC_CLK_INTERNAL ((void)0)
139#define EMAC_CLK_EXTERNAL ((void)0)
140#endif
147 141
148/* If EMACs share a common MDIO device, this points to it */ 142/* I don't want to litter system log with timeout errors
149static struct net_device *mdio_ndev = NULL; 143 * when we have brain-damaged PHY.
144 */
145static inline void emac_report_timeout_error(struct ocp_enet_private *dev,
146 const char *error)
147{
148#if defined(CONFIG_IBM_EMAC_PHY_RX_CLK_FIX)
149 DBG("%d: %s" NL, dev->def->index, error);
150#else
151 if (net_ratelimit())
152 printk(KERN_ERR "emac%d: %s\n", dev->def->index, error);
153#endif
154}
150 155
151struct emac_def_dev { 156/* PHY polling intervals */
152 struct list_head link; 157#define PHY_POLL_LINK_ON HZ
153 struct ocp_device *ocpdev; 158#define PHY_POLL_LINK_OFF (HZ / 5)
154 struct ibm_ocp_mal *mal; 159
160/* Please, keep in sync with struct ibm_emac_stats/ibm_emac_error_stats */
161static const char emac_stats_keys[EMAC_ETHTOOL_STATS_COUNT][ETH_GSTRING_LEN] = {
162 "rx_packets", "rx_bytes", "tx_packets", "tx_bytes", "rx_packets_csum",
163 "tx_packets_csum", "tx_undo", "rx_dropped_stack", "rx_dropped_oom",
164 "rx_dropped_error", "rx_dropped_resize", "rx_dropped_mtu",
165 "rx_stopped", "rx_bd_errors", "rx_bd_overrun", "rx_bd_bad_packet",
166 "rx_bd_runt_packet", "rx_bd_short_event", "rx_bd_alignment_error",
167 "rx_bd_bad_fcs", "rx_bd_packet_too_long", "rx_bd_out_of_range",
168 "rx_bd_in_range", "rx_parity", "rx_fifo_overrun", "rx_overrun",
169 "rx_bad_packet", "rx_runt_packet", "rx_short_event",
170 "rx_alignment_error", "rx_bad_fcs", "rx_packet_too_long",
171 "rx_out_of_range", "rx_in_range", "tx_dropped", "tx_bd_errors",
172 "tx_bd_bad_fcs", "tx_bd_carrier_loss", "tx_bd_excessive_deferral",
173 "tx_bd_excessive_collisions", "tx_bd_late_collision",
174 "tx_bd_multple_collisions", "tx_bd_single_collision",
175 "tx_bd_underrun", "tx_bd_sqe", "tx_parity", "tx_underrun", "tx_sqe",
176 "tx_errors"
155}; 177};
156 178
157static struct net_device_stats *emac_stats(struct net_device *dev) 179static irqreturn_t emac_irq(int irq, void *dev_instance, struct pt_regs *regs);
180static void emac_clean_tx_ring(struct ocp_enet_private *dev);
181
182static inline int emac_phy_supports_gige(int phy_mode)
158{ 183{
159 struct ocp_enet_private *fep = dev->priv; 184 return phy_mode == PHY_MODE_GMII ||
160 return &fep->stats; 185 phy_mode == PHY_MODE_RGMII ||
161}; 186 phy_mode == PHY_MODE_TBI ||
187 phy_mode == PHY_MODE_RTBI;
188}
162 189
163static int 190static inline int emac_phy_gpcs(int phy_mode)
164emac_init_rgmii(struct ocp_device *rgmii_dev, int input, int phy_mode)
165{ 191{
166 struct ibm_ocp_rgmii *rgmii = RGMII_PRIV(rgmii_dev); 192 return phy_mode == PHY_MODE_TBI ||
167 const char *mode_name[] = { "RTBI", "RGMII", "TBI", "GMII" }; 193 phy_mode == PHY_MODE_RTBI;
168 int mode = -1; 194}
169 195
170 if (!rgmii) { 196static inline void emac_tx_enable(struct ocp_enet_private *dev)
171 rgmii = kmalloc(sizeof(struct ibm_ocp_rgmii), GFP_KERNEL); 197{
198 struct emac_regs *p = dev->emacp;
199 unsigned long flags;
200 u32 r;
172 201
173 if (rgmii == NULL) { 202 local_irq_save(flags);
174 printk(KERN_ERR
175 "rgmii%d: Out of memory allocating RGMII structure!\n",
176 rgmii_dev->def->index);
177 return -ENOMEM;
178 }
179 203
180 memset(rgmii, 0, sizeof(*rgmii)); 204 DBG("%d: tx_enable" NL, dev->def->index);
181 205
182 rgmii->base = 206 r = in_be32(&p->mr0);
183 (struct rgmii_regs *)ioremap(rgmii_dev->def->paddr, 207 if (!(r & EMAC_MR0_TXE))
184 sizeof(*rgmii->base)); 208 out_be32(&p->mr0, r | EMAC_MR0_TXE);
185 if (rgmii->base == NULL) { 209 local_irq_restore(flags);
186 printk(KERN_ERR 210}
187 "rgmii%d: Cannot ioremap bridge registers!\n",
188 rgmii_dev->def->index);
189 211
190 kfree(rgmii); 212static void emac_tx_disable(struct ocp_enet_private *dev)
191 return -ENOMEM; 213{
192 } 214 struct emac_regs *p = dev->emacp;
193 ocp_set_drvdata(rgmii_dev, rgmii); 215 unsigned long flags;
194 } 216 u32 r;
195 217
196 if (phy_mode) { 218 local_irq_save(flags);
197 switch (phy_mode) { 219
198 case PHY_MODE_GMII: 220 DBG("%d: tx_disable" NL, dev->def->index);
199 mode = GMII;
200 break;
201 case PHY_MODE_TBI:
202 mode = TBI;
203 break;
204 case PHY_MODE_RTBI:
205 mode = RTBI;
206 break;
207 case PHY_MODE_RGMII:
208 default:
209 mode = RGMII;
210 }
211 rgmii->base->fer &= ~RGMII_FER_MASK(input);
212 rgmii->base->fer |= rgmii_enable[mode] << (4 * input);
213 } else {
214 switch ((rgmii->base->fer & RGMII_FER_MASK(input)) >> (4 *
215 input)) {
216 case RGMII_RTBI:
217 mode = RTBI;
218 break;
219 case RGMII_RGMII:
220 mode = RGMII;
221 break;
222 case RGMII_TBI:
223 mode = TBI;
224 break;
225 case RGMII_GMII:
226 mode = GMII;
227 }
228 }
229 221
230 /* Set mode to RGMII if nothing valid is detected */ 222 r = in_be32(&p->mr0);
231 if (mode < 0) 223 if (r & EMAC_MR0_TXE) {
232 mode = RGMII; 224 int n = 300;
225 out_be32(&p->mr0, r & ~EMAC_MR0_TXE);
226 while (!(in_be32(&p->mr0) & EMAC_MR0_TXI) && n)
227 --n;
228 if (unlikely(!n))
229 emac_report_timeout_error(dev, "TX disable timeout");
230 }
231 local_irq_restore(flags);
232}
233 233
234 printk(KERN_NOTICE "rgmii%d: input %d in %s mode\n", 234static void emac_rx_enable(struct ocp_enet_private *dev)
235 rgmii_dev->def->index, input, mode_name[mode]); 235{
236 struct emac_regs *p = dev->emacp;
237 unsigned long flags;
238 u32 r;
236 239
237 rgmii->mode[input] = mode; 240 local_irq_save(flags);
238 rgmii->users++; 241 if (unlikely(dev->commac.rx_stopped))
242 goto out;
239 243
240 return 0; 244 DBG("%d: rx_enable" NL, dev->def->index);
245
246 r = in_be32(&p->mr0);
247 if (!(r & EMAC_MR0_RXE)) {
248 if (unlikely(!(r & EMAC_MR0_RXI))) {
249 /* Wait if previous async disable is still in progress */
250 int n = 100;
251 while (!(r = in_be32(&p->mr0) & EMAC_MR0_RXI) && n)
252 --n;
253 if (unlikely(!n))
254 emac_report_timeout_error(dev,
255 "RX disable timeout");
256 }
257 out_be32(&p->mr0, r | EMAC_MR0_RXE);
258 }
259 out:
260 local_irq_restore(flags);
241} 261}
242 262
243static void 263static void emac_rx_disable(struct ocp_enet_private *dev)
244emac_rgmii_port_speed(struct ocp_device *ocpdev, int input, int speed)
245{ 264{
246 struct ibm_ocp_rgmii *rgmii = RGMII_PRIV(ocpdev); 265 struct emac_regs *p = dev->emacp;
247 unsigned int rgmii_speed; 266 unsigned long flags;
248 267 u32 r;
249 rgmii_speed = in_be32(&rgmii->base->ssr);
250 268
251 rgmii_speed &= ~rgmii_speed_mask[input]; 269 local_irq_save(flags);
252 270
253 if (speed == 1000) 271 DBG("%d: rx_disable" NL, dev->def->index);
254 rgmii_speed |= rgmii_speed1000[input];
255 else if (speed == 100)
256 rgmii_speed |= rgmii_speed100[input];
257 272
258 out_be32(&rgmii->base->ssr, rgmii_speed); 273 r = in_be32(&p->mr0);
274 if (r & EMAC_MR0_RXE) {
275 int n = 300;
276 out_be32(&p->mr0, r & ~EMAC_MR0_RXE);
277 while (!(in_be32(&p->mr0) & EMAC_MR0_RXI) && n)
278 --n;
279 if (unlikely(!n))
280 emac_report_timeout_error(dev, "RX disable timeout");
281 }
282 local_irq_restore(flags);
259} 283}
260 284
261static void emac_close_rgmii(struct ocp_device *ocpdev) 285static inline void emac_rx_disable_async(struct ocp_enet_private *dev)
262{ 286{
263 struct ibm_ocp_rgmii *rgmii = RGMII_PRIV(ocpdev); 287 struct emac_regs *p = dev->emacp;
264 BUG_ON(!rgmii || rgmii->users == 0); 288 unsigned long flags;
289 u32 r;
265 290
266 if (!--rgmii->users) { 291 local_irq_save(flags);
267 ocp_set_drvdata(ocpdev, NULL); 292
268 iounmap((void *)rgmii->base); 293 DBG("%d: rx_disable_async" NL, dev->def->index);
269 kfree(rgmii); 294
270 } 295 r = in_be32(&p->mr0);
296 if (r & EMAC_MR0_RXE)
297 out_be32(&p->mr0, r & ~EMAC_MR0_RXE);
298 local_irq_restore(flags);
271} 299}
272 300
273static int emac_init_zmii(struct ocp_device *zmii_dev, int input, int phy_mode) 301static int emac_reset(struct ocp_enet_private *dev)
274{ 302{
275 struct ibm_ocp_zmii *zmii = ZMII_PRIV(zmii_dev); 303 struct emac_regs *p = dev->emacp;
276 const char *mode_name[] = { "SMII", "RMII", "MII" }; 304 unsigned long flags;
277 int mode = -1; 305 int n = 20;
278 306
279 if (!zmii) { 307 DBG("%d: reset" NL, dev->def->index);
280 zmii = kmalloc(sizeof(struct ibm_ocp_zmii), GFP_KERNEL);
281 if (zmii == NULL) {
282 printk(KERN_ERR
283 "zmii%d: Out of memory allocating ZMII structure!\n",
284 zmii_dev->def->index);
285 return -ENOMEM;
286 }
287 memset(zmii, 0, sizeof(*zmii));
288 308
289 zmii->base = 309 local_irq_save(flags);
290 (struct zmii_regs *)ioremap(zmii_dev->def->paddr,
291 sizeof(*zmii->base));
292 if (zmii->base == NULL) {
293 printk(KERN_ERR
294 "zmii%d: Cannot ioremap bridge registers!\n",
295 zmii_dev->def->index);
296 310
297 kfree(zmii); 311 if (!dev->reset_failed) {
298 return -ENOMEM; 312 /* 40x erratum suggests stopping RX channel before reset,
299 } 313 * we stop TX as well
300 ocp_set_drvdata(zmii_dev, zmii); 314 */
315 emac_rx_disable(dev);
316 emac_tx_disable(dev);
301 } 317 }
302 318
303 if (phy_mode) { 319 out_be32(&p->mr0, EMAC_MR0_SRST);
304 switch (phy_mode) { 320 while ((in_be32(&p->mr0) & EMAC_MR0_SRST) && n)
305 case PHY_MODE_MII: 321 --n;
306 mode = MII; 322 local_irq_restore(flags);
307 break; 323
308 case PHY_MODE_RMII: 324 if (n) {
309 mode = RMII; 325 dev->reset_failed = 0;
310 break; 326 return 0;
311 case PHY_MODE_SMII:
312 default:
313 mode = SMII;
314 }
315 zmii->base->fer &= ~ZMII_FER_MASK(input);
316 zmii->base->fer |= zmii_enable[input][mode];
317 } else { 327 } else {
318 switch ((zmii->base->fer & ZMII_FER_MASK(input)) << (4 * input)) { 328 emac_report_timeout_error(dev, "reset timeout");
319 case ZMII_MII0: 329 dev->reset_failed = 1;
320 mode = MII; 330 return -ETIMEDOUT;
321 break;
322 case ZMII_RMII0:
323 mode = RMII;
324 break;
325 case ZMII_SMII0:
326 mode = SMII;
327 }
328 } 331 }
332}
329 333
330 /* Set mode to SMII if nothing valid is detected */ 334static void emac_hash_mc(struct ocp_enet_private *dev)
331 if (mode < 0) 335{
332 mode = SMII; 336 struct emac_regs *p = dev->emacp;
337 u16 gaht[4] = { 0 };
338 struct dev_mc_list *dmi;
333 339
334 printk(KERN_NOTICE "zmii%d: input %d in %s mode\n", 340 DBG("%d: hash_mc %d" NL, dev->def->index, dev->ndev->mc_count);
335 zmii_dev->def->index, input, mode_name[mode]);
336 341
337 zmii->mode[input] = mode; 342 for (dmi = dev->ndev->mc_list; dmi; dmi = dmi->next) {
338 zmii->users++; 343 int bit;
344 DBG2("%d: mc %02x:%02x:%02x:%02x:%02x:%02x" NL,
345 dev->def->index,
346 dmi->dmi_addr[0], dmi->dmi_addr[1], dmi->dmi_addr[2],
347 dmi->dmi_addr[3], dmi->dmi_addr[4], dmi->dmi_addr[5]);
339 348
340 return 0; 349 bit = 63 - (ether_crc(ETH_ALEN, dmi->dmi_addr) >> 26);
350 gaht[bit >> 4] |= 0x8000 >> (bit & 0x0f);
351 }
352 out_be32(&p->gaht1, gaht[0]);
353 out_be32(&p->gaht2, gaht[1]);
354 out_be32(&p->gaht3, gaht[2]);
355 out_be32(&p->gaht4, gaht[3]);
341} 356}
342 357
343static void emac_enable_zmii_port(struct ocp_device *ocpdev, int input) 358static inline u32 emac_iff2rmr(struct net_device *ndev)
344{ 359{
345 u32 mask; 360 u32 r = EMAC_RMR_SP | EMAC_RMR_SFCS | EMAC_RMR_IAE | EMAC_RMR_BAE |
346 struct ibm_ocp_zmii *zmii = ZMII_PRIV(ocpdev); 361 EMAC_RMR_BASE;
347 362
348 mask = in_be32(&zmii->base->fer); 363 if (ndev->flags & IFF_PROMISC)
349 mask &= zmii_enable[input][MDI]; /* turn all non enabled MDI's off */ 364 r |= EMAC_RMR_PME;
350 mask |= zmii_enable[input][zmii->mode[input]] | mdi_enable[input]; 365 else if (ndev->flags & IFF_ALLMULTI || ndev->mc_count > 32)
351 out_be32(&zmii->base->fer, mask); 366 r |= EMAC_RMR_PMME;
367 else if (ndev->mc_count > 0)
368 r |= EMAC_RMR_MAE;
369
370 return r;
352} 371}
353 372
354static void 373static inline int emac_opb_mhz(void)
355emac_zmii_port_speed(struct ocp_device *ocpdev, int input, int speed)
356{ 374{
357 struct ibm_ocp_zmii *zmii = ZMII_PRIV(ocpdev); 375 return (ocp_sys_info.opb_bus_freq + 500000) / 1000000;
358
359 if (speed == 100)
360 zmii_speed |= zmii_speed100[input];
361 else
362 zmii_speed &= ~zmii_speed100[input];
363
364 out_be32(&zmii->base->ssr, zmii_speed);
365} 376}
366 377
367static void emac_close_zmii(struct ocp_device *ocpdev) 378/* BHs disabled */
379static int emac_configure(struct ocp_enet_private *dev)
368{ 380{
369 struct ibm_ocp_zmii *zmii = ZMII_PRIV(ocpdev); 381 struct emac_regs *p = dev->emacp;
370 BUG_ON(!zmii || zmii->users == 0); 382 struct net_device *ndev = dev->ndev;
383 int gige;
384 u32 r;
371 385
372 if (!--zmii->users) { 386 DBG("%d: configure" NL, dev->def->index);
373 ocp_set_drvdata(ocpdev, NULL);
374 iounmap((void *)zmii->base);
375 kfree(zmii);
376 }
377}
378 387
379int emac_phy_read(struct net_device *dev, int mii_id, int reg) 388 if (emac_reset(dev) < 0)
380{ 389 return -ETIMEDOUT;
381 int count;
382 uint32_t stacr;
383 struct ocp_enet_private *fep = dev->priv;
384 emac_t *emacp = fep->emacp;
385 390
386 MDIO_DEBUG(("%s: phy_read, id: 0x%x, reg: 0x%x\n", dev->name, mii_id, 391 tah_reset(dev->tah_dev);
387 reg));
388 392
389 /* Enable proper ZMII port */ 393 /* Mode register */
390 if (fep->zmii_dev) 394 r = EMAC_MR1_BASE(emac_opb_mhz()) | EMAC_MR1_VLE | EMAC_MR1_IST;
391 emac_enable_zmii_port(fep->zmii_dev, fep->zmii_input); 395 if (dev->phy.duplex == DUPLEX_FULL)
396 r |= EMAC_MR1_FDE;
397 switch (dev->phy.speed) {
398 case SPEED_1000:
399 if (emac_phy_gpcs(dev->phy.mode)) {
400 r |= EMAC_MR1_MF_1000GPCS |
401 EMAC_MR1_MF_IPPA(dev->phy.address);
392 402
393 /* Use the EMAC that has the MDIO port */ 403 /* Put some arbitrary OUI, Manuf & Rev IDs so we can
394 if (fep->mdio_dev) { 404 * identify this GPCS PHY later.
395 dev = fep->mdio_dev; 405 */
396 fep = dev->priv; 406 out_be32(&p->ipcr, 0xdeadbeef);
397 emacp = fep->emacp; 407 } else
408 r |= EMAC_MR1_MF_1000;
409 r |= EMAC_MR1_RFS_16K;
410 gige = 1;
411
412 if (dev->ndev->mtu > ETH_DATA_LEN)
413 r |= EMAC_MR1_JPSM;
414 break;
415 case SPEED_100:
416 r |= EMAC_MR1_MF_100;
417 /* Fall through */
418 default:
419 r |= EMAC_MR1_RFS_4K;
420 gige = 0;
421 break;
398 } 422 }
399 423
400 count = 0; 424 if (dev->rgmii_dev)
401 while ((((stacr = in_be32(&emacp->em0stacr)) & EMAC_STACR_OC) == 0) 425 rgmii_set_speed(dev->rgmii_dev, dev->rgmii_input,
402 && (count++ < MDIO_DELAY)) 426 dev->phy.speed);
403 udelay(1); 427 else
404 MDIO_DEBUG((" (count was %d)\n", count)); 428 zmii_set_speed(dev->zmii_dev, dev->zmii_input, dev->phy.speed);
405 429
406 if ((stacr & EMAC_STACR_OC) == 0) { 430#if !defined(CONFIG_40x)
407 printk(KERN_WARNING "%s: PHY read timeout #1!\n", dev->name); 431 /* on 40x erratum forces us to NOT use integrated flow control,
408 return -1; 432 * let's hope it works on 44x ;)
433 */
434 if (dev->phy.duplex == DUPLEX_FULL) {
435 if (dev->phy.pause)
436 r |= EMAC_MR1_EIFC | EMAC_MR1_APP;
437 else if (dev->phy.asym_pause)
438 r |= EMAC_MR1_APP;
409 } 439 }
440#endif
441 out_be32(&p->mr1, r);
442
443 /* Set individual MAC address */
444 out_be32(&p->iahr, (ndev->dev_addr[0] << 8) | ndev->dev_addr[1]);
445 out_be32(&p->ialr, (ndev->dev_addr[2] << 24) |
446 (ndev->dev_addr[3] << 16) | (ndev->dev_addr[4] << 8) |
447 ndev->dev_addr[5]);
448
449 /* VLAN Tag Protocol ID */
450 out_be32(&p->vtpid, 0x8100);
451
452 /* Receive mode register */
453 r = emac_iff2rmr(ndev);
454 if (r & EMAC_RMR_MAE)
455 emac_hash_mc(dev);
456 out_be32(&p->rmr, r);
457
458 /* FIFOs thresholds */
459 r = EMAC_TMR1((EMAC_MAL_BURST_SIZE / EMAC_FIFO_ENTRY_SIZE) + 1,
460 EMAC_TX_FIFO_SIZE / 2 / EMAC_FIFO_ENTRY_SIZE);
461 out_be32(&p->tmr1, r);
462 out_be32(&p->trtr, EMAC_TRTR(EMAC_TX_FIFO_SIZE / 2));
463
464 /* PAUSE frame is sent when RX FIFO reaches its high-water mark,
465 there should be still enough space in FIFO to allow the our link
466 partner time to process this frame and also time to send PAUSE
467 frame itself.
468
469 Here is the worst case scenario for the RX FIFO "headroom"
470 (from "The Switch Book") (100Mbps, without preamble, inter-frame gap):
471
472 1) One maximum-length frame on TX 1522 bytes
473 2) One PAUSE frame time 64 bytes
474 3) PAUSE frame decode time allowance 64 bytes
475 4) One maximum-length frame on RX 1522 bytes
476 5) Round-trip propagation delay of the link (100Mb) 15 bytes
477 ----------
478 3187 bytes
479
480 I chose to set high-water mark to RX_FIFO_SIZE / 4 (1024 bytes)
481 low-water mark to RX_FIFO_SIZE / 8 (512 bytes)
482 */
483 r = EMAC_RWMR(EMAC_RX_FIFO_SIZE(gige) / 8 / EMAC_FIFO_ENTRY_SIZE,
484 EMAC_RX_FIFO_SIZE(gige) / 4 / EMAC_FIFO_ENTRY_SIZE);
485 out_be32(&p->rwmr, r);
486
487 /* Set PAUSE timer to the maximum */
488 out_be32(&p->ptr, 0xffff);
489
490 /* IRQ sources */
491 out_be32(&p->iser, EMAC_ISR_TXPE | EMAC_ISR_RXPE | /* EMAC_ISR_TXUE |
492 EMAC_ISR_RXOE | */ EMAC_ISR_OVR | EMAC_ISR_BP | EMAC_ISR_SE |
493 EMAC_ISR_ALE | EMAC_ISR_BFCS | EMAC_ISR_PTLE | EMAC_ISR_ORE |
494 EMAC_ISR_IRE | EMAC_ISR_TE);
495
496 /* We need to take GPCS PHY out of isolate mode after EMAC reset */
497 if (emac_phy_gpcs(dev->phy.mode))
498 mii_reset_phy(&dev->phy);
499
500 return 0;
501}
410 502
411 /* Clear the speed bits and make a read request to the PHY */ 503/* BHs disabled */
412 stacr = ((EMAC_STACR_READ | (reg & 0x1f)) & ~EMAC_STACR_CLK_100MHZ); 504static void emac_reinitialize(struct ocp_enet_private *dev)
413 stacr |= ((mii_id & 0x1F) << 5); 505{
506 DBG("%d: reinitialize" NL, dev->def->index);
414 507
415 out_be32(&emacp->em0stacr, stacr); 508 if (!emac_configure(dev)) {
509 emac_tx_enable(dev);
510 emac_rx_enable(dev);
511 }
512}
416 513
417 count = 0; 514/* BHs disabled */
418 while ((((stacr = in_be32(&emacp->em0stacr)) & EMAC_STACR_OC) == 0) 515static void emac_full_tx_reset(struct net_device *ndev)
419 && (count++ < MDIO_DELAY)) 516{
420 udelay(1); 517 struct ocp_enet_private *dev = ndev->priv;
421 MDIO_DEBUG((" (count was %d)\n", count)); 518 struct ocp_func_emac_data *emacdata = dev->def->additions;
422 519
423 if ((stacr & EMAC_STACR_OC) == 0) { 520 DBG("%d: full_tx_reset" NL, dev->def->index);
424 printk(KERN_WARNING "%s: PHY read timeout #2!\n", dev->name);
425 return -1;
426 }
427 521
428 /* Check for a read error */ 522 emac_tx_disable(dev);
429 if (stacr & EMAC_STACR_PHYE) { 523 mal_disable_tx_channel(dev->mal, emacdata->mal_tx_chan);
430 MDIO_DEBUG(("EMAC MDIO PHY error !\n")); 524 emac_clean_tx_ring(dev);
431 return -1; 525 dev->tx_cnt = dev->tx_slot = dev->ack_slot = 0;
432 }
433 526
434 MDIO_DEBUG((" -> 0x%x\n", stacr >> 16)); 527 emac_configure(dev);
435 528
436 return (stacr >> 16); 529 mal_enable_tx_channel(dev->mal, emacdata->mal_tx_chan);
530 emac_tx_enable(dev);
531 emac_rx_enable(dev);
532
533 netif_wake_queue(ndev);
437} 534}
438 535
439void emac_phy_write(struct net_device *dev, int mii_id, int reg, int data) 536static int __emac_mdio_read(struct ocp_enet_private *dev, u8 id, u8 reg)
440{ 537{
441 int count; 538 struct emac_regs *p = dev->emacp;
442 uint32_t stacr; 539 u32 r;
443 struct ocp_enet_private *fep = dev->priv; 540 int n;
444 emac_t *emacp = fep->emacp;
445 541
446 MDIO_DEBUG(("%s phy_write, id: 0x%x, reg: 0x%x, data: 0x%x\n", 542 DBG2("%d: mdio_read(%02x,%02x)" NL, dev->def->index, id, reg);
447 dev->name, mii_id, reg, data));
448 543
449 /* Enable proper ZMII port */ 544 /* Enable proper MDIO port */
450 if (fep->zmii_dev) 545 zmii_enable_mdio(dev->zmii_dev, dev->zmii_input);
451 emac_enable_zmii_port(fep->zmii_dev, fep->zmii_input);
452 546
453 /* Use the EMAC that has the MDIO port */ 547 /* Wait for management interface to become idle */
454 if (fep->mdio_dev) { 548 n = 10;
455 dev = fep->mdio_dev; 549 while (!(in_be32(&p->stacr) & EMAC_STACR_OC)) {
456 fep = dev->priv; 550 udelay(1);
457 emacp = fep->emacp; 551 if (!--n)
552 goto to;
458 } 553 }
459 554
460 count = 0; 555 /* Issue read command */
461 while ((((stacr = in_be32(&emacp->em0stacr)) & EMAC_STACR_OC) == 0) 556 out_be32(&p->stacr,
462 && (count++ < MDIO_DELAY)) 557 EMAC_STACR_BASE(emac_opb_mhz()) | EMAC_STACR_STAC_READ |
558 (reg & EMAC_STACR_PRA_MASK)
559 | ((id & EMAC_STACR_PCDA_MASK) << EMAC_STACR_PCDA_SHIFT));
560
561 /* Wait for read to complete */
562 n = 100;
563 while (!((r = in_be32(&p->stacr)) & EMAC_STACR_OC)) {
463 udelay(1); 564 udelay(1);
464 MDIO_DEBUG((" (count was %d)\n", count)); 565 if (!--n)
566 goto to;
567 }
465 568
466 if ((stacr & EMAC_STACR_OC) == 0) { 569 if (unlikely(r & EMAC_STACR_PHYE)) {
467 printk(KERN_WARNING "%s: PHY write timeout #2!\n", dev->name); 570 DBG("%d: mdio_read(%02x, %02x) failed" NL, dev->def->index,
468 return; 571 id, reg);
572 return -EREMOTEIO;
469 } 573 }
470 574
471 /* Clear the speed bits and make a read request to the PHY */ 575 r = ((r >> EMAC_STACR_PHYD_SHIFT) & EMAC_STACR_PHYD_MASK);
576 DBG2("%d: mdio_read -> %04x" NL, dev->def->index, r);
577 return r;
578 to:
579 DBG("%d: MII management interface timeout (read)" NL, dev->def->index);
580 return -ETIMEDOUT;
581}
472 582
473 stacr = ((EMAC_STACR_WRITE | (reg & 0x1f)) & ~EMAC_STACR_CLK_100MHZ); 583static void __emac_mdio_write(struct ocp_enet_private *dev, u8 id, u8 reg,
474 stacr |= ((mii_id & 0x1f) << 5) | ((data & 0xffff) << 16); 584 u16 val)
585{
586 struct emac_regs *p = dev->emacp;
587 int n;
475 588
476 out_be32(&emacp->em0stacr, stacr); 589 DBG2("%d: mdio_write(%02x,%02x,%04x)" NL, dev->def->index, id, reg,
590 val);
477 591
478 count = 0; 592 /* Enable proper MDIO port */
479 while ((((stacr = in_be32(&emacp->em0stacr)) & EMAC_STACR_OC) == 0) 593 zmii_enable_mdio(dev->zmii_dev, dev->zmii_input);
480 && (count++ < MDIO_DELAY)) 594
595 /* Wait for management interface to be idle */
596 n = 10;
597 while (!(in_be32(&p->stacr) & EMAC_STACR_OC)) {
481 udelay(1); 598 udelay(1);
482 MDIO_DEBUG((" (count was %d)\n", count)); 599 if (!--n)
600 goto to;
601 }
483 602
484 if ((stacr & EMAC_STACR_OC) == 0) 603 /* Issue write command */
485 printk(KERN_WARNING "%s: PHY write timeout #2!\n", dev->name); 604 out_be32(&p->stacr,
605 EMAC_STACR_BASE(emac_opb_mhz()) | EMAC_STACR_STAC_WRITE |
606 (reg & EMAC_STACR_PRA_MASK) |
607 ((id & EMAC_STACR_PCDA_MASK) << EMAC_STACR_PCDA_SHIFT) |
608 (val << EMAC_STACR_PHYD_SHIFT));
486 609
487 /* Check for a write error */ 610 /* Wait for write to complete */
488 if ((stacr & EMAC_STACR_PHYE) != 0) { 611 n = 100;
489 MDIO_DEBUG(("EMAC MDIO PHY error !\n")); 612 while (!(in_be32(&p->stacr) & EMAC_STACR_OC)) {
613 udelay(1);
614 if (!--n)
615 goto to;
490 } 616 }
617 return;
618 to:
619 DBG("%d: MII management interface timeout (write)" NL, dev->def->index);
491} 620}
492 621
493static void emac_txeob_dev(void *param, u32 chanmask) 622static int emac_mdio_read(struct net_device *ndev, int id, int reg)
494{ 623{
495 struct net_device *dev = param; 624 struct ocp_enet_private *dev = ndev->priv;
496 struct ocp_enet_private *fep = dev->priv; 625 int res;
497 unsigned long flags; 626
498 627 local_bh_disable();
499 spin_lock_irqsave(&fep->lock, flags); 628 res = __emac_mdio_read(dev->mdio_dev ? dev->mdio_dev : dev, (u8) id,
500 629 (u8) reg);
501 PKT_DEBUG(("emac_txeob_dev() entry, tx_cnt: %d\n", fep->tx_cnt)); 630 local_bh_enable();
502 631 return res;
503 while (fep->tx_cnt && 632}
504 !(fep->tx_desc[fep->ack_slot].ctrl & MAL_TX_CTRL_READY)) {
505 633
506 if (fep->tx_desc[fep->ack_slot].ctrl & MAL_TX_CTRL_LAST) { 634static void emac_mdio_write(struct net_device *ndev, int id, int reg, int val)
507 /* Tell the system the transmit completed. */ 635{
508 dma_unmap_single(&fep->ocpdev->dev, 636 struct ocp_enet_private *dev = ndev->priv;
509 fep->tx_desc[fep->ack_slot].data_ptr,
510 fep->tx_desc[fep->ack_slot].data_len,
511 DMA_TO_DEVICE);
512 dev_kfree_skb_irq(fep->tx_skb[fep->ack_slot]);
513 637
514 if (fep->tx_desc[fep->ack_slot].ctrl & 638 local_bh_disable();
515 (EMAC_TX_ST_EC | EMAC_TX_ST_MC | EMAC_TX_ST_SC)) 639 __emac_mdio_write(dev->mdio_dev ? dev->mdio_dev : dev, (u8) id,
516 fep->stats.collisions++; 640 (u8) reg, (u16) val);
517 } 641 local_bh_enable();
642}
518 643
519 fep->tx_skb[fep->ack_slot] = (struct sk_buff *)NULL; 644/* BHs disabled */
520 if (++fep->ack_slot == NUM_TX_BUFF) 645static void emac_set_multicast_list(struct net_device *ndev)
521 fep->ack_slot = 0; 646{
647 struct ocp_enet_private *dev = ndev->priv;
648 struct emac_regs *p = dev->emacp;
649 u32 rmr = emac_iff2rmr(ndev);
650
651 DBG("%d: multicast %08x" NL, dev->def->index, rmr);
652 BUG_ON(!netif_running(dev->ndev));
653
654 /* I decided to relax register access rules here to avoid
655 * full EMAC reset.
656 *
657 * There is a real problem with EMAC4 core if we use MWSW_001 bit
658 * in MR1 register and do a full EMAC reset.
659 * One TX BD status update is delayed and, after EMAC reset, it
660 * never happens, resulting in TX hung (it'll be recovered by TX
661 * timeout handler eventually, but this is just gross).
662 * So we either have to do full TX reset or try to cheat here :)
663 *
664 * The only required change is to RX mode register, so I *think* all
665 * we need is just to stop RX channel. This seems to work on all
666 * tested SoCs. --ebs
667 */
668 emac_rx_disable(dev);
669 if (rmr & EMAC_RMR_MAE)
670 emac_hash_mc(dev);
671 out_be32(&p->rmr, rmr);
672 emac_rx_enable(dev);
673}
522 674
523 fep->tx_cnt--; 675/* BHs disabled */
676static int emac_resize_rx_ring(struct ocp_enet_private *dev, int new_mtu)
677{
678 struct ocp_func_emac_data *emacdata = dev->def->additions;
679 int rx_sync_size = emac_rx_sync_size(new_mtu);
680 int rx_skb_size = emac_rx_skb_size(new_mtu);
681 int i, ret = 0;
682
683 emac_rx_disable(dev);
684 mal_disable_rx_channel(dev->mal, emacdata->mal_rx_chan);
685
686 if (dev->rx_sg_skb) {
687 ++dev->estats.rx_dropped_resize;
688 dev_kfree_skb(dev->rx_sg_skb);
689 dev->rx_sg_skb = NULL;
524 } 690 }
525 if (fep->tx_cnt < NUM_TX_BUFF)
526 netif_wake_queue(dev);
527 691
528 PKT_DEBUG(("emac_txeob_dev() exit, tx_cnt: %d\n", fep->tx_cnt)); 692 /* Make a first pass over RX ring and mark BDs ready, dropping
693 * non-processed packets on the way. We need this as a separate pass
694 * to simplify error recovery in the case of allocation failure later.
695 */
696 for (i = 0; i < NUM_RX_BUFF; ++i) {
697 if (dev->rx_desc[i].ctrl & MAL_RX_CTRL_FIRST)
698 ++dev->estats.rx_dropped_resize;
529 699
530 spin_unlock_irqrestore(&fep->lock, flags); 700 dev->rx_desc[i].data_len = 0;
531} 701 dev->rx_desc[i].ctrl = MAL_RX_CTRL_EMPTY |
702 (i == (NUM_RX_BUFF - 1) ? MAL_RX_CTRL_WRAP : 0);
703 }
532 704
533/* 705 /* Reallocate RX ring only if bigger skb buffers are required */
534 Fill/Re-fill the rx chain with valid ctrl/ptrs. 706 if (rx_skb_size <= dev->rx_skb_size)
535 This function will fill from rx_slot up to the parm end. 707 goto skip;
536 So to completely fill the chain pre-set rx_slot to 0 and
537 pass in an end of 0.
538 */
539static void emac_rx_fill(struct net_device *dev, int end)
540{
541 int i;
542 struct ocp_enet_private *fep = dev->priv;
543
544 i = fep->rx_slot;
545 do {
546 /* We don't want the 16 bytes skb_reserve done by dev_alloc_skb,
547 * it breaks our cache line alignement. However, we still allocate
548 * +16 so that we end up allocating the exact same size as
549 * dev_alloc_skb() would do.
550 * Also, because of the skb_res, the max DMA size we give to EMAC
551 * is slighly wrong, causing it to potentially DMA 2 more bytes
552 * from a broken/oversized packet. These 16 bytes will take care
553 * that we don't walk on somebody else toes with that.
554 */
555 fep->rx_skb[i] =
556 alloc_skb(fep->rx_buffer_size + 16, GFP_ATOMIC);
557
558 if (fep->rx_skb[i] == NULL) {
559 /* Keep rx_slot here, the next time clean/fill is called
560 * we will try again before the MAL wraps back here
561 * If the MAL tries to use this descriptor with
562 * the EMPTY bit off it will cause the
563 * rxde interrupt. That is where we will
564 * try again to allocate an sk_buff.
565 */
566 break;
567 708
709 /* Second pass, allocate new skbs */
710 for (i = 0; i < NUM_RX_BUFF; ++i) {
711 struct sk_buff *skb = alloc_skb(rx_skb_size, GFP_ATOMIC);
712 if (!skb) {
713 ret = -ENOMEM;
714 goto oom;
568 } 715 }
569 716
570 if (skb_res) 717 BUG_ON(!dev->rx_skb[i]);
571 skb_reserve(fep->rx_skb[i], skb_res); 718 dev_kfree_skb(dev->rx_skb[i]);
572 719
573 /* We must NOT dma_map_single the cache line right after the 720 skb_reserve(skb, EMAC_RX_SKB_HEADROOM + 2);
574 * buffer, so we must crop our sync size to account for the 721 dev->rx_desc[i].data_ptr =
575 * reserved space 722 dma_map_single(dev->ldev, skb->data - 2, rx_sync_size,
576 */ 723 DMA_FROM_DEVICE) + 2;
577 fep->rx_desc[i].data_ptr = 724 dev->rx_skb[i] = skb;
578 (unsigned char *)dma_map_single(&fep->ocpdev->dev, 725 }
579 (void *)fep->rx_skb[i]-> 726 skip:
580 data, 727 /* Check if we need to change "Jumbo" bit in MR1 */
581 fep->rx_buffer_size - 728 if ((new_mtu > ETH_DATA_LEN) ^ (dev->ndev->mtu > ETH_DATA_LEN)) {
582 skb_res, DMA_FROM_DEVICE); 729 /* This is to prevent starting RX channel in emac_rx_enable() */
583 730 dev->commac.rx_stopped = 1;
584 /* 731
585 * Some 4xx implementations use the previously 732 dev->ndev->mtu = new_mtu;
586 * reserved bits in data_len to encode the MS 733 emac_full_tx_reset(dev->ndev);
587 * 4-bits of a 36-bit physical address (ERPN) 734 }
588 * This must be initialized.
589 */
590 fep->rx_desc[i].data_len = 0;
591 fep->rx_desc[i].ctrl = MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR |
592 (i == (NUM_RX_BUFF - 1) ? MAL_RX_CTRL_WRAP : 0);
593 735
594 } while ((i = (i + 1) % NUM_RX_BUFF) != end); 736 mal_set_rcbs(dev->mal, emacdata->mal_rx_chan, emac_rx_size(new_mtu));
737 oom:
738 /* Restart RX */
739 dev->commac.rx_stopped = dev->rx_slot = 0;
740 mal_enable_rx_channel(dev->mal, emacdata->mal_rx_chan);
741 emac_rx_enable(dev);
595 742
596 fep->rx_slot = i; 743 return ret;
597} 744}
598 745
599static void 746/* Process ctx, rtnl_lock semaphore */
600emac_rx_csum(struct net_device *dev, unsigned short ctrl, struct sk_buff *skb) 747static int emac_change_mtu(struct net_device *ndev, int new_mtu)
601{ 748{
602 struct ocp_enet_private *fep = dev->priv; 749 struct ocp_enet_private *dev = ndev->priv;
750 int ret = 0;
603 751
604 /* Exit if interface has no TAH engine */ 752 if (new_mtu < EMAC_MIN_MTU || new_mtu > EMAC_MAX_MTU)
605 if (!fep->tah_dev) { 753 return -EINVAL;
606 skb->ip_summed = CHECKSUM_NONE;
607 return;
608 }
609 754
610 /* Check for TCP/UDP/IP csum error */ 755 DBG("%d: change_mtu(%d)" NL, dev->def->index, new_mtu);
611 if (ctrl & EMAC_CSUM_VER_ERROR) {
612 /* Let the stack verify checksum errors */
613 skb->ip_summed = CHECKSUM_NONE;
614/* adapter->hw_csum_err++; */
615 } else {
616 /* Csum is good */
617 skb->ip_summed = CHECKSUM_UNNECESSARY;
618/* adapter->hw_csum_good++; */
619 }
620}
621 756
622static int emac_rx_clean(struct net_device *dev) 757 local_bh_disable();
623{ 758 if (netif_running(ndev)) {
624 int i, b, bnum = 0, buf[6]; 759 /* Check if we really need to reinitalize RX ring */
625 int error, frame_length; 760 if (emac_rx_skb_size(ndev->mtu) != emac_rx_skb_size(new_mtu))
626 struct ocp_enet_private *fep = dev->priv; 761 ret = emac_resize_rx_ring(dev, new_mtu);
627 unsigned short ctrl; 762 }
628 763
629 i = fep->rx_slot; 764 if (!ret) {
765 ndev->mtu = new_mtu;
766 dev->rx_skb_size = emac_rx_skb_size(new_mtu);
767 dev->rx_sync_size = emac_rx_sync_size(new_mtu);
768 }
769 local_bh_enable();
630 770
631 PKT_DEBUG(("emac_rx_clean() entry, rx_slot: %d\n", fep->rx_slot)); 771 return ret;
772}
632 773
633 do { 774static void emac_clean_tx_ring(struct ocp_enet_private *dev)
634 if (fep->rx_skb[i] == NULL) 775{
635 continue; /*we have already handled the packet but haved failed to alloc */ 776 int i;
636 /* 777 for (i = 0; i < NUM_TX_BUFF; ++i) {
637 since rx_desc is in uncached mem we don't keep reading it directly 778 if (dev->tx_skb[i]) {
638 we pull out a local copy of ctrl and do the checks on the copy. 779 dev_kfree_skb(dev->tx_skb[i]);
639 */ 780 dev->tx_skb[i] = NULL;
640 ctrl = fep->rx_desc[i].ctrl; 781 if (dev->tx_desc[i].ctrl & MAL_TX_CTRL_READY)
641 if (ctrl & MAL_RX_CTRL_EMPTY) 782 ++dev->estats.tx_dropped;
642 break; /*we don't have any more ready packets */
643
644 if (EMAC_IS_BAD_RX_PACKET(ctrl)) {
645 fep->stats.rx_errors++;
646 fep->stats.rx_dropped++;
647
648 if (ctrl & EMAC_RX_ST_OE)
649 fep->stats.rx_fifo_errors++;
650 if (ctrl & EMAC_RX_ST_AE)
651 fep->stats.rx_frame_errors++;
652 if (ctrl & EMAC_RX_ST_BFCS)
653 fep->stats.rx_crc_errors++;
654 if (ctrl & (EMAC_RX_ST_RP | EMAC_RX_ST_PTL |
655 EMAC_RX_ST_ORE | EMAC_RX_ST_IRE))
656 fep->stats.rx_length_errors++;
657 } else {
658 if ((ctrl & (MAL_RX_CTRL_FIRST | MAL_RX_CTRL_LAST)) ==
659 (MAL_RX_CTRL_FIRST | MAL_RX_CTRL_LAST)) {
660 /* Single descriptor packet */
661 emac_rx_csum(dev, ctrl, fep->rx_skb[i]);
662 /* Send the skb up the chain. */
663 frame_length = fep->rx_desc[i].data_len - 4;
664 skb_put(fep->rx_skb[i], frame_length);
665 fep->rx_skb[i]->dev = dev;
666 fep->rx_skb[i]->protocol =
667 eth_type_trans(fep->rx_skb[i], dev);
668 error = netif_rx(fep->rx_skb[i]);
669
670 if ((error == NET_RX_DROP) ||
671 (error == NET_RX_BAD)) {
672 fep->stats.rx_dropped++;
673 } else {
674 fep->stats.rx_packets++;
675 fep->stats.rx_bytes += frame_length;
676 }
677 fep->rx_skb[i] = NULL;
678 } else {
679 /* Multiple descriptor packet */
680 if (ctrl & MAL_RX_CTRL_FIRST) {
681 if (fep->rx_desc[(i + 1) % NUM_RX_BUFF].
682 ctrl & MAL_RX_CTRL_EMPTY)
683 break;
684 bnum = 0;
685 buf[bnum] = i;
686 ++bnum;
687 continue;
688 }
689 if (((ctrl & MAL_RX_CTRL_FIRST) !=
690 MAL_RX_CTRL_FIRST) &&
691 ((ctrl & MAL_RX_CTRL_LAST) !=
692 MAL_RX_CTRL_LAST)) {
693 if (fep->rx_desc[(i + 1) %
694 NUM_RX_BUFF].ctrl &
695 MAL_RX_CTRL_EMPTY) {
696 i = buf[0];
697 break;
698 }
699 buf[bnum] = i;
700 ++bnum;
701 continue;
702 }
703 if (ctrl & MAL_RX_CTRL_LAST) {
704 buf[bnum] = i;
705 ++bnum;
706 skb_put(fep->rx_skb[buf[0]],
707 fep->rx_desc[buf[0]].data_len);
708 for (b = 1; b < bnum; b++) {
709 /*
710 * MAL is braindead, we need
711 * to copy the remainder
712 * of the packet from the
713 * latter descriptor buffers
714 * to the first skb. Then
715 * dispose of the source
716 * skbs.
717 *
718 * Once the stack is fixed
719 * to handle frags on most
720 * protocols we can generate
721 * a fragmented skb with
722 * no copies.
723 */
724 memcpy(fep->rx_skb[buf[0]]->
725 data +
726 fep->rx_skb[buf[0]]->len,
727 fep->rx_skb[buf[b]]->
728 data,
729 fep->rx_desc[buf[b]].
730 data_len);
731 skb_put(fep->rx_skb[buf[0]],
732 fep->rx_desc[buf[b]].
733 data_len);
734 dma_unmap_single(&fep->ocpdev->
735 dev,
736 fep->
737 rx_desc[buf
738 [b]].
739 data_ptr,
740 fep->
741 rx_desc[buf
742 [b]].
743 data_len,
744 DMA_FROM_DEVICE);
745 dev_kfree_skb(fep->
746 rx_skb[buf[b]]);
747 }
748 emac_rx_csum(dev, ctrl,
749 fep->rx_skb[buf[0]]);
750
751 fep->rx_skb[buf[0]]->dev = dev;
752 fep->rx_skb[buf[0]]->protocol =
753 eth_type_trans(fep->rx_skb[buf[0]],
754 dev);
755 error = netif_rx(fep->rx_skb[buf[0]]);
756
757 if ((error == NET_RX_DROP)
758 || (error == NET_RX_BAD)) {
759 fep->stats.rx_dropped++;
760 } else {
761 fep->stats.rx_packets++;
762 fep->stats.rx_bytes +=
763 fep->rx_skb[buf[0]]->len;
764 }
765 for (b = 0; b < bnum; b++)
766 fep->rx_skb[buf[b]] = NULL;
767 }
768 }
769 } 783 }
770 } while ((i = (i + 1) % NUM_RX_BUFF) != fep->rx_slot); 784 dev->tx_desc[i].ctrl = 0;
771 785 dev->tx_desc[i].data_ptr = 0;
772 PKT_DEBUG(("emac_rx_clean() exit, rx_slot: %d\n", fep->rx_slot)); 786 }
773
774 return i;
775} 787}
776 788
777static void emac_rxeob_dev(void *param, u32 chanmask) 789static void emac_clean_rx_ring(struct ocp_enet_private *dev)
778{ 790{
779 struct net_device *dev = param; 791 int i;
780 struct ocp_enet_private *fep = dev->priv; 792 for (i = 0; i < NUM_RX_BUFF; ++i)
781 unsigned long flags; 793 if (dev->rx_skb[i]) {
782 int n; 794 dev->rx_desc[i].ctrl = 0;
795 dev_kfree_skb(dev->rx_skb[i]);
796 dev->rx_skb[i] = NULL;
797 dev->rx_desc[i].data_ptr = 0;
798 }
783 799
784 spin_lock_irqsave(&fep->lock, flags); 800 if (dev->rx_sg_skb) {
785 if ((n = emac_rx_clean(dev)) != fep->rx_slot) 801 dev_kfree_skb(dev->rx_sg_skb);
786 emac_rx_fill(dev, n); 802 dev->rx_sg_skb = NULL;
787 spin_unlock_irqrestore(&fep->lock, flags); 803 }
788} 804}
789 805
790/* 806static inline int emac_alloc_rx_skb(struct ocp_enet_private *dev, int slot,
791 * This interrupt should never occurr, we don't program 807 int flags)
792 * the MAL for contiunous mode.
793 */
794static void emac_txde_dev(void *param, u32 chanmask)
795{ 808{
796 struct net_device *dev = param; 809 struct sk_buff *skb = alloc_skb(dev->rx_skb_size, flags);
797 struct ocp_enet_private *fep = dev->priv; 810 if (unlikely(!skb))
811 return -ENOMEM;
798 812
799 printk(KERN_WARNING "%s: transmit descriptor error\n", dev->name); 813 dev->rx_skb[slot] = skb;
814 dev->rx_desc[slot].data_len = 0;
800 815
801 emac_mac_dump(dev); 816 skb_reserve(skb, EMAC_RX_SKB_HEADROOM + 2);
802 emac_mal_dump(dev); 817 dev->rx_desc[slot].data_ptr =
818 dma_map_single(dev->ldev, skb->data - 2, dev->rx_sync_size,
819 DMA_FROM_DEVICE) + 2;
820 barrier();
821 dev->rx_desc[slot].ctrl = MAL_RX_CTRL_EMPTY |
822 (slot == (NUM_RX_BUFF - 1) ? MAL_RX_CTRL_WRAP : 0);
803 823
804 /* Reenable the transmit channel */ 824 return 0;
805 mal_enable_tx_channels(fep->mal, fep->commac.tx_chan_mask);
806} 825}
807 826
808/* 827static void emac_print_link_status(struct ocp_enet_private *dev)
809 * This interrupt should be very rare at best. This occurs when
810 * the hardware has a problem with the receive descriptors. The manual
811 * states that it occurs when the hardware cannot the receive descriptor
812 * empty bit is not set. The recovery mechanism will be to
813 * traverse through the descriptors, handle any that are marked to be
814 * handled and reinitialize each along the way. At that point the driver
815 * will be restarted.
816 */
817static void emac_rxde_dev(void *param, u32 chanmask)
818{ 828{
819 struct net_device *dev = param; 829 if (netif_carrier_ok(dev->ndev))
820 struct ocp_enet_private *fep = dev->priv; 830 printk(KERN_INFO "%s: link is up, %d %s%s\n",
821 unsigned long flags; 831 dev->ndev->name, dev->phy.speed,
822 832 dev->phy.duplex == DUPLEX_FULL ? "FDX" : "HDX",
823 if (net_ratelimit()) { 833 dev->phy.pause ? ", pause enabled" :
824 printk(KERN_WARNING "%s: receive descriptor error\n", 834 dev->phy.asym_pause ? ", assymetric pause enabled" : "");
825 fep->ndev->name); 835 else
836 printk(KERN_INFO "%s: link is down\n", dev->ndev->name);
837}
826 838
827 emac_mac_dump(dev); 839/* Process ctx, rtnl_lock semaphore */
828 emac_mal_dump(dev); 840static int emac_open(struct net_device *ndev)
829 emac_desc_dump(dev); 841{
842 struct ocp_enet_private *dev = ndev->priv;
843 struct ocp_func_emac_data *emacdata = dev->def->additions;
844 int err, i;
845
846 DBG("%d: open" NL, dev->def->index);
847
848 /* Setup error IRQ handler */
849 err = request_irq(dev->def->irq, emac_irq, 0, "EMAC", dev);
850 if (err) {
851 printk(KERN_ERR "%s: failed to request IRQ %d\n",
852 ndev->name, dev->def->irq);
853 return err;
830 } 854 }
831 855
832 /* Disable RX channel */ 856 /* Allocate RX ring */
833 spin_lock_irqsave(&fep->lock, flags); 857 for (i = 0; i < NUM_RX_BUFF; ++i)
834 mal_disable_rx_channels(fep->mal, fep->commac.rx_chan_mask); 858 if (emac_alloc_rx_skb(dev, i, GFP_KERNEL)) {
835 859 printk(KERN_ERR "%s: failed to allocate RX ring\n",
836 /* For now, charge the error against all emacs */ 860 ndev->name);
837 fep->stats.rx_errors++; 861 goto oom;
838 862 }
839 /* so do we have any good packets still? */
840 emac_rx_clean(dev);
841
842 /* When the interface is restarted it resets processing to the
843 * first descriptor in the table.
844 */
845
846 fep->rx_slot = 0;
847 emac_rx_fill(dev, 0);
848 863
849 set_mal_dcrn(fep->mal, DCRN_MALRXEOBISR, fep->commac.rx_chan_mask); 864 local_bh_disable();
850 set_mal_dcrn(fep->mal, DCRN_MALRXDEIR, fep->commac.rx_chan_mask); 865 dev->tx_cnt = dev->tx_slot = dev->ack_slot = dev->rx_slot =
866 dev->commac.rx_stopped = 0;
867 dev->rx_sg_skb = NULL;
868
869 if (dev->phy.address >= 0) {
870 int link_poll_interval;
871 if (dev->phy.def->ops->poll_link(&dev->phy)) {
872 dev->phy.def->ops->read_link(&dev->phy);
873 EMAC_RX_CLK_DEFAULT(dev->def->index);
874 netif_carrier_on(dev->ndev);
875 link_poll_interval = PHY_POLL_LINK_ON;
876 } else {
877 EMAC_RX_CLK_TX(dev->def->index);
878 netif_carrier_off(dev->ndev);
879 link_poll_interval = PHY_POLL_LINK_OFF;
880 }
881 mod_timer(&dev->link_timer, jiffies + link_poll_interval);
882 emac_print_link_status(dev);
883 } else
884 netif_carrier_on(dev->ndev);
885
886 emac_configure(dev);
887 mal_poll_add(dev->mal, &dev->commac);
888 mal_enable_tx_channel(dev->mal, emacdata->mal_tx_chan);
889 mal_set_rcbs(dev->mal, emacdata->mal_rx_chan, emac_rx_size(ndev->mtu));
890 mal_enable_rx_channel(dev->mal, emacdata->mal_rx_chan);
891 emac_tx_enable(dev);
892 emac_rx_enable(dev);
893 netif_start_queue(ndev);
894 local_bh_enable();
851 895
852 /* Reenable the receive channels */ 896 return 0;
853 mal_enable_rx_channels(fep->mal, fep->commac.rx_chan_mask); 897 oom:
854 spin_unlock_irqrestore(&fep->lock, flags); 898 emac_clean_rx_ring(dev);
899 free_irq(dev->def->irq, dev);
900 return -ENOMEM;
855} 901}
856 902
857static irqreturn_t 903/* BHs disabled */
858emac_mac_irq(int irq, void *dev_instance, struct pt_regs *regs) 904static int emac_link_differs(struct ocp_enet_private *dev)
859{ 905{
860 struct net_device *dev = dev_instance; 906 u32 r = in_be32(&dev->emacp->mr1);
861 struct ocp_enet_private *fep = dev->priv;
862 emac_t *emacp = fep->emacp;
863 unsigned long tmp_em0isr;
864 907
865 /* EMAC interrupt */ 908 int duplex = r & EMAC_MR1_FDE ? DUPLEX_FULL : DUPLEX_HALF;
866 tmp_em0isr = in_be32(&emacp->em0isr); 909 int speed, pause, asym_pause;
867 if (tmp_em0isr & (EMAC_ISR_TE0 | EMAC_ISR_TE1)) {
868 /* This error is a hard transmit error - could retransmit */
869 fep->stats.tx_errors++;
870 910
871 /* Reenable the transmit channel */ 911 if (r & (EMAC_MR1_MF_1000 | EMAC_MR1_MF_1000GPCS))
872 mal_enable_tx_channels(fep->mal, fep->commac.tx_chan_mask); 912 speed = SPEED_1000;
913 else if (r & EMAC_MR1_MF_100)
914 speed = SPEED_100;
915 else
916 speed = SPEED_10;
873 917
874 } else { 918 switch (r & (EMAC_MR1_EIFC | EMAC_MR1_APP)) {
875 fep->stats.rx_errors++; 919 case (EMAC_MR1_EIFC | EMAC_MR1_APP):
920 pause = 1;
921 asym_pause = 0;
922 break;
923 case EMAC_MR1_APP:
924 pause = 0;
925 asym_pause = 1;
926 break;
927 default:
928 pause = asym_pause = 0;
876 } 929 }
877 930 return speed != dev->phy.speed || duplex != dev->phy.duplex ||
878 if (tmp_em0isr & EMAC_ISR_RP) 931 pause != dev->phy.pause || asym_pause != dev->phy.asym_pause;
879 fep->stats.rx_length_errors++;
880 if (tmp_em0isr & EMAC_ISR_ALE)
881 fep->stats.rx_frame_errors++;
882 if (tmp_em0isr & EMAC_ISR_BFCS)
883 fep->stats.rx_crc_errors++;
884 if (tmp_em0isr & EMAC_ISR_PTLE)
885 fep->stats.rx_length_errors++;
886 if (tmp_em0isr & EMAC_ISR_ORE)
887 fep->stats.rx_length_errors++;
888 if (tmp_em0isr & EMAC_ISR_TE0)
889 fep->stats.tx_aborted_errors++;
890
891 emac_err_dump(dev, tmp_em0isr);
892
893 out_be32(&emacp->em0isr, tmp_em0isr);
894
895 return IRQ_HANDLED;
896} 932}
897 933
898static int emac_start_xmit(struct sk_buff *skb, struct net_device *dev) 934/* BHs disabled */
935static void emac_link_timer(unsigned long data)
899{ 936{
900 unsigned short ctrl; 937 struct ocp_enet_private *dev = (struct ocp_enet_private *)data;
901 unsigned long flags; 938 int link_poll_interval;
902 struct ocp_enet_private *fep = dev->priv;
903 emac_t *emacp = fep->emacp;
904 int len = skb->len;
905 unsigned int offset = 0, size, f, tx_slot_first;
906 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
907 939
908 spin_lock_irqsave(&fep->lock, flags); 940 DBG2("%d: link timer" NL, dev->def->index);
909 941
910 len -= skb->data_len; 942 if (dev->phy.def->ops->poll_link(&dev->phy)) {
943 if (!netif_carrier_ok(dev->ndev)) {
944 EMAC_RX_CLK_DEFAULT(dev->def->index);
911 945
912 if ((fep->tx_cnt + nr_frags + len / DESC_BUF_SIZE + 1) > NUM_TX_BUFF) { 946 /* Get new link parameters */
913 PKT_DEBUG(("emac_start_xmit() stopping queue\n")); 947 dev->phy.def->ops->read_link(&dev->phy);
914 netif_stop_queue(dev);
915 spin_unlock_irqrestore(&fep->lock, flags);
916 return -EBUSY;
917 }
918 948
919 tx_slot_first = fep->tx_slot; 949 if (dev->tah_dev || emac_link_differs(dev))
950 emac_full_tx_reset(dev->ndev);
920 951
921 while (len) { 952 netif_carrier_on(dev->ndev);
922 size = min(len, DESC_BUF_SIZE); 953 emac_print_link_status(dev);
923 954 }
924 fep->tx_desc[fep->tx_slot].data_len = (short)size; 955 link_poll_interval = PHY_POLL_LINK_ON;
925 fep->tx_desc[fep->tx_slot].data_ptr = 956 } else {
926 (unsigned char *)dma_map_single(&fep->ocpdev->dev, 957 if (netif_carrier_ok(dev->ndev)) {
927 (void *)((unsigned int)skb-> 958 EMAC_RX_CLK_TX(dev->def->index);
928 data + offset), 959#if defined(CONFIG_IBM_EMAC_PHY_RX_CLK_FIX)
929 size, DMA_TO_DEVICE); 960 emac_reinitialize(dev);
930 961#endif
931 ctrl = EMAC_TX_CTRL_DFLT; 962 netif_carrier_off(dev->ndev);
932 if (fep->tx_slot != tx_slot_first) 963 emac_print_link_status(dev);
933 ctrl |= MAL_TX_CTRL_READY;
934 if ((NUM_TX_BUFF - 1) == fep->tx_slot)
935 ctrl |= MAL_TX_CTRL_WRAP;
936 if (!nr_frags && (len == size)) {
937 ctrl |= MAL_TX_CTRL_LAST;
938 fep->tx_skb[fep->tx_slot] = skb;
939 } 964 }
940 if (skb->ip_summed == CHECKSUM_HW)
941 ctrl |= EMAC_TX_CTRL_TAH_CSUM;
942 965
943 fep->tx_desc[fep->tx_slot].ctrl = ctrl; 966 /* Retry reset if the previous attempt failed.
967 * This is needed mostly for CONFIG_IBM_EMAC_PHY_RX_CLK_FIX
968 * case, but I left it here because it shouldn't trigger for
969 * sane PHYs anyway.
970 */
971 if (unlikely(dev->reset_failed))
972 emac_reinitialize(dev);
944 973
945 len -= size; 974 link_poll_interval = PHY_POLL_LINK_OFF;
946 offset += size; 975 }
976 mod_timer(&dev->link_timer, jiffies + link_poll_interval);
977}
947 978
948 /* Bump tx count */ 979/* BHs disabled */
949 if (++fep->tx_cnt == NUM_TX_BUFF) 980static void emac_force_link_update(struct ocp_enet_private *dev)
950 netif_stop_queue(dev); 981{
982 netif_carrier_off(dev->ndev);
983 if (timer_pending(&dev->link_timer))
984 mod_timer(&dev->link_timer, jiffies + PHY_POLL_LINK_OFF);
985}
951 986
952 /* Next descriptor */ 987/* Process ctx, rtnl_lock semaphore */
953 if (++fep->tx_slot == NUM_TX_BUFF) 988static int emac_close(struct net_device *ndev)
954 fep->tx_slot = 0; 989{
955 } 990 struct ocp_enet_private *dev = ndev->priv;
991 struct ocp_func_emac_data *emacdata = dev->def->additions;
956 992
957 for (f = 0; f < nr_frags; f++) { 993 DBG("%d: close" NL, dev->def->index);
958 struct skb_frag_struct *frag;
959 994
960 frag = &skb_shinfo(skb)->frags[f]; 995 local_bh_disable();
961 len = frag->size;
962 offset = 0;
963
964 while (len) {
965 size = min(len, DESC_BUF_SIZE);
966
967 dma_map_page(&fep->ocpdev->dev,
968 frag->page,
969 frag->page_offset + offset,
970 size, DMA_TO_DEVICE);
971
972 ctrl = EMAC_TX_CTRL_DFLT | MAL_TX_CTRL_READY;
973 if ((NUM_TX_BUFF - 1) == fep->tx_slot)
974 ctrl |= MAL_TX_CTRL_WRAP;
975 if ((f == (nr_frags - 1)) && (len == size)) {
976 ctrl |= MAL_TX_CTRL_LAST;
977 fep->tx_skb[fep->tx_slot] = skb;
978 }
979 996
980 if (skb->ip_summed == CHECKSUM_HW) 997 if (dev->phy.address >= 0)
981 ctrl |= EMAC_TX_CTRL_TAH_CSUM; 998 del_timer_sync(&dev->link_timer);
982 999
983 fep->tx_desc[fep->tx_slot].data_len = (short)size; 1000 netif_stop_queue(ndev);
984 fep->tx_desc[fep->tx_slot].data_ptr = 1001 emac_rx_disable(dev);
985 (char *)((page_to_pfn(frag->page) << PAGE_SHIFT) + 1002 emac_tx_disable(dev);
986 frag->page_offset + offset); 1003 mal_disable_rx_channel(dev->mal, emacdata->mal_rx_chan);
987 fep->tx_desc[fep->tx_slot].ctrl = ctrl; 1004 mal_disable_tx_channel(dev->mal, emacdata->mal_tx_chan);
1005 mal_poll_del(dev->mal, &dev->commac);
1006 local_bh_enable();
988 1007
989 len -= size; 1008 emac_clean_tx_ring(dev);
990 offset += size; 1009 emac_clean_rx_ring(dev);
1010 free_irq(dev->def->irq, dev);
991 1011
992 /* Bump tx count */ 1012 return 0;
993 if (++fep->tx_cnt == NUM_TX_BUFF) 1013}
994 netif_stop_queue(dev);
995 1014
996 /* Next descriptor */ 1015static inline u16 emac_tx_csum(struct ocp_enet_private *dev,
997 if (++fep->tx_slot == NUM_TX_BUFF) 1016 struct sk_buff *skb)
998 fep->tx_slot = 0; 1017{
999 } 1018#if defined(CONFIG_IBM_EMAC_TAH)
1019 if (skb->ip_summed == CHECKSUM_HW) {
1020 ++dev->stats.tx_packets_csum;
1021 return EMAC_TX_CTRL_TAH_CSUM;
1000 } 1022 }
1023#endif
1024 return 0;
1025}
1001 1026
1002 /* 1027static inline int emac_xmit_finish(struct ocp_enet_private *dev, int len)
1003 * Deferred set READY on first descriptor of packet to 1028{
1004 * avoid TX MAL race. 1029 struct emac_regs *p = dev->emacp;
1005 */ 1030 struct net_device *ndev = dev->ndev;
1006 fep->tx_desc[tx_slot_first].ctrl |= MAL_TX_CTRL_READY;
1007
1008 /* Send the packet out. */
1009 out_be32(&emacp->em0tmr0, EMAC_TMR0_XMIT);
1010 1031
1011 fep->stats.tx_packets++; 1032 /* Send the packet out */
1012 fep->stats.tx_bytes += skb->len; 1033 out_be32(&p->tmr0, EMAC_TMR0_XMIT);
1013 1034
1014 PKT_DEBUG(("emac_start_xmit() exitn")); 1035 if (unlikely(++dev->tx_cnt == NUM_TX_BUFF)) {
1036 netif_stop_queue(ndev);
1037 DBG2("%d: stopped TX queue" NL, dev->def->index);
1038 }
1015 1039
1016 spin_unlock_irqrestore(&fep->lock, flags); 1040 ndev->trans_start = jiffies;
1041 ++dev->stats.tx_packets;
1042 dev->stats.tx_bytes += len;
1017 1043
1018 return 0; 1044 return 0;
1019} 1045}
1020 1046
1021static int emac_adjust_to_link(struct ocp_enet_private *fep) 1047/* BHs disabled */
1048static int emac_start_xmit(struct sk_buff *skb, struct net_device *ndev)
1022{ 1049{
1023 emac_t *emacp = fep->emacp; 1050 struct ocp_enet_private *dev = ndev->priv;
1024 unsigned long mode_reg; 1051 unsigned int len = skb->len;
1025 int full_duplex, speed; 1052 int slot;
1026 1053
1027 full_duplex = 0; 1054 u16 ctrl = EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP | MAL_TX_CTRL_READY |
1028 speed = SPEED_10; 1055 MAL_TX_CTRL_LAST | emac_tx_csum(dev, skb);
1029 1056
1030 /* set mode register 1 defaults */ 1057 slot = dev->tx_slot++;
1031 mode_reg = EMAC_M1_DEFAULT; 1058 if (dev->tx_slot == NUM_TX_BUFF) {
1032 1059 dev->tx_slot = 0;
1033 /* Read link mode on PHY */ 1060 ctrl |= MAL_TX_CTRL_WRAP;
1034 if (fep->phy_mii.def->ops->read_link(&fep->phy_mii) == 0) {
1035 /* If an error occurred, we don't deal with it yet */
1036 full_duplex = (fep->phy_mii.duplex == DUPLEX_FULL);
1037 speed = fep->phy_mii.speed;
1038 } 1061 }
1039 1062
1063 DBG2("%d: xmit(%u) %d" NL, dev->def->index, len, slot);
1040 1064
1041 /* set speed (default is 10Mb) */ 1065 dev->tx_skb[slot] = skb;
1042 switch (speed) { 1066 dev->tx_desc[slot].data_ptr = dma_map_single(dev->ldev, skb->data, len,
1043 case SPEED_1000: 1067 DMA_TO_DEVICE);
1044 mode_reg |= EMAC_M1_RFS_16K; 1068 dev->tx_desc[slot].data_len = (u16) len;
1045 if (fep->rgmii_dev) { 1069 barrier();
1046 struct ibm_ocp_rgmii *rgmii = RGMII_PRIV(fep->rgmii_dev); 1070 dev->tx_desc[slot].ctrl = ctrl;
1047
1048 if ((rgmii->mode[fep->rgmii_input] == RTBI)
1049 || (rgmii->mode[fep->rgmii_input] == TBI))
1050 mode_reg |= EMAC_M1_MF_1000GPCS;
1051 else
1052 mode_reg |= EMAC_M1_MF_1000MBPS;
1053
1054 emac_rgmii_port_speed(fep->rgmii_dev, fep->rgmii_input,
1055 1000);
1056 }
1057 break;
1058 case SPEED_100:
1059 mode_reg |= EMAC_M1_MF_100MBPS | EMAC_M1_RFS_4K;
1060 if (fep->rgmii_dev)
1061 emac_rgmii_port_speed(fep->rgmii_dev, fep->rgmii_input,
1062 100);
1063 if (fep->zmii_dev)
1064 emac_zmii_port_speed(fep->zmii_dev, fep->zmii_input,
1065 100);
1066 break;
1067 case SPEED_10:
1068 default:
1069 mode_reg = (mode_reg & ~EMAC_M1_MF_100MBPS) | EMAC_M1_RFS_4K;
1070 if (fep->rgmii_dev)
1071 emac_rgmii_port_speed(fep->rgmii_dev, fep->rgmii_input,
1072 10);
1073 if (fep->zmii_dev)
1074 emac_zmii_port_speed(fep->zmii_dev, fep->zmii_input,
1075 10);
1076 }
1077
1078 if (full_duplex)
1079 mode_reg |= EMAC_M1_FDE | EMAC_M1_EIFC | EMAC_M1_IST;
1080 else
1081 mode_reg &= ~(EMAC_M1_FDE | EMAC_M1_EIFC | EMAC_M1_ILE);
1082 1071
1083 LINK_DEBUG(("%s: adjust to link, speed: %d, duplex: %d, opened: %d\n", 1072 return emac_xmit_finish(dev, len);
1084 fep->ndev->name, speed, full_duplex, fep->opened));
1085
1086 printk(KERN_INFO "%s: Speed: %d, %s duplex.\n",
1087 fep->ndev->name, speed, full_duplex ? "Full" : "Half");
1088 if (fep->opened)
1089 out_be32(&emacp->em0mr1, mode_reg);
1090
1091 return 0;
1092} 1073}
1093 1074
1094static int emac_set_mac_address(struct net_device *ndev, void *p) 1075#if defined(CONFIG_IBM_EMAC_TAH)
1076static inline int emac_xmit_split(struct ocp_enet_private *dev, int slot,
1077 u32 pd, int len, int last, u16 base_ctrl)
1095{ 1078{
1096 struct ocp_enet_private *fep = ndev->priv; 1079 while (1) {
1097 emac_t *emacp = fep->emacp; 1080 u16 ctrl = base_ctrl;
1098 struct sockaddr *addr = p; 1081 int chunk = min(len, MAL_MAX_TX_SIZE);
1082 len -= chunk;
1099 1083
1100 if (!is_valid_ether_addr(addr->sa_data)) 1084 slot = (slot + 1) % NUM_TX_BUFF;
1101 return -EADDRNOTAVAIL;
1102 1085
1103 memcpy(ndev->dev_addr, addr->sa_data, ndev->addr_len); 1086 if (last && !len)
1087 ctrl |= MAL_TX_CTRL_LAST;
1088 if (slot == NUM_TX_BUFF - 1)
1089 ctrl |= MAL_TX_CTRL_WRAP;
1104 1090
1105 /* set the high address */ 1091 dev->tx_skb[slot] = NULL;
1106 out_be32(&emacp->em0iahr, 1092 dev->tx_desc[slot].data_ptr = pd;
1107 (fep->ndev->dev_addr[0] << 8) | fep->ndev->dev_addr[1]); 1093 dev->tx_desc[slot].data_len = (u16) chunk;
1094 dev->tx_desc[slot].ctrl = ctrl;
1095 ++dev->tx_cnt;
1108 1096
1109 /* set the low address */ 1097 if (!len)
1110 out_be32(&emacp->em0ialr, 1098 break;
1111 (fep->ndev->dev_addr[2] << 24) | (fep->ndev->dev_addr[3] << 16)
1112 | (fep->ndev->dev_addr[4] << 8) | fep->ndev->dev_addr[5]);
1113 1099
1114 return 0; 1100 pd += chunk;
1101 }
1102 return slot;
1115} 1103}
1116 1104
1117static int emac_change_mtu(struct net_device *dev, int new_mtu) 1105/* BHs disabled (SG version for TAH equipped EMACs) */
1106static int emac_start_xmit_sg(struct sk_buff *skb, struct net_device *ndev)
1118{ 1107{
1119 struct ocp_enet_private *fep = dev->priv; 1108 struct ocp_enet_private *dev = ndev->priv;
1120 int old_mtu = dev->mtu; 1109 int nr_frags = skb_shinfo(skb)->nr_frags;
1121 unsigned long mode_reg; 1110 int len = skb->len, chunk;
1122 emac_t *emacp = fep->emacp; 1111 int slot, i;
1123 u32 em0mr0; 1112 u16 ctrl;
1124 int i, full; 1113 u32 pd;
1125 unsigned long flags;
1126 1114
1127 if ((new_mtu < EMAC_MIN_MTU) || (new_mtu > EMAC_MAX_MTU)) { 1115 /* This is common "fast" path */
1128 printk(KERN_ERR 1116 if (likely(!nr_frags && len <= MAL_MAX_TX_SIZE))
1129 "emac: Invalid MTU setting, MTU must be between %d and %d\n", 1117 return emac_start_xmit(skb, ndev);
1130 EMAC_MIN_MTU, EMAC_MAX_MTU);
1131 return -EINVAL;
1132 }
1133 1118
1134 if (old_mtu != new_mtu && netif_running(dev)) { 1119 len -= skb->data_len;
1135 /* Stop rx engine */
1136 em0mr0 = in_be32(&emacp->em0mr0);
1137 out_be32(&emacp->em0mr0, em0mr0 & ~EMAC_M0_RXE);
1138
1139 /* Wait for descriptors to be empty */
1140 do {
1141 full = 0;
1142 for (i = 0; i < NUM_RX_BUFF; i++)
1143 if (!(fep->rx_desc[i].ctrl & MAL_RX_CTRL_EMPTY)) {
1144 printk(KERN_NOTICE
1145 "emac: RX ring is still full\n");
1146 full = 1;
1147 }
1148 } while (full);
1149
1150 spin_lock_irqsave(&fep->lock, flags);
1151
1152 mal_disable_rx_channels(fep->mal, fep->commac.rx_chan_mask);
1153
1154 /* Destroy all old rx skbs */
1155 for (i = 0; i < NUM_RX_BUFF; i++) {
1156 dma_unmap_single(&fep->ocpdev->dev,
1157 fep->rx_desc[i].data_ptr,
1158 fep->rx_desc[i].data_len,
1159 DMA_FROM_DEVICE);
1160 dev_kfree_skb(fep->rx_skb[i]);
1161 fep->rx_skb[i] = NULL;
1162 }
1163 1120
1164 /* Set new rx_buffer_size, jumbo cap, and advertise new mtu */ 1121 /* Note, this is only an *estimation*, we can still run out of empty
1165 mode_reg = in_be32(&emacp->em0mr1); 1122 * slots because of the additional fragmentation into
1166 if (new_mtu > ENET_DEF_MTU_SIZE) { 1123 * MAL_MAX_TX_SIZE-sized chunks
1167 mode_reg |= EMAC_M1_JUMBO_ENABLE; 1124 */
1168 fep->rx_buffer_size = EMAC_MAX_FRAME; 1125 if (unlikely(dev->tx_cnt + nr_frags + mal_tx_chunks(len) > NUM_TX_BUFF))
1169 } else { 1126 goto stop_queue;
1170 mode_reg &= ~EMAC_M1_JUMBO_ENABLE; 1127
1171 fep->rx_buffer_size = ENET_DEF_BUF_SIZE; 1128 ctrl = EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP | MAL_TX_CTRL_READY |
1172 } 1129 emac_tx_csum(dev, skb);
1173 dev->mtu = new_mtu; 1130 slot = dev->tx_slot;
1174 out_be32(&emacp->em0mr1, mode_reg); 1131
1132 /* skb data */
1133 dev->tx_skb[slot] = NULL;
1134 chunk = min(len, MAL_MAX_TX_SIZE);
1135 dev->tx_desc[slot].data_ptr = pd =
1136 dma_map_single(dev->ldev, skb->data, len, DMA_TO_DEVICE);
1137 dev->tx_desc[slot].data_len = (u16) chunk;
1138 len -= chunk;
1139 if (unlikely(len))
1140 slot = emac_xmit_split(dev, slot, pd + chunk, len, !nr_frags,
1141 ctrl);
1142 /* skb fragments */
1143 for (i = 0; i < nr_frags; ++i) {
1144 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i];
1145 len = frag->size;
1175 1146
1176 /* Re-init rx skbs */ 1147 if (unlikely(dev->tx_cnt + mal_tx_chunks(len) >= NUM_TX_BUFF))
1177 fep->rx_slot = 0; 1148 goto undo_frame;
1178 emac_rx_fill(dev, 0);
1179 1149
1180 /* Restart the rx engine */ 1150 pd = dma_map_page(dev->ldev, frag->page, frag->page_offset, len,
1181 mal_enable_rx_channels(fep->mal, fep->commac.rx_chan_mask); 1151 DMA_TO_DEVICE);
1182 out_be32(&emacp->em0mr0, em0mr0 | EMAC_M0_RXE);
1183 1152
1184 spin_unlock_irqrestore(&fep->lock, flags); 1153 slot = emac_xmit_split(dev, slot, pd, len, i == nr_frags - 1,
1154 ctrl);
1185 } 1155 }
1186 1156
1187 return 0; 1157 DBG2("%d: xmit_sg(%u) %d - %d" NL, dev->def->index, skb->len,
1188} 1158 dev->tx_slot, slot);
1189 1159
1190static void __emac_set_multicast_list(struct net_device *dev) 1160 /* Attach skb to the last slot so we don't release it too early */
1191{ 1161 dev->tx_skb[slot] = skb;
1192 struct ocp_enet_private *fep = dev->priv;
1193 emac_t *emacp = fep->emacp;
1194 u32 rmr = in_be32(&emacp->em0rmr);
1195 1162
1196 /* First clear all special bits, they can be set later */ 1163 /* Send the packet out */
1197 rmr &= ~(EMAC_RMR_PME | EMAC_RMR_PMME | EMAC_RMR_MAE); 1164 if (dev->tx_slot == NUM_TX_BUFF - 1)
1165 ctrl |= MAL_TX_CTRL_WRAP;
1166 barrier();
1167 dev->tx_desc[dev->tx_slot].ctrl = ctrl;
1168 dev->tx_slot = (slot + 1) % NUM_TX_BUFF;
1198 1169
1199 if (dev->flags & IFF_PROMISC) { 1170 return emac_xmit_finish(dev, skb->len);
1200 rmr |= EMAC_RMR_PME;
1201 } else if (dev->flags & IFF_ALLMULTI || 32 < dev->mc_count) {
1202 /*
1203 * Must be setting up to use multicast
1204 * Now check for promiscuous multicast
1205 */
1206 rmr |= EMAC_RMR_PMME;
1207 } else if (dev->flags & IFF_MULTICAST && 0 < dev->mc_count) {
1208 unsigned short em0gaht[4] = { 0, 0, 0, 0 };
1209 struct dev_mc_list *dmi;
1210
1211 /* Need to hash on the multicast address. */
1212 for (dmi = dev->mc_list; dmi; dmi = dmi->next) {
1213 unsigned long mc_crc;
1214 unsigned int bit_number;
1215
1216 mc_crc = ether_crc(6, (char *)dmi->dmi_addr);
1217 bit_number = 63 - (mc_crc >> 26); /* MSB: 0 LSB: 63 */
1218 em0gaht[bit_number >> 4] |=
1219 0x8000 >> (bit_number & 0x0f);
1220 }
1221 emacp->em0gaht1 = em0gaht[0];
1222 emacp->em0gaht2 = em0gaht[1];
1223 emacp->em0gaht3 = em0gaht[2];
1224 emacp->em0gaht4 = em0gaht[3];
1225 1171
1226 /* Turn on multicast addressing */ 1172 undo_frame:
1227 rmr |= EMAC_RMR_MAE; 1173 /* Well, too bad. Our previous estimation was overly optimistic.
1174 * Undo everything.
1175 */
1176 while (slot != dev->tx_slot) {
1177 dev->tx_desc[slot].ctrl = 0;
1178 --dev->tx_cnt;
1179 if (--slot < 0)
1180 slot = NUM_TX_BUFF - 1;
1228 } 1181 }
1229 out_be32(&emacp->em0rmr, rmr); 1182 ++dev->estats.tx_undo;
1183
1184 stop_queue:
1185 netif_stop_queue(ndev);
1186 DBG2("%d: stopped TX queue" NL, dev->def->index);
1187 return 1;
1230} 1188}
1189#else
1190# define emac_start_xmit_sg emac_start_xmit
1191#endif /* !defined(CONFIG_IBM_EMAC_TAH) */
1231 1192
1232static int emac_init_tah(struct ocp_enet_private *fep) 1193/* BHs disabled */
1194static void emac_parse_tx_error(struct ocp_enet_private *dev, u16 ctrl)
1233{ 1195{
1234 tah_t *tahp; 1196 struct ibm_emac_error_stats *st = &dev->estats;
1197 DBG("%d: BD TX error %04x" NL, dev->def->index, ctrl);
1198
1199 ++st->tx_bd_errors;
1200 if (ctrl & EMAC_TX_ST_BFCS)
1201 ++st->tx_bd_bad_fcs;
1202 if (ctrl & EMAC_TX_ST_LCS)
1203 ++st->tx_bd_carrier_loss;
1204 if (ctrl & EMAC_TX_ST_ED)
1205 ++st->tx_bd_excessive_deferral;
1206 if (ctrl & EMAC_TX_ST_EC)
1207 ++st->tx_bd_excessive_collisions;
1208 if (ctrl & EMAC_TX_ST_LC)
1209 ++st->tx_bd_late_collision;
1210 if (ctrl & EMAC_TX_ST_MC)
1211 ++st->tx_bd_multple_collisions;
1212 if (ctrl & EMAC_TX_ST_SC)
1213 ++st->tx_bd_single_collision;
1214 if (ctrl & EMAC_TX_ST_UR)
1215 ++st->tx_bd_underrun;
1216 if (ctrl & EMAC_TX_ST_SQE)
1217 ++st->tx_bd_sqe;
1218}
1235 1219
1236 /* Initialize TAH and enable checksum verification */ 1220static void emac_poll_tx(void *param)
1237 tahp = (tah_t *) ioremap(fep->tah_dev->def->paddr, sizeof(*tahp)); 1221{
1222 struct ocp_enet_private *dev = param;
1223 DBG2("%d: poll_tx, %d %d" NL, dev->def->index, dev->tx_cnt,
1224 dev->ack_slot);
1225
1226 if (dev->tx_cnt) {
1227 u16 ctrl;
1228 int slot = dev->ack_slot, n = 0;
1229 again:
1230 ctrl = dev->tx_desc[slot].ctrl;
1231 if (!(ctrl & MAL_TX_CTRL_READY)) {
1232 struct sk_buff *skb = dev->tx_skb[slot];
1233 ++n;
1234
1235 if (skb) {
1236 dev_kfree_skb(skb);
1237 dev->tx_skb[slot] = NULL;
1238 }
1239 slot = (slot + 1) % NUM_TX_BUFF;
1238 1240
1239 if (tahp == NULL) { 1241 if (unlikely(EMAC_IS_BAD_TX(ctrl)))
1240 printk(KERN_ERR "tah%d: Cannot ioremap TAH registers!\n", 1242 emac_parse_tx_error(dev, ctrl);
1241 fep->tah_dev->def->index);
1242 1243
1243 return -ENOMEM; 1244 if (--dev->tx_cnt)
1244 } 1245 goto again;
1245 1246 }
1246 out_be32(&tahp->tah_mr, TAH_MR_SR); 1247 if (n) {
1248 dev->ack_slot = slot;
1249 if (netif_queue_stopped(dev->ndev) &&
1250 dev->tx_cnt < EMAC_TX_WAKEUP_THRESH)
1251 netif_wake_queue(dev->ndev);
1247 1252
1248 /* wait for reset to complete */ 1253 DBG2("%d: tx %d pkts" NL, dev->def->index, n);
1249 while (in_be32(&tahp->tah_mr) & TAH_MR_SR) ; 1254 }
1255 }
1256}
1250 1257
1251 /* 10KB TAH TX FIFO accomodates the max MTU of 9000 */ 1258static inline void emac_recycle_rx_skb(struct ocp_enet_private *dev, int slot,
1252 out_be32(&tahp->tah_mr, 1259 int len)
1253 TAH_MR_CVR | TAH_MR_ST_768 | TAH_MR_TFS_10KB | TAH_MR_DTFP | 1260{
1254 TAH_MR_DIG); 1261 struct sk_buff *skb = dev->rx_skb[slot];
1262 DBG2("%d: recycle %d %d" NL, dev->def->index, slot, len);
1255 1263
1256 iounmap(tahp); 1264 if (len)
1265 dma_map_single(dev->ldev, skb->data - 2,
1266 EMAC_DMA_ALIGN(len + 2), DMA_FROM_DEVICE);
1257 1267
1258 return 0; 1268 dev->rx_desc[slot].data_len = 0;
1269 barrier();
1270 dev->rx_desc[slot].ctrl = MAL_RX_CTRL_EMPTY |
1271 (slot == (NUM_RX_BUFF - 1) ? MAL_RX_CTRL_WRAP : 0);
1259} 1272}
1260 1273
1261static void emac_init_rings(struct net_device *dev) 1274static void emac_parse_rx_error(struct ocp_enet_private *dev, u16 ctrl)
1262{ 1275{
1263 struct ocp_enet_private *ep = dev->priv; 1276 struct ibm_emac_error_stats *st = &dev->estats;
1264 int loop; 1277 DBG("%d: BD RX error %04x" NL, dev->def->index, ctrl);
1278
1279 ++st->rx_bd_errors;
1280 if (ctrl & EMAC_RX_ST_OE)
1281 ++st->rx_bd_overrun;
1282 if (ctrl & EMAC_RX_ST_BP)
1283 ++st->rx_bd_bad_packet;
1284 if (ctrl & EMAC_RX_ST_RP)
1285 ++st->rx_bd_runt_packet;
1286 if (ctrl & EMAC_RX_ST_SE)
1287 ++st->rx_bd_short_event;
1288 if (ctrl & EMAC_RX_ST_AE)
1289 ++st->rx_bd_alignment_error;
1290 if (ctrl & EMAC_RX_ST_BFCS)
1291 ++st->rx_bd_bad_fcs;
1292 if (ctrl & EMAC_RX_ST_PTL)
1293 ++st->rx_bd_packet_too_long;
1294 if (ctrl & EMAC_RX_ST_ORE)
1295 ++st->rx_bd_out_of_range;
1296 if (ctrl & EMAC_RX_ST_IRE)
1297 ++st->rx_bd_in_range;
1298}
1265 1299
1266 ep->tx_desc = (struct mal_descriptor *)((char *)ep->mal->tx_virt_addr + 1300static inline void emac_rx_csum(struct ocp_enet_private *dev,
1267 (ep->mal_tx_chan * 1301 struct sk_buff *skb, u16 ctrl)
1268 MAL_DT_ALIGN)); 1302{
1269 ep->rx_desc = 1303#if defined(CONFIG_IBM_EMAC_TAH)
1270 (struct mal_descriptor *)((char *)ep->mal->rx_virt_addr + 1304 if (!ctrl && dev->tah_dev) {
1271 (ep->mal_rx_chan * MAL_DT_ALIGN)); 1305 skb->ip_summed = CHECKSUM_UNNECESSARY;
1306 ++dev->stats.rx_packets_csum;
1307 }
1308#endif
1309}
1272 1310
1273 /* Fill in the transmit descriptor ring. */ 1311static inline int emac_rx_sg_append(struct ocp_enet_private *dev, int slot)
1274 for (loop = 0; loop < NUM_TX_BUFF; loop++) { 1312{
1275 if (ep->tx_skb[loop]) { 1313 if (likely(dev->rx_sg_skb != NULL)) {
1276 dma_unmap_single(&ep->ocpdev->dev, 1314 int len = dev->rx_desc[slot].data_len;
1277 ep->tx_desc[loop].data_ptr, 1315 int tot_len = dev->rx_sg_skb->len + len;
1278 ep->tx_desc[loop].data_len, 1316
1279 DMA_TO_DEVICE); 1317 if (unlikely(tot_len + 2 > dev->rx_skb_size)) {
1280 dev_kfree_skb_irq(ep->tx_skb[loop]); 1318 ++dev->estats.rx_dropped_mtu;
1319 dev_kfree_skb(dev->rx_sg_skb);
1320 dev->rx_sg_skb = NULL;
1321 } else {
1322 cacheable_memcpy(dev->rx_sg_skb->tail,
1323 dev->rx_skb[slot]->data, len);
1324 skb_put(dev->rx_sg_skb, len);
1325 emac_recycle_rx_skb(dev, slot, len);
1326 return 0;
1281 } 1327 }
1282 ep->tx_skb[loop] = NULL;
1283 ep->tx_desc[loop].ctrl = 0;
1284 ep->tx_desc[loop].data_len = 0;
1285 ep->tx_desc[loop].data_ptr = NULL;
1286 }
1287 ep->tx_desc[loop - 1].ctrl |= MAL_TX_CTRL_WRAP;
1288
1289 /* Format the receive descriptor ring. */
1290 ep->rx_slot = 0;
1291 /* Default is MTU=1500 + Ethernet overhead */
1292 ep->rx_buffer_size = dev->mtu + ENET_HEADER_SIZE + ENET_FCS_SIZE;
1293 emac_rx_fill(dev, 0);
1294 if (ep->rx_slot != 0) {
1295 printk(KERN_ERR
1296 "%s: Not enough mem for RxChain durning Open?\n",
1297 dev->name);
1298 /*We couldn't fill the ring at startup?
1299 *We could clean up and fail to open but right now we will try to
1300 *carry on. It may be a sign of a bad NUM_RX_BUFF value
1301 */
1302 } 1328 }
1303 1329 emac_recycle_rx_skb(dev, slot, 0);
1304 ep->tx_cnt = 0; 1330 return -1;
1305 ep->tx_slot = 0;
1306 ep->ack_slot = 0;
1307} 1331}
1308 1332
1309static void emac_reset_configure(struct ocp_enet_private *fep) 1333/* BHs disabled */
1334static int emac_poll_rx(void *param, int budget)
1310{ 1335{
1311 emac_t *emacp = fep->emacp; 1336 struct ocp_enet_private *dev = param;
1312 int i; 1337 int slot = dev->rx_slot, received = 0;
1313
1314 mal_disable_tx_channels(fep->mal, fep->commac.tx_chan_mask);
1315 mal_disable_rx_channels(fep->mal, fep->commac.rx_chan_mask);
1316 1338
1317 /* 1339 DBG2("%d: poll_rx(%d)" NL, dev->def->index, budget);
1318 * Check for a link, some PHYs don't provide a clock if
1319 * no link is present. Some EMACs will not come out of
1320 * soft reset without a PHY clock present.
1321 */
1322 if (fep->phy_mii.def->ops->poll_link(&fep->phy_mii)) {
1323 /* Reset the EMAC */
1324 out_be32(&emacp->em0mr0, EMAC_M0_SRST);
1325 udelay(20);
1326 for (i = 0; i < 100; i++) {
1327 if ((in_be32(&emacp->em0mr0) & EMAC_M0_SRST) == 0)
1328 break;
1329 udelay(10);
1330 }
1331
1332 if (i >= 100) {
1333 printk(KERN_ERR "%s: Cannot reset EMAC\n",
1334 fep->ndev->name);
1335 return;
1336 }
1337 }
1338 1340
1339 /* Switch IRQs off for now */ 1341 again:
1340 out_be32(&emacp->em0iser, 0); 1342 while (budget > 0) {
1343 int len;
1344 struct sk_buff *skb;
1345 u16 ctrl = dev->rx_desc[slot].ctrl;
1341 1346
1342 /* Configure MAL rx channel */ 1347 if (ctrl & MAL_RX_CTRL_EMPTY)
1343 mal_set_rcbs(fep->mal, fep->mal_rx_chan, DESC_BUF_SIZE_REG); 1348 break;
1344 1349
1345 /* set the high address */ 1350 skb = dev->rx_skb[slot];
1346 out_be32(&emacp->em0iahr, 1351 barrier();
1347 (fep->ndev->dev_addr[0] << 8) | fep->ndev->dev_addr[1]); 1352 len = dev->rx_desc[slot].data_len;
1348 1353
1349 /* set the low address */ 1354 if (unlikely(!MAL_IS_SINGLE_RX(ctrl)))
1350 out_be32(&emacp->em0ialr, 1355 goto sg;
1351 (fep->ndev->dev_addr[2] << 24) | (fep->ndev->dev_addr[3] << 16)
1352 | (fep->ndev->dev_addr[4] << 8) | fep->ndev->dev_addr[5]);
1353 1356
1354 /* Adjust to link */ 1357 ctrl &= EMAC_BAD_RX_MASK;
1355 if (netif_carrier_ok(fep->ndev)) 1358 if (unlikely(ctrl && ctrl != EMAC_RX_TAH_BAD_CSUM)) {
1356 emac_adjust_to_link(fep); 1359 emac_parse_rx_error(dev, ctrl);
1360 ++dev->estats.rx_dropped_error;
1361 emac_recycle_rx_skb(dev, slot, 0);
1362 len = 0;
1363 goto next;
1364 }
1357 1365
1358 /* enable broadcast/individual address and RX FIFO defaults */ 1366 if (len && len < EMAC_RX_COPY_THRESH) {
1359 out_be32(&emacp->em0rmr, EMAC_RMR_DEFAULT); 1367 struct sk_buff *copy_skb =
1368 alloc_skb(len + EMAC_RX_SKB_HEADROOM + 2, GFP_ATOMIC);
1369 if (unlikely(!copy_skb))
1370 goto oom;
1371
1372 skb_reserve(copy_skb, EMAC_RX_SKB_HEADROOM + 2);
1373 cacheable_memcpy(copy_skb->data - 2, skb->data - 2,
1374 len + 2);
1375 emac_recycle_rx_skb(dev, slot, len);
1376 skb = copy_skb;
1377 } else if (unlikely(emac_alloc_rx_skb(dev, slot, GFP_ATOMIC)))
1378 goto oom;
1379
1380 skb_put(skb, len);
1381 push_packet:
1382 skb->dev = dev->ndev;
1383 skb->protocol = eth_type_trans(skb, dev->ndev);
1384 emac_rx_csum(dev, skb, ctrl);
1385
1386 if (unlikely(netif_receive_skb(skb) == NET_RX_DROP))
1387 ++dev->estats.rx_dropped_stack;
1388 next:
1389 ++dev->stats.rx_packets;
1390 skip:
1391 dev->stats.rx_bytes += len;
1392 slot = (slot + 1) % NUM_RX_BUFF;
1393 --budget;
1394 ++received;
1395 continue;
1396 sg:
1397 if (ctrl & MAL_RX_CTRL_FIRST) {
1398 BUG_ON(dev->rx_sg_skb);
1399 if (unlikely(emac_alloc_rx_skb(dev, slot, GFP_ATOMIC))) {
1400 DBG("%d: rx OOM %d" NL, dev->def->index, slot);
1401 ++dev->estats.rx_dropped_oom;
1402 emac_recycle_rx_skb(dev, slot, 0);
1403 } else {
1404 dev->rx_sg_skb = skb;
1405 skb_put(skb, len);
1406 }
1407 } else if (!emac_rx_sg_append(dev, slot) &&
1408 (ctrl & MAL_RX_CTRL_LAST)) {
1409
1410 skb = dev->rx_sg_skb;
1411 dev->rx_sg_skb = NULL;
1412
1413 ctrl &= EMAC_BAD_RX_MASK;
1414 if (unlikely(ctrl && ctrl != EMAC_RX_TAH_BAD_CSUM)) {
1415 emac_parse_rx_error(dev, ctrl);
1416 ++dev->estats.rx_dropped_error;
1417 dev_kfree_skb(skb);
1418 len = 0;
1419 } else
1420 goto push_packet;
1421 }
1422 goto skip;
1423 oom:
1424 DBG("%d: rx OOM %d" NL, dev->def->index, slot);
1425 /* Drop the packet and recycle skb */
1426 ++dev->estats.rx_dropped_oom;
1427 emac_recycle_rx_skb(dev, slot, 0);
1428 goto next;
1429 }
1360 1430
1361 /* set transmit request threshold register */ 1431 if (received) {
1362 out_be32(&emacp->em0trtr, EMAC_TRTR_DEFAULT); 1432 DBG2("%d: rx %d BDs" NL, dev->def->index, received);
1433 dev->rx_slot = slot;
1434 }
1363 1435
1364 /* Reconfigure multicast */ 1436 if (unlikely(budget && dev->commac.rx_stopped)) {
1365 __emac_set_multicast_list(fep->ndev); 1437 struct ocp_func_emac_data *emacdata = dev->def->additions;
1366 1438
1367 /* Set receiver/transmitter defaults */ 1439 barrier();
1368 out_be32(&emacp->em0rwmr, EMAC_RWMR_DEFAULT); 1440 if (!(dev->rx_desc[slot].ctrl & MAL_RX_CTRL_EMPTY)) {
1369 out_be32(&emacp->em0tmr0, EMAC_TMR0_DEFAULT); 1441 DBG2("%d: rx restart" NL, dev->def->index);
1370 out_be32(&emacp->em0tmr1, EMAC_TMR1_DEFAULT); 1442 received = 0;
1443 goto again;
1444 }
1371 1445
1372 /* set frame gap */ 1446 if (dev->rx_sg_skb) {
1373 out_be32(&emacp->em0ipgvr, CONFIG_IBM_EMAC_FGAP); 1447 DBG2("%d: dropping partial rx packet" NL,
1374 1448 dev->def->index);
1375 /* set VLAN Tag Protocol Identifier */ 1449 ++dev->estats.rx_dropped_error;
1376 out_be32(&emacp->em0vtpid, 0x8100); 1450 dev_kfree_skb(dev->rx_sg_skb);
1451 dev->rx_sg_skb = NULL;
1452 }
1377 1453
1378 /* Init ring buffers */ 1454 dev->commac.rx_stopped = 0;
1379 emac_init_rings(fep->ndev); 1455 mal_enable_rx_channel(dev->mal, emacdata->mal_rx_chan);
1456 emac_rx_enable(dev);
1457 dev->rx_slot = 0;
1458 }
1459 return received;
1380} 1460}
1381 1461
1382static void emac_kick(struct ocp_enet_private *fep) 1462/* BHs disabled */
1463static int emac_peek_rx(void *param)
1383{ 1464{
1384 emac_t *emacp = fep->emacp; 1465 struct ocp_enet_private *dev = param;
1385 unsigned long emac_ier; 1466 return !(dev->rx_desc[dev->rx_slot].ctrl & MAL_RX_CTRL_EMPTY);
1386 1467}
1387 emac_ier = EMAC_ISR_PP | EMAC_ISR_BP | EMAC_ISR_RP |
1388 EMAC_ISR_SE | EMAC_ISR_PTLE | EMAC_ISR_ALE |
1389 EMAC_ISR_BFCS | EMAC_ISR_ORE | EMAC_ISR_IRE;
1390 1468
1391 out_be32(&emacp->em0iser, emac_ier); 1469/* BHs disabled */
1470static int emac_peek_rx_sg(void *param)
1471{
1472 struct ocp_enet_private *dev = param;
1473 int slot = dev->rx_slot;
1474 while (1) {
1475 u16 ctrl = dev->rx_desc[slot].ctrl;
1476 if (ctrl & MAL_RX_CTRL_EMPTY)
1477 return 0;
1478 else if (ctrl & MAL_RX_CTRL_LAST)
1479 return 1;
1392 1480
1393 /* enable all MAL transmit and receive channels */ 1481 slot = (slot + 1) % NUM_RX_BUFF;
1394 mal_enable_tx_channels(fep->mal, fep->commac.tx_chan_mask);
1395 mal_enable_rx_channels(fep->mal, fep->commac.rx_chan_mask);
1396 1482
1397 /* set transmit and receive enable */ 1483 /* I'm just being paranoid here :) */
1398 out_be32(&emacp->em0mr0, EMAC_M0_TXE | EMAC_M0_RXE); 1484 if (unlikely(slot == dev->rx_slot))
1485 return 0;
1486 }
1399} 1487}
1400 1488
1401static void 1489/* Hard IRQ */
1402emac_start_link(struct ocp_enet_private *fep, struct ethtool_cmd *ep) 1490static void emac_rxde(void *param)
1403{ 1491{
1404 u32 advertise; 1492 struct ocp_enet_private *dev = param;
1405 int autoneg; 1493 ++dev->estats.rx_stopped;
1406 int forced_speed; 1494 emac_rx_disable_async(dev);
1407 int forced_duplex; 1495}
1408 1496
1409 /* Default advertise */ 1497/* Hard IRQ */
1410 advertise = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | 1498static irqreturn_t emac_irq(int irq, void *dev_instance, struct pt_regs *regs)
1411 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | 1499{
1412 ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full; 1500 struct ocp_enet_private *dev = dev_instance;
1413 autoneg = fep->want_autoneg; 1501 struct emac_regs *p = dev->emacp;
1414 forced_speed = fep->phy_mii.speed; 1502 struct ibm_emac_error_stats *st = &dev->estats;
1415 forced_duplex = fep->phy_mii.duplex; 1503
1504 u32 isr = in_be32(&p->isr);
1505 out_be32(&p->isr, isr);
1506
1507 DBG("%d: isr = %08x" NL, dev->def->index, isr);
1508
1509 if (isr & EMAC_ISR_TXPE)
1510 ++st->tx_parity;
1511 if (isr & EMAC_ISR_RXPE)
1512 ++st->rx_parity;
1513 if (isr & EMAC_ISR_TXUE)
1514 ++st->tx_underrun;
1515 if (isr & EMAC_ISR_RXOE)
1516 ++st->rx_fifo_overrun;
1517 if (isr & EMAC_ISR_OVR)
1518 ++st->rx_overrun;
1519 if (isr & EMAC_ISR_BP)
1520 ++st->rx_bad_packet;
1521 if (isr & EMAC_ISR_RP)
1522 ++st->rx_runt_packet;
1523 if (isr & EMAC_ISR_SE)
1524 ++st->rx_short_event;
1525 if (isr & EMAC_ISR_ALE)
1526 ++st->rx_alignment_error;
1527 if (isr & EMAC_ISR_BFCS)
1528 ++st->rx_bad_fcs;
1529 if (isr & EMAC_ISR_PTLE)
1530 ++st->rx_packet_too_long;
1531 if (isr & EMAC_ISR_ORE)
1532 ++st->rx_out_of_range;
1533 if (isr & EMAC_ISR_IRE)
1534 ++st->rx_in_range;
1535 if (isr & EMAC_ISR_SQE)
1536 ++st->tx_sqe;
1537 if (isr & EMAC_ISR_TE)
1538 ++st->tx_errors;
1416 1539
1417 /* Setup link parameters */ 1540 return IRQ_HANDLED;
1418 if (ep) { 1541}
1419 if (ep->autoneg == AUTONEG_ENABLE) {
1420 advertise = ep->advertising;
1421 autoneg = 1;
1422 } else {
1423 autoneg = 0;
1424 forced_speed = ep->speed;
1425 forced_duplex = ep->duplex;
1426 }
1427 }
1428 1542
1429 /* Configure PHY & start aneg */ 1543static struct net_device_stats *emac_stats(struct net_device *ndev)
1430 fep->want_autoneg = autoneg; 1544{
1431 if (autoneg) { 1545 struct ocp_enet_private *dev = ndev->priv;
1432 LINK_DEBUG(("%s: start link aneg, advertise: 0x%x\n", 1546 struct ibm_emac_stats *st = &dev->stats;
1433 fep->ndev->name, advertise)); 1547 struct ibm_emac_error_stats *est = &dev->estats;
1434 fep->phy_mii.def->ops->setup_aneg(&fep->phy_mii, advertise); 1548 struct net_device_stats *nst = &dev->nstats;
1435 } else { 1549
1436 LINK_DEBUG(("%s: start link forced, speed: %d, duplex: %d\n", 1550 DBG2("%d: stats" NL, dev->def->index);
1437 fep->ndev->name, forced_speed, forced_duplex)); 1551
1438 fep->phy_mii.def->ops->setup_forced(&fep->phy_mii, forced_speed, 1552 /* Compute "legacy" statistics */
1439 forced_duplex); 1553 local_irq_disable();
1440 } 1554 nst->rx_packets = (unsigned long)st->rx_packets;
1441 fep->timer_ticks = 0; 1555 nst->rx_bytes = (unsigned long)st->rx_bytes;
1442 mod_timer(&fep->link_timer, jiffies + HZ); 1556 nst->tx_packets = (unsigned long)st->tx_packets;
1557 nst->tx_bytes = (unsigned long)st->tx_bytes;
1558 nst->rx_dropped = (unsigned long)(est->rx_dropped_oom +
1559 est->rx_dropped_error +
1560 est->rx_dropped_resize +
1561 est->rx_dropped_mtu);
1562 nst->tx_dropped = (unsigned long)est->tx_dropped;
1563
1564 nst->rx_errors = (unsigned long)est->rx_bd_errors;
1565 nst->rx_fifo_errors = (unsigned long)(est->rx_bd_overrun +
1566 est->rx_fifo_overrun +
1567 est->rx_overrun);
1568 nst->rx_frame_errors = (unsigned long)(est->rx_bd_alignment_error +
1569 est->rx_alignment_error);
1570 nst->rx_crc_errors = (unsigned long)(est->rx_bd_bad_fcs +
1571 est->rx_bad_fcs);
1572 nst->rx_length_errors = (unsigned long)(est->rx_bd_runt_packet +
1573 est->rx_bd_short_event +
1574 est->rx_bd_packet_too_long +
1575 est->rx_bd_out_of_range +
1576 est->rx_bd_in_range +
1577 est->rx_runt_packet +
1578 est->rx_short_event +
1579 est->rx_packet_too_long +
1580 est->rx_out_of_range +
1581 est->rx_in_range);
1582
1583 nst->tx_errors = (unsigned long)(est->tx_bd_errors + est->tx_errors);
1584 nst->tx_fifo_errors = (unsigned long)(est->tx_bd_underrun +
1585 est->tx_underrun);
1586 nst->tx_carrier_errors = (unsigned long)est->tx_bd_carrier_loss;
1587 nst->collisions = (unsigned long)(est->tx_bd_excessive_deferral +
1588 est->tx_bd_excessive_collisions +
1589 est->tx_bd_late_collision +
1590 est->tx_bd_multple_collisions);
1591 local_irq_enable();
1592 return nst;
1443} 1593}
1444 1594
1445static void emac_link_timer(unsigned long data) 1595static void emac_remove(struct ocp_device *ocpdev)
1446{ 1596{
1447 struct ocp_enet_private *fep = (struct ocp_enet_private *)data; 1597 struct ocp_enet_private *dev = ocp_get_drvdata(ocpdev);
1448 int link;
1449 1598
1450 if (fep->going_away) 1599 DBG("%d: remove" NL, dev->def->index);
1451 return;
1452 1600
1453 spin_lock_irq(&fep->lock); 1601 ocp_set_drvdata(ocpdev, 0);
1602 unregister_netdev(dev->ndev);
1454 1603
1455 link = fep->phy_mii.def->ops->poll_link(&fep->phy_mii); 1604 tah_fini(dev->tah_dev);
1456 LINK_DEBUG(("%s: poll_link: %d\n", fep->ndev->name, link)); 1605 rgmii_fini(dev->rgmii_dev, dev->rgmii_input);
1606 zmii_fini(dev->zmii_dev, dev->zmii_input);
1457 1607
1458 if (link == netif_carrier_ok(fep->ndev)) { 1608 emac_dbg_register(dev->def->index, 0);
1459 if (!link && fep->want_autoneg && (++fep->timer_ticks) > 10) 1609
1460 emac_start_link(fep, NULL); 1610 mal_unregister_commac(dev->mal, &dev->commac);
1461 goto out; 1611 iounmap((void *)dev->emacp);
1462 } 1612 kfree(dev->ndev);
1463 printk(KERN_INFO "%s: Link is %s\n", fep->ndev->name,
1464 link ? "Up" : "Down");
1465 if (link) {
1466 netif_carrier_on(fep->ndev);
1467 /* Chip needs a full reset on config change. That sucks, so I
1468 * should ultimately move that to some tasklet to limit
1469 * latency peaks caused by this code
1470 */
1471 emac_reset_configure(fep);
1472 if (fep->opened)
1473 emac_kick(fep);
1474 } else {
1475 fep->timer_ticks = 0;
1476 netif_carrier_off(fep->ndev);
1477 }
1478 out:
1479 mod_timer(&fep->link_timer, jiffies + HZ);
1480 spin_unlock_irq(&fep->lock);
1481} 1613}
1482 1614
1483static void emac_set_multicast_list(struct net_device *dev) 1615static struct mal_commac_ops emac_commac_ops = {
1484{ 1616 .poll_tx = &emac_poll_tx,
1485 struct ocp_enet_private *fep = dev->priv; 1617 .poll_rx = &emac_poll_rx,
1618 .peek_rx = &emac_peek_rx,
1619 .rxde = &emac_rxde,
1620};
1486 1621
1487 spin_lock_irq(&fep->lock); 1622static struct mal_commac_ops emac_commac_sg_ops = {
1488 __emac_set_multicast_list(dev); 1623 .poll_tx = &emac_poll_tx,
1489 spin_unlock_irq(&fep->lock); 1624 .poll_rx = &emac_poll_rx,
1490} 1625 .peek_rx = &emac_peek_rx_sg,
1626 .rxde = &emac_rxde,
1627};
1491 1628
1492static int emac_get_settings(struct net_device *ndev, struct ethtool_cmd *cmd) 1629/* Ethtool support */
1630static int emac_ethtool_get_settings(struct net_device *ndev,
1631 struct ethtool_cmd *cmd)
1493{ 1632{
1494 struct ocp_enet_private *fep = ndev->priv; 1633 struct ocp_enet_private *dev = ndev->priv;
1495 1634
1496 cmd->supported = fep->phy_mii.def->features; 1635 cmd->supported = dev->phy.features;
1497 cmd->port = PORT_MII; 1636 cmd->port = PORT_MII;
1498 cmd->transceiver = XCVR_EXTERNAL; 1637 cmd->phy_address = dev->phy.address;
1499 cmd->phy_address = fep->mii_phy_addr; 1638 cmd->transceiver =
1500 spin_lock_irq(&fep->lock); 1639 dev->phy.address >= 0 ? XCVR_EXTERNAL : XCVR_INTERNAL;
1501 cmd->autoneg = fep->want_autoneg; 1640
1502 cmd->speed = fep->phy_mii.speed; 1641 local_bh_disable();
1503 cmd->duplex = fep->phy_mii.duplex; 1642 cmd->advertising = dev->phy.advertising;
1504 spin_unlock_irq(&fep->lock); 1643 cmd->autoneg = dev->phy.autoneg;
1644 cmd->speed = dev->phy.speed;
1645 cmd->duplex = dev->phy.duplex;
1646 local_bh_enable();
1647
1505 return 0; 1648 return 0;
1506} 1649}
1507 1650
1508static int emac_set_settings(struct net_device *ndev, struct ethtool_cmd *cmd) 1651static int emac_ethtool_set_settings(struct net_device *ndev,
1652 struct ethtool_cmd *cmd)
1509{ 1653{
1510 struct ocp_enet_private *fep = ndev->priv; 1654 struct ocp_enet_private *dev = ndev->priv;
1511 unsigned long features = fep->phy_mii.def->features; 1655 u32 f = dev->phy.features;
1512 1656
1513 if (!capable(CAP_NET_ADMIN)) 1657 DBG("%d: set_settings(%d, %d, %d, 0x%08x)" NL, dev->def->index,
1514 return -EPERM; 1658 cmd->autoneg, cmd->speed, cmd->duplex, cmd->advertising);
1515 1659
1660 /* Basic sanity checks */
1661 if (dev->phy.address < 0)
1662 return -EOPNOTSUPP;
1516 if (cmd->autoneg != AUTONEG_ENABLE && cmd->autoneg != AUTONEG_DISABLE) 1663 if (cmd->autoneg != AUTONEG_ENABLE && cmd->autoneg != AUTONEG_DISABLE)
1517 return -EINVAL; 1664 return -EINVAL;
1518 if (cmd->autoneg == AUTONEG_ENABLE && cmd->advertising == 0) 1665 if (cmd->autoneg == AUTONEG_ENABLE && cmd->advertising == 0)
1519 return -EINVAL; 1666 return -EINVAL;
1520 if (cmd->duplex != DUPLEX_HALF && cmd->duplex != DUPLEX_FULL) 1667 if (cmd->duplex != DUPLEX_HALF && cmd->duplex != DUPLEX_FULL)
1521 return -EINVAL; 1668 return -EINVAL;
1522 if (cmd->autoneg == AUTONEG_DISABLE) 1669
1670 if (cmd->autoneg == AUTONEG_DISABLE) {
1523 switch (cmd->speed) { 1671 switch (cmd->speed) {
1524 case SPEED_10: 1672 case SPEED_10:
1525 if (cmd->duplex == DUPLEX_HALF && 1673 if (cmd->duplex == DUPLEX_HALF
1526 (features & SUPPORTED_10baseT_Half) == 0) 1674 && !(f & SUPPORTED_10baseT_Half))
1527 return -EINVAL; 1675 return -EINVAL;
1528 if (cmd->duplex == DUPLEX_FULL && 1676 if (cmd->duplex == DUPLEX_FULL
1529 (features & SUPPORTED_10baseT_Full) == 0) 1677 && !(f & SUPPORTED_10baseT_Full))
1530 return -EINVAL; 1678 return -EINVAL;
1531 break; 1679 break;
1532 case SPEED_100: 1680 case SPEED_100:
1533 if (cmd->duplex == DUPLEX_HALF && 1681 if (cmd->duplex == DUPLEX_HALF
1534 (features & SUPPORTED_100baseT_Half) == 0) 1682 && !(f & SUPPORTED_100baseT_Half))
1535 return -EINVAL; 1683 return -EINVAL;
1536 if (cmd->duplex == DUPLEX_FULL && 1684 if (cmd->duplex == DUPLEX_FULL
1537 (features & SUPPORTED_100baseT_Full) == 0) 1685 && !(f & SUPPORTED_100baseT_Full))
1538 return -EINVAL; 1686 return -EINVAL;
1539 break; 1687 break;
1540 case SPEED_1000: 1688 case SPEED_1000:
1541 if (cmd->duplex == DUPLEX_HALF && 1689 if (cmd->duplex == DUPLEX_HALF
1542 (features & SUPPORTED_1000baseT_Half) == 0) 1690 && !(f & SUPPORTED_1000baseT_Half))
1543 return -EINVAL; 1691 return -EINVAL;
1544 if (cmd->duplex == DUPLEX_FULL && 1692 if (cmd->duplex == DUPLEX_FULL
1545 (features & SUPPORTED_1000baseT_Full) == 0) 1693 && !(f & SUPPORTED_1000baseT_Full))
1546 return -EINVAL; 1694 return -EINVAL;
1547 break; 1695 break;
1548 default: 1696 default:
1549 return -EINVAL; 1697 return -EINVAL;
1550 } else if ((features & SUPPORTED_Autoneg) == 0) 1698 }
1551 return -EINVAL; 1699
1552 spin_lock_irq(&fep->lock); 1700 local_bh_disable();
1553 emac_start_link(fep, cmd); 1701 dev->phy.def->ops->setup_forced(&dev->phy, cmd->speed,
1554 spin_unlock_irq(&fep->lock); 1702 cmd->duplex);
1703
1704 } else {
1705 if (!(f & SUPPORTED_Autoneg))
1706 return -EINVAL;
1707
1708 local_bh_disable();
1709 dev->phy.def->ops->setup_aneg(&dev->phy,
1710 (cmd->advertising & f) |
1711 (dev->phy.advertising &
1712 (ADVERTISED_Pause |
1713 ADVERTISED_Asym_Pause)));
1714 }
1715 emac_force_link_update(dev);
1716 local_bh_enable();
1717
1555 return 0; 1718 return 0;
1556} 1719}
1557 1720
1558static void 1721static void emac_ethtool_get_ringparam(struct net_device *ndev,
1559emac_get_drvinfo(struct net_device *ndev, struct ethtool_drvinfo *info) 1722 struct ethtool_ringparam *rp)
1560{ 1723{
1561 struct ocp_enet_private *fep = ndev->priv; 1724 rp->rx_max_pending = rp->rx_pending = NUM_RX_BUFF;
1562 1725 rp->tx_max_pending = rp->tx_pending = NUM_TX_BUFF;
1563 strcpy(info->driver, DRV_NAME);
1564 strcpy(info->version, DRV_VERSION);
1565 info->fw_version[0] = '\0';
1566 sprintf(info->bus_info, "IBM EMAC %d", fep->ocpdev->def->index);
1567 info->regdump_len = 0;
1568} 1726}
1569 1727
1570static int emac_nway_reset(struct net_device *ndev) 1728static void emac_ethtool_get_pauseparam(struct net_device *ndev,
1729 struct ethtool_pauseparam *pp)
1571{ 1730{
1572 struct ocp_enet_private *fep = ndev->priv; 1731 struct ocp_enet_private *dev = ndev->priv;
1732
1733 local_bh_disable();
1734 if ((dev->phy.features & SUPPORTED_Autoneg) &&
1735 (dev->phy.advertising & (ADVERTISED_Pause | ADVERTISED_Asym_Pause)))
1736 pp->autoneg = 1;
1737
1738 if (dev->phy.duplex == DUPLEX_FULL) {
1739 if (dev->phy.pause)
1740 pp->rx_pause = pp->tx_pause = 1;
1741 else if (dev->phy.asym_pause)
1742 pp->tx_pause = 1;
1743 }
1744 local_bh_enable();
1745}
1573 1746
1574 if (!fep->want_autoneg) 1747static u32 emac_ethtool_get_rx_csum(struct net_device *ndev)
1575 return -EINVAL; 1748{
1576 spin_lock_irq(&fep->lock); 1749 struct ocp_enet_private *dev = ndev->priv;
1577 emac_start_link(fep, NULL); 1750 return dev->tah_dev != 0;
1578 spin_unlock_irq(&fep->lock);
1579 return 0;
1580} 1751}
1581 1752
1582static u32 emac_get_link(struct net_device *ndev) 1753static int emac_get_regs_len(struct ocp_enet_private *dev)
1583{ 1754{
1584 return netif_carrier_ok(ndev); 1755 return sizeof(struct emac_ethtool_regs_subhdr) + EMAC_ETHTOOL_REGS_SIZE;
1585} 1756}
1586 1757
1587static struct ethtool_ops emac_ethtool_ops = { 1758static int emac_ethtool_get_regs_len(struct net_device *ndev)
1588 .get_settings = emac_get_settings, 1759{
1589 .set_settings = emac_set_settings, 1760 struct ocp_enet_private *dev = ndev->priv;
1590 .get_drvinfo = emac_get_drvinfo, 1761 return sizeof(struct emac_ethtool_regs_hdr) +
1591 .nway_reset = emac_nway_reset, 1762 emac_get_regs_len(dev) + mal_get_regs_len(dev->mal) +
1592 .get_link = emac_get_link 1763 zmii_get_regs_len(dev->zmii_dev) +
1593}; 1764 rgmii_get_regs_len(dev->rgmii_dev) +
1765 tah_get_regs_len(dev->tah_dev);
1766}
1594 1767
1595static int emac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 1768static void *emac_dump_regs(struct ocp_enet_private *dev, void *buf)
1596{ 1769{
1597 struct ocp_enet_private *fep = dev->priv; 1770 struct emac_ethtool_regs_subhdr *hdr = buf;
1598 uint16_t *data = (uint16_t *) & rq->ifr_ifru;
1599 1771
1600 switch (cmd) { 1772 hdr->version = EMAC_ETHTOOL_REGS_VER;
1601 case SIOCGMIIPHY: 1773 hdr->index = dev->def->index;
1602 data[0] = fep->mii_phy_addr; 1774 memcpy_fromio(hdr + 1, dev->emacp, EMAC_ETHTOOL_REGS_SIZE);
1603 /* Fall through */ 1775 return ((void *)(hdr + 1) + EMAC_ETHTOOL_REGS_SIZE);
1604 case SIOCGMIIREG: 1776}
1605 data[3] = emac_phy_read(dev, fep->mii_phy_addr, data[1]);
1606 return 0;
1607 case SIOCSMIIREG:
1608 if (!capable(CAP_NET_ADMIN))
1609 return -EPERM;
1610 1777
1611 emac_phy_write(dev, fep->mii_phy_addr, data[1], data[2]); 1778static void emac_ethtool_get_regs(struct net_device *ndev,
1612 return 0; 1779 struct ethtool_regs *regs, void *buf)
1613 default: 1780{
1614 return -EOPNOTSUPP; 1781 struct ocp_enet_private *dev = ndev->priv;
1782 struct emac_ethtool_regs_hdr *hdr = buf;
1783
1784 hdr->components = 0;
1785 buf = hdr + 1;
1786
1787 local_irq_disable();
1788 buf = mal_dump_regs(dev->mal, buf);
1789 buf = emac_dump_regs(dev, buf);
1790 if (dev->zmii_dev) {
1791 hdr->components |= EMAC_ETHTOOL_REGS_ZMII;
1792 buf = zmii_dump_regs(dev->zmii_dev, buf);
1615 } 1793 }
1794 if (dev->rgmii_dev) {
1795 hdr->components |= EMAC_ETHTOOL_REGS_RGMII;
1796 buf = rgmii_dump_regs(dev->rgmii_dev, buf);
1797 }
1798 if (dev->tah_dev) {
1799 hdr->components |= EMAC_ETHTOOL_REGS_TAH;
1800 buf = tah_dump_regs(dev->tah_dev, buf);
1801 }
1802 local_irq_enable();
1616} 1803}
1617 1804
1618static int emac_open(struct net_device *dev) 1805static int emac_ethtool_nway_reset(struct net_device *ndev)
1619{ 1806{
1620 struct ocp_enet_private *fep = dev->priv; 1807 struct ocp_enet_private *dev = ndev->priv;
1621 int rc; 1808 int res = 0;
1622 1809
1623 spin_lock_irq(&fep->lock); 1810 DBG("%d: nway_reset" NL, dev->def->index);
1624 1811
1625 fep->opened = 1; 1812 if (dev->phy.address < 0)
1626 netif_carrier_off(dev); 1813 return -EOPNOTSUPP;
1627 1814
1628 /* Reset & configure the chip */ 1815 local_bh_disable();
1629 emac_reset_configure(fep); 1816 if (!dev->phy.autoneg) {
1817 res = -EINVAL;
1818 goto out;
1819 }
1630 1820
1631 spin_unlock_irq(&fep->lock); 1821 dev->phy.def->ops->setup_aneg(&dev->phy, dev->phy.advertising);
1822 emac_force_link_update(dev);
1632 1823
1633 /* Request our interrupt lines */ 1824 out:
1634 rc = request_irq(dev->irq, emac_mac_irq, 0, "IBM EMAC MAC", dev); 1825 local_bh_enable();
1635 if (rc != 0) { 1826 return res;
1636 printk("dev->irq %d failed\n", dev->irq); 1827}
1637 goto bail;
1638 }
1639 /* Kick the chip rx & tx channels into life */
1640 spin_lock_irq(&fep->lock);
1641 emac_kick(fep);
1642 spin_unlock_irq(&fep->lock);
1643 1828
1644 netif_start_queue(dev); 1829static int emac_ethtool_get_stats_count(struct net_device *ndev)
1645 bail: 1830{
1646 return rc; 1831 return EMAC_ETHTOOL_STATS_COUNT;
1647} 1832}
1648 1833
1649static int emac_close(struct net_device *dev) 1834static void emac_ethtool_get_strings(struct net_device *ndev, u32 stringset,
1835 u8 * buf)
1650{ 1836{
1651 struct ocp_enet_private *fep = dev->priv; 1837 if (stringset == ETH_SS_STATS)
1652 emac_t *emacp = fep->emacp; 1838 memcpy(buf, &emac_stats_keys, sizeof(emac_stats_keys));
1839}
1653 1840
1654 /* XXX Stop IRQ emitting here */ 1841static void emac_ethtool_get_ethtool_stats(struct net_device *ndev,
1655 spin_lock_irq(&fep->lock); 1842 struct ethtool_stats *estats,
1656 fep->opened = 0; 1843 u64 * tmp_stats)
1657 mal_disable_tx_channels(fep->mal, fep->commac.tx_chan_mask); 1844{
1658 mal_disable_rx_channels(fep->mal, fep->commac.rx_chan_mask); 1845 struct ocp_enet_private *dev = ndev->priv;
1659 netif_carrier_off(dev); 1846 local_irq_disable();
1660 netif_stop_queue(dev); 1847 memcpy(tmp_stats, &dev->stats, sizeof(dev->stats));
1848 tmp_stats += sizeof(dev->stats) / sizeof(u64);
1849 memcpy(tmp_stats, &dev->estats, sizeof(dev->estats));
1850 local_irq_enable();
1851}
1661 1852
1662 /* 1853static void emac_ethtool_get_drvinfo(struct net_device *ndev,
1663 * Check for a link, some PHYs don't provide a clock if 1854 struct ethtool_drvinfo *info)
1664 * no link is present. Some EMACs will not come out of 1855{
1665 * soft reset without a PHY clock present. 1856 struct ocp_enet_private *dev = ndev->priv;
1666 */
1667 if (fep->phy_mii.def->ops->poll_link(&fep->phy_mii)) {
1668 out_be32(&emacp->em0mr0, EMAC_M0_SRST);
1669 udelay(10);
1670 1857
1671 if (emacp->em0mr0 & EMAC_M0_SRST) { 1858 strcpy(info->driver, "ibm_emac");
1672 /*not sure what to do here hopefully it clears before another open */ 1859 strcpy(info->version, DRV_VERSION);
1673 printk(KERN_ERR 1860 info->fw_version[0] = '\0';
1674 "%s: Phy SoftReset didn't clear, no link?\n", 1861 sprintf(info->bus_info, "PPC 4xx EMAC %d", dev->def->index);
1675 dev->name); 1862 info->n_stats = emac_ethtool_get_stats_count(ndev);
1676 } 1863 info->regdump_len = emac_ethtool_get_regs_len(ndev);
1677 } 1864}
1678 1865
1679 /* Free the irq's */ 1866static struct ethtool_ops emac_ethtool_ops = {
1680 free_irq(dev->irq, dev); 1867 .get_settings = emac_ethtool_get_settings,
1868 .set_settings = emac_ethtool_set_settings,
1869 .get_drvinfo = emac_ethtool_get_drvinfo,
1681 1870
1682 spin_unlock_irq(&fep->lock); 1871 .get_regs_len = emac_ethtool_get_regs_len,
1872 .get_regs = emac_ethtool_get_regs,
1683 1873
1684 return 0; 1874 .nway_reset = emac_ethtool_nway_reset,
1685}
1686 1875
1687static void emac_remove(struct ocp_device *ocpdev) 1876 .get_ringparam = emac_ethtool_get_ringparam,
1688{ 1877 .get_pauseparam = emac_ethtool_get_pauseparam,
1689 struct net_device *dev = ocp_get_drvdata(ocpdev); 1878
1690 struct ocp_enet_private *ep = dev->priv; 1879 .get_rx_csum = emac_ethtool_get_rx_csum,
1691 1880
1692 /* FIXME: locking, races, ... */ 1881 .get_strings = emac_ethtool_get_strings,
1693 ep->going_away = 1; 1882 .get_stats_count = emac_ethtool_get_stats_count,
1694 ocp_set_drvdata(ocpdev, NULL); 1883 .get_ethtool_stats = emac_ethtool_get_ethtool_stats,
1695 if (ep->rgmii_dev) 1884
1696 emac_close_rgmii(ep->rgmii_dev); 1885 .get_link = ethtool_op_get_link,
1697 if (ep->zmii_dev) 1886 .get_tx_csum = ethtool_op_get_tx_csum,
1698 emac_close_zmii(ep->zmii_dev); 1887 .get_sg = ethtool_op_get_sg,
1699
1700 unregister_netdev(dev);
1701 del_timer_sync(&ep->link_timer);
1702 mal_unregister_commac(ep->mal, &ep->commac);
1703 iounmap((void *)ep->emacp);
1704 kfree(dev);
1705}
1706
1707struct mal_commac_ops emac_commac_ops = {
1708 .txeob = &emac_txeob_dev,
1709 .txde = &emac_txde_dev,
1710 .rxeob = &emac_rxeob_dev,
1711 .rxde = &emac_rxde_dev,
1712}; 1888};
1713 1889
1714#ifdef CONFIG_NET_POLL_CONTROLLER 1890static int emac_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
1715static void emac_netpoll(struct net_device *ndev)
1716{ 1891{
1717 emac_rxeob_dev((void *)ndev, 0); 1892 struct ocp_enet_private *dev = ndev->priv;
1718 emac_txeob_dev((void *)ndev, 0); 1893 uint16_t *data = (uint16_t *) & rq->ifr_ifru;
1894
1895 DBG("%d: ioctl %08x" NL, dev->def->index, cmd);
1896
1897 if (dev->phy.address < 0)
1898 return -EOPNOTSUPP;
1899
1900 switch (cmd) {
1901 case SIOCGMIIPHY:
1902 case SIOCDEVPRIVATE:
1903 data[0] = dev->phy.address;
1904 /* Fall through */
1905 case SIOCGMIIREG:
1906 case SIOCDEVPRIVATE + 1:
1907 data[3] = emac_mdio_read(ndev, dev->phy.address, data[1]);
1908 return 0;
1909
1910 case SIOCSMIIREG:
1911 case SIOCDEVPRIVATE + 2:
1912 if (!capable(CAP_NET_ADMIN))
1913 return -EPERM;
1914 emac_mdio_write(ndev, dev->phy.address, data[1], data[2]);
1915 return 0;
1916 default:
1917 return -EOPNOTSUPP;
1918 }
1719} 1919}
1720#endif
1721 1920
1722static int emac_init_device(struct ocp_device *ocpdev, struct ibm_ocp_mal *mal) 1921static int __init emac_probe(struct ocp_device *ocpdev)
1723{ 1922{
1724 int deferred_init = 0; 1923 struct ocp_func_emac_data *emacdata = ocpdev->def->additions;
1725 int rc = 0, i;
1726 struct net_device *ndev; 1924 struct net_device *ndev;
1727 struct ocp_enet_private *ep; 1925 struct ocp_device *maldev;
1728 struct ocp_func_emac_data *emacdata; 1926 struct ocp_enet_private *dev;
1729 int commac_reg = 0; 1927 int err, i;
1730 u32 phy_map; 1928
1929 DBG("%d: probe" NL, ocpdev->def->index);
1731 1930
1732 emacdata = (struct ocp_func_emac_data *)ocpdev->def->additions;
1733 if (!emacdata) { 1931 if (!emacdata) {
1734 printk(KERN_ERR "emac%d: Missing additional data!\n", 1932 printk(KERN_ERR "emac%d: Missing additional data!\n",
1735 ocpdev->def->index); 1933 ocpdev->def->index);
@@ -1738,304 +1936,312 @@ static int emac_init_device(struct ocp_device *ocpdev, struct ibm_ocp_mal *mal)
1738 1936
1739 /* Allocate our net_device structure */ 1937 /* Allocate our net_device structure */
1740 ndev = alloc_etherdev(sizeof(struct ocp_enet_private)); 1938 ndev = alloc_etherdev(sizeof(struct ocp_enet_private));
1741 if (ndev == NULL) { 1939 if (!ndev) {
1742 printk(KERN_ERR 1940 printk(KERN_ERR "emac%d: could not allocate ethernet device!\n",
1743 "emac%d: Could not allocate ethernet device.\n",
1744 ocpdev->def->index); 1941 ocpdev->def->index);
1745 return -ENOMEM; 1942 return -ENOMEM;
1746 } 1943 }
1747 ep = ndev->priv; 1944 dev = ndev->priv;
1748 ep->ndev = ndev; 1945 dev->ndev = ndev;
1749 ep->ocpdev = ocpdev; 1946 dev->ldev = &ocpdev->dev;
1750 ndev->irq = ocpdev->def->irq; 1947 dev->def = ocpdev->def;
1751 ep->wol_irq = emacdata->wol_irq; 1948 SET_MODULE_OWNER(ndev);
1752 if (emacdata->mdio_idx >= 0) {
1753 if (emacdata->mdio_idx == ocpdev->def->index) {
1754 /* Set the common MDIO net_device */
1755 mdio_ndev = ndev;
1756 deferred_init = 1;
1757 }
1758 ep->mdio_dev = mdio_ndev;
1759 } else {
1760 ep->mdio_dev = ndev;
1761 }
1762 1949
1763 ocp_set_drvdata(ocpdev, ndev); 1950 /* Find MAL device we are connected to */
1764 1951 maldev =
1765 spin_lock_init(&ep->lock); 1952 ocp_find_device(OCP_VENDOR_IBM, OCP_FUNC_MAL, emacdata->mal_idx);
1766 1953 if (!maldev) {
1767 /* Fill out MAL informations and register commac */ 1954 printk(KERN_ERR "emac%d: unknown mal%d device!\n",
1768 ep->mal = mal; 1955 dev->def->index, emacdata->mal_idx);
1769 ep->mal_tx_chan = emacdata->mal_tx_chan; 1956 err = -ENODEV;
1770 ep->mal_rx_chan = emacdata->mal_rx_chan; 1957 goto out;
1771 ep->commac.ops = &emac_commac_ops; 1958 }
1772 ep->commac.dev = ndev; 1959 dev->mal = ocp_get_drvdata(maldev);
1773 ep->commac.tx_chan_mask = MAL_CHAN_MASK(ep->mal_tx_chan); 1960 if (!dev->mal) {
1774 ep->commac.rx_chan_mask = MAL_CHAN_MASK(ep->mal_rx_chan); 1961 printk(KERN_ERR "emac%d: mal%d hasn't been initialized yet!\n",
1775 rc = mal_register_commac(ep->mal, &ep->commac); 1962 dev->def->index, emacdata->mal_idx);
1776 if (rc != 0) 1963 err = -ENODEV;
1777 goto bail; 1964 goto out;
1778 commac_reg = 1;
1779
1780 /* Map our MMIOs */
1781 ep->emacp = (emac_t *) ioremap(ocpdev->def->paddr, sizeof(emac_t));
1782
1783 /* Check if we need to attach to a ZMII */
1784 if (emacdata->zmii_idx >= 0) {
1785 ep->zmii_input = emacdata->zmii_mux;
1786 ep->zmii_dev =
1787 ocp_find_device(OCP_ANY_ID, OCP_FUNC_ZMII,
1788 emacdata->zmii_idx);
1789 if (ep->zmii_dev == NULL)
1790 printk(KERN_WARNING
1791 "emac%d: ZMII %d requested but not found !\n",
1792 ocpdev->def->index, emacdata->zmii_idx);
1793 else if ((rc =
1794 emac_init_zmii(ep->zmii_dev, ep->zmii_input,
1795 emacdata->phy_mode)) != 0)
1796 goto bail;
1797 } 1965 }
1798 1966
1799 /* Check if we need to attach to a RGMII */ 1967 /* Register with MAL */
1800 if (emacdata->rgmii_idx >= 0) { 1968 dev->commac.ops = &emac_commac_ops;
1801 ep->rgmii_input = emacdata->rgmii_mux; 1969 dev->commac.dev = dev;
1802 ep->rgmii_dev = 1970 dev->commac.tx_chan_mask = MAL_CHAN_MASK(emacdata->mal_tx_chan);
1803 ocp_find_device(OCP_ANY_ID, OCP_FUNC_RGMII, 1971 dev->commac.rx_chan_mask = MAL_CHAN_MASK(emacdata->mal_rx_chan);
1804 emacdata->rgmii_idx); 1972 err = mal_register_commac(dev->mal, &dev->commac);
1805 if (ep->rgmii_dev == NULL) 1973 if (err) {
1806 printk(KERN_WARNING 1974 printk(KERN_ERR "emac%d: failed to register with mal%d!\n",
1807 "emac%d: RGMII %d requested but not found !\n", 1975 dev->def->index, emacdata->mal_idx);
1808 ocpdev->def->index, emacdata->rgmii_idx); 1976 goto out;
1809 else if ((rc = 1977 }
1810 emac_init_rgmii(ep->rgmii_dev, ep->rgmii_input, 1978 dev->rx_skb_size = emac_rx_skb_size(ndev->mtu);
1811 emacdata->phy_mode)) != 0) 1979 dev->rx_sync_size = emac_rx_sync_size(ndev->mtu);
1812 goto bail; 1980
1981 /* Get pointers to BD rings */
1982 dev->tx_desc =
1983 dev->mal->bd_virt + mal_tx_bd_offset(dev->mal,
1984 emacdata->mal_tx_chan);
1985 dev->rx_desc =
1986 dev->mal->bd_virt + mal_rx_bd_offset(dev->mal,
1987 emacdata->mal_rx_chan);
1988
1989 DBG("%d: tx_desc %p" NL, ocpdev->def->index, dev->tx_desc);
1990 DBG("%d: rx_desc %p" NL, ocpdev->def->index, dev->rx_desc);
1991
1992 /* Clean rings */
1993 memset(dev->tx_desc, 0, NUM_TX_BUFF * sizeof(struct mal_descriptor));
1994 memset(dev->rx_desc, 0, NUM_RX_BUFF * sizeof(struct mal_descriptor));
1995
1996 /* If we depend on another EMAC for MDIO, check whether it was probed already */
1997 if (emacdata->mdio_idx >= 0 && emacdata->mdio_idx != ocpdev->def->index) {
1998 struct ocp_device *mdiodev =
1999 ocp_find_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC,
2000 emacdata->mdio_idx);
2001 if (!mdiodev) {
2002 printk(KERN_ERR "emac%d: unknown emac%d device!\n",
2003 dev->def->index, emacdata->mdio_idx);
2004 err = -ENODEV;
2005 goto out2;
2006 }
2007 dev->mdio_dev = ocp_get_drvdata(mdiodev);
2008 if (!dev->mdio_dev) {
2009 printk(KERN_ERR
2010 "emac%d: emac%d hasn't been initialized yet!\n",
2011 dev->def->index, emacdata->mdio_idx);
2012 err = -ENODEV;
2013 goto out2;
2014 }
1813 } 2015 }
1814 2016
1815 /* Check if we need to attach to a TAH */ 2017 /* Attach to ZMII, if needed */
1816 if (emacdata->tah_idx >= 0) { 2018 if ((err = zmii_attach(dev)) != 0)
1817 ep->tah_dev = 2019 goto out2;
1818 ocp_find_device(OCP_ANY_ID, OCP_FUNC_TAH, 2020
1819 emacdata->tah_idx); 2021 /* Attach to RGMII, if needed */
1820 if (ep->tah_dev == NULL) 2022 if ((err = rgmii_attach(dev)) != 0)
1821 printk(KERN_WARNING 2023 goto out3;
1822 "emac%d: TAH %d requested but not found !\n", 2024
1823 ocpdev->def->index, emacdata->tah_idx); 2025 /* Attach to TAH, if needed */
1824 else if ((rc = emac_init_tah(ep)) != 0) 2026 if ((err = tah_attach(dev)) != 0)
1825 goto bail; 2027 goto out4;
2028
2029 /* Map EMAC regs */
2030 dev->emacp =
2031 (struct emac_regs *)ioremap(dev->def->paddr,
2032 sizeof(struct emac_regs));
2033 if (!dev->emacp) {
2034 printk(KERN_ERR "emac%d: could not ioremap device registers!\n",
2035 dev->def->index);
2036 err = -ENOMEM;
2037 goto out5;
1826 } 2038 }
1827 2039
1828 if (deferred_init) { 2040 /* Fill in MAC address */
1829 if (!list_empty(&emac_init_list)) { 2041 for (i = 0; i < 6; ++i)
1830 struct list_head *entry; 2042 ndev->dev_addr[i] = emacdata->mac_addr[i];
1831 struct emac_def_dev *ddev;
1832 2043
1833 list_for_each(entry, &emac_init_list) { 2044 /* Set some link defaults before we can find out real parameters */
1834 ddev = 2045 dev->phy.speed = SPEED_100;
1835 list_entry(entry, struct emac_def_dev, 2046 dev->phy.duplex = DUPLEX_FULL;
1836 link); 2047 dev->phy.autoneg = AUTONEG_DISABLE;
1837 emac_init_device(ddev->ocpdev, ddev->mal); 2048 dev->phy.pause = dev->phy.asym_pause = 0;
1838 } 2049 init_timer(&dev->link_timer);
2050 dev->link_timer.function = emac_link_timer;
2051 dev->link_timer.data = (unsigned long)dev;
2052
2053 /* Find PHY if any */
2054 dev->phy.dev = ndev;
2055 dev->phy.mode = emacdata->phy_mode;
2056 if (emacdata->phy_map != 0xffffffff) {
2057 u32 phy_map = emacdata->phy_map | busy_phy_map;
2058 u32 adv;
2059
2060 DBG("%d: PHY maps %08x %08x" NL, dev->def->index,
2061 emacdata->phy_map, busy_phy_map);
2062
2063 EMAC_RX_CLK_TX(dev->def->index);
2064
2065 dev->phy.mdio_read = emac_mdio_read;
2066 dev->phy.mdio_write = emac_mdio_write;
2067
2068 /* Configure EMAC with defaults so we can at least use MDIO
2069 * This is needed mostly for 440GX
2070 */
2071 if (emac_phy_gpcs(dev->phy.mode)) {
2072 /* XXX
2073 * Make GPCS PHY address equal to EMAC index.
2074 * We probably should take into account busy_phy_map
2075 * and/or phy_map here.
2076 */
2077 dev->phy.address = dev->def->index;
1839 } 2078 }
1840 } 2079
2080 emac_configure(dev);
1841 2081
1842 /* Init link monitoring timer */ 2082 for (i = 0; i < 0x20; phy_map >>= 1, ++i)
1843 init_timer(&ep->link_timer); 2083 if (!(phy_map & 1)) {
1844 ep->link_timer.function = emac_link_timer; 2084 int r;
1845 ep->link_timer.data = (unsigned long)ep; 2085 busy_phy_map |= 1 << i;
1846 ep->timer_ticks = 0; 2086
1847 2087 /* Quick check if there is a PHY at the address */
1848 /* Fill up the mii_phy structure */ 2088 r = emac_mdio_read(dev->ndev, i, MII_BMCR);
1849 ep->phy_mii.dev = ndev; 2089 if (r == 0xffff || r < 0)
1850 ep->phy_mii.mdio_read = emac_phy_read; 2090 continue;
1851 ep->phy_mii.mdio_write = emac_phy_write; 2091 if (!mii_phy_probe(&dev->phy, i))
1852 ep->phy_mii.mode = emacdata->phy_mode; 2092 break;
1853 2093 }
1854 /* Find PHY */ 2094 if (i == 0x20) {
1855 phy_map = emacdata->phy_map | busy_phy_map; 2095 printk(KERN_WARNING "emac%d: can't find PHY!\n",
1856 for (i = 0; i <= 0x1f; i++, phy_map >>= 1) { 2096 dev->def->index);
1857 if ((phy_map & 0x1) == 0) { 2097 goto out6;
1858 int val = emac_phy_read(ndev, i, MII_BMCR);
1859 if (val != 0xffff && val != -1)
1860 break;
1861 } 2098 }
1862 }
1863 if (i == 0x20) {
1864 printk(KERN_WARNING "emac%d: Can't find PHY.\n",
1865 ocpdev->def->index);
1866 rc = -ENODEV;
1867 goto bail;
1868 }
1869 busy_phy_map |= 1 << i;
1870 ep->mii_phy_addr = i;
1871 rc = mii_phy_probe(&ep->phy_mii, i);
1872 if (rc) {
1873 printk(KERN_WARNING "emac%d: Failed to probe PHY type.\n",
1874 ocpdev->def->index);
1875 rc = -ENODEV;
1876 goto bail;
1877 }
1878
1879 /* Disable any PHY features not supported by the platform */
1880 ep->phy_mii.def->features &= ~emacdata->phy_feat_exc;
1881 2099
1882 /* Setup initial PHY config & startup aneg */ 2100 /* Init PHY */
1883 if (ep->phy_mii.def->ops->init) 2101 if (dev->phy.def->ops->init)
1884 ep->phy_mii.def->ops->init(&ep->phy_mii); 2102 dev->phy.def->ops->init(&dev->phy);
1885 netif_carrier_off(ndev);
1886 if (ep->phy_mii.def->features & SUPPORTED_Autoneg)
1887 ep->want_autoneg = 1;
1888 else {
1889 ep->want_autoneg = 0;
1890 2103
1891 /* Select highest supported speed/duplex */ 2104 /* Disable any PHY features not supported by the platform */
1892 if (ep->phy_mii.def->features & SUPPORTED_1000baseT_Full) { 2105 dev->phy.def->features &= ~emacdata->phy_feat_exc;
1893 ep->phy_mii.speed = SPEED_1000; 2106
1894 ep->phy_mii.duplex = DUPLEX_FULL; 2107 /* Setup initial link parameters */
1895 } else if (ep->phy_mii.def->features & 2108 if (dev->phy.features & SUPPORTED_Autoneg) {
1896 SUPPORTED_1000baseT_Half) { 2109 adv = dev->phy.features;
1897 ep->phy_mii.speed = SPEED_1000; 2110#if !defined(CONFIG_40x)
1898 ep->phy_mii.duplex = DUPLEX_HALF; 2111 adv |= ADVERTISED_Pause | ADVERTISED_Asym_Pause;
1899 } else if (ep->phy_mii.def->features & 2112#endif
1900 SUPPORTED_100baseT_Full) { 2113 /* Restart autonegotiation */
1901 ep->phy_mii.speed = SPEED_100; 2114 dev->phy.def->ops->setup_aneg(&dev->phy, adv);
1902 ep->phy_mii.duplex = DUPLEX_FULL;
1903 } else if (ep->phy_mii.def->features &
1904 SUPPORTED_100baseT_Half) {
1905 ep->phy_mii.speed = SPEED_100;
1906 ep->phy_mii.duplex = DUPLEX_HALF;
1907 } else if (ep->phy_mii.def->features &
1908 SUPPORTED_10baseT_Full) {
1909 ep->phy_mii.speed = SPEED_10;
1910 ep->phy_mii.duplex = DUPLEX_FULL;
1911 } else { 2115 } else {
1912 ep->phy_mii.speed = SPEED_10; 2116 u32 f = dev->phy.def->features;
1913 ep->phy_mii.duplex = DUPLEX_HALF; 2117 int speed = SPEED_10, fd = DUPLEX_HALF;
2118
2119 /* Select highest supported speed/duplex */
2120 if (f & SUPPORTED_1000baseT_Full) {
2121 speed = SPEED_1000;
2122 fd = DUPLEX_FULL;
2123 } else if (f & SUPPORTED_1000baseT_Half)
2124 speed = SPEED_1000;
2125 else if (f & SUPPORTED_100baseT_Full) {
2126 speed = SPEED_100;
2127 fd = DUPLEX_FULL;
2128 } else if (f & SUPPORTED_100baseT_Half)
2129 speed = SPEED_100;
2130 else if (f & SUPPORTED_10baseT_Full)
2131 fd = DUPLEX_FULL;
2132
2133 /* Force link parameters */
2134 dev->phy.def->ops->setup_forced(&dev->phy, speed, fd);
1914 } 2135 }
1915 } 2136 } else {
1916 emac_start_link(ep, NULL); 2137 emac_reset(dev);
1917 2138
1918 /* read the MAC Address */ 2139 /* PHY-less configuration.
1919 for (i = 0; i < 6; i++) 2140 * XXX I probably should move these settings to emacdata
1920 ndev->dev_addr[i] = emacdata->mac_addr[i]; 2141 */
2142 dev->phy.address = -1;
2143 dev->phy.features = SUPPORTED_100baseT_Full | SUPPORTED_MII;
2144 dev->phy.pause = 1;
2145 }
1921 2146
1922 /* Fill in the driver function table */ 2147 /* Fill in the driver function table */
1923 ndev->open = &emac_open; 2148 ndev->open = &emac_open;
1924 ndev->hard_start_xmit = &emac_start_xmit; 2149 if (dev->tah_dev) {
2150 ndev->hard_start_xmit = &emac_start_xmit_sg;
2151 ndev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
2152 } else
2153 ndev->hard_start_xmit = &emac_start_xmit;
2154 ndev->tx_timeout = &emac_full_tx_reset;
2155 ndev->watchdog_timeo = 5 * HZ;
1925 ndev->stop = &emac_close; 2156 ndev->stop = &emac_close;
1926 ndev->get_stats = &emac_stats; 2157 ndev->get_stats = &emac_stats;
1927 if (emacdata->jumbo)
1928 ndev->change_mtu = &emac_change_mtu;
1929 ndev->set_mac_address = &emac_set_mac_address;
1930 ndev->set_multicast_list = &emac_set_multicast_list; 2158 ndev->set_multicast_list = &emac_set_multicast_list;
1931 ndev->do_ioctl = &emac_ioctl; 2159 ndev->do_ioctl = &emac_ioctl;
2160 if (emac_phy_supports_gige(emacdata->phy_mode)) {
2161 ndev->change_mtu = &emac_change_mtu;
2162 dev->commac.ops = &emac_commac_sg_ops;
2163 }
1932 SET_ETHTOOL_OPS(ndev, &emac_ethtool_ops); 2164 SET_ETHTOOL_OPS(ndev, &emac_ethtool_ops);
1933 if (emacdata->tah_idx >= 0)
1934 ndev->features = NETIF_F_IP_CSUM | NETIF_F_SG;
1935#ifdef CONFIG_NET_POLL_CONTROLLER
1936 ndev->poll_controller = emac_netpoll;
1937#endif
1938 2165
1939 SET_MODULE_OWNER(ndev); 2166 netif_carrier_off(ndev);
2167 netif_stop_queue(ndev);
2168
2169 err = register_netdev(ndev);
2170 if (err) {
2171 printk(KERN_ERR "emac%d: failed to register net device (%d)!\n",
2172 dev->def->index, err);
2173 goto out6;
2174 }
1940 2175
1941 rc = register_netdev(ndev); 2176 ocp_set_drvdata(ocpdev, dev);
1942 if (rc != 0)
1943 goto bail;
1944 2177
1945 printk("%s: IBM emac, MAC %02x:%02x:%02x:%02x:%02x:%02x\n", 2178 printk("%s: emac%d, MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
1946 ndev->name, 2179 ndev->name, dev->def->index,
1947 ndev->dev_addr[0], ndev->dev_addr[1], ndev->dev_addr[2], 2180 ndev->dev_addr[0], ndev->dev_addr[1], ndev->dev_addr[2],
1948 ndev->dev_addr[3], ndev->dev_addr[4], ndev->dev_addr[5]); 2181 ndev->dev_addr[3], ndev->dev_addr[4], ndev->dev_addr[5]);
1949 printk(KERN_INFO "%s: Found %s PHY (0x%02x)\n",
1950 ndev->name, ep->phy_mii.def->name, ep->mii_phy_addr);
1951 2182
1952 bail: 2183 if (dev->phy.address >= 0)
1953 if (rc && commac_reg) 2184 printk("%s: found %s PHY (0x%02x)\n", ndev->name,
1954 mal_unregister_commac(ep->mal, &ep->commac); 2185 dev->phy.def->name, dev->phy.address);
1955 if (rc && ndev)
1956 kfree(ndev);
1957 2186
1958 return rc; 2187 emac_dbg_register(dev->def->index, dev);
1959}
1960
1961static int emac_probe(struct ocp_device *ocpdev)
1962{
1963 struct ocp_device *maldev;
1964 struct ibm_ocp_mal *mal;
1965 struct ocp_func_emac_data *emacdata;
1966
1967 emacdata = (struct ocp_func_emac_data *)ocpdev->def->additions;
1968 if (emacdata == NULL) {
1969 printk(KERN_ERR "emac%d: Missing additional datas !\n",
1970 ocpdev->def->index);
1971 return -ENODEV;
1972 }
1973
1974 /* Get the MAL device */
1975 maldev = ocp_find_device(OCP_ANY_ID, OCP_FUNC_MAL, emacdata->mal_idx);
1976 if (maldev == NULL) {
1977 printk("No maldev\n");
1978 return -ENODEV;
1979 }
1980 /*
1981 * Get MAL driver data, it must be here due to link order.
1982 * When the driver is modularized, symbol dependencies will
1983 * ensure the MAL driver is already present if built as a
1984 * module.
1985 */
1986 mal = (struct ibm_ocp_mal *)ocp_get_drvdata(maldev);
1987 if (mal == NULL) {
1988 printk("No maldrv\n");
1989 return -ENODEV;
1990 }
1991
1992 /* If we depend on another EMAC for MDIO, wait for it to show up */
1993 if (emacdata->mdio_idx >= 0 &&
1994 (emacdata->mdio_idx != ocpdev->def->index) && !mdio_ndev) {
1995 struct emac_def_dev *ddev;
1996 /* Add this index to the deferred init table */
1997 ddev = kmalloc(sizeof(struct emac_def_dev), GFP_KERNEL);
1998 ddev->ocpdev = ocpdev;
1999 ddev->mal = mal;
2000 list_add_tail(&ddev->link, &emac_init_list);
2001 } else {
2002 emac_init_device(ocpdev, mal);
2003 }
2004 2188
2005 return 0; 2189 return 0;
2190 out6:
2191 iounmap((void *)dev->emacp);
2192 out5:
2193 tah_fini(dev->tah_dev);
2194 out4:
2195 rgmii_fini(dev->rgmii_dev, dev->rgmii_input);
2196 out3:
2197 zmii_fini(dev->zmii_dev, dev->zmii_input);
2198 out2:
2199 mal_unregister_commac(dev->mal, &dev->commac);
2200 out:
2201 kfree(ndev);
2202 return err;
2006} 2203}
2007 2204
2008/* Structure for a device driver */
2009static struct ocp_device_id emac_ids[] = { 2205static struct ocp_device_id emac_ids[] = {
2010 {.vendor = OCP_ANY_ID,.function = OCP_FUNC_EMAC}, 2206 { .vendor = OCP_VENDOR_IBM, .function = OCP_FUNC_EMAC },
2011 {.vendor = OCP_VENDOR_INVALID} 2207 { .vendor = OCP_VENDOR_INVALID}
2012}; 2208};
2013 2209
2014static struct ocp_driver emac_driver = { 2210static struct ocp_driver emac_driver = {
2015 .name = "emac", 2211 .name = "emac",
2016 .id_table = emac_ids, 2212 .id_table = emac_ids,
2017
2018 .probe = emac_probe, 2213 .probe = emac_probe,
2019 .remove = emac_remove, 2214 .remove = emac_remove,
2020}; 2215};
2021 2216
2022static int __init emac_init(void) 2217static int __init emac_init(void)
2023{ 2218{
2024 printk(KERN_INFO DRV_NAME ": " DRV_DESC ", version " DRV_VERSION "\n"); 2219 printk(KERN_INFO DRV_DESC ", version " DRV_VERSION "\n");
2025 printk(KERN_INFO "Maintained by " DRV_AUTHOR "\n"); 2220
2221 DBG(": init" NL);
2026 2222
2027 if (skb_res > 2) { 2223 if (mal_init())
2028 printk(KERN_WARNING "Invalid skb_res: %d, cropping to 2\n", 2224 return -ENODEV;
2029 skb_res); 2225
2030 skb_res = 2; 2226 EMAC_CLK_INTERNAL;
2227 if (ocp_register_driver(&emac_driver)) {
2228 EMAC_CLK_EXTERNAL;
2229 ocp_unregister_driver(&emac_driver);
2230 mal_exit();
2231 return -ENODEV;
2031 } 2232 }
2233 EMAC_CLK_EXTERNAL;
2032 2234
2033 return ocp_register_driver(&emac_driver); 2235 emac_init_debug();
2236 return 0;
2034} 2237}
2035 2238
2036static void __exit emac_exit(void) 2239static void __exit emac_exit(void)
2037{ 2240{
2241 DBG(": exit" NL);
2038 ocp_unregister_driver(&emac_driver); 2242 ocp_unregister_driver(&emac_driver);
2243 mal_exit();
2244 emac_fini_debug();
2039} 2245}
2040 2246
2041module_init(emac_init); 2247module_init(emac_init);
diff --git a/drivers/net/ibm_emac/ibm_emac_core.h b/drivers/net/ibm_emac/ibm_emac_core.h
index 97e6e1ea8c89..e9b44d030ac3 100644
--- a/drivers/net/ibm_emac/ibm_emac_core.h
+++ b/drivers/net/ibm_emac/ibm_emac_core.h
@@ -1,146 +1,221 @@
1/* 1/*
2 * ibm_emac_core.h 2 * drivers/net/ibm_emac/ibm_emac_core.h
3 * 3 *
4 * Ethernet driver for the built in ethernet on the IBM 405 PowerPC 4 * Driver for PowerPC 4xx on-chip ethernet controller.
5 * processor.
6 * 5 *
7 * Armin Kuster akuster@mvista.com 6 * Copyright (c) 2004, 2005 Zultys Technologies.
8 * Sept, 2001 7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
9 * 8 *
10 * Orignial driver 9 * Based on original work by
11 * Johnnie Peters 10 * Armin Kuster <akuster@mvista.com>
12 * jpeters@mvista.com 11 * Johnnie Peters <jpeters@mvista.com>
13 * 12 * Copyright 2000, 2001 MontaVista Softare Inc.
14 * Copyright 2000 MontaVista Softare Inc.
15 * 13 *
16 * This program is free software; you can redistribute it and/or modify it 14 * This program is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License as published by the 15 * under the terms of the GNU General Public License as published by the
18 * Free Software Foundation; either version 2 of the License, or (at your 16 * Free Software Foundation; either version 2 of the License, or (at your
19 * option) any later version. 17 * option) any later version.
18 *
20 */ 19 */
20#ifndef __IBM_EMAC_CORE_H_
21#define __IBM_EMAC_CORE_H_
21 22
22#ifndef _IBM_EMAC_CORE_H_ 23#include <linux/config.h>
23#define _IBM_EMAC_CORE_H_
24
25#include <linux/netdevice.h> 24#include <linux/netdevice.h>
25#include <linux/dma-mapping.h>
26#include <asm/ocp.h> 26#include <asm/ocp.h>
27#include <asm/mmu.h> /* For phys_addr_t */
28 27
29#include "ibm_emac.h" 28#include "ibm_emac.h"
30#include "ibm_emac_phy.h" 29#include "ibm_emac_phy.h"
31#include "ibm_emac_rgmii.h"
32#include "ibm_emac_zmii.h" 30#include "ibm_emac_zmii.h"
31#include "ibm_emac_rgmii.h"
33#include "ibm_emac_mal.h" 32#include "ibm_emac_mal.h"
34#include "ibm_emac_tah.h" 33#include "ibm_emac_tah.h"
35 34
36#ifndef CONFIG_IBM_EMAC_TXB 35#define NUM_TX_BUFF CONFIG_IBM_EMAC_TXB
37#define NUM_TX_BUFF 64 36#define NUM_RX_BUFF CONFIG_IBM_EMAC_RXB
38#define NUM_RX_BUFF 64
39#else
40#define NUM_TX_BUFF CONFIG_IBM_EMAC_TXB
41#define NUM_RX_BUFF CONFIG_IBM_EMAC_RXB
42#endif
43 37
44/* This does 16 byte alignment, exactly what we need. 38/* Simple sanity check */
45 * The packet length includes FCS, but we don't want to 39#if NUM_TX_BUFF > 256 || NUM_RX_BUFF > 256
46 * include that when passing upstream as it messes up 40#error Invalid number of buffer descriptors (greater than 256)
47 * bridging applications.
48 */
49#ifndef CONFIG_IBM_EMAC_SKBRES
50#define SKB_RES 2
51#else
52#define SKB_RES CONFIG_IBM_EMAC_SKBRES
53#endif 41#endif
54 42
55/* Note about alignement. alloc_skb() returns a cache line 43// XXX
56 * aligned buffer. However, dev_alloc_skb() will add 16 more 44#define EMAC_MIN_MTU 46
57 * bytes and "reserve" them, so our buffer will actually end 45#define EMAC_MAX_MTU 9000
58 * on a half cache line. What we do is to use directly 46
59 * alloc_skb, allocate 16 more bytes to match the total amount 47/* Maximum L2 header length (VLAN tagged, no FCS) */
60 * allocated by dev_alloc_skb(), but we don't reserve. 48#define EMAC_MTU_OVERHEAD (6 * 2 + 2 + 4)
49
50/* RX BD size for the given MTU */
51static inline int emac_rx_size(int mtu)
52{
53 if (mtu > ETH_DATA_LEN)
54 return MAL_MAX_RX_SIZE;
55 else
56 return mal_rx_size(ETH_DATA_LEN + EMAC_MTU_OVERHEAD);
57}
58
59#define EMAC_DMA_ALIGN(x) ALIGN((x), dma_get_cache_alignment())
60
61#define EMAC_RX_SKB_HEADROOM \
62 EMAC_DMA_ALIGN(CONFIG_IBM_EMAC_RX_SKB_HEADROOM)
63
64/* Size of RX skb for the given MTU */
65static inline int emac_rx_skb_size(int mtu)
66{
67 int size = max(mtu + EMAC_MTU_OVERHEAD, emac_rx_size(mtu));
68 return EMAC_DMA_ALIGN(size + 2) + EMAC_RX_SKB_HEADROOM;
69}
70
71/* RX DMA sync size */
72static inline int emac_rx_sync_size(int mtu)
73{
74 return EMAC_DMA_ALIGN(emac_rx_size(mtu) + 2);
75}
76
77/* Driver statistcs is split into two parts to make it more cache friendly:
78 * - normal statistics (packet count, etc)
79 * - error statistics
80 *
81 * When statistics is requested by ethtool, these parts are concatenated,
82 * normal one goes first.
83 *
84 * Please, keep these structures in sync with emac_stats_keys.
61 */ 85 */
62#define MAX_NUM_BUF_DESC 255 86
63#define DESC_BUF_SIZE 4080 /* max 4096-16 */ 87/* Normal TX/RX Statistics */
64#define DESC_BUF_SIZE_REG (DESC_BUF_SIZE / 16) 88struct ibm_emac_stats {
65 89 u64 rx_packets;
66/* Transmitter timeout. */ 90 u64 rx_bytes;
67#define TX_TIMEOUT (2*HZ) 91 u64 tx_packets;
68 92 u64 tx_bytes;
69/* MDIO latency delay */ 93 u64 rx_packets_csum;
70#define MDIO_DELAY 250 94 u64 tx_packets_csum;
71 95};
72/* Power managment shift registers */ 96
73#define IBM_CPM_EMMII 0 /* Shift value for MII */ 97/* Error statistics */
74#define IBM_CPM_EMRX 1 /* Shift value for recv */ 98struct ibm_emac_error_stats {
75#define IBM_CPM_EMTX 2 /* Shift value for MAC */ 99 u64 tx_undo;
76#define IBM_CPM_EMAC(x) (((x)>>IBM_CPM_EMMII) | ((x)>>IBM_CPM_EMRX) | ((x)>>IBM_CPM_EMTX)) 100
77 101 /* Software RX Errors */
78#define ENET_HEADER_SIZE 14 102 u64 rx_dropped_stack;
79#define ENET_FCS_SIZE 4 103 u64 rx_dropped_oom;
80#define ENET_DEF_MTU_SIZE 1500 104 u64 rx_dropped_error;
81#define ENET_DEF_BUF_SIZE (ENET_DEF_MTU_SIZE + ENET_HEADER_SIZE + ENET_FCS_SIZE) 105 u64 rx_dropped_resize;
82#define EMAC_MIN_FRAME 64 106 u64 rx_dropped_mtu;
83#define EMAC_MAX_FRAME 9018 107 u64 rx_stopped;
84#define EMAC_MIN_MTU (EMAC_MIN_FRAME - ENET_HEADER_SIZE - ENET_FCS_SIZE) 108 /* BD reported RX errors */
85#define EMAC_MAX_MTU (EMAC_MAX_FRAME - ENET_HEADER_SIZE - ENET_FCS_SIZE) 109 u64 rx_bd_errors;
86 110 u64 rx_bd_overrun;
87#ifdef CONFIG_IBM_EMAC_ERRMSG 111 u64 rx_bd_bad_packet;
88void emac_serr_dump_0(struct net_device *dev); 112 u64 rx_bd_runt_packet;
89void emac_serr_dump_1(struct net_device *dev); 113 u64 rx_bd_short_event;
90void emac_err_dump(struct net_device *dev, int em0isr); 114 u64 rx_bd_alignment_error;
91void emac_phy_dump(struct net_device *); 115 u64 rx_bd_bad_fcs;
92void emac_desc_dump(struct net_device *); 116 u64 rx_bd_packet_too_long;
93void emac_mac_dump(struct net_device *); 117 u64 rx_bd_out_of_range;
94void emac_mal_dump(struct net_device *); 118 u64 rx_bd_in_range;
95#else 119 /* EMAC IRQ reported RX errors */
96#define emac_serr_dump_0(dev) do { } while (0) 120 u64 rx_parity;
97#define emac_serr_dump_1(dev) do { } while (0) 121 u64 rx_fifo_overrun;
98#define emac_err_dump(dev,x) do { } while (0) 122 u64 rx_overrun;
99#define emac_phy_dump(dev) do { } while (0) 123 u64 rx_bad_packet;
100#define emac_desc_dump(dev) do { } while (0) 124 u64 rx_runt_packet;
101#define emac_mac_dump(dev) do { } while (0) 125 u64 rx_short_event;
102#define emac_mal_dump(dev) do { } while (0) 126 u64 rx_alignment_error;
103#endif 127 u64 rx_bad_fcs;
128 u64 rx_packet_too_long;
129 u64 rx_out_of_range;
130 u64 rx_in_range;
131
132 /* Software TX Errors */
133 u64 tx_dropped;
134 /* BD reported TX errors */
135 u64 tx_bd_errors;
136 u64 tx_bd_bad_fcs;
137 u64 tx_bd_carrier_loss;
138 u64 tx_bd_excessive_deferral;
139 u64 tx_bd_excessive_collisions;
140 u64 tx_bd_late_collision;
141 u64 tx_bd_multple_collisions;
142 u64 tx_bd_single_collision;
143 u64 tx_bd_underrun;
144 u64 tx_bd_sqe;
145 /* EMAC IRQ reported TX errors */
146 u64 tx_parity;
147 u64 tx_underrun;
148 u64 tx_sqe;
149 u64 tx_errors;
150};
151
152#define EMAC_ETHTOOL_STATS_COUNT ((sizeof(struct ibm_emac_stats) + \
153 sizeof(struct ibm_emac_error_stats)) \
154 / sizeof(u64))
104 155
105struct ocp_enet_private { 156struct ocp_enet_private {
106 struct sk_buff *tx_skb[NUM_TX_BUFF]; 157 struct net_device *ndev; /* 0 */
107 struct sk_buff *rx_skb[NUM_RX_BUFF]; 158 struct emac_regs *emacp;
108 struct mal_descriptor *tx_desc; 159
109 struct mal_descriptor *rx_desc; 160 struct mal_descriptor *tx_desc;
110 struct mal_descriptor *rx_dirty; 161 int tx_cnt;
111 struct net_device_stats stats; 162 int tx_slot;
112 int tx_cnt; 163 int ack_slot;
113 int rx_slot; 164
114 int dirty_rx; 165 struct mal_descriptor *rx_desc;
115 int tx_slot; 166 int rx_slot;
116 int ack_slot; 167 struct sk_buff *rx_sg_skb; /* 1 */
117 int rx_buffer_size; 168 int rx_skb_size;
118 169 int rx_sync_size;
119 struct mii_phy phy_mii; 170
120 int mii_phy_addr; 171 struct ibm_emac_stats stats;
121 int want_autoneg; 172 struct ocp_device *tah_dev;
122 int timer_ticks; 173
123 struct timer_list link_timer; 174 struct ibm_ocp_mal *mal;
124 struct net_device *mdio_dev; 175 struct mal_commac commac;
125 176
126 struct ocp_device *rgmii_dev; 177 struct sk_buff *tx_skb[NUM_TX_BUFF];
127 int rgmii_input; 178 struct sk_buff *rx_skb[NUM_RX_BUFF];
128 179
129 struct ocp_device *zmii_dev; 180 struct ocp_device *zmii_dev;
130 int zmii_input; 181 int zmii_input;
131 182 struct ocp_enet_private *mdio_dev;
132 struct ibm_ocp_mal *mal; 183 struct ocp_device *rgmii_dev;
133 int mal_tx_chan, mal_rx_chan; 184 int rgmii_input;
134 struct mal_commac commac; 185
135 186 struct ocp_def *def;
136 struct ocp_device *tah_dev; 187
137 188 struct mii_phy phy;
138 int opened; 189 struct timer_list link_timer;
139 int going_away; 190 int reset_failed;
140 int wol_irq; 191
141 emac_t *emacp; 192 struct ibm_emac_error_stats estats;
142 struct ocp_device *ocpdev; 193 struct net_device_stats nstats;
143 struct net_device *ndev; 194
144 spinlock_t lock; 195 struct device* ldev;
145}; 196};
146#endif /* _IBM_EMAC_CORE_H_ */ 197
198/* Ethtool get_regs complex data.
199 * We want to get not just EMAC registers, but also MAL, ZMII, RGMII, TAH
200 * when available.
201 *
202 * Returned BLOB consists of the ibm_emac_ethtool_regs_hdr,
203 * MAL registers, EMAC registers and optional ZMII, RGMII, TAH registers.
204 * Each register component is preceded with emac_ethtool_regs_subhdr.
205 * Order of the optional headers follows their relative bit posititions
206 * in emac_ethtool_regs_hdr.components
207 */
208#define EMAC_ETHTOOL_REGS_ZMII 0x00000001
209#define EMAC_ETHTOOL_REGS_RGMII 0x00000002
210#define EMAC_ETHTOOL_REGS_TAH 0x00000004
211
212struct emac_ethtool_regs_hdr {
213 u32 components;
214};
215
216struct emac_ethtool_regs_subhdr {
217 u32 version;
218 u32 index;
219};
220
221#endif /* __IBM_EMAC_CORE_H_ */
diff --git a/drivers/net/ibm_emac/ibm_emac_debug.c b/drivers/net/ibm_emac/ibm_emac_debug.c
index c8512046cf84..75d3b8639041 100644
--- a/drivers/net/ibm_emac/ibm_emac_debug.c
+++ b/drivers/net/ibm_emac/ibm_emac_debug.c
@@ -1,224 +1,213 @@
1/* 1/*
2 * ibm_ocp_debug.c 2 * drivers/net/ibm_emac/ibm_emac_debug.c
3 * 3 *
4 * This has all the debug routines that where in *_enet.c 4 * Driver for PowerPC 4xx on-chip ethernet controller, debug print routines.
5 * 5 *
6 * Armin Kuster akuster@mvista.com 6 * Copyright (c) 2004, 2005 Zultys Technologies
7 * April , 2002 7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
8 *
9 * Copyright 2002 MontaVista Softare Inc.
10 * 8 *
11 * This program is free software; you can redistribute it and/or modify it 9 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the 10 * 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 11 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version. 12 * option) any later version.
13 *
15 */ 14 */
16
17#include <linux/config.h> 15#include <linux/config.h>
16#include <linux/init.h>
17#include <linux/module.h>
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/netdevice.h> 19#include <linux/netdevice.h>
20#include <linux/sysrq.h>
20#include <asm/io.h> 21#include <asm/io.h>
21#include "ibm_ocp_mal.h"
22#include "ibm_ocp_zmii.h"
23#include "ibm_ocp_enet.h"
24 22
25extern int emac_phy_read(struct net_device *dev, int mii_id, int reg); 23#include "ibm_emac_core.h"
24
25static void emac_desc_dump(int idx, struct ocp_enet_private *p)
26{
27 int i;
28 printk("** EMAC%d TX BDs **\n"
29 " tx_cnt = %d tx_slot = %d ack_slot = %d\n",
30 idx, p->tx_cnt, p->tx_slot, p->ack_slot);
31 for (i = 0; i < NUM_TX_BUFF / 2; ++i)
32 printk
33 ("bd[%2d] 0x%08x %c 0x%04x %4u - bd[%2d] 0x%08x %c 0x%04x %4u\n",
34 i, p->tx_desc[i].data_ptr, p->tx_skb[i] ? 'V' : ' ',
35 p->tx_desc[i].ctrl, p->tx_desc[i].data_len,
36 NUM_TX_BUFF / 2 + i,
37 p->tx_desc[NUM_TX_BUFF / 2 + i].data_ptr,
38 p->tx_skb[NUM_TX_BUFF / 2 + i] ? 'V' : ' ',
39 p->tx_desc[NUM_TX_BUFF / 2 + i].ctrl,
40 p->tx_desc[NUM_TX_BUFF / 2 + i].data_len);
41
42 printk("** EMAC%d RX BDs **\n"
43 " rx_slot = %d rx_stopped = %d rx_skb_size = %d rx_sync_size = %d\n"
44 " rx_sg_skb = 0x%p\n",
45 idx, p->rx_slot, p->commac.rx_stopped, p->rx_skb_size,
46 p->rx_sync_size, p->rx_sg_skb);
47 for (i = 0; i < NUM_RX_BUFF / 2; ++i)
48 printk
49 ("bd[%2d] 0x%08x %c 0x%04x %4u - bd[%2d] 0x%08x %c 0x%04x %4u\n",
50 i, p->rx_desc[i].data_ptr, p->rx_skb[i] ? 'V' : ' ',
51 p->rx_desc[i].ctrl, p->rx_desc[i].data_len,
52 NUM_RX_BUFF / 2 + i,
53 p->rx_desc[NUM_RX_BUFF / 2 + i].data_ptr,
54 p->rx_skb[NUM_RX_BUFF / 2 + i] ? 'V' : ' ',
55 p->rx_desc[NUM_RX_BUFF / 2 + i].ctrl,
56 p->rx_desc[NUM_RX_BUFF / 2 + i].data_len);
57}
58
59static void emac_mac_dump(int idx, struct ocp_enet_private *dev)
60{
61 struct emac_regs *p = dev->emacp;
62
63 printk("** EMAC%d registers **\n"
64 "MR0 = 0x%08x MR1 = 0x%08x TMR0 = 0x%08x TMR1 = 0x%08x\n"
65 "RMR = 0x%08x ISR = 0x%08x ISER = 0x%08x\n"
66 "IAR = %04x%08x VTPID = 0x%04x VTCI = 0x%04x\n"
67 "IAHT: 0x%04x 0x%04x 0x%04x 0x%04x "
68 "GAHT: 0x%04x 0x%04x 0x%04x 0x%04x\n"
69 "LSA = %04x%08x IPGVR = 0x%04x\n"
70 "STACR = 0x%08x TRTR = 0x%08x RWMR = 0x%08x\n"
71 "OCTX = 0x%08x OCRX = 0x%08x IPCR = 0x%08x\n",
72 idx, in_be32(&p->mr0), in_be32(&p->mr1),
73 in_be32(&p->tmr0), in_be32(&p->tmr1),
74 in_be32(&p->rmr), in_be32(&p->isr), in_be32(&p->iser),
75 in_be32(&p->iahr), in_be32(&p->ialr), in_be32(&p->vtpid),
76 in_be32(&p->vtci),
77 in_be32(&p->iaht1), in_be32(&p->iaht2), in_be32(&p->iaht3),
78 in_be32(&p->iaht4),
79 in_be32(&p->gaht1), in_be32(&p->gaht2), in_be32(&p->gaht3),
80 in_be32(&p->gaht4),
81 in_be32(&p->lsah), in_be32(&p->lsal), in_be32(&p->ipgvr),
82 in_be32(&p->stacr), in_be32(&p->trtr), in_be32(&p->rwmr),
83 in_be32(&p->octx), in_be32(&p->ocrx), in_be32(&p->ipcr)
84 );
85
86 emac_desc_dump(idx, dev);
87}
88
89static void emac_mal_dump(struct ibm_ocp_mal *mal)
90{
91 struct ocp_func_mal_data *maldata = mal->def->additions;
92 int i;
93
94 printk("** MAL%d Registers **\n"
95 "CFG = 0x%08x ESR = 0x%08x IER = 0x%08x\n"
96 "TX|CASR = 0x%08x CARR = 0x%08x EOBISR = 0x%08x DEIR = 0x%08x\n"
97 "RX|CASR = 0x%08x CARR = 0x%08x EOBISR = 0x%08x DEIR = 0x%08x\n",
98 mal->def->index,
99 get_mal_dcrn(mal, MAL_CFG), get_mal_dcrn(mal, MAL_ESR),
100 get_mal_dcrn(mal, MAL_IER),
101 get_mal_dcrn(mal, MAL_TXCASR), get_mal_dcrn(mal, MAL_TXCARR),
102 get_mal_dcrn(mal, MAL_TXEOBISR), get_mal_dcrn(mal, MAL_TXDEIR),
103 get_mal_dcrn(mal, MAL_RXCASR), get_mal_dcrn(mal, MAL_RXCARR),
104 get_mal_dcrn(mal, MAL_RXEOBISR), get_mal_dcrn(mal, MAL_RXDEIR)
105 );
106
107 printk("TX|");
108 for (i = 0; i < maldata->num_tx_chans; ++i) {
109 if (i && !(i % 4))
110 printk("\n ");
111 printk("CTP%d = 0x%08x ", i, get_mal_dcrn(mal, MAL_TXCTPR(i)));
112 }
113 printk("\nRX|");
114 for (i = 0; i < maldata->num_rx_chans; ++i) {
115 if (i && !(i % 4))
116 printk("\n ");
117 printk("CTP%d = 0x%08x ", i, get_mal_dcrn(mal, MAL_RXCTPR(i)));
118 }
119 printk("\n ");
120 for (i = 0; i < maldata->num_rx_chans; ++i) {
121 u32 r = get_mal_dcrn(mal, MAL_RCBS(i));
122 if (i && !(i % 3))
123 printk("\n ");
124 printk("RCBS%d = 0x%08x (%d) ", i, r, r * 16);
125 }
126 printk("\n");
127}
128
129static struct ocp_enet_private *__emacs[4];
130static struct ibm_ocp_mal *__mals[1];
26 131
27void emac_phy_dump(struct net_device *dev) 132void emac_dbg_register(int idx, struct ocp_enet_private *dev)
28{ 133{
29 struct ocp_enet_private *fep = dev->priv; 134 unsigned long flags;
30 unsigned long i; 135
31 uint data; 136 if (idx >= sizeof(__emacs) / sizeof(__emacs[0])) {
32 137 printk(KERN_WARNING
33 printk(KERN_DEBUG " Prepare for Phy dump....\n"); 138 "invalid index %d when registering EMAC for debugging\n",
34 for (i = 0; i < 0x1A; i++) { 139 idx);
35 data = emac_phy_read(dev, fep->mii_phy_addr, i); 140 return;
36 printk(KERN_DEBUG "Phy reg 0x%lx ==> %4x\n", i, data);
37 if (i == 0x07)
38 i = 0x0f;
39 } 141 }
142
143 local_irq_save(flags);
144 __emacs[idx] = dev;
145 local_irq_restore(flags);
40} 146}
41 147
42void emac_desc_dump(struct net_device *dev) 148void mal_dbg_register(int idx, struct ibm_ocp_mal *mal)
43{ 149{
44 struct ocp_enet_private *fep = dev->priv; 150 unsigned long flags;
45 int curr_slot; 151
46 152 if (idx >= sizeof(__mals) / sizeof(__mals[0])) {
47 printk(KERN_DEBUG 153 printk(KERN_WARNING
48 "dumping the receive descriptors: current slot is %d\n", 154 "invalid index %d when registering MAL for debugging\n",
49 fep->rx_slot); 155 idx);
50 for (curr_slot = 0; curr_slot < NUM_RX_BUFF; curr_slot++) { 156 return;
51 printk(KERN_DEBUG
52 "Desc %02d: status 0x%04x, length %3d, addr 0x%x\n",
53 curr_slot, fep->rx_desc[curr_slot].ctrl,
54 fep->rx_desc[curr_slot].data_len,
55 (unsigned int)fep->rx_desc[curr_slot].data_ptr);
56 } 157 }
158
159 local_irq_save(flags);
160 __mals[idx] = mal;
161 local_irq_restore(flags);
57} 162}
58 163
59void emac_mac_dump(struct net_device *dev) 164void emac_dbg_dump_all(void)
60{ 165{
61 struct ocp_enet_private *fep = dev->priv; 166 unsigned int i;
62 volatile emac_t *emacp = fep->emacp; 167 unsigned long flags;
63 168
64 printk(KERN_DEBUG "EMAC DEBUG ********** \n"); 169 local_irq_save(flags);
65 printk(KERN_DEBUG "EMAC_M0 ==> 0x%x\n", in_be32(&emacp->em0mr0)); 170
66 printk(KERN_DEBUG "EMAC_M1 ==> 0x%x\n", in_be32(&emacp->em0mr1)); 171 for (i = 0; i < sizeof(__mals) / sizeof(__mals[0]); ++i)
67 printk(KERN_DEBUG "EMAC_TXM0==> 0x%x\n", in_be32(&emacp->em0tmr0)); 172 if (__mals[i])
68 printk(KERN_DEBUG "EMAC_TXM1==> 0x%x\n", in_be32(&emacp->em0tmr1)); 173 emac_mal_dump(__mals[i]);
69 printk(KERN_DEBUG "EMAC_RXM ==> 0x%x\n", in_be32(&emacp->em0rmr)); 174
70 printk(KERN_DEBUG "EMAC_ISR ==> 0x%x\n", in_be32(&emacp->em0isr)); 175 for (i = 0; i < sizeof(__emacs) / sizeof(__emacs[0]); ++i)
71 printk(KERN_DEBUG "EMAC_IER ==> 0x%x\n", in_be32(&emacp->em0iser)); 176 if (__emacs[i])
72 printk(KERN_DEBUG "EMAC_IAH ==> 0x%x\n", in_be32(&emacp->em0iahr)); 177 emac_mac_dump(i, __emacs[i]);
73 printk(KERN_DEBUG "EMAC_IAL ==> 0x%x\n", in_be32(&emacp->em0ialr)); 178
74 printk(KERN_DEBUG "EMAC_VLAN_TPID_REG ==> 0x%x\n", 179 local_irq_restore(flags);
75 in_be32(&emacp->em0vtpid));
76} 180}
77 181
78void emac_mal_dump(struct net_device *dev) 182#if defined(CONFIG_MAGIC_SYSRQ)
183static void emac_sysrq_handler(int key, struct pt_regs *pt_regs,
184 struct tty_struct *tty)
79{ 185{
80 struct ibm_ocp_mal *mal = ((struct ocp_enet_private *)dev->priv)->mal; 186 emac_dbg_dump_all();
81
82 printk(KERN_DEBUG " MAL DEBUG ********** \n");
83 printk(KERN_DEBUG " MCR ==> 0x%x\n",
84 (unsigned int)get_mal_dcrn(mal, DCRN_MALCR));
85 printk(KERN_DEBUG " ESR ==> 0x%x\n",
86 (unsigned int)get_mal_dcrn(mal, DCRN_MALESR));
87 printk(KERN_DEBUG " IER ==> 0x%x\n",
88 (unsigned int)get_mal_dcrn(mal, DCRN_MALIER));
89#ifdef CONFIG_40x
90 printk(KERN_DEBUG " DBR ==> 0x%x\n",
91 (unsigned int)get_mal_dcrn(mal, DCRN_MALDBR));
92#endif /* CONFIG_40x */
93 printk(KERN_DEBUG " TXCASR ==> 0x%x\n",
94 (unsigned int)get_mal_dcrn(mal, DCRN_MALTXCASR));
95 printk(KERN_DEBUG " TXCARR ==> 0x%x\n",
96 (unsigned int)get_mal_dcrn(mal, DCRN_MALTXCARR));
97 printk(KERN_DEBUG " TXEOBISR ==> 0x%x\n",
98 (unsigned int)get_mal_dcrn(mal, DCRN_MALTXEOBISR));
99 printk(KERN_DEBUG " TXDEIR ==> 0x%x\n",
100 (unsigned int)get_mal_dcrn(mal, DCRN_MALTXDEIR));
101 printk(KERN_DEBUG " RXCASR ==> 0x%x\n",
102 (unsigned int)get_mal_dcrn(mal, DCRN_MALRXCASR));
103 printk(KERN_DEBUG " RXCARR ==> 0x%x\n",
104 (unsigned int)get_mal_dcrn(mal, DCRN_MALRXCARR));
105 printk(KERN_DEBUG " RXEOBISR ==> 0x%x\n",
106 (unsigned int)get_mal_dcrn(mal, DCRN_MALRXEOBISR));
107 printk(KERN_DEBUG " RXDEIR ==> 0x%x\n",
108 (unsigned int)get_mal_dcrn(mal, DCRN_MALRXDEIR));
109 printk(KERN_DEBUG " TXCTP0R ==> 0x%x\n",
110 (unsigned int)get_mal_dcrn(mal, DCRN_MALTXCTP0R));
111 printk(KERN_DEBUG " TXCTP1R ==> 0x%x\n",
112 (unsigned int)get_mal_dcrn(mal, DCRN_MALTXCTP1R));
113 printk(KERN_DEBUG " TXCTP2R ==> 0x%x\n",
114 (unsigned int)get_mal_dcrn(mal, DCRN_MALTXCTP2R));
115 printk(KERN_DEBUG " TXCTP3R ==> 0x%x\n",
116 (unsigned int)get_mal_dcrn(mal, DCRN_MALTXCTP3R));
117 printk(KERN_DEBUG " RXCTP0R ==> 0x%x\n",
118 (unsigned int)get_mal_dcrn(mal, DCRN_MALRXCTP0R));
119 printk(KERN_DEBUG " RXCTP1R ==> 0x%x\n",
120 (unsigned int)get_mal_dcrn(mal, DCRN_MALRXCTP1R));
121 printk(KERN_DEBUG " RCBS0 ==> 0x%x\n",
122 (unsigned int)get_mal_dcrn(mal, DCRN_MALRCBS0));
123 printk(KERN_DEBUG " RCBS1 ==> 0x%x\n",
124 (unsigned int)get_mal_dcrn(mal, DCRN_MALRCBS1));
125} 187}
126 188
127void emac_serr_dump_0(struct net_device *dev) 189static struct sysrq_key_op emac_sysrq_op = {
190 .handler = emac_sysrq_handler,
191 .help_msg = "emaC",
192 .action_msg = "Show EMAC(s) status",
193};
194
195int __init emac_init_debug(void)
128{ 196{
129 struct ibm_ocp_mal *mal = ((struct ocp_enet_private *)dev->priv)->mal; 197 return register_sysrq_key('c', &emac_sysrq_op);
130 unsigned long int mal_error, plb_error, plb_addr;
131
132 mal_error = get_mal_dcrn(mal, DCRN_MALESR);
133 printk(KERN_DEBUG "ppc405_eth_serr: %s channel %ld \n",
134 (mal_error & 0x40000000) ? "Receive" :
135 "Transmit", (mal_error & 0x3e000000) >> 25);
136 printk(KERN_DEBUG " ----- latched error -----\n");
137 if (mal_error & MALESR_DE)
138 printk(KERN_DEBUG " DE: descriptor error\n");
139 if (mal_error & MALESR_OEN)
140 printk(KERN_DEBUG " ONE: OPB non-fullword error\n");
141 if (mal_error & MALESR_OTE)
142 printk(KERN_DEBUG " OTE: OPB timeout error\n");
143 if (mal_error & MALESR_OSE)
144 printk(KERN_DEBUG " OSE: OPB slave error\n");
145
146 if (mal_error & MALESR_PEIN) {
147 plb_error = mfdcr(DCRN_PLB0_BESR);
148 printk(KERN_DEBUG
149 " PEIN: PLB error, PLB0_BESR is 0x%x\n",
150 (unsigned int)plb_error);
151 plb_addr = mfdcr(DCRN_PLB0_BEAR);
152 printk(KERN_DEBUG
153 " PEIN: PLB error, PLB0_BEAR is 0x%x\n",
154 (unsigned int)plb_addr);
155 }
156} 198}
157 199
158void emac_serr_dump_1(struct net_device *dev) 200void __exit emac_fini_debug(void)
159{ 201{
160 struct ibm_ocp_mal *mal = ((struct ocp_enet_private *)dev->priv)->mal; 202 unregister_sysrq_key('c', &emac_sysrq_op);
161 int mal_error = get_mal_dcrn(mal, DCRN_MALESR);
162
163 printk(KERN_DEBUG " ----- cumulative errors -----\n");
164 if (mal_error & MALESR_DEI)
165 printk(KERN_DEBUG " DEI: descriptor error interrupt\n");
166 if (mal_error & MALESR_ONEI)
167 printk(KERN_DEBUG " OPB non-fullword error interrupt\n");
168 if (mal_error & MALESR_OTEI)
169 printk(KERN_DEBUG " OTEI: timeout error interrupt\n");
170 if (mal_error & MALESR_OSEI)
171 printk(KERN_DEBUG " OSEI: slave error interrupt\n");
172 if (mal_error & MALESR_PBEI)
173 printk(KERN_DEBUG " PBEI: PLB bus error interrupt\n");
174} 203}
175 204
176void emac_err_dump(struct net_device *dev, int em0isr) 205#else
206int __init emac_init_debug(void)
207{
208 return 0;
209}
210void __exit emac_fini_debug(void)
177{ 211{
178 printk(KERN_DEBUG "%s: on-chip ethernet error:\n", dev->name);
179
180 if (em0isr & EMAC_ISR_OVR)
181 printk(KERN_DEBUG " OVR: overrun\n");
182 if (em0isr & EMAC_ISR_PP)
183 printk(KERN_DEBUG " PP: control pause packet\n");
184 if (em0isr & EMAC_ISR_BP)
185 printk(KERN_DEBUG " BP: packet error\n");
186 if (em0isr & EMAC_ISR_RP)
187 printk(KERN_DEBUG " RP: runt packet\n");
188 if (em0isr & EMAC_ISR_SE)
189 printk(KERN_DEBUG " SE: short event\n");
190 if (em0isr & EMAC_ISR_ALE)
191 printk(KERN_DEBUG " ALE: odd number of nibbles in packet\n");
192 if (em0isr & EMAC_ISR_BFCS)
193 printk(KERN_DEBUG " BFCS: bad FCS\n");
194 if (em0isr & EMAC_ISR_PTLE)
195 printk(KERN_DEBUG " PTLE: oversized packet\n");
196 if (em0isr & EMAC_ISR_ORE)
197 printk(KERN_DEBUG
198 " ORE: packet length field > max allowed LLC\n");
199 if (em0isr & EMAC_ISR_IRE)
200 printk(KERN_DEBUG " IRE: In Range error\n");
201 if (em0isr & EMAC_ISR_DBDM)
202 printk(KERN_DEBUG " DBDM: xmit error or SQE\n");
203 if (em0isr & EMAC_ISR_DB0)
204 printk(KERN_DEBUG " DB0: xmit error or SQE on TX channel 0\n");
205 if (em0isr & EMAC_ISR_SE0)
206 printk(KERN_DEBUG
207 " SE0: Signal Quality Error test failure from TX channel 0\n");
208 if (em0isr & EMAC_ISR_TE0)
209 printk(KERN_DEBUG " TE0: xmit channel 0 aborted\n");
210 if (em0isr & EMAC_ISR_DB1)
211 printk(KERN_DEBUG " DB1: xmit error or SQE on TX channel \n");
212 if (em0isr & EMAC_ISR_SE1)
213 printk(KERN_DEBUG
214 " SE1: Signal Quality Error test failure from TX channel 1\n");
215 if (em0isr & EMAC_ISR_TE1)
216 printk(KERN_DEBUG " TE1: xmit channel 1 aborted\n");
217 if (em0isr & EMAC_ISR_MOS)
218 printk(KERN_DEBUG " MOS\n");
219 if (em0isr & EMAC_ISR_MOF)
220 printk(KERN_DEBUG " MOF\n");
221
222 emac_mac_dump(dev);
223 emac_mal_dump(dev);
224} 212}
213#endif /* CONFIG_MAGIC_SYSRQ */
diff --git a/drivers/net/ibm_emac/ibm_emac_debug.h b/drivers/net/ibm_emac/ibm_emac_debug.h
new file mode 100644
index 000000000000..e85fbe0a8da9
--- /dev/null
+++ b/drivers/net/ibm_emac/ibm_emac_debug.h
@@ -0,0 +1,63 @@
1/*
2 * drivers/net/ibm_emac/ibm_ocp_debug.h
3 *
4 * Driver for PowerPC 4xx on-chip ethernet controller, debug print routines.
5 *
6 * Copyright (c) 2004, 2005 Zultys Technologies
7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 *
14 */
15#ifndef __IBM_EMAC_DEBUG_H_
16#define __IBM_EMAC_DEBUG_H_
17
18#include <linux/config.h>
19#include <linux/init.h>
20#include "ibm_emac_core.h"
21#include "ibm_emac_mal.h"
22
23#if defined(CONFIG_IBM_EMAC_DEBUG)
24void emac_dbg_register(int idx, struct ocp_enet_private *dev);
25void mal_dbg_register(int idx, struct ibm_ocp_mal *mal);
26int emac_init_debug(void) __init;
27void emac_fini_debug(void) __exit;
28void emac_dbg_dump_all(void);
29# define DBG_LEVEL 1
30#else
31# define emac_dbg_register(x,y) ((void)0)
32# define mal_dbg_register(x,y) ((void)0)
33# define emac_init_debug() ((void)0)
34# define emac_fini_debug() ((void)0)
35# define emac_dbg_dump_all() ((void)0)
36# define DBG_LEVEL 0
37#endif
38
39#if DBG_LEVEL > 0
40# define DBG(f,x...) printk("emac" f, ##x)
41# define MAL_DBG(f,x...) printk("mal" f, ##x)
42# define ZMII_DBG(f,x...) printk("zmii" f, ##x)
43# define RGMII_DBG(f,x...) printk("rgmii" f, ##x)
44# define NL "\n"
45#else
46# define DBG(f,x...) ((void)0)
47# define MAL_DBG(f,x...) ((void)0)
48# define ZMII_DBG(f,x...) ((void)0)
49# define RGMII_DBG(f,x...) ((void)0)
50#endif
51#if DBG_LEVEL > 1
52# define DBG2(f,x...) DBG(f, ##x)
53# define MAL_DBG2(f,x...) MAL_DBG(f, ##x)
54# define ZMII_DBG2(f,x...) ZMII_DBG(f, ##x)
55# define RGMII_DBG2(f,x...) RGMII_DBG(f, ##x)
56#else
57# define DBG2(f,x...) ((void)0)
58# define MAL_DBG2(f,x...) ((void)0)
59# define ZMII_DBG2(f,x...) ((void)0)
60# define RGMII_DBG2(f,x...) ((void)0)
61#endif
62
63#endif /* __IBM_EMAC_DEBUG_H_ */
diff --git a/drivers/net/ibm_emac/ibm_emac_mal.c b/drivers/net/ibm_emac/ibm_emac_mal.c
index e59f57f363ca..da88d43081cc 100644
--- a/drivers/net/ibm_emac/ibm_emac_mal.c
+++ b/drivers/net/ibm_emac/ibm_emac_mal.c
@@ -1,436 +1,565 @@
1/* 1/*
2 * ibm_ocp_mal.c 2 * drivers/net/ibm_emac/ibm_emac_mal.c
3 * 3 *
4 * Armin Kuster akuster@mvista.com 4 * Memory Access Layer (MAL) support
5 * Juen, 2002 5 *
6 * Copyright (c) 2004, 2005 Zultys Technologies.
7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
6 * 8 *
7 * Copyright 2002 MontaVista Softare Inc. 9 * Based on original work by
10 * Benjamin Herrenschmidt <benh@kernel.crashing.org>,
11 * David Gibson <hermes@gibson.dropbear.id.au>,
12 *
13 * Armin Kuster <akuster@mvista.com>
14 * Copyright 2002 MontaVista Softare Inc.
8 * 15 *
9 * This program is free software; you can redistribute it and/or modify it 16 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the 17 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your 18 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version. 19 * option) any later version.
20 *
13 */ 21 */
14
15#include <linux/config.h> 22#include <linux/config.h>
16#include <linux/module.h> 23#include <linux/module.h>
17#include <linux/kernel.h> 24#include <linux/kernel.h>
18#include <linux/errno.h> 25#include <linux/errno.h>
19#include <linux/netdevice.h> 26#include <linux/netdevice.h>
20#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/interrupt.h>
21#include <linux/dma-mapping.h> 29#include <linux/dma-mapping.h>
22 30
23#include <asm/io.h>
24#include <asm/irq.h>
25#include <asm/ocp.h> 31#include <asm/ocp.h>
26 32
33#include "ibm_emac_core.h"
27#include "ibm_emac_mal.h" 34#include "ibm_emac_mal.h"
35#include "ibm_emac_debug.h"
28 36
29// Locking: Should we share a lock with the client ? The client could provide 37int __init mal_register_commac(struct ibm_ocp_mal *mal,
30// a lock pointer (optionally) in the commac structure... I don't think this is 38 struct mal_commac *commac)
31// really necessary though
32
33/* This lock protects the commac list. On today UP implementations, it's
34 * really only used as IRQ protection in mal_{register,unregister}_commac()
35 */
36static DEFINE_RWLOCK(mal_list_lock);
37
38int mal_register_commac(struct ibm_ocp_mal *mal, struct mal_commac *commac)
39{ 39{
40 unsigned long flags; 40 unsigned long flags;
41 local_irq_save(flags);
41 42
42 write_lock_irqsave(&mal_list_lock, flags); 43 MAL_DBG("%d: reg(%08x, %08x)" NL, mal->def->index,
44 commac->tx_chan_mask, commac->rx_chan_mask);
43 45
44 /* Don't let multiple commacs claim the same channel */ 46 /* Don't let multiple commacs claim the same channel(s) */
45 if ((mal->tx_chan_mask & commac->tx_chan_mask) || 47 if ((mal->tx_chan_mask & commac->tx_chan_mask) ||
46 (mal->rx_chan_mask & commac->rx_chan_mask)) { 48 (mal->rx_chan_mask & commac->rx_chan_mask)) {
47 write_unlock_irqrestore(&mal_list_lock, flags); 49 local_irq_restore(flags);
50 printk(KERN_WARNING "mal%d: COMMAC channels conflict!\n",
51 mal->def->index);
48 return -EBUSY; 52 return -EBUSY;
49 } 53 }
50 54
51 mal->tx_chan_mask |= commac->tx_chan_mask; 55 mal->tx_chan_mask |= commac->tx_chan_mask;
52 mal->rx_chan_mask |= commac->rx_chan_mask; 56 mal->rx_chan_mask |= commac->rx_chan_mask;
57 list_add(&commac->list, &mal->list);
53 58
54 list_add(&commac->list, &mal->commac); 59 local_irq_restore(flags);
55
56 write_unlock_irqrestore(&mal_list_lock, flags);
57
58 return 0; 60 return 0;
59} 61}
60 62
61int mal_unregister_commac(struct ibm_ocp_mal *mal, struct mal_commac *commac) 63void __exit mal_unregister_commac(struct ibm_ocp_mal *mal,
64 struct mal_commac *commac)
62{ 65{
63 unsigned long flags; 66 unsigned long flags;
67 local_irq_save(flags);
64 68
65 write_lock_irqsave(&mal_list_lock, flags); 69 MAL_DBG("%d: unreg(%08x, %08x)" NL, mal->def->index,
70 commac->tx_chan_mask, commac->rx_chan_mask);
66 71
67 mal->tx_chan_mask &= ~commac->tx_chan_mask; 72 mal->tx_chan_mask &= ~commac->tx_chan_mask;
68 mal->rx_chan_mask &= ~commac->rx_chan_mask; 73 mal->rx_chan_mask &= ~commac->rx_chan_mask;
69
70 list_del_init(&commac->list); 74 list_del_init(&commac->list);
71 75
72 write_unlock_irqrestore(&mal_list_lock, flags); 76 local_irq_restore(flags);
73
74 return 0;
75} 77}
76 78
77int mal_set_rcbs(struct ibm_ocp_mal *mal, int channel, unsigned long size) 79int mal_set_rcbs(struct ibm_ocp_mal *mal, int channel, unsigned long size)
78{ 80{
79 switch (channel) { 81 struct ocp_func_mal_data *maldata = mal->def->additions;
80 case 0: 82 BUG_ON(channel < 0 || channel >= maldata->num_rx_chans ||
81 set_mal_dcrn(mal, DCRN_MALRCBS0, size); 83 size > MAL_MAX_RX_SIZE);
82 break; 84
83#ifdef DCRN_MALRCBS1 85 MAL_DBG("%d: set_rbcs(%d, %lu)" NL, mal->def->index, channel, size);
84 case 1: 86
85 set_mal_dcrn(mal, DCRN_MALRCBS1, size); 87 if (size & 0xf) {
86 break; 88 printk(KERN_WARNING
87#endif 89 "mal%d: incorrect RX size %lu for the channel %d\n",
88#ifdef DCRN_MALRCBS2 90 mal->def->index, size, channel);
89 case 2:
90 set_mal_dcrn(mal, DCRN_MALRCBS2, size);
91 break;
92#endif
93#ifdef DCRN_MALRCBS3
94 case 3:
95 set_mal_dcrn(mal, DCRN_MALRCBS3, size);
96 break;
97#endif
98 default:
99 return -EINVAL; 91 return -EINVAL;
100 } 92 }
101 93
94 set_mal_dcrn(mal, MAL_RCBS(channel), size >> 4);
102 return 0; 95 return 0;
103} 96}
104 97
105static irqreturn_t mal_serr(int irq, void *dev_instance, struct pt_regs *regs) 98int mal_tx_bd_offset(struct ibm_ocp_mal *mal, int channel)
106{ 99{
107 struct ibm_ocp_mal *mal = dev_instance; 100 struct ocp_func_mal_data *maldata = mal->def->additions;
108 unsigned long mal_error; 101 BUG_ON(channel < 0 || channel >= maldata->num_tx_chans);
102 return channel * NUM_TX_BUFF;
103}
109 104
110 /* 105int mal_rx_bd_offset(struct ibm_ocp_mal *mal, int channel)
111 * This SERR applies to one of the devices on the MAL, here we charge 106{
112 * it against the first EMAC registered for the MAL. 107 struct ocp_func_mal_data *maldata = mal->def->additions;
113 */ 108 BUG_ON(channel < 0 || channel >= maldata->num_rx_chans);
109 return maldata->num_tx_chans * NUM_TX_BUFF + channel * NUM_RX_BUFF;
110}
114 111
115 mal_error = get_mal_dcrn(mal, DCRN_MALESR); 112void mal_enable_tx_channel(struct ibm_ocp_mal *mal, int channel)
113{
114 local_bh_disable();
115 MAL_DBG("%d: enable_tx(%d)" NL, mal->def->index, channel);
116 set_mal_dcrn(mal, MAL_TXCASR,
117 get_mal_dcrn(mal, MAL_TXCASR) | MAL_CHAN_MASK(channel));
118 local_bh_enable();
119}
116 120
117 printk(KERN_ERR "%s: System Error (MALESR=%lx)\n", 121void mal_disable_tx_channel(struct ibm_ocp_mal *mal, int channel)
118 "MAL" /* FIXME: get the name right */ , mal_error); 122{
123 set_mal_dcrn(mal, MAL_TXCARR, MAL_CHAN_MASK(channel));
124 MAL_DBG("%d: disable_tx(%d)" NL, mal->def->index, channel);
125}
119 126
120 /* FIXME: decipher error */ 127void mal_enable_rx_channel(struct ibm_ocp_mal *mal, int channel)
121 /* DIXME: distribute to commacs, if possible */ 128{
129 local_bh_disable();
130 MAL_DBG("%d: enable_rx(%d)" NL, mal->def->index, channel);
131 set_mal_dcrn(mal, MAL_RXCASR,
132 get_mal_dcrn(mal, MAL_RXCASR) | MAL_CHAN_MASK(channel));
133 local_bh_enable();
134}
122 135
123 /* Clear the error status register */ 136void mal_disable_rx_channel(struct ibm_ocp_mal *mal, int channel)
124 set_mal_dcrn(mal, DCRN_MALESR, mal_error); 137{
138 set_mal_dcrn(mal, MAL_RXCARR, MAL_CHAN_MASK(channel));
139 MAL_DBG("%d: disable_rx(%d)" NL, mal->def->index, channel);
140}
125 141
126 return IRQ_HANDLED; 142void mal_poll_add(struct ibm_ocp_mal *mal, struct mal_commac *commac)
143{
144 local_bh_disable();
145 MAL_DBG("%d: poll_add(%p)" NL, mal->def->index, commac);
146 list_add_tail(&commac->poll_list, &mal->poll_list);
147 local_bh_enable();
127} 148}
128 149
129static irqreturn_t mal_txeob(int irq, void *dev_instance, struct pt_regs *regs) 150void mal_poll_del(struct ibm_ocp_mal *mal, struct mal_commac *commac)
151{
152 local_bh_disable();
153 MAL_DBG("%d: poll_del(%p)" NL, mal->def->index, commac);
154 list_del(&commac->poll_list);
155 local_bh_enable();
156}
157
158/* synchronized by mal_poll() */
159static inline void mal_enable_eob_irq(struct ibm_ocp_mal *mal)
160{
161 MAL_DBG2("%d: enable_irq" NL, mal->def->index);
162 set_mal_dcrn(mal, MAL_CFG, get_mal_dcrn(mal, MAL_CFG) | MAL_CFG_EOPIE);
163}
164
165/* synchronized by __LINK_STATE_RX_SCHED bit in ndev->state */
166static inline void mal_disable_eob_irq(struct ibm_ocp_mal *mal)
167{
168 set_mal_dcrn(mal, MAL_CFG, get_mal_dcrn(mal, MAL_CFG) & ~MAL_CFG_EOPIE);
169 MAL_DBG2("%d: disable_irq" NL, mal->def->index);
170}
171
172static irqreturn_t mal_serr(int irq, void *dev_instance, struct pt_regs *regs)
130{ 173{
131 struct ibm_ocp_mal *mal = dev_instance; 174 struct ibm_ocp_mal *mal = dev_instance;
132 struct list_head *l; 175 u32 esr = get_mal_dcrn(mal, MAL_ESR);
133 unsigned long isr;
134 176
135 isr = get_mal_dcrn(mal, DCRN_MALTXEOBISR); 177 /* Clear the error status register */
136 set_mal_dcrn(mal, DCRN_MALTXEOBISR, isr); 178 set_mal_dcrn(mal, MAL_ESR, esr);
137 179
138 read_lock(&mal_list_lock); 180 MAL_DBG("%d: SERR %08x" NL, mal->def->index, esr);
139 list_for_each(l, &mal->commac) {
140 struct mal_commac *mc = list_entry(l, struct mal_commac, list);
141 181
142 if (isr & mc->tx_chan_mask) { 182 if (esr & MAL_ESR_EVB) {
143 mc->ops->txeob(mc->dev, isr & mc->tx_chan_mask); 183 if (esr & MAL_ESR_DE) {
184 /* We ignore Descriptor error,
185 * TXDE or RXDE interrupt will be generated anyway.
186 */
187 return IRQ_HANDLED;
144 } 188 }
189
190 if (esr & MAL_ESR_PEIN) {
191 /* PLB error, it's probably buggy hardware or
192 * incorrect physical address in BD (i.e. bug)
193 */
194 if (net_ratelimit())
195 printk(KERN_ERR
196 "mal%d: system error, PLB (ESR = 0x%08x)\n",
197 mal->def->index, esr);
198 return IRQ_HANDLED;
199 }
200
201 /* OPB error, it's probably buggy hardware or incorrect EBC setup */
202 if (net_ratelimit())
203 printk(KERN_ERR
204 "mal%d: system error, OPB (ESR = 0x%08x)\n",
205 mal->def->index, esr);
145 } 206 }
146 read_unlock(&mal_list_lock); 207 return IRQ_HANDLED;
208}
209
210static inline void mal_schedule_poll(struct ibm_ocp_mal *mal)
211{
212 if (likely(netif_rx_schedule_prep(&mal->poll_dev))) {
213 MAL_DBG2("%d: schedule_poll" NL, mal->def->index);
214 mal_disable_eob_irq(mal);
215 __netif_rx_schedule(&mal->poll_dev);
216 } else
217 MAL_DBG2("%d: already in poll" NL, mal->def->index);
218}
147 219
220static irqreturn_t mal_txeob(int irq, void *dev_instance, struct pt_regs *regs)
221{
222 struct ibm_ocp_mal *mal = dev_instance;
223 u32 r = get_mal_dcrn(mal, MAL_TXEOBISR);
224 MAL_DBG2("%d: txeob %08x" NL, mal->def->index, r);
225 mal_schedule_poll(mal);
226 set_mal_dcrn(mal, MAL_TXEOBISR, r);
148 return IRQ_HANDLED; 227 return IRQ_HANDLED;
149} 228}
150 229
151static irqreturn_t mal_rxeob(int irq, void *dev_instance, struct pt_regs *regs) 230static irqreturn_t mal_rxeob(int irq, void *dev_instance, struct pt_regs *regs)
152{ 231{
153 struct ibm_ocp_mal *mal = dev_instance; 232 struct ibm_ocp_mal *mal = dev_instance;
154 struct list_head *l; 233 u32 r = get_mal_dcrn(mal, MAL_RXEOBISR);
155 unsigned long isr; 234 MAL_DBG2("%d: rxeob %08x" NL, mal->def->index, r);
235 mal_schedule_poll(mal);
236 set_mal_dcrn(mal, MAL_RXEOBISR, r);
237 return IRQ_HANDLED;
238}
156 239
157 isr = get_mal_dcrn(mal, DCRN_MALRXEOBISR); 240static irqreturn_t mal_txde(int irq, void *dev_instance, struct pt_regs *regs)
158 set_mal_dcrn(mal, DCRN_MALRXEOBISR, isr); 241{
242 struct ibm_ocp_mal *mal = dev_instance;
243 u32 deir = get_mal_dcrn(mal, MAL_TXDEIR);
244 set_mal_dcrn(mal, MAL_TXDEIR, deir);
159 245
160 read_lock(&mal_list_lock); 246 MAL_DBG("%d: txde %08x" NL, mal->def->index, deir);
161 list_for_each(l, &mal->commac) {
162 struct mal_commac *mc = list_entry(l, struct mal_commac, list);
163 247
164 if (isr & mc->rx_chan_mask) { 248 if (net_ratelimit())
165 mc->ops->rxeob(mc->dev, isr & mc->rx_chan_mask); 249 printk(KERN_ERR
166 } 250 "mal%d: TX descriptor error (TXDEIR = 0x%08x)\n",
167 } 251 mal->def->index, deir);
168 read_unlock(&mal_list_lock);
169 252
170 return IRQ_HANDLED; 253 return IRQ_HANDLED;
171} 254}
172 255
173static irqreturn_t mal_txde(int irq, void *dev_instance, struct pt_regs *regs) 256static irqreturn_t mal_rxde(int irq, void *dev_instance, struct pt_regs *regs)
174{ 257{
175 struct ibm_ocp_mal *mal = dev_instance; 258 struct ibm_ocp_mal *mal = dev_instance;
176 struct list_head *l; 259 struct list_head *l;
177 unsigned long deir; 260 u32 deir = get_mal_dcrn(mal, MAL_RXDEIR);
178 261
179 deir = get_mal_dcrn(mal, DCRN_MALTXDEIR); 262 MAL_DBG("%d: rxde %08x" NL, mal->def->index, deir);
180 263
181 /* FIXME: print which MAL correctly */ 264 list_for_each(l, &mal->list) {
182 printk(KERN_WARNING "%s: Tx descriptor error (MALTXDEIR=%lx)\n",
183 "MAL", deir);
184
185 read_lock(&mal_list_lock);
186 list_for_each(l, &mal->commac) {
187 struct mal_commac *mc = list_entry(l, struct mal_commac, list); 265 struct mal_commac *mc = list_entry(l, struct mal_commac, list);
188 266 if (deir & mc->rx_chan_mask) {
189 if (deir & mc->tx_chan_mask) { 267 mc->rx_stopped = 1;
190 mc->ops->txde(mc->dev, deir & mc->tx_chan_mask); 268 mc->ops->rxde(mc->dev);
191 } 269 }
192 } 270 }
193 read_unlock(&mal_list_lock); 271
272 mal_schedule_poll(mal);
273 set_mal_dcrn(mal, MAL_RXDEIR, deir);
194 274
195 return IRQ_HANDLED; 275 return IRQ_HANDLED;
196} 276}
197 277
198/* 278static int mal_poll(struct net_device *ndev, int *budget)
199 * This interrupt should be very rare at best. This occurs when
200 * the hardware has a problem with the receive descriptors. The manual
201 * states that it occurs when the hardware cannot the receive descriptor
202 * empty bit is not set. The recovery mechanism will be to
203 * traverse through the descriptors, handle any that are marked to be
204 * handled and reinitialize each along the way. At that point the driver
205 * will be restarted.
206 */
207static irqreturn_t mal_rxde(int irq, void *dev_instance, struct pt_regs *regs)
208{ 279{
209 struct ibm_ocp_mal *mal = dev_instance; 280 struct ibm_ocp_mal *mal = ndev->priv;
210 struct list_head *l; 281 struct list_head *l;
211 unsigned long deir; 282 int rx_work_limit = min(ndev->quota, *budget), received = 0, done;
212 283
213 deir = get_mal_dcrn(mal, DCRN_MALRXDEIR); 284 MAL_DBG2("%d: poll(%d) %d ->" NL, mal->def->index, *budget,
285 rx_work_limit);
286 again:
287 /* Process TX skbs */
288 list_for_each(l, &mal->poll_list) {
289 struct mal_commac *mc =
290 list_entry(l, struct mal_commac, poll_list);
291 mc->ops->poll_tx(mc->dev);
292 }
214 293
215 /* 294 /* Process RX skbs.
216 * This really is needed. This case encountered in stress testing. 295 * We _might_ need something more smart here to enforce polling fairness.
217 */ 296 */
218 if (deir == 0) 297 list_for_each(l, &mal->poll_list) {
219 return IRQ_HANDLED; 298 struct mal_commac *mc =
220 299 list_entry(l, struct mal_commac, poll_list);
221 /* FIXME: print which MAL correctly */ 300 int n = mc->ops->poll_rx(mc->dev, rx_work_limit);
222 printk(KERN_WARNING "%s: Rx descriptor error (MALRXDEIR=%lx)\n", 301 if (n) {
223 "MAL", deir); 302 received += n;
224 303 rx_work_limit -= n;
225 read_lock(&mal_list_lock); 304 if (rx_work_limit <= 0) {
226 list_for_each(l, &mal->commac) { 305 done = 0;
227 struct mal_commac *mc = list_entry(l, struct mal_commac, list); 306 goto more_work; // XXX What if this is the last one ?
307 }
308 }
309 }
228 310
229 if (deir & mc->rx_chan_mask) { 311 /* We need to disable IRQs to protect from RXDE IRQ here */
230 mc->ops->rxde(mc->dev, deir & mc->rx_chan_mask); 312 local_irq_disable();
313 __netif_rx_complete(ndev);
314 mal_enable_eob_irq(mal);
315 local_irq_enable();
316
317 done = 1;
318
319 /* Check for "rotting" packet(s) */
320 list_for_each(l, &mal->poll_list) {
321 struct mal_commac *mc =
322 list_entry(l, struct mal_commac, poll_list);
323 if (unlikely(mc->ops->peek_rx(mc->dev) || mc->rx_stopped)) {
324 MAL_DBG2("%d: rotting packet" NL, mal->def->index);
325 if (netif_rx_reschedule(ndev, received))
326 mal_disable_eob_irq(mal);
327 else
328 MAL_DBG2("%d: already in poll list" NL,
329 mal->def->index);
330
331 if (rx_work_limit > 0)
332 goto again;
333 else
334 goto more_work;
231 } 335 }
336 mc->ops->poll_tx(mc->dev);
232 } 337 }
233 read_unlock(&mal_list_lock);
234 338
235 return IRQ_HANDLED; 339 more_work:
340 ndev->quota -= received;
341 *budget -= received;
342
343 MAL_DBG2("%d: poll() %d <- %d" NL, mal->def->index, *budget,
344 done ? 0 : 1);
345 return done ? 0 : 1;
346}
347
348static void mal_reset(struct ibm_ocp_mal *mal)
349{
350 int n = 10;
351 MAL_DBG("%d: reset" NL, mal->def->index);
352
353 set_mal_dcrn(mal, MAL_CFG, MAL_CFG_SR);
354
355 /* Wait for reset to complete (1 system clock) */
356 while ((get_mal_dcrn(mal, MAL_CFG) & MAL_CFG_SR) && n)
357 --n;
358
359 if (unlikely(!n))
360 printk(KERN_ERR "mal%d: reset timeout\n", mal->def->index);
361}
362
363int mal_get_regs_len(struct ibm_ocp_mal *mal)
364{
365 return sizeof(struct emac_ethtool_regs_subhdr) +
366 sizeof(struct ibm_mal_regs);
367}
368
369void *mal_dump_regs(struct ibm_ocp_mal *mal, void *buf)
370{
371 struct emac_ethtool_regs_subhdr *hdr = buf;
372 struct ibm_mal_regs *regs = (struct ibm_mal_regs *)(hdr + 1);
373 struct ocp_func_mal_data *maldata = mal->def->additions;
374 int i;
375
376 hdr->version = MAL_VERSION;
377 hdr->index = mal->def->index;
378
379 regs->tx_count = maldata->num_tx_chans;
380 regs->rx_count = maldata->num_rx_chans;
381
382 regs->cfg = get_mal_dcrn(mal, MAL_CFG);
383 regs->esr = get_mal_dcrn(mal, MAL_ESR);
384 regs->ier = get_mal_dcrn(mal, MAL_IER);
385 regs->tx_casr = get_mal_dcrn(mal, MAL_TXCASR);
386 regs->tx_carr = get_mal_dcrn(mal, MAL_TXCARR);
387 regs->tx_eobisr = get_mal_dcrn(mal, MAL_TXEOBISR);
388 regs->tx_deir = get_mal_dcrn(mal, MAL_TXDEIR);
389 regs->rx_casr = get_mal_dcrn(mal, MAL_RXCASR);
390 regs->rx_carr = get_mal_dcrn(mal, MAL_RXCARR);
391 regs->rx_eobisr = get_mal_dcrn(mal, MAL_RXEOBISR);
392 regs->rx_deir = get_mal_dcrn(mal, MAL_RXDEIR);
393
394 for (i = 0; i < regs->tx_count; ++i)
395 regs->tx_ctpr[i] = get_mal_dcrn(mal, MAL_TXCTPR(i));
396
397 for (i = 0; i < regs->rx_count; ++i) {
398 regs->rx_ctpr[i] = get_mal_dcrn(mal, MAL_RXCTPR(i));
399 regs->rcbs[i] = get_mal_dcrn(mal, MAL_RCBS(i));
400 }
401 return regs + 1;
236} 402}
237 403
238static int __init mal_probe(struct ocp_device *ocpdev) 404static int __init mal_probe(struct ocp_device *ocpdev)
239{ 405{
240 struct ibm_ocp_mal *mal = NULL; 406 struct ibm_ocp_mal *mal;
241 struct ocp_func_mal_data *maldata; 407 struct ocp_func_mal_data *maldata;
242 int err = 0; 408 int err = 0, i, bd_size;
409
410 MAL_DBG("%d: probe" NL, ocpdev->def->index);
243 411
244 maldata = (struct ocp_func_mal_data *)ocpdev->def->additions; 412 maldata = ocpdev->def->additions;
245 if (maldata == NULL) { 413 if (maldata == NULL) {
246 printk(KERN_ERR "mal%d: Missing additional datas !\n", 414 printk(KERN_ERR "mal%d: missing additional data!\n",
247 ocpdev->def->index); 415 ocpdev->def->index);
248 return -ENODEV; 416 return -ENODEV;
249 } 417 }
250 418
251 mal = kmalloc(sizeof(struct ibm_ocp_mal), GFP_KERNEL); 419 mal = kzalloc(sizeof(struct ibm_ocp_mal), GFP_KERNEL);
252 if (mal == NULL) { 420 if (!mal) {
253 printk(KERN_ERR 421 printk(KERN_ERR
254 "mal%d: Out of memory allocating MAL structure !\n", 422 "mal%d: out of memory allocating MAL structure!\n",
255 ocpdev->def->index); 423 ocpdev->def->index);
256 return -ENOMEM; 424 return -ENOMEM;
257 } 425 }
258 memset(mal, 0, sizeof(*mal)); 426 mal->dcrbase = maldata->dcr_base;
259 427 mal->def = ocpdev->def;
260 switch (ocpdev->def->index) {
261 case 0:
262 mal->dcrbase = DCRN_MAL_BASE;
263 break;
264#ifdef DCRN_MAL1_BASE
265 case 1:
266 mal->dcrbase = DCRN_MAL1_BASE;
267 break;
268#endif
269 default:
270 BUG();
271 }
272
273 /**************************/
274 428
275 INIT_LIST_HEAD(&mal->commac); 429 INIT_LIST_HEAD(&mal->poll_list);
430 set_bit(__LINK_STATE_START, &mal->poll_dev.state);
431 mal->poll_dev.weight = CONFIG_IBM_EMAC_POLL_WEIGHT;
432 mal->poll_dev.poll = mal_poll;
433 mal->poll_dev.priv = mal;
434 atomic_set(&mal->poll_dev.refcnt, 1);
276 435
277 set_mal_dcrn(mal, DCRN_MALRXCARR, 0xFFFFFFFF); 436 INIT_LIST_HEAD(&mal->list);
278 set_mal_dcrn(mal, DCRN_MALTXCARR, 0xFFFFFFFF);
279 437
280 set_mal_dcrn(mal, DCRN_MALCR, MALCR_MMSR); /* 384 */ 438 /* Load power-on reset defaults */
281 /* FIXME: Add delay */ 439 mal_reset(mal);
282 440
283 /* Set the MAL configuration register */ 441 /* Set the MAL configuration register */
284 set_mal_dcrn(mal, DCRN_MALCR, 442 set_mal_dcrn(mal, MAL_CFG, MAL_CFG_DEFAULT | MAL_CFG_PLBB |
285 MALCR_PLBB | MALCR_OPBBL | MALCR_LEA | 443 MAL_CFG_OPBBL | MAL_CFG_LEA);
286 MALCR_PLBLT_DEFAULT); 444
287 445 mal_enable_eob_irq(mal);
288 /* It would be nice to allocate buffers separately for each 446
289 * channel, but we can't because the channels share the upper 447 /* Allocate space for BD rings */
290 * 13 bits of address lines. Each channels buffer must also 448 BUG_ON(maldata->num_tx_chans <= 0 || maldata->num_tx_chans > 32);
291 * be 4k aligned, so we allocate 4k for each channel. This is 449 BUG_ON(maldata->num_rx_chans <= 0 || maldata->num_rx_chans > 32);
292 * inefficient FIXME: do better, if possible */ 450 bd_size = sizeof(struct mal_descriptor) *
293 mal->tx_virt_addr = dma_alloc_coherent(&ocpdev->dev, 451 (NUM_TX_BUFF * maldata->num_tx_chans +
294 MAL_DT_ALIGN * 452 NUM_RX_BUFF * maldata->num_rx_chans);
295 maldata->num_tx_chans, 453 mal->bd_virt =
296 &mal->tx_phys_addr, GFP_KERNEL); 454 dma_alloc_coherent(&ocpdev->dev, bd_size, &mal->bd_dma, GFP_KERNEL);
297 if (mal->tx_virt_addr == NULL) { 455
456 if (!mal->bd_virt) {
298 printk(KERN_ERR 457 printk(KERN_ERR
299 "mal%d: Out of memory allocating MAL descriptors !\n", 458 "mal%d: out of memory allocating RX/TX descriptors!\n",
300 ocpdev->def->index); 459 mal->def->index);
301 err = -ENOMEM; 460 err = -ENOMEM;
302 goto fail; 461 goto fail;
303 } 462 }
463 memset(mal->bd_virt, 0, bd_size);
304 464
305 /* God, oh, god, I hate DCRs */ 465 for (i = 0; i < maldata->num_tx_chans; ++i)
306 set_mal_dcrn(mal, DCRN_MALTXCTP0R, mal->tx_phys_addr); 466 set_mal_dcrn(mal, MAL_TXCTPR(i), mal->bd_dma +
307#ifdef DCRN_MALTXCTP1R 467 sizeof(struct mal_descriptor) *
308 if (maldata->num_tx_chans > 1) 468 mal_tx_bd_offset(mal, i));
309 set_mal_dcrn(mal, DCRN_MALTXCTP1R, 469
310 mal->tx_phys_addr + MAL_DT_ALIGN); 470 for (i = 0; i < maldata->num_rx_chans; ++i)
311#endif /* DCRN_MALTXCTP1R */ 471 set_mal_dcrn(mal, MAL_RXCTPR(i), mal->bd_dma +
312#ifdef DCRN_MALTXCTP2R 472 sizeof(struct mal_descriptor) *
313 if (maldata->num_tx_chans > 2) 473 mal_rx_bd_offset(mal, i));
314 set_mal_dcrn(mal, DCRN_MALTXCTP2R,
315 mal->tx_phys_addr + 2 * MAL_DT_ALIGN);
316#endif /* DCRN_MALTXCTP2R */
317#ifdef DCRN_MALTXCTP3R
318 if (maldata->num_tx_chans > 3)
319 set_mal_dcrn(mal, DCRN_MALTXCTP3R,
320 mal->tx_phys_addr + 3 * MAL_DT_ALIGN);
321#endif /* DCRN_MALTXCTP3R */
322#ifdef DCRN_MALTXCTP4R
323 if (maldata->num_tx_chans > 4)
324 set_mal_dcrn(mal, DCRN_MALTXCTP4R,
325 mal->tx_phys_addr + 4 * MAL_DT_ALIGN);
326#endif /* DCRN_MALTXCTP4R */
327#ifdef DCRN_MALTXCTP5R
328 if (maldata->num_tx_chans > 5)
329 set_mal_dcrn(mal, DCRN_MALTXCTP5R,
330 mal->tx_phys_addr + 5 * MAL_DT_ALIGN);
331#endif /* DCRN_MALTXCTP5R */
332#ifdef DCRN_MALTXCTP6R
333 if (maldata->num_tx_chans > 6)
334 set_mal_dcrn(mal, DCRN_MALTXCTP6R,
335 mal->tx_phys_addr + 6 * MAL_DT_ALIGN);
336#endif /* DCRN_MALTXCTP6R */
337#ifdef DCRN_MALTXCTP7R
338 if (maldata->num_tx_chans > 7)
339 set_mal_dcrn(mal, DCRN_MALTXCTP7R,
340 mal->tx_phys_addr + 7 * MAL_DT_ALIGN);
341#endif /* DCRN_MALTXCTP7R */
342
343 mal->rx_virt_addr = dma_alloc_coherent(&ocpdev->dev,
344 MAL_DT_ALIGN *
345 maldata->num_rx_chans,
346 &mal->rx_phys_addr, GFP_KERNEL);
347
348 set_mal_dcrn(mal, DCRN_MALRXCTP0R, mal->rx_phys_addr);
349#ifdef DCRN_MALRXCTP1R
350 if (maldata->num_rx_chans > 1)
351 set_mal_dcrn(mal, DCRN_MALRXCTP1R,
352 mal->rx_phys_addr + MAL_DT_ALIGN);
353#endif /* DCRN_MALRXCTP1R */
354#ifdef DCRN_MALRXCTP2R
355 if (maldata->num_rx_chans > 2)
356 set_mal_dcrn(mal, DCRN_MALRXCTP2R,
357 mal->rx_phys_addr + 2 * MAL_DT_ALIGN);
358#endif /* DCRN_MALRXCTP2R */
359#ifdef DCRN_MALRXCTP3R
360 if (maldata->num_rx_chans > 3)
361 set_mal_dcrn(mal, DCRN_MALRXCTP3R,
362 mal->rx_phys_addr + 3 * MAL_DT_ALIGN);
363#endif /* DCRN_MALRXCTP3R */
364 474
365 err = request_irq(maldata->serr_irq, mal_serr, 0, "MAL SERR", mal); 475 err = request_irq(maldata->serr_irq, mal_serr, 0, "MAL SERR", mal);
366 if (err) 476 if (err)
367 goto fail; 477 goto fail2;
368 err = request_irq(maldata->txde_irq, mal_txde, 0, "MAL TX DE ", mal); 478 err = request_irq(maldata->txde_irq, mal_txde, 0, "MAL TX DE", mal);
369 if (err) 479 if (err)
370 goto fail; 480 goto fail3;
371 err = request_irq(maldata->txeob_irq, mal_txeob, 0, "MAL TX EOB", mal); 481 err = request_irq(maldata->txeob_irq, mal_txeob, 0, "MAL TX EOB", mal);
372 if (err) 482 if (err)
373 goto fail; 483 goto fail4;
374 err = request_irq(maldata->rxde_irq, mal_rxde, 0, "MAL RX DE", mal); 484 err = request_irq(maldata->rxde_irq, mal_rxde, 0, "MAL RX DE", mal);
375 if (err) 485 if (err)
376 goto fail; 486 goto fail5;
377 err = request_irq(maldata->rxeob_irq, mal_rxeob, 0, "MAL RX EOB", mal); 487 err = request_irq(maldata->rxeob_irq, mal_rxeob, 0, "MAL RX EOB", mal);
378 if (err) 488 if (err)
379 goto fail; 489 goto fail6;
380 490
381 set_mal_dcrn(mal, DCRN_MALIER, 491 /* Enable all MAL SERR interrupt sources */
382 MALIER_DE | MALIER_NE | MALIER_TE | 492 set_mal_dcrn(mal, MAL_IER, MAL_IER_EVENTS);
383 MALIER_OPBE | MALIER_PLBE);
384 493
385 /* Advertise me to the rest of the world */ 494 /* Advertise this instance to the rest of the world */
386 ocp_set_drvdata(ocpdev, mal); 495 ocp_set_drvdata(ocpdev, mal);
387 496
388 printk(KERN_INFO "mal%d: Initialized, %d tx channels, %d rx channels\n", 497 mal_dbg_register(mal->def->index, mal);
389 ocpdev->def->index, maldata->num_tx_chans,
390 maldata->num_rx_chans);
391 498
499 printk(KERN_INFO "mal%d: initialized, %d TX channels, %d RX channels\n",
500 mal->def->index, maldata->num_tx_chans, maldata->num_rx_chans);
392 return 0; 501 return 0;
393 502
503 fail6:
504 free_irq(maldata->rxde_irq, mal);
505 fail5:
506 free_irq(maldata->txeob_irq, mal);
507 fail4:
508 free_irq(maldata->txde_irq, mal);
509 fail3:
510 free_irq(maldata->serr_irq, mal);
511 fail2:
512 dma_free_coherent(&ocpdev->dev, bd_size, mal->bd_virt, mal->bd_dma);
394 fail: 513 fail:
395 /* FIXME: dispose requested IRQs ! */ 514 kfree(mal);
396 if (err && mal)
397 kfree(mal);
398 return err; 515 return err;
399} 516}
400 517
401static void __exit mal_remove(struct ocp_device *ocpdev) 518static void __exit mal_remove(struct ocp_device *ocpdev)
402{ 519{
403 struct ibm_ocp_mal *mal = ocp_get_drvdata(ocpdev); 520 struct ibm_ocp_mal *mal = ocp_get_drvdata(ocpdev);
404 struct ocp_func_mal_data *maldata = ocpdev->def->additions; 521 struct ocp_func_mal_data *maldata = mal->def->additions;
522
523 MAL_DBG("%d: remove" NL, mal->def->index);
405 524
406 BUG_ON(!maldata); 525 /* Syncronize with scheduled polling,
526 stolen from net/core/dev.c:dev_close()
527 */
528 clear_bit(__LINK_STATE_START, &mal->poll_dev.state);
529 netif_poll_disable(&mal->poll_dev);
530
531 if (!list_empty(&mal->list)) {
532 /* This is *very* bad */
533 printk(KERN_EMERG
534 "mal%d: commac list is not empty on remove!\n",
535 mal->def->index);
536 }
407 537
408 ocp_set_drvdata(ocpdev, NULL); 538 ocp_set_drvdata(ocpdev, NULL);
409 539
410 /* FIXME: shut down the MAL, deal with dependency with emac */
411 free_irq(maldata->serr_irq, mal); 540 free_irq(maldata->serr_irq, mal);
412 free_irq(maldata->txde_irq, mal); 541 free_irq(maldata->txde_irq, mal);
413 free_irq(maldata->txeob_irq, mal); 542 free_irq(maldata->txeob_irq, mal);
414 free_irq(maldata->rxde_irq, mal); 543 free_irq(maldata->rxde_irq, mal);
415 free_irq(maldata->rxeob_irq, mal); 544 free_irq(maldata->rxeob_irq, mal);
416 545
417 if (mal->tx_virt_addr) 546 mal_reset(mal);
418 dma_free_coherent(&ocpdev->dev,
419 MAL_DT_ALIGN * maldata->num_tx_chans,
420 mal->tx_virt_addr, mal->tx_phys_addr);
421 547
422 if (mal->rx_virt_addr) 548 mal_dbg_register(mal->def->index, NULL);
423 dma_free_coherent(&ocpdev->dev, 549
424 MAL_DT_ALIGN * maldata->num_rx_chans, 550 dma_free_coherent(&ocpdev->dev,
425 mal->rx_virt_addr, mal->rx_phys_addr); 551 sizeof(struct mal_descriptor) *
552 (NUM_TX_BUFF * maldata->num_tx_chans +
553 NUM_RX_BUFF * maldata->num_rx_chans), mal->bd_virt,
554 mal->bd_dma);
426 555
427 kfree(mal); 556 kfree(mal);
428} 557}
429 558
430/* Structure for a device driver */ 559/* Structure for a device driver */
431static struct ocp_device_id mal_ids[] = { 560static struct ocp_device_id mal_ids[] = {
432 {.vendor = OCP_ANY_ID,.function = OCP_FUNC_MAL}, 561 { .vendor = OCP_VENDOR_IBM, .function = OCP_FUNC_MAL },
433 {.vendor = OCP_VENDOR_INVALID} 562 { .vendor = OCP_VENDOR_INVALID}
434}; 563};
435 564
436static struct ocp_driver mal_driver = { 565static struct ocp_driver mal_driver = {
@@ -441,23 +570,14 @@ static struct ocp_driver mal_driver = {
441 .remove = mal_remove, 570 .remove = mal_remove,
442}; 571};
443 572
444static int __init init_mals(void) 573int __init mal_init(void)
445{ 574{
446 int rc; 575 MAL_DBG(": init" NL);
447 576 return ocp_register_driver(&mal_driver);
448 rc = ocp_register_driver(&mal_driver);
449 if (rc < 0) {
450 ocp_unregister_driver(&mal_driver);
451 return -ENODEV;
452 }
453
454 return 0;
455} 577}
456 578
457static void __exit exit_mals(void) 579void __exit mal_exit(void)
458{ 580{
581 MAL_DBG(": exit" NL);
459 ocp_unregister_driver(&mal_driver); 582 ocp_unregister_driver(&mal_driver);
460} 583}
461
462module_init(init_mals);
463module_exit(exit_mals);
diff --git a/drivers/net/ibm_emac/ibm_emac_mal.h b/drivers/net/ibm_emac/ibm_emac_mal.h
index dd9f0dabc6e0..15b0bdae26ac 100644
--- a/drivers/net/ibm_emac/ibm_emac_mal.h
+++ b/drivers/net/ibm_emac/ibm_emac_mal.h
@@ -1,131 +1,267 @@
1#ifndef _IBM_EMAC_MAL_H 1/*
2#define _IBM_EMAC_MAL_H 2 * drivers/net/ibm_emac/ibm_emac_mal.h
3 *
4 * Memory Access Layer (MAL) support
5 *
6 * Copyright (c) 2004, 2005 Zultys Technologies.
7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
8 *
9 * Based on original work by
10 * Armin Kuster <akuster@mvista.com>
11 * Copyright 2002 MontaVista Softare Inc.
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 *
18 */
19#ifndef __IBM_EMAC_MAL_H_
20#define __IBM_EMAC_MAL_H_
3 21
22#include <linux/config.h>
23#include <linux/init.h>
4#include <linux/list.h> 24#include <linux/list.h>
25#include <linux/netdevice.h>
5 26
6#define MAL_DT_ALIGN (4096) /* Alignment for each channel's descriptor table */ 27#include <asm/io.h>
7 28
8#define MAL_CHAN_MASK(chan) (0x80000000 >> (chan)) 29/*
30 * These MAL "versions" probably aren't the real versions IBM uses for these
31 * MAL cores, I assigned them just to make #ifdefs in this file nicer and
32 * reflect the fact that 40x and 44x have slightly different MALs. --ebs
33 */
34#if defined(CONFIG_405GP) || defined(CONFIG_405GPR) || defined(CONFIG_405EP) || \
35 defined(CONFIG_440EP) || defined(CONFIG_NP405H)
36#define MAL_VERSION 1
37#elif defined(CONFIG_440GP) || defined(CONFIG_440GX) || defined(CONFIG_440SP)
38#define MAL_VERSION 2
39#else
40#error "Unknown SoC, please check chip manual and choose MAL 'version'"
41#endif
42
43/* MALx DCR registers */
44#define MAL_CFG 0x00
45#define MAL_CFG_SR 0x80000000
46#define MAL_CFG_PLBB 0x00004000
47#define MAL_CFG_OPBBL 0x00000080
48#define MAL_CFG_EOPIE 0x00000004
49#define MAL_CFG_LEA 0x00000002
50#define MAL_CFG_SD 0x00000001
51#if MAL_VERSION == 1
52#define MAL_CFG_PLBP_MASK 0x00c00000
53#define MAL_CFG_PLBP_10 0x00800000
54#define MAL_CFG_GA 0x00200000
55#define MAL_CFG_OA 0x00100000
56#define MAL_CFG_PLBLE 0x00080000
57#define MAL_CFG_PLBT_MASK 0x00078000
58#define MAL_CFG_DEFAULT (MAL_CFG_PLBP_10 | MAL_CFG_PLBT_MASK)
59#elif MAL_VERSION == 2
60#define MAL_CFG_RPP_MASK 0x00c00000
61#define MAL_CFG_RPP_10 0x00800000
62#define MAL_CFG_RMBS_MASK 0x00300000
63#define MAL_CFG_WPP_MASK 0x000c0000
64#define MAL_CFG_WPP_10 0x00080000
65#define MAL_CFG_WMBS_MASK 0x00030000
66#define MAL_CFG_PLBLE 0x00008000
67#define MAL_CFG_DEFAULT (MAL_CFG_RMBS_MASK | MAL_CFG_WMBS_MASK | \
68 MAL_CFG_RPP_10 | MAL_CFG_WPP_10)
69#else
70#error "Unknown MAL version"
71#endif
72
73#define MAL_ESR 0x01
74#define MAL_ESR_EVB 0x80000000
75#define MAL_ESR_CIDT 0x40000000
76#define MAL_ESR_CID_MASK 0x3e000000
77#define MAL_ESR_CID_SHIFT 25
78#define MAL_ESR_DE 0x00100000
79#define MAL_ESR_OTE 0x00040000
80#define MAL_ESR_OSE 0x00020000
81#define MAL_ESR_PEIN 0x00010000
82#define MAL_ESR_DEI 0x00000010
83#define MAL_ESR_OTEI 0x00000004
84#define MAL_ESR_OSEI 0x00000002
85#define MAL_ESR_PBEI 0x00000001
86#if MAL_VERSION == 1
87#define MAL_ESR_ONE 0x00080000
88#define MAL_ESR_ONEI 0x00000008
89#elif MAL_VERSION == 2
90#define MAL_ESR_PTE 0x00800000
91#define MAL_ESR_PRE 0x00400000
92#define MAL_ESR_PWE 0x00200000
93#define MAL_ESR_PTEI 0x00000080
94#define MAL_ESR_PREI 0x00000040
95#define MAL_ESR_PWEI 0x00000020
96#else
97#error "Unknown MAL version"
98#endif
99
100#define MAL_IER 0x02
101#define MAL_IER_DE 0x00000010
102#define MAL_IER_OTE 0x00000004
103#define MAL_IER_OE 0x00000002
104#define MAL_IER_PE 0x00000001
105#if MAL_VERSION == 1
106#define MAL_IER_NWE 0x00000008
107#define MAL_IER_SOC_EVENTS MAL_IER_NWE
108#elif MAL_VERSION == 2
109#define MAL_IER_PT 0x00000080
110#define MAL_IER_PRE 0x00000040
111#define MAL_IER_PWE 0x00000020
112#define MAL_IER_SOC_EVENTS (MAL_IER_PT | MAL_IER_PRE | MAL_IER_PWE)
113#else
114#error "Unknown MAL version"
115#endif
116#define MAL_IER_EVENTS (MAL_IER_SOC_EVENTS | MAL_IER_OTE | \
117 MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE)
118
119#define MAL_TXCASR 0x04
120#define MAL_TXCARR 0x05
121#define MAL_TXEOBISR 0x06
122#define MAL_TXDEIR 0x07
123#define MAL_RXCASR 0x10
124#define MAL_RXCARR 0x11
125#define MAL_RXEOBISR 0x12
126#define MAL_RXDEIR 0x13
127#define MAL_TXCTPR(n) ((n) + 0x20)
128#define MAL_RXCTPR(n) ((n) + 0x40)
129#define MAL_RCBS(n) ((n) + 0x60)
130
131/* In reality MAL can handle TX buffers up to 4095 bytes long,
132 * but this isn't a good round number :) --ebs
133 */
134#define MAL_MAX_TX_SIZE 4080
135#define MAL_MAX_RX_SIZE 4080
136
137static inline int mal_rx_size(int len)
138{
139 len = (len + 0xf) & ~0xf;
140 return len > MAL_MAX_RX_SIZE ? MAL_MAX_RX_SIZE : len;
141}
142
143static inline int mal_tx_chunks(int len)
144{
145 return (len + MAL_MAX_TX_SIZE - 1) / MAL_MAX_TX_SIZE;
146}
147
148#define MAL_CHAN_MASK(n) (0x80000000 >> (n))
9 149
10/* MAL Buffer Descriptor structure */ 150/* MAL Buffer Descriptor structure */
11struct mal_descriptor { 151struct mal_descriptor {
12 unsigned short ctrl; /* MAL / Commac status control bits */ 152 u16 ctrl; /* MAL / Commac status control bits */
13 short data_len; /* Max length is 4K-1 (12 bits) */ 153 u16 data_len; /* Max length is 4K-1 (12 bits) */
14 unsigned char *data_ptr; /* pointer to actual data buffer */ 154 u32 data_ptr; /* pointer to actual data buffer */
15} __attribute__ ((packed)); 155};
16 156
17/* the following defines are for the MadMAL status and control registers. */ 157/* the following defines are for the MadMAL status and control registers. */
18/* MADMAL transmit and receive status/control bits */ 158/* MADMAL transmit and receive status/control bits */
19#define MAL_RX_CTRL_EMPTY 0x8000 159#define MAL_RX_CTRL_EMPTY 0x8000
20#define MAL_RX_CTRL_WRAP 0x4000 160#define MAL_RX_CTRL_WRAP 0x4000
21#define MAL_RX_CTRL_CM 0x2000 161#define MAL_RX_CTRL_CM 0x2000
22#define MAL_RX_CTRL_LAST 0x1000 162#define MAL_RX_CTRL_LAST 0x1000
23#define MAL_RX_CTRL_FIRST 0x0800 163#define MAL_RX_CTRL_FIRST 0x0800
24#define MAL_RX_CTRL_INTR 0x0400 164#define MAL_RX_CTRL_INTR 0x0400
25 165#define MAL_RX_CTRL_SINGLE (MAL_RX_CTRL_LAST | MAL_RX_CTRL_FIRST)
26#define MAL_TX_CTRL_READY 0x8000 166#define MAL_IS_SINGLE_RX(ctrl) (((ctrl) & MAL_RX_CTRL_SINGLE) == MAL_RX_CTRL_SINGLE)
27#define MAL_TX_CTRL_WRAP 0x4000 167
28#define MAL_TX_CTRL_CM 0x2000 168#define MAL_TX_CTRL_READY 0x8000
29#define MAL_TX_CTRL_LAST 0x1000 169#define MAL_TX_CTRL_WRAP 0x4000
30#define MAL_TX_CTRL_INTR 0x0400 170#define MAL_TX_CTRL_CM 0x2000
171#define MAL_TX_CTRL_LAST 0x1000
172#define MAL_TX_CTRL_INTR 0x0400
31 173
32struct mal_commac_ops { 174struct mal_commac_ops {
33 void (*txeob) (void *dev, u32 chanmask); 175 void (*poll_tx) (void *dev);
34 void (*txde) (void *dev, u32 chanmask); 176 int (*poll_rx) (void *dev, int budget);
35 void (*rxeob) (void *dev, u32 chanmask); 177 int (*peek_rx) (void *dev);
36 void (*rxde) (void *dev, u32 chanmask); 178 void (*rxde) (void *dev);
37}; 179};
38 180
39struct mal_commac { 181struct mal_commac {
40 struct mal_commac_ops *ops; 182 struct mal_commac_ops *ops;
41 void *dev; 183 void *dev;
42 u32 tx_chan_mask, rx_chan_mask; 184 struct list_head poll_list;
43 struct list_head list; 185 int rx_stopped;
186
187 u32 tx_chan_mask;
188 u32 rx_chan_mask;
189 struct list_head list;
44}; 190};
45 191
46struct ibm_ocp_mal { 192struct ibm_ocp_mal {
47 int dcrbase; 193 int dcrbase;
48 194
49 struct list_head commac; 195 struct list_head poll_list;
50 u32 tx_chan_mask, rx_chan_mask; 196 struct net_device poll_dev;
51 197
52 dma_addr_t tx_phys_addr; 198 struct list_head list;
53 struct mal_descriptor *tx_virt_addr; 199 u32 tx_chan_mask;
200 u32 rx_chan_mask;
54 201
55 dma_addr_t rx_phys_addr; 202 dma_addr_t bd_dma;
56 struct mal_descriptor *rx_virt_addr; 203 struct mal_descriptor *bd_virt;
57};
58 204
59#define GET_MAL_STANZA(base,dcrn) \ 205 struct ocp_def *def;
60 case base: \ 206};
61 x = mfdcr(dcrn(base)); \
62 break;
63
64#define SET_MAL_STANZA(base,dcrn, val) \
65 case base: \
66 mtdcr(dcrn(base), (val)); \
67 break;
68
69#define GET_MAL0_STANZA(dcrn) GET_MAL_STANZA(DCRN_MAL_BASE,dcrn)
70#define SET_MAL0_STANZA(dcrn,val) SET_MAL_STANZA(DCRN_MAL_BASE,dcrn,val)
71
72#ifdef DCRN_MAL1_BASE
73#define GET_MAL1_STANZA(dcrn) GET_MAL_STANZA(DCRN_MAL1_BASE,dcrn)
74#define SET_MAL1_STANZA(dcrn,val) SET_MAL_STANZA(DCRN_MAL1_BASE,dcrn,val)
75#else /* ! DCRN_MAL1_BASE */
76#define GET_MAL1_STANZA(dcrn)
77#define SET_MAL1_STANZA(dcrn,val)
78#endif
79 207
80#define get_mal_dcrn(mal, dcrn) ({ \ 208static inline u32 get_mal_dcrn(struct ibm_ocp_mal *mal, int reg)
81 u32 x; \
82 switch ((mal)->dcrbase) { \
83 GET_MAL0_STANZA(dcrn) \
84 GET_MAL1_STANZA(dcrn) \
85 default: \
86 x = 0; \
87 BUG(); \
88 } \
89x; })
90
91#define set_mal_dcrn(mal, dcrn, val) do { \
92 switch ((mal)->dcrbase) { \
93 SET_MAL0_STANZA(dcrn,val) \
94 SET_MAL1_STANZA(dcrn,val) \
95 default: \
96 BUG(); \
97 } } while (0)
98
99static inline void mal_enable_tx_channels(struct ibm_ocp_mal *mal, u32 chanmask)
100{ 209{
101 set_mal_dcrn(mal, DCRN_MALTXCASR, 210 return mfdcr(mal->dcrbase + reg);
102 get_mal_dcrn(mal, DCRN_MALTXCASR) | chanmask);
103} 211}
104 212
105static inline void mal_disable_tx_channels(struct ibm_ocp_mal *mal, 213static inline void set_mal_dcrn(struct ibm_ocp_mal *mal, int reg, u32 val)
106 u32 chanmask)
107{ 214{
108 set_mal_dcrn(mal, DCRN_MALTXCARR, chanmask); 215 mtdcr(mal->dcrbase + reg, val);
109} 216}
110 217
111static inline void mal_enable_rx_channels(struct ibm_ocp_mal *mal, u32 chanmask) 218/* Register MAL devices */
112{ 219int mal_init(void) __init;
113 set_mal_dcrn(mal, DCRN_MALRXCASR, 220void mal_exit(void) __exit;
114 get_mal_dcrn(mal, DCRN_MALRXCASR) | chanmask);
115}
116 221
117static inline void mal_disable_rx_channels(struct ibm_ocp_mal *mal, 222int mal_register_commac(struct ibm_ocp_mal *mal,
118 u32 chanmask) 223 struct mal_commac *commac) __init;
119{ 224void mal_unregister_commac(struct ibm_ocp_mal *mal,
120 set_mal_dcrn(mal, DCRN_MALRXCARR, chanmask); 225 struct mal_commac *commac) __exit;
121} 226int mal_set_rcbs(struct ibm_ocp_mal *mal, int channel, unsigned long size);
227
228/* Returns BD ring offset for a particular channel
229 (in 'struct mal_descriptor' elements)
230*/
231int mal_tx_bd_offset(struct ibm_ocp_mal *mal, int channel);
232int mal_rx_bd_offset(struct ibm_ocp_mal *mal, int channel);
233
234void mal_enable_tx_channel(struct ibm_ocp_mal *mal, int channel);
235void mal_disable_tx_channel(struct ibm_ocp_mal *mal, int channel);
236void mal_enable_rx_channel(struct ibm_ocp_mal *mal, int channel);
237void mal_disable_rx_channel(struct ibm_ocp_mal *mal, int channel);
122 238
123extern int mal_register_commac(struct ibm_ocp_mal *mal, 239/* Add/remove EMAC to/from MAL polling list */
124 struct mal_commac *commac); 240void mal_poll_add(struct ibm_ocp_mal *mal, struct mal_commac *commac);
125extern int mal_unregister_commac(struct ibm_ocp_mal *mal, 241void mal_poll_del(struct ibm_ocp_mal *mal, struct mal_commac *commac);
126 struct mal_commac *commac); 242
243/* Ethtool MAL registers */
244struct ibm_mal_regs {
245 u32 tx_count;
246 u32 rx_count;
247
248 u32 cfg;
249 u32 esr;
250 u32 ier;
251 u32 tx_casr;
252 u32 tx_carr;
253 u32 tx_eobisr;
254 u32 tx_deir;
255 u32 rx_casr;
256 u32 rx_carr;
257 u32 rx_eobisr;
258 u32 rx_deir;
259 u32 tx_ctpr[32];
260 u32 rx_ctpr[32];
261 u32 rcbs[32];
262};
127 263
128extern int mal_set_rcbs(struct ibm_ocp_mal *mal, int channel, 264int mal_get_regs_len(struct ibm_ocp_mal *mal);
129 unsigned long size); 265void *mal_dump_regs(struct ibm_ocp_mal *mal, void *buf);
130 266
131#endif /* _IBM_EMAC_MAL_H */ 267#endif /* __IBM_EMAC_MAL_H_ */
diff --git a/drivers/net/ibm_emac/ibm_emac_phy.c b/drivers/net/ibm_emac/ibm_emac_phy.c
index 14213f090e91..a27e49cfe43b 100644
--- a/drivers/net/ibm_emac/ibm_emac_phy.c
+++ b/drivers/net/ibm_emac/ibm_emac_phy.c
@@ -1,96 +1,80 @@
1/* 1/*
2 * ibm_ocp_phy.c 2 * drivers/net/ibm_emac/ibm_emac_phy.c
3 * 3 *
4 * PHY drivers for the ibm ocp ethernet driver. Borrowed 4 * Driver for PowerPC 4xx on-chip ethernet controller, PHY support.
5 * from sungem_phy.c, though I only kept the generic MII 5 * Borrowed from sungem_phy.c, though I only kept the generic MII
6 * driver for now. 6 * driver for now.
7 * 7 *
8 * This file should be shared with other drivers or eventually 8 * This file should be shared with other drivers or eventually
9 * merged as the "low level" part of miilib 9 * merged as the "low level" part of miilib
10 * 10 *
11 * (c) 2003, Benjamin Herrenscmidt (benh@kernel.crashing.org) 11 * (c) 2003, Benjamin Herrenscmidt (benh@kernel.crashing.org)
12 * (c) 2004-2005, Eugene Surovegin <ebs@ebshome.net>
12 * 13 *
13 */ 14 */
14
15#include <linux/config.h> 15#include <linux/config.h>
16
17#include <linux/module.h> 16#include <linux/module.h>
18
19#include <linux/kernel.h> 17#include <linux/kernel.h>
20#include <linux/sched.h>
21#include <linux/types.h> 18#include <linux/types.h>
22#include <linux/netdevice.h> 19#include <linux/netdevice.h>
23#include <linux/etherdevice.h>
24#include <linux/mii.h> 20#include <linux/mii.h>
25#include <linux/ethtool.h> 21#include <linux/ethtool.h>
26#include <linux/delay.h> 22#include <linux/delay.h>
27 23
24#include <asm/ocp.h>
25
28#include "ibm_emac_phy.h" 26#include "ibm_emac_phy.h"
29 27
30static int reset_one_mii_phy(struct mii_phy *phy, int phy_id) 28static inline int phy_read(struct mii_phy *phy, int reg)
29{
30 return phy->mdio_read(phy->dev, phy->address, reg);
31}
32
33static inline void phy_write(struct mii_phy *phy, int reg, int val)
31{ 34{
32 u16 val; 35 phy->mdio_write(phy->dev, phy->address, reg, val);
36}
37
38int mii_reset_phy(struct mii_phy *phy)
39{
40 int val;
33 int limit = 10000; 41 int limit = 10000;
34 42
35 val = __phy_read(phy, phy_id, MII_BMCR); 43 val = phy_read(phy, MII_BMCR);
36 val &= ~BMCR_ISOLATE; 44 val &= ~BMCR_ISOLATE;
37 val |= BMCR_RESET; 45 val |= BMCR_RESET;
38 __phy_write(phy, phy_id, MII_BMCR, val); 46 phy_write(phy, MII_BMCR, val);
39 47
40 udelay(100); 48 udelay(300);
41 49
42 while (limit--) { 50 while (limit--) {
43 val = __phy_read(phy, phy_id, MII_BMCR); 51 val = phy_read(phy, MII_BMCR);
44 if ((val & BMCR_RESET) == 0) 52 if (val >= 0 && (val & BMCR_RESET) == 0)
45 break; 53 break;
46 udelay(10); 54 udelay(10);
47 } 55 }
48 if ((val & BMCR_ISOLATE) && limit > 0) 56 if ((val & BMCR_ISOLATE) && limit > 0)
49 __phy_write(phy, phy_id, MII_BMCR, val & ~BMCR_ISOLATE); 57 phy_write(phy, MII_BMCR, val & ~BMCR_ISOLATE);
50
51 return (limit <= 0);
52}
53
54static int cis8201_init(struct mii_phy *phy)
55{
56 u16 epcr;
57
58 epcr = phy_read(phy, MII_CIS8201_EPCR);
59 epcr &= ~EPCR_MODE_MASK;
60
61 switch (phy->mode) {
62 case PHY_MODE_TBI:
63 epcr |= EPCR_TBI_MODE;
64 break;
65 case PHY_MODE_RTBI:
66 epcr |= EPCR_RTBI_MODE;
67 break;
68 case PHY_MODE_GMII:
69 epcr |= EPCR_GMII_MODE;
70 break;
71 case PHY_MODE_RGMII:
72 default:
73 epcr |= EPCR_RGMII_MODE;
74 }
75 58
76 phy_write(phy, MII_CIS8201_EPCR, epcr); 59 return limit <= 0;
77
78 return 0;
79} 60}
80 61
81static int genmii_setup_aneg(struct mii_phy *phy, u32 advertise) 62static int genmii_setup_aneg(struct mii_phy *phy, u32 advertise)
82{ 63{
83 u16 ctl, adv; 64 int ctl, adv;
84 65
85 phy->autoneg = 1; 66 phy->autoneg = AUTONEG_ENABLE;
86 phy->speed = SPEED_10; 67 phy->speed = SPEED_10;
87 phy->duplex = DUPLEX_HALF; 68 phy->duplex = DUPLEX_HALF;
88 phy->pause = 0; 69 phy->pause = phy->asym_pause = 0;
89 phy->advertising = advertise; 70 phy->advertising = advertise;
90 71
91 /* Setup standard advertise */ 72 /* Setup standard advertise */
92 adv = phy_read(phy, MII_ADVERTISE); 73 adv = phy_read(phy, MII_ADVERTISE);
93 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4); 74 if (adv < 0)
75 return adv;
76 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP |
77 ADVERTISE_PAUSE_ASYM);
94 if (advertise & ADVERTISED_10baseT_Half) 78 if (advertise & ADVERTISED_10baseT_Half)
95 adv |= ADVERTISE_10HALF; 79 adv |= ADVERTISE_10HALF;
96 if (advertise & ADVERTISED_10baseT_Full) 80 if (advertise & ADVERTISED_10baseT_Full)
@@ -99,8 +83,25 @@ static int genmii_setup_aneg(struct mii_phy *phy, u32 advertise)
99 adv |= ADVERTISE_100HALF; 83 adv |= ADVERTISE_100HALF;
100 if (advertise & ADVERTISED_100baseT_Full) 84 if (advertise & ADVERTISED_100baseT_Full)
101 adv |= ADVERTISE_100FULL; 85 adv |= ADVERTISE_100FULL;
86 if (advertise & ADVERTISED_Pause)
87 adv |= ADVERTISE_PAUSE_CAP;
88 if (advertise & ADVERTISED_Asym_Pause)
89 adv |= ADVERTISE_PAUSE_ASYM;
102 phy_write(phy, MII_ADVERTISE, adv); 90 phy_write(phy, MII_ADVERTISE, adv);
103 91
92 if (phy->features &
93 (SUPPORTED_1000baseT_Full | SUPPORTED_1000baseT_Half)) {
94 adv = phy_read(phy, MII_CTRL1000);
95 if (adv < 0)
96 return adv;
97 adv &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF);
98 if (advertise & ADVERTISED_1000baseT_Full)
99 adv |= ADVERTISE_1000FULL;
100 if (advertise & ADVERTISED_1000baseT_Half)
101 adv |= ADVERTISE_1000HALF;
102 phy_write(phy, MII_CTRL1000, adv);
103 }
104
104 /* Start/Restart aneg */ 105 /* Start/Restart aneg */
105 ctl = phy_read(phy, MII_BMCR); 106 ctl = phy_read(phy, MII_BMCR);
106 ctl |= (BMCR_ANENABLE | BMCR_ANRESTART); 107 ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
@@ -111,14 +112,16 @@ static int genmii_setup_aneg(struct mii_phy *phy, u32 advertise)
111 112
112static int genmii_setup_forced(struct mii_phy *phy, int speed, int fd) 113static int genmii_setup_forced(struct mii_phy *phy, int speed, int fd)
113{ 114{
114 u16 ctl; 115 int ctl;
115 116
116 phy->autoneg = 0; 117 phy->autoneg = AUTONEG_DISABLE;
117 phy->speed = speed; 118 phy->speed = speed;
118 phy->duplex = fd; 119 phy->duplex = fd;
119 phy->pause = 0; 120 phy->pause = phy->asym_pause = 0;
120 121
121 ctl = phy_read(phy, MII_BMCR); 122 ctl = phy_read(phy, MII_BMCR);
123 if (ctl < 0)
124 return ctl;
122 ctl &= ~(BMCR_FULLDPLX | BMCR_SPEED100 | BMCR_ANENABLE); 125 ctl &= ~(BMCR_FULLDPLX | BMCR_SPEED100 | BMCR_ANENABLE);
123 126
124 /* First reset the PHY */ 127 /* First reset the PHY */
@@ -132,6 +135,8 @@ static int genmii_setup_forced(struct mii_phy *phy, int speed, int fd)
132 ctl |= BMCR_SPEED100; 135 ctl |= BMCR_SPEED100;
133 break; 136 break;
134 case SPEED_1000: 137 case SPEED_1000:
138 ctl |= BMCR_SPEED1000;
139 break;
135 default: 140 default:
136 return -EINVAL; 141 return -EINVAL;
137 } 142 }
@@ -144,112 +149,143 @@ static int genmii_setup_forced(struct mii_phy *phy, int speed, int fd)
144 149
145static int genmii_poll_link(struct mii_phy *phy) 150static int genmii_poll_link(struct mii_phy *phy)
146{ 151{
147 u16 status; 152 int status;
148 153
149 (void)phy_read(phy, MII_BMSR); 154 /* Clear latched value with dummy read */
155 phy_read(phy, MII_BMSR);
150 status = phy_read(phy, MII_BMSR); 156 status = phy_read(phy, MII_BMSR);
151 if ((status & BMSR_LSTATUS) == 0) 157 if (status < 0 || (status & BMSR_LSTATUS) == 0)
152 return 0; 158 return 0;
153 if (phy->autoneg && !(status & BMSR_ANEGCOMPLETE)) 159 if (phy->autoneg == AUTONEG_ENABLE && !(status & BMSR_ANEGCOMPLETE))
154 return 0; 160 return 0;
155 return 1; 161 return 1;
156} 162}
157 163
158#define MII_CIS8201_ACSR 0x1c 164static int genmii_read_link(struct mii_phy *phy)
159#define ACSR_DUPLEX_STATUS 0x0020
160#define ACSR_SPEED_1000BASET 0x0010
161#define ACSR_SPEED_100BASET 0x0008
162
163static int cis8201_read_link(struct mii_phy *phy)
164{ 165{
165 u16 acsr; 166 if (phy->autoneg == AUTONEG_ENABLE) {
167 int glpa = 0;
168 int lpa = phy_read(phy, MII_LPA) & phy_read(phy, MII_ADVERTISE);
169 if (lpa < 0)
170 return lpa;
171
172 if (phy->features &
173 (SUPPORTED_1000baseT_Full | SUPPORTED_1000baseT_Half)) {
174 int adv = phy_read(phy, MII_CTRL1000);
175 glpa = phy_read(phy, MII_STAT1000);
176
177 if (glpa < 0 || adv < 0)
178 return adv;
179
180 glpa &= adv << 2;
181 }
182
183 phy->speed = SPEED_10;
184 phy->duplex = DUPLEX_HALF;
185 phy->pause = phy->asym_pause = 0;
186
187 if (glpa & (LPA_1000FULL | LPA_1000HALF)) {
188 phy->speed = SPEED_1000;
189 if (glpa & LPA_1000FULL)
190 phy->duplex = DUPLEX_FULL;
191 } else if (lpa & (LPA_100FULL | LPA_100HALF)) {
192 phy->speed = SPEED_100;
193 if (lpa & LPA_100FULL)
194 phy->duplex = DUPLEX_FULL;
195 } else if (lpa & LPA_10FULL)
196 phy->duplex = DUPLEX_FULL;
166 197
167 if (phy->autoneg) { 198 if (phy->duplex == DUPLEX_FULL) {
168 acsr = phy_read(phy, MII_CIS8201_ACSR); 199 phy->pause = lpa & LPA_PAUSE_CAP ? 1 : 0;
200 phy->asym_pause = lpa & LPA_PAUSE_ASYM ? 1 : 0;
201 }
202 } else {
203 int bmcr = phy_read(phy, MII_BMCR);
204 if (bmcr < 0)
205 return bmcr;
169 206
170 if (acsr & ACSR_DUPLEX_STATUS) 207 if (bmcr & BMCR_FULLDPLX)
171 phy->duplex = DUPLEX_FULL; 208 phy->duplex = DUPLEX_FULL;
172 else 209 else
173 phy->duplex = DUPLEX_HALF; 210 phy->duplex = DUPLEX_HALF;
174 if (acsr & ACSR_SPEED_1000BASET) { 211 if (bmcr & BMCR_SPEED1000)
175 phy->speed = SPEED_1000; 212 phy->speed = SPEED_1000;
176 } else if (acsr & ACSR_SPEED_100BASET) 213 else if (bmcr & BMCR_SPEED100)
177 phy->speed = SPEED_100; 214 phy->speed = SPEED_100;
178 else 215 else
179 phy->speed = SPEED_10; 216 phy->speed = SPEED_10;
180 phy->pause = 0;
181 }
182 /* On non-aneg, we assume what we put in BMCR is the speed,
183 * though magic-aneg shouldn't prevent this case from occurring
184 */
185 217
218 phy->pause = phy->asym_pause = 0;
219 }
186 return 0; 220 return 0;
187} 221}
188 222
189static int genmii_read_link(struct mii_phy *phy) 223/* Generic implementation for most 10/100/1000 PHYs */
224static struct mii_phy_ops generic_phy_ops = {
225 .setup_aneg = genmii_setup_aneg,
226 .setup_forced = genmii_setup_forced,
227 .poll_link = genmii_poll_link,
228 .read_link = genmii_read_link
229};
230
231static struct mii_phy_def genmii_phy_def = {
232 .phy_id = 0x00000000,
233 .phy_id_mask = 0x00000000,
234 .name = "Generic MII",
235 .ops = &generic_phy_ops
236};
237
238/* CIS8201 */
239#define MII_CIS8201_EPCR 0x17
240#define EPCR_MODE_MASK 0x3000
241#define EPCR_GMII_MODE 0x0000
242#define EPCR_RGMII_MODE 0x1000
243#define EPCR_TBI_MODE 0x2000
244#define EPCR_RTBI_MODE 0x3000
245
246static int cis8201_init(struct mii_phy *phy)
190{ 247{
191 u16 lpa; 248 int epcr;
192 249
193 if (phy->autoneg) { 250 epcr = phy_read(phy, MII_CIS8201_EPCR);
194 lpa = phy_read(phy, MII_LPA) & phy_read(phy, MII_ADVERTISE); 251 if (epcr < 0)
252 return epcr;
195 253
196 phy->speed = SPEED_10; 254 epcr &= ~EPCR_MODE_MASK;
197 phy->duplex = DUPLEX_HALF;
198 phy->pause = 0;
199 255
200 if (lpa & (LPA_100FULL | LPA_100HALF)) { 256 switch (phy->mode) {
201 phy->speed = SPEED_100; 257 case PHY_MODE_TBI:
202 if (lpa & LPA_100FULL) 258 epcr |= EPCR_TBI_MODE;
203 phy->duplex = DUPLEX_FULL; 259 break;
204 } else if (lpa & LPA_10FULL) 260 case PHY_MODE_RTBI:
205 phy->duplex = DUPLEX_FULL; 261 epcr |= EPCR_RTBI_MODE;
262 break;
263 case PHY_MODE_GMII:
264 epcr |= EPCR_GMII_MODE;
265 break;
266 case PHY_MODE_RGMII:
267 default:
268 epcr |= EPCR_RGMII_MODE;
206 } 269 }
207 /* On non-aneg, we assume what we put in BMCR is the speed, 270
208 * though magic-aneg shouldn't prevent this case from occurring 271 phy_write(phy, MII_CIS8201_EPCR, epcr);
209 */
210 272
211 return 0; 273 return 0;
212} 274}
213 275
214#define MII_BASIC_FEATURES (SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full | \
215 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full | \
216 SUPPORTED_Autoneg | SUPPORTED_TP | SUPPORTED_MII)
217#define MII_GBIT_FEATURES (MII_BASIC_FEATURES | \
218 SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full)
219
220/* CIS8201 phy ops */
221static struct mii_phy_ops cis8201_phy_ops = { 276static struct mii_phy_ops cis8201_phy_ops = {
222 init:cis8201_init, 277 .init = cis8201_init,
223 setup_aneg:genmii_setup_aneg, 278 .setup_aneg = genmii_setup_aneg,
224 setup_forced:genmii_setup_forced, 279 .setup_forced = genmii_setup_forced,
225 poll_link:genmii_poll_link, 280 .poll_link = genmii_poll_link,
226 read_link:cis8201_read_link 281 .read_link = genmii_read_link
227};
228
229/* Generic implementation for most 10/100 PHYs */
230static struct mii_phy_ops generic_phy_ops = {
231 setup_aneg:genmii_setup_aneg,
232 setup_forced:genmii_setup_forced,
233 poll_link:genmii_poll_link,
234 read_link:genmii_read_link
235}; 282};
236 283
237static struct mii_phy_def cis8201_phy_def = { 284static struct mii_phy_def cis8201_phy_def = {
238 phy_id:0x000fc410, 285 .phy_id = 0x000fc410,
239 phy_id_mask:0x000ffff0, 286 .phy_id_mask = 0x000ffff0,
240 name:"CIS8201 Gigabit Ethernet", 287 .name = "CIS8201 Gigabit Ethernet",
241 features:MII_GBIT_FEATURES, 288 .ops = &cis8201_phy_ops
242 magic_aneg:0,
243 ops:&cis8201_phy_ops
244};
245
246static struct mii_phy_def genmii_phy_def = {
247 phy_id:0x00000000,
248 phy_id_mask:0x00000000,
249 name:"Generic MII",
250 features:MII_BASIC_FEATURES,
251 magic_aneg:0,
252 ops:&generic_phy_ops
253}; 289};
254 290
255static struct mii_phy_def *mii_phy_table[] = { 291static struct mii_phy_def *mii_phy_table[] = {
@@ -258,39 +294,60 @@ static struct mii_phy_def *mii_phy_table[] = {
258 NULL 294 NULL
259}; 295};
260 296
261int mii_phy_probe(struct mii_phy *phy, int mii_id) 297int mii_phy_probe(struct mii_phy *phy, int address)
262{ 298{
263 int rc;
264 u32 id;
265 struct mii_phy_def *def; 299 struct mii_phy_def *def;
266 int i; 300 int i;
301 u32 id;
267 302
268 phy->autoneg = 0; 303 phy->autoneg = AUTONEG_DISABLE;
269 phy->advertising = 0; 304 phy->advertising = 0;
270 phy->mii_id = mii_id; 305 phy->address = address;
271 phy->speed = 0; 306 phy->speed = SPEED_10;
272 phy->duplex = 0; 307 phy->duplex = DUPLEX_HALF;
273 phy->pause = 0; 308 phy->pause = phy->asym_pause = 0;
274 309
275 /* Take PHY out of isloate mode and reset it. */ 310 /* Take PHY out of isolate mode and reset it. */
276 rc = reset_one_mii_phy(phy, mii_id); 311 if (mii_reset_phy(phy))
277 if (rc)
278 return -ENODEV; 312 return -ENODEV;
279 313
280 /* Read ID and find matching entry */ 314 /* Read ID and find matching entry */
281 id = (phy_read(phy, MII_PHYSID1) << 16 | phy_read(phy, MII_PHYSID2)) 315 id = (phy_read(phy, MII_PHYSID1) << 16) | phy_read(phy, MII_PHYSID2);
282 & 0xfffffff0;
283 for (i = 0; (def = mii_phy_table[i]) != NULL; i++) 316 for (i = 0; (def = mii_phy_table[i]) != NULL; i++)
284 if ((id & def->phy_id_mask) == def->phy_id) 317 if ((id & def->phy_id_mask) == def->phy_id)
285 break; 318 break;
286 /* Should never be NULL (we have a generic entry), but... */ 319 /* Should never be NULL (we have a generic entry), but... */
287 if (def == NULL) 320 if (!def)
288 return -ENODEV; 321 return -ENODEV;
289 322
290 phy->def = def; 323 phy->def = def;
291 324
325 /* Determine PHY features if needed */
326 phy->features = def->features;
327 if (!phy->features) {
328 u16 bmsr = phy_read(phy, MII_BMSR);
329 if (bmsr & BMSR_ANEGCAPABLE)
330 phy->features |= SUPPORTED_Autoneg;
331 if (bmsr & BMSR_10HALF)
332 phy->features |= SUPPORTED_10baseT_Half;
333 if (bmsr & BMSR_10FULL)
334 phy->features |= SUPPORTED_10baseT_Full;
335 if (bmsr & BMSR_100HALF)
336 phy->features |= SUPPORTED_100baseT_Half;
337 if (bmsr & BMSR_100FULL)
338 phy->features |= SUPPORTED_100baseT_Full;
339 if (bmsr & BMSR_ESTATEN) {
340 u16 esr = phy_read(phy, MII_ESTATUS);
341 if (esr & ESTATUS_1000_TFULL)
342 phy->features |= SUPPORTED_1000baseT_Full;
343 if (esr & ESTATUS_1000_THALF)
344 phy->features |= SUPPORTED_1000baseT_Half;
345 }
346 phy->features |= SUPPORTED_MII;
347 }
348
292 /* Setup default advertising */ 349 /* Setup default advertising */
293 phy->advertising = def->features; 350 phy->advertising = phy->features;
294 351
295 return 0; 352 return 0;
296} 353}
diff --git a/drivers/net/ibm_emac/ibm_emac_phy.h b/drivers/net/ibm_emac/ibm_emac_phy.h
index 61afbea96563..a70e0fea54c4 100644
--- a/drivers/net/ibm_emac/ibm_emac_phy.h
+++ b/drivers/net/ibm_emac/ibm_emac_phy.h
@@ -1,65 +1,25 @@
1
2/* 1/*
3 * ibm_emac_phy.h 2 * drivers/net/ibm_emac/ibm_emac_phy.h
4 *
5 * 3 *
6 * Benjamin Herrenschmidt <benh@kernel.crashing.org> 4 * Driver for PowerPC 4xx on-chip ethernet controller, PHY support
7 * February 2003
8 * 5 *
9 * This program is free software; you can redistribute it and/or modify it 6 * Benjamin Herrenschmidt <benh@kernel.crashing.org>
10 * under the terms of the GNU General Public License as published by the 7 * February 2003
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 * 8 *
14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 9 * Minor additions by Eugene Surovegin <ebs@ebshome.net>, 2004
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
20 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * You should have received a copy of the GNU General Public License along
26 * with this program; if not, write to the Free Software Foundation, Inc.,
27 * 675 Mass Ave, Cambridge, MA 02139, USA.
28 * 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.
29 * 15 *
30 * This file basically duplicates sungem_phy.{c,h} with different PHYs 16 * This file basically duplicates sungem_phy.{c,h} with different PHYs
31 * supported. I'm looking into merging that in a single mii layer more 17 * supported. I'm looking into merging that in a single mii layer more
32 * flexible than mii.c 18 * flexible than mii.c
33 */ 19 */
34 20
35#ifndef _IBM_EMAC_PHY_H_ 21#ifndef _IBM_OCP_PHY_H_
36#define _IBM_EMAC_PHY_H_ 22#define _IBM_OCP_PHY_H_
37
38/*
39 * PHY mode settings
40 * Used for multi-mode capable PHYs
41 */
42#define PHY_MODE_NA 0
43#define PHY_MODE_MII 1
44#define PHY_MODE_RMII 2
45#define PHY_MODE_SMII 3
46#define PHY_MODE_RGMII 4
47#define PHY_MODE_TBI 5
48#define PHY_MODE_GMII 6
49#define PHY_MODE_RTBI 7
50#define PHY_MODE_SGMII 8
51
52/*
53 * PHY specific registers/values
54 */
55
56/* CIS8201 */
57#define MII_CIS8201_EPCR 0x17
58#define EPCR_MODE_MASK 0x3000
59#define EPCR_GMII_MODE 0x0000
60#define EPCR_RGMII_MODE 0x1000
61#define EPCR_TBI_MODE 0x2000
62#define EPCR_RTBI_MODE 0x3000
63 23
64struct mii_phy; 24struct mii_phy;
65 25
@@ -77,7 +37,8 @@ struct mii_phy_ops {
77struct mii_phy_def { 37struct mii_phy_def {
78 u32 phy_id; /* Concatenated ID1 << 16 | ID2 */ 38 u32 phy_id; /* Concatenated ID1 << 16 | ID2 */
79 u32 phy_id_mask; /* Significant bits */ 39 u32 phy_id_mask; /* Significant bits */
80 u32 features; /* Ethtool SUPPORTED_* defines */ 40 u32 features; /* Ethtool SUPPORTED_* defines or
41 0 for autodetect */
81 int magic_aneg; /* Autoneg does all speed test for us */ 42 int magic_aneg; /* Autoneg does all speed test for us */
82 const char *name; 43 const char *name;
83 const struct mii_phy_ops *ops; 44 const struct mii_phy_ops *ops;
@@ -86,8 +47,11 @@ struct mii_phy_def {
86/* An instance of a PHY, partially borrowed from mii_if_info */ 47/* An instance of a PHY, partially borrowed from mii_if_info */
87struct mii_phy { 48struct mii_phy {
88 struct mii_phy_def *def; 49 struct mii_phy_def *def;
89 int advertising; 50 u32 advertising; /* Ethtool ADVERTISED_* defines */
90 int mii_id; 51 u32 features; /* Copied from mii_phy_def.features
52 or determined automaticaly */
53 int address; /* PHY address */
54 int mode; /* PHY mode */
91 55
92 /* 1: autoneg enabled, 0: disabled */ 56 /* 1: autoneg enabled, 0: disabled */
93 int autoneg; 57 int autoneg;
@@ -98,40 +62,19 @@ struct mii_phy {
98 int speed; 62 int speed;
99 int duplex; 63 int duplex;
100 int pause; 64 int pause;
101 65 int asym_pause;
102 /* PHY mode - if needed */
103 int mode;
104 66
105 /* Provided by host chip */ 67 /* Provided by host chip */
106 struct net_device *dev; 68 struct net_device *dev;
107 int (*mdio_read) (struct net_device * dev, int mii_id, int reg); 69 int (*mdio_read) (struct net_device * dev, int addr, int reg);
108 void (*mdio_write) (struct net_device * dev, int mii_id, int reg, 70 void (*mdio_write) (struct net_device * dev, int addr, int reg,
109 int val); 71 int val);
110}; 72};
111 73
112/* Pass in a struct mii_phy with dev, mdio_read and mdio_write 74/* Pass in a struct mii_phy with dev, mdio_read and mdio_write
113 * filled, the remaining fields will be filled on return 75 * filled, the remaining fields will be filled on return
114 */ 76 */
115extern int mii_phy_probe(struct mii_phy *phy, int mii_id); 77int mii_phy_probe(struct mii_phy *phy, int address);
116 78int mii_reset_phy(struct mii_phy *phy);
117static inline int __phy_read(struct mii_phy *phy, int id, int reg)
118{
119 return phy->mdio_read(phy->dev, id, reg);
120}
121
122static inline void __phy_write(struct mii_phy *phy, int id, int reg, int val)
123{
124 phy->mdio_write(phy->dev, id, reg, val);
125}
126
127static inline int phy_read(struct mii_phy *phy, int reg)
128{
129 return phy->mdio_read(phy->dev, phy->mii_id, reg);
130}
131
132static inline void phy_write(struct mii_phy *phy, int reg, int val)
133{
134 phy->mdio_write(phy->dev, phy->mii_id, reg, val);
135}
136 79
137#endif /* _IBM_EMAC_PHY_H_ */ 80#endif /* _IBM_OCP_PHY_H_ */
diff --git a/drivers/net/ibm_emac/ibm_emac_rgmii.c b/drivers/net/ibm_emac/ibm_emac_rgmii.c
new file mode 100644
index 000000000000..f0b1ffb2dbbf
--- /dev/null
+++ b/drivers/net/ibm_emac/ibm_emac_rgmii.c
@@ -0,0 +1,201 @@
1/*
2 * drivers/net/ibm_emac/ibm_emac_rgmii.c
3 *
4 * Driver for PowerPC 4xx on-chip ethernet controller, RGMII bridge support.
5 *
6 * Copyright (c) 2004, 2005 Zultys Technologies.
7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
8 *
9 * Based on original work by
10 * Matt Porter <mporter@kernel.crashing.org>
11 * Copyright 2004 MontaVista Software, Inc.
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 *
18 */
19#include <linux/config.h>
20#include <linux/kernel.h>
21#include <linux/ethtool.h>
22#include <asm/io.h>
23
24#include "ibm_emac_core.h"
25#include "ibm_emac_debug.h"
26
27/* RGMIIx_FER */
28#define RGMII_FER_MASK(idx) (0x7 << ((idx) * 4))
29#define RGMII_FER_RTBI(idx) (0x4 << ((idx) * 4))
30#define RGMII_FER_RGMII(idx) (0x5 << ((idx) * 4))
31#define RGMII_FER_TBI(idx) (0x6 << ((idx) * 4))
32#define RGMII_FER_GMII(idx) (0x7 << ((idx) * 4))
33
34/* RGMIIx_SSR */
35#define RGMII_SSR_MASK(idx) (0x7 << ((idx) * 8))
36#define RGMII_SSR_100(idx) (0x2 << ((idx) * 8))
37#define RGMII_SSR_1000(idx) (0x4 << ((idx) * 8))
38
39/* RGMII bridge supports only GMII/TBI and RGMII/RTBI PHYs */
40static inline int rgmii_valid_mode(int phy_mode)
41{
42 return phy_mode == PHY_MODE_GMII ||
43 phy_mode == PHY_MODE_RGMII ||
44 phy_mode == PHY_MODE_TBI ||
45 phy_mode == PHY_MODE_RTBI;
46}
47
48static inline const char *rgmii_mode_name(int mode)
49{
50 switch (mode) {
51 case PHY_MODE_RGMII:
52 return "RGMII";
53 case PHY_MODE_TBI:
54 return "TBI";
55 case PHY_MODE_GMII:
56 return "GMII";
57 case PHY_MODE_RTBI:
58 return "RTBI";
59 default:
60 BUG();
61 }
62}
63
64static inline u32 rgmii_mode_mask(int mode, int input)
65{
66 switch (mode) {
67 case PHY_MODE_RGMII:
68 return RGMII_FER_RGMII(input);
69 case PHY_MODE_TBI:
70 return RGMII_FER_TBI(input);
71 case PHY_MODE_GMII:
72 return RGMII_FER_GMII(input);
73 case PHY_MODE_RTBI:
74 return RGMII_FER_RTBI(input);
75 default:
76 BUG();
77 }
78}
79
80static int __init rgmii_init(struct ocp_device *ocpdev, int input, int mode)
81{
82 struct ibm_ocp_rgmii *dev = ocp_get_drvdata(ocpdev);
83 struct rgmii_regs *p;
84
85 RGMII_DBG("%d: init(%d, %d)" NL, ocpdev->def->index, input, mode);
86
87 if (!dev) {
88 dev = kzalloc(sizeof(struct ibm_ocp_rgmii), GFP_KERNEL);
89 if (!dev) {
90 printk(KERN_ERR
91 "rgmii%d: couldn't allocate device structure!\n",
92 ocpdev->def->index);
93 return -ENOMEM;
94 }
95
96 p = (struct rgmii_regs *)ioremap(ocpdev->def->paddr,
97 sizeof(struct rgmii_regs));
98 if (!p) {
99 printk(KERN_ERR
100 "rgmii%d: could not ioremap device registers!\n",
101 ocpdev->def->index);
102 kfree(dev);
103 return -ENOMEM;
104 }
105
106 dev->base = p;
107 ocp_set_drvdata(ocpdev, dev);
108
109 /* Disable all inputs by default */
110 out_be32(&p->fer, 0);
111 } else
112 p = dev->base;
113
114 /* Enable this input */
115 out_be32(&p->fer, in_be32(&p->fer) | rgmii_mode_mask(mode, input));
116
117 printk(KERN_NOTICE "rgmii%d: input %d in %s mode\n",
118 ocpdev->def->index, input, rgmii_mode_name(mode));
119
120 ++dev->users;
121 return 0;
122}
123
124int __init rgmii_attach(void *emac)
125{
126 struct ocp_enet_private *dev = emac;
127 struct ocp_func_emac_data *emacdata = dev->def->additions;
128
129 /* Check if we need to attach to a RGMII */
130 if (emacdata->rgmii_idx >= 0 && rgmii_valid_mode(emacdata->phy_mode)) {
131 dev->rgmii_input = emacdata->rgmii_mux;
132 dev->rgmii_dev =
133 ocp_find_device(OCP_VENDOR_IBM, OCP_FUNC_RGMII,
134 emacdata->rgmii_idx);
135 if (!dev->rgmii_dev) {
136 printk(KERN_ERR "emac%d: unknown rgmii%d!\n",
137 dev->def->index, emacdata->rgmii_idx);
138 return -ENODEV;
139 }
140 if (rgmii_init
141 (dev->rgmii_dev, dev->rgmii_input, emacdata->phy_mode)) {
142 printk(KERN_ERR
143 "emac%d: rgmii%d initialization failed!\n",
144 dev->def->index, emacdata->rgmii_idx);
145 return -ENODEV;
146 }
147 }
148 return 0;
149}
150
151void rgmii_set_speed(struct ocp_device *ocpdev, int input, int speed)
152{
153 struct ibm_ocp_rgmii *dev = ocp_get_drvdata(ocpdev);
154 u32 ssr = in_be32(&dev->base->ssr) & ~RGMII_SSR_MASK(input);
155
156 RGMII_DBG("%d: speed(%d, %d)" NL, ocpdev->def->index, input, speed);
157
158 if (speed == SPEED_1000)
159 ssr |= RGMII_SSR_1000(input);
160 else if (speed == SPEED_100)
161 ssr |= RGMII_SSR_100(input);
162
163 out_be32(&dev->base->ssr, ssr);
164}
165
166void __exit __rgmii_fini(struct ocp_device *ocpdev, int input)
167{
168 struct ibm_ocp_rgmii *dev = ocp_get_drvdata(ocpdev);
169 BUG_ON(!dev || dev->users == 0);
170
171 RGMII_DBG("%d: fini(%d)" NL, ocpdev->def->index, input);
172
173 /* Disable this input */
174 out_be32(&dev->base->fer,
175 in_be32(&dev->base->fer) & ~RGMII_FER_MASK(input));
176
177 if (!--dev->users) {
178 /* Free everything if this is the last user */
179 ocp_set_drvdata(ocpdev, NULL);
180 iounmap((void *)dev->base);
181 kfree(dev);
182 }
183}
184
185int __rgmii_get_regs_len(struct ocp_device *ocpdev)
186{
187 return sizeof(struct emac_ethtool_regs_subhdr) +
188 sizeof(struct rgmii_regs);
189}
190
191void *rgmii_dump_regs(struct ocp_device *ocpdev, void *buf)
192{
193 struct ibm_ocp_rgmii *dev = ocp_get_drvdata(ocpdev);
194 struct emac_ethtool_regs_subhdr *hdr = buf;
195 struct rgmii_regs *regs = (struct rgmii_regs *)(hdr + 1);
196
197 hdr->version = 0;
198 hdr->index = ocpdev->def->index;
199 memcpy_fromio(regs, dev->base, sizeof(struct rgmii_regs));
200 return regs + 1;
201}
diff --git a/drivers/net/ibm_emac/ibm_emac_rgmii.h b/drivers/net/ibm_emac/ibm_emac_rgmii.h
index 49f188f4ea6e..a1ffb8a44fff 100644
--- a/drivers/net/ibm_emac/ibm_emac_rgmii.h
+++ b/drivers/net/ibm_emac/ibm_emac_rgmii.h
@@ -1,5 +1,7 @@
1/* 1/*
2 * Defines for the IBM RGMII bridge 2 * drivers/net/ibm_emac/ibm_emac_rgmii.c
3 *
4 * Driver for PowerPC 4xx on-chip ethernet controller, RGMII bridge support.
3 * 5 *
4 * Based on ocp_zmii.h/ibm_emac_zmii.h 6 * Based on ocp_zmii.h/ibm_emac_zmii.h
5 * Armin Kuster akuster@mvista.com 7 * Armin Kuster akuster@mvista.com
@@ -7,6 +9,9 @@
7 * Copyright 2004 MontaVista Software, Inc. 9 * Copyright 2004 MontaVista Software, Inc.
8 * Matt Porter <mporter@kernel.crashing.org> 10 * Matt Porter <mporter@kernel.crashing.org>
9 * 11 *
12 * Copyright (c) 2004, 2005 Zultys Technologies.
13 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
14 *
10 * This program is free software; you can redistribute it and/or modify it 15 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the 16 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your 17 * Free Software Foundation; either version 2 of the License, or (at your
@@ -19,47 +24,42 @@
19#include <linux/config.h> 24#include <linux/config.h>
20 25
21/* RGMII bridge */ 26/* RGMII bridge */
22typedef struct rgmii_regs { 27struct rgmii_regs {
23 u32 fer; /* Function enable register */ 28 u32 fer; /* Function enable register */
24 u32 ssr; /* Speed select register */ 29 u32 ssr; /* Speed select register */
25} rgmii_t; 30};
26
27#define RGMII_INPUTS 4
28 31
29/* RGMII device */ 32/* RGMII device */
30struct ibm_ocp_rgmii { 33struct ibm_ocp_rgmii {
31 struct rgmii_regs *base; 34 struct rgmii_regs *base;
32 int mode[RGMII_INPUTS];
33 int users; /* number of EMACs using this RGMII bridge */ 35 int users; /* number of EMACs using this RGMII bridge */
34}; 36};
35 37
36/* Fuctional Enable Reg */ 38#ifdef CONFIG_IBM_EMAC_RGMII
37#define RGMII_FER_MASK(x) (0x00000007 << (4*x)) 39int rgmii_attach(void *emac) __init;
38#define RGMII_RTBI 0x00000004
39#define RGMII_RGMII 0x00000005
40#define RGMII_TBI 0x00000006
41#define RGMII_GMII 0x00000007
42
43/* Speed Selection reg */
44 40
45#define RGMII_SP2_100 0x00000002 41void __rgmii_fini(struct ocp_device *ocpdev, int input) __exit;
46#define RGMII_SP2_1000 0x00000004 42static inline void rgmii_fini(struct ocp_device *ocpdev, int input)
47#define RGMII_SP3_100 0x00000200 43{
48#define RGMII_SP3_1000 0x00000400 44 if (ocpdev)
45 __rgmii_fini(ocpdev, input);
46}
49 47
50#define RGMII_MII2_SPDMASK 0x00000007 48void rgmii_set_speed(struct ocp_device *ocpdev, int input, int speed);
51#define RGMII_MII3_SPDMASK 0x00000700
52 49
53#define RGMII_MII2_100MB RGMII_SP2_100 & ~RGMII_SP2_1000 50int __rgmii_get_regs_len(struct ocp_device *ocpdev);
54#define RGMII_MII2_1000MB RGMII_SP2_1000 & ~RGMII_SP2_100 51static inline int rgmii_get_regs_len(struct ocp_device *ocpdev)
55#define RGMII_MII2_10MB ~(RGMII_SP2_100 | RGMII_SP2_1000) 52{
56#define RGMII_MII3_100MB RGMII_SP3_100 & ~RGMII_SP3_1000 53 return ocpdev ? __rgmii_get_regs_len(ocpdev) : 0;
57#define RGMII_MII3_1000MB RGMII_SP3_1000 & ~RGMII_SP3_100 54}
58#define RGMII_MII3_10MB ~(RGMII_SP3_100 | RGMII_SP3_1000)
59 55
60#define RTBI 0 56void *rgmii_dump_regs(struct ocp_device *ocpdev, void *buf);
61#define RGMII 1 57#else
62#define TBI 2 58# define rgmii_attach(x) 0
63#define GMII 3 59# define rgmii_fini(x,y) ((void)0)
60# define rgmii_set_speed(x,y,z) ((void)0)
61# define rgmii_get_regs_len(x) 0
62# define rgmii_dump_regs(x,buf) (buf)
63#endif /* !CONFIG_IBM_EMAC_RGMII */
64 64
65#endif /* _IBM_EMAC_RGMII_H_ */ 65#endif /* _IBM_EMAC_RGMII_H_ */
diff --git a/drivers/net/ibm_emac/ibm_emac_tah.c b/drivers/net/ibm_emac/ibm_emac_tah.c
new file mode 100644
index 000000000000..af08afc22f9f
--- /dev/null
+++ b/drivers/net/ibm_emac/ibm_emac_tah.c
@@ -0,0 +1,111 @@
1/*
2 * drivers/net/ibm_emac/ibm_emac_tah.c
3 *
4 * Driver for PowerPC 4xx on-chip ethernet controller, TAH support.
5 *
6 * Copyright 2004 MontaVista Software, Inc.
7 * Matt Porter <mporter@kernel.crashing.org>
8 *
9 * Copyright (c) 2005 Eugene Surovegin <ebs@ebshome.net>
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#include <linux/config.h>
17#include <asm/io.h>
18
19#include "ibm_emac_core.h"
20
21static int __init tah_init(struct ocp_device *ocpdev)
22{
23 struct tah_regs *p;
24
25 if (ocp_get_drvdata(ocpdev)) {
26 printk(KERN_ERR "tah%d: already in use!\n", ocpdev->def->index);
27 return -EBUSY;
28 }
29
30 /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
31 p = (struct tah_regs *)ioremap(ocpdev->def->paddr, sizeof(*p));
32 if (!p) {
33 printk(KERN_ERR "tah%d: could not ioremap device registers!\n",
34 ocpdev->def->index);
35 return -ENOMEM;
36 }
37 ocp_set_drvdata(ocpdev, p);
38 __tah_reset(ocpdev);
39
40 return 0;
41}
42
43int __init tah_attach(void *emac)
44{
45 struct ocp_enet_private *dev = emac;
46 struct ocp_func_emac_data *emacdata = dev->def->additions;
47
48 /* Check if we need to attach to a TAH */
49 if (emacdata->tah_idx >= 0) {
50 dev->tah_dev = ocp_find_device(OCP_ANY_ID, OCP_FUNC_TAH,
51 emacdata->tah_idx);
52 if (!dev->tah_dev) {
53 printk(KERN_ERR "emac%d: unknown tah%d!\n",
54 dev->def->index, emacdata->tah_idx);
55 return -ENODEV;
56 }
57 if (tah_init(dev->tah_dev)) {
58 printk(KERN_ERR
59 "emac%d: tah%d initialization failed!\n",
60 dev->def->index, emacdata->tah_idx);
61 return -ENODEV;
62 }
63 }
64 return 0;
65}
66
67void __exit __tah_fini(struct ocp_device *ocpdev)
68{
69 struct tah_regs *p = ocp_get_drvdata(ocpdev);
70 BUG_ON(!p);
71 ocp_set_drvdata(ocpdev, NULL);
72 iounmap((void *)p);
73}
74
75void __tah_reset(struct ocp_device *ocpdev)
76{
77 struct tah_regs *p = ocp_get_drvdata(ocpdev);
78 int n;
79
80 /* Reset TAH */
81 out_be32(&p->mr, TAH_MR_SR);
82 n = 100;
83 while ((in_be32(&p->mr) & TAH_MR_SR) && n)
84 --n;
85
86 if (unlikely(!n))
87 printk(KERN_ERR "tah%d: reset timeout\n", ocpdev->def->index);
88
89 /* 10KB TAH TX FIFO accomodates the max MTU of 9000 */
90 out_be32(&p->mr,
91 TAH_MR_CVR | TAH_MR_ST_768 | TAH_MR_TFS_10KB | TAH_MR_DTFP |
92 TAH_MR_DIG);
93}
94
95int __tah_get_regs_len(struct ocp_device *ocpdev)
96{
97 return sizeof(struct emac_ethtool_regs_subhdr) +
98 sizeof(struct tah_regs);
99}
100
101void *tah_dump_regs(struct ocp_device *ocpdev, void *buf)
102{
103 struct tah_regs *dev = ocp_get_drvdata(ocpdev);
104 struct emac_ethtool_regs_subhdr *hdr = buf;
105 struct tah_regs *regs = (struct tah_regs *)(hdr + 1);
106
107 hdr->version = 0;
108 hdr->index = ocpdev->def->index;
109 memcpy_fromio(regs, dev, sizeof(struct tah_regs));
110 return regs + 1;
111}
diff --git a/drivers/net/ibm_emac/ibm_emac_tah.h b/drivers/net/ibm_emac/ibm_emac_tah.h
index ecfc69805521..9299b5dd7eb1 100644
--- a/drivers/net/ibm_emac/ibm_emac_tah.h
+++ b/drivers/net/ibm_emac/ibm_emac_tah.h
@@ -1,9 +1,13 @@
1/* 1/*
2 * Defines for the IBM TAH 2 * drivers/net/ibm_emac/ibm_emac_tah.h
3 *
4 * Driver for PowerPC 4xx on-chip ethernet controller, TAH support.
3 * 5 *
4 * Copyright 2004 MontaVista Software, Inc. 6 * Copyright 2004 MontaVista Software, Inc.
5 * Matt Porter <mporter@kernel.crashing.org> 7 * Matt Porter <mporter@kernel.crashing.org>
6 * 8 *
9 * Copyright (c) 2005 Eugene Surovegin <ebs@ebshome.net>
10 *
7 * This program is free software; you can redistribute it and/or modify it 11 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the 12 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your 13 * Free Software Foundation; either version 2 of the License, or (at your
@@ -13,36 +17,72 @@
13#ifndef _IBM_EMAC_TAH_H 17#ifndef _IBM_EMAC_TAH_H
14#define _IBM_EMAC_TAH_H 18#define _IBM_EMAC_TAH_H
15 19
20#include <linux/config.h>
21#include <linux/init.h>
22#include <asm/ocp.h>
23
16/* TAH */ 24/* TAH */
17typedef struct tah_regs { 25struct tah_regs {
18 u32 tah_revid; 26 u32 revid;
19 u32 pad[3]; 27 u32 pad[3];
20 u32 tah_mr; 28 u32 mr;
21 u32 tah_ssr0; 29 u32 ssr0;
22 u32 tah_ssr1; 30 u32 ssr1;
23 u32 tah_ssr2; 31 u32 ssr2;
24 u32 tah_ssr3; 32 u32 ssr3;
25 u32 tah_ssr4; 33 u32 ssr4;
26 u32 tah_ssr5; 34 u32 ssr5;
27 u32 tah_tsr; 35 u32 tsr;
28} tah_t; 36};
29 37
30/* TAH engine */ 38/* TAH engine */
31#define TAH_MR_CVR 0x80000000 39#define TAH_MR_CVR 0x80000000
32#define TAH_MR_SR 0x40000000 40#define TAH_MR_SR 0x40000000
33#define TAH_MR_ST_256 0x01000000 41#define TAH_MR_ST_256 0x01000000
34#define TAH_MR_ST_512 0x02000000 42#define TAH_MR_ST_512 0x02000000
35#define TAH_MR_ST_768 0x03000000 43#define TAH_MR_ST_768 0x03000000
36#define TAH_MR_ST_1024 0x04000000 44#define TAH_MR_ST_1024 0x04000000
37#define TAH_MR_ST_1280 0x05000000 45#define TAH_MR_ST_1280 0x05000000
38#define TAH_MR_ST_1536 0x06000000 46#define TAH_MR_ST_1536 0x06000000
39#define TAH_MR_TFS_16KB 0x00000000 47#define TAH_MR_TFS_16KB 0x00000000
40#define TAH_MR_TFS_2KB 0x00200000 48#define TAH_MR_TFS_2KB 0x00200000
41#define TAH_MR_TFS_4KB 0x00400000 49#define TAH_MR_TFS_4KB 0x00400000
42#define TAH_MR_TFS_6KB 0x00600000 50#define TAH_MR_TFS_6KB 0x00600000
43#define TAH_MR_TFS_8KB 0x00800000 51#define TAH_MR_TFS_8KB 0x00800000
44#define TAH_MR_TFS_10KB 0x00a00000 52#define TAH_MR_TFS_10KB 0x00a00000
45#define TAH_MR_DTFP 0x00100000 53#define TAH_MR_DTFP 0x00100000
46#define TAH_MR_DIG 0x00080000 54#define TAH_MR_DIG 0x00080000
55
56#ifdef CONFIG_IBM_EMAC_TAH
57int tah_attach(void *emac) __init;
58
59void __tah_fini(struct ocp_device *ocpdev) __exit;
60static inline void tah_fini(struct ocp_device *ocpdev)
61{
62 if (ocpdev)
63 __tah_fini(ocpdev);
64}
65
66void __tah_reset(struct ocp_device *ocpdev);
67static inline void tah_reset(struct ocp_device *ocpdev)
68{
69 if (ocpdev)
70 __tah_reset(ocpdev);
71}
72
73int __tah_get_regs_len(struct ocp_device *ocpdev);
74static inline int tah_get_regs_len(struct ocp_device *ocpdev)
75{
76 return ocpdev ? __tah_get_regs_len(ocpdev) : 0;
77}
78
79void *tah_dump_regs(struct ocp_device *ocpdev, void *buf);
80#else
81# define tah_attach(x) 0
82# define tah_fini(x) ((void)0)
83# define tah_reset(x) ((void)0)
84# define tah_get_regs_len(x) 0
85# define tah_dump_regs(x,buf) (buf)
86#endif /* !CONFIG_IBM_EMAC_TAH */
47 87
48#endif /* _IBM_EMAC_TAH_H */ 88#endif /* _IBM_EMAC_TAH_H */
diff --git a/drivers/net/ibm_emac/ibm_emac_zmii.c b/drivers/net/ibm_emac/ibm_emac_zmii.c
new file mode 100644
index 000000000000..35c1185079ed
--- /dev/null
+++ b/drivers/net/ibm_emac/ibm_emac_zmii.c
@@ -0,0 +1,255 @@
1/*
2 * drivers/net/ibm_emac/ibm_emac_zmii.c
3 *
4 * Driver for PowerPC 4xx on-chip ethernet controller, ZMII bridge support.
5 *
6 * Copyright (c) 2004, 2005 Zultys Technologies.
7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
8 *
9 * Based on original work by
10 * Armin Kuster <akuster@mvista.com>
11 * Copyright 2001 MontaVista Softare Inc.
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 *
18 */
19#include <linux/config.h>
20#include <linux/kernel.h>
21#include <linux/ethtool.h>
22#include <asm/io.h>
23
24#include "ibm_emac_core.h"
25#include "ibm_emac_debug.h"
26
27/* ZMIIx_FER */
28#define ZMII_FER_MDI(idx) (0x80000000 >> ((idx) * 4))
29#define ZMII_FER_MDI_ALL (ZMII_FER_MDI(0) | ZMII_FER_MDI(1) | \
30 ZMII_FER_MDI(2) | ZMII_FER_MDI(3))
31
32#define ZMII_FER_SMII(idx) (0x40000000 >> ((idx) * 4))
33#define ZMII_FER_RMII(idx) (0x20000000 >> ((idx) * 4))
34#define ZMII_FER_MII(idx) (0x10000000 >> ((idx) * 4))
35
36/* ZMIIx_SSR */
37#define ZMII_SSR_SCI(idx) (0x40000000 >> ((idx) * 4))
38#define ZMII_SSR_FSS(idx) (0x20000000 >> ((idx) * 4))
39#define ZMII_SSR_SP(idx) (0x10000000 >> ((idx) * 4))
40
41/* ZMII only supports MII, RMII and SMII
42 * we also support autodetection for backward compatibility
43 */
44static inline int zmii_valid_mode(int mode)
45{
46 return mode == PHY_MODE_MII ||
47 mode == PHY_MODE_RMII ||
48 mode == PHY_MODE_SMII ||
49 mode == PHY_MODE_NA;
50}
51
52static inline const char *zmii_mode_name(int mode)
53{
54 switch (mode) {
55 case PHY_MODE_MII:
56 return "MII";
57 case PHY_MODE_RMII:
58 return "RMII";
59 case PHY_MODE_SMII:
60 return "SMII";
61 default:
62 BUG();
63 }
64}
65
66static inline u32 zmii_mode_mask(int mode, int input)
67{
68 switch (mode) {
69 case PHY_MODE_MII:
70 return ZMII_FER_MII(input);
71 case PHY_MODE_RMII:
72 return ZMII_FER_RMII(input);
73 case PHY_MODE_SMII:
74 return ZMII_FER_SMII(input);
75 default:
76 return 0;
77 }
78}
79
80static int __init zmii_init(struct ocp_device *ocpdev, int input, int *mode)
81{
82 struct ibm_ocp_zmii *dev = ocp_get_drvdata(ocpdev);
83 struct zmii_regs *p;
84
85 ZMII_DBG("%d: init(%d, %d)" NL, ocpdev->def->index, input, *mode);
86
87 if (!dev) {
88 dev = kzalloc(sizeof(struct ibm_ocp_zmii), GFP_KERNEL);
89 if (!dev) {
90 printk(KERN_ERR
91 "zmii%d: couldn't allocate device structure!\n",
92 ocpdev->def->index);
93 return -ENOMEM;
94 }
95 dev->mode = PHY_MODE_NA;
96
97 p = (struct zmii_regs *)ioremap(ocpdev->def->paddr,
98 sizeof(struct zmii_regs));
99 if (!p) {
100 printk(KERN_ERR
101 "zmii%d: could not ioremap device registers!\n",
102 ocpdev->def->index);
103 kfree(dev);
104 return -ENOMEM;
105 }
106 dev->base = p;
107 ocp_set_drvdata(ocpdev, dev);
108
109 /* We may need FER value for autodetection later */
110 dev->fer_save = in_be32(&p->fer);
111
112 /* Disable all inputs by default */
113 out_be32(&p->fer, 0);
114 } else
115 p = dev->base;
116
117 if (!zmii_valid_mode(*mode)) {
118 /* Probably an EMAC connected to RGMII,
119 * but it still may need ZMII for MDIO
120 */
121 goto out;
122 }
123
124 /* Autodetect ZMII mode if not specified.
125 * This is only for backward compatibility with the old driver.
126 * Please, always specify PHY mode in your board port to avoid
127 * any surprises.
128 */
129 if (dev->mode == PHY_MODE_NA) {
130 if (*mode == PHY_MODE_NA) {
131 u32 r = dev->fer_save;
132
133 ZMII_DBG("%d: autodetecting mode, FER = 0x%08x" NL,
134 ocpdev->def->index, r);
135
136 if (r & (ZMII_FER_MII(0) | ZMII_FER_MII(1)))
137 dev->mode = PHY_MODE_MII;
138 else if (r & (ZMII_FER_RMII(0) | ZMII_FER_RMII(1)))
139 dev->mode = PHY_MODE_RMII;
140 else
141 dev->mode = PHY_MODE_SMII;
142 } else
143 dev->mode = *mode;
144
145 printk(KERN_NOTICE "zmii%d: bridge in %s mode\n",
146 ocpdev->def->index, zmii_mode_name(dev->mode));
147 } else {
148 /* All inputs must use the same mode */
149 if (*mode != PHY_MODE_NA && *mode != dev->mode) {
150 printk(KERN_ERR
151 "zmii%d: invalid mode %d specified for input %d\n",
152 ocpdev->def->index, *mode, input);
153 return -EINVAL;
154 }
155 }
156
157 /* Report back correct PHY mode,
158 * it may be used during PHY initialization.
159 */
160 *mode = dev->mode;
161
162 /* Enable this input */
163 out_be32(&p->fer, in_be32(&p->fer) | zmii_mode_mask(dev->mode, input));
164 out:
165 ++dev->users;
166 return 0;
167}
168
169int __init zmii_attach(void *emac)
170{
171 struct ocp_enet_private *dev = emac;
172 struct ocp_func_emac_data *emacdata = dev->def->additions;
173
174 if (emacdata->zmii_idx >= 0) {
175 dev->zmii_input = emacdata->zmii_mux;
176 dev->zmii_dev =
177 ocp_find_device(OCP_VENDOR_IBM, OCP_FUNC_ZMII,
178 emacdata->zmii_idx);
179 if (!dev->zmii_dev) {
180 printk(KERN_ERR "emac%d: unknown zmii%d!\n",
181 dev->def->index, emacdata->zmii_idx);
182 return -ENODEV;
183 }
184 if (zmii_init
185 (dev->zmii_dev, dev->zmii_input, &emacdata->phy_mode)) {
186 printk(KERN_ERR
187 "emac%d: zmii%d initialization failed!\n",
188 dev->def->index, emacdata->zmii_idx);
189 return -ENODEV;
190 }
191 }
192 return 0;
193}
194
195void __zmii_enable_mdio(struct ocp_device *ocpdev, int input)
196{
197 struct ibm_ocp_zmii *dev = ocp_get_drvdata(ocpdev);
198 u32 fer = in_be32(&dev->base->fer) & ~ZMII_FER_MDI_ALL;
199
200 ZMII_DBG2("%d: mdio(%d)" NL, ocpdev->def->index, input);
201
202 out_be32(&dev->base->fer, fer | ZMII_FER_MDI(input));
203}
204
205void __zmii_set_speed(struct ocp_device *ocpdev, int input, int speed)
206{
207 struct ibm_ocp_zmii *dev = ocp_get_drvdata(ocpdev);
208 u32 ssr = in_be32(&dev->base->ssr);
209
210 ZMII_DBG("%d: speed(%d, %d)" NL, ocpdev->def->index, input, speed);
211
212 if (speed == SPEED_100)
213 ssr |= ZMII_SSR_SP(input);
214 else
215 ssr &= ~ZMII_SSR_SP(input);
216
217 out_be32(&dev->base->ssr, ssr);
218}
219
220void __exit __zmii_fini(struct ocp_device *ocpdev, int input)
221{
222 struct ibm_ocp_zmii *dev = ocp_get_drvdata(ocpdev);
223 BUG_ON(!dev || dev->users == 0);
224
225 ZMII_DBG("%d: fini(%d)" NL, ocpdev->def->index, input);
226
227 /* Disable this input */
228 out_be32(&dev->base->fer,
229 in_be32(&dev->base->fer) & ~zmii_mode_mask(dev->mode, input));
230
231 if (!--dev->users) {
232 /* Free everything if this is the last user */
233 ocp_set_drvdata(ocpdev, NULL);
234 iounmap((void *)dev->base);
235 kfree(dev);
236 }
237}
238
239int __zmii_get_regs_len(struct ocp_device *ocpdev)
240{
241 return sizeof(struct emac_ethtool_regs_subhdr) +
242 sizeof(struct zmii_regs);
243}
244
245void *zmii_dump_regs(struct ocp_device *ocpdev, void *buf)
246{
247 struct ibm_ocp_zmii *dev = ocp_get_drvdata(ocpdev);
248 struct emac_ethtool_regs_subhdr *hdr = buf;
249 struct zmii_regs *regs = (struct zmii_regs *)(hdr + 1);
250
251 hdr->version = 0;
252 hdr->index = ocpdev->def->index;
253 memcpy_fromio(regs, dev->base, sizeof(struct zmii_regs));
254 return regs + 1;
255}
diff --git a/drivers/net/ibm_emac/ibm_emac_zmii.h b/drivers/net/ibm_emac/ibm_emac_zmii.h
index 6f6cd2a39e38..0bb26062c0ad 100644
--- a/drivers/net/ibm_emac/ibm_emac_zmii.h
+++ b/drivers/net/ibm_emac/ibm_emac_zmii.h
@@ -1,23 +1,27 @@
1/* 1/*
2 * ocp_zmii.h 2 * drivers/net/ibm_emac/ibm_emac_zmii.h
3 * 3 *
4 * Defines for the IBM ZMII bridge 4 * Driver for PowerPC 4xx on-chip ethernet controller, ZMII bridge support.
5 * 5 *
6 * Armin Kuster akuster@mvista.com 6 * Copyright (c) 2004, 2005 Zultys Technologies.
7 * Dec, 2001 7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
8 * 8 *
9 * Copyright 2001 MontaVista Softare Inc. 9 * Based on original work by
10 * Armin Kuster <akuster@mvista.com>
11 * Copyright 2001 MontaVista Softare Inc.
10 * 12 *
11 * This program is free software; you can redistribute it and/or modify it 13 * 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 14 * 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 15 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version. 16 * option) any later version.
17 *
15 */ 18 */
16
17#ifndef _IBM_EMAC_ZMII_H_ 19#ifndef _IBM_EMAC_ZMII_H_
18#define _IBM_EMAC_ZMII_H_ 20#define _IBM_EMAC_ZMII_H_
19 21
20#include <linux/config.h> 22#include <linux/config.h>
23#include <linux/init.h>
24#include <asm/ocp.h>
21 25
22/* ZMII bridge registers */ 26/* ZMII bridge registers */
23struct zmii_regs { 27struct zmii_regs {
@@ -26,68 +30,54 @@ struct zmii_regs {
26 u32 smiirs; /* SMII status reg */ 30 u32 smiirs; /* SMII status reg */
27}; 31};
28 32
29#define ZMII_INPUTS 4
30
31/* ZMII device */ 33/* ZMII device */
32struct ibm_ocp_zmii { 34struct ibm_ocp_zmii {
33 struct zmii_regs *base; 35 struct zmii_regs *base;
34 int mode[ZMII_INPUTS]; 36 int mode; /* subset of PHY_MODE_XXXX */
35 int users; /* number of EMACs using this ZMII bridge */ 37 int users; /* number of EMACs using this ZMII bridge */
38 u32 fer_save; /* FER value left by firmware */
36}; 39};
37 40
38/* Fuctional Enable Reg */ 41#ifdef CONFIG_IBM_EMAC_ZMII
39 42int zmii_attach(void *emac) __init;
40#define ZMII_FER_MASK(x) (0xf0000000 >> (4*x))
41
42#define ZMII_MDI0 0x80000000
43#define ZMII_SMII0 0x40000000
44#define ZMII_RMII0 0x20000000
45#define ZMII_MII0 0x10000000
46#define ZMII_MDI1 0x08000000
47#define ZMII_SMII1 0x04000000
48#define ZMII_RMII1 0x02000000
49#define ZMII_MII1 0x01000000
50#define ZMII_MDI2 0x00800000
51#define ZMII_SMII2 0x00400000
52#define ZMII_RMII2 0x00200000
53#define ZMII_MII2 0x00100000
54#define ZMII_MDI3 0x00080000
55#define ZMII_SMII3 0x00040000
56#define ZMII_RMII3 0x00020000
57#define ZMII_MII3 0x00010000
58 43
59/* Speed Selection reg */ 44void __zmii_fini(struct ocp_device *ocpdev, int input) __exit;
45static inline void zmii_fini(struct ocp_device *ocpdev, int input)
46{
47 if (ocpdev)
48 __zmii_fini(ocpdev, input);
49}
60 50
61#define ZMII_SCI0 0x40000000 51void __zmii_enable_mdio(struct ocp_device *ocpdev, int input);
62#define ZMII_FSS0 0x20000000 52static inline void zmii_enable_mdio(struct ocp_device *ocpdev, int input)
63#define ZMII_SP0 0x10000000 53{
64#define ZMII_SCI1 0x04000000 54 if (ocpdev)
65#define ZMII_FSS1 0x02000000 55 __zmii_enable_mdio(ocpdev, input);
66#define ZMII_SP1 0x01000000 56}
67#define ZMII_SCI2 0x00400000
68#define ZMII_FSS2 0x00200000
69#define ZMII_SP2 0x00100000
70#define ZMII_SCI3 0x00040000
71#define ZMII_FSS3 0x00020000
72#define ZMII_SP3 0x00010000
73 57
74#define ZMII_MII0_100MB ZMII_SP0 58void __zmii_set_speed(struct ocp_device *ocpdev, int input, int speed);
75#define ZMII_MII0_10MB ~ZMII_SP0 59static inline void zmii_set_speed(struct ocp_device *ocpdev, int input,
76#define ZMII_MII1_100MB ZMII_SP1 60 int speed)
77#define ZMII_MII1_10MB ~ZMII_SP1 61{
78#define ZMII_MII2_100MB ZMII_SP2 62 if (ocpdev)
79#define ZMII_MII2_10MB ~ZMII_SP2 63 __zmii_set_speed(ocpdev, input, speed);
80#define ZMII_MII3_100MB ZMII_SP3 64}
81#define ZMII_MII3_10MB ~ZMII_SP3
82 65
83/* SMII Status reg */ 66int __zmii_get_regs_len(struct ocp_device *ocpdev);
67static inline int zmii_get_regs_len(struct ocp_device *ocpdev)
68{
69 return ocpdev ? __zmii_get_regs_len(ocpdev) : 0;
70}
84 71
85#define ZMII_STS0 0xFF000000 /* EMAC0 smii status mask */ 72void *zmii_dump_regs(struct ocp_device *ocpdev, void *buf);
86#define ZMII_STS1 0x00FF0000 /* EMAC1 smii status mask */
87 73
88#define SMII 0 74#else
89#define RMII 1 75# define zmii_attach(x) 0
90#define MII 2 76# define zmii_fini(x,y) ((void)0)
91#define MDI 3 77# define zmii_enable_mdio(x,y) ((void)0)
78# define zmii_set_speed(x,y,z) ((void)0)
79# define zmii_get_regs_len(x) 0
80# define zmii_dump_regs(x,buf) (buf)
81#endif /* !CONFIG_IBM_EMAC_ZMII */
92 82
93#endif /* _IBM_EMAC_ZMII_H_ */ 83#endif /* _IBM_EMAC_ZMII_H_ */
diff --git a/drivers/net/ibmveth.c b/drivers/net/ibmveth.c
index cbe9368a4d56..e5246f227c98 100644
--- a/drivers/net/ibmveth.c
+++ b/drivers/net/ibmveth.c
@@ -96,7 +96,7 @@ static void ibmveth_proc_unregister_driver(void);
96static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter); 96static void ibmveth_proc_register_adapter(struct ibmveth_adapter *adapter);
97static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter); 97static void ibmveth_proc_unregister_adapter(struct ibmveth_adapter *adapter);
98static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance, struct pt_regs *regs); 98static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance, struct pt_regs *regs);
99static inline void ibmveth_schedule_replenishing(struct ibmveth_adapter*); 99static inline void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter);
100 100
101#ifdef CONFIG_PROC_FS 101#ifdef CONFIG_PROC_FS
102#define IBMVETH_PROC_DIR "net/ibmveth" 102#define IBMVETH_PROC_DIR "net/ibmveth"
@@ -181,6 +181,7 @@ static int ibmveth_alloc_buffer_pool(struct ibmveth_buff_pool *pool)
181 atomic_set(&pool->available, 0); 181 atomic_set(&pool->available, 0);
182 pool->producer_index = 0; 182 pool->producer_index = 0;
183 pool->consumer_index = 0; 183 pool->consumer_index = 0;
184 pool->active = 0;
184 185
185 return 0; 186 return 0;
186} 187}
@@ -236,7 +237,7 @@ static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, struc
236 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc); 237 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc);
237 238
238 if(lpar_rc != H_Success) { 239 if(lpar_rc != H_Success) {
239 pool->free_map[free_index] = IBM_VETH_INVALID_MAP; 240 pool->free_map[free_index] = index;
240 pool->skbuff[index] = NULL; 241 pool->skbuff[index] = NULL;
241 pool->consumer_index--; 242 pool->consumer_index--;
242 dma_unmap_single(&adapter->vdev->dev, 243 dma_unmap_single(&adapter->vdev->dev,
@@ -255,37 +256,19 @@ static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, struc
255 atomic_add(buffers_added, &(pool->available)); 256 atomic_add(buffers_added, &(pool->available));
256} 257}
257 258
258/* check if replenishing is needed. */ 259/* replenish routine */
259static inline int ibmveth_is_replenishing_needed(struct ibmveth_adapter *adapter)
260{
261 return ((atomic_read(&adapter->rx_buff_pool[0].available) < adapter->rx_buff_pool[0].threshold) ||
262 (atomic_read(&adapter->rx_buff_pool[1].available) < adapter->rx_buff_pool[1].threshold) ||
263 (atomic_read(&adapter->rx_buff_pool[2].available) < adapter->rx_buff_pool[2].threshold));
264}
265
266/* kick the replenish tasklet if we need replenishing and it isn't already running */
267static inline void ibmveth_schedule_replenishing(struct ibmveth_adapter *adapter)
268{
269 if(ibmveth_is_replenishing_needed(adapter) &&
270 (atomic_dec_if_positive(&adapter->not_replenishing) == 0)) {
271 schedule_work(&adapter->replenish_task);
272 }
273}
274
275/* replenish tasklet routine */
276static void ibmveth_replenish_task(struct ibmveth_adapter *adapter) 260static void ibmveth_replenish_task(struct ibmveth_adapter *adapter)
277{ 261{
262 int i;
263
278 adapter->replenish_task_cycles++; 264 adapter->replenish_task_cycles++;
279 265
280 ibmveth_replenish_buffer_pool(adapter, &adapter->rx_buff_pool[0]); 266 for(i = 0; i < IbmVethNumBufferPools; i++)
281 ibmveth_replenish_buffer_pool(adapter, &adapter->rx_buff_pool[1]); 267 if(adapter->rx_buff_pool[i].active)
282 ibmveth_replenish_buffer_pool(adapter, &adapter->rx_buff_pool[2]); 268 ibmveth_replenish_buffer_pool(adapter,
269 &adapter->rx_buff_pool[i]);
283 270
284 adapter->rx_no_buffer = *(u64*)(((char*)adapter->buffer_list_addr) + 4096 - 8); 271 adapter->rx_no_buffer = *(u64*)(((char*)adapter->buffer_list_addr) + 4096 - 8);
285
286 atomic_inc(&adapter->not_replenishing);
287
288 ibmveth_schedule_replenishing(adapter);
289} 272}
290 273
291/* empty and free ana buffer pool - also used to do cleanup in error paths */ 274/* empty and free ana buffer pool - also used to do cleanup in error paths */
@@ -293,10 +276,8 @@ static void ibmveth_free_buffer_pool(struct ibmveth_adapter *adapter, struct ibm
293{ 276{
294 int i; 277 int i;
295 278
296 if(pool->free_map) { 279 kfree(pool->free_map);
297 kfree(pool->free_map); 280 pool->free_map = NULL;
298 pool->free_map = NULL;
299 }
300 281
301 if(pool->skbuff && pool->dma_addr) { 282 if(pool->skbuff && pool->dma_addr) {
302 for(i = 0; i < pool->size; ++i) { 283 for(i = 0; i < pool->size; ++i) {
@@ -321,6 +302,7 @@ static void ibmveth_free_buffer_pool(struct ibmveth_adapter *adapter, struct ibm
321 kfree(pool->skbuff); 302 kfree(pool->skbuff);
322 pool->skbuff = NULL; 303 pool->skbuff = NULL;
323 } 304 }
305 pool->active = 0;
324} 306}
325 307
326/* remove a buffer from a pool */ 308/* remove a buffer from a pool */
@@ -379,6 +361,12 @@ static void ibmveth_rxq_recycle_buffer(struct ibmveth_adapter *adapter)
379 ibmveth_assert(pool < IbmVethNumBufferPools); 361 ibmveth_assert(pool < IbmVethNumBufferPools);
380 ibmveth_assert(index < adapter->rx_buff_pool[pool].size); 362 ibmveth_assert(index < adapter->rx_buff_pool[pool].size);
381 363
364 if(!adapter->rx_buff_pool[pool].active) {
365 ibmveth_rxq_harvest_buffer(adapter);
366 ibmveth_free_buffer_pool(adapter, &adapter->rx_buff_pool[pool]);
367 return;
368 }
369
382 desc.desc = 0; 370 desc.desc = 0;
383 desc.fields.valid = 1; 371 desc.fields.valid = 1;
384 desc.fields.length = adapter->rx_buff_pool[pool].buff_size; 372 desc.fields.length = adapter->rx_buff_pool[pool].buff_size;
@@ -409,6 +397,8 @@ static inline void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter)
409 397
410static void ibmveth_cleanup(struct ibmveth_adapter *adapter) 398static void ibmveth_cleanup(struct ibmveth_adapter *adapter)
411{ 399{
400 int i;
401
412 if(adapter->buffer_list_addr != NULL) { 402 if(adapter->buffer_list_addr != NULL) {
413 if(!dma_mapping_error(adapter->buffer_list_dma)) { 403 if(!dma_mapping_error(adapter->buffer_list_dma)) {
414 dma_unmap_single(&adapter->vdev->dev, 404 dma_unmap_single(&adapter->vdev->dev,
@@ -443,26 +433,24 @@ static void ibmveth_cleanup(struct ibmveth_adapter *adapter)
443 adapter->rx_queue.queue_addr = NULL; 433 adapter->rx_queue.queue_addr = NULL;
444 } 434 }
445 435
446 ibmveth_free_buffer_pool(adapter, &adapter->rx_buff_pool[0]); 436 for(i = 0; i<IbmVethNumBufferPools; i++)
447 ibmveth_free_buffer_pool(adapter, &adapter->rx_buff_pool[1]); 437 ibmveth_free_buffer_pool(adapter, &adapter->rx_buff_pool[i]);
448 ibmveth_free_buffer_pool(adapter, &adapter->rx_buff_pool[2]);
449} 438}
450 439
451static int ibmveth_open(struct net_device *netdev) 440static int ibmveth_open(struct net_device *netdev)
452{ 441{
453 struct ibmveth_adapter *adapter = netdev->priv; 442 struct ibmveth_adapter *adapter = netdev->priv;
454 u64 mac_address = 0; 443 u64 mac_address = 0;
455 int rxq_entries; 444 int rxq_entries = 1;
456 unsigned long lpar_rc; 445 unsigned long lpar_rc;
457 int rc; 446 int rc;
458 union ibmveth_buf_desc rxq_desc; 447 union ibmveth_buf_desc rxq_desc;
448 int i;
459 449
460 ibmveth_debug_printk("open starting\n"); 450 ibmveth_debug_printk("open starting\n");
461 451
462 rxq_entries = 452 for(i = 0; i<IbmVethNumBufferPools; i++)
463 adapter->rx_buff_pool[0].size + 453 rxq_entries += adapter->rx_buff_pool[i].size;
464 adapter->rx_buff_pool[1].size +
465 adapter->rx_buff_pool[2].size + 1;
466 454
467 adapter->buffer_list_addr = (void*) get_zeroed_page(GFP_KERNEL); 455 adapter->buffer_list_addr = (void*) get_zeroed_page(GFP_KERNEL);
468 adapter->filter_list_addr = (void*) get_zeroed_page(GFP_KERNEL); 456 adapter->filter_list_addr = (void*) get_zeroed_page(GFP_KERNEL);
@@ -502,14 +490,8 @@ static int ibmveth_open(struct net_device *netdev)
502 adapter->rx_queue.num_slots = rxq_entries; 490 adapter->rx_queue.num_slots = rxq_entries;
503 adapter->rx_queue.toggle = 1; 491 adapter->rx_queue.toggle = 1;
504 492
505 if(ibmveth_alloc_buffer_pool(&adapter->rx_buff_pool[0]) || 493 /* call change_mtu to init the buffer pools based in initial mtu */
506 ibmveth_alloc_buffer_pool(&adapter->rx_buff_pool[1]) || 494 ibmveth_change_mtu(netdev, netdev->mtu);
507 ibmveth_alloc_buffer_pool(&adapter->rx_buff_pool[2]))
508 {
509 ibmveth_error_printk("unable to allocate buffer pools\n");
510 ibmveth_cleanup(adapter);
511 return -ENOMEM;
512 }
513 495
514 memcpy(&mac_address, netdev->dev_addr, netdev->addr_len); 496 memcpy(&mac_address, netdev->dev_addr, netdev->addr_len);
515 mac_address = mac_address >> 16; 497 mac_address = mac_address >> 16;
@@ -552,10 +534,10 @@ static int ibmveth_open(struct net_device *netdev)
552 return rc; 534 return rc;
553 } 535 }
554 536
555 netif_start_queue(netdev); 537 ibmveth_debug_printk("initial replenish cycle\n");
538 ibmveth_replenish_task(adapter);
556 539
557 ibmveth_debug_printk("scheduling initial replenish cycle\n"); 540 netif_start_queue(netdev);
558 ibmveth_schedule_replenishing(adapter);
559 541
560 ibmveth_debug_printk("open complete\n"); 542 ibmveth_debug_printk("open complete\n");
561 543
@@ -573,9 +555,6 @@ static int ibmveth_close(struct net_device *netdev)
573 555
574 free_irq(netdev->irq, netdev); 556 free_irq(netdev->irq, netdev);
575 557
576 cancel_delayed_work(&adapter->replenish_task);
577 flush_scheduled_work();
578
579 do { 558 do {
580 lpar_rc = h_free_logical_lan(adapter->vdev->unit_address); 559 lpar_rc = h_free_logical_lan(adapter->vdev->unit_address);
581 } while (H_isLongBusy(lpar_rc) || (lpar_rc == H_Busy)); 560 } while (H_isLongBusy(lpar_rc) || (lpar_rc == H_Busy));
@@ -640,12 +619,18 @@ static int ibmveth_start_xmit(struct sk_buff *skb, struct net_device *netdev)
640 unsigned long lpar_rc; 619 unsigned long lpar_rc;
641 int nfrags = 0, curfrag; 620 int nfrags = 0, curfrag;
642 unsigned long correlator; 621 unsigned long correlator;
622 unsigned long flags;
643 unsigned int retry_count; 623 unsigned int retry_count;
624 unsigned int tx_dropped = 0;
625 unsigned int tx_bytes = 0;
626 unsigned int tx_packets = 0;
627 unsigned int tx_send_failed = 0;
628 unsigned int tx_map_failed = 0;
629
644 630
645 if ((skb_shinfo(skb)->nr_frags + 1) > IbmVethMaxSendFrags) { 631 if ((skb_shinfo(skb)->nr_frags + 1) > IbmVethMaxSendFrags) {
646 adapter->stats.tx_dropped++; 632 tx_dropped++;
647 dev_kfree_skb(skb); 633 goto out;
648 return 0;
649 } 634 }
650 635
651 memset(&desc, 0, sizeof(desc)); 636 memset(&desc, 0, sizeof(desc));
@@ -664,10 +649,9 @@ static int ibmveth_start_xmit(struct sk_buff *skb, struct net_device *netdev)
664 649
665 if(dma_mapping_error(desc[0].fields.address)) { 650 if(dma_mapping_error(desc[0].fields.address)) {
666 ibmveth_error_printk("tx: unable to map initial fragment\n"); 651 ibmveth_error_printk("tx: unable to map initial fragment\n");
667 adapter->tx_map_failed++; 652 tx_map_failed++;
668 adapter->stats.tx_dropped++; 653 tx_dropped++;
669 dev_kfree_skb(skb); 654 goto out;
670 return 0;
671 } 655 }
672 656
673 curfrag = nfrags; 657 curfrag = nfrags;
@@ -684,8 +668,8 @@ static int ibmveth_start_xmit(struct sk_buff *skb, struct net_device *netdev)
684 668
685 if(dma_mapping_error(desc[curfrag+1].fields.address)) { 669 if(dma_mapping_error(desc[curfrag+1].fields.address)) {
686 ibmveth_error_printk("tx: unable to map fragment %d\n", curfrag); 670 ibmveth_error_printk("tx: unable to map fragment %d\n", curfrag);
687 adapter->tx_map_failed++; 671 tx_map_failed++;
688 adapter->stats.tx_dropped++; 672 tx_dropped++;
689 /* Free all the mappings we just created */ 673 /* Free all the mappings we just created */
690 while(curfrag < nfrags) { 674 while(curfrag < nfrags) {
691 dma_unmap_single(&adapter->vdev->dev, 675 dma_unmap_single(&adapter->vdev->dev,
@@ -694,8 +678,7 @@ static int ibmveth_start_xmit(struct sk_buff *skb, struct net_device *netdev)
694 DMA_TO_DEVICE); 678 DMA_TO_DEVICE);
695 curfrag++; 679 curfrag++;
696 } 680 }
697 dev_kfree_skb(skb); 681 goto out;
698 return 0;
699 } 682 }
700 } 683 }
701 684
@@ -720,11 +703,12 @@ static int ibmveth_start_xmit(struct sk_buff *skb, struct net_device *netdev)
720 ibmveth_error_printk("tx: desc[%i] valid=%d, len=%d, address=0x%d\n", i, 703 ibmveth_error_printk("tx: desc[%i] valid=%d, len=%d, address=0x%d\n", i,
721 desc[i].fields.valid, desc[i].fields.length, desc[i].fields.address); 704 desc[i].fields.valid, desc[i].fields.length, desc[i].fields.address);
722 } 705 }
723 adapter->tx_send_failed++; 706 tx_send_failed++;
724 adapter->stats.tx_dropped++; 707 tx_dropped++;
725 } else { 708 } else {
726 adapter->stats.tx_packets++; 709 tx_packets++;
727 adapter->stats.tx_bytes += skb->len; 710 tx_bytes += skb->len;
711 netdev->trans_start = jiffies;
728 } 712 }
729 713
730 do { 714 do {
@@ -733,6 +717,14 @@ static int ibmveth_start_xmit(struct sk_buff *skb, struct net_device *netdev)
733 desc[nfrags].fields.length, DMA_TO_DEVICE); 717 desc[nfrags].fields.length, DMA_TO_DEVICE);
734 } while(--nfrags >= 0); 718 } while(--nfrags >= 0);
735 719
720out: spin_lock_irqsave(&adapter->stats_lock, flags);
721 adapter->stats.tx_dropped += tx_dropped;
722 adapter->stats.tx_bytes += tx_bytes;
723 adapter->stats.tx_packets += tx_packets;
724 adapter->tx_send_failed += tx_send_failed;
725 adapter->tx_map_failed += tx_map_failed;
726 spin_unlock_irqrestore(&adapter->stats_lock, flags);
727
736 dev_kfree_skb(skb); 728 dev_kfree_skb(skb);
737 return 0; 729 return 0;
738} 730}
@@ -776,13 +768,14 @@ static int ibmveth_poll(struct net_device *netdev, int *budget)
776 adapter->stats.rx_packets++; 768 adapter->stats.rx_packets++;
777 adapter->stats.rx_bytes += length; 769 adapter->stats.rx_bytes += length;
778 frames_processed++; 770 frames_processed++;
771 netdev->last_rx = jiffies;
779 } 772 }
780 } else { 773 } else {
781 more_work = 0; 774 more_work = 0;
782 } 775 }
783 } while(more_work && (frames_processed < max_frames_to_process)); 776 } while(more_work && (frames_processed < max_frames_to_process));
784 777
785 ibmveth_schedule_replenishing(adapter); 778 ibmveth_replenish_task(adapter);
786 779
787 if(more_work) { 780 if(more_work) {
788 /* more work to do - return that we are not done yet */ 781 /* more work to do - return that we are not done yet */
@@ -883,17 +876,54 @@ static void ibmveth_set_multicast_list(struct net_device *netdev)
883 876
884static int ibmveth_change_mtu(struct net_device *dev, int new_mtu) 877static int ibmveth_change_mtu(struct net_device *dev, int new_mtu)
885{ 878{
886 if ((new_mtu < 68) || (new_mtu > (1<<20))) 879 struct ibmveth_adapter *adapter = dev->priv;
880 int i;
881 int prev_smaller = 1;
882
883 if ((new_mtu < 68) ||
884 (new_mtu > (pool_size[IbmVethNumBufferPools-1]) - IBMVETH_BUFF_OH))
887 return -EINVAL; 885 return -EINVAL;
886
887 for(i = 0; i<IbmVethNumBufferPools; i++) {
888 int activate = 0;
889 if (new_mtu > (pool_size[i] - IBMVETH_BUFF_OH)) {
890 activate = 1;
891 prev_smaller= 1;
892 } else {
893 if (prev_smaller)
894 activate = 1;
895 prev_smaller= 0;
896 }
897
898 if (activate && !adapter->rx_buff_pool[i].active) {
899 struct ibmveth_buff_pool *pool =
900 &adapter->rx_buff_pool[i];
901 if(ibmveth_alloc_buffer_pool(pool)) {
902 ibmveth_error_printk("unable to alloc pool\n");
903 return -ENOMEM;
904 }
905 adapter->rx_buff_pool[i].active = 1;
906 } else if (!activate && adapter->rx_buff_pool[i].active) {
907 adapter->rx_buff_pool[i].active = 0;
908 h_free_logical_lan_buffer(adapter->vdev->unit_address,
909 (u64)pool_size[i]);
910 }
911
912 }
913
914 /* kick the interrupt handler so that the new buffer pools get
915 replenished or deallocated */
916 ibmveth_interrupt(dev->irq, dev, NULL);
917
888 dev->mtu = new_mtu; 918 dev->mtu = new_mtu;
889 return 0; 919 return 0;
890} 920}
891 921
892static int __devinit ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id) 922static int __devinit ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id)
893{ 923{
894 int rc; 924 int rc, i;
895 struct net_device *netdev; 925 struct net_device *netdev;
896 struct ibmveth_adapter *adapter; 926 struct ibmveth_adapter *adapter = NULL;
897 927
898 unsigned char *mac_addr_p; 928 unsigned char *mac_addr_p;
899 unsigned int *mcastFilterSize_p; 929 unsigned int *mcastFilterSize_p;
@@ -960,23 +990,21 @@ static int __devinit ibmveth_probe(struct vio_dev *dev, const struct vio_device_
960 netdev->ethtool_ops = &netdev_ethtool_ops; 990 netdev->ethtool_ops = &netdev_ethtool_ops;
961 netdev->change_mtu = ibmveth_change_mtu; 991 netdev->change_mtu = ibmveth_change_mtu;
962 SET_NETDEV_DEV(netdev, &dev->dev); 992 SET_NETDEV_DEV(netdev, &dev->dev);
993 netdev->features |= NETIF_F_LLTX;
994 spin_lock_init(&adapter->stats_lock);
963 995
964 memcpy(&netdev->dev_addr, &adapter->mac_addr, netdev->addr_len); 996 memcpy(&netdev->dev_addr, &adapter->mac_addr, netdev->addr_len);
965 997
966 ibmveth_init_buffer_pool(&adapter->rx_buff_pool[0], 0, IbmVethPool0DftCnt, IbmVethPool0DftSize); 998 for(i = 0; i<IbmVethNumBufferPools; i++)
967 ibmveth_init_buffer_pool(&adapter->rx_buff_pool[1], 1, IbmVethPool1DftCnt, IbmVethPool1DftSize); 999 ibmveth_init_buffer_pool(&adapter->rx_buff_pool[i], i,
968 ibmveth_init_buffer_pool(&adapter->rx_buff_pool[2], 2, IbmVethPool2DftCnt, IbmVethPool2DftSize); 1000 pool_count[i], pool_size[i]);
969 1001
970 ibmveth_debug_printk("adapter @ 0x%p\n", adapter); 1002 ibmveth_debug_printk("adapter @ 0x%p\n", adapter);
971 1003
972 INIT_WORK(&adapter->replenish_task, (void*)ibmveth_replenish_task, (void*)adapter);
973
974 adapter->buffer_list_dma = DMA_ERROR_CODE; 1004 adapter->buffer_list_dma = DMA_ERROR_CODE;
975 adapter->filter_list_dma = DMA_ERROR_CODE; 1005 adapter->filter_list_dma = DMA_ERROR_CODE;
976 adapter->rx_queue.queue_dma = DMA_ERROR_CODE; 1006 adapter->rx_queue.queue_dma = DMA_ERROR_CODE;
977 1007
978 atomic_set(&adapter->not_replenishing, 1);
979
980 ibmveth_debug_printk("registering netdev...\n"); 1008 ibmveth_debug_printk("registering netdev...\n");
981 1009
982 rc = register_netdev(netdev); 1010 rc = register_netdev(netdev);
diff --git a/drivers/net/ibmveth.h b/drivers/net/ibmveth.h
index 51a470da9686..46919a814fca 100644
--- a/drivers/net/ibmveth.h
+++ b/drivers/net/ibmveth.h
@@ -49,6 +49,7 @@
49#define H_SEND_LOGICAL_LAN 0x120 49#define H_SEND_LOGICAL_LAN 0x120
50#define H_MULTICAST_CTRL 0x130 50#define H_MULTICAST_CTRL 0x130
51#define H_CHANGE_LOGICAL_LAN_MAC 0x14C 51#define H_CHANGE_LOGICAL_LAN_MAC 0x14C
52#define H_FREE_LOGICAL_LAN_BUFFER 0x1D4
52 53
53/* hcall macros */ 54/* hcall macros */
54#define h_register_logical_lan(ua, buflst, rxq, fltlst, mac) \ 55#define h_register_logical_lan(ua, buflst, rxq, fltlst, mac) \
@@ -69,13 +70,15 @@
69#define h_change_logical_lan_mac(ua, mac) \ 70#define h_change_logical_lan_mac(ua, mac) \
70 plpar_hcall_norets(H_CHANGE_LOGICAL_LAN_MAC, ua, mac) 71 plpar_hcall_norets(H_CHANGE_LOGICAL_LAN_MAC, ua, mac)
71 72
72#define IbmVethNumBufferPools 3 73#define h_free_logical_lan_buffer(ua, bufsize) \
73#define IbmVethPool0DftSize (1024 * 2) 74 plpar_hcall_norets(H_FREE_LOGICAL_LAN_BUFFER, ua, bufsize)
74#define IbmVethPool1DftSize (1024 * 4) 75
75#define IbmVethPool2DftSize (1024 * 10) 76#define IbmVethNumBufferPools 5
76#define IbmVethPool0DftCnt 256 77#define IBMVETH_BUFF_OH 22 /* Overhead: 14 ethernet header + 8 opaque handle */
77#define IbmVethPool1DftCnt 256 78
78#define IbmVethPool2DftCnt 256 79/* pool_size should be sorted */
80static int pool_size[] = { 512, 1024 * 2, 1024 * 16, 1024 * 32, 1024 * 64 };
81static int pool_count[] = { 256, 768, 256, 256, 256 };
79 82
80#define IBM_VETH_INVALID_MAP ((u16)0xffff) 83#define IBM_VETH_INVALID_MAP ((u16)0xffff)
81 84
@@ -90,6 +93,7 @@ struct ibmveth_buff_pool {
90 u16 *free_map; 93 u16 *free_map;
91 dma_addr_t *dma_addr; 94 dma_addr_t *dma_addr;
92 struct sk_buff **skbuff; 95 struct sk_buff **skbuff;
96 int active;
93}; 97};
94 98
95struct ibmveth_rx_q { 99struct ibmveth_rx_q {
@@ -114,10 +118,6 @@ struct ibmveth_adapter {
114 dma_addr_t filter_list_dma; 118 dma_addr_t filter_list_dma;
115 struct ibmveth_buff_pool rx_buff_pool[IbmVethNumBufferPools]; 119 struct ibmveth_buff_pool rx_buff_pool[IbmVethNumBufferPools];
116 struct ibmveth_rx_q rx_queue; 120 struct ibmveth_rx_q rx_queue;
117 atomic_t not_replenishing;
118
119 /* helper tasks */
120 struct work_struct replenish_task;
121 121
122 /* adapter specific stats */ 122 /* adapter specific stats */
123 u64 replenish_task_cycles; 123 u64 replenish_task_cycles;
@@ -131,6 +131,7 @@ struct ibmveth_adapter {
131 u64 tx_linearize_failed; 131 u64 tx_linearize_failed;
132 u64 tx_map_failed; 132 u64 tx_map_failed;
133 u64 tx_send_failed; 133 u64 tx_send_failed;
134 spinlock_t stats_lock;
134}; 135};
135 136
136struct ibmveth_buf_desc_fields { 137struct ibmveth_buf_desc_fields {
diff --git a/drivers/net/irda/Kconfig b/drivers/net/irda/Kconfig
index ca5914091d3a..d54156f11e61 100644
--- a/drivers/net/irda/Kconfig
+++ b/drivers/net/irda/Kconfig
@@ -400,5 +400,15 @@ config VIA_FIR
400 To compile it as a module, choose M here: the module will be called 400 To compile it as a module, choose M here: the module will be called
401 via-ircc. 401 via-ircc.
402 402
403config PXA_FICP
404 tristate "Intel PXA2xx Internal FICP"
405 depends on ARCH_PXA && IRDA
406 help
407 Say Y or M here if you want to build support for the PXA2xx
408 built-in IRDA interface which can support both SIR and FIR.
409 This driver relies on platform specific helper routines so
410 available capabilities may vary from one PXA2xx target to
411 another.
412
403endmenu 413endmenu
404 414
diff --git a/drivers/net/irda/Makefile b/drivers/net/irda/Makefile
index 29a8bd812b21..e7a8b7f7f5dd 100644
--- a/drivers/net/irda/Makefile
+++ b/drivers/net/irda/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_SMC_IRCC_FIR) += smsc-ircc2.o
18obj-$(CONFIG_ALI_FIR) += ali-ircc.o 18obj-$(CONFIG_ALI_FIR) += ali-ircc.o
19obj-$(CONFIG_VLSI_FIR) += vlsi_ir.o 19obj-$(CONFIG_VLSI_FIR) += vlsi_ir.o
20obj-$(CONFIG_VIA_FIR) += via-ircc.o 20obj-$(CONFIG_VIA_FIR) += via-ircc.o
21obj-$(CONFIG_PXA_FICP) += pxaficp_ir.o
21# Old dongle drivers for old SIR drivers 22# Old dongle drivers for old SIR drivers
22obj-$(CONFIG_ESI_DONGLE_OLD) += esi.o 23obj-$(CONFIG_ESI_DONGLE_OLD) += esi.o
23obj-$(CONFIG_TEKRAM_DONGLE_OLD) += tekram.o 24obj-$(CONFIG_TEKRAM_DONGLE_OLD) += tekram.o
diff --git a/drivers/net/irda/donauboe.c b/drivers/net/irda/donauboe.c
index 0a08c539c051..0282771b1cbb 100644
--- a/drivers/net/irda/donauboe.c
+++ b/drivers/net/irda/donauboe.c
@@ -1695,11 +1695,9 @@ toshoboe_open (struct pci_dev *pci_dev, const struct pci_device_id *pdid)
1695 1695
1696freebufs: 1696freebufs:
1697 for (i = 0; i < TX_SLOTS; ++i) 1697 for (i = 0; i < TX_SLOTS; ++i)
1698 if (self->tx_bufs[i]) 1698 kfree (self->tx_bufs[i]);
1699 kfree (self->tx_bufs[i]);
1700 for (i = 0; i < RX_SLOTS; ++i) 1699 for (i = 0; i < RX_SLOTS; ++i)
1701 if (self->rx_bufs[i]) 1700 kfree (self->rx_bufs[i]);
1702 kfree (self->rx_bufs[i]);
1703 kfree(self->ringbuf); 1701 kfree(self->ringbuf);
1704 1702
1705freeregion: 1703freeregion:
diff --git a/drivers/net/irda/irda-usb.c b/drivers/net/irda/irda-usb.c
index 6c766fdc51a6..c22c0517883c 100644
--- a/drivers/net/irda/irda-usb.c
+++ b/drivers/net/irda/irda-usb.c
@@ -1168,10 +1168,8 @@ static inline void irda_usb_close(struct irda_usb_cb *self)
1168 unregister_netdev(self->netdev); 1168 unregister_netdev(self->netdev);
1169 1169
1170 /* Remove the speed buffer */ 1170 /* Remove the speed buffer */
1171 if (self->speed_buff != NULL) { 1171 kfree(self->speed_buff);
1172 kfree(self->speed_buff); 1172 self->speed_buff = NULL;
1173 self->speed_buff = NULL;
1174 }
1175} 1173}
1176 1174
1177/********************** USB CONFIG SUBROUTINES **********************/ 1175/********************** USB CONFIG SUBROUTINES **********************/
diff --git a/drivers/net/irda/irport.c b/drivers/net/irda/irport.c
index 5971315f3fa0..3d016a498e1d 100644
--- a/drivers/net/irda/irport.c
+++ b/drivers/net/irda/irport.c
@@ -235,8 +235,7 @@ static int irport_close(struct irport_cb *self)
235 __FUNCTION__, self->io.sir_base); 235 __FUNCTION__, self->io.sir_base);
236 release_region(self->io.sir_base, self->io.sir_ext); 236 release_region(self->io.sir_base, self->io.sir_ext);
237 237
238 if (self->tx_buff.head) 238 kfree(self->tx_buff.head);
239 kfree(self->tx_buff.head);
240 239
241 if (self->rx_buff.skb) 240 if (self->rx_buff.skb)
242 kfree_skb(self->rx_buff.skb); 241 kfree_skb(self->rx_buff.skb);
diff --git a/drivers/net/irda/pxaficp_ir.c b/drivers/net/irda/pxaficp_ir.c
new file mode 100644
index 000000000000..b886b07412a6
--- /dev/null
+++ b/drivers/net/irda/pxaficp_ir.c
@@ -0,0 +1,865 @@
1/*
2 * linux/drivers/net/irda/pxaficp_ir.c
3 *
4 * Based on sa1100_ir.c by Russell King
5 *
6 * Changes copyright (C) 2003-2005 MontaVista Software, Inc.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * Infra-red driver (SIR/FIR) for the PXA2xx embedded microprocessor
13 *
14 */
15#include <linux/config.h>
16#include <linux/module.h>
17#include <linux/types.h>
18#include <linux/init.h>
19#include <linux/errno.h>
20#include <linux/netdevice.h>
21#include <linux/slab.h>
22#include <linux/rtnetlink.h>
23#include <linux/interrupt.h>
24#include <linux/dma-mapping.h>
25#include <linux/pm.h>
26
27#include <net/irda/irda.h>
28#include <net/irda/irmod.h>
29#include <net/irda/wrapper.h>
30#include <net/irda/irda_device.h>
31
32#include <asm/irq.h>
33#include <asm/dma.h>
34#include <asm/delay.h>
35#include <asm/hardware.h>
36#include <asm/arch/irda.h>
37#include <asm/arch/pxa-regs.h>
38
39#ifdef CONFIG_MACH_MAINSTONE
40#include <asm/arch/mainstone.h>
41#endif
42
43#define IrSR_RXPL_NEG_IS_ZERO (1<<4)
44#define IrSR_RXPL_POS_IS_ZERO 0x0
45#define IrSR_TXPL_NEG_IS_ZERO (1<<3)
46#define IrSR_TXPL_POS_IS_ZERO 0x0
47#define IrSR_XMODE_PULSE_1_6 (1<<2)
48#define IrSR_XMODE_PULSE_3_16 0x0
49#define IrSR_RCVEIR_IR_MODE (1<<1)
50#define IrSR_RCVEIR_UART_MODE 0x0
51#define IrSR_XMITIR_IR_MODE (1<<0)
52#define IrSR_XMITIR_UART_MODE 0x0
53
54#define IrSR_IR_RECEIVE_ON (\
55 IrSR_RXPL_NEG_IS_ZERO | \
56 IrSR_TXPL_POS_IS_ZERO | \
57 IrSR_XMODE_PULSE_3_16 | \
58 IrSR_RCVEIR_IR_MODE | \
59 IrSR_XMITIR_UART_MODE)
60
61#define IrSR_IR_TRANSMIT_ON (\
62 IrSR_RXPL_NEG_IS_ZERO | \
63 IrSR_TXPL_POS_IS_ZERO | \
64 IrSR_XMODE_PULSE_3_16 | \
65 IrSR_RCVEIR_UART_MODE | \
66 IrSR_XMITIR_IR_MODE)
67
68struct pxa_irda {
69 int speed;
70 int newspeed;
71 unsigned long last_oscr;
72
73 unsigned char *dma_rx_buff;
74 unsigned char *dma_tx_buff;
75 dma_addr_t dma_rx_buff_phy;
76 dma_addr_t dma_tx_buff_phy;
77 unsigned int dma_tx_buff_len;
78 int txdma;
79 int rxdma;
80
81 struct net_device_stats stats;
82 struct irlap_cb *irlap;
83 struct qos_info qos;
84
85 iobuff_t tx_buff;
86 iobuff_t rx_buff;
87
88 struct device *dev;
89 struct pxaficp_platform_data *pdata;
90};
91
92
93#define IS_FIR(si) ((si)->speed >= 4000000)
94#define IRDA_FRAME_SIZE_LIMIT 2047
95
96inline static void pxa_irda_fir_dma_rx_start(struct pxa_irda *si)
97{
98 DCSR(si->rxdma) = DCSR_NODESC;
99 DSADR(si->rxdma) = __PREG(ICDR);
100 DTADR(si->rxdma) = si->dma_rx_buff_phy;
101 DCMD(si->rxdma) = DCMD_INCTRGADDR | DCMD_FLOWSRC | DCMD_WIDTH1 | DCMD_BURST32 | IRDA_FRAME_SIZE_LIMIT;
102 DCSR(si->rxdma) |= DCSR_RUN;
103}
104
105inline static void pxa_irda_fir_dma_tx_start(struct pxa_irda *si)
106{
107 DCSR(si->txdma) = DCSR_NODESC;
108 DSADR(si->txdma) = si->dma_tx_buff_phy;
109 DTADR(si->txdma) = __PREG(ICDR);
110 DCMD(si->txdma) = DCMD_INCSRCADDR | DCMD_FLOWTRG | DCMD_ENDIRQEN | DCMD_WIDTH1 | DCMD_BURST32 | si->dma_tx_buff_len;
111 DCSR(si->txdma) |= DCSR_RUN;
112}
113
114/*
115 * Set the IrDA communications speed.
116 */
117static int pxa_irda_set_speed(struct pxa_irda *si, int speed)
118{
119 unsigned long flags;
120 unsigned int divisor;
121
122 switch (speed) {
123 case 9600: case 19200: case 38400:
124 case 57600: case 115200:
125
126 /* refer to PXA250/210 Developer's Manual 10-7 */
127 /* BaudRate = 14.7456 MHz / (16*Divisor) */
128 divisor = 14745600 / (16 * speed);
129
130 local_irq_save(flags);
131
132 if (IS_FIR(si)) {
133 /* stop RX DMA */
134 DCSR(si->rxdma) &= ~DCSR_RUN;
135 /* disable FICP */
136 ICCR0 = 0;
137 pxa_set_cken(CKEN13_FICP, 0);
138
139 /* set board transceiver to SIR mode */
140 si->pdata->transceiver_mode(si->dev, IR_SIRMODE);
141
142 /* configure GPIO46/47 */
143 pxa_gpio_mode(GPIO46_STRXD_MD);
144 pxa_gpio_mode(GPIO47_STTXD_MD);
145
146 /* enable the STUART clock */
147 pxa_set_cken(CKEN5_STUART, 1);
148 }
149
150 /* disable STUART first */
151 STIER = 0;
152
153 /* access DLL & DLH */
154 STLCR |= LCR_DLAB;
155 STDLL = divisor & 0xff;
156 STDLH = divisor >> 8;
157 STLCR &= ~LCR_DLAB;
158
159 si->speed = speed;
160 STISR = IrSR_IR_RECEIVE_ON | IrSR_XMODE_PULSE_1_6;
161 STIER = IER_UUE | IER_RLSE | IER_RAVIE | IER_RTIOE;
162
163 local_irq_restore(flags);
164 break;
165
166 case 4000000:
167 local_irq_save(flags);
168
169 /* disable STUART */
170 STIER = 0;
171 STISR = 0;
172 pxa_set_cken(CKEN5_STUART, 0);
173
174 /* disable FICP first */
175 ICCR0 = 0;
176
177 /* set board transceiver to FIR mode */
178 si->pdata->transceiver_mode(si->dev, IR_FIRMODE);
179
180 /* configure GPIO46/47 */
181 pxa_gpio_mode(GPIO46_ICPRXD_MD);
182 pxa_gpio_mode(GPIO47_ICPTXD_MD);
183
184 /* enable the FICP clock */
185 pxa_set_cken(CKEN13_FICP, 1);
186
187 si->speed = speed;
188 pxa_irda_fir_dma_rx_start(si);
189 ICCR0 = ICCR0_ITR | ICCR0_RXE;
190
191 local_irq_restore(flags);
192 break;
193
194 default:
195 return -EINVAL;
196 }
197
198 return 0;
199}
200
201/* SIR interrupt service routine. */
202static irqreturn_t pxa_irda_sir_irq(int irq, void *dev_id, struct pt_regs *regs)
203{
204 struct net_device *dev = dev_id;
205 struct pxa_irda *si = netdev_priv(dev);
206 int iir, lsr, data;
207
208 iir = STIIR;
209
210 switch (iir & 0x0F) {
211 case 0x06: /* Receiver Line Status */
212 lsr = STLSR;
213 while (lsr & LSR_FIFOE) {
214 data = STRBR;
215 if (lsr & (LSR_OE | LSR_PE | LSR_FE | LSR_BI)) {
216 printk(KERN_DEBUG "pxa_ir: sir receiving error\n");
217 si->stats.rx_errors++;
218 if (lsr & LSR_FE)
219 si->stats.rx_frame_errors++;
220 if (lsr & LSR_OE)
221 si->stats.rx_fifo_errors++;
222 } else {
223 si->stats.rx_bytes++;
224 async_unwrap_char(dev, &si->stats, &si->rx_buff, data);
225 }
226 lsr = STLSR;
227 }
228 dev->last_rx = jiffies;
229 si->last_oscr = OSCR;
230 break;
231
232 case 0x04: /* Received Data Available */
233 /* forth through */
234
235 case 0x0C: /* Character Timeout Indication */
236 do {
237 si->stats.rx_bytes++;
238 async_unwrap_char(dev, &si->stats, &si->rx_buff, STRBR);
239 } while (STLSR & LSR_DR);
240 dev->last_rx = jiffies;
241 si->last_oscr = OSCR;
242 break;
243
244 case 0x02: /* Transmit FIFO Data Request */
245 while ((si->tx_buff.len) && (STLSR & LSR_TDRQ)) {
246 STTHR = *si->tx_buff.data++;
247 si->tx_buff.len -= 1;
248 }
249
250 if (si->tx_buff.len == 0) {
251 si->stats.tx_packets++;
252 si->stats.tx_bytes += si->tx_buff.data -
253 si->tx_buff.head;
254
255 /* We need to ensure that the transmitter has finished. */
256 while ((STLSR & LSR_TEMT) == 0)
257 cpu_relax();
258 si->last_oscr = OSCR;
259
260 /*
261 * Ok, we've finished transmitting. Now enable
262 * the receiver. Sometimes we get a receive IRQ
263 * immediately after a transmit...
264 */
265 if (si->newspeed) {
266 pxa_irda_set_speed(si, si->newspeed);
267 si->newspeed = 0;
268 } else {
269 /* enable IR Receiver, disable IR Transmitter */
270 STISR = IrSR_IR_RECEIVE_ON | IrSR_XMODE_PULSE_1_6;
271 /* enable STUART and receive interrupts */
272 STIER = IER_UUE | IER_RLSE | IER_RAVIE | IER_RTIOE;
273 }
274 /* I'm hungry! */
275 netif_wake_queue(dev);
276 }
277 break;
278 }
279
280 return IRQ_HANDLED;
281}
282
283/* FIR Receive DMA interrupt handler */
284static void pxa_irda_fir_dma_rx_irq(int channel, void *data, struct pt_regs *regs)
285{
286 int dcsr = DCSR(channel);
287
288 DCSR(channel) = dcsr & ~DCSR_RUN;
289
290 printk(KERN_DEBUG "pxa_ir: fir rx dma bus error %#x\n", dcsr);
291}
292
293/* FIR Transmit DMA interrupt handler */
294static void pxa_irda_fir_dma_tx_irq(int channel, void *data, struct pt_regs *regs)
295{
296 struct net_device *dev = data;
297 struct pxa_irda *si = netdev_priv(dev);
298 int dcsr;
299
300 dcsr = DCSR(channel);
301 DCSR(channel) = dcsr & ~DCSR_RUN;
302
303 if (dcsr & DCSR_ENDINTR) {
304 si->stats.tx_packets++;
305 si->stats.tx_bytes += si->dma_tx_buff_len;
306 } else {
307 si->stats.tx_errors++;
308 }
309
310 while (ICSR1 & ICSR1_TBY)
311 cpu_relax();
312 si->last_oscr = OSCR;
313
314 /*
315 * HACK: It looks like the TBY bit is dropped too soon.
316 * Without this delay things break.
317 */
318 udelay(120);
319
320 if (si->newspeed) {
321 pxa_irda_set_speed(si, si->newspeed);
322 si->newspeed = 0;
323 } else {
324 ICCR0 = 0;
325 pxa_irda_fir_dma_rx_start(si);
326 ICCR0 = ICCR0_ITR | ICCR0_RXE;
327 }
328 netif_wake_queue(dev);
329}
330
331/* EIF(Error in FIFO/End in Frame) handler for FIR */
332static void pxa_irda_fir_irq_eif(struct pxa_irda *si, struct net_device *dev)
333{
334 unsigned int len, stat, data;
335
336 /* Get the current data position. */
337 len = DTADR(si->rxdma) - si->dma_rx_buff_phy;
338
339 do {
340 /* Read Status, and then Data. */
341 stat = ICSR1;
342 rmb();
343 data = ICDR;
344
345 if (stat & (ICSR1_CRE | ICSR1_ROR)) {
346 si->stats.rx_errors++;
347 if (stat & ICSR1_CRE) {
348 printk(KERN_DEBUG "pxa_ir: fir receive CRC error\n");
349 si->stats.rx_crc_errors++;
350 }
351 if (stat & ICSR1_ROR) {
352 printk(KERN_DEBUG "pxa_ir: fir receive overrun\n");
353 si->stats.rx_frame_errors++;
354 }
355 } else {
356 si->dma_rx_buff[len++] = data;
357 }
358 /* If we hit the end of frame, there's no point in continuing. */
359 if (stat & ICSR1_EOF)
360 break;
361 } while (ICSR0 & ICSR0_EIF);
362
363 if (stat & ICSR1_EOF) {
364 /* end of frame. */
365 struct sk_buff *skb = alloc_skb(len+1,GFP_ATOMIC);
366 if (!skb) {
367 printk(KERN_ERR "pxa_ir: fir out of memory for receive skb\n");
368 si->stats.rx_dropped++;
369 return;
370 }
371
372 /* Align IP header to 20 bytes */
373 skb_reserve(skb, 1);
374 memcpy(skb->data, si->dma_rx_buff, len);
375 skb_put(skb, len);
376
377 /* Feed it to IrLAP */
378 skb->dev = dev;
379 skb->mac.raw = skb->data;
380 skb->protocol = htons(ETH_P_IRDA);
381 netif_rx(skb);
382
383 si->stats.rx_packets++;
384 si->stats.rx_bytes += len;
385
386 dev->last_rx = jiffies;
387 }
388}
389
390/* FIR interrupt handler */
391static irqreturn_t pxa_irda_fir_irq(int irq, void *dev_id, struct pt_regs *regs)
392{
393 struct net_device *dev = dev_id;
394 struct pxa_irda *si = netdev_priv(dev);
395 int icsr0;
396
397 /* stop RX DMA */
398 DCSR(si->rxdma) &= ~DCSR_RUN;
399 si->last_oscr = OSCR;
400 icsr0 = ICSR0;
401
402 if (icsr0 & (ICSR0_FRE | ICSR0_RAB)) {
403 if (icsr0 & ICSR0_FRE) {
404 printk(KERN_DEBUG "pxa_ir: fir receive frame error\n");
405 si->stats.rx_frame_errors++;
406 } else {
407 printk(KERN_DEBUG "pxa_ir: fir receive abort\n");
408 si->stats.rx_errors++;
409 }
410 ICSR0 = icsr0 & (ICSR0_FRE | ICSR0_RAB);
411 }
412
413 if (icsr0 & ICSR0_EIF) {
414 /* An error in FIFO occured, or there is a end of frame */
415 pxa_irda_fir_irq_eif(si, dev);
416 }
417
418 ICCR0 = 0;
419 pxa_irda_fir_dma_rx_start(si);
420 ICCR0 = ICCR0_ITR | ICCR0_RXE;
421
422 return IRQ_HANDLED;
423}
424
425/* hard_xmit interface of irda device */
426static int pxa_irda_hard_xmit(struct sk_buff *skb, struct net_device *dev)
427{
428 struct pxa_irda *si = netdev_priv(dev);
429 int speed = irda_get_next_speed(skb);
430
431 /*
432 * Does this packet contain a request to change the interface
433 * speed? If so, remember it until we complete the transmission
434 * of this frame.
435 */
436 if (speed != si->speed && speed != -1)
437 si->newspeed = speed;
438
439 /*
440 * If this is an empty frame, we can bypass a lot.
441 */
442 if (skb->len == 0) {
443 if (si->newspeed) {
444 si->newspeed = 0;
445 pxa_irda_set_speed(si, speed);
446 }
447 dev_kfree_skb(skb);
448 return 0;
449 }
450
451 netif_stop_queue(dev);
452
453 if (!IS_FIR(si)) {
454 si->tx_buff.data = si->tx_buff.head;
455 si->tx_buff.len = async_wrap_skb(skb, si->tx_buff.data, si->tx_buff.truesize);
456
457 /* Disable STUART interrupts and switch to transmit mode. */
458 STIER = 0;
459 STISR = IrSR_IR_TRANSMIT_ON | IrSR_XMODE_PULSE_1_6;
460
461 /* enable STUART and transmit interrupts */
462 STIER = IER_UUE | IER_TIE;
463 } else {
464 unsigned long mtt = irda_get_mtt(skb);
465
466 si->dma_tx_buff_len = skb->len;
467 memcpy(si->dma_tx_buff, skb->data, skb->len);
468
469 if (mtt)
470 while ((unsigned)(OSCR - si->last_oscr)/4 < mtt)
471 cpu_relax();
472
473 /* stop RX DMA, disable FICP */
474 DCSR(si->rxdma) &= ~DCSR_RUN;
475 ICCR0 = 0;
476
477 pxa_irda_fir_dma_tx_start(si);
478 ICCR0 = ICCR0_ITR | ICCR0_TXE;
479 }
480
481 dev_kfree_skb(skb);
482 dev->trans_start = jiffies;
483 return 0;
484}
485
486static int pxa_irda_ioctl(struct net_device *dev, struct ifreq *ifreq, int cmd)
487{
488 struct if_irda_req *rq = (struct if_irda_req *)ifreq;
489 struct pxa_irda *si = netdev_priv(dev);
490 int ret;
491
492 switch (cmd) {
493 case SIOCSBANDWIDTH:
494 ret = -EPERM;
495 if (capable(CAP_NET_ADMIN)) {
496 /*
497 * We are unable to set the speed if the
498 * device is not running.
499 */
500 if (netif_running(dev)) {
501 ret = pxa_irda_set_speed(si,
502 rq->ifr_baudrate);
503 } else {
504 printk(KERN_INFO "pxa_ir: SIOCSBANDWIDTH: !netif_running\n");
505 ret = 0;
506 }
507 }
508 break;
509
510 case SIOCSMEDIABUSY:
511 ret = -EPERM;
512 if (capable(CAP_NET_ADMIN)) {
513 irda_device_set_media_busy(dev, TRUE);
514 ret = 0;
515 }
516 break;
517
518 case SIOCGRECEIVING:
519 ret = 0;
520 rq->ifr_receiving = IS_FIR(si) ? 0
521 : si->rx_buff.state != OUTSIDE_FRAME;
522 break;
523
524 default:
525 ret = -EOPNOTSUPP;
526 break;
527 }
528
529 return ret;
530}
531
532static struct net_device_stats *pxa_irda_stats(struct net_device *dev)
533{
534 struct pxa_irda *si = netdev_priv(dev);
535 return &si->stats;
536}
537
538static void pxa_irda_startup(struct pxa_irda *si)
539{
540 /* Disable STUART interrupts */
541 STIER = 0;
542 /* enable STUART interrupt to the processor */
543 STMCR = MCR_OUT2;
544 /* configure SIR frame format: StartBit - Data 7 ... Data 0 - Stop Bit */
545 STLCR = LCR_WLS0 | LCR_WLS1;
546 /* enable FIFO, we use FIFO to improve performance */
547 STFCR = FCR_TRFIFOE | FCR_ITL_32;
548
549 /* disable FICP */
550 ICCR0 = 0;
551 /* configure FICP ICCR2 */
552 ICCR2 = ICCR2_TXP | ICCR2_TRIG_32;
553
554 /* configure DMAC */
555 DRCMR17 = si->rxdma | DRCMR_MAPVLD;
556 DRCMR18 = si->txdma | DRCMR_MAPVLD;
557
558 /* force SIR reinitialization */
559 si->speed = 4000000;
560 pxa_irda_set_speed(si, 9600);
561
562 printk(KERN_DEBUG "pxa_ir: irda startup\n");
563}
564
565static void pxa_irda_shutdown(struct pxa_irda *si)
566{
567 unsigned long flags;
568
569 local_irq_save(flags);
570
571 /* disable STUART and interrupt */
572 STIER = 0;
573 /* disable STUART SIR mode */
574 STISR = 0;
575 /* disable the STUART clock */
576 pxa_set_cken(CKEN5_STUART, 0);
577
578 /* disable DMA */
579 DCSR(si->txdma) &= ~DCSR_RUN;
580 DCSR(si->rxdma) &= ~DCSR_RUN;
581 /* disable FICP */
582 ICCR0 = 0;
583 /* disable the FICP clock */
584 pxa_set_cken(CKEN13_FICP, 0);
585
586 DRCMR17 = 0;
587 DRCMR18 = 0;
588
589 local_irq_restore(flags);
590
591 /* power off board transceiver */
592 si->pdata->transceiver_mode(si->dev, IR_OFF);
593
594 printk(KERN_DEBUG "pxa_ir: irda shutdown\n");
595}
596
597static int pxa_irda_start(struct net_device *dev)
598{
599 struct pxa_irda *si = netdev_priv(dev);
600 int err;
601
602 si->speed = 9600;
603
604 err = request_irq(IRQ_STUART, pxa_irda_sir_irq, 0, dev->name, dev);
605 if (err)
606 goto err_irq1;
607
608 err = request_irq(IRQ_ICP, pxa_irda_fir_irq, 0, dev->name, dev);
609 if (err)
610 goto err_irq2;
611
612 /*
613 * The interrupt must remain disabled for now.
614 */
615 disable_irq(IRQ_STUART);
616 disable_irq(IRQ_ICP);
617
618 err = -EBUSY;
619 si->rxdma = pxa_request_dma("FICP_RX",DMA_PRIO_LOW, pxa_irda_fir_dma_rx_irq, dev);
620 if (si->rxdma < 0)
621 goto err_rx_dma;
622
623 si->txdma = pxa_request_dma("FICP_TX",DMA_PRIO_LOW, pxa_irda_fir_dma_tx_irq, dev);
624 if (si->txdma < 0)
625 goto err_tx_dma;
626
627 err = -ENOMEM;
628 si->dma_rx_buff = dma_alloc_coherent(si->dev, IRDA_FRAME_SIZE_LIMIT,
629 &si->dma_rx_buff_phy, GFP_KERNEL );
630 if (!si->dma_rx_buff)
631 goto err_dma_rx_buff;
632
633 si->dma_tx_buff = dma_alloc_coherent(si->dev, IRDA_FRAME_SIZE_LIMIT,
634 &si->dma_tx_buff_phy, GFP_KERNEL );
635 if (!si->dma_tx_buff)
636 goto err_dma_tx_buff;
637
638 /* Setup the serial port for the initial speed. */
639 pxa_irda_startup(si);
640
641 /*
642 * Open a new IrLAP layer instance.
643 */
644 si->irlap = irlap_open(dev, &si->qos, "pxa");
645 err = -ENOMEM;
646 if (!si->irlap)
647 goto err_irlap;
648
649 /*
650 * Now enable the interrupt and start the queue
651 */
652 enable_irq(IRQ_STUART);
653 enable_irq(IRQ_ICP);
654 netif_start_queue(dev);
655
656 printk(KERN_DEBUG "pxa_ir: irda driver opened\n");
657
658 return 0;
659
660err_irlap:
661 pxa_irda_shutdown(si);
662 dma_free_coherent(si->dev, IRDA_FRAME_SIZE_LIMIT, si->dma_tx_buff, si->dma_tx_buff_phy);
663err_dma_tx_buff:
664 dma_free_coherent(si->dev, IRDA_FRAME_SIZE_LIMIT, si->dma_rx_buff, si->dma_rx_buff_phy);
665err_dma_rx_buff:
666 pxa_free_dma(si->txdma);
667err_tx_dma:
668 pxa_free_dma(si->rxdma);
669err_rx_dma:
670 free_irq(IRQ_ICP, dev);
671err_irq2:
672 free_irq(IRQ_STUART, dev);
673err_irq1:
674
675 return err;
676}
677
678static int pxa_irda_stop(struct net_device *dev)
679{
680 struct pxa_irda *si = netdev_priv(dev);
681
682 netif_stop_queue(dev);
683
684 pxa_irda_shutdown(si);
685
686 /* Stop IrLAP */
687 if (si->irlap) {
688 irlap_close(si->irlap);
689 si->irlap = NULL;
690 }
691
692 free_irq(IRQ_STUART, dev);
693 free_irq(IRQ_ICP, dev);
694
695 pxa_free_dma(si->rxdma);
696 pxa_free_dma(si->txdma);
697
698 if (si->dma_rx_buff)
699 dma_free_coherent(si->dev, IRDA_FRAME_SIZE_LIMIT, si->dma_tx_buff, si->dma_tx_buff_phy);
700 if (si->dma_tx_buff)
701 dma_free_coherent(si->dev, IRDA_FRAME_SIZE_LIMIT, si->dma_rx_buff, si->dma_rx_buff_phy);
702
703 printk(KERN_DEBUG "pxa_ir: irda driver closed\n");
704 return 0;
705}
706
707static int pxa_irda_suspend(struct device *_dev, pm_message_t state)
708{
709 struct net_device *dev = dev_get_drvdata(_dev);
710 struct pxa_irda *si;
711
712 if (dev && netif_running(dev)) {
713 si = netdev_priv(dev);
714 netif_device_detach(dev);
715 pxa_irda_shutdown(si);
716 }
717
718 return 0;
719}
720
721static int pxa_irda_resume(struct device *_dev)
722{
723 struct net_device *dev = dev_get_drvdata(_dev);
724 struct pxa_irda *si;
725
726 if (dev && netif_running(dev)) {
727 si = netdev_priv(dev);
728 pxa_irda_startup(si);
729 netif_device_attach(dev);
730 netif_wake_queue(dev);
731 }
732
733 return 0;
734}
735
736
737static int pxa_irda_init_iobuf(iobuff_t *io, int size)
738{
739 io->head = kmalloc(size, GFP_KERNEL | GFP_DMA);
740 if (io->head != NULL) {
741 io->truesize = size;
742 io->in_frame = FALSE;
743 io->state = OUTSIDE_FRAME;
744 io->data = io->head;
745 }
746 return io->head ? 0 : -ENOMEM;
747}
748
749static int pxa_irda_probe(struct device *_dev)
750{
751 struct platform_device *pdev = to_platform_device(_dev);
752 struct net_device *dev;
753 struct pxa_irda *si;
754 unsigned int baudrate_mask;
755 int err;
756
757 if (!pdev->dev.platform_data)
758 return -ENODEV;
759
760 err = request_mem_region(__PREG(STUART), 0x24, "IrDA") ? 0 : -EBUSY;
761 if (err)
762 goto err_mem_1;
763
764 err = request_mem_region(__PREG(FICP), 0x1c, "IrDA") ? 0 : -EBUSY;
765 if (err)
766 goto err_mem_2;
767
768 dev = alloc_irdadev(sizeof(struct pxa_irda));
769 if (!dev)
770 goto err_mem_3;
771
772 si = netdev_priv(dev);
773 si->dev = &pdev->dev;
774 si->pdata = pdev->dev.platform_data;
775
776 /*
777 * Initialise the SIR buffers
778 */
779 err = pxa_irda_init_iobuf(&si->rx_buff, 14384);
780 if (err)
781 goto err_mem_4;
782 err = pxa_irda_init_iobuf(&si->tx_buff, 4000);
783 if (err)
784 goto err_mem_5;
785
786 dev->hard_start_xmit = pxa_irda_hard_xmit;
787 dev->open = pxa_irda_start;
788 dev->stop = pxa_irda_stop;
789 dev->do_ioctl = pxa_irda_ioctl;
790 dev->get_stats = pxa_irda_stats;
791
792 irda_init_max_qos_capabilies(&si->qos);
793
794 baudrate_mask = 0;
795 if (si->pdata->transceiver_cap & IR_SIRMODE)
796 baudrate_mask |= IR_9600|IR_19200|IR_38400|IR_57600|IR_115200;
797 if (si->pdata->transceiver_cap & IR_FIRMODE)
798 baudrate_mask |= IR_4000000 << 8;
799
800 si->qos.baud_rate.bits &= baudrate_mask;
801 si->qos.min_turn_time.bits = 7; /* 1ms or more */
802
803 irda_qos_bits_to_value(&si->qos);
804
805 err = register_netdev(dev);
806
807 if (err == 0)
808 dev_set_drvdata(&pdev->dev, dev);
809
810 if (err) {
811 kfree(si->tx_buff.head);
812err_mem_5:
813 kfree(si->rx_buff.head);
814err_mem_4:
815 free_netdev(dev);
816err_mem_3:
817 release_mem_region(__PREG(FICP), 0x1c);
818err_mem_2:
819 release_mem_region(__PREG(STUART), 0x24);
820 }
821err_mem_1:
822 return err;
823}
824
825static int pxa_irda_remove(struct device *_dev)
826{
827 struct net_device *dev = dev_get_drvdata(_dev);
828
829 if (dev) {
830 struct pxa_irda *si = netdev_priv(dev);
831 unregister_netdev(dev);
832 kfree(si->tx_buff.head);
833 kfree(si->rx_buff.head);
834 free_netdev(dev);
835 }
836
837 release_mem_region(__PREG(STUART), 0x24);
838 release_mem_region(__PREG(FICP), 0x1c);
839
840 return 0;
841}
842
843static struct device_driver pxa_ir_driver = {
844 .name = "pxa2xx-ir",
845 .bus = &platform_bus_type,
846 .probe = pxa_irda_probe,
847 .remove = pxa_irda_remove,
848 .suspend = pxa_irda_suspend,
849 .resume = pxa_irda_resume,
850};
851
852static int __init pxa_irda_init(void)
853{
854 return driver_register(&pxa_ir_driver);
855}
856
857static void __exit pxa_irda_exit(void)
858{
859 driver_unregister(&pxa_ir_driver);
860}
861
862module_init(pxa_irda_init);
863module_exit(pxa_irda_exit);
864
865MODULE_LICENSE("GPL");
diff --git a/drivers/net/irda/sa1100_ir.c b/drivers/net/irda/sa1100_ir.c
index 8d34ac60d906..06883309916d 100644
--- a/drivers/net/irda/sa1100_ir.c
+++ b/drivers/net/irda/sa1100_ir.c
@@ -291,12 +291,12 @@ static void sa1100_irda_shutdown(struct sa1100_irda *si)
291/* 291/*
292 * Suspend the IrDA interface. 292 * Suspend the IrDA interface.
293 */ 293 */
294static int sa1100_irda_suspend(struct device *_dev, pm_message_t state, u32 level) 294static int sa1100_irda_suspend(struct device *_dev, pm_message_t state)
295{ 295{
296 struct net_device *dev = dev_get_drvdata(_dev); 296 struct net_device *dev = dev_get_drvdata(_dev);
297 struct sa1100_irda *si; 297 struct sa1100_irda *si;
298 298
299 if (!dev || level != SUSPEND_DISABLE) 299 if (!dev)
300 return 0; 300 return 0;
301 301
302 si = dev->priv; 302 si = dev->priv;
@@ -316,12 +316,12 @@ static int sa1100_irda_suspend(struct device *_dev, pm_message_t state, u32 leve
316/* 316/*
317 * Resume the IrDA interface. 317 * Resume the IrDA interface.
318 */ 318 */
319static int sa1100_irda_resume(struct device *_dev, u32 level) 319static int sa1100_irda_resume(struct device *_dev)
320{ 320{
321 struct net_device *dev = dev_get_drvdata(_dev); 321 struct net_device *dev = dev_get_drvdata(_dev);
322 struct sa1100_irda *si; 322 struct sa1100_irda *si;
323 323
324 if (!dev || level != RESUME_ENABLE) 324 if (!dev)
325 return 0; 325 return 0;
326 326
327 si = dev->priv; 327 si = dev->priv;
diff --git a/drivers/net/irda/sir_dev.c b/drivers/net/irda/sir_dev.c
index efc5a8870565..df22b8b532e7 100644
--- a/drivers/net/irda/sir_dev.c
+++ b/drivers/net/irda/sir_dev.c
@@ -490,8 +490,7 @@ static void sirdev_free_buffers(struct sir_dev *dev)
490{ 490{
491 if (dev->rx_buff.skb) 491 if (dev->rx_buff.skb)
492 kfree_skb(dev->rx_buff.skb); 492 kfree_skb(dev->rx_buff.skb);
493 if (dev->tx_buff.head) 493 kfree(dev->tx_buff.head);
494 kfree(dev->tx_buff.head);
495 dev->rx_buff.head = dev->tx_buff.head = NULL; 494 dev->rx_buff.head = dev->tx_buff.head = NULL;
496 dev->rx_buff.skb = NULL; 495 dev->rx_buff.skb = NULL;
497} 496}
diff --git a/drivers/net/irda/smsc-ircc2.c b/drivers/net/irda/smsc-ircc2.c
index dd89bda1f131..140b7cdb1f7e 100644
--- a/drivers/net/irda/smsc-ircc2.c
+++ b/drivers/net/irda/smsc-ircc2.c
@@ -213,8 +213,8 @@ static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base);
213 213
214/* Power Management */ 214/* Power Management */
215 215
216static int smsc_ircc_suspend(struct device *dev, pm_message_t state, u32 level); 216static int smsc_ircc_suspend(struct device *dev, pm_message_t state);
217static int smsc_ircc_resume(struct device *dev, u32 level); 217static int smsc_ircc_resume(struct device *dev);
218 218
219static struct device_driver smsc_ircc_driver = { 219static struct device_driver smsc_ircc_driver = {
220 .name = SMSC_IRCC2_DRIVER_NAME, 220 .name = SMSC_IRCC2_DRIVER_NAME,
@@ -638,21 +638,14 @@ static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self)
638 */ 638 */
639static void smsc_ircc_init_chip(struct smsc_ircc_cb *self) 639static void smsc_ircc_init_chip(struct smsc_ircc_cb *self)
640{ 640{
641 int iobase, ir_mode, ctrl, fast; 641 int iobase = self->io.fir_base;
642
643 IRDA_ASSERT(self != NULL, return;);
644
645 iobase = self->io.fir_base;
646 ir_mode = IRCC_CFGA_IRDA_SIR_A;
647 ctrl = 0;
648 fast = 0;
649 642
650 register_bank(iobase, 0); 643 register_bank(iobase, 0);
651 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER); 644 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
652 outb(0x00, iobase + IRCC_MASTER); 645 outb(0x00, iobase + IRCC_MASTER);
653 646
654 register_bank(iobase, 1); 647 register_bank(iobase, 1);
655 outb(((inb(iobase + IRCC_SCE_CFGA) & 0x87) | ir_mode), 648 outb(((inb(iobase + IRCC_SCE_CFGA) & 0x87) | IRCC_CFGA_IRDA_SIR_A),
656 iobase + IRCC_SCE_CFGA); 649 iobase + IRCC_SCE_CFGA);
657 650
658#ifdef smsc_669 /* Uses pin 88/89 for Rx/Tx */ 651#ifdef smsc_669 /* Uses pin 88/89 for Rx/Tx */
@@ -666,10 +659,10 @@ static void smsc_ircc_init_chip(struct smsc_ircc_cb *self)
666 outb(SMSC_IRCC2_FIFO_THRESHOLD, iobase + IRCC_FIFO_THRESHOLD); 659 outb(SMSC_IRCC2_FIFO_THRESHOLD, iobase + IRCC_FIFO_THRESHOLD);
667 660
668 register_bank(iobase, 4); 661 register_bank(iobase, 4);
669 outb((inb(iobase + IRCC_CONTROL) & 0x30) | ctrl, iobase + IRCC_CONTROL); 662 outb((inb(iobase + IRCC_CONTROL) & 0x30), iobase + IRCC_CONTROL);
670 663
671 register_bank(iobase, 0); 664 register_bank(iobase, 0);
672 outb(fast, iobase + IRCC_LCR_A); 665 outb(0, iobase + IRCC_LCR_A);
673 666
674 smsc_ircc_set_sir_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED); 667 smsc_ircc_set_sir_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
675 668
@@ -1556,6 +1549,46 @@ static int ircc_is_receiving(struct smsc_ircc_cb *self)
1556} 1549}
1557#endif /* unused */ 1550#endif /* unused */
1558 1551
1552static int smsc_ircc_request_irq(struct smsc_ircc_cb *self)
1553{
1554 int error;
1555
1556 error = request_irq(self->io.irq, smsc_ircc_interrupt, 0,
1557 self->netdev->name, self->netdev);
1558 if (error)
1559 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d, err=%d\n",
1560 __FUNCTION__, self->io.irq, error);
1561
1562 return error;
1563}
1564
1565static void smsc_ircc_start_interrupts(struct smsc_ircc_cb *self)
1566{
1567 unsigned long flags;
1568
1569 spin_lock_irqsave(&self->lock, flags);
1570
1571 self->io.speed = 0;
1572 smsc_ircc_change_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
1573
1574 spin_unlock_irqrestore(&self->lock, flags);
1575}
1576
1577static void smsc_ircc_stop_interrupts(struct smsc_ircc_cb *self)
1578{
1579 int iobase = self->io.fir_base;
1580 unsigned long flags;
1581
1582 spin_lock_irqsave(&self->lock, flags);
1583
1584 register_bank(iobase, 0);
1585 outb(0, iobase + IRCC_IER);
1586 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
1587 outb(0x00, iobase + IRCC_MASTER);
1588
1589 spin_unlock_irqrestore(&self->lock, flags);
1590}
1591
1559 1592
1560/* 1593/*
1561 * Function smsc_ircc_net_open (dev) 1594 * Function smsc_ircc_net_open (dev)
@@ -1567,7 +1600,6 @@ static int smsc_ircc_net_open(struct net_device *dev)
1567{ 1600{
1568 struct smsc_ircc_cb *self; 1601 struct smsc_ircc_cb *self;
1569 char hwname[16]; 1602 char hwname[16];
1570 unsigned long flags;
1571 1603
1572 IRDA_DEBUG(1, "%s\n", __FUNCTION__); 1604 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1573 1605
@@ -1575,6 +1607,11 @@ static int smsc_ircc_net_open(struct net_device *dev)
1575 self = netdev_priv(dev); 1607 self = netdev_priv(dev);
1576 IRDA_ASSERT(self != NULL, return 0;); 1608 IRDA_ASSERT(self != NULL, return 0;);
1577 1609
1610 if (self->io.suspended) {
1611 IRDA_DEBUG(0, "%s(), device is suspended\n", __FUNCTION__);
1612 return -EAGAIN;
1613 }
1614
1578 if (request_irq(self->io.irq, smsc_ircc_interrupt, 0, dev->name, 1615 if (request_irq(self->io.irq, smsc_ircc_interrupt, 0, dev->name,
1579 (void *) dev)) { 1616 (void *) dev)) {
1580 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d\n", 1617 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d\n",
@@ -1582,11 +1619,7 @@ static int smsc_ircc_net_open(struct net_device *dev)
1582 return -EAGAIN; 1619 return -EAGAIN;
1583 } 1620 }
1584 1621
1585 spin_lock_irqsave(&self->lock, flags); 1622 smsc_ircc_start_interrupts(self);
1586 /*smsc_ircc_sir_start(self);*/
1587 self->io.speed = 0;
1588 smsc_ircc_change_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
1589 spin_unlock_irqrestore(&self->lock, flags);
1590 1623
1591 /* Give self a hardware name */ 1624 /* Give self a hardware name */
1592 /* It would be cool to offer the chip revision here - Jean II */ 1625 /* It would be cool to offer the chip revision here - Jean II */
@@ -1639,37 +1672,63 @@ static int smsc_ircc_net_close(struct net_device *dev)
1639 irlap_close(self->irlap); 1672 irlap_close(self->irlap);
1640 self->irlap = NULL; 1673 self->irlap = NULL;
1641 1674
1642 free_irq(self->io.irq, dev); 1675 smsc_ircc_stop_interrupts(self);
1676
1677 /* if we are called from smsc_ircc_resume we don't have IRQ reserved */
1678 if (!self->io.suspended)
1679 free_irq(self->io.irq, dev);
1680
1643 disable_dma(self->io.dma); 1681 disable_dma(self->io.dma);
1644 free_dma(self->io.dma); 1682 free_dma(self->io.dma);
1645 1683
1646 return 0; 1684 return 0;
1647} 1685}
1648 1686
1649static int smsc_ircc_suspend(struct device *dev, pm_message_t state, u32 level) 1687static int smsc_ircc_suspend(struct device *dev, pm_message_t state)
1650{ 1688{
1651 struct smsc_ircc_cb *self = dev_get_drvdata(dev); 1689 struct smsc_ircc_cb *self = dev_get_drvdata(dev);
1652 1690
1653 IRDA_MESSAGE("%s, Suspending\n", driver_name); 1691 if (!self->io.suspended) {
1692 IRDA_DEBUG(1, "%s, Suspending\n", driver_name);
1654 1693
1655 if (level == SUSPEND_DISABLE && !self->io.suspended) { 1694 rtnl_lock();
1656 smsc_ircc_net_close(self->netdev); 1695 if (netif_running(self->netdev)) {
1696 netif_device_detach(self->netdev);
1697 smsc_ircc_stop_interrupts(self);
1698 free_irq(self->io.irq, self->netdev);
1699 disable_dma(self->io.dma);
1700 }
1657 self->io.suspended = 1; 1701 self->io.suspended = 1;
1702 rtnl_unlock();
1658 } 1703 }
1659 1704
1660 return 0; 1705 return 0;
1661} 1706}
1662 1707
1663static int smsc_ircc_resume(struct device *dev, u32 level) 1708static int smsc_ircc_resume(struct device *dev)
1664{ 1709{
1665 struct smsc_ircc_cb *self = dev_get_drvdata(dev); 1710 struct smsc_ircc_cb *self = dev_get_drvdata(dev);
1666 1711
1667 if (level == RESUME_ENABLE && self->io.suspended) { 1712 if (self->io.suspended) {
1668 1713 IRDA_DEBUG(1, "%s, Waking up\n", driver_name);
1669 smsc_ircc_net_open(self->netdev); 1714
1715 rtnl_lock();
1716 smsc_ircc_init_chip(self);
1717 if (netif_running(self->netdev)) {
1718 if (smsc_ircc_request_irq(self)) {
1719 /*
1720 * Don't fail resume process, just kill this
1721 * network interface
1722 */
1723 unregister_netdevice(self->netdev);
1724 } else {
1725 enable_dma(self->io.dma);
1726 smsc_ircc_start_interrupts(self);
1727 netif_device_attach(self->netdev);
1728 }
1729 }
1670 self->io.suspended = 0; 1730 self->io.suspended = 0;
1671 1731 rtnl_unlock();
1672 IRDA_MESSAGE("%s, Waking up\n", driver_name);
1673 } 1732 }
1674 return 0; 1733 return 0;
1675} 1734}
@@ -1682,9 +1741,6 @@ static int smsc_ircc_resume(struct device *dev, u32 level)
1682 */ 1741 */
1683static int __exit smsc_ircc_close(struct smsc_ircc_cb *self) 1742static int __exit smsc_ircc_close(struct smsc_ircc_cb *self)
1684{ 1743{
1685 int iobase;
1686 unsigned long flags;
1687
1688 IRDA_DEBUG(1, "%s\n", __FUNCTION__); 1744 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1689 1745
1690 IRDA_ASSERT(self != NULL, return -1;); 1746 IRDA_ASSERT(self != NULL, return -1;);
@@ -1694,22 +1750,7 @@ static int __exit smsc_ircc_close(struct smsc_ircc_cb *self)
1694 /* Remove netdevice */ 1750 /* Remove netdevice */
1695 unregister_netdev(self->netdev); 1751 unregister_netdev(self->netdev);
1696 1752
1697 /* Make sure the irq handler is not exectuting */ 1753 smsc_ircc_stop_interrupts(self);
1698 spin_lock_irqsave(&self->lock, flags);
1699
1700 /* Stop interrupts */
1701 iobase = self->io.fir_base;
1702 register_bank(iobase, 0);
1703 outb(0, iobase + IRCC_IER);
1704 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
1705 outb(0x00, iobase + IRCC_MASTER);
1706#if 0
1707 /* Reset to SIR mode */
1708 register_bank(iobase, 1);
1709 outb(IRCC_CFGA_IRDA_SIR_A|IRCC_CFGA_TX_POLARITY, iobase + IRCC_SCE_CFGA);
1710 outb(IRCC_CFGB_IR, iobase + IRCC_SCE_CFGB);
1711#endif
1712 spin_unlock_irqrestore(&self->lock, flags);
1713 1754
1714 /* Release the PORTS that this driver is using */ 1755 /* Release the PORTS that this driver is using */
1715 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__, 1756 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
diff --git a/drivers/net/irda/stir4200.c b/drivers/net/irda/stir4200.c
index 15f207323d97..3961a754e920 100644
--- a/drivers/net/irda/stir4200.c
+++ b/drivers/net/irda/stir4200.c
@@ -678,10 +678,9 @@ static void turnaround_delay(const struct stir_cb *stir, long us)
678 return; 678 return;
679 679
680 ticks = us / (1000000 / HZ); 680 ticks = us / (1000000 / HZ);
681 if (ticks > 0) { 681 if (ticks > 0)
682 current->state = TASK_INTERRUPTIBLE; 682 schedule_timeout_interruptible(1 + ticks);
683 schedule_timeout(1 + ticks); 683 else
684 } else
685 udelay(us); 684 udelay(us);
686} 685}
687 686
diff --git a/drivers/net/irda/vlsi_ir.c b/drivers/net/irda/vlsi_ir.c
index 651c5a6578fd..a9f49f058cfb 100644
--- a/drivers/net/irda/vlsi_ir.c
+++ b/drivers/net/irda/vlsi_ir.c
@@ -473,8 +473,7 @@ static int vlsi_free_ring(struct vlsi_ring *r)
473 rd_set_addr_status(rd, 0, 0); 473 rd_set_addr_status(rd, 0, 0);
474 if (busaddr) 474 if (busaddr)
475 pci_unmap_single(r->pdev, busaddr, r->len, r->dir); 475 pci_unmap_single(r->pdev, busaddr, r->len, r->dir);
476 if (rd->buf) 476 kfree(rd->buf);
477 kfree(rd->buf);
478 } 477 }
479 kfree(r); 478 kfree(r);
480 return 0; 479 return 0;
diff --git a/drivers/net/ixgb/ixgb_ethtool.c b/drivers/net/ixgb/ixgb_ethtool.c
index 9d026ed77ddd..04e47189d830 100644
--- a/drivers/net/ixgb/ixgb_ethtool.c
+++ b/drivers/net/ixgb/ixgb_ethtool.c
@@ -645,11 +645,10 @@ ixgb_phys_id(struct net_device *netdev, uint32_t data)
645 645
646 mod_timer(&adapter->blink_timer, jiffies); 646 mod_timer(&adapter->blink_timer, jiffies);
647 647
648 set_current_state(TASK_INTERRUPTIBLE); 648 if (data)
649 if(data) 649 schedule_timeout_interruptible(data * HZ);
650 schedule_timeout(data * HZ);
651 else 650 else
652 schedule_timeout(MAX_SCHEDULE_TIMEOUT); 651 schedule_timeout_interruptible(MAX_SCHEDULE_TIMEOUT);
653 652
654 del_timer_sync(&adapter->blink_timer); 653 del_timer_sync(&adapter->blink_timer);
655 ixgb_led_off(&adapter->hw); 654 ixgb_led_off(&adapter->hw);
@@ -723,6 +722,7 @@ struct ethtool_ops ixgb_ethtool_ops = {
723 .phys_id = ixgb_phys_id, 722 .phys_id = ixgb_phys_id,
724 .get_stats_count = ixgb_get_stats_count, 723 .get_stats_count = ixgb_get_stats_count,
725 .get_ethtool_stats = ixgb_get_ethtool_stats, 724 .get_ethtool_stats = ixgb_get_ethtool_stats,
725 .get_perm_addr = ethtool_op_get_perm_addr,
726}; 726};
727 727
728void ixgb_set_ethtool_ops(struct net_device *netdev) 728void ixgb_set_ethtool_ops(struct net_device *netdev)
diff --git a/drivers/net/ixgb/ixgb_main.c b/drivers/net/ixgb/ixgb_main.c
index 89d6d69be382..176680cb153e 100644
--- a/drivers/net/ixgb/ixgb_main.c
+++ b/drivers/net/ixgb/ixgb_main.c
@@ -460,8 +460,9 @@ ixgb_probe(struct pci_dev *pdev,
460 } 460 }
461 461
462 ixgb_get_ee_mac_addr(&adapter->hw, netdev->dev_addr); 462 ixgb_get_ee_mac_addr(&adapter->hw, netdev->dev_addr);
463 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
463 464
464 if(!is_valid_ether_addr(netdev->dev_addr)) { 465 if(!is_valid_ether_addr(netdev->perm_addr)) {
465 err = -EIO; 466 err = -EIO;
466 goto err_eeprom; 467 goto err_eeprom;
467 } 468 }
diff --git a/drivers/net/lance.c b/drivers/net/lance.c
index b4929beb33b2..1d75ca0bb939 100644
--- a/drivers/net/lance.c
+++ b/drivers/net/lance.c
@@ -298,7 +298,7 @@ enum {OLD_LANCE = 0, PCNET_ISA=1, PCNET_ISAP=2, PCNET_PCI=3, PCNET_VLB=4, PCNET_
298static unsigned char lance_need_isa_bounce_buffers = 1; 298static unsigned char lance_need_isa_bounce_buffers = 1;
299 299
300static int lance_open(struct net_device *dev); 300static int lance_open(struct net_device *dev);
301static void lance_init_ring(struct net_device *dev, int mode); 301static void lance_init_ring(struct net_device *dev, gfp_t mode);
302static int lance_start_xmit(struct sk_buff *skb, struct net_device *dev); 302static int lance_start_xmit(struct sk_buff *skb, struct net_device *dev);
303static int lance_rx(struct net_device *dev); 303static int lance_rx(struct net_device *dev);
304static irqreturn_t lance_interrupt(int irq, void *dev_id, struct pt_regs *regs); 304static irqreturn_t lance_interrupt(int irq, void *dev_id, struct pt_regs *regs);
@@ -846,7 +846,7 @@ lance_purge_ring(struct net_device *dev)
846 846
847/* Initialize the LANCE Rx and Tx rings. */ 847/* Initialize the LANCE Rx and Tx rings. */
848static void 848static void
849lance_init_ring(struct net_device *dev, int gfp) 849lance_init_ring(struct net_device *dev, gfp_t gfp)
850{ 850{
851 struct lance_private *lp = dev->priv; 851 struct lance_private *lp = dev->priv;
852 int i; 852 int i;
diff --git a/drivers/net/lasi_82596.c b/drivers/net/lasi_82596.c
index 41bad07ac1ac..f7b7238d8352 100644
--- a/drivers/net/lasi_82596.c
+++ b/drivers/net/lasi_82596.c
@@ -415,6 +415,10 @@ static int rx_ring_size = RX_RING_SIZE;
415static int ticks_limit = 100; 415static int ticks_limit = 100;
416static int max_cmd_backlog = TX_RING_SIZE-1; 416static int max_cmd_backlog = TX_RING_SIZE-1;
417 417
418#ifdef CONFIG_NET_POLL_CONTROLLER
419static void i596_poll_controller(struct net_device *dev);
420#endif
421
418 422
419static inline void CA(struct net_device *dev) 423static inline void CA(struct net_device *dev)
420{ 424{
@@ -636,11 +640,11 @@ static int init_i596_mem(struct net_device *dev)
636 640
637 disable_irq(dev->irq); /* disable IRQs from LAN */ 641 disable_irq(dev->irq); /* disable IRQs from LAN */
638 DEB(DEB_INIT, 642 DEB(DEB_INIT,
639 printk("RESET 82596 port: %p (with IRQ %d disabled)\n", 643 printk("RESET 82596 port: %lx (with IRQ %d disabled)\n",
640 (void*)(dev->base_addr + PA_I82596_RESET), 644 (dev->base_addr + PA_I82596_RESET),
641 dev->irq)); 645 dev->irq));
642 646
643 gsc_writel(0, (void*)(dev->base_addr + PA_I82596_RESET)); /* Hard Reset */ 647 gsc_writel(0, (dev->base_addr + PA_I82596_RESET)); /* Hard Reset */
644 udelay(100); /* Wait 100us - seems to help */ 648 udelay(100); /* Wait 100us - seems to help */
645 649
646 /* change the scp address */ 650 /* change the scp address */
@@ -1209,6 +1213,9 @@ static int __devinit i82596_probe(struct net_device *dev,
1209 dev->set_multicast_list = set_multicast_list; 1213 dev->set_multicast_list = set_multicast_list;
1210 dev->tx_timeout = i596_tx_timeout; 1214 dev->tx_timeout = i596_tx_timeout;
1211 dev->watchdog_timeo = TX_TIMEOUT; 1215 dev->watchdog_timeo = TX_TIMEOUT;
1216#ifdef CONFIG_NET_POLL_CONTROLLER
1217 dev->poll_controller = i596_poll_controller;
1218#endif
1212 1219
1213 dev->priv = (void *)(dev->mem_start); 1220 dev->priv = (void *)(dev->mem_start);
1214 1221
@@ -1242,6 +1249,14 @@ static int __devinit i82596_probe(struct net_device *dev,
1242 return 0; 1249 return 0;
1243} 1250}
1244 1251
1252#ifdef CONFIG_NET_POLL_CONTROLLER
1253static void i596_poll_controller(struct net_device *dev)
1254{
1255 disable_irq(dev->irq);
1256 i596_interrupt(dev->irq, dev, NULL);
1257 enable_irq(dev->irq);
1258}
1259#endif
1245 1260
1246static irqreturn_t i596_interrupt(int irq, void *dev_id, struct pt_regs *regs) 1261static irqreturn_t i596_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1247{ 1262{
@@ -1528,17 +1543,18 @@ lan_init_chip(struct parisc_device *dev)
1528 1543
1529 if (!dev->irq) { 1544 if (!dev->irq) {
1530 printk(KERN_ERR "%s: IRQ not found for i82596 at 0x%lx\n", 1545 printk(KERN_ERR "%s: IRQ not found for i82596 at 0x%lx\n",
1531 __FILE__, dev->hpa); 1546 __FILE__, dev->hpa.start);
1532 return -ENODEV; 1547 return -ENODEV;
1533 } 1548 }
1534 1549
1535 printk(KERN_INFO "Found i82596 at 0x%lx, IRQ %d\n", dev->hpa, dev->irq); 1550 printk(KERN_INFO "Found i82596 at 0x%lx, IRQ %d\n", dev->hpa.start,
1551 dev->irq);
1536 1552
1537 netdevice = alloc_etherdev(0); 1553 netdevice = alloc_etherdev(0);
1538 if (!netdevice) 1554 if (!netdevice)
1539 return -ENOMEM; 1555 return -ENOMEM;
1540 1556
1541 netdevice->base_addr = dev->hpa; 1557 netdevice->base_addr = dev->hpa.start;
1542 netdevice->irq = dev->irq; 1558 netdevice->irq = dev->irq;
1543 1559
1544 retval = i82596_probe(netdevice, &dev->dev); 1560 retval = i82596_probe(netdevice, &dev->dev);
@@ -1566,7 +1582,7 @@ static struct parisc_device_id lan_tbl[] = {
1566MODULE_DEVICE_TABLE(parisc, lan_tbl); 1582MODULE_DEVICE_TABLE(parisc, lan_tbl);
1567 1583
1568static struct parisc_driver lan_driver = { 1584static struct parisc_driver lan_driver = {
1569 .name = "Apricot", 1585 .name = "lasi_82596",
1570 .id_table = lan_tbl, 1586 .id_table = lan_tbl,
1571 .probe = lan_init_chip, 1587 .probe = lan_init_chip,
1572}; 1588};
diff --git a/drivers/net/lne390.c b/drivers/net/lne390.c
index 27f0d8ac4c40..309d254842cf 100644
--- a/drivers/net/lne390.c
+++ b/drivers/net/lne390.c
@@ -298,7 +298,7 @@ static int __init lne390_probe1(struct net_device *dev, int ioaddr)
298 return 0; 298 return 0;
299unmap: 299unmap:
300 if (ei_status.reg0) 300 if (ei_status.reg0)
301 iounmap((void *)dev->mem_start); 301 iounmap(ei_status.mem);
302cleanup: 302cleanup:
303 free_irq(dev->irq, dev); 303 free_irq(dev->irq, dev);
304 return ret; 304 return ret;
diff --git a/drivers/net/mace.c b/drivers/net/mace.c
index f2fc1f26cd4b..2a5add257b8f 100644
--- a/drivers/net/mace.c
+++ b/drivers/net/mace.c
@@ -1036,10 +1036,8 @@ static void __exit mace_cleanup(void)
1036{ 1036{
1037 macio_unregister_driver(&mace_driver); 1037 macio_unregister_driver(&mace_driver);
1038 1038
1039 if (dummy_buf) { 1039 kfree(dummy_buf);
1040 kfree(dummy_buf); 1040 dummy_buf = NULL;
1041 dummy_buf = NULL;
1042 }
1043} 1041}
1044 1042
1045MODULE_AUTHOR("Paul Mackerras"); 1043MODULE_AUTHOR("Paul Mackerras");
diff --git a/drivers/net/mii.c b/drivers/net/mii.c
index c33cb3dc942b..e42aa797f08b 100644
--- a/drivers/net/mii.c
+++ b/drivers/net/mii.c
@@ -207,6 +207,20 @@ int mii_ethtool_sset(struct mii_if_info *mii, struct ethtool_cmd *ecmd)
207 return 0; 207 return 0;
208} 208}
209 209
210int mii_check_gmii_support(struct mii_if_info *mii)
211{
212 int reg;
213
214 reg = mii->mdio_read(mii->dev, mii->phy_id, MII_BMSR);
215 if (reg & BMSR_ESTATEN) {
216 reg = mii->mdio_read(mii->dev, mii->phy_id, MII_ESTATUS);
217 if (reg & (ESTATUS_1000_TFULL | ESTATUS_1000_THALF))
218 return 1;
219 }
220
221 return 0;
222}
223
210int mii_link_ok (struct mii_if_info *mii) 224int mii_link_ok (struct mii_if_info *mii)
211{ 225{
212 /* first, a dummy read, needed to latch some MII phys */ 226 /* first, a dummy read, needed to latch some MII phys */
@@ -394,5 +408,6 @@ EXPORT_SYMBOL(mii_ethtool_gset);
394EXPORT_SYMBOL(mii_ethtool_sset); 408EXPORT_SYMBOL(mii_ethtool_sset);
395EXPORT_SYMBOL(mii_check_link); 409EXPORT_SYMBOL(mii_check_link);
396EXPORT_SYMBOL(mii_check_media); 410EXPORT_SYMBOL(mii_check_media);
411EXPORT_SYMBOL(mii_check_gmii_support);
397EXPORT_SYMBOL(generic_mii_ioctl); 412EXPORT_SYMBOL(generic_mii_ioctl);
398 413
diff --git a/drivers/net/mipsnet.c b/drivers/net/mipsnet.c
new file mode 100644
index 000000000000..f79f7ee72ab8
--- /dev/null
+++ b/drivers/net/mipsnet.c
@@ -0,0 +1,371 @@
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 */
6
7#define DEBUG
8
9#include <linux/init.h>
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/netdevice.h>
13#include <linux/sched.h>
14#include <linux/etherdevice.h>
15#include <linux/netdevice.h>
16#include <asm/io.h>
17#include <asm/mips-boards/simint.h>
18
19#include "mipsnet.h" /* actual device IO mapping */
20
21#define MIPSNET_VERSION "2005-06-20"
22
23#define mipsnet_reg_address(dev, field) (dev->base_addr + field_offset(field))
24
25struct mipsnet_priv {
26 struct net_device_stats stats;
27};
28
29static struct platform_device *mips_plat_dev;
30
31static char mipsnet_string[] = "mipsnet";
32
33/*
34 * Copy data from the MIPSNET rx data port
35 */
36static int ioiocpy_frommipsnet(struct net_device *dev, unsigned char *kdata,
37 int len)
38{
39 uint32_t available_len = inl(mipsnet_reg_address(dev, rxDataCount));
40 if (available_len < len)
41 return -EFAULT;
42
43 for (; len > 0; len--, kdata++) {
44 *kdata = inb(mipsnet_reg_address(dev, rxDataBuffer));
45 }
46
47 return inl(mipsnet_reg_address(dev, rxDataCount));
48}
49
50static inline ssize_t mipsnet_put_todevice(struct net_device *dev,
51 struct sk_buff *skb)
52{
53 int count_to_go = skb->len;
54 char *buf_ptr = skb->data;
55 struct mipsnet_priv *mp = netdev_priv(dev);
56
57 pr_debug("%s: %s(): telling MIPSNET txDataCount(%d)\n",
58 dev->name, __FUNCTION__, skb->len);
59
60 outl(skb->len, mipsnet_reg_address(dev, txDataCount));
61
62 pr_debug("%s: %s(): sending data to MIPSNET txDataBuffer(%d)\n",
63 dev->name, __FUNCTION__, skb->len);
64
65 for (; count_to_go; buf_ptr++, count_to_go--) {
66 outb(*buf_ptr, mipsnet_reg_address(dev, txDataBuffer));
67 }
68
69 mp->stats.tx_packets++;
70 mp->stats.tx_bytes += skb->len;
71
72 return skb->len;
73}
74
75static int mipsnet_xmit(struct sk_buff *skb, struct net_device *dev)
76{
77 pr_debug("%s:%s(): transmitting %d bytes\n",
78 dev->name, __FUNCTION__, skb->len);
79
80 /* Only one packet at a time. Once TXDONE interrupt is serviced, the
81 * queue will be restarted.
82 */
83 netif_stop_queue(dev);
84 mipsnet_put_todevice(dev, skb);
85
86 return 0;
87}
88
89static inline ssize_t mipsnet_get_fromdev(struct net_device *dev, size_t count)
90{
91 struct sk_buff *skb;
92 size_t len = count;
93 struct mipsnet_priv *mp = netdev_priv(dev);
94
95 if (!(skb = alloc_skb(len + 2, GFP_KERNEL))) {
96 mp->stats.rx_dropped++;
97 return -ENOMEM;
98 }
99
100 skb_reserve(skb, 2);
101 if (ioiocpy_frommipsnet(dev, skb_put(skb, len), len))
102 return -EFAULT;
103
104 skb->dev = dev;
105 skb->protocol = eth_type_trans(skb, dev);
106 skb->ip_summed = CHECKSUM_UNNECESSARY;
107
108 pr_debug("%s:%s(): pushing RXed data to kernel\n",
109 dev->name, __FUNCTION__);
110 netif_rx(skb);
111
112 mp->stats.rx_packets++;
113 mp->stats.rx_bytes += len;
114
115 return count;
116}
117
118static irqreturn_t
119mipsnet_interrupt(int irq, void *dev_id, struct pt_regs *regs)
120{
121 struct net_device *dev = dev_id;
122
123 irqreturn_t retval = IRQ_NONE;
124 uint64_t interruptFlags;
125
126 if (irq == dev->irq) {
127 pr_debug("%s:%s(): irq %d for device\n",
128 dev->name, __FUNCTION__, irq);
129
130 retval = IRQ_HANDLED;
131
132 interruptFlags =
133 inl(mipsnet_reg_address(dev, interruptControl));
134 pr_debug("%s:%s(): intCtl=0x%016llx\n", dev->name,
135 __FUNCTION__, interruptFlags);
136
137 if (interruptFlags & MIPSNET_INTCTL_TXDONE) {
138 pr_debug("%s:%s(): got TXDone\n",
139 dev->name, __FUNCTION__);
140 outl(MIPSNET_INTCTL_TXDONE,
141 mipsnet_reg_address(dev, interruptControl));
142 // only one packet at a time, we are done.
143 netif_wake_queue(dev);
144 } else if (interruptFlags & MIPSNET_INTCTL_RXDONE) {
145 pr_debug("%s:%s(): got RX data\n",
146 dev->name, __FUNCTION__);
147 mipsnet_get_fromdev(dev,
148 inl(mipsnet_reg_address(dev, rxDataCount)));
149 pr_debug("%s:%s(): clearing RX int\n",
150 dev->name, __FUNCTION__);
151 outl(MIPSNET_INTCTL_RXDONE,
152 mipsnet_reg_address(dev, interruptControl));
153
154 } else if (interruptFlags & MIPSNET_INTCTL_TESTBIT) {
155 pr_debug("%s:%s(): got test interrupt\n",
156 dev->name, __FUNCTION__);
157 // TESTBIT is cleared on read.
158 // And takes effect after a write with 0
159 outl(0, mipsnet_reg_address(dev, interruptControl));
160 } else {
161 pr_debug("%s:%s(): no valid fags 0x%016llx\n",
162 dev->name, __FUNCTION__, interruptFlags);
163 // Maybe shared IRQ, just ignore, no clearing.
164 retval = IRQ_NONE;
165 }
166
167 } else {
168 printk(KERN_INFO "%s: %s(): irq %d for unknown device\n",
169 dev->name, __FUNCTION__, irq);
170 retval = IRQ_NONE;
171 }
172 return retval;
173} //mipsnet_interrupt()
174
175static int mipsnet_open(struct net_device *dev)
176{
177 int err;
178 pr_debug("%s: mipsnet_open\n", dev->name);
179
180 err = request_irq(dev->irq, &mipsnet_interrupt,
181 SA_SHIRQ, dev->name, (void *) dev);
182
183 if (err) {
184 pr_debug("%s: %s(): can't get irq %d\n",
185 dev->name, __FUNCTION__, dev->irq);
186 release_region(dev->base_addr, MIPSNET_IO_EXTENT);
187 return err;
188 }
189
190 pr_debug("%s: %s(): got IO region at 0x%04lx and irq %d for dev.\n",
191 dev->name, __FUNCTION__, dev->base_addr, dev->irq);
192
193
194 netif_start_queue(dev);
195
196 // test interrupt handler
197 outl(MIPSNET_INTCTL_TESTBIT,
198 mipsnet_reg_address(dev, interruptControl));
199
200
201 return 0;
202}
203
204static int mipsnet_close(struct net_device *dev)
205{
206 pr_debug("%s: %s()\n", dev->name, __FUNCTION__);
207 netif_stop_queue(dev);
208 return 0;
209}
210
211static struct net_device_stats *mipsnet_get_stats(struct net_device *dev)
212{
213 struct mipsnet_priv *mp = netdev_priv(dev);
214
215 return &mp->stats;
216}
217
218static void mipsnet_set_mclist(struct net_device *dev)
219{
220 // we don't do anything
221 return;
222}
223
224static int __init mipsnet_probe(struct device *dev)
225{
226 struct net_device *netdev;
227 int err;
228
229 netdev = alloc_etherdev(sizeof(struct mipsnet_priv));
230 if (!netdev) {
231 err = -ENOMEM;
232 goto out;
233 }
234
235 dev_set_drvdata(dev, netdev);
236
237 netdev->open = mipsnet_open;
238 netdev->stop = mipsnet_close;
239 netdev->hard_start_xmit = mipsnet_xmit;
240 netdev->get_stats = mipsnet_get_stats;
241 netdev->set_multicast_list = mipsnet_set_mclist;
242
243 /*
244 * TODO: probe for these or load them from PARAM
245 */
246 netdev->base_addr = 0x4200;
247 netdev->irq = MIPSCPU_INT_BASE + MIPSCPU_INT_MB0 +
248 inl(mipsnet_reg_address(netdev, interruptInfo));
249
250 // Get the io region now, get irq on open()
251 if (!request_region(netdev->base_addr, MIPSNET_IO_EXTENT, "mipsnet")) {
252 pr_debug("%s: %s(): IO region {start: 0x%04lux, len: %d} "
253 "for dev is not availble.\n", netdev->name,
254 __FUNCTION__, netdev->base_addr, MIPSNET_IO_EXTENT);
255 err = -EBUSY;
256 goto out_free_netdev;
257 }
258
259 /*
260 * Lacking any better mechanism to allocate a MAC address we use a
261 * random one ...
262 */
263 random_ether_addr(netdev->dev_addr);
264
265 err = register_netdev(netdev);
266 if (err) {
267 printk(KERN_ERR "MIPSNet: failed to register netdev.\n");
268 goto out_free_region;
269 }
270
271 return 0;
272
273out_free_region:
274 release_region(netdev->base_addr, MIPSNET_IO_EXTENT);
275
276out_free_netdev:
277 free_netdev(netdev);
278
279out:
280 return err;
281}
282
283static int __devexit mipsnet_device_remove(struct device *device)
284{
285 struct net_device *dev = dev_get_drvdata(device);
286
287 unregister_netdev(dev);
288 release_region(dev->base_addr, MIPSNET_IO_EXTENT);
289 free_netdev(dev);
290 dev_set_drvdata(device, NULL);
291
292 return 0;
293}
294
295static struct device_driver mipsnet_driver = {
296 .name = mipsnet_string,
297 .bus = &platform_bus_type,
298 .probe = mipsnet_probe,
299 .remove = __devexit_p(mipsnet_device_remove),
300};
301
302static void mipsnet_platform_release(struct device *device)
303{
304 struct platform_device *pldev;
305
306 /* free device */
307 pldev = to_platform_device(device);
308 kfree(pldev);
309}
310
311static int __init mipsnet_init_module(void)
312{
313 struct platform_device *pldev;
314 int err;
315
316 printk(KERN_INFO "MIPSNet Ethernet driver. Version: %s. "
317 "(c)2005 MIPS Technologies, Inc.\n", MIPSNET_VERSION);
318
319 if (driver_register(&mipsnet_driver)) {
320 printk(KERN_ERR "Driver registration failed\n");
321 err = -ENODEV;
322 goto out;
323 }
324
325 if (!(pldev = kmalloc (sizeof (*pldev), GFP_KERNEL))) {
326 err = -ENOMEM;
327 goto out_unregister_driver;
328 }
329
330 memset (pldev, 0, sizeof (*pldev));
331 pldev->name = mipsnet_string;
332 pldev->id = 0;
333 pldev->dev.release = mipsnet_platform_release;
334
335 if (platform_device_register(pldev)) {
336 err = -ENODEV;
337 goto out_free_pldev;
338 }
339
340 if (!pldev->dev.driver) {
341 /*
342 * The driver was not bound to this device, there was
343 * no hardware at this address. Unregister it, as the
344 * release fuction will take care of freeing the
345 * allocated structure
346 */
347 platform_device_unregister (pldev);
348 }
349
350 mips_plat_dev = pldev;
351
352 return 0;
353
354out_free_pldev:
355 kfree(pldev);
356
357out_unregister_driver:
358 driver_unregister(&mipsnet_driver);
359out:
360 return err;
361}
362
363static void __exit mipsnet_exit_module(void)
364{
365 pr_debug("MIPSNet Ethernet driver exiting\n");
366
367 driver_unregister(&mipsnet_driver);
368}
369
370module_init(mipsnet_init_module);
371module_exit(mipsnet_exit_module);
diff --git a/drivers/net/mipsnet.h b/drivers/net/mipsnet.h
new file mode 100644
index 000000000000..878535953cb1
--- /dev/null
+++ b/drivers/net/mipsnet.h
@@ -0,0 +1,127 @@
1//
2// <COPYRIGHT CLASS="1B" YEAR="2005">
3// Unpublished work (c) MIPS Technologies, Inc. All rights reserved.
4// Unpublished rights reserved under the copyright laws of the U.S.A. and
5// other countries.
6//
7// PROPRIETARY / SECRET CONFIDENTIAL INFORMATION OF MIPS TECHNOLOGIES, INC.
8// FOR INTERNAL USE ONLY.
9//
10// Under no circumstances (contract or otherwise) may this information be
11// disclosed to, or copied, modified or used by anyone other than employees
12// or contractors of MIPS Technologies having a need to know.
13// </COPYRIGHT>
14//
15//++
16// File: MIPS_Net.h
17//
18// Description:
19// The definition of the emulated MIPSNET device's interface.
20//
21// Notes: This include file needs to work from a Linux device drivers.
22//
23//--
24//
25
26#ifndef __MIPSNET_H
27#define __MIPSNET_H
28
29/*
30 * Id of this Net device, as seen by the core.
31 */
32#define MIPS_NET_DEV_ID ((uint64_t) \
33 ((uint64_t)'M'<< 0)| \
34 ((uint64_t)'I'<< 8)| \
35 ((uint64_t)'P'<<16)| \
36 ((uint64_t)'S'<<24)| \
37 ((uint64_t)'N'<<32)| \
38 ((uint64_t)'E'<<40)| \
39 ((uint64_t)'T'<<48)| \
40 ((uint64_t)'0'<<56))
41
42/*
43 * Net status/control block as seen by sw in the core.
44 * (Why not use bit fields? can't be bothered with cross-platform struct
45 * packing.)
46 */
47typedef struct _net_control_block {
48 /// dev info for probing
49 /// reads as MIPSNET%d where %d is some form of version
50 uint64_t devId; /*0x00 */
51
52 /*
53 * read only busy flag.
54 * Set and cleared by the Net Device to indicate that an rx or a tx
55 * is in progress.
56 */
57 uint32_t busy; /*0x08 */
58
59 /*
60 * Set by the Net Device.
61 * The device will set it once data has been received.
62 * The value is the number of bytes that should be read from
63 * rxDataBuffer. The value will decrease till 0 until all the data
64 * from rxDataBuffer has been read.
65 */
66 uint32_t rxDataCount; /*0x0c */
67#define MIPSNET_MAX_RXTX_DATACOUNT (1<<16)
68
69 /*
70 * Settable from the MIPS core, cleared by the Net Device.
71 * The core should set the number of bytes it wants to send,
72 * then it should write those bytes of data to txDataBuffer.
73 * The device will clear txDataCount has been processed (not necessarily sent).
74 */
75 uint32_t txDataCount; /*0x10 */
76
77 /*
78 * Interrupt control
79 *
80 * Used to clear the interrupted generated by this dev.
81 * Write a 1 to clear the interrupt. (except bit31).
82 *
83 * Bit0 is set if it was a tx-done interrupt.
84 * Bit1 is set when new rx-data is available.
85 * Until this bit is cleared there will be no other RXs.
86 *
87 * Bit31 is used for testing, it clears after a read.
88 * Writing 1 to this bit will cause an interrupt to be generated.
89 * To clear the test interrupt, write 0 to this register.
90 */
91 uint32_t interruptControl; /*0x14 */
92#define MIPSNET_INTCTL_TXDONE ((uint32_t)(1<< 0))
93#define MIPSNET_INTCTL_RXDONE ((uint32_t)(1<< 1))
94#define MIPSNET_INTCTL_TESTBIT ((uint32_t)(1<<31))
95#define MIPSNET_INTCTL_ALLSOURCES (MIPSNET_INTCTL_TXDONE|MIPSNET_INTCTL_RXDONE|MIPSNET_INTCTL_TESTBIT)
96
97 /*
98 * Readonly core-specific interrupt info for the device to signal the core.
99 * The meaning of the contents of this field might change.
100 */
101 /*###\todo: the whole memIntf interrupt scheme is messy: the device should have
102 * no control what so ever of what VPE/register set is being used.
103 * The MemIntf should only expose interrupt lines, and something in the
104 * config should be responsible for the line<->core/vpe bindings.
105 */
106 uint32_t interruptInfo; /*0x18 */
107
108 /*
109 * This is where the received data is read out.
110 * There is more data to read until rxDataReady is 0.
111 * Only 1 byte at this regs offset is used.
112 */
113 uint32_t rxDataBuffer; /*0x1c */
114
115 /*
116 * This is where the data to transmit is written.
117 * Data should be written for the amount specified in the txDataCount register.
118 * Only 1 byte at this regs offset is used.
119 */
120 uint32_t txDataBuffer; /*0x20 */
121} MIPS_T_NetControl;
122
123#define MIPSNET_IO_EXTENT 0x40 /* being generous */
124
125#define field_offset(field) ((int)&((MIPS_T_NetControl*)(0))->field)
126
127#endif /* __MIPSNET_H */
diff --git a/drivers/net/myri_sbus.c b/drivers/net/myri_sbus.c
index f0996ce5c268..6c86dca62e2a 100644
--- a/drivers/net/myri_sbus.c
+++ b/drivers/net/myri_sbus.c
@@ -277,7 +277,7 @@ static void myri_init_rings(struct myri_eth *mp, int from_irq)
277 struct recvq __iomem *rq = mp->rq; 277 struct recvq __iomem *rq = mp->rq;
278 struct myri_rxd __iomem *rxd = &rq->myri_rxd[0]; 278 struct myri_rxd __iomem *rxd = &rq->myri_rxd[0];
279 struct net_device *dev = mp->dev; 279 struct net_device *dev = mp->dev;
280 int gfp_flags = GFP_KERNEL; 280 gfp_t gfp_flags = GFP_KERNEL;
281 int i; 281 int i;
282 282
283 if (from_irq || in_interrupt()) 283 if (from_irq || in_interrupt())
diff --git a/drivers/net/myri_sbus.h b/drivers/net/myri_sbus.h
index 9391e55a5e92..47722f708a41 100644
--- a/drivers/net/myri_sbus.h
+++ b/drivers/net/myri_sbus.h
@@ -296,7 +296,7 @@ struct myri_eth {
296/* We use this to acquire receive skb's that we can DMA directly into. */ 296/* We use this to acquire receive skb's that we can DMA directly into. */
297#define ALIGNED_RX_SKB_ADDR(addr) \ 297#define ALIGNED_RX_SKB_ADDR(addr) \
298 ((((unsigned long)(addr) + (64 - 1)) & ~(64 - 1)) - (unsigned long)(addr)) 298 ((((unsigned long)(addr) + (64 - 1)) & ~(64 - 1)) - (unsigned long)(addr))
299static inline struct sk_buff *myri_alloc_skb(unsigned int length, int gfp_flags) 299static inline struct sk_buff *myri_alloc_skb(unsigned int length, gfp_t gfp_flags)
300{ 300{
301 struct sk_buff *skb; 301 struct sk_buff *skb;
302 302
diff --git a/drivers/net/ne.c b/drivers/net/ne.c
index d209a1556b2e..0de8fdd2aa86 100644
--- a/drivers/net/ne.c
+++ b/drivers/net/ne.c
@@ -54,6 +54,10 @@ static const char version2[] =
54#include <asm/system.h> 54#include <asm/system.h>
55#include <asm/io.h> 55#include <asm/io.h>
56 56
57#if defined(CONFIG_TOSHIBA_RBTX4927) || defined(CONFIG_TOSHIBA_RBTX4938)
58#include <asm/tx4938/rbtx4938.h>
59#endif
60
57#include "8390.h" 61#include "8390.h"
58 62
59#define DRV_NAME "ne" 63#define DRV_NAME "ne"
@@ -111,6 +115,9 @@ bad_clone_list[] __initdata = {
111 {"E-LAN100", "E-LAN200", {0x00, 0x00, 0x5d}}, /* Broken ne1000 clones */ 115 {"E-LAN100", "E-LAN200", {0x00, 0x00, 0x5d}}, /* Broken ne1000 clones */
112 {"PCM-4823", "PCM-4823", {0x00, 0xc0, 0x6c}}, /* Broken Advantech MoBo */ 116 {"PCM-4823", "PCM-4823", {0x00, 0xc0, 0x6c}}, /* Broken Advantech MoBo */
113 {"REALTEK", "RTL8019", {0x00, 0x00, 0xe8}}, /* no-name with Realtek chip */ 117 {"REALTEK", "RTL8019", {0x00, 0x00, 0xe8}}, /* no-name with Realtek chip */
118#if defined(CONFIG_TOSHIBA_RBTX4927) || defined(CONFIG_TOSHIBA_RBTX4938)
119 {"RBHMA4X00-RTL8019", "RBHMA4X00/RTL8019", {0x00, 0x60, 0x0a}}, /* Toshiba built-in */
120#endif
114 {"LCS-8834", "LCS-8836", {0x04, 0x04, 0x37}}, /* ShinyNet (SET) */ 121 {"LCS-8834", "LCS-8836", {0x04, 0x04, 0x37}}, /* ShinyNet (SET) */
115 {NULL,} 122 {NULL,}
116}; 123};
@@ -226,6 +233,10 @@ struct net_device * __init ne_probe(int unit)
226 sprintf(dev->name, "eth%d", unit); 233 sprintf(dev->name, "eth%d", unit);
227 netdev_boot_setup_check(dev); 234 netdev_boot_setup_check(dev);
228 235
236#ifdef CONFIG_TOSHIBA_RBTX4938
237 dev->base_addr = 0x07f20280;
238 dev->irq = RBTX4938_RTL_8019_IRQ;
239#endif
229 err = do_ne_probe(dev); 240 err = do_ne_probe(dev);
230 if (err) 241 if (err)
231 goto out; 242 goto out;
@@ -506,6 +517,10 @@ static int __init ne_probe1(struct net_device *dev, int ioaddr)
506 ei_status.name = name; 517 ei_status.name = name;
507 ei_status.tx_start_page = start_page; 518 ei_status.tx_start_page = start_page;
508 ei_status.stop_page = stop_page; 519 ei_status.stop_page = stop_page;
520#if defined(CONFIG_TOSHIBA_RBTX4927) || defined(CONFIG_TOSHIBA_RBTX4938)
521 wordlength = 1;
522#endif
523
509#ifdef CONFIG_PLAT_OAKS32R 524#ifdef CONFIG_PLAT_OAKS32R
510 ei_status.word16 = 0; 525 ei_status.word16 = 0;
511#else 526#else
diff --git a/drivers/net/ne2k-pci.c b/drivers/net/ne2k-pci.c
index f1c01ac29102..d11821dd86ed 100644
--- a/drivers/net/ne2k-pci.c
+++ b/drivers/net/ne2k-pci.c
@@ -372,6 +372,7 @@ static int __devinit ne2k_pci_init_one (struct pci_dev *pdev,
372 printk("%2.2X%s", SA_prom[i], i == 5 ? ".\n": ":"); 372 printk("%2.2X%s", SA_prom[i], i == 5 ? ".\n": ":");
373 dev->dev_addr[i] = SA_prom[i]; 373 dev->dev_addr[i] = SA_prom[i];
374 } 374 }
375 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
375 376
376 return 0; 377 return 0;
377 378
@@ -637,6 +638,7 @@ static struct ethtool_ops ne2k_pci_ethtool_ops = {
637 .get_drvinfo = ne2k_pci_get_drvinfo, 638 .get_drvinfo = ne2k_pci_get_drvinfo,
638 .get_tx_csum = ethtool_op_get_tx_csum, 639 .get_tx_csum = ethtool_op_get_tx_csum,
639 .get_sg = ethtool_op_get_sg, 640 .get_sg = ethtool_op_get_sg,
641 .get_perm_addr = ethtool_op_get_perm_addr,
640}; 642};
641 643
642static void __devexit ne2k_pci_remove_one (struct pci_dev *pdev) 644static void __devexit ne2k_pci_remove_one (struct pci_dev *pdev)
@@ -673,7 +675,6 @@ static int ne2k_pci_resume (struct pci_dev *pdev)
673 pci_set_power_state(pdev, 0); 675 pci_set_power_state(pdev, 0);
674 pci_restore_state(pdev); 676 pci_restore_state(pdev);
675 pci_enable_device(pdev); 677 pci_enable_device(pdev);
676 pci_set_master(pdev);
677 NS8390_init(dev, 1); 678 NS8390_init(dev, 1);
678 netif_device_attach(dev); 679 netif_device_attach(dev);
679 680
diff --git a/drivers/net/ni65.c b/drivers/net/ni65.c
index 925d1dfcc4dc..bb42ff218484 100644
--- a/drivers/net/ni65.c
+++ b/drivers/net/ni65.c
@@ -696,8 +696,7 @@ static void ni65_free_buffer(struct priv *p)
696 return; 696 return;
697 697
698 for(i=0;i<TMDNUM;i++) { 698 for(i=0;i<TMDNUM;i++) {
699 if(p->tmdbounce[i]) 699 kfree(p->tmdbounce[i]);
700 kfree(p->tmdbounce[i]);
701#ifdef XMT_VIA_SKB 700#ifdef XMT_VIA_SKB
702 if(p->tmd_skb[i]) 701 if(p->tmd_skb[i])
703 dev_kfree_skb(p->tmd_skb[i]); 702 dev_kfree_skb(p->tmd_skb[i]);
@@ -710,12 +709,10 @@ static void ni65_free_buffer(struct priv *p)
710 if(p->recv_skb[i]) 709 if(p->recv_skb[i])
711 dev_kfree_skb(p->recv_skb[i]); 710 dev_kfree_skb(p->recv_skb[i]);
712#else 711#else
713 if(p->recvbounce[i]) 712 kfree(p->recvbounce[i]);
714 kfree(p->recvbounce[i]);
715#endif 713#endif
716 } 714 }
717 if(p->self) 715 kfree(p->self);
718 kfree(p->self);
719} 716}
720 717
721 718
diff --git a/drivers/net/ns83820.c b/drivers/net/ns83820.c
index e4811b42a6b7..a3c3fc9c0d8a 100644
--- a/drivers/net/ns83820.c
+++ b/drivers/net/ns83820.c
@@ -1632,8 +1632,7 @@ static void ns83820_run_bist(struct net_device *ndev, const char *name, u32 enab
1632 timed_out = 1; 1632 timed_out = 1;
1633 break; 1633 break;
1634 } 1634 }
1635 set_current_state(TASK_UNINTERRUPTIBLE); 1635 schedule_timeout_uninterruptible(1);
1636 schedule_timeout(1);
1637 } 1636 }
1638 1637
1639 if (status & fail) 1638 if (status & fail)
diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c
index 9f22d138e3ad..818c185d6438 100644
--- a/drivers/net/pcmcia/pcnet_cs.c
+++ b/drivers/net/pcmcia/pcnet_cs.c
@@ -1020,6 +1020,12 @@ static void set_misc_reg(struct net_device *dev)
1020 } else { 1020 } else {
1021 outb(full_duplex ? 4 : 0, nic_base + DLINK_DIAG); 1021 outb(full_duplex ? 4 : 0, nic_base + DLINK_DIAG);
1022 } 1022 }
1023 } else if (info->flags & IS_DL10019) {
1024 /* Advertise 100F, 100H, 10F, 10H */
1025 mdio_write(nic_base + DLINK_GPIO, info->eth_phy, 4, 0x01e1);
1026 /* Restart MII autonegotiation */
1027 mdio_write(nic_base + DLINK_GPIO, info->eth_phy, 0, 0x0000);
1028 mdio_write(nic_base + DLINK_GPIO, info->eth_phy, 0, 0x1200);
1023 } 1029 }
1024} 1030}
1025 1031
diff --git a/drivers/net/pcnet32.c b/drivers/net/pcnet32.c
index 113b68099216..70fe81a89df9 100644
--- a/drivers/net/pcnet32.c
+++ b/drivers/net/pcnet32.c
@@ -22,8 +22,8 @@
22 *************************************************************************/ 22 *************************************************************************/
23 23
24#define DRV_NAME "pcnet32" 24#define DRV_NAME "pcnet32"
25#define DRV_VERSION "1.30j" 25#define DRV_VERSION "1.31a"
26#define DRV_RELDATE "29.04.2005" 26#define DRV_RELDATE "12.Sep.2005"
27#define PFX DRV_NAME ": " 27#define PFX DRV_NAME ": "
28 28
29static const char *version = 29static const char *version =
@@ -257,6 +257,9 @@ static int homepna[MAX_UNITS];
257 * v1.30h 24 Jun 2004 Don Fry correctly select auto, speed, duplex in bcr32. 257 * v1.30h 24 Jun 2004 Don Fry correctly select auto, speed, duplex in bcr32.
258 * v1.30i 28 Jun 2004 Don Fry change to use module_param. 258 * v1.30i 28 Jun 2004 Don Fry change to use module_param.
259 * v1.30j 29 Apr 2005 Don Fry fix skb/map leak with loopback test. 259 * v1.30j 29 Apr 2005 Don Fry fix skb/map leak with loopback test.
260 * v1.31 02 Sep 2005 Hubert WS Lin <wslin@tw.ibm.c0m> added set_ringparam().
261 * v1.31a 12 Sep 2005 Hubert WS Lin <wslin@tw.ibm.c0m> set min ring size to 4
262 * to allow loopback test to work unchanged.
260 */ 263 */
261 264
262 265
@@ -266,17 +269,17 @@ static int homepna[MAX_UNITS];
266 * That translates to 2 (4 == 2^^2) and 4 (16 == 2^^4). 269 * That translates to 2 (4 == 2^^2) and 4 (16 == 2^^4).
267 */ 270 */
268#ifndef PCNET32_LOG_TX_BUFFERS 271#ifndef PCNET32_LOG_TX_BUFFERS
269#define PCNET32_LOG_TX_BUFFERS 4 272#define PCNET32_LOG_TX_BUFFERS 4
270#define PCNET32_LOG_RX_BUFFERS 5 273#define PCNET32_LOG_RX_BUFFERS 5
274#define PCNET32_LOG_MAX_TX_BUFFERS 9 /* 2^9 == 512 */
275#define PCNET32_LOG_MAX_RX_BUFFERS 9
271#endif 276#endif
272 277
273#define TX_RING_SIZE (1 << (PCNET32_LOG_TX_BUFFERS)) 278#define TX_RING_SIZE (1 << (PCNET32_LOG_TX_BUFFERS))
274#define TX_RING_MOD_MASK (TX_RING_SIZE - 1) 279#define TX_MAX_RING_SIZE (1 << (PCNET32_LOG_MAX_TX_BUFFERS))
275#define TX_RING_LEN_BITS ((PCNET32_LOG_TX_BUFFERS) << 12)
276 280
277#define RX_RING_SIZE (1 << (PCNET32_LOG_RX_BUFFERS)) 281#define RX_RING_SIZE (1 << (PCNET32_LOG_RX_BUFFERS))
278#define RX_RING_MOD_MASK (RX_RING_SIZE - 1) 282#define RX_MAX_RING_SIZE (1 << (PCNET32_LOG_MAX_RX_BUFFERS))
279#define RX_RING_LEN_BITS ((PCNET32_LOG_RX_BUFFERS) << 4)
280 283
281#define PKT_BUF_SZ 1544 284#define PKT_BUF_SZ 1544
282 285
@@ -334,14 +337,14 @@ struct pcnet32_access {
334}; 337};
335 338
336/* 339/*
337 * The first three fields of pcnet32_private are read by the ethernet device 340 * The first field of pcnet32_private is read by the ethernet device
338 * so we allocate the structure should be allocated by pci_alloc_consistent(). 341 * so the structure should be allocated using pci_alloc_consistent().
339 */ 342 */
340struct pcnet32_private { 343struct pcnet32_private {
341 /* The Tx and Rx ring entries must be aligned on 16-byte boundaries in 32bit mode. */
342 struct pcnet32_rx_head rx_ring[RX_RING_SIZE];
343 struct pcnet32_tx_head tx_ring[TX_RING_SIZE];
344 struct pcnet32_init_block init_block; 344 struct pcnet32_init_block init_block;
345 /* The Tx and Rx ring entries must be aligned on 16-byte boundaries in 32bit mode. */
346 struct pcnet32_rx_head *rx_ring;
347 struct pcnet32_tx_head *tx_ring;
345 dma_addr_t dma_addr; /* DMA address of beginning of this 348 dma_addr_t dma_addr; /* DMA address of beginning of this
346 object, returned by 349 object, returned by
347 pci_alloc_consistent */ 350 pci_alloc_consistent */
@@ -349,13 +352,21 @@ struct pcnet32_private {
349 structure */ 352 structure */
350 const char *name; 353 const char *name;
351 /* The saved address of a sent-in-place packet/buffer, for skfree(). */ 354 /* The saved address of a sent-in-place packet/buffer, for skfree(). */
352 struct sk_buff *tx_skbuff[TX_RING_SIZE]; 355 struct sk_buff **tx_skbuff;
353 struct sk_buff *rx_skbuff[RX_RING_SIZE]; 356 struct sk_buff **rx_skbuff;
354 dma_addr_t tx_dma_addr[TX_RING_SIZE]; 357 dma_addr_t *tx_dma_addr;
355 dma_addr_t rx_dma_addr[RX_RING_SIZE]; 358 dma_addr_t *rx_dma_addr;
356 struct pcnet32_access a; 359 struct pcnet32_access a;
357 spinlock_t lock; /* Guard lock */ 360 spinlock_t lock; /* Guard lock */
358 unsigned int cur_rx, cur_tx; /* The next free ring entry */ 361 unsigned int cur_rx, cur_tx; /* The next free ring entry */
362 unsigned int rx_ring_size; /* current rx ring size */
363 unsigned int tx_ring_size; /* current tx ring size */
364 unsigned int rx_mod_mask; /* rx ring modular mask */
365 unsigned int tx_mod_mask; /* tx ring modular mask */
366 unsigned short rx_len_bits;
367 unsigned short tx_len_bits;
368 dma_addr_t rx_ring_dma_addr;
369 dma_addr_t tx_ring_dma_addr;
359 unsigned int dirty_rx, dirty_tx; /* The ring entries to be free()ed. */ 370 unsigned int dirty_rx, dirty_tx; /* The ring entries to be free()ed. */
360 struct net_device_stats stats; 371 struct net_device_stats stats;
361 char tx_full; 372 char tx_full;
@@ -397,6 +408,9 @@ static int pcnet32_get_regs_len(struct net_device *dev);
397static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs, 408static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
398 void *ptr); 409 void *ptr);
399static void pcnet32_purge_tx_ring(struct net_device *dev); 410static void pcnet32_purge_tx_ring(struct net_device *dev);
411static int pcnet32_alloc_ring(struct net_device *dev);
412static void pcnet32_free_ring(struct net_device *dev);
413
400 414
401enum pci_flags_bit { 415enum pci_flags_bit {
402 PCI_USES_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4, 416 PCI_USES_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4,
@@ -613,10 +627,62 @@ static void pcnet32_get_ringparam(struct net_device *dev, struct ethtool_ringpar
613{ 627{
614 struct pcnet32_private *lp = dev->priv; 628 struct pcnet32_private *lp = dev->priv;
615 629
616 ering->tx_max_pending = TX_RING_SIZE - 1; 630 ering->tx_max_pending = TX_MAX_RING_SIZE - 1;
617 ering->tx_pending = lp->cur_tx - lp->dirty_tx; 631 ering->tx_pending = lp->tx_ring_size - 1;
618 ering->rx_max_pending = RX_RING_SIZE - 1; 632 ering->rx_max_pending = RX_MAX_RING_SIZE - 1;
619 ering->rx_pending = lp->cur_rx & RX_RING_MOD_MASK; 633 ering->rx_pending = lp->rx_ring_size - 1;
634}
635
636static int pcnet32_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
637{
638 struct pcnet32_private *lp = dev->priv;
639 unsigned long flags;
640 int i;
641
642 if (ering->rx_mini_pending || ering->rx_jumbo_pending)
643 return -EINVAL;
644
645 if (netif_running(dev))
646 pcnet32_close(dev);
647
648 spin_lock_irqsave(&lp->lock, flags);
649 pcnet32_free_ring(dev);
650 lp->tx_ring_size = min(ering->tx_pending, (unsigned int) TX_MAX_RING_SIZE);
651 lp->rx_ring_size = min(ering->rx_pending, (unsigned int) RX_MAX_RING_SIZE);
652
653 /* set the minimum ring size to 4, to allow the loopback test to work
654 * unchanged.
655 */
656 for (i = 2; i <= PCNET32_LOG_MAX_TX_BUFFERS; i++) {
657 if (lp->tx_ring_size <= (1 << i))
658 break;
659 }
660 lp->tx_ring_size = (1 << i);
661 lp->tx_mod_mask = lp->tx_ring_size - 1;
662 lp->tx_len_bits = (i << 12);
663
664 for (i = 2; i <= PCNET32_LOG_MAX_RX_BUFFERS; i++) {
665 if (lp->rx_ring_size <= (1 << i))
666 break;
667 }
668 lp->rx_ring_size = (1 << i);
669 lp->rx_mod_mask = lp->rx_ring_size - 1;
670 lp->rx_len_bits = (i << 4);
671
672 if (pcnet32_alloc_ring(dev)) {
673 pcnet32_free_ring(dev);
674 return -ENOMEM;
675 }
676
677 spin_unlock_irqrestore(&lp->lock, flags);
678
679 if (pcnet32_debug & NETIF_MSG_DRV)
680 printk(KERN_INFO PFX "Ring Param Settings: RX: %d, TX: %d\n", lp->rx_ring_size, lp->tx_ring_size);
681
682 if (netif_running(dev))
683 pcnet32_open(dev);
684
685 return 0;
620} 686}
621 687
622static void pcnet32_get_strings(struct net_device *dev, u32 stringset, u8 *data) 688static void pcnet32_get_strings(struct net_device *dev, u32 stringset, u8 *data)
@@ -948,6 +1014,7 @@ static struct ethtool_ops pcnet32_ethtool_ops = {
948 .nway_reset = pcnet32_nway_reset, 1014 .nway_reset = pcnet32_nway_reset,
949 .get_link = pcnet32_get_link, 1015 .get_link = pcnet32_get_link,
950 .get_ringparam = pcnet32_get_ringparam, 1016 .get_ringparam = pcnet32_get_ringparam,
1017 .set_ringparam = pcnet32_set_ringparam,
951 .get_tx_csum = ethtool_op_get_tx_csum, 1018 .get_tx_csum = ethtool_op_get_tx_csum,
952 .get_sg = ethtool_op_get_sg, 1019 .get_sg = ethtool_op_get_sg,
953 .get_tso = ethtool_op_get_tso, 1020 .get_tso = ethtool_op_get_tso,
@@ -957,6 +1024,7 @@ static struct ethtool_ops pcnet32_ethtool_ops = {
957 .phys_id = pcnet32_phys_id, 1024 .phys_id = pcnet32_phys_id,
958 .get_regs_len = pcnet32_get_regs_len, 1025 .get_regs_len = pcnet32_get_regs_len,
959 .get_regs = pcnet32_get_regs, 1026 .get_regs = pcnet32_get_regs,
1027 .get_perm_addr = ethtool_op_get_perm_addr,
960}; 1028};
961 1029
962/* only probes for non-PCI devices, the rest are handled by 1030/* only probes for non-PCI devices, the rest are handled by
@@ -1185,9 +1253,10 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
1185 memcpy(dev->dev_addr, promaddr, 6); 1253 memcpy(dev->dev_addr, promaddr, 6);
1186 } 1254 }
1187 } 1255 }
1256 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
1188 1257
1189 /* if the ethernet address is not valid, force to 00:00:00:00:00:00 */ 1258 /* if the ethernet address is not valid, force to 00:00:00:00:00:00 */
1190 if (!is_valid_ether_addr(dev->dev_addr)) 1259 if (!is_valid_ether_addr(dev->perm_addr))
1191 memset(dev->dev_addr, 0, sizeof(dev->dev_addr)); 1260 memset(dev->dev_addr, 0, sizeof(dev->dev_addr));
1192 1261
1193 if (pcnet32_debug & NETIF_MSG_PROBE) { 1262 if (pcnet32_debug & NETIF_MSG_PROBE) {
@@ -1239,6 +1308,12 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
1239 dev->priv = lp; 1308 dev->priv = lp;
1240 lp->name = chipname; 1309 lp->name = chipname;
1241 lp->shared_irq = shared; 1310 lp->shared_irq = shared;
1311 lp->tx_ring_size = TX_RING_SIZE; /* default tx ring size */
1312 lp->rx_ring_size = RX_RING_SIZE; /* default rx ring size */
1313 lp->tx_mod_mask = lp->tx_ring_size - 1;
1314 lp->rx_mod_mask = lp->rx_ring_size - 1;
1315 lp->tx_len_bits = (PCNET32_LOG_TX_BUFFERS << 12);
1316 lp->rx_len_bits = (PCNET32_LOG_RX_BUFFERS << 4);
1242 lp->mii_if.full_duplex = fdx; 1317 lp->mii_if.full_duplex = fdx;
1243 lp->mii_if.phy_id_mask = 0x1f; 1318 lp->mii_if.phy_id_mask = 0x1f;
1244 lp->mii_if.reg_num_mask = 0x1f; 1319 lp->mii_if.reg_num_mask = 0x1f;
@@ -1265,21 +1340,23 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
1265 } 1340 }
1266 lp->a = *a; 1341 lp->a = *a;
1267 1342
1343 if (pcnet32_alloc_ring(dev)) {
1344 ret = -ENOMEM;
1345 goto err_free_ring;
1346 }
1268 /* detect special T1/E1 WAN card by checking for MAC address */ 1347 /* detect special T1/E1 WAN card by checking for MAC address */
1269 if (dev->dev_addr[0] == 0x00 && dev->dev_addr[1] == 0xe0 1348 if (dev->dev_addr[0] == 0x00 && dev->dev_addr[1] == 0xe0
1270 && dev->dev_addr[2] == 0x75) 1349 && dev->dev_addr[2] == 0x75)
1271 lp->options = PCNET32_PORT_FD | PCNET32_PORT_GPSI; 1350 lp->options = PCNET32_PORT_FD | PCNET32_PORT_GPSI;
1272 1351
1273 lp->init_block.mode = le16_to_cpu(0x0003); /* Disable Rx and Tx. */ 1352 lp->init_block.mode = le16_to_cpu(0x0003); /* Disable Rx and Tx. */
1274 lp->init_block.tlen_rlen = le16_to_cpu(TX_RING_LEN_BITS | RX_RING_LEN_BITS); 1353 lp->init_block.tlen_rlen = le16_to_cpu(lp->tx_len_bits | lp->rx_len_bits);
1275 for (i = 0; i < 6; i++) 1354 for (i = 0; i < 6; i++)
1276 lp->init_block.phys_addr[i] = dev->dev_addr[i]; 1355 lp->init_block.phys_addr[i] = dev->dev_addr[i];
1277 lp->init_block.filter[0] = 0x00000000; 1356 lp->init_block.filter[0] = 0x00000000;
1278 lp->init_block.filter[1] = 0x00000000; 1357 lp->init_block.filter[1] = 0x00000000;
1279 lp->init_block.rx_ring = (u32)le32_to_cpu(lp->dma_addr + 1358 lp->init_block.rx_ring = (u32)le32_to_cpu(lp->rx_ring_dma_addr);
1280 offsetof(struct pcnet32_private, rx_ring)); 1359 lp->init_block.tx_ring = (u32)le32_to_cpu(lp->tx_ring_dma_addr);
1281 lp->init_block.tx_ring = (u32)le32_to_cpu(lp->dma_addr +
1282 offsetof(struct pcnet32_private, tx_ring));
1283 1360
1284 /* switch pcnet32 to 32bit mode */ 1361 /* switch pcnet32 to 32bit mode */
1285 a->write_bcr(ioaddr, 20, 2); 1362 a->write_bcr(ioaddr, 20, 2);
@@ -1310,7 +1387,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
1310 if (pcnet32_debug & NETIF_MSG_PROBE) 1387 if (pcnet32_debug & NETIF_MSG_PROBE)
1311 printk(", failed to detect IRQ line.\n"); 1388 printk(", failed to detect IRQ line.\n");
1312 ret = -ENODEV; 1389 ret = -ENODEV;
1313 goto err_free_consistent; 1390 goto err_free_ring;
1314 } 1391 }
1315 if (pcnet32_debug & NETIF_MSG_PROBE) 1392 if (pcnet32_debug & NETIF_MSG_PROBE)
1316 printk(", probed IRQ %d.\n", dev->irq); 1393 printk(", probed IRQ %d.\n", dev->irq);
@@ -1341,7 +1418,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
1341 1418
1342 /* Fill in the generic fields of the device structure. */ 1419 /* Fill in the generic fields of the device structure. */
1343 if (register_netdev(dev)) 1420 if (register_netdev(dev))
1344 goto err_free_consistent; 1421 goto err_free_ring;
1345 1422
1346 if (pdev) { 1423 if (pdev) {
1347 pci_set_drvdata(pdev, dev); 1424 pci_set_drvdata(pdev, dev);
@@ -1359,6 +1436,8 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
1359 1436
1360 return 0; 1437 return 0;
1361 1438
1439err_free_ring:
1440 pcnet32_free_ring(dev);
1362err_free_consistent: 1441err_free_consistent:
1363 pci_free_consistent(lp->pci_dev, sizeof(*lp), lp, lp->dma_addr); 1442 pci_free_consistent(lp->pci_dev, sizeof(*lp), lp, lp->dma_addr);
1364err_free_netdev: 1443err_free_netdev:
@@ -1369,6 +1448,86 @@ err_release_region:
1369} 1448}
1370 1449
1371 1450
1451static int pcnet32_alloc_ring(struct net_device *dev)
1452{
1453 struct pcnet32_private *lp = dev->priv;
1454
1455 if ((lp->tx_ring = pci_alloc_consistent(lp->pci_dev, sizeof(struct pcnet32_tx_head) * lp->tx_ring_size,
1456 &lp->tx_ring_dma_addr)) == NULL) {
1457 if (pcnet32_debug & NETIF_MSG_DRV)
1458 printk(KERN_ERR PFX "Consistent memory allocation failed.\n");
1459 return -ENOMEM;
1460 }
1461
1462 if ((lp->rx_ring = pci_alloc_consistent(lp->pci_dev, sizeof(struct pcnet32_rx_head) * lp->rx_ring_size,
1463 &lp->rx_ring_dma_addr)) == NULL) {
1464 if (pcnet32_debug & NETIF_MSG_DRV)
1465 printk(KERN_ERR PFX "Consistent memory allocation failed.\n");
1466 return -ENOMEM;
1467 }
1468
1469 if (!(lp->tx_dma_addr = kmalloc(sizeof(dma_addr_t) * lp->tx_ring_size, GFP_ATOMIC))) {
1470 if (pcnet32_debug & NETIF_MSG_DRV)
1471 printk(KERN_ERR PFX "Memory allocation failed.\n");
1472 return -ENOMEM;
1473 }
1474 memset(lp->tx_dma_addr, 0, sizeof(dma_addr_t) * lp->tx_ring_size);
1475
1476 if (!(lp->rx_dma_addr = kmalloc(sizeof(dma_addr_t) * lp->rx_ring_size, GFP_ATOMIC))) {
1477 if (pcnet32_debug & NETIF_MSG_DRV)
1478 printk(KERN_ERR PFX "Memory allocation failed.\n");
1479 return -ENOMEM;
1480 }
1481 memset(lp->rx_dma_addr, 0, sizeof(dma_addr_t) * lp->rx_ring_size);
1482
1483 if (!(lp->tx_skbuff = kmalloc(sizeof(struct sk_buff *) * lp->tx_ring_size, GFP_ATOMIC))) {
1484 if (pcnet32_debug & NETIF_MSG_DRV)
1485 printk(KERN_ERR PFX "Memory allocation failed.\n");
1486 return -ENOMEM;
1487 }
1488 memset(lp->tx_skbuff, 0, sizeof(struct sk_buff *) * lp->tx_ring_size);
1489
1490 if (!(lp->rx_skbuff = kmalloc(sizeof(struct sk_buff *) * lp->rx_ring_size, GFP_ATOMIC))) {
1491 if (pcnet32_debug & NETIF_MSG_DRV)
1492 printk(KERN_ERR PFX "Memory allocation failed.\n");
1493 return -ENOMEM;
1494 }
1495 memset(lp->rx_skbuff, 0, sizeof(struct sk_buff *) * lp->rx_ring_size);
1496
1497 return 0;
1498}
1499
1500
1501static void pcnet32_free_ring(struct net_device *dev)
1502{
1503 struct pcnet32_private *lp = dev->priv;
1504
1505 kfree(lp->tx_skbuff);
1506 lp->tx_skbuff = NULL;
1507
1508 kfree(lp->rx_skbuff);
1509 lp->rx_skbuff = NULL;
1510
1511 kfree(lp->tx_dma_addr);
1512 lp->tx_dma_addr = NULL;
1513
1514 kfree(lp->rx_dma_addr);
1515 lp->rx_dma_addr = NULL;
1516
1517 if (lp->tx_ring) {
1518 pci_free_consistent(lp->pci_dev, sizeof(struct pcnet32_tx_head) * lp->tx_ring_size,
1519 lp->tx_ring, lp->tx_ring_dma_addr);
1520 lp->tx_ring = NULL;
1521 }
1522
1523 if (lp->rx_ring) {
1524 pci_free_consistent(lp->pci_dev, sizeof(struct pcnet32_rx_head) * lp->rx_ring_size,
1525 lp->rx_ring, lp->rx_ring_dma_addr);
1526 lp->rx_ring = NULL;
1527 }
1528}
1529
1530
1372static int 1531static int
1373pcnet32_open(struct net_device *dev) 1532pcnet32_open(struct net_device *dev)
1374{ 1533{
@@ -1400,8 +1559,8 @@ pcnet32_open(struct net_device *dev)
1400 if (netif_msg_ifup(lp)) 1559 if (netif_msg_ifup(lp))
1401 printk(KERN_DEBUG "%s: pcnet32_open() irq %d tx/rx rings %#x/%#x init %#x.\n", 1560 printk(KERN_DEBUG "%s: pcnet32_open() irq %d tx/rx rings %#x/%#x init %#x.\n",
1402 dev->name, dev->irq, 1561 dev->name, dev->irq,
1403 (u32) (lp->dma_addr + offsetof(struct pcnet32_private, tx_ring)), 1562 (u32) (lp->tx_ring_dma_addr),
1404 (u32) (lp->dma_addr + offsetof(struct pcnet32_private, rx_ring)), 1563 (u32) (lp->rx_ring_dma_addr),
1405 (u32) (lp->dma_addr + offsetof(struct pcnet32_private, init_block))); 1564 (u32) (lp->dma_addr + offsetof(struct pcnet32_private, init_block)));
1406 1565
1407 /* set/reset autoselect bit */ 1566 /* set/reset autoselect bit */
@@ -1521,7 +1680,7 @@ pcnet32_open(struct net_device *dev)
1521 1680
1522err_free_ring: 1681err_free_ring:
1523 /* free any allocated skbuffs */ 1682 /* free any allocated skbuffs */
1524 for (i = 0; i < RX_RING_SIZE; i++) { 1683 for (i = 0; i < lp->rx_ring_size; i++) {
1525 lp->rx_ring[i].status = 0; 1684 lp->rx_ring[i].status = 0;
1526 if (lp->rx_skbuff[i]) { 1685 if (lp->rx_skbuff[i]) {
1527 pci_unmap_single(lp->pci_dev, lp->rx_dma_addr[i], PKT_BUF_SZ-2, 1686 pci_unmap_single(lp->pci_dev, lp->rx_dma_addr[i], PKT_BUF_SZ-2,
@@ -1531,6 +1690,9 @@ err_free_ring:
1531 lp->rx_skbuff[i] = NULL; 1690 lp->rx_skbuff[i] = NULL;
1532 lp->rx_dma_addr[i] = 0; 1691 lp->rx_dma_addr[i] = 0;
1533 } 1692 }
1693
1694 pcnet32_free_ring(dev);
1695
1534 /* 1696 /*
1535 * Switch back to 16bit mode to avoid problems with dumb 1697 * Switch back to 16bit mode to avoid problems with dumb
1536 * DOS packet driver after a warm reboot 1698 * DOS packet driver after a warm reboot
@@ -1562,7 +1724,7 @@ pcnet32_purge_tx_ring(struct net_device *dev)
1562 struct pcnet32_private *lp = dev->priv; 1724 struct pcnet32_private *lp = dev->priv;
1563 int i; 1725 int i;
1564 1726
1565 for (i = 0; i < TX_RING_SIZE; i++) { 1727 for (i = 0; i < lp->tx_ring_size; i++) {
1566 lp->tx_ring[i].status = 0; /* CPU owns buffer */ 1728 lp->tx_ring[i].status = 0; /* CPU owns buffer */
1567 wmb(); /* Make sure adapter sees owner change */ 1729 wmb(); /* Make sure adapter sees owner change */
1568 if (lp->tx_skbuff[i]) { 1730 if (lp->tx_skbuff[i]) {
@@ -1587,7 +1749,7 @@ pcnet32_init_ring(struct net_device *dev)
1587 lp->cur_rx = lp->cur_tx = 0; 1749 lp->cur_rx = lp->cur_tx = 0;
1588 lp->dirty_rx = lp->dirty_tx = 0; 1750 lp->dirty_rx = lp->dirty_tx = 0;
1589 1751
1590 for (i = 0; i < RX_RING_SIZE; i++) { 1752 for (i = 0; i < lp->rx_ring_size; i++) {
1591 struct sk_buff *rx_skbuff = lp->rx_skbuff[i]; 1753 struct sk_buff *rx_skbuff = lp->rx_skbuff[i];
1592 if (rx_skbuff == NULL) { 1754 if (rx_skbuff == NULL) {
1593 if (!(rx_skbuff = lp->rx_skbuff[i] = dev_alloc_skb (PKT_BUF_SZ))) { 1755 if (!(rx_skbuff = lp->rx_skbuff[i] = dev_alloc_skb (PKT_BUF_SZ))) {
@@ -1611,20 +1773,18 @@ pcnet32_init_ring(struct net_device *dev)
1611 } 1773 }
1612 /* The Tx buffer address is filled in as needed, but we do need to clear 1774 /* The Tx buffer address is filled in as needed, but we do need to clear
1613 * the upper ownership bit. */ 1775 * the upper ownership bit. */
1614 for (i = 0; i < TX_RING_SIZE; i++) { 1776 for (i = 0; i < lp->tx_ring_size; i++) {
1615 lp->tx_ring[i].status = 0; /* CPU owns buffer */ 1777 lp->tx_ring[i].status = 0; /* CPU owns buffer */
1616 wmb(); /* Make sure adapter sees owner change */ 1778 wmb(); /* Make sure adapter sees owner change */
1617 lp->tx_ring[i].base = 0; 1779 lp->tx_ring[i].base = 0;
1618 lp->tx_dma_addr[i] = 0; 1780 lp->tx_dma_addr[i] = 0;
1619 } 1781 }
1620 1782
1621 lp->init_block.tlen_rlen = le16_to_cpu(TX_RING_LEN_BITS | RX_RING_LEN_BITS); 1783 lp->init_block.tlen_rlen = le16_to_cpu(lp->tx_len_bits | lp->rx_len_bits);
1622 for (i = 0; i < 6; i++) 1784 for (i = 0; i < 6; i++)
1623 lp->init_block.phys_addr[i] = dev->dev_addr[i]; 1785 lp->init_block.phys_addr[i] = dev->dev_addr[i];
1624 lp->init_block.rx_ring = (u32)le32_to_cpu(lp->dma_addr + 1786 lp->init_block.rx_ring = (u32)le32_to_cpu(lp->rx_ring_dma_addr);
1625 offsetof(struct pcnet32_private, rx_ring)); 1787 lp->init_block.tx_ring = (u32)le32_to_cpu(lp->tx_ring_dma_addr);
1626 lp->init_block.tx_ring = (u32)le32_to_cpu(lp->dma_addr +
1627 offsetof(struct pcnet32_private, tx_ring));
1628 wmb(); /* Make sure all changes are visible */ 1788 wmb(); /* Make sure all changes are visible */
1629 return 0; 1789 return 0;
1630} 1790}
@@ -1682,13 +1842,13 @@ pcnet32_tx_timeout (struct net_device *dev)
1682 printk(KERN_DEBUG " Ring data dump: dirty_tx %d cur_tx %d%s cur_rx %d.", 1842 printk(KERN_DEBUG " Ring data dump: dirty_tx %d cur_tx %d%s cur_rx %d.",
1683 lp->dirty_tx, lp->cur_tx, lp->tx_full ? " (full)" : "", 1843 lp->dirty_tx, lp->cur_tx, lp->tx_full ? " (full)" : "",
1684 lp->cur_rx); 1844 lp->cur_rx);
1685 for (i = 0 ; i < RX_RING_SIZE; i++) 1845 for (i = 0 ; i < lp->rx_ring_size; i++)
1686 printk("%s %08x %04x %08x %04x", i & 1 ? "" : "\n ", 1846 printk("%s %08x %04x %08x %04x", i & 1 ? "" : "\n ",
1687 le32_to_cpu(lp->rx_ring[i].base), 1847 le32_to_cpu(lp->rx_ring[i].base),
1688 (-le16_to_cpu(lp->rx_ring[i].buf_length)) & 0xffff, 1848 (-le16_to_cpu(lp->rx_ring[i].buf_length)) & 0xffff,
1689 le32_to_cpu(lp->rx_ring[i].msg_length), 1849 le32_to_cpu(lp->rx_ring[i].msg_length),
1690 le16_to_cpu(lp->rx_ring[i].status)); 1850 le16_to_cpu(lp->rx_ring[i].status));
1691 for (i = 0 ; i < TX_RING_SIZE; i++) 1851 for (i = 0 ; i < lp->tx_ring_size; i++)
1692 printk("%s %08x %04x %08x %04x", i & 1 ? "" : "\n ", 1852 printk("%s %08x %04x %08x %04x", i & 1 ? "" : "\n ",
1693 le32_to_cpu(lp->tx_ring[i].base), 1853 le32_to_cpu(lp->tx_ring[i].base),
1694 (-le16_to_cpu(lp->tx_ring[i].length)) & 0xffff, 1854 (-le16_to_cpu(lp->tx_ring[i].length)) & 0xffff,
@@ -1729,7 +1889,7 @@ pcnet32_start_xmit(struct sk_buff *skb, struct net_device *dev)
1729 /* Fill in a Tx ring entry */ 1889 /* Fill in a Tx ring entry */
1730 1890
1731 /* Mask to ring buffer boundary. */ 1891 /* Mask to ring buffer boundary. */
1732 entry = lp->cur_tx & TX_RING_MOD_MASK; 1892 entry = lp->cur_tx & lp->tx_mod_mask;
1733 1893
1734 /* Caution: the write order is important here, set the status 1894 /* Caution: the write order is important here, set the status
1735 * with the "ownership" bits last. */ 1895 * with the "ownership" bits last. */
@@ -1753,7 +1913,7 @@ pcnet32_start_xmit(struct sk_buff *skb, struct net_device *dev)
1753 1913
1754 dev->trans_start = jiffies; 1914 dev->trans_start = jiffies;
1755 1915
1756 if (lp->tx_ring[(entry+1) & TX_RING_MOD_MASK].base != 0) { 1916 if (lp->tx_ring[(entry+1) & lp->tx_mod_mask].base != 0) {
1757 lp->tx_full = 1; 1917 lp->tx_full = 1;
1758 netif_stop_queue(dev); 1918 netif_stop_queue(dev);
1759 } 1919 }
@@ -1806,7 +1966,7 @@ pcnet32_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1806 int delta; 1966 int delta;
1807 1967
1808 while (dirty_tx != lp->cur_tx) { 1968 while (dirty_tx != lp->cur_tx) {
1809 int entry = dirty_tx & TX_RING_MOD_MASK; 1969 int entry = dirty_tx & lp->tx_mod_mask;
1810 int status = (short)le16_to_cpu(lp->tx_ring[entry].status); 1970 int status = (short)le16_to_cpu(lp->tx_ring[entry].status);
1811 1971
1812 if (status < 0) 1972 if (status < 0)
@@ -1864,18 +2024,18 @@ pcnet32_interrupt(int irq, void *dev_id, struct pt_regs * regs)
1864 dirty_tx++; 2024 dirty_tx++;
1865 } 2025 }
1866 2026
1867 delta = (lp->cur_tx - dirty_tx) & (TX_RING_MOD_MASK + TX_RING_SIZE); 2027 delta = (lp->cur_tx - dirty_tx) & (lp->tx_mod_mask + lp->tx_ring_size);
1868 if (delta > TX_RING_SIZE) { 2028 if (delta > lp->tx_ring_size) {
1869 if (netif_msg_drv(lp)) 2029 if (netif_msg_drv(lp))
1870 printk(KERN_ERR "%s: out-of-sync dirty pointer, %d vs. %d, full=%d.\n", 2030 printk(KERN_ERR "%s: out-of-sync dirty pointer, %d vs. %d, full=%d.\n",
1871 dev->name, dirty_tx, lp->cur_tx, lp->tx_full); 2031 dev->name, dirty_tx, lp->cur_tx, lp->tx_full);
1872 dirty_tx += TX_RING_SIZE; 2032 dirty_tx += lp->tx_ring_size;
1873 delta -= TX_RING_SIZE; 2033 delta -= lp->tx_ring_size;
1874 } 2034 }
1875 2035
1876 if (lp->tx_full && 2036 if (lp->tx_full &&
1877 netif_queue_stopped(dev) && 2037 netif_queue_stopped(dev) &&
1878 delta < TX_RING_SIZE - 2) { 2038 delta < lp->tx_ring_size - 2) {
1879 /* The ring is no longer full, clear tbusy. */ 2039 /* The ring is no longer full, clear tbusy. */
1880 lp->tx_full = 0; 2040 lp->tx_full = 0;
1881 netif_wake_queue (dev); 2041 netif_wake_queue (dev);
@@ -1932,8 +2092,8 @@ static int
1932pcnet32_rx(struct net_device *dev) 2092pcnet32_rx(struct net_device *dev)
1933{ 2093{
1934 struct pcnet32_private *lp = dev->priv; 2094 struct pcnet32_private *lp = dev->priv;
1935 int entry = lp->cur_rx & RX_RING_MOD_MASK; 2095 int entry = lp->cur_rx & lp->rx_mod_mask;
1936 int boguscnt = RX_RING_SIZE / 2; 2096 int boguscnt = lp->rx_ring_size / 2;
1937 2097
1938 /* If we own the next entry, it's a new packet. Send it up. */ 2098 /* If we own the next entry, it's a new packet. Send it up. */
1939 while ((short)le16_to_cpu(lp->rx_ring[entry].status) >= 0) { 2099 while ((short)le16_to_cpu(lp->rx_ring[entry].status) >= 0) {
@@ -1998,12 +2158,12 @@ pcnet32_rx(struct net_device *dev)
1998 if (netif_msg_drv(lp)) 2158 if (netif_msg_drv(lp))
1999 printk(KERN_ERR "%s: Memory squeeze, deferring packet.\n", 2159 printk(KERN_ERR "%s: Memory squeeze, deferring packet.\n",
2000 dev->name); 2160 dev->name);
2001 for (i = 0; i < RX_RING_SIZE; i++) 2161 for (i = 0; i < lp->rx_ring_size; i++)
2002 if ((short)le16_to_cpu(lp->rx_ring[(entry+i) 2162 if ((short)le16_to_cpu(lp->rx_ring[(entry+i)
2003 & RX_RING_MOD_MASK].status) < 0) 2163 & lp->rx_mod_mask].status) < 0)
2004 break; 2164 break;
2005 2165
2006 if (i > RX_RING_SIZE -2) { 2166 if (i > lp->rx_ring_size -2) {
2007 lp->stats.rx_dropped++; 2167 lp->stats.rx_dropped++;
2008 lp->rx_ring[entry].status |= le16_to_cpu(0x8000); 2168 lp->rx_ring[entry].status |= le16_to_cpu(0x8000);
2009 wmb(); /* Make sure adapter sees owner change */ 2169 wmb(); /* Make sure adapter sees owner change */
@@ -2041,7 +2201,7 @@ pcnet32_rx(struct net_device *dev)
2041 lp->rx_ring[entry].buf_length = le16_to_cpu(2-PKT_BUF_SZ); 2201 lp->rx_ring[entry].buf_length = le16_to_cpu(2-PKT_BUF_SZ);
2042 wmb(); /* Make sure owner changes after all others are visible */ 2202 wmb(); /* Make sure owner changes after all others are visible */
2043 lp->rx_ring[entry].status |= le16_to_cpu(0x8000); 2203 lp->rx_ring[entry].status |= le16_to_cpu(0x8000);
2044 entry = (++lp->cur_rx) & RX_RING_MOD_MASK; 2204 entry = (++lp->cur_rx) & lp->rx_mod_mask;
2045 if (--boguscnt <= 0) break; /* don't stay in loop forever */ 2205 if (--boguscnt <= 0) break; /* don't stay in loop forever */
2046 } 2206 }
2047 2207
@@ -2084,7 +2244,7 @@ pcnet32_close(struct net_device *dev)
2084 spin_lock_irqsave(&lp->lock, flags); 2244 spin_lock_irqsave(&lp->lock, flags);
2085 2245
2086 /* free all allocated skbuffs */ 2246 /* free all allocated skbuffs */
2087 for (i = 0; i < RX_RING_SIZE; i++) { 2247 for (i = 0; i < lp->rx_ring_size; i++) {
2088 lp->rx_ring[i].status = 0; 2248 lp->rx_ring[i].status = 0;
2089 wmb(); /* Make sure adapter sees owner change */ 2249 wmb(); /* Make sure adapter sees owner change */
2090 if (lp->rx_skbuff[i]) { 2250 if (lp->rx_skbuff[i]) {
@@ -2096,7 +2256,7 @@ pcnet32_close(struct net_device *dev)
2096 lp->rx_dma_addr[i] = 0; 2256 lp->rx_dma_addr[i] = 0;
2097 } 2257 }
2098 2258
2099 for (i = 0; i < TX_RING_SIZE; i++) { 2259 for (i = 0; i < lp->tx_ring_size; i++) {
2100 lp->tx_ring[i].status = 0; /* CPU owns buffer */ 2260 lp->tx_ring[i].status = 0; /* CPU owns buffer */
2101 wmb(); /* Make sure adapter sees owner change */ 2261 wmb(); /* Make sure adapter sees owner change */
2102 if (lp->tx_skbuff[i]) { 2262 if (lp->tx_skbuff[i]) {
@@ -2265,6 +2425,7 @@ static void __devexit pcnet32_remove_one(struct pci_dev *pdev)
2265 struct pcnet32_private *lp = dev->priv; 2425 struct pcnet32_private *lp = dev->priv;
2266 2426
2267 unregister_netdev(dev); 2427 unregister_netdev(dev);
2428 pcnet32_free_ring(dev);
2268 release_region(dev->base_addr, PCNET32_TOTAL_SIZE); 2429 release_region(dev->base_addr, PCNET32_TOTAL_SIZE);
2269 pci_free_consistent(lp->pci_dev, sizeof(*lp), lp, lp->dma_addr); 2430 pci_free_consistent(lp->pci_dev, sizeof(*lp), lp, lp->dma_addr);
2270 free_netdev(dev); 2431 free_netdev(dev);
@@ -2340,6 +2501,7 @@ static void __exit pcnet32_cleanup_module(void)
2340 struct pcnet32_private *lp = pcnet32_dev->priv; 2501 struct pcnet32_private *lp = pcnet32_dev->priv;
2341 next_dev = lp->next; 2502 next_dev = lp->next;
2342 unregister_netdev(pcnet32_dev); 2503 unregister_netdev(pcnet32_dev);
2504 pcnet32_free_ring(pcnet32_dev);
2343 release_region(pcnet32_dev->base_addr, PCNET32_TOTAL_SIZE); 2505 release_region(pcnet32_dev->base_addr, PCNET32_TOTAL_SIZE);
2344 pci_free_consistent(lp->pci_dev, sizeof(*lp), lp, lp->dma_addr); 2506 pci_free_consistent(lp->pci_dev, sizeof(*lp), lp, lp->dma_addr);
2345 free_netdev(pcnet32_dev); 2507 free_netdev(pcnet32_dev);
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index 14f4de1a8180..c782a6329805 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -12,14 +12,6 @@ config PHYLIB
12 devices. This option provides infrastructure for 12 devices. This option provides infrastructure for
13 managing PHY devices. 13 managing PHY devices.
14 14
15config PHYCONTROL
16 bool " Support for automatically handling PHY state changes"
17 depends on PHYLIB
18 help
19 Adds code to perform all the work for keeping PHY link
20 state (speed/duplex/etc) up-to-date. Also handles
21 interrupts.
22
23comment "MII PHY device drivers" 15comment "MII PHY device drivers"
24 depends on PHYLIB 16 depends on PHYLIB
25 17
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 90630672703d..ad93b0da87f0 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -133,13 +133,9 @@ static int mdio_bus_suspend(struct device * dev, pm_message_t state)
133 int ret = 0; 133 int ret = 0;
134 struct device_driver *drv = dev->driver; 134 struct device_driver *drv = dev->driver;
135 135
136 if (drv && drv->suspend) { 136 if (drv && drv->suspend)
137 ret = drv->suspend(dev, state, SUSPEND_DISABLE); 137 ret = drv->suspend(dev, state);
138 if (ret == 0) 138
139 ret = drv->suspend(dev, state, SUSPEND_SAVE_STATE);
140 if (ret == 0)
141 ret = drv->suspend(dev, state, SUSPEND_POWER_DOWN);
142 }
143 return ret; 139 return ret;
144} 140}
145 141
@@ -148,13 +144,9 @@ static int mdio_bus_resume(struct device * dev)
148 int ret = 0; 144 int ret = 0;
149 struct device_driver *drv = dev->driver; 145 struct device_driver *drv = dev->driver;
150 146
151 if (drv && drv->resume) { 147 if (drv && drv->resume)
152 ret = drv->resume(dev, RESUME_POWER_ON); 148 ret = drv->resume(dev);
153 if (ret == 0) 149
154 ret = drv->resume(dev, RESUME_RESTORE_STATE);
155 if (ret == 0)
156 ret = drv->resume(dev, RESUME_ENABLE);
157 }
158 return ret; 150 return ret;
159} 151}
160 152
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index d9e11f93bf3a..9209da9dde0d 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -242,10 +242,6 @@ EXPORT_SYMBOL(phy_sanitize_settings);
242 * choose the next best ones from the ones selected, so we don't 242 * choose the next best ones from the ones selected, so we don't
243 * care if ethtool tries to give us bad values 243 * care if ethtool tries to give us bad values
244 * 244 *
245 * A note about the PHYCONTROL Layer. If you turn off
246 * CONFIG_PHYCONTROL, you will need to read the PHY status
247 * registers after this function completes, and update your
248 * controller manually.
249 */ 245 */
250int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd) 246int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd)
251{ 247{
@@ -380,7 +376,6 @@ int phy_start_aneg(struct phy_device *phydev)
380 376
381 err = phydev->drv->config_aneg(phydev); 377 err = phydev->drv->config_aneg(phydev);
382 378
383#ifdef CONFIG_PHYCONTROL
384 if (err < 0) 379 if (err < 0)
385 goto out_unlock; 380 goto out_unlock;
386 381
@@ -395,14 +390,12 @@ int phy_start_aneg(struct phy_device *phydev)
395 } 390 }
396 391
397out_unlock: 392out_unlock:
398#endif
399 spin_unlock(&phydev->lock); 393 spin_unlock(&phydev->lock);
400 return err; 394 return err;
401} 395}
402EXPORT_SYMBOL(phy_start_aneg); 396EXPORT_SYMBOL(phy_start_aneg);
403 397
404 398
405#ifdef CONFIG_PHYCONTROL
406static void phy_change(void *data); 399static void phy_change(void *data);
407static void phy_timer(unsigned long data); 400static void phy_timer(unsigned long data);
408 401
@@ -868,4 +861,3 @@ static void phy_timer(unsigned long data)
868 mod_timer(&phydev->phy_timer, jiffies + PHY_STATE_TIME * HZ); 861 mod_timer(&phydev->phy_timer, jiffies + PHY_STATE_TIME * HZ);
869} 862}
870 863
871#endif /* CONFIG_PHYCONTROL */
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 33f7bdb5857c..6da1aa0706a1 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -101,7 +101,6 @@ struct phy_device * get_phy_device(struct mii_bus *bus, int addr)
101 return dev; 101 return dev;
102} 102}
103 103
104#ifdef CONFIG_PHYCONTROL
105/* phy_prepare_link: 104/* phy_prepare_link:
106 * 105 *
107 * description: Tells the PHY infrastructure to handle the 106 * description: Tells the PHY infrastructure to handle the
@@ -160,8 +159,6 @@ void phy_disconnect(struct phy_device *phydev)
160} 159}
161EXPORT_SYMBOL(phy_disconnect); 160EXPORT_SYMBOL(phy_disconnect);
162 161
163#endif /* CONFIG_PHYCONTROL */
164
165/* phy_attach: 162/* phy_attach:
166 * 163 *
167 * description: Called by drivers to attach to a particular PHY 164 * description: Called by drivers to attach to a particular PHY
diff --git a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c
index 0df7e92b0bf8..d3c9958b00d0 100644
--- a/drivers/net/ppp_generic.c
+++ b/drivers/net/ppp_generic.c
@@ -863,7 +863,7 @@ static int __init ppp_init(void)
863 err = PTR_ERR(ppp_class); 863 err = PTR_ERR(ppp_class);
864 goto out_chrdev; 864 goto out_chrdev;
865 } 865 }
866 class_device_create(ppp_class, MKDEV(PPP_MAJOR, 0), NULL, "ppp"); 866 class_device_create(ppp_class, NULL, MKDEV(PPP_MAJOR, 0), NULL, "ppp");
867 err = devfs_mk_cdev(MKDEV(PPP_MAJOR, 0), 867 err = devfs_mk_cdev(MKDEV(PPP_MAJOR, 0),
868 S_IFCHR|S_IRUSR|S_IWUSR, "ppp"); 868 S_IFCHR|S_IRUSR|S_IWUSR, "ppp");
869 if (err) 869 if (err)
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index afb3f186b884..159b56a56ef4 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -1027,6 +1027,7 @@ static struct ethtool_ops rtl8169_ethtool_ops = {
1027 .get_strings = rtl8169_get_strings, 1027 .get_strings = rtl8169_get_strings,
1028 .get_stats_count = rtl8169_get_stats_count, 1028 .get_stats_count = rtl8169_get_stats_count,
1029 .get_ethtool_stats = rtl8169_get_ethtool_stats, 1029 .get_ethtool_stats = rtl8169_get_ethtool_stats,
1030 .get_perm_addr = ethtool_op_get_perm_addr,
1030}; 1031};
1031 1032
1032static void rtl8169_write_gmii_reg_bit(void __iomem *ioaddr, int reg, int bitnum, 1033static void rtl8169_write_gmii_reg_bit(void __iomem *ioaddr, int reg, int bitnum,
@@ -1511,6 +1512,7 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1511 /* Get MAC address. FIXME: read EEPROM */ 1512 /* Get MAC address. FIXME: read EEPROM */
1512 for (i = 0; i < MAC_ADDR_LEN; i++) 1513 for (i = 0; i < MAC_ADDR_LEN; i++)
1513 dev->dev_addr[i] = RTL_R8(MAC0 + i); 1514 dev->dev_addr[i] = RTL_R8(MAC0 + i);
1515 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
1514 1516
1515 dev->open = rtl8169_open; 1517 dev->open = rtl8169_open;
1516 dev->hard_start_xmit = rtl8169_start_xmit; 1518 dev->hard_start_xmit = rtl8169_start_xmit;
diff --git a/drivers/net/rionet.c b/drivers/net/rionet.c
new file mode 100644
index 000000000000..12cde0604580
--- /dev/null
+++ b/drivers/net/rionet.c
@@ -0,0 +1,574 @@
1/*
2 * rionet - Ethernet driver over RapidIO messaging services
3 *
4 * Copyright 2005 MontaVista Software, Inc.
5 * Matt Porter <mporter@kernel.crashing.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#include <linux/module.h>
14#include <linux/kernel.h>
15#include <linux/dma-mapping.h>
16#include <linux/delay.h>
17#include <linux/rio.h>
18#include <linux/rio_drv.h>
19#include <linux/rio_ids.h>
20
21#include <linux/netdevice.h>
22#include <linux/etherdevice.h>
23#include <linux/skbuff.h>
24#include <linux/crc32.h>
25#include <linux/ethtool.h>
26
27#define DRV_NAME "rionet"
28#define DRV_VERSION "0.2"
29#define DRV_AUTHOR "Matt Porter <mporter@kernel.crashing.org>"
30#define DRV_DESC "Ethernet over RapidIO"
31
32MODULE_AUTHOR(DRV_AUTHOR);
33MODULE_DESCRIPTION(DRV_DESC);
34MODULE_LICENSE("GPL");
35
36#define RIONET_DEFAULT_MSGLEVEL \
37 (NETIF_MSG_DRV | \
38 NETIF_MSG_LINK | \
39 NETIF_MSG_RX_ERR | \
40 NETIF_MSG_TX_ERR)
41
42#define RIONET_DOORBELL_JOIN 0x1000
43#define RIONET_DOORBELL_LEAVE 0x1001
44
45#define RIONET_MAILBOX 0
46
47#define RIONET_TX_RING_SIZE CONFIG_RIONET_TX_SIZE
48#define RIONET_RX_RING_SIZE CONFIG_RIONET_RX_SIZE
49
50static LIST_HEAD(rionet_peers);
51
52struct rionet_private {
53 struct rio_mport *mport;
54 struct sk_buff *rx_skb[RIONET_RX_RING_SIZE];
55 struct sk_buff *tx_skb[RIONET_TX_RING_SIZE];
56 struct net_device_stats stats;
57 int rx_slot;
58 int tx_slot;
59 int tx_cnt;
60 int ack_slot;
61 spinlock_t lock;
62 spinlock_t tx_lock;
63 u32 msg_enable;
64};
65
66struct rionet_peer {
67 struct list_head node;
68 struct rio_dev *rdev;
69 struct resource *res;
70};
71
72static int rionet_check = 0;
73static int rionet_capable = 1;
74
75/*
76 * This is a fast lookup table for for translating TX
77 * Ethernet packets into a destination RIO device. It
78 * could be made into a hash table to save memory depending
79 * on system trade-offs.
80 */
81static struct rio_dev *rionet_active[RIO_MAX_ROUTE_ENTRIES];
82
83#define is_rionet_capable(pef, src_ops, dst_ops) \
84 ((pef & RIO_PEF_INB_MBOX) && \
85 (pef & RIO_PEF_INB_DOORBELL) && \
86 (src_ops & RIO_SRC_OPS_DOORBELL) && \
87 (dst_ops & RIO_DST_OPS_DOORBELL))
88#define dev_rionet_capable(dev) \
89 is_rionet_capable(dev->pef, dev->src_ops, dev->dst_ops)
90
91#define RIONET_MAC_MATCH(x) (*(u32 *)x == 0x00010001)
92#define RIONET_GET_DESTID(x) (*(u16 *)(x + 4))
93
94static struct net_device_stats *rionet_stats(struct net_device *ndev)
95{
96 struct rionet_private *rnet = ndev->priv;
97 return &rnet->stats;
98}
99
100static int rionet_rx_clean(struct net_device *ndev)
101{
102 int i;
103 int error = 0;
104 struct rionet_private *rnet = ndev->priv;
105 void *data;
106
107 i = rnet->rx_slot;
108
109 do {
110 if (!rnet->rx_skb[i])
111 continue;
112
113 if (!(data = rio_get_inb_message(rnet->mport, RIONET_MAILBOX)))
114 break;
115
116 rnet->rx_skb[i]->data = data;
117 skb_put(rnet->rx_skb[i], RIO_MAX_MSG_SIZE);
118 rnet->rx_skb[i]->dev = ndev;
119 rnet->rx_skb[i]->protocol =
120 eth_type_trans(rnet->rx_skb[i], ndev);
121 error = netif_rx(rnet->rx_skb[i]);
122
123 if (error == NET_RX_DROP) {
124 rnet->stats.rx_dropped++;
125 } else if (error == NET_RX_BAD) {
126 if (netif_msg_rx_err(rnet))
127 printk(KERN_WARNING "%s: bad rx packet\n",
128 DRV_NAME);
129 rnet->stats.rx_errors++;
130 } else {
131 rnet->stats.rx_packets++;
132 rnet->stats.rx_bytes += RIO_MAX_MSG_SIZE;
133 }
134
135 } while ((i = (i + 1) % RIONET_RX_RING_SIZE) != rnet->rx_slot);
136
137 return i;
138}
139
140static void rionet_rx_fill(struct net_device *ndev, int end)
141{
142 int i;
143 struct rionet_private *rnet = ndev->priv;
144
145 i = rnet->rx_slot;
146 do {
147 rnet->rx_skb[i] = dev_alloc_skb(RIO_MAX_MSG_SIZE);
148
149 if (!rnet->rx_skb[i])
150 break;
151
152 rio_add_inb_buffer(rnet->mport, RIONET_MAILBOX,
153 rnet->rx_skb[i]->data);
154 } while ((i = (i + 1) % RIONET_RX_RING_SIZE) != end);
155
156 rnet->rx_slot = i;
157}
158
159static int rionet_queue_tx_msg(struct sk_buff *skb, struct net_device *ndev,
160 struct rio_dev *rdev)
161{
162 struct rionet_private *rnet = ndev->priv;
163
164 rio_add_outb_message(rnet->mport, rdev, 0, skb->data, skb->len);
165 rnet->tx_skb[rnet->tx_slot] = skb;
166
167 rnet->stats.tx_packets++;
168 rnet->stats.tx_bytes += skb->len;
169
170 if (++rnet->tx_cnt == RIONET_TX_RING_SIZE)
171 netif_stop_queue(ndev);
172
173 ++rnet->tx_slot;
174 rnet->tx_slot &= (RIONET_TX_RING_SIZE - 1);
175
176 if (netif_msg_tx_queued(rnet))
177 printk(KERN_INFO "%s: queued skb %8.8x len %8.8x\n", DRV_NAME,
178 (u32) skb, skb->len);
179
180 return 0;
181}
182
183static int rionet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
184{
185 int i;
186 struct rionet_private *rnet = ndev->priv;
187 struct ethhdr *eth = (struct ethhdr *)skb->data;
188 u16 destid;
189 unsigned long flags;
190
191 local_irq_save(flags);
192 if (!spin_trylock(&rnet->tx_lock)) {
193 local_irq_restore(flags);
194 return NETDEV_TX_LOCKED;
195 }
196
197 if ((rnet->tx_cnt + 1) > RIONET_TX_RING_SIZE) {
198 netif_stop_queue(ndev);
199 spin_unlock_irqrestore(&rnet->tx_lock, flags);
200 printk(KERN_ERR "%s: BUG! Tx Ring full when queue awake!\n",
201 ndev->name);
202 return NETDEV_TX_BUSY;
203 }
204
205 if (eth->h_dest[0] & 0x01) {
206 for (i = 0; i < RIO_MAX_ROUTE_ENTRIES; i++)
207 if (rionet_active[i])
208 rionet_queue_tx_msg(skb, ndev,
209 rionet_active[i]);
210 } else if (RIONET_MAC_MATCH(eth->h_dest)) {
211 destid = RIONET_GET_DESTID(eth->h_dest);
212 if (rionet_active[destid])
213 rionet_queue_tx_msg(skb, ndev, rionet_active[destid]);
214 }
215
216 spin_unlock_irqrestore(&rnet->tx_lock, flags);
217
218 return 0;
219}
220
221static void rionet_dbell_event(struct rio_mport *mport, void *dev_id, u16 sid, u16 tid,
222 u16 info)
223{
224 struct net_device *ndev = dev_id;
225 struct rionet_private *rnet = ndev->priv;
226 struct rionet_peer *peer;
227
228 if (netif_msg_intr(rnet))
229 printk(KERN_INFO "%s: doorbell sid %4.4x tid %4.4x info %4.4x",
230 DRV_NAME, sid, tid, info);
231 if (info == RIONET_DOORBELL_JOIN) {
232 if (!rionet_active[sid]) {
233 list_for_each_entry(peer, &rionet_peers, node) {
234 if (peer->rdev->destid == sid)
235 rionet_active[sid] = peer->rdev;
236 }
237 rio_mport_send_doorbell(mport, sid,
238 RIONET_DOORBELL_JOIN);
239 }
240 } else if (info == RIONET_DOORBELL_LEAVE) {
241 rionet_active[sid] = NULL;
242 } else {
243 if (netif_msg_intr(rnet))
244 printk(KERN_WARNING "%s: unhandled doorbell\n",
245 DRV_NAME);
246 }
247}
248
249static void rionet_inb_msg_event(struct rio_mport *mport, void *dev_id, int mbox, int slot)
250{
251 int n;
252 struct net_device *ndev = dev_id;
253 struct rionet_private *rnet = (struct rionet_private *)ndev->priv;
254
255 if (netif_msg_intr(rnet))
256 printk(KERN_INFO "%s: inbound message event, mbox %d slot %d\n",
257 DRV_NAME, mbox, slot);
258
259 spin_lock(&rnet->lock);
260 if ((n = rionet_rx_clean(ndev)) != rnet->rx_slot)
261 rionet_rx_fill(ndev, n);
262 spin_unlock(&rnet->lock);
263}
264
265static void rionet_outb_msg_event(struct rio_mport *mport, void *dev_id, int mbox, int slot)
266{
267 struct net_device *ndev = dev_id;
268 struct rionet_private *rnet = ndev->priv;
269
270 spin_lock(&rnet->lock);
271
272 if (netif_msg_intr(rnet))
273 printk(KERN_INFO
274 "%s: outbound message event, mbox %d slot %d\n",
275 DRV_NAME, mbox, slot);
276
277 while (rnet->tx_cnt && (rnet->ack_slot != slot)) {
278 /* dma unmap single */
279 dev_kfree_skb_irq(rnet->tx_skb[rnet->ack_slot]);
280 rnet->tx_skb[rnet->ack_slot] = NULL;
281 ++rnet->ack_slot;
282 rnet->ack_slot &= (RIONET_TX_RING_SIZE - 1);
283 rnet->tx_cnt--;
284 }
285
286 if (rnet->tx_cnt < RIONET_TX_RING_SIZE)
287 netif_wake_queue(ndev);
288
289 spin_unlock(&rnet->lock);
290}
291
292static int rionet_open(struct net_device *ndev)
293{
294 int i, rc = 0;
295 struct rionet_peer *peer, *tmp;
296 u32 pwdcsr;
297 struct rionet_private *rnet = ndev->priv;
298
299 if (netif_msg_ifup(rnet))
300 printk(KERN_INFO "%s: open\n", DRV_NAME);
301
302 if ((rc = rio_request_inb_dbell(rnet->mport,
303 (void *)ndev,
304 RIONET_DOORBELL_JOIN,
305 RIONET_DOORBELL_LEAVE,
306 rionet_dbell_event)) < 0)
307 goto out;
308
309 if ((rc = rio_request_inb_mbox(rnet->mport,
310 (void *)ndev,
311 RIONET_MAILBOX,
312 RIONET_RX_RING_SIZE,
313 rionet_inb_msg_event)) < 0)
314 goto out;
315
316 if ((rc = rio_request_outb_mbox(rnet->mport,
317 (void *)ndev,
318 RIONET_MAILBOX,
319 RIONET_TX_RING_SIZE,
320 rionet_outb_msg_event)) < 0)
321 goto out;
322
323 /* Initialize inbound message ring */
324 for (i = 0; i < RIONET_RX_RING_SIZE; i++)
325 rnet->rx_skb[i] = NULL;
326 rnet->rx_slot = 0;
327 rionet_rx_fill(ndev, 0);
328
329 rnet->tx_slot = 0;
330 rnet->tx_cnt = 0;
331 rnet->ack_slot = 0;
332
333 netif_carrier_on(ndev);
334 netif_start_queue(ndev);
335
336 list_for_each_entry_safe(peer, tmp, &rionet_peers, node) {
337 if (!(peer->res = rio_request_outb_dbell(peer->rdev,
338 RIONET_DOORBELL_JOIN,
339 RIONET_DOORBELL_LEAVE)))
340 {
341 printk(KERN_ERR "%s: error requesting doorbells\n",
342 DRV_NAME);
343 continue;
344 }
345
346 /*
347 * If device has initialized inbound doorbells,
348 * send a join message
349 */
350 rio_read_config_32(peer->rdev, RIO_WRITE_PORT_CSR, &pwdcsr);
351 if (pwdcsr & RIO_DOORBELL_AVAIL)
352 rio_send_doorbell(peer->rdev, RIONET_DOORBELL_JOIN);
353 }
354
355 out:
356 return rc;
357}
358
359static int rionet_close(struct net_device *ndev)
360{
361 struct rionet_private *rnet = (struct rionet_private *)ndev->priv;
362 struct rionet_peer *peer, *tmp;
363 int i;
364
365 if (netif_msg_ifup(rnet))
366 printk(KERN_INFO "%s: close\n", DRV_NAME);
367
368 netif_stop_queue(ndev);
369 netif_carrier_off(ndev);
370
371 for (i = 0; i < RIONET_RX_RING_SIZE; i++)
372 if (rnet->rx_skb[i])
373 kfree_skb(rnet->rx_skb[i]);
374
375 list_for_each_entry_safe(peer, tmp, &rionet_peers, node) {
376 if (rionet_active[peer->rdev->destid]) {
377 rio_send_doorbell(peer->rdev, RIONET_DOORBELL_LEAVE);
378 rionet_active[peer->rdev->destid] = NULL;
379 }
380 rio_release_outb_dbell(peer->rdev, peer->res);
381 }
382
383 rio_release_inb_dbell(rnet->mport, RIONET_DOORBELL_JOIN,
384 RIONET_DOORBELL_LEAVE);
385 rio_release_inb_mbox(rnet->mport, RIONET_MAILBOX);
386 rio_release_outb_mbox(rnet->mport, RIONET_MAILBOX);
387
388 return 0;
389}
390
391static void rionet_remove(struct rio_dev *rdev)
392{
393 struct net_device *ndev = NULL;
394 struct rionet_peer *peer, *tmp;
395
396 unregister_netdev(ndev);
397 kfree(ndev);
398
399 list_for_each_entry_safe(peer, tmp, &rionet_peers, node) {
400 list_del(&peer->node);
401 kfree(peer);
402 }
403}
404
405static void rionet_get_drvinfo(struct net_device *ndev,
406 struct ethtool_drvinfo *info)
407{
408 struct rionet_private *rnet = ndev->priv;
409
410 strcpy(info->driver, DRV_NAME);
411 strcpy(info->version, DRV_VERSION);
412 strcpy(info->fw_version, "n/a");
413 strcpy(info->bus_info, rnet->mport->name);
414}
415
416static u32 rionet_get_msglevel(struct net_device *ndev)
417{
418 struct rionet_private *rnet = ndev->priv;
419
420 return rnet->msg_enable;
421}
422
423static void rionet_set_msglevel(struct net_device *ndev, u32 value)
424{
425 struct rionet_private *rnet = ndev->priv;
426
427 rnet->msg_enable = value;
428}
429
430static struct ethtool_ops rionet_ethtool_ops = {
431 .get_drvinfo = rionet_get_drvinfo,
432 .get_msglevel = rionet_get_msglevel,
433 .set_msglevel = rionet_set_msglevel,
434 .get_link = ethtool_op_get_link,
435};
436
437static int rionet_setup_netdev(struct rio_mport *mport)
438{
439 int rc = 0;
440 struct net_device *ndev = NULL;
441 struct rionet_private *rnet;
442 u16 device_id;
443
444 /* Allocate our net_device structure */
445 ndev = alloc_etherdev(sizeof(struct rionet_private));
446 if (ndev == NULL) {
447 printk(KERN_INFO "%s: could not allocate ethernet device.\n",
448 DRV_NAME);
449 rc = -ENOMEM;
450 goto out;
451 }
452
453 /* Set up private area */
454 rnet = (struct rionet_private *)ndev->priv;
455 rnet->mport = mport;
456
457 /* Set the default MAC address */
458 device_id = rio_local_get_device_id(mport);
459 ndev->dev_addr[0] = 0x00;
460 ndev->dev_addr[1] = 0x01;
461 ndev->dev_addr[2] = 0x00;
462 ndev->dev_addr[3] = 0x01;
463 ndev->dev_addr[4] = device_id >> 8;
464 ndev->dev_addr[5] = device_id & 0xff;
465
466 /* Fill in the driver function table */
467 ndev->open = &rionet_open;
468 ndev->hard_start_xmit = &rionet_start_xmit;
469 ndev->stop = &rionet_close;
470 ndev->get_stats = &rionet_stats;
471 ndev->mtu = RIO_MAX_MSG_SIZE - 14;
472 ndev->features = NETIF_F_LLTX;
473 SET_ETHTOOL_OPS(ndev, &rionet_ethtool_ops);
474
475 SET_MODULE_OWNER(ndev);
476
477 spin_lock_init(&rnet->lock);
478 spin_lock_init(&rnet->tx_lock);
479
480 rnet->msg_enable = RIONET_DEFAULT_MSGLEVEL;
481
482 rc = register_netdev(ndev);
483 if (rc != 0)
484 goto out;
485
486 printk("%s: %s %s Version %s, MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
487 ndev->name,
488 DRV_NAME,
489 DRV_DESC,
490 DRV_VERSION,
491 ndev->dev_addr[0], ndev->dev_addr[1], ndev->dev_addr[2],
492 ndev->dev_addr[3], ndev->dev_addr[4], ndev->dev_addr[5]);
493
494 out:
495 return rc;
496}
497
498/*
499 * XXX Make multi-net safe
500 */
501static int rionet_probe(struct rio_dev *rdev, const struct rio_device_id *id)
502{
503 int rc = -ENODEV;
504 u32 lpef, lsrc_ops, ldst_ops;
505 struct rionet_peer *peer;
506
507 /* If local device is not rionet capable, give up quickly */
508 if (!rionet_capable)
509 goto out;
510
511 /*
512 * First time through, make sure local device is rionet
513 * capable, setup netdev, and set flags so this is skipped
514 * on later probes
515 */
516 if (!rionet_check) {
517 rio_local_read_config_32(rdev->net->hport, RIO_PEF_CAR, &lpef);
518 rio_local_read_config_32(rdev->net->hport, RIO_SRC_OPS_CAR,
519 &lsrc_ops);
520 rio_local_read_config_32(rdev->net->hport, RIO_DST_OPS_CAR,
521 &ldst_ops);
522 if (!is_rionet_capable(lpef, lsrc_ops, ldst_ops)) {
523 printk(KERN_ERR
524 "%s: local device is not network capable\n",
525 DRV_NAME);
526 rionet_check = 1;
527 rionet_capable = 0;
528 goto out;
529 }
530
531 rc = rionet_setup_netdev(rdev->net->hport);
532 rionet_check = 1;
533 }
534
535 /*
536 * If the remote device has mailbox/doorbell capabilities,
537 * add it to the peer list.
538 */
539 if (dev_rionet_capable(rdev)) {
540 if (!(peer = kmalloc(sizeof(struct rionet_peer), GFP_KERNEL))) {
541 rc = -ENOMEM;
542 goto out;
543 }
544 peer->rdev = rdev;
545 list_add_tail(&peer->node, &rionet_peers);
546 }
547
548 out:
549 return rc;
550}
551
552static struct rio_device_id rionet_id_table[] = {
553 {RIO_DEVICE(RIO_ANY_ID, RIO_ANY_ID)}
554};
555
556static struct rio_driver rionet_driver = {
557 .name = "rionet",
558 .id_table = rionet_id_table,
559 .probe = rionet_probe,
560 .remove = rionet_remove,
561};
562
563static int __init rionet_init(void)
564{
565 return rio_register_driver(&rionet_driver);
566}
567
568static void __exit rionet_exit(void)
569{
570 rio_unregister_driver(&rionet_driver);
571}
572
573module_init(rionet_init);
574module_exit(rionet_exit);
diff --git a/drivers/net/rrunner.c b/drivers/net/rrunner.c
index ec1a18d189a1..19c2df9c86fe 100644
--- a/drivers/net/rrunner.c
+++ b/drivers/net/rrunner.c
@@ -1710,10 +1710,8 @@ static int rr_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1710 error = -EFAULT; 1710 error = -EFAULT;
1711 } 1711 }
1712 wf_out: 1712 wf_out:
1713 if (oldimage) 1713 kfree(oldimage);
1714 kfree(oldimage); 1714 kfree(image);
1715 if (image)
1716 kfree(image);
1717 return error; 1715 return error;
1718 1716
1719 case SIOCRRID: 1717 case SIOCRRID:
diff --git a/drivers/net/s2io-regs.h b/drivers/net/s2io-regs.h
index 7cefe5507b9e..00179bc3437f 100644
--- a/drivers/net/s2io-regs.h
+++ b/drivers/net/s2io-regs.h
@@ -814,6 +814,17 @@ typedef struct _XENA_dev_config {
814 u64 rxgxs_ber_0; /* CHANGED */ 814 u64 rxgxs_ber_0; /* CHANGED */
815 u64 rxgxs_ber_1; /* CHANGED */ 815 u64 rxgxs_ber_1; /* CHANGED */
816 816
817 u64 spi_control;
818#define SPI_CONTROL_KEY(key) vBIT(key,0,4)
819#define SPI_CONTROL_BYTECNT(cnt) vBIT(cnt,29,3)
820#define SPI_CONTROL_CMD(cmd) vBIT(cmd,32,8)
821#define SPI_CONTROL_ADDR(addr) vBIT(addr,40,24)
822#define SPI_CONTROL_SEL1 BIT(4)
823#define SPI_CONTROL_REQ BIT(7)
824#define SPI_CONTROL_NACK BIT(5)
825#define SPI_CONTROL_DONE BIT(6)
826 u64 spi_data;
827#define SPI_DATA_WRITE(data,len) vBIT(data,0,len)
817} XENA_dev_config_t; 828} XENA_dev_config_t;
818 829
819#define XENA_REG_SPACE sizeof(XENA_dev_config_t) 830#define XENA_REG_SPACE sizeof(XENA_dev_config_t)
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c
index dd451e099a4c..3f5e93aad5c7 100644
--- a/drivers/net/s2io.c
+++ b/drivers/net/s2io.c
@@ -65,9 +65,11 @@
65#include "s2io.h" 65#include "s2io.h"
66#include "s2io-regs.h" 66#include "s2io-regs.h"
67 67
68#define DRV_VERSION "Version 2.0.9.1"
69
68/* S2io Driver name & version. */ 70/* S2io Driver name & version. */
69static char s2io_driver_name[] = "Neterion"; 71static char s2io_driver_name[] = "Neterion";
70static char s2io_driver_version[] = "Version 2.0.8.1"; 72static char s2io_driver_version[] = DRV_VERSION;
71 73
72static inline int RXD_IS_UP2DT(RxD_t *rxdp) 74static inline int RXD_IS_UP2DT(RxD_t *rxdp)
73{ 75{
@@ -307,6 +309,8 @@ static unsigned int indicate_max_pkts;
307#endif 309#endif
308/* Frequency of Rx desc syncs expressed as power of 2 */ 310/* Frequency of Rx desc syncs expressed as power of 2 */
309static unsigned int rxsync_frequency = 3; 311static unsigned int rxsync_frequency = 3;
312/* Interrupt type. Values can be 0(INTA), 1(MSI), 2(MSI_X) */
313static unsigned int intr_type = 0;
310 314
311/* 315/*
312 * S2IO device table. 316 * S2IO device table.
@@ -701,8 +705,7 @@ static void free_shared_mem(struct s2io_nic *nic)
701 } 705 }
702 kfree(mac_control->rings[i].ba[j]); 706 kfree(mac_control->rings[i].ba[j]);
703 } 707 }
704 if (mac_control->rings[i].ba) 708 kfree(mac_control->rings[i].ba);
705 kfree(mac_control->rings[i].ba);
706 } 709 }
707#endif 710#endif
708 711
@@ -1396,8 +1399,13 @@ static int init_nic(struct s2io_nic *nic)
1396 writeq(val64, &bar0->rti_data1_mem); 1399 writeq(val64, &bar0->rti_data1_mem);
1397 1400
1398 val64 = RTI_DATA2_MEM_RX_UFC_A(0x1) | 1401 val64 = RTI_DATA2_MEM_RX_UFC_A(0x1) |
1399 RTI_DATA2_MEM_RX_UFC_B(0x2) | 1402 RTI_DATA2_MEM_RX_UFC_B(0x2) ;
1400 RTI_DATA2_MEM_RX_UFC_C(0x40) | RTI_DATA2_MEM_RX_UFC_D(0x80); 1403 if (nic->intr_type == MSI_X)
1404 val64 |= (RTI_DATA2_MEM_RX_UFC_C(0x20) | \
1405 RTI_DATA2_MEM_RX_UFC_D(0x40));
1406 else
1407 val64 |= (RTI_DATA2_MEM_RX_UFC_C(0x40) | \
1408 RTI_DATA2_MEM_RX_UFC_D(0x80));
1401 writeq(val64, &bar0->rti_data2_mem); 1409 writeq(val64, &bar0->rti_data2_mem);
1402 1410
1403 for (i = 0; i < config->rx_ring_num; i++) { 1411 for (i = 0; i < config->rx_ring_num; i++) {
@@ -1507,17 +1515,15 @@ static int init_nic(struct s2io_nic *nic)
1507#define LINK_UP_DOWN_INTERRUPT 1 1515#define LINK_UP_DOWN_INTERRUPT 1
1508#define MAC_RMAC_ERR_TIMER 2 1516#define MAC_RMAC_ERR_TIMER 2
1509 1517
1510#if defined(CONFIG_MSI_MODE) || defined(CONFIG_MSIX_MODE)
1511#define s2io_link_fault_indication(x) MAC_RMAC_ERR_TIMER
1512#else
1513int s2io_link_fault_indication(nic_t *nic) 1518int s2io_link_fault_indication(nic_t *nic)
1514{ 1519{
1520 if (nic->intr_type != INTA)
1521 return MAC_RMAC_ERR_TIMER;
1515 if (nic->device_type == XFRAME_II_DEVICE) 1522 if (nic->device_type == XFRAME_II_DEVICE)
1516 return LINK_UP_DOWN_INTERRUPT; 1523 return LINK_UP_DOWN_INTERRUPT;
1517 else 1524 else
1518 return MAC_RMAC_ERR_TIMER; 1525 return MAC_RMAC_ERR_TIMER;
1519} 1526}
1520#endif
1521 1527
1522/** 1528/**
1523 * en_dis_able_nic_intrs - Enable or Disable the interrupts 1529 * en_dis_able_nic_intrs - Enable or Disable the interrupts
@@ -1941,11 +1947,14 @@ static int start_nic(struct s2io_nic *nic)
1941 } 1947 }
1942 1948
1943 /* Enable select interrupts */ 1949 /* Enable select interrupts */
1944 interruptible = TX_TRAFFIC_INTR | RX_TRAFFIC_INTR; 1950 if (nic->intr_type != INTA)
1945 interruptible |= TX_PIC_INTR | RX_PIC_INTR; 1951 en_dis_able_nic_intrs(nic, ENA_ALL_INTRS, DISABLE_INTRS);
1946 interruptible |= TX_MAC_INTR | RX_MAC_INTR; 1952 else {
1947 1953 interruptible = TX_TRAFFIC_INTR | RX_TRAFFIC_INTR;
1948 en_dis_able_nic_intrs(nic, interruptible, ENABLE_INTRS); 1954 interruptible |= TX_PIC_INTR | RX_PIC_INTR;
1955 interruptible |= TX_MAC_INTR | RX_MAC_INTR;
1956 en_dis_able_nic_intrs(nic, interruptible, ENABLE_INTRS);
1957 }
1949 1958
1950 /* 1959 /*
1951 * With some switches, link might be already up at this point. 1960 * With some switches, link might be already up at this point.
@@ -2633,11 +2642,11 @@ static void tx_intr_handler(fifo_info_t *fifo_data)
2633 err = txdlp->Control_1 & TXD_T_CODE; 2642 err = txdlp->Control_1 & TXD_T_CODE;
2634 if ((err >> 48) == 0xA) { 2643 if ((err >> 48) == 0xA) {
2635 DBG_PRINT(TX_DBG, "TxD returned due \ 2644 DBG_PRINT(TX_DBG, "TxD returned due \
2636 to loss of link\n"); 2645to loss of link\n");
2637 } 2646 }
2638 else { 2647 else {
2639 DBG_PRINT(ERR_DBG, "***TxD error \ 2648 DBG_PRINT(ERR_DBG, "***TxD error \
2640 %llx\n", err); 2649%llx\n", err);
2641 } 2650 }
2642 } 2651 }
2643 2652
@@ -2854,6 +2863,9 @@ void s2io_reset(nic_t * sp)
2854 /* Set swapper to enable I/O register access */ 2863 /* Set swapper to enable I/O register access */
2855 s2io_set_swapper(sp); 2864 s2io_set_swapper(sp);
2856 2865
2866 /* Restore the MSIX table entries from local variables */
2867 restore_xmsi_data(sp);
2868
2857 /* Clear certain PCI/PCI-X fields after reset */ 2869 /* Clear certain PCI/PCI-X fields after reset */
2858 if (sp->device_type == XFRAME_II_DEVICE) { 2870 if (sp->device_type == XFRAME_II_DEVICE) {
2859 /* Clear parity err detect bit */ 2871 /* Clear parity err detect bit */
@@ -2983,8 +2995,9 @@ int s2io_set_swapper(nic_t * sp)
2983 SWAPPER_CTRL_RXD_W_FE | 2995 SWAPPER_CTRL_RXD_W_FE |
2984 SWAPPER_CTRL_RXF_W_FE | 2996 SWAPPER_CTRL_RXF_W_FE |
2985 SWAPPER_CTRL_XMSI_FE | 2997 SWAPPER_CTRL_XMSI_FE |
2986 SWAPPER_CTRL_XMSI_SE |
2987 SWAPPER_CTRL_STATS_FE | SWAPPER_CTRL_STATS_SE); 2998 SWAPPER_CTRL_STATS_FE | SWAPPER_CTRL_STATS_SE);
2999 if (sp->intr_type == INTA)
3000 val64 |= SWAPPER_CTRL_XMSI_SE;
2988 writeq(val64, &bar0->swapper_ctrl); 3001 writeq(val64, &bar0->swapper_ctrl);
2989#else 3002#else
2990 /* 3003 /*
@@ -3005,8 +3018,9 @@ int s2io_set_swapper(nic_t * sp)
3005 SWAPPER_CTRL_RXD_W_SE | 3018 SWAPPER_CTRL_RXD_W_SE |
3006 SWAPPER_CTRL_RXF_W_FE | 3019 SWAPPER_CTRL_RXF_W_FE |
3007 SWAPPER_CTRL_XMSI_FE | 3020 SWAPPER_CTRL_XMSI_FE |
3008 SWAPPER_CTRL_XMSI_SE |
3009 SWAPPER_CTRL_STATS_FE | SWAPPER_CTRL_STATS_SE); 3021 SWAPPER_CTRL_STATS_FE | SWAPPER_CTRL_STATS_SE);
3022 if (sp->intr_type == INTA)
3023 val64 |= SWAPPER_CTRL_XMSI_SE;
3010 writeq(val64, &bar0->swapper_ctrl); 3024 writeq(val64, &bar0->swapper_ctrl);
3011#endif 3025#endif
3012 val64 = readq(&bar0->swapper_ctrl); 3026 val64 = readq(&bar0->swapper_ctrl);
@@ -3028,6 +3042,201 @@ int s2io_set_swapper(nic_t * sp)
3028 return SUCCESS; 3042 return SUCCESS;
3029} 3043}
3030 3044
3045int wait_for_msix_trans(nic_t *nic, int i)
3046{
3047 XENA_dev_config_t __iomem *bar0 = nic->bar0;
3048 u64 val64;
3049 int ret = 0, cnt = 0;
3050
3051 do {
3052 val64 = readq(&bar0->xmsi_access);
3053 if (!(val64 & BIT(15)))
3054 break;
3055 mdelay(1);
3056 cnt++;
3057 } while(cnt < 5);
3058 if (cnt == 5) {
3059 DBG_PRINT(ERR_DBG, "XMSI # %d Access failed\n", i);
3060 ret = 1;
3061 }
3062
3063 return ret;
3064}
3065
3066void restore_xmsi_data(nic_t *nic)
3067{
3068 XENA_dev_config_t __iomem *bar0 = nic->bar0;
3069 u64 val64;
3070 int i;
3071
3072 for (i=0; i< MAX_REQUESTED_MSI_X; i++) {
3073 writeq(nic->msix_info[i].addr, &bar0->xmsi_address);
3074 writeq(nic->msix_info[i].data, &bar0->xmsi_data);
3075 val64 = (BIT(7) | BIT(15) | vBIT(i, 26, 6));
3076 writeq(val64, &bar0->xmsi_access);
3077 if (wait_for_msix_trans(nic, i)) {
3078 DBG_PRINT(ERR_DBG, "failed in %s\n", __FUNCTION__);
3079 continue;
3080 }
3081 }
3082}
3083
3084void store_xmsi_data(nic_t *nic)
3085{
3086 XENA_dev_config_t __iomem *bar0 = nic->bar0;
3087 u64 val64, addr, data;
3088 int i;
3089
3090 /* Store and display */
3091 for (i=0; i< MAX_REQUESTED_MSI_X; i++) {
3092 val64 = (BIT(15) | vBIT(i, 26, 6));
3093 writeq(val64, &bar0->xmsi_access);
3094 if (wait_for_msix_trans(nic, i)) {
3095 DBG_PRINT(ERR_DBG, "failed in %s\n", __FUNCTION__);
3096 continue;
3097 }
3098 addr = readq(&bar0->xmsi_address);
3099 data = readq(&bar0->xmsi_data);
3100 if (addr && data) {
3101 nic->msix_info[i].addr = addr;
3102 nic->msix_info[i].data = data;
3103 }
3104 }
3105}
3106
3107int s2io_enable_msi(nic_t *nic)
3108{
3109 XENA_dev_config_t __iomem *bar0 = nic->bar0;
3110 u16 msi_ctrl, msg_val;
3111 struct config_param *config = &nic->config;
3112 struct net_device *dev = nic->dev;
3113 u64 val64, tx_mat, rx_mat;
3114 int i, err;
3115
3116 val64 = readq(&bar0->pic_control);
3117 val64 &= ~BIT(1);
3118 writeq(val64, &bar0->pic_control);
3119
3120 err = pci_enable_msi(nic->pdev);
3121 if (err) {
3122 DBG_PRINT(ERR_DBG, "%s: enabling MSI failed\n",
3123 nic->dev->name);
3124 return err;
3125 }
3126
3127 /*
3128 * Enable MSI and use MSI-1 in stead of the standard MSI-0
3129 * for interrupt handling.
3130 */
3131 pci_read_config_word(nic->pdev, 0x4c, &msg_val);
3132 msg_val ^= 0x1;
3133 pci_write_config_word(nic->pdev, 0x4c, msg_val);
3134 pci_read_config_word(nic->pdev, 0x4c, &msg_val);
3135
3136 pci_read_config_word(nic->pdev, 0x42, &msi_ctrl);
3137 msi_ctrl |= 0x10;
3138 pci_write_config_word(nic->pdev, 0x42, msi_ctrl);
3139
3140 /* program MSI-1 into all usable Tx_Mat and Rx_Mat fields */
3141 tx_mat = readq(&bar0->tx_mat0_n[0]);
3142 for (i=0; i<config->tx_fifo_num; i++) {
3143 tx_mat |= TX_MAT_SET(i, 1);
3144 }
3145 writeq(tx_mat, &bar0->tx_mat0_n[0]);
3146
3147 rx_mat = readq(&bar0->rx_mat);
3148 for (i=0; i<config->rx_ring_num; i++) {
3149 rx_mat |= RX_MAT_SET(i, 1);
3150 }
3151 writeq(rx_mat, &bar0->rx_mat);
3152
3153 dev->irq = nic->pdev->irq;
3154 return 0;
3155}
3156
3157int s2io_enable_msi_x(nic_t *nic)
3158{
3159 XENA_dev_config_t __iomem *bar0 = nic->bar0;
3160 u64 tx_mat, rx_mat;
3161 u16 msi_control; /* Temp variable */
3162 int ret, i, j, msix_indx = 1;
3163
3164 nic->entries = kmalloc(MAX_REQUESTED_MSI_X * sizeof(struct msix_entry),
3165 GFP_KERNEL);
3166 if (nic->entries == NULL) {
3167 DBG_PRINT(ERR_DBG, "%s: Memory allocation failed\n", __FUNCTION__);
3168 return -ENOMEM;
3169 }
3170 memset(nic->entries, 0, MAX_REQUESTED_MSI_X * sizeof(struct msix_entry));
3171
3172 nic->s2io_entries =
3173 kmalloc(MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry),
3174 GFP_KERNEL);
3175 if (nic->s2io_entries == NULL) {
3176 DBG_PRINT(ERR_DBG, "%s: Memory allocation failed\n", __FUNCTION__);
3177 kfree(nic->entries);
3178 return -ENOMEM;
3179 }
3180 memset(nic->s2io_entries, 0,
3181 MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry));
3182
3183 for (i=0; i< MAX_REQUESTED_MSI_X; i++) {
3184 nic->entries[i].entry = i;
3185 nic->s2io_entries[i].entry = i;
3186 nic->s2io_entries[i].arg = NULL;
3187 nic->s2io_entries[i].in_use = 0;
3188 }
3189
3190 tx_mat = readq(&bar0->tx_mat0_n[0]);
3191 for (i=0; i<nic->config.tx_fifo_num; i++, msix_indx++) {
3192 tx_mat |= TX_MAT_SET(i, msix_indx);
3193 nic->s2io_entries[msix_indx].arg = &nic->mac_control.fifos[i];
3194 nic->s2io_entries[msix_indx].type = MSIX_FIFO_TYPE;
3195 nic->s2io_entries[msix_indx].in_use = MSIX_FLG;
3196 }
3197 writeq(tx_mat, &bar0->tx_mat0_n[0]);
3198
3199 if (!nic->config.bimodal) {
3200 rx_mat = readq(&bar0->rx_mat);
3201 for (j=0; j<nic->config.rx_ring_num; j++, msix_indx++) {
3202 rx_mat |= RX_MAT_SET(j, msix_indx);
3203 nic->s2io_entries[msix_indx].arg = &nic->mac_control.rings[j];
3204 nic->s2io_entries[msix_indx].type = MSIX_RING_TYPE;
3205 nic->s2io_entries[msix_indx].in_use = MSIX_FLG;
3206 }
3207 writeq(rx_mat, &bar0->rx_mat);
3208 } else {
3209 tx_mat = readq(&bar0->tx_mat0_n[7]);
3210 for (j=0; j<nic->config.rx_ring_num; j++, msix_indx++) {
3211 tx_mat |= TX_MAT_SET(i, msix_indx);
3212 nic->s2io_entries[msix_indx].arg = &nic->mac_control.rings[j];
3213 nic->s2io_entries[msix_indx].type = MSIX_RING_TYPE;
3214 nic->s2io_entries[msix_indx].in_use = MSIX_FLG;
3215 }
3216 writeq(tx_mat, &bar0->tx_mat0_n[7]);
3217 }
3218
3219 ret = pci_enable_msix(nic->pdev, nic->entries, MAX_REQUESTED_MSI_X);
3220 if (ret) {
3221 DBG_PRINT(ERR_DBG, "%s: Enabling MSIX failed\n", nic->dev->name);
3222 kfree(nic->entries);
3223 kfree(nic->s2io_entries);
3224 nic->entries = NULL;
3225 nic->s2io_entries = NULL;
3226 return -ENOMEM;
3227 }
3228
3229 /*
3230 * To enable MSI-X, MSI also needs to be enabled, due to a bug
3231 * in the herc NIC. (Temp change, needs to be removed later)
3232 */
3233 pci_read_config_word(nic->pdev, 0x42, &msi_control);
3234 msi_control |= 0x1; /* Enable MSI */
3235 pci_write_config_word(nic->pdev, 0x42, msi_control);
3236
3237 return 0;
3238}
3239
3031/* ********************************************************* * 3240/* ********************************************************* *
3032 * Functions defined below concern the OS part of the driver * 3241 * Functions defined below concern the OS part of the driver *
3033 * ********************************************************* */ 3242 * ********************************************************* */
@@ -3048,6 +3257,8 @@ int s2io_open(struct net_device *dev)
3048{ 3257{
3049 nic_t *sp = dev->priv; 3258 nic_t *sp = dev->priv;
3050 int err = 0; 3259 int err = 0;
3260 int i;
3261 u16 msi_control; /* Temp variable */
3051 3262
3052 /* 3263 /*
3053 * Make sure you have link off by default every time 3264 * Make sure you have link off by default every time
@@ -3064,13 +3275,55 @@ int s2io_open(struct net_device *dev)
3064 goto hw_init_failed; 3275 goto hw_init_failed;
3065 } 3276 }
3066 3277
3278 /* Store the values of the MSIX table in the nic_t structure */
3279 store_xmsi_data(sp);
3280
3067 /* After proper initialization of H/W, register ISR */ 3281 /* After proper initialization of H/W, register ISR */
3068 err = request_irq((int) sp->pdev->irq, s2io_isr, SA_SHIRQ, 3282 if (sp->intr_type == MSI) {
3069 sp->name, dev); 3283 err = request_irq((int) sp->pdev->irq, s2io_msi_handle,
3070 if (err) { 3284 SA_SHIRQ, sp->name, dev);
3071 DBG_PRINT(ERR_DBG, "%s: ISR registration failed\n", 3285 if (err) {
3072 dev->name); 3286 DBG_PRINT(ERR_DBG, "%s: MSI registration \
3073 goto isr_registration_failed; 3287failed\n", dev->name);
3288 goto isr_registration_failed;
3289 }
3290 }
3291 if (sp->intr_type == MSI_X) {
3292 for (i=1; (sp->s2io_entries[i].in_use == MSIX_FLG); i++) {
3293 if (sp->s2io_entries[i].type == MSIX_FIFO_TYPE) {
3294 sprintf(sp->desc1, "%s:MSI-X-%d-TX",
3295 dev->name, i);
3296 err = request_irq(sp->entries[i].vector,
3297 s2io_msix_fifo_handle, 0, sp->desc1,
3298 sp->s2io_entries[i].arg);
3299 DBG_PRINT(ERR_DBG, "%s @ 0x%llx\n", sp->desc1,
3300 sp->msix_info[i].addr);
3301 } else {
3302 sprintf(sp->desc2, "%s:MSI-X-%d-RX",
3303 dev->name, i);
3304 err = request_irq(sp->entries[i].vector,
3305 s2io_msix_ring_handle, 0, sp->desc2,
3306 sp->s2io_entries[i].arg);
3307 DBG_PRINT(ERR_DBG, "%s @ 0x%llx\n", sp->desc2,
3308 sp->msix_info[i].addr);
3309 }
3310 if (err) {
3311 DBG_PRINT(ERR_DBG, "%s: MSI-X-%d registration \
3312failed\n", dev->name, i);
3313 DBG_PRINT(ERR_DBG, "Returned: %d\n", err);
3314 goto isr_registration_failed;
3315 }
3316 sp->s2io_entries[i].in_use = MSIX_REGISTERED_SUCCESS;
3317 }
3318 }
3319 if (sp->intr_type == INTA) {
3320 err = request_irq((int) sp->pdev->irq, s2io_isr, SA_SHIRQ,
3321 sp->name, dev);
3322 if (err) {
3323 DBG_PRINT(ERR_DBG, "%s: ISR registration failed\n",
3324 dev->name);
3325 goto isr_registration_failed;
3326 }
3074 } 3327 }
3075 3328
3076 if (s2io_set_mac_addr(dev, dev->dev_addr) == FAILURE) { 3329 if (s2io_set_mac_addr(dev, dev->dev_addr) == FAILURE) {
@@ -3083,11 +3336,37 @@ int s2io_open(struct net_device *dev)
3083 return 0; 3336 return 0;
3084 3337
3085setting_mac_address_failed: 3338setting_mac_address_failed:
3086 free_irq(sp->pdev->irq, dev); 3339 if (sp->intr_type != MSI_X)
3340 free_irq(sp->pdev->irq, dev);
3087isr_registration_failed: 3341isr_registration_failed:
3088 del_timer_sync(&sp->alarm_timer); 3342 del_timer_sync(&sp->alarm_timer);
3343 if (sp->intr_type == MSI_X) {
3344 if (sp->device_type == XFRAME_II_DEVICE) {
3345 for (i=1; (sp->s2io_entries[i].in_use ==
3346 MSIX_REGISTERED_SUCCESS); i++) {
3347 int vector = sp->entries[i].vector;
3348 void *arg = sp->s2io_entries[i].arg;
3349
3350 free_irq(vector, arg);
3351 }
3352 pci_disable_msix(sp->pdev);
3353
3354 /* Temp */
3355 pci_read_config_word(sp->pdev, 0x42, &msi_control);
3356 msi_control &= 0xFFFE; /* Disable MSI */
3357 pci_write_config_word(sp->pdev, 0x42, msi_control);
3358 }
3359 }
3360 else if (sp->intr_type == MSI)
3361 pci_disable_msi(sp->pdev);
3089 s2io_reset(sp); 3362 s2io_reset(sp);
3090hw_init_failed: 3363hw_init_failed:
3364 if (sp->intr_type == MSI_X) {
3365 if (sp->entries)
3366 kfree(sp->entries);
3367 if (sp->s2io_entries)
3368 kfree(sp->s2io_entries);
3369 }
3091 return err; 3370 return err;
3092} 3371}
3093 3372
@@ -3107,12 +3386,35 @@ hw_init_failed:
3107int s2io_close(struct net_device *dev) 3386int s2io_close(struct net_device *dev)
3108{ 3387{
3109 nic_t *sp = dev->priv; 3388 nic_t *sp = dev->priv;
3389 int i;
3390 u16 msi_control;
3391
3110 flush_scheduled_work(); 3392 flush_scheduled_work();
3111 netif_stop_queue(dev); 3393 netif_stop_queue(dev);
3112 /* Reset card, kill tasklet and free Tx and Rx buffers. */ 3394 /* Reset card, kill tasklet and free Tx and Rx buffers. */
3113 s2io_card_down(sp); 3395 s2io_card_down(sp);
3114 3396
3115 free_irq(sp->pdev->irq, dev); 3397 if (sp->intr_type == MSI_X) {
3398 if (sp->device_type == XFRAME_II_DEVICE) {
3399 for (i=1; (sp->s2io_entries[i].in_use ==
3400 MSIX_REGISTERED_SUCCESS); i++) {
3401 int vector = sp->entries[i].vector;
3402 void *arg = sp->s2io_entries[i].arg;
3403
3404 free_irq(vector, arg);
3405 }
3406 pci_read_config_word(sp->pdev, 0x42, &msi_control);
3407 msi_control &= 0xFFFE; /* Disable MSI */
3408 pci_write_config_word(sp->pdev, 0x42, msi_control);
3409
3410 pci_disable_msix(sp->pdev);
3411 }
3412 }
3413 else {
3414 free_irq(sp->pdev->irq, dev);
3415 if (sp->intr_type == MSI)
3416 pci_disable_msi(sp->pdev);
3417 }
3116 sp->device_close_flag = TRUE; /* Device is shut down. */ 3418 sp->device_close_flag = TRUE; /* Device is shut down. */
3117 return 0; 3419 return 0;
3118} 3420}
@@ -3278,6 +3580,104 @@ s2io_alarm_handle(unsigned long data)
3278 mod_timer(&sp->alarm_timer, jiffies + HZ / 2); 3580 mod_timer(&sp->alarm_timer, jiffies + HZ / 2);
3279} 3581}
3280 3582
3583static irqreturn_t
3584s2io_msi_handle(int irq, void *dev_id, struct pt_regs *regs)
3585{
3586 struct net_device *dev = (struct net_device *) dev_id;
3587 nic_t *sp = dev->priv;
3588 int i;
3589 int ret;
3590 mac_info_t *mac_control;
3591 struct config_param *config;
3592
3593 atomic_inc(&sp->isr_cnt);
3594 mac_control = &sp->mac_control;
3595 config = &sp->config;
3596 DBG_PRINT(INTR_DBG, "%s: MSI handler\n", __FUNCTION__);
3597
3598 /* If Intr is because of Rx Traffic */
3599 for (i = 0; i < config->rx_ring_num; i++)
3600 rx_intr_handler(&mac_control->rings[i]);
3601
3602 /* If Intr is because of Tx Traffic */
3603 for (i = 0; i < config->tx_fifo_num; i++)
3604 tx_intr_handler(&mac_control->fifos[i]);
3605
3606 /*
3607 * If the Rx buffer count is below the panic threshold then
3608 * reallocate the buffers from the interrupt handler itself,
3609 * else schedule a tasklet to reallocate the buffers.
3610 */
3611 for (i = 0; i < config->rx_ring_num; i++) {
3612 int rxb_size = atomic_read(&sp->rx_bufs_left[i]);
3613 int level = rx_buffer_level(sp, rxb_size, i);
3614
3615 if ((level == PANIC) && (!TASKLET_IN_USE)) {
3616 DBG_PRINT(INTR_DBG, "%s: Rx BD hit ", dev->name);
3617 DBG_PRINT(INTR_DBG, "PANIC levels\n");
3618 if ((ret = fill_rx_buffers(sp, i)) == -ENOMEM) {
3619 DBG_PRINT(ERR_DBG, "%s:Out of memory",
3620 dev->name);
3621 DBG_PRINT(ERR_DBG, " in ISR!!\n");
3622 clear_bit(0, (&sp->tasklet_status));
3623 atomic_dec(&sp->isr_cnt);
3624 return IRQ_HANDLED;
3625 }
3626 clear_bit(0, (&sp->tasklet_status));
3627 } else if (level == LOW) {
3628 tasklet_schedule(&sp->task);
3629 }
3630 }
3631
3632 atomic_dec(&sp->isr_cnt);
3633 return IRQ_HANDLED;
3634}
3635
3636static irqreturn_t
3637s2io_msix_ring_handle(int irq, void *dev_id, struct pt_regs *regs)
3638{
3639 ring_info_t *ring = (ring_info_t *)dev_id;
3640 nic_t *sp = ring->nic;
3641 int rxb_size, level, rng_n;
3642
3643 atomic_inc(&sp->isr_cnt);
3644 rx_intr_handler(ring);
3645
3646 rng_n = ring->ring_no;
3647 rxb_size = atomic_read(&sp->rx_bufs_left[rng_n]);
3648 level = rx_buffer_level(sp, rxb_size, rng_n);
3649
3650 if ((level == PANIC) && (!TASKLET_IN_USE)) {
3651 int ret;
3652 DBG_PRINT(INTR_DBG, "%s: Rx BD hit ", __FUNCTION__);
3653 DBG_PRINT(INTR_DBG, "PANIC levels\n");
3654 if ((ret = fill_rx_buffers(sp, rng_n)) == -ENOMEM) {
3655 DBG_PRINT(ERR_DBG, "Out of memory in %s",
3656 __FUNCTION__);
3657 clear_bit(0, (&sp->tasklet_status));
3658 return IRQ_HANDLED;
3659 }
3660 clear_bit(0, (&sp->tasklet_status));
3661 } else if (level == LOW) {
3662 tasklet_schedule(&sp->task);
3663 }
3664 atomic_dec(&sp->isr_cnt);
3665
3666 return IRQ_HANDLED;
3667}
3668
3669static irqreturn_t
3670s2io_msix_fifo_handle(int irq, void *dev_id, struct pt_regs *regs)
3671{
3672 fifo_info_t *fifo = (fifo_info_t *)dev_id;
3673 nic_t *sp = fifo->nic;
3674
3675 atomic_inc(&sp->isr_cnt);
3676 tx_intr_handler(fifo);
3677 atomic_dec(&sp->isr_cnt);
3678 return IRQ_HANDLED;
3679}
3680
3281static void s2io_txpic_intr_handle(nic_t *sp) 3681static void s2io_txpic_intr_handle(nic_t *sp)
3282{ 3682{
3283 XENA_dev_config_t __iomem *bar0 = sp->bar0; 3683 XENA_dev_config_t __iomem *bar0 = sp->bar0;
@@ -3778,11 +4178,10 @@ static void s2io_ethtool_gdrvinfo(struct net_device *dev,
3778{ 4178{
3779 nic_t *sp = dev->priv; 4179 nic_t *sp = dev->priv;
3780 4180
3781 strncpy(info->driver, s2io_driver_name, sizeof(s2io_driver_name)); 4181 strncpy(info->driver, s2io_driver_name, sizeof(info->driver));
3782 strncpy(info->version, s2io_driver_version, 4182 strncpy(info->version, s2io_driver_version, sizeof(info->version));
3783 sizeof(s2io_driver_version)); 4183 strncpy(info->fw_version, "", sizeof(info->fw_version));
3784 strncpy(info->fw_version, "", 32); 4184 strncpy(info->bus_info, pci_name(sp->pdev), sizeof(info->bus_info));
3785 strncpy(info->bus_info, pci_name(sp->pdev), 32);
3786 info->regdump_len = XENA_REG_SPACE; 4185 info->regdump_len = XENA_REG_SPACE;
3787 info->eedump_len = XENA_EEPROM_SPACE; 4186 info->eedump_len = XENA_EEPROM_SPACE;
3788 info->testinfo_len = S2IO_TEST_LEN; 4187 info->testinfo_len = S2IO_TEST_LEN;
@@ -3978,29 +4377,53 @@ static int s2io_ethtool_setpause_data(struct net_device *dev,
3978 */ 4377 */
3979 4378
3980#define S2IO_DEV_ID 5 4379#define S2IO_DEV_ID 5
3981static int read_eeprom(nic_t * sp, int off, u32 * data) 4380static int read_eeprom(nic_t * sp, int off, u64 * data)
3982{ 4381{
3983 int ret = -1; 4382 int ret = -1;
3984 u32 exit_cnt = 0; 4383 u32 exit_cnt = 0;
3985 u64 val64; 4384 u64 val64;
3986 XENA_dev_config_t __iomem *bar0 = sp->bar0; 4385 XENA_dev_config_t __iomem *bar0 = sp->bar0;
3987 4386
3988 val64 = I2C_CONTROL_DEV_ID(S2IO_DEV_ID) | I2C_CONTROL_ADDR(off) | 4387 if (sp->device_type == XFRAME_I_DEVICE) {
3989 I2C_CONTROL_BYTE_CNT(0x3) | I2C_CONTROL_READ | 4388 val64 = I2C_CONTROL_DEV_ID(S2IO_DEV_ID) | I2C_CONTROL_ADDR(off) |
3990 I2C_CONTROL_CNTL_START; 4389 I2C_CONTROL_BYTE_CNT(0x3) | I2C_CONTROL_READ |
3991 SPECIAL_REG_WRITE(val64, &bar0->i2c_control, LF); 4390 I2C_CONTROL_CNTL_START;
4391 SPECIAL_REG_WRITE(val64, &bar0->i2c_control, LF);
3992 4392
3993 while (exit_cnt < 5) { 4393 while (exit_cnt < 5) {
3994 val64 = readq(&bar0->i2c_control); 4394 val64 = readq(&bar0->i2c_control);
3995 if (I2C_CONTROL_CNTL_END(val64)) { 4395 if (I2C_CONTROL_CNTL_END(val64)) {
3996 *data = I2C_CONTROL_GET_DATA(val64); 4396 *data = I2C_CONTROL_GET_DATA(val64);
3997 ret = 0; 4397 ret = 0;
3998 break; 4398 break;
4399 }
4400 msleep(50);
4401 exit_cnt++;
3999 } 4402 }
4000 msleep(50);
4001 exit_cnt++;
4002 } 4403 }
4003 4404
4405 if (sp->device_type == XFRAME_II_DEVICE) {
4406 val64 = SPI_CONTROL_KEY(0x9) | SPI_CONTROL_SEL1 |
4407 SPI_CONTROL_BYTECNT(0x3) |
4408 SPI_CONTROL_CMD(0x3) | SPI_CONTROL_ADDR(off);
4409 SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
4410 val64 |= SPI_CONTROL_REQ;
4411 SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
4412 while (exit_cnt < 5) {
4413 val64 = readq(&bar0->spi_control);
4414 if (val64 & SPI_CONTROL_NACK) {
4415 ret = 1;
4416 break;
4417 } else if (val64 & SPI_CONTROL_DONE) {
4418 *data = readq(&bar0->spi_data);
4419 *data &= 0xffffff;
4420 ret = 0;
4421 break;
4422 }
4423 msleep(50);
4424 exit_cnt++;
4425 }
4426 }
4004 return ret; 4427 return ret;
4005} 4428}
4006 4429
@@ -4019,28 +4442,53 @@ static int read_eeprom(nic_t * sp, int off, u32 * data)
4019 * 0 on success, -1 on failure. 4442 * 0 on success, -1 on failure.
4020 */ 4443 */
4021 4444
4022static int write_eeprom(nic_t * sp, int off, u32 data, int cnt) 4445static int write_eeprom(nic_t * sp, int off, u64 data, int cnt)
4023{ 4446{
4024 int exit_cnt = 0, ret = -1; 4447 int exit_cnt = 0, ret = -1;
4025 u64 val64; 4448 u64 val64;
4026 XENA_dev_config_t __iomem *bar0 = sp->bar0; 4449 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4027 4450
4028 val64 = I2C_CONTROL_DEV_ID(S2IO_DEV_ID) | I2C_CONTROL_ADDR(off) | 4451 if (sp->device_type == XFRAME_I_DEVICE) {
4029 I2C_CONTROL_BYTE_CNT(cnt) | I2C_CONTROL_SET_DATA(data) | 4452 val64 = I2C_CONTROL_DEV_ID(S2IO_DEV_ID) | I2C_CONTROL_ADDR(off) |
4030 I2C_CONTROL_CNTL_START; 4453 I2C_CONTROL_BYTE_CNT(cnt) | I2C_CONTROL_SET_DATA((u32)data) |
4031 SPECIAL_REG_WRITE(val64, &bar0->i2c_control, LF); 4454 I2C_CONTROL_CNTL_START;
4455 SPECIAL_REG_WRITE(val64, &bar0->i2c_control, LF);
4456
4457 while (exit_cnt < 5) {
4458 val64 = readq(&bar0->i2c_control);
4459 if (I2C_CONTROL_CNTL_END(val64)) {
4460 if (!(val64 & I2C_CONTROL_NACK))
4461 ret = 0;
4462 break;
4463 }
4464 msleep(50);
4465 exit_cnt++;
4466 }
4467 }
4032 4468
4033 while (exit_cnt < 5) { 4469 if (sp->device_type == XFRAME_II_DEVICE) {
4034 val64 = readq(&bar0->i2c_control); 4470 int write_cnt = (cnt == 8) ? 0 : cnt;
4035 if (I2C_CONTROL_CNTL_END(val64)) { 4471 writeq(SPI_DATA_WRITE(data,(cnt<<3)), &bar0->spi_data);
4036 if (!(val64 & I2C_CONTROL_NACK)) 4472
4473 val64 = SPI_CONTROL_KEY(0x9) | SPI_CONTROL_SEL1 |
4474 SPI_CONTROL_BYTECNT(write_cnt) |
4475 SPI_CONTROL_CMD(0x2) | SPI_CONTROL_ADDR(off);
4476 SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
4477 val64 |= SPI_CONTROL_REQ;
4478 SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
4479 while (exit_cnt < 5) {
4480 val64 = readq(&bar0->spi_control);
4481 if (val64 & SPI_CONTROL_NACK) {
4482 ret = 1;
4483 break;
4484 } else if (val64 & SPI_CONTROL_DONE) {
4037 ret = 0; 4485 ret = 0;
4038 break; 4486 break;
4487 }
4488 msleep(50);
4489 exit_cnt++;
4039 } 4490 }
4040 msleep(50);
4041 exit_cnt++;
4042 } 4491 }
4043
4044 return ret; 4492 return ret;
4045} 4493}
4046 4494
@@ -4060,7 +4508,8 @@ static int write_eeprom(nic_t * sp, int off, u32 data, int cnt)
4060static int s2io_ethtool_geeprom(struct net_device *dev, 4508static int s2io_ethtool_geeprom(struct net_device *dev,
4061 struct ethtool_eeprom *eeprom, u8 * data_buf) 4509 struct ethtool_eeprom *eeprom, u8 * data_buf)
4062{ 4510{
4063 u32 data, i, valid; 4511 u32 i, valid;
4512 u64 data;
4064 nic_t *sp = dev->priv; 4513 nic_t *sp = dev->priv;
4065 4514
4066 eeprom->magic = sp->pdev->vendor | (sp->pdev->device << 16); 4515 eeprom->magic = sp->pdev->vendor | (sp->pdev->device << 16);
@@ -4098,7 +4547,7 @@ static int s2io_ethtool_seeprom(struct net_device *dev,
4098 u8 * data_buf) 4547 u8 * data_buf)
4099{ 4548{
4100 int len = eeprom->len, cnt = 0; 4549 int len = eeprom->len, cnt = 0;
4101 u32 valid = 0, data; 4550 u64 valid = 0, data;
4102 nic_t *sp = dev->priv; 4551 nic_t *sp = dev->priv;
4103 4552
4104 if (eeprom->magic != (sp->pdev->vendor | (sp->pdev->device << 16))) { 4553 if (eeprom->magic != (sp->pdev->vendor | (sp->pdev->device << 16))) {
@@ -4146,7 +4595,7 @@ static int s2io_ethtool_seeprom(struct net_device *dev,
4146static int s2io_register_test(nic_t * sp, uint64_t * data) 4595static int s2io_register_test(nic_t * sp, uint64_t * data)
4147{ 4596{
4148 XENA_dev_config_t __iomem *bar0 = sp->bar0; 4597 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4149 u64 val64 = 0; 4598 u64 val64 = 0, exp_val;
4150 int fail = 0; 4599 int fail = 0;
4151 4600
4152 val64 = readq(&bar0->pif_rd_swapper_fb); 4601 val64 = readq(&bar0->pif_rd_swapper_fb);
@@ -4162,7 +4611,11 @@ static int s2io_register_test(nic_t * sp, uint64_t * data)
4162 } 4611 }
4163 4612
4164 val64 = readq(&bar0->rx_queue_cfg); 4613 val64 = readq(&bar0->rx_queue_cfg);
4165 if (val64 != 0x0808080808080808ULL) { 4614 if (sp->device_type == XFRAME_II_DEVICE)
4615 exp_val = 0x0404040404040404ULL;
4616 else
4617 exp_val = 0x0808080808080808ULL;
4618 if (val64 != exp_val) {
4166 fail = 1; 4619 fail = 1;
4167 DBG_PRINT(INFO_DBG, "Read Test level 3 fails\n"); 4620 DBG_PRINT(INFO_DBG, "Read Test level 3 fails\n");
4168 } 4621 }
@@ -4190,7 +4643,7 @@ static int s2io_register_test(nic_t * sp, uint64_t * data)
4190 } 4643 }
4191 4644
4192 *data = fail; 4645 *data = fail;
4193 return 0; 4646 return fail;
4194} 4647}
4195 4648
4196/** 4649/**
@@ -4209,58 +4662,83 @@ static int s2io_register_test(nic_t * sp, uint64_t * data)
4209static int s2io_eeprom_test(nic_t * sp, uint64_t * data) 4662static int s2io_eeprom_test(nic_t * sp, uint64_t * data)
4210{ 4663{
4211 int fail = 0; 4664 int fail = 0;
4212 u32 ret_data; 4665 u64 ret_data, org_4F0, org_7F0;
4666 u8 saved_4F0 = 0, saved_7F0 = 0;
4667 struct net_device *dev = sp->dev;
4213 4668
4214 /* Test Write Error at offset 0 */ 4669 /* Test Write Error at offset 0 */
4215 if (!write_eeprom(sp, 0, 0, 3)) 4670 /* Note that SPI interface allows write access to all areas
4216 fail = 1; 4671 * of EEPROM. Hence doing all negative testing only for Xframe I.
4672 */
4673 if (sp->device_type == XFRAME_I_DEVICE)
4674 if (!write_eeprom(sp, 0, 0, 3))
4675 fail = 1;
4676
4677 /* Save current values at offsets 0x4F0 and 0x7F0 */
4678 if (!read_eeprom(sp, 0x4F0, &org_4F0))
4679 saved_4F0 = 1;
4680 if (!read_eeprom(sp, 0x7F0, &org_7F0))
4681 saved_7F0 = 1;
4217 4682
4218 /* Test Write at offset 4f0 */ 4683 /* Test Write at offset 4f0 */
4219 if (write_eeprom(sp, 0x4F0, 0x01234567, 3)) 4684 if (write_eeprom(sp, 0x4F0, 0x012345, 3))
4220 fail = 1; 4685 fail = 1;
4221 if (read_eeprom(sp, 0x4F0, &ret_data)) 4686 if (read_eeprom(sp, 0x4F0, &ret_data))
4222 fail = 1; 4687 fail = 1;
4223 4688
4224 if (ret_data != 0x01234567) 4689 if (ret_data != 0x012345) {
4690 DBG_PRINT(ERR_DBG, "%s: eeprom test error at offset 0x4F0. Data written %llx Data read %llx\n", dev->name, (u64)0x12345, ret_data);
4225 fail = 1; 4691 fail = 1;
4692 }
4226 4693
4227 /* Reset the EEPROM data go FFFF */ 4694 /* Reset the EEPROM data go FFFF */
4228 write_eeprom(sp, 0x4F0, 0xFFFFFFFF, 3); 4695 write_eeprom(sp, 0x4F0, 0xFFFFFF, 3);
4229 4696
4230 /* Test Write Request Error at offset 0x7c */ 4697 /* Test Write Request Error at offset 0x7c */
4231 if (!write_eeprom(sp, 0x07C, 0, 3)) 4698 if (sp->device_type == XFRAME_I_DEVICE)
4232 fail = 1; 4699 if (!write_eeprom(sp, 0x07C, 0, 3))
4700 fail = 1;
4233 4701
4234 /* Test Write Request at offset 0x7fc */ 4702 /* Test Write Request at offset 0x7f0 */
4235 if (write_eeprom(sp, 0x7FC, 0x01234567, 3)) 4703 if (write_eeprom(sp, 0x7F0, 0x012345, 3))
4236 fail = 1; 4704 fail = 1;
4237 if (read_eeprom(sp, 0x7FC, &ret_data)) 4705 if (read_eeprom(sp, 0x7F0, &ret_data))
4238 fail = 1; 4706 fail = 1;
4239 4707
4240 if (ret_data != 0x01234567) 4708 if (ret_data != 0x012345) {
4709 DBG_PRINT(ERR_DBG, "%s: eeprom test error at offset 0x7F0. Data written %llx Data read %llx\n", dev->name, (u64)0x12345, ret_data);
4241 fail = 1; 4710 fail = 1;
4711 }
4242 4712
4243 /* Reset the EEPROM data go FFFF */ 4713 /* Reset the EEPROM data go FFFF */
4244 write_eeprom(sp, 0x7FC, 0xFFFFFFFF, 3); 4714 write_eeprom(sp, 0x7F0, 0xFFFFFF, 3);
4245 4715
4246 /* Test Write Error at offset 0x80 */ 4716 if (sp->device_type == XFRAME_I_DEVICE) {
4247 if (!write_eeprom(sp, 0x080, 0, 3)) 4717 /* Test Write Error at offset 0x80 */
4248 fail = 1; 4718 if (!write_eeprom(sp, 0x080, 0, 3))
4719 fail = 1;
4249 4720
4250 /* Test Write Error at offset 0xfc */ 4721 /* Test Write Error at offset 0xfc */
4251 if (!write_eeprom(sp, 0x0FC, 0, 3)) 4722 if (!write_eeprom(sp, 0x0FC, 0, 3))
4252 fail = 1; 4723 fail = 1;
4253 4724
4254 /* Test Write Error at offset 0x100 */ 4725 /* Test Write Error at offset 0x100 */
4255 if (!write_eeprom(sp, 0x100, 0, 3)) 4726 if (!write_eeprom(sp, 0x100, 0, 3))
4256 fail = 1; 4727 fail = 1;
4257 4728
4258 /* Test Write Error at offset 4ec */ 4729 /* Test Write Error at offset 4ec */
4259 if (!write_eeprom(sp, 0x4EC, 0, 3)) 4730 if (!write_eeprom(sp, 0x4EC, 0, 3))
4260 fail = 1; 4731 fail = 1;
4732 }
4733
4734 /* Restore values at offsets 0x4F0 and 0x7F0 */
4735 if (saved_4F0)
4736 write_eeprom(sp, 0x4F0, org_4F0, 3);
4737 if (saved_7F0)
4738 write_eeprom(sp, 0x7F0, org_7F0, 3);
4261 4739
4262 *data = fail; 4740 *data = fail;
4263 return 0; 4741 return fail;
4264} 4742}
4265 4743
4266/** 4744/**
@@ -4342,7 +4820,7 @@ static int s2io_rldram_test(nic_t * sp, uint64_t * data)
4342{ 4820{
4343 XENA_dev_config_t __iomem *bar0 = sp->bar0; 4821 XENA_dev_config_t __iomem *bar0 = sp->bar0;
4344 u64 val64; 4822 u64 val64;
4345 int cnt, iteration = 0, test_pass = 0; 4823 int cnt, iteration = 0, test_fail = 0;
4346 4824
4347 val64 = readq(&bar0->adapter_control); 4825 val64 = readq(&bar0->adapter_control);
4348 val64 &= ~ADAPTER_ECC_EN; 4826 val64 &= ~ADAPTER_ECC_EN;
@@ -4350,7 +4828,7 @@ static int s2io_rldram_test(nic_t * sp, uint64_t * data)
4350 4828
4351 val64 = readq(&bar0->mc_rldram_test_ctrl); 4829 val64 = readq(&bar0->mc_rldram_test_ctrl);
4352 val64 |= MC_RLDRAM_TEST_MODE; 4830 val64 |= MC_RLDRAM_TEST_MODE;
4353 writeq(val64, &bar0->mc_rldram_test_ctrl); 4831 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
4354 4832
4355 val64 = readq(&bar0->mc_rldram_mrs); 4833 val64 = readq(&bar0->mc_rldram_mrs);
4356 val64 |= MC_RLDRAM_QUEUE_SIZE_ENABLE; 4834 val64 |= MC_RLDRAM_QUEUE_SIZE_ENABLE;
@@ -4378,17 +4856,12 @@ static int s2io_rldram_test(nic_t * sp, uint64_t * data)
4378 } 4856 }
4379 writeq(val64, &bar0->mc_rldram_test_d2); 4857 writeq(val64, &bar0->mc_rldram_test_d2);
4380 4858
4381 val64 = (u64) (0x0000003fffff0000ULL); 4859 val64 = (u64) (0x0000003ffffe0100ULL);
4382 writeq(val64, &bar0->mc_rldram_test_add); 4860 writeq(val64, &bar0->mc_rldram_test_add);
4383 4861
4384 4862 val64 = MC_RLDRAM_TEST_MODE | MC_RLDRAM_TEST_WRITE |
4385 val64 = MC_RLDRAM_TEST_MODE; 4863 MC_RLDRAM_TEST_GO;
4386 writeq(val64, &bar0->mc_rldram_test_ctrl); 4864 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
4387
4388 val64 |=
4389 MC_RLDRAM_TEST_MODE | MC_RLDRAM_TEST_WRITE |
4390 MC_RLDRAM_TEST_GO;
4391 writeq(val64, &bar0->mc_rldram_test_ctrl);
4392 4865
4393 for (cnt = 0; cnt < 5; cnt++) { 4866 for (cnt = 0; cnt < 5; cnt++) {
4394 val64 = readq(&bar0->mc_rldram_test_ctrl); 4867 val64 = readq(&bar0->mc_rldram_test_ctrl);
@@ -4400,11 +4873,8 @@ static int s2io_rldram_test(nic_t * sp, uint64_t * data)
4400 if (cnt == 5) 4873 if (cnt == 5)
4401 break; 4874 break;
4402 4875
4403 val64 = MC_RLDRAM_TEST_MODE; 4876 val64 = MC_RLDRAM_TEST_MODE | MC_RLDRAM_TEST_GO;
4404 writeq(val64, &bar0->mc_rldram_test_ctrl); 4877 SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
4405
4406 val64 |= MC_RLDRAM_TEST_MODE | MC_RLDRAM_TEST_GO;
4407 writeq(val64, &bar0->mc_rldram_test_ctrl);
4408 4878
4409 for (cnt = 0; cnt < 5; cnt++) { 4879 for (cnt = 0; cnt < 5; cnt++) {
4410 val64 = readq(&bar0->mc_rldram_test_ctrl); 4880 val64 = readq(&bar0->mc_rldram_test_ctrl);
@@ -4417,18 +4887,18 @@ static int s2io_rldram_test(nic_t * sp, uint64_t * data)
4417 break; 4887 break;
4418 4888
4419 val64 = readq(&bar0->mc_rldram_test_ctrl); 4889 val64 = readq(&bar0->mc_rldram_test_ctrl);
4420 if (val64 & MC_RLDRAM_TEST_PASS) 4890 if (!(val64 & MC_RLDRAM_TEST_PASS))
4421 test_pass = 1; 4891 test_fail = 1;
4422 4892
4423 iteration++; 4893 iteration++;
4424 } 4894 }
4425 4895
4426 if (!test_pass) 4896 *data = test_fail;
4427 *data = 1;
4428 else
4429 *data = 0;
4430 4897
4431 return 0; 4898 /* Bring the adapter out of test mode */
4899 SPECIAL_REG_WRITE(0, &bar0->mc_rldram_test_ctrl, LF);
4900
4901 return test_fail;
4432} 4902}
4433 4903
4434/** 4904/**
@@ -4932,7 +5402,7 @@ static void s2io_card_down(nic_t * sp)
4932 5402
4933static int s2io_card_up(nic_t * sp) 5403static int s2io_card_up(nic_t * sp)
4934{ 5404{
4935 int i, ret; 5405 int i, ret = 0;
4936 mac_info_t *mac_control; 5406 mac_info_t *mac_control;
4937 struct config_param *config; 5407 struct config_param *config;
4938 struct net_device *dev = (struct net_device *) sp->dev; 5408 struct net_device *dev = (struct net_device *) sp->dev;
@@ -4944,6 +5414,15 @@ static int s2io_card_up(nic_t * sp)
4944 return -ENODEV; 5414 return -ENODEV;
4945 } 5415 }
4946 5416
5417 if (sp->intr_type == MSI)
5418 ret = s2io_enable_msi(sp);
5419 else if (sp->intr_type == MSI_X)
5420 ret = s2io_enable_msi_x(sp);
5421 if (ret) {
5422 DBG_PRINT(ERR_DBG, "%s: Defaulting to INTA\n", dev->name);
5423 sp->intr_type = INTA;
5424 }
5425
4947 /* 5426 /*
4948 * Initializing the Rx buffers. For now we are considering only 1 5427 * Initializing the Rx buffers. For now we are considering only 1
4949 * Rx ring and initializing buffers into 30 Rx blocks 5428 * Rx ring and initializing buffers into 30 Rx blocks
@@ -5228,6 +5707,8 @@ static void s2io_init_pci(nic_t * sp)
5228 5707
5229MODULE_AUTHOR("Raghavendra Koushik <raghavendra.koushik@neterion.com>"); 5708MODULE_AUTHOR("Raghavendra Koushik <raghavendra.koushik@neterion.com>");
5230MODULE_LICENSE("GPL"); 5709MODULE_LICENSE("GPL");
5710MODULE_VERSION(DRV_VERSION);
5711
5231module_param(tx_fifo_num, int, 0); 5712module_param(tx_fifo_num, int, 0);
5232module_param(rx_ring_num, int, 0); 5713module_param(rx_ring_num, int, 0);
5233module_param_array(tx_fifo_len, uint, NULL, 0); 5714module_param_array(tx_fifo_len, uint, NULL, 0);
@@ -5245,6 +5726,7 @@ module_param(bimodal, bool, 0);
5245module_param(indicate_max_pkts, int, 0); 5726module_param(indicate_max_pkts, int, 0);
5246#endif 5727#endif
5247module_param(rxsync_frequency, int, 0); 5728module_param(rxsync_frequency, int, 0);
5729module_param(intr_type, int, 0);
5248 5730
5249/** 5731/**
5250 * s2io_init_nic - Initialization of the adapter . 5732 * s2io_init_nic - Initialization of the adapter .
@@ -5274,9 +5756,16 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
5274 mac_info_t *mac_control; 5756 mac_info_t *mac_control;
5275 struct config_param *config; 5757 struct config_param *config;
5276 int mode; 5758 int mode;
5759 u8 dev_intr_type = intr_type;
5277 5760
5278#ifdef CONFIG_S2IO_NAPI 5761#ifdef CONFIG_S2IO_NAPI
5279 DBG_PRINT(ERR_DBG, "NAPI support has been enabled\n"); 5762 if (dev_intr_type != INTA) {
5763 DBG_PRINT(ERR_DBG, "NAPI cannot be enabled when MSI/MSI-X \
5764is enabled. Defaulting to INTA\n");
5765 dev_intr_type = INTA;
5766 }
5767 else
5768 DBG_PRINT(ERR_DBG, "NAPI support has been enabled\n");
5280#endif 5769#endif
5281 5770
5282 if ((ret = pci_enable_device(pdev))) { 5771 if ((ret = pci_enable_device(pdev))) {
@@ -5303,10 +5792,35 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
5303 return -ENOMEM; 5792 return -ENOMEM;
5304 } 5793 }
5305 5794
5306 if (pci_request_regions(pdev, s2io_driver_name)) { 5795 if ((dev_intr_type == MSI_X) &&
5307 DBG_PRINT(ERR_DBG, "Request Regions failed\n"), 5796 ((pdev->device != PCI_DEVICE_ID_HERC_WIN) &&
5308 pci_disable_device(pdev); 5797 (pdev->device != PCI_DEVICE_ID_HERC_UNI))) {
5309 return -ENODEV; 5798 DBG_PRINT(ERR_DBG, "Xframe I does not support MSI_X. \
5799Defaulting to INTA\n");
5800 dev_intr_type = INTA;
5801 }
5802 if (dev_intr_type != MSI_X) {
5803 if (pci_request_regions(pdev, s2io_driver_name)) {
5804 DBG_PRINT(ERR_DBG, "Request Regions failed\n"),
5805 pci_disable_device(pdev);
5806 return -ENODEV;
5807 }
5808 }
5809 else {
5810 if (!(request_mem_region(pci_resource_start(pdev, 0),
5811 pci_resource_len(pdev, 0), s2io_driver_name))) {
5812 DBG_PRINT(ERR_DBG, "bar0 Request Regions failed\n");
5813 pci_disable_device(pdev);
5814 return -ENODEV;
5815 }
5816 if (!(request_mem_region(pci_resource_start(pdev, 2),
5817 pci_resource_len(pdev, 2), s2io_driver_name))) {
5818 DBG_PRINT(ERR_DBG, "bar1 Request Regions failed\n");
5819 release_mem_region(pci_resource_start(pdev, 0),
5820 pci_resource_len(pdev, 0));
5821 pci_disable_device(pdev);
5822 return -ENODEV;
5823 }
5310 } 5824 }
5311 5825
5312 dev = alloc_etherdev(sizeof(nic_t)); 5826 dev = alloc_etherdev(sizeof(nic_t));
@@ -5329,6 +5843,7 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
5329 sp->pdev = pdev; 5843 sp->pdev = pdev;
5330 sp->high_dma_flag = dma_flag; 5844 sp->high_dma_flag = dma_flag;
5331 sp->device_enabled_once = FALSE; 5845 sp->device_enabled_once = FALSE;
5846 sp->intr_type = dev_intr_type;
5332 5847
5333 if ((pdev->device == PCI_DEVICE_ID_HERC_WIN) || 5848 if ((pdev->device == PCI_DEVICE_ID_HERC_WIN) ||
5334 (pdev->device == PCI_DEVICE_ID_HERC_UNI)) 5849 (pdev->device == PCI_DEVICE_ID_HERC_UNI))
@@ -5336,6 +5851,7 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
5336 else 5851 else
5337 sp->device_type = XFRAME_I_DEVICE; 5852 sp->device_type = XFRAME_I_DEVICE;
5338 5853
5854
5339 /* Initialize some PCI/PCI-X fields of the NIC. */ 5855 /* Initialize some PCI/PCI-X fields of the NIC. */
5340 s2io_init_pci(sp); 5856 s2io_init_pci(sp);
5341 5857
@@ -5571,12 +6087,23 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
5571 if (sp->device_type & XFRAME_II_DEVICE) { 6087 if (sp->device_type & XFRAME_II_DEVICE) {
5572 DBG_PRINT(ERR_DBG, "%s: Neterion Xframe II 10GbE adapter ", 6088 DBG_PRINT(ERR_DBG, "%s: Neterion Xframe II 10GbE adapter ",
5573 dev->name); 6089 dev->name);
5574 DBG_PRINT(ERR_DBG, "(rev %d), %s", 6090 DBG_PRINT(ERR_DBG, "(rev %d), Version %s",
5575 get_xena_rev_id(sp->pdev), 6091 get_xena_rev_id(sp->pdev),
5576 s2io_driver_version); 6092 s2io_driver_version);
5577#ifdef CONFIG_2BUFF_MODE 6093#ifdef CONFIG_2BUFF_MODE
5578 DBG_PRINT(ERR_DBG, ", Buffer mode %d",2); 6094 DBG_PRINT(ERR_DBG, ", Buffer mode %d",2);
5579#endif 6095#endif
6096 switch(sp->intr_type) {
6097 case INTA:
6098 DBG_PRINT(ERR_DBG, ", Intr type INTA");
6099 break;
6100 case MSI:
6101 DBG_PRINT(ERR_DBG, ", Intr type MSI");
6102 break;
6103 case MSI_X:
6104 DBG_PRINT(ERR_DBG, ", Intr type MSI-X");
6105 break;
6106 }
5580 6107
5581 DBG_PRINT(ERR_DBG, "\nCopyright(c) 2002-2005 Neterion Inc.\n"); 6108 DBG_PRINT(ERR_DBG, "\nCopyright(c) 2002-2005 Neterion Inc.\n");
5582 DBG_PRINT(ERR_DBG, "MAC ADDR: %02x:%02x:%02x:%02x:%02x:%02x\n", 6109 DBG_PRINT(ERR_DBG, "MAC ADDR: %02x:%02x:%02x:%02x:%02x:%02x\n",
@@ -5595,12 +6122,23 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
5595 } else { 6122 } else {
5596 DBG_PRINT(ERR_DBG, "%s: Neterion Xframe I 10GbE adapter ", 6123 DBG_PRINT(ERR_DBG, "%s: Neterion Xframe I 10GbE adapter ",
5597 dev->name); 6124 dev->name);
5598 DBG_PRINT(ERR_DBG, "(rev %d), %s", 6125 DBG_PRINT(ERR_DBG, "(rev %d), Version %s",
5599 get_xena_rev_id(sp->pdev), 6126 get_xena_rev_id(sp->pdev),
5600 s2io_driver_version); 6127 s2io_driver_version);
5601#ifdef CONFIG_2BUFF_MODE 6128#ifdef CONFIG_2BUFF_MODE
5602 DBG_PRINT(ERR_DBG, ", Buffer mode %d",2); 6129 DBG_PRINT(ERR_DBG, ", Buffer mode %d",2);
5603#endif 6130#endif
6131 switch(sp->intr_type) {
6132 case INTA:
6133 DBG_PRINT(ERR_DBG, ", Intr type INTA");
6134 break;
6135 case MSI:
6136 DBG_PRINT(ERR_DBG, ", Intr type MSI");
6137 break;
6138 case MSI_X:
6139 DBG_PRINT(ERR_DBG, ", Intr type MSI-X");
6140 break;
6141 }
5604 DBG_PRINT(ERR_DBG, "\nCopyright(c) 2002-2005 Neterion Inc.\n"); 6142 DBG_PRINT(ERR_DBG, "\nCopyright(c) 2002-2005 Neterion Inc.\n");
5605 DBG_PRINT(ERR_DBG, "MAC ADDR: %02x:%02x:%02x:%02x:%02x:%02x\n", 6143 DBG_PRINT(ERR_DBG, "MAC ADDR: %02x:%02x:%02x:%02x:%02x:%02x\n",
5606 sp->def_mac_addr[0].mac_addr[0], 6144 sp->def_mac_addr[0].mac_addr[0],
@@ -5644,7 +6182,14 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
5644 mem_alloc_failed: 6182 mem_alloc_failed:
5645 free_shared_mem(sp); 6183 free_shared_mem(sp);
5646 pci_disable_device(pdev); 6184 pci_disable_device(pdev);
5647 pci_release_regions(pdev); 6185 if (dev_intr_type != MSI_X)
6186 pci_release_regions(pdev);
6187 else {
6188 release_mem_region(pci_resource_start(pdev, 0),
6189 pci_resource_len(pdev, 0));
6190 release_mem_region(pci_resource_start(pdev, 2),
6191 pci_resource_len(pdev, 2));
6192 }
5648 pci_set_drvdata(pdev, NULL); 6193 pci_set_drvdata(pdev, NULL);
5649 free_netdev(dev); 6194 free_netdev(dev);
5650 6195
@@ -5678,7 +6223,14 @@ static void __devexit s2io_rem_nic(struct pci_dev *pdev)
5678 iounmap(sp->bar0); 6223 iounmap(sp->bar0);
5679 iounmap(sp->bar1); 6224 iounmap(sp->bar1);
5680 pci_disable_device(pdev); 6225 pci_disable_device(pdev);
5681 pci_release_regions(pdev); 6226 if (sp->intr_type != MSI_X)
6227 pci_release_regions(pdev);
6228 else {
6229 release_mem_region(pci_resource_start(pdev, 0),
6230 pci_resource_len(pdev, 0));
6231 release_mem_region(pci_resource_start(pdev, 2),
6232 pci_resource_len(pdev, 2));
6233 }
5682 pci_set_drvdata(pdev, NULL); 6234 pci_set_drvdata(pdev, NULL);
5683 free_netdev(dev); 6235 free_netdev(dev);
5684} 6236}
diff --git a/drivers/net/s2io.h b/drivers/net/s2io.h
index 89151cb52181..1cc24b56760e 100644
--- a/drivers/net/s2io.h
+++ b/drivers/net/s2io.h
@@ -652,6 +652,30 @@ typedef struct {
652#define SMALL_BLK_CNT 30 652#define SMALL_BLK_CNT 30
653#define LARGE_BLK_CNT 100 653#define LARGE_BLK_CNT 100
654 654
655/*
656 * Structure to keep track of the MSI-X vectors and the corresponding
657 * argument registered against each vector
658 */
659#define MAX_REQUESTED_MSI_X 17
660struct s2io_msix_entry
661{
662 u16 vector;
663 u16 entry;
664 void *arg;
665
666 u8 type;
667#define MSIX_FIFO_TYPE 1
668#define MSIX_RING_TYPE 2
669
670 u8 in_use;
671#define MSIX_REGISTERED_SUCCESS 0xAA
672};
673
674struct msix_info_st {
675 u64 addr;
676 u64 data;
677};
678
655/* Structure representing one instance of the NIC */ 679/* Structure representing one instance of the NIC */
656struct s2io_nic { 680struct s2io_nic {
657#ifdef CONFIG_S2IO_NAPI 681#ifdef CONFIG_S2IO_NAPI
@@ -719,13 +743,8 @@ struct s2io_nic {
719 * a schedule task that will set the correct Link state once the 743 * a schedule task that will set the correct Link state once the
720 * NIC's PHY has stabilized after a state change. 744 * NIC's PHY has stabilized after a state change.
721 */ 745 */
722#ifdef INIT_TQUEUE
723 struct tq_struct rst_timer_task;
724 struct tq_struct set_link_task;
725#else
726 struct work_struct rst_timer_task; 746 struct work_struct rst_timer_task;
727 struct work_struct set_link_task; 747 struct work_struct set_link_task;
728#endif
729 748
730 /* Flag that can be used to turn on or turn off the Rx checksum 749 /* Flag that can be used to turn on or turn off the Rx checksum
731 * offload feature. 750 * offload feature.
@@ -748,10 +767,23 @@ struct s2io_nic {
748 atomic_t card_state; 767 atomic_t card_state;
749 volatile unsigned long link_state; 768 volatile unsigned long link_state;
750 struct vlan_group *vlgrp; 769 struct vlan_group *vlgrp;
770#define MSIX_FLG 0xA5
771 struct msix_entry *entries;
772 struct s2io_msix_entry *s2io_entries;
773 char desc1[35];
774 char desc2[35];
775
776 struct msix_info_st msix_info[0x3f];
777
751#define XFRAME_I_DEVICE 1 778#define XFRAME_I_DEVICE 1
752#define XFRAME_II_DEVICE 2 779#define XFRAME_II_DEVICE 2
753 u8 device_type; 780 u8 device_type;
754 781
782#define INTA 0
783#define MSI 1
784#define MSI_X 2
785 u8 intr_type;
786
755 spinlock_t rx_lock; 787 spinlock_t rx_lock;
756 atomic_t isr_cnt; 788 atomic_t isr_cnt;
757}; 789};
@@ -886,6 +918,13 @@ static int s2io_poll(struct net_device *dev, int *budget);
886static void s2io_init_pci(nic_t * sp); 918static void s2io_init_pci(nic_t * sp);
887int s2io_set_mac_addr(struct net_device *dev, u8 * addr); 919int s2io_set_mac_addr(struct net_device *dev, u8 * addr);
888static void s2io_alarm_handle(unsigned long data); 920static void s2io_alarm_handle(unsigned long data);
921static int s2io_enable_msi(nic_t *nic);
922static irqreturn_t s2io_msi_handle(int irq, void *dev_id, struct pt_regs *regs);
923static irqreturn_t
924s2io_msix_ring_handle(int irq, void *dev_id, struct pt_regs *regs);
925static irqreturn_t
926s2io_msix_fifo_handle(int irq, void *dev_id, struct pt_regs *regs);
927int s2io_enable_msi_x(nic_t *nic);
889static irqreturn_t s2io_isr(int irq, void *dev_id, struct pt_regs *regs); 928static irqreturn_t s2io_isr(int irq, void *dev_id, struct pt_regs *regs);
890static int verify_xena_quiescence(nic_t *sp, u64 val64, int flag); 929static int verify_xena_quiescence(nic_t *sp, u64 val64, int flag);
891static struct ethtool_ops netdev_ethtool_ops; 930static struct ethtool_ops netdev_ethtool_ops;
@@ -894,4 +933,5 @@ int s2io_set_swapper(nic_t * sp);
894static void s2io_card_down(nic_t *nic); 933static void s2io_card_down(nic_t *nic);
895static int s2io_card_up(nic_t *nic); 934static int s2io_card_up(nic_t *nic);
896int get_xena_rev_id(struct pci_dev *pdev); 935int get_xena_rev_id(struct pci_dev *pdev);
936void restore_xmsi_data(nic_t *nic);
897#endif /* _S2IO_H */ 937#endif /* _S2IO_H */
diff --git a/drivers/net/saa9730.c b/drivers/net/saa9730.c
index fd0167077fbe..110e777f206e 100644
--- a/drivers/net/saa9730.c
+++ b/drivers/net/saa9730.c
@@ -997,10 +997,7 @@ static void __devexit saa9730_remove_one(struct pci_dev *pdev)
997 997
998 if (dev) { 998 if (dev) {
999 unregister_netdev(dev); 999 unregister_netdev(dev);
1000 1000 kfree(dev->priv);
1001 if (dev->priv)
1002 kfree(dev->priv);
1003
1004 free_netdev(dev); 1001 free_netdev(dev);
1005 pci_release_regions(pdev); 1002 pci_release_regions(pdev);
1006 pci_disable_device(pdev); 1003 pci_disable_device(pdev);
@@ -1096,8 +1093,7 @@ static int lan_saa9730_init(struct net_device *dev, int ioaddr, int irq)
1096 return 0; 1093 return 0;
1097 1094
1098 out: 1095 out:
1099 if (dev->priv) 1096 kfree(dev->priv);
1100 kfree(dev->priv);
1101 return ret; 1097 return ret;
1102} 1098}
1103 1099
diff --git a/drivers/net/sb1250-mac.c b/drivers/net/sb1250-mac.c
index 7abd55a4fb21..aa4ca1821759 100644
--- a/drivers/net/sb1250-mac.c
+++ b/drivers/net/sb1250-mac.c
@@ -10,7 +10,7 @@
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software 15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -118,8 +118,6 @@ MODULE_PARM_DESC(int_timeout, "Timeout value");
118 ********************************************************************* */ 118 ********************************************************************* */
119 119
120 120
121typedef unsigned long sbmac_port_t;
122
123typedef enum { sbmac_speed_auto, sbmac_speed_10, 121typedef enum { sbmac_speed_auto, sbmac_speed_10,
124 sbmac_speed_100, sbmac_speed_1000 } sbmac_speed_t; 122 sbmac_speed_100, sbmac_speed_1000 } sbmac_speed_t;
125 123
@@ -129,7 +127,7 @@ typedef enum { sbmac_duplex_auto, sbmac_duplex_half,
129typedef enum { sbmac_fc_auto, sbmac_fc_disabled, sbmac_fc_frame, 127typedef enum { sbmac_fc_auto, sbmac_fc_disabled, sbmac_fc_frame,
130 sbmac_fc_collision, sbmac_fc_carrier } sbmac_fc_t; 128 sbmac_fc_collision, sbmac_fc_carrier } sbmac_fc_t;
131 129
132typedef enum { sbmac_state_uninit, sbmac_state_off, sbmac_state_on, 130typedef enum { sbmac_state_uninit, sbmac_state_off, sbmac_state_on,
133 sbmac_state_broken } sbmac_state_t; 131 sbmac_state_broken } sbmac_state_t;
134 132
135 133
@@ -144,17 +142,13 @@ typedef enum { sbmac_state_uninit, sbmac_state_off, sbmac_state_on,
144 142
145#define NUMCACHEBLKS(x) (((x)+SMP_CACHE_BYTES-1)/SMP_CACHE_BYTES) 143#define NUMCACHEBLKS(x) (((x)+SMP_CACHE_BYTES-1)/SMP_CACHE_BYTES)
146 144
147#define SBMAC_READCSR(t) __raw_readq((unsigned long)t)
148#define SBMAC_WRITECSR(t,v) __raw_writeq(v, (unsigned long)t)
149
150
151#define SBMAC_MAX_TXDESCR 32 145#define SBMAC_MAX_TXDESCR 32
152#define SBMAC_MAX_RXDESCR 32 146#define SBMAC_MAX_RXDESCR 32
153 147
154#define ETHER_ALIGN 2 148#define ETHER_ALIGN 2
155#define ETHER_ADDR_LEN 6 149#define ETHER_ADDR_LEN 6
156#define ENET_PACKET_SIZE 1518 150#define ENET_PACKET_SIZE 1518
157/*#define ENET_PACKET_SIZE 9216 */ 151/*#define ENET_PACKET_SIZE 9216 */
158 152
159/********************************************************************** 153/**********************************************************************
160 * DMA Descriptor structure 154 * DMA Descriptor structure
@@ -172,12 +166,12 @@ typedef unsigned long paddr_t;
172 ********************************************************************* */ 166 ********************************************************************* */
173 167
174typedef struct sbmacdma_s { 168typedef struct sbmacdma_s {
175 169
176 /* 170 /*
177 * This stuff is used to identify the channel and the registers 171 * This stuff is used to identify the channel and the registers
178 * associated with it. 172 * associated with it.
179 */ 173 */
180 174
181 struct sbmac_softc *sbdma_eth; /* back pointer to associated MAC */ 175 struct sbmac_softc *sbdma_eth; /* back pointer to associated MAC */
182 int sbdma_channel; /* channel number */ 176 int sbdma_channel; /* channel number */
183 int sbdma_txdir; /* direction (1=transmit) */ 177 int sbdma_txdir; /* direction (1=transmit) */
@@ -187,21 +181,21 @@ typedef struct sbmacdma_s {
187 int sbdma_int_timeout; /* # usec rx/tx interrupt */ 181 int sbdma_int_timeout; /* # usec rx/tx interrupt */
188#endif 182#endif
189 183
190 sbmac_port_t sbdma_config0; /* DMA config register 0 */ 184 volatile void __iomem *sbdma_config0; /* DMA config register 0 */
191 sbmac_port_t sbdma_config1; /* DMA config register 1 */ 185 volatile void __iomem *sbdma_config1; /* DMA config register 1 */
192 sbmac_port_t sbdma_dscrbase; /* Descriptor base address */ 186 volatile void __iomem *sbdma_dscrbase; /* Descriptor base address */
193 sbmac_port_t sbdma_dscrcnt; /* Descriptor count register */ 187 volatile void __iomem *sbdma_dscrcnt; /* Descriptor count register */
194 sbmac_port_t sbdma_curdscr; /* current descriptor address */ 188 volatile void __iomem *sbdma_curdscr; /* current descriptor address */
195 189
196 /* 190 /*
197 * This stuff is for maintenance of the ring 191 * This stuff is for maintenance of the ring
198 */ 192 */
199 193
200 sbdmadscr_t *sbdma_dscrtable; /* base of descriptor table */ 194 sbdmadscr_t *sbdma_dscrtable; /* base of descriptor table */
201 sbdmadscr_t *sbdma_dscrtable_end; /* end of descriptor table */ 195 sbdmadscr_t *sbdma_dscrtable_end; /* end of descriptor table */
202 196
203 struct sk_buff **sbdma_ctxtable; /* context table, one per descr */ 197 struct sk_buff **sbdma_ctxtable; /* context table, one per descr */
204 198
205 paddr_t sbdma_dscrtable_phys; /* and also the phys addr */ 199 paddr_t sbdma_dscrtable_phys; /* and also the phys addr */
206 sbdmadscr_t *sbdma_addptr; /* next dscr for sw to add */ 200 sbdmadscr_t *sbdma_addptr; /* next dscr for sw to add */
207 sbdmadscr_t *sbdma_remptr; /* next dscr for sw to remove */ 201 sbdmadscr_t *sbdma_remptr; /* next dscr for sw to remove */
@@ -213,15 +207,15 @@ typedef struct sbmacdma_s {
213 ********************************************************************* */ 207 ********************************************************************* */
214 208
215struct sbmac_softc { 209struct sbmac_softc {
216 210
217 /* 211 /*
218 * Linux-specific things 212 * Linux-specific things
219 */ 213 */
220 214
221 struct net_device *sbm_dev; /* pointer to linux device */ 215 struct net_device *sbm_dev; /* pointer to linux device */
222 spinlock_t sbm_lock; /* spin lock */ 216 spinlock_t sbm_lock; /* spin lock */
223 struct timer_list sbm_timer; /* for monitoring MII */ 217 struct timer_list sbm_timer; /* for monitoring MII */
224 struct net_device_stats sbm_stats; 218 struct net_device_stats sbm_stats;
225 int sbm_devflags; /* current device flags */ 219 int sbm_devflags; /* current device flags */
226 220
227 int sbm_phy_oldbmsr; 221 int sbm_phy_oldbmsr;
@@ -229,31 +223,31 @@ struct sbmac_softc {
229 int sbm_phy_oldk1stsr; 223 int sbm_phy_oldk1stsr;
230 int sbm_phy_oldlinkstat; 224 int sbm_phy_oldlinkstat;
231 int sbm_buffersize; 225 int sbm_buffersize;
232 226
233 unsigned char sbm_phys[2]; 227 unsigned char sbm_phys[2];
234 228
235 /* 229 /*
236 * Controller-specific things 230 * Controller-specific things
237 */ 231 */
238 232
239 unsigned long sbm_base; /* MAC's base address */ 233 volatile void __iomem *sbm_base; /* MAC's base address */
240 sbmac_state_t sbm_state; /* current state */ 234 sbmac_state_t sbm_state; /* current state */
241 235
242 sbmac_port_t sbm_macenable; /* MAC Enable Register */ 236 volatile void __iomem *sbm_macenable; /* MAC Enable Register */
243 sbmac_port_t sbm_maccfg; /* MAC Configuration Register */ 237 volatile void __iomem *sbm_maccfg; /* MAC Configuration Register */
244 sbmac_port_t sbm_fifocfg; /* FIFO configuration register */ 238 volatile void __iomem *sbm_fifocfg; /* FIFO configuration register */
245 sbmac_port_t sbm_framecfg; /* Frame configuration register */ 239 volatile void __iomem *sbm_framecfg; /* Frame configuration register */
246 sbmac_port_t sbm_rxfilter; /* receive filter register */ 240 volatile void __iomem *sbm_rxfilter; /* receive filter register */
247 sbmac_port_t sbm_isr; /* Interrupt status register */ 241 volatile void __iomem *sbm_isr; /* Interrupt status register */
248 sbmac_port_t sbm_imr; /* Interrupt mask register */ 242 volatile void __iomem *sbm_imr; /* Interrupt mask register */
249 sbmac_port_t sbm_mdio; /* MDIO register */ 243 volatile void __iomem *sbm_mdio; /* MDIO register */
250 244
251 sbmac_speed_t sbm_speed; /* current speed */ 245 sbmac_speed_t sbm_speed; /* current speed */
252 sbmac_duplex_t sbm_duplex; /* current duplex */ 246 sbmac_duplex_t sbm_duplex; /* current duplex */
253 sbmac_fc_t sbm_fc; /* current flow control setting */ 247 sbmac_fc_t sbm_fc; /* current flow control setting */
254 248
255 unsigned char sbm_hwaddr[ETHER_ADDR_LEN]; 249 unsigned char sbm_hwaddr[ETHER_ADDR_LEN];
256 250
257 sbmacdma_t sbm_txdma; /* for now, only use channel 0 */ 251 sbmacdma_t sbm_txdma; /* for now, only use channel 0 */
258 sbmacdma_t sbm_rxdma; 252 sbmacdma_t sbm_rxdma;
259 int rx_hw_checksum; 253 int rx_hw_checksum;
@@ -302,6 +296,7 @@ static void sbmac_set_rx_mode(struct net_device *dev);
302static int sbmac_mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 296static int sbmac_mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
303static int sbmac_close(struct net_device *dev); 297static int sbmac_close(struct net_device *dev);
304static int sbmac_mii_poll(struct sbmac_softc *s,int noisy); 298static int sbmac_mii_poll(struct sbmac_softc *s,int noisy);
299static int sbmac_mii_probe(struct net_device *dev);
305 300
306static void sbmac_mii_sync(struct sbmac_softc *s); 301static void sbmac_mii_sync(struct sbmac_softc *s);
307static void sbmac_mii_senddata(struct sbmac_softc *s,unsigned int data, int bitcnt); 302static void sbmac_mii_senddata(struct sbmac_softc *s,unsigned int data, int bitcnt);
@@ -439,6 +434,9 @@ static uint64_t sbmac_orig_hwaddr[MAX_UNITS];
439 434
440#define MII_BMCR 0x00 /* Basic mode control register (rw) */ 435#define MII_BMCR 0x00 /* Basic mode control register (rw) */
441#define MII_BMSR 0x01 /* Basic mode status register (ro) */ 436#define MII_BMSR 0x01 /* Basic mode status register (ro) */
437#define MII_PHYIDR1 0x02
438#define MII_PHYIDR2 0x03
439
442#define MII_K1STSR 0x0A /* 1K Status Register (ro) */ 440#define MII_K1STSR 0x0A /* 1K Status Register (ro) */
443#define MII_ANLPAR 0x05 /* Autonegotiation lnk partner abilities (rw) */ 441#define MII_ANLPAR 0x05 /* Autonegotiation lnk partner abilities (rw) */
444 442
@@ -450,13 +448,13 @@ static uint64_t sbmac_orig_hwaddr[MAX_UNITS];
450 448
451/********************************************************************** 449/**********************************************************************
452 * SBMAC_MII_SYNC(s) 450 * SBMAC_MII_SYNC(s)
453 * 451 *
454 * Synchronize with the MII - send a pattern of bits to the MII 452 * Synchronize with the MII - send a pattern of bits to the MII
455 * that will guarantee that it is ready to accept a command. 453 * that will guarantee that it is ready to accept a command.
456 * 454 *
457 * Input parameters: 455 * Input parameters:
458 * s - sbmac structure 456 * s - sbmac structure
459 * 457 *
460 * Return value: 458 * Return value:
461 * nothing 459 * nothing
462 ********************************************************************* */ 460 ********************************************************************* */
@@ -467,25 +465,25 @@ static void sbmac_mii_sync(struct sbmac_softc *s)
467 uint64_t bits; 465 uint64_t bits;
468 int mac_mdio_genc; 466 int mac_mdio_genc;
469 467
470 mac_mdio_genc = SBMAC_READCSR(s->sbm_mdio) & M_MAC_GENC; 468 mac_mdio_genc = __raw_readq(s->sbm_mdio) & M_MAC_GENC;
471 469
472 bits = M_MAC_MDIO_DIR_OUTPUT | M_MAC_MDIO_OUT; 470 bits = M_MAC_MDIO_DIR_OUTPUT | M_MAC_MDIO_OUT;
473 471
474 SBMAC_WRITECSR(s->sbm_mdio,bits | mac_mdio_genc); 472 __raw_writeq(bits | mac_mdio_genc, s->sbm_mdio);
475 473
476 for (cnt = 0; cnt < 32; cnt++) { 474 for (cnt = 0; cnt < 32; cnt++) {
477 SBMAC_WRITECSR(s->sbm_mdio,bits | M_MAC_MDC | mac_mdio_genc); 475 __raw_writeq(bits | M_MAC_MDC | mac_mdio_genc, s->sbm_mdio);
478 SBMAC_WRITECSR(s->sbm_mdio,bits | mac_mdio_genc); 476 __raw_writeq(bits | mac_mdio_genc, s->sbm_mdio);
479 } 477 }
480} 478}
481 479
482/********************************************************************** 480/**********************************************************************
483 * SBMAC_MII_SENDDATA(s,data,bitcnt) 481 * SBMAC_MII_SENDDATA(s,data,bitcnt)
484 * 482 *
485 * Send some bits to the MII. The bits to be sent are right- 483 * Send some bits to the MII. The bits to be sent are right-
486 * justified in the 'data' parameter. 484 * justified in the 'data' parameter.
487 * 485 *
488 * Input parameters: 486 * Input parameters:
489 * s - sbmac structure 487 * s - sbmac structure
490 * data - data to send 488 * data - data to send
491 * bitcnt - number of bits to send 489 * bitcnt - number of bits to send
@@ -498,20 +496,20 @@ static void sbmac_mii_senddata(struct sbmac_softc *s,unsigned int data, int bitc
498 unsigned int curmask; 496 unsigned int curmask;
499 int mac_mdio_genc; 497 int mac_mdio_genc;
500 498
501 mac_mdio_genc = SBMAC_READCSR(s->sbm_mdio) & M_MAC_GENC; 499 mac_mdio_genc = __raw_readq(s->sbm_mdio) & M_MAC_GENC;
502 500
503 bits = M_MAC_MDIO_DIR_OUTPUT; 501 bits = M_MAC_MDIO_DIR_OUTPUT;
504 SBMAC_WRITECSR(s->sbm_mdio,bits | mac_mdio_genc); 502 __raw_writeq(bits | mac_mdio_genc, s->sbm_mdio);
505 503
506 curmask = 1 << (bitcnt - 1); 504 curmask = 1 << (bitcnt - 1);
507 505
508 for (i = 0; i < bitcnt; i++) { 506 for (i = 0; i < bitcnt; i++) {
509 if (data & curmask) 507 if (data & curmask)
510 bits |= M_MAC_MDIO_OUT; 508 bits |= M_MAC_MDIO_OUT;
511 else bits &= ~M_MAC_MDIO_OUT; 509 else bits &= ~M_MAC_MDIO_OUT;
512 SBMAC_WRITECSR(s->sbm_mdio,bits | mac_mdio_genc); 510 __raw_writeq(bits | mac_mdio_genc, s->sbm_mdio);
513 SBMAC_WRITECSR(s->sbm_mdio,bits | M_MAC_MDC | mac_mdio_genc); 511 __raw_writeq(bits | M_MAC_MDC | mac_mdio_genc, s->sbm_mdio);
514 SBMAC_WRITECSR(s->sbm_mdio,bits | mac_mdio_genc); 512 __raw_writeq(bits | mac_mdio_genc, s->sbm_mdio);
515 curmask >>= 1; 513 curmask >>= 1;
516 } 514 }
517} 515}
@@ -520,14 +518,14 @@ static void sbmac_mii_senddata(struct sbmac_softc *s,unsigned int data, int bitc
520 518
521/********************************************************************** 519/**********************************************************************
522 * SBMAC_MII_READ(s,phyaddr,regidx) 520 * SBMAC_MII_READ(s,phyaddr,regidx)
523 * 521 *
524 * Read a PHY register. 522 * Read a PHY register.
525 * 523 *
526 * Input parameters: 524 * Input parameters:
527 * s - sbmac structure 525 * s - sbmac structure
528 * phyaddr - PHY's address 526 * phyaddr - PHY's address
529 * regidx = index of register to read 527 * regidx = index of register to read
530 * 528 *
531 * Return value: 529 * Return value:
532 * value read, or 0 if an error occurred. 530 * value read, or 0 if an error occurred.
533 ********************************************************************* */ 531 ********************************************************************* */
@@ -543,9 +541,9 @@ static unsigned int sbmac_mii_read(struct sbmac_softc *s,int phyaddr,int regidx)
543 * Synchronize ourselves so that the PHY knows the next 541 * Synchronize ourselves so that the PHY knows the next
544 * thing coming down is a command 542 * thing coming down is a command
545 */ 543 */
546 544
547 sbmac_mii_sync(s); 545 sbmac_mii_sync(s);
548 546
549 /* 547 /*
550 * Send the data to the PHY. The sequence is 548 * Send the data to the PHY. The sequence is
551 * a "start" command (2 bits) 549 * a "start" command (2 bits)
@@ -553,59 +551,55 @@ static unsigned int sbmac_mii_read(struct sbmac_softc *s,int phyaddr,int regidx)
553 * the PHY addr (5 bits) 551 * the PHY addr (5 bits)
554 * the register index (5 bits) 552 * the register index (5 bits)
555 */ 553 */
556 554
557 sbmac_mii_senddata(s,MII_COMMAND_START, 2); 555 sbmac_mii_senddata(s,MII_COMMAND_START, 2);
558 sbmac_mii_senddata(s,MII_COMMAND_READ, 2); 556 sbmac_mii_senddata(s,MII_COMMAND_READ, 2);
559 sbmac_mii_senddata(s,phyaddr, 5); 557 sbmac_mii_senddata(s,phyaddr, 5);
560 sbmac_mii_senddata(s,regidx, 5); 558 sbmac_mii_senddata(s,regidx, 5);
561 559
562 mac_mdio_genc = SBMAC_READCSR(s->sbm_mdio) & M_MAC_GENC; 560 mac_mdio_genc = __raw_readq(s->sbm_mdio) & M_MAC_GENC;
563 561
564 /* 562 /*
565 * Switch the port around without a clock transition. 563 * Switch the port around without a clock transition.
566 */ 564 */
567 SBMAC_WRITECSR(s->sbm_mdio,M_MAC_MDIO_DIR_INPUT | mac_mdio_genc); 565 __raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, s->sbm_mdio);
568 566
569 /* 567 /*
570 * Send out a clock pulse to signal we want the status 568 * Send out a clock pulse to signal we want the status
571 */ 569 */
572 570
573 SBMAC_WRITECSR(s->sbm_mdio, 571 __raw_writeq(M_MAC_MDIO_DIR_INPUT | M_MAC_MDC | mac_mdio_genc, s->sbm_mdio);
574 M_MAC_MDIO_DIR_INPUT | M_MAC_MDC | mac_mdio_genc); 572 __raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, s->sbm_mdio);
575 SBMAC_WRITECSR(s->sbm_mdio,M_MAC_MDIO_DIR_INPUT | mac_mdio_genc); 573
576 574 /*
577 /*
578 * If an error occurred, the PHY will signal '1' back 575 * If an error occurred, the PHY will signal '1' back
579 */ 576 */
580 error = SBMAC_READCSR(s->sbm_mdio) & M_MAC_MDIO_IN; 577 error = __raw_readq(s->sbm_mdio) & M_MAC_MDIO_IN;
581 578
582 /* 579 /*
583 * Issue an 'idle' clock pulse, but keep the direction 580 * Issue an 'idle' clock pulse, but keep the direction
584 * the same. 581 * the same.
585 */ 582 */
586 SBMAC_WRITECSR(s->sbm_mdio, 583 __raw_writeq(M_MAC_MDIO_DIR_INPUT | M_MAC_MDC | mac_mdio_genc, s->sbm_mdio);
587 M_MAC_MDIO_DIR_INPUT | M_MAC_MDC | mac_mdio_genc); 584 __raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, s->sbm_mdio);
588 SBMAC_WRITECSR(s->sbm_mdio,M_MAC_MDIO_DIR_INPUT | mac_mdio_genc); 585
589
590 regval = 0; 586 regval = 0;
591 587
592 for (idx = 0; idx < 16; idx++) { 588 for (idx = 0; idx < 16; idx++) {
593 regval <<= 1; 589 regval <<= 1;
594 590
595 if (error == 0) { 591 if (error == 0) {
596 if (SBMAC_READCSR(s->sbm_mdio) & M_MAC_MDIO_IN) 592 if (__raw_readq(s->sbm_mdio) & M_MAC_MDIO_IN)
597 regval |= 1; 593 regval |= 1;
598 } 594 }
599 595
600 SBMAC_WRITECSR(s->sbm_mdio, 596 __raw_writeq(M_MAC_MDIO_DIR_INPUT|M_MAC_MDC | mac_mdio_genc, s->sbm_mdio);
601 M_MAC_MDIO_DIR_INPUT|M_MAC_MDC | mac_mdio_genc); 597 __raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, s->sbm_mdio);
602 SBMAC_WRITECSR(s->sbm_mdio,
603 M_MAC_MDIO_DIR_INPUT | mac_mdio_genc);
604 } 598 }
605 599
606 /* Switch back to output */ 600 /* Switch back to output */
607 SBMAC_WRITECSR(s->sbm_mdio,M_MAC_MDIO_DIR_OUTPUT | mac_mdio_genc); 601 __raw_writeq(M_MAC_MDIO_DIR_OUTPUT | mac_mdio_genc, s->sbm_mdio);
608 602
609 if (error == 0) 603 if (error == 0)
610 return regval; 604 return regval;
611 return 0; 605 return 0;
@@ -614,15 +608,15 @@ static unsigned int sbmac_mii_read(struct sbmac_softc *s,int phyaddr,int regidx)
614 608
615/********************************************************************** 609/**********************************************************************
616 * SBMAC_MII_WRITE(s,phyaddr,regidx,regval) 610 * SBMAC_MII_WRITE(s,phyaddr,regidx,regval)
617 * 611 *
618 * Write a value to a PHY register. 612 * Write a value to a PHY register.
619 * 613 *
620 * Input parameters: 614 * Input parameters:
621 * s - sbmac structure 615 * s - sbmac structure
622 * phyaddr - PHY to use 616 * phyaddr - PHY to use
623 * regidx - register within the PHY 617 * regidx - register within the PHY
624 * regval - data to write to register 618 * regval - data to write to register
625 * 619 *
626 * Return value: 620 * Return value:
627 * nothing 621 * nothing
628 ********************************************************************* */ 622 ********************************************************************* */
@@ -633,7 +627,7 @@ static void sbmac_mii_write(struct sbmac_softc *s,int phyaddr,int regidx,
633 int mac_mdio_genc; 627 int mac_mdio_genc;
634 628
635 sbmac_mii_sync(s); 629 sbmac_mii_sync(s);
636 630
637 sbmac_mii_senddata(s,MII_COMMAND_START,2); 631 sbmac_mii_senddata(s,MII_COMMAND_START,2);
638 sbmac_mii_senddata(s,MII_COMMAND_WRITE,2); 632 sbmac_mii_senddata(s,MII_COMMAND_WRITE,2);
639 sbmac_mii_senddata(s,phyaddr, 5); 633 sbmac_mii_senddata(s,phyaddr, 5);
@@ -641,27 +635,27 @@ static void sbmac_mii_write(struct sbmac_softc *s,int phyaddr,int regidx,
641 sbmac_mii_senddata(s,MII_COMMAND_ACK,2); 635 sbmac_mii_senddata(s,MII_COMMAND_ACK,2);
642 sbmac_mii_senddata(s,regval,16); 636 sbmac_mii_senddata(s,regval,16);
643 637
644 mac_mdio_genc = SBMAC_READCSR(s->sbm_mdio) & M_MAC_GENC; 638 mac_mdio_genc = __raw_readq(s->sbm_mdio) & M_MAC_GENC;
645 639
646 SBMAC_WRITECSR(s->sbm_mdio,M_MAC_MDIO_DIR_OUTPUT | mac_mdio_genc); 640 __raw_writeq(M_MAC_MDIO_DIR_OUTPUT | mac_mdio_genc, s->sbm_mdio);
647} 641}
648 642
649 643
650 644
651/********************************************************************** 645/**********************************************************************
652 * SBDMA_INITCTX(d,s,chan,txrx,maxdescr) 646 * SBDMA_INITCTX(d,s,chan,txrx,maxdescr)
653 * 647 *
654 * Initialize a DMA channel context. Since there are potentially 648 * Initialize a DMA channel context. Since there are potentially
655 * eight DMA channels per MAC, it's nice to do this in a standard 649 * eight DMA channels per MAC, it's nice to do this in a standard
656 * way. 650 * way.
657 * 651 *
658 * Input parameters: 652 * Input parameters:
659 * d - sbmacdma_t structure (DMA channel context) 653 * d - sbmacdma_t structure (DMA channel context)
660 * s - sbmac_softc structure (pointer to a MAC) 654 * s - sbmac_softc structure (pointer to a MAC)
661 * chan - channel number (0..1 right now) 655 * chan - channel number (0..1 right now)
662 * txrx - Identifies DMA_TX or DMA_RX for channel direction 656 * txrx - Identifies DMA_TX or DMA_RX for channel direction
663 * maxdescr - number of descriptors 657 * maxdescr - number of descriptors
664 * 658 *
665 * Return value: 659 * Return value:
666 * nothing 660 * nothing
667 ********************************************************************* */ 661 ********************************************************************* */
@@ -672,101 +666,87 @@ static void sbdma_initctx(sbmacdma_t *d,
672 int txrx, 666 int txrx,
673 int maxdescr) 667 int maxdescr)
674{ 668{
675 /* 669 /*
676 * Save away interesting stuff in the structure 670 * Save away interesting stuff in the structure
677 */ 671 */
678 672
679 d->sbdma_eth = s; 673 d->sbdma_eth = s;
680 d->sbdma_channel = chan; 674 d->sbdma_channel = chan;
681 d->sbdma_txdir = txrx; 675 d->sbdma_txdir = txrx;
682 676
683#if 0 677#if 0
684 /* RMON clearing */ 678 /* RMON clearing */
685 s->sbe_idx =(s->sbm_base - A_MAC_BASE_0)/MAC_SPACING; 679 s->sbe_idx =(s->sbm_base - A_MAC_BASE_0)/MAC_SPACING;
686#endif 680#endif
687 681
688 SBMAC_WRITECSR(IOADDR( 682 __raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_BYTES)));
689 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_BYTES)), 0); 683 __raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_COLLISIONS)));
690 SBMAC_WRITECSR(IOADDR( 684 __raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_LATE_COL)));
691 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_COLLISIONS)), 0); 685 __raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_EX_COL)));
692 SBMAC_WRITECSR(IOADDR( 686 __raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_FCS_ERROR)));
693 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_LATE_COL)), 0); 687 __raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_ABORT)));
694 SBMAC_WRITECSR(IOADDR( 688 __raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_BAD)));
695 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_EX_COL)), 0); 689 __raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_GOOD)));
696 SBMAC_WRITECSR(IOADDR( 690 __raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_RUNT)));
697 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_FCS_ERROR)), 0); 691 __raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_OVERSIZE)));
698 SBMAC_WRITECSR(IOADDR( 692 __raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_BYTES)));
699 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_ABORT)), 0); 693 __raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_MCAST)));
700 SBMAC_WRITECSR(IOADDR( 694 __raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_BCAST)));
701 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_BAD)), 0); 695 __raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_BAD)));
702 SBMAC_WRITECSR(IOADDR( 696 __raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_GOOD)));
703 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_GOOD)), 0); 697 __raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_RUNT)));
704 SBMAC_WRITECSR(IOADDR( 698 __raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_OVERSIZE)));
705 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_RUNT)), 0); 699 __raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_FCS_ERROR)));
706 SBMAC_WRITECSR(IOADDR( 700 __raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_LENGTH_ERROR)));
707 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_TX_OVERSIZE)), 0); 701 __raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_CODE_ERROR)));
708 SBMAC_WRITECSR(IOADDR( 702 __raw_writeq(0, IOADDR(A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_ALIGN_ERROR)));
709 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_BYTES)), 0); 703
710 SBMAC_WRITECSR(IOADDR( 704 /*
711 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_MCAST)), 0); 705 * initialize register pointers
712 SBMAC_WRITECSR(IOADDR( 706 */
713 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_BCAST)), 0); 707
714 SBMAC_WRITECSR(IOADDR( 708 d->sbdma_config0 =
715 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_BAD)), 0);
716 SBMAC_WRITECSR(IOADDR(
717 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_GOOD)), 0);
718 SBMAC_WRITECSR(IOADDR(
719 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_RUNT)), 0);
720 SBMAC_WRITECSR(IOADDR(
721 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_OVERSIZE)), 0);
722 SBMAC_WRITECSR(IOADDR(
723 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_FCS_ERROR)), 0);
724 SBMAC_WRITECSR(IOADDR(
725 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_LENGTH_ERROR)), 0);
726 SBMAC_WRITECSR(IOADDR(
727 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_CODE_ERROR)), 0);
728 SBMAC_WRITECSR(IOADDR(
729 A_MAC_REGISTER(s->sbe_idx, R_MAC_RMON_RX_ALIGN_ERROR)), 0);
730
731 /*
732 * initialize register pointers
733 */
734
735 d->sbdma_config0 =
736 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CONFIG0); 709 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CONFIG0);
737 d->sbdma_config1 = 710 d->sbdma_config1 =
738 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CONFIG1); 711 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CONFIG1);
739 d->sbdma_dscrbase = 712 d->sbdma_dscrbase =
740 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_DSCR_BASE); 713 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_DSCR_BASE);
741 d->sbdma_dscrcnt = 714 d->sbdma_dscrcnt =
742 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_DSCR_CNT); 715 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_DSCR_CNT);
743 d->sbdma_curdscr = 716 d->sbdma_curdscr =
744 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CUR_DSCRADDR); 717 s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CUR_DSCRADDR);
745 718
746 /* 719 /*
747 * Allocate memory for the ring 720 * Allocate memory for the ring
748 */ 721 */
749 722
750 d->sbdma_maxdescr = maxdescr; 723 d->sbdma_maxdescr = maxdescr;
751 724
752 d->sbdma_dscrtable = (sbdmadscr_t *) 725 d->sbdma_dscrtable = (sbdmadscr_t *)
753 kmalloc(d->sbdma_maxdescr*sizeof(sbdmadscr_t), GFP_KERNEL); 726 kmalloc((d->sbdma_maxdescr+1)*sizeof(sbdmadscr_t), GFP_KERNEL);
754 727
728 /*
729 * The descriptor table must be aligned to at least 16 bytes or the
730 * MAC will corrupt it.
731 */
732 d->sbdma_dscrtable = (sbdmadscr_t *)
733 ALIGN((unsigned long)d->sbdma_dscrtable, sizeof(sbdmadscr_t));
734
755 memset(d->sbdma_dscrtable,0,d->sbdma_maxdescr*sizeof(sbdmadscr_t)); 735 memset(d->sbdma_dscrtable,0,d->sbdma_maxdescr*sizeof(sbdmadscr_t));
756 736
757 d->sbdma_dscrtable_end = d->sbdma_dscrtable + d->sbdma_maxdescr; 737 d->sbdma_dscrtable_end = d->sbdma_dscrtable + d->sbdma_maxdescr;
758 738
759 d->sbdma_dscrtable_phys = virt_to_phys(d->sbdma_dscrtable); 739 d->sbdma_dscrtable_phys = virt_to_phys(d->sbdma_dscrtable);
760 740
761 /* 741 /*
762 * And context table 742 * And context table
763 */ 743 */
764 744
765 d->sbdma_ctxtable = (struct sk_buff **) 745 d->sbdma_ctxtable = (struct sk_buff **)
766 kmalloc(d->sbdma_maxdescr*sizeof(struct sk_buff *), GFP_KERNEL); 746 kmalloc(d->sbdma_maxdescr*sizeof(struct sk_buff *), GFP_KERNEL);
767 747
768 memset(d->sbdma_ctxtable,0,d->sbdma_maxdescr*sizeof(struct sk_buff *)); 748 memset(d->sbdma_ctxtable,0,d->sbdma_maxdescr*sizeof(struct sk_buff *));
769 749
770#ifdef CONFIG_SBMAC_COALESCE 750#ifdef CONFIG_SBMAC_COALESCE
771 /* 751 /*
772 * Setup Rx/Tx DMA coalescing defaults 752 * Setup Rx/Tx DMA coalescing defaults
@@ -777,7 +757,7 @@ static void sbdma_initctx(sbmacdma_t *d,
777 } else { 757 } else {
778 d->sbdma_int_pktcnt = 1; 758 d->sbdma_int_pktcnt = 1;
779 } 759 }
780 760
781 if ( int_timeout ) { 761 if ( int_timeout ) {
782 d->sbdma_int_timeout = int_timeout; 762 d->sbdma_int_timeout = int_timeout;
783 } else { 763 } else {
@@ -789,13 +769,13 @@ static void sbdma_initctx(sbmacdma_t *d,
789 769
790/********************************************************************** 770/**********************************************************************
791 * SBDMA_CHANNEL_START(d) 771 * SBDMA_CHANNEL_START(d)
792 * 772 *
793 * Initialize the hardware registers for a DMA channel. 773 * Initialize the hardware registers for a DMA channel.
794 * 774 *
795 * Input parameters: 775 * Input parameters:
796 * d - DMA channel to init (context must be previously init'd 776 * d - DMA channel to init (context must be previously init'd
797 * rxtx - DMA_RX or DMA_TX depending on what type of channel 777 * rxtx - DMA_RX or DMA_TX depending on what type of channel
798 * 778 *
799 * Return value: 779 * Return value:
800 * nothing 780 * nothing
801 ********************************************************************* */ 781 ********************************************************************* */
@@ -805,24 +785,21 @@ static void sbdma_channel_start(sbmacdma_t *d, int rxtx )
805 /* 785 /*
806 * Turn on the DMA channel 786 * Turn on the DMA channel
807 */ 787 */
808 788
809#ifdef CONFIG_SBMAC_COALESCE 789#ifdef CONFIG_SBMAC_COALESCE
810 SBMAC_WRITECSR(d->sbdma_config1, 790 __raw_writeq(V_DMA_INT_TIMEOUT(d->sbdma_int_timeout) |
811 V_DMA_INT_TIMEOUT(d->sbdma_int_timeout) | 791 0, d->sbdma_config1);
812 0); 792 __raw_writeq(M_DMA_EOP_INT_EN |
813 SBMAC_WRITECSR(d->sbdma_config0,
814 M_DMA_EOP_INT_EN |
815 V_DMA_RINGSZ(d->sbdma_maxdescr) | 793 V_DMA_RINGSZ(d->sbdma_maxdescr) |
816 V_DMA_INT_PKTCNT(d->sbdma_int_pktcnt) | 794 V_DMA_INT_PKTCNT(d->sbdma_int_pktcnt) |
817 0); 795 0, d->sbdma_config0);
818#else 796#else
819 SBMAC_WRITECSR(d->sbdma_config1,0); 797 __raw_writeq(0, d->sbdma_config1);
820 SBMAC_WRITECSR(d->sbdma_config0, 798 __raw_writeq(V_DMA_RINGSZ(d->sbdma_maxdescr) |
821 V_DMA_RINGSZ(d->sbdma_maxdescr) | 799 0, d->sbdma_config0);
822 0);
823#endif 800#endif
824 801
825 SBMAC_WRITECSR(d->sbdma_dscrbase,d->sbdma_dscrtable_phys); 802 __raw_writeq(d->sbdma_dscrtable_phys, d->sbdma_dscrbase);
826 803
827 /* 804 /*
828 * Initialize ring pointers 805 * Initialize ring pointers
@@ -834,12 +811,12 @@ static void sbdma_channel_start(sbmacdma_t *d, int rxtx )
834 811
835/********************************************************************** 812/**********************************************************************
836 * SBDMA_CHANNEL_STOP(d) 813 * SBDMA_CHANNEL_STOP(d)
837 * 814 *
838 * Initialize the hardware registers for a DMA channel. 815 * Initialize the hardware registers for a DMA channel.
839 * 816 *
840 * Input parameters: 817 * Input parameters:
841 * d - DMA channel to init (context must be previously init'd 818 * d - DMA channel to init (context must be previously init'd
842 * 819 *
843 * Return value: 820 * Return value:
844 * nothing 821 * nothing
845 ********************************************************************* */ 822 ********************************************************************* */
@@ -849,44 +826,44 @@ static void sbdma_channel_stop(sbmacdma_t *d)
849 /* 826 /*
850 * Turn off the DMA channel 827 * Turn off the DMA channel
851 */ 828 */
852 829
853 SBMAC_WRITECSR(d->sbdma_config1,0); 830 __raw_writeq(0, d->sbdma_config1);
854 831
855 SBMAC_WRITECSR(d->sbdma_dscrbase,0); 832 __raw_writeq(0, d->sbdma_dscrbase);
856 833
857 SBMAC_WRITECSR(d->sbdma_config0,0); 834 __raw_writeq(0, d->sbdma_config0);
858 835
859 /* 836 /*
860 * Zero ring pointers 837 * Zero ring pointers
861 */ 838 */
862 839
863 d->sbdma_addptr = 0; 840 d->sbdma_addptr = NULL;
864 d->sbdma_remptr = 0; 841 d->sbdma_remptr = NULL;
865} 842}
866 843
867static void sbdma_align_skb(struct sk_buff *skb,int power2,int offset) 844static void sbdma_align_skb(struct sk_buff *skb,int power2,int offset)
868{ 845{
869 unsigned long addr; 846 unsigned long addr;
870 unsigned long newaddr; 847 unsigned long newaddr;
871 848
872 addr = (unsigned long) skb->data; 849 addr = (unsigned long) skb->data;
873 850
874 newaddr = (addr + power2 - 1) & ~(power2 - 1); 851 newaddr = (addr + power2 - 1) & ~(power2 - 1);
875 852
876 skb_reserve(skb,newaddr-addr+offset); 853 skb_reserve(skb,newaddr-addr+offset);
877} 854}
878 855
879 856
880/********************************************************************** 857/**********************************************************************
881 * SBDMA_ADD_RCVBUFFER(d,sb) 858 * SBDMA_ADD_RCVBUFFER(d,sb)
882 * 859 *
883 * Add a buffer to the specified DMA channel. For receive channels, 860 * Add a buffer to the specified DMA channel. For receive channels,
884 * this queues a buffer for inbound packets. 861 * this queues a buffer for inbound packets.
885 * 862 *
886 * Input parameters: 863 * Input parameters:
887 * d - DMA channel descriptor 864 * d - DMA channel descriptor
888 * sb - sk_buff to add, or NULL if we should allocate one 865 * sb - sk_buff to add, or NULL if we should allocate one
889 * 866 *
890 * Return value: 867 * Return value:
891 * 0 if buffer could not be added (ring is full) 868 * 0 if buffer could not be added (ring is full)
892 * 1 if buffer added successfully 869 * 1 if buffer added successfully
@@ -899,24 +876,24 @@ static int sbdma_add_rcvbuffer(sbmacdma_t *d,struct sk_buff *sb)
899 sbdmadscr_t *nextdsc; 876 sbdmadscr_t *nextdsc;
900 struct sk_buff *sb_new = NULL; 877 struct sk_buff *sb_new = NULL;
901 int pktsize = ENET_PACKET_SIZE; 878 int pktsize = ENET_PACKET_SIZE;
902 879
903 /* get pointer to our current place in the ring */ 880 /* get pointer to our current place in the ring */
904 881
905 dsc = d->sbdma_addptr; 882 dsc = d->sbdma_addptr;
906 nextdsc = SBDMA_NEXTBUF(d,sbdma_addptr); 883 nextdsc = SBDMA_NEXTBUF(d,sbdma_addptr);
907 884
908 /* 885 /*
909 * figure out if the ring is full - if the next descriptor 886 * figure out if the ring is full - if the next descriptor
910 * is the same as the one that we're going to remove from 887 * is the same as the one that we're going to remove from
911 * the ring, the ring is full 888 * the ring, the ring is full
912 */ 889 */
913 890
914 if (nextdsc == d->sbdma_remptr) { 891 if (nextdsc == d->sbdma_remptr) {
915 return -ENOSPC; 892 return -ENOSPC;
916 } 893 }
917 894
918 /* 895 /*
919 * Allocate a sk_buff if we don't already have one. 896 * Allocate a sk_buff if we don't already have one.
920 * If we do have an sk_buff, reset it so that it's empty. 897 * If we do have an sk_buff, reset it so that it's empty.
921 * 898 *
922 * Note: sk_buffs don't seem to be guaranteed to have any sort 899 * Note: sk_buffs don't seem to be guaranteed to have any sort
@@ -925,7 +902,7 @@ static int sbdma_add_rcvbuffer(sbmacdma_t *d,struct sk_buff *sb)
925 * 902 *
926 * 1. the data does not start in the middle of a cache line. 903 * 1. the data does not start in the middle of a cache line.
927 * 2. The data does not end in the middle of a cache line 904 * 2. The data does not end in the middle of a cache line
928 * 3. The buffer can be aligned such that the IP addresses are 905 * 3. The buffer can be aligned such that the IP addresses are
929 * naturally aligned. 906 * naturally aligned.
930 * 907 *
931 * Remember, the SOCs MAC writes whole cache lines at a time, 908 * Remember, the SOCs MAC writes whole cache lines at a time,
@@ -933,7 +910,7 @@ static int sbdma_add_rcvbuffer(sbmacdma_t *d,struct sk_buff *sb)
933 * data portion starts in the middle of a cache line, the SOC 910 * data portion starts in the middle of a cache line, the SOC
934 * DMA will trash the beginning (and ending) portions. 911 * DMA will trash the beginning (and ending) portions.
935 */ 912 */
936 913
937 if (sb == NULL) { 914 if (sb == NULL) {
938 sb_new = dev_alloc_skb(ENET_PACKET_SIZE + SMP_CACHE_BYTES * 2 + ETHER_ALIGN); 915 sb_new = dev_alloc_skb(ENET_PACKET_SIZE + SMP_CACHE_BYTES * 2 + ETHER_ALIGN);
939 if (sb_new == NULL) { 916 if (sb_new == NULL) {
@@ -949,23 +926,22 @@ static int sbdma_add_rcvbuffer(sbmacdma_t *d,struct sk_buff *sb)
949 } 926 }
950 else { 927 else {
951 sb_new = sb; 928 sb_new = sb;
952 /* 929 /*
953 * nothing special to reinit buffer, it's already aligned 930 * nothing special to reinit buffer, it's already aligned
954 * and sb->data already points to a good place. 931 * and sb->data already points to a good place.
955 */ 932 */
956 } 933 }
957 934
958 /* 935 /*
959 * fill in the descriptor 936 * fill in the descriptor
960 */ 937 */
961 938
962#ifdef CONFIG_SBMAC_COALESCE 939#ifdef CONFIG_SBMAC_COALESCE
963 /* 940 /*
964 * Do not interrupt per DMA transfer. 941 * Do not interrupt per DMA transfer.
965 */ 942 */
966 dsc->dscr_a = virt_to_phys(sb_new->data) | 943 dsc->dscr_a = virt_to_phys(sb_new->data) |
967 V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize+ETHER_ALIGN)) | 944 V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize+ETHER_ALIGN)) | 0;
968 0;
969#else 945#else
970 dsc->dscr_a = virt_to_phys(sb_new->data) | 946 dsc->dscr_a = virt_to_phys(sb_new->data) |
971 V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize+ETHER_ALIGN)) | 947 V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize+ETHER_ALIGN)) |
@@ -974,38 +950,38 @@ static int sbdma_add_rcvbuffer(sbmacdma_t *d,struct sk_buff *sb)
974 950
975 /* receiving: no options */ 951 /* receiving: no options */
976 dsc->dscr_b = 0; 952 dsc->dscr_b = 0;
977 953
978 /* 954 /*
979 * fill in the context 955 * fill in the context
980 */ 956 */
981 957
982 d->sbdma_ctxtable[dsc-d->sbdma_dscrtable] = sb_new; 958 d->sbdma_ctxtable[dsc-d->sbdma_dscrtable] = sb_new;
983 959
984 /* 960 /*
985 * point at next packet 961 * point at next packet
986 */ 962 */
987 963
988 d->sbdma_addptr = nextdsc; 964 d->sbdma_addptr = nextdsc;
989 965
990 /* 966 /*
991 * Give the buffer to the DMA engine. 967 * Give the buffer to the DMA engine.
992 */ 968 */
993 969
994 SBMAC_WRITECSR(d->sbdma_dscrcnt,1); 970 __raw_writeq(1, d->sbdma_dscrcnt);
995 971
996 return 0; /* we did it */ 972 return 0; /* we did it */
997} 973}
998 974
999/********************************************************************** 975/**********************************************************************
1000 * SBDMA_ADD_TXBUFFER(d,sb) 976 * SBDMA_ADD_TXBUFFER(d,sb)
1001 * 977 *
1002 * Add a transmit buffer to the specified DMA channel, causing a 978 * Add a transmit buffer to the specified DMA channel, causing a
1003 * transmit to start. 979 * transmit to start.
1004 * 980 *
1005 * Input parameters: 981 * Input parameters:
1006 * d - DMA channel descriptor 982 * d - DMA channel descriptor
1007 * sb - sk_buff to add 983 * sb - sk_buff to add
1008 * 984 *
1009 * Return value: 985 * Return value:
1010 * 0 transmit queued successfully 986 * 0 transmit queued successfully
1011 * otherwise error code 987 * otherwise error code
@@ -1019,70 +995,70 @@ static int sbdma_add_txbuffer(sbmacdma_t *d,struct sk_buff *sb)
1019 uint64_t phys; 995 uint64_t phys;
1020 uint64_t ncb; 996 uint64_t ncb;
1021 int length; 997 int length;
1022 998
1023 /* get pointer to our current place in the ring */ 999 /* get pointer to our current place in the ring */
1024 1000
1025 dsc = d->sbdma_addptr; 1001 dsc = d->sbdma_addptr;
1026 nextdsc = SBDMA_NEXTBUF(d,sbdma_addptr); 1002 nextdsc = SBDMA_NEXTBUF(d,sbdma_addptr);
1027 1003
1028 /* 1004 /*
1029 * figure out if the ring is full - if the next descriptor 1005 * figure out if the ring is full - if the next descriptor
1030 * is the same as the one that we're going to remove from 1006 * is the same as the one that we're going to remove from
1031 * the ring, the ring is full 1007 * the ring, the ring is full
1032 */ 1008 */
1033 1009
1034 if (nextdsc == d->sbdma_remptr) { 1010 if (nextdsc == d->sbdma_remptr) {
1035 return -ENOSPC; 1011 return -ENOSPC;
1036 } 1012 }
1037 1013
1038 /* 1014 /*
1039 * Under Linux, it's not necessary to copy/coalesce buffers 1015 * Under Linux, it's not necessary to copy/coalesce buffers
1040 * like it is on NetBSD. We think they're all contiguous, 1016 * like it is on NetBSD. We think they're all contiguous,
1041 * but that may not be true for GBE. 1017 * but that may not be true for GBE.
1042 */ 1018 */
1043 1019
1044 length = sb->len; 1020 length = sb->len;
1045 1021
1046 /* 1022 /*
1047 * fill in the descriptor. Note that the number of cache 1023 * fill in the descriptor. Note that the number of cache
1048 * blocks in the descriptor is the number of blocks 1024 * blocks in the descriptor is the number of blocks
1049 * *spanned*, so we need to add in the offset (if any) 1025 * *spanned*, so we need to add in the offset (if any)
1050 * while doing the calculation. 1026 * while doing the calculation.
1051 */ 1027 */
1052 1028
1053 phys = virt_to_phys(sb->data); 1029 phys = virt_to_phys(sb->data);
1054 ncb = NUMCACHEBLKS(length+(phys & (SMP_CACHE_BYTES - 1))); 1030 ncb = NUMCACHEBLKS(length+(phys & (SMP_CACHE_BYTES - 1)));
1055 1031
1056 dsc->dscr_a = phys | 1032 dsc->dscr_a = phys |
1057 V_DMA_DSCRA_A_SIZE(ncb) | 1033 V_DMA_DSCRA_A_SIZE(ncb) |
1058#ifndef CONFIG_SBMAC_COALESCE 1034#ifndef CONFIG_SBMAC_COALESCE
1059 M_DMA_DSCRA_INTERRUPT | 1035 M_DMA_DSCRA_INTERRUPT |
1060#endif 1036#endif
1061 M_DMA_ETHTX_SOP; 1037 M_DMA_ETHTX_SOP;
1062 1038
1063 /* transmitting: set outbound options and length */ 1039 /* transmitting: set outbound options and length */
1064 1040
1065 dsc->dscr_b = V_DMA_DSCRB_OPTIONS(K_DMA_ETHTX_APPENDCRC_APPENDPAD) | 1041 dsc->dscr_b = V_DMA_DSCRB_OPTIONS(K_DMA_ETHTX_APPENDCRC_APPENDPAD) |
1066 V_DMA_DSCRB_PKT_SIZE(length); 1042 V_DMA_DSCRB_PKT_SIZE(length);
1067 1043
1068 /* 1044 /*
1069 * fill in the context 1045 * fill in the context
1070 */ 1046 */
1071 1047
1072 d->sbdma_ctxtable[dsc-d->sbdma_dscrtable] = sb; 1048 d->sbdma_ctxtable[dsc-d->sbdma_dscrtable] = sb;
1073 1049
1074 /* 1050 /*
1075 * point at next packet 1051 * point at next packet
1076 */ 1052 */
1077 1053
1078 d->sbdma_addptr = nextdsc; 1054 d->sbdma_addptr = nextdsc;
1079 1055
1080 /* 1056 /*
1081 * Give the buffer to the DMA engine. 1057 * Give the buffer to the DMA engine.
1082 */ 1058 */
1083 1059
1084 SBMAC_WRITECSR(d->sbdma_dscrcnt,1); 1060 __raw_writeq(1, d->sbdma_dscrcnt);
1085 1061
1086 return 0; /* we did it */ 1062 return 0; /* we did it */
1087} 1063}
1088 1064
@@ -1091,12 +1067,12 @@ static int sbdma_add_txbuffer(sbmacdma_t *d,struct sk_buff *sb)
1091 1067
1092/********************************************************************** 1068/**********************************************************************
1093 * SBDMA_EMPTYRING(d) 1069 * SBDMA_EMPTYRING(d)
1094 * 1070 *
1095 * Free all allocated sk_buffs on the specified DMA channel; 1071 * Free all allocated sk_buffs on the specified DMA channel;
1096 * 1072 *
1097 * Input parameters: 1073 * Input parameters:
1098 * d - DMA channel 1074 * d - DMA channel
1099 * 1075 *
1100 * Return value: 1076 * Return value:
1101 * nothing 1077 * nothing
1102 ********************************************************************* */ 1078 ********************************************************************* */
@@ -1105,7 +1081,7 @@ static void sbdma_emptyring(sbmacdma_t *d)
1105{ 1081{
1106 int idx; 1082 int idx;
1107 struct sk_buff *sb; 1083 struct sk_buff *sb;
1108 1084
1109 for (idx = 0; idx < d->sbdma_maxdescr; idx++) { 1085 for (idx = 0; idx < d->sbdma_maxdescr; idx++) {
1110 sb = d->sbdma_ctxtable[idx]; 1086 sb = d->sbdma_ctxtable[idx];
1111 if (sb) { 1087 if (sb) {
@@ -1118,13 +1094,13 @@ static void sbdma_emptyring(sbmacdma_t *d)
1118 1094
1119/********************************************************************** 1095/**********************************************************************
1120 * SBDMA_FILLRING(d) 1096 * SBDMA_FILLRING(d)
1121 * 1097 *
1122 * Fill the specified DMA channel (must be receive channel) 1098 * Fill the specified DMA channel (must be receive channel)
1123 * with sk_buffs 1099 * with sk_buffs
1124 * 1100 *
1125 * Input parameters: 1101 * Input parameters:
1126 * d - DMA channel 1102 * d - DMA channel
1127 * 1103 *
1128 * Return value: 1104 * Return value:
1129 * nothing 1105 * nothing
1130 ********************************************************************* */ 1106 ********************************************************************* */
@@ -1132,7 +1108,7 @@ static void sbdma_emptyring(sbmacdma_t *d)
1132static void sbdma_fillring(sbmacdma_t *d) 1108static void sbdma_fillring(sbmacdma_t *d)
1133{ 1109{
1134 int idx; 1110 int idx;
1135 1111
1136 for (idx = 0; idx < SBMAC_MAX_RXDESCR-1; idx++) { 1112 for (idx = 0; idx < SBMAC_MAX_RXDESCR-1; idx++) {
1137 if (sbdma_add_rcvbuffer(d,NULL) != 0) 1113 if (sbdma_add_rcvbuffer(d,NULL) != 0)
1138 break; 1114 break;
@@ -1142,16 +1118,16 @@ static void sbdma_fillring(sbmacdma_t *d)
1142 1118
1143/********************************************************************** 1119/**********************************************************************
1144 * SBDMA_RX_PROCESS(sc,d) 1120 * SBDMA_RX_PROCESS(sc,d)
1145 * 1121 *
1146 * Process "completed" receive buffers on the specified DMA channel. 1122 * Process "completed" receive buffers on the specified DMA channel.
1147 * Note that this isn't really ideal for priority channels, since 1123 * Note that this isn't really ideal for priority channels, since
1148 * it processes all of the packets on a given channel before 1124 * it processes all of the packets on a given channel before
1149 * returning. 1125 * returning.
1150 * 1126 *
1151 * Input parameters: 1127 * Input parameters:
1152 * sc - softc structure 1128 * sc - softc structure
1153 * d - DMA channel context 1129 * d - DMA channel context
1154 * 1130 *
1155 * Return value: 1131 * Return value:
1156 * nothing 1132 * nothing
1157 ********************************************************************* */ 1133 ********************************************************************* */
@@ -1163,56 +1139,56 @@ static void sbdma_rx_process(struct sbmac_softc *sc,sbmacdma_t *d)
1163 sbdmadscr_t *dsc; 1139 sbdmadscr_t *dsc;
1164 struct sk_buff *sb; 1140 struct sk_buff *sb;
1165 int len; 1141 int len;
1166 1142
1167 for (;;) { 1143 for (;;) {
1168 /* 1144 /*
1169 * figure out where we are (as an index) and where 1145 * figure out where we are (as an index) and where
1170 * the hardware is (also as an index) 1146 * the hardware is (also as an index)
1171 * 1147 *
1172 * This could be done faster if (for example) the 1148 * This could be done faster if (for example) the
1173 * descriptor table was page-aligned and contiguous in 1149 * descriptor table was page-aligned and contiguous in
1174 * both virtual and physical memory -- you could then 1150 * both virtual and physical memory -- you could then
1175 * just compare the low-order bits of the virtual address 1151 * just compare the low-order bits of the virtual address
1176 * (sbdma_remptr) and the physical address (sbdma_curdscr CSR) 1152 * (sbdma_remptr) and the physical address (sbdma_curdscr CSR)
1177 */ 1153 */
1178 1154
1179 curidx = d->sbdma_remptr - d->sbdma_dscrtable; 1155 curidx = d->sbdma_remptr - d->sbdma_dscrtable;
1180 hwidx = (int) (((SBMAC_READCSR(d->sbdma_curdscr) & M_DMA_CURDSCR_ADDR) - 1156 hwidx = (int) (((__raw_readq(d->sbdma_curdscr) & M_DMA_CURDSCR_ADDR) -
1181 d->sbdma_dscrtable_phys) / sizeof(sbdmadscr_t)); 1157 d->sbdma_dscrtable_phys) / sizeof(sbdmadscr_t));
1182 1158
1183 /* 1159 /*
1184 * If they're the same, that means we've processed all 1160 * If they're the same, that means we've processed all
1185 * of the descriptors up to (but not including) the one that 1161 * of the descriptors up to (but not including) the one that
1186 * the hardware is working on right now. 1162 * the hardware is working on right now.
1187 */ 1163 */
1188 1164
1189 if (curidx == hwidx) 1165 if (curidx == hwidx)
1190 break; 1166 break;
1191 1167
1192 /* 1168 /*
1193 * Otherwise, get the packet's sk_buff ptr back 1169 * Otherwise, get the packet's sk_buff ptr back
1194 */ 1170 */
1195 1171
1196 dsc = &(d->sbdma_dscrtable[curidx]); 1172 dsc = &(d->sbdma_dscrtable[curidx]);
1197 sb = d->sbdma_ctxtable[curidx]; 1173 sb = d->sbdma_ctxtable[curidx];
1198 d->sbdma_ctxtable[curidx] = NULL; 1174 d->sbdma_ctxtable[curidx] = NULL;
1199 1175
1200 len = (int)G_DMA_DSCRB_PKT_SIZE(dsc->dscr_b) - 4; 1176 len = (int)G_DMA_DSCRB_PKT_SIZE(dsc->dscr_b) - 4;
1201 1177
1202 /* 1178 /*
1203 * Check packet status. If good, process it. 1179 * Check packet status. If good, process it.
1204 * If not, silently drop it and put it back on the 1180 * If not, silently drop it and put it back on the
1205 * receive ring. 1181 * receive ring.
1206 */ 1182 */
1207 1183
1208 if (!(dsc->dscr_a & M_DMA_ETHRX_BAD)) { 1184 if (!(dsc->dscr_a & M_DMA_ETHRX_BAD)) {
1209 1185
1210 /* 1186 /*
1211 * Add a new buffer to replace the old one. If we fail 1187 * Add a new buffer to replace the old one. If we fail
1212 * to allocate a buffer, we're going to drop this 1188 * to allocate a buffer, we're going to drop this
1213 * packet and put it right back on the receive ring. 1189 * packet and put it right back on the receive ring.
1214 */ 1190 */
1215 1191
1216 if (sbdma_add_rcvbuffer(d,NULL) == -ENOBUFS) { 1192 if (sbdma_add_rcvbuffer(d,NULL) == -ENOBUFS) {
1217 sc->sbm_stats.rx_dropped++; 1193 sc->sbm_stats.rx_dropped++;
1218 sbdma_add_rcvbuffer(d,sb); /* re-add old buffer */ 1194 sbdma_add_rcvbuffer(d,sb); /* re-add old buffer */
@@ -1221,7 +1197,7 @@ static void sbdma_rx_process(struct sbmac_softc *sc,sbmacdma_t *d)
1221 * Set length into the packet 1197 * Set length into the packet
1222 */ 1198 */
1223 skb_put(sb,len); 1199 skb_put(sb,len);
1224 1200
1225 /* 1201 /*
1226 * Buffer has been replaced on the 1202 * Buffer has been replaced on the
1227 * receive ring. Pass the buffer to 1203 * receive ring. Pass the buffer to
@@ -1240,7 +1216,7 @@ static void sbdma_rx_process(struct sbmac_softc *sc,sbmacdma_t *d)
1240 sb->ip_summed = CHECKSUM_NONE; 1216 sb->ip_summed = CHECKSUM_NONE;
1241 } 1217 }
1242 } 1218 }
1243 1219
1244 netif_rx(sb); 1220 netif_rx(sb);
1245 } 1221 }
1246 } else { 1222 } else {
@@ -1251,14 +1227,14 @@ static void sbdma_rx_process(struct sbmac_softc *sc,sbmacdma_t *d)
1251 sc->sbm_stats.rx_errors++; 1227 sc->sbm_stats.rx_errors++;
1252 sbdma_add_rcvbuffer(d,sb); 1228 sbdma_add_rcvbuffer(d,sb);
1253 } 1229 }
1254 1230
1255 1231
1256 /* 1232 /*
1257 * .. and advance to the next buffer. 1233 * .. and advance to the next buffer.
1258 */ 1234 */
1259 1235
1260 d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr); 1236 d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr);
1261 1237
1262 } 1238 }
1263} 1239}
1264 1240
@@ -1266,17 +1242,17 @@ static void sbdma_rx_process(struct sbmac_softc *sc,sbmacdma_t *d)
1266 1242
1267/********************************************************************** 1243/**********************************************************************
1268 * SBDMA_TX_PROCESS(sc,d) 1244 * SBDMA_TX_PROCESS(sc,d)
1269 * 1245 *
1270 * Process "completed" transmit buffers on the specified DMA channel. 1246 * Process "completed" transmit buffers on the specified DMA channel.
1271 * This is normally called within the interrupt service routine. 1247 * This is normally called within the interrupt service routine.
1272 * Note that this isn't really ideal for priority channels, since 1248 * Note that this isn't really ideal for priority channels, since
1273 * it processes all of the packets on a given channel before 1249 * it processes all of the packets on a given channel before
1274 * returning. 1250 * returning.
1275 * 1251 *
1276 * Input parameters: 1252 * Input parameters:
1277 * sc - softc structure 1253 * sc - softc structure
1278 * d - DMA channel context 1254 * d - DMA channel context
1279 * 1255 *
1280 * Return value: 1256 * Return value:
1281 * nothing 1257 * nothing
1282 ********************************************************************* */ 1258 ********************************************************************* */
@@ -1290,21 +1266,21 @@ static void sbdma_tx_process(struct sbmac_softc *sc,sbmacdma_t *d)
1290 unsigned long flags; 1266 unsigned long flags;
1291 1267
1292 spin_lock_irqsave(&(sc->sbm_lock), flags); 1268 spin_lock_irqsave(&(sc->sbm_lock), flags);
1293 1269
1294 for (;;) { 1270 for (;;) {
1295 /* 1271 /*
1296 * figure out where we are (as an index) and where 1272 * figure out where we are (as an index) and where
1297 * the hardware is (also as an index) 1273 * the hardware is (also as an index)
1298 * 1274 *
1299 * This could be done faster if (for example) the 1275 * This could be done faster if (for example) the
1300 * descriptor table was page-aligned and contiguous in 1276 * descriptor table was page-aligned and contiguous in
1301 * both virtual and physical memory -- you could then 1277 * both virtual and physical memory -- you could then
1302 * just compare the low-order bits of the virtual address 1278 * just compare the low-order bits of the virtual address
1303 * (sbdma_remptr) and the physical address (sbdma_curdscr CSR) 1279 * (sbdma_remptr) and the physical address (sbdma_curdscr CSR)
1304 */ 1280 */
1305 1281
1306 curidx = d->sbdma_remptr - d->sbdma_dscrtable; 1282 curidx = d->sbdma_remptr - d->sbdma_dscrtable;
1307 hwidx = (int) (((SBMAC_READCSR(d->sbdma_curdscr) & M_DMA_CURDSCR_ADDR) - 1283 hwidx = (int) (((__raw_readq(d->sbdma_curdscr) & M_DMA_CURDSCR_ADDR) -
1308 d->sbdma_dscrtable_phys) / sizeof(sbdmadscr_t)); 1284 d->sbdma_dscrtable_phys) / sizeof(sbdmadscr_t));
1309 1285
1310 /* 1286 /*
@@ -1312,75 +1288,75 @@ static void sbdma_tx_process(struct sbmac_softc *sc,sbmacdma_t *d)
1312 * of the descriptors up to (but not including) the one that 1288 * of the descriptors up to (but not including) the one that
1313 * the hardware is working on right now. 1289 * the hardware is working on right now.
1314 */ 1290 */
1315 1291
1316 if (curidx == hwidx) 1292 if (curidx == hwidx)
1317 break; 1293 break;
1318 1294
1319 /* 1295 /*
1320 * Otherwise, get the packet's sk_buff ptr back 1296 * Otherwise, get the packet's sk_buff ptr back
1321 */ 1297 */
1322 1298
1323 dsc = &(d->sbdma_dscrtable[curidx]); 1299 dsc = &(d->sbdma_dscrtable[curidx]);
1324 sb = d->sbdma_ctxtable[curidx]; 1300 sb = d->sbdma_ctxtable[curidx];
1325 d->sbdma_ctxtable[curidx] = NULL; 1301 d->sbdma_ctxtable[curidx] = NULL;
1326 1302
1327 /* 1303 /*
1328 * Stats 1304 * Stats
1329 */ 1305 */
1330 1306
1331 sc->sbm_stats.tx_bytes += sb->len; 1307 sc->sbm_stats.tx_bytes += sb->len;
1332 sc->sbm_stats.tx_packets++; 1308 sc->sbm_stats.tx_packets++;
1333 1309
1334 /* 1310 /*
1335 * for transmits, we just free buffers. 1311 * for transmits, we just free buffers.
1336 */ 1312 */
1337 1313
1338 dev_kfree_skb_irq(sb); 1314 dev_kfree_skb_irq(sb);
1339 1315
1340 /* 1316 /*
1341 * .. and advance to the next buffer. 1317 * .. and advance to the next buffer.
1342 */ 1318 */
1343 1319
1344 d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr); 1320 d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr);
1345 1321
1346 } 1322 }
1347 1323
1348 /* 1324 /*
1349 * Decide if we should wake up the protocol or not. 1325 * Decide if we should wake up the protocol or not.
1350 * Other drivers seem to do this when we reach a low 1326 * Other drivers seem to do this when we reach a low
1351 * watermark on the transmit queue. 1327 * watermark on the transmit queue.
1352 */ 1328 */
1353 1329
1354 netif_wake_queue(d->sbdma_eth->sbm_dev); 1330 netif_wake_queue(d->sbdma_eth->sbm_dev);
1355 1331
1356 spin_unlock_irqrestore(&(sc->sbm_lock), flags); 1332 spin_unlock_irqrestore(&(sc->sbm_lock), flags);
1357 1333
1358} 1334}
1359 1335
1360 1336
1361 1337
1362/********************************************************************** 1338/**********************************************************************
1363 * SBMAC_INITCTX(s) 1339 * SBMAC_INITCTX(s)
1364 * 1340 *
1365 * Initialize an Ethernet context structure - this is called 1341 * Initialize an Ethernet context structure - this is called
1366 * once per MAC on the 1250. Memory is allocated here, so don't 1342 * once per MAC on the 1250. Memory is allocated here, so don't
1367 * call it again from inside the ioctl routines that bring the 1343 * call it again from inside the ioctl routines that bring the
1368 * interface up/down 1344 * interface up/down
1369 * 1345 *
1370 * Input parameters: 1346 * Input parameters:
1371 * s - sbmac context structure 1347 * s - sbmac context structure
1372 * 1348 *
1373 * Return value: 1349 * Return value:
1374 * 0 1350 * 0
1375 ********************************************************************* */ 1351 ********************************************************************* */
1376 1352
1377static int sbmac_initctx(struct sbmac_softc *s) 1353static int sbmac_initctx(struct sbmac_softc *s)
1378{ 1354{
1379 1355
1380 /* 1356 /*
1381 * figure out the addresses of some ports 1357 * figure out the addresses of some ports
1382 */ 1358 */
1383 1359
1384 s->sbm_macenable = s->sbm_base + R_MAC_ENABLE; 1360 s->sbm_macenable = s->sbm_base + R_MAC_ENABLE;
1385 s->sbm_maccfg = s->sbm_base + R_MAC_CFG; 1361 s->sbm_maccfg = s->sbm_base + R_MAC_CFG;
1386 s->sbm_fifocfg = s->sbm_base + R_MAC_THRSH_CFG; 1362 s->sbm_fifocfg = s->sbm_base + R_MAC_THRSH_CFG;
@@ -1397,29 +1373,29 @@ static int sbmac_initctx(struct sbmac_softc *s)
1397 s->sbm_phy_oldanlpar = 0; 1373 s->sbm_phy_oldanlpar = 0;
1398 s->sbm_phy_oldk1stsr = 0; 1374 s->sbm_phy_oldk1stsr = 0;
1399 s->sbm_phy_oldlinkstat = 0; 1375 s->sbm_phy_oldlinkstat = 0;
1400 1376
1401 /* 1377 /*
1402 * Initialize the DMA channels. Right now, only one per MAC is used 1378 * Initialize the DMA channels. Right now, only one per MAC is used
1403 * Note: Only do this _once_, as it allocates memory from the kernel! 1379 * Note: Only do this _once_, as it allocates memory from the kernel!
1404 */ 1380 */
1405 1381
1406 sbdma_initctx(&(s->sbm_txdma),s,0,DMA_TX,SBMAC_MAX_TXDESCR); 1382 sbdma_initctx(&(s->sbm_txdma),s,0,DMA_TX,SBMAC_MAX_TXDESCR);
1407 sbdma_initctx(&(s->sbm_rxdma),s,0,DMA_RX,SBMAC_MAX_RXDESCR); 1383 sbdma_initctx(&(s->sbm_rxdma),s,0,DMA_RX,SBMAC_MAX_RXDESCR);
1408 1384
1409 /* 1385 /*
1410 * initial state is OFF 1386 * initial state is OFF
1411 */ 1387 */
1412 1388
1413 s->sbm_state = sbmac_state_off; 1389 s->sbm_state = sbmac_state_off;
1414 1390
1415 /* 1391 /*
1416 * Initial speed is (XXX TEMP) 10MBit/s HDX no FC 1392 * Initial speed is (XXX TEMP) 10MBit/s HDX no FC
1417 */ 1393 */
1418 1394
1419 s->sbm_speed = sbmac_speed_10; 1395 s->sbm_speed = sbmac_speed_10;
1420 s->sbm_duplex = sbmac_duplex_half; 1396 s->sbm_duplex = sbmac_duplex_half;
1421 s->sbm_fc = sbmac_fc_disabled; 1397 s->sbm_fc = sbmac_fc_disabled;
1422 1398
1423 return 0; 1399 return 0;
1424} 1400}
1425 1401
@@ -1430,7 +1406,7 @@ static void sbdma_uninitctx(struct sbmacdma_s *d)
1430 kfree(d->sbdma_dscrtable); 1406 kfree(d->sbdma_dscrtable);
1431 d->sbdma_dscrtable = NULL; 1407 d->sbdma_dscrtable = NULL;
1432 } 1408 }
1433 1409
1434 if (d->sbdma_ctxtable) { 1410 if (d->sbdma_ctxtable) {
1435 kfree(d->sbdma_ctxtable); 1411 kfree(d->sbdma_ctxtable);
1436 d->sbdma_ctxtable = NULL; 1412 d->sbdma_ctxtable = NULL;
@@ -1447,12 +1423,12 @@ static void sbmac_uninitctx(struct sbmac_softc *sc)
1447 1423
1448/********************************************************************** 1424/**********************************************************************
1449 * SBMAC_CHANNEL_START(s) 1425 * SBMAC_CHANNEL_START(s)
1450 * 1426 *
1451 * Start packet processing on this MAC. 1427 * Start packet processing on this MAC.
1452 * 1428 *
1453 * Input parameters: 1429 * Input parameters:
1454 * s - sbmac structure 1430 * s - sbmac structure
1455 * 1431 *
1456 * Return value: 1432 * Return value:
1457 * nothing 1433 * nothing
1458 ********************************************************************* */ 1434 ********************************************************************* */
@@ -1460,49 +1436,49 @@ static void sbmac_uninitctx(struct sbmac_softc *sc)
1460static void sbmac_channel_start(struct sbmac_softc *s) 1436static void sbmac_channel_start(struct sbmac_softc *s)
1461{ 1437{
1462 uint64_t reg; 1438 uint64_t reg;
1463 sbmac_port_t port; 1439 volatile void __iomem *port;
1464 uint64_t cfg,fifo,framecfg; 1440 uint64_t cfg,fifo,framecfg;
1465 int idx, th_value; 1441 int idx, th_value;
1466 1442
1467 /* 1443 /*
1468 * Don't do this if running 1444 * Don't do this if running
1469 */ 1445 */
1470 1446
1471 if (s->sbm_state == sbmac_state_on) 1447 if (s->sbm_state == sbmac_state_on)
1472 return; 1448 return;
1473 1449
1474 /* 1450 /*
1475 * Bring the controller out of reset, but leave it off. 1451 * Bring the controller out of reset, but leave it off.
1476 */ 1452 */
1477 1453
1478 SBMAC_WRITECSR(s->sbm_macenable,0); 1454 __raw_writeq(0, s->sbm_macenable);
1479 1455
1480 /* 1456 /*
1481 * Ignore all received packets 1457 * Ignore all received packets
1482 */ 1458 */
1483 1459
1484 SBMAC_WRITECSR(s->sbm_rxfilter,0); 1460 __raw_writeq(0, s->sbm_rxfilter);
1485 1461
1486 /* 1462 /*
1487 * Calculate values for various control registers. 1463 * Calculate values for various control registers.
1488 */ 1464 */
1489 1465
1490 cfg = M_MAC_RETRY_EN | 1466 cfg = M_MAC_RETRY_EN |
1491 M_MAC_TX_HOLD_SOP_EN | 1467 M_MAC_TX_HOLD_SOP_EN |
1492 V_MAC_TX_PAUSE_CNT_16K | 1468 V_MAC_TX_PAUSE_CNT_16K |
1493 M_MAC_AP_STAT_EN | 1469 M_MAC_AP_STAT_EN |
1494 M_MAC_FAST_SYNC | 1470 M_MAC_FAST_SYNC |
1495 M_MAC_SS_EN | 1471 M_MAC_SS_EN |
1496 0; 1472 0;
1497 1473
1498 /* 1474 /*
1499 * Be sure that RD_THRSH+WR_THRSH <= 32 for pass1 pars 1475 * Be sure that RD_THRSH+WR_THRSH <= 32 for pass1 pars
1500 * and make sure that RD_THRSH + WR_THRSH <=128 for pass2 and above 1476 * and make sure that RD_THRSH + WR_THRSH <=128 for pass2 and above
1501 * Use a larger RD_THRSH for gigabit 1477 * Use a larger RD_THRSH for gigabit
1502 */ 1478 */
1503 if (periph_rev >= 2) 1479 if (periph_rev >= 2)
1504 th_value = 64; 1480 th_value = 64;
1505 else 1481 else
1506 th_value = 28; 1482 th_value = 28;
1507 1483
1508 fifo = V_MAC_TX_WR_THRSH(4) | /* Must be '4' or '8' */ 1484 fifo = V_MAC_TX_WR_THRSH(4) | /* Must be '4' or '8' */
@@ -1520,51 +1496,51 @@ static void sbmac_channel_start(struct sbmac_softc *s)
1520 V_MAC_BACKOFF_SEL(1); 1496 V_MAC_BACKOFF_SEL(1);
1521 1497
1522 /* 1498 /*
1523 * Clear out the hash address map 1499 * Clear out the hash address map
1524 */ 1500 */
1525 1501
1526 port = s->sbm_base + R_MAC_HASH_BASE; 1502 port = s->sbm_base + R_MAC_HASH_BASE;
1527 for (idx = 0; idx < MAC_HASH_COUNT; idx++) { 1503 for (idx = 0; idx < MAC_HASH_COUNT; idx++) {
1528 SBMAC_WRITECSR(port,0); 1504 __raw_writeq(0, port);
1529 port += sizeof(uint64_t); 1505 port += sizeof(uint64_t);
1530 } 1506 }
1531 1507
1532 /* 1508 /*
1533 * Clear out the exact-match table 1509 * Clear out the exact-match table
1534 */ 1510 */
1535 1511
1536 port = s->sbm_base + R_MAC_ADDR_BASE; 1512 port = s->sbm_base + R_MAC_ADDR_BASE;
1537 for (idx = 0; idx < MAC_ADDR_COUNT; idx++) { 1513 for (idx = 0; idx < MAC_ADDR_COUNT; idx++) {
1538 SBMAC_WRITECSR(port,0); 1514 __raw_writeq(0, port);
1539 port += sizeof(uint64_t); 1515 port += sizeof(uint64_t);
1540 } 1516 }
1541 1517
1542 /* 1518 /*
1543 * Clear out the DMA Channel mapping table registers 1519 * Clear out the DMA Channel mapping table registers
1544 */ 1520 */
1545 1521
1546 port = s->sbm_base + R_MAC_CHUP0_BASE; 1522 port = s->sbm_base + R_MAC_CHUP0_BASE;
1547 for (idx = 0; idx < MAC_CHMAP_COUNT; idx++) { 1523 for (idx = 0; idx < MAC_CHMAP_COUNT; idx++) {
1548 SBMAC_WRITECSR(port,0); 1524 __raw_writeq(0, port);
1549 port += sizeof(uint64_t); 1525 port += sizeof(uint64_t);
1550 } 1526 }
1551 1527
1552 1528
1553 port = s->sbm_base + R_MAC_CHLO0_BASE; 1529 port = s->sbm_base + R_MAC_CHLO0_BASE;
1554 for (idx = 0; idx < MAC_CHMAP_COUNT; idx++) { 1530 for (idx = 0; idx < MAC_CHMAP_COUNT; idx++) {
1555 SBMAC_WRITECSR(port,0); 1531 __raw_writeq(0, port);
1556 port += sizeof(uint64_t); 1532 port += sizeof(uint64_t);
1557 } 1533 }
1558 1534
1559 /* 1535 /*
1560 * Program the hardware address. It goes into the hardware-address 1536 * Program the hardware address. It goes into the hardware-address
1561 * register as well as the first filter register. 1537 * register as well as the first filter register.
1562 */ 1538 */
1563 1539
1564 reg = sbmac_addr2reg(s->sbm_hwaddr); 1540 reg = sbmac_addr2reg(s->sbm_hwaddr);
1565 1541
1566 port = s->sbm_base + R_MAC_ADDR_BASE; 1542 port = s->sbm_base + R_MAC_ADDR_BASE;
1567 SBMAC_WRITECSR(port,reg); 1543 __raw_writeq(reg, port);
1568 port = s->sbm_base + R_MAC_ETHERNET_ADDR; 1544 port = s->sbm_base + R_MAC_ETHERNET_ADDR;
1569 1545
1570#ifdef CONFIG_SB1_PASS_1_WORKAROUNDS 1546#ifdef CONFIG_SB1_PASS_1_WORKAROUNDS
@@ -1573,108 +1549,105 @@ static void sbmac_channel_start(struct sbmac_softc *s)
1573 * destination address in the R_MAC_ETHERNET_ADDR register. 1549 * destination address in the R_MAC_ETHERNET_ADDR register.
1574 * Set the value to zero. 1550 * Set the value to zero.
1575 */ 1551 */
1576 SBMAC_WRITECSR(port,0); 1552 __raw_writeq(0, port);
1577#else 1553#else
1578 SBMAC_WRITECSR(port,reg); 1554 __raw_writeq(reg, port);
1579#endif 1555#endif
1580 1556
1581 /* 1557 /*
1582 * Set the receive filter for no packets, and write values 1558 * Set the receive filter for no packets, and write values
1583 * to the various config registers 1559 * to the various config registers
1584 */ 1560 */
1585 1561
1586 SBMAC_WRITECSR(s->sbm_rxfilter,0); 1562 __raw_writeq(0, s->sbm_rxfilter);
1587 SBMAC_WRITECSR(s->sbm_imr,0); 1563 __raw_writeq(0, s->sbm_imr);
1588 SBMAC_WRITECSR(s->sbm_framecfg,framecfg); 1564 __raw_writeq(framecfg, s->sbm_framecfg);
1589 SBMAC_WRITECSR(s->sbm_fifocfg,fifo); 1565 __raw_writeq(fifo, s->sbm_fifocfg);
1590 SBMAC_WRITECSR(s->sbm_maccfg,cfg); 1566 __raw_writeq(cfg, s->sbm_maccfg);
1591 1567
1592 /* 1568 /*
1593 * Initialize DMA channels (rings should be ok now) 1569 * Initialize DMA channels (rings should be ok now)
1594 */ 1570 */
1595 1571
1596 sbdma_channel_start(&(s->sbm_rxdma), DMA_RX); 1572 sbdma_channel_start(&(s->sbm_rxdma), DMA_RX);
1597 sbdma_channel_start(&(s->sbm_txdma), DMA_TX); 1573 sbdma_channel_start(&(s->sbm_txdma), DMA_TX);
1598 1574
1599 /* 1575 /*
1600 * Configure the speed, duplex, and flow control 1576 * Configure the speed, duplex, and flow control
1601 */ 1577 */
1602 1578
1603 sbmac_set_speed(s,s->sbm_speed); 1579 sbmac_set_speed(s,s->sbm_speed);
1604 sbmac_set_duplex(s,s->sbm_duplex,s->sbm_fc); 1580 sbmac_set_duplex(s,s->sbm_duplex,s->sbm_fc);
1605 1581
1606 /* 1582 /*
1607 * Fill the receive ring 1583 * Fill the receive ring
1608 */ 1584 */
1609 1585
1610 sbdma_fillring(&(s->sbm_rxdma)); 1586 sbdma_fillring(&(s->sbm_rxdma));
1611 1587
1612 /* 1588 /*
1613 * Turn on the rest of the bits in the enable register 1589 * Turn on the rest of the bits in the enable register
1614 */ 1590 */
1615 1591
1616 SBMAC_WRITECSR(s->sbm_macenable, 1592 __raw_writeq(M_MAC_RXDMA_EN0 |
1617 M_MAC_RXDMA_EN0 |
1618 M_MAC_TXDMA_EN0 | 1593 M_MAC_TXDMA_EN0 |
1619 M_MAC_RX_ENABLE | 1594 M_MAC_RX_ENABLE |
1620 M_MAC_TX_ENABLE); 1595 M_MAC_TX_ENABLE, s->sbm_macenable);
1621 1596
1622 1597
1623 1598
1624 1599
1625#ifdef CONFIG_SBMAC_COALESCE 1600#ifdef CONFIG_SBMAC_COALESCE
1626 /* 1601 /*
1627 * Accept any TX interrupt and EOP count/timer RX interrupts on ch 0 1602 * Accept any TX interrupt and EOP count/timer RX interrupts on ch 0
1628 */ 1603 */
1629 SBMAC_WRITECSR(s->sbm_imr, 1604 __raw_writeq(((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_TX_CH0) |
1630 ((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_TX_CH0) | 1605 ((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_RX_CH0), s->sbm_imr);
1631 ((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_RX_CH0));
1632#else 1606#else
1633 /* 1607 /*
1634 * Accept any kind of interrupt on TX and RX DMA channel 0 1608 * Accept any kind of interrupt on TX and RX DMA channel 0
1635 */ 1609 */
1636 SBMAC_WRITECSR(s->sbm_imr, 1610 __raw_writeq((M_MAC_INT_CHANNEL << S_MAC_TX_CH0) |
1637 (M_MAC_INT_CHANNEL << S_MAC_TX_CH0) | 1611 (M_MAC_INT_CHANNEL << S_MAC_RX_CH0), s->sbm_imr);
1638 (M_MAC_INT_CHANNEL << S_MAC_RX_CH0));
1639#endif 1612#endif
1640 1613
1641 /* 1614 /*
1642 * Enable receiving unicasts and broadcasts 1615 * Enable receiving unicasts and broadcasts
1643 */ 1616 */
1644 1617
1645 SBMAC_WRITECSR(s->sbm_rxfilter,M_MAC_UCAST_EN | M_MAC_BCAST_EN); 1618 __raw_writeq(M_MAC_UCAST_EN | M_MAC_BCAST_EN, s->sbm_rxfilter);
1646 1619
1647 /* 1620 /*
1648 * we're running now. 1621 * we're running now.
1649 */ 1622 */
1650 1623
1651 s->sbm_state = sbmac_state_on; 1624 s->sbm_state = sbmac_state_on;
1652 1625
1653 /* 1626 /*
1654 * Program multicast addresses 1627 * Program multicast addresses
1655 */ 1628 */
1656 1629
1657 sbmac_setmulti(s); 1630 sbmac_setmulti(s);
1658 1631
1659 /* 1632 /*
1660 * If channel was in promiscuous mode before, turn that on 1633 * If channel was in promiscuous mode before, turn that on
1661 */ 1634 */
1662 1635
1663 if (s->sbm_devflags & IFF_PROMISC) { 1636 if (s->sbm_devflags & IFF_PROMISC) {
1664 sbmac_promiscuous_mode(s,1); 1637 sbmac_promiscuous_mode(s,1);
1665 } 1638 }
1666 1639
1667} 1640}
1668 1641
1669 1642
1670/********************************************************************** 1643/**********************************************************************
1671 * SBMAC_CHANNEL_STOP(s) 1644 * SBMAC_CHANNEL_STOP(s)
1672 * 1645 *
1673 * Stop packet processing on this MAC. 1646 * Stop packet processing on this MAC.
1674 * 1647 *
1675 * Input parameters: 1648 * Input parameters:
1676 * s - sbmac structure 1649 * s - sbmac structure
1677 * 1650 *
1678 * Return value: 1651 * Return value:
1679 * nothing 1652 * nothing
1680 ********************************************************************* */ 1653 ********************************************************************* */
@@ -1682,49 +1655,49 @@ static void sbmac_channel_start(struct sbmac_softc *s)
1682static void sbmac_channel_stop(struct sbmac_softc *s) 1655static void sbmac_channel_stop(struct sbmac_softc *s)
1683{ 1656{
1684 /* don't do this if already stopped */ 1657 /* don't do this if already stopped */
1685 1658
1686 if (s->sbm_state == sbmac_state_off) 1659 if (s->sbm_state == sbmac_state_off)
1687 return; 1660 return;
1688 1661
1689 /* don't accept any packets, disable all interrupts */ 1662 /* don't accept any packets, disable all interrupts */
1690 1663
1691 SBMAC_WRITECSR(s->sbm_rxfilter,0); 1664 __raw_writeq(0, s->sbm_rxfilter);
1692 SBMAC_WRITECSR(s->sbm_imr,0); 1665 __raw_writeq(0, s->sbm_imr);
1693 1666
1694 /* Turn off ticker */ 1667 /* Turn off ticker */
1695 1668
1696 /* XXX */ 1669 /* XXX */
1697 1670
1698 /* turn off receiver and transmitter */ 1671 /* turn off receiver and transmitter */
1699 1672
1700 SBMAC_WRITECSR(s->sbm_macenable,0); 1673 __raw_writeq(0, s->sbm_macenable);
1701 1674
1702 /* We're stopped now. */ 1675 /* We're stopped now. */
1703 1676
1704 s->sbm_state = sbmac_state_off; 1677 s->sbm_state = sbmac_state_off;
1705 1678
1706 /* 1679 /*
1707 * Stop DMA channels (rings should be ok now) 1680 * Stop DMA channels (rings should be ok now)
1708 */ 1681 */
1709 1682
1710 sbdma_channel_stop(&(s->sbm_rxdma)); 1683 sbdma_channel_stop(&(s->sbm_rxdma));
1711 sbdma_channel_stop(&(s->sbm_txdma)); 1684 sbdma_channel_stop(&(s->sbm_txdma));
1712 1685
1713 /* Empty the receive and transmit rings */ 1686 /* Empty the receive and transmit rings */
1714 1687
1715 sbdma_emptyring(&(s->sbm_rxdma)); 1688 sbdma_emptyring(&(s->sbm_rxdma));
1716 sbdma_emptyring(&(s->sbm_txdma)); 1689 sbdma_emptyring(&(s->sbm_txdma));
1717 1690
1718} 1691}
1719 1692
1720/********************************************************************** 1693/**********************************************************************
1721 * SBMAC_SET_CHANNEL_STATE(state) 1694 * SBMAC_SET_CHANNEL_STATE(state)
1722 * 1695 *
1723 * Set the channel's state ON or OFF 1696 * Set the channel's state ON or OFF
1724 * 1697 *
1725 * Input parameters: 1698 * Input parameters:
1726 * state - new state 1699 * state - new state
1727 * 1700 *
1728 * Return value: 1701 * Return value:
1729 * old state 1702 * old state
1730 ********************************************************************* */ 1703 ********************************************************************* */
@@ -1732,43 +1705,43 @@ static sbmac_state_t sbmac_set_channel_state(struct sbmac_softc *sc,
1732 sbmac_state_t state) 1705 sbmac_state_t state)
1733{ 1706{
1734 sbmac_state_t oldstate = sc->sbm_state; 1707 sbmac_state_t oldstate = sc->sbm_state;
1735 1708
1736 /* 1709 /*
1737 * If same as previous state, return 1710 * If same as previous state, return
1738 */ 1711 */
1739 1712
1740 if (state == oldstate) { 1713 if (state == oldstate) {
1741 return oldstate; 1714 return oldstate;
1742 } 1715 }
1743 1716
1744 /* 1717 /*
1745 * If new state is ON, turn channel on 1718 * If new state is ON, turn channel on
1746 */ 1719 */
1747 1720
1748 if (state == sbmac_state_on) { 1721 if (state == sbmac_state_on) {
1749 sbmac_channel_start(sc); 1722 sbmac_channel_start(sc);
1750 } 1723 }
1751 else { 1724 else {
1752 sbmac_channel_stop(sc); 1725 sbmac_channel_stop(sc);
1753 } 1726 }
1754 1727
1755 /* 1728 /*
1756 * Return previous state 1729 * Return previous state
1757 */ 1730 */
1758 1731
1759 return oldstate; 1732 return oldstate;
1760} 1733}
1761 1734
1762 1735
1763/********************************************************************** 1736/**********************************************************************
1764 * SBMAC_PROMISCUOUS_MODE(sc,onoff) 1737 * SBMAC_PROMISCUOUS_MODE(sc,onoff)
1765 * 1738 *
1766 * Turn on or off promiscuous mode 1739 * Turn on or off promiscuous mode
1767 * 1740 *
1768 * Input parameters: 1741 * Input parameters:
1769 * sc - softc 1742 * sc - softc
1770 * onoff - 1 to turn on, 0 to turn off 1743 * onoff - 1 to turn on, 0 to turn off
1771 * 1744 *
1772 * Return value: 1745 * Return value:
1773 * nothing 1746 * nothing
1774 ********************************************************************* */ 1747 ********************************************************************* */
@@ -1776,30 +1749,30 @@ static sbmac_state_t sbmac_set_channel_state(struct sbmac_softc *sc,
1776static void sbmac_promiscuous_mode(struct sbmac_softc *sc,int onoff) 1749static void sbmac_promiscuous_mode(struct sbmac_softc *sc,int onoff)
1777{ 1750{
1778 uint64_t reg; 1751 uint64_t reg;
1779 1752
1780 if (sc->sbm_state != sbmac_state_on) 1753 if (sc->sbm_state != sbmac_state_on)
1781 return; 1754 return;
1782 1755
1783 if (onoff) { 1756 if (onoff) {
1784 reg = SBMAC_READCSR(sc->sbm_rxfilter); 1757 reg = __raw_readq(sc->sbm_rxfilter);
1785 reg |= M_MAC_ALLPKT_EN; 1758 reg |= M_MAC_ALLPKT_EN;
1786 SBMAC_WRITECSR(sc->sbm_rxfilter,reg); 1759 __raw_writeq(reg, sc->sbm_rxfilter);
1787 } 1760 }
1788 else { 1761 else {
1789 reg = SBMAC_READCSR(sc->sbm_rxfilter); 1762 reg = __raw_readq(sc->sbm_rxfilter);
1790 reg &= ~M_MAC_ALLPKT_EN; 1763 reg &= ~M_MAC_ALLPKT_EN;
1791 SBMAC_WRITECSR(sc->sbm_rxfilter,reg); 1764 __raw_writeq(reg, sc->sbm_rxfilter);
1792 } 1765 }
1793} 1766}
1794 1767
1795/********************************************************************** 1768/**********************************************************************
1796 * SBMAC_SETIPHDR_OFFSET(sc,onoff) 1769 * SBMAC_SETIPHDR_OFFSET(sc,onoff)
1797 * 1770 *
1798 * Set the iphdr offset as 15 assuming ethernet encapsulation 1771 * Set the iphdr offset as 15 assuming ethernet encapsulation
1799 * 1772 *
1800 * Input parameters: 1773 * Input parameters:
1801 * sc - softc 1774 * sc - softc
1802 * 1775 *
1803 * Return value: 1776 * Return value:
1804 * nothing 1777 * nothing
1805 ********************************************************************* */ 1778 ********************************************************************* */
@@ -1807,12 +1780,12 @@ static void sbmac_promiscuous_mode(struct sbmac_softc *sc,int onoff)
1807static void sbmac_set_iphdr_offset(struct sbmac_softc *sc) 1780static void sbmac_set_iphdr_offset(struct sbmac_softc *sc)
1808{ 1781{
1809 uint64_t reg; 1782 uint64_t reg;
1810 1783
1811 /* Hard code the off set to 15 for now */ 1784 /* Hard code the off set to 15 for now */
1812 reg = SBMAC_READCSR(sc->sbm_rxfilter); 1785 reg = __raw_readq(sc->sbm_rxfilter);
1813 reg &= ~M_MAC_IPHDR_OFFSET | V_MAC_IPHDR_OFFSET(15); 1786 reg &= ~M_MAC_IPHDR_OFFSET | V_MAC_IPHDR_OFFSET(15);
1814 SBMAC_WRITECSR(sc->sbm_rxfilter,reg); 1787 __raw_writeq(reg, sc->sbm_rxfilter);
1815 1788
1816 /* read system identification to determine revision */ 1789 /* read system identification to determine revision */
1817 if (periph_rev >= 2) { 1790 if (periph_rev >= 2) {
1818 sc->rx_hw_checksum = ENABLE; 1791 sc->rx_hw_checksum = ENABLE;
@@ -1824,13 +1797,13 @@ static void sbmac_set_iphdr_offset(struct sbmac_softc *sc)
1824 1797
1825/********************************************************************** 1798/**********************************************************************
1826 * SBMAC_ADDR2REG(ptr) 1799 * SBMAC_ADDR2REG(ptr)
1827 * 1800 *
1828 * Convert six bytes into the 64-bit register value that 1801 * Convert six bytes into the 64-bit register value that
1829 * we typically write into the SBMAC's address/mcast registers 1802 * we typically write into the SBMAC's address/mcast registers
1830 * 1803 *
1831 * Input parameters: 1804 * Input parameters:
1832 * ptr - pointer to 6 bytes 1805 * ptr - pointer to 6 bytes
1833 * 1806 *
1834 * Return value: 1807 * Return value:
1835 * register value 1808 * register value
1836 ********************************************************************* */ 1809 ********************************************************************* */
@@ -1838,35 +1811,35 @@ static void sbmac_set_iphdr_offset(struct sbmac_softc *sc)
1838static uint64_t sbmac_addr2reg(unsigned char *ptr) 1811static uint64_t sbmac_addr2reg(unsigned char *ptr)
1839{ 1812{
1840 uint64_t reg = 0; 1813 uint64_t reg = 0;
1841 1814
1842 ptr += 6; 1815 ptr += 6;
1843 1816
1844 reg |= (uint64_t) *(--ptr); 1817 reg |= (uint64_t) *(--ptr);
1845 reg <<= 8; 1818 reg <<= 8;
1846 reg |= (uint64_t) *(--ptr); 1819 reg |= (uint64_t) *(--ptr);
1847 reg <<= 8; 1820 reg <<= 8;
1848 reg |= (uint64_t) *(--ptr); 1821 reg |= (uint64_t) *(--ptr);
1849 reg <<= 8; 1822 reg <<= 8;
1850 reg |= (uint64_t) *(--ptr); 1823 reg |= (uint64_t) *(--ptr);
1851 reg <<= 8; 1824 reg <<= 8;
1852 reg |= (uint64_t) *(--ptr); 1825 reg |= (uint64_t) *(--ptr);
1853 reg <<= 8; 1826 reg <<= 8;
1854 reg |= (uint64_t) *(--ptr); 1827 reg |= (uint64_t) *(--ptr);
1855 1828
1856 return reg; 1829 return reg;
1857} 1830}
1858 1831
1859 1832
1860/********************************************************************** 1833/**********************************************************************
1861 * SBMAC_SET_SPEED(s,speed) 1834 * SBMAC_SET_SPEED(s,speed)
1862 * 1835 *
1863 * Configure LAN speed for the specified MAC. 1836 * Configure LAN speed for the specified MAC.
1864 * Warning: must be called when MAC is off! 1837 * Warning: must be called when MAC is off!
1865 * 1838 *
1866 * Input parameters: 1839 * Input parameters:
1867 * s - sbmac structure 1840 * s - sbmac structure
1868 * speed - speed to set MAC to (see sbmac_speed_t enum) 1841 * speed - speed to set MAC to (see sbmac_speed_t enum)
1869 * 1842 *
1870 * Return value: 1843 * Return value:
1871 * 1 if successful 1844 * 1 if successful
1872 * 0 indicates invalid parameters 1845 * 0 indicates invalid parameters
@@ -1880,31 +1853,31 @@ static int sbmac_set_speed(struct sbmac_softc *s,sbmac_speed_t speed)
1880 /* 1853 /*
1881 * Save new current values 1854 * Save new current values
1882 */ 1855 */
1883 1856
1884 s->sbm_speed = speed; 1857 s->sbm_speed = speed;
1885 1858
1886 if (s->sbm_state == sbmac_state_on) 1859 if (s->sbm_state == sbmac_state_on)
1887 return 0; /* save for next restart */ 1860 return 0; /* save for next restart */
1888 1861
1889 /* 1862 /*
1890 * Read current register values 1863 * Read current register values
1891 */ 1864 */
1892 1865
1893 cfg = SBMAC_READCSR(s->sbm_maccfg); 1866 cfg = __raw_readq(s->sbm_maccfg);
1894 framecfg = SBMAC_READCSR(s->sbm_framecfg); 1867 framecfg = __raw_readq(s->sbm_framecfg);
1895 1868
1896 /* 1869 /*
1897 * Mask out the stuff we want to change 1870 * Mask out the stuff we want to change
1898 */ 1871 */
1899 1872
1900 cfg &= ~(M_MAC_BURST_EN | M_MAC_SPEED_SEL); 1873 cfg &= ~(M_MAC_BURST_EN | M_MAC_SPEED_SEL);
1901 framecfg &= ~(M_MAC_IFG_RX | M_MAC_IFG_TX | M_MAC_IFG_THRSH | 1874 framecfg &= ~(M_MAC_IFG_RX | M_MAC_IFG_TX | M_MAC_IFG_THRSH |
1902 M_MAC_SLOT_SIZE); 1875 M_MAC_SLOT_SIZE);
1903 1876
1904 /* 1877 /*
1905 * Now add in the new bits 1878 * Now add in the new bits
1906 */ 1879 */
1907 1880
1908 switch (speed) { 1881 switch (speed) {
1909 case sbmac_speed_10: 1882 case sbmac_speed_10:
1910 framecfg |= V_MAC_IFG_RX_10 | 1883 framecfg |= V_MAC_IFG_RX_10 |
@@ -1913,7 +1886,7 @@ static int sbmac_set_speed(struct sbmac_softc *s,sbmac_speed_t speed)
1913 V_MAC_SLOT_SIZE_10; 1886 V_MAC_SLOT_SIZE_10;
1914 cfg |= V_MAC_SPEED_SEL_10MBPS; 1887 cfg |= V_MAC_SPEED_SEL_10MBPS;
1915 break; 1888 break;
1916 1889
1917 case sbmac_speed_100: 1890 case sbmac_speed_100:
1918 framecfg |= V_MAC_IFG_RX_100 | 1891 framecfg |= V_MAC_IFG_RX_100 |
1919 V_MAC_IFG_TX_100 | 1892 V_MAC_IFG_TX_100 |
@@ -1921,7 +1894,7 @@ static int sbmac_set_speed(struct sbmac_softc *s,sbmac_speed_t speed)
1921 V_MAC_SLOT_SIZE_100; 1894 V_MAC_SLOT_SIZE_100;
1922 cfg |= V_MAC_SPEED_SEL_100MBPS ; 1895 cfg |= V_MAC_SPEED_SEL_100MBPS ;
1923 break; 1896 break;
1924 1897
1925 case sbmac_speed_1000: 1898 case sbmac_speed_1000:
1926 framecfg |= V_MAC_IFG_RX_1000 | 1899 framecfg |= V_MAC_IFG_RX_1000 |
1927 V_MAC_IFG_TX_1000 | 1900 V_MAC_IFG_TX_1000 |
@@ -1929,34 +1902,34 @@ static int sbmac_set_speed(struct sbmac_softc *s,sbmac_speed_t speed)
1929 V_MAC_SLOT_SIZE_1000; 1902 V_MAC_SLOT_SIZE_1000;
1930 cfg |= V_MAC_SPEED_SEL_1000MBPS | M_MAC_BURST_EN; 1903 cfg |= V_MAC_SPEED_SEL_1000MBPS | M_MAC_BURST_EN;
1931 break; 1904 break;
1932 1905
1933 case sbmac_speed_auto: /* XXX not implemented */ 1906 case sbmac_speed_auto: /* XXX not implemented */
1934 /* fall through */ 1907 /* fall through */
1935 default: 1908 default:
1936 return 0; 1909 return 0;
1937 } 1910 }
1938 1911
1939 /* 1912 /*
1940 * Send the bits back to the hardware 1913 * Send the bits back to the hardware
1941 */ 1914 */
1942 1915
1943 SBMAC_WRITECSR(s->sbm_framecfg,framecfg); 1916 __raw_writeq(framecfg, s->sbm_framecfg);
1944 SBMAC_WRITECSR(s->sbm_maccfg,cfg); 1917 __raw_writeq(cfg, s->sbm_maccfg);
1945 1918
1946 return 1; 1919 return 1;
1947} 1920}
1948 1921
1949/********************************************************************** 1922/**********************************************************************
1950 * SBMAC_SET_DUPLEX(s,duplex,fc) 1923 * SBMAC_SET_DUPLEX(s,duplex,fc)
1951 * 1924 *
1952 * Set Ethernet duplex and flow control options for this MAC 1925 * Set Ethernet duplex and flow control options for this MAC
1953 * Warning: must be called when MAC is off! 1926 * Warning: must be called when MAC is off!
1954 * 1927 *
1955 * Input parameters: 1928 * Input parameters:
1956 * s - sbmac structure 1929 * s - sbmac structure
1957 * duplex - duplex setting (see sbmac_duplex_t) 1930 * duplex - duplex setting (see sbmac_duplex_t)
1958 * fc - flow control setting (see sbmac_fc_t) 1931 * fc - flow control setting (see sbmac_fc_t)
1959 * 1932 *
1960 * Return value: 1933 * Return value:
1961 * 1 if ok 1934 * 1 if ok
1962 * 0 if an invalid parameter combination was specified 1935 * 0 if an invalid parameter combination was specified
@@ -1965,67 +1938,67 @@ static int sbmac_set_speed(struct sbmac_softc *s,sbmac_speed_t speed)
1965static int sbmac_set_duplex(struct sbmac_softc *s,sbmac_duplex_t duplex,sbmac_fc_t fc) 1938static int sbmac_set_duplex(struct sbmac_softc *s,sbmac_duplex_t duplex,sbmac_fc_t fc)
1966{ 1939{
1967 uint64_t cfg; 1940 uint64_t cfg;
1968 1941
1969 /* 1942 /*
1970 * Save new current values 1943 * Save new current values
1971 */ 1944 */
1972 1945
1973 s->sbm_duplex = duplex; 1946 s->sbm_duplex = duplex;
1974 s->sbm_fc = fc; 1947 s->sbm_fc = fc;
1975 1948
1976 if (s->sbm_state == sbmac_state_on) 1949 if (s->sbm_state == sbmac_state_on)
1977 return 0; /* save for next restart */ 1950 return 0; /* save for next restart */
1978 1951
1979 /* 1952 /*
1980 * Read current register values 1953 * Read current register values
1981 */ 1954 */
1982 1955
1983 cfg = SBMAC_READCSR(s->sbm_maccfg); 1956 cfg = __raw_readq(s->sbm_maccfg);
1984 1957
1985 /* 1958 /*
1986 * Mask off the stuff we're about to change 1959 * Mask off the stuff we're about to change
1987 */ 1960 */
1988 1961
1989 cfg &= ~(M_MAC_FC_SEL | M_MAC_FC_CMD | M_MAC_HDX_EN); 1962 cfg &= ~(M_MAC_FC_SEL | M_MAC_FC_CMD | M_MAC_HDX_EN);
1990 1963
1991 1964
1992 switch (duplex) { 1965 switch (duplex) {
1993 case sbmac_duplex_half: 1966 case sbmac_duplex_half:
1994 switch (fc) { 1967 switch (fc) {
1995 case sbmac_fc_disabled: 1968 case sbmac_fc_disabled:
1996 cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_DISABLED; 1969 cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_DISABLED;
1997 break; 1970 break;
1998 1971
1999 case sbmac_fc_collision: 1972 case sbmac_fc_collision:
2000 cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_ENABLED; 1973 cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_ENABLED;
2001 break; 1974 break;
2002 1975
2003 case sbmac_fc_carrier: 1976 case sbmac_fc_carrier:
2004 cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_ENAB_FALSECARR; 1977 cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_ENAB_FALSECARR;
2005 break; 1978 break;
2006 1979
2007 case sbmac_fc_auto: /* XXX not implemented */ 1980 case sbmac_fc_auto: /* XXX not implemented */
2008 /* fall through */ 1981 /* fall through */
2009 case sbmac_fc_frame: /* not valid in half duplex */ 1982 case sbmac_fc_frame: /* not valid in half duplex */
2010 default: /* invalid selection */ 1983 default: /* invalid selection */
2011 return 0; 1984 return 0;
2012 } 1985 }
2013 break; 1986 break;
2014 1987
2015 case sbmac_duplex_full: 1988 case sbmac_duplex_full:
2016 switch (fc) { 1989 switch (fc) {
2017 case sbmac_fc_disabled: 1990 case sbmac_fc_disabled:
2018 cfg |= V_MAC_FC_CMD_DISABLED; 1991 cfg |= V_MAC_FC_CMD_DISABLED;
2019 break; 1992 break;
2020 1993
2021 case sbmac_fc_frame: 1994 case sbmac_fc_frame:
2022 cfg |= V_MAC_FC_CMD_ENABLED; 1995 cfg |= V_MAC_FC_CMD_ENABLED;
2023 break; 1996 break;
2024 1997
2025 case sbmac_fc_collision: /* not valid in full duplex */ 1998 case sbmac_fc_collision: /* not valid in full duplex */
2026 case sbmac_fc_carrier: /* not valid in full duplex */ 1999 case sbmac_fc_carrier: /* not valid in full duplex */
2027 case sbmac_fc_auto: /* XXX not implemented */ 2000 case sbmac_fc_auto: /* XXX not implemented */
2028 /* fall through */ 2001 /* fall through */
2029 default: 2002 default:
2030 return 0; 2003 return 0;
2031 } 2004 }
@@ -2034,13 +2007,13 @@ static int sbmac_set_duplex(struct sbmac_softc *s,sbmac_duplex_t duplex,sbmac_fc
2034 /* XXX not implemented */ 2007 /* XXX not implemented */
2035 break; 2008 break;
2036 } 2009 }
2037 2010
2038 /* 2011 /*
2039 * Send the bits back to the hardware 2012 * Send the bits back to the hardware
2040 */ 2013 */
2041 2014
2042 SBMAC_WRITECSR(s->sbm_maccfg,cfg); 2015 __raw_writeq(cfg, s->sbm_maccfg);
2043 2016
2044 return 1; 2017 return 1;
2045} 2018}
2046 2019
@@ -2049,12 +2022,12 @@ static int sbmac_set_duplex(struct sbmac_softc *s,sbmac_duplex_t duplex,sbmac_fc
2049 2022
2050/********************************************************************** 2023/**********************************************************************
2051 * SBMAC_INTR() 2024 * SBMAC_INTR()
2052 * 2025 *
2053 * Interrupt handler for MAC interrupts 2026 * Interrupt handler for MAC interrupts
2054 * 2027 *
2055 * Input parameters: 2028 * Input parameters:
2056 * MAC structure 2029 * MAC structure
2057 * 2030 *
2058 * Return value: 2031 * Return value:
2059 * nothing 2032 * nothing
2060 ********************************************************************* */ 2033 ********************************************************************* */
@@ -2066,27 +2039,27 @@ static irqreturn_t sbmac_intr(int irq,void *dev_instance,struct pt_regs *rgs)
2066 int handled = 0; 2039 int handled = 0;
2067 2040
2068 for (;;) { 2041 for (;;) {
2069 2042
2070 /* 2043 /*
2071 * Read the ISR (this clears the bits in the real 2044 * Read the ISR (this clears the bits in the real
2072 * register, except for counter addr) 2045 * register, except for counter addr)
2073 */ 2046 */
2074 2047
2075 isr = SBMAC_READCSR(sc->sbm_isr) & ~M_MAC_COUNTER_ADDR; 2048 isr = __raw_readq(sc->sbm_isr) & ~M_MAC_COUNTER_ADDR;
2076 2049
2077 if (isr == 0) 2050 if (isr == 0)
2078 break; 2051 break;
2079 2052
2080 handled = 1; 2053 handled = 1;
2081 2054
2082 /* 2055 /*
2083 * Transmits on channel 0 2056 * Transmits on channel 0
2084 */ 2057 */
2085 2058
2086 if (isr & (M_MAC_INT_CHANNEL << S_MAC_TX_CH0)) { 2059 if (isr & (M_MAC_INT_CHANNEL << S_MAC_TX_CH0)) {
2087 sbdma_tx_process(sc,&(sc->sbm_txdma)); 2060 sbdma_tx_process(sc,&(sc->sbm_txdma));
2088 } 2061 }
2089 2062
2090 /* 2063 /*
2091 * Receives on channel 0 2064 * Receives on channel 0
2092 */ 2065 */
@@ -2106,8 +2079,8 @@ static irqreturn_t sbmac_intr(int irq,void *dev_instance,struct pt_regs *rgs)
2106 * EOP_SEEN here takes care of this case. 2079 * EOP_SEEN here takes care of this case.
2107 * (EOP_SEEN is part of M_MAC_INT_CHANNEL << S_MAC_RX_CH0) 2080 * (EOP_SEEN is part of M_MAC_INT_CHANNEL << S_MAC_RX_CH0)
2108 */ 2081 */
2109 2082
2110 2083
2111 if (isr & (M_MAC_INT_CHANNEL << S_MAC_RX_CH0)) { 2084 if (isr & (M_MAC_INT_CHANNEL << S_MAC_RX_CH0)) {
2112 sbdma_rx_process(sc,&(sc->sbm_rxdma)); 2085 sbdma_rx_process(sc,&(sc->sbm_rxdma));
2113 } 2086 }
@@ -2118,29 +2091,29 @@ static irqreturn_t sbmac_intr(int irq,void *dev_instance,struct pt_regs *rgs)
2118 2091
2119/********************************************************************** 2092/**********************************************************************
2120 * SBMAC_START_TX(skb,dev) 2093 * SBMAC_START_TX(skb,dev)
2121 * 2094 *
2122 * Start output on the specified interface. Basically, we 2095 * Start output on the specified interface. Basically, we
2123 * queue as many buffers as we can until the ring fills up, or 2096 * queue as many buffers as we can until the ring fills up, or
2124 * we run off the end of the queue, whichever comes first. 2097 * we run off the end of the queue, whichever comes first.
2125 * 2098 *
2126 * Input parameters: 2099 * Input parameters:
2127 * 2100 *
2128 * 2101 *
2129 * Return value: 2102 * Return value:
2130 * nothing 2103 * nothing
2131 ********************************************************************* */ 2104 ********************************************************************* */
2132static int sbmac_start_tx(struct sk_buff *skb, struct net_device *dev) 2105static int sbmac_start_tx(struct sk_buff *skb, struct net_device *dev)
2133{ 2106{
2134 struct sbmac_softc *sc = netdev_priv(dev); 2107 struct sbmac_softc *sc = netdev_priv(dev);
2135 2108
2136 /* lock eth irq */ 2109 /* lock eth irq */
2137 spin_lock_irq (&sc->sbm_lock); 2110 spin_lock_irq (&sc->sbm_lock);
2138 2111
2139 /* 2112 /*
2140 * Put the buffer on the transmit ring. If we 2113 * Put the buffer on the transmit ring. If we
2141 * don't have room, stop the queue. 2114 * don't have room, stop the queue.
2142 */ 2115 */
2143 2116
2144 if (sbdma_add_txbuffer(&(sc->sbm_txdma),skb)) { 2117 if (sbdma_add_txbuffer(&(sc->sbm_txdma),skb)) {
2145 /* XXX save skb that we could not send */ 2118 /* XXX save skb that we could not send */
2146 netif_stop_queue(dev); 2119 netif_stop_queue(dev);
@@ -2148,24 +2121,24 @@ static int sbmac_start_tx(struct sk_buff *skb, struct net_device *dev)
2148 2121
2149 return 1; 2122 return 1;
2150 } 2123 }
2151 2124
2152 dev->trans_start = jiffies; 2125 dev->trans_start = jiffies;
2153 2126
2154 spin_unlock_irq (&sc->sbm_lock); 2127 spin_unlock_irq (&sc->sbm_lock);
2155 2128
2156 return 0; 2129 return 0;
2157} 2130}
2158 2131
2159/********************************************************************** 2132/**********************************************************************
2160 * SBMAC_SETMULTI(sc) 2133 * SBMAC_SETMULTI(sc)
2161 * 2134 *
2162 * Reprogram the multicast table into the hardware, given 2135 * Reprogram the multicast table into the hardware, given
2163 * the list of multicasts associated with the interface 2136 * the list of multicasts associated with the interface
2164 * structure. 2137 * structure.
2165 * 2138 *
2166 * Input parameters: 2139 * Input parameters:
2167 * sc - softc 2140 * sc - softc
2168 * 2141 *
2169 * Return value: 2142 * Return value:
2170 * nothing 2143 * nothing
2171 ********************************************************************* */ 2144 ********************************************************************* */
@@ -2173,75 +2146,75 @@ static int sbmac_start_tx(struct sk_buff *skb, struct net_device *dev)
2173static void sbmac_setmulti(struct sbmac_softc *sc) 2146static void sbmac_setmulti(struct sbmac_softc *sc)
2174{ 2147{
2175 uint64_t reg; 2148 uint64_t reg;
2176 sbmac_port_t port; 2149 volatile void __iomem *port;
2177 int idx; 2150 int idx;
2178 struct dev_mc_list *mclist; 2151 struct dev_mc_list *mclist;
2179 struct net_device *dev = sc->sbm_dev; 2152 struct net_device *dev = sc->sbm_dev;
2180 2153
2181 /* 2154 /*
2182 * Clear out entire multicast table. We do this by nuking 2155 * Clear out entire multicast table. We do this by nuking
2183 * the entire hash table and all the direct matches except 2156 * the entire hash table and all the direct matches except
2184 * the first one, which is used for our station address 2157 * the first one, which is used for our station address
2185 */ 2158 */
2186 2159
2187 for (idx = 1; idx < MAC_ADDR_COUNT; idx++) { 2160 for (idx = 1; idx < MAC_ADDR_COUNT; idx++) {
2188 port = sc->sbm_base + R_MAC_ADDR_BASE+(idx*sizeof(uint64_t)); 2161 port = sc->sbm_base + R_MAC_ADDR_BASE+(idx*sizeof(uint64_t));
2189 SBMAC_WRITECSR(port,0); 2162 __raw_writeq(0, port);
2190 } 2163 }
2191 2164
2192 for (idx = 0; idx < MAC_HASH_COUNT; idx++) { 2165 for (idx = 0; idx < MAC_HASH_COUNT; idx++) {
2193 port = sc->sbm_base + R_MAC_HASH_BASE+(idx*sizeof(uint64_t)); 2166 port = sc->sbm_base + R_MAC_HASH_BASE+(idx*sizeof(uint64_t));
2194 SBMAC_WRITECSR(port,0); 2167 __raw_writeq(0, port);
2195 } 2168 }
2196 2169
2197 /* 2170 /*
2198 * Clear the filter to say we don't want any multicasts. 2171 * Clear the filter to say we don't want any multicasts.
2199 */ 2172 */
2200 2173
2201 reg = SBMAC_READCSR(sc->sbm_rxfilter); 2174 reg = __raw_readq(sc->sbm_rxfilter);
2202 reg &= ~(M_MAC_MCAST_INV | M_MAC_MCAST_EN); 2175 reg &= ~(M_MAC_MCAST_INV | M_MAC_MCAST_EN);
2203 SBMAC_WRITECSR(sc->sbm_rxfilter,reg); 2176 __raw_writeq(reg, sc->sbm_rxfilter);
2204 2177
2205 if (dev->flags & IFF_ALLMULTI) { 2178 if (dev->flags & IFF_ALLMULTI) {
2206 /* 2179 /*
2207 * Enable ALL multicasts. Do this by inverting the 2180 * Enable ALL multicasts. Do this by inverting the
2208 * multicast enable bit. 2181 * multicast enable bit.
2209 */ 2182 */
2210 reg = SBMAC_READCSR(sc->sbm_rxfilter); 2183 reg = __raw_readq(sc->sbm_rxfilter);
2211 reg |= (M_MAC_MCAST_INV | M_MAC_MCAST_EN); 2184 reg |= (M_MAC_MCAST_INV | M_MAC_MCAST_EN);
2212 SBMAC_WRITECSR(sc->sbm_rxfilter,reg); 2185 __raw_writeq(reg, sc->sbm_rxfilter);
2213 return; 2186 return;
2214 } 2187 }
2215
2216 2188
2217 /* 2189
2190 /*
2218 * Progam new multicast entries. For now, only use the 2191 * Progam new multicast entries. For now, only use the
2219 * perfect filter. In the future we'll need to use the 2192 * perfect filter. In the future we'll need to use the
2220 * hash filter if the perfect filter overflows 2193 * hash filter if the perfect filter overflows
2221 */ 2194 */
2222 2195
2223 /* XXX only using perfect filter for now, need to use hash 2196 /* XXX only using perfect filter for now, need to use hash
2224 * XXX if the table overflows */ 2197 * XXX if the table overflows */
2225 2198
2226 idx = 1; /* skip station address */ 2199 idx = 1; /* skip station address */
2227 mclist = dev->mc_list; 2200 mclist = dev->mc_list;
2228 while (mclist && (idx < MAC_ADDR_COUNT)) { 2201 while (mclist && (idx < MAC_ADDR_COUNT)) {
2229 reg = sbmac_addr2reg(mclist->dmi_addr); 2202 reg = sbmac_addr2reg(mclist->dmi_addr);
2230 port = sc->sbm_base + R_MAC_ADDR_BASE+(idx * sizeof(uint64_t)); 2203 port = sc->sbm_base + R_MAC_ADDR_BASE+(idx * sizeof(uint64_t));
2231 SBMAC_WRITECSR(port,reg); 2204 __raw_writeq(reg, port);
2232 idx++; 2205 idx++;
2233 mclist = mclist->next; 2206 mclist = mclist->next;
2234 } 2207 }
2235 2208
2236 /* 2209 /*
2237 * Enable the "accept multicast bits" if we programmed at least one 2210 * Enable the "accept multicast bits" if we programmed at least one
2238 * multicast. 2211 * multicast.
2239 */ 2212 */
2240 2213
2241 if (idx > 1) { 2214 if (idx > 1) {
2242 reg = SBMAC_READCSR(sc->sbm_rxfilter); 2215 reg = __raw_readq(sc->sbm_rxfilter);
2243 reg |= M_MAC_MCAST_EN; 2216 reg |= M_MAC_MCAST_EN;
2244 SBMAC_WRITECSR(sc->sbm_rxfilter,reg); 2217 __raw_writeq(reg, sc->sbm_rxfilter);
2245 } 2218 }
2246} 2219}
2247 2220
@@ -2250,12 +2223,12 @@ static void sbmac_setmulti(struct sbmac_softc *sc)
2250#if defined(SBMAC_ETH0_HWADDR) || defined(SBMAC_ETH1_HWADDR) || defined(SBMAC_ETH2_HWADDR) 2223#if defined(SBMAC_ETH0_HWADDR) || defined(SBMAC_ETH1_HWADDR) || defined(SBMAC_ETH2_HWADDR)
2251/********************************************************************** 2224/**********************************************************************
2252 * SBMAC_PARSE_XDIGIT(str) 2225 * SBMAC_PARSE_XDIGIT(str)
2253 * 2226 *
2254 * Parse a hex digit, returning its value 2227 * Parse a hex digit, returning its value
2255 * 2228 *
2256 * Input parameters: 2229 * Input parameters:
2257 * str - character 2230 * str - character
2258 * 2231 *
2259 * Return value: 2232 * Return value:
2260 * hex value, or -1 if invalid 2233 * hex value, or -1 if invalid
2261 ********************************************************************* */ 2234 ********************************************************************* */
@@ -2263,7 +2236,7 @@ static void sbmac_setmulti(struct sbmac_softc *sc)
2263static int sbmac_parse_xdigit(char str) 2236static int sbmac_parse_xdigit(char str)
2264{ 2237{
2265 int digit; 2238 int digit;
2266 2239
2267 if ((str >= '0') && (str <= '9')) 2240 if ((str >= '0') && (str <= '9'))
2268 digit = str - '0'; 2241 digit = str - '0';
2269 else if ((str >= 'a') && (str <= 'f')) 2242 else if ((str >= 'a') && (str <= 'f'))
@@ -2272,20 +2245,20 @@ static int sbmac_parse_xdigit(char str)
2272 digit = str - 'A' + 10; 2245 digit = str - 'A' + 10;
2273 else 2246 else
2274 return -1; 2247 return -1;
2275 2248
2276 return digit; 2249 return digit;
2277} 2250}
2278 2251
2279/********************************************************************** 2252/**********************************************************************
2280 * SBMAC_PARSE_HWADDR(str,hwaddr) 2253 * SBMAC_PARSE_HWADDR(str,hwaddr)
2281 * 2254 *
2282 * Convert a string in the form xx:xx:xx:xx:xx:xx into a 6-byte 2255 * Convert a string in the form xx:xx:xx:xx:xx:xx into a 6-byte
2283 * Ethernet address. 2256 * Ethernet address.
2284 * 2257 *
2285 * Input parameters: 2258 * Input parameters:
2286 * str - string 2259 * str - string
2287 * hwaddr - pointer to hardware address 2260 * hwaddr - pointer to hardware address
2288 * 2261 *
2289 * Return value: 2262 * Return value:
2290 * 0 if ok, else -1 2263 * 0 if ok, else -1
2291 ********************************************************************* */ 2264 ********************************************************************* */
@@ -2294,7 +2267,7 @@ static int sbmac_parse_hwaddr(char *str, unsigned char *hwaddr)
2294{ 2267{
2295 int digit1,digit2; 2268 int digit1,digit2;
2296 int idx = 6; 2269 int idx = 6;
2297 2270
2298 while (*str && (idx > 0)) { 2271 while (*str && (idx > 0)) {
2299 digit1 = sbmac_parse_xdigit(*str); 2272 digit1 = sbmac_parse_xdigit(*str);
2300 if (digit1 < 0) 2273 if (digit1 < 0)
@@ -2302,7 +2275,7 @@ static int sbmac_parse_hwaddr(char *str, unsigned char *hwaddr)
2302 str++; 2275 str++;
2303 if (!*str) 2276 if (!*str)
2304 return -1; 2277 return -1;
2305 2278
2306 if ((*str == ':') || (*str == '-')) { 2279 if ((*str == ':') || (*str == '-')) {
2307 digit2 = digit1; 2280 digit2 = digit1;
2308 digit1 = 0; 2281 digit1 = 0;
@@ -2313,10 +2286,10 @@ static int sbmac_parse_hwaddr(char *str, unsigned char *hwaddr)
2313 return -1; 2286 return -1;
2314 str++; 2287 str++;
2315 } 2288 }
2316 2289
2317 *hwaddr++ = (digit1 << 4) | digit2; 2290 *hwaddr++ = (digit1 << 4) | digit2;
2318 idx--; 2291 idx--;
2319 2292
2320 if (*str == '-') 2293 if (*str == '-')
2321 str++; 2294 str++;
2322 if (*str == ':') 2295 if (*str == ':')
@@ -2337,12 +2310,12 @@ static int sb1250_change_mtu(struct net_device *_dev, int new_mtu)
2337 2310
2338/********************************************************************** 2311/**********************************************************************
2339 * SBMAC_INIT(dev) 2312 * SBMAC_INIT(dev)
2340 * 2313 *
2341 * Attach routine - init hardware and hook ourselves into linux 2314 * Attach routine - init hardware and hook ourselves into linux
2342 * 2315 *
2343 * Input parameters: 2316 * Input parameters:
2344 * dev - net_device structure 2317 * dev - net_device structure
2345 * 2318 *
2346 * Return value: 2319 * Return value:
2347 * status 2320 * status
2348 ********************************************************************* */ 2321 ********************************************************************* */
@@ -2354,53 +2327,53 @@ static int sbmac_init(struct net_device *dev, int idx)
2354 uint64_t ea_reg; 2327 uint64_t ea_reg;
2355 int i; 2328 int i;
2356 int err; 2329 int err;
2357 2330
2358 sc = netdev_priv(dev); 2331 sc = netdev_priv(dev);
2359 2332
2360 /* Determine controller base address */ 2333 /* Determine controller base address */
2361 2334
2362 sc->sbm_base = IOADDR(dev->base_addr); 2335 sc->sbm_base = IOADDR(dev->base_addr);
2363 sc->sbm_dev = dev; 2336 sc->sbm_dev = dev;
2364 sc->sbe_idx = idx; 2337 sc->sbe_idx = idx;
2365 2338
2366 eaddr = sc->sbm_hwaddr; 2339 eaddr = sc->sbm_hwaddr;
2367 2340
2368 /* 2341 /*
2369 * Read the ethernet address. The firwmare left this programmed 2342 * Read the ethernet address. The firwmare left this programmed
2370 * for us in the ethernet address register for each mac. 2343 * for us in the ethernet address register for each mac.
2371 */ 2344 */
2372 2345
2373 ea_reg = SBMAC_READCSR(sc->sbm_base + R_MAC_ETHERNET_ADDR); 2346 ea_reg = __raw_readq(sc->sbm_base + R_MAC_ETHERNET_ADDR);
2374 SBMAC_WRITECSR(sc->sbm_base + R_MAC_ETHERNET_ADDR, 0); 2347 __raw_writeq(0, sc->sbm_base + R_MAC_ETHERNET_ADDR);
2375 for (i = 0; i < 6; i++) { 2348 for (i = 0; i < 6; i++) {
2376 eaddr[i] = (uint8_t) (ea_reg & 0xFF); 2349 eaddr[i] = (uint8_t) (ea_reg & 0xFF);
2377 ea_reg >>= 8; 2350 ea_reg >>= 8;
2378 } 2351 }
2379 2352
2380 for (i = 0; i < 6; i++) { 2353 for (i = 0; i < 6; i++) {
2381 dev->dev_addr[i] = eaddr[i]; 2354 dev->dev_addr[i] = eaddr[i];
2382 } 2355 }
2383 2356
2384 2357
2385 /* 2358 /*
2386 * Init packet size 2359 * Init packet size
2387 */ 2360 */
2388 2361
2389 sc->sbm_buffersize = ENET_PACKET_SIZE + SMP_CACHE_BYTES * 2 + ETHER_ALIGN; 2362 sc->sbm_buffersize = ENET_PACKET_SIZE + SMP_CACHE_BYTES * 2 + ETHER_ALIGN;
2390 2363
2391 /* 2364 /*
2392 * Initialize context (get pointers to registers and stuff), then 2365 * Initialize context (get pointers to registers and stuff), then
2393 * allocate the memory for the descriptor tables. 2366 * allocate the memory for the descriptor tables.
2394 */ 2367 */
2395 2368
2396 sbmac_initctx(sc); 2369 sbmac_initctx(sc);
2397 2370
2398 /* 2371 /*
2399 * Set up Linux device callins 2372 * Set up Linux device callins
2400 */ 2373 */
2401 2374
2402 spin_lock_init(&(sc->sbm_lock)); 2375 spin_lock_init(&(sc->sbm_lock));
2403 2376
2404 dev->open = sbmac_open; 2377 dev->open = sbmac_open;
2405 dev->hard_start_xmit = sbmac_start_tx; 2378 dev->hard_start_xmit = sbmac_start_tx;
2406 dev->stop = sbmac_close; 2379 dev->stop = sbmac_close;
@@ -2419,7 +2392,7 @@ static int sbmac_init(struct net_device *dev, int idx)
2419 if (err) 2392 if (err)
2420 goto out_uninit; 2393 goto out_uninit;
2421 2394
2422 if (periph_rev >= 2) { 2395 if (sc->rx_hw_checksum == ENABLE) {
2423 printk(KERN_INFO "%s: enabling TCP rcv checksum\n", 2396 printk(KERN_INFO "%s: enabling TCP rcv checksum\n",
2424 sc->sbm_dev->name); 2397 sc->sbm_dev->name);
2425 } 2398 }
@@ -2430,10 +2403,10 @@ static int sbmac_init(struct net_device *dev, int idx)
2430 * was being displayed) 2403 * was being displayed)
2431 */ 2404 */
2432 printk(KERN_INFO 2405 printk(KERN_INFO
2433 "%s: SiByte Ethernet at 0x%08lX, address: %02X:%02X:%02X:%02X:%02X:%02X\n", 2406 "%s: SiByte Ethernet at 0x%08lX, address: %02X:%02X:%02X:%02X:%02X:%02X\n",
2434 dev->name, dev->base_addr, 2407 dev->name, dev->base_addr,
2435 eaddr[0],eaddr[1],eaddr[2],eaddr[3],eaddr[4],eaddr[5]); 2408 eaddr[0],eaddr[1],eaddr[2],eaddr[3],eaddr[4],eaddr[5]);
2436 2409
2437 2410
2438 return 0; 2411 return 0;
2439 2412
@@ -2447,54 +2420,86 @@ out_uninit:
2447static int sbmac_open(struct net_device *dev) 2420static int sbmac_open(struct net_device *dev)
2448{ 2421{
2449 struct sbmac_softc *sc = netdev_priv(dev); 2422 struct sbmac_softc *sc = netdev_priv(dev);
2450 2423
2451 if (debug > 1) { 2424 if (debug > 1) {
2452 printk(KERN_DEBUG "%s: sbmac_open() irq %d.\n", dev->name, dev->irq); 2425 printk(KERN_DEBUG "%s: sbmac_open() irq %d.\n", dev->name, dev->irq);
2453 } 2426 }
2454 2427
2455 /* 2428 /*
2456 * map/route interrupt (clear status first, in case something 2429 * map/route interrupt (clear status first, in case something
2457 * weird is pending; we haven't initialized the mac registers 2430 * weird is pending; we haven't initialized the mac registers
2458 * yet) 2431 * yet)
2459 */ 2432 */
2460 2433
2461 SBMAC_READCSR(sc->sbm_isr); 2434 __raw_readq(sc->sbm_isr);
2462 if (request_irq(dev->irq, &sbmac_intr, SA_SHIRQ, dev->name, dev)) 2435 if (request_irq(dev->irq, &sbmac_intr, SA_SHIRQ, dev->name, dev))
2463 return -EBUSY; 2436 return -EBUSY;
2464 2437
2465 /* 2438 /*
2466 * Configure default speed 2439 * Probe phy address
2440 */
2441
2442 if(sbmac_mii_probe(dev) == -1) {
2443 printk("%s: failed to probe PHY.\n", dev->name);
2444 return -EINVAL;
2445 }
2446
2447 /*
2448 * Configure default speed
2467 */ 2449 */
2468 2450
2469 sbmac_mii_poll(sc,noisy_mii); 2451 sbmac_mii_poll(sc,noisy_mii);
2470 2452
2471 /* 2453 /*
2472 * Turn on the channel 2454 * Turn on the channel
2473 */ 2455 */
2474 2456
2475 sbmac_set_channel_state(sc,sbmac_state_on); 2457 sbmac_set_channel_state(sc,sbmac_state_on);
2476 2458
2477 /* 2459 /*
2478 * XXX Station address is in dev->dev_addr 2460 * XXX Station address is in dev->dev_addr
2479 */ 2461 */
2480 2462
2481 if (dev->if_port == 0) 2463 if (dev->if_port == 0)
2482 dev->if_port = 0; 2464 dev->if_port = 0;
2483 2465
2484 netif_start_queue(dev); 2466 netif_start_queue(dev);
2485 2467
2486 sbmac_set_rx_mode(dev); 2468 sbmac_set_rx_mode(dev);
2487 2469
2488 /* Set the timer to check for link beat. */ 2470 /* Set the timer to check for link beat. */
2489 init_timer(&sc->sbm_timer); 2471 init_timer(&sc->sbm_timer);
2490 sc->sbm_timer.expires = jiffies + 2 * HZ/100; 2472 sc->sbm_timer.expires = jiffies + 2 * HZ/100;
2491 sc->sbm_timer.data = (unsigned long)dev; 2473 sc->sbm_timer.data = (unsigned long)dev;
2492 sc->sbm_timer.function = &sbmac_timer; 2474 sc->sbm_timer.function = &sbmac_timer;
2493 add_timer(&sc->sbm_timer); 2475 add_timer(&sc->sbm_timer);
2494 2476
2495 return 0; 2477 return 0;
2496} 2478}
2497 2479
2480static int sbmac_mii_probe(struct net_device *dev)
2481{
2482 int i;
2483 struct sbmac_softc *s = netdev_priv(dev);
2484 u16 bmsr, id1, id2;
2485 u32 vendor, device;
2486
2487 for (i=1; i<31; i++) {
2488 bmsr = sbmac_mii_read(s, i, MII_BMSR);
2489 if (bmsr != 0) {
2490 s->sbm_phys[0] = i;
2491 id1 = sbmac_mii_read(s, i, MII_PHYIDR1);
2492 id2 = sbmac_mii_read(s, i, MII_PHYIDR2);
2493 vendor = ((u32)id1 << 6) | ((id2 >> 10) & 0x3f);
2494 device = (id2 >> 4) & 0x3f;
2495
2496 printk(KERN_INFO "%s: found phy %d, vendor %06x part %02x\n",
2497 dev->name, i, vendor, device);
2498 return i;
2499 }
2500 }
2501 return -1;
2502}
2498 2503
2499 2504
2500static int sbmac_mii_poll(struct sbmac_softc *s,int noisy) 2505static int sbmac_mii_poll(struct sbmac_softc *s,int noisy)
@@ -2609,20 +2614,20 @@ static void sbmac_timer(unsigned long data)
2609 int mii_status; 2614 int mii_status;
2610 2615
2611 spin_lock_irq (&sc->sbm_lock); 2616 spin_lock_irq (&sc->sbm_lock);
2612 2617
2613 /* make IFF_RUNNING follow the MII status bit "Link established" */ 2618 /* make IFF_RUNNING follow the MII status bit "Link established" */
2614 mii_status = sbmac_mii_read(sc, sc->sbm_phys[0], MII_BMSR); 2619 mii_status = sbmac_mii_read(sc, sc->sbm_phys[0], MII_BMSR);
2615 2620
2616 if ( (mii_status & BMSR_LINKSTAT) != (sc->sbm_phy_oldlinkstat) ) { 2621 if ( (mii_status & BMSR_LINKSTAT) != (sc->sbm_phy_oldlinkstat) ) {
2617 sc->sbm_phy_oldlinkstat = mii_status & BMSR_LINKSTAT; 2622 sc->sbm_phy_oldlinkstat = mii_status & BMSR_LINKSTAT;
2618 if (mii_status & BMSR_LINKSTAT) { 2623 if (mii_status & BMSR_LINKSTAT) {
2619 netif_carrier_on(dev); 2624 netif_carrier_on(dev);
2620 } 2625 }
2621 else { 2626 else {
2622 netif_carrier_off(dev); 2627 netif_carrier_off(dev);
2623 } 2628 }
2624 } 2629 }
2625 2630
2626 /* 2631 /*
2627 * Poll the PHY to see what speed we should be running at 2632 * Poll the PHY to see what speed we should be running at
2628 */ 2633 */
@@ -2640,9 +2645,9 @@ static void sbmac_timer(unsigned long data)
2640 sbmac_channel_start(sc); 2645 sbmac_channel_start(sc);
2641 } 2646 }
2642 } 2647 }
2643 2648
2644 spin_unlock_irq (&sc->sbm_lock); 2649 spin_unlock_irq (&sc->sbm_lock);
2645 2650
2646 sc->sbm_timer.expires = jiffies + next_tick; 2651 sc->sbm_timer.expires = jiffies + next_tick;
2647 add_timer(&sc->sbm_timer); 2652 add_timer(&sc->sbm_timer);
2648} 2653}
@@ -2651,13 +2656,13 @@ static void sbmac_timer(unsigned long data)
2651static void sbmac_tx_timeout (struct net_device *dev) 2656static void sbmac_tx_timeout (struct net_device *dev)
2652{ 2657{
2653 struct sbmac_softc *sc = netdev_priv(dev); 2658 struct sbmac_softc *sc = netdev_priv(dev);
2654 2659
2655 spin_lock_irq (&sc->sbm_lock); 2660 spin_lock_irq (&sc->sbm_lock);
2656 2661
2657 2662
2658 dev->trans_start = jiffies; 2663 dev->trans_start = jiffies;
2659 sc->sbm_stats.tx_errors++; 2664 sc->sbm_stats.tx_errors++;
2660 2665
2661 spin_unlock_irq (&sc->sbm_lock); 2666 spin_unlock_irq (&sc->sbm_lock);
2662 2667
2663 printk (KERN_WARNING "%s: Transmit timed out\n",dev->name); 2668 printk (KERN_WARNING "%s: Transmit timed out\n",dev->name);
@@ -2670,13 +2675,13 @@ static struct net_device_stats *sbmac_get_stats(struct net_device *dev)
2670{ 2675{
2671 struct sbmac_softc *sc = netdev_priv(dev); 2676 struct sbmac_softc *sc = netdev_priv(dev);
2672 unsigned long flags; 2677 unsigned long flags;
2673 2678
2674 spin_lock_irqsave(&sc->sbm_lock, flags); 2679 spin_lock_irqsave(&sc->sbm_lock, flags);
2675 2680
2676 /* XXX update other stats here */ 2681 /* XXX update other stats here */
2677 2682
2678 spin_unlock_irqrestore(&sc->sbm_lock, flags); 2683 spin_unlock_irqrestore(&sc->sbm_lock, flags);
2679 2684
2680 return &sc->sbm_stats; 2685 return &sc->sbm_stats;
2681} 2686}
2682 2687
@@ -2693,8 +2698,8 @@ static void sbmac_set_rx_mode(struct net_device *dev)
2693 /* 2698 /*
2694 * Promiscuous changed. 2699 * Promiscuous changed.
2695 */ 2700 */
2696 2701
2697 if (dev->flags & IFF_PROMISC) { 2702 if (dev->flags & IFF_PROMISC) {
2698 /* Unconditionally log net taps. */ 2703 /* Unconditionally log net taps. */
2699 msg_flag = 1; 2704 msg_flag = 1;
2700 sbmac_promiscuous_mode(sc,1); 2705 sbmac_promiscuous_mode(sc,1);
@@ -2705,18 +2710,18 @@ static void sbmac_set_rx_mode(struct net_device *dev)
2705 } 2710 }
2706 } 2711 }
2707 spin_unlock_irqrestore(&sc->sbm_lock, flags); 2712 spin_unlock_irqrestore(&sc->sbm_lock, flags);
2708 2713
2709 if (msg_flag) { 2714 if (msg_flag) {
2710 printk(KERN_NOTICE "%s: Promiscuous mode %sabled.\n", 2715 printk(KERN_NOTICE "%s: Promiscuous mode %sabled.\n",
2711 dev->name,(msg_flag==1)?"en":"dis"); 2716 dev->name,(msg_flag==1)?"en":"dis");
2712 } 2717 }
2713 2718
2714 /* 2719 /*
2715 * Program the multicasts. Do this every time. 2720 * Program the multicasts. Do this every time.
2716 */ 2721 */
2717 2722
2718 sbmac_setmulti(sc); 2723 sbmac_setmulti(sc);
2719 2724
2720} 2725}
2721 2726
2722static int sbmac_mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 2727static int sbmac_mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
@@ -2725,10 +2730,10 @@ static int sbmac_mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2725 u16 *data = (u16 *)&rq->ifr_ifru; 2730 u16 *data = (u16 *)&rq->ifr_ifru;
2726 unsigned long flags; 2731 unsigned long flags;
2727 int retval; 2732 int retval;
2728 2733
2729 spin_lock_irqsave(&sc->sbm_lock, flags); 2734 spin_lock_irqsave(&sc->sbm_lock, flags);
2730 retval = 0; 2735 retval = 0;
2731 2736
2732 switch(cmd) { 2737 switch(cmd) {
2733 case SIOCDEVPRIVATE: /* Get the address of the PHY in use. */ 2738 case SIOCDEVPRIVATE: /* Get the address of the PHY in use. */
2734 data[0] = sc->sbm_phys[0] & 0x1f; 2739 data[0] = sc->sbm_phys[0] & 0x1f;
@@ -2750,7 +2755,7 @@ static int sbmac_mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2750 default: 2755 default:
2751 retval = -EOPNOTSUPP; 2756 retval = -EOPNOTSUPP;
2752 } 2757 }
2753 2758
2754 spin_unlock_irqrestore(&sc->sbm_lock, flags); 2759 spin_unlock_irqrestore(&sc->sbm_lock, flags);
2755 return retval; 2760 return retval;
2756} 2761}
@@ -2781,7 +2786,7 @@ static int sbmac_close(struct net_device *dev)
2781 2786
2782 sbdma_emptyring(&(sc->sbm_txdma)); 2787 sbdma_emptyring(&(sc->sbm_txdma));
2783 sbdma_emptyring(&(sc->sbm_rxdma)); 2788 sbdma_emptyring(&(sc->sbm_rxdma));
2784 2789
2785 return 0; 2790 return 0;
2786} 2791}
2787 2792
@@ -2793,13 +2798,13 @@ sbmac_setup_hwaddr(int chan,char *addr)
2793{ 2798{
2794 uint8_t eaddr[6]; 2799 uint8_t eaddr[6];
2795 uint64_t val; 2800 uint64_t val;
2796 sbmac_port_t port; 2801 unsigned long port;
2797 2802
2798 port = A_MAC_CHANNEL_BASE(chan); 2803 port = A_MAC_CHANNEL_BASE(chan);
2799 sbmac_parse_hwaddr(addr,eaddr); 2804 sbmac_parse_hwaddr(addr,eaddr);
2800 val = sbmac_addr2reg(eaddr); 2805 val = sbmac_addr2reg(eaddr);
2801 SBMAC_WRITECSR(IOADDR(port+R_MAC_ETHERNET_ADDR),val); 2806 __raw_writeq(val, IOADDR(port+R_MAC_ETHERNET_ADDR));
2802 val = SBMAC_READCSR(IOADDR(port+R_MAC_ETHERNET_ADDR)); 2807 val = __raw_readq(IOADDR(port+R_MAC_ETHERNET_ADDR));
2803} 2808}
2804#endif 2809#endif
2805 2810
@@ -2810,9 +2815,9 @@ sbmac_init_module(void)
2810{ 2815{
2811 int idx; 2816 int idx;
2812 struct net_device *dev; 2817 struct net_device *dev;
2813 sbmac_port_t port; 2818 unsigned long port;
2814 int chip_max_units; 2819 int chip_max_units;
2815 2820
2816 /* 2821 /*
2817 * For bringup when not using the firmware, we can pre-fill 2822 * For bringup when not using the firmware, we can pre-fill
2818 * the MAC addresses using the environment variables 2823 * the MAC addresses using the environment variables
@@ -2858,13 +2863,13 @@ sbmac_init_module(void)
2858 2863
2859 port = A_MAC_CHANNEL_BASE(idx); 2864 port = A_MAC_CHANNEL_BASE(idx);
2860 2865
2861 /* 2866 /*
2862 * The R_MAC_ETHERNET_ADDR register will be set to some nonzero 2867 * The R_MAC_ETHERNET_ADDR register will be set to some nonzero
2863 * value for us by the firmware if we're going to use this MAC. 2868 * value for us by the firmware if we're going to use this MAC.
2864 * If we find a zero, skip this MAC. 2869 * If we find a zero, skip this MAC.
2865 */ 2870 */
2866 2871
2867 sbmac_orig_hwaddr[idx] = SBMAC_READCSR(IOADDR(port+R_MAC_ETHERNET_ADDR)); 2872 sbmac_orig_hwaddr[idx] = __raw_readq(IOADDR(port+R_MAC_ETHERNET_ADDR));
2868 if (sbmac_orig_hwaddr[idx] == 0) { 2873 if (sbmac_orig_hwaddr[idx] == 0) {
2869 printk(KERN_DEBUG "sbmac: not configuring MAC at " 2874 printk(KERN_DEBUG "sbmac: not configuring MAC at "
2870 "%lx\n", port); 2875 "%lx\n", port);
@@ -2876,7 +2881,7 @@ sbmac_init_module(void)
2876 */ 2881 */
2877 2882
2878 dev = alloc_etherdev(sizeof(struct sbmac_softc)); 2883 dev = alloc_etherdev(sizeof(struct sbmac_softc));
2879 if (!dev) 2884 if (!dev)
2880 return -ENOMEM; /* return ENOMEM */ 2885 return -ENOMEM; /* return ENOMEM */
2881 2886
2882 printk(KERN_DEBUG "sbmac: configuring MAC at %lx\n", port); 2887 printk(KERN_DEBUG "sbmac: configuring MAC at %lx\n", port);
@@ -2886,8 +2891,7 @@ sbmac_init_module(void)
2886 dev->mem_end = 0; 2891 dev->mem_end = 0;
2887 if (sbmac_init(dev, idx)) { 2892 if (sbmac_init(dev, idx)) {
2888 port = A_MAC_CHANNEL_BASE(idx); 2893 port = A_MAC_CHANNEL_BASE(idx);
2889 SBMAC_WRITECSR(IOADDR(port+R_MAC_ETHERNET_ADDR), 2894 __raw_writeq(sbmac_orig_hwaddr[idx], IOADDR(port+R_MAC_ETHERNET_ADDR));
2890 sbmac_orig_hwaddr[idx]);
2891 free_netdev(dev); 2895 free_netdev(dev);
2892 continue; 2896 continue;
2893 } 2897 }
diff --git a/drivers/net/sgiseeq.c b/drivers/net/sgiseeq.c
index 9bc3b1c0dd6a..a4614df38a90 100644
--- a/drivers/net/sgiseeq.c
+++ b/drivers/net/sgiseeq.c
@@ -32,8 +32,6 @@
32 32
33#include "sgiseeq.h" 33#include "sgiseeq.h"
34 34
35static char *version = "sgiseeq.c: David S. Miller (dm@engr.sgi.com)\n";
36
37static char *sgiseeqstr = "SGI Seeq8003"; 35static char *sgiseeqstr = "SGI Seeq8003";
38 36
39/* 37/*
@@ -113,9 +111,9 @@ static struct net_device *root_sgiseeq_dev;
113 111
114static inline void hpc3_eth_reset(struct hpc3_ethregs *hregs) 112static inline void hpc3_eth_reset(struct hpc3_ethregs *hregs)
115{ 113{
116 hregs->rx_reset = HPC3_ERXRST_CRESET | HPC3_ERXRST_CLRIRQ; 114 hregs->reset = HPC3_ERST_CRESET | HPC3_ERST_CLRIRQ;
117 udelay(20); 115 udelay(20);
118 hregs->rx_reset = 0; 116 hregs->reset = 0;
119} 117}
120 118
121static inline void reset_hpc3_and_seeq(struct hpc3_ethregs *hregs, 119static inline void reset_hpc3_and_seeq(struct hpc3_ethregs *hregs,
@@ -252,7 +250,6 @@ void sgiseeq_dump_rings(void)
252 250
253#define TSTAT_INIT_SEEQ (SEEQ_TCMD_IPT|SEEQ_TCMD_I16|SEEQ_TCMD_IC|SEEQ_TCMD_IUF) 251#define TSTAT_INIT_SEEQ (SEEQ_TCMD_IPT|SEEQ_TCMD_I16|SEEQ_TCMD_IC|SEEQ_TCMD_IUF)
254#define TSTAT_INIT_EDLC ((TSTAT_INIT_SEEQ) | SEEQ_TCMD_RB2) 252#define TSTAT_INIT_EDLC ((TSTAT_INIT_SEEQ) | SEEQ_TCMD_RB2)
255#define RDMACFG_INIT (HPC3_ERXDCFG_FRXDC | HPC3_ERXDCFG_FEOP | HPC3_ERXDCFG_FIRQ)
256 253
257static int init_seeq(struct net_device *dev, struct sgiseeq_private *sp, 254static int init_seeq(struct net_device *dev, struct sgiseeq_private *sp,
258 struct sgiseeq_regs *sregs) 255 struct sgiseeq_regs *sregs)
@@ -274,8 +271,6 @@ static int init_seeq(struct net_device *dev, struct sgiseeq_private *sp,
274 sregs->tstat = TSTAT_INIT_SEEQ; 271 sregs->tstat = TSTAT_INIT_SEEQ;
275 } 272 }
276 273
277 hregs->rx_dconfig |= RDMACFG_INIT;
278
279 hregs->rx_ndptr = CPHYSADDR(sp->rx_desc); 274 hregs->rx_ndptr = CPHYSADDR(sp->rx_desc);
280 hregs->tx_ndptr = CPHYSADDR(sp->tx_desc); 275 hregs->tx_ndptr = CPHYSADDR(sp->tx_desc);
281 276
@@ -446,7 +441,7 @@ static irqreturn_t sgiseeq_interrupt(int irq, void *dev_id, struct pt_regs *regs
446 spin_lock(&sp->tx_lock); 441 spin_lock(&sp->tx_lock);
447 442
448 /* Ack the IRQ and set software state. */ 443 /* Ack the IRQ and set software state. */
449 hregs->rx_reset = HPC3_ERXRST_CLRIRQ; 444 hregs->reset = HPC3_ERST_CLRIRQ;
450 445
451 /* Always check for received packets. */ 446 /* Always check for received packets. */
452 sgiseeq_rx(dev, sp, hregs, sregs); 447 sgiseeq_rx(dev, sp, hregs, sregs);
@@ -493,11 +488,13 @@ static int sgiseeq_close(struct net_device *dev)
493{ 488{
494 struct sgiseeq_private *sp = netdev_priv(dev); 489 struct sgiseeq_private *sp = netdev_priv(dev);
495 struct sgiseeq_regs *sregs = sp->sregs; 490 struct sgiseeq_regs *sregs = sp->sregs;
491 unsigned int irq = dev->irq;
496 492
497 netif_stop_queue(dev); 493 netif_stop_queue(dev);
498 494
499 /* Shutdown the Seeq. */ 495 /* Shutdown the Seeq. */
500 reset_hpc3_and_seeq(sp->hregs, sregs); 496 reset_hpc3_and_seeq(sp->hregs, sregs);
497 free_irq(irq, dev);
501 498
502 return 0; 499 return 0;
503} 500}
@@ -644,7 +641,7 @@ static inline void setup_rx_ring(struct sgiseeq_rx_desc *buf, int nbufs)
644 641
645#define ALIGNED(x) ((((unsigned long)(x)) + 0xf) & ~(0xf)) 642#define ALIGNED(x) ((((unsigned long)(x)) + 0xf) & ~(0xf))
646 643
647static int sgiseeq_init(struct hpc3_regs* regs, int irq) 644static int sgiseeq_init(struct hpc3_regs* hpcregs, int irq)
648{ 645{
649 struct sgiseeq_init_block *sr; 646 struct sgiseeq_init_block *sr;
650 struct sgiseeq_private *sp; 647 struct sgiseeq_private *sp;
@@ -680,8 +677,8 @@ static int sgiseeq_init(struct hpc3_regs* regs, int irq)
680 gpriv = sp; 677 gpriv = sp;
681 gdev = dev; 678 gdev = dev;
682#endif 679#endif
683 sp->sregs = (struct sgiseeq_regs *) &hpc3c0->eth_ext[0]; 680 sp->sregs = (struct sgiseeq_regs *) &hpcregs->eth_ext[0];
684 sp->hregs = &hpc3c0->ethregs; 681 sp->hregs = &hpcregs->ethregs;
685 sp->name = sgiseeqstr; 682 sp->name = sgiseeqstr;
686 sp->mode = SEEQ_RCMD_RBCAST; 683 sp->mode = SEEQ_RCMD_RBCAST;
687 684
@@ -698,6 +695,11 @@ static int sgiseeq_init(struct hpc3_regs* regs, int irq)
698 setup_rx_ring(sp->rx_desc, SEEQ_RX_BUFFERS); 695 setup_rx_ring(sp->rx_desc, SEEQ_RX_BUFFERS);
699 setup_tx_ring(sp->tx_desc, SEEQ_TX_BUFFERS); 696 setup_tx_ring(sp->tx_desc, SEEQ_TX_BUFFERS);
700 697
698 /* Setup PIO and DMA transfer timing */
699 sp->hregs->pconfig = 0x161;
700 sp->hregs->dconfig = HPC3_EDCFG_FIRQ | HPC3_EDCFG_FEOP |
701 HPC3_EDCFG_FRXDC | HPC3_EDCFG_PTO | 0x026;
702
701 /* Reset the chip. */ 703 /* Reset the chip. */
702 hpc3_eth_reset(sp->hregs); 704 hpc3_eth_reset(sp->hregs);
703 705
@@ -724,7 +726,7 @@ static int sgiseeq_init(struct hpc3_regs* regs, int irq)
724 goto err_out_free_page; 726 goto err_out_free_page;
725 } 727 }
726 728
727 printk(KERN_INFO "%s: SGI Seeq8003 ", dev->name); 729 printk(KERN_INFO "%s: %s ", dev->name, sgiseeqstr);
728 for (i = 0; i < 6; i++) 730 for (i = 0; i < 6; i++)
729 printk("%2.2x%c", dev->dev_addr[i], i == 5 ? '\n' : ':'); 731 printk("%2.2x%c", dev->dev_addr[i], i == 5 ? '\n' : ':');
730 732
@@ -734,7 +736,7 @@ static int sgiseeq_init(struct hpc3_regs* regs, int irq)
734 return 0; 736 return 0;
735 737
736err_out_free_page: 738err_out_free_page:
737 free_page((unsigned long) sp); 739 free_page((unsigned long) sp->srings);
738err_out_free_dev: 740err_out_free_dev:
739 kfree(dev); 741 kfree(dev);
740 742
@@ -744,8 +746,6 @@ err_out:
744 746
745static int __init sgiseeq_probe(void) 747static int __init sgiseeq_probe(void)
746{ 748{
747 printk(version);
748
749 /* On board adapter on 1st HPC is always present */ 749 /* On board adapter on 1st HPC is always present */
750 return sgiseeq_init(hpc3c0, SGI_ENET_IRQ); 750 return sgiseeq_init(hpc3c0, SGI_ENET_IRQ);
751} 751}
@@ -754,15 +754,12 @@ static void __exit sgiseeq_exit(void)
754{ 754{
755 struct net_device *next, *dev; 755 struct net_device *next, *dev;
756 struct sgiseeq_private *sp; 756 struct sgiseeq_private *sp;
757 int irq;
758 757
759 for (dev = root_sgiseeq_dev; dev; dev = next) { 758 for (dev = root_sgiseeq_dev; dev; dev = next) {
760 sp = (struct sgiseeq_private *) netdev_priv(dev); 759 sp = (struct sgiseeq_private *) netdev_priv(dev);
761 next = sp->next_module; 760 next = sp->next_module;
762 irq = dev->irq;
763 unregister_netdev(dev); 761 unregister_netdev(dev);
764 free_irq(irq, dev); 762 free_page((unsigned long) sp->srings);
765 free_page((unsigned long) sp);
766 free_netdev(dev); 763 free_netdev(dev);
767 } 764 }
768} 765}
@@ -770,4 +767,6 @@ static void __exit sgiseeq_exit(void)
770module_init(sgiseeq_probe); 767module_init(sgiseeq_probe);
771module_exit(sgiseeq_exit); 768module_exit(sgiseeq_exit);
772 769
770MODULE_DESCRIPTION("SGI Seeq 8003 driver");
771MODULE_AUTHOR("Linux/MIPS Mailing List <linux-mips@linux-mips.org>");
773MODULE_LICENSE("GPL"); 772MODULE_LICENSE("GPL");
diff --git a/drivers/net/sis190.c b/drivers/net/sis190.c
index 92f75529eff8..478791e09bf7 100644
--- a/drivers/net/sis190.c
+++ b/drivers/net/sis190.c
@@ -842,7 +842,7 @@ static void sis190_set_rx_mode(struct net_device *dev)
842 for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count; 842 for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
843 i++, mclist = mclist->next) { 843 i++, mclist = mclist->next) {
844 int bit_nr = 844 int bit_nr =
845 ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26; 845 ether_crc(ETH_ALEN, mclist->dmi_addr) & 0x3f;
846 mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); 846 mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31);
847 rx_mode |= AcceptMulticast; 847 rx_mode |= AcceptMulticast;
848 } 848 }
diff --git a/drivers/net/sis900.c b/drivers/net/sis900.c
index 23b713c700b3..1d4d88680db1 100644
--- a/drivers/net/sis900.c
+++ b/drivers/net/sis900.c
@@ -1696,15 +1696,20 @@ static int sis900_rx(struct net_device *net_dev)
1696 long ioaddr = net_dev->base_addr; 1696 long ioaddr = net_dev->base_addr;
1697 unsigned int entry = sis_priv->cur_rx % NUM_RX_DESC; 1697 unsigned int entry = sis_priv->cur_rx % NUM_RX_DESC;
1698 u32 rx_status = sis_priv->rx_ring[entry].cmdsts; 1698 u32 rx_status = sis_priv->rx_ring[entry].cmdsts;
1699 int rx_work_limit;
1699 1700
1700 if (netif_msg_rx_status(sis_priv)) 1701 if (netif_msg_rx_status(sis_priv))
1701 printk(KERN_DEBUG "sis900_rx, cur_rx:%4.4d, dirty_rx:%4.4d " 1702 printk(KERN_DEBUG "sis900_rx, cur_rx:%4.4d, dirty_rx:%4.4d "
1702 "status:0x%8.8x\n", 1703 "status:0x%8.8x\n",
1703 sis_priv->cur_rx, sis_priv->dirty_rx, rx_status); 1704 sis_priv->cur_rx, sis_priv->dirty_rx, rx_status);
1705 rx_work_limit = sis_priv->dirty_rx + NUM_RX_DESC - sis_priv->cur_rx;
1704 1706
1705 while (rx_status & OWN) { 1707 while (rx_status & OWN) {
1706 unsigned int rx_size; 1708 unsigned int rx_size;
1707 1709
1710 if (--rx_work_limit < 0)
1711 break;
1712
1708 rx_size = (rx_status & DSIZE) - CRC_SIZE; 1713 rx_size = (rx_status & DSIZE) - CRC_SIZE;
1709 1714
1710 if (rx_status & (ABORT|OVERRUN|TOOLONG|RUNT|RXISERR|CRCERR|FAERR)) { 1715 if (rx_status & (ABORT|OVERRUN|TOOLONG|RUNT|RXISERR|CRCERR|FAERR)) {
@@ -1732,9 +1737,11 @@ static int sis900_rx(struct net_device *net_dev)
1732 we are working on NULL sk_buff :-( */ 1737 we are working on NULL sk_buff :-( */
1733 if (sis_priv->rx_skbuff[entry] == NULL) { 1738 if (sis_priv->rx_skbuff[entry] == NULL) {
1734 if (netif_msg_rx_err(sis_priv)) 1739 if (netif_msg_rx_err(sis_priv))
1735 printk(KERN_INFO "%s: NULL pointer " 1740 printk(KERN_WARNING "%s: NULL pointer "
1736 "encountered in Rx ring, skipping\n", 1741 "encountered in Rx ring\n"
1737 net_dev->name); 1742 "cur_rx:%4.4d, dirty_rx:%4.4d\n",
1743 net_dev->name, sis_priv->cur_rx,
1744 sis_priv->dirty_rx);
1738 break; 1745 break;
1739 } 1746 }
1740 1747
@@ -1770,6 +1777,7 @@ static int sis900_rx(struct net_device *net_dev)
1770 sis_priv->rx_ring[entry].cmdsts = 0; 1777 sis_priv->rx_ring[entry].cmdsts = 0;
1771 sis_priv->rx_ring[entry].bufptr = 0; 1778 sis_priv->rx_ring[entry].bufptr = 0;
1772 sis_priv->stats.rx_dropped++; 1779 sis_priv->stats.rx_dropped++;
1780 sis_priv->cur_rx++;
1773 break; 1781 break;
1774 } 1782 }
1775 skb->dev = net_dev; 1783 skb->dev = net_dev;
@@ -1787,7 +1795,7 @@ static int sis900_rx(struct net_device *net_dev)
1787 1795
1788 /* refill the Rx buffer, what if the rate of refilling is slower 1796 /* refill the Rx buffer, what if the rate of refilling is slower
1789 * than consuming ?? */ 1797 * than consuming ?? */
1790 for (;sis_priv->cur_rx - sis_priv->dirty_rx > 0; sis_priv->dirty_rx++) { 1798 for (; sis_priv->cur_rx != sis_priv->dirty_rx; sis_priv->dirty_rx++) {
1791 struct sk_buff *skb; 1799 struct sk_buff *skb;
1792 1800
1793 entry = sis_priv->dirty_rx % NUM_RX_DESC; 1801 entry = sis_priv->dirty_rx % NUM_RX_DESC;
diff --git a/drivers/net/skfp/smt.c b/drivers/net/skfp/smt.c
index f17c05cbe44b..99a776a51fb5 100644
--- a/drivers/net/skfp/smt.c
+++ b/drivers/net/skfp/smt.c
@@ -1896,7 +1896,7 @@ void smt_swap_para(struct smt_header *sm, int len, int direction)
1896 1896
1897static void smt_string_swap(char *data, const char *format, int len) 1897static void smt_string_swap(char *data, const char *format, int len)
1898{ 1898{
1899 const char *open_paren = 0 ; 1899 const char *open_paren = NULL ;
1900 int x ; 1900 int x ;
1901 1901
1902 while (len > 0 && *format) { 1902 while (len > 0 && *format) {
diff --git a/drivers/net/skge.c b/drivers/net/skge.c
index c2e6484ef138..572f121b1f4e 100644
--- a/drivers/net/skge.c
+++ b/drivers/net/skge.c
@@ -730,6 +730,7 @@ static struct ethtool_ops skge_ethtool_ops = {
730 .phys_id = skge_phys_id, 730 .phys_id = skge_phys_id,
731 .get_stats_count = skge_get_stats_count, 731 .get_stats_count = skge_get_stats_count,
732 .get_ethtool_stats = skge_get_ethtool_stats, 732 .get_ethtool_stats = skge_get_ethtool_stats,
733 .get_perm_addr = ethtool_op_get_perm_addr,
733}; 734};
734 735
735/* 736/*
@@ -3096,6 +3097,7 @@ static struct net_device *skge_devinit(struct skge_hw *hw, int port,
3096 3097
3097 /* read the mac address */ 3098 /* read the mac address */
3098 memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port*8, ETH_ALEN); 3099 memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port*8, ETH_ALEN);
3100 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
3099 3101
3100 /* device is off until link detection */ 3102 /* device is off until link detection */
3101 netif_carrier_off(dev); 3103 netif_carrier_off(dev);
diff --git a/drivers/net/smc91x.c b/drivers/net/smc91x.c
index 1438fdd20826..c573bb351d4c 100644
--- a/drivers/net/smc91x.c
+++ b/drivers/net/smc91x.c
@@ -1983,6 +1983,10 @@ static int __init smc_probe(struct net_device *dev, void __iomem *ioaddr)
1983 if (lp->version >= (CHIP_91100 << 4)) 1983 if (lp->version >= (CHIP_91100 << 4))
1984 smc_phy_detect(dev); 1984 smc_phy_detect(dev);
1985 1985
1986 /* then shut everything down to save power */
1987 smc_shutdown(dev);
1988 smc_phy_powerdown(dev);
1989
1986 /* Set default parameters */ 1990 /* Set default parameters */
1987 lp->msg_enable = NETIF_MSG_LINK; 1991 lp->msg_enable = NETIF_MSG_LINK;
1988 lp->ctl_rfduplx = 0; 1992 lp->ctl_rfduplx = 0;
@@ -2291,11 +2295,11 @@ static int smc_drv_remove(struct device *dev)
2291 return 0; 2295 return 0;
2292} 2296}
2293 2297
2294static int smc_drv_suspend(struct device *dev, pm_message_t state, u32 level) 2298static int smc_drv_suspend(struct device *dev, pm_message_t state)
2295{ 2299{
2296 struct net_device *ndev = dev_get_drvdata(dev); 2300 struct net_device *ndev = dev_get_drvdata(dev);
2297 2301
2298 if (ndev && level == SUSPEND_DISABLE) { 2302 if (ndev) {
2299 if (netif_running(ndev)) { 2303 if (netif_running(ndev)) {
2300 netif_device_detach(ndev); 2304 netif_device_detach(ndev);
2301 smc_shutdown(ndev); 2305 smc_shutdown(ndev);
@@ -2305,12 +2309,12 @@ static int smc_drv_suspend(struct device *dev, pm_message_t state, u32 level)
2305 return 0; 2309 return 0;
2306} 2310}
2307 2311
2308static int smc_drv_resume(struct device *dev, u32 level) 2312static int smc_drv_resume(struct device *dev)
2309{ 2313{
2310 struct platform_device *pdev = to_platform_device(dev); 2314 struct platform_device *pdev = to_platform_device(dev);
2311 struct net_device *ndev = dev_get_drvdata(dev); 2315 struct net_device *ndev = dev_get_drvdata(dev);
2312 2316
2313 if (ndev && level == RESUME_ENABLE) { 2317 if (ndev) {
2314 struct smc_local *lp = netdev_priv(ndev); 2318 struct smc_local *lp = netdev_priv(ndev);
2315 smc_enable_device(pdev); 2319 smc_enable_device(pdev);
2316 if (netif_running(ndev)) { 2320 if (netif_running(ndev)) {
diff --git a/drivers/net/smc91x.h b/drivers/net/smc91x.h
index ac9ce6509eee..817f200742c3 100644
--- a/drivers/net/smc91x.h
+++ b/drivers/net/smc91x.h
@@ -230,12 +230,12 @@ SMC_outw(u16 val, void __iomem *ioaddr, int reg)
230#define SMC_CAN_USE_16BIT 1 230#define SMC_CAN_USE_16BIT 1
231#define SMC_CAN_USE_32BIT 0 231#define SMC_CAN_USE_32BIT 0
232 232
233#define SMC_inb(a, r) inb((a) + (r) - 0xa0000000) 233#define SMC_inb(a, r) inb((u32)a) + (r))
234#define SMC_inw(a, r) inw((a) + (r) - 0xa0000000) 234#define SMC_inw(a, r) inw(((u32)a) + (r))
235#define SMC_outb(v, a, r) outb(v, (a) + (r) - 0xa0000000) 235#define SMC_outb(v, a, r) outb(v, ((u32)a) + (r))
236#define SMC_outw(v, a, r) outw(v, (a) + (r) - 0xa0000000) 236#define SMC_outw(v, a, r) outw(v, ((u32)a) + (r))
237#define SMC_insw(a, r, p, l) insw((a) + (r) - 0xa0000000, p, l) 237#define SMC_insw(a, r, p, l) insw(((u32)a) + (r), p, l)
238#define SMC_outsw(a, r, p, l) outsw((a) + (r) - 0xa0000000, p, l) 238#define SMC_outsw(a, r, p, l) outsw(((u32)a) + (r), p, l)
239 239
240#define set_irq_type(irq, type) do {} while(0) 240#define set_irq_type(irq, type) do {} while(0)
241 241
diff --git a/drivers/net/starfire.c b/drivers/net/starfire.c
index efdb179ecc8c..38b2b0a3ce96 100644
--- a/drivers/net/starfire.c
+++ b/drivers/net/starfire.c
@@ -1091,8 +1091,10 @@ static int netdev_open(struct net_device *dev)
1091 rx_ring_size = sizeof(struct starfire_rx_desc) * RX_RING_SIZE; 1091 rx_ring_size = sizeof(struct starfire_rx_desc) * RX_RING_SIZE;
1092 np->queue_mem_size = tx_done_q_size + rx_done_q_size + tx_ring_size + rx_ring_size; 1092 np->queue_mem_size = tx_done_q_size + rx_done_q_size + tx_ring_size + rx_ring_size;
1093 np->queue_mem = pci_alloc_consistent(np->pci_dev, np->queue_mem_size, &np->queue_mem_dma); 1093 np->queue_mem = pci_alloc_consistent(np->pci_dev, np->queue_mem_size, &np->queue_mem_dma);
1094 if (np->queue_mem == 0) 1094 if (np->queue_mem == NULL) {
1095 free_irq(dev->irq, dev);
1095 return -ENOMEM; 1096 return -ENOMEM;
1097 }
1096 1098
1097 np->tx_done_q = np->queue_mem; 1099 np->tx_done_q = np->queue_mem;
1098 np->tx_done_q_dma = np->queue_mem_dma; 1100 np->tx_done_q_dma = np->queue_mem_dma;
diff --git a/drivers/net/sunbmac.c b/drivers/net/sunbmac.c
index f88f5e32b714..cfaf47c63c58 100644
--- a/drivers/net/sunbmac.c
+++ b/drivers/net/sunbmac.c
@@ -214,7 +214,8 @@ static void bigmac_init_rings(struct bigmac *bp, int from_irq)
214{ 214{
215 struct bmac_init_block *bb = bp->bmac_block; 215 struct bmac_init_block *bb = bp->bmac_block;
216 struct net_device *dev = bp->dev; 216 struct net_device *dev = bp->dev;
217 int i, gfp_flags = GFP_KERNEL; 217 int i;
218 gfp_t gfp_flags = GFP_KERNEL;
218 219
219 if (from_irq || in_interrupt()) 220 if (from_irq || in_interrupt())
220 gfp_flags = GFP_ATOMIC; 221 gfp_flags = GFP_ATOMIC;
diff --git a/drivers/net/sunbmac.h b/drivers/net/sunbmac.h
index 5674003fc38a..b0dbc5187143 100644
--- a/drivers/net/sunbmac.h
+++ b/drivers/net/sunbmac.h
@@ -339,7 +339,7 @@ struct bigmac {
339#define ALIGNED_RX_SKB_ADDR(addr) \ 339#define ALIGNED_RX_SKB_ADDR(addr) \
340 ((((unsigned long)(addr) + (64 - 1)) & ~(64 - 1)) - (unsigned long)(addr)) 340 ((((unsigned long)(addr) + (64 - 1)) & ~(64 - 1)) - (unsigned long)(addr))
341 341
342static inline struct sk_buff *big_mac_alloc_skb(unsigned int length, int gfp_flags) 342static inline struct sk_buff *big_mac_alloc_skb(unsigned int length, gfp_t gfp_flags)
343{ 343{
344 struct sk_buff *skb; 344 struct sk_buff *skb;
345 345
diff --git a/drivers/net/sundance.c b/drivers/net/sundance.c
index d500a5771dbc..0ab9c38b4a34 100644
--- a/drivers/net/sundance.c
+++ b/drivers/net/sundance.c
@@ -80,7 +80,7 @@
80 I/O access could affect performance in ARM-based system 80 I/O access could affect performance in ARM-based system
81 - Add Linux software VLAN support 81 - Add Linux software VLAN support
82 82
83 Version LK1.08 (D-Link): 83 Version LK1.08 (Philippe De Muyter phdm@macqel.be):
84 - Fix bug of custom mac address 84 - Fix bug of custom mac address
85 (StationAddr register only accept word write) 85 (StationAddr register only accept word write)
86 86
@@ -91,11 +91,14 @@
91 Version LK1.09a (ICPlus): 91 Version LK1.09a (ICPlus):
92 - Add the delay time in reading the contents of EEPROM 92 - Add the delay time in reading the contents of EEPROM
93 93
94 Version LK1.10 (Philippe De Muyter phdm@macqel.be):
95 - Make 'unblock interface after Tx underrun' work
96
94*/ 97*/
95 98
96#define DRV_NAME "sundance" 99#define DRV_NAME "sundance"
97#define DRV_VERSION "1.01+LK1.09a" 100#define DRV_VERSION "1.01+LK1.10"
98#define DRV_RELDATE "10-Jul-2003" 101#define DRV_RELDATE "28-Oct-2005"
99 102
100 103
101/* The user-configurable values. 104/* The user-configurable values.
@@ -263,8 +266,10 @@ IV. Notes
263IVb. References 266IVb. References
264 267
265The Sundance ST201 datasheet, preliminary version. 268The Sundance ST201 datasheet, preliminary version.
266http://cesdis.gsfc.nasa.gov/linux/misc/100mbps.html 269The Kendin KS8723 datasheet, preliminary version.
267http://cesdis.gsfc.nasa.gov/linux/misc/NWay.html 270The ICplus IP100 datasheet, preliminary version.
271http://www.scyld.com/expert/100mbps.html
272http://www.scyld.com/expert/NWay.html
268 273
269IVc. Errata 274IVc. Errata
270 275
@@ -500,6 +505,25 @@ static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
500static int netdev_close(struct net_device *dev); 505static int netdev_close(struct net_device *dev);
501static struct ethtool_ops ethtool_ops; 506static struct ethtool_ops ethtool_ops;
502 507
508static void sundance_reset(struct net_device *dev, unsigned long reset_cmd)
509{
510 struct netdev_private *np = netdev_priv(dev);
511 void __iomem *ioaddr = np->base + ASICCtrl;
512 int countdown;
513
514 /* ST201 documentation states ASICCtrl is a 32bit register */
515 iowrite32 (reset_cmd | ioread32 (ioaddr), ioaddr);
516 /* ST201 documentation states reset can take up to 1 ms */
517 countdown = 10 + 1;
518 while (ioread32 (ioaddr) & (ResetBusy << 16)) {
519 if (--countdown == 0) {
520 printk(KERN_WARNING "%s : reset not completed !!\n", dev->name);
521 break;
522 }
523 udelay(100);
524 }
525}
526
503static int __devinit sundance_probe1 (struct pci_dev *pdev, 527static int __devinit sundance_probe1 (struct pci_dev *pdev,
504 const struct pci_device_id *ent) 528 const struct pci_device_id *ent)
505{ 529{
@@ -518,6 +542,7 @@ static int __devinit sundance_probe1 (struct pci_dev *pdev,
518#else 542#else
519 int bar = 1; 543 int bar = 1;
520#endif 544#endif
545 int phy, phy_idx = 0;
521 546
522 547
523/* when built into the kernel, we only print version if device is found */ 548/* when built into the kernel, we only print version if device is found */
@@ -549,6 +574,7 @@ static int __devinit sundance_probe1 (struct pci_dev *pdev,
549 for (i = 0; i < 3; i++) 574 for (i = 0; i < 3; i++)
550 ((u16 *)dev->dev_addr)[i] = 575 ((u16 *)dev->dev_addr)[i] =
551 le16_to_cpu(eeprom_read(ioaddr, i + EEPROM_SA_OFFSET)); 576 le16_to_cpu(eeprom_read(ioaddr, i + EEPROM_SA_OFFSET));
577 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
552 578
553 dev->base_addr = (unsigned long)ioaddr; 579 dev->base_addr = (unsigned long)ioaddr;
554 dev->irq = irq; 580 dev->irq = irq;
@@ -605,33 +631,31 @@ static int __devinit sundance_probe1 (struct pci_dev *pdev,
605 printk("%2.2x:", dev->dev_addr[i]); 631 printk("%2.2x:", dev->dev_addr[i]);
606 printk("%2.2x, IRQ %d.\n", dev->dev_addr[i], irq); 632 printk("%2.2x, IRQ %d.\n", dev->dev_addr[i], irq);
607 633
608 if (1) { 634 np->phys[0] = 1; /* Default setting */
609 int phy, phy_idx = 0; 635 np->mii_preamble_required++;
610 np->phys[0] = 1; /* Default setting */ 636 for (phy = 1; phy <= 32 && phy_idx < MII_CNT; phy++) {
611 np->mii_preamble_required++; 637 int mii_status = mdio_read(dev, phy, MII_BMSR);
612 for (phy = 1; phy < 32 && phy_idx < MII_CNT; phy++) { 638 int phyx = phy & 0x1f;
613 int mii_status = mdio_read(dev, phy, MII_BMSR); 639 if (mii_status != 0xffff && mii_status != 0x0000) {
614 if (mii_status != 0xffff && mii_status != 0x0000) { 640 np->phys[phy_idx++] = phyx;
615 np->phys[phy_idx++] = phy; 641 np->mii_if.advertising = mdio_read(dev, phyx, MII_ADVERTISE);
616 np->mii_if.advertising = mdio_read(dev, phy, MII_ADVERTISE); 642 if ((mii_status & 0x0040) == 0)
617 if ((mii_status & 0x0040) == 0) 643 np->mii_preamble_required++;
618 np->mii_preamble_required++; 644 printk(KERN_INFO "%s: MII PHY found at address %d, status "
619 printk(KERN_INFO "%s: MII PHY found at address %d, status " 645 "0x%4.4x advertising %4.4x.\n",
620 "0x%4.4x advertising %4.4x.\n", 646 dev->name, phyx, mii_status, np->mii_if.advertising);
621 dev->name, phy, mii_status, np->mii_if.advertising);
622 }
623 }
624 np->mii_preamble_required--;
625
626 if (phy_idx == 0) {
627 printk(KERN_INFO "%s: No MII transceiver found, aborting. ASIC status %x\n",
628 dev->name, ioread32(ioaddr + ASICCtrl));
629 goto err_out_unregister;
630 } 647 }
648 }
649 np->mii_preamble_required--;
631 650
632 np->mii_if.phy_id = np->phys[0]; 651 if (phy_idx == 0) {
652 printk(KERN_INFO "%s: No MII transceiver found, aborting. ASIC status %x\n",
653 dev->name, ioread32(ioaddr + ASICCtrl));
654 goto err_out_unregister;
633 } 655 }
634 656
657 np->mii_if.phy_id = np->phys[0];
658
635 /* Parse override configuration */ 659 /* Parse override configuration */
636 np->an_enable = 1; 660 np->an_enable = 1;
637 if (card_idx < MAX_UNITS) { 661 if (card_idx < MAX_UNITS) {
@@ -692,7 +716,7 @@ static int __devinit sundance_probe1 (struct pci_dev *pdev,
692 /* Reset the chip to erase previous misconfiguration. */ 716 /* Reset the chip to erase previous misconfiguration. */
693 if (netif_msg_hw(np)) 717 if (netif_msg_hw(np))
694 printk("ASIC Control is %x.\n", ioread32(ioaddr + ASICCtrl)); 718 printk("ASIC Control is %x.\n", ioread32(ioaddr + ASICCtrl));
695 iowrite16(0x007f, ioaddr + ASICCtrl + 2); 719 iowrite16(0x00ff, ioaddr + ASICCtrl + 2);
696 if (netif_msg_hw(np)) 720 if (netif_msg_hw(np))
697 printk("ASIC Control is now %x.\n", ioread32(ioaddr + ASICCtrl)); 721 printk("ASIC Control is now %x.\n", ioread32(ioaddr + ASICCtrl));
698 722
@@ -1190,23 +1214,33 @@ static irqreturn_t intr_handler(int irq, void *dev_instance, struct pt_regs *rgs
1190 ("%s: Transmit status is %2.2x.\n", 1214 ("%s: Transmit status is %2.2x.\n",
1191 dev->name, tx_status); 1215 dev->name, tx_status);
1192 if (tx_status & 0x1e) { 1216 if (tx_status & 0x1e) {
1217 if (netif_msg_tx_err(np))
1218 printk("%s: Transmit error status %4.4x.\n",
1219 dev->name, tx_status);
1193 np->stats.tx_errors++; 1220 np->stats.tx_errors++;
1194 if (tx_status & 0x10) 1221 if (tx_status & 0x10)
1195 np->stats.tx_fifo_errors++; 1222 np->stats.tx_fifo_errors++;
1196 if (tx_status & 0x08) 1223 if (tx_status & 0x08)
1197 np->stats.collisions++; 1224 np->stats.collisions++;
1225 if (tx_status & 0x04)
1226 np->stats.tx_fifo_errors++;
1198 if (tx_status & 0x02) 1227 if (tx_status & 0x02)
1199 np->stats.tx_window_errors++; 1228 np->stats.tx_window_errors++;
1200 /* This reset has not been verified!. */ 1229 /*
1201 if (tx_status & 0x10) { /* Reset the Tx. */ 1230 ** This reset has been verified on
1202 np->stats.tx_fifo_errors++; 1231 ** DFE-580TX boards ! phdm@macqel.be.
1203 spin_lock(&np->lock); 1232 */
1204 reset_tx(dev); 1233 if (tx_status & 0x10) { /* TxUnderrun */
1205 spin_unlock(&np->lock); 1234 unsigned short txthreshold;
1235
1236 txthreshold = ioread16 (ioaddr + TxStartThresh);
1237 /* Restart Tx FIFO and transmitter */
1238 sundance_reset(dev, (NetworkReset|FIFOReset|TxReset) << 16);
1239 iowrite16 (txthreshold, ioaddr + TxStartThresh);
1240 /* No need to reset the Tx pointer here */
1206 } 1241 }
1207 if (tx_status & 0x1e) /* Restart the Tx. */ 1242 /* Restart the Tx. */
1208 iowrite16 (TxEnable, 1243 iowrite16 (TxEnable, ioaddr + MACCtrl1);
1209 ioaddr + MACCtrl1);
1210 } 1244 }
1211 /* Yup, this is a documentation bug. It cost me *hours*. */ 1245 /* Yup, this is a documentation bug. It cost me *hours*. */
1212 iowrite16 (0, ioaddr + TxStatus); 1246 iowrite16 (0, ioaddr + TxStatus);
@@ -1619,6 +1653,7 @@ static struct ethtool_ops ethtool_ops = {
1619 .get_link = get_link, 1653 .get_link = get_link,
1620 .get_msglevel = get_msglevel, 1654 .get_msglevel = get_msglevel,
1621 .set_msglevel = set_msglevel, 1655 .set_msglevel = set_msglevel,
1656 .get_perm_addr = ethtool_op_get_perm_addr,
1622}; 1657};
1623 1658
1624static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 1659static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index 1802c3b48799..1828a6bf8458 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -37,6 +37,7 @@
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#include <linux/prefetch.h>
40#include <linux/dma-mapping.h>
40 41
41#include <net/checksum.h> 42#include <net/checksum.h>
42 43
@@ -67,8 +68,8 @@
67 68
68#define DRV_MODULE_NAME "tg3" 69#define DRV_MODULE_NAME "tg3"
69#define PFX DRV_MODULE_NAME ": " 70#define PFX DRV_MODULE_NAME ": "
70#define DRV_MODULE_VERSION "3.42" 71#define DRV_MODULE_VERSION "3.43"
71#define DRV_MODULE_RELDATE "Oct 3, 2005" 72#define DRV_MODULE_RELDATE "Oct 24, 2005"
72 73
73#define TG3_DEF_MAC_MODE 0 74#define TG3_DEF_MAC_MODE 0
74#define TG3_DEF_RX_MODE 0 75#define TG3_DEF_RX_MODE 0
@@ -219,6 +220,10 @@ static struct pci_device_id tg3_pci_tbl[] = {
219 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, 220 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
220 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F, 221 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F,
221 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, 222 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
223 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714,
224 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
225 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715,
226 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
222 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780, 227 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780,
223 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, 228 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
224 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S, 229 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S,
@@ -466,6 +471,15 @@ static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val)
466 spin_unlock_irqrestore(&tp->indirect_lock, flags); 471 spin_unlock_irqrestore(&tp->indirect_lock, flags);
467} 472}
468 473
474static void tg3_write_mem_fast(struct tg3 *tp, u32 off, u32 val)
475{
476 /* If no workaround is needed, write to mem space directly */
477 if (tp->write32 != tg3_write_indirect_reg32)
478 tw32(NIC_SRAM_WIN_BASE + off, val);
479 else
480 tg3_write_mem(tp, off, val);
481}
482
469static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val) 483static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val)
470{ 484{
471 unsigned long flags; 485 unsigned long flags;
@@ -570,7 +584,7 @@ static void tg3_switch_clocks(struct tg3 *tp)
570 u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL); 584 u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL);
571 u32 orig_clock_ctrl; 585 u32 orig_clock_ctrl;
572 586
573 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) 587 if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
574 return; 588 return;
575 589
576 orig_clock_ctrl = clock_ctrl; 590 orig_clock_ctrl = clock_ctrl;
@@ -1210,7 +1224,7 @@ static int tg3_set_power_state(struct tg3 *tp, int state)
1210 CLOCK_CTRL_ALTCLK | 1224 CLOCK_CTRL_ALTCLK |
1211 CLOCK_CTRL_PWRDOWN_PLL133); 1225 CLOCK_CTRL_PWRDOWN_PLL133);
1212 udelay(40); 1226 udelay(40);
1213 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) { 1227 } else if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
1214 /* do nothing */ 1228 /* do nothing */
1215 } else if (!((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) && 1229 } else if (!((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
1216 (tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) { 1230 (tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) {
@@ -3712,14 +3726,14 @@ static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp,
3712 dev->mtu = new_mtu; 3726 dev->mtu = new_mtu;
3713 3727
3714 if (new_mtu > ETH_DATA_LEN) { 3728 if (new_mtu > ETH_DATA_LEN) {
3715 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) { 3729 if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
3716 tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE; 3730 tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
3717 ethtool_op_set_tso(dev, 0); 3731 ethtool_op_set_tso(dev, 0);
3718 } 3732 }
3719 else 3733 else
3720 tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE; 3734 tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
3721 } else { 3735 } else {
3722 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) 3736 if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
3723 tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE; 3737 tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE;
3724 tp->tg3_flags &= ~TG3_FLAG_JUMBO_RING_ENABLE; 3738 tp->tg3_flags &= ~TG3_FLAG_JUMBO_RING_ENABLE;
3725 } 3739 }
@@ -3850,7 +3864,7 @@ static void tg3_init_rings(struct tg3 *tp)
3850 memset(tp->tx_ring, 0, TG3_TX_RING_BYTES); 3864 memset(tp->tx_ring, 0, TG3_TX_RING_BYTES);
3851 3865
3852 tp->rx_pkt_buf_sz = RX_PKT_BUF_SZ; 3866 tp->rx_pkt_buf_sz = RX_PKT_BUF_SZ;
3853 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) && 3867 if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) &&
3854 (tp->dev->mtu > ETH_DATA_LEN)) 3868 (tp->dev->mtu > ETH_DATA_LEN))
3855 tp->rx_pkt_buf_sz = RX_JUMBO_PKT_BUF_SZ; 3869 tp->rx_pkt_buf_sz = RX_JUMBO_PKT_BUF_SZ;
3856 3870
@@ -3905,10 +3919,8 @@ static void tg3_init_rings(struct tg3 *tp)
3905 */ 3919 */
3906static void tg3_free_consistent(struct tg3 *tp) 3920static void tg3_free_consistent(struct tg3 *tp)
3907{ 3921{
3908 if (tp->rx_std_buffers) { 3922 kfree(tp->rx_std_buffers);
3909 kfree(tp->rx_std_buffers); 3923 tp->rx_std_buffers = NULL;
3910 tp->rx_std_buffers = NULL;
3911 }
3912 if (tp->rx_std) { 3924 if (tp->rx_std) {
3913 pci_free_consistent(tp->pdev, TG3_RX_RING_BYTES, 3925 pci_free_consistent(tp->pdev, TG3_RX_RING_BYTES,
3914 tp->rx_std, tp->rx_std_mapping); 3926 tp->rx_std, tp->rx_std_mapping);
@@ -4347,7 +4359,7 @@ static int tg3_chip_reset(struct tg3 *tp)
4347 val &= ~PCIX_CAPS_RELAXED_ORDERING; 4359 val &= ~PCIX_CAPS_RELAXED_ORDERING;
4348 pci_write_config_dword(tp->pdev, TG3PCI_X_CAPS, val); 4360 pci_write_config_dword(tp->pdev, TG3PCI_X_CAPS, val);
4349 4361
4350 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) { 4362 if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
4351 u32 val; 4363 u32 val;
4352 4364
4353 /* Chip reset on 5780 will reset MSI enable bit, 4365 /* Chip reset on 5780 will reset MSI enable bit,
@@ -6003,7 +6015,7 @@ static int tg3_reset_hw(struct tg3 *tp)
6003 tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK); 6015 tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK);
6004 6016
6005 if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) && 6017 if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
6006 (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5780)) 6018 !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
6007 limit = 8; 6019 limit = 8;
6008 else 6020 else
6009 limit = 16; 6021 limit = 16;
@@ -6191,14 +6203,16 @@ static void tg3_timer(unsigned long __opaque)
6191 tp->timer_counter = tp->timer_multiplier; 6203 tp->timer_counter = tp->timer_multiplier;
6192 } 6204 }
6193 6205
6194 /* Heartbeat is only sent once every 120 seconds. */ 6206 /* Heartbeat is only sent once every 2 seconds. */
6195 if (!--tp->asf_counter) { 6207 if (!--tp->asf_counter) {
6196 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) { 6208 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
6197 u32 val; 6209 u32 val;
6198 6210
6199 tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_ALIVE); 6211 tg3_write_mem_fast(tp, NIC_SRAM_FW_CMD_MBOX,
6200 tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4); 6212 FWCMD_NICDRV_ALIVE2);
6201 tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 3); 6213 tg3_write_mem_fast(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4);
6214 /* 5 seconds timeout */
6215 tg3_write_mem_fast(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5);
6202 val = tr32(GRC_RX_CPU_EVENT); 6216 val = tr32(GRC_RX_CPU_EVENT);
6203 val |= (1 << 14); 6217 val |= (1 << 14);
6204 tw32(GRC_RX_CPU_EVENT, val); 6218 tw32(GRC_RX_CPU_EVENT, val);
@@ -6409,7 +6423,7 @@ static int tg3_open(struct net_device *dev)
6409 tp->timer_counter = tp->timer_multiplier = 6423 tp->timer_counter = tp->timer_multiplier =
6410 (HZ / tp->timer_offset); 6424 (HZ / tp->timer_offset);
6411 tp->asf_counter = tp->asf_multiplier = 6425 tp->asf_counter = tp->asf_multiplier =
6412 ((HZ / tp->timer_offset) * 120); 6426 ((HZ / tp->timer_offset) * 2);
6413 6427
6414 init_timer(&tp->timer); 6428 init_timer(&tp->timer);
6415 tp->timer.expires = jiffies + tp->timer_offset; 6429 tp->timer.expires = jiffies + tp->timer_offset;
@@ -7237,7 +7251,7 @@ static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
7237 cmd->supported |= (SUPPORTED_1000baseT_Half | 7251 cmd->supported |= (SUPPORTED_1000baseT_Half |
7238 SUPPORTED_1000baseT_Full); 7252 SUPPORTED_1000baseT_Full);
7239 7253
7240 if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) 7254 if (!(tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
7241 cmd->supported |= (SUPPORTED_100baseT_Half | 7255 cmd->supported |= (SUPPORTED_100baseT_Half |
7242 SUPPORTED_100baseT_Full | 7256 SUPPORTED_100baseT_Full |
7243 SUPPORTED_10baseT_Half | 7257 SUPPORTED_10baseT_Half |
@@ -7264,7 +7278,7 @@ static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
7264{ 7278{
7265 struct tg3 *tp = netdev_priv(dev); 7279 struct tg3 *tp = netdev_priv(dev);
7266 7280
7267 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) { 7281 if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) {
7268 /* These are the only valid advertisement bits allowed. */ 7282 /* These are the only valid advertisement bits allowed. */
7269 if (cmd->autoneg == AUTONEG_ENABLE && 7283 if (cmd->autoneg == AUTONEG_ENABLE &&
7270 (cmd->advertising & ~(ADVERTISED_1000baseT_Half | 7284 (cmd->advertising & ~(ADVERTISED_1000baseT_Half |
@@ -7272,7 +7286,17 @@ static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
7272 ADVERTISED_Autoneg | 7286 ADVERTISED_Autoneg |
7273 ADVERTISED_FIBRE))) 7287 ADVERTISED_FIBRE)))
7274 return -EINVAL; 7288 return -EINVAL;
7275 } 7289 /* Fiber can only do SPEED_1000. */
7290 else if ((cmd->autoneg != AUTONEG_ENABLE) &&
7291 (cmd->speed != SPEED_1000))
7292 return -EINVAL;
7293 /* Copper cannot force SPEED_1000. */
7294 } else if ((cmd->autoneg != AUTONEG_ENABLE) &&
7295 (cmd->speed == SPEED_1000))
7296 return -EINVAL;
7297 else if ((cmd->speed == SPEED_1000) &&
7298 (tp->tg3_flags2 & TG3_FLAG_10_100_ONLY))
7299 return -EINVAL;
7276 7300
7277 tg3_full_lock(tp, 0); 7301 tg3_full_lock(tp, 0);
7278 7302
@@ -8380,7 +8404,7 @@ static void __devinit tg3_get_nvram_info(struct tg3 *tp)
8380 } 8404 }
8381 8405
8382 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) || 8406 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) ||
8383 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780)) { 8407 (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
8384 switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) { 8408 switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) {
8385 case FLASH_VENDOR_ATMEL_FLASH_BUFFERED: 8409 case FLASH_VENDOR_ATMEL_FLASH_BUFFERED:
8386 tp->nvram_jedecnum = JEDEC_ATMEL; 8410 tp->nvram_jedecnum = JEDEC_ATMEL;
@@ -8980,7 +9004,7 @@ static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp)
8980 9004
8981 tp->phy_id = eeprom_phy_id; 9005 tp->phy_id = eeprom_phy_id;
8982 if (eeprom_phy_serdes) { 9006 if (eeprom_phy_serdes) {
8983 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) 9007 if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)
8984 tp->tg3_flags2 |= TG3_FLG2_MII_SERDES; 9008 tp->tg3_flags2 |= TG3_FLG2_MII_SERDES;
8985 else 9009 else
8986 tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES; 9010 tp->tg3_flags2 |= TG3_FLG2_PHY_SERDES;
@@ -9393,8 +9417,11 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
9393 } 9417 }
9394 9418
9395 /* Find msi capability. */ 9419 /* Find msi capability. */
9396 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) 9420 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 ||
9421 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
9422 tp->tg3_flags2 |= TG3_FLG2_5780_CLASS;
9397 tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI); 9423 tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI);
9424 }
9398 9425
9399 /* Initialize misc host control in PCI block. */ 9426 /* Initialize misc host control in PCI block. */
9400 tp->misc_host_ctrl |= (misc_ctrl_reg & 9427 tp->misc_host_ctrl |= (misc_ctrl_reg &
@@ -9412,7 +9439,7 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
9412 9439
9413 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || 9440 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
9414 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || 9441 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
9415 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) 9442 (tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
9416 tp->tg3_flags2 |= TG3_FLG2_5750_PLUS; 9443 tp->tg3_flags2 |= TG3_FLG2_5750_PLUS;
9417 9444
9418 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) || 9445 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) ||
@@ -9607,7 +9634,7 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
9607 * ether_setup() via the alloc_etherdev() call 9634 * ether_setup() via the alloc_etherdev() call
9608 */ 9635 */
9609 if (tp->dev->mtu > ETH_DATA_LEN && 9636 if (tp->dev->mtu > ETH_DATA_LEN &&
9610 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5780) 9637 !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
9611 tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE; 9638 tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
9612 9639
9613 /* Determine WakeOnLan speed to use. */ 9640 /* Determine WakeOnLan speed to use. */
@@ -9830,7 +9857,7 @@ static int __devinit tg3_get_device_address(struct tg3 *tp)
9830 mac_offset = 0x7c; 9857 mac_offset = 0x7c;
9831 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 && 9858 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 &&
9832 !(tp->tg3_flags & TG3_FLG2_SUN_570X)) || 9859 !(tp->tg3_flags & TG3_FLG2_SUN_570X)) ||
9833 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) { 9860 (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) {
9834 if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) 9861 if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID)
9835 mac_offset = 0xcc; 9862 mac_offset = 0xcc;
9836 if (tg3_nvram_lock(tp)) 9863 if (tg3_nvram_lock(tp))
@@ -10148,6 +10175,9 @@ static int __devinit tg3_test_dma(struct tg3 *tp)
10148 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) { 10175 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) {
10149 /* 5780 always in PCIX mode */ 10176 /* 5780 always in PCIX mode */
10150 tp->dma_rwctrl |= 0x00144000; 10177 tp->dma_rwctrl |= 0x00144000;
10178 } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) {
10179 /* 5714 always in PCIX mode */
10180 tp->dma_rwctrl |= 0x00148000;
10151 } else { 10181 } else {
10152 tp->dma_rwctrl |= 0x001b000f; 10182 tp->dma_rwctrl |= 0x001b000f;
10153 } 10183 }
@@ -10347,6 +10377,7 @@ static char * __devinit tg3_phy_string(struct tg3 *tp)
10347 case PHY_ID_BCM5705: return "5705"; 10377 case PHY_ID_BCM5705: return "5705";
10348 case PHY_ID_BCM5750: return "5750"; 10378 case PHY_ID_BCM5750: return "5750";
10349 case PHY_ID_BCM5752: return "5752"; 10379 case PHY_ID_BCM5752: return "5752";
10380 case PHY_ID_BCM5714: return "5714";
10350 case PHY_ID_BCM5780: return "5780"; 10381 case PHY_ID_BCM5780: return "5780";
10351 case PHY_ID_BCM8002: return "8002/serdes"; 10382 case PHY_ID_BCM8002: return "8002/serdes";
10352 case 0: return "serdes"; 10383 case 0: return "serdes";
@@ -10492,17 +10523,17 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
10492 } 10523 }
10493 10524
10494 /* Configure DMA attributes. */ 10525 /* Configure DMA attributes. */
10495 err = pci_set_dma_mask(pdev, 0xffffffffffffffffULL); 10526 err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
10496 if (!err) { 10527 if (!err) {
10497 pci_using_dac = 1; 10528 pci_using_dac = 1;
10498 err = pci_set_consistent_dma_mask(pdev, 0xffffffffffffffffULL); 10529 err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
10499 if (err < 0) { 10530 if (err < 0) {
10500 printk(KERN_ERR PFX "Unable to obtain 64 bit DMA " 10531 printk(KERN_ERR PFX "Unable to obtain 64 bit DMA "
10501 "for consistent allocations\n"); 10532 "for consistent allocations\n");
10502 goto err_out_free_res; 10533 goto err_out_free_res;
10503 } 10534 }
10504 } else { 10535 } else {
10505 err = pci_set_dma_mask(pdev, 0xffffffffULL); 10536 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
10506 if (err) { 10537 if (err) {
10507 printk(KERN_ERR PFX "No usable DMA configuration, " 10538 printk(KERN_ERR PFX "No usable DMA configuration, "
10508 "aborting.\n"); 10539 "aborting.\n");
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
index 2e733c60bfa4..fb7e2a5f4a08 100644
--- a/drivers/net/tg3.h
+++ b/drivers/net/tg3.h
@@ -137,6 +137,7 @@
137#define ASIC_REV_5750 0x04 137#define ASIC_REV_5750 0x04
138#define ASIC_REV_5752 0x06 138#define ASIC_REV_5752 0x06
139#define ASIC_REV_5780 0x08 139#define ASIC_REV_5780 0x08
140#define ASIC_REV_5714 0x09
140#define GET_CHIP_REV(CHIP_REV_ID) ((CHIP_REV_ID) >> 8) 141#define GET_CHIP_REV(CHIP_REV_ID) ((CHIP_REV_ID) >> 8)
141#define CHIPREV_5700_AX 0x70 142#define CHIPREV_5700_AX 0x70
142#define CHIPREV_5700_BX 0x71 143#define CHIPREV_5700_BX 0x71
@@ -531,6 +532,8 @@
531#define MAC_SERDES_CFG_EDGE_SELECT 0x00001000 532#define MAC_SERDES_CFG_EDGE_SELECT 0x00001000
532#define MAC_SERDES_STAT 0x00000594 533#define MAC_SERDES_STAT 0x00000594
533/* 0x598 --> 0x5b0 unused */ 534/* 0x598 --> 0x5b0 unused */
535#define SERDES_RX_CTRL 0x000005b0 /* 5780/5714 only */
536#define SERDES_RX_SIG_DETECT 0x00000400
534#define SG_DIG_CTRL 0x000005b0 537#define SG_DIG_CTRL 0x000005b0
535#define SG_DIG_USING_HW_AUTONEG 0x80000000 538#define SG_DIG_USING_HW_AUTONEG 0x80000000
536#define SG_DIG_SOFT_RESET 0x40000000 539#define SG_DIG_SOFT_RESET 0x40000000
@@ -1329,6 +1332,8 @@
1329#define GRC_LCLCTRL_CLEARINT 0x00000002 1332#define GRC_LCLCTRL_CLEARINT 0x00000002
1330#define GRC_LCLCTRL_SETINT 0x00000004 1333#define GRC_LCLCTRL_SETINT 0x00000004
1331#define GRC_LCLCTRL_INT_ON_ATTN 0x00000008 1334#define GRC_LCLCTRL_INT_ON_ATTN 0x00000008
1335#define GRC_LCLCTRL_USE_SIG_DETECT 0x00000010 /* 5714/5780 only */
1336#define GRC_LCLCTRL_USE_EXT_SIG_DETECT 0x00000020 /* 5714/5780 only */
1332#define GRC_LCLCTRL_GPIO_INPUT3 0x00000020 1337#define GRC_LCLCTRL_GPIO_INPUT3 0x00000020
1333#define GRC_LCLCTRL_GPIO_OE3 0x00000040 1338#define GRC_LCLCTRL_GPIO_OE3 0x00000040
1334#define GRC_LCLCTRL_GPIO_OUTPUT3 0x00000080 1339#define GRC_LCLCTRL_GPIO_OUTPUT3 0x00000080
@@ -1507,6 +1512,7 @@
1507#define FWCMD_NICDRV_IPV6ADDR_CHG 0x00000004 1512#define FWCMD_NICDRV_IPV6ADDR_CHG 0x00000004
1508#define FWCMD_NICDRV_FIX_DMAR 0x00000005 1513#define FWCMD_NICDRV_FIX_DMAR 0x00000005
1509#define FWCMD_NICDRV_FIX_DMAW 0x00000006 1514#define FWCMD_NICDRV_FIX_DMAW 0x00000006
1515#define FWCMD_NICDRV_ALIVE2 0x0000000d
1510#define NIC_SRAM_FW_CMD_LEN_MBOX 0x00000b7c 1516#define NIC_SRAM_FW_CMD_LEN_MBOX 0x00000b7c
1511#define NIC_SRAM_FW_CMD_DATA_MBOX 0x00000b80 1517#define NIC_SRAM_FW_CMD_DATA_MBOX 0x00000b80
1512#define NIC_SRAM_FW_ASF_STATUS_MBOX 0x00000c00 1518#define NIC_SRAM_FW_ASF_STATUS_MBOX 0x00000c00
@@ -2175,6 +2181,7 @@ struct tg3 {
2175 TG3_FLG2_MII_SERDES) 2181 TG3_FLG2_MII_SERDES)
2176#define TG3_FLG2_PARALLEL_DETECT 0x01000000 2182#define TG3_FLG2_PARALLEL_DETECT 0x01000000
2177#define TG3_FLG2_ICH_WORKAROUND 0x02000000 2183#define TG3_FLG2_ICH_WORKAROUND 0x02000000
2184#define TG3_FLG2_5780_CLASS 0x04000000
2178 2185
2179 u32 split_mode_max_reqs; 2186 u32 split_mode_max_reqs;
2180#define SPLIT_MODE_5704_MAX_REQ 3 2187#define SPLIT_MODE_5704_MAX_REQ 3
@@ -2222,6 +2229,7 @@ struct tg3 {
2222#define PHY_ID_BCM5705 0x600081a0 2229#define PHY_ID_BCM5705 0x600081a0
2223#define PHY_ID_BCM5750 0x60008180 2230#define PHY_ID_BCM5750 0x60008180
2224#define PHY_ID_BCM5752 0x60008100 2231#define PHY_ID_BCM5752 0x60008100
2232#define PHY_ID_BCM5714 0x60008340
2225#define PHY_ID_BCM5780 0x60008350 2233#define PHY_ID_BCM5780 0x60008350
2226#define PHY_ID_BCM8002 0x60010140 2234#define PHY_ID_BCM8002 0x60010140
2227#define PHY_ID_INVALID 0xffffffff 2235#define PHY_ID_INVALID 0xffffffff
@@ -2246,8 +2254,8 @@ struct tg3 {
2246 (X) == PHY_ID_BCM5411 || (X) == PHY_ID_BCM5701 || \ 2254 (X) == PHY_ID_BCM5411 || (X) == PHY_ID_BCM5701 || \
2247 (X) == PHY_ID_BCM5703 || (X) == PHY_ID_BCM5704 || \ 2255 (X) == PHY_ID_BCM5703 || (X) == PHY_ID_BCM5704 || \
2248 (X) == PHY_ID_BCM5705 || (X) == PHY_ID_BCM5750 || \ 2256 (X) == PHY_ID_BCM5705 || (X) == PHY_ID_BCM5750 || \
2249 (X) == PHY_ID_BCM5752 || (X) == PHY_ID_BCM5780 || \ 2257 (X) == PHY_ID_BCM5752 || (X) == PHY_ID_BCM5714 || \
2250 (X) == PHY_ID_BCM8002) 2258 (X) == PHY_ID_BCM5780 || (X) == PHY_ID_BCM8002)
2251 2259
2252 struct tg3_hw_stats *hw_stats; 2260 struct tg3_hw_stats *hw_stats;
2253 dma_addr_t stats_mapping; 2261 dma_addr_t stats_mapping;
diff --git a/drivers/net/tokenring/ibmtr.c b/drivers/net/tokenring/ibmtr.c
index 32057e65808b..9f491563944e 100644
--- a/drivers/net/tokenring/ibmtr.c
+++ b/drivers/net/tokenring/ibmtr.c
@@ -318,7 +318,7 @@ static void ibmtr_cleanup_card(struct net_device *dev)
318 if (dev->base_addr) { 318 if (dev->base_addr) {
319 outb(0,dev->base_addr+ADAPTRESET); 319 outb(0,dev->base_addr+ADAPTRESET);
320 320
321 schedule_timeout(TR_RST_TIME); /* wait 50ms */ 321 schedule_timeout_uninterruptible(TR_RST_TIME); /* wait 50ms */
322 322
323 outb(0,dev->base_addr+ADAPTRESETREL); 323 outb(0,dev->base_addr+ADAPTRESETREL);
324 } 324 }
@@ -854,8 +854,7 @@ static int tok_init_card(struct net_device *dev)
854 writeb(~INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_EVEN); 854 writeb(~INT_ENABLE, ti->mmio + ACA_OFFSET + ACA_RESET + ISRP_EVEN);
855 outb(0, PIOaddr + ADAPTRESET); 855 outb(0, PIOaddr + ADAPTRESET);
856 856
857 current->state=TASK_UNINTERRUPTIBLE; 857 schedule_timeout_uninterruptible(TR_RST_TIME); /* wait 50ms */
858 schedule_timeout(TR_RST_TIME); /* wait 50ms */
859 858
860 outb(0, PIOaddr + ADAPTRESETREL); 859 outb(0, PIOaddr + ADAPTRESETREL);
861#ifdef ENABLE_PAGING 860#ifdef ENABLE_PAGING
@@ -903,8 +902,8 @@ static int tok_open(struct net_device *dev)
903 DPRINTK("Adapter is up and running\n"); 902 DPRINTK("Adapter is up and running\n");
904 return 0; 903 return 0;
905 } 904 }
906 current->state=TASK_INTERRUPTIBLE; 905 i=schedule_timeout_interruptible(TR_RETRY_INTERVAL);
907 i=schedule_timeout(TR_RETRY_INTERVAL); /* wait 30 seconds */ 906 /* wait 30 seconds */
908 if(i!=0) break; /*prob. a signal, like the i>24*HZ case above */ 907 if(i!=0) break; /*prob. a signal, like the i>24*HZ case above */
909 } 908 }
910 outb(0, dev->base_addr + ADAPTRESET);/* kill pending interrupts*/ 909 outb(0, dev->base_addr + ADAPTRESET);/* kill pending interrupts*/
diff --git a/drivers/net/tokenring/olympic.c b/drivers/net/tokenring/olympic.c
index 9e7923192a49..05477d24fd49 100644
--- a/drivers/net/tokenring/olympic.c
+++ b/drivers/net/tokenring/olympic.c
@@ -1101,7 +1101,7 @@ static int olympic_close(struct net_device *dev)
1101 1101
1102 while(olympic_priv->srb_queued) { 1102 while(olympic_priv->srb_queued) {
1103 1103
1104 t = schedule_timeout(60*HZ); 1104 t = schedule_timeout_interruptible(60*HZ);
1105 1105
1106 if(signal_pending(current)) { 1106 if(signal_pending(current)) {
1107 printk(KERN_WARNING "%s: SRB timed out.\n",dev->name); 1107 printk(KERN_WARNING "%s: SRB timed out.\n",dev->name);
diff --git a/drivers/net/tokenring/tms380tr.c b/drivers/net/tokenring/tms380tr.c
index 2e39bf1f7462..c1925590a0e1 100644
--- a/drivers/net/tokenring/tms380tr.c
+++ b/drivers/net/tokenring/tms380tr.c
@@ -1243,8 +1243,7 @@ void tms380tr_wait(unsigned long time)
1243 1243
1244 tmp = jiffies + time/(1000000/HZ); 1244 tmp = jiffies + time/(1000000/HZ);
1245 do { 1245 do {
1246 current->state = TASK_INTERRUPTIBLE; 1246 tmp = schedule_timeout_interruptible(tmp);
1247 tmp = schedule_timeout(tmp);
1248 } while(time_after(tmp, jiffies)); 1247 } while(time_after(tmp, jiffies));
1249#else 1248#else
1250 udelay(time); 1249 udelay(time);
diff --git a/drivers/net/tulip/de2104x.c b/drivers/net/tulip/de2104x.c
index a22d00198e4d..d7fb3ffe06ac 100644
--- a/drivers/net/tulip/de2104x.c
+++ b/drivers/net/tulip/de2104x.c
@@ -1787,10 +1787,15 @@ static void __init de21041_get_srom_info (struct de_private *de)
1787 /* DEC now has a specification but early board makers 1787 /* DEC now has a specification but early board makers
1788 just put the address in the first EEPROM locations. */ 1788 just put the address in the first EEPROM locations. */
1789 /* This does memcmp(eedata, eedata+16, 8) */ 1789 /* This does memcmp(eedata, eedata+16, 8) */
1790
1791#ifndef CONFIG_MIPS_COBALT
1792
1790 for (i = 0; i < 8; i ++) 1793 for (i = 0; i < 8; i ++)
1791 if (ee_data[i] != ee_data[16+i]) 1794 if (ee_data[i] != ee_data[16+i])
1792 sa_offset = 20; 1795 sa_offset = 20;
1793 1796
1797#endif
1798
1794 /* store MAC address */ 1799 /* store MAC address */
1795 for (i = 0; i < 6; i ++) 1800 for (i = 0; i < 6; i ++)
1796 de->dev->dev_addr[i] = ee_data[i + sa_offset]; 1801 de->dev->dev_addr[i] = ee_data[i + sa_offset];
@@ -2071,8 +2076,7 @@ static int __init de_init_one (struct pci_dev *pdev,
2071 return 0; 2076 return 0;
2072 2077
2073err_out_iomap: 2078err_out_iomap:
2074 if (de->ee_data) 2079 kfree(de->ee_data);
2075 kfree(de->ee_data);
2076 iounmap(regs); 2080 iounmap(regs);
2077err_out_res: 2081err_out_res:
2078 pci_release_regions(pdev); 2082 pci_release_regions(pdev);
@@ -2091,8 +2095,7 @@ static void __exit de_remove_one (struct pci_dev *pdev)
2091 if (!dev) 2095 if (!dev)
2092 BUG(); 2096 BUG();
2093 unregister_netdev(dev); 2097 unregister_netdev(dev);
2094 if (de->ee_data) 2098 kfree(de->ee_data);
2095 kfree(de->ee_data);
2096 iounmap(de->regs); 2099 iounmap(de->regs);
2097 pci_release_regions(pdev); 2100 pci_release_regions(pdev);
2098 pci_disable_device(pdev); 2101 pci_disable_device(pdev);
diff --git a/drivers/net/tulip/tulip_core.c b/drivers/net/tulip/tulip_core.c
index 6266a9a7e6e3..125ed00e95a5 100644
--- a/drivers/net/tulip/tulip_core.c
+++ b/drivers/net/tulip/tulip_core.c
@@ -1727,8 +1727,7 @@ err_out_free_ring:
1727 tp->rx_ring, tp->rx_ring_dma); 1727 tp->rx_ring, tp->rx_ring_dma);
1728 1728
1729err_out_mtable: 1729err_out_mtable:
1730 if (tp->mtable) 1730 kfree (tp->mtable);
1731 kfree (tp->mtable);
1732 pci_iounmap(pdev, ioaddr); 1731 pci_iounmap(pdev, ioaddr);
1733 1732
1734err_out_free_res: 1733err_out_free_res:
@@ -1806,8 +1805,7 @@ static void __devexit tulip_remove_one (struct pci_dev *pdev)
1806 sizeof (struct tulip_rx_desc) * RX_RING_SIZE + 1805 sizeof (struct tulip_rx_desc) * RX_RING_SIZE +
1807 sizeof (struct tulip_tx_desc) * TX_RING_SIZE, 1806 sizeof (struct tulip_tx_desc) * TX_RING_SIZE,
1808 tp->rx_ring, tp->rx_ring_dma); 1807 tp->rx_ring, tp->rx_ring_dma);
1809 if (tp->mtable) 1808 kfree (tp->mtable);
1810 kfree (tp->mtable);
1811 pci_iounmap(pdev, tp->base_addr); 1809 pci_iounmap(pdev, tp->base_addr);
1812 free_netdev (dev); 1810 free_netdev (dev);
1813 pci_release_regions (pdev); 1811 pci_release_regions (pdev);
diff --git a/drivers/net/typhoon.c b/drivers/net/typhoon.c
index ecfa6f8805ce..4c76cb794bfb 100644
--- a/drivers/net/typhoon.c
+++ b/drivers/net/typhoon.c
@@ -419,10 +419,9 @@ typhoon_reset(void __iomem *ioaddr, int wait_type)
419 TYPHOON_STATUS_WAITING_FOR_HOST) 419 TYPHOON_STATUS_WAITING_FOR_HOST)
420 goto out; 420 goto out;
421 421
422 if(wait_type == WaitSleep) { 422 if(wait_type == WaitSleep)
423 set_current_state(TASK_UNINTERRUPTIBLE); 423 schedule_timeout_uninterruptible(1);
424 schedule_timeout(1); 424 else
425 } else
426 udelay(TYPHOON_UDELAY); 425 udelay(TYPHOON_UDELAY);
427 } 426 }
428 427
diff --git a/drivers/net/via-rhine.c b/drivers/net/via-rhine.c
index fc7738ffbfff..241871589283 100644
--- a/drivers/net/via-rhine.c
+++ b/drivers/net/via-rhine.c
@@ -490,6 +490,8 @@ struct rhine_private {
490 u8 tx_thresh, rx_thresh; 490 u8 tx_thresh, rx_thresh;
491 491
492 struct mii_if_info mii_if; 492 struct mii_if_info mii_if;
493 struct work_struct tx_timeout_task;
494 struct work_struct check_media_task;
493 void __iomem *base; 495 void __iomem *base;
494}; 496};
495 497
@@ -497,6 +499,8 @@ static int mdio_read(struct net_device *dev, int phy_id, int location);
497static void mdio_write(struct net_device *dev, int phy_id, int location, int value); 499static void mdio_write(struct net_device *dev, int phy_id, int location, int value);
498static int rhine_open(struct net_device *dev); 500static int rhine_open(struct net_device *dev);
499static void rhine_tx_timeout(struct net_device *dev); 501static void rhine_tx_timeout(struct net_device *dev);
502static void rhine_tx_timeout_task(struct net_device *dev);
503static void rhine_check_media_task(struct net_device *dev);
500static int rhine_start_tx(struct sk_buff *skb, struct net_device *dev); 504static int rhine_start_tx(struct sk_buff *skb, struct net_device *dev);
501static irqreturn_t rhine_interrupt(int irq, void *dev_instance, struct pt_regs *regs); 505static irqreturn_t rhine_interrupt(int irq, void *dev_instance, struct pt_regs *regs);
502static void rhine_tx(struct net_device *dev); 506static void rhine_tx(struct net_device *dev);
@@ -814,8 +818,9 @@ static int __devinit rhine_init_one(struct pci_dev *pdev,
814 818
815 for (i = 0; i < 6; i++) 819 for (i = 0; i < 6; i++)
816 dev->dev_addr[i] = ioread8(ioaddr + StationAddr + i); 820 dev->dev_addr[i] = ioread8(ioaddr + StationAddr + i);
821 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
817 822
818 if (!is_valid_ether_addr(dev->dev_addr)) { 823 if (!is_valid_ether_addr(dev->perm_addr)) {
819 rc = -EIO; 824 rc = -EIO;
820 printk(KERN_ERR "Invalid MAC address\n"); 825 printk(KERN_ERR "Invalid MAC address\n");
821 goto err_out_unmap; 826 goto err_out_unmap;
@@ -850,6 +855,12 @@ static int __devinit rhine_init_one(struct pci_dev *pdev,
850 if (rp->quirks & rqRhineI) 855 if (rp->quirks & rqRhineI)
851 dev->features |= NETIF_F_SG|NETIF_F_HW_CSUM; 856 dev->features |= NETIF_F_SG|NETIF_F_HW_CSUM;
852 857
858 INIT_WORK(&rp->tx_timeout_task,
859 (void (*)(void *))rhine_tx_timeout_task, dev);
860
861 INIT_WORK(&rp->check_media_task,
862 (void (*)(void *))rhine_check_media_task, dev);
863
853 /* dev->name not defined before register_netdev()! */ 864 /* dev->name not defined before register_netdev()! */
854 rc = register_netdev(dev); 865 rc = register_netdev(dev);
855 if (rc) 866 if (rc)
@@ -1076,6 +1087,11 @@ static void rhine_check_media(struct net_device *dev, unsigned int init_media)
1076 ioaddr + ChipCmd1); 1087 ioaddr + ChipCmd1);
1077} 1088}
1078 1089
1090static void rhine_check_media_task(struct net_device *dev)
1091{
1092 rhine_check_media(dev, 0);
1093}
1094
1079static void init_registers(struct net_device *dev) 1095static void init_registers(struct net_device *dev)
1080{ 1096{
1081 struct rhine_private *rp = netdev_priv(dev); 1097 struct rhine_private *rp = netdev_priv(dev);
@@ -1129,8 +1145,8 @@ static void rhine_disable_linkmon(void __iomem *ioaddr, u32 quirks)
1129 if (quirks & rqRhineI) { 1145 if (quirks & rqRhineI) {
1130 iowrite8(0x01, ioaddr + MIIRegAddr); // MII_BMSR 1146 iowrite8(0x01, ioaddr + MIIRegAddr); // MII_BMSR
1131 1147
1132 /* Can be called from ISR. Evil. */ 1148 /* Do not call from ISR! */
1133 mdelay(1); 1149 msleep(1);
1134 1150
1135 /* 0x80 must be set immediately before turning it off */ 1151 /* 0x80 must be set immediately before turning it off */
1136 iowrite8(0x80, ioaddr + MIICmd); 1152 iowrite8(0x80, ioaddr + MIICmd);
@@ -1220,6 +1236,16 @@ static int rhine_open(struct net_device *dev)
1220static void rhine_tx_timeout(struct net_device *dev) 1236static void rhine_tx_timeout(struct net_device *dev)
1221{ 1237{
1222 struct rhine_private *rp = netdev_priv(dev); 1238 struct rhine_private *rp = netdev_priv(dev);
1239
1240 /*
1241 * Move bulk of work outside of interrupt context
1242 */
1243 schedule_work(&rp->tx_timeout_task);
1244}
1245
1246static void rhine_tx_timeout_task(struct net_device *dev)
1247{
1248 struct rhine_private *rp = netdev_priv(dev);
1223 void __iomem *ioaddr = rp->base; 1249 void __iomem *ioaddr = rp->base;
1224 1250
1225 printk(KERN_WARNING "%s: Transmit timed out, status %4.4x, PHY status " 1251 printk(KERN_WARNING "%s: Transmit timed out, status %4.4x, PHY status "
@@ -1625,7 +1651,7 @@ static void rhine_error(struct net_device *dev, int intr_status)
1625 spin_lock(&rp->lock); 1651 spin_lock(&rp->lock);
1626 1652
1627 if (intr_status & IntrLinkChange) 1653 if (intr_status & IntrLinkChange)
1628 rhine_check_media(dev, 0); 1654 schedule_work(&rp->check_media_task);
1629 if (intr_status & IntrStatsMax) { 1655 if (intr_status & IntrStatsMax) {
1630 rp->stats.rx_crc_errors += ioread16(ioaddr + RxCRCErrs); 1656 rp->stats.rx_crc_errors += ioread16(ioaddr + RxCRCErrs);
1631 rp->stats.rx_missed_errors += ioread16(ioaddr + RxMissed); 1657 rp->stats.rx_missed_errors += ioread16(ioaddr + RxMissed);
@@ -1829,6 +1855,7 @@ static struct ethtool_ops netdev_ethtool_ops = {
1829 .set_wol = rhine_set_wol, 1855 .set_wol = rhine_set_wol,
1830 .get_sg = ethtool_op_get_sg, 1856 .get_sg = ethtool_op_get_sg,
1831 .get_tx_csum = ethtool_op_get_tx_csum, 1857 .get_tx_csum = ethtool_op_get_tx_csum,
1858 .get_perm_addr = ethtool_op_get_perm_addr,
1832}; 1859};
1833 1860
1834static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 1861static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
@@ -1872,6 +1899,9 @@ static int rhine_close(struct net_device *dev)
1872 spin_unlock_irq(&rp->lock); 1899 spin_unlock_irq(&rp->lock);
1873 1900
1874 free_irq(rp->pdev->irq, dev); 1901 free_irq(rp->pdev->irq, dev);
1902
1903 flush_scheduled_work();
1904
1875 free_rbufs(dev); 1905 free_rbufs(dev);
1876 free_tbufs(dev); 1906 free_tbufs(dev);
1877 free_ring(dev); 1907 free_ring(dev);
diff --git a/drivers/net/via-velocity.c b/drivers/net/via-velocity.c
index abc5cee6eedc..a368d08e7d19 100644
--- a/drivers/net/via-velocity.c
+++ b/drivers/net/via-velocity.c
@@ -1212,10 +1212,8 @@ static void velocity_free_td_ring(struct velocity_info *vptr)
1212 velocity_free_td_ring_entry(vptr, j, i); 1212 velocity_free_td_ring_entry(vptr, j, i);
1213 1213
1214 } 1214 }
1215 if (vptr->td_infos[j]) { 1215 kfree(vptr->td_infos[j]);
1216 kfree(vptr->td_infos[j]); 1216 vptr->td_infos[j] = NULL;
1217 vptr->td_infos[j] = NULL;
1218 }
1219 } 1217 }
1220} 1218}
1221 1219
diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c
index 7ff814fd65d0..e392ee8b37a1 100644
--- a/drivers/net/wan/cosa.c
+++ b/drivers/net/wan/cosa.c
@@ -400,7 +400,7 @@ static int __init cosa_init(void)
400 goto out_chrdev; 400 goto out_chrdev;
401 } 401 }
402 for (i=0; i<nr_cards; i++) { 402 for (i=0; i<nr_cards; i++) {
403 class_device_create(cosa_class, MKDEV(cosa_major, i), 403 class_device_create(cosa_class, NULL, MKDEV(cosa_major, i),
404 NULL, "cosa%d", i); 404 NULL, "cosa%d", i);
405 err = devfs_mk_cdev(MKDEV(cosa_major, i), 405 err = devfs_mk_cdev(MKDEV(cosa_major, i),
406 S_IFCHR|S_IRUSR|S_IWUSR, 406 S_IFCHR|S_IRUSR|S_IWUSR,
@@ -1617,8 +1617,7 @@ static int get_wait_data(struct cosa_data *cosa)
1617 return r; 1617 return r;
1618 } 1618 }
1619 /* sleep if not ready to read */ 1619 /* sleep if not ready to read */
1620 set_current_state(TASK_INTERRUPTIBLE); 1620 schedule_timeout_interruptible(1);
1621 schedule_timeout(1);
1622 } 1621 }
1623 printk(KERN_INFO "cosa: timeout in get_wait_data (status 0x%x)\n", 1622 printk(KERN_INFO "cosa: timeout in get_wait_data (status 0x%x)\n",
1624 cosa_getstatus(cosa)); 1623 cosa_getstatus(cosa));
@@ -1644,8 +1643,7 @@ static int put_wait_data(struct cosa_data *cosa, int data)
1644 } 1643 }
1645#if 0 1644#if 0
1646 /* sleep if not ready to read */ 1645 /* sleep if not ready to read */
1647 current->state = TASK_INTERRUPTIBLE; 1646 schedule_timeout_interruptible(1);
1648 schedule_timeout(1);
1649#endif 1647#endif
1650 } 1648 }
1651 printk(KERN_INFO "cosa%d: timeout in put_wait_data (status 0x%x)\n", 1649 printk(KERN_INFO "cosa%d: timeout in put_wait_data (status 0x%x)\n",
diff --git a/drivers/net/wan/cycx_drv.c b/drivers/net/wan/cycx_drv.c
index 9e56fc346ba4..e6d005726aad 100644
--- a/drivers/net/wan/cycx_drv.c
+++ b/drivers/net/wan/cycx_drv.c
@@ -109,7 +109,7 @@ static long cycx_2x_irq_options[] = { 7, 3, 5, 9, 10, 11, 12, 15 };
109 * < 0 error. 109 * < 0 error.
110 * Context: process */ 110 * Context: process */
111 111
112int __init cycx_drv_init(void) 112static int __init cycx_drv_init(void)
113{ 113{
114 printk(KERN_INFO "%s v%u.%u %s\n", fullname, MOD_VERSION, MOD_RELEASE, 114 printk(KERN_INFO "%s v%u.%u %s\n", fullname, MOD_VERSION, MOD_RELEASE,
115 copyright); 115 copyright);
@@ -119,7 +119,7 @@ int __init cycx_drv_init(void)
119 119
120/* Module 'remove' entry point. 120/* Module 'remove' entry point.
121 * o release all remaining system resources */ 121 * o release all remaining system resources */
122void cycx_drv_cleanup(void) 122static void cycx_drv_cleanup(void)
123{ 123{
124} 124}
125 125
@@ -184,8 +184,7 @@ int cycx_down(struct cycx_hw *hw)
184} 184}
185 185
186/* Enable interrupt generation. */ 186/* Enable interrupt generation. */
187EXPORT_SYMBOL(cycx_inten); 187static void cycx_inten(struct cycx_hw *hw)
188void cycx_inten(struct cycx_hw *hw)
189{ 188{
190 writeb(0, hw->dpmbase); 189 writeb(0, hw->dpmbase);
191} 190}
diff --git a/drivers/net/wan/cycx_main.c b/drivers/net/wan/cycx_main.c
index 7b48064364dc..430b1f630fb4 100644
--- a/drivers/net/wan/cycx_main.c
+++ b/drivers/net/wan/cycx_main.c
@@ -103,7 +103,7 @@ static struct cycx_device *cycx_card_array; /* adapter data space */
103 * < 0 error. 103 * < 0 error.
104 * Context: process 104 * Context: process
105 */ 105 */
106int __init cycx_init(void) 106static int __init cycx_init(void)
107{ 107{
108 int cnt, err = -ENOMEM; 108 int cnt, err = -ENOMEM;
109 109
diff --git a/drivers/net/wan/cycx_x25.c b/drivers/net/wan/cycx_x25.c
index 02d57c0b4243..a631d1c2fa14 100644
--- a/drivers/net/wan/cycx_x25.c
+++ b/drivers/net/wan/cycx_x25.c
@@ -78,6 +78,7 @@
78 78
79#define CYCLOMX_X25_DEBUG 1 79#define CYCLOMX_X25_DEBUG 1
80 80
81#include <linux/ctype.h> /* isdigit() */
81#include <linux/errno.h> /* return codes */ 82#include <linux/errno.h> /* return codes */
82#include <linux/if_arp.h> /* ARPHRD_HWX25 */ 83#include <linux/if_arp.h> /* ARPHRD_HWX25 */
83#include <linux/kernel.h> /* printk(), and other useful stuff */ 84#include <linux/kernel.h> /* printk(), and other useful stuff */
@@ -418,7 +419,7 @@ static int cycx_wan_new_if(struct wan_device *wandev, struct net_device *dev,
418 419
419 /* Set channel timeouts (default if not specified) */ 420 /* Set channel timeouts (default if not specified) */
420 chan->idle_tmout = conf->idle_timeout ? conf->idle_timeout : 90; 421 chan->idle_tmout = conf->idle_timeout ? conf->idle_timeout : 90;
421 } else if (is_digit(conf->addr[0])) { /* PVC */ 422 } else if (isdigit(conf->addr[0])) { /* PVC */
422 s16 lcn = dec_to_uint(conf->addr, 0); 423 s16 lcn = dec_to_uint(conf->addr, 0);
423 424
424 if (lcn >= card->u.x.lo_pvc && lcn <= card->u.x.hi_pvc) 425 if (lcn >= card->u.x.lo_pvc && lcn <= card->u.x.hi_pvc)
@@ -1531,7 +1532,7 @@ static unsigned dec_to_uint(u8 *str, int len)
1531 if (!len) 1532 if (!len)
1532 len = strlen(str); 1533 len = strlen(str);
1533 1534
1534 for (; len && is_digit(*str); ++str, --len) 1535 for (; len && isdigit(*str); ++str, --len)
1535 val = (val * 10) + (*str - (unsigned) '0'); 1536 val = (val * 10) + (*str - (unsigned) '0');
1536 1537
1537 return val; 1538 return val;
diff --git a/drivers/net/wan/dscc4.c b/drivers/net/wan/dscc4.c
index 520a77a798e2..2f61a47b4716 100644
--- a/drivers/net/wan/dscc4.c
+++ b/drivers/net/wan/dscc4.c
@@ -446,8 +446,8 @@ static inline unsigned int dscc4_tx_quiescent(struct dscc4_dev_priv *dpriv,
446 return readl(dpriv->base_addr + CH0FTDA + dpriv->dev_id*4) == dpriv->ltda; 446 return readl(dpriv->base_addr + CH0FTDA + dpriv->dev_id*4) == dpriv->ltda;
447} 447}
448 448
449int state_check(u32 state, struct dscc4_dev_priv *dpriv, struct net_device *dev, 449static int state_check(u32 state, struct dscc4_dev_priv *dpriv,
450 const char *msg) 450 struct net_device *dev, const char *msg)
451{ 451{
452 int ret = 0; 452 int ret = 0;
453 453
@@ -466,8 +466,9 @@ int state_check(u32 state, struct dscc4_dev_priv *dpriv, struct net_device *dev,
466 return ret; 466 return ret;
467} 467}
468 468
469void dscc4_tx_print(struct net_device *dev, struct dscc4_dev_priv *dpriv, 469static void dscc4_tx_print(struct net_device *dev,
470 char *msg) 470 struct dscc4_dev_priv *dpriv,
471 char *msg)
471{ 472{
472 printk(KERN_DEBUG "%s: tx_current=%02d tx_dirty=%02d (%s)\n", 473 printk(KERN_DEBUG "%s: tx_current=%02d tx_dirty=%02d (%s)\n",
473 dev->name, dpriv->tx_current, dpriv->tx_dirty, msg); 474 dev->name, dpriv->tx_current, dpriv->tx_dirty, msg);
@@ -507,7 +508,8 @@ static void dscc4_release_ring(struct dscc4_dev_priv *dpriv)
507 } 508 }
508} 509}
509 510
510inline int try_get_rx_skb(struct dscc4_dev_priv *dpriv, struct net_device *dev) 511static inline int try_get_rx_skb(struct dscc4_dev_priv *dpriv,
512 struct net_device *dev)
511{ 513{
512 unsigned int dirty = dpriv->rx_dirty%RX_RING_SIZE; 514 unsigned int dirty = dpriv->rx_dirty%RX_RING_SIZE;
513 struct RxFD *rx_fd = dpriv->rx_fd + dirty; 515 struct RxFD *rx_fd = dpriv->rx_fd + dirty;
@@ -542,8 +544,7 @@ static int dscc4_wait_ack_cec(struct dscc4_dev_priv *dpriv,
542 msg, i); 544 msg, i);
543 goto done; 545 goto done;
544 } 546 }
545 set_current_state(TASK_UNINTERRUPTIBLE); 547 schedule_timeout_uninterruptible(10);
546 schedule_timeout(10);
547 rmb(); 548 rmb();
548 } while (++i > 0); 549 } while (++i > 0);
549 printk(KERN_ERR "%s: %s timeout\n", dev->name, msg); 550 printk(KERN_ERR "%s: %s timeout\n", dev->name, msg);
@@ -588,8 +589,7 @@ static inline int dscc4_xpr_ack(struct dscc4_dev_priv *dpriv)
588 (dpriv->iqtx[cur] & Xpr)) 589 (dpriv->iqtx[cur] & Xpr))
589 break; 590 break;
590 smp_rmb(); 591 smp_rmb();
591 set_current_state(TASK_UNINTERRUPTIBLE); 592 schedule_timeout_uninterruptible(10);
592 schedule_timeout(10);
593 } while (++i > 0); 593 } while (++i > 0);
594 594
595 return (i >= 0 ) ? i : -EAGAIN; 595 return (i >= 0 ) ? i : -EAGAIN;
@@ -1035,8 +1035,7 @@ static void dscc4_pci_reset(struct pci_dev *pdev, void __iomem *ioaddr)
1035 /* Flush posted writes */ 1035 /* Flush posted writes */
1036 readl(ioaddr + GSTAR); 1036 readl(ioaddr + GSTAR);
1037 1037
1038 set_current_state(TASK_UNINTERRUPTIBLE); 1038 schedule_timeout_uninterruptible(10);
1039 schedule_timeout(10);
1040 1039
1041 for (i = 0; i < 16; i++) 1040 for (i = 0; i < 16; i++)
1042 pci_write_config_dword(pdev, i << 2, dscc4_pci_config_store[i]); 1041 pci_write_config_dword(pdev, i << 2, dscc4_pci_config_store[i]);
@@ -1894,7 +1893,7 @@ try:
1894 * It failed and locked solid. Thus the introduction of a dummy skb. 1893 * It failed and locked solid. Thus the introduction of a dummy skb.
1895 * Problem is acknowledged in errata sheet DS5. Joy :o/ 1894 * Problem is acknowledged in errata sheet DS5. Joy :o/
1896 */ 1895 */
1897struct sk_buff *dscc4_init_dummy_skb(struct dscc4_dev_priv *dpriv) 1896static struct sk_buff *dscc4_init_dummy_skb(struct dscc4_dev_priv *dpriv)
1898{ 1897{
1899 struct sk_buff *skb; 1898 struct sk_buff *skb;
1900 1899
diff --git a/drivers/net/wan/farsync.c b/drivers/net/wan/farsync.c
index 2c83cca34b86..7981a2c7906e 100644
--- a/drivers/net/wan/farsync.c
+++ b/drivers/net/wan/farsync.c
@@ -74,11 +74,11 @@ MODULE_LICENSE("GPL");
74/* 74/*
75 * Modules parameters and associated varaibles 75 * Modules parameters and associated varaibles
76 */ 76 */
77int fst_txq_low = FST_LOW_WATER_MARK; 77static int fst_txq_low = FST_LOW_WATER_MARK;
78int fst_txq_high = FST_HIGH_WATER_MARK; 78static int fst_txq_high = FST_HIGH_WATER_MARK;
79int fst_max_reads = 7; 79static int fst_max_reads = 7;
80int fst_excluded_cards = 0; 80static int fst_excluded_cards = 0;
81int fst_excluded_list[FST_MAX_CARDS]; 81static int fst_excluded_list[FST_MAX_CARDS];
82 82
83module_param(fst_txq_low, int, 0); 83module_param(fst_txq_low, int, 0);
84module_param(fst_txq_high, int, 0); 84module_param(fst_txq_high, int, 0);
@@ -572,13 +572,13 @@ static void do_bottom_half_rx(struct fst_card_info *card);
572static void fst_process_tx_work_q(unsigned long work_q); 572static void fst_process_tx_work_q(unsigned long work_q);
573static void fst_process_int_work_q(unsigned long work_q); 573static void fst_process_int_work_q(unsigned long work_q);
574 574
575DECLARE_TASKLET(fst_tx_task, fst_process_tx_work_q, 0); 575static DECLARE_TASKLET(fst_tx_task, fst_process_tx_work_q, 0);
576DECLARE_TASKLET(fst_int_task, fst_process_int_work_q, 0); 576static DECLARE_TASKLET(fst_int_task, fst_process_int_work_q, 0);
577 577
578struct fst_card_info *fst_card_array[FST_MAX_CARDS]; 578static struct fst_card_info *fst_card_array[FST_MAX_CARDS];
579spinlock_t fst_work_q_lock; 579static spinlock_t fst_work_q_lock;
580u64 fst_work_txq; 580static u64 fst_work_txq;
581u64 fst_work_intq; 581static u64 fst_work_intq;
582 582
583static void 583static void
584fst_q_work_item(u64 * queue, int card_index) 584fst_q_work_item(u64 * queue, int card_index)
@@ -980,8 +980,7 @@ fst_issue_cmd(struct fst_port_info *port, unsigned short cmd)
980 /* Wait for any previous command to complete */ 980 /* Wait for any previous command to complete */
981 while (mbval > NAK) { 981 while (mbval > NAK) {
982 spin_unlock_irqrestore(&card->card_lock, flags); 982 spin_unlock_irqrestore(&card->card_lock, flags);
983 set_current_state(TASK_UNINTERRUPTIBLE); 983 schedule_timeout_uninterruptible(1);
984 schedule_timeout(1);
985 spin_lock_irqsave(&card->card_lock, flags); 984 spin_lock_irqsave(&card->card_lock, flags);
986 985
987 if (++safety > 2000) { 986 if (++safety > 2000) {
@@ -1498,7 +1497,7 @@ do_bottom_half_rx(struct fst_card_info *card)
1498 * The interrupt service routine 1497 * The interrupt service routine
1499 * Dev_id is our fst_card_info pointer 1498 * Dev_id is our fst_card_info pointer
1500 */ 1499 */
1501irqreturn_t 1500static irqreturn_t
1502fst_intr(int irq, void *dev_id, struct pt_regs *regs) 1501fst_intr(int irq, void *dev_id, struct pt_regs *regs)
1503{ 1502{
1504 struct fst_card_info *card; 1503 struct fst_card_info *card;
diff --git a/drivers/net/wan/hdlc_fr.c b/drivers/net/wan/hdlc_fr.c
index a5d6891c9d4c..e1601d35dced 100644
--- a/drivers/net/wan/hdlc_fr.c
+++ b/drivers/net/wan/hdlc_fr.c
@@ -330,7 +330,7 @@ static int pvc_close(struct net_device *dev)
330 330
331 331
332 332
333int pvc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) 333static int pvc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
334{ 334{
335 pvc_device *pvc = dev_to_pvc(dev); 335 pvc_device *pvc = dev_to_pvc(dev);
336 fr_proto_pvc_info info; 336 fr_proto_pvc_info info;
diff --git a/drivers/net/wan/lmc/lmc_debug.c b/drivers/net/wan/lmc/lmc_debug.c
index 9dccd9546a17..3b94352b0d03 100644
--- a/drivers/net/wan/lmc/lmc_debug.c
+++ b/drivers/net/wan/lmc/lmc_debug.c
@@ -8,10 +8,10 @@
8/* 8/*
9 * Prints out len, max to 80 octets using printk, 20 per line 9 * Prints out len, max to 80 octets using printk, 20 per line
10 */ 10 */
11void lmcConsoleLog(char *type, unsigned char *ucData, int iLen)
12{
13#ifdef DEBUG 11#ifdef DEBUG
14#ifdef LMC_PACKET_LOG 12#ifdef LMC_PACKET_LOG
13void lmcConsoleLog(char *type, unsigned char *ucData, int iLen)
14{
15 int iNewLine = 1; 15 int iNewLine = 1;
16 char str[80], *pstr; 16 char str[80], *pstr;
17 17
@@ -43,26 +43,24 @@ void lmcConsoleLog(char *type, unsigned char *ucData, int iLen)
43 } 43 }
44 sprintf(pstr, "\n"); 44 sprintf(pstr, "\n");
45 printk(str); 45 printk(str);
46}
46#endif 47#endif
47#endif 48#endif
48}
49 49
50#ifdef DEBUG 50#ifdef DEBUG
51u_int32_t lmcEventLogIndex = 0; 51u_int32_t lmcEventLogIndex = 0;
52u_int32_t lmcEventLogBuf[LMC_EVENTLOGSIZE * LMC_EVENTLOGARGS]; 52u_int32_t lmcEventLogBuf[LMC_EVENTLOGSIZE * LMC_EVENTLOGARGS];
53#endif
54 53
55void lmcEventLog (u_int32_t EventNum, u_int32_t arg2, u_int32_t arg3) 54void lmcEventLog (u_int32_t EventNum, u_int32_t arg2, u_int32_t arg3)
56{ 55{
57#ifdef DEBUG
58 lmcEventLogBuf[lmcEventLogIndex++] = EventNum; 56 lmcEventLogBuf[lmcEventLogIndex++] = EventNum;
59 lmcEventLogBuf[lmcEventLogIndex++] = arg2; 57 lmcEventLogBuf[lmcEventLogIndex++] = arg2;
60 lmcEventLogBuf[lmcEventLogIndex++] = arg3; 58 lmcEventLogBuf[lmcEventLogIndex++] = arg3;
61 lmcEventLogBuf[lmcEventLogIndex++] = jiffies; 59 lmcEventLogBuf[lmcEventLogIndex++] = jiffies;
62 60
63 lmcEventLogIndex &= (LMC_EVENTLOGSIZE * LMC_EVENTLOGARGS) - 1; 61 lmcEventLogIndex &= (LMC_EVENTLOGSIZE * LMC_EVENTLOGARGS) - 1;
64#endif
65} 62}
63#endif /* DEBUG */
66 64
67void lmc_trace(struct net_device *dev, char *msg){ 65void lmc_trace(struct net_device *dev, char *msg){
68#ifdef LMC_TRACE 66#ifdef LMC_TRACE
diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
index f55ce76b00ed..af8b55fdd9d9 100644
--- a/drivers/net/wan/lmc/lmc_media.c
+++ b/drivers/net/wan/lmc/lmc_media.c
@@ -48,14 +48,6 @@
48 */ 48 */
49 49
50/* 50/*
51 * For lack of a better place, put the SSI cable stuff here.
52 */
53char *lmc_t1_cables[] = {
54 "V.10/RS423", "EIA530A", "reserved", "X.21", "V.35",
55 "EIA449/EIA530/V.36", "V.28/EIA232", "none", NULL
56};
57
58/*
59 * protocol independent method. 51 * protocol independent method.
60 */ 52 */
61static void lmc_set_protocol (lmc_softc_t * const, lmc_ctl_t *); 53static void lmc_set_protocol (lmc_softc_t * const, lmc_ctl_t *);
diff --git a/drivers/net/wan/pc300.h b/drivers/net/wan/pc300.h
index 73401b0f0151..2024b26b99e6 100644
--- a/drivers/net/wan/pc300.h
+++ b/drivers/net/wan/pc300.h
@@ -472,24 +472,8 @@ enum pc300_loopback_cmds {
472 472
473#ifdef __KERNEL__ 473#ifdef __KERNEL__
474/* Function Prototypes */ 474/* Function Prototypes */
475int dma_buf_write(pc300_t *, int, ucchar *, int);
476int dma_buf_read(pc300_t *, int, struct sk_buff *);
477void tx_dma_start(pc300_t *, int); 475void tx_dma_start(pc300_t *, int);
478void rx_dma_start(pc300_t *, int);
479void tx_dma_stop(pc300_t *, int);
480void rx_dma_stop(pc300_t *, int);
481int cpc_queue_xmit(struct sk_buff *, struct net_device *);
482void cpc_net_rx(struct net_device *);
483void cpc_sca_status(pc300_t *, int);
484int cpc_change_mtu(struct net_device *, int);
485int cpc_ioctl(struct net_device *, struct ifreq *, int);
486int ch_config(pc300dev_t *);
487int rx_config(pc300dev_t *);
488int tx_config(pc300dev_t *);
489void cpc_opench(pc300dev_t *);
490void cpc_closech(pc300dev_t *);
491int cpc_open(struct net_device *dev); 476int cpc_open(struct net_device *dev);
492int cpc_close(struct net_device *dev);
493int cpc_set_media(hdlc_device *, int); 477int cpc_set_media(hdlc_device *, int);
494#endif /* __KERNEL__ */ 478#endif /* __KERNEL__ */
495 479
diff --git a/drivers/net/wan/pc300_drv.c b/drivers/net/wan/pc300_drv.c
index 3e7753b10717..a3e65d1bc19b 100644
--- a/drivers/net/wan/pc300_drv.c
+++ b/drivers/net/wan/pc300_drv.c
@@ -291,6 +291,7 @@ static uclong detect_ram(pc300_t *);
291static void plx_init(pc300_t *); 291static void plx_init(pc300_t *);
292static void cpc_trace(struct net_device *, struct sk_buff *, char); 292static void cpc_trace(struct net_device *, struct sk_buff *, char);
293static int cpc_attach(struct net_device *, unsigned short, unsigned short); 293static int cpc_attach(struct net_device *, unsigned short, unsigned short);
294static int cpc_close(struct net_device *dev);
294 295
295#ifdef CONFIG_PC300_MLPPP 296#ifdef CONFIG_PC300_MLPPP
296void cpc_tty_init(pc300dev_t * dev); 297void cpc_tty_init(pc300dev_t * dev);
@@ -437,7 +438,7 @@ static void rx_dma_buf_check(pc300_t * card, int ch)
437 printk("\n"); 438 printk("\n");
438} 439}
439 440
440int dma_get_rx_frame_size(pc300_t * card, int ch) 441static int dma_get_rx_frame_size(pc300_t * card, int ch)
441{ 442{
442 volatile pcsca_bd_t __iomem *ptdescr; 443 volatile pcsca_bd_t __iomem *ptdescr;
443 ucshort first_bd = card->chan[ch].rx_first_bd; 444 ucshort first_bd = card->chan[ch].rx_first_bd;
@@ -462,7 +463,7 @@ int dma_get_rx_frame_size(pc300_t * card, int ch)
462 * dma_buf_write: writes a frame to the Tx DMA buffers 463 * dma_buf_write: writes a frame to the Tx DMA buffers
463 * NOTE: this function writes one frame at a time. 464 * NOTE: this function writes one frame at a time.
464 */ 465 */
465int dma_buf_write(pc300_t * card, int ch, ucchar * ptdata, int len) 466static int dma_buf_write(pc300_t * card, int ch, ucchar * ptdata, int len)
466{ 467{
467 int i, nchar; 468 int i, nchar;
468 volatile pcsca_bd_t __iomem *ptdescr; 469 volatile pcsca_bd_t __iomem *ptdescr;
@@ -503,7 +504,7 @@ int dma_buf_write(pc300_t * card, int ch, ucchar * ptdata, int len)
503 * dma_buf_read: reads a frame from the Rx DMA buffers 504 * dma_buf_read: reads a frame from the Rx DMA buffers
504 * NOTE: this function reads one frame at a time. 505 * NOTE: this function reads one frame at a time.
505 */ 506 */
506int dma_buf_read(pc300_t * card, int ch, struct sk_buff *skb) 507static int dma_buf_read(pc300_t * card, int ch, struct sk_buff *skb)
507{ 508{
508 int nchar; 509 int nchar;
509 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 510 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
@@ -560,7 +561,7 @@ int dma_buf_read(pc300_t * card, int ch, struct sk_buff *skb)
560 return (rcvd); 561 return (rcvd);
561} 562}
562 563
563void tx_dma_stop(pc300_t * card, int ch) 564static void tx_dma_stop(pc300_t * card, int ch)
564{ 565{
565 void __iomem *scabase = card->hw.scabase; 566 void __iomem *scabase = card->hw.scabase;
566 ucchar drr_ena_bit = 1 << (5 + 2 * ch); 567 ucchar drr_ena_bit = 1 << (5 + 2 * ch);
@@ -571,7 +572,7 @@ void tx_dma_stop(pc300_t * card, int ch)
571 cpc_writeb(scabase + DRR, drr_rst_bit & ~drr_ena_bit); 572 cpc_writeb(scabase + DRR, drr_rst_bit & ~drr_ena_bit);
572} 573}
573 574
574void rx_dma_stop(pc300_t * card, int ch) 575static void rx_dma_stop(pc300_t * card, int ch)
575{ 576{
576 void __iomem *scabase = card->hw.scabase; 577 void __iomem *scabase = card->hw.scabase;
577 ucchar drr_ena_bit = 1 << (4 + 2 * ch); 578 ucchar drr_ena_bit = 1 << (4 + 2 * ch);
@@ -582,7 +583,7 @@ void rx_dma_stop(pc300_t * card, int ch)
582 cpc_writeb(scabase + DRR, drr_rst_bit & ~drr_ena_bit); 583 cpc_writeb(scabase + DRR, drr_rst_bit & ~drr_ena_bit);
583} 584}
584 585
585void rx_dma_start(pc300_t * card, int ch) 586static void rx_dma_start(pc300_t * card, int ch)
586{ 587{
587 void __iomem *scabase = card->hw.scabase; 588 void __iomem *scabase = card->hw.scabase;
588 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 589 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
@@ -607,7 +608,7 @@ void rx_dma_start(pc300_t * card, int ch)
607/*************************/ 608/*************************/
608/*** FALC Routines ***/ 609/*** FALC Routines ***/
609/*************************/ 610/*************************/
610void falc_issue_cmd(pc300_t * card, int ch, ucchar cmd) 611static void falc_issue_cmd(pc300_t * card, int ch, ucchar cmd)
611{ 612{
612 void __iomem *falcbase = card->hw.falcbase; 613 void __iomem *falcbase = card->hw.falcbase;
613 unsigned long i = 0; 614 unsigned long i = 0;
@@ -622,7 +623,7 @@ void falc_issue_cmd(pc300_t * card, int ch, ucchar cmd)
622 cpc_writeb(falcbase + F_REG(CMDR, ch), cmd); 623 cpc_writeb(falcbase + F_REG(CMDR, ch), cmd);
623} 624}
624 625
625void falc_intr_enable(pc300_t * card, int ch) 626static void falc_intr_enable(pc300_t * card, int ch)
626{ 627{
627 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 628 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
628 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf; 629 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
@@ -672,7 +673,7 @@ void falc_intr_enable(pc300_t * card, int ch)
672 } 673 }
673} 674}
674 675
675void falc_open_timeslot(pc300_t * card, int ch, int timeslot) 676static void falc_open_timeslot(pc300_t * card, int ch, int timeslot)
676{ 677{
677 void __iomem *falcbase = card->hw.falcbase; 678 void __iomem *falcbase = card->hw.falcbase;
678 ucchar tshf = card->chan[ch].falc.offset; 679 ucchar tshf = card->chan[ch].falc.offset;
@@ -688,7 +689,7 @@ void falc_open_timeslot(pc300_t * card, int ch, int timeslot)
688 (0x80 >> (timeslot & 0x07))); 689 (0x80 >> (timeslot & 0x07)));
689} 690}
690 691
691void falc_close_timeslot(pc300_t * card, int ch, int timeslot) 692static void falc_close_timeslot(pc300_t * card, int ch, int timeslot)
692{ 693{
693 void __iomem *falcbase = card->hw.falcbase; 694 void __iomem *falcbase = card->hw.falcbase;
694 ucchar tshf = card->chan[ch].falc.offset; 695 ucchar tshf = card->chan[ch].falc.offset;
@@ -704,7 +705,7 @@ void falc_close_timeslot(pc300_t * card, int ch, int timeslot)
704 ~(0x80 >> (timeslot & 0x07))); 705 ~(0x80 >> (timeslot & 0x07)));
705} 706}
706 707
707void falc_close_all_timeslots(pc300_t * card, int ch) 708static void falc_close_all_timeslots(pc300_t * card, int ch)
708{ 709{
709 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 710 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
710 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf; 711 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
@@ -726,7 +727,7 @@ void falc_close_all_timeslots(pc300_t * card, int ch)
726 } 727 }
727} 728}
728 729
729void falc_open_all_timeslots(pc300_t * card, int ch) 730static void falc_open_all_timeslots(pc300_t * card, int ch)
730{ 731{
731 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 732 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
732 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf; 733 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
@@ -758,7 +759,7 @@ void falc_open_all_timeslots(pc300_t * card, int ch)
758 } 759 }
759} 760}
760 761
761void falc_init_timeslot(pc300_t * card, int ch) 762static void falc_init_timeslot(pc300_t * card, int ch)
762{ 763{
763 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 764 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
764 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf; 765 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
@@ -776,7 +777,7 @@ void falc_init_timeslot(pc300_t * card, int ch)
776 } 777 }
777} 778}
778 779
779void falc_enable_comm(pc300_t * card, int ch) 780static void falc_enable_comm(pc300_t * card, int ch)
780{ 781{
781 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 782 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
782 falc_t *pfalc = (falc_t *) & chan->falc; 783 falc_t *pfalc = (falc_t *) & chan->falc;
@@ -792,7 +793,7 @@ void falc_enable_comm(pc300_t * card, int ch)
792 ~((CPLD_REG1_FALC_DCD | CPLD_REG1_FALC_CTS) << (2 * ch))); 793 ~((CPLD_REG1_FALC_DCD | CPLD_REG1_FALC_CTS) << (2 * ch)));
793} 794}
794 795
795void falc_disable_comm(pc300_t * card, int ch) 796static void falc_disable_comm(pc300_t * card, int ch)
796{ 797{
797 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 798 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
798 falc_t *pfalc = (falc_t *) & chan->falc; 799 falc_t *pfalc = (falc_t *) & chan->falc;
@@ -806,7 +807,7 @@ void falc_disable_comm(pc300_t * card, int ch)
806 ((CPLD_REG1_FALC_DCD | CPLD_REG1_FALC_CTS) << (2 * ch))); 807 ((CPLD_REG1_FALC_DCD | CPLD_REG1_FALC_CTS) << (2 * ch)));
807} 808}
808 809
809void falc_init_t1(pc300_t * card, int ch) 810static void falc_init_t1(pc300_t * card, int ch)
810{ 811{
811 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 812 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
812 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf; 813 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
@@ -975,7 +976,7 @@ void falc_init_t1(pc300_t * card, int ch)
975 falc_close_all_timeslots(card, ch); 976 falc_close_all_timeslots(card, ch);
976} 977}
977 978
978void falc_init_e1(pc300_t * card, int ch) 979static void falc_init_e1(pc300_t * card, int ch)
979{ 980{
980 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 981 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
981 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf; 982 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
@@ -1155,7 +1156,7 @@ void falc_init_e1(pc300_t * card, int ch)
1155 falc_close_all_timeslots(card, ch); 1156 falc_close_all_timeslots(card, ch);
1156} 1157}
1157 1158
1158void falc_init_hdlc(pc300_t * card, int ch) 1159static void falc_init_hdlc(pc300_t * card, int ch)
1159{ 1160{
1160 void __iomem *falcbase = card->hw.falcbase; 1161 void __iomem *falcbase = card->hw.falcbase;
1161 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 1162 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
@@ -1181,7 +1182,7 @@ void falc_init_hdlc(pc300_t * card, int ch)
1181 falc_intr_enable(card, ch); 1182 falc_intr_enable(card, ch);
1182} 1183}
1183 1184
1184void te_config(pc300_t * card, int ch) 1185static void te_config(pc300_t * card, int ch)
1185{ 1186{
1186 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 1187 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
1187 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf; 1188 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
@@ -1241,7 +1242,7 @@ void te_config(pc300_t * card, int ch)
1241 CPC_UNLOCK(card, flags); 1242 CPC_UNLOCK(card, flags);
1242} 1243}
1243 1244
1244void falc_check_status(pc300_t * card, int ch, unsigned char frs0) 1245static void falc_check_status(pc300_t * card, int ch, unsigned char frs0)
1245{ 1246{
1246 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 1247 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
1247 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf; 1248 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
@@ -1397,7 +1398,7 @@ void falc_check_status(pc300_t * card, int ch, unsigned char frs0)
1397 } 1398 }
1398} 1399}
1399 1400
1400void falc_update_stats(pc300_t * card, int ch) 1401static void falc_update_stats(pc300_t * card, int ch)
1401{ 1402{
1402 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 1403 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
1403 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf; 1404 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
@@ -1450,7 +1451,7 @@ void falc_update_stats(pc300_t * card, int ch)
1450 * the synchronizer and then sent to the system interface. 1451 * the synchronizer and then sent to the system interface.
1451 *---------------------------------------------------------------------------- 1452 *----------------------------------------------------------------------------
1452 */ 1453 */
1453void falc_remote_loop(pc300_t * card, int ch, int loop_on) 1454static void falc_remote_loop(pc300_t * card, int ch, int loop_on)
1454{ 1455{
1455 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 1456 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
1456 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf; 1457 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
@@ -1495,7 +1496,7 @@ void falc_remote_loop(pc300_t * card, int ch, int loop_on)
1495 * coding must be identical. 1496 * coding must be identical.
1496 *---------------------------------------------------------------------------- 1497 *----------------------------------------------------------------------------
1497 */ 1498 */
1498void falc_local_loop(pc300_t * card, int ch, int loop_on) 1499static void falc_local_loop(pc300_t * card, int ch, int loop_on)
1499{ 1500{
1500 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 1501 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
1501 falc_t *pfalc = (falc_t *) & chan->falc; 1502 falc_t *pfalc = (falc_t *) & chan->falc;
@@ -1522,7 +1523,7 @@ void falc_local_loop(pc300_t * card, int ch, int loop_on)
1522 * looped. They are originated by the FALC-LH transmitter. 1523 * looped. They are originated by the FALC-LH transmitter.
1523 *---------------------------------------------------------------------------- 1524 *----------------------------------------------------------------------------
1524 */ 1525 */
1525void falc_payload_loop(pc300_t * card, int ch, int loop_on) 1526static void falc_payload_loop(pc300_t * card, int ch, int loop_on)
1526{ 1527{
1527 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 1528 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
1528 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf; 1529 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
@@ -1576,7 +1577,7 @@ void falc_payload_loop(pc300_t * card, int ch, int loop_on)
1576 * Description: Turns XLU bit off in the proper register 1577 * Description: Turns XLU bit off in the proper register
1577 *---------------------------------------------------------------------------- 1578 *----------------------------------------------------------------------------
1578 */ 1579 */
1579void turn_off_xlu(pc300_t * card, int ch) 1580static void turn_off_xlu(pc300_t * card, int ch)
1580{ 1581{
1581 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 1582 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
1582 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf; 1583 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
@@ -1597,7 +1598,7 @@ void turn_off_xlu(pc300_t * card, int ch)
1597 * Description: Turns XLD bit off in the proper register 1598 * Description: Turns XLD bit off in the proper register
1598 *---------------------------------------------------------------------------- 1599 *----------------------------------------------------------------------------
1599 */ 1600 */
1600void turn_off_xld(pc300_t * card, int ch) 1601static void turn_off_xld(pc300_t * card, int ch)
1601{ 1602{
1602 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 1603 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
1603 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf; 1604 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
@@ -1619,7 +1620,7 @@ void turn_off_xld(pc300_t * card, int ch)
1619 * to generate a LOOP activation code over a T1/E1 line. 1620 * to generate a LOOP activation code over a T1/E1 line.
1620 *---------------------------------------------------------------------------- 1621 *----------------------------------------------------------------------------
1621 */ 1622 */
1622void falc_generate_loop_up_code(pc300_t * card, int ch) 1623static void falc_generate_loop_up_code(pc300_t * card, int ch)
1623{ 1624{
1624 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 1625 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
1625 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf; 1626 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
@@ -1652,7 +1653,7 @@ void falc_generate_loop_up_code(pc300_t * card, int ch)
1652 * to generate a LOOP deactivation code over a T1/E1 line. 1653 * to generate a LOOP deactivation code over a T1/E1 line.
1653 *---------------------------------------------------------------------------- 1654 *----------------------------------------------------------------------------
1654 */ 1655 */
1655void falc_generate_loop_down_code(pc300_t * card, int ch) 1656static void falc_generate_loop_down_code(pc300_t * card, int ch)
1656{ 1657{
1657 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 1658 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
1658 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf; 1659 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
@@ -1682,7 +1683,7 @@ void falc_generate_loop_down_code(pc300_t * card, int ch)
1682 * it on the reception side. 1683 * it on the reception side.
1683 *---------------------------------------------------------------------------- 1684 *----------------------------------------------------------------------------
1684 */ 1685 */
1685void falc_pattern_test(pc300_t * card, int ch, unsigned int activate) 1686static void falc_pattern_test(pc300_t * card, int ch, unsigned int activate)
1686{ 1687{
1687 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 1688 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
1688 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf; 1689 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
@@ -1729,7 +1730,7 @@ void falc_pattern_test(pc300_t * card, int ch, unsigned int activate)
1729 * Description: This routine returns the bit error counter value 1730 * Description: This routine returns the bit error counter value
1730 *---------------------------------------------------------------------------- 1731 *----------------------------------------------------------------------------
1731 */ 1732 */
1732ucshort falc_pattern_test_error(pc300_t * card, int ch) 1733static ucshort falc_pattern_test_error(pc300_t * card, int ch)
1733{ 1734{
1734 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch]; 1735 pc300ch_t *chan = (pc300ch_t *) & card->chan[ch];
1735 falc_t *pfalc = (falc_t *) & chan->falc; 1736 falc_t *pfalc = (falc_t *) & chan->falc;
@@ -1769,7 +1770,7 @@ cpc_trace(struct net_device *dev, struct sk_buff *skb_main, char rx_tx)
1769 netif_rx(skb); 1770 netif_rx(skb);
1770} 1771}
1771 1772
1772void cpc_tx_timeout(struct net_device *dev) 1773static void cpc_tx_timeout(struct net_device *dev)
1773{ 1774{
1774 pc300dev_t *d = (pc300dev_t *) dev->priv; 1775 pc300dev_t *d = (pc300dev_t *) dev->priv;
1775 pc300ch_t *chan = (pc300ch_t *) d->chan; 1776 pc300ch_t *chan = (pc300ch_t *) d->chan;
@@ -1797,7 +1798,7 @@ void cpc_tx_timeout(struct net_device *dev)
1797 netif_wake_queue(dev); 1798 netif_wake_queue(dev);
1798} 1799}
1799 1800
1800int cpc_queue_xmit(struct sk_buff *skb, struct net_device *dev) 1801static int cpc_queue_xmit(struct sk_buff *skb, struct net_device *dev)
1801{ 1802{
1802 pc300dev_t *d = (pc300dev_t *) dev->priv; 1803 pc300dev_t *d = (pc300dev_t *) dev->priv;
1803 pc300ch_t *chan = (pc300ch_t *) d->chan; 1804 pc300ch_t *chan = (pc300ch_t *) d->chan;
@@ -1880,7 +1881,7 @@ int cpc_queue_xmit(struct sk_buff *skb, struct net_device *dev)
1880 return 0; 1881 return 0;
1881} 1882}
1882 1883
1883void cpc_net_rx(struct net_device *dev) 1884static void cpc_net_rx(struct net_device *dev)
1884{ 1885{
1885 pc300dev_t *d = (pc300dev_t *) dev->priv; 1886 pc300dev_t *d = (pc300dev_t *) dev->priv;
1886 pc300ch_t *chan = (pc300ch_t *) d->chan; 1887 pc300ch_t *chan = (pc300ch_t *) d->chan;
@@ -2403,7 +2404,7 @@ static irqreturn_t cpc_intr(int irq, void *dev_id, struct pt_regs *regs)
2403 return IRQ_HANDLED; 2404 return IRQ_HANDLED;
2404} 2405}
2405 2406
2406void cpc_sca_status(pc300_t * card, int ch) 2407static void cpc_sca_status(pc300_t * card, int ch)
2407{ 2408{
2408 ucchar ilar; 2409 ucchar ilar;
2409 void __iomem *scabase = card->hw.scabase; 2410 void __iomem *scabase = card->hw.scabase;
@@ -2495,7 +2496,7 @@ void cpc_sca_status(pc300_t * card, int ch)
2495 } 2496 }
2496} 2497}
2497 2498
2498void cpc_falc_status(pc300_t * card, int ch) 2499static void cpc_falc_status(pc300_t * card, int ch)
2499{ 2500{
2500 pc300ch_t *chan = &card->chan[ch]; 2501 pc300ch_t *chan = &card->chan[ch];
2501 falc_t *pfalc = (falc_t *) & chan->falc; 2502 falc_t *pfalc = (falc_t *) & chan->falc;
@@ -2523,7 +2524,7 @@ void cpc_falc_status(pc300_t * card, int ch)
2523 CPC_UNLOCK(card, flags); 2524 CPC_UNLOCK(card, flags);
2524} 2525}
2525 2526
2526int cpc_change_mtu(struct net_device *dev, int new_mtu) 2527static int cpc_change_mtu(struct net_device *dev, int new_mtu)
2527{ 2528{
2528 if ((new_mtu < 128) || (new_mtu > PC300_DEF_MTU)) 2529 if ((new_mtu < 128) || (new_mtu > PC300_DEF_MTU))
2529 return -EINVAL; 2530 return -EINVAL;
@@ -2531,7 +2532,7 @@ int cpc_change_mtu(struct net_device *dev, int new_mtu)
2531 return 0; 2532 return 0;
2532} 2533}
2533 2534
2534int cpc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) 2535static int cpc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2535{ 2536{
2536 hdlc_device *hdlc = dev_to_hdlc(dev); 2537 hdlc_device *hdlc = dev_to_hdlc(dev);
2537 pc300dev_t *d = (pc300dev_t *) dev->priv; 2538 pc300dev_t *d = (pc300dev_t *) dev->priv;
@@ -2856,7 +2857,7 @@ static int clock_rate_calc(uclong rate, uclong clock, int *br_io)
2856 } 2857 }
2857} 2858}
2858 2859
2859int ch_config(pc300dev_t * d) 2860static int ch_config(pc300dev_t * d)
2860{ 2861{
2861 pc300ch_t *chan = (pc300ch_t *) d->chan; 2862 pc300ch_t *chan = (pc300ch_t *) d->chan;
2862 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf; 2863 pc300chconf_t *conf = (pc300chconf_t *) & chan->conf;
@@ -3004,7 +3005,7 @@ int ch_config(pc300dev_t * d)
3004 return 0; 3005 return 0;
3005} 3006}
3006 3007
3007int rx_config(pc300dev_t * d) 3008static int rx_config(pc300dev_t * d)
3008{ 3009{
3009 pc300ch_t *chan = (pc300ch_t *) d->chan; 3010 pc300ch_t *chan = (pc300ch_t *) d->chan;
3010 pc300_t *card = (pc300_t *) chan->card; 3011 pc300_t *card = (pc300_t *) chan->card;
@@ -3035,7 +3036,7 @@ int rx_config(pc300dev_t * d)
3035 return 0; 3036 return 0;
3036} 3037}
3037 3038
3038int tx_config(pc300dev_t * d) 3039static int tx_config(pc300dev_t * d)
3039{ 3040{
3040 pc300ch_t *chan = (pc300ch_t *) d->chan; 3041 pc300ch_t *chan = (pc300ch_t *) d->chan;
3041 pc300_t *card = (pc300_t *) chan->card; 3042 pc300_t *card = (pc300_t *) chan->card;
@@ -3098,7 +3099,7 @@ static int cpc_attach(struct net_device *dev, unsigned short encoding,
3098 return 0; 3099 return 0;
3099} 3100}
3100 3101
3101void cpc_opench(pc300dev_t * d) 3102static void cpc_opench(pc300dev_t * d)
3102{ 3103{
3103 pc300ch_t *chan = (pc300ch_t *) d->chan; 3104 pc300ch_t *chan = (pc300ch_t *) d->chan;
3104 pc300_t *card = (pc300_t *) chan->card; 3105 pc300_t *card = (pc300_t *) chan->card;
@@ -3116,7 +3117,7 @@ void cpc_opench(pc300dev_t * d)
3116 cpc_readb(scabase + M_REG(CTL, ch)) & ~(CTL_RTS | CTL_DTR)); 3117 cpc_readb(scabase + M_REG(CTL, ch)) & ~(CTL_RTS | CTL_DTR));
3117} 3118}
3118 3119
3119void cpc_closech(pc300dev_t * d) 3120static void cpc_closech(pc300dev_t * d)
3120{ 3121{
3121 pc300ch_t *chan = (pc300ch_t *) d->chan; 3122 pc300ch_t *chan = (pc300ch_t *) d->chan;
3122 pc300_t *card = (pc300_t *) chan->card; 3123 pc300_t *card = (pc300_t *) chan->card;
@@ -3173,7 +3174,7 @@ int cpc_open(struct net_device *dev)
3173 return 0; 3174 return 0;
3174} 3175}
3175 3176
3176int cpc_close(struct net_device *dev) 3177static int cpc_close(struct net_device *dev)
3177{ 3178{
3178 hdlc_device *hdlc = dev_to_hdlc(dev); 3179 hdlc_device *hdlc = dev_to_hdlc(dev);
3179 pc300dev_t *d = (pc300dev_t *) dev->priv; 3180 pc300dev_t *d = (pc300dev_t *) dev->priv;
diff --git a/drivers/net/wan/pc300_tty.c b/drivers/net/wan/pc300_tty.c
index 8454bf6caaa7..52f26b9c69d2 100644
--- a/drivers/net/wan/pc300_tty.c
+++ b/drivers/net/wan/pc300_tty.c
@@ -112,10 +112,10 @@ typedef struct _st_cpc_tty_area {
112static struct tty_driver serial_drv; 112static struct tty_driver serial_drv;
113 113
114/* local variables */ 114/* local variables */
115st_cpc_tty_area cpc_tty_area[CPC_TTY_NPORTS]; 115static st_cpc_tty_area cpc_tty_area[CPC_TTY_NPORTS];
116 116
117int cpc_tty_cnt=0; /* number of intrfaces configured with MLPPP */ 117static int cpc_tty_cnt = 0; /* number of intrfaces configured with MLPPP */
118int cpc_tty_unreg_flag = 0; 118static int cpc_tty_unreg_flag = 0;
119 119
120/* TTY functions prototype */ 120/* TTY functions prototype */
121static int cpc_tty_open(struct tty_struct *tty, struct file *flip); 121static int cpc_tty_open(struct tty_struct *tty, struct file *flip);
@@ -132,9 +132,9 @@ static void cpc_tty_trace(pc300dev_t *dev, char* buf, int len, char rxtx);
132static void cpc_tty_signal_off(pc300dev_t *pc300dev, unsigned char); 132static void cpc_tty_signal_off(pc300dev_t *pc300dev, unsigned char);
133static void cpc_tty_signal_on(pc300dev_t *pc300dev, unsigned char); 133static void cpc_tty_signal_on(pc300dev_t *pc300dev, unsigned char);
134 134
135int pc300_tiocmset(struct tty_struct *, struct file *, 135static int pc300_tiocmset(struct tty_struct *, struct file *,
136 unsigned int, unsigned int); 136 unsigned int, unsigned int);
137int pc300_tiocmget(struct tty_struct *, struct file *); 137static int pc300_tiocmget(struct tty_struct *, struct file *);
138 138
139/* functions called by PC300 driver */ 139/* functions called by PC300 driver */
140void cpc_tty_init(pc300dev_t *dev); 140void cpc_tty_init(pc300dev_t *dev);
@@ -538,8 +538,8 @@ static int cpc_tty_chars_in_buffer(struct tty_struct *tty)
538 return(0); 538 return(0);
539} 539}
540 540
541int pc300_tiocmset(struct tty_struct *tty, struct file *file, 541static int pc300_tiocmset(struct tty_struct *tty, struct file *file,
542 unsigned int set, unsigned int clear) 542 unsigned int set, unsigned int clear)
543{ 543{
544 st_cpc_tty_area *cpc_tty; 544 st_cpc_tty_area *cpc_tty;
545 545
@@ -565,7 +565,7 @@ int pc300_tiocmset(struct tty_struct *tty, struct file *file,
565 return 0; 565 return 0;
566} 566}
567 567
568int pc300_tiocmget(struct tty_struct *tty, struct file *file) 568static int pc300_tiocmget(struct tty_struct *tty, struct file *file)
569{ 569{
570 unsigned int result; 570 unsigned int result;
571 unsigned char status; 571 unsigned char status;
diff --git a/drivers/net/wan/sdla.c b/drivers/net/wan/sdla.c
index 3ac9a45b20fa..036adc4f8ba7 100644
--- a/drivers/net/wan/sdla.c
+++ b/drivers/net/wan/sdla.c
@@ -182,7 +182,7 @@ static char sdla_byte(struct net_device *dev, int addr)
182 return(byte); 182 return(byte);
183} 183}
184 184
185void sdla_stop(struct net_device *dev) 185static void sdla_stop(struct net_device *dev)
186{ 186{
187 struct frad_local *flp; 187 struct frad_local *flp;
188 188
@@ -209,7 +209,7 @@ void sdla_stop(struct net_device *dev)
209 } 209 }
210} 210}
211 211
212void sdla_start(struct net_device *dev) 212static void sdla_start(struct net_device *dev)
213{ 213{
214 struct frad_local *flp; 214 struct frad_local *flp;
215 215
@@ -247,7 +247,7 @@ void sdla_start(struct net_device *dev)
247 * 247 *
248 ***************************************************/ 248 ***************************************************/
249 249
250int sdla_z80_poll(struct net_device *dev, int z80_addr, int jiffs, char resp1, char resp2) 250static int sdla_z80_poll(struct net_device *dev, int z80_addr, int jiffs, char resp1, char resp2)
251{ 251{
252 unsigned long start, done, now; 252 unsigned long start, done, now;
253 char resp, *temp; 253 char resp, *temp;
@@ -505,7 +505,7 @@ static int sdla_cmd(struct net_device *dev, int cmd, short dlci, short flags,
505 505
506static int sdla_reconfig(struct net_device *dev); 506static int sdla_reconfig(struct net_device *dev);
507 507
508int sdla_activate(struct net_device *slave, struct net_device *master) 508static int sdla_activate(struct net_device *slave, struct net_device *master)
509{ 509{
510 struct frad_local *flp; 510 struct frad_local *flp;
511 int i; 511 int i;
@@ -527,7 +527,7 @@ int sdla_activate(struct net_device *slave, struct net_device *master)
527 return(0); 527 return(0);
528} 528}
529 529
530int sdla_deactivate(struct net_device *slave, struct net_device *master) 530static int sdla_deactivate(struct net_device *slave, struct net_device *master)
531{ 531{
532 struct frad_local *flp; 532 struct frad_local *flp;
533 int i; 533 int i;
@@ -549,7 +549,7 @@ int sdla_deactivate(struct net_device *slave, struct net_device *master)
549 return(0); 549 return(0);
550} 550}
551 551
552int sdla_assoc(struct net_device *slave, struct net_device *master) 552static int sdla_assoc(struct net_device *slave, struct net_device *master)
553{ 553{
554 struct frad_local *flp; 554 struct frad_local *flp;
555 int i; 555 int i;
@@ -585,7 +585,7 @@ int sdla_assoc(struct net_device *slave, struct net_device *master)
585 return(0); 585 return(0);
586} 586}
587 587
588int sdla_deassoc(struct net_device *slave, struct net_device *master) 588static int sdla_deassoc(struct net_device *slave, struct net_device *master)
589{ 589{
590 struct frad_local *flp; 590 struct frad_local *flp;
591 int i; 591 int i;
@@ -613,7 +613,7 @@ int sdla_deassoc(struct net_device *slave, struct net_device *master)
613 return(0); 613 return(0);
614} 614}
615 615
616int sdla_dlci_conf(struct net_device *slave, struct net_device *master, int get) 616static int sdla_dlci_conf(struct net_device *slave, struct net_device *master, int get)
617{ 617{
618 struct frad_local *flp; 618 struct frad_local *flp;
619 struct dlci_local *dlp; 619 struct dlci_local *dlp;
@@ -1324,7 +1324,7 @@ NOTE: This is rather a useless action right now, as the
1324 return(0); 1324 return(0);
1325} 1325}
1326 1326
1327int sdla_change_mtu(struct net_device *dev, int new_mtu) 1327static int sdla_change_mtu(struct net_device *dev, int new_mtu)
1328{ 1328{
1329 struct frad_local *flp; 1329 struct frad_local *flp;
1330 1330
@@ -1337,7 +1337,7 @@ int sdla_change_mtu(struct net_device *dev, int new_mtu)
1337 return(-EOPNOTSUPP); 1337 return(-EOPNOTSUPP);
1338} 1338}
1339 1339
1340int sdla_set_config(struct net_device *dev, struct ifmap *map) 1340static int sdla_set_config(struct net_device *dev, struct ifmap *map)
1341{ 1341{
1342 struct frad_local *flp; 1342 struct frad_local *flp;
1343 int i; 1343 int i;
diff --git a/drivers/net/wan/sdla_fr.c b/drivers/net/wan/sdla_fr.c
index 0497dbdb8631..7f1ce9d4333e 100644
--- a/drivers/net/wan/sdla_fr.c
+++ b/drivers/net/wan/sdla_fr.c
@@ -822,7 +822,7 @@ static int new_if(struct wan_device* wandev, struct net_device* dev,
822 chan->card = card; 822 chan->card = card;
823 823
824 /* verify media address */ 824 /* verify media address */
825 if (is_digit(conf->addr[0])) { 825 if (isdigit(conf->addr[0])) {
826 826
827 dlci = dec_to_uint(conf->addr, 0); 827 dlci = dec_to_uint(conf->addr, 0);
828 828
@@ -3456,7 +3456,7 @@ static unsigned int dec_to_uint (unsigned char* str, int len)
3456 if (!len) 3456 if (!len)
3457 len = strlen(str); 3457 len = strlen(str);
3458 3458
3459 for (val = 0; len && is_digit(*str); ++str, --len) 3459 for (val = 0; len && isdigit(*str); ++str, --len)
3460 val = (val * 10) + (*str - (unsigned)'0'); 3460 val = (val * 10) + (*str - (unsigned)'0');
3461 3461
3462 return val; 3462 return val;
diff --git a/drivers/net/wan/sdla_x25.c b/drivers/net/wan/sdla_x25.c
index 8a95d61a2f8f..63f846d6f3a6 100644
--- a/drivers/net/wan/sdla_x25.c
+++ b/drivers/net/wan/sdla_x25.c
@@ -957,7 +957,7 @@ static int new_if(struct wan_device* wandev, struct net_device* dev,
957 chan->hold_timeout = (conf->hold_timeout) ? 957 chan->hold_timeout = (conf->hold_timeout) ?
958 conf->hold_timeout : 10; 958 conf->hold_timeout : 10;
959 959
960 }else if (is_digit(conf->addr[0])){ /* PVC */ 960 }else if (isdigit(conf->addr[0])){ /* PVC */
961 int lcn = dec_to_uint(conf->addr, 0); 961 int lcn = dec_to_uint(conf->addr, 0);
962 962
963 if ((lcn >= card->u.x.lo_pvc) && (lcn <= card->u.x.hi_pvc)){ 963 if ((lcn >= card->u.x.lo_pvc) && (lcn <= card->u.x.hi_pvc)){
@@ -3875,7 +3875,7 @@ static unsigned int dec_to_uint (unsigned char* str, int len)
3875 if (!len) 3875 if (!len)
3876 len = strlen(str); 3876 len = strlen(str);
3877 3877
3878 for (val = 0; len && is_digit(*str); ++str, --len) 3878 for (val = 0; len && isdigit(*str); ++str, --len)
3879 val = (val * 10) + (*str - (unsigned)'0'); 3879 val = (val * 10) + (*str - (unsigned)'0');
3880 3880
3881 return val; 3881 return val;
@@ -3896,9 +3896,9 @@ static unsigned int hex_to_uint (unsigned char* str, int len)
3896 for (val = 0; len; ++str, --len) 3896 for (val = 0; len; ++str, --len)
3897 { 3897 {
3898 ch = *str; 3898 ch = *str;
3899 if (is_digit(ch)) 3899 if (isdigit(ch))
3900 val = (val << 4) + (ch - (unsigned)'0'); 3900 val = (val << 4) + (ch - (unsigned)'0');
3901 else if (is_hex_digit(ch)) 3901 else if (isxdigit(ch))
3902 val = (val << 4) + ((ch & 0xDF) - (unsigned)'A' + 10); 3902 val = (val << 4) + ((ch & 0xDF) - (unsigned)'A' + 10);
3903 else break; 3903 else break;
3904 } 3904 }
diff --git a/drivers/net/wan/sdladrv.c b/drivers/net/wan/sdladrv.c
index c8bc6da57a41..7c2cf2e76300 100644
--- a/drivers/net/wan/sdladrv.c
+++ b/drivers/net/wan/sdladrv.c
@@ -642,9 +642,7 @@ int sdla_mapmem (sdlahw_t* hw, unsigned long addr)
642 * Enable interrupt generation. 642 * Enable interrupt generation.
643 */ 643 */
644 644
645EXPORT_SYMBOL(sdla_inten); 645static int sdla_inten (sdlahw_t* hw)
646
647int sdla_inten (sdlahw_t* hw)
648{ 646{
649 unsigned port = hw->port; 647 unsigned port = hw->port;
650 int tmp, i; 648 int tmp, i;
@@ -698,8 +696,7 @@ int sdla_inten (sdlahw_t* hw)
698 * Disable interrupt generation. 696 * Disable interrupt generation.
699 */ 697 */
700 698
701EXPORT_SYMBOL(sdla_intde); 699#if 0
702
703int sdla_intde (sdlahw_t* hw) 700int sdla_intde (sdlahw_t* hw)
704{ 701{
705 unsigned port = hw->port; 702 unsigned port = hw->port;
@@ -748,14 +745,13 @@ int sdla_intde (sdlahw_t* hw)
748 } 745 }
749 return 0; 746 return 0;
750} 747}
748#endif /* 0 */
751 749
752/*============================================================================ 750/*============================================================================
753 * Acknowledge SDLA hardware interrupt. 751 * Acknowledge SDLA hardware interrupt.
754 */ 752 */
755 753
756EXPORT_SYMBOL(sdla_intack); 754static int sdla_intack (sdlahw_t* hw)
757
758int sdla_intack (sdlahw_t* hw)
759{ 755{
760 unsigned port = hw->port; 756 unsigned port = hw->port;
761 int tmp; 757 int tmp;
@@ -827,8 +823,7 @@ void read_S514_int_stat (sdlahw_t* hw, u32* int_status)
827 * Generate an interrupt to adapter's CPU. 823 * Generate an interrupt to adapter's CPU.
828 */ 824 */
829 825
830EXPORT_SYMBOL(sdla_intr); 826#if 0
831
832int sdla_intr (sdlahw_t* hw) 827int sdla_intr (sdlahw_t* hw)
833{ 828{
834 unsigned port = hw->port; 829 unsigned port = hw->port;
@@ -863,6 +858,7 @@ int sdla_intr (sdlahw_t* hw)
863 } 858 }
864 return 0; 859 return 0;
865} 860}
861#endif /* 0 */
866 862
867/*============================================================================ 863/*============================================================================
868 * Execute Adapter Command. 864 * Execute Adapter Command.
diff --git a/drivers/net/wan/syncppp.c b/drivers/net/wan/syncppp.c
index a6d3b55013a5..2d1bba06a085 100644
--- a/drivers/net/wan/syncppp.c
+++ b/drivers/net/wan/syncppp.c
@@ -221,7 +221,7 @@ static void sppp_clear_timeout(struct sppp *p)
221 * here. 221 * here.
222 */ 222 */
223 223
224void sppp_input (struct net_device *dev, struct sk_buff *skb) 224static void sppp_input (struct net_device *dev, struct sk_buff *skb)
225{ 225{
226 struct ppp_header *h; 226 struct ppp_header *h;
227 struct sppp *sp = (struct sppp *)sppp_of(dev); 227 struct sppp *sp = (struct sppp *)sppp_of(dev);
@@ -355,8 +355,6 @@ done:
355 return; 355 return;
356} 356}
357 357
358EXPORT_SYMBOL(sppp_input);
359
360/* 358/*
361 * Handle transmit packets. 359 * Handle transmit packets.
362 */ 360 */
@@ -990,7 +988,7 @@ EXPORT_SYMBOL(sppp_reopen);
990 * the mtu is out of range. 988 * the mtu is out of range.
991 */ 989 */
992 990
993int sppp_change_mtu(struct net_device *dev, int new_mtu) 991static int sppp_change_mtu(struct net_device *dev, int new_mtu)
994{ 992{
995 if(new_mtu<128||new_mtu>PPP_MTU||(dev->flags&IFF_UP)) 993 if(new_mtu<128||new_mtu>PPP_MTU||(dev->flags&IFF_UP))
996 return -EINVAL; 994 return -EINVAL;
@@ -998,8 +996,6 @@ int sppp_change_mtu(struct net_device *dev, int new_mtu)
998 return 0; 996 return 0;
999} 997}
1000 998
1001EXPORT_SYMBOL(sppp_change_mtu);
1002
1003/** 999/**
1004 * sppp_do_ioctl - Ioctl handler for ppp/hdlc 1000 * sppp_do_ioctl - Ioctl handler for ppp/hdlc
1005 * @dev: Device subject to ioctl 1001 * @dev: Device subject to ioctl
@@ -1456,7 +1452,7 @@ static int sppp_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_t
1456 return 0; 1452 return 0;
1457} 1453}
1458 1454
1459struct packet_type sppp_packet_type = { 1455static struct packet_type sppp_packet_type = {
1460 .type = __constant_htons(ETH_P_WAN_PPP), 1456 .type = __constant_htons(ETH_P_WAN_PPP),
1461 .func = sppp_rcv, 1457 .func = sppp_rcv,
1462}; 1458};
diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index 06998c2240d9..750c0167539c 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -35,6 +35,7 @@
35#include <linux/interrupt.h> 35#include <linux/interrupt.h>
36#include <linux/in.h> 36#include <linux/in.h>
37#include <linux/bitops.h> 37#include <linux/bitops.h>
38#include <linux/scatterlist.h>
38#include <asm/io.h> 39#include <asm/io.h>
39#include <asm/system.h> 40#include <asm/system.h>
40 41
@@ -1046,7 +1047,6 @@ static WifiCtlHdr wifictlhdr8023 = {
1046 } 1047 }
1047}; 1048};
1048 1049
1049#ifdef WIRELESS_EXT
1050// Frequency list (map channels to frequencies) 1050// Frequency list (map channels to frequencies)
1051static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442, 1051static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
1052 2447, 2452, 2457, 2462, 2467, 2472, 2484 }; 1052 2447, 2452, 2457, 2462, 2467, 2472, 2484 };
@@ -1067,7 +1067,6 @@ typedef struct wep_key_t {
1067 1067
1068/* List of Wireless Handlers (new API) */ 1068/* List of Wireless Handlers (new API) */
1069static const struct iw_handler_def airo_handler_def; 1069static const struct iw_handler_def airo_handler_def;
1070#endif /* WIRELESS_EXT */
1071 1070
1072static const char version[] = "airo.c 0.6 (Ben Reed & Javier Achirica)"; 1071static const char version[] = "airo.c 0.6 (Ben Reed & Javier Achirica)";
1073 1072
@@ -1110,10 +1109,8 @@ static irqreturn_t airo_interrupt( int irq, void* dev_id, struct pt_regs
1110static int airo_thread(void *data); 1109static int airo_thread(void *data);
1111static void timer_func( struct net_device *dev ); 1110static void timer_func( struct net_device *dev );
1112static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 1111static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
1113#ifdef WIRELESS_EXT
1114static struct iw_statistics *airo_get_wireless_stats (struct net_device *dev); 1112static struct iw_statistics *airo_get_wireless_stats (struct net_device *dev);
1115static void airo_read_wireless_stats (struct airo_info *local); 1113static void airo_read_wireless_stats (struct airo_info *local);
1116#endif /* WIRELESS_EXT */
1117#ifdef CISCO_EXT 1114#ifdef CISCO_EXT
1118static int readrids(struct net_device *dev, aironet_ioctl *comp); 1115static int readrids(struct net_device *dev, aironet_ioctl *comp);
1119static int writerids(struct net_device *dev, aironet_ioctl *comp); 1116static int writerids(struct net_device *dev, aironet_ioctl *comp);
@@ -1187,12 +1184,10 @@ struct airo_info {
1187 int fid; 1184 int fid;
1188 } xmit, xmit11; 1185 } xmit, xmit11;
1189 struct net_device *wifidev; 1186 struct net_device *wifidev;
1190#ifdef WIRELESS_EXT
1191 struct iw_statistics wstats; // wireless stats 1187 struct iw_statistics wstats; // wireless stats
1192 unsigned long scan_timestamp; /* Time started to scan */ 1188 unsigned long scan_timestamp; /* Time started to scan */
1193 struct iw_spy_data spy_data; 1189 struct iw_spy_data spy_data;
1194 struct iw_public_data wireless_data; 1190 struct iw_public_data wireless_data;
1195#endif /* WIRELESS_EXT */
1196#ifdef MICSUPPORT 1191#ifdef MICSUPPORT
1197 /* MIC stuff */ 1192 /* MIC stuff */
1198 struct crypto_tfm *tfm; 1193 struct crypto_tfm *tfm;
@@ -1596,11 +1591,9 @@ static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct
1596 aes_counter[12] = (u8)(counter >> 24); 1591 aes_counter[12] = (u8)(counter >> 24);
1597 counter++; 1592 counter++;
1598 memcpy (plain, aes_counter, 16); 1593 memcpy (plain, aes_counter, 16);
1599 sg[0].page = virt_to_page(plain); 1594 sg_set_buf(sg, plain, 16);
1600 sg[0].offset = ((long) plain & ~PAGE_MASK);
1601 sg[0].length = 16;
1602 crypto_cipher_encrypt(tfm, sg, sg, 16); 1595 crypto_cipher_encrypt(tfm, sg, sg, 16);
1603 cipher = kmap(sg[0].page) + sg[0].offset; 1596 cipher = kmap(sg->page) + sg->offset;
1604 for (j=0; (j<16) && (i< (sizeof(context->coeff)/sizeof(context->coeff[0]))); ) { 1597 for (j=0; (j<16) && (i< (sizeof(context->coeff)/sizeof(context->coeff[0]))); ) {
1605 context->coeff[i++] = ntohl(*(u32 *)&cipher[j]); 1598 context->coeff[i++] = ntohl(*(u32 *)&cipher[j]);
1606 j += 4; 1599 j += 4;
@@ -2387,14 +2380,10 @@ void stop_airo_card( struct net_device *dev, int freeres )
2387 dev_kfree_skb(skb); 2380 dev_kfree_skb(skb);
2388 } 2381 }
2389 2382
2390 if (ai->flash) 2383 kfree(ai->flash);
2391 kfree(ai->flash); 2384 kfree(ai->rssi);
2392 if (ai->rssi) 2385 kfree(ai->APList);
2393 kfree(ai->rssi); 2386 kfree(ai->SSID);
2394 if (ai->APList)
2395 kfree(ai->APList);
2396 if (ai->SSID)
2397 kfree(ai->SSID);
2398 if (freeres) { 2387 if (freeres) {
2399 /* PCMCIA frees this stuff, so only for PCI and ISA */ 2388 /* PCMCIA frees this stuff, so only for PCI and ISA */
2400 release_region( dev->base_addr, 64 ); 2389 release_region( dev->base_addr, 64 );
@@ -2527,7 +2516,8 @@ static int mpi_map_card(struct airo_info *ai, struct pci_dev *pci,
2527 unsigned long mem_start, mem_len, aux_start, aux_len; 2516 unsigned long mem_start, mem_len, aux_start, aux_len;
2528 int rc = -1; 2517 int rc = -1;
2529 int i; 2518 int i;
2530 unsigned char *busaddroff,*vpackoff; 2519 dma_addr_t busaddroff;
2520 unsigned char *vpackoff;
2531 unsigned char __iomem *pciaddroff; 2521 unsigned char __iomem *pciaddroff;
2532 2522
2533 mem_start = pci_resource_start(pci, 1); 2523 mem_start = pci_resource_start(pci, 1);
@@ -2570,7 +2560,7 @@ static int mpi_map_card(struct airo_info *ai, struct pci_dev *pci,
2570 /* 2560 /*
2571 * Setup descriptor RX, TX, CONFIG 2561 * Setup descriptor RX, TX, CONFIG
2572 */ 2562 */
2573 busaddroff = (unsigned char *)ai->shared_dma; 2563 busaddroff = ai->shared_dma;
2574 pciaddroff = ai->pciaux + AUX_OFFSET; 2564 pciaddroff = ai->pciaux + AUX_OFFSET;
2575 vpackoff = ai->shared; 2565 vpackoff = ai->shared;
2576 2566
@@ -2579,7 +2569,7 @@ static int mpi_map_card(struct airo_info *ai, struct pci_dev *pci,
2579 ai->rxfids[i].pending = 0; 2569 ai->rxfids[i].pending = 0;
2580 ai->rxfids[i].card_ram_off = pciaddroff; 2570 ai->rxfids[i].card_ram_off = pciaddroff;
2581 ai->rxfids[i].virtual_host_addr = vpackoff; 2571 ai->rxfids[i].virtual_host_addr = vpackoff;
2582 ai->rxfids[i].rx_desc.host_addr = (dma_addr_t) busaddroff; 2572 ai->rxfids[i].rx_desc.host_addr = busaddroff;
2583 ai->rxfids[i].rx_desc.valid = 1; 2573 ai->rxfids[i].rx_desc.valid = 1;
2584 ai->rxfids[i].rx_desc.len = PKTSIZE; 2574 ai->rxfids[i].rx_desc.len = PKTSIZE;
2585 ai->rxfids[i].rx_desc.rdy = 0; 2575 ai->rxfids[i].rx_desc.rdy = 0;
@@ -2594,7 +2584,7 @@ static int mpi_map_card(struct airo_info *ai, struct pci_dev *pci,
2594 ai->txfids[i].card_ram_off = pciaddroff; 2584 ai->txfids[i].card_ram_off = pciaddroff;
2595 ai->txfids[i].virtual_host_addr = vpackoff; 2585 ai->txfids[i].virtual_host_addr = vpackoff;
2596 ai->txfids[i].tx_desc.valid = 1; 2586 ai->txfids[i].tx_desc.valid = 1;
2597 ai->txfids[i].tx_desc.host_addr = (dma_addr_t) busaddroff; 2587 ai->txfids[i].tx_desc.host_addr = busaddroff;
2598 memcpy(ai->txfids[i].virtual_host_addr, 2588 memcpy(ai->txfids[i].virtual_host_addr,
2599 &wifictlhdr8023, sizeof(wifictlhdr8023)); 2589 &wifictlhdr8023, sizeof(wifictlhdr8023));
2600 2590
@@ -2607,8 +2597,8 @@ static int mpi_map_card(struct airo_info *ai, struct pci_dev *pci,
2607 /* Rid descriptor setup */ 2597 /* Rid descriptor setup */
2608 ai->config_desc.card_ram_off = pciaddroff; 2598 ai->config_desc.card_ram_off = pciaddroff;
2609 ai->config_desc.virtual_host_addr = vpackoff; 2599 ai->config_desc.virtual_host_addr = vpackoff;
2610 ai->config_desc.rid_desc.host_addr = (dma_addr_t) busaddroff; 2600 ai->config_desc.rid_desc.host_addr = busaddroff;
2611 ai->ridbus = (dma_addr_t)busaddroff; 2601 ai->ridbus = busaddroff;
2612 ai->config_desc.rid_desc.rid = 0; 2602 ai->config_desc.rid_desc.rid = 0;
2613 ai->config_desc.rid_desc.len = RIDSIZE; 2603 ai->config_desc.rid_desc.len = RIDSIZE;
2614 ai->config_desc.rid_desc.valid = 1; 2604 ai->config_desc.rid_desc.valid = 1;
@@ -2647,9 +2637,7 @@ static void wifi_setup(struct net_device *dev)
2647 dev->get_stats = &airo_get_stats; 2637 dev->get_stats = &airo_get_stats;
2648 dev->set_mac_address = &airo_set_mac_address; 2638 dev->set_mac_address = &airo_set_mac_address;
2649 dev->do_ioctl = &airo_ioctl; 2639 dev->do_ioctl = &airo_ioctl;
2650#ifdef WIRELESS_EXT
2651 dev->wireless_handlers = &airo_handler_def; 2640 dev->wireless_handlers = &airo_handler_def;
2652#endif /* WIRELESS_EXT */
2653 dev->change_mtu = &airo_change_mtu; 2641 dev->change_mtu = &airo_change_mtu;
2654 dev->open = &airo_open; 2642 dev->open = &airo_open;
2655 dev->stop = &airo_close; 2643 dev->stop = &airo_close;
@@ -2675,9 +2663,7 @@ static struct net_device *init_wifidev(struct airo_info *ai,
2675 dev->priv = ethdev->priv; 2663 dev->priv = ethdev->priv;
2676 dev->irq = ethdev->irq; 2664 dev->irq = ethdev->irq;
2677 dev->base_addr = ethdev->base_addr; 2665 dev->base_addr = ethdev->base_addr;
2678#ifdef WIRELESS_EXT
2679 dev->wireless_data = ethdev->wireless_data; 2666 dev->wireless_data = ethdev->wireless_data;
2680#endif /* WIRELESS_EXT */
2681 memcpy(dev->dev_addr, ethdev->dev_addr, dev->addr_len); 2667 memcpy(dev->dev_addr, ethdev->dev_addr, dev->addr_len);
2682 err = register_netdev(dev); 2668 err = register_netdev(dev);
2683 if (err<0) { 2669 if (err<0) {
@@ -2755,11 +2741,9 @@ static struct net_device *_init_airo_card( unsigned short irq, int port,
2755 dev->set_multicast_list = &airo_set_multicast_list; 2741 dev->set_multicast_list = &airo_set_multicast_list;
2756 dev->set_mac_address = &airo_set_mac_address; 2742 dev->set_mac_address = &airo_set_mac_address;
2757 dev->do_ioctl = &airo_ioctl; 2743 dev->do_ioctl = &airo_ioctl;
2758#ifdef WIRELESS_EXT
2759 dev->wireless_handlers = &airo_handler_def; 2744 dev->wireless_handlers = &airo_handler_def;
2760 ai->wireless_data.spy_data = &ai->spy_data; 2745 ai->wireless_data.spy_data = &ai->spy_data;
2761 dev->wireless_data = &ai->wireless_data; 2746 dev->wireless_data = &ai->wireless_data;
2762#endif /* WIRELESS_EXT */
2763 dev->change_mtu = &airo_change_mtu; 2747 dev->change_mtu = &airo_change_mtu;
2764 dev->open = &airo_open; 2748 dev->open = &airo_open;
2765 dev->stop = &airo_close; 2749 dev->stop = &airo_close;
@@ -3637,10 +3621,8 @@ static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
3637 int rc; 3621 int rc;
3638 3622
3639 memset( &mySsid, 0, sizeof( mySsid ) ); 3623 memset( &mySsid, 0, sizeof( mySsid ) );
3640 if (ai->flash) { 3624 kfree (ai->flash);
3641 kfree (ai->flash); 3625 ai->flash = NULL;
3642 ai->flash = NULL;
3643 }
3644 3626
3645 /* The NOP is the first step in getting the card going */ 3627 /* The NOP is the first step in getting the card going */
3646 cmd.cmd = NOP; 3628 cmd.cmd = NOP;
@@ -3677,14 +3659,10 @@ static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
3677 tdsRssiRid rssi_rid; 3659 tdsRssiRid rssi_rid;
3678 CapabilityRid cap_rid; 3660 CapabilityRid cap_rid;
3679 3661
3680 if (ai->APList) { 3662 kfree(ai->APList);
3681 kfree(ai->APList); 3663 ai->APList = NULL;
3682 ai->APList = NULL; 3664 kfree(ai->SSID);
3683 } 3665 ai->SSID = NULL;
3684 if (ai->SSID) {
3685 kfree(ai->SSID);
3686 ai->SSID = NULL;
3687 }
3688 // general configuration (read/modify/write) 3666 // general configuration (read/modify/write)
3689 status = readConfigRid(ai, lock); 3667 status = readConfigRid(ai, lock);
3690 if ( status != SUCCESS ) return ERROR; 3668 if ( status != SUCCESS ) return ERROR;
@@ -3698,10 +3676,8 @@ static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
3698 memcpy(ai->rssi, (u8*)&rssi_rid + 2, 512); /* Skip RID length member */ 3676 memcpy(ai->rssi, (u8*)&rssi_rid + 2, 512); /* Skip RID length member */
3699 } 3677 }
3700 else { 3678 else {
3701 if (ai->rssi) { 3679 kfree(ai->rssi);
3702 kfree(ai->rssi); 3680 ai->rssi = NULL;
3703 ai->rssi = NULL;
3704 }
3705 if (cap_rid.softCap & 8) 3681 if (cap_rid.softCap & 8)
3706 ai->config.rmode |= RXMODE_NORMALIZED_RSSI; 3682 ai->config.rmode |= RXMODE_NORMALIZED_RSSI;
3707 else 3683 else
@@ -5380,11 +5356,13 @@ static int proc_BSSList_open( struct inode *inode, struct file *file ) {
5380 5356
5381static int proc_close( struct inode *inode, struct file *file ) 5357static int proc_close( struct inode *inode, struct file *file )
5382{ 5358{
5383 struct proc_data *data = (struct proc_data *)file->private_data; 5359 struct proc_data *data = file->private_data;
5384 if ( data->on_close != NULL ) data->on_close( inode, file ); 5360
5385 if ( data->rbuffer ) kfree( data->rbuffer ); 5361 if (data->on_close != NULL)
5386 if ( data->wbuffer ) kfree( data->wbuffer ); 5362 data->on_close(inode, file);
5387 kfree( data ); 5363 kfree(data->rbuffer);
5364 kfree(data->wbuffer);
5365 kfree(data);
5388 return 0; 5366 return 0;
5389} 5367}
5390 5368
@@ -5515,12 +5493,13 @@ static int airo_pci_resume(struct pci_dev *pdev)
5515 struct net_device *dev = pci_get_drvdata(pdev); 5493 struct net_device *dev = pci_get_drvdata(pdev);
5516 struct airo_info *ai = dev->priv; 5494 struct airo_info *ai = dev->priv;
5517 Resp rsp; 5495 Resp rsp;
5496 pci_power_t prev_state = pdev->current_state;
5518 5497
5519 pci_set_power_state(pdev, 0); 5498 pci_set_power_state(pdev, PCI_D0);
5520 pci_restore_state(pdev); 5499 pci_restore_state(pdev);
5521 pci_enable_wake(pdev, pci_choose_state(pdev, ai->power), 0); 5500 pci_enable_wake(pdev, PCI_D0, 0);
5522 5501
5523 if (ai->power.event > 1) { 5502 if (prev_state != PCI_D1) {
5524 reset_card(dev, 0); 5503 reset_card(dev, 0);
5525 mpi_init_descriptors(ai); 5504 mpi_init_descriptors(ai);
5526 setup_card(ai, dev->dev_addr, 0); 5505 setup_card(ai, dev->dev_addr, 0);
@@ -5598,7 +5577,6 @@ static void __exit airo_cleanup_module( void )
5598 remove_proc_entry("aironet", proc_root_driver); 5577 remove_proc_entry("aironet", proc_root_driver);
5599} 5578}
5600 5579
5601#ifdef WIRELESS_EXT
5602/* 5580/*
5603 * Initial Wireless Extension code for Aironet driver by : 5581 * Initial Wireless Extension code for Aironet driver by :
5604 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00 5582 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
@@ -7107,8 +7085,6 @@ static const struct iw_handler_def airo_handler_def =
7107 .get_wireless_stats = airo_get_wireless_stats, 7085 .get_wireless_stats = airo_get_wireless_stats,
7108}; 7086};
7109 7087
7110#endif /* WIRELESS_EXT */
7111
7112/* 7088/*
7113 * This defines the configuration part of the Wireless Extensions 7089 * This defines the configuration part of the Wireless Extensions
7114 * Note : irq and spinlock protection will occur in the subroutines 7090 * Note : irq and spinlock protection will occur in the subroutines
@@ -7187,7 +7163,6 @@ static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
7187 return rc; 7163 return rc;
7188} 7164}
7189 7165
7190#ifdef WIRELESS_EXT
7191/* 7166/*
7192 * Get the Wireless stats out of the driver 7167 * Get the Wireless stats out of the driver
7193 * Note : irq and spinlock protection will occur in the subroutines 7168 * Note : irq and spinlock protection will occur in the subroutines
@@ -7260,7 +7235,6 @@ static struct iw_statistics *airo_get_wireless_stats(struct net_device *dev)
7260 7235
7261 return &local->wstats; 7236 return &local->wstats;
7262} 7237}
7263#endif /* WIRELESS_EXT */
7264 7238
7265#ifdef CISCO_EXT 7239#ifdef CISCO_EXT
7266/* 7240/*
diff --git a/drivers/net/wireless/airo_cs.c b/drivers/net/wireless/airo_cs.c
index bf25584d68d3..784de9109113 100644
--- a/drivers/net/wireless/airo_cs.c
+++ b/drivers/net/wireless/airo_cs.c
@@ -258,9 +258,7 @@ static void airo_detach(dev_link_t *link)
258 258
259 /* Unlink device structure, free pieces */ 259 /* Unlink device structure, free pieces */
260 *linkp = link->next; 260 *linkp = link->next;
261 if (link->priv) { 261 kfree(link->priv);
262 kfree(link->priv);
263 }
264 kfree(link); 262 kfree(link);
265 263
266} /* airo_detach */ 264} /* airo_detach */
diff --git a/drivers/net/wireless/airport.c b/drivers/net/wireless/airport.c
index 9d496703c465..7b321f7cf358 100644
--- a/drivers/net/wireless/airport.c
+++ b/drivers/net/wireless/airport.c
@@ -15,28 +15,11 @@
15#define PFX DRIVER_NAME ": " 15#define PFX DRIVER_NAME ": "
16 16
17#include <linux/config.h> 17#include <linux/config.h>
18
19#include <linux/module.h> 18#include <linux/module.h>
20#include <linux/kernel.h> 19#include <linux/kernel.h>
21#include <linux/init.h> 20#include <linux/init.h>
22#include <linux/ptrace.h> 21#include <linux/delay.h>
23#include <linux/slab.h>
24#include <linux/string.h>
25#include <linux/timer.h>
26#include <linux/ioport.h>
27#include <linux/netdevice.h>
28#include <linux/if_arp.h>
29#include <linux/etherdevice.h>
30#include <linux/wireless.h>
31
32#include <asm/io.h>
33#include <asm/system.h>
34#include <asm/current.h>
35#include <asm/prom.h>
36#include <asm/machdep.h>
37#include <asm/pmac_feature.h> 22#include <asm/pmac_feature.h>
38#include <asm/irq.h>
39#include <asm/uaccess.h>
40 23
41#include "orinoco.h" 24#include "orinoco.h"
42 25
diff --git a/drivers/net/wireless/atmel.c b/drivers/net/wireless/atmel.c
index 587869d86eee..1fbe027d26b6 100644
--- a/drivers/net/wireless/atmel.c
+++ b/drivers/net/wireless/atmel.c
@@ -618,12 +618,12 @@ static int atmel_lock_mac(struct atmel_private *priv);
618static void atmel_wmem32(struct atmel_private *priv, u16 pos, u32 data); 618static void atmel_wmem32(struct atmel_private *priv, u16 pos, u32 data);
619static void atmel_command_irq(struct atmel_private *priv); 619static void atmel_command_irq(struct atmel_private *priv);
620static int atmel_validate_channel(struct atmel_private *priv, int channel); 620static int atmel_validate_channel(struct atmel_private *priv, int channel);
621static void atmel_management_frame(struct atmel_private *priv, struct ieee80211_hdr *header, 621static void atmel_management_frame(struct atmel_private *priv, struct ieee80211_hdr_4addr *header,
622 u16 frame_len, u8 rssi); 622 u16 frame_len, u8 rssi);
623static void atmel_management_timer(u_long a); 623static void atmel_management_timer(u_long a);
624static void atmel_send_command(struct atmel_private *priv, int command, void *cmd, int cmd_size); 624static void atmel_send_command(struct atmel_private *priv, int command, void *cmd, int cmd_size);
625static int atmel_send_command_wait(struct atmel_private *priv, int command, void *cmd, int cmd_size); 625static int atmel_send_command_wait(struct atmel_private *priv, int command, void *cmd, int cmd_size);
626static void atmel_transmit_management_frame(struct atmel_private *priv, struct ieee80211_hdr *header, 626static void atmel_transmit_management_frame(struct atmel_private *priv, struct ieee80211_hdr_4addr *header,
627 u8 *body, int body_len); 627 u8 *body, int body_len);
628 628
629static u8 atmel_get_mib8(struct atmel_private *priv, u8 type, u8 index); 629static u8 atmel_get_mib8(struct atmel_private *priv, u8 type, u8 index);
@@ -827,7 +827,7 @@ static void tx_update_descriptor(struct atmel_private *priv, int is_bcast, u16 l
827static int start_tx (struct sk_buff *skb, struct net_device *dev) 827static int start_tx (struct sk_buff *skb, struct net_device *dev)
828{ 828{
829 struct atmel_private *priv = netdev_priv(dev); 829 struct atmel_private *priv = netdev_priv(dev);
830 struct ieee80211_hdr header; 830 struct ieee80211_hdr_4addr header;
831 unsigned long flags; 831 unsigned long flags;
832 u16 buff, frame_ctl, len = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN; 832 u16 buff, frame_ctl, len = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN;
833 u8 SNAP_RFC1024[6] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00}; 833 u8 SNAP_RFC1024[6] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
@@ -902,7 +902,7 @@ static int start_tx (struct sk_buff *skb, struct net_device *dev)
902} 902}
903 903
904static void atmel_transmit_management_frame(struct atmel_private *priv, 904static void atmel_transmit_management_frame(struct atmel_private *priv,
905 struct ieee80211_hdr *header, 905 struct ieee80211_hdr_4addr *header,
906 u8 *body, int body_len) 906 u8 *body, int body_len)
907{ 907{
908 u16 buff; 908 u16 buff;
@@ -917,7 +917,7 @@ static void atmel_transmit_management_frame(struct atmel_private *priv,
917 tx_update_descriptor(priv, header->addr1[0] & 0x01, len, buff, TX_PACKET_TYPE_MGMT); 917 tx_update_descriptor(priv, header->addr1[0] & 0x01, len, buff, TX_PACKET_TYPE_MGMT);
918} 918}
919 919
920static void fast_rx_path(struct atmel_private *priv, struct ieee80211_hdr *header, 920static void fast_rx_path(struct atmel_private *priv, struct ieee80211_hdr_4addr *header,
921 u16 msdu_size, u16 rx_packet_loc, u32 crc) 921 u16 msdu_size, u16 rx_packet_loc, u32 crc)
922{ 922{
923 /* fast path: unfragmented packet copy directly into skbuf */ 923 /* fast path: unfragmented packet copy directly into skbuf */
@@ -990,7 +990,7 @@ static int probe_crc(struct atmel_private *priv, u16 packet_loc, u16 msdu_size)
990 return (crc ^ 0xffffffff) == netcrc; 990 return (crc ^ 0xffffffff) == netcrc;
991} 991}
992 992
993static void frag_rx_path(struct atmel_private *priv, struct ieee80211_hdr *header, 993static void frag_rx_path(struct atmel_private *priv, struct ieee80211_hdr_4addr *header,
994 u16 msdu_size, u16 rx_packet_loc, u32 crc, u16 seq_no, u8 frag_no, int more_frags) 994 u16 msdu_size, u16 rx_packet_loc, u32 crc, u16 seq_no, u8 frag_no, int more_frags)
995{ 995{
996 u8 mac4[6]; 996 u8 mac4[6];
@@ -1082,7 +1082,7 @@ static void frag_rx_path(struct atmel_private *priv, struct ieee80211_hdr *heade
1082static void rx_done_irq(struct atmel_private *priv) 1082static void rx_done_irq(struct atmel_private *priv)
1083{ 1083{
1084 int i; 1084 int i;
1085 struct ieee80211_hdr header; 1085 struct ieee80211_hdr_4addr header;
1086 1086
1087 for (i = 0; 1087 for (i = 0;
1088 atmel_rmem8(priv, atmel_rx(priv, RX_DESC_FLAGS_OFFSET, priv->rx_desc_head)) == RX_DESC_FLAG_VALID && 1088 atmel_rmem8(priv, atmel_rx(priv, RX_DESC_FLAGS_OFFSET, priv->rx_desc_head)) == RX_DESC_FLAG_VALID &&
@@ -1653,8 +1653,7 @@ void stop_atmel_card(struct net_device *dev, int freeres)
1653 unregister_netdev(dev); 1653 unregister_netdev(dev);
1654 remove_proc_entry("driver/atmel", NULL); 1654 remove_proc_entry("driver/atmel", NULL);
1655 free_irq(dev->irq, dev); 1655 free_irq(dev->irq, dev);
1656 if (priv->firmware) 1656 kfree(priv->firmware);
1657 kfree(priv->firmware);
1658 if (freeres) { 1657 if (freeres) {
1659 /* PCMCIA frees this stuff, so only for PCI */ 1658 /* PCMCIA frees this stuff, so only for PCI */
1660 release_region(dev->base_addr, 64); 1659 release_region(dev->base_addr, 64);
@@ -2450,8 +2449,7 @@ static int atmel_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2450 break; 2449 break;
2451 } 2450 }
2452 2451
2453 if (priv->firmware) 2452 kfree(priv->firmware);
2454 kfree(priv->firmware);
2455 2453
2456 priv->firmware = new_firmware; 2454 priv->firmware = new_firmware;
2457 priv->firmware_length = com.len; 2455 priv->firmware_length = com.len;
@@ -2650,7 +2648,7 @@ static void handle_beacon_probe(struct atmel_private *priv, u16 capability, u8 c
2650 2648
2651static void send_authentication_request(struct atmel_private *priv, u8 *challenge, int challenge_len) 2649static void send_authentication_request(struct atmel_private *priv, u8 *challenge, int challenge_len)
2652{ 2650{
2653 struct ieee80211_hdr header; 2651 struct ieee80211_hdr_4addr header;
2654 struct auth_body auth; 2652 struct auth_body auth;
2655 2653
2656 header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH); 2654 header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH);
@@ -2688,7 +2686,7 @@ static void send_association_request(struct atmel_private *priv, int is_reassoc)
2688{ 2686{
2689 u8 *ssid_el_p; 2687 u8 *ssid_el_p;
2690 int bodysize; 2688 int bodysize;
2691 struct ieee80211_hdr header; 2689 struct ieee80211_hdr_4addr header;
2692 struct ass_req_format { 2690 struct ass_req_format {
2693 u16 capability; 2691 u16 capability;
2694 u16 listen_interval; 2692 u16 listen_interval;
@@ -2738,7 +2736,7 @@ static void send_association_request(struct atmel_private *priv, int is_reassoc)
2738 atmel_transmit_management_frame(priv, &header, (void *)&body, bodysize); 2736 atmel_transmit_management_frame(priv, &header, (void *)&body, bodysize);
2739} 2737}
2740 2738
2741static int is_frame_from_current_bss(struct atmel_private *priv, struct ieee80211_hdr *header) 2739static int is_frame_from_current_bss(struct atmel_private *priv, struct ieee80211_hdr_4addr *header)
2742{ 2740{
2743 if (le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_FROMDS) 2741 if (le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_FROMDS)
2744 return memcmp(header->addr3, priv->CurrentBSSID, 6) == 0; 2742 return memcmp(header->addr3, priv->CurrentBSSID, 6) == 0;
@@ -2788,7 +2786,7 @@ static int retrieve_bss(struct atmel_private *priv)
2788} 2786}
2789 2787
2790 2788
2791static void store_bss_info(struct atmel_private *priv, struct ieee80211_hdr *header, 2789static void store_bss_info(struct atmel_private *priv, struct ieee80211_hdr_4addr *header,
2792 u16 capability, u16 beacon_period, u8 channel, u8 rssi, 2790 u16 capability, u16 beacon_period, u8 channel, u8 rssi,
2793 u8 ssid_len, u8 *ssid, int is_beacon) 2791 u8 ssid_len, u8 *ssid, int is_beacon)
2794{ 2792{
@@ -3072,7 +3070,7 @@ static void atmel_smooth_qual(struct atmel_private *priv)
3072} 3070}
3073 3071
3074/* deals with incoming managment frames. */ 3072/* deals with incoming managment frames. */
3075static void atmel_management_frame(struct atmel_private *priv, struct ieee80211_hdr *header, 3073static void atmel_management_frame(struct atmel_private *priv, struct ieee80211_hdr_4addr *header,
3076 u16 frame_len, u8 rssi) 3074 u16 frame_len, u8 rssi)
3077{ 3075{
3078 u16 subtype; 3076 u16 subtype;
diff --git a/drivers/net/wireless/atmel_cs.c b/drivers/net/wireless/atmel_cs.c
index ff031a3985b3..195cb36619e8 100644
--- a/drivers/net/wireless/atmel_cs.c
+++ b/drivers/net/wireless/atmel_cs.c
@@ -259,8 +259,7 @@ static void atmel_detach(dev_link_t *link)
259 259
260 /* Unlink device structure, free pieces */ 260 /* Unlink device structure, free pieces */
261 *linkp = link->next; 261 *linkp = link->next;
262 if (link->priv) 262 kfree(link->priv);
263 kfree(link->priv);
264 kfree(link); 263 kfree(link);
265} 264}
266 265
diff --git a/drivers/net/wireless/hermes.c b/drivers/net/wireless/hermes.c
index 21c3d0d227e6..579480dad374 100644
--- a/drivers/net/wireless/hermes.c
+++ b/drivers/net/wireless/hermes.c
@@ -39,17 +39,10 @@
39 */ 39 */
40 40
41#include <linux/config.h> 41#include <linux/config.h>
42
43#include <linux/module.h> 42#include <linux/module.h>
44#include <linux/types.h>
45#include <linux/threads.h>
46#include <linux/smp.h>
47#include <asm/io.h>
48#include <linux/delay.h>
49#include <linux/init.h>
50#include <linux/kernel.h> 43#include <linux/kernel.h>
51#include <linux/net.h> 44#include <linux/init.h>
52#include <asm/errno.h> 45#include <linux/delay.h>
53 46
54#include "hermes.h" 47#include "hermes.h"
55 48
@@ -451,6 +444,43 @@ int hermes_bap_pwrite(hermes_t *hw, int bap, const void *buf, unsigned len,
451 return err; 444 return err;
452} 445}
453 446
447/* Write a block of data to the chip's buffer with padding if
448 * neccessary, via the BAP. Synchronization/serialization is the
449 * caller's problem. len must be even.
450 *
451 * Returns: < 0 on internal failure (errno), 0 on success, > 0 on error from firmware
452 */
453int hermes_bap_pwrite_pad(hermes_t *hw, int bap, const void *buf, unsigned data_len, unsigned len,
454 u16 id, u16 offset)
455{
456 int dreg = bap ? HERMES_DATA1 : HERMES_DATA0;
457 int err = 0;
458
459 if (len < 0 || len % 2 || data_len > len)
460 return -EINVAL;
461
462 err = hermes_bap_seek(hw, bap, id, offset);
463 if (err)
464 goto out;
465
466 /* Transfer all the complete words of data */
467 hermes_write_words(hw, dreg, buf, data_len/2);
468 /* If there is an odd byte left over pad and transfer it */
469 if (data_len & 1) {
470 u8 end[2];
471 end[1] = 0;
472 end[0] = ((unsigned char *)buf)[data_len - 1];
473 hermes_write_words(hw, dreg, end, 1);
474 data_len ++;
475 }
476 /* Now send zeros for the padding */
477 if (data_len < len)
478 hermes_clear_words(hw, dreg, (len - data_len) / 2);
479 /* Complete */
480 out:
481 return err;
482}
483
454/* Read a Length-Type-Value record from the card. 484/* Read a Length-Type-Value record from the card.
455 * 485 *
456 * If length is NULL, we ignore the length read from the card, and 486 * If length is NULL, we ignore the length read from the card, and
@@ -538,6 +568,7 @@ EXPORT_SYMBOL(hermes_allocate);
538 568
539EXPORT_SYMBOL(hermes_bap_pread); 569EXPORT_SYMBOL(hermes_bap_pread);
540EXPORT_SYMBOL(hermes_bap_pwrite); 570EXPORT_SYMBOL(hermes_bap_pwrite);
571EXPORT_SYMBOL(hermes_bap_pwrite_pad);
541EXPORT_SYMBOL(hermes_read_ltv); 572EXPORT_SYMBOL(hermes_read_ltv);
542EXPORT_SYMBOL(hermes_write_ltv); 573EXPORT_SYMBOL(hermes_write_ltv);
543 574
diff --git a/drivers/net/wireless/hermes.h b/drivers/net/wireless/hermes.h
index 8c9e874c9118..a6bd472d75d4 100644
--- a/drivers/net/wireless/hermes.h
+++ b/drivers/net/wireless/hermes.h
@@ -30,9 +30,8 @@
30 * access to the hermes_t structure, and to the hardware 30 * access to the hermes_t structure, and to the hardware
31*/ 31*/
32 32
33#include <linux/delay.h>
34#include <linux/if_ether.h> 33#include <linux/if_ether.h>
35#include <asm/byteorder.h> 34#include <asm/io.h>
36 35
37/* 36/*
38 * Limits and constants 37 * Limits and constants
@@ -192,13 +191,13 @@
192#define HERMES_RXSTAT_WMP (0x6000) /* Wavelan-II Management Protocol frame */ 191#define HERMES_RXSTAT_WMP (0x6000) /* Wavelan-II Management Protocol frame */
193 192
194struct hermes_tx_descriptor { 193struct hermes_tx_descriptor {
195 u16 status; 194 __le16 status;
196 u16 reserved1; 195 __le16 reserved1;
197 u16 reserved2; 196 __le16 reserved2;
198 u32 sw_support; 197 __le32 sw_support;
199 u8 retry_count; 198 u8 retry_count;
200 u8 tx_rate; 199 u8 tx_rate;
201 u16 tx_control; 200 __le16 tx_control;
202} __attribute__ ((packed)); 201} __attribute__ ((packed));
203 202
204#define HERMES_TXSTAT_RETRYERR (0x0001) 203#define HERMES_TXSTAT_RETRYERR (0x0001)
@@ -222,60 +221,60 @@ struct hermes_tx_descriptor {
222#define HERMES_INQ_SEC_STAT_AGERE (0xF202) 221#define HERMES_INQ_SEC_STAT_AGERE (0xF202)
223 222
224struct hermes_tallies_frame { 223struct hermes_tallies_frame {
225 u16 TxUnicastFrames; 224 __le16 TxUnicastFrames;
226 u16 TxMulticastFrames; 225 __le16 TxMulticastFrames;
227 u16 TxFragments; 226 __le16 TxFragments;
228 u16 TxUnicastOctets; 227 __le16 TxUnicastOctets;
229 u16 TxMulticastOctets; 228 __le16 TxMulticastOctets;
230 u16 TxDeferredTransmissions; 229 __le16 TxDeferredTransmissions;
231 u16 TxSingleRetryFrames; 230 __le16 TxSingleRetryFrames;
232 u16 TxMultipleRetryFrames; 231 __le16 TxMultipleRetryFrames;
233 u16 TxRetryLimitExceeded; 232 __le16 TxRetryLimitExceeded;
234 u16 TxDiscards; 233 __le16 TxDiscards;
235 u16 RxUnicastFrames; 234 __le16 RxUnicastFrames;
236 u16 RxMulticastFrames; 235 __le16 RxMulticastFrames;
237 u16 RxFragments; 236 __le16 RxFragments;
238 u16 RxUnicastOctets; 237 __le16 RxUnicastOctets;
239 u16 RxMulticastOctets; 238 __le16 RxMulticastOctets;
240 u16 RxFCSErrors; 239 __le16 RxFCSErrors;
241 u16 RxDiscards_NoBuffer; 240 __le16 RxDiscards_NoBuffer;
242 u16 TxDiscardsWrongSA; 241 __le16 TxDiscardsWrongSA;
243 u16 RxWEPUndecryptable; 242 __le16 RxWEPUndecryptable;
244 u16 RxMsgInMsgFragments; 243 __le16 RxMsgInMsgFragments;
245 u16 RxMsgInBadMsgFragments; 244 __le16 RxMsgInBadMsgFragments;
246 /* Those last are probably not available in very old firmwares */ 245 /* Those last are probably not available in very old firmwares */
247 u16 RxDiscards_WEPICVError; 246 __le16 RxDiscards_WEPICVError;
248 u16 RxDiscards_WEPExcluded; 247 __le16 RxDiscards_WEPExcluded;
249} __attribute__ ((packed)); 248} __attribute__ ((packed));
250 249
251/* Grabbed from wlan-ng - Thanks Mark... - Jean II 250/* Grabbed from wlan-ng - Thanks Mark... - Jean II
252 * This is the result of a scan inquiry command */ 251 * This is the result of a scan inquiry command */
253/* Structure describing info about an Access Point */ 252/* Structure describing info about an Access Point */
254struct prism2_scan_apinfo { 253struct prism2_scan_apinfo {
255 u16 channel; /* Channel where the AP sits */ 254 __le16 channel; /* Channel where the AP sits */
256 u16 noise; /* Noise level */ 255 __le16 noise; /* Noise level */
257 u16 level; /* Signal level */ 256 __le16 level; /* Signal level */
258 u8 bssid[ETH_ALEN]; /* MAC address of the Access Point */ 257 u8 bssid[ETH_ALEN]; /* MAC address of the Access Point */
259 u16 beacon_interv; /* Beacon interval */ 258 __le16 beacon_interv; /* Beacon interval */
260 u16 capabilities; /* Capabilities */ 259 __le16 capabilities; /* Capabilities */
261 u16 essid_len; /* ESSID length */ 260 __le16 essid_len; /* ESSID length */
262 u8 essid[32]; /* ESSID of the network */ 261 u8 essid[32]; /* ESSID of the network */
263 u8 rates[10]; /* Bit rate supported */ 262 u8 rates[10]; /* Bit rate supported */
264 u16 proberesp_rate; /* Data rate of the response frame */ 263 __le16 proberesp_rate; /* Data rate of the response frame */
265 u16 atim; /* ATIM window time, Kus (hostscan only) */ 264 __le16 atim; /* ATIM window time, Kus (hostscan only) */
266} __attribute__ ((packed)); 265} __attribute__ ((packed));
267 266
268/* Same stuff for the Lucent/Agere card. 267/* Same stuff for the Lucent/Agere card.
269 * Thanks to h1kari <h1kari AT dachb0den.com> - Jean II */ 268 * Thanks to h1kari <h1kari AT dachb0den.com> - Jean II */
270struct agere_scan_apinfo { 269struct agere_scan_apinfo {
271 u16 channel; /* Channel where the AP sits */ 270 __le16 channel; /* Channel where the AP sits */
272 u16 noise; /* Noise level */ 271 __le16 noise; /* Noise level */
273 u16 level; /* Signal level */ 272 __le16 level; /* Signal level */
274 u8 bssid[ETH_ALEN]; /* MAC address of the Access Point */ 273 u8 bssid[ETH_ALEN]; /* MAC address of the Access Point */
275 u16 beacon_interv; /* Beacon interval */ 274 __le16 beacon_interv; /* Beacon interval */
276 u16 capabilities; /* Capabilities */ 275 __le16 capabilities; /* Capabilities */
277 /* bits: 0-ess, 1-ibss, 4-privacy [wep] */ 276 /* bits: 0-ess, 1-ibss, 4-privacy [wep] */
278 u16 essid_len; /* ESSID length */ 277 __le16 essid_len; /* ESSID length */
279 u8 essid[32]; /* ESSID of the network */ 278 u8 essid[32]; /* ESSID of the network */
280} __attribute__ ((packed)); 279} __attribute__ ((packed));
281 280
@@ -283,16 +282,16 @@ struct agere_scan_apinfo {
283struct symbol_scan_apinfo { 282struct symbol_scan_apinfo {
284 u8 channel; /* Channel where the AP sits */ 283 u8 channel; /* Channel where the AP sits */
285 u8 unknown1; /* 8 in 2.9x and 3.9x f/w, 0 otherwise */ 284 u8 unknown1; /* 8 in 2.9x and 3.9x f/w, 0 otherwise */
286 u16 noise; /* Noise level */ 285 __le16 noise; /* Noise level */
287 u16 level; /* Signal level */ 286 __le16 level; /* Signal level */
288 u8 bssid[ETH_ALEN]; /* MAC address of the Access Point */ 287 u8 bssid[ETH_ALEN]; /* MAC address of the Access Point */
289 u16 beacon_interv; /* Beacon interval */ 288 __le16 beacon_interv; /* Beacon interval */
290 u16 capabilities; /* Capabilities */ 289 __le16 capabilities; /* Capabilities */
291 /* bits: 0-ess, 1-ibss, 4-privacy [wep] */ 290 /* bits: 0-ess, 1-ibss, 4-privacy [wep] */
292 u16 essid_len; /* ESSID length */ 291 __le16 essid_len; /* ESSID length */
293 u8 essid[32]; /* ESSID of the network */ 292 u8 essid[32]; /* ESSID of the network */
294 u16 rates[5]; /* Bit rate supported */ 293 __le16 rates[5]; /* Bit rate supported */
295 u16 basic_rates; /* Basic rates bitmask */ 294 __le16 basic_rates; /* Basic rates bitmask */
296 u8 unknown2[6]; /* Always FF:FF:FF:FF:00:00 */ 295 u8 unknown2[6]; /* Always FF:FF:FF:FF:00:00 */
297 u8 unknown3[8]; /* Always 0, appeared in f/w 3.91-68 */ 296 u8 unknown3[8]; /* Always 0, appeared in f/w 3.91-68 */
298} __attribute__ ((packed)); 297} __attribute__ ((packed));
@@ -312,7 +311,7 @@ union hermes_scan_info {
312#define HERMES_LINKSTATUS_ASSOC_FAILED (0x0006) 311#define HERMES_LINKSTATUS_ASSOC_FAILED (0x0006)
313 312
314struct hermes_linkstatus { 313struct hermes_linkstatus {
315 u16 linkstatus; /* Link status */ 314 __le16 linkstatus; /* Link status */
316} __attribute__ ((packed)); 315} __attribute__ ((packed));
317 316
318struct hermes_response { 317struct hermes_response {
@@ -321,8 +320,8 @@ struct hermes_response {
321 320
322/* "ID" structure - used for ESSID and station nickname */ 321/* "ID" structure - used for ESSID and station nickname */
323struct hermes_idstring { 322struct hermes_idstring {
324 u16 len; 323 __le16 len;
325 u16 val[16]; 324 __le16 val[16];
326} __attribute__ ((packed)); 325} __attribute__ ((packed));
327 326
328struct hermes_multicast { 327struct hermes_multicast {
@@ -377,6 +376,8 @@ int hermes_bap_pread(hermes_t *hw, int bap, void *buf, unsigned len,
377 u16 id, u16 offset); 376 u16 id, u16 offset);
378int hermes_bap_pwrite(hermes_t *hw, int bap, const void *buf, unsigned len, 377int hermes_bap_pwrite(hermes_t *hw, int bap, const void *buf, unsigned len,
379 u16 id, u16 offset); 378 u16 id, u16 offset);
379int hermes_bap_pwrite_pad(hermes_t *hw, int bap, const void *buf,
380 unsigned data_len, unsigned len, u16 id, u16 offset);
380int hermes_read_ltv(hermes_t *hw, int bap, u16 rid, unsigned buflen, 381int hermes_read_ltv(hermes_t *hw, int bap, u16 rid, unsigned buflen,
381 u16 *length, void *buf); 382 u16 *length, void *buf);
382int hermes_write_ltv(hermes_t *hw, int bap, u16 rid, 383int hermes_write_ltv(hermes_t *hw, int bap, u16 rid,
@@ -447,7 +448,7 @@ static inline void hermes_clear_words(struct hermes *hw, int off, unsigned count
447 448
448static inline int hermes_read_wordrec(hermes_t *hw, int bap, u16 rid, u16 *word) 449static inline int hermes_read_wordrec(hermes_t *hw, int bap, u16 rid, u16 *word)
449{ 450{
450 u16 rec; 451 __le16 rec;
451 int err; 452 int err;
452 453
453 err = HERMES_READ_RECORD(hw, bap, rid, &rec); 454 err = HERMES_READ_RECORD(hw, bap, rid, &rec);
@@ -457,7 +458,7 @@ static inline int hermes_read_wordrec(hermes_t *hw, int bap, u16 rid, u16 *word)
457 458
458static inline int hermes_write_wordrec(hermes_t *hw, int bap, u16 rid, u16 word) 459static inline int hermes_write_wordrec(hermes_t *hw, int bap, u16 rid, u16 word)
459{ 460{
460 u16 rec = cpu_to_le16(word); 461 __le16 rec = cpu_to_le16(word);
461 return HERMES_WRITE_RECORD(hw, bap, rid, &rec); 462 return HERMES_WRITE_RECORD(hw, bap, rid, &rec);
462} 463}
463 464
diff --git a/drivers/net/wireless/hostap/hostap.c b/drivers/net/wireless/hostap/hostap.c
index e7f5821b4942..6a96cd9f2685 100644
--- a/drivers/net/wireless/hostap/hostap.c
+++ b/drivers/net/wireless/hostap/hostap.c
@@ -716,9 +716,6 @@ static int prism2_close(struct net_device *dev)
716 hostap_deauth_all_stas(dev, local->ap, 1); 716 hostap_deauth_all_stas(dev, local->ap, 1);
717#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */ 717#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
718 718
719 if (local->func->dev_close && local->func->dev_close(local))
720 return 0;
721
722 if (dev == local->dev) { 719 if (dev == local->dev) {
723 local->func->hw_shutdown(dev, HOSTAP_HW_ENABLE_CMDCOMPL); 720 local->func->hw_shutdown(dev, HOSTAP_HW_ENABLE_CMDCOMPL);
724 } 721 }
@@ -766,9 +763,6 @@ static int prism2_open(struct net_device *dev)
766 local->hw_downloading) 763 local->hw_downloading)
767 return -ENODEV; 764 return -ENODEV;
768 765
769 if (local->func->dev_open && local->func->dev_open(local))
770 return 1;
771
772 if (!try_module_get(local->hw_module)) 766 if (!try_module_get(local->hw_module))
773 return -ENODEV; 767 return -ENODEV;
774 local->num_dev_open++; 768 local->num_dev_open++;
diff --git a/drivers/net/wireless/hostap/hostap_80211_rx.c b/drivers/net/wireless/hostap/hostap_80211_rx.c
index b0501243b175..ffac50899454 100644
--- a/drivers/net/wireless/hostap/hostap_80211_rx.c
+++ b/drivers/net/wireless/hostap/hostap_80211_rx.c
@@ -6,10 +6,10 @@
6void hostap_dump_rx_80211(const char *name, struct sk_buff *skb, 6void hostap_dump_rx_80211(const char *name, struct sk_buff *skb,
7 struct hostap_80211_rx_status *rx_stats) 7 struct hostap_80211_rx_status *rx_stats)
8{ 8{
9 struct ieee80211_hdr *hdr; 9 struct ieee80211_hdr_4addr *hdr;
10 u16 fc; 10 u16 fc;
11 11
12 hdr = (struct ieee80211_hdr *) skb->data; 12 hdr = (struct ieee80211_hdr_4addr *) skb->data;
13 13
14 printk(KERN_DEBUG "%s: RX signal=%d noise=%d rate=%d len=%d " 14 printk(KERN_DEBUG "%s: RX signal=%d noise=%d rate=%d len=%d "
15 "jiffies=%ld\n", 15 "jiffies=%ld\n",
@@ -51,7 +51,7 @@ int prism2_rx_80211(struct net_device *dev, struct sk_buff *skb,
51 int hdrlen, phdrlen, head_need, tail_need; 51 int hdrlen, phdrlen, head_need, tail_need;
52 u16 fc; 52 u16 fc;
53 int prism_header, ret; 53 int prism_header, ret;
54 struct ieee80211_hdr *hdr; 54 struct ieee80211_hdr_4addr *hdr;
55 55
56 iface = netdev_priv(dev); 56 iface = netdev_priv(dev);
57 local = iface->local; 57 local = iface->local;
@@ -70,7 +70,7 @@ int prism2_rx_80211(struct net_device *dev, struct sk_buff *skb,
70 phdrlen = 0; 70 phdrlen = 0;
71 } 71 }
72 72
73 hdr = (struct ieee80211_hdr *) skb->data; 73 hdr = (struct ieee80211_hdr_4addr *) skb->data;
74 fc = le16_to_cpu(hdr->frame_ctl); 74 fc = le16_to_cpu(hdr->frame_ctl);
75 75
76 if (type == PRISM2_RX_MGMT && (fc & IEEE80211_FCTL_VERS)) { 76 if (type == PRISM2_RX_MGMT && (fc & IEEE80211_FCTL_VERS)) {
@@ -215,7 +215,7 @@ prism2_frag_cache_find(local_info_t *local, unsigned int seq,
215 215
216/* Called only as a tasklet (software IRQ) */ 216/* Called only as a tasklet (software IRQ) */
217static struct sk_buff * 217static struct sk_buff *
218prism2_frag_cache_get(local_info_t *local, struct ieee80211_hdr *hdr) 218prism2_frag_cache_get(local_info_t *local, struct ieee80211_hdr_4addr *hdr)
219{ 219{
220 struct sk_buff *skb = NULL; 220 struct sk_buff *skb = NULL;
221 u16 sc; 221 u16 sc;
@@ -229,7 +229,7 @@ prism2_frag_cache_get(local_info_t *local, struct ieee80211_hdr *hdr)
229 if (frag == 0) { 229 if (frag == 0) {
230 /* Reserve enough space to fit maximum frame length */ 230 /* Reserve enough space to fit maximum frame length */
231 skb = dev_alloc_skb(local->dev->mtu + 231 skb = dev_alloc_skb(local->dev->mtu +
232 sizeof(struct ieee80211_hdr) + 232 sizeof(struct ieee80211_hdr_4addr) +
233 8 /* LLC */ + 233 8 /* LLC */ +
234 2 /* alignment */ + 234 2 /* alignment */ +
235 8 /* WEP */ + ETH_ALEN /* WDS */); 235 8 /* WEP */ + ETH_ALEN /* WDS */);
@@ -267,7 +267,7 @@ prism2_frag_cache_get(local_info_t *local, struct ieee80211_hdr *hdr)
267 267
268/* Called only as a tasklet (software IRQ) */ 268/* Called only as a tasklet (software IRQ) */
269static int prism2_frag_cache_invalidate(local_info_t *local, 269static int prism2_frag_cache_invalidate(local_info_t *local,
270 struct ieee80211_hdr *hdr) 270 struct ieee80211_hdr_4addr *hdr)
271{ 271{
272 u16 sc; 272 u16 sc;
273 unsigned int seq; 273 unsigned int seq;
@@ -441,7 +441,7 @@ hostap_rx_frame_mgmt(local_info_t *local, struct sk_buff *skb,
441 u16 stype) 441 u16 stype)
442{ 442{
443 if (local->iw_mode == IW_MODE_MASTER) { 443 if (local->iw_mode == IW_MODE_MASTER) {
444 hostap_update_sta_ps(local, (struct ieee80211_hdr *) 444 hostap_update_sta_ps(local, (struct ieee80211_hdr_4addr *)
445 skb->data); 445 skb->data);
446 } 446 }
447 447
@@ -520,7 +520,7 @@ static inline struct net_device *prism2_rx_get_wds(local_info_t *local,
520 520
521 521
522static inline int 522static inline int
523hostap_rx_frame_wds(local_info_t *local, struct ieee80211_hdr *hdr, 523hostap_rx_frame_wds(local_info_t *local, struct ieee80211_hdr_4addr *hdr,
524 u16 fc, struct net_device **wds) 524 u16 fc, struct net_device **wds)
525{ 525{
526 /* FIX: is this really supposed to accept WDS frames only in Master 526 /* FIX: is this really supposed to accept WDS frames only in Master
@@ -579,13 +579,13 @@ static int hostap_is_eapol_frame(local_info_t *local, struct sk_buff *skb)
579{ 579{
580 struct net_device *dev = local->dev; 580 struct net_device *dev = local->dev;
581 u16 fc, ethertype; 581 u16 fc, ethertype;
582 struct ieee80211_hdr *hdr; 582 struct ieee80211_hdr_4addr *hdr;
583 u8 *pos; 583 u8 *pos;
584 584
585 if (skb->len < 24) 585 if (skb->len < 24)
586 return 0; 586 return 0;
587 587
588 hdr = (struct ieee80211_hdr *) skb->data; 588 hdr = (struct ieee80211_hdr_4addr *) skb->data;
589 fc = le16_to_cpu(hdr->frame_ctl); 589 fc = le16_to_cpu(hdr->frame_ctl);
590 590
591 /* check that the frame is unicast frame to us */ 591 /* check that the frame is unicast frame to us */
@@ -619,13 +619,13 @@ static inline int
619hostap_rx_frame_decrypt(local_info_t *local, struct sk_buff *skb, 619hostap_rx_frame_decrypt(local_info_t *local, struct sk_buff *skb,
620 struct ieee80211_crypt_data *crypt) 620 struct ieee80211_crypt_data *crypt)
621{ 621{
622 struct ieee80211_hdr *hdr; 622 struct ieee80211_hdr_4addr *hdr;
623 int res, hdrlen; 623 int res, hdrlen;
624 624
625 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL) 625 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
626 return 0; 626 return 0;
627 627
628 hdr = (struct ieee80211_hdr *) skb->data; 628 hdr = (struct ieee80211_hdr_4addr *) skb->data;
629 hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); 629 hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
630 630
631 if (local->tkip_countermeasures && 631 if (local->tkip_countermeasures &&
@@ -658,13 +658,13 @@ static inline int
658hostap_rx_frame_decrypt_msdu(local_info_t *local, struct sk_buff *skb, 658hostap_rx_frame_decrypt_msdu(local_info_t *local, struct sk_buff *skb,
659 int keyidx, struct ieee80211_crypt_data *crypt) 659 int keyidx, struct ieee80211_crypt_data *crypt)
660{ 660{
661 struct ieee80211_hdr *hdr; 661 struct ieee80211_hdr_4addr *hdr;
662 int res, hdrlen; 662 int res, hdrlen;
663 663
664 if (crypt == NULL || crypt->ops->decrypt_msdu == NULL) 664 if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
665 return 0; 665 return 0;
666 666
667 hdr = (struct ieee80211_hdr *) skb->data; 667 hdr = (struct ieee80211_hdr_4addr *) skb->data;
668 hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); 668 hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
669 669
670 atomic_inc(&crypt->refcnt); 670 atomic_inc(&crypt->refcnt);
@@ -689,7 +689,7 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
689{ 689{
690 struct hostap_interface *iface; 690 struct hostap_interface *iface;
691 local_info_t *local; 691 local_info_t *local;
692 struct ieee80211_hdr *hdr; 692 struct ieee80211_hdr_4addr *hdr;
693 size_t hdrlen; 693 size_t hdrlen;
694 u16 fc, type, stype, sc; 694 u16 fc, type, stype, sc;
695 struct net_device *wds = NULL; 695 struct net_device *wds = NULL;
@@ -716,7 +716,7 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
716 dev = local->ddev; 716 dev = local->ddev;
717 iface = netdev_priv(dev); 717 iface = netdev_priv(dev);
718 718
719 hdr = (struct ieee80211_hdr *) skb->data; 719 hdr = (struct ieee80211_hdr_4addr *) skb->data;
720 stats = hostap_get_stats(dev); 720 stats = hostap_get_stats(dev);
721 721
722 if (skb->len < 10) 722 if (skb->len < 10)
@@ -737,7 +737,8 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
737 struct iw_quality wstats; 737 struct iw_quality wstats;
738 wstats.level = rx_stats->signal; 738 wstats.level = rx_stats->signal;
739 wstats.noise = rx_stats->noise; 739 wstats.noise = rx_stats->noise;
740 wstats.updated = 6; /* No qual value */ 740 wstats.updated = IW_QUAL_LEVEL_UPDATED | IW_QUAL_NOISE_UPDATED
741 | IW_QUAL_QUAL_INVALID | IW_QUAL_DBM;
741 /* Update spy records */ 742 /* Update spy records */
742 wireless_spy_update(dev, hdr->addr2, &wstats); 743 wireless_spy_update(dev, hdr->addr2, &wstats);
743 } 744 }
@@ -889,7 +890,7 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
889 if (local->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) && 890 if (local->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
890 (keyidx = hostap_rx_frame_decrypt(local, skb, crypt)) < 0) 891 (keyidx = hostap_rx_frame_decrypt(local, skb, crypt)) < 0)
891 goto rx_dropped; 892 goto rx_dropped;
892 hdr = (struct ieee80211_hdr *) skb->data; 893 hdr = (struct ieee80211_hdr_4addr *) skb->data;
893 894
894 /* skb: hdr + (possibly fragmented) plaintext payload */ 895 /* skb: hdr + (possibly fragmented) plaintext payload */
895 896
@@ -941,7 +942,7 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
941 /* this was the last fragment and the frame will be 942 /* this was the last fragment and the frame will be
942 * delivered, so remove skb from fragment cache */ 943 * delivered, so remove skb from fragment cache */
943 skb = frag_skb; 944 skb = frag_skb;
944 hdr = (struct ieee80211_hdr *) skb->data; 945 hdr = (struct ieee80211_hdr_4addr *) skb->data;
945 prism2_frag_cache_invalidate(local, hdr); 946 prism2_frag_cache_invalidate(local, hdr);
946 } 947 }
947 948
@@ -952,7 +953,7 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
952 hostap_rx_frame_decrypt_msdu(local, skb, keyidx, crypt)) 953 hostap_rx_frame_decrypt_msdu(local, skb, keyidx, crypt))
953 goto rx_dropped; 954 goto rx_dropped;
954 955
955 hdr = (struct ieee80211_hdr *) skb->data; 956 hdr = (struct ieee80211_hdr_4addr *) skb->data;
956 if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !local->open_wep) { 957 if (crypt && !(fc & IEEE80211_FCTL_PROTECTED) && !local->open_wep) {
957 if (local->ieee_802_1x && 958 if (local->ieee_802_1x &&
958 hostap_is_eapol_frame(local, skb)) { 959 hostap_is_eapol_frame(local, skb)) {
diff --git a/drivers/net/wireless/hostap/hostap_80211_tx.c b/drivers/net/wireless/hostap/hostap_80211_tx.c
index 6358015f6526..9d24f8a38ac5 100644
--- a/drivers/net/wireless/hostap/hostap_80211_tx.c
+++ b/drivers/net/wireless/hostap/hostap_80211_tx.c
@@ -1,9 +1,9 @@
1void hostap_dump_tx_80211(const char *name, struct sk_buff *skb) 1void hostap_dump_tx_80211(const char *name, struct sk_buff *skb)
2{ 2{
3 struct ieee80211_hdr *hdr; 3 struct ieee80211_hdr_4addr *hdr;
4 u16 fc; 4 u16 fc;
5 5
6 hdr = (struct ieee80211_hdr *) skb->data; 6 hdr = (struct ieee80211_hdr_4addr *) skb->data;
7 7
8 printk(KERN_DEBUG "%s: TX len=%d jiffies=%ld\n", 8 printk(KERN_DEBUG "%s: TX len=%d jiffies=%ld\n",
9 name, skb->len, jiffies); 9 name, skb->len, jiffies);
@@ -41,7 +41,7 @@ int hostap_data_start_xmit(struct sk_buff *skb, struct net_device *dev)
41 struct hostap_interface *iface; 41 struct hostap_interface *iface;
42 local_info_t *local; 42 local_info_t *local;
43 int need_headroom, need_tailroom = 0; 43 int need_headroom, need_tailroom = 0;
44 struct ieee80211_hdr hdr; 44 struct ieee80211_hdr_4addr hdr;
45 u16 fc, ethertype = 0; 45 u16 fc, ethertype = 0;
46 enum { 46 enum {
47 WDS_NO = 0, WDS_OWN_FRAME, WDS_COMPLIANT_FRAME 47 WDS_NO = 0, WDS_OWN_FRAME, WDS_COMPLIANT_FRAME
@@ -244,7 +244,7 @@ int hostap_mgmt_start_xmit(struct sk_buff *skb, struct net_device *dev)
244 struct hostap_interface *iface; 244 struct hostap_interface *iface;
245 local_info_t *local; 245 local_info_t *local;
246 struct hostap_skb_tx_data *meta; 246 struct hostap_skb_tx_data *meta;
247 struct ieee80211_hdr *hdr; 247 struct ieee80211_hdr_4addr *hdr;
248 u16 fc; 248 u16 fc;
249 249
250 iface = netdev_priv(dev); 250 iface = netdev_priv(dev);
@@ -266,7 +266,7 @@ int hostap_mgmt_start_xmit(struct sk_buff *skb, struct net_device *dev)
266 meta->iface = iface; 266 meta->iface = iface;
267 267
268 if (skb->len >= IEEE80211_DATA_HDR3_LEN + sizeof(rfc1042_header) + 2) { 268 if (skb->len >= IEEE80211_DATA_HDR3_LEN + sizeof(rfc1042_header) + 2) {
269 hdr = (struct ieee80211_hdr *) skb->data; 269 hdr = (struct ieee80211_hdr_4addr *) skb->data;
270 fc = le16_to_cpu(hdr->frame_ctl); 270 fc = le16_to_cpu(hdr->frame_ctl);
271 if (WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA && 271 if (WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA &&
272 WLAN_FC_GET_STYPE(fc) == IEEE80211_STYPE_DATA) { 272 WLAN_FC_GET_STYPE(fc) == IEEE80211_STYPE_DATA) {
@@ -289,7 +289,7 @@ struct sk_buff * hostap_tx_encrypt(struct sk_buff *skb,
289{ 289{
290 struct hostap_interface *iface; 290 struct hostap_interface *iface;
291 local_info_t *local; 291 local_info_t *local;
292 struct ieee80211_hdr *hdr; 292 struct ieee80211_hdr_4addr *hdr;
293 u16 fc; 293 u16 fc;
294 int hdr_len, res; 294 int hdr_len, res;
295 295
@@ -303,7 +303,7 @@ struct sk_buff * hostap_tx_encrypt(struct sk_buff *skb,
303 303
304 if (local->tkip_countermeasures && 304 if (local->tkip_countermeasures &&
305 crypt && crypt->ops && strcmp(crypt->ops->name, "TKIP") == 0) { 305 crypt && crypt->ops && strcmp(crypt->ops->name, "TKIP") == 0) {
306 hdr = (struct ieee80211_hdr *) skb->data; 306 hdr = (struct ieee80211_hdr_4addr *) skb->data;
307 if (net_ratelimit()) { 307 if (net_ratelimit()) {
308 printk(KERN_DEBUG "%s: TKIP countermeasures: dropped " 308 printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
309 "TX packet to " MACSTR "\n", 309 "TX packet to " MACSTR "\n",
@@ -317,15 +317,15 @@ struct sk_buff * hostap_tx_encrypt(struct sk_buff *skb,
317 if (skb == NULL) 317 if (skb == NULL)
318 return NULL; 318 return NULL;
319 319
320 if ((skb_headroom(skb) < crypt->ops->extra_prefix_len || 320 if ((skb_headroom(skb) < crypt->ops->extra_mpdu_prefix_len ||
321 skb_tailroom(skb) < crypt->ops->extra_postfix_len) && 321 skb_tailroom(skb) < crypt->ops->extra_mpdu_postfix_len) &&
322 pskb_expand_head(skb, crypt->ops->extra_prefix_len, 322 pskb_expand_head(skb, crypt->ops->extra_mpdu_prefix_len,
323 crypt->ops->extra_postfix_len, GFP_ATOMIC)) { 323 crypt->ops->extra_mpdu_postfix_len, GFP_ATOMIC)) {
324 kfree_skb(skb); 324 kfree_skb(skb);
325 return NULL; 325 return NULL;
326 } 326 }
327 327
328 hdr = (struct ieee80211_hdr *) skb->data; 328 hdr = (struct ieee80211_hdr_4addr *) skb->data;
329 fc = le16_to_cpu(hdr->frame_ctl); 329 fc = le16_to_cpu(hdr->frame_ctl);
330 hdr_len = hostap_80211_get_hdrlen(fc); 330 hdr_len = hostap_80211_get_hdrlen(fc);
331 331
@@ -360,7 +360,7 @@ int hostap_master_start_xmit(struct sk_buff *skb, struct net_device *dev)
360 ap_tx_ret tx_ret; 360 ap_tx_ret tx_ret;
361 struct hostap_skb_tx_data *meta; 361 struct hostap_skb_tx_data *meta;
362 int no_encrypt = 0; 362 int no_encrypt = 0;
363 struct ieee80211_hdr *hdr; 363 struct ieee80211_hdr_4addr *hdr;
364 364
365 iface = netdev_priv(dev); 365 iface = netdev_priv(dev);
366 local = iface->local; 366 local = iface->local;
@@ -403,7 +403,7 @@ int hostap_master_start_xmit(struct sk_buff *skb, struct net_device *dev)
403 tx_ret = hostap_handle_sta_tx(local, &tx); 403 tx_ret = hostap_handle_sta_tx(local, &tx);
404 skb = tx.skb; 404 skb = tx.skb;
405 meta = (struct hostap_skb_tx_data *) skb->cb; 405 meta = (struct hostap_skb_tx_data *) skb->cb;
406 hdr = (struct ieee80211_hdr *) skb->data; 406 hdr = (struct ieee80211_hdr_4addr *) skb->data;
407 fc = le16_to_cpu(hdr->frame_ctl); 407 fc = le16_to_cpu(hdr->frame_ctl);
408 switch (tx_ret) { 408 switch (tx_ret) {
409 case AP_TX_CONTINUE: 409 case AP_TX_CONTINUE:
diff --git a/drivers/net/wireless/hostap/hostap_ap.c b/drivers/net/wireless/hostap/hostap_ap.c
index 930cef8367f2..9da94ab7f05f 100644
--- a/drivers/net/wireless/hostap/hostap_ap.c
+++ b/drivers/net/wireless/hostap/hostap_ap.c
@@ -591,14 +591,14 @@ static void hostap_ap_tx_cb(struct sk_buff *skb, int ok, void *data)
591{ 591{
592 struct ap_data *ap = data; 592 struct ap_data *ap = data;
593 u16 fc; 593 u16 fc;
594 struct ieee80211_hdr *hdr; 594 struct ieee80211_hdr_4addr *hdr;
595 595
596 if (!ap->local->hostapd || !ap->local->apdev) { 596 if (!ap->local->hostapd || !ap->local->apdev) {
597 dev_kfree_skb(skb); 597 dev_kfree_skb(skb);
598 return; 598 return;
599 } 599 }
600 600
601 hdr = (struct ieee80211_hdr *) skb->data; 601 hdr = (struct ieee80211_hdr_4addr *) skb->data;
602 fc = le16_to_cpu(hdr->frame_ctl); 602 fc = le16_to_cpu(hdr->frame_ctl);
603 603
604 /* Pass the TX callback frame to the hostapd; use 802.11 header version 604 /* Pass the TX callback frame to the hostapd; use 802.11 header version
@@ -623,7 +623,7 @@ static void hostap_ap_tx_cb_auth(struct sk_buff *skb, int ok, void *data)
623{ 623{
624 struct ap_data *ap = data; 624 struct ap_data *ap = data;
625 struct net_device *dev = ap->local->dev; 625 struct net_device *dev = ap->local->dev;
626 struct ieee80211_hdr *hdr; 626 struct ieee80211_hdr_4addr *hdr;
627 u16 fc, *pos, auth_alg, auth_transaction, status; 627 u16 fc, *pos, auth_alg, auth_transaction, status;
628 struct sta_info *sta = NULL; 628 struct sta_info *sta = NULL;
629 char *txt = NULL; 629 char *txt = NULL;
@@ -633,7 +633,7 @@ static void hostap_ap_tx_cb_auth(struct sk_buff *skb, int ok, void *data)
633 return; 633 return;
634 } 634 }
635 635
636 hdr = (struct ieee80211_hdr *) skb->data; 636 hdr = (struct ieee80211_hdr_4addr *) skb->data;
637 fc = le16_to_cpu(hdr->frame_ctl); 637 fc = le16_to_cpu(hdr->frame_ctl);
638 if (WLAN_FC_GET_TYPE(fc) != IEEE80211_FTYPE_MGMT || 638 if (WLAN_FC_GET_TYPE(fc) != IEEE80211_FTYPE_MGMT ||
639 WLAN_FC_GET_STYPE(fc) != IEEE80211_STYPE_AUTH || 639 WLAN_FC_GET_STYPE(fc) != IEEE80211_STYPE_AUTH ||
@@ -692,7 +692,7 @@ static void hostap_ap_tx_cb_assoc(struct sk_buff *skb, int ok, void *data)
692{ 692{
693 struct ap_data *ap = data; 693 struct ap_data *ap = data;
694 struct net_device *dev = ap->local->dev; 694 struct net_device *dev = ap->local->dev;
695 struct ieee80211_hdr *hdr; 695 struct ieee80211_hdr_4addr *hdr;
696 u16 fc, *pos, status; 696 u16 fc, *pos, status;
697 struct sta_info *sta = NULL; 697 struct sta_info *sta = NULL;
698 char *txt = NULL; 698 char *txt = NULL;
@@ -702,7 +702,7 @@ static void hostap_ap_tx_cb_assoc(struct sk_buff *skb, int ok, void *data)
702 return; 702 return;
703 } 703 }
704 704
705 hdr = (struct ieee80211_hdr *) skb->data; 705 hdr = (struct ieee80211_hdr_4addr *) skb->data;
706 fc = le16_to_cpu(hdr->frame_ctl); 706 fc = le16_to_cpu(hdr->frame_ctl);
707 if (WLAN_FC_GET_TYPE(fc) != IEEE80211_FTYPE_MGMT || 707 if (WLAN_FC_GET_TYPE(fc) != IEEE80211_FTYPE_MGMT ||
708 (WLAN_FC_GET_STYPE(fc) != IEEE80211_STYPE_ASSOC_RESP && 708 (WLAN_FC_GET_STYPE(fc) != IEEE80211_STYPE_ASSOC_RESP &&
@@ -757,12 +757,12 @@ static void hostap_ap_tx_cb_assoc(struct sk_buff *skb, int ok, void *data)
757static void hostap_ap_tx_cb_poll(struct sk_buff *skb, int ok, void *data) 757static void hostap_ap_tx_cb_poll(struct sk_buff *skb, int ok, void *data)
758{ 758{
759 struct ap_data *ap = data; 759 struct ap_data *ap = data;
760 struct ieee80211_hdr *hdr; 760 struct ieee80211_hdr_4addr *hdr;
761 struct sta_info *sta; 761 struct sta_info *sta;
762 762
763 if (skb->len < 24) 763 if (skb->len < 24)
764 goto fail; 764 goto fail;
765 hdr = (struct ieee80211_hdr *) skb->data; 765 hdr = (struct ieee80211_hdr_4addr *) skb->data;
766 if (ok) { 766 if (ok) {
767 spin_lock(&ap->sta_table_lock); 767 spin_lock(&ap->sta_table_lock);
768 sta = ap_get_sta(ap, hdr->addr1); 768 sta = ap_get_sta(ap, hdr->addr1);
@@ -918,7 +918,7 @@ static void prism2_send_mgmt(struct net_device *dev,
918{ 918{
919 struct hostap_interface *iface; 919 struct hostap_interface *iface;
920 local_info_t *local; 920 local_info_t *local;
921 struct ieee80211_hdr *hdr; 921 struct ieee80211_hdr_4addr *hdr;
922 u16 fc; 922 u16 fc;
923 struct sk_buff *skb; 923 struct sk_buff *skb;
924 struct hostap_skb_tx_data *meta; 924 struct hostap_skb_tx_data *meta;
@@ -944,7 +944,7 @@ static void prism2_send_mgmt(struct net_device *dev,
944 944
945 fc = type_subtype; 945 fc = type_subtype;
946 hdrlen = hostap_80211_get_hdrlen(fc); 946 hdrlen = hostap_80211_get_hdrlen(fc);
947 hdr = (struct ieee80211_hdr *) skb_put(skb, hdrlen); 947 hdr = (struct ieee80211_hdr_4addr *) skb_put(skb, hdrlen);
948 if (body) 948 if (body)
949 memcpy(skb_put(skb, body_len), body, body_len); 949 memcpy(skb_put(skb, body_len), body, body_len);
950 950
@@ -1256,14 +1256,14 @@ static char * ap_auth_make_challenge(struct ap_data *ap)
1256 } 1256 }
1257 1257
1258 skb = dev_alloc_skb(WLAN_AUTH_CHALLENGE_LEN + 1258 skb = dev_alloc_skb(WLAN_AUTH_CHALLENGE_LEN +
1259 ap->crypt->extra_prefix_len + 1259 ap->crypt->extra_mpdu_prefix_len +
1260 ap->crypt->extra_postfix_len); 1260 ap->crypt->extra_mpdu_postfix_len);
1261 if (skb == NULL) { 1261 if (skb == NULL) {
1262 kfree(tmpbuf); 1262 kfree(tmpbuf);
1263 return NULL; 1263 return NULL;
1264 } 1264 }
1265 1265
1266 skb_reserve(skb, ap->crypt->extra_prefix_len); 1266 skb_reserve(skb, ap->crypt->extra_mpdu_prefix_len);
1267 memset(skb_put(skb, WLAN_AUTH_CHALLENGE_LEN), 0, 1267 memset(skb_put(skb, WLAN_AUTH_CHALLENGE_LEN), 0,
1268 WLAN_AUTH_CHALLENGE_LEN); 1268 WLAN_AUTH_CHALLENGE_LEN);
1269 if (ap->crypt->encrypt_mpdu(skb, 0, ap->crypt_priv)) { 1269 if (ap->crypt->encrypt_mpdu(skb, 0, ap->crypt_priv)) {
@@ -1272,7 +1272,7 @@ static char * ap_auth_make_challenge(struct ap_data *ap)
1272 return NULL; 1272 return NULL;
1273 } 1273 }
1274 1274
1275 memcpy(tmpbuf, skb->data + ap->crypt->extra_prefix_len, 1275 memcpy(tmpbuf, skb->data + ap->crypt->extra_mpdu_prefix_len,
1276 WLAN_AUTH_CHALLENGE_LEN); 1276 WLAN_AUTH_CHALLENGE_LEN);
1277 dev_kfree_skb(skb); 1277 dev_kfree_skb(skb);
1278 1278
@@ -1285,7 +1285,7 @@ static void handle_authen(local_info_t *local, struct sk_buff *skb,
1285 struct hostap_80211_rx_status *rx_stats) 1285 struct hostap_80211_rx_status *rx_stats)
1286{ 1286{
1287 struct net_device *dev = local->dev; 1287 struct net_device *dev = local->dev;
1288 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 1288 struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *) skb->data;
1289 size_t hdrlen; 1289 size_t hdrlen;
1290 struct ap_data *ap = local->ap; 1290 struct ap_data *ap = local->ap;
1291 char body[8 + WLAN_AUTH_CHALLENGE_LEN], *challenge = NULL; 1291 char body[8 + WLAN_AUTH_CHALLENGE_LEN], *challenge = NULL;
@@ -1498,7 +1498,7 @@ static void handle_assoc(local_info_t *local, struct sk_buff *skb,
1498 struct hostap_80211_rx_status *rx_stats, int reassoc) 1498 struct hostap_80211_rx_status *rx_stats, int reassoc)
1499{ 1499{
1500 struct net_device *dev = local->dev; 1500 struct net_device *dev = local->dev;
1501 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 1501 struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *) skb->data;
1502 char body[12], *p, *lpos; 1502 char body[12], *p, *lpos;
1503 int len, left; 1503 int len, left;
1504 u16 *pos; 1504 u16 *pos;
@@ -1705,7 +1705,7 @@ static void handle_deauth(local_info_t *local, struct sk_buff *skb,
1705 struct hostap_80211_rx_status *rx_stats) 1705 struct hostap_80211_rx_status *rx_stats)
1706{ 1706{
1707 struct net_device *dev = local->dev; 1707 struct net_device *dev = local->dev;
1708 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 1708 struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *) skb->data;
1709 char *body = (char *) (skb->data + IEEE80211_MGMT_HDR_LEN); 1709 char *body = (char *) (skb->data + IEEE80211_MGMT_HDR_LEN);
1710 int len; 1710 int len;
1711 u16 reason_code, *pos; 1711 u16 reason_code, *pos;
@@ -1746,7 +1746,7 @@ static void handle_disassoc(local_info_t *local, struct sk_buff *skb,
1746 struct hostap_80211_rx_status *rx_stats) 1746 struct hostap_80211_rx_status *rx_stats)
1747{ 1747{
1748 struct net_device *dev = local->dev; 1748 struct net_device *dev = local->dev;
1749 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 1749 struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *) skb->data;
1750 char *body = skb->data + IEEE80211_MGMT_HDR_LEN; 1750 char *body = skb->data + IEEE80211_MGMT_HDR_LEN;
1751 int len; 1751 int len;
1752 u16 reason_code, *pos; 1752 u16 reason_code, *pos;
@@ -1784,7 +1784,7 @@ static void handle_disassoc(local_info_t *local, struct sk_buff *skb,
1784 1784
1785/* Called only as a scheduled task for pending AP frames. */ 1785/* Called only as a scheduled task for pending AP frames. */
1786static void ap_handle_data_nullfunc(local_info_t *local, 1786static void ap_handle_data_nullfunc(local_info_t *local,
1787 struct ieee80211_hdr *hdr) 1787 struct ieee80211_hdr_4addr *hdr)
1788{ 1788{
1789 struct net_device *dev = local->dev; 1789 struct net_device *dev = local->dev;
1790 1790
@@ -1801,7 +1801,7 @@ static void ap_handle_data_nullfunc(local_info_t *local,
1801 1801
1802/* Called only as a scheduled task for pending AP frames. */ 1802/* Called only as a scheduled task for pending AP frames. */
1803static void ap_handle_dropped_data(local_info_t *local, 1803static void ap_handle_dropped_data(local_info_t *local,
1804 struct ieee80211_hdr *hdr) 1804 struct ieee80211_hdr_4addr *hdr)
1805{ 1805{
1806 struct net_device *dev = local->dev; 1806 struct net_device *dev = local->dev;
1807 struct sta_info *sta; 1807 struct sta_info *sta;
@@ -1860,7 +1860,7 @@ static void pspoll_send_buffered(local_info_t *local, struct sta_info *sta,
1860 1860
1861/* Called only as a scheduled task for pending AP frames. */ 1861/* Called only as a scheduled task for pending AP frames. */
1862static void handle_pspoll(local_info_t *local, 1862static void handle_pspoll(local_info_t *local,
1863 struct ieee80211_hdr *hdr, 1863 struct ieee80211_hdr_4addr *hdr,
1864 struct hostap_80211_rx_status *rx_stats) 1864 struct hostap_80211_rx_status *rx_stats)
1865{ 1865{
1866 struct net_device *dev = local->dev; 1866 struct net_device *dev = local->dev;
@@ -1979,7 +1979,7 @@ static void handle_wds_oper_queue(void *data)
1979static void handle_beacon(local_info_t *local, struct sk_buff *skb, 1979static void handle_beacon(local_info_t *local, struct sk_buff *skb,
1980 struct hostap_80211_rx_status *rx_stats) 1980 struct hostap_80211_rx_status *rx_stats)
1981{ 1981{
1982 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 1982 struct ieee80211_hdr_4addr *hdr = (struct ieee80211_hdr_4addr *) skb->data;
1983 char *body = skb->data + IEEE80211_MGMT_HDR_LEN; 1983 char *body = skb->data + IEEE80211_MGMT_HDR_LEN;
1984 int len, left; 1984 int len, left;
1985 u16 *pos, beacon_int, capability; 1985 u16 *pos, beacon_int, capability;
@@ -2137,11 +2137,11 @@ static void handle_ap_item(local_info_t *local, struct sk_buff *skb,
2137 struct net_device *dev = local->dev; 2137 struct net_device *dev = local->dev;
2138#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */ 2138#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2139 u16 fc, type, stype; 2139 u16 fc, type, stype;
2140 struct ieee80211_hdr *hdr; 2140 struct ieee80211_hdr_4addr *hdr;
2141 2141
2142 /* FIX: should give skb->len to handler functions and check that the 2142 /* FIX: should give skb->len to handler functions and check that the
2143 * buffer is long enough */ 2143 * buffer is long enough */
2144 hdr = (struct ieee80211_hdr *) skb->data; 2144 hdr = (struct ieee80211_hdr_4addr *) skb->data;
2145 fc = le16_to_cpu(hdr->frame_ctl); 2145 fc = le16_to_cpu(hdr->frame_ctl);
2146 type = WLAN_FC_GET_TYPE(fc); 2146 type = WLAN_FC_GET_TYPE(fc);
2147 stype = WLAN_FC_GET_STYPE(fc); 2147 stype = WLAN_FC_GET_STYPE(fc);
@@ -2258,7 +2258,7 @@ void hostap_rx(struct net_device *dev, struct sk_buff *skb,
2258 struct hostap_interface *iface; 2258 struct hostap_interface *iface;
2259 local_info_t *local; 2259 local_info_t *local;
2260 u16 fc; 2260 u16 fc;
2261 struct ieee80211_hdr *hdr; 2261 struct ieee80211_hdr_4addr *hdr;
2262 2262
2263 iface = netdev_priv(dev); 2263 iface = netdev_priv(dev);
2264 local = iface->local; 2264 local = iface->local;
@@ -2268,7 +2268,7 @@ void hostap_rx(struct net_device *dev, struct sk_buff *skb,
2268 2268
2269 local->stats.rx_packets++; 2269 local->stats.rx_packets++;
2270 2270
2271 hdr = (struct ieee80211_hdr *) skb->data; 2271 hdr = (struct ieee80211_hdr_4addr *) skb->data;
2272 fc = le16_to_cpu(hdr->frame_ctl); 2272 fc = le16_to_cpu(hdr->frame_ctl);
2273 2273
2274 if (local->ap->ap_policy == AP_OTHER_AP_SKIP_ALL && 2274 if (local->ap->ap_policy == AP_OTHER_AP_SKIP_ALL &&
@@ -2289,7 +2289,7 @@ void hostap_rx(struct net_device *dev, struct sk_buff *skb,
2289static void schedule_packet_send(local_info_t *local, struct sta_info *sta) 2289static void schedule_packet_send(local_info_t *local, struct sta_info *sta)
2290{ 2290{
2291 struct sk_buff *skb; 2291 struct sk_buff *skb;
2292 struct ieee80211_hdr *hdr; 2292 struct ieee80211_hdr_4addr *hdr;
2293 struct hostap_80211_rx_status rx_stats; 2293 struct hostap_80211_rx_status rx_stats;
2294 2294
2295 if (skb_queue_empty(&sta->tx_buf)) 2295 if (skb_queue_empty(&sta->tx_buf))
@@ -2302,7 +2302,7 @@ static void schedule_packet_send(local_info_t *local, struct sta_info *sta)
2302 return; 2302 return;
2303 } 2303 }
2304 2304
2305 hdr = (struct ieee80211_hdr *) skb_put(skb, 16); 2305 hdr = (struct ieee80211_hdr_4addr *) skb_put(skb, 16);
2306 2306
2307 /* Generate a fake pspoll frame to start packet delivery */ 2307 /* Generate a fake pspoll frame to start packet delivery */
2308 hdr->frame_ctl = __constant_cpu_to_le16( 2308 hdr->frame_ctl = __constant_cpu_to_le16(
@@ -2349,7 +2349,7 @@ static int prism2_ap_get_sta_qual(local_info_t *local, struct sockaddr addr[],
2349 qual[count].noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence); 2349 qual[count].noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence);
2350 qual[count].updated = sta->last_rx_updated; 2350 qual[count].updated = sta->last_rx_updated;
2351 2351
2352 sta->last_rx_updated = 0; 2352 sta->last_rx_updated = IW_QUAL_DBM;
2353 2353
2354 count++; 2354 count++;
2355 if (count >= buf_size) 2355 if (count >= buf_size)
@@ -2467,7 +2467,7 @@ static int prism2_ap_translate_scan(struct net_device *dev, char *buffer)
2467 } 2467 }
2468#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */ 2468#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2469 2469
2470 sta->last_rx_updated = 0; 2470 sta->last_rx_updated = IW_QUAL_DBM;
2471 2471
2472 /* To be continued, we should make good use of IWEVCUSTOM */ 2472 /* To be continued, we should make good use of IWEVCUSTOM */
2473 } 2473 }
@@ -2685,7 +2685,7 @@ ap_tx_ret hostap_handle_sta_tx(local_info_t *local, struct hostap_tx_data *tx)
2685 struct sta_info *sta = NULL; 2685 struct sta_info *sta = NULL;
2686 struct sk_buff *skb = tx->skb; 2686 struct sk_buff *skb = tx->skb;
2687 int set_tim, ret; 2687 int set_tim, ret;
2688 struct ieee80211_hdr *hdr; 2688 struct ieee80211_hdr_4addr *hdr;
2689 struct hostap_skb_tx_data *meta; 2689 struct hostap_skb_tx_data *meta;
2690 2690
2691 meta = (struct hostap_skb_tx_data *) skb->cb; 2691 meta = (struct hostap_skb_tx_data *) skb->cb;
@@ -2694,7 +2694,7 @@ ap_tx_ret hostap_handle_sta_tx(local_info_t *local, struct hostap_tx_data *tx)
2694 meta->iface->type == HOSTAP_INTERFACE_STA) 2694 meta->iface->type == HOSTAP_INTERFACE_STA)
2695 goto out; 2695 goto out;
2696 2696
2697 hdr = (struct ieee80211_hdr *) skb->data; 2697 hdr = (struct ieee80211_hdr_4addr *) skb->data;
2698 2698
2699 if (hdr->addr1[0] & 0x01) { 2699 if (hdr->addr1[0] & 0x01) {
2700 /* broadcast/multicast frame - no AP related processing */ 2700 /* broadcast/multicast frame - no AP related processing */
@@ -2821,10 +2821,10 @@ void hostap_handle_sta_release(void *ptr)
2821void hostap_handle_sta_tx_exc(local_info_t *local, struct sk_buff *skb) 2821void hostap_handle_sta_tx_exc(local_info_t *local, struct sk_buff *skb)
2822{ 2822{
2823 struct sta_info *sta; 2823 struct sta_info *sta;
2824 struct ieee80211_hdr *hdr; 2824 struct ieee80211_hdr_4addr *hdr;
2825 struct hostap_skb_tx_data *meta; 2825 struct hostap_skb_tx_data *meta;
2826 2826
2827 hdr = (struct ieee80211_hdr *) skb->data; 2827 hdr = (struct ieee80211_hdr_4addr *) skb->data;
2828 meta = (struct hostap_skb_tx_data *) skb->cb; 2828 meta = (struct hostap_skb_tx_data *) skb->cb;
2829 2829
2830 spin_lock(&local->ap->sta_table_lock); 2830 spin_lock(&local->ap->sta_table_lock);
@@ -2892,7 +2892,7 @@ static void hostap_update_sta_ps2(local_info_t *local, struct sta_info *sta,
2892 2892
2893/* Called only as a tasklet (software IRQ). Called for each RX frame to update 2893/* Called only as a tasklet (software IRQ). Called for each RX frame to update
2894 * STA power saving state. pwrmgt is a flag from 802.11 frame_ctl field. */ 2894 * STA power saving state. pwrmgt is a flag from 802.11 frame_ctl field. */
2895int hostap_update_sta_ps(local_info_t *local, struct ieee80211_hdr *hdr) 2895int hostap_update_sta_ps(local_info_t *local, struct ieee80211_hdr_4addr *hdr)
2896{ 2896{
2897 struct sta_info *sta; 2897 struct sta_info *sta;
2898 u16 fc; 2898 u16 fc;
@@ -2925,12 +2925,12 @@ ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev,
2925 int ret; 2925 int ret;
2926 struct sta_info *sta; 2926 struct sta_info *sta;
2927 u16 fc, type, stype; 2927 u16 fc, type, stype;
2928 struct ieee80211_hdr *hdr; 2928 struct ieee80211_hdr_4addr *hdr;
2929 2929
2930 if (local->ap == NULL) 2930 if (local->ap == NULL)
2931 return AP_RX_CONTINUE; 2931 return AP_RX_CONTINUE;
2932 2932
2933 hdr = (struct ieee80211_hdr *) skb->data; 2933 hdr = (struct ieee80211_hdr_4addr *) skb->data;
2934 2934
2935 fc = le16_to_cpu(hdr->frame_ctl); 2935 fc = le16_to_cpu(hdr->frame_ctl);
2936 type = WLAN_FC_GET_TYPE(fc); 2936 type = WLAN_FC_GET_TYPE(fc);
@@ -3058,7 +3058,7 @@ ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev,
3058 3058
3059/* Called only as a tasklet (software IRQ) */ 3059/* Called only as a tasklet (software IRQ) */
3060int hostap_handle_sta_crypto(local_info_t *local, 3060int hostap_handle_sta_crypto(local_info_t *local,
3061 struct ieee80211_hdr *hdr, 3061 struct ieee80211_hdr_4addr *hdr,
3062 struct ieee80211_crypt_data **crypt, 3062 struct ieee80211_crypt_data **crypt,
3063 void **sta_ptr) 3063 void **sta_ptr)
3064{ 3064{
@@ -3160,7 +3160,7 @@ int hostap_add_sta(struct ap_data *ap, u8 *sta_addr)
3160 3160
3161/* Called only as a tasklet (software IRQ) */ 3161/* Called only as a tasklet (software IRQ) */
3162int hostap_update_rx_stats(struct ap_data *ap, 3162int hostap_update_rx_stats(struct ap_data *ap,
3163 struct ieee80211_hdr *hdr, 3163 struct ieee80211_hdr_4addr *hdr,
3164 struct hostap_80211_rx_status *rx_stats) 3164 struct hostap_80211_rx_status *rx_stats)
3165{ 3165{
3166 struct sta_info *sta; 3166 struct sta_info *sta;
@@ -3174,7 +3174,7 @@ int hostap_update_rx_stats(struct ap_data *ap,
3174 sta->last_rx_silence = rx_stats->noise; 3174 sta->last_rx_silence = rx_stats->noise;
3175 sta->last_rx_signal = rx_stats->signal; 3175 sta->last_rx_signal = rx_stats->signal;
3176 sta->last_rx_rate = rx_stats->rate; 3176 sta->last_rx_rate = rx_stats->rate;
3177 sta->last_rx_updated = 7; 3177 sta->last_rx_updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
3178 if (rx_stats->rate == 10) 3178 if (rx_stats->rate == 10)
3179 sta->rx_count[0]++; 3179 sta->rx_count[0]++;
3180 else if (rx_stats->rate == 20) 3180 else if (rx_stats->rate == 20)
diff --git a/drivers/net/wireless/hostap/hostap_ap.h b/drivers/net/wireless/hostap/hostap_ap.h
index 816a52bcea8f..6d00df69c2e3 100644
--- a/drivers/net/wireless/hostap/hostap_ap.h
+++ b/drivers/net/wireless/hostap/hostap_ap.h
@@ -233,7 +233,7 @@ struct hostap_tx_data {
233ap_tx_ret hostap_handle_sta_tx(local_info_t *local, struct hostap_tx_data *tx); 233ap_tx_ret hostap_handle_sta_tx(local_info_t *local, struct hostap_tx_data *tx);
234void hostap_handle_sta_release(void *ptr); 234void hostap_handle_sta_release(void *ptr);
235void hostap_handle_sta_tx_exc(local_info_t *local, struct sk_buff *skb); 235void hostap_handle_sta_tx_exc(local_info_t *local, struct sk_buff *skb);
236int hostap_update_sta_ps(local_info_t *local, struct ieee80211_hdr *hdr); 236int hostap_update_sta_ps(local_info_t *local, struct ieee80211_hdr_4addr *hdr);
237typedef enum { 237typedef enum {
238 AP_RX_CONTINUE, AP_RX_DROP, AP_RX_EXIT, AP_RX_CONTINUE_NOT_AUTHORIZED 238 AP_RX_CONTINUE, AP_RX_DROP, AP_RX_EXIT, AP_RX_CONTINUE_NOT_AUTHORIZED
239} ap_rx_ret; 239} ap_rx_ret;
@@ -241,13 +241,13 @@ ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev,
241 struct sk_buff *skb, 241 struct sk_buff *skb,
242 struct hostap_80211_rx_status *rx_stats, 242 struct hostap_80211_rx_status *rx_stats,
243 int wds); 243 int wds);
244int hostap_handle_sta_crypto(local_info_t *local, struct ieee80211_hdr *hdr, 244int hostap_handle_sta_crypto(local_info_t *local, struct ieee80211_hdr_4addr *hdr,
245 struct ieee80211_crypt_data **crypt, 245 struct ieee80211_crypt_data **crypt,
246 void **sta_ptr); 246 void **sta_ptr);
247int hostap_is_sta_assoc(struct ap_data *ap, u8 *sta_addr); 247int hostap_is_sta_assoc(struct ap_data *ap, u8 *sta_addr);
248int hostap_is_sta_authorized(struct ap_data *ap, u8 *sta_addr); 248int hostap_is_sta_authorized(struct ap_data *ap, u8 *sta_addr);
249int hostap_add_sta(struct ap_data *ap, u8 *sta_addr); 249int hostap_add_sta(struct ap_data *ap, u8 *sta_addr);
250int hostap_update_rx_stats(struct ap_data *ap, struct ieee80211_hdr *hdr, 250int hostap_update_rx_stats(struct ap_data *ap, struct ieee80211_hdr_4addr *hdr,
251 struct hostap_80211_rx_status *rx_stats); 251 struct hostap_80211_rx_status *rx_stats);
252void hostap_update_rates(local_info_t *local); 252void hostap_update_rates(local_info_t *local);
253void hostap_add_wds_links(local_info_t *local); 253void hostap_add_wds_links(local_info_t *local);
diff --git a/drivers/net/wireless/hostap/hostap_cs.c b/drivers/net/wireless/hostap/hostap_cs.c
index faa83badf0a1..2643976a6677 100644
--- a/drivers/net/wireless/hostap/hostap_cs.c
+++ b/drivers/net/wireless/hostap/hostap_cs.c
@@ -492,42 +492,10 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
492} 492}
493 493
494 494
495static int prism2_pccard_dev_open(local_info_t *local)
496{
497 struct hostap_cs_priv *hw_priv = local->hw_priv;
498 hw_priv->link->open++;
499 return 0;
500}
501
502
503static int prism2_pccard_dev_close(local_info_t *local)
504{
505 struct hostap_cs_priv *hw_priv;
506
507 if (local == NULL || local->hw_priv == NULL)
508 return 1;
509 hw_priv = local->hw_priv;
510 if (hw_priv->link == NULL)
511 return 1;
512
513 if (!hw_priv->link->open) {
514 printk(KERN_WARNING "%s: prism2_pccard_dev_close(): "
515 "link not open?!\n", local->dev->name);
516 return 1;
517 }
518
519 hw_priv->link->open--;
520
521 return 0;
522}
523
524
525static struct prism2_helper_functions prism2_pccard_funcs = 495static struct prism2_helper_functions prism2_pccard_funcs =
526{ 496{
527 .card_present = prism2_pccard_card_present, 497 .card_present = prism2_pccard_card_present,
528 .cor_sreset = prism2_pccard_cor_sreset, 498 .cor_sreset = prism2_pccard_cor_sreset,
529 .dev_open = prism2_pccard_dev_open,
530 .dev_close = prism2_pccard_dev_close,
531 .genesis_reset = prism2_pccard_genesis_reset, 499 .genesis_reset = prism2_pccard_genesis_reset,
532 .hw_type = HOSTAP_HW_PCCARD, 500 .hw_type = HOSTAP_HW_PCCARD,
533}; 501};
@@ -597,13 +565,14 @@ static void prism2_detach(dev_link_t *link)
597 *linkp = link->next; 565 *linkp = link->next;
598 /* release net devices */ 566 /* release net devices */
599 if (link->priv) { 567 if (link->priv) {
568 struct hostap_cs_priv *hw_priv;
600 struct net_device *dev; 569 struct net_device *dev;
601 struct hostap_interface *iface; 570 struct hostap_interface *iface;
602 dev = link->priv; 571 dev = link->priv;
603 iface = netdev_priv(dev); 572 iface = netdev_priv(dev);
604 kfree(iface->local->hw_priv); 573 hw_priv = iface->local->hw_priv;
605 iface->local->hw_priv = NULL;
606 prism2_free_local_data(dev); 574 prism2_free_local_data(dev);
575 kfree(hw_priv);
607 } 576 }
608 kfree(link); 577 kfree(link);
609} 578}
@@ -883,6 +852,13 @@ static int prism2_event(event_t event, int priority,
883{ 852{
884 dev_link_t *link = args->client_data; 853 dev_link_t *link = args->client_data;
885 struct net_device *dev = (struct net_device *) link->priv; 854 struct net_device *dev = (struct net_device *) link->priv;
855 int dev_open = 0;
856
857 if (link->state & DEV_CONFIG) {
858 struct hostap_interface *iface = netdev_priv(dev);
859 if (iface && iface->local)
860 dev_open = iface->local->num_dev_open > 0;
861 }
886 862
887 switch (event) { 863 switch (event) {
888 case CS_EVENT_CARD_INSERTION: 864 case CS_EVENT_CARD_INSERTION:
@@ -911,7 +887,7 @@ static int prism2_event(event_t event, int priority,
911 case CS_EVENT_RESET_PHYSICAL: 887 case CS_EVENT_RESET_PHYSICAL:
912 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_RESET_PHYSICAL\n", dev_info); 888 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_RESET_PHYSICAL\n", dev_info);
913 if (link->state & DEV_CONFIG) { 889 if (link->state & DEV_CONFIG) {
914 if (link->open) { 890 if (dev_open) {
915 netif_stop_queue(dev); 891 netif_stop_queue(dev);
916 netif_device_detach(dev); 892 netif_device_detach(dev);
917 } 893 }
@@ -931,8 +907,8 @@ static int prism2_event(event_t event, int priority,
931 pcmcia_request_configuration(link->handle, 907 pcmcia_request_configuration(link->handle,
932 &link->conf); 908 &link->conf);
933 prism2_hw_shutdown(dev, 1); 909 prism2_hw_shutdown(dev, 1);
934 prism2_hw_config(dev, link->open ? 0 : 1); 910 prism2_hw_config(dev, dev_open ? 0 : 1);
935 if (link->open) { 911 if (dev_open) {
936 netif_device_attach(dev); 912 netif_device_attach(dev);
937 netif_start_queue(dev); 913 netif_start_queue(dev);
938 } 914 }
diff --git a/drivers/net/wireless/hostap/hostap_hw.c b/drivers/net/wireless/hostap/hostap_hw.c
index e533a663deda..59fc15572395 100644
--- a/drivers/net/wireless/hostap/hostap_hw.c
+++ b/drivers/net/wireless/hostap/hostap_hw.c
@@ -3322,6 +3322,18 @@ static void prism2_free_local_data(struct net_device *dev)
3322 iface = netdev_priv(dev); 3322 iface = netdev_priv(dev);
3323 local = iface->local; 3323 local = iface->local;
3324 3324
3325 /* Unregister all netdevs before freeing local data. */
3326 list_for_each_safe(ptr, n, &local->hostap_interfaces) {
3327 iface = list_entry(ptr, struct hostap_interface, list);
3328 if (iface->type == HOSTAP_INTERFACE_MASTER) {
3329 /* special handling for this interface below */
3330 continue;
3331 }
3332 hostap_remove_interface(iface->dev, 0, 1);
3333 }
3334
3335 unregister_netdev(local->dev);
3336
3325 flush_scheduled_work(); 3337 flush_scheduled_work();
3326 3338
3327 if (timer_pending(&local->crypt_deinit_timer)) 3339 if (timer_pending(&local->crypt_deinit_timer))
@@ -3382,15 +3394,6 @@ static void prism2_free_local_data(struct net_device *dev)
3382 prism2_download_free_data(local->dl_sec); 3394 prism2_download_free_data(local->dl_sec);
3383#endif /* PRISM2_DOWNLOAD_SUPPORT */ 3395#endif /* PRISM2_DOWNLOAD_SUPPORT */
3384 3396
3385 list_for_each_safe(ptr, n, &local->hostap_interfaces) {
3386 iface = list_entry(ptr, struct hostap_interface, list);
3387 if (iface->type == HOSTAP_INTERFACE_MASTER) {
3388 /* special handling for this interface below */
3389 continue;
3390 }
3391 hostap_remove_interface(iface->dev, 0, 1);
3392 }
3393
3394 prism2_clear_set_tim_queue(local); 3397 prism2_clear_set_tim_queue(local);
3395 3398
3396 list_for_each_safe(ptr, n, &local->bss_list) { 3399 list_for_each_safe(ptr, n, &local->bss_list) {
@@ -3403,7 +3406,6 @@ static void prism2_free_local_data(struct net_device *dev)
3403 kfree(local->last_scan_results); 3406 kfree(local->last_scan_results);
3404 kfree(local->generic_elem); 3407 kfree(local->generic_elem);
3405 3408
3406 unregister_netdev(local->dev);
3407 free_netdev(local->dev); 3409 free_netdev(local->dev);
3408} 3410}
3409 3411
diff --git a/drivers/net/wireless/hostap/hostap_ioctl.c b/drivers/net/wireless/hostap/hostap_ioctl.c
index e720369a3515..2617d70bcda9 100644
--- a/drivers/net/wireless/hostap/hostap_ioctl.c
+++ b/drivers/net/wireless/hostap/hostap_ioctl.c
@@ -50,7 +50,8 @@ static struct iw_statistics *hostap_get_wireless_stats(struct net_device *dev)
50#endif /* in_atomic */ 50#endif /* in_atomic */
51 51
52 if (update && prism2_update_comms_qual(dev) == 0) 52 if (update && prism2_update_comms_qual(dev) == 0)
53 wstats->qual.updated = 7; 53 wstats->qual.updated = IW_QUAL_ALL_UPDATED |
54 IW_QUAL_DBM;
54 55
55 wstats->qual.qual = local->comms_qual; 56 wstats->qual.qual = local->comms_qual;
56 wstats->qual.level = local->avg_signal; 57 wstats->qual.level = local->avg_signal;
@@ -59,7 +60,7 @@ static struct iw_statistics *hostap_get_wireless_stats(struct net_device *dev)
59 wstats->qual.qual = 0; 60 wstats->qual.qual = 0;
60 wstats->qual.level = 0; 61 wstats->qual.level = 0;
61 wstats->qual.noise = 0; 62 wstats->qual.noise = 0;
62 wstats->qual.updated = 0; 63 wstats->qual.updated = IW_QUAL_ALL_INVALID;
63 } 64 }
64 65
65 return wstats; 66 return wstats;
@@ -551,7 +552,6 @@ static int prism2_ioctl_giwaplist(struct net_device *dev,
551 552
552 kfree(addr); 553 kfree(addr);
553 kfree(qual); 554 kfree(qual);
554
555 return 0; 555 return 0;
556} 556}
557 557
@@ -1827,13 +1827,6 @@ static char * __prism2_translate_scan(local_info_t *local,
1827 iwe.cmd = SIOCGIWAP; 1827 iwe.cmd = SIOCGIWAP;
1828 iwe.u.ap_addr.sa_family = ARPHRD_ETHER; 1828 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1829 memcpy(iwe.u.ap_addr.sa_data, bssid, ETH_ALEN); 1829 memcpy(iwe.u.ap_addr.sa_data, bssid, ETH_ALEN);
1830 /* FIX:
1831 * I do not know how this is possible, but iwe_stream_add_event
1832 * seems to re-order memcpy execution so that len is set only
1833 * after copying.. Pre-setting len here "fixes" this, but real
1834 * problems should be solved (after which these iwe.len
1835 * settings could be removed from this function). */
1836 iwe.len = IW_EV_ADDR_LEN;
1837 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, 1830 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1838 IW_EV_ADDR_LEN); 1831 IW_EV_ADDR_LEN);
1839 1832
@@ -1843,7 +1836,6 @@ static char * __prism2_translate_scan(local_info_t *local,
1843 iwe.cmd = SIOCGIWESSID; 1836 iwe.cmd = SIOCGIWESSID;
1844 iwe.u.data.length = ssid_len; 1837 iwe.u.data.length = ssid_len;
1845 iwe.u.data.flags = 1; 1838 iwe.u.data.flags = 1;
1846 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1847 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, ssid); 1839 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, ssid);
1848 1840
1849 memset(&iwe, 0, sizeof(iwe)); 1841 memset(&iwe, 0, sizeof(iwe));
@@ -1859,7 +1851,6 @@ static char * __prism2_translate_scan(local_info_t *local,
1859 iwe.u.mode = IW_MODE_MASTER; 1851 iwe.u.mode = IW_MODE_MASTER;
1860 else 1852 else
1861 iwe.u.mode = IW_MODE_ADHOC; 1853 iwe.u.mode = IW_MODE_ADHOC;
1862 iwe.len = IW_EV_UINT_LEN;
1863 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, 1854 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1864 IW_EV_UINT_LEN); 1855 IW_EV_UINT_LEN);
1865 } 1856 }
@@ -1877,7 +1868,6 @@ static char * __prism2_translate_scan(local_info_t *local,
1877 if (chan > 0) { 1868 if (chan > 0) {
1878 iwe.u.freq.m = freq_list[le16_to_cpu(chan - 1)] * 100000; 1869 iwe.u.freq.m = freq_list[le16_to_cpu(chan - 1)] * 100000;
1879 iwe.u.freq.e = 1; 1870 iwe.u.freq.e = 1;
1880 iwe.len = IW_EV_FREQ_LEN;
1881 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, 1871 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1882 IW_EV_FREQ_LEN); 1872 IW_EV_FREQ_LEN);
1883 } 1873 }
@@ -1894,7 +1884,10 @@ static char * __prism2_translate_scan(local_info_t *local,
1894 iwe.u.qual.noise = 1884 iwe.u.qual.noise =
1895 HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->anl)); 1885 HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->anl));
1896 } 1886 }
1897 iwe.len = IW_EV_QUAL_LEN; 1887 iwe.u.qual.updated = IW_QUAL_LEVEL_UPDATED
1888 | IW_QUAL_NOISE_UPDATED
1889 | IW_QUAL_QUAL_INVALID
1890 | IW_QUAL_DBM;
1898 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, 1891 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1899 IW_EV_QUAL_LEN); 1892 IW_EV_QUAL_LEN);
1900 } 1893 }
@@ -1906,7 +1899,6 @@ static char * __prism2_translate_scan(local_info_t *local,
1906 else 1899 else
1907 iwe.u.data.flags = IW_ENCODE_DISABLED; 1900 iwe.u.data.flags = IW_ENCODE_DISABLED;
1908 iwe.u.data.length = 0; 1901 iwe.u.data.length = 0;
1909 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1910 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, ""); 1902 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, "");
1911 1903
1912 /* TODO: add SuppRates into BSS table */ 1904 /* TODO: add SuppRates into BSS table */
@@ -1930,7 +1922,7 @@ static char * __prism2_translate_scan(local_info_t *local,
1930 } 1922 }
1931 1923
1932 /* TODO: add BeaconInt,resp_rate,atim into BSS table */ 1924 /* TODO: add BeaconInt,resp_rate,atim into BSS table */
1933 buf = kmalloc(MAX_WPA_IE_LEN * 2 + 30, GFP_KERNEL); 1925 buf = kmalloc(MAX_WPA_IE_LEN * 2 + 30, GFP_ATOMIC);
1934 if (buf && scan) { 1926 if (buf && scan) {
1935 memset(&iwe, 0, sizeof(iwe)); 1927 memset(&iwe, 0, sizeof(iwe));
1936 iwe.cmd = IWEVCUSTOM; 1928 iwe.cmd = IWEVCUSTOM;
@@ -3088,9 +3080,7 @@ static int prism2_ioctl_priv_download(local_info_t *local, struct iw_point *p)
3088 ret = local->func->download(local, param); 3080 ret = local->func->download(local, param);
3089 3081
3090 out: 3082 out:
3091 if (param != NULL) 3083 kfree(param);
3092 kfree(param);
3093
3094 return ret; 3084 return ret;
3095} 3085}
3096#endif /* PRISM2_DOWNLOAD_SUPPORT */ 3086#endif /* PRISM2_DOWNLOAD_SUPPORT */
@@ -3897,9 +3887,7 @@ static int prism2_ioctl_priv_hostapd(local_info_t *local, struct iw_point *p)
3897 } 3887 }
3898 3888
3899 out: 3889 out:
3900 if (param != NULL) 3890 kfree(param);
3901 kfree(param);
3902
3903 return ret; 3891 return ret;
3904} 3892}
3905 3893
diff --git a/drivers/net/wireless/hostap/hostap_pci.c b/drivers/net/wireless/hostap/hostap_pci.c
index 025f8cdb5566..da0c80fb941c 100644
--- a/drivers/net/wireless/hostap/hostap_pci.c
+++ b/drivers/net/wireless/hostap/hostap_pci.c
@@ -59,11 +59,13 @@ static struct pci_device_id prism2_pci_id_table[] __devinitdata = {
59static inline void hfa384x_outb_debug(struct net_device *dev, int a, u8 v) 59static inline void hfa384x_outb_debug(struct net_device *dev, int a, u8 v)
60{ 60{
61 struct hostap_interface *iface; 61 struct hostap_interface *iface;
62 struct hostap_pci_priv *hw_priv;
62 local_info_t *local; 63 local_info_t *local;
63 unsigned long flags; 64 unsigned long flags;
64 65
65 iface = netdev_priv(dev); 66 iface = netdev_priv(dev);
66 local = iface->local; 67 local = iface->local;
68 hw_priv = local->hw_priv;
67 69
68 spin_lock_irqsave(&local->lock, flags); 70 spin_lock_irqsave(&local->lock, flags);
69 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTB, a, v); 71 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTB, a, v);
@@ -74,12 +76,14 @@ static inline void hfa384x_outb_debug(struct net_device *dev, int a, u8 v)
74static inline u8 hfa384x_inb_debug(struct net_device *dev, int a) 76static inline u8 hfa384x_inb_debug(struct net_device *dev, int a)
75{ 77{
76 struct hostap_interface *iface; 78 struct hostap_interface *iface;
79 struct hostap_pci_priv *hw_priv;
77 local_info_t *local; 80 local_info_t *local;
78 unsigned long flags; 81 unsigned long flags;
79 u8 v; 82 u8 v;
80 83
81 iface = netdev_priv(dev); 84 iface = netdev_priv(dev);
82 local = iface->local; 85 local = iface->local;
86 hw_priv = local->hw_priv;
83 87
84 spin_lock_irqsave(&local->lock, flags); 88 spin_lock_irqsave(&local->lock, flags);
85 v = readb(hw_priv->mem_start + a); 89 v = readb(hw_priv->mem_start + a);
@@ -91,11 +95,13 @@ static inline u8 hfa384x_inb_debug(struct net_device *dev, int a)
91static inline void hfa384x_outw_debug(struct net_device *dev, int a, u16 v) 95static inline void hfa384x_outw_debug(struct net_device *dev, int a, u16 v)
92{ 96{
93 struct hostap_interface *iface; 97 struct hostap_interface *iface;
98 struct hostap_pci_priv *hw_priv;
94 local_info_t *local; 99 local_info_t *local;
95 unsigned long flags; 100 unsigned long flags;
96 101
97 iface = netdev_priv(dev); 102 iface = netdev_priv(dev);
98 local = iface->local; 103 local = iface->local;
104 hw_priv = local->hw_priv;
99 105
100 spin_lock_irqsave(&local->lock, flags); 106 spin_lock_irqsave(&local->lock, flags);
101 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTW, a, v); 107 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTW, a, v);
@@ -106,12 +112,14 @@ static inline void hfa384x_outw_debug(struct net_device *dev, int a, u16 v)
106static inline u16 hfa384x_inw_debug(struct net_device *dev, int a) 112static inline u16 hfa384x_inw_debug(struct net_device *dev, int a)
107{ 113{
108 struct hostap_interface *iface; 114 struct hostap_interface *iface;
115 struct hostap_pci_priv *hw_priv;
109 local_info_t *local; 116 local_info_t *local;
110 unsigned long flags; 117 unsigned long flags;
111 u16 v; 118 u16 v;
112 119
113 iface = netdev_priv(dev); 120 iface = netdev_priv(dev);
114 local = iface->local; 121 local = iface->local;
122 hw_priv = local->hw_priv;
115 123
116 spin_lock_irqsave(&local->lock, flags); 124 spin_lock_irqsave(&local->lock, flags);
117 v = readw(hw_priv->mem_start + a); 125 v = readw(hw_priv->mem_start + a);
@@ -277,8 +285,6 @@ static struct prism2_helper_functions prism2_pci_funcs =
277{ 285{
278 .card_present = NULL, 286 .card_present = NULL,
279 .cor_sreset = prism2_pci_cor_sreset, 287 .cor_sreset = prism2_pci_cor_sreset,
280 .dev_open = NULL,
281 .dev_close = NULL,
282 .genesis_reset = prism2_pci_genesis_reset, 288 .genesis_reset = prism2_pci_genesis_reset,
283 .hw_type = HOSTAP_HW_PCI, 289 .hw_type = HOSTAP_HW_PCI,
284}; 290};
@@ -352,8 +358,6 @@ static int prism2_pci_probe(struct pci_dev *pdev,
352 return hostap_hw_ready(dev); 358 return hostap_hw_ready(dev);
353 359
354 fail: 360 fail:
355 kfree(hw_priv);
356
357 if (irq_registered && dev) 361 if (irq_registered && dev)
358 free_irq(dev->irq, dev); 362 free_irq(dev->irq, dev);
359 363
@@ -364,10 +368,8 @@ static int prism2_pci_probe(struct pci_dev *pdev,
364 368
365 err_out_disable: 369 err_out_disable:
366 pci_disable_device(pdev); 370 pci_disable_device(pdev);
367 kfree(hw_priv);
368 if (local)
369 local->hw_priv = NULL;
370 prism2_free_local_data(dev); 371 prism2_free_local_data(dev);
372 kfree(hw_priv);
371 373
372 return -ENODEV; 374 return -ENODEV;
373} 375}
@@ -392,9 +394,8 @@ static void prism2_pci_remove(struct pci_dev *pdev)
392 free_irq(dev->irq, dev); 394 free_irq(dev->irq, dev);
393 395
394 mem_start = hw_priv->mem_start; 396 mem_start = hw_priv->mem_start;
395 kfree(hw_priv);
396 iface->local->hw_priv = NULL;
397 prism2_free_local_data(dev); 397 prism2_free_local_data(dev);
398 kfree(hw_priv);
398 399
399 iounmap(mem_start); 400 iounmap(mem_start);
400 401
@@ -441,7 +442,7 @@ static int prism2_pci_resume(struct pci_dev *pdev)
441MODULE_DEVICE_TABLE(pci, prism2_pci_id_table); 442MODULE_DEVICE_TABLE(pci, prism2_pci_id_table);
442 443
443static struct pci_driver prism2_pci_drv_id = { 444static struct pci_driver prism2_pci_drv_id = {
444 .name = "prism2_pci", 445 .name = "hostap_pci",
445 .id_table = prism2_pci_id_table, 446 .id_table = prism2_pci_id_table,
446 .probe = prism2_pci_probe, 447 .probe = prism2_pci_probe,
447 .remove = prism2_pci_remove, 448 .remove = prism2_pci_remove,
diff --git a/drivers/net/wireless/hostap/hostap_plx.c b/drivers/net/wireless/hostap/hostap_plx.c
index 474ef83d813e..78d67b408b2f 100644
--- a/drivers/net/wireless/hostap/hostap_plx.c
+++ b/drivers/net/wireless/hostap/hostap_plx.c
@@ -328,8 +328,6 @@ static struct prism2_helper_functions prism2_plx_funcs =
328{ 328{
329 .card_present = NULL, 329 .card_present = NULL,
330 .cor_sreset = prism2_plx_cor_sreset, 330 .cor_sreset = prism2_plx_cor_sreset,
331 .dev_open = NULL,
332 .dev_close = NULL,
333 .genesis_reset = prism2_plx_genesis_reset, 331 .genesis_reset = prism2_plx_genesis_reset,
334 .hw_type = HOSTAP_HW_PLX, 332 .hw_type = HOSTAP_HW_PLX,
335}; 333};
@@ -570,10 +568,8 @@ static int prism2_plx_probe(struct pci_dev *pdev,
570 return hostap_hw_ready(dev); 568 return hostap_hw_ready(dev);
571 569
572 fail: 570 fail:
573 kfree(hw_priv);
574 if (local)
575 local->hw_priv = NULL;
576 prism2_free_local_data(dev); 571 prism2_free_local_data(dev);
572 kfree(hw_priv);
577 573
578 if (irq_registered && dev) 574 if (irq_registered && dev)
579 free_irq(dev->irq, dev); 575 free_irq(dev->irq, dev);
@@ -606,9 +602,8 @@ static void prism2_plx_remove(struct pci_dev *pdev)
606 if (dev->irq) 602 if (dev->irq)
607 free_irq(dev->irq, dev); 603 free_irq(dev->irq, dev);
608 604
609 kfree(iface->local->hw_priv);
610 iface->local->hw_priv = NULL;
611 prism2_free_local_data(dev); 605 prism2_free_local_data(dev);
606 kfree(hw_priv);
612 pci_disable_device(pdev); 607 pci_disable_device(pdev);
613} 608}
614 609
@@ -616,7 +611,7 @@ static void prism2_plx_remove(struct pci_dev *pdev)
616MODULE_DEVICE_TABLE(pci, prism2_plx_id_table); 611MODULE_DEVICE_TABLE(pci, prism2_plx_id_table);
617 612
618static struct pci_driver prism2_plx_drv_id = { 613static struct pci_driver prism2_plx_drv_id = {
619 .name = "prism2_plx", 614 .name = "hostap_plx",
620 .id_table = prism2_plx_id_table, 615 .id_table = prism2_plx_id_table,
621 .probe = prism2_plx_probe, 616 .probe = prism2_plx_probe,
622 .remove = prism2_plx_remove, 617 .remove = prism2_plx_remove,
diff --git a/drivers/net/wireless/hostap/hostap_wlan.h b/drivers/net/wireless/hostap/hostap_wlan.h
index cc061e1560d3..cfd801559492 100644
--- a/drivers/net/wireless/hostap/hostap_wlan.h
+++ b/drivers/net/wireless/hostap/hostap_wlan.h
@@ -552,8 +552,6 @@ struct prism2_helper_functions {
552 * (hostap_{cs,plx,pci}.c */ 552 * (hostap_{cs,plx,pci}.c */
553 int (*card_present)(local_info_t *local); 553 int (*card_present)(local_info_t *local);
554 void (*cor_sreset)(local_info_t *local); 554 void (*cor_sreset)(local_info_t *local);
555 int (*dev_open)(local_info_t *local);
556 int (*dev_close)(local_info_t *local);
557 void (*genesis_reset)(local_info_t *local, int hcr); 555 void (*genesis_reset)(local_info_t *local, int hcr);
558 556
559 /* the following functions are from hostap_hw.c, but they may have some 557 /* the following functions are from hostap_hw.c, but they may have some
diff --git a/drivers/net/wireless/ipw2100.c b/drivers/net/wireless/ipw2100.c
index 2414e6493aa5..ad7f8cd76db9 100644
--- a/drivers/net/wireless/ipw2100.c
+++ b/drivers/net/wireless/ipw2100.c
@@ -800,8 +800,7 @@ static int ipw2100_hw_send_command(struct ipw2100_priv *priv,
800 * doesn't seem to have as many firmware restart cycles... 800 * doesn't seem to have as many firmware restart cycles...
801 * 801 *
802 * As a test, we're sticking in a 1/100s delay here */ 802 * As a test, we're sticking in a 1/100s delay here */
803 set_current_state(TASK_UNINTERRUPTIBLE); 803 schedule_timeout_uninterruptible(msecs_to_jiffies(10));
804 schedule_timeout(HZ / 100);
805 804
806 return 0; 805 return 0;
807 806
@@ -1256,8 +1255,7 @@ static int ipw2100_start_adapter(struct ipw2100_priv *priv)
1256 IPW_DEBUG_FW("Waiting for f/w initialization to complete...\n"); 1255 IPW_DEBUG_FW("Waiting for f/w initialization to complete...\n");
1257 i = 5000; 1256 i = 5000;
1258 do { 1257 do {
1259 set_current_state(TASK_UNINTERRUPTIBLE); 1258 schedule_timeout_uninterruptible(msecs_to_jiffies(40));
1260 schedule_timeout(40 * HZ / 1000);
1261 /* Todo... wait for sync command ... */ 1259 /* Todo... wait for sync command ... */
1262 1260
1263 read_register(priv->net_dev, IPW_REG_INTA, &inta); 1261 read_register(priv->net_dev, IPW_REG_INTA, &inta);
@@ -1411,8 +1409,7 @@ static int ipw2100_hw_phy_off(struct ipw2100_priv *priv)
1411 (val2 & IPW2100_COMMAND_PHY_OFF)) 1409 (val2 & IPW2100_COMMAND_PHY_OFF))
1412 return 0; 1410 return 0;
1413 1411
1414 set_current_state(TASK_UNINTERRUPTIBLE); 1412 schedule_timeout_uninterruptible(HW_PHY_OFF_LOOP_DELAY);
1415 schedule_timeout(HW_PHY_OFF_LOOP_DELAY);
1416 } 1413 }
1417 1414
1418 return -EIO; 1415 return -EIO;
@@ -1466,7 +1463,7 @@ fail_up:
1466 1463
1467static int ipw2100_hw_stop_adapter(struct ipw2100_priv *priv) 1464static int ipw2100_hw_stop_adapter(struct ipw2100_priv *priv)
1468{ 1465{
1469#define HW_POWER_DOWN_DELAY (HZ / 10) 1466#define HW_POWER_DOWN_DELAY (msecs_to_jiffies(100))
1470 1467
1471 struct host_command cmd = { 1468 struct host_command cmd = {
1472 .host_command = HOST_PRE_POWER_DOWN, 1469 .host_command = HOST_PRE_POWER_DOWN,
@@ -1520,10 +1517,8 @@ static int ipw2100_hw_stop_adapter(struct ipw2100_priv *priv)
1520 printk(KERN_WARNING DRV_NAME ": " 1517 printk(KERN_WARNING DRV_NAME ": "
1521 "%s: Power down command failed: Error %d\n", 1518 "%s: Power down command failed: Error %d\n",
1522 priv->net_dev->name, err); 1519 priv->net_dev->name, err);
1523 else { 1520 else
1524 set_current_state(TASK_UNINTERRUPTIBLE); 1521 schedule_timeout_uninterruptible(HW_POWER_DOWN_DELAY);
1525 schedule_timeout(HW_POWER_DOWN_DELAY);
1526 }
1527 } 1522 }
1528 1523
1529 priv->status &= ~STATUS_ENABLED; 1524 priv->status &= ~STATUS_ENABLED;
@@ -2953,7 +2948,7 @@ static void ipw2100_tx_send_data(struct ipw2100_priv *priv)
2953 int next = txq->next; 2948 int next = txq->next;
2954 int i = 0; 2949 int i = 0;
2955 struct ipw2100_data_header *ipw_hdr; 2950 struct ipw2100_data_header *ipw_hdr;
2956 struct ieee80211_hdr *hdr; 2951 struct ieee80211_hdr_3addr *hdr;
2957 2952
2958 while (!list_empty(&priv->tx_pend_list)) { 2953 while (!list_empty(&priv->tx_pend_list)) {
2959 /* if there isn't enough space in TBD queue, then 2954 /* if there isn't enough space in TBD queue, then
@@ -2989,7 +2984,7 @@ static void ipw2100_tx_send_data(struct ipw2100_priv *priv)
2989 packet->index = txq->next; 2984 packet->index = txq->next;
2990 2985
2991 ipw_hdr = packet->info.d_struct.data; 2986 ipw_hdr = packet->info.d_struct.data;
2992 hdr = (struct ieee80211_hdr *)packet->info.d_struct.txb-> 2987 hdr = (struct ieee80211_hdr_3addr *)packet->info.d_struct.txb->
2993 fragments[0]->data; 2988 fragments[0]->data;
2994 2989
2995 if (priv->ieee->iw_mode == IW_MODE_INFRA) { 2990 if (priv->ieee->iw_mode == IW_MODE_INFRA) {
@@ -3274,7 +3269,8 @@ static irqreturn_t ipw2100_interrupt(int irq, void *data,
3274 return IRQ_NONE; 3269 return IRQ_NONE;
3275} 3270}
3276 3271
3277static int ipw2100_tx(struct ieee80211_txb *txb, struct net_device *dev) 3272static int ipw2100_tx(struct ieee80211_txb *txb, struct net_device *dev,
3273 int pri)
3278{ 3274{
3279 struct ipw2100_priv *priv = ieee80211_priv(dev); 3275 struct ipw2100_priv *priv = ieee80211_priv(dev);
3280 struct list_head *element; 3276 struct list_head *element;
diff --git a/drivers/net/wireless/ipw2100.h b/drivers/net/wireless/ipw2100.h
index 2a3cdbd50168..c9e99ce15d66 100644
--- a/drivers/net/wireless/ipw2100.h
+++ b/drivers/net/wireless/ipw2100.h
@@ -808,7 +808,7 @@ struct ipw2100_priv {
808struct ipw2100_rx { 808struct ipw2100_rx {
809 union { 809 union {
810 unsigned char payload[IPW_RX_NIC_BUFFER_LENGTH]; 810 unsigned char payload[IPW_RX_NIC_BUFFER_LENGTH];
811 struct ieee80211_hdr header; 811 struct ieee80211_hdr_4addr header;
812 u32 status; 812 u32 status;
813 struct ipw2100_notification notification; 813 struct ipw2100_notification notification;
814 struct ipw2100_cmd_header command; 814 struct ipw2100_cmd_header command;
diff --git a/drivers/net/wireless/ipw2200.c b/drivers/net/wireless/ipw2200.c
index b7f275c00de3..3db0c32afe82 100644
--- a/drivers/net/wireless/ipw2200.c
+++ b/drivers/net/wireless/ipw2200.c
@@ -4030,6 +4030,10 @@ static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
4030 int i; 4030 int i;
4031 4031
4032 rxq = (struct ipw_rx_queue *)kmalloc(sizeof(*rxq), GFP_KERNEL); 4032 rxq = (struct ipw_rx_queue *)kmalloc(sizeof(*rxq), GFP_KERNEL);
4033 if (unlikely(!rxq)) {
4034 IPW_ERROR("memory allocation failed\n");
4035 return NULL;
4036 }
4033 memset(rxq, 0, sizeof(*rxq)); 4037 memset(rxq, 0, sizeof(*rxq));
4034 spin_lock_init(&rxq->lock); 4038 spin_lock_init(&rxq->lock);
4035 INIT_LIST_HEAD(&rxq->rx_free); 4039 INIT_LIST_HEAD(&rxq->rx_free);
@@ -4904,7 +4908,7 @@ static void ipw_rx(struct ipw_priv *priv)
4904{ 4908{
4905 struct ipw_rx_mem_buffer *rxb; 4909 struct ipw_rx_mem_buffer *rxb;
4906 struct ipw_rx_packet *pkt; 4910 struct ipw_rx_packet *pkt;
4907 struct ieee80211_hdr *header; 4911 struct ieee80211_hdr_4addr *header;
4908 u32 r, w, i; 4912 u32 r, w, i;
4909 u8 network_packet; 4913 u8 network_packet;
4910 4914
@@ -4967,8 +4971,9 @@ static void ipw_rx(struct ipw_priv *priv)
4967#endif 4971#endif
4968 4972
4969 header = 4973 header =
4970 (struct ieee80211_hdr *)(rxb->skb->data + 4974 (struct ieee80211_hdr_4addr *)(rxb->skb->
4971 IPW_RX_FRAME_SIZE); 4975 data +
4976 IPW_RX_FRAME_SIZE);
4972 /* TODO: Check Ad-Hoc dest/source and make sure 4977 /* TODO: Check Ad-Hoc dest/source and make sure
4973 * that we are actually parsing these packets 4978 * that we are actually parsing these packets
4974 * correctly -- we should probably use the 4979 * correctly -- we should probably use the
@@ -5317,8 +5322,6 @@ static int ipw_wx_set_freq(struct net_device *dev,
5317 5322
5318 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m); 5323 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
5319 return ipw_set_channel(priv, (u8) fwrq->m); 5324 return ipw_set_channel(priv, (u8) fwrq->m);
5320
5321 return 0;
5322} 5325}
5323 5326
5324static int ipw_wx_get_freq(struct net_device *dev, 5327static int ipw_wx_get_freq(struct net_device *dev,
@@ -6010,12 +6013,12 @@ static int ipw_wx_set_wireless_mode(struct net_device *dev,
6010 } 6013 }
6011 6014
6012 if (priv->adapter == IPW_2915ABG) { 6015 if (priv->adapter == IPW_2915ABG) {
6013 priv->ieee->abg_ture = 1; 6016 priv->ieee->abg_true = 1;
6014 if (mode & IEEE_A) { 6017 if (mode & IEEE_A) {
6015 band |= IEEE80211_52GHZ_BAND; 6018 band |= IEEE80211_52GHZ_BAND;
6016 modulation |= IEEE80211_OFDM_MODULATION; 6019 modulation |= IEEE80211_OFDM_MODULATION;
6017 } else 6020 } else
6018 priv->ieee->abg_ture = 0; 6021 priv->ieee->abg_true = 0;
6019 } else { 6022 } else {
6020 if (mode & IEEE_A) { 6023 if (mode & IEEE_A) {
6021 IPW_WARNING("Attempt to set 2200BG into " 6024 IPW_WARNING("Attempt to set 2200BG into "
@@ -6023,20 +6026,20 @@ static int ipw_wx_set_wireless_mode(struct net_device *dev,
6023 return -EINVAL; 6026 return -EINVAL;
6024 } 6027 }
6025 6028
6026 priv->ieee->abg_ture = 0; 6029 priv->ieee->abg_true = 0;
6027 } 6030 }
6028 6031
6029 if (mode & IEEE_B) { 6032 if (mode & IEEE_B) {
6030 band |= IEEE80211_24GHZ_BAND; 6033 band |= IEEE80211_24GHZ_BAND;
6031 modulation |= IEEE80211_CCK_MODULATION; 6034 modulation |= IEEE80211_CCK_MODULATION;
6032 } else 6035 } else
6033 priv->ieee->abg_ture = 0; 6036 priv->ieee->abg_true = 0;
6034 6037
6035 if (mode & IEEE_G) { 6038 if (mode & IEEE_G) {
6036 band |= IEEE80211_24GHZ_BAND; 6039 band |= IEEE80211_24GHZ_BAND;
6037 modulation |= IEEE80211_OFDM_MODULATION; 6040 modulation |= IEEE80211_OFDM_MODULATION;
6038 } else 6041 } else
6039 priv->ieee->abg_ture = 0; 6042 priv->ieee->abg_true = 0;
6040 6043
6041 priv->ieee->mode = mode; 6044 priv->ieee->mode = mode;
6042 priv->ieee->freq_band = band; 6045 priv->ieee->freq_band = band;
@@ -6325,7 +6328,7 @@ we need to heavily modify the ieee80211_skb_to_txb.
6325 6328
6326static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb) 6329static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb)
6327{ 6330{
6328 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) 6331 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)
6329 txb->fragments[0]->data; 6332 txb->fragments[0]->data;
6330 int i = 0; 6333 int i = 0;
6331 struct tfd_frame *tfd; 6334 struct tfd_frame *tfd;
@@ -6448,7 +6451,7 @@ static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb)
6448} 6451}
6449 6452
6450static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb, 6453static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
6451 struct net_device *dev) 6454 struct net_device *dev, int pri)
6452{ 6455{
6453 struct ipw_priv *priv = ieee80211_priv(dev); 6456 struct ipw_priv *priv = ieee80211_priv(dev);
6454 unsigned long flags; 6457 unsigned long flags;
@@ -7108,7 +7111,7 @@ static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
7108 printk(KERN_INFO DRV_NAME 7111 printk(KERN_INFO DRV_NAME
7109 ": Detected Intel PRO/Wireless 2915ABG Network " 7112 ": Detected Intel PRO/Wireless 2915ABG Network "
7110 "Connection\n"); 7113 "Connection\n");
7111 priv->ieee->abg_ture = 1; 7114 priv->ieee->abg_true = 1;
7112 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND; 7115 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
7113 modulation = IEEE80211_OFDM_MODULATION | 7116 modulation = IEEE80211_OFDM_MODULATION |
7114 IEEE80211_CCK_MODULATION; 7117 IEEE80211_CCK_MODULATION;
@@ -7124,7 +7127,7 @@ static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
7124 ": Detected Intel PRO/Wireless 2200BG Network " 7127 ": Detected Intel PRO/Wireless 2200BG Network "
7125 "Connection\n"); 7128 "Connection\n");
7126 7129
7127 priv->ieee->abg_ture = 0; 7130 priv->ieee->abg_true = 0;
7128 band = IEEE80211_24GHZ_BAND; 7131 band = IEEE80211_24GHZ_BAND;
7129 modulation = IEEE80211_OFDM_MODULATION | 7132 modulation = IEEE80211_OFDM_MODULATION |
7130 IEEE80211_CCK_MODULATION; 7133 IEEE80211_CCK_MODULATION;
diff --git a/drivers/net/wireless/ipw2200.h b/drivers/net/wireless/ipw2200.h
index 5b00882133f9..e9cf32bf3e31 100644
--- a/drivers/net/wireless/ipw2200.h
+++ b/drivers/net/wireless/ipw2200.h
@@ -1654,12 +1654,12 @@ static const long ipw_frequencies[] = {
1654 1654
1655#define IPW_MAX_CONFIG_RETRIES 10 1655#define IPW_MAX_CONFIG_RETRIES 10
1656 1656
1657static inline u32 frame_hdr_len(struct ieee80211_hdr *hdr) 1657static inline u32 frame_hdr_len(struct ieee80211_hdr_4addr *hdr)
1658{ 1658{
1659 u32 retval; 1659 u32 retval;
1660 u16 fc; 1660 u16 fc;
1661 1661
1662 retval = sizeof(struct ieee80211_hdr); 1662 retval = sizeof(struct ieee80211_hdr_3addr);
1663 fc = le16_to_cpu(hdr->frame_ctl); 1663 fc = le16_to_cpu(hdr->frame_ctl);
1664 1664
1665 /* 1665 /*
diff --git a/drivers/net/wireless/netwave_cs.c b/drivers/net/wireless/netwave_cs.c
index ca6c03c89926..92793b958e32 100644
--- a/drivers/net/wireless/netwave_cs.c
+++ b/drivers/net/wireless/netwave_cs.c
@@ -57,9 +57,7 @@
57#include <linux/bitops.h> 57#include <linux/bitops.h>
58#ifdef CONFIG_NET_RADIO 58#ifdef CONFIG_NET_RADIO
59#include <linux/wireless.h> 59#include <linux/wireless.h>
60#if WIRELESS_EXT > 12
61#include <net/iw_handler.h> 60#include <net/iw_handler.h>
62#endif /* WIRELESS_EXT > 12 */
63#endif 61#endif
64 62
65#include <pcmcia/cs_types.h> 63#include <pcmcia/cs_types.h>
@@ -225,10 +223,7 @@ static void update_stats(struct net_device *dev);
225static struct net_device_stats *netwave_get_stats(struct net_device *dev); 223static struct net_device_stats *netwave_get_stats(struct net_device *dev);
226 224
227/* Wireless extensions */ 225/* Wireless extensions */
228#ifdef WIRELESS_EXT
229static struct iw_statistics* netwave_get_wireless_stats(struct net_device *dev); 226static struct iw_statistics* netwave_get_wireless_stats(struct net_device *dev);
230#endif
231static int netwave_ioctl(struct net_device *, struct ifreq *, int);
232 227
233static void set_multicast_list(struct net_device *dev); 228static void set_multicast_list(struct net_device *dev);
234 229
@@ -260,26 +255,7 @@ static dev_link_t *dev_list;
260 because they generally can't be allocated dynamically. 255 because they generally can't be allocated dynamically.
261*/ 256*/
262 257
263#if WIRELESS_EXT <= 12
264/* Wireless extensions backward compatibility */
265
266/* Part of iw_handler prototype we need */
267struct iw_request_info
268{
269 __u16 cmd; /* Wireless Extension command */
270 __u16 flags; /* More to come ;-) */
271};
272
273/* Wireless Extension Backward compatibility - Jean II
274 * If the new wireless device private ioctl range is not defined,
275 * default to standard device private ioctl range */
276#ifndef SIOCIWFIRSTPRIV
277#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
278#endif /* SIOCIWFIRSTPRIV */
279
280#else /* WIRELESS_EXT <= 12 */
281static const struct iw_handler_def netwave_handler_def; 258static const struct iw_handler_def netwave_handler_def;
282#endif /* WIRELESS_EXT <= 12 */
283 259
284#define SIOCGIPSNAP SIOCIWFIRSTPRIV + 1 /* Site Survey Snapshot */ 260#define SIOCGIPSNAP SIOCIWFIRSTPRIV + 1 /* Site Survey Snapshot */
285 261
@@ -319,9 +295,7 @@ typedef struct netwave_private {
319 struct timer_list watchdog; /* To avoid blocking state */ 295 struct timer_list watchdog; /* To avoid blocking state */
320 struct site_survey nss; 296 struct site_survey nss;
321 struct net_device_stats stats; 297 struct net_device_stats stats;
322#ifdef WIRELESS_EXT
323 struct iw_statistics iw_stats; /* Wireless stats */ 298 struct iw_statistics iw_stats; /* Wireless stats */
324#endif
325} netwave_private; 299} netwave_private;
326 300
327#ifdef NETWAVE_STATS 301#ifdef NETWAVE_STATS
@@ -353,7 +327,6 @@ static inline void wait_WOC(unsigned int iobase)
353 while ((inb(iobase + NETWAVE_REG_ASR) & 0x8) != 0x8) ; 327 while ((inb(iobase + NETWAVE_REG_ASR) & 0x8) != 0x8) ;
354} 328}
355 329
356#ifdef WIRELESS_EXT
357static void netwave_snapshot(netwave_private *priv, u_char __iomem *ramBase, 330static void netwave_snapshot(netwave_private *priv, u_char __iomem *ramBase,
358 kio_addr_t iobase) { 331 kio_addr_t iobase) {
359 u_short resultBuffer; 332 u_short resultBuffer;
@@ -376,9 +349,7 @@ static void netwave_snapshot(netwave_private *priv, u_char __iomem *ramBase,
376 sizeof(struct site_survey)); 349 sizeof(struct site_survey));
377 } 350 }
378} 351}
379#endif
380 352
381#ifdef WIRELESS_EXT
382/* 353/*
383 * Function netwave_get_wireless_stats (dev) 354 * Function netwave_get_wireless_stats (dev)
384 * 355 *
@@ -411,7 +382,6 @@ static struct iw_statistics *netwave_get_wireless_stats(struct net_device *dev)
411 382
412 return &priv->iw_stats; 383 return &priv->iw_stats;
413} 384}
414#endif
415 385
416/* 386/*
417 * Function netwave_attach (void) 387 * Function netwave_attach (void)
@@ -471,13 +441,7 @@ static dev_link_t *netwave_attach(void)
471 dev->get_stats = &netwave_get_stats; 441 dev->get_stats = &netwave_get_stats;
472 dev->set_multicast_list = &set_multicast_list; 442 dev->set_multicast_list = &set_multicast_list;
473 /* wireless extensions */ 443 /* wireless extensions */
474#if WIRELESS_EXT <= 16
475 dev->get_wireless_stats = &netwave_get_wireless_stats;
476#endif /* WIRELESS_EXT <= 16 */
477#if WIRELESS_EXT > 12
478 dev->wireless_handlers = (struct iw_handler_def *)&netwave_handler_def; 444 dev->wireless_handlers = (struct iw_handler_def *)&netwave_handler_def;
479#endif /* WIRELESS_EXT > 12 */
480 dev->do_ioctl = &netwave_ioctl;
481 445
482 dev->tx_timeout = &netwave_watchdog; 446 dev->tx_timeout = &netwave_watchdog;
483 dev->watchdog_timeo = TX_TIMEOUT; 447 dev->watchdog_timeo = TX_TIMEOUT;
@@ -576,13 +540,8 @@ static int netwave_set_nwid(struct net_device *dev,
576 /* Disable interrupts & save flags */ 540 /* Disable interrupts & save flags */
577 spin_lock_irqsave(&priv->spinlock, flags); 541 spin_lock_irqsave(&priv->spinlock, flags);
578 542
579#if WIRELESS_EXT > 8
580 if(!wrqu->nwid.disabled) { 543 if(!wrqu->nwid.disabled) {
581 domain = wrqu->nwid.value; 544 domain = wrqu->nwid.value;
582#else /* WIRELESS_EXT > 8 */
583 if(wrqu->nwid.on) {
584 domain = wrqu->nwid.nwid;
585#endif /* WIRELESS_EXT > 8 */
586 printk( KERN_DEBUG "Setting domain to 0x%x%02x\n", 545 printk( KERN_DEBUG "Setting domain to 0x%x%02x\n",
587 (domain >> 8) & 0x01, domain & 0xff); 546 (domain >> 8) & 0x01, domain & 0xff);
588 wait_WOC(iobase); 547 wait_WOC(iobase);
@@ -606,15 +565,9 @@ static int netwave_get_nwid(struct net_device *dev,
606 union iwreq_data *wrqu, 565 union iwreq_data *wrqu,
607 char *extra) 566 char *extra)
608{ 567{
609#if WIRELESS_EXT > 8
610 wrqu->nwid.value = domain; 568 wrqu->nwid.value = domain;
611 wrqu->nwid.disabled = 0; 569 wrqu->nwid.disabled = 0;
612 wrqu->nwid.fixed = 1; 570 wrqu->nwid.fixed = 1;
613#else /* WIRELESS_EXT > 8 */
614 wrqu->nwid.nwid = domain;
615 wrqu->nwid.on = 1;
616#endif /* WIRELESS_EXT > 8 */
617
618 return 0; 571 return 0;
619} 572}
620 573
@@ -657,17 +610,11 @@ static int netwave_get_scramble(struct net_device *dev,
657{ 610{
658 key[1] = scramble_key & 0xff; 611 key[1] = scramble_key & 0xff;
659 key[0] = (scramble_key>>8) & 0xff; 612 key[0] = (scramble_key>>8) & 0xff;
660#if WIRELESS_EXT > 8
661 wrqu->encoding.flags = IW_ENCODE_ENABLED; 613 wrqu->encoding.flags = IW_ENCODE_ENABLED;
662 wrqu->encoding.length = 2; 614 wrqu->encoding.length = 2;
663#else /* WIRELESS_EXT > 8 */
664 wrqu->encoding.method = 1;
665#endif /* WIRELESS_EXT > 8 */
666
667 return 0; 615 return 0;
668} 616}
669 617
670#if WIRELESS_EXT > 8
671/* 618/*
672 * Wireless Handler : get mode 619 * Wireless Handler : get mode
673 */ 620 */
@@ -683,7 +630,6 @@ static int netwave_get_mode(struct net_device *dev,
683 630
684 return 0; 631 return 0;
685} 632}
686#endif /* WIRELESS_EXT > 8 */
687 633
688/* 634/*
689 * Wireless Handler : get range info 635 * Wireless Handler : get range info
@@ -702,11 +648,9 @@ static int netwave_get_range(struct net_device *dev,
702 /* Set all the info we don't care or don't know about to zero */ 648 /* Set all the info we don't care or don't know about to zero */
703 memset(range, 0, sizeof(struct iw_range)); 649 memset(range, 0, sizeof(struct iw_range));
704 650
705#if WIRELESS_EXT > 10
706 /* Set the Wireless Extension versions */ 651 /* Set the Wireless Extension versions */
707 range->we_version_compiled = WIRELESS_EXT; 652 range->we_version_compiled = WIRELESS_EXT;
708 range->we_version_source = 9; /* Nothing for us in v10 and v11 */ 653 range->we_version_source = 9; /* Nothing for us in v10 and v11 */
709#endif /* WIRELESS_EXT > 10 */
710 654
711 /* Set information in the range struct */ 655 /* Set information in the range struct */
712 range->throughput = 450 * 1000; /* don't argue on this ! */ 656 range->throughput = 450 * 1000; /* don't argue on this ! */
@@ -720,16 +664,12 @@ static int netwave_get_range(struct net_device *dev,
720 range->max_qual.level = 255; 664 range->max_qual.level = 255;
721 range->max_qual.noise = 0; 665 range->max_qual.noise = 0;
722 666
723#if WIRELESS_EXT > 7
724 range->num_bitrates = 1; 667 range->num_bitrates = 1;
725 range->bitrate[0] = 1000000; /* 1 Mb/s */ 668 range->bitrate[0] = 1000000; /* 1 Mb/s */
726#endif /* WIRELESS_EXT > 7 */
727 669
728#if WIRELESS_EXT > 8
729 range->encoding_size[0] = 2; /* 16 bits scrambling */ 670 range->encoding_size[0] = 2; /* 16 bits scrambling */
730 range->num_encoding_sizes = 1; 671 range->num_encoding_sizes = 1;
731 range->max_encoding_tokens = 1; /* Only one key possible */ 672 range->max_encoding_tokens = 1; /* Only one key possible */
732#endif /* WIRELESS_EXT > 8 */
733 673
734 return ret; 674 return ret;
735} 675}
@@ -775,8 +715,6 @@ static const struct iw_priv_args netwave_private_args[] = {
775 "getsitesurvey" }, 715 "getsitesurvey" },
776}; 716};
777 717
778#if WIRELESS_EXT > 12
779
780static const iw_handler netwave_handler[] = 718static const iw_handler netwave_handler[] =
781{ 719{
782 NULL, /* SIOCSIWNAME */ 720 NULL, /* SIOCSIWNAME */
@@ -839,131 +777,8 @@ static const struct iw_handler_def netwave_handler_def =
839 .standard = (iw_handler *) netwave_handler, 777 .standard = (iw_handler *) netwave_handler,
840 .private = (iw_handler *) netwave_private_handler, 778 .private = (iw_handler *) netwave_private_handler,
841 .private_args = (struct iw_priv_args *) netwave_private_args, 779 .private_args = (struct iw_priv_args *) netwave_private_args,
842#if WIRELESS_EXT > 16
843 .get_wireless_stats = netwave_get_wireless_stats, 780 .get_wireless_stats = netwave_get_wireless_stats,
844#endif /* WIRELESS_EXT > 16 */
845}; 781};
846#endif /* WIRELESS_EXT > 12 */
847
848/*
849 * Function netwave_ioctl (dev, rq, cmd)
850 *
851 * Perform ioctl : config & info stuff
852 * This is the stuff that are treated the wireless extensions (iwconfig)
853 *
854 */
855static int netwave_ioctl(struct net_device *dev, /* ioctl device */
856 struct ifreq *rq, /* Data passed */
857 int cmd) /* Ioctl number */
858{
859 int ret = 0;
860#ifdef WIRELESS_EXT
861#if WIRELESS_EXT <= 12
862 struct iwreq *wrq = (struct iwreq *) rq;
863#endif
864#endif
865
866 DEBUG(0, "%s: ->netwave_ioctl(cmd=0x%X)\n", dev->name, cmd);
867
868 /* Look what is the request */
869 switch(cmd) {
870 /* --------------- WIRELESS EXTENSIONS --------------- */
871#ifdef WIRELESS_EXT
872#if WIRELESS_EXT <= 12
873 case SIOCGIWNAME:
874 netwave_get_name(dev, NULL, &(wrq->u), NULL);
875 break;
876 case SIOCSIWNWID:
877 ret = netwave_set_nwid(dev, NULL, &(wrq->u), NULL);
878 break;
879 case SIOCGIWNWID:
880 ret = netwave_get_nwid(dev, NULL, &(wrq->u), NULL);
881 break;
882#if WIRELESS_EXT > 8 /* Note : The API did change... */
883 case SIOCGIWENCODE:
884 /* Get scramble key */
885 if(wrq->u.encoding.pointer != (caddr_t) 0)
886 {
887 char key[2];
888 ret = netwave_get_scramble(dev, NULL, &(wrq->u), key);
889 if(copy_to_user(wrq->u.encoding.pointer, key, 2))
890 ret = -EFAULT;
891 }
892 break;
893 case SIOCSIWENCODE:
894 /* Set scramble key */
895 if(wrq->u.encoding.pointer != (caddr_t) 0)
896 {
897 char key[2];
898 if(copy_from_user(key, wrq->u.encoding.pointer, 2))
899 {
900 ret = -EFAULT;
901 break;
902 }
903 ret = netwave_set_scramble(dev, NULL, &(wrq->u), key);
904 }
905 break;
906 case SIOCGIWMODE:
907 /* Mode of operation */
908 ret = netwave_get_mode(dev, NULL, &(wrq->u), NULL);
909 break;
910#else /* WIRELESS_EXT > 8 */
911 case SIOCGIWENCODE:
912 /* Get scramble key */
913 ret = netwave_get_scramble(dev, NULL, &(wrq->u),
914 (char *) &wrq->u.encoding.code);
915 break;
916 case SIOCSIWENCODE:
917 /* Set scramble key */
918 ret = netwave_set_scramble(dev, NULL, &(wrq->u),
919 (char *) &wrq->u.encoding.code);
920 break;
921#endif /* WIRELESS_EXT > 8 */
922 case SIOCGIWRANGE:
923 /* Basic checking... */
924 if(wrq->u.data.pointer != (caddr_t) 0) {
925 struct iw_range range;
926 ret = netwave_get_range(dev, NULL, &(wrq->u), (char *) &range);
927 if (copy_to_user(wrq->u.data.pointer, &range,
928 sizeof(struct iw_range)))
929 ret = -EFAULT;
930 }
931 break;
932 case SIOCGIWPRIV:
933 /* Basic checking... */
934 if(wrq->u.data.pointer != (caddr_t) 0) {
935 /* Set the number of ioctl available */
936 wrq->u.data.length = sizeof(netwave_private_args) / sizeof(netwave_private_args[0]);
937
938 /* Copy structure to the user buffer */
939 if(copy_to_user(wrq->u.data.pointer,
940 (u_char *) netwave_private_args,
941 sizeof(netwave_private_args)))
942 ret = -EFAULT;
943 }
944 break;
945 case SIOCGIPSNAP:
946 if(wrq->u.data.pointer != (caddr_t) 0) {
947 char buffer[sizeof( struct site_survey)];
948 ret = netwave_get_snap(dev, NULL, &(wrq->u), buffer);
949 /* Copy structure to the user buffer */
950 if(copy_to_user(wrq->u.data.pointer,
951 buffer,
952 sizeof( struct site_survey)))
953 {
954 printk(KERN_DEBUG "Bad buffer!\n");
955 break;
956 }
957 }
958 break;
959#endif /* WIRELESS_EXT <= 12 */
960#endif /* WIRELESS_EXT */
961 default:
962 ret = -EOPNOTSUPP;
963 }
964
965 return ret;
966}
967 782
968/* 783/*
969 * Function netwave_pcmcia_config (link) 784 * Function netwave_pcmcia_config (link)
diff --git a/drivers/net/wireless/orinoco.c b/drivers/net/wireless/orinoco.c
index 15ceaf615756..488ab06fb79f 100644
--- a/drivers/net/wireless/orinoco.c
+++ b/drivers/net/wireless/orinoco.c
@@ -77,30 +77,16 @@
77#define DRIVER_NAME "orinoco" 77#define DRIVER_NAME "orinoco"
78 78
79#include <linux/config.h> 79#include <linux/config.h>
80
81#include <linux/module.h> 80#include <linux/module.h>
82#include <linux/kernel.h> 81#include <linux/kernel.h>
83#include <linux/init.h> 82#include <linux/init.h>
84#include <linux/ptrace.h>
85#include <linux/slab.h>
86#include <linux/string.h>
87#include <linux/timer.h>
88#include <linux/ioport.h>
89#include <linux/netdevice.h> 83#include <linux/netdevice.h>
90#include <linux/if_arp.h>
91#include <linux/etherdevice.h> 84#include <linux/etherdevice.h>
92#include <linux/ethtool.h> 85#include <linux/ethtool.h>
93#include <linux/wireless.h> 86#include <linux/wireless.h>
94#include <net/iw_handler.h> 87#include <net/iw_handler.h>
95#include <net/ieee80211.h> 88#include <net/ieee80211.h>
96 89
97#include <net/ieee80211.h>
98
99#include <asm/uaccess.h>
100#include <asm/io.h>
101#include <asm/system.h>
102
103#include "hermes.h"
104#include "hermes_rid.h" 90#include "hermes_rid.h"
105#include "orinoco.h" 91#include "orinoco.h"
106 92
@@ -137,7 +123,7 @@ MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
137 123
138/* We do this this way to avoid ifdefs in the actual code */ 124/* We do this this way to avoid ifdefs in the actual code */
139#ifdef WIRELESS_SPY 125#ifdef WIRELESS_SPY
140#define SPY_NUMBER(priv) (priv->spy_number) 126#define SPY_NUMBER(priv) (priv->spy_data.spy_number)
141#else 127#else
142#define SPY_NUMBER(priv) 0 128#define SPY_NUMBER(priv) 0
143#endif /* WIRELESS_SPY */ 129#endif /* WIRELESS_SPY */
@@ -216,31 +202,32 @@ static struct {
216/********************************************************************/ 202/********************************************************************/
217 203
218/* Used in Event handling. 204/* Used in Event handling.
219 * We avoid nested structres as they break on ARM -- Moustafa */ 205 * We avoid nested structures as they break on ARM -- Moustafa */
220struct hermes_tx_descriptor_802_11 { 206struct hermes_tx_descriptor_802_11 {
221 /* hermes_tx_descriptor */ 207 /* hermes_tx_descriptor */
222 u16 status; 208 __le16 status;
223 u16 reserved1; 209 __le16 reserved1;
224 u16 reserved2; 210 __le16 reserved2;
225 u32 sw_support; 211 __le32 sw_support;
226 u8 retry_count; 212 u8 retry_count;
227 u8 tx_rate; 213 u8 tx_rate;
228 u16 tx_control; 214 __le16 tx_control;
229 215
230 /* ieee802_11_hdr */ 216 /* ieee80211_hdr */
231 u16 frame_ctl; 217 __le16 frame_ctl;
232 u16 duration_id; 218 __le16 duration_id;
233 u8 addr1[ETH_ALEN]; 219 u8 addr1[ETH_ALEN];
234 u8 addr2[ETH_ALEN]; 220 u8 addr2[ETH_ALEN];
235 u8 addr3[ETH_ALEN]; 221 u8 addr3[ETH_ALEN];
236 u16 seq_ctl; 222 __le16 seq_ctl;
237 u8 addr4[ETH_ALEN]; 223 u8 addr4[ETH_ALEN];
238 u16 data_len; 224
225 __le16 data_len;
239 226
240 /* ethhdr */ 227 /* ethhdr */
241 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */ 228 u8 h_dest[ETH_ALEN]; /* destination eth addr */
242 unsigned char h_source[ETH_ALEN]; /* source ether addr */ 229 u8 h_source[ETH_ALEN]; /* source ether addr */
243 unsigned short h_proto; /* packet type ID field */ 230 __be16 h_proto; /* packet type ID field */
244 231
245 /* p8022_hdr */ 232 /* p8022_hdr */
246 u8 dsap; 233 u8 dsap;
@@ -248,31 +235,31 @@ struct hermes_tx_descriptor_802_11 {
248 u8 ctrl; 235 u8 ctrl;
249 u8 oui[3]; 236 u8 oui[3];
250 237
251 u16 ethertype; 238 __be16 ethertype;
252} __attribute__ ((packed)); 239} __attribute__ ((packed));
253 240
254/* Rx frame header except compatibility 802.3 header */ 241/* Rx frame header except compatibility 802.3 header */
255struct hermes_rx_descriptor { 242struct hermes_rx_descriptor {
256 /* Control */ 243 /* Control */
257 u16 status; 244 __le16 status;
258 u32 time; 245 __le32 time;
259 u8 silence; 246 u8 silence;
260 u8 signal; 247 u8 signal;
261 u8 rate; 248 u8 rate;
262 u8 rxflow; 249 u8 rxflow;
263 u32 reserved; 250 __le32 reserved;
264 251
265 /* 802.11 header */ 252 /* 802.11 header */
266 u16 frame_ctl; 253 __le16 frame_ctl;
267 u16 duration_id; 254 __le16 duration_id;
268 u8 addr1[ETH_ALEN]; 255 u8 addr1[ETH_ALEN];
269 u8 addr2[ETH_ALEN]; 256 u8 addr2[ETH_ALEN];
270 u8 addr3[ETH_ALEN]; 257 u8 addr3[ETH_ALEN];
271 u16 seq_ctl; 258 __le16 seq_ctl;
272 u8 addr4[ETH_ALEN]; 259 u8 addr4[ETH_ALEN];
273 260
274 /* Data length */ 261 /* Data length */
275 u16 data_len; 262 __le16 data_len;
276} __attribute__ ((packed)); 263} __attribute__ ((packed));
277 264
278/********************************************************************/ 265/********************************************************************/
@@ -396,14 +383,14 @@ static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
396 /* If a spy address is defined, we report stats of the 383 /* If a spy address is defined, we report stats of the
397 * first spy address - Jean II */ 384 * first spy address - Jean II */
398 if (SPY_NUMBER(priv)) { 385 if (SPY_NUMBER(priv)) {
399 wstats->qual.qual = priv->spy_stat[0].qual; 386 wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
400 wstats->qual.level = priv->spy_stat[0].level; 387 wstats->qual.level = priv->spy_data.spy_stat[0].level;
401 wstats->qual.noise = priv->spy_stat[0].noise; 388 wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
402 wstats->qual.updated = priv->spy_stat[0].updated; 389 wstats->qual.updated = priv->spy_data.spy_stat[0].updated;
403 } 390 }
404 } else { 391 } else {
405 struct { 392 struct {
406 u16 qual, signal, noise; 393 __le16 qual, signal, noise;
407 } __attribute__ ((packed)) cq; 394 } __attribute__ ((packed)) cq;
408 395
409 err = HERMES_READ_RECORD(hw, USER_BAP, 396 err = HERMES_READ_RECORD(hw, USER_BAP,
@@ -503,13 +490,12 @@ static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
503 return 0; 490 return 0;
504 } 491 }
505 492
506 /* Check packet length, pad short packets, round up odd length */ 493 /* Length of the packet body */
494 /* FIXME: what if the skb is smaller than this? */
507 len = max_t(int, ALIGN(skb->len, 2), ETH_ZLEN); 495 len = max_t(int, ALIGN(skb->len, 2), ETH_ZLEN);
508 if (skb->len < len) { 496 skb = skb_padto(skb, len);
509 skb = skb_padto(skb, len); 497 if (skb == NULL)
510 if (skb == NULL) 498 goto fail;
511 goto fail;
512 }
513 len -= ETH_HLEN; 499 len -= ETH_HLEN;
514 500
515 eh = (struct ethhdr *)skb->data; 501 eh = (struct ethhdr *)skb->data;
@@ -556,13 +542,21 @@ static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
556 stats->tx_errors++; 542 stats->tx_errors++;
557 goto fail; 543 goto fail;
558 } 544 }
545 /* Actual xfer length - allow for padding */
546 len = ALIGN(data_len, 2);
547 if (len < ETH_ZLEN - ETH_HLEN)
548 len = ETH_ZLEN - ETH_HLEN;
559 } else { /* IEEE 802.3 frame */ 549 } else { /* IEEE 802.3 frame */
560 data_len = len + ETH_HLEN; 550 data_len = len + ETH_HLEN;
561 data_off = HERMES_802_3_OFFSET; 551 data_off = HERMES_802_3_OFFSET;
562 p = skb->data; 552 p = skb->data;
553 /* Actual xfer length - round up for odd length packets */
554 len = ALIGN(data_len, 2);
555 if (len < ETH_ZLEN)
556 len = ETH_ZLEN;
563 } 557 }
564 558
565 err = hermes_bap_pwrite(hw, USER_BAP, p, data_len, 559 err = hermes_bap_pwrite_pad(hw, USER_BAP, p, data_len, len,
566 txfid, data_off); 560 txfid, data_off);
567 if (err) { 561 if (err) {
568 printk(KERN_ERR "%s: Error %d writing packet to BAP\n", 562 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
@@ -634,16 +628,17 @@ static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
634 struct orinoco_private *priv = netdev_priv(dev); 628 struct orinoco_private *priv = netdev_priv(dev);
635 struct net_device_stats *stats = &priv->stats; 629 struct net_device_stats *stats = &priv->stats;
636 u16 fid = hermes_read_regn(hw, TXCOMPLFID); 630 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
631 u16 status;
637 struct hermes_tx_descriptor_802_11 hdr; 632 struct hermes_tx_descriptor_802_11 hdr;
638 int err = 0; 633 int err = 0;
639 634
640 if (fid == DUMMY_FID) 635 if (fid == DUMMY_FID)
641 return; /* Nothing's really happened */ 636 return; /* Nothing's really happened */
642 637
643 /* Read the frame header */ 638 /* Read part of the frame header - we need status and addr1 */
644 err = hermes_bap_pread(hw, IRQ_BAP, &hdr, 639 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
645 sizeof(struct hermes_tx_descriptor) + 640 offsetof(struct hermes_tx_descriptor_802_11,
646 sizeof(struct ieee80211_hdr), 641 addr2),
647 fid, 0); 642 fid, 0);
648 643
649 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID); 644 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
@@ -663,8 +658,8 @@ static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
663 * exceeded, because that's the only status that really mean 658 * exceeded, because that's the only status that really mean
664 * that this particular node went away. 659 * that this particular node went away.
665 * Other errors means that *we* screwed up. - Jean II */ 660 * Other errors means that *we* screwed up. - Jean II */
666 hdr.status = le16_to_cpu(hdr.status); 661 status = le16_to_cpu(hdr.status);
667 if (hdr.status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) { 662 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
668 union iwreq_data wrqu; 663 union iwreq_data wrqu;
669 664
670 /* Copy 802.11 dest address. 665 /* Copy 802.11 dest address.
@@ -723,18 +718,13 @@ static inline int is_ethersnap(void *_hdr)
723static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac, 718static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
724 int level, int noise) 719 int level, int noise)
725{ 720{
726 struct orinoco_private *priv = netdev_priv(dev); 721 struct iw_quality wstats;
727 int i; 722 wstats.level = level - 0x95;
728 723 wstats.noise = noise - 0x95;
729 /* Gather wireless spy statistics: for each packet, compare the 724 wstats.qual = (level > noise) ? (level - noise) : 0;
730 * source address with out list, and if match, get the stats... */ 725 wstats.updated = 7;
731 for (i = 0; i < priv->spy_number; i++) 726 /* Update spy records */
732 if (!memcmp(mac, priv->spy_address[i], ETH_ALEN)) { 727 wireless_spy_update(dev, mac, &wstats);
733 priv->spy_stat[i].level = level - 0x95;
734 priv->spy_stat[i].noise = noise - 0x95;
735 priv->spy_stat[i].qual = (level > noise) ? (level - noise) : 0;
736 priv->spy_stat[i].updated = 7;
737 }
738} 728}
739 729
740static void orinoco_stat_gather(struct net_device *dev, 730static void orinoco_stat_gather(struct net_device *dev,
@@ -1055,7 +1045,7 @@ static void orinoco_join_ap(struct net_device *dev)
1055 unsigned long flags; 1045 unsigned long flags;
1056 struct join_req { 1046 struct join_req {
1057 u8 bssid[ETH_ALEN]; 1047 u8 bssid[ETH_ALEN];
1058 u16 channel; 1048 __le16 channel;
1059 } __attribute__ ((packed)) req; 1049 } __attribute__ ((packed)) req;
1060 const int atom_len = offsetof(struct prism2_scan_apinfo, atim); 1050 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
1061 struct prism2_scan_apinfo *atom = NULL; 1051 struct prism2_scan_apinfo *atom = NULL;
@@ -1070,7 +1060,7 @@ static void orinoco_join_ap(struct net_device *dev)
1070 return; 1060 return;
1071 1061
1072 if (orinoco_lock(priv, &flags) != 0) 1062 if (orinoco_lock(priv, &flags) != 0)
1073 goto out; 1063 goto fail_lock;
1074 1064
1075 /* Sanity checks in case user changed something in the meantime */ 1065 /* Sanity checks in case user changed something in the meantime */
1076 if (! priv->bssid_fixed) 1066 if (! priv->bssid_fixed)
@@ -1115,8 +1105,10 @@ static void orinoco_join_ap(struct net_device *dev)
1115 printk(KERN_ERR "%s: Error issuing join request\n", dev->name); 1105 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1116 1106
1117 out: 1107 out:
1118 kfree(buf);
1119 orinoco_unlock(priv, &flags); 1108 orinoco_unlock(priv, &flags);
1109
1110 fail_lock:
1111 kfree(buf);
1120} 1112}
1121 1113
1122/* Send new BSSID to userspace */ 1114/* Send new BSSID to userspace */
@@ -1134,12 +1126,14 @@ static void orinoco_send_wevents(struct net_device *dev)
1134 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID, 1126 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1135 ETH_ALEN, NULL, wrqu.ap_addr.sa_data); 1127 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1136 if (err != 0) 1128 if (err != 0)
1137 return; 1129 goto out;
1138 1130
1139 wrqu.ap_addr.sa_family = ARPHRD_ETHER; 1131 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1140 1132
1141 /* Send event to user space */ 1133 /* Send event to user space */
1142 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); 1134 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1135
1136 out:
1143 orinoco_unlock(priv, &flags); 1137 orinoco_unlock(priv, &flags);
1144} 1138}
1145 1139
@@ -1148,8 +1142,8 @@ static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1148 struct orinoco_private *priv = netdev_priv(dev); 1142 struct orinoco_private *priv = netdev_priv(dev);
1149 u16 infofid; 1143 u16 infofid;
1150 struct { 1144 struct {
1151 u16 len; 1145 __le16 len;
1152 u16 type; 1146 __le16 type;
1153 } __attribute__ ((packed)) info; 1147 } __attribute__ ((packed)) info;
1154 int len, type; 1148 int len, type;
1155 int err; 1149 int err;
@@ -2464,6 +2458,10 @@ struct net_device *alloc_orinocodev(int sizeof_card,
2464 dev->get_stats = orinoco_get_stats; 2458 dev->get_stats = orinoco_get_stats;
2465 dev->ethtool_ops = &orinoco_ethtool_ops; 2459 dev->ethtool_ops = &orinoco_ethtool_ops;
2466 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def; 2460 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
2461#ifdef WIRELESS_SPY
2462 priv->wireless_data.spy_data = &priv->spy_data;
2463 dev->wireless_data = &priv->wireless_data;
2464#endif
2467 dev->change_mtu = orinoco_change_mtu; 2465 dev->change_mtu = orinoco_change_mtu;
2468 dev->set_multicast_list = orinoco_set_multicast_list; 2466 dev->set_multicast_list = orinoco_set_multicast_list;
2469 /* we use the default eth_mac_addr for setting the MAC addr */ 2467 /* we use the default eth_mac_addr for setting the MAC addr */
@@ -2835,7 +2833,7 @@ static int orinoco_ioctl_getiwrange(struct net_device *dev,
2835 } 2833 }
2836 } 2834 }
2837 2835
2838 if ((priv->iw_mode == IW_MODE_ADHOC) && (priv->spy_number == 0)){ 2836 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
2839 /* Quality stats meaningless in ad-hoc mode */ 2837 /* Quality stats meaningless in ad-hoc mode */
2840 } else { 2838 } else {
2841 range->max_qual.qual = 0x8b - 0x2f; 2839 range->max_qual.qual = 0x8b - 0x2f;
@@ -2882,6 +2880,14 @@ static int orinoco_ioctl_getiwrange(struct net_device *dev,
2882 range->min_r_time = 0; 2880 range->min_r_time = 0;
2883 range->max_r_time = 65535 * 1000; /* ??? */ 2881 range->max_r_time = 65535 * 1000; /* ??? */
2884 2882
2883 /* Event capability (kernel) */
2884 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
2885 /* Event capability (driver) */
2886 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
2887 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
2888 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
2889 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
2890
2885 TRACE_EXIT(dev->name); 2891 TRACE_EXIT(dev->name);
2886 2892
2887 return 0; 2893 return 0;
@@ -3841,92 +3847,6 @@ static int orinoco_ioctl_getrid(struct net_device *dev,
3841 return err; 3847 return err;
3842} 3848}
3843 3849
3844/* Spy is used for link quality/strength measurements in Ad-Hoc mode
3845 * Jean II */
3846static int orinoco_ioctl_setspy(struct net_device *dev,
3847 struct iw_request_info *info,
3848 struct iw_point *srq,
3849 char *extra)
3850
3851{
3852 struct orinoco_private *priv = netdev_priv(dev);
3853 struct sockaddr *address = (struct sockaddr *) extra;
3854 int number = srq->length;
3855 int i;
3856 unsigned long flags;
3857
3858 /* Make sure nobody mess with the structure while we do */
3859 if (orinoco_lock(priv, &flags) != 0)
3860 return -EBUSY;
3861
3862 /* orinoco_lock() doesn't disable interrupts, so make sure the
3863 * interrupt rx path don't get confused while we copy */
3864 priv->spy_number = 0;
3865
3866 if (number > 0) {
3867 /* Extract the addresses */
3868 for (i = 0; i < number; i++)
3869 memcpy(priv->spy_address[i], address[i].sa_data,
3870 ETH_ALEN);
3871 /* Reset stats */
3872 memset(priv->spy_stat, 0,
3873 sizeof(struct iw_quality) * IW_MAX_SPY);
3874 /* Set number of addresses */
3875 priv->spy_number = number;
3876 }
3877
3878 /* Now, let the others play */
3879 orinoco_unlock(priv, &flags);
3880
3881 /* Do NOT call commit handler */
3882 return 0;
3883}
3884
3885static int orinoco_ioctl_getspy(struct net_device *dev,
3886 struct iw_request_info *info,
3887 struct iw_point *srq,
3888 char *extra)
3889{
3890 struct orinoco_private *priv = netdev_priv(dev);
3891 struct sockaddr *address = (struct sockaddr *) extra;
3892 int number;
3893 int i;
3894 unsigned long flags;
3895
3896 if (orinoco_lock(priv, &flags) != 0)
3897 return -EBUSY;
3898
3899 number = priv->spy_number;
3900 /* Create address struct */
3901 for (i = 0; i < number; i++) {
3902 memcpy(address[i].sa_data, priv->spy_address[i], ETH_ALEN);
3903 address[i].sa_family = AF_UNIX;
3904 }
3905 if (number > 0) {
3906 /* Create address struct */
3907 for (i = 0; i < number; i++) {
3908 memcpy(address[i].sa_data, priv->spy_address[i],
3909 ETH_ALEN);
3910 address[i].sa_family = AF_UNIX;
3911 }
3912 /* Copy stats */
3913 /* In theory, we should disable irqs while copying the stats
3914 * because the rx path might update it in the middle...
3915 * Bah, who care ? - Jean II */
3916 memcpy(extra + (sizeof(struct sockaddr) * number),
3917 priv->spy_stat, sizeof(struct iw_quality) * number);
3918 }
3919 /* Reset updated flags. */
3920 for (i = 0; i < number; i++)
3921 priv->spy_stat[i].updated = 0;
3922
3923 orinoco_unlock(priv, &flags);
3924
3925 srq->length = number;
3926
3927 return 0;
3928}
3929
3930/* Trigger a scan (look for other cells in the vicinity */ 3850/* Trigger a scan (look for other cells in the vicinity */
3931static int orinoco_ioctl_setscan(struct net_device *dev, 3851static int orinoco_ioctl_setscan(struct net_device *dev,
3932 struct iw_request_info *info, 3852 struct iw_request_info *info,
@@ -3999,7 +3919,7 @@ static int orinoco_ioctl_setscan(struct net_device *dev,
3999 HERMES_HOSTSCAN_SYMBOL_BCAST); 3919 HERMES_HOSTSCAN_SYMBOL_BCAST);
4000 break; 3920 break;
4001 case FIRMWARE_TYPE_INTERSIL: { 3921 case FIRMWARE_TYPE_INTERSIL: {
4002 u16 req[3]; 3922 __le16 req[3];
4003 3923
4004 req[0] = cpu_to_le16(0x3fff); /* All channels */ 3924 req[0] = cpu_to_le16(0x3fff); /* All channels */
4005 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */ 3925 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
@@ -4073,7 +3993,7 @@ static inline int orinoco_translate_scan(struct net_device *dev,
4073 case FIRMWARE_TYPE_INTERSIL: 3993 case FIRMWARE_TYPE_INTERSIL:
4074 offset = 4; 3994 offset = 4;
4075 if (priv->has_hostscan) { 3995 if (priv->has_hostscan) {
4076 atom_len = le16_to_cpup((u16 *)scan); 3996 atom_len = le16_to_cpup((__le16 *)scan);
4077 /* Sanity check for atom_len */ 3997 /* Sanity check for atom_len */
4078 if (atom_len < sizeof(struct prism2_scan_apinfo)) { 3998 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
4079 printk(KERN_ERR "%s: Invalid atom_len in scan data: %d\n", 3999 printk(KERN_ERR "%s: Invalid atom_len in scan data: %d\n",
@@ -4357,8 +4277,10 @@ static const iw_handler orinoco_handler[] = {
4357 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens, 4277 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
4358 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens, 4278 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
4359 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange, 4279 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
4360 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setspy, 4280 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
4361 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getspy, 4281 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
4282 [SIOCSIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
4283 [SIOCGIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
4362 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap, 4284 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
4363 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap, 4285 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
4364 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan, 4286 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
diff --git a/drivers/net/wireless/orinoco.h b/drivers/net/wireless/orinoco.h
index 2f213a7103fe..7a17bb31fc89 100644
--- a/drivers/net/wireless/orinoco.h
+++ b/drivers/net/wireless/orinoco.h
@@ -7,12 +7,11 @@
7#ifndef _ORINOCO_H 7#ifndef _ORINOCO_H
8#define _ORINOCO_H 8#define _ORINOCO_H
9 9
10#define DRIVER_VERSION "0.15rc2" 10#define DRIVER_VERSION "0.15rc3"
11 11
12#include <linux/types.h>
13#include <linux/spinlock.h>
14#include <linux/netdevice.h> 12#include <linux/netdevice.h>
15#include <linux/wireless.h> 13#include <linux/wireless.h>
14#include <net/iw_handler.h>
16#include <linux/version.h> 15#include <linux/version.h>
17 16
18#include "hermes.h" 17#include "hermes.h"
@@ -28,7 +27,7 @@
28#define ORINOCO_MAX_KEYS 4 27#define ORINOCO_MAX_KEYS 4
29 28
30struct orinoco_key { 29struct orinoco_key {
31 u16 len; /* always stored as little-endian */ 30 __le16 len; /* always stored as little-endian */
32 char data[ORINOCO_MAX_KEY_SIZE]; 31 char data[ORINOCO_MAX_KEY_SIZE];
33} __attribute__ ((packed)); 32} __attribute__ ((packed));
34 33
@@ -36,14 +35,14 @@ struct header_struct {
36 /* 802.3 */ 35 /* 802.3 */
37 u8 dest[ETH_ALEN]; 36 u8 dest[ETH_ALEN];
38 u8 src[ETH_ALEN]; 37 u8 src[ETH_ALEN];
39 u16 len; 38 __be16 len;
40 /* 802.2 */ 39 /* 802.2 */
41 u8 dsap; 40 u8 dsap;
42 u8 ssap; 41 u8 ssap;
43 u8 ctrl; 42 u8 ctrl;
44 /* SNAP */ 43 /* SNAP */
45 u8 oui[3]; 44 u8 oui[3];
46 u16 ethertype; 45 unsigned short ethertype;
47} __attribute__ ((packed)); 46} __attribute__ ((packed));
48 47
49typedef enum { 48typedef enum {
@@ -112,9 +111,8 @@ struct orinoco_private {
112 u16 pm_on, pm_mcast, pm_period, pm_timeout; 111 u16 pm_on, pm_mcast, pm_period, pm_timeout;
113 u16 preamble; 112 u16 preamble;
114#ifdef WIRELESS_SPY 113#ifdef WIRELESS_SPY
115 int spy_number; 114 struct iw_spy_data spy_data; /* iwspy support */
116 u_char spy_address[IW_MAX_SPY][ETH_ALEN]; 115 struct iw_public_data wireless_data;
117 struct iw_quality spy_stat[IW_MAX_SPY];
118#endif 116#endif
119 117
120 /* Configuration dependent variables */ 118 /* Configuration dependent variables */
diff --git a/drivers/net/wireless/orinoco_cs.c b/drivers/net/wireless/orinoco_cs.c
index bedd7f9f23e4..dc1128a00971 100644
--- a/drivers/net/wireless/orinoco_cs.c
+++ b/drivers/net/wireless/orinoco_cs.c
@@ -14,33 +14,16 @@
14#define PFX DRIVER_NAME ": " 14#define PFX DRIVER_NAME ": "
15 15
16#include <linux/config.h> 16#include <linux/config.h>
17#ifdef __IN_PCMCIA_PACKAGE__
18#include <pcmcia/k_compat.h>
19#endif /* __IN_PCMCIA_PACKAGE__ */
20
21#include <linux/module.h> 17#include <linux/module.h>
22#include <linux/kernel.h> 18#include <linux/kernel.h>
23#include <linux/init.h> 19#include <linux/init.h>
24#include <linux/sched.h> 20#include <linux/delay.h>
25#include <linux/ptrace.h>
26#include <linux/slab.h>
27#include <linux/string.h>
28#include <linux/ioport.h>
29#include <linux/netdevice.h>
30#include <linux/if_arp.h>
31#include <linux/etherdevice.h>
32#include <linux/wireless.h>
33
34#include <pcmcia/cs_types.h> 21#include <pcmcia/cs_types.h>
35#include <pcmcia/cs.h> 22#include <pcmcia/cs.h>
36#include <pcmcia/cistpl.h> 23#include <pcmcia/cistpl.h>
37#include <pcmcia/cisreg.h> 24#include <pcmcia/cisreg.h>
38#include <pcmcia/ds.h> 25#include <pcmcia/ds.h>
39 26
40#include <asm/uaccess.h>
41#include <asm/io.h>
42#include <asm/system.h>
43
44#include "orinoco.h" 27#include "orinoco.h"
45 28
46/********************************************************************/ 29/********************************************************************/
@@ -97,17 +80,8 @@ static dev_link_t *dev_list; /* = NULL */
97/* Function prototypes */ 80/* Function prototypes */
98/********************************************************************/ 81/********************************************************************/
99 82
100/* device methods */ 83static void orinoco_cs_release(dev_link_t *link);
101static int orinoco_cs_hard_reset(struct orinoco_private *priv); 84static void orinoco_cs_detach(dev_link_t *link);
102
103/* PCMCIA gumpf */
104static void orinoco_cs_config(dev_link_t * link);
105static void orinoco_cs_release(dev_link_t * link);
106static int orinoco_cs_event(event_t event, int priority,
107 event_callback_args_t * args);
108
109static dev_link_t *orinoco_cs_attach(void);
110static void orinoco_cs_detach(dev_link_t *);
111 85
112/********************************************************************/ 86/********************************************************************/
113/* Device methods */ 87/* Device methods */
@@ -603,49 +577,85 @@ static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
603 "Pavel Roskin <proski@gnu.org>, et al)"; 577 "Pavel Roskin <proski@gnu.org>, et al)";
604 578
605static struct pcmcia_device_id orinoco_cs_ids[] = { 579static struct pcmcia_device_id orinoco_cs_ids[] = {
606 PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300), 580 PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7100), /* SonicWALL Long Range Wireless Card */
607 PCMCIA_DEVICE_MANF_CARD(0x0138, 0x0002), 581 PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300), /* Sohoware NCP110, Philips 802.11b */
608 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0002), 582 PCMCIA_DEVICE_MANF_CARD(0x0089, 0x0002), /* AnyPoint(TM) Wireless II PC Card */
609 PCMCIA_DEVICE_MANF_CARD(0x01eb, 0x080a), 583 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0777), /* 3Com AirConnect PCI 777A */
610 PCMCIA_DEVICE_MANF_CARD(0x0261, 0x0002), 584 PCMCIA_DEVICE_MANF_CARD(0x0126, 0x8000), /* PROXIM RangeLAN-DS/LAN PC CARD */
611 PCMCIA_DEVICE_MANF_CARD(0x0268, 0x0001), 585 PCMCIA_DEVICE_MANF_CARD(0x0138, 0x0002), /* Compaq WL100 11 Mbps Wireless Adapter */
612 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0305), 586 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0002), /* Lucent Orinoco and old Intersil */
613 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1613), 587 PCMCIA_DEVICE_MANF_CARD(0x016b, 0x0001), /* Ericsson WLAN Card C11 */
614 PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0002), 588 PCMCIA_DEVICE_MANF_CARD(0x01eb, 0x080a), /* Nortel Networks eMobility 802.11 Wireless Adapter */
615 PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0673), 589 PCMCIA_DEVICE_MANF_CARD(0x01ff, 0x0008), /* Intermec MobileLAN 11Mbps 802.11b WLAN Card */
616 PCMCIA_DEVICE_MANF_CARD(0x02aa, 0x0002), 590 PCMCIA_DEVICE_MANF_CARD(0x0250, 0x0002), /* Samsung SWL2000-N 11Mb/s WLAN Card */
617 PCMCIA_DEVICE_MANF_CARD(0x02ac, 0x0002), 591 PCMCIA_DEVICE_MANF_CARD(0x0261, 0x0002), /* AirWay 802.11 Adapter (PCMCIA) */
618 PCMCIA_DEVICE_MANF_CARD(0x14ea, 0xb001), 592 PCMCIA_DEVICE_MANF_CARD(0x0268, 0x0001), /* ARtem Onair */
619 PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x7300), 593 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0305), /* Buffalo WLI-PCM-S11 */
620 PCMCIA_DEVICE_MANF_CARD(0x9005, 0x0021), 594 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1612), /* Linksys WPC11 Version 2.5 */
621 PCMCIA_DEVICE_MANF_CARD(0xc250, 0x0002), 595 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1613), /* Linksys WPC11 Version 3 */
622 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002), 596 PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0002), /* Compaq HNW-100 11 Mbps Wireless Adapter */
623 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005), 597 PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0673), /* Linksys WCF12 Wireless CompactFlash Card */
598 PCMCIA_DEVICE_MANF_CARD(0x02aa, 0x0002), /* ASUS SpaceLink WL-100 */
599 PCMCIA_DEVICE_MANF_CARD(0x02ac, 0x0002), /* SpeedStream SS1021 Wireless Adapter */
600 PCMCIA_DEVICE_MANF_CARD(0x14ea, 0xb001), /* PLANEX RoadLannerWave GW-NS11H */
601 PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x7300), /* Airvast WN-100 */
602 PCMCIA_DEVICE_MANF_CARD(0x9005, 0x0021), /* Adaptec Ultra Wireless ANW-8030 */
603 PCMCIA_DEVICE_MANF_CARD(0xc001, 0x0008), /* CONTEC FLEXSCAN/FX-DDS110-PCC */
604 PCMCIA_DEVICE_MANF_CARD(0xc250, 0x0002), /* Conceptronic CON11Cpro, EMTAC A2424i */
605 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002), /* Safeway 802.11b, ZCOMAX AirRunner/XI-300 */
606 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005), /* D-Link DCF660, Sandisk Connect SDWCFB-000 */
607 PCMCIA_DEVICE_PROD_ID12(" ", "IEEE 802.11 Wireless LAN/PC Card", 0x3b6e20c8, 0xefccafe9),
624 PCMCIA_DEVICE_PROD_ID12("3Com", "3CRWE737A AirConnect Wireless LAN PC Card", 0x41240e5b, 0x56010af3), 608 PCMCIA_DEVICE_PROD_ID12("3Com", "3CRWE737A AirConnect Wireless LAN PC Card", 0x41240e5b, 0x56010af3),
625 PCMCIA_DEVICE_PROD_ID123("Instant Wireless ", " Network PC CARD", "Version 01.02", 0x11d901af, 0x6e9bd926, 0x4b74baa0),
626 PCMCIA_DEVICE_PROD_ID12("ACTIONTEC", "PRISM Wireless LAN PC Card", 0x393089da, 0xa71e69d5), 609 PCMCIA_DEVICE_PROD_ID12("ACTIONTEC", "PRISM Wireless LAN PC Card", 0x393089da, 0xa71e69d5),
610 PCMCIA_DEVICE_PROD_ID12("Addtron", "AWP-100 Wireless PCMCIA", 0xe6ec52ce, 0x08649af2),
611 PCMCIA_DEVICE_PROD_ID123("AIRVAST", "IEEE 802.11b Wireless PCMCIA Card", "HFA3863", 0xea569531, 0x4bcb9645, 0x355cb092),
612 PCMCIA_DEVICE_PROD_ID12("Allied Telesyn", "AT-WCL452 Wireless PCMCIA Radio", 0x5cd01705, 0x4271660f),
613 PCMCIA_DEVICE_PROD_ID12("ASUS", "802_11b_PC_CARD_25", 0x78fc06ee, 0xdb9aa842),
614 PCMCIA_DEVICE_PROD_ID12("ASUS", "802_11B_CF_CARD_25", 0x78fc06ee, 0x45a50c1e),
627 PCMCIA_DEVICE_PROD_ID12("Avaya Communication", "Avaya Wireless PC Card", 0xd8a43b78, 0x0d341169), 615 PCMCIA_DEVICE_PROD_ID12("Avaya Communication", "Avaya Wireless PC Card", 0xd8a43b78, 0x0d341169),
616 PCMCIA_DEVICE_PROD_ID12("BENQ", "AWL100 PCMCIA ADAPTER", 0x35dadc74, 0x01f7fedb),
628 PCMCIA_DEVICE_PROD_ID12("BUFFALO", "WLI-PCM-L11G", 0x2decece3, 0xf57ca4b3), 617 PCMCIA_DEVICE_PROD_ID12("BUFFALO", "WLI-PCM-L11G", 0x2decece3, 0xf57ca4b3),
618 PCMCIA_DEVICE_PROD_ID12("BUFFALO", "WLI-CF-S11G", 0x2decece3, 0x82067c18),
629 PCMCIA_DEVICE_PROD_ID12("Cabletron", "RoamAbout 802.11 DS", 0x32d445f5, 0xedeffd90), 619 PCMCIA_DEVICE_PROD_ID12("Cabletron", "RoamAbout 802.11 DS", 0x32d445f5, 0xedeffd90),
620 PCMCIA_DEVICE_PROD_ID12("Compaq", "WL200_11Mbps_Wireless_PCI_Card", 0x54f7c49c, 0x15a75e5b),
621 PCMCIA_DEVICE_PROD_ID123("corega", "WL PCCL-11", "ISL37300P", 0x0a21501a, 0x59868926, 0xc9049a39),
630 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "Wireless LAN PCC-11", 0x5261440f, 0xa6405584), 622 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "Wireless LAN PCC-11", 0x5261440f, 0xa6405584),
631 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "Wireless LAN PCCA-11", 0x5261440f, 0xdf6115f9), 623 PCMCIA_DEVICE_PROD_ID12("corega K.K.", "Wireless LAN PCCA-11", 0x5261440f, 0xdf6115f9),
632 PCMCIA_DEVICE_PROD_ID12("corega_K.K.", "Wireless_LAN_PCCB-11", 0x29e33311, 0xee7a27ae), 624 PCMCIA_DEVICE_PROD_ID12("corega_K.K.", "Wireless_LAN_PCCB-11", 0x29e33311, 0xee7a27ae),
633 PCMCIA_DEVICE_PROD_ID12("D", "Link DRC-650 11Mbps WLAN Card", 0x71b18589, 0xf144e3ac), 625 PCMCIA_DEVICE_PROD_ID12("D", "Link DRC-650 11Mbps WLAN Card", 0x71b18589, 0xf144e3ac),
634 PCMCIA_DEVICE_PROD_ID12("D", "Link DWL-650 11Mbps WLAN Card", 0x71b18589, 0xb6f1b0ab), 626 PCMCIA_DEVICE_PROD_ID12("D", "Link DWL-650 11Mbps WLAN Card", 0x71b18589, 0xb6f1b0ab),
627 PCMCIA_DEVICE_PROD_ID12("D-Link Corporation", "D-Link DWL-650H 11Mbps WLAN Adapter", 0xef544d24, 0xcd8ea916),
628 PCMCIA_DEVICE_PROD_ID12("Digital Data Communications", "WPC-0100", 0xfdd73470, 0xe0b6f146),
635 PCMCIA_DEVICE_PROD_ID12("ELSA", "AirLancer MC-11", 0x4507a33a, 0xef54f0e3), 629 PCMCIA_DEVICE_PROD_ID12("ELSA", "AirLancer MC-11", 0x4507a33a, 0xef54f0e3),
636 PCMCIA_DEVICE_PROD_ID12("HyperLink", "Wireless PC Card 11Mbps", 0x56cc3f1a, 0x0bcf220c), 630 PCMCIA_DEVICE_PROD_ID12("HyperLink", "Wireless PC Card 11Mbps", 0x56cc3f1a, 0x0bcf220c),
631 PCMCIA_DEVICE_PROD_ID123("Instant Wireless ", " Network PC CARD", "Version 01.02", 0x11d901af, 0x6e9bd926, 0x4b74baa0),
632 PCMCIA_DEVICE_PROD_ID12("Intel", "PRO/Wireless 2011 LAN PC Card", 0x816cc815, 0x07f58077),
637 PCMCIA_DEVICE_PROD_ID12("INTERSIL", "HFA384x/IEEE", 0x74c5e40d, 0xdb472a18), 633 PCMCIA_DEVICE_PROD_ID12("INTERSIL", "HFA384x/IEEE", 0x74c5e40d, 0xdb472a18),
634 PCMCIA_DEVICE_PROD_ID12("INTERSIL", "I-GATE 11M PC Card / PC Card plus", 0x74c5e40d, 0x8304ff77),
635 PCMCIA_DEVICE_PROD_ID12("Intersil", "PRISM 2_5 PCMCIA ADAPTER", 0x4b801a17, 0x6345a0bf),
636 PCMCIA_DEVICE_PROD_ID123("Intersil", "PRISM Freedom PCMCIA Adapter", "ISL37100P", 0x4b801a17, 0xf222ec2d, 0x630d52b2),
637 PCMCIA_DEVICE_PROD_ID12("LeArtery", "SYNCBYAIR 11Mbps Wireless LAN PC Card", 0x7e3b326a, 0x49893e92),
638 PCMCIA_DEVICE_PROD_ID12("Linksys", "Wireless CompactFlash Card", 0x0733cc81, 0x0c52f395),
638 PCMCIA_DEVICE_PROD_ID12("Lucent Technologies", "WaveLAN/IEEE", 0x23eb9949, 0xc562e72a), 639 PCMCIA_DEVICE_PROD_ID12("Lucent Technologies", "WaveLAN/IEEE", 0x23eb9949, 0xc562e72a),
639 PCMCIA_DEVICE_PROD_ID12("MELCO", "WLI-PCM-L11", 0x481e0094, 0x7360e410), 640 PCMCIA_DEVICE_PROD_ID12("MELCO", "WLI-PCM-L11", 0x481e0094, 0x7360e410),
640 PCMCIA_DEVICE_PROD_ID12("MELCO", "WLI-PCM-L11G", 0x481e0094, 0xf57ca4b3), 641 PCMCIA_DEVICE_PROD_ID12("MELCO", "WLI-PCM-L11G", 0x481e0094, 0xf57ca4b3),
641 PCMCIA_DEVICE_PROD_ID12("Microsoft", "Wireless Notebook Adapter MN-520", 0x5961bf85, 0x6eec8c01), 642 PCMCIA_DEVICE_PROD_ID12("Microsoft", "Wireless Notebook Adapter MN-520", 0x5961bf85, 0x6eec8c01),
642 PCMCIA_DEVICE_PROD_ID12("NCR", "WaveLAN/IEEE", 0x24358cd4, 0xc562e72a), 643 PCMCIA_DEVICE_PROD_ID12("NCR", "WaveLAN/IEEE", 0x24358cd4, 0xc562e72a),
644 PCMCIA_DEVICE_PROD_ID12("NETGEAR MA401 Wireless PC", "Card", 0xa37434e9, 0x9762e8f1),
643 PCMCIA_DEVICE_PROD_ID12("NETGEAR MA401RA Wireless PC", "Card", 0x0306467f, 0x9762e8f1), 645 PCMCIA_DEVICE_PROD_ID12("NETGEAR MA401RA Wireless PC", "Card", 0x0306467f, 0x9762e8f1),
646 PCMCIA_DEVICE_PROD_ID12("Nortel Networks", "emobility 802.11 Wireless LAN PC Card", 0x2d617ea0, 0x88cd5767),
647 PCMCIA_DEVICE_PROD_ID12("OEM", "PRISM2 IEEE 802.11 PC-Card", 0xfea54c90, 0x48f2bdd6),
648 PCMCIA_DEVICE_PROD_ID12("OTC", "Wireless AirEZY 2411-PCC WLAN Card", 0x4ac44287, 0x235a6bed),
649 PCMCIA_DEVICE_PROD_ID123("PCMCIA", "11M WLAN Card v2.5", "ISL37300P", 0x281f1c5d, 0x6e440487, 0xc9049a39),
644 PCMCIA_DEVICE_PROD_ID12("PLANEX", "GeoWave/GW-CF110", 0x209f40ab, 0xd9715264), 650 PCMCIA_DEVICE_PROD_ID12("PLANEX", "GeoWave/GW-CF110", 0x209f40ab, 0xd9715264),
651 PCMCIA_DEVICE_PROD_ID12("PLANEX", "GeoWave/GW-NS110", 0x209f40ab, 0x46263178),
645 PCMCIA_DEVICE_PROD_ID12("PROXIM", "LAN PC CARD HARMONY 80211B", 0xc6536a5e, 0x090c3cd9), 652 PCMCIA_DEVICE_PROD_ID12("PROXIM", "LAN PC CARD HARMONY 80211B", 0xc6536a5e, 0x090c3cd9),
646 PCMCIA_DEVICE_PROD_ID12("PROXIM", "LAN PCI CARD HARMONY 80211B", 0xc6536a5e, 0x9f494e26), 653 PCMCIA_DEVICE_PROD_ID12("PROXIM", "LAN PCI CARD HARMONY 80211B", 0xc6536a5e, 0x9f494e26),
647 PCMCIA_DEVICE_PROD_ID12("SAMSUNG", "11Mbps WLAN Card", 0x43d74cb4, 0x579bd91b), 654 PCMCIA_DEVICE_PROD_ID12("SAMSUNG", "11Mbps WLAN Card", 0x43d74cb4, 0x579bd91b),
648 PCMCIA_DEVICE_PROD_ID1("Symbol Technologies", 0x3f02b4d6), 655 PCMCIA_DEVICE_PROD_ID12("SMC", "SMC2632W", 0xc4f8b18b, 0x474a1f2a),
656 PCMCIA_DEVICE_PROD_ID12("Symbol Technologies", "LA4111 Spectrum24 Wireless LAN PC Card", 0x3f02b4d6, 0x3663cb0e),
657 PCMCIA_DEVICE_PROD_ID123("The Linksys Group, Inc.", "Instant Wireless Network PC Card", "ISL37300P", 0xa5f472c2, 0x590eb502, 0xc9049a39),
658 PCMCIA_DEVICE_PROD_ID12("ZoomAir 11Mbps High", "Rate wireless Networking", 0x273fe3db, 0x32a1eaee),
649 PCMCIA_DEVICE_NULL, 659 PCMCIA_DEVICE_NULL,
650}; 660};
651MODULE_DEVICE_TABLE(pcmcia, orinoco_cs_ids); 661MODULE_DEVICE_TABLE(pcmcia, orinoco_cs_ids);
@@ -656,8 +666,8 @@ static struct pcmcia_driver orinoco_driver = {
656 .name = DRIVER_NAME, 666 .name = DRIVER_NAME,
657 }, 667 },
658 .attach = orinoco_cs_attach, 668 .attach = orinoco_cs_attach,
659 .event = orinoco_cs_event,
660 .detach = orinoco_cs_detach, 669 .detach = orinoco_cs_detach,
670 .event = orinoco_cs_event,
661 .id_table = orinoco_cs_ids, 671 .id_table = orinoco_cs_ids,
662}; 672};
663 673
diff --git a/drivers/net/wireless/orinoco_nortel.c b/drivers/net/wireless/orinoco_nortel.c
index 86fa58e5cfac..d8afd51ff8a5 100644
--- a/drivers/net/wireless/orinoco_nortel.c
+++ b/drivers/net/wireless/orinoco_nortel.c
@@ -40,29 +40,13 @@
40#define PFX DRIVER_NAME ": " 40#define PFX DRIVER_NAME ": "
41 41
42#include <linux/config.h> 42#include <linux/config.h>
43
44#include <linux/module.h> 43#include <linux/module.h>
45#include <linux/kernel.h> 44#include <linux/kernel.h>
46#include <linux/init.h> 45#include <linux/init.h>
47#include <linux/sched.h> 46#include <linux/delay.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> 47#include <linux/pci.h>
61#include <linux/fcntl.h>
62
63#include <pcmcia/cisreg.h> 48#include <pcmcia/cisreg.h>
64 49
65#include "hermes.h"
66#include "orinoco.h" 50#include "orinoco.h"
67 51
68#define COR_OFFSET (0xe0) /* COR attribute offset of Prism2 PC card */ 52#define COR_OFFSET (0xe0) /* COR attribute offset of Prism2 PC card */
@@ -108,7 +92,7 @@ static int nortel_pci_cor_reset(struct orinoco_private *priv)
108 return 0; 92 return 0;
109} 93}
110 94
111int nortel_pci_hw_init(struct nortel_pci_card *card) 95static int nortel_pci_hw_init(struct nortel_pci_card *card)
112{ 96{
113 int i; 97 int i;
114 u32 reg; 98 u32 reg;
diff --git a/drivers/net/wireless/orinoco_pci.c b/drivers/net/wireless/orinoco_pci.c
index 42e03438291b..5362c214fc8e 100644
--- a/drivers/net/wireless/orinoco_pci.c
+++ b/drivers/net/wireless/orinoco_pci.c
@@ -93,28 +93,12 @@
93#define PFX DRIVER_NAME ": " 93#define PFX DRIVER_NAME ": "
94 94
95#include <linux/config.h> 95#include <linux/config.h>
96
97#include <linux/module.h> 96#include <linux/module.h>
98#include <linux/kernel.h> 97#include <linux/kernel.h>
99#include <linux/init.h> 98#include <linux/init.h>
100#include <linux/sched.h> 99#include <linux/delay.h>
101#include <linux/ptrace.h>
102#include <linux/slab.h>
103#include <linux/string.h>
104#include <linux/timer.h>
105#include <linux/ioport.h>
106#include <linux/netdevice.h>
107#include <linux/if_arp.h>
108#include <linux/etherdevice.h>
109#include <linux/list.h>
110#include <linux/pci.h> 100#include <linux/pci.h>
111#include <linux/fcntl.h>
112
113#include <asm/uaccess.h>
114#include <asm/io.h>
115#include <asm/system.h>
116 101
117#include "hermes.h"
118#include "orinoco.h" 102#include "orinoco.h"
119 103
120/* All the magic there is from wlan-ng */ 104/* All the magic there is from wlan-ng */
diff --git a/drivers/net/wireless/orinoco_plx.c b/drivers/net/wireless/orinoco_plx.c
index 7ab05b89fb3f..210e73776545 100644
--- a/drivers/net/wireless/orinoco_plx.c
+++ b/drivers/net/wireless/orinoco_plx.c
@@ -117,29 +117,13 @@
117#define PFX DRIVER_NAME ": " 117#define PFX DRIVER_NAME ": "
118 118
119#include <linux/config.h> 119#include <linux/config.h>
120
121#include <linux/module.h> 120#include <linux/module.h>
122#include <linux/kernel.h> 121#include <linux/kernel.h>
123#include <linux/init.h> 122#include <linux/init.h>
124#include <linux/sched.h> 123#include <linux/delay.h>
125#include <linux/ptrace.h>
126#include <linux/slab.h>
127#include <linux/string.h>
128#include <linux/timer.h>
129#include <linux/ioport.h>
130#include <asm/uaccess.h>
131#include <asm/io.h>
132#include <asm/system.h>
133#include <linux/netdevice.h>
134#include <linux/if_arp.h>
135#include <linux/etherdevice.h>
136#include <linux/list.h>
137#include <linux/pci.h> 124#include <linux/pci.h>
138#include <linux/fcntl.h>
139
140#include <pcmcia/cisreg.h> 125#include <pcmcia/cisreg.h>
141 126
142#include "hermes.h"
143#include "orinoco.h" 127#include "orinoco.h"
144 128
145#define COR_OFFSET (0x3e0) /* COR attribute offset of Prism2 PC card */ 129#define COR_OFFSET (0x3e0) /* COR attribute offset of Prism2 PC card */
diff --git a/drivers/net/wireless/orinoco_tmd.c b/drivers/net/wireless/orinoco_tmd.c
index 85893f42445b..5e68b7026186 100644
--- a/drivers/net/wireless/orinoco_tmd.c
+++ b/drivers/net/wireless/orinoco_tmd.c
@@ -53,29 +53,13 @@
53#define PFX DRIVER_NAME ": " 53#define PFX DRIVER_NAME ": "
54 54
55#include <linux/config.h> 55#include <linux/config.h>
56
57#include <linux/module.h> 56#include <linux/module.h>
58#include <linux/kernel.h> 57#include <linux/kernel.h>
59#include <linux/init.h> 58#include <linux/init.h>
60#include <linux/sched.h> 59#include <linux/delay.h>
61#include <linux/ptrace.h>
62#include <linux/slab.h>
63#include <linux/string.h>
64#include <linux/timer.h>
65#include <linux/ioport.h>
66#include <asm/uaccess.h>
67#include <asm/io.h>
68#include <asm/system.h>
69#include <linux/netdevice.h>
70#include <linux/if_arp.h>
71#include <linux/etherdevice.h>
72#include <linux/list.h>
73#include <linux/pci.h> 60#include <linux/pci.h>
74#include <linux/fcntl.h>
75
76#include <pcmcia/cisreg.h> 61#include <pcmcia/cisreg.h>
77 62
78#include "hermes.h"
79#include "orinoco.h" 63#include "orinoco.h"
80 64
81#define COR_VALUE (COR_LEVEL_REQ | COR_FUNC_ENA) /* Enable PC card with interrupt in level trigger */ 65#define COR_VALUE (COR_LEVEL_REQ | COR_FUNC_ENA) /* Enable PC card with interrupt in level trigger */
diff --git a/drivers/net/wireless/prism54/isl_ioctl.c b/drivers/net/wireless/prism54/isl_ioctl.c
index 9a8790e3580c..5c1a1adf1ff8 100644
--- a/drivers/net/wireless/prism54/isl_ioctl.c
+++ b/drivers/net/wireless/prism54/isl_ioctl.c
@@ -462,14 +462,12 @@ prism54_get_range(struct net_device *ndev, struct iw_request_info *info,
462 /* txpower is supported in dBm's */ 462 /* txpower is supported in dBm's */
463 range->txpower_capa = IW_TXPOW_DBM; 463 range->txpower_capa = IW_TXPOW_DBM;
464 464
465#if WIRELESS_EXT > 16
466 /* Event capability (kernel + driver) */ 465 /* Event capability (kernel + driver) */
467 range->event_capa[0] = (IW_EVENT_CAPA_K_0 | 466 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
468 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) | 467 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
469 IW_EVENT_CAPA_MASK(SIOCGIWAP)); 468 IW_EVENT_CAPA_MASK(SIOCGIWAP));
470 range->event_capa[1] = IW_EVENT_CAPA_K_1; 469 range->event_capa[1] = IW_EVENT_CAPA_K_1;
471 range->event_capa[4] = IW_EVENT_CAPA_MASK(IWEVCUSTOM); 470 range->event_capa[4] = IW_EVENT_CAPA_MASK(IWEVCUSTOM);
472#endif /* WIRELESS_EXT > 16 */
473 471
474 if (islpci_get_state(priv) < PRV_STATE_INIT) 472 if (islpci_get_state(priv) < PRV_STATE_INIT)
475 return 0; 473 return 0;
@@ -693,14 +691,13 @@ prism54_get_scan(struct net_device *ndev, struct iw_request_info *info,
693 extra + dwrq->length, 691 extra + dwrq->length,
694 &(bsslist->bsslist[i]), 692 &(bsslist->bsslist[i]),
695 noise); 693 noise);
696#if WIRELESS_EXT > 16 694
697 /* Check if there is space for one more entry */ 695 /* Check if there is space for one more entry */
698 if((extra + dwrq->length - current_ev) <= IW_EV_ADDR_LEN) { 696 if((extra + dwrq->length - current_ev) <= IW_EV_ADDR_LEN) {
699 /* Ask user space to try again with a bigger buffer */ 697 /* Ask user space to try again with a bigger buffer */
700 rvalue = -E2BIG; 698 rvalue = -E2BIG;
701 break; 699 break;
702 } 700 }
703#endif /* WIRELESS_EXT > 16 */
704 } 701 }
705 702
706 kfree(bsslist); 703 kfree(bsslist);
@@ -2727,12 +2724,7 @@ const struct iw_handler_def prism54_handler_def = {
2727 .standard = (iw_handler *) prism54_handler, 2724 .standard = (iw_handler *) prism54_handler,
2728 .private = (iw_handler *) prism54_private_handler, 2725 .private = (iw_handler *) prism54_private_handler,
2729 .private_args = (struct iw_priv_args *) prism54_private_args, 2726 .private_args = (struct iw_priv_args *) prism54_private_args,
2730#if WIRELESS_EXT > 16
2731 .get_wireless_stats = prism54_get_wireless_stats, 2727 .get_wireless_stats = prism54_get_wireless_stats,
2732#endif /* WIRELESS_EXT > 16 */
2733#if WIRELESS_EXT == 16
2734 .spy_offset = offsetof(islpci_private, spy_data),
2735#endif /* WIRELESS_EXT == 16 */
2736}; 2728};
2737 2729
2738/* For wpa_supplicant */ 2730/* For wpa_supplicant */
diff --git a/drivers/net/wireless/prism54/islpci_dev.c b/drivers/net/wireless/prism54/islpci_dev.c
index 6f13d4a8e2d3..78bdb359835e 100644
--- a/drivers/net/wireless/prism54/islpci_dev.c
+++ b/drivers/net/wireless/prism54/islpci_dev.c
@@ -439,8 +439,7 @@ prism54_bring_down(islpci_private *priv)
439 wmb(); 439 wmb();
440 440
441 /* wait a while for the device to reset */ 441 /* wait a while for the device to reset */
442 set_current_state(TASK_UNINTERRUPTIBLE); 442 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
443 schedule_timeout(50*HZ/1000);
444 443
445 return 0; 444 return 0;
446} 445}
@@ -491,8 +490,7 @@ islpci_reset_if(islpci_private *priv)
491 /* The software reset acknowledge needs about 220 msec here. 490 /* The software reset acknowledge needs about 220 msec here.
492 * Be conservative and wait for up to one second. */ 491 * Be conservative and wait for up to one second. */
493 492
494 set_current_state(TASK_UNINTERRUPTIBLE); 493 remaining = schedule_timeout_uninterruptible(HZ);
495 remaining = schedule_timeout(HZ);
496 494
497 if(remaining > 0) { 495 if(remaining > 0) {
498 result = 0; 496 result = 0;
@@ -756,8 +754,7 @@ islpci_free_memory(islpci_private *priv)
756 pci_unmap_single(priv->pdev, buf->pci_addr, 754 pci_unmap_single(priv->pdev, buf->pci_addr,
757 buf->size, PCI_DMA_FROMDEVICE); 755 buf->size, PCI_DMA_FROMDEVICE);
758 buf->pci_addr = 0; 756 buf->pci_addr = 0;
759 if (buf->mem) 757 kfree(buf->mem);
760 kfree(buf->mem);
761 buf->size = 0; 758 buf->size = 0;
762 buf->mem = NULL; 759 buf->mem = NULL;
763 } 760 }
@@ -839,13 +836,9 @@ islpci_setup(struct pci_dev *pdev)
839 priv->ndev->type = (priv->iw_mode == IW_MODE_MONITOR) ? 836 priv->ndev->type = (priv->iw_mode == IW_MODE_MONITOR) ?
840 priv->monitor_type : ARPHRD_ETHER; 837 priv->monitor_type : ARPHRD_ETHER;
841 838
842#if WIRELESS_EXT > 16
843 /* Add pointers to enable iwspy support. */ 839 /* Add pointers to enable iwspy support. */
844 priv->wireless_data.spy_data = &priv->spy_data; 840 priv->wireless_data.spy_data = &priv->spy_data;
845 ndev->wireless_data = &priv->wireless_data; 841 ndev->wireless_data = &priv->wireless_data;
846#else /* WIRELESS_EXT > 16 */
847 ndev->get_wireless_stats = &prism54_get_wireless_stats;
848#endif /* WIRELESS_EXT > 16 */
849 842
850 /* save the start and end address of the PCI memory area */ 843 /* save the start and end address of the PCI memory area */
851 ndev->mem_start = (unsigned long) priv->device_base; 844 ndev->mem_start = (unsigned long) priv->device_base;
diff --git a/drivers/net/wireless/prism54/islpci_dev.h b/drivers/net/wireless/prism54/islpci_dev.h
index 32a1019f1b36..efbed4397951 100644
--- a/drivers/net/wireless/prism54/islpci_dev.h
+++ b/drivers/net/wireless/prism54/islpci_dev.h
@@ -100,9 +100,7 @@ typedef struct {
100 100
101 struct iw_spy_data spy_data; /* iwspy support */ 101 struct iw_spy_data spy_data; /* iwspy support */
102 102
103#if WIRELESS_EXT > 16
104 struct iw_public_data wireless_data; 103 struct iw_public_data wireless_data;
105#endif /* WIRELESS_EXT > 16 */
106 104
107 int monitor_type; /* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_PRISM */ 105 int monitor_type; /* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_PRISM */
108 106
diff --git a/drivers/net/wireless/prism54/islpci_eth.c b/drivers/net/wireless/prism54/islpci_eth.c
index 5952e9960499..3b49efa37ee5 100644
--- a/drivers/net/wireless/prism54/islpci_eth.c
+++ b/drivers/net/wireless/prism54/islpci_eth.c
@@ -97,12 +97,6 @@ islpci_eth_transmit(struct sk_buff *skb, struct net_device *ndev)
97 /* lock the driver code */ 97 /* lock the driver code */
98 spin_lock_irqsave(&priv->slock, flags); 98 spin_lock_irqsave(&priv->slock, flags);
99 99
100 /* determine the amount of fragments needed to store the frame */
101
102 frame_size = skb->len < ETH_ZLEN ? ETH_ZLEN : skb->len;
103 if (init_wds)
104 frame_size += 6;
105
106 /* check whether the destination queue has enough fragments for the frame */ 100 /* check whether the destination queue has enough fragments for the frame */
107 curr_frag = le32_to_cpu(cb->driver_curr_frag[ISL38XX_CB_TX_DATA_LQ]); 101 curr_frag = le32_to_cpu(cb->driver_curr_frag[ISL38XX_CB_TX_DATA_LQ]);
108 if (unlikely(curr_frag - priv->free_data_tx >= ISL38XX_CB_TX_QSIZE)) { 102 if (unlikely(curr_frag - priv->free_data_tx >= ISL38XX_CB_TX_QSIZE)) {
@@ -213,6 +207,7 @@ islpci_eth_transmit(struct sk_buff *skb, struct net_device *ndev)
213 /* store the skb address for future freeing */ 207 /* store the skb address for future freeing */
214 priv->data_low_tx[index] = skb; 208 priv->data_low_tx[index] = skb;
215 /* set the proper fragment start address and size information */ 209 /* set the proper fragment start address and size information */
210 frame_size = skb->len;
216 fragment->size = cpu_to_le16(frame_size); 211 fragment->size = cpu_to_le16(frame_size);
217 fragment->flags = cpu_to_le16(0); /* set to 1 if more fragments */ 212 fragment->flags = cpu_to_le16(0); /* set to 1 if more fragments */
218 fragment->address = cpu_to_le32(pci_map_address); 213 fragment->address = cpu_to_le32(pci_map_address);
@@ -246,12 +241,10 @@ islpci_eth_transmit(struct sk_buff *skb, struct net_device *ndev)
246 return 0; 241 return 0;
247 242
248 drop_free: 243 drop_free:
249 /* free the skbuf structure before aborting */
250 dev_kfree_skb(skb);
251 skb = NULL;
252
253 priv->statistics.tx_dropped++; 244 priv->statistics.tx_dropped++;
254 spin_unlock_irqrestore(&priv->slock, flags); 245 spin_unlock_irqrestore(&priv->slock, flags);
246 dev_kfree_skb(skb);
247 skb = NULL;
255 return err; 248 return err;
256} 249}
257 250
diff --git a/drivers/net/wireless/prism54/islpci_mgt.c b/drivers/net/wireless/prism54/islpci_mgt.c
index b6f2e5a223be..6a60c5970cb5 100644
--- a/drivers/net/wireless/prism54/islpci_mgt.c
+++ b/drivers/net/wireless/prism54/islpci_mgt.c
@@ -137,7 +137,7 @@ islpci_mgmt_rx_fill(struct net_device *ndev)
137 PCI_DMA_FROMDEVICE); 137 PCI_DMA_FROMDEVICE);
138 if (!buf->pci_addr) { 138 if (!buf->pci_addr) {
139 printk(KERN_WARNING 139 printk(KERN_WARNING
140 "Failed to make memory DMA'able\n."); 140 "Failed to make memory DMA'able.\n");
141 return -ENOMEM; 141 return -ENOMEM;
142 } 142 }
143 } 143 }
@@ -455,7 +455,7 @@ islpci_mgt_transaction(struct net_device *ndev,
455 struct islpci_mgmtframe **recvframe) 455 struct islpci_mgmtframe **recvframe)
456{ 456{
457 islpci_private *priv = netdev_priv(ndev); 457 islpci_private *priv = netdev_priv(ndev);
458 const long wait_cycle_jiffies = (ISL38XX_WAIT_CYCLE * 10 * HZ) / 1000; 458 const long wait_cycle_jiffies = msecs_to_jiffies(ISL38XX_WAIT_CYCLE * 10);
459 long timeout_left = ISL38XX_MAX_WAIT_CYCLES * wait_cycle_jiffies; 459 long timeout_left = ISL38XX_MAX_WAIT_CYCLES * wait_cycle_jiffies;
460 int err; 460 int err;
461 DEFINE_WAIT(wait); 461 DEFINE_WAIT(wait);
@@ -475,8 +475,7 @@ islpci_mgt_transaction(struct net_device *ndev,
475 int timeleft; 475 int timeleft;
476 struct islpci_mgmtframe *frame; 476 struct islpci_mgmtframe *frame;
477 477
478 set_current_state(TASK_UNINTERRUPTIBLE); 478 timeleft = schedule_timeout_uninterruptible(wait_cycle_jiffies);
479 timeleft = schedule_timeout(wait_cycle_jiffies);
480 frame = xchg(&priv->mgmt_received, NULL); 479 frame = xchg(&priv->mgmt_received, NULL);
481 if (frame) { 480 if (frame) {
482 if (frame->header->oid == oid) { 481 if (frame->header->oid == oid) {
diff --git a/drivers/net/wireless/prism54/oid_mgt.c b/drivers/net/wireless/prism54/oid_mgt.c
index 12123e24b113..eea2f04c8c6d 100644
--- a/drivers/net/wireless/prism54/oid_mgt.c
+++ b/drivers/net/wireless/prism54/oid_mgt.c
@@ -268,11 +268,10 @@ mgt_clean(islpci_private *priv)
268 268
269 if (!priv->mib) 269 if (!priv->mib)
270 return; 270 return;
271 for (i = 0; i < OID_NUM_LAST; i++) 271 for (i = 0; i < OID_NUM_LAST; i++) {
272 if (priv->mib[i]) { 272 kfree(priv->mib[i]);
273 kfree(priv->mib[i]); 273 priv->mib[i] = NULL;
274 priv->mib[i] = NULL; 274 }
275 }
276 kfree(priv->mib); 275 kfree(priv->mib);
277 priv->mib = NULL; 276 priv->mib = NULL;
278} 277}
diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c
index e9c5ea0f5535..70fd6fd8feb9 100644
--- a/drivers/net/wireless/ray_cs.c
+++ b/drivers/net/wireless/ray_cs.c
@@ -1649,28 +1649,28 @@ static iw_stats * ray_get_wireless_stats(struct net_device * dev)
1649 */ 1649 */
1650 1650
1651static const iw_handler ray_handler[] = { 1651static const iw_handler ray_handler[] = {
1652 [SIOCSIWCOMMIT-SIOCIWFIRST] (iw_handler) ray_commit, 1652 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) ray_commit,
1653 [SIOCGIWNAME -SIOCIWFIRST] (iw_handler) ray_get_name, 1653 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) ray_get_name,
1654 [SIOCSIWFREQ -SIOCIWFIRST] (iw_handler) ray_set_freq, 1654 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) ray_set_freq,
1655 [SIOCGIWFREQ -SIOCIWFIRST] (iw_handler) ray_get_freq, 1655 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) ray_get_freq,
1656 [SIOCSIWMODE -SIOCIWFIRST] (iw_handler) ray_set_mode, 1656 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) ray_set_mode,
1657 [SIOCGIWMODE -SIOCIWFIRST] (iw_handler) ray_get_mode, 1657 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) ray_get_mode,
1658 [SIOCGIWRANGE -SIOCIWFIRST] (iw_handler) ray_get_range, 1658 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) ray_get_range,
1659#ifdef WIRELESS_SPY 1659#ifdef WIRELESS_SPY
1660 [SIOCSIWSPY -SIOCIWFIRST] (iw_handler) iw_handler_set_spy, 1660 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
1661 [SIOCGIWSPY -SIOCIWFIRST] (iw_handler) iw_handler_get_spy, 1661 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
1662 [SIOCSIWTHRSPY-SIOCIWFIRST] (iw_handler) iw_handler_set_thrspy, 1662 [SIOCSIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
1663 [SIOCGIWTHRSPY-SIOCIWFIRST] (iw_handler) iw_handler_get_thrspy, 1663 [SIOCGIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
1664#endif /* WIRELESS_SPY */ 1664#endif /* WIRELESS_SPY */
1665 [SIOCGIWAP -SIOCIWFIRST] (iw_handler) ray_get_wap, 1665 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) ray_get_wap,
1666 [SIOCSIWESSID -SIOCIWFIRST] (iw_handler) ray_set_essid, 1666 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) ray_set_essid,
1667 [SIOCGIWESSID -SIOCIWFIRST] (iw_handler) ray_get_essid, 1667 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) ray_get_essid,
1668 [SIOCSIWRATE -SIOCIWFIRST] (iw_handler) ray_set_rate, 1668 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) ray_set_rate,
1669 [SIOCGIWRATE -SIOCIWFIRST] (iw_handler) ray_get_rate, 1669 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) ray_get_rate,
1670 [SIOCSIWRTS -SIOCIWFIRST] (iw_handler) ray_set_rts, 1670 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) ray_set_rts,
1671 [SIOCGIWRTS -SIOCIWFIRST] (iw_handler) ray_get_rts, 1671 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) ray_get_rts,
1672 [SIOCSIWFRAG -SIOCIWFIRST] (iw_handler) ray_set_frag, 1672 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) ray_set_frag,
1673 [SIOCGIWFRAG -SIOCIWFIRST] (iw_handler) ray_get_frag, 1673 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) ray_get_frag,
1674}; 1674};
1675 1675
1676#define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */ 1676#define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */
@@ -1678,9 +1678,9 @@ static const iw_handler ray_handler[] = {
1678#define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */ 1678#define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */
1679 1679
1680static const iw_handler ray_private_handler[] = { 1680static const iw_handler ray_private_handler[] = {
1681 [0] (iw_handler) ray_set_framing, 1681 [0] = (iw_handler) ray_set_framing,
1682 [1] (iw_handler) ray_get_framing, 1682 [1] = (iw_handler) ray_get_framing,
1683 [3] (iw_handler) ray_get_country, 1683 [3] = (iw_handler) ray_get_country,
1684}; 1684};
1685 1685
1686static const struct iw_priv_args ray_private_args[] = { 1686static const struct iw_priv_args ray_private_args[] = {
diff --git a/drivers/net/wireless/spectrum_cs.c b/drivers/net/wireless/spectrum_cs.c
index 39c6cdf7f3f7..b1bbc8e8e91f 100644
--- a/drivers/net/wireless/spectrum_cs.c
+++ b/drivers/net/wireless/spectrum_cs.c
@@ -22,58 +22,23 @@
22#define PFX DRIVER_NAME ": " 22#define PFX DRIVER_NAME ": "
23 23
24#include <linux/config.h> 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> 25#include <linux/module.h>
30#include <linux/kernel.h> 26#include <linux/kernel.h>
31#include <linux/init.h> 27#include <linux/init.h>
32#include <linux/sched.h> 28#include <linux/delay.h>
33#include <linux/ptrace.h> 29#include <linux/firmware.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> 30#include <pcmcia/cs_types.h>
43#include <pcmcia/cs.h> 31#include <pcmcia/cs.h>
44#include <pcmcia/cistpl.h> 32#include <pcmcia/cistpl.h>
45#include <pcmcia/cisreg.h> 33#include <pcmcia/cisreg.h>
46#include <pcmcia/ds.h> 34#include <pcmcia/ds.h>
47 35
48#include <asm/uaccess.h>
49#include <asm/io.h>
50#include <asm/system.h>
51
52#include "orinoco.h" 36#include "orinoco.h"
53 37
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; 38static unsigned char *primsym;
73static unsigned char *secsym; 39static unsigned char *secsym;
74static const char primary_fw_name[] = "symbol_sp24t_prim_fw"; 40static const char primary_fw_name[] = "symbol_sp24t_prim_fw";
75static const char secondary_fw_name[] = "symbol_sp24t_sec_fw"; 41static const char secondary_fw_name[] = "symbol_sp24t_sec_fw";
76#endif /* !SPECTRUM_FW_INCLUDED */
77 42
78/********************************************************************/ 43/********************************************************************/
79/* Module stuff */ 44/* Module stuff */
@@ -124,17 +89,8 @@ static dev_link_t *dev_list; /* = NULL */
124/* Function prototypes */ 89/* Function prototypes */
125/********************************************************************/ 90/********************************************************************/
126 91
127/* device methods */ 92static void spectrum_cs_release(dev_link_t *link);
128static int spectrum_cs_hard_reset(struct orinoco_private *priv); 93static void spectrum_cs_detach(dev_link_t *link);
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 94
139/********************************************************************/ 95/********************************************************************/
140/* Firmware downloader */ 96/* Firmware downloader */
@@ -182,8 +138,8 @@ static void spectrum_cs_detach(dev_link_t *);
182 * Each block has the following structure. 138 * Each block has the following structure.
183 */ 139 */
184struct dblock { 140struct dblock {
185 u32 _addr; /* adapter address where to write the block */ 141 __le32 _addr; /* adapter address where to write the block */
186 u16 _len; /* length of the data only, in bytes */ 142 __le16 _len; /* length of the data only, in bytes */
187 char data[0]; /* data to be written */ 143 char data[0]; /* data to be written */
188} __attribute__ ((packed)); 144} __attribute__ ((packed));
189 145
@@ -193,9 +149,9 @@ struct dblock {
193 * items with matching ID should be written. 149 * items with matching ID should be written.
194 */ 150 */
195struct pdr { 151struct pdr {
196 u32 _id; /* record ID */ 152 __le32 _id; /* record ID */
197 u32 _addr; /* adapter address where to write the data */ 153 __le32 _addr; /* adapter address where to write the data */
198 u32 _len; /* expected length of the data, in bytes */ 154 __le32 _len; /* expected length of the data, in bytes */
199 char next[0]; /* next PDR starts here */ 155 char next[0]; /* next PDR starts here */
200} __attribute__ ((packed)); 156} __attribute__ ((packed));
201 157
@@ -206,8 +162,8 @@ struct pdr {
206 * be plugged into the secondary firmware. 162 * be plugged into the secondary firmware.
207 */ 163 */
208struct pdi { 164struct pdi {
209 u16 _len; /* length of ID and data, in words */ 165 __le16 _len; /* length of ID and data, in words */
210 u16 _id; /* record ID */ 166 __le16 _id; /* record ID */
211 char data[0]; /* plug data */ 167 char data[0]; /* plug data */
212} __attribute__ ((packed));; 168} __attribute__ ((packed));;
213 169
@@ -414,7 +370,7 @@ spectrum_plug_pdi(hermes_t *hw, struct pdr *first_pdr, struct pdi *pdi)
414 370
415/* Read PDA from the adapter */ 371/* Read PDA from the adapter */
416static int 372static int
417spectrum_read_pda(hermes_t *hw, u16 *pda, int pda_len) 373spectrum_read_pda(hermes_t *hw, __le16 *pda, int pda_len)
418{ 374{
419 int ret; 375 int ret;
420 int pda_size; 376 int pda_size;
@@ -445,7 +401,7 @@ spectrum_read_pda(hermes_t *hw, u16 *pda, int pda_len)
445/* Parse PDA and write the records into the adapter */ 401/* Parse PDA and write the records into the adapter */
446static int 402static int
447spectrum_apply_pda(hermes_t *hw, const struct dblock *first_block, 403spectrum_apply_pda(hermes_t *hw, const struct dblock *first_block,
448 u16 *pda) 404 __le16 *pda)
449{ 405{
450 int ret; 406 int ret;
451 struct pdi *pdi; 407 struct pdi *pdi;
@@ -511,7 +467,7 @@ spectrum_dl_image(hermes_t *hw, dev_link_t *link,
511 const struct dblock *first_block; 467 const struct dblock *first_block;
512 468
513 /* Plug Data Area (PDA) */ 469 /* Plug Data Area (PDA) */
514 u16 pda[PDA_WORDS]; 470 __le16 pda[PDA_WORDS];
515 471
516 /* Binary block begins after the 0x1A marker */ 472 /* Binary block begins after the 0x1A marker */
517 ptr = image; 473 ptr = image;
@@ -571,8 +527,6 @@ spectrum_dl_firmware(hermes_t *hw, dev_link_t *link)
571{ 527{
572 int ret; 528 int ret;
573 client_handle_t handle = link->handle; 529 client_handle_t handle = link->handle;
574
575#ifndef SPECTRUM_FW_INCLUDED
576 const struct firmware *fw_entry; 530 const struct firmware *fw_entry;
577 531
578 if (request_firmware(&fw_entry, primary_fw_name, 532 if (request_firmware(&fw_entry, primary_fw_name,
@@ -592,7 +546,6 @@ spectrum_dl_firmware(hermes_t *hw, dev_link_t *link)
592 secondary_fw_name); 546 secondary_fw_name);
593 return -ENOENT; 547 return -ENOENT;
594 } 548 }
595#endif
596 549
597 /* Load primary firmware */ 550 /* Load primary firmware */
598 ret = spectrum_dl_image(hw, link, primsym); 551 ret = spectrum_dl_image(hw, link, primsym);
@@ -1085,7 +1038,7 @@ static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
1085static struct pcmcia_device_id spectrum_cs_ids[] = { 1038static struct pcmcia_device_id spectrum_cs_ids[] = {
1086 PCMCIA_DEVICE_MANF_CARD(0x026c, 0x0001), /* Symbol Spectrum24 LA4100 */ 1039 PCMCIA_DEVICE_MANF_CARD(0x026c, 0x0001), /* Symbol Spectrum24 LA4100 */
1087 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0001), /* Socket Communications CF */ 1040 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0001), /* Socket Communications CF */
1088 PCMCIA_DEVICE_MANF_CARD(0x0089, 0x0001), /* Intel PRO/Wireless 2011B */ 1041 PCMCIA_DEVICE_PROD_ID12("Intel", "PRO/Wireless LAN PC Card", 0x816cc815, 0x6fbf459a), /* 2011B, not 2011 */
1089 PCMCIA_DEVICE_NULL, 1042 PCMCIA_DEVICE_NULL,
1090}; 1043};
1091MODULE_DEVICE_TABLE(pcmcia, spectrum_cs_ids); 1044MODULE_DEVICE_TABLE(pcmcia, spectrum_cs_ids);
@@ -1096,8 +1049,8 @@ static struct pcmcia_driver orinoco_driver = {
1096 .name = DRIVER_NAME, 1049 .name = DRIVER_NAME,
1097 }, 1050 },
1098 .attach = spectrum_cs_attach, 1051 .attach = spectrum_cs_attach,
1099 .event = spectrum_cs_event,
1100 .detach = spectrum_cs_detach, 1052 .detach = spectrum_cs_detach,
1053 .event = spectrum_cs_event,
1101 .id_table = spectrum_cs_ids, 1054 .id_table = spectrum_cs_ids,
1102}; 1055};
1103 1056
diff --git a/drivers/net/wireless/strip.c b/drivers/net/wireless/strip.c
index 7bc7fc823128..d25264ba0c0e 100644
--- a/drivers/net/wireless/strip.c
+++ b/drivers/net/wireless/strip.c
@@ -860,12 +860,9 @@ static int allocate_buffers(struct strip *strip_info, int mtu)
860 strip_info->mtu = dev->mtu = mtu; 860 strip_info->mtu = dev->mtu = mtu;
861 return (1); 861 return (1);
862 } 862 }
863 if (r) 863 kfree(r);
864 kfree(r); 864 kfree(s);
865 if (s) 865 kfree(t);
866 kfree(s);
867 if (t)
868 kfree(t);
869 return (0); 866 return (0);
870} 867}
871 868
@@ -922,13 +919,9 @@ static int strip_change_mtu(struct net_device *dev, int new_mtu)
922 printk(KERN_NOTICE "%s: strip MTU changed fom %d to %d.\n", 919 printk(KERN_NOTICE "%s: strip MTU changed fom %d to %d.\n",
923 strip_info->dev->name, old_mtu, strip_info->mtu); 920 strip_info->dev->name, old_mtu, strip_info->mtu);
924 921
925 if (orbuff) 922 kfree(orbuff);
926 kfree(orbuff); 923 kfree(osbuff);
927 if (osbuff) 924 kfree(otbuff);
928 kfree(osbuff);
929 if (otbuff)
930 kfree(otbuff);
931
932 return 0; 925 return 0;
933} 926}
934 927
@@ -2498,18 +2491,13 @@ static int strip_close_low(struct net_device *dev)
2498 /* 2491 /*
2499 * Free all STRIP frame buffers. 2492 * Free all STRIP frame buffers.
2500 */ 2493 */
2501 if (strip_info->rx_buff) { 2494 kfree(strip_info->rx_buff);
2502 kfree(strip_info->rx_buff); 2495 strip_info->rx_buff = NULL;
2503 strip_info->rx_buff = NULL; 2496 kfree(strip_info->sx_buff);
2504 } 2497 strip_info->sx_buff = NULL;
2505 if (strip_info->sx_buff) { 2498 kfree(strip_info->tx_buff);
2506 kfree(strip_info->sx_buff); 2499 strip_info->tx_buff = NULL;
2507 strip_info->sx_buff = NULL; 2500
2508 }
2509 if (strip_info->tx_buff) {
2510 kfree(strip_info->tx_buff);
2511 strip_info->tx_buff = NULL;
2512 }
2513 del_timer(&strip_info->idle_timer); 2501 del_timer(&strip_info->idle_timer);
2514 return 0; 2502 return 0;
2515} 2503}
diff --git a/drivers/net/wireless/wavelan.c b/drivers/net/wireless/wavelan.c
index 7a5e20a17890..b0d8b5b03152 100644
--- a/drivers/net/wireless/wavelan.c
+++ b/drivers/net/wireless/wavelan.c
@@ -430,7 +430,6 @@ static void fee_read(unsigned long ioaddr, /* I/O port of the card */
430 } 430 }
431} 431}
432 432
433#ifdef WIRELESS_EXT /* if the wireless extension exists in the kernel */
434 433
435/*------------------------------------------------------------------*/ 434/*------------------------------------------------------------------*/
436/* 435/*
@@ -514,7 +513,6 @@ static void fee_write(unsigned long ioaddr, /* I/O port of the card */
514 fee_wait(ioaddr, 10, 100); 513 fee_wait(ioaddr, 10, 100);
515#endif /* EEPROM_IS_PROTECTED */ 514#endif /* EEPROM_IS_PROTECTED */
516} 515}
517#endif /* WIRELESS_EXT */
518 516
519/************************ I82586 SUBROUTINES *************************/ 517/************************ I82586 SUBROUTINES *************************/
520/* 518/*
@@ -973,11 +971,9 @@ static void wv_mmc_show(struct net_device * dev)
973 mmc_read(ioaddr, 0, (u8 *) & m, sizeof(m)); 971 mmc_read(ioaddr, 0, (u8 *) & m, sizeof(m));
974 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0); 972 mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
975 973
976#ifdef WIRELESS_EXT /* if wireless extension exists in the kernel */
977 /* Don't forget to update statistics */ 974 /* Don't forget to update statistics */
978 lp->wstats.discard.nwid += 975 lp->wstats.discard.nwid +=
979 (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l; 976 (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
980#endif /* WIRELESS_EXT */
981 977
982 printk(KERN_DEBUG "##### WaveLAN modem status registers: #####\n"); 978 printk(KERN_DEBUG "##### WaveLAN modem status registers: #####\n");
983#ifdef DEBUG_SHOW_UNUSED 979#ifdef DEBUG_SHOW_UNUSED
@@ -1499,7 +1495,6 @@ static int wavelan_set_mac_address(struct net_device * dev, void *addr)
1499} 1495}
1500#endif /* SET_MAC_ADDRESS */ 1496#endif /* SET_MAC_ADDRESS */
1501 1497
1502#ifdef WIRELESS_EXT /* if wireless extensions exist in the kernel */
1503 1498
1504/*------------------------------------------------------------------*/ 1499/*------------------------------------------------------------------*/
1505/* 1500/*
@@ -2473,7 +2468,6 @@ static iw_stats *wavelan_get_wireless_stats(struct net_device * dev)
2473#endif 2468#endif
2474 return &lp->wstats; 2469 return &lp->wstats;
2475} 2470}
2476#endif /* WIRELESS_EXT */
2477 2471
2478/************************* PACKET RECEPTION *************************/ 2472/************************* PACKET RECEPTION *************************/
2479/* 2473/*
@@ -4194,11 +4188,9 @@ static int __init wavelan_config(struct net_device *dev, unsigned short ioaddr)
4194 dev->set_mac_address = &wavelan_set_mac_address; 4188 dev->set_mac_address = &wavelan_set_mac_address;
4195#endif /* SET_MAC_ADDRESS */ 4189#endif /* SET_MAC_ADDRESS */
4196 4190
4197#ifdef WIRELESS_EXT /* if wireless extension exists in the kernel */
4198 dev->wireless_handlers = &wavelan_handler_def; 4191 dev->wireless_handlers = &wavelan_handler_def;
4199 lp->wireless_data.spy_data = &lp->spy_data; 4192 lp->wireless_data.spy_data = &lp->spy_data;
4200 dev->wireless_data = &lp->wireless_data; 4193 dev->wireless_data = &lp->wireless_data;
4201#endif
4202 4194
4203 dev->mtu = WAVELAN_MTU; 4195 dev->mtu = WAVELAN_MTU;
4204 4196
diff --git a/drivers/net/wireless/wavelan.p.h b/drivers/net/wireless/wavelan.p.h
index 509ff22a6caa..166e28b9a4f7 100644
--- a/drivers/net/wireless/wavelan.p.h
+++ b/drivers/net/wireless/wavelan.p.h
@@ -409,11 +409,9 @@
409#define MULTICAST_AVOID /* Avoid extra multicast (I'm sceptical). */ 409#define MULTICAST_AVOID /* Avoid extra multicast (I'm sceptical). */
410#undef SET_MAC_ADDRESS /* Experimental */ 410#undef SET_MAC_ADDRESS /* Experimental */
411 411
412#ifdef WIRELESS_EXT /* If wireless extensions exist in the kernel */
413/* Warning: this stuff will slow down the driver. */ 412/* Warning: this stuff will slow down the driver. */
414#define WIRELESS_SPY /* Enable spying addresses. */ 413#define WIRELESS_SPY /* Enable spying addresses. */
415#undef HISTOGRAM /* Enable histogram of signal level. */ 414#undef HISTOGRAM /* Enable histogram of signal level. */
416#endif
417 415
418/****************************** DEBUG ******************************/ 416/****************************** DEBUG ******************************/
419 417
@@ -506,12 +504,10 @@ struct net_local
506 u_short tx_first_free; 504 u_short tx_first_free;
507 u_short tx_first_in_use; 505 u_short tx_first_in_use;
508 506
509#ifdef WIRELESS_EXT
510 iw_stats wstats; /* Wireless-specific statistics */ 507 iw_stats wstats; /* Wireless-specific statistics */
511 508
512 struct iw_spy_data spy_data; 509 struct iw_spy_data spy_data;
513 struct iw_public_data wireless_data; 510 struct iw_public_data wireless_data;
514#endif
515 511
516#ifdef HISTOGRAM 512#ifdef HISTOGRAM
517 int his_number; /* number of intervals */ 513 int his_number; /* number of intervals */
diff --git a/drivers/net/wireless/wavelan_cs.c b/drivers/net/wireless/wavelan_cs.c
index 183c4732ef65..4b3c98f5c564 100644
--- a/drivers/net/wireless/wavelan_cs.c
+++ b/drivers/net/wireless/wavelan_cs.c
@@ -415,7 +415,6 @@ fee_read(u_long base, /* i/o port of the card */
415 } 415 }
416} 416}
417 417
418#ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */
419 418
420/*------------------------------------------------------------------*/ 419/*------------------------------------------------------------------*/
421/* 420/*
@@ -500,7 +499,6 @@ fee_write(u_long base, /* i/o port of the card */
500 fee_wait(base, 10, 100); 499 fee_wait(base, 10, 100);
501#endif /* EEPROM_IS_PROTECTED */ 500#endif /* EEPROM_IS_PROTECTED */
502} 501}
503#endif /* WIRELESS_EXT */
504 502
505/******************* WaveLAN Roaming routines... ********************/ 503/******************* WaveLAN Roaming routines... ********************/
506 504
@@ -1161,10 +1159,8 @@ wv_mmc_show(struct net_device * dev)
1161 mmc_read(base, 0, (u_char *)&m, sizeof(m)); 1159 mmc_read(base, 0, (u_char *)&m, sizeof(m));
1162 mmc_out(base, mmwoff(0, mmw_freeze), 0); 1160 mmc_out(base, mmwoff(0, mmw_freeze), 0);
1163 1161
1164#ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */
1165 /* Don't forget to update statistics */ 1162 /* Don't forget to update statistics */
1166 lp->wstats.discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l; 1163 lp->wstats.discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
1167#endif /* WIRELESS_EXT */
1168 1164
1169 spin_unlock_irqrestore(&lp->spinlock, flags); 1165 spin_unlock_irqrestore(&lp->spinlock, flags);
1170 1166
@@ -1550,7 +1546,6 @@ wavelan_set_mac_address(struct net_device * dev,
1550} 1546}
1551#endif /* SET_MAC_ADDRESS */ 1547#endif /* SET_MAC_ADDRESS */
1552 1548
1553#ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */
1554 1549
1555/*------------------------------------------------------------------*/ 1550/*------------------------------------------------------------------*/
1556/* 1551/*
@@ -2793,7 +2788,6 @@ wavelan_get_wireless_stats(struct net_device * dev)
2793#endif 2788#endif
2794 return &lp->wstats; 2789 return &lp->wstats;
2795} 2790}
2796#endif /* WIRELESS_EXT */
2797 2791
2798/************************* PACKET RECEPTION *************************/ 2792/************************* PACKET RECEPTION *************************/
2799/* 2793/*
@@ -4679,11 +4673,9 @@ wavelan_attach(void)
4679 dev->watchdog_timeo = WATCHDOG_JIFFIES; 4673 dev->watchdog_timeo = WATCHDOG_JIFFIES;
4680 SET_ETHTOOL_OPS(dev, &ops); 4674 SET_ETHTOOL_OPS(dev, &ops);
4681 4675
4682#ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */
4683 dev->wireless_handlers = &wavelan_handler_def; 4676 dev->wireless_handlers = &wavelan_handler_def;
4684 lp->wireless_data.spy_data = &lp->spy_data; 4677 lp->wireless_data.spy_data = &lp->spy_data;
4685 dev->wireless_data = &lp->wireless_data; 4678 dev->wireless_data = &lp->wireless_data;
4686#endif
4687 4679
4688 /* Other specific data */ 4680 /* Other specific data */
4689 dev->mtu = WAVELAN_MTU; 4681 dev->mtu = WAVELAN_MTU;
diff --git a/drivers/net/wireless/wavelan_cs.p.h b/drivers/net/wireless/wavelan_cs.p.h
index 01d882be8790..724a715089c9 100644
--- a/drivers/net/wireless/wavelan_cs.p.h
+++ b/drivers/net/wireless/wavelan_cs.p.h
@@ -472,11 +472,9 @@
472#define MULTICAST_AVOID /* Avoid extra multicast (I'm sceptical) */ 472#define MULTICAST_AVOID /* Avoid extra multicast (I'm sceptical) */
473#undef SET_MAC_ADDRESS /* Experimental */ 473#undef SET_MAC_ADDRESS /* Experimental */
474 474
475#ifdef WIRELESS_EXT /* If wireless extension exist in the kernel */
476/* Warning : these stuff will slow down the driver... */ 475/* Warning : these stuff will slow down the driver... */
477#define WIRELESS_SPY /* Enable spying addresses */ 476#define WIRELESS_SPY /* Enable spying addresses */
478#undef HISTOGRAM /* Enable histogram of sig level... */ 477#undef HISTOGRAM /* Enable histogram of sig level... */
479#endif
480 478
481/****************************** DEBUG ******************************/ 479/****************************** DEBUG ******************************/
482 480
@@ -624,12 +622,10 @@ struct net_local
624 int rfp; /* Last DMA machine receive pointer */ 622 int rfp; /* Last DMA machine receive pointer */
625 int overrunning; /* Receiver overrun flag */ 623 int overrunning; /* Receiver overrun flag */
626 624
627#ifdef WIRELESS_EXT
628 iw_stats wstats; /* Wireless specific stats */ 625 iw_stats wstats; /* Wireless specific stats */
629 626
630 struct iw_spy_data spy_data; 627 struct iw_spy_data spy_data;
631 struct iw_public_data wireless_data; 628 struct iw_public_data wireless_data;
632#endif
633 629
634#ifdef HISTOGRAM 630#ifdef HISTOGRAM
635 int his_number; /* Number of intervals */ 631 int his_number; /* Number of intervals */
diff --git a/drivers/net/wireless/wl3501.h b/drivers/net/wireless/wl3501.h
index 7fcbe589c3f2..4303c50c2ab6 100644
--- a/drivers/net/wireless/wl3501.h
+++ b/drivers/net/wireless/wl3501.h
@@ -548,7 +548,7 @@ struct wl3501_80211_tx_plcp_hdr {
548 548
549struct wl3501_80211_tx_hdr { 549struct wl3501_80211_tx_hdr {
550 struct wl3501_80211_tx_plcp_hdr pclp_hdr; 550 struct wl3501_80211_tx_plcp_hdr pclp_hdr;
551 struct ieee80211_hdr mac_hdr; 551 struct ieee80211_hdr_4addr mac_hdr;
552} __attribute__ ((packed)); 552} __attribute__ ((packed));
553 553
554/* 554/*
diff --git a/drivers/parisc/asp.c b/drivers/parisc/asp.c
index 388609967133..558420bc9f88 100644
--- a/drivers/parisc/asp.c
+++ b/drivers/parisc/asp.c
@@ -77,12 +77,12 @@ asp_init_chip(struct parisc_device *dev)
77 struct gsc_irq gsc_irq; 77 struct gsc_irq gsc_irq;
78 int ret; 78 int ret;
79 79
80 asp.version = gsc_readb(dev->hpa + ASP_VER_OFFSET) & 0xf; 80 asp.version = gsc_readb(dev->hpa.start + ASP_VER_OFFSET) & 0xf;
81 asp.name = (asp.version == 1) ? "Asp" : "Cutoff"; 81 asp.name = (asp.version == 1) ? "Asp" : "Cutoff";
82 asp.hpa = ASP_INTERRUPT_ADDR; 82 asp.hpa = ASP_INTERRUPT_ADDR;
83 83
84 printk(KERN_INFO "%s version %d at 0x%lx found.\n", 84 printk(KERN_INFO "%s version %d at 0x%lx found.\n",
85 asp.name, asp.version, dev->hpa); 85 asp.name, asp.version, dev->hpa.start);
86 86
87 /* the IRQ ASP should use */ 87 /* the IRQ ASP should use */
88 ret = -EBUSY; 88 ret = -EBUSY;
@@ -126,7 +126,7 @@ static struct parisc_device_id asp_tbl[] = {
126}; 126};
127 127
128struct parisc_driver asp_driver = { 128struct parisc_driver asp_driver = {
129 .name = "Asp", 129 .name = "asp",
130 .id_table = asp_tbl, 130 .id_table = asp_tbl,
131 .probe = asp_init_chip, 131 .probe = asp_init_chip,
132}; 132};
diff --git a/drivers/parisc/ccio-dma.c b/drivers/parisc/ccio-dma.c
index 0e98a9d9834c..9e0229f7e25f 100644
--- a/drivers/parisc/ccio-dma.c
+++ b/drivers/parisc/ccio-dma.c
@@ -100,9 +100,9 @@
100#define DBG_RUN_SG(x...) 100#define DBG_RUN_SG(x...)
101#endif 101#endif
102 102
103#define CCIO_INLINE /* inline */ 103#define CCIO_INLINE inline
104#define WRITE_U32(value, addr) gsc_writel(value, (u32 *)(addr)) 104#define WRITE_U32(value, addr) __raw_writel(value, addr)
105#define READ_U32(addr) gsc_readl((u32 *)(addr)) 105#define READ_U32(addr) __raw_readl(addr)
106 106
107#define U2_IOA_RUNWAY 0x580 107#define U2_IOA_RUNWAY 0x580
108#define U2_BC_GSC 0x501 108#define U2_BC_GSC 0x501
@@ -115,28 +115,28 @@
115 115
116struct ioa_registers { 116struct ioa_registers {
117 /* Runway Supervisory Set */ 117 /* Runway Supervisory Set */
118 volatile int32_t unused1[12]; 118 int32_t unused1[12];
119 volatile uint32_t io_command; /* Offset 12 */ 119 uint32_t io_command; /* Offset 12 */
120 volatile uint32_t io_status; /* Offset 13 */ 120 uint32_t io_status; /* Offset 13 */
121 volatile uint32_t io_control; /* Offset 14 */ 121 uint32_t io_control; /* Offset 14 */
122 volatile int32_t unused2[1]; 122 int32_t unused2[1];
123 123
124 /* Runway Auxiliary Register Set */ 124 /* Runway Auxiliary Register Set */
125 volatile uint32_t io_err_resp; /* Offset 0 */ 125 uint32_t io_err_resp; /* Offset 0 */
126 volatile uint32_t io_err_info; /* Offset 1 */ 126 uint32_t io_err_info; /* Offset 1 */
127 volatile uint32_t io_err_req; /* Offset 2 */ 127 uint32_t io_err_req; /* Offset 2 */
128 volatile uint32_t io_err_resp_hi; /* Offset 3 */ 128 uint32_t io_err_resp_hi; /* Offset 3 */
129 volatile uint32_t io_tlb_entry_m; /* Offset 4 */ 129 uint32_t io_tlb_entry_m; /* Offset 4 */
130 volatile uint32_t io_tlb_entry_l; /* Offset 5 */ 130 uint32_t io_tlb_entry_l; /* Offset 5 */
131 volatile uint32_t unused3[1]; 131 uint32_t unused3[1];
132 volatile uint32_t io_pdir_base; /* Offset 7 */ 132 uint32_t io_pdir_base; /* Offset 7 */
133 volatile uint32_t io_io_low_hv; /* Offset 8 */ 133 uint32_t io_io_low_hv; /* Offset 8 */
134 volatile uint32_t io_io_high_hv; /* Offset 9 */ 134 uint32_t io_io_high_hv; /* Offset 9 */
135 volatile uint32_t unused4[1]; 135 uint32_t unused4[1];
136 volatile uint32_t io_chain_id_mask; /* Offset 11 */ 136 uint32_t io_chain_id_mask; /* Offset 11 */
137 volatile uint32_t unused5[2]; 137 uint32_t unused5[2];
138 volatile uint32_t io_io_low; /* Offset 14 */ 138 uint32_t io_io_low; /* Offset 14 */
139 volatile uint32_t io_io_high; /* Offset 15 */ 139 uint32_t io_io_high; /* Offset 15 */
140}; 140};
141 141
142/* 142/*
@@ -226,7 +226,7 @@ struct ioa_registers {
226*/ 226*/
227 227
228struct ioc { 228struct ioc {
229 struct ioa_registers *ioc_hpa; /* I/O MMU base address */ 229 struct ioa_registers __iomem *ioc_regs; /* I/O MMU base address */
230 u8 *res_map; /* resource map, bit == pdir entry */ 230 u8 *res_map; /* resource map, bit == pdir entry */
231 u64 *pdir_base; /* physical base address */ 231 u64 *pdir_base; /* physical base address */
232 u32 pdir_size; /* bytes, function of IOV Space size */ 232 u32 pdir_size; /* bytes, function of IOV Space size */
@@ -595,7 +595,7 @@ ccio_io_pdir_entry(u64 *pdir_ptr, space_t sid, unsigned long vba,
595 ** Grab virtual index [0:11] 595 ** Grab virtual index [0:11]
596 ** Deposit virt_idx bits into I/O PDIR word 596 ** Deposit virt_idx bits into I/O PDIR word
597 */ 597 */
598 asm volatile ("lci 0(%%sr1, %1), %0" : "=r" (ci) : "r" (vba)); 598 asm volatile ("lci %%r0(%%sr1, %1), %0" : "=r" (ci) : "r" (vba));
599 asm volatile ("extru %1,19,12,%0" : "+r" (ci) : "r" (ci)); 599 asm volatile ("extru %1,19,12,%0" : "+r" (ci) : "r" (ci));
600 asm volatile ("depw %1,15,12,%0" : "+r" (pa) : "r" (ci)); 600 asm volatile ("depw %1,15,12,%0" : "+r" (pa) : "r" (ci));
601 601
@@ -613,7 +613,7 @@ ccio_io_pdir_entry(u64 *pdir_ptr, space_t sid, unsigned long vba,
613 ** the real mode coherence index generation of U2, the PDIR entry 613 ** the real mode coherence index generation of U2, the PDIR entry
614 ** must be flushed to memory to retain coherence." 614 ** must be flushed to memory to retain coherence."
615 */ 615 */
616 asm volatile("fdc 0(%0)" : : "r" (pdir_ptr)); 616 asm volatile("fdc %%r0(%0)" : : "r" (pdir_ptr));
617 asm volatile("sync"); 617 asm volatile("sync");
618} 618}
619 619
@@ -636,7 +636,7 @@ ccio_clear_io_tlb(struct ioc *ioc, dma_addr_t iovp, size_t byte_cnt)
636 byte_cnt += chain_size; 636 byte_cnt += chain_size;
637 637
638 while(byte_cnt > chain_size) { 638 while(byte_cnt > chain_size) {
639 WRITE_U32(CMD_TLB_PURGE | iovp, &ioc->ioc_hpa->io_command); 639 WRITE_U32(CMD_TLB_PURGE | iovp, &ioc->ioc_regs->io_command);
640 iovp += chain_size; 640 iovp += chain_size;
641 byte_cnt -= chain_size; 641 byte_cnt -= chain_size;
642 } 642 }
@@ -684,7 +684,7 @@ ccio_mark_invalid(struct ioc *ioc, dma_addr_t iova, size_t byte_cnt)
684 ** Hopefully someone figures out how to patch (NOP) the 684 ** Hopefully someone figures out how to patch (NOP) the
685 ** FDC/SYNC out at boot time. 685 ** FDC/SYNC out at boot time.
686 */ 686 */
687 asm volatile("fdc 0(%0)" : : "r" (pdir_ptr[7])); 687 asm volatile("fdc %%r0(%0)" : : "r" (pdir_ptr[7]));
688 688
689 iovp += IOVP_SIZE; 689 iovp += IOVP_SIZE;
690 byte_cnt -= IOVP_SIZE; 690 byte_cnt -= IOVP_SIZE;
@@ -836,7 +836,7 @@ ccio_unmap_single(struct device *dev, dma_addr_t iova, size_t size,
836 * This function implements the pci_alloc_consistent function. 836 * This function implements the pci_alloc_consistent function.
837 */ 837 */
838static void * 838static void *
839ccio_alloc_consistent(struct device *dev, size_t size, dma_addr_t *dma_handle, int flag) 839ccio_alloc_consistent(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t flag)
840{ 840{
841 void *ret; 841 void *ret;
842#if 0 842#if 0
@@ -1251,7 +1251,7 @@ static struct parisc_device_id ccio_tbl[] = {
1251static int ccio_probe(struct parisc_device *dev); 1251static int ccio_probe(struct parisc_device *dev);
1252 1252
1253static struct parisc_driver ccio_driver = { 1253static struct parisc_driver ccio_driver = {
1254 .name = "U2:Uturn", 1254 .name = "ccio",
1255 .id_table = ccio_tbl, 1255 .id_table = ccio_tbl,
1256 .probe = ccio_probe, 1256 .probe = ccio_probe,
1257}; 1257};
@@ -1314,14 +1314,13 @@ ccio_ioc_init(struct ioc *ioc)
1314 1314
1315 ioc->pdir_size = (iova_space_size / IOVP_SIZE) * sizeof(u64); 1315 ioc->pdir_size = (iova_space_size / IOVP_SIZE) * sizeof(u64);
1316 1316
1317 BUG_ON(ioc->pdir_size >= 4 * 1024 * 1024); /* max pdir size < 4MB */ 1317 BUG_ON(ioc->pdir_size > 8 * 1024 * 1024); /* max pdir size <= 8MB */
1318 1318
1319 /* Verify it's a power of two */ 1319 /* Verify it's a power of two */
1320 BUG_ON((1 << get_order(ioc->pdir_size)) != (ioc->pdir_size >> PAGE_SHIFT)); 1320 BUG_ON((1 << get_order(ioc->pdir_size)) != (ioc->pdir_size >> PAGE_SHIFT));
1321 1321
1322 DBG_INIT("%s() hpa 0x%lx mem %luMB IOV %dMB (%d bits)\n", 1322 DBG_INIT("%s() hpa 0x%p mem %luMB IOV %dMB (%d bits)\n",
1323 __FUNCTION__, 1323 __FUNCTION__, ioc->ioc_regs,
1324 ioc->ioc_hpa,
1325 (unsigned long) num_physpages >> (20 - PAGE_SHIFT), 1324 (unsigned long) num_physpages >> (20 - PAGE_SHIFT),
1326 iova_space_size>>20, 1325 iova_space_size>>20,
1327 iov_order + PAGE_SHIFT); 1326 iov_order + PAGE_SHIFT);
@@ -1329,13 +1328,12 @@ ccio_ioc_init(struct ioc *ioc)
1329 ioc->pdir_base = (u64 *)__get_free_pages(GFP_KERNEL, 1328 ioc->pdir_base = (u64 *)__get_free_pages(GFP_KERNEL,
1330 get_order(ioc->pdir_size)); 1329 get_order(ioc->pdir_size));
1331 if(NULL == ioc->pdir_base) { 1330 if(NULL == ioc->pdir_base) {
1332 panic("%s:%s() could not allocate I/O Page Table\n", __FILE__, 1331 panic("%s() could not allocate I/O Page Table\n", __FUNCTION__);
1333 __FUNCTION__);
1334 } 1332 }
1335 memset(ioc->pdir_base, 0, ioc->pdir_size); 1333 memset(ioc->pdir_base, 0, ioc->pdir_size);
1336 1334
1337 BUG_ON((((unsigned long)ioc->pdir_base) & PAGE_MASK) != (unsigned long)ioc->pdir_base); 1335 BUG_ON((((unsigned long)ioc->pdir_base) & PAGE_MASK) != (unsigned long)ioc->pdir_base);
1338 DBG_INIT(" base %p", ioc->pdir_base); 1336 DBG_INIT(" base %p\n", ioc->pdir_base);
1339 1337
1340 /* resource map size dictated by pdir_size */ 1338 /* resource map size dictated by pdir_size */
1341 ioc->res_size = (ioc->pdir_size / sizeof(u64)) >> 3; 1339 ioc->res_size = (ioc->pdir_size / sizeof(u64)) >> 3;
@@ -1344,8 +1342,7 @@ ccio_ioc_init(struct ioc *ioc)
1344 ioc->res_map = (u8 *)__get_free_pages(GFP_KERNEL, 1342 ioc->res_map = (u8 *)__get_free_pages(GFP_KERNEL,
1345 get_order(ioc->res_size)); 1343 get_order(ioc->res_size));
1346 if(NULL == ioc->res_map) { 1344 if(NULL == ioc->res_map) {
1347 panic("%s:%s() could not allocate resource map\n", __FILE__, 1345 panic("%s() could not allocate resource map\n", __FUNCTION__);
1348 __FUNCTION__);
1349 } 1346 }
1350 memset(ioc->res_map, 0, ioc->res_size); 1347 memset(ioc->res_map, 0, ioc->res_size);
1351 1348
@@ -1366,44 +1363,58 @@ ccio_ioc_init(struct ioc *ioc)
1366 ** Initialize IOA hardware 1363 ** Initialize IOA hardware
1367 */ 1364 */
1368 WRITE_U32(CCIO_CHAINID_MASK << ioc->chainid_shift, 1365 WRITE_U32(CCIO_CHAINID_MASK << ioc->chainid_shift,
1369 &ioc->ioc_hpa->io_chain_id_mask); 1366 &ioc->ioc_regs->io_chain_id_mask);
1370 1367
1371 WRITE_U32(virt_to_phys(ioc->pdir_base), 1368 WRITE_U32(virt_to_phys(ioc->pdir_base),
1372 &ioc->ioc_hpa->io_pdir_base); 1369 &ioc->ioc_regs->io_pdir_base);
1373 1370
1374 /* 1371 /*
1375 ** Go to "Virtual Mode" 1372 ** Go to "Virtual Mode"
1376 */ 1373 */
1377 WRITE_U32(IOA_NORMAL_MODE, &ioc->ioc_hpa->io_control); 1374 WRITE_U32(IOA_NORMAL_MODE, &ioc->ioc_regs->io_control);
1378 1375
1379 /* 1376 /*
1380 ** Initialize all I/O TLB entries to 0 (Valid bit off). 1377 ** Initialize all I/O TLB entries to 0 (Valid bit off).
1381 */ 1378 */
1382 WRITE_U32(0, &ioc->ioc_hpa->io_tlb_entry_m); 1379 WRITE_U32(0, &ioc->ioc_regs->io_tlb_entry_m);
1383 WRITE_U32(0, &ioc->ioc_hpa->io_tlb_entry_l); 1380 WRITE_U32(0, &ioc->ioc_regs->io_tlb_entry_l);
1384 1381
1385 for(i = 1 << CCIO_CHAINID_SHIFT; i ; i--) { 1382 for(i = 1 << CCIO_CHAINID_SHIFT; i ; i--) {
1386 WRITE_U32((CMD_TLB_DIRECT_WRITE | (i << ioc->chainid_shift)), 1383 WRITE_U32((CMD_TLB_DIRECT_WRITE | (i << ioc->chainid_shift)),
1387 &ioc->ioc_hpa->io_command); 1384 &ioc->ioc_regs->io_command);
1388 } 1385 }
1389} 1386}
1390 1387
1391static void 1388static void
1392ccio_init_resource(struct resource *res, char *name, unsigned long ioaddr) 1389ccio_init_resource(struct resource *res, char *name, void __iomem *ioaddr)
1393{ 1390{
1394 int result; 1391 int result;
1395 1392
1396 res->parent = NULL; 1393 res->parent = NULL;
1397 res->flags = IORESOURCE_MEM; 1394 res->flags = IORESOURCE_MEM;
1398 res->start = (unsigned long)(signed) __raw_readl(ioaddr) << 16; 1395 /*
1399 res->end = (unsigned long)(signed) (__raw_readl(ioaddr + 4) << 16) - 1; 1396 * bracing ((signed) ...) are required for 64bit kernel because
1397 * we only want to sign extend the lower 16 bits of the register.
1398 * The upper 16-bits of range registers are hardcoded to 0xffff.
1399 */
1400 res->start = (unsigned long)((signed) READ_U32(ioaddr) << 16);
1401 res->end = (unsigned long)((signed) (READ_U32(ioaddr + 4) << 16) - 1);
1400 res->name = name; 1402 res->name = name;
1403 /*
1404 * Check if this MMIO range is disable
1405 */
1401 if (res->end + 1 == res->start) 1406 if (res->end + 1 == res->start)
1402 return; 1407 return;
1403 result = request_resource(&iomem_resource, res); 1408
1409 /* On some platforms (e.g. K-Class), we have already registered
1410 * resources for devices reported by firmware. Some are children
1411 * of ccio.
1412 * "insert" ccio ranges in the mmio hierarchy (/proc/iomem).
1413 */
1414 result = insert_resource(&iomem_resource, res);
1404 if (result < 0) { 1415 if (result < 0) {
1405 printk(KERN_ERR "%s: failed to claim CCIO bus address space (%08lx,%08lx)\n", 1416 printk(KERN_ERR "%s() failed to claim CCIO bus address space (%08lx,%08lx)\n",
1406 __FILE__, res->start, res->end); 1417 __FUNCTION__, res->start, res->end);
1407 } 1418 }
1408} 1419}
1409 1420
@@ -1414,9 +1425,8 @@ static void __init ccio_init_resources(struct ioc *ioc)
1414 1425
1415 sprintf(name, "GSC Bus [%d/]", ioc->hw_path); 1426 sprintf(name, "GSC Bus [%d/]", ioc->hw_path);
1416 1427
1417 ccio_init_resource(res, name, (unsigned long)&ioc->ioc_hpa->io_io_low); 1428 ccio_init_resource(res, name, &ioc->ioc_regs->io_io_low);
1418 ccio_init_resource(res + 1, name, 1429 ccio_init_resource(res + 1, name, &ioc->ioc_regs->io_io_low_hv);
1419 (unsigned long)&ioc->ioc_hpa->io_io_low_hv);
1420} 1430}
1421 1431
1422static int new_ioc_area(struct resource *res, unsigned long size, 1432static int new_ioc_area(struct resource *res, unsigned long size,
@@ -1427,7 +1437,12 @@ static int new_ioc_area(struct resource *res, unsigned long size,
1427 1437
1428 res->start = (max - size + 1) &~ (align - 1); 1438 res->start = (max - size + 1) &~ (align - 1);
1429 res->end = res->start + size; 1439 res->end = res->start + size;
1430 if (!request_resource(&iomem_resource, res)) 1440
1441 /* We might be trying to expand the MMIO range to include
1442 * a child device that has already registered it's MMIO space.
1443 * Use "insert" instead of request_resource().
1444 */
1445 if (!insert_resource(&iomem_resource, res))
1431 return 0; 1446 return 0;
1432 1447
1433 return new_ioc_area(res, size, min, max - size, align); 1448 return new_ioc_area(res, size, min, max - size, align);
@@ -1486,15 +1501,15 @@ int ccio_allocate_resource(const struct parisc_device *dev,
1486 1501
1487 if (!expand_ioc_area(parent, size, min, max, align)) { 1502 if (!expand_ioc_area(parent, size, min, max, align)) {
1488 __raw_writel(((parent->start)>>16) | 0xffff0000, 1503 __raw_writel(((parent->start)>>16) | 0xffff0000,
1489 (unsigned long)&(ioc->ioc_hpa->io_io_low)); 1504 &ioc->ioc_regs->io_io_low);
1490 __raw_writel(((parent->end)>>16) | 0xffff0000, 1505 __raw_writel(((parent->end)>>16) | 0xffff0000,
1491 (unsigned long)&(ioc->ioc_hpa->io_io_high)); 1506 &ioc->ioc_regs->io_io_high);
1492 } else if (!expand_ioc_area(parent + 1, size, min, max, align)) { 1507 } else if (!expand_ioc_area(parent + 1, size, min, max, align)) {
1493 parent++; 1508 parent++;
1494 __raw_writel(((parent->start)>>16) | 0xffff0000, 1509 __raw_writel(((parent->start)>>16) | 0xffff0000,
1495 (unsigned long)&(ioc->ioc_hpa->io_io_low_hv)); 1510 &ioc->ioc_regs->io_io_low_hv);
1496 __raw_writel(((parent->end)>>16) | 0xffff0000, 1511 __raw_writel(((parent->end)>>16) | 0xffff0000,
1497 (unsigned long)&(ioc->ioc_hpa->io_io_high_hv)); 1512 &ioc->ioc_regs->io_io_high_hv);
1498 } else { 1513 } else {
1499 return -EBUSY; 1514 return -EBUSY;
1500 } 1515 }
@@ -1521,7 +1536,12 @@ int ccio_request_resource(const struct parisc_device *dev,
1521 return -EBUSY; 1536 return -EBUSY;
1522 } 1537 }
1523 1538
1524 return request_resource(parent, res); 1539 /* "transparent" bus bridges need to register MMIO resources
1540 * firmware assigned them. e.g. children of hppb.c (e.g. K-class)
1541 * registered their resources in the PDC "bus walk" (See
1542 * arch/parisc/kernel/inventory.c).
1543 */
1544 return insert_resource(parent, res);
1525} 1545}
1526 1546
1527/** 1547/**
@@ -1546,7 +1566,7 @@ static int ccio_probe(struct parisc_device *dev)
1546 1566
1547 ioc->name = dev->id.hversion == U2_IOA_RUNWAY ? "U2" : "UTurn"; 1567 ioc->name = dev->id.hversion == U2_IOA_RUNWAY ? "U2" : "UTurn";
1548 1568
1549 printk(KERN_INFO "Found %s at 0x%lx\n", ioc->name, dev->hpa); 1569 printk(KERN_INFO "Found %s at 0x%lx\n", ioc->name, dev->hpa.start);
1550 1570
1551 for (i = 0; i < ioc_count; i++) { 1571 for (i = 0; i < ioc_count; i++) {
1552 ioc_p = &(*ioc_p)->next; 1572 ioc_p = &(*ioc_p)->next;
@@ -1554,7 +1574,7 @@ static int ccio_probe(struct parisc_device *dev)
1554 *ioc_p = ioc; 1574 *ioc_p = ioc;
1555 1575
1556 ioc->hw_path = dev->hw_path; 1576 ioc->hw_path = dev->hw_path;
1557 ioc->ioc_hpa = (struct ioa_registers *)dev->hpa; 1577 ioc->ioc_regs = ioremap(dev->hpa.start, 4096);
1558 ccio_ioc_init(ioc); 1578 ccio_ioc_init(ioc);
1559 ccio_init_resources(ioc); 1579 ccio_init_resources(ioc);
1560 hppa_dma_ops = &ccio_ops; 1580 hppa_dma_ops = &ccio_ops;
diff --git a/drivers/parisc/ccio-rm-dma.c b/drivers/parisc/ccio-rm-dma.c
index 57e6385976e2..356b8357bccc 100644
--- a/drivers/parisc/ccio-rm-dma.c
+++ b/drivers/parisc/ccio-rm-dma.c
@@ -167,7 +167,7 @@ ccio_probe(struct parisc_device *dev)
167{ 167{
168 printk(KERN_INFO "%s found %s at 0x%lx\n", MODULE_NAME, 168 printk(KERN_INFO "%s found %s at 0x%lx\n", MODULE_NAME,
169 dev->id.hversion == U2_BC_GSC ? "U2" : "UTurn", 169 dev->id.hversion == U2_BC_GSC ? "U2" : "UTurn",
170 dev->hpa); 170 dev->hpa.start);
171 171
172/* 172/*
173** FIXME - should check U2 registers to verify it's really running 173** FIXME - should check U2 registers to verify it's really running
diff --git a/drivers/parisc/dino.c b/drivers/parisc/dino.c
index 2f2dbef2c3b7..5ab75334c579 100644
--- a/drivers/parisc/dino.c
+++ b/drivers/parisc/dino.c
@@ -178,6 +178,8 @@ static int dino_cfg_read(struct pci_bus *bus, unsigned int devfn, int where,
178 void __iomem *base_addr = d->hba.base_addr; 178 void __iomem *base_addr = d->hba.base_addr;
179 unsigned long flags; 179 unsigned long flags;
180 180
181 DBG("%s: %p, %d, %d, %d\n", __FUNCTION__, base_addr, devfn, where,
182 size);
181 spin_lock_irqsave(&d->dinosaur_pen, flags); 183 spin_lock_irqsave(&d->dinosaur_pen, flags);
182 184
183 /* tell HW which CFG address */ 185 /* tell HW which CFG address */
@@ -211,6 +213,8 @@ static int dino_cfg_write(struct pci_bus *bus, unsigned int devfn, int where,
211 void __iomem *base_addr = d->hba.base_addr; 213 void __iomem *base_addr = d->hba.base_addr;
212 unsigned long flags; 214 unsigned long flags;
213 215
216 DBG("%s: %p, %d, %d, %d\n", __FUNCTION__, base_addr, devfn, where,
217 size);
214 spin_lock_irqsave(&d->dinosaur_pen, flags); 218 spin_lock_irqsave(&d->dinosaur_pen, flags);
215 219
216 /* avoid address stepping feature */ 220 /* avoid address stepping feature */
@@ -295,7 +299,7 @@ static void dino_disable_irq(unsigned int irq)
295 struct dino_device *dino_dev = irq_desc[irq].handler_data; 299 struct dino_device *dino_dev = irq_desc[irq].handler_data;
296 int local_irq = gsc_find_local_irq(irq, dino_dev->global_irq, irq); 300 int local_irq = gsc_find_local_irq(irq, dino_dev->global_irq, irq);
297 301
298 DBG(KERN_WARNING "%s(0x%p, %d)\n", __FUNCTION__, irq_dev, irq); 302 DBG(KERN_WARNING "%s(0x%p, %d)\n", __FUNCTION__, dino_dev, irq);
299 303
300 /* Clear the matching bit in the IMR register */ 304 /* Clear the matching bit in the IMR register */
301 dino_dev->imr &= ~(DINO_MASK_IRQ(local_irq)); 305 dino_dev->imr &= ~(DINO_MASK_IRQ(local_irq));
@@ -308,7 +312,7 @@ static void dino_enable_irq(unsigned int irq)
308 int local_irq = gsc_find_local_irq(irq, dino_dev->global_irq, irq); 312 int local_irq = gsc_find_local_irq(irq, dino_dev->global_irq, irq);
309 u32 tmp; 313 u32 tmp;
310 314
311 DBG(KERN_WARNING "%s(0x%p, %d)\n", __FUNCTION__, irq_dev, irq); 315 DBG(KERN_WARNING "%s(0x%p, %d)\n", __FUNCTION__, dino_dev, irq);
312 316
313 /* 317 /*
314 ** clear pending IRQ bits 318 ** clear pending IRQ bits
@@ -490,7 +494,7 @@ dino_card_setup(struct pci_bus *bus, void __iomem *base_addr)
490 if (res->start == F_EXTEND(0xf0000000UL | (i * _8MB))) 494 if (res->start == F_EXTEND(0xf0000000UL | (i * _8MB)))
491 break; 495 break;
492 } 496 }
493 DBG("DINO GSC WRITE i=%d, start=%lx, dino addr = %lx\n", 497 DBG("DINO GSC WRITE i=%d, start=%lx, dino addr = %p\n",
494 i, res->start, base_addr + DINO_IO_ADDR_EN); 498 i, res->start, base_addr + DINO_IO_ADDR_EN);
495 __raw_writel(1 << i, base_addr + DINO_IO_ADDR_EN); 499 __raw_writel(1 << i, base_addr + DINO_IO_ADDR_EN);
496} 500}
@@ -683,6 +687,14 @@ static void __init
683dino_card_init(struct dino_device *dino_dev) 687dino_card_init(struct dino_device *dino_dev)
684{ 688{
685 u32 brdg_feat = 0x00784e05; 689 u32 brdg_feat = 0x00784e05;
690 unsigned long status;
691
692 status = __raw_readl(dino_dev->hba.base_addr+DINO_IO_STATUS);
693 if (status & 0x0000ff80) {
694 __raw_writel(0x00000005,
695 dino_dev->hba.base_addr+DINO_IO_COMMAND);
696 udelay(1);
697 }
686 698
687 __raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_GMASK); 699 __raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_GMASK);
688 __raw_writel(0x00000001, dino_dev->hba.base_addr+DINO_IO_FBB_EN); 700 __raw_writel(0x00000001, dino_dev->hba.base_addr+DINO_IO_FBB_EN);
@@ -902,15 +914,15 @@ void ccio_cujo20_fixup(struct parisc_device *dev, u32 iovp);
902** If so, initialize the chip appropriately (card-mode vs bridge mode). 914** If so, initialize the chip appropriately (card-mode vs bridge mode).
903** Much of the initialization is common though. 915** Much of the initialization is common though.
904*/ 916*/
905static int __init 917static int __init dino_probe(struct parisc_device *dev)
906dino_driver_callback(struct parisc_device *dev)
907{ 918{
908 struct dino_device *dino_dev; // Dino specific control struct 919 struct dino_device *dino_dev; // Dino specific control struct
909 const char *version = "unknown"; 920 const char *version = "unknown";
910 char *name; 921 char *name;
911 int is_cujo = 0; 922 int is_cujo = 0;
912 struct pci_bus *bus; 923 struct pci_bus *bus;
913 924 unsigned long hpa = dev->hpa.start;
925
914 name = "Dino"; 926 name = "Dino";
915 if (is_card_dino(&dev->id)) { 927 if (is_card_dino(&dev->id)) {
916 version = "3.x (card mode)"; 928 version = "3.x (card mode)";
@@ -928,11 +940,11 @@ dino_driver_callback(struct parisc_device *dev)
928 } 940 }
929 } 941 }
930 942
931 printk("%s version %s found at 0x%lx\n", name, version, dev->hpa); 943 printk("%s version %s found at 0x%lx\n", name, version, hpa);
932 944
933 if (!request_mem_region(dev->hpa, PAGE_SIZE, name)) { 945 if (!request_mem_region(hpa, PAGE_SIZE, name)) {
934 printk(KERN_ERR "DINO: Hey! Someone took my MMIO space (0x%ld)!\n", 946 printk(KERN_ERR "DINO: Hey! Someone took my MMIO space (0x%ld)!\n",
935 dev->hpa); 947 hpa);
936 return 1; 948 return 1;
937 } 949 }
938 950
@@ -940,12 +952,12 @@ dino_driver_callback(struct parisc_device *dev)
940 if (is_cujo && dev->id.hversion_rev == 1) { 952 if (is_cujo && dev->id.hversion_rev == 1) {
941#ifdef CONFIG_IOMMU_CCIO 953#ifdef CONFIG_IOMMU_CCIO
942 printk(KERN_WARNING "Enabling Cujo 2.0 bug workaround\n"); 954 printk(KERN_WARNING "Enabling Cujo 2.0 bug workaround\n");
943 if (dev->hpa == (unsigned long)CUJO_RAVEN_ADDR) { 955 if (hpa == (unsigned long)CUJO_RAVEN_ADDR) {
944 ccio_cujo20_fixup(dev, CUJO_RAVEN_BADPAGE); 956 ccio_cujo20_fixup(dev, CUJO_RAVEN_BADPAGE);
945 } else if (dev->hpa == (unsigned long)CUJO_FIREHAWK_ADDR) { 957 } else if (hpa == (unsigned long)CUJO_FIREHAWK_ADDR) {
946 ccio_cujo20_fixup(dev, CUJO_FIREHAWK_BADPAGE); 958 ccio_cujo20_fixup(dev, CUJO_FIREHAWK_BADPAGE);
947 } else { 959 } else {
948 printk("Don't recognise Cujo at address 0x%lx, not enabling workaround\n", dev->hpa); 960 printk("Don't recognise Cujo at address 0x%lx, not enabling workaround\n", hpa);
949 } 961 }
950#endif 962#endif
951 } else if (!is_cujo && !is_card_dino(&dev->id) && 963 } else if (!is_cujo && !is_card_dino(&dev->id) &&
@@ -970,7 +982,7 @@ dino_driver_callback(struct parisc_device *dev)
970 memset(dino_dev, 0, sizeof(struct dino_device)); 982 memset(dino_dev, 0, sizeof(struct dino_device));
971 983
972 dino_dev->hba.dev = dev; 984 dino_dev->hba.dev = dev;
973 dino_dev->hba.base_addr = ioremap(dev->hpa, 4096); /* faster access */ 985 dino_dev->hba.base_addr = ioremap(hpa, 4096);
974 dino_dev->hba.lmmio_space_offset = 0; /* CPU addrs == bus addrs */ 986 dino_dev->hba.lmmio_space_offset = 0; /* CPU addrs == bus addrs */
975 spin_lock_init(&dino_dev->dinosaur_pen); 987 spin_lock_init(&dino_dev->dinosaur_pen);
976 dino_dev->hba.iommu = ccio_get_iommu(dev); 988 dino_dev->hba.iommu = ccio_get_iommu(dev);
@@ -1027,9 +1039,9 @@ static struct parisc_device_id dino_tbl[] = {
1027}; 1039};
1028 1040
1029static struct parisc_driver dino_driver = { 1041static struct parisc_driver dino_driver = {
1030 .name = "Dino", 1042 .name = "dino",
1031 .id_table = dino_tbl, 1043 .id_table = dino_tbl,
1032 .probe = dino_driver_callback, 1044 .probe = dino_probe,
1033}; 1045};
1034 1046
1035/* 1047/*
diff --git a/drivers/parisc/eisa.c b/drivers/parisc/eisa.c
index 043d47aea75b..6362bf99eff6 100644
--- a/drivers/parisc/eisa.c
+++ b/drivers/parisc/eisa.c
@@ -315,7 +315,7 @@ static int __devinit eisa_probe(struct parisc_device *dev)
315 char *name = is_mongoose(dev) ? "Mongoose" : "Wax"; 315 char *name = is_mongoose(dev) ? "Mongoose" : "Wax";
316 316
317 printk(KERN_INFO "%s EISA Adapter found at 0x%08lx\n", 317 printk(KERN_INFO "%s EISA Adapter found at 0x%08lx\n",
318 name, dev->hpa); 318 name, dev->hpa.start);
319 319
320 eisa_dev.hba.dev = dev; 320 eisa_dev.hba.dev = dev;
321 eisa_dev.hba.iommu = ccio_get_iommu(dev); 321 eisa_dev.hba.iommu = ccio_get_iommu(dev);
@@ -397,7 +397,7 @@ static struct parisc_device_id eisa_tbl[] = {
397MODULE_DEVICE_TABLE(parisc, eisa_tbl); 397MODULE_DEVICE_TABLE(parisc, eisa_tbl);
398 398
399static struct parisc_driver eisa_driver = { 399static struct parisc_driver eisa_driver = {
400 .name = "EISA Bus Adapter", 400 .name = "eisa_ba",
401 .id_table = eisa_tbl, 401 .id_table = eisa_tbl,
402 .probe = eisa_probe, 402 .probe = eisa_probe,
403}; 403};
diff --git a/drivers/parisc/gsc.c b/drivers/parisc/gsc.c
index af5e02526a18..16d40f95978d 100644
--- a/drivers/parisc/gsc.c
+++ b/drivers/parisc/gsc.c
@@ -183,12 +183,20 @@ void gsc_asic_assign_irq(struct gsc_asic *asic, int local_irq, int *irqp)
183 *irqp = irq; 183 *irqp = irq;
184} 184}
185 185
186static struct device *next_device(struct klist_iter *i)
187{
188 struct klist_node * n = klist_next(i);
189 return n ? container_of(n, struct device, knode_parent) : NULL;
190}
191
186void gsc_fixup_irqs(struct parisc_device *parent, void *ctrl, 192void gsc_fixup_irqs(struct parisc_device *parent, void *ctrl,
187 void (*choose_irq)(struct parisc_device *, void *)) 193 void (*choose_irq)(struct parisc_device *, void *))
188{ 194{
189 struct device *dev; 195 struct device *dev;
196 struct klist_iter i;
190 197
191 list_for_each_entry(dev, &parent->dev.children, node) { 198 klist_iter_init(&parent->dev.klist_children, &i);
199 while ((dev = next_device(&i))) {
192 struct parisc_device *padev = to_parisc_device(dev); 200 struct parisc_device *padev = to_parisc_device(dev);
193 201
194 /* work-around for 715/64 and others which have parent 202 /* work-around for 715/64 and others which have parent
@@ -197,6 +205,7 @@ void gsc_fixup_irqs(struct parisc_device *parent, void *ctrl,
197 return gsc_fixup_irqs(padev, ctrl, choose_irq); 205 return gsc_fixup_irqs(padev, ctrl, choose_irq);
198 choose_irq(padev, ctrl); 206 choose_irq(padev, ctrl);
199 } 207 }
208 klist_iter_exit(&i);
200} 209}
201 210
202int gsc_common_setup(struct parisc_device *parent, struct gsc_asic *gsc_asic) 211int gsc_common_setup(struct parisc_device *parent, struct gsc_asic *gsc_asic)
diff --git a/drivers/parisc/hppb.c b/drivers/parisc/hppb.c
index e869c6020370..5edf93f80757 100644
--- a/drivers/parisc/hppb.c
+++ b/drivers/parisc/hppb.c
@@ -68,14 +68,14 @@ static int hppb_probe(struct parisc_device *dev)
68 memset(card->next, '\0', sizeof(struct hppb_card)); 68 memset(card->next, '\0', sizeof(struct hppb_card));
69 card = card->next; 69 card = card->next;
70 } 70 }
71 printk(KERN_INFO "Found GeckoBoa at 0x%lx\n", dev->hpa); 71 printk(KERN_INFO "Found GeckoBoa at 0x%lx\n", dev->hpa.start);
72 72
73 card->hpa = dev->hpa; 73 card->hpa = dev->hpa.start;
74 card->mmio_region.name = "HP-PB Bus"; 74 card->mmio_region.name = "HP-PB Bus";
75 card->mmio_region.flags = IORESOURCE_MEM; 75 card->mmio_region.flags = IORESOURCE_MEM;
76 76
77 card->mmio_region.start = __raw_readl(dev->hpa + IO_IO_LOW); 77 card->mmio_region.start = gsc_readl(dev->hpa.start + IO_IO_LOW);
78 card->mmio_region.end = __raw_readl(dev->hpa + IO_IO_HIGH) - 1; 78 card->mmio_region.end = gsc_readl(dev->hpa.start + IO_IO_HIGH) - 1;
79 79
80 status = ccio_request_resource(dev, &card->mmio_region); 80 status = ccio_request_resource(dev, &card->mmio_region);
81 if(status < 0) { 81 if(status < 0) {
@@ -93,7 +93,7 @@ static struct parisc_device_id hppb_tbl[] = {
93}; 93};
94 94
95static struct parisc_driver hppb_driver = { 95static struct parisc_driver hppb_driver = {
96 .name = "Gecko Boa", 96 .name = "gecko_boa",
97 .id_table = hppb_tbl, 97 .id_table = hppb_tbl,
98 .probe = hppb_probe, 98 .probe = hppb_probe,
99}; 99};
diff --git a/drivers/parisc/iosapic.c b/drivers/parisc/iosapic.c
index 7a57c1b8373f..a39fbfef789a 100644
--- a/drivers/parisc/iosapic.c
+++ b/drivers/parisc/iosapic.c
@@ -244,7 +244,7 @@ static struct irt_entry *iosapic_alloc_irt(int num_entries)
244 * 4-byte alignment on 32-bit kernels 244 * 4-byte alignment on 32-bit kernels
245 */ 245 */
246 a = (unsigned long)kmalloc(sizeof(struct irt_entry) * num_entries + 8, GFP_KERNEL); 246 a = (unsigned long)kmalloc(sizeof(struct irt_entry) * num_entries + 8, GFP_KERNEL);
247 a = (a + 7) & ~7; 247 a = (a + 7UL) & ~7UL;
248 return (struct irt_entry *)a; 248 return (struct irt_entry *)a;
249} 249}
250 250
diff --git a/drivers/parisc/lasi.c b/drivers/parisc/lasi.c
index cb84a4e84a2f..a8c20396ffbe 100644
--- a/drivers/parisc/lasi.c
+++ b/drivers/parisc/lasi.c
@@ -175,7 +175,7 @@ lasi_init_chip(struct parisc_device *dev)
175 return -ENOMEM; 175 return -ENOMEM;
176 176
177 lasi->name = "Lasi"; 177 lasi->name = "Lasi";
178 lasi->hpa = dev->hpa; 178 lasi->hpa = dev->hpa.start;
179 179
180 /* Check the 4-bit (yes, only 4) version register */ 180 /* Check the 4-bit (yes, only 4) version register */
181 lasi->version = gsc_readl(lasi->hpa + LASI_VER) & 0xf; 181 lasi->version = gsc_readl(lasi->hpa + LASI_VER) & 0xf;
@@ -233,7 +233,7 @@ static struct parisc_device_id lasi_tbl[] = {
233}; 233};
234 234
235struct parisc_driver lasi_driver = { 235struct parisc_driver lasi_driver = {
236 .name = "Lasi", 236 .name = "lasi",
237 .id_table = lasi_tbl, 237 .id_table = lasi_tbl,
238 .probe = lasi_init_chip, 238 .probe = lasi_init_chip,
239}; 239};
diff --git a/drivers/parisc/lba_pci.c b/drivers/parisc/lba_pci.c
index 7fdd80b7eb47..5e495dcbc58a 100644
--- a/drivers/parisc/lba_pci.c
+++ b/drivers/parisc/lba_pci.c
@@ -1288,7 +1288,7 @@ lba_legacy_resources(struct parisc_device *pa_dev, struct lba_device *lba_dev)
1288 ** Adjust "window" for this rope. 1288 ** Adjust "window" for this rope.
1289 */ 1289 */
1290 rsize /= ROPES_PER_IOC; 1290 rsize /= ROPES_PER_IOC;
1291 r->start += (rsize + 1) * LBA_NUM(pa_dev->hpa); 1291 r->start += (rsize + 1) * LBA_NUM(pa_dev->hpa.start);
1292 r->end = r->start + rsize; 1292 r->end = r->start + rsize;
1293 } else { 1293 } else {
1294 r->end = r->start = 0; /* Not enabled. */ 1294 r->end = r->start = 0; /* Not enabled. */
@@ -1458,7 +1458,7 @@ lba_driver_probe(struct parisc_device *dev)
1458 u32 func_class; 1458 u32 func_class;
1459 void *tmp_obj; 1459 void *tmp_obj;
1460 char *version; 1460 char *version;
1461 void __iomem *addr = ioremap(dev->hpa, 4096); 1461 void __iomem *addr = ioremap(dev->hpa.start, 4096);
1462 1462
1463 /* Read HW Rev First */ 1463 /* Read HW Rev First */
1464 func_class = READ_REG32(addr + LBA_FCLASS); 1464 func_class = READ_REG32(addr + LBA_FCLASS);
@@ -1476,7 +1476,7 @@ lba_driver_probe(struct parisc_device *dev)
1476 } 1476 }
1477 1477
1478 printk(KERN_INFO "%s version %s (0x%x) found at 0x%lx\n", 1478 printk(KERN_INFO "%s version %s (0x%x) found at 0x%lx\n",
1479 MODULE_NAME, version, func_class & 0xf, dev->hpa); 1479 MODULE_NAME, version, func_class & 0xf, dev->hpa.start);
1480 1480
1481 if (func_class < 2) { 1481 if (func_class < 2) {
1482 printk(KERN_WARNING "Can't support LBA older than " 1482 printk(KERN_WARNING "Can't support LBA older than "
@@ -1503,17 +1503,17 @@ lba_driver_probe(struct parisc_device *dev)
1503 * but for the mask for func_class. 1503 * but for the mask for func_class.
1504 */ 1504 */
1505 printk(KERN_INFO "%s version %s (0x%x) found at 0x%lx\n", 1505 printk(KERN_INFO "%s version %s (0x%x) found at 0x%lx\n",
1506 MODULE_NAME, version, func_class & 0xff, dev->hpa); 1506 MODULE_NAME, version, func_class & 0xff, dev->hpa.start);
1507 cfg_ops = &mercury_cfg_ops; 1507 cfg_ops = &mercury_cfg_ops;
1508 } else { 1508 } else {
1509 printk(KERN_ERR "Unknown LBA found at 0x%lx\n", dev->hpa); 1509 printk(KERN_ERR "Unknown LBA found at 0x%lx\n", dev->hpa.start);
1510 return -ENODEV; 1510 return -ENODEV;
1511 } 1511 }
1512 1512
1513 /* 1513 /*
1514 ** Tell I/O SAPIC driver we have a IRQ handler/region. 1514 ** Tell I/O SAPIC driver we have a IRQ handler/region.
1515 */ 1515 */
1516 tmp_obj = iosapic_register(dev->hpa + LBA_IOSAPIC_BASE); 1516 tmp_obj = iosapic_register(dev->hpa.start + LBA_IOSAPIC_BASE);
1517 1517
1518 /* NOTE: PCI devices (e.g. 103c:1005 graphics card) which don't 1518 /* NOTE: PCI devices (e.g. 103c:1005 graphics card) which don't
1519 ** have an IRT entry will get NULL back from iosapic code. 1519 ** have an IRT entry will get NULL back from iosapic code.
@@ -1635,7 +1635,7 @@ void __init lba_init(void)
1635*/ 1635*/
1636void lba_set_iregs(struct parisc_device *lba, u32 ibase, u32 imask) 1636void lba_set_iregs(struct parisc_device *lba, u32 ibase, u32 imask)
1637{ 1637{
1638 void __iomem * base_addr = ioremap(lba->hpa, 4096); 1638 void __iomem * base_addr = ioremap(lba->hpa.start, 4096);
1639 1639
1640 imask <<= 2; /* adjust for hints - 2 more bits */ 1640 imask <<= 2; /* adjust for hints - 2 more bits */
1641 1641
diff --git a/drivers/parisc/led.c b/drivers/parisc/led.c
index 286902298e33..95bd07b8b61b 100644
--- a/drivers/parisc/led.c
+++ b/drivers/parisc/led.c
@@ -18,6 +18,9 @@
18 * Changes: 18 * Changes:
19 * - Audit copy_from_user in led_proc_write. 19 * - Audit copy_from_user in led_proc_write.
20 * Daniele Bellucci <bellucda@tiscali.it> 20 * Daniele Bellucci <bellucda@tiscali.it>
21 * - Switch from using a tasklet to a work queue, so the led_LCD_driver
22 * can sleep.
23 * David Pye <dmp@davidmpye.dyndns.org>
21 */ 24 */
22 25
23#include <linux/config.h> 26#include <linux/config.h>
@@ -37,6 +40,7 @@
37#include <linux/proc_fs.h> 40#include <linux/proc_fs.h>
38#include <linux/ctype.h> 41#include <linux/ctype.h>
39#include <linux/blkdev.h> 42#include <linux/blkdev.h>
43#include <linux/workqueue.h>
40#include <linux/rcupdate.h> 44#include <linux/rcupdate.h>
41#include <asm/io.h> 45#include <asm/io.h>
42#include <asm/processor.h> 46#include <asm/processor.h>
@@ -47,25 +51,30 @@
47#include <asm/uaccess.h> 51#include <asm/uaccess.h>
48 52
49/* The control of the LEDs and LCDs on PARISC-machines have to be done 53/* The control of the LEDs and LCDs on PARISC-machines have to be done
50 completely in software. The necessary calculations are done in a tasklet 54 completely in software. The necessary calculations are done in a work queue
51 which is scheduled at every timer interrupt and since the calculations 55 task which is scheduled regularly, and since the calculations may consume a
52 may consume relatively much CPU-time some of the calculations can be 56 relatively large amount of CPU time, some of the calculations can be
53 turned off with the following variables (controlled via procfs) */ 57 turned off with the following variables (controlled via procfs) */
54 58
55static int led_type = -1; 59static int led_type = -1;
56static int led_heartbeat = 1; 60static unsigned char lastleds; /* LED state from most recent update */
57static int led_diskio = 1; 61static unsigned int led_heartbeat = 1;
58static int led_lanrxtx = 1; 62static unsigned int led_diskio = 1;
63static unsigned int led_lanrxtx = 1;
59static char lcd_text[32]; 64static char lcd_text[32];
60static char lcd_text_default[32]; 65static char lcd_text_default[32];
61 66
67
68static struct workqueue_struct *led_wq;
69static void led_work_func(void *);
70static DECLARE_WORK(led_task, led_work_func, NULL);
71
62#if 0 72#if 0
63#define DPRINTK(x) printk x 73#define DPRINTK(x) printk x
64#else 74#else
65#define DPRINTK(x) 75#define DPRINTK(x)
66#endif 76#endif
67 77
68
69struct lcd_block { 78struct lcd_block {
70 unsigned char command; /* stores the command byte */ 79 unsigned char command; /* stores the command byte */
71 unsigned char on; /* value for turning LED on */ 80 unsigned char on; /* value for turning LED on */
@@ -116,12 +125,27 @@ lcd_info __attribute__((aligned(8))) =
116#define LCD_DATA_REG lcd_info.lcd_data_reg_addr 125#define LCD_DATA_REG lcd_info.lcd_data_reg_addr
117#define LED_DATA_REG lcd_info.lcd_cmd_reg_addr /* LASI & ASP only */ 126#define LED_DATA_REG lcd_info.lcd_cmd_reg_addr /* LASI & ASP only */
118 127
128#define LED_HASLCD 1
129#define LED_NOLCD 0
130
131/* The workqueue must be created at init-time */
132static int start_task(void)
133{
134 /* Display the default text now */
135 if (led_type == LED_HASLCD) lcd_print( lcd_text_default );
136
137 /* Create the work queue and queue the LED task */
138 led_wq = create_singlethread_workqueue("led_wq");
139 queue_work(led_wq, &led_task);
140
141 return 0;
142}
143
144device_initcall(start_task);
119 145
120/* ptr to LCD/LED-specific function */ 146/* ptr to LCD/LED-specific function */
121static void (*led_func_ptr) (unsigned char); 147static void (*led_func_ptr) (unsigned char);
122 148
123#define LED_HASLCD 1
124#define LED_NOLCD 0
125#ifdef CONFIG_PROC_FS 149#ifdef CONFIG_PROC_FS
126static int led_proc_read(char *page, char **start, off_t off, int count, 150static int led_proc_read(char *page, char **start, off_t off, int count,
127 int *eof, void *data) 151 int *eof, void *data)
@@ -286,52 +310,35 @@ static void led_LASI_driver(unsigned char leds)
286/* 310/*
287 ** 311 **
288 ** led_LCD_driver() 312 ** led_LCD_driver()
289 **
290 ** The logic of the LCD driver is, that we write at every scheduled call
291 ** only to one of LCD_CMD_REG _or_ LCD_DATA_REG - registers.
292 ** That way we don't need to let this tasklet busywait for min_cmd_delay
293 ** milliseconds.
294 **
295 ** TODO: check the value of "min_cmd_delay" against the value of HZ.
296 ** 313 **
297 */ 314 */
298static void led_LCD_driver(unsigned char leds) 315static void led_LCD_driver(unsigned char leds)
299{ 316{
300 static int last_index; /* 0:heartbeat, 1:disk, 2:lan_in, 3:lan_out */ 317 static int i;
301 static int last_was_cmd;/* 0: CMD was written last, 1: DATA was last */ 318 static unsigned char mask[4] = { LED_HEARTBEAT, LED_DISK_IO,
302 struct lcd_block *block_ptr; 319 LED_LAN_RCV, LED_LAN_TX };
303 int value;
304
305 switch (last_index) {
306 case 0: block_ptr = &lcd_info.heartbeat;
307 value = leds & LED_HEARTBEAT;
308 break;
309 case 1: block_ptr = &lcd_info.disk_io;
310 value = leds & LED_DISK_IO;
311 break;
312 case 2: block_ptr = &lcd_info.lan_rcv;
313 value = leds & LED_LAN_RCV;
314 break;
315 case 3: block_ptr = &lcd_info.lan_tx;
316 value = leds & LED_LAN_TX;
317 break;
318 default: /* should never happen: */
319 return;
320 }
321
322 if (last_was_cmd) {
323 /* write the value to the LCD data port */
324 gsc_writeb( value ? block_ptr->on : block_ptr->off, LCD_DATA_REG );
325 } else {
326 /* write the command-byte to the LCD command register */
327 gsc_writeb( block_ptr->command, LCD_CMD_REG );
328 }
329 320
330 /* now update the vars for the next interrupt iteration */ 321 static struct lcd_block * blockp[4] = {
331 if (++last_was_cmd == 2) { /* switch between cmd & data */ 322 &lcd_info.heartbeat,
332 last_was_cmd = 0; 323 &lcd_info.disk_io,
333 if (++last_index == 4) 324 &lcd_info.lan_rcv,
334 last_index = 0; /* switch back to heartbeat index */ 325 &lcd_info.lan_tx
326 };
327
328 /* Convert min_cmd_delay to milliseconds */
329 unsigned int msec_cmd_delay = 1 + (lcd_info.min_cmd_delay / 1000);
330
331 for (i=0; i<4; ++i)
332 {
333 if ((leds & mask[i]) != (lastleds & mask[i]))
334 {
335 gsc_writeb( blockp[i]->command, LCD_CMD_REG );
336 msleep(msec_cmd_delay);
337
338 gsc_writeb( leds & mask[i] ? blockp[i]->on :
339 blockp[i]->off, LCD_DATA_REG );
340 msleep(msec_cmd_delay);
341 }
335 } 342 }
336} 343}
337 344
@@ -356,7 +363,7 @@ static __inline__ int led_get_net_activity(void)
356 363
357 rx_total = tx_total = 0; 364 rx_total = tx_total = 0;
358 365
359 /* we are running as tasklet, so locking dev_base 366 /* we are running as a workqueue task, so locking dev_base
360 * for reading should be OK */ 367 * for reading should be OK */
361 read_lock(&dev_base_lock); 368 read_lock(&dev_base_lock);
362 rcu_read_lock(); 369 rcu_read_lock();
@@ -405,7 +412,7 @@ static __inline__ int led_get_diskio_activity(void)
405 static unsigned long last_pgpgin, last_pgpgout; 412 static unsigned long last_pgpgin, last_pgpgout;
406 struct page_state pgstat; 413 struct page_state pgstat;
407 int changed; 414 int changed;
408 415
409 get_full_page_state(&pgstat); /* get no of sectors in & out */ 416 get_full_page_state(&pgstat); /* get no of sectors in & out */
410 417
411 /* Just use a very simple calculation here. Do not care about overflow, 418 /* Just use a very simple calculation here. Do not care about overflow,
@@ -413,86 +420,70 @@ static __inline__ int led_get_diskio_activity(void)
413 changed = (pgstat.pgpgin != last_pgpgin) || (pgstat.pgpgout != last_pgpgout); 420 changed = (pgstat.pgpgin != last_pgpgin) || (pgstat.pgpgout != last_pgpgout);
414 last_pgpgin = pgstat.pgpgin; 421 last_pgpgin = pgstat.pgpgin;
415 last_pgpgout = pgstat.pgpgout; 422 last_pgpgout = pgstat.pgpgout;
416 423
417 return (changed ? LED_DISK_IO : 0); 424 return (changed ? LED_DISK_IO : 0);
418} 425}
419 426
420 427
421 428
422/* 429/*
423 ** led_tasklet_func() 430 ** led_work_func()
424 ** 431 **
425 ** is scheduled at every timer interrupt from time.c and 432 ** manages when and which chassis LCD/LED gets updated
426 ** updates the chassis LCD/LED
427 433
428 TODO: 434 TODO:
429 - display load average (older machines like 715/64 have 4 "free" LED's for that) 435 - display load average (older machines like 715/64 have 4 "free" LED's for that)
430 - optimizations 436 - optimizations
431 */ 437 */
432 438
433#define HEARTBEAT_LEN (HZ*6/100) 439#define HEARTBEAT_LEN (HZ*10/100)
434#define HEARTBEAT_2ND_RANGE_START (HZ*22/100) 440#define HEARTBEAT_2ND_RANGE_START (HZ*28/100)
435#define HEARTBEAT_2ND_RANGE_END (HEARTBEAT_2ND_RANGE_START + HEARTBEAT_LEN) 441#define HEARTBEAT_2ND_RANGE_END (HEARTBEAT_2ND_RANGE_START + HEARTBEAT_LEN)
436 442
437#define NORMALIZED_COUNT(count) (count/(HZ/100)) 443#define LED_UPDATE_INTERVAL (1 + (HZ*19/1000))
438 444
439static void led_tasklet_func(unsigned long unused) 445static void led_work_func (void *unused)
440{ 446{
441 static unsigned char lastleds; 447 static unsigned long last_jiffies;
442 unsigned char currentleds; /* stores current value of the LEDs */
443 static unsigned long count; /* static incremented value, not wrapped */
444 static unsigned long count_HZ; /* counter in range 0..HZ */ 448 static unsigned long count_HZ; /* counter in range 0..HZ */
449 unsigned char currentleds = 0; /* stores current value of the LEDs */
445 450
446 /* exit if not initialized */ 451 /* exit if not initialized */
447 if (!led_func_ptr) 452 if (!led_func_ptr)
448 return; 453 return;
449 454
450 /* increment the local counters */ 455 /* increment the heartbeat timekeeper */
451 ++count; 456 count_HZ += jiffies - last_jiffies;
452 if (++count_HZ == HZ) 457 last_jiffies = jiffies;
458 if (count_HZ >= HZ)
453 count_HZ = 0; 459 count_HZ = 0;
454 460
455 currentleds = lastleds; 461 if (likely(led_heartbeat))
456
457 if (led_heartbeat)
458 {
459 /* flash heartbeat-LED like a real heart (2 x short then a long delay) */
460 if (count_HZ<HEARTBEAT_LEN ||
461 (count_HZ>=HEARTBEAT_2ND_RANGE_START && count_HZ<HEARTBEAT_2ND_RANGE_END))
462 currentleds |= LED_HEARTBEAT;
463 else
464 currentleds &= ~LED_HEARTBEAT;
465 }
466
467 /* look for network activity and flash LEDs respectively */
468 if (led_lanrxtx && ((NORMALIZED_COUNT(count)+(8/2)) & 7) == 0)
469 { 462 {
470 currentleds &= ~(LED_LAN_RCV | LED_LAN_TX); 463 /* flash heartbeat-LED like a real heart
471 currentleds |= led_get_net_activity(); 464 * (2 x short then a long delay)
465 */
466 if (count_HZ < HEARTBEAT_LEN ||
467 (count_HZ >= HEARTBEAT_2ND_RANGE_START &&
468 count_HZ < HEARTBEAT_2ND_RANGE_END))
469 currentleds |= LED_HEARTBEAT;
472 } 470 }
473 471
474 /* avoid to calculate diskio-stats at same irq as netio-stats */ 472 if (likely(led_lanrxtx)) currentleds |= led_get_net_activity();
475 if (led_diskio && (NORMALIZED_COUNT(count) & 7) == 0) 473 if (likely(led_diskio)) currentleds |= led_get_diskio_activity();
476 {
477 currentleds &= ~LED_DISK_IO;
478 currentleds |= led_get_diskio_activity();
479 }
480 474
481 /* blink all LEDs twice a second if we got an Oops (HPMC) */ 475 /* blink all LEDs twice a second if we got an Oops (HPMC) */
482 if (oops_in_progress) { 476 if (unlikely(oops_in_progress))
483 currentleds = (count_HZ<=(HZ/2)) ? 0 : 0xff; 477 currentleds = (count_HZ<=(HZ/2)) ? 0 : 0xff;
484 }
485
486 /* update the LCD/LEDs */
487 if (currentleds != lastleds) {
488 led_func_ptr(currentleds);
489 lastleds = currentleds;
490 }
491}
492 478
493/* main led tasklet struct (scheduled from time.c) */ 479 if (currentleds != lastleds)
494DECLARE_TASKLET_DISABLED(led_tasklet, led_tasklet_func, 0); 480 {
481 led_func_ptr(currentleds); /* Update the LCD/LEDs */
482 lastleds = currentleds;
483 }
495 484
485 queue_delayed_work(led_wq, &led_task, LED_UPDATE_INTERVAL);
486}
496 487
497/* 488/*
498 ** led_halt() 489 ** led_halt()
@@ -522,9 +513,13 @@ static int led_halt(struct notifier_block *nb, unsigned long event, void *buf)
522 default: return NOTIFY_DONE; 513 default: return NOTIFY_DONE;
523 } 514 }
524 515
525 /* completely stop the LED/LCD tasklet */ 516 /* Cancel the work item and delete the queue */
526 tasklet_disable(&led_tasklet); 517 if (led_wq) {
527 518 cancel_rearming_delayed_workqueue(led_wq, &led_task);
519 destroy_workqueue(led_wq);
520 led_wq = NULL;
521 }
522
528 if (lcd_info.model == DISPLAY_MODEL_LCD) 523 if (lcd_info.model == DISPLAY_MODEL_LCD)
529 lcd_print(txt); 524 lcd_print(txt);
530 else 525 else
@@ -559,7 +554,6 @@ int __init register_led_driver(int model, unsigned long cmd_reg, unsigned long d
559 printk(KERN_INFO "LCD display at %lx,%lx registered\n", 554 printk(KERN_INFO "LCD display at %lx,%lx registered\n",
560 LCD_CMD_REG , LCD_DATA_REG); 555 LCD_CMD_REG , LCD_DATA_REG);
561 led_func_ptr = led_LCD_driver; 556 led_func_ptr = led_LCD_driver;
562 lcd_print( lcd_text_default );
563 led_type = LED_HASLCD; 557 led_type = LED_HASLCD;
564 break; 558 break;
565 559
@@ -589,9 +583,11 @@ int __init register_led_driver(int model, unsigned long cmd_reg, unsigned long d
589 initialized++; 583 initialized++;
590 register_reboot_notifier(&led_notifier); 584 register_reboot_notifier(&led_notifier);
591 585
592 /* start the led tasklet for the first time */ 586 /* Ensure the work is queued */
593 tasklet_enable(&led_tasklet); 587 if (led_wq) {
594 588 queue_work(led_wq, &led_task);
589 }
590
595 return 0; 591 return 0;
596} 592}
597 593
@@ -626,8 +622,8 @@ void __init register_led_regions(void)
626 ** lcd_print() 622 ** lcd_print()
627 ** 623 **
628 ** Displays the given string on the LCD-Display of newer machines. 624 ** Displays the given string on the LCD-Display of newer machines.
629 ** lcd_print() disables the timer-based led tasklet during its 625 ** lcd_print() disables/enables the timer-based led work queue to
630 ** execution and enables it afterwards again. 626 ** avoid a race condition while writing the CMD/DATA register pair.
631 ** 627 **
632 */ 628 */
633int lcd_print( char *str ) 629int lcd_print( char *str )
@@ -637,12 +633,13 @@ int lcd_print( char *str )
637 if (!led_func_ptr || lcd_info.model != DISPLAY_MODEL_LCD) 633 if (!led_func_ptr || lcd_info.model != DISPLAY_MODEL_LCD)
638 return 0; 634 return 0;
639 635
640 /* temporarily disable the led tasklet */ 636 /* temporarily disable the led work task */
641 tasklet_disable(&led_tasklet); 637 if (led_wq)
638 cancel_rearming_delayed_workqueue(led_wq, &led_task);
642 639
643 /* copy display string to buffer for procfs */ 640 /* copy display string to buffer for procfs */
644 strlcpy(lcd_text, str, sizeof(lcd_text)); 641 strlcpy(lcd_text, str, sizeof(lcd_text));
645 642
646 /* Set LCD Cursor to 1st character */ 643 /* Set LCD Cursor to 1st character */
647 gsc_writeb(lcd_info.reset_cmd1, LCD_CMD_REG); 644 gsc_writeb(lcd_info.reset_cmd1, LCD_CMD_REG);
648 udelay(lcd_info.min_cmd_delay); 645 udelay(lcd_info.min_cmd_delay);
@@ -656,8 +653,10 @@ int lcd_print( char *str )
656 udelay(lcd_info.min_cmd_delay); 653 udelay(lcd_info.min_cmd_delay);
657 } 654 }
658 655
659 /* re-enable the led tasklet */ 656 /* re-queue the work */
660 tasklet_enable(&led_tasklet); 657 if (led_wq) {
658 queue_work(led_wq, &led_task);
659 }
661 660
662 return lcd_info.lcd_width; 661 return lcd_info.lcd_width;
663} 662}
diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
index 67c8f3b44848..273a74179720 100644
--- a/drivers/parisc/pdc_stable.c
+++ b/drivers/parisc/pdc_stable.c
@@ -536,7 +536,7 @@ pdcs_info_read(struct subsystem *entry, char *buf)
536 536
537 out += sprintf(out, "Memory tested: "); 537 out += sprintf(out, "Memory tested: ");
538 if ((result & 0x0F) < 0x0E) 538 if ((result & 0x0F) < 0x0E)
539 out += sprintf(out, "%.3f MB", 0.256*(1<<(result & 0x0F))); 539 out += sprintf(out, "%d kB", (1<<(result & 0x0F))*256);
540 else 540 else
541 out += sprintf(out, "All"); 541 out += sprintf(out, "All");
542 out += sprintf(out, "\n"); 542 out += sprintf(out, "\n");
diff --git a/drivers/parisc/sba_iommu.c b/drivers/parisc/sba_iommu.c
index 82ea68b55df4..c85653f315aa 100644
--- a/drivers/parisc/sba_iommu.c
+++ b/drivers/parisc/sba_iommu.c
@@ -91,8 +91,8 @@ extern struct proc_dir_entry * proc_mckinley_root;
91#define DBG_RES(x...) 91#define DBG_RES(x...)
92#endif 92#endif
93 93
94#if defined(__LP64__) && !defined(CONFIG_PDC_NARROW) 94#if defined(CONFIG_64BIT)
95/* "low end" PA8800 machines use ZX1 chipset */ 95/* "low end" PA8800 machines use ZX1 chipset: PAT PDC and only run 64-bit */
96#define ZX1_SUPPORT 96#define ZX1_SUPPORT
97#endif 97#endif
98 98
@@ -231,7 +231,7 @@ struct ioc {
231 spinlock_t res_lock; 231 spinlock_t res_lock;
232 unsigned int res_bitshift; /* from the LEFT! */ 232 unsigned int res_bitshift; /* from the LEFT! */
233 unsigned int res_size; /* size of resource map in bytes */ 233 unsigned int res_size; /* size of resource map in bytes */
234#if SBA_HINT_SUPPORT 234#ifdef SBA_HINT_SUPPORT
235/* FIXME : DMA HINTs not used */ 235/* FIXME : DMA HINTs not used */
236 unsigned long hint_mask_pdir; /* bits used for DMA hints */ 236 unsigned long hint_mask_pdir; /* bits used for DMA hints */
237 unsigned int hint_shift_pdir; 237 unsigned int hint_shift_pdir;
@@ -294,7 +294,7 @@ static unsigned long piranha_bad_128k = 0;
294/* Looks nice and keeps the compiler happy */ 294/* Looks nice and keeps the compiler happy */
295#define SBA_DEV(d) ((struct sba_device *) (d)) 295#define SBA_DEV(d) ((struct sba_device *) (d))
296 296
297#if SBA_AGP_SUPPORT 297#ifdef SBA_AGP_SUPPORT
298static int reserve_sba_gart = 1; 298static int reserve_sba_gart = 1;
299#endif 299#endif
300 300
@@ -314,7 +314,7 @@ static int reserve_sba_gart = 1;
314#define WRITE_REG32(val, addr) __raw_writel(cpu_to_le32(val), addr) 314#define WRITE_REG32(val, addr) __raw_writel(cpu_to_le32(val), addr)
315#define WRITE_REG64(val, addr) __raw_writeq(cpu_to_le64(val), addr) 315#define WRITE_REG64(val, addr) __raw_writeq(cpu_to_le64(val), addr)
316 316
317#ifdef __LP64__ 317#ifdef CONFIG_64BIT
318#define READ_REG(addr) READ_REG64(addr) 318#define READ_REG(addr) READ_REG64(addr)
319#define WRITE_REG(value, addr) WRITE_REG64(value, addr) 319#define WRITE_REG(value, addr) WRITE_REG64(value, addr)
320#else 320#else
@@ -324,7 +324,7 @@ static int reserve_sba_gart = 1;
324 324
325#ifdef DEBUG_SBA_INIT 325#ifdef DEBUG_SBA_INIT
326 326
327/* NOTE: When __LP64__ isn't defined, READ_REG64() is two 32-bit reads */ 327/* NOTE: When CONFIG_64BIT isn't defined, READ_REG64() is two 32-bit reads */
328 328
329/** 329/**
330 * sba_dump_ranges - debugging only - print ranges assigned to this IOA 330 * sba_dump_ranges - debugging only - print ranges assigned to this IOA
@@ -364,7 +364,7 @@ static void sba_dump_tlb(void __iomem *hpa)
364#else 364#else
365#define sba_dump_ranges(x) 365#define sba_dump_ranges(x)
366#define sba_dump_tlb(x) 366#define sba_dump_tlb(x)
367#endif 367#endif /* DEBUG_SBA_INIT */
368 368
369 369
370#ifdef ASSERT_PDIR_SANITY 370#ifdef ASSERT_PDIR_SANITY
@@ -674,7 +674,7 @@ sba_free_range(struct ioc *ioc, dma_addr_t iova, size_t size)
674* 674*
675***************************************************************/ 675***************************************************************/
676 676
677#if SBA_HINT_SUPPORT 677#ifdef SBA_HINT_SUPPORT
678#define SBA_DMA_HINT(ioc, val) ((val) << (ioc)->hint_shift_pdir) 678#define SBA_DMA_HINT(ioc, val) ((val) << (ioc)->hint_shift_pdir)
679#endif 679#endif
680 680
@@ -743,9 +743,8 @@ sba_io_pdir_entry(u64 *pdir_ptr, space_t sid, unsigned long vba,
743 * (bit #61, big endian), we have to flush and sync every time 743 * (bit #61, big endian), we have to flush and sync every time
744 * IO-PDIR is changed in Ike/Astro. 744 * IO-PDIR is changed in Ike/Astro.
745 */ 745 */
746 if (ioc_needs_fdc) { 746 if (ioc_needs_fdc)
747 asm volatile("fdc 0(%%sr1,%0)\n\tsync" : : "r" (pdir_ptr)); 747 asm volatile("fdc %%r0(%0)" : : "r" (pdir_ptr));
748 }
749} 748}
750 749
751 750
@@ -769,42 +768,57 @@ static SBA_INLINE void
769sba_mark_invalid(struct ioc *ioc, dma_addr_t iova, size_t byte_cnt) 768sba_mark_invalid(struct ioc *ioc, dma_addr_t iova, size_t byte_cnt)
770{ 769{
771 u32 iovp = (u32) SBA_IOVP(ioc,iova); 770 u32 iovp = (u32) SBA_IOVP(ioc,iova);
772 771 u64 *pdir_ptr = &ioc->pdir_base[PDIR_INDEX(iovp)];
773 /* Even though this is a big-endian machine, the entries
774 ** in the iopdir are little endian. That's why we clear the byte
775 ** at +7 instead of at +0.
776 */
777 int off = PDIR_INDEX(iovp)*sizeof(u64)+7;
778 772
779#ifdef ASSERT_PDIR_SANITY 773#ifdef ASSERT_PDIR_SANITY
780 /* Assert first pdir entry is set */ 774 /* Assert first pdir entry is set.
781 if (0x80 != (((u8 *) ioc->pdir_base)[off])) { 775 **
776 ** Even though this is a big-endian machine, the entries
777 ** in the iopdir are little endian. That's why we look at
778 ** the byte at +7 instead of at +0.
779 */
780 if (0x80 != (((u8 *) pdir_ptr)[7])) {
782 sba_dump_pdir_entry(ioc,"sba_mark_invalid()", PDIR_INDEX(iovp)); 781 sba_dump_pdir_entry(ioc,"sba_mark_invalid()", PDIR_INDEX(iovp));
783 } 782 }
784#endif 783#endif
785 784
786 if (byte_cnt <= IOVP_SIZE) 785 if (byte_cnt > IOVP_SIZE)
787 { 786 {
788 iovp |= IOVP_SHIFT; /* set "size" field for PCOM */ 787#if 0
788 unsigned long entries_per_cacheline = ioc_needs_fdc ?
789 L1_CACHE_ALIGN(((unsigned long) pdir_ptr))
790 - (unsigned long) pdir_ptr;
791 : 262144;
792#endif
789 793
790 /* 794 /* set "size" field for PCOM */
791 ** clear I/O PDIR entry "valid" bit 795 iovp |= get_order(byte_cnt) + PAGE_SHIFT;
792 ** Do NOT clear the rest - save it for debugging.
793 ** We should only clear bits that have previously
794 ** been enabled.
795 */
796 ((u8 *)(ioc->pdir_base))[off] = 0;
797 } else {
798 u32 t = get_order(byte_cnt) + PAGE_SHIFT;
799 796
800 iovp |= t;
801 do { 797 do {
802 /* clear I/O Pdir entry "valid" bit first */ 798 /* clear I/O Pdir entry "valid" bit first */
803 ((u8 *)(ioc->pdir_base))[off] = 0; 799 ((u8 *) pdir_ptr)[7] = 0;
804 off += sizeof(u64); 800 if (ioc_needs_fdc) {
801 asm volatile("fdc %%r0(%0)" : : "r" (pdir_ptr));
802#if 0
803 entries_per_cacheline = L1_CACHE_SHIFT - 3;
804#endif
805 }
806 pdir_ptr++;
805 byte_cnt -= IOVP_SIZE; 807 byte_cnt -= IOVP_SIZE;
806 } while (byte_cnt > 0); 808 } while (byte_cnt > IOVP_SIZE);
807 } 809 } else
810 iovp |= IOVP_SHIFT; /* set "size" field for PCOM */
811
812 /*
813 ** clear I/O PDIR entry "valid" bit.
814 ** We have to R/M/W the cacheline regardless how much of the
815 ** pdir entry that we clobber.
816 ** The rest of the entry would be useful for debugging if we
817 ** could dump core on HPMC.
818 */
819 ((u8 *) pdir_ptr)[7] = 0;
820 if (ioc_needs_fdc)
821 asm volatile("fdc %%r0(%0)" : : "r" (pdir_ptr));
808 822
809 WRITE_REG( SBA_IOVA(ioc, iovp, 0, 0), ioc->ioc_hpa+IOC_PCOM); 823 WRITE_REG( SBA_IOVA(ioc, iovp, 0, 0), ioc->ioc_hpa+IOC_PCOM);
810} 824}
@@ -819,18 +833,29 @@ sba_mark_invalid(struct ioc *ioc, dma_addr_t iova, size_t byte_cnt)
819static int sba_dma_supported( struct device *dev, u64 mask) 833static int sba_dma_supported( struct device *dev, u64 mask)
820{ 834{
821 struct ioc *ioc; 835 struct ioc *ioc;
836
822 if (dev == NULL) { 837 if (dev == NULL) {
823 printk(KERN_ERR MODULE_NAME ": EISA/ISA/et al not supported\n"); 838 printk(KERN_ERR MODULE_NAME ": EISA/ISA/et al not supported\n");
824 BUG(); 839 BUG();
825 return(0); 840 return(0);
826 } 841 }
827 842
828 ioc = GET_IOC(dev); 843 /* Documentation/DMA-mapping.txt tells drivers to try 64-bit first,
844 * then fall back to 32-bit if that fails.
845 * We are just "encouraging" 32-bit DMA masks here since we can
846 * never allow IOMMU bypass unless we add special support for ZX1.
847 */
848 if (mask > ~0U)
849 return 0;
829 850
830 /* check if mask is > than the largest IO Virt Address */ 851 ioc = GET_IOC(dev);
831 852
832 return((int) (mask >= (ioc->ibase + 853 /*
833 (ioc->pdir_size / sizeof(u64) * IOVP_SIZE) ))); 854 * check if mask is >= than the current max IO Virt Address
855 * The max IO Virt address will *always* < 30 bits.
856 */
857 return((int)(mask >= (ioc->ibase - 1 +
858 (ioc->pdir_size / sizeof(u64) * IOVP_SIZE) )));
834} 859}
835 860
836 861
@@ -898,11 +923,17 @@ sba_map_single(struct device *dev, void *addr, size_t size,
898 size -= IOVP_SIZE; 923 size -= IOVP_SIZE;
899 pdir_start++; 924 pdir_start++;
900 } 925 }
901 /* form complete address */ 926
927 /* force FDC ops in io_pdir_entry() to be visible to IOMMU */
928 if (ioc_needs_fdc)
929 asm volatile("sync" : : );
930
902#ifdef ASSERT_PDIR_SANITY 931#ifdef ASSERT_PDIR_SANITY
903 sba_check_pdir(ioc,"Check after sba_map_single()"); 932 sba_check_pdir(ioc,"Check after sba_map_single()");
904#endif 933#endif
905 spin_unlock_irqrestore(&ioc->res_lock, flags); 934 spin_unlock_irqrestore(&ioc->res_lock, flags);
935
936 /* form complete address */
906 return SBA_IOVA(ioc, iovp, offset, DEFAULT_DMA_HINT_REG); 937 return SBA_IOVA(ioc, iovp, offset, DEFAULT_DMA_HINT_REG);
907} 938}
908 939
@@ -958,12 +989,19 @@ sba_unmap_single(struct device *dev, dma_addr_t iova, size_t size,
958 d--; 989 d--;
959 } 990 }
960 ioc->saved_cnt = 0; 991 ioc->saved_cnt = 0;
992
961 READ_REG(ioc->ioc_hpa+IOC_PCOM); /* flush purges */ 993 READ_REG(ioc->ioc_hpa+IOC_PCOM); /* flush purges */
962 } 994 }
963#else /* DELAYED_RESOURCE_CNT == 0 */ 995#else /* DELAYED_RESOURCE_CNT == 0 */
964 sba_free_range(ioc, iova, size); 996 sba_free_range(ioc, iova, size);
997
998 /* If fdc's were issued, force fdc's to be visible now */
999 if (ioc_needs_fdc)
1000 asm volatile("sync" : : );
1001
965 READ_REG(ioc->ioc_hpa+IOC_PCOM); /* flush purges */ 1002 READ_REG(ioc->ioc_hpa+IOC_PCOM); /* flush purges */
966#endif /* DELAYED_RESOURCE_CNT == 0 */ 1003#endif /* DELAYED_RESOURCE_CNT == 0 */
1004
967 spin_unlock_irqrestore(&ioc->res_lock, flags); 1005 spin_unlock_irqrestore(&ioc->res_lock, flags);
968 1006
969 /* XXX REVISIT for 2.5 Linux - need syncdma for zero-copy support. 1007 /* XXX REVISIT for 2.5 Linux - need syncdma for zero-copy support.
@@ -986,7 +1024,7 @@ sba_unmap_single(struct device *dev, dma_addr_t iova, size_t size,
986 * See Documentation/DMA-mapping.txt 1024 * See Documentation/DMA-mapping.txt
987 */ 1025 */
988static void *sba_alloc_consistent(struct device *hwdev, size_t size, 1026static void *sba_alloc_consistent(struct device *hwdev, size_t size,
989 dma_addr_t *dma_handle, int gfp) 1027 dma_addr_t *dma_handle, gfp_t gfp)
990{ 1028{
991 void *ret; 1029 void *ret;
992 1030
@@ -1106,6 +1144,10 @@ sba_map_sg(struct device *dev, struct scatterlist *sglist, int nents,
1106 */ 1144 */
1107 filled = iommu_fill_pdir(ioc, sglist, nents, 0, sba_io_pdir_entry); 1145 filled = iommu_fill_pdir(ioc, sglist, nents, 0, sba_io_pdir_entry);
1108 1146
1147 /* force FDC ops in io_pdir_entry() to be visible to IOMMU */
1148 if (ioc_needs_fdc)
1149 asm volatile("sync" : : );
1150
1109#ifdef ASSERT_PDIR_SANITY 1151#ifdef ASSERT_PDIR_SANITY
1110 if (sba_check_pdir(ioc,"Check after sba_map_sg()")) 1152 if (sba_check_pdir(ioc,"Check after sba_map_sg()"))
1111 { 1153 {
@@ -1234,8 +1276,10 @@ sba_alloc_pdir(unsigned int pdir_size)
1234 unsigned long pdir_order = get_order(pdir_size); 1276 unsigned long pdir_order = get_order(pdir_size);
1235 1277
1236 pdir_base = __get_free_pages(GFP_KERNEL, pdir_order); 1278 pdir_base = __get_free_pages(GFP_KERNEL, pdir_order);
1237 if (NULL == (void *) pdir_base) 1279 if (NULL == (void *) pdir_base) {
1238 panic("sba_ioc_init() could not allocate I/O Page Table\n"); 1280 panic("%s() could not allocate I/O Page Table\n",
1281 __FUNCTION__);
1282 }
1239 1283
1240 /* If this is not PA8700 (PCX-W2) 1284 /* If this is not PA8700 (PCX-W2)
1241 ** OR newer than ver 2.2 1285 ** OR newer than ver 2.2
@@ -1322,19 +1366,29 @@ sba_alloc_pdir(unsigned int pdir_size)
1322 return (void *) pdir_base; 1366 return (void *) pdir_base;
1323} 1367}
1324 1368
1369static struct device *next_device(struct klist_iter *i)
1370{
1371 struct klist_node * n = klist_next(i);
1372 return n ? container_of(n, struct device, knode_parent) : NULL;
1373}
1374
1325/* setup Mercury or Elroy IBASE/IMASK registers. */ 1375/* setup Mercury or Elroy IBASE/IMASK registers. */
1326static void setup_ibase_imask(struct parisc_device *sba, struct ioc *ioc, int ioc_num) 1376static void
1377setup_ibase_imask(struct parisc_device *sba, struct ioc *ioc, int ioc_num)
1327{ 1378{
1328 /* lba_set_iregs() is in drivers/parisc/lba_pci.c */ 1379 /* lba_set_iregs() is in drivers/parisc/lba_pci.c */
1329 extern void lba_set_iregs(struct parisc_device *, u32, u32); 1380 extern void lba_set_iregs(struct parisc_device *, u32, u32);
1330 struct device *dev; 1381 struct device *dev;
1382 struct klist_iter i;
1331 1383
1332 list_for_each_entry(dev, &sba->dev.children, node) { 1384 klist_iter_init(&sba->dev.klist_children, &i);
1385 while ((dev = next_device(&i))) {
1333 struct parisc_device *lba = to_parisc_device(dev); 1386 struct parisc_device *lba = to_parisc_device(dev);
1334 int rope_num = (lba->hpa >> 13) & 0xf; 1387 int rope_num = (lba->hpa.start >> 13) & 0xf;
1335 if (rope_num >> 3 == ioc_num) 1388 if (rope_num >> 3 == ioc_num)
1336 lba_set_iregs(lba, ioc->ibase, ioc->imask); 1389 lba_set_iregs(lba, ioc->ibase, ioc->imask);
1337 } 1390 }
1391 klist_iter_exit(&i);
1338} 1392}
1339 1393
1340static void 1394static void
@@ -1343,7 +1397,7 @@ sba_ioc_init_pluto(struct parisc_device *sba, struct ioc *ioc, int ioc_num)
1343 u32 iova_space_mask; 1397 u32 iova_space_mask;
1344 u32 iova_space_size; 1398 u32 iova_space_size;
1345 int iov_order, tcnfg; 1399 int iov_order, tcnfg;
1346#if SBA_AGP_SUPPORT 1400#ifdef SBA_AGP_SUPPORT
1347 int agp_found = 0; 1401 int agp_found = 0;
1348#endif 1402#endif
1349 /* 1403 /*
@@ -1380,7 +1434,7 @@ sba_ioc_init_pluto(struct parisc_device *sba, struct ioc *ioc, int ioc_num)
1380 DBG_INIT("%s() pdir %p size %x\n", 1434 DBG_INIT("%s() pdir %p size %x\n",
1381 __FUNCTION__, ioc->pdir_base, ioc->pdir_size); 1435 __FUNCTION__, ioc->pdir_base, ioc->pdir_size);
1382 1436
1383#if SBA_HINT_SUPPORT 1437#ifdef SBA_HINT_SUPPORT
1384 ioc->hint_shift_pdir = iov_order + PAGE_SHIFT; 1438 ioc->hint_shift_pdir = iov_order + PAGE_SHIFT;
1385 ioc->hint_mask_pdir = ~(0x3 << (iov_order + PAGE_SHIFT)); 1439 ioc->hint_mask_pdir = ~(0x3 << (iov_order + PAGE_SHIFT));
1386 1440
@@ -1404,7 +1458,7 @@ sba_ioc_init_pluto(struct parisc_device *sba, struct ioc *ioc, int ioc_num)
1404 1458
1405 WRITE_REG(ioc->imask, ioc->ioc_hpa + IOC_IMASK); 1459 WRITE_REG(ioc->imask, ioc->ioc_hpa + IOC_IMASK);
1406 1460
1407#ifdef __LP64__ 1461#ifdef CONFIG_64BIT
1408 /* 1462 /*
1409 ** Setting the upper bits makes checking for bypass addresses 1463 ** Setting the upper bits makes checking for bypass addresses
1410 ** a little faster later on. 1464 ** a little faster later on.
@@ -1437,7 +1491,7 @@ sba_ioc_init_pluto(struct parisc_device *sba, struct ioc *ioc, int ioc_num)
1437 */ 1491 */
1438 WRITE_REG(ioc->ibase | 31, ioc->ioc_hpa + IOC_PCOM); 1492 WRITE_REG(ioc->ibase | 31, ioc->ioc_hpa + IOC_PCOM);
1439 1493
1440#if SBA_AGP_SUPPORT 1494#ifdef SBA_AGP_SUPPORT
1441 /* 1495 /*
1442 ** If an AGP device is present, only use half of the IOV space 1496 ** If an AGP device is present, only use half of the IOV space
1443 ** for PCI DMA. Unfortunately we can't know ahead of time 1497 ** for PCI DMA. Unfortunately we can't know ahead of time
@@ -1489,11 +1543,9 @@ sba_ioc_init(struct parisc_device *sba, struct ioc *ioc, int ioc_num)
1489 if (iova_space_size < (1 << (20 - PAGE_SHIFT))) { 1543 if (iova_space_size < (1 << (20 - PAGE_SHIFT))) {
1490 iova_space_size = 1 << (20 - PAGE_SHIFT); 1544 iova_space_size = 1 << (20 - PAGE_SHIFT);
1491 } 1545 }
1492#ifdef __LP64__
1493 else if (iova_space_size > (1 << (30 - PAGE_SHIFT))) { 1546 else if (iova_space_size > (1 << (30 - PAGE_SHIFT))) {
1494 iova_space_size = 1 << (30 - PAGE_SHIFT); 1547 iova_space_size = 1 << (30 - PAGE_SHIFT);
1495 } 1548 }
1496#endif
1497 1549
1498 /* 1550 /*
1499 ** iova space must be log2() in size. 1551 ** iova space must be log2() in size.
@@ -1519,7 +1571,7 @@ sba_ioc_init(struct parisc_device *sba, struct ioc *ioc, int ioc_num)
1519 DBG_INIT("%s() pdir %p size %x\n", 1571 DBG_INIT("%s() pdir %p size %x\n",
1520 __FUNCTION__, ioc->pdir_base, pdir_size); 1572 __FUNCTION__, ioc->pdir_base, pdir_size);
1521 1573
1522#if SBA_HINT_SUPPORT 1574#ifdef SBA_HINT_SUPPORT
1523 /* FIXME : DMA HINTs not used */ 1575 /* FIXME : DMA HINTs not used */
1524 ioc->hint_shift_pdir = iov_order + PAGE_SHIFT; 1576 ioc->hint_shift_pdir = iov_order + PAGE_SHIFT;
1525 ioc->hint_mask_pdir = ~(0x3 << (iov_order + PAGE_SHIFT)); 1577 ioc->hint_mask_pdir = ~(0x3 << (iov_order + PAGE_SHIFT));
@@ -1590,7 +1642,7 @@ sba_ioc_init(struct parisc_device *sba, struct ioc *ioc, int ioc_num)
1590 1642
1591static void __iomem *ioc_remap(struct sba_device *sba_dev, int offset) 1643static void __iomem *ioc_remap(struct sba_device *sba_dev, int offset)
1592{ 1644{
1593 return ioremap(sba_dev->dev->hpa + offset, SBA_FUNC_SIZE); 1645 return ioremap(sba_dev->dev->hpa.start + offset, SBA_FUNC_SIZE);
1594} 1646}
1595 1647
1596static void sba_hw_init(struct sba_device *sba_dev) 1648static void sba_hw_init(struct sba_device *sba_dev)
@@ -1968,7 +2020,7 @@ sba_driver_callback(struct parisc_device *dev)
1968 u32 func_class; 2020 u32 func_class;
1969 int i; 2021 int i;
1970 char *version; 2022 char *version;
1971 void __iomem *sba_addr = ioremap(dev->hpa, SBA_FUNC_SIZE); 2023 void __iomem *sba_addr = ioremap(dev->hpa.start, SBA_FUNC_SIZE);
1972 2024
1973 sba_dump_ranges(sba_addr); 2025 sba_dump_ranges(sba_addr);
1974 2026
@@ -2010,7 +2062,7 @@ sba_driver_callback(struct parisc_device *dev)
2010 } 2062 }
2011 2063
2012 printk(KERN_INFO "%s found %s at 0x%lx\n", 2064 printk(KERN_INFO "%s found %s at 0x%lx\n",
2013 MODULE_NAME, version, dev->hpa); 2065 MODULE_NAME, version, dev->hpa.start);
2014 2066
2015 sba_dev = kmalloc(sizeof(struct sba_device), GFP_KERNEL); 2067 sba_dev = kmalloc(sizeof(struct sba_device), GFP_KERNEL);
2016 if (!sba_dev) { 2068 if (!sba_dev) {
diff --git a/drivers/parisc/superio.c b/drivers/parisc/superio.c
index e0efed796b92..bab3bcabcb6e 100644
--- a/drivers/parisc/superio.c
+++ b/drivers/parisc/superio.c
@@ -11,6 +11,7 @@
11 * (C) Copyright 2000 Alex deVries <alex@onefishtwo.ca> 11 * (C) Copyright 2000 Alex deVries <alex@onefishtwo.ca>
12 * (C) Copyright 2001 John Marvin <jsm fc hp com> 12 * (C) Copyright 2001 John Marvin <jsm fc hp com>
13 * (C) Copyright 2003 Grant Grundler <grundler parisc-linux org> 13 * (C) Copyright 2003 Grant Grundler <grundler parisc-linux org>
14 * (C) Copyright 2005 Kyle McMartin <kyle@parisc-linux.org>
14 * 15 *
15 * This program is free software; you can redistribute it and/or 16 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as 17 * modify it under the terms of the GNU General Public License as
@@ -405,6 +406,7 @@ static void __devinit superio_serial_init(void)
405 406
406 serial[0].iobase = sio_dev.sp1_base; 407 serial[0].iobase = sio_dev.sp1_base;
407 serial[0].irq = SP1_IRQ; 408 serial[0].irq = SP1_IRQ;
409 spin_lock_init(&serial[0].lock);
408 410
409 retval = early_serial_setup(&serial[0]); 411 retval = early_serial_setup(&serial[0]);
410 if (retval < 0) { 412 if (retval < 0) {
@@ -414,6 +416,7 @@ static void __devinit superio_serial_init(void)
414 416
415 serial[1].iobase = sio_dev.sp2_base; 417 serial[1].iobase = sio_dev.sp2_base;
416 serial[1].irq = SP2_IRQ; 418 serial[1].irq = SP2_IRQ;
419 spin_lock_init(&serial[1].lock);
417 retval = early_serial_setup(&serial[1]); 420 retval = early_serial_setup(&serial[1]);
418 421
419 if (retval < 0) 422 if (retval < 0)
diff --git a/drivers/parisc/wax.c b/drivers/parisc/wax.c
index e547d7d024d8..17dce2adf7fe 100644
--- a/drivers/parisc/wax.c
+++ b/drivers/parisc/wax.c
@@ -81,7 +81,7 @@ wax_init_chip(struct parisc_device *dev)
81 return -ENOMEM; 81 return -ENOMEM;
82 82
83 wax->name = "wax"; 83 wax->name = "wax";
84 wax->hpa = dev->hpa; 84 wax->hpa = dev->hpa.start;
85 85
86 wax->version = 0; /* gsc_readb(wax->hpa+WAX_VER); */ 86 wax->version = 0; /* gsc_readb(wax->hpa+WAX_VER); */
87 printk(KERN_INFO "%s at 0x%lx found.\n", wax->name, wax->hpa); 87 printk(KERN_INFO "%s at 0x%lx found.\n", wax->name, wax->hpa);
diff --git a/drivers/parport/parport_gsc.c b/drivers/parport/parport_gsc.c
index 02d72acd1c89..fde29a75f888 100644
--- a/drivers/parport/parport_gsc.c
+++ b/drivers/parport/parport_gsc.c
@@ -359,11 +359,12 @@ static int __devinit parport_init_chip(struct parisc_device *dev)
359 unsigned long port; 359 unsigned long port;
360 360
361 if (!dev->irq) { 361 if (!dev->irq) {
362 printk("IRQ not found for parallel device at 0x%lx\n", dev->hpa); 362 printk(KERN_WARNING "IRQ not found for parallel device at 0x%lx\n",
363 dev->hpa.start);
363 return -ENODEV; 364 return -ENODEV;
364 } 365 }
365 366
366 port = dev->hpa + PARPORT_GSC_OFFSET; 367 port = dev->hpa.start + PARPORT_GSC_OFFSET;
367 368
368 /* some older machines with ASP-chip don't support 369 /* some older machines with ASP-chip don't support
369 * the enhanced parport modes. 370 * the enhanced parport modes.
diff --git a/drivers/pci/access.c b/drivers/pci/access.c
index 24a76de49f41..2a42add7f563 100644
--- a/drivers/pci/access.c
+++ b/drivers/pci/access.c
@@ -60,3 +60,92 @@ EXPORT_SYMBOL(pci_bus_read_config_dword);
60EXPORT_SYMBOL(pci_bus_write_config_byte); 60EXPORT_SYMBOL(pci_bus_write_config_byte);
61EXPORT_SYMBOL(pci_bus_write_config_word); 61EXPORT_SYMBOL(pci_bus_write_config_word);
62EXPORT_SYMBOL(pci_bus_write_config_dword); 62EXPORT_SYMBOL(pci_bus_write_config_dword);
63
64static u32 pci_user_cached_config(struct pci_dev *dev, int pos)
65{
66 u32 data;
67
68 data = dev->saved_config_space[pos/sizeof(dev->saved_config_space[0])];
69 data >>= (pos % sizeof(dev->saved_config_space[0])) * 8;
70 return data;
71}
72
73#define PCI_USER_READ_CONFIG(size,type) \
74int pci_user_read_config_##size \
75 (struct pci_dev *dev, int pos, type *val) \
76{ \
77 unsigned long flags; \
78 int ret = 0; \
79 u32 data = -1; \
80 if (PCI_##size##_BAD) return PCIBIOS_BAD_REGISTER_NUMBER; \
81 spin_lock_irqsave(&pci_lock, flags); \
82 if (likely(!dev->block_ucfg_access)) \
83 ret = dev->bus->ops->read(dev->bus, dev->devfn, \
84 pos, sizeof(type), &data); \
85 else if (pos < sizeof(dev->saved_config_space)) \
86 data = pci_user_cached_config(dev, pos); \
87 spin_unlock_irqrestore(&pci_lock, flags); \
88 *val = (type)data; \
89 return ret; \
90}
91
92#define PCI_USER_WRITE_CONFIG(size,type) \
93int pci_user_write_config_##size \
94 (struct pci_dev *dev, int pos, type val) \
95{ \
96 unsigned long flags; \
97 int ret = -EIO; \
98 if (PCI_##size##_BAD) return PCIBIOS_BAD_REGISTER_NUMBER; \
99 spin_lock_irqsave(&pci_lock, flags); \
100 if (likely(!dev->block_ucfg_access)) \
101 ret = dev->bus->ops->write(dev->bus, dev->devfn, \
102 pos, sizeof(type), val); \
103 spin_unlock_irqrestore(&pci_lock, flags); \
104 return ret; \
105}
106
107PCI_USER_READ_CONFIG(byte, u8)
108PCI_USER_READ_CONFIG(word, u16)
109PCI_USER_READ_CONFIG(dword, u32)
110PCI_USER_WRITE_CONFIG(byte, u8)
111PCI_USER_WRITE_CONFIG(word, u16)
112PCI_USER_WRITE_CONFIG(dword, u32)
113
114/**
115 * pci_block_user_cfg_access - Block userspace PCI config reads/writes
116 * @dev: pci device struct
117 *
118 * This function blocks any userspace PCI config accesses from occurring.
119 * When blocked, any writes will be bit bucketed and reads will return the
120 * data saved using pci_save_state for the first 64 bytes of config
121 * space and return 0xff for all other config reads.
122 **/
123void pci_block_user_cfg_access(struct pci_dev *dev)
124{
125 unsigned long flags;
126
127 pci_save_state(dev);
128
129 /* spinlock to synchronize with anyone reading config space now */
130 spin_lock_irqsave(&pci_lock, flags);
131 dev->block_ucfg_access = 1;
132 spin_unlock_irqrestore(&pci_lock, flags);
133}
134EXPORT_SYMBOL_GPL(pci_block_user_cfg_access);
135
136/**
137 * pci_unblock_user_cfg_access - Unblock userspace PCI config reads/writes
138 * @dev: pci device struct
139 *
140 * This function allows userspace PCI config accesses to resume.
141 **/
142void pci_unblock_user_cfg_access(struct pci_dev *dev)
143{
144 unsigned long flags;
145
146 /* spinlock to synchronize with anyone reading saved config space */
147 spin_lock_irqsave(&pci_lock, flags);
148 dev->block_ucfg_access = 0;
149 spin_unlock_irqrestore(&pci_lock, flags);
150}
151EXPORT_SYMBOL_GPL(pci_unblock_user_cfg_access);
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 424e7de181ae..8e21f6ab89a1 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -58,6 +58,9 @@ static LIST_HEAD(bridge_list);
58 58
59static void handle_hotplug_event_bridge (acpi_handle, u32, void *); 59static void handle_hotplug_event_bridge (acpi_handle, u32, void *);
60static void handle_hotplug_event_func (acpi_handle, u32, void *); 60static void handle_hotplug_event_func (acpi_handle, u32, void *);
61static void acpiphp_sanitize_bus(struct pci_bus *bus);
62static void acpiphp_set_hpp_values(acpi_handle handle, struct pci_bus *bus);
63
61 64
62/* 65/*
63 * initialization & terminatation routines 66 * initialization & terminatation routines
@@ -796,8 +799,13 @@ static int enable_device(struct acpiphp_slot *slot)
796 } 799 }
797 } 800 }
798 801
802 pci_bus_size_bridges(bus);
799 pci_bus_assign_resources(bus); 803 pci_bus_assign_resources(bus);
804 acpiphp_sanitize_bus(bus);
805 pci_enable_bridges(bus);
800 pci_bus_add_devices(bus); 806 pci_bus_add_devices(bus);
807 acpiphp_set_hpp_values(DEVICE_ACPI_HANDLE(&bus->self->dev), bus);
808 acpiphp_configure_ioapics(DEVICE_ACPI_HANDLE(&bus->self->dev));
801 809
802 /* associate pci_dev to our representation */ 810 /* associate pci_dev to our representation */
803 list_for_each (l, &slot->funcs) { 811 list_for_each (l, &slot->funcs) {
diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
index a62a4345b466..2d4639d6841f 100644
--- a/drivers/pci/hotplug/cpcihp_generic.c
+++ b/drivers/pci/hotplug/cpcihp_generic.c
@@ -39,6 +39,7 @@
39#include <linux/init.h> 39#include <linux/init.h>
40#include <linux/errno.h> 40#include <linux/errno.h>
41#include <linux/pci.h> 41#include <linux/pci.h>
42#include <linux/string.h>
42#include "cpci_hotplug.h" 43#include "cpci_hotplug.h"
43 44
44#define DRIVER_VERSION "0.1" 45#define DRIVER_VERSION "0.1"
diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
index e9928024be78..f7cb00da38df 100644
--- a/drivers/pci/hotplug/cpcihp_zt5550.c
+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
@@ -36,6 +36,7 @@
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/errno.h> 37#include <linux/errno.h>
38#include <linux/pci.h> 38#include <linux/pci.h>
39#include <linux/signal.h> /* SA_SHIRQ */
39#include "cpci_hotplug.h" 40#include "cpci_hotplug.h"
40#include "cpcihp_zt5550.h" 41#include "cpcihp_zt5550.h"
41 42
@@ -78,11 +79,20 @@ static void __iomem *csr_int_mask;
78 79
79static int zt5550_hc_config(struct pci_dev *pdev) 80static int zt5550_hc_config(struct pci_dev *pdev)
80{ 81{
82 int ret;
83
81 /* Since we know that no boards exist with two HC chips, treat it as an error */ 84 /* Since we know that no boards exist with two HC chips, treat it as an error */
82 if(hc_dev) { 85 if(hc_dev) {
83 err("too many host controller devices?"); 86 err("too many host controller devices?");
84 return -EBUSY; 87 return -EBUSY;
85 } 88 }
89
90 ret = pci_enable_device(pdev);
91 if(ret) {
92 err("cannot enable %s\n", pci_name(pdev));
93 return ret;
94 }
95
86 hc_dev = pdev; 96 hc_dev = pdev;
87 dbg("hc_dev = %p", hc_dev); 97 dbg("hc_dev = %p", hc_dev);
88 dbg("pci resource start %lx", pci_resource_start(hc_dev, 1)); 98 dbg("pci resource start %lx", pci_resource_start(hc_dev, 1));
@@ -91,7 +101,8 @@ static int zt5550_hc_config(struct pci_dev *pdev)
91 if(!request_mem_region(pci_resource_start(hc_dev, 1), 101 if(!request_mem_region(pci_resource_start(hc_dev, 1),
92 pci_resource_len(hc_dev, 1), MY_NAME)) { 102 pci_resource_len(hc_dev, 1), MY_NAME)) {
93 err("cannot reserve MMIO region"); 103 err("cannot reserve MMIO region");
94 return -ENOMEM; 104 ret = -ENOMEM;
105 goto exit_disable_device;
95 } 106 }
96 107
97 hc_registers = 108 hc_registers =
@@ -99,9 +110,8 @@ static int zt5550_hc_config(struct pci_dev *pdev)
99 if(!hc_registers) { 110 if(!hc_registers) {
100 err("cannot remap MMIO region %lx @ %lx", 111 err("cannot remap MMIO region %lx @ %lx",
101 pci_resource_len(hc_dev, 1), pci_resource_start(hc_dev, 1)); 112 pci_resource_len(hc_dev, 1), pci_resource_start(hc_dev, 1));
102 release_mem_region(pci_resource_start(hc_dev, 1), 113 ret = -ENODEV;
103 pci_resource_len(hc_dev, 1)); 114 goto exit_release_region;
104 return -ENODEV;
105 } 115 }
106 116
107 csr_hc_index = hc_registers + CSR_HCINDEX; 117 csr_hc_index = hc_registers + CSR_HCINDEX;
@@ -124,6 +134,13 @@ static int zt5550_hc_config(struct pci_dev *pdev)
124 writeb((u8) ALL_DIRECT_INTS_MASK, csr_int_mask); 134 writeb((u8) ALL_DIRECT_INTS_MASK, csr_int_mask);
125 dbg("disabled timer0, timer1 and ENUM interrupts"); 135 dbg("disabled timer0, timer1 and ENUM interrupts");
126 return 0; 136 return 0;
137
138exit_release_region:
139 release_mem_region(pci_resource_start(hc_dev, 1),
140 pci_resource_len(hc_dev, 1));
141exit_disable_device:
142 pci_disable_device(hc_dev);
143 return ret;
127} 144}
128 145
129static int zt5550_hc_cleanup(void) 146static int zt5550_hc_cleanup(void)
@@ -134,6 +151,7 @@ static int zt5550_hc_cleanup(void)
134 iounmap(hc_registers); 151 iounmap(hc_registers);
135 release_mem_region(pci_resource_start(hc_dev, 1), 152 release_mem_region(pci_resource_start(hc_dev, 1),
136 pci_resource_len(hc_dev, 1)); 153 pci_resource_len(hc_dev, 1));
154 pci_disable_device(hc_dev);
137 return 0; 155 return 0;
138} 156}
139 157
diff --git a/drivers/pci/hotplug/cpqphp_core.c b/drivers/pci/hotplug/cpqphp_core.c
index 8c6d3987d461..9aed8efe6a11 100644
--- a/drivers/pci/hotplug/cpqphp_core.c
+++ b/drivers/pci/hotplug/cpqphp_core.c
@@ -794,12 +794,21 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
794 u32 rc; 794 u32 rc;
795 struct controller *ctrl; 795 struct controller *ctrl;
796 struct pci_func *func; 796 struct pci_func *func;
797 int err;
798
799 err = pci_enable_device(pdev);
800 if (err) {
801 printk(KERN_ERR MY_NAME ": cannot enable PCI device %s (%d)\n",
802 pci_name(pdev), err);
803 return err;
804 }
797 805
798 // Need to read VID early b/c it's used to differentiate CPQ and INTC discovery 806 // Need to read VID early b/c it's used to differentiate CPQ and INTC discovery
799 rc = pci_read_config_word(pdev, PCI_VENDOR_ID, &vendor_id); 807 rc = pci_read_config_word(pdev, PCI_VENDOR_ID, &vendor_id);
800 if (rc || ((vendor_id != PCI_VENDOR_ID_COMPAQ) && (vendor_id != PCI_VENDOR_ID_INTEL))) { 808 if (rc || ((vendor_id != PCI_VENDOR_ID_COMPAQ) && (vendor_id != PCI_VENDOR_ID_INTEL))) {
801 err(msg_HPC_non_compaq_or_intel); 809 err(msg_HPC_non_compaq_or_intel);
802 return -ENODEV; 810 rc = -ENODEV;
811 goto err_disable_device;
803 } 812 }
804 dbg("Vendor ID: %x\n", vendor_id); 813 dbg("Vendor ID: %x\n", vendor_id);
805 814
@@ -807,7 +816,8 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
807 dbg("revision: %d\n", rev); 816 dbg("revision: %d\n", rev);
808 if (rc || ((vendor_id == PCI_VENDOR_ID_COMPAQ) && (!rev))) { 817 if (rc || ((vendor_id == PCI_VENDOR_ID_COMPAQ) && (!rev))) {
809 err(msg_HPC_rev_error); 818 err(msg_HPC_rev_error);
810 return -ENODEV; 819 rc = -ENODEV;
820 goto err_disable_device;
811 } 821 }
812 822
813 /* Check for the proper subsytem ID's 823 /* Check for the proper subsytem ID's
@@ -820,18 +830,20 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
820 rc = pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vid); 830 rc = pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vid);
821 if (rc) { 831 if (rc) {
822 err("%s : pci_read_config_word failed\n", __FUNCTION__); 832 err("%s : pci_read_config_word failed\n", __FUNCTION__);
823 return rc; 833 goto err_disable_device;
824 } 834 }
825 dbg("Subsystem Vendor ID: %x\n", subsystem_vid); 835 dbg("Subsystem Vendor ID: %x\n", subsystem_vid);
826 if ((subsystem_vid != PCI_VENDOR_ID_COMPAQ) && (subsystem_vid != PCI_VENDOR_ID_INTEL)) { 836 if ((subsystem_vid != PCI_VENDOR_ID_COMPAQ) && (subsystem_vid != PCI_VENDOR_ID_INTEL)) {
827 err(msg_HPC_non_compaq_or_intel); 837 err(msg_HPC_non_compaq_or_intel);
828 return -ENODEV; 838 rc = -ENODEV;
839 goto err_disable_device;
829 } 840 }
830 841
831 ctrl = (struct controller *) kmalloc(sizeof(struct controller), GFP_KERNEL); 842 ctrl = (struct controller *) kmalloc(sizeof(struct controller), GFP_KERNEL);
832 if (!ctrl) { 843 if (!ctrl) {
833 err("%s : out of memory\n", __FUNCTION__); 844 err("%s : out of memory\n", __FUNCTION__);
834 return -ENOMEM; 845 rc = -ENOMEM;
846 goto err_disable_device;
835 } 847 }
836 memset(ctrl, 0, sizeof(struct controller)); 848 memset(ctrl, 0, sizeof(struct controller));
837 849
@@ -1264,6 +1276,8 @@ err_free_bus:
1264 kfree(ctrl->pci_bus); 1276 kfree(ctrl->pci_bus);
1265err_free_ctrl: 1277err_free_ctrl:
1266 kfree(ctrl); 1278 kfree(ctrl);
1279err_disable_device:
1280 pci_disable_device(pdev);
1267 return rc; 1281 return rc;
1268} 1282}
1269 1283
diff --git a/drivers/pci/hotplug/fakephp.c b/drivers/pci/hotplug/fakephp.c
index 8e47fa66e25e..060d74775d7b 100644
--- a/drivers/pci/hotplug/fakephp.c
+++ b/drivers/pci/hotplug/fakephp.c
@@ -37,6 +37,8 @@
37#include <linux/module.h> 37#include <linux/module.h>
38#include <linux/pci.h> 38#include <linux/pci.h>
39#include <linux/init.h> 39#include <linux/init.h>
40#include <linux/string.h>
41#include <linux/slab.h>
40#include "pci_hotplug.h" 42#include "pci_hotplug.h"
41#include "../pci.h" 43#include "../pci.h"
42 44
diff --git a/drivers/pci/hotplug/ibmphp_core.c b/drivers/pci/hotplug/ibmphp_core.c
index 0392e004258f..aabf1e70b528 100644
--- a/drivers/pci/hotplug/ibmphp_core.c
+++ b/drivers/pci/hotplug/ibmphp_core.c
@@ -1077,7 +1077,7 @@ static int enable_slot(struct hotplug_slot *hs)
1077 if (rc) { 1077 if (rc) {
1078 err("Adding this card exceeds the limitations of this bus.\n"); 1078 err("Adding this card exceeds the limitations of this bus.\n");
1079 err("(i.e., >1 133MHz cards running on same bus, or " 1079 err("(i.e., >1 133MHz cards running on same bus, or "
1080 ">2 66 PCI cards running on same bus\n."); 1080 ">2 66 PCI cards running on same bus.\n");
1081 err("Try hot-adding into another bus\n"); 1081 err("Try hot-adding into another bus\n");
1082 rc = -EINVAL; 1082 rc = -EINVAL;
1083 goto error_nopower; 1083 goto error_nopower;
diff --git a/drivers/pci/hotplug/pciehp_pci.c b/drivers/pci/hotplug/pciehp_pci.c
index 33b539b34f7e..ff17d8e07e94 100644
--- a/drivers/pci/hotplug/pciehp_pci.c
+++ b/drivers/pci/hotplug/pciehp_pci.c
@@ -113,7 +113,7 @@ int pciehp_unconfigure_device(struct pci_func* func)
113 */ 113 */
114int pciehp_set_irq (u8 bus_num, u8 dev_num, u8 int_pin, u8 irq_num) 114int pciehp_set_irq (u8 bus_num, u8 dev_num, u8 int_pin, u8 irq_num)
115{ 115{
116#if defined(CONFIG_X86) && !defined(CONFIG_X86_IO_APIC) && !defined(CONFIG_X86_64) 116#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_IO_APIC)
117 int rc; 117 int rc;
118 u16 temp_word; 118 u16 temp_word;
119 struct pci_dev fakedev; 119 struct pci_dev fakedev;
diff --git a/drivers/pci/hotplug/pciehprm_nonacpi.c b/drivers/pci/hotplug/pciehprm_nonacpi.c
index 3622965f8961..33b2c69a0829 100644
--- a/drivers/pci/hotplug/pciehprm_nonacpi.c
+++ b/drivers/pci/hotplug/pciehprm_nonacpi.c
@@ -33,10 +33,13 @@
33#include <linux/types.h> 33#include <linux/types.h>
34#include <linux/pci.h> 34#include <linux/pci.h>
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/slab.h>
37
36#include <asm/uaccess.h> 38#include <asm/uaccess.h>
37#ifdef CONFIG_IA64 39#ifdef CONFIG_IA64
38#include <asm/iosapic.h> 40#include <asm/iosapic.h>
39#endif 41#endif
42
40#include "pciehp.h" 43#include "pciehp.h"
41#include "pciehprm.h" 44#include "pciehprm.h"
42#include "pciehprm_nonacpi.h" 45#include "pciehprm_nonacpi.h"
diff --git a/drivers/pci/hotplug/rpadlpar_core.c b/drivers/pci/hotplug/rpadlpar_core.c
index ad1017da8656..fcb66b9a0e28 100644
--- a/drivers/pci/hotplug/rpadlpar_core.c
+++ b/drivers/pci/hotplug/rpadlpar_core.c
@@ -16,10 +16,13 @@
16 */ 16 */
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/pci.h> 18#include <linux/pci.h>
19#include <linux/string.h>
20
19#include <asm/pci-bridge.h> 21#include <asm/pci-bridge.h>
20#include <asm/semaphore.h> 22#include <asm/semaphore.h>
21#include <asm/rtas.h> 23#include <asm/rtas.h>
22#include <asm/vio.h> 24#include <asm/vio.h>
25
23#include "../pci.h" 26#include "../pci.h"
24#include "rpaphp.h" 27#include "rpaphp.h"
25#include "rpadlpar.h" 28#include "rpadlpar.h"
diff --git a/drivers/pci/hotplug/rpaphp.h b/drivers/pci/hotplug/rpaphp.h
index 61d94d1e29cb..71ea5f9bb284 100644
--- a/drivers/pci/hotplug/rpaphp.h
+++ b/drivers/pci/hotplug/rpaphp.h
@@ -92,9 +92,10 @@ extern struct pci_bus *rpaphp_find_pci_bus(struct device_node *dn);
92extern int rpaphp_claim_resource(struct pci_dev *dev, int resource); 92extern int rpaphp_claim_resource(struct pci_dev *dev, int resource);
93extern int rpaphp_enable_pci_slot(struct slot *slot); 93extern int rpaphp_enable_pci_slot(struct slot *slot);
94extern int register_pci_slot(struct slot *slot); 94extern int register_pci_slot(struct slot *slot);
95extern int rpaphp_unconfig_pci_adapter(struct slot *slot);
96extern int rpaphp_get_pci_adapter_status(struct slot *slot, int is_init, u8 * value); 95extern int rpaphp_get_pci_adapter_status(struct slot *slot, int is_init, u8 * value);
96
97extern int rpaphp_config_pci_adapter(struct pci_bus *bus); 97extern int rpaphp_config_pci_adapter(struct pci_bus *bus);
98extern int rpaphp_unconfig_pci_adapter(struct pci_bus *bus);
98 99
99/* rpaphp_core.c */ 100/* rpaphp_core.c */
100extern int rpaphp_add_slot(struct device_node *dn); 101extern int rpaphp_add_slot(struct device_node *dn);
diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c
index c830ff0acdc3..cf075c34b578 100644
--- a/drivers/pci/hotplug/rpaphp_core.c
+++ b/drivers/pci/hotplug/rpaphp_core.c
@@ -426,8 +426,11 @@ static int disable_slot(struct hotplug_slot *hotplug_slot)
426 426
427 dbg("DISABLING SLOT %s\n", slot->name); 427 dbg("DISABLING SLOT %s\n", slot->name);
428 down(&rpaphp_sem); 428 down(&rpaphp_sem);
429 retval = rpaphp_unconfig_pci_adapter(slot); 429 retval = rpaphp_unconfig_pci_adapter(slot->bus);
430 up(&rpaphp_sem); 430 up(&rpaphp_sem);
431 slot->state = NOT_CONFIGURED;
432 info("%s: devices in slot[%s] unconfigured.\n", __FUNCTION__,
433 slot->name);
431exit: 434exit:
432 dbg("%s - Exit: rc[%d]\n", __FUNCTION__, retval); 435 dbg("%s - Exit: rc[%d]\n", __FUNCTION__, retval);
433 return retval; 436 return retval;
diff --git a/drivers/pci/hotplug/rpaphp_pci.c b/drivers/pci/hotplug/rpaphp_pci.c
index 49e4d10a6488..f7c12d7dfcfc 100644
--- a/drivers/pci/hotplug/rpaphp_pci.c
+++ b/drivers/pci/hotplug/rpaphp_pci.c
@@ -23,11 +23,13 @@
23 * 23 *
24 */ 24 */
25#include <linux/pci.h> 25#include <linux/pci.h>
26#include <linux/string.h>
27
26#include <asm/pci-bridge.h> 28#include <asm/pci-bridge.h>
27#include <asm/rtas.h> 29#include <asm/rtas.h>
28#include <asm/machdep.h> 30#include <asm/machdep.h>
29#include "../pci.h" /* for pci_add_new_bus */
30 31
32#include "../pci.h" /* for pci_add_new_bus */
31#include "rpaphp.h" 33#include "rpaphp.h"
32 34
33static struct pci_bus *find_bus_among_children(struct pci_bus *bus, 35static struct pci_bus *find_bus_among_children(struct pci_bus *bus,
@@ -319,20 +321,15 @@ static void rpaphp_eeh_remove_bus_device(struct pci_dev *dev)
319 return; 321 return;
320} 322}
321 323
322int rpaphp_unconfig_pci_adapter(struct slot *slot) 324int rpaphp_unconfig_pci_adapter(struct pci_bus *bus)
323{ 325{
324 struct pci_dev *dev, *tmp; 326 struct pci_dev *dev, *tmp;
325 int retval = 0;
326 327
327 list_for_each_entry_safe(dev, tmp, slot->pci_devs, bus_list) { 328 list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list) {
328 rpaphp_eeh_remove_bus_device(dev); 329 rpaphp_eeh_remove_bus_device(dev);
329 pci_remove_bus_device(dev); 330 pci_remove_bus_device(dev);
330 } 331 }
331 332 return 0;
332 slot->state = NOT_CONFIGURED;
333 info("%s: devices in slot[%s] unconfigured.\n", __FUNCTION__,
334 slot->name);
335 return retval;
336} 333}
337 334
338static int setup_pci_hotplug_slot_info(struct slot *slot) 335static int setup_pci_hotplug_slot_info(struct slot *slot)
diff --git a/drivers/pci/hotplug/rpaphp_slot.c b/drivers/pci/hotplug/rpaphp_slot.c
index 0e8815495083..daa89ae57123 100644
--- a/drivers/pci/hotplug/rpaphp_slot.c
+++ b/drivers/pci/hotplug/rpaphp_slot.c
@@ -27,6 +27,9 @@
27#include <linux/kobject.h> 27#include <linux/kobject.h>
28#include <linux/sysfs.h> 28#include <linux/sysfs.h>
29#include <linux/pci.h> 29#include <linux/pci.h>
30#include <linux/string.h>
31#include <linux/slab.h>
32
30#include <asm/rtas.h> 33#include <asm/rtas.h>
31#include "rpaphp.h" 34#include "rpaphp.h"
32 35
diff --git a/drivers/pci/hotplug/shpchp.h b/drivers/pci/hotplug/shpchp.h
index b7d1c61d6bbb..08ad26a0cae7 100644
--- a/drivers/pci/hotplug/shpchp.h
+++ b/drivers/pci/hotplug/shpchp.h
@@ -32,8 +32,8 @@
32#include <linux/types.h> 32#include <linux/types.h>
33#include <linux/pci.h> 33#include <linux/pci.h>
34#include <linux/delay.h> 34#include <linux/delay.h>
35#include <asm/semaphore.h> 35#include <linux/sched.h> /* signal_pending(), struct timer_list */
36#include <asm/io.h> 36
37#include "pci_hotplug.h" 37#include "pci_hotplug.h"
38 38
39#if !defined(MODULE) 39#if !defined(MODULE)
@@ -52,42 +52,18 @@ extern int shpchp_debug;
52#define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg) 52#define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg)
53#define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg) 53#define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg)
54 54
55struct pci_func {
56 struct pci_func *next;
57 u8 bus;
58 u8 device;
59 u8 function;
60 u8 is_a_board;
61 u16 status;
62 u8 configured;
63 u8 switch_save;
64 u8 presence_save;
65 u8 pwr_save;
66 u32 base_length[0x06];
67 u8 base_type[0x06];
68 u16 reserved2;
69 u32 config_space[0x20];
70 struct pci_resource *mem_head;
71 struct pci_resource *p_mem_head;
72 struct pci_resource *io_head;
73 struct pci_resource *bus_head;
74 struct pci_dev* pci_dev;
75};
76
77#define SLOT_MAGIC 0x67267321 55#define SLOT_MAGIC 0x67267321
78struct slot { 56struct slot {
79 u32 magic; 57 u32 magic;
80 struct slot *next; 58 struct slot *next;
81 u8 bus; 59 u8 bus;
82 u8 device; 60 u8 device;
61 u16 status;
83 u32 number; 62 u32 number;
84 u8 is_a_board; 63 u8 is_a_board;
85 u8 configured;
86 u8 state; 64 u8 state;
87 u8 switch_save;
88 u8 presence_save; 65 u8 presence_save;
89 u32 capabilities; 66 u8 pwr_save;
90 u16 reserved2;
91 struct timer_list task_event; 67 struct timer_list task_event;
92 u8 hp_slot; 68 u8 hp_slot;
93 struct controller *ctrl; 69 struct controller *ctrl;
@@ -96,12 +72,6 @@ struct slot {
96 struct list_head slot_list; 72 struct list_head slot_list;
97}; 73};
98 74
99struct pci_resource {
100 struct pci_resource * next;
101 u32 base;
102 u32 length;
103};
104
105struct event_info { 75struct event_info {
106 u32 event_type; 76 u32 event_type;
107 u8 hp_slot; 77 u8 hp_slot;
@@ -110,13 +80,9 @@ struct event_info {
110struct controller { 80struct controller {
111 struct controller *next; 81 struct controller *next;
112 struct semaphore crit_sect; /* critical section semaphore */ 82 struct semaphore crit_sect; /* critical section semaphore */
113 void * hpc_ctlr_handle; /* HPC controller handle */ 83 struct php_ctlr_state_s *hpc_ctlr_handle; /* HPC controller handle */
114 int num_slots; /* Number of slots on ctlr */ 84 int num_slots; /* Number of slots on ctlr */
115 int slot_num_inc; /* 1 or -1 */ 85 int slot_num_inc; /* 1 or -1 */
116 struct pci_resource *mem_head;
117 struct pci_resource *p_mem_head;
118 struct pci_resource *io_head;
119 struct pci_resource *bus_head;
120 struct pci_dev *pci_dev; 86 struct pci_dev *pci_dev;
121 struct pci_bus *pci_bus; 87 struct pci_bus *pci_bus;
122 struct event_info event_queue[10]; 88 struct event_info event_queue[10];
@@ -124,33 +90,21 @@ struct controller {
124 struct hpc_ops *hpc_ops; 90 struct hpc_ops *hpc_ops;
125 wait_queue_head_t queue; /* sleep & wake process */ 91 wait_queue_head_t queue; /* sleep & wake process */
126 u8 next_event; 92 u8 next_event;
127 u8 seg;
128 u8 bus; 93 u8 bus;
129 u8 device; 94 u8 device;
130 u8 function; 95 u8 function;
131 u8 rev;
132 u8 slot_device_offset; 96 u8 slot_device_offset;
133 u8 add_support; 97 u8 add_support;
134 enum pci_bus_speed speed; 98 enum pci_bus_speed speed;
135 u32 first_slot; /* First physical slot number */ 99 u32 first_slot; /* First physical slot number */
136 u8 slot_bus; /* Bus where the slots handled by this controller sit */ 100 u8 slot_bus; /* Bus where the slots handled by this controller sit */
137 u8 push_flag;
138 u16 ctlrcap;
139 u16 vendor_id;
140};
141
142struct irq_mapping {
143 u8 barber_pole;
144 u8 valid_INT;
145 u8 interrupt[4];
146}; 101};
147 102
148struct resource_lists { 103struct hotplug_params {
149 struct pci_resource *mem_head; 104 u8 cache_line_size;
150 struct pci_resource *p_mem_head; 105 u8 latency_timer;
151 struct pci_resource *io_head; 106 u8 enable_serr;
152 struct pci_resource *bus_head; 107 u8 enable_perr;
153 struct irq_mapping *irqs;
154}; 108};
155 109
156/* Define AMD SHPC ID */ 110/* Define AMD SHPC ID */
@@ -194,24 +148,16 @@ struct resource_lists {
194 * error Messages 148 * error Messages
195 */ 149 */
196#define msg_initialization_err "Initialization failure, error=%d\n" 150#define msg_initialization_err "Initialization failure, error=%d\n"
197#define msg_HPC_rev_error "Unsupported revision of the PCI hot plug controller found.\n"
198#define msg_HPC_non_shpc "The PCI hot plug controller is not supported by this driver.\n"
199#define msg_HPC_not_supported "This system is not supported by this version of shpcphd mdoule. Upgrade to a newer version of shpchpd\n"
200#define msg_unable_to_save "Unable to store PCI hot plug add resource information. This system must be rebooted before adding any PCI devices.\n"
201#define msg_button_on "PCI slot #%d - powering on due to button press.\n" 151#define msg_button_on "PCI slot #%d - powering on due to button press.\n"
202#define msg_button_off "PCI slot #%d - powering off due to button press.\n" 152#define msg_button_off "PCI slot #%d - powering off due to button press.\n"
203#define msg_button_cancel "PCI slot #%d - action canceled due to button press.\n" 153#define msg_button_cancel "PCI slot #%d - action canceled due to button press.\n"
204#define msg_button_ignore "PCI slot #%d - button press ignored. (action in progress...)\n"
205 154
206/* sysfs functions for the hotplug controller info */ 155/* sysfs functions for the hotplug controller info */
207extern void shpchp_create_ctrl_files (struct controller *ctrl); 156extern void shpchp_create_ctrl_files (struct controller *ctrl);
208 157
209/* controller functions */ 158/* controller functions */
210extern int shpchprm_find_available_resources(struct controller *ctrl);
211extern int shpchp_event_start_thread(void); 159extern int shpchp_event_start_thread(void);
212extern void shpchp_event_stop_thread(void); 160extern void shpchp_event_stop_thread(void);
213extern struct pci_func *shpchp_slot_create(unsigned char busnumber);
214extern struct pci_func *shpchp_slot_find(unsigned char bus, unsigned char device, unsigned char index);
215extern int shpchp_enable_slot(struct slot *slot); 161extern int shpchp_enable_slot(struct slot *slot);
216extern int shpchp_disable_slot(struct slot *slot); 162extern int shpchp_disable_slot(struct slot *slot);
217 163
@@ -220,29 +166,20 @@ extern u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id);
220extern u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id); 166extern u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id);
221extern u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id); 167extern u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id);
222 168
223/* resource functions */
224extern int shpchp_resource_sort_and_combine(struct pci_resource **head);
225
226/* pci functions */ 169/* pci functions */
227extern int shpchp_set_irq(u8 bus_num, u8 dev_num, u8 int_pin, u8 irq_num);
228/*extern int shpchp_get_bus_dev(struct controller *ctrl, u8 *bus_num, u8 *dev_num, struct slot *slot);*/
229extern int shpchp_save_config(struct controller *ctrl, int busnumber, int num_ctlr_slots, int first_device_num); 170extern int shpchp_save_config(struct controller *ctrl, int busnumber, int num_ctlr_slots, int first_device_num);
230extern int shpchp_save_used_resources(struct controller *ctrl, struct pci_func * func, int flag); 171extern int shpchp_configure_device(struct slot *p_slot);
231extern int shpchp_save_slot_config(struct controller *ctrl, struct pci_func * new_slot); 172extern int shpchp_unconfigure_device(struct slot *p_slot);
232extern void shpchp_destroy_board_resources(struct pci_func * func); 173extern void get_hp_hw_control_from_firmware(struct pci_dev *dev);
233extern int shpchp_return_board_resources(struct pci_func * func, struct resource_lists * resources); 174extern void get_hp_params_from_firmware(struct pci_dev *dev,
234extern void shpchp_destroy_resource_list(struct resource_lists * resources); 175 struct hotplug_params *hpp);
235extern int shpchp_configure_device(struct controller* ctrl, struct pci_func* func); 176extern int shpchprm_get_physical_slot_number(struct controller *ctrl,
236extern int shpchp_unconfigure_device(struct pci_func* func); 177 u32 *sun, u8 busnum, u8 devnum);
178extern void shpchp_remove_ctrl_files(struct controller *ctrl);
237 179
238 180
239/* Global variables */ 181/* Global variables */
240extern struct controller *shpchp_ctrl_list; 182extern struct controller *shpchp_ctrl_list;
241extern struct pci_func *shpchp_slot_list[256];
242
243/* These are added to support AMD shpc */
244extern u8 shpchp_nic_irq;
245extern u8 shpchp_disk_irq;
246 183
247struct ctrl_reg { 184struct ctrl_reg {
248 volatile u32 base_offset; 185 volatile u32 base_offset;
@@ -298,7 +235,7 @@ enum ctrl_offsets {
298 SLOT11 = offsetof(struct ctrl_reg, slot11), 235 SLOT11 = offsetof(struct ctrl_reg, slot11),
299 SLOT12 = offsetof(struct ctrl_reg, slot12), 236 SLOT12 = offsetof(struct ctrl_reg, slot12),
300}; 237};
301typedef u8(*php_intr_callback_t) (unsigned int change_id, void *instance_id); 238typedef u8(*php_intr_callback_t) (u8 hp_slot, void *instance_id);
302struct php_ctlr_state_s { 239struct php_ctlr_state_s {
303 struct php_ctlr_state_s *pnext; 240 struct php_ctlr_state_s *pnext;
304 struct pci_dev *pci_dev; 241 struct pci_dev *pci_dev;
@@ -359,12 +296,9 @@ static inline struct slot *shpchp_find_slot (struct controller *ctrl, u8 device)
359 296
360 p_slot = ctrl->slot; 297 p_slot = ctrl->slot;
361 298
362 dbg("p_slot = %p\n", p_slot);
363
364 while (p_slot && (p_slot->device != device)) { 299 while (p_slot && (p_slot->device != device)) {
365 tmp_slot = p_slot; 300 tmp_slot = p_slot;
366 p_slot = p_slot->next; 301 p_slot = p_slot->next;
367 dbg("In while loop, p_slot = %p\n", p_slot);
368 } 302 }
369 if (p_slot == NULL) { 303 if (p_slot == NULL) {
370 err("ERROR: shpchp_find_slot device=0x%x\n", device); 304 err("ERROR: shpchp_find_slot device=0x%x\n", device);
@@ -379,8 +313,6 @@ static inline int wait_for_ctrl_irq (struct controller *ctrl)
379 DECLARE_WAITQUEUE(wait, current); 313 DECLARE_WAITQUEUE(wait, current);
380 int retval = 0; 314 int retval = 0;
381 315
382 dbg("%s : start\n",__FUNCTION__);
383
384 add_wait_queue(&ctrl->queue, &wait); 316 add_wait_queue(&ctrl->queue, &wait);
385 317
386 if (!shpchp_poll_mode) { 318 if (!shpchp_poll_mode) {
@@ -394,19 +326,9 @@ static inline int wait_for_ctrl_irq (struct controller *ctrl)
394 if (signal_pending(current)) 326 if (signal_pending(current))
395 retval = -EINTR; 327 retval = -EINTR;
396 328
397 dbg("%s : end\n", __FUNCTION__);
398 return retval; 329 return retval;
399} 330}
400 331
401/* Puts node back in the resource list pointed to by head */
402static inline void return_resource(struct pci_resource **head, struct pci_resource *node)
403{
404 if (!node || !head)
405 return;
406 node->next = *head;
407 *head = node;
408}
409
410#define SLOT_NAME_SIZE 10 332#define SLOT_NAME_SIZE 10
411 333
412static inline void make_slot_name(char *buffer, int buffer_size, struct slot *slot) 334static inline void make_slot_name(char *buffer, int buffer_size, struct slot *slot)
@@ -420,11 +342,7 @@ enum php_ctlr_type {
420 ACPI 342 ACPI
421}; 343};
422 344
423int shpc_init( struct controller *ctrl, struct pci_dev *pdev, 345int shpc_init( struct controller *ctrl, struct pci_dev *pdev);
424 php_intr_callback_t attention_button_callback,
425 php_intr_callback_t switch_change_callback,
426 php_intr_callback_t presence_change_callback,
427 php_intr_callback_t power_fault_callback);
428 346
429int shpc_get_ctlr_slot_config( struct controller *ctrl, 347int shpc_get_ctlr_slot_config( struct controller *ctrl,
430 int *num_ctlr_slots, 348 int *num_ctlr_slots,
@@ -437,8 +355,6 @@ struct hpc_ops {
437 int (*power_on_slot ) (struct slot *slot); 355 int (*power_on_slot ) (struct slot *slot);
438 int (*slot_enable ) (struct slot *slot); 356 int (*slot_enable ) (struct slot *slot);
439 int (*slot_disable ) (struct slot *slot); 357 int (*slot_disable ) (struct slot *slot);
440 int (*enable_all_slots) (struct slot *slot);
441 int (*pwr_on_all_slots) (struct slot *slot);
442 int (*set_bus_speed_mode) (struct slot *slot, enum pci_bus_speed speed); 358 int (*set_bus_speed_mode) (struct slot *slot, enum pci_bus_speed speed);
443 int (*get_power_status) (struct slot *slot, u8 *status); 359 int (*get_power_status) (struct slot *slot, u8 *status);
444 int (*get_attention_status) (struct slot *slot, u8 *status); 360 int (*get_attention_status) (struct slot *slot, u8 *status);
diff --git a/drivers/pci/hotplug/shpchp_core.c b/drivers/pci/hotplug/shpchp_core.c
index 6f7d8a29957a..63628e01dd43 100644
--- a/drivers/pci/hotplug/shpchp_core.c
+++ b/drivers/pci/hotplug/shpchp_core.c
@@ -27,26 +27,18 @@
27 * 27 *
28 */ 28 */
29 29
30#include <linux/config.h>
31#include <linux/module.h> 30#include <linux/module.h>
32#include <linux/moduleparam.h> 31#include <linux/moduleparam.h>
33#include <linux/kernel.h> 32#include <linux/kernel.h>
34#include <linux/types.h> 33#include <linux/types.h>
35#include <linux/proc_fs.h>
36#include <linux/slab.h>
37#include <linux/workqueue.h>
38#include <linux/pci.h> 34#include <linux/pci.h>
39#include <linux/init.h>
40#include <asm/uaccess.h>
41#include "shpchp.h" 35#include "shpchp.h"
42#include "shpchprm.h"
43 36
44/* Global variables */ 37/* Global variables */
45int shpchp_debug; 38int shpchp_debug;
46int shpchp_poll_mode; 39int shpchp_poll_mode;
47int shpchp_poll_time; 40int shpchp_poll_time;
48struct controller *shpchp_ctrl_list; /* = NULL */ 41struct controller *shpchp_ctrl_list; /* = NULL */
49struct pci_func *shpchp_slot_list[256];
50 42
51#define DRIVER_VERSION "0.4" 43#define DRIVER_VERSION "0.4"
52#define DRIVER_AUTHOR "Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>, Dely Sy <dely.l.sy@intel.com>" 44#define DRIVER_AUTHOR "Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>, Dely Sy <dely.l.sy@intel.com>"
@@ -113,8 +105,6 @@ static int init_slots(struct controller *ctrl)
113 u32 slot_number, sun; 105 u32 slot_number, sun;
114 int result = -ENOMEM; 106 int result = -ENOMEM;
115 107
116 dbg("%s\n",__FUNCTION__);
117
118 number_of_slots = ctrl->num_slots; 108 number_of_slots = ctrl->num_slots;
119 slot_device = ctrl->slot_device_offset; 109 slot_device = ctrl->slot_device_offset;
120 slot_number = ctrl->first_slot; 110 slot_number = ctrl->first_slot;
@@ -352,6 +342,17 @@ static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_sp
352 return 0; 342 return 0;
353} 343}
354 344
345static int is_shpc_capable(struct pci_dev *dev)
346{
347 if ((dev->vendor == PCI_VENDOR_ID_AMD) || (dev->device ==
348 PCI_DEVICE_ID_AMD_GOLAM_7450))
349 return 1;
350 if (pci_find_capability(dev, PCI_CAP_ID_SHPC))
351 return 1;
352
353 return 0;
354}
355
355static int shpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 356static int shpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
356{ 357{
357 int rc; 358 int rc;
@@ -360,6 +361,9 @@ static int shpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
360 int first_device_num; /* first PCI device number supported by this SHPC */ 361 int first_device_num; /* first PCI device number supported by this SHPC */
361 int num_ctlr_slots; /* number of slots supported by this SHPC */ 362 int num_ctlr_slots; /* number of slots supported by this SHPC */
362 363
364 if (!is_shpc_capable(pdev))
365 return -ENODEV;
366
363 ctrl = (struct controller *) kmalloc(sizeof(struct controller), GFP_KERNEL); 367 ctrl = (struct controller *) kmalloc(sizeof(struct controller), GFP_KERNEL);
364 if (!ctrl) { 368 if (!ctrl) {
365 err("%s : out of memory\n", __FUNCTION__); 369 err("%s : out of memory\n", __FUNCTION__);
@@ -367,19 +371,12 @@ static int shpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
367 } 371 }
368 memset(ctrl, 0, sizeof(struct controller)); 372 memset(ctrl, 0, sizeof(struct controller));
369 373
370 dbg("DRV_thread pid = %d\n", current->pid); 374 rc = shpc_init(ctrl, pdev);
371
372 rc = shpc_init(ctrl, pdev,
373 (php_intr_callback_t) shpchp_handle_attention_button,
374 (php_intr_callback_t) shpchp_handle_switch_change,
375 (php_intr_callback_t) shpchp_handle_presence_change,
376 (php_intr_callback_t) shpchp_handle_power_fault);
377 if (rc) { 375 if (rc) {
378 dbg("%s: controller initialization failed\n", SHPC_MODULE_NAME); 376 dbg("%s: controller initialization failed\n", SHPC_MODULE_NAME);
379 goto err_out_free_ctrl; 377 goto err_out_free_ctrl;
380 } 378 }
381 379
382 dbg("%s: controller initialization success\n", __FUNCTION__);
383 ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */ 380 ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */
384 381
385 pci_set_drvdata(pdev, ctrl); 382 pci_set_drvdata(pdev, ctrl);
@@ -411,23 +408,8 @@ static int shpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
411 first_device_num = ctrl->slot_device_offset; 408 first_device_num = ctrl->slot_device_offset;
412 num_ctlr_slots = ctrl->num_slots; 409 num_ctlr_slots = ctrl->num_slots;
413 410
414 /* Store PCI Config Space for all devices on this bus */ 411 ctrl->add_support = 1;
415 rc = shpchp_save_config(ctrl, ctrl->slot_bus, num_ctlr_slots, first_device_num);
416 if (rc) {
417 err("%s: unable to save PCI configuration data, error %d\n", __FUNCTION__, rc);
418 goto err_out_free_ctrl_bus;
419 }
420
421 /* Get IO, memory, and IRQ resources for new devices */
422 rc = shpchprm_find_available_resources(ctrl);
423 ctrl->add_support = !rc;
424 412
425 if (rc) {
426 dbg("shpchprm_find_available_resources = %#x\n", rc);
427 err("unable to locate PCI configuration resources for hot plug add.\n");
428 goto err_out_free_ctrl_bus;
429 }
430
431 /* Setup the slot information structures */ 413 /* Setup the slot information structures */
432 rc = init_slots(ctrl); 414 rc = init_slots(ctrl);
433 if (rc) { 415 if (rc) {
@@ -477,7 +459,6 @@ err_out_none:
477 459
478static int shpc_start_thread(void) 460static int shpc_start_thread(void)
479{ 461{
480 int loop;
481 int retval = 0; 462 int retval = 0;
482 463
483 dbg("Initialize + Start the notification/polling mechanism \n"); 464 dbg("Initialize + Start the notification/polling mechanism \n");
@@ -488,48 +469,21 @@ static int shpc_start_thread(void)
488 return retval; 469 return retval;
489 } 470 }
490 471
491 dbg("Initialize slot lists\n");
492 /* One slot list for each bus in the system */
493 for (loop = 0; loop < 256; loop++) {
494 shpchp_slot_list[loop] = NULL;
495 }
496
497 return retval; 472 return retval;
498} 473}
499 474
500static inline void __exit
501free_shpchp_res(struct pci_resource *res)
502{
503 struct pci_resource *tres;
504
505 while (res) {
506 tres = res;
507 res = res->next;
508 kfree(tres);
509 }
510}
511
512static void __exit unload_shpchpd(void) 475static void __exit unload_shpchpd(void)
513{ 476{
514 struct pci_func *next;
515 struct pci_func *TempSlot;
516 int loop;
517 struct controller *ctrl; 477 struct controller *ctrl;
518 struct controller *tctrl; 478 struct controller *tctrl;
519 479
520 ctrl = shpchp_ctrl_list; 480 ctrl = shpchp_ctrl_list;
521 481
522 while (ctrl) { 482 while (ctrl) {
483 shpchp_remove_ctrl_files(ctrl);
523 cleanup_slots(ctrl); 484 cleanup_slots(ctrl);
524 485
525 free_shpchp_res(ctrl->io_head);
526 free_shpchp_res(ctrl->mem_head);
527 free_shpchp_res(ctrl->p_mem_head);
528 free_shpchp_res(ctrl->bus_head);
529
530 kfree (ctrl->pci_bus); 486 kfree (ctrl->pci_bus);
531
532 dbg("%s: calling release_ctlr\n", __FUNCTION__);
533 ctrl->hpc_ops->release_ctlr(ctrl); 487 ctrl->hpc_ops->release_ctlr(ctrl);
534 488
535 tctrl = ctrl; 489 tctrl = ctrl;
@@ -538,20 +492,6 @@ static void __exit unload_shpchpd(void)
538 kfree(tctrl); 492 kfree(tctrl);
539 } 493 }
540 494
541 for (loop = 0; loop < 256; loop++) {
542 next = shpchp_slot_list[loop];
543 while (next != NULL) {
544 free_shpchp_res(next->io_head);
545 free_shpchp_res(next->mem_head);
546 free_shpchp_res(next->p_mem_head);
547 free_shpchp_res(next->bus_head);
548
549 TempSlot = next;
550 next = next->next;
551 kfree(TempSlot);
552 }
553 }
554
555 /* Stop the notification mechanism */ 495 /* Stop the notification mechanism */
556 shpchp_event_stop_thread(); 496 shpchp_event_stop_thread();
557 497
@@ -596,20 +536,14 @@ static int __init shpcd_init(void)
596 if (retval) 536 if (retval)
597 goto error_hpc_init; 537 goto error_hpc_init;
598 538
599 retval = shpchprm_init(PCI); 539 retval = pci_register_driver(&shpc_driver);
600 if (!retval) { 540 dbg("%s: pci_register_driver = %d\n", __FUNCTION__, retval);
601 retval = pci_register_driver(&shpc_driver); 541 info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
602 dbg("%s: pci_register_driver = %d\n", __FUNCTION__, retval);
603 info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
604 }
605 542
606error_hpc_init: 543error_hpc_init:
607 if (retval) { 544 if (retval) {
608 shpchprm_cleanup();
609 shpchp_event_stop_thread(); 545 shpchp_event_stop_thread();
610 } else 546 }
611 shpchprm_print_pirt();
612
613 return retval; 547 return retval;
614} 548}
615 549
@@ -618,9 +552,6 @@ static void __exit shpcd_cleanup(void)
618 dbg("unload_shpchpd()\n"); 552 dbg("unload_shpchpd()\n");
619 unload_shpchpd(); 553 unload_shpchpd();
620 554
621 shpchprm_cleanup();
622
623 dbg("pci_unregister_driver\n");
624 pci_unregister_driver(&shpc_driver); 555 pci_unregister_driver(&shpc_driver);
625 556
626 info(DRIVER_DESC " version: " DRIVER_VERSION " unloaded\n"); 557 info(DRIVER_DESC " version: " DRIVER_VERSION " unloaded\n");
diff --git a/drivers/pci/hotplug/shpchp_ctrl.c b/drivers/pci/hotplug/shpchp_ctrl.c
index 91c9903e621f..58619359ad08 100644
--- a/drivers/pci/hotplug/shpchp_ctrl.c
+++ b/drivers/pci/hotplug/shpchp_ctrl.c
@@ -27,24 +27,14 @@
27 * 27 *
28 */ 28 */
29 29
30#include <linux/config.h>
31#include <linux/module.h> 30#include <linux/module.h>
32#include <linux/kernel.h> 31#include <linux/kernel.h>
33#include <linux/types.h> 32#include <linux/types.h>
34#include <linux/slab.h>
35#include <linux/workqueue.h>
36#include <linux/interrupt.h>
37#include <linux/delay.h>
38#include <linux/wait.h>
39#include <linux/smp_lock.h> 33#include <linux/smp_lock.h>
40#include <linux/pci.h> 34#include <linux/pci.h>
35#include "../pci.h"
41#include "shpchp.h" 36#include "shpchp.h"
42#include "shpchprm.h"
43 37
44static u32 configure_new_device(struct controller *ctrl, struct pci_func *func,
45 u8 behind_bridge, struct resource_lists *resources, u8 bridge_bus, u8 bridge_dev);
46static int configure_new_function( struct controller *ctrl, struct pci_func *func,
47 u8 behind_bridge, struct resource_lists *resources, u8 bridge_bus, u8 bridge_dev);
48static void interrupt_event_handler(struct controller *ctrl); 38static void interrupt_event_handler(struct controller *ctrl);
49 39
50static struct semaphore event_semaphore; /* mutex for process loop (up if something to process) */ 40static struct semaphore event_semaphore; /* mutex for process loop (up if something to process) */
@@ -52,28 +42,22 @@ static struct semaphore event_exit; /* guard ensure thread has exited before ca
52static int event_finished; 42static int event_finished;
53static unsigned long pushbutton_pending; /* = 0 */ 43static unsigned long pushbutton_pending; /* = 0 */
54 44
55u8 shpchp_disk_irq;
56u8 shpchp_nic_irq;
57
58u8 shpchp_handle_attention_button(u8 hp_slot, void *inst_id) 45u8 shpchp_handle_attention_button(u8 hp_slot, void *inst_id)
59{ 46{
60 struct controller *ctrl = (struct controller *) inst_id; 47 struct controller *ctrl = (struct controller *) inst_id;
61 struct slot *p_slot; 48 struct slot *p_slot;
62 u8 rc = 0; 49 u8 rc = 0;
63 u8 getstatus; 50 u8 getstatus;
64 struct pci_func *func;
65 struct event_info *taskInfo; 51 struct event_info *taskInfo;
66 52
67 /* Attention Button Change */ 53 /* Attention Button Change */
68 dbg("shpchp: Attention button interrupt received.\n"); 54 dbg("shpchp: Attention button interrupt received.\n");
69 55
70 func = shpchp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);
71
72 /* This is the structure that tells the worker thread what to do */ 56 /* This is the structure that tells the worker thread what to do */
73 taskInfo = &(ctrl->event_queue[ctrl->next_event]); 57 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
74 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); 58 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
75 59
76 p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save)); 60 p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save));
77 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 61 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
78 62
79 ctrl->next_event = (ctrl->next_event + 1) % 10; 63 ctrl->next_event = (ctrl->next_event + 1) % 10;
@@ -118,14 +102,11 @@ u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id)
118 struct slot *p_slot; 102 struct slot *p_slot;
119 u8 rc = 0; 103 u8 rc = 0;
120 u8 getstatus; 104 u8 getstatus;
121 struct pci_func *func;
122 struct event_info *taskInfo; 105 struct event_info *taskInfo;
123 106
124 /* Switch Change */ 107 /* Switch Change */
125 dbg("shpchp: Switch interrupt received.\n"); 108 dbg("shpchp: Switch interrupt received.\n");
126 109
127 func = shpchp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);
128
129 /* This is the structure that tells the worker thread 110 /* This is the structure that tells the worker thread
130 * what to do 111 * what to do
131 */ 112 */
@@ -135,19 +116,18 @@ u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id)
135 116
136 rc++; 117 rc++;
137 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); 118 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
138 p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save)); 119 p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save));
139 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 120 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
140 dbg("%s: Card present %x Power status %x\n", __FUNCTION__, 121 dbg("%s: Card present %x Power status %x\n", __FUNCTION__,
141 func->presence_save, func->pwr_save); 122 p_slot->presence_save, p_slot->pwr_save);
142 123
143 if (getstatus) { 124 if (getstatus) {
144 /* 125 /*
145 * Switch opened 126 * Switch opened
146 */ 127 */
147 info("Latch open on Slot(%d)\n", ctrl->first_slot + hp_slot); 128 info("Latch open on Slot(%d)\n", ctrl->first_slot + hp_slot);
148 func->switch_save = 0;
149 taskInfo->event_type = INT_SWITCH_OPEN; 129 taskInfo->event_type = INT_SWITCH_OPEN;
150 if (func->pwr_save && func->presence_save) { 130 if (p_slot->pwr_save && p_slot->presence_save) {
151 taskInfo->event_type = INT_POWER_FAULT; 131 taskInfo->event_type = INT_POWER_FAULT;
152 err("Surprise Removal of card\n"); 132 err("Surprise Removal of card\n");
153 } 133 }
@@ -156,7 +136,6 @@ u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id)
156 * Switch closed 136 * Switch closed
157 */ 137 */
158 info("Latch close on Slot(%d)\n", ctrl->first_slot + hp_slot); 138 info("Latch close on Slot(%d)\n", ctrl->first_slot + hp_slot);
159 func->switch_save = 0x10;
160 taskInfo->event_type = INT_SWITCH_CLOSE; 139 taskInfo->event_type = INT_SWITCH_CLOSE;
161 } 140 }
162 141
@@ -172,14 +151,11 @@ u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id)
172 struct slot *p_slot; 151 struct slot *p_slot;
173 u8 rc = 0; 152 u8 rc = 0;
174 /*u8 temp_byte;*/ 153 /*u8 temp_byte;*/
175 struct pci_func *func;
176 struct event_info *taskInfo; 154 struct event_info *taskInfo;
177 155
178 /* Presence Change */ 156 /* Presence Change */
179 dbg("shpchp: Presence/Notify input change.\n"); 157 dbg("shpchp: Presence/Notify input change.\n");
180 158
181 func = shpchp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);
182
183 /* This is the structure that tells the worker thread 159 /* This is the structure that tells the worker thread
184 * what to do 160 * what to do
185 */ 161 */
@@ -193,8 +169,8 @@ u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id)
193 /* 169 /*
194 * Save the presence state 170 * Save the presence state
195 */ 171 */
196 p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save)); 172 p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save));
197 if (func->presence_save) { 173 if (p_slot->presence_save) {
198 /* 174 /*
199 * Card Present 175 * Card Present
200 */ 176 */
@@ -219,14 +195,11 @@ u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id)
219 struct controller *ctrl = (struct controller *) inst_id; 195 struct controller *ctrl = (struct controller *) inst_id;
220 struct slot *p_slot; 196 struct slot *p_slot;
221 u8 rc = 0; 197 u8 rc = 0;
222 struct pci_func *func;
223 struct event_info *taskInfo; 198 struct event_info *taskInfo;
224 199
225 /* Power fault */ 200 /* Power fault */
226 dbg("shpchp: Power fault interrupt received.\n"); 201 dbg("shpchp: Power fault interrupt received.\n");
227 202
228 func = shpchp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);
229
230 /* This is the structure that tells the worker thread 203 /* This is the structure that tells the worker thread
231 * what to do 204 * what to do
232 */ 205 */
@@ -242,7 +215,7 @@ u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id)
242 * Power fault Cleared 215 * Power fault Cleared
243 */ 216 */
244 info("Power fault cleared on Slot(%d)\n", ctrl->first_slot + hp_slot); 217 info("Power fault cleared on Slot(%d)\n", ctrl->first_slot + hp_slot);
245 func->status = 0x00; 218 p_slot->status = 0x00;
246 taskInfo->event_type = INT_POWER_FAULT_CLEAR; 219 taskInfo->event_type = INT_POWER_FAULT_CLEAR;
247 } else { 220 } else {
248 /* 221 /*
@@ -251,7 +224,7 @@ u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id)
251 info("Power fault on Slot(%d)\n", ctrl->first_slot + hp_slot); 224 info("Power fault on Slot(%d)\n", ctrl->first_slot + hp_slot);
252 taskInfo->event_type = INT_POWER_FAULT; 225 taskInfo->event_type = INT_POWER_FAULT;
253 /* set power fault status for this board */ 226 /* set power fault status for this board */
254 func->status = 0xFF; 227 p_slot->status = 0xFF;
255 info("power fault bit %x set\n", hp_slot); 228 info("power fault bit %x set\n", hp_slot);
256 } 229 }
257 if (rc) 230 if (rc)
@@ -260,799 +233,13 @@ u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id)
260 return rc; 233 return rc;
261} 234}
262 235
263
264/*
265 * sort_by_size
266 *
267 * Sorts nodes on the list by their length.
268 * Smallest first.
269 *
270 */
271static int sort_by_size(struct pci_resource **head)
272{
273 struct pci_resource *current_res;
274 struct pci_resource *next_res;
275 int out_of_order = 1;
276
277 if (!(*head))
278 return(1);
279
280 if (!((*head)->next))
281 return(0);
282
283 while (out_of_order) {
284 out_of_order = 0;
285
286 /* Special case for swapping list head */
287 if (((*head)->next) &&
288 ((*head)->length > (*head)->next->length)) {
289 out_of_order++;
290 current_res = *head;
291 *head = (*head)->next;
292 current_res->next = (*head)->next;
293 (*head)->next = current_res;
294 }
295
296 current_res = *head;
297
298 while (current_res->next && current_res->next->next) {
299 if (current_res->next->length > current_res->next->next->length) {
300 out_of_order++;
301 next_res = current_res->next;
302 current_res->next = current_res->next->next;
303 current_res = current_res->next;
304 next_res->next = current_res->next;
305 current_res->next = next_res;
306 } else
307 current_res = current_res->next;
308 }
309 } /* End of out_of_order loop */
310
311 return(0);
312}
313
314
315/*
316 * sort_by_max_size
317 *
318 * Sorts nodes on the list by their length.
319 * Largest first.
320 *
321 */
322static int sort_by_max_size(struct pci_resource **head)
323{
324 struct pci_resource *current_res;
325 struct pci_resource *next_res;
326 int out_of_order = 1;
327
328 if (!(*head))
329 return(1);
330
331 if (!((*head)->next))
332 return(0);
333
334 while (out_of_order) {
335 out_of_order = 0;
336
337 /* Special case for swapping list head */
338 if (((*head)->next) &&
339 ((*head)->length < (*head)->next->length)) {
340 out_of_order++;
341 current_res = *head;
342 *head = (*head)->next;
343 current_res->next = (*head)->next;
344 (*head)->next = current_res;
345 }
346
347 current_res = *head;
348
349 while (current_res->next && current_res->next->next) {
350 if (current_res->next->length < current_res->next->next->length) {
351 out_of_order++;
352 next_res = current_res->next;
353 current_res->next = current_res->next->next;
354 current_res = current_res->next;
355 next_res->next = current_res->next;
356 current_res->next = next_res;
357 } else
358 current_res = current_res->next;
359 }
360 } /* End of out_of_order loop */
361
362 return(0);
363}
364
365
366/*
367 * do_pre_bridge_resource_split
368 *
369 * Returns zero or one node of resources that aren't in use
370 *
371 */
372static struct pci_resource *do_pre_bridge_resource_split (struct pci_resource **head, struct pci_resource **orig_head, u32 alignment)
373{
374 struct pci_resource *prevnode = NULL;
375 struct pci_resource *node;
376 struct pci_resource *split_node;
377 u32 rc;
378 u32 temp_dword;
379 dbg("do_pre_bridge_resource_split\n");
380
381 if (!(*head) || !(*orig_head))
382 return(NULL);
383
384 rc = shpchp_resource_sort_and_combine(head);
385
386 if (rc)
387 return(NULL);
388
389 if ((*head)->base != (*orig_head)->base)
390 return(NULL);
391
392 if ((*head)->length == (*orig_head)->length)
393 return(NULL);
394
395
396 /* If we got here, there the bridge requires some of the resource, but
397 * we may be able to split some off of the front
398 */
399 node = *head;
400
401 if (node->length & (alignment -1)) {
402 /* This one isn't an aligned length, so we'll make a new entry
403 * and split it up.
404 */
405 split_node = kmalloc(sizeof(*split_node), GFP_KERNEL);
406
407 if (!split_node)
408 return(NULL);
409
410 temp_dword = (node->length | (alignment-1)) + 1 - alignment;
411
412 split_node->base = node->base;
413 split_node->length = temp_dword;
414
415 node->length -= temp_dword;
416 node->base += split_node->length;
417
418 /* Put it in the list */
419 *head = split_node;
420 split_node->next = node;
421 }
422
423 if (node->length < alignment) {
424 return(NULL);
425 }
426
427 /* Now unlink it */
428 if (*head == node) {
429 *head = node->next;
430 node->next = NULL;
431 } else {
432 prevnode = *head;
433 while (prevnode->next != node)
434 prevnode = prevnode->next;
435
436 prevnode->next = node->next;
437 node->next = NULL;
438 }
439
440 return(node);
441}
442
443
444/*
445 * do_bridge_resource_split
446 *
447 * Returns zero or one node of resources that aren't in use
448 *
449 */
450static struct pci_resource *do_bridge_resource_split (struct pci_resource **head, u32 alignment)
451{
452 struct pci_resource *prevnode = NULL;
453 struct pci_resource *node;
454 u32 rc;
455 u32 temp_dword;
456
457 if (!(*head))
458 return(NULL);
459
460 rc = shpchp_resource_sort_and_combine(head);
461
462 if (rc)
463 return(NULL);
464
465 node = *head;
466
467 while (node->next) {
468 prevnode = node;
469 node = node->next;
470 kfree(prevnode);
471 }
472
473 if (node->length < alignment) {
474 kfree(node);
475 return(NULL);
476 }
477
478 if (node->base & (alignment - 1)) {
479 /* Short circuit if adjusted size is too small */
480 temp_dword = (node->base | (alignment-1)) + 1;
481 if ((node->length - (temp_dword - node->base)) < alignment) {
482 kfree(node);
483 return(NULL);
484 }
485
486 node->length -= (temp_dword - node->base);
487 node->base = temp_dword;
488 }
489
490 if (node->length & (alignment - 1)) {
491 /* There's stuff in use after this node */
492 kfree(node);
493 return(NULL);
494 }
495
496 return(node);
497}
498
499
500/*
501 * get_io_resource
502 *
503 * this function sorts the resource list by size and then
504 * returns the first node of "size" length that is not in the
505 * ISA aliasing window. If it finds a node larger than "size"
506 * it will split it up.
507 *
508 * size must be a power of two.
509 */
510static struct pci_resource *get_io_resource (struct pci_resource **head, u32 size)
511{
512 struct pci_resource *prevnode;
513 struct pci_resource *node;
514 struct pci_resource *split_node = NULL;
515 u32 temp_dword;
516
517 if (!(*head))
518 return(NULL);
519
520 if ( shpchp_resource_sort_and_combine(head) )
521 return(NULL);
522
523 if ( sort_by_size(head) )
524 return(NULL);
525
526 for (node = *head; node; node = node->next) {
527 if (node->length < size)
528 continue;
529
530 if (node->base & (size - 1)) {
531 /* This one isn't base aligned properly
532 so we'll make a new entry and split it up */
533 temp_dword = (node->base | (size-1)) + 1;
534
535 /*/ Short circuit if adjusted size is too small */
536 if ((node->length - (temp_dword - node->base)) < size)
537 continue;
538
539 split_node = kmalloc(sizeof(*split_node), GFP_KERNEL);
540
541 if (!split_node)
542 return(NULL);
543
544 split_node->base = node->base;
545 split_node->length = temp_dword - node->base;
546 node->base = temp_dword;
547 node->length -= split_node->length;
548
549 /* Put it in the list */
550 split_node->next = node->next;
551 node->next = split_node;
552 } /* End of non-aligned base */
553
554 /* Don't need to check if too small since we already did */
555 if (node->length > size) {
556 /* This one is longer than we need
557 so we'll make a new entry and split it up */
558 split_node = kmalloc(sizeof(*split_node), GFP_KERNEL);
559
560 if (!split_node)
561 return(NULL);
562
563 split_node->base = node->base + size;
564 split_node->length = node->length - size;
565 node->length = size;
566
567 /* Put it in the list */
568 split_node->next = node->next;
569 node->next = split_node;
570 } /* End of too big on top end */
571
572 /* For IO make sure it's not in the ISA aliasing space */
573 if (node->base & 0x300L)
574 continue;
575
576 /* If we got here, then it is the right size
577 Now take it out of the list */
578 if (*head == node) {
579 *head = node->next;
580 } else {
581 prevnode = *head;
582 while (prevnode->next != node)
583 prevnode = prevnode->next;
584
585 prevnode->next = node->next;
586 }
587 node->next = NULL;
588 /* Stop looping */
589 break;
590 }
591
592 return(node);
593}
594
595
596/*
597 * get_max_resource
598 *
599 * Gets the largest node that is at least "size" big from the
600 * list pointed to by head. It aligns the node on top and bottom
601 * to "size" alignment before returning it.
602 * J.I. modified to put max size limits of; 64M->32M->16M->8M->4M->1M
603 * This is needed to avoid allocating entire ACPI _CRS res to one child bridge/slot.
604 */
605static struct pci_resource *get_max_resource (struct pci_resource **head, u32 size)
606{
607 struct pci_resource *max;
608 struct pci_resource *temp;
609 struct pci_resource *split_node;
610 u32 temp_dword;
611 u32 max_size[] = { 0x4000000, 0x2000000, 0x1000000, 0x0800000, 0x0400000, 0x0200000, 0x0100000, 0x00 };
612 int i;
613
614 if (!(*head))
615 return(NULL);
616
617 if (shpchp_resource_sort_and_combine(head))
618 return(NULL);
619
620 if (sort_by_max_size(head))
621 return(NULL);
622
623 for (max = *head;max; max = max->next) {
624
625 /* If not big enough we could probably just bail,
626 instead we'll continue to the next. */
627 if (max->length < size)
628 continue;
629
630 if (max->base & (size - 1)) {
631 /* This one isn't base aligned properly
632 so we'll make a new entry and split it up */
633 temp_dword = (max->base | (size-1)) + 1;
634
635 /* Short circuit if adjusted size is too small */
636 if ((max->length - (temp_dword - max->base)) < size)
637 continue;
638
639 split_node = kmalloc(sizeof(*split_node), GFP_KERNEL);
640
641 if (!split_node)
642 return(NULL);
643
644 split_node->base = max->base;
645 split_node->length = temp_dword - max->base;
646 max->base = temp_dword;
647 max->length -= split_node->length;
648
649 /* Put it next in the list */
650 split_node->next = max->next;
651 max->next = split_node;
652 }
653
654 if ((max->base + max->length) & (size - 1)) {
655 /* This one isn't end aligned properly at the top
656 so we'll make a new entry and split it up */
657 split_node = kmalloc(sizeof(*split_node), GFP_KERNEL);
658
659 if (!split_node)
660 return(NULL);
661 temp_dword = ((max->base + max->length) & ~(size - 1));
662 split_node->base = temp_dword;
663 split_node->length = max->length + max->base
664 - split_node->base;
665 max->length -= split_node->length;
666
667 /* Put it in the list */
668 split_node->next = max->next;
669 max->next = split_node;
670 }
671
672 /* Make sure it didn't shrink too much when we aligned it */
673 if (max->length < size)
674 continue;
675
676 for ( i = 0; max_size[i] > size; i++) {
677 if (max->length > max_size[i]) {
678 split_node = kmalloc(sizeof(*split_node),
679 GFP_KERNEL);
680 if (!split_node)
681 break; /* return (NULL); */
682 split_node->base = max->base + max_size[i];
683 split_node->length = max->length - max_size[i];
684 max->length = max_size[i];
685 /* Put it next in the list */
686 split_node->next = max->next;
687 max->next = split_node;
688 break;
689 }
690 }
691
692 /* Now take it out of the list */
693 temp = (struct pci_resource*) *head;
694 if (temp == max) {
695 *head = max->next;
696 } else {
697 while (temp && temp->next != max) {
698 temp = temp->next;
699 }
700
701 temp->next = max->next;
702 }
703
704 max->next = NULL;
705 return(max);
706 }
707
708 /* If we get here, we couldn't find one */
709 return(NULL);
710}
711
712
713/*
714 * get_resource
715 *
716 * this function sorts the resource list by size and then
717 * returns the first node of "size" length. If it finds a node
718 * larger than "size" it will split it up.
719 *
720 * size must be a power of two.
721 */
722static struct pci_resource *get_resource (struct pci_resource **head, u32 size)
723{
724 struct pci_resource *prevnode;
725 struct pci_resource *node;
726 struct pci_resource *split_node;
727 u32 temp_dword;
728
729 if (!(*head))
730 return(NULL);
731
732 if ( shpchp_resource_sort_and_combine(head) )
733 return(NULL);
734
735 if ( sort_by_size(head) )
736 return(NULL);
737
738 for (node = *head; node; node = node->next) {
739 dbg("%s: req_size =0x%x node=%p, base=0x%x, length=0x%x\n",
740 __FUNCTION__, size, node, node->base, node->length);
741 if (node->length < size)
742 continue;
743
744 if (node->base & (size - 1)) {
745 dbg("%s: not aligned\n", __FUNCTION__);
746 /* this one isn't base aligned properly
747 so we'll make a new entry and split it up */
748 temp_dword = (node->base | (size-1)) + 1;
749
750 /* Short circuit if adjusted size is too small */
751 if ((node->length - (temp_dword - node->base)) < size)
752 continue;
753
754 split_node = kmalloc(sizeof(*split_node), GFP_KERNEL);
755
756 if (!split_node)
757 return(NULL);
758
759 split_node->base = node->base;
760 split_node->length = temp_dword - node->base;
761 node->base = temp_dword;
762 node->length -= split_node->length;
763
764 /* Put it in the list */
765 split_node->next = node->next;
766 node->next = split_node;
767 } /* End of non-aligned base */
768
769 /* Don't need to check if too small since we already did */
770 if (node->length > size) {
771 dbg("%s: too big\n", __FUNCTION__);
772 /* this one is longer than we need
773 so we'll make a new entry and split it up */
774 split_node = kmalloc(sizeof(*split_node), GFP_KERNEL);
775
776 if (!split_node)
777 return(NULL);
778
779 split_node->base = node->base + size;
780 split_node->length = node->length - size;
781 node->length = size;
782
783 /* Put it in the list */
784 split_node->next = node->next;
785 node->next = split_node;
786 } /* End of too big on top end */
787
788 dbg("%s: got one!!!\n", __FUNCTION__);
789 /* If we got here, then it is the right size
790 Now take it out of the list */
791 if (*head == node) {
792 *head = node->next;
793 } else {
794 prevnode = *head;
795 while (prevnode->next != node)
796 prevnode = prevnode->next;
797
798 prevnode->next = node->next;
799 }
800 node->next = NULL;
801 /* Stop looping */
802 break;
803 }
804 return(node);
805}
806
807
808/*
809 * shpchp_resource_sort_and_combine
810 *
811 * Sorts all of the nodes in the list in ascending order by
812 * their base addresses. Also does garbage collection by
813 * combining adjacent nodes.
814 *
815 * returns 0 if success
816 */
817int shpchp_resource_sort_and_combine(struct pci_resource **head)
818{
819 struct pci_resource *node1;
820 struct pci_resource *node2;
821 int out_of_order = 1;
822
823 dbg("%s: head = %p, *head = %p\n", __FUNCTION__, head, *head);
824
825 if (!(*head))
826 return(1);
827
828 dbg("*head->next = %p\n",(*head)->next);
829
830 if (!(*head)->next)
831 return(0); /* only one item on the list, already sorted! */
832
833 dbg("*head->base = 0x%x\n",(*head)->base);
834 dbg("*head->next->base = 0x%x\n",(*head)->next->base);
835 while (out_of_order) {
836 out_of_order = 0;
837
838 /* Special case for swapping list head */
839 if (((*head)->next) &&
840 ((*head)->base > (*head)->next->base)) {
841 node1 = *head;
842 (*head) = (*head)->next;
843 node1->next = (*head)->next;
844 (*head)->next = node1;
845 out_of_order++;
846 }
847
848 node1 = (*head);
849
850 while (node1->next && node1->next->next) {
851 if (node1->next->base > node1->next->next->base) {
852 out_of_order++;
853 node2 = node1->next;
854 node1->next = node1->next->next;
855 node1 = node1->next;
856 node2->next = node1->next;
857 node1->next = node2;
858 } else
859 node1 = node1->next;
860 }
861 } /* End of out_of_order loop */
862
863 node1 = *head;
864
865 while (node1 && node1->next) {
866 if ((node1->base + node1->length) == node1->next->base) {
867 /* Combine */
868 dbg("8..\n");
869 node1->length += node1->next->length;
870 node2 = node1->next;
871 node1->next = node1->next->next;
872 kfree(node2);
873 } else
874 node1 = node1->next;
875 }
876
877 return(0);
878}
879
880
881/**
882 * shpchp_slot_create - Creates a node and adds it to the proper bus.
883 * @busnumber - bus where new node is to be located
884 *
885 * Returns pointer to the new node or NULL if unsuccessful
886 */
887struct pci_func *shpchp_slot_create(u8 busnumber)
888{
889 struct pci_func *new_slot;
890 struct pci_func *next;
891
892 new_slot = kmalloc(sizeof(*new_slot), GFP_KERNEL);
893
894 if (new_slot == NULL) {
895 return(new_slot);
896 }
897
898 memset(new_slot, 0, sizeof(struct pci_func));
899
900 new_slot->next = NULL;
901 new_slot->configured = 1;
902
903 if (shpchp_slot_list[busnumber] == NULL) {
904 shpchp_slot_list[busnumber] = new_slot;
905 } else {
906 next = shpchp_slot_list[busnumber];
907 while (next->next != NULL)
908 next = next->next;
909 next->next = new_slot;
910 }
911 return(new_slot);
912}
913
914
915/*
916 * slot_remove - Removes a node from the linked list of slots.
917 * @old_slot: slot to remove
918 *
919 * Returns 0 if successful, !0 otherwise.
920 */
921static int slot_remove(struct pci_func * old_slot)
922{
923 struct pci_func *next;
924
925 if (old_slot == NULL)
926 return(1);
927
928 next = shpchp_slot_list[old_slot->bus];
929
930 if (next == NULL) {
931 return(1);
932 }
933
934 if (next == old_slot) {
935 shpchp_slot_list[old_slot->bus] = old_slot->next;
936 shpchp_destroy_board_resources(old_slot);
937 kfree(old_slot);
938 return(0);
939 }
940
941 while ((next->next != old_slot) && (next->next != NULL)) {
942 next = next->next;
943 }
944
945 if (next->next == old_slot) {
946 next->next = old_slot->next;
947 shpchp_destroy_board_resources(old_slot);
948 kfree(old_slot);
949 return(0);
950 } else
951 return(2);
952}
953
954
955/**
956 * bridge_slot_remove - Removes a node from the linked list of slots.
957 * @bridge: bridge to remove
958 *
959 * Returns 0 if successful, !0 otherwise.
960 */
961static int bridge_slot_remove(struct pci_func *bridge)
962{
963 u8 subordinateBus, secondaryBus;
964 u8 tempBus;
965 struct pci_func *next;
966
967 if (bridge == NULL)
968 return(1);
969
970 secondaryBus = (bridge->config_space[0x06] >> 8) & 0xFF;
971 subordinateBus = (bridge->config_space[0x06] >> 16) & 0xFF;
972
973 for (tempBus = secondaryBus; tempBus <= subordinateBus; tempBus++) {
974 next = shpchp_slot_list[tempBus];
975
976 while (!slot_remove(next)) {
977 next = shpchp_slot_list[tempBus];
978 }
979 }
980
981 next = shpchp_slot_list[bridge->bus];
982
983 if (next == NULL) {
984 return(1);
985 }
986
987 if (next == bridge) {
988 shpchp_slot_list[bridge->bus] = bridge->next;
989 kfree(bridge);
990 return(0);
991 }
992
993 while ((next->next != bridge) && (next->next != NULL)) {
994 next = next->next;
995 }
996
997 if (next->next == bridge) {
998 next->next = bridge->next;
999 kfree(bridge);
1000 return(0);
1001 } else
1002 return(2);
1003}
1004
1005
1006/**
1007 * shpchp_slot_find - Looks for a node by bus, and device, multiple functions accessed
1008 * @bus: bus to find
1009 * @device: device to find
1010 * @index: is 0 for first function found, 1 for the second...
1011 *
1012 * Returns pointer to the node if successful, %NULL otherwise.
1013 */
1014struct pci_func *shpchp_slot_find(u8 bus, u8 device, u8 index)
1015{
1016 int found = -1;
1017 struct pci_func *func;
1018
1019 func = shpchp_slot_list[bus];
1020
1021 if ((func == NULL) || ((func->device == device) && (index == 0)))
1022 return(func);
1023
1024 if (func->device == device)
1025 found++;
1026
1027 while (func->next != NULL) {
1028 func = func->next;
1029
1030 if (func->device == device)
1031 found++;
1032
1033 if (found == index)
1034 return(func);
1035 }
1036
1037 return(NULL);
1038}
1039
1040static int is_bridge(struct pci_func * func)
1041{
1042 /* Check the header type */
1043 if (((func->config_space[0x03] >> 16) & 0xFF) == 0x01)
1044 return 1;
1045 else
1046 return 0;
1047}
1048
1049
1050/* The following routines constitute the bulk of the 236/* The following routines constitute the bulk of the
1051 hotplug controller logic 237 hotplug controller logic
1052 */ 238 */
1053static u32 change_bus_speed(struct controller *ctrl, struct slot *p_slot, enum pci_bus_speed speed) 239static int change_bus_speed(struct controller *ctrl, struct slot *p_slot,
240 enum pci_bus_speed speed)
1054{ 241{
1055 u32 rc = 0; 242 int rc = 0;
1056 243
1057 dbg("%s: change to speed %d\n", __FUNCTION__, speed); 244 dbg("%s: change to speed %d\n", __FUNCTION__, speed);
1058 down(&ctrl->crit_sect); 245 down(&ctrl->crit_sect);
@@ -1074,10 +261,11 @@ static u32 change_bus_speed(struct controller *ctrl, struct slot *p_slot, enum p
1074 return rc; 261 return rc;
1075} 262}
1076 263
1077static u32 fix_bus_speed(struct controller *ctrl, struct slot *pslot, u8 flag, 264static int fix_bus_speed(struct controller *ctrl, struct slot *pslot,
1078enum pci_bus_speed asp, enum pci_bus_speed bsp, enum pci_bus_speed msp) 265 u8 flag, enum pci_bus_speed asp, enum pci_bus_speed bsp,
266 enum pci_bus_speed msp)
1079{ 267{
1080 u32 rc = 0; 268 int rc = 0;
1081 269
1082 if (flag != 0) { /* Other slots on the same bus are occupied */ 270 if (flag != 0) { /* Other slots on the same bus are occupied */
1083 if ( asp < bsp ) { 271 if ( asp < bsp ) {
@@ -1116,23 +304,20 @@ enum pci_bus_speed asp, enum pci_bus_speed bsp, enum pci_bus_speed msp)
1116 * Configures board 304 * Configures board
1117 * 305 *
1118 */ 306 */
1119static u32 board_added(struct pci_func * func, struct controller * ctrl) 307static int board_added(struct slot *p_slot)
1120{ 308{
1121 u8 hp_slot; 309 u8 hp_slot;
1122 u8 slots_not_empty = 0; 310 u8 slots_not_empty = 0;
1123 int index; 311 int rc = 0;
1124 u32 temp_register = 0xFFFFFFFF;
1125 u32 retval, rc = 0;
1126 struct pci_func *new_func = NULL;
1127 struct slot *p_slot;
1128 struct resource_lists res_lists;
1129 enum pci_bus_speed adapter_speed, bus_speed, max_bus_speed; 312 enum pci_bus_speed adapter_speed, bus_speed, max_bus_speed;
1130 u8 pi, mode; 313 u8 pi, mode;
314 struct controller *ctrl = p_slot->ctrl;
1131 315
1132 p_slot = shpchp_find_slot(ctrl, func->device); 316 hp_slot = p_slot->device - ctrl->slot_device_offset;
1133 hp_slot = func->device - ctrl->slot_device_offset;
1134 317
1135 dbg("%s: func->device, slot_offset, hp_slot = %d, %d ,%d\n", __FUNCTION__, func->device, ctrl->slot_device_offset, hp_slot); 318 dbg("%s: p_slot->device, slot_offset, hp_slot = %d, %d ,%d\n",
319 __FUNCTION__, p_slot->device,
320 ctrl->slot_device_offset, hp_slot);
1136 321
1137 /* Wait for exclusive access to hardware */ 322 /* Wait for exclusive access to hardware */
1138 down(&ctrl->crit_sect); 323 down(&ctrl->crit_sect);
@@ -1320,143 +505,68 @@ static u32 board_added(struct pci_func * func, struct controller * ctrl)
1320 up(&ctrl->crit_sect); 505 up(&ctrl->crit_sect);
1321 506
1322 /* Wait for ~1 second */ 507 /* Wait for ~1 second */
1323 dbg("%s: before long_delay\n", __FUNCTION__);
1324 wait_for_ctrl_irq (ctrl); 508 wait_for_ctrl_irq (ctrl);
1325 dbg("%s: after long_delay\n", __FUNCTION__);
1326 509
1327 dbg("%s: func status = %x\n", __FUNCTION__, func->status); 510 dbg("%s: slot status = %x\n", __FUNCTION__, p_slot->status);
1328 /* Check for a power fault */ 511 /* Check for a power fault */
1329 if (func->status == 0xFF) { 512 if (p_slot->status == 0xFF) {
1330 /* power fault occurred, but it was benign */ 513 /* power fault occurred, but it was benign */
1331 temp_register = 0xFFFFFFFF; 514 dbg("%s: power fault\n", __FUNCTION__);
1332 dbg("%s: temp register set to %x by power fault\n", __FUNCTION__, temp_register);
1333 rc = POWER_FAILURE; 515 rc = POWER_FAILURE;
1334 func->status = 0; 516 p_slot->status = 0;
1335 } else { 517 goto err_exit;
1336 /* Get vendor/device ID u32 */
1337 rc = pci_bus_read_config_dword (ctrl->pci_dev->subordinate, PCI_DEVFN(func->device, func->function),
1338 PCI_VENDOR_ID, &temp_register);
1339 dbg("%s: pci_bus_read_config_dword returns %d\n", __FUNCTION__, rc);
1340 dbg("%s: temp_register is %x\n", __FUNCTION__, temp_register);
1341
1342 if (rc != 0) {
1343 /* Something's wrong here */
1344 temp_register = 0xFFFFFFFF;
1345 dbg("%s: temp register set to %x by error\n", __FUNCTION__, temp_register);
1346 }
1347 /* Preset return code. It will be changed later if things go okay. */
1348 rc = NO_ADAPTER_PRESENT;
1349 } 518 }
1350 519
1351 /* All F's is an empty slot or an invalid board */ 520 if (shpchp_configure_device(p_slot)) {
1352 if (temp_register != 0xFFFFFFFF) { /* Check for a board in the slot */ 521 err("Cannot add device at 0x%x:0x%x\n", p_slot->bus,
1353 res_lists.io_head = ctrl->io_head; 522 p_slot->device);
1354 res_lists.mem_head = ctrl->mem_head; 523 goto err_exit;
1355 res_lists.p_mem_head = ctrl->p_mem_head; 524 }
1356 res_lists.bus_head = ctrl->bus_head;
1357 res_lists.irqs = NULL;
1358
1359 rc = configure_new_device(ctrl, func, 0, &res_lists, 0, 0);
1360 dbg("%s: back from configure_new_device\n", __FUNCTION__);
1361
1362 ctrl->io_head = res_lists.io_head;
1363 ctrl->mem_head = res_lists.mem_head;
1364 ctrl->p_mem_head = res_lists.p_mem_head;
1365 ctrl->bus_head = res_lists.bus_head;
1366
1367 shpchp_resource_sort_and_combine(&(ctrl->mem_head));
1368 shpchp_resource_sort_and_combine(&(ctrl->p_mem_head));
1369 shpchp_resource_sort_and_combine(&(ctrl->io_head));
1370 shpchp_resource_sort_and_combine(&(ctrl->bus_head));
1371
1372 if (rc) {
1373 /* Wait for exclusive access to hardware */
1374 down(&ctrl->crit_sect);
1375
1376 /* turn off slot, turn on Amber LED, turn off Green LED */
1377 retval = p_slot->hpc_ops->slot_disable(p_slot);
1378 if (retval) {
1379 err("%s: Issue of Slot Enable command failed\n", __FUNCTION__);
1380 /* Done with exclusive hardware access */
1381 up(&ctrl->crit_sect);
1382 return retval;
1383 }
1384 /* Wait for the command to complete */
1385 wait_for_ctrl_irq (ctrl);
1386
1387 retval = p_slot->hpc_ops->check_cmd_status(ctrl);
1388 if (retval) {
1389 err("%s: Failed to disable slot, error code(%d)\n", __FUNCTION__, retval);
1390 /* Done with exclusive hardware access */
1391 up(&ctrl->crit_sect);
1392 return retval;
1393 }
1394
1395 /* Done with exclusive hardware access */
1396 up(&ctrl->crit_sect);
1397 525
1398 return(rc); 526 p_slot->status = 0;
1399 } 527 p_slot->is_a_board = 0x01;
1400 shpchp_save_slot_config(ctrl, func); 528 p_slot->pwr_save = 1;
1401 529
1402 func->status = 0; 530 /* Wait for exclusive access to hardware */
1403 func->switch_save = 0x10; 531 down(&ctrl->crit_sect);
1404 func->is_a_board = 0x01;
1405 func->pwr_save = 1;
1406 532
1407 /* Next, we will instantiate the linux pci_dev structures 533 p_slot->hpc_ops->green_led_on(p_slot);
1408 * (with appropriate driver notification, if already present)
1409 */
1410 index = 0;
1411 do {
1412 new_func = shpchp_slot_find(ctrl->slot_bus, func->device, index++);
1413 if (new_func && !new_func->pci_dev) {
1414 dbg("%s:call pci_hp_configure_dev\n", __FUNCTION__);
1415 shpchp_configure_device(ctrl, new_func);
1416 }
1417 } while (new_func);
1418 534
1419 /* Wait for exclusive access to hardware */ 535 /* Wait for the command to complete */
1420 down(&ctrl->crit_sect); 536 wait_for_ctrl_irq (ctrl);
1421 537
1422 p_slot->hpc_ops->green_led_on(p_slot); 538 /* Done with exclusive hardware access */
539 up(&ctrl->crit_sect);
1423 540
1424 /* Wait for the command to complete */ 541 return 0;
1425 wait_for_ctrl_irq (ctrl);
1426 542
543err_exit:
544 /* Wait for exclusive access to hardware */
545 down(&ctrl->crit_sect);
1427 546
547 /* turn off slot, turn on Amber LED, turn off Green LED */
548 rc = p_slot->hpc_ops->slot_disable(p_slot);
549 if (rc) {
550 err("%s: Issue of Slot Disable command failed\n", __FUNCTION__);
1428 /* Done with exclusive hardware access */ 551 /* Done with exclusive hardware access */
1429 up(&ctrl->crit_sect); 552 up(&ctrl->crit_sect);
553 return rc;
554 }
555 /* Wait for the command to complete */
556 wait_for_ctrl_irq (ctrl);
1430 557
1431 } else { 558 rc = p_slot->hpc_ops->check_cmd_status(ctrl);
1432 /* Wait for exclusive access to hardware */ 559 if (rc) {
1433 down(&ctrl->crit_sect); 560 err("%s: Failed to disable slot, error code(%d)\n", __FUNCTION__, rc);
1434
1435 /* turn off slot, turn on Amber LED, turn off Green LED */
1436 rc = p_slot->hpc_ops->slot_disable(p_slot);
1437 if (rc) {
1438 err("%s: Issue of Slot Disable command failed\n", __FUNCTION__);
1439 /* Done with exclusive hardware access */
1440 up(&ctrl->crit_sect);
1441 return rc;
1442 }
1443 /* Wait for the command to complete */
1444 wait_for_ctrl_irq (ctrl);
1445
1446 rc = p_slot->hpc_ops->check_cmd_status(ctrl);
1447 if (rc) {
1448 err("%s: Failed to disable slot, error code(%d)\n", __FUNCTION__, rc);
1449 /* Done with exclusive hardware access */
1450 up(&ctrl->crit_sect);
1451 return rc;
1452 }
1453
1454 /* Done with exclusive hardware access */ 561 /* Done with exclusive hardware access */
1455 up(&ctrl->crit_sect); 562 up(&ctrl->crit_sect);
1456 563 return rc;
1457 return(rc);
1458 } 564 }
1459 return 0; 565
566 /* Done with exclusive hardware access */
567 up(&ctrl->crit_sect);
568
569 return(rc);
1460} 570}
1461 571
1462 572
@@ -1464,55 +574,23 @@ static u32 board_added(struct pci_func * func, struct controller * ctrl)
1464 * remove_board - Turns off slot and LED's 574 * remove_board - Turns off slot and LED's
1465 * 575 *
1466 */ 576 */
1467static u32 remove_board(struct pci_func *func, struct controller *ctrl) 577static int remove_board(struct slot *p_slot)
1468{ 578{
1469 int index; 579 struct controller *ctrl = p_slot->ctrl;
1470 u8 skip = 0;
1471 u8 device;
1472 u8 hp_slot; 580 u8 hp_slot;
1473 u32 rc; 581 int rc;
1474 struct resource_lists res_lists;
1475 struct pci_func *temp_func;
1476 struct slot *p_slot;
1477
1478 if (func == NULL)
1479 return(1);
1480 582
1481 if (shpchp_unconfigure_device(func)) 583 if (shpchp_unconfigure_device(p_slot))
1482 return(1); 584 return(1);
1483 585
1484 device = func->device; 586 hp_slot = p_slot->device - ctrl->slot_device_offset;
1485
1486 hp_slot = func->device - ctrl->slot_device_offset;
1487 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); 587 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
1488 588
1489 dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot); 589 dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot);
1490 590
1491 if ((ctrl->add_support) &&
1492 !(func->bus_head || func->mem_head || func->p_mem_head || func->io_head)) {
1493 /* Here we check to see if we've saved any of the board's
1494 * resources already. If so, we'll skip the attempt to
1495 * determine what's being used.
1496 */
1497 index = 0;
1498
1499 temp_func = func;
1500
1501 while ((temp_func = shpchp_slot_find(temp_func->bus, temp_func->device, index++))) {
1502 if (temp_func->bus_head || temp_func->mem_head
1503 || temp_func->p_mem_head || temp_func->io_head) {
1504 skip = 1;
1505 break;
1506 }
1507 }
1508
1509 if (!skip)
1510 rc = shpchp_save_used_resources(ctrl, func, DISABLE_CARD);
1511 }
1512 /* Change status to shutdown */ 591 /* Change status to shutdown */
1513 if (func->is_a_board) 592 if (p_slot->is_a_board)
1514 func->status = 0x01; 593 p_slot->status = 0x01;
1515 func->configured = 0;
1516 594
1517 /* Wait for exclusive access to hardware */ 595 /* Wait for exclusive access to hardware */
1518 down(&ctrl->crit_sect); 596 down(&ctrl->crit_sect);
@@ -1549,55 +627,8 @@ static u32 remove_board(struct pci_func *func, struct controller *ctrl)
1549 /* Done with exclusive hardware access */ 627 /* Done with exclusive hardware access */
1550 up(&ctrl->crit_sect); 628 up(&ctrl->crit_sect);
1551 629
1552 if (ctrl->add_support) { 630 p_slot->pwr_save = 0;
1553 while (func) { 631 p_slot->is_a_board = 0;
1554 res_lists.io_head = ctrl->io_head;
1555 res_lists.mem_head = ctrl->mem_head;
1556 res_lists.p_mem_head = ctrl->p_mem_head;
1557 res_lists.bus_head = ctrl->bus_head;
1558
1559 dbg("Returning resources to ctlr lists for (B/D/F) = (%#x/%#x/%#x)\n", func->bus,
1560 func->device, func->function);
1561
1562 shpchp_return_board_resources(func, &res_lists);
1563
1564 ctrl->io_head = res_lists.io_head;
1565 ctrl->mem_head = res_lists.mem_head;
1566 ctrl->p_mem_head = res_lists.p_mem_head;
1567 ctrl->bus_head = res_lists.bus_head;
1568
1569 shpchp_resource_sort_and_combine(&(ctrl->mem_head));
1570 shpchp_resource_sort_and_combine(&(ctrl->p_mem_head));
1571 shpchp_resource_sort_and_combine(&(ctrl->io_head));
1572 shpchp_resource_sort_and_combine(&(ctrl->bus_head));
1573
1574 if (is_bridge(func)) {
1575 dbg("PCI Bridge Hot-Remove s:b:d:f(%02x:%02x:%02x:%02x)\n", ctrl->seg, func->bus,
1576 func->device, func->function);
1577 bridge_slot_remove(func);
1578 } else
1579 dbg("PCI Function Hot-Remove s:b:d:f(%02x:%02x:%02x:%02x)\n", ctrl->seg, func->bus,
1580 func->device, func->function);
1581 slot_remove(func);
1582
1583 func = shpchp_slot_find(ctrl->slot_bus, device, 0);
1584 }
1585
1586 /* Setup slot structure with entry for empty slot */
1587 func = shpchp_slot_create(ctrl->slot_bus);
1588
1589 if (func == NULL) {
1590 return(1);
1591 }
1592
1593 func->bus = ctrl->slot_bus;
1594 func->device = device;
1595 func->function = 0;
1596 func->configured = 0;
1597 func->switch_save = 0x10;
1598 func->pwr_save = 0;
1599 func->is_a_board = 0;
1600 }
1601 632
1602 return 0; 633 return 0;
1603} 634}
@@ -1633,13 +664,11 @@ static void shpchp_pushbutton_thread (unsigned long slot)
1633 p_slot->hpc_ops->get_power_status(p_slot, &getstatus); 664 p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
1634 if (getstatus) { 665 if (getstatus) {
1635 p_slot->state = POWEROFF_STATE; 666 p_slot->state = POWEROFF_STATE;
1636 dbg("In power_down_board, b:d(%x:%x)\n", p_slot->bus, p_slot->device);
1637 667
1638 shpchp_disable_slot(p_slot); 668 shpchp_disable_slot(p_slot);
1639 p_slot->state = STATIC_STATE; 669 p_slot->state = STATIC_STATE;
1640 } else { 670 } else {
1641 p_slot->state = POWERON_STATE; 671 p_slot->state = POWERON_STATE;
1642 dbg("In add_board, b:d(%x:%x)\n", p_slot->bus, p_slot->device);
1643 672
1644 if (shpchp_enable_slot(p_slot)) { 673 if (shpchp_enable_slot(p_slot)) {
1645 /* Wait for exclusive access to hardware */ 674 /* Wait for exclusive access to hardware */
@@ -1701,7 +730,6 @@ int shpchp_event_start_thread (void)
1701 err ("Can't start up our event thread\n"); 730 err ("Can't start up our event thread\n");
1702 return -1; 731 return -1;
1703 } 732 }
1704 dbg("Our event thread pid = %d\n", pid);
1705 return 0; 733 return 0;
1706} 734}
1707 735
@@ -1709,9 +737,7 @@ int shpchp_event_start_thread (void)
1709void shpchp_event_stop_thread (void) 737void shpchp_event_stop_thread (void)
1710{ 738{
1711 event_finished = 1; 739 event_finished = 1;
1712 dbg("event_thread finish command given\n");
1713 up(&event_semaphore); 740 up(&event_semaphore);
1714 dbg("wait for event_thread to exit\n");
1715 down(&event_exit); 741 down(&event_exit);
1716} 742}
1717 743
@@ -1739,12 +765,10 @@ static void interrupt_event_handler(struct controller *ctrl)
1739{ 765{
1740 int loop = 0; 766 int loop = 0;
1741 int change = 1; 767 int change = 1;
1742 struct pci_func *func;
1743 u8 hp_slot; 768 u8 hp_slot;
1744 u8 getstatus; 769 u8 getstatus;
1745 struct slot *p_slot; 770 struct slot *p_slot;
1746 771
1747 dbg("%s:\n", __FUNCTION__);
1748 while (change) { 772 while (change) {
1749 change = 0; 773 change = 0;
1750 774
@@ -1754,12 +778,8 @@ static void interrupt_event_handler(struct controller *ctrl)
1754 ctrl->event_queue[loop].event_type); 778 ctrl->event_queue[loop].event_type);
1755 hp_slot = ctrl->event_queue[loop].hp_slot; 779 hp_slot = ctrl->event_queue[loop].hp_slot;
1756 780
1757 func = shpchp_slot_find(ctrl->slot_bus, (hp_slot + ctrl->slot_device_offset), 0);
1758
1759 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); 781 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
1760 782
1761 dbg("%s: hp_slot %d, func %p, p_slot %p\n", __FUNCTION__, hp_slot, func, p_slot);
1762
1763 if (ctrl->event_queue[loop].event_type == INT_BUTTON_CANCEL) { 783 if (ctrl->event_queue[loop].event_type == INT_BUTTON_CANCEL) {
1764 dbg("%s: button cancel\n", __FUNCTION__); 784 dbg("%s: button cancel\n", __FUNCTION__);
1765 del_timer(&p_slot->task_event); 785 del_timer(&p_slot->task_event);
@@ -1880,13 +900,6 @@ int shpchp_enable_slot (struct slot *p_slot)
1880{ 900{
1881 u8 getstatus = 0; 901 u8 getstatus = 0;
1882 int rc; 902 int rc;
1883 struct pci_func *func;
1884
1885 func = shpchp_slot_find(p_slot->bus, p_slot->device, 0);
1886 if (!func) {
1887 dbg("%s: Error! slot NULL\n", __FUNCTION__);
1888 return -ENODEV;
1889 }
1890 903
1891 /* Check to see if (latch closed, card present, power off) */ 904 /* Check to see if (latch closed, card present, power off) */
1892 down(&p_slot->ctrl->crit_sect); 905 down(&p_slot->ctrl->crit_sect);
@@ -1910,72 +923,34 @@ int shpchp_enable_slot (struct slot *p_slot)
1910 } 923 }
1911 up(&p_slot->ctrl->crit_sect); 924 up(&p_slot->ctrl->crit_sect);
1912 925
1913 slot_remove(func); 926 p_slot->is_a_board = 1;
1914
1915 func = shpchp_slot_create(p_slot->bus);
1916 if (func == NULL)
1917 return -ENOMEM;
1918
1919 func->bus = p_slot->bus;
1920 func->device = p_slot->device;
1921 func->function = 0;
1922 func->configured = 0;
1923 func->is_a_board = 1;
1924 927
1925 /* We have to save the presence info for these slots */ 928 /* We have to save the presence info for these slots */
1926 p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save)); 929 p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save));
1927 p_slot->hpc_ops->get_power_status(p_slot, &(func->pwr_save)); 930 p_slot->hpc_ops->get_power_status(p_slot, &(p_slot->pwr_save));
1928 dbg("%s: func->pwr_save %x\n", __FUNCTION__, func->pwr_save); 931 dbg("%s: p_slot->pwr_save %x\n", __FUNCTION__, p_slot->pwr_save);
1929 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 932 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
1930 func->switch_save = !getstatus? 0x10:0;
1931 933
1932 rc = board_added(func, p_slot->ctrl); 934 rc = board_added(p_slot);
1933 if (rc) { 935 if (rc) {
1934 if (is_bridge(func)) 936 p_slot->hpc_ops->get_adapter_status(p_slot,
1935 bridge_slot_remove(func); 937 &(p_slot->presence_save));
1936 else
1937 slot_remove(func);
1938
1939 /* Setup slot structure with entry for empty slot */
1940 func = shpchp_slot_create(p_slot->bus);
1941 if (func == NULL)
1942 return -ENOMEM; /* Out of memory */
1943
1944 func->bus = p_slot->bus;
1945 func->device = p_slot->device;
1946 func->function = 0;
1947 func->configured = 0;
1948 func->is_a_board = 1;
1949
1950 /* We have to save the presence info for these slots */
1951 p_slot->hpc_ops->get_adapter_status(p_slot, &(func->presence_save));
1952 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 938 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
1953 func->switch_save = !getstatus? 0x10:0;
1954 } 939 }
1955 940
1956 if (p_slot) 941 update_slot_info(p_slot);
1957 update_slot_info(p_slot);
1958
1959 return rc; 942 return rc;
1960} 943}
1961 944
1962 945
1963int shpchp_disable_slot (struct slot *p_slot) 946int shpchp_disable_slot (struct slot *p_slot)
1964{ 947{
1965 u8 class_code, header_type, BCR;
1966 u8 index = 0;
1967 u8 getstatus = 0; 948 u8 getstatus = 0;
1968 u32 rc = 0;
1969 int ret = 0; 949 int ret = 0;
1970 unsigned int devfn;
1971 struct pci_bus *pci_bus;
1972 struct pci_func *func;
1973 950
1974 if (!p_slot->ctrl) 951 if (!p_slot->ctrl)
1975 return -ENODEV; 952 return -ENODEV;
1976 953
1977 pci_bus = p_slot->ctrl->pci_dev->subordinate;
1978
1979 /* Check to see if (latch closed, card present, power on) */ 954 /* Check to see if (latch closed, card present, power on) */
1980 down(&p_slot->ctrl->crit_sect); 955 down(&p_slot->ctrl->crit_sect);
1981 956
@@ -1999,849 +974,8 @@ int shpchp_disable_slot (struct slot *p_slot)
1999 } 974 }
2000 up(&p_slot->ctrl->crit_sect); 975 up(&p_slot->ctrl->crit_sect);
2001 976
2002 func = shpchp_slot_find(p_slot->bus, p_slot->device, index++); 977 ret = remove_board(p_slot);
2003 978 update_slot_info(p_slot);
2004 /* Make sure there are no video controllers here 979 return ret;
2005 * for all func of p_slot
2006 */
2007 while (func && !rc) {
2008 pci_bus->number = func->bus;
2009 devfn = PCI_DEVFN(func->device, func->function);
2010
2011 /* Check the Class Code */
2012 rc = pci_bus_read_config_byte (pci_bus, devfn, 0x0B, &class_code);
2013 if (rc)
2014 return -ENODEV;
2015
2016 if (class_code == PCI_BASE_CLASS_DISPLAY) {
2017 /* Display/Video adapter (not supported) */
2018 rc = REMOVE_NOT_SUPPORTED;
2019 } else {
2020 /* See if it's a bridge */
2021 rc = pci_bus_read_config_byte (pci_bus, devfn, PCI_HEADER_TYPE, &header_type);
2022 if (rc)
2023 return -ENODEV;
2024
2025 /* If it's a bridge, check the VGA Enable bit */
2026 if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) {
2027 rc = pci_bus_read_config_byte (pci_bus, devfn, PCI_BRIDGE_CONTROL, &BCR);
2028 if (rc)
2029 return -ENODEV;
2030
2031 /* If the VGA Enable bit is set, remove isn't supported */
2032 if (BCR & PCI_BRIDGE_CTL_VGA) {
2033 rc = REMOVE_NOT_SUPPORTED;
2034 }
2035 }
2036 }
2037
2038 func = shpchp_slot_find(p_slot->bus, p_slot->device, index++);
2039 }
2040
2041 func = shpchp_slot_find(p_slot->bus, p_slot->device, 0);
2042 if ((func != NULL) && !rc) {
2043 rc = remove_board(func, p_slot->ctrl);
2044 } else if (!rc)
2045 rc = -ENODEV;
2046
2047 if (p_slot)
2048 update_slot_info(p_slot);
2049
2050 return rc;
2051}
2052
2053
2054/**
2055 * configure_new_device - Configures the PCI header information of one board.
2056 *
2057 * @ctrl: pointer to controller structure
2058 * @func: pointer to function structure
2059 * @behind_bridge: 1 if this is a recursive call, 0 if not
2060 * @resources: pointer to set of resource lists
2061 *
2062 * Returns 0 if success
2063 *
2064 */
2065static u32 configure_new_device (struct controller * ctrl, struct pci_func * func,
2066 u8 behind_bridge, struct resource_lists * resources, u8 bridge_bus, u8 bridge_dev)
2067{
2068 u8 temp_byte, function, max_functions, stop_it;
2069 int rc;
2070 u32 ID;
2071 struct pci_func *new_slot;
2072 struct pci_bus lpci_bus, *pci_bus;
2073 int index;
2074
2075 new_slot = func;
2076
2077 dbg("%s\n", __FUNCTION__);
2078 memcpy(&lpci_bus, ctrl->pci_dev->subordinate, sizeof(lpci_bus));
2079 pci_bus = &lpci_bus;
2080 pci_bus->number = func->bus;
2081
2082 /* Check for Multi-function device */
2083 rc = pci_bus_read_config_byte(pci_bus, PCI_DEVFN(func->device, func->function), 0x0E, &temp_byte);
2084 if (rc) {
2085 dbg("%s: rc = %d\n", __FUNCTION__, rc);
2086 return rc;
2087 }
2088
2089 if (temp_byte & 0x80) /* Multi-function device */
2090 max_functions = 8;
2091 else
2092 max_functions = 1;
2093
2094 function = 0;
2095
2096 do {
2097 rc = configure_new_function(ctrl, new_slot, behind_bridge, resources, bridge_bus, bridge_dev);
2098
2099 if (rc) {
2100 dbg("configure_new_function failed %d\n",rc);
2101 index = 0;
2102
2103 while (new_slot) {
2104 new_slot = shpchp_slot_find(new_slot->bus, new_slot->device, index++);
2105
2106 if (new_slot)
2107 shpchp_return_board_resources(new_slot, resources);
2108 }
2109
2110 return(rc);
2111 }
2112
2113 function++;
2114
2115 stop_it = 0;
2116
2117 /* The following loop skips to the next present function
2118 * and creates a board structure
2119 */
2120
2121 while ((function < max_functions) && (!stop_it)) {
2122 pci_bus_read_config_dword(pci_bus, PCI_DEVFN(func->device, function), 0x00, &ID);
2123
2124 if (ID == 0xFFFFFFFF) { /* There's nothing there. */
2125 function++;
2126 } else { /* There's something there */
2127 /* Setup slot structure. */
2128 new_slot = shpchp_slot_create(func->bus);
2129
2130 if (new_slot == NULL) {
2131 /* Out of memory */
2132 return(1);
2133 }
2134
2135 new_slot->bus = func->bus;
2136 new_slot->device = func->device;
2137 new_slot->function = function;
2138 new_slot->is_a_board = 1;
2139 new_slot->status = 0;
2140
2141 stop_it++;
2142 }
2143 }
2144
2145 } while (function < max_functions);
2146 dbg("returning from configure_new_device\n");
2147
2148 return 0;
2149}
2150
2151
2152/*
2153 * Configuration logic that involves the hotplug data structures and
2154 * their bookkeeping
2155 */
2156
2157
2158/**
2159 * configure_new_function - Configures the PCI header information of one device
2160 *
2161 * @ctrl: pointer to controller structure
2162 * @func: pointer to function structure
2163 * @behind_bridge: 1 if this is a recursive call, 0 if not
2164 * @resources: pointer to set of resource lists
2165 *
2166 * Calls itself recursively for bridged devices.
2167 * Returns 0 if success
2168 *
2169 */
2170static int configure_new_function (struct controller * ctrl, struct pci_func * func,
2171 u8 behind_bridge, struct resource_lists *resources, u8 bridge_bus, u8 bridge_dev)
2172{
2173 int cloop;
2174 u8 temp_byte;
2175 u8 device;
2176 u8 class_code;
2177 u16 temp_word;
2178 u32 rc;
2179 u32 temp_register;
2180 u32 base;
2181 u32 ID;
2182 unsigned int devfn;
2183 struct pci_resource *mem_node;
2184 struct pci_resource *p_mem_node;
2185 struct pci_resource *io_node;
2186 struct pci_resource *bus_node;
2187 struct pci_resource *hold_mem_node;
2188 struct pci_resource *hold_p_mem_node;
2189 struct pci_resource *hold_IO_node;
2190 struct pci_resource *hold_bus_node;
2191 struct irq_mapping irqs;
2192 struct pci_func *new_slot;
2193 struct pci_bus lpci_bus, *pci_bus;
2194 struct resource_lists temp_resources;
2195#if defined(CONFIG_X86_64)
2196 u8 IRQ=0;
2197#endif
2198
2199 memcpy(&lpci_bus, ctrl->pci_dev->subordinate, sizeof(lpci_bus));
2200 pci_bus = &lpci_bus;
2201 pci_bus->number = func->bus;
2202 devfn = PCI_DEVFN(func->device, func->function);
2203
2204 /* Check for Bridge */
2205 rc = pci_bus_read_config_byte (pci_bus, devfn, PCI_HEADER_TYPE, &temp_byte);
2206 if (rc)
2207 return rc;
2208
2209 if ((temp_byte & 0x7F) == PCI_HEADER_TYPE_BRIDGE) { /* PCI-PCI Bridge */
2210 /* set Primary bus */
2211 dbg("set Primary bus = 0x%x\n", func->bus);
2212 rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_PRIMARY_BUS, func->bus);
2213 if (rc)
2214 return rc;
2215
2216 /* find range of busses to use */
2217 bus_node = get_max_resource(&resources->bus_head, 1L);
2218
2219 /* If we don't have any busses to allocate, we can't continue */
2220 if (!bus_node) {
2221 err("Got NO bus resource to use\n");
2222 return -ENOMEM;
2223 }
2224 dbg("Got ranges of buses to use: base:len=0x%x:%x\n", bus_node->base, bus_node->length);
2225
2226 /* set Secondary bus */
2227 temp_byte = (u8)bus_node->base;
2228 dbg("set Secondary bus = 0x%x\n", temp_byte);
2229 rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_SECONDARY_BUS, temp_byte);
2230 if (rc)
2231 return rc;
2232
2233 /* set subordinate bus */
2234 temp_byte = (u8)(bus_node->base + bus_node->length - 1);
2235 dbg("set subordinate bus = 0x%x\n", temp_byte);
2236 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_SUBORDINATE_BUS, temp_byte);
2237 if (rc)
2238 return rc;
2239
2240 /* Set HP parameters (Cache Line Size, Latency Timer) */
2241 rc = shpchprm_set_hpp(ctrl, func, PCI_HEADER_TYPE_BRIDGE);
2242 if (rc)
2243 return rc;
2244
2245 /* Setup the IO, memory, and prefetchable windows */
2246
2247 io_node = get_max_resource(&(resources->io_head), 0x1000L);
2248 if (io_node) {
2249 dbg("io_node(base, len, next) (%x, %x, %p)\n", io_node->base, io_node->length, io_node->next);
2250 }
2251
2252 mem_node = get_max_resource(&(resources->mem_head), 0x100000L);
2253 if (mem_node) {
2254 dbg("mem_node(base, len, next) (%x, %x, %p)\n", mem_node->base, mem_node->length, mem_node->next);
2255 }
2256
2257 if (resources->p_mem_head)
2258 p_mem_node = get_max_resource(&(resources->p_mem_head), 0x100000L);
2259 else {
2260 /*
2261 * In some platform implementation, MEM and PMEM are not
2262 * distinguished, and hence ACPI _CRS has only MEM entries
2263 * for both MEM and PMEM.
2264 */
2265 dbg("using MEM for PMEM\n");
2266 p_mem_node = get_max_resource(&(resources->mem_head), 0x100000L);
2267 }
2268 if (p_mem_node) {
2269 dbg("p_mem_node(base, len, next) (%x, %x, %p)\n", p_mem_node->base, p_mem_node->length, p_mem_node->next);
2270 }
2271
2272 /* set up the IRQ info */
2273 if (!resources->irqs) {
2274 irqs.barber_pole = 0;
2275 irqs.interrupt[0] = 0;
2276 irqs.interrupt[1] = 0;
2277 irqs.interrupt[2] = 0;
2278 irqs.interrupt[3] = 0;
2279 irqs.valid_INT = 0;
2280 } else {
2281 irqs.barber_pole = resources->irqs->barber_pole;
2282 irqs.interrupt[0] = resources->irqs->interrupt[0];
2283 irqs.interrupt[1] = resources->irqs->interrupt[1];
2284 irqs.interrupt[2] = resources->irqs->interrupt[2];
2285 irqs.interrupt[3] = resources->irqs->interrupt[3];
2286 irqs.valid_INT = resources->irqs->valid_INT;
2287 }
2288
2289 /* set up resource lists that are now aligned on top and bottom
2290 * for anything behind the bridge.
2291 */
2292 temp_resources.bus_head = bus_node;
2293 temp_resources.io_head = io_node;
2294 temp_resources.mem_head = mem_node;
2295 temp_resources.p_mem_head = p_mem_node;
2296 temp_resources.irqs = &irqs;
2297
2298 /* Make copies of the nodes we are going to pass down so that
2299 * if there is a problem,we can just use these to free resources
2300 */
2301 hold_bus_node = kmalloc(sizeof(*hold_bus_node), GFP_KERNEL);
2302 hold_IO_node = kmalloc(sizeof(*hold_IO_node), GFP_KERNEL);
2303 hold_mem_node = kmalloc(sizeof(*hold_mem_node), GFP_KERNEL);
2304 hold_p_mem_node = kmalloc(sizeof(*hold_p_mem_node), GFP_KERNEL);
2305
2306 if (!hold_bus_node || !hold_IO_node || !hold_mem_node || !hold_p_mem_node) {
2307 kfree(hold_bus_node);
2308 kfree(hold_IO_node);
2309 kfree(hold_mem_node);
2310 kfree(hold_p_mem_node);
2311
2312 return 1;
2313 }
2314
2315 memcpy(hold_bus_node, bus_node, sizeof(struct pci_resource));
2316
2317 bus_node->base += 1;
2318 bus_node->length -= 1;
2319 bus_node->next = NULL;
2320
2321 /* If we have IO resources copy them and fill in the bridge's
2322 * IO range registers
2323 */
2324 if (io_node) {
2325 memcpy(hold_IO_node, io_node, sizeof(struct pci_resource));
2326 io_node->next = NULL;
2327
2328 /* set IO base and Limit registers */
2329 RES_CHECK(io_node->base, 8);
2330 temp_byte = (u8)(io_node->base >> 8);
2331 rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_IO_BASE, temp_byte);
2332
2333 RES_CHECK(io_node->base + io_node->length - 1, 8);
2334 temp_byte = (u8)((io_node->base + io_node->length - 1) >> 8);
2335 rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_IO_LIMIT, temp_byte);
2336 } else {
2337 kfree(hold_IO_node);
2338 hold_IO_node = NULL;
2339 }
2340
2341 /* If we have memory resources copy them and fill in the bridge's
2342 * memory range registers. Otherwise, fill in the range
2343 * registers with values that disable them.
2344 */
2345 if (mem_node) {
2346 memcpy(hold_mem_node, mem_node, sizeof(struct pci_resource));
2347 mem_node->next = NULL;
2348
2349 /* set Mem base and Limit registers */
2350 RES_CHECK(mem_node->base, 16);
2351 temp_word = (u32)(mem_node->base >> 16);
2352 rc = pci_bus_write_config_word(pci_bus, devfn, PCI_MEMORY_BASE, temp_word);
2353
2354 RES_CHECK(mem_node->base + mem_node->length - 1, 16);
2355 temp_word = (u32)((mem_node->base + mem_node->length - 1) >> 16);
2356 rc = pci_bus_write_config_word(pci_bus, devfn, PCI_MEMORY_LIMIT, temp_word);
2357 } else {
2358 temp_word = 0xFFFF;
2359 rc = pci_bus_write_config_word(pci_bus, devfn, PCI_MEMORY_BASE, temp_word);
2360
2361 temp_word = 0x0000;
2362 rc = pci_bus_write_config_word(pci_bus, devfn, PCI_MEMORY_LIMIT, temp_word);
2363
2364 kfree(hold_mem_node);
2365 hold_mem_node = NULL;
2366 }
2367
2368 /* If we have prefetchable memory resources copy them and
2369 * fill in the bridge's memory range registers. Otherwise,
2370 * fill in the range registers with values that disable them.
2371 */
2372 if (p_mem_node) {
2373 memcpy(hold_p_mem_node, p_mem_node, sizeof(struct pci_resource));
2374 p_mem_node->next = NULL;
2375
2376 /* set Pre Mem base and Limit registers */
2377 RES_CHECK(p_mem_node->base, 16);
2378 temp_word = (u32)(p_mem_node->base >> 16);
2379 rc = pci_bus_write_config_word(pci_bus, devfn, PCI_PREF_MEMORY_BASE, temp_word);
2380
2381 RES_CHECK(p_mem_node->base + p_mem_node->length - 1, 16);
2382 temp_word = (u32)((p_mem_node->base + p_mem_node->length - 1) >> 16);
2383 rc = pci_bus_write_config_word(pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word);
2384 } else {
2385 temp_word = 0xFFFF;
2386 rc = pci_bus_write_config_word(pci_bus, devfn, PCI_PREF_MEMORY_BASE, temp_word);
2387
2388 temp_word = 0x0000;
2389 rc = pci_bus_write_config_word(pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word);
2390
2391 kfree(hold_p_mem_node);
2392 hold_p_mem_node = NULL;
2393 }
2394
2395 /* Adjust this to compensate for extra adjustment in first loop */
2396 irqs.barber_pole--;
2397
2398 rc = 0;
2399
2400 /* Here we actually find the devices and configure them */
2401 for (device = 0; (device <= 0x1F) && !rc; device++) {
2402 irqs.barber_pole = (irqs.barber_pole + 1) & 0x03;
2403
2404 ID = 0xFFFFFFFF;
2405 pci_bus->number = hold_bus_node->base;
2406 pci_bus_read_config_dword(pci_bus, PCI_DEVFN(device, 0),
2407 PCI_VENDOR_ID, &ID);
2408 pci_bus->number = func->bus;
2409
2410 if (ID != 0xFFFFFFFF) { /* device Present */
2411 /* Setup slot structure. */
2412 new_slot = shpchp_slot_create(hold_bus_node->base);
2413
2414 if (new_slot == NULL) {
2415 /* Out of memory */
2416 rc = -ENOMEM;
2417 continue;
2418 }
2419
2420 new_slot->bus = hold_bus_node->base;
2421 new_slot->device = device;
2422 new_slot->function = 0;
2423 new_slot->is_a_board = 1;
2424 new_slot->status = 0;
2425
2426 rc = configure_new_device(ctrl, new_slot, 1, &temp_resources, func->bus, func->device);
2427 dbg("configure_new_device rc=0x%x\n",rc);
2428 } /* End of IF (device in slot?) */
2429 } /* End of FOR loop */
2430
2431 if (rc) {
2432 shpchp_destroy_resource_list(&temp_resources);
2433
2434 return_resource(&(resources->bus_head), hold_bus_node);
2435 return_resource(&(resources->io_head), hold_IO_node);
2436 return_resource(&(resources->mem_head), hold_mem_node);
2437 return_resource(&(resources->p_mem_head), hold_p_mem_node);
2438 return(rc);
2439 }
2440
2441 /* save the interrupt routing information */
2442 if (resources->irqs) {
2443 resources->irqs->interrupt[0] = irqs.interrupt[0];
2444 resources->irqs->interrupt[1] = irqs.interrupt[1];
2445 resources->irqs->interrupt[2] = irqs.interrupt[2];
2446 resources->irqs->interrupt[3] = irqs.interrupt[3];
2447 resources->irqs->valid_INT = irqs.valid_INT;
2448 } else if (!behind_bridge) {
2449 /* We need to hook up the interrupts here */
2450 for (cloop = 0; cloop < 4; cloop++) {
2451 if (irqs.valid_INT & (0x01 << cloop)) {
2452 rc = shpchp_set_irq(func->bus, func->device,
2453 0x0A + cloop, irqs.interrupt[cloop]);
2454 if (rc) {
2455 shpchp_destroy_resource_list (&temp_resources);
2456 return_resource(&(resources->bus_head), hold_bus_node);
2457 return_resource(&(resources->io_head), hold_IO_node);
2458 return_resource(&(resources->mem_head), hold_mem_node);
2459 return_resource(&(resources->p_mem_head), hold_p_mem_node);
2460 return rc;
2461 }
2462 }
2463 } /* end of for loop */
2464 }
2465
2466 /* Return unused bus resources
2467 * First use the temporary node to store information for the board
2468 */
2469 if (hold_bus_node && bus_node && temp_resources.bus_head) {
2470 hold_bus_node->length = bus_node->base - hold_bus_node->base;
2471
2472 hold_bus_node->next = func->bus_head;
2473 func->bus_head = hold_bus_node;
2474
2475 temp_byte = (u8)(temp_resources.bus_head->base - 1);
2476
2477 /* set subordinate bus */
2478 dbg("re-set subordinate bus = 0x%x\n", temp_byte);
2479 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_SUBORDINATE_BUS, temp_byte);
2480
2481 if (temp_resources.bus_head->length == 0) {
2482 kfree(temp_resources.bus_head);
2483 temp_resources.bus_head = NULL;
2484 } else {
2485 dbg("return bus res of b:d(0x%x:%x) base:len(0x%x:%x)\n",
2486 func->bus, func->device, temp_resources.bus_head->base, temp_resources.bus_head->length);
2487 return_resource(&(resources->bus_head), temp_resources.bus_head);
2488 }
2489 }
2490
2491 /* If we have IO space available and there is some left,
2492 * return the unused portion
2493 */
2494 if (hold_IO_node && temp_resources.io_head) {
2495 io_node = do_pre_bridge_resource_split(&(temp_resources.io_head),
2496 &hold_IO_node, 0x1000);
2497
2498 /* Check if we were able to split something off */
2499 if (io_node) {
2500 hold_IO_node->base = io_node->base + io_node->length;
2501
2502 RES_CHECK(hold_IO_node->base, 8);
2503 temp_byte = (u8)((hold_IO_node->base) >> 8);
2504 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_IO_BASE, temp_byte);
2505
2506 return_resource(&(resources->io_head), io_node);
2507 }
2508
2509 io_node = do_bridge_resource_split(&(temp_resources.io_head), 0x1000);
2510
2511 /* Check if we were able to split something off */
2512 if (io_node) {
2513 /* First use the temporary node to store information for the board */
2514 hold_IO_node->length = io_node->base - hold_IO_node->base;
2515
2516 /* If we used any, add it to the board's list */
2517 if (hold_IO_node->length) {
2518 hold_IO_node->next = func->io_head;
2519 func->io_head = hold_IO_node;
2520
2521 RES_CHECK(io_node->base - 1, 8);
2522 temp_byte = (u8)((io_node->base - 1) >> 8);
2523 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_IO_LIMIT, temp_byte);
2524
2525 return_resource(&(resources->io_head), io_node);
2526 } else {
2527 /* it doesn't need any IO */
2528 temp_byte = 0x00;
2529 rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_IO_LIMIT, temp_byte);
2530
2531 return_resource(&(resources->io_head), io_node);
2532 kfree(hold_IO_node);
2533 }
2534 } else {
2535 /* it used most of the range */
2536 hold_IO_node->next = func->io_head;
2537 func->io_head = hold_IO_node;
2538 }
2539 } else if (hold_IO_node) {
2540 /* it used the whole range */
2541 hold_IO_node->next = func->io_head;
2542 func->io_head = hold_IO_node;
2543 }
2544
2545 /* If we have memory space available and there is some left,
2546 * return the unused portion
2547 */
2548 if (hold_mem_node && temp_resources.mem_head) {
2549 mem_node = do_pre_bridge_resource_split(&(temp_resources.mem_head), &hold_mem_node, 0x100000L);
2550
2551 /* Check if we were able to split something off */
2552 if (mem_node) {
2553 hold_mem_node->base = mem_node->base + mem_node->length;
2554
2555 RES_CHECK(hold_mem_node->base, 16);
2556 temp_word = (u32)((hold_mem_node->base) >> 16);
2557 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_MEMORY_BASE, temp_word);
2558
2559 return_resource(&(resources->mem_head), mem_node);
2560 }
2561
2562 mem_node = do_bridge_resource_split(&(temp_resources.mem_head), 0x100000L);
2563
2564 /* Check if we were able to split something off */
2565 if (mem_node) {
2566 /* First use the temporary node to store information for the board */
2567 hold_mem_node->length = mem_node->base - hold_mem_node->base;
2568
2569 if (hold_mem_node->length) {
2570 hold_mem_node->next = func->mem_head;
2571 func->mem_head = hold_mem_node;
2572
2573 /* configure end address */
2574 RES_CHECK(mem_node->base - 1, 16);
2575 temp_word = (u32)((mem_node->base - 1) >> 16);
2576 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_MEMORY_LIMIT, temp_word);
2577
2578 /* Return unused resources to the pool */
2579 return_resource(&(resources->mem_head), mem_node);
2580 } else {
2581 /* it doesn't need any Mem */
2582 temp_word = 0x0000;
2583 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_MEMORY_LIMIT, temp_word);
2584
2585 return_resource(&(resources->mem_head), mem_node);
2586 kfree(hold_mem_node);
2587 }
2588 } else {
2589 /* it used most of the range */
2590 hold_mem_node->next = func->mem_head;
2591 func->mem_head = hold_mem_node;
2592 }
2593 } else if (hold_mem_node) {
2594 /* it used the whole range */
2595 hold_mem_node->next = func->mem_head;
2596 func->mem_head = hold_mem_node;
2597 }
2598
2599 /* If we have prefetchable memory space available and there is some
2600 * left at the end, return the unused portion
2601 */
2602 if (hold_p_mem_node && temp_resources.p_mem_head) {
2603 p_mem_node = do_pre_bridge_resource_split(&(temp_resources.p_mem_head),
2604 &hold_p_mem_node, 0x100000L);
2605
2606 /* Check if we were able to split something off */
2607 if (p_mem_node) {
2608 hold_p_mem_node->base = p_mem_node->base + p_mem_node->length;
2609
2610 RES_CHECK(hold_p_mem_node->base, 16);
2611 temp_word = (u32)((hold_p_mem_node->base) >> 16);
2612 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_BASE, temp_word);
2613
2614 return_resource(&(resources->p_mem_head), p_mem_node);
2615 }
2616
2617 p_mem_node = do_bridge_resource_split(&(temp_resources.p_mem_head), 0x100000L);
2618
2619 /* Check if we were able to split something off */
2620 if (p_mem_node) {
2621 /* First use the temporary node to store information for the board */
2622 hold_p_mem_node->length = p_mem_node->base - hold_p_mem_node->base;
2623
2624 /* If we used any, add it to the board's list */
2625 if (hold_p_mem_node->length) {
2626 hold_p_mem_node->next = func->p_mem_head;
2627 func->p_mem_head = hold_p_mem_node;
2628
2629 RES_CHECK(p_mem_node->base - 1, 16);
2630 temp_word = (u32)((p_mem_node->base - 1) >> 16);
2631 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word);
2632
2633 return_resource(&(resources->p_mem_head), p_mem_node);
2634 } else {
2635 /* it doesn't need any PMem */
2636 temp_word = 0x0000;
2637 rc = pci_bus_write_config_word (pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, temp_word);
2638
2639 return_resource(&(resources->p_mem_head), p_mem_node);
2640 kfree(hold_p_mem_node);
2641 }
2642 } else {
2643 /* it used the most of the range */
2644 hold_p_mem_node->next = func->p_mem_head;
2645 func->p_mem_head = hold_p_mem_node;
2646 }
2647 } else if (hold_p_mem_node) {
2648 /* it used the whole range */
2649 hold_p_mem_node->next = func->p_mem_head;
2650 func->p_mem_head = hold_p_mem_node;
2651 }
2652
2653 /* We should be configuring an IRQ and the bridge's base address
2654 * registers if it needs them. Although we have never seen such
2655 * a device
2656 */
2657
2658 shpchprm_enable_card(ctrl, func, PCI_HEADER_TYPE_BRIDGE);
2659
2660 dbg("PCI Bridge Hot-Added s:b:d:f(%02x:%02x:%02x:%02x)\n", ctrl->seg, func->bus, func->device, func->function);
2661 } else if ((temp_byte & 0x7F) == PCI_HEADER_TYPE_NORMAL) {
2662 /* Standard device */
2663 u64 base64;
2664 rc = pci_bus_read_config_byte (pci_bus, devfn, 0x0B, &class_code);
2665
2666 if (class_code == PCI_BASE_CLASS_DISPLAY)
2667 return (DEVICE_TYPE_NOT_SUPPORTED);
2668
2669 /* Figure out IO and memory needs */
2670 for (cloop = PCI_BASE_ADDRESS_0; cloop <= PCI_BASE_ADDRESS_5; cloop += 4) {
2671 temp_register = 0xFFFFFFFF;
2672
2673 rc = pci_bus_write_config_dword (pci_bus, devfn, cloop, temp_register);
2674 rc = pci_bus_read_config_dword(pci_bus, devfn, cloop, &temp_register);
2675 dbg("Bar[%x]=0x%x on bus:dev:func(0x%x:%x:%x)\n", cloop, temp_register, func->bus, func->device,
2676 func->function);
2677
2678 if (!temp_register)
2679 continue;
2680
2681 base64 = 0L;
2682 if (temp_register & PCI_BASE_ADDRESS_SPACE_IO) {
2683 /* Map IO */
2684
2685 /* set base = amount of IO space */
2686 base = temp_register & 0xFFFFFFFC;
2687 base = ~base + 1;
2688
2689 dbg("NEED IO length(0x%x)\n", base);
2690 io_node = get_io_resource(&(resources->io_head),(ulong)base);
2691
2692 /* allocate the resource to the board */
2693 if (io_node) {
2694 dbg("Got IO base=0x%x(length=0x%x)\n", io_node->base, io_node->length);
2695 base = (u32)io_node->base;
2696 io_node->next = func->io_head;
2697 func->io_head = io_node;
2698 } else {
2699 err("Got NO IO resource(length=0x%x)\n", base);
2700 return -ENOMEM;
2701 }
2702 } else { /* map MEM */
2703 int prefetchable = 1;
2704 struct pci_resource **res_node = &func->p_mem_head;
2705 char *res_type_str = "PMEM";
2706 u32 temp_register2;
2707
2708 if (!(temp_register & PCI_BASE_ADDRESS_MEM_PREFETCH)) {
2709 prefetchable = 0;
2710 res_node = &func->mem_head;
2711 res_type_str++;
2712 }
2713
2714 base = temp_register & 0xFFFFFFF0;
2715 base = ~base + 1;
2716
2717 switch (temp_register & PCI_BASE_ADDRESS_MEM_TYPE_MASK) {
2718 case PCI_BASE_ADDRESS_MEM_TYPE_32:
2719 dbg("NEED 32 %s bar=0x%x(length=0x%x)\n", res_type_str, temp_register, base);
2720
2721 if (prefetchable && resources->p_mem_head)
2722 mem_node=get_resource(&(resources->p_mem_head), (ulong)base);
2723 else {
2724 if (prefetchable)
2725 dbg("using MEM for PMEM\n");
2726 mem_node=get_resource(&(resources->mem_head), (ulong)base);
2727 }
2728
2729 /* allocate the resource to the board */
2730 if (mem_node) {
2731 base = (u32)mem_node->base;
2732 mem_node->next = *res_node;
2733 *res_node = mem_node;
2734 dbg("Got 32 %s base=0x%x(length=0x%x)\n", res_type_str, mem_node->base,
2735 mem_node->length);
2736 } else {
2737 err("Got NO 32 %s resource(length=0x%x)\n", res_type_str, base);
2738 return -ENOMEM;
2739 }
2740 break;
2741 case PCI_BASE_ADDRESS_MEM_TYPE_64:
2742 rc = pci_bus_read_config_dword(pci_bus, devfn, cloop+4, &temp_register2);
2743 dbg("NEED 64 %s bar=0x%x:%x(length=0x%x)\n", res_type_str, temp_register2,
2744 temp_register, base);
2745
2746 if (prefetchable && resources->p_mem_head)
2747 mem_node = get_resource(&(resources->p_mem_head), (ulong)base);
2748 else {
2749 if (prefetchable)
2750 dbg("using MEM for PMEM\n");
2751 mem_node = get_resource(&(resources->mem_head), (ulong)base);
2752 }
2753
2754 /* allocate the resource to the board */
2755 if (mem_node) {
2756 base64 = mem_node->base;
2757 mem_node->next = *res_node;
2758 *res_node = mem_node;
2759 dbg("Got 64 %s base=0x%x:%x(length=%x)\n", res_type_str, (u32)(base64 >> 32),
2760 (u32)base64, mem_node->length);
2761 } else {
2762 err("Got NO 64 %s resource(length=0x%x)\n", res_type_str, base);
2763 return -ENOMEM;
2764 }
2765 break;
2766 default:
2767 dbg("reserved BAR type=0x%x\n", temp_register);
2768 break;
2769 }
2770
2771 }
2772
2773 if (base64) {
2774 rc = pci_bus_write_config_dword(pci_bus, devfn, cloop, (u32)base64);
2775 cloop += 4;
2776 base64 >>= 32;
2777
2778 if (base64) {
2779 dbg("%s: high dword of base64(0x%x) set to 0\n", __FUNCTION__, (u32)base64);
2780 base64 = 0x0L;
2781 }
2782
2783 rc = pci_bus_write_config_dword(pci_bus, devfn, cloop, (u32)base64);
2784 } else {
2785 rc = pci_bus_write_config_dword(pci_bus, devfn, cloop, base);
2786 }
2787 } /* End of base register loop */
2788
2789#if defined(CONFIG_X86_64)
2790 /* Figure out which interrupt pin this function uses */
2791 rc = pci_bus_read_config_byte (pci_bus, devfn, PCI_INTERRUPT_PIN, &temp_byte);
2792
2793 /* If this function needs an interrupt and we are behind a bridge
2794 and the pin is tied to something that's alread mapped,
2795 set this one the same
2796 */
2797 if (temp_byte && resources->irqs &&
2798 (resources->irqs->valid_INT &
2799 (0x01 << ((temp_byte + resources->irqs->barber_pole - 1) & 0x03)))) {
2800 /* We have to share with something already set up */
2801 IRQ = resources->irqs->interrupt[(temp_byte + resources->irqs->barber_pole - 1) & 0x03];
2802 } else {
2803 /* Program IRQ based on card type */
2804 rc = pci_bus_read_config_byte (pci_bus, devfn, 0x0B, &class_code);
2805
2806 if (class_code == PCI_BASE_CLASS_STORAGE) {
2807 IRQ = shpchp_disk_irq;
2808 } else {
2809 IRQ = shpchp_nic_irq;
2810 }
2811 }
2812
2813 /* IRQ Line */
2814 rc = pci_bus_write_config_byte (pci_bus, devfn, PCI_INTERRUPT_LINE, IRQ);
2815
2816 if (!behind_bridge) {
2817 rc = shpchp_set_irq(func->bus, func->device, temp_byte + 0x09, IRQ);
2818 if (rc)
2819 return(1);
2820 } else {
2821 /* TBD - this code may also belong in the other clause of this If statement */
2822 resources->irqs->interrupt[(temp_byte + resources->irqs->barber_pole - 1) & 0x03] = IRQ;
2823 resources->irqs->valid_INT |= 0x01 << (temp_byte + resources->irqs->barber_pole - 1) & 0x03;
2824 }
2825#endif
2826 /* Disable ROM base Address */
2827 rc = pci_bus_write_config_dword (pci_bus, devfn, PCI_ROM_ADDRESS, 0x00);
2828
2829 /* Set HP parameters (Cache Line Size, Latency Timer) */
2830 rc = shpchprm_set_hpp(ctrl, func, PCI_HEADER_TYPE_NORMAL);
2831 if (rc)
2832 return rc;
2833
2834 shpchprm_enable_card(ctrl, func, PCI_HEADER_TYPE_NORMAL);
2835
2836 dbg("PCI function Hot-Added s:b:d:f(%02x:%02x:%02x:%02x)\n", ctrl->seg, func->bus, func->device, func->function);
2837 } /* End of Not-A-Bridge else */
2838 else {
2839 /* It's some strange type of PCI adapter (Cardbus?) */
2840 return(DEVICE_TYPE_NOT_SUPPORTED);
2841 }
2842
2843 func->configured = 1;
2844
2845 return 0;
2846} 980}
2847 981
diff --git a/drivers/pci/hotplug/shpchp_hpc.c b/drivers/pci/hotplug/shpchp_hpc.c
index 8d98410bf1c0..40905a6c8094 100644
--- a/drivers/pci/hotplug/shpchp_hpc.c
+++ b/drivers/pci/hotplug/shpchp_hpc.c
@@ -27,17 +27,10 @@
27 * 27 *
28 */ 28 */
29 29
30#include <linux/config.h>
31#include <linux/kernel.h> 30#include <linux/kernel.h>
32#include <linux/module.h> 31#include <linux/module.h>
33#include <linux/types.h> 32#include <linux/types.h>
34#include <linux/slab.h>
35#include <linux/vmalloc.h>
36#include <linux/interrupt.h>
37#include <linux/spinlock.h>
38#include <linux/delay.h>
39#include <linux/pci.h> 33#include <linux/pci.h>
40#include <asm/system.h>
41#include "shpchp.h" 34#include "shpchp.h"
42 35
43#ifdef DEBUG 36#ifdef DEBUG
@@ -282,7 +275,7 @@ static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds)
282 275
283static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd) 276static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
284{ 277{
285 struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle; 278 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
286 u16 cmd_status; 279 u16 cmd_status;
287 int retval = 0; 280 int retval = 0;
288 u16 temp_word; 281 u16 temp_word;
@@ -320,7 +313,6 @@ static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
320 * command. 313 * command.
321 */ 314 */
322 writew(temp_word, php_ctlr->creg + CMD); 315 writew(temp_word, php_ctlr->creg + CMD);
323 dbg("%s: temp_word written %x\n", __FUNCTION__, temp_word);
324 316
325 DBG_LEAVE_ROUTINE 317 DBG_LEAVE_ROUTINE
326 return retval; 318 return retval;
@@ -328,7 +320,7 @@ static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
328 320
329static int hpc_check_cmd_status(struct controller *ctrl) 321static int hpc_check_cmd_status(struct controller *ctrl)
330{ 322{
331 struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) ctrl->hpc_ctlr_handle; 323 struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
332 u16 cmd_status; 324 u16 cmd_status;
333 int retval = 0; 325 int retval = 0;
334 326
@@ -368,7 +360,7 @@ static int hpc_check_cmd_status(struct controller *ctrl)
368 360
369static int hpc_get_attention_status(struct slot *slot, u8 *status) 361static int hpc_get_attention_status(struct slot *slot, u8 *status)
370{ 362{
371 struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle; 363 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
372 u32 slot_reg; 364 u32 slot_reg;
373 u16 slot_status; 365 u16 slot_status;
374 u8 atten_led_state; 366 u8 atten_led_state;
@@ -408,7 +400,7 @@ static int hpc_get_attention_status(struct slot *slot, u8 *status)
408 400
409static int hpc_get_power_status(struct slot * slot, u8 *status) 401static int hpc_get_power_status(struct slot * slot, u8 *status)
410{ 402{
411 struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle; 403 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
412 u32 slot_reg; 404 u32 slot_reg;
413 u16 slot_status; 405 u16 slot_status;
414 u8 slot_state; 406 u8 slot_state;
@@ -450,7 +442,7 @@ static int hpc_get_power_status(struct slot * slot, u8 *status)
450 442
451static int hpc_get_latch_status(struct slot *slot, u8 *status) 443static int hpc_get_latch_status(struct slot *slot, u8 *status)
452{ 444{
453 struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle; 445 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
454 u32 slot_reg; 446 u32 slot_reg;
455 u16 slot_status; 447 u16 slot_status;
456 448
@@ -473,7 +465,7 @@ static int hpc_get_latch_status(struct slot *slot, u8 *status)
473 465
474static int hpc_get_adapter_status(struct slot *slot, u8 *status) 466static int hpc_get_adapter_status(struct slot *slot, u8 *status)
475{ 467{
476 struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle; 468 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
477 u32 slot_reg; 469 u32 slot_reg;
478 u16 slot_status; 470 u16 slot_status;
479 u8 card_state; 471 u8 card_state;
@@ -496,7 +488,7 @@ static int hpc_get_adapter_status(struct slot *slot, u8 *status)
496 488
497static int hpc_get_prog_int(struct slot *slot, u8 *prog_int) 489static int hpc_get_prog_int(struct slot *slot, u8 *prog_int)
498{ 490{
499 struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle; 491 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
500 492
501 DBG_ENTER_ROUTINE 493 DBG_ENTER_ROUTINE
502 494
@@ -513,7 +505,7 @@ static int hpc_get_prog_int(struct slot *slot, u8 *prog_int)
513 505
514static int hpc_get_adapter_speed(struct slot *slot, enum pci_bus_speed *value) 506static int hpc_get_adapter_speed(struct slot *slot, enum pci_bus_speed *value)
515{ 507{
516 struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle; 508 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
517 u32 slot_reg; 509 u32 slot_reg;
518 u16 slot_status, sec_bus_status; 510 u16 slot_status, sec_bus_status;
519 u8 m66_cap, pcix_cap, pi; 511 u8 m66_cap, pcix_cap, pi;
@@ -594,7 +586,7 @@ static int hpc_get_adapter_speed(struct slot *slot, enum pci_bus_speed *value)
594 586
595static int hpc_get_mode1_ECC_cap(struct slot *slot, u8 *mode) 587static int hpc_get_mode1_ECC_cap(struct slot *slot, u8 *mode)
596{ 588{
597 struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle; 589 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
598 u16 sec_bus_status; 590 u16 sec_bus_status;
599 u8 pi; 591 u8 pi;
600 int retval = 0; 592 int retval = 0;
@@ -623,7 +615,7 @@ static int hpc_get_mode1_ECC_cap(struct slot *slot, u8 *mode)
623 615
624static int hpc_query_power_fault(struct slot * slot) 616static int hpc_query_power_fault(struct slot * slot)
625{ 617{
626 struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle; 618 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
627 u32 slot_reg; 619 u32 slot_reg;
628 u16 slot_status; 620 u16 slot_status;
629 u8 pwr_fault_state, status; 621 u8 pwr_fault_state, status;
@@ -647,7 +639,7 @@ static int hpc_query_power_fault(struct slot * slot)
647 639
648static int hpc_set_attention_status(struct slot *slot, u8 value) 640static int hpc_set_attention_status(struct slot *slot, u8 value)
649{ 641{
650 struct php_ctlr_state_s *php_ctlr =(struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle; 642 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
651 u8 slot_cmd = 0; 643 u8 slot_cmd = 0;
652 int rc = 0; 644 int rc = 0;
653 645
@@ -683,7 +675,7 @@ static int hpc_set_attention_status(struct slot *slot, u8 value)
683 675
684static void hpc_set_green_led_on(struct slot *slot) 676static void hpc_set_green_led_on(struct slot *slot)
685{ 677{
686 struct php_ctlr_state_s *php_ctlr =(struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle; 678 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
687 u8 slot_cmd; 679 u8 slot_cmd;
688 680
689 if (!slot->ctrl->hpc_ctlr_handle) { 681 if (!slot->ctrl->hpc_ctlr_handle) {
@@ -705,7 +697,7 @@ static void hpc_set_green_led_on(struct slot *slot)
705 697
706static void hpc_set_green_led_off(struct slot *slot) 698static void hpc_set_green_led_off(struct slot *slot)
707{ 699{
708 struct php_ctlr_state_s *php_ctlr =(struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle; 700 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
709 u8 slot_cmd; 701 u8 slot_cmd;
710 702
711 if (!slot->ctrl->hpc_ctlr_handle) { 703 if (!slot->ctrl->hpc_ctlr_handle) {
@@ -727,7 +719,7 @@ static void hpc_set_green_led_off(struct slot *slot)
727 719
728static void hpc_set_green_led_blink(struct slot *slot) 720static void hpc_set_green_led_blink(struct slot *slot)
729{ 721{
730 struct php_ctlr_state_s *php_ctlr =(struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle; 722 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
731 u8 slot_cmd; 723 u8 slot_cmd;
732 724
733 if (!slot->ctrl->hpc_ctlr_handle) { 725 if (!slot->ctrl->hpc_ctlr_handle) {
@@ -754,7 +746,7 @@ int shpc_get_ctlr_slot_config(struct controller *ctrl,
754 int *updown, /* physical_slot_num increament: 1 or -1 */ 746 int *updown, /* physical_slot_num increament: 1 or -1 */
755 int *flags) 747 int *flags)
756{ 748{
757 struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) ctrl->hpc_ctlr_handle; 749 struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
758 750
759 DBG_ENTER_ROUTINE 751 DBG_ENTER_ROUTINE
760 752
@@ -776,7 +768,7 @@ int shpc_get_ctlr_slot_config(struct controller *ctrl,
776 768
777static void hpc_release_ctlr(struct controller *ctrl) 769static void hpc_release_ctlr(struct controller *ctrl)
778{ 770{
779 struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) ctrl->hpc_ctlr_handle; 771 struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
780 struct php_ctlr_state_s *p, *p_prev; 772 struct php_ctlr_state_s *p, *p_prev;
781 773
782 DBG_ENTER_ROUTINE 774 DBG_ENTER_ROUTINE
@@ -796,10 +788,8 @@ static void hpc_release_ctlr(struct controller *ctrl)
796 } 788 }
797 } 789 }
798 if (php_ctlr->pci_dev) { 790 if (php_ctlr->pci_dev) {
799 dbg("%s: before calling iounmap & release_mem_region\n", __FUNCTION__);
800 iounmap(php_ctlr->creg); 791 iounmap(php_ctlr->creg);
801 release_mem_region(pci_resource_start(php_ctlr->pci_dev, 0), pci_resource_len(php_ctlr->pci_dev, 0)); 792 release_mem_region(pci_resource_start(php_ctlr->pci_dev, 0), pci_resource_len(php_ctlr->pci_dev, 0));
802 dbg("%s: before calling iounmap & release_mem_region\n", __FUNCTION__);
803 php_ctlr->pci_dev = NULL; 793 php_ctlr->pci_dev = NULL;
804 } 794 }
805 795
@@ -828,7 +818,7 @@ DBG_LEAVE_ROUTINE
828 818
829static int hpc_power_on_slot(struct slot * slot) 819static int hpc_power_on_slot(struct slot * slot)
830{ 820{
831 struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle; 821 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
832 u8 slot_cmd; 822 u8 slot_cmd;
833 int retval = 0; 823 int retval = 0;
834 824
@@ -859,7 +849,7 @@ static int hpc_power_on_slot(struct slot * slot)
859 849
860static int hpc_slot_enable(struct slot * slot) 850static int hpc_slot_enable(struct slot * slot)
861{ 851{
862 struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle; 852 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
863 u8 slot_cmd; 853 u8 slot_cmd;
864 int retval = 0; 854 int retval = 0;
865 855
@@ -890,7 +880,7 @@ static int hpc_slot_enable(struct slot * slot)
890 880
891static int hpc_slot_disable(struct slot * slot) 881static int hpc_slot_disable(struct slot * slot)
892{ 882{
893 struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle; 883 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
894 u8 slot_cmd; 884 u8 slot_cmd;
895 int retval = 0; 885 int retval = 0;
896 886
@@ -920,51 +910,12 @@ static int hpc_slot_disable(struct slot * slot)
920 return retval; 910 return retval;
921} 911}
922 912
923static int hpc_enable_all_slots( struct slot *slot )
924{
925 int retval = 0;
926
927 DBG_ENTER_ROUTINE
928
929 if (!slot->ctrl->hpc_ctlr_handle) {
930 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
931 return -1;
932 }
933
934 retval = shpc_write_cmd(slot, 0, SET_ENABLE_ALL);
935 if (retval) {
936 err("%s: Write command failed!\n", __FUNCTION__);
937 return -1;
938 }
939
940 DBG_LEAVE_ROUTINE
941
942 return retval;
943}
944
945static int hpc_pwr_on_all_slots(struct slot *slot)
946{
947 int retval = 0;
948
949 DBG_ENTER_ROUTINE
950
951 retval = shpc_write_cmd(slot, 0, SET_PWR_ON_ALL);
952
953 if (retval) {
954 err("%s: Write command failed!\n", __FUNCTION__);
955 return -1;
956 }
957
958 DBG_LEAVE_ROUTINE
959 return retval;
960}
961
962static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value) 913static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value)
963{ 914{
964 u8 slot_cmd; 915 u8 slot_cmd;
965 u8 pi; 916 u8 pi;
966 int retval = 0; 917 int retval = 0;
967 struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle; 918 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
968 919
969 DBG_ENTER_ROUTINE 920 DBG_ENTER_ROUTINE
970 921
@@ -1089,18 +1040,13 @@ static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs)
1089 1040
1090 if (!intr_loc) 1041 if (!intr_loc)
1091 return IRQ_NONE; 1042 return IRQ_NONE;
1092 dbg("%s: shpc_isr proceeds\n", __FUNCTION__);
1093 dbg("%s: intr_loc = %x\n",__FUNCTION__, intr_loc); 1043 dbg("%s: intr_loc = %x\n",__FUNCTION__, intr_loc);
1094 1044
1095 if(!shpchp_poll_mode) { 1045 if(!shpchp_poll_mode) {
1096 /* Mask Global Interrupt Mask - see implementation note on p. 139 */ 1046 /* Mask Global Interrupt Mask - see implementation note on p. 139 */
1097 /* of SHPC spec rev 1.0*/ 1047 /* of SHPC spec rev 1.0*/
1098 temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE); 1048 temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
1099 dbg("%s: Before masking global interrupt, temp_dword = %x\n",
1100 __FUNCTION__, temp_dword);
1101 temp_dword |= 0x00000001; 1049 temp_dword |= 0x00000001;
1102 dbg("%s: After masking global interrupt, temp_dword = %x\n",
1103 __FUNCTION__, temp_dword);
1104 writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE); 1050 writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);
1105 1051
1106 intr_loc2 = readl(php_ctlr->creg + INTR_LOC); 1052 intr_loc2 = readl(php_ctlr->creg + INTR_LOC);
@@ -1114,11 +1060,7 @@ static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs)
1114 * Detect bit in Controller SERR-INT register 1060 * Detect bit in Controller SERR-INT register
1115 */ 1061 */
1116 temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE); 1062 temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
1117 dbg("%s: Before clearing CCIP, temp_dword = %x\n",
1118 __FUNCTION__, temp_dword);
1119 temp_dword &= 0xfffeffff; 1063 temp_dword &= 0xfffeffff;
1120 dbg("%s: After clearing CCIP, temp_dword = %x\n",
1121 __FUNCTION__, temp_dword);
1122 writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE); 1064 writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);
1123 wake_up_interruptible(&ctrl->queue); 1065 wake_up_interruptible(&ctrl->queue);
1124 } 1066 }
@@ -1126,11 +1068,7 @@ static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs)
1126 if ((intr_loc = (intr_loc >> 1)) == 0) { 1068 if ((intr_loc = (intr_loc >> 1)) == 0) {
1127 /* Unmask Global Interrupt Mask */ 1069 /* Unmask Global Interrupt Mask */
1128 temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE); 1070 temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
1129 dbg("%s: 1-Before unmasking global interrupt, temp_dword = %x\n",
1130 __FUNCTION__, temp_dword);
1131 temp_dword &= 0xfffffffe; 1071 temp_dword &= 0xfffffffe;
1132 dbg("%s: 1-After unmasking global interrupt, temp_dword = %x\n",
1133 __FUNCTION__, temp_dword);
1134 writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE); 1072 writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);
1135 1073
1136 return IRQ_NONE; 1074 return IRQ_NONE;
@@ -1140,11 +1078,9 @@ static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs)
1140 /* To find out which slot has interrupt pending */ 1078 /* To find out which slot has interrupt pending */
1141 if ((intr_loc >> hp_slot) & 0x01) { 1079 if ((intr_loc >> hp_slot) & 0x01) {
1142 temp_dword = readl(php_ctlr->creg + SLOT1 + (4*hp_slot)); 1080 temp_dword = readl(php_ctlr->creg + SLOT1 + (4*hp_slot));
1143 dbg("%s: Slot %x with intr, temp_dword = %x\n", 1081 dbg("%s: Slot %x with intr, slot register = %x\n",
1144 __FUNCTION__, hp_slot, temp_dword); 1082 __FUNCTION__, hp_slot, temp_dword);
1145 temp_byte = (temp_dword >> 16) & 0xFF; 1083 temp_byte = (temp_dword >> 16) & 0xFF;
1146 dbg("%s: Slot with intr, temp_byte = %x\n",
1147 __FUNCTION__, temp_byte);
1148 if ((php_ctlr->switch_change_callback) && (temp_byte & 0x08)) 1084 if ((php_ctlr->switch_change_callback) && (temp_byte & 0x08))
1149 schedule_flag += php_ctlr->switch_change_callback( 1085 schedule_flag += php_ctlr->switch_change_callback(
1150 hp_slot, php_ctlr->callback_instance_id); 1086 hp_slot, php_ctlr->callback_instance_id);
@@ -1160,8 +1096,6 @@ static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs)
1160 1096
1161 /* Clear all slot events */ 1097 /* Clear all slot events */
1162 temp_dword = 0xe01f3fff; 1098 temp_dword = 0xe01f3fff;
1163 dbg("%s: Clearing slot events, temp_dword = %x\n",
1164 __FUNCTION__, temp_dword);
1165 writel(temp_dword, php_ctlr->creg + SLOT1 + (4*hp_slot)); 1099 writel(temp_dword, php_ctlr->creg + SLOT1 + (4*hp_slot));
1166 1100
1167 intr_loc2 = readl(php_ctlr->creg + INTR_LOC); 1101 intr_loc2 = readl(php_ctlr->creg + INTR_LOC);
@@ -1171,11 +1105,7 @@ static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs)
1171 if (!shpchp_poll_mode) { 1105 if (!shpchp_poll_mode) {
1172 /* Unmask Global Interrupt Mask */ 1106 /* Unmask Global Interrupt Mask */
1173 temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE); 1107 temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
1174 dbg("%s: 2-Before unmasking global interrupt, temp_dword = %x\n",
1175 __FUNCTION__, temp_dword);
1176 temp_dword &= 0xfffffffe; 1108 temp_dword &= 0xfffffffe;
1177 dbg("%s: 2-After unmasking global interrupt, temp_dword = %x\n",
1178 __FUNCTION__, temp_dword);
1179 writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE); 1109 writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);
1180 } 1110 }
1181 1111
@@ -1184,7 +1114,7 @@ static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs)
1184 1114
1185static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value) 1115static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value)
1186{ 1116{
1187 struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle; 1117 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
1188 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN; 1118 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
1189 int retval = 0; 1119 int retval = 0;
1190 u8 pi; 1120 u8 pi;
@@ -1253,7 +1183,7 @@ static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value)
1253 1183
1254static int hpc_get_cur_bus_speed (struct slot *slot, enum pci_bus_speed *value) 1184static int hpc_get_cur_bus_speed (struct slot *slot, enum pci_bus_speed *value)
1255{ 1185{
1256 struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle; 1186 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
1257 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN; 1187 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
1258 u16 sec_bus_status; 1188 u16 sec_bus_status;
1259 int retval = 0; 1189 int retval = 0;
@@ -1367,8 +1297,6 @@ static struct hpc_ops shpchp_hpc_ops = {
1367 .power_on_slot = hpc_power_on_slot, 1297 .power_on_slot = hpc_power_on_slot,
1368 .slot_enable = hpc_slot_enable, 1298 .slot_enable = hpc_slot_enable,
1369 .slot_disable = hpc_slot_disable, 1299 .slot_disable = hpc_slot_disable,
1370 .enable_all_slots = hpc_enable_all_slots,
1371 .pwr_on_all_slots = hpc_pwr_on_all_slots,
1372 .set_bus_speed_mode = hpc_set_bus_speed_mode, 1300 .set_bus_speed_mode = hpc_set_bus_speed_mode,
1373 .set_attention_status = hpc_set_attention_status, 1301 .set_attention_status = hpc_set_attention_status,
1374 .get_power_status = hpc_get_power_status, 1302 .get_power_status = hpc_get_power_status,
@@ -1391,12 +1319,7 @@ static struct hpc_ops shpchp_hpc_ops = {
1391 .check_cmd_status = hpc_check_cmd_status, 1319 .check_cmd_status = hpc_check_cmd_status,
1392}; 1320};
1393 1321
1394int shpc_init(struct controller * ctrl, 1322int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1395 struct pci_dev * pdev,
1396 php_intr_callback_t attention_button_callback,
1397 php_intr_callback_t switch_change_callback,
1398 php_intr_callback_t presence_change_callback,
1399 php_intr_callback_t power_fault_callback)
1400{ 1323{
1401 struct php_ctlr_state_s *php_ctlr, *p; 1324 struct php_ctlr_state_s *php_ctlr, *p;
1402 void *instance_id = ctrl; 1325 void *instance_id = ctrl;
@@ -1405,7 +1328,6 @@ int shpc_init(struct controller * ctrl,
1405 static int first = 1; 1328 static int first = 1;
1406 u32 shpc_cap_offset, shpc_base_offset; 1329 u32 shpc_cap_offset, shpc_base_offset;
1407 u32 tempdword, slot_reg; 1330 u32 tempdword, slot_reg;
1408 u16 vendor_id, device_id;
1409 u8 i; 1331 u8 i;
1410 1332
1411 DBG_ENTER_ROUTINE 1333 DBG_ENTER_ROUTINE
@@ -1422,21 +1344,8 @@ int shpc_init(struct controller * ctrl,
1422 1344
1423 php_ctlr->pci_dev = pdev; /* save pci_dev in context */ 1345 php_ctlr->pci_dev = pdev; /* save pci_dev in context */
1424 1346
1425 rc = pci_read_config_word(pdev, PCI_VENDOR_ID, &vendor_id); 1347 if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device ==
1426 dbg("%s: Vendor ID: %x\n",__FUNCTION__, vendor_id); 1348 PCI_DEVICE_ID_AMD_GOLAM_7450)) {
1427 if (rc) {
1428 err("%s: unable to read PCI configuration data\n", __FUNCTION__);
1429 goto abort_free_ctlr;
1430 }
1431
1432 rc = pci_read_config_word(pdev, PCI_DEVICE_ID, &device_id);
1433 dbg("%s: Device ID: %x\n",__FUNCTION__, device_id);
1434 if (rc) {
1435 err("%s: unable to read PCI configuration data\n", __FUNCTION__);
1436 goto abort_free_ctlr;
1437 }
1438
1439 if ((vendor_id == PCI_VENDOR_ID_AMD) || (device_id == PCI_DEVICE_ID_AMD_GOLAM_7450)) {
1440 shpc_base_offset = 0; /* amd shpc driver doesn't use this; assume 0 */ 1349 shpc_base_offset = 0; /* amd shpc driver doesn't use this; assume 0 */
1441 } else { 1350 } else {
1442 if ((shpc_cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC)) == 0) { 1351 if ((shpc_cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC)) == 0) {
@@ -1469,7 +1378,8 @@ int shpc_init(struct controller * ctrl,
1469 err("%s : pci_read_config_dword failed\n", __FUNCTION__); 1378 err("%s : pci_read_config_dword failed\n", __FUNCTION__);
1470 goto abort_free_ctlr; 1379 goto abort_free_ctlr;
1471 } 1380 }
1472 dbg("%s: offset %d: tempdword %x\n", __FUNCTION__,i, tempdword); 1381 dbg("%s: offset %d: value %x\n", __FUNCTION__,i,
1382 tempdword);
1473 } 1383 }
1474 } 1384 }
1475 1385
@@ -1478,13 +1388,6 @@ int shpc_init(struct controller * ctrl,
1478 first = 0; 1388 first = 0;
1479 } 1389 }
1480 1390
1481 dbg("pdev = %p: b:d:f:irq=0x%x:%x:%x:%x\n", pdev, pdev->bus->number, PCI_SLOT(pdev->devfn),
1482 PCI_FUNC(pdev->devfn), pdev->irq);
1483 for ( rc = 0; rc < DEVICE_COUNT_RESOURCE; rc++)
1484 if (pci_resource_len(pdev, rc) > 0)
1485 dbg("pci resource[%d] start=0x%lx(len=0x%lx), shpc_base_offset %x\n", rc,
1486 pci_resource_start(pdev, rc), pci_resource_len(pdev, rc), shpc_base_offset);
1487
1488 info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device, pdev->subsystem_vendor, 1391 info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device, pdev->subsystem_vendor,
1489 pdev->subsystem_device); 1392 pdev->subsystem_device);
1490 1393
@@ -1504,7 +1407,6 @@ int shpc_init(struct controller * ctrl,
1504 goto abort_free_ctlr; 1407 goto abort_free_ctlr;
1505 } 1408 }
1506 dbg("%s: php_ctlr->creg %p\n", __FUNCTION__, php_ctlr->creg); 1409 dbg("%s: php_ctlr->creg %p\n", __FUNCTION__, php_ctlr->creg);
1507 dbg("%s: physical addr %p\n", __FUNCTION__, (void*)pci_resource_start(pdev, 0));
1508 1410
1509 init_MUTEX(&ctrl->crit_sect); 1411 init_MUTEX(&ctrl->crit_sect);
1510 /* Setup wait queue */ 1412 /* Setup wait queue */
@@ -1512,13 +1414,10 @@ int shpc_init(struct controller * ctrl,
1512 1414
1513 /* Find the IRQ */ 1415 /* Find the IRQ */
1514 php_ctlr->irq = pdev->irq; 1416 php_ctlr->irq = pdev->irq;
1515 dbg("HPC interrupt = %d\n", php_ctlr->irq); 1417 php_ctlr->attention_button_callback = shpchp_handle_attention_button,
1516 1418 php_ctlr->switch_change_callback = shpchp_handle_switch_change;
1517 /* Save interrupt callback info */ 1419 php_ctlr->presence_change_callback = shpchp_handle_presence_change;
1518 php_ctlr->attention_button_callback = attention_button_callback; 1420 php_ctlr->power_fault_callback = shpchp_handle_power_fault;
1519 php_ctlr->switch_change_callback = switch_change_callback;
1520 php_ctlr->presence_change_callback = presence_change_callback;
1521 php_ctlr->power_fault_callback = power_fault_callback;
1522 php_ctlr->callback_instance_id = instance_id; 1421 php_ctlr->callback_instance_id = instance_id;
1523 1422
1524 /* Return PCI Controller Info */ 1423 /* Return PCI Controller Info */
@@ -1556,7 +1455,6 @@ int shpc_init(struct controller * ctrl,
1556 if (rc) { 1455 if (rc) {
1557 info("Can't get msi for the hotplug controller\n"); 1456 info("Can't get msi for the hotplug controller\n");
1558 info("Use INTx for the hotplug controller\n"); 1457 info("Use INTx for the hotplug controller\n");
1559 dbg("%s: rc = %x\n", __FUNCTION__, rc);
1560 } else 1458 } else
1561 php_ctlr->irq = pdev->irq; 1459 php_ctlr->irq = pdev->irq;
1562 1460
@@ -1566,9 +1464,11 @@ int shpc_init(struct controller * ctrl,
1566 err("Can't get irq %d for the hotplug controller\n", php_ctlr->irq); 1464 err("Can't get irq %d for the hotplug controller\n", php_ctlr->irq);
1567 goto abort_free_ctlr; 1465 goto abort_free_ctlr;
1568 } 1466 }
1569 /* Execute OSHP method here */
1570 } 1467 }
1571 dbg("%s: Before adding HPC to HPC list\n", __FUNCTION__); 1468 dbg("%s: HPC at b:d:f:irq=0x%x:%x:%x:%x\n", __FUNCTION__,
1469 pdev->bus->number, PCI_SLOT(pdev->devfn),
1470 PCI_FUNC(pdev->devfn), pdev->irq);
1471 get_hp_hw_control_from_firmware(pdev);
1572 1472
1573 /* Add this HPC instance into the HPC list */ 1473 /* Add this HPC instance into the HPC list */
1574 spin_lock(&list_lock); 1474 spin_lock(&list_lock);
@@ -1607,7 +1507,6 @@ int shpc_init(struct controller * ctrl,
1607 dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword); 1507 dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
1608 } 1508 }
1609 1509
1610 dbg("%s: Leaving shpc_init\n", __FUNCTION__);
1611 DBG_LEAVE_ROUTINE 1510 DBG_LEAVE_ROUTINE
1612 return 0; 1511 return 0;
1613 1512
diff --git a/drivers/pci/hotplug/shpchp_pci.c b/drivers/pci/hotplug/shpchp_pci.c
index d867099114ec..b8e95acea3b6 100644
--- a/drivers/pci/hotplug/shpchp_pci.c
+++ b/drivers/pci/hotplug/shpchp_pci.c
@@ -27,784 +27,151 @@
27 * 27 *
28 */ 28 */
29 29
30#include <linux/config.h>
31#include <linux/module.h> 30#include <linux/module.h>
32#include <linux/kernel.h> 31#include <linux/kernel.h>
33#include <linux/types.h> 32#include <linux/types.h>
34#include <linux/slab.h>
35#include <linux/workqueue.h>
36#include <linux/proc_fs.h>
37#include <linux/pci.h> 33#include <linux/pci.h>
38#include "../pci.h" 34#include "../pci.h"
39#include "shpchp.h" 35#include "shpchp.h"
40#ifndef CONFIG_IA64
41#include "../../../arch/i386/pci/pci.h" /* horrible hack showing how processor dependant we are... */
42#endif
43 36
44int shpchp_configure_device (struct controller* ctrl, struct pci_func* func) 37void program_fw_provided_values(struct pci_dev *dev)
45{ 38{
46 unsigned char bus; 39 u16 pci_cmd, pci_bctl;
47 struct pci_bus *child; 40 struct pci_dev *cdev;
48 int num; 41 struct hotplug_params hpp = {0x8, 0x40, 0, 0}; /* defaults */
49 42
50 if (func->pci_dev == NULL) 43 /* Program hpp values for this device */
51 func->pci_dev = pci_find_slot(func->bus, PCI_DEVFN(func->device, func->function)); 44 if (!(dev->hdr_type == PCI_HEADER_TYPE_NORMAL ||
52 45 (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE &&
53 /* Still NULL ? Well then scan for it ! */ 46 (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI)))
54 if (func->pci_dev == NULL) { 47 return;
55 num = pci_scan_slot(ctrl->pci_dev->subordinate, PCI_DEVFN(func->device, func->function)); 48
56 if (num) { 49 get_hp_params_from_firmware(dev, &hpp);
57 dbg("%s: subordiante %p number %x\n", __FUNCTION__, ctrl->pci_dev->subordinate, 50
58 ctrl->pci_dev->subordinate->number); 51 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, hpp.cache_line_size);
59 pci_bus_add_devices(ctrl->pci_dev->subordinate); 52 pci_write_config_byte(dev, PCI_LATENCY_TIMER, hpp.latency_timer);
60 } 53 pci_read_config_word(dev, PCI_COMMAND, &pci_cmd);
61 54 if (hpp.enable_serr)
62 func->pci_dev = pci_find_slot(func->bus, PCI_DEVFN(func->device, func->function)); 55 pci_cmd |= PCI_COMMAND_SERR;
63 if (func->pci_dev == NULL) { 56 else
64 dbg("ERROR: pci_dev still null\n"); 57 pci_cmd &= ~PCI_COMMAND_SERR;
65 return 0; 58 if (hpp.enable_perr)
59 pci_cmd |= PCI_COMMAND_PARITY;
60 else
61 pci_cmd &= ~PCI_COMMAND_PARITY;
62 pci_write_config_word(dev, PCI_COMMAND, pci_cmd);
63
64 /* Program bridge control value and child devices */
65 if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
66 pci_write_config_byte(dev, PCI_SEC_LATENCY_TIMER,
67 hpp.latency_timer);
68 pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &pci_bctl);
69 if (hpp.enable_serr)
70 pci_bctl |= PCI_BRIDGE_CTL_SERR;
71 else
72 pci_bctl &= ~PCI_BRIDGE_CTL_SERR;
73 if (hpp.enable_perr)
74 pci_bctl |= PCI_BRIDGE_CTL_PARITY;
75 else
76 pci_bctl &= ~PCI_BRIDGE_CTL_PARITY;
77 pci_write_config_word(dev, PCI_BRIDGE_CONTROL, pci_bctl);
78 if (dev->subordinate) {
79 list_for_each_entry(cdev, &dev->subordinate->devices,
80 bus_list)
81 program_fw_provided_values(cdev);
66 } 82 }
67 } 83 }
68
69 if (func->pci_dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
70 pci_read_config_byte(func->pci_dev, PCI_SECONDARY_BUS, &bus);
71 child = pci_add_new_bus(func->pci_dev->bus, (func->pci_dev), bus);
72 pci_do_scan_bus(child);
73
74 }
75
76 return 0;
77} 84}
78 85
79 86int shpchp_configure_device(struct slot *p_slot)
80int shpchp_unconfigure_device(struct pci_func* func)
81{ 87{
82 int rc = 0; 88 struct pci_dev *dev;
83 int j; 89 struct pci_bus *parent = p_slot->ctrl->pci_dev->subordinate;
84 90 int num, fn;
85 dbg("%s: bus/dev/func = %x/%x/%x\n", __FUNCTION__, func->bus, 91
86 func->device, func->function); 92 dev = pci_find_slot(p_slot->bus, PCI_DEVFN(p_slot->device, 0));
87 93 if (dev) {
88 for (j=0; j<8 ; j++) { 94 err("Device %s already exists at %x:%x, cannot hot-add\n",
89 struct pci_dev* temp = pci_find_slot(func->bus, 95 pci_name(dev), p_slot->bus, p_slot->device);
90 (func->device << 3) | j); 96 return -EINVAL;
91 if (temp) {
92 pci_remove_bus_device(temp);
93 }
94 } 97 }
95 return rc;
96}
97
98/*
99 * shpchp_set_irq
100 *
101 * @bus_num: bus number of PCI device
102 * @dev_num: device number of PCI device
103 * @slot: pointer to u8 where slot number will be returned
104 */
105int shpchp_set_irq (u8 bus_num, u8 dev_num, u8 int_pin, u8 irq_num)
106{
107#if defined(CONFIG_X86) && !defined(CONFIG_X86_IO_APIC) && !defined(CONFIG_X86_64)
108 int rc;
109 u16 temp_word;
110 struct pci_dev fakedev;
111 struct pci_bus fakebus;
112 98
113 fakedev.devfn = dev_num << 3; 99 num = pci_scan_slot(parent, PCI_DEVFN(p_slot->device, 0));
114 fakedev.bus = &fakebus; 100 if (num == 0) {
115 fakebus.number = bus_num; 101 err("No new device found\n");
116 dbg("%s: dev %d, bus %d, pin %d, num %d\n", 102 return -ENODEV;
117 __FUNCTION__, dev_num, bus_num, int_pin, irq_num);
118 rc = pcibios_set_irq_routing(&fakedev, int_pin - 0x0a, irq_num);
119 dbg("%s: rc %d\n", __FUNCTION__, rc);
120 if (!rc)
121 return !rc;
122
123 /* set the Edge Level Control Register (ELCR) */
124 temp_word = inb(0x4d0);
125 temp_word |= inb(0x4d1) << 8;
126
127 temp_word |= 0x01 << irq_num;
128
129 /* This should only be for x86 as it sets the Edge Level Control Register */
130 outb((u8) (temp_word & 0xFF), 0x4d0);
131 outb((u8) ((temp_word & 0xFF00) >> 8), 0x4d1);
132#endif
133 return 0;
134}
135
136/* More PCI configuration routines; this time centered around hotplug controller */
137
138
139/*
140 * shpchp_save_config
141 *
142 * Reads configuration for all slots in a PCI bus and saves info.
143 *
144 * Note: For non-hot plug busses, the slot # saved is the device #
145 *
146 * returns 0 if success
147 */
148int shpchp_save_config(struct controller *ctrl, int busnumber, int num_ctlr_slots, int first_device_num)
149{
150 int rc;
151 u8 class_code;
152 u8 header_type;
153 u32 ID;
154 u8 secondary_bus;
155 struct pci_func *new_slot;
156 int sub_bus;
157 int FirstSupported;
158 int LastSupported;
159 int max_functions;
160 int function;
161 u8 DevError;
162 int device = 0;
163 int cloop = 0;
164 int stop_it;
165 int index;
166 int is_hot_plug = num_ctlr_slots || first_device_num;
167 struct pci_bus lpci_bus, *pci_bus;
168
169 dbg("%s: num_ctlr_slots = %d, first_device_num = %d\n", __FUNCTION__,
170 num_ctlr_slots, first_device_num);
171
172 memcpy(&lpci_bus, ctrl->pci_dev->subordinate, sizeof(lpci_bus));
173 pci_bus = &lpci_bus;
174
175 dbg("%s: num_ctlr_slots = %d, first_device_num = %d\n", __FUNCTION__,
176 num_ctlr_slots, first_device_num);
177
178 /* Decide which slots are supported */
179 if (is_hot_plug) {
180 /*********************************
181 * is_hot_plug is the slot mask
182 *********************************/
183 FirstSupported = first_device_num;
184 LastSupported = FirstSupported + num_ctlr_slots - 1;
185 } else {
186 FirstSupported = 0;
187 LastSupported = 0x1F;
188 } 103 }
189 104
190 dbg("FirstSupported = %d, LastSupported = %d\n", FirstSupported, 105 for (fn = 0; fn < 8; fn++) {
191 LastSupported); 106 if (!(dev = pci_find_slot(p_slot->bus,
192 107 PCI_DEVFN(p_slot->device, fn))))
193 /* Save PCI configuration space for all devices in supported slots */ 108 continue;
194 pci_bus->number = busnumber; 109 if ((dev->class >> 16) == PCI_BASE_CLASS_DISPLAY) {
195 for (device = FirstSupported; device <= LastSupported; device++) { 110 err("Cannot hot-add display device %s\n",
196 ID = 0xFFFFFFFF; 111 pci_name(dev));
197 rc = pci_bus_read_config_dword(pci_bus, PCI_DEVFN(device, 0), 112 continue;
198 PCI_VENDOR_ID, &ID);
199
200 if (ID != 0xFFFFFFFF) { /* device in slot */
201 rc = pci_bus_read_config_byte(pci_bus, PCI_DEVFN(device, 0),
202 0x0B, &class_code);
203 if (rc)
204 return rc;
205
206 rc = pci_bus_read_config_byte(pci_bus, PCI_DEVFN(device, 0),
207 PCI_HEADER_TYPE, &header_type);
208 if (rc)
209 return rc;
210
211 dbg("class_code = %x, header_type = %x\n", class_code, header_type);
212
213 /* If multi-function device, set max_functions to 8 */
214 if (header_type & 0x80)
215 max_functions = 8;
216 else
217 max_functions = 1;
218
219 function = 0;
220
221 do {
222 DevError = 0;
223
224 if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) { /* P-P Bridge */
225 /* Recurse the subordinate bus
226 * get the subordinate bus number
227 */
228 rc = pci_bus_read_config_byte(pci_bus,
229 PCI_DEVFN(device, function),
230 PCI_SECONDARY_BUS, &secondary_bus);
231 if (rc) {
232 return rc;
233 } else {
234 sub_bus = (int) secondary_bus;
235
236 /* Save secondary bus cfg spc with this recursive call. */
237 rc = shpchp_save_config(ctrl, sub_bus, 0, 0);
238 if (rc)
239 return rc;
240 }
241 }
242
243 index = 0;
244 new_slot = shpchp_slot_find(busnumber, device, index++);
245
246 dbg("new_slot = %p\n", new_slot);
247
248 while (new_slot && (new_slot->function != (u8) function)) {
249 new_slot = shpchp_slot_find(busnumber, device, index++);
250 dbg("new_slot = %p\n", new_slot);
251 }
252 if (!new_slot) {
253 /* Setup slot structure. */
254 new_slot = shpchp_slot_create(busnumber);
255 dbg("new_slot = %p\n", new_slot);
256
257 if (new_slot == NULL)
258 return(1);
259 }
260
261 new_slot->bus = (u8) busnumber;
262 new_slot->device = (u8) device;
263 new_slot->function = (u8) function;
264 new_slot->is_a_board = 1;
265 new_slot->switch_save = 0x10;
266 new_slot->pwr_save = 1;
267 /* In case of unsupported board */
268 new_slot->status = DevError;
269 new_slot->pci_dev = pci_find_slot(new_slot->bus,
270 (new_slot->device << 3) | new_slot->function);
271 dbg("new_slot->pci_dev = %p\n", new_slot->pci_dev);
272
273 for (cloop = 0; cloop < 0x20; cloop++) {
274 rc = pci_bus_read_config_dword(pci_bus,
275 PCI_DEVFN(device, function),
276 cloop << 2,
277 (u32 *) &(new_slot->config_space [cloop]));
278 /* dbg("new_slot->config_space[%x] = %x\n",
279 cloop, new_slot->config_space[cloop]); */
280 if (rc)
281 return rc;
282 }
283
284 function++;
285
286 stop_it = 0;
287
288 /* this loop skips to the next present function
289 * reading in Class Code and Header type.
290 */
291
292 while ((function < max_functions)&&(!stop_it)) {
293 rc = pci_bus_read_config_dword(pci_bus,
294 PCI_DEVFN(device, function),
295 PCI_VENDOR_ID, &ID);
296
297 if (ID == 0xFFFFFFFF) { /* nothing there. */
298 function++;
299 dbg("Nothing there\n");
300 } else { /* Something there */
301 rc = pci_bus_read_config_byte(pci_bus,
302 PCI_DEVFN(device, function),
303 0x0B, &class_code);
304 if (rc)
305 return rc;
306
307 rc = pci_bus_read_config_byte(pci_bus,
308 PCI_DEVFN(device, function),
309 PCI_HEADER_TYPE, &header_type);
310 if (rc)
311 return rc;
312
313 dbg("class_code = %x, header_type = %x\n",
314 class_code, header_type);
315 stop_it++;
316 }
317 }
318
319 } while (function < max_functions);
320 /* End of IF (device in slot?) */
321 } else if (is_hot_plug) {
322 /* Setup slot structure with entry for empty slot */
323 new_slot = shpchp_slot_create(busnumber);
324
325 if (new_slot == NULL) {
326 return(1);
327 }
328 dbg("new_slot = %p\n", new_slot);
329
330 new_slot->bus = (u8) busnumber;
331 new_slot->device = (u8) device;
332 new_slot->function = 0;
333 new_slot->is_a_board = 0;
334 new_slot->presence_save = 0;
335 new_slot->switch_save = 0;
336 } 113 }
337 } /* End of FOR loop */ 114 if ((dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) ||
338 115 (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)) {
339 return(0); 116 /* Find an unused bus number for the new bridge */
340} 117 struct pci_bus *child;
341 118 unsigned char busnr, start = parent->secondary;
342 119 unsigned char end = parent->subordinate;
343/* 120 for (busnr = start; busnr <= end; busnr++) {
344 * shpchp_save_slot_config 121 if (!pci_find_bus(pci_domain_nr(parent),
345 * 122 busnr))
346 * Saves configuration info for all PCI devices in a given slot 123 break;
347 * including subordinate busses.
348 *
349 * returns 0 if success
350 */
351int shpchp_save_slot_config(struct controller *ctrl, struct pci_func * new_slot)
352{
353 int rc;
354 u8 class_code;
355 u8 header_type;
356 u32 ID;
357 u8 secondary_bus;
358 int sub_bus;
359 int max_functions;
360 int function;
361 int cloop = 0;
362 int stop_it;
363 struct pci_bus lpci_bus, *pci_bus;
364 memcpy(&lpci_bus, ctrl->pci_dev->subordinate, sizeof(lpci_bus));
365 pci_bus = &lpci_bus;
366 pci_bus->number = new_slot->bus;
367
368 ID = 0xFFFFFFFF;
369
370 pci_bus_read_config_dword(pci_bus, PCI_DEVFN(new_slot->device, 0),
371 PCI_VENDOR_ID, &ID);
372
373 if (ID != 0xFFFFFFFF) { /* device in slot */
374 pci_bus_read_config_byte(pci_bus, PCI_DEVFN(new_slot->device, 0),
375 0x0B, &class_code);
376
377 pci_bus_read_config_byte(pci_bus, PCI_DEVFN(new_slot->device, 0),
378 PCI_HEADER_TYPE, &header_type);
379
380 if (header_type & 0x80) /* Multi-function device */
381 max_functions = 8;
382 else
383 max_functions = 1;
384
385 function = 0;
386
387 do {
388 if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) { /* PCI-PCI Bridge */
389 /* Recurse the subordinate bus */
390 pci_bus_read_config_byte(pci_bus,
391 PCI_DEVFN(new_slot->device, function),
392 PCI_SECONDARY_BUS, &secondary_bus);
393
394 sub_bus = (int) secondary_bus;
395
396 /* Save the config headers for the secondary bus. */
397 rc = shpchp_save_config(ctrl, sub_bus, 0, 0);
398
399 if (rc)
400 return rc;
401
402 } /* End of IF */
403
404 new_slot->status = 0;
405
406 for (cloop = 0; cloop < 0x20; cloop++) {
407 pci_bus_read_config_dword(pci_bus,
408 PCI_DEVFN(new_slot->device, function),
409 cloop << 2,
410 (u32 *) &(new_slot->config_space [cloop]));
411 } 124 }
412 125 if (busnr >= end) {
413 function++; 126 err("No free bus for hot-added bridge\n");
414 127 continue;
415 stop_it = 0;
416
417 /* this loop skips to the next present function
418 * reading in the Class Code and the Header type.
419 */
420
421 while ((function < max_functions) && (!stop_it)) {
422 pci_bus_read_config_dword(pci_bus,
423 PCI_DEVFN(new_slot->device, function),
424 PCI_VENDOR_ID, &ID);
425
426 if (ID == 0xFFFFFFFF) { /* nothing there. */
427 function++;
428 } else { /* Something there */
429 pci_bus_read_config_byte(pci_bus,
430 PCI_DEVFN(new_slot->device, function),
431 0x0B, &class_code);
432
433 pci_bus_read_config_byte(pci_bus,
434 PCI_DEVFN(new_slot->device, function),
435 PCI_HEADER_TYPE, &header_type);
436
437 stop_it++;
438 }
439 } 128 }
440 129 child = pci_add_new_bus(parent, dev, busnr);
441 } while (function < max_functions); 130 if (!child) {
442 } /* End of IF (device in slot?) */ 131 err("Cannot add new bus for %s\n",
443 else { 132 pci_name(dev));
444 return 2; 133 continue;
134 }
135 child->subordinate = pci_do_scan_bus(child);
136 pci_bus_size_bridges(child);
137 }
138 program_fw_provided_values(dev);
445 } 139 }
446 140
141 pci_bus_assign_resources(parent);
142 pci_bus_add_devices(parent);
143 pci_enable_bridges(parent);
447 return 0; 144 return 0;
448} 145}
449 146
450 147int shpchp_unconfigure_device(struct slot *p_slot)
451/*
452 * shpchp_save_used_resources
453 *
454 * Stores used resource information for existing boards. this is
455 * for boards that were in the system when this driver was loaded.
456 * this function is for hot plug ADD
457 *
458 * returns 0 if success
459 * if disable == 1(DISABLE_CARD),
460 * it loops for all functions of the slot and disables them.
461 * else, it just get resources of the function and return.
462 */
463int shpchp_save_used_resources(struct controller *ctrl, struct pci_func *func, int disable)
464{ 148{
465 u8 cloop; 149 int rc = 0;
466 u8 header_type; 150 int j;
467 u8 secondary_bus; 151 u8 bctl = 0;
468 u8 temp_byte; 152
469 u16 command; 153 dbg("%s: bus/dev = %x/%x\n", __FUNCTION__, p_slot->bus, p_slot->device);
470 u16 save_command;
471 u16 w_base, w_length;
472 u32 temp_register;
473 u32 save_base;
474 u32 base, length;
475 u64 base64 = 0;
476 int index = 0;
477 unsigned int devfn;
478 struct pci_resource *mem_node = NULL;
479 struct pci_resource *p_mem_node = NULL;
480 struct pci_resource *t_mem_node;
481 struct pci_resource *io_node;
482 struct pci_resource *bus_node;
483 struct pci_bus lpci_bus, *pci_bus;
484 memcpy(&lpci_bus, ctrl->pci_dev->subordinate, sizeof(lpci_bus));
485 pci_bus = &lpci_bus;
486
487 if (disable)
488 func = shpchp_slot_find(func->bus, func->device, index++);
489
490 while ((func != NULL) && func->is_a_board) {
491 pci_bus->number = func->bus;
492 devfn = PCI_DEVFN(func->device, func->function);
493
494 /* Save the command register */
495 pci_bus_read_config_word(pci_bus, devfn, PCI_COMMAND, &save_command);
496 154
497 if (disable) { 155 for (j=0; j<8 ; j++) {
498 /* disable card */ 156 struct pci_dev* temp = pci_find_slot(p_slot->bus,
499 command = 0x00; 157 (p_slot->device << 3) | j);
500 pci_bus_write_config_word(pci_bus, devfn, PCI_COMMAND, command); 158 if (!temp)
159 continue;
160 if ((temp->class >> 16) == PCI_BASE_CLASS_DISPLAY) {
161 err("Cannot remove display device %s\n",
162 pci_name(temp));
163 continue;
501 } 164 }
502 165 if (temp->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
503 /* Check for Bridge */ 166 pci_read_config_byte(temp, PCI_BRIDGE_CONTROL, &bctl);
504 pci_bus_read_config_byte(pci_bus, devfn, PCI_HEADER_TYPE, &header_type); 167 if (bctl & PCI_BRIDGE_CTL_VGA) {
505 168 err("Cannot remove display device %s\n",
506 if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) { /* PCI-PCI Bridge */ 169 pci_name(temp));
507 dbg("Save_used_res of PCI bridge b:d=0x%x:%x, sc=0x%x\n", 170 continue;
508 func->bus, func->device, save_command);
509 if (disable) {
510 /* Clear Bridge Control Register */
511 command = 0x00;
512 pci_bus_write_config_word(pci_bus, devfn, PCI_BRIDGE_CONTROL, command);
513 } 171 }
514
515 pci_bus_read_config_byte(pci_bus, devfn, PCI_SECONDARY_BUS, &secondary_bus);
516 pci_bus_read_config_byte(pci_bus, devfn, PCI_SUBORDINATE_BUS, &temp_byte);
517
518 bus_node = kmalloc(sizeof(struct pci_resource),
519 GFP_KERNEL);
520 if (!bus_node)
521 return -ENOMEM;
522
523 bus_node->base = (ulong)secondary_bus;
524 bus_node->length = (ulong)(temp_byte - secondary_bus + 1);
525
526 bus_node->next = func->bus_head;
527 func->bus_head = bus_node;
528
529 /* Save IO base and Limit registers */
530 pci_bus_read_config_byte(pci_bus, devfn, PCI_IO_BASE, &temp_byte);
531 base = temp_byte;
532 pci_bus_read_config_byte(pci_bus, devfn, PCI_IO_LIMIT, &temp_byte);
533 length = temp_byte;
534
535 if ((base <= length) && (!disable || (save_command & PCI_COMMAND_IO))) {
536 io_node = kmalloc(sizeof(struct pci_resource),
537 GFP_KERNEL);
538 if (!io_node)
539 return -ENOMEM;
540
541 io_node->base = (ulong)(base & PCI_IO_RANGE_MASK) << 8;
542 io_node->length = (ulong)(length - base + 0x10) << 8;
543
544 io_node->next = func->io_head;
545 func->io_head = io_node;
546 }
547
548 /* Save memory base and Limit registers */
549 pci_bus_read_config_word(pci_bus, devfn, PCI_MEMORY_BASE, &w_base);
550 pci_bus_read_config_word(pci_bus, devfn, PCI_MEMORY_LIMIT, &w_length);
551
552 if ((w_base <= w_length) && (!disable || (save_command & PCI_COMMAND_MEMORY))) {
553 mem_node = kmalloc(sizeof(struct pci_resource),
554 GFP_KERNEL);
555 if (!mem_node)
556 return -ENOMEM;
557
558 mem_node->base = (ulong)w_base << 16;
559 mem_node->length = (ulong)(w_length - w_base + 0x10) << 16;
560
561 mem_node->next = func->mem_head;
562 func->mem_head = mem_node;
563 }
564 /* Save prefetchable memory base and Limit registers */
565 pci_bus_read_config_word(pci_bus, devfn, PCI_PREF_MEMORY_BASE, &w_base);
566 pci_bus_read_config_word(pci_bus, devfn, PCI_PREF_MEMORY_LIMIT, &w_length);
567
568 if ((w_base <= w_length) && (!disable || (save_command & PCI_COMMAND_MEMORY))) {
569 p_mem_node = kmalloc(sizeof(struct pci_resource),
570 GFP_KERNEL);
571 if (!p_mem_node)
572 return -ENOMEM;
573
574 p_mem_node->base = (ulong)w_base << 16;
575 p_mem_node->length = (ulong)(w_length - w_base + 0x10) << 16;
576
577 p_mem_node->next = func->p_mem_head;
578 func->p_mem_head = p_mem_node;
579 }
580 } else if ((header_type & 0x7F) == PCI_HEADER_TYPE_NORMAL) {
581 dbg("Save_used_res of PCI adapter b:d=0x%x:%x, sc=0x%x\n",
582 func->bus, func->device, save_command);
583
584 /* Figure out IO and memory base lengths */
585 for (cloop = PCI_BASE_ADDRESS_0; cloop <= PCI_BASE_ADDRESS_5; cloop += 4) {
586 pci_bus_read_config_dword(pci_bus, devfn, cloop, &save_base);
587
588 temp_register = 0xFFFFFFFF;
589 pci_bus_write_config_dword(pci_bus, devfn, cloop, temp_register);
590 pci_bus_read_config_dword(pci_bus, devfn, cloop, &temp_register);
591
592 if (!disable)
593 pci_bus_write_config_dword(pci_bus, devfn, cloop, save_base);
594
595 if (!temp_register)
596 continue;
597
598 base = temp_register;
599
600 if ((base & PCI_BASE_ADDRESS_SPACE_IO) &&
601 (!disable || (save_command & PCI_COMMAND_IO))) {
602 /* IO base */
603 /* set temp_register = amount of IO space requested */
604 base = base & 0xFFFFFFFCL;
605 base = (~base) + 1;
606
607 io_node = kmalloc(sizeof (struct pci_resource),
608 GFP_KERNEL);
609 if (!io_node)
610 return -ENOMEM;
611
612 io_node->base = (ulong)save_base & PCI_BASE_ADDRESS_IO_MASK;
613 io_node->length = (ulong)base;
614 dbg("sur adapter: IO bar=0x%x(length=0x%x)\n",
615 io_node->base, io_node->length);
616
617 io_node->next = func->io_head;
618 func->io_head = io_node;
619 } else { /* map Memory */
620 int prefetchable = 1;
621 /* struct pci_resources **res_node; */
622 char *res_type_str = "PMEM";
623 u32 temp_register2;
624
625 t_mem_node = kmalloc(sizeof (struct pci_resource),
626 GFP_KERNEL);
627 if (!t_mem_node)
628 return -ENOMEM;
629
630 if (!(base & PCI_BASE_ADDRESS_MEM_PREFETCH) &&
631 (!disable || (save_command & PCI_COMMAND_MEMORY))) {
632 prefetchable = 0;
633 mem_node = t_mem_node;
634 res_type_str++;
635 } else
636 p_mem_node = t_mem_node;
637
638 base = base & 0xFFFFFFF0L;
639 base = (~base) + 1;
640
641 switch (temp_register & PCI_BASE_ADDRESS_MEM_TYPE_MASK) {
642 case PCI_BASE_ADDRESS_MEM_TYPE_32:
643 if (prefetchable) {
644 p_mem_node->base = (ulong)save_base & PCI_BASE_ADDRESS_MEM_MASK;
645 p_mem_node->length = (ulong)base;
646 dbg("sur adapter: 32 %s bar=0x%x(length=0x%x)\n",
647 res_type_str,
648 p_mem_node->base,
649 p_mem_node->length);
650
651 p_mem_node->next = func->p_mem_head;
652 func->p_mem_head = p_mem_node;
653 } else {
654 mem_node->base = (ulong)save_base & PCI_BASE_ADDRESS_MEM_MASK;
655 mem_node->length = (ulong)base;
656 dbg("sur adapter: 32 %s bar=0x%x(length=0x%x)\n",
657 res_type_str,
658 mem_node->base,
659 mem_node->length);
660
661 mem_node->next = func->mem_head;
662 func->mem_head = mem_node;
663 }
664 break;
665 case PCI_BASE_ADDRESS_MEM_TYPE_64:
666 pci_bus_read_config_dword(pci_bus, devfn, cloop+4, &temp_register2);
667 base64 = temp_register2;
668 base64 = (base64 << 32) | save_base;
669
670 if (temp_register2) {
671 dbg("sur adapter: 64 %s high dword of base64(0x%x:%x) masked to 0\n",
672 res_type_str, temp_register2, (u32)base64);
673 base64 &= 0x00000000FFFFFFFFL;
674 }
675
676 if (prefetchable) {
677 p_mem_node->base = base64 & PCI_BASE_ADDRESS_MEM_MASK;
678 p_mem_node->length = base;
679 dbg("sur adapter: 64 %s base=0x%x(len=0x%x)\n",
680 res_type_str,
681 p_mem_node->base,
682 p_mem_node->length);
683
684 p_mem_node->next = func->p_mem_head;
685 func->p_mem_head = p_mem_node;
686 } else {
687 mem_node->base = base64 & PCI_BASE_ADDRESS_MEM_MASK;
688 mem_node->length = base;
689 dbg("sur adapter: 64 %s base=0x%x(len=0x%x)\n",
690 res_type_str,
691 mem_node->base,
692 mem_node->length);
693
694 mem_node->next = func->mem_head;
695 func->mem_head = mem_node;
696 }
697 cloop += 4;
698 break;
699 default:
700 dbg("asur: reserved BAR type=0x%x\n",
701 temp_register);
702 break;
703 }
704 }
705 } /* End of base register loop */
706 } else { /* Some other unknown header type */
707 dbg("Save_used_res of PCI unknown type b:d=0x%x:%x. skip.\n",
708 func->bus, func->device);
709 } 172 }
710 173 pci_remove_bus_device(temp);
711 /* find the next device in this slot */
712 if (!disable)
713 break;
714 func = shpchp_slot_find(func->bus, func->device, index++);
715 } 174 }
716
717 return 0;
718}
719
720/**
721 * kfree_resource_list: release memory of all list members
722 * @res: resource list to free
723 */
724static inline void
725return_resource_list(struct pci_resource **func, struct pci_resource **res)
726{
727 struct pci_resource *node;
728 struct pci_resource *t_node;
729
730 node = *func;
731 *func = NULL;
732 while (node) {
733 t_node = node->next;
734 return_resource(res, node);
735 node = t_node;
736 }
737}
738
739/*
740 * shpchp_return_board_resources
741 *
742 * this routine returns all resources allocated to a board to
743 * the available pool.
744 *
745 * returns 0 if success
746 */
747int shpchp_return_board_resources(struct pci_func * func,
748 struct resource_lists * resources)
749{
750 int rc;
751 dbg("%s\n", __FUNCTION__);
752
753 if (!func)
754 return 1;
755
756 return_resource_list(&(func->io_head),&(resources->io_head));
757 return_resource_list(&(func->mem_head),&(resources->mem_head));
758 return_resource_list(&(func->p_mem_head),&(resources->p_mem_head));
759 return_resource_list(&(func->bus_head),&(resources->bus_head));
760
761 rc = shpchp_resource_sort_and_combine(&(resources->mem_head));
762 rc |= shpchp_resource_sort_and_combine(&(resources->p_mem_head));
763 rc |= shpchp_resource_sort_and_combine(&(resources->io_head));
764 rc |= shpchp_resource_sort_and_combine(&(resources->bus_head));
765
766 return rc; 175 return rc;
767} 176}
768 177
769/**
770 * kfree_resource_list: release memory of all list members
771 * @res: resource list to free
772 */
773static inline void
774kfree_resource_list(struct pci_resource **r)
775{
776 struct pci_resource *res, *tres;
777
778 res = *r;
779 *r = NULL;
780
781 while (res) {
782 tres = res;
783 res = res->next;
784 kfree(tres);
785 }
786}
787
788/**
789 * shpchp_destroy_resource_list: put node back in the resource list
790 * @resources: list to put nodes back
791 */
792void shpchp_destroy_resource_list(struct resource_lists *resources)
793{
794 kfree_resource_list(&(resources->io_head));
795 kfree_resource_list(&(resources->mem_head));
796 kfree_resource_list(&(resources->p_mem_head));
797 kfree_resource_list(&(resources->bus_head));
798}
799
800/**
801 * shpchp_destroy_board_resources: put node back in the resource list
802 * @resources: list to put nodes back
803 */
804void shpchp_destroy_board_resources(struct pci_func * func)
805{
806 kfree_resource_list(&(func->io_head));
807 kfree_resource_list(&(func->mem_head));
808 kfree_resource_list(&(func->p_mem_head));
809 kfree_resource_list(&(func->bus_head));
810}
diff --git a/drivers/pci/hotplug/shpchp_sysfs.c b/drivers/pci/hotplug/shpchp_sysfs.c
index c9445ebda5c7..f5cfbf2c047c 100644
--- a/drivers/pci/hotplug/shpchp_sysfs.c
+++ b/drivers/pci/hotplug/shpchp_sysfs.c
@@ -26,12 +26,9 @@
26 * 26 *
27 */ 27 */
28 28
29#include <linux/config.h>
30#include <linux/module.h> 29#include <linux/module.h>
31#include <linux/kernel.h> 30#include <linux/kernel.h>
32#include <linux/types.h> 31#include <linux/types.h>
33#include <linux/proc_fs.h>
34#include <linux/workqueue.h>
35#include <linux/pci.h> 32#include <linux/pci.h>
36#include "shpchp.h" 33#include "shpchp.h"
37 34
@@ -40,104 +37,60 @@
40 37
41static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, char *buf) 38static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, char *buf)
42{ 39{
43 struct pci_dev *pci_dev; 40 struct pci_dev *pdev;
44 struct controller *ctrl;
45 char * out = buf; 41 char * out = buf;
46 int index; 42 int index, busnr;
47 struct pci_resource *res; 43 struct resource *res;
44 struct pci_bus *bus;
48 45
49 pci_dev = container_of (dev, struct pci_dev, dev); 46 pdev = container_of (dev, struct pci_dev, dev);
50 ctrl = pci_get_drvdata(pci_dev); 47 bus = pdev->subordinate;
51 48
52 out += sprintf(buf, "Free resources: memory\n"); 49 out += sprintf(buf, "Free resources: memory\n");
53 index = 11; 50 for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) {
54 res = ctrl->mem_head; 51 res = bus->resource[index];
55 while (res && index--) { 52 if (res && (res->flags & IORESOURCE_MEM) &&
56 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length); 53 !(res->flags & IORESOURCE_PREFETCH)) {
57 res = res->next; 54 out += sprintf(out, "start = %8.8lx, length = %8.8lx\n",
55 res->start, (res->end - res->start));
56 }
58 } 57 }
59 out += sprintf(out, "Free resources: prefetchable memory\n"); 58 out += sprintf(out, "Free resources: prefetchable memory\n");
60 index = 11; 59 for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) {
61 res = ctrl->p_mem_head; 60 res = bus->resource[index];
62 while (res && index--) { 61 if (res && (res->flags & IORESOURCE_MEM) &&
63 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length); 62 (res->flags & IORESOURCE_PREFETCH)) {
64 res = res->next; 63 out += sprintf(out, "start = %8.8lx, length = %8.8lx\n",
64 res->start, (res->end - res->start));
65 }
65 } 66 }
66 out += sprintf(out, "Free resources: IO\n"); 67 out += sprintf(out, "Free resources: IO\n");
67 index = 11; 68 for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) {
68 res = ctrl->io_head; 69 res = bus->resource[index];
69 while (res && index--) { 70 if (res && (res->flags & IORESOURCE_IO)) {
70 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length); 71 out += sprintf(out, "start = %8.8lx, length = %8.8lx\n",
71 res = res->next; 72 res->start, (res->end - res->start));
73 }
72 } 74 }
73 out += sprintf(out, "Free resources: bus numbers\n"); 75 out += sprintf(out, "Free resources: bus numbers\n");
74 index = 11; 76 for (busnr = bus->secondary; busnr <= bus->subordinate; busnr++) {
75 res = ctrl->bus_head; 77 if (!pci_find_bus(pci_domain_nr(bus), busnr))
76 while (res && index--) { 78 break;
77 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
78 res = res->next;
79 } 79 }
80 if (busnr < bus->subordinate)
81 out += sprintf(out, "start = %8.8x, length = %8.8x\n",
82 busnr, (bus->subordinate - busnr));
80 83
81 return out - buf; 84 return out - buf;
82} 85}
83static DEVICE_ATTR (ctrl, S_IRUGO, show_ctrl, NULL); 86static DEVICE_ATTR (ctrl, S_IRUGO, show_ctrl, NULL);
84 87
85static ssize_t show_dev (struct device *dev, struct device_attribute *attr, char *buf) 88void shpchp_create_ctrl_files (struct controller *ctrl)
86{ 89{
87 struct pci_dev *pci_dev; 90 device_create_file (&ctrl->pci_dev->dev, &dev_attr_ctrl);
88 struct controller *ctrl;
89 char * out = buf;
90 int index;
91 struct pci_resource *res;
92 struct pci_func *new_slot;
93 struct slot *slot;
94
95 pci_dev = container_of (dev, struct pci_dev, dev);
96 ctrl = pci_get_drvdata(pci_dev);
97
98 slot=ctrl->slot;
99
100 while (slot) {
101 new_slot = shpchp_slot_find(slot->bus, slot->device, 0);
102 if (!new_slot)
103 break;
104 out += sprintf(out, "assigned resources: memory\n");
105 index = 11;
106 res = new_slot->mem_head;
107 while (res && index--) {
108 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
109 res = res->next;
110 }
111 out += sprintf(out, "assigned resources: prefetchable memory\n");
112 index = 11;
113 res = new_slot->p_mem_head;
114 while (res && index--) {
115 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
116 res = res->next;
117 }
118 out += sprintf(out, "assigned resources: IO\n");
119 index = 11;
120 res = new_slot->io_head;
121 while (res && index--) {
122 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
123 res = res->next;
124 }
125 out += sprintf(out, "assigned resources: bus numbers\n");
126 index = 11;
127 res = new_slot->bus_head;
128 while (res && index--) {
129 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
130 res = res->next;
131 }
132 slot=slot->next;
133 }
134
135 return out - buf;
136} 91}
137static DEVICE_ATTR (dev, S_IRUGO, show_dev, NULL);
138 92
139void shpchp_create_ctrl_files (struct controller *ctrl) 93void shpchp_remove_ctrl_files(struct controller *ctrl)
140{ 94{
141 device_create_file (&ctrl->pci_dev->dev, &dev_attr_ctrl); 95 device_remove_file(&ctrl->pci_dev->dev, &dev_attr_ctrl);
142 device_create_file (&ctrl->pci_dev->dev, &dev_attr_dev);
143} 96}
diff --git a/drivers/pci/hotplug/shpchprm.h b/drivers/pci/hotplug/shpchprm.h
deleted file mode 100644
index 057b192ce589..000000000000
--- a/drivers/pci/hotplug/shpchprm.h
+++ /dev/null
@@ -1,55 +0,0 @@
1/*
2 * SHPCHPRM : SHPCHP Resource Manager for ACPI/non-ACPI platform
3 *
4 * Copyright (C) 1995,2001 Compaq Computer Corporation
5 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
6 * Copyright (C) 2001 IBM Corp.
7 * Copyright (C) 2003-2004 Intel Corporation
8 *
9 * All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or (at
14 * your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
19 * NON INFRINGEMENT. See the GNU General Public License for more
20 * details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 * Send feedback to <greg@kroah.com>, <kristen.c.accardi@intel.com>
27 *
28 */
29
30#ifndef _SHPCHPRM_H_
31#define _SHPCHPRM_H_
32
33#ifdef CONFIG_HOTPLUG_PCI_SHPC_PHPRM_LEGACY
34#include "shpchprm_legacy.h"
35#else
36#include "shpchprm_nonacpi.h"
37#endif
38
39int shpchprm_init(enum php_ctlr_type ct);
40void shpchprm_cleanup(void);
41int shpchprm_print_pirt(void);
42int shpchprm_find_available_resources(struct controller *ctrl);
43int shpchprm_set_hpp(struct controller *ctrl, struct pci_func *func, u8 card_type);
44void shpchprm_enable_card(struct controller *ctrl, struct pci_func *func, u8 card_type);
45int shpchprm_get_physical_slot_number(struct controller *ctrl, u32 *sun, u8 busnum, u8 devnum);
46
47#ifdef DEBUG
48#define RES_CHECK(this, bits) \
49 { if (((this) & (bits - 1))) \
50 printk("%s:%d ERR: potential res loss!\n", __FUNCTION__, __LINE__); }
51#else
52#define RES_CHECK(this, bits)
53#endif
54
55#endif /* _SHPCHPRM_H_ */
diff --git a/drivers/pci/hotplug/shpchprm_acpi.c b/drivers/pci/hotplug/shpchprm_acpi.c
index d37b31658edf..17145e52223a 100644
--- a/drivers/pci/hotplug/shpchprm_acpi.c
+++ b/drivers/pci/hotplug/shpchprm_acpi.c
@@ -24,91 +24,19 @@
24 * 24 *
25 */ 25 */
26 26
27#include <linux/config.h>
28#include <linux/module.h> 27#include <linux/module.h>
29#include <linux/kernel.h> 28#include <linux/kernel.h>
30#include <linux/types.h> 29#include <linux/types.h>
31#include <linux/pci.h> 30#include <linux/pci.h>
32#include <linux/init.h>
33#include <linux/acpi.h>
34#include <linux/efi.h>
35#include <asm/uaccess.h>
36#include <asm/system.h>
37#ifdef CONFIG_IA64
38#include <asm/iosapic.h>
39#endif
40#include <acpi/acpi.h> 31#include <acpi/acpi.h>
41#include <acpi/acpi_bus.h> 32#include <acpi/acpi_bus.h>
42#include <acpi/actypes.h> 33#include <acpi/actypes.h>
43#include "shpchp.h" 34#include "shpchp.h"
44#include "shpchprm.h"
45
46#define PCI_MAX_BUS 0x100
47#define ACPI_STA_DEVICE_PRESENT 0x01
48 35
49#define METHOD_NAME__SUN "_SUN" 36#define METHOD_NAME__SUN "_SUN"
50#define METHOD_NAME__HPP "_HPP" 37#define METHOD_NAME__HPP "_HPP"
51#define METHOD_NAME_OSHP "OSHP" 38#define METHOD_NAME_OSHP "OSHP"
52 39
53#define PHP_RES_BUS 0xA0
54#define PHP_RES_IO 0xA1
55#define PHP_RES_MEM 0xA2
56#define PHP_RES_PMEM 0xA3
57
58#define BRIDGE_TYPE_P2P 0x00
59#define BRIDGE_TYPE_HOST 0x01
60
61/* this should go to drivers/acpi/include/ */
62struct acpi__hpp {
63 u8 cache_line_size;
64 u8 latency_timer;
65 u8 enable_serr;
66 u8 enable_perr;
67};
68
69struct acpi_php_slot {
70 struct acpi_php_slot *next;
71 struct acpi_bridge *bridge;
72 acpi_handle handle;
73 int seg;
74 int bus;
75 int dev;
76 int fun;
77 u32 sun;
78 struct pci_resource *mem_head;
79 struct pci_resource *p_mem_head;
80 struct pci_resource *io_head;
81 struct pci_resource *bus_head;
82 void *slot_ops; /* _STA, _EJx, etc */
83 struct slot *slot;
84}; /* per func */
85
86struct acpi_bridge {
87 struct acpi_bridge *parent;
88 struct acpi_bridge *next;
89 struct acpi_bridge *child;
90 acpi_handle handle;
91 int seg;
92 int pbus; /* pdev->bus->number */
93 int pdevice; /* PCI_SLOT(pdev->devfn) */
94 int pfunction; /* PCI_DEVFN(pdev->devfn) */
95 int bus; /* pdev->subordinate->number */
96 struct acpi__hpp *_hpp;
97 struct acpi_php_slot *slots;
98 struct pci_resource *tmem_head; /* total from crs */
99 struct pci_resource *tp_mem_head; /* total from crs */
100 struct pci_resource *tio_head; /* total from crs */
101 struct pci_resource *tbus_head; /* total from crs */
102 struct pci_resource *mem_head; /* available */
103 struct pci_resource *p_mem_head; /* available */
104 struct pci_resource *io_head; /* available */
105 struct pci_resource *bus_head; /* available */
106 int scanned;
107 int type;
108};
109
110static struct acpi_bridge *acpi_bridges_head;
111
112static u8 * acpi_path_name( acpi_handle handle) 40static u8 * acpi_path_name( acpi_handle handle)
113{ 41{
114 acpi_status status; 42 acpi_status status;
@@ -124,82 +52,43 @@ static u8 * acpi_path_name( acpi_handle handle)
124 return path_name; 52 return path_name;
125} 53}
126 54
127static void acpi_get__hpp ( struct acpi_bridge *ab); 55static acpi_status
128static void acpi_run_oshp ( struct acpi_bridge *ab); 56acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
129
130static int acpi_add_slot_to_php_slots(
131 struct acpi_bridge *ab,
132 int bus_num,
133 acpi_handle handle,
134 u32 adr,
135 u32 sun
136 )
137{
138 struct acpi_php_slot *aps;
139 static long samesun = -1;
140
141 aps = (struct acpi_php_slot *) kmalloc (sizeof(struct acpi_php_slot), GFP_KERNEL);
142 if (!aps) {
143 err ("acpi_shpchprm: alloc for aps fail\n");
144 return -1;
145 }
146 memset(aps, 0, sizeof(struct acpi_php_slot));
147
148 aps->handle = handle;
149 aps->bus = bus_num;
150 aps->dev = (adr >> 16) & 0xffff;
151 aps->fun = adr & 0xffff;
152 aps->sun = sun;
153
154 aps->next = ab->slots; /* cling to the bridge */
155 aps->bridge = ab;
156 ab->slots = aps;
157
158 ab->scanned += 1;
159 if (!ab->_hpp)
160 acpi_get__hpp(ab);
161
162 acpi_run_oshp(ab);
163
164 if (sun != samesun) {
165 info("acpi_shpchprm: Slot sun(%x) at s:b:d:f=0x%02x:%02x:%02x:%02x\n", aps->sun, ab->seg,
166 aps->bus, aps->dev, aps->fun);
167 samesun = sun;
168 }
169 return 0;
170}
171
172static void acpi_get__hpp ( struct acpi_bridge *ab)
173{ 57{
174 acpi_status status; 58 acpi_status status;
175 u8 nui[4]; 59 u8 nui[4];
176 struct acpi_buffer ret_buf = { 0, NULL}; 60 struct acpi_buffer ret_buf = { 0, NULL};
177 union acpi_object *ext_obj, *package; 61 union acpi_object *ext_obj, *package;
178 u8 *path_name = acpi_path_name(ab->handle); 62 u8 *path_name = acpi_path_name(handle);
179 int i, len = 0; 63 int i, len = 0;
180 64
181 /* get _hpp */ 65 /* get _hpp */
182 status = acpi_evaluate_object(ab->handle, METHOD_NAME__HPP, NULL, &ret_buf); 66 status = acpi_evaluate_object(handle, METHOD_NAME__HPP, NULL, &ret_buf);
183 switch (status) { 67 switch (status) {
184 case AE_BUFFER_OVERFLOW: 68 case AE_BUFFER_OVERFLOW:
185 ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL); 69 ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL);
186 if (!ret_buf.pointer) { 70 if (!ret_buf.pointer) {
187 err ("acpi_shpchprm:%s alloc for _HPP fail\n", path_name); 71 err ("%s:%s alloc for _HPP fail\n", __FUNCTION__,
188 return; 72 path_name);
73 return AE_NO_MEMORY;
189 } 74 }
190 status = acpi_evaluate_object(ab->handle, METHOD_NAME__HPP, NULL, &ret_buf); 75 status = acpi_evaluate_object(handle, METHOD_NAME__HPP,
76 NULL, &ret_buf);
191 if (ACPI_SUCCESS(status)) 77 if (ACPI_SUCCESS(status))
192 break; 78 break;
193 default: 79 default:
194 if (ACPI_FAILURE(status)) { 80 if (ACPI_FAILURE(status)) {
195 err("acpi_shpchprm:%s _HPP fail=0x%x\n", path_name, status); 81 dbg("%s:%s _HPP fail=0x%x\n", __FUNCTION__,
196 return; 82 path_name, status);
83 return status;
197 } 84 }
198 } 85 }
199 86
200 ext_obj = (union acpi_object *) ret_buf.pointer; 87 ext_obj = (union acpi_object *) ret_buf.pointer;
201 if (ext_obj->type != ACPI_TYPE_PACKAGE) { 88 if (ext_obj->type != ACPI_TYPE_PACKAGE) {
202 err ("acpi_shpchprm:%s _HPP obj not a package\n", path_name); 89 err ("%s:%s _HPP obj not a package\n", __FUNCTION__,
90 path_name);
91 status = AE_ERROR;
203 goto free_and_return; 92 goto free_and_return;
204 } 93 }
205 94
@@ -212,1353 +101,41 @@ static void acpi_get__hpp ( struct acpi_bridge *ab)
212 nui[i] = (u8)ext_obj->integer.value; 101 nui[i] = (u8)ext_obj->integer.value;
213 break; 102 break;
214 default: 103 default:
215 err ("acpi_shpchprm:%s _HPP obj type incorrect\n", path_name); 104 err ("%s:%s _HPP obj type incorrect\n", __FUNCTION__,
105 path_name);
106 status = AE_ERROR;
216 goto free_and_return; 107 goto free_and_return;
217 } 108 }
218 } 109 }
219 110
220 ab->_hpp = kmalloc (sizeof (struct acpi__hpp), GFP_KERNEL); 111 hpp->cache_line_size = nui[0];
221 if (!ab->_hpp) { 112 hpp->latency_timer = nui[1];
222 err ("acpi_shpchprm:%s alloc for _HPP failed\n", path_name); 113 hpp->enable_serr = nui[2];
223 goto free_and_return; 114 hpp->enable_perr = nui[3];
224 }
225 memset(ab->_hpp, 0, sizeof(struct acpi__hpp));
226 115
227 ab->_hpp->cache_line_size = nui[0]; 116 dbg(" _HPP: cache_line_size=0x%x\n", hpp->cache_line_size);
228 ab->_hpp->latency_timer = nui[1]; 117 dbg(" _HPP: latency timer =0x%x\n", hpp->latency_timer);
229 ab->_hpp->enable_serr = nui[2]; 118 dbg(" _HPP: enable SERR =0x%x\n", hpp->enable_serr);
230 ab->_hpp->enable_perr = nui[3]; 119 dbg(" _HPP: enable PERR =0x%x\n", hpp->enable_perr);
231
232 dbg(" _HPP: cache_line_size=0x%x\n", ab->_hpp->cache_line_size);
233 dbg(" _HPP: latency timer =0x%x\n", ab->_hpp->latency_timer);
234 dbg(" _HPP: enable SERR =0x%x\n", ab->_hpp->enable_serr);
235 dbg(" _HPP: enable PERR =0x%x\n", ab->_hpp->enable_perr);
236 120
237free_and_return: 121free_and_return:
238 kfree(ret_buf.pointer); 122 kfree(ret_buf.pointer);
239}
240
241static void acpi_run_oshp ( struct acpi_bridge *ab)
242{
243 acpi_status status;
244 u8 *path_name = acpi_path_name(ab->handle);
245
246 /* run OSHP */
247 status = acpi_evaluate_object(ab->handle, METHOD_NAME_OSHP, NULL, NULL);
248 if (ACPI_FAILURE(status)) {
249 err("acpi_pciehprm:%s OSHP fails=0x%x\n", path_name, status);
250 } else
251 dbg("acpi_pciehprm:%s OSHP passes =0x%x\n", path_name, status);
252 return;
253}
254
255static acpi_status acpi_evaluate_crs(
256 acpi_handle handle,
257 struct acpi_resource **retbuf
258 )
259{
260 acpi_status status;
261 struct acpi_buffer crsbuf;
262 u8 *path_name = acpi_path_name(handle);
263
264 crsbuf.length = 0;
265 crsbuf.pointer = NULL;
266
267 status = acpi_get_current_resources (handle, &crsbuf);
268
269 switch (status) {
270 case AE_BUFFER_OVERFLOW:
271 break; /* found */
272 case AE_NOT_FOUND:
273 dbg("acpi_shpchprm:%s _CRS not found\n", path_name);
274 return status;
275 default:
276 err ("acpi_shpchprm:%s _CRS fail=0x%x\n", path_name, status);
277 return status;
278 }
279
280 crsbuf.pointer = kmalloc (crsbuf.length, GFP_KERNEL);
281 if (!crsbuf.pointer) {
282 err ("acpi_shpchprm: alloc %ld bytes for %s _CRS fail\n", (ulong)crsbuf.length, path_name);
283 return AE_NO_MEMORY;
284 }
285
286 status = acpi_get_current_resources (handle, &crsbuf);
287 if (ACPI_FAILURE(status)) {
288 err("acpi_shpchprm: %s _CRS fail=0x%x.\n", path_name, status);
289 kfree(crsbuf.pointer);
290 return status;
291 }
292
293 *retbuf = crsbuf.pointer;
294
295 return status;
296}
297
298static void free_pci_resource ( struct pci_resource *aprh)
299{
300 struct pci_resource *res, *next;
301
302 for (res = aprh; res; res = next) {
303 next = res->next;
304 kfree(res);
305 }
306}
307
308static void print_pci_resource ( struct pci_resource *aprh)
309{
310 struct pci_resource *res;
311
312 for (res = aprh; res; res = res->next)
313 dbg(" base= 0x%x length= 0x%x\n", res->base, res->length);
314}
315
316static void print_slot_resources( struct acpi_php_slot *aps)
317{
318 if (aps->bus_head) {
319 dbg(" BUS Resources:\n");
320 print_pci_resource (aps->bus_head);
321 }
322
323 if (aps->io_head) {
324 dbg(" IO Resources:\n");
325 print_pci_resource (aps->io_head);
326 }
327
328 if (aps->mem_head) {
329 dbg(" MEM Resources:\n");
330 print_pci_resource (aps->mem_head);
331 }
332
333 if (aps->p_mem_head) {
334 dbg(" PMEM Resources:\n");
335 print_pci_resource (aps->p_mem_head);
336 }
337}
338
339static void print_pci_resources( struct acpi_bridge *ab)
340{
341 if (ab->tbus_head) {
342 dbg(" Total BUS Resources:\n");
343 print_pci_resource (ab->tbus_head);
344 }
345 if (ab->bus_head) {
346 dbg(" BUS Resources:\n");
347 print_pci_resource (ab->bus_head);
348 }
349
350 if (ab->tio_head) {
351 dbg(" Total IO Resources:\n");
352 print_pci_resource (ab->tio_head);
353 }
354 if (ab->io_head) {
355 dbg(" IO Resources:\n");
356 print_pci_resource (ab->io_head);
357 }
358
359 if (ab->tmem_head) {
360 dbg(" Total MEM Resources:\n");
361 print_pci_resource (ab->tmem_head);
362 }
363 if (ab->mem_head) {
364 dbg(" MEM Resources:\n");
365 print_pci_resource (ab->mem_head);
366 }
367
368 if (ab->tp_mem_head) {
369 dbg(" Total PMEM Resources:\n");
370 print_pci_resource (ab->tp_mem_head);
371 }
372 if (ab->p_mem_head) {
373 dbg(" PMEM Resources:\n");
374 print_pci_resource (ab->p_mem_head);
375 }
376 if (ab->_hpp) {
377 dbg(" _HPP: cache_line_size=0x%x\n", ab->_hpp->cache_line_size);
378 dbg(" _HPP: latency timer =0x%x\n", ab->_hpp->latency_timer);
379 dbg(" _HPP: enable SERR =0x%x\n", ab->_hpp->enable_serr);
380 dbg(" _HPP: enable PERR =0x%x\n", ab->_hpp->enable_perr);
381 }
382}
383
384static int shpchprm_delete_resource(
385 struct pci_resource **aprh,
386 ulong base,
387 ulong size)
388{
389 struct pci_resource *res;
390 struct pci_resource *prevnode;
391 struct pci_resource *split_node;
392 ulong tbase;
393
394 shpchp_resource_sort_and_combine(aprh);
395
396 for (res = *aprh; res; res = res->next) {
397 if (res->base > base)
398 continue;
399
400 if ((res->base + res->length) < (base + size))
401 continue;
402
403 if (res->base < base) {
404 tbase = base;
405
406 if ((res->length - (tbase - res->base)) < size)
407 continue;
408
409 split_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
410 if (!split_node)
411 return -ENOMEM;
412
413 split_node->base = res->base;
414 split_node->length = tbase - res->base;
415 res->base = tbase;
416 res->length -= split_node->length;
417
418 split_node->next = res->next;
419 res->next = split_node;
420 }
421
422 if (res->length >= size) {
423 split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
424 if (!split_node)
425 return -ENOMEM;
426
427 split_node->base = res->base + size;
428 split_node->length = res->length - size;
429 res->length = size;
430
431 split_node->next = res->next;
432 res->next = split_node;
433 }
434
435 if (*aprh == res) {
436 *aprh = res->next;
437 } else {
438 prevnode = *aprh;
439 while (prevnode->next != res)
440 prevnode = prevnode->next;
441
442 prevnode->next = res->next;
443 }
444 res->next = NULL;
445 kfree(res);
446 break;
447 }
448
449 return 0;
450}
451
452static int shpchprm_delete_resources(
453 struct pci_resource **aprh,
454 struct pci_resource *this
455 )
456{
457 struct pci_resource *res;
458
459 for (res = this; res; res = res->next)
460 shpchprm_delete_resource(aprh, res->base, res->length);
461
462 return 0;
463}
464
465static int shpchprm_add_resource(
466 struct pci_resource **aprh,
467 ulong base,
468 ulong size)
469{
470 struct pci_resource *res;
471
472 for (res = *aprh; res; res = res->next) {
473 if ((res->base + res->length) == base) {
474 res->length += size;
475 size = 0L;
476 break;
477 }
478 if (res->next == *aprh)
479 break;
480 }
481
482 if (size) {
483 res = kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
484 if (!res) {
485 err ("acpi_shpchprm: alloc for res fail\n");
486 return -ENOMEM;
487 }
488 memset(res, 0, sizeof (struct pci_resource));
489
490 res->base = base;
491 res->length = size;
492 res->next = *aprh;
493 *aprh = res;
494 }
495
496 return 0;
497}
498
499static int shpchprm_add_resources(
500 struct pci_resource **aprh,
501 struct pci_resource *this
502 )
503{
504 struct pci_resource *res;
505 int rc = 0;
506
507 for (res = this; res && !rc; res = res->next)
508 rc = shpchprm_add_resource(aprh, res->base, res->length);
509
510 return rc;
511}
512
513static void acpi_parse_io (
514 struct acpi_bridge *ab,
515 union acpi_resource_data *data
516 )
517{
518 struct acpi_resource_io *dataio;
519 dataio = (struct acpi_resource_io *) data;
520
521 dbg("Io Resource\n");
522 dbg(" %d bit decode\n", ACPI_DECODE_16 == dataio->io_decode ? 16:10);
523 dbg(" Range minimum base: %08X\n", dataio->min_base_address);
524 dbg(" Range maximum base: %08X\n", dataio->max_base_address);
525 dbg(" Alignment: %08X\n", dataio->alignment);
526 dbg(" Range Length: %08X\n", dataio->range_length);
527}
528
529static void acpi_parse_fixed_io (
530 struct acpi_bridge *ab,
531 union acpi_resource_data *data
532 )
533{
534 struct acpi_resource_fixed_io *datafio;
535 datafio = (struct acpi_resource_fixed_io *) data;
536
537 dbg("Fixed Io Resource\n");
538 dbg(" Range base address: %08X", datafio->base_address);
539 dbg(" Range length: %08X", datafio->range_length);
540}
541
542static void acpi_parse_address16_32 (
543 struct acpi_bridge *ab,
544 union acpi_resource_data *data,
545 acpi_resource_type id
546 )
547{
548 /*
549 * acpi_resource_address16 == acpi_resource_address32
550 * acpi_resource_address16 *data16 = (acpi_resource_address16 *) data;
551 */
552 struct acpi_resource_address32 *data32 = (struct acpi_resource_address32 *) data;
553 struct pci_resource **aprh, **tprh;
554
555 if (id == ACPI_RSTYPE_ADDRESS16)
556 dbg("acpi_shpchprm:16-Bit Address Space Resource\n");
557 else
558 dbg("acpi_shpchprm:32-Bit Address Space Resource\n");
559
560 switch (data32->resource_type) {
561 case ACPI_MEMORY_RANGE:
562 dbg(" Resource Type: Memory Range\n");
563 aprh = &ab->mem_head;
564 tprh = &ab->tmem_head;
565
566 switch (data32->attribute.memory.cache_attribute) {
567 case ACPI_NON_CACHEABLE_MEMORY:
568 dbg(" Type Specific: Noncacheable memory\n");
569 break;
570 case ACPI_CACHABLE_MEMORY:
571 dbg(" Type Specific: Cacheable memory\n");
572 break;
573 case ACPI_WRITE_COMBINING_MEMORY:
574 dbg(" Type Specific: Write-combining memory\n");
575 break;
576 case ACPI_PREFETCHABLE_MEMORY:
577 aprh = &ab->p_mem_head;
578 dbg(" Type Specific: Prefetchable memory\n");
579 break;
580 default:
581 dbg(" Type Specific: Invalid cache attribute\n");
582 break;
583 }
584
585 dbg(" Type Specific: Read%s\n", ACPI_READ_WRITE_MEMORY == data32->attribute.memory.read_write_attribute ? "/Write":" Only");
586 break;
587
588 case ACPI_IO_RANGE:
589 dbg(" Resource Type: I/O Range\n");
590 aprh = &ab->io_head;
591 tprh = &ab->tio_head;
592
593 switch (data32->attribute.io.range_attribute) {
594 case ACPI_NON_ISA_ONLY_RANGES:
595 dbg(" Type Specific: Non-ISA Io Addresses\n");
596 break;
597 case ACPI_ISA_ONLY_RANGES:
598 dbg(" Type Specific: ISA Io Addresses\n");
599 break;
600 case ACPI_ENTIRE_RANGE:
601 dbg(" Type Specific: ISA and non-ISA Io Addresses\n");
602 break;
603 default:
604 dbg(" Type Specific: Invalid range attribute\n");
605 break;
606 }
607 break;
608
609 case ACPI_BUS_NUMBER_RANGE:
610 dbg(" Resource Type: Bus Number Range(fixed)\n");
611 /* fixup to be compatible with the rest of php driver */
612 data32->min_address_range++;
613 data32->address_length--;
614 aprh = &ab->bus_head;
615 tprh = &ab->tbus_head;
616 break;
617 default:
618 dbg(" Resource Type: Invalid resource type. Exiting.\n");
619 return;
620 }
621
622 dbg(" Resource %s\n", ACPI_CONSUMER == data32->producer_consumer ? "Consumer":"Producer");
623 dbg(" %s decode\n", ACPI_SUB_DECODE == data32->decode ? "Subtractive":"Positive");
624 dbg(" Min address is %s fixed\n", ACPI_ADDRESS_FIXED == data32->min_address_fixed ? "":"not");
625 dbg(" Max address is %s fixed\n", ACPI_ADDRESS_FIXED == data32->max_address_fixed ? "":"not");
626 dbg(" Granularity: %08X\n", data32->granularity);
627 dbg(" Address range min: %08X\n", data32->min_address_range);
628 dbg(" Address range max: %08X\n", data32->max_address_range);
629 dbg(" Address translation offset: %08X\n", data32->address_translation_offset);
630 dbg(" Address Length: %08X\n", data32->address_length);
631
632 if (0xFF != data32->resource_source.index) {
633 dbg(" Resource Source Index: %X\n", data32->resource_source.index);
634 /* dbg(" Resource Source: %s\n", data32->resource_source.string_ptr); */
635 }
636
637 shpchprm_add_resource(aprh, data32->min_address_range, data32->address_length);
638}
639
640static acpi_status acpi_parse_crs(
641 struct acpi_bridge *ab,
642 struct acpi_resource *crsbuf
643 )
644{
645 acpi_status status = AE_OK;
646 struct acpi_resource *resource = crsbuf;
647 u8 count = 0;
648 u8 done = 0;
649
650 while (!done) {
651 dbg("acpi_shpchprm: PCI bus 0x%x Resource structure %x.\n", ab->bus, count++);
652 switch (resource->id) {
653 case ACPI_RSTYPE_IRQ:
654 dbg("Irq -------- Resource\n");
655 break;
656 case ACPI_RSTYPE_DMA:
657 dbg("DMA -------- Resource\n");
658 break;
659 case ACPI_RSTYPE_START_DPF:
660 dbg("Start DPF -------- Resource\n");
661 break;
662 case ACPI_RSTYPE_END_DPF:
663 dbg("End DPF -------- Resource\n");
664 break;
665 case ACPI_RSTYPE_IO:
666 acpi_parse_io (ab, &resource->data);
667 break;
668 case ACPI_RSTYPE_FIXED_IO:
669 acpi_parse_fixed_io (ab, &resource->data);
670 break;
671 case ACPI_RSTYPE_VENDOR:
672 dbg("Vendor -------- Resource\n");
673 break;
674 case ACPI_RSTYPE_END_TAG:
675 dbg("End_tag -------- Resource\n");
676 done = 1;
677 break;
678 case ACPI_RSTYPE_MEM24:
679 dbg("Mem24 -------- Resource\n");
680 break;
681 case ACPI_RSTYPE_MEM32:
682 dbg("Mem32 -------- Resource\n");
683 break;
684 case ACPI_RSTYPE_FIXED_MEM32:
685 dbg("Fixed Mem32 -------- Resource\n");
686 break;
687 case ACPI_RSTYPE_ADDRESS16:
688 acpi_parse_address16_32(ab, &resource->data, ACPI_RSTYPE_ADDRESS16);
689 break;
690 case ACPI_RSTYPE_ADDRESS32:
691 acpi_parse_address16_32(ab, &resource->data, ACPI_RSTYPE_ADDRESS32);
692 break;
693 case ACPI_RSTYPE_ADDRESS64:
694 info("Address64 -------- Resource unparsed\n");
695 break;
696 case ACPI_RSTYPE_EXT_IRQ:
697 dbg("Ext Irq -------- Resource\n");
698 break;
699 default:
700 dbg("Invalid -------- resource type 0x%x\n", resource->id);
701 break;
702 }
703
704 resource = (struct acpi_resource *) ((char *)resource + resource->length);
705 }
706
707 return status; 123 return status;
708} 124}
709 125
710static acpi_status acpi_get_crs( struct acpi_bridge *ab) 126static void acpi_run_oshp(acpi_handle handle)
711{ 127{
712 acpi_status status; 128 acpi_status status;
713 struct acpi_resource *crsbuf;
714
715 status = acpi_evaluate_crs(ab->handle, &crsbuf);
716 if (ACPI_SUCCESS(status)) {
717 status = acpi_parse_crs(ab, crsbuf);
718 kfree(crsbuf);
719
720 shpchp_resource_sort_and_combine(&ab->bus_head);
721 shpchp_resource_sort_and_combine(&ab->io_head);
722 shpchp_resource_sort_and_combine(&ab->mem_head);
723 shpchp_resource_sort_and_combine(&ab->p_mem_head);
724
725 shpchprm_add_resources (&ab->tbus_head, ab->bus_head);
726 shpchprm_add_resources (&ab->tio_head, ab->io_head);
727 shpchprm_add_resources (&ab->tmem_head, ab->mem_head);
728 shpchprm_add_resources (&ab->tp_mem_head, ab->p_mem_head);
729 }
730
731 return status;
732}
733
734/* find acpi_bridge downword from ab. */
735static struct acpi_bridge *
736find_acpi_bridge_by_bus(
737 struct acpi_bridge *ab,
738 int seg,
739 int bus /* pdev->subordinate->number */
740 )
741{
742 struct acpi_bridge *lab = NULL;
743
744 if (!ab)
745 return NULL;
746
747 if ((ab->bus == bus) && (ab->seg == seg))
748 return ab;
749
750 if (ab->child)
751 lab = find_acpi_bridge_by_bus(ab->child, seg, bus);
752
753 if (!lab)
754 if (ab->next)
755 lab = find_acpi_bridge_by_bus(ab->next, seg, bus);
756
757 return lab;
758}
759
760/*
761 * Build a device tree of ACPI PCI Bridges
762 */
763static void shpchprm_acpi_register_a_bridge (
764 struct acpi_bridge **head,
765 struct acpi_bridge *pab, /* parent bridge to which child bridge is added */
766 struct acpi_bridge *cab /* child bridge to add */
767 )
768{
769 struct acpi_bridge *lpab;
770 struct acpi_bridge *lcab;
771
772 lpab = find_acpi_bridge_by_bus(*head, pab->seg, pab->bus);
773 if (!lpab) {
774 if (!(pab->type & BRIDGE_TYPE_HOST))
775 warn("PCI parent bridge s:b(%x:%x) not in list.\n", pab->seg, pab->bus);
776 pab->next = *head;
777 *head = pab;
778 lpab = pab;
779 }
780
781 if ((cab->type & BRIDGE_TYPE_HOST) && (pab == cab))
782 return;
783
784 lcab = find_acpi_bridge_by_bus(*head, cab->seg, cab->bus);
785 if (lcab) {
786 if ((pab->bus != lcab->parent->bus) || (lcab->bus != cab->bus))
787 err("PCI child bridge s:b(%x:%x) in list with diff parent.\n", cab->seg, cab->bus);
788 return;
789 } else
790 lcab = cab;
791
792 lcab->parent = lpab;
793 lcab->next = lpab->child;
794 lpab->child = lcab;
795}
796
797static acpi_status shpchprm_acpi_build_php_slots_callback(
798 acpi_handle handle,
799 u32 Level,
800 void *context,
801 void **retval
802 )
803{
804 ulong bus_num;
805 ulong seg_num;
806 ulong sun, adr;
807 ulong padr = 0;
808 acpi_handle phandle = NULL;
809 struct acpi_bridge *pab = (struct acpi_bridge *)context;
810 struct acpi_bridge *lab;
811 acpi_status status;
812 u8 *path_name = acpi_path_name(handle); 129 u8 *path_name = acpi_path_name(handle);
813 130
814 /* get _SUN */ 131 /* run OSHP */
815 status = acpi_evaluate_integer(handle, METHOD_NAME__SUN, NULL, &sun); 132 status = acpi_evaluate_object(handle, METHOD_NAME_OSHP, NULL, NULL);
816 switch(status) {
817 case AE_NOT_FOUND:
818 return AE_OK;
819 default:
820 if (ACPI_FAILURE(status)) {
821 err("acpi_shpchprm:%s _SUN fail=0x%x\n", path_name, status);
822 return status;
823 }
824 }
825
826 /* get _ADR. _ADR must exist if _SUN exists */
827 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &adr);
828 if (ACPI_FAILURE(status)) {
829 err("acpi_shpchprm:%s _ADR fail=0x%x\n", path_name, status);
830 return status;
831 }
832
833 dbg("acpi_shpchprm:%s sun=0x%08x adr=0x%08x\n", path_name, (u32)sun, (u32)adr);
834
835 status = acpi_get_parent(handle, &phandle);
836 if (ACPI_FAILURE(status)) { 133 if (ACPI_FAILURE(status)) {
837 err("acpi_shpchprm:%s get_parent fail=0x%x\n", path_name, status); 134 err("%s:%s OSHP fails=0x%x\n", __FUNCTION__, path_name,
838 return (status); 135 status);
839 }
840
841 bus_num = pab->bus;
842 seg_num = pab->seg;
843
844 if (pab->bus == bus_num) {
845 lab = pab;
846 } else { 136 } else {
847 dbg("WARN: pab is not parent\n"); 137 dbg("%s:%s OSHP passes\n", __FUNCTION__, path_name);
848 lab = find_acpi_bridge_by_bus(pab, seg_num, bus_num);
849 if (!lab) {
850 dbg("acpi_shpchprm: alloc new P2P bridge(%x) for sun(%08x)\n", (u32)bus_num, (u32)sun);
851 lab = (struct acpi_bridge *)kmalloc(sizeof(struct acpi_bridge), GFP_KERNEL);
852 if (!lab) {
853 err("acpi_shpchprm: alloc for ab fail\n");
854 return AE_NO_MEMORY;
855 }
856 memset(lab, 0, sizeof(struct acpi_bridge));
857
858 lab->handle = phandle;
859 lab->pbus = pab->bus;
860 lab->pdevice = (int)(padr >> 16) & 0xffff;
861 lab->pfunction = (int)(padr & 0xffff);
862 lab->bus = (int)bus_num;
863 lab->scanned = 0;
864 lab->type = BRIDGE_TYPE_P2P;
865
866 shpchprm_acpi_register_a_bridge (&acpi_bridges_head, pab, lab);
867 } else
868 dbg("acpi_shpchprm: found P2P bridge(%x) for sun(%08x)\n", (u32)bus_num, (u32)sun);
869 } 138 }
870
871 acpi_add_slot_to_php_slots(lab, (int)bus_num, handle, (u32)adr, (u32)sun);
872 return (status);
873}
874
875static int shpchprm_acpi_build_php_slots(
876 struct acpi_bridge *ab,
877 u32 depth
878 )
879{
880 acpi_status status;
881 u8 *path_name = acpi_path_name(ab->handle);
882
883 /* Walk down this pci bridge to get _SUNs if any behind P2P */
884 status = acpi_walk_namespace ( ACPI_TYPE_DEVICE,
885 ab->handle,
886 depth,
887 shpchprm_acpi_build_php_slots_callback,
888 ab,
889 NULL );
890 if (ACPI_FAILURE(status)) {
891 dbg("acpi_shpchprm:%s walk for _SUN on pci bridge seg:bus(%x:%x) fail=0x%x\n", path_name, ab->seg, ab->bus, status);
892 return -1;
893 }
894
895 return 0;
896}
897
898static void build_a_bridge(
899 struct acpi_bridge *pab,
900 struct acpi_bridge *ab
901 )
902{
903 u8 *path_name = acpi_path_name(ab->handle);
904
905 shpchprm_acpi_register_a_bridge (&acpi_bridges_head, pab, ab);
906
907 switch (ab->type) {
908 case BRIDGE_TYPE_HOST:
909 dbg("acpi_shpchprm: Registered PCI HOST Bridge(%02x) on s:b:d:f(%02x:%02x:%02x:%02x) [%s]\n",
910 ab->bus, ab->seg, ab->pbus, ab->pdevice, ab->pfunction, path_name);
911 break;
912 case BRIDGE_TYPE_P2P:
913 dbg("acpi_shpchprm: Registered PCI P2P Bridge(%02x-%02x) on s:b:d:f(%02x:%02x:%02x:%02x) [%s]\n",
914 ab->pbus, ab->bus, ab->seg, ab->pbus, ab->pdevice, ab->pfunction, path_name);
915 break;
916 };
917
918 /* build any immediate PHP slots under this pci bridge */
919 shpchprm_acpi_build_php_slots(ab, 1);
920}
921
922static struct acpi_bridge * add_p2p_bridge(
923 acpi_handle handle,
924 struct acpi_bridge *pab, /* parent */
925 ulong adr
926 )
927{
928 struct acpi_bridge *ab;
929 struct pci_dev *pdev;
930 ulong devnum, funcnum;
931 u8 *path_name = acpi_path_name(handle);
932
933 ab = (struct acpi_bridge *) kmalloc (sizeof(struct acpi_bridge), GFP_KERNEL);
934 if (!ab) {
935 err("acpi_shpchprm: alloc for ab fail\n");
936 return NULL;
937 }
938 memset(ab, 0, sizeof(struct acpi_bridge));
939
940 devnum = (adr >> 16) & 0xffff;
941 funcnum = adr & 0xffff;
942
943 pdev = pci_find_slot(pab->bus, PCI_DEVFN(devnum, funcnum));
944 if (!pdev || !pdev->subordinate) {
945 err("acpi_shpchprm:%s is not a P2P Bridge\n", path_name);
946 kfree(ab);
947 return NULL;
948 }
949
950 ab->handle = handle;
951 ab->seg = pab->seg;
952 ab->pbus = pab->bus; /* or pdev->bus->number */
953 ab->pdevice = devnum; /* or PCI_SLOT(pdev->devfn) */
954 ab->pfunction = funcnum; /* or PCI_FUNC(pdev->devfn) */
955 ab->bus = pdev->subordinate->number;
956 ab->scanned = 0;
957 ab->type = BRIDGE_TYPE_P2P;
958
959 dbg("acpi_shpchprm: P2P(%x-%x) on pci=b:d:f(%x:%x:%x) acpi=b:d:f(%x:%x:%x) [%s]\n",
960 pab->bus, ab->bus, pdev->bus->number, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
961 pab->bus, (u32)devnum, (u32)funcnum, path_name);
962
963 build_a_bridge(pab, ab);
964
965 return ab;
966}
967
968static acpi_status scan_p2p_bridge(
969 acpi_handle handle,
970 u32 Level,
971 void *context,
972 void **retval
973 )
974{
975 struct acpi_bridge *pab = (struct acpi_bridge *)context;
976 struct acpi_bridge *ab;
977 acpi_status status;
978 ulong adr = 0;
979 u8 *path_name = acpi_path_name(handle);
980 ulong devnum, funcnum;
981 struct pci_dev *pdev;
982
983 /* get device, function */
984 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &adr);
985 if (ACPI_FAILURE(status)) {
986 if (status != AE_NOT_FOUND)
987 err("acpi_shpchprm:%s _ADR fail=0x%x\n", path_name, status);
988 return AE_OK;
989 }
990
991 devnum = (adr >> 16) & 0xffff;
992 funcnum = adr & 0xffff;
993
994 pdev = pci_find_slot(pab->bus, PCI_DEVFN(devnum, funcnum));
995 if (!pdev)
996 return AE_OK;
997 if (!pdev->subordinate)
998 return AE_OK;
999
1000 ab = add_p2p_bridge(handle, pab, adr);
1001 if (ab) {
1002 status = acpi_walk_namespace ( ACPI_TYPE_DEVICE,
1003 handle,
1004 (u32)1,
1005 scan_p2p_bridge,
1006 ab,
1007 NULL);
1008 if (ACPI_FAILURE(status))
1009 dbg("acpi_shpchprm:%s find_p2p fail=0x%x\n", path_name, status);
1010 }
1011
1012 return AE_OK;
1013}
1014
1015static struct acpi_bridge * add_host_bridge(
1016 acpi_handle handle,
1017 ulong segnum,
1018 ulong busnum
1019 )
1020{
1021 ulong adr = 0;
1022 acpi_status status;
1023 struct acpi_bridge *ab;
1024 u8 *path_name = acpi_path_name(handle);
1025
1026 /* get device, function: host br adr is always 0000 though. */
1027 status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &adr);
1028 if (ACPI_FAILURE(status)) {
1029 err("acpi_shpchprm:%s _ADR fail=0x%x\n", path_name, status);
1030 return NULL;
1031 }
1032 dbg("acpi_shpchprm: ROOT PCI seg(0x%x)bus(0x%x)dev(0x%x)func(0x%x) [%s]\n", (u32)segnum, (u32)busnum,
1033 (u32)(adr >> 16) & 0xffff, (u32)adr & 0xffff, path_name);
1034
1035 ab = (struct acpi_bridge *) kmalloc (sizeof(struct acpi_bridge), GFP_KERNEL);
1036 if (!ab) {
1037 err("acpi_shpchprm: alloc for ab fail\n");
1038 return NULL;
1039 }
1040 memset(ab, 0, sizeof(struct acpi_bridge));
1041
1042 ab->handle = handle;
1043 ab->seg = (int)segnum;
1044 ab->bus = ab->pbus = (int)busnum;
1045 ab->pdevice = (int)(adr >> 16) & 0xffff;
1046 ab->pfunction = (int)(adr & 0xffff);
1047 ab->scanned = 0;
1048 ab->type = BRIDGE_TYPE_HOST;
1049
1050 /* get root pci bridge's current resources */
1051 status = acpi_get_crs(ab);
1052 if (ACPI_FAILURE(status)) {
1053 err("acpi_shpchprm:%s evaluate _CRS fail=0x%x\n", path_name, status);
1054 kfree(ab);
1055 return NULL;
1056 }
1057 build_a_bridge(ab, ab);
1058
1059 return ab;
1060}
1061
1062static acpi_status acpi_scan_from_root_pci_callback (
1063 acpi_handle handle,
1064 u32 Level,
1065 void *context,
1066 void **retval
1067 )
1068{
1069 ulong segnum = 0;
1070 ulong busnum = 0;
1071 acpi_status status;
1072 struct acpi_bridge *ab;
1073 u8 *path_name = acpi_path_name(handle);
1074
1075 /* get bus number of this pci root bridge */
1076 status = acpi_evaluate_integer(handle, METHOD_NAME__SEG, NULL, &segnum);
1077 if (ACPI_FAILURE(status)) {
1078 if (status != AE_NOT_FOUND) {
1079 err("acpi_shpchprm:%s evaluate _SEG fail=0x%x\n", path_name, status);
1080 return status;
1081 }
1082 segnum = 0;
1083 }
1084
1085 /* get bus number of this pci root bridge */
1086 status = acpi_evaluate_integer(handle, METHOD_NAME__BBN, NULL, &busnum);
1087 if (ACPI_FAILURE(status)) {
1088 err("acpi_shpchprm:%s evaluate _BBN fail=0x%x\n", path_name, status);
1089 return (status);
1090 }
1091
1092 ab = add_host_bridge(handle, segnum, busnum);
1093 if (ab) {
1094 status = acpi_walk_namespace ( ACPI_TYPE_DEVICE,
1095 handle,
1096 1,
1097 scan_p2p_bridge,
1098 ab,
1099 NULL);
1100 if (ACPI_FAILURE(status))
1101 dbg("acpi_shpchprm:%s find_p2p fail=0x%x\n", path_name, status);
1102 }
1103
1104 return AE_OK;
1105}
1106
1107static int shpchprm_acpi_scan_pci (void)
1108{
1109 acpi_status status;
1110
1111 /*
1112 * TBD: traverse LDM device tree with the help of
1113 * unified ACPI augmented for php device population.
1114 */
1115 status = acpi_get_devices ( PCI_ROOT_HID_STRING,
1116 acpi_scan_from_root_pci_callback,
1117 NULL,
1118 NULL );
1119 if (ACPI_FAILURE(status)) {
1120 err("acpi_shpchprm:get_device PCI ROOT HID fail=0x%x\n", status);
1121 return -1;
1122 }
1123
1124 return 0;
1125}
1126
1127int shpchprm_init(enum php_ctlr_type ctlr_type)
1128{
1129 int rc;
1130
1131 if (ctlr_type != PCI)
1132 return -ENODEV;
1133
1134 dbg("shpchprm ACPI init <enter>\n");
1135 acpi_bridges_head = NULL;
1136
1137 /* construct PCI bus:device tree of acpi_handles */
1138 rc = shpchprm_acpi_scan_pci();
1139 if (rc)
1140 return rc;
1141
1142 dbg("shpchprm ACPI init %s\n", (rc)?"fail":"success");
1143 return rc;
1144}
1145
1146static void free_a_slot(struct acpi_php_slot *aps)
1147{
1148 dbg(" free a php func of slot(0x%02x) on PCI b:d:f=0x%02x:%02x:%02x\n", aps->sun, aps->bus, aps->dev, aps->fun);
1149
1150 free_pci_resource (aps->io_head);
1151 free_pci_resource (aps->bus_head);
1152 free_pci_resource (aps->mem_head);
1153 free_pci_resource (aps->p_mem_head);
1154
1155 kfree(aps);
1156}
1157
1158static void free_a_bridge( struct acpi_bridge *ab)
1159{
1160 struct acpi_php_slot *aps, *next;
1161
1162 switch (ab->type) {
1163 case BRIDGE_TYPE_HOST:
1164 dbg("Free ACPI PCI HOST Bridge(%x) [%s] on s:b:d:f(%x:%x:%x:%x)\n",
1165 ab->bus, acpi_path_name(ab->handle), ab->seg, ab->pbus, ab->pdevice, ab->pfunction);
1166 break;
1167 case BRIDGE_TYPE_P2P:
1168 dbg("Free ACPI PCI P2P Bridge(%x-%x) [%s] on s:b:d:f(%x:%x:%x:%x)\n",
1169 ab->pbus, ab->bus, acpi_path_name(ab->handle), ab->seg, ab->pbus, ab->pdevice, ab->pfunction);
1170 break;
1171 };
1172
1173 /* free slots first */
1174 for (aps = ab->slots; aps; aps = next) {
1175 next = aps->next;
1176 free_a_slot(aps);
1177 }
1178
1179 free_pci_resource (ab->io_head);
1180 free_pci_resource (ab->tio_head);
1181 free_pci_resource (ab->bus_head);
1182 free_pci_resource (ab->tbus_head);
1183 free_pci_resource (ab->mem_head);
1184 free_pci_resource (ab->tmem_head);
1185 free_pci_resource (ab->p_mem_head);
1186 free_pci_resource (ab->tp_mem_head);
1187
1188 kfree(ab);
1189}
1190
1191static void shpchprm_free_bridges ( struct acpi_bridge *ab)
1192{
1193 if (!ab)
1194 return;
1195
1196 if (ab->child)
1197 shpchprm_free_bridges (ab->child);
1198
1199 if (ab->next)
1200 shpchprm_free_bridges (ab->next);
1201
1202 free_a_bridge(ab);
1203}
1204
1205void shpchprm_cleanup(void)
1206{
1207 shpchprm_free_bridges (acpi_bridges_head);
1208}
1209
1210static int get_number_of_slots (
1211 struct acpi_bridge *ab,
1212 int selfonly
1213 )
1214{
1215 struct acpi_php_slot *aps;
1216 int prev_slot = -1;
1217 int slot_num = 0;
1218
1219 for ( aps = ab->slots; aps; aps = aps->next)
1220 if (aps->dev != prev_slot) {
1221 prev_slot = aps->dev;
1222 slot_num++;
1223 }
1224
1225 if (ab->child)
1226 slot_num += get_number_of_slots (ab->child, 0);
1227
1228 if (selfonly)
1229 return slot_num;
1230
1231 if (ab->next)
1232 slot_num += get_number_of_slots (ab->next, 0);
1233
1234 return slot_num;
1235}
1236
1237static int print_acpi_resources (struct acpi_bridge *ab)
1238{
1239 struct acpi_php_slot *aps;
1240 int i;
1241
1242 switch (ab->type) {
1243 case BRIDGE_TYPE_HOST:
1244 dbg("PCI HOST Bridge (%x) [%s]\n", ab->bus, acpi_path_name(ab->handle));
1245 break;
1246 case BRIDGE_TYPE_P2P:
1247 dbg("PCI P2P Bridge (%x-%x) [%s]\n", ab->pbus, ab->bus, acpi_path_name(ab->handle));
1248 break;
1249 };
1250
1251 print_pci_resources (ab);
1252
1253 for ( i = -1, aps = ab->slots; aps; aps = aps->next) {
1254 if (aps->dev == i)
1255 continue;
1256 dbg(" Slot sun(%x) s:b:d:f(%02x:%02x:%02x:%02x)\n", aps->sun, aps->seg, aps->bus, aps->dev, aps->fun);
1257 print_slot_resources(aps);
1258 i = aps->dev;
1259 }
1260
1261 if (ab->child)
1262 print_acpi_resources (ab->child);
1263
1264 if (ab->next)
1265 print_acpi_resources (ab->next);
1266
1267 return 0;
1268}
1269
1270int shpchprm_print_pirt(void)
1271{
1272 dbg("SHPCHPRM ACPI Slots\n");
1273 if (acpi_bridges_head)
1274 print_acpi_resources (acpi_bridges_head);
1275 return 0;
1276}
1277
1278static struct acpi_php_slot * get_acpi_slot (
1279 struct acpi_bridge *ab,
1280 u32 sun
1281 )
1282{
1283 struct acpi_php_slot *aps = NULL;
1284
1285 for ( aps = ab->slots; aps; aps = aps->next)
1286 if (aps->sun == sun)
1287 return aps;
1288
1289 if (!aps && ab->child) {
1290 aps = (struct acpi_php_slot *)get_acpi_slot (ab->child, sun);
1291 if (aps)
1292 return aps;
1293 }
1294
1295 if (!aps && ab->next) {
1296 aps = (struct acpi_php_slot *)get_acpi_slot (ab->next, sun);
1297 if (aps)
1298 return aps;
1299 }
1300
1301 return aps;
1302
1303}
1304
1305#if 0
1306static void * shpchprm_get_slot(struct slot *slot)
1307{
1308 struct acpi_bridge *ab = acpi_bridges_head;
1309 struct acpi_php_slot *aps = get_acpi_slot (ab, slot->number);
1310
1311 aps->slot = slot;
1312
1313 dbg("Got acpi slot sun(%x): s:b:d:f(%x:%x:%x:%x)\n", aps->sun, aps->seg, aps->bus, aps->dev, aps->fun);
1314
1315 return (void *)aps;
1316}
1317#endif
1318
1319static void shpchprm_dump_func_res( struct pci_func *fun)
1320{
1321 struct pci_func *func = fun;
1322
1323 if (func->bus_head) {
1324 dbg(": BUS Resources:\n");
1325 print_pci_resource (func->bus_head);
1326 }
1327 if (func->io_head) {
1328 dbg(": IO Resources:\n");
1329 print_pci_resource (func->io_head);
1330 }
1331 if (func->mem_head) {
1332 dbg(": MEM Resources:\n");
1333 print_pci_resource (func->mem_head);
1334 }
1335 if (func->p_mem_head) {
1336 dbg(": PMEM Resources:\n");
1337 print_pci_resource (func->p_mem_head);
1338 }
1339}
1340
1341static void shpchprm_dump_ctrl_res( struct controller *ctlr)
1342{
1343 struct controller *ctrl = ctlr;
1344
1345 if (ctrl->bus_head) {
1346 dbg(": BUS Resources:\n");
1347 print_pci_resource (ctrl->bus_head);
1348 }
1349 if (ctrl->io_head) {
1350 dbg(": IO Resources:\n");
1351 print_pci_resource (ctrl->io_head);
1352 }
1353 if (ctrl->mem_head) {
1354 dbg(": MEM Resources:\n");
1355 print_pci_resource (ctrl->mem_head);
1356 }
1357 if (ctrl->p_mem_head) {
1358 dbg(": PMEM Resources:\n");
1359 print_pci_resource (ctrl->p_mem_head);
1360 }
1361}
1362
1363static int shpchprm_get_used_resources (
1364 struct controller *ctrl,
1365 struct pci_func *func
1366 )
1367{
1368 return shpchp_save_used_resources (ctrl, func, !DISABLE_CARD);
1369}
1370
1371static int configure_existing_function(
1372 struct controller *ctrl,
1373 struct pci_func *func
1374 )
1375{
1376 int rc;
1377
1378 /* see how much resources the func has used. */
1379 rc = shpchprm_get_used_resources (ctrl, func);
1380
1381 if (!rc) {
1382 /* subtract the resources used by the func from ctrl resources */
1383 rc = shpchprm_delete_resources (&ctrl->bus_head, func->bus_head);
1384 rc |= shpchprm_delete_resources (&ctrl->io_head, func->io_head);
1385 rc |= shpchprm_delete_resources (&ctrl->mem_head, func->mem_head);
1386 rc |= shpchprm_delete_resources (&ctrl->p_mem_head, func->p_mem_head);
1387 if (rc)
1388 warn("aCEF: cannot del used resources\n");
1389 } else
1390 err("aCEF: cannot get used resources\n");
1391
1392 return rc;
1393}
1394
1395static int bind_pci_resources_to_slots ( struct controller *ctrl)
1396{
1397 struct pci_func *func, new_func;
1398 int busn = ctrl->slot_bus;
1399 int devn, funn;
1400 u32 vid;
1401
1402 for (devn = 0; devn < 32; devn++) {
1403 for (funn = 0; funn < 8; funn++) {
1404 /*
1405 if (devn == ctrl->device && funn == ctrl->function)
1406 continue;
1407 */
1408 /* find out if this entry is for an occupied slot */
1409 vid = 0xFFFFFFFF;
1410 pci_bus_read_config_dword(ctrl->pci_dev->subordinate, PCI_DEVFN(devn, funn), PCI_VENDOR_ID, &vid);
1411
1412 if (vid != 0xFFFFFFFF) {
1413 func = shpchp_slot_find(busn, devn, funn);
1414 if (!func) {
1415 memset(&new_func, 0, sizeof(struct pci_func));
1416 new_func.bus = busn;
1417 new_func.device = devn;
1418 new_func.function = funn;
1419 new_func.is_a_board = 1;
1420 configure_existing_function(ctrl, &new_func);
1421 shpchprm_dump_func_res(&new_func);
1422 } else {
1423 configure_existing_function(ctrl, func);
1424 shpchprm_dump_func_res(func);
1425 }
1426 dbg("aCCF:existing PCI 0x%x Func ResourceDump\n", ctrl->bus);
1427 }
1428 }
1429 }
1430
1431 return 0;
1432}
1433
1434static int bind_pci_resources(
1435 struct controller *ctrl,
1436 struct acpi_bridge *ab
1437 )
1438{
1439 int status = 0;
1440
1441 if (ab->bus_head) {
1442 dbg("bapr: BUS Resources add on PCI 0x%x\n", ab->bus);
1443 status = shpchprm_add_resources (&ctrl->bus_head, ab->bus_head);
1444 if (shpchprm_delete_resources (&ab->bus_head, ctrl->bus_head))
1445 warn("bapr: cannot sub BUS Resource on PCI 0x%x\n", ab->bus);
1446 if (status) {
1447 err("bapr: BUS Resource add on PCI 0x%x: fail=0x%x\n", ab->bus, status);
1448 return status;
1449 }
1450 } else
1451 info("bapr: No BUS Resource on PCI 0x%x.\n", ab->bus);
1452
1453 if (ab->io_head) {
1454 dbg("bapr: IO Resources add on PCI 0x%x\n", ab->bus);
1455 status = shpchprm_add_resources (&ctrl->io_head, ab->io_head);
1456 if (shpchprm_delete_resources (&ab->io_head, ctrl->io_head))
1457 warn("bapr: cannot sub IO Resource on PCI 0x%x\n", ab->bus);
1458 if (status) {
1459 err("bapr: IO Resource add on PCI 0x%x: fail=0x%x\n", ab->bus, status);
1460 return status;
1461 }
1462 } else
1463 info("bapr: No IO Resource on PCI 0x%x.\n", ab->bus);
1464
1465 if (ab->mem_head) {
1466 dbg("bapr: MEM Resources add on PCI 0x%x\n", ab->bus);
1467 status = shpchprm_add_resources (&ctrl->mem_head, ab->mem_head);
1468 if (shpchprm_delete_resources (&ab->mem_head, ctrl->mem_head))
1469 warn("bapr: cannot sub MEM Resource on PCI 0x%x\n", ab->bus);
1470 if (status) {
1471 err("bapr: MEM Resource add on PCI 0x%x: fail=0x%x\n", ab->bus, status);
1472 return status;
1473 }
1474 } else
1475 info("bapr: No MEM Resource on PCI 0x%x.\n", ab->bus);
1476
1477 if (ab->p_mem_head) {
1478 dbg("bapr: PMEM Resources add on PCI 0x%x\n", ab->bus);
1479 status = shpchprm_add_resources (&ctrl->p_mem_head, ab->p_mem_head);
1480 if (shpchprm_delete_resources (&ab->p_mem_head, ctrl->p_mem_head))
1481 warn("bapr: cannot sub PMEM Resource on PCI 0x%x\n", ab->bus);
1482 if (status) {
1483 err("bapr: PMEM Resource add on PCI 0x%x: fail=0x%x\n", ab->bus, status);
1484 return status;
1485 }
1486 } else
1487 info("bapr: No PMEM Resource on PCI 0x%x.\n", ab->bus);
1488
1489 return status;
1490}
1491
1492static int no_pci_resources( struct acpi_bridge *ab)
1493{
1494 return !(ab->p_mem_head || ab->mem_head || ab->io_head || ab->bus_head);
1495}
1496
1497static int find_pci_bridge_resources (
1498 struct controller *ctrl,
1499 struct acpi_bridge *ab
1500 )
1501{
1502 int rc = 0;
1503 struct pci_func func;
1504
1505 memset(&func, 0, sizeof(struct pci_func));
1506
1507 func.bus = ab->pbus;
1508 func.device = ab->pdevice;
1509 func.function = ab->pfunction;
1510 func.is_a_board = 1;
1511
1512 /* Get used resources for this PCI bridge */
1513 rc = shpchp_save_used_resources (ctrl, &func, !DISABLE_CARD);
1514
1515 ab->io_head = func.io_head;
1516 ab->mem_head = func.mem_head;
1517 ab->p_mem_head = func.p_mem_head;
1518 ab->bus_head = func.bus_head;
1519 if (ab->bus_head)
1520 shpchprm_delete_resource(&ab->bus_head, ctrl->bus, 1);
1521
1522 return rc;
1523}
1524
1525static int get_pci_resources_from_bridge(
1526 struct controller *ctrl,
1527 struct acpi_bridge *ab
1528 )
1529{
1530 int rc = 0;
1531
1532 dbg("grfb: Get Resources for PCI 0x%x from actual PCI bridge 0x%x.\n", ctrl->bus, ab->bus);
1533
1534 rc = find_pci_bridge_resources (ctrl, ab);
1535
1536 shpchp_resource_sort_and_combine(&ab->bus_head);
1537 shpchp_resource_sort_and_combine(&ab->io_head);
1538 shpchp_resource_sort_and_combine(&ab->mem_head);
1539 shpchp_resource_sort_and_combine(&ab->p_mem_head);
1540
1541 shpchprm_add_resources (&ab->tbus_head, ab->bus_head);
1542 shpchprm_add_resources (&ab->tio_head, ab->io_head);
1543 shpchprm_add_resources (&ab->tmem_head, ab->mem_head);
1544 shpchprm_add_resources (&ab->tp_mem_head, ab->p_mem_head);
1545
1546 return rc;
1547}
1548
1549static int get_pci_resources(
1550 struct controller *ctrl,
1551 struct acpi_bridge *ab
1552 )
1553{
1554 int rc = 0;
1555
1556 if (no_pci_resources(ab)) {
1557 dbg("spbr:PCI 0x%x has no resources. Get parent resources.\n", ab->bus);
1558 rc = get_pci_resources_from_bridge(ctrl, ab);
1559 }
1560
1561 return rc;
1562} 139}
1563 140
1564int shpchprm_get_physical_slot_number(struct controller *ctrl, u32 *sun, u8 busnum, u8 devnum) 141int shpchprm_get_physical_slot_number(struct controller *ctrl, u32 *sun, u8 busnum, u8 devnum)
@@ -1570,144 +147,40 @@ int shpchprm_get_physical_slot_number(struct controller *ctrl, u32 *sun, u8 busn
1570 return 0; 147 return 0;
1571} 148}
1572 149
1573/* 150void get_hp_hw_control_from_firmware(struct pci_dev *dev)
1574 * Get resources for this ctrl.
1575 * 1. get total resources from ACPI _CRS or bridge (this ctrl)
1576 * 2. find used resources of existing adapters
1577 * 3. subtract used resources from total resources
1578 */
1579int shpchprm_find_available_resources( struct controller *ctrl)
1580{ 151{
1581 int rc = 0; 152 /*
1582 struct acpi_bridge *ab; 153 * OSHP is an optional ACPI firmware control method. If present,
1583 154 * we need to run it to inform BIOS that we will control SHPC
1584 ab = find_acpi_bridge_by_bus(acpi_bridges_head, ctrl->seg, ctrl->pci_dev->subordinate->number); 155 * hardware from now on.
1585 if (!ab) { 156 */
1586 err("pfar:cannot locate acpi bridge of PCI 0x%x.\n", ctrl->pci_dev->subordinate->number); 157 acpi_handle handle = DEVICE_ACPI_HANDLE(&(dev->dev));
1587 return -1; 158 if (!handle)
1588 } 159 return;
1589 if (no_pci_resources(ab)) { 160 acpi_run_oshp(handle);
1590 rc = get_pci_resources(ctrl, ab);
1591 if (rc) {
1592 err("pfar:cannot get pci resources of PCI 0x%x.\n",ctrl->pci_dev->subordinate->number);
1593 return -1;
1594 }
1595 }
1596
1597 rc = bind_pci_resources(ctrl, ab);
1598 dbg("pfar:pre-Bind PCI 0x%x Ctrl Resource Dump\n", ctrl->pci_dev->subordinate->number);
1599 shpchprm_dump_ctrl_res(ctrl);
1600
1601 bind_pci_resources_to_slots (ctrl);
1602
1603 dbg("pfar:post-Bind PCI 0x%x Ctrl Resource Dump\n", ctrl->pci_dev->subordinate->number);
1604 shpchprm_dump_ctrl_res(ctrl);
1605
1606 return rc;
1607}
1608
1609int shpchprm_set_hpp(
1610 struct controller *ctrl,
1611 struct pci_func *func,
1612 u8 card_type
1613 )
1614{
1615 struct acpi_bridge *ab;
1616 struct pci_bus lpci_bus, *pci_bus;
1617 int rc = 0;
1618 unsigned int devfn;
1619 u8 cls= 0x08; /* default cache line size */
1620 u8 lt = 0x40; /* default latency timer */
1621 u8 ep = 0;
1622 u8 es = 0;
1623
1624 memcpy(&lpci_bus, ctrl->pci_bus, sizeof(lpci_bus));
1625 pci_bus = &lpci_bus;
1626 pci_bus->number = func->bus;
1627 devfn = PCI_DEVFN(func->device, func->function);
1628
1629 ab = find_acpi_bridge_by_bus(acpi_bridges_head, ctrl->seg, ctrl->slot_bus);
1630
1631 if (ab) {
1632 if (ab->_hpp) {
1633 lt = (u8)ab->_hpp->latency_timer;
1634 cls = (u8)ab->_hpp->cache_line_size;
1635 ep = (u8)ab->_hpp->enable_perr;
1636 es = (u8)ab->_hpp->enable_serr;
1637 } else
1638 dbg("_hpp: no _hpp for B/D/F=%#x/%#x/%#x. use default value\n", func->bus, func->device, func->function);
1639 } else
1640 dbg("_hpp: no acpi bridge for B/D/F = %#x/%#x/%#x. use default value\n", func->bus, func->device, func->function);
1641
1642
1643 if (card_type == PCI_HEADER_TYPE_BRIDGE) {
1644 /* set subordinate Latency Timer */
1645 rc |= pci_bus_write_config_byte(pci_bus, devfn, PCI_SEC_LATENCY_TIMER, lt);
1646 }
1647
1648 /* set base Latency Timer */
1649 rc |= pci_bus_write_config_byte(pci_bus, devfn, PCI_LATENCY_TIMER, lt);
1650 dbg(" set latency timer =0x%02x: %x\n", lt, rc);
1651
1652 rc |= pci_bus_write_config_byte(pci_bus, devfn, PCI_CACHE_LINE_SIZE, cls);
1653 dbg(" set cache_line_size=0x%02x: %x\n", cls, rc);
1654
1655 return rc;
1656} 161}
1657 162
1658void shpchprm_enable_card( 163void get_hp_params_from_firmware(struct pci_dev *dev,
1659 struct controller *ctrl, 164 struct hotplug_params *hpp)
1660 struct pci_func *func,
1661 u8 card_type)
1662{ 165{
1663 u16 command, cmd, bcommand, bcmd; 166 acpi_status status = AE_NOT_FOUND;
1664 struct pci_bus lpci_bus, *pci_bus; 167 struct pci_dev *pdev = dev;
1665 struct acpi_bridge *ab;
1666 unsigned int devfn;
1667 int rc;
1668
1669 memcpy(&lpci_bus, ctrl->pci_bus, sizeof(lpci_bus));
1670 pci_bus = &lpci_bus;
1671 pci_bus->number = func->bus;
1672 devfn = PCI_DEVFN(func->device, func->function);
1673
1674 rc = pci_bus_read_config_word(pci_bus, devfn, PCI_COMMAND, &command);
1675
1676 if (card_type == PCI_HEADER_TYPE_BRIDGE) {
1677 rc = pci_bus_read_config_word(pci_bus, devfn, PCI_BRIDGE_CONTROL, &bcommand);
1678 }
1679 168
1680 cmd = command = command | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE 169 /*
1681 | PCI_COMMAND_IO | PCI_COMMAND_MEMORY; 170 * _HPP settings apply to all child buses, until another _HPP is
1682 bcmd = bcommand = bcommand | PCI_BRIDGE_CTL_NO_ISA; 171 * encountered. If we don't find an _HPP for the input pci dev,
1683 172 * look for it in the parent device scope since that would apply to
1684 ab = find_acpi_bridge_by_bus(acpi_bridges_head, ctrl->seg, ctrl->slot_bus); 173 * this pci dev. If we don't find any _HPP, use hardcoded defaults
1685 if (ab) { 174 */
1686 if (ab->_hpp) { 175 while (pdev && (ACPI_FAILURE(status))) {
1687 if (ab->_hpp->enable_perr) { 176 acpi_handle handle = DEVICE_ACPI_HANDLE(&(pdev->dev));
1688 command |= PCI_COMMAND_PARITY; 177 if (!handle)
1689 bcommand |= PCI_BRIDGE_CTL_PARITY; 178 break;
1690 } else { 179 status = acpi_run_hpp(handle, hpp);
1691 command &= ~PCI_COMMAND_PARITY; 180 if (!(pdev->bus->parent))
1692 bcommand &= ~PCI_BRIDGE_CTL_PARITY; 181 break;
1693 } 182 /* Check if a parent object supports _HPP */
1694 if (ab->_hpp->enable_serr) { 183 pdev = pdev->bus->parent->self;
1695 command |= PCI_COMMAND_SERR;
1696 bcommand |= PCI_BRIDGE_CTL_SERR;
1697 } else {
1698 command &= ~PCI_COMMAND_SERR;
1699 bcommand &= ~PCI_BRIDGE_CTL_SERR;
1700 }
1701 } else
1702 dbg("no _hpp for B/D/F = %#x/%#x/%#x.\n", func->bus, func->device, func->function);
1703 } else
1704 dbg("no acpi bridge for B/D/F = %#x/%#x/%#x.\n", func->bus, func->device, func->function);
1705
1706 if (command != cmd) {
1707 rc = pci_bus_write_config_word(pci_bus, devfn, PCI_COMMAND, command);
1708 }
1709 if ((card_type == PCI_HEADER_TYPE_BRIDGE) && (bcommand != bcmd)) {
1710 rc = pci_bus_write_config_word(pci_bus, devfn, PCI_BRIDGE_CONTROL, bcommand);
1711 } 184 }
1712} 185}
1713 186
diff --git a/drivers/pci/hotplug/shpchprm_legacy.c b/drivers/pci/hotplug/shpchprm_legacy.c
index ba6c549c9b9d..ed6c1254bf6f 100644
--- a/drivers/pci/hotplug/shpchprm_legacy.c
+++ b/drivers/pci/hotplug/shpchprm_legacy.c
@@ -27,33 +27,11 @@
27 * 27 *
28 */ 28 */
29 29
30#include <linux/config.h>
31#include <linux/module.h> 30#include <linux/module.h>
32#include <linux/kernel.h> 31#include <linux/kernel.h>
33#include <linux/types.h> 32#include <linux/types.h>
34#include <linux/pci.h> 33#include <linux/pci.h>
35#include <linux/init.h>
36#include <asm/uaccess.h>
37#ifdef CONFIG_IA64
38#include <asm/iosapic.h>
39#endif
40#include "shpchp.h" 34#include "shpchp.h"
41#include "shpchprm.h"
42#include "shpchprm_legacy.h"
43
44static void __iomem *shpchp_rom_start;
45static u16 unused_IRQ;
46
47void shpchprm_cleanup(void)
48{
49 if (shpchp_rom_start)
50 iounmap(shpchp_rom_start);
51}
52
53int shpchprm_print_pirt(void)
54{
55 return 0;
56}
57 35
58int shpchprm_get_physical_slot_number(struct controller *ctrl, u32 *sun, u8 busnum, u8 devnum) 36int shpchprm_get_physical_slot_number(struct controller *ctrl, u32 *sun, u8 busnum, u8 devnum)
59{ 37{
@@ -63,377 +41,14 @@ int shpchprm_get_physical_slot_number(struct controller *ctrl, u32 *sun, u8 busn
63 return 0; 41 return 0;
64} 42}
65 43
66/* Find the Hot Plug Resource Table in the specified region of memory */ 44void get_hp_params_from_firmware(struct pci_dev *dev,
67static void __iomem *detect_HRT_floating_pointer(void __iomem *begin, void __iomem *end) 45 struct hotplug_params *hpp)
68{ 46{
69 void __iomem *fp; 47 return;
70 void __iomem *endp;
71 u8 temp1, temp2, temp3, temp4;
72 int status = 0;
73
74 endp = (end - sizeof(struct hrt) + 1);
75
76 for (fp = begin; fp <= endp; fp += 16) {
77 temp1 = readb(fp + SIG0);
78 temp2 = readb(fp + SIG1);
79 temp3 = readb(fp + SIG2);
80 temp4 = readb(fp + SIG3);
81 if (temp1 == '$' && temp2 == 'H' && temp3 == 'R' && temp4 == 'T') {
82 status = 1;
83 break;
84 }
85 }
86
87 if (!status)
88 fp = NULL;
89
90 dbg("Discovered Hotplug Resource Table at %p\n", fp);
91 return fp;
92} 48}
93 49
94/* 50void get_hp_hw_control_from_firmware(struct pci_dev *dev)
95 * shpchprm_find_available_resources
96 *
97 * Finds available memory, IO, and IRQ resources for programming
98 * devices which may be added to the system
99 * this function is for hot plug ADD!
100 *
101 * returns 0 if success
102 */
103int shpchprm_find_available_resources(struct controller *ctrl)
104{ 51{
105 u8 populated_slot; 52 return;
106 u8 bridged_slot;
107 void __iomem *one_slot;
108 struct pci_func *func = NULL;
109 int i = 10, index = 0;
110 u32 temp_dword, rc;
111 ulong temp_ulong;
112 struct pci_resource *mem_node;
113 struct pci_resource *p_mem_node;
114 struct pci_resource *io_node;
115 struct pci_resource *bus_node;
116 void __iomem *rom_resource_table;
117 struct pci_bus lpci_bus, *pci_bus;
118 u8 cfgspc_irq, temp;
119
120 memcpy(&lpci_bus, ctrl->pci_bus, sizeof(lpci_bus));
121 pci_bus = &lpci_bus;
122 rom_resource_table = detect_HRT_floating_pointer(shpchp_rom_start, shpchp_rom_start + 0xffff);
123 dbg("rom_resource_table = %p\n", rom_resource_table);
124 if (rom_resource_table == NULL)
125 return -ENODEV;
126
127 /* Sum all resources and setup resource maps */
128 unused_IRQ = readl(rom_resource_table + UNUSED_IRQ);
129 dbg("unused_IRQ = %x\n", unused_IRQ);
130
131 temp = 0;
132 while (unused_IRQ) {
133 if (unused_IRQ & 1) {
134 shpchp_disk_irq = temp;
135 break;
136 }
137 unused_IRQ = unused_IRQ >> 1;
138 temp++;
139 }
140
141 dbg("shpchp_disk_irq= %d\n", shpchp_disk_irq);
142 unused_IRQ = unused_IRQ >> 1;
143 temp++;
144
145 while (unused_IRQ) {
146 if (unused_IRQ & 1) {
147 shpchp_nic_irq = temp;
148 break;
149 }
150 unused_IRQ = unused_IRQ >> 1;
151 temp++;
152 }
153
154 dbg("shpchp_nic_irq= %d\n", shpchp_nic_irq);
155 unused_IRQ = readl(rom_resource_table + PCIIRQ);
156
157 temp = 0;
158
159 pci_read_config_byte(ctrl->pci_dev, PCI_INTERRUPT_LINE, &cfgspc_irq);
160
161 if (!shpchp_nic_irq) {
162 shpchp_nic_irq = cfgspc_irq;
163 }
164
165 if (!shpchp_disk_irq) {
166 shpchp_disk_irq = cfgspc_irq;
167 }
168
169 dbg("shpchp_disk_irq, shpchp_nic_irq= %d, %d\n", shpchp_disk_irq, shpchp_nic_irq);
170
171 one_slot = rom_resource_table + sizeof(struct hrt);
172
173 i = readb(rom_resource_table + NUMBER_OF_ENTRIES);
174 dbg("number_of_entries = %d\n", i);
175
176 if (!readb(one_slot + SECONDARY_BUS))
177 return (1);
178
179 dbg("dev|IO base|length|MEMbase|length|PM base|length|PB SB MB\n");
180
181 while (i && readb(one_slot + SECONDARY_BUS)) {
182 u8 dev_func = readb(one_slot + DEV_FUNC);
183 u8 primary_bus = readb(one_slot + PRIMARY_BUS);
184 u8 secondary_bus = readb(one_slot + SECONDARY_BUS);
185 u8 max_bus = readb(one_slot + MAX_BUS);
186 u16 io_base = readw(one_slot + IO_BASE);
187 u16 io_length = readw(one_slot + IO_LENGTH);
188 u16 mem_base = readw(one_slot + MEM_BASE);
189 u16 mem_length = readw(one_slot + MEM_LENGTH);
190 u16 pre_mem_base = readw(one_slot + PRE_MEM_BASE);
191 u16 pre_mem_length = readw(one_slot + PRE_MEM_LENGTH);
192
193 dbg("%2.2x | %4.4x | %4.4x | %4.4x | %4.4x | %4.4x | %4.4x |%2.2x %2.2x %2.2x\n",
194 dev_func, io_base, io_length, mem_base, mem_length, pre_mem_base, pre_mem_length,
195 primary_bus, secondary_bus, max_bus);
196
197 /* If this entry isn't for our controller's bus, ignore it */
198 if (primary_bus != ctrl->slot_bus) {
199 i--;
200 one_slot += sizeof(struct slot_rt);
201 continue;
202 }
203 /* find out if this entry is for an occupied slot */
204 temp_dword = 0xFFFFFFFF;
205 pci_bus->number = primary_bus;
206 pci_bus_read_config_dword(pci_bus, dev_func, PCI_VENDOR_ID, &temp_dword);
207
208 dbg("temp_D_word = %x\n", temp_dword);
209
210 if (temp_dword != 0xFFFFFFFF) {
211 index = 0;
212 func = shpchp_slot_find(primary_bus, dev_func >> 3, 0);
213
214 while (func && (func->function != (dev_func & 0x07))) {
215 dbg("func = %p b:d:f(%x:%x:%x)\n", func, primary_bus, dev_func >> 3, index);
216 func = shpchp_slot_find(primary_bus, dev_func >> 3, index++);
217 }
218
219 /* If we can't find a match, skip this table entry */
220 if (!func) {
221 i--;
222 one_slot += sizeof(struct slot_rt);
223 continue;
224 }
225 /* this may not work and shouldn't be used */
226 if (secondary_bus != primary_bus)
227 bridged_slot = 1;
228 else
229 bridged_slot = 0;
230
231 populated_slot = 1;
232 } else {
233 populated_slot = 0;
234 bridged_slot = 0;
235 }
236 dbg("slot populated =%s \n", populated_slot?"yes":"no");
237
238 /* If we've got a valid IO base, use it */
239
240 temp_ulong = io_base + io_length;
241
242 if ((io_base) && (temp_ulong <= 0x10000)) {
243 io_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
244 if (!io_node)
245 return -ENOMEM;
246
247 io_node->base = (ulong)io_base;
248 io_node->length = (ulong)io_length;
249 dbg("found io_node(base, length) = %x, %x\n", io_node->base, io_node->length);
250
251 if (!populated_slot) {
252 io_node->next = ctrl->io_head;
253 ctrl->io_head = io_node;
254 } else {
255 io_node->next = func->io_head;
256 func->io_head = io_node;
257 }
258 }
259
260 /* If we've got a valid memory base, use it */
261 temp_ulong = mem_base + mem_length;
262 if ((mem_base) && (temp_ulong <= 0x10000)) {
263 mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
264 if (!mem_node)
265 return -ENOMEM;
266
267 mem_node->base = (ulong)mem_base << 16;
268 mem_node->length = (ulong)(mem_length << 16);
269 dbg("found mem_node(base, length) = %x, %x\n", mem_node->base, mem_node->length);
270
271 if (!populated_slot) {
272 mem_node->next = ctrl->mem_head;
273 ctrl->mem_head = mem_node;
274 } else {
275 mem_node->next = func->mem_head;
276 func->mem_head = mem_node;
277 }
278 }
279
280 /*
281 * If we've got a valid prefetchable memory base, and
282 * the base + length isn't greater than 0xFFFF
283 */
284 temp_ulong = pre_mem_base + pre_mem_length;
285 if ((pre_mem_base) && (temp_ulong <= 0x10000)) {
286 p_mem_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
287 if (!p_mem_node)
288 return -ENOMEM;
289
290 p_mem_node->base = (ulong)pre_mem_base << 16;
291 p_mem_node->length = (ulong)pre_mem_length << 16;
292 dbg("found p_mem_node(base, length) = %x, %x\n", p_mem_node->base, p_mem_node->length);
293
294 if (!populated_slot) {
295 p_mem_node->next = ctrl->p_mem_head;
296 ctrl->p_mem_head = p_mem_node;
297 } else {
298 p_mem_node->next = func->p_mem_head;
299 func->p_mem_head = p_mem_node;
300 }
301 }
302
303 /*
304 * If we've got a valid bus number, use it
305 * The second condition is to ignore bus numbers on
306 * populated slots that don't have PCI-PCI bridges
307 */
308 if (secondary_bus && (secondary_bus != primary_bus)) {
309 bus_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
310 if (!bus_node)
311 return -ENOMEM;
312
313 bus_node->base = (ulong)secondary_bus;
314 bus_node->length = (ulong)(max_bus - secondary_bus + 1);
315 dbg("found bus_node(base, length) = %x, %x\n", bus_node->base, bus_node->length);
316
317 if (!populated_slot) {
318 bus_node->next = ctrl->bus_head;
319 ctrl->bus_head = bus_node;
320 } else {
321 bus_node->next = func->bus_head;
322 func->bus_head = bus_node;
323 }
324 }
325
326 i--;
327 one_slot += sizeof(struct slot_rt);
328 }
329
330 /* If all of the following fail, we don't have any resources for hot plug add */
331 rc = 1;
332 rc &= shpchp_resource_sort_and_combine(&(ctrl->mem_head));
333 rc &= shpchp_resource_sort_and_combine(&(ctrl->p_mem_head));
334 rc &= shpchp_resource_sort_and_combine(&(ctrl->io_head));
335 rc &= shpchp_resource_sort_and_combine(&(ctrl->bus_head));
336
337 return (rc);
338} 53}
339 54
340int shpchprm_set_hpp(
341 struct controller *ctrl,
342 struct pci_func *func,
343 u8 card_type)
344{
345 u32 rc;
346 u8 temp_byte;
347 struct pci_bus lpci_bus, *pci_bus;
348 unsigned int devfn;
349 memcpy(&lpci_bus, ctrl->pci_bus, sizeof(lpci_bus));
350 pci_bus = &lpci_bus;
351 pci_bus->number = func->bus;
352 devfn = PCI_DEVFN(func->device, func->function);
353
354 temp_byte = 0x40; /* hard coded value for LT */
355 if (card_type == PCI_HEADER_TYPE_BRIDGE) {
356 /* set subordinate Latency Timer */
357 rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_SEC_LATENCY_TIMER, temp_byte);
358 if (rc) {
359 dbg("%s: set secondary LT error. b:d:f(%02x:%02x:%02x)\n", __FUNCTION__, func->bus,
360 func->device, func->function);
361 return rc;
362 }
363 }
364
365 /* set base Latency Timer */
366 rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_LATENCY_TIMER, temp_byte);
367 if (rc) {
368 dbg("%s: set LT error. b:d:f(%02x:%02x:%02x)\n", __FUNCTION__, func->bus, func->device, func->function);
369 return rc;
370 }
371
372 /* set Cache Line size */
373 temp_byte = 0x08; /* hard coded value for CLS */
374 rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_CACHE_LINE_SIZE, temp_byte);
375 if (rc) {
376 dbg("%s: set CLS error. b:d:f(%02x:%02x:%02x)\n", __FUNCTION__, func->bus, func->device, func->function);
377 }
378
379 /* set enable_perr */
380 /* set enable_serr */
381
382 return rc;
383}
384
385void shpchprm_enable_card(
386 struct controller *ctrl,
387 struct pci_func *func,
388 u8 card_type)
389{
390 u16 command, bcommand;
391 struct pci_bus lpci_bus, *pci_bus;
392 unsigned int devfn;
393 int rc;
394
395 memcpy(&lpci_bus, ctrl->pci_bus, sizeof(lpci_bus));
396 pci_bus = &lpci_bus;
397 pci_bus->number = func->bus;
398 devfn = PCI_DEVFN(func->device, func->function);
399
400 rc = pci_bus_read_config_word(pci_bus, devfn, PCI_COMMAND, &command);
401 command |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR
402 | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE
403 | PCI_COMMAND_IO | PCI_COMMAND_MEMORY;
404 rc = pci_bus_write_config_word(pci_bus, devfn, PCI_COMMAND, command);
405
406 if (card_type == PCI_HEADER_TYPE_BRIDGE) {
407 rc = pci_bus_read_config_word(pci_bus, devfn, PCI_BRIDGE_CONTROL, &bcommand);
408 bcommand |= PCI_BRIDGE_CTL_PARITY | PCI_BRIDGE_CTL_SERR
409 | PCI_BRIDGE_CTL_NO_ISA;
410 rc = pci_bus_write_config_word(pci_bus, devfn, PCI_BRIDGE_CONTROL, bcommand);
411 }
412}
413
414static int legacy_shpchprm_init_pci(void)
415{
416 shpchp_rom_start = ioremap(ROM_PHY_ADDR, ROM_PHY_LEN);
417 if (!shpchp_rom_start) {
418 err("Could not ioremap memory region for ROM\n");
419 return -EIO;
420 }
421
422 return 0;
423}
424
425int shpchprm_init(enum php_ctlr_type ctrl_type)
426{
427 int retval;
428
429 switch (ctrl_type) {
430 case PCI:
431 retval = legacy_shpchprm_init_pci();
432 break;
433 default:
434 retval = -ENODEV;
435 break;
436 }
437
438 return retval;
439}
diff --git a/drivers/pci/hotplug/shpchprm_legacy.h b/drivers/pci/hotplug/shpchprm_legacy.h
deleted file mode 100644
index 21bda74ddfa5..000000000000
--- a/drivers/pci/hotplug/shpchprm_legacy.h
+++ /dev/null
@@ -1,113 +0,0 @@
1/*
2 * SHPCHPRM Legacy: PHP Resource Manager for Non-ACPI/Legacy platform using HRT
3 *
4 * Copyright (C) 1995,2001 Compaq Computer Corporation
5 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
6 * Copyright (C) 2001 IBM Corp.
7 * Copyright (C) 2003-2004 Intel Corporation
8 *
9 * All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or (at
14 * your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
19 * NON INFRINGEMENT. See the GNU General Public License for more
20 * details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 * Send feedback to <greg@kroah.com>, <kristen.c.accardi@intel.com>
27 *
28 */
29
30#ifndef _SHPCHPRM_LEGACY_H_
31#define _SHPCHPRM_LEGACY_H_
32
33#define ROM_PHY_ADDR 0x0F0000
34#define ROM_PHY_LEN 0x00FFFF
35
36struct slot_rt {
37 u8 dev_func;
38 u8 primary_bus;
39 u8 secondary_bus;
40 u8 max_bus;
41 u16 io_base;
42 u16 io_length;
43 u16 mem_base;
44 u16 mem_length;
45 u16 pre_mem_base;
46 u16 pre_mem_length;
47} __attribute__ ((packed));
48
49/* offsets to the hotplug slot resource table registers based on the above structure layout */
50enum slot_rt_offsets {
51 DEV_FUNC = offsetof(struct slot_rt, dev_func),
52 PRIMARY_BUS = offsetof(struct slot_rt, primary_bus),
53 SECONDARY_BUS = offsetof(struct slot_rt, secondary_bus),
54 MAX_BUS = offsetof(struct slot_rt, max_bus),
55 IO_BASE = offsetof(struct slot_rt, io_base),
56 IO_LENGTH = offsetof(struct slot_rt, io_length),
57 MEM_BASE = offsetof(struct slot_rt, mem_base),
58 MEM_LENGTH = offsetof(struct slot_rt, mem_length),
59 PRE_MEM_BASE = offsetof(struct slot_rt, pre_mem_base),
60 PRE_MEM_LENGTH = offsetof(struct slot_rt, pre_mem_length),
61};
62
63struct hrt {
64 char sig0;
65 char sig1;
66 char sig2;
67 char sig3;
68 u16 unused_IRQ;
69 u16 PCIIRQ;
70 u8 number_of_entries;
71 u8 revision;
72 u16 reserved1;
73 u32 reserved2;
74} __attribute__ ((packed));
75
76/* offsets to the hotplug resource table registers based on the above structure layout */
77enum hrt_offsets {
78 SIG0 = offsetof(struct hrt, sig0),
79 SIG1 = offsetof(struct hrt, sig1),
80 SIG2 = offsetof(struct hrt, sig2),
81 SIG3 = offsetof(struct hrt, sig3),
82 UNUSED_IRQ = offsetof(struct hrt, unused_IRQ),
83 PCIIRQ = offsetof(struct hrt, PCIIRQ),
84 NUMBER_OF_ENTRIES = offsetof(struct hrt, number_of_entries),
85 REVISION = offsetof(struct hrt, revision),
86 HRT_RESERVED1 = offsetof(struct hrt, reserved1),
87 HRT_RESERVED2 = offsetof(struct hrt, reserved2),
88};
89
90struct irq_info {
91 u8 bus, devfn; /* bus, device and function */
92 struct {
93 u8 link; /* IRQ line ID, chipset dependent, 0=not routed */
94 u16 bitmap; /* Available IRQs */
95 } __attribute__ ((packed)) irq[4];
96 u8 slot; /* slot number, 0=onboard */
97 u8 rfu;
98} __attribute__ ((packed));
99
100struct irq_routing_table {
101 u32 signature; /* PIRQ_SIGNATURE should be here */
102 u16 version; /* PIRQ_VERSION */
103 u16 size; /* Table size in bytes */
104 u8 rtr_bus, rtr_devfn; /* Where the interrupt router lies */
105 u16 exclusive_irqs; /* IRQs devoted exclusively to PCI usage */
106 u16 rtr_vendor, rtr_device; /* Vendor and device ID of interrupt router */
107 u32 miniport_data; /* Crap */
108 u8 rfu[11];
109 u8 checksum; /* Modulo 256 checksum must give zero */
110 struct irq_info slots[0];
111} __attribute__ ((packed));
112
113#endif /* _SHPCHPRM_LEGACY_H_ */
diff --git a/drivers/pci/hotplug/shpchprm_nonacpi.c b/drivers/pci/hotplug/shpchprm_nonacpi.c
index 5f75ef7f3df2..c6b40998eeb3 100644
--- a/drivers/pci/hotplug/shpchprm_nonacpi.c
+++ b/drivers/pci/hotplug/shpchprm_nonacpi.c
@@ -32,24 +32,9 @@
32#include <linux/kernel.h> 32#include <linux/kernel.h>
33#include <linux/types.h> 33#include <linux/types.h>
34#include <linux/pci.h> 34#include <linux/pci.h>
35#include <linux/init.h> 35#include <linux/slab.h>
36#include <asm/uaccess.h>
37#ifdef CONFIG_IA64
38#include <asm/iosapic.h>
39#endif
40#include "shpchp.h"
41#include "shpchprm.h"
42#include "shpchprm_nonacpi.h"
43 36
44void shpchprm_cleanup(void) 37#include "shpchp.h"
45{
46 return;
47}
48
49int shpchprm_print_pirt(void)
50{
51 return 0;
52}
53 38
54int shpchprm_get_physical_slot_number(struct controller *ctrl, u32 *sun, u8 busnum, u8 devnum) 39int shpchprm_get_physical_slot_number(struct controller *ctrl, u32 *sun, u8 busnum, u8 devnum)
55{ 40{
@@ -60,375 +45,13 @@ int shpchprm_get_physical_slot_number(struct controller *ctrl, u32 *sun, u8 busn
60 return 0; 45 return 0;
61} 46}
62 47
63static void print_pci_resource ( struct pci_resource *aprh) 48void get_hp_params_from_firmware(struct pci_dev *dev,
64{ 49 struct hotplug_params *hpp)
65 struct pci_resource *res;
66
67 for (res = aprh; res; res = res->next)
68 dbg(" base= 0x%x length= 0x%x\n", res->base, res->length);
69}
70
71
72static void phprm_dump_func_res( struct pci_func *fun)
73{
74 struct pci_func *func = fun;
75
76 if (func->bus_head) {
77 dbg(": BUS Resources:\n");
78 print_pci_resource (func->bus_head);
79 }
80 if (func->io_head) {
81 dbg(": IO Resources:\n");
82 print_pci_resource (func->io_head);
83 }
84 if (func->mem_head) {
85 dbg(": MEM Resources:\n");
86 print_pci_resource (func->mem_head);
87 }
88 if (func->p_mem_head) {
89 dbg(": PMEM Resources:\n");
90 print_pci_resource (func->p_mem_head);
91 }
92}
93
94static int phprm_get_used_resources (
95 struct controller *ctrl,
96 struct pci_func *func
97 )
98{
99 return shpchp_save_used_resources (ctrl, func, !DISABLE_CARD);
100}
101
102static int phprm_delete_resource(
103 struct pci_resource **aprh,
104 ulong base,
105 ulong size)
106{
107 struct pci_resource *res;
108 struct pci_resource *prevnode;
109 struct pci_resource *split_node;
110 ulong tbase;
111
112 shpchp_resource_sort_and_combine(aprh);
113
114 for (res = *aprh; res; res = res->next) {
115 if (res->base > base)
116 continue;
117
118 if ((res->base + res->length) < (base + size))
119 continue;
120
121 if (res->base < base) {
122 tbase = base;
123
124 if ((res->length - (tbase - res->base)) < size)
125 continue;
126
127 split_node = (struct pci_resource *) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
128 if (!split_node)
129 return -ENOMEM;
130
131 split_node->base = res->base;
132 split_node->length = tbase - res->base;
133 res->base = tbase;
134 res->length -= split_node->length;
135
136 split_node->next = res->next;
137 res->next = split_node;
138 }
139
140 if (res->length >= size) {
141 split_node = (struct pci_resource*) kmalloc(sizeof(struct pci_resource), GFP_KERNEL);
142 if (!split_node)
143 return -ENOMEM;
144
145 split_node->base = res->base + size;
146 split_node->length = res->length - size;
147 res->length = size;
148
149 split_node->next = res->next;
150 res->next = split_node;
151 }
152
153 if (*aprh == res) {
154 *aprh = res->next;
155 } else {
156 prevnode = *aprh;
157 while (prevnode->next != res)
158 prevnode = prevnode->next;
159
160 prevnode->next = res->next;
161 }
162 res->next = NULL;
163 kfree(res);
164 break;
165 }
166
167 return 0;
168}
169
170
171static int phprm_delete_resources(
172 struct pci_resource **aprh,
173 struct pci_resource *this
174 )
175{
176 struct pci_resource *res;
177
178 for (res = this; res; res = res->next)
179 phprm_delete_resource(aprh, res->base, res->length);
180
181 return 0;
182}
183
184
185static int configure_existing_function(
186 struct controller *ctrl,
187 struct pci_func *func
188 )
189{
190 int rc;
191
192 /* see how much resources the func has used. */
193 rc = phprm_get_used_resources (ctrl, func);
194
195 if (!rc) {
196 /* subtract the resources used by the func from ctrl resources */
197 rc = phprm_delete_resources (&ctrl->bus_head, func->bus_head);
198 rc |= phprm_delete_resources (&ctrl->io_head, func->io_head);
199 rc |= phprm_delete_resources (&ctrl->mem_head, func->mem_head);
200 rc |= phprm_delete_resources (&ctrl->p_mem_head, func->p_mem_head);
201 if (rc)
202 warn("aCEF: cannot del used resources\n");
203 } else
204 err("aCEF: cannot get used resources\n");
205
206 return rc;
207}
208
209static int bind_pci_resources_to_slots ( struct controller *ctrl)
210{
211 struct pci_func *func, new_func;
212 int busn = ctrl->slot_bus;
213 int devn, funn;
214 u32 vid;
215
216 for (devn = 0; devn < 32; devn++) {
217 for (funn = 0; funn < 8; funn++) {
218 /*
219 if (devn == ctrl->device && funn == ctrl->function)
220 continue;
221 */
222 /* find out if this entry is for an occupied slot */
223 vid = 0xFFFFFFFF;
224
225 pci_bus_read_config_dword(ctrl->pci_dev->subordinate, PCI_DEVFN(devn, funn), PCI_VENDOR_ID, &vid);
226
227 if (vid != 0xFFFFFFFF) {
228 func = shpchp_slot_find(busn, devn, funn);
229 if (!func) {
230 memset(&new_func, 0, sizeof(struct pci_func));
231 new_func.bus = busn;
232 new_func.device = devn;
233 new_func.function = funn;
234 new_func.is_a_board = 1;
235 configure_existing_function(ctrl, &new_func);
236 phprm_dump_func_res(&new_func);
237 } else {
238 configure_existing_function(ctrl, func);
239 phprm_dump_func_res(func);
240 }
241 dbg("aCCF:existing PCI 0x%x Func ResourceDump\n", ctrl->bus);
242 }
243 }
244 }
245
246 return 0;
247}
248
249static void phprm_dump_ctrl_res( struct controller *ctlr)
250{
251 struct controller *ctrl = ctlr;
252
253 if (ctrl->bus_head) {
254 dbg(": BUS Resources:\n");
255 print_pci_resource (ctrl->bus_head);
256 }
257 if (ctrl->io_head) {
258 dbg(": IO Resources:\n");
259 print_pci_resource (ctrl->io_head);
260 }
261 if (ctrl->mem_head) {
262 dbg(": MEM Resources:\n");
263 print_pci_resource (ctrl->mem_head);
264 }
265 if (ctrl->p_mem_head) {
266 dbg(": PMEM Resources:\n");
267 print_pci_resource (ctrl->p_mem_head);
268 }
269}
270
271/*
272 * phprm_find_available_resources
273 *
274 * Finds available memory, IO, and IRQ resources for programming
275 * devices which may be added to the system
276 * this function is for hot plug ADD!
277 *
278 * returns 0 if success
279 */
280int shpchprm_find_available_resources(struct controller *ctrl)
281{
282 struct pci_func func;
283 u32 rc;
284
285 memset(&func, 0, sizeof(struct pci_func));
286
287 func.bus = ctrl->bus;
288 func.device = ctrl->device;
289 func.function = ctrl->function;
290 func.is_a_board = 1;
291
292 /* Get resources for this PCI bridge */
293 rc = shpchp_save_used_resources (ctrl, &func, !DISABLE_CARD);
294 dbg("%s: shpchp_save_used_resources rc = %d\n", __FUNCTION__, rc);
295
296 if (func.mem_head)
297 func.mem_head->next = ctrl->mem_head;
298 ctrl->mem_head = func.mem_head;
299
300 if (func.p_mem_head)
301 func.p_mem_head->next = ctrl->p_mem_head;
302 ctrl->p_mem_head = func.p_mem_head;
303
304 if (func.io_head)
305 func.io_head->next = ctrl->io_head;
306 ctrl->io_head = func.io_head;
307
308 if(func.bus_head)
309 func.bus_head->next = ctrl->bus_head;
310 ctrl->bus_head = func.bus_head;
311 if (ctrl->bus_head)
312 phprm_delete_resource(&ctrl->bus_head, ctrl->pci_dev->subordinate->number, 1);
313
314 dbg("%s:pre-Bind PCI 0x%x Ctrl Resource Dump\n", __FUNCTION__, ctrl->bus);
315 phprm_dump_ctrl_res(ctrl);
316 bind_pci_resources_to_slots (ctrl);
317
318 dbg("%s:post-Bind PCI 0x%x Ctrl Resource Dump\n", __FUNCTION__, ctrl->bus);
319 phprm_dump_ctrl_res(ctrl);
320
321
322 /* If all of the following fail, we don't have any resources for hot plug add */
323 rc = 1;
324 rc &= shpchp_resource_sort_and_combine(&(ctrl->mem_head));
325 rc &= shpchp_resource_sort_and_combine(&(ctrl->p_mem_head));
326 rc &= shpchp_resource_sort_and_combine(&(ctrl->io_head));
327 rc &= shpchp_resource_sort_and_combine(&(ctrl->bus_head));
328
329 return (rc);
330}
331
332int shpchprm_set_hpp(
333 struct controller *ctrl,
334 struct pci_func *func,
335 u8 card_type)
336{ 50{
337 u32 rc; 51 return;
338 u8 temp_byte;
339 struct pci_bus lpci_bus, *pci_bus;
340 unsigned int devfn;
341 memcpy(&lpci_bus, ctrl->pci_bus, sizeof(lpci_bus));
342 pci_bus = &lpci_bus;
343 pci_bus->number = func->bus;
344 devfn = PCI_DEVFN(func->device, func->function);
345
346 temp_byte = 0x40; /* hard coded value for LT */
347 if (card_type == PCI_HEADER_TYPE_BRIDGE) {
348 /* set subordinate Latency Timer */
349 rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_SEC_LATENCY_TIMER, temp_byte);
350
351 if (rc) {
352 dbg("%s: set secondary LT error. b:d:f(%02x:%02x:%02x)\n", __FUNCTION__, func->bus,
353 func->device, func->function);
354 return rc;
355 }
356 }
357
358 /* set base Latency Timer */
359 rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_LATENCY_TIMER, temp_byte);
360
361 if (rc) {
362 dbg("%s: set LT error. b:d:f(%02x:%02x:%02x)\n", __FUNCTION__, func->bus, func->device, func->function);
363 return rc;
364 }
365
366 /* set Cache Line size */
367 temp_byte = 0x08; /* hard coded value for CLS */
368
369 rc = pci_bus_write_config_byte(pci_bus, devfn, PCI_CACHE_LINE_SIZE, temp_byte);
370
371 if (rc) {
372 dbg("%s: set CLS error. b:d:f(%02x:%02x:%02x)\n", __FUNCTION__, func->bus, func->device, func->function);
373 }
374
375 /* set enable_perr */
376 /* set enable_serr */
377
378 return rc;
379}
380
381void shpchprm_enable_card(
382 struct controller *ctrl,
383 struct pci_func *func,
384 u8 card_type)
385{
386 u16 command, bcommand;
387 struct pci_bus lpci_bus, *pci_bus;
388 unsigned int devfn;
389 int rc;
390
391 memcpy(&lpci_bus, ctrl->pci_bus, sizeof(lpci_bus));
392 pci_bus = &lpci_bus;
393 pci_bus->number = func->bus;
394 devfn = PCI_DEVFN(func->device, func->function);
395
396 rc = pci_bus_read_config_word(pci_bus, devfn, PCI_COMMAND, &command);
397
398 command |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR
399 | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE
400 | PCI_COMMAND_IO | PCI_COMMAND_MEMORY;
401
402 rc = pci_bus_write_config_word(pci_bus, devfn, PCI_COMMAND, command);
403
404 if (card_type == PCI_HEADER_TYPE_BRIDGE) {
405
406 rc = pci_bus_read_config_word(pci_bus, devfn, PCI_BRIDGE_CONTROL, &bcommand);
407
408 bcommand |= PCI_BRIDGE_CTL_PARITY | PCI_BRIDGE_CTL_SERR
409 | PCI_BRIDGE_CTL_NO_ISA;
410
411 rc = pci_bus_write_config_word(pci_bus, devfn, PCI_BRIDGE_CONTROL, bcommand);
412 }
413}
414
415static int legacy_shpchprm_init_pci(void)
416{
417 return 0;
418} 52}
419 53
420int shpchprm_init(enum php_ctlr_type ctrl_type) 54void get_hp_hw_control_from_firmware(struct pci_dev *dev)
421{ 55{
422 int retval; 56 return;
423
424 switch (ctrl_type) {
425 case PCI:
426 retval = legacy_shpchprm_init_pci();
427 break;
428 default:
429 retval = -ENODEV;
430 break;
431 }
432
433 return retval;
434} 57}
diff --git a/drivers/pci/hotplug/shpchprm_nonacpi.h b/drivers/pci/hotplug/shpchprm_nonacpi.h
deleted file mode 100644
index cddaaa5ee1b3..000000000000
--- a/drivers/pci/hotplug/shpchprm_nonacpi.h
+++ /dev/null
@@ -1,56 +0,0 @@
1/*
2 * SHPCHPRM NONACPI: PHP Resource Manager for Non-ACPI/Legacy platform
3 *
4 * Copyright (C) 1995,2001 Compaq Computer Corporation
5 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
6 * Copyright (C) 2001 IBM Corp.
7 * Copyright (C) 2003-2004 Intel Corporation
8 *
9 * All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or (at
14 * your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
19 * NON INFRINGEMENT. See the GNU General Public License for more
20 * details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 * Send feedback to <greg@kroah.com>, <kristen.c.accardi@intel.com>
27 *
28 */
29
30#ifndef _SHPCHPRM_NONACPI_H_
31#define _SHPCHPRM_NONACPI_H_
32
33struct irq_info {
34 u8 bus, devfn; /* bus, device and function */
35 struct {
36 u8 link; /* IRQ line ID, chipset dependent, 0=not routed */
37 u16 bitmap; /* Available IRQs */
38 } __attribute__ ((packed)) irq[4];
39 u8 slot; /* slot number, 0=onboard */
40 u8 rfu;
41} __attribute__ ((packed));
42
43struct irq_routing_table {
44 u32 signature; /* PIRQ_SIGNATURE should be here */
45 u16 version; /* PIRQ_VERSION */
46 u16 size; /* Table size in bytes */
47 u8 rtr_bus, rtr_devfn; /* Where the interrupt router lies */
48 u16 exclusive_irqs; /* IRQs devoted exclusively to PCI usage */
49 u16 rtr_vendor, rtr_device; /* Vendor and device ID of interrupt router */
50 u32 miniport_data; /* Crap */
51 u8 rfu[11];
52 u8 checksum; /* Modulo 256 checksum must give zero */
53 struct irq_info slots[0];
54} __attribute__ ((packed));
55
56#endif /* _SHPCHPRM_NONACPI_H_ */
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index ee8677bda950..a2033552423c 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -575,6 +575,8 @@ static int msi_capability_init(struct pci_dev *dev)
575/** 575/**
576 * msix_capability_init - configure device's MSI-X capability 576 * msix_capability_init - configure device's MSI-X capability
577 * @dev: pointer to the pci_dev data structure of MSI-X device function 577 * @dev: pointer to the pci_dev data structure of MSI-X device function
578 * @entries: pointer to an array of struct msix_entry entries
579 * @nvec: number of @entries
578 * 580 *
579 * Setup the MSI-X capability structure of device function with a 581 * Setup the MSI-X capability structure of device function with a
580 * single MSI-X vector. A return of zero indicates the successful setup of 582 * single MSI-X vector. A return of zero indicates the successful setup of
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 0d0d533894e0..ae986e590b48 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -8,6 +8,8 @@
8#include <linux/init.h> 8#include <linux/init.h>
9#include <linux/device.h> 9#include <linux/device.h>
10#include <linux/mempolicy.h> 10#include <linux/mempolicy.h>
11#include <linux/string.h>
12#include <linux/slab.h>
11#include "pci.h" 13#include "pci.h"
12 14
13/* 15/*
@@ -26,7 +28,10 @@ struct pci_dynid {
26#ifdef CONFIG_HOTPLUG 28#ifdef CONFIG_HOTPLUG
27 29
28/** 30/**
29 * store_new_id 31 * store_new_id - add a new PCI device ID to this driver and re-probe devices
32 * @driver: target device driver
33 * @buf: buffer for scanning device ID data
34 * @count: input size
30 * 35 *
31 * Adds a new dynamic pci device ID to this driver, 36 * Adds a new dynamic pci device ID to this driver,
32 * and causes the driver to probe for all devices again. 37 * and causes the driver to probe for all devices again.
@@ -194,8 +199,10 @@ static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev,
194 199
195/** 200/**
196 * __pci_device_probe() 201 * __pci_device_probe()
202 * @drv: driver to call to check if it wants the PCI device
203 * @pci_dev: PCI device being probed
197 * 204 *
198 * returns 0 on success, else error. 205 * returns 0 on success, else error.
199 * side-effect: pci_dev->driver is set to drv when drv claims pci_dev. 206 * side-effect: pci_dev->driver is set to drv when drv claims pci_dev.
200 */ 207 */
201static int 208static int
@@ -377,6 +384,10 @@ int pci_register_driver(struct pci_driver *drv)
377 * the pci shutdown function, this test can go away. */ 384 * the pci shutdown function, this test can go away. */
378 if (!drv->driver.shutdown) 385 if (!drv->driver.shutdown)
379 drv->driver.shutdown = pci_device_shutdown; 386 drv->driver.shutdown = pci_device_shutdown;
387 else
388 printk(KERN_WARNING "Warning: PCI driver %s has a struct "
389 "device_driver shutdown method, please update!\n",
390 drv->name);
380 drv->driver.owner = drv->owner; 391 drv->driver.owner = drv->owner;
381 drv->driver.kobj.ktype = &pci_driver_kobj_type; 392 drv->driver.kobj.ktype = &pci_driver_kobj_type;
382 393
@@ -436,11 +447,11 @@ pci_dev_driver(const struct pci_dev *dev)
436 447
437/** 448/**
438 * pci_bus_match - Tell if a PCI device structure has a matching PCI device id structure 449 * pci_bus_match - Tell if a PCI device structure has a matching PCI device id structure
439 * @ids: array of PCI device id structures to search in
440 * @dev: the PCI device structure to match against 450 * @dev: the PCI device structure to match against
451 * @drv: the device driver to search for matching PCI device id structures
441 * 452 *
442 * Used by a driver to check whether a PCI device present in the 453 * Used by a driver to check whether a PCI device present in the
443 * system is in its list of supported devices.Returns the matching 454 * system is in its list of supported devices. Returns the matching
444 * pci_device_id structure or %NULL if there is no match. 455 * pci_device_id structure or %NULL if there is no match.
445 */ 456 */
446static int pci_bus_match(struct device *dev, struct device_driver *drv) 457static int pci_bus_match(struct device *dev, struct device_driver *drv)
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 2898830c496f..965a5934623a 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -130,7 +130,7 @@ pci_read_config(struct kobject *kobj, char *buf, loff_t off, size_t count)
130 130
131 if ((off & 1) && size) { 131 if ((off & 1) && size) {
132 u8 val; 132 u8 val;
133 pci_read_config_byte(dev, off, &val); 133 pci_user_read_config_byte(dev, off, &val);
134 data[off - init_off] = val; 134 data[off - init_off] = val;
135 off++; 135 off++;
136 size--; 136 size--;
@@ -138,7 +138,7 @@ pci_read_config(struct kobject *kobj, char *buf, loff_t off, size_t count)
138 138
139 if ((off & 3) && size > 2) { 139 if ((off & 3) && size > 2) {
140 u16 val; 140 u16 val;
141 pci_read_config_word(dev, off, &val); 141 pci_user_read_config_word(dev, off, &val);
142 data[off - init_off] = val & 0xff; 142 data[off - init_off] = val & 0xff;
143 data[off - init_off + 1] = (val >> 8) & 0xff; 143 data[off - init_off + 1] = (val >> 8) & 0xff;
144 off += 2; 144 off += 2;
@@ -147,7 +147,7 @@ pci_read_config(struct kobject *kobj, char *buf, loff_t off, size_t count)
147 147
148 while (size > 3) { 148 while (size > 3) {
149 u32 val; 149 u32 val;
150 pci_read_config_dword(dev, off, &val); 150 pci_user_read_config_dword(dev, off, &val);
151 data[off - init_off] = val & 0xff; 151 data[off - init_off] = val & 0xff;
152 data[off - init_off + 1] = (val >> 8) & 0xff; 152 data[off - init_off + 1] = (val >> 8) & 0xff;
153 data[off - init_off + 2] = (val >> 16) & 0xff; 153 data[off - init_off + 2] = (val >> 16) & 0xff;
@@ -158,7 +158,7 @@ pci_read_config(struct kobject *kobj, char *buf, loff_t off, size_t count)
158 158
159 if (size >= 2) { 159 if (size >= 2) {
160 u16 val; 160 u16 val;
161 pci_read_config_word(dev, off, &val); 161 pci_user_read_config_word(dev, off, &val);
162 data[off - init_off] = val & 0xff; 162 data[off - init_off] = val & 0xff;
163 data[off - init_off + 1] = (val >> 8) & 0xff; 163 data[off - init_off + 1] = (val >> 8) & 0xff;
164 off += 2; 164 off += 2;
@@ -167,7 +167,7 @@ pci_read_config(struct kobject *kobj, char *buf, loff_t off, size_t count)
167 167
168 if (size > 0) { 168 if (size > 0) {
169 u8 val; 169 u8 val;
170 pci_read_config_byte(dev, off, &val); 170 pci_user_read_config_byte(dev, off, &val);
171 data[off - init_off] = val; 171 data[off - init_off] = val;
172 off++; 172 off++;
173 --size; 173 --size;
@@ -192,7 +192,7 @@ pci_write_config(struct kobject *kobj, char *buf, loff_t off, size_t count)
192 } 192 }
193 193
194 if ((off & 1) && size) { 194 if ((off & 1) && size) {
195 pci_write_config_byte(dev, off, data[off - init_off]); 195 pci_user_write_config_byte(dev, off, data[off - init_off]);
196 off++; 196 off++;
197 size--; 197 size--;
198 } 198 }
@@ -200,7 +200,7 @@ pci_write_config(struct kobject *kobj, char *buf, loff_t off, size_t count)
200 if ((off & 3) && size > 2) { 200 if ((off & 3) && size > 2) {
201 u16 val = data[off - init_off]; 201 u16 val = data[off - init_off];
202 val |= (u16) data[off - init_off + 1] << 8; 202 val |= (u16) data[off - init_off + 1] << 8;
203 pci_write_config_word(dev, off, val); 203 pci_user_write_config_word(dev, off, val);
204 off += 2; 204 off += 2;
205 size -= 2; 205 size -= 2;
206 } 206 }
@@ -210,7 +210,7 @@ pci_write_config(struct kobject *kobj, char *buf, loff_t off, size_t count)
210 val |= (u32) data[off - init_off + 1] << 8; 210 val |= (u32) data[off - init_off + 1] << 8;
211 val |= (u32) data[off - init_off + 2] << 16; 211 val |= (u32) data[off - init_off + 2] << 16;
212 val |= (u32) data[off - init_off + 3] << 24; 212 val |= (u32) data[off - init_off + 3] << 24;
213 pci_write_config_dword(dev, off, val); 213 pci_user_write_config_dword(dev, off, val);
214 off += 4; 214 off += 4;
215 size -= 4; 215 size -= 4;
216 } 216 }
@@ -218,13 +218,13 @@ pci_write_config(struct kobject *kobj, char *buf, loff_t off, size_t count)
218 if (size >= 2) { 218 if (size >= 2) {
219 u16 val = data[off - init_off]; 219 u16 val = data[off - init_off];
220 val |= (u16) data[off - init_off + 1] << 8; 220 val |= (u16) data[off - init_off + 1] << 8;
221 pci_write_config_word(dev, off, val); 221 pci_user_write_config_word(dev, off, val);
222 off += 2; 222 off += 2;
223 size -= 2; 223 size -= 2;
224 } 224 }
225 225
226 if (size) { 226 if (size) {
227 pci_write_config_byte(dev, off, data[off - init_off]); 227 pci_user_write_config_byte(dev, off, data[off - init_off]);
228 off++; 228 off++;
229 --size; 229 --size;
230 } 230 }
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 259d247b7551..e74d75843047 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -15,6 +15,7 @@
15#include <linux/pci.h> 15#include <linux/pci.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/spinlock.h> 17#include <linux/spinlock.h>
18#include <linux/string.h>
18#include <asm/dma.h> /* isa_dma_bridge_buggy */ 19#include <asm/dma.h> /* isa_dma_bridge_buggy */
19#include "pci.h" 20#include "pci.h"
20 21
@@ -252,6 +253,8 @@ pci_restore_bars(struct pci_dev *dev)
252 pci_update_resource(dev, &dev->resource[i], i); 253 pci_update_resource(dev, &dev->resource[i], i);
253} 254}
254 255
256int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t t);
257
255/** 258/**
256 * pci_set_power_state - Set the power state of a PCI device 259 * pci_set_power_state - Set the power state of a PCI device
257 * @dev: PCI device to be suspended 260 * @dev: PCI device to be suspended
@@ -266,7 +269,6 @@ pci_restore_bars(struct pci_dev *dev)
266 * -EIO if device does not support PCI PM. 269 * -EIO if device does not support PCI PM.
267 * 0 if we can successfully change the power state. 270 * 0 if we can successfully change the power state.
268 */ 271 */
269int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t t);
270int 272int
271pci_set_power_state(struct pci_dev *dev, pci_power_t state) 273pci_set_power_state(struct pci_dev *dev, pci_power_t state)
272{ 274{
@@ -314,19 +316,19 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state)
314 * sets PowerState to 0. 316 * sets PowerState to 0.
315 */ 317 */
316 switch (dev->current_state) { 318 switch (dev->current_state) {
319 case PCI_D0:
320 case PCI_D1:
321 case PCI_D2:
322 pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
323 pmcsr |= state;
324 break;
317 case PCI_UNKNOWN: /* Boot-up */ 325 case PCI_UNKNOWN: /* Boot-up */
318 if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot 326 if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot
319 && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET)) 327 && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET))
320 need_restore = 1; 328 need_restore = 1;
321 /* Fall-through: force to D0 */ 329 /* Fall-through: force to D0 */
322 case PCI_D3hot:
323 case PCI_D3cold:
324 case PCI_POWER_ERROR:
325 pmcsr = 0;
326 break;
327 default: 330 default:
328 pmcsr &= ~PCI_PM_CTRL_STATE_MASK; 331 pmcsr = 0;
329 pmcsr |= state;
330 break; 332 break;
331 } 333 }
332 334
@@ -808,8 +810,8 @@ pci_clear_mwi(struct pci_dev *dev)
808 810
809/** 811/**
810 * pci_intx - enables/disables PCI INTx for device dev 812 * pci_intx - enables/disables PCI INTx for device dev
811 * @dev: the PCI device to operate on 813 * @pdev: the PCI device to operate on
812 * @enable: boolean 814 * @enable: boolean: whether to enable or disable PCI INTx
813 * 815 *
814 * Enables/disables PCI INTx for device dev 816 * Enables/disables PCI INTx for device dev
815 */ 817 */
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index d3f3dd42240d..6527b36c9a61 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -15,6 +15,13 @@ extern int pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
15extern int (*platform_pci_choose_state)(struct pci_dev *dev, pm_message_t state); 15extern int (*platform_pci_choose_state)(struct pci_dev *dev, pm_message_t state);
16extern int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t state); 16extern int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t state);
17 17
18extern int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val);
19extern int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val);
20extern int pci_user_read_config_dword(struct pci_dev *dev, int where, u32 *val);
21extern int pci_user_write_config_byte(struct pci_dev *dev, int where, u8 val);
22extern int pci_user_write_config_word(struct pci_dev *dev, int where, u16 val);
23extern int pci_user_write_config_dword(struct pci_dev *dev, int where, u32 val);
24
18/* PCI /proc functions */ 25/* PCI /proc functions */
19#ifdef CONFIG_PROC_FS 26#ifdef CONFIG_PROC_FS
20extern int pci_proc_attach_device(struct pci_dev *dev); 27extern int pci_proc_attach_device(struct pci_dev *dev);
diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
index 393e0cee91a9..467a4ceccf10 100644
--- a/drivers/pci/pcie/portdrv_core.c
+++ b/drivers/pci/pcie/portdrv_core.c
@@ -11,6 +11,8 @@
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/errno.h> 12#include <linux/errno.h>
13#include <linux/pm.h> 13#include <linux/pm.h>
14#include <linux/string.h>
15#include <linux/slab.h>
14#include <linux/pcieport_if.h> 16#include <linux/pcieport_if.h>
15 17
16#include "portdrv.h" 18#include "portdrv.h"
@@ -61,7 +63,7 @@ static int pcie_port_remove_service(struct device *dev)
61 63
62static void pcie_port_shutdown_service(struct device *dev) {} 64static void pcie_port_shutdown_service(struct device *dev) {}
63 65
64static int pcie_port_suspend_service(struct device *dev, pm_message_t state, u32 level) 66static int pcie_port_suspend_service(struct device *dev, pm_message_t state)
65{ 67{
66 struct pcie_device *pciedev; 68 struct pcie_device *pciedev;
67 struct pcie_port_service_driver *driver; 69 struct pcie_port_service_driver *driver;
@@ -76,7 +78,7 @@ static int pcie_port_suspend_service(struct device *dev, pm_message_t state, u32
76 return 0; 78 return 0;
77} 79}
78 80
79static int pcie_port_resume_service(struct device *dev, u32 level) 81static int pcie_port_resume_service(struct device *dev)
80{ 82{
81 struct pcie_device *pciedev; 83 struct pcie_device *pciedev;
82 struct pcie_port_service_driver *driver; 84 struct pcie_port_service_driver *driver;
diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c
index 3c565ce7f77b..02260141dc81 100644
--- a/drivers/pci/pcie/portdrv_pci.c
+++ b/drivers/pci/pcie/portdrv_pci.c
@@ -12,6 +12,7 @@
12#include <linux/errno.h> 12#include <linux/errno.h>
13#include <linux/pm.h> 13#include <linux/pm.h>
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/slab.h>
15#include <linux/pcieport_if.h> 16#include <linux/pcieport_if.h>
16 17
17#include "portdrv.h" 18#include "portdrv.h"
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 005786416bb5..fce2cb2112d8 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -669,6 +669,7 @@ static void pci_release_dev(struct device *dev)
669 669
670/** 670/**
671 * pci_cfg_space_size - get the configuration space size of the PCI device. 671 * pci_cfg_space_size - get the configuration space size of the PCI device.
672 * @dev: PCI device
672 * 673 *
673 * Regular PCI devices have 256 bytes, but PCI-X 2 and PCI Express devices 674 * Regular PCI devices have 256 bytes, but PCI-X 2 and PCI Express devices
674 * have 4096 bytes. Even if the device is capable, that doesn't mean we can 675 * have 4096 bytes. Even if the device is capable, that doesn't mean we can
diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
index 9613f666c110..9eb465727fce 100644
--- a/drivers/pci/proc.c
+++ b/drivers/pci/proc.c
@@ -80,7 +80,7 @@ proc_bus_pci_read(struct file *file, char __user *buf, size_t nbytes, loff_t *pp
80 80
81 if ((pos & 1) && cnt) { 81 if ((pos & 1) && cnt) {
82 unsigned char val; 82 unsigned char val;
83 pci_read_config_byte(dev, pos, &val); 83 pci_user_read_config_byte(dev, pos, &val);
84 __put_user(val, buf); 84 __put_user(val, buf);
85 buf++; 85 buf++;
86 pos++; 86 pos++;
@@ -89,7 +89,7 @@ proc_bus_pci_read(struct file *file, char __user *buf, size_t nbytes, loff_t *pp
89 89
90 if ((pos & 3) && cnt > 2) { 90 if ((pos & 3) && cnt > 2) {
91 unsigned short val; 91 unsigned short val;
92 pci_read_config_word(dev, pos, &val); 92 pci_user_read_config_word(dev, pos, &val);
93 __put_user(cpu_to_le16(val), (unsigned short __user *) buf); 93 __put_user(cpu_to_le16(val), (unsigned short __user *) buf);
94 buf += 2; 94 buf += 2;
95 pos += 2; 95 pos += 2;
@@ -98,7 +98,7 @@ proc_bus_pci_read(struct file *file, char __user *buf, size_t nbytes, loff_t *pp
98 98
99 while (cnt >= 4) { 99 while (cnt >= 4) {
100 unsigned int val; 100 unsigned int val;
101 pci_read_config_dword(dev, pos, &val); 101 pci_user_read_config_dword(dev, pos, &val);
102 __put_user(cpu_to_le32(val), (unsigned int __user *) buf); 102 __put_user(cpu_to_le32(val), (unsigned int __user *) buf);
103 buf += 4; 103 buf += 4;
104 pos += 4; 104 pos += 4;
@@ -107,7 +107,7 @@ proc_bus_pci_read(struct file *file, char __user *buf, size_t nbytes, loff_t *pp
107 107
108 if (cnt >= 2) { 108 if (cnt >= 2) {
109 unsigned short val; 109 unsigned short val;
110 pci_read_config_word(dev, pos, &val); 110 pci_user_read_config_word(dev, pos, &val);
111 __put_user(cpu_to_le16(val), (unsigned short __user *) buf); 111 __put_user(cpu_to_le16(val), (unsigned short __user *) buf);
112 buf += 2; 112 buf += 2;
113 pos += 2; 113 pos += 2;
@@ -116,7 +116,7 @@ proc_bus_pci_read(struct file *file, char __user *buf, size_t nbytes, loff_t *pp
116 116
117 if (cnt) { 117 if (cnt) {
118 unsigned char val; 118 unsigned char val;
119 pci_read_config_byte(dev, pos, &val); 119 pci_user_read_config_byte(dev, pos, &val);
120 __put_user(val, buf); 120 __put_user(val, buf);
121 buf++; 121 buf++;
122 pos++; 122 pos++;
@@ -151,7 +151,7 @@ proc_bus_pci_write(struct file *file, const char __user *buf, size_t nbytes, lof
151 if ((pos & 1) && cnt) { 151 if ((pos & 1) && cnt) {
152 unsigned char val; 152 unsigned char val;
153 __get_user(val, buf); 153 __get_user(val, buf);
154 pci_write_config_byte(dev, pos, val); 154 pci_user_write_config_byte(dev, pos, val);
155 buf++; 155 buf++;
156 pos++; 156 pos++;
157 cnt--; 157 cnt--;
@@ -160,7 +160,7 @@ proc_bus_pci_write(struct file *file, const char __user *buf, size_t nbytes, lof
160 if ((pos & 3) && cnt > 2) { 160 if ((pos & 3) && cnt > 2) {
161 unsigned short val; 161 unsigned short val;
162 __get_user(val, (unsigned short __user *) buf); 162 __get_user(val, (unsigned short __user *) buf);
163 pci_write_config_word(dev, pos, le16_to_cpu(val)); 163 pci_user_write_config_word(dev, pos, le16_to_cpu(val));
164 buf += 2; 164 buf += 2;
165 pos += 2; 165 pos += 2;
166 cnt -= 2; 166 cnt -= 2;
@@ -169,7 +169,7 @@ proc_bus_pci_write(struct file *file, const char __user *buf, size_t nbytes, lof
169 while (cnt >= 4) { 169 while (cnt >= 4) {
170 unsigned int val; 170 unsigned int val;
171 __get_user(val, (unsigned int __user *) buf); 171 __get_user(val, (unsigned int __user *) buf);
172 pci_write_config_dword(dev, pos, le32_to_cpu(val)); 172 pci_user_write_config_dword(dev, pos, le32_to_cpu(val));
173 buf += 4; 173 buf += 4;
174 pos += 4; 174 pos += 4;
175 cnt -= 4; 175 cnt -= 4;
@@ -178,7 +178,7 @@ proc_bus_pci_write(struct file *file, const char __user *buf, size_t nbytes, lof
178 if (cnt >= 2) { 178 if (cnt >= 2) {
179 unsigned short val; 179 unsigned short val;
180 __get_user(val, (unsigned short __user *) buf); 180 __get_user(val, (unsigned short __user *) buf);
181 pci_write_config_word(dev, pos, le16_to_cpu(val)); 181 pci_user_write_config_word(dev, pos, le16_to_cpu(val));
182 buf += 2; 182 buf += 2;
183 pos += 2; 183 pos += 2;
184 cnt -= 2; 184 cnt -= 2;
@@ -187,7 +187,7 @@ proc_bus_pci_write(struct file *file, const char __user *buf, size_t nbytes, lof
187 if (cnt) { 187 if (cnt) {
188 unsigned char val; 188 unsigned char val;
189 __get_user(val, buf); 189 __get_user(val, buf);
190 pci_write_config_byte(dev, pos, val); 190 pci_user_write_config_byte(dev, pos, val);
191 buf++; 191 buf++;
192 pos++; 192 pos++;
193 cnt--; 193 cnt--;
@@ -484,10 +484,10 @@ static int show_dev_config(struct seq_file *m, void *v)
484 484
485 drv = pci_dev_driver(dev); 485 drv = pci_dev_driver(dev);
486 486
487 pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev); 487 pci_user_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
488 pci_read_config_byte (dev, PCI_LATENCY_TIMER, &latency); 488 pci_user_read_config_byte (dev, PCI_LATENCY_TIMER, &latency);
489 pci_read_config_byte (dev, PCI_MIN_GNT, &min_gnt); 489 pci_user_read_config_byte (dev, PCI_MIN_GNT, &min_gnt);
490 pci_read_config_byte (dev, PCI_MAX_LAT, &max_lat); 490 pci_user_read_config_byte (dev, PCI_MAX_LAT, &max_lat);
491 seq_printf(m, " Bus %2d, device %3d, function %2d:\n", 491 seq_printf(m, " Bus %2d, device %3d, function %2d:\n",
492 dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)); 492 dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
493 seq_printf(m, " Class %04x", class_rev >> 16); 493 seq_printf(m, " Class %04x", class_rev >> 16);
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 7992bc8cc6a4..5627ce1d2b32 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -7,6 +7,9 @@
7 * 7 *
8 * Copyright (c) 1999 Martin Mares <mj@ucw.cz> 8 * Copyright (c) 1999 Martin Mares <mj@ucw.cz>
9 * 9 *
10 * Init/reset quirks for USB host controllers should be in the
11 * USB quirks file, where their drivers can access reuse it.
12 *
10 * The bridge optimization stuff has been removed. If you really 13 * The bridge optimization stuff has been removed. If you really
11 * have a silly BIOS which is unable to set your host bridge right, 14 * have a silly BIOS which is unable to set your host bridge right,
12 * use the PowerTweak utility (see http://powertweak.sourceforge.net). 15 * use the PowerTweak utility (see http://powertweak.sourceforge.net).
@@ -353,7 +356,7 @@ static void piix4_mem_quirk(struct pci_dev *dev, const char *name, unsigned int
353/* 356/*
354 * PIIX4 ACPI: Two IO regions pointed to by longwords at 357 * PIIX4 ACPI: Two IO regions pointed to by longwords at
355 * 0x40 (64 bytes of ACPI registers) 358 * 0x40 (64 bytes of ACPI registers)
356 * 0x90 (32 bytes of SMB registers) 359 * 0x90 (16 bytes of SMB registers)
357 * and a few strange programmable PIIX4 device resources. 360 * and a few strange programmable PIIX4 device resources.
358 */ 361 */
359static void __devinit quirk_piix4_acpi(struct pci_dev *dev) 362static void __devinit quirk_piix4_acpi(struct pci_dev *dev)
@@ -363,7 +366,7 @@ static void __devinit quirk_piix4_acpi(struct pci_dev *dev)
363 pci_read_config_dword(dev, 0x40, &region); 366 pci_read_config_dword(dev, 0x40, &region);
364 quirk_io_region(dev, region, 64, PCI_BRIDGE_RESOURCES, "PIIX4 ACPI"); 367 quirk_io_region(dev, region, 64, PCI_BRIDGE_RESOURCES, "PIIX4 ACPI");
365 pci_read_config_dword(dev, 0x90, &region); 368 pci_read_config_dword(dev, 0x90, &region);
366 quirk_io_region(dev, region, 32, PCI_BRIDGE_RESOURCES+1, "PIIX4 SMB"); 369 quirk_io_region(dev, region, 16, PCI_BRIDGE_RESOURCES+1, "PIIX4 SMB");
367 370
368 /* Device resource A has enables for some of the other ones */ 371 /* Device resource A has enables for some of the other ones */
369 pci_read_config_dword(dev, 0x5c, &res_a); 372 pci_read_config_dword(dev, 0x5c, &res_a);
@@ -414,6 +417,18 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12,
414DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, quirk_ich4_lpc_acpi ); 417DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, quirk_ich4_lpc_acpi );
415DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1, quirk_ich4_lpc_acpi ); 418DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1, quirk_ich4_lpc_acpi );
416 419
420static void __devinit quirk_ich6_lpc_acpi(struct pci_dev *dev)
421{
422 u32 region;
423
424 pci_read_config_dword(dev, 0x40, &region);
425 quirk_io_region(dev, region, 128, PCI_BRIDGE_RESOURCES, "ICH6 ACPI/GPIO/TCO");
426
427 pci_read_config_dword(dev, 0x48, &region);
428 quirk_io_region(dev, region, 64, PCI_BRIDGE_RESOURCES+1, "ICH6 GPIO");
429}
430DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, quirk_ich6_lpc_acpi );
431
417/* 432/*
418 * VIA ACPI: One IO region pointed to by longword at 433 * VIA ACPI: One IO region pointed to by longword at
419 * 0x48 or 0x20 (256 bytes of ACPI registers) 434 * 0x48 or 0x20 (256 bytes of ACPI registers)
@@ -633,28 +648,6 @@ static void quirk_via_irq(struct pci_dev *dev)
633DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_ANY_ID, quirk_via_irq); 648DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_ANY_ID, quirk_via_irq);
634 649
635/* 650/*
636 * PIIX3 USB: We have to disable USB interrupts that are
637 * hardwired to PIRQD# and may be shared with an
638 * external device.
639 *
640 * Legacy Support Register (LEGSUP):
641 * bit13: USB PIRQ Enable (USBPIRQDEN),
642 * bit4: Trap/SMI On IRQ Enable (USBSMIEN).
643 *
644 * We mask out all r/wc bits, too.
645 */
646static void __devinit quirk_piix3_usb(struct pci_dev *dev)
647{
648 u16 legsup;
649
650 pci_read_config_word(dev, 0xc0, &legsup);
651 legsup &= 0x50ef;
652 pci_write_config_word(dev, 0xc0, legsup);
653}
654DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371SB_2, quirk_piix3_usb );
655DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_2, quirk_piix3_usb );
656
657/*
658 * VIA VT82C598 has its device ID settable and many BIOSes 651 * VIA VT82C598 has its device ID settable and many BIOSes
659 * set it to the ID of VT82C597 for backward compatibility. 652 * set it to the ID of VT82C597 for backward compatibility.
660 * We need to switch it off to be able to recognize the real 653 * We need to switch it off to be able to recognize the real
@@ -922,6 +915,12 @@ static void __init asus_hides_smbus_hostbridge(struct pci_dev *dev)
922 case 0x186a: /* M6Ne notebook */ 915 case 0x186a: /* M6Ne notebook */
923 asus_hides_smbus = 1; 916 asus_hides_smbus = 1;
924 } 917 }
918 if (dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB) {
919 switch (dev->subsystem_device) {
920 case 0x1882: /* M6V notebook */
921 asus_hides_smbus = 1;
922 }
923 }
925 } else if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_HP)) { 924 } else if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_HP)) {
926 if (dev->device == PCI_DEVICE_ID_INTEL_82855PM_HB) 925 if (dev->device == PCI_DEVICE_ID_INTEL_82855PM_HB)
927 switch(dev->subsystem_device) { 926 switch(dev->subsystem_device) {
@@ -932,6 +931,7 @@ static void __init asus_hides_smbus_hostbridge(struct pci_dev *dev)
932 if (dev->device == PCI_DEVICE_ID_INTEL_82865_HB) 931 if (dev->device == PCI_DEVICE_ID_INTEL_82865_HB)
933 switch (dev->subsystem_device) { 932 switch (dev->subsystem_device) {
934 case 0x12bc: /* HP D330L */ 933 case 0x12bc: /* HP D330L */
934 case 0x12bd: /* HP D530 */
935 asus_hides_smbus = 1; 935 asus_hides_smbus = 1;
936 } 936 }
937 } else if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_TOSHIBA)) { 937 } else if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_TOSHIBA)) {
@@ -966,6 +966,7 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82865_HB, asus
966DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_7205_0, asus_hides_smbus_hostbridge ); 966DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_7205_0, asus_hides_smbus_hostbridge );
967DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82855PM_HB, asus_hides_smbus_hostbridge ); 967DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82855PM_HB, asus_hides_smbus_hostbridge );
968DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82855GM_HB, asus_hides_smbus_hostbridge ); 968DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82855GM_HB, asus_hides_smbus_hostbridge );
969DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82915GM_HB, asus_hides_smbus_hostbridge );
969 970
970static void __init asus_hides_smbus_lpc(struct pci_dev *dev) 971static void __init asus_hides_smbus_lpc(struct pci_dev *dev)
971{ 972{
@@ -990,6 +991,23 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, as
990DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc ); 991DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc );
991DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc ); 992DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc );
992 993
994static void __init asus_hides_smbus_lpc_ich6(struct pci_dev *dev)
995{
996 u32 val, rcba;
997 void __iomem *base;
998
999 if (likely(!asus_hides_smbus))
1000 return;
1001 pci_read_config_dword(dev, 0xF0, &rcba);
1002 base = ioremap_nocache(rcba & 0xFFFFC000, 0x4000); /* use bits 31:14, 16 kB aligned */
1003 if (base == NULL) return;
1004 val=readl(base + 0x3418); /* read the Function Disable register, dword mode only */
1005 writel(val & 0xFFFFFFF7, base + 0x3418); /* enable the SMBus device */
1006 iounmap(base);
1007 printk(KERN_INFO "PCI: Enabled ICH6/i801 SMBus device\n");
1008}
1009DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6 );
1010
993/* 1011/*
994 * SiS 96x south bridge: BIOS typically hides SMBus device... 1012 * SiS 96x south bridge: BIOS typically hides SMBus device...
995 */ 1013 */
@@ -1002,234 +1020,6 @@ static void __init quirk_sis_96x_smbus(struct pci_dev *dev)
1002 pci_read_config_byte(dev, 0x77, &val); 1020 pci_read_config_byte(dev, 0x77, &val);
1003} 1021}
1004 1022
1005
1006#define UHCI_USBLEGSUP 0xc0 /* legacy support */
1007#define UHCI_USBCMD 0 /* command register */
1008#define UHCI_USBSTS 2 /* status register */
1009#define UHCI_USBINTR 4 /* interrupt register */
1010#define UHCI_USBLEGSUP_DEFAULT 0x2000 /* only PIRQ enable set */
1011#define UHCI_USBCMD_RUN (1 << 0) /* RUN/STOP bit */
1012#define UHCI_USBCMD_GRESET (1 << 2) /* Global reset */
1013#define UHCI_USBCMD_CONFIGURE (1 << 6) /* config semaphore */
1014#define UHCI_USBSTS_HALTED (1 << 5) /* HCHalted bit */
1015
1016#define OHCI_CONTROL 0x04
1017#define OHCI_CMDSTATUS 0x08
1018#define OHCI_INTRSTATUS 0x0c
1019#define OHCI_INTRENABLE 0x10
1020#define OHCI_INTRDISABLE 0x14
1021#define OHCI_OCR (1 << 3) /* ownership change request */
1022#define OHCI_CTRL_IR (1 << 8) /* interrupt routing */
1023#define OHCI_INTR_OC (1 << 30) /* ownership change */
1024
1025#define EHCI_HCC_PARAMS 0x08 /* extended capabilities */
1026#define EHCI_USBCMD 0 /* command register */
1027#define EHCI_USBCMD_RUN (1 << 0) /* RUN/STOP bit */
1028#define EHCI_USBSTS 4 /* status register */
1029#define EHCI_USBSTS_HALTED (1 << 12) /* HCHalted bit */
1030#define EHCI_USBINTR 8 /* interrupt register */
1031#define EHCI_USBLEGSUP 0 /* legacy support register */
1032#define EHCI_USBLEGSUP_BIOS (1 << 16) /* BIOS semaphore */
1033#define EHCI_USBLEGSUP_OS (1 << 24) /* OS semaphore */
1034#define EHCI_USBLEGCTLSTS 4 /* legacy control/status */
1035#define EHCI_USBLEGCTLSTS_SOOE (1 << 13) /* SMI on ownership change */
1036
1037int usb_early_handoff __devinitdata = 0;
1038static int __init usb_handoff_early(char *str)
1039{
1040 usb_early_handoff = 1;
1041 return 0;
1042}
1043__setup("usb-handoff", usb_handoff_early);
1044
1045static void __devinit quirk_usb_handoff_uhci(struct pci_dev *pdev)
1046{
1047 unsigned long base = 0;
1048 int wait_time, delta;
1049 u16 val, sts;
1050 int i;
1051
1052 for (i = 0; i < PCI_ROM_RESOURCE; i++)
1053 if ((pci_resource_flags(pdev, i) & IORESOURCE_IO)) {
1054 base = pci_resource_start(pdev, i);
1055 break;
1056 }
1057
1058 if (!base)
1059 return;
1060
1061 /*
1062 * stop controller
1063 */
1064 sts = inw(base + UHCI_USBSTS);
1065 val = inw(base + UHCI_USBCMD);
1066 val &= ~(u16)(UHCI_USBCMD_RUN | UHCI_USBCMD_CONFIGURE);
1067 outw(val, base + UHCI_USBCMD);
1068
1069 /*
1070 * wait while it stops if it was running
1071 */
1072 if ((sts & UHCI_USBSTS_HALTED) == 0)
1073 {
1074 wait_time = 1000;
1075 delta = 100;
1076
1077 do {
1078 outw(0x1f, base + UHCI_USBSTS);
1079 udelay(delta);
1080 wait_time -= delta;
1081 val = inw(base + UHCI_USBSTS);
1082 if (val & UHCI_USBSTS_HALTED)
1083 break;
1084 } while (wait_time > 0);
1085 }
1086
1087 /*
1088 * disable interrupts & legacy support
1089 */
1090 outw(0, base + UHCI_USBINTR);
1091 outw(0x1f, base + UHCI_USBSTS);
1092 pci_read_config_word(pdev, UHCI_USBLEGSUP, &val);
1093 if (val & 0xbf)
1094 pci_write_config_word(pdev, UHCI_USBLEGSUP, UHCI_USBLEGSUP_DEFAULT);
1095
1096}
1097
1098static void __devinit quirk_usb_handoff_ohci(struct pci_dev *pdev)
1099{
1100 void __iomem *base;
1101 int wait_time;
1102
1103 base = ioremap_nocache(pci_resource_start(pdev, 0),
1104 pci_resource_len(pdev, 0));
1105 if (base == NULL) return;
1106
1107 if (readl(base + OHCI_CONTROL) & OHCI_CTRL_IR) {
1108 wait_time = 500; /* 0.5 seconds */
1109 writel(OHCI_INTR_OC, base + OHCI_INTRENABLE);
1110 writel(OHCI_OCR, base + OHCI_CMDSTATUS);
1111 while (wait_time > 0 &&
1112 readl(base + OHCI_CONTROL) & OHCI_CTRL_IR) {
1113 wait_time -= 10;
1114 msleep(10);
1115 }
1116 }
1117
1118 /*
1119 * disable interrupts
1120 */
1121 writel(~(u32)0, base + OHCI_INTRDISABLE);
1122 writel(~(u32)0, base + OHCI_INTRSTATUS);
1123
1124 iounmap(base);
1125}
1126
1127static void __devinit quirk_usb_disable_ehci(struct pci_dev *pdev)
1128{
1129 int wait_time, delta;
1130 void __iomem *base, *op_reg_base;
1131 u32 hcc_params, val, temp;
1132 u8 cap_length;
1133
1134 base = ioremap_nocache(pci_resource_start(pdev, 0),
1135 pci_resource_len(pdev, 0));
1136 if (base == NULL) return;
1137
1138 cap_length = readb(base);
1139 op_reg_base = base + cap_length;
1140 hcc_params = readl(base + EHCI_HCC_PARAMS);
1141 hcc_params = (hcc_params >> 8) & 0xff;
1142 if (hcc_params) {
1143 pci_read_config_dword(pdev,
1144 hcc_params + EHCI_USBLEGSUP,
1145 &val);
1146 if (((val & 0xff) == 1) && (val & EHCI_USBLEGSUP_BIOS)) {
1147 /*
1148 * Ok, BIOS is in smm mode, try to hand off...
1149 */
1150 pci_read_config_dword(pdev,
1151 hcc_params + EHCI_USBLEGCTLSTS,
1152 &temp);
1153 pci_write_config_dword(pdev,
1154 hcc_params + EHCI_USBLEGCTLSTS,
1155 temp | EHCI_USBLEGCTLSTS_SOOE);
1156 val |= EHCI_USBLEGSUP_OS;
1157 pci_write_config_dword(pdev,
1158 hcc_params + EHCI_USBLEGSUP,
1159 val);
1160
1161 wait_time = 500;
1162 do {
1163 msleep(10);
1164 wait_time -= 10;
1165 pci_read_config_dword(pdev,
1166 hcc_params + EHCI_USBLEGSUP,
1167 &val);
1168 } while (wait_time && (val & EHCI_USBLEGSUP_BIOS));
1169 if (!wait_time) {
1170 /*
1171 * well, possibly buggy BIOS...
1172 */
1173 printk(KERN_WARNING "EHCI early BIOS handoff "
1174 "failed (BIOS bug ?)\n");
1175 pci_write_config_dword(pdev,
1176 hcc_params + EHCI_USBLEGSUP,
1177 EHCI_USBLEGSUP_OS);
1178 pci_write_config_dword(pdev,
1179 hcc_params + EHCI_USBLEGCTLSTS,
1180 0);
1181 }
1182 }
1183 }
1184
1185 /*
1186 * halt EHCI & disable its interrupts in any case
1187 */
1188 val = readl(op_reg_base + EHCI_USBSTS);
1189 if ((val & EHCI_USBSTS_HALTED) == 0) {
1190 val = readl(op_reg_base + EHCI_USBCMD);
1191 val &= ~EHCI_USBCMD_RUN;
1192 writel(val, op_reg_base + EHCI_USBCMD);
1193
1194 wait_time = 2000;
1195 delta = 100;
1196 do {
1197 writel(0x3f, op_reg_base + EHCI_USBSTS);
1198 udelay(delta);
1199 wait_time -= delta;
1200 val = readl(op_reg_base + EHCI_USBSTS);
1201 if ((val == ~(u32)0) || (val & EHCI_USBSTS_HALTED)) {
1202 break;
1203 }
1204 } while (wait_time > 0);
1205 }
1206 writel(0, op_reg_base + EHCI_USBINTR);
1207 writel(0x3f, op_reg_base + EHCI_USBSTS);
1208
1209 iounmap(base);
1210
1211 return;
1212}
1213
1214
1215
1216static void __devinit quirk_usb_early_handoff(struct pci_dev *pdev)
1217{
1218 if (!usb_early_handoff)
1219 return;
1220
1221 if (pdev->class == ((PCI_CLASS_SERIAL_USB << 8) | 0x00)) { /* UHCI */
1222 quirk_usb_handoff_uhci(pdev);
1223 } else if (pdev->class == ((PCI_CLASS_SERIAL_USB << 8) | 0x10)) { /* OHCI */
1224 quirk_usb_handoff_ohci(pdev);
1225 } else if (pdev->class == ((PCI_CLASS_SERIAL_USB << 8) | 0x20)) { /* EHCI */
1226 quirk_usb_disable_ehci(pdev);
1227 }
1228
1229 return;
1230}
1231DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, quirk_usb_early_handoff);
1232
1233/* 1023/*
1234 * ... This is further complicated by the fact that some SiS96x south 1024 * ... This is further complicated by the fact that some SiS96x south
1235 * bridges pretend to be 85C503/5513 instead. In that case see if we 1025 * bridges pretend to be 85C503/5513 instead. In that case see if we
diff --git a/drivers/pci/rom.c b/drivers/pci/rom.c
index 49bd21702314..598a115cd00e 100644
--- a/drivers/pci/rom.c
+++ b/drivers/pci/rom.c
@@ -9,6 +9,7 @@
9#include <linux/config.h> 9#include <linux/config.h>
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/pci.h> 11#include <linux/pci.h>
12#include <linux/slab.h>
12 13
13#include "pci.h" 14#include "pci.h"
14 15
diff --git a/drivers/pci/syscall.c b/drivers/pci/syscall.c
index c071790cc983..87fafc08cb9d 100644
--- a/drivers/pci/syscall.c
+++ b/drivers/pci/syscall.c
@@ -13,7 +13,7 @@
13#include <linux/smp_lock.h> 13#include <linux/smp_lock.h>
14#include <linux/syscalls.h> 14#include <linux/syscalls.h>
15#include <asm/uaccess.h> 15#include <asm/uaccess.h>
16 16#include "pci.h"
17 17
18asmlinkage long 18asmlinkage long
19sys_pciconfig_read(unsigned long bus, unsigned long dfn, 19sys_pciconfig_read(unsigned long bus, unsigned long dfn,
@@ -38,13 +38,13 @@ sys_pciconfig_read(unsigned long bus, unsigned long dfn,
38 lock_kernel(); 38 lock_kernel();
39 switch (len) { 39 switch (len) {
40 case 1: 40 case 1:
41 cfg_ret = pci_read_config_byte(dev, off, &byte); 41 cfg_ret = pci_user_read_config_byte(dev, off, &byte);
42 break; 42 break;
43 case 2: 43 case 2:
44 cfg_ret = pci_read_config_word(dev, off, &word); 44 cfg_ret = pci_user_read_config_word(dev, off, &word);
45 break; 45 break;
46 case 4: 46 case 4:
47 cfg_ret = pci_read_config_dword(dev, off, &dword); 47 cfg_ret = pci_user_read_config_dword(dev, off, &dword);
48 break; 48 break;
49 default: 49 default:
50 err = -EINVAL; 50 err = -EINVAL;
@@ -112,7 +112,7 @@ sys_pciconfig_write(unsigned long bus, unsigned long dfn,
112 err = get_user(byte, (u8 __user *)buf); 112 err = get_user(byte, (u8 __user *)buf);
113 if (err) 113 if (err)
114 break; 114 break;
115 err = pci_write_config_byte(dev, off, byte); 115 err = pci_user_write_config_byte(dev, off, byte);
116 if (err != PCIBIOS_SUCCESSFUL) 116 if (err != PCIBIOS_SUCCESSFUL)
117 err = -EIO; 117 err = -EIO;
118 break; 118 break;
@@ -121,7 +121,7 @@ sys_pciconfig_write(unsigned long bus, unsigned long dfn,
121 err = get_user(word, (u16 __user *)buf); 121 err = get_user(word, (u16 __user *)buf);
122 if (err) 122 if (err)
123 break; 123 break;
124 err = pci_write_config_word(dev, off, word); 124 err = pci_user_write_config_word(dev, off, word);
125 if (err != PCIBIOS_SUCCESSFUL) 125 if (err != PCIBIOS_SUCCESSFUL)
126 err = -EIO; 126 err = -EIO;
127 break; 127 break;
@@ -130,7 +130,7 @@ sys_pciconfig_write(unsigned long bus, unsigned long dfn,
130 err = get_user(dword, (u32 __user *)buf); 130 err = get_user(dword, (u32 __user *)buf);
131 if (err) 131 if (err)
132 break; 132 break;
133 err = pci_write_config_dword(dev, off, dword); 133 err = pci_user_write_config_dword(dev, off, dword);
134 if (err != PCIBIOS_SUCCESSFUL) 134 if (err != PCIBIOS_SUCCESSFUL)
135 err = -EIO; 135 err = -EIO;
136 break; 136 break;
diff --git a/drivers/pcmcia/Makefile b/drivers/pcmcia/Makefile
index cb4861d9cb80..fe37541abbfe 100644
--- a/drivers/pcmcia/Makefile
+++ b/drivers/pcmcia/Makefile
@@ -43,9 +43,11 @@ pxa2xx_core-y += soc_common.o pxa2xx_base.o
43au1x00_ss-y += au1000_generic.o 43au1x00_ss-y += au1000_generic.o
44au1x00_ss-$(CONFIG_MIPS_PB1000) += au1000_pb1x00.o 44au1x00_ss-$(CONFIG_MIPS_PB1000) += au1000_pb1x00.o
45au1x00_ss-$(CONFIG_MIPS_PB1100) += au1000_pb1x00.o 45au1x00_ss-$(CONFIG_MIPS_PB1100) += au1000_pb1x00.o
46au1x00_ss-$(CONFIG_MIPS_PB1200) += au1000_db1x00.o
46au1x00_ss-$(CONFIG_MIPS_PB1500) += au1000_pb1x00.o 47au1x00_ss-$(CONFIG_MIPS_PB1500) += au1000_pb1x00.o
47au1x00_ss-$(CONFIG_MIPS_DB1000) += au1000_db1x00.o 48au1x00_ss-$(CONFIG_MIPS_DB1000) += au1000_db1x00.o
48au1x00_ss-$(CONFIG_MIPS_DB1100) += au1000_db1x00.o 49au1x00_ss-$(CONFIG_MIPS_DB1100) += au1000_db1x00.o
50au1x00_ss-$(CONFIG_MIPS_DB1200) += au1000_db1x00.o
49au1x00_ss-$(CONFIG_MIPS_DB1500) += au1000_db1x00.o 51au1x00_ss-$(CONFIG_MIPS_DB1500) += au1000_db1x00.o
50au1x00_ss-$(CONFIG_MIPS_DB1550) += au1000_db1x00.o 52au1x00_ss-$(CONFIG_MIPS_DB1550) += au1000_db1x00.o
51au1x00_ss-$(CONFIG_MIPS_XXS1500) += au1000_xxs1500.o 53au1x00_ss-$(CONFIG_MIPS_XXS1500) += au1000_xxs1500.o
@@ -58,6 +60,7 @@ sa1111_cs-$(CONFIG_SA1100_JORNADA720) += sa1100_jornada720.o
58sa1100_cs-y += sa1100_generic.o 60sa1100_cs-y += sa1100_generic.o
59sa1100_cs-$(CONFIG_SA1100_ASSABET) += sa1100_assabet.o 61sa1100_cs-$(CONFIG_SA1100_ASSABET) += sa1100_assabet.o
60sa1100_cs-$(CONFIG_SA1100_CERF) += sa1100_cerf.o 62sa1100_cs-$(CONFIG_SA1100_CERF) += sa1100_cerf.o
63sa1100_cs-$(CONFIG_SA1100_COLLIE) += pxa2xx_sharpsl.o
61sa1100_cs-$(CONFIG_SA1100_H3600) += sa1100_h3600.o 64sa1100_cs-$(CONFIG_SA1100_H3600) += sa1100_h3600.o
62sa1100_cs-$(CONFIG_SA1100_SHANNON) += sa1100_shannon.o 65sa1100_cs-$(CONFIG_SA1100_SHANNON) += sa1100_shannon.o
63sa1100_cs-$(CONFIG_SA1100_SIMPAD) += sa1100_simpad.o 66sa1100_cs-$(CONFIG_SA1100_SIMPAD) += sa1100_simpad.o
diff --git a/drivers/pcmcia/au1000_db1x00.c b/drivers/pcmcia/au1000_db1x00.c
index 42cf8bfbcc98..24cfee1a412c 100644
--- a/drivers/pcmcia/au1000_db1x00.c
+++ b/drivers/pcmcia/au1000_db1x00.c
@@ -40,7 +40,15 @@
40#include <asm/irq.h> 40#include <asm/irq.h>
41#include <asm/signal.h> 41#include <asm/signal.h>
42#include <asm/mach-au1x00/au1000.h> 42#include <asm/mach-au1x00/au1000.h>
43#include <asm/mach-db1x00/db1x00.h> 43
44#if defined(CONFIG_MIPS_DB1200)
45 #include <db1200.h>
46#elif defined(CONFIG_MIPS_PB1200)
47 #include <pb1200.h>
48#else
49 #include <asm/mach-db1x00/db1x00.h>
50 static BCSR * const bcsr = (BCSR *)BCSR_KSEG1_ADDR;
51#endif
44 52
45#include "au1000_generic.h" 53#include "au1000_generic.h"
46 54
@@ -50,7 +58,6 @@
50#define debug(x,args...) 58#define debug(x,args...)
51#endif 59#endif
52 60
53static BCSR * const bcsr = (BCSR *)BCSR_KSEG1_ADDR;
54 61
55struct au1000_pcmcia_socket au1000_pcmcia_socket[PCMCIA_NUM_SOCKS]; 62struct au1000_pcmcia_socket au1000_pcmcia_socket[PCMCIA_NUM_SOCKS];
56extern int au1x00_pcmcia_socket_probe(struct device *, struct pcmcia_low_level *, int, int); 63extern int au1x00_pcmcia_socket_probe(struct device *, struct pcmcia_low_level *, int, int);
@@ -59,6 +66,8 @@ static int db1x00_pcmcia_hw_init(struct au1000_pcmcia_socket *skt)
59{ 66{
60#ifdef CONFIG_MIPS_DB1550 67#ifdef CONFIG_MIPS_DB1550
61 skt->irq = skt->nr ? AU1000_GPIO_5 : AU1000_GPIO_3; 68 skt->irq = skt->nr ? AU1000_GPIO_5 : AU1000_GPIO_3;
69#elif defined(CONFIG_MIPS_DB1200) || defined(CONFIG_MIPS_PB1200)
70 skt->irq = skt->nr ? BOARD_PC1_INT : BOARD_PC0_INT;
62#else 71#else
63 skt->irq = skt->nr ? AU1000_GPIO_5 : AU1000_GPIO_2; 72 skt->irq = skt->nr ? AU1000_GPIO_5 : AU1000_GPIO_2;
64#endif 73#endif
@@ -85,11 +94,19 @@ db1x00_pcmcia_socket_state(struct au1000_pcmcia_socket *skt, struct pcmcia_state
85 switch (skt->nr) { 94 switch (skt->nr) {
86 case 0: 95 case 0:
87 vs = bcsr->status & 0x3; 96 vs = bcsr->status & 0x3;
97#if defined(CONFIG_MIPS_DB1200) || defined(CONFIG_MIPS_PB1200)
98 inserted = BOARD_CARD_INSERTED(0);
99#else
88 inserted = !(bcsr->status & (1<<4)); 100 inserted = !(bcsr->status & (1<<4));
101#endif
89 break; 102 break;
90 case 1: 103 case 1:
91 vs = (bcsr->status & 0xC)>>2; 104 vs = (bcsr->status & 0xC)>>2;
105#if defined(CONFIG_MIPS_DB1200) || defined(CONFIG_MIPS_PB1200)
106 inserted = BOARD_CARD_INSERTED(1);
107#else
92 inserted = !(bcsr->status & (1<<5)); 108 inserted = !(bcsr->status & (1<<5));
109#endif
93 break; 110 break;
94 default:/* should never happen */ 111 default:/* should never happen */
95 return; 112 return;
diff --git a/drivers/pcmcia/au1000_generic.c b/drivers/pcmcia/au1000_generic.c
index 470ef756252e..ba48cef3a9dc 100644
--- a/drivers/pcmcia/au1000_generic.c
+++ b/drivers/pcmcia/au1000_generic.c
@@ -490,7 +490,7 @@ int au1x00_drv_pcmcia_remove(struct device *dev)
490 flush_scheduled_work(); 490 flush_scheduled_work();
491 skt->ops->hw_shutdown(skt); 491 skt->ops->hw_shutdown(skt);
492 au1x00_pcmcia_config_skt(skt, &dead_socket); 492 au1x00_pcmcia_config_skt(skt, &dead_socket);
493 iounmap(skt->virt_io); 493 iounmap(skt->virt_io + (u32)mips_io_port_base);
494 skt->virt_io = NULL; 494 skt->virt_io = NULL;
495 } 495 }
496 496
@@ -519,36 +519,15 @@ static int au1x00_drv_pcmcia_probe(struct device *dev)
519} 519}
520 520
521 521
522static int au1x00_drv_pcmcia_suspend(struct device *dev, pm_message_t state, u32 level)
523{
524 int ret = 0;
525 if (level == SUSPEND_SAVE_STATE)
526 ret = pcmcia_socket_dev_suspend(dev, state);
527 return ret;
528}
529
530static int au1x00_drv_pcmcia_resume(struct device *dev, u32 level)
531{
532 int ret = 0;
533 if (level == RESUME_RESTORE_STATE)
534 ret = pcmcia_socket_dev_resume(dev);
535 return ret;
536}
537
538
539static struct device_driver au1x00_pcmcia_driver = { 522static struct device_driver au1x00_pcmcia_driver = {
540 .probe = au1x00_drv_pcmcia_probe, 523 .probe = au1x00_drv_pcmcia_probe,
541 .remove = au1x00_drv_pcmcia_remove, 524 .remove = au1x00_drv_pcmcia_remove,
542 .name = "au1x00-pcmcia", 525 .name = "au1x00-pcmcia",
543 .bus = &platform_bus_type, 526 .bus = &platform_bus_type,
544 .suspend = au1x00_drv_pcmcia_suspend, 527 .suspend = pcmcia_socket_dev_suspend,
545 .resume = au1x00_drv_pcmcia_resume 528 .resume = pcmcia_socket_dev_resume,
546}; 529};
547 530
548static struct platform_device au1x00_device = {
549 .name = "au1x00-pcmcia",
550 .id = 0,
551};
552 531
553/* au1x00_pcmcia_init() 532/* au1x00_pcmcia_init()
554 * 533 *
@@ -562,7 +541,6 @@ static int __init au1x00_pcmcia_init(void)
562 int error = 0; 541 int error = 0;
563 if ((error = driver_register(&au1x00_pcmcia_driver))) 542 if ((error = driver_register(&au1x00_pcmcia_driver)))
564 return error; 543 return error;
565 platform_device_register(&au1x00_device);
566 return error; 544 return error;
567} 545}
568 546
@@ -573,7 +551,6 @@ static int __init au1x00_pcmcia_init(void)
573static void __exit au1x00_pcmcia_exit(void) 551static void __exit au1x00_pcmcia_exit(void)
574{ 552{
575 driver_unregister(&au1x00_pcmcia_driver); 553 driver_unregister(&au1x00_pcmcia_driver);
576 platform_device_unregister(&au1x00_device);
577} 554}
578 555
579module_init(au1x00_pcmcia_init); 556module_init(au1x00_pcmcia_init);
diff --git a/drivers/pcmcia/au1000_generic.h b/drivers/pcmcia/au1000_generic.h
index d5122b1ea94b..b0e7908392a7 100644
--- a/drivers/pcmcia/au1000_generic.h
+++ b/drivers/pcmcia/au1000_generic.h
@@ -44,13 +44,13 @@
44/* pcmcia socket 1 needs external glue logic so the memory map 44/* pcmcia socket 1 needs external glue logic so the memory map
45 * differs from board to board. 45 * differs from board to board.
46 */ 46 */
47#if defined(CONFIG_MIPS_PB1000) || defined(CONFIG_MIPS_PB1100) || defined(CONFIG_MIPS_PB1500) || defined(CONFIG_MIPS_PB1550) 47#if defined(CONFIG_MIPS_PB1000) || defined(CONFIG_MIPS_PB1100) || defined(CONFIG_MIPS_PB1500) || defined(CONFIG_MIPS_PB1550) || defined(CONFIG_MIPS_PB1200)
48#define AU1X_SOCK1_IO 0xF08000000 48#define AU1X_SOCK1_IO 0xF08000000
49#define AU1X_SOCK1_PHYS_ATTR 0xF48000000 49#define AU1X_SOCK1_PHYS_ATTR 0xF48000000
50#define AU1X_SOCK1_PHYS_MEM 0xF88000000 50#define AU1X_SOCK1_PHYS_MEM 0xF88000000
51#define AU1X_SOCK1_PSEUDO_PHYS_ATTR 0xF4800000 51#define AU1X_SOCK1_PSEUDO_PHYS_ATTR 0xF4800000
52#define AU1X_SOCK1_PSEUDO_PHYS_MEM 0xF8800000 52#define AU1X_SOCK1_PSEUDO_PHYS_MEM 0xF8800000
53#elif defined(CONFIG_MIPS_DB1000) || defined(CONFIG_MIPS_DB1100) || defined(CONFIG_MIPS_DB1500) || defined(CONFIG_MIPS_DB1550) 53#elif defined(CONFIG_MIPS_DB1000) || defined(CONFIG_MIPS_DB1100) || defined(CONFIG_MIPS_DB1500) || defined(CONFIG_MIPS_DB1550) || defined(CONFIG_MIPS_DB1200)
54#define AU1X_SOCK1_IO 0xF04000000 54#define AU1X_SOCK1_IO 0xF04000000
55#define AU1X_SOCK1_PHYS_ATTR 0xF44000000 55#define AU1X_SOCK1_PHYS_ATTR 0xF44000000
56#define AU1X_SOCK1_PHYS_MEM 0xF84000000 56#define AU1X_SOCK1_PHYS_MEM 0xF84000000
diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c
index 080608c7381a..39d096b52926 100644
--- a/drivers/pcmcia/ds.c
+++ b/drivers/pcmcia/ds.c
@@ -1157,7 +1157,8 @@ static struct pcmcia_callback pcmcia_bus_callback = {
1157 .requery = pcmcia_bus_rescan, 1157 .requery = pcmcia_bus_rescan,
1158}; 1158};
1159 1159
1160static int __devinit pcmcia_bus_add_socket(struct class_device *class_dev) 1160static int __devinit pcmcia_bus_add_socket(struct class_device *class_dev,
1161 struct class_interface *class_intf)
1161{ 1162{
1162 struct pcmcia_socket *socket = class_get_devdata(class_dev); 1163 struct pcmcia_socket *socket = class_get_devdata(class_dev);
1163 int ret; 1164 int ret;
@@ -1192,7 +1193,8 @@ static int __devinit pcmcia_bus_add_socket(struct class_device *class_dev)
1192 return 0; 1193 return 0;
1193} 1194}
1194 1195
1195static void pcmcia_bus_remove_socket(struct class_device *class_dev) 1196static void pcmcia_bus_remove_socket(struct class_device *class_dev,
1197 struct class_interface *class_intf)
1196{ 1198{
1197 struct pcmcia_socket *socket = class_get_devdata(class_dev); 1199 struct pcmcia_socket *socket = class_get_devdata(class_dev);
1198 1200
diff --git a/drivers/pcmcia/hd64465_ss.c b/drivers/pcmcia/hd64465_ss.c
index 316f8bcc878b..b57a0b98b4d6 100644
--- a/drivers/pcmcia/hd64465_ss.c
+++ b/drivers/pcmcia/hd64465_ss.c
@@ -844,27 +844,11 @@ static void hs_exit_socket(hs_socket_t *sp)
844 local_irq_restore(flags); 844 local_irq_restore(flags);
845} 845}
846 846
847static int hd64465_suspend(struct device *dev, pm_message_t state, u32 level)
848{
849 int ret = 0;
850 if (level == SUSPEND_SAVE_STATE)
851 ret = pcmcia_socket_dev_suspend(dev, state);
852 return ret;
853}
854
855static int hd64465_resume(struct device *dev, u32 level)
856{
857 int ret = 0;
858 if (level == RESUME_RESTORE_STATE)
859 ret = pcmcia_socket_dev_resume(dev);
860 return ret;
861}
862
863static struct device_driver hd64465_driver = { 847static struct device_driver hd64465_driver = {
864 .name = "hd64465-pcmcia", 848 .name = "hd64465-pcmcia",
865 .bus = &platform_bus_type, 849 .bus = &platform_bus_type,
866 .suspend = hd64465_suspend, 850 .suspend = pcmcia_socket_dev_suspend,
867 .resume = hd64465_resume, 851 .resume = pcmcia_socket_dev_resume,
868}; 852};
869 853
870static struct platform_device hd64465_device = { 854static struct platform_device hd64465_device = {
diff --git a/drivers/pcmcia/i82365.c b/drivers/pcmcia/i82365.c
index a713015e8228..4a41f67d185d 100644
--- a/drivers/pcmcia/i82365.c
+++ b/drivers/pcmcia/i82365.c
@@ -1332,27 +1332,11 @@ static struct pccard_operations pcic_operations = {
1332 1332
1333/*====================================================================*/ 1333/*====================================================================*/
1334 1334
1335static int i82365_suspend(struct device *dev, pm_message_t state, u32 level)
1336{
1337 int ret = 0;
1338 if (level == SUSPEND_SAVE_STATE)
1339 ret = pcmcia_socket_dev_suspend(dev, state);
1340 return ret;
1341}
1342
1343static int i82365_resume(struct device *dev, u32 level)
1344{
1345 int ret = 0;
1346 if (level == RESUME_RESTORE_STATE)
1347 ret = pcmcia_socket_dev_resume(dev);
1348 return ret;
1349}
1350
1351static struct device_driver i82365_driver = { 1335static struct device_driver i82365_driver = {
1352 .name = "i82365", 1336 .name = "i82365",
1353 .bus = &platform_bus_type, 1337 .bus = &platform_bus_type,
1354 .suspend = i82365_suspend, 1338 .suspend = pcmcia_socket_dev_suspend,
1355 .resume = i82365_resume, 1339 .resume = pcmcia_socket_dev_resume,
1356}; 1340};
1357 1341
1358static struct platform_device i82365_device = { 1342static struct platform_device i82365_device = {
diff --git a/drivers/pcmcia/m32r_cfc.c b/drivers/pcmcia/m32r_cfc.c
index 65f3ee3d4d3c..c6ed70ea4812 100644
--- a/drivers/pcmcia/m32r_cfc.c
+++ b/drivers/pcmcia/m32r_cfc.c
@@ -731,28 +731,11 @@ static struct pccard_operations pcc_operations = {
731 731
732/*====================================================================*/ 732/*====================================================================*/
733 733
734static int m32r_pcc_suspend(struct device *dev, pm_message_t state, u32 level)
735{
736 int ret = 0;
737 if (level == SUSPEND_SAVE_STATE)
738 ret = pcmcia_socket_dev_suspend(dev, state);
739 return ret;
740}
741
742static int m32r_pcc_resume(struct device *dev, u32 level)
743{
744 int ret = 0;
745 if (level == RESUME_RESTORE_STATE)
746 ret = pcmcia_socket_dev_resume(dev);
747 return ret;
748}
749
750
751static struct device_driver pcc_driver = { 734static struct device_driver pcc_driver = {
752 .name = "cfc", 735 .name = "cfc",
753 .bus = &platform_bus_type, 736 .bus = &platform_bus_type,
754 .suspend = m32r_pcc_suspend, 737 .suspend = pcmcia_socket_dev_suspend,
755 .resume = m32r_pcc_resume, 738 .resume = pcmcia_socket_dev_resume,
756}; 739};
757 740
758static struct platform_device pcc_device = { 741static struct platform_device pcc_device = {
diff --git a/drivers/pcmcia/m32r_pcc.c b/drivers/pcmcia/m32r_pcc.c
index 7b14d7efd68c..3397ff28de6a 100644
--- a/drivers/pcmcia/m32r_pcc.c
+++ b/drivers/pcmcia/m32r_pcc.c
@@ -695,28 +695,11 @@ static struct pccard_operations pcc_operations = {
695 695
696/*====================================================================*/ 696/*====================================================================*/
697 697
698static int m32r_pcc_suspend(struct device *dev, pm_message_t state, u32 level)
699{
700 int ret = 0;
701 if (level == SUSPEND_SAVE_STATE)
702 ret = pcmcia_socket_dev_suspend(dev, state);
703 return ret;
704}
705
706static int m32r_pcc_resume(struct device *dev, u32 level)
707{
708 int ret = 0;
709 if (level == RESUME_RESTORE_STATE)
710 ret = pcmcia_socket_dev_resume(dev);
711 return ret;
712}
713
714
715static struct device_driver pcc_driver = { 698static struct device_driver pcc_driver = {
716 .name = "pcc", 699 .name = "pcc",
717 .bus = &platform_bus_type, 700 .bus = &platform_bus_type,
718 .suspend = m32r_pcc_suspend, 701 .suspend = pcmcia_socket_dev_suspend,
719 .resume = m32r_pcc_resume, 702 .resume = pcmcia_socket_dev_resume,
720}; 703};
721 704
722static struct platform_device pcc_device = { 705static struct platform_device pcc_device = {
diff --git a/drivers/pcmcia/omap_cf.c b/drivers/pcmcia/omap_cf.c
index 94be9e51654e..2558c3cc91ec 100644
--- a/drivers/pcmcia/omap_cf.c
+++ b/drivers/pcmcia/omap_cf.c
@@ -329,27 +329,13 @@ static int __devexit omap_cf_remove(struct device *dev)
329 return 0; 329 return 0;
330} 330}
331 331
332static int omap_cf_suspend(struct device *dev, pm_message_t mesg, u32 level)
333{
334 if (level != SUSPEND_SAVE_STATE)
335 return 0;
336 return pcmcia_socket_dev_suspend(dev, mesg);
337}
338
339static int omap_cf_resume(struct device *dev, u32 level)
340{
341 if (level != RESUME_RESTORE_STATE)
342 return 0;
343 return pcmcia_socket_dev_resume(dev);
344}
345
346static struct device_driver omap_cf_driver = { 332static struct device_driver omap_cf_driver = {
347 .name = (char *) driver_name, 333 .name = (char *) driver_name,
348 .bus = &platform_bus_type, 334 .bus = &platform_bus_type,
349 .probe = omap_cf_probe, 335 .probe = omap_cf_probe,
350 .remove = __devexit_p(omap_cf_remove), 336 .remove = __devexit_p(omap_cf_remove),
351 .suspend = omap_cf_suspend, 337 .suspend = pcmcia_socket_dev_suspend,
352 .resume = omap_cf_resume, 338 .resume = pcmcia_socket_dev_resume,
353}; 339};
354 340
355static int __init omap_cf_init(void) 341static int __init omap_cf_init(void)
diff --git a/drivers/pcmcia/pxa2xx_base.c b/drivers/pcmcia/pxa2xx_base.c
index 325c992f7d8f..c2a12d53f6c7 100644
--- a/drivers/pcmcia/pxa2xx_base.c
+++ b/drivers/pcmcia/pxa2xx_base.c
@@ -205,32 +205,20 @@ int pxa2xx_drv_pcmcia_probe(struct device *dev)
205} 205}
206EXPORT_SYMBOL(pxa2xx_drv_pcmcia_probe); 206EXPORT_SYMBOL(pxa2xx_drv_pcmcia_probe);
207 207
208static int pxa2xx_drv_pcmcia_suspend(struct device *dev, pm_message_t state, u32 level) 208static int pxa2xx_drv_pcmcia_resume(struct device *dev)
209{ 209{
210 int ret = 0; 210 struct pcmcia_low_level *ops = dev->platform_data;
211 if (level == SUSPEND_SAVE_STATE) 211 int nr = ops ? ops->nr : 0;
212 ret = pcmcia_socket_dev_suspend(dev, state);
213 return ret;
214}
215 212
216static int pxa2xx_drv_pcmcia_resume(struct device *dev, u32 level) 213 MECR = nr > 1 ? MECR_CIT | MECR_NOS : (nr > 0 ? MECR_CIT : 0);
217{ 214
218 int ret = 0; 215 return pcmcia_socket_dev_resume(dev);
219 if (level == RESUME_RESTORE_STATE)
220 {
221 struct pcmcia_low_level *ops = dev->platform_data;
222 int nr = ops ? ops->nr : 0;
223
224 MECR = nr > 1 ? MECR_CIT | MECR_NOS : (nr > 0 ? MECR_CIT : 0);
225 ret = pcmcia_socket_dev_resume(dev);
226 }
227 return ret;
228} 216}
229 217
230static struct device_driver pxa2xx_pcmcia_driver = { 218static struct device_driver pxa2xx_pcmcia_driver = {
231 .probe = pxa2xx_drv_pcmcia_probe, 219 .probe = pxa2xx_drv_pcmcia_probe,
232 .remove = soc_common_drv_pcmcia_remove, 220 .remove = soc_common_drv_pcmcia_remove,
233 .suspend = pxa2xx_drv_pcmcia_suspend, 221 .suspend = pcmcia_socket_dev_suspend,
234 .resume = pxa2xx_drv_pcmcia_resume, 222 .resume = pxa2xx_drv_pcmcia_resume,
235 .name = "pxa2xx-pcmcia", 223 .name = "pxa2xx-pcmcia",
236 .bus = &platform_bus_type, 224 .bus = &platform_bus_type,
diff --git a/drivers/pcmcia/pxa2xx_sharpsl.c b/drivers/pcmcia/pxa2xx_sharpsl.c
index a1178a600e3c..bd924336a49f 100644
--- a/drivers/pcmcia/pxa2xx_sharpsl.c
+++ b/drivers/pcmcia/pxa2xx_sharpsl.c
@@ -18,10 +18,15 @@
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19#include <linux/device.h> 19#include <linux/device.h>
20 20
21#include <asm/mach-types.h>
21#include <asm/hardware.h> 22#include <asm/hardware.h>
22#include <asm/irq.h> 23#include <asm/irq.h>
23#include <asm/hardware/scoop.h> 24#include <asm/hardware/scoop.h>
24#include <asm/arch/pxa-regs.h> 25#ifdef CONFIG_SA1100_COLLIE
26#include <asm/arch-sa1100/collie.h>
27#else
28#include <asm/arch-pxa/pxa-regs.h>
29#endif
25 30
26#include "soc_common.h" 31#include "soc_common.h"
27 32
@@ -38,6 +43,7 @@ static int sharpsl_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
38{ 43{
39 int ret; 44 int ret;
40 45
46#ifndef CONFIG_SA1100_COLLIE
41 /* 47 /*
42 * Setup default state of GPIO outputs 48 * Setup default state of GPIO outputs
43 * before we enable them as outputs. 49 * before we enable them as outputs.
@@ -60,6 +66,7 @@ static int sharpsl_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
60 pxa_gpio_mode(GPIO55_nPREG_MD); 66 pxa_gpio_mode(GPIO55_nPREG_MD);
61 pxa_gpio_mode(GPIO56_nPWAIT_MD); 67 pxa_gpio_mode(GPIO56_nPWAIT_MD);
62 pxa_gpio_mode(GPIO57_nIOIS16_MD); 68 pxa_gpio_mode(GPIO57_nIOIS16_MD);
69#endif
63 70
64 /* Register interrupts */ 71 /* Register interrupts */
65 if (scoop_devs[skt->nr].cd_irq >= 0) { 72 if (scoop_devs[skt->nr].cd_irq >= 0) {
@@ -213,12 +220,20 @@ static void sharpsl_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
213 write_scoop_reg(scoop_devs[skt->nr].dev, SCOOP_IMR, 0x00C0); 220 write_scoop_reg(scoop_devs[skt->nr].dev, SCOOP_IMR, 0x00C0);
214 write_scoop_reg(scoop_devs[skt->nr].dev, SCOOP_MCR, 0x0101); 221 write_scoop_reg(scoop_devs[skt->nr].dev, SCOOP_MCR, 0x0101);
215 scoop_devs[skt->nr].keep_vs = NO_KEEP_VS; 222 scoop_devs[skt->nr].keep_vs = NO_KEEP_VS;
223
224 if (machine_is_collie())
225 /* We need to disable SS_OUTPUT_ENA here. */
226 write_scoop_reg(scoop_devs[skt->nr].dev, SCOOP_CPR, read_scoop_reg(scoop_devs[skt->nr].dev, SCOOP_CPR) & ~0x0080);
216} 227}
217 228
218static void sharpsl_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt) 229static void sharpsl_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
219{ 230{
220 /* CF_BUS_OFF */ 231 /* CF_BUS_OFF */
221 sharpsl_pcmcia_init_reset(&scoop_devs[skt->nr]); 232 sharpsl_pcmcia_init_reset(&scoop_devs[skt->nr]);
233
234 if (machine_is_collie())
235 /* We need to disable SS_OUTPUT_ENA here. */
236 write_scoop_reg(scoop_devs[skt->nr].dev, SCOOP_CPR, read_scoop_reg(scoop_devs[skt->nr].dev, SCOOP_CPR) & ~0x0080);
222} 237}
223 238
224static struct pcmcia_low_level sharpsl_pcmcia_ops = { 239static struct pcmcia_low_level sharpsl_pcmcia_ops = {
@@ -235,6 +250,19 @@ static struct pcmcia_low_level sharpsl_pcmcia_ops = {
235 250
236static struct platform_device *sharpsl_pcmcia_device; 251static struct platform_device *sharpsl_pcmcia_device;
237 252
253#ifdef CONFIG_SA1100_COLLIE
254int __init pcmcia_collie_init(struct device *dev)
255{
256 int ret = -ENODEV;
257
258 if (machine_is_collie())
259 ret = sa11xx_drv_pcmcia_probe(dev, &sharpsl_pcmcia_ops, 0, 1);
260
261 return ret;
262}
263
264#else
265
238static int __init sharpsl_pcmcia_init(void) 266static int __init sharpsl_pcmcia_init(void)
239{ 267{
240 int ret; 268 int ret;
@@ -269,6 +297,7 @@ static void __exit sharpsl_pcmcia_exit(void)
269 297
270fs_initcall(sharpsl_pcmcia_init); 298fs_initcall(sharpsl_pcmcia_init);
271module_exit(sharpsl_pcmcia_exit); 299module_exit(sharpsl_pcmcia_exit);
300#endif
272 301
273MODULE_DESCRIPTION("Sharp SL Series PCMCIA Support"); 302MODULE_DESCRIPTION("Sharp SL Series PCMCIA Support");
274MODULE_LICENSE("GPL"); 303MODULE_LICENSE("GPL");
diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c
index f9a5c70284b5..00960a379b9c 100644
--- a/drivers/pcmcia/rsrc_nonstatic.c
+++ b/drivers/pcmcia/rsrc_nonstatic.c
@@ -779,7 +779,7 @@ static int nonstatic_autoadd_resources(struct pcmcia_socket *s)
779 if (!s->cb_dev || !s->cb_dev->bus) 779 if (!s->cb_dev || !s->cb_dev->bus)
780 return -ENODEV; 780 return -ENODEV;
781 781
782#if defined(CONFIG_X86) || defined(CONFIG_X86_64) 782#if defined(CONFIG_X86)
783 /* If this is the root bus, the risk of hitting 783 /* If this is the root bus, the risk of hitting
784 * some strange system devices which aren't protected 784 * some strange system devices which aren't protected
785 * by either ACPI resource tables or properly requested 785 * by either ACPI resource tables or properly requested
@@ -994,7 +994,8 @@ static struct class_device_attribute *pccard_rsrc_attributes[] = {
994 NULL, 994 NULL,
995}; 995};
996 996
997static int __devinit pccard_sysfs_add_rsrc(struct class_device *class_dev) 997static int __devinit pccard_sysfs_add_rsrc(struct class_device *class_dev,
998 struct class_interface *class_intf)
998{ 999{
999 struct pcmcia_socket *s = class_get_devdata(class_dev); 1000 struct pcmcia_socket *s = class_get_devdata(class_dev);
1000 struct class_device_attribute **attr; 1001 struct class_device_attribute **attr;
@@ -1011,7 +1012,8 @@ static int __devinit pccard_sysfs_add_rsrc(struct class_device *class_dev)
1011 return ret; 1012 return ret;
1012} 1013}
1013 1014
1014static void __devexit pccard_sysfs_remove_rsrc(struct class_device *class_dev) 1015static void __devexit pccard_sysfs_remove_rsrc(struct class_device *class_dev,
1016 struct class_interface *class_intf)
1015{ 1017{
1016 struct pcmcia_socket *s = class_get_devdata(class_dev); 1018 struct pcmcia_socket *s = class_get_devdata(class_dev);
1017 struct class_device_attribute **attr; 1019 struct class_device_attribute **attr;
diff --git a/drivers/pcmcia/sa1100_generic.c b/drivers/pcmcia/sa1100_generic.c
index d4ed508b38be..acf60ffc8a12 100644
--- a/drivers/pcmcia/sa1100_generic.c
+++ b/drivers/pcmcia/sa1100_generic.c
@@ -38,8 +38,12 @@
38#include <pcmcia/cs.h> 38#include <pcmcia/cs.h>
39#include <pcmcia/ss.h> 39#include <pcmcia/ss.h>
40 40
41#include <asm/hardware/scoop.h>
42
41#include "sa1100_generic.h" 43#include "sa1100_generic.h"
42 44
45int __init pcmcia_collie_init(struct device *dev);
46
43static int (*sa11x0_pcmcia_hw_init[])(struct device *dev) = { 47static int (*sa11x0_pcmcia_hw_init[])(struct device *dev) = {
44#ifdef CONFIG_SA1100_ASSABET 48#ifdef CONFIG_SA1100_ASSABET
45 pcmcia_assabet_init, 49 pcmcia_assabet_init,
@@ -56,6 +60,9 @@ static int (*sa11x0_pcmcia_hw_init[])(struct device *dev) = {
56#ifdef CONFIG_SA1100_SIMPAD 60#ifdef CONFIG_SA1100_SIMPAD
57 pcmcia_simpad_init, 61 pcmcia_simpad_init,
58#endif 62#endif
63#ifdef CONFIG_SA1100_COLLIE
64 pcmcia_collie_init,
65#endif
59}; 66};
60 67
61static int sa11x0_drv_pcmcia_probe(struct device *dev) 68static int sa11x0_drv_pcmcia_probe(struct device *dev)
@@ -74,29 +81,13 @@ static int sa11x0_drv_pcmcia_probe(struct device *dev)
74 return ret; 81 return ret;
75} 82}
76 83
77static int sa11x0_drv_pcmcia_suspend(struct device *dev, pm_message_t state, u32 level)
78{
79 int ret = 0;
80 if (level == SUSPEND_SAVE_STATE)
81 ret = pcmcia_socket_dev_suspend(dev, state);
82 return ret;
83}
84
85static int sa11x0_drv_pcmcia_resume(struct device *dev, u32 level)
86{
87 int ret = 0;
88 if (level == RESUME_RESTORE_STATE)
89 ret = pcmcia_socket_dev_resume(dev);
90 return ret;
91}
92
93static struct device_driver sa11x0_pcmcia_driver = { 84static struct device_driver sa11x0_pcmcia_driver = {
94 .probe = sa11x0_drv_pcmcia_probe, 85 .probe = sa11x0_drv_pcmcia_probe,
95 .remove = soc_common_drv_pcmcia_remove, 86 .remove = soc_common_drv_pcmcia_remove,
96 .name = "sa11x0-pcmcia", 87 .name = "sa11x0-pcmcia",
97 .bus = &platform_bus_type, 88 .bus = &platform_bus_type,
98 .suspend = sa11x0_drv_pcmcia_suspend, 89 .suspend = pcmcia_socket_dev_suspend,
99 .resume = sa11x0_drv_pcmcia_resume, 90 .resume = pcmcia_socket_dev_resume,
100}; 91};
101 92
102/* sa11x0_pcmcia_init() 93/* sa11x0_pcmcia_init()
diff --git a/drivers/pcmcia/sa1111_generic.c b/drivers/pcmcia/sa1111_generic.c
index bb90a1448a53..81ded52c8959 100644
--- a/drivers/pcmcia/sa1111_generic.c
+++ b/drivers/pcmcia/sa1111_generic.c
@@ -122,7 +122,7 @@ void sa1111_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
122 122
123static int pcmcia_probe(struct sa1111_dev *dev) 123static int pcmcia_probe(struct sa1111_dev *dev)
124{ 124{
125 char *base; 125 void __iomem *base;
126 126
127 if (!request_mem_region(dev->res.start, 512, 127 if (!request_mem_region(dev->res.start, 512,
128 SA1111_DRIVER_NAME(dev))) 128 SA1111_DRIVER_NAME(dev)))
diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c
index 1040a6c1a8a4..4a3150a7854c 100644
--- a/drivers/pcmcia/socket_sysfs.c
+++ b/drivers/pcmcia/socket_sysfs.c
@@ -341,7 +341,8 @@ static struct bin_attribute pccard_cis_attr = {
341 .write = pccard_store_cis, 341 .write = pccard_store_cis,
342}; 342};
343 343
344static int __devinit pccard_sysfs_add_socket(struct class_device *class_dev) 344static int __devinit pccard_sysfs_add_socket(struct class_device *class_dev,
345 struct class_interface *class_intf)
345{ 346{
346 struct class_device_attribute **attr; 347 struct class_device_attribute **attr;
347 int ret = 0; 348 int ret = 0;
@@ -357,7 +358,8 @@ static int __devinit pccard_sysfs_add_socket(struct class_device *class_dev)
357 return ret; 358 return ret;
358} 359}
359 360
360static void __devexit pccard_sysfs_remove_socket(struct class_device *class_dev) 361static void __devexit pccard_sysfs_remove_socket(struct class_device *class_dev,
362 struct class_interface *class_intf)
361{ 363{
362 struct class_device_attribute **attr; 364 struct class_device_attribute **attr;
363 365
diff --git a/drivers/pcmcia/tcic.c b/drivers/pcmcia/tcic.c
index d5a61eae6119..f158b67f6610 100644
--- a/drivers/pcmcia/tcic.c
+++ b/drivers/pcmcia/tcic.c
@@ -372,27 +372,11 @@ static int __init get_tcic_id(void)
372 372
373/*====================================================================*/ 373/*====================================================================*/
374 374
375static int tcic_drv_suspend(struct device *dev, pm_message_t state, u32 level)
376{
377 int ret = 0;
378 if (level == SUSPEND_SAVE_STATE)
379 ret = pcmcia_socket_dev_suspend(dev, state);
380 return ret;
381}
382
383static int tcic_drv_resume(struct device *dev, u32 level)
384{
385 int ret = 0;
386 if (level == RESUME_RESTORE_STATE)
387 ret = pcmcia_socket_dev_resume(dev);
388 return ret;
389}
390
391static struct device_driver tcic_driver = { 375static struct device_driver tcic_driver = {
392 .name = "tcic-pcmcia", 376 .name = "tcic-pcmcia",
393 .bus = &platform_bus_type, 377 .bus = &platform_bus_type,
394 .suspend = tcic_drv_suspend, 378 .suspend = pcmcia_socket_dev_suspend,
395 .resume = tcic_drv_resume, 379 .resume = pcmcia_socket_dev_resume,
396}; 380};
397 381
398static struct platform_device tcic_device = { 382static struct platform_device tcic_device = {
diff --git a/drivers/pcmcia/vrc4171_card.c b/drivers/pcmcia/vrc4171_card.c
index 17bb2da6752b..3d2dca675e02 100644
--- a/drivers/pcmcia/vrc4171_card.c
+++ b/drivers/pcmcia/vrc4171_card.c
@@ -774,31 +774,11 @@ static int __devinit vrc4171_card_setup(char *options)
774 774
775__setup("vrc4171_card=", vrc4171_card_setup); 775__setup("vrc4171_card=", vrc4171_card_setup);
776 776
777static int vrc4171_card_suspend(struct device *dev, pm_message_t state, u32 level)
778{
779 int retval = 0;
780
781 if (level == SUSPEND_SAVE_STATE)
782 retval = pcmcia_socket_dev_suspend(dev, state);
783
784 return retval;
785}
786
787static int vrc4171_card_resume(struct device *dev, u32 level)
788{
789 int retval = 0;
790
791 if (level == RESUME_RESTORE_STATE)
792 retval = pcmcia_socket_dev_resume(dev);
793
794 return retval;
795}
796
797static struct device_driver vrc4171_card_driver = { 777static struct device_driver vrc4171_card_driver = {
798 .name = vrc4171_card_name, 778 .name = vrc4171_card_name,
799 .bus = &platform_bus_type, 779 .bus = &platform_bus_type,
800 .suspend = vrc4171_card_suspend, 780 .suspend = pcmcia_socket_dev_suspend,
801 .resume = vrc4171_card_resume, 781 .resume = pcmcia_socket_dev_resume,
802}; 782};
803 783
804static int __devinit vrc4171_card_init(void) 784static int __devinit vrc4171_card_init(void)
diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c
index db9f952f9e3c..ec6ab65f0872 100644
--- a/drivers/pcmcia/yenta_socket.c
+++ b/drivers/pcmcia/yenta_socket.c
@@ -151,6 +151,40 @@ static void exca_writew(struct yenta_socket *socket, unsigned reg, u16 val)
151 readb(socket->base + 0x800 + reg + 1); 151 readb(socket->base + 0x800 + reg + 1);
152} 152}
153 153
154static ssize_t show_yenta_registers(struct device *yentadev, struct device_attribute *attr, char *buf)
155{
156 struct pci_dev *dev = to_pci_dev(yentadev);
157 struct yenta_socket *socket = pci_get_drvdata(dev);
158 int offset = 0, i;
159
160 offset = snprintf(buf, PAGE_SIZE, "CB registers:");
161 for (i = 0; i < 0x24; i += 4) {
162 unsigned val;
163 if (!(i & 15))
164 offset += snprintf(buf + offset, PAGE_SIZE - offset, "\n%02x:", i);
165 val = cb_readl(socket, i);
166 offset += snprintf(buf + offset, PAGE_SIZE - offset, " %08x", val);
167 }
168
169 offset += snprintf(buf + offset, PAGE_SIZE - offset, "\n\nExCA registers:");
170 for (i = 0; i < 0x45; i++) {
171 unsigned char val;
172 if (!(i & 7)) {
173 if (i & 8) {
174 memcpy(buf + offset, " -", 2);
175 offset += 2;
176 } else
177 offset += snprintf(buf + offset, PAGE_SIZE - offset, "\n%02x:", i);
178 }
179 val = exca_readb(socket, i);
180 offset += snprintf(buf + offset, PAGE_SIZE - offset, " %02x", val);
181 }
182 buf[offset++] = '\n';
183 return offset;
184}
185
186static DEVICE_ATTR(yenta_registers, S_IRUSR, show_yenta_registers, NULL);
187
154/* 188/*
155 * Ugh, mixed-mode cardbus and 16-bit pccard state: things depend 189 * Ugh, mixed-mode cardbus and 16-bit pccard state: things depend
156 * on what kind of card is inserted.. 190 * on what kind of card is inserted..
@@ -765,6 +799,9 @@ static void yenta_close(struct pci_dev *dev)
765{ 799{
766 struct yenta_socket *sock = pci_get_drvdata(dev); 800 struct yenta_socket *sock = pci_get_drvdata(dev);
767 801
802 /* Remove the register attributes */
803 device_remove_file(&dev->dev, &dev_attr_yenta_registers);
804
768 /* we don't want a dying socket registered */ 805 /* we don't want a dying socket registered */
769 pcmcia_unregister_socket(&sock->socket); 806 pcmcia_unregister_socket(&sock->socket);
770 807
@@ -1138,8 +1175,11 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
1138 1175
1139 /* Register it with the pcmcia layer.. */ 1176 /* Register it with the pcmcia layer.. */
1140 ret = pcmcia_register_socket(&socket->socket); 1177 ret = pcmcia_register_socket(&socket->socket);
1141 if (ret == 0) 1178 if (ret == 0) {
1179 /* Add the yenta register attributes */
1180 device_create_file(&dev->dev, &dev_attr_yenta_registers);
1142 goto out; 1181 goto out;
1182 }
1143 1183
1144 unmap: 1184 unmap:
1145 iounmap(socket->base); 1185 iounmap(socket->base);
diff --git a/drivers/pnp/manager.c b/drivers/pnp/manager.c
index 94442ffd4aed..cbb2749db178 100644
--- a/drivers/pnp/manager.c
+++ b/drivers/pnp/manager.c
@@ -12,6 +12,8 @@
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/pnp.h> 14#include <linux/pnp.h>
15#include <linux/slab.h>
16#include <linux/bitmap.h>
15#include "base.h" 17#include "base.h"
16 18
17DECLARE_MUTEX(pnp_res_mutex); 19DECLARE_MUTEX(pnp_res_mutex);
diff --git a/drivers/pnp/pnpbios/rsparser.c b/drivers/pnp/pnpbios/rsparser.c
index b0ca65b68645..5e38cd7335f7 100644
--- a/drivers/pnp/pnpbios/rsparser.c
+++ b/drivers/pnp/pnpbios/rsparser.c
@@ -7,6 +7,8 @@
7#include <linux/ctype.h> 7#include <linux/ctype.h>
8#include <linux/pnp.h> 8#include <linux/pnp.h>
9#include <linux/pnpbios.h> 9#include <linux/pnpbios.h>
10#include <linux/string.h>
11#include <linux/slab.h>
10 12
11#ifdef CONFIG_PCI 13#ifdef CONFIG_PCI
12#include <linux/pci.h> 14#include <linux/pci.h>
diff --git a/drivers/s390/char/con3270.c b/drivers/s390/char/con3270.c
index fc7a213e591f..c570a9f6ce9c 100644
--- a/drivers/s390/char/con3270.c
+++ b/drivers/s390/char/con3270.c
@@ -213,6 +213,9 @@ con3270_update(struct con3270 *cp)
213 struct string *s, *n; 213 struct string *s, *n;
214 int rc; 214 int rc;
215 215
216 if (cp->view.dev)
217 raw3270_activate_view(&cp->view);
218
216 wrq = xchg(&cp->write, 0); 219 wrq = xchg(&cp->write, 0);
217 if (!wrq) { 220 if (!wrq) {
218 con3270_set_timer(cp, 1); 221 con3270_set_timer(cp, 1);
@@ -489,8 +492,6 @@ con3270_write(struct console *co, const char *str, unsigned int count)
489 unsigned char c; 492 unsigned char c;
490 493
491 cp = condev; 494 cp = condev;
492 if (cp->view.dev)
493 raw3270_activate_view(&cp->view);
494 spin_lock_irqsave(&cp->view.lock, flags); 495 spin_lock_irqsave(&cp->view.lock, flags);
495 while (count-- > 0) { 496 while (count-- > 0) {
496 c = *str++; 497 c = *str++;
@@ -620,7 +621,7 @@ con3270_init(void)
620 (void (*)(unsigned long)) con3270_read_tasklet, 621 (void (*)(unsigned long)) con3270_read_tasklet,
621 (unsigned long) condev->read); 622 (unsigned long) condev->read);
622 623
623 raw3270_add_view(&condev->view, &con3270_fn, 0); 624 raw3270_add_view(&condev->view, &con3270_fn, 1);
624 625
625 INIT_LIST_HEAD(&condev->freemem); 626 INIT_LIST_HEAD(&condev->freemem);
626 for (i = 0; i < CON3270_STRING_PAGES; i++) { 627 for (i = 0; i < CON3270_STRING_PAGES; i++) {
diff --git a/drivers/s390/char/fs3270.c b/drivers/s390/char/fs3270.c
index 60afcdcf91c2..735a7fcdeff5 100644
--- a/drivers/s390/char/fs3270.c
+++ b/drivers/s390/char/fs3270.c
@@ -33,8 +33,11 @@ struct fs3270 {
33 int read_command; /* ccw command to use for reads. */ 33 int read_command; /* ccw command to use for reads. */
34 int write_command; /* ccw command to use for writes. */ 34 int write_command; /* ccw command to use for writes. */
35 int attention; /* Got attention. */ 35 int attention; /* Got attention. */
36 struct raw3270_request *clear; /* single clear request. */ 36 int active; /* Fullscreen view is active. */
37 wait_queue_head_t attn_wait; /* Attention wait queue. */ 37 struct raw3270_request *init; /* single init request. */
38 wait_queue_head_t wait; /* Init & attention wait queue. */
39 struct idal_buffer *rdbuf; /* full-screen-deactivate buffer */
40 size_t rdbuf_size; /* size of data returned by RDBUF */
38}; 41};
39 42
40static void 43static void
@@ -43,58 +46,172 @@ fs3270_wake_up(struct raw3270_request *rq, void *data)
43 wake_up((wait_queue_head_t *) data); 46 wake_up((wait_queue_head_t *) data);
44} 47}
45 48
49static inline int
50fs3270_working(struct fs3270 *fp)
51{
52 /*
53 * The fullscreen view is in working order if the view
54 * has been activated AND the initial request is finished.
55 */
56 return fp->active && raw3270_request_final(fp->init);
57}
58
46static int 59static int
47fs3270_do_io(struct raw3270_view *view, struct raw3270_request *rq) 60fs3270_do_io(struct raw3270_view *view, struct raw3270_request *rq)
48{ 61{
49 wait_queue_head_t wq; 62 struct fs3270 *fp;
50 int rc; 63 int rc;
51 64
52 init_waitqueue_head(&wq); 65 fp = (struct fs3270 *) view;
53 rq->callback = fs3270_wake_up; 66 rq->callback = fs3270_wake_up;
54 rq->callback_data = &wq; 67 rq->callback_data = &fp->wait;
55 rc = raw3270_start(view, rq); 68
56 if (rc) 69 do {
57 return rc; 70 if (!fs3270_working(fp)) {
58 /* Started sucessfully. Now wait for completion. */ 71 /* Fullscreen view isn't ready yet. */
59 wait_event(wq, raw3270_request_final(rq)); 72 rc = wait_event_interruptible(fp->wait,
60 return rq->rc; 73 fs3270_working(fp));
74 if (rc != 0)
75 break;
76 }
77 rc = raw3270_start(view, rq);
78 if (rc == 0) {
79 /* Started sucessfully. Now wait for completion. */
80 wait_event(fp->wait, raw3270_request_final(rq));
81 }
82 } while (rc == -EACCES);
83 return rc;
61} 84}
62 85
86/*
87 * Switch to the fullscreen view.
88 */
63static void 89static void
64fs3270_reset_callback(struct raw3270_request *rq, void *data) 90fs3270_reset_callback(struct raw3270_request *rq, void *data)
65{ 91{
92 struct fs3270 *fp;
93
94 fp = (struct fs3270 *) rq->view;
66 raw3270_request_reset(rq); 95 raw3270_request_reset(rq);
96 wake_up(&fp->wait);
97}
98
99static void
100fs3270_restore_callback(struct raw3270_request *rq, void *data)
101{
102 struct fs3270 *fp;
103
104 fp = (struct fs3270 *) rq->view;
105 if (rq->rc != 0 || rq->rescnt != 0) {
106 if (fp->fs_pid)
107 kill_proc(fp->fs_pid, SIGHUP, 1);
108 }
109 fp->rdbuf_size = 0;
110 raw3270_request_reset(rq);
111 wake_up(&fp->wait);
67} 112}
68 113
69/*
70 * Switch to the fullscreen view.
71 */
72static int 114static int
73fs3270_activate(struct raw3270_view *view) 115fs3270_activate(struct raw3270_view *view)
74{ 116{
75 struct fs3270 *fp; 117 struct fs3270 *fp;
118 char *cp;
119 int rc;
76 120
77 fp = (struct fs3270 *) view; 121 fp = (struct fs3270 *) view;
78 raw3270_request_set_cmd(fp->clear, TC_EWRITEA); 122
79 fp->clear->callback = fs3270_reset_callback; 123 /* If an old init command is still running just return. */
80 return raw3270_start(view, fp->clear); 124 if (!raw3270_request_final(fp->init))
125 return 0;
126
127 if (fp->rdbuf_size == 0) {
128 /* No saved buffer. Just clear the screen. */
129 raw3270_request_set_cmd(fp->init, TC_EWRITEA);
130 fp->init->callback = fs3270_reset_callback;
131 } else {
132 /* Restore fullscreen buffer saved by fs3270_deactivate. */
133 raw3270_request_set_cmd(fp->init, TC_EWRITEA);
134 raw3270_request_set_idal(fp->init, fp->rdbuf);
135 fp->init->ccw.count = fp->rdbuf_size;
136 cp = fp->rdbuf->data[0];
137 cp[0] = TW_KR;
138 cp[1] = TO_SBA;
139 cp[2] = cp[6];
140 cp[3] = cp[7];
141 cp[4] = TO_IC;
142 cp[5] = TO_SBA;
143 cp[6] = 0x40;
144 cp[7] = 0x40;
145 fp->init->rescnt = 0;
146 fp->init->callback = fs3270_restore_callback;
147 }
148 rc = fp->init->rc = raw3270_start_locked(view, fp->init);
149 if (rc)
150 fp->init->callback(fp->init, NULL);
151 else
152 fp->active = 1;
153 return rc;
81} 154}
82 155
83/* 156/*
84 * Shutdown fullscreen view. 157 * Shutdown fullscreen view.
85 */ 158 */
86static void 159static void
160fs3270_save_callback(struct raw3270_request *rq, void *data)
161{
162 struct fs3270 *fp;
163
164 fp = (struct fs3270 *) rq->view;
165
166 /* Correct idal buffer element 0 address. */
167 fp->rdbuf->data[0] -= 5;
168 fp->rdbuf->size += 5;
169
170 /*
171 * If the rdbuf command failed or the idal buffer is
172 * to small for the amount of data returned by the
173 * rdbuf command, then we have no choice but to send
174 * a SIGHUP to the application.
175 */
176 if (rq->rc != 0 || rq->rescnt == 0) {
177 if (fp->fs_pid)
178 kill_proc(fp->fs_pid, SIGHUP, 1);
179 fp->rdbuf_size = 0;
180 } else
181 fp->rdbuf_size = fp->rdbuf->size - rq->rescnt;
182 raw3270_request_reset(rq);
183 wake_up(&fp->wait);
184}
185
186static void
87fs3270_deactivate(struct raw3270_view *view) 187fs3270_deactivate(struct raw3270_view *view)
88{ 188{
89 // FIXME: is this a good idea? The user program using fullscreen 3270
90 // will die just because a console message appeared. On the other
91 // hand the fullscreen device is unoperational now.
92 struct fs3270 *fp; 189 struct fs3270 *fp;
93 190
94 fp = (struct fs3270 *) view; 191 fp = (struct fs3270 *) view;
95 if (fp->fs_pid != 0) 192 fp->active = 0;
96 kill_proc(fp->fs_pid, SIGHUP, 1); 193
97 fp->fs_pid = 0; 194 /* If an old init command is still running just return. */
195 if (!raw3270_request_final(fp->init))
196 return;
197
198 /* Prepare read-buffer request. */
199 raw3270_request_set_cmd(fp->init, TC_RDBUF);
200 /*
201 * Hackish: skip first 5 bytes of the idal buffer to make
202 * room for the TW_KR/TO_SBA/<address>/<address>/TO_IC sequence
203 * in the activation command.
204 */
205 fp->rdbuf->data[0] += 5;
206 fp->rdbuf->size -= 5;
207 raw3270_request_set_idal(fp->init, fp->rdbuf);
208 fp->init->rescnt = 0;
209 fp->init->callback = fs3270_save_callback;
210
211 /* Start I/O to read in the 3270 buffer. */
212 fp->init->rc = raw3270_start_locked(view, fp->init);
213 if (fp->init->rc)
214 fp->init->callback(fp->init, NULL);
98} 215}
99 216
100static int 217static int
@@ -103,7 +220,7 @@ fs3270_irq(struct fs3270 *fp, struct raw3270_request *rq, struct irb *irb)
103 /* Handle ATTN. Set indication and wake waiters for attention. */ 220 /* Handle ATTN. Set indication and wake waiters for attention. */
104 if (irb->scsw.dstat & DEV_STAT_ATTENTION) { 221 if (irb->scsw.dstat & DEV_STAT_ATTENTION) {
105 fp->attention = 1; 222 fp->attention = 1;
106 wake_up(&fp->attn_wait); 223 wake_up(&fp->wait);
107 } 224 }
108 225
109 if (rq) { 226 if (rq) {
@@ -125,7 +242,7 @@ fs3270_read(struct file *filp, char *data, size_t count, loff_t *off)
125 struct fs3270 *fp; 242 struct fs3270 *fp;
126 struct raw3270_request *rq; 243 struct raw3270_request *rq;
127 struct idal_buffer *ib; 244 struct idal_buffer *ib;
128 int rc; 245 ssize_t rc;
129 246
130 if (count == 0 || count > 65535) 247 if (count == 0 || count > 65535)
131 return -EINVAL; 248 return -EINVAL;
@@ -133,7 +250,7 @@ fs3270_read(struct file *filp, char *data, size_t count, loff_t *off)
133 if (!fp) 250 if (!fp)
134 return -ENODEV; 251 return -ENODEV;
135 ib = idal_buffer_alloc(count, 0); 252 ib = idal_buffer_alloc(count, 0);
136 if (!ib) 253 if (IS_ERR(ib))
137 return -ENOMEM; 254 return -ENOMEM;
138 rq = raw3270_request_alloc(0); 255 rq = raw3270_request_alloc(0);
139 if (!IS_ERR(rq)) { 256 if (!IS_ERR(rq)) {
@@ -141,10 +258,19 @@ fs3270_read(struct file *filp, char *data, size_t count, loff_t *off)
141 fp->read_command = 6; 258 fp->read_command = 6;
142 raw3270_request_set_cmd(rq, fp->read_command ? : 2); 259 raw3270_request_set_cmd(rq, fp->read_command ? : 2);
143 raw3270_request_set_idal(rq, ib); 260 raw3270_request_set_idal(rq, ib);
144 wait_event(fp->attn_wait, fp->attention); 261 rc = wait_event_interruptible(fp->wait, fp->attention);
145 rc = fs3270_do_io(&fp->view, rq); 262 fp->attention = 0;
146 if (rc == 0 && idal_buffer_to_user(ib, data, count)) 263 if (rc == 0) {
147 rc = -EFAULT; 264 rc = fs3270_do_io(&fp->view, rq);
265 if (rc == 0) {
266 count -= rq->rescnt;
267 if (idal_buffer_to_user(ib, data, count) != 0)
268 rc = -EFAULT;
269 else
270 rc = count;
271
272 }
273 }
148 raw3270_request_free(rq); 274 raw3270_request_free(rq);
149 } else 275 } else
150 rc = PTR_ERR(rq); 276 rc = PTR_ERR(rq);
@@ -162,13 +288,13 @@ fs3270_write(struct file *filp, const char *data, size_t count, loff_t *off)
162 struct raw3270_request *rq; 288 struct raw3270_request *rq;
163 struct idal_buffer *ib; 289 struct idal_buffer *ib;
164 int write_command; 290 int write_command;
165 int rc; 291 ssize_t rc;
166 292
167 fp = filp->private_data; 293 fp = filp->private_data;
168 if (!fp) 294 if (!fp)
169 return -ENODEV; 295 return -ENODEV;
170 ib = idal_buffer_alloc(count, 0); 296 ib = idal_buffer_alloc(count, 0);
171 if (!ib) 297 if (IS_ERR(ib))
172 return -ENOMEM; 298 return -ENOMEM;
173 rq = raw3270_request_alloc(0); 299 rq = raw3270_request_alloc(0);
174 if (!IS_ERR(rq)) { 300 if (!IS_ERR(rq)) {
@@ -179,6 +305,8 @@ fs3270_write(struct file *filp, const char *data, size_t count, loff_t *off)
179 raw3270_request_set_cmd(rq, write_command); 305 raw3270_request_set_cmd(rq, write_command);
180 raw3270_request_set_idal(rq, ib); 306 raw3270_request_set_idal(rq, ib);
181 rc = fs3270_do_io(&fp->view, rq); 307 rc = fs3270_do_io(&fp->view, rq);
308 if (rc == 0)
309 rc = count - rq->rescnt;
182 } else 310 } else
183 rc = -EFAULT; 311 rc = -EFAULT;
184 raw3270_request_free(rq); 312 raw3270_request_free(rq);
@@ -232,7 +360,7 @@ fs3270_ioctl(struct inode *inode, struct file *filp,
232} 360}
233 361
234/* 362/*
235 * Allocate tty3270 structure. 363 * Allocate fs3270 structure.
236 */ 364 */
237static struct fs3270 * 365static struct fs3270 *
238fs3270_alloc_view(void) 366fs3270_alloc_view(void)
@@ -243,8 +371,8 @@ fs3270_alloc_view(void)
243 if (!fp) 371 if (!fp)
244 return ERR_PTR(-ENOMEM); 372 return ERR_PTR(-ENOMEM);
245 memset(fp, 0, sizeof(struct fs3270)); 373 memset(fp, 0, sizeof(struct fs3270));
246 fp->clear = raw3270_request_alloc(0); 374 fp->init = raw3270_request_alloc(0);
247 if (!IS_ERR(fp->clear)) { 375 if (IS_ERR(fp->init)) {
248 kfree(fp); 376 kfree(fp);
249 return ERR_PTR(-ENOMEM); 377 return ERR_PTR(-ENOMEM);
250 } 378 }
@@ -252,12 +380,17 @@ fs3270_alloc_view(void)
252} 380}
253 381
254/* 382/*
255 * Free tty3270 structure. 383 * Free fs3270 structure.
256 */ 384 */
257static void 385static void
258fs3270_free_view(struct raw3270_view *view) 386fs3270_free_view(struct raw3270_view *view)
259{ 387{
260 raw3270_request_free(((struct fs3270 *) view)->clear); 388 struct fs3270 *fp;
389
390 fp = (struct fs3270 *) view;
391 if (fp->rdbuf)
392 idal_buffer_free(fp->rdbuf);
393 raw3270_request_free(((struct fs3270 *) view)->init);
261 kfree(view); 394 kfree(view);
262} 395}
263 396
@@ -285,11 +418,20 @@ static int
285fs3270_open(struct inode *inode, struct file *filp) 418fs3270_open(struct inode *inode, struct file *filp)
286{ 419{
287 struct fs3270 *fp; 420 struct fs3270 *fp;
421 struct idal_buffer *ib;
288 int minor, rc; 422 int minor, rc;
289 423
290 if (imajor(filp->f_dentry->d_inode) != IBM_FS3270_MAJOR) 424 if (imajor(filp->f_dentry->d_inode) != IBM_FS3270_MAJOR)
291 return -ENODEV; 425 return -ENODEV;
292 minor = iminor(filp->f_dentry->d_inode); 426 minor = iminor(filp->f_dentry->d_inode);
427 /* Check for minor 0 multiplexer. */
428 if (minor == 0) {
429 if (!current->signal->tty)
430 return -ENODEV;
431 if (current->signal->tty->driver->major != IBM_TTY3270_MAJOR)
432 return -ENODEV;
433 minor = current->signal->tty->index + RAW3270_FIRSTMINOR;
434 }
293 /* Check if some other program is already using fullscreen mode. */ 435 /* Check if some other program is already using fullscreen mode. */
294 fp = (struct fs3270 *) raw3270_find_view(&fs3270_fn, minor); 436 fp = (struct fs3270 *) raw3270_find_view(&fs3270_fn, minor);
295 if (!IS_ERR(fp)) { 437 if (!IS_ERR(fp)) {
@@ -301,7 +443,7 @@ fs3270_open(struct inode *inode, struct file *filp)
301 if (IS_ERR(fp)) 443 if (IS_ERR(fp))
302 return PTR_ERR(fp); 444 return PTR_ERR(fp);
303 445
304 init_waitqueue_head(&fp->attn_wait); 446 init_waitqueue_head(&fp->wait);
305 fp->fs_pid = current->pid; 447 fp->fs_pid = current->pid;
306 rc = raw3270_add_view(&fp->view, &fs3270_fn, minor); 448 rc = raw3270_add_view(&fp->view, &fs3270_fn, minor);
307 if (rc) { 449 if (rc) {
@@ -309,8 +451,18 @@ fs3270_open(struct inode *inode, struct file *filp)
309 return rc; 451 return rc;
310 } 452 }
311 453
454 /* Allocate idal-buffer. */
455 ib = idal_buffer_alloc(2*fp->view.rows*fp->view.cols + 5, 0);
456 if (IS_ERR(ib)) {
457 raw3270_put_view(&fp->view);
458 raw3270_del_view(&fp->view);
459 return PTR_ERR(fp);
460 }
461 fp->rdbuf = ib;
462
312 rc = raw3270_activate_view(&fp->view); 463 rc = raw3270_activate_view(&fp->view);
313 if (rc) { 464 if (rc) {
465 raw3270_put_view(&fp->view);
314 raw3270_del_view(&fp->view); 466 raw3270_del_view(&fp->view);
315 return rc; 467 return rc;
316 } 468 }
@@ -329,8 +481,12 @@ fs3270_close(struct inode *inode, struct file *filp)
329 481
330 fp = filp->private_data; 482 fp = filp->private_data;
331 filp->private_data = 0; 483 filp->private_data = 0;
332 if (fp) 484 if (fp) {
485 fp->fs_pid = 0;
486 raw3270_reset(&fp->view);
487 raw3270_put_view(&fp->view);
333 raw3270_del_view(&fp->view); 488 raw3270_del_view(&fp->view);
489 }
334 return 0; 490 return 0;
335} 491}
336 492
diff --git a/drivers/s390/char/raw3270.c b/drivers/s390/char/raw3270.c
index 328d9cbc56a3..d66946443dfc 100644
--- a/drivers/s390/char/raw3270.c
+++ b/drivers/s390/char/raw3270.c
@@ -25,6 +25,12 @@
25 25
26#include "raw3270.h" 26#include "raw3270.h"
27 27
28#include <linux/major.h>
29#include <linux/kdev_t.h>
30#include <linux/device.h>
31
32struct class *class3270;
33
28/* The main 3270 data structure. */ 34/* The main 3270 data structure. */
29struct raw3270 { 35struct raw3270 {
30 struct list_head list; 36 struct list_head list;
@@ -41,6 +47,8 @@ struct raw3270 {
41 struct timer_list timer; /* Device timer. */ 47 struct timer_list timer; /* Device timer. */
42 48
43 unsigned char *ascebc; /* ascii -> ebcdic table */ 49 unsigned char *ascebc; /* ascii -> ebcdic table */
50 struct class_device *clttydev; /* 3270-class tty device ptr */
51 struct class_device *cltubdev; /* 3270-class tub device ptr */
44}; 52};
45 53
46/* raw3270->flags */ 54/* raw3270->flags */
@@ -317,6 +325,22 @@ raw3270_start(struct raw3270_view *view, struct raw3270_request *rq)
317} 325}
318 326
319int 327int
328raw3270_start_locked(struct raw3270_view *view, struct raw3270_request *rq)
329{
330 struct raw3270 *rp;
331 int rc;
332
333 rp = view->dev;
334 if (!rp || rp->view != view)
335 rc = -EACCES;
336 else if (!test_bit(RAW3270_FLAGS_READY, &rp->flags))
337 rc = -ENODEV;
338 else
339 rc = __raw3270_start(rp, view, rq);
340 return rc;
341}
342
343int
320raw3270_start_irq(struct raw3270_view *view, struct raw3270_request *rq) 344raw3270_start_irq(struct raw3270_view *view, struct raw3270_request *rq)
321{ 345{
322 struct raw3270 *rp; 346 struct raw3270 *rp;
@@ -744,6 +768,22 @@ raw3270_reset_device(struct raw3270 *rp)
744 return rc; 768 return rc;
745} 769}
746 770
771int
772raw3270_reset(struct raw3270_view *view)
773{
774 struct raw3270 *rp;
775 int rc;
776
777 rp = view->dev;
778 if (!rp || rp->view != view)
779 rc = -EACCES;
780 else if (!test_bit(RAW3270_FLAGS_READY, &rp->flags))
781 rc = -ENODEV;
782 else
783 rc = raw3270_reset_device(view->dev);
784 return rc;
785}
786
747/* 787/*
748 * Setup new 3270 device. 788 * Setup new 3270 device.
749 */ 789 */
@@ -774,11 +814,12 @@ raw3270_setup_device(struct ccw_device *cdev, struct raw3270 *rp, char *ascebc)
774 814
775 /* 815 /*
776 * Add device to list and find the smallest unused minor 816 * Add device to list and find the smallest unused minor
777 * number for it. 817 * number for it. Note: there is no device with minor 0,
818 * see special case for fs3270.c:fs3270_open().
778 */ 819 */
779 down(&raw3270_sem); 820 down(&raw3270_sem);
780 /* Keep the list sorted. */ 821 /* Keep the list sorted. */
781 minor = 0; 822 minor = RAW3270_FIRSTMINOR;
782 rp->minor = -1; 823 rp->minor = -1;
783 list_for_each(l, &raw3270_devices) { 824 list_for_each(l, &raw3270_devices) {
784 tmp = list_entry(l, struct raw3270, list); 825 tmp = list_entry(l, struct raw3270, list);
@@ -789,7 +830,7 @@ raw3270_setup_device(struct ccw_device *cdev, struct raw3270 *rp, char *ascebc)
789 } 830 }
790 minor++; 831 minor++;
791 } 832 }
792 if (rp->minor == -1 && minor < RAW3270_MAXDEVS) { 833 if (rp->minor == -1 && minor < RAW3270_MAXDEVS + RAW3270_FIRSTMINOR) {
793 rp->minor = minor; 834 rp->minor = minor;
794 list_add_tail(&rp->list, &raw3270_devices); 835 list_add_tail(&rp->list, &raw3270_devices);
795 } 836 }
@@ -941,11 +982,12 @@ raw3270_deactivate_view(struct raw3270_view *view)
941 list_add_tail(&view->list, &rp->view_list); 982 list_add_tail(&view->list, &rp->view_list);
942 /* Try to activate another view. */ 983 /* Try to activate another view. */
943 if (test_bit(RAW3270_FLAGS_READY, &rp->flags)) { 984 if (test_bit(RAW3270_FLAGS_READY, &rp->flags)) {
944 list_for_each_entry(view, &rp->view_list, list) 985 list_for_each_entry(view, &rp->view_list, list) {
945 if (view->fn->activate(view) == 0) { 986 rp->view = view;
946 rp->view = view; 987 if (view->fn->activate(view) == 0)
947 break; 988 break;
948 } 989 rp->view = 0;
990 }
949 } 991 }
950 } 992 }
951 spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags); 993 spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
@@ -961,6 +1003,8 @@ raw3270_add_view(struct raw3270_view *view, struct raw3270_fn *fn, int minor)
961 struct raw3270 *rp; 1003 struct raw3270 *rp;
962 int rc; 1004 int rc;
963 1005
1006 if (minor <= 0)
1007 return -ENODEV;
964 down(&raw3270_sem); 1008 down(&raw3270_sem);
965 rc = -ENODEV; 1009 rc = -ENODEV;
966 list_for_each_entry(rp, &raw3270_devices, list) { 1010 list_for_each_entry(rp, &raw3270_devices, list) {
@@ -976,7 +1020,7 @@ raw3270_add_view(struct raw3270_view *view, struct raw3270_fn *fn, int minor)
976 view->cols = rp->cols; 1020 view->cols = rp->cols;
977 view->ascebc = rp->ascebc; 1021 view->ascebc = rp->ascebc;
978 spin_lock_init(&view->lock); 1022 spin_lock_init(&view->lock);
979 list_add_tail(&view->list, &rp->view_list); 1023 list_add(&view->list, &rp->view_list);
980 rc = 0; 1024 rc = 0;
981 } 1025 }
982 spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags); 1026 spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
@@ -1039,7 +1083,7 @@ raw3270_del_view(struct raw3270_view *view)
1039 if (!rp->view && test_bit(RAW3270_FLAGS_READY, &rp->flags)) { 1083 if (!rp->view && test_bit(RAW3270_FLAGS_READY, &rp->flags)) {
1040 /* Try to activate another view. */ 1084 /* Try to activate another view. */
1041 list_for_each_entry(nv, &rp->view_list, list) { 1085 list_for_each_entry(nv, &rp->view_list, list) {
1042 if (nv->fn->activate(view) == 0) { 1086 if (nv->fn->activate(nv) == 0) {
1043 rp->view = nv; 1087 rp->view = nv;
1044 break; 1088 break;
1045 } 1089 }
@@ -1063,6 +1107,12 @@ raw3270_delete_device(struct raw3270 *rp)
1063 1107
1064 /* Remove from device chain. */ 1108 /* Remove from device chain. */
1065 down(&raw3270_sem); 1109 down(&raw3270_sem);
1110 if (rp->clttydev)
1111 class_device_destroy(class3270,
1112 MKDEV(IBM_TTY3270_MAJOR, rp->minor));
1113 if (rp->cltubdev)
1114 class_device_destroy(class3270,
1115 MKDEV(IBM_FS3270_MAJOR, rp->minor));
1066 list_del_init(&rp->list); 1116 list_del_init(&rp->list);
1067 up(&raw3270_sem); 1117 up(&raw3270_sem);
1068 1118
@@ -1129,6 +1179,16 @@ raw3270_create_attributes(struct raw3270 *rp)
1129{ 1179{
1130 //FIXME: check return code 1180 //FIXME: check return code
1131 sysfs_create_group(&rp->cdev->dev.kobj, &raw3270_attr_group); 1181 sysfs_create_group(&rp->cdev->dev.kobj, &raw3270_attr_group);
1182 rp->clttydev =
1183 class_device_create(class3270,
1184 MKDEV(IBM_TTY3270_MAJOR, rp->minor),
1185 &rp->cdev->dev, "tty%s",
1186 rp->cdev->dev.bus_id);
1187 rp->cltubdev =
1188 class_device_create(class3270,
1189 MKDEV(IBM_FS3270_MAJOR, rp->minor),
1190 &rp->cdev->dev, "tub%s",
1191 rp->cdev->dev.bus_id);
1132} 1192}
1133 1193
1134/* 1194/*
@@ -1189,13 +1249,13 @@ raw3270_set_online (struct ccw_device *cdev)
1189 return PTR_ERR(rp); 1249 return PTR_ERR(rp);
1190 rc = raw3270_reset_device(rp); 1250 rc = raw3270_reset_device(rp);
1191 if (rc) 1251 if (rc)
1192 return rc; 1252 goto failure;
1193 rc = raw3270_size_device(rp); 1253 rc = raw3270_size_device(rp);
1194 if (rc) 1254 if (rc)
1195 return rc; 1255 goto failure;
1196 rc = raw3270_reset_device(rp); 1256 rc = raw3270_reset_device(rp);
1197 if (rc) 1257 if (rc)
1198 return rc; 1258 goto failure;
1199 raw3270_create_attributes(rp); 1259 raw3270_create_attributes(rp);
1200 set_bit(RAW3270_FLAGS_READY, &rp->flags); 1260 set_bit(RAW3270_FLAGS_READY, &rp->flags);
1201 down(&raw3270_sem); 1261 down(&raw3270_sem);
@@ -1203,6 +1263,10 @@ raw3270_set_online (struct ccw_device *cdev)
1203 np->notifier(rp->minor, 1); 1263 np->notifier(rp->minor, 1);
1204 up(&raw3270_sem); 1264 up(&raw3270_sem);
1205 return 0; 1265 return 0;
1266
1267failure:
1268 raw3270_delete_device(rp);
1269 return rc;
1206} 1270}
1207 1271
1208/* 1272/*
@@ -1217,6 +1281,14 @@ raw3270_remove (struct ccw_device *cdev)
1217 struct raw3270_notifier *np; 1281 struct raw3270_notifier *np;
1218 1282
1219 rp = cdev->dev.driver_data; 1283 rp = cdev->dev.driver_data;
1284 /*
1285 * _remove is the opposite of _probe; it's probe that
1286 * should set up rp. raw3270_remove gets entered for
1287 * devices even if they haven't been varied online.
1288 * Thus, rp may validly be NULL here.
1289 */
1290 if (rp == NULL)
1291 return;
1220 clear_bit(RAW3270_FLAGS_READY, &rp->flags); 1292 clear_bit(RAW3270_FLAGS_READY, &rp->flags);
1221 1293
1222 sysfs_remove_group(&cdev->dev.kobj, &raw3270_attr_group); 1294 sysfs_remove_group(&cdev->dev.kobj, &raw3270_attr_group);
@@ -1301,6 +1373,7 @@ raw3270_init(void)
1301 if (rc == 0) { 1373 if (rc == 0) {
1302 /* Create attributes for early (= console) device. */ 1374 /* Create attributes for early (= console) device. */
1303 down(&raw3270_sem); 1375 down(&raw3270_sem);
1376 class3270 = class_create(THIS_MODULE, "3270");
1304 list_for_each_entry(rp, &raw3270_devices, list) { 1377 list_for_each_entry(rp, &raw3270_devices, list) {
1305 get_device(&rp->cdev->dev); 1378 get_device(&rp->cdev->dev);
1306 raw3270_create_attributes(rp); 1379 raw3270_create_attributes(rp);
@@ -1314,6 +1387,7 @@ static void
1314raw3270_exit(void) 1387raw3270_exit(void)
1315{ 1388{
1316 ccw_driver_unregister(&raw3270_ccw_driver); 1389 ccw_driver_unregister(&raw3270_ccw_driver);
1390 class_destroy(class3270);
1317} 1391}
1318 1392
1319MODULE_LICENSE("GPL"); 1393MODULE_LICENSE("GPL");
@@ -1335,7 +1409,9 @@ EXPORT_SYMBOL(raw3270_find_view);
1335EXPORT_SYMBOL(raw3270_activate_view); 1409EXPORT_SYMBOL(raw3270_activate_view);
1336EXPORT_SYMBOL(raw3270_deactivate_view); 1410EXPORT_SYMBOL(raw3270_deactivate_view);
1337EXPORT_SYMBOL(raw3270_start); 1411EXPORT_SYMBOL(raw3270_start);
1412EXPORT_SYMBOL(raw3270_start_locked);
1338EXPORT_SYMBOL(raw3270_start_irq); 1413EXPORT_SYMBOL(raw3270_start_irq);
1414EXPORT_SYMBOL(raw3270_reset);
1339EXPORT_SYMBOL(raw3270_register_notifier); 1415EXPORT_SYMBOL(raw3270_register_notifier);
1340EXPORT_SYMBOL(raw3270_unregister_notifier); 1416EXPORT_SYMBOL(raw3270_unregister_notifier);
1341EXPORT_SYMBOL(raw3270_wait_queue); 1417EXPORT_SYMBOL(raw3270_wait_queue);
diff --git a/drivers/s390/char/raw3270.h b/drivers/s390/char/raw3270.h
index ed5d4eb9f623..b635bf8e7775 100644
--- a/drivers/s390/char/raw3270.h
+++ b/drivers/s390/char/raw3270.h
@@ -21,6 +21,7 @@
21 21
22/* Local Channel Commands */ 22/* Local Channel Commands */
23#define TC_WRITE 0x01 /* Write */ 23#define TC_WRITE 0x01 /* Write */
24#define TC_RDBUF 0x02 /* Read Buffer */
24#define TC_EWRITE 0x05 /* Erase write */ 25#define TC_EWRITE 0x05 /* Erase write */
25#define TC_READMOD 0x06 /* Read modified */ 26#define TC_READMOD 0x06 /* Read modified */
26#define TC_EWRITEA 0x0d /* Erase write alternate */ 27#define TC_EWRITEA 0x0d /* Erase write alternate */
@@ -76,7 +77,8 @@
76#define TW_KR 0xc2 /* Keyboard restore */ 77#define TW_KR 0xc2 /* Keyboard restore */
77#define TW_PLUSALARM 0x04 /* Add this bit for alarm */ 78#define TW_PLUSALARM 0x04 /* Add this bit for alarm */
78 79
79#define RAW3270_MAXDEVS 256 80#define RAW3270_FIRSTMINOR 1 /* First minor number */
81#define RAW3270_MAXDEVS 255 /* Max number of 3270 devices */
80 82
81/* For TUBGETMOD and TUBSETMOD. Should include. */ 83/* For TUBGETMOD and TUBSETMOD. Should include. */
82struct raw3270_iocb { 84struct raw3270_iocb {
@@ -166,7 +168,10 @@ void raw3270_del_view(struct raw3270_view *);
166void raw3270_deactivate_view(struct raw3270_view *); 168void raw3270_deactivate_view(struct raw3270_view *);
167struct raw3270_view *raw3270_find_view(struct raw3270_fn *, int); 169struct raw3270_view *raw3270_find_view(struct raw3270_fn *, int);
168int raw3270_start(struct raw3270_view *, struct raw3270_request *); 170int raw3270_start(struct raw3270_view *, struct raw3270_request *);
171int raw3270_start_locked(struct raw3270_view *, struct raw3270_request *);
169int raw3270_start_irq(struct raw3270_view *, struct raw3270_request *); 172int raw3270_start_irq(struct raw3270_view *, struct raw3270_request *);
173int raw3270_reset(struct raw3270_view *);
174struct raw3270_view *raw3270_view(struct raw3270_view *);
170 175
171/* Reference count inliner for view structures. */ 176/* Reference count inliner for view structures. */
172static inline void 177static inline void
diff --git a/drivers/s390/char/tape_class.c b/drivers/s390/char/tape_class.c
index ed0cb1f15b4c..fcaee447d6fe 100644
--- a/drivers/s390/char/tape_class.c
+++ b/drivers/s390/char/tape_class.c
@@ -72,6 +72,7 @@ struct tape_class_device *register_tape_dev(
72 72
73 tcd->class_device = class_device_create( 73 tcd->class_device = class_device_create(
74 tape_class, 74 tape_class,
75 NULL,
75 tcd->char_device->dev, 76 tcd->char_device->dev,
76 device, 77 device,
77 "%s", tcd->device_name 78 "%s", tcd->device_name
diff --git a/drivers/s390/char/tty3270.c b/drivers/s390/char/tty3270.c
index 7db5ebce7f0f..4b9069370388 100644
--- a/drivers/s390/char/tty3270.c
+++ b/drivers/s390/char/tty3270.c
@@ -653,18 +653,12 @@ tty3270_activate(struct raw3270_view *view)
653 tp->update_flags = TTY_UPDATE_ALL; 653 tp->update_flags = TTY_UPDATE_ALL;
654 tty3270_set_timer(tp, 1); 654 tty3270_set_timer(tp, 1);
655 spin_unlock_irqrestore(&tp->view.lock, flags); 655 spin_unlock_irqrestore(&tp->view.lock, flags);
656 start_tty(tp->tty);
657 return 0; 656 return 0;
658} 657}
659 658
660static void 659static void
661tty3270_deactivate(struct raw3270_view *view) 660tty3270_deactivate(struct raw3270_view *view)
662{ 661{
663 struct tty3270 *tp;
664
665 tp = (struct tty3270 *) view;
666 if (tp && tp->tty)
667 stop_tty(tp->tty);
668} 662}
669 663
670static int 664static int
@@ -716,13 +710,13 @@ tty3270_alloc_view(void)
716 tp->freemem_pages[pages], PAGE_SIZE); 710 tp->freemem_pages[pages], PAGE_SIZE);
717 } 711 }
718 tp->write = raw3270_request_alloc(TTY3270_OUTPUT_BUFFER_SIZE); 712 tp->write = raw3270_request_alloc(TTY3270_OUTPUT_BUFFER_SIZE);
719 if (!tp->write) 713 if (IS_ERR(tp->write))
720 goto out_pages; 714 goto out_pages;
721 tp->read = raw3270_request_alloc(0); 715 tp->read = raw3270_request_alloc(0);
722 if (!tp->read) 716 if (IS_ERR(tp->read))
723 goto out_write; 717 goto out_write;
724 tp->kreset = raw3270_request_alloc(1); 718 tp->kreset = raw3270_request_alloc(1);
725 if (!tp->kreset) 719 if (IS_ERR(tp->kreset))
726 goto out_read; 720 goto out_read;
727 tp->kbd = kbd_alloc(); 721 tp->kbd = kbd_alloc();
728 if (!tp->kbd) 722 if (!tp->kbd)
@@ -845,7 +839,8 @@ tty3270_del_views(void)
845 int i; 839 int i;
846 840
847 for (i = 0; i < tty3270_max_index; i++) { 841 for (i = 0; i < tty3270_max_index; i++) {
848 tp = (struct tty3270 *) raw3270_find_view(&tty3270_fn, i); 842 tp = (struct tty3270 *)
843 raw3270_find_view(&tty3270_fn, i + RAW3270_FIRSTMINOR);
849 if (!IS_ERR(tp)) 844 if (!IS_ERR(tp))
850 raw3270_del_view(&tp->view); 845 raw3270_del_view(&tp->view);
851 } 846 }
@@ -871,7 +866,9 @@ tty3270_open(struct tty_struct *tty, struct file * filp)
871 if (tty->count > 1) 866 if (tty->count > 1)
872 return 0; 867 return 0;
873 /* Check if the tty3270 is already there. */ 868 /* Check if the tty3270 is already there. */
874 tp = (struct tty3270 *) raw3270_find_view(&tty3270_fn, tty->index); 869 tp = (struct tty3270 *)
870 raw3270_find_view(&tty3270_fn,
871 tty->index + RAW3270_FIRSTMINOR);
875 if (!IS_ERR(tp)) { 872 if (!IS_ERR(tp)) {
876 tty->driver_data = tp; 873 tty->driver_data = tp;
877 tty->winsize.ws_row = tp->view.rows - 2; 874 tty->winsize.ws_row = tp->view.rows - 2;
@@ -903,7 +900,8 @@ tty3270_open(struct tty_struct *tty, struct file * filp)
903 (void (*)(unsigned long)) tty3270_read_tasklet, 900 (void (*)(unsigned long)) tty3270_read_tasklet,
904 (unsigned long) tp->read); 901 (unsigned long) tp->read);
905 902
906 rc = raw3270_add_view(&tp->view, &tty3270_fn, tty->index); 903 rc = raw3270_add_view(&tp->view, &tty3270_fn,
904 tty->index + RAW3270_FIRSTMINOR);
907 if (rc) { 905 if (rc) {
908 tty3270_free_view(tp); 906 tty3270_free_view(tp);
909 return rc; 907 return rc;
@@ -911,8 +909,8 @@ tty3270_open(struct tty_struct *tty, struct file * filp)
911 909
912 rc = tty3270_alloc_screen(tp); 910 rc = tty3270_alloc_screen(tp);
913 if (rc) { 911 if (rc) {
914 raw3270_del_view(&tp->view);
915 raw3270_put_view(&tp->view); 912 raw3270_put_view(&tp->view);
913 raw3270_del_view(&tp->view);
916 return rc; 914 return rc;
917 } 915 }
918 916
@@ -1780,7 +1778,7 @@ tty3270_init(void)
1780 struct tty_driver *driver; 1778 struct tty_driver *driver;
1781 int ret; 1779 int ret;
1782 1780
1783 driver = alloc_tty_driver(256); 1781 driver = alloc_tty_driver(RAW3270_MAXDEVS);
1784 if (!driver) 1782 if (!driver)
1785 return -ENOMEM; 1783 return -ENOMEM;
1786 1784
@@ -1794,6 +1792,7 @@ tty3270_init(void)
1794 driver->driver_name = "ttyTUB"; 1792 driver->driver_name = "ttyTUB";
1795 driver->name = "ttyTUB"; 1793 driver->name = "ttyTUB";
1796 driver->major = IBM_TTY3270_MAJOR; 1794 driver->major = IBM_TTY3270_MAJOR;
1795 driver->minor_start = RAW3270_FIRSTMINOR;
1797 driver->type = TTY_DRIVER_TYPE_SYSTEM; 1796 driver->type = TTY_DRIVER_TYPE_SYSTEM;
1798 driver->subtype = SYSTEM_TYPE_TTY; 1797 driver->subtype = SYSTEM_TYPE_TTY;
1799 driver->init_termios = tty_std_termios; 1798 driver->init_termios = tty_std_termios;
diff --git a/drivers/s390/char/vmlogrdr.c b/drivers/s390/char/vmlogrdr.c
index 491f00c032e8..b2d75de144c6 100644
--- a/drivers/s390/char/vmlogrdr.c
+++ b/drivers/s390/char/vmlogrdr.c
@@ -788,6 +788,7 @@ vmlogrdr_register_device(struct vmlogrdr_priv_t *priv) {
788 } 788 }
789 priv->class_device = class_device_create( 789 priv->class_device = class_device_create(
790 vmlogrdr_class, 790 vmlogrdr_class,
791 NULL,
791 MKDEV(vmlogrdr_major, priv->minor_num), 792 MKDEV(vmlogrdr_major, priv->minor_num),
792 dev, 793 dev,
793 "%s", dev->bus_id ); 794 "%s", dev->bus_id );
diff --git a/drivers/s390/cio/cmf.c b/drivers/s390/cio/cmf.c
index 8cc4f1a940dc..c05b069c2996 100644
--- a/drivers/s390/cio/cmf.c
+++ b/drivers/s390/cio/cmf.c
@@ -30,10 +30,13 @@
30#include <linux/list.h> 30#include <linux/list.h>
31#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/moduleparam.h> 32#include <linux/moduleparam.h>
33#include <linux/slab.h>
34#include <linux/timex.h> /* get_clock() */
33 35
34#include <asm/ccwdev.h> 36#include <asm/ccwdev.h>
35#include <asm/cio.h> 37#include <asm/cio.h>
36#include <asm/cmb.h> 38#include <asm/cmb.h>
39#include <asm/div64.h>
37 40
38#include "cio.h" 41#include "cio.h"
39#include "css.h" 42#include "css.h"
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index 9adc11e8b8bc..811c9d150637 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -22,6 +22,7 @@
22 22
23#include <asm/ccwdev.h> 23#include <asm/ccwdev.h>
24#include <asm/cio.h> 24#include <asm/cio.h>
25#include <asm/param.h> /* HZ */
25 26
26#include "cio.h" 27#include "cio.h"
27#include "css.h" 28#include "css.h"
@@ -252,6 +253,23 @@ cutype_show (struct device *dev, struct device_attribute *attr, char *buf)
252} 253}
253 254
254static ssize_t 255static ssize_t
256modalias_show (struct device *dev, struct device_attribute *attr, char *buf)
257{
258 struct ccw_device *cdev = to_ccwdev(dev);
259 struct ccw_device_id *id = &(cdev->id);
260 int ret;
261
262 ret = sprintf(buf, "ccw:t%04Xm%02x",
263 id->cu_type, id->cu_model);
264 if (id->dev_type != 0)
265 ret += sprintf(buf + ret, "dt%04Xdm%02X\n",
266 id->dev_type, id->dev_model);
267 else
268 ret += sprintf(buf + ret, "dtdm\n");
269 return ret;
270}
271
272static ssize_t
255online_show (struct device *dev, struct device_attribute *attr, char *buf) 273online_show (struct device *dev, struct device_attribute *attr, char *buf)
256{ 274{
257 struct ccw_device *cdev = to_ccwdev(dev); 275 struct ccw_device *cdev = to_ccwdev(dev);
@@ -448,6 +466,7 @@ static DEVICE_ATTR(chpids, 0444, chpids_show, NULL);
448static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL); 466static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL);
449static DEVICE_ATTR(devtype, 0444, devtype_show, NULL); 467static DEVICE_ATTR(devtype, 0444, devtype_show, NULL);
450static DEVICE_ATTR(cutype, 0444, cutype_show, NULL); 468static DEVICE_ATTR(cutype, 0444, cutype_show, NULL);
469static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
451static DEVICE_ATTR(online, 0644, online_show, online_store); 470static DEVICE_ATTR(online, 0644, online_show, online_store);
452extern struct device_attribute dev_attr_cmb_enable; 471extern struct device_attribute dev_attr_cmb_enable;
453static DEVICE_ATTR(availability, 0444, available_show, NULL); 472static DEVICE_ATTR(availability, 0444, available_show, NULL);
@@ -471,6 +490,7 @@ subchannel_add_files (struct device *dev)
471static struct attribute * ccwdev_attrs[] = { 490static struct attribute * ccwdev_attrs[] = {
472 &dev_attr_devtype.attr, 491 &dev_attr_devtype.attr,
473 &dev_attr_cutype.attr, 492 &dev_attr_cutype.attr,
493 &dev_attr_modalias.attr,
474 &dev_attr_online.attr, 494 &dev_attr_online.attr,
475 &dev_attr_cmb_enable.attr, 495 &dev_attr_cmb_enable.attr,
476 &dev_attr_availability.attr, 496 &dev_attr_availability.attr,
diff --git a/drivers/s390/cio/device_fsm.c b/drivers/s390/cio/device_fsm.c
index fbe4202a3f6f..c1c89f4fd4e3 100644
--- a/drivers/s390/cio/device_fsm.c
+++ b/drivers/s390/cio/device_fsm.c
@@ -11,6 +11,8 @@
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/config.h> 12#include <linux/config.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/jiffies.h>
15#include <linux/string.h>
14 16
15#include <asm/ccwdev.h> 17#include <asm/ccwdev.h>
16#include <asm/cio.h> 18#include <asm/cio.h>
diff --git a/drivers/s390/net/fsm.c b/drivers/s390/net/fsm.c
index fa09440d82e5..38f50b7129a2 100644
--- a/drivers/s390/net/fsm.c
+++ b/drivers/s390/net/fsm.c
@@ -16,7 +16,7 @@ MODULE_LICENSE("GPL");
16 16
17fsm_instance * 17fsm_instance *
18init_fsm(char *name, const char **state_names, const char **event_names, int nr_states, 18init_fsm(char *name, const char **state_names, const char **event_names, int nr_states,
19 int nr_events, const fsm_node *tmpl, int tmpl_len, int order) 19 int nr_events, const fsm_node *tmpl, int tmpl_len, gfp_t order)
20{ 20{
21 int i; 21 int i;
22 fsm_instance *this; 22 fsm_instance *this;
diff --git a/drivers/s390/net/fsm.h b/drivers/s390/net/fsm.h
index f9a011001eb6..1b8a7e7c34f3 100644
--- a/drivers/s390/net/fsm.h
+++ b/drivers/s390/net/fsm.h
@@ -110,7 +110,7 @@ extern fsm_instance *
110init_fsm(char *name, const char **state_names, 110init_fsm(char *name, const char **state_names,
111 const char **event_names, 111 const char **event_names,
112 int nr_states, int nr_events, const fsm_node *tmpl, 112 int nr_states, int nr_events, const fsm_node *tmpl,
113 int tmpl_len, int order); 113 int tmpl_len, gfp_t order);
114 114
115/** 115/**
116 * Releases an FSM 116 * Releases an FSM
diff --git a/drivers/s390/net/qeth.h b/drivers/s390/net/qeth.h
index 9963479ba89f..38a2441564d7 100644
--- a/drivers/s390/net/qeth.h
+++ b/drivers/s390/net/qeth.h
@@ -275,6 +275,10 @@ qeth_is_ipa_enabled(struct qeth_ipa_info *ipa, enum qeth_ipa_funcs func)
275 QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT, \ 275 QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT, \
276 QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT, \ 276 QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT, \
277 QETH_MAX_QUEUES,0x103}, \ 277 QETH_MAX_QUEUES,0x103}, \
278 {0x1731,0x06,0x1732,0x06,QETH_CARD_TYPE_OSN,0, \
279 QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT, \
280 QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT, \
281 QETH_MAX_QUEUES,0}, \
278 {0,0,0,0,0,0,0,0,0}} 282 {0,0,0,0,0,0,0,0,0}}
279 283
280#define QETH_REAL_CARD 1 284#define QETH_REAL_CARD 1
@@ -363,10 +367,22 @@ struct qeth_hdr_layer2 {
363 __u8 reserved2[16]; 367 __u8 reserved2[16];
364} __attribute__ ((packed)); 368} __attribute__ ((packed));
365 369
370struct qeth_hdr_osn {
371 __u8 id;
372 __u8 reserved;
373 __u16 seq_no;
374 __u16 reserved2;
375 __u16 control_flags;
376 __u16 pdu_length;
377 __u8 reserved3[18];
378 __u32 ccid;
379} __attribute__ ((packed));
380
366struct qeth_hdr { 381struct qeth_hdr {
367 union { 382 union {
368 struct qeth_hdr_layer2 l2; 383 struct qeth_hdr_layer2 l2;
369 struct qeth_hdr_layer3 l3; 384 struct qeth_hdr_layer3 l3;
385 struct qeth_hdr_osn osn;
370 } hdr; 386 } hdr;
371} __attribute__ ((packed)); 387} __attribute__ ((packed));
372 388
@@ -413,6 +429,7 @@ enum qeth_header_ids {
413 QETH_HEADER_TYPE_LAYER3 = 0x01, 429 QETH_HEADER_TYPE_LAYER3 = 0x01,
414 QETH_HEADER_TYPE_LAYER2 = 0x02, 430 QETH_HEADER_TYPE_LAYER2 = 0x02,
415 QETH_HEADER_TYPE_TSO = 0x03, 431 QETH_HEADER_TYPE_TSO = 0x03,
432 QETH_HEADER_TYPE_OSN = 0x04,
416}; 433};
417/* flags for qeth_hdr.ext_flags */ 434/* flags for qeth_hdr.ext_flags */
418#define QETH_HDR_EXT_VLAN_FRAME 0x01 435#define QETH_HDR_EXT_VLAN_FRAME 0x01
@@ -582,7 +599,6 @@ enum qeth_card_states {
582 * Protocol versions 599 * Protocol versions
583 */ 600 */
584enum qeth_prot_versions { 601enum qeth_prot_versions {
585 QETH_PROT_SNA = 0x0001,
586 QETH_PROT_IPV4 = 0x0004, 602 QETH_PROT_IPV4 = 0x0004,
587 QETH_PROT_IPV6 = 0x0006, 603 QETH_PROT_IPV6 = 0x0006,
588}; 604};
@@ -761,6 +777,11 @@ enum qeth_threads {
761 QETH_RECOVER_THREAD = 2, 777 QETH_RECOVER_THREAD = 2,
762}; 778};
763 779
780struct qeth_osn_info {
781 int (*assist_cb)(struct net_device *dev, void *data);
782 int (*data_cb)(struct sk_buff *skb);
783};
784
764struct qeth_card { 785struct qeth_card {
765 struct list_head list; 786 struct list_head list;
766 enum qeth_card_states state; 787 enum qeth_card_states state;
@@ -803,6 +824,7 @@ struct qeth_card {
803 int use_hard_stop; 824 int use_hard_stop;
804 int (*orig_hard_header)(struct sk_buff *,struct net_device *, 825 int (*orig_hard_header)(struct sk_buff *,struct net_device *,
805 unsigned short,void *,void *,unsigned); 826 unsigned short,void *,void *,unsigned);
827 struct qeth_osn_info osn_info;
806}; 828};
807 829
808struct qeth_card_list_struct { 830struct qeth_card_list_struct {
@@ -916,10 +938,12 @@ qeth_get_hlen(__u8 link_type)
916static inline unsigned short 938static inline unsigned short
917qeth_get_netdev_flags(struct qeth_card *card) 939qeth_get_netdev_flags(struct qeth_card *card)
918{ 940{
919 if (card->options.layer2) 941 if (card->options.layer2 &&
942 (card->info.type == QETH_CARD_TYPE_OSAE))
920 return 0; 943 return 0;
921 switch (card->info.type) { 944 switch (card->info.type) {
922 case QETH_CARD_TYPE_IQD: 945 case QETH_CARD_TYPE_IQD:
946 case QETH_CARD_TYPE_OSN:
923 return IFF_NOARP; 947 return IFF_NOARP;
924#ifdef CONFIG_QETH_IPV6 948#ifdef CONFIG_QETH_IPV6
925 default: 949 default:
@@ -956,9 +980,10 @@ static inline int
956qeth_get_max_mtu_for_card(int cardtype) 980qeth_get_max_mtu_for_card(int cardtype)
957{ 981{
958 switch (cardtype) { 982 switch (cardtype) {
983
959 case QETH_CARD_TYPE_UNKNOWN: 984 case QETH_CARD_TYPE_UNKNOWN:
960 return 61440;
961 case QETH_CARD_TYPE_OSAE: 985 case QETH_CARD_TYPE_OSAE:
986 case QETH_CARD_TYPE_OSN:
962 return 61440; 987 return 61440;
963 case QETH_CARD_TYPE_IQD: 988 case QETH_CARD_TYPE_IQD:
964 return 57344; 989 return 57344;
@@ -1004,6 +1029,7 @@ qeth_mtu_is_valid(struct qeth_card * card, int mtu)
1004 case QETH_CARD_TYPE_IQD: 1029 case QETH_CARD_TYPE_IQD:
1005 return ((mtu >= 576) && 1030 return ((mtu >= 576) &&
1006 (mtu <= card->info.max_mtu + 4096 - 32)); 1031 (mtu <= card->info.max_mtu + 4096 - 32));
1032 case QETH_CARD_TYPE_OSN:
1007 case QETH_CARD_TYPE_UNKNOWN: 1033 case QETH_CARD_TYPE_UNKNOWN:
1008 default: 1034 default:
1009 return 1; 1035 return 1;
@@ -1015,6 +1041,7 @@ qeth_get_arphdr_type(int cardtype, int linktype)
1015{ 1041{
1016 switch (cardtype) { 1042 switch (cardtype) {
1017 case QETH_CARD_TYPE_OSAE: 1043 case QETH_CARD_TYPE_OSAE:
1044 case QETH_CARD_TYPE_OSN:
1018 switch (linktype) { 1045 switch (linktype) {
1019 case QETH_LINK_TYPE_LANE_TR: 1046 case QETH_LINK_TYPE_LANE_TR:
1020 case QETH_LINK_TYPE_HSTR: 1047 case QETH_LINK_TYPE_HSTR:
@@ -1182,4 +1209,16 @@ qeth_fill_header(struct qeth_card *, struct qeth_hdr *,
1182extern void 1209extern void
1183qeth_flush_buffers(struct qeth_qdio_out_q *, int, int, int); 1210qeth_flush_buffers(struct qeth_qdio_out_q *, int, int, int);
1184 1211
1212extern int
1213qeth_osn_assist(struct net_device *, void *, int);
1214
1215extern int
1216qeth_osn_register(unsigned char *read_dev_no,
1217 struct net_device **,
1218 int (*assist_cb)(struct net_device *, void *),
1219 int (*data_cb)(struct sk_buff *));
1220
1221extern void
1222qeth_osn_deregister(struct net_device *);
1223
1185#endif /* __QETH_H__ */ 1224#endif /* __QETH_H__ */
diff --git a/drivers/s390/net/qeth_fs.h b/drivers/s390/net/qeth_fs.h
index 5c9a51ce91b6..c0b4c8d82c45 100644
--- a/drivers/s390/net/qeth_fs.h
+++ b/drivers/s390/net/qeth_fs.h
@@ -12,7 +12,7 @@
12#ifndef __QETH_FS_H__ 12#ifndef __QETH_FS_H__
13#define __QETH_FS_H__ 13#define __QETH_FS_H__
14 14
15#define VERSION_QETH_FS_H "$Revision: 1.9 $" 15#define VERSION_QETH_FS_H "$Revision: 1.10 $"
16 16
17extern const char *VERSION_QETH_PROC_C; 17extern const char *VERSION_QETH_PROC_C;
18extern const char *VERSION_QETH_SYS_C; 18extern const char *VERSION_QETH_SYS_C;
@@ -43,6 +43,12 @@ extern void
43qeth_remove_device_attributes(struct device *dev); 43qeth_remove_device_attributes(struct device *dev);
44 44
45extern int 45extern int
46qeth_create_device_attributes_osn(struct device *dev);
47
48extern void
49qeth_remove_device_attributes_osn(struct device *dev);
50
51extern int
46qeth_create_driver_attributes(void); 52qeth_create_driver_attributes(void);
47 53
48extern void 54extern void
@@ -108,6 +114,8 @@ qeth_get_cardname(struct qeth_card *card)
108 return " OSD Express"; 114 return " OSD Express";
109 case QETH_CARD_TYPE_IQD: 115 case QETH_CARD_TYPE_IQD:
110 return " HiperSockets"; 116 return " HiperSockets";
117 case QETH_CARD_TYPE_OSN:
118 return " OSN QDIO";
111 default: 119 default:
112 return " unknown"; 120 return " unknown";
113 } 121 }
@@ -153,6 +161,8 @@ qeth_get_cardname_short(struct qeth_card *card)
153 } 161 }
154 case QETH_CARD_TYPE_IQD: 162 case QETH_CARD_TYPE_IQD:
155 return "HiperSockets"; 163 return "HiperSockets";
164 case QETH_CARD_TYPE_OSN:
165 return "OSN";
156 default: 166 default:
157 return "unknown"; 167 return "unknown";
158 } 168 }
diff --git a/drivers/s390/net/qeth_main.c b/drivers/s390/net/qeth_main.c
index bd28e2438d7f..692003c9f896 100644
--- a/drivers/s390/net/qeth_main.c
+++ b/drivers/s390/net/qeth_main.c
@@ -196,7 +196,6 @@ qeth_notifier_register(struct task_struct *p, int signum)
196{ 196{
197 struct qeth_notify_list_struct *n_entry; 197 struct qeth_notify_list_struct *n_entry;
198 198
199
200 /*check first if entry already exists*/ 199 /*check first if entry already exists*/
201 spin_lock(&qeth_notify_lock); 200 spin_lock(&qeth_notify_lock);
202 list_for_each_entry(n_entry, &qeth_notify_list, list) { 201 list_for_each_entry(n_entry, &qeth_notify_list, list) {
@@ -1024,7 +1023,10 @@ qeth_set_intial_options(struct qeth_card *card)
1024 card->options.fake_broadcast = 0; 1023 card->options.fake_broadcast = 0;
1025 card->options.add_hhlen = DEFAULT_ADD_HHLEN; 1024 card->options.add_hhlen = DEFAULT_ADD_HHLEN;
1026 card->options.fake_ll = 0; 1025 card->options.fake_ll = 0;
1027 card->options.layer2 = 0; 1026 if (card->info.type == QETH_CARD_TYPE_OSN)
1027 card->options.layer2 = 1;
1028 else
1029 card->options.layer2 = 0;
1028} 1030}
1029 1031
1030/** 1032/**
@@ -1113,19 +1115,20 @@ qeth_determine_card_type(struct qeth_card *card)
1113 1115
1114 QETH_DBF_TEXT(setup, 2, "detcdtyp"); 1116 QETH_DBF_TEXT(setup, 2, "detcdtyp");
1115 1117
1118 card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
1119 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
1116 while (known_devices[i][4]) { 1120 while (known_devices[i][4]) {
1117 if ((CARD_RDEV(card)->id.dev_type == known_devices[i][2]) && 1121 if ((CARD_RDEV(card)->id.dev_type == known_devices[i][2]) &&
1118 (CARD_RDEV(card)->id.dev_model == known_devices[i][3])) { 1122 (CARD_RDEV(card)->id.dev_model == known_devices[i][3])) {
1119 card->info.type = known_devices[i][4]; 1123 card->info.type = known_devices[i][4];
1124 card->qdio.no_out_queues = known_devices[i][8];
1125 card->info.is_multicast_different = known_devices[i][9];
1120 if (is_1920_device(card)) { 1126 if (is_1920_device(card)) {
1121 PRINT_INFO("Priority Queueing not able " 1127 PRINT_INFO("Priority Queueing not able "
1122 "due to hardware limitations!\n"); 1128 "due to hardware limitations!\n");
1123 card->qdio.no_out_queues = 1; 1129 card->qdio.no_out_queues = 1;
1124 card->qdio.default_out_queue = 0; 1130 card->qdio.default_out_queue = 0;
1125 } else { 1131 }
1126 card->qdio.no_out_queues = known_devices[i][8];
1127 }
1128 card->info.is_multicast_different = known_devices[i][9];
1129 return 0; 1132 return 0;
1130 } 1133 }
1131 i++; 1134 i++;
@@ -1149,6 +1152,8 @@ qeth_probe_device(struct ccwgroup_device *gdev)
1149 if (!get_device(dev)) 1152 if (!get_device(dev))
1150 return -ENODEV; 1153 return -ENODEV;
1151 1154
1155 QETH_DBF_TEXT_(setup, 2, "%s", gdev->dev.bus_id);
1156
1152 card = qeth_alloc_card(); 1157 card = qeth_alloc_card();
1153 if (!card) { 1158 if (!card) {
1154 put_device(dev); 1159 put_device(dev);
@@ -1158,28 +1163,27 @@ qeth_probe_device(struct ccwgroup_device *gdev)
1158 card->read.ccwdev = gdev->cdev[0]; 1163 card->read.ccwdev = gdev->cdev[0];
1159 card->write.ccwdev = gdev->cdev[1]; 1164 card->write.ccwdev = gdev->cdev[1];
1160 card->data.ccwdev = gdev->cdev[2]; 1165 card->data.ccwdev = gdev->cdev[2];
1161
1162 if ((rc = qeth_setup_card(card))){
1163 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
1164 put_device(dev);
1165 qeth_free_card(card);
1166 return rc;
1167 }
1168 gdev->dev.driver_data = card; 1166 gdev->dev.driver_data = card;
1169 card->gdev = gdev; 1167 card->gdev = gdev;
1170 gdev->cdev[0]->handler = qeth_irq; 1168 gdev->cdev[0]->handler = qeth_irq;
1171 gdev->cdev[1]->handler = qeth_irq; 1169 gdev->cdev[1]->handler = qeth_irq;
1172 gdev->cdev[2]->handler = qeth_irq; 1170 gdev->cdev[2]->handler = qeth_irq;
1173 1171
1174 rc = qeth_create_device_attributes(dev); 1172 if ((rc = qeth_determine_card_type(card))){
1175 if (rc) { 1173 PRINT_WARN("%s: not a valid card type\n", __func__);
1174 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
1175 put_device(dev);
1176 qeth_free_card(card);
1177 return rc;
1178 }
1179 if ((rc = qeth_setup_card(card))){
1180 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
1176 put_device(dev); 1181 put_device(dev);
1177 qeth_free_card(card); 1182 qeth_free_card(card);
1178 return rc; 1183 return rc;
1179 } 1184 }
1180 if ((rc = qeth_determine_card_type(card))){ 1185 rc = qeth_create_device_attributes(dev);
1181 PRINT_WARN("%s: not a valid card type\n", __func__); 1186 if (rc) {
1182 QETH_DBF_TEXT_(setup, 2, "3err%d", rc);
1183 put_device(dev); 1187 put_device(dev);
1184 qeth_free_card(card); 1188 qeth_free_card(card);
1185 return rc; 1189 return rc;
@@ -1660,6 +1664,8 @@ qeth_check_ipa_data(struct qeth_card *card, struct qeth_cmd_buffer *iob)
1660 netif_carrier_on(card->dev); 1664 netif_carrier_on(card->dev);
1661 qeth_schedule_recovery(card); 1665 qeth_schedule_recovery(card);
1662 return NULL; 1666 return NULL;
1667 case IPA_CMD_MODCCID:
1668 return cmd;
1663 case IPA_CMD_REGISTER_LOCAL_ADDR: 1669 case IPA_CMD_REGISTER_LOCAL_ADDR:
1664 QETH_DBF_TEXT(trace,3, "irla"); 1670 QETH_DBF_TEXT(trace,3, "irla");
1665 break; 1671 break;
@@ -1721,6 +1727,14 @@ qeth_send_control_data_cb(struct qeth_channel *channel,
1721 cmd = qeth_check_ipa_data(card, iob); 1727 cmd = qeth_check_ipa_data(card, iob);
1722 if ((cmd == NULL) && (card->state != CARD_STATE_DOWN)) 1728 if ((cmd == NULL) && (card->state != CARD_STATE_DOWN))
1723 goto out; 1729 goto out;
1730 /*in case of OSN : check if cmd is set */
1731 if (card->info.type == QETH_CARD_TYPE_OSN &&
1732 cmd &&
1733 cmd->hdr.command != IPA_CMD_STARTLAN &&
1734 card->osn_info.assist_cb != NULL) {
1735 card->osn_info.assist_cb(card->dev, cmd);
1736 goto out;
1737 }
1724 1738
1725 spin_lock_irqsave(&card->lock, flags); 1739 spin_lock_irqsave(&card->lock, flags);
1726 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) { 1740 list_for_each_entry_safe(reply, r, &card->cmd_waiter_list, list) {
@@ -1737,8 +1751,7 @@ qeth_send_control_data_cb(struct qeth_channel *channel,
1737 keep_reply = reply->callback(card, 1751 keep_reply = reply->callback(card,
1738 reply, 1752 reply,
1739 (unsigned long)cmd); 1753 (unsigned long)cmd);
1740 } 1754 } else
1741 else
1742 keep_reply = reply->callback(card, 1755 keep_reply = reply->callback(card,
1743 reply, 1756 reply,
1744 (unsigned long)iob); 1757 (unsigned long)iob);
@@ -1768,6 +1781,24 @@ out:
1768 qeth_release_buffer(channel,iob); 1781 qeth_release_buffer(channel,iob);
1769} 1782}
1770 1783
1784static inline void
1785qeth_prepare_control_data(struct qeth_card *card, int len,
1786struct qeth_cmd_buffer *iob)
1787{
1788 qeth_setup_ccw(&card->write,iob->data,len);
1789 iob->callback = qeth_release_buffer;
1790
1791 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1792 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1793 card->seqno.trans_hdr++;
1794 memcpy(QETH_PDU_HEADER_SEQ_NO(iob->data),
1795 &card->seqno.pdu_hdr, QETH_SEQ_NO_LENGTH);
1796 card->seqno.pdu_hdr++;
1797 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob->data),
1798 &card->seqno.pdu_hdr_ack, QETH_SEQ_NO_LENGTH);
1799 QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN);
1800}
1801
1771static int 1802static int
1772qeth_send_control_data(struct qeth_card *card, int len, 1803qeth_send_control_data(struct qeth_card *card, int len,
1773 struct qeth_cmd_buffer *iob, 1804 struct qeth_cmd_buffer *iob,
@@ -1778,24 +1809,11 @@ qeth_send_control_data(struct qeth_card *card, int len,
1778{ 1809{
1779 int rc; 1810 int rc;
1780 unsigned long flags; 1811 unsigned long flags;
1781 struct qeth_reply *reply; 1812 struct qeth_reply *reply = NULL;
1782 struct timer_list timer; 1813 struct timer_list timer;
1783 1814
1784 QETH_DBF_TEXT(trace, 2, "sendctl"); 1815 QETH_DBF_TEXT(trace, 2, "sendctl");
1785 1816
1786 qeth_setup_ccw(&card->write,iob->data,len);
1787
1788 memcpy(QETH_TRANSPORT_HEADER_SEQ_NO(iob->data),
1789 &card->seqno.trans_hdr, QETH_SEQ_NO_LENGTH);
1790 card->seqno.trans_hdr++;
1791
1792 memcpy(QETH_PDU_HEADER_SEQ_NO(iob->data),
1793 &card->seqno.pdu_hdr, QETH_SEQ_NO_LENGTH);
1794 card->seqno.pdu_hdr++;
1795 memcpy(QETH_PDU_HEADER_ACK_SEQ_NO(iob->data),
1796 &card->seqno.pdu_hdr_ack, QETH_SEQ_NO_LENGTH);
1797 iob->callback = qeth_release_buffer;
1798
1799 reply = qeth_alloc_reply(card); 1817 reply = qeth_alloc_reply(card);
1800 if (!reply) { 1818 if (!reply) {
1801 PRINT_WARN("Could no alloc qeth_reply!\n"); 1819 PRINT_WARN("Could no alloc qeth_reply!\n");
@@ -1810,10 +1828,6 @@ qeth_send_control_data(struct qeth_card *card, int len,
1810 init_timer(&timer); 1828 init_timer(&timer);
1811 timer.function = qeth_cmd_timeout; 1829 timer.function = qeth_cmd_timeout;
1812 timer.data = (unsigned long) reply; 1830 timer.data = (unsigned long) reply;
1813 if (IS_IPA(iob->data))
1814 timer.expires = jiffies + QETH_IPA_TIMEOUT;
1815 else
1816 timer.expires = jiffies + QETH_TIMEOUT;
1817 init_waitqueue_head(&reply->wait_q); 1831 init_waitqueue_head(&reply->wait_q);
1818 spin_lock_irqsave(&card->lock, flags); 1832 spin_lock_irqsave(&card->lock, flags);
1819 list_add_tail(&reply->list, &card->cmd_waiter_list); 1833 list_add_tail(&reply->list, &card->cmd_waiter_list);
@@ -1821,6 +1835,11 @@ qeth_send_control_data(struct qeth_card *card, int len,
1821 QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN); 1835 QETH_DBF_HEX(control, 2, iob->data, QETH_DBF_CONTROL_LEN);
1822 wait_event(card->wait_q, 1836 wait_event(card->wait_q,
1823 atomic_compare_and_swap(0,1,&card->write.irq_pending) == 0); 1837 atomic_compare_and_swap(0,1,&card->write.irq_pending) == 0);
1838 qeth_prepare_control_data(card, len, iob);
1839 if (IS_IPA(iob->data))
1840 timer.expires = jiffies + QETH_IPA_TIMEOUT;
1841 else
1842 timer.expires = jiffies + QETH_TIMEOUT;
1824 QETH_DBF_TEXT(trace, 6, "noirqpnd"); 1843 QETH_DBF_TEXT(trace, 6, "noirqpnd");
1825 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags); 1844 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1826 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw, 1845 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
@@ -1848,6 +1867,62 @@ qeth_send_control_data(struct qeth_card *card, int len,
1848} 1867}
1849 1868
1850static int 1869static int
1870qeth_osn_send_control_data(struct qeth_card *card, int len,
1871 struct qeth_cmd_buffer *iob)
1872{
1873 unsigned long flags;
1874 int rc = 0;
1875
1876 QETH_DBF_TEXT(trace, 5, "osndctrd");
1877
1878 wait_event(card->wait_q,
1879 atomic_compare_and_swap(0,1,&card->write.irq_pending) == 0);
1880 qeth_prepare_control_data(card, len, iob);
1881 QETH_DBF_TEXT(trace, 6, "osnoirqp");
1882 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1883 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1884 (addr_t) iob, 0, 0);
1885 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1886 if (rc){
1887 PRINT_WARN("qeth_osn_send_control_data: "
1888 "ccw_device_start rc = %i\n", rc);
1889 QETH_DBF_TEXT_(trace, 2, " err%d", rc);
1890 qeth_release_buffer(iob->channel, iob);
1891 atomic_set(&card->write.irq_pending, 0);
1892 wake_up(&card->wait_q);
1893 }
1894 return rc;
1895}
1896
1897static inline void
1898qeth_prepare_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1899 char prot_type)
1900{
1901 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
1902 memcpy(QETH_IPA_CMD_PROT_TYPE(iob->data),&prot_type,1);
1903 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
1904 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
1905}
1906
1907static int
1908qeth_osn_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1909 int data_len)
1910{
1911 u16 s1, s2;
1912
1913QETH_DBF_TEXT(trace,4,"osndipa");
1914
1915 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1916 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1917 s2 = (u16)data_len;
1918 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1919 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1920 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1921 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1922 return qeth_osn_send_control_data(card, s1, iob);
1923}
1924
1925static int
1851qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob, 1926qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1852 int (*reply_cb) 1927 int (*reply_cb)
1853 (struct qeth_card *,struct qeth_reply*, unsigned long), 1928 (struct qeth_card *,struct qeth_reply*, unsigned long),
@@ -1858,17 +1933,14 @@ qeth_send_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1858 1933
1859 QETH_DBF_TEXT(trace,4,"sendipa"); 1934 QETH_DBF_TEXT(trace,4,"sendipa");
1860 1935
1861 memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE);
1862
1863 if (card->options.layer2) 1936 if (card->options.layer2)
1864 prot_type = QETH_PROT_LAYER2; 1937 if (card->info.type == QETH_CARD_TYPE_OSN)
1938 prot_type = QETH_PROT_OSN2;
1939 else
1940 prot_type = QETH_PROT_LAYER2;
1865 else 1941 else
1866 prot_type = QETH_PROT_TCPIP; 1942 prot_type = QETH_PROT_TCPIP;
1867 1943 qeth_prepare_ipa_cmd(card,iob,prot_type);
1868 memcpy(QETH_IPA_CMD_PROT_TYPE(iob->data),&prot_type,1);
1869 memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data),
1870 &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH);
1871
1872 rc = qeth_send_control_data(card, IPA_CMD_LENGTH, iob, 1944 rc = qeth_send_control_data(card, IPA_CMD_LENGTH, iob,
1873 reply_cb, reply_param); 1945 reply_cb, reply_param);
1874 return rc; 1946 return rc;
@@ -2010,7 +2082,10 @@ qeth_ulp_enable(struct qeth_card *card)
2010 *(QETH_ULP_ENABLE_LINKNUM(iob->data)) = 2082 *(QETH_ULP_ENABLE_LINKNUM(iob->data)) =
2011 (__u8) card->info.portno; 2083 (__u8) card->info.portno;
2012 if (card->options.layer2) 2084 if (card->options.layer2)
2013 prot_type = QETH_PROT_LAYER2; 2085 if (card->info.type == QETH_CARD_TYPE_OSN)
2086 prot_type = QETH_PROT_OSN2;
2087 else
2088 prot_type = QETH_PROT_LAYER2;
2014 else 2089 else
2015 prot_type = QETH_PROT_TCPIP; 2090 prot_type = QETH_PROT_TCPIP;
2016 2091
@@ -2100,15 +2175,21 @@ qeth_check_for_inbound_error(struct qeth_qdio_buffer *buf,
2100} 2175}
2101 2176
2102static inline struct sk_buff * 2177static inline struct sk_buff *
2103qeth_get_skb(unsigned int length) 2178qeth_get_skb(unsigned int length, struct qeth_hdr *hdr)
2104{ 2179{
2105 struct sk_buff* skb; 2180 struct sk_buff* skb;
2181 int add_len;
2182
2183 add_len = 0;
2184 if (hdr->hdr.osn.id == QETH_HEADER_TYPE_OSN)
2185 add_len = sizeof(struct qeth_hdr);
2106#ifdef CONFIG_QETH_VLAN 2186#ifdef CONFIG_QETH_VLAN
2107 if ((skb = dev_alloc_skb(length + VLAN_HLEN))) 2187 else
2108 skb_reserve(skb, VLAN_HLEN); 2188 add_len = VLAN_HLEN;
2109#else
2110 skb = dev_alloc_skb(length);
2111#endif 2189#endif
2190 skb = dev_alloc_skb(length + add_len);
2191 if (skb && add_len)
2192 skb_reserve(skb, add_len);
2112 return skb; 2193 return skb;
2113} 2194}
2114 2195
@@ -2138,7 +2219,10 @@ qeth_get_next_skb(struct qeth_card *card, struct qdio_buffer *buffer,
2138 2219
2139 offset += sizeof(struct qeth_hdr); 2220 offset += sizeof(struct qeth_hdr);
2140 if (card->options.layer2) 2221 if (card->options.layer2)
2141 skb_len = (*hdr)->hdr.l2.pkt_length; 2222 if (card->info.type == QETH_CARD_TYPE_OSN)
2223 skb_len = (*hdr)->hdr.osn.pdu_length;
2224 else
2225 skb_len = (*hdr)->hdr.l2.pkt_length;
2142 else 2226 else
2143 skb_len = (*hdr)->hdr.l3.length; 2227 skb_len = (*hdr)->hdr.l3.length;
2144 2228
@@ -2146,15 +2230,15 @@ qeth_get_next_skb(struct qeth_card *card, struct qdio_buffer *buffer,
2146 return NULL; 2230 return NULL;
2147 if (card->options.fake_ll){ 2231 if (card->options.fake_ll){
2148 if(card->dev->type == ARPHRD_IEEE802_TR){ 2232 if(card->dev->type == ARPHRD_IEEE802_TR){
2149 if (!(skb = qeth_get_skb(skb_len+QETH_FAKE_LL_LEN_TR))) 2233 if (!(skb = qeth_get_skb(skb_len+QETH_FAKE_LL_LEN_TR, *hdr)))
2150 goto no_mem; 2234 goto no_mem;
2151 skb_reserve(skb,QETH_FAKE_LL_LEN_TR); 2235 skb_reserve(skb,QETH_FAKE_LL_LEN_TR);
2152 } else { 2236 } else {
2153 if (!(skb = qeth_get_skb(skb_len+QETH_FAKE_LL_LEN_ETH))) 2237 if (!(skb = qeth_get_skb(skb_len+QETH_FAKE_LL_LEN_ETH, *hdr)))
2154 goto no_mem; 2238 goto no_mem;
2155 skb_reserve(skb,QETH_FAKE_LL_LEN_ETH); 2239 skb_reserve(skb,QETH_FAKE_LL_LEN_ETH);
2156 } 2240 }
2157 } else if (!(skb = qeth_get_skb(skb_len))) 2241 } else if (!(skb = qeth_get_skb(skb_len, *hdr)))
2158 goto no_mem; 2242 goto no_mem;
2159 data_ptr = element->addr + offset; 2243 data_ptr = element->addr + offset;
2160 while (skb_len) { 2244 while (skb_len) {
@@ -2453,8 +2537,12 @@ qeth_process_inbound_buffer(struct qeth_card *card,
2453 skb->dev = card->dev; 2537 skb->dev = card->dev;
2454 if (hdr->hdr.l2.id == QETH_HEADER_TYPE_LAYER2) 2538 if (hdr->hdr.l2.id == QETH_HEADER_TYPE_LAYER2)
2455 vlan_tag = qeth_layer2_rebuild_skb(card, skb, hdr); 2539 vlan_tag = qeth_layer2_rebuild_skb(card, skb, hdr);
2456 else 2540 else if (hdr->hdr.l3.id == QETH_HEADER_TYPE_LAYER3)
2457 qeth_rebuild_skb(card, skb, hdr); 2541 qeth_rebuild_skb(card, skb, hdr);
2542 else { /*in case of OSN*/
2543 skb_push(skb, sizeof(struct qeth_hdr));
2544 memcpy(skb->data, hdr, sizeof(struct qeth_hdr));
2545 }
2458 /* is device UP ? */ 2546 /* is device UP ? */
2459 if (!(card->dev->flags & IFF_UP)){ 2547 if (!(card->dev->flags & IFF_UP)){
2460 dev_kfree_skb_any(skb); 2548 dev_kfree_skb_any(skb);
@@ -2465,7 +2553,10 @@ qeth_process_inbound_buffer(struct qeth_card *card,
2465 vlan_hwaccel_rx(skb, card->vlangrp, vlan_tag); 2553 vlan_hwaccel_rx(skb, card->vlangrp, vlan_tag);
2466 else 2554 else
2467#endif 2555#endif
2468 rxrc = netif_rx(skb); 2556 if (card->info.type == QETH_CARD_TYPE_OSN)
2557 rxrc = card->osn_info.data_cb(skb);
2558 else
2559 rxrc = netif_rx(skb);
2469 card->dev->last_rx = jiffies; 2560 card->dev->last_rx = jiffies;
2470 card->stats.rx_packets++; 2561 card->stats.rx_packets++;
2471 card->stats.rx_bytes += skb->len; 2562 card->stats.rx_bytes += skb->len;
@@ -3150,8 +3241,6 @@ qeth_init_qdio_info(struct qeth_card *card)
3150 INIT_LIST_HEAD(&card->qdio.in_buf_pool.entry_list); 3241 INIT_LIST_HEAD(&card->qdio.in_buf_pool.entry_list);
3151 INIT_LIST_HEAD(&card->qdio.init_pool.entry_list); 3242 INIT_LIST_HEAD(&card->qdio.init_pool.entry_list);
3152 /* outbound */ 3243 /* outbound */
3153 card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
3154 card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
3155} 3244}
3156 3245
3157static int 3246static int
@@ -3466,7 +3555,7 @@ qeth_mpc_initialize(struct qeth_card *card)
3466 3555
3467 return 0; 3556 return 0;
3468out_qdio: 3557out_qdio:
3469 qeth_qdio_clear_card(card, card->info.type==QETH_CARD_TYPE_OSAE); 3558 qeth_qdio_clear_card(card, card->info.type!=QETH_CARD_TYPE_IQD);
3470 return rc; 3559 return rc;
3471} 3560}
3472 3561
@@ -3491,6 +3580,9 @@ qeth_get_netdevice(enum qeth_card_types type, enum qeth_link_types linktype)
3491 case QETH_CARD_TYPE_IQD: 3580 case QETH_CARD_TYPE_IQD:
3492 dev = alloc_netdev(0, "hsi%d", ether_setup); 3581 dev = alloc_netdev(0, "hsi%d", ether_setup);
3493 break; 3582 break;
3583 case QETH_CARD_TYPE_OSN:
3584 dev = alloc_netdev(0, "osn%d", ether_setup);
3585 break;
3494 default: 3586 default:
3495 dev = alloc_etherdev(0); 3587 dev = alloc_etherdev(0);
3496 } 3588 }
@@ -3655,7 +3747,8 @@ qeth_open(struct net_device *dev)
3655 if (card->state != CARD_STATE_SOFTSETUP) 3747 if (card->state != CARD_STATE_SOFTSETUP)
3656 return -ENODEV; 3748 return -ENODEV;
3657 3749
3658 if ( (card->options.layer2) && 3750 if ( (card->info.type != QETH_CARD_TYPE_OSN) &&
3751 (card->options.layer2) &&
3659 (!card->info.layer2_mac_registered)) { 3752 (!card->info.layer2_mac_registered)) {
3660 QETH_DBF_TEXT(trace,4,"nomacadr"); 3753 QETH_DBF_TEXT(trace,4,"nomacadr");
3661 return -EPERM; 3754 return -EPERM;
@@ -3693,6 +3786,9 @@ qeth_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
3693{ 3786{
3694 int cast_type = RTN_UNSPEC; 3787 int cast_type = RTN_UNSPEC;
3695 3788
3789 if (card->info.type == QETH_CARD_TYPE_OSN)
3790 return cast_type;
3791
3696 if (skb->dst && skb->dst->neighbour){ 3792 if (skb->dst && skb->dst->neighbour){
3697 cast_type = skb->dst->neighbour->type; 3793 cast_type = skb->dst->neighbour->type;
3698 if ((cast_type == RTN_BROADCAST) || 3794 if ((cast_type == RTN_BROADCAST) ||
@@ -3782,13 +3878,16 @@ static inline int
3782qeth_prepare_skb(struct qeth_card *card, struct sk_buff **skb, 3878qeth_prepare_skb(struct qeth_card *card, struct sk_buff **skb,
3783 struct qeth_hdr **hdr, int ipv) 3879 struct qeth_hdr **hdr, int ipv)
3784{ 3880{
3785 int rc; 3881 int rc = 0;
3786#ifdef CONFIG_QETH_VLAN 3882#ifdef CONFIG_QETH_VLAN
3787 u16 *tag; 3883 u16 *tag;
3788#endif 3884#endif
3789 3885
3790 QETH_DBF_TEXT(trace, 6, "prepskb"); 3886 QETH_DBF_TEXT(trace, 6, "prepskb");
3791 3887 if (card->info.type == QETH_CARD_TYPE_OSN) {
3888 *hdr = (struct qeth_hdr *)(*skb)->data;
3889 return rc;
3890 }
3792 rc = qeth_realloc_headroom(card, skb, sizeof(struct qeth_hdr)); 3891 rc = qeth_realloc_headroom(card, skb, sizeof(struct qeth_hdr));
3793 if (rc) 3892 if (rc)
3794 return rc; 3893 return rc;
@@ -4291,8 +4390,14 @@ qeth_send_packet(struct qeth_card *card, struct sk_buff *skb)
4291 } 4390 }
4292 } 4391 }
4293 } 4392 }
4393 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
4394 (skb->protocol == htons(ETH_P_IPV6))) {
4395 dev_kfree_skb_any(skb);
4396 return 0;
4397 }
4294 cast_type = qeth_get_cast_type(card, skb); 4398 cast_type = qeth_get_cast_type(card, skb);
4295 if ((cast_type == RTN_BROADCAST) && (card->info.broadcast_capable == 0)){ 4399 if ((cast_type == RTN_BROADCAST) &&
4400 (card->info.broadcast_capable == 0)){
4296 card->stats.tx_dropped++; 4401 card->stats.tx_dropped++;
4297 card->stats.tx_errors++; 4402 card->stats.tx_errors++;
4298 dev_kfree_skb_any(skb); 4403 dev_kfree_skb_any(skb);
@@ -4320,7 +4425,8 @@ qeth_send_packet(struct qeth_card *card, struct sk_buff *skb)
4320 QETH_DBF_TEXT_(trace, 4, "pskbe%d", rc); 4425 QETH_DBF_TEXT_(trace, 4, "pskbe%d", rc);
4321 return rc; 4426 return rc;
4322 } 4427 }
4323 qeth_fill_header(card, hdr, skb, ipv, cast_type); 4428 if (card->info.type != QETH_CARD_TYPE_OSN)
4429 qeth_fill_header(card, hdr, skb, ipv, cast_type);
4324 } 4430 }
4325 4431
4326 if (large_send == QETH_LARGE_SEND_EDDP) { 4432 if (large_send == QETH_LARGE_SEND_EDDP) {
@@ -4381,6 +4487,7 @@ qeth_mdio_read(struct net_device *dev, int phy_id, int regnum)
4381 case MII_BMCR: /* Basic mode control register */ 4487 case MII_BMCR: /* Basic mode control register */
4382 rc = BMCR_FULLDPLX; 4488 rc = BMCR_FULLDPLX;
4383 if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH)&& 4489 if ((card->info.link_type != QETH_LINK_TYPE_GBIT_ETH)&&
4490 (card->info.link_type != QETH_LINK_TYPE_OSN) &&
4384 (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH)) 4491 (card->info.link_type != QETH_LINK_TYPE_10GBIT_ETH))
4385 rc |= BMCR_SPEED100; 4492 rc |= BMCR_SPEED100;
4386 break; 4493 break;
@@ -5004,6 +5111,9 @@ qeth_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
5004 (card->state != CARD_STATE_SOFTSETUP)) 5111 (card->state != CARD_STATE_SOFTSETUP))
5005 return -ENODEV; 5112 return -ENODEV;
5006 5113
5114 if (card->info.type == QETH_CARD_TYPE_OSN)
5115 return -EPERM;
5116
5007 switch (cmd){ 5117 switch (cmd){
5008 case SIOC_QETH_ARP_SET_NO_ENTRIES: 5118 case SIOC_QETH_ARP_SET_NO_ENTRIES:
5009 if ( !capable(CAP_NET_ADMIN) || 5119 if ( !capable(CAP_NET_ADMIN) ||
@@ -5329,6 +5439,9 @@ qeth_set_multicast_list(struct net_device *dev)
5329{ 5439{
5330 struct qeth_card *card = (struct qeth_card *) dev->priv; 5440 struct qeth_card *card = (struct qeth_card *) dev->priv;
5331 5441
5442 if (card->info.type == QETH_CARD_TYPE_OSN)
5443 return ;
5444
5332 QETH_DBF_TEXT(trace,3,"setmulti"); 5445 QETH_DBF_TEXT(trace,3,"setmulti");
5333 qeth_delete_mc_addresses(card); 5446 qeth_delete_mc_addresses(card);
5334 qeth_add_multicast_ipv4(card); 5447 qeth_add_multicast_ipv4(card);
@@ -5370,6 +5483,94 @@ qeth_get_addr_buffer(enum qeth_prot_versions prot)
5370 return addr; 5483 return addr;
5371} 5484}
5372 5485
5486int
5487qeth_osn_assist(struct net_device *dev,
5488 void *data,
5489 int data_len)
5490{
5491 struct qeth_cmd_buffer *iob;
5492 struct qeth_card *card;
5493 int rc;
5494
5495 QETH_DBF_TEXT(trace, 2, "osnsdmc");
5496 if (!dev)
5497 return -ENODEV;
5498 card = (struct qeth_card *)dev->priv;
5499 if (!card)
5500 return -ENODEV;
5501 if ((card->state != CARD_STATE_UP) &&
5502 (card->state != CARD_STATE_SOFTSETUP))
5503 return -ENODEV;
5504 iob = qeth_wait_for_buffer(&card->write);
5505 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
5506 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
5507 return rc;
5508}
5509
5510static struct net_device *
5511qeth_netdev_by_devno(unsigned char *read_dev_no)
5512{
5513 struct qeth_card *card;
5514 struct net_device *ndev;
5515 unsigned char *readno;
5516 __u16 temp_dev_no, card_dev_no;
5517 char *endp;
5518 unsigned long flags;
5519
5520 ndev = NULL;
5521 memcpy(&temp_dev_no, read_dev_no, 2);
5522 read_lock_irqsave(&qeth_card_list.rwlock, flags);
5523 list_for_each_entry(card, &qeth_card_list.list, list) {
5524 readno = CARD_RDEV_ID(card);
5525 readno += (strlen(readno) - 4);
5526 card_dev_no = simple_strtoul(readno, &endp, 16);
5527 if (card_dev_no == temp_dev_no) {
5528 ndev = card->dev;
5529 break;
5530 }
5531 }
5532 read_unlock_irqrestore(&qeth_card_list.rwlock, flags);
5533 return ndev;
5534}
5535
5536int
5537qeth_osn_register(unsigned char *read_dev_no,
5538 struct net_device **dev,
5539 int (*assist_cb)(struct net_device *, void *),
5540 int (*data_cb)(struct sk_buff *))
5541{
5542 struct qeth_card * card;
5543
5544 QETH_DBF_TEXT(trace, 2, "osnreg");
5545 *dev = qeth_netdev_by_devno(read_dev_no);
5546 if (*dev == NULL)
5547 return -ENODEV;
5548 card = (struct qeth_card *)(*dev)->priv;
5549 if (!card)
5550 return -ENODEV;
5551 if ((assist_cb == NULL) || (data_cb == NULL))
5552 return -EINVAL;
5553 card->osn_info.assist_cb = assist_cb;
5554 card->osn_info.data_cb = data_cb;
5555 return 0;
5556}
5557
5558void
5559qeth_osn_deregister(struct net_device * dev)
5560{
5561 struct qeth_card *card;
5562
5563 QETH_DBF_TEXT(trace, 2, "osndereg");
5564 if (!dev)
5565 return;
5566 card = (struct qeth_card *)dev->priv;
5567 if (!card)
5568 return;
5569 card->osn_info.assist_cb = NULL;
5570 card->osn_info.data_cb = NULL;
5571 return;
5572}
5573
5373static void 5574static void
5374qeth_delete_mc_addresses(struct qeth_card *card) 5575qeth_delete_mc_addresses(struct qeth_card *card)
5375{ 5576{
@@ -5700,6 +5901,12 @@ qeth_layer2_set_mac_address(struct net_device *dev, void *p)
5700 QETH_DBF_TEXT(trace, 3, "setmcLY3"); 5901 QETH_DBF_TEXT(trace, 3, "setmcLY3");
5701 return -EOPNOTSUPP; 5902 return -EOPNOTSUPP;
5702 } 5903 }
5904 if (card->info.type == QETH_CARD_TYPE_OSN) {
5905 PRINT_WARN("Setting MAC address on %s is not supported.\n",
5906 dev->name);
5907 QETH_DBF_TEXT(trace, 3, "setmcOSN");
5908 return -EOPNOTSUPP;
5909 }
5703 QETH_DBF_TEXT_(trace, 3, "%s", CARD_BUS_ID(card)); 5910 QETH_DBF_TEXT_(trace, 3, "%s", CARD_BUS_ID(card));
5704 QETH_DBF_HEX(trace, 3, addr->sa_data, OSA_ADDR_LEN); 5911 QETH_DBF_HEX(trace, 3, addr->sa_data, OSA_ADDR_LEN);
5705 rc = qeth_layer2_send_delmac(card, &card->dev->dev_addr[0]); 5912 rc = qeth_layer2_send_delmac(card, &card->dev->dev_addr[0]);
@@ -6076,9 +6283,8 @@ qeth_netdev_init(struct net_device *dev)
6076 qeth_get_hlen(card->info.link_type) + card->options.add_hhlen; 6283 qeth_get_hlen(card->info.link_type) + card->options.add_hhlen;
6077 dev->addr_len = OSA_ADDR_LEN; 6284 dev->addr_len = OSA_ADDR_LEN;
6078 dev->mtu = card->info.initial_mtu; 6285 dev->mtu = card->info.initial_mtu;
6079 6286 if (card->info.type != QETH_CARD_TYPE_OSN)
6080 SET_ETHTOOL_OPS(dev, &qeth_ethtool_ops); 6287 SET_ETHTOOL_OPS(dev, &qeth_ethtool_ops);
6081
6082 SET_MODULE_OWNER(dev); 6288 SET_MODULE_OWNER(dev);
6083 return 0; 6289 return 0;
6084} 6290}
@@ -6095,6 +6301,7 @@ qeth_init_func_level(struct qeth_card *card)
6095 QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT; 6301 QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT;
6096 } else { 6302 } else {
6097 if (card->info.type == QETH_CARD_TYPE_IQD) 6303 if (card->info.type == QETH_CARD_TYPE_IQD)
6304 /*FIXME:why do we have same values for dis and ena for osae??? */
6098 card->info.func_level = 6305 card->info.func_level =
6099 QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT; 6306 QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT;
6100 else 6307 else
@@ -6124,7 +6331,7 @@ retry:
6124 ccw_device_set_online(CARD_WDEV(card)); 6331 ccw_device_set_online(CARD_WDEV(card));
6125 ccw_device_set_online(CARD_DDEV(card)); 6332 ccw_device_set_online(CARD_DDEV(card));
6126 } 6333 }
6127 rc = qeth_qdio_clear_card(card,card->info.type==QETH_CARD_TYPE_OSAE); 6334 rc = qeth_qdio_clear_card(card,card->info.type!=QETH_CARD_TYPE_IQD);
6128 if (rc == -ERESTARTSYS) { 6335 if (rc == -ERESTARTSYS) {
6129 QETH_DBF_TEXT(setup, 2, "break1"); 6336 QETH_DBF_TEXT(setup, 2, "break1");
6130 return rc; 6337 return rc;
@@ -6176,8 +6383,8 @@ retry:
6176 card->dev = qeth_get_netdevice(card->info.type, 6383 card->dev = qeth_get_netdevice(card->info.type,
6177 card->info.link_type); 6384 card->info.link_type);
6178 if (!card->dev){ 6385 if (!card->dev){
6179 qeth_qdio_clear_card(card, card->info.type == 6386 qeth_qdio_clear_card(card, card->info.type !=
6180 QETH_CARD_TYPE_OSAE); 6387 QETH_CARD_TYPE_IQD);
6181 rc = -ENODEV; 6388 rc = -ENODEV;
6182 QETH_DBF_TEXT_(setup, 2, "6err%d", rc); 6389 QETH_DBF_TEXT_(setup, 2, "6err%d", rc);
6183 goto out; 6390 goto out;
@@ -7084,6 +7291,8 @@ qeth_softsetup_card(struct qeth_card *card)
7084 return rc; 7291 return rc;
7085 } else 7292 } else
7086 card->lan_online = 1; 7293 card->lan_online = 1;
7294 if (card->info.type==QETH_CARD_TYPE_OSN)
7295 goto out;
7087 if (card->options.layer2) { 7296 if (card->options.layer2) {
7088 card->dev->features |= 7297 card->dev->features |=
7089 NETIF_F_HW_VLAN_FILTER | 7298 NETIF_F_HW_VLAN_FILTER |
@@ -7255,7 +7464,8 @@ qeth_stop_card(struct qeth_card *card, int recovery_mode)
7255 if (card->read.state == CH_STATE_UP && 7464 if (card->read.state == CH_STATE_UP &&
7256 card->write.state == CH_STATE_UP && 7465 card->write.state == CH_STATE_UP &&
7257 (card->state == CARD_STATE_UP)) { 7466 (card->state == CARD_STATE_UP)) {
7258 if(recovery_mode) { 7467 if (recovery_mode &&
7468 card->info.type != QETH_CARD_TYPE_OSN) {
7259 qeth_stop(card->dev); 7469 qeth_stop(card->dev);
7260 } else { 7470 } else {
7261 rtnl_lock(); 7471 rtnl_lock();
@@ -7437,7 +7647,8 @@ qeth_start_again(struct qeth_card *card, int recovery_mode)
7437{ 7647{
7438 QETH_DBF_TEXT(setup ,2, "startag"); 7648 QETH_DBF_TEXT(setup ,2, "startag");
7439 7649
7440 if(recovery_mode) { 7650 if (recovery_mode &&
7651 card->info.type != QETH_CARD_TYPE_OSN) {
7441 qeth_open(card->dev); 7652 qeth_open(card->dev);
7442 } else { 7653 } else {
7443 rtnl_lock(); 7654 rtnl_lock();
@@ -7469,33 +7680,36 @@ qeth_start_again(struct qeth_card *card, int recovery_mode)
7469static void qeth_make_parameters_consistent(struct qeth_card *card) 7680static void qeth_make_parameters_consistent(struct qeth_card *card)
7470{ 7681{
7471 7682
7472 if (card->options.layer2) { 7683 if (card->options.layer2 == 0)
7473 if (card->info.type == QETH_CARD_TYPE_IQD) { 7684 return;
7474 PRINT_ERR("Device %s does not support " \ 7685 if (card->info.type == QETH_CARD_TYPE_OSN)
7475 "layer 2 functionality. " \ 7686 return;
7476 "Ignoring layer2 option.\n",CARD_BUS_ID(card)); 7687 if (card->info.type == QETH_CARD_TYPE_IQD) {
7477 } 7688 PRINT_ERR("Device %s does not support layer 2 functionality." \
7478 IGNORE_PARAM_NEQ(route4.type, NO_ROUTER, NO_ROUTER, 7689 " Ignoring layer2 option.\n",CARD_BUS_ID(card));
7479 "Routing options are"); 7690 card->options.layer2 = 0;
7691 return;
7692 }
7693 IGNORE_PARAM_NEQ(route4.type, NO_ROUTER, NO_ROUTER,
7694 "Routing options are");
7480#ifdef CONFIG_QETH_IPV6 7695#ifdef CONFIG_QETH_IPV6
7481 IGNORE_PARAM_NEQ(route6.type, NO_ROUTER, NO_ROUTER, 7696 IGNORE_PARAM_NEQ(route6.type, NO_ROUTER, NO_ROUTER,
7482 "Routing options are"); 7697 "Routing options are");
7483#endif 7698#endif
7484 IGNORE_PARAM_EQ(checksum_type, HW_CHECKSUMMING, 7699 IGNORE_PARAM_EQ(checksum_type, HW_CHECKSUMMING,
7485 QETH_CHECKSUM_DEFAULT, 7700 QETH_CHECKSUM_DEFAULT,
7486 "Checksumming options are"); 7701 "Checksumming options are");
7487 IGNORE_PARAM_NEQ(broadcast_mode, QETH_TR_BROADCAST_ALLRINGS, 7702 IGNORE_PARAM_NEQ(broadcast_mode, QETH_TR_BROADCAST_ALLRINGS,
7488 QETH_TR_BROADCAST_ALLRINGS, 7703 QETH_TR_BROADCAST_ALLRINGS,
7489 "Broadcast mode options are"); 7704 "Broadcast mode options are");
7490 IGNORE_PARAM_NEQ(macaddr_mode, QETH_TR_MACADDR_NONCANONICAL, 7705 IGNORE_PARAM_NEQ(macaddr_mode, QETH_TR_MACADDR_NONCANONICAL,
7491 QETH_TR_MACADDR_NONCANONICAL, 7706 QETH_TR_MACADDR_NONCANONICAL,
7492 "Canonical MAC addr options are"); 7707 "Canonical MAC addr options are");
7493 IGNORE_PARAM_NEQ(fake_broadcast, 0, 0, 7708 IGNORE_PARAM_NEQ(fake_broadcast, 0, 0,
7494 "Broadcast faking options are"); 7709 "Broadcast faking options are");
7495 IGNORE_PARAM_NEQ(add_hhlen, DEFAULT_ADD_HHLEN, 7710 IGNORE_PARAM_NEQ(add_hhlen, DEFAULT_ADD_HHLEN,
7496 DEFAULT_ADD_HHLEN,"Option add_hhlen is"); 7711 DEFAULT_ADD_HHLEN,"Option add_hhlen is");
7497 IGNORE_PARAM_NEQ(fake_ll, 0, 0,"Option fake_ll is"); 7712 IGNORE_PARAM_NEQ(fake_ll, 0, 0,"Option fake_ll is");
7498 }
7499} 7713}
7500 7714
7501 7715
@@ -7525,8 +7739,7 @@ __qeth_set_online(struct ccwgroup_device *gdev, int recovery_mode)
7525 return -EIO; 7739 return -EIO;
7526 } 7740 }
7527 7741
7528 if (card->options.layer2) 7742 qeth_make_parameters_consistent(card);
7529 qeth_make_parameters_consistent(card);
7530 7743
7531 if ((rc = qeth_hardsetup_card(card))){ 7744 if ((rc = qeth_hardsetup_card(card))){
7532 QETH_DBF_TEXT_(setup, 2, "2err%d", rc); 7745 QETH_DBF_TEXT_(setup, 2, "2err%d", rc);
@@ -7585,6 +7798,7 @@ qeth_set_online(struct ccwgroup_device *gdev)
7585static struct ccw_device_id qeth_ids[] = { 7798static struct ccw_device_id qeth_ids[] = {
7586 {CCW_DEVICE(0x1731, 0x01), driver_info:QETH_CARD_TYPE_OSAE}, 7799 {CCW_DEVICE(0x1731, 0x01), driver_info:QETH_CARD_TYPE_OSAE},
7587 {CCW_DEVICE(0x1731, 0x05), driver_info:QETH_CARD_TYPE_IQD}, 7800 {CCW_DEVICE(0x1731, 0x05), driver_info:QETH_CARD_TYPE_IQD},
7801 {CCW_DEVICE(0x1731, 0x06), driver_info:QETH_CARD_TYPE_OSN},
7588 {}, 7802 {},
7589}; 7803};
7590MODULE_DEVICE_TABLE(ccw, qeth_ids); 7804MODULE_DEVICE_TABLE(ccw, qeth_ids);
@@ -8329,6 +8543,9 @@ again:
8329 printk("qeth: removed\n"); 8543 printk("qeth: removed\n");
8330} 8544}
8331 8545
8546EXPORT_SYMBOL(qeth_osn_register);
8547EXPORT_SYMBOL(qeth_osn_deregister);
8548EXPORT_SYMBOL(qeth_osn_assist);
8332module_init(qeth_init); 8549module_init(qeth_init);
8333module_exit(qeth_exit); 8550module_exit(qeth_exit);
8334MODULE_AUTHOR("Frank Pavlic <pavlic@de.ibm.com>"); 8551MODULE_AUTHOR("Frank Pavlic <pavlic@de.ibm.com>");
diff --git a/drivers/s390/net/qeth_mpc.c b/drivers/s390/net/qeth_mpc.c
index f685ecc7da99..30e053d3cac2 100644
--- a/drivers/s390/net/qeth_mpc.c
+++ b/drivers/s390/net/qeth_mpc.c
@@ -11,7 +11,7 @@
11#include <asm/cio.h> 11#include <asm/cio.h>
12#include "qeth_mpc.h" 12#include "qeth_mpc.h"
13 13
14const char *VERSION_QETH_MPC_C = "$Revision: 1.11 $"; 14const char *VERSION_QETH_MPC_C = "$Revision: 1.12 $";
15 15
16unsigned char IDX_ACTIVATE_READ[]={ 16unsigned char IDX_ACTIVATE_READ[]={
17 0x00,0x00,0x80,0x00, 0x00,0x00,0x00,0x00, 17 0x00,0x00,0x80,0x00, 0x00,0x00,0x00,0x00,
@@ -138,7 +138,9 @@ unsigned char IPA_PDU_HEADER[]={
138 sizeof(struct qeth_ipa_cmd)%256, 138 sizeof(struct qeth_ipa_cmd)%256,
139 0x00, 139 0x00,
140 sizeof(struct qeth_ipa_cmd)/256, 140 sizeof(struct qeth_ipa_cmd)/256,
141 sizeof(struct qeth_ipa_cmd),0x05, 0x77,0x77,0x77,0x77, 141 sizeof(struct qeth_ipa_cmd)%256,
142 0x05,
143 0x77,0x77,0x77,0x77,
142 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 144 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,
143 0x01,0x00, 145 0x01,0x00,
144 sizeof(struct qeth_ipa_cmd)/256, 146 sizeof(struct qeth_ipa_cmd)/256,
diff --git a/drivers/s390/net/qeth_mpc.h b/drivers/s390/net/qeth_mpc.h
index 3d916b5c5d09..7edc5f1fc0d2 100644
--- a/drivers/s390/net/qeth_mpc.h
+++ b/drivers/s390/net/qeth_mpc.h
@@ -46,13 +46,16 @@ extern unsigned char IPA_PDU_HEADER[];
46/* IP Assist related definitions */ 46/* IP Assist related definitions */
47/*****************************************************************************/ 47/*****************************************************************************/
48#define IPA_CMD_INITIATOR_HOST 0x00 48#define IPA_CMD_INITIATOR_HOST 0x00
49#define IPA_CMD_INITIATOR_HYDRA 0x01 49#define IPA_CMD_INITIATOR_OSA 0x01
50#define IPA_CMD_INITIATOR_HOST_REPLY 0x80
51#define IPA_CMD_INITIATOR_OSA_REPLY 0x81
50#define IPA_CMD_PRIM_VERSION_NO 0x01 52#define IPA_CMD_PRIM_VERSION_NO 0x01
51 53
52enum qeth_card_types { 54enum qeth_card_types {
53 QETH_CARD_TYPE_UNKNOWN = 0, 55 QETH_CARD_TYPE_UNKNOWN = 0,
54 QETH_CARD_TYPE_OSAE = 10, 56 QETH_CARD_TYPE_OSAE = 10,
55 QETH_CARD_TYPE_IQD = 1234, 57 QETH_CARD_TYPE_IQD = 1234,
58 QETH_CARD_TYPE_OSN = 11,
56}; 59};
57 60
58#define QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE 0x18 61#define QETH_MPC_DIFINFO_LEN_INDICATES_LINK_TYPE 0x18
@@ -61,6 +64,7 @@ enum qeth_link_types {
61 QETH_LINK_TYPE_FAST_ETH = 0x01, 64 QETH_LINK_TYPE_FAST_ETH = 0x01,
62 QETH_LINK_TYPE_HSTR = 0x02, 65 QETH_LINK_TYPE_HSTR = 0x02,
63 QETH_LINK_TYPE_GBIT_ETH = 0x03, 66 QETH_LINK_TYPE_GBIT_ETH = 0x03,
67 QETH_LINK_TYPE_OSN = 0x04,
64 QETH_LINK_TYPE_10GBIT_ETH = 0x10, 68 QETH_LINK_TYPE_10GBIT_ETH = 0x10,
65 QETH_LINK_TYPE_LANE_ETH100 = 0x81, 69 QETH_LINK_TYPE_LANE_ETH100 = 0x81,
66 QETH_LINK_TYPE_LANE_TR = 0x82, 70 QETH_LINK_TYPE_LANE_TR = 0x82,
@@ -111,6 +115,9 @@ enum qeth_ipa_cmds {
111 IPA_CMD_DELGMAC = 0x24, 115 IPA_CMD_DELGMAC = 0x24,
112 IPA_CMD_SETVLAN = 0x25, 116 IPA_CMD_SETVLAN = 0x25,
113 IPA_CMD_DELVLAN = 0x26, 117 IPA_CMD_DELVLAN = 0x26,
118 IPA_CMD_SETCCID = 0x41,
119 IPA_CMD_DELCCID = 0x42,
120 IPA_CMD_MODCCID = 0x43,
114 IPA_CMD_SETIP = 0xb1, 121 IPA_CMD_SETIP = 0xb1,
115 IPA_CMD_DELIP = 0xb7, 122 IPA_CMD_DELIP = 0xb7,
116 IPA_CMD_QIPASSIST = 0xb2, 123 IPA_CMD_QIPASSIST = 0xb2,
@@ -437,8 +444,9 @@ enum qeth_ipa_arp_return_codes {
437#define QETH_ARP_DATA_SIZE 3968 444#define QETH_ARP_DATA_SIZE 3968
438#define QETH_ARP_CMD_LEN (QETH_ARP_DATA_SIZE + 8) 445#define QETH_ARP_CMD_LEN (QETH_ARP_DATA_SIZE + 8)
439/* Helper functions */ 446/* Helper functions */
440#define IS_IPA_REPLY(cmd) (cmd->hdr.initiator == IPA_CMD_INITIATOR_HOST) 447#define IS_IPA_REPLY(cmd) ((cmd->hdr.initiator == IPA_CMD_INITIATOR_HOST) || \
441 448 (cmd->hdr.initiator == IPA_CMD_INITIATOR_OSA_REPLY))
449
442/*****************************************************************************/ 450/*****************************************************************************/
443/* END OF IP Assist related definitions */ 451/* END OF IP Assist related definitions */
444/*****************************************************************************/ 452/*****************************************************************************/
@@ -483,6 +491,7 @@ extern unsigned char ULP_ENABLE[];
483/* Layer 2 defintions */ 491/* Layer 2 defintions */
484#define QETH_PROT_LAYER2 0x08 492#define QETH_PROT_LAYER2 0x08
485#define QETH_PROT_TCPIP 0x03 493#define QETH_PROT_TCPIP 0x03
494#define QETH_PROT_OSN2 0x0a
486#define QETH_ULP_ENABLE_PROT_TYPE(buffer) (buffer+0x50) 495#define QETH_ULP_ENABLE_PROT_TYPE(buffer) (buffer+0x50)
487#define QETH_IPA_CMD_PROT_TYPE(buffer) (buffer+0x19) 496#define QETH_IPA_CMD_PROT_TYPE(buffer) (buffer+0x19)
488 497
diff --git a/drivers/s390/net/qeth_sys.c b/drivers/s390/net/qeth_sys.c
index dda105b73063..f91a02db5743 100644
--- a/drivers/s390/net/qeth_sys.c
+++ b/drivers/s390/net/qeth_sys.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * 2 *
3 * linux/drivers/s390/net/qeth_sys.c ($Revision: 1.54 $) 3 * linux/drivers/s390/net/qeth_sys.c ($Revision: 1.55 $)
4 * 4 *
5 * Linux on zSeries OSA Express and HiperSockets support 5 * Linux on zSeries OSA Express and HiperSockets support
6 * This file contains code related to sysfs. 6 * This file contains code related to sysfs.
@@ -20,7 +20,7 @@
20#include "qeth_mpc.h" 20#include "qeth_mpc.h"
21#include "qeth_fs.h" 21#include "qeth_fs.h"
22 22
23const char *VERSION_QETH_SYS_C = "$Revision: 1.54 $"; 23const char *VERSION_QETH_SYS_C = "$Revision: 1.55 $";
24 24
25/*****************************************************************************/ 25/*****************************************************************************/
26/* */ 26/* */
@@ -937,6 +937,19 @@ static struct attribute_group qeth_device_attr_group = {
937 .attrs = (struct attribute **)qeth_device_attrs, 937 .attrs = (struct attribute **)qeth_device_attrs,
938}; 938};
939 939
940static struct device_attribute * qeth_osn_device_attrs[] = {
941 &dev_attr_state,
942 &dev_attr_chpid,
943 &dev_attr_if_name,
944 &dev_attr_card_type,
945 &dev_attr_buffer_count,
946 &dev_attr_recover,
947 NULL,
948};
949
950static struct attribute_group qeth_osn_device_attr_group = {
951 .attrs = (struct attribute **)qeth_osn_device_attrs,
952};
940 953
941#define QETH_DEVICE_ATTR(_id,_name,_mode,_show,_store) \ 954#define QETH_DEVICE_ATTR(_id,_name,_mode,_show,_store) \
942struct device_attribute dev_attr_##_id = { \ 955struct device_attribute dev_attr_##_id = { \
@@ -1667,7 +1680,12 @@ int
1667qeth_create_device_attributes(struct device *dev) 1680qeth_create_device_attributes(struct device *dev)
1668{ 1681{
1669 int ret; 1682 int ret;
1683 struct qeth_card *card = dev->driver_data;
1670 1684
1685 if (card->info.type == QETH_CARD_TYPE_OSN)
1686 return sysfs_create_group(&dev->kobj,
1687 &qeth_osn_device_attr_group);
1688
1671 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_attr_group))) 1689 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_attr_group)))
1672 return ret; 1690 return ret;
1673 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_ipato_group))){ 1691 if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_ipato_group))){
@@ -1693,6 +1711,12 @@ qeth_create_device_attributes(struct device *dev)
1693void 1711void
1694qeth_remove_device_attributes(struct device *dev) 1712qeth_remove_device_attributes(struct device *dev)
1695{ 1713{
1714 struct qeth_card *card = dev->driver_data;
1715
1716 if (card->info.type == QETH_CARD_TYPE_OSN)
1717 return sysfs_remove_group(&dev->kobj,
1718 &qeth_osn_device_attr_group);
1719
1696 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group); 1720 sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
1697 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group); 1721 sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
1698 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group); 1722 sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 3ee9b8b33be0..9c9f162bd6ed 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -489,11 +489,11 @@ config SCSI_SATA_NV
489 489
490 If unsure, say N. 490 If unsure, say N.
491 491
492config SCSI_SATA_PROMISE 492config SCSI_PDC_ADMA
493 tristate "Promise SATA TX2/TX4 support" 493 tristate "Pacific Digital ADMA support"
494 depends on SCSI_SATA && PCI 494 depends on SCSI_SATA && PCI
495 help 495 help
496 This option enables support for Promise Serial ATA TX2/TX4. 496 This option enables support for Pacific Digital ADMA controllers
497 497
498 If unsure, say N. 498 If unsure, say N.
499 499
@@ -505,6 +505,14 @@ config SCSI_SATA_QSTOR
505 505
506 If unsure, say N. 506 If unsure, say N.
507 507
508config SCSI_SATA_PROMISE
509 tristate "Promise SATA TX2/TX4 support"
510 depends on SCSI_SATA && PCI
511 help
512 This option enables support for Promise Serial ATA TX2/TX4.
513
514 If unsure, say N.
515
508config SCSI_SATA_SX4 516config SCSI_SATA_SX4
509 tristate "Promise SATA SX4 support" 517 tristate "Promise SATA SX4 support"
510 depends on SCSI_SATA && PCI && EXPERIMENTAL 518 depends on SCSI_SATA && PCI && EXPERIMENTAL
@@ -521,6 +529,14 @@ config SCSI_SATA_SIL
521 529
522 If unsure, say N. 530 If unsure, say N.
523 531
532config SCSI_SATA_SIL24
533 tristate "Silicon Image 3124/3132 SATA support"
534 depends on SCSI_SATA && PCI && EXPERIMENTAL
535 help
536 This option enables support for Silicon Image 3124/3132 Serial ATA.
537
538 If unsure, say N.
539
524config SCSI_SATA_SIS 540config SCSI_SATA_SIS
525 tristate "SiS 964/180 SATA support" 541 tristate "SiS 964/180 SATA support"
526 depends on SCSI_SATA && PCI && EXPERIMENTAL 542 depends on SCSI_SATA && PCI && EXPERIMENTAL
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index 48529d180ca8..2d4439826c08 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -130,6 +130,7 @@ obj-$(CONFIG_SCSI_ATA_PIIX) += libata.o ata_piix.o
130obj-$(CONFIG_SCSI_SATA_PROMISE) += libata.o sata_promise.o 130obj-$(CONFIG_SCSI_SATA_PROMISE) += libata.o sata_promise.o
131obj-$(CONFIG_SCSI_SATA_QSTOR) += libata.o sata_qstor.o 131obj-$(CONFIG_SCSI_SATA_QSTOR) += libata.o sata_qstor.o
132obj-$(CONFIG_SCSI_SATA_SIL) += libata.o sata_sil.o 132obj-$(CONFIG_SCSI_SATA_SIL) += libata.o sata_sil.o
133obj-$(CONFIG_SCSI_SATA_SIL24) += libata.o sata_sil24.o
133obj-$(CONFIG_SCSI_SATA_VIA) += libata.o sata_via.o 134obj-$(CONFIG_SCSI_SATA_VIA) += libata.o sata_via.o
134obj-$(CONFIG_SCSI_SATA_VITESSE) += libata.o sata_vsc.o 135obj-$(CONFIG_SCSI_SATA_VITESSE) += libata.o sata_vsc.o
135obj-$(CONFIG_SCSI_SATA_SIS) += libata.o sata_sis.o 136obj-$(CONFIG_SCSI_SATA_SIS) += libata.o sata_sis.o
@@ -137,6 +138,7 @@ obj-$(CONFIG_SCSI_SATA_SX4) += libata.o sata_sx4.o
137obj-$(CONFIG_SCSI_SATA_NV) += libata.o sata_nv.o 138obj-$(CONFIG_SCSI_SATA_NV) += libata.o sata_nv.o
138obj-$(CONFIG_SCSI_SATA_ULI) += libata.o sata_uli.o 139obj-$(CONFIG_SCSI_SATA_ULI) += libata.o sata_uli.o
139obj-$(CONFIG_SCSI_SATA_MV) += libata.o sata_mv.o 140obj-$(CONFIG_SCSI_SATA_MV) += libata.o sata_mv.o
141obj-$(CONFIG_SCSI_PDC_ADMA) += libata.o pdc_adma.o
140 142
141obj-$(CONFIG_ARM) += arm/ 143obj-$(CONFIG_ARM) += arm/
142 144
diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c
index c2c8fa828e24..e2a5657d5fdb 100644
--- a/drivers/scsi/ahci.c
+++ b/drivers/scsi/ahci.c
@@ -41,6 +41,7 @@
41#include <linux/interrupt.h> 41#include <linux/interrupt.h>
42#include <linux/sched.h> 42#include <linux/sched.h>
43#include <linux/dma-mapping.h> 43#include <linux/dma-mapping.h>
44#include <linux/device.h>
44#include "scsi.h" 45#include "scsi.h"
45#include <scsi/scsi_host.h> 46#include <scsi/scsi_host.h>
46#include <linux/libata.h> 47#include <linux/libata.h>
@@ -192,7 +193,6 @@ static void ahci_port_stop(struct ata_port *ap);
192static void ahci_tf_read(struct ata_port *ap, struct ata_taskfile *tf); 193static void ahci_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
193static void ahci_qc_prep(struct ata_queued_cmd *qc); 194static void ahci_qc_prep(struct ata_queued_cmd *qc);
194static u8 ahci_check_status(struct ata_port *ap); 195static u8 ahci_check_status(struct ata_port *ap);
195static u8 ahci_check_err(struct ata_port *ap);
196static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc); 196static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc);
197static void ahci_remove_one (struct pci_dev *pdev); 197static void ahci_remove_one (struct pci_dev *pdev);
198 198
@@ -216,12 +216,11 @@ static Scsi_Host_Template ahci_sht = {
216 .ordered_flush = 1, 216 .ordered_flush = 1,
217}; 217};
218 218
219static struct ata_port_operations ahci_ops = { 219static const struct ata_port_operations ahci_ops = {
220 .port_disable = ata_port_disable, 220 .port_disable = ata_port_disable,
221 221
222 .check_status = ahci_check_status, 222 .check_status = ahci_check_status,
223 .check_altstatus = ahci_check_status, 223 .check_altstatus = ahci_check_status,
224 .check_err = ahci_check_err,
225 .dev_select = ata_noop_dev_select, 224 .dev_select = ata_noop_dev_select,
226 225
227 .tf_read = ahci_tf_read, 226 .tf_read = ahci_tf_read,
@@ -407,7 +406,7 @@ static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg_in)
407 return 0xffffffffU; 406 return 0xffffffffU;
408 } 407 }
409 408
410 return readl((void *) ap->ioaddr.scr_addr + (sc_reg * 4)); 409 return readl((void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
411} 410}
412 411
413 412
@@ -425,7 +424,7 @@ static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg_in,
425 return; 424 return;
426 } 425 }
427 426
428 writel(val, (void *) ap->ioaddr.scr_addr + (sc_reg * 4)); 427 writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
429} 428}
430 429
431static void ahci_phy_reset(struct ata_port *ap) 430static void ahci_phy_reset(struct ata_port *ap)
@@ -453,18 +452,11 @@ static void ahci_phy_reset(struct ata_port *ap)
453 452
454static u8 ahci_check_status(struct ata_port *ap) 453static u8 ahci_check_status(struct ata_port *ap)
455{ 454{
456 void *mmio = (void *) ap->ioaddr.cmd_addr; 455 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr;
457 456
458 return readl(mmio + PORT_TFDATA) & 0xFF; 457 return readl(mmio + PORT_TFDATA) & 0xFF;
459} 458}
460 459
461static u8 ahci_check_err(struct ata_port *ap)
462{
463 void *mmio = (void *) ap->ioaddr.cmd_addr;
464
465 return (readl(mmio + PORT_TFDATA) >> 8) & 0xFF;
466}
467
468static void ahci_tf_read(struct ata_port *ap, struct ata_taskfile *tf) 460static void ahci_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
469{ 461{
470 struct ahci_port_priv *pp = ap->private_data; 462 struct ahci_port_priv *pp = ap->private_data;
@@ -609,7 +601,7 @@ static void ahci_eng_timeout(struct ata_port *ap)
609 * not being called from the SCSI EH. 601 * not being called from the SCSI EH.
610 */ 602 */
611 qc->scsidone = scsi_finish_command; 603 qc->scsidone = scsi_finish_command;
612 ata_qc_complete(qc, ATA_ERR); 604 ata_qc_complete(qc, AC_ERR_OTHER);
613 } 605 }
614 606
615 spin_unlock_irqrestore(&host_set->lock, flags); 607 spin_unlock_irqrestore(&host_set->lock, flags);
@@ -638,7 +630,7 @@ static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
638 if (status & PORT_IRQ_FATAL) { 630 if (status & PORT_IRQ_FATAL) {
639 ahci_intr_error(ap, status); 631 ahci_intr_error(ap, status);
640 if (qc) 632 if (qc)
641 ata_qc_complete(qc, ATA_ERR); 633 ata_qc_complete(qc, AC_ERR_OTHER);
642 } 634 }
643 635
644 return 1; 636 return 1;
@@ -672,17 +664,35 @@ static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs *
672 664
673 for (i = 0; i < host_set->n_ports; i++) { 665 for (i = 0; i < host_set->n_ports; i++) {
674 struct ata_port *ap; 666 struct ata_port *ap;
675 u32 tmp;
676 667
677 VPRINTK("port %u\n", i); 668 if (!(irq_stat & (1 << i)))
669 continue;
670
678 ap = host_set->ports[i]; 671 ap = host_set->ports[i];
679 tmp = irq_stat & (1 << i); 672 if (ap) {
680 if (tmp && ap) {
681 struct ata_queued_cmd *qc; 673 struct ata_queued_cmd *qc;
682 qc = ata_qc_from_tag(ap, ap->active_tag); 674 qc = ata_qc_from_tag(ap, ap->active_tag);
683 if (ahci_host_intr(ap, qc)) 675 if (!ahci_host_intr(ap, qc))
684 irq_ack |= (1 << i); 676 if (ata_ratelimit()) {
677 struct pci_dev *pdev =
678 to_pci_dev(ap->host_set->dev);
679 dev_printk(KERN_WARNING, &pdev->dev,
680 "unhandled interrupt on port %u\n",
681 i);
682 }
683
684 VPRINTK("port %u\n", i);
685 } else {
686 VPRINTK("port %u (no irq)\n", i);
687 if (ata_ratelimit()) {
688 struct pci_dev *pdev =
689 to_pci_dev(ap->host_set->dev);
690 dev_printk(KERN_WARNING, &pdev->dev,
691 "interrupt on disabled port %u\n", i);
692 }
685 } 693 }
694
695 irq_ack |= (1 << i);
686 } 696 }
687 697
688 if (irq_ack) { 698 if (irq_ack) {
@@ -750,8 +760,8 @@ static int ahci_host_init(struct ata_probe_ent *probe_ent)
750 760
751 tmp = readl(mmio + HOST_CTL); 761 tmp = readl(mmio + HOST_CTL);
752 if (tmp & HOST_RESET) { 762 if (tmp & HOST_RESET) {
753 printk(KERN_ERR DRV_NAME "(%s): controller reset failed (0x%x)\n", 763 dev_printk(KERN_ERR, &pdev->dev,
754 pci_name(pdev), tmp); 764 "controller reset failed (0x%x)\n", tmp);
755 return -EIO; 765 return -EIO;
756 } 766 }
757 767
@@ -779,22 +789,22 @@ static int ahci_host_init(struct ata_probe_ent *probe_ent)
779 if (rc) { 789 if (rc) {
780 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 790 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
781 if (rc) { 791 if (rc) {
782 printk(KERN_ERR DRV_NAME "(%s): 64-bit DMA enable failed\n", 792 dev_printk(KERN_ERR, &pdev->dev,
783 pci_name(pdev)); 793 "64-bit DMA enable failed\n");
784 return rc; 794 return rc;
785 } 795 }
786 } 796 }
787 } else { 797 } else {
788 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 798 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
789 if (rc) { 799 if (rc) {
790 printk(KERN_ERR DRV_NAME "(%s): 32-bit DMA enable failed\n", 800 dev_printk(KERN_ERR, &pdev->dev,
791 pci_name(pdev)); 801 "32-bit DMA enable failed\n");
792 return rc; 802 return rc;
793 } 803 }
794 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 804 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
795 if (rc) { 805 if (rc) {
796 printk(KERN_ERR DRV_NAME "(%s): 32-bit consistent DMA enable failed\n", 806 dev_printk(KERN_ERR, &pdev->dev,
797 pci_name(pdev)); 807 "32-bit consistent DMA enable failed\n");
798 return rc; 808 return rc;
799 } 809 }
800 } 810 }
@@ -897,10 +907,10 @@ static void ahci_print_info(struct ata_probe_ent *probe_ent)
897 else 907 else
898 scc_s = "unknown"; 908 scc_s = "unknown";
899 909
900 printk(KERN_INFO DRV_NAME "(%s) AHCI %02x%02x.%02x%02x " 910 dev_printk(KERN_INFO, &pdev->dev,
911 "AHCI %02x%02x.%02x%02x "
901 "%u slots %u ports %s Gbps 0x%x impl %s mode\n" 912 "%u slots %u ports %s Gbps 0x%x impl %s mode\n"
902 , 913 ,
903 pci_name(pdev),
904 914
905 (vers >> 24) & 0xff, 915 (vers >> 24) & 0xff,
906 (vers >> 16) & 0xff, 916 (vers >> 16) & 0xff,
@@ -913,11 +923,11 @@ static void ahci_print_info(struct ata_probe_ent *probe_ent)
913 impl, 923 impl,
914 scc_s); 924 scc_s);
915 925
916 printk(KERN_INFO DRV_NAME "(%s) flags: " 926 dev_printk(KERN_INFO, &pdev->dev,
927 "flags: "
917 "%s%s%s%s%s%s" 928 "%s%s%s%s%s%s"
918 "%s%s%s%s%s%s%s\n" 929 "%s%s%s%s%s%s%s\n"
919 , 930 ,
920 pci_name(pdev),
921 931
922 cap & (1 << 31) ? "64bit " : "", 932 cap & (1 << 31) ? "64bit " : "",
923 cap & (1 << 30) ? "ncq " : "", 933 cap & (1 << 30) ? "ncq " : "",
@@ -950,7 +960,7 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
950 VPRINTK("ENTER\n"); 960 VPRINTK("ENTER\n");
951 961
952 if (!printed_version++) 962 if (!printed_version++)
953 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 963 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
954 964
955 rc = pci_enable_device(pdev); 965 rc = pci_enable_device(pdev);
956 if (rc) 966 if (rc)
diff --git a/drivers/scsi/arm/scsi.h b/drivers/scsi/arm/scsi.h
index 48e1c4d9738b..19937640e2e7 100644
--- a/drivers/scsi/arm/scsi.h
+++ b/drivers/scsi/arm/scsi.h
@@ -10,6 +10,8 @@
10 * Commonly used scsi driver functions. 10 * Commonly used scsi driver functions.
11 */ 11 */
12 12
13#include <linux/scatterlist.h>
14
13#define BELT_AND_BRACES 15#define BELT_AND_BRACES
14 16
15/* 17/*
@@ -22,9 +24,7 @@ static inline int copy_SCp_to_sg(struct scatterlist *sg, Scsi_Pointer *SCp, int
22 24
23 BUG_ON(bufs + 1 > max); 25 BUG_ON(bufs + 1 > max);
24 26
25 sg->page = virt_to_page(SCp->ptr); 27 sg_set_buf(sg, SCp->ptr, SCp->this_residual);
26 sg->offset = offset_in_page(SCp->ptr);
27 sg->length = SCp->this_residual;
28 28
29 if (bufs) 29 if (bufs)
30 memcpy(sg + 1, SCp->buffer + 1, 30 memcpy(sg + 1, SCp->buffer + 1,
diff --git a/drivers/scsi/ata_piix.c b/drivers/scsi/ata_piix.c
index d71cef767cec..7f8aa1b552ce 100644
--- a/drivers/scsi/ata_piix.c
+++ b/drivers/scsi/ata_piix.c
@@ -45,6 +45,7 @@
45#include <linux/init.h> 45#include <linux/init.h>
46#include <linux/blkdev.h> 46#include <linux/blkdev.h>
47#include <linux/delay.h> 47#include <linux/delay.h>
48#include <linux/device.h>
48#include "scsi.h" 49#include "scsi.h"
49#include <scsi/scsi_host.h> 50#include <scsi/scsi_host.h>
50#include <linux/libata.h> 51#include <linux/libata.h>
@@ -147,7 +148,7 @@ static Scsi_Host_Template piix_sht = {
147 .ordered_flush = 1, 148 .ordered_flush = 1,
148}; 149};
149 150
150static struct ata_port_operations piix_pata_ops = { 151static const struct ata_port_operations piix_pata_ops = {
151 .port_disable = ata_port_disable, 152 .port_disable = ata_port_disable,
152 .set_piomode = piix_set_piomode, 153 .set_piomode = piix_set_piomode,
153 .set_dmamode = piix_set_dmamode, 154 .set_dmamode = piix_set_dmamode,
@@ -177,7 +178,7 @@ static struct ata_port_operations piix_pata_ops = {
177 .host_stop = ata_host_stop, 178 .host_stop = ata_host_stop,
178}; 179};
179 180
180static struct ata_port_operations piix_sata_ops = { 181static const struct ata_port_operations piix_sata_ops = {
181 .port_disable = ata_port_disable, 182 .port_disable = ata_port_disable,
182 183
183 .tf_load = ata_tf_load, 184 .tf_load = ata_tf_load,
@@ -621,18 +622,19 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
621{ 622{
622 static int printed_version; 623 static int printed_version;
623 struct ata_port_info *port_info[2]; 624 struct ata_port_info *port_info[2];
624 unsigned int combined = 0, n_ports = 1; 625 unsigned int combined = 0;
625 unsigned int pata_chan = 0, sata_chan = 0; 626 unsigned int pata_chan = 0, sata_chan = 0;
626 627
627 if (!printed_version++) 628 if (!printed_version++)
628 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 629 dev_printk(KERN_DEBUG, &pdev->dev,
630 "version " DRV_VERSION "\n");
629 631
630 /* no hotplugging support (FIXME) */ 632 /* no hotplugging support (FIXME) */
631 if (!in_module_init) 633 if (!in_module_init)
632 return -ENODEV; 634 return -ENODEV;
633 635
634 port_info[0] = &piix_port_info[ent->driver_data]; 636 port_info[0] = &piix_port_info[ent->driver_data];
635 port_info[1] = NULL; 637 port_info[1] = &piix_port_info[ent->driver_data];
636 638
637 if (port_info[0]->host_flags & PIIX_FLAG_AHCI) { 639 if (port_info[0]->host_flags & PIIX_FLAG_AHCI) {
638 u8 tmp; 640 u8 tmp;
@@ -670,12 +672,13 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
670 port_info[sata_chan] = &piix_port_info[ent->driver_data]; 672 port_info[sata_chan] = &piix_port_info[ent->driver_data];
671 port_info[sata_chan]->host_flags |= ATA_FLAG_SLAVE_POSS; 673 port_info[sata_chan]->host_flags |= ATA_FLAG_SLAVE_POSS;
672 port_info[pata_chan] = &piix_port_info[ich5_pata]; 674 port_info[pata_chan] = &piix_port_info[ich5_pata];
673 n_ports++;
674 675
675 printk(KERN_WARNING DRV_NAME ": combined mode detected\n"); 676 dev_printk(KERN_WARNING, &pdev->dev,
677 "combined mode detected (p=%u, s=%u)\n",
678 pata_chan, sata_chan);
676 } 679 }
677 680
678 return ata_pci_init_one(pdev, port_info, n_ports); 681 return ata_pci_init_one(pdev, port_info, 2);
679} 682}
680 683
681static int __init piix_init(void) 684static int __init piix_init(void)
diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index da6e51c7fe69..540147cb51ce 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -936,7 +936,7 @@ static int ch_probe(struct device *dev)
936 if (init) 936 if (init)
937 ch_init_elem(ch); 937 ch_init_elem(ch);
938 938
939 class_device_create(ch_sysfs_class, 939 class_device_create(ch_sysfs_class, NULL,
940 MKDEV(SCSI_CHANGER_MAJOR,ch->minor), 940 MKDEV(SCSI_CHANGER_MAJOR,ch->minor),
941 dev, "s%s", ch->name); 941 dev, "s%s", ch->name);
942 942
diff --git a/drivers/scsi/dec_esp.c b/drivers/scsi/dec_esp.c
index 315f95a0d6c0..4f39890b44ac 100644
--- a/drivers/scsi/dec_esp.c
+++ b/drivers/scsi/dec_esp.c
@@ -228,7 +228,7 @@ static int dec_esp_detect(Scsi_Host_Template * tpnt)
228 mem_start = get_tc_base_addr(slot); 228 mem_start = get_tc_base_addr(slot);
229 229
230 /* Store base addr into esp struct */ 230 /* Store base addr into esp struct */
231 esp->slot = PHYSADDR(mem_start); 231 esp->slot = CPHYSADDR(mem_start);
232 232
233 esp->dregs = 0; 233 esp->dregs = 0;
234 esp->eregs = (struct ESP_regs *) (mem_start + DEC_SCSI_SREG); 234 esp->eregs = (struct ESP_regs *) (mem_start + DEC_SCSI_SREG);
diff --git a/drivers/scsi/eata.c b/drivers/scsi/eata.c
index c10e45b94b62..3d13fdee4fc2 100644
--- a/drivers/scsi/eata.c
+++ b/drivers/scsi/eata.c
@@ -1357,7 +1357,7 @@ static int port_detect(unsigned long port_base, unsigned int j,
1357 1357
1358 for (i = 0; i < shost->can_queue; i++) { 1358 for (i = 0; i < shost->can_queue; i++) {
1359 size_t sz = shost->sg_tablesize *sizeof(struct sg_list); 1359 size_t sz = shost->sg_tablesize *sizeof(struct sg_list);
1360 unsigned int gfp_mask = (shost->unchecked_isa_dma ? GFP_DMA : 0) | GFP_ATOMIC; 1360 gfp_t gfp_mask = (shost->unchecked_isa_dma ? GFP_DMA : 0) | GFP_ATOMIC;
1361 ha->cp[i].sglist = kmalloc(sz, gfp_mask); 1361 ha->cp[i].sglist = kmalloc(sz, gfp_mask);
1362 if (!ha->cp[i].sglist) { 1362 if (!ha->cp[i].sglist) {
1363 printk 1363 printk
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 02fe371b0ab8..f24d84538fd5 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -287,7 +287,8 @@ static void scsi_host_dev_release(struct device *dev)
287struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize) 287struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
288{ 288{
289 struct Scsi_Host *shost; 289 struct Scsi_Host *shost;
290 int gfp_mask = GFP_KERNEL, rval; 290 gfp_t gfp_mask = GFP_KERNEL;
291 int rval;
291 292
292 if (sht->unchecked_isa_dma && privsize) 293 if (sht->unchecked_isa_dma && privsize)
293 gfp_mask |= __GFP_DMA; 294 gfp_mask |= __GFP_DMA;
diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
index 3d62c9bcbff7..00d6a6657ebc 100644
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -180,19 +180,12 @@ static void idescsi_input_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsigne
180 return; 180 return;
181 } 181 }
182 count = min(pc->sg->length - pc->b_count, bcount); 182 count = min(pc->sg->length - pc->b_count, bcount);
183 if (PageHighMem(pc->sg->page)) { 183 buf = kmap_atomic(pc->sg->page, KM_IRQ0);
184 unsigned long flags; 184 drive->hwif->atapi_input_bytes(drive,
185 185 buf + pc->b_count + pc->sg->offset, count);
186 local_irq_save(flags); 186 kunmap_atomic(buf, KM_IRQ0);
187 buf = kmap_atomic(pc->sg->page, KM_IRQ0) + pc->sg->offset; 187 bcount -= count;
188 drive->hwif->atapi_input_bytes(drive, buf + pc->b_count, count); 188 pc->b_count += count;
189 kunmap_atomic(buf - pc->sg->offset, KM_IRQ0);
190 local_irq_restore(flags);
191 } else {
192 buf = page_address(pc->sg->page) + pc->sg->offset;
193 drive->hwif->atapi_input_bytes(drive, buf + pc->b_count, count);
194 }
195 bcount -= count; pc->b_count += count;
196 if (pc->b_count == pc->sg->length) { 189 if (pc->b_count == pc->sg->length) {
197 pc->sg++; 190 pc->sg++;
198 pc->b_count = 0; 191 pc->b_count = 0;
@@ -212,19 +205,12 @@ static void idescsi_output_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsign
212 return; 205 return;
213 } 206 }
214 count = min(pc->sg->length - pc->b_count, bcount); 207 count = min(pc->sg->length - pc->b_count, bcount);
215 if (PageHighMem(pc->sg->page)) { 208 buf = kmap_atomic(pc->sg->page, KM_IRQ0);
216 unsigned long flags; 209 drive->hwif->atapi_output_bytes(drive,
217 210 buf + pc->b_count + pc->sg->offset, count);
218 local_irq_save(flags); 211 kunmap_atomic(buf, KM_IRQ0);
219 buf = kmap_atomic(pc->sg->page, KM_IRQ0) + pc->sg->offset; 212 bcount -= count;
220 drive->hwif->atapi_output_bytes(drive, buf + pc->b_count, count); 213 pc->b_count += count;
221 kunmap_atomic(buf - pc->sg->offset, KM_IRQ0);
222 local_irq_restore(flags);
223 } else {
224 buf = page_address(pc->sg->page) + pc->sg->offset;
225 drive->hwif->atapi_output_bytes(drive, buf + pc->b_count, count);
226 }
227 bcount -= count; pc->b_count += count;
228 if (pc->b_count == pc->sg->length) { 214 if (pc->b_count == pc->sg->length) {
229 pc->sg++; 215 pc->sg++;
230 pc->b_count = 0; 216 pc->b_count = 0;
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index babd48363402..e0039dfae8e5 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -4944,6 +4944,7 @@ static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
4944 int rc; 4944 int rc;
4945 4945
4946 ENTER; 4946 ENTER;
4947 pci_unblock_user_cfg_access(ioa_cfg->pdev);
4947 rc = pci_restore_state(ioa_cfg->pdev); 4948 rc = pci_restore_state(ioa_cfg->pdev);
4948 4949
4949 if (rc != PCIBIOS_SUCCESSFUL) { 4950 if (rc != PCIBIOS_SUCCESSFUL) {
@@ -4998,6 +4999,7 @@ static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
4998 int rc; 4999 int rc;
4999 5000
5000 ENTER; 5001 ENTER;
5002 pci_block_user_cfg_access(ioa_cfg->pdev);
5001 rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START); 5003 rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
5002 5004
5003 if (rc != PCIBIOS_SUCCESSFUL) { 5005 if (rc != PCIBIOS_SUCCESSFUL) {
diff --git a/drivers/scsi/lasi700.c b/drivers/scsi/lasi700.c
index 4cbb6187cc44..459a4daebece 100644
--- a/drivers/scsi/lasi700.c
+++ b/drivers/scsi/lasi700.c
@@ -98,7 +98,7 @@ MODULE_DEVICE_TABLE(parisc, lasi700_ids);
98static int __init 98static int __init
99lasi700_probe(struct parisc_device *dev) 99lasi700_probe(struct parisc_device *dev)
100{ 100{
101 unsigned long base = dev->hpa + LASI_SCSI_CORE_OFFSET; 101 unsigned long base = dev->hpa.start + LASI_SCSI_CORE_OFFSET;
102 struct NCR_700_Host_Parameters *hostdata; 102 struct NCR_700_Host_Parameters *hostdata;
103 struct Scsi_Host *host; 103 struct Scsi_Host *host;
104 104
@@ -125,8 +125,6 @@ lasi700_probe(struct parisc_device *dev)
125 hostdata->dmode_extra = DMODE_FC2; 125 hostdata->dmode_extra = DMODE_FC2;
126 } 126 }
127 127
128 NCR_700_set_mem_mapped(hostdata);
129
130 host = NCR_700_detect(&lasi700_template, hostdata, &dev->dev); 128 host = NCR_700_detect(&lasi700_template, hostdata, &dev->dev);
131 if (!host) 129 if (!host)
132 goto out_kfree; 130 goto out_kfree;
@@ -168,7 +166,7 @@ lasi700_driver_remove(struct parisc_device *dev)
168} 166}
169 167
170static struct parisc_driver lasi700_driver = { 168static struct parisc_driver lasi700_driver = {
171 .name = "Lasi SCSI", 169 .name = "lasi_scsi",
172 .id_table = lasi700_ids, 170 .id_table = lasi700_ids,
173 .probe = lasi700_probe, 171 .probe = lasi700_probe,
174 .remove = __devexit_p(lasi700_driver_remove), 172 .remove = __devexit_p(lasi700_driver_remove),
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index e5b01997117a..8be7dc0b47b8 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -48,6 +48,8 @@
48#include <linux/completion.h> 48#include <linux/completion.h>
49#include <linux/suspend.h> 49#include <linux/suspend.h>
50#include <linux/workqueue.h> 50#include <linux/workqueue.h>
51#include <linux/jiffies.h>
52#include <linux/scatterlist.h>
51#include <scsi/scsi.h> 53#include <scsi/scsi.h>
52#include "scsi.h" 54#include "scsi.h"
53#include "scsi_priv.h" 55#include "scsi_priv.h"
@@ -62,14 +64,15 @@
62static unsigned int ata_busy_sleep (struct ata_port *ap, 64static unsigned int ata_busy_sleep (struct ata_port *ap,
63 unsigned long tmout_pat, 65 unsigned long tmout_pat,
64 unsigned long tmout); 66 unsigned long tmout);
67static void ata_dev_reread_id(struct ata_port *ap, struct ata_device *dev);
68static void ata_dev_init_params(struct ata_port *ap, struct ata_device *dev);
65static void ata_set_mode(struct ata_port *ap); 69static void ata_set_mode(struct ata_port *ap);
66static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev); 70static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev);
67static unsigned int ata_get_mode_mask(struct ata_port *ap, int shift); 71static unsigned int ata_get_mode_mask(const struct ata_port *ap, int shift);
68static int fgb(u32 bitmap); 72static int fgb(u32 bitmap);
69static int ata_choose_xfer_mode(struct ata_port *ap, 73static int ata_choose_xfer_mode(const struct ata_port *ap,
70 u8 *xfer_mode_out, 74 u8 *xfer_mode_out,
71 unsigned int *xfer_shift_out); 75 unsigned int *xfer_shift_out);
72static int ata_qc_complete_noop(struct ata_queued_cmd *qc, u8 drv_stat);
73static void __ata_qc_complete(struct ata_queued_cmd *qc); 76static void __ata_qc_complete(struct ata_queued_cmd *qc);
74 77
75static unsigned int ata_unique_id = 1; 78static unsigned int ata_unique_id = 1;
@@ -85,7 +88,7 @@ MODULE_LICENSE("GPL");
85MODULE_VERSION(DRV_VERSION); 88MODULE_VERSION(DRV_VERSION);
86 89
87/** 90/**
88 * ata_tf_load - send taskfile registers to host controller 91 * ata_tf_load_pio - send taskfile registers to host controller
89 * @ap: Port to which output is sent 92 * @ap: Port to which output is sent
90 * @tf: ATA taskfile register set 93 * @tf: ATA taskfile register set
91 * 94 *
@@ -95,7 +98,7 @@ MODULE_VERSION(DRV_VERSION);
95 * Inherited from caller. 98 * Inherited from caller.
96 */ 99 */
97 100
98static void ata_tf_load_pio(struct ata_port *ap, struct ata_taskfile *tf) 101static void ata_tf_load_pio(struct ata_port *ap, const struct ata_taskfile *tf)
99{ 102{
100 struct ata_ioports *ioaddr = &ap->ioaddr; 103 struct ata_ioports *ioaddr = &ap->ioaddr;
101 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; 104 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
@@ -153,7 +156,7 @@ static void ata_tf_load_pio(struct ata_port *ap, struct ata_taskfile *tf)
153 * Inherited from caller. 156 * Inherited from caller.
154 */ 157 */
155 158
156static void ata_tf_load_mmio(struct ata_port *ap, struct ata_taskfile *tf) 159static void ata_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
157{ 160{
158 struct ata_ioports *ioaddr = &ap->ioaddr; 161 struct ata_ioports *ioaddr = &ap->ioaddr;
159 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; 162 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
@@ -222,7 +225,7 @@ static void ata_tf_load_mmio(struct ata_port *ap, struct ata_taskfile *tf)
222 * LOCKING: 225 * LOCKING:
223 * Inherited from caller. 226 * Inherited from caller.
224 */ 227 */
225void ata_tf_load(struct ata_port *ap, struct ata_taskfile *tf) 228void ata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
226{ 229{
227 if (ap->flags & ATA_FLAG_MMIO) 230 if (ap->flags & ATA_FLAG_MMIO)
228 ata_tf_load_mmio(ap, tf); 231 ata_tf_load_mmio(ap, tf);
@@ -242,7 +245,7 @@ void ata_tf_load(struct ata_port *ap, struct ata_taskfile *tf)
242 * spin_lock_irqsave(host_set lock) 245 * spin_lock_irqsave(host_set lock)
243 */ 246 */
244 247
245static void ata_exec_command_pio(struct ata_port *ap, struct ata_taskfile *tf) 248static void ata_exec_command_pio(struct ata_port *ap, const struct ata_taskfile *tf)
246{ 249{
247 DPRINTK("ata%u: cmd 0x%X\n", ap->id, tf->command); 250 DPRINTK("ata%u: cmd 0x%X\n", ap->id, tf->command);
248 251
@@ -263,7 +266,7 @@ static void ata_exec_command_pio(struct ata_port *ap, struct ata_taskfile *tf)
263 * spin_lock_irqsave(host_set lock) 266 * spin_lock_irqsave(host_set lock)
264 */ 267 */
265 268
266static void ata_exec_command_mmio(struct ata_port *ap, struct ata_taskfile *tf) 269static void ata_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
267{ 270{
268 DPRINTK("ata%u: cmd 0x%X\n", ap->id, tf->command); 271 DPRINTK("ata%u: cmd 0x%X\n", ap->id, tf->command);
269 272
@@ -283,7 +286,7 @@ static void ata_exec_command_mmio(struct ata_port *ap, struct ata_taskfile *tf)
283 * LOCKING: 286 * LOCKING:
284 * spin_lock_irqsave(host_set lock) 287 * spin_lock_irqsave(host_set lock)
285 */ 288 */
286void ata_exec_command(struct ata_port *ap, struct ata_taskfile *tf) 289void ata_exec_command(struct ata_port *ap, const struct ata_taskfile *tf)
287{ 290{
288 if (ap->flags & ATA_FLAG_MMIO) 291 if (ap->flags & ATA_FLAG_MMIO)
289 ata_exec_command_mmio(ap, tf); 292 ata_exec_command_mmio(ap, tf);
@@ -303,7 +306,7 @@ void ata_exec_command(struct ata_port *ap, struct ata_taskfile *tf)
303 * Obtains host_set lock. 306 * Obtains host_set lock.
304 */ 307 */
305 308
306static inline void ata_exec(struct ata_port *ap, struct ata_taskfile *tf) 309static inline void ata_exec(struct ata_port *ap, const struct ata_taskfile *tf)
307{ 310{
308 unsigned long flags; 311 unsigned long flags;
309 312
@@ -326,7 +329,7 @@ static inline void ata_exec(struct ata_port *ap, struct ata_taskfile *tf)
326 * Obtains host_set lock. 329 * Obtains host_set lock.
327 */ 330 */
328 331
329static void ata_tf_to_host(struct ata_port *ap, struct ata_taskfile *tf) 332static void ata_tf_to_host(struct ata_port *ap, const struct ata_taskfile *tf)
330{ 333{
331 ap->ops->tf_load(ap, tf); 334 ap->ops->tf_load(ap, tf);
332 335
@@ -346,7 +349,7 @@ static void ata_tf_to_host(struct ata_port *ap, struct ata_taskfile *tf)
346 * spin_lock_irqsave(host_set lock) 349 * spin_lock_irqsave(host_set lock)
347 */ 350 */
348 351
349void ata_tf_to_host_nolock(struct ata_port *ap, struct ata_taskfile *tf) 352void ata_tf_to_host_nolock(struct ata_port *ap, const struct ata_taskfile *tf)
350{ 353{
351 ap->ops->tf_load(ap, tf); 354 ap->ops->tf_load(ap, tf);
352 ap->ops->exec_command(ap, tf); 355 ap->ops->exec_command(ap, tf);
@@ -368,6 +371,8 @@ static void ata_tf_read_pio(struct ata_port *ap, struct ata_taskfile *tf)
368{ 371{
369 struct ata_ioports *ioaddr = &ap->ioaddr; 372 struct ata_ioports *ioaddr = &ap->ioaddr;
370 373
374 tf->command = ata_check_status(ap);
375 tf->feature = inb(ioaddr->error_addr);
371 tf->nsect = inb(ioaddr->nsect_addr); 376 tf->nsect = inb(ioaddr->nsect_addr);
372 tf->lbal = inb(ioaddr->lbal_addr); 377 tf->lbal = inb(ioaddr->lbal_addr);
373 tf->lbam = inb(ioaddr->lbam_addr); 378 tf->lbam = inb(ioaddr->lbam_addr);
@@ -400,6 +405,8 @@ static void ata_tf_read_mmio(struct ata_port *ap, struct ata_taskfile *tf)
400{ 405{
401 struct ata_ioports *ioaddr = &ap->ioaddr; 406 struct ata_ioports *ioaddr = &ap->ioaddr;
402 407
408 tf->command = ata_check_status(ap);
409 tf->feature = readb((void __iomem *)ioaddr->error_addr);
403 tf->nsect = readb((void __iomem *)ioaddr->nsect_addr); 410 tf->nsect = readb((void __iomem *)ioaddr->nsect_addr);
404 tf->lbal = readb((void __iomem *)ioaddr->lbal_addr); 411 tf->lbal = readb((void __iomem *)ioaddr->lbal_addr);
405 tf->lbam = readb((void __iomem *)ioaddr->lbam_addr); 412 tf->lbam = readb((void __iomem *)ioaddr->lbam_addr);
@@ -520,30 +527,6 @@ u8 ata_altstatus(struct ata_port *ap)
520 527
521 528
522/** 529/**
523 * ata_chk_err - Read device error reg
524 * @ap: port where the device is
525 *
526 * Reads ATA taskfile error register for
527 * currently-selected device and return its value.
528 *
529 * Note: may NOT be used as the check_err() entry in
530 * ata_port_operations.
531 *
532 * LOCKING:
533 * Inherited from caller.
534 */
535u8 ata_chk_err(struct ata_port *ap)
536{
537 if (ap->ops->check_err)
538 return ap->ops->check_err(ap);
539
540 if (ap->flags & ATA_FLAG_MMIO) {
541 return readb((void __iomem *) ap->ioaddr.error_addr);
542 }
543 return inb(ap->ioaddr.error_addr);
544}
545
546/**
547 * ata_tf_to_fis - Convert ATA taskfile to SATA FIS structure 530 * ata_tf_to_fis - Convert ATA taskfile to SATA FIS structure
548 * @tf: Taskfile to convert 531 * @tf: Taskfile to convert
549 * @fis: Buffer into which data will output 532 * @fis: Buffer into which data will output
@@ -556,7 +539,7 @@ u8 ata_chk_err(struct ata_port *ap)
556 * Inherited from caller. 539 * Inherited from caller.
557 */ 540 */
558 541
559void ata_tf_to_fis(struct ata_taskfile *tf, u8 *fis, u8 pmp) 542void ata_tf_to_fis(const struct ata_taskfile *tf, u8 *fis, u8 pmp)
560{ 543{
561 fis[0] = 0x27; /* Register - Host to Device FIS */ 544 fis[0] = 0x27; /* Register - Host to Device FIS */
562 fis[1] = (pmp & 0xf) | (1 << 7); /* Port multiplier number, 545 fis[1] = (pmp & 0xf) | (1 << 7); /* Port multiplier number,
@@ -597,7 +580,7 @@ void ata_tf_to_fis(struct ata_taskfile *tf, u8 *fis, u8 pmp)
597 * Inherited from caller. 580 * Inherited from caller.
598 */ 581 */
599 582
600void ata_tf_from_fis(u8 *fis, struct ata_taskfile *tf) 583void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf)
601{ 584{
602 tf->command = fis[2]; /* status */ 585 tf->command = fis[2]; /* status */
603 tf->feature = fis[3]; /* error */ 586 tf->feature = fis[3]; /* error */
@@ -615,79 +598,53 @@ void ata_tf_from_fis(u8 *fis, struct ata_taskfile *tf)
615 tf->hob_nsect = fis[13]; 598 tf->hob_nsect = fis[13];
616} 599}
617 600
618/** 601static const u8 ata_rw_cmds[] = {
619 * ata_prot_to_cmd - determine which read/write opcodes to use 602 /* pio multi */
620 * @protocol: ATA_PROT_xxx taskfile protocol 603 ATA_CMD_READ_MULTI,
621 * @lba48: true is lba48 is present 604 ATA_CMD_WRITE_MULTI,
622 * 605 ATA_CMD_READ_MULTI_EXT,
623 * Given necessary input, determine which read/write commands 606 ATA_CMD_WRITE_MULTI_EXT,
624 * to use to transfer data. 607 /* pio */
625 * 608 ATA_CMD_PIO_READ,
626 * LOCKING: 609 ATA_CMD_PIO_WRITE,
627 * None. 610 ATA_CMD_PIO_READ_EXT,
628 */ 611 ATA_CMD_PIO_WRITE_EXT,
629static int ata_prot_to_cmd(int protocol, int lba48) 612 /* dma */
630{ 613 ATA_CMD_READ,
631 int rcmd = 0, wcmd = 0; 614 ATA_CMD_WRITE,
632 615 ATA_CMD_READ_EXT,
633 switch (protocol) { 616 ATA_CMD_WRITE_EXT
634 case ATA_PROT_PIO: 617};
635 if (lba48) {
636 rcmd = ATA_CMD_PIO_READ_EXT;
637 wcmd = ATA_CMD_PIO_WRITE_EXT;
638 } else {
639 rcmd = ATA_CMD_PIO_READ;
640 wcmd = ATA_CMD_PIO_WRITE;
641 }
642 break;
643
644 case ATA_PROT_DMA:
645 if (lba48) {
646 rcmd = ATA_CMD_READ_EXT;
647 wcmd = ATA_CMD_WRITE_EXT;
648 } else {
649 rcmd = ATA_CMD_READ;
650 wcmd = ATA_CMD_WRITE;
651 }
652 break;
653
654 default:
655 return -1;
656 }
657
658 return rcmd | (wcmd << 8);
659}
660 618
661/** 619/**
662 * ata_dev_set_protocol - set taskfile protocol and r/w commands 620 * ata_rwcmd_protocol - set taskfile r/w commands and protocol
663 * @dev: device to examine and configure 621 * @qc: command to examine and configure
664 * 622 *
665 * Examine the device configuration, after we have 623 * Examine the device configuration and tf->flags to calculate
666 * read the identify-device page and configured the 624 * the proper read/write commands and protocol to use.
667 * data transfer mode. Set internal state related to
668 * the ATA taskfile protocol (pio, pio mult, dma, etc.)
669 * and calculate the proper read/write commands to use.
670 * 625 *
671 * LOCKING: 626 * LOCKING:
672 * caller. 627 * caller.
673 */ 628 */
674static void ata_dev_set_protocol(struct ata_device *dev) 629void ata_rwcmd_protocol(struct ata_queued_cmd *qc)
675{ 630{
676 int pio = (dev->flags & ATA_DFLAG_PIO); 631 struct ata_taskfile *tf = &qc->tf;
677 int lba48 = (dev->flags & ATA_DFLAG_LBA48); 632 struct ata_device *dev = qc->dev;
678 int proto, cmd;
679 633
680 if (pio) 634 int index, lba48, write;
681 proto = dev->xfer_protocol = ATA_PROT_PIO; 635
682 else 636 lba48 = (tf->flags & ATA_TFLAG_LBA48) ? 2 : 0;
683 proto = dev->xfer_protocol = ATA_PROT_DMA; 637 write = (tf->flags & ATA_TFLAG_WRITE) ? 1 : 0;
684 638
685 cmd = ata_prot_to_cmd(proto, lba48); 639 if (dev->flags & ATA_DFLAG_PIO) {
686 if (cmd < 0) 640 tf->protocol = ATA_PROT_PIO;
687 BUG(); 641 index = dev->multi_count ? 0 : 4;
642 } else {
643 tf->protocol = ATA_PROT_DMA;
644 index = 8;
645 }
688 646
689 dev->read_cmd = cmd & 0xff; 647 tf->command = ata_rw_cmds[index + lba48 + write];
690 dev->write_cmd = (cmd >> 8) & 0xff;
691} 648}
692 649
693static const char * xfer_mode_str[] = { 650static const char * xfer_mode_str[] = {
@@ -869,7 +826,7 @@ static unsigned int ata_devchk(struct ata_port *ap,
869 * the event of failure. 826 * the event of failure.
870 */ 827 */
871 828
872unsigned int ata_dev_classify(struct ata_taskfile *tf) 829unsigned int ata_dev_classify(const struct ata_taskfile *tf)
873{ 830{
874 /* Apple's open source Darwin code hints that some devices only 831 /* Apple's open source Darwin code hints that some devices only
875 * put a proper signature into the LBA mid/high registers, 832 * put a proper signature into the LBA mid/high registers,
@@ -921,8 +878,8 @@ static u8 ata_dev_try_classify(struct ata_port *ap, unsigned int device)
921 878
922 memset(&tf, 0, sizeof(tf)); 879 memset(&tf, 0, sizeof(tf));
923 880
924 err = ata_chk_err(ap);
925 ap->ops->tf_read(ap, &tf); 881 ap->ops->tf_read(ap, &tf);
882 err = tf.feature;
926 883
927 dev->class = ATA_DEV_NONE; 884 dev->class = ATA_DEV_NONE;
928 885
@@ -961,7 +918,7 @@ static u8 ata_dev_try_classify(struct ata_port *ap, unsigned int device)
961 * caller. 918 * caller.
962 */ 919 */
963 920
964void ata_dev_id_string(u16 *id, unsigned char *s, 921void ata_dev_id_string(const u16 *id, unsigned char *s,
965 unsigned int ofs, unsigned int len) 922 unsigned int ofs, unsigned int len)
966{ 923{
967 unsigned int c; 924 unsigned int c;
@@ -1078,7 +1035,7 @@ void ata_dev_select(struct ata_port *ap, unsigned int device,
1078 * caller. 1035 * caller.
1079 */ 1036 */
1080 1037
1081static inline void ata_dump_id(struct ata_device *dev) 1038static inline void ata_dump_id(const struct ata_device *dev)
1082{ 1039{
1083 DPRINTK("49==0x%04x " 1040 DPRINTK("49==0x%04x "
1084 "53==0x%04x " 1041 "53==0x%04x "
@@ -1106,6 +1063,31 @@ static inline void ata_dump_id(struct ata_device *dev)
1106 dev->id[93]); 1063 dev->id[93]);
1107} 1064}
1108 1065
1066/*
1067 * Compute the PIO modes available for this device. This is not as
1068 * trivial as it seems if we must consider early devices correctly.
1069 *
1070 * FIXME: pre IDE drive timing (do we care ?).
1071 */
1072
1073static unsigned int ata_pio_modes(const struct ata_device *adev)
1074{
1075 u16 modes;
1076
1077 /* Usual case. Word 53 indicates word 88 is valid */
1078 if (adev->id[ATA_ID_FIELD_VALID] & (1 << 2)) {
1079 modes = adev->id[ATA_ID_PIO_MODES] & 0x03;
1080 modes <<= 3;
1081 modes |= 0x7;
1082 return modes;
1083 }
1084
1085 /* If word 88 isn't valid then Word 51 holds the PIO timing number
1086 for the maximum. Turn it into a mask and return it */
1087 modes = (2 << (adev->id[ATA_ID_OLD_PIO_MODES] & 0xFF)) - 1 ;
1088 return modes;
1089}
1090
1109/** 1091/**
1110 * ata_dev_identify - obtain IDENTIFY x DEVICE page 1092 * ata_dev_identify - obtain IDENTIFY x DEVICE page
1111 * @ap: port on which device we wish to probe resides 1093 * @ap: port on which device we wish to probe resides
@@ -1131,10 +1113,9 @@ static inline void ata_dump_id(struct ata_device *dev)
1131static void ata_dev_identify(struct ata_port *ap, unsigned int device) 1113static void ata_dev_identify(struct ata_port *ap, unsigned int device)
1132{ 1114{
1133 struct ata_device *dev = &ap->device[device]; 1115 struct ata_device *dev = &ap->device[device];
1134 unsigned int i; 1116 unsigned int major_version;
1135 u16 tmp; 1117 u16 tmp;
1136 unsigned long xfer_modes; 1118 unsigned long xfer_modes;
1137 u8 status;
1138 unsigned int using_edd; 1119 unsigned int using_edd;
1139 DECLARE_COMPLETION(wait); 1120 DECLARE_COMPLETION(wait);
1140 struct ata_queued_cmd *qc; 1121 struct ata_queued_cmd *qc;
@@ -1188,8 +1169,11 @@ retry:
1188 else 1169 else
1189 wait_for_completion(&wait); 1170 wait_for_completion(&wait);
1190 1171
1191 status = ata_chk_status(ap); 1172 spin_lock_irqsave(&ap->host_set->lock, flags);
1192 if (status & ATA_ERR) { 1173 ap->ops->tf_read(ap, &qc->tf);
1174 spin_unlock_irqrestore(&ap->host_set->lock, flags);
1175
1176 if (qc->tf.command & ATA_ERR) {
1193 /* 1177 /*
1194 * arg! EDD works for all test cases, but seems to return 1178 * arg! EDD works for all test cases, but seems to return
1195 * the ATA signature for some ATAPI devices. Until the 1179 * the ATA signature for some ATAPI devices. Until the
@@ -1202,7 +1186,7 @@ retry:
1202 * to have this problem. 1186 * to have this problem.
1203 */ 1187 */
1204 if ((using_edd) && (qc->tf.command == ATA_CMD_ID_ATA)) { 1188 if ((using_edd) && (qc->tf.command == ATA_CMD_ID_ATA)) {
1205 u8 err = ata_chk_err(ap); 1189 u8 err = qc->tf.feature;
1206 if (err & ATA_ABORTED) { 1190 if (err & ATA_ABORTED) {
1207 dev->class = ATA_DEV_ATAPI; 1191 dev->class = ATA_DEV_ATAPI;
1208 qc->cursg = 0; 1192 qc->cursg = 0;
@@ -1229,9 +1213,9 @@ retry:
1229 * common ATA, ATAPI feature tests 1213 * common ATA, ATAPI feature tests
1230 */ 1214 */
1231 1215
1232 /* we require LBA and DMA support (bits 8 & 9 of word 49) */ 1216 /* we require DMA support (bits 8 of word 49) */
1233 if (!ata_id_has_dma(dev->id) || !ata_id_has_lba(dev->id)) { 1217 if (!ata_id_has_dma(dev->id)) {
1234 printk(KERN_DEBUG "ata%u: no dma/lba\n", ap->id); 1218 printk(KERN_DEBUG "ata%u: no dma\n", ap->id);
1235 goto err_out_nosup; 1219 goto err_out_nosup;
1236 } 1220 }
1237 1221
@@ -1239,10 +1223,8 @@ retry:
1239 xfer_modes = dev->id[ATA_ID_UDMA_MODES]; 1223 xfer_modes = dev->id[ATA_ID_UDMA_MODES];
1240 if (!xfer_modes) 1224 if (!xfer_modes)
1241 xfer_modes = (dev->id[ATA_ID_MWDMA_MODES]) << ATA_SHIFT_MWDMA; 1225 xfer_modes = (dev->id[ATA_ID_MWDMA_MODES]) << ATA_SHIFT_MWDMA;
1242 if (!xfer_modes) { 1226 if (!xfer_modes)
1243 xfer_modes = (dev->id[ATA_ID_PIO_MODES]) << (ATA_SHIFT_PIO + 3); 1227 xfer_modes = ata_pio_modes(dev);
1244 xfer_modes |= (0x7 << ATA_SHIFT_PIO);
1245 }
1246 1228
1247 ata_dump_id(dev); 1229 ata_dump_id(dev);
1248 1230
@@ -1251,32 +1233,75 @@ retry:
1251 if (!ata_id_is_ata(dev->id)) /* sanity check */ 1233 if (!ata_id_is_ata(dev->id)) /* sanity check */
1252 goto err_out_nosup; 1234 goto err_out_nosup;
1253 1235
1236 /* get major version */
1254 tmp = dev->id[ATA_ID_MAJOR_VER]; 1237 tmp = dev->id[ATA_ID_MAJOR_VER];
1255 for (i = 14; i >= 1; i--) 1238 for (major_version = 14; major_version >= 1; major_version--)
1256 if (tmp & (1 << i)) 1239 if (tmp & (1 << major_version))
1257 break; 1240 break;
1258 1241
1259 /* we require at least ATA-3 */ 1242 /*
1260 if (i < 3) { 1243 * The exact sequence expected by certain pre-ATA4 drives is:
1261 printk(KERN_DEBUG "ata%u: no ATA-3\n", ap->id); 1244 * SRST RESET
1262 goto err_out_nosup; 1245 * IDENTIFY
1246 * INITIALIZE DEVICE PARAMETERS
1247 * anything else..
1248 * Some drives were very specific about that exact sequence.
1249 */
1250 if (major_version < 4 || (!ata_id_has_lba(dev->id))) {
1251 ata_dev_init_params(ap, dev);
1252
1253 /* current CHS translation info (id[53-58]) might be
1254 * changed. reread the identify device info.
1255 */
1256 ata_dev_reread_id(ap, dev);
1263 } 1257 }
1264 1258
1265 if (ata_id_has_lba48(dev->id)) { 1259 if (ata_id_has_lba(dev->id)) {
1266 dev->flags |= ATA_DFLAG_LBA48; 1260 dev->flags |= ATA_DFLAG_LBA;
1267 dev->n_sectors = ata_id_u64(dev->id, 100); 1261
1268 } else { 1262 if (ata_id_has_lba48(dev->id)) {
1269 dev->n_sectors = ata_id_u32(dev->id, 60); 1263 dev->flags |= ATA_DFLAG_LBA48;
1264 dev->n_sectors = ata_id_u64(dev->id, 100);
1265 } else {
1266 dev->n_sectors = ata_id_u32(dev->id, 60);
1267 }
1268
1269 /* print device info to dmesg */
1270 printk(KERN_INFO "ata%u: dev %u ATA-%d, max %s, %Lu sectors:%s\n",
1271 ap->id, device,
1272 major_version,
1273 ata_mode_string(xfer_modes),
1274 (unsigned long long)dev->n_sectors,
1275 dev->flags & ATA_DFLAG_LBA48 ? " LBA48" : " LBA");
1276 } else {
1277 /* CHS */
1278
1279 /* Default translation */
1280 dev->cylinders = dev->id[1];
1281 dev->heads = dev->id[3];
1282 dev->sectors = dev->id[6];
1283 dev->n_sectors = dev->cylinders * dev->heads * dev->sectors;
1284
1285 if (ata_id_current_chs_valid(dev->id)) {
1286 /* Current CHS translation is valid. */
1287 dev->cylinders = dev->id[54];
1288 dev->heads = dev->id[55];
1289 dev->sectors = dev->id[56];
1290
1291 dev->n_sectors = ata_id_u32(dev->id, 57);
1292 }
1293
1294 /* print device info to dmesg */
1295 printk(KERN_INFO "ata%u: dev %u ATA-%d, max %s, %Lu sectors: CHS %d/%d/%d\n",
1296 ap->id, device,
1297 major_version,
1298 ata_mode_string(xfer_modes),
1299 (unsigned long long)dev->n_sectors,
1300 (int)dev->cylinders, (int)dev->heads, (int)dev->sectors);
1301
1270 } 1302 }
1271 1303
1272 ap->host->max_cmd_len = 16; 1304 ap->host->max_cmd_len = 16;
1273
1274 /* print device info to dmesg */
1275 printk(KERN_INFO "ata%u: dev %u ATA, max %s, %Lu sectors:%s\n",
1276 ap->id, device,
1277 ata_mode_string(xfer_modes),
1278 (unsigned long long)dev->n_sectors,
1279 dev->flags & ATA_DFLAG_LBA48 ? " lba48" : "");
1280 } 1305 }
1281 1306
1282 /* ATAPI-specific feature tests */ 1307 /* ATAPI-specific feature tests */
@@ -1310,7 +1335,7 @@ err_out:
1310} 1335}
1311 1336
1312 1337
1313static inline u8 ata_dev_knobble(struct ata_port *ap) 1338static inline u8 ata_dev_knobble(const struct ata_port *ap)
1314{ 1339{
1315 return ((ap->cbl == ATA_CBL_SATA) && (!ata_id_is_sata(ap->device->id))); 1340 return ((ap->cbl == ATA_CBL_SATA) && (!ata_id_is_sata(ap->device->id)));
1316} 1341}
@@ -1496,7 +1521,153 @@ void ata_port_disable(struct ata_port *ap)
1496 ap->flags |= ATA_FLAG_PORT_DISABLED; 1521 ap->flags |= ATA_FLAG_PORT_DISABLED;
1497} 1522}
1498 1523
1499static struct { 1524/*
1525 * This mode timing computation functionality is ported over from
1526 * drivers/ide/ide-timing.h and was originally written by Vojtech Pavlik
1527 */
1528/*
1529 * PIO 0-5, MWDMA 0-2 and UDMA 0-6 timings (in nanoseconds).
1530 * These were taken from ATA/ATAPI-6 standard, rev 0a, except
1531 * for PIO 5, which is a nonstandard extension and UDMA6, which
1532 * is currently supported only by Maxtor drives.
1533 */
1534
1535static const struct ata_timing ata_timing[] = {
1536
1537 { XFER_UDMA_6, 0, 0, 0, 0, 0, 0, 0, 15 },
1538 { XFER_UDMA_5, 0, 0, 0, 0, 0, 0, 0, 20 },
1539 { XFER_UDMA_4, 0, 0, 0, 0, 0, 0, 0, 30 },
1540 { XFER_UDMA_3, 0, 0, 0, 0, 0, 0, 0, 45 },
1541
1542 { XFER_UDMA_2, 0, 0, 0, 0, 0, 0, 0, 60 },
1543 { XFER_UDMA_1, 0, 0, 0, 0, 0, 0, 0, 80 },
1544 { XFER_UDMA_0, 0, 0, 0, 0, 0, 0, 0, 120 },
1545
1546/* { XFER_UDMA_SLOW, 0, 0, 0, 0, 0, 0, 0, 150 }, */
1547
1548 { XFER_MW_DMA_2, 25, 0, 0, 0, 70, 25, 120, 0 },
1549 { XFER_MW_DMA_1, 45, 0, 0, 0, 80, 50, 150, 0 },
1550 { XFER_MW_DMA_0, 60, 0, 0, 0, 215, 215, 480, 0 },
1551
1552 { XFER_SW_DMA_2, 60, 0, 0, 0, 120, 120, 240, 0 },
1553 { XFER_SW_DMA_1, 90, 0, 0, 0, 240, 240, 480, 0 },
1554 { XFER_SW_DMA_0, 120, 0, 0, 0, 480, 480, 960, 0 },
1555
1556/* { XFER_PIO_5, 20, 50, 30, 100, 50, 30, 100, 0 }, */
1557 { XFER_PIO_4, 25, 70, 25, 120, 70, 25, 120, 0 },
1558 { XFER_PIO_3, 30, 80, 70, 180, 80, 70, 180, 0 },
1559
1560 { XFER_PIO_2, 30, 290, 40, 330, 100, 90, 240, 0 },
1561 { XFER_PIO_1, 50, 290, 93, 383, 125, 100, 383, 0 },
1562 { XFER_PIO_0, 70, 290, 240, 600, 165, 150, 600, 0 },
1563
1564/* { XFER_PIO_SLOW, 120, 290, 240, 960, 290, 240, 960, 0 }, */
1565
1566 { 0xFF }
1567};
1568
1569#define ENOUGH(v,unit) (((v)-1)/(unit)+1)
1570#define EZ(v,unit) ((v)?ENOUGH(v,unit):0)
1571
1572static void ata_timing_quantize(const struct ata_timing *t, struct ata_timing *q, int T, int UT)
1573{
1574 q->setup = EZ(t->setup * 1000, T);
1575 q->act8b = EZ(t->act8b * 1000, T);
1576 q->rec8b = EZ(t->rec8b * 1000, T);
1577 q->cyc8b = EZ(t->cyc8b * 1000, T);
1578 q->active = EZ(t->active * 1000, T);
1579 q->recover = EZ(t->recover * 1000, T);
1580 q->cycle = EZ(t->cycle * 1000, T);
1581 q->udma = EZ(t->udma * 1000, UT);
1582}
1583
1584void ata_timing_merge(const struct ata_timing *a, const struct ata_timing *b,
1585 struct ata_timing *m, unsigned int what)
1586{
1587 if (what & ATA_TIMING_SETUP ) m->setup = max(a->setup, b->setup);
1588 if (what & ATA_TIMING_ACT8B ) m->act8b = max(a->act8b, b->act8b);
1589 if (what & ATA_TIMING_REC8B ) m->rec8b = max(a->rec8b, b->rec8b);
1590 if (what & ATA_TIMING_CYC8B ) m->cyc8b = max(a->cyc8b, b->cyc8b);
1591 if (what & ATA_TIMING_ACTIVE ) m->active = max(a->active, b->active);
1592 if (what & ATA_TIMING_RECOVER) m->recover = max(a->recover, b->recover);
1593 if (what & ATA_TIMING_CYCLE ) m->cycle = max(a->cycle, b->cycle);
1594 if (what & ATA_TIMING_UDMA ) m->udma = max(a->udma, b->udma);
1595}
1596
1597static const struct ata_timing* ata_timing_find_mode(unsigned short speed)
1598{
1599 const struct ata_timing *t;
1600
1601 for (t = ata_timing; t->mode != speed; t++)
1602 if (t->mode == 0xFF)
1603 return NULL;
1604 return t;
1605}
1606
1607int ata_timing_compute(struct ata_device *adev, unsigned short speed,
1608 struct ata_timing *t, int T, int UT)
1609{
1610 const struct ata_timing *s;
1611 struct ata_timing p;
1612
1613 /*
1614 * Find the mode.
1615 */
1616
1617 if (!(s = ata_timing_find_mode(speed)))
1618 return -EINVAL;
1619
1620 /*
1621 * If the drive is an EIDE drive, it can tell us it needs extended
1622 * PIO/MW_DMA cycle timing.
1623 */
1624
1625 if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE drive */
1626 memset(&p, 0, sizeof(p));
1627 if(speed >= XFER_PIO_0 && speed <= XFER_SW_DMA_0) {
1628 if (speed <= XFER_PIO_2) p.cycle = p.cyc8b = adev->id[ATA_ID_EIDE_PIO];
1629 else p.cycle = p.cyc8b = adev->id[ATA_ID_EIDE_PIO_IORDY];
1630 } else if(speed >= XFER_MW_DMA_0 && speed <= XFER_MW_DMA_2) {
1631 p.cycle = adev->id[ATA_ID_EIDE_DMA_MIN];
1632 }
1633 ata_timing_merge(&p, t, t, ATA_TIMING_CYCLE | ATA_TIMING_CYC8B);
1634 }
1635
1636 /*
1637 * Convert the timing to bus clock counts.
1638 */
1639
1640 ata_timing_quantize(s, t, T, UT);
1641
1642 /*
1643 * Even in DMA/UDMA modes we still use PIO access for IDENTIFY, S.M.A.R.T
1644 * and some other commands. We have to ensure that the DMA cycle timing is
1645 * slower/equal than the fastest PIO timing.
1646 */
1647
1648 if (speed > XFER_PIO_4) {
1649 ata_timing_compute(adev, adev->pio_mode, &p, T, UT);
1650 ata_timing_merge(&p, t, t, ATA_TIMING_ALL);
1651 }
1652
1653 /*
1654 * Lenghten active & recovery time so that cycle time is correct.
1655 */
1656
1657 if (t->act8b + t->rec8b < t->cyc8b) {
1658 t->act8b += (t->cyc8b - (t->act8b + t->rec8b)) / 2;
1659 t->rec8b = t->cyc8b - t->act8b;
1660 }
1661
1662 if (t->active + t->recover < t->cycle) {
1663 t->active += (t->cycle - (t->active + t->recover)) / 2;
1664 t->recover = t->cycle - t->active;
1665 }
1666
1667 return 0;
1668}
1669
1670static const struct {
1500 unsigned int shift; 1671 unsigned int shift;
1501 u8 base; 1672 u8 base;
1502} xfer_mode_classes[] = { 1673} xfer_mode_classes[] = {
@@ -1603,7 +1774,7 @@ static void ata_host_set_dma(struct ata_port *ap, u8 xfer_mode,
1603 */ 1774 */
1604static void ata_set_mode(struct ata_port *ap) 1775static void ata_set_mode(struct ata_port *ap)
1605{ 1776{
1606 unsigned int i, xfer_shift; 1777 unsigned int xfer_shift;
1607 u8 xfer_mode; 1778 u8 xfer_mode;
1608 int rc; 1779 int rc;
1609 1780
@@ -1632,11 +1803,6 @@ static void ata_set_mode(struct ata_port *ap)
1632 if (ap->ops->post_set_mode) 1803 if (ap->ops->post_set_mode)
1633 ap->ops->post_set_mode(ap); 1804 ap->ops->post_set_mode(ap);
1634 1805
1635 for (i = 0; i < 2; i++) {
1636 struct ata_device *dev = &ap->device[i];
1637 ata_dev_set_protocol(dev);
1638 }
1639
1640 return; 1806 return;
1641 1807
1642err_out: 1808err_out:
@@ -1910,7 +2076,8 @@ err_out:
1910 DPRINTK("EXIT\n"); 2076 DPRINTK("EXIT\n");
1911} 2077}
1912 2078
1913static void ata_pr_blacklisted(struct ata_port *ap, struct ata_device *dev) 2079static void ata_pr_blacklisted(const struct ata_port *ap,
2080 const struct ata_device *dev)
1914{ 2081{
1915 printk(KERN_WARNING "ata%u: dev %u is on DMA blacklist, disabling DMA\n", 2082 printk(KERN_WARNING "ata%u: dev %u is on DMA blacklist, disabling DMA\n",
1916 ap->id, dev->devno); 2083 ap->id, dev->devno);
@@ -1948,7 +2115,7 @@ static const char * ata_dma_blacklist [] = {
1948 "_NEC DV5800A", 2115 "_NEC DV5800A",
1949}; 2116};
1950 2117
1951static int ata_dma_blacklisted(struct ata_port *ap, struct ata_device *dev) 2118static int ata_dma_blacklisted(const struct ata_device *dev)
1952{ 2119{
1953 unsigned char model_num[40]; 2120 unsigned char model_num[40];
1954 char *s; 2121 char *s;
@@ -1973,9 +2140,9 @@ static int ata_dma_blacklisted(struct ata_port *ap, struct ata_device *dev)
1973 return 0; 2140 return 0;
1974} 2141}
1975 2142
1976static unsigned int ata_get_mode_mask(struct ata_port *ap, int shift) 2143static unsigned int ata_get_mode_mask(const struct ata_port *ap, int shift)
1977{ 2144{
1978 struct ata_device *master, *slave; 2145 const struct ata_device *master, *slave;
1979 unsigned int mask; 2146 unsigned int mask;
1980 2147
1981 master = &ap->device[0]; 2148 master = &ap->device[0];
@@ -1987,14 +2154,14 @@ static unsigned int ata_get_mode_mask(struct ata_port *ap, int shift)
1987 mask = ap->udma_mask; 2154 mask = ap->udma_mask;
1988 if (ata_dev_present(master)) { 2155 if (ata_dev_present(master)) {
1989 mask &= (master->id[ATA_ID_UDMA_MODES] & 0xff); 2156 mask &= (master->id[ATA_ID_UDMA_MODES] & 0xff);
1990 if (ata_dma_blacklisted(ap, master)) { 2157 if (ata_dma_blacklisted(master)) {
1991 mask = 0; 2158 mask = 0;
1992 ata_pr_blacklisted(ap, master); 2159 ata_pr_blacklisted(ap, master);
1993 } 2160 }
1994 } 2161 }
1995 if (ata_dev_present(slave)) { 2162 if (ata_dev_present(slave)) {
1996 mask &= (slave->id[ATA_ID_UDMA_MODES] & 0xff); 2163 mask &= (slave->id[ATA_ID_UDMA_MODES] & 0xff);
1997 if (ata_dma_blacklisted(ap, slave)) { 2164 if (ata_dma_blacklisted(slave)) {
1998 mask = 0; 2165 mask = 0;
1999 ata_pr_blacklisted(ap, slave); 2166 ata_pr_blacklisted(ap, slave);
2000 } 2167 }
@@ -2004,14 +2171,14 @@ static unsigned int ata_get_mode_mask(struct ata_port *ap, int shift)
2004 mask = ap->mwdma_mask; 2171 mask = ap->mwdma_mask;
2005 if (ata_dev_present(master)) { 2172 if (ata_dev_present(master)) {
2006 mask &= (master->id[ATA_ID_MWDMA_MODES] & 0x07); 2173 mask &= (master->id[ATA_ID_MWDMA_MODES] & 0x07);
2007 if (ata_dma_blacklisted(ap, master)) { 2174 if (ata_dma_blacklisted(master)) {
2008 mask = 0; 2175 mask = 0;
2009 ata_pr_blacklisted(ap, master); 2176 ata_pr_blacklisted(ap, master);
2010 } 2177 }
2011 } 2178 }
2012 if (ata_dev_present(slave)) { 2179 if (ata_dev_present(slave)) {
2013 mask &= (slave->id[ATA_ID_MWDMA_MODES] & 0x07); 2180 mask &= (slave->id[ATA_ID_MWDMA_MODES] & 0x07);
2014 if (ata_dma_blacklisted(ap, slave)) { 2181 if (ata_dma_blacklisted(slave)) {
2015 mask = 0; 2182 mask = 0;
2016 ata_pr_blacklisted(ap, slave); 2183 ata_pr_blacklisted(ap, slave);
2017 } 2184 }
@@ -2075,7 +2242,7 @@ static int fgb(u32 bitmap)
2075 * Zero on success, negative on error. 2242 * Zero on success, negative on error.
2076 */ 2243 */
2077 2244
2078static int ata_choose_xfer_mode(struct ata_port *ap, 2245static int ata_choose_xfer_mode(const struct ata_port *ap,
2079 u8 *xfer_mode_out, 2246 u8 *xfer_mode_out,
2080 unsigned int *xfer_shift_out) 2247 unsigned int *xfer_shift_out)
2081{ 2248{
@@ -2144,6 +2311,110 @@ static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev)
2144} 2311}
2145 2312
2146/** 2313/**
2314 * ata_dev_reread_id - Reread the device identify device info
2315 * @ap: port where the device is
2316 * @dev: device to reread the identify device info
2317 *
2318 * LOCKING:
2319 */
2320
2321static void ata_dev_reread_id(struct ata_port *ap, struct ata_device *dev)
2322{
2323 DECLARE_COMPLETION(wait);
2324 struct ata_queued_cmd *qc;
2325 unsigned long flags;
2326 int rc;
2327
2328 qc = ata_qc_new_init(ap, dev);
2329 BUG_ON(qc == NULL);
2330
2331 ata_sg_init_one(qc, dev->id, sizeof(dev->id));
2332 qc->dma_dir = DMA_FROM_DEVICE;
2333
2334 if (dev->class == ATA_DEV_ATA) {
2335 qc->tf.command = ATA_CMD_ID_ATA;
2336 DPRINTK("do ATA identify\n");
2337 } else {
2338 qc->tf.command = ATA_CMD_ID_ATAPI;
2339 DPRINTK("do ATAPI identify\n");
2340 }
2341
2342 qc->tf.flags |= ATA_TFLAG_DEVICE;
2343 qc->tf.protocol = ATA_PROT_PIO;
2344 qc->nsect = 1;
2345
2346 qc->waiting = &wait;
2347 qc->complete_fn = ata_qc_complete_noop;
2348
2349 spin_lock_irqsave(&ap->host_set->lock, flags);
2350 rc = ata_qc_issue(qc);
2351 spin_unlock_irqrestore(&ap->host_set->lock, flags);
2352
2353 if (rc)
2354 goto err_out;
2355
2356 wait_for_completion(&wait);
2357
2358 swap_buf_le16(dev->id, ATA_ID_WORDS);
2359
2360 ata_dump_id(dev);
2361
2362 DPRINTK("EXIT\n");
2363
2364 return;
2365err_out:
2366 ata_port_disable(ap);
2367}
2368
2369/**
2370 * ata_dev_init_params - Issue INIT DEV PARAMS command
2371 * @ap: Port associated with device @dev
2372 * @dev: Device to which command will be sent
2373 *
2374 * LOCKING:
2375 */
2376
2377static void ata_dev_init_params(struct ata_port *ap, struct ata_device *dev)
2378{
2379 DECLARE_COMPLETION(wait);
2380 struct ata_queued_cmd *qc;
2381 int rc;
2382 unsigned long flags;
2383 u16 sectors = dev->id[6];
2384 u16 heads = dev->id[3];
2385
2386 /* Number of sectors per track 1-255. Number of heads 1-16 */
2387 if (sectors < 1 || sectors > 255 || heads < 1 || heads > 16)
2388 return;
2389
2390 /* set up init dev params taskfile */
2391 DPRINTK("init dev params \n");
2392
2393 qc = ata_qc_new_init(ap, dev);
2394 BUG_ON(qc == NULL);
2395
2396 qc->tf.command = ATA_CMD_INIT_DEV_PARAMS;
2397 qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
2398 qc->tf.protocol = ATA_PROT_NODATA;
2399 qc->tf.nsect = sectors;
2400 qc->tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */
2401
2402 qc->waiting = &wait;
2403 qc->complete_fn = ata_qc_complete_noop;
2404
2405 spin_lock_irqsave(&ap->host_set->lock, flags);
2406 rc = ata_qc_issue(qc);
2407 spin_unlock_irqrestore(&ap->host_set->lock, flags);
2408
2409 if (rc)
2410 ata_port_disable(ap);
2411 else
2412 wait_for_completion(&wait);
2413
2414 DPRINTK("EXIT\n");
2415}
2416
2417/**
2147 * ata_sg_clean - Unmap DMA memory associated with command 2418 * ata_sg_clean - Unmap DMA memory associated with command
2148 * @qc: Command containing DMA memory to be released 2419 * @qc: Command containing DMA memory to be released
2149 * 2420 *
@@ -2284,19 +2555,12 @@ void ata_qc_prep(struct ata_queued_cmd *qc)
2284 2555
2285void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen) 2556void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen)
2286{ 2557{
2287 struct scatterlist *sg;
2288
2289 qc->flags |= ATA_QCFLAG_SINGLE; 2558 qc->flags |= ATA_QCFLAG_SINGLE;
2290 2559
2291 memset(&qc->sgent, 0, sizeof(qc->sgent));
2292 qc->sg = &qc->sgent; 2560 qc->sg = &qc->sgent;
2293 qc->n_elem = 1; 2561 qc->n_elem = 1;
2294 qc->buf_virt = buf; 2562 qc->buf_virt = buf;
2295 2563 sg_init_one(qc->sg, buf, buflen);
2296 sg = qc->sg;
2297 sg->page = virt_to_page(buf);
2298 sg->offset = (unsigned long) buf & ~PAGE_MASK;
2299 sg->length = buflen;
2300} 2564}
2301 2565
2302/** 2566/**
@@ -2399,7 +2663,7 @@ static int ata_sg_setup(struct ata_queued_cmd *qc)
2399 * None. (grabs host lock) 2663 * None. (grabs host lock)
2400 */ 2664 */
2401 2665
2402void ata_poll_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) 2666void ata_poll_qc_complete(struct ata_queued_cmd *qc, unsigned int err_mask)
2403{ 2667{
2404 struct ata_port *ap = qc->ap; 2668 struct ata_port *ap = qc->ap;
2405 unsigned long flags; 2669 unsigned long flags;
@@ -2407,38 +2671,38 @@ void ata_poll_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat)
2407 spin_lock_irqsave(&ap->host_set->lock, flags); 2671 spin_lock_irqsave(&ap->host_set->lock, flags);
2408 ap->flags &= ~ATA_FLAG_NOINTR; 2672 ap->flags &= ~ATA_FLAG_NOINTR;
2409 ata_irq_on(ap); 2673 ata_irq_on(ap);
2410 ata_qc_complete(qc, drv_stat); 2674 ata_qc_complete(qc, err_mask);
2411 spin_unlock_irqrestore(&ap->host_set->lock, flags); 2675 spin_unlock_irqrestore(&ap->host_set->lock, flags);
2412} 2676}
2413 2677
2414/** 2678/**
2415 * ata_pio_poll - 2679 * ata_pio_poll -
2416 * @ap: 2680 * @ap: the target ata_port
2417 * 2681 *
2418 * LOCKING: 2682 * LOCKING:
2419 * None. (executing in kernel thread context) 2683 * None. (executing in kernel thread context)
2420 * 2684 *
2421 * RETURNS: 2685 * RETURNS:
2422 * 2686 * timeout value to use
2423 */ 2687 */
2424 2688
2425static unsigned long ata_pio_poll(struct ata_port *ap) 2689static unsigned long ata_pio_poll(struct ata_port *ap)
2426{ 2690{
2427 u8 status; 2691 u8 status;
2428 unsigned int poll_state = PIO_ST_UNKNOWN; 2692 unsigned int poll_state = HSM_ST_UNKNOWN;
2429 unsigned int reg_state = PIO_ST_UNKNOWN; 2693 unsigned int reg_state = HSM_ST_UNKNOWN;
2430 const unsigned int tmout_state = PIO_ST_TMOUT; 2694 const unsigned int tmout_state = HSM_ST_TMOUT;
2431 2695
2432 switch (ap->pio_task_state) { 2696 switch (ap->hsm_task_state) {
2433 case PIO_ST: 2697 case HSM_ST:
2434 case PIO_ST_POLL: 2698 case HSM_ST_POLL:
2435 poll_state = PIO_ST_POLL; 2699 poll_state = HSM_ST_POLL;
2436 reg_state = PIO_ST; 2700 reg_state = HSM_ST;
2437 break; 2701 break;
2438 case PIO_ST_LAST: 2702 case HSM_ST_LAST:
2439 case PIO_ST_LAST_POLL: 2703 case HSM_ST_LAST_POLL:
2440 poll_state = PIO_ST_LAST_POLL; 2704 poll_state = HSM_ST_LAST_POLL;
2441 reg_state = PIO_ST_LAST; 2705 reg_state = HSM_ST_LAST;
2442 break; 2706 break;
2443 default: 2707 default:
2444 BUG(); 2708 BUG();
@@ -2448,20 +2712,20 @@ static unsigned long ata_pio_poll(struct ata_port *ap)
2448 status = ata_chk_status(ap); 2712 status = ata_chk_status(ap);
2449 if (status & ATA_BUSY) { 2713 if (status & ATA_BUSY) {
2450 if (time_after(jiffies, ap->pio_task_timeout)) { 2714 if (time_after(jiffies, ap->pio_task_timeout)) {
2451 ap->pio_task_state = tmout_state; 2715 ap->hsm_task_state = tmout_state;
2452 return 0; 2716 return 0;
2453 } 2717 }
2454 ap->pio_task_state = poll_state; 2718 ap->hsm_task_state = poll_state;
2455 return ATA_SHORT_PAUSE; 2719 return ATA_SHORT_PAUSE;
2456 } 2720 }
2457 2721
2458 ap->pio_task_state = reg_state; 2722 ap->hsm_task_state = reg_state;
2459 return 0; 2723 return 0;
2460} 2724}
2461 2725
2462/** 2726/**
2463 * ata_pio_complete - 2727 * ata_pio_complete - check if drive is busy or idle
2464 * @ap: 2728 * @ap: the target ata_port
2465 * 2729 *
2466 * LOCKING: 2730 * LOCKING:
2467 * None. (executing in kernel thread context) 2731 * None. (executing in kernel thread context)
@@ -2480,14 +2744,14 @@ static int ata_pio_complete (struct ata_port *ap)
2480 * we enter, BSY will be cleared in a chk-status or two. If not, 2744 * we enter, BSY will be cleared in a chk-status or two. If not,
2481 * the drive is probably seeking or something. Snooze for a couple 2745 * the drive is probably seeking or something. Snooze for a couple
2482 * msecs, then chk-status again. If still busy, fall back to 2746 * msecs, then chk-status again. If still busy, fall back to
2483 * PIO_ST_POLL state. 2747 * HSM_ST_POLL state.
2484 */ 2748 */
2485 drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 10); 2749 drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 10);
2486 if (drv_stat & (ATA_BUSY | ATA_DRQ)) { 2750 if (drv_stat & (ATA_BUSY | ATA_DRQ)) {
2487 msleep(2); 2751 msleep(2);
2488 drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 10); 2752 drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 10);
2489 if (drv_stat & (ATA_BUSY | ATA_DRQ)) { 2753 if (drv_stat & (ATA_BUSY | ATA_DRQ)) {
2490 ap->pio_task_state = PIO_ST_LAST_POLL; 2754 ap->hsm_task_state = HSM_ST_LAST_POLL;
2491 ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO; 2755 ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO;
2492 return 0; 2756 return 0;
2493 } 2757 }
@@ -2495,16 +2759,16 @@ static int ata_pio_complete (struct ata_port *ap)
2495 2759
2496 drv_stat = ata_wait_idle(ap); 2760 drv_stat = ata_wait_idle(ap);
2497 if (!ata_ok(drv_stat)) { 2761 if (!ata_ok(drv_stat)) {
2498 ap->pio_task_state = PIO_ST_ERR; 2762 ap->hsm_task_state = HSM_ST_ERR;
2499 return 0; 2763 return 0;
2500 } 2764 }
2501 2765
2502 qc = ata_qc_from_tag(ap, ap->active_tag); 2766 qc = ata_qc_from_tag(ap, ap->active_tag);
2503 assert(qc != NULL); 2767 assert(qc != NULL);
2504 2768
2505 ap->pio_task_state = PIO_ST_IDLE; 2769 ap->hsm_task_state = HSM_ST_IDLE;
2506 2770
2507 ata_poll_qc_complete(qc, drv_stat); 2771 ata_poll_qc_complete(qc, 0);
2508 2772
2509 /* another command may start at this point */ 2773 /* another command may start at this point */
2510 2774
@@ -2513,7 +2777,7 @@ static int ata_pio_complete (struct ata_port *ap)
2513 2777
2514 2778
2515/** 2779/**
2516 * swap_buf_le16 - 2780 * swap_buf_le16 - swap halves of 16-words in place
2517 * @buf: Buffer to swap 2781 * @buf: Buffer to swap
2518 * @buf_words: Number of 16-bit words in buffer. 2782 * @buf_words: Number of 16-bit words in buffer.
2519 * 2783 *
@@ -2522,6 +2786,7 @@ static int ata_pio_complete (struct ata_port *ap)
2522 * vice-versa. 2786 * vice-versa.
2523 * 2787 *
2524 * LOCKING: 2788 * LOCKING:
2789 * Inherited from caller.
2525 */ 2790 */
2526void swap_buf_le16(u16 *buf, unsigned int buf_words) 2791void swap_buf_le16(u16 *buf, unsigned int buf_words)
2527{ 2792{
@@ -2544,7 +2809,6 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
2544 * 2809 *
2545 * LOCKING: 2810 * LOCKING:
2546 * Inherited from caller. 2811 * Inherited from caller.
2547 *
2548 */ 2812 */
2549 2813
2550static void ata_mmio_data_xfer(struct ata_port *ap, unsigned char *buf, 2814static void ata_mmio_data_xfer(struct ata_port *ap, unsigned char *buf,
@@ -2590,7 +2854,6 @@ static void ata_mmio_data_xfer(struct ata_port *ap, unsigned char *buf,
2590 * 2854 *
2591 * LOCKING: 2855 * LOCKING:
2592 * Inherited from caller. 2856 * Inherited from caller.
2593 *
2594 */ 2857 */
2595 2858
2596static void ata_pio_data_xfer(struct ata_port *ap, unsigned char *buf, 2859static void ata_pio_data_xfer(struct ata_port *ap, unsigned char *buf,
@@ -2630,7 +2893,6 @@ static void ata_pio_data_xfer(struct ata_port *ap, unsigned char *buf,
2630 * 2893 *
2631 * LOCKING: 2894 * LOCKING:
2632 * Inherited from caller. 2895 * Inherited from caller.
2633 *
2634 */ 2896 */
2635 2897
2636static void ata_data_xfer(struct ata_port *ap, unsigned char *buf, 2898static void ata_data_xfer(struct ata_port *ap, unsigned char *buf,
@@ -2662,7 +2924,7 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
2662 unsigned char *buf; 2924 unsigned char *buf;
2663 2925
2664 if (qc->cursect == (qc->nsect - 1)) 2926 if (qc->cursect == (qc->nsect - 1))
2665 ap->pio_task_state = PIO_ST_LAST; 2927 ap->hsm_task_state = HSM_ST_LAST;
2666 2928
2667 page = sg[qc->cursg].page; 2929 page = sg[qc->cursg].page;
2668 offset = sg[qc->cursg].offset + qc->cursg_ofs * ATA_SECT_SIZE; 2930 offset = sg[qc->cursg].offset + qc->cursg_ofs * ATA_SECT_SIZE;
@@ -2712,7 +2974,7 @@ static void __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes)
2712 unsigned int offset, count; 2974 unsigned int offset, count;
2713 2975
2714 if (qc->curbytes + bytes >= qc->nbytes) 2976 if (qc->curbytes + bytes >= qc->nbytes)
2715 ap->pio_task_state = PIO_ST_LAST; 2977 ap->hsm_task_state = HSM_ST_LAST;
2716 2978
2717next_sg: 2979next_sg:
2718 if (unlikely(qc->cursg >= qc->n_elem)) { 2980 if (unlikely(qc->cursg >= qc->n_elem)) {
@@ -2734,7 +2996,7 @@ next_sg:
2734 for (i = 0; i < words; i++) 2996 for (i = 0; i < words; i++)
2735 ata_data_xfer(ap, (unsigned char*)pad_buf, 2, do_write); 2997 ata_data_xfer(ap, (unsigned char*)pad_buf, 2, do_write);
2736 2998
2737 ap->pio_task_state = PIO_ST_LAST; 2999 ap->hsm_task_state = HSM_ST_LAST;
2738 return; 3000 return;
2739 } 3001 }
2740 3002
@@ -2783,7 +3045,6 @@ next_sg:
2783 * 3045 *
2784 * LOCKING: 3046 * LOCKING:
2785 * Inherited from caller. 3047 * Inherited from caller.
2786 *
2787 */ 3048 */
2788 3049
2789static void atapi_pio_bytes(struct ata_queued_cmd *qc) 3050static void atapi_pio_bytes(struct ata_queued_cmd *qc)
@@ -2815,12 +3076,12 @@ static void atapi_pio_bytes(struct ata_queued_cmd *qc)
2815err_out: 3076err_out:
2816 printk(KERN_INFO "ata%u: dev %u: ATAPI check failed\n", 3077 printk(KERN_INFO "ata%u: dev %u: ATAPI check failed\n",
2817 ap->id, dev->devno); 3078 ap->id, dev->devno);
2818 ap->pio_task_state = PIO_ST_ERR; 3079 ap->hsm_task_state = HSM_ST_ERR;
2819} 3080}
2820 3081
2821/** 3082/**
2822 * ata_pio_sector - 3083 * ata_pio_block - start PIO on a block
2823 * @ap: 3084 * @ap: the target ata_port
2824 * 3085 *
2825 * LOCKING: 3086 * LOCKING:
2826 * None. (executing in kernel thread context) 3087 * None. (executing in kernel thread context)
@@ -2832,19 +3093,19 @@ static void ata_pio_block(struct ata_port *ap)
2832 u8 status; 3093 u8 status;
2833 3094
2834 /* 3095 /*
2835 * This is purely hueristic. This is a fast path. 3096 * This is purely heuristic. This is a fast path.
2836 * Sometimes when we enter, BSY will be cleared in 3097 * Sometimes when we enter, BSY will be cleared in
2837 * a chk-status or two. If not, the drive is probably seeking 3098 * a chk-status or two. If not, the drive is probably seeking
2838 * or something. Snooze for a couple msecs, then 3099 * or something. Snooze for a couple msecs, then
2839 * chk-status again. If still busy, fall back to 3100 * chk-status again. If still busy, fall back to
2840 * PIO_ST_POLL state. 3101 * HSM_ST_POLL state.
2841 */ 3102 */
2842 status = ata_busy_wait(ap, ATA_BUSY, 5); 3103 status = ata_busy_wait(ap, ATA_BUSY, 5);
2843 if (status & ATA_BUSY) { 3104 if (status & ATA_BUSY) {
2844 msleep(2); 3105 msleep(2);
2845 status = ata_busy_wait(ap, ATA_BUSY, 10); 3106 status = ata_busy_wait(ap, ATA_BUSY, 10);
2846 if (status & ATA_BUSY) { 3107 if (status & ATA_BUSY) {
2847 ap->pio_task_state = PIO_ST_POLL; 3108 ap->hsm_task_state = HSM_ST_POLL;
2848 ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO; 3109 ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO;
2849 return; 3110 return;
2850 } 3111 }
@@ -2856,7 +3117,7 @@ static void ata_pio_block(struct ata_port *ap)
2856 if (is_atapi_taskfile(&qc->tf)) { 3117 if (is_atapi_taskfile(&qc->tf)) {
2857 /* no more data to transfer or unsupported ATAPI command */ 3118 /* no more data to transfer or unsupported ATAPI command */
2858 if ((status & ATA_DRQ) == 0) { 3119 if ((status & ATA_DRQ) == 0) {
2859 ap->pio_task_state = PIO_ST_LAST; 3120 ap->hsm_task_state = HSM_ST_LAST;
2860 return; 3121 return;
2861 } 3122 }
2862 3123
@@ -2864,7 +3125,7 @@ static void ata_pio_block(struct ata_port *ap)
2864 } else { 3125 } else {
2865 /* handle BSY=0, DRQ=0 as error */ 3126 /* handle BSY=0, DRQ=0 as error */
2866 if ((status & ATA_DRQ) == 0) { 3127 if ((status & ATA_DRQ) == 0) {
2867 ap->pio_task_state = PIO_ST_ERR; 3128 ap->hsm_task_state = HSM_ST_ERR;
2868 return; 3129 return;
2869 } 3130 }
2870 3131
@@ -2875,18 +3136,15 @@ static void ata_pio_block(struct ata_port *ap)
2875static void ata_pio_error(struct ata_port *ap) 3136static void ata_pio_error(struct ata_port *ap)
2876{ 3137{
2877 struct ata_queued_cmd *qc; 3138 struct ata_queued_cmd *qc;
2878 u8 drv_stat; 3139
3140 printk(KERN_WARNING "ata%u: PIO error\n", ap->id);
2879 3141
2880 qc = ata_qc_from_tag(ap, ap->active_tag); 3142 qc = ata_qc_from_tag(ap, ap->active_tag);
2881 assert(qc != NULL); 3143 assert(qc != NULL);
2882 3144
2883 drv_stat = ata_chk_status(ap); 3145 ap->hsm_task_state = HSM_ST_IDLE;
2884 printk(KERN_WARNING "ata%u: PIO error, drv_stat 0x%x\n",
2885 ap->id, drv_stat);
2886
2887 ap->pio_task_state = PIO_ST_IDLE;
2888 3146
2889 ata_poll_qc_complete(qc, drv_stat | ATA_ERR); 3147 ata_poll_qc_complete(qc, AC_ERR_ATA_BUS);
2890} 3148}
2891 3149
2892static void ata_pio_task(void *_data) 3150static void ata_pio_task(void *_data)
@@ -2899,25 +3157,25 @@ fsm_start:
2899 timeout = 0; 3157 timeout = 0;
2900 qc_completed = 0; 3158 qc_completed = 0;
2901 3159
2902 switch (ap->pio_task_state) { 3160 switch (ap->hsm_task_state) {
2903 case PIO_ST_IDLE: 3161 case HSM_ST_IDLE:
2904 return; 3162 return;
2905 3163
2906 case PIO_ST: 3164 case HSM_ST:
2907 ata_pio_block(ap); 3165 ata_pio_block(ap);
2908 break; 3166 break;
2909 3167
2910 case PIO_ST_LAST: 3168 case HSM_ST_LAST:
2911 qc_completed = ata_pio_complete(ap); 3169 qc_completed = ata_pio_complete(ap);
2912 break; 3170 break;
2913 3171
2914 case PIO_ST_POLL: 3172 case HSM_ST_POLL:
2915 case PIO_ST_LAST_POLL: 3173 case HSM_ST_LAST_POLL:
2916 timeout = ata_pio_poll(ap); 3174 timeout = ata_pio_poll(ap);
2917 break; 3175 break;
2918 3176
2919 case PIO_ST_TMOUT: 3177 case HSM_ST_TMOUT:
2920 case PIO_ST_ERR: 3178 case HSM_ST_ERR:
2921 ata_pio_error(ap); 3179 ata_pio_error(ap);
2922 return; 3180 return;
2923 } 3181 }
@@ -2928,52 +3186,6 @@ fsm_start:
2928 goto fsm_start; 3186 goto fsm_start;
2929} 3187}
2930 3188
2931static void atapi_request_sense(struct ata_port *ap, struct ata_device *dev,
2932 struct scsi_cmnd *cmd)
2933{
2934 DECLARE_COMPLETION(wait);
2935 struct ata_queued_cmd *qc;
2936 unsigned long flags;
2937 int rc;
2938
2939 DPRINTK("ATAPI request sense\n");
2940
2941 qc = ata_qc_new_init(ap, dev);
2942 BUG_ON(qc == NULL);
2943
2944 /* FIXME: is this needed? */
2945 memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
2946
2947 ata_sg_init_one(qc, cmd->sense_buffer, sizeof(cmd->sense_buffer));
2948 qc->dma_dir = DMA_FROM_DEVICE;
2949
2950 memset(&qc->cdb, 0, ap->cdb_len);
2951 qc->cdb[0] = REQUEST_SENSE;
2952 qc->cdb[4] = SCSI_SENSE_BUFFERSIZE;
2953
2954 qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
2955 qc->tf.command = ATA_CMD_PACKET;
2956
2957 qc->tf.protocol = ATA_PROT_ATAPI;
2958 qc->tf.lbam = (8 * 1024) & 0xff;
2959 qc->tf.lbah = (8 * 1024) >> 8;
2960 qc->nbytes = SCSI_SENSE_BUFFERSIZE;
2961
2962 qc->waiting = &wait;
2963 qc->complete_fn = ata_qc_complete_noop;
2964
2965 spin_lock_irqsave(&ap->host_set->lock, flags);
2966 rc = ata_qc_issue(qc);
2967 spin_unlock_irqrestore(&ap->host_set->lock, flags);
2968
2969 if (rc)
2970 ata_port_disable(ap);
2971 else
2972 wait_for_completion(&wait);
2973
2974 DPRINTK("EXIT\n");
2975}
2976
2977/** 3189/**
2978 * ata_qc_timeout - Handle timeout of queued command 3190 * ata_qc_timeout - Handle timeout of queued command
2979 * @qc: Command that timed out 3191 * @qc: Command that timed out
@@ -3055,7 +3267,7 @@ static void ata_qc_timeout(struct ata_queued_cmd *qc)
3055 ap->id, qc->tf.command, drv_stat, host_stat); 3267 ap->id, qc->tf.command, drv_stat, host_stat);
3056 3268
3057 /* complete taskfile transaction */ 3269 /* complete taskfile transaction */
3058 ata_qc_complete(qc, drv_stat); 3270 ata_qc_complete(qc, ac_err_mask(drv_stat));
3059 break; 3271 break;
3060 } 3272 }
3061 3273
@@ -3091,14 +3303,14 @@ void ata_eng_timeout(struct ata_port *ap)
3091 DPRINTK("ENTER\n"); 3303 DPRINTK("ENTER\n");
3092 3304
3093 qc = ata_qc_from_tag(ap, ap->active_tag); 3305 qc = ata_qc_from_tag(ap, ap->active_tag);
3094 if (!qc) { 3306 if (qc)
3307 ata_qc_timeout(qc);
3308 else {
3095 printk(KERN_ERR "ata%u: BUG: timeout without command\n", 3309 printk(KERN_ERR "ata%u: BUG: timeout without command\n",
3096 ap->id); 3310 ap->id);
3097 goto out; 3311 goto out;
3098 } 3312 }
3099 3313
3100 ata_qc_timeout(qc);
3101
3102out: 3314out:
3103 DPRINTK("EXIT\n"); 3315 DPRINTK("EXIT\n");
3104} 3316}
@@ -3155,15 +3367,12 @@ struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap,
3155 qc->nbytes = qc->curbytes = 0; 3367 qc->nbytes = qc->curbytes = 0;
3156 3368
3157 ata_tf_init(ap, &qc->tf, dev->devno); 3369 ata_tf_init(ap, &qc->tf, dev->devno);
3158
3159 if (dev->flags & ATA_DFLAG_LBA48)
3160 qc->tf.flags |= ATA_TFLAG_LBA48;
3161 } 3370 }
3162 3371
3163 return qc; 3372 return qc;
3164} 3373}
3165 3374
3166static int ata_qc_complete_noop(struct ata_queued_cmd *qc, u8 drv_stat) 3375int ata_qc_complete_noop(struct ata_queued_cmd *qc, unsigned int err_mask)
3167{ 3376{
3168 return 0; 3377 return 0;
3169} 3378}
@@ -3201,7 +3410,6 @@ static void __ata_qc_complete(struct ata_queued_cmd *qc)
3201 * 3410 *
3202 * LOCKING: 3411 * LOCKING:
3203 * spin_lock_irqsave(host_set lock) 3412 * spin_lock_irqsave(host_set lock)
3204 *
3205 */ 3413 */
3206void ata_qc_free(struct ata_queued_cmd *qc) 3414void ata_qc_free(struct ata_queued_cmd *qc)
3207{ 3415{
@@ -3221,10 +3429,9 @@ void ata_qc_free(struct ata_queued_cmd *qc)
3221 * 3429 *
3222 * LOCKING: 3430 * LOCKING:
3223 * spin_lock_irqsave(host_set lock) 3431 * spin_lock_irqsave(host_set lock)
3224 *
3225 */ 3432 */
3226 3433
3227void ata_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) 3434void ata_qc_complete(struct ata_queued_cmd *qc, unsigned int err_mask)
3228{ 3435{
3229 int rc; 3436 int rc;
3230 3437
@@ -3241,7 +3448,7 @@ void ata_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat)
3241 qc->flags &= ~ATA_QCFLAG_ACTIVE; 3448 qc->flags &= ~ATA_QCFLAG_ACTIVE;
3242 3449
3243 /* call completion callback */ 3450 /* call completion callback */
3244 rc = qc->complete_fn(qc, drv_stat); 3451 rc = qc->complete_fn(qc, err_mask);
3245 3452
3246 /* if callback indicates not to complete command (non-zero), 3453 /* if callback indicates not to complete command (non-zero),
3247 * return immediately 3454 * return immediately
@@ -3360,7 +3567,7 @@ int ata_qc_issue_prot(struct ata_queued_cmd *qc)
3360 case ATA_PROT_PIO: /* load tf registers, initiate polling pio */ 3567 case ATA_PROT_PIO: /* load tf registers, initiate polling pio */
3361 ata_qc_set_polling(qc); 3568 ata_qc_set_polling(qc);
3362 ata_tf_to_host_nolock(ap, &qc->tf); 3569 ata_tf_to_host_nolock(ap, &qc->tf);
3363 ap->pio_task_state = PIO_ST; 3570 ap->hsm_task_state = HSM_ST;
3364 queue_work(ata_wq, &ap->pio_task); 3571 queue_work(ata_wq, &ap->pio_task);
3365 break; 3572 break;
3366 3573
@@ -3586,7 +3793,7 @@ u8 ata_bmdma_status(struct ata_port *ap)
3586 void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr; 3793 void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr;
3587 host_stat = readb(mmio + ATA_DMA_STATUS); 3794 host_stat = readb(mmio + ATA_DMA_STATUS);
3588 } else 3795 } else
3589 host_stat = inb(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS); 3796 host_stat = inb(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
3590 return host_stat; 3797 return host_stat;
3591} 3798}
3592 3799
@@ -3679,7 +3886,7 @@ inline unsigned int ata_host_intr (struct ata_port *ap,
3679 ap->ops->irq_clear(ap); 3886 ap->ops->irq_clear(ap);
3680 3887
3681 /* complete taskfile transaction */ 3888 /* complete taskfile transaction */
3682 ata_qc_complete(qc, status); 3889 ata_qc_complete(qc, ac_err_mask(status));
3683 break; 3890 break;
3684 3891
3685 default: 3892 default:
@@ -3715,7 +3922,6 @@ idle_irq:
3715 * 3922 *
3716 * RETURNS: 3923 * RETURNS:
3717 * IRQ_NONE or IRQ_HANDLED. 3924 * IRQ_NONE or IRQ_HANDLED.
3718 *
3719 */ 3925 */
3720 3926
3721irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs) 3927irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs)
@@ -3775,7 +3981,7 @@ static void atapi_packet_task(void *_data)
3775 /* sleep-wait for BSY to clear */ 3981 /* sleep-wait for BSY to clear */
3776 DPRINTK("busy wait\n"); 3982 DPRINTK("busy wait\n");
3777 if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB)) 3983 if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB))
3778 goto err_out; 3984 goto err_out_status;
3779 3985
3780 /* make sure DRQ is set */ 3986 /* make sure DRQ is set */
3781 status = ata_chk_status(ap); 3987 status = ata_chk_status(ap);
@@ -3806,14 +4012,16 @@ static void atapi_packet_task(void *_data)
3806 ata_data_xfer(ap, qc->cdb, ap->cdb_len, 1); 4012 ata_data_xfer(ap, qc->cdb, ap->cdb_len, 1);
3807 4013
3808 /* PIO commands are handled by polling */ 4014 /* PIO commands are handled by polling */
3809 ap->pio_task_state = PIO_ST; 4015 ap->hsm_task_state = HSM_ST;
3810 queue_work(ata_wq, &ap->pio_task); 4016 queue_work(ata_wq, &ap->pio_task);
3811 } 4017 }
3812 4018
3813 return; 4019 return;
3814 4020
4021err_out_status:
4022 status = ata_chk_status(ap);
3815err_out: 4023err_out:
3816 ata_poll_qc_complete(qc, ATA_ERR); 4024 ata_poll_qc_complete(qc, __ac_err_mask(status));
3817} 4025}
3818 4026
3819 4027
@@ -3827,6 +4035,7 @@ err_out:
3827 * May be used as the port_start() entry in ata_port_operations. 4035 * May be used as the port_start() entry in ata_port_operations.
3828 * 4036 *
3829 * LOCKING: 4037 * LOCKING:
4038 * Inherited from caller.
3830 */ 4039 */
3831 4040
3832int ata_port_start (struct ata_port *ap) 4041int ata_port_start (struct ata_port *ap)
@@ -3852,6 +4061,7 @@ int ata_port_start (struct ata_port *ap)
3852 * May be used as the port_stop() entry in ata_port_operations. 4061 * May be used as the port_stop() entry in ata_port_operations.
3853 * 4062 *
3854 * LOCKING: 4063 * LOCKING:
4064 * Inherited from caller.
3855 */ 4065 */
3856 4066
3857void ata_port_stop (struct ata_port *ap) 4067void ata_port_stop (struct ata_port *ap)
@@ -3874,6 +4084,7 @@ void ata_host_stop (struct ata_host_set *host_set)
3874 * @do_unregister: 1 if we fully unregister, 0 to just stop the port 4084 * @do_unregister: 1 if we fully unregister, 0 to just stop the port
3875 * 4085 *
3876 * LOCKING: 4086 * LOCKING:
4087 * Inherited from caller.
3877 */ 4088 */
3878 4089
3879static void ata_host_remove(struct ata_port *ap, unsigned int do_unregister) 4090static void ata_host_remove(struct ata_port *ap, unsigned int do_unregister)
@@ -3901,12 +4112,11 @@ static void ata_host_remove(struct ata_port *ap, unsigned int do_unregister)
3901 * 4112 *
3902 * LOCKING: 4113 * LOCKING:
3903 * Inherited from caller. 4114 * Inherited from caller.
3904 *
3905 */ 4115 */
3906 4116
3907static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host, 4117static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host,
3908 struct ata_host_set *host_set, 4118 struct ata_host_set *host_set,
3909 struct ata_probe_ent *ent, unsigned int port_no) 4119 const struct ata_probe_ent *ent, unsigned int port_no)
3910{ 4120{
3911 unsigned int i; 4121 unsigned int i;
3912 4122
@@ -3962,10 +4172,9 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host,
3962 * 4172 *
3963 * RETURNS: 4173 * RETURNS:
3964 * New ata_port on success, for NULL on error. 4174 * New ata_port on success, for NULL on error.
3965 *
3966 */ 4175 */
3967 4176
3968static struct ata_port * ata_host_add(struct ata_probe_ent *ent, 4177static struct ata_port * ata_host_add(const struct ata_probe_ent *ent,
3969 struct ata_host_set *host_set, 4178 struct ata_host_set *host_set,
3970 unsigned int port_no) 4179 unsigned int port_no)
3971{ 4180{
@@ -4010,10 +4219,9 @@ err_out:
4010 * 4219 *
4011 * RETURNS: 4220 * RETURNS:
4012 * Number of ports registered. Zero on error (no ports registered). 4221 * Number of ports registered. Zero on error (no ports registered).
4013 *
4014 */ 4222 */
4015 4223
4016int ata_device_add(struct ata_probe_ent *ent) 4224int ata_device_add(const struct ata_probe_ent *ent)
4017{ 4225{
4018 unsigned int count = 0, i; 4226 unsigned int count = 0, i;
4019 struct device *dev = ent->dev; 4227 struct device *dev = ent->dev;
@@ -4021,11 +4229,10 @@ int ata_device_add(struct ata_probe_ent *ent)
4021 4229
4022 DPRINTK("ENTER\n"); 4230 DPRINTK("ENTER\n");
4023 /* alloc a container for our list of ATA ports (buses) */ 4231 /* alloc a container for our list of ATA ports (buses) */
4024 host_set = kmalloc(sizeof(struct ata_host_set) + 4232 host_set = kzalloc(sizeof(struct ata_host_set) +
4025 (ent->n_ports * sizeof(void *)), GFP_KERNEL); 4233 (ent->n_ports * sizeof(void *)), GFP_KERNEL);
4026 if (!host_set) 4234 if (!host_set)
4027 return 0; 4235 return 0;
4028 memset(host_set, 0, sizeof(struct ata_host_set) + (ent->n_ports * sizeof(void *)));
4029 spin_lock_init(&host_set->lock); 4236 spin_lock_init(&host_set->lock);
4030 4237
4031 host_set->dev = dev; 4238 host_set->dev = dev;
@@ -4065,10 +4272,8 @@ int ata_device_add(struct ata_probe_ent *ent)
4065 count++; 4272 count++;
4066 } 4273 }
4067 4274
4068 if (!count) { 4275 if (!count)
4069 kfree(host_set); 4276 goto err_free_ret;
4070 return 0;
4071 }
4072 4277
4073 /* obtain irq, that is shared between channels */ 4278 /* obtain irq, that is shared between channels */
4074 if (request_irq(ent->irq, ent->port_ops->irq_handler, ent->irq_flags, 4279 if (request_irq(ent->irq, ent->port_ops->irq_handler, ent->irq_flags,
@@ -4113,7 +4318,7 @@ int ata_device_add(struct ata_probe_ent *ent)
4113 for (i = 0; i < count; i++) { 4318 for (i = 0; i < count; i++) {
4114 struct ata_port *ap = host_set->ports[i]; 4319 struct ata_port *ap = host_set->ports[i];
4115 4320
4116 scsi_scan_host(ap->host); 4321 ata_scsi_scan_host(ap);
4117 } 4322 }
4118 4323
4119 dev_set_drvdata(dev, host_set); 4324 dev_set_drvdata(dev, host_set);
@@ -4126,6 +4331,7 @@ err_out:
4126 ata_host_remove(host_set->ports[i], 1); 4331 ata_host_remove(host_set->ports[i], 1);
4127 scsi_host_put(host_set->ports[i]->host); 4332 scsi_host_put(host_set->ports[i]->host);
4128 } 4333 }
4334err_free_ret:
4129 kfree(host_set); 4335 kfree(host_set);
4130 VPRINTK("EXIT, returning 0\n"); 4336 VPRINTK("EXIT, returning 0\n");
4131 return 0; 4337 return 0;
@@ -4142,7 +4348,6 @@ err_out:
4142 * Inherited from calling layer (may sleep). 4348 * Inherited from calling layer (may sleep).
4143 */ 4349 */
4144 4350
4145
4146void ata_host_set_remove(struct ata_host_set *host_set) 4351void ata_host_set_remove(struct ata_host_set *host_set)
4147{ 4352{
4148 struct ata_port *ap; 4353 struct ata_port *ap;
@@ -4232,19 +4437,17 @@ void ata_std_ports(struct ata_ioports *ioaddr)
4232} 4437}
4233 4438
4234static struct ata_probe_ent * 4439static struct ata_probe_ent *
4235ata_probe_ent_alloc(struct device *dev, struct ata_port_info *port) 4440ata_probe_ent_alloc(struct device *dev, const struct ata_port_info *port)
4236{ 4441{
4237 struct ata_probe_ent *probe_ent; 4442 struct ata_probe_ent *probe_ent;
4238 4443
4239 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL); 4444 probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL);
4240 if (!probe_ent) { 4445 if (!probe_ent) {
4241 printk(KERN_ERR DRV_NAME "(%s): out of memory\n", 4446 printk(KERN_ERR DRV_NAME "(%s): out of memory\n",
4242 kobject_name(&(dev->kobj))); 4447 kobject_name(&(dev->kobj)));
4243 return NULL; 4448 return NULL;
4244 } 4449 }
4245 4450
4246 memset(probe_ent, 0, sizeof(*probe_ent));
4247
4248 INIT_LIST_HEAD(&probe_ent->node); 4451 INIT_LIST_HEAD(&probe_ent->node);
4249 probe_ent->dev = dev; 4452 probe_ent->dev = dev;
4250 4453
@@ -4273,85 +4476,86 @@ void ata_pci_host_stop (struct ata_host_set *host_set)
4273 * ata_pci_init_native_mode - Initialize native-mode driver 4476 * ata_pci_init_native_mode - Initialize native-mode driver
4274 * @pdev: pci device to be initialized 4477 * @pdev: pci device to be initialized
4275 * @port: array[2] of pointers to port info structures. 4478 * @port: array[2] of pointers to port info structures.
4479 * @ports: bitmap of ports present
4276 * 4480 *
4277 * Utility function which allocates and initializes an 4481 * Utility function which allocates and initializes an
4278 * ata_probe_ent structure for a standard dual-port 4482 * ata_probe_ent structure for a standard dual-port
4279 * PIO-based IDE controller. The returned ata_probe_ent 4483 * PIO-based IDE controller. The returned ata_probe_ent
4280 * structure can be passed to ata_device_add(). The returned 4484 * structure can be passed to ata_device_add(). The returned
4281 * ata_probe_ent structure should then be freed with kfree(). 4485 * ata_probe_ent structure should then be freed with kfree().
4486 *
4487 * The caller need only pass the address of the primary port, the
4488 * secondary will be deduced automatically. If the device has non
4489 * standard secondary port mappings this function can be called twice,
4490 * once for each interface.
4282 */ 4491 */
4283 4492
4284struct ata_probe_ent * 4493struct ata_probe_ent *
4285ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port) 4494ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int ports)
4286{ 4495{
4287 struct ata_probe_ent *probe_ent = 4496 struct ata_probe_ent *probe_ent =
4288 ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]); 4497 ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]);
4498 int p = 0;
4499
4289 if (!probe_ent) 4500 if (!probe_ent)
4290 return NULL; 4501 return NULL;
4291 4502
4292 probe_ent->n_ports = 2;
4293 probe_ent->irq = pdev->irq; 4503 probe_ent->irq = pdev->irq;
4294 probe_ent->irq_flags = SA_SHIRQ; 4504 probe_ent->irq_flags = SA_SHIRQ;
4295 4505
4296 probe_ent->port[0].cmd_addr = pci_resource_start(pdev, 0); 4506 if (ports & ATA_PORT_PRIMARY) {
4297 probe_ent->port[0].altstatus_addr = 4507 probe_ent->port[p].cmd_addr = pci_resource_start(pdev, 0);
4298 probe_ent->port[0].ctl_addr = 4508 probe_ent->port[p].altstatus_addr =
4299 pci_resource_start(pdev, 1) | ATA_PCI_CTL_OFS; 4509 probe_ent->port[p].ctl_addr =
4300 probe_ent->port[0].bmdma_addr = pci_resource_start(pdev, 4); 4510 pci_resource_start(pdev, 1) | ATA_PCI_CTL_OFS;
4301 4511 probe_ent->port[p].bmdma_addr = pci_resource_start(pdev, 4);
4302 probe_ent->port[1].cmd_addr = pci_resource_start(pdev, 2); 4512 ata_std_ports(&probe_ent->port[p]);
4303 probe_ent->port[1].altstatus_addr = 4513 p++;
4304 probe_ent->port[1].ctl_addr = 4514 }
4305 pci_resource_start(pdev, 3) | ATA_PCI_CTL_OFS;
4306 probe_ent->port[1].bmdma_addr = pci_resource_start(pdev, 4) + 8;
4307 4515
4308 ata_std_ports(&probe_ent->port[0]); 4516 if (ports & ATA_PORT_SECONDARY) {
4309 ata_std_ports(&probe_ent->port[1]); 4517 probe_ent->port[p].cmd_addr = pci_resource_start(pdev, 2);
4518 probe_ent->port[p].altstatus_addr =
4519 probe_ent->port[p].ctl_addr =
4520 pci_resource_start(pdev, 3) | ATA_PCI_CTL_OFS;
4521 probe_ent->port[p].bmdma_addr = pci_resource_start(pdev, 4) + 8;
4522 ata_std_ports(&probe_ent->port[p]);
4523 p++;
4524 }
4310 4525
4526 probe_ent->n_ports = p;
4311 return probe_ent; 4527 return probe_ent;
4312} 4528}
4313 4529
4314static struct ata_probe_ent * 4530static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev, struct ata_port_info *port, int port_num)
4315ata_pci_init_legacy_mode(struct pci_dev *pdev, struct ata_port_info **port,
4316 struct ata_probe_ent **ppe2)
4317{ 4531{
4318 struct ata_probe_ent *probe_ent, *probe_ent2; 4532 struct ata_probe_ent *probe_ent;
4319 4533
4320 probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]); 4534 probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port);
4321 if (!probe_ent) 4535 if (!probe_ent)
4322 return NULL; 4536 return NULL;
4323 probe_ent2 = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[1]);
4324 if (!probe_ent2) {
4325 kfree(probe_ent);
4326 return NULL;
4327 }
4328
4329 probe_ent->n_ports = 1;
4330 probe_ent->irq = 14;
4331 4537
4332 probe_ent->hard_port_no = 0;
4333 probe_ent->legacy_mode = 1; 4538 probe_ent->legacy_mode = 1;
4334 4539 probe_ent->n_ports = 1;
4335 probe_ent2->n_ports = 1; 4540 probe_ent->hard_port_no = port_num;
4336 probe_ent2->irq = 15; 4541
4337 4542 switch(port_num)
4338 probe_ent2->hard_port_no = 1; 4543 {
4339 probe_ent2->legacy_mode = 1; 4544 case 0:
4340 4545 probe_ent->irq = 14;
4341 probe_ent->port[0].cmd_addr = 0x1f0; 4546 probe_ent->port[0].cmd_addr = 0x1f0;
4342 probe_ent->port[0].altstatus_addr = 4547 probe_ent->port[0].altstatus_addr =
4343 probe_ent->port[0].ctl_addr = 0x3f6; 4548 probe_ent->port[0].ctl_addr = 0x3f6;
4344 probe_ent->port[0].bmdma_addr = pci_resource_start(pdev, 4); 4549 break;
4345 4550 case 1:
4346 probe_ent2->port[0].cmd_addr = 0x170; 4551 probe_ent->irq = 15;
4347 probe_ent2->port[0].altstatus_addr = 4552 probe_ent->port[0].cmd_addr = 0x170;
4348 probe_ent2->port[0].ctl_addr = 0x376; 4553 probe_ent->port[0].altstatus_addr =
4349 probe_ent2->port[0].bmdma_addr = pci_resource_start(pdev, 4)+8; 4554 probe_ent->port[0].ctl_addr = 0x376;
4350 4555 break;
4556 }
4557 probe_ent->port[0].bmdma_addr = pci_resource_start(pdev, 4) + 8 * port_num;
4351 ata_std_ports(&probe_ent->port[0]); 4558 ata_std_ports(&probe_ent->port[0]);
4352 ata_std_ports(&probe_ent2->port[0]);
4353
4354 *ppe2 = probe_ent2;
4355 return probe_ent; 4559 return probe_ent;
4356} 4560}
4357 4561
@@ -4374,13 +4578,12 @@ ata_pci_init_legacy_mode(struct pci_dev *pdev, struct ata_port_info **port,
4374 * 4578 *
4375 * RETURNS: 4579 * RETURNS:
4376 * Zero on success, negative on errno-based value on error. 4580 * Zero on success, negative on errno-based value on error.
4377 *
4378 */ 4581 */
4379 4582
4380int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info, 4583int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
4381 unsigned int n_ports) 4584 unsigned int n_ports)
4382{ 4585{
4383 struct ata_probe_ent *probe_ent, *probe_ent2 = NULL; 4586 struct ata_probe_ent *probe_ent = NULL, *probe_ent2 = NULL;
4384 struct ata_port_info *port[2]; 4587 struct ata_port_info *port[2];
4385 u8 tmp8, mask; 4588 u8 tmp8, mask;
4386 unsigned int legacy_mode = 0; 4589 unsigned int legacy_mode = 0;
@@ -4397,7 +4600,7 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
4397 4600
4398 if ((port[0]->host_flags & ATA_FLAG_NO_LEGACY) == 0 4601 if ((port[0]->host_flags & ATA_FLAG_NO_LEGACY) == 0
4399 && (pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) { 4602 && (pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) {
4400 /* TODO: support transitioning to native mode? */ 4603 /* TODO: What if one channel is in native mode ... */
4401 pci_read_config_byte(pdev, PCI_CLASS_PROG, &tmp8); 4604 pci_read_config_byte(pdev, PCI_CLASS_PROG, &tmp8);
4402 mask = (1 << 2) | (1 << 0); 4605 mask = (1 << 2) | (1 << 0);
4403 if ((tmp8 & mask) != mask) 4606 if ((tmp8 & mask) != mask)
@@ -4405,11 +4608,20 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
4405 } 4608 }
4406 4609
4407 /* FIXME... */ 4610 /* FIXME... */
4408 if ((!legacy_mode) && (n_ports > 1)) { 4611 if ((!legacy_mode) && (n_ports > 2)) {
4409 printk(KERN_ERR "ata: BUG: native mode, n_ports > 1\n"); 4612 printk(KERN_ERR "ata: BUG: native mode, n_ports > 2\n");
4410 return -EINVAL; 4613 n_ports = 2;
4614 /* For now */
4411 } 4615 }
4412 4616
4617 /* FIXME: Really for ATA it isn't safe because the device may be
4618 multi-purpose and we want to leave it alone if it was already
4619 enabled. Secondly for shared use as Arjan says we want refcounting
4620
4621 Checking dev->is_enabled is insufficient as this is not set at
4622 boot for the primary video which is BIOS enabled
4623 */
4624
4413 rc = pci_enable_device(pdev); 4625 rc = pci_enable_device(pdev);
4414 if (rc) 4626 if (rc)
4415 return rc; 4627 return rc;
@@ -4420,6 +4632,7 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
4420 goto err_out; 4632 goto err_out;
4421 } 4633 }
4422 4634
4635 /* FIXME: Should use platform specific mappers for legacy port ranges */
4423 if (legacy_mode) { 4636 if (legacy_mode) {
4424 if (!request_region(0x1f0, 8, "libata")) { 4637 if (!request_region(0x1f0, 8, "libata")) {
4425 struct resource *conflict, res; 4638 struct resource *conflict, res;
@@ -4464,10 +4677,17 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
4464 goto err_out_regions; 4677 goto err_out_regions;
4465 4678
4466 if (legacy_mode) { 4679 if (legacy_mode) {
4467 probe_ent = ata_pci_init_legacy_mode(pdev, port, &probe_ent2); 4680 if (legacy_mode & (1 << 0))
4468 } else 4681 probe_ent = ata_pci_init_legacy_port(pdev, port[0], 0);
4469 probe_ent = ata_pci_init_native_mode(pdev, port); 4682 if (legacy_mode & (1 << 1))
4470 if (!probe_ent) { 4683 probe_ent2 = ata_pci_init_legacy_port(pdev, port[1], 1);
4684 } else {
4685 if (n_ports == 2)
4686 probe_ent = ata_pci_init_native_mode(pdev, port, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
4687 else
4688 probe_ent = ata_pci_init_native_mode(pdev, port, ATA_PORT_PRIMARY);
4689 }
4690 if (!probe_ent && !probe_ent2) {
4471 rc = -ENOMEM; 4691 rc = -ENOMEM;
4472 goto err_out_regions; 4692 goto err_out_regions;
4473 } 4693 }
@@ -4505,7 +4725,7 @@ err_out:
4505 * @pdev: PCI device that was removed 4725 * @pdev: PCI device that was removed
4506 * 4726 *
4507 * PCI layer indicates to libata via this hook that 4727 * PCI layer indicates to libata via this hook that
4508 * hot-unplug or module unload event has occured. 4728 * hot-unplug or module unload event has occurred.
4509 * Handle this by unregistering all objects associated 4729 * Handle this by unregistering all objects associated
4510 * with this PCI device. Free those objects. Then finally 4730 * with this PCI device. Free those objects. Then finally
4511 * release PCI resources and disable device. 4731 * release PCI resources and disable device.
@@ -4526,7 +4746,7 @@ void ata_pci_remove_one (struct pci_dev *pdev)
4526} 4746}
4527 4747
4528/* move to PCI subsystem */ 4748/* move to PCI subsystem */
4529int pci_test_config_bits(struct pci_dev *pdev, struct pci_bits *bits) 4749int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits)
4530{ 4750{
4531 unsigned long tmp = 0; 4751 unsigned long tmp = 0;
4532 4752
@@ -4579,6 +4799,27 @@ static void __exit ata_exit(void)
4579module_init(ata_init); 4799module_init(ata_init);
4580module_exit(ata_exit); 4800module_exit(ata_exit);
4581 4801
4802static unsigned long ratelimit_time;
4803static spinlock_t ata_ratelimit_lock = SPIN_LOCK_UNLOCKED;
4804
4805int ata_ratelimit(void)
4806{
4807 int rc;
4808 unsigned long flags;
4809
4810 spin_lock_irqsave(&ata_ratelimit_lock, flags);
4811
4812 if (time_after(jiffies, ratelimit_time)) {
4813 rc = 1;
4814 ratelimit_time = jiffies + (HZ/5);
4815 } else
4816 rc = 0;
4817
4818 spin_unlock_irqrestore(&ata_ratelimit_lock, flags);
4819
4820 return rc;
4821}
4822
4582/* 4823/*
4583 * libata is essentially a library of internal helper functions for 4824 * libata is essentially a library of internal helper functions for
4584 * low-level ATA host controller drivers. As such, the API/ABI is 4825 * low-level ATA host controller drivers. As such, the API/ABI is
@@ -4603,7 +4844,6 @@ EXPORT_SYMBOL_GPL(ata_tf_to_fis);
4603EXPORT_SYMBOL_GPL(ata_tf_from_fis); 4844EXPORT_SYMBOL_GPL(ata_tf_from_fis);
4604EXPORT_SYMBOL_GPL(ata_check_status); 4845EXPORT_SYMBOL_GPL(ata_check_status);
4605EXPORT_SYMBOL_GPL(ata_altstatus); 4846EXPORT_SYMBOL_GPL(ata_altstatus);
4606EXPORT_SYMBOL_GPL(ata_chk_err);
4607EXPORT_SYMBOL_GPL(ata_exec_command); 4847EXPORT_SYMBOL_GPL(ata_exec_command);
4608EXPORT_SYMBOL_GPL(ata_port_start); 4848EXPORT_SYMBOL_GPL(ata_port_start);
4609EXPORT_SYMBOL_GPL(ata_port_stop); 4849EXPORT_SYMBOL_GPL(ata_port_stop);
@@ -4620,6 +4860,7 @@ EXPORT_SYMBOL_GPL(sata_phy_reset);
4620EXPORT_SYMBOL_GPL(__sata_phy_reset); 4860EXPORT_SYMBOL_GPL(__sata_phy_reset);
4621EXPORT_SYMBOL_GPL(ata_bus_reset); 4861EXPORT_SYMBOL_GPL(ata_bus_reset);
4622EXPORT_SYMBOL_GPL(ata_port_disable); 4862EXPORT_SYMBOL_GPL(ata_port_disable);
4863EXPORT_SYMBOL_GPL(ata_ratelimit);
4623EXPORT_SYMBOL_GPL(ata_scsi_ioctl); 4864EXPORT_SYMBOL_GPL(ata_scsi_ioctl);
4624EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); 4865EXPORT_SYMBOL_GPL(ata_scsi_queuecmd);
4625EXPORT_SYMBOL_GPL(ata_scsi_error); 4866EXPORT_SYMBOL_GPL(ata_scsi_error);
@@ -4631,6 +4872,9 @@ EXPORT_SYMBOL_GPL(ata_dev_id_string);
4631EXPORT_SYMBOL_GPL(ata_dev_config); 4872EXPORT_SYMBOL_GPL(ata_dev_config);
4632EXPORT_SYMBOL_GPL(ata_scsi_simulate); 4873EXPORT_SYMBOL_GPL(ata_scsi_simulate);
4633 4874
4875EXPORT_SYMBOL_GPL(ata_timing_compute);
4876EXPORT_SYMBOL_GPL(ata_timing_merge);
4877
4634#ifdef CONFIG_PCI 4878#ifdef CONFIG_PCI
4635EXPORT_SYMBOL_GPL(pci_test_config_bits); 4879EXPORT_SYMBOL_GPL(pci_test_config_bits);
4636EXPORT_SYMBOL_GPL(ata_pci_host_stop); 4880EXPORT_SYMBOL_GPL(ata_pci_host_stop);
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index 104fd9a63e73..1e3792f86fcf 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -40,14 +40,64 @@
40#include "scsi.h" 40#include "scsi.h"
41#include <scsi/scsi_host.h> 41#include <scsi/scsi_host.h>
42#include <linux/libata.h> 42#include <linux/libata.h>
43#include <linux/hdreg.h>
43#include <asm/uaccess.h> 44#include <asm/uaccess.h>
44 45
45#include "libata.h" 46#include "libata.h"
46 47
47typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc, u8 *scsicmd); 48#define SECTOR_SIZE 512
48static struct ata_device *
49ata_scsi_find_dev(struct ata_port *ap, struct scsi_device *scsidev);
50 49
50typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc, const u8 *scsicmd);
51static struct ata_device *
52ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev);
53
54#define RW_RECOVERY_MPAGE 0x1
55#define RW_RECOVERY_MPAGE_LEN 12
56#define CACHE_MPAGE 0x8
57#define CACHE_MPAGE_LEN 20
58#define CONTROL_MPAGE 0xa
59#define CONTROL_MPAGE_LEN 12
60#define ALL_MPAGES 0x3f
61#define ALL_SUB_MPAGES 0xff
62
63
64static const u8 def_rw_recovery_mpage[] = {
65 RW_RECOVERY_MPAGE,
66 RW_RECOVERY_MPAGE_LEN - 2,
67 (1 << 7) | /* AWRE, sat-r06 say it shall be 0 */
68 (1 << 6), /* ARRE (auto read reallocation) */
69 0, /* read retry count */
70 0, 0, 0, 0,
71 0, /* write retry count */
72 0, 0, 0
73};
74
75static const u8 def_cache_mpage[CACHE_MPAGE_LEN] = {
76 CACHE_MPAGE,
77 CACHE_MPAGE_LEN - 2,
78 0, /* contains WCE, needs to be 0 for logic */
79 0, 0, 0, 0, 0, 0, 0, 0, 0,
80 0, /* contains DRA, needs to be 0 for logic */
81 0, 0, 0, 0, 0, 0, 0
82};
83
84static const u8 def_control_mpage[CONTROL_MPAGE_LEN] = {
85 CONTROL_MPAGE,
86 CONTROL_MPAGE_LEN - 2,
87 2, /* DSENSE=0, GLTSD=1 */
88 0, /* [QAM+QERR may be 1, see 05-359r1] */
89 0, 0, 0, 0, 0xff, 0xff,
90 0, 30 /* extended self test time, see 05-359r1 */
91};
92
93
94static void ata_scsi_invalid_field(struct scsi_cmnd *cmd,
95 void (*done)(struct scsi_cmnd *))
96{
97 ata_scsi_set_sense(cmd, ILLEGAL_REQUEST, 0x24, 0x0);
98 /* "Invalid field in cbd" */
99 done(cmd);
100}
51 101
52/** 102/**
53 * ata_std_bios_param - generic bios head/sector/cylinder calculator used by sd. 103 * ata_std_bios_param - generic bios head/sector/cylinder calculator used by sd.
@@ -78,6 +128,150 @@ int ata_std_bios_param(struct scsi_device *sdev, struct block_device *bdev,
78 return 0; 128 return 0;
79} 129}
80 130
131/**
132 * ata_cmd_ioctl - Handler for HDIO_DRIVE_CMD ioctl
133 * @dev: Device to whom we are issuing command
134 * @arg: User provided data for issuing command
135 *
136 * LOCKING:
137 * Defined by the SCSI layer. We don't really care.
138 *
139 * RETURNS:
140 * Zero on success, negative errno on error.
141 */
142
143int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg)
144{
145 int rc = 0;
146 u8 scsi_cmd[MAX_COMMAND_SIZE];
147 u8 args[4], *argbuf = NULL;
148 int argsize = 0;
149 struct scsi_request *sreq;
150
151 if (NULL == (void *)arg)
152 return -EINVAL;
153
154 if (copy_from_user(args, arg, sizeof(args)))
155 return -EFAULT;
156
157 sreq = scsi_allocate_request(scsidev, GFP_KERNEL);
158 if (!sreq)
159 return -EINTR;
160
161 memset(scsi_cmd, 0, sizeof(scsi_cmd));
162
163 if (args[3]) {
164 argsize = SECTOR_SIZE * args[3];
165 argbuf = kmalloc(argsize, GFP_KERNEL);
166 if (argbuf == NULL) {
167 rc = -ENOMEM;
168 goto error;
169 }
170
171 scsi_cmd[1] = (4 << 1); /* PIO Data-in */
172 scsi_cmd[2] = 0x0e; /* no off.line or cc, read from dev,
173 block count in sector count field */
174 sreq->sr_data_direction = DMA_FROM_DEVICE;
175 } else {
176 scsi_cmd[1] = (3 << 1); /* Non-data */
177 /* scsi_cmd[2] is already 0 -- no off.line, cc, or data xfer */
178 sreq->sr_data_direction = DMA_NONE;
179 }
180
181 scsi_cmd[0] = ATA_16;
182
183 scsi_cmd[4] = args[2];
184 if (args[0] == WIN_SMART) { /* hack -- ide driver does this too... */
185 scsi_cmd[6] = args[3];
186 scsi_cmd[8] = args[1];
187 scsi_cmd[10] = 0x4f;
188 scsi_cmd[12] = 0xc2;
189 } else {
190 scsi_cmd[6] = args[1];
191 }
192 scsi_cmd[14] = args[0];
193
194 /* Good values for timeout and retries? Values below
195 from scsi_ioctl_send_command() for default case... */
196 scsi_wait_req(sreq, scsi_cmd, argbuf, argsize, (10*HZ), 5);
197
198 if (sreq->sr_result) {
199 rc = -EIO;
200 goto error;
201 }
202
203 /* Need code to retrieve data from check condition? */
204
205 if ((argbuf)
206 && copy_to_user((void *)(arg + sizeof(args)), argbuf, argsize))
207 rc = -EFAULT;
208error:
209 scsi_release_request(sreq);
210
211 if (argbuf)
212 kfree(argbuf);
213
214 return rc;
215}
216
217/**
218 * ata_task_ioctl - Handler for HDIO_DRIVE_TASK ioctl
219 * @dev: Device to whom we are issuing command
220 * @arg: User provided data for issuing command
221 *
222 * LOCKING:
223 * Defined by the SCSI layer. We don't really care.
224 *
225 * RETURNS:
226 * Zero on success, negative errno on error.
227 */
228int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
229{
230 int rc = 0;
231 u8 scsi_cmd[MAX_COMMAND_SIZE];
232 u8 args[7];
233 struct scsi_request *sreq;
234
235 if (NULL == (void *)arg)
236 return -EINVAL;
237
238 if (copy_from_user(args, arg, sizeof(args)))
239 return -EFAULT;
240
241 memset(scsi_cmd, 0, sizeof(scsi_cmd));
242 scsi_cmd[0] = ATA_16;
243 scsi_cmd[1] = (3 << 1); /* Non-data */
244 /* scsi_cmd[2] is already 0 -- no off.line, cc, or data xfer */
245 scsi_cmd[4] = args[1];
246 scsi_cmd[6] = args[2];
247 scsi_cmd[8] = args[3];
248 scsi_cmd[10] = args[4];
249 scsi_cmd[12] = args[5];
250 scsi_cmd[14] = args[0];
251
252 sreq = scsi_allocate_request(scsidev, GFP_KERNEL);
253 if (!sreq) {
254 rc = -EINTR;
255 goto error;
256 }
257
258 sreq->sr_data_direction = DMA_NONE;
259 /* Good values for timeout and retries? Values below
260 from scsi_ioctl_send_command() for default case... */
261 scsi_wait_req(sreq, scsi_cmd, NULL, 0, (10*HZ), 5);
262
263 if (sreq->sr_result) {
264 rc = -EIO;
265 goto error;
266 }
267
268 /* Need code to retrieve data from check condition? */
269
270error:
271 scsi_release_request(sreq);
272 return rc;
273}
274
81int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg) 275int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg)
82{ 276{
83 struct ata_port *ap; 277 struct ata_port *ap;
@@ -107,6 +301,16 @@ int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg)
107 return -EINVAL; 301 return -EINVAL;
108 return 0; 302 return 0;
109 303
304 case HDIO_DRIVE_CMD:
305 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
306 return -EACCES;
307 return ata_cmd_ioctl(scsidev, arg);
308
309 case HDIO_DRIVE_TASK:
310 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
311 return -EACCES;
312 return ata_task_ioctl(scsidev, arg);
313
110 default: 314 default:
111 rc = -ENOTTY; 315 rc = -ENOTTY;
112 break; 316 break;
@@ -165,24 +369,70 @@ struct ata_queued_cmd *ata_scsi_qc_new(struct ata_port *ap,
165} 369}
166 370
167/** 371/**
372 * ata_dump_status - user friendly display of error info
373 * @id: id of the port in question
374 * @tf: ptr to filled out taskfile
375 *
376 * Decode and dump the ATA error/status registers for the user so
377 * that they have some idea what really happened at the non
378 * make-believe layer.
379 *
380 * LOCKING:
381 * inherited from caller
382 */
383void ata_dump_status(unsigned id, struct ata_taskfile *tf)
384{
385 u8 stat = tf->command, err = tf->feature;
386
387 printk(KERN_WARNING "ata%u: status=0x%02x { ", id, stat);
388 if (stat & ATA_BUSY) {
389 printk("Busy }\n"); /* Data is not valid in this case */
390 } else {
391 if (stat & 0x40) printk("DriveReady ");
392 if (stat & 0x20) printk("DeviceFault ");
393 if (stat & 0x10) printk("SeekComplete ");
394 if (stat & 0x08) printk("DataRequest ");
395 if (stat & 0x04) printk("CorrectedError ");
396 if (stat & 0x02) printk("Index ");
397 if (stat & 0x01) printk("Error ");
398 printk("}\n");
399
400 if (err) {
401 printk(KERN_WARNING "ata%u: error=0x%02x { ", id, err);
402 if (err & 0x04) printk("DriveStatusError ");
403 if (err & 0x80) {
404 if (err & 0x04) printk("BadCRC ");
405 else printk("Sector ");
406 }
407 if (err & 0x40) printk("UncorrectableError ");
408 if (err & 0x10) printk("SectorIdNotFound ");
409 if (err & 0x02) printk("TrackZeroNotFound ");
410 if (err & 0x01) printk("AddrMarkNotFound ");
411 printk("}\n");
412 }
413 }
414}
415
416/**
168 * ata_to_sense_error - convert ATA error to SCSI error 417 * ata_to_sense_error - convert ATA error to SCSI error
169 * @qc: Command that we are erroring out
170 * @drv_stat: value contained in ATA status register 418 * @drv_stat: value contained in ATA status register
419 * @drv_err: value contained in ATA error register
420 * @sk: the sense key we'll fill out
421 * @asc: the additional sense code we'll fill out
422 * @ascq: the additional sense code qualifier we'll fill out
171 * 423 *
172 * Converts an ATA error into a SCSI error. While we are at it 424 * Converts an ATA error into a SCSI error. Fill out pointers to
173 * we decode and dump the ATA error for the user so that they 425 * SK, ASC, and ASCQ bytes for later use in fixed or descriptor
174 * have some idea what really happened at the non make-believe 426 * format sense blocks.
175 * layer.
176 * 427 *
177 * LOCKING: 428 * LOCKING:
178 * spin_lock_irqsave(host_set lock) 429 * spin_lock_irqsave(host_set lock)
179 */ 430 */
180 431void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc,
181void ata_to_sense_error(struct ata_queued_cmd *qc, u8 drv_stat) 432 u8 *ascq)
182{ 433{
183 struct scsi_cmnd *cmd = qc->scsicmd; 434 int i;
184 u8 err = 0; 435
185 unsigned char *sb = cmd->sense_buffer;
186 /* Based on the 3ware driver translation table */ 436 /* Based on the 3ware driver translation table */
187 static unsigned char sense_table[][4] = { 437 static unsigned char sense_table[][4] = {
188 /* BBD|ECC|ID|MAR */ 438 /* BBD|ECC|ID|MAR */
@@ -223,105 +473,192 @@ void ata_to_sense_error(struct ata_queued_cmd *qc, u8 drv_stat)
223 {0x04, RECOVERED_ERROR, 0x11, 0x00}, // Recovered ECC error Medium error, recovered 473 {0x04, RECOVERED_ERROR, 0x11, 0x00}, // Recovered ECC error Medium error, recovered
224 {0xFF, 0xFF, 0xFF, 0xFF}, // END mark 474 {0xFF, 0xFF, 0xFF, 0xFF}, // END mark
225 }; 475 };
226 int i = 0;
227
228 cmd->result = SAM_STAT_CHECK_CONDITION;
229 476
230 /* 477 /*
231 * Is this an error we can process/parse 478 * Is this an error we can process/parse
232 */ 479 */
480 if (drv_stat & ATA_BUSY) {
481 drv_err = 0; /* Ignore the err bits, they're invalid */
482 }
483
484 if (drv_err) {
485 /* Look for drv_err */
486 for (i = 0; sense_table[i][0] != 0xFF; i++) {
487 /* Look for best matches first */
488 if ((sense_table[i][0] & drv_err) ==
489 sense_table[i][0]) {
490 *sk = sense_table[i][1];
491 *asc = sense_table[i][2];
492 *ascq = sense_table[i][3];
493 goto translate_done;
494 }
495 }
496 /* No immediate match */
497 printk(KERN_WARNING "ata%u: no sense translation for "
498 "error 0x%02x\n", id, drv_err);
499 }
500
501 /* Fall back to interpreting status bits */
502 for (i = 0; stat_table[i][0] != 0xFF; i++) {
503 if (stat_table[i][0] & drv_stat) {
504 *sk = stat_table[i][1];
505 *asc = stat_table[i][2];
506 *ascq = stat_table[i][3];
507 goto translate_done;
508 }
509 }
510 /* No error? Undecoded? */
511 printk(KERN_WARNING "ata%u: no sense translation for status: 0x%02x\n",
512 id, drv_stat);
513
514 /* For our last chance pick, use medium read error because
515 * it's much more common than an ATA drive telling you a write
516 * has failed.
517 */
518 *sk = MEDIUM_ERROR;
519 *asc = 0x11; /* "unrecovered read error" */
520 *ascq = 0x04; /* "auto-reallocation failed" */
521
522 translate_done:
523 printk(KERN_ERR "ata%u: translated ATA stat/err 0x%02x/%02x to "
524 "SCSI SK/ASC/ASCQ 0x%x/%02x/%02x\n", id, drv_stat, drv_err,
525 *sk, *asc, *ascq);
526 return;
527}
528
529/*
530 * ata_gen_ata_desc_sense - Generate check condition sense block.
531 * @qc: Command that completed.
532 *
533 * This function is specific to the ATA descriptor format sense
534 * block specified for the ATA pass through commands. Regardless
535 * of whether the command errored or not, return a sense
536 * block. Copy all controller registers into the sense
537 * block. Clear sense key, ASC & ASCQ if there is no error.
538 *
539 * LOCKING:
540 * spin_lock_irqsave(host_set lock)
541 */
542void ata_gen_ata_desc_sense(struct ata_queued_cmd *qc)
543{
544 struct scsi_cmnd *cmd = qc->scsicmd;
545 struct ata_taskfile *tf = &qc->tf;
546 unsigned char *sb = cmd->sense_buffer;
547 unsigned char *desc = sb + 8;
233 548
234 if(drv_stat & ATA_ERR) 549 memset(sb, 0, SCSI_SENSE_BUFFERSIZE);
235 /* Read the err bits */
236 err = ata_chk_err(qc->ap);
237 550
238 /* Display the ATA level error info */ 551 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
239 552
240 printk(KERN_WARNING "ata%u: status=0x%02x { ", qc->ap->id, drv_stat); 553 /*
241 if(drv_stat & 0x80) 554 * Read the controller registers.
242 { 555 */
243 printk("Busy "); 556 assert(NULL != qc->ap->ops->tf_read);
244 err = 0; /* Data is not valid in this case */ 557 qc->ap->ops->tf_read(qc->ap, tf);
558
559 /*
560 * Use ata_to_sense_error() to map status register bits
561 * onto sense key, asc & ascq.
562 */
563 if (tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) {
564 ata_to_sense_error(qc->ap->id, tf->command, tf->feature,
565 &sb[1], &sb[2], &sb[3]);
566 sb[1] &= 0x0f;
245 } 567 }
246 else { 568
247 if(drv_stat & 0x40) printk("DriveReady "); 569 /*
248 if(drv_stat & 0x20) printk("DeviceFault "); 570 * Sense data is current and format is descriptor.
249 if(drv_stat & 0x10) printk("SeekComplete "); 571 */
250 if(drv_stat & 0x08) printk("DataRequest "); 572 sb[0] = 0x72;
251 if(drv_stat & 0x04) printk("CorrectedError "); 573
252 if(drv_stat & 0x02) printk("Index "); 574 desc[0] = 0x09;
253 if(drv_stat & 0x01) printk("Error "); 575
576 /*
577 * Set length of additional sense data.
578 * Since we only populate descriptor 0, the total
579 * length is the same (fixed) length as descriptor 0.
580 */
581 desc[1] = sb[7] = 14;
582
583 /*
584 * Copy registers into sense buffer.
585 */
586 desc[2] = 0x00;
587 desc[3] = tf->feature; /* == error reg */
588 desc[5] = tf->nsect;
589 desc[7] = tf->lbal;
590 desc[9] = tf->lbam;
591 desc[11] = tf->lbah;
592 desc[12] = tf->device;
593 desc[13] = tf->command; /* == status reg */
594
595 /*
596 * Fill in Extend bit, and the high order bytes
597 * if applicable.
598 */
599 if (tf->flags & ATA_TFLAG_LBA48) {
600 desc[2] |= 0x01;
601 desc[4] = tf->hob_nsect;
602 desc[6] = tf->hob_lbal;
603 desc[8] = tf->hob_lbam;
604 desc[10] = tf->hob_lbah;
254 } 605 }
255 printk("}\n"); 606}
256
257 if(err)
258 {
259 printk(KERN_WARNING "ata%u: error=0x%02x { ", qc->ap->id, err);
260 if(err & 0x04) printk("DriveStatusError ");
261 if(err & 0x80)
262 {
263 if(err & 0x04)
264 printk("BadCRC ");
265 else
266 printk("Sector ");
267 }
268 if(err & 0x40) printk("UncorrectableError ");
269 if(err & 0x10) printk("SectorIdNotFound ");
270 if(err & 0x02) printk("TrackZeroNotFound ");
271 if(err & 0x01) printk("AddrMarkNotFound ");
272 printk("}\n");
273 607
274 /* Should we dump sector info here too ?? */ 608/**
609 * ata_gen_fixed_sense - generate a SCSI fixed sense block
610 * @qc: Command that we are erroring out
611 *
612 * Leverage ata_to_sense_error() to give us the codes. Fit our
613 * LBA in here if there's room.
614 *
615 * LOCKING:
616 * inherited from caller
617 */
618void ata_gen_fixed_sense(struct ata_queued_cmd *qc)
619{
620 struct scsi_cmnd *cmd = qc->scsicmd;
621 struct ata_taskfile *tf = &qc->tf;
622 unsigned char *sb = cmd->sense_buffer;
623
624 memset(sb, 0, SCSI_SENSE_BUFFERSIZE);
625
626 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
627
628 /*
629 * Read the controller registers.
630 */
631 assert(NULL != qc->ap->ops->tf_read);
632 qc->ap->ops->tf_read(qc->ap, tf);
633
634 /*
635 * Use ata_to_sense_error() to map status register bits
636 * onto sense key, asc & ascq.
637 */
638 if (tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) {
639 ata_to_sense_error(qc->ap->id, tf->command, tf->feature,
640 &sb[2], &sb[12], &sb[13]);
641 sb[2] &= 0x0f;
275 } 642 }
276 643
644 sb[0] = 0x70;
645 sb[7] = 0x0a;
277 646
278 /* Look for err */ 647 if (tf->flags & ATA_TFLAG_LBA48) {
279 while(sense_table[i][0] != 0xFF) 648 /* TODO: find solution for LBA48 descriptors */
280 {
281 /* Look for best matches first */
282 if((sense_table[i][0] & err) == sense_table[i][0])
283 {
284 sb[0] = 0x70;
285 sb[2] = sense_table[i][1];
286 sb[7] = 0x0a;
287 sb[12] = sense_table[i][2];
288 sb[13] = sense_table[i][3];
289 return;
290 }
291 i++;
292 } 649 }
293 /* No immediate match */
294 if(err)
295 printk(KERN_DEBUG "ata%u: no sense translation for 0x%02x\n", qc->ap->id, err);
296 650
297 i = 0; 651 else if (tf->flags & ATA_TFLAG_LBA) {
298 /* Fall back to interpreting status bits */ 652 /* A small (28b) LBA will fit in the 32b info field */
299 while(stat_table[i][0] != 0xFF) 653 sb[0] |= 0x80; /* set valid bit */
300 { 654 sb[3] = tf->device & 0x0f;
301 if(stat_table[i][0] & drv_stat) 655 sb[4] = tf->lbah;
302 { 656 sb[5] = tf->lbam;
303 sb[0] = 0x70; 657 sb[6] = tf->lbal;
304 sb[2] = stat_table[i][1];
305 sb[7] = 0x0a;
306 sb[12] = stat_table[i][2];
307 sb[13] = stat_table[i][3];
308 return;
309 }
310 i++;
311 } 658 }
312 /* No error ?? */
313 printk(KERN_ERR "ata%u: called with no error (%02X)!\n", qc->ap->id, drv_stat);
314 /* additional-sense-code[-qualifier] */
315 659
316 sb[0] = 0x70; 660 else {
317 sb[2] = MEDIUM_ERROR; 661 /* TODO: C/H/S */
318 sb[7] = 0x0A;
319 if (cmd->sc_data_direction == DMA_FROM_DEVICE) {
320 sb[12] = 0x11; /* "unrecovered read error" */
321 sb[13] = 0x04;
322 } else {
323 sb[12] = 0x0C; /* "write error - */
324 sb[13] = 0x02; /* auto-reallocation failed" */
325 } 662 }
326} 663}
327 664
@@ -420,7 +757,7 @@ int ata_scsi_error(struct Scsi_Host *host)
420 */ 757 */
421 758
422static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc, 759static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc,
423 u8 *scsicmd) 760 const u8 *scsicmd)
424{ 761{
425 struct ata_taskfile *tf = &qc->tf; 762 struct ata_taskfile *tf = &qc->tf;
426 763
@@ -430,15 +767,26 @@ static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc,
430 ; /* ignore IMMED bit, violates sat-r05 */ 767 ; /* ignore IMMED bit, violates sat-r05 */
431 } 768 }
432 if (scsicmd[4] & 0x2) 769 if (scsicmd[4] & 0x2)
433 return 1; /* LOEJ bit set not supported */ 770 goto invalid_fld; /* LOEJ bit set not supported */
434 if (((scsicmd[4] >> 4) & 0xf) != 0) 771 if (((scsicmd[4] >> 4) & 0xf) != 0)
435 return 1; /* power conditions not supported */ 772 goto invalid_fld; /* power conditions not supported */
436 if (scsicmd[4] & 0x1) { 773 if (scsicmd[4] & 0x1) {
437 tf->nsect = 1; /* 1 sector, lba=0 */ 774 tf->nsect = 1; /* 1 sector, lba=0 */
438 tf->lbah = 0x0; 775
439 tf->lbam = 0x0; 776 if (qc->dev->flags & ATA_DFLAG_LBA) {
440 tf->lbal = 0x0; 777 qc->tf.flags |= ATA_TFLAG_LBA;
441 tf->device |= ATA_LBA; 778
779 tf->lbah = 0x0;
780 tf->lbam = 0x0;
781 tf->lbal = 0x0;
782 tf->device |= ATA_LBA;
783 } else {
784 /* CHS */
785 tf->lbal = 0x1; /* sect */
786 tf->lbam = 0x0; /* cyl low */
787 tf->lbah = 0x0; /* cyl high */
788 }
789
442 tf->command = ATA_CMD_VERIFY; /* READ VERIFY */ 790 tf->command = ATA_CMD_VERIFY; /* READ VERIFY */
443 } else { 791 } else {
444 tf->nsect = 0; /* time period value (0 implies now) */ 792 tf->nsect = 0; /* time period value (0 implies now) */
@@ -453,6 +801,11 @@ static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc,
453 */ 801 */
454 802
455 return 0; 803 return 0;
804
805invalid_fld:
806 ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x24, 0x0);
807 /* "Invalid field in cbd" */
808 return 1;
456} 809}
457 810
458 811
@@ -471,14 +824,14 @@ static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc,
471 * Zero on success, non-zero on error. 824 * Zero on success, non-zero on error.
472 */ 825 */
473 826
474static unsigned int ata_scsi_flush_xlat(struct ata_queued_cmd *qc, u8 *scsicmd) 827static unsigned int ata_scsi_flush_xlat(struct ata_queued_cmd *qc, const u8 *scsicmd)
475{ 828{
476 struct ata_taskfile *tf = &qc->tf; 829 struct ata_taskfile *tf = &qc->tf;
477 830
478 tf->flags |= ATA_TFLAG_DEVICE; 831 tf->flags |= ATA_TFLAG_DEVICE;
479 tf->protocol = ATA_PROT_NODATA; 832 tf->protocol = ATA_PROT_NODATA;
480 833
481 if ((tf->flags & ATA_TFLAG_LBA48) && 834 if ((qc->dev->flags & ATA_DFLAG_LBA48) &&
482 (ata_id_has_flush_ext(qc->dev->id))) 835 (ata_id_has_flush_ext(qc->dev->id)))
483 tf->command = ATA_CMD_FLUSH_EXT; 836 tf->command = ATA_CMD_FLUSH_EXT;
484 else 837 else
@@ -488,6 +841,99 @@ static unsigned int ata_scsi_flush_xlat(struct ata_queued_cmd *qc, u8 *scsicmd)
488} 841}
489 842
490/** 843/**
844 * scsi_6_lba_len - Get LBA and transfer length
845 * @scsicmd: SCSI command to translate
846 *
847 * Calculate LBA and transfer length for 6-byte commands.
848 *
849 * RETURNS:
850 * @plba: the LBA
851 * @plen: the transfer length
852 */
853
854static void scsi_6_lba_len(const u8 *scsicmd, u64 *plba, u32 *plen)
855{
856 u64 lba = 0;
857 u32 len = 0;
858
859 VPRINTK("six-byte command\n");
860
861 lba |= ((u64)scsicmd[2]) << 8;
862 lba |= ((u64)scsicmd[3]);
863
864 len |= ((u32)scsicmd[4]);
865
866 *plba = lba;
867 *plen = len;
868}
869
870/**
871 * scsi_10_lba_len - Get LBA and transfer length
872 * @scsicmd: SCSI command to translate
873 *
874 * Calculate LBA and transfer length for 10-byte commands.
875 *
876 * RETURNS:
877 * @plba: the LBA
878 * @plen: the transfer length
879 */
880
881static void scsi_10_lba_len(const u8 *scsicmd, u64 *plba, u32 *plen)
882{
883 u64 lba = 0;
884 u32 len = 0;
885
886 VPRINTK("ten-byte command\n");
887
888 lba |= ((u64)scsicmd[2]) << 24;
889 lba |= ((u64)scsicmd[3]) << 16;
890 lba |= ((u64)scsicmd[4]) << 8;
891 lba |= ((u64)scsicmd[5]);
892
893 len |= ((u32)scsicmd[7]) << 8;
894 len |= ((u32)scsicmd[8]);
895
896 *plba = lba;
897 *plen = len;
898}
899
900/**
901 * scsi_16_lba_len - Get LBA and transfer length
902 * @scsicmd: SCSI command to translate
903 *
904 * Calculate LBA and transfer length for 16-byte commands.
905 *
906 * RETURNS:
907 * @plba: the LBA
908 * @plen: the transfer length
909 */
910
911static void scsi_16_lba_len(const u8 *scsicmd, u64 *plba, u32 *plen)
912{
913 u64 lba = 0;
914 u32 len = 0;
915
916 VPRINTK("sixteen-byte command\n");
917
918 lba |= ((u64)scsicmd[2]) << 56;
919 lba |= ((u64)scsicmd[3]) << 48;
920 lba |= ((u64)scsicmd[4]) << 40;
921 lba |= ((u64)scsicmd[5]) << 32;
922 lba |= ((u64)scsicmd[6]) << 24;
923 lba |= ((u64)scsicmd[7]) << 16;
924 lba |= ((u64)scsicmd[8]) << 8;
925 lba |= ((u64)scsicmd[9]);
926
927 len |= ((u32)scsicmd[10]) << 24;
928 len |= ((u32)scsicmd[11]) << 16;
929 len |= ((u32)scsicmd[12]) << 8;
930 len |= ((u32)scsicmd[13]);
931
932 *plba = lba;
933 *plen = len;
934}
935
936/**
491 * ata_scsi_verify_xlat - Translate SCSI VERIFY command into an ATA one 937 * ata_scsi_verify_xlat - Translate SCSI VERIFY command into an ATA one
492 * @qc: Storage for translated ATA taskfile 938 * @qc: Storage for translated ATA taskfile
493 * @scsicmd: SCSI command to translate 939 * @scsicmd: SCSI command to translate
@@ -501,82 +947,110 @@ static unsigned int ata_scsi_flush_xlat(struct ata_queued_cmd *qc, u8 *scsicmd)
501 * Zero on success, non-zero on error. 947 * Zero on success, non-zero on error.
502 */ 948 */
503 949
504static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, u8 *scsicmd) 950static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, const u8 *scsicmd)
505{ 951{
506 struct ata_taskfile *tf = &qc->tf; 952 struct ata_taskfile *tf = &qc->tf;
507 unsigned int lba48 = tf->flags & ATA_TFLAG_LBA48; 953 struct ata_device *dev = qc->dev;
508 u64 dev_sectors = qc->dev->n_sectors; 954 u64 dev_sectors = qc->dev->n_sectors;
509 u64 sect = 0; 955 u64 block;
510 u32 n_sect = 0; 956 u32 n_block;
511 957
512 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; 958 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
513 tf->protocol = ATA_PROT_NODATA; 959 tf->protocol = ATA_PROT_NODATA;
514 tf->device |= ATA_LBA;
515 960
516 if (scsicmd[0] == VERIFY) { 961 if (scsicmd[0] == VERIFY)
517 sect |= ((u64)scsicmd[2]) << 24; 962 scsi_10_lba_len(scsicmd, &block, &n_block);
518 sect |= ((u64)scsicmd[3]) << 16; 963 else if (scsicmd[0] == VERIFY_16)
519 sect |= ((u64)scsicmd[4]) << 8; 964 scsi_16_lba_len(scsicmd, &block, &n_block);
520 sect |= ((u64)scsicmd[5]); 965 else
966 goto invalid_fld;
521 967
522 n_sect |= ((u32)scsicmd[7]) << 8; 968 if (!n_block)
523 n_sect |= ((u32)scsicmd[8]); 969 goto nothing_to_do;
524 } 970 if (block >= dev_sectors)
971 goto out_of_range;
972 if ((block + n_block) > dev_sectors)
973 goto out_of_range;
525 974
526 else if (scsicmd[0] == VERIFY_16) { 975 if (dev->flags & ATA_DFLAG_LBA) {
527 sect |= ((u64)scsicmd[2]) << 56; 976 tf->flags |= ATA_TFLAG_LBA;
528 sect |= ((u64)scsicmd[3]) << 48;
529 sect |= ((u64)scsicmd[4]) << 40;
530 sect |= ((u64)scsicmd[5]) << 32;
531 sect |= ((u64)scsicmd[6]) << 24;
532 sect |= ((u64)scsicmd[7]) << 16;
533 sect |= ((u64)scsicmd[8]) << 8;
534 sect |= ((u64)scsicmd[9]);
535
536 n_sect |= ((u32)scsicmd[10]) << 24;
537 n_sect |= ((u32)scsicmd[11]) << 16;
538 n_sect |= ((u32)scsicmd[12]) << 8;
539 n_sect |= ((u32)scsicmd[13]);
540 }
541 977
542 else 978 if (dev->flags & ATA_DFLAG_LBA48) {
543 return 1; 979 if (n_block > (64 * 1024))
980 goto invalid_fld;
544 981
545 if (!n_sect) 982 /* use LBA48 */
546 return 1; 983 tf->flags |= ATA_TFLAG_LBA48;
547 if (sect >= dev_sectors) 984 tf->command = ATA_CMD_VERIFY_EXT;
548 return 1;
549 if ((sect + n_sect) > dev_sectors)
550 return 1;
551 if (lba48) {
552 if (n_sect > (64 * 1024))
553 return 1;
554 } else {
555 if (n_sect > 256)
556 return 1;
557 }
558 985
559 if (lba48) { 986 tf->hob_nsect = (n_block >> 8) & 0xff;
560 tf->command = ATA_CMD_VERIFY_EXT; 987
988 tf->hob_lbah = (block >> 40) & 0xff;
989 tf->hob_lbam = (block >> 32) & 0xff;
990 tf->hob_lbal = (block >> 24) & 0xff;
991 } else {
992 if (n_block > 256)
993 goto invalid_fld;
994
995 /* use LBA28 */
996 tf->command = ATA_CMD_VERIFY;
997
998 tf->device |= (block >> 24) & 0xf;
999 }
561 1000
562 tf->hob_nsect = (n_sect >> 8) & 0xff; 1001 tf->nsect = n_block & 0xff;
563 1002
564 tf->hob_lbah = (sect >> 40) & 0xff; 1003 tf->lbah = (block >> 16) & 0xff;
565 tf->hob_lbam = (sect >> 32) & 0xff; 1004 tf->lbam = (block >> 8) & 0xff;
566 tf->hob_lbal = (sect >> 24) & 0xff; 1005 tf->lbal = block & 0xff;
1006
1007 tf->device |= ATA_LBA;
567 } else { 1008 } else {
1009 /* CHS */
1010 u32 sect, head, cyl, track;
1011
1012 if (n_block > 256)
1013 goto invalid_fld;
1014
1015 /* Convert LBA to CHS */
1016 track = (u32)block / dev->sectors;
1017 cyl = track / dev->heads;
1018 head = track % dev->heads;
1019 sect = (u32)block % dev->sectors + 1;
1020
1021 DPRINTK("block %u track %u cyl %u head %u sect %u\n",
1022 (u32)block, track, cyl, head, sect);
1023
1024 /* Check whether the converted CHS can fit.
1025 Cylinder: 0-65535
1026 Head: 0-15
1027 Sector: 1-255*/
1028 if ((cyl >> 16) || (head >> 4) || (sect >> 8) || (!sect))
1029 goto out_of_range;
1030
568 tf->command = ATA_CMD_VERIFY; 1031 tf->command = ATA_CMD_VERIFY;
569 1032 tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */
570 tf->device |= (sect >> 24) & 0xf; 1033 tf->lbal = sect;
1034 tf->lbam = cyl;
1035 tf->lbah = cyl >> 8;
1036 tf->device |= head;
571 } 1037 }
572 1038
573 tf->nsect = n_sect & 0xff; 1039 return 0;
574 1040
575 tf->lbah = (sect >> 16) & 0xff; 1041invalid_fld:
576 tf->lbam = (sect >> 8) & 0xff; 1042 ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x24, 0x0);
577 tf->lbal = sect & 0xff; 1043 /* "Invalid field in cbd" */
1044 return 1;
578 1045
579 return 0; 1046out_of_range:
1047 ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x21, 0x0);
1048 /* "Logical Block Address out of range" */
1049 return 1;
1050
1051nothing_to_do:
1052 qc->scsicmd->result = SAM_STAT_GOOD;
1053 return 1;
580} 1054}
581 1055
582/** 1056/**
@@ -599,117 +1073,175 @@ static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, u8 *scsicmd)
599 * Zero on success, non-zero on error. 1073 * Zero on success, non-zero on error.
600 */ 1074 */
601 1075
602static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, u8 *scsicmd) 1076static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicmd)
603{ 1077{
604 struct ata_taskfile *tf = &qc->tf; 1078 struct ata_taskfile *tf = &qc->tf;
605 unsigned int lba48 = tf->flags & ATA_TFLAG_LBA48; 1079 struct ata_device *dev = qc->dev;
1080 u64 block;
1081 u32 n_block;
606 1082
607 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; 1083 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
608 tf->protocol = qc->dev->xfer_protocol;
609 tf->device |= ATA_LBA;
610 1084
611 if (scsicmd[0] == READ_10 || scsicmd[0] == READ_6 || 1085 if (scsicmd[0] == WRITE_10 || scsicmd[0] == WRITE_6 ||
612 scsicmd[0] == READ_16) { 1086 scsicmd[0] == WRITE_16)
613 tf->command = qc->dev->read_cmd;
614 } else {
615 tf->command = qc->dev->write_cmd;
616 tf->flags |= ATA_TFLAG_WRITE; 1087 tf->flags |= ATA_TFLAG_WRITE;
617 }
618 1088
619 if (scsicmd[0] == READ_10 || scsicmd[0] == WRITE_10) { 1089 /* Calculate the SCSI LBA and transfer length. */
620 if (lba48) { 1090 switch (scsicmd[0]) {
621 tf->hob_nsect = scsicmd[7]; 1091 case READ_10:
622 tf->hob_lbal = scsicmd[2]; 1092 case WRITE_10:
1093 scsi_10_lba_len(scsicmd, &block, &n_block);
1094 break;
1095 case READ_6:
1096 case WRITE_6:
1097 scsi_6_lba_len(scsicmd, &block, &n_block);
623 1098
624 qc->nsect = ((unsigned int)scsicmd[7] << 8) | 1099 /* for 6-byte r/w commands, transfer length 0
625 scsicmd[8]; 1100 * means 256 blocks of data, not 0 block.
626 } else { 1101 */
627 /* if we don't support LBA48 addressing, the request 1102 if (!n_block)
628 * -may- be too large. */ 1103 n_block = 256;
629 if ((scsicmd[2] & 0xf0) || scsicmd[7]) 1104 break;
630 return 1; 1105 case READ_16:
1106 case WRITE_16:
1107 scsi_16_lba_len(scsicmd, &block, &n_block);
1108 break;
1109 default:
1110 DPRINTK("no-byte command\n");
1111 goto invalid_fld;
1112 }
631 1113
632 /* stores LBA27:24 in lower 4 bits of device reg */ 1114 /* Check and compose ATA command */
633 tf->device |= scsicmd[2]; 1115 if (!n_block)
1116 /* For 10-byte and 16-byte SCSI R/W commands, transfer
1117 * length 0 means transfer 0 block of data.
1118 * However, for ATA R/W commands, sector count 0 means
1119 * 256 or 65536 sectors, not 0 sectors as in SCSI.
1120 */
1121 goto nothing_to_do;
634 1122
635 qc->nsect = scsicmd[8]; 1123 if (dev->flags & ATA_DFLAG_LBA) {
636 } 1124 tf->flags |= ATA_TFLAG_LBA;
637 1125
638 tf->nsect = scsicmd[8]; 1126 if (dev->flags & ATA_DFLAG_LBA48) {
639 tf->lbal = scsicmd[5]; 1127 /* The request -may- be too large for LBA48. */
640 tf->lbam = scsicmd[4]; 1128 if ((block >> 48) || (n_block > 65536))
641 tf->lbah = scsicmd[3]; 1129 goto out_of_range;
642 1130
643 VPRINTK("ten-byte command\n"); 1131 /* use LBA48 */
644 if (qc->nsect == 0) /* we don't support length==0 cmds */ 1132 tf->flags |= ATA_TFLAG_LBA48;
645 return 1;
646 return 0;
647 }
648 1133
649 if (scsicmd[0] == READ_6 || scsicmd[0] == WRITE_6) { 1134 tf->hob_nsect = (n_block >> 8) & 0xff;
650 qc->nsect = tf->nsect = scsicmd[4];
651 if (!qc->nsect) {
652 qc->nsect = 256;
653 if (lba48)
654 tf->hob_nsect = 1;
655 }
656 1135
657 tf->lbal = scsicmd[3]; 1136 tf->hob_lbah = (block >> 40) & 0xff;
658 tf->lbam = scsicmd[2]; 1137 tf->hob_lbam = (block >> 32) & 0xff;
659 tf->lbah = scsicmd[1] & 0x1f; /* mask out reserved bits */ 1138 tf->hob_lbal = (block >> 24) & 0xff;
1139 } else {
1140 /* use LBA28 */
660 1141
661 VPRINTK("six-byte command\n"); 1142 /* The request -may- be too large for LBA28. */
662 return 0; 1143 if ((block >> 28) || (n_block > 256))
663 } 1144 goto out_of_range;
664 1145
665 if (scsicmd[0] == READ_16 || scsicmd[0] == WRITE_16) { 1146 tf->device |= (block >> 24) & 0xf;
666 /* rule out impossible LBAs and sector counts */ 1147 }
667 if (scsicmd[2] || scsicmd[3] || scsicmd[10] || scsicmd[11])
668 return 1;
669 1148
670 if (lba48) { 1149 ata_rwcmd_protocol(qc);
671 tf->hob_nsect = scsicmd[12];
672 tf->hob_lbal = scsicmd[6];
673 tf->hob_lbam = scsicmd[5];
674 tf->hob_lbah = scsicmd[4];
675 1150
676 qc->nsect = ((unsigned int)scsicmd[12] << 8) | 1151 qc->nsect = n_block;
677 scsicmd[13]; 1152 tf->nsect = n_block & 0xff;
678 } else {
679 /* once again, filter out impossible non-zero values */
680 if (scsicmd[4] || scsicmd[5] || scsicmd[12] ||
681 (scsicmd[6] & 0xf0))
682 return 1;
683 1153
684 /* stores LBA27:24 in lower 4 bits of device reg */ 1154 tf->lbah = (block >> 16) & 0xff;
685 tf->device |= scsicmd[6]; 1155 tf->lbam = (block >> 8) & 0xff;
1156 tf->lbal = block & 0xff;
686 1157
687 qc->nsect = scsicmd[13]; 1158 tf->device |= ATA_LBA;
688 } 1159 } else {
1160 /* CHS */
1161 u32 sect, head, cyl, track;
1162
1163 /* The request -may- be too large for CHS addressing. */
1164 if ((block >> 28) || (n_block > 256))
1165 goto out_of_range;
1166
1167 ata_rwcmd_protocol(qc);
1168
1169 /* Convert LBA to CHS */
1170 track = (u32)block / dev->sectors;
1171 cyl = track / dev->heads;
1172 head = track % dev->heads;
1173 sect = (u32)block % dev->sectors + 1;
1174
1175 DPRINTK("block %u track %u cyl %u head %u sect %u\n",
1176 (u32)block, track, cyl, head, sect);
1177
1178 /* Check whether the converted CHS can fit.
1179 Cylinder: 0-65535
1180 Head: 0-15
1181 Sector: 1-255*/
1182 if ((cyl >> 16) || (head >> 4) || (sect >> 8) || (!sect))
1183 goto out_of_range;
1184
1185 qc->nsect = n_block;
1186 tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */
1187 tf->lbal = sect;
1188 tf->lbam = cyl;
1189 tf->lbah = cyl >> 8;
1190 tf->device |= head;
1191 }
689 1192
690 tf->nsect = scsicmd[13]; 1193 return 0;
691 tf->lbal = scsicmd[9];
692 tf->lbam = scsicmd[8];
693 tf->lbah = scsicmd[7];
694 1194
695 VPRINTK("sixteen-byte command\n"); 1195invalid_fld:
696 if (qc->nsect == 0) /* we don't support length==0 cmds */ 1196 ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x24, 0x0);
697 return 1; 1197 /* "Invalid field in cbd" */
698 return 0; 1198 return 1;
699 }
700 1199
701 DPRINTK("no-byte command\n"); 1200out_of_range:
1201 ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x21, 0x0);
1202 /* "Logical Block Address out of range" */
1203 return 1;
1204
1205nothing_to_do:
1206 qc->scsicmd->result = SAM_STAT_GOOD;
702 return 1; 1207 return 1;
703} 1208}
704 1209
705static int ata_scsi_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) 1210static int ata_scsi_qc_complete(struct ata_queued_cmd *qc,
1211 unsigned int err_mask)
706{ 1212{
707 struct scsi_cmnd *cmd = qc->scsicmd; 1213 struct scsi_cmnd *cmd = qc->scsicmd;
1214 u8 *cdb = cmd->cmnd;
1215 int need_sense = (err_mask != 0);
1216
1217 /* For ATA pass thru (SAT) commands, generate a sense block if
1218 * user mandated it or if there's an error. Note that if we
1219 * generate because the user forced us to, a check condition
1220 * is generated and the ATA register values are returned
1221 * whether the command completed successfully or not. If there
1222 * was no error, SK, ASC and ASCQ will all be zero.
1223 */
1224 if (((cdb[0] == ATA_16) || (cdb[0] == ATA_12)) &&
1225 ((cdb[2] & 0x20) || need_sense)) {
1226 ata_gen_ata_desc_sense(qc);
1227 } else {
1228 if (!need_sense) {
1229 cmd->result = SAM_STAT_GOOD;
1230 } else {
1231 /* TODO: decide which descriptor format to use
1232 * for 48b LBA devices and call that here
1233 * instead of the fixed desc, which is only
1234 * good for smaller LBA (and maybe CHS?)
1235 * devices.
1236 */
1237 ata_gen_fixed_sense(qc);
1238 }
1239 }
708 1240
709 if (unlikely(drv_stat & (ATA_ERR | ATA_BUSY | ATA_DRQ))) 1241 if (need_sense) {
710 ata_to_sense_error(qc, drv_stat); 1242 /* The ata_gen_..._sense routines fill in tf */
711 else 1243 ata_dump_status(qc->ap->id, &qc->tf);
712 cmd->result = SAM_STAT_GOOD; 1244 }
713 1245
714 qc->scsidone(cmd); 1246 qc->scsidone(cmd);
715 1247
@@ -731,6 +1263,12 @@ static int ata_scsi_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat)
731 * This function sets up an ata_queued_cmd structure for the 1263 * This function sets up an ata_queued_cmd structure for the
732 * SCSI command, and sends that ata_queued_cmd to the hardware. 1264 * SCSI command, and sends that ata_queued_cmd to the hardware.
733 * 1265 *
1266 * The xlat_func argument (actor) returns 0 if ready to execute
1267 * ATA command, else 1 to finish translation. If 1 is returned
1268 * then cmd->result (and possibly cmd->sense_buffer) are assumed
1269 * to be set reflecting an error condition or clean (early)
1270 * termination.
1271 *
734 * LOCKING: 1272 * LOCKING:
735 * spin_lock_irqsave(host_set lock) 1273 * spin_lock_irqsave(host_set lock)
736 */ 1274 */
@@ -747,7 +1285,7 @@ static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev,
747 1285
748 qc = ata_scsi_qc_new(ap, dev, cmd, done); 1286 qc = ata_scsi_qc_new(ap, dev, cmd, done);
749 if (!qc) 1287 if (!qc)
750 return; 1288 goto err_mem;
751 1289
752 /* data is present; dma-map it */ 1290 /* data is present; dma-map it */
753 if (cmd->sc_data_direction == DMA_FROM_DEVICE || 1291 if (cmd->sc_data_direction == DMA_FROM_DEVICE ||
@@ -755,7 +1293,7 @@ static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev,
755 if (unlikely(cmd->request_bufflen < 1)) { 1293 if (unlikely(cmd->request_bufflen < 1)) {
756 printk(KERN_WARNING "ata%u(%u): WARNING: zero len r/w req\n", 1294 printk(KERN_WARNING "ata%u(%u): WARNING: zero len r/w req\n",
757 ap->id, dev->devno); 1295 ap->id, dev->devno);
758 goto err_out; 1296 goto err_did;
759 } 1297 }
760 1298
761 if (cmd->use_sg) 1299 if (cmd->use_sg)
@@ -770,19 +1308,28 @@ static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev,
770 qc->complete_fn = ata_scsi_qc_complete; 1308 qc->complete_fn = ata_scsi_qc_complete;
771 1309
772 if (xlat_func(qc, scsicmd)) 1310 if (xlat_func(qc, scsicmd))
773 goto err_out; 1311 goto early_finish;
774 1312
775 /* select device, send command to hardware */ 1313 /* select device, send command to hardware */
776 if (ata_qc_issue(qc)) 1314 if (ata_qc_issue(qc))
777 goto err_out; 1315 goto err_did;
778 1316
779 VPRINTK("EXIT\n"); 1317 VPRINTK("EXIT\n");
780 return; 1318 return;
781 1319
782err_out: 1320early_finish:
1321 ata_qc_free(qc);
1322 done(cmd);
1323 DPRINTK("EXIT - early finish (good or error)\n");
1324 return;
1325
1326err_did:
783 ata_qc_free(qc); 1327 ata_qc_free(qc);
784 ata_bad_cdb(cmd, done); 1328err_mem:
785 DPRINTK("EXIT - badcmd\n"); 1329 cmd->result = (DID_ERROR << 16);
1330 done(cmd);
1331 DPRINTK("EXIT - internal\n");
1332 return;
786} 1333}
787 1334
788/** 1335/**
@@ -849,7 +1396,8 @@ static inline void ata_scsi_rbuf_put(struct scsi_cmnd *cmd, u8 *buf)
849 * Mapping the response buffer, calling the command's handler, 1396 * Mapping the response buffer, calling the command's handler,
850 * and handling the handler's return value. This return value 1397 * and handling the handler's return value. This return value
851 * indicates whether the handler wishes the SCSI command to be 1398 * indicates whether the handler wishes the SCSI command to be
852 * completed successfully, or not. 1399 * completed successfully (0), or not (in which case cmd->result
1400 * and sense buffer are assumed to be set).
853 * 1401 *
854 * LOCKING: 1402 * LOCKING:
855 * spin_lock_irqsave(host_set lock) 1403 * spin_lock_irqsave(host_set lock)
@@ -868,12 +1416,9 @@ void ata_scsi_rbuf_fill(struct ata_scsi_args *args,
868 rc = actor(args, rbuf, buflen); 1416 rc = actor(args, rbuf, buflen);
869 ata_scsi_rbuf_put(cmd, rbuf); 1417 ata_scsi_rbuf_put(cmd, rbuf);
870 1418
871 if (rc) 1419 if (rc == 0)
872 ata_bad_cdb(cmd, args->done);
873 else {
874 cmd->result = SAM_STAT_GOOD; 1420 cmd->result = SAM_STAT_GOOD;
875 args->done(cmd); 1421 args->done(cmd);
876 }
877} 1422}
878 1423
879/** 1424/**
@@ -1087,13 +1632,9 @@ static void ata_msense_push(u8 **ptr_io, const u8 *last,
1087static unsigned int ata_msense_caching(u16 *id, u8 **ptr_io, 1632static unsigned int ata_msense_caching(u16 *id, u8 **ptr_io,
1088 const u8 *last) 1633 const u8 *last)
1089{ 1634{
1090 u8 page[] = { 1635 u8 page[CACHE_MPAGE_LEN];
1091 0x8, /* page code */
1092 0x12, /* page length */
1093 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 10 zeroes */
1094 0, 0, 0, 0, 0, 0, 0, 0 /* 8 zeroes */
1095 };
1096 1636
1637 memcpy(page, def_cache_mpage, sizeof(page));
1097 if (ata_id_wcache_enabled(id)) 1638 if (ata_id_wcache_enabled(id))
1098 page[2] |= (1 << 2); /* write cache enable */ 1639 page[2] |= (1 << 2); /* write cache enable */
1099 if (!ata_id_rahead_enabled(id)) 1640 if (!ata_id_rahead_enabled(id))
@@ -1117,15 +1658,9 @@ static unsigned int ata_msense_caching(u16 *id, u8 **ptr_io,
1117 1658
1118static unsigned int ata_msense_ctl_mode(u8 **ptr_io, const u8 *last) 1659static unsigned int ata_msense_ctl_mode(u8 **ptr_io, const u8 *last)
1119{ 1660{
1120 const u8 page[] = {0xa, 0xa, 6, 0, 0, 0, 0, 0, 0xff, 0xff, 0, 30}; 1661 ata_msense_push(ptr_io, last, def_control_mpage,
1121 1662 sizeof(def_control_mpage));
1122 /* byte 2: set the descriptor format sense data bit (bit 2) 1663 return sizeof(def_control_mpage);
1123 * since we need to support returning this format for SAT
1124 * commands and any SCSI commands against a 48b LBA device.
1125 */
1126
1127 ata_msense_push(ptr_io, last, page, sizeof(page));
1128 return sizeof(page);
1129} 1664}
1130 1665
1131/** 1666/**
@@ -1142,15 +1677,10 @@ static unsigned int ata_msense_ctl_mode(u8 **ptr_io, const u8 *last)
1142 1677
1143static unsigned int ata_msense_rw_recovery(u8 **ptr_io, const u8 *last) 1678static unsigned int ata_msense_rw_recovery(u8 **ptr_io, const u8 *last)
1144{ 1679{
1145 const u8 page[] = {
1146 0x1, /* page code */
1147 0xa, /* page length */
1148 (1 << 7) | (1 << 6), /* note auto r/w reallocation */
1149 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 9 zeroes */
1150 };
1151 1680
1152 ata_msense_push(ptr_io, last, page, sizeof(page)); 1681 ata_msense_push(ptr_io, last, def_rw_recovery_mpage,
1153 return sizeof(page); 1682 sizeof(def_rw_recovery_mpage));
1683 return sizeof(def_rw_recovery_mpage);
1154} 1684}
1155 1685
1156/** 1686/**
@@ -1159,7 +1689,9 @@ static unsigned int ata_msense_rw_recovery(u8 **ptr_io, const u8 *last)
1159 * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. 1689 * @rbuf: Response buffer, to which simulated SCSI cmd output is sent.
1160 * @buflen: Response buffer length. 1690 * @buflen: Response buffer length.
1161 * 1691 *
1162 * Simulate MODE SENSE commands. 1692 * Simulate MODE SENSE commands. Assume this is invoked for direct
1693 * access devices (e.g. disks) only. There should be no block
1694 * descriptor for other device types.
1163 * 1695 *
1164 * LOCKING: 1696 * LOCKING:
1165 * spin_lock_irqsave(host_set lock) 1697 * spin_lock_irqsave(host_set lock)
@@ -1169,61 +1701,115 @@ unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf,
1169 unsigned int buflen) 1701 unsigned int buflen)
1170{ 1702{
1171 u8 *scsicmd = args->cmd->cmnd, *p, *last; 1703 u8 *scsicmd = args->cmd->cmnd, *p, *last;
1172 unsigned int page_control, six_byte, output_len; 1704 const u8 sat_blk_desc[] = {
1705 0, 0, 0, 0, /* number of blocks: sat unspecified */
1706 0,
1707 0, 0x2, 0x0 /* block length: 512 bytes */
1708 };
1709 u8 pg, spg;
1710 unsigned int ebd, page_control, six_byte, output_len, alloc_len, minlen;
1173 1711
1174 VPRINTK("ENTER\n"); 1712 VPRINTK("ENTER\n");
1175 1713
1176 six_byte = (scsicmd[0] == MODE_SENSE); 1714 six_byte = (scsicmd[0] == MODE_SENSE);
1177 1715 ebd = !(scsicmd[1] & 0x8); /* dbd bit inverted == edb */
1178 /* we only support saved and current values (which we treat 1716 /*
1179 * in the same manner) 1717 * LLBA bit in msense(10) ignored (compliant)
1180 */ 1718 */
1719
1181 page_control = scsicmd[2] >> 6; 1720 page_control = scsicmd[2] >> 6;
1182 if ((page_control != 0) && (page_control != 3)) 1721 switch (page_control) {
1183 return 1; 1722 case 0: /* current */
1723 break; /* supported */
1724 case 3: /* saved */
1725 goto saving_not_supp;
1726 case 1: /* changeable */
1727 case 2: /* defaults */
1728 default:
1729 goto invalid_fld;
1730 }
1184 1731
1185 if (six_byte) 1732 if (six_byte) {
1186 output_len = 4; 1733 output_len = 4 + (ebd ? 8 : 0);
1187 else 1734 alloc_len = scsicmd[4];
1188 output_len = 8; 1735 } else {
1736 output_len = 8 + (ebd ? 8 : 0);
1737 alloc_len = (scsicmd[7] << 8) + scsicmd[8];
1738 }
1739 minlen = (alloc_len < buflen) ? alloc_len : buflen;
1189 1740
1190 p = rbuf + output_len; 1741 p = rbuf + output_len;
1191 last = rbuf + buflen - 1; 1742 last = rbuf + minlen - 1;
1192 1743
1193 switch(scsicmd[2] & 0x3f) { 1744 pg = scsicmd[2] & 0x3f;
1194 case 0x01: /* r/w error recovery */ 1745 spg = scsicmd[3];
1746 /*
1747 * No mode subpages supported (yet) but asking for _all_
1748 * subpages may be valid
1749 */
1750 if (spg && (spg != ALL_SUB_MPAGES))
1751 goto invalid_fld;
1752
1753 switch(pg) {
1754 case RW_RECOVERY_MPAGE:
1195 output_len += ata_msense_rw_recovery(&p, last); 1755 output_len += ata_msense_rw_recovery(&p, last);
1196 break; 1756 break;
1197 1757
1198 case 0x08: /* caching */ 1758 case CACHE_MPAGE:
1199 output_len += ata_msense_caching(args->id, &p, last); 1759 output_len += ata_msense_caching(args->id, &p, last);
1200 break; 1760 break;
1201 1761
1202 case 0x0a: { /* control mode */ 1762 case CONTROL_MPAGE: {
1203 output_len += ata_msense_ctl_mode(&p, last); 1763 output_len += ata_msense_ctl_mode(&p, last);
1204 break; 1764 break;
1205 } 1765 }
1206 1766
1207 case 0x3f: /* all pages */ 1767 case ALL_MPAGES:
1208 output_len += ata_msense_rw_recovery(&p, last); 1768 output_len += ata_msense_rw_recovery(&p, last);
1209 output_len += ata_msense_caching(args->id, &p, last); 1769 output_len += ata_msense_caching(args->id, &p, last);
1210 output_len += ata_msense_ctl_mode(&p, last); 1770 output_len += ata_msense_ctl_mode(&p, last);
1211 break; 1771 break;
1212 1772
1213 default: /* invalid page code */ 1773 default: /* invalid page code */
1214 return 1; 1774 goto invalid_fld;
1215 } 1775 }
1216 1776
1777 if (minlen < 1)
1778 return 0;
1217 if (six_byte) { 1779 if (six_byte) {
1218 output_len--; 1780 output_len--;
1219 rbuf[0] = output_len; 1781 rbuf[0] = output_len;
1782 if (ebd) {
1783 if (minlen > 3)
1784 rbuf[3] = sizeof(sat_blk_desc);
1785 if (minlen > 11)
1786 memcpy(rbuf + 4, sat_blk_desc,
1787 sizeof(sat_blk_desc));
1788 }
1220 } else { 1789 } else {
1221 output_len -= 2; 1790 output_len -= 2;
1222 rbuf[0] = output_len >> 8; 1791 rbuf[0] = output_len >> 8;
1223 rbuf[1] = output_len; 1792 if (minlen > 1)
1793 rbuf[1] = output_len;
1794 if (ebd) {
1795 if (minlen > 7)
1796 rbuf[7] = sizeof(sat_blk_desc);
1797 if (minlen > 15)
1798 memcpy(rbuf + 8, sat_blk_desc,
1799 sizeof(sat_blk_desc));
1800 }
1224 } 1801 }
1225
1226 return 0; 1802 return 0;
1803
1804invalid_fld:
1805 ata_scsi_set_sense(args->cmd, ILLEGAL_REQUEST, 0x24, 0x0);
1806 /* "Invalid field in cbd" */
1807 return 1;
1808
1809saving_not_supp:
1810 ata_scsi_set_sense(args->cmd, ILLEGAL_REQUEST, 0x39, 0x0);
1811 /* "Saving parameters not supported" */
1812 return 1;
1227} 1813}
1228 1814
1229/** 1815/**
@@ -1246,10 +1832,20 @@ unsigned int ata_scsiop_read_cap(struct ata_scsi_args *args, u8 *rbuf,
1246 1832
1247 VPRINTK("ENTER\n"); 1833 VPRINTK("ENTER\n");
1248 1834
1249 if (ata_id_has_lba48(args->id)) 1835 if (ata_id_has_lba(args->id)) {
1250 n_sectors = ata_id_u64(args->id, 100); 1836 if (ata_id_has_lba48(args->id))
1251 else 1837 n_sectors = ata_id_u64(args->id, 100);
1252 n_sectors = ata_id_u32(args->id, 60); 1838 else
1839 n_sectors = ata_id_u32(args->id, 60);
1840 } else {
1841 /* CHS default translation */
1842 n_sectors = args->id[1] * args->id[3] * args->id[6];
1843
1844 if (ata_id_current_chs_valid(args->id))
1845 /* CHS current translation */
1846 n_sectors = ata_id_u32(args->id, 57);
1847 }
1848
1253 n_sectors--; /* ATA TotalUserSectors - 1 */ 1849 n_sectors--; /* ATA TotalUserSectors - 1 */
1254 1850
1255 if (args->cmd->cmnd[0] == READ_CAPACITY) { 1851 if (args->cmd->cmnd[0] == READ_CAPACITY) {
@@ -1313,6 +1909,34 @@ unsigned int ata_scsiop_report_luns(struct ata_scsi_args *args, u8 *rbuf,
1313} 1909}
1314 1910
1315/** 1911/**
1912 * ata_scsi_set_sense - Set SCSI sense data and status
1913 * @cmd: SCSI request to be handled
1914 * @sk: SCSI-defined sense key
1915 * @asc: SCSI-defined additional sense code
1916 * @ascq: SCSI-defined additional sense code qualifier
1917 *
1918 * Helper function that builds a valid fixed format, current
1919 * response code and the given sense key (sk), additional sense
1920 * code (asc) and additional sense code qualifier (ascq) with
1921 * a SCSI command status of %SAM_STAT_CHECK_CONDITION and
1922 * DRIVER_SENSE set in the upper bits of scsi_cmnd::result .
1923 *
1924 * LOCKING:
1925 * Not required
1926 */
1927
1928void ata_scsi_set_sense(struct scsi_cmnd *cmd, u8 sk, u8 asc, u8 ascq)
1929{
1930 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
1931
1932 cmd->sense_buffer[0] = 0x70; /* fixed format, current */
1933 cmd->sense_buffer[2] = sk;
1934 cmd->sense_buffer[7] = 18 - 8; /* additional sense length */
1935 cmd->sense_buffer[12] = asc;
1936 cmd->sense_buffer[13] = ascq;
1937}
1938
1939/**
1316 * ata_scsi_badcmd - End a SCSI request with an error 1940 * ata_scsi_badcmd - End a SCSI request with an error
1317 * @cmd: SCSI request to be handled 1941 * @cmd: SCSI request to be handled
1318 * @done: SCSI command completion function 1942 * @done: SCSI command completion function
@@ -1330,30 +1954,89 @@ unsigned int ata_scsiop_report_luns(struct ata_scsi_args *args, u8 *rbuf,
1330void ata_scsi_badcmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *), u8 asc, u8 ascq) 1954void ata_scsi_badcmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *), u8 asc, u8 ascq)
1331{ 1955{
1332 DPRINTK("ENTER\n"); 1956 DPRINTK("ENTER\n");
1333 cmd->result = SAM_STAT_CHECK_CONDITION; 1957 ata_scsi_set_sense(cmd, ILLEGAL_REQUEST, asc, ascq);
1334
1335 cmd->sense_buffer[0] = 0x70;
1336 cmd->sense_buffer[2] = ILLEGAL_REQUEST;
1337 cmd->sense_buffer[7] = 14 - 8; /* addnl. sense len. FIXME: correct? */
1338 cmd->sense_buffer[12] = asc;
1339 cmd->sense_buffer[13] = ascq;
1340 1958
1341 done(cmd); 1959 done(cmd);
1342} 1960}
1343 1961
1344static int atapi_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) 1962void atapi_request_sense(struct ata_port *ap, struct ata_device *dev,
1963 struct scsi_cmnd *cmd)
1964{
1965 DECLARE_COMPLETION(wait);
1966 struct ata_queued_cmd *qc;
1967 unsigned long flags;
1968 int rc;
1969
1970 DPRINTK("ATAPI request sense\n");
1971
1972 qc = ata_qc_new_init(ap, dev);
1973 BUG_ON(qc == NULL);
1974
1975 /* FIXME: is this needed? */
1976 memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
1977
1978 ata_sg_init_one(qc, cmd->sense_buffer, sizeof(cmd->sense_buffer));
1979 qc->dma_dir = DMA_FROM_DEVICE;
1980
1981 memset(&qc->cdb, 0, ap->cdb_len);
1982 qc->cdb[0] = REQUEST_SENSE;
1983 qc->cdb[4] = SCSI_SENSE_BUFFERSIZE;
1984
1985 qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
1986 qc->tf.command = ATA_CMD_PACKET;
1987
1988 qc->tf.protocol = ATA_PROT_ATAPI;
1989 qc->tf.lbam = (8 * 1024) & 0xff;
1990 qc->tf.lbah = (8 * 1024) >> 8;
1991 qc->nbytes = SCSI_SENSE_BUFFERSIZE;
1992
1993 qc->waiting = &wait;
1994 qc->complete_fn = ata_qc_complete_noop;
1995
1996 spin_lock_irqsave(&ap->host_set->lock, flags);
1997 rc = ata_qc_issue(qc);
1998 spin_unlock_irqrestore(&ap->host_set->lock, flags);
1999
2000 if (rc)
2001 ata_port_disable(ap);
2002 else
2003 wait_for_completion(&wait);
2004
2005 DPRINTK("EXIT\n");
2006}
2007
2008static int atapi_qc_complete(struct ata_queued_cmd *qc, unsigned int err_mask)
1345{ 2009{
1346 struct scsi_cmnd *cmd = qc->scsicmd; 2010 struct scsi_cmnd *cmd = qc->scsicmd;
1347 2011
1348 if (unlikely(drv_stat & (ATA_ERR | ATA_BUSY | ATA_DRQ))) { 2012 VPRINTK("ENTER, err_mask 0x%X\n", err_mask);
2013
2014 if (unlikely(err_mask & AC_ERR_DEV)) {
1349 DPRINTK("request check condition\n"); 2015 DPRINTK("request check condition\n");
1350 2016
2017 /* FIXME: command completion with check condition
2018 * but no sense causes the error handler to run,
2019 * which then issues REQUEST SENSE, fills in the sense
2020 * buffer, and completes the command (for the second
2021 * time). We need to issue REQUEST SENSE some other
2022 * way, to avoid completing the command twice.
2023 */
1351 cmd->result = SAM_STAT_CHECK_CONDITION; 2024 cmd->result = SAM_STAT_CHECK_CONDITION;
1352 2025
1353 qc->scsidone(cmd); 2026 qc->scsidone(cmd);
1354 2027
1355 return 1; 2028 return 1;
1356 } else { 2029 }
2030
2031 else if (unlikely(err_mask))
2032 /* FIXME: not quite right; we don't want the
2033 * translation of taskfile registers into
2034 * a sense descriptors, since that's only
2035 * correct for ATA, not ATAPI
2036 */
2037 ata_gen_ata_desc_sense(qc);
2038
2039 else {
1357 u8 *scsicmd = cmd->cmnd; 2040 u8 *scsicmd = cmd->cmnd;
1358 2041
1359 if (scsicmd[0] == INQUIRY) { 2042 if (scsicmd[0] == INQUIRY) {
@@ -1361,15 +2044,30 @@ static int atapi_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat)
1361 unsigned int buflen; 2044 unsigned int buflen;
1362 2045
1363 buflen = ata_scsi_rbuf_get(cmd, &buf); 2046 buflen = ata_scsi_rbuf_get(cmd, &buf);
1364 buf[2] = 0x5; 2047
1365 buf[3] = (buf[3] & 0xf0) | 2; 2048 /* ATAPI devices typically report zero for their SCSI version,
2049 * and sometimes deviate from the spec WRT response data
2050 * format. If SCSI version is reported as zero like normal,
2051 * then we make the following fixups: 1) Fake MMC-5 version,
2052 * to indicate to the Linux scsi midlayer this is a modern
2053 * device. 2) Ensure response data format / ATAPI information
2054 * are always correct.
2055 */
2056 /* FIXME: do we ever override EVPD pages and the like, with
2057 * this code?
2058 */
2059 if (buf[2] == 0) {
2060 buf[2] = 0x5;
2061 buf[3] = 0x32;
2062 }
2063
1366 ata_scsi_rbuf_put(cmd, buf); 2064 ata_scsi_rbuf_put(cmd, buf);
1367 } 2065 }
2066
1368 cmd->result = SAM_STAT_GOOD; 2067 cmd->result = SAM_STAT_GOOD;
1369 } 2068 }
1370 2069
1371 qc->scsidone(cmd); 2070 qc->scsidone(cmd);
1372
1373 return 0; 2071 return 0;
1374} 2072}
1375/** 2073/**
@@ -1384,7 +2082,7 @@ static int atapi_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat)
1384 * Zero on success, non-zero on failure. 2082 * Zero on success, non-zero on failure.
1385 */ 2083 */
1386 2084
1387static unsigned int atapi_xlat(struct ata_queued_cmd *qc, u8 *scsicmd) 2085static unsigned int atapi_xlat(struct ata_queued_cmd *qc, const u8 *scsicmd)
1388{ 2086{
1389 struct scsi_cmnd *cmd = qc->scsicmd; 2087 struct scsi_cmnd *cmd = qc->scsicmd;
1390 struct ata_device *dev = qc->dev; 2088 struct ata_device *dev = qc->dev;
@@ -1453,7 +2151,7 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc, u8 *scsicmd)
1453 */ 2151 */
1454 2152
1455static struct ata_device * 2153static struct ata_device *
1456ata_scsi_find_dev(struct ata_port *ap, struct scsi_device *scsidev) 2154ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev)
1457{ 2155{
1458 struct ata_device *dev; 2156 struct ata_device *dev;
1459 2157
@@ -1478,6 +2176,143 @@ ata_scsi_find_dev(struct ata_port *ap, struct scsi_device *scsidev)
1478 return dev; 2176 return dev;
1479} 2177}
1480 2178
2179/*
2180 * ata_scsi_map_proto - Map pass-thru protocol value to taskfile value.
2181 * @byte1: Byte 1 from pass-thru CDB.
2182 *
2183 * RETURNS:
2184 * ATA_PROT_UNKNOWN if mapping failed/unimplemented, protocol otherwise.
2185 */
2186static u8
2187ata_scsi_map_proto(u8 byte1)
2188{
2189 switch((byte1 & 0x1e) >> 1) {
2190 case 3: /* Non-data */
2191 return ATA_PROT_NODATA;
2192
2193 case 6: /* DMA */
2194 return ATA_PROT_DMA;
2195
2196 case 4: /* PIO Data-in */
2197 case 5: /* PIO Data-out */
2198 if (byte1 & 0xe0) {
2199 return ATA_PROT_PIO_MULT;
2200 }
2201 return ATA_PROT_PIO;
2202
2203 case 10: /* Device Reset */
2204 case 0: /* Hard Reset */
2205 case 1: /* SRST */
2206 case 2: /* Bus Idle */
2207 case 7: /* Packet */
2208 case 8: /* DMA Queued */
2209 case 9: /* Device Diagnostic */
2210 case 11: /* UDMA Data-in */
2211 case 12: /* UDMA Data-Out */
2212 case 13: /* FPDMA */
2213 default: /* Reserved */
2214 break;
2215 }
2216
2217 return ATA_PROT_UNKNOWN;
2218}
2219
2220/**
2221 * ata_scsi_pass_thru - convert ATA pass-thru CDB to taskfile
2222 * @qc: command structure to be initialized
2223 * @cmd: SCSI command to convert
2224 *
2225 * Handles either 12 or 16-byte versions of the CDB.
2226 *
2227 * RETURNS:
2228 * Zero on success, non-zero on failure.
2229 */
2230static unsigned int
2231ata_scsi_pass_thru(struct ata_queued_cmd *qc, const u8 *scsicmd)
2232{
2233 struct ata_taskfile *tf = &(qc->tf);
2234 struct scsi_cmnd *cmd = qc->scsicmd;
2235
2236 if ((tf->protocol = ata_scsi_map_proto(scsicmd[1])) == ATA_PROT_UNKNOWN)
2237 return 1;
2238
2239 /*
2240 * 12 and 16 byte CDBs use different offsets to
2241 * provide the various register values.
2242 */
2243 if (scsicmd[0] == ATA_16) {
2244 /*
2245 * 16-byte CDB - may contain extended commands.
2246 *
2247 * If that is the case, copy the upper byte register values.
2248 */
2249 if (scsicmd[1] & 0x01) {
2250 tf->hob_feature = scsicmd[3];
2251 tf->hob_nsect = scsicmd[5];
2252 tf->hob_lbal = scsicmd[7];
2253 tf->hob_lbam = scsicmd[9];
2254 tf->hob_lbah = scsicmd[11];
2255 tf->flags |= ATA_TFLAG_LBA48;
2256 } else
2257 tf->flags &= ~ATA_TFLAG_LBA48;
2258
2259 /*
2260 * Always copy low byte, device and command registers.
2261 */
2262 tf->feature = scsicmd[4];
2263 tf->nsect = scsicmd[6];
2264 tf->lbal = scsicmd[8];
2265 tf->lbam = scsicmd[10];
2266 tf->lbah = scsicmd[12];
2267 tf->device = scsicmd[13];
2268 tf->command = scsicmd[14];
2269 } else {
2270 /*
2271 * 12-byte CDB - incapable of extended commands.
2272 */
2273 tf->flags &= ~ATA_TFLAG_LBA48;
2274
2275 tf->feature = scsicmd[3];
2276 tf->nsect = scsicmd[4];
2277 tf->lbal = scsicmd[5];
2278 tf->lbam = scsicmd[6];
2279 tf->lbah = scsicmd[7];
2280 tf->device = scsicmd[8];
2281 tf->command = scsicmd[9];
2282 }
2283
2284 /*
2285 * Filter SET_FEATURES - XFER MODE command -- otherwise,
2286 * SET_FEATURES - XFER MODE must be preceded/succeeded
2287 * by an update to hardware-specific registers for each
2288 * controller (i.e. the reason for ->set_piomode(),
2289 * ->set_dmamode(), and ->post_set_mode() hooks).
2290 */
2291 if ((tf->command == ATA_CMD_SET_FEATURES)
2292 && (tf->feature == SETFEATURES_XFER))
2293 return 1;
2294
2295 /*
2296 * Set flags so that all registers will be written,
2297 * and pass on write indication (used for PIO/DMA
2298 * setup.)
2299 */
2300 tf->flags |= (ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE);
2301
2302 if (cmd->sc_data_direction == DMA_TO_DEVICE)
2303 tf->flags |= ATA_TFLAG_WRITE;
2304
2305 /*
2306 * Set transfer length.
2307 *
2308 * TODO: find out if we need to do more here to
2309 * cover scatter/gather case.
2310 */
2311 qc->nsect = cmd->bufflen / ATA_SECT_SIZE;
2312
2313 return 0;
2314}
2315
1481/** 2316/**
1482 * ata_get_xlat_func - check if SCSI to ATA translation is possible 2317 * ata_get_xlat_func - check if SCSI to ATA translation is possible
1483 * @dev: ATA device 2318 * @dev: ATA device
@@ -1510,6 +2345,11 @@ static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev, u8 cmd)
1510 case VERIFY: 2345 case VERIFY:
1511 case VERIFY_16: 2346 case VERIFY_16:
1512 return ata_scsi_verify_xlat; 2347 return ata_scsi_verify_xlat;
2348
2349 case ATA_12:
2350 case ATA_16:
2351 return ata_scsi_pass_thru;
2352
1513 case START_STOP: 2353 case START_STOP:
1514 return ata_scsi_start_stop_xlat; 2354 return ata_scsi_start_stop_xlat;
1515 } 2355 }
@@ -1610,7 +2450,7 @@ void ata_scsi_simulate(u16 *id,
1610 void (*done)(struct scsi_cmnd *)) 2450 void (*done)(struct scsi_cmnd *))
1611{ 2451{
1612 struct ata_scsi_args args; 2452 struct ata_scsi_args args;
1613 u8 *scsicmd = cmd->cmnd; 2453 const u8 *scsicmd = cmd->cmnd;
1614 2454
1615 args.id = id; 2455 args.id = id;
1616 args.cmd = cmd; 2456 args.cmd = cmd;
@@ -1630,7 +2470,7 @@ void ata_scsi_simulate(u16 *id,
1630 2470
1631 case INQUIRY: 2471 case INQUIRY:
1632 if (scsicmd[1] & 2) /* is CmdDt set? */ 2472 if (scsicmd[1] & 2) /* is CmdDt set? */
1633 ata_bad_cdb(cmd, done); 2473 ata_scsi_invalid_field(cmd, done);
1634 else if ((scsicmd[1] & 1) == 0) /* is EVPD clear? */ 2474 else if ((scsicmd[1] & 1) == 0) /* is EVPD clear? */
1635 ata_scsi_rbuf_fill(&args, ata_scsiop_inq_std); 2475 ata_scsi_rbuf_fill(&args, ata_scsiop_inq_std);
1636 else if (scsicmd[2] == 0x00) 2476 else if (scsicmd[2] == 0x00)
@@ -1640,7 +2480,7 @@ void ata_scsi_simulate(u16 *id,
1640 else if (scsicmd[2] == 0x83) 2480 else if (scsicmd[2] == 0x83)
1641 ata_scsi_rbuf_fill(&args, ata_scsiop_inq_83); 2481 ata_scsi_rbuf_fill(&args, ata_scsiop_inq_83);
1642 else 2482 else
1643 ata_bad_cdb(cmd, done); 2483 ata_scsi_invalid_field(cmd, done);
1644 break; 2484 break;
1645 2485
1646 case MODE_SENSE: 2486 case MODE_SENSE:
@@ -1650,7 +2490,7 @@ void ata_scsi_simulate(u16 *id,
1650 2490
1651 case MODE_SELECT: /* unconditionally return */ 2491 case MODE_SELECT: /* unconditionally return */
1652 case MODE_SELECT_10: /* bad-field-in-cdb */ 2492 case MODE_SELECT_10: /* bad-field-in-cdb */
1653 ata_bad_cdb(cmd, done); 2493 ata_scsi_invalid_field(cmd, done);
1654 break; 2494 break;
1655 2495
1656 case READ_CAPACITY: 2496 case READ_CAPACITY:
@@ -1661,20 +2501,38 @@ void ata_scsi_simulate(u16 *id,
1661 if ((scsicmd[1] & 0x1f) == SAI_READ_CAPACITY_16) 2501 if ((scsicmd[1] & 0x1f) == SAI_READ_CAPACITY_16)
1662 ata_scsi_rbuf_fill(&args, ata_scsiop_read_cap); 2502 ata_scsi_rbuf_fill(&args, ata_scsiop_read_cap);
1663 else 2503 else
1664 ata_bad_cdb(cmd, done); 2504 ata_scsi_invalid_field(cmd, done);
1665 break; 2505 break;
1666 2506
1667 case REPORT_LUNS: 2507 case REPORT_LUNS:
1668 ata_scsi_rbuf_fill(&args, ata_scsiop_report_luns); 2508 ata_scsi_rbuf_fill(&args, ata_scsiop_report_luns);
1669 break; 2509 break;
1670 2510
1671 /* mandantory commands we haven't implemented yet */ 2511 /* mandatory commands we haven't implemented yet */
1672 case REQUEST_SENSE: 2512 case REQUEST_SENSE:
1673 2513
1674 /* all other commands */ 2514 /* all other commands */
1675 default: 2515 default:
1676 ata_bad_scsiop(cmd, done); 2516 ata_scsi_set_sense(cmd, ILLEGAL_REQUEST, 0x20, 0x0);
2517 /* "Invalid command operation code" */
2518 done(cmd);
1677 break; 2519 break;
1678 } 2520 }
1679} 2521}
1680 2522
2523void ata_scsi_scan_host(struct ata_port *ap)
2524{
2525 struct ata_device *dev;
2526 unsigned int i;
2527
2528 if (ap->flags & ATA_FLAG_PORT_DISABLED)
2529 return;
2530
2531 for (i = 0; i < ATA_MAX_DEVICES; i++) {
2532 dev = &ap->device[i];
2533
2534 if (ata_dev_present(dev))
2535 scsi_scan_target(&ap->host->shost_gendev, 0, i, 0, 0);
2536 }
2537}
2538
diff --git a/drivers/scsi/libata.h b/drivers/scsi/libata.h
index d608b3a0f6fe..10ecd9e15e4f 100644
--- a/drivers/scsi/libata.h
+++ b/drivers/scsi/libata.h
@@ -39,19 +39,25 @@ struct ata_scsi_args {
39 39
40/* libata-core.c */ 40/* libata-core.c */
41extern int atapi_enabled; 41extern int atapi_enabled;
42extern int ata_qc_complete_noop(struct ata_queued_cmd *qc, unsigned int err_mask);
42extern struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap, 43extern struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap,
43 struct ata_device *dev); 44 struct ata_device *dev);
45extern void ata_rwcmd_protocol(struct ata_queued_cmd *qc);
44extern void ata_qc_free(struct ata_queued_cmd *qc); 46extern void ata_qc_free(struct ata_queued_cmd *qc);
45extern int ata_qc_issue(struct ata_queued_cmd *qc); 47extern int ata_qc_issue(struct ata_queued_cmd *qc);
46extern int ata_check_atapi_dma(struct ata_queued_cmd *qc); 48extern int ata_check_atapi_dma(struct ata_queued_cmd *qc);
47extern void ata_dev_select(struct ata_port *ap, unsigned int device, 49extern void ata_dev_select(struct ata_port *ap, unsigned int device,
48 unsigned int wait, unsigned int can_sleep); 50 unsigned int wait, unsigned int can_sleep);
49extern void ata_tf_to_host_nolock(struct ata_port *ap, struct ata_taskfile *tf); 51extern void ata_tf_to_host_nolock(struct ata_port *ap, const struct ata_taskfile *tf);
50extern void swap_buf_le16(u16 *buf, unsigned int buf_words); 52extern void swap_buf_le16(u16 *buf, unsigned int buf_words);
53extern int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg);
54extern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg);
51 55
52 56
53/* libata-scsi.c */ 57/* libata-scsi.c */
54extern void ata_to_sense_error(struct ata_queued_cmd *qc, u8 drv_stat); 58extern void atapi_request_sense(struct ata_port *ap, struct ata_device *dev,
59 struct scsi_cmnd *cmd);
60extern void ata_scsi_scan_host(struct ata_port *ap);
55extern int ata_scsi_error(struct Scsi_Host *host); 61extern int ata_scsi_error(struct Scsi_Host *host);
56extern unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf, 62extern unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf,
57 unsigned int buflen); 63 unsigned int buflen);
@@ -76,18 +82,10 @@ extern unsigned int ata_scsiop_report_luns(struct ata_scsi_args *args, u8 *rbuf,
76extern void ata_scsi_badcmd(struct scsi_cmnd *cmd, 82extern void ata_scsi_badcmd(struct scsi_cmnd *cmd,
77 void (*done)(struct scsi_cmnd *), 83 void (*done)(struct scsi_cmnd *),
78 u8 asc, u8 ascq); 84 u8 asc, u8 ascq);
85extern void ata_scsi_set_sense(struct scsi_cmnd *cmd,
86 u8 sk, u8 asc, u8 ascq);
79extern void ata_scsi_rbuf_fill(struct ata_scsi_args *args, 87extern void ata_scsi_rbuf_fill(struct ata_scsi_args *args,
80 unsigned int (*actor) (struct ata_scsi_args *args, 88 unsigned int (*actor) (struct ata_scsi_args *args,
81 u8 *rbuf, unsigned int buflen)); 89 u8 *rbuf, unsigned int buflen));
82 90
83static inline void ata_bad_scsiop(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
84{
85 ata_scsi_badcmd(cmd, done, 0x20, 0x00);
86}
87
88static inline void ata_bad_cdb(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
89{
90 ata_scsi_badcmd(cmd, done, 0x24, 0x00);
91}
92
93#endif /* __LIBATA_H__ */ 91#endif /* __LIBATA_H__ */
diff --git a/drivers/scsi/lpfc/lpfc_mem.c b/drivers/scsi/lpfc/lpfc_mem.c
index 0aba13ceaacf..352df47bcaca 100644
--- a/drivers/scsi/lpfc/lpfc_mem.c
+++ b/drivers/scsi/lpfc/lpfc_mem.c
@@ -39,7 +39,7 @@
39#define LPFC_MEM_POOL_SIZE 64 /* max elem in non-DMA safety pool */ 39#define LPFC_MEM_POOL_SIZE 64 /* max elem in non-DMA safety pool */
40 40
41static void * 41static void *
42lpfc_pool_kmalloc(unsigned int gfp_flags, void *data) 42lpfc_pool_kmalloc(gfp_t gfp_flags, void *data)
43{ 43{
44 return kmalloc((unsigned long)data, gfp_flags); 44 return kmalloc((unsigned long)data, gfp_flags);
45} 45}
diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
index d47be8e0ea3a..c9e743ba09ec 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -76,7 +76,7 @@ static void megaraid_exit(void);
76 76
77static int megaraid_probe_one(struct pci_dev*, const struct pci_device_id *); 77static int megaraid_probe_one(struct pci_dev*, const struct pci_device_id *);
78static void megaraid_detach_one(struct pci_dev *); 78static void megaraid_detach_one(struct pci_dev *);
79static void megaraid_mbox_shutdown(struct device *); 79static void megaraid_mbox_shutdown(struct pci_dev *);
80 80
81static int megaraid_io_attach(adapter_t *); 81static int megaraid_io_attach(adapter_t *);
82static void megaraid_io_detach(adapter_t *); 82static void megaraid_io_detach(adapter_t *);
@@ -369,9 +369,7 @@ static struct pci_driver megaraid_pci_driver_g = {
369 .id_table = pci_id_table_g, 369 .id_table = pci_id_table_g,
370 .probe = megaraid_probe_one, 370 .probe = megaraid_probe_one,
371 .remove = __devexit_p(megaraid_detach_one), 371 .remove = __devexit_p(megaraid_detach_one),
372 .driver = { 372 .shutdown = megaraid_mbox_shutdown,
373 .shutdown = megaraid_mbox_shutdown,
374 }
375}; 373};
376 374
377 375
@@ -673,9 +671,9 @@ megaraid_detach_one(struct pci_dev *pdev)
673 * Shutdown notification, perform flush cache 671 * Shutdown notification, perform flush cache
674 */ 672 */
675static void 673static void
676megaraid_mbox_shutdown(struct device *device) 674megaraid_mbox_shutdown(struct pci_dev *pdev)
677{ 675{
678 adapter_t *adapter = pci_get_drvdata(to_pci_dev(device)); 676 adapter_t *adapter = pci_get_drvdata(pdev);
679 static int counter; 677 static int counter;
680 678
681 if (!adapter) { 679 if (!adapter) {
diff --git a/drivers/scsi/mesh.c b/drivers/scsi/mesh.c
index b235556b7b65..bdccf73cf9fe 100644
--- a/drivers/scsi/mesh.c
+++ b/drivers/scsi/mesh.c
@@ -730,7 +730,7 @@ static void start_phase(struct mesh_state *ms)
730 * issue a SEQ_MSGOUT to get the mesh to drop ACK. 730 * issue a SEQ_MSGOUT to get the mesh to drop ACK.
731 */ 731 */
732 if ((in_8(&mr->bus_status0) & BS0_ATN) == 0) { 732 if ((in_8(&mr->bus_status0) & BS0_ATN) == 0) {
733 dlog(ms, "bus0 was %.2x explictly asserting ATN", mr->bus_status0); 733 dlog(ms, "bus0 was %.2x explicitly asserting ATN", mr->bus_status0);
734 out_8(&mr->bus_status0, BS0_ATN); /* explicit ATN */ 734 out_8(&mr->bus_status0, BS0_ATN); /* explicit ATN */
735 mesh_flush_io(mr); 735 mesh_flush_io(mr);
736 udelay(1); 736 udelay(1);
diff --git a/drivers/scsi/osst.c b/drivers/scsi/osst.c
index 3f2f2464fa63..172839fce0eb 100644
--- a/drivers/scsi/osst.c
+++ b/drivers/scsi/osst.c
@@ -5146,7 +5146,8 @@ static long osst_compat_ioctl(struct file * file, unsigned int cmd_in, unsigned
5146/* Try to allocate a new tape buffer skeleton. Caller must not hold os_scsi_tapes_lock */ 5146/* Try to allocate a new tape buffer skeleton. Caller must not hold os_scsi_tapes_lock */
5147static struct osst_buffer * new_tape_buffer( int from_initialization, int need_dma, int max_sg ) 5147static struct osst_buffer * new_tape_buffer( int from_initialization, int need_dma, int max_sg )
5148{ 5148{
5149 int i, priority; 5149 int i;
5150 gfp_t priority;
5150 struct osst_buffer *tb; 5151 struct osst_buffer *tb;
5151 5152
5152 if (from_initialization) 5153 if (from_initialization)
@@ -5178,7 +5179,8 @@ static struct osst_buffer * new_tape_buffer( int from_initialization, int need_d
5178/* Try to allocate a temporary (while a user has the device open) enlarged tape buffer */ 5179/* Try to allocate a temporary (while a user has the device open) enlarged tape buffer */
5179static int enlarge_buffer(struct osst_buffer *STbuffer, int need_dma) 5180static int enlarge_buffer(struct osst_buffer *STbuffer, int need_dma)
5180{ 5181{
5181 int segs, nbr, max_segs, b_size, priority, order, got; 5182 int segs, nbr, max_segs, b_size, order, got;
5183 gfp_t priority;
5182 5184
5183 if (STbuffer->buffer_size >= OS_FRAME_SIZE) 5185 if (STbuffer->buffer_size >= OS_FRAME_SIZE)
5184 return 1; 5186 return 1;
@@ -5627,7 +5629,7 @@ static void osst_sysfs_add(dev_t dev, struct device *device, struct osst_tape *
5627 5629
5628 if (!osst_sysfs_valid) return; 5630 if (!osst_sysfs_valid) return;
5629 5631
5630 osst_class_member = class_device_create(osst_sysfs_class, dev, device, "%s", name); 5632 osst_class_member = class_device_create(osst_sysfs_class, NULL, dev, device, "%s", name);
5631 if (IS_ERR(osst_class_member)) { 5633 if (IS_ERR(osst_class_member)) {
5632 printk(KERN_WARNING "osst :W: Unable to add sysfs class member %s\n", name); 5634 printk(KERN_WARNING "osst :W: Unable to add sysfs class member %s\n", name);
5633 return; 5635 return;
diff --git a/drivers/scsi/pdc_adma.c b/drivers/scsi/pdc_adma.c
new file mode 100644
index 000000000000..665017eda8a6
--- /dev/null
+++ b/drivers/scsi/pdc_adma.c
@@ -0,0 +1,741 @@
1/*
2 * pdc_adma.c - Pacific Digital Corporation ADMA
3 *
4 * Maintained by: Mark Lord <mlord@pobox.com>
5 *
6 * Copyright 2005 Mark Lord
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; 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; see the file COPYING. If not, write to
20 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 *
23 * libata documentation is available via 'make {ps|pdf}docs',
24 * as Documentation/DocBook/libata.*
25 *
26 *
27 * Supports ATA disks in single-packet ADMA mode.
28 * Uses PIO for everything else.
29 *
30 * TODO: Use ADMA transfers for ATAPI devices, when possible.
31 * This requires careful attention to a number of quirks of the chip.
32 *
33 */
34
35#include <linux/kernel.h>
36#include <linux/module.h>
37#include <linux/pci.h>
38#include <linux/init.h>
39#include <linux/blkdev.h>
40#include <linux/delay.h>
41#include <linux/interrupt.h>
42#include <linux/sched.h>
43#include <linux/device.h>
44#include "scsi.h"
45#include <scsi/scsi_host.h>
46#include <asm/io.h>
47#include <linux/libata.h>
48
49#define DRV_NAME "pdc_adma"
50#define DRV_VERSION "0.03"
51
52/* macro to calculate base address for ATA regs */
53#define ADMA_ATA_REGS(base,port_no) ((base) + ((port_no) * 0x40))
54
55/* macro to calculate base address for ADMA regs */
56#define ADMA_REGS(base,port_no) ((base) + 0x80 + ((port_no) * 0x20))
57
58enum {
59 ADMA_PORTS = 2,
60 ADMA_CPB_BYTES = 40,
61 ADMA_PRD_BYTES = LIBATA_MAX_PRD * 16,
62 ADMA_PKT_BYTES = ADMA_CPB_BYTES + ADMA_PRD_BYTES,
63
64 ADMA_DMA_BOUNDARY = 0xffffffff,
65
66 /* global register offsets */
67 ADMA_MODE_LOCK = 0x00c7,
68
69 /* per-channel register offsets */
70 ADMA_CONTROL = 0x0000, /* ADMA control */
71 ADMA_STATUS = 0x0002, /* ADMA status */
72 ADMA_CPB_COUNT = 0x0004, /* CPB count */
73 ADMA_CPB_CURRENT = 0x000c, /* current CPB address */
74 ADMA_CPB_NEXT = 0x000c, /* next CPB address */
75 ADMA_CPB_LOOKUP = 0x0010, /* CPB lookup table */
76 ADMA_FIFO_IN = 0x0014, /* input FIFO threshold */
77 ADMA_FIFO_OUT = 0x0016, /* output FIFO threshold */
78
79 /* ADMA_CONTROL register bits */
80 aNIEN = (1 << 8), /* irq mask: 1==masked */
81 aGO = (1 << 7), /* packet trigger ("Go!") */
82 aRSTADM = (1 << 5), /* ADMA logic reset */
83 aPIOMD4 = 0x0003, /* PIO mode 4 */
84
85 /* ADMA_STATUS register bits */
86 aPSD = (1 << 6),
87 aUIRQ = (1 << 4),
88 aPERR = (1 << 0),
89
90 /* CPB bits */
91 cDONE = (1 << 0),
92 cVLD = (1 << 0),
93 cDAT = (1 << 2),
94 cIEN = (1 << 3),
95
96 /* PRD bits */
97 pORD = (1 << 4),
98 pDIRO = (1 << 5),
99 pEND = (1 << 7),
100
101 /* ATA register flags */
102 rIGN = (1 << 5),
103 rEND = (1 << 7),
104
105 /* ATA register addresses */
106 ADMA_REGS_CONTROL = 0x0e,
107 ADMA_REGS_SECTOR_COUNT = 0x12,
108 ADMA_REGS_LBA_LOW = 0x13,
109 ADMA_REGS_LBA_MID = 0x14,
110 ADMA_REGS_LBA_HIGH = 0x15,
111 ADMA_REGS_DEVICE = 0x16,
112 ADMA_REGS_COMMAND = 0x17,
113
114 /* PCI device IDs */
115 board_1841_idx = 0, /* ADMA 2-port controller */
116};
117
118typedef enum { adma_state_idle, adma_state_pkt, adma_state_mmio } adma_state_t;
119
120struct adma_port_priv {
121 u8 *pkt;
122 dma_addr_t pkt_dma;
123 adma_state_t state;
124};
125
126static int adma_ata_init_one (struct pci_dev *pdev,
127 const struct pci_device_id *ent);
128static irqreturn_t adma_intr (int irq, void *dev_instance,
129 struct pt_regs *regs);
130static int adma_port_start(struct ata_port *ap);
131static void adma_host_stop(struct ata_host_set *host_set);
132static void adma_port_stop(struct ata_port *ap);
133static void adma_phy_reset(struct ata_port *ap);
134static void adma_qc_prep(struct ata_queued_cmd *qc);
135static int adma_qc_issue(struct ata_queued_cmd *qc);
136static int adma_check_atapi_dma(struct ata_queued_cmd *qc);
137static void adma_bmdma_stop(struct ata_queued_cmd *qc);
138static u8 adma_bmdma_status(struct ata_port *ap);
139static void adma_irq_clear(struct ata_port *ap);
140static void adma_eng_timeout(struct ata_port *ap);
141
142static Scsi_Host_Template adma_ata_sht = {
143 .module = THIS_MODULE,
144 .name = DRV_NAME,
145 .ioctl = ata_scsi_ioctl,
146 .queuecommand = ata_scsi_queuecmd,
147 .eh_strategy_handler = ata_scsi_error,
148 .can_queue = ATA_DEF_QUEUE,
149 .this_id = ATA_SHT_THIS_ID,
150 .sg_tablesize = LIBATA_MAX_PRD,
151 .max_sectors = ATA_MAX_SECTORS,
152 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
153 .emulated = ATA_SHT_EMULATED,
154 .use_clustering = ENABLE_CLUSTERING,
155 .proc_name = DRV_NAME,
156 .dma_boundary = ADMA_DMA_BOUNDARY,
157 .slave_configure = ata_scsi_slave_config,
158 .bios_param = ata_std_bios_param,
159};
160
161static const struct ata_port_operations adma_ata_ops = {
162 .port_disable = ata_port_disable,
163 .tf_load = ata_tf_load,
164 .tf_read = ata_tf_read,
165 .check_status = ata_check_status,
166 .check_atapi_dma = adma_check_atapi_dma,
167 .exec_command = ata_exec_command,
168 .dev_select = ata_std_dev_select,
169 .phy_reset = adma_phy_reset,
170 .qc_prep = adma_qc_prep,
171 .qc_issue = adma_qc_issue,
172 .eng_timeout = adma_eng_timeout,
173 .irq_handler = adma_intr,
174 .irq_clear = adma_irq_clear,
175 .port_start = adma_port_start,
176 .port_stop = adma_port_stop,
177 .host_stop = adma_host_stop,
178 .bmdma_stop = adma_bmdma_stop,
179 .bmdma_status = adma_bmdma_status,
180};
181
182static struct ata_port_info adma_port_info[] = {
183 /* board_1841_idx */
184 {
185 .sht = &adma_ata_sht,
186 .host_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST |
187 ATA_FLAG_NO_LEGACY | ATA_FLAG_MMIO,
188 .pio_mask = 0x10, /* pio4 */
189 .udma_mask = 0x1f, /* udma0-4 */
190 .port_ops = &adma_ata_ops,
191 },
192};
193
194static struct pci_device_id adma_ata_pci_tbl[] = {
195 { PCI_VENDOR_ID_PDC, 0x1841, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
196 board_1841_idx },
197
198 { } /* terminate list */
199};
200
201static struct pci_driver adma_ata_pci_driver = {
202 .name = DRV_NAME,
203 .id_table = adma_ata_pci_tbl,
204 .probe = adma_ata_init_one,
205 .remove = ata_pci_remove_one,
206};
207
208static int adma_check_atapi_dma(struct ata_queued_cmd *qc)
209{
210 return 1; /* ATAPI DMA not yet supported */
211}
212
213static void adma_bmdma_stop(struct ata_queued_cmd *qc)
214{
215 /* nothing */
216}
217
218static u8 adma_bmdma_status(struct ata_port *ap)
219{
220 return 0;
221}
222
223static void adma_irq_clear(struct ata_port *ap)
224{
225 /* nothing */
226}
227
228static void adma_reset_engine(void __iomem *chan)
229{
230 /* reset ADMA to idle state */
231 writew(aPIOMD4 | aNIEN | aRSTADM, chan + ADMA_CONTROL);
232 udelay(2);
233 writew(aPIOMD4, chan + ADMA_CONTROL);
234 udelay(2);
235}
236
237static void adma_reinit_engine(struct ata_port *ap)
238{
239 struct adma_port_priv *pp = ap->private_data;
240 void __iomem *mmio_base = ap->host_set->mmio_base;
241 void __iomem *chan = ADMA_REGS(mmio_base, ap->port_no);
242
243 /* mask/clear ATA interrupts */
244 writeb(ATA_NIEN, (void __iomem *)ap->ioaddr.ctl_addr);
245 ata_check_status(ap);
246
247 /* reset the ADMA engine */
248 adma_reset_engine(chan);
249
250 /* set in-FIFO threshold to 0x100 */
251 writew(0x100, chan + ADMA_FIFO_IN);
252
253 /* set CPB pointer */
254 writel((u32)pp->pkt_dma, chan + ADMA_CPB_NEXT);
255
256 /* set out-FIFO threshold to 0x100 */
257 writew(0x100, chan + ADMA_FIFO_OUT);
258
259 /* set CPB count */
260 writew(1, chan + ADMA_CPB_COUNT);
261
262 /* read/discard ADMA status */
263 readb(chan + ADMA_STATUS);
264}
265
266static inline void adma_enter_reg_mode(struct ata_port *ap)
267{
268 void __iomem *chan = ADMA_REGS(ap->host_set->mmio_base, ap->port_no);
269
270 writew(aPIOMD4, chan + ADMA_CONTROL);
271 readb(chan + ADMA_STATUS); /* flush */
272}
273
274static void adma_phy_reset(struct ata_port *ap)
275{
276 struct adma_port_priv *pp = ap->private_data;
277
278 pp->state = adma_state_idle;
279 adma_reinit_engine(ap);
280 ata_port_probe(ap);
281 ata_bus_reset(ap);
282}
283
284static void adma_eng_timeout(struct ata_port *ap)
285{
286 struct adma_port_priv *pp = ap->private_data;
287
288 if (pp->state != adma_state_idle) /* healthy paranoia */
289 pp->state = adma_state_mmio;
290 adma_reinit_engine(ap);
291 ata_eng_timeout(ap);
292}
293
294static int adma_fill_sg(struct ata_queued_cmd *qc)
295{
296 struct scatterlist *sg = qc->sg;
297 struct ata_port *ap = qc->ap;
298 struct adma_port_priv *pp = ap->private_data;
299 u8 *buf = pp->pkt;
300 int nelem, i = (2 + buf[3]) * 8;
301 u8 pFLAGS = pORD | ((qc->tf.flags & ATA_TFLAG_WRITE) ? pDIRO : 0);
302
303 for (nelem = 0; nelem < qc->n_elem; nelem++,sg++) {
304 u32 addr;
305 u32 len;
306
307 addr = (u32)sg_dma_address(sg);
308 *(__le32 *)(buf + i) = cpu_to_le32(addr);
309 i += 4;
310
311 len = sg_dma_len(sg) >> 3;
312 *(__le32 *)(buf + i) = cpu_to_le32(len);
313 i += 4;
314
315 if ((nelem + 1) == qc->n_elem)
316 pFLAGS |= pEND;
317 buf[i++] = pFLAGS;
318 buf[i++] = qc->dev->dma_mode & 0xf;
319 buf[i++] = 0; /* pPKLW */
320 buf[i++] = 0; /* reserved */
321
322 *(__le32 *)(buf + i)
323 = (pFLAGS & pEND) ? 0 : cpu_to_le32(pp->pkt_dma + i + 4);
324 i += 4;
325
326 VPRINTK("PRD[%u] = (0x%lX, 0x%X)\n", nelem,
327 (unsigned long)addr, len);
328 }
329 return i;
330}
331
332static void adma_qc_prep(struct ata_queued_cmd *qc)
333{
334 struct adma_port_priv *pp = qc->ap->private_data;
335 u8 *buf = pp->pkt;
336 u32 pkt_dma = (u32)pp->pkt_dma;
337 int i = 0;
338
339 VPRINTK("ENTER\n");
340
341 adma_enter_reg_mode(qc->ap);
342 if (qc->tf.protocol != ATA_PROT_DMA) {
343 ata_qc_prep(qc);
344 return;
345 }
346
347 buf[i++] = 0; /* Response flags */
348 buf[i++] = 0; /* reserved */
349 buf[i++] = cVLD | cDAT | cIEN;
350 i++; /* cLEN, gets filled in below */
351
352 *(__le32 *)(buf+i) = cpu_to_le32(pkt_dma); /* cNCPB */
353 i += 4; /* cNCPB */
354 i += 4; /* cPRD, gets filled in below */
355
356 buf[i++] = 0; /* reserved */
357 buf[i++] = 0; /* reserved */
358 buf[i++] = 0; /* reserved */
359 buf[i++] = 0; /* reserved */
360
361 /* ATA registers; must be a multiple of 4 */
362 buf[i++] = qc->tf.device;
363 buf[i++] = ADMA_REGS_DEVICE;
364 if ((qc->tf.flags & ATA_TFLAG_LBA48)) {
365 buf[i++] = qc->tf.hob_nsect;
366 buf[i++] = ADMA_REGS_SECTOR_COUNT;
367 buf[i++] = qc->tf.hob_lbal;
368 buf[i++] = ADMA_REGS_LBA_LOW;
369 buf[i++] = qc->tf.hob_lbam;
370 buf[i++] = ADMA_REGS_LBA_MID;
371 buf[i++] = qc->tf.hob_lbah;
372 buf[i++] = ADMA_REGS_LBA_HIGH;
373 }
374 buf[i++] = qc->tf.nsect;
375 buf[i++] = ADMA_REGS_SECTOR_COUNT;
376 buf[i++] = qc->tf.lbal;
377 buf[i++] = ADMA_REGS_LBA_LOW;
378 buf[i++] = qc->tf.lbam;
379 buf[i++] = ADMA_REGS_LBA_MID;
380 buf[i++] = qc->tf.lbah;
381 buf[i++] = ADMA_REGS_LBA_HIGH;
382 buf[i++] = 0;
383 buf[i++] = ADMA_REGS_CONTROL;
384 buf[i++] = rIGN;
385 buf[i++] = 0;
386 buf[i++] = qc->tf.command;
387 buf[i++] = ADMA_REGS_COMMAND | rEND;
388
389 buf[3] = (i >> 3) - 2; /* cLEN */
390 *(__le32 *)(buf+8) = cpu_to_le32(pkt_dma + i); /* cPRD */
391
392 i = adma_fill_sg(qc);
393 wmb(); /* flush PRDs and pkt to memory */
394#if 0
395 /* dump out CPB + PRDs for debug */
396 {
397 int j, len = 0;
398 static char obuf[2048];
399 for (j = 0; j < i; ++j) {
400 len += sprintf(obuf+len, "%02x ", buf[j]);
401 if ((j & 7) == 7) {
402 printk("%s\n", obuf);
403 len = 0;
404 }
405 }
406 if (len)
407 printk("%s\n", obuf);
408 }
409#endif
410}
411
412static inline void adma_packet_start(struct ata_queued_cmd *qc)
413{
414 struct ata_port *ap = qc->ap;
415 void __iomem *chan = ADMA_REGS(ap->host_set->mmio_base, ap->port_no);
416
417 VPRINTK("ENTER, ap %p\n", ap);
418
419 /* fire up the ADMA engine */
420 writew(aPIOMD4 | aGO, chan + ADMA_CONTROL);
421}
422
423static int adma_qc_issue(struct ata_queued_cmd *qc)
424{
425 struct adma_port_priv *pp = qc->ap->private_data;
426
427 switch (qc->tf.protocol) {
428 case ATA_PROT_DMA:
429 pp->state = adma_state_pkt;
430 adma_packet_start(qc);
431 return 0;
432
433 case ATA_PROT_ATAPI_DMA:
434 BUG();
435 break;
436
437 default:
438 break;
439 }
440
441 pp->state = adma_state_mmio;
442 return ata_qc_issue_prot(qc);
443}
444
445static inline unsigned int adma_intr_pkt(struct ata_host_set *host_set)
446{
447 unsigned int handled = 0, port_no;
448 u8 __iomem *mmio_base = host_set->mmio_base;
449
450 for (port_no = 0; port_no < host_set->n_ports; ++port_no) {
451 struct ata_port *ap = host_set->ports[port_no];
452 struct adma_port_priv *pp;
453 struct ata_queued_cmd *qc;
454 void __iomem *chan = ADMA_REGS(mmio_base, port_no);
455 u8 status = readb(chan + ADMA_STATUS);
456
457 if (status == 0)
458 continue;
459 handled = 1;
460 adma_enter_reg_mode(ap);
461 if (ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))
462 continue;
463 pp = ap->private_data;
464 if (!pp || pp->state != adma_state_pkt)
465 continue;
466 qc = ata_qc_from_tag(ap, ap->active_tag);
467 if (qc && (!(qc->tf.ctl & ATA_NIEN))) {
468 unsigned int err_mask = 0;
469
470 if ((status & (aPERR | aPSD | aUIRQ)))
471 err_mask = AC_ERR_OTHER;
472 else if (pp->pkt[0] != cDONE)
473 err_mask = AC_ERR_OTHER;
474
475 ata_qc_complete(qc, err_mask);
476 }
477 }
478 return handled;
479}
480
481static inline unsigned int adma_intr_mmio(struct ata_host_set *host_set)
482{
483 unsigned int handled = 0, port_no;
484
485 for (port_no = 0; port_no < host_set->n_ports; ++port_no) {
486 struct ata_port *ap;
487 ap = host_set->ports[port_no];
488 if (ap && (!(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR)))) {
489 struct ata_queued_cmd *qc;
490 struct adma_port_priv *pp = ap->private_data;
491 if (!pp || pp->state != adma_state_mmio)
492 continue;
493 qc = ata_qc_from_tag(ap, ap->active_tag);
494 if (qc && (!(qc->tf.ctl & ATA_NIEN))) {
495
496 /* check main status, clearing INTRQ */
497 u8 status = ata_check_status(ap);
498 if ((status & ATA_BUSY))
499 continue;
500 DPRINTK("ata%u: protocol %d (dev_stat 0x%X)\n",
501 ap->id, qc->tf.protocol, status);
502
503 /* complete taskfile transaction */
504 pp->state = adma_state_idle;
505 ata_qc_complete(qc, ac_err_mask(status));
506 handled = 1;
507 }
508 }
509 }
510 return handled;
511}
512
513static irqreturn_t adma_intr(int irq, void *dev_instance, struct pt_regs *regs)
514{
515 struct ata_host_set *host_set = dev_instance;
516 unsigned int handled = 0;
517
518 VPRINTK("ENTER\n");
519
520 spin_lock(&host_set->lock);
521 handled = adma_intr_pkt(host_set) | adma_intr_mmio(host_set);
522 spin_unlock(&host_set->lock);
523
524 VPRINTK("EXIT\n");
525
526 return IRQ_RETVAL(handled);
527}
528
529static void adma_ata_setup_port(struct ata_ioports *port, unsigned long base)
530{
531 port->cmd_addr =
532 port->data_addr = base + 0x000;
533 port->error_addr =
534 port->feature_addr = base + 0x004;
535 port->nsect_addr = base + 0x008;
536 port->lbal_addr = base + 0x00c;
537 port->lbam_addr = base + 0x010;
538 port->lbah_addr = base + 0x014;
539 port->device_addr = base + 0x018;
540 port->status_addr =
541 port->command_addr = base + 0x01c;
542 port->altstatus_addr =
543 port->ctl_addr = base + 0x038;
544}
545
546static int adma_port_start(struct ata_port *ap)
547{
548 struct device *dev = ap->host_set->dev;
549 struct adma_port_priv *pp;
550 int rc;
551
552 rc = ata_port_start(ap);
553 if (rc)
554 return rc;
555 adma_enter_reg_mode(ap);
556 rc = -ENOMEM;
557 pp = kcalloc(1, sizeof(*pp), GFP_KERNEL);
558 if (!pp)
559 goto err_out;
560 pp->pkt = dma_alloc_coherent(dev, ADMA_PKT_BYTES, &pp->pkt_dma,
561 GFP_KERNEL);
562 if (!pp->pkt)
563 goto err_out_kfree;
564 /* paranoia? */
565 if ((pp->pkt_dma & 7) != 0) {
566 printk("bad alignment for pp->pkt_dma: %08x\n",
567 (u32)pp->pkt_dma);
568 dma_free_coherent(dev, ADMA_PKT_BYTES,
569 pp->pkt, pp->pkt_dma);
570 goto err_out_kfree;
571 }
572 memset(pp->pkt, 0, ADMA_PKT_BYTES);
573 ap->private_data = pp;
574 adma_reinit_engine(ap);
575 return 0;
576
577err_out_kfree:
578 kfree(pp);
579err_out:
580 ata_port_stop(ap);
581 return rc;
582}
583
584static void adma_port_stop(struct ata_port *ap)
585{
586 struct device *dev = ap->host_set->dev;
587 struct adma_port_priv *pp = ap->private_data;
588
589 adma_reset_engine(ADMA_REGS(ap->host_set->mmio_base, ap->port_no));
590 if (pp != NULL) {
591 ap->private_data = NULL;
592 if (pp->pkt != NULL)
593 dma_free_coherent(dev, ADMA_PKT_BYTES,
594 pp->pkt, pp->pkt_dma);
595 kfree(pp);
596 }
597 ata_port_stop(ap);
598}
599
600static void adma_host_stop(struct ata_host_set *host_set)
601{
602 unsigned int port_no;
603
604 for (port_no = 0; port_no < ADMA_PORTS; ++port_no)
605 adma_reset_engine(ADMA_REGS(host_set->mmio_base, port_no));
606
607 ata_pci_host_stop(host_set);
608}
609
610static void adma_host_init(unsigned int chip_id,
611 struct ata_probe_ent *probe_ent)
612{
613 unsigned int port_no;
614 void __iomem *mmio_base = probe_ent->mmio_base;
615
616 /* enable/lock aGO operation */
617 writeb(7, mmio_base + ADMA_MODE_LOCK);
618
619 /* reset the ADMA logic */
620 for (port_no = 0; port_no < ADMA_PORTS; ++port_no)
621 adma_reset_engine(ADMA_REGS(mmio_base, port_no));
622}
623
624static int adma_set_dma_masks(struct pci_dev *pdev, void __iomem *mmio_base)
625{
626 int rc;
627
628 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
629 if (rc) {
630 dev_printk(KERN_ERR, &pdev->dev,
631 "32-bit DMA enable failed\n");
632 return rc;
633 }
634 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
635 if (rc) {
636 dev_printk(KERN_ERR, &pdev->dev,
637 "32-bit consistent DMA enable failed\n");
638 return rc;
639 }
640 return 0;
641}
642
643static int adma_ata_init_one(struct pci_dev *pdev,
644 const struct pci_device_id *ent)
645{
646 static int printed_version;
647 struct ata_probe_ent *probe_ent = NULL;
648 void __iomem *mmio_base;
649 unsigned int board_idx = (unsigned int) ent->driver_data;
650 int rc, port_no;
651
652 if (!printed_version++)
653 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
654
655 rc = pci_enable_device(pdev);
656 if (rc)
657 return rc;
658
659 rc = pci_request_regions(pdev, DRV_NAME);
660 if (rc)
661 goto err_out;
662
663 if ((pci_resource_flags(pdev, 4) & IORESOURCE_MEM) == 0) {
664 rc = -ENODEV;
665 goto err_out_regions;
666 }
667
668 mmio_base = pci_iomap(pdev, 4, 0);
669 if (mmio_base == NULL) {
670 rc = -ENOMEM;
671 goto err_out_regions;
672 }
673
674 rc = adma_set_dma_masks(pdev, mmio_base);
675 if (rc)
676 goto err_out_iounmap;
677
678 probe_ent = kcalloc(1, sizeof(*probe_ent), GFP_KERNEL);
679 if (probe_ent == NULL) {
680 rc = -ENOMEM;
681 goto err_out_iounmap;
682 }
683
684 probe_ent->dev = pci_dev_to_dev(pdev);
685 INIT_LIST_HEAD(&probe_ent->node);
686
687 probe_ent->sht = adma_port_info[board_idx].sht;
688 probe_ent->host_flags = adma_port_info[board_idx].host_flags;
689 probe_ent->pio_mask = adma_port_info[board_idx].pio_mask;
690 probe_ent->mwdma_mask = adma_port_info[board_idx].mwdma_mask;
691 probe_ent->udma_mask = adma_port_info[board_idx].udma_mask;
692 probe_ent->port_ops = adma_port_info[board_idx].port_ops;
693
694 probe_ent->irq = pdev->irq;
695 probe_ent->irq_flags = SA_SHIRQ;
696 probe_ent->mmio_base = mmio_base;
697 probe_ent->n_ports = ADMA_PORTS;
698
699 for (port_no = 0; port_no < probe_ent->n_ports; ++port_no) {
700 adma_ata_setup_port(&probe_ent->port[port_no],
701 ADMA_ATA_REGS((unsigned long)mmio_base, port_no));
702 }
703
704 pci_set_master(pdev);
705
706 /* initialize adapter */
707 adma_host_init(board_idx, probe_ent);
708
709 rc = ata_device_add(probe_ent);
710 kfree(probe_ent);
711 if (rc != ADMA_PORTS)
712 goto err_out_iounmap;
713 return 0;
714
715err_out_iounmap:
716 pci_iounmap(pdev, mmio_base);
717err_out_regions:
718 pci_release_regions(pdev);
719err_out:
720 pci_disable_device(pdev);
721 return rc;
722}
723
724static int __init adma_ata_init(void)
725{
726 return pci_module_init(&adma_ata_pci_driver);
727}
728
729static void __exit adma_ata_exit(void)
730{
731 pci_unregister_driver(&adma_ata_pci_driver);
732}
733
734MODULE_AUTHOR("Mark Lord");
735MODULE_DESCRIPTION("Pacific Digital Corporation ADMA low-level driver");
736MODULE_LICENSE("GPL");
737MODULE_DEVICE_TABLE(pci, adma_ata_pci_tbl);
738MODULE_VERSION(DRV_VERSION);
739
740module_init(adma_ata_init);
741module_exit(adma_ata_exit);
diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index 1ed32e7b5472..e451941ad81d 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -52,7 +52,7 @@ extern int qla2x00_load_risc(struct scsi_qla_host *, uint32_t *);
52extern int qla24xx_load_risc_flash(scsi_qla_host_t *, uint32_t *); 52extern int qla24xx_load_risc_flash(scsi_qla_host_t *, uint32_t *);
53extern int qla24xx_load_risc_hotplug(scsi_qla_host_t *, uint32_t *); 53extern int qla24xx_load_risc_hotplug(scsi_qla_host_t *, uint32_t *);
54 54
55extern fc_port_t *qla2x00_alloc_fcport(scsi_qla_host_t *, int); 55extern fc_port_t *qla2x00_alloc_fcport(scsi_qla_host_t *, gfp_t);
56 56
57extern int qla2x00_loop_resync(scsi_qla_host_t *); 57extern int qla2x00_loop_resync(scsi_qla_host_t *);
58 58
@@ -277,7 +277,7 @@ extern int qla2x00_fdmi_register(scsi_qla_host_t *);
277/* 277/*
278 * Global Function Prototypes in qla_rscn.c source file. 278 * Global Function Prototypes in qla_rscn.c source file.
279 */ 279 */
280extern fc_port_t *qla2x00_alloc_rscn_fcport(scsi_qla_host_t *, int); 280extern fc_port_t *qla2x00_alloc_rscn_fcport(scsi_qla_host_t *, gfp_t);
281extern int qla2x00_handle_port_rscn(scsi_qla_host_t *, uint32_t, fc_port_t *, 281extern int qla2x00_handle_port_rscn(scsi_qla_host_t *, uint32_t, fc_port_t *,
282 int); 282 int);
283extern void qla2x00_process_iodesc(scsi_qla_host_t *, struct mbx_entry *); 283extern void qla2x00_process_iodesc(scsi_qla_host_t *, struct mbx_entry *);
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 23d095d3817b..fbb6feee40cf 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -1685,7 +1685,7 @@ qla2x00_nvram_config(scsi_qla_host_t *ha)
1685 * Returns a pointer to the allocated fcport, or NULL, if none available. 1685 * Returns a pointer to the allocated fcport, or NULL, if none available.
1686 */ 1686 */
1687fc_port_t * 1687fc_port_t *
1688qla2x00_alloc_fcport(scsi_qla_host_t *ha, int flags) 1688qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
1689{ 1689{
1690 fc_port_t *fcport; 1690 fc_port_t *fcport;
1691 1691
diff --git a/drivers/scsi/qla2xxx/qla_rscn.c b/drivers/scsi/qla2xxx/qla_rscn.c
index 1eba98828636..7534efcc8918 100644
--- a/drivers/scsi/qla2xxx/qla_rscn.c
+++ b/drivers/scsi/qla2xxx/qla_rscn.c
@@ -1066,7 +1066,7 @@ qla2x00_send_login_iocb_cb(scsi_qla_host_t *ha, struct io_descriptor *iodesc,
1066 * Returns a pointer to the allocated RSCN fcport, or NULL, if none available. 1066 * Returns a pointer to the allocated RSCN fcport, or NULL, if none available.
1067 */ 1067 */
1068fc_port_t * 1068fc_port_t *
1069qla2x00_alloc_rscn_fcport(scsi_qla_host_t *ha, int flags) 1069qla2x00_alloc_rscn_fcport(scsi_qla_host_t *ha, gfp_t flags)
1070{ 1070{
1071 fc_port_t *fcport; 1071 fc_port_t *fcport;
1072 1072
diff --git a/drivers/scsi/sata_mv.c b/drivers/scsi/sata_mv.c
index ea76fe44585e..46dbdee79f77 100644
--- a/drivers/scsi/sata_mv.c
+++ b/drivers/scsi/sata_mv.c
@@ -29,13 +29,14 @@
29#include <linux/interrupt.h> 29#include <linux/interrupt.h>
30#include <linux/sched.h> 30#include <linux/sched.h>
31#include <linux/dma-mapping.h> 31#include <linux/dma-mapping.h>
32#include <linux/device.h>
32#include "scsi.h" 33#include "scsi.h"
33#include <scsi/scsi_host.h> 34#include <scsi/scsi_host.h>
34#include <linux/libata.h> 35#include <linux/libata.h>
35#include <asm/io.h> 36#include <asm/io.h>
36 37
37#define DRV_NAME "sata_mv" 38#define DRV_NAME "sata_mv"
38#define DRV_VERSION "0.12" 39#define DRV_VERSION "0.25"
39 40
40enum { 41enum {
41 /* BAR's are enumerated in terms of pci_resource_start() terms */ 42 /* BAR's are enumerated in terms of pci_resource_start() terms */
@@ -55,31 +56,61 @@ enum {
55 MV_SATAHC_ARBTR_REG_SZ = MV_MINOR_REG_AREA_SZ, /* arbiter */ 56 MV_SATAHC_ARBTR_REG_SZ = MV_MINOR_REG_AREA_SZ, /* arbiter */
56 MV_PORT_REG_SZ = MV_MINOR_REG_AREA_SZ, 57 MV_PORT_REG_SZ = MV_MINOR_REG_AREA_SZ,
57 58
58 MV_Q_CT = 32, 59 MV_USE_Q_DEPTH = ATA_DEF_QUEUE,
59 MV_CRQB_SZ = 32,
60 MV_CRPB_SZ = 8,
61 60
62 MV_DMA_BOUNDARY = 0xffffffffU, 61 MV_MAX_Q_DEPTH = 32,
63 SATAHC_MASK = (~(MV_SATAHC_REG_SZ - 1)), 62 MV_MAX_Q_DEPTH_MASK = MV_MAX_Q_DEPTH - 1,
63
64 /* CRQB needs alignment on a 1KB boundary. Size == 1KB
65 * CRPB needs alignment on a 256B boundary. Size == 256B
66 * SG count of 176 leads to MV_PORT_PRIV_DMA_SZ == 4KB
67 * ePRD (SG) entries need alignment on a 16B boundary. Size == 16B
68 */
69 MV_CRQB_Q_SZ = (32 * MV_MAX_Q_DEPTH),
70 MV_CRPB_Q_SZ = (8 * MV_MAX_Q_DEPTH),
71 MV_MAX_SG_CT = 176,
72 MV_SG_TBL_SZ = (16 * MV_MAX_SG_CT),
73 MV_PORT_PRIV_DMA_SZ = (MV_CRQB_Q_SZ + MV_CRPB_Q_SZ + MV_SG_TBL_SZ),
74
75 /* Our DMA boundary is determined by an ePRD being unable to handle
76 * anything larger than 64KB
77 */
78 MV_DMA_BOUNDARY = 0xffffU,
64 79
65 MV_PORTS_PER_HC = 4, 80 MV_PORTS_PER_HC = 4,
66 /* == (port / MV_PORTS_PER_HC) to determine HC from 0-7 port */ 81 /* == (port / MV_PORTS_PER_HC) to determine HC from 0-7 port */
67 MV_PORT_HC_SHIFT = 2, 82 MV_PORT_HC_SHIFT = 2,
68 /* == (port % MV_PORTS_PER_HC) to determine port from 0-7 port */ 83 /* == (port % MV_PORTS_PER_HC) to determine hard port from 0-7 port */
69 MV_PORT_MASK = 3, 84 MV_PORT_MASK = 3,
70 85
71 /* Host Flags */ 86 /* Host Flags */
72 MV_FLAG_DUAL_HC = (1 << 30), /* two SATA Host Controllers */ 87 MV_FLAG_DUAL_HC = (1 << 30), /* two SATA Host Controllers */
73 MV_FLAG_IRQ_COALESCE = (1 << 29), /* IRQ coalescing capability */ 88 MV_FLAG_IRQ_COALESCE = (1 << 29), /* IRQ coalescing capability */
74 MV_FLAG_BDMA = (1 << 28), /* Basic DMA */ 89 MV_FLAG_GLBL_SFT_RST = (1 << 28), /* Global Soft Reset support */
90 MV_COMMON_FLAGS = (ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
91 ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO),
92 MV_6XXX_FLAGS = (MV_FLAG_IRQ_COALESCE |
93 MV_FLAG_GLBL_SFT_RST),
75 94
76 chip_504x = 0, 95 chip_504x = 0,
77 chip_508x = 1, 96 chip_508x = 1,
78 chip_604x = 2, 97 chip_604x = 2,
79 chip_608x = 3, 98 chip_608x = 3,
80 99
100 CRQB_FLAG_READ = (1 << 0),
101 CRQB_TAG_SHIFT = 1,
102 CRQB_CMD_ADDR_SHIFT = 8,
103 CRQB_CMD_CS = (0x2 << 11),
104 CRQB_CMD_LAST = (1 << 15),
105
106 CRPB_FLAG_STATUS_SHIFT = 8,
107
108 EPRD_FLAG_END_OF_TBL = (1 << 31),
109
81 /* PCI interface registers */ 110 /* PCI interface registers */
82 111
112 PCI_COMMAND_OFS = 0xc00,
113
83 PCI_MAIN_CMD_STS_OFS = 0xd30, 114 PCI_MAIN_CMD_STS_OFS = 0xd30,
84 STOP_PCI_MASTER = (1 << 2), 115 STOP_PCI_MASTER = (1 << 2),
85 PCI_MASTER_EMPTY = (1 << 3), 116 PCI_MASTER_EMPTY = (1 << 3),
@@ -111,20 +142,13 @@ enum {
111 HC_CFG_OFS = 0, 142 HC_CFG_OFS = 0,
112 143
113 HC_IRQ_CAUSE_OFS = 0x14, 144 HC_IRQ_CAUSE_OFS = 0x14,
114 CRBP_DMA_DONE = (1 << 0), /* shift by port # */ 145 CRPB_DMA_DONE = (1 << 0), /* shift by port # */
115 HC_IRQ_COAL = (1 << 4), /* IRQ coalescing */ 146 HC_IRQ_COAL = (1 << 4), /* IRQ coalescing */
116 DEV_IRQ = (1 << 8), /* shift by port # */ 147 DEV_IRQ = (1 << 8), /* shift by port # */
117 148
118 /* Shadow block registers */ 149 /* Shadow block registers */
119 SHD_PIO_DATA_OFS = 0x100, 150 SHD_BLK_OFS = 0x100,
120 SHD_FEA_ERR_OFS = 0x104, 151 SHD_CTL_AST_OFS = 0x20, /* ofs from SHD_BLK_OFS */
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 152
129 /* SATA registers */ 153 /* SATA registers */
130 SATA_STATUS_OFS = 0x300, /* ctrl, err regs follow status */ 154 SATA_STATUS_OFS = 0x300, /* ctrl, err regs follow status */
@@ -132,6 +156,11 @@ enum {
132 156
133 /* Port registers */ 157 /* Port registers */
134 EDMA_CFG_OFS = 0, 158 EDMA_CFG_OFS = 0,
159 EDMA_CFG_Q_DEPTH = 0, /* queueing disabled */
160 EDMA_CFG_NCQ = (1 << 5),
161 EDMA_CFG_NCQ_GO_ON_ERR = (1 << 14), /* continue on error */
162 EDMA_CFG_RD_BRST_EXT = (1 << 11), /* read burst 512B */
163 EDMA_CFG_WR_BUFF_LEN = (1 << 13), /* write buffer 512B */
135 164
136 EDMA_ERR_IRQ_CAUSE_OFS = 0x8, 165 EDMA_ERR_IRQ_CAUSE_OFS = 0x8,
137 EDMA_ERR_IRQ_MASK_OFS = 0xc, 166 EDMA_ERR_IRQ_MASK_OFS = 0xc,
@@ -161,33 +190,84 @@ enum {
161 EDMA_ERR_LNK_DATA_TX | 190 EDMA_ERR_LNK_DATA_TX |
162 EDMA_ERR_TRANS_PROTO), 191 EDMA_ERR_TRANS_PROTO),
163 192
193 EDMA_REQ_Q_BASE_HI_OFS = 0x10,
194 EDMA_REQ_Q_IN_PTR_OFS = 0x14, /* also contains BASE_LO */
195 EDMA_REQ_Q_BASE_LO_MASK = 0xfffffc00U,
196
197 EDMA_REQ_Q_OUT_PTR_OFS = 0x18,
198 EDMA_REQ_Q_PTR_SHIFT = 5,
199
200 EDMA_RSP_Q_BASE_HI_OFS = 0x1c,
201 EDMA_RSP_Q_IN_PTR_OFS = 0x20,
202 EDMA_RSP_Q_OUT_PTR_OFS = 0x24, /* also contains BASE_LO */
203 EDMA_RSP_Q_BASE_LO_MASK = 0xffffff00U,
204 EDMA_RSP_Q_PTR_SHIFT = 3,
205
164 EDMA_CMD_OFS = 0x28, 206 EDMA_CMD_OFS = 0x28,
165 EDMA_EN = (1 << 0), 207 EDMA_EN = (1 << 0),
166 EDMA_DS = (1 << 1), 208 EDMA_DS = (1 << 1),
167 ATA_RST = (1 << 2), 209 ATA_RST = (1 << 2),
168 210
169 /* BDMA is 6xxx part only */ 211 /* Host private flags (hp_flags) */
170 BDMA_CMD_OFS = 0x224, 212 MV_HP_FLAG_MSI = (1 << 0),
171 BDMA_START = (1 << 0),
172 213
173 MV_UNDEF = 0, 214 /* Port private flags (pp_flags) */
215 MV_PP_FLAG_EDMA_EN = (1 << 0),
216 MV_PP_FLAG_EDMA_DS_ACT = (1 << 1),
174}; 217};
175 218
176struct mv_port_priv { 219/* Command ReQuest Block: 32B */
220struct mv_crqb {
221 u32 sg_addr;
222 u32 sg_addr_hi;
223 u16 ctrl_flags;
224 u16 ata_cmd[11];
225};
177 226
227/* Command ResPonse Block: 8B */
228struct mv_crpb {
229 u16 id;
230 u16 flags;
231 u32 tmstmp;
178}; 232};
179 233
180struct mv_host_priv { 234/* EDMA Physical Region Descriptor (ePRD); A.K.A. SG */
235struct mv_sg {
236 u32 addr;
237 u32 flags_size;
238 u32 addr_hi;
239 u32 reserved;
240};
181 241
242struct mv_port_priv {
243 struct mv_crqb *crqb;
244 dma_addr_t crqb_dma;
245 struct mv_crpb *crpb;
246 dma_addr_t crpb_dma;
247 struct mv_sg *sg_tbl;
248 dma_addr_t sg_tbl_dma;
249
250 unsigned req_producer; /* cp of req_in_ptr */
251 unsigned rsp_consumer; /* cp of rsp_out_ptr */
252 u32 pp_flags;
253};
254
255struct mv_host_priv {
256 u32 hp_flags;
182}; 257};
183 258
184static void mv_irq_clear(struct ata_port *ap); 259static void mv_irq_clear(struct ata_port *ap);
185static u32 mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in); 260static 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); 261static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val);
187static void mv_phy_reset(struct ata_port *ap); 262static void mv_phy_reset(struct ata_port *ap);
188static int mv_master_reset(void __iomem *mmio_base); 263static void mv_host_stop(struct ata_host_set *host_set);
264static int mv_port_start(struct ata_port *ap);
265static void mv_port_stop(struct ata_port *ap);
266static void mv_qc_prep(struct ata_queued_cmd *qc);
267static int mv_qc_issue(struct ata_queued_cmd *qc);
189static irqreturn_t mv_interrupt(int irq, void *dev_instance, 268static irqreturn_t mv_interrupt(int irq, void *dev_instance,
190 struct pt_regs *regs); 269 struct pt_regs *regs);
270static void mv_eng_timeout(struct ata_port *ap);
191static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); 271static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
192 272
193static Scsi_Host_Template mv_sht = { 273static Scsi_Host_Template mv_sht = {
@@ -196,13 +276,13 @@ static Scsi_Host_Template mv_sht = {
196 .ioctl = ata_scsi_ioctl, 276 .ioctl = ata_scsi_ioctl,
197 .queuecommand = ata_scsi_queuecmd, 277 .queuecommand = ata_scsi_queuecmd,
198 .eh_strategy_handler = ata_scsi_error, 278 .eh_strategy_handler = ata_scsi_error,
199 .can_queue = ATA_DEF_QUEUE, 279 .can_queue = MV_USE_Q_DEPTH,
200 .this_id = ATA_SHT_THIS_ID, 280 .this_id = ATA_SHT_THIS_ID,
201 .sg_tablesize = MV_UNDEF, 281 .sg_tablesize = MV_MAX_SG_CT,
202 .max_sectors = ATA_MAX_SECTORS, 282 .max_sectors = ATA_MAX_SECTORS,
203 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 283 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
204 .emulated = ATA_SHT_EMULATED, 284 .emulated = ATA_SHT_EMULATED,
205 .use_clustering = MV_UNDEF, 285 .use_clustering = ATA_SHT_USE_CLUSTERING,
206 .proc_name = DRV_NAME, 286 .proc_name = DRV_NAME,
207 .dma_boundary = MV_DMA_BOUNDARY, 287 .dma_boundary = MV_DMA_BOUNDARY,
208 .slave_configure = ata_scsi_slave_config, 288 .slave_configure = ata_scsi_slave_config,
@@ -210,7 +290,7 @@ static Scsi_Host_Template mv_sht = {
210 .ordered_flush = 1, 290 .ordered_flush = 1,
211}; 291};
212 292
213static struct ata_port_operations mv_ops = { 293static const struct ata_port_operations mv_ops = {
214 .port_disable = ata_port_disable, 294 .port_disable = ata_port_disable,
215 295
216 .tf_load = ata_tf_load, 296 .tf_load = ata_tf_load,
@@ -221,10 +301,10 @@ static struct ata_port_operations mv_ops = {
221 301
222 .phy_reset = mv_phy_reset, 302 .phy_reset = mv_phy_reset,
223 303
224 .qc_prep = ata_qc_prep, 304 .qc_prep = mv_qc_prep,
225 .qc_issue = ata_qc_issue_prot, 305 .qc_issue = mv_qc_issue,
226 306
227 .eng_timeout = ata_eng_timeout, 307 .eng_timeout = mv_eng_timeout,
228 308
229 .irq_handler = mv_interrupt, 309 .irq_handler = mv_interrupt,
230 .irq_clear = mv_irq_clear, 310 .irq_clear = mv_irq_clear,
@@ -232,46 +312,39 @@ static struct ata_port_operations mv_ops = {
232 .scr_read = mv_scr_read, 312 .scr_read = mv_scr_read,
233 .scr_write = mv_scr_write, 313 .scr_write = mv_scr_write,
234 314
235 .port_start = ata_port_start, 315 .port_start = mv_port_start,
236 .port_stop = ata_port_stop, 316 .port_stop = mv_port_stop,
237 .host_stop = ata_host_stop, 317 .host_stop = mv_host_stop,
238}; 318};
239 319
240static struct ata_port_info mv_port_info[] = { 320static struct ata_port_info mv_port_info[] = {
241 { /* chip_504x */ 321 { /* chip_504x */
242 .sht = &mv_sht, 322 .sht = &mv_sht,
243 .host_flags = (ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 323 .host_flags = MV_COMMON_FLAGS,
244 ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO), 324 .pio_mask = 0x1f, /* pio0-4 */
245 .pio_mask = 0x1f, /* pio4-0 */ 325 .udma_mask = 0, /* 0x7f (udma0-6 disabled for now) */
246 .udma_mask = 0, /* 0x7f (udma6-0 disabled for now) */
247 .port_ops = &mv_ops, 326 .port_ops = &mv_ops,
248 }, 327 },
249 { /* chip_508x */ 328 { /* chip_508x */
250 .sht = &mv_sht, 329 .sht = &mv_sht,
251 .host_flags = (ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 330 .host_flags = (MV_COMMON_FLAGS | MV_FLAG_DUAL_HC),
252 ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO | 331 .pio_mask = 0x1f, /* pio0-4 */
253 MV_FLAG_DUAL_HC), 332 .udma_mask = 0, /* 0x7f (udma0-6 disabled for now) */
254 .pio_mask = 0x1f, /* pio4-0 */
255 .udma_mask = 0, /* 0x7f (udma6-0 disabled for now) */
256 .port_ops = &mv_ops, 333 .port_ops = &mv_ops,
257 }, 334 },
258 { /* chip_604x */ 335 { /* chip_604x */
259 .sht = &mv_sht, 336 .sht = &mv_sht,
260 .host_flags = (ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 337 .host_flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS),
261 ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO | 338 .pio_mask = 0x1f, /* pio0-4 */
262 MV_FLAG_IRQ_COALESCE | MV_FLAG_BDMA), 339 .udma_mask = 0x7f, /* udma0-6 */
263 .pio_mask = 0x1f, /* pio4-0 */
264 .udma_mask = 0, /* 0x7f (udma6-0 disabled for now) */
265 .port_ops = &mv_ops, 340 .port_ops = &mv_ops,
266 }, 341 },
267 { /* chip_608x */ 342 { /* chip_608x */
268 .sht = &mv_sht, 343 .sht = &mv_sht,
269 .host_flags = (ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 344 .host_flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS |
270 ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO | 345 MV_FLAG_DUAL_HC),
271 MV_FLAG_IRQ_COALESCE | MV_FLAG_DUAL_HC | 346 .pio_mask = 0x1f, /* pio0-4 */
272 MV_FLAG_BDMA), 347 .udma_mask = 0x7f, /* udma0-6 */
273 .pio_mask = 0x1f, /* pio4-0 */
274 .udma_mask = 0, /* 0x7f (udma6-0 disabled for now) */
275 .port_ops = &mv_ops, 348 .port_ops = &mv_ops,
276 }, 349 },
277}; 350};
@@ -306,12 +379,6 @@ static inline void writelfl(unsigned long data, void __iomem *addr)
306 (void) readl(addr); /* flush to avoid PCI posted write */ 379 (void) readl(addr); /* flush to avoid PCI posted write */
307} 380}
308 381
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) 382static inline void __iomem *mv_hc_base(void __iomem *base, unsigned int hc)
316{ 383{
317 return (base + MV_SATAHC0_REG_BASE + (hc * MV_SATAHC_REG_SZ)); 384 return (base + MV_SATAHC0_REG_BASE + (hc * MV_SATAHC_REG_SZ));
@@ -329,24 +396,150 @@ static inline void __iomem *mv_ap_base(struct ata_port *ap)
329 return mv_port_base(ap->host_set->mmio_base, ap->port_no); 396 return mv_port_base(ap->host_set->mmio_base, ap->port_no);
330} 397}
331 398
332static inline int mv_get_hc_count(unsigned long flags) 399static inline int mv_get_hc_count(unsigned long hp_flags)
333{ 400{
334 return ((flags & MV_FLAG_DUAL_HC) ? 2 : 1); 401 return ((hp_flags & MV_FLAG_DUAL_HC) ? 2 : 1);
335} 402}
336 403
337static inline int mv_is_edma_active(struct ata_port *ap) 404static void mv_irq_clear(struct ata_port *ap)
405{
406}
407
408/**
409 * mv_start_dma - Enable eDMA engine
410 * @base: port base address
411 * @pp: port private data
412 *
413 * Verify the local cache of the eDMA state is accurate with an
414 * assert.
415 *
416 * LOCKING:
417 * Inherited from caller.
418 */
419static void mv_start_dma(void __iomem *base, struct mv_port_priv *pp)
420{
421 if (!(MV_PP_FLAG_EDMA_EN & pp->pp_flags)) {
422 writelfl(EDMA_EN, base + EDMA_CMD_OFS);
423 pp->pp_flags |= MV_PP_FLAG_EDMA_EN;
424 }
425 assert(EDMA_EN & readl(base + EDMA_CMD_OFS));
426}
427
428/**
429 * mv_stop_dma - Disable eDMA engine
430 * @ap: ATA channel to manipulate
431 *
432 * Verify the local cache of the eDMA state is accurate with an
433 * assert.
434 *
435 * LOCKING:
436 * Inherited from caller.
437 */
438static void mv_stop_dma(struct ata_port *ap)
338{ 439{
339 void __iomem *port_mmio = mv_ap_base(ap); 440 void __iomem *port_mmio = mv_ap_base(ap);
340 return (EDMA_EN & readl(port_mmio + EDMA_CMD_OFS)); 441 struct mv_port_priv *pp = ap->private_data;
442 u32 reg;
443 int i;
444
445 if (MV_PP_FLAG_EDMA_EN & pp->pp_flags) {
446 /* Disable EDMA if active. The disable bit auto clears.
447 */
448 writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS);
449 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
450 } else {
451 assert(!(EDMA_EN & readl(port_mmio + EDMA_CMD_OFS)));
452 }
453
454 /* now properly wait for the eDMA to stop */
455 for (i = 1000; i > 0; i--) {
456 reg = readl(port_mmio + EDMA_CMD_OFS);
457 if (!(EDMA_EN & reg)) {
458 break;
459 }
460 udelay(100);
461 }
462
463 if (EDMA_EN & reg) {
464 printk(KERN_ERR "ata%u: Unable to stop eDMA\n", ap->id);
465 /* FIXME: Consider doing a reset here to recover */
466 }
341} 467}
342 468
343static inline int mv_port_bdma_capable(struct ata_port *ap) 469#ifdef ATA_DEBUG
470static void mv_dump_mem(void __iomem *start, unsigned bytes)
344{ 471{
345 return (ap->flags & MV_FLAG_BDMA); 472 int b, w;
473 for (b = 0; b < bytes; ) {
474 DPRINTK("%p: ", start + b);
475 for (w = 0; b < bytes && w < 4; w++) {
476 printk("%08x ",readl(start + b));
477 b += sizeof(u32);
478 }
479 printk("\n");
480 }
346} 481}
482#endif
347 483
348static void mv_irq_clear(struct ata_port *ap) 484static void mv_dump_pci_cfg(struct pci_dev *pdev, unsigned bytes)
485{
486#ifdef ATA_DEBUG
487 int b, w;
488 u32 dw;
489 for (b = 0; b < bytes; ) {
490 DPRINTK("%02x: ", b);
491 for (w = 0; b < bytes && w < 4; w++) {
492 (void) pci_read_config_dword(pdev,b,&dw);
493 printk("%08x ",dw);
494 b += sizeof(u32);
495 }
496 printk("\n");
497 }
498#endif
499}
500static void mv_dump_all_regs(void __iomem *mmio_base, int port,
501 struct pci_dev *pdev)
349{ 502{
503#ifdef ATA_DEBUG
504 void __iomem *hc_base = mv_hc_base(mmio_base,
505 port >> MV_PORT_HC_SHIFT);
506 void __iomem *port_base;
507 int start_port, num_ports, p, start_hc, num_hcs, hc;
508
509 if (0 > port) {
510 start_hc = start_port = 0;
511 num_ports = 8; /* shld be benign for 4 port devs */
512 num_hcs = 2;
513 } else {
514 start_hc = port >> MV_PORT_HC_SHIFT;
515 start_port = port;
516 num_ports = num_hcs = 1;
517 }
518 DPRINTK("All registers for port(s) %u-%u:\n", start_port,
519 num_ports > 1 ? num_ports - 1 : start_port);
520
521 if (NULL != pdev) {
522 DPRINTK("PCI config space regs:\n");
523 mv_dump_pci_cfg(pdev, 0x68);
524 }
525 DPRINTK("PCI regs:\n");
526 mv_dump_mem(mmio_base+0xc00, 0x3c);
527 mv_dump_mem(mmio_base+0xd00, 0x34);
528 mv_dump_mem(mmio_base+0xf00, 0x4);
529 mv_dump_mem(mmio_base+0x1d00, 0x6c);
530 for (hc = start_hc; hc < start_hc + num_hcs; hc++) {
531 hc_base = mv_hc_base(mmio_base, port >> MV_PORT_HC_SHIFT);
532 DPRINTK("HC regs (HC %i):\n", hc);
533 mv_dump_mem(hc_base, 0x1c);
534 }
535 for (p = start_port; p < start_port + num_ports; p++) {
536 port_base = mv_port_base(mmio_base, p);
537 DPRINTK("EDMA regs (port %i):\n",p);
538 mv_dump_mem(port_base, 0x54);
539 DPRINTK("SATA regs (port %i):\n",p);
540 mv_dump_mem(port_base+0x300, 0x60);
541 }
542#endif
350} 543}
351 544
352static unsigned int mv_scr_offset(unsigned int sc_reg_in) 545static unsigned int mv_scr_offset(unsigned int sc_reg_in)
@@ -389,30 +582,37 @@ static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val)
389 } 582 }
390} 583}
391 584
392static int mv_master_reset(void __iomem *mmio_base) 585/**
586 * mv_global_soft_reset - Perform the 6xxx global soft reset
587 * @mmio_base: base address of the HBA
588 *
589 * This routine only applies to 6xxx parts.
590 *
591 * LOCKING:
592 * Inherited from caller.
593 */
594static int mv_global_soft_reset(void __iomem *mmio_base)
393{ 595{
394 void __iomem *reg = mmio_base + PCI_MAIN_CMD_STS_OFS; 596 void __iomem *reg = mmio_base + PCI_MAIN_CMD_STS_OFS;
395 int i, rc = 0; 597 int i, rc = 0;
396 u32 t; 598 u32 t;
397 599
398 VPRINTK("ENTER\n");
399
400 /* Following procedure defined in PCI "main command and status 600 /* Following procedure defined in PCI "main command and status
401 * register" table. 601 * register" table.
402 */ 602 */
403 t = readl(reg); 603 t = readl(reg);
404 writel(t | STOP_PCI_MASTER, reg); 604 writel(t | STOP_PCI_MASTER, reg);
405 605
406 for (i = 0; i < 100; i++) { 606 for (i = 0; i < 1000; i++) {
407 msleep(10); 607 udelay(1);
408 t = readl(reg); 608 t = readl(reg);
409 if (PCI_MASTER_EMPTY & t) { 609 if (PCI_MASTER_EMPTY & t) {
410 break; 610 break;
411 } 611 }
412 } 612 }
413 if (!(PCI_MASTER_EMPTY & t)) { 613 if (!(PCI_MASTER_EMPTY & t)) {
414 printk(KERN_ERR DRV_NAME "PCI master won't flush\n"); 614 printk(KERN_ERR DRV_NAME ": PCI master won't flush\n");
415 rc = 1; /* broken HW? */ 615 rc = 1;
416 goto done; 616 goto done;
417 } 617 }
418 618
@@ -425,39 +625,399 @@ static int mv_master_reset(void __iomem *mmio_base)
425 } while (!(GLOB_SFT_RST & t) && (i-- > 0)); 625 } while (!(GLOB_SFT_RST & t) && (i-- > 0));
426 626
427 if (!(GLOB_SFT_RST & t)) { 627 if (!(GLOB_SFT_RST & t)) {
428 printk(KERN_ERR DRV_NAME "can't set global reset\n"); 628 printk(KERN_ERR DRV_NAME ": can't set global reset\n");
429 rc = 1; /* broken HW? */ 629 rc = 1;
430 goto done; 630 goto done;
431 } 631 }
432 632
433 /* clear reset */ 633 /* clear reset and *reenable the PCI master* (not mentioned in spec) */
434 i = 5; 634 i = 5;
435 do { 635 do {
436 writel(t & ~GLOB_SFT_RST, reg); 636 writel(t & ~(GLOB_SFT_RST | STOP_PCI_MASTER), reg);
437 t = readl(reg); 637 t = readl(reg);
438 udelay(1); 638 udelay(1);
439 } while ((GLOB_SFT_RST & t) && (i-- > 0)); 639 } while ((GLOB_SFT_RST & t) && (i-- > 0));
440 640
441 if (GLOB_SFT_RST & t) { 641 if (GLOB_SFT_RST & t) {
442 printk(KERN_ERR DRV_NAME "can't clear global reset\n"); 642 printk(KERN_ERR DRV_NAME ": can't clear global reset\n");
443 rc = 1; /* broken HW? */ 643 rc = 1;
444 } 644 }
445 645done:
446 done:
447 VPRINTK("EXIT, rc = %i\n", rc);
448 return rc; 646 return rc;
449} 647}
450 648
451static void mv_err_intr(struct ata_port *ap) 649/**
650 * mv_host_stop - Host specific cleanup/stop routine.
651 * @host_set: host data structure
652 *
653 * Disable ints, cleanup host memory, call general purpose
654 * host_stop.
655 *
656 * LOCKING:
657 * Inherited from caller.
658 */
659static void mv_host_stop(struct ata_host_set *host_set)
452{ 660{
453 void __iomem *port_mmio; 661 struct mv_host_priv *hpriv = host_set->private_data;
454 u32 edma_err_cause, serr = 0; 662 struct pci_dev *pdev = to_pci_dev(host_set->dev);
663
664 if (hpriv->hp_flags & MV_HP_FLAG_MSI) {
665 pci_disable_msi(pdev);
666 } else {
667 pci_intx(pdev, 0);
668 }
669 kfree(hpriv);
670 ata_host_stop(host_set);
671}
672
673/**
674 * mv_port_start - Port specific init/start routine.
675 * @ap: ATA channel to manipulate
676 *
677 * Allocate and point to DMA memory, init port private memory,
678 * zero indices.
679 *
680 * LOCKING:
681 * Inherited from caller.
682 */
683static int mv_port_start(struct ata_port *ap)
684{
685 struct device *dev = ap->host_set->dev;
686 struct mv_port_priv *pp;
687 void __iomem *port_mmio = mv_ap_base(ap);
688 void *mem;
689 dma_addr_t mem_dma;
690
691 pp = kmalloc(sizeof(*pp), GFP_KERNEL);
692 if (!pp) {
693 return -ENOMEM;
694 }
695 memset(pp, 0, sizeof(*pp));
696
697 mem = dma_alloc_coherent(dev, MV_PORT_PRIV_DMA_SZ, &mem_dma,
698 GFP_KERNEL);
699 if (!mem) {
700 kfree(pp);
701 return -ENOMEM;
702 }
703 memset(mem, 0, MV_PORT_PRIV_DMA_SZ);
704
705 /* First item in chunk of DMA memory:
706 * 32-slot command request table (CRQB), 32 bytes each in size
707 */
708 pp->crqb = mem;
709 pp->crqb_dma = mem_dma;
710 mem += MV_CRQB_Q_SZ;
711 mem_dma += MV_CRQB_Q_SZ;
712
713 /* Second item:
714 * 32-slot command response table (CRPB), 8 bytes each in size
715 */
716 pp->crpb = mem;
717 pp->crpb_dma = mem_dma;
718 mem += MV_CRPB_Q_SZ;
719 mem_dma += MV_CRPB_Q_SZ;
720
721 /* Third item:
722 * Table of scatter-gather descriptors (ePRD), 16 bytes each
723 */
724 pp->sg_tbl = mem;
725 pp->sg_tbl_dma = mem_dma;
726
727 writelfl(EDMA_CFG_Q_DEPTH | EDMA_CFG_RD_BRST_EXT |
728 EDMA_CFG_WR_BUFF_LEN, port_mmio + EDMA_CFG_OFS);
455 729
456 /* bug here b/c we got an err int on a port we don't know about, 730 writel((pp->crqb_dma >> 16) >> 16, port_mmio + EDMA_REQ_Q_BASE_HI_OFS);
457 * so there's no way to clear it 731 writelfl(pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK,
732 port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
733
734 writelfl(0, port_mmio + EDMA_REQ_Q_OUT_PTR_OFS);
735 writelfl(0, port_mmio + EDMA_RSP_Q_IN_PTR_OFS);
736
737 writel((pp->crpb_dma >> 16) >> 16, port_mmio + EDMA_RSP_Q_BASE_HI_OFS);
738 writelfl(pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK,
739 port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
740
741 pp->req_producer = pp->rsp_consumer = 0;
742
743 /* Don't turn on EDMA here...do it before DMA commands only. Else
744 * we'll be unable to send non-data, PIO, etc due to restricted access
745 * to shadow regs.
458 */ 746 */
459 BUG_ON(NULL == ap); 747 ap->private_data = pp;
460 port_mmio = mv_ap_base(ap); 748 return 0;
749}
750
751/**
752 * mv_port_stop - Port specific cleanup/stop routine.
753 * @ap: ATA channel to manipulate
754 *
755 * Stop DMA, cleanup port memory.
756 *
757 * LOCKING:
758 * This routine uses the host_set lock to protect the DMA stop.
759 */
760static void mv_port_stop(struct ata_port *ap)
761{
762 struct device *dev = ap->host_set->dev;
763 struct mv_port_priv *pp = ap->private_data;
764 unsigned long flags;
765
766 spin_lock_irqsave(&ap->host_set->lock, flags);
767 mv_stop_dma(ap);
768 spin_unlock_irqrestore(&ap->host_set->lock, flags);
769
770 ap->private_data = NULL;
771 dma_free_coherent(dev, MV_PORT_PRIV_DMA_SZ, pp->crpb, pp->crpb_dma);
772 kfree(pp);
773}
774
775/**
776 * mv_fill_sg - Fill out the Marvell ePRD (scatter gather) entries
777 * @qc: queued command whose SG list to source from
778 *
779 * Populate the SG list and mark the last entry.
780 *
781 * LOCKING:
782 * Inherited from caller.
783 */
784static void mv_fill_sg(struct ata_queued_cmd *qc)
785{
786 struct mv_port_priv *pp = qc->ap->private_data;
787 unsigned int i;
788
789 for (i = 0; i < qc->n_elem; i++) {
790 u32 sg_len;
791 dma_addr_t addr;
792
793 addr = sg_dma_address(&qc->sg[i]);
794 sg_len = sg_dma_len(&qc->sg[i]);
795
796 pp->sg_tbl[i].addr = cpu_to_le32(addr & 0xffffffff);
797 pp->sg_tbl[i].addr_hi = cpu_to_le32((addr >> 16) >> 16);
798 assert(0 == (sg_len & ~MV_DMA_BOUNDARY));
799 pp->sg_tbl[i].flags_size = cpu_to_le32(sg_len);
800 }
801 if (0 < qc->n_elem) {
802 pp->sg_tbl[qc->n_elem - 1].flags_size |=
803 cpu_to_le32(EPRD_FLAG_END_OF_TBL);
804 }
805}
806
807static inline unsigned mv_inc_q_index(unsigned *index)
808{
809 *index = (*index + 1) & MV_MAX_Q_DEPTH_MASK;
810 return *index;
811}
812
813static inline void mv_crqb_pack_cmd(u16 *cmdw, u8 data, u8 addr, unsigned last)
814{
815 *cmdw = data | (addr << CRQB_CMD_ADDR_SHIFT) | CRQB_CMD_CS |
816 (last ? CRQB_CMD_LAST : 0);
817}
818
819/**
820 * mv_qc_prep - Host specific command preparation.
821 * @qc: queued command to prepare
822 *
823 * This routine simply redirects to the general purpose routine
824 * if command is not DMA. Else, it handles prep of the CRQB
825 * (command request block), does some sanity checking, and calls
826 * the SG load routine.
827 *
828 * LOCKING:
829 * Inherited from caller.
830 */
831static void mv_qc_prep(struct ata_queued_cmd *qc)
832{
833 struct ata_port *ap = qc->ap;
834 struct mv_port_priv *pp = ap->private_data;
835 u16 *cw;
836 struct ata_taskfile *tf;
837 u16 flags = 0;
838
839 if (ATA_PROT_DMA != qc->tf.protocol) {
840 return;
841 }
842
843 /* the req producer index should be the same as we remember it */
844 assert(((readl(mv_ap_base(qc->ap) + EDMA_REQ_Q_IN_PTR_OFS) >>
845 EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) ==
846 pp->req_producer);
847
848 /* Fill in command request block
849 */
850 if (!(qc->tf.flags & ATA_TFLAG_WRITE)) {
851 flags |= CRQB_FLAG_READ;
852 }
853 assert(MV_MAX_Q_DEPTH > qc->tag);
854 flags |= qc->tag << CRQB_TAG_SHIFT;
855
856 pp->crqb[pp->req_producer].sg_addr =
857 cpu_to_le32(pp->sg_tbl_dma & 0xffffffff);
858 pp->crqb[pp->req_producer].sg_addr_hi =
859 cpu_to_le32((pp->sg_tbl_dma >> 16) >> 16);
860 pp->crqb[pp->req_producer].ctrl_flags = cpu_to_le16(flags);
861
862 cw = &pp->crqb[pp->req_producer].ata_cmd[0];
863 tf = &qc->tf;
864
865 /* Sadly, the CRQB cannot accomodate all registers--there are
866 * only 11 bytes...so we must pick and choose required
867 * registers based on the command. So, we drop feature and
868 * hob_feature for [RW] DMA commands, but they are needed for
869 * NCQ. NCQ will drop hob_nsect.
870 */
871 switch (tf->command) {
872 case ATA_CMD_READ:
873 case ATA_CMD_READ_EXT:
874 case ATA_CMD_WRITE:
875 case ATA_CMD_WRITE_EXT:
876 mv_crqb_pack_cmd(cw++, tf->hob_nsect, ATA_REG_NSECT, 0);
877 break;
878#ifdef LIBATA_NCQ /* FIXME: remove this line when NCQ added */
879 case ATA_CMD_FPDMA_READ:
880 case ATA_CMD_FPDMA_WRITE:
881 mv_crqb_pack_cmd(cw++, tf->hob_feature, ATA_REG_FEATURE, 0);
882 mv_crqb_pack_cmd(cw++, tf->feature, ATA_REG_FEATURE, 0);
883 break;
884#endif /* FIXME: remove this line when NCQ added */
885 default:
886 /* The only other commands EDMA supports in non-queued and
887 * non-NCQ mode are: [RW] STREAM DMA and W DMA FUA EXT, none
888 * of which are defined/used by Linux. If we get here, this
889 * driver needs work.
890 *
891 * FIXME: modify libata to give qc_prep a return value and
892 * return error here.
893 */
894 BUG_ON(tf->command);
895 break;
896 }
897 mv_crqb_pack_cmd(cw++, tf->nsect, ATA_REG_NSECT, 0);
898 mv_crqb_pack_cmd(cw++, tf->hob_lbal, ATA_REG_LBAL, 0);
899 mv_crqb_pack_cmd(cw++, tf->lbal, ATA_REG_LBAL, 0);
900 mv_crqb_pack_cmd(cw++, tf->hob_lbam, ATA_REG_LBAM, 0);
901 mv_crqb_pack_cmd(cw++, tf->lbam, ATA_REG_LBAM, 0);
902 mv_crqb_pack_cmd(cw++, tf->hob_lbah, ATA_REG_LBAH, 0);
903 mv_crqb_pack_cmd(cw++, tf->lbah, ATA_REG_LBAH, 0);
904 mv_crqb_pack_cmd(cw++, tf->device, ATA_REG_DEVICE, 0);
905 mv_crqb_pack_cmd(cw++, tf->command, ATA_REG_CMD, 1); /* last */
906
907 if (!(qc->flags & ATA_QCFLAG_DMAMAP)) {
908 return;
909 }
910 mv_fill_sg(qc);
911}
912
913/**
914 * mv_qc_issue - Initiate a command to the host
915 * @qc: queued command to start
916 *
917 * This routine simply redirects to the general purpose routine
918 * if command is not DMA. Else, it sanity checks our local
919 * caches of the request producer/consumer indices then enables
920 * DMA and bumps the request producer index.
921 *
922 * LOCKING:
923 * Inherited from caller.
924 */
925static int mv_qc_issue(struct ata_queued_cmd *qc)
926{
927 void __iomem *port_mmio = mv_ap_base(qc->ap);
928 struct mv_port_priv *pp = qc->ap->private_data;
929 u32 in_ptr;
930
931 if (ATA_PROT_DMA != qc->tf.protocol) {
932 /* We're about to send a non-EDMA capable command to the
933 * port. Turn off EDMA so there won't be problems accessing
934 * shadow block, etc registers.
935 */
936 mv_stop_dma(qc->ap);
937 return ata_qc_issue_prot(qc);
938 }
939
940 in_ptr = readl(port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
941
942 /* the req producer index should be the same as we remember it */
943 assert(((in_ptr >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) ==
944 pp->req_producer);
945 /* until we do queuing, the queue should be empty at this point */
946 assert(((in_ptr >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) ==
947 ((readl(port_mmio + EDMA_REQ_Q_OUT_PTR_OFS) >>
948 EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK));
949
950 mv_inc_q_index(&pp->req_producer); /* now incr producer index */
951
952 mv_start_dma(port_mmio, pp);
953
954 /* and write the request in pointer to kick the EDMA to life */
955 in_ptr &= EDMA_REQ_Q_BASE_LO_MASK;
956 in_ptr |= pp->req_producer << EDMA_REQ_Q_PTR_SHIFT;
957 writelfl(in_ptr, port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
958
959 return 0;
960}
961
962/**
963 * mv_get_crpb_status - get status from most recently completed cmd
964 * @ap: ATA channel to manipulate
965 *
966 * This routine is for use when the port is in DMA mode, when it
967 * will be using the CRPB (command response block) method of
968 * returning command completion information. We assert indices
969 * are good, grab status, and bump the response consumer index to
970 * prove that we're up to date.
971 *
972 * LOCKING:
973 * Inherited from caller.
974 */
975static u8 mv_get_crpb_status(struct ata_port *ap)
976{
977 void __iomem *port_mmio = mv_ap_base(ap);
978 struct mv_port_priv *pp = ap->private_data;
979 u32 out_ptr;
980
981 out_ptr = readl(port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
982
983 /* the response consumer index should be the same as we remember it */
984 assert(((out_ptr >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) ==
985 pp->rsp_consumer);
986
987 /* increment our consumer index... */
988 pp->rsp_consumer = mv_inc_q_index(&pp->rsp_consumer);
989
990 /* and, until we do NCQ, there should only be 1 CRPB waiting */
991 assert(((readl(port_mmio + EDMA_RSP_Q_IN_PTR_OFS) >>
992 EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) ==
993 pp->rsp_consumer);
994
995 /* write out our inc'd consumer index so EDMA knows we're caught up */
996 out_ptr &= EDMA_RSP_Q_BASE_LO_MASK;
997 out_ptr |= pp->rsp_consumer << EDMA_RSP_Q_PTR_SHIFT;
998 writelfl(out_ptr, port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
999
1000 /* Return ATA status register for completed CRPB */
1001 return (pp->crpb[pp->rsp_consumer].flags >> CRPB_FLAG_STATUS_SHIFT);
1002}
1003
1004/**
1005 * mv_err_intr - Handle error interrupts on the port
1006 * @ap: ATA channel to manipulate
1007 *
1008 * In most cases, just clear the interrupt and move on. However,
1009 * some cases require an eDMA reset, which is done right before
1010 * the COMRESET in mv_phy_reset(). The SERR case requires a
1011 * clear of pending errors in the SATA SERROR register. Finally,
1012 * if the port disabled DMA, update our cached copy to match.
1013 *
1014 * LOCKING:
1015 * Inherited from caller.
1016 */
1017static void mv_err_intr(struct ata_port *ap)
1018{
1019 void __iomem *port_mmio = mv_ap_base(ap);
1020 u32 edma_err_cause, serr = 0;
461 1021
462 edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 1022 edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
463 1023
@@ -465,8 +1025,12 @@ static void mv_err_intr(struct ata_port *ap)
465 serr = scr_read(ap, SCR_ERROR); 1025 serr = scr_read(ap, SCR_ERROR);
466 scr_write_flush(ap, SCR_ERROR, serr); 1026 scr_write_flush(ap, SCR_ERROR, serr);
467 } 1027 }
468 DPRINTK("port %u error; EDMA err cause: 0x%08x SERR: 0x%08x\n", 1028 if (EDMA_ERR_SELF_DIS & edma_err_cause) {
469 ap->port_no, edma_err_cause, serr); 1029 struct mv_port_priv *pp = ap->private_data;
1030 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
1031 }
1032 DPRINTK(KERN_ERR "ata%u: port error; EDMA err cause: 0x%08x "
1033 "SERR: 0x%08x\n", ap->id, edma_err_cause, serr);
470 1034
471 /* Clear EDMA now that SERR cleanup done */ 1035 /* Clear EDMA now that SERR cleanup done */
472 writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 1036 writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
@@ -477,7 +1041,21 @@ static void mv_err_intr(struct ata_port *ap)
477 } 1041 }
478} 1042}
479 1043
480/* Handle any outstanding interrupts in a single SATAHC 1044/**
1045 * mv_host_intr - Handle all interrupts on the given host controller
1046 * @host_set: host specific structure
1047 * @relevant: port error bits relevant to this host controller
1048 * @hc: which host controller we're to look at
1049 *
1050 * Read then write clear the HC interrupt status then walk each
1051 * port connected to the HC and see if it needs servicing. Port
1052 * success ints are reported in the HC interrupt status reg, the
1053 * port error ints are reported in the higher level main
1054 * interrupt status register and thus are passed in via the
1055 * 'relevant' argument.
1056 *
1057 * LOCKING:
1058 * Inherited from caller.
481 */ 1059 */
482static void mv_host_intr(struct ata_host_set *host_set, u32 relevant, 1060static void mv_host_intr(struct ata_host_set *host_set, u32 relevant,
483 unsigned int hc) 1061 unsigned int hc)
@@ -487,8 +1065,9 @@ static void mv_host_intr(struct ata_host_set *host_set, u32 relevant,
487 struct ata_port *ap; 1065 struct ata_port *ap;
488 struct ata_queued_cmd *qc; 1066 struct ata_queued_cmd *qc;
489 u32 hc_irq_cause; 1067 u32 hc_irq_cause;
490 int shift, port, port0, hard_port; 1068 int shift, port, port0, hard_port, handled;
491 u8 ata_status; 1069 unsigned int err_mask;
1070 u8 ata_status = 0;
492 1071
493 if (hc == 0) { 1072 if (hc == 0) {
494 port0 = 0; 1073 port0 = 0;
@@ -499,7 +1078,7 @@ static void mv_host_intr(struct ata_host_set *host_set, u32 relevant,
499 /* we'll need the HC success int register in most cases */ 1078 /* we'll need the HC success int register in most cases */
500 hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS); 1079 hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS);
501 if (hc_irq_cause) { 1080 if (hc_irq_cause) {
502 writelfl(0, hc_mmio + HC_IRQ_CAUSE_OFS); 1081 writelfl(~hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS);
503 } 1082 }
504 1083
505 VPRINTK("ENTER, hc%u relevant=0x%08x HC IRQ cause=0x%08x\n", 1084 VPRINTK("ENTER, hc%u relevant=0x%08x HC IRQ cause=0x%08x\n",
@@ -508,54 +1087,70 @@ static void mv_host_intr(struct ata_host_set *host_set, u32 relevant,
508 for (port = port0; port < port0 + MV_PORTS_PER_HC; port++) { 1087 for (port = port0; port < port0 + MV_PORTS_PER_HC; port++) {
509 ap = host_set->ports[port]; 1088 ap = host_set->ports[port];
510 hard_port = port & MV_PORT_MASK; /* range 0-3 */ 1089 hard_port = port & MV_PORT_MASK; /* range 0-3 */
511 ata_status = 0xffU; 1090 handled = 0; /* ensure ata_status is set if handled++ */
512 1091
513 if (((CRBP_DMA_DONE | DEV_IRQ) << hard_port) & hc_irq_cause) { 1092 if ((CRPB_DMA_DONE << hard_port) & hc_irq_cause) {
514 BUG_ON(NULL == ap); 1093 /* new CRPB on the queue; just one at a time until NCQ
515 /* rcv'd new resp, basic DMA complete, or ATA IRQ */ 1094 */
516 /* This is needed to clear the ATA INTRQ. 1095 ata_status = mv_get_crpb_status(ap);
517 * FIXME: don't read the status reg in EDMA mode! 1096 handled++;
1097 } else if ((DEV_IRQ << hard_port) & hc_irq_cause) {
1098 /* received ATA IRQ; read the status reg to clear INTRQ
518 */ 1099 */
519 ata_status = readb((void __iomem *) 1100 ata_status = readb((void __iomem *)
520 ap->ioaddr.status_addr); 1101 ap->ioaddr.status_addr);
1102 handled++;
521 } 1103 }
522 1104
523 shift = port * 2; 1105 err_mask = ac_err_mask(ata_status);
1106
1107 shift = port << 1; /* (port * 2) */
524 if (port >= MV_PORTS_PER_HC) { 1108 if (port >= MV_PORTS_PER_HC) {
525 shift++; /* skip bit 8 in the HC Main IRQ reg */ 1109 shift++; /* skip bit 8 in the HC Main IRQ reg */
526 } 1110 }
527 if ((PORT0_ERR << shift) & relevant) { 1111 if ((PORT0_ERR << shift) & relevant) {
528 mv_err_intr(ap); 1112 mv_err_intr(ap);
529 /* FIXME: smart to OR in ATA_ERR? */ 1113 err_mask |= AC_ERR_OTHER;
530 ata_status = readb((void __iomem *) 1114 handled++;
531 ap->ioaddr.status_addr) | ATA_ERR;
532 } 1115 }
533 1116
534 if (ap) { 1117 if (handled && ap) {
535 qc = ata_qc_from_tag(ap, ap->active_tag); 1118 qc = ata_qc_from_tag(ap, ap->active_tag);
536 if (NULL != qc) { 1119 if (NULL != qc) {
537 VPRINTK("port %u IRQ found for qc, " 1120 VPRINTK("port %u IRQ found for qc, "
538 "ata_status 0x%x\n", port,ata_status); 1121 "ata_status 0x%x\n", port,ata_status);
539 BUG_ON(0xffU == ata_status);
540 /* mark qc status appropriately */ 1122 /* mark qc status appropriately */
541 ata_qc_complete(qc, ata_status); 1123 ata_qc_complete(qc, err_mask);
542 } 1124 }
543 } 1125 }
544 } 1126 }
545 VPRINTK("EXIT\n"); 1127 VPRINTK("EXIT\n");
546} 1128}
547 1129
1130/**
1131 * mv_interrupt -
1132 * @irq: unused
1133 * @dev_instance: private data; in this case the host structure
1134 * @regs: unused
1135 *
1136 * Read the read only register to determine if any host
1137 * controllers have pending interrupts. If so, call lower level
1138 * routine to handle. Also check for PCI errors which are only
1139 * reported here.
1140 *
1141 * LOCKING:
1142 * This routine holds the host_set lock while processing pending
1143 * interrupts.
1144 */
548static irqreturn_t mv_interrupt(int irq, void *dev_instance, 1145static irqreturn_t mv_interrupt(int irq, void *dev_instance,
549 struct pt_regs *regs) 1146 struct pt_regs *regs)
550{ 1147{
551 struct ata_host_set *host_set = dev_instance; 1148 struct ata_host_set *host_set = dev_instance;
552 unsigned int hc, handled = 0, n_hcs; 1149 unsigned int hc, handled = 0, n_hcs;
553 void __iomem *mmio; 1150 void __iomem *mmio = host_set->mmio_base;
554 u32 irq_stat; 1151 u32 irq_stat;
555 1152
556 mmio = host_set->mmio_base;
557 irq_stat = readl(mmio + HC_MAIN_IRQ_CAUSE_OFS); 1153 irq_stat = readl(mmio + HC_MAIN_IRQ_CAUSE_OFS);
558 n_hcs = mv_get_hc_count(host_set->ports[0]->flags);
559 1154
560 /* check the cases where we either have nothing pending or have read 1155 /* 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 1156 * a bogus register value which can indicate HW removal or PCI fault
@@ -564,64 +1159,89 @@ static irqreturn_t mv_interrupt(int irq, void *dev_instance,
564 return IRQ_NONE; 1159 return IRQ_NONE;
565 } 1160 }
566 1161
1162 n_hcs = mv_get_hc_count(host_set->ports[0]->flags);
567 spin_lock(&host_set->lock); 1163 spin_lock(&host_set->lock);
568 1164
569 for (hc = 0; hc < n_hcs; hc++) { 1165 for (hc = 0; hc < n_hcs; hc++) {
570 u32 relevant = irq_stat & (HC0_IRQ_PEND << (hc * HC_SHIFT)); 1166 u32 relevant = irq_stat & (HC0_IRQ_PEND << (hc * HC_SHIFT));
571 if (relevant) { 1167 if (relevant) {
572 mv_host_intr(host_set, relevant, hc); 1168 mv_host_intr(host_set, relevant, hc);
573 handled = 1; 1169 handled++;
574 } 1170 }
575 } 1171 }
576 if (PCI_ERR & irq_stat) { 1172 if (PCI_ERR & irq_stat) {
577 /* FIXME: these are all masked by default, but still need 1173 printk(KERN_ERR DRV_NAME ": PCI ERROR; PCI IRQ cause=0x%08x\n",
578 * to recover from them properly. 1174 readl(mmio + PCI_IRQ_CAUSE_OFS));
579 */
580 }
581 1175
1176 DPRINTK("All regs @ PCI error\n");
1177 mv_dump_all_regs(mmio, -1, to_pci_dev(host_set->dev));
1178
1179 writelfl(0, mmio + PCI_IRQ_CAUSE_OFS);
1180 handled++;
1181 }
582 spin_unlock(&host_set->lock); 1182 spin_unlock(&host_set->lock);
583 1183
584 return IRQ_RETVAL(handled); 1184 return IRQ_RETVAL(handled);
585} 1185}
586 1186
1187/**
1188 * mv_phy_reset - Perform eDMA reset followed by COMRESET
1189 * @ap: ATA channel to manipulate
1190 *
1191 * Part of this is taken from __sata_phy_reset and modified to
1192 * not sleep since this routine gets called from interrupt level.
1193 *
1194 * LOCKING:
1195 * Inherited from caller. This is coded to safe to call at
1196 * interrupt level, i.e. it does not sleep.
1197 */
587static void mv_phy_reset(struct ata_port *ap) 1198static void mv_phy_reset(struct ata_port *ap)
588{ 1199{
589 void __iomem *port_mmio = mv_ap_base(ap); 1200 void __iomem *port_mmio = mv_ap_base(ap);
590 struct ata_taskfile tf; 1201 struct ata_taskfile tf;
591 struct ata_device *dev = &ap->device[0]; 1202 struct ata_device *dev = &ap->device[0];
592 u32 edma = 0, bdma; 1203 unsigned long timeout;
593 1204
594 VPRINTK("ENTER, port %u, mmio 0x%p\n", ap->port_no, port_mmio); 1205 VPRINTK("ENTER, port %u, mmio 0x%p\n", ap->port_no, port_mmio);
595 1206
596 edma = readl(port_mmio + EDMA_CMD_OFS); 1207 mv_stop_dma(ap);
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 1208
608 writelfl(edma | ATA_RST, port_mmio + EDMA_CMD_OFS); 1209 writelfl(ATA_RST, port_mmio + EDMA_CMD_OFS);
609 udelay(25); /* allow reset propagation */ 1210 udelay(25); /* allow reset propagation */
610 1211
611 /* Spec never mentions clearing the bit. Marvell's driver does 1212 /* Spec never mentions clearing the bit. Marvell's driver does
612 * clear the bit, however. 1213 * clear the bit, however.
613 */ 1214 */
614 writelfl(edma & ~ATA_RST, port_mmio + EDMA_CMD_OFS); 1215 writelfl(0, port_mmio + EDMA_CMD_OFS);
615 1216
616 VPRINTK("Done. Now calling __sata_phy_reset()\n"); 1217 VPRINTK("S-regs after ATA_RST: SStat 0x%08x SErr 0x%08x "
1218 "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS),
1219 mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL));
617 1220
618 /* proceed to init communications via the scr_control reg */ 1221 /* proceed to init communications via the scr_control reg */
619 __sata_phy_reset(ap); 1222 scr_write_flush(ap, SCR_CONTROL, 0x301);
1223 mdelay(1);
1224 scr_write_flush(ap, SCR_CONTROL, 0x300);
1225 timeout = jiffies + (HZ * 1);
1226 do {
1227 mdelay(10);
1228 if ((scr_read(ap, SCR_STATUS) & 0xf) != 1)
1229 break;
1230 } while (time_before(jiffies, timeout));
1231
1232 VPRINTK("S-regs after PHY wake: SStat 0x%08x SErr 0x%08x "
1233 "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS),
1234 mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL));
620 1235
621 if (ap->flags & ATA_FLAG_PORT_DISABLED) { 1236 if (sata_dev_present(ap)) {
622 VPRINTK("Port disabled pre-sig. Exiting.\n"); 1237 ata_port_probe(ap);
1238 } else {
1239 printk(KERN_INFO "ata%u: no device found (phy stat %08x)\n",
1240 ap->id, scr_read(ap, SCR_STATUS));
1241 ata_port_disable(ap);
623 return; 1242 return;
624 } 1243 }
1244 ap->cbl = ATA_CBL_SATA;
625 1245
626 tf.lbah = readb((void __iomem *) ap->ioaddr.lbah_addr); 1246 tf.lbah = readb((void __iomem *) ap->ioaddr.lbah_addr);
627 tf.lbam = readb((void __iomem *) ap->ioaddr.lbam_addr); 1247 tf.lbam = readb((void __iomem *) ap->ioaddr.lbam_addr);
@@ -636,37 +1256,118 @@ static void mv_phy_reset(struct ata_port *ap)
636 VPRINTK("EXIT\n"); 1256 VPRINTK("EXIT\n");
637} 1257}
638 1258
639static void mv_port_init(struct ata_ioports *port, unsigned long base) 1259/**
1260 * mv_eng_timeout - Routine called by libata when SCSI times out I/O
1261 * @ap: ATA channel to manipulate
1262 *
1263 * Intent is to clear all pending error conditions, reset the
1264 * chip/bus, fail the command, and move on.
1265 *
1266 * LOCKING:
1267 * This routine holds the host_set lock while failing the command.
1268 */
1269static void mv_eng_timeout(struct ata_port *ap)
1270{
1271 struct ata_queued_cmd *qc;
1272 unsigned long flags;
1273
1274 printk(KERN_ERR "ata%u: Entering mv_eng_timeout\n",ap->id);
1275 DPRINTK("All regs @ start of eng_timeout\n");
1276 mv_dump_all_regs(ap->host_set->mmio_base, ap->port_no,
1277 to_pci_dev(ap->host_set->dev));
1278
1279 qc = ata_qc_from_tag(ap, ap->active_tag);
1280 printk(KERN_ERR "mmio_base %p ap %p qc %p scsi_cmnd %p &cmnd %p\n",
1281 ap->host_set->mmio_base, ap, qc, qc->scsicmd,
1282 &qc->scsicmd->cmnd);
1283
1284 mv_err_intr(ap);
1285 mv_phy_reset(ap);
1286
1287 if (!qc) {
1288 printk(KERN_ERR "ata%u: BUG: timeout without command\n",
1289 ap->id);
1290 } else {
1291 /* hack alert! We cannot use the supplied completion
1292 * function from inside the ->eh_strategy_handler() thread.
1293 * libata is the only user of ->eh_strategy_handler() in
1294 * any kernel, so the default scsi_done() assumes it is
1295 * not being called from the SCSI EH.
1296 */
1297 spin_lock_irqsave(&ap->host_set->lock, flags);
1298 qc->scsidone = scsi_finish_command;
1299 ata_qc_complete(qc, AC_ERR_OTHER);
1300 spin_unlock_irqrestore(&ap->host_set->lock, flags);
1301 }
1302}
1303
1304/**
1305 * mv_port_init - Perform some early initialization on a single port.
1306 * @port: libata data structure storing shadow register addresses
1307 * @port_mmio: base address of the port
1308 *
1309 * Initialize shadow register mmio addresses, clear outstanding
1310 * interrupts on the port, and unmask interrupts for the future
1311 * start of the port.
1312 *
1313 * LOCKING:
1314 * Inherited from caller.
1315 */
1316static void mv_port_init(struct ata_ioports *port, void __iomem *port_mmio)
640{ 1317{
641 /* PIO related setup */ 1318 unsigned long shd_base = (unsigned long) port_mmio + SHD_BLK_OFS;
642 port->data_addr = base + SHD_PIO_DATA_OFS; 1319 unsigned serr_ofs;
643 port->error_addr = port->feature_addr = base + SHD_FEA_ERR_OFS; 1320
644 port->nsect_addr = base + SHD_SECT_CNT_OFS; 1321 /* PIO related setup
645 port->lbal_addr = base + SHD_LBA_L_OFS; 1322 */
646 port->lbam_addr = base + SHD_LBA_M_OFS; 1323 port->data_addr = shd_base + (sizeof(u32) * ATA_REG_DATA);
647 port->lbah_addr = base + SHD_LBA_H_OFS; 1324 port->error_addr =
648 port->device_addr = base + SHD_DEV_HD_OFS; 1325 port->feature_addr = shd_base + (sizeof(u32) * ATA_REG_ERR);
649 port->status_addr = port->command_addr = base + SHD_CMD_STA_OFS; 1326 port->nsect_addr = shd_base + (sizeof(u32) * ATA_REG_NSECT);
650 port->altstatus_addr = port->ctl_addr = base + SHD_CTL_AST_OFS; 1327 port->lbal_addr = shd_base + (sizeof(u32) * ATA_REG_LBAL);
651 /* unused */ 1328 port->lbam_addr = shd_base + (sizeof(u32) * ATA_REG_LBAM);
1329 port->lbah_addr = shd_base + (sizeof(u32) * ATA_REG_LBAH);
1330 port->device_addr = shd_base + (sizeof(u32) * ATA_REG_DEVICE);
1331 port->status_addr =
1332 port->command_addr = shd_base + (sizeof(u32) * ATA_REG_STATUS);
1333 /* special case: control/altstatus doesn't have ATA_REG_ address */
1334 port->altstatus_addr = port->ctl_addr = shd_base + SHD_CTL_AST_OFS;
1335
1336 /* unused: */
652 port->cmd_addr = port->bmdma_addr = port->scr_addr = 0; 1337 port->cmd_addr = port->bmdma_addr = port->scr_addr = 0;
653 1338
1339 /* Clear any currently outstanding port interrupt conditions */
1340 serr_ofs = mv_scr_offset(SCR_ERROR);
1341 writelfl(readl(port_mmio + serr_ofs), port_mmio + serr_ofs);
1342 writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
1343
654 /* unmask all EDMA error interrupts */ 1344 /* unmask all EDMA error interrupts */
655 writel(~0, (void __iomem *)base + EDMA_ERR_IRQ_MASK_OFS); 1345 writelfl(~0, port_mmio + EDMA_ERR_IRQ_MASK_OFS);
656 1346
657 VPRINTK("EDMA cfg=0x%08x EDMA IRQ err cause/mask=0x%08x/0x%08x\n", 1347 VPRINTK("EDMA cfg=0x%08x EDMA IRQ err cause/mask=0x%08x/0x%08x\n",
658 readl((void __iomem *)base + EDMA_CFG_OFS), 1348 readl(port_mmio + EDMA_CFG_OFS),
659 readl((void __iomem *)base + EDMA_ERR_IRQ_CAUSE_OFS), 1349 readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS),
660 readl((void __iomem *)base + EDMA_ERR_IRQ_MASK_OFS)); 1350 readl(port_mmio + EDMA_ERR_IRQ_MASK_OFS));
661} 1351}
662 1352
1353/**
1354 * mv_host_init - Perform some early initialization of the host.
1355 * @probe_ent: early data struct representing the host
1356 *
1357 * If possible, do an early global reset of the host. Then do
1358 * our port init and clear/unmask all/relevant host interrupts.
1359 *
1360 * LOCKING:
1361 * Inherited from caller.
1362 */
663static int mv_host_init(struct ata_probe_ent *probe_ent) 1363static int mv_host_init(struct ata_probe_ent *probe_ent)
664{ 1364{
665 int rc = 0, n_hc, port, hc; 1365 int rc = 0, n_hc, port, hc;
666 void __iomem *mmio = probe_ent->mmio_base; 1366 void __iomem *mmio = probe_ent->mmio_base;
667 void __iomem *port_mmio; 1367 void __iomem *port_mmio;
668 1368
669 if (mv_master_reset(probe_ent->mmio_base)) { 1369 if ((MV_FLAG_GLBL_SFT_RST & probe_ent->host_flags) &&
1370 mv_global_soft_reset(probe_ent->mmio_base)) {
670 rc = 1; 1371 rc = 1;
671 goto done; 1372 goto done;
672 } 1373 }
@@ -676,17 +1377,27 @@ static int mv_host_init(struct ata_probe_ent *probe_ent)
676 1377
677 for (port = 0; port < probe_ent->n_ports; port++) { 1378 for (port = 0; port < probe_ent->n_ports; port++) {
678 port_mmio = mv_port_base(mmio, port); 1379 port_mmio = mv_port_base(mmio, port);
679 mv_port_init(&probe_ent->port[port], (unsigned long)port_mmio); 1380 mv_port_init(&probe_ent->port[port], port_mmio);
680 } 1381 }
681 1382
682 for (hc = 0; hc < n_hc; hc++) { 1383 for (hc = 0; hc < n_hc; hc++) {
683 VPRINTK("HC%i: HC config=0x%08x HC IRQ cause=0x%08x\n", hc, 1384 void __iomem *hc_mmio = mv_hc_base(mmio, hc);
684 readl(mv_hc_base(mmio, hc) + HC_CFG_OFS), 1385
685 readl(mv_hc_base(mmio, hc) + HC_IRQ_CAUSE_OFS)); 1386 VPRINTK("HC%i: HC config=0x%08x HC IRQ cause "
1387 "(before clear)=0x%08x\n", hc,
1388 readl(hc_mmio + HC_CFG_OFS),
1389 readl(hc_mmio + HC_IRQ_CAUSE_OFS));
1390
1391 /* Clear any currently outstanding hc interrupt conditions */
1392 writelfl(0, hc_mmio + HC_IRQ_CAUSE_OFS);
686 } 1393 }
687 1394
688 writel(~HC_MAIN_MASKED_IRQS, mmio + HC_MAIN_IRQ_MASK_OFS); 1395 /* Clear any currently outstanding host interrupt conditions */
689 writel(PCI_UNMASK_ALL_IRQS, mmio + PCI_IRQ_MASK_OFS); 1396 writelfl(0, mmio + PCI_IRQ_CAUSE_OFS);
1397
1398 /* and unmask interrupt generation for host regs */
1399 writelfl(PCI_UNMASK_ALL_IRQS, mmio + PCI_IRQ_MASK_OFS);
1400 writelfl(~HC_MAIN_MASKED_IRQS, mmio + HC_MAIN_IRQ_MASK_OFS);
690 1401
691 VPRINTK("HC MAIN IRQ cause/mask=0x%08x/0x%08x " 1402 VPRINTK("HC MAIN IRQ cause/mask=0x%08x/0x%08x "
692 "PCI int cause/mask=0x%08x/0x%08x\n", 1403 "PCI int cause/mask=0x%08x/0x%08x\n",
@@ -694,11 +1405,53 @@ static int mv_host_init(struct ata_probe_ent *probe_ent)
694 readl(mmio + HC_MAIN_IRQ_MASK_OFS), 1405 readl(mmio + HC_MAIN_IRQ_MASK_OFS),
695 readl(mmio + PCI_IRQ_CAUSE_OFS), 1406 readl(mmio + PCI_IRQ_CAUSE_OFS),
696 readl(mmio + PCI_IRQ_MASK_OFS)); 1407 readl(mmio + PCI_IRQ_MASK_OFS));
697 1408done:
698 done:
699 return rc; 1409 return rc;
700} 1410}
701 1411
1412/**
1413 * mv_print_info - Dump key info to kernel log for perusal.
1414 * @probe_ent: early data struct representing the host
1415 *
1416 * FIXME: complete this.
1417 *
1418 * LOCKING:
1419 * Inherited from caller.
1420 */
1421static void mv_print_info(struct ata_probe_ent *probe_ent)
1422{
1423 struct pci_dev *pdev = to_pci_dev(probe_ent->dev);
1424 struct mv_host_priv *hpriv = probe_ent->private_data;
1425 u8 rev_id, scc;
1426 const char *scc_s;
1427
1428 /* Use this to determine the HW stepping of the chip so we know
1429 * what errata to workaround
1430 */
1431 pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id);
1432
1433 pci_read_config_byte(pdev, PCI_CLASS_DEVICE, &scc);
1434 if (scc == 0)
1435 scc_s = "SCSI";
1436 else if (scc == 0x01)
1437 scc_s = "RAID";
1438 else
1439 scc_s = "unknown";
1440
1441 dev_printk(KERN_INFO, &pdev->dev,
1442 "%u slots %u ports %s mode IRQ via %s\n",
1443 (unsigned)MV_MAX_Q_DEPTH, probe_ent->n_ports,
1444 scc_s, (MV_HP_FLAG_MSI & hpriv->hp_flags) ? "MSI" : "INTx");
1445}
1446
1447/**
1448 * mv_init_one - handle a positive probe of a Marvell host
1449 * @pdev: PCI device found
1450 * @ent: PCI device ID entry for the matched host
1451 *
1452 * LOCKING:
1453 * Inherited from caller.
1454 */
702static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 1455static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
703{ 1456{
704 static int printed_version = 0; 1457 static int printed_version = 0;
@@ -706,15 +1459,10 @@ static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
706 struct mv_host_priv *hpriv; 1459 struct mv_host_priv *hpriv;
707 unsigned int board_idx = (unsigned int)ent->driver_data; 1460 unsigned int board_idx = (unsigned int)ent->driver_data;
708 void __iomem *mmio_base; 1461 void __iomem *mmio_base;
709 int pci_dev_busy = 0; 1462 int pci_dev_busy = 0, rc;
710 int rc;
711 1463
712 if (!printed_version++) { 1464 if (!printed_version++)
713 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 1465 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
714 }
715
716 VPRINTK("ENTER for PCI Bus:Slot.Func=%u:%u.%u\n", pdev->bus->number,
717 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
718 1466
719 rc = pci_enable_device(pdev); 1467 rc = pci_enable_device(pdev);
720 if (rc) { 1468 if (rc) {
@@ -727,8 +1475,6 @@ static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
727 goto err_out; 1475 goto err_out;
728 } 1476 }
729 1477
730 pci_intx(pdev, 1);
731
732 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL); 1478 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL);
733 if (probe_ent == NULL) { 1479 if (probe_ent == NULL) {
734 rc = -ENOMEM; 1480 rc = -ENOMEM;
@@ -739,8 +1485,7 @@ static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
739 probe_ent->dev = pci_dev_to_dev(pdev); 1485 probe_ent->dev = pci_dev_to_dev(pdev);
740 INIT_LIST_HEAD(&probe_ent->node); 1486 INIT_LIST_HEAD(&probe_ent->node);
741 1487
742 mmio_base = ioremap_nocache(pci_resource_start(pdev, MV_PRIMARY_BAR), 1488 mmio_base = pci_iomap(pdev, MV_PRIMARY_BAR, 0);
743 pci_resource_len(pdev, MV_PRIMARY_BAR));
744 if (mmio_base == NULL) { 1489 if (mmio_base == NULL) {
745 rc = -ENOMEM; 1490 rc = -ENOMEM;
746 goto err_out_free_ent; 1491 goto err_out_free_ent;
@@ -769,37 +1514,40 @@ static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
769 if (rc) { 1514 if (rc) {
770 goto err_out_hpriv; 1515 goto err_out_hpriv;
771 } 1516 }
772/* mv_print_info(probe_ent); */
773 1517
774 { 1518 /* Enable interrupts */
775 int b, w; 1519 if (pci_enable_msi(pdev) == 0) {
776 u32 dw[4]; /* hold a line of 16b */ 1520 hpriv->hp_flags |= MV_HP_FLAG_MSI;
777 VPRINTK("PCI config space:\n"); 1521 } else {
778 for (b = 0; b < 0x40; ) { 1522 pci_intx(pdev, 1);
779 for (w = 0; w < 4; w++) {
780 (void) pci_read_config_dword(pdev,b,&dw[w]);
781 b += sizeof(*dw);
782 }
783 VPRINTK("%08x %08x %08x %08x\n",
784 dw[0],dw[1],dw[2],dw[3]);
785 }
786 } 1523 }
787 1524
788 /* FIXME: check ata_device_add return value */ 1525 mv_dump_pci_cfg(pdev, 0x68);
789 ata_device_add(probe_ent); 1526 mv_print_info(probe_ent);
790 kfree(probe_ent); 1527
1528 if (ata_device_add(probe_ent) == 0) {
1529 rc = -ENODEV; /* No devices discovered */
1530 goto err_out_dev_add;
1531 }
791 1532
1533 kfree(probe_ent);
792 return 0; 1534 return 0;
793 1535
794 err_out_hpriv: 1536err_out_dev_add:
1537 if (MV_HP_FLAG_MSI & hpriv->hp_flags) {
1538 pci_disable_msi(pdev);
1539 } else {
1540 pci_intx(pdev, 0);
1541 }
1542err_out_hpriv:
795 kfree(hpriv); 1543 kfree(hpriv);
796 err_out_iounmap: 1544err_out_iounmap:
797 iounmap(mmio_base); 1545 pci_iounmap(pdev, mmio_base);
798 err_out_free_ent: 1546err_out_free_ent:
799 kfree(probe_ent); 1547 kfree(probe_ent);
800 err_out_regions: 1548err_out_regions:
801 pci_release_regions(pdev); 1549 pci_release_regions(pdev);
802 err_out: 1550err_out:
803 if (!pci_dev_busy) { 1551 if (!pci_dev_busy) {
804 pci_disable_device(pdev); 1552 pci_disable_device(pdev);
805 } 1553 }
diff --git a/drivers/scsi/sata_nv.c b/drivers/scsi/sata_nv.c
index cb832b03ec5e..d573888eda76 100644
--- a/drivers/scsi/sata_nv.c
+++ b/drivers/scsi/sata_nv.c
@@ -61,6 +61,7 @@
61#include <linux/blkdev.h> 61#include <linux/blkdev.h>
62#include <linux/delay.h> 62#include <linux/delay.h>
63#include <linux/interrupt.h> 63#include <linux/interrupt.h>
64#include <linux/device.h>
64#include "scsi.h" 65#include "scsi.h"
65#include <scsi/scsi_host.h> 66#include <scsi/scsi_host.h>
66#include <linux/libata.h> 67#include <linux/libata.h>
@@ -238,7 +239,7 @@ static Scsi_Host_Template nv_sht = {
238 .ordered_flush = 1, 239 .ordered_flush = 1,
239}; 240};
240 241
241static struct ata_port_operations nv_ops = { 242static const struct ata_port_operations nv_ops = {
242 .port_disable = ata_port_disable, 243 .port_disable = ata_port_disable,
243 .tf_load = ata_tf_load, 244 .tf_load = ata_tf_load,
244 .tf_read = ata_tf_read, 245 .tf_read = ata_tf_read,
@@ -331,7 +332,7 @@ static u32 nv_scr_read (struct ata_port *ap, unsigned int sc_reg)
331 return 0xffffffffU; 332 return 0xffffffffU;
332 333
333 if (host->host_flags & NV_HOST_FLAGS_SCR_MMIO) 334 if (host->host_flags & NV_HOST_FLAGS_SCR_MMIO)
334 return readl((void*)ap->ioaddr.scr_addr + (sc_reg * 4)); 335 return readl((void __iomem *)ap->ioaddr.scr_addr + (sc_reg * 4));
335 else 336 else
336 return inl(ap->ioaddr.scr_addr + (sc_reg * 4)); 337 return inl(ap->ioaddr.scr_addr + (sc_reg * 4));
337} 338}
@@ -345,7 +346,7 @@ static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
345 return; 346 return;
346 347
347 if (host->host_flags & NV_HOST_FLAGS_SCR_MMIO) 348 if (host->host_flags & NV_HOST_FLAGS_SCR_MMIO)
348 writel(val, (void*)ap->ioaddr.scr_addr + (sc_reg * 4)); 349 writel(val, (void __iomem *)ap->ioaddr.scr_addr + (sc_reg * 4));
349 else 350 else
350 outl(val, ap->ioaddr.scr_addr + (sc_reg * 4)); 351 outl(val, ap->ioaddr.scr_addr + (sc_reg * 4));
351} 352}
@@ -383,7 +384,7 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
383 return -ENODEV; 384 return -ENODEV;
384 385
385 if (!printed_version++) 386 if (!printed_version++)
386 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 387 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
387 388
388 rc = pci_enable_device(pdev); 389 rc = pci_enable_device(pdev);
389 if (rc) 390 if (rc)
@@ -405,7 +406,7 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
405 rc = -ENOMEM; 406 rc = -ENOMEM;
406 407
407 ppi = &nv_port_info; 408 ppi = &nv_port_info;
408 probe_ent = ata_pci_init_native_mode(pdev, &ppi); 409 probe_ent = ata_pci_init_native_mode(pdev, &ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
409 if (!probe_ent) 410 if (!probe_ent)
410 goto err_out_regions; 411 goto err_out_regions;
411 412
diff --git a/drivers/scsi/sata_promise.c b/drivers/scsi/sata_promise.c
index 538ad727bd2e..b41c977d6fab 100644
--- a/drivers/scsi/sata_promise.c
+++ b/drivers/scsi/sata_promise.c
@@ -38,6 +38,7 @@
38#include <linux/delay.h> 38#include <linux/delay.h>
39#include <linux/interrupt.h> 39#include <linux/interrupt.h>
40#include <linux/sched.h> 40#include <linux/sched.h>
41#include <linux/device.h>
41#include "scsi.h" 42#include "scsi.h"
42#include <scsi/scsi_host.h> 43#include <scsi/scsi_host.h>
43#include <linux/libata.h> 44#include <linux/libata.h>
@@ -87,8 +88,8 @@ static void pdc_port_stop(struct ata_port *ap);
87static void pdc_pata_phy_reset(struct ata_port *ap); 88static void pdc_pata_phy_reset(struct ata_port *ap);
88static void pdc_sata_phy_reset(struct ata_port *ap); 89static void pdc_sata_phy_reset(struct ata_port *ap);
89static void pdc_qc_prep(struct ata_queued_cmd *qc); 90static void pdc_qc_prep(struct ata_queued_cmd *qc);
90static void pdc_tf_load_mmio(struct ata_port *ap, struct ata_taskfile *tf); 91static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
91static void pdc_exec_command_mmio(struct ata_port *ap, struct ata_taskfile *tf); 92static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
92static void pdc_irq_clear(struct ata_port *ap); 93static void pdc_irq_clear(struct ata_port *ap);
93static int pdc_qc_issue_prot(struct ata_queued_cmd *qc); 94static int pdc_qc_issue_prot(struct ata_queued_cmd *qc);
94 95
@@ -113,7 +114,7 @@ static Scsi_Host_Template pdc_ata_sht = {
113 .ordered_flush = 1, 114 .ordered_flush = 1,
114}; 115};
115 116
116static struct ata_port_operations pdc_sata_ops = { 117static const struct ata_port_operations pdc_sata_ops = {
117 .port_disable = ata_port_disable, 118 .port_disable = ata_port_disable,
118 .tf_load = pdc_tf_load_mmio, 119 .tf_load = pdc_tf_load_mmio,
119 .tf_read = ata_tf_read, 120 .tf_read = ata_tf_read,
@@ -136,7 +137,7 @@ static struct ata_port_operations pdc_sata_ops = {
136 .host_stop = ata_pci_host_stop, 137 .host_stop = ata_pci_host_stop,
137}; 138};
138 139
139static struct ata_port_operations pdc_pata_ops = { 140static const struct ata_port_operations pdc_pata_ops = {
140 .port_disable = ata_port_disable, 141 .port_disable = ata_port_disable,
141 .tf_load = pdc_tf_load_mmio, 142 .tf_load = pdc_tf_load_mmio,
142 .tf_read = ata_tf_read, 143 .tf_read = ata_tf_read,
@@ -195,6 +196,8 @@ static struct ata_port_info pdc_port_info[] = {
195static struct pci_device_id pdc_ata_pci_tbl[] = { 196static struct pci_device_id pdc_ata_pci_tbl[] = {
196 { PCI_VENDOR_ID_PROMISE, 0x3371, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 197 { PCI_VENDOR_ID_PROMISE, 0x3371, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
197 board_2037x }, 198 board_2037x },
199 { PCI_VENDOR_ID_PROMISE, 0x3570, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
200 board_2037x },
198 { PCI_VENDOR_ID_PROMISE, 0x3571, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 201 { PCI_VENDOR_ID_PROMISE, 0x3571, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
199 board_2037x }, 202 board_2037x },
200 { PCI_VENDOR_ID_PROMISE, 0x3373, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 203 { PCI_VENDOR_ID_PROMISE, 0x3373, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
@@ -207,6 +210,8 @@ static struct pci_device_id pdc_ata_pci_tbl[] = {
207 board_2037x }, 210 board_2037x },
208 { PCI_VENDOR_ID_PROMISE, 0x3d75, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 211 { PCI_VENDOR_ID_PROMISE, 0x3d75, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
209 board_2037x }, 212 board_2037x },
213 { PCI_VENDOR_ID_PROMISE, 0x3d73, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
214 board_2037x },
210 215
211 { PCI_VENDOR_ID_PROMISE, 0x3318, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 216 { PCI_VENDOR_ID_PROMISE, 0x3318, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
212 board_20319 }, 217 board_20319 },
@@ -324,7 +329,7 @@ static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
324{ 329{
325 if (sc_reg > SCR_CONTROL) 330 if (sc_reg > SCR_CONTROL)
326 return 0xffffffffU; 331 return 0xffffffffU;
327 return readl((void *) ap->ioaddr.scr_addr + (sc_reg * 4)); 332 return readl((void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
328} 333}
329 334
330 335
@@ -333,7 +338,7 @@ static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg,
333{ 338{
334 if (sc_reg > SCR_CONTROL) 339 if (sc_reg > SCR_CONTROL)
335 return; 340 return;
336 writel(val, (void *) ap->ioaddr.scr_addr + (sc_reg * 4)); 341 writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
337} 342}
338 343
339static void pdc_qc_prep(struct ata_queued_cmd *qc) 344static void pdc_qc_prep(struct ata_queued_cmd *qc)
@@ -395,7 +400,8 @@ static void pdc_eng_timeout(struct ata_port *ap)
395 case ATA_PROT_DMA: 400 case ATA_PROT_DMA:
396 case ATA_PROT_NODATA: 401 case ATA_PROT_NODATA:
397 printk(KERN_ERR "ata%u: command timeout\n", ap->id); 402 printk(KERN_ERR "ata%u: command timeout\n", ap->id);
398 ata_qc_complete(qc, ata_wait_idle(ap) | ATA_ERR); 403 drv_stat = ata_wait_idle(ap);
404 ata_qc_complete(qc, __ac_err_mask(drv_stat));
399 break; 405 break;
400 406
401 default: 407 default:
@@ -404,7 +410,7 @@ static void pdc_eng_timeout(struct ata_port *ap)
404 printk(KERN_ERR "ata%u: unknown timeout, cmd 0x%x stat 0x%x\n", 410 printk(KERN_ERR "ata%u: unknown timeout, cmd 0x%x stat 0x%x\n",
405 ap->id, qc->tf.command, drv_stat); 411 ap->id, qc->tf.command, drv_stat);
406 412
407 ata_qc_complete(qc, drv_stat); 413 ata_qc_complete(qc, ac_err_mask(drv_stat));
408 break; 414 break;
409 } 415 }
410 416
@@ -416,33 +422,30 @@ out:
416static inline unsigned int pdc_host_intr( struct ata_port *ap, 422static inline unsigned int pdc_host_intr( struct ata_port *ap,
417 struct ata_queued_cmd *qc) 423 struct ata_queued_cmd *qc)
418{ 424{
419 u8 status; 425 unsigned int handled = 0, err_mask = 0;
420 unsigned int handled = 0, have_err = 0;
421 u32 tmp; 426 u32 tmp;
422 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_GLOBAL_CTL; 427 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_GLOBAL_CTL;
423 428
424 tmp = readl(mmio); 429 tmp = readl(mmio);
425 if (tmp & PDC_ERR_MASK) { 430 if (tmp & PDC_ERR_MASK) {
426 have_err = 1; 431 err_mask = AC_ERR_DEV;
427 pdc_reset_port(ap); 432 pdc_reset_port(ap);
428 } 433 }
429 434
430 switch (qc->tf.protocol) { 435 switch (qc->tf.protocol) {
431 case ATA_PROT_DMA: 436 case ATA_PROT_DMA:
432 case ATA_PROT_NODATA: 437 case ATA_PROT_NODATA:
433 status = ata_wait_idle(ap); 438 err_mask |= ac_err_mask(ata_wait_idle(ap));
434 if (have_err) 439 ata_qc_complete(qc, err_mask);
435 status |= ATA_ERR;
436 ata_qc_complete(qc, status);
437 handled = 1; 440 handled = 1;
438 break; 441 break;
439 442
440 default: 443 default:
441 ap->stats.idle_irq++; 444 ap->stats.idle_irq++;
442 break; 445 break;
443 } 446 }
444 447
445 return handled; 448 return handled;
446} 449}
447 450
448static void pdc_irq_clear(struct ata_port *ap) 451static void pdc_irq_clear(struct ata_port *ap)
@@ -523,8 +526,8 @@ static inline void pdc_packet_start(struct ata_queued_cmd *qc)
523 526
524 pp->pkt[2] = seq; 527 pp->pkt[2] = seq;
525 wmb(); /* flush PRD, pkt writes */ 528 wmb(); /* flush PRD, pkt writes */
526 writel(pp->pkt_dma, (void *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); 529 writel(pp->pkt_dma, (void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
527 readl((void *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); /* flush */ 530 readl((void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); /* flush */
528} 531}
529 532
530static int pdc_qc_issue_prot(struct ata_queued_cmd *qc) 533static int pdc_qc_issue_prot(struct ata_queued_cmd *qc)
@@ -546,7 +549,7 @@ static int pdc_qc_issue_prot(struct ata_queued_cmd *qc)
546 return ata_qc_issue_prot(qc); 549 return ata_qc_issue_prot(qc);
547} 550}
548 551
549static void pdc_tf_load_mmio(struct ata_port *ap, struct ata_taskfile *tf) 552static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
550{ 553{
551 WARN_ON (tf->protocol == ATA_PROT_DMA || 554 WARN_ON (tf->protocol == ATA_PROT_DMA ||
552 tf->protocol == ATA_PROT_NODATA); 555 tf->protocol == ATA_PROT_NODATA);
@@ -554,7 +557,7 @@ static void pdc_tf_load_mmio(struct ata_port *ap, struct ata_taskfile *tf)
554} 557}
555 558
556 559
557static void pdc_exec_command_mmio(struct ata_port *ap, struct ata_taskfile *tf) 560static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
558{ 561{
559 WARN_ON (tf->protocol == ATA_PROT_DMA || 562 WARN_ON (tf->protocol == ATA_PROT_DMA ||
560 tf->protocol == ATA_PROT_NODATA); 563 tf->protocol == ATA_PROT_NODATA);
@@ -631,7 +634,7 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
631 int rc; 634 int rc;
632 635
633 if (!printed_version++) 636 if (!printed_version++)
634 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 637 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
635 638
636 /* 639 /*
637 * If this driver happens to only be useful on Apple's K2, then 640 * If this driver happens to only be useful on Apple's K2, then
diff --git a/drivers/scsi/sata_qstor.c b/drivers/scsi/sata_qstor.c
index ffcdeb68641c..9938dae782b6 100644
--- a/drivers/scsi/sata_qstor.c
+++ b/drivers/scsi/sata_qstor.c
@@ -35,6 +35,7 @@
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/interrupt.h> 36#include <linux/interrupt.h>
37#include <linux/sched.h> 37#include <linux/sched.h>
38#include <linux/device.h>
38#include "scsi.h" 39#include "scsi.h"
39#include <scsi/scsi_host.h> 40#include <scsi/scsi_host.h>
40#include <asm/io.h> 41#include <asm/io.h>
@@ -51,8 +52,6 @@ enum {
51 QS_PRD_BYTES = QS_MAX_PRD * 16, 52 QS_PRD_BYTES = QS_MAX_PRD * 16,
52 QS_PKT_BYTES = QS_CPB_BYTES + QS_PRD_BYTES, 53 QS_PKT_BYTES = QS_CPB_BYTES + QS_PRD_BYTES,
53 54
54 QS_DMA_BOUNDARY = ~0UL,
55
56 /* global register offsets */ 55 /* global register offsets */
57 QS_HCF_CNFG3 = 0x0003, /* host configuration offset */ 56 QS_HCF_CNFG3 = 0x0003, /* host configuration offset */
58 QS_HID_HPHY = 0x0004, /* host physical interface info */ 57 QS_HID_HPHY = 0x0004, /* host physical interface info */
@@ -101,6 +100,10 @@ enum {
101 board_2068_idx = 0, /* QStor 4-port SATA/RAID */ 100 board_2068_idx = 0, /* QStor 4-port SATA/RAID */
102}; 101};
103 102
103enum {
104 QS_DMA_BOUNDARY = ~0UL
105};
106
104typedef enum { qs_state_idle, qs_state_pkt, qs_state_mmio } qs_state_t; 107typedef enum { qs_state_idle, qs_state_pkt, qs_state_mmio } qs_state_t;
105 108
106struct qs_port_priv { 109struct qs_port_priv {
@@ -145,7 +148,7 @@ static Scsi_Host_Template qs_ata_sht = {
145 .bios_param = ata_std_bios_param, 148 .bios_param = ata_std_bios_param,
146}; 149};
147 150
148static struct ata_port_operations qs_ata_ops = { 151static const struct ata_port_operations qs_ata_ops = {
149 .port_disable = ata_port_disable, 152 .port_disable = ata_port_disable,
150 .tf_load = ata_tf_load, 153 .tf_load = ata_tf_load,
151 .tf_read = ata_tf_read, 154 .tf_read = ata_tf_read,
@@ -398,11 +401,12 @@ static inline unsigned int qs_intr_pkt(struct ata_host_set *host_set)
398 qc = ata_qc_from_tag(ap, ap->active_tag); 401 qc = ata_qc_from_tag(ap, ap->active_tag);
399 if (qc && (!(qc->tf.ctl & ATA_NIEN))) { 402 if (qc && (!(qc->tf.ctl & ATA_NIEN))) {
400 switch (sHST) { 403 switch (sHST) {
401 case 0: /* sucessful CPB */ 404 case 0: /* successful CPB */
402 case 3: /* device error */ 405 case 3: /* device error */
403 pp->state = qs_state_idle; 406 pp->state = qs_state_idle;
404 qs_enter_reg_mode(qc->ap); 407 qs_enter_reg_mode(qc->ap);
405 ata_qc_complete(qc, sDST); 408 ata_qc_complete(qc,
409 ac_err_mask(sDST));
406 break; 410 break;
407 default: 411 default:
408 break; 412 break;
@@ -431,7 +435,7 @@ static inline unsigned int qs_intr_mmio(struct ata_host_set *host_set)
431 if (qc && (!(qc->tf.ctl & ATA_NIEN))) { 435 if (qc && (!(qc->tf.ctl & ATA_NIEN))) {
432 436
433 /* check main status, clearing INTRQ */ 437 /* check main status, clearing INTRQ */
434 u8 status = ata_chk_status(ap); 438 u8 status = ata_check_status(ap);
435 if ((status & ATA_BUSY)) 439 if ((status & ATA_BUSY))
436 continue; 440 continue;
437 DPRINTK("ata%u: protocol %d (dev_stat 0x%X)\n", 441 DPRINTK("ata%u: protocol %d (dev_stat 0x%X)\n",
@@ -439,7 +443,7 @@ static inline unsigned int qs_intr_mmio(struct ata_host_set *host_set)
439 443
440 /* complete taskfile transaction */ 444 /* complete taskfile transaction */
441 pp->state = qs_state_idle; 445 pp->state = qs_state_idle;
442 ata_qc_complete(qc, status); 446 ata_qc_complete(qc, ac_err_mask(status));
443 handled = 1; 447 handled = 1;
444 } 448 }
445 } 449 }
@@ -597,25 +601,22 @@ static int qs_set_dma_masks(struct pci_dev *pdev, void __iomem *mmio_base)
597 if (rc) { 601 if (rc) {
598 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 602 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
599 if (rc) { 603 if (rc) {
600 printk(KERN_ERR DRV_NAME 604 dev_printk(KERN_ERR, &pdev->dev,
601 "(%s): 64-bit DMA enable failed\n", 605 "64-bit DMA enable failed\n");
602 pci_name(pdev));
603 return rc; 606 return rc;
604 } 607 }
605 } 608 }
606 } else { 609 } else {
607 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 610 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
608 if (rc) { 611 if (rc) {
609 printk(KERN_ERR DRV_NAME 612 dev_printk(KERN_ERR, &pdev->dev,
610 "(%s): 32-bit DMA enable failed\n", 613 "32-bit DMA enable failed\n");
611 pci_name(pdev));
612 return rc; 614 return rc;
613 } 615 }
614 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 616 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
615 if (rc) { 617 if (rc) {
616 printk(KERN_ERR DRV_NAME 618 dev_printk(KERN_ERR, &pdev->dev,
617 "(%s): 32-bit consistent DMA enable failed\n", 619 "32-bit consistent DMA enable failed\n");
618 pci_name(pdev));
619 return rc; 620 return rc;
620 } 621 }
621 } 622 }
@@ -632,7 +633,7 @@ static int qs_ata_init_one(struct pci_dev *pdev,
632 int rc, port_no; 633 int rc, port_no;
633 634
634 if (!printed_version++) 635 if (!printed_version++)
635 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 636 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
636 637
637 rc = pci_enable_device(pdev); 638 rc = pci_enable_device(pdev);
638 if (rc) 639 if (rc)
diff --git a/drivers/scsi/sata_sil.c b/drivers/scsi/sata_sil.c
index ba98a175ee3a..435f7e0085ec 100644
--- a/drivers/scsi/sata_sil.c
+++ b/drivers/scsi/sata_sil.c
@@ -41,6 +41,7 @@
41#include <linux/blkdev.h> 41#include <linux/blkdev.h>
42#include <linux/delay.h> 42#include <linux/delay.h>
43#include <linux/interrupt.h> 43#include <linux/interrupt.h>
44#include <linux/device.h>
44#include "scsi.h" 45#include "scsi.h"
45#include <scsi/scsi_host.h> 46#include <scsi/scsi_host.h>
46#include <linux/libata.h> 47#include <linux/libata.h>
@@ -150,7 +151,7 @@ static Scsi_Host_Template sil_sht = {
150 .ordered_flush = 1, 151 .ordered_flush = 1,
151}; 152};
152 153
153static struct ata_port_operations sil_ops = { 154static const struct ata_port_operations sil_ops = {
154 .port_disable = ata_port_disable, 155 .port_disable = ata_port_disable,
155 .dev_config = sil_dev_config, 156 .dev_config = sil_dev_config,
156 .tf_load = ata_tf_load, 157 .tf_load = ata_tf_load,
@@ -289,7 +290,7 @@ static inline unsigned long sil_scr_addr(struct ata_port *ap, unsigned int sc_re
289 290
290static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg) 291static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg)
291{ 292{
292 void *mmio = (void *) sil_scr_addr(ap, sc_reg); 293 void __iomem *mmio = (void __iomem *) sil_scr_addr(ap, sc_reg);
293 if (mmio) 294 if (mmio)
294 return readl(mmio); 295 return readl(mmio);
295 return 0xffffffffU; 296 return 0xffffffffU;
@@ -297,7 +298,7 @@ static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg)
297 298
298static void sil_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) 299static void sil_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
299{ 300{
300 void *mmio = (void *) sil_scr_addr(ap, sc_reg); 301 void *mmio = (void __iomem *) sil_scr_addr(ap, sc_reg);
301 if (mmio) 302 if (mmio)
302 writel(val, mmio); 303 writel(val, mmio);
303} 304}
@@ -386,7 +387,7 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
386 u8 cls; 387 u8 cls;
387 388
388 if (!printed_version++) 389 if (!printed_version++)
389 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 390 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
390 391
391 /* 392 /*
392 * If this driver happens to only be useful on Apple's K2, then 393 * If this driver happens to only be useful on Apple's K2, then
@@ -463,8 +464,8 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
463 writeb(cls, mmio_base + SIL_FIFO_W3); 464 writeb(cls, mmio_base + SIL_FIFO_W3);
464 } 465 }
465 } else 466 } else
466 printk(KERN_WARNING DRV_NAME "(%s): cache line size not set. Driver may not function\n", 467 dev_printk(KERN_WARNING, &pdev->dev,
467 pci_name(pdev)); 468 "cache line size not set. Driver may not function\n");
468 469
469 if (ent->driver_data == sil_3114) { 470 if (ent->driver_data == sil_3114) {
470 irq_mask = SIL_MASK_4PORT; 471 irq_mask = SIL_MASK_4PORT;
diff --git a/drivers/scsi/sata_sil24.c b/drivers/scsi/sata_sil24.c
new file mode 100644
index 000000000000..c66548025657
--- /dev/null
+++ b/drivers/scsi/sata_sil24.c
@@ -0,0 +1,871 @@
1/*
2 * sata_sil24.c - Driver for Silicon Image 3124/3132 SATA-2 controllers
3 *
4 * Copyright 2005 Tejun Heo
5 *
6 * Based on preview driver from Silicon Image.
7 *
8 * NOTE: No NCQ/ATAPI support yet. The preview driver didn't support
9 * NCQ nor ATAPI, and, unfortunately, I couldn't find out how to make
10 * those work. Enabling those shouldn't be difficult. Basic
11 * structure is all there (in libata-dev tree). If you have any
12 * information about this hardware, please contact me or linux-ide.
13 * Info is needed on...
14 *
15 * - How to issue tagged commands and turn on sactive on issue accordingly.
16 * - Where to put an ATAPI command and how to tell the device to send it.
17 * - How to enable/use 64bit.
18 *
19 * This program is free software; you can redistribute it and/or modify it
20 * under the terms of the GNU General Public License as published by the
21 * Free Software Foundation; either version 2, or (at your option) any
22 * later version.
23 *
24 * This program is distributed in the hope that it will be useful, but
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * General Public License for more details.
28 *
29 */
30
31#include <linux/kernel.h>
32#include <linux/module.h>
33#include <linux/pci.h>
34#include <linux/blkdev.h>
35#include <linux/delay.h>
36#include <linux/interrupt.h>
37#include <linux/dma-mapping.h>
38#include <linux/device.h>
39#include <scsi/scsi_host.h>
40#include "scsi.h"
41#include <linux/libata.h>
42#include <asm/io.h>
43
44#define DRV_NAME "sata_sil24"
45#define DRV_VERSION "0.22" /* Silicon Image's preview driver was 0.10 */
46
47/*
48 * Port request block (PRB) 32 bytes
49 */
50struct sil24_prb {
51 u16 ctrl;
52 u16 prot;
53 u32 rx_cnt;
54 u8 fis[6 * 4];
55};
56
57/*
58 * Scatter gather entry (SGE) 16 bytes
59 */
60struct sil24_sge {
61 u64 addr;
62 u32 cnt;
63 u32 flags;
64};
65
66/*
67 * Port multiplier
68 */
69struct sil24_port_multiplier {
70 u32 diag;
71 u32 sactive;
72};
73
74enum {
75 /*
76 * Global controller registers (128 bytes @ BAR0)
77 */
78 /* 32 bit regs */
79 HOST_SLOT_STAT = 0x00, /* 32 bit slot stat * 4 */
80 HOST_CTRL = 0x40,
81 HOST_IRQ_STAT = 0x44,
82 HOST_PHY_CFG = 0x48,
83 HOST_BIST_CTRL = 0x50,
84 HOST_BIST_PTRN = 0x54,
85 HOST_BIST_STAT = 0x58,
86 HOST_MEM_BIST_STAT = 0x5c,
87 HOST_FLASH_CMD = 0x70,
88 /* 8 bit regs */
89 HOST_FLASH_DATA = 0x74,
90 HOST_TRANSITION_DETECT = 0x75,
91 HOST_GPIO_CTRL = 0x76,
92 HOST_I2C_ADDR = 0x78, /* 32 bit */
93 HOST_I2C_DATA = 0x7c,
94 HOST_I2C_XFER_CNT = 0x7e,
95 HOST_I2C_CTRL = 0x7f,
96
97 /* HOST_SLOT_STAT bits */
98 HOST_SSTAT_ATTN = (1 << 31),
99
100 /*
101 * Port registers
102 * (8192 bytes @ +0x0000, +0x2000, +0x4000 and +0x6000 @ BAR2)
103 */
104 PORT_REGS_SIZE = 0x2000,
105 PORT_PRB = 0x0000, /* (32 bytes PRB + 16 bytes SGEs * 6) * 31 (3968 bytes) */
106
107 PORT_PM = 0x0f80, /* 8 bytes PM * 16 (128 bytes) */
108 /* 32 bit regs */
109 PORT_CTRL_STAT = 0x1000, /* write: ctrl-set, read: stat */
110 PORT_CTRL_CLR = 0x1004, /* write: ctrl-clear */
111 PORT_IRQ_STAT = 0x1008, /* high: status, low: interrupt */
112 PORT_IRQ_ENABLE_SET = 0x1010, /* write: enable-set */
113 PORT_IRQ_ENABLE_CLR = 0x1014, /* write: enable-clear */
114 PORT_ACTIVATE_UPPER_ADDR= 0x101c,
115 PORT_EXEC_FIFO = 0x1020, /* command execution fifo */
116 PORT_CMD_ERR = 0x1024, /* command error number */
117 PORT_FIS_CFG = 0x1028,
118 PORT_FIFO_THRES = 0x102c,
119 /* 16 bit regs */
120 PORT_DECODE_ERR_CNT = 0x1040,
121 PORT_DECODE_ERR_THRESH = 0x1042,
122 PORT_CRC_ERR_CNT = 0x1044,
123 PORT_CRC_ERR_THRESH = 0x1046,
124 PORT_HSHK_ERR_CNT = 0x1048,
125 PORT_HSHK_ERR_THRESH = 0x104a,
126 /* 32 bit regs */
127 PORT_PHY_CFG = 0x1050,
128 PORT_SLOT_STAT = 0x1800,
129 PORT_CMD_ACTIVATE = 0x1c00, /* 64 bit cmd activate * 31 (248 bytes) */
130 PORT_EXEC_DIAG = 0x1e00, /* 32bit exec diag * 16 (64 bytes, 0-10 used on 3124) */
131 PORT_PSD_DIAG = 0x1e40, /* 32bit psd diag * 16 (64 bytes, 0-8 used on 3124) */
132 PORT_SCONTROL = 0x1f00,
133 PORT_SSTATUS = 0x1f04,
134 PORT_SERROR = 0x1f08,
135 PORT_SACTIVE = 0x1f0c,
136
137 /* PORT_CTRL_STAT bits */
138 PORT_CS_PORT_RST = (1 << 0), /* port reset */
139 PORT_CS_DEV_RST = (1 << 1), /* device reset */
140 PORT_CS_INIT = (1 << 2), /* port initialize */
141 PORT_CS_IRQ_WOC = (1 << 3), /* interrupt write one to clear */
142 PORT_CS_RESUME = (1 << 6), /* port resume */
143 PORT_CS_32BIT_ACTV = (1 << 10), /* 32-bit activation */
144 PORT_CS_PM_EN = (1 << 13), /* port multiplier enable */
145 PORT_CS_RDY = (1 << 31), /* port ready to accept commands */
146
147 /* PORT_IRQ_STAT/ENABLE_SET/CLR */
148 /* bits[11:0] are masked */
149 PORT_IRQ_COMPLETE = (1 << 0), /* command(s) completed */
150 PORT_IRQ_ERROR = (1 << 1), /* command execution error */
151 PORT_IRQ_PORTRDY_CHG = (1 << 2), /* port ready change */
152 PORT_IRQ_PWR_CHG = (1 << 3), /* power management change */
153 PORT_IRQ_PHYRDY_CHG = (1 << 4), /* PHY ready change */
154 PORT_IRQ_COMWAKE = (1 << 5), /* COMWAKE received */
155 PORT_IRQ_UNK_FIS = (1 << 6), /* Unknown FIS received */
156 PORT_IRQ_SDB_FIS = (1 << 11), /* SDB FIS received */
157
158 /* bits[27:16] are unmasked (raw) */
159 PORT_IRQ_RAW_SHIFT = 16,
160 PORT_IRQ_MASKED_MASK = 0x7ff,
161 PORT_IRQ_RAW_MASK = (0x7ff << PORT_IRQ_RAW_SHIFT),
162
163 /* ENABLE_SET/CLR specific, intr steering - 2 bit field */
164 PORT_IRQ_STEER_SHIFT = 30,
165 PORT_IRQ_STEER_MASK = (3 << PORT_IRQ_STEER_SHIFT),
166
167 /* PORT_CMD_ERR constants */
168 PORT_CERR_DEV = 1, /* Error bit in D2H Register FIS */
169 PORT_CERR_SDB = 2, /* Error bit in SDB FIS */
170 PORT_CERR_DATA = 3, /* Error in data FIS not detected by dev */
171 PORT_CERR_SEND = 4, /* Initial cmd FIS transmission failure */
172 PORT_CERR_INCONSISTENT = 5, /* Protocol mismatch */
173 PORT_CERR_DIRECTION = 6, /* Data direction mismatch */
174 PORT_CERR_UNDERRUN = 7, /* Ran out of SGEs while writing */
175 PORT_CERR_OVERRUN = 8, /* Ran out of SGEs while reading */
176 PORT_CERR_PKT_PROT = 11, /* DIR invalid in 1st PIO setup of ATAPI */
177 PORT_CERR_SGT_BOUNDARY = 16, /* PLD ecode 00 - SGT not on qword boundary */
178 PORT_CERR_SGT_TGTABRT = 17, /* PLD ecode 01 - target abort */
179 PORT_CERR_SGT_MSTABRT = 18, /* PLD ecode 10 - master abort */
180 PORT_CERR_SGT_PCIPERR = 19, /* PLD ecode 11 - PCI parity err while fetching SGT */
181 PORT_CERR_CMD_BOUNDARY = 24, /* ctrl[15:13] 001 - PRB not on qword boundary */
182 PORT_CERR_CMD_TGTABRT = 25, /* ctrl[15:13] 010 - target abort */
183 PORT_CERR_CMD_MSTABRT = 26, /* ctrl[15:13] 100 - master abort */
184 PORT_CERR_CMD_PCIPERR = 27, /* ctrl[15:13] 110 - PCI parity err while fetching PRB */
185 PORT_CERR_XFR_UNDEF = 32, /* PSD ecode 00 - undefined */
186 PORT_CERR_XFR_TGTABRT = 33, /* PSD ecode 01 - target abort */
187 PORT_CERR_XFR_MSGABRT = 34, /* PSD ecode 10 - master abort */
188 PORT_CERR_XFR_PCIPERR = 35, /* PSD ecode 11 - PCI prity err during transfer */
189 PORT_CERR_SENDSERVICE = 36, /* FIS received while sending service */
190
191 /*
192 * Other constants
193 */
194 SGE_TRM = (1 << 31), /* Last SGE in chain */
195 PRB_SOFT_RST = (1 << 7), /* Soft reset request (ign BSY?) */
196
197 /* board id */
198 BID_SIL3124 = 0,
199 BID_SIL3132 = 1,
200 BID_SIL3131 = 2,
201
202 IRQ_STAT_4PORTS = 0xf,
203};
204
205struct sil24_cmd_block {
206 struct sil24_prb prb;
207 struct sil24_sge sge[LIBATA_MAX_PRD];
208};
209
210/*
211 * ap->private_data
212 *
213 * The preview driver always returned 0 for status. We emulate it
214 * here from the previous interrupt.
215 */
216struct sil24_port_priv {
217 struct sil24_cmd_block *cmd_block; /* 32 cmd blocks */
218 dma_addr_t cmd_block_dma; /* DMA base addr for them */
219 struct ata_taskfile tf; /* Cached taskfile registers */
220};
221
222/* ap->host_set->private_data */
223struct sil24_host_priv {
224 void __iomem *host_base; /* global controller control (128 bytes @BAR0) */
225 void __iomem *port_base; /* port registers (4 * 8192 bytes @BAR2) */
226};
227
228static u8 sil24_check_status(struct ata_port *ap);
229static u32 sil24_scr_read(struct ata_port *ap, unsigned sc_reg);
230static void sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val);
231static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
232static void sil24_phy_reset(struct ata_port *ap);
233static void sil24_qc_prep(struct ata_queued_cmd *qc);
234static int sil24_qc_issue(struct ata_queued_cmd *qc);
235static void sil24_irq_clear(struct ata_port *ap);
236static void sil24_eng_timeout(struct ata_port *ap);
237static irqreturn_t sil24_interrupt(int irq, void *dev_instance, struct pt_regs *regs);
238static int sil24_port_start(struct ata_port *ap);
239static void sil24_port_stop(struct ata_port *ap);
240static void sil24_host_stop(struct ata_host_set *host_set);
241static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
242
243static struct pci_device_id sil24_pci_tbl[] = {
244 { 0x1095, 0x3124, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BID_SIL3124 },
245 { 0x1095, 0x3132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BID_SIL3132 },
246 { 0x1095, 0x3131, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BID_SIL3131 },
247 { 0x1095, 0x3531, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BID_SIL3131 },
248 { } /* terminate list */
249};
250
251static struct pci_driver sil24_pci_driver = {
252 .name = DRV_NAME,
253 .id_table = sil24_pci_tbl,
254 .probe = sil24_init_one,
255 .remove = ata_pci_remove_one, /* safe? */
256};
257
258static Scsi_Host_Template sil24_sht = {
259 .module = THIS_MODULE,
260 .name = DRV_NAME,
261 .ioctl = ata_scsi_ioctl,
262 .queuecommand = ata_scsi_queuecmd,
263 .eh_strategy_handler = ata_scsi_error,
264 .can_queue = ATA_DEF_QUEUE,
265 .this_id = ATA_SHT_THIS_ID,
266 .sg_tablesize = LIBATA_MAX_PRD,
267 .max_sectors = ATA_MAX_SECTORS,
268 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
269 .emulated = ATA_SHT_EMULATED,
270 .use_clustering = ATA_SHT_USE_CLUSTERING,
271 .proc_name = DRV_NAME,
272 .dma_boundary = ATA_DMA_BOUNDARY,
273 .slave_configure = ata_scsi_slave_config,
274 .bios_param = ata_std_bios_param,
275 .ordered_flush = 1, /* NCQ not supported yet */
276};
277
278static const struct ata_port_operations sil24_ops = {
279 .port_disable = ata_port_disable,
280
281 .check_status = sil24_check_status,
282 .check_altstatus = sil24_check_status,
283 .dev_select = ata_noop_dev_select,
284
285 .tf_read = sil24_tf_read,
286
287 .phy_reset = sil24_phy_reset,
288
289 .qc_prep = sil24_qc_prep,
290 .qc_issue = sil24_qc_issue,
291
292 .eng_timeout = sil24_eng_timeout,
293
294 .irq_handler = sil24_interrupt,
295 .irq_clear = sil24_irq_clear,
296
297 .scr_read = sil24_scr_read,
298 .scr_write = sil24_scr_write,
299
300 .port_start = sil24_port_start,
301 .port_stop = sil24_port_stop,
302 .host_stop = sil24_host_stop,
303};
304
305/*
306 * Use bits 30-31 of host_flags to encode available port numbers.
307 * Current maxium is 4.
308 */
309#define SIL24_NPORTS2FLAG(nports) ((((unsigned)(nports) - 1) & 0x3) << 30)
310#define SIL24_FLAG2NPORTS(flag) ((((flag) >> 30) & 0x3) + 1)
311
312static struct ata_port_info sil24_port_info[] = {
313 /* sil_3124 */
314 {
315 .sht = &sil24_sht,
316 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
317 ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO |
318 ATA_FLAG_PIO_DMA | SIL24_NPORTS2FLAG(4),
319 .pio_mask = 0x1f, /* pio0-4 */
320 .mwdma_mask = 0x07, /* mwdma0-2 */
321 .udma_mask = 0x3f, /* udma0-5 */
322 .port_ops = &sil24_ops,
323 },
324 /* sil_3132 */
325 {
326 .sht = &sil24_sht,
327 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
328 ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO |
329 ATA_FLAG_PIO_DMA | SIL24_NPORTS2FLAG(2),
330 .pio_mask = 0x1f, /* pio0-4 */
331 .mwdma_mask = 0x07, /* mwdma0-2 */
332 .udma_mask = 0x3f, /* udma0-5 */
333 .port_ops = &sil24_ops,
334 },
335 /* sil_3131/sil_3531 */
336 {
337 .sht = &sil24_sht,
338 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
339 ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO |
340 ATA_FLAG_PIO_DMA | SIL24_NPORTS2FLAG(1),
341 .pio_mask = 0x1f, /* pio0-4 */
342 .mwdma_mask = 0x07, /* mwdma0-2 */
343 .udma_mask = 0x3f, /* udma0-5 */
344 .port_ops = &sil24_ops,
345 },
346};
347
348static inline void sil24_update_tf(struct ata_port *ap)
349{
350 struct sil24_port_priv *pp = ap->private_data;
351 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
352 struct sil24_prb __iomem *prb = port;
353 u8 fis[6 * 4];
354
355 memcpy_fromio(fis, prb->fis, 6 * 4);
356 ata_tf_from_fis(fis, &pp->tf);
357}
358
359static u8 sil24_check_status(struct ata_port *ap)
360{
361 struct sil24_port_priv *pp = ap->private_data;
362 return pp->tf.command;
363}
364
365static int sil24_scr_map[] = {
366 [SCR_CONTROL] = 0,
367 [SCR_STATUS] = 1,
368 [SCR_ERROR] = 2,
369 [SCR_ACTIVE] = 3,
370};
371
372static u32 sil24_scr_read(struct ata_port *ap, unsigned sc_reg)
373{
374 void __iomem *scr_addr = (void __iomem *)ap->ioaddr.scr_addr;
375 if (sc_reg < ARRAY_SIZE(sil24_scr_map)) {
376 void __iomem *addr;
377 addr = scr_addr + sil24_scr_map[sc_reg] * 4;
378 return readl(scr_addr + sil24_scr_map[sc_reg] * 4);
379 }
380 return 0xffffffffU;
381}
382
383static void sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val)
384{
385 void __iomem *scr_addr = (void __iomem *)ap->ioaddr.scr_addr;
386 if (sc_reg < ARRAY_SIZE(sil24_scr_map)) {
387 void __iomem *addr;
388 addr = scr_addr + sil24_scr_map[sc_reg] * 4;
389 writel(val, scr_addr + sil24_scr_map[sc_reg] * 4);
390 }
391}
392
393static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
394{
395 struct sil24_port_priv *pp = ap->private_data;
396 *tf = pp->tf;
397}
398
399static void sil24_phy_reset(struct ata_port *ap)
400{
401 __sata_phy_reset(ap);
402 /*
403 * No ATAPI yet. Just unconditionally indicate ATA device.
404 * If ATAPI device is attached, it will fail ATA_CMD_ID_ATA
405 * and libata core will ignore the device.
406 */
407 if (!(ap->flags & ATA_FLAG_PORT_DISABLED))
408 ap->device[0].class = ATA_DEV_ATA;
409}
410
411static inline void sil24_fill_sg(struct ata_queued_cmd *qc,
412 struct sil24_cmd_block *cb)
413{
414 struct scatterlist *sg = qc->sg;
415 struct sil24_sge *sge = cb->sge;
416 unsigned i;
417
418 for (i = 0; i < qc->n_elem; i++, sg++, sge++) {
419 sge->addr = cpu_to_le64(sg_dma_address(sg));
420 sge->cnt = cpu_to_le32(sg_dma_len(sg));
421 sge->flags = 0;
422 sge->flags = i < qc->n_elem - 1 ? 0 : cpu_to_le32(SGE_TRM);
423 }
424}
425
426static void sil24_qc_prep(struct ata_queued_cmd *qc)
427{
428 struct ata_port *ap = qc->ap;
429 struct sil24_port_priv *pp = ap->private_data;
430 struct sil24_cmd_block *cb = pp->cmd_block + qc->tag;
431 struct sil24_prb *prb = &cb->prb;
432
433 switch (qc->tf.protocol) {
434 case ATA_PROT_PIO:
435 case ATA_PROT_DMA:
436 case ATA_PROT_NODATA:
437 break;
438 default:
439 /* ATAPI isn't supported yet */
440 BUG();
441 }
442
443 ata_tf_to_fis(&qc->tf, prb->fis, 0);
444
445 if (qc->flags & ATA_QCFLAG_DMAMAP)
446 sil24_fill_sg(qc, cb);
447}
448
449static int sil24_qc_issue(struct ata_queued_cmd *qc)
450{
451 struct ata_port *ap = qc->ap;
452 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
453 struct sil24_port_priv *pp = ap->private_data;
454 dma_addr_t paddr = pp->cmd_block_dma + qc->tag * sizeof(*pp->cmd_block);
455
456 writel((u32)paddr, port + PORT_CMD_ACTIVATE);
457 return 0;
458}
459
460static void sil24_irq_clear(struct ata_port *ap)
461{
462 /* unused */
463}
464
465static int __sil24_reset_controller(void __iomem *port)
466{
467 int cnt;
468 u32 tmp;
469
470 /* Reset controller state. Is this correct? */
471 writel(PORT_CS_DEV_RST, port + PORT_CTRL_STAT);
472 readl(port + PORT_CTRL_STAT); /* sync */
473
474 /* Max ~100ms */
475 for (cnt = 0; cnt < 1000; cnt++) {
476 udelay(100);
477 tmp = readl(port + PORT_CTRL_STAT);
478 if (!(tmp & PORT_CS_DEV_RST))
479 break;
480 }
481
482 if (tmp & PORT_CS_DEV_RST)
483 return -1;
484 return 0;
485}
486
487static void sil24_reset_controller(struct ata_port *ap)
488{
489 printk(KERN_NOTICE DRV_NAME
490 " ata%u: resetting controller...\n", ap->id);
491 if (__sil24_reset_controller((void __iomem *)ap->ioaddr.cmd_addr))
492 printk(KERN_ERR DRV_NAME
493 " ata%u: failed to reset controller\n", ap->id);
494}
495
496static void sil24_eng_timeout(struct ata_port *ap)
497{
498 struct ata_queued_cmd *qc;
499
500 qc = ata_qc_from_tag(ap, ap->active_tag);
501 if (!qc) {
502 printk(KERN_ERR "ata%u: BUG: timeout without command\n",
503 ap->id);
504 return;
505 }
506
507 /*
508 * hack alert! We cannot use the supplied completion
509 * function from inside the ->eh_strategy_handler() thread.
510 * libata is the only user of ->eh_strategy_handler() in
511 * any kernel, so the default scsi_done() assumes it is
512 * not being called from the SCSI EH.
513 */
514 printk(KERN_ERR "ata%u: command timeout\n", ap->id);
515 qc->scsidone = scsi_finish_command;
516 ata_qc_complete(qc, AC_ERR_OTHER);
517
518 sil24_reset_controller(ap);
519}
520
521static void sil24_error_intr(struct ata_port *ap, u32 slot_stat)
522{
523 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->active_tag);
524 struct sil24_port_priv *pp = ap->private_data;
525 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
526 u32 irq_stat, cmd_err, sstatus, serror;
527 unsigned int err_mask;
528
529 irq_stat = readl(port + PORT_IRQ_STAT);
530 writel(irq_stat, port + PORT_IRQ_STAT); /* clear irq */
531
532 if (!(irq_stat & PORT_IRQ_ERROR)) {
533 /* ignore non-completion, non-error irqs for now */
534 printk(KERN_WARNING DRV_NAME
535 "ata%u: non-error exception irq (irq_stat %x)\n",
536 ap->id, irq_stat);
537 return;
538 }
539
540 cmd_err = readl(port + PORT_CMD_ERR);
541 sstatus = readl(port + PORT_SSTATUS);
542 serror = readl(port + PORT_SERROR);
543 if (serror)
544 writel(serror, port + PORT_SERROR);
545
546 printk(KERN_ERR DRV_NAME " ata%u: error interrupt on port%d\n"
547 " stat=0x%x irq=0x%x cmd_err=%d sstatus=0x%x serror=0x%x\n",
548 ap->id, ap->port_no, slot_stat, irq_stat, cmd_err, sstatus, serror);
549
550 if (cmd_err == PORT_CERR_DEV || cmd_err == PORT_CERR_SDB) {
551 /*
552 * Device is reporting error, tf registers are valid.
553 */
554 sil24_update_tf(ap);
555 err_mask = ac_err_mask(pp->tf.command);
556 } else {
557 /*
558 * Other errors. libata currently doesn't have any
559 * mechanism to report these errors. Just turn on
560 * ATA_ERR.
561 */
562 err_mask = AC_ERR_OTHER;
563 }
564
565 if (qc)
566 ata_qc_complete(qc, err_mask);
567
568 sil24_reset_controller(ap);
569}
570
571static inline void sil24_host_intr(struct ata_port *ap)
572{
573 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->active_tag);
574 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr;
575 u32 slot_stat;
576
577 slot_stat = readl(port + PORT_SLOT_STAT);
578 if (!(slot_stat & HOST_SSTAT_ATTN)) {
579 struct sil24_port_priv *pp = ap->private_data;
580 /*
581 * !HOST_SSAT_ATTN guarantees successful completion,
582 * so reading back tf registers is unnecessary for
583 * most commands. TODO: read tf registers for
584 * commands which require these values on successful
585 * completion (EXECUTE DEVICE DIAGNOSTIC, CHECK POWER,
586 * DEVICE RESET and READ PORT MULTIPLIER (any more?).
587 */
588 sil24_update_tf(ap);
589
590 if (qc)
591 ata_qc_complete(qc, ac_err_mask(pp->tf.command));
592 } else
593 sil24_error_intr(ap, slot_stat);
594}
595
596static irqreturn_t sil24_interrupt(int irq, void *dev_instance, struct pt_regs *regs)
597{
598 struct ata_host_set *host_set = dev_instance;
599 struct sil24_host_priv *hpriv = host_set->private_data;
600 unsigned handled = 0;
601 u32 status;
602 int i;
603
604 status = readl(hpriv->host_base + HOST_IRQ_STAT);
605
606 if (status == 0xffffffff) {
607 printk(KERN_ERR DRV_NAME ": IRQ status == 0xffffffff, "
608 "PCI fault or device removal?\n");
609 goto out;
610 }
611
612 if (!(status & IRQ_STAT_4PORTS))
613 goto out;
614
615 spin_lock(&host_set->lock);
616
617 for (i = 0; i < host_set->n_ports; i++)
618 if (status & (1 << i)) {
619 struct ata_port *ap = host_set->ports[i];
620 if (ap && !(ap->flags & ATA_FLAG_PORT_DISABLED)) {
621 sil24_host_intr(host_set->ports[i]);
622 handled++;
623 } else
624 printk(KERN_ERR DRV_NAME
625 ": interrupt from disabled port %d\n", i);
626 }
627
628 spin_unlock(&host_set->lock);
629 out:
630 return IRQ_RETVAL(handled);
631}
632
633static int sil24_port_start(struct ata_port *ap)
634{
635 struct device *dev = ap->host_set->dev;
636 struct sil24_port_priv *pp;
637 struct sil24_cmd_block *cb;
638 size_t cb_size = sizeof(*cb);
639 dma_addr_t cb_dma;
640
641 pp = kmalloc(sizeof(*pp), GFP_KERNEL);
642 if (!pp)
643 return -ENOMEM;
644 memset(pp, 0, sizeof(*pp));
645
646 pp->tf.command = ATA_DRDY;
647
648 cb = dma_alloc_coherent(dev, cb_size, &cb_dma, GFP_KERNEL);
649 if (!cb) {
650 kfree(pp);
651 return -ENOMEM;
652 }
653 memset(cb, 0, cb_size);
654
655 pp->cmd_block = cb;
656 pp->cmd_block_dma = cb_dma;
657
658 ap->private_data = pp;
659
660 return 0;
661}
662
663static void sil24_port_stop(struct ata_port *ap)
664{
665 struct device *dev = ap->host_set->dev;
666 struct sil24_port_priv *pp = ap->private_data;
667 size_t cb_size = sizeof(*pp->cmd_block);
668
669 dma_free_coherent(dev, cb_size, pp->cmd_block, pp->cmd_block_dma);
670 kfree(pp);
671}
672
673static void sil24_host_stop(struct ata_host_set *host_set)
674{
675 struct sil24_host_priv *hpriv = host_set->private_data;
676
677 iounmap(hpriv->host_base);
678 iounmap(hpriv->port_base);
679 kfree(hpriv);
680}
681
682static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
683{
684 static int printed_version = 0;
685 unsigned int board_id = (unsigned int)ent->driver_data;
686 struct ata_port_info *pinfo = &sil24_port_info[board_id];
687 struct ata_probe_ent *probe_ent = NULL;
688 struct sil24_host_priv *hpriv = NULL;
689 void __iomem *host_base = NULL;
690 void __iomem *port_base = NULL;
691 int i, rc;
692
693 if (!printed_version++)
694 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
695
696 rc = pci_enable_device(pdev);
697 if (rc)
698 return rc;
699
700 rc = pci_request_regions(pdev, DRV_NAME);
701 if (rc)
702 goto out_disable;
703
704 rc = -ENOMEM;
705 /* ioremap mmio registers */
706 host_base = ioremap(pci_resource_start(pdev, 0),
707 pci_resource_len(pdev, 0));
708 if (!host_base)
709 goto out_free;
710 port_base = ioremap(pci_resource_start(pdev, 2),
711 pci_resource_len(pdev, 2));
712 if (!port_base)
713 goto out_free;
714
715 /* allocate & init probe_ent and hpriv */
716 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL);
717 if (!probe_ent)
718 goto out_free;
719
720 hpriv = kmalloc(sizeof(*hpriv), GFP_KERNEL);
721 if (!hpriv)
722 goto out_free;
723
724 memset(probe_ent, 0, sizeof(*probe_ent));
725 probe_ent->dev = pci_dev_to_dev(pdev);
726 INIT_LIST_HEAD(&probe_ent->node);
727
728 probe_ent->sht = pinfo->sht;
729 probe_ent->host_flags = pinfo->host_flags;
730 probe_ent->pio_mask = pinfo->pio_mask;
731 probe_ent->udma_mask = pinfo->udma_mask;
732 probe_ent->port_ops = pinfo->port_ops;
733 probe_ent->n_ports = SIL24_FLAG2NPORTS(pinfo->host_flags);
734
735 probe_ent->irq = pdev->irq;
736 probe_ent->irq_flags = SA_SHIRQ;
737 probe_ent->mmio_base = port_base;
738 probe_ent->private_data = hpriv;
739
740 memset(hpriv, 0, sizeof(*hpriv));
741 hpriv->host_base = host_base;
742 hpriv->port_base = port_base;
743
744 /*
745 * Configure the device
746 */
747 /*
748 * FIXME: This device is certainly 64-bit capable. We just
749 * don't know how to use it. After fixing 32bit activation in
750 * this function, enable 64bit masks here.
751 */
752 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
753 if (rc) {
754 dev_printk(KERN_ERR, &pdev->dev,
755 "32-bit DMA enable failed\n");
756 goto out_free;
757 }
758 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
759 if (rc) {
760 dev_printk(KERN_ERR, &pdev->dev,
761 "32-bit consistent DMA enable failed\n");
762 goto out_free;
763 }
764
765 /* GPIO off */
766 writel(0, host_base + HOST_FLASH_CMD);
767
768 /* Mask interrupts during initialization */
769 writel(0, host_base + HOST_CTRL);
770
771 for (i = 0; i < probe_ent->n_ports; i++) {
772 void __iomem *port = port_base + i * PORT_REGS_SIZE;
773 unsigned long portu = (unsigned long)port;
774 u32 tmp;
775 int cnt;
776
777 probe_ent->port[i].cmd_addr = portu + PORT_PRB;
778 probe_ent->port[i].scr_addr = portu + PORT_SCONTROL;
779
780 ata_std_ports(&probe_ent->port[i]);
781
782 /* Initial PHY setting */
783 writel(0x20c, port + PORT_PHY_CFG);
784
785 /* Clear port RST */
786 tmp = readl(port + PORT_CTRL_STAT);
787 if (tmp & PORT_CS_PORT_RST) {
788 writel(PORT_CS_PORT_RST, port + PORT_CTRL_CLR);
789 readl(port + PORT_CTRL_STAT); /* sync */
790 for (cnt = 0; cnt < 10; cnt++) {
791 msleep(10);
792 tmp = readl(port + PORT_CTRL_STAT);
793 if (!(tmp & PORT_CS_PORT_RST))
794 break;
795 }
796 if (tmp & PORT_CS_PORT_RST)
797 dev_printk(KERN_ERR, &pdev->dev,
798 "failed to clear port RST\n");
799 }
800
801 /* Zero error counters. */
802 writel(0x8000, port + PORT_DECODE_ERR_THRESH);
803 writel(0x8000, port + PORT_CRC_ERR_THRESH);
804 writel(0x8000, port + PORT_HSHK_ERR_THRESH);
805 writel(0x0000, port + PORT_DECODE_ERR_CNT);
806 writel(0x0000, port + PORT_CRC_ERR_CNT);
807 writel(0x0000, port + PORT_HSHK_ERR_CNT);
808
809 /* FIXME: 32bit activation? */
810 writel(0, port + PORT_ACTIVATE_UPPER_ADDR);
811 writel(PORT_CS_32BIT_ACTV, port + PORT_CTRL_STAT);
812
813 /* Configure interrupts */
814 writel(0xffff, port + PORT_IRQ_ENABLE_CLR);
815 writel(PORT_IRQ_COMPLETE | PORT_IRQ_ERROR | PORT_IRQ_SDB_FIS,
816 port + PORT_IRQ_ENABLE_SET);
817
818 /* Clear interrupts */
819 writel(0x0fff0fff, port + PORT_IRQ_STAT);
820 writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_CLR);
821
822 /* Clear port multiplier enable and resume bits */
823 writel(PORT_CS_PM_EN | PORT_CS_RESUME, port + PORT_CTRL_CLR);
824
825 /* Reset itself */
826 if (__sil24_reset_controller(port))
827 dev_printk(KERN_ERR, &pdev->dev,
828 "failed to reset controller\n");
829 }
830
831 /* Turn on interrupts */
832 writel(IRQ_STAT_4PORTS, host_base + HOST_CTRL);
833
834 pci_set_master(pdev);
835
836 /* FIXME: check ata_device_add return value */
837 ata_device_add(probe_ent);
838
839 kfree(probe_ent);
840 return 0;
841
842 out_free:
843 if (host_base)
844 iounmap(host_base);
845 if (port_base)
846 iounmap(port_base);
847 kfree(probe_ent);
848 kfree(hpriv);
849 pci_release_regions(pdev);
850 out_disable:
851 pci_disable_device(pdev);
852 return rc;
853}
854
855static int __init sil24_init(void)
856{
857 return pci_module_init(&sil24_pci_driver);
858}
859
860static void __exit sil24_exit(void)
861{
862 pci_unregister_driver(&sil24_pci_driver);
863}
864
865MODULE_AUTHOR("Tejun Heo");
866MODULE_DESCRIPTION("Silicon Image 3124/3132 SATA low-level driver");
867MODULE_LICENSE("GPL");
868MODULE_DEVICE_TABLE(pci, sil24_pci_tbl);
869
870module_init(sil24_init);
871module_exit(sil24_exit);
diff --git a/drivers/scsi/sata_sis.c b/drivers/scsi/sata_sis.c
index b227e51d12f4..42288be0e561 100644
--- a/drivers/scsi/sata_sis.c
+++ b/drivers/scsi/sata_sis.c
@@ -38,6 +38,7 @@
38#include <linux/blkdev.h> 38#include <linux/blkdev.h>
39#include <linux/delay.h> 39#include <linux/delay.h>
40#include <linux/interrupt.h> 40#include <linux/interrupt.h>
41#include <linux/device.h>
41#include "scsi.h" 42#include "scsi.h"
42#include <scsi/scsi_host.h> 43#include <scsi/scsi_host.h>
43#include <linux/libata.h> 44#include <linux/libata.h>
@@ -102,7 +103,7 @@ static Scsi_Host_Template sis_sht = {
102 .ordered_flush = 1, 103 .ordered_flush = 1,
103}; 104};
104 105
105static struct ata_port_operations sis_ops = { 106static const struct ata_port_operations sis_ops = {
106 .port_disable = ata_port_disable, 107 .port_disable = ata_port_disable,
107 .tf_load = ata_tf_load, 108 .tf_load = ata_tf_load,
108 .tf_read = ata_tf_read, 109 .tf_read = ata_tf_read,
@@ -237,6 +238,7 @@ static void sis_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
237 238
238static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 239static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
239{ 240{
241 static int printed_version;
240 struct ata_probe_ent *probe_ent = NULL; 242 struct ata_probe_ent *probe_ent = NULL;
241 int rc; 243 int rc;
242 u32 genctl; 244 u32 genctl;
@@ -245,6 +247,9 @@ static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
245 u8 pmr; 247 u8 pmr;
246 u8 port2_start; 248 u8 port2_start;
247 249
250 if (!printed_version++)
251 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
252
248 rc = pci_enable_device(pdev); 253 rc = pci_enable_device(pdev);
249 if (rc) 254 if (rc)
250 return rc; 255 return rc;
@@ -263,7 +268,7 @@ static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
263 goto err_out_regions; 268 goto err_out_regions;
264 269
265 ppi = &sis_port_info; 270 ppi = &sis_port_info;
266 probe_ent = ata_pci_init_native_mode(pdev, &ppi); 271 probe_ent = ata_pci_init_native_mode(pdev, &ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
267 if (!probe_ent) { 272 if (!probe_ent) {
268 rc = -ENOMEM; 273 rc = -ENOMEM;
269 goto err_out_regions; 274 goto err_out_regions;
@@ -288,16 +293,18 @@ static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
288 pci_read_config_byte(pdev, SIS_PMR, &pmr); 293 pci_read_config_byte(pdev, SIS_PMR, &pmr);
289 if (ent->device != 0x182) { 294 if (ent->device != 0x182) {
290 if ((pmr & SIS_PMR_COMBINED) == 0) { 295 if ((pmr & SIS_PMR_COMBINED) == 0) {
291 printk(KERN_INFO "sata_sis: Detected SiS 180/181 chipset in SATA mode\n"); 296 dev_printk(KERN_INFO, &pdev->dev,
297 "Detected SiS 180/181 chipset in SATA mode\n");
292 port2_start = 64; 298 port2_start = 64;
293 } 299 }
294 else { 300 else {
295 printk(KERN_INFO "sata_sis: Detected SiS 180/181 chipset in combined mode\n"); 301 dev_printk(KERN_INFO, &pdev->dev,
302 "Detected SiS 180/181 chipset in combined mode\n");
296 port2_start=0; 303 port2_start=0;
297 } 304 }
298 } 305 }
299 else { 306 else {
300 printk(KERN_INFO "sata_sis: Detected SiS 182 chipset\n"); 307 dev_printk(KERN_INFO, &pdev->dev, "Detected SiS 182 chipset\n");
301 port2_start = 0x20; 308 port2_start = 0x20;
302 } 309 }
303 310
diff --git a/drivers/scsi/sata_svw.c b/drivers/scsi/sata_svw.c
index d89d968bedac..db615ff794d8 100644
--- a/drivers/scsi/sata_svw.c
+++ b/drivers/scsi/sata_svw.c
@@ -44,6 +44,7 @@
44#include <linux/blkdev.h> 44#include <linux/blkdev.h>
45#include <linux/delay.h> 45#include <linux/delay.h>
46#include <linux/interrupt.h> 46#include <linux/interrupt.h>
47#include <linux/device.h>
47#include "scsi.h" 48#include "scsi.h"
48#include <scsi/scsi_host.h> 49#include <scsi/scsi_host.h>
49#include <linux/libata.h> 50#include <linux/libata.h>
@@ -84,6 +85,8 @@
84/* Port stride */ 85/* Port stride */
85#define K2_SATA_PORT_OFFSET 0x100 86#define K2_SATA_PORT_OFFSET 0x100
86 87
88static u8 k2_stat_check_status(struct ata_port *ap);
89
87 90
88static u32 k2_sata_scr_read (struct ata_port *ap, unsigned int sc_reg) 91static u32 k2_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
89{ 92{
@@ -102,7 +105,7 @@ static void k2_sata_scr_write (struct ata_port *ap, unsigned int sc_reg,
102} 105}
103 106
104 107
105static void k2_sata_tf_load(struct ata_port *ap, struct ata_taskfile *tf) 108static void k2_sata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
106{ 109{
107 struct ata_ioports *ioaddr = &ap->ioaddr; 110 struct ata_ioports *ioaddr = &ap->ioaddr;
108 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; 111 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
@@ -136,16 +139,24 @@ static void k2_sata_tf_load(struct ata_port *ap, struct ata_taskfile *tf)
136static void k2_sata_tf_read(struct ata_port *ap, struct ata_taskfile *tf) 139static void k2_sata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
137{ 140{
138 struct ata_ioports *ioaddr = &ap->ioaddr; 141 struct ata_ioports *ioaddr = &ap->ioaddr;
139 u16 nsect, lbal, lbam, lbah; 142 u16 nsect, lbal, lbam, lbah, feature;
140 143
141 nsect = tf->nsect = readw(ioaddr->nsect_addr); 144 tf->command = k2_stat_check_status(ap);
142 lbal = tf->lbal = readw(ioaddr->lbal_addr);
143 lbam = tf->lbam = readw(ioaddr->lbam_addr);
144 lbah = tf->lbah = readw(ioaddr->lbah_addr);
145 tf->device = readw(ioaddr->device_addr); 145 tf->device = readw(ioaddr->device_addr);
146 feature = readw(ioaddr->error_addr);
147 nsect = readw(ioaddr->nsect_addr);
148 lbal = readw(ioaddr->lbal_addr);
149 lbam = readw(ioaddr->lbam_addr);
150 lbah = readw(ioaddr->lbah_addr);
151
152 tf->feature = feature;
153 tf->nsect = nsect;
154 tf->lbal = lbal;
155 tf->lbam = lbam;
156 tf->lbah = lbah;
146 157
147 if (tf->flags & ATA_TFLAG_LBA48) { 158 if (tf->flags & ATA_TFLAG_LBA48) {
148 tf->hob_feature = readw(ioaddr->error_addr) >> 8; 159 tf->hob_feature = feature >> 8;
149 tf->hob_nsect = nsect >> 8; 160 tf->hob_nsect = nsect >> 8;
150 tf->hob_lbal = lbal >> 8; 161 tf->hob_lbal = lbal >> 8;
151 tf->hob_lbam = lbam >> 8; 162 tf->hob_lbam = lbam >> 8;
@@ -297,7 +308,7 @@ static Scsi_Host_Template k2_sata_sht = {
297}; 308};
298 309
299 310
300static struct ata_port_operations k2_sata_ops = { 311static const struct ata_port_operations k2_sata_ops = {
301 .port_disable = ata_port_disable, 312 .port_disable = ata_port_disable,
302 .tf_load = k2_sata_tf_load, 313 .tf_load = k2_sata_tf_load,
303 .tf_read = k2_sata_tf_read, 314 .tf_read = k2_sata_tf_read,
@@ -352,7 +363,7 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
352 int i; 363 int i;
353 364
354 if (!printed_version++) 365 if (!printed_version++)
355 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 366 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
356 367
357 /* 368 /*
358 * If this driver happens to only be useful on Apple's K2, then 369 * If this driver happens to only be useful on Apple's K2, then
diff --git a/drivers/scsi/sata_sx4.c b/drivers/scsi/sata_sx4.c
index 540a85191172..0ec21e09f5d8 100644
--- a/drivers/scsi/sata_sx4.c
+++ b/drivers/scsi/sata_sx4.c
@@ -38,6 +38,7 @@
38#include <linux/delay.h> 38#include <linux/delay.h>
39#include <linux/interrupt.h> 39#include <linux/interrupt.h>
40#include <linux/sched.h> 40#include <linux/sched.h>
41#include <linux/device.h>
41#include "scsi.h" 42#include "scsi.h"
42#include <scsi/scsi_host.h> 43#include <scsi/scsi_host.h>
43#include <linux/libata.h> 44#include <linux/libata.h>
@@ -137,7 +138,7 @@ struct pdc_port_priv {
137}; 138};
138 139
139struct pdc_host_priv { 140struct pdc_host_priv {
140 void *dimm_mmio; 141 void __iomem *dimm_mmio;
141 142
142 unsigned int doing_hdma; 143 unsigned int doing_hdma;
143 unsigned int hdma_prod; 144 unsigned int hdma_prod;
@@ -157,8 +158,8 @@ static void pdc_20621_phy_reset (struct ata_port *ap);
157static int pdc_port_start(struct ata_port *ap); 158static int pdc_port_start(struct ata_port *ap);
158static void pdc_port_stop(struct ata_port *ap); 159static void pdc_port_stop(struct ata_port *ap);
159static void pdc20621_qc_prep(struct ata_queued_cmd *qc); 160static void pdc20621_qc_prep(struct ata_queued_cmd *qc);
160static void pdc_tf_load_mmio(struct ata_port *ap, struct ata_taskfile *tf); 161static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
161static void pdc_exec_command_mmio(struct ata_port *ap, struct ata_taskfile *tf); 162static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
162static void pdc20621_host_stop(struct ata_host_set *host_set); 163static void pdc20621_host_stop(struct ata_host_set *host_set);
163static unsigned int pdc20621_dimm_init(struct ata_probe_ent *pe); 164static unsigned int pdc20621_dimm_init(struct ata_probe_ent *pe);
164static int pdc20621_detect_dimm(struct ata_probe_ent *pe); 165static int pdc20621_detect_dimm(struct ata_probe_ent *pe);
@@ -196,7 +197,7 @@ static Scsi_Host_Template pdc_sata_sht = {
196 .ordered_flush = 1, 197 .ordered_flush = 1,
197}; 198};
198 199
199static struct ata_port_operations pdc_20621_ops = { 200static const struct ata_port_operations pdc_20621_ops = {
200 .port_disable = ata_port_disable, 201 .port_disable = ata_port_disable,
201 .tf_load = pdc_tf_load_mmio, 202 .tf_load = pdc_tf_load_mmio,
202 .tf_read = ata_tf_read, 203 .tf_read = ata_tf_read,
@@ -247,7 +248,7 @@ static void pdc20621_host_stop(struct ata_host_set *host_set)
247{ 248{
248 struct pci_dev *pdev = to_pci_dev(host_set->dev); 249 struct pci_dev *pdev = to_pci_dev(host_set->dev);
249 struct pdc_host_priv *hpriv = host_set->private_data; 250 struct pdc_host_priv *hpriv = host_set->private_data;
250 void *dimm_mmio = hpriv->dimm_mmio; 251 void __iomem *dimm_mmio = hpriv->dimm_mmio;
251 252
252 pci_iounmap(pdev, dimm_mmio); 253 pci_iounmap(pdev, dimm_mmio);
253 kfree(hpriv); 254 kfree(hpriv);
@@ -669,8 +670,8 @@ static void pdc20621_packet_start(struct ata_queued_cmd *qc)
669 readl(mmio + PDC_20621_SEQCTL + (seq * 4)); /* flush */ 670 readl(mmio + PDC_20621_SEQCTL + (seq * 4)); /* flush */
670 671
671 writel(port_ofs + PDC_DIMM_ATA_PKT, 672 writel(port_ofs + PDC_DIMM_ATA_PKT,
672 (void *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); 673 (void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
673 readl((void *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); 674 readl((void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
674 VPRINTK("submitted ofs 0x%x (%u), seq %u\n", 675 VPRINTK("submitted ofs 0x%x (%u), seq %u\n",
675 port_ofs + PDC_DIMM_ATA_PKT, 676 port_ofs + PDC_DIMM_ATA_PKT,
676 port_ofs + PDC_DIMM_ATA_PKT, 677 port_ofs + PDC_DIMM_ATA_PKT,
@@ -718,7 +719,7 @@ static inline unsigned int pdc20621_host_intr( struct ata_port *ap,
718 VPRINTK("ata%u: read hdma, 0x%x 0x%x\n", ap->id, 719 VPRINTK("ata%u: read hdma, 0x%x 0x%x\n", ap->id,
719 readl(mmio + 0x104), readl(mmio + PDC_HDMA_CTLSTAT)); 720 readl(mmio + 0x104), readl(mmio + PDC_HDMA_CTLSTAT));
720 /* get drive status; clear intr; complete txn */ 721 /* get drive status; clear intr; complete txn */
721 ata_qc_complete(qc, ata_wait_idle(ap)); 722 ata_qc_complete(qc, ac_err_mask(ata_wait_idle(ap)));
722 pdc20621_pop_hdma(qc); 723 pdc20621_pop_hdma(qc);
723 } 724 }
724 725
@@ -747,8 +748,8 @@ static inline unsigned int pdc20621_host_intr( struct ata_port *ap,
747 writel(0x00000001, mmio + PDC_20621_SEQCTL + (seq * 4)); 748 writel(0x00000001, mmio + PDC_20621_SEQCTL + (seq * 4));
748 readl(mmio + PDC_20621_SEQCTL + (seq * 4)); 749 readl(mmio + PDC_20621_SEQCTL + (seq * 4));
749 writel(port_ofs + PDC_DIMM_ATA_PKT, 750 writel(port_ofs + PDC_DIMM_ATA_PKT,
750 (void *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); 751 (void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
751 readl((void *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); 752 readl((void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
752 } 753 }
753 754
754 /* step two - execute ATA command */ 755 /* step two - execute ATA command */
@@ -756,7 +757,7 @@ static inline unsigned int pdc20621_host_intr( struct ata_port *ap,
756 VPRINTK("ata%u: write ata, 0x%x 0x%x\n", ap->id, 757 VPRINTK("ata%u: write ata, 0x%x 0x%x\n", ap->id,
757 readl(mmio + 0x104), readl(mmio + PDC_HDMA_CTLSTAT)); 758 readl(mmio + 0x104), readl(mmio + PDC_HDMA_CTLSTAT));
758 /* get drive status; clear intr; complete txn */ 759 /* get drive status; clear intr; complete txn */
759 ata_qc_complete(qc, ata_wait_idle(ap)); 760 ata_qc_complete(qc, ac_err_mask(ata_wait_idle(ap)));
760 pdc20621_pop_hdma(qc); 761 pdc20621_pop_hdma(qc);
761 } 762 }
762 handled = 1; 763 handled = 1;
@@ -766,7 +767,7 @@ static inline unsigned int pdc20621_host_intr( struct ata_port *ap,
766 767
767 status = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000); 768 status = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
768 DPRINTK("BUS_NODATA (drv_stat 0x%X)\n", status); 769 DPRINTK("BUS_NODATA (drv_stat 0x%X)\n", status);
769 ata_qc_complete(qc, status); 770 ata_qc_complete(qc, ac_err_mask(status));
770 handled = 1; 771 handled = 1;
771 772
772 } else { 773 } else {
@@ -881,7 +882,7 @@ static void pdc_eng_timeout(struct ata_port *ap)
881 case ATA_PROT_DMA: 882 case ATA_PROT_DMA:
882 case ATA_PROT_NODATA: 883 case ATA_PROT_NODATA:
883 printk(KERN_ERR "ata%u: command timeout\n", ap->id); 884 printk(KERN_ERR "ata%u: command timeout\n", ap->id);
884 ata_qc_complete(qc, ata_wait_idle(ap) | ATA_ERR); 885 ata_qc_complete(qc, __ac_err_mask(ata_wait_idle(ap)));
885 break; 886 break;
886 887
887 default: 888 default:
@@ -890,7 +891,7 @@ static void pdc_eng_timeout(struct ata_port *ap)
890 printk(KERN_ERR "ata%u: unknown timeout, cmd 0x%x stat 0x%x\n", 891 printk(KERN_ERR "ata%u: unknown timeout, cmd 0x%x stat 0x%x\n",
891 ap->id, qc->tf.command, drv_stat); 892 ap->id, qc->tf.command, drv_stat);
892 893
893 ata_qc_complete(qc, drv_stat); 894 ata_qc_complete(qc, ac_err_mask(drv_stat));
894 break; 895 break;
895 } 896 }
896 897
@@ -899,7 +900,7 @@ out:
899 DPRINTK("EXIT\n"); 900 DPRINTK("EXIT\n");
900} 901}
901 902
902static void pdc_tf_load_mmio(struct ata_port *ap, struct ata_taskfile *tf) 903static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
903{ 904{
904 WARN_ON (tf->protocol == ATA_PROT_DMA || 905 WARN_ON (tf->protocol == ATA_PROT_DMA ||
905 tf->protocol == ATA_PROT_NODATA); 906 tf->protocol == ATA_PROT_NODATA);
@@ -907,7 +908,7 @@ static void pdc_tf_load_mmio(struct ata_port *ap, struct ata_taskfile *tf)
907} 908}
908 909
909 910
910static void pdc_exec_command_mmio(struct ata_port *ap, struct ata_taskfile *tf) 911static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
911{ 912{
912 WARN_ON (tf->protocol == ATA_PROT_DMA || 913 WARN_ON (tf->protocol == ATA_PROT_DMA ||
913 tf->protocol == ATA_PROT_NODATA); 914 tf->protocol == ATA_PROT_NODATA);
@@ -1014,7 +1015,7 @@ static void pdc20621_put_to_dimm(struct ata_probe_ent *pe, void *psource,
1014 idx++; 1015 idx++;
1015 dist = ((long)(s32)(window_size - (offset + size))) >= 0 ? size : 1016 dist = ((long)(s32)(window_size - (offset + size))) >= 0 ? size :
1016 (long) (window_size - offset); 1017 (long) (window_size - offset);
1017 memcpy_toio((char *) (dimm_mmio + offset / 4), (char *) psource, dist); 1018 memcpy_toio(dimm_mmio + offset / 4, psource, dist);
1018 writel(0x01, mmio + PDC_GENERAL_CTLR); 1019 writel(0x01, mmio + PDC_GENERAL_CTLR);
1019 readl(mmio + PDC_GENERAL_CTLR); 1020 readl(mmio + PDC_GENERAL_CTLR);
1020 1021
@@ -1023,8 +1024,7 @@ static void pdc20621_put_to_dimm(struct ata_probe_ent *pe, void *psource,
1023 for (; (long) size >= (long) window_size ;) { 1024 for (; (long) size >= (long) window_size ;) {
1024 writel(((idx) << page_mask), mmio + PDC_DIMM_WINDOW_CTLR); 1025 writel(((idx) << page_mask), mmio + PDC_DIMM_WINDOW_CTLR);
1025 readl(mmio + PDC_DIMM_WINDOW_CTLR); 1026 readl(mmio + PDC_DIMM_WINDOW_CTLR);
1026 memcpy_toio((char *) (dimm_mmio), (char *) psource, 1027 memcpy_toio(dimm_mmio, psource, window_size / 4);
1027 window_size / 4);
1028 writel(0x01, mmio + PDC_GENERAL_CTLR); 1028 writel(0x01, mmio + PDC_GENERAL_CTLR);
1029 readl(mmio + PDC_GENERAL_CTLR); 1029 readl(mmio + PDC_GENERAL_CTLR);
1030 psource += window_size; 1030 psource += window_size;
@@ -1035,7 +1035,7 @@ static void pdc20621_put_to_dimm(struct ata_probe_ent *pe, void *psource,
1035 if (size) { 1035 if (size) {
1036 writel(((idx) << page_mask), mmio + PDC_DIMM_WINDOW_CTLR); 1036 writel(((idx) << page_mask), mmio + PDC_DIMM_WINDOW_CTLR);
1037 readl(mmio + PDC_DIMM_WINDOW_CTLR); 1037 readl(mmio + PDC_DIMM_WINDOW_CTLR);
1038 memcpy_toio((char *) (dimm_mmio), (char *) psource, size / 4); 1038 memcpy_toio(dimm_mmio, psource, size / 4);
1039 writel(0x01, mmio + PDC_GENERAL_CTLR); 1039 writel(0x01, mmio + PDC_GENERAL_CTLR);
1040 readl(mmio + PDC_GENERAL_CTLR); 1040 readl(mmio + PDC_GENERAL_CTLR);
1041 } 1041 }
@@ -1386,7 +1386,7 @@ static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *
1386 int rc; 1386 int rc;
1387 1387
1388 if (!printed_version++) 1388 if (!printed_version++)
1389 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 1389 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
1390 1390
1391 /* 1391 /*
1392 * If this driver happens to only be useful on Apple's K2, then 1392 * If this driver happens to only be useful on Apple's K2, then
diff --git a/drivers/scsi/sata_uli.c b/drivers/scsi/sata_uli.c
index 4c9fb8b71be1..a5e245c098e1 100644
--- a/drivers/scsi/sata_uli.c
+++ b/drivers/scsi/sata_uli.c
@@ -32,6 +32,7 @@
32#include <linux/blkdev.h> 32#include <linux/blkdev.h>
33#include <linux/delay.h> 33#include <linux/delay.h>
34#include <linux/interrupt.h> 34#include <linux/interrupt.h>
35#include <linux/device.h>
35#include "scsi.h" 36#include "scsi.h"
36#include <scsi/scsi_host.h> 37#include <scsi/scsi_host.h>
37#include <linux/libata.h> 38#include <linux/libata.h>
@@ -90,7 +91,7 @@ static Scsi_Host_Template uli_sht = {
90 .ordered_flush = 1, 91 .ordered_flush = 1,
91}; 92};
92 93
93static struct ata_port_operations uli_ops = { 94static const struct ata_port_operations uli_ops = {
94 .port_disable = ata_port_disable, 95 .port_disable = ata_port_disable,
95 96
96 .tf_load = ata_tf_load, 97 .tf_load = ata_tf_load,
@@ -178,12 +179,16 @@ static void uli_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
178 179
179static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 180static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
180{ 181{
182 static int printed_version;
181 struct ata_probe_ent *probe_ent; 183 struct ata_probe_ent *probe_ent;
182 struct ata_port_info *ppi; 184 struct ata_port_info *ppi;
183 int rc; 185 int rc;
184 unsigned int board_idx = (unsigned int) ent->driver_data; 186 unsigned int board_idx = (unsigned int) ent->driver_data;
185 int pci_dev_busy = 0; 187 int pci_dev_busy = 0;
186 188
189 if (!printed_version++)
190 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
191
187 rc = pci_enable_device(pdev); 192 rc = pci_enable_device(pdev);
188 if (rc) 193 if (rc)
189 return rc; 194 return rc;
@@ -202,7 +207,7 @@ static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
202 goto err_out_regions; 207 goto err_out_regions;
203 208
204 ppi = &uli_port_info; 209 ppi = &uli_port_info;
205 probe_ent = ata_pci_init_native_mode(pdev, &ppi); 210 probe_ent = ata_pci_init_native_mode(pdev, &ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
206 if (!probe_ent) { 211 if (!probe_ent) {
207 rc = -ENOMEM; 212 rc = -ENOMEM;
208 goto err_out_regions; 213 goto err_out_regions;
diff --git a/drivers/scsi/sata_via.c b/drivers/scsi/sata_via.c
index 128b996b07b7..b3ecdbe400e9 100644
--- a/drivers/scsi/sata_via.c
+++ b/drivers/scsi/sata_via.c
@@ -41,6 +41,7 @@
41#include <linux/init.h> 41#include <linux/init.h>
42#include <linux/blkdev.h> 42#include <linux/blkdev.h>
43#include <linux/delay.h> 43#include <linux/delay.h>
44#include <linux/device.h>
44#include "scsi.h" 45#include "scsi.h"
45#include <scsi/scsi_host.h> 46#include <scsi/scsi_host.h>
46#include <linux/libata.h> 47#include <linux/libata.h>
@@ -109,7 +110,7 @@ static Scsi_Host_Template svia_sht = {
109 .ordered_flush = 1, 110 .ordered_flush = 1,
110}; 111};
111 112
112static struct ata_port_operations svia_sata_ops = { 113static const struct ata_port_operations svia_sata_ops = {
113 .port_disable = ata_port_disable, 114 .port_disable = ata_port_disable,
114 115
115 .tf_load = ata_tf_load, 116 .tf_load = ata_tf_load,
@@ -212,7 +213,7 @@ static struct ata_probe_ent *vt6420_init_probe_ent(struct pci_dev *pdev)
212 struct ata_probe_ent *probe_ent; 213 struct ata_probe_ent *probe_ent;
213 struct ata_port_info *ppi = &svia_port_info; 214 struct ata_port_info *ppi = &svia_port_info;
214 215
215 probe_ent = ata_pci_init_native_mode(pdev, &ppi); 216 probe_ent = ata_pci_init_native_mode(pdev, &ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
216 if (!probe_ent) 217 if (!probe_ent)
217 return NULL; 218 return NULL;
218 219
@@ -259,15 +260,15 @@ static void svia_configure(struct pci_dev *pdev)
259 u8 tmp8; 260 u8 tmp8;
260 261
261 pci_read_config_byte(pdev, PCI_INTERRUPT_LINE, &tmp8); 262 pci_read_config_byte(pdev, PCI_INTERRUPT_LINE, &tmp8);
262 printk(KERN_INFO DRV_NAME "(%s): routed to hard irq line %d\n", 263 dev_printk(KERN_INFO, &pdev->dev, "routed to hard irq line %d\n",
263 pci_name(pdev),
264 (int) (tmp8 & 0xf0) == 0xf0 ? 0 : tmp8 & 0x0f); 264 (int) (tmp8 & 0xf0) == 0xf0 ? 0 : tmp8 & 0x0f);
265 265
266 /* make sure SATA channels are enabled */ 266 /* make sure SATA channels are enabled */
267 pci_read_config_byte(pdev, SATA_CHAN_ENAB, &tmp8); 267 pci_read_config_byte(pdev, SATA_CHAN_ENAB, &tmp8);
268 if ((tmp8 & ALL_PORTS) != ALL_PORTS) { 268 if ((tmp8 & ALL_PORTS) != ALL_PORTS) {
269 printk(KERN_DEBUG DRV_NAME "(%s): enabling SATA channels (0x%x)\n", 269 dev_printk(KERN_DEBUG, &pdev->dev,
270 pci_name(pdev), (int) tmp8); 270 "enabling SATA channels (0x%x)\n",
271 (int) tmp8);
271 tmp8 |= ALL_PORTS; 272 tmp8 |= ALL_PORTS;
272 pci_write_config_byte(pdev, SATA_CHAN_ENAB, tmp8); 273 pci_write_config_byte(pdev, SATA_CHAN_ENAB, tmp8);
273 } 274 }
@@ -275,8 +276,9 @@ static void svia_configure(struct pci_dev *pdev)
275 /* make sure interrupts for each channel sent to us */ 276 /* make sure interrupts for each channel sent to us */
276 pci_read_config_byte(pdev, SATA_INT_GATE, &tmp8); 277 pci_read_config_byte(pdev, SATA_INT_GATE, &tmp8);
277 if ((tmp8 & ALL_PORTS) != ALL_PORTS) { 278 if ((tmp8 & ALL_PORTS) != ALL_PORTS) {
278 printk(KERN_DEBUG DRV_NAME "(%s): enabling SATA channel interrupts (0x%x)\n", 279 dev_printk(KERN_DEBUG, &pdev->dev,
279 pci_name(pdev), (int) tmp8); 280 "enabling SATA channel interrupts (0x%x)\n",
281 (int) tmp8);
280 tmp8 |= ALL_PORTS; 282 tmp8 |= ALL_PORTS;
281 pci_write_config_byte(pdev, SATA_INT_GATE, tmp8); 283 pci_write_config_byte(pdev, SATA_INT_GATE, tmp8);
282 } 284 }
@@ -284,8 +286,9 @@ static void svia_configure(struct pci_dev *pdev)
284 /* make sure native mode is enabled */ 286 /* make sure native mode is enabled */
285 pci_read_config_byte(pdev, SATA_NATIVE_MODE, &tmp8); 287 pci_read_config_byte(pdev, SATA_NATIVE_MODE, &tmp8);
286 if ((tmp8 & NATIVE_MODE_ALL) != NATIVE_MODE_ALL) { 288 if ((tmp8 & NATIVE_MODE_ALL) != NATIVE_MODE_ALL) {
287 printk(KERN_DEBUG DRV_NAME "(%s): enabling SATA channel native mode (0x%x)\n", 289 dev_printk(KERN_DEBUG, &pdev->dev,
288 pci_name(pdev), (int) tmp8); 290 "enabling SATA channel native mode (0x%x)\n",
291 (int) tmp8);
289 tmp8 |= NATIVE_MODE_ALL; 292 tmp8 |= NATIVE_MODE_ALL;
290 pci_write_config_byte(pdev, SATA_NATIVE_MODE, tmp8); 293 pci_write_config_byte(pdev, SATA_NATIVE_MODE, tmp8);
291 } 294 }
@@ -303,7 +306,7 @@ static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
303 u8 tmp8; 306 u8 tmp8;
304 307
305 if (!printed_version++) 308 if (!printed_version++)
306 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 309 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
307 310
308 rc = pci_enable_device(pdev); 311 rc = pci_enable_device(pdev);
309 if (rc) 312 if (rc)
@@ -318,8 +321,9 @@ static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
318 if (board_id == vt6420) { 321 if (board_id == vt6420) {
319 pci_read_config_byte(pdev, SATA_PATA_SHARING, &tmp8); 322 pci_read_config_byte(pdev, SATA_PATA_SHARING, &tmp8);
320 if (tmp8 & SATA_2DEV) { 323 if (tmp8 & SATA_2DEV) {
321 printk(KERN_ERR DRV_NAME "(%s): SATA master/slave not supported (0x%x)\n", 324 dev_printk(KERN_ERR, &pdev->dev,
322 pci_name(pdev), (int) tmp8); 325 "SATA master/slave not supported (0x%x)\n",
326 (int) tmp8);
323 rc = -EIO; 327 rc = -EIO;
324 goto err_out_regions; 328 goto err_out_regions;
325 } 329 }
@@ -332,10 +336,11 @@ static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
332 for (i = 0; i < ARRAY_SIZE(svia_bar_sizes); i++) 336 for (i = 0; i < ARRAY_SIZE(svia_bar_sizes); i++)
333 if ((pci_resource_start(pdev, i) == 0) || 337 if ((pci_resource_start(pdev, i) == 0) ||
334 (pci_resource_len(pdev, i) < bar_sizes[i])) { 338 (pci_resource_len(pdev, i) < bar_sizes[i])) {
335 printk(KERN_ERR DRV_NAME "(%s): invalid PCI BAR %u (sz 0x%lx, val 0x%lx)\n", 339 dev_printk(KERN_ERR, &pdev->dev,
336 pci_name(pdev), i, 340 "invalid PCI BAR %u (sz 0x%lx, val 0x%lx)\n",
337 pci_resource_start(pdev, i), 341 i,
338 pci_resource_len(pdev, i)); 342 pci_resource_start(pdev, i),
343 pci_resource_len(pdev, i));
339 rc = -ENODEV; 344 rc = -ENODEV;
340 goto err_out_regions; 345 goto err_out_regions;
341 } 346 }
@@ -353,8 +358,7 @@ static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
353 probe_ent = vt6421_init_probe_ent(pdev); 358 probe_ent = vt6421_init_probe_ent(pdev);
354 359
355 if (!probe_ent) { 360 if (!probe_ent) {
356 printk(KERN_ERR DRV_NAME "(%s): out of memory\n", 361 dev_printk(KERN_ERR, &pdev->dev, "out of memory\n");
357 pci_name(pdev));
358 rc = -ENOMEM; 362 rc = -ENOMEM;
359 goto err_out_regions; 363 goto err_out_regions;
360 } 364 }
diff --git a/drivers/scsi/sata_vsc.c b/drivers/scsi/sata_vsc.c
index cf94e0158a8d..bb84ba0c7e83 100644
--- a/drivers/scsi/sata_vsc.c
+++ b/drivers/scsi/sata_vsc.c
@@ -42,6 +42,7 @@
42#include <linux/delay.h> 42#include <linux/delay.h>
43#include <linux/interrupt.h> 43#include <linux/interrupt.h>
44#include <linux/dma-mapping.h> 44#include <linux/dma-mapping.h>
45#include <linux/device.h>
45#include "scsi.h" 46#include "scsi.h"
46#include <scsi/scsi_host.h> 47#include <scsi/scsi_host.h>
47#include <linux/libata.h> 48#include <linux/libata.h>
@@ -86,7 +87,7 @@ static u32 vsc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
86{ 87{
87 if (sc_reg > SCR_CONTROL) 88 if (sc_reg > SCR_CONTROL)
88 return 0xffffffffU; 89 return 0xffffffffU;
89 return readl((void *) ap->ioaddr.scr_addr + (sc_reg * 4)); 90 return readl((void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
90} 91}
91 92
92 93
@@ -95,16 +96,16 @@ static void vsc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg,
95{ 96{
96 if (sc_reg > SCR_CONTROL) 97 if (sc_reg > SCR_CONTROL)
97 return; 98 return;
98 writel(val, (void *) ap->ioaddr.scr_addr + (sc_reg * 4)); 99 writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
99} 100}
100 101
101 102
102static void vsc_intr_mask_update(struct ata_port *ap, u8 ctl) 103static void vsc_intr_mask_update(struct ata_port *ap, u8 ctl)
103{ 104{
104 unsigned long mask_addr; 105 void __iomem *mask_addr;
105 u8 mask; 106 u8 mask;
106 107
107 mask_addr = (unsigned long) ap->host_set->mmio_base + 108 mask_addr = ap->host_set->mmio_base +
108 VSC_SATA_INT_MASK_OFFSET + ap->port_no; 109 VSC_SATA_INT_MASK_OFFSET + ap->port_no;
109 mask = readb(mask_addr); 110 mask = readb(mask_addr);
110 if (ctl & ATA_NIEN) 111 if (ctl & ATA_NIEN)
@@ -115,7 +116,7 @@ static void vsc_intr_mask_update(struct ata_port *ap, u8 ctl)
115} 116}
116 117
117 118
118static void vsc_sata_tf_load(struct ata_port *ap, struct ata_taskfile *tf) 119static void vsc_sata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
119{ 120{
120 struct ata_ioports *ioaddr = &ap->ioaddr; 121 struct ata_ioports *ioaddr = &ap->ioaddr;
121 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; 122 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
@@ -153,16 +154,24 @@ static void vsc_sata_tf_load(struct ata_port *ap, struct ata_taskfile *tf)
153static void vsc_sata_tf_read(struct ata_port *ap, struct ata_taskfile *tf) 154static void vsc_sata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
154{ 155{
155 struct ata_ioports *ioaddr = &ap->ioaddr; 156 struct ata_ioports *ioaddr = &ap->ioaddr;
156 u16 nsect, lbal, lbam, lbah; 157 u16 nsect, lbal, lbam, lbah, feature;
157 158
158 nsect = tf->nsect = readw(ioaddr->nsect_addr); 159 tf->command = ata_check_status(ap);
159 lbal = tf->lbal = readw(ioaddr->lbal_addr);
160 lbam = tf->lbam = readw(ioaddr->lbam_addr);
161 lbah = tf->lbah = readw(ioaddr->lbah_addr);
162 tf->device = readw(ioaddr->device_addr); 160 tf->device = readw(ioaddr->device_addr);
161 feature = readw(ioaddr->error_addr);
162 nsect = readw(ioaddr->nsect_addr);
163 lbal = readw(ioaddr->lbal_addr);
164 lbam = readw(ioaddr->lbam_addr);
165 lbah = readw(ioaddr->lbah_addr);
166
167 tf->feature = feature;
168 tf->nsect = nsect;
169 tf->lbal = lbal;
170 tf->lbam = lbam;
171 tf->lbah = lbah;
163 172
164 if (tf->flags & ATA_TFLAG_LBA48) { 173 if (tf->flags & ATA_TFLAG_LBA48) {
165 tf->hob_feature = readb(ioaddr->error_addr); 174 tf->hob_feature = feature >> 8;
166 tf->hob_nsect = nsect >> 8; 175 tf->hob_nsect = nsect >> 8;
167 tf->hob_lbal = lbal >> 8; 176 tf->hob_lbal = lbal >> 8;
168 tf->hob_lbam = lbam >> 8; 177 tf->hob_lbam = lbam >> 8;
@@ -231,7 +240,7 @@ static Scsi_Host_Template vsc_sata_sht = {
231}; 240};
232 241
233 242
234static struct ata_port_operations vsc_sata_ops = { 243static const struct ata_port_operations vsc_sata_ops = {
235 .port_disable = ata_port_disable, 244 .port_disable = ata_port_disable,
236 .tf_load = vsc_sata_tf_load, 245 .tf_load = vsc_sata_tf_load,
237 .tf_read = vsc_sata_tf_read, 246 .tf_read = vsc_sata_tf_read,
@@ -283,11 +292,11 @@ static int __devinit vsc_sata_init_one (struct pci_dev *pdev, const struct pci_d
283 struct ata_probe_ent *probe_ent = NULL; 292 struct ata_probe_ent *probe_ent = NULL;
284 unsigned long base; 293 unsigned long base;
285 int pci_dev_busy = 0; 294 int pci_dev_busy = 0;
286 void *mmio_base; 295 void __iomem *mmio_base;
287 int rc; 296 int rc;
288 297
289 if (!printed_version++) 298 if (!printed_version++)
290 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 299 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
291 300
292 rc = pci_enable_device(pdev); 301 rc = pci_enable_device(pdev);
293 if (rc) 302 if (rc)
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 1f0ebabf6d47..a5711d545d71 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -130,7 +130,7 @@ EXPORT_SYMBOL(scsi_device_types);
130 * Returns: Pointer to request block. 130 * Returns: Pointer to request block.
131 */ 131 */
132struct scsi_request *scsi_allocate_request(struct scsi_device *sdev, 132struct scsi_request *scsi_allocate_request(struct scsi_device *sdev,
133 int gfp_mask) 133 gfp_t gfp_mask)
134{ 134{
135 const int offset = ALIGN(sizeof(struct scsi_request), 4); 135 const int offset = ALIGN(sizeof(struct scsi_request), 4);
136 const int size = offset + sizeof(struct request); 136 const int size = offset + sizeof(struct request);
@@ -196,7 +196,7 @@ struct scsi_host_cmd_pool {
196 unsigned int users; 196 unsigned int users;
197 char *name; 197 char *name;
198 unsigned int slab_flags; 198 unsigned int slab_flags;
199 unsigned int gfp_mask; 199 gfp_t gfp_mask;
200}; 200};
201 201
202static struct scsi_host_cmd_pool scsi_cmd_pool = { 202static struct scsi_host_cmd_pool scsi_cmd_pool = {
@@ -213,7 +213,7 @@ static struct scsi_host_cmd_pool scsi_cmd_dma_pool = {
213static DECLARE_MUTEX(host_cmd_pool_mutex); 213static DECLARE_MUTEX(host_cmd_pool_mutex);
214 214
215static struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *shost, 215static struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *shost,
216 int gfp_mask) 216 gfp_t gfp_mask)
217{ 217{
218 struct scsi_cmnd *cmd; 218 struct scsi_cmnd *cmd;
219 219
@@ -245,7 +245,7 @@ static struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *shost,
245 * 245 *
246 * Returns: The allocated scsi command structure. 246 * Returns: The allocated scsi command structure.
247 */ 247 */
248struct scsi_cmnd *scsi_get_command(struct scsi_device *dev, int gfp_mask) 248struct scsi_cmnd *scsi_get_command(struct scsi_device *dev, gfp_t gfp_mask)
249{ 249{
250 struct scsi_cmnd *cmd; 250 struct scsi_cmnd *cmd;
251 251
diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c
index de7f98cc38fe..6a3f6aae8a97 100644
--- a/drivers/scsi/scsi_ioctl.c
+++ b/drivers/scsi/scsi_ioctl.c
@@ -205,7 +205,8 @@ int scsi_ioctl_send_command(struct scsi_device *sdev,
205 unsigned int inlen, outlen, cmdlen; 205 unsigned int inlen, outlen, cmdlen;
206 unsigned int needed, buf_needed; 206 unsigned int needed, buf_needed;
207 int timeout, retries, result; 207 int timeout, retries, result;
208 int data_direction, gfp_mask = GFP_KERNEL; 208 int data_direction;
209 gfp_t gfp_mask = GFP_KERNEL;
209 210
210 if (!sic) 211 if (!sic)
211 return -EINVAL; 212 return -EINVAL;
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 0074f28c37b2..3ff538809786 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -677,7 +677,7 @@ static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int uptodate,
677 return NULL; 677 return NULL;
678} 678}
679 679
680static struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd *cmd, int gfp_mask) 680static struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd *cmd, gfp_t gfp_mask)
681{ 681{
682 struct scsi_host_sg_pool *sgp; 682 struct scsi_host_sg_pool *sgp;
683 struct scatterlist *sgl; 683 struct scatterlist *sgl;
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 771e97ef136e..b856e140e65f 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -26,6 +26,7 @@
26 */ 26 */
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/sched.h> /* workqueue stuff, HZ */
29#include <scsi/scsi_device.h> 30#include <scsi/scsi_device.h>
30#include <scsi/scsi_host.h> 31#include <scsi/scsi_host.h>
31#include <scsi/scsi_transport.h> 32#include <scsi/scsi_transport.h>
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index 8bb8222ea589..d2caa35059d9 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -19,6 +19,9 @@
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#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/string.h>
23#include <linux/slab.h>
24
22#include <scsi/scsi.h> 25#include <scsi/scsi.h>
23#include <scsi/scsi_host.h> 26#include <scsi/scsi_host.h>
24#include <scsi/scsi_device.h> 27#include <scsi/scsi_device.h>
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index ad94367df430..d86d5c26061d 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -49,6 +49,7 @@ static int sg_version_num = 30533; /* 2 digits for each component */
49#include <linux/seq_file.h> 49#include <linux/seq_file.h>
50#include <linux/blkdev.h> 50#include <linux/blkdev.h>
51#include <linux/delay.h> 51#include <linux/delay.h>
52#include <linux/scatterlist.h>
52 53
53#include "scsi.h" 54#include "scsi.h"
54#include <scsi/scsi_dbg.h> 55#include <scsi/scsi_dbg.h>
@@ -104,8 +105,8 @@ static int sg_allow_dio = SG_ALLOW_DIO_DEF;
104 105
105#define SG_DEV_ARR_LUMP 32 /* amount to over allocate sg_dev_arr by */ 106#define SG_DEV_ARR_LUMP 32 /* amount to over allocate sg_dev_arr by */
106 107
107static int sg_add(struct class_device *); 108static int sg_add(struct class_device *, struct class_interface *);
108static void sg_remove(struct class_device *); 109static void sg_remove(struct class_device *, struct class_interface *);
109 110
110static Scsi_Request *dummy_cmdp; /* only used for sizeof */ 111static Scsi_Request *dummy_cmdp; /* only used for sizeof */
111 112
@@ -1506,7 +1507,7 @@ static int sg_alloc(struct gendisk *disk, struct scsi_device *scsidp)
1506} 1507}
1507 1508
1508static int 1509static int
1509sg_add(struct class_device *cl_dev) 1510sg_add(struct class_device *cl_dev, struct class_interface *cl_intf)
1510{ 1511{
1511 struct scsi_device *scsidp = to_scsi_device(cl_dev->dev); 1512 struct scsi_device *scsidp = to_scsi_device(cl_dev->dev);
1512 struct gendisk *disk; 1513 struct gendisk *disk;
@@ -1550,7 +1551,7 @@ sg_add(struct class_device *cl_dev)
1550 if (sg_sysfs_valid) { 1551 if (sg_sysfs_valid) {
1551 struct class_device * sg_class_member; 1552 struct class_device * sg_class_member;
1552 1553
1553 sg_class_member = class_device_create(sg_sysfs_class, 1554 sg_class_member = class_device_create(sg_sysfs_class, NULL,
1554 MKDEV(SCSI_GENERIC_MAJOR, k), 1555 MKDEV(SCSI_GENERIC_MAJOR, k),
1555 cl_dev->dev, "%s", 1556 cl_dev->dev, "%s",
1556 disk->disk_name); 1557 disk->disk_name);
@@ -1582,7 +1583,7 @@ out:
1582} 1583}
1583 1584
1584static void 1585static void
1585sg_remove(struct class_device *cl_dev) 1586sg_remove(struct class_device *cl_dev, struct class_interface *cl_intf)
1586{ 1587{
1587 struct scsi_device *scsidp = to_scsi_device(cl_dev->dev); 1588 struct scsi_device *scsidp = to_scsi_device(cl_dev->dev);
1588 Sg_device *sdp = NULL; 1589 Sg_device *sdp = NULL;
@@ -1886,13 +1887,17 @@ st_unmap_user_pages(struct scatterlist *sgl, const unsigned int nr_pages,
1886 int i; 1887 int i;
1887 1888
1888 for (i=0; i < nr_pages; i++) { 1889 for (i=0; i < nr_pages; i++) {
1889 if (dirtied && !PageReserved(sgl[i].page)) 1890 struct page *page = sgl[i].page;
1890 SetPageDirty(sgl[i].page); 1891
1891 /* unlock_page(sgl[i].page); */ 1892 /* XXX: just for debug. Remove when PageReserved is removed */
1893 BUG_ON(PageReserved(page));
1894 if (dirtied)
1895 SetPageDirty(page);
1896 /* unlock_page(page); */
1892 /* FIXME: cache flush missing for rw==READ 1897 /* FIXME: cache flush missing for rw==READ
1893 * FIXME: call the correct reference counting function 1898 * FIXME: call the correct reference counting function
1894 */ 1899 */
1895 page_cache_release(sgl[i].page); 1900 page_cache_release(page);
1896 } 1901 }
1897 1902
1898 return 0; 1903 return 0;
@@ -1992,9 +1997,7 @@ sg_build_indirect(Sg_scatter_hold * schp, Sg_fd * sfp, int buff_size)
1992 if (!p) 1997 if (!p)
1993 break; 1998 break;
1994 } 1999 }
1995 sclp->page = virt_to_page(p); 2000 sg_set_buf(sclp, p, ret_sz);
1996 sclp->offset = offset_in_page(p);
1997 sclp->length = ret_sz;
1998 2001
1999 SCSI_LOG_TIMEOUT(5, printk("sg_build_build: k=%d, a=0x%p, len=%d\n", 2002 SCSI_LOG_TIMEOUT(5, printk("sg_build_build: k=%d, a=0x%p, len=%d\n",
2000 k, sg_scatg2virt(sclp), ret_sz)); 2003 k, sg_scatg2virt(sclp), ret_sz));
@@ -2644,7 +2647,7 @@ static char *
2644sg_page_malloc(int rqSz, int lowDma, int *retSzp) 2647sg_page_malloc(int rqSz, int lowDma, int *retSzp)
2645{ 2648{
2646 char *resp = NULL; 2649 char *resp = NULL;
2647 int page_mask; 2650 gfp_t page_mask;
2648 int order, a_size; 2651 int order, a_size;
2649 int resSz = rqSz; 2652 int resSz = rqSz;
2650 2653
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index d001c046551b..da9766283bd7 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -3577,7 +3577,8 @@ static long st_compat_ioctl(struct file *file, unsigned int cmd, unsigned long a
3577static struct st_buffer * 3577static struct st_buffer *
3578 new_tape_buffer(int from_initialization, int need_dma, int max_sg) 3578 new_tape_buffer(int from_initialization, int need_dma, int max_sg)
3579{ 3579{
3580 int i, priority, got = 0, segs = 0; 3580 int i, got = 0, segs = 0;
3581 gfp_t priority;
3581 struct st_buffer *tb; 3582 struct st_buffer *tb;
3582 3583
3583 if (from_initialization) 3584 if (from_initialization)
@@ -3610,7 +3611,8 @@ static struct st_buffer *
3610/* Try to allocate enough space in the tape buffer */ 3611/* Try to allocate enough space in the tape buffer */
3611static int enlarge_buffer(struct st_buffer * STbuffer, int new_size, int need_dma) 3612static int enlarge_buffer(struct st_buffer * STbuffer, int new_size, int need_dma)
3612{ 3613{
3613 int segs, nbr, max_segs, b_size, priority, order, got; 3614 int segs, nbr, max_segs, b_size, order, got;
3615 gfp_t priority;
3614 3616
3615 if (new_size <= STbuffer->buffer_size) 3617 if (new_size <= STbuffer->buffer_size)
3616 return 1; 3618 return 1;
@@ -4375,7 +4377,7 @@ static void do_create_class_files(struct scsi_tape *STp, int dev_num, int mode)
4375 snprintf(name, 10, "%s%s%s", rew ? "n" : "", 4377 snprintf(name, 10, "%s%s%s", rew ? "n" : "",
4376 STp->disk->disk_name, st_formats[i]); 4378 STp->disk->disk_name, st_formats[i]);
4377 st_class_member = 4379 st_class_member =
4378 class_device_create(st_sysfs_class, 4380 class_device_create(st_sysfs_class, NULL,
4379 MKDEV(SCSI_TAPE_MAJOR, 4381 MKDEV(SCSI_TAPE_MAJOR,
4380 TAPE_MINOR(dev_num, mode, rew)), 4382 TAPE_MINOR(dev_num, mode, rew)),
4381 &STp->device->sdev_gendev, "%s", name); 4383 &STp->device->sdev_gendev, "%s", name);
@@ -4524,12 +4526,16 @@ static int sgl_unmap_user_pages(struct scatterlist *sgl, const unsigned int nr_p
4524 int i; 4526 int i;
4525 4527
4526 for (i=0; i < nr_pages; i++) { 4528 for (i=0; i < nr_pages; i++) {
4527 if (dirtied && !PageReserved(sgl[i].page)) 4529 struct page *page = sgl[i].page;
4528 SetPageDirty(sgl[i].page); 4530
4531 /* XXX: just for debug. Remove when PageReserved is removed */
4532 BUG_ON(PageReserved(page));
4533 if (dirtied)
4534 SetPageDirty(page);
4529 /* FIXME: cache flush missing for rw==READ 4535 /* FIXME: cache flush missing for rw==READ
4530 * FIXME: call the correct reference counting function 4536 * FIXME: call the correct reference counting function
4531 */ 4537 */
4532 page_cache_release(sgl[i].page); 4538 page_cache_release(page);
4533 } 4539 }
4534 4540
4535 return 0; 4541 return 0;
diff --git a/drivers/scsi/sym53c8xx_2/sym_hipd.c b/drivers/scsi/sym53c8xx_2/sym_hipd.c
index e753ba27dc59..a1a58e1d5ad3 100644
--- a/drivers/scsi/sym53c8xx_2/sym_hipd.c
+++ b/drivers/scsi/sym53c8xx_2/sym_hipd.c
@@ -37,6 +37,9 @@
37 * along with this program; if not, write to the Free Software 37 * along with this program; if not, write to the Free Software
38 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 38 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39 */ 39 */
40
41#include <linux/slab.h>
42
40#include "sym_glue.h" 43#include "sym_glue.h"
41#include "sym_nvram.h" 44#include "sym_nvram.h"
42 45
diff --git a/drivers/scsi/sym53c8xx_2/sym_hipd.h b/drivers/scsi/sym53c8xx_2/sym_hipd.h
index 3131a6bf7ab7..3a264a408216 100644
--- a/drivers/scsi/sym53c8xx_2/sym_hipd.h
+++ b/drivers/scsi/sym53c8xx_2/sym_hipd.h
@@ -37,6 +37,8 @@
37 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 37 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38 */ 38 */
39 39
40#include <linux/gfp.h>
41
40#ifndef SYM_HIPD_H 42#ifndef SYM_HIPD_H
41#define SYM_HIPD_H 43#define SYM_HIPD_H
42 44
diff --git a/drivers/scsi/zalon.c b/drivers/scsi/zalon.c
index 5a51051e31f0..b131432c677d 100644
--- a/drivers/scsi/zalon.c
+++ b/drivers/scsi/zalon.c
@@ -88,7 +88,7 @@ zalon_probe(struct parisc_device *dev)
88 struct gsc_irq gsc_irq; 88 struct gsc_irq gsc_irq;
89 u32 zalon_vers; 89 u32 zalon_vers;
90 int error = -ENODEV; 90 int error = -ENODEV;
91 void __iomem *zalon = ioremap(dev->hpa, 4096); 91 void __iomem *zalon = ioremap(dev->hpa.start, 4096);
92 void __iomem *io_port = zalon + GSC_SCSI_ZALON_OFFSET; 92 void __iomem *io_port = zalon + GSC_SCSI_ZALON_OFFSET;
93 static int unit = 0; 93 static int unit = 0;
94 struct Scsi_Host *host; 94 struct Scsi_Host *host;
@@ -127,7 +127,7 @@ zalon_probe(struct parisc_device *dev)
127 device.chip = zalon720_chip; 127 device.chip = zalon720_chip;
128 device.host_id = 7; 128 device.host_id = 7;
129 device.dev = &dev->dev; 129 device.dev = &dev->dev;
130 device.slot.base = dev->hpa + GSC_SCSI_ZALON_OFFSET; 130 device.slot.base = dev->hpa.start + GSC_SCSI_ZALON_OFFSET;
131 device.slot.base_v = io_port; 131 device.slot.base_v = io_port;
132 device.slot.irq = dev->irq; 132 device.slot.irq = dev->irq;
133 device.differential = 2; 133 device.differential = 2;
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index 4d75cdfa0a0a..afb7ddf200e0 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -2358,13 +2358,10 @@ static int __devexit serial8250_remove(struct device *dev)
2358 return 0; 2358 return 0;
2359} 2359}
2360 2360
2361static int serial8250_suspend(struct device *dev, pm_message_t state, u32 level) 2361static int serial8250_suspend(struct device *dev, pm_message_t state)
2362{ 2362{
2363 int i; 2363 int i;
2364 2364
2365 if (level != SUSPEND_DISABLE)
2366 return 0;
2367
2368 for (i = 0; i < UART_NR; i++) { 2365 for (i = 0; i < UART_NR; i++) {
2369 struct uart_8250_port *up = &serial8250_ports[i]; 2366 struct uart_8250_port *up = &serial8250_ports[i];
2370 2367
@@ -2375,13 +2372,10 @@ static int serial8250_suspend(struct device *dev, pm_message_t state, u32 level)
2375 return 0; 2372 return 0;
2376} 2373}
2377 2374
2378static int serial8250_resume(struct device *dev, u32 level) 2375static int serial8250_resume(struct device *dev)
2379{ 2376{
2380 int i; 2377 int i;
2381 2378
2382 if (level != RESUME_ENABLE)
2383 return 0;
2384
2385 for (i = 0; i < UART_NR; i++) { 2379 for (i = 0; i < UART_NR; i++) {
2386 struct uart_8250_port *up = &serial8250_ports[i]; 2380 struct uart_8250_port *up = &serial8250_ports[i];
2387 2381
diff --git a/drivers/serial/8250_gsc.c b/drivers/serial/8250_gsc.c
index 431aa5761a7a..8b4947933d9b 100644
--- a/drivers/serial/8250_gsc.c
+++ b/drivers/serial/8250_gsc.c
@@ -29,7 +29,6 @@
29static int __init 29static int __init
30serial_init_chip(struct parisc_device *dev) 30serial_init_chip(struct parisc_device *dev)
31{ 31{
32 static int serial_line_nr;
33 struct uart_port port; 32 struct uart_port port;
34 unsigned long address; 33 unsigned long address;
35 int err; 34 int err;
@@ -42,12 +41,13 @@ serial_init_chip(struct parisc_device *dev)
42 */ 41 */
43 if (parisc_parent(dev)->id.hw_type != HPHW_IOA) { 42 if (parisc_parent(dev)->id.hw_type != HPHW_IOA) {
44 printk(KERN_INFO "Serial: device 0x%lx not configured.\n" 43 printk(KERN_INFO "Serial: device 0x%lx not configured.\n"
45 "Enable support for Wax, Lasi, Asp or Dino.\n", dev->hpa); 44 "Enable support for Wax, Lasi, Asp or Dino.\n",
45 dev->hpa.start);
46 } 46 }
47 return -ENODEV; 47 return -ENODEV;
48 } 48 }
49 49
50 address = dev->hpa; 50 address = dev->hpa.start;
51 if (dev->id.sversion != 0x8d) { 51 if (dev->id.sversion != 0x8d) {
52 address += 0x800; 52 address += 0x800;
53 } 53 }
diff --git a/drivers/serial/amba-pl010.c b/drivers/serial/amba-pl010.c
index 679e678c7e6a..ddd0307fece2 100644
--- a/drivers/serial/amba-pl010.c
+++ b/drivers/serial/amba-pl010.c
@@ -50,6 +50,7 @@
50 50
51#include <asm/io.h> 51#include <asm/io.h>
52#include <asm/irq.h> 52#include <asm/irq.h>
53#include <asm/hardware.h>
53#include <asm/hardware/amba.h> 54#include <asm/hardware/amba.h>
54#include <asm/hardware/amba_serial.h> 55#include <asm/hardware/amba_serial.h>
55 56
diff --git a/drivers/serial/amba-pl011.c b/drivers/serial/amba-pl011.c
index 1ff629c74750..938d185841c9 100644
--- a/drivers/serial/amba-pl011.c
+++ b/drivers/serial/amba-pl011.c
@@ -50,6 +50,7 @@
50 50
51#include <asm/io.h> 51#include <asm/io.h>
52#include <asm/irq.h> 52#include <asm/irq.h>
53#include <asm/sizes.h>
53#include <asm/hardware/amba.h> 54#include <asm/hardware/amba.h>
54#include <asm/hardware/clock.h> 55#include <asm/hardware/clock.h>
55#include <asm/hardware/amba_serial.h> 56#include <asm/hardware/amba_serial.h>
diff --git a/drivers/serial/clps711x.c b/drivers/serial/clps711x.c
index 87ef368384fb..6a67e8f585b3 100644
--- a/drivers/serial/clps711x.c
+++ b/drivers/serial/clps711x.c
@@ -408,7 +408,11 @@ static struct uart_port clps711x_ports[UART_NR] = {
408 { 408 {
409 .iobase = SYSCON1, 409 .iobase = SYSCON1,
410 .irq = IRQ_UTXINT1, /* IRQ_URXINT1, IRQ_UMSINT */ 410 .irq = IRQ_UTXINT1, /* IRQ_URXINT1, IRQ_UMSINT */
411#ifdef CONFIG_MP1000_90MHZ
412 .uartclk = 4515840,
413#else
411 .uartclk = 3686400, 414 .uartclk = 3686400,
415#endif
412 .fifosize = 16, 416 .fifosize = 16,
413 .ops = &clps711x_pops, 417 .ops = &clps711x_pops,
414 .line = 0, 418 .line = 0,
@@ -417,7 +421,11 @@ static struct uart_port clps711x_ports[UART_NR] = {
417 { 421 {
418 .iobase = SYSCON2, 422 .iobase = SYSCON2,
419 .irq = IRQ_UTXINT2, /* IRQ_URXINT2 */ 423 .irq = IRQ_UTXINT2, /* IRQ_URXINT2 */
424#ifdef CONFIG_MP1000_90MHZ
425 .uartclk = 4515840,
426#else
420 .uartclk = 3686400, 427 .uartclk = 3686400,
428#endif
421 .fifosize = 16, 429 .fifosize = 16,
422 .ops = &clps711x_pops, 430 .ops = &clps711x_pops,
423 .line = 1, 431 .line = 1,
@@ -551,6 +559,7 @@ console_initcall(clps711xuart_console_init);
551static struct uart_driver clps711x_reg = { 559static struct uart_driver clps711x_reg = {
552 .driver_name = "ttyCL", 560 .driver_name = "ttyCL",
553 .dev_name = "ttyCL", 561 .dev_name = "ttyCL",
562 .devfs_name = "ttyCL",
554 .major = SERIAL_CLPS711X_MAJOR, 563 .major = SERIAL_CLPS711X_MAJOR,
555 .minor = SERIAL_CLPS711X_MINOR, 564 .minor = SERIAL_CLPS711X_MINOR,
556 .nr = UART_NR, 565 .nr = UART_NR,
diff --git a/drivers/serial/imx.c b/drivers/serial/imx.c
index bdb4e454b8b0..5b3933b0c997 100644
--- a/drivers/serial/imx.c
+++ b/drivers/serial/imx.c
@@ -921,21 +921,21 @@ static struct uart_driver imx_reg = {
921 .cons = IMX_CONSOLE, 921 .cons = IMX_CONSOLE,
922}; 922};
923 923
924static int serial_imx_suspend(struct device *_dev, pm_message_t state, u32 level) 924static int serial_imx_suspend(struct device *_dev, pm_message_t state)
925{ 925{
926 struct imx_port *sport = dev_get_drvdata(_dev); 926 struct imx_port *sport = dev_get_drvdata(_dev);
927 927
928 if (sport && level == SUSPEND_DISABLE) 928 if (sport)
929 uart_suspend_port(&imx_reg, &sport->port); 929 uart_suspend_port(&imx_reg, &sport->port);
930 930
931 return 0; 931 return 0;
932} 932}
933 933
934static int serial_imx_resume(struct device *_dev, u32 level) 934static int serial_imx_resume(struct device *_dev)
935{ 935{
936 struct imx_port *sport = dev_get_drvdata(_dev); 936 struct imx_port *sport = dev_get_drvdata(_dev);
937 937
938 if (sport && level == RESUME_ENABLE) 938 if (sport)
939 uart_resume_port(&imx_reg, &sport->port); 939 uart_resume_port(&imx_reg, &sport->port);
940 940
941 return 0; 941 return 0;
diff --git a/drivers/serial/ioc4_serial.c b/drivers/serial/ioc4_serial.c
index f88fdd480685..771676abee60 100644
--- a/drivers/serial/ioc4_serial.c
+++ b/drivers/serial/ioc4_serial.c
@@ -308,6 +308,8 @@ struct ioc4_serial {
308typedef void ioc4_intr_func_f(void *, uint32_t); 308typedef void ioc4_intr_func_f(void *, uint32_t);
309typedef ioc4_intr_func_f *ioc4_intr_func_t; 309typedef ioc4_intr_func_f *ioc4_intr_func_t;
310 310
311static unsigned int Num_of_ioc4_cards;
312
311/* defining this will get you LOTS of great debug info */ 313/* defining this will get you LOTS of great debug info */
312//#define DEBUG_INTERRUPTS 314//#define DEBUG_INTERRUPTS
313#define DPRINT_CONFIG(_x...) ; 315#define DPRINT_CONFIG(_x...) ;
@@ -317,7 +319,8 @@ typedef ioc4_intr_func_f *ioc4_intr_func_t;
317#define WAKEUP_CHARS 256 319#define WAKEUP_CHARS 256
318 320
319/* number of characters we want to transmit to the lower level at a time */ 321/* number of characters we want to transmit to the lower level at a time */
320#define IOC4_MAX_CHARS 128 322#define IOC4_MAX_CHARS 256
323#define IOC4_FIFO_CHARS 255
321 324
322/* Device name we're using */ 325/* Device name we're using */
323#define DEVICE_NAME "ttyIOC" 326#define DEVICE_NAME "ttyIOC"
@@ -1038,6 +1041,7 @@ static int inline ioc4_attach_local(struct ioc4_driver_data *idd)
1038 return -ENOMEM; 1041 return -ENOMEM;
1039 } 1042 }
1040 memset(port, 0, sizeof(struct ioc4_port)); 1043 memset(port, 0, sizeof(struct ioc4_port));
1044 spin_lock_init(&port->ip_lock);
1041 1045
1042 /* we need to remember the previous ones, to point back to 1046 /* we need to remember the previous ones, to point back to
1043 * them farther down - setting up the ring buffers. 1047 * them farther down - setting up the ring buffers.
@@ -1691,12 +1695,14 @@ ioc4_change_speed(struct uart_port *the_port,
1691 baud = 9600; 1695 baud = 9600;
1692 1696
1693 if (!the_port->fifosize) 1697 if (!the_port->fifosize)
1694 the_port->fifosize = IOC4_MAX_CHARS; 1698 the_port->fifosize = IOC4_FIFO_CHARS;
1695 the_port->timeout = ((the_port->fifosize * HZ * bits) / (baud / 10)); 1699 the_port->timeout = ((the_port->fifosize * HZ * bits) / (baud / 10));
1696 the_port->timeout += HZ / 50; /* Add .02 seconds of slop */ 1700 the_port->timeout += HZ / 50; /* Add .02 seconds of slop */
1697 1701
1698 the_port->ignore_status_mask = N_ALL_INPUT; 1702 the_port->ignore_status_mask = N_ALL_INPUT;
1699 1703
1704 info->tty->low_latency = 1;
1705
1700 if (I_IGNPAR(info->tty)) 1706 if (I_IGNPAR(info->tty))
1701 the_port->ignore_status_mask &= ~(N_PARITY_ERROR 1707 the_port->ignore_status_mask &= ~(N_PARITY_ERROR
1702 | N_FRAMING_ERROR); 1708 | N_FRAMING_ERROR);
@@ -1742,7 +1748,6 @@ ioc4_change_speed(struct uart_port *the_port,
1742 */ 1748 */
1743static inline int ic4_startup_local(struct uart_port *the_port) 1749static inline int ic4_startup_local(struct uart_port *the_port)
1744{ 1750{
1745 int retval = 0;
1746 struct ioc4_port *port; 1751 struct ioc4_port *port;
1747 struct uart_info *info; 1752 struct uart_info *info;
1748 1753
@@ -1754,9 +1759,6 @@ static inline int ic4_startup_local(struct uart_port *the_port)
1754 return -1; 1759 return -1;
1755 1760
1756 info = the_port->info; 1761 info = the_port->info;
1757 if (info->flags & UIF_INITIALIZED) {
1758 return retval;
1759 }
1760 1762
1761 if (info->tty) { 1763 if (info->tty) {
1762 set_bit(TTY_IO_ERROR, &info->tty->flags); 1764 set_bit(TTY_IO_ERROR, &info->tty->flags);
@@ -1775,7 +1777,6 @@ static inline int ic4_startup_local(struct uart_port *the_port)
1775 /* set the speed of the serial port */ 1777 /* set the speed of the serial port */
1776 ioc4_change_speed(the_port, info->tty->termios, (struct termios *)0); 1778 ioc4_change_speed(the_port, info->tty->termios, (struct termios *)0);
1777 1779
1778 info->flags |= UIF_INITIALIZED;
1779 return 0; 1780 return 0;
1780} 1781}
1781 1782
@@ -1785,9 +1786,13 @@ static inline int ic4_startup_local(struct uart_port *the_port)
1785 */ 1786 */
1786static void ioc4_cb_output_lowat(struct ioc4_port *port) 1787static void ioc4_cb_output_lowat(struct ioc4_port *port)
1787{ 1788{
1789 unsigned long pflags;
1790
1788 /* ip_lock is set on the call here */ 1791 /* ip_lock is set on the call here */
1789 if (port->ip_port) { 1792 if (port->ip_port) {
1793 spin_lock_irqsave(&port->ip_port->lock, pflags);
1790 transmit_chars(port->ip_port); 1794 transmit_chars(port->ip_port);
1795 spin_unlock_irqrestore(&port->ip_port->lock, pflags);
1791 } 1796 }
1792} 1797}
1793 1798
@@ -2064,8 +2069,7 @@ static inline int do_read(struct uart_port *the_port, unsigned char *buf,
2064 * available data as long as it returns some. 2069 * available data as long as it returns some.
2065 */ 2070 */
2066 /* Re-arm the timer */ 2071 /* Re-arm the timer */
2067 writel(port->ip_rx_cons | IOC4_SRCIR_ARM, 2072 writel(port->ip_rx_cons | IOC4_SRCIR_ARM, &port->ip_serial_regs->srcir);
2068 &port->ip_serial_regs->srcir);
2069 2073
2070 prod_ptr = readl(&port->ip_serial_regs->srpir) & PROD_CONS_MASK; 2074 prod_ptr = readl(&port->ip_serial_regs->srpir) & PROD_CONS_MASK;
2071 cons_ptr = port->ip_rx_cons; 2075 cons_ptr = port->ip_rx_cons;
@@ -2299,6 +2303,7 @@ static inline int do_read(struct uart_port *the_port, unsigned char *buf,
2299 } 2303 }
2300 return total; 2304 return total;
2301} 2305}
2306
2302/** 2307/**
2303 * receive_chars - upper level read. Called with ip_lock. 2308 * receive_chars - upper level read. Called with ip_lock.
2304 * @the_port: port to read from 2309 * @the_port: port to read from
@@ -2307,9 +2312,11 @@ static void receive_chars(struct uart_port *the_port)
2307{ 2312{
2308 struct tty_struct *tty; 2313 struct tty_struct *tty;
2309 unsigned char ch[IOC4_MAX_CHARS]; 2314 unsigned char ch[IOC4_MAX_CHARS];
2310 int read_count, request_count; 2315 int read_count, request_count = IOC4_MAX_CHARS;
2311 struct uart_icount *icount; 2316 struct uart_icount *icount;
2312 struct uart_info *info = the_port->info; 2317 struct uart_info *info = the_port->info;
2318 int flip = 0;
2319 unsigned long pflags;
2313 2320
2314 /* Make sure all the pointers are "good" ones */ 2321 /* Make sure all the pointers are "good" ones */
2315 if (!info) 2322 if (!info)
@@ -2317,16 +2324,17 @@ static void receive_chars(struct uart_port *the_port)
2317 if (!info->tty) 2324 if (!info->tty)
2318 return; 2325 return;
2319 2326
2327 spin_lock_irqsave(&the_port->lock, pflags);
2320 tty = info->tty; 2328 tty = info->tty;
2321 2329
2322 request_count = TTY_FLIPBUF_SIZE - tty->flip.count - 1; 2330 if (request_count > TTY_FLIPBUF_SIZE - tty->flip.count)
2331 request_count = TTY_FLIPBUF_SIZE - tty->flip.count;
2323 2332
2324 if (request_count > 0) { 2333 if (request_count > 0) {
2325 if (request_count > IOC4_MAX_CHARS - 2)
2326 request_count = IOC4_MAX_CHARS - 2;
2327 icount = &the_port->icount; 2334 icount = &the_port->icount;
2328 read_count = do_read(the_port, ch, request_count); 2335 read_count = do_read(the_port, ch, request_count);
2329 if (read_count > 0) { 2336 if (read_count > 0) {
2337 flip = 1;
2330 memcpy(tty->flip.char_buf_ptr, ch, read_count); 2338 memcpy(tty->flip.char_buf_ptr, ch, read_count);
2331 memset(tty->flip.flag_buf_ptr, TTY_NORMAL, read_count); 2339 memset(tty->flip.flag_buf_ptr, TTY_NORMAL, read_count);
2332 tty->flip.char_buf_ptr += read_count; 2340 tty->flip.char_buf_ptr += read_count;
@@ -2335,7 +2343,11 @@ static void receive_chars(struct uart_port *the_port)
2335 icount->rx += read_count; 2343 icount->rx += read_count;
2336 } 2344 }
2337 } 2345 }
2338 tty_flip_buffer_push(tty); 2346
2347 spin_unlock_irqrestore(&the_port->lock, pflags);
2348
2349 if (flip)
2350 tty_flip_buffer_push(tty);
2339} 2351}
2340 2352
2341/** 2353/**
@@ -2393,18 +2405,14 @@ static void ic4_shutdown(struct uart_port *the_port)
2393 2405
2394 info = the_port->info; 2406 info = the_port->info;
2395 2407
2396 if (!(info->flags & UIF_INITIALIZED))
2397 return;
2398
2399 wake_up_interruptible(&info->delta_msr_wait); 2408 wake_up_interruptible(&info->delta_msr_wait);
2400 2409
2401 if (info->tty) 2410 if (info->tty)
2402 set_bit(TTY_IO_ERROR, &info->tty->flags); 2411 set_bit(TTY_IO_ERROR, &info->tty->flags);
2403 2412
2404 spin_lock_irqsave(&port->ip_lock, port_flags); 2413 spin_lock_irqsave(&the_port->lock, port_flags);
2405 set_notification(port, N_ALL, 0); 2414 set_notification(port, N_ALL, 0);
2406 info->flags &= ~UIF_INITIALIZED; 2415 spin_unlock_irqrestore(&the_port->lock, port_flags);
2407 spin_unlock_irqrestore(&port->ip_lock, port_flags);
2408} 2416}
2409 2417
2410/** 2418/**
@@ -2463,12 +2471,10 @@ static unsigned int ic4_get_mctrl(struct uart_port *the_port)
2463static void ic4_start_tx(struct uart_port *the_port) 2471static void ic4_start_tx(struct uart_port *the_port)
2464{ 2472{
2465 struct ioc4_port *port = get_ioc4_port(the_port); 2473 struct ioc4_port *port = get_ioc4_port(the_port);
2466 unsigned long flags;
2467 2474
2468 if (port) { 2475 if (port) {
2469 spin_lock_irqsave(&port->ip_lock, flags); 2476 set_notification(port, N_OUTPUT_LOWAT, 1);
2470 transmit_chars(the_port); 2477 enable_intrs(port, port->ip_hooks->intr_tx_mt);
2471 spin_unlock_irqrestore(&port->ip_lock, flags);
2472 } 2478 }
2473} 2479}
2474 2480
@@ -2510,9 +2516,9 @@ static int ic4_startup(struct uart_port *the_port)
2510 } 2516 }
2511 2517
2512 /* Start up the serial port */ 2518 /* Start up the serial port */
2513 spin_lock_irqsave(&port->ip_lock, port_flags); 2519 spin_lock_irqsave(&the_port->lock, port_flags);
2514 retval = ic4_startup_local(the_port); 2520 retval = ic4_startup_local(the_port);
2515 spin_unlock_irqrestore(&port->ip_lock, port_flags); 2521 spin_unlock_irqrestore(&the_port->lock, port_flags);
2516 return retval; 2522 return retval;
2517} 2523}
2518 2524
@@ -2527,12 +2533,11 @@ static void
2527ic4_set_termios(struct uart_port *the_port, 2533ic4_set_termios(struct uart_port *the_port,
2528 struct termios *termios, struct termios *old_termios) 2534 struct termios *termios, struct termios *old_termios)
2529{ 2535{
2530 struct ioc4_port *port = get_ioc4_port(the_port);
2531 unsigned long port_flags; 2536 unsigned long port_flags;
2532 2537
2533 spin_lock_irqsave(&port->ip_lock, port_flags); 2538 spin_lock_irqsave(&the_port->lock, port_flags);
2534 ioc4_change_speed(the_port, termios, old_termios); 2539 ioc4_change_speed(the_port, termios, old_termios);
2535 spin_unlock_irqrestore(&port->ip_lock, port_flags); 2540 spin_unlock_irqrestore(&the_port->lock, port_flags);
2536} 2541}
2537 2542
2538/** 2543/**
@@ -2607,24 +2612,25 @@ ioc4_serial_core_attach(struct pci_dev *pdev)
2607 __FUNCTION__, (void *)the_port, 2612 __FUNCTION__, (void *)the_port,
2608 (void *)port)); 2613 (void *)port));
2609 2614
2610 spin_lock_init(&the_port->lock);
2611 /* membase, iobase and mapbase just need to be non-0 */ 2615 /* membase, iobase and mapbase just need to be non-0 */
2612 the_port->membase = (unsigned char __iomem *)1; 2616 the_port->membase = (unsigned char __iomem *)1;
2613 the_port->line = the_port->iobase = ii; 2617 the_port->iobase = (pdev->bus->number << 16) | ii;
2618 the_port->line = (Num_of_ioc4_cards << 2) | ii;
2614 the_port->mapbase = 1; 2619 the_port->mapbase = 1;
2615 the_port->type = PORT_16550A; 2620 the_port->type = PORT_16550A;
2616 the_port->fifosize = IOC4_MAX_CHARS; 2621 the_port->fifosize = IOC4_FIFO_CHARS;
2617 the_port->ops = &ioc4_ops; 2622 the_port->ops = &ioc4_ops;
2618 the_port->irq = control->ic_irq; 2623 the_port->irq = control->ic_irq;
2619 the_port->dev = &pdev->dev; 2624 the_port->dev = &pdev->dev;
2625 spin_lock_init(&the_port->lock);
2620 if (uart_add_one_port(&ioc4_uart, the_port) < 0) { 2626 if (uart_add_one_port(&ioc4_uart, the_port) < 0) {
2621 printk(KERN_WARNING 2627 printk(KERN_WARNING
2622 "%s: unable to add port %d\n", 2628 "%s: unable to add port %d bus %d\n",
2623 __FUNCTION__, the_port->line); 2629 __FUNCTION__, the_port->line, pdev->bus->number);
2624 } else { 2630 } else {
2625 DPRINT_CONFIG( 2631 DPRINT_CONFIG(
2626 ("IOC4 serial driver port %d irq = %d\n", 2632 ("IOC4 serial port %d irq = %d, bus %d\n",
2627 the_port->line, the_port->irq)); 2633 the_port->line, the_port->irq, pdev->bus->number));
2628 } 2634 }
2629 /* all ports are rs232 for now */ 2635 /* all ports are rs232 for now */
2630 ioc4_set_proto(port, PROTO_RS232); 2636 ioc4_set_proto(port, PROTO_RS232);
@@ -2734,6 +2740,8 @@ ioc4_serial_attach_one(struct ioc4_driver_data *idd)
2734 if ((ret = ioc4_serial_core_attach(idd->idd_pdev))) 2740 if ((ret = ioc4_serial_core_attach(idd->idd_pdev)))
2735 goto out4; 2741 goto out4;
2736 2742
2743 Num_of_ioc4_cards++;
2744
2737 return ret; 2745 return ret;
2738 2746
2739 /* error exits that give back resources */ 2747 /* error exits that give back resources */
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index 0585ab27ffde..8a79968f8ce1 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -781,22 +781,22 @@ mpc52xx_uart_remove(struct device *dev)
781 781
782#ifdef CONFIG_PM 782#ifdef CONFIG_PM
783static int 783static int
784mpc52xx_uart_suspend(struct device *dev, pm_message_t state, u32 level) 784mpc52xx_uart_suspend(struct device *dev, pm_message_t state)
785{ 785{
786 struct uart_port *port = (struct uart_port *) dev_get_drvdata(dev); 786 struct uart_port *port = (struct uart_port *) dev_get_drvdata(dev);
787 787
788 if (sport && level == SUSPEND_DISABLE) 788 if (sport)
789 uart_suspend_port(&mpc52xx_uart_driver, port); 789 uart_suspend_port(&mpc52xx_uart_driver, port);
790 790
791 return 0; 791 return 0;
792} 792}
793 793
794static int 794static int
795mpc52xx_uart_resume(struct device *dev, u32 level) 795mpc52xx_uart_resume(struct device *dev)
796{ 796{
797 struct uart_port *port = (struct uart_port *) dev_get_drvdata(dev); 797 struct uart_port *port = (struct uart_port *) dev_get_drvdata(dev);
798 798
799 if (port && level == RESUME_ENABLE) 799 if (port)
800 uart_resume_port(&mpc52xx_uart_driver, port); 800 uart_resume_port(&mpc52xx_uart_driver, port);
801 801
802 return 0; 802 return 0;
diff --git a/drivers/serial/mpsc.c b/drivers/serial/mpsc.c
index efe79b1fd431..aec83f577ce6 100644
--- a/drivers/serial/mpsc.c
+++ b/drivers/serial/mpsc.c
@@ -1100,6 +1100,8 @@ mpsc_start_rx(struct mpsc_port_info *pi)
1100{ 1100{
1101 pr_debug("mpsc_start_rx[%d]: Starting...\n", pi->port.line); 1101 pr_debug("mpsc_start_rx[%d]: Starting...\n", pi->port.line);
1102 1102
1103 /* Issue a Receive Abort to clear any receive errors */
1104 writel(MPSC_CHR_2_RA, pi->mpsc_base + MPSC_CHR_2);
1103 if (pi->rcv_data) { 1105 if (pi->rcv_data) {
1104 mpsc_enter_hunt(pi); 1106 mpsc_enter_hunt(pi);
1105 mpsc_sdma_cmd(pi, SDMA_SDCM_ERD); 1107 mpsc_sdma_cmd(pi, SDMA_SDCM_ERD);
diff --git a/drivers/serial/mux.c b/drivers/serial/mux.c
index 189064607709..660bae5ba179 100644
--- a/drivers/serial/mux.c
+++ b/drivers/serial/mux.c
@@ -27,6 +27,7 @@
27#include <linux/delay.h> /* for udelay */ 27#include <linux/delay.h> /* for udelay */
28#include <linux/device.h> 28#include <linux/device.h>
29#include <asm/io.h> 29#include <asm/io.h>
30#include <asm/irq.h>
30#include <asm/parisc-device.h> 31#include <asm/parisc-device.h>
31 32
32#ifdef CONFIG_MAGIC_SYSRQ 33#ifdef CONFIG_MAGIC_SYSRQ
@@ -444,7 +445,7 @@ static int __init mux_probe(struct parisc_device *dev)
444 unsigned long bytecnt; 445 unsigned long bytecnt;
445 struct uart_port *port; 446 struct uart_port *port;
446 447
447 status = pdc_iodc_read(&bytecnt, dev->hpa, 0, iodc_data, 32); 448 status = pdc_iodc_read(&bytecnt, dev->hpa.start, 0, iodc_data, 32);
448 if(status != PDC_OK) { 449 if(status != PDC_OK) {
449 printk(KERN_ERR "Serial mux: Unable to read IODC.\n"); 450 printk(KERN_ERR "Serial mux: Unable to read IODC.\n");
450 return 1; 451 return 1;
@@ -469,16 +470,18 @@ static int __init mux_probe(struct parisc_device *dev)
469 for(i = 0; i < ports; ++i, ++port_cnt) { 470 for(i = 0; i < ports; ++i, ++port_cnt) {
470 port = &mux_ports[port_cnt]; 471 port = &mux_ports[port_cnt];
471 port->iobase = 0; 472 port->iobase = 0;
472 port->mapbase = dev->hpa + MUX_OFFSET + (i * MUX_LINE_OFFSET); 473 port->mapbase = dev->hpa.start + MUX_OFFSET +
474 (i * MUX_LINE_OFFSET);
473 port->membase = ioremap(port->mapbase, MUX_LINE_OFFSET); 475 port->membase = ioremap(port->mapbase, MUX_LINE_OFFSET);
474 port->iotype = SERIAL_IO_MEM; 476 port->iotype = SERIAL_IO_MEM;
475 port->type = PORT_MUX; 477 port->type = PORT_MUX;
476 port->irq = SERIAL_IRQ_NONE; 478 port->irq = NO_IRQ;
477 port->uartclk = 0; 479 port->uartclk = 0;
478 port->fifosize = MUX_FIFO_SIZE; 480 port->fifosize = MUX_FIFO_SIZE;
479 port->ops = &mux_pops; 481 port->ops = &mux_pops;
480 port->flags = UPF_BOOT_AUTOCONF; 482 port->flags = UPF_BOOT_AUTOCONF;
481 port->line = port_cnt; 483 port->line = port_cnt;
484 spin_lock_init(&port->lock);
482 status = uart_add_one_port(&mux_driver, port); 485 status = uart_add_one_port(&mux_driver, port);
483 BUG_ON(status); 486 BUG_ON(status);
484 } 487 }
@@ -497,7 +500,7 @@ static struct parisc_device_id mux_tbl[] = {
497MODULE_DEVICE_TABLE(parisc, mux_tbl); 500MODULE_DEVICE_TABLE(parisc, mux_tbl);
498 501
499static struct parisc_driver serial_mux_driver = { 502static struct parisc_driver serial_mux_driver = {
500 .name = "Serial MUX", 503 .name = "serial_mux",
501 .id_table = mux_tbl, 504 .id_table = mux_tbl,
502 .probe = mux_probe, 505 .probe = mux_probe,
503}; 506};
diff --git a/drivers/serial/pxa.c b/drivers/serial/pxa.c
index 90c2a86c421b..8cc4cedadd99 100644
--- a/drivers/serial/pxa.c
+++ b/drivers/serial/pxa.c
@@ -358,6 +358,9 @@ static int serial_pxa_startup(struct uart_port *port)
358 unsigned long flags; 358 unsigned long flags;
359 int retval; 359 int retval;
360 360
361 if (port->line == 3) /* HWUART */
362 up->mcr |= UART_MCR_AFE;
363 else
361 up->mcr = 0; 364 up->mcr = 0;
362 365
363 /* 366 /*
@@ -481,8 +484,10 @@ serial_pxa_set_termios(struct uart_port *port, struct termios *termios,
481 484
482 if ((up->port.uartclk / quot) < (2400 * 16)) 485 if ((up->port.uartclk / quot) < (2400 * 16))
483 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_PXAR1; 486 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_PXAR1;
484 else 487 else if ((up->port.uartclk / quot) < (230400 * 16))
485 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_PXAR8; 488 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_PXAR8;
489 else
490 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_PXAR32;
486 491
487 /* 492 /*
488 * Ok, we're now changing the port state. Do it with 493 * Ok, we're now changing the port state. Do it with
@@ -772,6 +777,20 @@ static struct uart_pxa_port serial_pxa_ports[] = {
772 .ops = &serial_pxa_pops, 777 .ops = &serial_pxa_pops,
773 .line = 2, 778 .line = 2,
774 }, 779 },
780 }, { /* HWUART */
781 .name = "HWUART",
782 .cken = CKEN4_HWUART,
783 .port = {
784 .type = PORT_PXA,
785 .iotype = UPIO_MEM,
786 .membase = (void *)&HWUART,
787 .mapbase = __PREG(HWUART),
788 .irq = IRQ_HWUART,
789 .uartclk = 921600 * 16,
790 .fifosize = 64,
791 .ops = &serial_pxa_pops,
792 .line = 3,
793 },
775 } 794 }
776}; 795};
777 796
@@ -786,21 +805,21 @@ static struct uart_driver serial_pxa_reg = {
786 .cons = PXA_CONSOLE, 805 .cons = PXA_CONSOLE,
787}; 806};
788 807
789static int serial_pxa_suspend(struct device *_dev, pm_message_t state, u32 level) 808static int serial_pxa_suspend(struct device *_dev, pm_message_t state)
790{ 809{
791 struct uart_pxa_port *sport = dev_get_drvdata(_dev); 810 struct uart_pxa_port *sport = dev_get_drvdata(_dev);
792 811
793 if (sport && level == SUSPEND_DISABLE) 812 if (sport)
794 uart_suspend_port(&serial_pxa_reg, &sport->port); 813 uart_suspend_port(&serial_pxa_reg, &sport->port);
795 814
796 return 0; 815 return 0;
797} 816}
798 817
799static int serial_pxa_resume(struct device *_dev, u32 level) 818static int serial_pxa_resume(struct device *_dev)
800{ 819{
801 struct uart_pxa_port *sport = dev_get_drvdata(_dev); 820 struct uart_pxa_port *sport = dev_get_drvdata(_dev);
802 821
803 if (sport && level == RESUME_ENABLE) 822 if (sport)
804 uart_resume_port(&serial_pxa_reg, &sport->port); 823 uart_resume_port(&serial_pxa_reg, &sport->port);
805 824
806 return 0; 825 return 0;
diff --git a/drivers/serial/s3c2410.c b/drivers/serial/s3c2410.c
index 52692aa345ec..06a17dff1a73 100644
--- a/drivers/serial/s3c2410.c
+++ b/drivers/serial/s3c2410.c
@@ -1134,23 +1134,22 @@ static int s3c24xx_serial_remove(struct device *_dev)
1134 1134
1135#ifdef CONFIG_PM 1135#ifdef CONFIG_PM
1136 1136
1137static int s3c24xx_serial_suspend(struct device *dev, pm_message_t state, 1137static int s3c24xx_serial_suspend(struct device *dev, pm_message_t state)
1138 u32 level)
1139{ 1138{
1140 struct uart_port *port = s3c24xx_dev_to_port(dev); 1139 struct uart_port *port = s3c24xx_dev_to_port(dev);
1141 1140
1142 if (port && level == SUSPEND_DISABLE) 1141 if (port)
1143 uart_suspend_port(&s3c24xx_uart_drv, port); 1142 uart_suspend_port(&s3c24xx_uart_drv, port);
1144 1143
1145 return 0; 1144 return 0;
1146} 1145}
1147 1146
1148static int s3c24xx_serial_resume(struct device *dev, u32 level) 1147static int s3c24xx_serial_resume(struct device *dev)
1149{ 1148{
1150 struct uart_port *port = s3c24xx_dev_to_port(dev); 1149 struct uart_port *port = s3c24xx_dev_to_port(dev);
1151 struct s3c24xx_uart_port *ourport = to_ourport(port); 1150 struct s3c24xx_uart_port *ourport = to_ourport(port);
1152 1151
1153 if (port && level == RESUME_ENABLE) { 1152 if (port) {
1154 clk_enable(ourport->clk); 1153 clk_enable(ourport->clk);
1155 s3c24xx_serial_resetport(port, s3c24xx_port_to_cfg(port)); 1154 s3c24xx_serial_resetport(port, s3c24xx_port_to_cfg(port));
1156 clk_disable(ourport->clk); 1155 clk_disable(ourport->clk);
diff --git a/drivers/serial/sa1100.c b/drivers/serial/sa1100.c
index dd8aed242357..c4a789e6af44 100644
--- a/drivers/serial/sa1100.c
+++ b/drivers/serial/sa1100.c
@@ -834,21 +834,21 @@ static struct uart_driver sa1100_reg = {
834 .cons = SA1100_CONSOLE, 834 .cons = SA1100_CONSOLE,
835}; 835};
836 836
837static int sa1100_serial_suspend(struct device *_dev, pm_message_t state, u32 level) 837static int sa1100_serial_suspend(struct device *_dev, pm_message_t state)
838{ 838{
839 struct sa1100_port *sport = dev_get_drvdata(_dev); 839 struct sa1100_port *sport = dev_get_drvdata(_dev);
840 840
841 if (sport && level == SUSPEND_DISABLE) 841 if (sport)
842 uart_suspend_port(&sa1100_reg, &sport->port); 842 uart_suspend_port(&sa1100_reg, &sport->port);
843 843
844 return 0; 844 return 0;
845} 845}
846 846
847static int sa1100_serial_resume(struct device *_dev, u32 level) 847static int sa1100_serial_resume(struct device *_dev)
848{ 848{
849 struct sa1100_port *sport = dev_get_drvdata(_dev); 849 struct sa1100_port *sport = dev_get_drvdata(_dev);
850 850
851 if (sport && level == RESUME_ENABLE) 851 if (sport)
852 uart_resume_port(&sa1100_reg, &sport->port); 852 uart_resume_port(&sa1100_reg, &sport->port);
853 853
854 return 0; 854 return 0;
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index 2d8622eef701..401d94a7fe2e 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -147,8 +147,7 @@ static int uart_startup(struct uart_state *state, int init_hw)
147 * once we have successfully opened the port. Also set 147 * once we have successfully opened the port. Also set
148 * up the tty->alt_speed kludge 148 * up the tty->alt_speed kludge
149 */ 149 */
150 if (info->tty) 150 set_bit(TTY_IO_ERROR, &info->tty->flags);
151 set_bit(TTY_IO_ERROR, &info->tty->flags);
152 151
153 if (port->type == PORT_UNKNOWN) 152 if (port->type == PORT_UNKNOWN)
154 return 0; 153 return 0;
diff --git a/drivers/serial/vr41xx_siu.c b/drivers/serial/vr41xx_siu.c
index 0c5d65a08f6e..2b623ab0e36e 100644
--- a/drivers/serial/vr41xx_siu.c
+++ b/drivers/serial/vr41xx_siu.c
@@ -976,14 +976,11 @@ static int siu_remove(struct device *dev)
976 return 0; 976 return 0;
977} 977}
978 978
979static int siu_suspend(struct device *dev, pm_message_t state, u32 level) 979static int siu_suspend(struct device *dev, pm_message_t state)
980{ 980{
981 struct uart_port *port; 981 struct uart_port *port;
982 int i; 982 int i;
983 983
984 if (level != SUSPEND_DISABLE)
985 return 0;
986
987 for (i = 0; i < siu_uart_driver.nr; i++) { 984 for (i = 0; i < siu_uart_driver.nr; i++) {
988 port = &siu_uart_ports[i]; 985 port = &siu_uart_ports[i];
989 if ((port->type == PORT_VR41XX_SIU || 986 if ((port->type == PORT_VR41XX_SIU ||
@@ -995,14 +992,11 @@ static int siu_suspend(struct device *dev, pm_message_t state, u32 level)
995 return 0; 992 return 0;
996} 993}
997 994
998static int siu_resume(struct device *dev, u32 level) 995static int siu_resume(struct device *dev)
999{ 996{
1000 struct uart_port *port; 997 struct uart_port *port;
1001 int i; 998 int i;
1002 999
1003 if (level != RESUME_ENABLE)
1004 return 0;
1005
1006 for (i = 0; i < siu_uart_driver.nr; i++) { 1000 for (i = 0; i < siu_uart_driver.nr; i++) {
1007 port = &siu_uart_ports[i]; 1001 port = &siu_uart_ports[i];
1008 if ((port->type == PORT_VR41XX_SIU || 1002 if ((port->type == PORT_VR41XX_SIU ||
diff --git a/drivers/sh/superhyway/superhyway.c b/drivers/sh/superhyway/superhyway.c
index f056276b08a1..28757cb9d246 100644
--- a/drivers/sh/superhyway/superhyway.c
+++ b/drivers/sh/superhyway/superhyway.c
@@ -16,6 +16,8 @@
16#include <linux/types.h> 16#include <linux/types.h>
17#include <linux/list.h> 17#include <linux/list.h>
18#include <linux/superhyway.h> 18#include <linux/superhyway.h>
19#include <linux/string.h>
20#include <linux/slab.h>
19 21
20static int superhyway_devices; 22static int superhyway_devices;
21 23
diff --git a/drivers/tc/tc.c b/drivers/tc/tc.c
index a89ef4df80c3..a0e5af638e0e 100644
--- a/drivers/tc/tc.c
+++ b/drivers/tc/tc.c
@@ -8,33 +8,31 @@
8 * for more details. 8 * for more details.
9 * 9 *
10 * Copyright (c) Harald Koerfgen, 1998 10 * Copyright (c) Harald Koerfgen, 1998
11 * Copyright (c) 2001, 2003 Maciej W. Rozycki 11 * Copyright (c) 2001, 2003, 2005 Maciej W. Rozycki
12 */ 12 */
13#include <linux/string.h>
14#include <linux/init.h> 13#include <linux/init.h>
15#include <linux/ioport.h>
16#include <linux/kernel.h> 14#include <linux/kernel.h>
17#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/string.h>
17#include <linux/types.h>
18 18
19#include <asm/addrspace.h> 19#include <asm/addrspace.h>
20#include <asm/bug.h>
20#include <asm/errno.h> 21#include <asm/errno.h>
22#include <asm/io.h>
23#include <asm/paccess.h>
24
21#include <asm/dec/machtype.h> 25#include <asm/dec/machtype.h>
22#include <asm/dec/prom.h> 26#include <asm/dec/prom.h>
23#include <asm/dec/tcinfo.h> 27#include <asm/dec/tcinfo.h>
24#include <asm/dec/tcmodule.h> 28#include <asm/dec/tcmodule.h>
25#include <asm/dec/interrupts.h> 29#include <asm/dec/interrupts.h>
26#include <asm/paccess.h>
27#include <asm/ptrace.h>
28
29#define TC_DEBUG
30 30
31MODULE_LICENSE("GPL"); 31MODULE_LICENSE("GPL");
32slot_info tc_bus[MAX_SLOT]; 32slot_info tc_bus[MAX_SLOT];
33static int num_tcslots; 33static int num_tcslots;
34static tcinfo *info; 34static tcinfo *info;
35 35
36unsigned long system_base;
37
38/* 36/*
39 * Interface to the world. Read comment in include/asm-mips/tc.h. 37 * Interface to the world. Read comment in include/asm-mips/tc.h.
40 */ 38 */
@@ -97,13 +95,16 @@ unsigned long get_tc_speed(void)
97static void __init tc_probe(unsigned long startaddr, unsigned long size, 95static void __init tc_probe(unsigned long startaddr, unsigned long size,
98 int slots) 96 int slots)
99{ 97{
98 unsigned long slotaddr;
100 int i, slot, err; 99 int i, slot, err;
101 long offset; 100 long offset;
102 unsigned char pattern[4]; 101 u8 pattern[4];
103 unsigned char *module; 102 volatile u8 *module;
104 103
105 for (slot = 0; slot < slots; slot++) { 104 for (slot = 0; slot < slots; slot++) {
106 module = (char *)(startaddr + slot * size); 105 slotaddr = startaddr + slot * size;
106 module = ioremap_nocache(slotaddr, size);
107 BUG_ON(!module);
107 108
108 offset = OLDCARD; 109 offset = OLDCARD;
109 110
@@ -112,8 +113,10 @@ static void __init tc_probe(unsigned long startaddr, unsigned long size,
112 err |= get_dbe(pattern[1], module + OLDCARD + TC_PATTERN1); 113 err |= get_dbe(pattern[1], module + OLDCARD + TC_PATTERN1);
113 err |= get_dbe(pattern[2], module + OLDCARD + TC_PATTERN2); 114 err |= get_dbe(pattern[2], module + OLDCARD + TC_PATTERN2);
114 err |= get_dbe(pattern[3], module + OLDCARD + TC_PATTERN3); 115 err |= get_dbe(pattern[3], module + OLDCARD + TC_PATTERN3);
115 if (err) 116 if (err) {
117 iounmap(module);
116 continue; 118 continue;
119 }
117 120
118 if (pattern[0] != 0x55 || pattern[1] != 0x00 || 121 if (pattern[0] != 0x55 || pattern[1] != 0x00 ||
119 pattern[2] != 0xaa || pattern[3] != 0xff) { 122 pattern[2] != 0xaa || pattern[3] != 0xff) {
@@ -124,16 +127,20 @@ static void __init tc_probe(unsigned long startaddr, unsigned long size,
124 err |= get_dbe(pattern[1], module + TC_PATTERN1); 127 err |= get_dbe(pattern[1], module + TC_PATTERN1);
125 err |= get_dbe(pattern[2], module + TC_PATTERN2); 128 err |= get_dbe(pattern[2], module + TC_PATTERN2);
126 err |= get_dbe(pattern[3], module + TC_PATTERN3); 129 err |= get_dbe(pattern[3], module + TC_PATTERN3);
127 if (err) 130 if (err) {
131 iounmap(module);
128 continue; 132 continue;
133 }
129 } 134 }
130 135
131 if (pattern[0] != 0x55 || pattern[1] != 0x00 || 136 if (pattern[0] != 0x55 || pattern[1] != 0x00 ||
132 pattern[2] != 0xaa || pattern[3] != 0xff) 137 pattern[2] != 0xaa || pattern[3] != 0xff) {
138 iounmap(module);
133 continue; 139 continue;
140 }
134 141
135 tc_bus[slot].base_addr = (unsigned long)module; 142 tc_bus[slot].base_addr = slotaddr;
136 for(i = 0; i < 8; i++) { 143 for (i = 0; i < 8; i++) {
137 tc_bus[slot].firmware[i] = 144 tc_bus[slot].firmware[i] =
138 module[TC_FIRM_VER + offset + 4 * i]; 145 module[TC_FIRM_VER + offset + 4 * i];
139 tc_bus[slot].vendor[i] = 146 tc_bus[slot].vendor[i] =
@@ -171,13 +178,15 @@ static void __init tc_probe(unsigned long startaddr, unsigned long size,
171 tc_bus[slot].interrupt = -1; 178 tc_bus[slot].interrupt = -1;
172 break; 179 break;
173 } 180 }
181
182 iounmap(module);
174 } 183 }
175} 184}
176 185
177/* 186/*
178 * the main entry 187 * the main entry
179 */ 188 */
180void __init tc_init(void) 189static int __init tc_init(void)
181{ 190{
182 int tc_clock; 191 int tc_clock;
183 int i; 192 int i;
@@ -185,7 +194,7 @@ void __init tc_init(void)
185 unsigned long slot_size; 194 unsigned long slot_size;
186 195
187 if (!TURBOCHANNEL) 196 if (!TURBOCHANNEL)
188 return; 197 return 0;
189 198
190 for (i = 0; i < MAX_SLOT; i++) { 199 for (i = 0; i < MAX_SLOT; i++) {
191 tc_bus[i].base_addr = 0; 200 tc_bus[i].base_addr = 0;
@@ -196,8 +205,8 @@ void __init tc_init(void)
196 tc_bus[i].flags = FREE; 205 tc_bus[i].flags = FREE;
197 } 206 }
198 207
199 info = (tcinfo *) rex_gettcinfo(); 208 info = rex_gettcinfo();
200 slot0addr = (unsigned long)KSEG1ADDR(rex_slot_address(0)); 209 slot0addr = CPHYSADDR((long)rex_slot_address(0));
201 210
202 switch (mips_machtype) { 211 switch (mips_machtype) {
203 case MACH_DS5000_200: 212 case MACH_DS5000_200:
@@ -216,37 +225,24 @@ void __init tc_init(void)
216 225
217 tc_clock = 10000 / info->clk_period; 226 tc_clock = 10000 / info->clk_period;
218 227
219 if (TURBOCHANNEL && info->slot_size && slot0addr) { 228 if (info->slot_size && slot0addr) {
220 printk("TURBOchannel rev. %1d at %2d.%1d MHz ", info->revision, 229 pr_info("TURBOchannel rev. %d at %d.%d MHz (with%s parity)\n",
221 tc_clock / 10, tc_clock % 10); 230 info->revision, tc_clock / 10, tc_clock % 10,
222 printk("(with%s parity)\n", info->parity ? "" : "out"); 231 info->parity ? "" : "out");
223 232
224 slot_size = info->slot_size << 20; 233 slot_size = info->slot_size << 20;
225 234
226 tc_probe(slot0addr, slot_size, num_tcslots); 235 tc_probe(slot0addr, slot_size, num_tcslots);
227 236
228 /* 237 for (i = 0; i < num_tcslots; i++) {
229 * All TURBOchannel DECstations have the onboard devices 238 if (!tc_bus[i].base_addr)
230 * where the (num_tcslots + 0 or 1 on DS5k/xx) Option Module 239 continue;
231 * would be. 240 pr_info(" slot %d: %s %s %s\n", i, tc_bus[i].vendor,
232 */ 241 tc_bus[i].name, tc_bus[i].firmware);
233 if(mips_machtype == MACH_DS5000_XX) 242 }
234 i = 1;
235 else
236 i = 0;
237
238 system_base = slot0addr + slot_size * (num_tcslots + i);
239
240#ifdef TC_DEBUG
241 for (i = 0; i < num_tcslots; i++)
242 if (tc_bus[i].base_addr) {
243 printk(" slot %d: ", i);
244 printk("%s %s %s\n", tc_bus[i].vendor,
245 tc_bus[i].name, tc_bus[i].firmware);
246 }
247#endif
248 ioport_resource.end = KSEG2 - 1;
249 } 243 }
244
245 return 0;
250} 246}
251 247
252subsys_initcall(tc_init); 248subsys_initcall(tc_init);
@@ -257,4 +253,3 @@ EXPORT_SYMBOL(release_tc_card);
257EXPORT_SYMBOL(get_tc_base_addr); 253EXPORT_SYMBOL(get_tc_base_addr);
258EXPORT_SYMBOL(get_tc_irq_nr); 254EXPORT_SYMBOL(get_tc_irq_nr);
259EXPORT_SYMBOL(get_tc_speed); 255EXPORT_SYMBOL(get_tc_speed);
260EXPORT_SYMBOL(system_base);
diff --git a/drivers/tc/zs.c b/drivers/tc/zs.c
index 6bed8713897e..c52af73a251b 100644
--- a/drivers/tc/zs.c
+++ b/drivers/tc/zs.c
@@ -65,14 +65,14 @@
65#include <asm/system.h> 65#include <asm/system.h>
66#include <asm/uaccess.h> 66#include <asm/uaccess.h>
67#include <asm/bootinfo.h> 67#include <asm/bootinfo.h>
68#include <asm/dec/serial.h>
69 68
70#ifdef CONFIG_MACH_DECSTATION
71#include <asm/dec/interrupts.h> 69#include <asm/dec/interrupts.h>
70#include <asm/dec/ioasic_addrs.h>
72#include <asm/dec/machtype.h> 71#include <asm/dec/machtype.h>
72#include <asm/dec/serial.h>
73#include <asm/dec/system.h>
73#include <asm/dec/tc.h> 74#include <asm/dec/tc.h>
74#include <asm/dec/ioasic_addrs.h> 75
75#endif
76#ifdef CONFIG_KGDB 76#ifdef CONFIG_KGDB
77#include <asm/kgdb.h> 77#include <asm/kgdb.h>
78#endif 78#endif
@@ -192,18 +192,6 @@ static void probe_sccs(void);
192static void change_speed(struct dec_serial *info); 192static void change_speed(struct dec_serial *info);
193static void rs_wait_until_sent(struct tty_struct *tty, int timeout); 193static void rs_wait_until_sent(struct tty_struct *tty, int timeout);
194 194
195/*
196 * tmp_buf is used as a temporary buffer by serial_write. We need to
197 * lock it in case the copy_from_user blocks while swapping in a page,
198 * and some other program tries to do a serial write at the same time.
199 * Since the lock will only come under contention when the system is
200 * swapping and available memory is low, it makes sense to share one
201 * buffer across all the serial ports, since it significantly saves
202 * memory if large numbers of serial ports are open.
203 */
204static unsigned char tmp_buf[4096]; /* This is cheating */
205static DECLARE_MUTEX(tmp_buf_sem);
206
207static inline int serial_paranoia_check(struct dec_serial *info, 195static inline int serial_paranoia_check(struct dec_serial *info,
208 char *name, const char *routine) 196 char *name, const char *routine)
209{ 197{
@@ -1628,30 +1616,22 @@ static void __init probe_sccs(void)
1628 return; 1616 return;
1629 } 1617 }
1630 1618
1631 /*
1632 * When serial console is activated, tc_init has not been called yet
1633 * and system_base is undefined. Unfortunately we have to hardcode
1634 * system_base for this case :-(. HK
1635 */
1636 switch(mips_machtype) { 1619 switch(mips_machtype) {
1637#ifdef CONFIG_MACH_DECSTATION 1620#ifdef CONFIG_MACH_DECSTATION
1638 case MACH_DS5000_2X0: 1621 case MACH_DS5000_2X0:
1639 case MACH_DS5900: 1622 case MACH_DS5900:
1640 system_base = KSEG1ADDR(0x1f800000);
1641 n_chips = 2; 1623 n_chips = 2;
1642 zs_parms = &ds_parms; 1624 zs_parms = &ds_parms;
1643 zs_parms->irq0 = dec_interrupt[DEC_IRQ_SCC0]; 1625 zs_parms->irq0 = dec_interrupt[DEC_IRQ_SCC0];
1644 zs_parms->irq1 = dec_interrupt[DEC_IRQ_SCC1]; 1626 zs_parms->irq1 = dec_interrupt[DEC_IRQ_SCC1];
1645 break; 1627 break;
1646 case MACH_DS5000_1XX: 1628 case MACH_DS5000_1XX:
1647 system_base = KSEG1ADDR(0x1c000000);
1648 n_chips = 2; 1629 n_chips = 2;
1649 zs_parms = &ds_parms; 1630 zs_parms = &ds_parms;
1650 zs_parms->irq0 = dec_interrupt[DEC_IRQ_SCC0]; 1631 zs_parms->irq0 = dec_interrupt[DEC_IRQ_SCC0];
1651 zs_parms->irq1 = dec_interrupt[DEC_IRQ_SCC1]; 1632 zs_parms->irq1 = dec_interrupt[DEC_IRQ_SCC1];
1652 break; 1633 break;
1653 case MACH_DS5000_XX: 1634 case MACH_DS5000_XX:
1654 system_base = KSEG1ADDR(0x1c000000);
1655 n_chips = 1; 1635 n_chips = 1;
1656 zs_parms = &ds_parms; 1636 zs_parms = &ds_parms;
1657 zs_parms->irq0 = dec_interrupt[DEC_IRQ_SCC0]; 1637 zs_parms->irq0 = dec_interrupt[DEC_IRQ_SCC0];
@@ -1673,10 +1653,10 @@ static void __init probe_sccs(void)
1673 * The sccs reside on the high byte of the 16 bit IOBUS 1653 * The sccs reside on the high byte of the 16 bit IOBUS
1674 */ 1654 */
1675 zs_channels[n_channels].control = 1655 zs_channels[n_channels].control =
1676 (volatile unsigned char *)system_base + 1656 (volatile void *)CKSEG1ADDR(dec_kn_slot_base +
1677 (0 == chip ? zs_parms->scc0 : zs_parms->scc1) + 1657 (0 == chip ? zs_parms->scc0 : zs_parms->scc1) +
1678 (0 == channel ? zs_parms->channel_a_offset : 1658 (0 == channel ? zs_parms->channel_a_offset :
1679 zs_parms->channel_b_offset); 1659 zs_parms->channel_b_offset));
1680 zs_channels[n_channels].data = 1660 zs_channels[n_channels].data =
1681 zs_channels[n_channels].control + 4; 1661 zs_channels[n_channels].control + 4;
1682 1662
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index df014c2a7c54..a50c2bc506f2 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_USB) += core/
8 8
9obj-$(CONFIG_USB_MON) += mon/ 9obj-$(CONFIG_USB_MON) += mon/
10 10
11obj-$(CONFIG_PCI) += host/
11obj-$(CONFIG_USB_EHCI_HCD) += host/ 12obj-$(CONFIG_USB_EHCI_HCD) += host/
12obj-$(CONFIG_USB_ISP116X_HCD) += host/ 13obj-$(CONFIG_USB_ISP116X_HCD) += host/
13obj-$(CONFIG_USB_OHCI_HCD) += host/ 14obj-$(CONFIG_USB_OHCI_HCD) += host/
@@ -17,7 +18,6 @@ obj-$(CONFIG_ETRAX_USB_HOST) += host/
17 18
18obj-$(CONFIG_USB_ACM) += class/ 19obj-$(CONFIG_USB_ACM) += class/
19obj-$(CONFIG_USB_AUDIO) += class/ 20obj-$(CONFIG_USB_AUDIO) += class/
20obj-$(CONFIG_USB_BLUETOOTH_TTY) += class/
21obj-$(CONFIG_USB_MIDI) += class/ 21obj-$(CONFIG_USB_MIDI) += class/
22obj-$(CONFIG_USB_PRINTER) += class/ 22obj-$(CONFIG_USB_PRINTER) += class/
23 23
diff --git a/drivers/usb/class/Kconfig b/drivers/usb/class/Kconfig
index 333e39bb105f..ef105a92a7bd 100644
--- a/drivers/usb/class/Kconfig
+++ b/drivers/usb/class/Kconfig
@@ -28,29 +28,6 @@ config USB_AUDIO
28 To compile this driver as a module, choose M here: the 28 To compile this driver as a module, choose M here: the
29 module will be called audio. 29 module will be called audio.
30 30
31comment "USB Bluetooth TTY can only be used with disabled Bluetooth subsystem"
32 depends on USB && BT
33
34config USB_BLUETOOTH_TTY
35 tristate "USB Bluetooth TTY support"
36 depends on USB && BT=n
37 ---help---
38 This driver implements a nonstandard tty interface to a Bluetooth
39 device that can be used only by specialized Bluetooth HCI software.
40
41 Say Y here if you want to use OpenBT Bluetooth stack (available
42 at <http://developer.axis.com/software>), or other TTY based
43 Bluetooth stacks, and want to connect a USB Bluetooth device
44 to your computer's USB port.
45
46 Do *not* enable this driver if you want to use generic Linux
47 Bluetooth support.
48
49 If in doubt, say N here.
50
51 To compile this driver as a module, choose M here: the
52 module will be called bluetty.
53
54config USB_MIDI 31config USB_MIDI
55 tristate "USB MIDI support" 32 tristate "USB MIDI support"
56 depends on USB && SOUND && OBSOLETE_OSS_USB_DRIVER 33 depends on USB && SOUND && OBSOLETE_OSS_USB_DRIVER
diff --git a/drivers/usb/class/Makefile b/drivers/usb/class/Makefile
index 971e5497a3fd..229471247751 100644
--- a/drivers/usb/class/Makefile
+++ b/drivers/usb/class/Makefile
@@ -5,6 +5,5 @@
5 5
6obj-$(CONFIG_USB_ACM) += cdc-acm.o 6obj-$(CONFIG_USB_ACM) += cdc-acm.o
7obj-$(CONFIG_USB_AUDIO) += audio.o 7obj-$(CONFIG_USB_AUDIO) += audio.o
8obj-$(CONFIG_USB_BLUETOOTH_TTY) += bluetty.o
9obj-$(CONFIG_USB_MIDI) += usb-midi.o 8obj-$(CONFIG_USB_MIDI) += usb-midi.o
10obj-$(CONFIG_USB_PRINTER) += usblp.o 9obj-$(CONFIG_USB_PRINTER) += usblp.o
diff --git a/drivers/usb/class/bluetty.c b/drivers/usb/class/bluetty.c
deleted file mode 100644
index 524023327c49..000000000000
--- a/drivers/usb/class/bluetty.c
+++ /dev/null
@@ -1,1279 +0,0 @@
1/*
2 * bluetty.c Version 0.13
3 *
4 * Copyright (C) 2000, 2001 Greg Kroah-Hartman <greg@kroah.com>
5 * Copyright (C) 2000 Mark Douglas Corner <mcorner@umich.edu>
6 *
7 * USB Bluetooth TTY driver, based on the Bluetooth Spec version 1.0B
8 *
9 * (2001/11/30) Version 0.13 gkh
10 * - added locking patch from Masoodur Rahman <rmasoodu@in.ibm.com>
11 * - removed active variable, as open_count will do.
12 *
13 * (2001/07/09) Version 0.12 gkh
14 * - removed in_interrupt() call, as it doesn't make sense to do
15 * that anymore.
16 *
17 * (2001/06/05) Version 0.11 gkh
18 * - Fixed problem with read urb status saying that we have shutdown,
19 * and that we shouldn't resubmit the urb. Patch from unknown.
20 *
21 * (2001/05/28) Version 0.10 gkh
22 * - Fixed problem with using data from userspace in the bluetooth_write
23 * function as found by the CHECKER project.
24 * - Added a buffer to the write_urb_pool which reduces the number of
25 * buffers being created and destroyed for ever write. Also cleans
26 * up the logic a bit.
27 * - Added a buffer to the control_urb_pool which fixes a memory leak
28 * when the device is removed from the system.
29 *
30 * (2001/05/28) Version 0.9 gkh
31 * Fixed problem with bluetooth==NULL for bluetooth_read_bulk_callback
32 * which was found by both the CHECKER project and Mikko Rahkonen.
33 *
34 * (08/04/2001) gb
35 * Identify version on module load.
36 *
37 * (2001/03/10) Version 0.8 gkh
38 * Fixed problem with not unlinking interrupt urb on device close
39 * and resubmitting the read urb on error with bluetooth struct.
40 * Thanks to Narayan Mohanram <narayan@RovingNetworks.com> for the
41 * fixes.
42 *
43 * (11/29/2000) Version 0.7 gkh
44 * Fixed problem with overrunning the tty flip buffer.
45 * Removed unneeded NULL pointer initialization.
46 *
47 * (10/05/2000) Version 0.6 gkh
48 * Fixed bug with urb->dev not being set properly, now that the usb
49 * core needs it.
50 * Got a real major id number and name.
51 *
52 * (08/06/2000) Version 0.5 gkh
53 * Fixed problem of not resubmitting the bulk read urb if there is
54 * an error in the callback. Ericsson devices seem to need this.
55 *
56 * (07/11/2000) Version 0.4 gkh
57 * Fixed bug in disconnect for when we call tty_hangup
58 * Fixed bug in bluetooth_ctrl_msg where the bluetooth struct was not
59 * getting attached to the control urb properly.
60 * Fixed bug in bluetooth_write where we pay attention to the result
61 * of bluetooth_ctrl_msg.
62 *
63 * (08/03/2000) Version 0.3 gkh mdc
64 * Merged in Mark's changes to make the driver play nice with the Axis
65 * stack.
66 * Made the write bulk use an urb pool to enable larger transfers with
67 * fewer calls to the driver.
68 * Fixed off by one bug in acl pkt receive
69 * Made packet counters specific to each bluetooth device
70 * Added checks for zero length callbacks
71 * Added buffers for int and bulk packets. Had to do this otherwise
72 * packet types could intermingle.
73 * Made a control urb pool for the control messages.
74 *
75 * (07/11/2000) Version 0.2 gkh
76 * Fixed a small bug found by Nils Faerber in the usb_bluetooth_probe
77 * function.
78 *
79 * (07/09/2000) Version 0.1 gkh
80 * Initial release. Has support for sending ACL data (which is really just
81 * a HCI frame.) Raw HCI commands and HCI events are not supported.
82 * A ioctl will probably be needed for the HCI commands and events in the
83 * future. All isoch endpoints are ignored at this time also.
84 * This driver should work for all currently shipping USB Bluetooth
85 * devices at this time :)
86 *
87 */
88
89/*
90 * This program is free software; you can redistribute it and/or modify
91 * it under the terms of the GNU General Public License as published by
92 * the Free Software Foundation; either version 2 of the License, or
93 * (at your option) any later version.
94 *
95 * This program is distributed in the hope that it will be useful,
96 * but WITHOUT ANY WARRANTY; without even the implied warranty of
97 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
98 * GNU General Public License for more details.
99 *
100 * You should have received a copy of the GNU General Public License
101 * along with this program; if not, write to the Free Software
102 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
103 */
104
105
106#include <linux/kernel.h>
107#include <linux/errno.h>
108#include <linux/init.h>
109#include <linux/slab.h>
110#include <linux/tty.h>
111#include <linux/tty_driver.h>
112#include <linux/tty_flip.h>
113#include <linux/module.h>
114#include <asm/uaccess.h>
115
116#define DEBUG
117#include <linux/usb.h>
118
119/*
120 * Version Information
121 */
122#define DRIVER_VERSION "v0.13"
123#define DRIVER_AUTHOR "Greg Kroah-Hartman, Mark Douglas Corner"
124#define DRIVER_DESC "USB Bluetooth tty driver"
125
126/* define this if you have hardware that is not good */
127/*#define BTBUGGYHARDWARE */
128
129/* Class, SubClass, and Protocol codes that describe a Bluetooth device */
130#define WIRELESS_CLASS_CODE 0xe0
131#define RF_SUBCLASS_CODE 0x01
132#define BLUETOOTH_PROGRAMMING_PROTOCOL_CODE 0x01
133
134
135#define BLUETOOTH_TTY_MAJOR 216 /* real device node major id */
136#define BLUETOOTH_TTY_MINORS 256 /* whole lotta bluetooth devices */
137
138#define USB_BLUETOOTH_MAGIC 0x6d02 /* magic number for bluetooth struct */
139
140#define BLUETOOTH_CONTROL_REQUEST_TYPE 0x20
141
142/* Bluetooth packet types */
143#define CMD_PKT 0x01
144#define ACL_PKT 0x02
145#define SCO_PKT 0x03
146#define EVENT_PKT 0x04
147#define ERROR_PKT 0x05
148#define NEG_PKT 0x06
149
150/* Message sizes */
151#define MAX_EVENT_SIZE 0xFF
152#define EVENT_HDR_SIZE 3 /* 2 for the header + 1 for the type indicator */
153#define EVENT_BUFFER_SIZE (MAX_EVENT_SIZE + EVENT_HDR_SIZE)
154
155#define MAX_ACL_SIZE 0xFFFF
156#define ACL_HDR_SIZE 5 /* 4 for the header + 1 for the type indicator */
157#define ACL_BUFFER_SIZE (MAX_ACL_SIZE + ACL_HDR_SIZE)
158
159/* parity check flag */
160#define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
161
162#define CHAR2INT16(c1,c0) (((u32)((c1) & 0xff) << 8) + (u32)((c0) & 0xff))
163
164#define NUM_BULK_URBS 24
165#define NUM_CONTROL_URBS 16
166
167struct usb_bluetooth {
168 int magic;
169 struct usb_device * dev;
170 struct tty_driver * tty_driver; /* the tty_driver for this device */
171 struct tty_struct * tty; /* the corresponding tty for this port */
172
173 unsigned char minor; /* the starting minor number for this device */
174 int throttle; /* throttled by tty layer */
175 int open_count;
176
177 __u8 control_out_bInterfaceNum;
178 struct urb * control_urb_pool[NUM_CONTROL_URBS];
179 struct usb_ctrlrequest dr[NUM_CONTROL_URBS];
180
181 unsigned char * interrupt_in_buffer;
182 struct urb * interrupt_in_urb;
183 __u8 interrupt_in_endpointAddress;
184 __u8 interrupt_in_interval;
185 int interrupt_in_buffer_size;
186
187 unsigned char * bulk_in_buffer;
188 struct urb * read_urb;
189 __u8 bulk_in_endpointAddress;
190 int bulk_in_buffer_size;
191
192 int bulk_out_buffer_size;
193 __u8 bulk_out_endpointAddress;
194
195 wait_queue_head_t write_wait;
196
197 struct work_struct work; /* work queue entry for line discipline waking up */
198
199 unsigned int int_packet_pos;
200 unsigned char int_buffer[EVENT_BUFFER_SIZE];
201 unsigned int bulk_packet_pos;
202 unsigned char bulk_buffer[ACL_BUFFER_SIZE]; /* 64k preallocated, fix? */
203 struct semaphore lock;
204};
205
206
207/* local function prototypes */
208static int bluetooth_open (struct tty_struct *tty, struct file *filp);
209static void bluetooth_close (struct tty_struct *tty, struct file *filp);
210static int bluetooth_write (struct tty_struct *tty, const unsigned char *buf, int count);
211static int bluetooth_write_room (struct tty_struct *tty);
212static int bluetooth_chars_in_buffer (struct tty_struct *tty);
213static void bluetooth_throttle (struct tty_struct *tty);
214static void bluetooth_unthrottle (struct tty_struct *tty);
215static int bluetooth_ioctl (struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
216static void bluetooth_set_termios (struct tty_struct *tty, struct termios *old);
217
218static void bluetooth_int_callback (struct urb *urb, struct pt_regs *regs);
219static void bluetooth_ctrl_callback (struct urb *urb, struct pt_regs *regs);
220static void bluetooth_read_bulk_callback (struct urb *urb, struct pt_regs *regs);
221static void bluetooth_write_bulk_callback (struct urb *urb, struct pt_regs *regs);
222
223static int usb_bluetooth_probe (struct usb_interface *intf,
224 const struct usb_device_id *id);
225static void usb_bluetooth_disconnect (struct usb_interface *intf);
226
227
228static struct usb_device_id usb_bluetooth_ids [] = {
229 { USB_DEVICE_INFO(WIRELESS_CLASS_CODE, RF_SUBCLASS_CODE, BLUETOOTH_PROGRAMMING_PROTOCOL_CODE) },
230 { } /* Terminating entry */
231};
232
233MODULE_DEVICE_TABLE (usb, usb_bluetooth_ids);
234
235static struct usb_driver usb_bluetooth_driver = {
236 .owner = THIS_MODULE,
237 .name = "bluetty",
238 .probe = usb_bluetooth_probe,
239 .disconnect = usb_bluetooth_disconnect,
240 .id_table = usb_bluetooth_ids,
241};
242
243static struct tty_driver *bluetooth_tty_driver;
244static struct usb_bluetooth *bluetooth_table[BLUETOOTH_TTY_MINORS];
245
246
247static inline int bluetooth_paranoia_check (struct usb_bluetooth *bluetooth, const char *function)
248{
249 if (!bluetooth) {
250 dbg("%s - bluetooth == NULL", function);
251 return -1;
252 }
253 if (bluetooth->magic != USB_BLUETOOTH_MAGIC) {
254 dbg("%s - bad magic number for bluetooth", function);
255 return -1;
256 }
257
258 return 0;
259}
260
261
262static inline struct usb_bluetooth* get_usb_bluetooth (struct usb_bluetooth *bluetooth, const char *function)
263{
264 if (!bluetooth ||
265 bluetooth_paranoia_check (bluetooth, function)) {
266 /* then say that we don't have a valid usb_bluetooth thing, which will
267 * end up generating -ENODEV return values */
268 return NULL;
269 }
270
271 return bluetooth;
272}
273
274
275static inline struct usb_bluetooth *get_bluetooth_by_index (int index)
276{
277 return bluetooth_table[index];
278}
279
280
281static int bluetooth_ctrl_msg (struct usb_bluetooth *bluetooth, int request, int value, const unsigned char *buf, int len)
282{
283 struct urb *urb = NULL;
284 struct usb_ctrlrequest *dr = NULL;
285 int i;
286 int status;
287
288 dbg ("%s", __FUNCTION__);
289
290 /* try to find a free urb in our list */
291 for (i = 0; i < NUM_CONTROL_URBS; ++i) {
292 if (bluetooth->control_urb_pool[i]->status != -EINPROGRESS) {
293 urb = bluetooth->control_urb_pool[i];
294 dr = &bluetooth->dr[i];
295 break;
296 }
297 }
298 if (urb == NULL) {
299 dbg ("%s - no free urbs", __FUNCTION__);
300 return -ENOMEM;
301 }
302
303 /* keep increasing the urb transfer buffer to fit the size of the message */
304 if (urb->transfer_buffer == NULL) {
305 urb->transfer_buffer = kmalloc (len, GFP_KERNEL);
306 if (urb->transfer_buffer == NULL) {
307 err ("%s - out of memory", __FUNCTION__);
308 return -ENOMEM;
309 }
310 }
311 if (urb->transfer_buffer_length < len) {
312 kfree(urb->transfer_buffer);
313 urb->transfer_buffer = kmalloc (len, GFP_KERNEL);
314 if (urb->transfer_buffer == NULL) {
315 err ("%s - out of memory", __FUNCTION__);
316 return -ENOMEM;
317 }
318 }
319 memcpy (urb->transfer_buffer, buf, len);
320
321 dr->bRequestType= BLUETOOTH_CONTROL_REQUEST_TYPE;
322 dr->bRequest = request;
323 dr->wValue = cpu_to_le16((u16) value);
324 dr->wIndex = cpu_to_le16((u16) bluetooth->control_out_bInterfaceNum);
325 dr->wLength = cpu_to_le16((u16) len);
326
327 usb_fill_control_urb (urb, bluetooth->dev, usb_sndctrlpipe(bluetooth->dev, 0),
328 (unsigned char*)dr, urb->transfer_buffer, len, bluetooth_ctrl_callback, bluetooth);
329
330 /* send it down the pipe */
331 status = usb_submit_urb(urb, GFP_KERNEL);
332 if (status)
333 dbg("%s - usb_submit_urb(control) failed with status = %d", __FUNCTION__, status);
334
335 return status;
336}
337
338
339
340
341
342/*****************************************************************************
343 * Driver tty interface functions
344 *****************************************************************************/
345static int bluetooth_open (struct tty_struct *tty, struct file * filp)
346{
347 struct usb_bluetooth *bluetooth;
348 int result;
349
350 dbg("%s", __FUNCTION__);
351
352 /* initialize the pointer incase something fails */
353 tty->driver_data = NULL;
354
355 /* get the bluetooth object associated with this tty pointer */
356 bluetooth = get_bluetooth_by_index (tty->index);
357
358 if (bluetooth_paranoia_check (bluetooth, __FUNCTION__)) {
359 return -ENODEV;
360 }
361
362 down (&bluetooth->lock);
363
364 ++bluetooth->open_count;
365 if (bluetooth->open_count == 1) {
366 /* set up our structure making the tty driver remember our object, and us it */
367 tty->driver_data = bluetooth;
368 bluetooth->tty = tty;
369
370 /* force low_latency on so that our tty_push actually forces the data through,
371 * otherwise it is scheduled, and with high data rates (like with OHCI) data
372 * can get lost. */
373 bluetooth->tty->low_latency = 1;
374
375 /* Reset the packet position counters */
376 bluetooth->int_packet_pos = 0;
377 bluetooth->bulk_packet_pos = 0;
378
379#ifndef BTBUGGYHARDWARE
380 /* Start reading from the device */
381 usb_fill_bulk_urb (bluetooth->read_urb, bluetooth->dev,
382 usb_rcvbulkpipe(bluetooth->dev, bluetooth->bulk_in_endpointAddress),
383 bluetooth->bulk_in_buffer,
384 bluetooth->bulk_in_buffer_size,
385 bluetooth_read_bulk_callback, bluetooth);
386 result = usb_submit_urb(bluetooth->read_urb, GFP_KERNEL);
387 if (result)
388 dbg("%s - usb_submit_urb(read bulk) failed with status %d", __FUNCTION__, result);
389#endif
390 usb_fill_int_urb (bluetooth->interrupt_in_urb, bluetooth->dev,
391 usb_rcvintpipe(bluetooth->dev, bluetooth->interrupt_in_endpointAddress),
392 bluetooth->interrupt_in_buffer,
393 bluetooth->interrupt_in_buffer_size,
394 bluetooth_int_callback, bluetooth,
395 bluetooth->interrupt_in_interval);
396 result = usb_submit_urb(bluetooth->interrupt_in_urb, GFP_KERNEL);
397 if (result)
398 dbg("%s - usb_submit_urb(interrupt in) failed with status %d", __FUNCTION__, result);
399 }
400
401 up(&bluetooth->lock);
402
403 return 0;
404}
405
406
407static void bluetooth_close (struct tty_struct *tty, struct file * filp)
408{
409 struct usb_bluetooth *bluetooth = get_usb_bluetooth ((struct usb_bluetooth *)tty->driver_data, __FUNCTION__);
410
411 if (!bluetooth) {
412 return;
413 }
414
415 dbg("%s", __FUNCTION__);
416
417 if (!bluetooth->open_count) {
418 dbg ("%s - device not opened", __FUNCTION__);
419 return;
420 }
421
422 down (&bluetooth->lock);
423
424 --bluetooth->open_count;
425 if (bluetooth->open_count <= 0) {
426 bluetooth->open_count = 0;
427
428 /* shutdown any in-flight urbs that we know about */
429 usb_kill_urb (bluetooth->read_urb);
430 usb_kill_urb (bluetooth->interrupt_in_urb);
431 }
432 up(&bluetooth->lock);
433}
434
435
436static int bluetooth_write (struct tty_struct * tty, const unsigned char *buf, int count)
437{
438 struct usb_bluetooth *bluetooth = get_usb_bluetooth ((struct usb_bluetooth *)tty->driver_data, __FUNCTION__);
439 struct urb *urb = NULL;
440 unsigned char *temp_buffer = NULL;
441 const unsigned char *current_buffer;
442 unsigned char *urb_buffer;
443 int i;
444 int retval = 0;
445
446 if (!bluetooth) {
447 return -ENODEV;
448 }
449
450 dbg("%s - %d byte(s)", __FUNCTION__, count);
451
452 if (!bluetooth->open_count) {
453 dbg ("%s - device not opened", __FUNCTION__);
454 return -EINVAL;
455 }
456
457 if (count == 0) {
458 dbg("%s - write request of 0 bytes", __FUNCTION__);
459 return 0;
460 }
461 if (count == 1) {
462 dbg("%s - write request only included type %d", __FUNCTION__, buf[0]);
463 return 1;
464 }
465
466#ifdef DEBUG
467 printk (KERN_DEBUG __FILE__ ": %s - length = %d, data = ", __FUNCTION__, count);
468 for (i = 0; i < count; ++i) {
469 printk ("%.2x ", buf[i]);
470 }
471 printk ("\n");
472#endif
473
474 current_buffer = buf;
475
476 switch (*current_buffer) {
477 /* First byte indicates the type of packet */
478 case CMD_PKT:
479 /* dbg("%s- Send cmd_pkt len:%d", __FUNCTION__, count);*/
480
481 retval = bluetooth_ctrl_msg (bluetooth, 0x00, 0x00, &current_buffer[1], count-1);
482 if (retval) {
483 goto exit;
484 }
485 retval = count;
486 break;
487
488 case ACL_PKT:
489 ++current_buffer;
490 --count;
491
492 urb_buffer = kmalloc (count, GFP_ATOMIC);
493 if (!urb_buffer) {
494 dev_err(&bluetooth->dev->dev, "out of memory\n");
495 retval = -ENOMEM;
496 goto exit;
497 }
498
499 urb = usb_alloc_urb(0, GFP_ATOMIC);
500 if (!urb) {
501 dev_err(&bluetooth->dev->dev, "no more free urbs\n");
502 kfree(urb_buffer);
503 retval = -ENOMEM;
504 goto exit;
505 }
506 memcpy (urb_buffer, current_buffer, count);
507
508 /* build up our urb */
509 usb_fill_bulk_urb(urb, bluetooth->dev,
510 usb_sndbulkpipe(bluetooth->dev,
511 bluetooth->bulk_out_endpointAddress),
512 urb_buffer,
513 count,
514 bluetooth_write_bulk_callback,
515 bluetooth);
516
517
518 /* send it down the pipe */
519 retval = usb_submit_urb(urb, GFP_KERNEL);
520 if (retval) {
521 dbg("%s - usb_submit_urb(write bulk) failed with error = %d", __FUNCTION__, retval);
522 goto exit;
523 }
524
525 /* we are done with this urb, so let the host driver
526 * really free it when it is finished with it */
527 usb_free_urb (urb);
528 retval = count + 1;
529 break;
530
531 default :
532 dbg("%s - unsupported (at this time) write type", __FUNCTION__);
533 retval = -EINVAL;
534 break;
535 }
536
537exit:
538 kfree(temp_buffer);
539
540 return retval;
541}
542
543
544static int bluetooth_write_room (struct tty_struct *tty)
545{
546 dbg("%s", __FUNCTION__);
547
548 /*
549 * We really can take anything the user throws at us
550 * but let's pick a nice big number to tell the tty
551 * layer that we have lots of free space
552 */
553 return 2048;
554}
555
556
557static int bluetooth_chars_in_buffer (struct tty_struct *tty)
558{
559 dbg("%s", __FUNCTION__);
560
561 /*
562 * We can't really account for how much data we
563 * have sent out, but hasn't made it through to the
564 * device, so just tell the tty layer that everything
565 * is flushed.
566 */
567 return 0;
568}
569
570
571static void bluetooth_throttle (struct tty_struct * tty)
572{
573 struct usb_bluetooth *bluetooth = get_usb_bluetooth ((struct usb_bluetooth *)tty->driver_data, __FUNCTION__);
574
575 if (!bluetooth) {
576 return;
577 }
578
579 dbg("%s", __FUNCTION__);
580
581 if (!bluetooth->open_count) {
582 dbg ("%s - device not open", __FUNCTION__);
583 return;
584 }
585
586 dbg("%s unsupported (at this time)", __FUNCTION__);
587
588 return;
589}
590
591
592static void bluetooth_unthrottle (struct tty_struct * tty)
593{
594 struct usb_bluetooth *bluetooth = get_usb_bluetooth ((struct usb_bluetooth *)tty->driver_data, __FUNCTION__);
595
596 if (!bluetooth) {
597 return;
598 }
599
600 dbg("%s", __FUNCTION__);
601
602 if (!bluetooth->open_count) {
603 dbg ("%s - device not open", __FUNCTION__);
604 return;
605 }
606
607 dbg("%s unsupported (at this time)", __FUNCTION__);
608}
609
610
611static int bluetooth_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg)
612{
613 struct usb_bluetooth *bluetooth = get_usb_bluetooth ((struct usb_bluetooth *)tty->driver_data, __FUNCTION__);
614
615 if (!bluetooth) {
616 return -ENODEV;
617 }
618
619 dbg("%s - cmd 0x%.4x", __FUNCTION__, cmd);
620
621 if (!bluetooth->open_count) {
622 dbg ("%s - device not open", __FUNCTION__);
623 return -ENODEV;
624 }
625
626 /* FIXME!!! */
627 return -ENOIOCTLCMD;
628}
629
630
631static void bluetooth_set_termios (struct tty_struct *tty, struct termios * old)
632{
633 struct usb_bluetooth *bluetooth = get_usb_bluetooth ((struct usb_bluetooth *)tty->driver_data, __FUNCTION__);
634
635 if (!bluetooth) {
636 return;
637 }
638
639 dbg("%s", __FUNCTION__);
640
641 if (!bluetooth->open_count) {
642 dbg ("%s - device not open", __FUNCTION__);
643 return;
644 }
645
646 /* FIXME!!! */
647
648 return;
649}
650
651
652#ifdef BTBUGGYHARDWARE
653void btusb_enable_bulk_read(struct tty_struct *tty){
654 struct usb_bluetooth *bluetooth = get_usb_bluetooth ((struct usb_bluetooth *)tty->driver_data, __FUNCTION__);
655 int result;
656
657 if (!bluetooth) {
658 return;
659 }
660
661 dbg("%s", __FUNCTION__);
662
663 if (!bluetooth->open_count) {
664 dbg ("%s - device not open", __FUNCTION__);
665 return;
666 }
667
668 if (bluetooth->read_urb) {
669 usb_fill_bulk_urb(bluetooth->read_urb, bluetooth->dev,
670 usb_rcvbulkpipe(bluetooth->dev, bluetooth->bulk_in_endpointAddress),
671 bluetooth->bulk_in_buffer, bluetooth->bulk_in_buffer_size,
672 bluetooth_read_bulk_callback, bluetooth);
673 result = usb_submit_urb(bluetooth->read_urb, GFP_KERNEL);
674 if (result)
675 err ("%s - failed submitting read urb, error %d", __FUNCTION__, result);
676 }
677}
678
679void btusb_disable_bulk_read(struct tty_struct *tty){
680 struct usb_bluetooth *bluetooth = get_usb_bluetooth ((struct usb_bluetooth *)tty->driver_data, __FUNCTION__);
681
682 if (!bluetooth) {
683 return;
684 }
685
686 dbg("%s", __FUNCTION__);
687
688 if (!bluetooth->open_count) {
689 dbg ("%s - device not open", __FUNCTION__);
690 return;
691 }
692
693 if ((bluetooth->read_urb) && (bluetooth->read_urb->actual_length))
694 usb_kill_urb(bluetooth->read_urb);
695}
696#endif
697
698
699/*****************************************************************************
700 * urb callback functions
701 *****************************************************************************/
702
703
704static void bluetooth_int_callback (struct urb *urb, struct pt_regs *regs)
705{
706 struct usb_bluetooth *bluetooth = get_usb_bluetooth ((struct usb_bluetooth *)urb->context, __FUNCTION__);
707 unsigned char *data = urb->transfer_buffer;
708 unsigned int i;
709 unsigned int count = urb->actual_length;
710 unsigned int packet_size;
711 int status;
712
713 dbg("%s", __FUNCTION__);
714
715 if (!bluetooth) {
716 dbg("%s - bad bluetooth pointer, exiting", __FUNCTION__);
717 return;
718 }
719
720 switch (urb->status) {
721 case 0:
722 /* success */
723 break;
724 case -ECONNRESET:
725 case -ENOENT:
726 case -ESHUTDOWN:
727 /* this urb is terminated, clean up */
728 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
729 return;
730 default:
731 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
732 goto exit;
733 }
734
735 if (!count) {
736 dbg("%s - zero length int", __FUNCTION__);
737 goto exit;
738 }
739
740
741#ifdef DEBUG
742 if (count) {
743 printk (KERN_DEBUG __FILE__ ": %s- length = %d, data = ", __FUNCTION__, count);
744 for (i = 0; i < count; ++i) {
745 printk ("%.2x ", data[i]);
746 }
747 printk ("\n");
748 }
749#endif
750
751#ifdef BTBUGGYHARDWARE
752 if ((count >= 2) && (data[0] == 0xFF) && (data[1] == 0x00)) {
753 data += 2;
754 count -= 2;
755 }
756 if (count == 0) {
757 urb->actual_length = 0;
758 goto exit;
759 }
760#endif
761 /* We add a packet type identifier to the beginning of each
762 HCI frame. This makes the data in the tty look like a
763 serial USB devices. Each HCI frame can be broken across
764 multiple URBs so we buffer them until we have a full hci
765 packet */
766
767 if (!bluetooth->int_packet_pos) {
768 bluetooth->int_buffer[0] = EVENT_PKT;
769 bluetooth->int_packet_pos++;
770 }
771
772 if (bluetooth->int_packet_pos + count > EVENT_BUFFER_SIZE) {
773 err("%s - exceeded EVENT_BUFFER_SIZE", __FUNCTION__);
774 bluetooth->int_packet_pos = 0;
775 goto exit;
776 }
777
778 memcpy (&bluetooth->int_buffer[bluetooth->int_packet_pos],
779 urb->transfer_buffer, count);
780 bluetooth->int_packet_pos += count;
781 urb->actual_length = 0;
782
783 if (bluetooth->int_packet_pos >= EVENT_HDR_SIZE)
784 packet_size = bluetooth->int_buffer[2];
785 else
786 goto exit;
787
788 if (packet_size + EVENT_HDR_SIZE < bluetooth->int_packet_pos) {
789 err("%s - packet was too long", __FUNCTION__);
790 bluetooth->int_packet_pos = 0;
791 goto exit;
792 }
793
794 if (packet_size + EVENT_HDR_SIZE == bluetooth->int_packet_pos) {
795 for (i = 0; i < bluetooth->int_packet_pos; ++i) {
796 /* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them */
797 if (bluetooth->tty->flip.count >= TTY_FLIPBUF_SIZE) {
798 tty_flip_buffer_push(bluetooth->tty);
799 }
800 tty_insert_flip_char(bluetooth->tty, bluetooth->int_buffer[i], 0);
801 }
802 tty_flip_buffer_push(bluetooth->tty);
803
804 bluetooth->int_packet_pos = 0;
805 }
806
807exit:
808 status = usb_submit_urb (urb, GFP_ATOMIC);
809 if (status)
810 err ("%s - usb_submit_urb failed with result %d",
811 __FUNCTION__, status);
812}
813
814
815static void bluetooth_ctrl_callback (struct urb *urb, struct pt_regs *regs)
816{
817 struct usb_bluetooth *bluetooth = get_usb_bluetooth ((struct usb_bluetooth *)urb->context, __FUNCTION__);
818
819 dbg("%s", __FUNCTION__);
820
821 if (!bluetooth) {
822 dbg("%s - bad bluetooth pointer, exiting", __FUNCTION__);
823 return;
824 }
825
826 if (urb->status) {
827 dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status);
828 return;
829 }
830}
831
832
833static void bluetooth_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
834{
835 struct usb_bluetooth *bluetooth = get_usb_bluetooth ((struct usb_bluetooth *)urb->context, __FUNCTION__);
836 unsigned char *data = urb->transfer_buffer;
837 unsigned int count = urb->actual_length;
838 unsigned int i;
839 unsigned int packet_size;
840 int result;
841
842
843 dbg("%s", __FUNCTION__);
844
845 if (!bluetooth) {
846 dbg("%s - bad bluetooth pointer, exiting", __FUNCTION__);
847 return;
848 }
849
850 if (urb->status) {
851 dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status);
852 if (urb->status == -ENOENT) {
853 dbg("%s - URB canceled, won't reschedule", __FUNCTION__);
854 return;
855 }
856 goto exit;
857 }
858
859 if (!count) {
860 dbg("%s - zero length read bulk", __FUNCTION__);
861 goto exit;
862 }
863
864#ifdef DEBUG
865 if (count) {
866 printk (KERN_DEBUG __FILE__ ": %s- length = %d, data = ", __FUNCTION__, count);
867 for (i = 0; i < count; ++i) {
868 printk ("%.2x ", data[i]);
869 }
870 printk ("\n");
871 }
872#endif
873#ifdef BTBUGGYHARDWARE
874 if ((count == 4) && (data[0] == 0x00) && (data[1] == 0x00)
875 && (data[2] == 0x00) && (data[3] == 0x00)) {
876 urb->actual_length = 0;
877 usb_fill_bulk_urb(bluetooth->read_urb, bluetooth->dev,
878 usb_rcvbulkpipe(bluetooth->dev, bluetooth->bulk_in_endpointAddress),
879 bluetooth->bulk_in_buffer, bluetooth->bulk_in_buffer_size,
880 bluetooth_read_bulk_callback, bluetooth);
881 result = usb_submit_urb(bluetooth->read_urb, GFP_KERNEL);
882 if (result)
883 err ("%s - failed resubmitting read urb, error %d", __FUNCTION__, result);
884
885 return;
886 }
887#endif
888 /* We add a packet type identifier to the beginning of each
889 HCI frame. This makes the data in the tty look like a
890 serial USB devices. Each HCI frame can be broken across
891 multiple URBs so we buffer them until we have a full hci
892 packet */
893
894 if (!bluetooth->bulk_packet_pos) {
895 bluetooth->bulk_buffer[0] = ACL_PKT;
896 bluetooth->bulk_packet_pos++;
897 }
898
899 if (bluetooth->bulk_packet_pos + count > ACL_BUFFER_SIZE) {
900 err("%s - exceeded ACL_BUFFER_SIZE", __FUNCTION__);
901 bluetooth->bulk_packet_pos = 0;
902 goto exit;
903 }
904
905 memcpy (&bluetooth->bulk_buffer[bluetooth->bulk_packet_pos],
906 urb->transfer_buffer, count);
907 bluetooth->bulk_packet_pos += count;
908 urb->actual_length = 0;
909
910 if (bluetooth->bulk_packet_pos >= ACL_HDR_SIZE) {
911 packet_size = CHAR2INT16(bluetooth->bulk_buffer[4],bluetooth->bulk_buffer[3]);
912 } else {
913 goto exit;
914 }
915
916 if (packet_size + ACL_HDR_SIZE < bluetooth->bulk_packet_pos) {
917 err("%s - packet was too long", __FUNCTION__);
918 bluetooth->bulk_packet_pos = 0;
919 goto exit;
920 }
921
922 if (packet_size + ACL_HDR_SIZE == bluetooth->bulk_packet_pos) {
923 for (i = 0; i < bluetooth->bulk_packet_pos; ++i) {
924 /* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */
925 if (bluetooth->tty->flip.count >= TTY_FLIPBUF_SIZE) {
926 tty_flip_buffer_push(bluetooth->tty);
927 }
928 tty_insert_flip_char(bluetooth->tty, bluetooth->bulk_buffer[i], 0);
929 }
930 tty_flip_buffer_push(bluetooth->tty);
931 bluetooth->bulk_packet_pos = 0;
932 }
933
934exit:
935 if (!bluetooth || !bluetooth->open_count)
936 return;
937
938 usb_fill_bulk_urb(bluetooth->read_urb, bluetooth->dev,
939 usb_rcvbulkpipe(bluetooth->dev, bluetooth->bulk_in_endpointAddress),
940 bluetooth->bulk_in_buffer, bluetooth->bulk_in_buffer_size,
941 bluetooth_read_bulk_callback, bluetooth);
942 result = usb_submit_urb(bluetooth->read_urb, GFP_KERNEL);
943 if (result)
944 err ("%s - failed resubmitting read urb, error %d", __FUNCTION__, result);
945
946 return;
947}
948
949
950static void bluetooth_write_bulk_callback (struct urb *urb, struct pt_regs *regs)
951{
952 struct usb_bluetooth *bluetooth = get_usb_bluetooth ((struct usb_bluetooth *)urb->context, __FUNCTION__);
953
954 dbg("%s", __FUNCTION__);
955
956 /* free up the transfer buffer, as usb_free_urb() does not do this */
957 kfree(urb->transfer_buffer);
958
959 if (!bluetooth) {
960 dbg("%s - bad bluetooth pointer, exiting", __FUNCTION__);
961 return;
962 }
963
964 if (urb->status) {
965 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
966 return;
967 }
968
969 /* wake up our little function to let the tty layer know that something happened */
970 schedule_work(&bluetooth->work);
971}
972
973
974static void bluetooth_softint(void *private)
975{
976 struct usb_bluetooth *bluetooth = get_usb_bluetooth ((struct usb_bluetooth *)private, __FUNCTION__);
977
978 dbg("%s", __FUNCTION__);
979
980 if (!bluetooth)
981 return;
982
983 tty_wakeup(bluetooth->tty);
984}
985
986
987static int usb_bluetooth_probe (struct usb_interface *intf,
988 const struct usb_device_id *id)
989{
990 struct usb_device *dev = interface_to_usbdev (intf);
991 struct usb_bluetooth *bluetooth = NULL;
992 struct usb_host_interface *interface;
993 struct usb_endpoint_descriptor *endpoint;
994 struct usb_endpoint_descriptor *interrupt_in_endpoint[8];
995 struct usb_endpoint_descriptor *bulk_in_endpoint[8];
996 struct usb_endpoint_descriptor *bulk_out_endpoint[8];
997 int control_out_endpoint;
998
999 int minor;
1000 int buffer_size;
1001 int i;
1002 int num_interrupt_in = 0;
1003 int num_bulk_in = 0;
1004 int num_bulk_out = 0;
1005
1006 interface = intf->cur_altsetting;
1007 control_out_endpoint = interface->desc.bInterfaceNumber;
1008
1009 /* find the endpoints that we need */
1010 for (i = 0; i < interface->desc.bNumEndpoints; ++i) {
1011 endpoint = &interface->endpoint[i].desc;
1012
1013 if ((endpoint->bEndpointAddress & 0x80) &&
1014 ((endpoint->bmAttributes & 3) == 0x02)) {
1015 /* we found a bulk in endpoint */
1016 dbg("found bulk in");
1017 bulk_in_endpoint[num_bulk_in] = endpoint;
1018 ++num_bulk_in;
1019 }
1020
1021 if (((endpoint->bEndpointAddress & 0x80) == 0x00) &&
1022 ((endpoint->bmAttributes & 3) == 0x02)) {
1023 /* we found a bulk out endpoint */
1024 dbg("found bulk out");
1025 bulk_out_endpoint[num_bulk_out] = endpoint;
1026 ++num_bulk_out;
1027 }
1028
1029 if ((endpoint->bEndpointAddress & 0x80) &&
1030 ((endpoint->bmAttributes & 3) == 0x03)) {
1031 /* we found a interrupt in endpoint */
1032 dbg("found interrupt in");
1033 interrupt_in_endpoint[num_interrupt_in] = endpoint;
1034 ++num_interrupt_in;
1035 }
1036 }
1037
1038 /* according to the spec, we can only have 1 bulk_in, 1 bulk_out, and 1 interrupt_in endpoints */
1039 if ((num_bulk_in != 1) ||
1040 (num_bulk_out != 1) ||
1041 (num_interrupt_in != 1)) {
1042 dbg ("%s - improper number of endpoints. Bluetooth driver not bound.", __FUNCTION__);
1043 return -EIO;
1044 }
1045
1046 info("USB Bluetooth converter detected");
1047
1048 for (minor = 0; minor < BLUETOOTH_TTY_MINORS && bluetooth_table[minor]; ++minor)
1049 ;
1050 if (bluetooth_table[minor]) {
1051 err("No more free Bluetooth devices");
1052 return -ENODEV;
1053 }
1054
1055 if (!(bluetooth = kmalloc(sizeof(struct usb_bluetooth), GFP_KERNEL))) {
1056 err("Out of memory");
1057 return -ENOMEM;
1058 }
1059
1060 memset(bluetooth, 0, sizeof(struct usb_bluetooth));
1061
1062 bluetooth->magic = USB_BLUETOOTH_MAGIC;
1063 bluetooth->dev = dev;
1064 bluetooth->minor = minor;
1065 INIT_WORK(&bluetooth->work, bluetooth_softint, bluetooth);
1066 init_MUTEX(&bluetooth->lock);
1067
1068 /* record the interface number for the control out */
1069 bluetooth->control_out_bInterfaceNum = control_out_endpoint;
1070
1071 /* create our control out urb pool */
1072 for (i = 0; i < NUM_CONTROL_URBS; ++i) {
1073 struct urb *urb = usb_alloc_urb(0, GFP_KERNEL);
1074 if (urb == NULL) {
1075 err("No free urbs available");
1076 goto probe_error;
1077 }
1078 urb->transfer_buffer = NULL;
1079 bluetooth->control_urb_pool[i] = urb;
1080 }
1081
1082 /* set up the endpoint information */
1083 endpoint = bulk_in_endpoint[0];
1084 bluetooth->read_urb = usb_alloc_urb (0, GFP_KERNEL);
1085 if (!bluetooth->read_urb) {
1086 err("No free urbs available");
1087 goto probe_error;
1088 }
1089 bluetooth->bulk_in_buffer_size = buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
1090 bluetooth->bulk_in_endpointAddress = endpoint->bEndpointAddress;
1091 bluetooth->bulk_in_buffer = kmalloc (buffer_size, GFP_KERNEL);
1092 if (!bluetooth->bulk_in_buffer) {
1093 err("Couldn't allocate bulk_in_buffer");
1094 goto probe_error;
1095 }
1096 usb_fill_bulk_urb(bluetooth->read_urb, dev, usb_rcvbulkpipe(dev, endpoint->bEndpointAddress),
1097 bluetooth->bulk_in_buffer, buffer_size, bluetooth_read_bulk_callback, bluetooth);
1098
1099 endpoint = bulk_out_endpoint[0];
1100 bluetooth->bulk_out_endpointAddress = endpoint->bEndpointAddress;
1101 bluetooth->bulk_out_buffer_size = le16_to_cpu(endpoint->wMaxPacketSize) * 2;
1102
1103 endpoint = interrupt_in_endpoint[0];
1104 bluetooth->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL);
1105 if (!bluetooth->interrupt_in_urb) {
1106 err("No free urbs available");
1107 goto probe_error;
1108 }
1109 bluetooth->interrupt_in_buffer_size = buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
1110 bluetooth->interrupt_in_endpointAddress = endpoint->bEndpointAddress;
1111 bluetooth->interrupt_in_interval = endpoint->bInterval;
1112 bluetooth->interrupt_in_buffer = kmalloc (buffer_size, GFP_KERNEL);
1113 if (!bluetooth->interrupt_in_buffer) {
1114 err("Couldn't allocate interrupt_in_buffer");
1115 goto probe_error;
1116 }
1117 usb_fill_int_urb(bluetooth->interrupt_in_urb, dev, usb_rcvintpipe(dev, endpoint->bEndpointAddress),
1118 bluetooth->interrupt_in_buffer, buffer_size, bluetooth_int_callback,
1119 bluetooth, endpoint->bInterval);
1120
1121 /* initialize the devfs nodes for this device and let the user know what bluetooths we are bound to */
1122 tty_register_device (bluetooth_tty_driver, minor, &intf->dev);
1123 info("Bluetooth converter now attached to ttyUB%d (or usb/ttub/%d for devfs)", minor, minor);
1124
1125 bluetooth_table[minor] = bluetooth;
1126
1127 /* success */
1128 usb_set_intfdata (intf, bluetooth);
1129 return 0;
1130
1131probe_error:
1132 if (bluetooth->read_urb)
1133 usb_free_urb (bluetooth->read_urb);
1134 if (bluetooth->bulk_in_buffer)
1135 kfree (bluetooth->bulk_in_buffer);
1136 if (bluetooth->interrupt_in_urb)
1137 usb_free_urb (bluetooth->interrupt_in_urb);
1138 if (bluetooth->interrupt_in_buffer)
1139 kfree (bluetooth->interrupt_in_buffer);
1140 for (i = 0; i < NUM_CONTROL_URBS; ++i)
1141 if (bluetooth->control_urb_pool[i]) {
1142 if (bluetooth->control_urb_pool[i]->transfer_buffer)
1143 kfree (bluetooth->control_urb_pool[i]->transfer_buffer);
1144 usb_free_urb (bluetooth->control_urb_pool[i]);
1145 }
1146
1147 bluetooth_table[minor] = NULL;
1148
1149 /* free up any memory that we allocated */
1150 kfree (bluetooth);
1151 return -EIO;
1152}
1153
1154
1155static void usb_bluetooth_disconnect(struct usb_interface *intf)
1156{
1157 struct usb_bluetooth *bluetooth = usb_get_intfdata (intf);
1158 int i;
1159
1160 usb_set_intfdata (intf, NULL);
1161 if (bluetooth) {
1162 if ((bluetooth->open_count) && (bluetooth->tty))
1163 tty_hangup(bluetooth->tty);
1164
1165 bluetooth->open_count = 0;
1166
1167 if (bluetooth->read_urb) {
1168 usb_kill_urb (bluetooth->read_urb);
1169 usb_free_urb (bluetooth->read_urb);
1170 }
1171 if (bluetooth->bulk_in_buffer)
1172 kfree (bluetooth->bulk_in_buffer);
1173
1174 if (bluetooth->interrupt_in_urb) {
1175 usb_kill_urb (bluetooth->interrupt_in_urb);
1176 usb_free_urb (bluetooth->interrupt_in_urb);
1177 }
1178 if (bluetooth->interrupt_in_buffer)
1179 kfree (bluetooth->interrupt_in_buffer);
1180
1181 tty_unregister_device (bluetooth_tty_driver, bluetooth->minor);
1182
1183 for (i = 0; i < NUM_CONTROL_URBS; ++i) {
1184 if (bluetooth->control_urb_pool[i]) {
1185 usb_kill_urb (bluetooth->control_urb_pool[i]);
1186 if (bluetooth->control_urb_pool[i]->transfer_buffer)
1187 kfree (bluetooth->control_urb_pool[i]->transfer_buffer);
1188 usb_free_urb (bluetooth->control_urb_pool[i]);
1189 }
1190 }
1191
1192 info("Bluetooth converter now disconnected from ttyUB%d", bluetooth->minor);
1193
1194 bluetooth_table[bluetooth->minor] = NULL;
1195
1196 /* free up any memory that we allocated */
1197 kfree (bluetooth);
1198 } else {
1199 info("device disconnected");
1200 }
1201}
1202
1203static struct tty_operations bluetooth_ops = {
1204 .open = bluetooth_open,
1205 .close = bluetooth_close,
1206 .write = bluetooth_write,
1207 .write_room = bluetooth_write_room,
1208 .ioctl = bluetooth_ioctl,
1209 .set_termios = bluetooth_set_termios,
1210 .throttle = bluetooth_throttle,
1211 .unthrottle = bluetooth_unthrottle,
1212 .chars_in_buffer = bluetooth_chars_in_buffer,
1213};
1214
1215static int usb_bluetooth_init(void)
1216{
1217 int i;
1218 int result;
1219
1220 /* Initialize our global data */
1221 for (i = 0; i < BLUETOOTH_TTY_MINORS; ++i) {
1222 bluetooth_table[i] = NULL;
1223 }
1224
1225 info ("USB Bluetooth support registered");
1226
1227 bluetooth_tty_driver = alloc_tty_driver(BLUETOOTH_TTY_MINORS);
1228 if (!bluetooth_tty_driver)
1229 return -ENOMEM;
1230
1231 bluetooth_tty_driver->owner = THIS_MODULE;
1232 bluetooth_tty_driver->driver_name = "usb-bluetooth";
1233 bluetooth_tty_driver->name = "ttyUB";
1234 bluetooth_tty_driver->devfs_name = "usb/ttub/";
1235 bluetooth_tty_driver->major = BLUETOOTH_TTY_MAJOR;
1236 bluetooth_tty_driver->minor_start = 0;
1237 bluetooth_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
1238 bluetooth_tty_driver->subtype = SERIAL_TYPE_NORMAL;
1239 bluetooth_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS;
1240 bluetooth_tty_driver->init_termios = tty_std_termios;
1241 bluetooth_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1242 tty_set_operations(bluetooth_tty_driver, &bluetooth_ops);
1243 if (tty_register_driver (bluetooth_tty_driver)) {
1244 err("%s - failed to register tty driver", __FUNCTION__);
1245 put_tty_driver(bluetooth_tty_driver);
1246 return -1;
1247 }
1248
1249 /* register the USB driver */
1250 result = usb_register(&usb_bluetooth_driver);
1251 if (result < 0) {
1252 tty_unregister_driver(bluetooth_tty_driver);
1253 put_tty_driver(bluetooth_tty_driver);
1254 err("usb_register failed for the USB bluetooth driver. Error number %d", result);
1255 return -1;
1256 }
1257
1258 info(DRIVER_DESC " " DRIVER_VERSION);
1259
1260 return 0;
1261}
1262
1263
1264static void usb_bluetooth_exit(void)
1265{
1266 usb_deregister(&usb_bluetooth_driver);
1267 tty_unregister_driver(bluetooth_tty_driver);
1268 put_tty_driver(bluetooth_tty_driver);
1269}
1270
1271
1272module_init(usb_bluetooth_init);
1273module_exit(usb_bluetooth_exit);
1274
1275/* Module information */
1276MODULE_AUTHOR( DRIVER_AUTHOR );
1277MODULE_DESCRIPTION( DRIVER_DESC );
1278MODULE_LICENSE("GPL");
1279
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 16ecad30e29c..1b4751412970 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -827,11 +827,10 @@ skip_normal_probe:
827 return -ENODEV; 827 return -ENODEV;
828 } 828 }
829 829
830 if (!(acm = kmalloc(sizeof(struct acm), GFP_KERNEL))) { 830 if (!(acm = kzalloc(sizeof(struct acm), GFP_KERNEL))) {
831 dev_dbg(&intf->dev, "out of memory (acm kmalloc)\n"); 831 dev_dbg(&intf->dev, "out of memory (acm kzalloc)\n");
832 goto alloc_fail; 832 goto alloc_fail;
833 } 833 }
834 memset(acm, 0, sizeof(struct acm));
835 834
836 ctrlsize = le16_to_cpu(epctrl->wMaxPacketSize); 835 ctrlsize = le16_to_cpu(epctrl->wMaxPacketSize);
837 readsize = le16_to_cpu(epread->wMaxPacketSize); 836 readsize = le16_to_cpu(epread->wMaxPacketSize);
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index e195709c9c7f..357e75335f17 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -844,9 +844,8 @@ static struct file_operations usblp_fops = {
844}; 844};
845 845
846static struct usb_class_driver usblp_class = { 846static struct usb_class_driver usblp_class = {
847 .name = "usb/lp%d", 847 .name = "lp%d",
848 .fops = &usblp_fops, 848 .fops = &usblp_fops,
849 .mode = S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
850 .minor_base = USBLP_MINOR_BASE, 849 .minor_base = USBLP_MINOR_BASE,
851}; 850};
852 851
diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig
index 1a9ff6184943..ff03184da403 100644
--- a/drivers/usb/core/Kconfig
+++ b/drivers/usb/core/Kconfig
@@ -61,14 +61,17 @@ config USB_DYNAMIC_MINORS
61 If you are unsure about this, say N here. 61 If you are unsure about this, say N here.
62 62
63config USB_SUSPEND 63config USB_SUSPEND
64 bool "USB suspend/resume (EXPERIMENTAL)" 64 bool "USB selective suspend/resume and wakeup (EXPERIMENTAL)"
65 depends on USB && PM && EXPERIMENTAL 65 depends on USB && PM && EXPERIMENTAL
66 help 66 help
67 If you say Y here, you can use driver calls or the sysfs 67 If you say Y here, you can use driver calls or the sysfs
68 "power/state" file to suspend or resume individual USB 68 "power/state" file to suspend or resume individual USB
69 peripherals. There are many related features, such as 69 peripherals.
70 remote wakeup and driver-specific suspend processing, that 70
71 may not yet work as expected. 71 Also, USB "remote wakeup" signaling is supported, whereby some
72 USB devices (like keyboards and network adapters) can wake up
73 their parent hub. That wakeup cascades up the USB tree, and
74 could wake the system from states like suspend-to-RAM.
72 75
73 If you are unsure about this, say N here. 76 If you are unsure about this, say N here.
74 77
diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile
index d5503cf0bf74..dd1c4d2a0c31 100644
--- a/drivers/usb/core/Makefile
+++ b/drivers/usb/core/Makefile
@@ -3,7 +3,7 @@
3# 3#
4 4
5usbcore-objs := usb.o hub.o hcd.o urb.o message.o \ 5usbcore-objs := usb.o hub.o hcd.o urb.o message.o \
6 config.o file.o buffer.o sysfs.o devio.o 6 config.o file.o buffer.o sysfs.o devio.o notify.o
7 7
8ifeq ($(CONFIG_PCI),y) 8ifeq ($(CONFIG_PCI),y)
9 usbcore-objs += hcd-pci.o 9 usbcore-objs += hcd-pci.o
diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c
index fc15b4acc8af..57e800ac3cee 100644
--- a/drivers/usb/core/buffer.c
+++ b/drivers/usb/core/buffer.c
@@ -106,7 +106,7 @@ void hcd_buffer_destroy (struct usb_hcd *hcd)
106void *hcd_buffer_alloc ( 106void *hcd_buffer_alloc (
107 struct usb_bus *bus, 107 struct usb_bus *bus,
108 size_t size, 108 size_t size,
109 unsigned mem_flags, 109 gfp_t mem_flags,
110 dma_addr_t *dma 110 dma_addr_t *dma
111) 111)
112{ 112{
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
index 99595e07b653..993019500cc3 100644
--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -112,8 +112,12 @@ void usb_release_interface_cache(struct kref *ref)
112 struct usb_interface_cache *intfc = ref_to_usb_interface_cache(ref); 112 struct usb_interface_cache *intfc = ref_to_usb_interface_cache(ref);
113 int j; 113 int j;
114 114
115 for (j = 0; j < intfc->num_altsetting; j++) 115 for (j = 0; j < intfc->num_altsetting; j++) {
116 kfree(intfc->altsetting[j].endpoint); 116 struct usb_host_interface *alt = &intfc->altsetting[j];
117
118 kfree(alt->endpoint);
119 kfree(alt->string);
120 }
117 kfree(intfc); 121 kfree(intfc);
118} 122}
119 123
@@ -188,10 +192,9 @@ static int usb_parse_interface(struct device *ddev, int cfgno,
188 } 192 }
189 193
190 len = sizeof(struct usb_host_endpoint) * num_ep; 194 len = sizeof(struct usb_host_endpoint) * num_ep;
191 alt->endpoint = kmalloc(len, GFP_KERNEL); 195 alt->endpoint = kzalloc(len, GFP_KERNEL);
192 if (!alt->endpoint) 196 if (!alt->endpoint)
193 return -ENOMEM; 197 return -ENOMEM;
194 memset(alt->endpoint, 0, len);
195 198
196 /* Parse all the endpoint descriptors */ 199 /* Parse all the endpoint descriptors */
197 n = 0; 200 n = 0;
@@ -353,10 +356,9 @@ static int usb_parse_configuration(struct device *ddev, int cfgidx,
353 } 356 }
354 357
355 len = sizeof(*intfc) + sizeof(struct usb_host_interface) * j; 358 len = sizeof(*intfc) + sizeof(struct usb_host_interface) * j;
356 config->intf_cache[i] = intfc = kmalloc(len, GFP_KERNEL); 359 config->intf_cache[i] = intfc = kzalloc(len, GFP_KERNEL);
357 if (!intfc) 360 if (!intfc)
358 return -ENOMEM; 361 return -ENOMEM;
359 memset(intfc, 0, len);
360 kref_init(&intfc->ref); 362 kref_init(&intfc->ref);
361 } 363 }
362 364
@@ -422,8 +424,6 @@ void usb_destroy_configuration(struct usb_device *dev)
422 struct usb_host_config *cf = &dev->config[c]; 424 struct usb_host_config *cf = &dev->config[c];
423 425
424 kfree(cf->string); 426 kfree(cf->string);
425 cf->string = NULL;
426
427 for (i = 0; i < cf->desc.bNumInterfaces; i++) { 427 for (i = 0; i < cf->desc.bNumInterfaces; i++) {
428 if (cf->intf_cache[i]) 428 if (cf->intf_cache[i])
429 kref_put(&cf->intf_cache[i]->ref, 429 kref_put(&cf->intf_cache[i]->ref,
@@ -459,16 +459,14 @@ int usb_get_configuration(struct usb_device *dev)
459 } 459 }
460 460
461 length = ncfg * sizeof(struct usb_host_config); 461 length = ncfg * sizeof(struct usb_host_config);
462 dev->config = kmalloc(length, GFP_KERNEL); 462 dev->config = kzalloc(length, GFP_KERNEL);
463 if (!dev->config) 463 if (!dev->config)
464 goto err2; 464 goto err2;
465 memset(dev->config, 0, length);
466 465
467 length = ncfg * sizeof(char *); 466 length = ncfg * sizeof(char *);
468 dev->rawdescriptors = kmalloc(length, GFP_KERNEL); 467 dev->rawdescriptors = kzalloc(length, GFP_KERNEL);
469 if (!dev->rawdescriptors) 468 if (!dev->rawdescriptors)
470 goto err2; 469 goto err2;
471 memset(dev->rawdescriptors, 0, length);
472 470
473 buffer = kmalloc(USB_DT_CONFIG_SIZE, GFP_KERNEL); 471 buffer = kmalloc(USB_DT_CONFIG_SIZE, GFP_KERNEL);
474 if (!buffer) 472 if (!buffer)
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 487ff672b104..942cd437dc48 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -46,6 +46,7 @@
46#include <linux/usb.h> 46#include <linux/usb.h>
47#include <linux/usbdevice_fs.h> 47#include <linux/usbdevice_fs.h>
48#include <linux/cdev.h> 48#include <linux/cdev.h>
49#include <linux/notifier.h>
49#include <asm/uaccess.h> 50#include <asm/uaccess.h>
50#include <asm/byteorder.h> 51#include <asm/byteorder.h>
51#include <linux/moduleparam.h> 52#include <linux/moduleparam.h>
@@ -209,10 +210,10 @@ err:
209static struct async *alloc_async(unsigned int numisoframes) 210static struct async *alloc_async(unsigned int numisoframes)
210{ 211{
211 unsigned int assize = sizeof(struct async) + numisoframes * sizeof(struct usb_iso_packet_descriptor); 212 unsigned int assize = sizeof(struct async) + numisoframes * sizeof(struct usb_iso_packet_descriptor);
212 struct async *as = kmalloc(assize, GFP_KERNEL); 213 struct async *as = kzalloc(assize, GFP_KERNEL);
214
213 if (!as) 215 if (!as)
214 return NULL; 216 return NULL;
215 memset(as, 0, assize);
216 as->urb = usb_alloc_urb(numisoframes, GFP_KERNEL); 217 as->urb = usb_alloc_urb(numisoframes, GFP_KERNEL);
217 if (!as->urb) { 218 if (!as->urb) {
218 kfree(as); 219 kfree(as);
@@ -279,6 +280,28 @@ static inline struct async *async_getpending(struct dev_state *ps, void __user *
279 return NULL; 280 return NULL;
280} 281}
281 282
283static void snoop_urb(struct urb *urb, void __user *userurb)
284{
285 int j;
286 unsigned char *data = urb->transfer_buffer;
287
288 if (!usbfs_snoop)
289 return;
290
291 if (urb->pipe & USB_DIR_IN)
292 dev_info(&urb->dev->dev, "direction=IN\n");
293 else
294 dev_info(&urb->dev->dev, "direction=OUT\n");
295 dev_info(&urb->dev->dev, "userurb=%p\n", userurb);
296 dev_info(&urb->dev->dev, "transfer_buffer_length=%d\n",
297 urb->transfer_buffer_length);
298 dev_info(&urb->dev->dev, "actual_length=%d\n", urb->actual_length);
299 dev_info(&urb->dev->dev, "data: ");
300 for (j = 0; j < urb->transfer_buffer_length; ++j)
301 printk ("%02x ", data[j]);
302 printk("\n");
303}
304
282static void async_completed(struct urb *urb, struct pt_regs *regs) 305static void async_completed(struct urb *urb, struct pt_regs *regs)
283{ 306{
284 struct async *as = (struct async *)urb->context; 307 struct async *as = (struct async *)urb->context;
@@ -296,7 +319,9 @@ static void async_completed(struct urb *urb, struct pt_regs *regs)
296 kill_proc_info_as_uid(as->signr, &sinfo, as->pid, as->uid, 319 kill_proc_info_as_uid(as->signr, &sinfo, as->pid, as->uid,
297 as->euid); 320 as->euid);
298 } 321 }
299 wake_up(&ps->wait); 322 snoop(&urb->dev->dev, "urb complete\n");
323 snoop_urb(urb, as->userurb);
324 wake_up(&ps->wait);
300} 325}
301 326
302static void destroy_async (struct dev_state *ps, struct list_head *list) 327static void destroy_async (struct dev_state *ps, struct list_head *list)
@@ -493,6 +518,23 @@ static int check_ctrlrecip(struct dev_state *ps, unsigned int requesttype, unsig
493 return ret; 518 return ret;
494} 519}
495 520
521static struct usb_device *usbdev_lookup_minor(int minor)
522{
523 struct class_device *class_dev;
524 struct usb_device *dev = NULL;
525
526 down(&usb_device_class->sem);
527 list_for_each_entry(class_dev, &usb_device_class->children, node) {
528 if (class_dev->devt == MKDEV(USB_DEVICE_MAJOR, minor)) {
529 dev = class_dev->class_data;
530 break;
531 }
532 }
533 up(&usb_device_class->sem);
534
535 return dev;
536};
537
496/* 538/*
497 * file operations 539 * file operations
498 */ 540 */
@@ -601,7 +643,7 @@ static int proc_control(struct dev_state *ps, void __user *arg)
601 if (usbfs_snoop) { 643 if (usbfs_snoop) {
602 dev_info(&dev->dev, "control read: data "); 644 dev_info(&dev->dev, "control read: data ");
603 for (j = 0; j < i; ++j) 645 for (j = 0; j < i; ++j)
604 printk ("%02x ", (unsigned char)(tbuf)[j]); 646 printk("%02x ", (unsigned char)(tbuf)[j]);
605 printk("\n"); 647 printk("\n");
606 } 648 }
607 if (copy_to_user(ctrl.data, tbuf, i)) { 649 if (copy_to_user(ctrl.data, tbuf, i)) {
@@ -624,7 +666,7 @@ static int proc_control(struct dev_state *ps, void __user *arg)
624 if (usbfs_snoop) { 666 if (usbfs_snoop) {
625 dev_info(&dev->dev, "control write: data: "); 667 dev_info(&dev->dev, "control write: data: ");
626 for (j = 0; j < ctrl.wLength; ++j) 668 for (j = 0; j < ctrl.wLength; ++j)
627 printk ("%02x ", (unsigned char)(tbuf)[j]); 669 printk("%02x ", (unsigned char)(tbuf)[j]);
628 printk("\n"); 670 printk("\n");
629 } 671 }
630 usb_unlock_device(dev); 672 usb_unlock_device(dev);
@@ -649,7 +691,7 @@ static int proc_bulk(struct dev_state *ps, void __user *arg)
649 unsigned int tmo, len1, pipe; 691 unsigned int tmo, len1, pipe;
650 int len2; 692 int len2;
651 unsigned char *tbuf; 693 unsigned char *tbuf;
652 int i, ret; 694 int i, j, ret;
653 695
654 if (copy_from_user(&bulk, arg, sizeof(bulk))) 696 if (copy_from_user(&bulk, arg, sizeof(bulk)))
655 return -EFAULT; 697 return -EFAULT;
@@ -674,10 +716,18 @@ static int proc_bulk(struct dev_state *ps, void __user *arg)
674 kfree(tbuf); 716 kfree(tbuf);
675 return -EINVAL; 717 return -EINVAL;
676 } 718 }
719 snoop(&dev->dev, "bulk read: len=0x%02x timeout=%04d\n",
720 bulk.len, bulk.timeout);
677 usb_unlock_device(dev); 721 usb_unlock_device(dev);
678 i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo); 722 i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo);
679 usb_lock_device(dev); 723 usb_lock_device(dev);
680 if (!i && len2) { 724 if (!i && len2) {
725 if (usbfs_snoop) {
726 dev_info(&dev->dev, "bulk read: data ");
727 for (j = 0; j < len2; ++j)
728 printk("%02x ", (unsigned char)(tbuf)[j]);
729 printk("\n");
730 }
681 if (copy_to_user(bulk.data, tbuf, len2)) { 731 if (copy_to_user(bulk.data, tbuf, len2)) {
682 kfree(tbuf); 732 kfree(tbuf);
683 return -EFAULT; 733 return -EFAULT;
@@ -690,6 +740,14 @@ static int proc_bulk(struct dev_state *ps, void __user *arg)
690 return -EFAULT; 740 return -EFAULT;
691 } 741 }
692 } 742 }
743 snoop(&dev->dev, "bulk write: len=0x%02x timeout=%04d\n",
744 bulk.len, bulk.timeout);
745 if (usbfs_snoop) {
746 dev_info(&dev->dev, "bulk write: data: ");
747 for (j = 0; j < len1; ++j)
748 printk("%02x ", (unsigned char)(tbuf)[j]);
749 printk("\n");
750 }
693 usb_unlock_device(dev); 751 usb_unlock_device(dev);
694 i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo); 752 i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo);
695 usb_lock_device(dev); 753 usb_lock_device(dev);
@@ -835,7 +893,6 @@ static int proc_setconfig(struct dev_state *ps, void __user *arg)
835 return status; 893 return status;
836} 894}
837 895
838
839static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, 896static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
840 struct usbdevfs_iso_packet_desc __user *iso_frame_desc, 897 struct usbdevfs_iso_packet_desc __user *iso_frame_desc,
841 void __user *arg) 898 void __user *arg)
@@ -896,6 +953,7 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
896 kfree(dr); 953 kfree(dr);
897 return -EFAULT; 954 return -EFAULT;
898 } 955 }
956 snoop(&ps->dev->dev, "control urb\n");
899 break; 957 break;
900 958
901 case USBDEVFS_URB_TYPE_BULK: 959 case USBDEVFS_URB_TYPE_BULK:
@@ -910,6 +968,7 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
910 return -EINVAL; 968 return -EINVAL;
911 if (!access_ok((uurb->endpoint & USB_DIR_IN) ? VERIFY_WRITE : VERIFY_READ, uurb->buffer, uurb->buffer_length)) 969 if (!access_ok((uurb->endpoint & USB_DIR_IN) ? VERIFY_WRITE : VERIFY_READ, uurb->buffer, uurb->buffer_length))
912 return -EFAULT; 970 return -EFAULT;
971 snoop(&ps->dev->dev, "bulk urb\n");
913 break; 972 break;
914 973
915 case USBDEVFS_URB_TYPE_ISO: 974 case USBDEVFS_URB_TYPE_ISO:
@@ -939,6 +998,7 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
939 return -EINVAL; 998 return -EINVAL;
940 } 999 }
941 uurb->buffer_length = totlen; 1000 uurb->buffer_length = totlen;
1001 snoop(&ps->dev->dev, "iso urb\n");
942 break; 1002 break;
943 1003
944 case USBDEVFS_URB_TYPE_INTERRUPT: 1004 case USBDEVFS_URB_TYPE_INTERRUPT:
@@ -954,6 +1014,7 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
954 return -EINVAL; 1014 return -EINVAL;
955 if (!access_ok((uurb->endpoint & USB_DIR_IN) ? VERIFY_WRITE : VERIFY_READ, uurb->buffer, uurb->buffer_length)) 1015 if (!access_ok((uurb->endpoint & USB_DIR_IN) ? VERIFY_WRITE : VERIFY_READ, uurb->buffer, uurb->buffer_length))
956 return -EFAULT; 1016 return -EFAULT;
1017 snoop(&ps->dev->dev, "interrupt urb\n");
957 break; 1018 break;
958 1019
959 default: 1020 default:
@@ -1003,6 +1064,8 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1003 return -EFAULT; 1064 return -EFAULT;
1004 } 1065 }
1005 } 1066 }
1067 snoop(&as->urb->dev->dev, "submit urb\n");
1068 snoop_urb(as->urb, as->userurb);
1006 async_newpending(as); 1069 async_newpending(as);
1007 if ((ret = usb_submit_urb(as->urb, GFP_KERNEL))) { 1070 if ((ret = usb_submit_urb(as->urb, GFP_KERNEL))) {
1008 dev_printk(KERN_DEBUG, &ps->dev->dev, "usbfs: usb_submit_urb returned %d\n", ret); 1071 dev_printk(KERN_DEBUG, &ps->dev->dev, "usbfs: usb_submit_urb returned %d\n", ret);
@@ -1238,23 +1301,20 @@ static int proc_releaseinterface(struct dev_state *ps, void __user *arg)
1238 return 0; 1301 return 0;
1239} 1302}
1240 1303
1241static int proc_ioctl (struct dev_state *ps, void __user *arg) 1304static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
1242{ 1305{
1243 struct usbdevfs_ioctl ctrl;
1244 int size; 1306 int size;
1245 void *buf = NULL; 1307 void *buf = NULL;
1246 int retval = 0; 1308 int retval = 0;
1247 struct usb_interface *intf = NULL; 1309 struct usb_interface *intf = NULL;
1248 struct usb_driver *driver = NULL; 1310 struct usb_driver *driver = NULL;
1249 1311
1250 /* get input parameters and alloc buffer */ 1312 /* alloc buffer */
1251 if (copy_from_user(&ctrl, arg, sizeof (ctrl))) 1313 if ((size = _IOC_SIZE (ctl->ioctl_code)) > 0) {
1252 return -EFAULT;
1253 if ((size = _IOC_SIZE (ctrl.ioctl_code)) > 0) {
1254 if ((buf = kmalloc (size, GFP_KERNEL)) == NULL) 1314 if ((buf = kmalloc (size, GFP_KERNEL)) == NULL)
1255 return -ENOMEM; 1315 return -ENOMEM;
1256 if ((_IOC_DIR(ctrl.ioctl_code) & _IOC_WRITE)) { 1316 if ((_IOC_DIR(ctl->ioctl_code) & _IOC_WRITE)) {
1257 if (copy_from_user (buf, ctrl.data, size)) { 1317 if (copy_from_user (buf, ctl->data, size)) {
1258 kfree(buf); 1318 kfree(buf);
1259 return -EFAULT; 1319 return -EFAULT;
1260 } 1320 }
@@ -1270,9 +1330,9 @@ static int proc_ioctl (struct dev_state *ps, void __user *arg)
1270 1330
1271 if (ps->dev->state != USB_STATE_CONFIGURED) 1331 if (ps->dev->state != USB_STATE_CONFIGURED)
1272 retval = -EHOSTUNREACH; 1332 retval = -EHOSTUNREACH;
1273 else if (!(intf = usb_ifnum_to_if (ps->dev, ctrl.ifno))) 1333 else if (!(intf = usb_ifnum_to_if (ps->dev, ctl->ifno)))
1274 retval = -EINVAL; 1334 retval = -EINVAL;
1275 else switch (ctrl.ioctl_code) { 1335 else switch (ctl->ioctl_code) {
1276 1336
1277 /* disconnect kernel driver from interface */ 1337 /* disconnect kernel driver from interface */
1278 case USBDEVFS_DISCONNECT: 1338 case USBDEVFS_DISCONNECT:
@@ -1304,7 +1364,7 @@ static int proc_ioctl (struct dev_state *ps, void __user *arg)
1304 if (driver == NULL || driver->ioctl == NULL) { 1364 if (driver == NULL || driver->ioctl == NULL) {
1305 retval = -ENOTTY; 1365 retval = -ENOTTY;
1306 } else { 1366 } else {
1307 retval = driver->ioctl (intf, ctrl.ioctl_code, buf); 1367 retval = driver->ioctl (intf, ctl->ioctl_code, buf);
1308 if (retval == -ENOIOCTLCMD) 1368 if (retval == -ENOIOCTLCMD)
1309 retval = -ENOTTY; 1369 retval = -ENOTTY;
1310 } 1370 }
@@ -1313,15 +1373,42 @@ static int proc_ioctl (struct dev_state *ps, void __user *arg)
1313 1373
1314 /* cleanup and return */ 1374 /* cleanup and return */
1315 if (retval >= 0 1375 if (retval >= 0
1316 && (_IOC_DIR (ctrl.ioctl_code) & _IOC_READ) != 0 1376 && (_IOC_DIR (ctl->ioctl_code) & _IOC_READ) != 0
1317 && size > 0 1377 && size > 0
1318 && copy_to_user (ctrl.data, buf, size) != 0) 1378 && copy_to_user (ctl->data, buf, size) != 0)
1319 retval = -EFAULT; 1379 retval = -EFAULT;
1320 1380
1321 kfree(buf); 1381 kfree(buf);
1322 return retval; 1382 return retval;
1323} 1383}
1324 1384
1385static int proc_ioctl_default(struct dev_state *ps, void __user *arg)
1386{
1387 struct usbdevfs_ioctl ctrl;
1388
1389 if (copy_from_user(&ctrl, arg, sizeof (ctrl)))
1390 return -EFAULT;
1391 return proc_ioctl(ps, &ctrl);
1392}
1393
1394#ifdef CONFIG_COMPAT
1395static int proc_ioctl_compat(struct dev_state *ps, void __user *arg)
1396{
1397 struct usbdevfs_ioctl32 __user *uioc;
1398 struct usbdevfs_ioctl ctrl;
1399 u32 udata;
1400
1401 uioc = compat_ptr(arg);
1402 if (get_user(ctrl.ifno, &uioc->ifno) ||
1403 get_user(ctrl.ioctl_code, &uioc->ioctl_code) ||
1404 __get_user(udata, &uioc->data))
1405 return -EFAULT;
1406 ctrl.data = compat_ptr(udata);
1407
1408 return proc_ioctl(ps, &ctrl);
1409}
1410#endif
1411
1325/* 1412/*
1326 * NOTE: All requests here that have interface numbers as parameters 1413 * NOTE: All requests here that have interface numbers as parameters
1327 * are assuming that somehow the configuration has been prevented from 1414 * are assuming that somehow the configuration has been prevented from
@@ -1422,6 +1509,10 @@ static int usbdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
1422 ret = proc_reapurbnonblock_compat(ps, p); 1509 ret = proc_reapurbnonblock_compat(ps, p);
1423 break; 1510 break;
1424 1511
1512 case USBDEVFS_IOCTL32:
1513 snoop(&dev->dev, "%s: IOCTL\n", __FUNCTION__);
1514 ret = proc_ioctl_compat(ps, p);
1515 break;
1425#endif 1516#endif
1426 1517
1427 case USBDEVFS_DISCARDURB: 1518 case USBDEVFS_DISCARDURB:
@@ -1456,7 +1547,7 @@ static int usbdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
1456 1547
1457 case USBDEVFS_IOCTL: 1548 case USBDEVFS_IOCTL:
1458 snoop(&dev->dev, "%s: IOCTL\n", __FUNCTION__); 1549 snoop(&dev->dev, "%s: IOCTL\n", __FUNCTION__);
1459 ret = proc_ioctl(ps, p); 1550 ret = proc_ioctl_default(ps, p);
1460 break; 1551 break;
1461 } 1552 }
1462 usb_unlock_device(dev); 1553 usb_unlock_device(dev);
@@ -1488,39 +1579,40 @@ struct file_operations usbfs_device_file_operations = {
1488 .release = usbdev_release, 1579 .release = usbdev_release,
1489}; 1580};
1490 1581
1491struct usb_device *usbdev_lookup_minor(int minor) 1582static void usbdev_add(struct usb_device *dev)
1492{
1493 struct class_device *class_dev;
1494 struct usb_device *dev = NULL;
1495
1496 down(&usb_device_class->sem);
1497 list_for_each_entry(class_dev, &usb_device_class->children, node) {
1498 if (class_dev->devt == MKDEV(USB_DEVICE_MAJOR, minor)) {
1499 dev = class_dev->class_data;
1500 break;
1501 }
1502 }
1503 up(&usb_device_class->sem);
1504
1505 return dev;
1506};
1507
1508void usbdev_add(struct usb_device *dev)
1509{ 1583{
1510 int minor = ((dev->bus->busnum-1) * 128) + (dev->devnum-1); 1584 int minor = ((dev->bus->busnum-1) * 128) + (dev->devnum-1);
1511 1585
1512 dev->class_dev = class_device_create(usb_device_class, 1586 dev->class_dev = class_device_create(usb_device_class, NULL,
1513 MKDEV(USB_DEVICE_MAJOR, minor), &dev->dev, 1587 MKDEV(USB_DEVICE_MAJOR, minor), &dev->dev,
1514 "usbdev%d.%d", dev->bus->busnum, dev->devnum); 1588 "usbdev%d.%d", dev->bus->busnum, dev->devnum);
1515 1589
1516 dev->class_dev->class_data = dev; 1590 dev->class_dev->class_data = dev;
1517} 1591}
1518 1592
1519void usbdev_remove(struct usb_device *dev) 1593static void usbdev_remove(struct usb_device *dev)
1520{ 1594{
1521 class_device_unregister(dev->class_dev); 1595 class_device_unregister(dev->class_dev);
1522} 1596}
1523 1597
1598static int usbdev_notify(struct notifier_block *self, unsigned long action,
1599 void *dev)
1600{
1601 switch (action) {
1602 case USB_DEVICE_ADD:
1603 usbdev_add(dev);
1604 break;
1605 case USB_DEVICE_REMOVE:
1606 usbdev_remove(dev);
1607 break;
1608 }
1609 return NOTIFY_OK;
1610}
1611
1612static struct notifier_block usbdev_nb = {
1613 .notifier_call = usbdev_notify,
1614};
1615
1524static struct cdev usb_device_cdev = { 1616static struct cdev usb_device_cdev = {
1525 .kobj = {.name = "usb_device", }, 1617 .kobj = {.name = "usb_device", },
1526 .owner = THIS_MODULE, 1618 .owner = THIS_MODULE,
@@ -1540,24 +1632,32 @@ int __init usbdev_init(void)
1540 retval = cdev_add(&usb_device_cdev, USB_DEVICE_DEV, USB_DEVICE_MAX); 1632 retval = cdev_add(&usb_device_cdev, USB_DEVICE_DEV, USB_DEVICE_MAX);
1541 if (retval) { 1633 if (retval) {
1542 err("unable to get usb_device major %d", USB_DEVICE_MAJOR); 1634 err("unable to get usb_device major %d", USB_DEVICE_MAJOR);
1543 unregister_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX); 1635 goto error_cdev;
1544 goto out;
1545 } 1636 }
1546 usb_device_class = class_create(THIS_MODULE, "usb_device"); 1637 usb_device_class = class_create(THIS_MODULE, "usb_device");
1547 if (IS_ERR(usb_device_class)) { 1638 if (IS_ERR(usb_device_class)) {
1548 err("unable to register usb_device class"); 1639 err("unable to register usb_device class");
1549 retval = PTR_ERR(usb_device_class); 1640 retval = PTR_ERR(usb_device_class);
1550 usb_device_class = NULL; 1641 goto error_class;
1551 cdev_del(&usb_device_cdev);
1552 unregister_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX);
1553 } 1642 }
1554 1643
1644 usb_register_notify(&usbdev_nb);
1645
1555out: 1646out:
1556 return retval; 1647 return retval;
1648
1649error_class:
1650 usb_device_class = NULL;
1651 cdev_del(&usb_device_cdev);
1652
1653error_cdev:
1654 unregister_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX);
1655 goto out;
1557} 1656}
1558 1657
1559void usbdev_cleanup(void) 1658void usbdev_cleanup(void)
1560{ 1659{
1660 usb_unregister_notify(&usbdev_nb);
1561 class_destroy(usb_device_class); 1661 class_destroy(usb_device_class);
1562 cdev_del(&usb_device_cdev); 1662 cdev_del(&usb_device_cdev);
1563 unregister_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX); 1663 unregister_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX);
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
index 65ca131cc44c..e695308095ae 100644
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -17,7 +17,6 @@
17 17
18#include <linux/config.h> 18#include <linux/config.h>
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/devfs_fs_kernel.h>
21#include <linux/spinlock.h> 20#include <linux/spinlock.h>
22#include <linux/errno.h> 21#include <linux/errno.h>
23 22
@@ -88,8 +87,6 @@ int usb_major_init(void)
88 goto out; 87 goto out;
89 } 88 }
90 89
91 devfs_mk_dir("usb");
92
93out: 90out:
94 return error; 91 return error;
95} 92}
@@ -97,7 +94,6 @@ out:
97void usb_major_cleanup(void) 94void usb_major_cleanup(void)
98{ 95{
99 class_destroy(usb_class); 96 class_destroy(usb_class);
100 devfs_remove("usb");
101 unregister_chrdev(USB_MAJOR, "usb"); 97 unregister_chrdev(USB_MAJOR, "usb");
102} 98}
103 99
@@ -112,8 +108,7 @@ void usb_major_cleanup(void)
112 * enabled, the minor number will be based on the next available free minor, 108 * enabled, the minor number will be based on the next available free minor,
113 * starting at the class_driver->minor_base. 109 * starting at the class_driver->minor_base.
114 * 110 *
115 * This function also creates the devfs file for the usb device, if devfs 111 * This function also creates a usb class device in the sysfs tree.
116 * is enabled, and creates a usb class device in the sysfs tree.
117 * 112 *
118 * usb_deregister_dev() must be called when the driver is done with 113 * usb_deregister_dev() must be called when the driver is done with
119 * the minor numbers given out by this function. 114 * the minor numbers given out by this function.
@@ -162,22 +157,20 @@ int usb_register_dev(struct usb_interface *intf,
162 157
163 intf->minor = minor; 158 intf->minor = minor;
164 159
165 /* handle the devfs registration */
166 snprintf(name, BUS_ID_SIZE, class_driver->name, minor - minor_base);
167 devfs_mk_cdev(MKDEV(USB_MAJOR, minor), class_driver->mode, name);
168
169 /* create a usb class device for this usb interface */ 160 /* create a usb class device for this usb interface */
161 snprintf(name, BUS_ID_SIZE, class_driver->name, minor - minor_base);
170 temp = strrchr(name, '/'); 162 temp = strrchr(name, '/');
171 if (temp && (temp[1] != 0x00)) 163 if (temp && (temp[1] != 0x00))
172 ++temp; 164 ++temp;
173 else 165 else
174 temp = name; 166 temp = name;
175 intf->class_dev = class_device_create(usb_class, MKDEV(USB_MAJOR, minor), &intf->dev, "%s", temp); 167 intf->class_dev = class_device_create(usb_class, NULL,
168 MKDEV(USB_MAJOR, minor),
169 &intf->dev, "%s", temp);
176 if (IS_ERR(intf->class_dev)) { 170 if (IS_ERR(intf->class_dev)) {
177 spin_lock (&minor_lock); 171 spin_lock (&minor_lock);
178 usb_minors[intf->minor] = NULL; 172 usb_minors[intf->minor] = NULL;
179 spin_unlock (&minor_lock); 173 spin_unlock (&minor_lock);
180 devfs_remove (name);
181 retval = PTR_ERR(intf->class_dev); 174 retval = PTR_ERR(intf->class_dev);
182 } 175 }
183exit: 176exit:
@@ -195,9 +188,8 @@ EXPORT_SYMBOL(usb_register_dev);
195 * call to usb_register_dev() (usually when the device is disconnected 188 * call to usb_register_dev() (usually when the device is disconnected
196 * from the system.) 189 * from the system.)
197 * 190 *
198 * This function also cleans up the devfs file for the usb device, if devfs 191 * This function also removes the usb class device from the sysfs tree.
199 * is enabled, and removes the usb class device from the sysfs tree. 192 *
200 *
201 * This should be called by all drivers that use the USB major number. 193 * This should be called by all drivers that use the USB major number.
202 */ 194 */
203void usb_deregister_dev(struct usb_interface *intf, 195void usb_deregister_dev(struct usb_interface *intf,
@@ -220,7 +212,6 @@ void usb_deregister_dev(struct usb_interface *intf,
220 spin_unlock (&minor_lock); 212 spin_unlock (&minor_lock);
221 213
222 snprintf(name, BUS_ID_SIZE, class_driver->name, intf->minor - minor_base); 214 snprintf(name, BUS_ID_SIZE, class_driver->name, intf->minor - minor_base);
223 devfs_remove (name);
224 class_device_destroy(usb_class, MKDEV(USB_MAJOR, intf->minor)); 215 class_device_destroy(usb_class, MKDEV(USB_MAJOR, intf->minor));
225 intf->class_dev = NULL; 216 intf->class_dev = NULL;
226 intf->minor = -1; 217 intf->minor = -1;
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index 6385d1a99b60..84d9e69329bb 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -30,6 +30,8 @@
30#include <asm/io.h> 30#include <asm/io.h>
31#include <asm/irq.h> 31#include <asm/irq.h>
32#include <linux/usb.h> 32#include <linux/usb.h>
33
34#include "usb.h"
33#include "hcd.h" 35#include "hcd.h"
34 36
35 37
@@ -197,6 +199,26 @@ int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message)
197 199
198 hcd = pci_get_drvdata(dev); 200 hcd = pci_get_drvdata(dev);
199 201
202 /* Root hub suspend should have stopped all downstream traffic,
203 * and all bus master traffic. And done so for both the interface
204 * and the stub usb_device (which we check here). But maybe it
205 * didn't; writing sysfs power/state files ignores such rules...
206 *
207 * We must ignore the FREEZE vs SUSPEND distinction here, because
208 * otherwise the swsusp will save (and restore) garbage state.
209 */
210 if (hcd->self.root_hub->dev.power.power_state.event == PM_EVENT_ON)
211 return -EBUSY;
212
213 if (hcd->driver->suspend) {
214 retval = hcd->driver->suspend(hcd, message);
215 if (retval) {
216 dev_dbg (&dev->dev, "PCI pre-suspend fail, %d\n",
217 retval);
218 goto done;
219 }
220 }
221
200 /* FIXME until the generic PM interfaces change a lot more, this 222 /* FIXME until the generic PM interfaces change a lot more, this
201 * can't use PCI D1 and D2 states. For example, the confusion 223 * can't use PCI D1 and D2 states. For example, the confusion
202 * between messages and states will need to vanish, and messages 224 * between messages and states will need to vanish, and messages
@@ -215,31 +237,13 @@ int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message)
215 */ 237 */
216 has_pci_pm = pci_find_capability(dev, PCI_CAP_ID_PM); 238 has_pci_pm = pci_find_capability(dev, PCI_CAP_ID_PM);
217 239
218 switch (hcd->state) { 240 /* Downstream ports from this root hub should already be quiesced, so
219 241 * there will be no DMA activity. Now we can shut down the upstream
220 /* entry if root hub wasn't yet suspended ... from sysfs, 242 * link (except maybe for PME# resume signaling) and enter some PCI
221 * without autosuspend, or if USB_SUSPEND isn't configured. 243 * low power state, if the hardware allows.
222 */ 244 */
223 case HC_STATE_RUNNING: 245 if (hcd->state == HC_STATE_SUSPENDED) {
224 hcd->state = HC_STATE_QUIESCING;
225 retval = hcd->driver->suspend (hcd, message);
226 if (retval) {
227 dev_dbg (hcd->self.controller,
228 "suspend fail, retval %d\n",
229 retval);
230 break;
231 }
232 hcd->state = HC_STATE_SUSPENDED;
233 /* FALLTHROUGH */
234 246
235 /* entry with CONFIG_USB_SUSPEND, or hcds that autosuspend: the
236 * controller and/or root hub will already have been suspended,
237 * but it won't be ready for a PCI resume call.
238 *
239 * FIXME only CONFIG_USB_SUSPEND guarantees hub_suspend() will
240 * have been called, otherwise root hub timers still run ...
241 */
242 case HC_STATE_SUSPENDED:
243 /* no DMA or IRQs except when HC is active */ 247 /* no DMA or IRQs except when HC is active */
244 if (dev->current_state == PCI_D0) { 248 if (dev->current_state == PCI_D0) {
245 pci_save_state (dev); 249 pci_save_state (dev);
@@ -248,7 +252,7 @@ int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message)
248 252
249 if (!has_pci_pm) { 253 if (!has_pci_pm) {
250 dev_dbg (hcd->self.controller, "--> PCI D0/legacy\n"); 254 dev_dbg (hcd->self.controller, "--> PCI D0/legacy\n");
251 break; 255 goto done;
252 } 256 }
253 257
254 /* NOTE: dev->current_state becomes nonzero only here, and 258 /* NOTE: dev->current_state becomes nonzero only here, and
@@ -259,28 +263,29 @@ int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message)
259 retval = pci_set_power_state (dev, PCI_D3hot); 263 retval = pci_set_power_state (dev, PCI_D3hot);
260 if (retval == 0) { 264 if (retval == 0) {
261 dev_dbg (hcd->self.controller, "--> PCI D3\n"); 265 dev_dbg (hcd->self.controller, "--> PCI D3\n");
262 retval = pci_enable_wake (dev, PCI_D3hot, hcd->remote_wakeup); 266
263 if (retval) 267 /* Ignore these return values. We rely on pci code to
264 break; 268 * reject requests the hardware can't implement, rather
265 retval = pci_enable_wake (dev, PCI_D3cold, hcd->remote_wakeup); 269 * than coding the same thing.
266 } else if (retval < 0) { 270 */
271 (void) pci_enable_wake (dev, PCI_D3hot, hcd->remote_wakeup);
272 (void) pci_enable_wake (dev, PCI_D3cold, hcd->remote_wakeup);
273 } else {
267 dev_dbg (&dev->dev, "PCI D3 suspend fail, %d\n", 274 dev_dbg (&dev->dev, "PCI D3 suspend fail, %d\n",
268 retval); 275 retval);
269 (void) usb_hcd_pci_resume (dev); 276 (void) usb_hcd_pci_resume (dev);
270 break;
271 } 277 }
272 break; 278
273 default: 279 } else {
274 dev_dbg (hcd->self.controller, "hcd state %d; not suspended\n", 280 dev_dbg (hcd->self.controller, "hcd state %d; not suspended\n",
275 hcd->state); 281 hcd->state);
276 WARN_ON(1); 282 WARN_ON(1);
277 retval = -EINVAL; 283 retval = -EINVAL;
278 break;
279 } 284 }
280 285
281 /* update power_state **ONLY** to make sysfs happier */ 286done:
282 if (retval == 0) 287 if (retval == 0)
283 dev->dev.power.power_state = message; 288 dev->dev.power.power_state = PMSG_SUSPEND;
284 return retval; 289 return retval;
285} 290}
286EXPORT_SYMBOL (usb_hcd_pci_suspend); 291EXPORT_SYMBOL (usb_hcd_pci_suspend);
@@ -336,20 +341,9 @@ int usb_hcd_pci_resume (struct pci_dev *dev)
336 dev->current_state); 341 dev->current_state);
337 } 342 }
338#endif 343#endif
339 retval = pci_enable_wake (dev, dev->current_state, 0); 344 /* yes, ignore these results too... */
340 if (retval) { 345 (void) pci_enable_wake (dev, dev->current_state, 0);
341 dev_err(hcd->self.controller, 346 (void) pci_enable_wake (dev, PCI_D3cold, 0);
342 "can't enable_wake to %d, %d!\n",
343 dev->current_state, retval);
344 return retval;
345 }
346 retval = pci_enable_wake (dev, PCI_D3cold, 0);
347 if (retval) {
348 dev_err(hcd->self.controller,
349 "can't enable_wake to %d, %d!\n",
350 PCI_D3cold, retval);
351 return retval;
352 }
353 } else { 347 } else {
354 /* Same basic cases: clean (powered/not), dirty */ 348 /* Same basic cases: clean (powered/not), dirty */
355 dev_dbg(hcd->self.controller, "PCI legacy resume\n"); 349 dev_dbg(hcd->self.controller, "PCI legacy resume\n");
@@ -371,17 +365,17 @@ int usb_hcd_pci_resume (struct pci_dev *dev)
371 365
372 dev->dev.power.power_state = PMSG_ON; 366 dev->dev.power.power_state = PMSG_ON;
373 367
374 hcd->state = HC_STATE_RESUMING;
375 hcd->saw_irq = 0; 368 hcd->saw_irq = 0;
376 369
377 retval = hcd->driver->resume (hcd); 370 if (hcd->driver->resume) {
378 if (!HC_IS_RUNNING (hcd->state)) { 371 retval = hcd->driver->resume(hcd);
379 dev_dbg (hcd->self.controller, 372 if (retval) {
380 "resume fail, retval %d\n", retval); 373 dev_err (hcd->self.controller,
381 usb_hc_died (hcd); 374 "PCI post-resume error %d!\n", retval);
375 usb_hc_died (hcd);
376 }
382 } 377 }
383 378
384 retval = pci_enable_device(dev);
385 return retval; 379 return retval;
386} 380}
387EXPORT_SYMBOL (usb_hcd_pci_resume); 381EXPORT_SYMBOL (usb_hcd_pci_resume);
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 1017a97a418b..6c7ca5b08cd6 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -130,7 +130,7 @@ static const u8 usb2_rh_dev_descriptor [18] = {
130 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */ 130 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
131 0x00, /* __u8 bDeviceSubClass; */ 131 0x00, /* __u8 bDeviceSubClass; */
132 0x01, /* __u8 bDeviceProtocol; [ usb 2.0 single TT ]*/ 132 0x01, /* __u8 bDeviceProtocol; [ usb 2.0 single TT ]*/
133 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */ 133 0x40, /* __u8 bMaxPacketSize0; 64 Bytes */
134 134
135 0x00, 0x00, /* __le16 idVendor; */ 135 0x00, 0x00, /* __le16 idVendor; */
136 0x00, 0x00, /* __le16 idProduct; */ 136 0x00, 0x00, /* __le16 idProduct; */
@@ -153,7 +153,7 @@ static const u8 usb11_rh_dev_descriptor [18] = {
153 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */ 153 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
154 0x00, /* __u8 bDeviceSubClass; */ 154 0x00, /* __u8 bDeviceSubClass; */
155 0x00, /* __u8 bDeviceProtocol; [ low/full speeds only ] */ 155 0x00, /* __u8 bDeviceProtocol; [ low/full speeds only ] */
156 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */ 156 0x40, /* __u8 bMaxPacketSize0; 64 Bytes */
157 157
158 0x00, 0x00, /* __le16 idVendor; */ 158 0x00, 0x00, /* __le16 idVendor; */
159 0x00, 0x00, /* __le16 idProduct; */ 159 0x00, 0x00, /* __le16 idProduct; */
@@ -458,22 +458,18 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
458 458
459 default: 459 default:
460 /* non-generic request */ 460 /* non-generic request */
461 if (HC_IS_SUSPENDED (hcd->state)) 461 switch (typeReq) {
462 status = -EAGAIN; 462 case GetHubStatus:
463 else { 463 case GetPortStatus:
464 switch (typeReq) { 464 len = 4;
465 case GetHubStatus: 465 break;
466 case GetPortStatus: 466 case GetHubDescriptor:
467 len = 4; 467 len = sizeof (struct usb_hub_descriptor);
468 break; 468 break;
469 case GetHubDescriptor:
470 len = sizeof (struct usb_hub_descriptor);
471 break;
472 }
473 status = hcd->driver->hub_control (hcd,
474 typeReq, wValue, wIndex,
475 tbuf, wLength);
476 } 469 }
470 status = hcd->driver->hub_control (hcd,
471 typeReq, wValue, wIndex,
472 tbuf, wLength);
477 break; 473 break;
478error: 474error:
479 /* "protocol stall" on error */ 475 /* "protocol stall" on error */
@@ -487,7 +483,7 @@ error:
487 "CTRL: TypeReq=0x%x val=0x%x " 483 "CTRL: TypeReq=0x%x val=0x%x "
488 "idx=0x%x len=%d ==> %d\n", 484 "idx=0x%x len=%d ==> %d\n",
489 typeReq, wValue, wIndex, 485 typeReq, wValue, wIndex,
490 wLength, urb->status); 486 wLength, status);
491 } 487 }
492 } 488 }
493 if (len) { 489 if (len) {
@@ -748,10 +744,9 @@ struct usb_bus *usb_alloc_bus (struct usb_operations *op)
748{ 744{
749 struct usb_bus *bus; 745 struct usb_bus *bus;
750 746
751 bus = kmalloc (sizeof *bus, GFP_KERNEL); 747 bus = kzalloc (sizeof *bus, GFP_KERNEL);
752 if (!bus) 748 if (!bus)
753 return NULL; 749 return NULL;
754 memset(bus, 0, sizeof(struct usb_bus));
755 usb_bus_init (bus); 750 usb_bus_init (bus);
756 bus->op = op; 751 bus->op = op;
757 return bus; 752 return bus;
@@ -782,7 +777,8 @@ static int usb_register_bus(struct usb_bus *bus)
782 return -E2BIG; 777 return -E2BIG;
783 } 778 }
784 779
785 bus->class_dev = class_device_create(usb_host_class, MKDEV(0,0), bus->controller, "usb_host%d", busnum); 780 bus->class_dev = class_device_create(usb_host_class, NULL, MKDEV(0,0),
781 bus->controller, "usb_host%d", busnum);
786 if (IS_ERR(bus->class_dev)) { 782 if (IS_ERR(bus->class_dev)) {
787 clear_bit(busnum, busmap.busmap); 783 clear_bit(busnum, busmap.busmap);
788 up(&usb_bus_list_lock); 784 up(&usb_bus_list_lock);
@@ -795,8 +791,7 @@ static int usb_register_bus(struct usb_bus *bus)
795 list_add (&bus->bus_list, &usb_bus_list); 791 list_add (&bus->bus_list, &usb_bus_list);
796 up (&usb_bus_list_lock); 792 up (&usb_bus_list_lock);
797 793
798 usbfs_add_bus (bus); 794 usb_notify_add_bus(bus);
799 usbmon_notify_bus_add (bus);
800 795
801 dev_info (bus->controller, "new USB bus registered, assigned bus number %d\n", bus->busnum); 796 dev_info (bus->controller, "new USB bus registered, assigned bus number %d\n", bus->busnum);
802 return 0; 797 return 0;
@@ -823,8 +818,7 @@ static void usb_deregister_bus (struct usb_bus *bus)
823 list_del (&bus->bus_list); 818 list_del (&bus->bus_list);
824 up (&usb_bus_list_lock); 819 up (&usb_bus_list_lock);
825 820
826 usbmon_notify_bus_remove (bus); 821 usb_notify_remove_bus(bus);
827 usbfs_remove_bus (bus);
828 822
829 clear_bit (bus->busnum, busmap.busmap); 823 clear_bit (bus->busnum, busmap.busmap);
830 824
@@ -1112,7 +1106,7 @@ static void urb_unlink (struct urb *urb)
1112 * expects usb_submit_urb() to have sanity checked and conditioned all 1106 * expects usb_submit_urb() to have sanity checked and conditioned all
1113 * inputs in the urb 1107 * inputs in the urb
1114 */ 1108 */
1115static int hcd_submit_urb (struct urb *urb, unsigned mem_flags) 1109static int hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
1116{ 1110{
1117 int status; 1111 int status;
1118 struct usb_hcd *hcd = urb->dev->bus->hcpriv; 1112 struct usb_hcd *hcd = urb->dev->bus->hcpriv;
@@ -1142,10 +1136,20 @@ static int hcd_submit_urb (struct urb *urb, unsigned mem_flags)
1142 else switch (hcd->state) { 1136 else switch (hcd->state) {
1143 case HC_STATE_RUNNING: 1137 case HC_STATE_RUNNING:
1144 case HC_STATE_RESUMING: 1138 case HC_STATE_RESUMING:
1139doit:
1145 usb_get_dev (urb->dev); 1140 usb_get_dev (urb->dev);
1146 list_add_tail (&urb->urb_list, &ep->urb_list); 1141 list_add_tail (&urb->urb_list, &ep->urb_list);
1147 status = 0; 1142 status = 0;
1148 break; 1143 break;
1144 case HC_STATE_SUSPENDED:
1145 /* HC upstream links (register access, wakeup signaling) can work
1146 * even when the downstream links (and DMA etc) are quiesced; let
1147 * usbcore talk to the root hub.
1148 */
1149 if (hcd->self.controller->power.power_state.event == PM_EVENT_ON
1150 && urb->dev->parent == NULL)
1151 goto doit;
1152 /* FALL THROUGH */
1149 default: 1153 default:
1150 status = -ESHUTDOWN; 1154 status = -ESHUTDOWN;
1151 break; 1155 break;
@@ -1293,12 +1297,6 @@ static int hcd_unlink_urb (struct urb *urb, int status)
1293 goto done; 1297 goto done;
1294 } 1298 }
1295 1299
1296 /* running ~= hc unlink handshake works (irq, timer, etc)
1297 * halted ~= no unlink handshake is needed
1298 * suspended, resuming == should never happen
1299 */
1300 WARN_ON (!HC_IS_RUNNING (hcd->state) && hcd->state != HC_STATE_HALT);
1301
1302 /* insist the urb is still queued */ 1300 /* insist the urb is still queued */
1303 list_for_each(tmp, &ep->urb_list) { 1301 list_for_each(tmp, &ep->urb_list) {
1304 if (tmp == &urb->urb_list) 1302 if (tmp == &urb->urb_list)
@@ -1430,28 +1428,92 @@ rescan:
1430 1428
1431/*-------------------------------------------------------------------------*/ 1429/*-------------------------------------------------------------------------*/
1432 1430
1433#ifdef CONFIG_USB_SUSPEND 1431#ifdef CONFIG_PM
1434 1432
1435static int hcd_hub_suspend (struct usb_bus *bus) 1433int hcd_bus_suspend (struct usb_bus *bus)
1436{ 1434{
1437 struct usb_hcd *hcd; 1435 struct usb_hcd *hcd;
1436 int status;
1438 1437
1439 hcd = container_of (bus, struct usb_hcd, self); 1438 hcd = container_of (bus, struct usb_hcd, self);
1440 if (hcd->driver->hub_suspend) 1439 if (!hcd->driver->bus_suspend)
1441 return hcd->driver->hub_suspend (hcd); 1440 return -ENOENT;
1442 return 0; 1441 hcd->state = HC_STATE_QUIESCING;
1442 status = hcd->driver->bus_suspend (hcd);
1443 if (status == 0)
1444 hcd->state = HC_STATE_SUSPENDED;
1445 else
1446 dev_dbg(&bus->root_hub->dev, "%s fail, err %d\n",
1447 "suspend", status);
1448 return status;
1443} 1449}
1444 1450
1445static int hcd_hub_resume (struct usb_bus *bus) 1451int hcd_bus_resume (struct usb_bus *bus)
1446{ 1452{
1447 struct usb_hcd *hcd; 1453 struct usb_hcd *hcd;
1454 int status;
1448 1455
1449 hcd = container_of (bus, struct usb_hcd, self); 1456 hcd = container_of (bus, struct usb_hcd, self);
1450 if (hcd->driver->hub_resume) 1457 if (!hcd->driver->bus_resume)
1451 return hcd->driver->hub_resume (hcd); 1458 return -ENOENT;
1452 return 0; 1459 if (hcd->state == HC_STATE_RUNNING)
1460 return 0;
1461 hcd->state = HC_STATE_RESUMING;
1462 status = hcd->driver->bus_resume (hcd);
1463 if (status == 0)
1464 hcd->state = HC_STATE_RUNNING;
1465 else {
1466 dev_dbg(&bus->root_hub->dev, "%s fail, err %d\n",
1467 "resume", status);
1468 usb_hc_died(hcd);
1469 }
1470 return status;
1453} 1471}
1454 1472
1473/*
1474 * usb_hcd_suspend_root_hub - HCD autosuspends downstream ports
1475 * @hcd: host controller for this root hub
1476 *
1477 * This call arranges that usb_hcd_resume_root_hub() is safe to call later;
1478 * that the HCD's root hub polling is deactivated; and that the root's hub
1479 * driver is suspended. HCDs may call this to autosuspend when their root
1480 * hub's downstream ports are all inactive: unpowered, disconnected,
1481 * disabled, or suspended.
1482 *
1483 * The HCD will autoresume on device connect change detection (using SRP
1484 * or a D+/D- pullup). The HCD also autoresumes on remote wakeup signaling
1485 * from any ports that are suspended (if that is enabled). In most cases,
1486 * overcurrent signaling (on powered ports) will also start autoresume.
1487 *
1488 * Always called with IRQs blocked.
1489 */
1490void usb_hcd_suspend_root_hub (struct usb_hcd *hcd)
1491{
1492 struct urb *urb;
1493
1494 spin_lock (&hcd_root_hub_lock);
1495 usb_suspend_root_hub (hcd->self.root_hub);
1496
1497 /* force status urb to complete/unlink while suspended */
1498 if (hcd->status_urb) {
1499 urb = hcd->status_urb;
1500 urb->status = -ECONNRESET;
1501 urb->hcpriv = NULL;
1502 urb->actual_length = 0;
1503
1504 del_timer (&hcd->rh_timer);
1505 hcd->poll_pending = 0;
1506 hcd->status_urb = NULL;
1507 } else
1508 urb = NULL;
1509 spin_unlock (&hcd_root_hub_lock);
1510 hcd->state = HC_STATE_SUSPENDED;
1511
1512 if (urb)
1513 usb_hcd_giveback_urb (hcd, urb, NULL);
1514}
1515EXPORT_SYMBOL_GPL(usb_hcd_suspend_root_hub);
1516
1455/** 1517/**
1456 * usb_hcd_resume_root_hub - called by HCD to resume its root hub 1518 * usb_hcd_resume_root_hub - called by HCD to resume its root hub
1457 * @hcd: host controller for this root hub 1519 * @hcd: host controller for this root hub
@@ -1459,7 +1521,7 @@ static int hcd_hub_resume (struct usb_bus *bus)
1459 * The USB host controller calls this function when its root hub is 1521 * The USB host controller calls this function when its root hub is
1460 * suspended (with the remote wakeup feature enabled) and a remote 1522 * suspended (with the remote wakeup feature enabled) and a remote
1461 * wakeup request is received. It queues a request for khubd to 1523 * wakeup request is received. It queues a request for khubd to
1462 * resume the root hub. 1524 * resume the root hub (that is, manage its downstream ports again).
1463 */ 1525 */
1464void usb_hcd_resume_root_hub (struct usb_hcd *hcd) 1526void usb_hcd_resume_root_hub (struct usb_hcd *hcd)
1465{ 1527{
@@ -1470,13 +1532,9 @@ void usb_hcd_resume_root_hub (struct usb_hcd *hcd)
1470 usb_resume_root_hub (hcd->self.root_hub); 1532 usb_resume_root_hub (hcd->self.root_hub);
1471 spin_unlock_irqrestore (&hcd_root_hub_lock, flags); 1533 spin_unlock_irqrestore (&hcd_root_hub_lock, flags);
1472} 1534}
1535EXPORT_SYMBOL_GPL(usb_hcd_resume_root_hub);
1473 1536
1474#else
1475void usb_hcd_resume_root_hub (struct usb_hcd *hcd)
1476{
1477}
1478#endif 1537#endif
1479EXPORT_SYMBOL_GPL(usb_hcd_resume_root_hub);
1480 1538
1481/*-------------------------------------------------------------------------*/ 1539/*-------------------------------------------------------------------------*/
1482 1540
@@ -1529,10 +1587,6 @@ static struct usb_operations usb_hcd_operations = {
1529 .buffer_alloc = hcd_buffer_alloc, 1587 .buffer_alloc = hcd_buffer_alloc,
1530 .buffer_free = hcd_buffer_free, 1588 .buffer_free = hcd_buffer_free,
1531 .disable = hcd_endpoint_disable, 1589 .disable = hcd_endpoint_disable,
1532#ifdef CONFIG_USB_SUSPEND
1533 .hub_suspend = hcd_hub_suspend,
1534 .hub_resume = hcd_hub_resume,
1535#endif
1536}; 1590};
1537 1591
1538/*-------------------------------------------------------------------------*/ 1592/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
index ac451fa7e4d2..24a62a2ff86d 100644
--- a/drivers/usb/core/hcd.h
+++ b/drivers/usb/core/hcd.h
@@ -142,22 +142,18 @@ struct hcd_timeout { /* timeouts we allocate */
142 142
143struct usb_operations { 143struct usb_operations {
144 int (*get_frame_number) (struct usb_device *usb_dev); 144 int (*get_frame_number) (struct usb_device *usb_dev);
145 int (*submit_urb) (struct urb *urb, unsigned mem_flags); 145 int (*submit_urb) (struct urb *urb, gfp_t mem_flags);
146 int (*unlink_urb) (struct urb *urb, int status); 146 int (*unlink_urb) (struct urb *urb, int status);
147 147
148 /* allocate dma-consistent buffer for URB_DMA_NOMAPPING */ 148 /* allocate dma-consistent buffer for URB_DMA_NOMAPPING */
149 void *(*buffer_alloc)(struct usb_bus *bus, size_t size, 149 void *(*buffer_alloc)(struct usb_bus *bus, size_t size,
150 unsigned mem_flags, 150 gfp_t mem_flags,
151 dma_addr_t *dma); 151 dma_addr_t *dma);
152 void (*buffer_free)(struct usb_bus *bus, size_t size, 152 void (*buffer_free)(struct usb_bus *bus, size_t size,
153 void *addr, dma_addr_t dma); 153 void *addr, dma_addr_t dma);
154 154
155 void (*disable)(struct usb_device *udev, 155 void (*disable)(struct usb_device *udev,
156 struct usb_host_endpoint *ep); 156 struct usb_host_endpoint *ep);
157
158 /* global suspend/resume of bus */
159 int (*hub_suspend)(struct usb_bus *);
160 int (*hub_resume)(struct usb_bus *);
161}; 157};
162 158
163/* each driver provides one of these, and hardware init support */ 159/* each driver provides one of these, and hardware init support */
@@ -182,12 +178,12 @@ struct hc_driver {
182 int (*start) (struct usb_hcd *hcd); 178 int (*start) (struct usb_hcd *hcd);
183 179
184 /* NOTE: these suspend/resume calls relate to the HC as 180 /* NOTE: these suspend/resume calls relate to the HC as
185 * a whole, not just the root hub; they're for bus glue. 181 * a whole, not just the root hub; they're for PCI bus glue.
186 */ 182 */
187 /* called after all devices were suspended */ 183 /* called after suspending the hub, before entering D3 etc */
188 int (*suspend) (struct usb_hcd *hcd, pm_message_t message); 184 int (*suspend) (struct usb_hcd *hcd, pm_message_t message);
189 185
190 /* called before any devices get resumed */ 186 /* called after entering D0 (etc), before resuming the hub */
191 int (*resume) (struct usb_hcd *hcd); 187 int (*resume) (struct usb_hcd *hcd);
192 188
193 /* cleanly make HCD stop writing memory and doing I/O */ 189 /* cleanly make HCD stop writing memory and doing I/O */
@@ -200,7 +196,7 @@ struct hc_driver {
200 int (*urb_enqueue) (struct usb_hcd *hcd, 196 int (*urb_enqueue) (struct usb_hcd *hcd,
201 struct usb_host_endpoint *ep, 197 struct usb_host_endpoint *ep,
202 struct urb *urb, 198 struct urb *urb,
203 unsigned mem_flags); 199 gfp_t mem_flags);
204 int (*urb_dequeue) (struct usb_hcd *hcd, struct urb *urb); 200 int (*urb_dequeue) (struct usb_hcd *hcd, struct urb *urb);
205 201
206 /* hw synch, freeing endpoint resources that urb_dequeue can't */ 202 /* hw synch, freeing endpoint resources that urb_dequeue can't */
@@ -212,8 +208,8 @@ struct hc_driver {
212 int (*hub_control) (struct usb_hcd *hcd, 208 int (*hub_control) (struct usb_hcd *hcd,
213 u16 typeReq, u16 wValue, u16 wIndex, 209 u16 typeReq, u16 wValue, u16 wIndex,
214 char *buf, u16 wLength); 210 char *buf, u16 wLength);
215 int (*hub_suspend)(struct usb_hcd *); 211 int (*bus_suspend)(struct usb_hcd *);
216 int (*hub_resume)(struct usb_hcd *); 212 int (*bus_resume)(struct usb_hcd *);
217 int (*start_port_reset)(struct usb_hcd *, unsigned port_num); 213 int (*start_port_reset)(struct usb_hcd *, unsigned port_num);
218 void (*hub_irq_enable)(struct usb_hcd *); 214 void (*hub_irq_enable)(struct usb_hcd *);
219 /* Needed only if port-change IRQs are level-triggered */ 215 /* Needed only if port-change IRQs are level-triggered */
@@ -247,7 +243,7 @@ int hcd_buffer_create (struct usb_hcd *hcd);
247void hcd_buffer_destroy (struct usb_hcd *hcd); 243void hcd_buffer_destroy (struct usb_hcd *hcd);
248 244
249void *hcd_buffer_alloc (struct usb_bus *bus, size_t size, 245void *hcd_buffer_alloc (struct usb_bus *bus, size_t size,
250 unsigned mem_flags, dma_addr_t *dma); 246 gfp_t mem_flags, dma_addr_t *dma);
251void hcd_buffer_free (struct usb_bus *bus, size_t size, 247void hcd_buffer_free (struct usb_bus *bus, size_t size,
252 void *addr, dma_addr_t dma); 248 void *addr, dma_addr_t dma);
253 249
@@ -355,8 +351,6 @@ extern long usb_calc_bus_time (int speed, int is_input,
355 351
356extern struct usb_bus *usb_alloc_bus (struct usb_operations *); 352extern struct usb_bus *usb_alloc_bus (struct usb_operations *);
357 353
358extern void usb_hcd_resume_root_hub (struct usb_hcd *hcd);
359
360extern void usb_set_device_state(struct usb_device *udev, 354extern void usb_set_device_state(struct usb_device *udev,
361 enum usb_device_state new_state); 355 enum usb_device_state new_state);
362 356
@@ -378,6 +372,33 @@ extern int usb_find_interface_driver (struct usb_device *dev,
378 372
379#define usb_endpoint_out(ep_dir) (!((ep_dir) & USB_DIR_IN)) 373#define usb_endpoint_out(ep_dir) (!((ep_dir) & USB_DIR_IN))
380 374
375#ifdef CONFIG_PM
376extern void usb_hcd_suspend_root_hub (struct usb_hcd *hcd);
377extern void usb_hcd_resume_root_hub (struct usb_hcd *hcd);
378extern int hcd_bus_suspend (struct usb_bus *bus);
379extern int hcd_bus_resume (struct usb_bus *bus);
380#else
381static inline void usb_hcd_suspend_root_hub(struct usb_hcd *hcd)
382{
383 return;
384}
385
386static inline void usb_hcd_resume_root_hub(struct usb_hcd *hcd)
387{
388 return;
389}
390
391static inline int hcd_bus_suspend(struct usb_bus *bus)
392{
393 return 0;
394}
395
396static inline int hcd_bus_resume (struct usb_bus *bus)
397{
398 return 0;
399}
400#endif /* CONFIG_PM */
401
381/* 402/*
382 * USB device fs stuff 403 * USB device fs stuff
383 */ 404 */
@@ -388,23 +409,13 @@ extern int usb_find_interface_driver (struct usb_device *dev,
388 * these are expected to be called from the USB core/hub thread 409 * these are expected to be called from the USB core/hub thread
389 * with the kernel lock held 410 * with the kernel lock held
390 */ 411 */
391extern void usbfs_add_bus(struct usb_bus *bus);
392extern void usbfs_remove_bus(struct usb_bus *bus);
393extern void usbfs_add_device(struct usb_device *dev);
394extern void usbfs_remove_device(struct usb_device *dev);
395extern void usbfs_update_special (void); 412extern void usbfs_update_special (void);
396
397extern int usbfs_init(void); 413extern int usbfs_init(void);
398extern void usbfs_cleanup(void); 414extern void usbfs_cleanup(void);
399 415
400#else /* CONFIG_USB_DEVICEFS */ 416#else /* CONFIG_USB_DEVICEFS */
401 417
402static inline void usbfs_add_bus(struct usb_bus *bus) {}
403static inline void usbfs_remove_bus(struct usb_bus *bus) {}
404static inline void usbfs_add_device(struct usb_device *dev) {}
405static inline void usbfs_remove_device(struct usb_device *dev) {}
406static inline void usbfs_update_special (void) {} 418static inline void usbfs_update_special (void) {}
407
408static inline int usbfs_init(void) { return 0; } 419static inline int usbfs_init(void) { return 0; }
409static inline void usbfs_cleanup(void) { } 420static inline void usbfs_cleanup(void) { }
410 421
@@ -419,8 +430,6 @@ struct usb_mon_operations {
419 void (*urb_submit_error)(struct usb_bus *bus, struct urb *urb, int err); 430 void (*urb_submit_error)(struct usb_bus *bus, struct urb *urb, int err);
420 void (*urb_complete)(struct usb_bus *bus, struct urb *urb); 431 void (*urb_complete)(struct usb_bus *bus, struct urb *urb);
421 /* void (*urb_unlink)(struct usb_bus *bus, struct urb *urb); */ 432 /* void (*urb_unlink)(struct usb_bus *bus, struct urb *urb); */
422 void (*bus_add)(struct usb_bus *bus);
423 void (*bus_remove)(struct usb_bus *bus);
424}; 433};
425 434
426extern struct usb_mon_operations *mon_ops; 435extern struct usb_mon_operations *mon_ops;
@@ -443,18 +452,6 @@ static inline void usbmon_urb_complete(struct usb_bus *bus, struct urb *urb)
443 if (bus->monitored) 452 if (bus->monitored)
444 (*mon_ops->urb_complete)(bus, urb); 453 (*mon_ops->urb_complete)(bus, urb);
445} 454}
446
447static inline void usbmon_notify_bus_add(struct usb_bus *bus)
448{
449 if (mon_ops)
450 (*mon_ops->bus_add)(bus);
451}
452
453static inline void usbmon_notify_bus_remove(struct usb_bus *bus)
454{
455 if (mon_ops)
456 (*mon_ops->bus_remove)(bus);
457}
458 455
459int usb_mon_register(struct usb_mon_operations *ops); 456int usb_mon_register(struct usb_mon_operations *ops);
460void usb_mon_deregister(void); 457void usb_mon_deregister(void);
@@ -465,8 +462,6 @@ static inline void usbmon_urb_submit(struct usb_bus *bus, struct urb *urb) {}
465static inline void usbmon_urb_submit_error(struct usb_bus *bus, struct urb *urb, 462static inline void usbmon_urb_submit_error(struct usb_bus *bus, struct urb *urb,
466 int error) {} 463 int error) {}
467static inline void usbmon_urb_complete(struct usb_bus *bus, struct urb *urb) {} 464static inline void usbmon_urb_complete(struct usb_bus *bus, struct urb *urb) {}
468static inline void usbmon_notify_bus_add(struct usb_bus *bus) {}
469static inline void usbmon_notify_bus_remove(struct usb_bus *bus) {}
470 465
471#endif /* CONFIG_USB_MON */ 466#endif /* CONFIG_USB_MON */
472 467
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index a12cab5314e9..256d9f698715 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -436,9 +436,10 @@ static void hub_power_on(struct usb_hub *hub)
436{ 436{
437 int port1; 437 int port1;
438 unsigned pgood_delay = hub->descriptor->bPwrOn2PwrGood * 2; 438 unsigned pgood_delay = hub->descriptor->bPwrOn2PwrGood * 2;
439 u16 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics);
439 440
440 /* if hub supports power switching, enable power on each port */ 441 /* if hub supports power switching, enable power on each port */
441 if ((hub->descriptor->wHubCharacteristics & HUB_CHAR_LPSM) < 2) { 442 if ((wHubCharacteristics & HUB_CHAR_LPSM) < 2) {
442 dev_dbg(hub->intfdev, "enabling power on all ports\n"); 443 dev_dbg(hub->intfdev, "enabling power on all ports\n");
443 for (port1 = 1; port1 <= hub->descriptor->bNbrPorts; port1++) 444 for (port1 = 1; port1 <= hub->descriptor->bNbrPorts; port1++)
444 set_port_feature(hub->hdev, port1, 445 set_port_feature(hub->hdev, port1,
@@ -449,10 +450,18 @@ static void hub_power_on(struct usb_hub *hub)
449 msleep(max(pgood_delay, (unsigned) 100)); 450 msleep(max(pgood_delay, (unsigned) 100));
450} 451}
451 452
452static void hub_quiesce(struct usb_hub *hub) 453static inline void __hub_quiesce(struct usb_hub *hub)
453{ 454{
454 /* stop khubd and related activity */ 455 /* (nonblocking) khubd and related activity won't re-trigger */
455 hub->quiescing = 1; 456 hub->quiescing = 1;
457 hub->activating = 0;
458 hub->resume_root_hub = 0;
459}
460
461static void hub_quiesce(struct usb_hub *hub)
462{
463 /* (blocking) stop khubd and related activity */
464 __hub_quiesce(hub);
456 usb_kill_urb(hub->urb); 465 usb_kill_urb(hub->urb);
457 if (hub->has_indicators) 466 if (hub->has_indicators)
458 cancel_delayed_work(&hub->leds); 467 cancel_delayed_work(&hub->leds);
@@ -466,6 +475,7 @@ static void hub_activate(struct usb_hub *hub)
466 475
467 hub->quiescing = 0; 476 hub->quiescing = 0;
468 hub->activating = 1; 477 hub->activating = 1;
478 hub->resume_root_hub = 0;
469 status = usb_submit_urb(hub->urb, GFP_NOIO); 479 status = usb_submit_urb(hub->urb, GFP_NOIO);
470 if (status < 0) 480 if (status < 0)
471 dev_err(hub->intfdev, "activate --> %d\n", status); 481 dev_err(hub->intfdev, "activate --> %d\n", status);
@@ -516,6 +526,7 @@ static int hub_configure(struct usb_hub *hub,
516 struct usb_device *hdev = hub->hdev; 526 struct usb_device *hdev = hub->hdev;
517 struct device *hub_dev = hub->intfdev; 527 struct device *hub_dev = hub->intfdev;
518 u16 hubstatus, hubchange; 528 u16 hubstatus, hubchange;
529 u16 wHubCharacteristics;
519 unsigned int pipe; 530 unsigned int pipe;
520 int maxp, ret; 531 int maxp, ret;
521 char *message; 532 char *message;
@@ -561,9 +572,9 @@ static int hub_configure(struct usb_hub *hub,
561 dev_info (hub_dev, "%d port%s detected\n", hdev->maxchild, 572 dev_info (hub_dev, "%d port%s detected\n", hdev->maxchild,
562 (hdev->maxchild == 1) ? "" : "s"); 573 (hdev->maxchild == 1) ? "" : "s");
563 574
564 le16_to_cpus(&hub->descriptor->wHubCharacteristics); 575 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics);
565 576
566 if (hub->descriptor->wHubCharacteristics & HUB_CHAR_COMPOUND) { 577 if (wHubCharacteristics & HUB_CHAR_COMPOUND) {
567 int i; 578 int i;
568 char portstr [USB_MAXCHILDREN + 1]; 579 char portstr [USB_MAXCHILDREN + 1];
569 580
@@ -576,7 +587,7 @@ static int hub_configure(struct usb_hub *hub,
576 } else 587 } else
577 dev_dbg(hub_dev, "standalone hub\n"); 588 dev_dbg(hub_dev, "standalone hub\n");
578 589
579 switch (hub->descriptor->wHubCharacteristics & HUB_CHAR_LPSM) { 590 switch (wHubCharacteristics & HUB_CHAR_LPSM) {
580 case 0x00: 591 case 0x00:
581 dev_dbg(hub_dev, "ganged power switching\n"); 592 dev_dbg(hub_dev, "ganged power switching\n");
582 break; 593 break;
@@ -589,7 +600,7 @@ static int hub_configure(struct usb_hub *hub,
589 break; 600 break;
590 } 601 }
591 602
592 switch (hub->descriptor->wHubCharacteristics & HUB_CHAR_OCPM) { 603 switch (wHubCharacteristics & HUB_CHAR_OCPM) {
593 case 0x00: 604 case 0x00:
594 dev_dbg(hub_dev, "global over-current protection\n"); 605 dev_dbg(hub_dev, "global over-current protection\n");
595 break; 606 break;
@@ -629,7 +640,7 @@ static int hub_configure(struct usb_hub *hub,
629 } 640 }
630 641
631 /* Note 8 FS bit times == (8 bits / 12000000 bps) ~= 666ns */ 642 /* Note 8 FS bit times == (8 bits / 12000000 bps) ~= 666ns */
632 switch (hub->descriptor->wHubCharacteristics & HUB_CHAR_TTTT) { 643 switch (wHubCharacteristics & HUB_CHAR_TTTT) {
633 case HUB_TTTT_8_BITS: 644 case HUB_TTTT_8_BITS:
634 if (hdev->descriptor.bDeviceProtocol != 0) { 645 if (hdev->descriptor.bDeviceProtocol != 0) {
635 hub->tt.think_time = 666; 646 hub->tt.think_time = 666;
@@ -659,7 +670,7 @@ static int hub_configure(struct usb_hub *hub,
659 } 670 }
660 671
661 /* probe() zeroes hub->indicator[] */ 672 /* probe() zeroes hub->indicator[] */
662 if (hub->descriptor->wHubCharacteristics & HUB_CHAR_PORTIND) { 673 if (wHubCharacteristics & HUB_CHAR_PORTIND) {
663 hub->has_indicators = 1; 674 hub->has_indicators = 1;
664 dev_dbg(hub_dev, "Port indicators are supported\n"); 675 dev_dbg(hub_dev, "Port indicators are supported\n");
665 } 676 }
@@ -704,7 +715,7 @@ static int hub_configure(struct usb_hub *hub,
704 (hubstatus & HUB_STATUS_LOCAL_POWER) 715 (hubstatus & HUB_STATUS_LOCAL_POWER)
705 ? "lost (inactive)" : "good"); 716 ? "lost (inactive)" : "good");
706 717
707 if ((hub->descriptor->wHubCharacteristics & HUB_CHAR_OCPM) == 0) 718 if ((wHubCharacteristics & HUB_CHAR_OCPM) == 0)
708 dev_dbg(hub_dev, "%sover-current condition exists\n", 719 dev_dbg(hub_dev, "%sover-current condition exists\n",
709 (hubstatus & HUB_STATUS_OVERCURRENT) ? "" : "no "); 720 (hubstatus & HUB_STATUS_OVERCURRENT) ? "" : "no ");
710 721
@@ -854,14 +865,12 @@ descriptor_error:
854 /* We found a hub */ 865 /* We found a hub */
855 dev_info (&intf->dev, "USB hub found\n"); 866 dev_info (&intf->dev, "USB hub found\n");
856 867
857 hub = kmalloc(sizeof(*hub), GFP_KERNEL); 868 hub = kzalloc(sizeof(*hub), GFP_KERNEL);
858 if (!hub) { 869 if (!hub) {
859 dev_dbg (&intf->dev, "couldn't kmalloc hub struct\n"); 870 dev_dbg (&intf->dev, "couldn't kmalloc hub struct\n");
860 return -ENOMEM; 871 return -ENOMEM;
861 } 872 }
862 873
863 memset(hub, 0, sizeof(*hub));
864
865 INIT_LIST_HEAD(&hub->event_list); 874 INIT_LIST_HEAD(&hub->event_list);
866 hub->intfdev = &intf->dev; 875 hub->intfdev = &intf->dev;
867 hub->hdev = hdev; 876 hub->hdev = hdev;
@@ -1020,9 +1029,15 @@ void usb_set_device_state(struct usb_device *udev,
1020 spin_lock_irqsave(&device_state_lock, flags); 1029 spin_lock_irqsave(&device_state_lock, flags);
1021 if (udev->state == USB_STATE_NOTATTACHED) 1030 if (udev->state == USB_STATE_NOTATTACHED)
1022 ; /* do nothing */ 1031 ; /* do nothing */
1023 else if (new_state != USB_STATE_NOTATTACHED) 1032 else if (new_state != USB_STATE_NOTATTACHED) {
1024 udev->state = new_state; 1033 udev->state = new_state;
1025 else 1034 if (new_state == USB_STATE_CONFIGURED)
1035 device_init_wakeup(&udev->dev,
1036 (udev->actconfig->desc.bmAttributes
1037 & USB_CONFIG_ATT_WAKEUP));
1038 else if (new_state != USB_STATE_SUSPENDED)
1039 device_init_wakeup(&udev->dev, 0);
1040 } else
1026 recursively_mark_NOTATTACHED(udev); 1041 recursively_mark_NOTATTACHED(udev);
1027 spin_unlock_irqrestore(&device_state_lock, flags); 1042 spin_unlock_irqrestore(&device_state_lock, flags);
1028} 1043}
@@ -1111,14 +1126,14 @@ void usb_disconnect(struct usb_device **pdev)
1111 */ 1126 */
1112 usb_disable_device(udev, 0); 1127 usb_disable_device(udev, 0);
1113 1128
1129 usb_notify_remove_device(udev);
1130
1114 /* Free the device number, remove the /proc/bus/usb entry and 1131 /* Free the device number, remove the /proc/bus/usb entry and
1115 * the sysfs attributes, and delete the parent's children[] 1132 * the sysfs attributes, and delete the parent's children[]
1116 * (or root_hub) pointer. 1133 * (or root_hub) pointer.
1117 */ 1134 */
1118 dev_dbg (&udev->dev, "unregistering device\n"); 1135 dev_dbg (&udev->dev, "unregistering device\n");
1119 release_address(udev); 1136 release_address(udev);
1120 usbfs_remove_device(udev);
1121 usbdev_remove(udev);
1122 usb_remove_sysfs_dev_files(udev); 1137 usb_remove_sysfs_dev_files(udev);
1123 1138
1124 /* Avoid races with recursively_mark_NOTATTACHED() */ 1139 /* Avoid races with recursively_mark_NOTATTACHED() */
@@ -1189,21 +1204,6 @@ static inline void show_string(struct usb_device *udev, char *id, char *string)
1189{} 1204{}
1190#endif 1205#endif
1191 1206
1192static void get_string(struct usb_device *udev, char **string, int index)
1193{
1194 char *buf;
1195
1196 if (!index)
1197 return;
1198 buf = kmalloc(256, GFP_KERNEL);
1199 if (!buf)
1200 return;
1201 if (usb_string(udev, index, buf, 256) > 0)
1202 *string = buf;
1203 else
1204 kfree(buf);
1205}
1206
1207 1207
1208#ifdef CONFIG_USB_OTG 1208#ifdef CONFIG_USB_OTG
1209#include "otg_whitelist.h" 1209#include "otg_whitelist.h"
@@ -1242,9 +1242,10 @@ int usb_new_device(struct usb_device *udev)
1242 } 1242 }
1243 1243
1244 /* read the standard strings and cache them if present */ 1244 /* read the standard strings and cache them if present */
1245 get_string(udev, &udev->product, udev->descriptor.iProduct); 1245 udev->product = usb_cache_string(udev, udev->descriptor.iProduct);
1246 get_string(udev, &udev->manufacturer, udev->descriptor.iManufacturer); 1246 udev->manufacturer = usb_cache_string(udev,
1247 get_string(udev, &udev->serial, udev->descriptor.iSerialNumber); 1247 udev->descriptor.iManufacturer);
1248 udev->serial = usb_cache_string(udev, udev->descriptor.iSerialNumber);
1248 1249
1249 /* Tell the world! */ 1250 /* Tell the world! */
1250 dev_dbg(&udev->dev, "new device strings: Mfr=%d, Product=%d, " 1251 dev_dbg(&udev->dev, "new device strings: Mfr=%d, Product=%d, "
@@ -1316,11 +1317,9 @@ int usb_new_device(struct usb_device *udev)
1316 * (Includes HNP test device.) 1317 * (Includes HNP test device.)
1317 */ 1318 */
1318 if (udev->bus->b_hnp_enable || udev->bus->is_b_host) { 1319 if (udev->bus->b_hnp_enable || udev->bus->is_b_host) {
1319 static int __usb_suspend_device (struct usb_device *, 1320 static int __usb_suspend_device(struct usb_device *,
1320 int port1, pm_message_t state); 1321 int port1);
1321 err = __usb_suspend_device(udev, 1322 err = __usb_suspend_device(udev, udev->bus->otg_port);
1322 udev->bus->otg_port,
1323 PMSG_SUSPEND);
1324 if (err < 0) 1323 if (err < 0)
1325 dev_dbg(&udev->dev, "HNP fail, %d\n", err); 1324 dev_dbg(&udev->dev, "HNP fail, %d\n", err);
1326 } 1325 }
@@ -1356,10 +1355,8 @@ int usb_new_device(struct usb_device *udev)
1356 } 1355 }
1357 1356
1358 /* USB device state == configured ... usable */ 1357 /* USB device state == configured ... usable */
1358 usb_notify_add_device(udev);
1359 1359
1360 /* add a /proc/bus/usb entry */
1361 usbdev_add(udev);
1362 usbfs_add_device(udev);
1363 return 0; 1360 return 0;
1364 1361
1365fail: 1362fail:
@@ -1510,7 +1507,7 @@ static void hub_port_logical_disconnect(struct usb_hub *hub, int port1)
1510 /* FIXME let caller ask to power down the port: 1507 /* FIXME let caller ask to power down the port:
1511 * - some devices won't enumerate without a VBUS power cycle 1508 * - some devices won't enumerate without a VBUS power cycle
1512 * - SRP saves power that way 1509 * - SRP saves power that way
1513 * - usb_suspend_device(dev, PMSG_SUSPEND) 1510 * - ... new call, TBD ...
1514 * That's easy if this hub can switch power per-port, and 1511 * That's easy if this hub can switch power per-port, and
1515 * khubd reactivates the port later (timer, SRP, etc). 1512 * khubd reactivates the port later (timer, SRP, etc).
1516 * Powerdown must be optional, because of reset/DFU. 1513 * Powerdown must be optional, because of reset/DFU.
@@ -1546,11 +1543,7 @@ static int hub_port_suspend(struct usb_hub *hub, int port1,
1546 * NOTE: OTG devices may issue remote wakeup (or SRP) even when 1543 * NOTE: OTG devices may issue remote wakeup (or SRP) even when
1547 * we don't explicitly enable it here. 1544 * we don't explicitly enable it here.
1548 */ 1545 */
1549 if (udev->actconfig 1546 if (device_may_wakeup(&udev->dev)) {
1550 // && FIXME (remote wakeup enabled on this bus)
1551 // ... currently assuming it's always appropriate
1552 && (udev->actconfig->desc.bmAttributes
1553 & USB_CONFIG_ATT_WAKEUP) != 0) {
1554 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 1547 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1555 USB_REQ_SET_FEATURE, USB_RECIP_DEVICE, 1548 USB_REQ_SET_FEATURE, USB_RECIP_DEVICE,
1556 USB_DEVICE_REMOTE_WAKEUP, 0, 1549 USB_DEVICE_REMOTE_WAKEUP, 0,
@@ -1596,11 +1589,14 @@ static int hub_port_suspend(struct usb_hub *hub, int port1,
1596 * Other than re-initializing the hub (plug/unplug, except for root hubs), 1589 * Other than re-initializing the hub (plug/unplug, except for root hubs),
1597 * Linux (2.6) currently has NO mechanisms to initiate that: no khubd 1590 * Linux (2.6) currently has NO mechanisms to initiate that: no khubd
1598 * timer, no SRP, no requests through sysfs. 1591 * timer, no SRP, no requests through sysfs.
1592 *
1593 * If CONFIG_USB_SUSPEND isn't enabled, devices only really suspend when
1594 * the root hub for their bus goes into global suspend ... so we don't
1595 * (falsely) update the device power state to say it suspended.
1599 */ 1596 */
1600static int __usb_suspend_device (struct usb_device *udev, int port1, 1597static int __usb_suspend_device (struct usb_device *udev, int port1)
1601 pm_message_t state)
1602{ 1598{
1603 int status; 1599 int status = 0;
1604 1600
1605 /* caller owns the udev device lock */ 1601 /* caller owns the udev device lock */
1606 if (port1 < 0) 1602 if (port1 < 0)
@@ -1611,95 +1607,39 @@ static int __usb_suspend_device (struct usb_device *udev, int port1,
1611 return 0; 1607 return 0;
1612 } 1608 }
1613 1609
1614 /* suspend interface drivers; if this is a hub, it 1610 /* all interfaces must already be suspended */
1615 * suspends the child devices
1616 */
1617 if (udev->actconfig) { 1611 if (udev->actconfig) {
1618 int i; 1612 int i;
1619 1613
1620 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { 1614 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) {
1621 struct usb_interface *intf; 1615 struct usb_interface *intf;
1622 struct usb_driver *driver;
1623 1616
1624 intf = udev->actconfig->interface[i]; 1617 intf = udev->actconfig->interface[i];
1625 if (state.event <= intf->dev.power.power_state.event) 1618 if (is_active(intf)) {
1626 continue; 1619 dev_dbg(&intf->dev, "nyet suspended\n");
1627 if (!intf->dev.driver) 1620 return -EBUSY;
1628 continue;
1629 driver = to_usb_driver(intf->dev.driver);
1630
1631 if (driver->suspend) {
1632 status = driver->suspend(intf, state);
1633 if (intf->dev.power.power_state.event != state.event
1634 || status)
1635 dev_err(&intf->dev,
1636 "suspend %d fail, code %d\n",
1637 state.event, status);
1638 }
1639
1640 /* only drivers with suspend() can ever resume();
1641 * and after power loss, even they won't.
1642 * bus_rescan_devices() can rebind drivers later.
1643 *
1644 * FIXME the PM core self-deadlocks when unbinding
1645 * drivers during suspend/resume ... everything grabs
1646 * dpm_sem (not a spinlock, ugh). we want to unbind,
1647 * since we know every driver's probe/disconnect works
1648 * even for drivers that can't suspend.
1649 */
1650 if (!driver->suspend || state.event > PM_EVENT_FREEZE) {
1651#if 1
1652 dev_warn(&intf->dev, "resume is unsafe!\n");
1653#else
1654 down_write(&usb_bus_type.rwsem);
1655 device_release_driver(&intf->dev);
1656 up_write(&usb_bus_type.rwsem);
1657#endif
1658 } 1621 }
1659 } 1622 }
1660 } 1623 }
1661 1624
1662 /* 1625 /* we only change a device's upstream USB link.
1663 * FIXME this needs port power off call paths too, to help force 1626 * root hubs have no upstream USB link.
1664 * USB into the "generic" PM model. At least for devices on
1665 * ports that aren't using ganged switching (usually root hubs).
1666 *
1667 * NOTE: SRP-capable links should adopt more aggressive poweroff
1668 * policies (when HNP doesn't apply) once we have mechanisms to
1669 * turn power back on! (Likely not before 2.7...)
1670 */ 1627 */
1671 if (state.event > PM_EVENT_FREEZE) { 1628 if (udev->parent)
1672 dev_warn(&udev->dev, "no poweroff yet, suspending instead\n");
1673 }
1674
1675 /* "global suspend" of the HC-to-USB interface (root hub), or
1676 * "selective suspend" of just one hub-device link.
1677 */
1678 if (!udev->parent) {
1679 struct usb_bus *bus = udev->bus;
1680 if (bus && bus->op->hub_suspend) {
1681 status = bus->op->hub_suspend (bus);
1682 if (status == 0) {
1683 dev_dbg(&udev->dev, "usb suspend\n");
1684 usb_set_device_state(udev,
1685 USB_STATE_SUSPENDED);
1686 }
1687 } else
1688 status = -EOPNOTSUPP;
1689 } else
1690 status = hub_port_suspend(hdev_to_hub(udev->parent), port1, 1629 status = hub_port_suspend(hdev_to_hub(udev->parent), port1,
1691 udev); 1630 udev);
1692 1631
1693 if (status == 0) 1632 if (status == 0)
1694 udev->dev.power.power_state = state; 1633 udev->dev.power.power_state = PMSG_SUSPEND;
1695 return status; 1634 return status;
1696} 1635}
1697 1636
1698/** 1637#endif
1638
1639/*
1699 * usb_suspend_device - suspend a usb device 1640 * usb_suspend_device - suspend a usb device
1700 * @udev: device that's no longer in active use 1641 * @udev: device that's no longer in active use
1701 * @state: PMSG_SUSPEND to suspend 1642 * Context: must be able to sleep; device not locked; pm locks held
1702 * Context: must be able to sleep; device not locked
1703 * 1643 *
1704 * Suspends a USB device that isn't in active use, conserving power. 1644 * Suspends a USB device that isn't in active use, conserving power.
1705 * Devices may wake out of a suspend, if anything important happens, 1645 * Devices may wake out of a suspend, if anything important happens,
@@ -1707,37 +1647,50 @@ static int __usb_suspend_device (struct usb_device *udev, int port1,
1707 * suspend by the host, using usb_resume_device(). It's also routine 1647 * suspend by the host, using usb_resume_device(). It's also routine
1708 * to disconnect devices while they are suspended. 1648 * to disconnect devices while they are suspended.
1709 * 1649 *
1650 * This only affects the USB hardware for a device; its interfaces
1651 * (and, for hubs, child devices) must already have been suspended.
1652 *
1710 * Suspending OTG devices may trigger HNP, if that's been enabled 1653 * Suspending OTG devices may trigger HNP, if that's been enabled
1711 * between a pair of dual-role devices. That will change roles, such 1654 * between a pair of dual-role devices. That will change roles, such
1712 * as from A-Host to A-Peripheral or from B-Host back to B-Peripheral. 1655 * as from A-Host to A-Peripheral or from B-Host back to B-Peripheral.
1713 * 1656 *
1714 * Returns 0 on success, else negative errno. 1657 * Returns 0 on success, else negative errno.
1715 */ 1658 */
1716int usb_suspend_device(struct usb_device *udev, pm_message_t state) 1659int usb_suspend_device(struct usb_device *udev)
1717{ 1660{
1661#ifdef CONFIG_USB_SUSPEND
1718 int port1, status; 1662 int port1, status;
1719 1663
1720 port1 = locktree(udev); 1664 port1 = locktree(udev);
1721 if (port1 < 0) 1665 if (port1 < 0)
1722 return port1; 1666 return port1;
1723 1667
1724 status = __usb_suspend_device(udev, port1, state); 1668 status = __usb_suspend_device(udev, port1);
1725 usb_unlock_device(udev); 1669 usb_unlock_device(udev);
1726 return status; 1670 return status;
1671#else
1672 /* NOTE: udev->state unchanged, it's not lying ... */
1673 udev->dev.power.power_state = PMSG_SUSPEND;
1674 return 0;
1675#endif
1727} 1676}
1677EXPORT_SYMBOL_GPL(usb_suspend_device);
1728 1678
1729/* 1679/*
1680 * If the USB "suspend" state is in use (rather than "global suspend"),
1681 * many devices will be individually taken out of suspend state using
1682 * special" resume" signaling. These routines kick in shortly after
1730 * hardware resume signaling is finished, either because of selective 1683 * hardware resume signaling is finished, either because of selective
1731 * resume (by host) or remote wakeup (by device) ... now see what changed 1684 * resume (by host) or remote wakeup (by device) ... now see what changed
1732 * in the tree that's rooted at this device. 1685 * in the tree that's rooted at this device.
1733 */ 1686 */
1734static int finish_port_resume(struct usb_device *udev) 1687static int finish_device_resume(struct usb_device *udev)
1735{ 1688{
1736 int status; 1689 int status;
1737 u16 devstatus; 1690 u16 devstatus;
1738 1691
1739 /* caller owns the udev device lock */ 1692 /* caller owns the udev device lock */
1740 dev_dbg(&udev->dev, "usb resume\n"); 1693 dev_dbg(&udev->dev, "finish resume\n");
1741 1694
1742 /* usb ch9 identifies four variants of SUSPENDED, based on what 1695 /* usb ch9 identifies four variants of SUSPENDED, based on what
1743 * state the device resumes to. Linux currently won't see the 1696 * state the device resumes to. Linux currently won't see the
@@ -1747,7 +1700,6 @@ static int finish_port_resume(struct usb_device *udev)
1747 usb_set_device_state(udev, udev->actconfig 1700 usb_set_device_state(udev, udev->actconfig
1748 ? USB_STATE_CONFIGURED 1701 ? USB_STATE_CONFIGURED
1749 : USB_STATE_ADDRESS); 1702 : USB_STATE_ADDRESS);
1750 udev->dev.power.power_state = PMSG_ON;
1751 1703
1752 /* 10.5.4.5 says be sure devices in the tree are still there. 1704 /* 10.5.4.5 says be sure devices in the tree are still there.
1753 * For now let's assume the device didn't go crazy on resume, 1705 * For now let's assume the device didn't go crazy on resume,
@@ -1760,9 +1712,11 @@ static int finish_port_resume(struct usb_device *udev)
1760 status); 1712 status);
1761 else if (udev->actconfig) { 1713 else if (udev->actconfig) {
1762 unsigned i; 1714 unsigned i;
1715 int (*resume)(struct device *);
1763 1716
1764 le16_to_cpus(&devstatus); 1717 le16_to_cpus(&devstatus);
1765 if (devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP)) { 1718 if (devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP)
1719 && udev->parent) {
1766 status = usb_control_msg(udev, 1720 status = usb_control_msg(udev,
1767 usb_sndctrlpipe(udev, 0), 1721 usb_sndctrlpipe(udev, 0),
1768 USB_REQ_CLEAR_FEATURE, 1722 USB_REQ_CLEAR_FEATURE,
@@ -1778,33 +1732,11 @@ static int finish_port_resume(struct usb_device *udev)
1778 } 1732 }
1779 1733
1780 /* resume interface drivers; if this is a hub, it 1734 /* resume interface drivers; if this is a hub, it
1781 * resumes the child devices 1735 * may have a child resume event to deal with soon
1782 */ 1736 */
1783 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { 1737 resume = udev->dev.bus->resume;
1784 struct usb_interface *intf; 1738 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++)
1785 struct usb_driver *driver; 1739 (void) resume(&udev->actconfig->interface[i]->dev);
1786
1787 intf = udev->actconfig->interface[i];
1788 if (intf->dev.power.power_state.event == PM_EVENT_ON)
1789 continue;
1790 if (!intf->dev.driver) {
1791 /* FIXME maybe force to alt 0 */
1792 continue;
1793 }
1794 driver = to_usb_driver(intf->dev.driver);
1795
1796 /* bus_rescan_devices() may rebind drivers */
1797 if (!driver->resume)
1798 continue;
1799
1800 /* can we do better than just logging errors? */
1801 status = driver->resume(intf);
1802 if (intf->dev.power.power_state.event != PM_EVENT_ON
1803 || status)
1804 dev_dbg(&intf->dev,
1805 "resume fail, state %d code %d\n",
1806 intf->dev.power.power_state.event, status);
1807 }
1808 status = 0; 1740 status = 0;
1809 1741
1810 } else if (udev->devnum <= 0) { 1742 } else if (udev->devnum <= 0) {
@@ -1814,6 +1746,8 @@ static int finish_port_resume(struct usb_device *udev)
1814 return status; 1746 return status;
1815} 1747}
1816 1748
1749#ifdef CONFIG_USB_SUSPEND
1750
1817static int 1751static int
1818hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev) 1752hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev)
1819{ 1753{
@@ -1859,7 +1793,7 @@ hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev)
1859 /* TRSMRCY = 10 msec */ 1793 /* TRSMRCY = 10 msec */
1860 msleep(10); 1794 msleep(10);
1861 if (udev) 1795 if (udev)
1862 status = finish_port_resume(udev); 1796 status = finish_device_resume(udev);
1863 } 1797 }
1864 } 1798 }
1865 if (status < 0) 1799 if (status < 0)
@@ -1868,12 +1802,12 @@ hub_port_resume(struct usb_hub *hub, int port1, struct usb_device *udev)
1868 return status; 1802 return status;
1869} 1803}
1870 1804
1871static int hub_resume (struct usb_interface *intf); 1805#endif
1872 1806
1873/** 1807/*
1874 * usb_resume_device - re-activate a suspended usb device 1808 * usb_resume_device - re-activate a suspended usb device
1875 * @udev: device to re-activate 1809 * @udev: device to re-activate
1876 * Context: must be able to sleep; device not locked 1810 * Context: must be able to sleep; device not locked; pm locks held
1877 * 1811 *
1878 * This will re-activate the suspended device, increasing power usage 1812 * This will re-activate the suspended device, increasing power usage
1879 * while letting drivers communicate again with its endpoints. 1813 * while letting drivers communicate again with its endpoints.
@@ -1891,35 +1825,22 @@ int usb_resume_device(struct usb_device *udev)
1891 if (port1 < 0) 1825 if (port1 < 0)
1892 return port1; 1826 return port1;
1893 1827
1894 /* "global resume" of the HC-to-USB interface (root hub), or 1828#ifdef CONFIG_USB_SUSPEND
1895 * selective resume of one hub-to-device port 1829 /* selective resume of one downstream hub-to-device port */
1896 */ 1830 if (udev->parent) {
1897 if (!udev->parent) { 1831 if (udev->state == USB_STATE_SUSPENDED) {
1898 struct usb_bus *bus = udev->bus; 1832 // NOTE swsusp may bork us, device state being wrong...
1899 if (bus && bus->op->hub_resume) { 1833 // NOTE this fails if parent is also suspended...
1900 status = bus->op->hub_resume (bus); 1834 status = hub_port_resume(hdev_to_hub(udev->parent),
1835 port1, udev);
1901 } else 1836 } else
1902 status = -EOPNOTSUPP; 1837 status = 0;
1903 if (status == 0) { 1838 } else
1904 dev_dbg(&udev->dev, "usb resume\n"); 1839#endif
1905 /* TRSMRCY = 10 msec */ 1840 status = finish_device_resume(udev);
1906 msleep(10); 1841 if (status < 0)
1907 usb_set_device_state (udev, USB_STATE_CONFIGURED);
1908 udev->dev.power.power_state = PMSG_ON;
1909 status = hub_resume (udev
1910 ->actconfig->interface[0]);
1911 }
1912 } else if (udev->state == USB_STATE_SUSPENDED) {
1913 // NOTE this fails if parent is also suspended...
1914 status = hub_port_resume(hdev_to_hub(udev->parent),
1915 port1, udev);
1916 } else {
1917 status = 0;
1918 }
1919 if (status < 0) {
1920 dev_dbg(&udev->dev, "can't resume, status %d\n", 1842 dev_dbg(&udev->dev, "can't resume, status %d\n",
1921 status); 1843 status);
1922 }
1923 1844
1924 usb_unlock_device(udev); 1845 usb_unlock_device(udev);
1925 1846
@@ -1936,6 +1857,8 @@ static int remote_wakeup(struct usb_device *udev)
1936{ 1857{
1937 int status = 0; 1858 int status = 0;
1938 1859
1860#ifdef CONFIG_USB_SUSPEND
1861
1939 /* don't repeat RESUME sequence if this device 1862 /* don't repeat RESUME sequence if this device
1940 * was already woken up by some other task 1863 * was already woken up by some other task
1941 */ 1864 */
@@ -1944,38 +1867,52 @@ static int remote_wakeup(struct usb_device *udev)
1944 dev_dbg(&udev->dev, "RESUME (wakeup)\n"); 1867 dev_dbg(&udev->dev, "RESUME (wakeup)\n");
1945 /* TRSMRCY = 10 msec */ 1868 /* TRSMRCY = 10 msec */
1946 msleep(10); 1869 msleep(10);
1947 status = finish_port_resume(udev); 1870 status = finish_device_resume(udev);
1948 } 1871 }
1949 up(&udev->serialize); 1872 up(&udev->serialize);
1873#endif
1950 return status; 1874 return status;
1951} 1875}
1952 1876
1953static int hub_suspend(struct usb_interface *intf, pm_message_t state) 1877static int hub_suspend(struct usb_interface *intf, pm_message_t msg)
1954{ 1878{
1955 struct usb_hub *hub = usb_get_intfdata (intf); 1879 struct usb_hub *hub = usb_get_intfdata (intf);
1956 struct usb_device *hdev = hub->hdev; 1880 struct usb_device *hdev = hub->hdev;
1957 unsigned port1; 1881 unsigned port1;
1958 int status;
1959 1882
1960 /* stop khubd and related activity */ 1883 /* fail if children aren't already suspended */
1961 hub_quiesce(hub);
1962
1963 /* then suspend every port */
1964 for (port1 = 1; port1 <= hdev->maxchild; port1++) { 1884 for (port1 = 1; port1 <= hdev->maxchild; port1++) {
1965 struct usb_device *udev; 1885 struct usb_device *udev;
1966 1886
1967 udev = hdev->children [port1-1]; 1887 udev = hdev->children [port1-1];
1968 if (!udev) 1888 if (udev && (udev->dev.power.power_state.event
1969 continue; 1889 == PM_EVENT_ON
1970 down(&udev->serialize); 1890#ifdef CONFIG_USB_SUSPEND
1971 status = __usb_suspend_device(udev, port1, state); 1891 || udev->state != USB_STATE_SUSPENDED
1972 up(&udev->serialize); 1892#endif
1973 if (status < 0) 1893 )) {
1974 dev_dbg(&intf->dev, "suspend port %d --> %d\n", 1894 dev_dbg(&intf->dev, "port %d nyet suspended\n", port1);
1975 port1, status); 1895 return -EBUSY;
1896 }
1976 } 1897 }
1977 1898
1978 intf->dev.power.power_state = state; 1899 /* "global suspend" of the downstream HC-to-USB interface */
1900 if (!hdev->parent) {
1901 struct usb_bus *bus = hdev->bus;
1902 if (bus) {
1903 int status = hcd_bus_suspend (bus);
1904
1905 if (status != 0) {
1906 dev_dbg(&hdev->dev, "'global' suspend %d\n",
1907 status);
1908 return status;
1909 }
1910 } else
1911 return -EOPNOTSUPP;
1912 }
1913
1914 /* stop khubd and related activity */
1915 hub_quiesce(hub);
1979 return 0; 1916 return 0;
1980} 1917}
1981 1918
@@ -1983,11 +1920,35 @@ static int hub_resume(struct usb_interface *intf)
1983{ 1920{
1984 struct usb_device *hdev = interface_to_usbdev(intf); 1921 struct usb_device *hdev = interface_to_usbdev(intf);
1985 struct usb_hub *hub = usb_get_intfdata (intf); 1922 struct usb_hub *hub = usb_get_intfdata (intf);
1986 unsigned port1;
1987 int status; 1923 int status;
1988 1924
1989 if (intf->dev.power.power_state.event == PM_EVENT_ON) 1925 /* "global resume" of the downstream HC-to-USB interface */
1990 return 0; 1926 if (!hdev->parent) {
1927 struct usb_bus *bus = hdev->bus;
1928 if (bus) {
1929 status = hcd_bus_resume (bus);
1930 if (status) {
1931 dev_dbg(&intf->dev, "'global' resume %d\n",
1932 status);
1933 return status;
1934 }
1935 } else
1936 return -EOPNOTSUPP;
1937 if (status == 0) {
1938 /* TRSMRCY = 10 msec */
1939 msleep(10);
1940 }
1941 }
1942
1943 hub_activate(hub);
1944
1945 /* REVISIT: this recursion probably shouldn't exist. Remove
1946 * this code sometime, after retesting with different root and
1947 * external hubs.
1948 */
1949#ifdef CONFIG_USB_SUSPEND
1950 {
1951 unsigned port1;
1991 1952
1992 for (port1 = 1; port1 <= hdev->maxchild; port1++) { 1953 for (port1 = 1; port1 <= hdev->maxchild; port1++) {
1993 struct usb_device *udev; 1954 struct usb_device *udev;
@@ -2013,7 +1974,7 @@ static int hub_resume(struct usb_interface *intf)
2013 if (portstat & USB_PORT_STAT_SUSPEND) 1974 if (portstat & USB_PORT_STAT_SUSPEND)
2014 status = hub_port_resume(hub, port1, udev); 1975 status = hub_port_resume(hub, port1, udev);
2015 else { 1976 else {
2016 status = finish_port_resume(udev); 1977 status = finish_device_resume(udev);
2017 if (status < 0) { 1978 if (status < 0) {
2018 dev_dbg(&intf->dev, "resume port %d --> %d\n", 1979 dev_dbg(&intf->dev, "resume port %d --> %d\n",
2019 port1, status); 1980 port1, status);
@@ -2022,43 +1983,31 @@ static int hub_resume(struct usb_interface *intf)
2022 } 1983 }
2023 up(&udev->serialize); 1984 up(&udev->serialize);
2024 } 1985 }
2025 intf->dev.power.power_state = PMSG_ON; 1986 }
2026 1987#endif
2027 hub->resume_root_hub = 0;
2028 hub_activate(hub);
2029 return 0; 1988 return 0;
2030} 1989}
2031 1990
2032void usb_resume_root_hub(struct usb_device *hdev) 1991void usb_suspend_root_hub(struct usb_device *hdev)
2033{ 1992{
2034 struct usb_hub *hub = hdev_to_hub(hdev); 1993 struct usb_hub *hub = hdev_to_hub(hdev);
2035 1994
2036 hub->resume_root_hub = 1; 1995 /* This also makes any led blinker stop retriggering. We're called
2037 kick_khubd(hub); 1996 * from irq, so the blinker might still be scheduled. Caller promises
1997 * that the root hub status URB will be canceled.
1998 */
1999 __hub_quiesce(hub);
2000 mark_quiesced(to_usb_interface(hub->intfdev));
2038} 2001}
2039 2002
2040#else /* !CONFIG_USB_SUSPEND */ 2003void usb_resume_root_hub(struct usb_device *hdev)
2041
2042int usb_suspend_device(struct usb_device *udev, pm_message_t state)
2043{ 2004{
2044 return 0; 2005 struct usb_hub *hub = hdev_to_hub(hdev);
2045}
2046 2006
2047int usb_resume_device(struct usb_device *udev) 2007 hub->resume_root_hub = 1;
2048{ 2008 kick_khubd(hub);
2049 return 0;
2050} 2009}
2051 2010
2052#define hub_suspend NULL
2053#define hub_resume NULL
2054#define remote_wakeup(x) 0
2055
2056#endif /* CONFIG_USB_SUSPEND */
2057
2058EXPORT_SYMBOL(usb_suspend_device);
2059EXPORT_SYMBOL(usb_resume_device);
2060
2061
2062 2011
2063/* USB 2.0 spec, 7.1.7.3 / fig 7-29: 2012/* USB 2.0 spec, 7.1.7.3 / fig 7-29:
2064 * 2013 *
@@ -2467,6 +2416,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
2467{ 2416{
2468 struct usb_device *hdev = hub->hdev; 2417 struct usb_device *hdev = hub->hdev;
2469 struct device *hub_dev = hub->intfdev; 2418 struct device *hub_dev = hub->intfdev;
2419 u16 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics);
2470 int status, i; 2420 int status, i;
2471 2421
2472 dev_dbg (hub_dev, 2422 dev_dbg (hub_dev,
@@ -2504,8 +2454,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
2504 if (!(portstatus & USB_PORT_STAT_CONNECTION)) { 2454 if (!(portstatus & USB_PORT_STAT_CONNECTION)) {
2505 2455
2506 /* maybe switch power back on (e.g. root hub was reset) */ 2456 /* maybe switch power back on (e.g. root hub was reset) */
2507 if ((hub->descriptor->wHubCharacteristics 2457 if ((wHubCharacteristics & HUB_CHAR_LPSM) < 2
2508 & HUB_CHAR_LPSM) < 2
2509 && !(portstatus & (1 << USB_PORT_FEAT_POWER))) 2458 && !(portstatus & (1 << USB_PORT_FEAT_POWER)))
2510 set_port_feature(hdev, port1, USB_PORT_FEAT_POWER); 2459 set_port_feature(hdev, port1, USB_PORT_FEAT_POWER);
2511 2460
@@ -2684,21 +2633,28 @@ static void hub_events(void)
2684 intf = to_usb_interface(hub->intfdev); 2633 intf = to_usb_interface(hub->intfdev);
2685 hub_dev = &intf->dev; 2634 hub_dev = &intf->dev;
2686 2635
2687 dev_dbg(hub_dev, "state %d ports %d chg %04x evt %04x\n", 2636 i = hub->resume_root_hub;
2637
2638 dev_dbg(hub_dev, "state %d ports %d chg %04x evt %04x%s\n",
2688 hdev->state, hub->descriptor 2639 hdev->state, hub->descriptor
2689 ? hub->descriptor->bNbrPorts 2640 ? hub->descriptor->bNbrPorts
2690 : 0, 2641 : 0,
2691 /* NOTE: expects max 15 ports... */ 2642 /* NOTE: expects max 15 ports... */
2692 (u16) hub->change_bits[0], 2643 (u16) hub->change_bits[0],
2693 (u16) hub->event_bits[0]); 2644 (u16) hub->event_bits[0],
2645 i ? ", resume root" : "");
2694 2646
2695 usb_get_intf(intf); 2647 usb_get_intf(intf);
2696 i = hub->resume_root_hub;
2697 spin_unlock_irq(&hub_event_lock); 2648 spin_unlock_irq(&hub_event_lock);
2698 2649
2699 /* Is this is a root hub wanting to be resumed? */ 2650 /* Is this is a root hub wanting to reactivate the downstream
2700 if (i) 2651 * ports? If so, be sure the interface resumes even if its
2701 usb_resume_device(hdev); 2652 * stub "device" node was never suspended.
2653 */
2654 if (i) {
2655 dpm_runtime_resume(&hdev->dev);
2656 dpm_runtime_resume(&intf->dev);
2657 }
2702 2658
2703 /* Lock the device, then check to see if we were 2659 /* Lock the device, then check to see if we were
2704 * disconnected while waiting for the lock to succeed. */ 2660 * disconnected while waiting for the lock to succeed. */
diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h
index e7fa9b5a521e..bf23f8978024 100644
--- a/drivers/usb/core/hub.h
+++ b/drivers/usb/core/hub.h
@@ -131,7 +131,7 @@ struct usb_hub_descriptor {
131 __u8 bDescLength; 131 __u8 bDescLength;
132 __u8 bDescriptorType; 132 __u8 bDescriptorType;
133 __u8 bNbrPorts; 133 __u8 bNbrPorts;
134 __u16 wHubCharacteristics; 134 __le16 wHubCharacteristics;
135 __u8 bPwrOn2PwrGood; 135 __u8 bPwrOn2PwrGood;
136 __u8 bHubContrCurrent; 136 __u8 bHubContrCurrent;
137 /* add 1 bit for hub status change; round to bytes */ 137 /* add 1 bit for hub status change; round to bytes */
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c
index d07bba01995b..12f490fdee8f 100644
--- a/drivers/usb/core/inode.c
+++ b/drivers/usb/core/inode.c
@@ -39,6 +39,7 @@
39#include <linux/usbdevice_fs.h> 39#include <linux/usbdevice_fs.h>
40#include <linux/smp_lock.h> 40#include <linux/smp_lock.h>
41#include <linux/parser.h> 41#include <linux/parser.h>
42#include <linux/notifier.h>
42#include <asm/byteorder.h> 43#include <asm/byteorder.h>
43#include "usb.h" 44#include "usb.h"
44#include "hcd.h" 45#include "hcd.h"
@@ -619,7 +620,7 @@ void usbfs_update_special (void)
619 } 620 }
620} 621}
621 622
622void usbfs_add_bus(struct usb_bus *bus) 623static void usbfs_add_bus(struct usb_bus *bus)
623{ 624{
624 struct dentry *parent; 625 struct dentry *parent;
625 char name[8]; 626 char name[8];
@@ -642,12 +643,9 @@ void usbfs_add_bus(struct usb_bus *bus)
642 err ("error creating usbfs bus entry"); 643 err ("error creating usbfs bus entry");
643 return; 644 return;
644 } 645 }
645
646 usbfs_update_special();
647 usbfs_conn_disc_event();
648} 646}
649 647
650void usbfs_remove_bus(struct usb_bus *bus) 648static void usbfs_remove_bus(struct usb_bus *bus)
651{ 649{
652 if (bus->usbfs_dentry) { 650 if (bus->usbfs_dentry) {
653 fs_remove_file (bus->usbfs_dentry); 651 fs_remove_file (bus->usbfs_dentry);
@@ -659,12 +657,9 @@ void usbfs_remove_bus(struct usb_bus *bus)
659 remove_special_files(); 657 remove_special_files();
660 num_buses = 0; 658 num_buses = 0;
661 } 659 }
662
663 usbfs_update_special();
664 usbfs_conn_disc_event();
665} 660}
666 661
667void usbfs_add_device(struct usb_device *dev) 662static void usbfs_add_device(struct usb_device *dev)
668{ 663{
669 char name[8]; 664 char name[8];
670 int i; 665 int i;
@@ -690,12 +685,9 @@ void usbfs_add_device(struct usb_device *dev)
690 } 685 }
691 if (dev->usbfs_dentry->d_inode) 686 if (dev->usbfs_dentry->d_inode)
692 dev->usbfs_dentry->d_inode->i_size = i_size; 687 dev->usbfs_dentry->d_inode->i_size = i_size;
693
694 usbfs_update_special();
695 usbfs_conn_disc_event();
696} 688}
697 689
698void usbfs_remove_device(struct usb_device *dev) 690static void usbfs_remove_device(struct usb_device *dev)
699{ 691{
700 struct dev_state *ds; 692 struct dev_state *ds;
701 struct siginfo sinfo; 693 struct siginfo sinfo;
@@ -716,10 +708,33 @@ void usbfs_remove_device(struct usb_device *dev)
716 kill_proc_info_as_uid(ds->discsignr, &sinfo, ds->disc_pid, ds->disc_uid, ds->disc_euid); 708 kill_proc_info_as_uid(ds->discsignr, &sinfo, ds->disc_pid, ds->disc_uid, ds->disc_euid);
717 } 709 }
718 } 710 }
711}
712
713static int usbfs_notify(struct notifier_block *self, unsigned long action, void *dev)
714{
715 switch (action) {
716 case USB_DEVICE_ADD:
717 usbfs_add_device(dev);
718 break;
719 case USB_DEVICE_REMOVE:
720 usbfs_remove_device(dev);
721 break;
722 case USB_BUS_ADD:
723 usbfs_add_bus(dev);
724 break;
725 case USB_BUS_REMOVE:
726 usbfs_remove_bus(dev);
727 }
728
719 usbfs_update_special(); 729 usbfs_update_special();
720 usbfs_conn_disc_event(); 730 usbfs_conn_disc_event();
731 return NOTIFY_OK;
721} 732}
722 733
734static struct notifier_block usbfs_nb = {
735 .notifier_call = usbfs_notify,
736};
737
723/* --------------------------------------------------------------------- */ 738/* --------------------------------------------------------------------- */
724 739
725static struct proc_dir_entry *usbdir = NULL; 740static struct proc_dir_entry *usbdir = NULL;
@@ -732,6 +747,8 @@ int __init usbfs_init(void)
732 if (retval) 747 if (retval)
733 return retval; 748 return retval;
734 749
750 usb_register_notify(&usbfs_nb);
751
735 /* create mount point for usbfs */ 752 /* create mount point for usbfs */
736 usbdir = proc_mkdir("usb", proc_bus); 753 usbdir = proc_mkdir("usb", proc_bus);
737 754
@@ -740,6 +757,7 @@ int __init usbfs_init(void)
740 757
741void usbfs_cleanup(void) 758void usbfs_cleanup(void)
742{ 759{
760 usb_unregister_notify(&usbfs_nb);
743 unregister_filesystem(&usb_fs_type); 761 unregister_filesystem(&usb_fs_type);
744 if (usbdir) 762 if (usbdir)
745 remove_proc_entry("usb", proc_bus); 763 remove_proc_entry("usb", proc_bus);
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index f1fb67fe22a8..644a3d4f12aa 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -187,21 +187,37 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, __u
187 * If a thread in your driver uses this call, make sure your disconnect() 187 * If a thread in your driver uses this call, make sure your disconnect()
188 * method can wait for it to complete. Since you don't have a handle on 188 * method can wait for it to complete. Since you don't have a handle on
189 * the URB used, you can't cancel the request. 189 * the URB used, you can't cancel the request.
190 *
191 * Because there is no usb_interrupt_msg() and no USBDEVFS_INTERRUPT
192 * ioctl, users are forced to abuse this routine by using it to submit
193 * URBs for interrupt endpoints. We will take the liberty of creating
194 * an interrupt URB (with the default interval) if the target is an
195 * interrupt endpoint.
190 */ 196 */
191int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe, 197int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
192 void *data, int len, int *actual_length, int timeout) 198 void *data, int len, int *actual_length, int timeout)
193{ 199{
194 struct urb *urb; 200 struct urb *urb;
201 struct usb_host_endpoint *ep;
195 202
196 if (len < 0) 203 ep = (usb_pipein(pipe) ? usb_dev->ep_in : usb_dev->ep_out)
204 [usb_pipeendpoint(pipe)];
205 if (!ep || len < 0)
197 return -EINVAL; 206 return -EINVAL;
198 207
199 urb=usb_alloc_urb(0, GFP_KERNEL); 208 urb = usb_alloc_urb(0, GFP_KERNEL);
200 if (!urb) 209 if (!urb)
201 return -ENOMEM; 210 return -ENOMEM;
202 211
203 usb_fill_bulk_urb(urb, usb_dev, pipe, data, len, 212 if ((ep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
204 usb_api_blocking_completion, NULL); 213 USB_ENDPOINT_XFER_INT) {
214 pipe = (pipe & ~(3 << 30)) | (PIPE_INTERRUPT << 30);
215 usb_fill_int_urb(urb, usb_dev, pipe, data, len,
216 usb_api_blocking_completion, NULL,
217 ep->desc.bInterval);
218 } else
219 usb_fill_bulk_urb(urb, usb_dev, pipe, data, len,
220 usb_api_blocking_completion, NULL);
205 221
206 return usb_start_wait_urb(urb, timeout, actual_length); 222 return usb_start_wait_urb(urb, timeout, actual_length);
207} 223}
@@ -321,7 +337,7 @@ int usb_sg_init (
321 struct scatterlist *sg, 337 struct scatterlist *sg,
322 int nents, 338 int nents,
323 size_t length, 339 size_t length,
324 unsigned mem_flags 340 gfp_t mem_flags
325) 341)
326{ 342{
327 int i; 343 int i;
@@ -771,6 +787,31 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
771 return err; 787 return err;
772} 788}
773 789
790/**
791 * usb_cache_string - read a string descriptor and cache it for later use
792 * @udev: the device whose string descriptor is being read
793 * @index: the descriptor index
794 *
795 * Returns a pointer to a kmalloc'ed buffer containing the descriptor string,
796 * or NULL if the index is 0 or the string could not be read.
797 */
798char *usb_cache_string(struct usb_device *udev, int index)
799{
800 char *buf;
801 char *smallbuf = NULL;
802 int len;
803
804 if (index > 0 && (buf = kmalloc(256, GFP_KERNEL)) != NULL) {
805 if ((len = usb_string(udev, index, buf, 256)) > 0) {
806 if ((smallbuf = kmalloc(++len, GFP_KERNEL)) == NULL)
807 return buf;
808 memcpy(smallbuf, buf, len);
809 }
810 kfree(buf);
811 }
812 return smallbuf;
813}
814
774/* 815/*
775 * usb_get_device_descriptor - (re)reads the device descriptor (usbcore) 816 * usb_get_device_descriptor - (re)reads the device descriptor (usbcore)
776 * @dev: the device whose device descriptor is being updated 817 * @dev: the device whose device descriptor is being updated
@@ -992,8 +1033,6 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
992 dev_dbg (&dev->dev, "unregistering interface %s\n", 1033 dev_dbg (&dev->dev, "unregistering interface %s\n",
993 interface->dev.bus_id); 1034 interface->dev.bus_id);
994 usb_remove_sysfs_intf_files(interface); 1035 usb_remove_sysfs_intf_files(interface);
995 kfree(interface->cur_altsetting->string);
996 interface->cur_altsetting->string = NULL;
997 device_del (&interface->dev); 1036 device_del (&interface->dev);
998 } 1037 }
999 1038
@@ -1133,6 +1172,8 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
1133 */ 1172 */
1134 1173
1135 /* prevent submissions using previous endpoint settings */ 1174 /* prevent submissions using previous endpoint settings */
1175 if (device_is_registered(&iface->dev))
1176 usb_remove_sysfs_intf_files(iface);
1136 usb_disable_interface(dev, iface); 1177 usb_disable_interface(dev, iface);
1137 1178
1138 iface->cur_altsetting = alt; 1179 iface->cur_altsetting = alt;
@@ -1168,6 +1209,8 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
1168 * (Likewise, EP0 never "halts" on well designed devices.) 1209 * (Likewise, EP0 never "halts" on well designed devices.)
1169 */ 1210 */
1170 usb_enable_interface(dev, iface); 1211 usb_enable_interface(dev, iface);
1212 if (device_is_registered(&iface->dev))
1213 usb_create_sysfs_intf_files(iface);
1171 1214
1172 return 0; 1215 return 0;
1173} 1216}
@@ -1217,10 +1260,8 @@ int usb_reset_configuration(struct usb_device *dev)
1217 USB_REQ_SET_CONFIGURATION, 0, 1260 USB_REQ_SET_CONFIGURATION, 0,
1218 config->desc.bConfigurationValue, 0, 1261 config->desc.bConfigurationValue, 0,
1219 NULL, 0, USB_CTRL_SET_TIMEOUT); 1262 NULL, 0, USB_CTRL_SET_TIMEOUT);
1220 if (retval < 0) { 1263 if (retval < 0)
1221 usb_set_device_state(dev, USB_STATE_ADDRESS);
1222 return retval; 1264 return retval;
1223 }
1224 1265
1225 dev->toggle[0] = dev->toggle[1] = 0; 1266 dev->toggle[0] = dev->toggle[1] = 0;
1226 1267
@@ -1229,6 +1270,8 @@ int usb_reset_configuration(struct usb_device *dev)
1229 struct usb_interface *intf = config->interface[i]; 1270 struct usb_interface *intf = config->interface[i];
1230 struct usb_host_interface *alt; 1271 struct usb_host_interface *alt;
1231 1272
1273 if (device_is_registered(&intf->dev))
1274 usb_remove_sysfs_intf_files(intf);
1232 alt = usb_altnum_to_altsetting(intf, 0); 1275 alt = usb_altnum_to_altsetting(intf, 0);
1233 1276
1234 /* No altsetting 0? We'll assume the first altsetting. 1277 /* No altsetting 0? We'll assume the first altsetting.
@@ -1241,6 +1284,8 @@ int usb_reset_configuration(struct usb_device *dev)
1241 1284
1242 intf->cur_altsetting = alt; 1285 intf->cur_altsetting = alt;
1243 usb_enable_interface(dev, intf); 1286 usb_enable_interface(dev, intf);
1287 if (device_is_registered(&intf->dev))
1288 usb_create_sysfs_intf_files(intf);
1244 } 1289 }
1245 return 0; 1290 return 0;
1246} 1291}
@@ -1328,7 +1373,7 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
1328 } 1373 }
1329 1374
1330 for (; n < nintf; ++n) { 1375 for (; n < nintf; ++n) {
1331 new_interfaces[n] = kmalloc( 1376 new_interfaces[n] = kzalloc(
1332 sizeof(struct usb_interface), 1377 sizeof(struct usb_interface),
1333 GFP_KERNEL); 1378 GFP_KERNEL);
1334 if (!new_interfaces[n]) { 1379 if (!new_interfaces[n]) {
@@ -1369,7 +1414,6 @@ free_interfaces:
1369 struct usb_host_interface *alt; 1414 struct usb_host_interface *alt;
1370 1415
1371 cp->interface[i] = intf = new_interfaces[i]; 1416 cp->interface[i] = intf = new_interfaces[i];
1372 memset(intf, 0, sizeof(*intf));
1373 intfc = cp->intf_cache[i]; 1417 intfc = cp->intf_cache[i];
1374 intf->altsetting = intfc->altsetting; 1418 intf->altsetting = intfc->altsetting;
1375 intf->num_altsetting = intfc->num_altsetting; 1419 intf->num_altsetting = intfc->num_altsetting;
@@ -1393,6 +1437,7 @@ free_interfaces:
1393 intf->dev.dma_mask = dev->dev.dma_mask; 1437 intf->dev.dma_mask = dev->dev.dma_mask;
1394 intf->dev.release = release_interface; 1438 intf->dev.release = release_interface;
1395 device_initialize (&intf->dev); 1439 device_initialize (&intf->dev);
1440 mark_quiesced(intf);
1396 sprintf (&intf->dev.bus_id[0], "%d-%s:%d.%d", 1441 sprintf (&intf->dev.bus_id[0], "%d-%s:%d.%d",
1397 dev->bus->busnum, dev->devpath, 1442 dev->bus->busnum, dev->devpath,
1398 configuration, 1443 configuration,
@@ -1400,12 +1445,9 @@ free_interfaces:
1400 } 1445 }
1401 kfree(new_interfaces); 1446 kfree(new_interfaces);
1402 1447
1403 if ((cp->desc.iConfiguration) && 1448 if (cp->string == NULL)
1404 (cp->string == NULL)) { 1449 cp->string = usb_cache_string(dev,
1405 cp->string = kmalloc(256, GFP_KERNEL); 1450 cp->desc.iConfiguration);
1406 if (cp->string)
1407 usb_string(dev, cp->desc.iConfiguration, cp->string, 256);
1408 }
1409 1451
1410 /* Now that all the interfaces are set up, register them 1452 /* Now that all the interfaces are set up, register them
1411 * to trigger binding of drivers to interfaces. probe() 1453 * to trigger binding of drivers to interfaces. probe()
@@ -1415,13 +1457,12 @@ free_interfaces:
1415 */ 1457 */
1416 for (i = 0; i < nintf; ++i) { 1458 for (i = 0; i < nintf; ++i) {
1417 struct usb_interface *intf = cp->interface[i]; 1459 struct usb_interface *intf = cp->interface[i];
1418 struct usb_interface_descriptor *desc; 1460 struct usb_host_interface *alt = intf->cur_altsetting;
1419 1461
1420 desc = &intf->altsetting [0].desc;
1421 dev_dbg (&dev->dev, 1462 dev_dbg (&dev->dev,
1422 "adding %s (config #%d, interface %d)\n", 1463 "adding %s (config #%d, interface %d)\n",
1423 intf->dev.bus_id, configuration, 1464 intf->dev.bus_id, configuration,
1424 desc->bInterfaceNumber); 1465 alt->desc.bInterfaceNumber);
1425 ret = device_add (&intf->dev); 1466 ret = device_add (&intf->dev);
1426 if (ret != 0) { 1467 if (ret != 0) {
1427 dev_err(&dev->dev, 1468 dev_err(&dev->dev,
@@ -1430,13 +1471,6 @@ free_interfaces:
1430 ret); 1471 ret);
1431 continue; 1472 continue;
1432 } 1473 }
1433 if ((intf->cur_altsetting->desc.iInterface) &&
1434 (intf->cur_altsetting->string == NULL)) {
1435 intf->cur_altsetting->string = kmalloc(256, GFP_KERNEL);
1436 if (intf->cur_altsetting->string)
1437 usb_string(dev, intf->cur_altsetting->desc.iInterface,
1438 intf->cur_altsetting->string, 256);
1439 }
1440 usb_create_sysfs_intf_files (intf); 1474 usb_create_sysfs_intf_files (intf);
1441 } 1475 }
1442 } 1476 }
diff --git a/drivers/usb/core/notify.c b/drivers/usb/core/notify.c
new file mode 100644
index 000000000000..37da059eced7
--- /dev/null
+++ b/drivers/usb/core/notify.c
@@ -0,0 +1,120 @@
1/*
2 * All the USB notify logic
3 *
4 * (C) Copyright 2005 Greg Kroah-Hartman <gregkh@suse.de>
5 *
6 * notifier functions originally based on those in kernel/sys.c
7 * but fixed up to not be so broken.
8 *
9 */
10
11
12#include <linux/config.h>
13#include <linux/kernel.h>
14#include <linux/notifier.h>
15#ifdef CONFIG_USB_DEBUG
16 #define DEBUG
17#else
18 #undef DEBUG
19#endif
20#include <linux/usb.h>
21
22#include "usb.h"
23
24
25static struct notifier_block *usb_notifier_list;
26static DECLARE_MUTEX(usb_notifier_lock);
27
28static void usb_notifier_chain_register(struct notifier_block **list,
29 struct notifier_block *n)
30{
31 down(&usb_notifier_lock);
32 while (*list) {
33 if (n->priority > (*list)->priority)
34 break;
35 list = &((*list)->next);
36 }
37 n->next = *list;
38 *list = n;
39 up(&usb_notifier_lock);
40}
41
42static void usb_notifier_chain_unregister(struct notifier_block **nl,
43 struct notifier_block *n)
44{
45 down(&usb_notifier_lock);
46 while ((*nl)!=NULL) {
47 if ((*nl)==n) {
48 *nl = n->next;
49 goto exit;
50 }
51 nl=&((*nl)->next);
52 }
53exit:
54 up(&usb_notifier_lock);
55}
56
57static int usb_notifier_call_chain(struct notifier_block **n,
58 unsigned long val, void *v)
59{
60 int ret=NOTIFY_DONE;
61 struct notifier_block *nb = *n;
62
63 down(&usb_notifier_lock);
64 while (nb) {
65 ret = nb->notifier_call(nb,val,v);
66 if (ret&NOTIFY_STOP_MASK) {
67 goto exit;
68 }
69 nb = nb->next;
70 }
71exit:
72 up(&usb_notifier_lock);
73 return ret;
74}
75
76/**
77 * usb_register_notify - register a notifier callback whenever a usb change happens
78 * @nb: pointer to the notifier block for the callback events.
79 *
80 * These changes are either USB devices or busses being added or removed.
81 */
82void usb_register_notify(struct notifier_block *nb)
83{
84 usb_notifier_chain_register(&usb_notifier_list, nb);
85}
86EXPORT_SYMBOL_GPL(usb_register_notify);
87
88/**
89 * usb_unregister_notify - unregister a notifier callback
90 * @nb: pointer to the notifier block for the callback events.
91 *
92 * usb_register_notifier() must have been previously called for this function
93 * to work properly.
94 */
95void usb_unregister_notify(struct notifier_block *nb)
96{
97 usb_notifier_chain_unregister(&usb_notifier_list, nb);
98}
99EXPORT_SYMBOL_GPL(usb_unregister_notify);
100
101
102void usb_notify_add_device(struct usb_device *udev)
103{
104 usb_notifier_call_chain(&usb_notifier_list, USB_DEVICE_ADD, udev);
105}
106
107void usb_notify_remove_device(struct usb_device *udev)
108{
109 usb_notifier_call_chain(&usb_notifier_list, USB_DEVICE_REMOVE, udev);
110}
111
112void usb_notify_add_bus(struct usb_bus *ubus)
113{
114 usb_notifier_call_chain(&usb_notifier_list, USB_BUS_ADD, ubus);
115}
116
117void usb_notify_remove_bus(struct usb_bus *ubus)
118{
119 usb_notifier_call_chain(&usb_notifier_list, USB_BUS_REMOVE, ubus);
120}
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 00297f113849..edd83e014452 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -22,9 +22,207 @@
22 22
23#include "usb.h" 23#include "usb.h"
24 24
25/* endpoint stuff */
26struct ep_object {
27 struct usb_endpoint_descriptor *desc;
28 struct usb_device *udev;
29 struct kobject kobj;
30};
31#define to_ep_object(_kobj) \
32 container_of(_kobj, struct ep_object, kobj)
33
34struct ep_attribute {
35 struct attribute attr;
36 ssize_t (*show)(struct usb_device *,
37 struct usb_endpoint_descriptor *, char *);
38};
39#define to_ep_attribute(_attr) \
40 container_of(_attr, struct ep_attribute, attr)
41
42#define EP_ATTR(_name) \
43struct ep_attribute ep_##_name = { \
44 .attr = {.name = #_name, .owner = THIS_MODULE, \
45 .mode = S_IRUGO}, \
46 .show = show_ep_##_name}
47
48#define usb_ep_attr(field, format_string) \
49static ssize_t show_ep_##field(struct usb_device *udev, \
50 struct usb_endpoint_descriptor *desc, \
51 char *buf) \
52{ \
53 return sprintf(buf, format_string, desc->field); \
54} \
55static EP_ATTR(field);
56
57usb_ep_attr(bLength, "%02x\n")
58usb_ep_attr(bEndpointAddress, "%02x\n")
59usb_ep_attr(bmAttributes, "%02x\n")
60usb_ep_attr(bInterval, "%02x\n")
61
62static ssize_t show_ep_wMaxPacketSize(struct usb_device *udev,
63 struct usb_endpoint_descriptor *desc, char *buf)
64{
65 return sprintf(buf, "%04x\n",
66 le16_to_cpu(desc->wMaxPacketSize) & 0x07ff);
67}
68static EP_ATTR(wMaxPacketSize);
69
70static ssize_t show_ep_type(struct usb_device *udev,
71 struct usb_endpoint_descriptor *desc, char *buf)
72{
73 char *type = "unknown";
74
75 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
76 case USB_ENDPOINT_XFER_CONTROL:
77 type = "Control";
78 break;
79 case USB_ENDPOINT_XFER_ISOC:
80 type = "Isoc";
81 break;
82 case USB_ENDPOINT_XFER_BULK:
83 type = "Bulk";
84 break;
85 case USB_ENDPOINT_XFER_INT:
86 type = "Interrupt";
87 break;
88 }
89 return sprintf(buf, "%s\n", type);
90}
91static EP_ATTR(type);
92
93static ssize_t show_ep_interval(struct usb_device *udev,
94 struct usb_endpoint_descriptor *desc, char *buf)
95{
96 char unit;
97 unsigned interval = 0;
98 unsigned in;
99
100 in = (desc->bEndpointAddress & USB_DIR_IN);
101
102 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
103 case USB_ENDPOINT_XFER_CONTROL:
104 if (udev->speed == USB_SPEED_HIGH) /* uframes per NAK */
105 interval = desc->bInterval;
106 break;
107 case USB_ENDPOINT_XFER_ISOC:
108 interval = 1 << (desc->bInterval - 1);
109 break;
110 case USB_ENDPOINT_XFER_BULK:
111 if (udev->speed == USB_SPEED_HIGH && !in) /* uframes per NAK */
112 interval = desc->bInterval;
113 break;
114 case USB_ENDPOINT_XFER_INT:
115 if (udev->speed == USB_SPEED_HIGH)
116 interval = 1 << (desc->bInterval - 1);
117 else
118 interval = desc->bInterval;
119 break;
120 }
121 interval *= (udev->speed == USB_SPEED_HIGH) ? 125 : 1000;
122 if (interval % 1000)
123 unit = 'u';
124 else {
125 unit = 'm';
126 interval /= 1000;
127 }
128
129 return sprintf(buf, "%d%cs\n", interval, unit);
130}
131static EP_ATTR(interval);
132
133static ssize_t show_ep_direction(struct usb_device *udev,
134 struct usb_endpoint_descriptor *desc, char *buf)
135{
136 char *direction;
137
138 if ((desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
139 USB_ENDPOINT_XFER_CONTROL)
140 direction = "both";
141 else if (desc->bEndpointAddress & USB_DIR_IN)
142 direction = "in";
143 else
144 direction = "out";
145 return sprintf(buf, "%s\n", direction);
146}
147static EP_ATTR(direction);
148
149static struct attribute *ep_attrs[] = {
150 &ep_bLength.attr,
151 &ep_bEndpointAddress.attr,
152 &ep_bmAttributes.attr,
153 &ep_bInterval.attr,
154 &ep_wMaxPacketSize.attr,
155 &ep_type.attr,
156 &ep_interval.attr,
157 &ep_direction.attr,
158 NULL,
159};
160
161static void ep_object_release(struct kobject *kobj)
162{
163 kfree(to_ep_object(kobj));
164}
165
166static ssize_t ep_object_show(struct kobject *kobj, struct attribute *attr,
167 char *buf)
168{
169 struct ep_object *ep_obj = to_ep_object(kobj);
170 struct ep_attribute *ep_attr = to_ep_attribute(attr);
171
172 return (ep_attr->show)(ep_obj->udev, ep_obj->desc, buf);
173}
174
175static struct sysfs_ops ep_object_sysfs_ops = {
176 .show = ep_object_show,
177};
178
179static struct kobj_type ep_object_ktype = {
180 .release = ep_object_release,
181 .sysfs_ops = &ep_object_sysfs_ops,
182 .default_attrs = ep_attrs,
183};
184
185static void usb_create_ep_files(struct kobject *parent,
186 struct usb_host_endpoint *endpoint,
187 struct usb_device *udev)
188{
189 struct ep_object *ep_obj;
190 struct kobject *kobj;
191
192 ep_obj = kzalloc(sizeof(struct ep_object), GFP_KERNEL);
193 if (!ep_obj)
194 return;
195
196 ep_obj->desc = &endpoint->desc;
197 ep_obj->udev = udev;
198
199 kobj = &ep_obj->kobj;
200 kobject_set_name(kobj, "ep_%02x", endpoint->desc.bEndpointAddress);
201 kobj->parent = parent;
202 kobj->ktype = &ep_object_ktype;
203
204 /* Don't use kobject_register, because it generates a hotplug event */
205 kobject_init(kobj);
206 if (kobject_add(kobj) == 0)
207 endpoint->kobj = kobj;
208 else
209 kobject_put(kobj);
210}
211
212static void usb_remove_ep_files(struct usb_host_endpoint *endpoint)
213{
214
215 if (endpoint->kobj) {
216 kobject_del(endpoint->kobj);
217 kobject_put(endpoint->kobj);
218 endpoint->kobj = NULL;
219 }
220}
221
25/* Active configuration fields */ 222/* Active configuration fields */
26#define usb_actconfig_show(field, multiplier, format_string) \ 223#define usb_actconfig_show(field, multiplier, format_string) \
27static ssize_t show_##field (struct device *dev, struct device_attribute *attr, char *buf) \ 224static ssize_t show_##field (struct device *dev, \
225 struct device_attribute *attr, char *buf) \
28{ \ 226{ \
29 struct usb_device *udev; \ 227 struct usb_device *udev; \
30 struct usb_host_config *actconfig; \ 228 struct usb_host_config *actconfig; \
@@ -46,22 +244,17 @@ usb_actconfig_attr (bNumInterfaces, 1, "%2d\n")
46usb_actconfig_attr (bmAttributes, 1, "%2x\n") 244usb_actconfig_attr (bmAttributes, 1, "%2x\n")
47usb_actconfig_attr (bMaxPower, 2, "%3dmA\n") 245usb_actconfig_attr (bMaxPower, 2, "%3dmA\n")
48 246
49static ssize_t show_configuration_string(struct device *dev, struct device_attribute *attr, char *buf) 247static ssize_t show_configuration_string(struct device *dev,
248 struct device_attribute *attr, char *buf)
50{ 249{
51 struct usb_device *udev; 250 struct usb_device *udev;
52 struct usb_host_config *actconfig; 251 struct usb_host_config *actconfig;
53 int len;
54 252
55 udev = to_usb_device (dev); 253 udev = to_usb_device (dev);
56 actconfig = udev->actconfig; 254 actconfig = udev->actconfig;
57 if ((!actconfig) || (!actconfig->string)) 255 if ((!actconfig) || (!actconfig->string))
58 return 0; 256 return 0;
59 len = sprintf(buf, actconfig->string, PAGE_SIZE); 257 return sprintf(buf, "%s\n", actconfig->string);
60 if (len < 0)
61 return 0;
62 buf[len] = '\n';
63 buf[len+1] = 0;
64 return len+1;
65} 258}
66static DEVICE_ATTR(configuration, S_IRUGO, show_configuration_string, NULL); 259static DEVICE_ATTR(configuration, S_IRUGO, show_configuration_string, NULL);
67 260
@@ -69,7 +262,8 @@ static DEVICE_ATTR(configuration, S_IRUGO, show_configuration_string, NULL);
69usb_actconfig_show(bConfigurationValue, 1, "%u\n"); 262usb_actconfig_show(bConfigurationValue, 1, "%u\n");
70 263
71static ssize_t 264static ssize_t
72set_bConfigurationValue (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 265set_bConfigurationValue (struct device *dev, struct device_attribute *attr,
266 const char *buf, size_t count)
73{ 267{
74 struct usb_device *udev = udev = to_usb_device (dev); 268 struct usb_device *udev = udev = to_usb_device (dev);
75 int config, value; 269 int config, value;
@@ -87,18 +281,13 @@ static DEVICE_ATTR(bConfigurationValue, S_IRUGO | S_IWUSR,
87 281
88/* String fields */ 282/* String fields */
89#define usb_string_attr(name) \ 283#define usb_string_attr(name) \
90static ssize_t show_##name(struct device *dev, struct device_attribute *attr, char *buf) \ 284static ssize_t show_##name(struct device *dev, \
285 struct device_attribute *attr, char *buf) \
91{ \ 286{ \
92 struct usb_device *udev; \ 287 struct usb_device *udev; \
93 int len; \
94 \ 288 \
95 udev = to_usb_device (dev); \ 289 udev = to_usb_device (dev); \
96 len = snprintf(buf, 256, "%s", udev->name); \ 290 return sprintf(buf, "%s\n", udev->name); \
97 if (len < 0) \
98 return 0; \
99 buf[len] = '\n'; \
100 buf[len+1] = 0; \
101 return len+1; \
102} \ 291} \
103static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL); 292static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
104 293
@@ -167,7 +356,8 @@ static DEVICE_ATTR(maxchild, S_IRUGO, show_maxchild, NULL);
167/* Descriptor fields */ 356/* Descriptor fields */
168#define usb_descriptor_attr_le16(field, format_string) \ 357#define usb_descriptor_attr_le16(field, format_string) \
169static ssize_t \ 358static ssize_t \
170show_##field (struct device *dev, struct device_attribute *attr, char *buf) \ 359show_##field (struct device *dev, struct device_attribute *attr, \
360 char *buf) \
171{ \ 361{ \
172 struct usb_device *udev; \ 362 struct usb_device *udev; \
173 \ 363 \
@@ -183,7 +373,8 @@ usb_descriptor_attr_le16(bcdDevice, "%04x\n")
183 373
184#define usb_descriptor_attr(field, format_string) \ 374#define usb_descriptor_attr(field, format_string) \
185static ssize_t \ 375static ssize_t \
186show_##field (struct device *dev, struct device_attribute *attr, char *buf) \ 376show_##field (struct device *dev, struct device_attribute *attr, \
377 char *buf) \
187{ \ 378{ \
188 struct usb_device *udev; \ 379 struct usb_device *udev; \
189 \ 380 \
@@ -236,19 +427,21 @@ void usb_create_sysfs_dev_files (struct usb_device *udev)
236 if (udev->serial) 427 if (udev->serial)
237 device_create_file (dev, &dev_attr_serial); 428 device_create_file (dev, &dev_attr_serial);
238 device_create_file (dev, &dev_attr_configuration); 429 device_create_file (dev, &dev_attr_configuration);
430 usb_create_ep_files(&dev->kobj, &udev->ep0, udev);
239} 431}
240 432
241void usb_remove_sysfs_dev_files (struct usb_device *udev) 433void usb_remove_sysfs_dev_files (struct usb_device *udev)
242{ 434{
243 struct device *dev = &udev->dev; 435 struct device *dev = &udev->dev;
244 436
437 usb_remove_ep_files(&udev->ep0);
245 sysfs_remove_group(&dev->kobj, &dev_attr_grp); 438 sysfs_remove_group(&dev->kobj, &dev_attr_grp);
246 439
247 if (udev->descriptor.iManufacturer) 440 if (udev->manufacturer)
248 device_remove_file(dev, &dev_attr_manufacturer); 441 device_remove_file(dev, &dev_attr_manufacturer);
249 if (udev->descriptor.iProduct) 442 if (udev->product)
250 device_remove_file(dev, &dev_attr_product); 443 device_remove_file(dev, &dev_attr_product);
251 if (udev->descriptor.iSerialNumber) 444 if (udev->serial)
252 device_remove_file(dev, &dev_attr_serial); 445 device_remove_file(dev, &dev_attr_serial);
253 device_remove_file (dev, &dev_attr_configuration); 446 device_remove_file (dev, &dev_attr_configuration);
254} 447}
@@ -256,11 +449,13 @@ void usb_remove_sysfs_dev_files (struct usb_device *udev)
256/* Interface fields */ 449/* Interface fields */
257#define usb_intf_attr(field, format_string) \ 450#define usb_intf_attr(field, format_string) \
258static ssize_t \ 451static ssize_t \
259show_##field (struct device *dev, struct device_attribute *attr, char *buf) \ 452show_##field (struct device *dev, struct device_attribute *attr, \
453 char *buf) \
260{ \ 454{ \
261 struct usb_interface *intf = to_usb_interface (dev); \ 455 struct usb_interface *intf = to_usb_interface (dev); \
262 \ 456 \
263 return sprintf (buf, format_string, intf->cur_altsetting->desc.field); \ 457 return sprintf (buf, format_string, \
458 intf->cur_altsetting->desc.field); \
264} \ 459} \
265static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL); 460static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL);
266 461
@@ -271,7 +466,8 @@ usb_intf_attr (bInterfaceClass, "%02x\n")
271usb_intf_attr (bInterfaceSubClass, "%02x\n") 466usb_intf_attr (bInterfaceSubClass, "%02x\n")
272usb_intf_attr (bInterfaceProtocol, "%02x\n") 467usb_intf_attr (bInterfaceProtocol, "%02x\n")
273 468
274static ssize_t show_interface_string(struct device *dev, struct device_attribute *attr, char *buf) 469static ssize_t show_interface_string(struct device *dev,
470 struct device_attribute *attr, char *buf)
275{ 471{
276 struct usb_interface *intf; 472 struct usb_interface *intf;
277 struct usb_device *udev; 473 struct usb_device *udev;
@@ -288,34 +484,28 @@ static ssize_t show_interface_string(struct device *dev, struct device_attribute
288} 484}
289static DEVICE_ATTR(interface, S_IRUGO, show_interface_string, NULL); 485static DEVICE_ATTR(interface, S_IRUGO, show_interface_string, NULL);
290 486
291static ssize_t show_modalias(struct device *dev, struct device_attribute *attr, char *buf) 487static ssize_t show_modalias(struct device *dev,
488 struct device_attribute *attr, char *buf)
292{ 489{
293 struct usb_interface *intf; 490 struct usb_interface *intf;
294 struct usb_device *udev; 491 struct usb_device *udev;
295 int len; 492 struct usb_host_interface *alt;
296 493
297 intf = to_usb_interface(dev); 494 intf = to_usb_interface(dev);
298 udev = interface_to_usbdev(intf); 495 udev = interface_to_usbdev(intf);
299 496 alt = intf->cur_altsetting;
300 len = sprintf(buf, "usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic", 497
301 le16_to_cpu(udev->descriptor.idVendor), 498 return sprintf(buf, "usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02X"
302 le16_to_cpu(udev->descriptor.idProduct), 499 "ic%02Xisc%02Xip%02X\n",
303 le16_to_cpu(udev->descriptor.bcdDevice), 500 le16_to_cpu(udev->descriptor.idVendor),
304 udev->descriptor.bDeviceClass, 501 le16_to_cpu(udev->descriptor.idProduct),
305 udev->descriptor.bDeviceSubClass, 502 le16_to_cpu(udev->descriptor.bcdDevice),
306 udev->descriptor.bDeviceProtocol); 503 udev->descriptor.bDeviceClass,
307 buf += len; 504 udev->descriptor.bDeviceSubClass,
308 505 udev->descriptor.bDeviceProtocol,
309 if (udev->descriptor.bDeviceClass == 0) { 506 alt->desc.bInterfaceClass,
310 struct usb_host_interface *alt = intf->cur_altsetting; 507 alt->desc.bInterfaceSubClass,
311 508 alt->desc.bInterfaceProtocol);
312 return len + sprintf(buf, "%02Xisc%02Xip%02X\n",
313 alt->desc.bInterfaceClass,
314 alt->desc.bInterfaceSubClass,
315 alt->desc.bInterfaceProtocol);
316 } else {
317 return len + sprintf(buf, "*isc*ip*\n");
318 }
319} 509}
320static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL); 510static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL);
321 511
@@ -333,20 +523,47 @@ static struct attribute_group intf_attr_grp = {
333 .attrs = intf_attrs, 523 .attrs = intf_attrs,
334}; 524};
335 525
526static inline void usb_create_intf_ep_files(struct usb_interface *intf,
527 struct usb_device *udev)
528{
529 struct usb_host_interface *iface_desc;
530 int i;
531
532 iface_desc = intf->cur_altsetting;
533 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i)
534 usb_create_ep_files(&intf->dev.kobj, &iface_desc->endpoint[i],
535 udev);
536}
537
538static inline void usb_remove_intf_ep_files(struct usb_interface *intf)
539{
540 struct usb_host_interface *iface_desc;
541 int i;
542
543 iface_desc = intf->cur_altsetting;
544 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i)
545 usb_remove_ep_files(&iface_desc->endpoint[i]);
546}
547
336void usb_create_sysfs_intf_files (struct usb_interface *intf) 548void usb_create_sysfs_intf_files (struct usb_interface *intf)
337{ 549{
550 struct usb_device *udev = interface_to_usbdev(intf);
551 struct usb_host_interface *alt = intf->cur_altsetting;
552
338 sysfs_create_group(&intf->dev.kobj, &intf_attr_grp); 553 sysfs_create_group(&intf->dev.kobj, &intf_attr_grp);
339 554
340 if (intf->cur_altsetting->string) 555 if (alt->string == NULL)
556 alt->string = usb_cache_string(udev, alt->desc.iInterface);
557 if (alt->string)
341 device_create_file(&intf->dev, &dev_attr_interface); 558 device_create_file(&intf->dev, &dev_attr_interface);
342 559 usb_create_intf_ep_files(intf, udev);
343} 560}
344 561
345void usb_remove_sysfs_intf_files (struct usb_interface *intf) 562void usb_remove_sysfs_intf_files (struct usb_interface *intf)
346{ 563{
564 usb_remove_intf_ep_files(intf);
347 sysfs_remove_group(&intf->dev.kobj, &intf_attr_grp); 565 sysfs_remove_group(&intf->dev.kobj, &intf_attr_grp);
348 566
349 if (intf->cur_altsetting->string) 567 if (intf->cur_altsetting->string)
350 device_remove_file(&intf->dev, &dev_attr_interface); 568 device_remove_file(&intf->dev, &dev_attr_interface);
351
352} 569}
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index c846fefb7386..f2a1fed2a802 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -60,7 +60,7 @@ void usb_init_urb(struct urb *urb)
60 * 60 *
61 * The driver must call usb_free_urb() when it is finished with the urb. 61 * The driver must call usb_free_urb() when it is finished with the urb.
62 */ 62 */
63struct urb *usb_alloc_urb(int iso_packets, unsigned mem_flags) 63struct urb *usb_alloc_urb(int iso_packets, gfp_t mem_flags)
64{ 64{
65 struct urb *urb; 65 struct urb *urb;
66 66
@@ -224,7 +224,7 @@ struct urb * usb_get_urb(struct urb *urb)
224 * GFP_NOIO, unless b) or c) apply 224 * GFP_NOIO, unless b) or c) apply
225 * 225 *
226 */ 226 */
227int usb_submit_urb(struct urb *urb, unsigned mem_flags) 227int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
228{ 228{
229 int pipe, temp, max; 229 int pipe, temp, max;
230 struct usb_device *dev; 230 struct usb_device *dev;
@@ -237,7 +237,8 @@ int usb_submit_urb(struct urb *urb, unsigned mem_flags)
237 (dev->state < USB_STATE_DEFAULT) || 237 (dev->state < USB_STATE_DEFAULT) ||
238 (!dev->bus) || (dev->devnum <= 0)) 238 (!dev->bus) || (dev->devnum <= 0))
239 return -ENODEV; 239 return -ENODEV;
240 if (dev->state == USB_STATE_SUSPENDED) 240 if (dev->bus->controller->power.power_state.event != PM_EVENT_ON
241 || dev->state == USB_STATE_SUSPENDED)
241 return -EHOSTUNREACH; 242 return -EHOSTUNREACH;
242 if (!(op = dev->bus->op) || !op->submit_urb) 243 if (!(op = dev->bus->op) || !op->submit_urb)
243 return -ENODEV; 244 return -ENODEV;
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 7d131509e419..0eefff7bcb3c 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -107,10 +107,19 @@ static int usb_probe_interface(struct device *dev)
107 id = usb_match_id (intf, driver->id_table); 107 id = usb_match_id (intf, driver->id_table);
108 if (id) { 108 if (id) {
109 dev_dbg (dev, "%s - got id\n", __FUNCTION__); 109 dev_dbg (dev, "%s - got id\n", __FUNCTION__);
110
111 /* Interface "power state" doesn't correspond to any hardware
112 * state whatsoever. We use it to record when it's bound to
113 * a driver that may start I/0: it's not frozen/quiesced.
114 */
115 mark_active(intf);
110 intf->condition = USB_INTERFACE_BINDING; 116 intf->condition = USB_INTERFACE_BINDING;
111 error = driver->probe (intf, id); 117 error = driver->probe (intf, id);
112 intf->condition = error ? USB_INTERFACE_UNBOUND : 118 if (error) {
113 USB_INTERFACE_BOUND; 119 mark_quiesced(intf);
120 intf->condition = USB_INTERFACE_UNBOUND;
121 } else
122 intf->condition = USB_INTERFACE_BOUND;
114 } 123 }
115 124
116 return error; 125 return error;
@@ -136,6 +145,7 @@ static int usb_unbind_interface(struct device *dev)
136 0); 145 0);
137 usb_set_intfdata(intf, NULL); 146 usb_set_intfdata(intf, NULL);
138 intf->condition = USB_INTERFACE_UNBOUND; 147 intf->condition = USB_INTERFACE_UNBOUND;
148 mark_quiesced(intf);
139 149
140 return 0; 150 return 0;
141} 151}
@@ -299,6 +309,7 @@ int usb_driver_claim_interface(struct usb_driver *driver,
299 dev->driver = &driver->driver; 309 dev->driver = &driver->driver;
300 usb_set_intfdata(iface, priv); 310 usb_set_intfdata(iface, priv);
301 iface->condition = USB_INTERFACE_BOUND; 311 iface->condition = USB_INTERFACE_BOUND;
312 mark_active(iface);
302 313
303 /* if interface was already added, bind now; else let 314 /* if interface was already added, bind now; else let
304 * the future device_add() bind it, bypassing probe() 315 * the future device_add() bind it, bypassing probe()
@@ -345,6 +356,7 @@ void usb_driver_release_interface(struct usb_driver *driver,
345 dev->driver = NULL; 356 dev->driver = NULL;
346 usb_set_intfdata(iface, NULL); 357 usb_set_intfdata(iface, NULL);
347 iface->condition = USB_INTERFACE_UNBOUND; 358 iface->condition = USB_INTERFACE_UNBOUND;
359 mark_quiesced(iface);
348} 360}
349 361
350/** 362/**
@@ -557,6 +569,7 @@ static int usb_hotplug (struct device *dev, char **envp, int num_envp,
557{ 569{
558 struct usb_interface *intf; 570 struct usb_interface *intf;
559 struct usb_device *usb_dev; 571 struct usb_device *usb_dev;
572 struct usb_host_interface *alt;
560 int i = 0; 573 int i = 0;
561 int length = 0; 574 int length = 0;
562 575
@@ -573,7 +586,8 @@ static int usb_hotplug (struct device *dev, char **envp, int num_envp,
573 586
574 intf = to_usb_interface(dev); 587 intf = to_usb_interface(dev);
575 usb_dev = interface_to_usbdev (intf); 588 usb_dev = interface_to_usbdev (intf);
576 589 alt = intf->cur_altsetting;
590
577 if (usb_dev->devnum < 0) { 591 if (usb_dev->devnum < 0) {
578 pr_debug ("usb %s: already deleted?\n", dev->bus_id); 592 pr_debug ("usb %s: already deleted?\n", dev->bus_id);
579 return -ENODEV; 593 return -ENODEV;
@@ -615,46 +629,27 @@ static int usb_hotplug (struct device *dev, char **envp, int num_envp,
615 usb_dev->descriptor.bDeviceProtocol)) 629 usb_dev->descriptor.bDeviceProtocol))
616 return -ENOMEM; 630 return -ENOMEM;
617 631
618 if (usb_dev->descriptor.bDeviceClass == 0) { 632 if (add_hotplug_env_var(envp, num_envp, &i,
619 struct usb_host_interface *alt = intf->cur_altsetting; 633 buffer, buffer_size, &length,
634 "INTERFACE=%d/%d/%d",
635 alt->desc.bInterfaceClass,
636 alt->desc.bInterfaceSubClass,
637 alt->desc.bInterfaceProtocol))
638 return -ENOMEM;
620 639
621 /* 2.4 only exposed interface zero. in 2.5, hotplug 640 if (add_hotplug_env_var(envp, num_envp, &i,
622 * agents are called for all interfaces, and can use 641 buffer, buffer_size, &length,
623 * $DEVPATH/bInterfaceNumber if necessary. 642 "MODALIAS=usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X",
624 */ 643 le16_to_cpu(usb_dev->descriptor.idVendor),
625 if (add_hotplug_env_var(envp, num_envp, &i, 644 le16_to_cpu(usb_dev->descriptor.idProduct),
626 buffer, buffer_size, &length, 645 le16_to_cpu(usb_dev->descriptor.bcdDevice),
627 "INTERFACE=%d/%d/%d", 646 usb_dev->descriptor.bDeviceClass,
628 alt->desc.bInterfaceClass, 647 usb_dev->descriptor.bDeviceSubClass,
629 alt->desc.bInterfaceSubClass, 648 usb_dev->descriptor.bDeviceProtocol,
630 alt->desc.bInterfaceProtocol)) 649 alt->desc.bInterfaceClass,
631 return -ENOMEM; 650 alt->desc.bInterfaceSubClass,
632 651 alt->desc.bInterfaceProtocol))
633 if (add_hotplug_env_var(envp, num_envp, &i, 652 return -ENOMEM;
634 buffer, buffer_size, &length,
635 "MODALIAS=usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X",
636 le16_to_cpu(usb_dev->descriptor.idVendor),
637 le16_to_cpu(usb_dev->descriptor.idProduct),
638 le16_to_cpu(usb_dev->descriptor.bcdDevice),
639 usb_dev->descriptor.bDeviceClass,
640 usb_dev->descriptor.bDeviceSubClass,
641 usb_dev->descriptor.bDeviceProtocol,
642 alt->desc.bInterfaceClass,
643 alt->desc.bInterfaceSubClass,
644 alt->desc.bInterfaceProtocol))
645 return -ENOMEM;
646 } else {
647 if (add_hotplug_env_var(envp, num_envp, &i,
648 buffer, buffer_size, &length,
649 "MODALIAS=usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic*isc*ip*",
650 le16_to_cpu(usb_dev->descriptor.idVendor),
651 le16_to_cpu(usb_dev->descriptor.idProduct),
652 le16_to_cpu(usb_dev->descriptor.bcdDevice),
653 usb_dev->descriptor.bDeviceClass,
654 usb_dev->descriptor.bDeviceSubClass,
655 usb_dev->descriptor.bDeviceProtocol))
656 return -ENOMEM;
657 }
658 653
659 envp[i] = NULL; 654 envp[i] = NULL;
660 655
@@ -709,12 +704,10 @@ usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1)
709{ 704{
710 struct usb_device *dev; 705 struct usb_device *dev;
711 706
712 dev = kmalloc(sizeof(*dev), GFP_KERNEL); 707 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
713 if (!dev) 708 if (!dev)
714 return NULL; 709 return NULL;
715 710
716 memset(dev, 0, sizeof(*dev));
717
718 bus = usb_bus_get(bus); 711 bus = usb_bus_get(bus);
719 if (!bus) { 712 if (!bus) {
720 kfree(dev); 713 kfree(dev);
@@ -1147,7 +1140,7 @@ int __usb_get_extra_descriptor(char *buffer, unsigned size,
1147void *usb_buffer_alloc ( 1140void *usb_buffer_alloc (
1148 struct usb_device *dev, 1141 struct usb_device *dev,
1149 size_t size, 1142 size_t size,
1150 unsigned mem_flags, 1143 gfp_t mem_flags,
1151 dma_addr_t *dma 1144 dma_addr_t *dma
1152) 1145)
1153{ 1146{
@@ -1402,13 +1395,30 @@ void usb_buffer_unmap_sg (struct usb_device *dev, unsigned pipe,
1402 usb_pipein (pipe) ? DMA_FROM_DEVICE : DMA_TO_DEVICE); 1395 usb_pipein (pipe) ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
1403} 1396}
1404 1397
1398static int verify_suspended(struct device *dev, void *unused)
1399{
1400 return (dev->power.power_state.event == PM_EVENT_ON) ? -EBUSY : 0;
1401}
1402
1405static int usb_generic_suspend(struct device *dev, pm_message_t message) 1403static int usb_generic_suspend(struct device *dev, pm_message_t message)
1406{ 1404{
1407 struct usb_interface *intf; 1405 struct usb_interface *intf;
1408 struct usb_driver *driver; 1406 struct usb_driver *driver;
1407 int status;
1409 1408
1410 if (dev->driver == &usb_generic_driver) 1409 /* USB devices enter SUSPEND state through their hubs, but can be
1411 return usb_suspend_device (to_usb_device(dev), message); 1410 * marked for FREEZE as soon as their children are already idled.
1411 * But those semantics are useless, so we equate the two (sigh).
1412 */
1413 if (dev->driver == &usb_generic_driver) {
1414 if (dev->power.power_state.event == message.event)
1415 return 0;
1416 /* we need to rule out bogus requests through sysfs */
1417 status = device_for_each_child(dev, NULL, verify_suspended);
1418 if (status)
1419 return status;
1420 return usb_suspend_device (to_usb_device(dev));
1421 }
1412 1422
1413 if ((dev->driver == NULL) || 1423 if ((dev->driver == NULL) ||
1414 (dev->driver_data == &usb_generic_driver_data)) 1424 (dev->driver_data == &usb_generic_driver_data))
@@ -1417,23 +1427,44 @@ static int usb_generic_suspend(struct device *dev, pm_message_t message)
1417 intf = to_usb_interface(dev); 1427 intf = to_usb_interface(dev);
1418 driver = to_usb_driver(dev->driver); 1428 driver = to_usb_driver(dev->driver);
1419 1429
1420 /* there's only one USB suspend state */ 1430 /* with no hardware, USB interfaces only use FREEZE and ON states */
1421 if (intf->dev.power.power_state.event) 1431 if (!is_active(intf))
1422 return 0; 1432 return 0;
1423 1433
1424 if (driver->suspend) 1434 if (driver->suspend && driver->resume) {
1425 return driver->suspend(intf, message); 1435 status = driver->suspend(intf, message);
1426 return 0; 1436 if (status)
1437 dev_err(dev, "%s error %d\n", "suspend", status);
1438 else
1439 mark_quiesced(intf);
1440 } else {
1441 // FIXME else if there's no suspend method, disconnect...
1442 dev_warn(dev, "no %s?\n", "suspend");
1443 status = 0;
1444 }
1445 return status;
1427} 1446}
1428 1447
1429static int usb_generic_resume(struct device *dev) 1448static int usb_generic_resume(struct device *dev)
1430{ 1449{
1431 struct usb_interface *intf; 1450 struct usb_interface *intf;
1432 struct usb_driver *driver; 1451 struct usb_driver *driver;
1452 struct usb_device *udev;
1453 int status;
1433 1454
1434 /* devices resume through their hub */ 1455 if (dev->power.power_state.event == PM_EVENT_ON)
1435 if (dev->driver == &usb_generic_driver) 1456 return 0;
1457
1458 /* mark things as "on" immediately, no matter what errors crop up */
1459 dev->power.power_state.event = PM_EVENT_ON;
1460
1461 /* devices resume through their hubs */
1462 if (dev->driver == &usb_generic_driver) {
1463 udev = to_usb_device(dev);
1464 if (udev->state == USB_STATE_NOTATTACHED)
1465 return 0;
1436 return usb_resume_device (to_usb_device(dev)); 1466 return usb_resume_device (to_usb_device(dev));
1467 }
1437 1468
1438 if ((dev->driver == NULL) || 1469 if ((dev->driver == NULL) ||
1439 (dev->driver_data == &usb_generic_driver_data)) 1470 (dev->driver_data == &usb_generic_driver_data))
@@ -1442,8 +1473,22 @@ static int usb_generic_resume(struct device *dev)
1442 intf = to_usb_interface(dev); 1473 intf = to_usb_interface(dev);
1443 driver = to_usb_driver(dev->driver); 1474 driver = to_usb_driver(dev->driver);
1444 1475
1445 if (driver->resume) 1476 udev = interface_to_usbdev(intf);
1446 return driver->resume(intf); 1477 if (udev->state == USB_STATE_NOTATTACHED)
1478 return 0;
1479
1480 /* if driver was suspended, it has a resume method;
1481 * however, sysfs can wrongly mark things as suspended
1482 * (on the "no suspend method" FIXME path above)
1483 */
1484 if (driver->resume) {
1485 status = driver->resume(intf);
1486 if (status) {
1487 dev_err(dev, "%s error %d\n", "resume", status);
1488 mark_quiesced(intf);
1489 }
1490 } else
1491 dev_warn(dev, "no %s?\n", "resume");
1447 return 0; 1492 return 0;
1448} 1493}
1449 1494
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index e6504f3370ad..1c4a68499dce 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -13,12 +13,14 @@ extern void usb_disable_device (struct usb_device *dev, int skip_ep0);
13 13
14extern int usb_get_device_descriptor(struct usb_device *dev, 14extern int usb_get_device_descriptor(struct usb_device *dev,
15 unsigned int size); 15 unsigned int size);
16extern char *usb_cache_string(struct usb_device *udev, int index);
16extern int usb_set_configuration(struct usb_device *dev, int configuration); 17extern int usb_set_configuration(struct usb_device *dev, int configuration);
17 18
18extern void usb_lock_all_devices(void); 19extern void usb_lock_all_devices(void);
19extern void usb_unlock_all_devices(void); 20extern void usb_unlock_all_devices(void);
20 21
21extern void usb_kick_khubd(struct usb_device *dev); 22extern void usb_kick_khubd(struct usb_device *dev);
23extern void usb_suspend_root_hub(struct usb_device *hdev);
22extern void usb_resume_root_hub(struct usb_device *dev); 24extern void usb_resume_root_hub(struct usb_device *dev);
23 25
24extern int usb_hub_init(void); 26extern int usb_hub_init(void);
@@ -28,6 +30,28 @@ extern void usb_major_cleanup(void);
28extern int usb_host_init(void); 30extern int usb_host_init(void);
29extern void usb_host_cleanup(void); 31extern void usb_host_cleanup(void);
30 32
33extern int usb_suspend_device(struct usb_device *dev);
34extern int usb_resume_device(struct usb_device *dev);
35
36
37/* Interfaces and their "power state" are owned by usbcore */
38
39static inline void mark_active(struct usb_interface *f)
40{
41 f->dev.power.power_state.event = PM_EVENT_ON;
42}
43
44static inline void mark_quiesced(struct usb_interface *f)
45{
46 f->dev.power.power_state.event = PM_EVENT_FREEZE;
47}
48
49static inline int is_active(struct usb_interface *f)
50{
51 return f->dev.power.power_state.event == PM_EVENT_ON;
52}
53
54
31/* for labeling diagnostics */ 55/* for labeling diagnostics */
32extern const char *usbcore_name; 56extern const char *usbcore_name;
33 57
@@ -39,9 +63,6 @@ extern void usbfs_conn_disc_event(void);
39 63
40extern int usbdev_init(void); 64extern int usbdev_init(void);
41extern void usbdev_cleanup(void); 65extern void usbdev_cleanup(void);
42extern void usbdev_add(struct usb_device *dev);
43extern void usbdev_remove(struct usb_device *dev);
44extern struct usb_device *usbdev_lookup_minor(int minor);
45 66
46struct dev_state { 67struct dev_state {
47 struct list_head list; /* state list */ 68 struct list_head list; /* state list */
@@ -58,3 +79,9 @@ struct dev_state {
58 unsigned long ifclaimed; 79 unsigned long ifclaimed;
59}; 80};
60 81
82/* internal notify stuff */
83extern void usb_notify_add_device(struct usb_device *udev);
84extern void usb_notify_remove_device(struct usb_device *udev);
85extern void usb_notify_add_bus(struct usb_bus *ubus);
86extern void usb_notify_remove_bus(struct usb_bus *ubus);
87
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index 583db7c38cf1..02106bebd5c1 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -470,7 +470,7 @@ static int dummy_disable (struct usb_ep *_ep)
470} 470}
471 471
472static struct usb_request * 472static struct usb_request *
473dummy_alloc_request (struct usb_ep *_ep, unsigned mem_flags) 473dummy_alloc_request (struct usb_ep *_ep, gfp_t mem_flags)
474{ 474{
475 struct dummy_ep *ep; 475 struct dummy_ep *ep;
476 struct dummy_request *req; 476 struct dummy_request *req;
@@ -507,7 +507,7 @@ dummy_alloc_buffer (
507 struct usb_ep *_ep, 507 struct usb_ep *_ep,
508 unsigned bytes, 508 unsigned bytes,
509 dma_addr_t *dma, 509 dma_addr_t *dma,
510 unsigned mem_flags 510 gfp_t mem_flags
511) { 511) {
512 char *retval; 512 char *retval;
513 struct dummy_ep *ep; 513 struct dummy_ep *ep;
@@ -541,7 +541,7 @@ fifo_complete (struct usb_ep *ep, struct usb_request *req)
541 541
542static int 542static int
543dummy_queue (struct usb_ep *_ep, struct usb_request *_req, 543dummy_queue (struct usb_ep *_ep, struct usb_request *_req,
544 unsigned mem_flags) 544 gfp_t mem_flags)
545{ 545{
546 struct dummy_ep *ep; 546 struct dummy_ep *ep;
547 struct dummy_request *req; 547 struct dummy_request *req;
@@ -935,14 +935,10 @@ static int dummy_udc_remove (struct device *dev)
935 return 0; 935 return 0;
936} 936}
937 937
938static int dummy_udc_suspend (struct device *dev, pm_message_t state, 938static int dummy_udc_suspend (struct device *dev, pm_message_t state)
939 u32 level)
940{ 939{
941 struct dummy *dum = dev_get_drvdata(dev); 940 struct dummy *dum = dev_get_drvdata(dev);
942 941
943 if (level != SUSPEND_DISABLE)
944 return 0;
945
946 dev_dbg (dev, "%s\n", __FUNCTION__); 942 dev_dbg (dev, "%s\n", __FUNCTION__);
947 spin_lock_irq (&dum->lock); 943 spin_lock_irq (&dum->lock);
948 dum->udc_suspended = 1; 944 dum->udc_suspended = 1;
@@ -954,13 +950,10 @@ static int dummy_udc_suspend (struct device *dev, pm_message_t state,
954 return 0; 950 return 0;
955} 951}
956 952
957static int dummy_udc_resume (struct device *dev, u32 level) 953static int dummy_udc_resume (struct device *dev)
958{ 954{
959 struct dummy *dum = dev_get_drvdata(dev); 955 struct dummy *dum = dev_get_drvdata(dev);
960 956
961 if (level != RESUME_ENABLE)
962 return 0;
963
964 dev_dbg (dev, "%s\n", __FUNCTION__); 957 dev_dbg (dev, "%s\n", __FUNCTION__);
965 spin_lock_irq (&dum->lock); 958 spin_lock_irq (&dum->lock);
966 dum->udc_suspended = 0; 959 dum->udc_suspended = 0;
@@ -974,6 +967,7 @@ static int dummy_udc_resume (struct device *dev, u32 level)
974 967
975static struct device_driver dummy_udc_driver = { 968static struct device_driver dummy_udc_driver = {
976 .name = (char *) gadget_name, 969 .name = (char *) gadget_name,
970 .owner = THIS_MODULE,
977 .bus = &platform_bus_type, 971 .bus = &platform_bus_type,
978 .probe = dummy_udc_probe, 972 .probe = dummy_udc_probe,
979 .remove = dummy_udc_remove, 973 .remove = dummy_udc_remove,
@@ -999,7 +993,7 @@ static int dummy_urb_enqueue (
999 struct usb_hcd *hcd, 993 struct usb_hcd *hcd,
1000 struct usb_host_endpoint *ep, 994 struct usb_host_endpoint *ep,
1001 struct urb *urb, 995 struct urb *urb,
1002 unsigned mem_flags 996 gfp_t mem_flags
1003) { 997) {
1004 struct dummy *dum; 998 struct dummy *dum;
1005 struct urbp *urbp; 999 struct urbp *urbp;
@@ -1758,7 +1752,7 @@ static int dummy_hub_control (
1758 return retval; 1752 return retval;
1759} 1753}
1760 1754
1761static int dummy_hub_suspend (struct usb_hcd *hcd) 1755static int dummy_bus_suspend (struct usb_hcd *hcd)
1762{ 1756{
1763 struct dummy *dum = hcd_to_dummy (hcd); 1757 struct dummy *dum = hcd_to_dummy (hcd);
1764 1758
@@ -1769,7 +1763,7 @@ static int dummy_hub_suspend (struct usb_hcd *hcd)
1769 return 0; 1763 return 0;
1770} 1764}
1771 1765
1772static int dummy_hub_resume (struct usb_hcd *hcd) 1766static int dummy_bus_resume (struct usb_hcd *hcd)
1773{ 1767{
1774 struct dummy *dum = hcd_to_dummy (hcd); 1768 struct dummy *dum = hcd_to_dummy (hcd);
1775 1769
@@ -1901,8 +1895,8 @@ static const struct hc_driver dummy_hcd = {
1901 1895
1902 .hub_status_data = dummy_hub_status, 1896 .hub_status_data = dummy_hub_status,
1903 .hub_control = dummy_hub_control, 1897 .hub_control = dummy_hub_control,
1904 .hub_suspend = dummy_hub_suspend, 1898 .bus_suspend = dummy_bus_suspend,
1905 .hub_resume = dummy_hub_resume, 1899 .bus_resume = dummy_bus_resume,
1906}; 1900};
1907 1901
1908static int dummy_hcd_probe (struct device *dev) 1902static int dummy_hcd_probe (struct device *dev)
@@ -1936,52 +1930,32 @@ static int dummy_hcd_remove (struct device *dev)
1936 return 0; 1930 return 0;
1937} 1931}
1938 1932
1939static int dummy_hcd_suspend (struct device *dev, pm_message_t state, 1933static int dummy_hcd_suspend (struct device *dev, pm_message_t state)
1940 u32 level)
1941{ 1934{
1942 struct usb_hcd *hcd; 1935 struct usb_hcd *hcd;
1943 1936
1944 if (level != SUSPEND_DISABLE)
1945 return 0;
1946
1947 dev_dbg (dev, "%s\n", __FUNCTION__); 1937 dev_dbg (dev, "%s\n", __FUNCTION__);
1948 hcd = dev_get_drvdata (dev); 1938 hcd = dev_get_drvdata (dev);
1949 1939
1950#ifndef CONFIG_USB_SUSPEND
1951 /* Otherwise this would never happen */
1952 usb_lock_device (hcd->self.root_hub);
1953 dummy_hub_suspend (hcd);
1954 usb_unlock_device (hcd->self.root_hub);
1955#endif
1956
1957 hcd->state = HC_STATE_SUSPENDED; 1940 hcd->state = HC_STATE_SUSPENDED;
1958 return 0; 1941 return 0;
1959} 1942}
1960 1943
1961static int dummy_hcd_resume (struct device *dev, u32 level) 1944static int dummy_hcd_resume (struct device *dev)
1962{ 1945{
1963 struct usb_hcd *hcd; 1946 struct usb_hcd *hcd;
1964 1947
1965 if (level != RESUME_ENABLE)
1966 return 0;
1967
1968 dev_dbg (dev, "%s\n", __FUNCTION__); 1948 dev_dbg (dev, "%s\n", __FUNCTION__);
1969 hcd = dev_get_drvdata (dev); 1949 hcd = dev_get_drvdata (dev);
1970 hcd->state = HC_STATE_RUNNING; 1950 hcd->state = HC_STATE_RUNNING;
1971 1951
1972#ifndef CONFIG_USB_SUSPEND
1973 /* Otherwise this would never happen */
1974 usb_lock_device (hcd->self.root_hub);
1975 dummy_hub_resume (hcd);
1976 usb_unlock_device (hcd->self.root_hub);
1977#endif
1978
1979 usb_hcd_poll_rh_status (hcd); 1952 usb_hcd_poll_rh_status (hcd);
1980 return 0; 1953 return 0;
1981} 1954}
1982 1955
1983static struct device_driver dummy_hcd_driver = { 1956static struct device_driver dummy_hcd_driver = {
1984 .name = (char *) driver_name, 1957 .name = (char *) driver_name,
1958 .owner = THIS_MODULE,
1985 .bus = &platform_bus_type, 1959 .bus = &platform_bus_type,
1986 .probe = dummy_hcd_probe, 1960 .probe = dummy_hcd_probe,
1987 .remove = dummy_hcd_remove, 1961 .remove = dummy_hcd_remove,
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 49459e33e952..8f402f85e1ca 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -945,11 +945,11 @@ config_buf (enum usb_device_speed speed,
945 945
946/*-------------------------------------------------------------------------*/ 946/*-------------------------------------------------------------------------*/
947 947
948static void eth_start (struct eth_dev *dev, unsigned gfp_flags); 948static void eth_start (struct eth_dev *dev, gfp_t gfp_flags);
949static int alloc_requests (struct eth_dev *dev, unsigned n, unsigned gfp_flags); 949static int alloc_requests (struct eth_dev *dev, unsigned n, gfp_t gfp_flags);
950 950
951static int 951static int
952set_ether_config (struct eth_dev *dev, unsigned gfp_flags) 952set_ether_config (struct eth_dev *dev, gfp_t gfp_flags)
953{ 953{
954 int result = 0; 954 int result = 0;
955 struct usb_gadget *gadget = dev->gadget; 955 struct usb_gadget *gadget = dev->gadget;
@@ -1081,7 +1081,7 @@ static void eth_reset_config (struct eth_dev *dev)
1081 * that returns config descriptors, and altsetting code. 1081 * that returns config descriptors, and altsetting code.
1082 */ 1082 */
1083static int 1083static int
1084eth_set_config (struct eth_dev *dev, unsigned number, unsigned gfp_flags) 1084eth_set_config (struct eth_dev *dev, unsigned number, gfp_t gfp_flags)
1085{ 1085{
1086 int result = 0; 1086 int result = 0;
1087 struct usb_gadget *gadget = dev->gadget; 1087 struct usb_gadget *gadget = dev->gadget;
@@ -1598,7 +1598,7 @@ static void defer_kevent (struct eth_dev *dev, int flag)
1598static void rx_complete (struct usb_ep *ep, struct usb_request *req); 1598static void rx_complete (struct usb_ep *ep, struct usb_request *req);
1599 1599
1600static int 1600static int
1601rx_submit (struct eth_dev *dev, struct usb_request *req, unsigned gfp_flags) 1601rx_submit (struct eth_dev *dev, struct usb_request *req, gfp_t gfp_flags)
1602{ 1602{
1603 struct sk_buff *skb; 1603 struct sk_buff *skb;
1604 int retval = -ENOMEM; 1604 int retval = -ENOMEM;
@@ -1724,7 +1724,7 @@ clean:
1724} 1724}
1725 1725
1726static int prealloc (struct list_head *list, struct usb_ep *ep, 1726static int prealloc (struct list_head *list, struct usb_ep *ep,
1727 unsigned n, unsigned gfp_flags) 1727 unsigned n, gfp_t gfp_flags)
1728{ 1728{
1729 unsigned i; 1729 unsigned i;
1730 struct usb_request *req; 1730 struct usb_request *req;
@@ -1763,7 +1763,7 @@ extra:
1763 return 0; 1763 return 0;
1764} 1764}
1765 1765
1766static int alloc_requests (struct eth_dev *dev, unsigned n, unsigned gfp_flags) 1766static int alloc_requests (struct eth_dev *dev, unsigned n, gfp_t gfp_flags)
1767{ 1767{
1768 int status; 1768 int status;
1769 1769
@@ -1779,7 +1779,7 @@ fail:
1779 return status; 1779 return status;
1780} 1780}
1781 1781
1782static void rx_fill (struct eth_dev *dev, unsigned gfp_flags) 1782static void rx_fill (struct eth_dev *dev, gfp_t gfp_flags)
1783{ 1783{
1784 struct usb_request *req; 1784 struct usb_request *req;
1785 unsigned long flags; 1785 unsigned long flags;
@@ -1962,7 +1962,7 @@ drop:
1962 * normally just one notification will be queued. 1962 * normally just one notification will be queued.
1963 */ 1963 */
1964 1964
1965static struct usb_request *eth_req_alloc (struct usb_ep *, unsigned, unsigned); 1965static struct usb_request *eth_req_alloc (struct usb_ep *, unsigned, gfp_t);
1966static void eth_req_free (struct usb_ep *ep, struct usb_request *req); 1966static void eth_req_free (struct usb_ep *ep, struct usb_request *req);
1967 1967
1968static void 1968static void
@@ -2024,7 +2024,7 @@ static int rndis_control_ack (struct net_device *net)
2024 2024
2025#endif /* RNDIS */ 2025#endif /* RNDIS */
2026 2026
2027static void eth_start (struct eth_dev *dev, unsigned gfp_flags) 2027static void eth_start (struct eth_dev *dev, gfp_t gfp_flags)
2028{ 2028{
2029 DEBUG (dev, "%s\n", __FUNCTION__); 2029 DEBUG (dev, "%s\n", __FUNCTION__);
2030 2030
@@ -2092,7 +2092,7 @@ static int eth_stop (struct net_device *net)
2092/*-------------------------------------------------------------------------*/ 2092/*-------------------------------------------------------------------------*/
2093 2093
2094static struct usb_request * 2094static struct usb_request *
2095eth_req_alloc (struct usb_ep *ep, unsigned size, unsigned gfp_flags) 2095eth_req_alloc (struct usb_ep *ep, unsigned size, gfp_t gfp_flags)
2096{ 2096{
2097 struct usb_request *req; 2097 struct usb_request *req;
2098 2098
@@ -2533,6 +2533,7 @@ static struct usb_gadget_driver eth_driver = {
2533 2533
2534 .driver = { 2534 .driver = {
2535 .name = (char *) shortname, 2535 .name = (char *) shortname,
2536 .owner = THIS_MODULE,
2536 // .shutdown = ... 2537 // .shutdown = ...
2537 // .suspend = ... 2538 // .suspend = ...
2538 // .resume = ... 2539 // .resume = ...
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index a41d9d4baee3..ea09aaa3cab6 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -224,6 +224,7 @@
224#include <linux/fs.h> 224#include <linux/fs.h>
225#include <linux/init.h> 225#include <linux/init.h>
226#include <linux/kernel.h> 226#include <linux/kernel.h>
227#include <linux/kthread.h>
227#include <linux/limits.h> 228#include <linux/limits.h>
228#include <linux/list.h> 229#include <linux/list.h>
229#include <linux/module.h> 230#include <linux/module.h>
@@ -669,7 +670,6 @@ struct fsg_dev {
669 wait_queue_head_t thread_wqh; 670 wait_queue_head_t thread_wqh;
670 int thread_wakeup_needed; 671 int thread_wakeup_needed;
671 struct completion thread_notifier; 672 struct completion thread_notifier;
672 int thread_pid;
673 struct task_struct *thread_task; 673 struct task_struct *thread_task;
674 sigset_t thread_signal_mask; 674 sigset_t thread_signal_mask;
675 675
@@ -1084,7 +1084,6 @@ static void wakeup_thread(struct fsg_dev *fsg)
1084static void raise_exception(struct fsg_dev *fsg, enum fsg_state new_state) 1084static void raise_exception(struct fsg_dev *fsg, enum fsg_state new_state)
1085{ 1085{
1086 unsigned long flags; 1086 unsigned long flags;
1087 struct task_struct *thread_task;
1088 1087
1089 /* Do nothing if a higher-priority exception is already in progress. 1088 /* Do nothing if a higher-priority exception is already in progress.
1090 * If a lower-or-equal priority exception is in progress, preempt it 1089 * If a lower-or-equal priority exception is in progress, preempt it
@@ -1093,9 +1092,9 @@ static void raise_exception(struct fsg_dev *fsg, enum fsg_state new_state)
1093 if (fsg->state <= new_state) { 1092 if (fsg->state <= new_state) {
1094 fsg->exception_req_tag = fsg->ep0_req_tag; 1093 fsg->exception_req_tag = fsg->ep0_req_tag;
1095 fsg->state = new_state; 1094 fsg->state = new_state;
1096 thread_task = fsg->thread_task; 1095 if (fsg->thread_task)
1097 if (thread_task) 1096 send_sig_info(SIGUSR1, SEND_SIG_FORCED,
1098 send_sig_info(SIGUSR1, SEND_SIG_FORCED, thread_task); 1097 fsg->thread_task);
1099 } 1098 }
1100 spin_unlock_irqrestore(&fsg->lock, flags); 1099 spin_unlock_irqrestore(&fsg->lock, flags);
1101} 1100}
@@ -3383,11 +3382,6 @@ static int fsg_main_thread(void *fsg_)
3383{ 3382{
3384 struct fsg_dev *fsg = (struct fsg_dev *) fsg_; 3383 struct fsg_dev *fsg = (struct fsg_dev *) fsg_;
3385 3384
3386 fsg->thread_task = current;
3387
3388 /* Release all our userspace resources */
3389 daemonize("file-storage-gadget");
3390
3391 /* Allow the thread to be killed by a signal, but set the signal mask 3385 /* Allow the thread to be killed by a signal, but set the signal mask
3392 * to block everything but INT, TERM, KILL, and USR1. */ 3386 * to block everything but INT, TERM, KILL, and USR1. */
3393 siginitsetinv(&fsg->thread_signal_mask, sigmask(SIGINT) | 3387 siginitsetinv(&fsg->thread_signal_mask, sigmask(SIGINT) |
@@ -3400,9 +3394,6 @@ static int fsg_main_thread(void *fsg_)
3400 * that expects a __user pointer and it will work okay. */ 3394 * that expects a __user pointer and it will work okay. */
3401 set_fs(get_ds()); 3395 set_fs(get_ds());
3402 3396
3403 /* Wait for the gadget registration to finish up */
3404 wait_for_completion(&fsg->thread_notifier);
3405
3406 /* The main loop */ 3397 /* The main loop */
3407 while (fsg->state != FSG_STATE_TERMINATED) { 3398 while (fsg->state != FSG_STATE_TERMINATED) {
3408 if (exception_in_progress(fsg) || signal_pending(current)) { 3399 if (exception_in_progress(fsg) || signal_pending(current)) {
@@ -3440,8 +3431,9 @@ static int fsg_main_thread(void *fsg_)
3440 spin_unlock_irq(&fsg->lock); 3431 spin_unlock_irq(&fsg->lock);
3441 } 3432 }
3442 3433
3434 spin_lock_irq(&fsg->lock);
3443 fsg->thread_task = NULL; 3435 fsg->thread_task = NULL;
3444 flush_signals(current); 3436 spin_unlock_irq(&fsg->lock);
3445 3437
3446 /* In case we are exiting because of a signal, unregister the 3438 /* In case we are exiting because of a signal, unregister the
3447 * gadget driver and close the backing file. */ 3439 * gadget driver and close the backing file. */
@@ -3831,12 +3823,11 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3831 3823
3832 /* Create the LUNs, open their backing files, and register the 3824 /* Create the LUNs, open their backing files, and register the
3833 * LUN devices in sysfs. */ 3825 * LUN devices in sysfs. */
3834 fsg->luns = kmalloc(i * sizeof(struct lun), GFP_KERNEL); 3826 fsg->luns = kzalloc(i * sizeof(struct lun), GFP_KERNEL);
3835 if (!fsg->luns) { 3827 if (!fsg->luns) {
3836 rc = -ENOMEM; 3828 rc = -ENOMEM;
3837 goto out; 3829 goto out;
3838 } 3830 }
3839 memset(fsg->luns, 0, i * sizeof(struct lun));
3840 fsg->nluns = i; 3831 fsg->nluns = i;
3841 3832
3842 for (i = 0; i < fsg->nluns; ++i) { 3833 for (i = 0; i < fsg->nluns; ++i) {
@@ -3959,10 +3950,12 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3959 sprintf(&serial[i], "%02X", c); 3950 sprintf(&serial[i], "%02X", c);
3960 } 3951 }
3961 3952
3962 if ((rc = kernel_thread(fsg_main_thread, fsg, (CLONE_VM | CLONE_FS | 3953 fsg->thread_task = kthread_create(fsg_main_thread, fsg,
3963 CLONE_FILES))) < 0) 3954 "file-storage-gadget");
3955 if (IS_ERR(fsg->thread_task)) {
3956 rc = PTR_ERR(fsg->thread_task);
3964 goto out; 3957 goto out;
3965 fsg->thread_pid = rc; 3958 }
3966 3959
3967 INFO(fsg, DRIVER_DESC ", version: " DRIVER_VERSION "\n"); 3960 INFO(fsg, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
3968 INFO(fsg, "Number of LUNs=%d\n", fsg->nluns); 3961 INFO(fsg, "Number of LUNs=%d\n", fsg->nluns);
@@ -3994,7 +3987,12 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3994 DBG(fsg, "removable=%d, stall=%d, buflen=%u\n", 3987 DBG(fsg, "removable=%d, stall=%d, buflen=%u\n",
3995 mod_data.removable, mod_data.can_stall, 3988 mod_data.removable, mod_data.can_stall,
3996 mod_data.buflen); 3989 mod_data.buflen);
3997 DBG(fsg, "I/O thread pid: %d\n", fsg->thread_pid); 3990 DBG(fsg, "I/O thread pid: %d\n", fsg->thread_task->pid);
3991
3992 set_bit(REGISTERED, &fsg->atomic_bitflags);
3993
3994 /* Tell the thread to start working */
3995 wake_up_process(fsg->thread_task);
3998 return 0; 3996 return 0;
3999 3997
4000autoconf_fail: 3998autoconf_fail:
@@ -4046,6 +4044,7 @@ static struct usb_gadget_driver fsg_driver = {
4046 4044
4047 .driver = { 4045 .driver = {
4048 .name = (char *) shortname, 4046 .name = (char *) shortname,
4047 .owner = THIS_MODULE,
4049 // .release = ... 4048 // .release = ...
4050 // .suspend = ... 4049 // .suspend = ...
4051 // .resume = ... 4050 // .resume = ...
@@ -4057,10 +4056,9 @@ static int __init fsg_alloc(void)
4057{ 4056{
4058 struct fsg_dev *fsg; 4057 struct fsg_dev *fsg;
4059 4058
4060 fsg = kmalloc(sizeof *fsg, GFP_KERNEL); 4059 fsg = kzalloc(sizeof *fsg, GFP_KERNEL);
4061 if (!fsg) 4060 if (!fsg)
4062 return -ENOMEM; 4061 return -ENOMEM;
4063 memset(fsg, 0, sizeof *fsg);
4064 spin_lock_init(&fsg->lock); 4062 spin_lock_init(&fsg->lock);
4065 init_rwsem(&fsg->filesem); 4063 init_rwsem(&fsg->filesem);
4066 init_waitqueue_head(&fsg->thread_wqh); 4064 init_waitqueue_head(&fsg->thread_wqh);
@@ -4086,15 +4084,9 @@ static int __init fsg_init(void)
4086 if ((rc = fsg_alloc()) != 0) 4084 if ((rc = fsg_alloc()) != 0)
4087 return rc; 4085 return rc;
4088 fsg = the_fsg; 4086 fsg = the_fsg;
4089 if ((rc = usb_gadget_register_driver(&fsg_driver)) != 0) { 4087 if ((rc = usb_gadget_register_driver(&fsg_driver)) != 0)
4090 fsg_free(fsg); 4088 fsg_free(fsg);
4091 return rc; 4089 return rc;
4092 }
4093 set_bit(REGISTERED, &fsg->atomic_bitflags);
4094
4095 /* Tell the thread to start working */
4096 complete(&fsg->thread_notifier);
4097 return 0;
4098} 4090}
4099module_init(fsg_init); 4091module_init(fsg_init);
4100 4092
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index eaab26f4ed37..654469778ab5 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -269,7 +269,7 @@ static int goku_ep_disable(struct usb_ep *_ep)
269/*-------------------------------------------------------------------------*/ 269/*-------------------------------------------------------------------------*/
270 270
271static struct usb_request * 271static struct usb_request *
272goku_alloc_request(struct usb_ep *_ep, unsigned gfp_flags) 272goku_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
273{ 273{
274 struct goku_request *req; 274 struct goku_request *req;
275 275
@@ -327,7 +327,7 @@ goku_free_request(struct usb_ep *_ep, struct usb_request *_req)
327 */ 327 */
328static void * 328static void *
329goku_alloc_buffer(struct usb_ep *_ep, unsigned bytes, 329goku_alloc_buffer(struct usb_ep *_ep, unsigned bytes,
330 dma_addr_t *dma, unsigned gfp_flags) 330 dma_addr_t *dma, gfp_t gfp_flags)
331{ 331{
332 void *retval; 332 void *retval;
333 struct goku_ep *ep; 333 struct goku_ep *ep;
@@ -789,7 +789,7 @@ finished:
789/*-------------------------------------------------------------------------*/ 789/*-------------------------------------------------------------------------*/
790 790
791static int 791static int
792goku_queue(struct usb_ep *_ep, struct usb_request *_req, unsigned gfp_flags) 792goku_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
793{ 793{
794 struct goku_request *req; 794 struct goku_request *req;
795 struct goku_ep *ep; 795 struct goku_ep *ep;
@@ -1970,6 +1970,7 @@ MODULE_DEVICE_TABLE (pci, pci_ids);
1970static struct pci_driver goku_pci_driver = { 1970static struct pci_driver goku_pci_driver = {
1971 .name = (char *) driver_name, 1971 .name = (char *) driver_name,
1972 .id_table = pci_ids, 1972 .id_table = pci_ids,
1973 .owner = THIS_MODULE,
1973 1974
1974 .probe = goku_probe, 1975 .probe = goku_probe,
1975 .remove = goku_remove, 1976 .remove = goku_remove,
diff --git a/drivers/usb/gadget/lh7a40x_udc.c b/drivers/usb/gadget/lh7a40x_udc.c
index 4842577789c9..9b3673904daf 100644
--- a/drivers/usb/gadget/lh7a40x_udc.c
+++ b/drivers/usb/gadget/lh7a40x_udc.c
@@ -71,13 +71,13 @@ static char *state_names[] = {
71static int lh7a40x_ep_enable(struct usb_ep *ep, 71static int lh7a40x_ep_enable(struct usb_ep *ep,
72 const struct usb_endpoint_descriptor *); 72 const struct usb_endpoint_descriptor *);
73static int lh7a40x_ep_disable(struct usb_ep *ep); 73static int lh7a40x_ep_disable(struct usb_ep *ep);
74static struct usb_request *lh7a40x_alloc_request(struct usb_ep *ep, int); 74static struct usb_request *lh7a40x_alloc_request(struct usb_ep *ep, gfp_t);
75static void lh7a40x_free_request(struct usb_ep *ep, struct usb_request *); 75static void lh7a40x_free_request(struct usb_ep *ep, struct usb_request *);
76static void *lh7a40x_alloc_buffer(struct usb_ep *ep, unsigned, dma_addr_t *, 76static void *lh7a40x_alloc_buffer(struct usb_ep *ep, unsigned, dma_addr_t *,
77 int); 77 gfp_t);
78static void lh7a40x_free_buffer(struct usb_ep *ep, void *, dma_addr_t, 78static void lh7a40x_free_buffer(struct usb_ep *ep, void *, dma_addr_t,
79 unsigned); 79 unsigned);
80static int lh7a40x_queue(struct usb_ep *ep, struct usb_request *, int); 80static int lh7a40x_queue(struct usb_ep *ep, struct usb_request *, gfp_t);
81static int lh7a40x_dequeue(struct usb_ep *ep, struct usb_request *); 81static int lh7a40x_dequeue(struct usb_ep *ep, struct usb_request *);
82static int lh7a40x_set_halt(struct usb_ep *ep, int); 82static int lh7a40x_set_halt(struct usb_ep *ep, int);
83static int lh7a40x_fifo_status(struct usb_ep *ep); 83static int lh7a40x_fifo_status(struct usb_ep *ep);
@@ -1106,7 +1106,7 @@ static int lh7a40x_ep_disable(struct usb_ep *_ep)
1106} 1106}
1107 1107
1108static struct usb_request *lh7a40x_alloc_request(struct usb_ep *ep, 1108static struct usb_request *lh7a40x_alloc_request(struct usb_ep *ep,
1109 unsigned gfp_flags) 1109 gfp_t gfp_flags)
1110{ 1110{
1111 struct lh7a40x_request *req; 1111 struct lh7a40x_request *req;
1112 1112
@@ -1134,7 +1134,7 @@ static void lh7a40x_free_request(struct usb_ep *ep, struct usb_request *_req)
1134} 1134}
1135 1135
1136static void *lh7a40x_alloc_buffer(struct usb_ep *ep, unsigned bytes, 1136static void *lh7a40x_alloc_buffer(struct usb_ep *ep, unsigned bytes,
1137 dma_addr_t * dma, unsigned gfp_flags) 1137 dma_addr_t * dma, gfp_t gfp_flags)
1138{ 1138{
1139 char *retval; 1139 char *retval;
1140 1140
@@ -1158,7 +1158,7 @@ static void lh7a40x_free_buffer(struct usb_ep *ep, void *buf, dma_addr_t dma,
1158 * NOTE: Sets INDEX register 1158 * NOTE: Sets INDEX register
1159 */ 1159 */
1160static int lh7a40x_queue(struct usb_ep *_ep, struct usb_request *_req, 1160static int lh7a40x_queue(struct usb_ep *_ep, struct usb_request *_req,
1161 unsigned gfp_flags) 1161 gfp_t gfp_flags)
1162{ 1162{
1163 struct lh7a40x_request *req; 1163 struct lh7a40x_request *req;
1164 struct lh7a40x_ep *ep; 1164 struct lh7a40x_ep *ep;
@@ -2140,6 +2140,7 @@ static int lh7a40x_udc_remove(struct device *_dev)
2140 2140
2141static struct device_driver udc_driver = { 2141static struct device_driver udc_driver = {
2142 .name = (char *)driver_name, 2142 .name = (char *)driver_name,
2143 .owner = THIS_MODULE,
2143 .bus = &platform_bus_type, 2144 .bus = &platform_bus_type,
2144 .probe = lh7a40x_udc_probe, 2145 .probe = lh7a40x_udc_probe,
2145 .remove = lh7a40x_udc_remove 2146 .remove = lh7a40x_udc_remove
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index 477fab2e74d1..0dc6bb00bf72 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -376,7 +376,7 @@ static int net2280_disable (struct usb_ep *_ep)
376/*-------------------------------------------------------------------------*/ 376/*-------------------------------------------------------------------------*/
377 377
378static struct usb_request * 378static struct usb_request *
379net2280_alloc_request (struct usb_ep *_ep, unsigned gfp_flags) 379net2280_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags)
380{ 380{
381 struct net2280_ep *ep; 381 struct net2280_ep *ep;
382 struct net2280_request *req; 382 struct net2280_request *req;
@@ -463,7 +463,7 @@ net2280_alloc_buffer (
463 struct usb_ep *_ep, 463 struct usb_ep *_ep,
464 unsigned bytes, 464 unsigned bytes,
465 dma_addr_t *dma, 465 dma_addr_t *dma,
466 unsigned gfp_flags 466 gfp_t gfp_flags
467) 467)
468{ 468{
469 void *retval; 469 void *retval;
@@ -897,7 +897,7 @@ done (struct net2280_ep *ep, struct net2280_request *req, int status)
897/*-------------------------------------------------------------------------*/ 897/*-------------------------------------------------------------------------*/
898 898
899static int 899static int
900net2280_queue (struct usb_ep *_ep, struct usb_request *_req, unsigned gfp_flags) 900net2280_queue (struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
901{ 901{
902 struct net2280_request *req; 902 struct net2280_request *req;
903 struct net2280_ep *ep; 903 struct net2280_ep *ep;
@@ -2948,6 +2948,7 @@ MODULE_DEVICE_TABLE (pci, pci_ids);
2948static struct pci_driver net2280_pci_driver = { 2948static struct pci_driver net2280_pci_driver = {
2949 .name = (char *) driver_name, 2949 .name = (char *) driver_name,
2950 .id_table = pci_ids, 2950 .id_table = pci_ids,
2951 .owner = THIS_MODULE,
2951 2952
2952 .probe = net2280_probe, 2953 .probe = net2280_probe,
2953 .remove = net2280_remove, 2954 .remove = net2280_remove,
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index ff5533e69560..41c96b0afbb3 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -269,7 +269,7 @@ static int omap_ep_disable(struct usb_ep *_ep)
269/*-------------------------------------------------------------------------*/ 269/*-------------------------------------------------------------------------*/
270 270
271static struct usb_request * 271static struct usb_request *
272omap_alloc_request(struct usb_ep *ep, unsigned gfp_flags) 272omap_alloc_request(struct usb_ep *ep, gfp_t gfp_flags)
273{ 273{
274 struct omap_req *req; 274 struct omap_req *req;
275 275
@@ -298,7 +298,7 @@ omap_alloc_buffer(
298 struct usb_ep *_ep, 298 struct usb_ep *_ep,
299 unsigned bytes, 299 unsigned bytes,
300 dma_addr_t *dma, 300 dma_addr_t *dma,
301 unsigned gfp_flags 301 gfp_t gfp_flags
302) 302)
303{ 303{
304 void *retval; 304 void *retval;
@@ -691,7 +691,7 @@ static void next_out_dma(struct omap_ep *ep, struct omap_req *req)
691} 691}
692 692
693static void 693static void
694finish_out_dma(struct omap_ep *ep, struct omap_req *req, int status) 694finish_out_dma(struct omap_ep *ep, struct omap_req *req, int status, int one)
695{ 695{
696 u16 count; 696 u16 count;
697 697
@@ -699,6 +699,8 @@ finish_out_dma(struct omap_ep *ep, struct omap_req *req, int status)
699 ep->dma_counter = (u16) (req->req.dma + req->req.actual); 699 ep->dma_counter = (u16) (req->req.dma + req->req.actual);
700 count = dma_dest_len(ep, req->req.dma + req->req.actual); 700 count = dma_dest_len(ep, req->req.dma + req->req.actual);
701 count += req->req.actual; 701 count += req->req.actual;
702 if (one)
703 count--;
702 if (count <= req->req.length) 704 if (count <= req->req.length)
703 req->req.actual = count; 705 req->req.actual = count;
704 706
@@ -747,7 +749,7 @@ static void dma_irq(struct omap_udc *udc, u16 irq_src)
747 if (!list_empty(&ep->queue)) { 749 if (!list_empty(&ep->queue)) {
748 req = container_of(ep->queue.next, 750 req = container_of(ep->queue.next,
749 struct omap_req, queue); 751 struct omap_req, queue);
750 finish_out_dma(ep, req, 0); 752 finish_out_dma(ep, req, 0, dman_stat & UDC_DMA_RX_SB);
751 } 753 }
752 UDC_IRQ_SRC_REG = UDC_RXN_EOT; 754 UDC_IRQ_SRC_REG = UDC_RXN_EOT;
753 755
@@ -925,7 +927,7 @@ static void dma_channel_release(struct omap_ep *ep)
925 while (UDC_RXDMA_CFG_REG & mask) 927 while (UDC_RXDMA_CFG_REG & mask)
926 udelay(10); 928 udelay(10);
927 if (req) 929 if (req)
928 finish_out_dma(ep, req, -ECONNRESET); 930 finish_out_dma(ep, req, -ECONNRESET, 0);
929 } 931 }
930 omap_free_dma(ep->lch); 932 omap_free_dma(ep->lch);
931 ep->dma_channel = 0; 933 ep->dma_channel = 0;
@@ -937,7 +939,7 @@ static void dma_channel_release(struct omap_ep *ep)
937/*-------------------------------------------------------------------------*/ 939/*-------------------------------------------------------------------------*/
938 940
939static int 941static int
940omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, unsigned gfp_flags) 942omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
941{ 943{
942 struct omap_ep *ep = container_of(_ep, struct omap_ep, ep); 944 struct omap_ep *ep = container_of(_ep, struct omap_ep, ep);
943 struct omap_req *req = container_of(_req, struct omap_req, req); 945 struct omap_req *req = container_of(_req, struct omap_req, req);
@@ -1786,8 +1788,12 @@ static void devstate_irq(struct omap_udc *udc, u16 irq_src)
1786 udc->driver->suspend(&udc->gadget); 1788 udc->driver->suspend(&udc->gadget);
1787 spin_lock(&udc->lock); 1789 spin_lock(&udc->lock);
1788 } 1790 }
1791 if (udc->transceiver)
1792 otg_set_suspend(udc->transceiver, 1);
1789 } else { 1793 } else {
1790 VDBG("resume\n"); 1794 VDBG("resume\n");
1795 if (udc->transceiver)
1796 otg_set_suspend(udc->transceiver, 0);
1791 if (udc->gadget.speed == USB_SPEED_FULL 1797 if (udc->gadget.speed == USB_SPEED_FULL
1792 && udc->driver->resume) { 1798 && udc->driver->resume) {
1793 spin_unlock(&udc->lock); 1799 spin_unlock(&udc->lock);
@@ -2909,12 +2915,10 @@ static int __exit omap_udc_remove(struct device *dev)
2909 * may involve talking to an external transceiver (e.g. isp1301). 2915 * may involve talking to an external transceiver (e.g. isp1301).
2910 */ 2916 */
2911 2917
2912static int omap_udc_suspend(struct device *dev, pm_message_t message, u32 level) 2918static int omap_udc_suspend(struct device *dev, pm_message_t message)
2913{ 2919{
2914 u32 devstat; 2920 u32 devstat;
2915 2921
2916 if (level != SUSPEND_POWER_DOWN)
2917 return 0;
2918 devstat = UDC_DEVSTAT_REG; 2922 devstat = UDC_DEVSTAT_REG;
2919 2923
2920 /* we're requesting 48 MHz clock if the pullup is enabled 2924 /* we're requesting 48 MHz clock if the pullup is enabled
@@ -2931,11 +2935,8 @@ static int omap_udc_suspend(struct device *dev, pm_message_t message, u32 level)
2931 return 0; 2935 return 0;
2932} 2936}
2933 2937
2934static int omap_udc_resume(struct device *dev, u32 level) 2938static int omap_udc_resume(struct device *dev)
2935{ 2939{
2936 if (level != RESUME_POWER_ON)
2937 return 0;
2938
2939 DBG("resume + wakeup/SRP\n"); 2940 DBG("resume + wakeup/SRP\n");
2940 omap_pullup(&udc->gadget, 1); 2941 omap_pullup(&udc->gadget, 1);
2941 2942
@@ -2948,6 +2949,7 @@ static int omap_udc_resume(struct device *dev, u32 level)
2948 2949
2949static struct device_driver udc_driver = { 2950static struct device_driver udc_driver = {
2950 .name = (char *) driver_name, 2951 .name = (char *) driver_name,
2952 .owner = THIS_MODULE,
2951 .bus = &platform_bus_type, 2953 .bus = &platform_bus_type,
2952 .probe = omap_udc_probe, 2954 .probe = omap_udc_probe,
2953 .remove = __exit_p(omap_udc_remove), 2955 .remove = __exit_p(omap_udc_remove),
diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c
index 73f8c9404156..f83a9262f953 100644
--- a/drivers/usb/gadget/pxa2xx_udc.c
+++ b/drivers/usb/gadget/pxa2xx_udc.c
@@ -332,7 +332,7 @@ static int pxa2xx_ep_disable (struct usb_ep *_ep)
332 * pxa2xx_ep_alloc_request - allocate a request data structure 332 * pxa2xx_ep_alloc_request - allocate a request data structure
333 */ 333 */
334static struct usb_request * 334static struct usb_request *
335pxa2xx_ep_alloc_request (struct usb_ep *_ep, unsigned gfp_flags) 335pxa2xx_ep_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags)
336{ 336{
337 struct pxa2xx_request *req; 337 struct pxa2xx_request *req;
338 338
@@ -367,7 +367,7 @@ pxa2xx_ep_free_request (struct usb_ep *_ep, struct usb_request *_req)
367 */ 367 */
368static void * 368static void *
369pxa2xx_ep_alloc_buffer(struct usb_ep *_ep, unsigned bytes, 369pxa2xx_ep_alloc_buffer(struct usb_ep *_ep, unsigned bytes,
370 dma_addr_t *dma, unsigned gfp_flags) 370 dma_addr_t *dma, gfp_t gfp_flags)
371{ 371{
372 char *retval; 372 char *retval;
373 373
@@ -422,7 +422,7 @@ static inline void ep0_idle (struct pxa2xx_udc *dev)
422} 422}
423 423
424static int 424static int
425write_packet(volatile unsigned long *uddr, struct pxa2xx_request *req, unsigned max) 425write_packet(volatile u32 *uddr, struct pxa2xx_request *req, unsigned max)
426{ 426{
427 u8 *buf; 427 u8 *buf;
428 unsigned length, count; 428 unsigned length, count;
@@ -874,7 +874,7 @@ done:
874/*-------------------------------------------------------------------------*/ 874/*-------------------------------------------------------------------------*/
875 875
876static int 876static int
877pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, unsigned gfp_flags) 877pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
878{ 878{
879 struct pxa2xx_request *req; 879 struct pxa2xx_request *req;
880 struct pxa2xx_ep *ep; 880 struct pxa2xx_ep *ep;
@@ -2602,24 +2602,23 @@ static int __exit pxa2xx_udc_remove(struct device *_dev)
2602 * VBUS IRQs should probably be ignored so that the PXA device just acts 2602 * VBUS IRQs should probably be ignored so that the PXA device just acts
2603 * "dead" to USB hosts until system resume. 2603 * "dead" to USB hosts until system resume.
2604 */ 2604 */
2605static int pxa2xx_udc_suspend(struct device *dev, pm_message_t state, u32 level) 2605static int pxa2xx_udc_suspend(struct device *dev, pm_message_t state)
2606{ 2606{
2607 struct pxa2xx_udc *udc = dev_get_drvdata(dev); 2607 struct pxa2xx_udc *udc = dev_get_drvdata(dev);
2608 2608
2609 if (level == SUSPEND_POWER_DOWN) { 2609 if (!udc->mach->udc_command)
2610 if (!udc->mach->udc_command) 2610 WARN("USB host won't detect disconnect!\n");
2611 WARN("USB host won't detect disconnect!\n"); 2611 pullup(udc, 0);
2612 pullup(udc, 0); 2612
2613 }
2614 return 0; 2613 return 0;
2615} 2614}
2616 2615
2617static int pxa2xx_udc_resume(struct device *dev, u32 level) 2616static int pxa2xx_udc_resume(struct device *dev)
2618{ 2617{
2619 struct pxa2xx_udc *udc = dev_get_drvdata(dev); 2618 struct pxa2xx_udc *udc = dev_get_drvdata(dev);
2620 2619
2621 if (level == RESUME_POWER_ON) 2620 pullup(udc, 1);
2622 pullup(udc, 1); 2621
2623 return 0; 2622 return 0;
2624} 2623}
2625 2624
@@ -2632,6 +2631,7 @@ static int pxa2xx_udc_resume(struct device *dev, u32 level)
2632 2631
2633static struct device_driver udc_driver = { 2632static struct device_driver udc_driver = {
2634 .name = "pxa2xx-udc", 2633 .name = "pxa2xx-udc",
2634 .owner = THIS_MODULE,
2635 .bus = &platform_bus_type, 2635 .bus = &platform_bus_type,
2636 .probe = pxa2xx_udc_probe, 2636 .probe = pxa2xx_udc_probe,
2637 .shutdown = pxa2xx_udc_shutdown, 2637 .shutdown = pxa2xx_udc_shutdown,
diff --git a/drivers/usb/gadget/pxa2xx_udc.h b/drivers/usb/gadget/pxa2xx_udc.h
index a58f3e6e71f1..19a883f7d1b8 100644
--- a/drivers/usb/gadget/pxa2xx_udc.h
+++ b/drivers/usb/gadget/pxa2xx_udc.h
@@ -69,11 +69,11 @@ struct pxa2xx_ep {
69 * UDDR = UDC Endpoint Data Register (the fifo) 69 * UDDR = UDC Endpoint Data Register (the fifo)
70 * DRCM = DMA Request Channel Map 70 * DRCM = DMA Request Channel Map
71 */ 71 */
72 volatile unsigned long *reg_udccs; 72 volatile u32 *reg_udccs;
73 volatile unsigned long *reg_ubcr; 73 volatile u32 *reg_ubcr;
74 volatile unsigned long *reg_uddr; 74 volatile u32 *reg_uddr;
75#ifdef USE_DMA 75#ifdef USE_DMA
76 volatile unsigned long *reg_drcmr; 76 volatile u32 *reg_drcmr;
77#define drcmr(n) .reg_drcmr = & DRCMR ## n , 77#define drcmr(n) .reg_drcmr = & DRCMR ## n ,
78#else 78#else
79#define drcmr(n) 79#define drcmr(n)
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index c925d9222f53..b35ac6d334f8 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -300,18 +300,18 @@ static int gs_build_config_buf(u8 *buf, enum usb_device_speed speed,
300 u8 type, unsigned int index, int is_otg); 300 u8 type, unsigned int index, int is_otg);
301 301
302static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len, 302static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len,
303 unsigned kmalloc_flags); 303 gfp_t kmalloc_flags);
304static void gs_free_req(struct usb_ep *ep, struct usb_request *req); 304static void gs_free_req(struct usb_ep *ep, struct usb_request *req);
305 305
306static struct gs_req_entry *gs_alloc_req_entry(struct usb_ep *ep, unsigned len, 306static struct gs_req_entry *gs_alloc_req_entry(struct usb_ep *ep, unsigned len,
307 unsigned kmalloc_flags); 307 gfp_t kmalloc_flags);
308static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req); 308static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req);
309 309
310static int gs_alloc_ports(struct gs_dev *dev, unsigned kmalloc_flags); 310static int gs_alloc_ports(struct gs_dev *dev, gfp_t kmalloc_flags);
311static void gs_free_ports(struct gs_dev *dev); 311static void gs_free_ports(struct gs_dev *dev);
312 312
313/* circular buffer */ 313/* circular buffer */
314static struct gs_buf *gs_buf_alloc(unsigned int size, unsigned kmalloc_flags); 314static struct gs_buf *gs_buf_alloc(unsigned int size, gfp_t kmalloc_flags);
315static void gs_buf_free(struct gs_buf *gb); 315static void gs_buf_free(struct gs_buf *gb);
316static void gs_buf_clear(struct gs_buf *gb); 316static void gs_buf_clear(struct gs_buf *gb);
317static unsigned int gs_buf_data_avail(struct gs_buf *gb); 317static unsigned int gs_buf_data_avail(struct gs_buf *gb);
@@ -2091,7 +2091,7 @@ static int gs_build_config_buf(u8 *buf, enum usb_device_speed speed,
2091 * usb_request or NULL if there is an error. 2091 * usb_request or NULL if there is an error.
2092 */ 2092 */
2093static struct usb_request * 2093static struct usb_request *
2094gs_alloc_req(struct usb_ep *ep, unsigned int len, unsigned kmalloc_flags) 2094gs_alloc_req(struct usb_ep *ep, unsigned int len, gfp_t kmalloc_flags)
2095{ 2095{
2096 struct usb_request *req; 2096 struct usb_request *req;
2097 2097
@@ -2132,7 +2132,7 @@ static void gs_free_req(struct usb_ep *ep, struct usb_request *req)
2132 * endpoint, buffer len, and kmalloc flags. 2132 * endpoint, buffer len, and kmalloc flags.
2133 */ 2133 */
2134static struct gs_req_entry * 2134static struct gs_req_entry *
2135gs_alloc_req_entry(struct usb_ep *ep, unsigned len, unsigned kmalloc_flags) 2135gs_alloc_req_entry(struct usb_ep *ep, unsigned len, gfp_t kmalloc_flags)
2136{ 2136{
2137 struct gs_req_entry *req; 2137 struct gs_req_entry *req;
2138 2138
@@ -2173,7 +2173,7 @@ static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req)
2173 * 2173 *
2174 * The device lock is normally held when calling this function. 2174 * The device lock is normally held when calling this function.
2175 */ 2175 */
2176static int gs_alloc_ports(struct gs_dev *dev, unsigned kmalloc_flags) 2176static int gs_alloc_ports(struct gs_dev *dev, gfp_t kmalloc_flags)
2177{ 2177{
2178 int i; 2178 int i;
2179 struct gs_port *port; 2179 struct gs_port *port;
@@ -2255,7 +2255,7 @@ static void gs_free_ports(struct gs_dev *dev)
2255 * 2255 *
2256 * Allocate a circular buffer and all associated memory. 2256 * Allocate a circular buffer and all associated memory.
2257 */ 2257 */
2258static struct gs_buf *gs_buf_alloc(unsigned int size, unsigned kmalloc_flags) 2258static struct gs_buf *gs_buf_alloc(unsigned int size, gfp_t kmalloc_flags)
2259{ 2259{
2260 struct gs_buf *gb; 2260 struct gs_buf *gb;
2261 2261
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 6890e773b2a2..6c58636e914b 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -612,7 +612,7 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req)
612} 612}
613 613
614static struct usb_request * 614static struct usb_request *
615source_sink_start_ep (struct usb_ep *ep, unsigned gfp_flags) 615source_sink_start_ep (struct usb_ep *ep, gfp_t gfp_flags)
616{ 616{
617 struct usb_request *req; 617 struct usb_request *req;
618 int status; 618 int status;
@@ -640,7 +640,7 @@ source_sink_start_ep (struct usb_ep *ep, unsigned gfp_flags)
640} 640}
641 641
642static int 642static int
643set_source_sink_config (struct zero_dev *dev, unsigned gfp_flags) 643set_source_sink_config (struct zero_dev *dev, gfp_t gfp_flags)
644{ 644{
645 int result = 0; 645 int result = 0;
646 struct usb_ep *ep; 646 struct usb_ep *ep;
@@ -744,7 +744,7 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req)
744} 744}
745 745
746static int 746static int
747set_loopback_config (struct zero_dev *dev, unsigned gfp_flags) 747set_loopback_config (struct zero_dev *dev, gfp_t gfp_flags)
748{ 748{
749 int result = 0; 749 int result = 0;
750 struct usb_ep *ep; 750 struct usb_ep *ep;
@@ -845,7 +845,7 @@ static void zero_reset_config (struct zero_dev *dev)
845 * by limiting configuration choices (like the pxa2xx). 845 * by limiting configuration choices (like the pxa2xx).
846 */ 846 */
847static int 847static int
848zero_set_config (struct zero_dev *dev, unsigned number, unsigned gfp_flags) 848zero_set_config (struct zero_dev *dev, unsigned number, gfp_t gfp_flags)
849{ 849{
850 int result = 0; 850 int result = 0;
851 struct usb_gadget *gadget = dev->gadget; 851 struct usb_gadget *gadget = dev->gadget;
@@ -1302,6 +1302,7 @@ static struct usb_gadget_driver zero_driver = {
1302 1302
1303 .driver = { 1303 .driver = {
1304 .name = (char *) shortname, 1304 .name = (char *) shortname,
1305 .owner = THIS_MODULE,
1305 // .shutdown = ... 1306 // .shutdown = ...
1306 // .suspend = ... 1307 // .suspend = ...
1307 // .resume = ... 1308 // .resume = ...
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 350d14fc1cc9..58321d3f314c 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -1,8 +1,9 @@
1# 1#
2# Makefile for USB Host Controller Driver 2# Makefile for USB Host Controller Drivers
3# framework and drivers
4# 3#
5 4
5obj-$(CONFIG_PCI) += pci-quirks.o
6
6obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o 7obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o
7obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o 8obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o
8obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o 9obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index b948ffd94f45..af3c05eb86fc 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -182,6 +182,9 @@ static int ehci_halt (struct ehci_hcd *ehci)
182{ 182{
183 u32 temp = readl (&ehci->regs->status); 183 u32 temp = readl (&ehci->regs->status);
184 184
185 /* disable any irqs left enabled by previous code */
186 writel (0, &ehci->regs->intr_enable);
187
185 if ((temp & STS_HALT) != 0) 188 if ((temp & STS_HALT) != 0)
186 return 0; 189 return 0;
187 190
@@ -297,50 +300,17 @@ static void ehci_watchdog (unsigned long param)
297 spin_unlock_irqrestore (&ehci->lock, flags); 300 spin_unlock_irqrestore (&ehci->lock, flags);
298} 301}
299 302
300#ifdef CONFIG_PCI 303/* Reboot notifiers kick in for silicon on any bus (not just pci, etc).
301 304 * This forcibly disables dma and IRQs, helping kexec and other cases
302/* EHCI 0.96 (and later) section 5.1 says how to kick BIOS/SMM/... 305 * where the next system software may expect clean state.
303 * off the controller (maybe it can boot from highspeed USB disks).
304 */ 306 */
305static int bios_handoff (struct ehci_hcd *ehci, int where, u32 cap)
306{
307 struct pci_dev *pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller);
308
309 /* always say Linux will own the hardware */
310 pci_write_config_byte(pdev, where + 3, 1);
311
312 /* maybe wait a while for BIOS to respond */
313 if (cap & (1 << 16)) {
314 int msec = 5000;
315
316 do {
317 msleep(10);
318 msec -= 10;
319 pci_read_config_dword(pdev, where, &cap);
320 } while ((cap & (1 << 16)) && msec);
321 if (cap & (1 << 16)) {
322 ehci_err(ehci, "BIOS handoff failed (%d, %08x)\n",
323 where, cap);
324 // some BIOS versions seem buggy...
325 // return 1;
326 ehci_warn (ehci, "continuing after BIOS bug...\n");
327 /* disable all SMIs, and clear "BIOS owns" flag */
328 pci_write_config_dword(pdev, where + 4, 0);
329 pci_write_config_byte(pdev, where + 2, 0);
330 } else
331 ehci_dbg(ehci, "BIOS handoff succeeded\n");
332 }
333 return 0;
334}
335
336#endif
337
338static int 307static int
339ehci_reboot (struct notifier_block *self, unsigned long code, void *null) 308ehci_reboot (struct notifier_block *self, unsigned long code, void *null)
340{ 309{
341 struct ehci_hcd *ehci; 310 struct ehci_hcd *ehci;
342 311
343 ehci = container_of (self, struct ehci_hcd, reboot_notifier); 312 ehci = container_of (self, struct ehci_hcd, reboot_notifier);
313 (void) ehci_halt (ehci);
344 314
345 /* make BIOS/etc use companion controller during reboot */ 315 /* make BIOS/etc use companion controller during reboot */
346 writel (0, &ehci->regs->configured_flag); 316 writel (0, &ehci->regs->configured_flag);
@@ -363,156 +333,90 @@ static void ehci_port_power (struct ehci_hcd *ehci, int is_on)
363 msleep(20); 333 msleep(20);
364} 334}
365 335
336/*-------------------------------------------------------------------------*/
337
338/*
339 * ehci_work is called from some interrupts, timers, and so on.
340 * it calls driver completion functions, after dropping ehci->lock.
341 */
342static void ehci_work (struct ehci_hcd *ehci, struct pt_regs *regs)
343{
344 timer_action_done (ehci, TIMER_IO_WATCHDOG);
345 if (ehci->reclaim_ready)
346 end_unlink_async (ehci, regs);
347
348 /* another CPU may drop ehci->lock during a schedule scan while
349 * it reports urb completions. this flag guards against bogus
350 * attempts at re-entrant schedule scanning.
351 */
352 if (ehci->scanning)
353 return;
354 ehci->scanning = 1;
355 scan_async (ehci, regs);
356 if (ehci->next_uframe != -1)
357 scan_periodic (ehci, regs);
358 ehci->scanning = 0;
366 359
367/* called by khubd or root hub init threads */ 360 /* the IO watchdog guards against hardware or driver bugs that
361 * misplace IRQs, and should let us run completely without IRQs.
362 * such lossage has been observed on both VT6202 and VT8235.
363 */
364 if (HC_IS_RUNNING (ehci_to_hcd(ehci)->state) &&
365 (ehci->async->qh_next.ptr != NULL ||
366 ehci->periodic_sched != 0))
367 timer_action (ehci, TIMER_IO_WATCHDOG);
368}
368 369
369static int ehci_hc_reset (struct usb_hcd *hcd) 370static void ehci_stop (struct usb_hcd *hcd)
370{ 371{
371 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 372 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
372 u32 temp;
373 unsigned count = 256/4;
374 373
375 spin_lock_init (&ehci->lock); 374 ehci_dbg (ehci, "stop\n");
376 375
377 ehci->caps = hcd->regs; 376 /* Turn off port power on all root hub ports. */
378 ehci->regs = hcd->regs + HC_LENGTH (readl (&ehci->caps->hc_capbase)); 377 ehci_port_power (ehci, 0);
379 dbg_hcs_params (ehci, "reset");
380 dbg_hcc_params (ehci, "reset");
381 378
382 /* cache this readonly data; minimize chip reads */ 379 /* no more interrupts ... */
383 ehci->hcs_params = readl (&ehci->caps->hcs_params); 380 del_timer_sync (&ehci->watchdog);
384 381
385#ifdef CONFIG_PCI 382 spin_lock_irq(&ehci->lock);
386 if (hcd->self.controller->bus == &pci_bus_type) { 383 if (HC_IS_RUNNING (hcd->state))
387 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 384 ehci_quiesce (ehci);
388 385
389 switch (pdev->vendor) { 386 ehci_reset (ehci);
390 case PCI_VENDOR_ID_TDI: 387 writel (0, &ehci->regs->intr_enable);
391 if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) { 388 spin_unlock_irq(&ehci->lock);
392 ehci->is_tdi_rh_tt = 1;
393 tdi_reset (ehci);
394 }
395 break;
396 case PCI_VENDOR_ID_AMD:
397 /* AMD8111 EHCI doesn't work, according to AMD errata */
398 if (pdev->device == 0x7463) {
399 ehci_info (ehci, "ignoring AMD8111 (errata)\n");
400 return -EIO;
401 }
402 break;
403 case PCI_VENDOR_ID_NVIDIA:
404 /* NVidia reports that certain chips don't handle
405 * QH, ITD, or SITD addresses above 2GB. (But TD,
406 * data buffer, and periodic schedule are normal.)
407 */
408 switch (pdev->device) {
409 case 0x003c: /* MCP04 */
410 case 0x005b: /* CK804 */
411 case 0x00d8: /* CK8 */
412 case 0x00e8: /* CK8S */
413 if (pci_set_consistent_dma_mask(pdev,
414 DMA_31BIT_MASK) < 0)
415 ehci_warn (ehci, "can't enable NVidia "
416 "workaround for >2GB RAM\n");
417 break;
418 }
419 break;
420 }
421 389
422 /* optional debug port, normally in the first BAR */ 390 /* let companion controllers work when we aren't */
423 temp = pci_find_capability (pdev, 0x0a); 391 writel (0, &ehci->regs->configured_flag);
424 if (temp) { 392 unregister_reboot_notifier (&ehci->reboot_notifier);
425 pci_read_config_dword(pdev, temp, &temp);
426 temp >>= 16;
427 if ((temp & (3 << 13)) == (1 << 13)) {
428 temp &= 0x1fff;
429 ehci->debug = hcd->regs + temp;
430 temp = readl (&ehci->debug->control);
431 ehci_info (ehci, "debug port %d%s\n",
432 HCS_DEBUG_PORT(ehci->hcs_params),
433 (temp & DBGP_ENABLED)
434 ? " IN USE"
435 : "");
436 if (!(temp & DBGP_ENABLED))
437 ehci->debug = NULL;
438 }
439 }
440 393
441 temp = HCC_EXT_CAPS (readl (&ehci->caps->hcc_params)); 394 remove_debug_files (ehci);
442 } else
443 temp = 0;
444
445 /* EHCI 0.96 and later may have "extended capabilities" */
446 while (temp && count--) {
447 u32 cap;
448
449 pci_read_config_dword (to_pci_dev(hcd->self.controller),
450 temp, &cap);
451 ehci_dbg (ehci, "capability %04x at %02x\n", cap, temp);
452 switch (cap & 0xff) {
453 case 1: /* BIOS/SMM/... handoff */
454 if (bios_handoff (ehci, temp, cap) != 0)
455 return -EOPNOTSUPP;
456 break;
457 case 0: /* illegal reserved capability */
458 ehci_warn (ehci, "illegal capability!\n");
459 cap = 0;
460 /* FALLTHROUGH */
461 default: /* unknown */
462 break;
463 }
464 temp = (cap >> 8) & 0xff;
465 }
466 if (!count) {
467 ehci_err (ehci, "bogus capabilities ... PCI problems!\n");
468 return -EIO;
469 }
470 if (ehci_is_TDI(ehci))
471 ehci_reset (ehci);
472#endif
473 395
474 ehci_port_power (ehci, 0); 396 /* root hub is shut down separately (first, when possible) */
397 spin_lock_irq (&ehci->lock);
398 if (ehci->async)
399 ehci_work (ehci, NULL);
400 spin_unlock_irq (&ehci->lock);
401 ehci_mem_cleanup (ehci);
475 402
476 /* at least the Genesys GL880S needs fixup here */ 403#ifdef EHCI_STATS
477 temp = HCS_N_CC(ehci->hcs_params) * HCS_N_PCC(ehci->hcs_params); 404 ehci_dbg (ehci, "irq normal %ld err %ld reclaim %ld (lost %ld)\n",
478 temp &= 0x0f; 405 ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim,
479 if (temp && HCS_N_PORTS(ehci->hcs_params) > temp) { 406 ehci->stats.lost_iaa);
480 ehci_dbg (ehci, "bogus port configuration: " 407 ehci_dbg (ehci, "complete %ld unlink %ld\n",
481 "cc=%d x pcc=%d < ports=%d\n", 408 ehci->stats.complete, ehci->stats.unlink);
482 HCS_N_CC(ehci->hcs_params),
483 HCS_N_PCC(ehci->hcs_params),
484 HCS_N_PORTS(ehci->hcs_params));
485
486#ifdef CONFIG_PCI
487 if (hcd->self.controller->bus == &pci_bus_type) {
488 struct pci_dev *pdev;
489
490 pdev = to_pci_dev(hcd->self.controller);
491 switch (pdev->vendor) {
492 case 0x17a0: /* GENESYS */
493 /* GL880S: should be PORTS=2 */
494 temp |= (ehci->hcs_params & ~0xf);
495 ehci->hcs_params = temp;
496 break;
497 case PCI_VENDOR_ID_NVIDIA:
498 /* NF4: should be PCC=10 */
499 break;
500 }
501 }
502#endif 409#endif
503 }
504 410
505 /* force HC to halt state */ 411 dbg_status (ehci, "ehci_stop completed", readl (&ehci->regs->status));
506 return ehci_halt (ehci);
507} 412}
508 413
509static int ehci_start (struct usb_hcd *hcd) 414static int ehci_run (struct usb_hcd *hcd)
510{ 415{
511 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 416 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
512 u32 temp; 417 u32 temp;
513 int retval; 418 int retval;
514 u32 hcc_params; 419 u32 hcc_params;
515 u8 sbrn = 0;
516 int first; 420 int first;
517 421
518 /* skip some things on restart paths */ 422 /* skip some things on restart paths */
@@ -551,27 +455,6 @@ static int ehci_start (struct usb_hcd *hcd)
551 } 455 }
552 writel (ehci->periodic_dma, &ehci->regs->frame_list); 456 writel (ehci->periodic_dma, &ehci->regs->frame_list);
553 457
554#ifdef CONFIG_PCI
555 if (hcd->self.controller->bus == &pci_bus_type) {
556 struct pci_dev *pdev;
557 u16 port_wake;
558
559 pdev = to_pci_dev(hcd->self.controller);
560
561 /* Serial Bus Release Number is at PCI 0x60 offset */
562 pci_read_config_byte(pdev, 0x60, &sbrn);
563
564 /* port wake capability, reported by boot firmware */
565 pci_read_config_word(pdev, 0x62, &port_wake);
566 hcd->can_wakeup = (port_wake & 1) != 0;
567
568 /* help hc dma work well with cachelines */
569 retval = pci_set_mwi(pdev);
570 if (retval)
571 ehci_dbg(ehci, "unable to enable MWI - not fatal.\n");
572 }
573#endif
574
575 /* 458 /*
576 * dedicate a qh for the async ring head, since we couldn't unlink 459 * dedicate a qh for the async ring head, since we couldn't unlink
577 * a 'real' qh without stopping the async schedule [4.8]. use it 460 * a 'real' qh without stopping the async schedule [4.8]. use it
@@ -667,7 +550,7 @@ static int ehci_start (struct usb_hcd *hcd)
667 temp = HC_VERSION(readl (&ehci->caps->hc_capbase)); 550 temp = HC_VERSION(readl (&ehci->caps->hc_capbase));
668 ehci_info (ehci, 551 ehci_info (ehci,
669 "USB %x.%x %s, EHCI %x.%02x, driver %s\n", 552 "USB %x.%x %s, EHCI %x.%02x, driver %s\n",
670 ((sbrn & 0xf0)>>4), (sbrn & 0x0f), 553 ((ehci->sbrn & 0xf0)>>4), (ehci->sbrn & 0x0f),
671 first ? "initialized" : "restarted", 554 first ? "initialized" : "restarted",
672 temp >> 8, temp & 0xff, DRIVER_VERSION); 555 temp >> 8, temp & 0xff, DRIVER_VERSION);
673 556
@@ -679,188 +562,6 @@ static int ehci_start (struct usb_hcd *hcd)
679 return 0; 562 return 0;
680} 563}
681 564
682/* always called by thread; normally rmmod */
683
684static void ehci_stop (struct usb_hcd *hcd)
685{
686 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
687
688 ehci_dbg (ehci, "stop\n");
689
690 /* Turn off port power on all root hub ports. */
691 ehci_port_power (ehci, 0);
692
693 /* no more interrupts ... */
694 del_timer_sync (&ehci->watchdog);
695
696 spin_lock_irq(&ehci->lock);
697 if (HC_IS_RUNNING (hcd->state))
698 ehci_quiesce (ehci);
699
700 ehci_reset (ehci);
701 writel (0, &ehci->regs->intr_enable);
702 spin_unlock_irq(&ehci->lock);
703
704 /* let companion controllers work when we aren't */
705 writel (0, &ehci->regs->configured_flag);
706 unregister_reboot_notifier (&ehci->reboot_notifier);
707
708 remove_debug_files (ehci);
709
710 /* root hub is shut down separately (first, when possible) */
711 spin_lock_irq (&ehci->lock);
712 if (ehci->async)
713 ehci_work (ehci, NULL);
714 spin_unlock_irq (&ehci->lock);
715 ehci_mem_cleanup (ehci);
716
717#ifdef EHCI_STATS
718 ehci_dbg (ehci, "irq normal %ld err %ld reclaim %ld (lost %ld)\n",
719 ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim,
720 ehci->stats.lost_iaa);
721 ehci_dbg (ehci, "complete %ld unlink %ld\n",
722 ehci->stats.complete, ehci->stats.unlink);
723#endif
724
725 dbg_status (ehci, "ehci_stop completed", readl (&ehci->regs->status));
726}
727
728static int ehci_get_frame (struct usb_hcd *hcd)
729{
730 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
731 return (readl (&ehci->regs->frame_index) >> 3) % ehci->periodic_size;
732}
733
734/*-------------------------------------------------------------------------*/
735
736#ifdef CONFIG_PM
737
738/* suspend/resume, section 4.3 */
739
740/* These routines rely on the bus (pci, platform, etc)
741 * to handle powerdown and wakeup, and currently also on
742 * transceivers that don't need any software attention to set up
743 * the right sort of wakeup.
744 */
745
746static int ehci_suspend (struct usb_hcd *hcd, pm_message_t message)
747{
748 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
749
750 if (time_before (jiffies, ehci->next_statechange))
751 msleep (100);
752
753#ifdef CONFIG_USB_SUSPEND
754 (void) usb_suspend_device (hcd->self.root_hub, message);
755#else
756 usb_lock_device (hcd->self.root_hub);
757 (void) ehci_hub_suspend (hcd);
758 usb_unlock_device (hcd->self.root_hub);
759#endif
760
761 // save (PCI) FLADJ in case of Vaux power loss
762 // ... we'd only use it to handle clock skew
763
764 return 0;
765}
766
767static int ehci_resume (struct usb_hcd *hcd)
768{
769 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
770 unsigned port;
771 struct usb_device *root = hcd->self.root_hub;
772 int retval = -EINVAL;
773
774 // maybe restore (PCI) FLADJ
775
776 if (time_before (jiffies, ehci->next_statechange))
777 msleep (100);
778
779 /* If any port is suspended (or owned by the companion),
780 * we know we can/must resume the HC (and mustn't reset it).
781 */
782 for (port = HCS_N_PORTS (ehci->hcs_params); port > 0; ) {
783 u32 status;
784 port--;
785 status = readl (&ehci->regs->port_status [port]);
786 if (!(status & PORT_POWER))
787 continue;
788 if (status & (PORT_SUSPEND | PORT_OWNER)) {
789 down (&hcd->self.root_hub->serialize);
790 retval = ehci_hub_resume (hcd);
791 up (&hcd->self.root_hub->serialize);
792 break;
793 }
794 if (!root->children [port])
795 continue;
796 dbg_port (ehci, __FUNCTION__, port + 1, status);
797 usb_set_device_state (root->children[port],
798 USB_STATE_NOTATTACHED);
799 }
800
801 /* Else reset, to cope with power loss or flush-to-storage
802 * style "resume" having activated BIOS during reboot.
803 */
804 if (port == 0) {
805 (void) ehci_halt (ehci);
806 (void) ehci_reset (ehci);
807 (void) ehci_hc_reset (hcd);
808
809 /* emptying the schedule aborts any urbs */
810 spin_lock_irq (&ehci->lock);
811 if (ehci->reclaim)
812 ehci->reclaim_ready = 1;
813 ehci_work (ehci, NULL);
814 spin_unlock_irq (&ehci->lock);
815
816 /* restart; khubd will disconnect devices */
817 retval = ehci_start (hcd);
818
819 /* here we "know" root ports should always stay powered;
820 * but some controllers may lose all power.
821 */
822 ehci_port_power (ehci, 1);
823 }
824
825 return retval;
826}
827
828#endif
829
830/*-------------------------------------------------------------------------*/
831
832/*
833 * ehci_work is called from some interrupts, timers, and so on.
834 * it calls driver completion functions, after dropping ehci->lock.
835 */
836static void ehci_work (struct ehci_hcd *ehci, struct pt_regs *regs)
837{
838 timer_action_done (ehci, TIMER_IO_WATCHDOG);
839 if (ehci->reclaim_ready)
840 end_unlink_async (ehci, regs);
841
842 /* another CPU may drop ehci->lock during a schedule scan while
843 * it reports urb completions. this flag guards against bogus
844 * attempts at re-entrant schedule scanning.
845 */
846 if (ehci->scanning)
847 return;
848 ehci->scanning = 1;
849 scan_async (ehci, regs);
850 if (ehci->next_uframe != -1)
851 scan_periodic (ehci, regs);
852 ehci->scanning = 0;
853
854 /* the IO watchdog guards against hardware or driver bugs that
855 * misplace IRQs, and should let us run completely without IRQs.
856 * such lossage has been observed on both VT6202 and VT8235.
857 */
858 if (HC_IS_RUNNING (ehci_to_hcd(ehci)->state) &&
859 (ehci->async->qh_next.ptr != NULL ||
860 ehci->periodic_sched != 0))
861 timer_action (ehci, TIMER_IO_WATCHDOG);
862}
863
864/*-------------------------------------------------------------------------*/ 565/*-------------------------------------------------------------------------*/
865 566
866static irqreturn_t ehci_irq (struct usb_hcd *hcd, struct pt_regs *regs) 567static irqreturn_t ehci_irq (struct usb_hcd *hcd, struct pt_regs *regs)
@@ -983,7 +684,7 @@ static int ehci_urb_enqueue (
983 struct usb_hcd *hcd, 684 struct usb_hcd *hcd,
984 struct usb_host_endpoint *ep, 685 struct usb_host_endpoint *ep,
985 struct urb *urb, 686 struct urb *urb,
986 unsigned mem_flags 687 gfp_t mem_flags
987) { 688) {
988 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 689 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
989 struct list_head qtd_list; 690 struct list_head qtd_list;
@@ -1171,106 +872,24 @@ done:
1171 return; 872 return;
1172} 873}
1173 874
1174/*-------------------------------------------------------------------------*/ 875static int ehci_get_frame (struct usb_hcd *hcd)
1175 876{
1176static const struct hc_driver ehci_driver = { 877 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
1177 .description = hcd_name, 878 return (readl (&ehci->regs->frame_index) >> 3) % ehci->periodic_size;
1178 .product_desc = "EHCI Host Controller", 879}
1179 .hcd_priv_size = sizeof(struct ehci_hcd),
1180
1181 /*
1182 * generic hardware linkage
1183 */
1184 .irq = ehci_irq,
1185 .flags = HCD_MEMORY | HCD_USB2,
1186
1187 /*
1188 * basic lifecycle operations
1189 */
1190 .reset = ehci_hc_reset,
1191 .start = ehci_start,
1192#ifdef CONFIG_PM
1193 .suspend = ehci_suspend,
1194 .resume = ehci_resume,
1195#endif
1196 .stop = ehci_stop,
1197
1198 /*
1199 * managing i/o requests and associated device resources
1200 */
1201 .urb_enqueue = ehci_urb_enqueue,
1202 .urb_dequeue = ehci_urb_dequeue,
1203 .endpoint_disable = ehci_endpoint_disable,
1204
1205 /*
1206 * scheduling support
1207 */
1208 .get_frame_number = ehci_get_frame,
1209
1210 /*
1211 * root hub support
1212 */
1213 .hub_status_data = ehci_hub_status_data,
1214 .hub_control = ehci_hub_control,
1215 .hub_suspend = ehci_hub_suspend,
1216 .hub_resume = ehci_hub_resume,
1217};
1218 880
1219/*-------------------------------------------------------------------------*/ 881/*-------------------------------------------------------------------------*/
1220 882
1221/* EHCI 1.0 doesn't require PCI */
1222
1223#ifdef CONFIG_PCI
1224
1225/* PCI driver selection metadata; PCI hotplugging uses this */
1226static const struct pci_device_id pci_ids [] = { {
1227 /* handle any USB 2.0 EHCI controller */
1228 PCI_DEVICE_CLASS(((PCI_CLASS_SERIAL_USB << 8) | 0x20), ~0),
1229 .driver_data = (unsigned long) &ehci_driver,
1230 },
1231 { /* end: all zeroes */ }
1232};
1233MODULE_DEVICE_TABLE (pci, pci_ids);
1234
1235/* pci driver glue; this is a "new style" PCI driver module */
1236static struct pci_driver ehci_pci_driver = {
1237 .name = (char *) hcd_name,
1238 .id_table = pci_ids,
1239
1240 .probe = usb_hcd_pci_probe,
1241 .remove = usb_hcd_pci_remove,
1242
1243#ifdef CONFIG_PM
1244 .suspend = usb_hcd_pci_suspend,
1245 .resume = usb_hcd_pci_resume,
1246#endif
1247};
1248
1249#endif /* PCI */
1250
1251
1252#define DRIVER_INFO DRIVER_VERSION " " DRIVER_DESC 883#define DRIVER_INFO DRIVER_VERSION " " DRIVER_DESC
1253 884
1254MODULE_DESCRIPTION (DRIVER_INFO); 885MODULE_DESCRIPTION (DRIVER_INFO);
1255MODULE_AUTHOR (DRIVER_AUTHOR); 886MODULE_AUTHOR (DRIVER_AUTHOR);
1256MODULE_LICENSE ("GPL"); 887MODULE_LICENSE ("GPL");
1257 888
1258static int __init init (void) 889#ifdef CONFIG_PCI
1259{ 890#include "ehci-pci.c"
1260 if (usb_disabled()) 891#endif
1261 return -ENODEV;
1262
1263 pr_debug ("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
1264 hcd_name,
1265 sizeof (struct ehci_qh), sizeof (struct ehci_qtd),
1266 sizeof (struct ehci_itd), sizeof (struct ehci_sitd));
1267
1268 return pci_register_driver (&ehci_pci_driver);
1269}
1270module_init (init);
1271 892
1272static void __exit cleanup (void) 893#if !defined(CONFIG_PCI)
1273{ 894#error "missing bus glue for ehci-hcd"
1274 pci_unregister_driver (&ehci_pci_driver); 895#endif
1275}
1276module_exit (cleanup);
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index 18d3f2270316..88cb4ada686e 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -30,7 +30,7 @@
30 30
31#ifdef CONFIG_PM 31#ifdef CONFIG_PM
32 32
33static int ehci_hub_suspend (struct usb_hcd *hcd) 33static int ehci_bus_suspend (struct usb_hcd *hcd)
34{ 34{
35 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 35 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
36 int port; 36 int port;
@@ -83,7 +83,7 @@ static int ehci_hub_suspend (struct usb_hcd *hcd)
83 83
84 84
85/* caller has locked the root hub, and should reset/reinit on error */ 85/* caller has locked the root hub, and should reset/reinit on error */
86static int ehci_hub_resume (struct usb_hcd *hcd) 86static int ehci_bus_resume (struct usb_hcd *hcd)
87{ 87{
88 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 88 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
89 u32 temp; 89 u32 temp;
@@ -159,8 +159,8 @@ static int ehci_hub_resume (struct usb_hcd *hcd)
159 159
160#else 160#else
161 161
162#define ehci_hub_suspend NULL 162#define ehci_bus_suspend NULL
163#define ehci_hub_resume NULL 163#define ehci_bus_resume NULL
164 164
165#endif /* CONFIG_PM */ 165#endif /* CONFIG_PM */
166 166
diff --git a/drivers/usb/host/ehci-mem.c b/drivers/usb/host/ehci-mem.c
index 5c38ad869485..91c2ab43cbcc 100644
--- a/drivers/usb/host/ehci-mem.c
+++ b/drivers/usb/host/ehci-mem.c
@@ -45,7 +45,7 @@ static inline void ehci_qtd_init (struct ehci_qtd *qtd, dma_addr_t dma)
45 INIT_LIST_HEAD (&qtd->qtd_list); 45 INIT_LIST_HEAD (&qtd->qtd_list);
46} 46}
47 47
48static struct ehci_qtd *ehci_qtd_alloc (struct ehci_hcd *ehci, int flags) 48static struct ehci_qtd *ehci_qtd_alloc (struct ehci_hcd *ehci, gfp_t flags)
49{ 49{
50 struct ehci_qtd *qtd; 50 struct ehci_qtd *qtd;
51 dma_addr_t dma; 51 dma_addr_t dma;
@@ -79,7 +79,7 @@ static void qh_destroy (struct kref *kref)
79 dma_pool_free (ehci->qh_pool, qh, qh->qh_dma); 79 dma_pool_free (ehci->qh_pool, qh, qh->qh_dma);
80} 80}
81 81
82static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, int flags) 82static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, gfp_t flags)
83{ 83{
84 struct ehci_qh *qh; 84 struct ehci_qh *qh;
85 dma_addr_t dma; 85 dma_addr_t dma;
@@ -161,7 +161,7 @@ static void ehci_mem_cleanup (struct ehci_hcd *ehci)
161} 161}
162 162
163/* remember to add cleanup code (above) if you add anything here */ 163/* remember to add cleanup code (above) if you add anything here */
164static int ehci_mem_init (struct ehci_hcd *ehci, int flags) 164static int ehci_mem_init (struct ehci_hcd *ehci, gfp_t flags)
165{ 165{
166 int i; 166 int i;
167 167
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
new file mode 100644
index 000000000000..145008853966
--- /dev/null
+++ b/drivers/usb/host/ehci-pci.c
@@ -0,0 +1,415 @@
1/*
2 * EHCI HCD (Host Controller Driver) PCI Bus Glue.
3 *
4 * Copyright (c) 2000-2004 by David Brownell
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#ifndef CONFIG_PCI
22#error "This file is PCI bus glue. CONFIG_PCI must be defined."
23#endif
24
25/*-------------------------------------------------------------------------*/
26
27/* EHCI 0.96 (and later) section 5.1 says how to kick BIOS/SMM/...
28 * off the controller (maybe it can boot from highspeed USB disks).
29 */
30static int bios_handoff (struct ehci_hcd *ehci, int where, u32 cap)
31{
32 struct pci_dev *pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller);
33
34 /* always say Linux will own the hardware */
35 pci_write_config_byte(pdev, where + 3, 1);
36
37 /* maybe wait a while for BIOS to respond */
38 if (cap & (1 << 16)) {
39 int msec = 5000;
40
41 do {
42 msleep(10);
43 msec -= 10;
44 pci_read_config_dword(pdev, where, &cap);
45 } while ((cap & (1 << 16)) && msec);
46 if (cap & (1 << 16)) {
47 ehci_err(ehci, "BIOS handoff failed (%d, %08x)\n",
48 where, cap);
49 // some BIOS versions seem buggy...
50 // return 1;
51 ehci_warn (ehci, "continuing after BIOS bug...\n");
52 /* disable all SMIs, and clear "BIOS owns" flag */
53 pci_write_config_dword(pdev, where + 4, 0);
54 pci_write_config_byte(pdev, where + 2, 0);
55 } else
56 ehci_dbg(ehci, "BIOS handoff succeeded\n");
57 }
58 return 0;
59}
60
61/* called by khubd or root hub init threads */
62static int ehci_pci_reset (struct usb_hcd *hcd)
63{
64 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
65 u32 temp;
66 unsigned count = 256/4;
67
68 spin_lock_init (&ehci->lock);
69
70 ehci->caps = hcd->regs;
71 ehci->regs = hcd->regs + HC_LENGTH (readl (&ehci->caps->hc_capbase));
72 dbg_hcs_params (ehci, "reset");
73 dbg_hcc_params (ehci, "reset");
74
75 /* cache this readonly data; minimize chip reads */
76 ehci->hcs_params = readl (&ehci->caps->hcs_params);
77
78 if (hcd->self.controller->bus == &pci_bus_type) {
79 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
80
81 switch (pdev->vendor) {
82 case PCI_VENDOR_ID_TDI:
83 if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) {
84 ehci->is_tdi_rh_tt = 1;
85 tdi_reset (ehci);
86 }
87 break;
88 case PCI_VENDOR_ID_AMD:
89 /* AMD8111 EHCI doesn't work, according to AMD errata */
90 if (pdev->device == 0x7463) {
91 ehci_info (ehci, "ignoring AMD8111 (errata)\n");
92 return -EIO;
93 }
94 break;
95 case PCI_VENDOR_ID_NVIDIA:
96 /* NVidia reports that certain chips don't handle
97 * QH, ITD, or SITD addresses above 2GB. (But TD,
98 * data buffer, and periodic schedule are normal.)
99 */
100 switch (pdev->device) {
101 case 0x003c: /* MCP04 */
102 case 0x005b: /* CK804 */
103 case 0x00d8: /* CK8 */
104 case 0x00e8: /* CK8S */
105 if (pci_set_consistent_dma_mask(pdev,
106 DMA_31BIT_MASK) < 0)
107 ehci_warn (ehci, "can't enable NVidia "
108 "workaround for >2GB RAM\n");
109 break;
110 }
111 break;
112 }
113
114 /* optional debug port, normally in the first BAR */
115 temp = pci_find_capability (pdev, 0x0a);
116 if (temp) {
117 pci_read_config_dword(pdev, temp, &temp);
118 temp >>= 16;
119 if ((temp & (3 << 13)) == (1 << 13)) {
120 temp &= 0x1fff;
121 ehci->debug = hcd->regs + temp;
122 temp = readl (&ehci->debug->control);
123 ehci_info (ehci, "debug port %d%s\n",
124 HCS_DEBUG_PORT(ehci->hcs_params),
125 (temp & DBGP_ENABLED)
126 ? " IN USE"
127 : "");
128 if (!(temp & DBGP_ENABLED))
129 ehci->debug = NULL;
130 }
131 }
132
133 temp = HCC_EXT_CAPS (readl (&ehci->caps->hcc_params));
134 } else
135 temp = 0;
136
137 /* EHCI 0.96 and later may have "extended capabilities" */
138 while (temp && count--) {
139 u32 cap;
140
141 pci_read_config_dword (to_pci_dev(hcd->self.controller),
142 temp, &cap);
143 ehci_dbg (ehci, "capability %04x at %02x\n", cap, temp);
144 switch (cap & 0xff) {
145 case 1: /* BIOS/SMM/... handoff */
146 if (bios_handoff (ehci, temp, cap) != 0)
147 return -EOPNOTSUPP;
148 break;
149 case 0: /* illegal reserved capability */
150 ehci_warn (ehci, "illegal capability!\n");
151 cap = 0;
152 /* FALLTHROUGH */
153 default: /* unknown */
154 break;
155 }
156 temp = (cap >> 8) & 0xff;
157 }
158 if (!count) {
159 ehci_err (ehci, "bogus capabilities ... PCI problems!\n");
160 return -EIO;
161 }
162 if (ehci_is_TDI(ehci))
163 ehci_reset (ehci);
164
165 ehci_port_power (ehci, 0);
166
167 /* at least the Genesys GL880S needs fixup here */
168 temp = HCS_N_CC(ehci->hcs_params) * HCS_N_PCC(ehci->hcs_params);
169 temp &= 0x0f;
170 if (temp && HCS_N_PORTS(ehci->hcs_params) > temp) {
171 ehci_dbg (ehci, "bogus port configuration: "
172 "cc=%d x pcc=%d < ports=%d\n",
173 HCS_N_CC(ehci->hcs_params),
174 HCS_N_PCC(ehci->hcs_params),
175 HCS_N_PORTS(ehci->hcs_params));
176
177 if (hcd->self.controller->bus == &pci_bus_type) {
178 struct pci_dev *pdev;
179
180 pdev = to_pci_dev(hcd->self.controller);
181 switch (pdev->vendor) {
182 case 0x17a0: /* GENESYS */
183 /* GL880S: should be PORTS=2 */
184 temp |= (ehci->hcs_params & ~0xf);
185 ehci->hcs_params = temp;
186 break;
187 case PCI_VENDOR_ID_NVIDIA:
188 /* NF4: should be PCC=10 */
189 break;
190 }
191 }
192 }
193
194 /* force HC to halt state */
195 return ehci_halt (ehci);
196}
197
198static int ehci_pci_start (struct usb_hcd *hcd)
199{
200 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
201 int result = 0;
202
203 if (hcd->self.controller->bus == &pci_bus_type) {
204 struct pci_dev *pdev;
205 u16 port_wake;
206
207 pdev = to_pci_dev(hcd->self.controller);
208
209 /* Serial Bus Release Number is at PCI 0x60 offset */
210 pci_read_config_byte(pdev, 0x60, &ehci->sbrn);
211
212 /* port wake capability, reported by boot firmware */
213 pci_read_config_word(pdev, 0x62, &port_wake);
214 hcd->can_wakeup = (port_wake & 1) != 0;
215
216 /* help hc dma work well with cachelines */
217 result = pci_set_mwi(pdev);
218 if (result)
219 ehci_dbg(ehci, "unable to enable MWI - not fatal.\n");
220 }
221
222 return ehci_run (hcd);
223}
224
225/* always called by thread; normally rmmod */
226
227static void ehci_pci_stop (struct usb_hcd *hcd)
228{
229 ehci_stop (hcd);
230}
231
232/*-------------------------------------------------------------------------*/
233
234#ifdef CONFIG_PM
235
236/* suspend/resume, section 4.3 */
237
238/* These routines rely on the bus (pci, platform, etc)
239 * to handle powerdown and wakeup, and currently also on
240 * transceivers that don't need any software attention to set up
241 * the right sort of wakeup.
242 */
243
244static int ehci_pci_suspend (struct usb_hcd *hcd, pm_message_t message)
245{
246 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
247
248 if (time_before (jiffies, ehci->next_statechange))
249 msleep (100);
250
251#ifdef CONFIG_USB_SUSPEND
252 (void) usb_suspend_device (hcd->self.root_hub);
253#else
254 usb_lock_device (hcd->self.root_hub);
255 (void) ehci_bus_suspend (hcd);
256 usb_unlock_device (hcd->self.root_hub);
257#endif
258
259 // save (PCI) FLADJ in case of Vaux power loss
260 // ... we'd only use it to handle clock skew
261
262 return 0;
263}
264
265static int ehci_pci_resume (struct usb_hcd *hcd)
266{
267 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
268 unsigned port;
269 struct usb_device *root = hcd->self.root_hub;
270 int retval = -EINVAL;
271
272 // maybe restore (PCI) FLADJ
273
274 if (time_before (jiffies, ehci->next_statechange))
275 msleep (100);
276
277 /* If any port is suspended (or owned by the companion),
278 * we know we can/must resume the HC (and mustn't reset it).
279 */
280 for (port = HCS_N_PORTS (ehci->hcs_params); port > 0; ) {
281 u32 status;
282 port--;
283 status = readl (&ehci->regs->port_status [port]);
284 if (!(status & PORT_POWER))
285 continue;
286 if (status & (PORT_SUSPEND | PORT_OWNER)) {
287 down (&hcd->self.root_hub->serialize);
288 retval = ehci_bus_resume (hcd);
289 up (&hcd->self.root_hub->serialize);
290 break;
291 }
292 if (!root->children [port])
293 continue;
294 dbg_port (ehci, __FUNCTION__, port + 1, status);
295 usb_set_device_state (root->children[port],
296 USB_STATE_NOTATTACHED);
297 }
298
299 /* Else reset, to cope with power loss or flush-to-storage
300 * style "resume" having activated BIOS during reboot.
301 */
302 if (port == 0) {
303 (void) ehci_halt (ehci);
304 (void) ehci_reset (ehci);
305 (void) ehci_pci_reset (hcd);
306
307 /* emptying the schedule aborts any urbs */
308 spin_lock_irq (&ehci->lock);
309 if (ehci->reclaim)
310 ehci->reclaim_ready = 1;
311 ehci_work (ehci, NULL);
312 spin_unlock_irq (&ehci->lock);
313
314 /* restart; khubd will disconnect devices */
315 retval = ehci_run (hcd);
316
317 /* here we "know" root ports should always stay powered;
318 * but some controllers may lose all power.
319 */
320 ehci_port_power (ehci, 1);
321 }
322
323 return retval;
324}
325#endif
326
327static const struct hc_driver ehci_pci_hc_driver = {
328 .description = hcd_name,
329 .product_desc = "EHCI Host Controller",
330 .hcd_priv_size = sizeof(struct ehci_hcd),
331
332 /*
333 * generic hardware linkage
334 */
335 .irq = ehci_irq,
336 .flags = HCD_MEMORY | HCD_USB2,
337
338 /*
339 * basic lifecycle operations
340 */
341 .reset = ehci_pci_reset,
342 .start = ehci_pci_start,
343#ifdef CONFIG_PM
344 .suspend = ehci_pci_suspend,
345 .resume = ehci_pci_resume,
346#endif
347 .stop = ehci_pci_stop,
348
349 /*
350 * managing i/o requests and associated device resources
351 */
352 .urb_enqueue = ehci_urb_enqueue,
353 .urb_dequeue = ehci_urb_dequeue,
354 .endpoint_disable = ehci_endpoint_disable,
355
356 /*
357 * scheduling support
358 */
359 .get_frame_number = ehci_get_frame,
360
361 /*
362 * root hub support
363 */
364 .hub_status_data = ehci_hub_status_data,
365 .hub_control = ehci_hub_control,
366 .bus_suspend = ehci_bus_suspend,
367 .bus_resume = ehci_bus_resume,
368};
369
370/*-------------------------------------------------------------------------*/
371
372/* PCI driver selection metadata; PCI hotplugging uses this */
373static const struct pci_device_id pci_ids [] = { {
374 /* handle any USB 2.0 EHCI controller */
375 PCI_DEVICE_CLASS(((PCI_CLASS_SERIAL_USB << 8) | 0x20), ~0),
376 .driver_data = (unsigned long) &ehci_pci_hc_driver,
377 },
378 { /* end: all zeroes */ }
379};
380MODULE_DEVICE_TABLE (pci, pci_ids);
381
382/* pci driver glue; this is a "new style" PCI driver module */
383static struct pci_driver ehci_pci_driver = {
384 .name = (char *) hcd_name,
385 .id_table = pci_ids,
386 .owner = THIS_MODULE,
387
388 .probe = usb_hcd_pci_probe,
389 .remove = usb_hcd_pci_remove,
390
391#ifdef CONFIG_PM
392 .suspend = usb_hcd_pci_suspend,
393 .resume = usb_hcd_pci_resume,
394#endif
395};
396
397static int __init ehci_hcd_pci_init (void)
398{
399 if (usb_disabled())
400 return -ENODEV;
401
402 pr_debug ("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",
403 hcd_name,
404 sizeof (struct ehci_qh), sizeof (struct ehci_qtd),
405 sizeof (struct ehci_itd), sizeof (struct ehci_sitd));
406
407 return pci_register_driver (&ehci_pci_driver);
408}
409module_init (ehci_hcd_pci_init);
410
411static void __exit ehci_hcd_pci_cleanup (void)
412{
413 pci_unregister_driver (&ehci_pci_driver);
414}
415module_exit (ehci_hcd_pci_cleanup);
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 940d38ca7d91..5bb872c3496d 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -477,7 +477,7 @@ qh_urb_transaction (
477 struct ehci_hcd *ehci, 477 struct ehci_hcd *ehci,
478 struct urb *urb, 478 struct urb *urb,
479 struct list_head *head, 479 struct list_head *head,
480 int flags 480 gfp_t flags
481) { 481) {
482 struct ehci_qtd *qtd, *qtd_prev; 482 struct ehci_qtd *qtd, *qtd_prev;
483 dma_addr_t buf; 483 dma_addr_t buf;
@@ -629,7 +629,7 @@ static struct ehci_qh *
629qh_make ( 629qh_make (
630 struct ehci_hcd *ehci, 630 struct ehci_hcd *ehci,
631 struct urb *urb, 631 struct urb *urb,
632 int flags 632 gfp_t flags
633) { 633) {
634 struct ehci_qh *qh = ehci_qh_alloc (ehci, flags); 634 struct ehci_qh *qh = ehci_qh_alloc (ehci, flags);
635 u32 info1 = 0, info2 = 0; 635 u32 info1 = 0, info2 = 0;
@@ -906,7 +906,7 @@ submit_async (
906 struct usb_host_endpoint *ep, 906 struct usb_host_endpoint *ep,
907 struct urb *urb, 907 struct urb *urb,
908 struct list_head *qtd_list, 908 struct list_head *qtd_list,
909 unsigned mem_flags 909 gfp_t mem_flags
910) { 910) {
911 struct ehci_qtd *qtd; 911 struct ehci_qtd *qtd;
912 int epnum; 912 int epnum;
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index ccc7300baa6d..f0c8aa1ccd5d 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -589,7 +589,7 @@ static int intr_submit (
589 struct usb_host_endpoint *ep, 589 struct usb_host_endpoint *ep,
590 struct urb *urb, 590 struct urb *urb,
591 struct list_head *qtd_list, 591 struct list_head *qtd_list,
592 unsigned mem_flags 592 gfp_t mem_flags
593) { 593) {
594 unsigned epnum; 594 unsigned epnum;
595 unsigned long flags; 595 unsigned long flags;
@@ -634,7 +634,7 @@ done:
634/* ehci_iso_stream ops work with both ITD and SITD */ 634/* ehci_iso_stream ops work with both ITD and SITD */
635 635
636static struct ehci_iso_stream * 636static struct ehci_iso_stream *
637iso_stream_alloc (unsigned mem_flags) 637iso_stream_alloc (gfp_t mem_flags)
638{ 638{
639 struct ehci_iso_stream *stream; 639 struct ehci_iso_stream *stream;
640 640
@@ -851,7 +851,7 @@ iso_stream_find (struct ehci_hcd *ehci, struct urb *urb)
851/* ehci_iso_sched ops can be ITD-only or SITD-only */ 851/* ehci_iso_sched ops can be ITD-only or SITD-only */
852 852
853static struct ehci_iso_sched * 853static struct ehci_iso_sched *
854iso_sched_alloc (unsigned packets, unsigned mem_flags) 854iso_sched_alloc (unsigned packets, gfp_t mem_flags)
855{ 855{
856 struct ehci_iso_sched *iso_sched; 856 struct ehci_iso_sched *iso_sched;
857 int size = sizeof *iso_sched; 857 int size = sizeof *iso_sched;
@@ -924,7 +924,7 @@ itd_urb_transaction (
924 struct ehci_iso_stream *stream, 924 struct ehci_iso_stream *stream,
925 struct ehci_hcd *ehci, 925 struct ehci_hcd *ehci,
926 struct urb *urb, 926 struct urb *urb,
927 unsigned mem_flags 927 gfp_t mem_flags
928) 928)
929{ 929{
930 struct ehci_itd *itd; 930 struct ehci_itd *itd;
@@ -1418,7 +1418,7 @@ itd_complete (
1418/*-------------------------------------------------------------------------*/ 1418/*-------------------------------------------------------------------------*/
1419 1419
1420static int itd_submit (struct ehci_hcd *ehci, struct urb *urb, 1420static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
1421 unsigned mem_flags) 1421 gfp_t mem_flags)
1422{ 1422{
1423 int status = -EINVAL; 1423 int status = -EINVAL;
1424 unsigned long flags; 1424 unsigned long flags;
@@ -1529,7 +1529,7 @@ sitd_urb_transaction (
1529 struct ehci_iso_stream *stream, 1529 struct ehci_iso_stream *stream,
1530 struct ehci_hcd *ehci, 1530 struct ehci_hcd *ehci,
1531 struct urb *urb, 1531 struct urb *urb,
1532 unsigned mem_flags 1532 gfp_t mem_flags
1533) 1533)
1534{ 1534{
1535 struct ehci_sitd *sitd; 1535 struct ehci_sitd *sitd;
@@ -1779,7 +1779,7 @@ sitd_complete (
1779 1779
1780 1780
1781static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb, 1781static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
1782 unsigned mem_flags) 1782 gfp_t mem_flags)
1783{ 1783{
1784 int status = -EINVAL; 1784 int status = -EINVAL;
1785 unsigned long flags; 1785 unsigned long flags;
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index f34a0516d35f..18e257c2bdb5 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -97,6 +97,7 @@ struct ehci_hcd { /* one per controller */
97#else 97#else
98# define COUNT(x) do {} while (0) 98# define COUNT(x) do {} while (0)
99#endif 99#endif
100 u8 sbrn; /* packed release number */
100}; 101};
101 102
102/* convert between an HCD pointer and the corresponding EHCI_HCD */ 103/* convert between an HCD pointer and the corresponding EHCI_HCD */
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index e142056b0d2c..ddb8fc591466 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -638,7 +638,7 @@ static irqreturn_t isp116x_irq(struct usb_hcd *hcd, struct pt_regs *regs)
638 + msecs_to_jiffies(20) + 1); 638 + msecs_to_jiffies(20) + 1);
639 if (intstat & HCINT_RD) { 639 if (intstat & HCINT_RD) {
640 DBG("---- remote wakeup\n"); 640 DBG("---- remote wakeup\n");
641 schedule_work(&isp116x->rh_resume); 641 usb_hcd_resume_root_hub(hcd);
642 ret = IRQ_HANDLED; 642 ret = IRQ_HANDLED;
643 } 643 }
644 irqstat &= ~HCuPINT_OPR; 644 irqstat &= ~HCuPINT_OPR;
@@ -694,7 +694,7 @@ static int balance(struct isp116x *isp116x, u16 period, u16 load)
694 694
695static int isp116x_urb_enqueue(struct usb_hcd *hcd, 695static int isp116x_urb_enqueue(struct usb_hcd *hcd,
696 struct usb_host_endpoint *hep, struct urb *urb, 696 struct usb_host_endpoint *hep, struct urb *urb,
697 unsigned mem_flags) 697 gfp_t mem_flags)
698{ 698{
699 struct isp116x *isp116x = hcd_to_isp116x(hcd); 699 struct isp116x *isp116x = hcd_to_isp116x(hcd);
700 struct usb_device *udev = urb->dev; 700 struct usb_device *udev = urb->dev;
@@ -1160,7 +1160,7 @@ static int isp116x_hub_control(struct usb_hcd *hcd,
1160 1160
1161#ifdef CONFIG_PM 1161#ifdef CONFIG_PM
1162 1162
1163static int isp116x_hub_suspend(struct usb_hcd *hcd) 1163static int isp116x_bus_suspend(struct usb_hcd *hcd)
1164{ 1164{
1165 struct isp116x *isp116x = hcd_to_isp116x(hcd); 1165 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1166 unsigned long flags; 1166 unsigned long flags;
@@ -1200,7 +1200,7 @@ static int isp116x_hub_suspend(struct usb_hcd *hcd)
1200 return ret; 1200 return ret;
1201} 1201}
1202 1202
1203static int isp116x_hub_resume(struct usb_hcd *hcd) 1203static int isp116x_bus_resume(struct usb_hcd *hcd)
1204{ 1204{
1205 struct isp116x *isp116x = hcd_to_isp116x(hcd); 1205 struct isp116x *isp116x = hcd_to_isp116x(hcd);
1206 u32 val; 1206 u32 val;
@@ -1263,21 +1263,11 @@ static int isp116x_hub_resume(struct usb_hcd *hcd)
1263 return 0; 1263 return 0;
1264} 1264}
1265 1265
1266static void isp116x_rh_resume(void *_hcd)
1267{
1268 struct usb_hcd *hcd = _hcd;
1269
1270 usb_resume_device(hcd->self.root_hub);
1271}
1272 1266
1273#else 1267#else
1274 1268
1275#define isp116x_hub_suspend NULL 1269#define isp116x_bus_suspend NULL
1276#define isp116x_hub_resume NULL 1270#define isp116x_bus_resume NULL
1277
1278static void isp116x_rh_resume(void *_hcd)
1279{
1280}
1281 1271
1282#endif 1272#endif
1283 1273
@@ -1636,8 +1626,8 @@ static struct hc_driver isp116x_hc_driver = {
1636 1626
1637 .hub_status_data = isp116x_hub_status_data, 1627 .hub_status_data = isp116x_hub_status_data,
1638 .hub_control = isp116x_hub_control, 1628 .hub_control = isp116x_hub_control,
1639 .hub_suspend = isp116x_hub_suspend, 1629 .bus_suspend = isp116x_bus_suspend,
1640 .hub_resume = isp116x_hub_resume, 1630 .bus_resume = isp116x_bus_resume,
1641}; 1631};
1642 1632
1643/*----------------------------------------------------------------*/ 1633/*----------------------------------------------------------------*/
@@ -1732,7 +1722,6 @@ static int __init isp116x_probe(struct device *dev)
1732 isp116x->addr_reg = addr_reg; 1722 isp116x->addr_reg = addr_reg;
1733 spin_lock_init(&isp116x->lock); 1723 spin_lock_init(&isp116x->lock);
1734 INIT_LIST_HEAD(&isp116x->async); 1724 INIT_LIST_HEAD(&isp116x->async);
1735 INIT_WORK(&isp116x->rh_resume, isp116x_rh_resume, hcd);
1736 isp116x->board = dev->platform_data; 1725 isp116x->board = dev->platform_data;
1737 1726
1738 if (!isp116x->board) { 1727 if (!isp116x->board) {
@@ -1774,22 +1763,13 @@ static int __init isp116x_probe(struct device *dev)
1774/* 1763/*
1775 Suspend of platform device 1764 Suspend of platform device
1776*/ 1765*/
1777static int isp116x_suspend(struct device *dev, pm_message_t state, u32 phase) 1766static int isp116x_suspend(struct device *dev, pm_message_t state)
1778{ 1767{
1779 int ret = 0; 1768 int ret = 0;
1780 struct usb_hcd *hcd = dev_get_drvdata(dev);
1781 1769
1782 VDBG("%s: state %x, phase %x\n", __func__, state, phase); 1770 VDBG("%s: state %x\n", __func__, state);
1783 1771
1784 if (phase != SUSPEND_DISABLE && phase != SUSPEND_POWER_DOWN) 1772 dev->power.power_state = state;
1785 return 0;
1786
1787 ret = usb_suspend_device(hcd->self.root_hub, state);
1788 if (!ret) {
1789 dev->power.power_state = state;
1790 INFO("%s suspended\n", hcd_name);
1791 } else
1792 ERR("%s suspend failed\n", hcd_name);
1793 1773
1794 return ret; 1774 return ret;
1795} 1775}
@@ -1797,21 +1777,14 @@ static int isp116x_suspend(struct device *dev, pm_message_t state, u32 phase)
1797/* 1777/*
1798 Resume platform device 1778 Resume platform device
1799*/ 1779*/
1800static int isp116x_resume(struct device *dev, u32 phase) 1780static int isp116x_resume(struct device *dev)
1801{ 1781{
1802 int ret = 0; 1782 int ret = 0;
1803 struct usb_hcd *hcd = dev_get_drvdata(dev);
1804 1783
1805 VDBG("%s: state %x, phase %x\n", __func__, dev->power.power_state, 1784 VDBG("%s: state %x\n", __func__, dev->power.power_state);
1806 phase); 1785
1807 if (phase != RESUME_POWER_ON) 1786 dev->power.power_state = PMSG_ON;
1808 return 0;
1809 1787
1810 ret = usb_resume_device(hcd->self.root_hub);
1811 if (!ret) {
1812 dev->power.power_state = PMSG_ON;
1813 VDBG("%s resumed\n", (char *)hcd_name);
1814 }
1815 return ret; 1788 return ret;
1816} 1789}
1817 1790
diff --git a/drivers/usb/host/isp116x.h b/drivers/usb/host/isp116x.h
index 58873470dcf5..c6fec96785fe 100644
--- a/drivers/usb/host/isp116x.h
+++ b/drivers/usb/host/isp116x.h
@@ -253,7 +253,6 @@ static const int cc_to_error[16] = {
253 253
254struct isp116x { 254struct isp116x {
255 spinlock_t lock; 255 spinlock_t lock;
256 struct work_struct rh_resume;
257 256
258 void __iomem *addr_reg; 257 void __iomem *addr_reg;
259 void __iomem *data_reg; 258 void __iomem *data_reg;
diff --git a/drivers/usb/host/ohci-au1xxx.c b/drivers/usb/host/ohci-au1xxx.c
index 3981bf15c8c7..a277e258eb6c 100644
--- a/drivers/usb/host/ohci-au1xxx.c
+++ b/drivers/usb/host/ohci-au1xxx.c
@@ -214,6 +214,11 @@ static const struct hc_driver ohci_au1xxx_hc_driver = {
214 */ 214 */
215 .hub_status_data = ohci_hub_status_data, 215 .hub_status_data = ohci_hub_status_data,
216 .hub_control = ohci_hub_control, 216 .hub_control = ohci_hub_control,
217#ifdef CONFIG_PM
218 .bus_suspend = ohci_bus_suspend,
219 .bus_resume = ohci_bus_resume,
220#endif
221 .start_port_reset = ohci_start_port_reset,
217}; 222};
218 223
219/*-------------------------------------------------------------------------*/ 224/*-------------------------------------------------------------------------*/
@@ -259,6 +264,7 @@ static int ohci_hcd_au1xxx_drv_resume(struct device *dev)
259 264
260static struct device_driver ohci_hcd_au1xxx_driver = { 265static struct device_driver ohci_hcd_au1xxx_driver = {
261 .name = "au1xxx-ohci", 266 .name = "au1xxx-ohci",
267 .owner = THIS_MODULE,
262 .bus = &platform_bus_type, 268 .bus = &platform_bus_type,
263 .probe = ohci_hcd_au1xxx_drv_probe, 269 .probe = ohci_hcd_au1xxx_drv_probe,
264 .remove = ohci_hcd_au1xxx_drv_remove, 270 .remove = ohci_hcd_au1xxx_drv_remove,
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c
index 7924c74f958e..7bfffcbbd226 100644
--- a/drivers/usb/host/ohci-dbg.c
+++ b/drivers/usb/host/ohci-dbg.c
@@ -193,10 +193,6 @@ ohci_dump_status (struct ohci_hcd *controller, char **next, unsigned *size)
193 193
194 maybe_print_eds (controller, "donehead", 194 maybe_print_eds (controller, "donehead",
195 ohci_readl (controller, &regs->donehead), next, size); 195 ohci_readl (controller, &regs->donehead), next, size);
196
197 /* broken fminterval means traffic won't flow! */
198 ohci_dbg (controller, "fminterval %08x\n",
199 ohci_readl (controller, &regs->fminterval));
200} 196}
201 197
202#define dbg_port_sw(hc,num,value,next,size) \ 198#define dbg_port_sw(hc,num,value,next,size) \
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 67c1aa5eb1c1..5c0c6c8a7a82 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -180,7 +180,7 @@ static int ohci_urb_enqueue (
180 struct usb_hcd *hcd, 180 struct usb_hcd *hcd,
181 struct usb_host_endpoint *ep, 181 struct usb_host_endpoint *ep,
182 struct urb *urb, 182 struct urb *urb,
183 unsigned mem_flags 183 gfp_t mem_flags
184) { 184) {
185 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 185 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
186 struct ed *ed; 186 struct ed *ed;
@@ -723,7 +723,7 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd, struct pt_regs *ptregs)
723 ohci_vdbg (ohci, "resume detect\n"); 723 ohci_vdbg (ohci, "resume detect\n");
724 ohci_writel (ohci, OHCI_INTR_RD, &regs->intrstatus); 724 ohci_writel (ohci, OHCI_INTR_RD, &regs->intrstatus);
725 if (hcd->state != HC_STATE_QUIESCING) 725 if (hcd->state != HC_STATE_QUIESCING)
726 schedule_work(&ohci->rh_resume); 726 usb_hcd_resume_root_hub(hcd);
727 } 727 }
728 728
729 if (ints & OHCI_INTR_WDH) { 729 if (ints & OHCI_INTR_WDH) {
@@ -791,7 +791,7 @@ static void ohci_stop (struct usb_hcd *hcd)
791 791
792/* must not be called from interrupt context */ 792/* must not be called from interrupt context */
793 793
794#if defined(CONFIG_USB_SUSPEND) || defined(CONFIG_PM) 794#ifdef CONFIG_PM
795 795
796static int ohci_restart (struct ohci_hcd *ohci) 796static int ohci_restart (struct ohci_hcd *ohci)
797{ 797{
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index ce7b28da7a15..e01e77bc324b 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -36,7 +36,7 @@
36 36
37/*-------------------------------------------------------------------------*/ 37/*-------------------------------------------------------------------------*/
38 38
39#if defined(CONFIG_USB_SUSPEND) || defined(CONFIG_PM) 39#ifdef CONFIG_PM
40 40
41#define OHCI_SCHED_ENABLES \ 41#define OHCI_SCHED_ENABLES \
42 (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE) 42 (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE)
@@ -45,7 +45,7 @@ static void dl_done_list (struct ohci_hcd *, struct pt_regs *);
45static void finish_unlinks (struct ohci_hcd *, u16 , struct pt_regs *); 45static void finish_unlinks (struct ohci_hcd *, u16 , struct pt_regs *);
46static int ohci_restart (struct ohci_hcd *ohci); 46static int ohci_restart (struct ohci_hcd *ohci);
47 47
48static int ohci_hub_suspend (struct usb_hcd *hcd) 48static int ohci_bus_suspend (struct usb_hcd *hcd)
49{ 49{
50 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 50 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
51 int status = 0; 51 int status = 0;
@@ -73,7 +73,6 @@ static int ohci_hub_suspend (struct usb_hcd *hcd)
73 ohci_dbg (ohci, "suspend root hub\n"); 73 ohci_dbg (ohci, "suspend root hub\n");
74 74
75 /* First stop any processing */ 75 /* First stop any processing */
76 hcd->state = HC_STATE_QUIESCING;
77 if (ohci->hc_control & OHCI_SCHED_ENABLES) { 76 if (ohci->hc_control & OHCI_SCHED_ENABLES) {
78 int limit; 77 int limit;
79 78
@@ -108,7 +107,9 @@ static int ohci_hub_suspend (struct usb_hcd *hcd)
108 else 107 else
109 ohci->hc_control &= ~OHCI_CTRL_RWE; 108 ohci->hc_control &= ~OHCI_CTRL_RWE;
110 109
111 /* Suspend hub */ 110 /* Suspend hub ... this is the "global (to this bus) suspend" mode,
111 * which doesn't imply ports will first be individually suspended.
112 */
112 ohci->hc_control &= ~OHCI_CTRL_HCFS; 113 ohci->hc_control &= ~OHCI_CTRL_HCFS;
113 ohci->hc_control |= OHCI_USB_SUSPEND; 114 ohci->hc_control |= OHCI_USB_SUSPEND;
114 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 115 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
@@ -118,8 +119,9 @@ static int ohci_hub_suspend (struct usb_hcd *hcd)
118 ohci->next_statechange = jiffies + msecs_to_jiffies (5); 119 ohci->next_statechange = jiffies + msecs_to_jiffies (5);
119 120
120done: 121done:
122 /* external suspend vs self autosuspend ... same effect */
121 if (status == 0) 123 if (status == 0)
122 hcd->state = HC_STATE_SUSPENDED; 124 usb_hcd_suspend_root_hub(hcd);
123 spin_unlock_irqrestore (&ohci->lock, flags); 125 spin_unlock_irqrestore (&ohci->lock, flags);
124 return status; 126 return status;
125} 127}
@@ -133,7 +135,7 @@ static inline struct ed *find_head (struct ed *ed)
133} 135}
134 136
135/* caller has locked the root hub */ 137/* caller has locked the root hub */
136static int ohci_hub_resume (struct usb_hcd *hcd) 138static int ohci_bus_resume (struct usb_hcd *hcd)
137{ 139{
138 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 140 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
139 u32 temp, enables; 141 u32 temp, enables;
@@ -146,7 +148,7 @@ static int ohci_hub_resume (struct usb_hcd *hcd)
146 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); 148 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
147 149
148 if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) { 150 if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) {
149 /* this can happen after suspend-to-disk */ 151 /* this can happen after resuming a swsusp snapshot */
150 if (hcd->state == HC_STATE_RESUMING) { 152 if (hcd->state == HC_STATE_RESUMING) {
151 ohci_dbg (ohci, "BIOS/SMM active, control %03x\n", 153 ohci_dbg (ohci, "BIOS/SMM active, control %03x\n",
152 ohci->hc_control); 154 ohci->hc_control);
@@ -169,11 +171,12 @@ static int ohci_hub_resume (struct usb_hcd *hcd)
169 ohci_info (ohci, "wakeup\n"); 171 ohci_info (ohci, "wakeup\n");
170 break; 172 break;
171 case OHCI_USB_OPER: 173 case OHCI_USB_OPER:
172 ohci_dbg (ohci, "already resumed\n"); 174 /* this can happen after resuming a swsusp snapshot */
173 status = 0; 175 ohci_dbg (ohci, "snapshot resume? reinit\n");
176 status = -EBUSY;
174 break; 177 break;
175 default: /* RESET, we lost power */ 178 default: /* RESET, we lost power */
176 ohci_dbg (ohci, "root hub hardware reset\n"); 179 ohci_dbg (ohci, "lost power\n");
177 status = -EBUSY; 180 status = -EBUSY;
178 } 181 }
179 spin_unlock_irq (&ohci->lock); 182 spin_unlock_irq (&ohci->lock);
@@ -198,8 +201,7 @@ static int ohci_hub_resume (struct usb_hcd *hcd)
198 } 201 }
199 202
200 /* Some controllers (lucent erratum) need extra-long delays */ 203 /* Some controllers (lucent erratum) need extra-long delays */
201 hcd->state = HC_STATE_RESUMING; 204 msleep (20 /* usb 11.5.1.10 */ + 12 /* 32 msec counter */ + 1);
202 mdelay (20 /* usb 11.5.1.10 */ + 15);
203 205
204 temp = ohci_readl (ohci, &ohci->regs->control); 206 temp = ohci_readl (ohci, &ohci->regs->control);
205 temp &= OHCI_CTRL_HCFS; 207 temp &= OHCI_CTRL_HCFS;
@@ -273,28 +275,10 @@ static int ohci_hub_resume (struct usb_hcd *hcd)
273 (void) ohci_readl (ohci, &ohci->regs->control); 275 (void) ohci_readl (ohci, &ohci->regs->control);
274 } 276 }
275 277
276 hcd->state = HC_STATE_RUNNING;
277 return 0; 278 return 0;
278} 279}
279 280
280static void ohci_rh_resume (void *_hcd) 281#endif /* CONFIG_PM */
281{
282 struct usb_hcd *hcd = _hcd;
283
284 usb_lock_device (hcd->self.root_hub);
285 (void) ohci_hub_resume (hcd);
286 usb_unlock_device (hcd->self.root_hub);
287}
288
289#else
290
291static void ohci_rh_resume (void *_hcd)
292{
293 struct ohci_hcd *ohci = hcd_to_ohci (_hcd);
294 ohci_dbg(ohci, "rh_resume ??\n");
295}
296
297#endif /* CONFIG_USB_SUSPEND || CONFIG_PM */
298 282
299/*-------------------------------------------------------------------------*/ 283/*-------------------------------------------------------------------------*/
300 284
@@ -367,7 +351,6 @@ done:
367#ifdef CONFIG_PM 351#ifdef CONFIG_PM
368 /* save power by suspending idle root hubs; 352 /* save power by suspending idle root hubs;
369 * INTR_RD wakes us when there's work 353 * INTR_RD wakes us when there's work
370 * NOTE: if we can do this, we don't need a root hub timer!
371 */ 354 */
372 if (can_suspend 355 if (can_suspend
373 && !changed 356 && !changed
@@ -379,8 +362,7 @@ done:
379 && usb_trylock_device (hcd->self.root_hub) 362 && usb_trylock_device (hcd->self.root_hub)
380 ) { 363 ) {
381 ohci_vdbg (ohci, "autosuspend\n"); 364 ohci_vdbg (ohci, "autosuspend\n");
382 (void) ohci_hub_suspend (hcd); 365 (void) ohci_bus_suspend (hcd);
383 hcd->state = HC_STATE_RUNNING;
384 usb_unlock_device (hcd->self.root_hub); 366 usb_unlock_device (hcd->self.root_hub);
385 } 367 }
386#endif 368#endif
@@ -554,7 +536,7 @@ static int ohci_hub_control (
554 temp = RH_PS_POCI; 536 temp = RH_PS_POCI;
555 if ((ohci->hc_control & OHCI_CTRL_HCFS) 537 if ((ohci->hc_control & OHCI_CTRL_HCFS)
556 != OHCI_USB_OPER) 538 != OHCI_USB_OPER)
557 schedule_work (&ohci->rh_resume); 539 usb_hcd_resume_root_hub(hcd);
558 break; 540 break;
559 case USB_PORT_FEAT_C_SUSPEND: 541 case USB_PORT_FEAT_C_SUSPEND:
560 temp = RH_PS_PSSC; 542 temp = RH_PS_PSSC;
diff --git a/drivers/usb/host/ohci-lh7a404.c b/drivers/usb/host/ohci-lh7a404.c
index 859aca7be753..238fa4ade615 100644
--- a/drivers/usb/host/ohci-lh7a404.c
+++ b/drivers/usb/host/ohci-lh7a404.c
@@ -193,6 +193,11 @@ static const struct hc_driver ohci_lh7a404_hc_driver = {
193 */ 193 */
194 .hub_status_data = ohci_hub_status_data, 194 .hub_status_data = ohci_hub_status_data,
195 .hub_control = ohci_hub_control, 195 .hub_control = ohci_hub_control,
196#ifdef CONFIG_PM
197 .bus_suspend = ohci_bus_suspend,
198 .bus_resume = ohci_bus_resume,
199#endif
200 .start_port_reset = ohci_start_port_reset,
196}; 201};
197 202
198/*-------------------------------------------------------------------------*/ 203/*-------------------------------------------------------------------------*/
@@ -239,6 +244,7 @@ static int ohci_hcd_lh7a404_drv_resume(struct device *dev)
239 244
240static struct device_driver ohci_hcd_lh7a404_driver = { 245static struct device_driver ohci_hcd_lh7a404_driver = {
241 .name = "lh7a404-ohci", 246 .name = "lh7a404-ohci",
247 .owner = THIS_MODULE,
242 .bus = &platform_bus_type, 248 .bus = &platform_bus_type,
243 .probe = ohci_hcd_lh7a404_drv_probe, 249 .probe = ohci_hcd_lh7a404_drv_probe,
244 .remove = ohci_hcd_lh7a404_drv_remove, 250 .remove = ohci_hcd_lh7a404_drv_remove,
diff --git a/drivers/usb/host/ohci-mem.c b/drivers/usb/host/ohci-mem.c
index fd3c4d3714bd..bfbe328a4788 100644
--- a/drivers/usb/host/ohci-mem.c
+++ b/drivers/usb/host/ohci-mem.c
@@ -28,7 +28,6 @@ static void ohci_hcd_init (struct ohci_hcd *ohci)
28 ohci->next_statechange = jiffies; 28 ohci->next_statechange = jiffies;
29 spin_lock_init (&ohci->lock); 29 spin_lock_init (&ohci->lock);
30 INIT_LIST_HEAD (&ohci->pending); 30 INIT_LIST_HEAD (&ohci->pending);
31 INIT_WORK (&ohci->rh_resume, ohci_rh_resume, ohci_to_hcd(ohci));
32 ohci->reboot_notifier.notifier_call = ohci_reboot; 31 ohci->reboot_notifier.notifier_call = ohci_reboot;
33} 32}
34 33
@@ -84,7 +83,7 @@ dma_to_td (struct ohci_hcd *hc, dma_addr_t td_dma)
84 83
85/* TDs ... */ 84/* TDs ... */
86static struct td * 85static struct td *
87td_alloc (struct ohci_hcd *hc, unsigned mem_flags) 86td_alloc (struct ohci_hcd *hc, gfp_t mem_flags)
88{ 87{
89 dma_addr_t dma; 88 dma_addr_t dma;
90 struct td *td; 89 struct td *td;
@@ -118,7 +117,7 @@ td_free (struct ohci_hcd *hc, struct td *td)
118 117
119/* EDs ... */ 118/* EDs ... */
120static struct ed * 119static struct ed *
121ed_alloc (struct ohci_hcd *hc, unsigned mem_flags) 120ed_alloc (struct ohci_hcd *hc, gfp_t mem_flags)
122{ 121{
123 dma_addr_t dma; 122 dma_addr_t dma;
124 struct ed *ed; 123 struct ed *ed;
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index d8f3ba7ad52e..49815ec4b842 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -14,6 +14,9 @@
14 * This file is licenced under the GPL. 14 * This file is licenced under the GPL.
15 */ 15 */
16 16
17#include <linux/signal.h> /* SA_INTERRUPT */
18#include <linux/jiffies.h>
19
17#include <asm/hardware.h> 20#include <asm/hardware.h>
18#include <asm/io.h> 21#include <asm/io.h>
19#include <asm/mach-types.h> 22#include <asm/mach-types.h>
@@ -420,9 +423,9 @@ static const struct hc_driver ohci_omap_hc_driver = {
420 */ 423 */
421 .hub_status_data = ohci_hub_status_data, 424 .hub_status_data = ohci_hub_status_data,
422 .hub_control = ohci_hub_control, 425 .hub_control = ohci_hub_control,
423#ifdef CONFIG_USB_SUSPEND 426#ifdef CONFIG_PM
424 .hub_suspend = ohci_hub_suspend, 427 .bus_suspend = ohci_bus_suspend,
425 .hub_resume = ohci_hub_resume, 428 .bus_resume = ohci_bus_resume,
426#endif 429#endif
427 .start_port_reset = ohci_start_port_reset, 430 .start_port_reset = ohci_start_port_reset,
428}; 431};
@@ -455,50 +458,32 @@ static int ohci_hcd_omap_drv_remove(struct device *dev)
455 458
456#ifdef CONFIG_PM 459#ifdef CONFIG_PM
457 460
458static int ohci_omap_suspend(struct device *dev, pm_message_t message, u32 level) 461static int ohci_omap_suspend(struct device *dev, pm_message_t message)
459{ 462{
460 struct ohci_hcd *ohci = hcd_to_ohci(dev_get_drvdata(dev)); 463 struct ohci_hcd *ohci = hcd_to_ohci(dev_get_drvdata(dev));
461 int status = -EINVAL; 464
462 465 if (time_before(jiffies, ohci->next_statechange))
463 if (level != SUSPEND_POWER_DOWN) 466 msleep(5);
464 return 0; 467 ohci->next_statechange = jiffies;
465 468
466 down(&ohci_to_hcd(ohci)->self.root_hub->serialize); 469 omap_ohci_clock_power(0);
467 status = ohci_hub_suspend(ohci_to_hcd(ohci)); 470 ohci_to_hcd(ohci)->state = HC_STATE_SUSPENDED;
468 if (status == 0) { 471 dev->power.power_state = PMSG_SUSPEND;
469 omap_ohci_clock_power(0); 472 return 0;
470 ohci_to_hcd(ohci)->self.root_hub->state =
471 USB_STATE_SUSPENDED;
472 ohci_to_hcd(ohci)->state = HC_STATE_SUSPENDED;
473 dev->power.power_state = PMSG_SUSPEND;
474 }
475 up(&ohci_to_hcd(ohci)->self.root_hub->serialize);
476 return status;
477} 473}
478 474
479static int ohci_omap_resume(struct device *dev, u32 level) 475static int ohci_omap_resume(struct device *dev)
480{ 476{
481 struct ohci_hcd *ohci = hcd_to_ohci(dev_get_drvdata(dev)); 477 struct ohci_hcd *ohci = hcd_to_ohci(dev_get_drvdata(dev));
482 int status = 0;
483
484 if (level != RESUME_POWER_ON)
485 return 0;
486 478
487 if (time_before(jiffies, ohci->next_statechange)) 479 if (time_before(jiffies, ohci->next_statechange))
488 msleep(5); 480 msleep(5);
489 ohci->next_statechange = jiffies; 481 ohci->next_statechange = jiffies;
482
490 omap_ohci_clock_power(1); 483 omap_ohci_clock_power(1);
491#ifdef CONFIG_USB_SUSPEND 484 dev->power.power_state = PMSG_ON;
492 /* get extra cleanup even if remote wakeup isn't in use */ 485 usb_hcd_resume_root_hub(dev_get_drvdata(dev));
493 status = usb_resume_device(ohci_to_hcd(ohci)->self.root_hub); 486 return 0;
494#else
495 down(&ohci_to_hcd(ohci)->self.root_hub->serialize);
496 status = ohci_hub_resume(ohci_to_hcd(ohci));
497 up(&ohci_to_hcd(ohci)->self.root_hub->serialize);
498#endif
499 if (status == 0)
500 dev->power.power_state = PMSG_ON;
501 return status;
502} 487}
503 488
504#endif 489#endif
@@ -510,6 +495,7 @@ static int ohci_omap_resume(struct device *dev, u32 level)
510 */ 495 */
511static struct device_driver ohci_hcd_omap_driver = { 496static struct device_driver ohci_hcd_omap_driver = {
512 .name = "ohci", 497 .name = "ohci",
498 .owner = THIS_MODULE,
513 .bus = &platform_bus_type, 499 .bus = &platform_bus_type,
514 .probe = ohci_hcd_omap_drv_probe, 500 .probe = ohci_hcd_omap_drv_probe,
515 .remove = ohci_hcd_omap_drv_remove, 501 .remove = ohci_hcd_omap_drv_remove,
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c
index eede6be098d2..7ce1d9ef0289 100644
--- a/drivers/usb/host/ohci-pci.c
+++ b/drivers/usb/host/ohci-pci.c
@@ -14,6 +14,8 @@
14 * This file is licenced under the GPL. 14 * This file is licenced under the GPL.
15 */ 15 */
16 16
17#include <linux/jiffies.h>
18
17#ifdef CONFIG_PPC_PMAC 19#ifdef CONFIG_PPC_PMAC
18#include <asm/machdep.h> 20#include <asm/machdep.h>
19#include <asm/pmac_feature.h> 21#include <asm/pmac_feature.h>
@@ -112,23 +114,13 @@ ohci_pci_start (struct usb_hcd *hcd)
112 114
113static int ohci_pci_suspend (struct usb_hcd *hcd, pm_message_t message) 115static int ohci_pci_suspend (struct usb_hcd *hcd, pm_message_t message)
114{ 116{
115 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 117 /* root hub was already suspended */
116
117 /* suspend root hub, hoping it keeps power during suspend */
118 if (time_before (jiffies, ohci->next_statechange))
119 msleep (100);
120
121#ifdef CONFIG_USB_SUSPEND
122 (void) usb_suspend_device (hcd->self.root_hub, message);
123#else
124 usb_lock_device (hcd->self.root_hub);
125 (void) ohci_hub_suspend (hcd);
126 usb_unlock_device (hcd->self.root_hub);
127#endif
128 118
129 /* let things settle down a bit */ 119 /* FIXME these PMAC things get called in the wrong places. ASIC
130 msleep (100); 120 * clocks should be turned off AFTER entering D3, and on BEFORE
131 121 * trying to enter D0. Evidently the PCI layer doesn't currently
122 * provide the right sort of platform hooks for this ...
123 */
132#ifdef CONFIG_PPC_PMAC 124#ifdef CONFIG_PPC_PMAC
133 if (_machine == _MACH_Pmac) { 125 if (_machine == _MACH_Pmac) {
134 struct device_node *of_node; 126 struct device_node *of_node;
@@ -145,9 +137,6 @@ static int ohci_pci_suspend (struct usb_hcd *hcd, pm_message_t message)
145 137
146static int ohci_pci_resume (struct usb_hcd *hcd) 138static int ohci_pci_resume (struct usb_hcd *hcd)
147{ 139{
148 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
149 int retval = 0;
150
151#ifdef CONFIG_PPC_PMAC 140#ifdef CONFIG_PPC_PMAC
152 if (_machine == _MACH_Pmac) { 141 if (_machine == _MACH_Pmac) {
153 struct device_node *of_node; 142 struct device_node *of_node;
@@ -159,19 +148,8 @@ static int ohci_pci_resume (struct usb_hcd *hcd)
159 } 148 }
160#endif /* CONFIG_PPC_PMAC */ 149#endif /* CONFIG_PPC_PMAC */
161 150
162 /* resume root hub */ 151 usb_hcd_resume_root_hub(hcd);
163 if (time_before (jiffies, ohci->next_statechange)) 152 return 0;
164 msleep (100);
165#ifdef CONFIG_USB_SUSPEND
166 /* get extra cleanup even if remote wakeup isn't in use */
167 retval = usb_resume_device (hcd->self.root_hub);
168#else
169 usb_lock_device (hcd->self.root_hub);
170 retval = ohci_hub_resume (hcd);
171 usb_unlock_device (hcd->self.root_hub);
172#endif
173
174 return retval;
175} 153}
176 154
177#endif /* CONFIG_PM */ 155#endif /* CONFIG_PM */
@@ -218,9 +196,9 @@ static const struct hc_driver ohci_pci_hc_driver = {
218 */ 196 */
219 .hub_status_data = ohci_hub_status_data, 197 .hub_status_data = ohci_hub_status_data,
220 .hub_control = ohci_hub_control, 198 .hub_control = ohci_hub_control,
221#ifdef CONFIG_USB_SUSPEND 199#ifdef CONFIG_PM
222 .hub_suspend = ohci_hub_suspend, 200 .bus_suspend = ohci_bus_suspend,
223 .hub_resume = ohci_hub_resume, 201 .bus_resume = ohci_bus_resume,
224#endif 202#endif
225 .start_port_reset = ohci_start_port_reset, 203 .start_port_reset = ohci_start_port_reset,
226}; 204};
@@ -240,6 +218,7 @@ MODULE_DEVICE_TABLE (pci, pci_ids);
240static struct pci_driver ohci_pci_driver = { 218static struct pci_driver ohci_pci_driver = {
241 .name = (char *) hcd_name, 219 .name = (char *) hcd_name,
242 .id_table = pci_ids, 220 .id_table = pci_ids,
221 .owner = THIS_MODULE,
243 222
244 .probe = usb_hcd_pci_probe, 223 .probe = usb_hcd_pci_probe,
245 .remove = usb_hcd_pci_remove, 224 .remove = usb_hcd_pci_remove,
diff --git a/drivers/usb/host/ohci-ppc-soc.c b/drivers/usb/host/ohci-ppc-soc.c
index 251533363028..4832e57ae579 100644
--- a/drivers/usb/host/ohci-ppc-soc.c
+++ b/drivers/usb/host/ohci-ppc-soc.c
@@ -163,9 +163,9 @@ static const struct hc_driver ohci_ppc_soc_hc_driver = {
163 */ 163 */
164 .hub_status_data = ohci_hub_status_data, 164 .hub_status_data = ohci_hub_status_data,
165 .hub_control = ohci_hub_control, 165 .hub_control = ohci_hub_control,
166#ifdef CONFIG_USB_SUSPEND 166#ifdef CONFIG_PM
167 .hub_suspend = ohci_hub_suspend, 167 .bus_suspend = ohci_bus_suspend,
168 .hub_resume = ohci_hub_resume, 168 .bus_resume = ohci_bus_resume,
169#endif 169#endif
170 .start_port_reset = ohci_start_port_reset, 170 .start_port_reset = ohci_start_port_reset,
171}; 171};
@@ -193,10 +193,11 @@ static int ohci_hcd_ppc_soc_drv_remove(struct device *dev)
193 193
194static struct device_driver ohci_hcd_ppc_soc_driver = { 194static struct device_driver ohci_hcd_ppc_soc_driver = {
195 .name = "ppc-soc-ohci", 195 .name = "ppc-soc-ohci",
196 .owner = THIS_MODULE,
196 .bus = &platform_bus_type, 197 .bus = &platform_bus_type,
197 .probe = ohci_hcd_ppc_soc_drv_probe, 198 .probe = ohci_hcd_ppc_soc_drv_probe,
198 .remove = ohci_hcd_ppc_soc_drv_remove, 199 .remove = ohci_hcd_ppc_soc_drv_remove,
199#if defined(CONFIG_USB_SUSPEND) || defined(CONFIG_PM) 200#ifdef CONFIG_PM
200 /*.suspend = ohci_hcd_ppc_soc_drv_suspend,*/ 201 /*.suspend = ohci_hcd_ppc_soc_drv_suspend,*/
201 /*.resume = ohci_hcd_ppc_soc_drv_resume,*/ 202 /*.resume = ohci_hcd_ppc_soc_drv_resume,*/
202#endif 203#endif
diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c
index 2fdb262d4726..f4a4aeda40b7 100644
--- a/drivers/usb/host/ohci-pxa27x.c
+++ b/drivers/usb/host/ohci-pxa27x.c
@@ -20,6 +20,7 @@
20 */ 20 */
21 21
22#include <linux/device.h> 22#include <linux/device.h>
23#include <linux/signal.h>
23#include <asm/mach-types.h> 24#include <asm/mach-types.h>
24#include <asm/hardware.h> 25#include <asm/hardware.h>
25#include <asm/arch/pxa-regs.h> 26#include <asm/arch/pxa-regs.h>
@@ -278,10 +279,11 @@ static const struct hc_driver ohci_pxa27x_hc_driver = {
278 */ 279 */
279 .hub_status_data = ohci_hub_status_data, 280 .hub_status_data = ohci_hub_status_data,
280 .hub_control = ohci_hub_control, 281 .hub_control = ohci_hub_control,
281#ifdef CONFIG_USB_SUSPEND 282#ifdef CONFIG_PM
282 .hub_suspend = ohci_hub_suspend, 283 .bus_suspend = ohci_bus_suspend,
283 .hub_resume = ohci_hub_resume, 284 .bus_resume = ohci_bus_resume,
284#endif 285#endif
286 .start_port_reset = ohci_start_port_reset,
285}; 287};
286 288
287/*-------------------------------------------------------------------------*/ 289/*-------------------------------------------------------------------------*/
@@ -309,7 +311,7 @@ static int ohci_hcd_pxa27x_drv_remove(struct device *dev)
309 return 0; 311 return 0;
310} 312}
311 313
312static int ohci_hcd_pxa27x_drv_suspend(struct device *dev, pm_message_t state, u32 level) 314static int ohci_hcd_pxa27x_drv_suspend(struct device *dev, pm_message_t state)
313{ 315{
314// struct platform_device *pdev = to_platform_device(dev); 316// struct platform_device *pdev = to_platform_device(dev);
315// struct usb_hcd *hcd = dev_get_drvdata(dev); 317// struct usb_hcd *hcd = dev_get_drvdata(dev);
@@ -318,7 +320,7 @@ static int ohci_hcd_pxa27x_drv_suspend(struct device *dev, pm_message_t state, u
318 return 0; 320 return 0;
319} 321}
320 322
321static int ohci_hcd_pxa27x_drv_resume(struct device *dev, u32 level) 323static int ohci_hcd_pxa27x_drv_resume(struct device *dev)
322{ 324{
323// struct platform_device *pdev = to_platform_device(dev); 325// struct platform_device *pdev = to_platform_device(dev);
324// struct usb_hcd *hcd = dev_get_drvdata(dev); 326// struct usb_hcd *hcd = dev_get_drvdata(dev);
diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c
index da7d5478f74d..fab420a2ce71 100644
--- a/drivers/usb/host/ohci-s3c2410.c
+++ b/drivers/usb/host/ohci-s3c2410.c
@@ -448,11 +448,11 @@ static const struct hc_driver ohci_s3c2410_hc_driver = {
448 */ 448 */
449 .hub_status_data = ohci_s3c2410_hub_status_data, 449 .hub_status_data = ohci_s3c2410_hub_status_data,
450 .hub_control = ohci_s3c2410_hub_control, 450 .hub_control = ohci_s3c2410_hub_control,
451 451#ifdef CONFIG_PM
452#if defined(CONFIG_USB_SUSPEND) && 0 452 .bus_suspend = ohci_bus_suspend,
453 .hub_suspend = ohci_hub_suspend, 453 .bus_resume = ohci_bus_resume,
454 .hub_resume = ohci_hub_resume,
455#endif 454#endif
455 .start_port_reset = ohci_start_port_reset,
456}; 456};
457 457
458/* device driver */ 458/* device driver */
@@ -474,6 +474,7 @@ static int ohci_hcd_s3c2410_drv_remove(struct device *dev)
474 474
475static struct device_driver ohci_hcd_s3c2410_driver = { 475static struct device_driver ohci_hcd_s3c2410_driver = {
476 .name = "s3c2410-ohci", 476 .name = "s3c2410-ohci",
477 .owner = THIS_MODULE,
477 .bus = &platform_bus_type, 478 .bus = &platform_bus_type,
478 .probe = ohci_hcd_s3c2410_drv_probe, 479 .probe = ohci_hcd_s3c2410_drv_probe,
479 .remove = ohci_hcd_s3c2410_drv_remove, 480 .remove = ohci_hcd_s3c2410_drv_remove,
diff --git a/drivers/usb/host/ohci-sa1111.c b/drivers/usb/host/ohci-sa1111.c
index 814d2be4ee7b..fb3221ebbb29 100644
--- a/drivers/usb/host/ohci-sa1111.c
+++ b/drivers/usb/host/ohci-sa1111.c
@@ -235,10 +235,11 @@ static const struct hc_driver ohci_sa1111_hc_driver = {
235 */ 235 */
236 .hub_status_data = ohci_hub_status_data, 236 .hub_status_data = ohci_hub_status_data,
237 .hub_control = ohci_hub_control, 237 .hub_control = ohci_hub_control,
238#ifdef CONFIG_USB_SUSPEND 238#ifdef CONFIG_PM
239 .hub_suspend = ohci_hub_suspend, 239 .bus_suspend = ohci_bus_suspend,
240 .hub_resume = ohci_hub_resume, 240 .bus_resume = ohci_bus_resume,
241#endif 241#endif
242 .start_port_reset = ohci_start_port_reset,
242}; 243};
243 244
244/*-------------------------------------------------------------------------*/ 245/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
index 8a9b9d9209e9..caacf14371f5 100644
--- a/drivers/usb/host/ohci.h
+++ b/drivers/usb/host/ohci.h
@@ -389,7 +389,6 @@ struct ohci_hcd {
389 unsigned long next_statechange; /* suspend/resume */ 389 unsigned long next_statechange; /* suspend/resume */
390 u32 fminterval; /* saved register */ 390 u32 fminterval; /* saved register */
391 391
392 struct work_struct rh_resume;
393 struct notifier_block reboot_notifier; 392 struct notifier_block reboot_notifier;
394 393
395 unsigned long flags; /* for HC bugs */ 394 unsigned long flags; /* for HC bugs */
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
new file mode 100644
index 000000000000..b7fd3f644e1e
--- /dev/null
+++ b/drivers/usb/host/pci-quirks.c
@@ -0,0 +1,296 @@
1/*
2 * This file contains code to reset and initialize USB host controllers.
3 * Some of it includes work-arounds for PCI hardware and BIOS quirks.
4 * It may need to run early during booting -- before USB would normally
5 * initialize -- to ensure that Linux doesn't use any legacy modes.
6 *
7 * Copyright (c) 1999 Martin Mares <mj@ucw.cz>
8 * (and others)
9 */
10
11#include <linux/config.h>
12#ifdef CONFIG_USB_DEBUG
13#define DEBUG
14#else
15#undef DEBUG
16#endif
17
18#include <linux/types.h>
19#include <linux/kernel.h>
20#include <linux/pci.h>
21#include <linux/init.h>
22#include <linux/delay.h>
23#include <linux/acpi.h>
24
25
26#define UHCI_USBLEGSUP 0xc0 /* legacy support */
27#define UHCI_USBCMD 0 /* command register */
28#define UHCI_USBINTR 4 /* interrupt register */
29#define UHCI_USBLEGSUP_RWC 0x8f00 /* the R/WC bits */
30#define UHCI_USBLEGSUP_RO 0x5040 /* R/O and reserved bits */
31#define UHCI_USBCMD_RUN 0x0001 /* RUN/STOP bit */
32#define UHCI_USBCMD_HCRESET 0x0002 /* Host Controller reset */
33#define UHCI_USBCMD_EGSM 0x0008 /* Global Suspend Mode */
34#define UHCI_USBCMD_CONFIGURE 0x0040 /* Config Flag */
35#define UHCI_USBINTR_RESUME 0x0002 /* Resume interrupt enable */
36
37#define OHCI_CONTROL 0x04
38#define OHCI_CMDSTATUS 0x08
39#define OHCI_INTRSTATUS 0x0c
40#define OHCI_INTRENABLE 0x10
41#define OHCI_INTRDISABLE 0x14
42#define OHCI_OCR (1 << 3) /* ownership change request */
43#define OHCI_CTRL_RWC (1 << 9) /* remote wakeup connected */
44#define OHCI_CTRL_IR (1 << 8) /* interrupt routing */
45#define OHCI_INTR_OC (1 << 30) /* ownership change */
46
47#define EHCI_HCC_PARAMS 0x08 /* extended capabilities */
48#define EHCI_USBCMD 0 /* command register */
49#define EHCI_USBCMD_RUN (1 << 0) /* RUN/STOP bit */
50#define EHCI_USBSTS 4 /* status register */
51#define EHCI_USBSTS_HALTED (1 << 12) /* HCHalted bit */
52#define EHCI_USBINTR 8 /* interrupt register */
53#define EHCI_USBLEGSUP 0 /* legacy support register */
54#define EHCI_USBLEGSUP_BIOS (1 << 16) /* BIOS semaphore */
55#define EHCI_USBLEGSUP_OS (1 << 24) /* OS semaphore */
56#define EHCI_USBLEGCTLSTS 4 /* legacy control/status */
57#define EHCI_USBLEGCTLSTS_SOOE (1 << 13) /* SMI on ownership change */
58
59
60/*
61 * Make sure the controller is completely inactive, unable to
62 * generate interrupts or do DMA.
63 */
64void uhci_reset_hc(struct pci_dev *pdev, unsigned long base)
65{
66 /* Turn off PIRQ enable and SMI enable. (This also turns off the
67 * BIOS's USB Legacy Support.) Turn off all the R/WC bits too.
68 */
69 pci_write_config_word(pdev, UHCI_USBLEGSUP, UHCI_USBLEGSUP_RWC);
70
71 /* Reset the HC - this will force us to get a
72 * new notification of any already connected
73 * ports due to the virtual disconnect that it
74 * implies.
75 */
76 outw(UHCI_USBCMD_HCRESET, base + UHCI_USBCMD);
77 mb();
78 udelay(5);
79 if (inw(base + UHCI_USBCMD) & UHCI_USBCMD_HCRESET)
80 dev_warn(&pdev->dev, "HCRESET not completed yet!\n");
81
82 /* Just to be safe, disable interrupt requests and
83 * make sure the controller is stopped.
84 */
85 outw(0, base + UHCI_USBINTR);
86 outw(0, base + UHCI_USBCMD);
87}
88EXPORT_SYMBOL_GPL(uhci_reset_hc);
89
90/*
91 * Initialize a controller that was newly discovered or has just been
92 * resumed. In either case we can't be sure of its previous state.
93 *
94 * Returns: 1 if the controller was reset, 0 otherwise.
95 */
96int uhci_check_and_reset_hc(struct pci_dev *pdev, unsigned long base)
97{
98 u16 legsup;
99 unsigned int cmd, intr;
100
101 /*
102 * When restarting a suspended controller, we expect all the
103 * settings to be the same as we left them:
104 *
105 * PIRQ and SMI disabled, no R/W bits set in USBLEGSUP;
106 * Controller is stopped and configured with EGSM set;
107 * No interrupts enabled except possibly Resume Detect.
108 *
109 * If any of these conditions are violated we do a complete reset.
110 */
111 pci_read_config_word(pdev, UHCI_USBLEGSUP, &legsup);
112 if (legsup & ~(UHCI_USBLEGSUP_RO | UHCI_USBLEGSUP_RWC)) {
113 dev_dbg(&pdev->dev, "%s: legsup = 0x%04x\n",
114 __FUNCTION__, legsup);
115 goto reset_needed;
116 }
117
118 cmd = inw(base + UHCI_USBCMD);
119 if ((cmd & UHCI_USBCMD_RUN) || !(cmd & UHCI_USBCMD_CONFIGURE) ||
120 !(cmd & UHCI_USBCMD_EGSM)) {
121 dev_dbg(&pdev->dev, "%s: cmd = 0x%04x\n",
122 __FUNCTION__, cmd);
123 goto reset_needed;
124 }
125
126 intr = inw(base + UHCI_USBINTR);
127 if (intr & (~UHCI_USBINTR_RESUME)) {
128 dev_dbg(&pdev->dev, "%s: intr = 0x%04x\n",
129 __FUNCTION__, intr);
130 goto reset_needed;
131 }
132 return 0;
133
134reset_needed:
135 dev_dbg(&pdev->dev, "Performing full reset\n");
136 uhci_reset_hc(pdev, base);
137 return 1;
138}
139EXPORT_SYMBOL_GPL(uhci_check_and_reset_hc);
140
141static void __devinit quirk_usb_handoff_uhci(struct pci_dev *pdev)
142{
143 unsigned long base = 0;
144 int i;
145
146 for (i = 0; i < PCI_ROM_RESOURCE; i++)
147 if ((pci_resource_flags(pdev, i) & IORESOURCE_IO)) {
148 base = pci_resource_start(pdev, i);
149 break;
150 }
151
152 if (base)
153 uhci_check_and_reset_hc(pdev, base);
154}
155
156static void __devinit quirk_usb_handoff_ohci(struct pci_dev *pdev)
157{
158 void __iomem *base;
159 int wait_time;
160 u32 control;
161
162 base = ioremap_nocache(pci_resource_start(pdev, 0),
163 pci_resource_len(pdev, 0));
164 if (base == NULL) return;
165
166/* On PA-RISC, PDC can leave IR set incorrectly; ignore it there. */
167#ifndef __hppa__
168 control = readl(base + OHCI_CONTROL);
169 if (control & OHCI_CTRL_IR) {
170 wait_time = 500; /* arbitrary; 5 seconds */
171 writel(OHCI_INTR_OC, base + OHCI_INTRENABLE);
172 writel(OHCI_OCR, base + OHCI_CMDSTATUS);
173 while (wait_time > 0 &&
174 readl(base + OHCI_CONTROL) & OHCI_CTRL_IR) {
175 wait_time -= 10;
176 msleep(10);
177 }
178 if (wait_time <= 0)
179 printk(KERN_WARNING "%s %s: early BIOS handoff "
180 "failed (BIOS bug ?)\n",
181 pdev->dev.bus_id, "OHCI");
182
183 /* reset controller, preserving RWC */
184 writel(control & OHCI_CTRL_RWC, base + OHCI_CONTROL);
185 }
186#endif
187
188 /*
189 * disable interrupts
190 */
191 writel(~(u32)0, base + OHCI_INTRDISABLE);
192 writel(~(u32)0, base + OHCI_INTRSTATUS);
193
194 iounmap(base);
195}
196
197static void __devinit quirk_usb_disable_ehci(struct pci_dev *pdev)
198{
199 int wait_time, delta;
200 void __iomem *base, *op_reg_base;
201 u32 hcc_params, val, temp;
202 u8 cap_length;
203
204 base = ioremap_nocache(pci_resource_start(pdev, 0),
205 pci_resource_len(pdev, 0));
206 if (base == NULL) return;
207
208 cap_length = readb(base);
209 op_reg_base = base + cap_length;
210 hcc_params = readl(base + EHCI_HCC_PARAMS);
211 hcc_params = (hcc_params >> 8) & 0xff;
212 if (hcc_params) {
213 pci_read_config_dword(pdev,
214 hcc_params + EHCI_USBLEGSUP,
215 &val);
216 if (((val & 0xff) == 1) && (val & EHCI_USBLEGSUP_BIOS)) {
217 /*
218 * Ok, BIOS is in smm mode, try to hand off...
219 */
220 pci_read_config_dword(pdev,
221 hcc_params + EHCI_USBLEGCTLSTS,
222 &temp);
223 pci_write_config_dword(pdev,
224 hcc_params + EHCI_USBLEGCTLSTS,
225 temp | EHCI_USBLEGCTLSTS_SOOE);
226 val |= EHCI_USBLEGSUP_OS;
227 pci_write_config_dword(pdev,
228 hcc_params + EHCI_USBLEGSUP,
229 val);
230
231 wait_time = 500;
232 do {
233 msleep(10);
234 wait_time -= 10;
235 pci_read_config_dword(pdev,
236 hcc_params + EHCI_USBLEGSUP,
237 &val);
238 } while (wait_time && (val & EHCI_USBLEGSUP_BIOS));
239 if (!wait_time) {
240 /*
241 * well, possibly buggy BIOS...
242 */
243 printk(KERN_WARNING "%s %s: early BIOS handoff "
244 "failed (BIOS bug ?)\n",
245 pdev->dev.bus_id, "EHCI");
246 pci_write_config_dword(pdev,
247 hcc_params + EHCI_USBLEGSUP,
248 EHCI_USBLEGSUP_OS);
249 pci_write_config_dword(pdev,
250 hcc_params + EHCI_USBLEGCTLSTS,
251 0);
252 }
253 }
254 }
255
256 /*
257 * halt EHCI & disable its interrupts in any case
258 */
259 val = readl(op_reg_base + EHCI_USBSTS);
260 if ((val & EHCI_USBSTS_HALTED) == 0) {
261 val = readl(op_reg_base + EHCI_USBCMD);
262 val &= ~EHCI_USBCMD_RUN;
263 writel(val, op_reg_base + EHCI_USBCMD);
264
265 wait_time = 2000;
266 delta = 100;
267 do {
268 writel(0x3f, op_reg_base + EHCI_USBSTS);
269 udelay(delta);
270 wait_time -= delta;
271 val = readl(op_reg_base + EHCI_USBSTS);
272 if ((val == ~(u32)0) || (val & EHCI_USBSTS_HALTED)) {
273 break;
274 }
275 } while (wait_time > 0);
276 }
277 writel(0, op_reg_base + EHCI_USBINTR);
278 writel(0x3f, op_reg_base + EHCI_USBSTS);
279
280 iounmap(base);
281
282 return;
283}
284
285
286
287static void __devinit quirk_usb_early_handoff(struct pci_dev *pdev)
288{
289 if (pdev->class == PCI_CLASS_SERIAL_USB_UHCI)
290 quirk_usb_handoff_uhci(pdev);
291 else if (pdev->class == PCI_CLASS_SERIAL_USB_OHCI)
292 quirk_usb_handoff_ohci(pdev);
293 else if (pdev->class == PCI_CLASS_SERIAL_USB_EHCI)
294 quirk_usb_disable_ehci(pdev);
295}
296DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, quirk_usb_early_handoff);
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index d42a15d10a46..40169d9cf2b1 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -818,7 +818,7 @@ static int sl811h_urb_enqueue(
818 struct usb_hcd *hcd, 818 struct usb_hcd *hcd,
819 struct usb_host_endpoint *hep, 819 struct usb_host_endpoint *hep,
820 struct urb *urb, 820 struct urb *urb,
821 unsigned mem_flags 821 gfp_t mem_flags
822) { 822) {
823 struct sl811 *sl811 = hcd_to_sl811(hcd); 823 struct sl811 *sl811 = hcd_to_sl811(hcd);
824 struct usb_device *udev = urb->dev; 824 struct usb_device *udev = urb->dev;
@@ -1363,7 +1363,7 @@ error:
1363#ifdef CONFIG_PM 1363#ifdef CONFIG_PM
1364 1364
1365static int 1365static int
1366sl811h_hub_suspend(struct usb_hcd *hcd) 1366sl811h_bus_suspend(struct usb_hcd *hcd)
1367{ 1367{
1368 // SOFs off 1368 // SOFs off
1369 DBG("%s\n", __FUNCTION__); 1369 DBG("%s\n", __FUNCTION__);
@@ -1371,7 +1371,7 @@ sl811h_hub_suspend(struct usb_hcd *hcd)
1371} 1371}
1372 1372
1373static int 1373static int
1374sl811h_hub_resume(struct usb_hcd *hcd) 1374sl811h_bus_resume(struct usb_hcd *hcd)
1375{ 1375{
1376 // SOFs on 1376 // SOFs on
1377 DBG("%s\n", __FUNCTION__); 1377 DBG("%s\n", __FUNCTION__);
@@ -1380,8 +1380,8 @@ sl811h_hub_resume(struct usb_hcd *hcd)
1380 1380
1381#else 1381#else
1382 1382
1383#define sl811h_hub_suspend NULL 1383#define sl811h_bus_suspend NULL
1384#define sl811h_hub_resume NULL 1384#define sl811h_bus_resume NULL
1385 1385
1386#endif 1386#endif
1387 1387
@@ -1623,8 +1623,8 @@ static struct hc_driver sl811h_hc_driver = {
1623 */ 1623 */
1624 .hub_status_data = sl811h_hub_status_data, 1624 .hub_status_data = sl811h_hub_status_data,
1625 .hub_control = sl811h_hub_control, 1625 .hub_control = sl811h_hub_control,
1626 .hub_suspend = sl811h_hub_suspend, 1626 .bus_suspend = sl811h_bus_suspend,
1627 .hub_resume = sl811h_hub_resume, 1627 .bus_resume = sl811h_bus_resume,
1628}; 1628};
1629 1629
1630/*-------------------------------------------------------------------------*/ 1630/*-------------------------------------------------------------------------*/
@@ -1784,17 +1784,14 @@ sl811h_probe(struct device *dev)
1784 */ 1784 */
1785 1785
1786static int 1786static int
1787sl811h_suspend(struct device *dev, pm_message_t state, u32 phase) 1787sl811h_suspend(struct device *dev, pm_message_t state)
1788{ 1788{
1789 struct usb_hcd *hcd = dev_get_drvdata(dev); 1789 struct usb_hcd *hcd = dev_get_drvdata(dev);
1790 struct sl811 *sl811 = hcd_to_sl811(hcd); 1790 struct sl811 *sl811 = hcd_to_sl811(hcd);
1791 int retval = 0; 1791 int retval = 0;
1792 1792
1793 if (phase != SUSPEND_POWER_DOWN)
1794 return retval;
1795
1796 if (state.event == PM_EVENT_FREEZE) 1793 if (state.event == PM_EVENT_FREEZE)
1797 retval = sl811h_hub_suspend(hcd); 1794 retval = sl811h_bus_suspend(hcd);
1798 else if (state.event == PM_EVENT_SUSPEND) 1795 else if (state.event == PM_EVENT_SUSPEND)
1799 port_power(sl811, 0); 1796 port_power(sl811, 0);
1800 if (retval == 0) 1797 if (retval == 0)
@@ -1803,14 +1800,11 @@ sl811h_suspend(struct device *dev, pm_message_t state, u32 phase)
1803} 1800}
1804 1801
1805static int 1802static int
1806sl811h_resume(struct device *dev, u32 phase) 1803sl811h_resume(struct device *dev)
1807{ 1804{
1808 struct usb_hcd *hcd = dev_get_drvdata(dev); 1805 struct usb_hcd *hcd = dev_get_drvdata(dev);
1809 struct sl811 *sl811 = hcd_to_sl811(hcd); 1806 struct sl811 *sl811 = hcd_to_sl811(hcd);
1810 1807
1811 if (phase != RESUME_POWER_ON)
1812 return 0;
1813
1814 /* with no "check to see if VBUS is still powered" board hook, 1808 /* with no "check to see if VBUS is still powered" board hook,
1815 * let's assume it'd only be powered to enable remote wakeup. 1809 * let's assume it'd only be powered to enable remote wakeup.
1816 */ 1810 */
@@ -1822,7 +1816,7 @@ sl811h_resume(struct device *dev, u32 phase)
1822 } 1816 }
1823 1817
1824 dev->power.power_state = PMSG_ON; 1818 dev->power.power_state = PMSG_ON;
1825 return sl811h_hub_resume(hcd); 1819 return sl811h_bus_resume(hcd);
1826} 1820}
1827 1821
1828#else 1822#else
@@ -1837,6 +1831,7 @@ sl811h_resume(struct device *dev, u32 phase)
1837struct device_driver sl811h_driver = { 1831struct device_driver sl811h_driver = {
1838 .name = (char *) hcd_name, 1832 .name = (char *) hcd_name,
1839 .bus = &platform_bus_type, 1833 .bus = &platform_bus_type,
1834 .owner = THIS_MODULE,
1840 1835
1841 .probe = sl811h_probe, 1836 .probe = sl811h_probe,
1842 .remove = __devexit_p(sl811h_remove), 1837 .remove = __devexit_p(sl811h_remove),
diff --git a/drivers/usb/host/uhci-debug.c b/drivers/usb/host/uhci-debug.c
index 4538a98b6f9d..151154df37fa 100644
--- a/drivers/usb/host/uhci-debug.c
+++ b/drivers/usb/host/uhci-debug.c
@@ -348,7 +348,6 @@ static int uhci_show_urbp(struct uhci_hcd *uhci, struct urb_priv *urbp, char *bu
348 348
349 if (urbp->urb->status != -EINPROGRESS) 349 if (urbp->urb->status != -EINPROGRESS)
350 out += sprintf(out, "Status=%d ", urbp->urb->status); 350 out += sprintf(out, "Status=%d ", urbp->urb->status);
351 //out += sprintf(out, "Inserttime=%lx ",urbp->inserttime);
352 //out += sprintf(out, "FSBRtime=%lx ",urbp->fsbrtime); 351 //out += sprintf(out, "FSBRtime=%lx ",urbp->fsbrtime);
353 352
354 count = 0; 353 count = 0;
@@ -446,11 +445,11 @@ static int uhci_sprint_schedule(struct uhci_hcd *uhci, char *buf, int len)
446 out += sprintf(out, "Frame List\n"); 445 out += sprintf(out, "Frame List\n");
447 for (i = 0; i < UHCI_NUMFRAMES; ++i) { 446 for (i = 0; i < UHCI_NUMFRAMES; ++i) {
448 int shown = 0; 447 int shown = 0;
449 td = uhci->fl->frame_cpu[i]; 448 td = uhci->frame_cpu[i];
450 if (!td) 449 if (!td)
451 continue; 450 continue;
452 451
453 if (td->dma_handle != (dma_addr_t)uhci->fl->frame[i]) { 452 if (td->dma_handle != (dma_addr_t)uhci->frame[i]) {
454 show_frame_num(); 453 show_frame_num();
455 out += sprintf(out, " frame list does not match td->dma_handle!\n"); 454 out += sprintf(out, " frame list does not match td->dma_handle!\n");
456 } 455 }
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index 0c024898cbea..15e0a511069b 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -101,37 +101,16 @@ static void uhci_get_current_frame_number(struct uhci_hcd *uhci);
101#include "uhci-q.c" 101#include "uhci-q.c"
102#include "uhci-hub.c" 102#include "uhci-hub.c"
103 103
104extern void uhci_reset_hc(struct pci_dev *pdev, unsigned long base);
105extern int uhci_check_and_reset_hc(struct pci_dev *pdev, unsigned long base);
106
104/* 107/*
105 * Make sure the controller is completely inactive, unable to 108 * Finish up a host controller reset and update the recorded state.
106 * generate interrupts or do DMA.
107 */ 109 */
108static void reset_hc(struct uhci_hcd *uhci) 110static void finish_reset(struct uhci_hcd *uhci)
109{ 111{
110 int port; 112 int port;
111 113
112 /* Turn off PIRQ enable and SMI enable. (This also turns off the
113 * BIOS's USB Legacy Support.) Turn off all the R/WC bits too.
114 */
115 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP,
116 USBLEGSUP_RWC);
117
118 /* Reset the HC - this will force us to get a
119 * new notification of any already connected
120 * ports due to the virtual disconnect that it
121 * implies.
122 */
123 outw(USBCMD_HCRESET, uhci->io_addr + USBCMD);
124 mb();
125 udelay(5);
126 if (inw(uhci->io_addr + USBCMD) & USBCMD_HCRESET)
127 dev_warn(uhci_dev(uhci), "HCRESET not completed yet!\n");
128
129 /* Just to be safe, disable interrupt requests and
130 * make sure the controller is stopped.
131 */
132 outw(0, uhci->io_addr + USBINTR);
133 outw(0, uhci->io_addr + USBCMD);
134
135 /* HCRESET doesn't affect the Suspend, Reset, and Resume Detect 114 /* HCRESET doesn't affect the Suspend, Reset, and Resume Detect
136 * bits in the port status and control registers. 115 * bits in the port status and control registers.
137 * We have to clear them by hand. 116 * We have to clear them by hand.
@@ -153,7 +132,8 @@ static void reset_hc(struct uhci_hcd *uhci)
153 */ 132 */
154static void hc_died(struct uhci_hcd *uhci) 133static void hc_died(struct uhci_hcd *uhci)
155{ 134{
156 reset_hc(uhci); 135 uhci_reset_hc(to_pci_dev(uhci_dev(uhci)), uhci->io_addr);
136 finish_reset(uhci);
157 uhci->hc_inaccessible = 1; 137 uhci->hc_inaccessible = 1;
158} 138}
159 139
@@ -163,44 +143,8 @@ static void hc_died(struct uhci_hcd *uhci)
163 */ 143 */
164static void check_and_reset_hc(struct uhci_hcd *uhci) 144static void check_and_reset_hc(struct uhci_hcd *uhci)
165{ 145{
166 u16 legsup; 146 if (uhci_check_and_reset_hc(to_pci_dev(uhci_dev(uhci)), uhci->io_addr))
167 unsigned int cmd, intr; 147 finish_reset(uhci);
168
169 /*
170 * When restarting a suspended controller, we expect all the
171 * settings to be the same as we left them:
172 *
173 * PIRQ and SMI disabled, no R/W bits set in USBLEGSUP;
174 * Controller is stopped and configured with EGSM set;
175 * No interrupts enabled except possibly Resume Detect.
176 *
177 * If any of these conditions are violated we do a complete reset.
178 */
179 pci_read_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, &legsup);
180 if (legsup & ~(USBLEGSUP_RO | USBLEGSUP_RWC)) {
181 dev_dbg(uhci_dev(uhci), "%s: legsup = 0x%04x\n",
182 __FUNCTION__, legsup);
183 goto reset_needed;
184 }
185
186 cmd = inw(uhci->io_addr + USBCMD);
187 if ((cmd & USBCMD_RS) || !(cmd & USBCMD_CF) || !(cmd & USBCMD_EGSM)) {
188 dev_dbg(uhci_dev(uhci), "%s: cmd = 0x%04x\n",
189 __FUNCTION__, cmd);
190 goto reset_needed;
191 }
192
193 intr = inw(uhci->io_addr + USBINTR);
194 if (intr & (~USBINTR_RESUME)) {
195 dev_dbg(uhci_dev(uhci), "%s: intr = 0x%04x\n",
196 __FUNCTION__, intr);
197 goto reset_needed;
198 }
199 return;
200
201reset_needed:
202 dev_dbg(uhci_dev(uhci), "Performing full reset\n");
203 reset_hc(uhci);
204} 148}
205 149
206/* 150/*
@@ -212,13 +156,13 @@ static void configure_hc(struct uhci_hcd *uhci)
212 outb(USBSOF_DEFAULT, uhci->io_addr + USBSOF); 156 outb(USBSOF_DEFAULT, uhci->io_addr + USBSOF);
213 157
214 /* Store the frame list base address */ 158 /* Store the frame list base address */
215 outl(uhci->fl->dma_handle, uhci->io_addr + USBFLBASEADD); 159 outl(uhci->frame_dma_handle, uhci->io_addr + USBFLBASEADD);
216 160
217 /* Set the current frame number */ 161 /* Set the current frame number */
218 outw(uhci->frame_number, uhci->io_addr + USBFRNUM); 162 outw(uhci->frame_number, uhci->io_addr + USBFRNUM);
219 163
220 /* Mark controller as running before we enable interrupts */ 164 /* Mark controller as not halted before we enable interrupts */
221 uhci_to_hcd(uhci)->state = HC_STATE_RUNNING; 165 uhci_to_hcd(uhci)->state = HC_STATE_SUSPENDED;
222 mb(); 166 mb();
223 167
224 /* Enable PIRQ */ 168 /* Enable PIRQ */
@@ -319,6 +263,7 @@ __acquires(uhci->lock)
319 263
320static void start_rh(struct uhci_hcd *uhci) 264static void start_rh(struct uhci_hcd *uhci)
321{ 265{
266 uhci_to_hcd(uhci)->state = HC_STATE_RUNNING;
322 uhci->is_stopped = 0; 267 uhci->is_stopped = 0;
323 smp_wmb(); 268 smp_wmb();
324 269
@@ -437,36 +382,21 @@ static void release_uhci(struct uhci_hcd *uhci)
437 int i; 382 int i;
438 383
439 for (i = 0; i < UHCI_NUM_SKELQH; i++) 384 for (i = 0; i < UHCI_NUM_SKELQH; i++)
440 if (uhci->skelqh[i]) { 385 uhci_free_qh(uhci, uhci->skelqh[i]);
441 uhci_free_qh(uhci, uhci->skelqh[i]);
442 uhci->skelqh[i] = NULL;
443 }
444 386
445 if (uhci->term_td) { 387 uhci_free_td(uhci, uhci->term_td);
446 uhci_free_td(uhci, uhci->term_td);
447 uhci->term_td = NULL;
448 }
449 388
450 if (uhci->qh_pool) { 389 dma_pool_destroy(uhci->qh_pool);
451 dma_pool_destroy(uhci->qh_pool);
452 uhci->qh_pool = NULL;
453 }
454 390
455 if (uhci->td_pool) { 391 dma_pool_destroy(uhci->td_pool);
456 dma_pool_destroy(uhci->td_pool);
457 uhci->td_pool = NULL;
458 }
459 392
460 if (uhci->fl) { 393 kfree(uhci->frame_cpu);
461 dma_free_coherent(uhci_dev(uhci), sizeof(*uhci->fl),
462 uhci->fl, uhci->fl->dma_handle);
463 uhci->fl = NULL;
464 }
465 394
466 if (uhci->dentry) { 395 dma_free_coherent(uhci_dev(uhci),
467 debugfs_remove(uhci->dentry); 396 UHCI_NUMFRAMES * sizeof(*uhci->frame),
468 uhci->dentry = NULL; 397 uhci->frame, uhci->frame_dma_handle);
469 } 398
399 debugfs_remove(uhci->dentry);
470} 400}
471 401
472static int uhci_reset(struct usb_hcd *hcd) 402static int uhci_reset(struct usb_hcd *hcd)
@@ -545,7 +475,6 @@ static int uhci_start(struct usb_hcd *hcd)
545 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 475 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
546 int retval = -EBUSY; 476 int retval = -EBUSY;
547 int i; 477 int i;
548 dma_addr_t dma_handle;
549 struct dentry *dentry; 478 struct dentry *dentry;
550 479
551 hcd->uses_new_polling = 1; 480 hcd->uses_new_polling = 1;
@@ -579,17 +508,23 @@ static int uhci_start(struct usb_hcd *hcd)
579 508
580 init_waitqueue_head(&uhci->waitqh); 509 init_waitqueue_head(&uhci->waitqh);
581 510
582 uhci->fl = dma_alloc_coherent(uhci_dev(uhci), sizeof(*uhci->fl), 511 uhci->frame = dma_alloc_coherent(uhci_dev(uhci),
583 &dma_handle, 0); 512 UHCI_NUMFRAMES * sizeof(*uhci->frame),
584 if (!uhci->fl) { 513 &uhci->frame_dma_handle, 0);
514 if (!uhci->frame) {
585 dev_err(uhci_dev(uhci), "unable to allocate " 515 dev_err(uhci_dev(uhci), "unable to allocate "
586 "consistent memory for frame list\n"); 516 "consistent memory for frame list\n");
587 goto err_alloc_fl; 517 goto err_alloc_frame;
588 } 518 }
519 memset(uhci->frame, 0, UHCI_NUMFRAMES * sizeof(*uhci->frame));
589 520
590 memset((void *)uhci->fl, 0, sizeof(*uhci->fl)); 521 uhci->frame_cpu = kcalloc(UHCI_NUMFRAMES, sizeof(*uhci->frame_cpu),
591 522 GFP_KERNEL);
592 uhci->fl->dma_handle = dma_handle; 523 if (!uhci->frame_cpu) {
524 dev_err(uhci_dev(uhci), "unable to allocate "
525 "memory for frame pointers\n");
526 goto err_alloc_frame_cpu;
527 }
593 528
594 uhci->td_pool = dma_pool_create("uhci_td", uhci_dev(uhci), 529 uhci->td_pool = dma_pool_create("uhci_td", uhci_dev(uhci),
595 sizeof(struct uhci_td), 16, 0); 530 sizeof(struct uhci_td), 16, 0);
@@ -672,7 +607,7 @@ static int uhci_start(struct usb_hcd *hcd)
672 irq = 7; 607 irq = 7;
673 608
674 /* Only place we don't use the frame list routines */ 609 /* Only place we don't use the frame list routines */
675 uhci->fl->frame[i] = UHCI_PTR_QH | 610 uhci->frame[i] = UHCI_PTR_QH |
676 cpu_to_le32(uhci->skelqh[irq]->dma_handle); 611 cpu_to_le32(uhci->skelqh[irq]->dma_handle);
677 } 612 }
678 613
@@ -690,31 +625,29 @@ static int uhci_start(struct usb_hcd *hcd)
690 * error exits: 625 * error exits:
691 */ 626 */
692err_alloc_skelqh: 627err_alloc_skelqh:
693 for (i = 0; i < UHCI_NUM_SKELQH; i++) 628 for (i = 0; i < UHCI_NUM_SKELQH; i++) {
694 if (uhci->skelqh[i]) { 629 if (uhci->skelqh[i])
695 uhci_free_qh(uhci, uhci->skelqh[i]); 630 uhci_free_qh(uhci, uhci->skelqh[i]);
696 uhci->skelqh[i] = NULL; 631 }
697 }
698 632
699 uhci_free_td(uhci, uhci->term_td); 633 uhci_free_td(uhci, uhci->term_td);
700 uhci->term_td = NULL;
701 634
702err_alloc_term_td: 635err_alloc_term_td:
703 dma_pool_destroy(uhci->qh_pool); 636 dma_pool_destroy(uhci->qh_pool);
704 uhci->qh_pool = NULL;
705 637
706err_create_qh_pool: 638err_create_qh_pool:
707 dma_pool_destroy(uhci->td_pool); 639 dma_pool_destroy(uhci->td_pool);
708 uhci->td_pool = NULL;
709 640
710err_create_td_pool: 641err_create_td_pool:
711 dma_free_coherent(uhci_dev(uhci), sizeof(*uhci->fl), 642 kfree(uhci->frame_cpu);
712 uhci->fl, uhci->fl->dma_handle); 643
713 uhci->fl = NULL; 644err_alloc_frame_cpu:
645 dma_free_coherent(uhci_dev(uhci),
646 UHCI_NUMFRAMES * sizeof(*uhci->frame),
647 uhci->frame, uhci->frame_dma_handle);
714 648
715err_alloc_fl: 649err_alloc_frame:
716 debugfs_remove(uhci->dentry); 650 debugfs_remove(uhci->dentry);
717 uhci->dentry = NULL;
718 651
719err_create_debug_entry: 652err_create_debug_entry:
720 return retval; 653 return retval;
@@ -726,7 +659,7 @@ static void uhci_stop(struct usb_hcd *hcd)
726 659
727 spin_lock_irq(&uhci->lock); 660 spin_lock_irq(&uhci->lock);
728 if (!uhci->hc_inaccessible) 661 if (!uhci->hc_inaccessible)
729 reset_hc(uhci); 662 hc_died(uhci);
730 uhci_scan_schedule(uhci, NULL); 663 uhci_scan_schedule(uhci, NULL);
731 spin_unlock_irq(&uhci->lock); 664 spin_unlock_irq(&uhci->lock);
732 665
@@ -774,14 +707,8 @@ static int uhci_suspend(struct usb_hcd *hcd, pm_message_t message)
774 if (uhci->hc_inaccessible) /* Dead or already suspended */ 707 if (uhci->hc_inaccessible) /* Dead or already suspended */
775 goto done; 708 goto done;
776 709
777#ifndef CONFIG_USB_SUSPEND
778 /* Otherwise this would never happen */
779 suspend_rh(uhci, UHCI_RH_SUSPENDED);
780#endif
781
782 if (uhci->rh_state > UHCI_RH_SUSPENDED) { 710 if (uhci->rh_state > UHCI_RH_SUSPENDED) {
783 dev_warn(uhci_dev(uhci), "Root hub isn't suspended!\n"); 711 dev_warn(uhci_dev(uhci), "Root hub isn't suspended!\n");
784 hcd->state = HC_STATE_RUNNING;
785 rc = -EBUSY; 712 rc = -EBUSY;
786 goto done; 713 goto done;
787 }; 714 };
@@ -820,10 +747,6 @@ static int uhci_resume(struct usb_hcd *hcd)
820 check_and_reset_hc(uhci); 747 check_and_reset_hc(uhci);
821 configure_hc(uhci); 748 configure_hc(uhci);
822 749
823#ifndef CONFIG_USB_SUSPEND
824 /* Otherwise this would never happen */
825 wakeup_rh(uhci);
826#endif
827 if (uhci->rh_state == UHCI_RH_RESET) 750 if (uhci->rh_state == UHCI_RH_RESET)
828 suspend_rh(uhci, UHCI_RH_SUSPENDED); 751 suspend_rh(uhci, UHCI_RH_SUSPENDED);
829 752
@@ -881,8 +804,8 @@ static const struct hc_driver uhci_driver = {
881#ifdef CONFIG_PM 804#ifdef CONFIG_PM
882 .suspend = uhci_suspend, 805 .suspend = uhci_suspend,
883 .resume = uhci_resume, 806 .resume = uhci_resume,
884 .hub_suspend = uhci_rh_suspend, 807 .bus_suspend = uhci_rh_suspend,
885 .hub_resume = uhci_rh_resume, 808 .bus_resume = uhci_rh_resume,
886#endif 809#endif
887 .stop = uhci_stop, 810 .stop = uhci_stop,
888 811
@@ -908,6 +831,7 @@ MODULE_DEVICE_TABLE(pci, uhci_pci_ids);
908static struct pci_driver uhci_pci_driver = { 831static struct pci_driver uhci_pci_driver = {
909 .name = (char *)hcd_name, 832 .name = (char *)hcd_name,
910 .id_table = uhci_pci_ids, 833 .id_table = uhci_pci_ids,
834 .owner = THIS_MODULE,
911 835
912 .probe = usb_hcd_pci_probe, 836 .probe = usb_hcd_pci_probe,
913 .remove = usb_hcd_pci_remove, 837 .remove = usb_hcd_pci_remove,
diff --git a/drivers/usb/host/uhci-hcd.h b/drivers/usb/host/uhci-hcd.h
index 282f40b75881..e576db57a926 100644
--- a/drivers/usb/host/uhci-hcd.h
+++ b/drivers/usb/host/uhci-hcd.h
@@ -7,6 +7,7 @@
7#define usb_packetid(pipe) (usb_pipein(pipe) ? USB_PID_IN : USB_PID_OUT) 7#define usb_packetid(pipe) (usb_pipein(pipe) ? USB_PID_IN : USB_PID_OUT)
8#define PIPE_DEVEP_MASK 0x0007ff00 8#define PIPE_DEVEP_MASK 0x0007ff00
9 9
10
10/* 11/*
11 * Universal Host Controller Interface data structures and defines 12 * Universal Host Controller Interface data structures and defines
12 */ 13 */
@@ -82,15 +83,10 @@
82#define UHCI_MAX_SOF_NUMBER 2047 /* in an SOF packet */ 83#define UHCI_MAX_SOF_NUMBER 2047 /* in an SOF packet */
83#define CAN_SCHEDULE_FRAMES 1000 /* how far future frames can be scheduled */ 84#define CAN_SCHEDULE_FRAMES 1000 /* how far future frames can be scheduled */
84 85
85struct uhci_frame_list {
86 __le32 frame[UHCI_NUMFRAMES];
87
88 void *frame_cpu[UHCI_NUMFRAMES];
89
90 dma_addr_t dma_handle;
91};
92 86
93struct urb_priv; 87/*
88 * Queue Headers
89 */
94 90
95/* 91/*
96 * One role of a QH is to hold a queue of TDs for some endpoint. Each QH is 92 * One role of a QH is to hold a queue of TDs for some endpoint. Each QH is
@@ -116,13 +112,13 @@ struct uhci_qh {
116 112
117 struct urb_priv *urbp; 113 struct urb_priv *urbp;
118 114
119 struct list_head list; /* P: uhci->frame_list_lock */ 115 struct list_head list;
120 struct list_head remove_list; /* P: uhci->remove_list_lock */ 116 struct list_head remove_list;
121} __attribute__((aligned(16))); 117} __attribute__((aligned(16)));
122 118
123/* 119/*
124 * We need a special accessor for the element pointer because it is 120 * We need a special accessor for the element pointer because it is
125 * subject to asynchronous updates by the controller 121 * subject to asynchronous updates by the controller.
126 */ 122 */
127static __le32 inline qh_element(struct uhci_qh *qh) { 123static __le32 inline qh_element(struct uhci_qh *qh) {
128 __le32 element = qh->element; 124 __le32 element = qh->element;
@@ -131,6 +127,11 @@ static __le32 inline qh_element(struct uhci_qh *qh) {
131 return element; 127 return element;
132} 128}
133 129
130
131/*
132 * Transfer Descriptors
133 */
134
134/* 135/*
135 * for TD <status>: 136 * for TD <status>:
136 */ 137 */
@@ -183,17 +184,10 @@ static __le32 inline qh_element(struct uhci_qh *qh) {
183 * 184 *
184 * That's silly, the hardware doesn't care. The hardware only cares that 185 * That's silly, the hardware doesn't care. The hardware only cares that
185 * the hardware words are 16-byte aligned, and we can have any amount of 186 * the hardware words are 16-byte aligned, and we can have any amount of
186 * sw space after the TD entry as far as I can tell. 187 * sw space after the TD entry.
187 *
188 * But let's just go with the documentation, at least for 32-bit machines.
189 * On 64-bit machines we probably want to take advantage of the fact that
190 * hw doesn't really care about the size of the sw-only area.
191 *
192 * Alas, not anymore, we have more than 4 words for software, woops.
193 * Everything still works tho, surprise! -jerdfelt
194 * 188 *
195 * td->link points to either another TD (not necessarily for the same urb or 189 * td->link points to either another TD (not necessarily for the same urb or
196 * even the same endpoint), or nothing (PTR_TERM), or a QH (for queued urbs) 190 * even the same endpoint), or nothing (PTR_TERM), or a QH (for queued urbs).
197 */ 191 */
198struct uhci_td { 192struct uhci_td {
199 /* Hardware fields */ 193 /* Hardware fields */
@@ -205,18 +199,16 @@ struct uhci_td {
205 /* Software fields */ 199 /* Software fields */
206 dma_addr_t dma_handle; 200 dma_addr_t dma_handle;
207 201
208 struct urb *urb; 202 struct list_head list;
209 203 struct list_head remove_list;
210 struct list_head list; /* P: urb->lock */
211 struct list_head remove_list; /* P: uhci->td_remove_list_lock */
212 204
213 int frame; /* for iso: what frame? */ 205 int frame; /* for iso: what frame? */
214 struct list_head fl_list; /* P: uhci->frame_list_lock */ 206 struct list_head fl_list;
215} __attribute__((aligned(16))); 207} __attribute__((aligned(16)));
216 208
217/* 209/*
218 * We need a special accessor for the control/status word because it is 210 * We need a special accessor for the control/status word because it is
219 * subject to asynchronous updates by the controller 211 * subject to asynchronous updates by the controller.
220 */ 212 */
221static u32 inline td_status(struct uhci_td *td) { 213static u32 inline td_status(struct uhci_td *td) {
222 __le32 status = td->status; 214 __le32 status = td->status;
@@ -227,6 +219,10 @@ static u32 inline td_status(struct uhci_td *td) {
227 219
228 220
229/* 221/*
222 * Skeleton Queue Headers
223 */
224
225/*
230 * The UHCI driver places Interrupt, Control and Bulk into QH's both 226 * The UHCI driver places Interrupt, Control and Bulk into QH's both
231 * to group together TD's for one transfer, and also to faciliate queuing 227 * to group together TD's for one transfer, and also to faciliate queuing
232 * of URB's. To make it easy to insert entries into the schedule, we have 228 * of URB's. To make it easy to insert entries into the schedule, we have
@@ -256,15 +252,15 @@ static u32 inline td_status(struct uhci_td *td) {
256 * 252 *
257 * The terminating QH is used for 2 reasons: 253 * The terminating QH is used for 2 reasons:
258 * - To place a terminating TD which is used to workaround a PIIX bug 254 * - To place a terminating TD which is used to workaround a PIIX bug
259 * (see Intel errata for explanation) 255 * (see Intel errata for explanation), and
260 * - To loop back to the full-speed control queue for full-speed bandwidth 256 * - To loop back to the full-speed control queue for full-speed bandwidth
261 * reclamation 257 * reclamation.
262 * 258 *
263 * Isochronous transfers are stored before the start of the skeleton 259 * Isochronous transfers are stored before the start of the skeleton
264 * schedule and don't use QH's. While the UHCI spec doesn't forbid the 260 * schedule and don't use QH's. While the UHCI spec doesn't forbid the
265 * use of QH's for Isochronous, it doesn't use them either. Since we don't 261 * use of QH's for Isochronous, it doesn't use them either. And the spec
266 * need to use them either, we follow the spec diagrams in hope that it'll 262 * says that queues never advance on an error completion status, which
267 * be more compatible with future UHCI implementations. 263 * makes them totally unsuitable for Isochronous transfers.
268 */ 264 */
269 265
270#define UHCI_NUM_SKELQH 12 266#define UHCI_NUM_SKELQH 12
@@ -314,8 +310,13 @@ static inline int __interval_to_skel(int interval)
314 return 0; /* int128 for 128-255 ms (Max.) */ 310 return 0; /* int128 for 128-255 ms (Max.) */
315} 311}
316 312
313
314/*
315 * The UHCI controller and root hub
316 */
317
317/* 318/*
318 * States for the root hub. 319 * States for the root hub:
319 * 320 *
320 * To prevent "bouncing" in the presence of electrical noise, 321 * To prevent "bouncing" in the presence of electrical noise,
321 * when there are no devices attached we delay for 1 second in the 322 * when there are no devices attached we delay for 1 second in the
@@ -326,7 +327,7 @@ static inline int __interval_to_skel(int interval)
326 */ 327 */
327enum uhci_rh_state { 328enum uhci_rh_state {
328 /* In the following states the HC must be halted. 329 /* In the following states the HC must be halted.
329 * These two must come first */ 330 * These two must come first. */
330 UHCI_RH_RESET, 331 UHCI_RH_RESET,
331 UHCI_RH_SUSPENDED, 332 UHCI_RH_SUSPENDED,
332 333
@@ -338,13 +339,13 @@ enum uhci_rh_state {
338 UHCI_RH_SUSPENDING, 339 UHCI_RH_SUSPENDING,
339 340
340 /* In the following states it's an error if the HC is halted. 341 /* In the following states it's an error if the HC is halted.
341 * These two must come last */ 342 * These two must come last. */
342 UHCI_RH_RUNNING, /* The normal state */ 343 UHCI_RH_RUNNING, /* The normal state */
343 UHCI_RH_RUNNING_NODEVS, /* Running with no devices attached */ 344 UHCI_RH_RUNNING_NODEVS, /* Running with no devices attached */
344}; 345};
345 346
346/* 347/*
347 * This describes the full uhci information. 348 * The full UHCI controller information:
348 */ 349 */
349struct uhci_hcd { 350struct uhci_hcd {
350 351
@@ -361,7 +362,11 @@ struct uhci_hcd {
361 struct uhci_qh *skelqh[UHCI_NUM_SKELQH]; /* Skeleton QH's */ 362 struct uhci_qh *skelqh[UHCI_NUM_SKELQH]; /* Skeleton QH's */
362 363
363 spinlock_t lock; 364 spinlock_t lock;
364 struct uhci_frame_list *fl; /* P: uhci->lock */ 365
366 dma_addr_t frame_dma_handle; /* Hardware frame list */
367 __le32 *frame;
368 void **frame_cpu; /* CPU's frame list */
369
365 int fsbr; /* Full-speed bandwidth reclamation */ 370 int fsbr; /* Full-speed bandwidth reclamation */
366 unsigned long fsbrtimeout; /* FSBR delay */ 371 unsigned long fsbrtimeout; /* FSBR delay */
367 372
@@ -385,22 +390,22 @@ struct uhci_hcd {
385 unsigned long ports_timeout; /* Time to stop signalling */ 390 unsigned long ports_timeout; /* Time to stop signalling */
386 391
387 /* Main list of URB's currently controlled by this HC */ 392 /* Main list of URB's currently controlled by this HC */
388 struct list_head urb_list; /* P: uhci->lock */ 393 struct list_head urb_list;
389 394
390 /* List of QH's that are done, but waiting to be unlinked (race) */ 395 /* List of QH's that are done, but waiting to be unlinked (race) */
391 struct list_head qh_remove_list; /* P: uhci->lock */ 396 struct list_head qh_remove_list;
392 unsigned int qh_remove_age; /* Age in frames */ 397 unsigned int qh_remove_age; /* Age in frames */
393 398
394 /* List of TD's that are done, but waiting to be freed (race) */ 399 /* List of TD's that are done, but waiting to be freed (race) */
395 struct list_head td_remove_list; /* P: uhci->lock */ 400 struct list_head td_remove_list;
396 unsigned int td_remove_age; /* Age in frames */ 401 unsigned int td_remove_age; /* Age in frames */
397 402
398 /* List of asynchronously unlinked URB's */ 403 /* List of asynchronously unlinked URB's */
399 struct list_head urb_remove_list; /* P: uhci->lock */ 404 struct list_head urb_remove_list;
400 unsigned int urb_remove_age; /* Age in frames */ 405 unsigned int urb_remove_age; /* Age in frames */
401 406
402 /* List of URB's awaiting completion callback */ 407 /* List of URB's awaiting completion callback */
403 struct list_head complete_list; /* P: uhci->lock */ 408 struct list_head complete_list;
404 409
405 int rh_numports; /* Number of root-hub ports */ 410 int rh_numports; /* Number of root-hub ports */
406 411
@@ -419,13 +424,17 @@ static inline struct usb_hcd *uhci_to_hcd(struct uhci_hcd *uhci)
419 424
420#define uhci_dev(u) (uhci_to_hcd(u)->self.controller) 425#define uhci_dev(u) (uhci_to_hcd(u)->self.controller)
421 426
427
428/*
429 * Private per-URB data
430 */
422struct urb_priv { 431struct urb_priv {
423 struct list_head urb_list; 432 struct list_head urb_list;
424 433
425 struct urb *urb; 434 struct urb *urb;
426 435
427 struct uhci_qh *qh; /* QH for this URB */ 436 struct uhci_qh *qh; /* QH for this URB */
428 struct list_head td_list; /* P: urb->lock */ 437 struct list_head td_list;
429 438
430 unsigned fsbr : 1; /* URB turned on FSBR */ 439 unsigned fsbr : 1; /* URB turned on FSBR */
431 unsigned fsbr_timeout : 1; /* URB timed out on FSBR */ 440 unsigned fsbr_timeout : 1; /* URB timed out on FSBR */
@@ -434,12 +443,12 @@ struct urb_priv {
434 /* a control transfer, retrigger */ 443 /* a control transfer, retrigger */
435 /* the status phase */ 444 /* the status phase */
436 445
437 unsigned long inserttime; /* In jiffies */
438 unsigned long fsbrtime; /* In jiffies */ 446 unsigned long fsbrtime; /* In jiffies */
439 447
440 struct list_head queue_list; /* P: uhci->frame_list_lock */ 448 struct list_head queue_list;
441}; 449};
442 450
451
443/* 452/*
444 * Locking in uhci.c 453 * Locking in uhci.c
445 * 454 *
@@ -459,6 +468,5 @@ struct urb_priv {
459 468
460#define PCI_VENDOR_ID_GENESYS 0x17a0 469#define PCI_VENDOR_ID_GENESYS 0x17a0
461#define PCI_DEVICE_ID_GL880S_UHCI 0x8083 470#define PCI_DEVICE_ID_GL880S_UHCI 0x8083
462#define PCI_DEVICE_ID_GL880S_EHCI 0x8084
463 471
464#endif 472#endif
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
index ea0d168a8c67..7e46887d9e12 100644
--- a/drivers/usb/host/uhci-q.c
+++ b/drivers/usb/host/uhci-q.c
@@ -89,10 +89,10 @@ static void uhci_insert_td_frame_list(struct uhci_hcd *uhci, struct uhci_td *td,
89 td->frame = framenum; 89 td->frame = framenum;
90 90
91 /* Is there a TD already mapped there? */ 91 /* Is there a TD already mapped there? */
92 if (uhci->fl->frame_cpu[framenum]) { 92 if (uhci->frame_cpu[framenum]) {
93 struct uhci_td *ftd, *ltd; 93 struct uhci_td *ftd, *ltd;
94 94
95 ftd = uhci->fl->frame_cpu[framenum]; 95 ftd = uhci->frame_cpu[framenum];
96 ltd = list_entry(ftd->fl_list.prev, struct uhci_td, fl_list); 96 ltd = list_entry(ftd->fl_list.prev, struct uhci_td, fl_list);
97 97
98 list_add_tail(&td->fl_list, &ftd->fl_list); 98 list_add_tail(&td->fl_list, &ftd->fl_list);
@@ -101,29 +101,32 @@ static void uhci_insert_td_frame_list(struct uhci_hcd *uhci, struct uhci_td *td,
101 wmb(); 101 wmb();
102 ltd->link = cpu_to_le32(td->dma_handle); 102 ltd->link = cpu_to_le32(td->dma_handle);
103 } else { 103 } else {
104 td->link = uhci->fl->frame[framenum]; 104 td->link = uhci->frame[framenum];
105 wmb(); 105 wmb();
106 uhci->fl->frame[framenum] = cpu_to_le32(td->dma_handle); 106 uhci->frame[framenum] = cpu_to_le32(td->dma_handle);
107 uhci->fl->frame_cpu[framenum] = td; 107 uhci->frame_cpu[framenum] = td;
108 } 108 }
109} 109}
110 110
111static void uhci_remove_td(struct uhci_hcd *uhci, struct uhci_td *td) 111static inline void uhci_remove_td_frame_list(struct uhci_hcd *uhci,
112 struct uhci_td *td)
112{ 113{
113 /* If it's not inserted, don't remove it */ 114 /* If it's not inserted, don't remove it */
114 if (td->frame == -1 && list_empty(&td->fl_list)) 115 if (td->frame == -1) {
116 WARN_ON(!list_empty(&td->fl_list));
115 return; 117 return;
118 }
116 119
117 if (td->frame != -1 && uhci->fl->frame_cpu[td->frame] == td) { 120 if (uhci->frame_cpu[td->frame] == td) {
118 if (list_empty(&td->fl_list)) { 121 if (list_empty(&td->fl_list)) {
119 uhci->fl->frame[td->frame] = td->link; 122 uhci->frame[td->frame] = td->link;
120 uhci->fl->frame_cpu[td->frame] = NULL; 123 uhci->frame_cpu[td->frame] = NULL;
121 } else { 124 } else {
122 struct uhci_td *ntd; 125 struct uhci_td *ntd;
123 126
124 ntd = list_entry(td->fl_list.next, struct uhci_td, fl_list); 127 ntd = list_entry(td->fl_list.next, struct uhci_td, fl_list);
125 uhci->fl->frame[td->frame] = cpu_to_le32(ntd->dma_handle); 128 uhci->frame[td->frame] = cpu_to_le32(ntd->dma_handle);
126 uhci->fl->frame_cpu[td->frame] = ntd; 129 uhci->frame_cpu[td->frame] = ntd;
127 } 130 }
128 } else { 131 } else {
129 struct uhci_td *ptd; 132 struct uhci_td *ptd;
@@ -132,13 +135,20 @@ static void uhci_remove_td(struct uhci_hcd *uhci, struct uhci_td *td)
132 ptd->link = td->link; 135 ptd->link = td->link;
133 } 136 }
134 137
135 wmb();
136 td->link = UHCI_PTR_TERM;
137
138 list_del_init(&td->fl_list); 138 list_del_init(&td->fl_list);
139 td->frame = -1; 139 td->frame = -1;
140} 140}
141 141
142static void unlink_isochronous_tds(struct uhci_hcd *uhci, struct urb *urb)
143{
144 struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv;
145 struct uhci_td *td;
146
147 list_for_each_entry(td, &urbp->td_list, list)
148 uhci_remove_td_frame_list(uhci, td);
149 wmb();
150}
151
142/* 152/*
143 * Inserts a td list into qh. 153 * Inserts a td list into qh.
144 */ 154 */
@@ -443,7 +453,6 @@ static struct urb_priv *uhci_alloc_urb_priv(struct uhci_hcd *uhci, struct urb *u
443 453
444 memset((void *)urbp, 0, sizeof(*urbp)); 454 memset((void *)urbp, 0, sizeof(*urbp));
445 455
446 urbp->inserttime = jiffies;
447 urbp->fsbrtime = jiffies; 456 urbp->fsbrtime = jiffies;
448 urbp->urb = urb; 457 urbp->urb = urb;
449 458
@@ -462,8 +471,6 @@ static void uhci_add_td_to_urb(struct urb *urb, struct uhci_td *td)
462{ 471{
463 struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv; 472 struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv;
464 473
465 td->urb = urb;
466
467 list_add_tail(&td->list, &urbp->td_list); 474 list_add_tail(&td->list, &urbp->td_list);
468} 475}
469 476
@@ -473,8 +480,6 @@ static void uhci_remove_td_from_urb(struct uhci_td *td)
473 return; 480 return;
474 481
475 list_del_init(&td->list); 482 list_del_init(&td->list);
476
477 td->urb = NULL;
478} 483}
479 484
480static void uhci_destroy_urb_priv(struct uhci_hcd *uhci, struct urb *urb) 485static void uhci_destroy_urb_priv(struct uhci_hcd *uhci, struct urb *urb)
@@ -503,7 +508,6 @@ static void uhci_destroy_urb_priv(struct uhci_hcd *uhci, struct urb *urb)
503 508
504 list_for_each_entry_safe(td, tmp, &urbp->td_list, list) { 509 list_for_each_entry_safe(td, tmp, &urbp->td_list, list) {
505 uhci_remove_td_from_urb(td); 510 uhci_remove_td_from_urb(td);
506 uhci_remove_td(uhci, td);
507 list_add(&td->remove_list, &uhci->td_remove_list); 511 list_add(&td->remove_list, &uhci->td_remove_list);
508 } 512 }
509 513
@@ -1073,6 +1077,7 @@ static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb)
1073 struct uhci_td *td; 1077 struct uhci_td *td;
1074 int i, ret, frame; 1078 int i, ret, frame;
1075 int status, destination; 1079 int status, destination;
1080 struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv;
1076 1081
1077 status = TD_CTRL_ACTIVE | TD_CTRL_IOS; 1082 status = TD_CTRL_ACTIVE | TD_CTRL_IOS;
1078 destination = (urb->pipe & PIPE_DEVEP_MASK) | usb_packetid(urb->pipe); 1083 destination = (urb->pipe & PIPE_DEVEP_MASK) | usb_packetid(urb->pipe);
@@ -1081,11 +1086,7 @@ static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb)
1081 if (ret) 1086 if (ret)
1082 return ret; 1087 return ret;
1083 1088
1084 frame = urb->start_frame; 1089 for (i = 0; i < urb->number_of_packets; i++) {
1085 for (i = 0; i < urb->number_of_packets; i++, frame += urb->interval) {
1086 if (!urb->iso_frame_desc[i].length)
1087 continue;
1088
1089 td = uhci_alloc_td(uhci); 1090 td = uhci_alloc_td(uhci);
1090 if (!td) 1091 if (!td)
1091 return -ENOMEM; 1092 return -ENOMEM;
@@ -1096,8 +1097,12 @@ static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb)
1096 1097
1097 if (i + 1 >= urb->number_of_packets) 1098 if (i + 1 >= urb->number_of_packets)
1098 td->status |= cpu_to_le32(TD_CTRL_IOC); 1099 td->status |= cpu_to_le32(TD_CTRL_IOC);
1100 }
1099 1101
1102 frame = urb->start_frame;
1103 list_for_each_entry(td, &urbp->td_list, list) {
1100 uhci_insert_td_frame_list(uhci, td, frame); 1104 uhci_insert_td_frame_list(uhci, td, frame);
1105 frame += urb->interval;
1101 } 1106 }
1102 1107
1103 return -EINPROGRESS; 1108 return -EINPROGRESS;
@@ -1110,7 +1115,7 @@ static int uhci_result_isochronous(struct uhci_hcd *uhci, struct urb *urb)
1110 int status; 1115 int status;
1111 int i, ret = 0; 1116 int i, ret = 0;
1112 1117
1113 urb->actual_length = 0; 1118 urb->actual_length = urb->error_count = 0;
1114 1119
1115 i = 0; 1120 i = 0;
1116 list_for_each_entry(td, &urbp->td_list, list) { 1121 list_for_each_entry(td, &urbp->td_list, list) {
@@ -1134,6 +1139,7 @@ static int uhci_result_isochronous(struct uhci_hcd *uhci, struct urb *urb)
1134 1139
1135 i++; 1140 i++;
1136 } 1141 }
1142 unlink_isochronous_tds(uhci, urb);
1137 1143
1138 return ret; 1144 return ret;
1139} 1145}
@@ -1164,7 +1170,7 @@ static struct urb *uhci_find_urb_ep(struct uhci_hcd *uhci, struct urb *urb)
1164 1170
1165static int uhci_urb_enqueue(struct usb_hcd *hcd, 1171static int uhci_urb_enqueue(struct usb_hcd *hcd,
1166 struct usb_host_endpoint *ep, 1172 struct usb_host_endpoint *ep,
1167 struct urb *urb, unsigned mem_flags) 1173 struct urb *urb, gfp_t mem_flags)
1168{ 1174{
1169 int ret; 1175 int ret;
1170 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 1176 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
@@ -1366,6 +1372,8 @@ static int uhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
1366 goto done; 1372 goto done;
1367 list_del_init(&urbp->urb_list); 1373 list_del_init(&urbp->urb_list);
1368 1374
1375 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS)
1376 unlink_isochronous_tds(uhci, urb);
1369 uhci_unlink_generic(uhci, urb); 1377 uhci_unlink_generic(uhci, urb);
1370 1378
1371 uhci_get_current_frame_number(uhci); 1379 uhci_get_current_frame_number(uhci);
diff --git a/drivers/usb/image/mdc800.c b/drivers/usb/image/mdc800.c
index a330a4b50e16..1d973bcf56aa 100644
--- a/drivers/usb/image/mdc800.c
+++ b/drivers/usb/image/mdc800.c
@@ -425,9 +425,8 @@ static void mdc800_usb_download_notify (struct urb *urb, struct pt_regs *res)
425static struct usb_driver mdc800_usb_driver; 425static struct usb_driver mdc800_usb_driver;
426static struct file_operations mdc800_device_ops; 426static struct file_operations mdc800_device_ops;
427static struct usb_class_driver mdc800_class = { 427static struct usb_class_driver mdc800_class = {
428 .name = "usb/mdc800%d", 428 .name = "mdc800%d",
429 .fops = &mdc800_device_ops, 429 .fops = &mdc800_device_ops,
430 .mode = S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
431 .minor_base = MDC800_DEVICE_MINOR_BASE, 430 .minor_base = MDC800_DEVICE_MINOR_BASE,
432}; 431};
433 432
@@ -976,13 +975,13 @@ static struct usb_driver mdc800_usb_driver =
976 Init and Cleanup this driver (Main Functions) 975 Init and Cleanup this driver (Main Functions)
977*************************************************************************/ 976*************************************************************************/
978 977
979#define try(A) if (!(A)) goto cleanup_on_fail;
980
981static int __init usb_mdc800_init (void) 978static int __init usb_mdc800_init (void)
982{ 979{
983 int retval = -ENODEV; 980 int retval = -ENODEV;
984 /* Allocate Memory */ 981 /* Allocate Memory */
985 try (mdc800=kmalloc (sizeof (struct mdc800_data), GFP_KERNEL)); 982 mdc800=kmalloc (sizeof (struct mdc800_data), GFP_KERNEL);
983 if (!mdc800)
984 goto cleanup_on_fail;
986 985
987 memset(mdc800, 0, sizeof(struct mdc800_data)); 986 memset(mdc800, 0, sizeof(struct mdc800_data));
988 mdc800->dev = NULL; 987 mdc800->dev = NULL;
@@ -998,13 +997,25 @@ static int __init usb_mdc800_init (void)
998 mdc800->downloaded = 0; 997 mdc800->downloaded = 0;
999 mdc800->written = 0; 998 mdc800->written = 0;
1000 999
1001 try (mdc800->irq_urb_buffer=kmalloc (8, GFP_KERNEL)); 1000 mdc800->irq_urb_buffer=kmalloc (8, GFP_KERNEL);
1002 try (mdc800->write_urb_buffer=kmalloc (8, GFP_KERNEL)); 1001 if (!mdc800->irq_urb_buffer)
1003 try (mdc800->download_urb_buffer=kmalloc (64, GFP_KERNEL)); 1002 goto cleanup_on_fail;
1003 mdc800->write_urb_buffer=kmalloc (8, GFP_KERNEL);
1004 if (!mdc800->write_urb_buffer)
1005 goto cleanup_on_fail;
1006 mdc800->download_urb_buffer=kmalloc (64, GFP_KERNEL);
1007 if (!mdc800->download_urb_buffer)
1008 goto cleanup_on_fail;
1004 1009
1005 try (mdc800->irq_urb=usb_alloc_urb (0, GFP_KERNEL)); 1010 mdc800->irq_urb=usb_alloc_urb (0, GFP_KERNEL);
1006 try (mdc800->download_urb=usb_alloc_urb (0, GFP_KERNEL)); 1011 if (!mdc800->irq_urb)
1007 try (mdc800->write_urb=usb_alloc_urb (0, GFP_KERNEL)); 1012 goto cleanup_on_fail;
1013 mdc800->download_urb=usb_alloc_urb (0, GFP_KERNEL);
1014 if (!mdc800->download_urb)
1015 goto cleanup_on_fail;
1016 mdc800->write_urb=usb_alloc_urb (0, GFP_KERNEL);
1017 if (!mdc800->write_urb)
1018 goto cleanup_on_fail;
1008 1019
1009 /* Register the driver */ 1020 /* Register the driver */
1010 retval = usb_register(&mdc800_usb_driver); 1021 retval = usb_register(&mdc800_usb_driver);
diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c
index c84e1486054f..c89d0769b3da 100644
--- a/drivers/usb/image/microtek.c
+++ b/drivers/usb/image/microtek.c
@@ -773,11 +773,10 @@ static int mts_usb_probe(struct usb_interface *intf,
773 } 773 }
774 774
775 775
776 new_desc = kmalloc(sizeof(struct mts_desc), GFP_KERNEL); 776 new_desc = kzalloc(sizeof(struct mts_desc), GFP_KERNEL);
777 if (!new_desc) 777 if (!new_desc)
778 goto out; 778 goto out;
779 779
780 memset(new_desc, 0, sizeof(*new_desc));
781 new_desc->urb = usb_alloc_urb(0, GFP_KERNEL); 780 new_desc->urb = usb_alloc_urb(0, GFP_KERNEL);
782 if (!new_desc->urb) 781 if (!new_desc->urb)
783 goto out_kfree; 782 goto out_kfree;
diff --git a/drivers/usb/input/acecad.c b/drivers/usb/input/acecad.c
index 74f8760d7c07..a32558b4048e 100644
--- a/drivers/usb/input/acecad.c
+++ b/drivers/usb/input/acecad.c
@@ -53,7 +53,7 @@ struct usb_acecad {
53 char name[128]; 53 char name[128];
54 char phys[64]; 54 char phys[64];
55 struct usb_device *usbdev; 55 struct usb_device *usbdev;
56 struct input_dev dev; 56 struct input_dev *input;
57 struct urb *irq; 57 struct urb *irq;
58 58
59 signed char *data; 59 signed char *data;
@@ -64,7 +64,7 @@ static void usb_acecad_irq(struct urb *urb, struct pt_regs *regs)
64{ 64{
65 struct usb_acecad *acecad = urb->context; 65 struct usb_acecad *acecad = urb->context;
66 unsigned char *data = acecad->data; 66 unsigned char *data = acecad->data;
67 struct input_dev *dev = &acecad->dev; 67 struct input_dev *dev = acecad->input;
68 int prox, status; 68 int prox, status;
69 69
70 switch (urb->status) { 70 switch (urb->status) {
@@ -135,8 +135,8 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_
135 struct usb_host_interface *interface = intf->cur_altsetting; 135 struct usb_host_interface *interface = intf->cur_altsetting;
136 struct usb_endpoint_descriptor *endpoint; 136 struct usb_endpoint_descriptor *endpoint;
137 struct usb_acecad *acecad; 137 struct usb_acecad *acecad;
138 struct input_dev *input_dev;
138 int pipe, maxp; 139 int pipe, maxp;
139 char path[64];
140 140
141 if (interface->desc.bNumEndpoints != 1) 141 if (interface->desc.bNumEndpoints != 1)
142 return -ENODEV; 142 return -ENODEV;
@@ -153,8 +153,9 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_
153 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); 153 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
154 154
155 acecad = kzalloc(sizeof(struct usb_acecad), GFP_KERNEL); 155 acecad = kzalloc(sizeof(struct usb_acecad), GFP_KERNEL);
156 if (!acecad) 156 input_dev = input_allocate_device();
157 return -ENOMEM; 157 if (!acecad || !input_dev)
158 goto fail1;
158 159
159 acecad->data = usb_buffer_alloc(dev, 8, SLAB_KERNEL, &acecad->data_dma); 160 acecad->data = usb_buffer_alloc(dev, 8, SLAB_KERNEL, &acecad->data_dma);
160 if (!acecad->data) 161 if (!acecad->data)
@@ -164,6 +165,9 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_
164 if (!acecad->irq) 165 if (!acecad->irq)
165 goto fail2; 166 goto fail2;
166 167
168 acecad->usbdev = dev;
169 acecad->input = input_dev;
170
167 if (dev->manufacturer) 171 if (dev->manufacturer)
168 strlcpy(acecad->name, dev->manufacturer, sizeof(acecad->name)); 172 strlcpy(acecad->name, dev->manufacturer, sizeof(acecad->name));
169 173
@@ -173,48 +177,48 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_
173 strlcat(acecad->name, dev->product, sizeof(acecad->name)); 177 strlcat(acecad->name, dev->product, sizeof(acecad->name));
174 } 178 }
175 179
176 usb_make_path(dev, path, sizeof(path)); 180 usb_make_path(dev, acecad->phys, sizeof(acecad->phys));
177 snprintf(acecad->phys, sizeof(acecad->phys), "%s/input0", path); 181 strlcat(acecad->phys, "/input0", sizeof(acecad->phys));
178 182
179 acecad->usbdev = dev; 183 input_dev->name = acecad->name;
184 input_dev->phys = acecad->phys;
185 usb_to_input_id(dev, &input_dev->id);
186 input_dev->cdev.dev = &intf->dev;
187 input_dev->private = acecad;
180 188
181 acecad->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 189 input_dev->open = usb_acecad_open;
182 acecad->dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE); 190 input_dev->close = usb_acecad_close;
183 acecad->dev.keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); 191
184 acecad->dev.keybit[LONG(BTN_DIGI)] = BIT(BTN_TOOL_PEN) |BIT(BTN_TOUCH) | BIT(BTN_STYLUS) | BIT(BTN_STYLUS2); 192 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
193 input_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
194 input_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
195 input_dev->keybit[LONG(BTN_DIGI)] = BIT(BTN_TOOL_PEN) |BIT(BTN_TOUCH) | BIT(BTN_STYLUS) | BIT(BTN_STYLUS2);
185 196
186 switch (id->driver_info) { 197 switch (id->driver_info) {
187 case 0: 198 case 0:
188 acecad->dev.absmax[ABS_X] = 5000; 199 input_dev->absmax[ABS_X] = 5000;
189 acecad->dev.absmax[ABS_Y] = 3750; 200 input_dev->absmax[ABS_Y] = 3750;
190 acecad->dev.absmax[ABS_PRESSURE] = 512; 201 input_dev->absmax[ABS_PRESSURE] = 512;
191 if (!strlen(acecad->name)) 202 if (!strlen(acecad->name))
192 snprintf(acecad->name, sizeof(acecad->name), 203 snprintf(acecad->name, sizeof(acecad->name),
193 "USB Acecad Flair Tablet %04x:%04x", 204 "USB Acecad Flair Tablet %04x:%04x",
194 dev->descriptor.idVendor, dev->descriptor.idProduct); 205 le16_to_cpu(dev->descriptor.idVendor),
206 le16_to_cpu(dev->descriptor.idProduct));
195 break; 207 break;
196 case 1: 208 case 1:
197 acecad->dev.absmax[ABS_X] = 3000; 209 input_dev->absmax[ABS_X] = 3000;
198 acecad->dev.absmax[ABS_Y] = 2250; 210 input_dev->absmax[ABS_Y] = 2250;
199 acecad->dev.absmax[ABS_PRESSURE] = 1024; 211 input_dev->absmax[ABS_PRESSURE] = 1024;
200 if (!strlen(acecad->name)) 212 if (!strlen(acecad->name))
201 snprintf(acecad->name, sizeof(acecad->name), 213 snprintf(acecad->name, sizeof(acecad->name),
202 "USB Acecad 302 Tablet %04x:%04x", 214 "USB Acecad 302 Tablet %04x:%04x",
203 dev->descriptor.idVendor, dev->descriptor.idProduct); 215 le16_to_cpu(dev->descriptor.idVendor),
216 le16_to_cpu(dev->descriptor.idProduct));
204 break; 217 break;
205 } 218 }
206 219
207 acecad->dev.absfuzz[ABS_X] = 4; 220 input_dev->absfuzz[ABS_X] = 4;
208 acecad->dev.absfuzz[ABS_Y] = 4; 221 input_dev->absfuzz[ABS_Y] = 4;
209
210 acecad->dev.private = acecad;
211 acecad->dev.open = usb_acecad_open;
212 acecad->dev.close = usb_acecad_close;
213
214 acecad->dev.name = acecad->name;
215 acecad->dev.phys = acecad->phys;
216 usb_to_input_id(dev, &acecad->dev.id);
217 acecad->dev.dev = &intf->dev;
218 222
219 usb_fill_int_urb(acecad->irq, dev, pipe, 223 usb_fill_int_urb(acecad->irq, dev, pipe,
220 acecad->data, maxp > 8 ? 8 : maxp, 224 acecad->data, maxp > 8 ? 8 : maxp,
@@ -222,17 +226,15 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_
222 acecad->irq->transfer_dma = acecad->data_dma; 226 acecad->irq->transfer_dma = acecad->data_dma;
223 acecad->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 227 acecad->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
224 228
225 input_register_device(&acecad->dev); 229 input_register_device(acecad->input);
226
227 printk(KERN_INFO "input: %s with packet size %d on %s\n",
228 acecad->name, maxp, path);
229 230
230 usb_set_intfdata(intf, acecad); 231 usb_set_intfdata(intf, acecad);
231 232
232 return 0; 233 return 0;
233 234
234 fail2: usb_buffer_free(dev, 8, acecad->data, acecad->data_dma); 235 fail2: usb_buffer_free(dev, 8, acecad->data, acecad->data_dma);
235 fail1: kfree(acecad); 236 fail1: input_free_device(input_dev);
237 kfree(acecad);
236 return -ENOMEM; 238 return -ENOMEM;
237} 239}
238 240
@@ -243,7 +245,7 @@ static void usb_acecad_disconnect(struct usb_interface *intf)
243 usb_set_intfdata(intf, NULL); 245 usb_set_intfdata(intf, NULL);
244 if (acecad) { 246 if (acecad) {
245 usb_kill_urb(acecad->irq); 247 usb_kill_urb(acecad->irq);
246 input_unregister_device(&acecad->dev); 248 input_unregister_device(acecad->input);
247 usb_free_urb(acecad->irq); 249 usb_free_urb(acecad->irq);
248 usb_buffer_free(interface_to_usbdev(intf), 10, acecad->data, acecad->data_dma); 250 usb_buffer_free(interface_to_usbdev(intf), 10, acecad->data, acecad->data_dma);
249 kfree(acecad); 251 kfree(acecad);
diff --git a/drivers/usb/input/aiptek.c b/drivers/usb/input/aiptek.c
index cd0cbfe20723..1c3b472a3bca 100644
--- a/drivers/usb/input/aiptek.c
+++ b/drivers/usb/input/aiptek.c
@@ -317,7 +317,7 @@ struct aiptek_settings {
317}; 317};
318 318
319struct aiptek { 319struct aiptek {
320 struct input_dev inputdev; /* input device struct */ 320 struct input_dev *inputdev; /* input device struct */
321 struct usb_device *usbdev; /* usb device struct */ 321 struct usb_device *usbdev; /* usb device struct */
322 struct urb *urb; /* urb for incoming reports */ 322 struct urb *urb; /* urb for incoming reports */
323 dma_addr_t data_dma; /* our dma stuffage */ 323 dma_addr_t data_dma; /* our dma stuffage */
@@ -402,7 +402,7 @@ static void aiptek_irq(struct urb *urb, struct pt_regs *regs)
402{ 402{
403 struct aiptek *aiptek = urb->context; 403 struct aiptek *aiptek = urb->context;
404 unsigned char *data = aiptek->data; 404 unsigned char *data = aiptek->data;
405 struct input_dev *inputdev = &aiptek->inputdev; 405 struct input_dev *inputdev = aiptek->inputdev;
406 int jitterable = 0; 406 int jitterable = 0;
407 int retval, macro, x, y, z, left, right, middle, p, dv, tip, bs, pck; 407 int retval, macro, x, y, z, left, right, middle, p, dv, tip, bs, pck;
408 408
@@ -955,20 +955,20 @@ static int aiptek_program_tablet(struct aiptek *aiptek)
955 /* Query getXextension */ 955 /* Query getXextension */
956 if ((ret = aiptek_query(aiptek, 0x01, 0x00)) < 0) 956 if ((ret = aiptek_query(aiptek, 0x01, 0x00)) < 0)
957 return ret; 957 return ret;
958 aiptek->inputdev.absmin[ABS_X] = 0; 958 aiptek->inputdev->absmin[ABS_X] = 0;
959 aiptek->inputdev.absmax[ABS_X] = ret - 1; 959 aiptek->inputdev->absmax[ABS_X] = ret - 1;
960 960
961 /* Query getYextension */ 961 /* Query getYextension */
962 if ((ret = aiptek_query(aiptek, 0x01, 0x01)) < 0) 962 if ((ret = aiptek_query(aiptek, 0x01, 0x01)) < 0)
963 return ret; 963 return ret;
964 aiptek->inputdev.absmin[ABS_Y] = 0; 964 aiptek->inputdev->absmin[ABS_Y] = 0;
965 aiptek->inputdev.absmax[ABS_Y] = ret - 1; 965 aiptek->inputdev->absmax[ABS_Y] = ret - 1;
966 966
967 /* Query getPressureLevels */ 967 /* Query getPressureLevels */
968 if ((ret = aiptek_query(aiptek, 0x08, 0x00)) < 0) 968 if ((ret = aiptek_query(aiptek, 0x08, 0x00)) < 0)
969 return ret; 969 return ret;
970 aiptek->inputdev.absmin[ABS_PRESSURE] = 0; 970 aiptek->inputdev->absmin[ABS_PRESSURE] = 0;
971 aiptek->inputdev.absmax[ABS_PRESSURE] = ret - 1; 971 aiptek->inputdev->absmax[ABS_PRESSURE] = ret - 1;
972 972
973 /* Depending on whether we are in absolute or relative mode, we will 973 /* Depending on whether we are in absolute or relative mode, we will
974 * do a switchToTablet(absolute) or switchToMouse(relative) command. 974 * do a switchToTablet(absolute) or switchToMouse(relative) command.
@@ -1025,8 +1025,8 @@ static ssize_t show_tabletSize(struct device *dev, struct device_attribute *attr
1025 return 0; 1025 return 0;
1026 1026
1027 return snprintf(buf, PAGE_SIZE, "%dx%d\n", 1027 return snprintf(buf, PAGE_SIZE, "%dx%d\n",
1028 aiptek->inputdev.absmax[ABS_X] + 1, 1028 aiptek->inputdev->absmax[ABS_X] + 1,
1029 aiptek->inputdev.absmax[ABS_Y] + 1); 1029 aiptek->inputdev->absmax[ABS_Y] + 1);
1030} 1030}
1031 1031
1032/* These structs define the sysfs files, param #1 is the name of the 1032/* These structs define the sysfs files, param #1 is the name of the
@@ -1048,7 +1048,7 @@ static ssize_t show_tabletProductId(struct device *dev, struct device_attribute
1048 return 0; 1048 return 0;
1049 1049
1050 return snprintf(buf, PAGE_SIZE, "0x%04x\n", 1050 return snprintf(buf, PAGE_SIZE, "0x%04x\n",
1051 aiptek->inputdev.id.product); 1051 aiptek->inputdev->id.product);
1052} 1052}
1053 1053
1054static DEVICE_ATTR(product_id, S_IRUGO, show_tabletProductId, NULL); 1054static DEVICE_ATTR(product_id, S_IRUGO, show_tabletProductId, NULL);
@@ -1063,7 +1063,7 @@ static ssize_t show_tabletVendorId(struct device *dev, struct device_attribute *
1063 if (aiptek == NULL) 1063 if (aiptek == NULL)
1064 return 0; 1064 return 0;
1065 1065
1066 return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->inputdev.id.vendor); 1066 return snprintf(buf, PAGE_SIZE, "0x%04x\n", aiptek->inputdev->id.vendor);
1067} 1067}
1068 1068
1069static DEVICE_ATTR(vendor_id, S_IRUGO, show_tabletVendorId, NULL); 1069static DEVICE_ATTR(vendor_id, S_IRUGO, show_tabletVendorId, NULL);
@@ -1977,7 +1977,6 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
1977 struct input_dev *inputdev; 1977 struct input_dev *inputdev;
1978 struct input_handle *inputhandle; 1978 struct input_handle *inputhandle;
1979 struct list_head *node, *next; 1979 struct list_head *node, *next;
1980 char path[64 + 1];
1981 int i; 1980 int i;
1982 int speeds[] = { 0, 1981 int speeds[] = { 0,
1983 AIPTEK_PROGRAMMABLE_DELAY_50, 1982 AIPTEK_PROGRAMMABLE_DELAY_50,
@@ -1996,24 +1995,26 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
1996 */ 1995 */
1997 speeds[0] = programmableDelay; 1996 speeds[0] = programmableDelay;
1998 1997
1999 if ((aiptek = kmalloc(sizeof(struct aiptek), GFP_KERNEL)) == NULL) 1998 aiptek = kzalloc(sizeof(struct aiptek), GFP_KERNEL);
2000 return -ENOMEM; 1999 inputdev = input_allocate_device();
2001 memset(aiptek, 0, sizeof(struct aiptek)); 2000 if (!aiptek || !inputdev)
2001 goto fail1;
2002 2002
2003 aiptek->data = usb_buffer_alloc(usbdev, AIPTEK_PACKET_LENGTH, 2003 aiptek->data = usb_buffer_alloc(usbdev, AIPTEK_PACKET_LENGTH,
2004 SLAB_ATOMIC, &aiptek->data_dma); 2004 SLAB_ATOMIC, &aiptek->data_dma);
2005 if (aiptek->data == NULL) { 2005 if (!aiptek->data)
2006 kfree(aiptek); 2006 goto fail1;
2007 return -ENOMEM;
2008 }
2009 2007
2010 aiptek->urb = usb_alloc_urb(0, GFP_KERNEL); 2008 aiptek->urb = usb_alloc_urb(0, GFP_KERNEL);
2011 if (aiptek->urb == NULL) { 2009 if (!aiptek->urb)
2012 usb_buffer_free(usbdev, AIPTEK_PACKET_LENGTH, aiptek->data, 2010 goto fail2;
2013 aiptek->data_dma); 2011
2014 kfree(aiptek); 2012 aiptek->inputdev = inputdev;
2015 return -ENOMEM; 2013 aiptek->usbdev = usbdev;
2016 } 2014 aiptek->ifnum = intf->altsetting[0].desc.bInterfaceNumber;
2015 aiptek->inDelay = 0;
2016 aiptek->endDelay = 0;
2017 aiptek->previousJitterable = 0;
2017 2018
2018 /* Set up the curSettings struct. Said struct contains the current 2019 /* Set up the curSettings struct. Said struct contains the current
2019 * programmable parameters. The newSetting struct contains changes 2020 * programmable parameters. The newSetting struct contains changes
@@ -2036,31 +2037,48 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
2036 2037
2037 /* Both structs should have equivalent settings 2038 /* Both structs should have equivalent settings
2038 */ 2039 */
2039 memcpy(&aiptek->newSetting, &aiptek->curSetting, 2040 aiptek->newSetting = aiptek->curSetting;
2040 sizeof(struct aiptek_settings)); 2041
2042 /* Determine the usb devices' physical path.
2043 * Asketh not why we always pretend we're using "../input0",
2044 * but I suspect this will have to be refactored one
2045 * day if a single USB device can be a keyboard & a mouse
2046 * & a tablet, and the inputX number actually will tell
2047 * us something...
2048 */
2049 usb_make_path(usbdev, aiptek->features.usbPath,
2050 sizeof(aiptek->features.usbPath));
2051 strlcat(aiptek->features.usbPath, "/input0",
2052 sizeof(aiptek->features.usbPath));
2053
2054 /* Set up client data, pointers to open and close routines
2055 * for the input device.
2056 */
2057 inputdev->name = "Aiptek";
2058 inputdev->phys = aiptek->features.usbPath;
2059 usb_to_input_id(usbdev, &inputdev->id);
2060 inputdev->cdev.dev = &intf->dev;
2061 inputdev->private = aiptek;
2062 inputdev->open = aiptek_open;
2063 inputdev->close = aiptek_close;
2041 2064
2042 /* Now program the capacities of the tablet, in terms of being 2065 /* Now program the capacities of the tablet, in terms of being
2043 * an input device. 2066 * an input device.
2044 */ 2067 */
2045 aiptek->inputdev.evbit[0] |= BIT(EV_KEY) 2068 inputdev->evbit[0] |= BIT(EV_KEY)
2046 | BIT(EV_ABS) 2069 | BIT(EV_ABS)
2047 | BIT(EV_REL) 2070 | BIT(EV_REL)
2048 | BIT(EV_MSC); 2071 | BIT(EV_MSC);
2049 2072
2050 aiptek->inputdev.absbit[0] |= 2073 inputdev->absbit[0] |= BIT(ABS_MISC);
2051 (BIT(ABS_X) |
2052 BIT(ABS_Y) |
2053 BIT(ABS_PRESSURE) |
2054 BIT(ABS_TILT_X) |
2055 BIT(ABS_TILT_Y) | BIT(ABS_WHEEL) | BIT(ABS_MISC));
2056 2074
2057 aiptek->inputdev.relbit[0] |= 2075 inputdev->relbit[0] |=
2058 (BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL) | BIT(REL_MISC)); 2076 (BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL) | BIT(REL_MISC));
2059 2077
2060 aiptek->inputdev.keybit[LONG(BTN_LEFT)] |= 2078 inputdev->keybit[LONG(BTN_LEFT)] |=
2061 (BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE)); 2079 (BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE));
2062 2080
2063 aiptek->inputdev.keybit[LONG(BTN_DIGI)] |= 2081 inputdev->keybit[LONG(BTN_DIGI)] |=
2064 (BIT(BTN_TOOL_PEN) | 2082 (BIT(BTN_TOOL_PEN) |
2065 BIT(BTN_TOOL_RUBBER) | 2083 BIT(BTN_TOOL_RUBBER) |
2066 BIT(BTN_TOOL_PENCIL) | 2084 BIT(BTN_TOOL_PENCIL) |
@@ -2070,70 +2088,26 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
2070 BIT(BTN_TOOL_LENS) | 2088 BIT(BTN_TOOL_LENS) |
2071 BIT(BTN_TOUCH) | BIT(BTN_STYLUS) | BIT(BTN_STYLUS2)); 2089 BIT(BTN_TOUCH) | BIT(BTN_STYLUS) | BIT(BTN_STYLUS2));
2072 2090
2073 aiptek->inputdev.mscbit[0] = BIT(MSC_SERIAL); 2091 inputdev->mscbit[0] = BIT(MSC_SERIAL);
2074 2092
2075 /* Programming the tablet macro keys needs to be done with a for loop 2093 /* Programming the tablet macro keys needs to be done with a for loop
2076 * as the keycodes are discontiguous. 2094 * as the keycodes are discontiguous.
2077 */ 2095 */
2078 for (i = 0; i < sizeof(macroKeyEvents) / sizeof(macroKeyEvents[0]); ++i) 2096 for (i = 0; i < sizeof(macroKeyEvents) / sizeof(macroKeyEvents[0]); ++i)
2079 set_bit(macroKeyEvents[i], aiptek->inputdev.keybit); 2097 set_bit(macroKeyEvents[i], inputdev->keybit);
2080
2081 /* Set up client data, pointers to open and close routines
2082 * for the input device.
2083 */
2084 aiptek->inputdev.private = aiptek;
2085 aiptek->inputdev.open = aiptek_open;
2086 aiptek->inputdev.close = aiptek_close;
2087 2098
2088 /* Determine the usb devices' physical path. 2099 /*
2089 * Asketh not why we always pretend we're using "../input0", 2100 * Program the input device coordinate capacities. We do not yet
2090 * but I suspect this will have to be refactored one
2091 * day if a single USB device can be a keyboard & a mouse
2092 * & a tablet, and the inputX number actually will tell
2093 * us something...
2094 */
2095 if (usb_make_path(usbdev, path, 64) > 0)
2096 sprintf(aiptek->features.usbPath, "%s/input0", path);
2097
2098 /* Program the input device coordinate capacities. We do not yet
2099 * know what maximum X, Y, and Z values are, so we're putting fake 2101 * know what maximum X, Y, and Z values are, so we're putting fake
2100 * values in. Later, we'll ask the tablet to put in the correct 2102 * values in. Later, we'll ask the tablet to put in the correct
2101 * values. 2103 * values.
2102 */ 2104 */
2103 aiptek->inputdev.absmin[ABS_X] = 0; 2105 input_set_abs_params(inputdev, ABS_X, 0, 2999, 0, 0);
2104 aiptek->inputdev.absmax[ABS_X] = 2999; 2106 input_set_abs_params(inputdev, ABS_X, 0, 2249, 0, 0);
2105 aiptek->inputdev.absmin[ABS_Y] = 0; 2107 input_set_abs_params(inputdev, ABS_PRESSURE, 0, 511, 0, 0);
2106 aiptek->inputdev.absmax[ABS_Y] = 2249; 2108 input_set_abs_params(inputdev, ABS_TILT_X, AIPTEK_TILT_MIN, AIPTEK_TILT_MAX, 0, 0);
2107 aiptek->inputdev.absmin[ABS_PRESSURE] = 0; 2109 input_set_abs_params(inputdev, ABS_TILT_Y, AIPTEK_TILT_MIN, AIPTEK_TILT_MAX, 0, 0);
2108 aiptek->inputdev.absmax[ABS_PRESSURE] = 511; 2110 input_set_abs_params(inputdev, ABS_WHEEL, AIPTEK_WHEEL_MIN, AIPTEK_WHEEL_MAX - 1, 0, 0);
2109 aiptek->inputdev.absmin[ABS_TILT_X] = AIPTEK_TILT_MIN;
2110 aiptek->inputdev.absmax[ABS_TILT_X] = AIPTEK_TILT_MAX;
2111 aiptek->inputdev.absmin[ABS_TILT_Y] = AIPTEK_TILT_MIN;
2112 aiptek->inputdev.absmax[ABS_TILT_Y] = AIPTEK_TILT_MAX;
2113 aiptek->inputdev.absmin[ABS_WHEEL] = AIPTEK_WHEEL_MIN;
2114 aiptek->inputdev.absmax[ABS_WHEEL] = AIPTEK_WHEEL_MAX - 1;
2115 aiptek->inputdev.absfuzz[ABS_X] = 0;
2116 aiptek->inputdev.absfuzz[ABS_Y] = 0;
2117 aiptek->inputdev.absfuzz[ABS_PRESSURE] = 0;
2118 aiptek->inputdev.absfuzz[ABS_TILT_X] = 0;
2119 aiptek->inputdev.absfuzz[ABS_TILT_Y] = 0;
2120 aiptek->inputdev.absfuzz[ABS_WHEEL] = 0;
2121 aiptek->inputdev.absflat[ABS_X] = 0;
2122 aiptek->inputdev.absflat[ABS_Y] = 0;
2123 aiptek->inputdev.absflat[ABS_PRESSURE] = 0;
2124 aiptek->inputdev.absflat[ABS_TILT_X] = 0;
2125 aiptek->inputdev.absflat[ABS_TILT_Y] = 0;
2126 aiptek->inputdev.absflat[ABS_WHEEL] = 0;
2127 aiptek->inputdev.name = "Aiptek";
2128 aiptek->inputdev.phys = aiptek->features.usbPath;
2129 usb_to_input_id(usbdev, &aiptek->inputdev.id);
2130 aiptek->inputdev.dev = &intf->dev;
2131
2132 aiptek->usbdev = usbdev;
2133 aiptek->ifnum = intf->altsetting[0].desc.bInterfaceNumber;
2134 aiptek->inDelay = 0;
2135 aiptek->endDelay = 0;
2136 aiptek->previousJitterable = 0;
2137 2111
2138 endpoint = &intf->altsetting[0].endpoint[0].desc; 2112 endpoint = &intf->altsetting[0].endpoint[0].desc;
2139 2113
@@ -2150,28 +2124,6 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
2150 aiptek->urb->transfer_dma = aiptek->data_dma; 2124 aiptek->urb->transfer_dma = aiptek->data_dma;
2151 aiptek->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 2125 aiptek->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
2152 2126
2153 /* Register the tablet as an Input Device
2154 */
2155 input_register_device(&aiptek->inputdev);
2156
2157 /* We now will look for the evdev device which is mapped to
2158 * the tablet. The partial name is kept in the link list of
2159 * input_handles associated with this input device.
2160 * What identifies an evdev input_handler is that it begins
2161 * with 'event', continues with a digit, and that in turn
2162 * is mapped to /{devfs}/input/eventN.
2163 */
2164 inputdev = &aiptek->inputdev;
2165 list_for_each_safe(node, next, &inputdev->h_list) {
2166 inputhandle = to_handle(node);
2167 if (strncmp(inputhandle->name, "event", 5) == 0) {
2168 strcpy(aiptek->features.inputPath, inputhandle->name);
2169 break;
2170 }
2171 }
2172
2173 info("input: Aiptek on %s (%s)\n", path, aiptek->features.inputPath);
2174
2175 /* Program the tablet. This sets the tablet up in the mode 2127 /* Program the tablet. This sets the tablet up in the mode
2176 * specified in newSetting, and also queries the tablet's 2128 * specified in newSetting, and also queries the tablet's
2177 * physical capacities. 2129 * physical capacities.
@@ -2186,13 +2138,32 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
2186 for (i = 0; i < sizeof(speeds) / sizeof(speeds[0]); ++i) { 2138 for (i = 0; i < sizeof(speeds) / sizeof(speeds[0]); ++i) {
2187 aiptek->curSetting.programmableDelay = speeds[i]; 2139 aiptek->curSetting.programmableDelay = speeds[i];
2188 (void)aiptek_program_tablet(aiptek); 2140 (void)aiptek_program_tablet(aiptek);
2189 if (aiptek->inputdev.absmax[ABS_X] > 0) { 2141 if (aiptek->inputdev->absmax[ABS_X] > 0) {
2190 info("input: Aiptek using %d ms programming speed\n", 2142 info("input: Aiptek using %d ms programming speed\n",
2191 aiptek->curSetting.programmableDelay); 2143 aiptek->curSetting.programmableDelay);
2192 break; 2144 break;
2193 } 2145 }
2194 } 2146 }
2195 2147
2148 /* Register the tablet as an Input Device
2149 */
2150 input_register_device(aiptek->inputdev);
2151
2152 /* We now will look for the evdev device which is mapped to
2153 * the tablet. The partial name is kept in the link list of
2154 * input_handles associated with this input device.
2155 * What identifies an evdev input_handler is that it begins
2156 * with 'event', continues with a digit, and that in turn
2157 * is mapped to input/eventN.
2158 */
2159 list_for_each_safe(node, next, &inputdev->h_list) {
2160 inputhandle = to_handle(node);
2161 if (strncmp(inputhandle->name, "event", 5) == 0) {
2162 strcpy(aiptek->features.inputPath, inputhandle->name);
2163 break;
2164 }
2165 }
2166
2196 /* Associate this driver's struct with the usb interface. 2167 /* Associate this driver's struct with the usb interface.
2197 */ 2168 */
2198 usb_set_intfdata(intf, aiptek); 2169 usb_set_intfdata(intf, aiptek);
@@ -2207,6 +2178,12 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
2207 info("aiptek: error loading 'evdev' module"); 2178 info("aiptek: error loading 'evdev' module");
2208 2179
2209 return 0; 2180 return 0;
2181
2182fail2: usb_buffer_free(usbdev, AIPTEK_PACKET_LENGTH, aiptek->data,
2183 aiptek->data_dma);
2184fail1: input_free_device(inputdev);
2185 kfree(aiptek);
2186 return -ENOMEM;
2210} 2187}
2211 2188
2212/* Forward declaration */ 2189/* Forward declaration */
@@ -2234,7 +2211,7 @@ static void aiptek_disconnect(struct usb_interface *intf)
2234 /* Free & unhook everything from the system. 2211 /* Free & unhook everything from the system.
2235 */ 2212 */
2236 usb_kill_urb(aiptek->urb); 2213 usb_kill_urb(aiptek->urb);
2237 input_unregister_device(&aiptek->inputdev); 2214 input_unregister_device(aiptek->inputdev);
2238 aiptek_delete_files(&intf->dev); 2215 aiptek_delete_files(&intf->dev);
2239 usb_free_urb(aiptek->urb); 2216 usb_free_urb(aiptek->urb);
2240 usb_buffer_free(interface_to_usbdev(intf), 2217 usb_buffer_free(interface_to_usbdev(intf),
diff --git a/drivers/usb/input/appletouch.c b/drivers/usb/input/appletouch.c
index e03c1c567a14..15840db092a5 100644
--- a/drivers/usb/input/appletouch.c
+++ b/drivers/usb/input/appletouch.c
@@ -39,7 +39,7 @@
39#define APPLE_VENDOR_ID 0x05AC 39#define APPLE_VENDOR_ID 0x05AC
40 40
41#define ATP_DEVICE(prod) \ 41#define ATP_DEVICE(prod) \
42 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \ 42 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
43 USB_DEVICE_ID_MATCH_INT_CLASS | \ 43 USB_DEVICE_ID_MATCH_INT_CLASS | \
44 USB_DEVICE_ID_MATCH_INT_PROTOCOL, \ 44 USB_DEVICE_ID_MATCH_INT_PROTOCOL, \
45 .idVendor = APPLE_VENDOR_ID, \ 45 .idVendor = APPLE_VENDOR_ID, \
@@ -78,9 +78,9 @@ MODULE_DEVICE_TABLE (usb, atp_table);
78 * We try to keep the touchpad aspect ratio while still doing only simple 78 * We try to keep the touchpad aspect ratio while still doing only simple
79 * arithmetics. 79 * arithmetics.
80 * The factors below give coordinates like: 80 * The factors below give coordinates like:
81 * 0 <= x < 960 on 12" and 15" Powerbooks 81 * 0 <= x < 960 on 12" and 15" Powerbooks
82 * 0 <= x < 1600 on 17" Powerbooks 82 * 0 <= x < 1600 on 17" Powerbooks
83 * 0 <= y < 646 83 * 0 <= y < 646
84 */ 84 */
85#define ATP_XFACT 64 85#define ATP_XFACT 64
86#define ATP_YFACT 43 86#define ATP_YFACT 43
@@ -93,11 +93,12 @@ MODULE_DEVICE_TABLE (usb, atp_table);
93 93
94/* Structure to hold all of our device specific stuff */ 94/* Structure to hold all of our device specific stuff */
95struct atp { 95struct atp {
96 char phys[64];
96 struct usb_device * udev; /* usb device */ 97 struct usb_device * udev; /* usb device */
97 struct urb * urb; /* usb request block */ 98 struct urb * urb; /* usb request block */
98 signed char * data; /* transferred data */ 99 signed char * data; /* transferred data */
99 int open; /* non-zero if opened */ 100 int open; /* non-zero if opened */
100 struct input_dev input; /* input dev */ 101 struct input_dev *input; /* input dev */
101 int valid; /* are the sensors valid ? */ 102 int valid; /* are the sensors valid ? */
102 int x_old; /* last reported x/y, */ 103 int x_old; /* last reported x/y, */
103 int y_old; /* used for smoothing */ 104 int y_old; /* used for smoothing */
@@ -114,11 +115,11 @@ struct atp {
114 int i; \ 115 int i; \
115 printk("appletouch: %s %lld", msg, (long long)jiffies); \ 116 printk("appletouch: %s %lld", msg, (long long)jiffies); \
116 for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) \ 117 for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) \
117 printk(" %02x", tab[i]); \ 118 printk(" %02x", tab[i]); \
118 printk("\n"); \ 119 printk("\n"); \
119 } 120 }
120 121
121#define dprintk(format, a...) \ 122#define dprintk(format, a...) \
122 do { \ 123 do { \
123 if (debug) printk(format, ##a); \ 124 if (debug) printk(format, ##a); \
124 } while (0) 125 } while (0)
@@ -219,8 +220,8 @@ static void atp_complete(struct urb* urb, struct pt_regs* regs)
219 for (i = 16; i < ATP_XSENSORS; i++) 220 for (i = 16; i < ATP_XSENSORS; i++)
220 if (dev->xy_cur[i]) { 221 if (dev->xy_cur[i]) {
221 printk("appletouch: 17\" model detected.\n"); 222 printk("appletouch: 17\" model detected.\n");
222 input_set_abs_params(&dev->input, ABS_X, 0, 223 input_set_abs_params(dev->input, ABS_X, 0,
223 (ATP_XSENSORS - 1) * 224 (ATP_XSENSORS - 1) *
224 ATP_XFACT - 1, 225 ATP_XFACT - 1,
225 ATP_FUZZ, 0); 226 ATP_FUZZ, 0);
226 break; 227 break;
@@ -260,12 +261,12 @@ static void atp_complete(struct urb* urb, struct pt_regs* regs)
260 "Xz: %3d Yz: %3d\n", 261 "Xz: %3d Yz: %3d\n",
261 x, y, x_z, y_z); 262 x, y, x_z, y_z);
262 263
263 input_report_key(&dev->input, BTN_TOUCH, 1); 264 input_report_key(dev->input, BTN_TOUCH, 1);
264 input_report_abs(&dev->input, ABS_X, x); 265 input_report_abs(dev->input, ABS_X, x);
265 input_report_abs(&dev->input, ABS_Y, y); 266 input_report_abs(dev->input, ABS_Y, y);
266 input_report_abs(&dev->input, ABS_PRESSURE, 267 input_report_abs(dev->input, ABS_PRESSURE,
267 min(ATP_PRESSURE, x_z + y_z)); 268 min(ATP_PRESSURE, x_z + y_z));
268 atp_report_fingers(&dev->input, max(x_f, y_f)); 269 atp_report_fingers(dev->input, max(x_f, y_f));
269 } 270 }
270 dev->x_old = x; 271 dev->x_old = x;
271 dev->y_old = y; 272 dev->y_old = y;
@@ -273,17 +274,17 @@ static void atp_complete(struct urb* urb, struct pt_regs* regs)
273 else if (!x && !y) { 274 else if (!x && !y) {
274 275
275 dev->x_old = dev->y_old = -1; 276 dev->x_old = dev->y_old = -1;
276 input_report_key(&dev->input, BTN_TOUCH, 0); 277 input_report_key(dev->input, BTN_TOUCH, 0);
277 input_report_abs(&dev->input, ABS_PRESSURE, 0); 278 input_report_abs(dev->input, ABS_PRESSURE, 0);
278 atp_report_fingers(&dev->input, 0); 279 atp_report_fingers(dev->input, 0);
279 280
280 /* reset the accumulator on release */ 281 /* reset the accumulator on release */
281 memset(dev->xy_acc, 0, sizeof(dev->xy_acc)); 282 memset(dev->xy_acc, 0, sizeof(dev->xy_acc));
282 } 283 }
283 284
284 input_report_key(&dev->input, BTN_LEFT, !!dev->data[80]); 285 input_report_key(dev->input, BTN_LEFT, !!dev->data[80]);
285 286
286 input_sync(&dev->input); 287 input_sync(dev->input);
287 288
288exit: 289exit:
289 retval = usb_submit_urb(dev->urb, GFP_ATOMIC); 290 retval = usb_submit_urb(dev->urb, GFP_ATOMIC);
@@ -314,21 +315,14 @@ static void atp_close(struct input_dev *input)
314 315
315static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id) 316static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id)
316{ 317{
317 struct atp *dev = NULL; 318 struct atp *dev;
319 struct input_dev *input_dev;
320 struct usb_device *udev = interface_to_usbdev(iface);
318 struct usb_host_interface *iface_desc; 321 struct usb_host_interface *iface_desc;
319 struct usb_endpoint_descriptor *endpoint; 322 struct usb_endpoint_descriptor *endpoint;
320 int int_in_endpointAddr = 0; 323 int int_in_endpointAddr = 0;
321 int i, retval = -ENOMEM; 324 int i, retval = -ENOMEM;
322 325
323 /* allocate memory for our device state and initialize it */
324 dev = kmalloc(sizeof(struct atp), GFP_KERNEL);
325 if (dev == NULL) {
326 err("Out of memory");
327 goto err_kmalloc;
328 }
329 memset(dev, 0, sizeof(struct atp));
330
331 dev->udev = interface_to_usbdev(iface);
332 326
333 /* set up the endpoint information */ 327 /* set up the endpoint information */
334 /* use only the first interrupt-in endpoint */ 328 /* use only the first interrupt-in endpoint */
@@ -345,70 +339,82 @@ static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id
345 } 339 }
346 } 340 }
347 if (!int_in_endpointAddr) { 341 if (!int_in_endpointAddr) {
348 retval = -EIO;
349 err("Could not find int-in endpoint"); 342 err("Could not find int-in endpoint");
350 goto err_endpoint; 343 return -EIO;
351 } 344 }
352 345
353 /* save our data pointer in this interface device */ 346 /* allocate memory for our device state and initialize it */
354 usb_set_intfdata(iface, dev); 347 dev = kzalloc(sizeof(struct atp), GFP_KERNEL);
348 input_dev = input_allocate_device();
349 if (!dev || !input_dev) {
350 err("Out of memory");
351 goto err_free_devs;
352 }
353
354 dev->udev = udev;
355 dev->input = input_dev;
355 356
356 dev->urb = usb_alloc_urb(0, GFP_KERNEL); 357 dev->urb = usb_alloc_urb(0, GFP_KERNEL);
357 if (!dev->urb) { 358 if (!dev->urb) {
358 retval = -ENOMEM; 359 retval = -ENOMEM;
359 goto err_usballoc; 360 goto err_free_devs;
360 } 361 }
362
361 dev->data = usb_buffer_alloc(dev->udev, ATP_DATASIZE, GFP_KERNEL, 363 dev->data = usb_buffer_alloc(dev->udev, ATP_DATASIZE, GFP_KERNEL,
362 &dev->urb->transfer_dma); 364 &dev->urb->transfer_dma);
363 if (!dev->data) { 365 if (!dev->data) {
364 retval = -ENOMEM; 366 retval = -ENOMEM;
365 goto err_usbbufalloc; 367 goto err_free_urb;
366 } 368 }
367 usb_fill_int_urb(dev->urb, dev->udev, 369
368 usb_rcvintpipe(dev->udev, int_in_endpointAddr), 370 usb_fill_int_urb(dev->urb, udev,
371 usb_rcvintpipe(udev, int_in_endpointAddr),
369 dev->data, ATP_DATASIZE, atp_complete, dev, 1); 372 dev->data, ATP_DATASIZE, atp_complete, dev, 1);
370 373
371 init_input_dev(&dev->input); 374 usb_make_path(udev, dev->phys, sizeof(dev->phys));
372 dev->input.name = "appletouch"; 375 strlcat(dev->phys, "/input0", sizeof(dev->phys));
373 dev->input.dev = &iface->dev; 376
374 dev->input.private = dev; 377 input_dev->name = "appletouch";
375 dev->input.open = atp_open; 378 input_dev->phys = dev->phys;
376 dev->input.close = atp_close; 379 usb_to_input_id(dev->udev, &input_dev->id);
380 input_dev->cdev.dev = &iface->dev;
377 381
378 usb_to_input_id(dev->udev, &dev->input.id); 382 input_dev->private = dev;
383 input_dev->open = atp_open;
384 input_dev->close = atp_close;
379 385
380 set_bit(EV_ABS, dev->input.evbit); 386 set_bit(EV_ABS, input_dev->evbit);
381 387
382 /* 388 /*
383 * 12" and 15" Powerbooks only have 16 x sensors, 389 * 12" and 15" Powerbooks only have 16 x sensors,
384 * 17" models are detected later. 390 * 17" models are detected later.
385 */ 391 */
386 input_set_abs_params(&dev->input, ABS_X, 0, 392 input_set_abs_params(input_dev, ABS_X, 0,
387 (16 - 1) * ATP_XFACT - 1, ATP_FUZZ, 0); 393 (16 - 1) * ATP_XFACT - 1, ATP_FUZZ, 0);
388 input_set_abs_params(&dev->input, ABS_Y, 0, 394 input_set_abs_params(input_dev, ABS_Y, 0,
389 (ATP_YSENSORS - 1) * ATP_YFACT - 1, ATP_FUZZ, 0); 395 (ATP_YSENSORS - 1) * ATP_YFACT - 1, ATP_FUZZ, 0);
390 input_set_abs_params(&dev->input, ABS_PRESSURE, 0, ATP_PRESSURE, 0, 0); 396 input_set_abs_params(input_dev, ABS_PRESSURE, 0, ATP_PRESSURE, 0, 0);
391 397
392 set_bit(EV_KEY, dev->input.evbit); 398 set_bit(EV_KEY, input_dev->evbit);
393 set_bit(BTN_TOUCH, dev->input.keybit); 399 set_bit(BTN_TOUCH, input_dev->keybit);
394 set_bit(BTN_TOOL_FINGER, dev->input.keybit); 400 set_bit(BTN_TOOL_FINGER, input_dev->keybit);
395 set_bit(BTN_TOOL_DOUBLETAP, dev->input.keybit); 401 set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit);
396 set_bit(BTN_TOOL_TRIPLETAP, dev->input.keybit); 402 set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit);
397 set_bit(BTN_LEFT, dev->input.keybit); 403 set_bit(BTN_LEFT, input_dev->keybit);
398 404
399 input_register_device(&dev->input); 405 input_register_device(dev->input);
400 406
401 printk(KERN_INFO "input: appletouch connected\n"); 407 /* save our data pointer in this interface device */
408 usb_set_intfdata(iface, dev);
402 409
403 return 0; 410 return 0;
404 411
405err_usbbufalloc: 412 err_free_urb:
406 usb_free_urb(dev->urb); 413 usb_free_urb(dev->urb);
407err_usballoc: 414 err_free_devs:
408 usb_set_intfdata(iface, NULL); 415 usb_set_intfdata(iface, NULL);
409err_endpoint:
410 kfree(dev); 416 kfree(dev);
411err_kmalloc: 417 input_free_device(input_dev);
412 return retval; 418 return retval;
413} 419}
414 420
@@ -419,7 +425,7 @@ static void atp_disconnect(struct usb_interface *iface)
419 usb_set_intfdata(iface, NULL); 425 usb_set_intfdata(iface, NULL);
420 if (dev) { 426 if (dev) {
421 usb_kill_urb(dev->urb); 427 usb_kill_urb(dev->urb);
422 input_unregister_device(&dev->input); 428 input_unregister_device(dev->input);
423 usb_free_urb(dev->urb); 429 usb_free_urb(dev->urb);
424 usb_buffer_free(dev->udev, ATP_DATASIZE, 430 usb_buffer_free(dev->udev, ATP_DATASIZE,
425 dev->data, dev->urb->transfer_dma); 431 dev->data, dev->urb->transfer_dma);
diff --git a/drivers/usb/input/ati_remote.c b/drivers/usb/input/ati_remote.c
index fd99681ee483..9a2a47db9494 100644
--- a/drivers/usb/input/ati_remote.c
+++ b/drivers/usb/input/ati_remote.c
@@ -112,7 +112,6 @@
112 112
113#define NAME_BUFSIZE 80 /* size of product name, path buffers */ 113#define NAME_BUFSIZE 80 /* size of product name, path buffers */
114#define DATA_BUFSIZE 63 /* size of URB data buffers */ 114#define DATA_BUFSIZE 63 /* size of URB data buffers */
115#define ATI_INPUTNUM 1 /* Which input device to register as */
116 115
117static unsigned long channel_mask; 116static unsigned long channel_mask;
118module_param(channel_mask, ulong, 0444); 117module_param(channel_mask, ulong, 0444);
@@ -162,7 +161,7 @@ static char accel[] = { 1, 2, 4, 6, 9, 13, 20 };
162static DECLARE_MUTEX(disconnect_sem); 161static DECLARE_MUTEX(disconnect_sem);
163 162
164struct ati_remote { 163struct ati_remote {
165 struct input_dev idev; 164 struct input_dev *idev;
166 struct usb_device *udev; 165 struct usb_device *udev;
167 struct usb_interface *interface; 166 struct usb_interface *interface;
168 167
@@ -198,15 +197,13 @@ struct ati_remote {
198#define KIND_ACCEL 7 /* Directional keypad - left, right, up, down.*/ 197#define KIND_ACCEL 7 /* Directional keypad - left, right, up, down.*/
199 198
200/* Translation table from hardware messages to input events. */ 199/* Translation table from hardware messages to input events. */
201static struct 200static struct {
202{
203 short kind; 201 short kind;
204 unsigned char data1, data2; 202 unsigned char data1, data2;
205 int type; 203 int type;
206 unsigned int code; 204 unsigned int code;
207 int value; 205 int value;
208} ati_remote_tbl[] = 206} ati_remote_tbl[] = {
209{
210 /* Directional control pad axes */ 207 /* Directional control pad axes */
211 {KIND_ACCEL, 0x35, 0x70, EV_REL, REL_X, -1}, /* left */ 208 {KIND_ACCEL, 0x35, 0x70, EV_REL, REL_X, -1}, /* left */
212 {KIND_ACCEL, 0x36, 0x71, EV_REL, REL_X, 1}, /* right */ 209 {KIND_ACCEL, 0x36, 0x71, EV_REL, REL_X, 1}, /* right */
@@ -286,7 +283,6 @@ static struct
286 283
287/* Local function prototypes */ 284/* Local function prototypes */
288static void ati_remote_dump (unsigned char *data, unsigned int actual_length); 285static void ati_remote_dump (unsigned char *data, unsigned int actual_length);
289static void ati_remote_delete (struct ati_remote *dev);
290static int ati_remote_open (struct input_dev *inputdev); 286static int ati_remote_open (struct input_dev *inputdev);
291static void ati_remote_close (struct input_dev *inputdev); 287static void ati_remote_close (struct input_dev *inputdev);
292static int ati_remote_sendpacket (struct ati_remote *ati_remote, u16 cmd, unsigned char *data); 288static int ati_remote_sendpacket (struct ati_remote *ati_remote, u16 cmd, unsigned char *data);
@@ -428,7 +424,7 @@ static void ati_remote_input_report(struct urb *urb, struct pt_regs *regs)
428{ 424{
429 struct ati_remote *ati_remote = urb->context; 425 struct ati_remote *ati_remote = urb->context;
430 unsigned char *data= ati_remote->inbuf; 426 unsigned char *data= ati_remote->inbuf;
431 struct input_dev *dev = &ati_remote->idev; 427 struct input_dev *dev = ati_remote->idev;
432 int index, acc; 428 int index, acc;
433 int remote_num; 429 int remote_num;
434 430
@@ -587,38 +583,55 @@ static void ati_remote_irq_in(struct urb *urb, struct pt_regs *regs)
587} 583}
588 584
589/* 585/*
590 * ati_remote_delete 586 * ati_remote_alloc_buffers
591 */ 587 */
592static void ati_remote_delete(struct ati_remote *ati_remote) 588static int ati_remote_alloc_buffers(struct usb_device *udev,
589 struct ati_remote *ati_remote)
593{ 590{
594 if (ati_remote->irq_urb) 591 ati_remote->inbuf = usb_buffer_alloc(udev, DATA_BUFSIZE, SLAB_ATOMIC,
595 usb_kill_urb(ati_remote->irq_urb); 592 &ati_remote->inbuf_dma);
593 if (!ati_remote->inbuf)
594 return -1;
596 595
597 if (ati_remote->out_urb) 596 ati_remote->outbuf = usb_buffer_alloc(udev, DATA_BUFSIZE, SLAB_ATOMIC,
598 usb_kill_urb(ati_remote->out_urb); 597 &ati_remote->outbuf_dma);
598 if (!ati_remote->outbuf)
599 return -1;
599 600
600 input_unregister_device(&ati_remote->idev); 601 ati_remote->irq_urb = usb_alloc_urb(0, GFP_KERNEL);
602 if (!ati_remote->irq_urb)
603 return -1;
601 604
602 if (ati_remote->inbuf) 605 ati_remote->out_urb = usb_alloc_urb(0, GFP_KERNEL);
603 usb_buffer_free(ati_remote->udev, DATA_BUFSIZE, 606 if (!ati_remote->out_urb)
604 ati_remote->inbuf, ati_remote->inbuf_dma); 607 return -1;
605 608
606 if (ati_remote->outbuf) 609 return 0;
607 usb_buffer_free(ati_remote->udev, DATA_BUFSIZE, 610}
608 ati_remote->outbuf, ati_remote->outbuf_dma);
609 611
612/*
613 * ati_remote_free_buffers
614 */
615static void ati_remote_free_buffers(struct ati_remote *ati_remote)
616{
610 if (ati_remote->irq_urb) 617 if (ati_remote->irq_urb)
611 usb_free_urb(ati_remote->irq_urb); 618 usb_free_urb(ati_remote->irq_urb);
612 619
613 if (ati_remote->out_urb) 620 if (ati_remote->out_urb)
614 usb_free_urb(ati_remote->out_urb); 621 usb_free_urb(ati_remote->out_urb);
615 622
616 kfree(ati_remote); 623 if (ati_remote->inbuf)
624 usb_buffer_free(ati_remote->udev, DATA_BUFSIZE,
625 ati_remote->inbuf, ati_remote->inbuf_dma);
626
627 if (ati_remote->outbuf)
628 usb_buffer_free(ati_remote->udev, DATA_BUFSIZE,
629 ati_remote->inbuf, ati_remote->outbuf_dma);
617} 630}
618 631
619static void ati_remote_input_init(struct ati_remote *ati_remote) 632static void ati_remote_input_init(struct ati_remote *ati_remote)
620{ 633{
621 struct input_dev *idev = &(ati_remote->idev); 634 struct input_dev *idev = ati_remote->idev;
622 int i; 635 int i;
623 636
624 idev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL); 637 idev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
@@ -637,7 +650,7 @@ static void ati_remote_input_init(struct ati_remote *ati_remote)
637 idev->phys = ati_remote->phys; 650 idev->phys = ati_remote->phys;
638 651
639 usb_to_input_id(ati_remote->udev, &idev->id); 652 usb_to_input_id(ati_remote->udev, &idev->id);
640 idev->dev = &ati_remote->udev->dev; 653 idev->cdev.dev = &ati_remote->udev->dev;
641} 654}
642 655
643static int ati_remote_initialize(struct ati_remote *ati_remote) 656static int ati_remote_initialize(struct ati_remote *ati_remote)
@@ -674,7 +687,7 @@ static int ati_remote_initialize(struct ati_remote *ati_remote)
674 (ati_remote_sendpacket(ati_remote, 0x8007, init2))) { 687 (ati_remote_sendpacket(ati_remote, 0x8007, init2))) {
675 dev_err(&ati_remote->interface->dev, 688 dev_err(&ati_remote->interface->dev,
676 "Initializing ati_remote hardware failed.\n"); 689 "Initializing ati_remote hardware failed.\n");
677 return 1; 690 return -EIO;
678 } 691 }
679 692
680 return 0; 693 return 0;
@@ -686,95 +699,83 @@ static int ati_remote_initialize(struct ati_remote *ati_remote)
686static int ati_remote_probe(struct usb_interface *interface, const struct usb_device_id *id) 699static int ati_remote_probe(struct usb_interface *interface, const struct usb_device_id *id)
687{ 700{
688 struct usb_device *udev = interface_to_usbdev(interface); 701 struct usb_device *udev = interface_to_usbdev(interface);
689 struct ati_remote *ati_remote = NULL; 702 struct usb_host_interface *iface_host = interface->cur_altsetting;
690 struct usb_host_interface *iface_host; 703 struct usb_endpoint_descriptor *endpoint_in, *endpoint_out;
691 int retval = -ENOMEM; 704 struct ati_remote *ati_remote;
692 char path[64]; 705 struct input_dev *input_dev;
693 706 int err = -ENOMEM;
694 /* Allocate and clear an ati_remote struct */
695 if (!(ati_remote = kmalloc(sizeof (struct ati_remote), GFP_KERNEL)))
696 return -ENOMEM;
697 memset(ati_remote, 0x00, sizeof (struct ati_remote));
698 707
699 iface_host = interface->cur_altsetting;
700 if (iface_host->desc.bNumEndpoints != 2) { 708 if (iface_host->desc.bNumEndpoints != 2) {
701 err("%s: Unexpected desc.bNumEndpoints\n", __FUNCTION__); 709 err("%s: Unexpected desc.bNumEndpoints\n", __FUNCTION__);
702 retval = -ENODEV; 710 return -ENODEV;
703 goto error;
704 } 711 }
705 712
706 ati_remote->endpoint_in = &(iface_host->endpoint[0].desc); 713 endpoint_in = &iface_host->endpoint[0].desc;
707 ati_remote->endpoint_out = &(iface_host->endpoint[1].desc); 714 endpoint_out = &iface_host->endpoint[1].desc;
708 ati_remote->udev = udev;
709 ati_remote->interface = interface;
710 715
711 if (!(ati_remote->endpoint_in->bEndpointAddress & 0x80)) { 716 if (!(endpoint_in->bEndpointAddress & USB_DIR_IN)) {
712 err("%s: Unexpected endpoint_in->bEndpointAddress\n", __FUNCTION__); 717 err("%s: Unexpected endpoint_in->bEndpointAddress\n", __FUNCTION__);
713 retval = -ENODEV; 718 return -ENODEV;
714 goto error;
715 } 719 }
716 if ((ati_remote->endpoint_in->bmAttributes & 3) != 3) { 720 if ((endpoint_in->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT) {
717 err("%s: Unexpected endpoint_in->bmAttributes\n", __FUNCTION__); 721 err("%s: Unexpected endpoint_in->bmAttributes\n", __FUNCTION__);
718 retval = -ENODEV; 722 return -ENODEV;
719 goto error;
720 } 723 }
721 if (le16_to_cpu(ati_remote->endpoint_in->wMaxPacketSize) == 0) { 724 if (le16_to_cpu(endpoint_in->wMaxPacketSize) == 0) {
722 err("%s: endpoint_in message size==0? \n", __FUNCTION__); 725 err("%s: endpoint_in message size==0? \n", __FUNCTION__);
723 retval = -ENODEV; 726 return -ENODEV;
724 goto error;
725 } 727 }
726 728
727 /* Allocate URB buffers, URBs */ 729 ati_remote = kzalloc(sizeof (struct ati_remote), GFP_KERNEL);
728 ati_remote->inbuf = usb_buffer_alloc(udev, DATA_BUFSIZE, SLAB_ATOMIC, 730 input_dev = input_allocate_device();
729 &ati_remote->inbuf_dma); 731 if (!ati_remote || !input_dev)
730 if (!ati_remote->inbuf) 732 goto fail1;
731 goto error;
732 733
733 ati_remote->outbuf = usb_buffer_alloc(udev, DATA_BUFSIZE, SLAB_ATOMIC, 734 /* Allocate URB buffers, URBs */
734 &ati_remote->outbuf_dma); 735 if (ati_remote_alloc_buffers(udev, ati_remote))
735 if (!ati_remote->outbuf) 736 goto fail2;
736 goto error;
737 737
738 ati_remote->irq_urb = usb_alloc_urb(0, GFP_KERNEL); 738 ati_remote->endpoint_in = endpoint_in;
739 if (!ati_remote->irq_urb) 739 ati_remote->endpoint_out = endpoint_out;
740 goto error; 740 ati_remote->udev = udev;
741 ati_remote->idev = input_dev;
742 ati_remote->interface = interface;
741 743
742 ati_remote->out_urb = usb_alloc_urb(0, GFP_KERNEL); 744 usb_make_path(udev, ati_remote->phys, sizeof(ati_remote->phys));
743 if (!ati_remote->out_urb) 745 strlcpy(ati_remote->phys, "/input0", sizeof(ati_remote->phys));
744 goto error;
745 746
746 usb_make_path(udev, path, NAME_BUFSIZE);
747 sprintf(ati_remote->phys, "%s/input%d", path, ATI_INPUTNUM);
748 if (udev->manufacturer) 747 if (udev->manufacturer)
749 strcat(ati_remote->name, udev->manufacturer); 748 strlcpy(ati_remote->name, udev->manufacturer, sizeof(ati_remote->name));
750 749
751 if (udev->product) 750 if (udev->product)
752 sprintf(ati_remote->name, "%s %s", ati_remote->name, udev->product); 751 snprintf(ati_remote->name, sizeof(ati_remote->name),
752 "%s %s", ati_remote->name, udev->product);
753 753
754 if (!strlen(ati_remote->name)) 754 if (!strlen(ati_remote->name))
755 sprintf(ati_remote->name, DRIVER_DESC "(%04x,%04x)", 755 snprintf(ati_remote->name, sizeof(ati_remote->name),
756 DRIVER_DESC "(%04x,%04x)",
756 le16_to_cpu(ati_remote->udev->descriptor.idVendor), 757 le16_to_cpu(ati_remote->udev->descriptor.idVendor),
757 le16_to_cpu(ati_remote->udev->descriptor.idProduct)); 758 le16_to_cpu(ati_remote->udev->descriptor.idProduct));
758 759
760 ati_remote_input_init(ati_remote);
761
759 /* Device Hardware Initialization - fills in ati_remote->idev from udev. */ 762 /* Device Hardware Initialization - fills in ati_remote->idev from udev. */
760 retval = ati_remote_initialize(ati_remote); 763 err = ati_remote_initialize(ati_remote);
761 if (retval) 764 if (err)
762 goto error; 765 goto fail3;
763 766
764 /* Set up and register input device */ 767 /* Set up and register input device */
765 ati_remote_input_init(ati_remote); 768 input_register_device(ati_remote->idev);
766 input_register_device(&ati_remote->idev);
767
768 dev_info(&ati_remote->interface->dev, "Input registered: %s on %s\n",
769 ati_remote->name, path);
770 769
771 usb_set_intfdata(interface, ati_remote); 770 usb_set_intfdata(interface, ati_remote);
771 return 0;
772 772
773error: 773fail3: usb_kill_urb(ati_remote->irq_urb);
774 if (retval) 774 usb_kill_urb(ati_remote->out_urb);
775 ati_remote_delete(ati_remote); 775fail2: ati_remote_free_buffers(ati_remote);
776 776fail1: input_free_device(input_dev);
777 return retval; 777 kfree(ati_remote);
778 return err;
778} 779}
779 780
780/* 781/*
@@ -791,7 +792,11 @@ static void ati_remote_disconnect(struct usb_interface *interface)
791 return; 792 return;
792 } 793 }
793 794
794 ati_remote_delete(ati_remote); 795 usb_kill_urb(ati_remote->irq_urb);
796 usb_kill_urb(ati_remote->out_urb);
797 input_unregister_device(ati_remote->idev);
798 ati_remote_free_buffers(ati_remote);
799 kfree(ati_remote);
795} 800}
796 801
797/* 802/*
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index 41f92b924761..79ddce4555ab 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -1619,8 +1619,8 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1619 struct hid_descriptor *hdesc; 1619 struct hid_descriptor *hdesc;
1620 struct hid_device *hid; 1620 struct hid_device *hid;
1621 unsigned quirks = 0, rsize = 0; 1621 unsigned quirks = 0, rsize = 0;
1622 char *buf, *rdesc; 1622 char *rdesc;
1623 int n, insize = 0; 1623 int n, len, insize = 0;
1624 1624
1625 for (n = 0; hid_blacklist[n].idVendor; n++) 1625 for (n = 0; hid_blacklist[n].idVendor; n++)
1626 if ((hid_blacklist[n].idVendor == le16_to_cpu(dev->descriptor.idVendor)) && 1626 if ((hid_blacklist[n].idVendor == le16_to_cpu(dev->descriptor.idVendor)) &&
@@ -1630,10 +1630,11 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1630 if (quirks & HID_QUIRK_IGNORE) 1630 if (quirks & HID_QUIRK_IGNORE)
1631 return NULL; 1631 return NULL;
1632 1632
1633 if (usb_get_extra_descriptor(interface, HID_DT_HID, &hdesc) && ((!interface->desc.bNumEndpoints) || 1633 if (usb_get_extra_descriptor(interface, HID_DT_HID, &hdesc) &&
1634 usb_get_extra_descriptor(&interface->endpoint[0], HID_DT_HID, &hdesc))) { 1634 (!interface->desc.bNumEndpoints ||
1635 dbg("class descriptor not present\n"); 1635 usb_get_extra_descriptor(&interface->endpoint[0], HID_DT_HID, &hdesc))) {
1636 return NULL; 1636 dbg("class descriptor not present\n");
1637 return NULL;
1637 } 1638 }
1638 1639
1639 for (n = 0; n < hdesc->bNumDescriptors; n++) 1640 for (n = 0; n < hdesc->bNumDescriptors; n++)
@@ -1749,38 +1750,43 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1749 1750
1750 hid->name[0] = 0; 1751 hid->name[0] = 0;
1751 1752
1752 if (!(buf = kmalloc(64, GFP_KERNEL))) 1753 if (dev->manufacturer)
1753 goto fail; 1754 strlcpy(hid->name, dev->manufacturer, sizeof(hid->name));
1755
1756 if (dev->product) {
1757 if (dev->manufacturer)
1758 strlcat(hid->name, " ", sizeof(hid->name));
1759 strlcat(hid->name, dev->product, sizeof(hid->name));
1760 }
1754 1761
1755 if (dev->manufacturer) { 1762 if (!strlen(hid->name))
1756 strcat(hid->name, dev->manufacturer); 1763 snprintf(hid->name, sizeof(hid->name), "HID %04x:%04x",
1757 if (dev->product) 1764 le16_to_cpu(dev->descriptor.idVendor),
1758 snprintf(hid->name, 64, "%s %s", hid->name, dev->product); 1765 le16_to_cpu(dev->descriptor.idProduct));
1759 } else if (dev->product) { 1766
1760 snprintf(hid->name, 128, "%s", dev->product); 1767 usb_make_path(dev, hid->phys, sizeof(hid->phys));
1761 } else 1768 strlcat(hid->phys, "/input", sizeof(hid->phys));
1762 snprintf(hid->name, 128, "%04x:%04x", 1769 len = strlen(hid->phys);
1763 le16_to_cpu(dev->descriptor.idVendor), 1770 if (len < sizeof(hid->phys) - 1)
1764 le16_to_cpu(dev->descriptor.idProduct)); 1771 snprintf(hid->phys + len, sizeof(hid->phys) - len,
1765 1772 "%d", intf->altsetting[0].desc.bInterfaceNumber);
1766 usb_make_path(dev, buf, 64);
1767 snprintf(hid->phys, 64, "%s/input%d", buf,
1768 intf->altsetting[0].desc.bInterfaceNumber);
1769 1773
1770 if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0) 1774 if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0)
1771 hid->uniq[0] = 0; 1775 hid->uniq[0] = 0;
1772 1776
1773 kfree(buf);
1774
1775 hid->urbctrl = usb_alloc_urb(0, GFP_KERNEL); 1777 hid->urbctrl = usb_alloc_urb(0, GFP_KERNEL);
1776 if (!hid->urbctrl) 1778 if (!hid->urbctrl)
1777 goto fail; 1779 goto fail;
1780
1778 usb_fill_control_urb(hid->urbctrl, dev, 0, (void *) hid->cr, 1781 usb_fill_control_urb(hid->urbctrl, dev, 0, (void *) hid->cr,
1779 hid->ctrlbuf, 1, hid_ctrl, hid); 1782 hid->ctrlbuf, 1, hid_ctrl, hid);
1780 hid->urbctrl->setup_dma = hid->cr_dma; 1783 hid->urbctrl->setup_dma = hid->cr_dma;
1781 hid->urbctrl->transfer_dma = hid->ctrlbuf_dma; 1784 hid->urbctrl->transfer_dma = hid->ctrlbuf_dma;
1782 hid->urbctrl->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP); 1785 hid->urbctrl->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP);
1783 1786
1787 /* May be needed for some devices */
1788 usb_clear_halt(hid->dev, hid->urbin->pipe);
1789
1784 return hid; 1790 return hid;
1785 1791
1786fail: 1792fail:
@@ -1884,7 +1890,6 @@ static int hid_suspend(struct usb_interface *intf, pm_message_t message)
1884 struct hid_device *hid = usb_get_intfdata (intf); 1890 struct hid_device *hid = usb_get_intfdata (intf);
1885 1891
1886 usb_kill_urb(hid->urbin); 1892 usb_kill_urb(hid->urbin);
1887 intf->dev.power.power_state = PMSG_SUSPEND;
1888 dev_dbg(&intf->dev, "suspend\n"); 1893 dev_dbg(&intf->dev, "suspend\n");
1889 return 0; 1894 return 0;
1890} 1895}
@@ -1894,7 +1899,6 @@ static int hid_resume(struct usb_interface *intf)
1894 struct hid_device *hid = usb_get_intfdata (intf); 1899 struct hid_device *hid = usb_get_intfdata (intf);
1895 int status; 1900 int status;
1896 1901
1897 intf->dev.power.power_state = PMSG_ON;
1898 if (hid->open) 1902 if (hid->open)
1899 status = usb_submit_urb(hid->urbin, GFP_NOIO); 1903 status = usb_submit_urb(hid->urbin, GFP_NOIO);
1900 else 1904 else
diff --git a/drivers/usb/input/hid-input.c b/drivers/usb/input/hid-input.c
index 0b6452248a39..9ff25eb520a6 100644
--- a/drivers/usb/input/hid-input.c
+++ b/drivers/usb/input/hid-input.c
@@ -76,8 +76,8 @@ static struct {
76static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_field *field, 76static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_field *field,
77 struct hid_usage *usage) 77 struct hid_usage *usage)
78{ 78{
79 struct input_dev *input = &hidinput->input; 79 struct input_dev *input = hidinput->input;
80 struct hid_device *device = hidinput->input.private; 80 struct hid_device *device = input->private;
81 int max = 0, code; 81 int max = 0, code;
82 unsigned long *bit = NULL; 82 unsigned long *bit = NULL;
83 83
@@ -461,7 +461,8 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
461 461
462 if (!field->hidinput) 462 if (!field->hidinput)
463 return; 463 return;
464 input = &field->hidinput->input; 464
465 input = field->hidinput->input;
465 466
466 input_regs(input, regs); 467 input_regs(input, regs);
467 468
@@ -533,13 +534,10 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
533 534
534void hidinput_report_event(struct hid_device *hid, struct hid_report *report) 535void hidinput_report_event(struct hid_device *hid, struct hid_report *report)
535{ 536{
536 struct list_head *lh;
537 struct hid_input *hidinput; 537 struct hid_input *hidinput;
538 538
539 list_for_each (lh, &hid->inputs) { 539 list_for_each_entry(hidinput, &hid->inputs, list)
540 hidinput = list_entry(lh, struct hid_input, list); 540 input_sync(hidinput->input);
541 input_sync(&hidinput->input);
542 }
543} 541}
544 542
545static int hidinput_find_field(struct hid_device *hid, unsigned int type, unsigned int code, struct hid_field **field) 543static int hidinput_find_field(struct hid_device *hid, unsigned int type, unsigned int code, struct hid_field **field)
@@ -604,6 +602,7 @@ int hidinput_connect(struct hid_device *hid)
604 struct usb_device *dev = hid->dev; 602 struct usb_device *dev = hid->dev;
605 struct hid_report *report; 603 struct hid_report *report;
606 struct hid_input *hidinput = NULL; 604 struct hid_input *hidinput = NULL;
605 struct input_dev *input_dev;
607 int i, j, k; 606 int i, j, k;
608 607
609 INIT_LIST_HEAD(&hid->inputs); 608 INIT_LIST_HEAD(&hid->inputs);
@@ -624,25 +623,28 @@ int hidinput_connect(struct hid_device *hid)
624 continue; 623 continue;
625 624
626 if (!hidinput) { 625 if (!hidinput) {
627 hidinput = kmalloc(sizeof(*hidinput), GFP_KERNEL); 626 hidinput = kzalloc(sizeof(*hidinput), GFP_KERNEL);
628 if (!hidinput) { 627 input_dev = input_allocate_device();
628 if (!hidinput || !input_dev) {
629 kfree(hidinput);
630 input_free_device(input_dev);
629 err("Out of memory during hid input probe"); 631 err("Out of memory during hid input probe");
630 return -1; 632 return -1;
631 } 633 }
632 memset(hidinput, 0, sizeof(*hidinput));
633 634
634 list_add_tail(&hidinput->list, &hid->inputs); 635 input_dev->private = hid;
636 input_dev->event = hidinput_input_event;
637 input_dev->open = hidinput_open;
638 input_dev->close = hidinput_close;
635 639
636 hidinput->input.private = hid; 640 input_dev->name = hid->name;
637 hidinput->input.event = hidinput_input_event; 641 input_dev->phys = hid->phys;
638 hidinput->input.open = hidinput_open; 642 input_dev->uniq = hid->uniq;
639 hidinput->input.close = hidinput_close; 643 usb_to_input_id(dev, &input_dev->id);
644 input_dev->cdev.dev = &hid->intf->dev;
640 645
641 hidinput->input.name = hid->name; 646 hidinput->input = input_dev;
642 hidinput->input.phys = hid->phys; 647 list_add_tail(&hidinput->list, &hid->inputs);
643 hidinput->input.uniq = hid->uniq;
644 usb_to_input_id(dev, &hidinput->input.id);
645 hidinput->input.dev = &hid->intf->dev;
646 } 648 }
647 649
648 for (i = 0; i < report->maxfield; i++) 650 for (i = 0; i < report->maxfield; i++)
@@ -657,7 +659,7 @@ int hidinput_connect(struct hid_device *hid)
657 * UGCI) cram a lot of unrelated inputs into the 659 * UGCI) cram a lot of unrelated inputs into the
658 * same interface. */ 660 * same interface. */
659 hidinput->report = report; 661 hidinput->report = report;
660 input_register_device(&hidinput->input); 662 input_register_device(hidinput->input);
661 hidinput = NULL; 663 hidinput = NULL;
662 } 664 }
663 } 665 }
@@ -667,7 +669,7 @@ int hidinput_connect(struct hid_device *hid)
667 * only useful in this case, and not for multi-input quirks. */ 669 * only useful in this case, and not for multi-input quirks. */
668 if (hidinput) { 670 if (hidinput) {
669 hid_ff_init(hid); 671 hid_ff_init(hid);
670 input_register_device(&hidinput->input); 672 input_register_device(hidinput->input);
671 } 673 }
672 674
673 return 0; 675 return 0;
@@ -675,13 +677,11 @@ int hidinput_connect(struct hid_device *hid)
675 677
676void hidinput_disconnect(struct hid_device *hid) 678void hidinput_disconnect(struct hid_device *hid)
677{ 679{
678 struct list_head *lh, *next; 680 struct hid_input *hidinput, *next;
679 struct hid_input *hidinput;
680 681
681 list_for_each_safe(lh, next, &hid->inputs) { 682 list_for_each_entry_safe(hidinput, next, &hid->inputs, list) {
682 hidinput = list_entry(lh, struct hid_input, list);
683 input_unregister_device(&hidinput->input);
684 list_del(&hidinput->list); 683 list_del(&hidinput->list);
684 input_unregister_device(hidinput->input);
685 kfree(hidinput); 685 kfree(hidinput);
686 } 686 }
687} 687}
diff --git a/drivers/usb/input/hid-lgff.c b/drivers/usb/input/hid-lgff.c
index 0c4c77aa31ea..f82c9c9e5d51 100644
--- a/drivers/usb/input/hid-lgff.c
+++ b/drivers/usb/input/hid-lgff.c
@@ -255,22 +255,19 @@ static void hid_lgff_input_init(struct hid_device* hid)
255 u16 idVendor = le16_to_cpu(hid->dev->descriptor.idVendor); 255 u16 idVendor = le16_to_cpu(hid->dev->descriptor.idVendor);
256 u16 idProduct = le16_to_cpu(hid->dev->descriptor.idProduct); 256 u16 idProduct = le16_to_cpu(hid->dev->descriptor.idProduct);
257 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); 257 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
258 struct input_dev *input_dev = hidinput->input;
258 259
259 while (dev->idVendor && (idVendor != dev->idVendor || idProduct != dev->idProduct)) 260 while (dev->idVendor && (idVendor != dev->idVendor || idProduct != dev->idProduct))
260 dev++; 261 dev++;
261 262
262 ff = dev->ff; 263 for (ff = dev->ff; *ff >= 0; ff++)
264 set_bit(*ff, input_dev->ffbit);
263 265
264 while (*ff >= 0) { 266 input_dev->upload_effect = hid_lgff_upload_effect;
265 set_bit(*ff, hidinput->input.ffbit); 267 input_dev->flush = hid_lgff_flush;
266 ++ff;
267 }
268
269 hidinput->input.upload_effect = hid_lgff_upload_effect;
270 hidinput->input.flush = hid_lgff_flush;
271 268
272 set_bit(EV_FF, hidinput->input.evbit); 269 set_bit(EV_FF, input_dev->evbit);
273 hidinput->input.ff_effects_max = LGFF_EFFECTS; 270 input_dev->ff_effects_max = LGFF_EFFECTS;
274} 271}
275 272
276static void hid_lgff_exit(struct hid_device* hid) 273static void hid_lgff_exit(struct hid_device* hid)
diff --git a/drivers/usb/input/hid-tmff.c b/drivers/usb/input/hid-tmff.c
index 8f6a0a6f94a9..023fd5ac31c8 100644
--- a/drivers/usb/input/hid-tmff.c
+++ b/drivers/usb/input/hid-tmff.c
@@ -111,6 +111,7 @@ int hid_tmff_init(struct hid_device *hid)
111 struct tmff_device *private; 111 struct tmff_device *private;
112 struct list_head *pos; 112 struct list_head *pos;
113 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); 113 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
114 struct input_dev *input_dev = hidinput->input;
114 115
115 private = kmalloc(sizeof(struct tmff_device), GFP_KERNEL); 116 private = kmalloc(sizeof(struct tmff_device), GFP_KERNEL);
116 if (!private) 117 if (!private)
@@ -155,7 +156,7 @@ int hid_tmff_init(struct hid_device *hid)
155 private->report = report; 156 private->report = report;
156 private->rumble = field; 157 private->rumble = field;
157 158
158 set_bit(FF_RUMBLE, hidinput->input.ffbit); 159 set_bit(FF_RUMBLE, input_dev->ffbit);
159 break; 160 break;
160 161
161 default: 162 default:
@@ -164,11 +165,11 @@ int hid_tmff_init(struct hid_device *hid)
164 } 165 }
165 166
166 /* Fallthrough to here only when a valid usage is found */ 167 /* Fallthrough to here only when a valid usage is found */
167 hidinput->input.upload_effect = hid_tmff_upload_effect; 168 input_dev->upload_effect = hid_tmff_upload_effect;
168 hidinput->input.flush = hid_tmff_flush; 169 input_dev->flush = hid_tmff_flush;
169 170
170 set_bit(EV_FF, hidinput->input.evbit); 171 set_bit(EV_FF, input_dev->evbit);
171 hidinput->input.ff_effects_max = TMFF_EFFECTS; 172 input_dev->ff_effects_max = TMFF_EFFECTS;
172 } 173 }
173 } 174 }
174 175
diff --git a/drivers/usb/input/hid.h b/drivers/usb/input/hid.h
index ec2412c42f1e..ee48a2276104 100644
--- a/drivers/usb/input/hid.h
+++ b/drivers/usb/input/hid.h
@@ -371,7 +371,7 @@ struct hid_control_fifo {
371struct hid_input { 371struct hid_input {
372 struct list_head list; 372 struct list_head list;
373 struct hid_report *report; 373 struct hid_report *report;
374 struct input_dev input; 374 struct input_dev *input;
375}; 375};
376 376
377struct hid_device { /* device report descriptor */ 377struct hid_device { /* device report descriptor */
diff --git a/drivers/usb/input/hiddev.c b/drivers/usb/input/hiddev.c
index d32427818af7..440377c7a0da 100644
--- a/drivers/usb/input/hiddev.c
+++ b/drivers/usb/input/hiddev.c
@@ -732,9 +732,8 @@ static struct file_operations hiddev_fops = {
732}; 732};
733 733
734static struct usb_class_driver hiddev_class = { 734static struct usb_class_driver hiddev_class = {
735 .name = "usb/hid/hiddev%d", 735 .name = "hiddev%d",
736 .fops = &hiddev_fops, 736 .fops = &hiddev_fops,
737 .mode = S_IFCHR | S_IRUGO | S_IWUSR,
738 .minor_base = HIDDEV_MINOR_BASE, 737 .minor_base = HIDDEV_MINOR_BASE,
739}; 738};
740 739
diff --git a/drivers/usb/input/itmtouch.c b/drivers/usb/input/itmtouch.c
index becb87efb869..3b581853cf10 100644
--- a/drivers/usb/input/itmtouch.c
+++ b/drivers/usb/input/itmtouch.c
@@ -73,7 +73,7 @@ MODULE_LICENSE( DRIVER_LICENSE );
73 73
74struct itmtouch_dev { 74struct itmtouch_dev {
75 struct usb_device *usbdev; /* usb device */ 75 struct usb_device *usbdev; /* usb device */
76 struct input_dev inputdev; /* input device */ 76 struct input_dev *inputdev; /* input device */
77 struct urb *readurb; /* urb */ 77 struct urb *readurb; /* urb */
78 char rbuf[ITM_BUFSIZE]; /* data */ 78 char rbuf[ITM_BUFSIZE]; /* data */
79 int users; 79 int users;
@@ -88,9 +88,9 @@ static struct usb_device_id itmtouch_ids [] = {
88 88
89static void itmtouch_irq(struct urb *urb, struct pt_regs *regs) 89static void itmtouch_irq(struct urb *urb, struct pt_regs *regs)
90{ 90{
91 struct itmtouch_dev * itmtouch = urb->context; 91 struct itmtouch_dev *itmtouch = urb->context;
92 unsigned char *data = urb->transfer_buffer; 92 unsigned char *data = urb->transfer_buffer;
93 struct input_dev *dev = &itmtouch->inputdev; 93 struct input_dev *dev = itmtouch->inputdev;
94 int retval; 94 int retval;
95 95
96 switch (urb->status) { 96 switch (urb->status) {
@@ -156,49 +156,62 @@ static void itmtouch_close(struct input_dev *input)
156static int itmtouch_probe(struct usb_interface *intf, const struct usb_device_id *id) 156static int itmtouch_probe(struct usb_interface *intf, const struct usb_device_id *id)
157{ 157{
158 struct itmtouch_dev *itmtouch; 158 struct itmtouch_dev *itmtouch;
159 struct input_dev *input_dev;
159 struct usb_host_interface *interface; 160 struct usb_host_interface *interface;
160 struct usb_endpoint_descriptor *endpoint; 161 struct usb_endpoint_descriptor *endpoint;
161 struct usb_device *udev = interface_to_usbdev(intf); 162 struct usb_device *udev = interface_to_usbdev(intf);
162 unsigned int pipe; 163 unsigned int pipe;
163 unsigned int maxp; 164 unsigned int maxp;
164 char path[PATH_SIZE];
165 165
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 = kzalloc(sizeof(struct itmtouch_dev), GFP_KERNEL))) { 169 itmtouch = kzalloc(sizeof(struct itmtouch_dev), GFP_KERNEL);
170 input_dev = input_allocate_device();
171 if (!itmtouch || !input_dev) {
170 err("%s - Out of memory.", __FUNCTION__); 172 err("%s - Out of memory.", __FUNCTION__);
171 return -ENOMEM; 173 goto fail;
172 } 174 }
173 175
174 itmtouch->usbdev = udev; 176 itmtouch->usbdev = udev;
177 itmtouch->inputdev = input_dev;
175 178
176 itmtouch->inputdev.private = itmtouch; 179 if (udev->manufacturer)
177 itmtouch->inputdev.open = itmtouch_open; 180 strlcpy(itmtouch->name, udev->manufacturer, sizeof(itmtouch->name));
178 itmtouch->inputdev.close = itmtouch_close;
179 181
180 usb_make_path(udev, path, PATH_SIZE); 182 if (udev->product) {
181 183 if (udev->manufacturer)
182 itmtouch->inputdev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 184 strlcat(itmtouch->name, " ", sizeof(itmtouch->name));
183 itmtouch->inputdev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE); 185 strlcat(itmtouch->name, udev->product, sizeof(itmtouch->name));
184 itmtouch->inputdev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); 186 }
185
186 itmtouch->inputdev.name = itmtouch->name;
187 itmtouch->inputdev.phys = itmtouch->phys;
188 usb_to_input_id(udev, &itmtouch->inputdev.id);
189 itmtouch->inputdev.dev = &intf->dev;
190 187
191 if (!strlen(itmtouch->name)) 188 if (!strlen(itmtouch->name))
192 sprintf(itmtouch->name, "USB ITM touchscreen"); 189 sprintf(itmtouch->name, "USB ITM touchscreen");
193 190
191 usb_make_path(udev, itmtouch->phys, sizeof(itmtouch->phys));
192 strlcpy(itmtouch->phys, "/input0", sizeof(itmtouch->phys));
193
194 input_dev->name = itmtouch->name;
195 input_dev->phys = itmtouch->phys;
196 usb_to_input_id(udev, &input_dev->id);
197 input_dev->cdev.dev = &intf->dev;
198 input_dev->private = itmtouch;
199
200 input_dev->open = itmtouch_open;
201 input_dev->close = itmtouch_close;
202
203 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
204 input_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
205 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
206
194 /* device limits */ 207 /* device limits */
195 /* as specified by the ITM datasheet, X and Y are 12bit, 208 /* as specified by the ITM datasheet, X and Y are 12bit,
196 * Z (pressure) is 8 bit. However, the fields are defined up 209 * Z (pressure) is 8 bit. However, the fields are defined up
197 * to 14 bits for future possible expansion. 210 * to 14 bits for future possible expansion.
198 */ 211 */
199 input_set_abs_params(&itmtouch->inputdev, ABS_X, 0, 0x0FFF, 2, 0); 212 input_set_abs_params(input_dev, ABS_X, 0, 0x0FFF, 2, 0);
200 input_set_abs_params(&itmtouch->inputdev, ABS_Y, 0, 0x0FFF, 2, 0); 213 input_set_abs_params(input_dev, ABS_Y, 0, 0x0FFF, 2, 0);
201 input_set_abs_params(&itmtouch->inputdev, ABS_PRESSURE, 0, 0xFF, 2, 0); 214 input_set_abs_params(input_dev, ABS_PRESSURE, 0, 0xFF, 2, 0);
202 215
203 /* initialise the URB so we can read from the transport stream */ 216 /* initialise the URB so we can read from the transport stream */
204 pipe = usb_rcvintpipe(itmtouch->usbdev, endpoint->bEndpointAddress); 217 pipe = usb_rcvintpipe(itmtouch->usbdev, endpoint->bEndpointAddress);
@@ -208,22 +221,23 @@ static int itmtouch_probe(struct usb_interface *intf, const struct usb_device_id
208 maxp = ITM_BUFSIZE; 221 maxp = ITM_BUFSIZE;
209 222
210 itmtouch->readurb = usb_alloc_urb(0, GFP_KERNEL); 223 itmtouch->readurb = usb_alloc_urb(0, GFP_KERNEL);
211
212 if (!itmtouch->readurb) { 224 if (!itmtouch->readurb) {
213 dbg("%s - usb_alloc_urb failed: itmtouch->readurb", __FUNCTION__); 225 dbg("%s - usb_alloc_urb failed: itmtouch->readurb", __FUNCTION__);
214 kfree(itmtouch); 226 goto fail;
215 return -ENOMEM;
216 } 227 }
217 228
218 usb_fill_int_urb(itmtouch->readurb, itmtouch->usbdev, pipe, itmtouch->rbuf, 229 usb_fill_int_urb(itmtouch->readurb, itmtouch->usbdev, pipe, itmtouch->rbuf,
219 maxp, itmtouch_irq, itmtouch, endpoint->bInterval); 230 maxp, itmtouch_irq, itmtouch, endpoint->bInterval);
220 231
221 input_register_device(&itmtouch->inputdev); 232 input_register_device(itmtouch->inputdev);
222 233
223 printk(KERN_INFO "itmtouch: %s registered on %s\n", itmtouch->name, path);
224 usb_set_intfdata(intf, itmtouch); 234 usb_set_intfdata(intf, itmtouch);
225 235
226 return 0; 236 return 0;
237
238 fail: input_free_device(input_dev);
239 kfree(itmtouch);
240 return -ENOMEM;
227} 241}
228 242
229static void itmtouch_disconnect(struct usb_interface *intf) 243static void itmtouch_disconnect(struct usb_interface *intf)
@@ -233,7 +247,7 @@ static void itmtouch_disconnect(struct usb_interface *intf)
233 usb_set_intfdata(intf, NULL); 247 usb_set_intfdata(intf, NULL);
234 248
235 if (itmtouch) { 249 if (itmtouch) {
236 input_unregister_device(&itmtouch->inputdev); 250 input_unregister_device(itmtouch->inputdev);
237 usb_kill_urb(itmtouch->readurb); 251 usb_kill_urb(itmtouch->readurb);
238 usb_free_urb(itmtouch->readurb); 252 usb_free_urb(itmtouch->readurb);
239 kfree(itmtouch); 253 kfree(itmtouch);
diff --git a/drivers/usb/input/kbtab.c b/drivers/usb/input/kbtab.c
index b6f6ac8d9c2f..a248664b5d1d 100644
--- a/drivers/usb/input/kbtab.c
+++ b/drivers/usb/input/kbtab.c
@@ -34,7 +34,7 @@ MODULE_PARM_DESC(kb_pressure_click, "pressure threshold for clicks");
34struct kbtab { 34struct kbtab {
35 signed char *data; 35 signed char *data;
36 dma_addr_t data_dma; 36 dma_addr_t data_dma;
37 struct input_dev dev; 37 struct input_dev *dev;
38 struct usb_device *usbdev; 38 struct usb_device *usbdev;
39 struct urb *irq; 39 struct urb *irq;
40 int x, y; 40 int x, y;
@@ -48,7 +48,7 @@ static void kbtab_irq(struct urb *urb, struct pt_regs *regs)
48{ 48{
49 struct kbtab *kbtab = urb->context; 49 struct kbtab *kbtab = urb->context;
50 unsigned char *data = kbtab->data; 50 unsigned char *data = kbtab->data;
51 struct input_dev *dev = &kbtab->dev; 51 struct input_dev *dev = kbtab->dev;
52 int retval; 52 int retval;
53 53
54 switch (urb->status) { 54 switch (urb->status) {
@@ -124,53 +124,43 @@ static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *i
124 struct usb_device *dev = interface_to_usbdev(intf); 124 struct usb_device *dev = interface_to_usbdev(intf);
125 struct usb_endpoint_descriptor *endpoint; 125 struct usb_endpoint_descriptor *endpoint;
126 struct kbtab *kbtab; 126 struct kbtab *kbtab;
127 char path[64]; 127 struct input_dev *input_dev;
128 128
129 if (!(kbtab = kmalloc(sizeof(struct kbtab), GFP_KERNEL))) 129 kbtab = kzalloc(sizeof(struct kbtab), GFP_KERNEL);
130 return -ENOMEM; 130 input_dev = input_allocate_device();
131 memset(kbtab, 0, sizeof(struct kbtab)); 131 if (!kbtab || !input_dev)
132 goto fail1;
132 133
133 kbtab->data = usb_buffer_alloc(dev, 8, GFP_KERNEL, &kbtab->data_dma); 134 kbtab->data = usb_buffer_alloc(dev, 8, GFP_KERNEL, &kbtab->data_dma);
134 if (!kbtab->data) { 135 if (!kbtab->data)
135 kfree(kbtab); 136 goto fail1;
136 return -ENOMEM;
137 }
138 137
139 kbtab->irq = usb_alloc_urb(0, GFP_KERNEL); 138 kbtab->irq = usb_alloc_urb(0, GFP_KERNEL);
140 if (!kbtab->irq) { 139 if (!kbtab->irq)
141 usb_buffer_free(dev, 10, kbtab->data, kbtab->data_dma); 140 goto fail2;
142 kfree(kbtab);
143 return -ENOMEM;
144 }
145
146 kbtab->dev.evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_MSC);
147 kbtab->dev.absbit[0] |= BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
148
149 kbtab->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
150
151 kbtab->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | BIT(BTN_TOUCH);
152 141
153 kbtab->dev.mscbit[0] |= BIT(MSC_SERIAL); 142 kbtab->usbdev = dev;
154 143 kbtab->dev = input_dev;
155 kbtab->dev.absmax[ABS_X] = 0x2000;
156 kbtab->dev.absmax[ABS_Y] = 0x1750;
157 kbtab->dev.absmax[ABS_PRESSURE] = 0xff;
158 144
159 kbtab->dev.absfuzz[ABS_X] = 4; 145 usb_make_path(dev, kbtab->phys, sizeof(kbtab->phys));
160 kbtab->dev.absfuzz[ABS_Y] = 4; 146 strlcat(kbtab->phys, "/input0", sizeof(kbtab->phys));
161 147
162 kbtab->dev.private = kbtab; 148 input_dev->name = "KB Gear Tablet";
163 kbtab->dev.open = kbtab_open; 149 input_dev->phys = kbtab->phys;
164 kbtab->dev.close = kbtab_close; 150 usb_to_input_id(dev, &input_dev->id);
151 input_dev->cdev.dev = &intf->dev;
152 input_dev->private = kbtab;
165 153
166 usb_make_path(dev, path, 64); 154 input_dev->open = kbtab_open;
167 sprintf(kbtab->phys, "%s/input0", path); 155 input_dev->close = kbtab_close;
168 156
169 kbtab->dev.name = "KB Gear Tablet"; 157 input_dev->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_MSC);
170 kbtab->dev.phys = kbtab->phys; 158 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
171 usb_to_input_id(dev, &kbtab->dev.id); 159 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | BIT(BTN_TOUCH);
172 kbtab->dev.dev = &intf->dev; 160 input_dev->mscbit[0] |= BIT(MSC_SERIAL);
173 kbtab->usbdev = dev; 161 input_set_abs_params(input_dev, ABS_X, 0, 0x2000, 4, 0);
162 input_set_abs_params(input_dev, ABS_X, 0, 0x1750, 4, 0);
163 input_set_abs_params(input_dev, ABS_PRESSURE, 0, 0xff, 0, 0);
174 164
175 endpoint = &intf->cur_altsetting->endpoint[0].desc; 165 endpoint = &intf->cur_altsetting->endpoint[0].desc;
176 166
@@ -181,23 +171,25 @@ static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *i
181 kbtab->irq->transfer_dma = kbtab->data_dma; 171 kbtab->irq->transfer_dma = kbtab->data_dma;
182 kbtab->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 172 kbtab->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
183 173
184 input_register_device(&kbtab->dev); 174 input_register_device(kbtab->dev);
185
186 printk(KERN_INFO "input: KB Gear Tablet on %s\n", path);
187 175
188 usb_set_intfdata(intf, kbtab); 176 usb_set_intfdata(intf, kbtab);
189
190 return 0; 177 return 0;
178
179fail2: usb_buffer_free(dev, 10, kbtab->data, kbtab->data_dma);
180fail1: input_free_device(input_dev);
181 kfree(kbtab);
182 return -ENOMEM;
191} 183}
192 184
193static void kbtab_disconnect(struct usb_interface *intf) 185static void kbtab_disconnect(struct usb_interface *intf)
194{ 186{
195 struct kbtab *kbtab = usb_get_intfdata (intf); 187 struct kbtab *kbtab = usb_get_intfdata(intf);
196 188
197 usb_set_intfdata(intf, NULL); 189 usb_set_intfdata(intf, NULL);
198 if (kbtab) { 190 if (kbtab) {
199 usb_kill_urb(kbtab->irq); 191 usb_kill_urb(kbtab->irq);
200 input_unregister_device(&kbtab->dev); 192 input_unregister_device(kbtab->dev);
201 usb_free_urb(kbtab->irq); 193 usb_free_urb(kbtab->irq);
202 usb_buffer_free(interface_to_usbdev(intf), 10, kbtab->data, kbtab->data_dma); 194 usb_buffer_free(interface_to_usbdev(intf), 10, kbtab->data, kbtab->data_dma);
203 kfree(kbtab); 195 kfree(kbtab);
diff --git a/drivers/usb/input/keyspan_remote.c b/drivers/usb/input/keyspan_remote.c
index 99de1b33c07d..5b8d65f62abf 100644
--- a/drivers/usb/input/keyspan_remote.c
+++ b/drivers/usb/input/keyspan_remote.c
@@ -20,6 +20,7 @@
20#include <linux/moduleparam.h> 20#include <linux/moduleparam.h>
21#include <linux/input.h> 21#include <linux/input.h>
22#include <linux/usb.h> 22#include <linux/usb.h>
23#include <linux/usb_input.h>
23 24
24#define DRIVER_VERSION "v0.1" 25#define DRIVER_VERSION "v0.1"
25#define DRIVER_AUTHOR "Michael Downey <downey@zymeta.com>" 26#define DRIVER_AUTHOR "Michael Downey <downey@zymeta.com>"
@@ -75,7 +76,7 @@ struct usb_keyspan {
75 char name[128]; 76 char name[128];
76 char phys[64]; 77 char phys[64];
77 struct usb_device* udev; 78 struct usb_device* udev;
78 struct input_dev input; 79 struct input_dev *input;
79 struct usb_interface* interface; 80 struct usb_interface* interface;
80 struct usb_endpoint_descriptor* in_endpoint; 81 struct usb_endpoint_descriptor* in_endpoint;
81 struct urb* irq_urb; 82 struct urb* irq_urb;
@@ -136,12 +137,11 @@ static struct usb_driver keyspan_driver;
136 */ 137 */
137static void keyspan_print(struct usb_keyspan* dev) /*unsigned char* data)*/ 138static void keyspan_print(struct usb_keyspan* dev) /*unsigned char* data)*/
138{ 139{
139 char codes[4*RECV_SIZE]; 140 char codes[4 * RECV_SIZE];
140 int i; 141 int i;
141 142
142 for (i = 0; i < RECV_SIZE; i++) { 143 for (i = 0; i < RECV_SIZE; i++)
143 snprintf(codes+i*3, 4, "%02x ", dev->in_buffer[i]); 144 snprintf(codes + i * 3, 4, "%02x ", dev->in_buffer[i]);
144 }
145 145
146 dev_info(&dev->udev->dev, "%s\n", codes); 146 dev_info(&dev->udev->dev, "%s\n", codes);
147} 147}
@@ -153,7 +153,7 @@ static void keyspan_print(struct usb_keyspan* dev) /*unsigned char* data)*/
153static int keyspan_load_tester(struct usb_keyspan* dev, int bits_needed) 153static int keyspan_load_tester(struct usb_keyspan* dev, int bits_needed)
154{ 154{
155 if (dev->data.bits_left >= bits_needed) 155 if (dev->data.bits_left >= bits_needed)
156 return(0); 156 return 0;
157 157
158 /* 158 /*
159 * Somehow we've missed the last message. The message will be repeated 159 * Somehow we've missed the last message. The message will be repeated
@@ -162,7 +162,7 @@ static int keyspan_load_tester(struct usb_keyspan* dev, int bits_needed)
162 if (dev->data.pos >= dev->data.len) { 162 if (dev->data.pos >= dev->data.len) {
163 dev_dbg(&dev->udev, "%s - Error ran out of data. pos: %d, len: %d\n", 163 dev_dbg(&dev->udev, "%s - Error ran out of data. pos: %d, len: %d\n",
164 __FUNCTION__, dev->data.pos, dev->data.len); 164 __FUNCTION__, dev->data.pos, dev->data.len);
165 return(-1); 165 return -1;
166 } 166 }
167 167
168 /* Load as much as we can into the tester. */ 168 /* Load as much as we can into the tester. */
@@ -172,7 +172,7 @@ static int keyspan_load_tester(struct usb_keyspan* dev, int bits_needed)
172 dev->data.bits_left += 8; 172 dev->data.bits_left += 8;
173 } 173 }
174 174
175 return(0); 175 return 0;
176} 176}
177 177
178/* 178/*
@@ -311,10 +311,10 @@ static void keyspan_check_data(struct usb_keyspan *remote, struct pt_regs *regs)
311 __FUNCTION__, message.system, message.button, message.toggle); 311 __FUNCTION__, message.system, message.button, message.toggle);
312 312
313 if (message.toggle != remote->toggle) { 313 if (message.toggle != remote->toggle) {
314 input_regs(&remote->input, regs); 314 input_regs(remote->input, regs);
315 input_report_key(&remote->input, keyspan_key_table[message.button], 1); 315 input_report_key(remote->input, keyspan_key_table[message.button], 1);
316 input_report_key(&remote->input, keyspan_key_table[message.button], 0); 316 input_report_key(remote->input, keyspan_key_table[message.button], 0);
317 input_sync(&remote->input); 317 input_sync(remote->input);
318 remote->toggle = message.toggle; 318 remote->toggle = message.toggle;
319 } 319 }
320 320
@@ -397,14 +397,9 @@ static int keyspan_open(struct input_dev *dev)
397{ 397{
398 struct usb_keyspan *remote = dev->private; 398 struct usb_keyspan *remote = dev->private;
399 399
400 if (remote->open++)
401 return 0;
402
403 remote->irq_urb->dev = remote->udev; 400 remote->irq_urb->dev = remote->udev;
404 if (usb_submit_urb(remote->irq_urb, GFP_KERNEL)) { 401 if (usb_submit_urb(remote->irq_urb, GFP_KERNEL))
405 remote->open--;
406 return -EIO; 402 return -EIO;
407 }
408 403
409 return 0; 404 return 0;
410} 405}
@@ -413,8 +408,26 @@ static void keyspan_close(struct input_dev *dev)
413{ 408{
414 struct usb_keyspan *remote = dev->private; 409 struct usb_keyspan *remote = dev->private;
415 410
416 if (!--remote->open) 411 usb_kill_urb(remote->irq_urb);
417 usb_kill_urb(remote->irq_urb); 412}
413
414static struct usb_endpoint_descriptor *keyspan_get_in_endpoint(struct usb_host_interface *iface)
415{
416
417 struct usb_endpoint_descriptor *endpoint;
418 int i;
419
420 for (i = 0; i < iface->desc.bNumEndpoints; ++i) {
421 endpoint = &iface->endpoint[i].desc;
422
423 if ((endpoint->bEndpointAddress & USB_DIR_IN) &&
424 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) {
425 /* we found our interrupt in endpoint */
426 return endpoint;
427 }
428 }
429
430 return NULL;
418} 431}
419 432
420/* 433/*
@@ -422,110 +435,78 @@ static void keyspan_close(struct input_dev *dev)
422 */ 435 */
423static int keyspan_probe(struct usb_interface *interface, const struct usb_device_id *id) 436static int keyspan_probe(struct usb_interface *interface, const struct usb_device_id *id)
424{ 437{
425 int i; 438 struct usb_device *udev = interface_to_usbdev(interface);
426 int retval = -ENOMEM;
427 char path[64];
428 char *buf;
429 struct usb_keyspan *remote = NULL;
430 struct usb_host_interface *iface_desc;
431 struct usb_endpoint_descriptor *endpoint; 439 struct usb_endpoint_descriptor *endpoint;
432 struct usb_device *udev = usb_get_dev(interface_to_usbdev(interface)); 440 struct usb_keyspan *remote;
441 struct input_dev *input_dev;
442 int i, retval;
433 443
434 /* allocate memory for our device state and initialize it */ 444 endpoint = keyspan_get_in_endpoint(interface->cur_altsetting);
435 remote = kmalloc(sizeof(*remote), GFP_KERNEL); 445 if (!endpoint)
436 if (remote == NULL) { 446 return -ENODEV;
437 err("Out of memory\n"); 447
438 goto error; 448 remote = kzalloc(sizeof(*remote), GFP_KERNEL);
449 input_dev = input_allocate_device();
450 if (!remote || !input_dev) {
451 retval = -ENOMEM;
452 goto fail1;
439 } 453 }
440 memset(remote, 0x00, sizeof(*remote));
441 454
442 remote->udev = udev; 455 remote->udev = udev;
456 remote->input = input_dev;
443 remote->interface = interface; 457 remote->interface = interface;
458 remote->in_endpoint = endpoint;
444 remote->toggle = -1; /* Set to -1 so we will always not match the toggle from the first remote message. */ 459 remote->toggle = -1; /* Set to -1 so we will always not match the toggle from the first remote message. */
445 460
446 /* set up the endpoint information */ 461 remote->in_buffer = usb_buffer_alloc(udev, RECV_SIZE, SLAB_ATOMIC, &remote->in_dma);
447 /* use only the first in interrupt endpoint */ 462 if (!remote->in_buffer) {
448 iface_desc = interface->cur_altsetting; 463 retval = -ENOMEM;
449 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { 464 goto fail1;
450 endpoint = &iface_desc->endpoint[i].desc;
451
452 if (!remote->in_endpoint &&
453 (endpoint->bEndpointAddress & USB_DIR_IN) &&
454 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) {
455 /* we found our interrupt in endpoint */
456 remote->in_endpoint = endpoint;
457
458 remote->in_buffer = usb_buffer_alloc(remote->udev, RECV_SIZE, SLAB_ATOMIC, &remote->in_dma);
459 if (!remote->in_buffer) {
460 retval = -ENOMEM;
461 goto error;
462 }
463 }
464 }
465
466 if (!remote->in_endpoint) {
467 err("Could not find interrupt input endpoint.\n");
468 retval = -ENODEV;
469 goto error;
470 } 465 }
471 466
472 remote->irq_urb = usb_alloc_urb(0, GFP_KERNEL); 467 remote->irq_urb = usb_alloc_urb(0, GFP_KERNEL);
473 if (!remote->irq_urb) { 468 if (!remote->irq_urb) {
474 err("Failed to allocate urb.\n");
475 retval = -ENOMEM; 469 retval = -ENOMEM;
476 goto error; 470 goto fail2;
477 } 471 }
478 472
479 retval = keyspan_setup(remote->udev); 473 retval = keyspan_setup(udev);
480 if (retval) { 474 if (retval) {
481 err("Failed to setup device.\n");
482 retval = -ENODEV; 475 retval = -ENODEV;
483 goto error; 476 goto fail3;
484 }
485
486 /*
487 * Setup the input system with the bits we are going to be reporting
488 */
489 remote->input.evbit[0] = BIT(EV_KEY); /* We will only report KEY events. */
490 for (i = 0; i < 32; ++i) {
491 if (keyspan_key_table[i] != KEY_RESERVED) {
492 set_bit(keyspan_key_table[i], remote->input.keybit);
493 }
494 } 477 }
495 478
496 remote->input.private = remote; 479 if (udev->manufacturer)
497 remote->input.open = keyspan_open; 480 strlcpy(remote->name, udev->manufacturer, sizeof(remote->name));
498 remote->input.close = keyspan_close;
499
500 usb_make_path(remote->udev, path, 64);
501 sprintf(remote->phys, "%s/input0", path);
502 481
503 remote->input.name = remote->name; 482 if (udev->product) {
504 remote->input.phys = remote->phys; 483 if (udev->manufacturer)
505 remote->input.id.bustype = BUS_USB; 484 strlcat(remote->name, " ", sizeof(remote->name));
506 remote->input.id.vendor = le16_to_cpu(remote->udev->descriptor.idVendor); 485 strlcat(remote->name, udev->product, sizeof(remote->name));
507 remote->input.id.product = le16_to_cpu(remote->udev->descriptor.idProduct);
508 remote->input.id.version = le16_to_cpu(remote->udev->descriptor.bcdDevice);
509
510 if (!(buf = kmalloc(63, GFP_KERNEL))) {
511 usb_buffer_free(remote->udev, RECV_SIZE, remote->in_buffer, remote->in_dma);
512 kfree(remote);
513 return -ENOMEM;
514 } 486 }
515 487
516 if (remote->udev->descriptor.iManufacturer && 488 if (!strlen(remote->name))
517 usb_string(remote->udev, remote->udev->descriptor.iManufacturer, buf, 63) > 0) 489 snprintf(remote->name, sizeof(remote->name),
518 strcat(remote->name, buf); 490 "USB Keyspan Remote %04x:%04x",
491 le16_to_cpu(udev->descriptor.idVendor),
492 le16_to_cpu(udev->descriptor.idProduct));
519 493
520 if (remote->udev->descriptor.iProduct && 494 usb_make_path(udev, remote->phys, sizeof(remote->phys));
521 usb_string(remote->udev, remote->udev->descriptor.iProduct, buf, 63) > 0) 495 strlcat(remote->phys, "/input0", sizeof(remote->phys));
522 sprintf(remote->name, "%s %s", remote->name, buf);
523 496
524 if (!strlen(remote->name)) 497 input_dev->name = remote->name;
525 sprintf(remote->name, "USB Keyspan Remote %04x:%04x", 498 input_dev->phys = remote->phys;
526 remote->input.id.vendor, remote->input.id.product); 499 usb_to_input_id(udev, &input_dev->id);
500 input_dev->cdev.dev = &interface->dev;
527 501
528 kfree(buf); 502 input_dev->evbit[0] = BIT(EV_KEY); /* We will only report KEY events. */
503 for (i = 0; i < ARRAY_SIZE(keyspan_key_table); i++)
504 if (keyspan_key_table[i] != KEY_RESERVED)
505 set_bit(keyspan_key_table[i], input_dev->keybit);
506
507 input_dev->private = remote;
508 input_dev->open = keyspan_open;
509 input_dev->close = keyspan_close;
529 510
530 /* 511 /*
531 * Initialize the URB to access the device. The urb gets sent to the device in keyspan_open() 512 * Initialize the URB to access the device. The urb gets sent to the device in keyspan_open()
@@ -538,27 +519,17 @@ static int keyspan_probe(struct usb_interface *interface, const struct usb_devic
538 remote->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 519 remote->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
539 520
540 /* we can register the device now, as it is ready */ 521 /* we can register the device now, as it is ready */
541 input_register_device(&remote->input); 522 input_register_device(remote->input);
542 523
543 /* save our data pointer in this interface device */ 524 /* save our data pointer in this interface device */
544 usb_set_intfdata(interface, remote); 525 usb_set_intfdata(interface, remote);
545 526
546 /* let the user know what node this device is now attached to */
547 info("connected: %s on %s", remote->name, path);
548 return 0; 527 return 0;
549 528
550error: 529 fail3: usb_free_urb(remote->irq_urb);
551 /* 530 fail2: usb_buffer_free(udev, RECV_SIZE, remote->in_buffer, remote->in_dma);
552 * In case of error we need to clean up any allocated buffers 531 fail1: kfree(remote);
553 */ 532 input_free_device(input_dev);
554 if (remote->irq_urb)
555 usb_free_urb(remote->irq_urb);
556
557 if (remote->in_buffer)
558 usb_buffer_free(remote->udev, RECV_SIZE, remote->in_buffer, remote->in_dma);
559
560 if (remote)
561 kfree(remote);
562 533
563 return retval; 534 return retval;
564} 535}
@@ -570,23 +541,16 @@ static void keyspan_disconnect(struct usb_interface *interface)
570{ 541{
571 struct usb_keyspan *remote; 542 struct usb_keyspan *remote;
572 543
573 /* prevent keyspan_open() from racing keyspan_disconnect() */
574 lock_kernel();
575
576 remote = usb_get_intfdata(interface); 544 remote = usb_get_intfdata(interface);
577 usb_set_intfdata(interface, NULL); 545 usb_set_intfdata(interface, NULL);
578 546
579 if (remote) { /* We have a valid driver structure so clean up everything we allocated. */ 547 if (remote) { /* We have a valid driver structure so clean up everything we allocated. */
580 input_unregister_device(&remote->input); 548 input_unregister_device(remote->input);
581 usb_kill_urb(remote->irq_urb); 549 usb_kill_urb(remote->irq_urb);
582 usb_free_urb(remote->irq_urb); 550 usb_free_urb(remote->irq_urb);
583 usb_buffer_free(interface_to_usbdev(interface), RECV_SIZE, remote->in_buffer, remote->in_dma); 551 usb_buffer_free(remote->udev, RECV_SIZE, remote->in_buffer, remote->in_dma);
584 kfree(remote); 552 kfree(remote);
585 } 553 }
586
587 unlock_kernel();
588
589 info("USB Keyspan now disconnected");
590} 554}
591 555
592/* 556/*
diff --git a/drivers/usb/input/map_to_7segment.h b/drivers/usb/input/map_to_7segment.h
index 52ff27f15127..a424094d9fe2 100644
--- a/drivers/usb/input/map_to_7segment.h
+++ b/drivers/usb/input/map_to_7segment.h
@@ -79,7 +79,7 @@ struct seg7_conversion_map {
79 79
80static inline int map_to_seg7(struct seg7_conversion_map *map, int c) 80static inline int map_to_seg7(struct seg7_conversion_map *map, int c)
81{ 81{
82 return c & 0x7f ? map->table[c] : -EINVAL; 82 return c >= 0 && c < sizeof(map->table) ? map->table[c] : -EINVAL;
83} 83}
84 84
85#define SEG7_CONVERSION_MAP(_name, _map) \ 85#define SEG7_CONVERSION_MAP(_name, _map) \
diff --git a/drivers/usb/input/mtouchusb.c b/drivers/usb/input/mtouchusb.c
index ff9275057a18..7fce526560ca 100644
--- a/drivers/usb/input/mtouchusb.c
+++ b/drivers/usb/input/mtouchusb.c
@@ -98,7 +98,7 @@ struct mtouch_usb {
98 dma_addr_t data_dma; 98 dma_addr_t data_dma;
99 struct urb *irq; 99 struct urb *irq;
100 struct usb_device *udev; 100 struct usb_device *udev;
101 struct input_dev input; 101 struct input_dev *input;
102 char name[128]; 102 char name[128];
103 char phys[64]; 103 char phys[64];
104}; 104};
@@ -135,14 +135,14 @@ static void mtouchusb_irq(struct urb *urb, struct pt_regs *regs)
135 goto exit; 135 goto exit;
136 } 136 }
137 137
138 input_regs(&mtouch->input, regs); 138 input_regs(mtouch->input, regs);
139 input_report_key(&mtouch->input, BTN_TOUCH, 139 input_report_key(mtouch->input, BTN_TOUCH,
140 MTOUCHUSB_GET_TOUCHED(mtouch->data)); 140 MTOUCHUSB_GET_TOUCHED(mtouch->data));
141 input_report_abs(&mtouch->input, ABS_X, MTOUCHUSB_GET_XC(mtouch->data)); 141 input_report_abs(mtouch->input, ABS_X, MTOUCHUSB_GET_XC(mtouch->data));
142 input_report_abs(&mtouch->input, ABS_Y, 142 input_report_abs(mtouch->input, ABS_Y,
143 (raw_coordinates ? MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC) 143 (raw_coordinates ? MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC)
144 - MTOUCHUSB_GET_YC(mtouch->data)); 144 - MTOUCHUSB_GET_YC(mtouch->data));
145 input_sync(&mtouch->input); 145 input_sync(mtouch->input);
146 146
147exit: 147exit:
148 retval = usb_submit_urb(urb, GFP_ATOMIC); 148 retval = usb_submit_urb(urb, GFP_ATOMIC);
@@ -195,10 +195,10 @@ static void mtouchusb_free_buffers(struct usb_device *udev, struct mtouch_usb *m
195static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_id *id) 195static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_id *id)
196{ 196{
197 struct mtouch_usb *mtouch; 197 struct mtouch_usb *mtouch;
198 struct input_dev *input_dev;
198 struct usb_host_interface *interface; 199 struct usb_host_interface *interface;
199 struct usb_endpoint_descriptor *endpoint; 200 struct usb_endpoint_descriptor *endpoint;
200 struct usb_device *udev = interface_to_usbdev(intf); 201 struct usb_device *udev = interface_to_usbdev(intf);
201 char path[64];
202 int nRet; 202 int nRet;
203 203
204 dbg("%s - called", __FUNCTION__); 204 dbg("%s - called", __FUNCTION__);
@@ -209,57 +209,55 @@ static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_i
209 dbg("%s - setting endpoint", __FUNCTION__); 209 dbg("%s - setting endpoint", __FUNCTION__);
210 endpoint = &interface->endpoint[0].desc; 210 endpoint = &interface->endpoint[0].desc;
211 211
212 if (!(mtouch = kmalloc(sizeof(struct mtouch_usb), GFP_KERNEL))) { 212 mtouch = kzalloc(sizeof(struct mtouch_usb), GFP_KERNEL);
213 input_dev = input_allocate_device();
214 if (!mtouch || !input_dev) {
213 err("%s - Out of memory.", __FUNCTION__); 215 err("%s - Out of memory.", __FUNCTION__);
214 return -ENOMEM; 216 goto fail1;
215 } 217 }
216 218
217 memset(mtouch, 0, sizeof(struct mtouch_usb));
218 mtouch->udev = udev;
219
220 dbg("%s - allocating buffers", __FUNCTION__); 219 dbg("%s - allocating buffers", __FUNCTION__);
221 if (mtouchusb_alloc_buffers(udev, mtouch)) { 220 if (mtouchusb_alloc_buffers(udev, mtouch))
222 mtouchusb_free_buffers(udev, mtouch); 221 goto fail2;
223 kfree(mtouch);
224 return -ENOMEM;
225 }
226 222
227 mtouch->input.private = mtouch; 223 mtouch->udev = udev;
228 mtouch->input.open = mtouchusb_open; 224 mtouch->input = input_dev;
229 mtouch->input.close = mtouchusb_close;
230
231 usb_make_path(udev, path, 64);
232 sprintf(mtouch->phys, "%s/input0", path);
233
234 mtouch->input.name = mtouch->name;
235 mtouch->input.phys = mtouch->phys;
236 usb_to_input_id(udev, &mtouch->input.id);
237 mtouch->input.dev = &intf->dev;
238
239 mtouch->input.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
240 mtouch->input.absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
241 mtouch->input.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
242
243 /* Used to Scale Compensated Data and Flip Y */
244 mtouch->input.absmin[ABS_X] = MTOUCHUSB_MIN_XC;
245 mtouch->input.absmax[ABS_X] = raw_coordinates ?
246 MTOUCHUSB_MAX_RAW_XC : MTOUCHUSB_MAX_CALIB_XC;
247 mtouch->input.absfuzz[ABS_X] = MTOUCHUSB_XC_FUZZ;
248 mtouch->input.absflat[ABS_X] = MTOUCHUSB_XC_FLAT;
249 mtouch->input.absmin[ABS_Y] = MTOUCHUSB_MIN_YC;
250 mtouch->input.absmax[ABS_Y] = raw_coordinates ?
251 MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC;
252 mtouch->input.absfuzz[ABS_Y] = MTOUCHUSB_YC_FUZZ;
253 mtouch->input.absflat[ABS_Y] = MTOUCHUSB_YC_FLAT;
254 225
255 if (udev->manufacturer) 226 if (udev->manufacturer)
256 strcat(mtouch->name, udev->manufacturer); 227 strlcpy(mtouch->name, udev->manufacturer, sizeof(mtouch->name));
257 if (udev->product) 228
258 sprintf(mtouch->name, "%s %s", mtouch->name, udev->product); 229 if (udev->product) {
230 if (udev->manufacturer)
231 strlcat(mtouch->name, " ", sizeof(mtouch->name));
232 strlcat(mtouch->name, udev->product, sizeof(mtouch->name));
233 }
259 234
260 if (!strlen(mtouch->name)) 235 if (!strlen(mtouch->name))
261 sprintf(mtouch->name, "USB Touchscreen %04x:%04x", 236 snprintf(mtouch->name, sizeof(mtouch->name),
262 mtouch->input.id.vendor, mtouch->input.id.product); 237 "USB Touchscreen %04x:%04x",
238 le16_to_cpu(udev->descriptor.idVendor),
239 le16_to_cpu(udev->descriptor.idProduct));
240
241 usb_make_path(udev, mtouch->phys, sizeof(mtouch->phys));
242 strlcpy(mtouch->phys, "/input0", sizeof(mtouch->phys));
243
244 input_dev->name = mtouch->name;
245 input_dev->phys = mtouch->phys;
246 usb_to_input_id(udev, &input_dev->id);
247 input_dev->cdev.dev = &intf->dev;
248 input_dev->private = mtouch;
249
250 input_dev->open = mtouchusb_open;
251 input_dev->close = mtouchusb_close;
252
253 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
254 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
255 input_set_abs_params(input_dev, ABS_X, MTOUCHUSB_MIN_XC,
256 raw_coordinates ? MTOUCHUSB_MAX_RAW_XC : MTOUCHUSB_MAX_CALIB_XC,
257 MTOUCHUSB_XC_FUZZ, MTOUCHUSB_XC_FLAT);
258 input_set_abs_params(input_dev, ABS_Y, MTOUCHUSB_MIN_YC,
259 raw_coordinates ? MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC,
260 MTOUCHUSB_YC_FUZZ, MTOUCHUSB_YC_FLAT);
263 261
264 nRet = usb_control_msg(mtouch->udev, usb_rcvctrlpipe(udev, 0), 262 nRet = usb_control_msg(mtouch->udev, usb_rcvctrlpipe(udev, 0),
265 MTOUCHUSB_RESET, 263 MTOUCHUSB_RESET,
@@ -272,9 +270,7 @@ static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_i
272 mtouch->irq = usb_alloc_urb(0, GFP_KERNEL); 270 mtouch->irq = usb_alloc_urb(0, GFP_KERNEL);
273 if (!mtouch->irq) { 271 if (!mtouch->irq) {
274 dbg("%s - usb_alloc_urb failed: mtouch->irq", __FUNCTION__); 272 dbg("%s - usb_alloc_urb failed: mtouch->irq", __FUNCTION__);
275 mtouchusb_free_buffers(udev, mtouch); 273 goto fail2;
276 kfree(mtouch);
277 return -ENOMEM;
278 } 274 }
279 275
280 dbg("%s - usb_fill_int_urb", __FUNCTION__); 276 dbg("%s - usb_fill_int_urb", __FUNCTION__);
@@ -284,7 +280,7 @@ static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_i
284 mtouchusb_irq, mtouch, endpoint->bInterval); 280 mtouchusb_irq, mtouch, endpoint->bInterval);
285 281
286 dbg("%s - input_register_device", __FUNCTION__); 282 dbg("%s - input_register_device", __FUNCTION__);
287 input_register_device(&mtouch->input); 283 input_register_device(mtouch->input);
288 284
289 nRet = usb_control_msg(mtouch->udev, usb_rcvctrlpipe(udev, 0), 285 nRet = usb_control_msg(mtouch->udev, usb_rcvctrlpipe(udev, 0),
290 MTOUCHUSB_ASYNC_REPORT, 286 MTOUCHUSB_ASYNC_REPORT,
@@ -293,10 +289,13 @@ static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_i
293 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d", 289 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
294 __FUNCTION__, nRet); 290 __FUNCTION__, nRet);
295 291
296 printk(KERN_INFO "input: %s on %s\n", mtouch->name, path);
297 usb_set_intfdata(intf, mtouch); 292 usb_set_intfdata(intf, mtouch);
298
299 return 0; 293 return 0;
294
295fail2: mtouchusb_free_buffers(udev, mtouch);
296fail1: input_free_device(input_dev);
297 kfree(mtouch);
298 return -ENOMEM;
300} 299}
301 300
302static void mtouchusb_disconnect(struct usb_interface *intf) 301static void mtouchusb_disconnect(struct usb_interface *intf)
@@ -308,7 +307,7 @@ static void mtouchusb_disconnect(struct usb_interface *intf)
308 if (mtouch) { 307 if (mtouch) {
309 dbg("%s - mtouch is initialized, cleaning up", __FUNCTION__); 308 dbg("%s - mtouch is initialized, cleaning up", __FUNCTION__);
310 usb_kill_urb(mtouch->irq); 309 usb_kill_urb(mtouch->irq);
311 input_unregister_device(&mtouch->input); 310 input_unregister_device(mtouch->input);
312 usb_free_urb(mtouch->irq); 311 usb_free_urb(mtouch->irq);
313 mtouchusb_free_buffers(interface_to_usbdev(intf), mtouch); 312 mtouchusb_free_buffers(interface_to_usbdev(intf), mtouch);
314 kfree(mtouch); 313 kfree(mtouch);
diff --git a/drivers/usb/input/pid.c b/drivers/usb/input/pid.c
index acc71ec560e9..dca5ee93a4ef 100644
--- a/drivers/usb/input/pid.c
+++ b/drivers/usb/input/pid.c
@@ -198,7 +198,7 @@ static int hid_pid_upload_effect(struct input_dev *dev,
198 } 198 }
199 199
200 effect->id = id; 200 effect->id = id;
201 dev_dbg(&pid_private->hid->dev->dev, "effect ID is %d\n.", id); 201 dev_dbg(&pid_private->hid->dev->dev, "effect ID is %d.\n", id);
202 pid_private->effects[id].owner = current->pid; 202 pid_private->effects[id].owner = current->pid;
203 pid_private->effects[id].flags = (1 << FF_PID_FLAGS_USED); 203 pid_private->effects[id].flags = (1 << FF_PID_FLAGS_USED);
204 spin_unlock_irqrestore(&pid_private->lock, flags); 204 spin_unlock_irqrestore(&pid_private->lock, flags);
@@ -262,6 +262,7 @@ int hid_pid_init(struct hid_device *hid)
262{ 262{
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 struct input_dev *input_dev = hidinput->input;
265 266
266 private = hid->ff_private = kzalloc(sizeof(struct hid_ff_pid), GFP_KERNEL); 267 private = hid->ff_private = kzalloc(sizeof(struct hid_ff_pid), GFP_KERNEL);
267 if (!private) 268 if (!private)
@@ -281,11 +282,12 @@ int hid_pid_init(struct hid_device *hid)
281 usb_fill_control_urb(private->urbffout, hid->dev, 0, 282 usb_fill_control_urb(private->urbffout, hid->dev, 0,
282 (void *)&private->ffcr, private->ctrl_buffer, 8, 283 (void *)&private->ffcr, private->ctrl_buffer, 8,
283 hid_pid_ctrl_out, hid); 284 hid_pid_ctrl_out, hid);
284 hidinput->input.upload_effect = hid_pid_upload_effect; 285
285 hidinput->input.flush = hid_pid_flush; 286 input_dev->upload_effect = hid_pid_upload_effect;
286 hidinput->input.ff_effects_max = 8; // A random default 287 input_dev->flush = hid_pid_flush;
287 set_bit(EV_FF, hidinput->input.evbit); 288 input_dev->ff_effects_max = 8; // A random default
288 set_bit(EV_FF_STATUS, hidinput->input.evbit); 289 set_bit(EV_FF, input_dev->evbit);
290 set_bit(EV_FF_STATUS, input_dev->evbit);
289 291
290 spin_lock_init(&private->lock); 292 spin_lock_init(&private->lock);
291 293
diff --git a/drivers/usb/input/powermate.c b/drivers/usb/input/powermate.c
index ad4afe7e5897..b7476233ef5d 100644
--- a/drivers/usb/input/powermate.c
+++ b/drivers/usb/input/powermate.c
@@ -68,7 +68,7 @@ struct powermate_device {
68 struct usb_ctrlrequest *configcr; 68 struct usb_ctrlrequest *configcr;
69 dma_addr_t configcr_dma; 69 dma_addr_t configcr_dma;
70 struct usb_device *udev; 70 struct usb_device *udev;
71 struct input_dev input; 71 struct input_dev *input;
72 spinlock_t lock; 72 spinlock_t lock;
73 int static_brightness; 73 int static_brightness;
74 int pulse_speed; 74 int pulse_speed;
@@ -106,10 +106,10 @@ static void powermate_irq(struct urb *urb, struct pt_regs *regs)
106 } 106 }
107 107
108 /* handle updates to device state */ 108 /* handle updates to device state */
109 input_regs(&pm->input, regs); 109 input_regs(pm->input, regs);
110 input_report_key(&pm->input, BTN_0, pm->data[0] & 0x01); 110 input_report_key(pm->input, BTN_0, pm->data[0] & 0x01);
111 input_report_rel(&pm->input, REL_DIAL, pm->data[1]); 111 input_report_rel(pm->input, REL_DIAL, pm->data[1]);
112 input_sync(&pm->input); 112 input_sync(pm->input);
113 113
114exit: 114exit:
115 retval = usb_submit_urb (urb, GFP_ATOMIC); 115 retval = usb_submit_urb (urb, GFP_ATOMIC);
@@ -153,10 +153,10 @@ static void powermate_sync_state(struct powermate_device *pm)
153 153
154 Only values of 'arg' quite close to 255 are particularly useful/spectacular. 154 Only values of 'arg' quite close to 255 are particularly useful/spectacular.
155 */ 155 */
156 if (pm->pulse_speed < 255){ 156 if (pm->pulse_speed < 255) {
157 op = 0; // divide 157 op = 0; // divide
158 arg = 255 - pm->pulse_speed; 158 arg = 255 - pm->pulse_speed;
159 } else if (pm->pulse_speed > 255){ 159 } else if (pm->pulse_speed > 255) {
160 op = 2; // multiply 160 op = 2; // multiply
161 arg = pm->pulse_speed - 255; 161 arg = pm->pulse_speed - 255;
162 } else { 162 } else {
@@ -166,11 +166,11 @@ static void powermate_sync_state(struct powermate_device *pm)
166 pm->configcr->wValue = cpu_to_le16( (pm->pulse_table << 8) | SET_PULSE_MODE ); 166 pm->configcr->wValue = cpu_to_le16( (pm->pulse_table << 8) | SET_PULSE_MODE );
167 pm->configcr->wIndex = cpu_to_le16( (arg << 8) | op ); 167 pm->configcr->wIndex = cpu_to_le16( (arg << 8) | op );
168 pm->requires_update &= ~UPDATE_PULSE_MODE; 168 pm->requires_update &= ~UPDATE_PULSE_MODE;
169 }else if (pm->requires_update & UPDATE_STATIC_BRIGHTNESS){ 169 } else if (pm->requires_update & UPDATE_STATIC_BRIGHTNESS) {
170 pm->configcr->wValue = cpu_to_le16( SET_STATIC_BRIGHTNESS ); 170 pm->configcr->wValue = cpu_to_le16( SET_STATIC_BRIGHTNESS );
171 pm->configcr->wIndex = cpu_to_le16( pm->static_brightness ); 171 pm->configcr->wIndex = cpu_to_le16( pm->static_brightness );
172 pm->requires_update &= ~UPDATE_STATIC_BRIGHTNESS; 172 pm->requires_update &= ~UPDATE_STATIC_BRIGHTNESS;
173 }else{ 173 } else {
174 printk(KERN_ERR "powermate: unknown update required"); 174 printk(KERN_ERR "powermate: unknown update required");
175 pm->requires_update = 0; /* fudge the bug */ 175 pm->requires_update = 0; /* fudge the bug */
176 return; 176 return;
@@ -228,19 +228,19 @@ static void powermate_pulse_led(struct powermate_device *pm, int static_brightne
228 spin_lock_irqsave(&pm->lock, flags); 228 spin_lock_irqsave(&pm->lock, flags);
229 229
230 /* mark state updates which are required */ 230 /* mark state updates which are required */
231 if (static_brightness != pm->static_brightness){ 231 if (static_brightness != pm->static_brightness) {
232 pm->static_brightness = static_brightness; 232 pm->static_brightness = static_brightness;
233 pm->requires_update |= UPDATE_STATIC_BRIGHTNESS; 233 pm->requires_update |= UPDATE_STATIC_BRIGHTNESS;
234 } 234 }
235 if (pulse_asleep != pm->pulse_asleep){ 235 if (pulse_asleep != pm->pulse_asleep) {
236 pm->pulse_asleep = pulse_asleep; 236 pm->pulse_asleep = pulse_asleep;
237 pm->requires_update |= (UPDATE_PULSE_ASLEEP | UPDATE_STATIC_BRIGHTNESS); 237 pm->requires_update |= (UPDATE_PULSE_ASLEEP | UPDATE_STATIC_BRIGHTNESS);
238 } 238 }
239 if (pulse_awake != pm->pulse_awake){ 239 if (pulse_awake != pm->pulse_awake) {
240 pm->pulse_awake = pulse_awake; 240 pm->pulse_awake = pulse_awake;
241 pm->requires_update |= (UPDATE_PULSE_AWAKE | UPDATE_STATIC_BRIGHTNESS); 241 pm->requires_update |= (UPDATE_PULSE_AWAKE | UPDATE_STATIC_BRIGHTNESS);
242 } 242 }
243 if (pulse_speed != pm->pulse_speed || pulse_table != pm->pulse_table){ 243 if (pulse_speed != pm->pulse_speed || pulse_table != pm->pulse_table) {
244 pm->pulse_speed = pulse_speed; 244 pm->pulse_speed = pulse_speed;
245 pm->pulse_table = pulse_table; 245 pm->pulse_table = pulse_table;
246 pm->requires_update |= UPDATE_PULSE_MODE; 246 pm->requires_update |= UPDATE_PULSE_MODE;
@@ -283,6 +283,7 @@ static int powermate_alloc_buffers(struct usb_device *udev, struct powermate_dev
283 SLAB_ATOMIC, &pm->data_dma); 283 SLAB_ATOMIC, &pm->data_dma);
284 if (!pm->data) 284 if (!pm->data)
285 return -1; 285 return -1;
286
286 pm->configcr = usb_buffer_alloc(udev, sizeof(*(pm->configcr)), 287 pm->configcr = usb_buffer_alloc(udev, sizeof(*(pm->configcr)),
287 SLAB_ATOMIC, &pm->configcr_dma); 288 SLAB_ATOMIC, &pm->configcr_dma);
288 if (!pm->configcr) 289 if (!pm->configcr)
@@ -308,8 +309,9 @@ static int powermate_probe(struct usb_interface *intf, const struct usb_device_i
308 struct usb_host_interface *interface; 309 struct usb_host_interface *interface;
309 struct usb_endpoint_descriptor *endpoint; 310 struct usb_endpoint_descriptor *endpoint;
310 struct powermate_device *pm; 311 struct powermate_device *pm;
312 struct input_dev *input_dev;
311 int pipe, maxp; 313 int pipe, maxp;
312 char path[64]; 314 int err = -ENOMEM;
313 315
314 interface = intf->cur_altsetting; 316 interface = intf->cur_altsetting;
315 endpoint = &interface->endpoint[0].desc; 317 endpoint = &interface->endpoint[0].desc;
@@ -323,42 +325,61 @@ static int powermate_probe(struct usb_interface *intf, const struct usb_device_i
323 0, interface->desc.bInterfaceNumber, NULL, 0, 325 0, interface->desc.bInterfaceNumber, NULL, 0,
324 USB_CTRL_SET_TIMEOUT); 326 USB_CTRL_SET_TIMEOUT);
325 327
326 if (!(pm = kmalloc(sizeof(struct powermate_device), GFP_KERNEL))) 328 pm = kzalloc(sizeof(struct powermate_device), GFP_KERNEL);
327 return -ENOMEM; 329 input_dev = input_allocate_device();
328 330 if (!pm || !input_dev)
329 memset(pm, 0, sizeof(struct powermate_device)); 331 goto fail1;
330 pm->udev = udev;
331 332
332 if (powermate_alloc_buffers(udev, pm)) { 333 if (powermate_alloc_buffers(udev, pm))
333 powermate_free_buffers(udev, pm); 334 goto fail2;
334 kfree(pm);
335 return -ENOMEM;
336 }
337 335
338 pm->irq = usb_alloc_urb(0, GFP_KERNEL); 336 pm->irq = usb_alloc_urb(0, GFP_KERNEL);
339 if (!pm->irq) { 337 if (!pm->irq)
340 powermate_free_buffers(udev, pm); 338 goto fail2;
341 kfree(pm);
342 return -ENOMEM;
343 }
344 339
345 pm->config = usb_alloc_urb(0, GFP_KERNEL); 340 pm->config = usb_alloc_urb(0, GFP_KERNEL);
346 if (!pm->config) { 341 if (!pm->config)
347 usb_free_urb(pm->irq); 342 goto fail3;
348 powermate_free_buffers(udev, pm); 343
349 kfree(pm); 344 pm->udev = udev;
350 return -ENOMEM; 345 pm->input = input_dev;
351 } 346
347 usb_make_path(udev, pm->phys, sizeof(pm->phys));
348 strlcpy(pm->phys, "/input0", sizeof(pm->phys));
352 349
353 spin_lock_init(&pm->lock); 350 spin_lock_init(&pm->lock);
354 init_input_dev(&pm->input); 351
352 switch (le16_to_cpu(udev->descriptor.idProduct)) {
353 case POWERMATE_PRODUCT_NEW:
354 input_dev->name = pm_name_powermate;
355 break;
356 case POWERMATE_PRODUCT_OLD:
357 input_dev->name = pm_name_soundknob;
358 break;
359 default:
360 input_dev->name = pm_name_soundknob;
361 printk(KERN_WARNING "powermate: unknown product id %04x\n",
362 le16_to_cpu(udev->descriptor.idProduct));
363 }
364
365 input_dev->phys = pm->phys;
366 usb_to_input_id(udev, &input_dev->id);
367 input_dev->cdev.dev = &intf->dev;
368 input_dev->private = pm;
369
370 input_dev->event = powermate_input_event;
371
372 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL) | BIT(EV_MSC);
373 input_dev->keybit[LONG(BTN_0)] = BIT(BTN_0);
374 input_dev->relbit[LONG(REL_DIAL)] = BIT(REL_DIAL);
375 input_dev->mscbit[LONG(MSC_PULSELED)] = BIT(MSC_PULSELED);
355 376
356 /* get a handle to the interrupt data pipe */ 377 /* get a handle to the interrupt data pipe */
357 pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress); 378 pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress);
358 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe)); 379 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
359 380
360 if(maxp < POWERMATE_PAYLOAD_SIZE_MIN || maxp > POWERMATE_PAYLOAD_SIZE_MAX){ 381 if (maxp < POWERMATE_PAYLOAD_SIZE_MIN || maxp > POWERMATE_PAYLOAD_SIZE_MAX) {
361 printk("powermate: Expected payload of %d--%d bytes, found %d bytes!\n", 382 printk(KERN_WARNING "powermate: Expected payload of %d--%d bytes, found %d bytes!\n",
362 POWERMATE_PAYLOAD_SIZE_MIN, POWERMATE_PAYLOAD_SIZE_MAX, maxp); 383 POWERMATE_PAYLOAD_SIZE_MIN, POWERMATE_PAYLOAD_SIZE_MAX, maxp);
363 maxp = POWERMATE_PAYLOAD_SIZE_MAX; 384 maxp = POWERMATE_PAYLOAD_SIZE_MAX;
364 } 385 }
@@ -371,35 +392,11 @@ static int powermate_probe(struct usb_interface *intf, const struct usb_device_i
371 392
372 /* register our interrupt URB with the USB system */ 393 /* register our interrupt URB with the USB system */
373 if (usb_submit_urb(pm->irq, GFP_KERNEL)) { 394 if (usb_submit_urb(pm->irq, GFP_KERNEL)) {
374 powermate_free_buffers(udev, pm); 395 err = -EIO;
375 kfree(pm); 396 goto fail4;
376 return -EIO; /* failure */
377 } 397 }
378 398
379 switch (le16_to_cpu(udev->descriptor.idProduct)) { 399 input_register_device(pm->input);
380 case POWERMATE_PRODUCT_NEW: pm->input.name = pm_name_powermate; break;
381 case POWERMATE_PRODUCT_OLD: pm->input.name = pm_name_soundknob; break;
382 default:
383 pm->input.name = pm_name_soundknob;
384 printk(KERN_WARNING "powermate: unknown product id %04x\n",
385 le16_to_cpu(udev->descriptor.idProduct));
386 }
387
388 pm->input.private = pm;
389 pm->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REL) | BIT(EV_MSC);
390 pm->input.keybit[LONG(BTN_0)] = BIT(BTN_0);
391 pm->input.relbit[LONG(REL_DIAL)] = BIT(REL_DIAL);
392 pm->input.mscbit[LONG(MSC_PULSELED)] = BIT(MSC_PULSELED);
393 usb_to_input_id(udev, &pm->input.id);
394 pm->input.event = powermate_input_event;
395 pm->input.dev = &intf->dev;
396 pm->input.phys = pm->phys;
397
398 input_register_device(&pm->input);
399
400 usb_make_path(udev, path, 64);
401 snprintf(pm->phys, 64, "%s/input0", path);
402 printk(KERN_INFO "input: %s on %s\n", pm->input.name, pm->input.phys);
403 400
404 /* force an update of everything */ 401 /* force an update of everything */
405 pm->requires_update = UPDATE_PULSE_ASLEEP | UPDATE_PULSE_AWAKE | UPDATE_PULSE_MODE | UPDATE_STATIC_BRIGHTNESS; 402 pm->requires_update = UPDATE_PULSE_ASLEEP | UPDATE_PULSE_AWAKE | UPDATE_PULSE_MODE | UPDATE_STATIC_BRIGHTNESS;
@@ -407,6 +404,13 @@ static int powermate_probe(struct usb_interface *intf, const struct usb_device_i
407 404
408 usb_set_intfdata(intf, pm); 405 usb_set_intfdata(intf, pm);
409 return 0; 406 return 0;
407
408fail4: usb_free_urb(pm->config);
409fail3: usb_free_urb(pm->irq);
410fail2: powermate_free_buffers(udev, pm);
411fail1: input_free_device(input_dev);
412 kfree(pm);
413 return err;
410} 414}
411 415
412/* Called when a USB device we've accepted ownership of is removed */ 416/* Called when a USB device we've accepted ownership of is removed */
@@ -418,7 +422,7 @@ static void powermate_disconnect(struct usb_interface *intf)
418 if (pm) { 422 if (pm) {
419 pm->requires_update = 0; 423 pm->requires_update = 0;
420 usb_kill_urb(pm->irq); 424 usb_kill_urb(pm->irq);
421 input_unregister_device(&pm->input); 425 input_unregister_device(pm->input);
422 usb_free_urb(pm->irq); 426 usb_free_urb(pm->irq);
423 usb_free_urb(pm->config); 427 usb_free_urb(pm->config);
424 powermate_free_buffers(interface_to_usbdev(intf), pm); 428 powermate_free_buffers(interface_to_usbdev(intf), pm);
diff --git a/drivers/usb/input/touchkitusb.c b/drivers/usb/input/touchkitusb.c
index 4276c24a5080..0043e6ebcd1f 100644
--- a/drivers/usb/input/touchkitusb.c
+++ b/drivers/usb/input/touchkitusb.c
@@ -68,14 +68,16 @@ struct touchkit_usb {
68 dma_addr_t data_dma; 68 dma_addr_t data_dma;
69 struct urb *irq; 69 struct urb *irq;
70 struct usb_device *udev; 70 struct usb_device *udev;
71 struct input_dev input; 71 struct input_dev *input;
72 char name[128]; 72 char name[128];
73 char phys[64]; 73 char phys[64];
74}; 74};
75 75
76static struct usb_device_id touchkit_devices[] = { 76static struct usb_device_id touchkit_devices[] = {
77 {USB_DEVICE(0x3823, 0x0001)}, 77 {USB_DEVICE(0x3823, 0x0001)},
78 {USB_DEVICE(0x0123, 0x0001)},
78 {USB_DEVICE(0x0eef, 0x0001)}, 79 {USB_DEVICE(0x0eef, 0x0001)},
80 {USB_DEVICE(0x0eef, 0x0002)},
79 {} 81 {}
80}; 82};
81 83
@@ -115,12 +117,12 @@ static void touchkit_irq(struct urb *urb, struct pt_regs *regs)
115 y = TOUCHKIT_GET_Y(touchkit->data); 117 y = TOUCHKIT_GET_Y(touchkit->data);
116 } 118 }
117 119
118 input_regs(&touchkit->input, regs); 120 input_regs(touchkit->input, regs);
119 input_report_key(&touchkit->input, BTN_TOUCH, 121 input_report_key(touchkit->input, BTN_TOUCH,
120 TOUCHKIT_GET_TOUCHED(touchkit->data)); 122 TOUCHKIT_GET_TOUCHED(touchkit->data));
121 input_report_abs(&touchkit->input, ABS_X, x); 123 input_report_abs(touchkit->input, ABS_X, x);
122 input_report_abs(&touchkit->input, ABS_Y, y); 124 input_report_abs(touchkit->input, ABS_Y, y);
123 input_sync(&touchkit->input); 125 input_sync(touchkit->input);
124 126
125exit: 127exit:
126 retval = usb_submit_urb(urb, GFP_ATOMIC); 128 retval = usb_submit_urb(urb, GFP_ATOMIC);
@@ -171,87 +173,81 @@ static void touchkit_free_buffers(struct usb_device *udev,
171static int touchkit_probe(struct usb_interface *intf, 173static int touchkit_probe(struct usb_interface *intf,
172 const struct usb_device_id *id) 174 const struct usb_device_id *id)
173{ 175{
174 int ret;
175 struct touchkit_usb *touchkit; 176 struct touchkit_usb *touchkit;
177 struct input_dev *input_dev;
176 struct usb_host_interface *interface; 178 struct usb_host_interface *interface;
177 struct usb_endpoint_descriptor *endpoint; 179 struct usb_endpoint_descriptor *endpoint;
178 struct usb_device *udev = interface_to_usbdev(intf); 180 struct usb_device *udev = interface_to_usbdev(intf);
179 char path[64];
180 181
181 interface = intf->cur_altsetting; 182 interface = intf->cur_altsetting;
182 endpoint = &interface->endpoint[0].desc; 183 endpoint = &interface->endpoint[0].desc;
183 184
184 touchkit = kmalloc(sizeof(struct touchkit_usb), GFP_KERNEL); 185 touchkit = kzalloc(sizeof(struct touchkit_usb), GFP_KERNEL);
185 if (!touchkit) 186 input_dev = input_allocate_device();
186 return -ENOMEM; 187 if (!touchkit || !input_dev)
187
188 memset(touchkit, 0, sizeof(struct touchkit_usb));
189 touchkit->udev = udev;
190
191 if (touchkit_alloc_buffers(udev, touchkit)) {
192 ret = -ENOMEM;
193 goto out_free; 188 goto out_free;
194 }
195
196 touchkit->input.private = touchkit;
197 touchkit->input.open = touchkit_open;
198 touchkit->input.close = touchkit_close;
199
200 usb_make_path(udev, path, 64);
201 sprintf(touchkit->phys, "%s/input0", path);
202
203 touchkit->input.name = touchkit->name;
204 touchkit->input.phys = touchkit->phys;
205 usb_to_input_id(udev, &touchkit->input.id);
206 touchkit->input.dev = &intf->dev;
207
208 touchkit->input.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
209 touchkit->input.absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
210 touchkit->input.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
211
212 /* Used to Scale Compensated Data */
213 touchkit->input.absmin[ABS_X] = TOUCHKIT_MIN_XC;
214 touchkit->input.absmax[ABS_X] = TOUCHKIT_MAX_XC;
215 touchkit->input.absfuzz[ABS_X] = TOUCHKIT_XC_FUZZ;
216 touchkit->input.absflat[ABS_X] = TOUCHKIT_XC_FLAT;
217 touchkit->input.absmin[ABS_Y] = TOUCHKIT_MIN_YC;
218 touchkit->input.absmax[ABS_Y] = TOUCHKIT_MAX_YC;
219 touchkit->input.absfuzz[ABS_Y] = TOUCHKIT_YC_FUZZ;
220 touchkit->input.absflat[ABS_Y] = TOUCHKIT_YC_FLAT;
221
222 if (udev->manufacturer)
223 strcat(touchkit->name, udev->manufacturer);
224 if (udev->product)
225 sprintf(touchkit->name, "%s %s", touchkit->name, udev->product);
226 189
227 if (!strlen(touchkit->name)) 190 if (touchkit_alloc_buffers(udev, touchkit))
228 sprintf(touchkit->name, "USB Touchscreen %04x:%04x", 191 goto out_free;
229 touchkit->input.id.vendor, touchkit->input.id.product);
230 192
231 touchkit->irq = usb_alloc_urb(0, GFP_KERNEL); 193 touchkit->irq = usb_alloc_urb(0, GFP_KERNEL);
232 if (!touchkit->irq) { 194 if (!touchkit->irq) {
233 dbg("%s - usb_alloc_urb failed: touchkit->irq", __FUNCTION__); 195 dbg("%s - usb_alloc_urb failed: touchkit->irq", __FUNCTION__);
234 ret = -ENOMEM;
235 goto out_free_buffers; 196 goto out_free_buffers;
236 } 197 }
237 198
199 touchkit->udev = udev;
200 touchkit->input = input_dev;
201
202 if (udev->manufacturer)
203 strlcpy(touchkit->name, udev->manufacturer, sizeof(touchkit->name));
204
205 if (udev->product) {
206 if (udev->manufacturer)
207 strlcat(touchkit->name, " ", sizeof(touchkit->name));
208 strlcat(touchkit->name, udev->product, sizeof(touchkit->name));
209 }
210
211 if (!strlen(touchkit->name))
212 snprintf(touchkit->name, sizeof(touchkit->name),
213 "USB Touchscreen %04x:%04x",
214 le16_to_cpu(udev->descriptor.idVendor),
215 le16_to_cpu(udev->descriptor.idProduct));
216
217 usb_make_path(udev, touchkit->phys, sizeof(touchkit->phys));
218 strlcpy(touchkit->phys, "/input0", sizeof(touchkit->phys));
219
220 input_dev->name = touchkit->name;
221 input_dev->phys = touchkit->phys;
222 usb_to_input_id(udev, &input_dev->id);
223 input_dev->cdev.dev = &intf->dev;
224 input_dev->private = touchkit;
225 input_dev->open = touchkit_open;
226 input_dev->close = touchkit_close;
227
228 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
229 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
230 input_set_abs_params(input_dev, ABS_X, TOUCHKIT_MIN_XC, TOUCHKIT_MAX_XC,
231 TOUCHKIT_XC_FUZZ, TOUCHKIT_XC_FLAT);
232 input_set_abs_params(input_dev, ABS_Y, TOUCHKIT_MIN_YC, TOUCHKIT_MAX_YC,
233 TOUCHKIT_YC_FUZZ, TOUCHKIT_YC_FLAT);
234
238 usb_fill_int_urb(touchkit->irq, touchkit->udev, 235 usb_fill_int_urb(touchkit->irq, touchkit->udev,
239 usb_rcvintpipe(touchkit->udev, 0x81), 236 usb_rcvintpipe(touchkit->udev, 0x81),
240 touchkit->data, TOUCHKIT_REPORT_DATA_SIZE, 237 touchkit->data, TOUCHKIT_REPORT_DATA_SIZE,
241 touchkit_irq, touchkit, endpoint->bInterval); 238 touchkit_irq, touchkit, endpoint->bInterval);
242 239
243 input_register_device(&touchkit->input); 240 input_register_device(touchkit->input);
244 241
245 printk(KERN_INFO "input: %s on %s\n", touchkit->name, path);
246 usb_set_intfdata(intf, touchkit); 242 usb_set_intfdata(intf, touchkit);
247
248 return 0; 243 return 0;
249 244
250out_free_buffers: 245out_free_buffers:
251 touchkit_free_buffers(udev, touchkit); 246 touchkit_free_buffers(udev, touchkit);
252out_free: 247out_free:
248 input_free_device(input_dev);
253 kfree(touchkit); 249 kfree(touchkit);
254 return ret; 250 return -ENOMEM;
255} 251}
256 252
257static void touchkit_disconnect(struct usb_interface *intf) 253static void touchkit_disconnect(struct usb_interface *intf)
@@ -265,8 +261,8 @@ static void touchkit_disconnect(struct usb_interface *intf)
265 261
266 dbg("%s - touchkit is initialized, cleaning up", __FUNCTION__); 262 dbg("%s - touchkit is initialized, cleaning up", __FUNCTION__);
267 usb_set_intfdata(intf, NULL); 263 usb_set_intfdata(intf, NULL);
268 input_unregister_device(&touchkit->input);
269 usb_kill_urb(touchkit->irq); 264 usb_kill_urb(touchkit->irq);
265 input_unregister_device(touchkit->input);
270 usb_free_urb(touchkit->irq); 266 usb_free_urb(touchkit->irq);
271 touchkit_free_buffers(interface_to_usbdev(intf), touchkit); 267 touchkit_free_buffers(interface_to_usbdev(intf), touchkit);
272 kfree(touchkit); 268 kfree(touchkit);
diff --git a/drivers/usb/input/usbkbd.c b/drivers/usb/input/usbkbd.c
index 28987f15eeee..226b6f90a907 100644
--- a/drivers/usb/input/usbkbd.c
+++ b/drivers/usb/input/usbkbd.c
@@ -66,7 +66,7 @@ static unsigned char usb_kbd_keycode[256] = {
66}; 66};
67 67
68struct usb_kbd { 68struct usb_kbd {
69 struct input_dev dev; 69 struct input_dev *dev;
70 struct usb_device *usbdev; 70 struct usb_device *usbdev;
71 unsigned char old[8]; 71 unsigned char old[8];
72 struct urb *irq, *led; 72 struct urb *irq, *led;
@@ -99,29 +99,29 @@ static void usb_kbd_irq(struct urb *urb, struct pt_regs *regs)
99 goto resubmit; 99 goto resubmit;
100 } 100 }
101 101
102 input_regs(&kbd->dev, regs); 102 input_regs(kbd->dev, regs);
103 103
104 for (i = 0; i < 8; i++) 104 for (i = 0; i < 8; i++)
105 input_report_key(&kbd->dev, usb_kbd_keycode[i + 224], (kbd->new[0] >> i) & 1); 105 input_report_key(kbd->dev, usb_kbd_keycode[i + 224], (kbd->new[0] >> i) & 1);
106 106
107 for (i = 2; i < 8; i++) { 107 for (i = 2; i < 8; i++) {
108 108
109 if (kbd->old[i] > 3 && memscan(kbd->new + 2, kbd->old[i], 6) == kbd->new + 8) { 109 if (kbd->old[i] > 3 && memscan(kbd->new + 2, kbd->old[i], 6) == kbd->new + 8) {
110 if (usb_kbd_keycode[kbd->old[i]]) 110 if (usb_kbd_keycode[kbd->old[i]])
111 input_report_key(&kbd->dev, usb_kbd_keycode[kbd->old[i]], 0); 111 input_report_key(kbd->dev, usb_kbd_keycode[kbd->old[i]], 0);
112 else 112 else
113 info("Unknown key (scancode %#x) released.", kbd->old[i]); 113 info("Unknown key (scancode %#x) released.", kbd->old[i]);
114 } 114 }
115 115
116 if (kbd->new[i] > 3 && memscan(kbd->old + 2, kbd->new[i], 6) == kbd->old + 8) { 116 if (kbd->new[i] > 3 && memscan(kbd->old + 2, kbd->new[i], 6) == kbd->old + 8) {
117 if (usb_kbd_keycode[kbd->new[i]]) 117 if (usb_kbd_keycode[kbd->new[i]])
118 input_report_key(&kbd->dev, usb_kbd_keycode[kbd->new[i]], 1); 118 input_report_key(kbd->dev, usb_kbd_keycode[kbd->new[i]], 1);
119 else 119 else
120 info("Unknown key (scancode %#x) pressed.", kbd->new[i]); 120 info("Unknown key (scancode %#x) pressed.", kbd->new[i]);
121 } 121 }
122 } 122 }
123 123
124 input_sync(&kbd->dev); 124 input_sync(kbd->dev);
125 125
126 memcpy(kbd->old, kbd->new, 8); 126 memcpy(kbd->old, kbd->new, 8);
127 127
@@ -227,12 +227,12 @@ static void usb_kbd_free_mem(struct usb_device *dev, struct usb_kbd *kbd)
227static int usb_kbd_probe(struct usb_interface *iface, 227static int usb_kbd_probe(struct usb_interface *iface,
228 const struct usb_device_id *id) 228 const struct usb_device_id *id)
229{ 229{
230 struct usb_device * dev = interface_to_usbdev(iface); 230 struct usb_device *dev = interface_to_usbdev(iface);
231 struct usb_host_interface *interface; 231 struct usb_host_interface *interface;
232 struct usb_endpoint_descriptor *endpoint; 232 struct usb_endpoint_descriptor *endpoint;
233 struct usb_kbd *kbd; 233 struct usb_kbd *kbd;
234 struct input_dev *input_dev;
234 int i, pipe, maxp; 235 int i, pipe, maxp;
235 char path[64];
236 236
237 interface = iface->cur_altsetting; 237 interface = iface->cur_altsetting;
238 238
@@ -240,37 +240,59 @@ static int usb_kbd_probe(struct usb_interface *iface,
240 return -ENODEV; 240 return -ENODEV;
241 241
242 endpoint = &interface->endpoint[0].desc; 242 endpoint = &interface->endpoint[0].desc;
243 if (!(endpoint->bEndpointAddress & 0x80)) 243 if (!(endpoint->bEndpointAddress & USB_DIR_IN))
244 return -ENODEV; 244 return -ENODEV;
245 if ((endpoint->bmAttributes & 3) != 3) 245 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT)
246 return -ENODEV; 246 return -ENODEV;
247 247
248 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); 248 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
249 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); 249 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
250 250
251 if (!(kbd = kmalloc(sizeof(struct usb_kbd), GFP_KERNEL))) 251 kbd = kzalloc(sizeof(struct usb_kbd), GFP_KERNEL);
252 return -ENOMEM; 252 input_dev = input_allocate_device();
253 memset(kbd, 0, sizeof(struct usb_kbd)); 253 if (!kbd || !input_dev)
254 goto fail1;
254 255
255 if (usb_kbd_alloc_mem(dev, kbd)) { 256 if (usb_kbd_alloc_mem(dev, kbd))
256 usb_kbd_free_mem(dev, kbd); 257 goto fail2;
257 kfree(kbd);
258 return -ENOMEM;
259 }
260 258
261 kbd->usbdev = dev; 259 kbd->usbdev = dev;
260 kbd->dev = input_dev;
261
262 if (dev->manufacturer)
263 strlcpy(kbd->name, dev->manufacturer, sizeof(kbd->name));
264
265 if (dev->product) {
266 if (dev->manufacturer)
267 strlcat(kbd->name, " ", sizeof(kbd->name));
268 strlcat(kbd->name, dev->product, sizeof(kbd->name));
269 }
270
271 if (!strlen(kbd->name))
272 snprintf(kbd->name, sizeof(kbd->name),
273 "USB HIDBP Keyboard %04x:%04x",
274 le16_to_cpu(dev->descriptor.idVendor),
275 le16_to_cpu(dev->descriptor.idProduct));
276
277 usb_make_path(dev, kbd->phys, sizeof(kbd->phys));
278 strlcpy(kbd->phys, "/input0", sizeof(kbd->phys));
262 279
263 kbd->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_REP); 280 input_dev->name = kbd->name;
264 kbd->dev.ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL) | BIT(LED_COMPOSE) | BIT(LED_KANA); 281 input_dev->phys = kbd->phys;
282 usb_to_input_id(dev, &input_dev->id);
283 input_dev->cdev.dev = &iface->dev;
284 input_dev->private = kbd;
285
286 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_REP);
287 input_dev->ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL) | BIT(LED_COMPOSE) | BIT(LED_KANA);
265 288
266 for (i = 0; i < 255; i++) 289 for (i = 0; i < 255; i++)
267 set_bit(usb_kbd_keycode[i], kbd->dev.keybit); 290 set_bit(usb_kbd_keycode[i], input_dev->keybit);
268 clear_bit(0, kbd->dev.keybit); 291 clear_bit(0, input_dev->keybit);
269 292
270 kbd->dev.private = kbd; 293 input_dev->event = usb_kbd_event;
271 kbd->dev.event = usb_kbd_event; 294 input_dev->open = usb_kbd_open;
272 kbd->dev.open = usb_kbd_open; 295 input_dev->close = usb_kbd_close;
273 kbd->dev.close = usb_kbd_close;
274 296
275 usb_fill_int_urb(kbd->irq, dev, pipe, 297 usb_fill_int_urb(kbd->irq, dev, pipe,
276 kbd->new, (maxp > 8 ? 8 : maxp), 298 kbd->new, (maxp > 8 ? 8 : maxp),
@@ -284,37 +306,22 @@ static int usb_kbd_probe(struct usb_interface *iface,
284 kbd->cr->wIndex = cpu_to_le16(interface->desc.bInterfaceNumber); 306 kbd->cr->wIndex = cpu_to_le16(interface->desc.bInterfaceNumber);
285 kbd->cr->wLength = cpu_to_le16(1); 307 kbd->cr->wLength = cpu_to_le16(1);
286 308
287 usb_make_path(dev, path, 64);
288 sprintf(kbd->phys, "%s/input0", path);
289
290 kbd->dev.name = kbd->name;
291 kbd->dev.phys = kbd->phys;
292 usb_to_input_id(dev, &kbd->dev.id);
293 kbd->dev.dev = &iface->dev;
294
295 if (dev->manufacturer)
296 strcat(kbd->name, dev->manufacturer);
297 if (dev->product)
298 sprintf(kbd->name, "%s %s", kbd->name, dev->product);
299
300 if (!strlen(kbd->name))
301 sprintf(kbd->name, "USB HIDBP Keyboard %04x:%04x",
302 kbd->dev.id.vendor, kbd->dev.id.product);
303
304 usb_fill_control_urb(kbd->led, dev, usb_sndctrlpipe(dev, 0), 309 usb_fill_control_urb(kbd->led, dev, usb_sndctrlpipe(dev, 0),
305 (void *) kbd->cr, kbd->leds, 1, 310 (void *) kbd->cr, kbd->leds, 1,
306 usb_kbd_led, kbd); 311 usb_kbd_led, kbd);
307 kbd->led->setup_dma = kbd->cr_dma; 312 kbd->led->setup_dma = kbd->cr_dma;
308 kbd->led->transfer_dma = kbd->leds_dma; 313 kbd->led->transfer_dma = kbd->leds_dma;
309 kbd->led->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP 314 kbd->led->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP);
310 | URB_NO_SETUP_DMA_MAP);
311 315
312 input_register_device(&kbd->dev); 316 input_register_device(kbd->dev);
313
314 printk(KERN_INFO "input: %s on %s\n", kbd->name, path);
315 317
316 usb_set_intfdata(iface, kbd); 318 usb_set_intfdata(iface, kbd);
317 return 0; 319 return 0;
320
321fail2: usb_kbd_free_mem(dev, kbd);
322fail1: input_free_device(input_dev);
323 kfree(kbd);
324 return -ENOMEM;
318} 325}
319 326
320static void usb_kbd_disconnect(struct usb_interface *intf) 327static void usb_kbd_disconnect(struct usb_interface *intf)
@@ -324,7 +331,7 @@ static void usb_kbd_disconnect(struct usb_interface *intf)
324 usb_set_intfdata(intf, NULL); 331 usb_set_intfdata(intf, NULL);
325 if (kbd) { 332 if (kbd) {
326 usb_kill_urb(kbd->irq); 333 usb_kill_urb(kbd->irq);
327 input_unregister_device(&kbd->dev); 334 input_unregister_device(kbd->dev);
328 usb_kbd_free_mem(interface_to_usbdev(intf), kbd); 335 usb_kbd_free_mem(interface_to_usbdev(intf), kbd);
329 kfree(kbd); 336 kfree(kbd);
330 } 337 }
diff --git a/drivers/usb/input/usbmouse.c b/drivers/usb/input/usbmouse.c
index 4104dec847fb..230f6b1b314a 100644
--- a/drivers/usb/input/usbmouse.c
+++ b/drivers/usb/input/usbmouse.c
@@ -50,7 +50,7 @@ struct usb_mouse {
50 char name[128]; 50 char name[128];
51 char phys[64]; 51 char phys[64];
52 struct usb_device *usbdev; 52 struct usb_device *usbdev;
53 struct input_dev dev; 53 struct input_dev *dev;
54 struct urb *irq; 54 struct urb *irq;
55 55
56 signed char *data; 56 signed char *data;
@@ -61,7 +61,7 @@ static void usb_mouse_irq(struct urb *urb, struct pt_regs *regs)
61{ 61{
62 struct usb_mouse *mouse = urb->context; 62 struct usb_mouse *mouse = urb->context;
63 signed char *data = mouse->data; 63 signed char *data = mouse->data;
64 struct input_dev *dev = &mouse->dev; 64 struct input_dev *dev = mouse->dev;
65 int status; 65 int status;
66 66
67 switch (urb->status) { 67 switch (urb->status) {
@@ -115,14 +115,14 @@ static void usb_mouse_close(struct input_dev *dev)
115 usb_kill_urb(mouse->irq); 115 usb_kill_urb(mouse->irq);
116} 116}
117 117
118static int usb_mouse_probe(struct usb_interface * intf, const struct usb_device_id * id) 118static int usb_mouse_probe(struct usb_interface *intf, const struct usb_device_id *id)
119{ 119{
120 struct usb_device * dev = interface_to_usbdev(intf); 120 struct usb_device *dev = interface_to_usbdev(intf);
121 struct usb_host_interface *interface; 121 struct usb_host_interface *interface;
122 struct usb_endpoint_descriptor *endpoint; 122 struct usb_endpoint_descriptor *endpoint;
123 struct usb_mouse *mouse; 123 struct usb_mouse *mouse;
124 struct input_dev *input_dev;
124 int pipe, maxp; 125 int pipe, maxp;
125 char path[64];
126 126
127 interface = intf->cur_altsetting; 127 interface = intf->cur_altsetting;
128 128
@@ -130,59 +130,62 @@ static int usb_mouse_probe(struct usb_interface * intf, const struct usb_device_
130 return -ENODEV; 130 return -ENODEV;
131 131
132 endpoint = &interface->endpoint[0].desc; 132 endpoint = &interface->endpoint[0].desc;
133 if (!(endpoint->bEndpointAddress & 0x80)) 133 if (!(endpoint->bEndpointAddress & USB_DIR_IN))
134 return -ENODEV; 134 return -ENODEV;
135 if ((endpoint->bmAttributes & 3) != 3) 135 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT)
136 return -ENODEV; 136 return -ENODEV;
137 137
138 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); 138 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
139 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); 139 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
140 140
141 if (!(mouse = kmalloc(sizeof(struct usb_mouse), GFP_KERNEL))) 141 mouse = kzalloc(sizeof(struct usb_mouse), GFP_KERNEL);
142 return -ENOMEM; 142 input_dev = input_allocate_device();
143 memset(mouse, 0, sizeof(struct usb_mouse)); 143 if (!mouse || !input_dev)
144 goto fail1;
144 145
145 mouse->data = usb_buffer_alloc(dev, 8, SLAB_ATOMIC, &mouse->data_dma); 146 mouse->data = usb_buffer_alloc(dev, 8, SLAB_ATOMIC, &mouse->data_dma);
146 if (!mouse->data) { 147 if (!mouse->data)
147 kfree(mouse); 148 goto fail1;
148 return -ENOMEM;
149 }
150 149
151 mouse->irq = usb_alloc_urb(0, GFP_KERNEL); 150 mouse->irq = usb_alloc_urb(0, GFP_KERNEL);
152 if (!mouse->irq) { 151 if (!mouse->irq)
153 usb_buffer_free(dev, 8, mouse->data, mouse->data_dma); 152 goto fail2;
154 kfree(mouse);
155 return -ENODEV;
156 }
157 153
158 mouse->usbdev = dev; 154 mouse->usbdev = dev;
155 mouse->dev = input_dev;
156
157 if (dev->manufacturer)
158 strlcpy(mouse->name, dev->manufacturer, sizeof(mouse->name));
159 159
160 mouse->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL); 160 if (dev->product) {
161 mouse->dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); 161 if (dev->manufacturer)
162 mouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y); 162 strlcat(mouse->name, " ", sizeof(mouse->name));
163 mouse->dev.keybit[LONG(BTN_MOUSE)] |= BIT(BTN_SIDE) | BIT(BTN_EXTRA); 163 strlcat(mouse->name, dev->product, sizeof(mouse->name));
164 mouse->dev.relbit[0] |= BIT(REL_WHEEL); 164 }
165 165
166 mouse->dev.private = mouse; 166 if (!strlen(mouse->name))
167 mouse->dev.open = usb_mouse_open; 167 snprintf(mouse->name, sizeof(mouse->name),
168 mouse->dev.close = usb_mouse_close; 168 "USB HIDBP Mouse %04x:%04x",
169 le16_to_cpu(dev->descriptor.idVendor),
170 le16_to_cpu(dev->descriptor.idProduct));
169 171
170 usb_make_path(dev, path, 64); 172 usb_make_path(dev, mouse->phys, sizeof(mouse->phys));
171 sprintf(mouse->phys, "%s/input0", path); 173 strlcat(mouse->phys, "/input0", sizeof(mouse->phys));
172 174
173 mouse->dev.name = mouse->name; 175 input_dev->name = mouse->name;
174 mouse->dev.phys = mouse->phys; 176 input_dev->phys = mouse->phys;
175 usb_to_input_id(dev, &mouse->dev.id); 177 usb_to_input_id(dev, &input_dev->id);
176 mouse->dev.dev = &intf->dev; 178 input_dev->cdev.dev = &intf->dev;
177 179
178 if (dev->manufacturer) 180 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
179 strcat(mouse->name, dev->manufacturer); 181 input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
180 if (dev->product) 182 input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
181 sprintf(mouse->name, "%s %s", mouse->name, dev->product); 183 input_dev->keybit[LONG(BTN_MOUSE)] |= BIT(BTN_SIDE) | BIT(BTN_EXTRA);
184 input_dev->relbit[0] |= BIT(REL_WHEEL);
182 185
183 if (!strlen(mouse->name)) 186 input_dev->private = mouse;
184 sprintf(mouse->name, "USB HIDBP Mouse %04x:%04x", 187 input_dev->open = usb_mouse_open;
185 mouse->dev.id.vendor, mouse->dev.id.product); 188 input_dev->close = usb_mouse_close;
186 189
187 usb_fill_int_urb(mouse->irq, dev, pipe, mouse->data, 190 usb_fill_int_urb(mouse->irq, dev, pipe, mouse->data,
188 (maxp > 8 ? 8 : maxp), 191 (maxp > 8 ? 8 : maxp),
@@ -190,11 +193,15 @@ static int usb_mouse_probe(struct usb_interface * intf, const struct usb_device_
190 mouse->irq->transfer_dma = mouse->data_dma; 193 mouse->irq->transfer_dma = mouse->data_dma;
191 mouse->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 194 mouse->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
192 195
193 input_register_device(&mouse->dev); 196 input_register_device(mouse->dev);
194 printk(KERN_INFO "input: %s on %s\n", mouse->name, path);
195 197
196 usb_set_intfdata(intf, mouse); 198 usb_set_intfdata(intf, mouse);
197 return 0; 199 return 0;
200
201fail2: usb_buffer_free(dev, 8, mouse->data, mouse->data_dma);
202fail1: input_free_device(input_dev);
203 kfree(mouse);
204 return -ENOMEM;
198} 205}
199 206
200static void usb_mouse_disconnect(struct usb_interface *intf) 207static void usb_mouse_disconnect(struct usb_interface *intf)
@@ -204,7 +211,7 @@ static void usb_mouse_disconnect(struct usb_interface *intf)
204 usb_set_intfdata(intf, NULL); 211 usb_set_intfdata(intf, NULL);
205 if (mouse) { 212 if (mouse) {
206 usb_kill_urb(mouse->irq); 213 usb_kill_urb(mouse->irq);
207 input_unregister_device(&mouse->dev); 214 input_unregister_device(mouse->dev);
208 usb_free_urb(mouse->irq); 215 usb_free_urb(mouse->irq);
209 usb_buffer_free(interface_to_usbdev(intf), 8, mouse->data, mouse->data_dma); 216 usb_buffer_free(interface_to_usbdev(intf), 8, mouse->data, mouse->data_dma);
210 kfree(mouse); 217 kfree(mouse);
diff --git a/drivers/usb/input/wacom.c b/drivers/usb/input/wacom.c
index 3b266af3048a..ea0f75773ae1 100644
--- a/drivers/usb/input/wacom.c
+++ b/drivers/usb/input/wacom.c
@@ -111,7 +111,7 @@ struct wacom_features {
111struct wacom { 111struct wacom {
112 signed char *data; 112 signed char *data;
113 dma_addr_t data_dma; 113 dma_addr_t data_dma;
114 struct input_dev dev; 114 struct input_dev *dev;
115 struct usb_device *usbdev; 115 struct usb_device *usbdev;
116 struct urb *irq; 116 struct urb *irq;
117 struct wacom_features *features; 117 struct wacom_features *features;
@@ -135,7 +135,7 @@ static void wacom_pl_irq(struct urb *urb, struct pt_regs *regs)
135{ 135{
136 struct wacom *wacom = urb->context; 136 struct wacom *wacom = urb->context;
137 unsigned char *data = wacom->data; 137 unsigned char *data = wacom->data;
138 struct input_dev *dev = &wacom->dev; 138 struct input_dev *dev = wacom->dev;
139 int prox, pressure; 139 int prox, pressure;
140 int retval; 140 int retval;
141 141
@@ -225,7 +225,7 @@ static void wacom_ptu_irq(struct urb *urb, struct pt_regs *regs)
225{ 225{
226 struct wacom *wacom = urb->context; 226 struct wacom *wacom = urb->context;
227 unsigned char *data = wacom->data; 227 unsigned char *data = wacom->data;
228 struct input_dev *dev = &wacom->dev; 228 struct input_dev *dev = wacom->dev;
229 int retval; 229 int retval;
230 230
231 switch (urb->status) { 231 switch (urb->status) {
@@ -275,7 +275,7 @@ static void wacom_penpartner_irq(struct urb *urb, struct pt_regs *regs)
275{ 275{
276 struct wacom *wacom = urb->context; 276 struct wacom *wacom = urb->context;
277 unsigned char *data = wacom->data; 277 unsigned char *data = wacom->data;
278 struct input_dev *dev = &wacom->dev; 278 struct input_dev *dev = wacom->dev;
279 int retval; 279 int retval;
280 280
281 switch (urb->status) { 281 switch (urb->status) {
@@ -318,7 +318,7 @@ static void wacom_graphire_irq(struct urb *urb, struct pt_regs *regs)
318{ 318{
319 struct wacom *wacom = urb->context; 319 struct wacom *wacom = urb->context;
320 unsigned char *data = wacom->data; 320 unsigned char *data = wacom->data;
321 struct input_dev *dev = &wacom->dev; 321 struct input_dev *dev = wacom->dev;
322 int x, y; 322 int x, y;
323 int retval; 323 int retval;
324 324
@@ -397,7 +397,7 @@ static int wacom_intuos_inout(struct urb *urb)
397{ 397{
398 struct wacom *wacom = urb->context; 398 struct wacom *wacom = urb->context;
399 unsigned char *data = wacom->data; 399 unsigned char *data = wacom->data;
400 struct input_dev *dev = &wacom->dev; 400 struct input_dev *dev = wacom->dev;
401 int idx; 401 int idx;
402 402
403 /* tool number */ 403 /* tool number */
@@ -479,7 +479,7 @@ static void wacom_intuos_general(struct urb *urb)
479{ 479{
480 struct wacom *wacom = urb->context; 480 struct wacom *wacom = urb->context;
481 unsigned char *data = wacom->data; 481 unsigned char *data = wacom->data;
482 struct input_dev *dev = &wacom->dev; 482 struct input_dev *dev = wacom->dev;
483 unsigned int t; 483 unsigned int t;
484 484
485 /* general pen packet */ 485 /* general pen packet */
@@ -509,7 +509,7 @@ static void wacom_intuos_irq(struct urb *urb, struct pt_regs *regs)
509{ 509{
510 struct wacom *wacom = urb->context; 510 struct wacom *wacom = urb->context;
511 unsigned char *data = wacom->data; 511 unsigned char *data = wacom->data;
512 struct input_dev *dev = &wacom->dev; 512 struct input_dev *dev = wacom->dev;
513 unsigned int t; 513 unsigned int t;
514 int idx; 514 int idx;
515 int retval; 515 int retval;
@@ -738,95 +738,83 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
738{ 738{
739 struct usb_device *dev = interface_to_usbdev(intf); 739 struct usb_device *dev = interface_to_usbdev(intf);
740 struct usb_endpoint_descriptor *endpoint; 740 struct usb_endpoint_descriptor *endpoint;
741 char rep_data[2] = {0x02, 0x02};
742 struct wacom *wacom; 741 struct wacom *wacom;
743 char path[64]; 742 struct input_dev *input_dev;
743 char rep_data[2] = {0x02, 0x02};
744 744
745 if (!(wacom = kmalloc(sizeof(struct wacom), GFP_KERNEL))) 745 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
746 return -ENOMEM; 746 input_dev = input_allocate_device();
747 memset(wacom, 0, sizeof(struct wacom)); 747 if (!wacom || !input_dev)
748 goto fail1;
748 749
749 wacom->data = usb_buffer_alloc(dev, 10, GFP_KERNEL, &wacom->data_dma); 750 wacom->data = usb_buffer_alloc(dev, 10, GFP_KERNEL, &wacom->data_dma);
750 if (!wacom->data) { 751 if (!wacom->data)
751 kfree(wacom); 752 goto fail1;
752 return -ENOMEM;
753 }
754 753
755 wacom->irq = usb_alloc_urb(0, GFP_KERNEL); 754 wacom->irq = usb_alloc_urb(0, GFP_KERNEL);
756 if (!wacom->irq) { 755 if (!wacom->irq)
757 usb_buffer_free(dev, 10, wacom->data, wacom->data_dma); 756 goto fail2;
758 kfree(wacom); 757
759 return -ENOMEM; 758 wacom->usbdev = dev;
760 } 759 wacom->dev = input_dev;
760 usb_make_path(dev, wacom->phys, sizeof(wacom->phys));
761 strlcat(wacom->phys, "/input0", sizeof(wacom->phys));
761 762
762 wacom->features = wacom_features + (id - wacom_ids); 763 wacom->features = wacom_features + (id - wacom_ids);
764 if (wacom->features->pktlen > 10)
765 BUG();
766
767 input_dev->name = wacom->features->name;
768 usb_to_input_id(dev, &input_dev->id);
763 769
764 wacom->dev.evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS); 770 input_dev->cdev.dev = &intf->dev;
765 wacom->dev.absbit[0] |= BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE); 771 input_dev->private = wacom;
766 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | BIT(BTN_TOUCH) | BIT(BTN_STYLUS); 772 input_dev->open = wacom_open;
773 input_dev->close = wacom_close;
774
775 input_dev->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS);
776 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_PEN) | BIT(BTN_TOUCH) | BIT(BTN_STYLUS);
777 input_set_abs_params(input_dev, ABS_X, 0, wacom->features->y_max, 4, 0);
778 input_set_abs_params(input_dev, ABS_Y, 0, wacom->features->y_max, 4, 0);
779 input_set_abs_params(input_dev, ABS_PRESSURE, 0, wacom->features->pressure_max, 0, 0);
767 780
768 switch (wacom->features->type) { 781 switch (wacom->features->type) {
769 case GRAPHIRE: 782 case GRAPHIRE:
770 wacom->dev.evbit[0] |= BIT(EV_REL); 783 input_dev->evbit[0] |= BIT(EV_REL);
771 wacom->dev.relbit[0] |= BIT(REL_WHEEL); 784 input_dev->relbit[0] |= BIT(REL_WHEEL);
772 wacom->dev.absbit[0] |= BIT(ABS_DISTANCE); 785 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
773 wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); 786 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_STYLUS2);
774 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_STYLUS2); 787 input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom->features->distance_max, 0, 0);
775 break; 788 break;
776 789
777 case INTUOS3: 790 case INTUOS3:
778 case CINTIQ: 791 case CINTIQ:
779 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER); 792 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER);
780 wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_0) | BIT(BTN_1) | BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4) | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7); 793 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_0) | BIT(BTN_1) | BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4) | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7);
781 wacom->dev.absbit[0] |= BIT(ABS_RX) | BIT(ABS_RY); 794 input_set_abs_params(input_dev, ABS_RX, 0, 4097, 0, 0);
795 input_set_abs_params(input_dev, ABS_RY, 0, 4097, 0, 0);
782 /* fall through */ 796 /* fall through */
783 797
784 case INTUOS: 798 case INTUOS:
785 wacom->dev.evbit[0] |= BIT(EV_MSC) | BIT(EV_REL); 799 input_dev->evbit[0] |= BIT(EV_MSC) | BIT(EV_REL);
786 wacom->dev.mscbit[0] |= BIT(MSC_SERIAL); 800 input_dev->mscbit[0] |= BIT(MSC_SERIAL);
787 wacom->dev.relbit[0] |= BIT(REL_WHEEL); 801 input_dev->relbit[0] |= BIT(REL_WHEEL);
788 wacom->dev.keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE) | BIT(BTN_SIDE) | BIT(BTN_EXTRA); 802 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE) | BIT(BTN_SIDE) | BIT(BTN_EXTRA);
789 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_TOOL_BRUSH) 803 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_RUBBER) | BIT(BTN_TOOL_MOUSE) | BIT(BTN_TOOL_BRUSH)
790 | BIT(BTN_TOOL_PENCIL) | BIT(BTN_TOOL_AIRBRUSH) | BIT(BTN_TOOL_LENS) | BIT(BTN_STYLUS2); 804 | BIT(BTN_TOOL_PENCIL) | BIT(BTN_TOOL_AIRBRUSH) | BIT(BTN_TOOL_LENS) | BIT(BTN_STYLUS2);
791 wacom->dev.absbit[0] |= BIT(ABS_DISTANCE) | BIT(ABS_WHEEL) | BIT(ABS_TILT_X) | BIT(ABS_TILT_Y) | BIT(ABS_RZ) | BIT(ABS_THROTTLE); 805 input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom->features->distance_max, 0, 0);
806 input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
807 input_set_abs_params(input_dev, ABS_TILT_X, 0, 127, 0, 0);
808 input_set_abs_params(input_dev, ABS_TILT_Y, 0, 127, 0, 0);
809 input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
810 input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
792 break; 811 break;
793 812
794 case PL: 813 case PL:
795 wacom->dev.keybit[LONG(BTN_DIGI)] |= BIT(BTN_STYLUS2) | BIT(BTN_TOOL_RUBBER); 814 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_STYLUS2) | BIT(BTN_TOOL_RUBBER);
796 break; 815 break;
797 } 816 }
798 817
799 wacom->dev.absmax[ABS_X] = wacom->features->x_max;
800 wacom->dev.absmax[ABS_Y] = wacom->features->y_max;
801 wacom->dev.absmax[ABS_PRESSURE] = wacom->features->pressure_max;
802 wacom->dev.absmax[ABS_DISTANCE] = wacom->features->distance_max;
803 wacom->dev.absmax[ABS_TILT_X] = 127;
804 wacom->dev.absmax[ABS_TILT_Y] = 127;
805 wacom->dev.absmax[ABS_WHEEL] = 1023;
806
807 wacom->dev.absmax[ABS_RX] = 4097;
808 wacom->dev.absmax[ABS_RY] = 4097;
809 wacom->dev.absmin[ABS_RZ] = -900;
810 wacom->dev.absmax[ABS_RZ] = 899;
811 wacom->dev.absmin[ABS_THROTTLE] = -1023;
812 wacom->dev.absmax[ABS_THROTTLE] = 1023;
813
814 wacom->dev.absfuzz[ABS_X] = 4;
815 wacom->dev.absfuzz[ABS_Y] = 4;
816
817 wacom->dev.private = wacom;
818 wacom->dev.open = wacom_open;
819 wacom->dev.close = wacom_close;
820
821 usb_make_path(dev, path, 64);
822 sprintf(wacom->phys, "%s/input0", path);
823
824 wacom->dev.name = wacom->features->name;
825 wacom->dev.phys = wacom->phys;
826 usb_to_input_id(dev, &wacom->dev.id);
827 wacom->dev.dev = &intf->dev;
828 wacom->usbdev = dev;
829
830 endpoint = &intf->cur_altsetting->endpoint[0].desc; 818 endpoint = &intf->cur_altsetting->endpoint[0].desc;
831 819
832 if (wacom->features->pktlen > 10) 820 if (wacom->features->pktlen > 10)
@@ -839,18 +827,20 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
839 wacom->irq->transfer_dma = wacom->data_dma; 827 wacom->irq->transfer_dma = wacom->data_dma;
840 wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 828 wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
841 829
842 input_register_device(&wacom->dev); 830 input_register_device(wacom->dev);
843 831
844 /* ask the tablet to report tablet data */ 832 /* ask the tablet to report tablet data */
845 usb_set_report(intf, 3, 2, rep_data, 2); 833 usb_set_report(intf, 3, 2, rep_data, 2);
846 /* repeat once (not sure why the first call often fails) */ 834 /* repeat once (not sure why the first call often fails) */
847 usb_set_report(intf, 3, 2, rep_data, 2); 835 usb_set_report(intf, 3, 2, rep_data, 2);
848 836
849 printk(KERN_INFO "input: %s on %s\n", wacom->features->name, path);
850
851 usb_set_intfdata(intf, wacom); 837 usb_set_intfdata(intf, wacom);
852
853 return 0; 838 return 0;
839
840fail2: usb_buffer_free(dev, 10, wacom->data, wacom->data_dma);
841fail1: input_free_device(input_dev);
842 kfree(wacom);
843 return -ENOMEM;
854} 844}
855 845
856static void wacom_disconnect(struct usb_interface *intf) 846static void wacom_disconnect(struct usb_interface *intf)
@@ -860,7 +850,7 @@ static void wacom_disconnect(struct usb_interface *intf)
860 usb_set_intfdata(intf, NULL); 850 usb_set_intfdata(intf, NULL);
861 if (wacom) { 851 if (wacom) {
862 usb_kill_urb(wacom->irq); 852 usb_kill_urb(wacom->irq);
863 input_unregister_device(&wacom->dev); 853 input_unregister_device(wacom->dev);
864 usb_free_urb(wacom->irq); 854 usb_free_urb(wacom->irq);
865 usb_buffer_free(interface_to_usbdev(intf), 10, wacom->data, wacom->data_dma); 855 usb_buffer_free(interface_to_usbdev(intf), 10, wacom->data, wacom->data_dma);
866 kfree(wacom); 856 kfree(wacom);
diff --git a/drivers/usb/input/xpad.c b/drivers/usb/input/xpad.c
index 18125e0bffa2..43112f040b6d 100644
--- a/drivers/usb/input/xpad.c
+++ b/drivers/usb/input/xpad.c
@@ -103,7 +103,7 @@ static struct usb_device_id xpad_table [] = {
103MODULE_DEVICE_TABLE (usb, xpad_table); 103MODULE_DEVICE_TABLE (usb, xpad_table);
104 104
105struct usb_xpad { 105struct usb_xpad {
106 struct input_dev dev; /* input device interface */ 106 struct input_dev *dev; /* input device interface */
107 struct usb_device *udev; /* usb device */ 107 struct usb_device *udev; /* usb device */
108 108
109 struct urb *irq_in; /* urb for interrupt in report */ 109 struct urb *irq_in; /* urb for interrupt in report */
@@ -125,7 +125,7 @@ struct usb_xpad {
125 125
126static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data, struct pt_regs *regs) 126static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data, struct pt_regs *regs)
127{ 127{
128 struct input_dev *dev = &xpad->dev; 128 struct input_dev *dev = xpad->dev;
129 129
130 input_regs(dev, regs); 130 input_regs(dev, regs);
131 131
@@ -214,9 +214,9 @@ static void xpad_close (struct input_dev *dev)
214static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id) 214static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id)
215{ 215{
216 struct usb_device *udev = interface_to_usbdev (intf); 216 struct usb_device *udev = interface_to_usbdev (intf);
217 struct usb_xpad *xpad = NULL; 217 struct usb_xpad *xpad;
218 struct input_dev *input_dev;
218 struct usb_endpoint_descriptor *ep_irq_in; 219 struct usb_endpoint_descriptor *ep_irq_in;
219 char path[64];
220 int i; 220 int i;
221 221
222 for (i = 0; xpad_device[i].idVendor; i++) { 222 for (i = 0; xpad_device[i].idVendor; i++) {
@@ -225,89 +225,80 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
225 break; 225 break;
226 } 226 }
227 227
228 if ((xpad = kmalloc (sizeof(struct usb_xpad), GFP_KERNEL)) == NULL) { 228 xpad = kzalloc(sizeof(struct usb_xpad), GFP_KERNEL);
229 err("cannot allocate memory for new pad"); 229 input_dev = input_allocate_device();
230 return -ENOMEM; 230 if (!xpad || !input_dev)
231 } 231 goto fail1;
232 memset(xpad, 0, sizeof(struct usb_xpad));
233 232
234 xpad->idata = usb_buffer_alloc(udev, XPAD_PKT_LEN, 233 xpad->idata = usb_buffer_alloc(udev, XPAD_PKT_LEN,
235 SLAB_ATOMIC, &xpad->idata_dma); 234 SLAB_ATOMIC, &xpad->idata_dma);
236 if (!xpad->idata) { 235 if (!xpad->idata)
237 kfree(xpad); 236 goto fail1;
238 return -ENOMEM;
239 }
240 237
241 xpad->irq_in = usb_alloc_urb(0, GFP_KERNEL); 238 xpad->irq_in = usb_alloc_urb(0, GFP_KERNEL);
242 if (!xpad->irq_in) { 239 if (!xpad->irq_in)
243 err("cannot allocate memory for new pad irq urb"); 240 goto fail2;
244 usb_buffer_free(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma);
245 kfree(xpad);
246 return -ENOMEM;
247 }
248
249 ep_irq_in = &intf->cur_altsetting->endpoint[0].desc;
250
251 usb_fill_int_urb(xpad->irq_in, udev,
252 usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress),
253 xpad->idata, XPAD_PKT_LEN, xpad_irq_in,
254 xpad, ep_irq_in->bInterval);
255 xpad->irq_in->transfer_dma = xpad->idata_dma;
256 xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
257 241
258 xpad->udev = udev; 242 xpad->udev = udev;
243 xpad->dev = input_dev;
244 usb_make_path(udev, xpad->phys, sizeof(xpad->phys));
245 strlcat(xpad->phys, "/input0", sizeof(xpad->phys));
259 246
260 usb_to_input_id(udev, &xpad->dev.id); 247 input_dev->name = xpad_device[i].name;
261 xpad->dev.dev = &intf->dev; 248 input_dev->phys = xpad->phys;
262 xpad->dev.private = xpad; 249 usb_to_input_id(udev, &input_dev->id);
263 xpad->dev.name = xpad_device[i].name; 250 input_dev->cdev.dev = &intf->dev;
264 xpad->dev.phys = xpad->phys; 251 input_dev->private = xpad;
265 xpad->dev.open = xpad_open; 252 input_dev->open = xpad_open;
266 xpad->dev.close = xpad_close; 253 input_dev->close = xpad_close;
267
268 usb_make_path(udev, path, 64);
269 snprintf(xpad->phys, 64, "%s/input0", path);
270 254
271 xpad->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 255 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
272 256
273 for (i = 0; xpad_btn[i] >= 0; i++) 257 for (i = 0; xpad_btn[i] >= 0; i++)
274 set_bit(xpad_btn[i], xpad->dev.keybit); 258 set_bit(xpad_btn[i], input_dev->keybit);
275 259
276 for (i = 0; xpad_abs[i] >= 0; i++) { 260 for (i = 0; xpad_abs[i] >= 0; i++) {
277 261
278 signed short t = xpad_abs[i]; 262 signed short t = xpad_abs[i];
279 263
280 set_bit(t, xpad->dev.absbit); 264 set_bit(t, input_dev->absbit);
281 265
282 switch (t) { 266 switch (t) {
283 case ABS_X: 267 case ABS_X:
284 case ABS_Y: 268 case ABS_Y:
285 case ABS_RX: 269 case ABS_RX:
286 case ABS_RY: /* the two sticks */ 270 case ABS_RY: /* the two sticks */
287 xpad->dev.absmax[t] = 32767; 271 input_set_abs_params(input_dev, t, -32768, 32767, 16, 128);
288 xpad->dev.absmin[t] = -32768;
289 xpad->dev.absflat[t] = 128;
290 xpad->dev.absfuzz[t] = 16;
291 break; 272 break;
292 case ABS_Z: 273 case ABS_Z:
293 case ABS_RZ: /* the triggers */ 274 case ABS_RZ: /* the triggers */
294 xpad->dev.absmax[t] = 255; 275 input_set_abs_params(input_dev, t, 0, 255, 0, 0);
295 xpad->dev.absmin[t] = 0;
296 break; 276 break;
297 case ABS_HAT0X: 277 case ABS_HAT0X:
298 case ABS_HAT0Y: /* the d-pad */ 278 case ABS_HAT0Y: /* the d-pad */
299 xpad->dev.absmax[t] = 1; 279 input_set_abs_params(input_dev, t, -1, 1, 0, 0);
300 xpad->dev.absmin[t] = -1;
301 break; 280 break;
302 } 281 }
303 } 282 }
304 283
305 input_register_device(&xpad->dev); 284 ep_irq_in = &intf->cur_altsetting->endpoint[0].desc;
285 usb_fill_int_urb(xpad->irq_in, udev,
286 usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress),
287 xpad->idata, XPAD_PKT_LEN, xpad_irq_in,
288 xpad, ep_irq_in->bInterval);
289 xpad->irq_in->transfer_dma = xpad->idata_dma;
290 xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
306 291
307 printk(KERN_INFO "input: %s on %s", xpad->dev.name, path); 292 input_register_device(xpad->dev);
308 293
309 usb_set_intfdata(intf, xpad); 294 usb_set_intfdata(intf, xpad);
310 return 0; 295 return 0;
296
297fail2: usb_buffer_free(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma);
298fail1: input_free_device(input_dev);
299 kfree(xpad);
300 return -ENOMEM;
301
311} 302}
312 303
313static void xpad_disconnect(struct usb_interface *intf) 304static void xpad_disconnect(struct usb_interface *intf)
@@ -317,7 +308,7 @@ static void xpad_disconnect(struct usb_interface *intf)
317 usb_set_intfdata(intf, NULL); 308 usb_set_intfdata(intf, NULL);
318 if (xpad) { 309 if (xpad) {
319 usb_kill_urb(xpad->irq_in); 310 usb_kill_urb(xpad->irq_in);
320 input_unregister_device(&xpad->dev); 311 input_unregister_device(xpad->dev);
321 usb_free_urb(xpad->irq_in); 312 usb_free_urb(xpad->irq_in);
322 usb_buffer_free(interface_to_usbdev(intf), XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); 313 usb_buffer_free(interface_to_usbdev(intf), XPAD_PKT_LEN, xpad->idata, xpad->idata_dma);
323 kfree(xpad); 314 kfree(xpad);
diff --git a/drivers/usb/input/yealink.c b/drivers/usb/input/yealink.c
index 58a176ef96a5..f526aebea502 100644
--- a/drivers/usb/input/yealink.c
+++ b/drivers/usb/input/yealink.c
@@ -54,6 +54,7 @@
54#include <linux/module.h> 54#include <linux/module.h>
55#include <linux/rwsem.h> 55#include <linux/rwsem.h>
56#include <linux/usb.h> 56#include <linux/usb.h>
57#include <linux/usb_input.h>
57 58
58#include "map_to_7segment.h" 59#include "map_to_7segment.h"
59#include "yealink.h" 60#include "yealink.h"
@@ -101,12 +102,12 @@ static const struct lcd_segment_map {
101}; 102};
102 103
103struct yealink_dev { 104struct yealink_dev {
104 struct input_dev idev; /* input device */ 105 struct input_dev *idev; /* input device */
105 struct usb_device *udev; /* usb device */ 106 struct usb_device *udev; /* usb device */
106 107
107 /* irq input channel */ 108 /* irq input channel */
108 struct yld_ctl_packet *irq_data; 109 struct yld_ctl_packet *irq_data;
109 dma_addr_t irq_dma; 110 dma_addr_t irq_dma;
110 struct urb *urb_irq; 111 struct urb *urb_irq;
111 112
112 /* control output channel */ 113 /* control output channel */
@@ -237,7 +238,7 @@ static int map_p1k_to_key(int scancode)
237 */ 238 */
238static void report_key(struct yealink_dev *yld, int key, struct pt_regs *regs) 239static void report_key(struct yealink_dev *yld, int key, struct pt_regs *regs)
239{ 240{
240 struct input_dev *idev = &yld->idev; 241 struct input_dev *idev = yld->idev;
241 242
242 input_regs(idev, regs); 243 input_regs(idev, regs);
243 if (yld->key_code >= 0) { 244 if (yld->key_code >= 0) {
@@ -809,8 +810,12 @@ static int usb_cleanup(struct yealink_dev *yld, int err)
809 } 810 }
810 if (yld->urb_ctl) 811 if (yld->urb_ctl)
811 usb_free_urb(yld->urb_ctl); 812 usb_free_urb(yld->urb_ctl);
812 if (yld->idev.dev) 813 if (yld->idev) {
813 input_unregister_device(&yld->idev); 814 if (err)
815 input_free_device(yld->idev);
816 else
817 input_unregister_device(yld->idev);
818 }
814 if (yld->ctl_req) 819 if (yld->ctl_req)
815 usb_buffer_free(yld->udev, sizeof(*(yld->ctl_req)), 820 usb_buffer_free(yld->udev, sizeof(*(yld->ctl_req)),
816 yld->ctl_req, yld->ctl_req_dma); 821 yld->ctl_req, yld->ctl_req_dma);
@@ -857,7 +862,7 @@ static int usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
857 struct usb_host_interface *interface; 862 struct usb_host_interface *interface;
858 struct usb_endpoint_descriptor *endpoint; 863 struct usb_endpoint_descriptor *endpoint;
859 struct yealink_dev *yld; 864 struct yealink_dev *yld;
860 char path[64]; 865 struct input_dev *input_dev;
861 int ret, pipe, i; 866 int ret, pipe, i;
862 867
863 i = usb_match(udev); 868 i = usb_match(udev);
@@ -866,17 +871,21 @@ static int usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
866 871
867 interface = intf->cur_altsetting; 872 interface = intf->cur_altsetting;
868 endpoint = &interface->endpoint[0].desc; 873 endpoint = &interface->endpoint[0].desc;
869 if (!(endpoint->bEndpointAddress & 0x80)) 874 if (!(endpoint->bEndpointAddress & USB_DIR_IN))
870 return -EIO; 875 return -EIO;
871 if ((endpoint->bmAttributes & 3) != 3) 876 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT)
872 return -EIO; 877 return -EIO;
873 878
874 if ((yld = kmalloc(sizeof(struct yealink_dev), GFP_KERNEL)) == NULL) 879 yld = kzalloc(sizeof(struct yealink_dev), GFP_KERNEL);
880 if (!yld)
875 return -ENOMEM; 881 return -ENOMEM;
876 882
877 memset(yld, 0, sizeof(*yld));
878 yld->udev = udev; 883 yld->udev = udev;
879 884
885 yld->idev = input_dev = input_allocate_device();
886 if (!input_dev)
887 return usb_cleanup(yld, -ENOMEM);
888
880 /* allocate usb buffers */ 889 /* allocate usb buffers */
881 yld->irq_data = usb_buffer_alloc(udev, USB_PKT_LEN, 890 yld->irq_data = usb_buffer_alloc(udev, USB_PKT_LEN,
882 SLAB_ATOMIC, &yld->irq_dma); 891 SLAB_ATOMIC, &yld->irq_dma);
@@ -935,42 +944,37 @@ static int usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
935 yld->urb_ctl->dev = udev; 944 yld->urb_ctl->dev = udev;
936 945
937 /* find out the physical bus location */ 946 /* find out the physical bus location */
938 if (usb_make_path(udev, path, sizeof(path)) > 0) 947 usb_make_path(udev, yld->phys, sizeof(yld->phys));
939 snprintf(yld->phys, sizeof(yld->phys)-1, "%s/input0", path); 948 strlcat(yld->phys, "/input0", sizeof(yld->phys));
940 949
941 /* register settings for the input device */ 950 /* register settings for the input device */
942 init_input_dev(&yld->idev); 951 input_dev->name = yld_device[i].name;
943 yld->idev.private = yld; 952 input_dev->phys = yld->phys;
944 yld->idev.id.bustype = BUS_USB; 953 usb_to_input_id(udev, &input_dev->id);
945 yld->idev.id.vendor = le16_to_cpu(udev->descriptor.idVendor); 954 input_dev->cdev.dev = &intf->dev;
946 yld->idev.id.product = le16_to_cpu(udev->descriptor.idProduct); 955
947 yld->idev.id.version = le16_to_cpu(udev->descriptor.bcdDevice); 956 input_dev->private = yld;
948 yld->idev.dev = &intf->dev; 957 input_dev->open = input_open;
949 yld->idev.name = yld_device[i].name; 958 input_dev->close = input_close;
950 yld->idev.phys = yld->phys; 959 /* input_dev->event = input_ev; TODO */
951 /* yld->idev.event = input_ev; TODO */
952 yld->idev.open = input_open;
953 yld->idev.close = input_close;
954 960
955 /* register available key events */ 961 /* register available key events */
956 yld->idev.evbit[0] = BIT(EV_KEY); 962 input_dev->evbit[0] = BIT(EV_KEY);
957 for (i = 0; i < 256; i++) { 963 for (i = 0; i < 256; i++) {
958 int k = map_p1k_to_key(i); 964 int k = map_p1k_to_key(i);
959 if (k >= 0) { 965 if (k >= 0) {
960 set_bit(k & 0xff, yld->idev.keybit); 966 set_bit(k & 0xff, input_dev->keybit);
961 if (k >> 8) 967 if (k >> 8)
962 set_bit(k >> 8, yld->idev.keybit); 968 set_bit(k >> 8, input_dev->keybit);
963 } 969 }
964 } 970 }
965 971
966 printk(KERN_INFO "input: %s on %s\n", yld->idev.name, path); 972 input_register_device(yld->idev);
967
968 input_register_device(&yld->idev);
969 973
970 usb_set_intfdata(intf, yld); 974 usb_set_intfdata(intf, yld);
971 975
972 /* clear visible elements */ 976 /* clear visible elements */
973 for (i=0; i<ARRAY_SIZE(lcdMap); i++) 977 for (i = 0; i < ARRAY_SIZE(lcdMap); i++)
974 setChar(yld, i, ' '); 978 setChar(yld, i, ' ');
975 979
976 /* display driver version on LCD line 3 */ 980 /* display driver version on LCD line 3 */
diff --git a/drivers/usb/media/dabusb.c b/drivers/usb/media/dabusb.c
index 6ca2fae99d2d..27b23c55bbc7 100644
--- a/drivers/usb/media/dabusb.c
+++ b/drivers/usb/media/dabusb.c
@@ -707,9 +707,8 @@ static struct file_operations dabusb_fops =
707}; 707};
708 708
709static struct usb_class_driver dabusb_class = { 709static struct usb_class_driver dabusb_class = {
710 .name = "usb/dabusb%d", 710 .name = "dabusb%d",
711 .fops = &dabusb_fops, 711 .fops = &dabusb_fops,
712 .mode = S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
713 .minor_base = DABUSB_MINOR, 712 .minor_base = DABUSB_MINOR,
714}; 713};
715 714
diff --git a/drivers/usb/media/konicawc.c b/drivers/usb/media/konicawc.c
index 20ac9e1069d4..9fe2c2710d13 100644
--- a/drivers/usb/media/konicawc.c
+++ b/drivers/usb/media/konicawc.c
@@ -119,7 +119,7 @@ struct konicawc {
119 int yplanesz; /* Number of bytes in the Y plane */ 119 int yplanesz; /* Number of bytes in the Y plane */
120 unsigned int buttonsts:1; 120 unsigned int buttonsts:1;
121#ifdef CONFIG_INPUT 121#ifdef CONFIG_INPUT
122 struct input_dev input; 122 struct input_dev *input;
123 char input_physname[64]; 123 char input_physname[64];
124#endif 124#endif
125}; 125};
@@ -218,6 +218,57 @@ static void konicawc_adjust_picture(struct uvd *uvd)
218 konicawc_camera_on(uvd); 218 konicawc_camera_on(uvd);
219} 219}
220 220
221#ifdef CONFIG_INPUT
222
223static void konicawc_register_input(struct konicawc *cam, struct usb_device *dev)
224{
225 struct input_dev *input_dev;
226
227 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
228 strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
229
230 cam->input = input_dev = input_allocate_device();
231 if (!input_dev) {
232 warn("Not enough memory for camera's input device\n");
233 return;
234 }
235
236 input_dev->name = "Konicawc snapshot button";
237 input_dev->phys = cam->input_physname;
238 usb_to_input_id(dev, &input_dev->id);
239 input_dev->cdev.dev = &dev->dev;
240
241 input_dev->evbit[0] = BIT(EV_KEY);
242 input_dev->keybit[LONG(BTN_0)] = BIT(BTN_0);
243
244 input_dev->private = cam;
245
246 input_register_device(cam->input);
247}
248
249static void konicawc_unregister_input(struct konicawc *cam)
250{
251 if (cam->input) {
252 input_unregister_device(cam->input);
253 cam->input = NULL;
254 }
255}
256
257static void konicawc_report_buttonstat(struct konicawc *cam)
258{
259 if (cam->input) {
260 input_report_key(cam->input, BTN_0, cam->buttonsts);
261 input_sync(cam->input);
262 }
263}
264
265#else
266
267static inline void konicawc_register_input(struct konicawc *cam, struct usb_device *dev) { }
268static inline void konicawc_unregister_input(struct konicawc *cam) { }
269static inline void konicawc_report_buttonstat(struct konicawc *cam) { }
270
271#endif /* CONFIG_INPUT */
221 272
222static int konicawc_compress_iso(struct uvd *uvd, struct urb *dataurb, struct urb *stsurb) 273static int konicawc_compress_iso(struct uvd *uvd, struct urb *dataurb, struct urb *stsurb)
223{ 274{
@@ -273,10 +324,7 @@ static int konicawc_compress_iso(struct uvd *uvd, struct urb *dataurb, struct ur
273 if(button != cam->buttonsts) { 324 if(button != cam->buttonsts) {
274 DEBUG(2, "button: %sclicked", button ? "" : "un"); 325 DEBUG(2, "button: %sclicked", button ? "" : "un");
275 cam->buttonsts = button; 326 cam->buttonsts = button;
276#ifdef CONFIG_INPUT 327 konicawc_report_buttonstat(cam);
277 input_report_key(&cam->input, BTN_0, cam->buttonsts);
278 input_sync(&cam->input);
279#endif
280 } 328 }
281 329
282 if(sts == 0x01) { /* drop frame */ 330 if(sts == 0x01) { /* drop frame */
@@ -645,9 +693,9 @@ static int konicawc_set_video_mode(struct uvd *uvd, struct video_window *vw)
645 RingQueue_Flush(&uvd->dp); 693 RingQueue_Flush(&uvd->dp);
646 cam->lastframe = -2; 694 cam->lastframe = -2;
647 if(uvd->curframe != -1) { 695 if(uvd->curframe != -1) {
648 uvd->frame[uvd->curframe].curline = 0; 696 uvd->frame[uvd->curframe].curline = 0;
649 uvd->frame[uvd->curframe].seqRead_Length = 0; 697 uvd->frame[uvd->curframe].seqRead_Length = 0;
650 uvd->frame[uvd->curframe].seqRead_Index = 0; 698 uvd->frame[uvd->curframe].seqRead_Index = 0;
651 } 699 }
652 700
653 konicawc_start_data(uvd); 701 konicawc_start_data(uvd);
@@ -718,7 +766,6 @@ static void konicawc_configure_video(struct uvd *uvd)
718 DEBUG(1, "setting initial values"); 766 DEBUG(1, "setting initial values");
719} 767}
720 768
721
722static int konicawc_probe(struct usb_interface *intf, const struct usb_device_id *devid) 769static int konicawc_probe(struct usb_interface *intf, const struct usb_device_id *devid)
723{ 770{
724 struct usb_device *dev = interface_to_usbdev(intf); 771 struct usb_device *dev = interface_to_usbdev(intf);
@@ -839,21 +886,8 @@ static int konicawc_probe(struct usb_interface *intf, const struct usb_device_id
839 err("usbvideo_RegisterVideoDevice() failed."); 886 err("usbvideo_RegisterVideoDevice() failed.");
840 uvd = NULL; 887 uvd = NULL;
841 } 888 }
842#ifdef CONFIG_INPUT 889
843 /* Register input device for button */ 890 konicawc_register_input(cam, dev);
844 memset(&cam->input, 0, sizeof(struct input_dev));
845 cam->input.name = "Konicawc snapshot button";
846 cam->input.private = cam;
847 cam->input.evbit[0] = BIT(EV_KEY);
848 cam->input.keybit[LONG(BTN_0)] = BIT(BTN_0);
849 usb_to_input_id(dev, &cam->input.id);
850 input_register_device(&cam->input);
851
852 usb_make_path(dev, cam->input_physname, 56);
853 strcat(cam->input_physname, "/input0");
854 cam->input.phys = cam->input_physname;
855 info("konicawc: %s on %s\n", cam->input.name, cam->input.phys);
856#endif
857 } 891 }
858 892
859 if (uvd) { 893 if (uvd) {
@@ -869,10 +903,9 @@ static void konicawc_free_uvd(struct uvd *uvd)
869 int i; 903 int i;
870 struct konicawc *cam = (struct konicawc *)uvd->user_data; 904 struct konicawc *cam = (struct konicawc *)uvd->user_data;
871 905
872#ifdef CONFIG_INPUT 906 konicawc_unregister_input(cam);
873 input_unregister_device(&cam->input); 907
874#endif 908 for (i = 0; i < USBVIDEO_NUMSBUF; i++) {
875 for (i=0; i < USBVIDEO_NUMSBUF; i++) {
876 usb_free_urb(cam->sts_urb[i]); 909 usb_free_urb(cam->sts_urb[i]);
877 cam->sts_urb[i] = NULL; 910 cam->sts_urb[i] = NULL;
878 } 911 }
diff --git a/drivers/usb/misc/auerswald.c b/drivers/usb/misc/auerswald.c
index ae4681f9f0ea..5f33f7c64885 100644
--- a/drivers/usb/misc/auerswald.c
+++ b/drivers/usb/misc/auerswald.c
@@ -1873,9 +1873,8 @@ static struct file_operations auerswald_fops =
1873}; 1873};
1874 1874
1875static struct usb_class_driver auerswald_class = { 1875static struct usb_class_driver auerswald_class = {
1876 .name = "usb/auer%d", 1876 .name = "auer%d",
1877 .fops = &auerswald_fops, 1877 .fops = &auerswald_fops,
1878 .mode = S_IFCHR | S_IRUGO | S_IWUGO,
1879 .minor_base = AUER_MINOR_BASE, 1878 .minor_base = AUER_MINOR_BASE,
1880}; 1879};
1881 1880
diff --git a/drivers/usb/misc/idmouse.c b/drivers/usb/misc/idmouse.c
index 733acc213726..1dc3e0f73014 100644
--- a/drivers/usb/misc/idmouse.c
+++ b/drivers/usb/misc/idmouse.c
@@ -105,11 +105,10 @@ static struct file_operations idmouse_fops = {
105 .release = idmouse_release, 105 .release = idmouse_release,
106}; 106};
107 107
108/* class driver information for devfs */ 108/* class driver information */
109static struct usb_class_driver idmouse_class = { 109static struct usb_class_driver idmouse_class = {
110 .name = "usb/idmouse%d", 110 .name = "idmouse%d",
111 .fops = &idmouse_fops, 111 .fops = &idmouse_fops,
112 .mode = S_IFCHR | S_IRUSR | S_IRGRP | S_IROTH, /* filemode (char, 444) */
113 .minor_base = USB_IDMOUSE_MINOR_BASE, 112 .minor_base = USB_IDMOUSE_MINOR_BASE,
114}; 113};
115 114
@@ -320,20 +319,8 @@ static ssize_t idmouse_read(struct file *file, char __user *buffer, size_t count
320 return -ENODEV; 319 return -ENODEV;
321 } 320 }
322 321
323 if (*ppos >= IMGSIZE) { 322 result = simple_read_from_buffer(buffer, count, ppos,
324 up (&dev->sem); 323 dev->bulk_in_buffer, IMGSIZE);
325 return 0;
326 }
327
328 count = min ((loff_t)count, IMGSIZE - (*ppos));
329
330 if (copy_to_user (buffer, dev->bulk_in_buffer + *ppos, count)) {
331 result = -EFAULT;
332 } else {
333 result = count;
334 *ppos += count;
335 }
336
337 /* unlock the device */ 324 /* unlock the device */
338 up(&dev->sem); 325 up(&dev->sem);
339 return result; 326 return result;
diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 7d06105763d4..2703e205bc8f 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -271,12 +271,11 @@ static struct file_operations tower_fops = {
271 271
272/* 272/*
273 * usb class driver info in order to get a minor number from the usb core, 273 * usb class driver info in order to get a minor number from the usb core,
274 * and to have the device registered with devfs and the driver core 274 * and to have the device registered with the driver core
275 */ 275 */
276static struct usb_class_driver tower_class = { 276static struct usb_class_driver tower_class = {
277 .name = "usb/legousbtower%d", 277 .name = "legousbtower%d",
278 .fops = &tower_fops, 278 .fops = &tower_fops,
279 .mode = S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH,
280 .minor_base = LEGO_USB_TOWER_MINOR_BASE, 279 .minor_base = LEGO_USB_TOWER_MINOR_BASE,
281}; 280};
282 281
diff --git a/drivers/usb/misc/rio500.c b/drivers/usb/misc/rio500.c
index 26f77e29c7a6..7d02d8ec6b1a 100644
--- a/drivers/usb/misc/rio500.c
+++ b/drivers/usb/misc/rio500.c
@@ -443,9 +443,8 @@ file_operations usb_rio_fops = {
443}; 443};
444 444
445static struct usb_class_driver usb_rio_class = { 445static struct usb_class_driver usb_rio_class = {
446 .name = "usb/rio500%d", 446 .name = "rio500%d",
447 .fops = &usb_rio_fops, 447 .fops = &usb_rio_fops,
448 .mode = S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
449 .minor_base = RIO_MINOR, 448 .minor_base = RIO_MINOR,
450}; 449};
451 450
diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c
index 39db3155723a..c946c9a538a0 100644
--- a/drivers/usb/misc/sisusbvga/sisusb.c
+++ b/drivers/usb/misc/sisusbvga/sisusb.c
@@ -2440,7 +2440,7 @@ int
2440sisusb_reset_text_mode(struct sisusb_usb_data *sisusb, int init) 2440sisusb_reset_text_mode(struct sisusb_usb_data *sisusb, int init)
2441{ 2441{
2442 int ret = 0, slot = sisusb->font_slot, i; 2442 int ret = 0, slot = sisusb->font_slot, i;
2443 struct font_desc *myfont; 2443 const struct font_desc *myfont;
2444 u8 *tempbuf; 2444 u8 *tempbuf;
2445 u16 *tempbufb; 2445 u16 *tempbufb;
2446 size_t written; 2446 size_t written;
@@ -3239,12 +3239,7 @@ static struct file_operations usb_sisusb_fops = {
3239}; 3239};
3240 3240
3241static struct usb_class_driver usb_sisusb_class = { 3241static struct usb_class_driver usb_sisusb_class = {
3242#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,13)
3243 .name = "usb/sisusbvga%d",
3244 .mode = S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
3245#else
3246 .name = "sisusbvga%d", 3242 .name = "sisusbvga%d",
3247#endif
3248 .fops = &usb_sisusb_fops, 3243 .fops = &usb_sisusb_fops,
3249 .minor_base = SISUSB_MINOR 3244 .minor_base = SISUSB_MINOR
3250}; 3245};
diff --git a/drivers/usb/misc/usblcd.c b/drivers/usb/misc/usblcd.c
index 096ab3029676..85f3725334b0 100644
--- a/drivers/usb/misc/usblcd.c
+++ b/drivers/usb/misc/usblcd.c
@@ -251,13 +251,12 @@ static struct file_operations lcd_fops = {
251}; 251};
252 252
253/* 253/*
254 * * usb class driver info in order to get a minor number from the usb core, 254 * usb class driver info in order to get a minor number from the usb core,
255 * * and to have the device registered with devfs and the driver core 255 * and to have the device registered with the driver core
256 * */ 256 */
257static struct usb_class_driver lcd_class = { 257static struct usb_class_driver lcd_class = {
258 .name = "usb/lcd%d", 258 .name = "lcd%d",
259 .fops = &lcd_fops, 259 .fops = &lcd_fops,
260 .mode = S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH,
261 .minor_base = USBLCD_MINOR, 260 .minor_base = USBLCD_MINOR,
262}; 261};
263 262
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index 54799eb0bc60..2997f558159b 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -9,7 +9,7 @@
9#include <linux/mm.h> 9#include <linux/mm.h>
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/moduleparam.h> 11#include <linux/moduleparam.h>
12#include <asm/scatterlist.h> 12#include <linux/scatterlist.h>
13 13
14#include <linux/usb.h> 14#include <linux/usb.h>
15 15
@@ -381,7 +381,6 @@ alloc_sglist (int nents, int max, int vary)
381 sg = kmalloc (nents * sizeof *sg, SLAB_KERNEL); 381 sg = kmalloc (nents * sizeof *sg, SLAB_KERNEL);
382 if (!sg) 382 if (!sg)
383 return NULL; 383 return NULL;
384 memset (sg, 0, nents * sizeof *sg);
385 384
386 for (i = 0; i < nents; i++) { 385 for (i = 0; i < nents; i++) {
387 char *buf; 386 char *buf;
@@ -394,9 +393,7 @@ alloc_sglist (int nents, int max, int vary)
394 memset (buf, 0, size); 393 memset (buf, 0, size);
395 394
396 /* kmalloc pages are always physically contiguous! */ 395 /* kmalloc pages are always physically contiguous! */
397 sg [i].page = virt_to_page (buf); 396 sg_init_one(&sg[i], buf, size);
398 sg [i].offset = offset_in_page (buf);
399 sg [i].length = size;
400 397
401 if (vary) { 398 if (vary) {
402 size += vary; 399 size += vary;
@@ -983,6 +980,7 @@ test_ctrl_queue (struct usbtest_dev *dev, struct usbtest_param *param)
983 reqp->number = i % NUM_SUBCASES; 980 reqp->number = i % NUM_SUBCASES;
984 reqp->expected = expected; 981 reqp->expected = expected;
985 u->setup_packet = (char *) &reqp->setup; 982 u->setup_packet = (char *) &reqp->setup;
983 u->transfer_flags |= URB_NO_SETUP_DMA_MAP;
986 984
987 u->context = &context; 985 u->context = &context;
988 u->complete = ctrl_complete; 986 u->complete = ctrl_complete;
@@ -1948,21 +1946,11 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id)
1948 1946
1949static int usbtest_suspend (struct usb_interface *intf, pm_message_t message) 1947static int usbtest_suspend (struct usb_interface *intf, pm_message_t message)
1950{ 1948{
1951 struct usbtest_dev *dev = usb_get_intfdata (intf);
1952
1953 down (&dev->sem);
1954 intf->dev.power.power_state = PMSG_SUSPEND;
1955 up (&dev->sem);
1956 return 0; 1949 return 0;
1957} 1950}
1958 1951
1959static int usbtest_resume (struct usb_interface *intf) 1952static int usbtest_resume (struct usb_interface *intf)
1960{ 1953{
1961 struct usbtest_dev *dev = usb_get_intfdata (intf);
1962
1963 down (&dev->sem);
1964 intf->dev.power.power_state = PMSG_ON;
1965 up (&dev->sem);
1966 return 0; 1954 return 0;
1967} 1955}
1968 1956
diff --git a/drivers/usb/misc/uss720.c b/drivers/usb/misc/uss720.c
index 03fb70ef2eb3..0592cb5e6c4d 100644
--- a/drivers/usb/misc/uss720.c
+++ b/drivers/usb/misc/uss720.c
@@ -137,7 +137,7 @@ static void async_complete(struct urb *urb, struct pt_regs *ptregs)
137 137
138static struct uss720_async_request *submit_async_request(struct parport_uss720_private *priv, 138static struct uss720_async_request *submit_async_request(struct parport_uss720_private *priv,
139 __u8 request, __u8 requesttype, __u16 value, __u16 index, 139 __u8 request, __u8 requesttype, __u16 value, __u16 index,
140 unsigned int mem_flags) 140 gfp_t mem_flags)
141{ 141{
142 struct usb_device *usbdev; 142 struct usb_device *usbdev;
143 struct uss720_async_request *rq; 143 struct uss720_async_request *rq;
@@ -204,7 +204,7 @@ static unsigned int kill_all_async_requests_priv(struct parport_uss720_private *
204 204
205/* --------------------------------------------------------------------- */ 205/* --------------------------------------------------------------------- */
206 206
207static int get_1284_register(struct parport *pp, unsigned char reg, unsigned char *val, unsigned int mem_flags) 207static int get_1284_register(struct parport *pp, unsigned char reg, unsigned char *val, gfp_t mem_flags)
208{ 208{
209 struct parport_uss720_private *priv; 209 struct parport_uss720_private *priv;
210 struct uss720_async_request *rq; 210 struct uss720_async_request *rq;
@@ -238,7 +238,7 @@ static int get_1284_register(struct parport *pp, unsigned char reg, unsigned cha
238 return -EIO; 238 return -EIO;
239} 239}
240 240
241static int set_1284_register(struct parport *pp, unsigned char reg, unsigned char val, unsigned int mem_flags) 241static int set_1284_register(struct parport *pp, unsigned char reg, unsigned char val, gfp_t mem_flags)
242{ 242{
243 struct parport_uss720_private *priv; 243 struct parport_uss720_private *priv;
244 struct uss720_async_request *rq; 244 struct uss720_async_request *rq;
diff --git a/drivers/usb/mon/mon_main.c b/drivers/usb/mon/mon_main.c
index 508a21028db4..c34944c75047 100644
--- a/drivers/usb/mon/mon_main.c
+++ b/drivers/usb/mon/mon_main.c
@@ -11,6 +11,7 @@
11#include <linux/usb.h> 11#include <linux/usb.h>
12#include <linux/debugfs.h> 12#include <linux/debugfs.h>
13#include <linux/smp_lock.h> 13#include <linux/smp_lock.h>
14#include <linux/notifier.h>
14 15
15#include "usb_mon.h" 16#include "usb_mon.h"
16#include "../core/hcd.h" 17#include "../core/hcd.h"
@@ -205,6 +206,23 @@ static void mon_bus_remove(struct usb_bus *ubus)
205 up(&mon_lock); 206 up(&mon_lock);
206} 207}
207 208
209static int mon_notify(struct notifier_block *self, unsigned long action,
210 void *dev)
211{
212 switch (action) {
213 case USB_BUS_ADD:
214 mon_bus_add(dev);
215 break;
216 case USB_BUS_REMOVE:
217 mon_bus_remove(dev);
218 }
219 return NOTIFY_OK;
220}
221
222static struct notifier_block mon_nb = {
223 .notifier_call = mon_notify,
224};
225
208/* 226/*
209 * Ops 227 * Ops
210 */ 228 */
@@ -212,8 +230,6 @@ static struct usb_mon_operations mon_ops_0 = {
212 .urb_submit = mon_submit, 230 .urb_submit = mon_submit,
213 .urb_submit_error = mon_submit_error, 231 .urb_submit_error = mon_submit_error,
214 .urb_complete = mon_complete, 232 .urb_complete = mon_complete,
215 .bus_add = mon_bus_add,
216 .bus_remove = mon_bus_remove,
217}; 233};
218 234
219/* 235/*
@@ -329,6 +345,8 @@ static int __init mon_init(void)
329 } 345 }
330 // MOD_INC_USE_COUNT(which_module?); 346 // MOD_INC_USE_COUNT(which_module?);
331 347
348 usb_register_notify(&mon_nb);
349
332 down(&usb_bus_list_lock); 350 down(&usb_bus_list_lock);
333 list_for_each_entry (ubus, &usb_bus_list, bus_list) { 351 list_for_each_entry (ubus, &usb_bus_list, bus_list) {
334 mon_bus_init(mondir, ubus); 352 mon_bus_init(mondir, ubus);
@@ -342,6 +360,7 @@ static void __exit mon_exit(void)
342 struct mon_bus *mbus; 360 struct mon_bus *mbus;
343 struct list_head *p; 361 struct list_head *p;
344 362
363 usb_unregister_notify(&mon_nb);
345 usb_mon_deregister(); 364 usb_mon_deregister();
346 365
347 down(&mon_lock); 366 down(&mon_lock);
diff --git a/drivers/usb/net/Kconfig b/drivers/usb/net/Kconfig
index 8c010bb44eb8..efd6ca7e4ac5 100644
--- a/drivers/usb/net/Kconfig
+++ b/drivers/usb/net/Kconfig
@@ -294,7 +294,7 @@ config USB_NET_ZAURUS
294 This also supports some related device firmware, as used in some 294 This also supports some related device firmware, as used in some
295 PDAs from Olympus and some cell phones from Motorola. 295 PDAs from Olympus and some cell phones from Motorola.
296 296
297 If you install an alternate ROM image, such as the Linux 2.6 based 297 If you install an alternate image, such as the Linux 2.6 based
298 versions of OpenZaurus, you should no longer need to support this 298 versions of OpenZaurus, you should no longer need to support this
299 protocol. Only the "eth-fd" or "net_fd" drivers in these devices 299 protocol. Only the "eth-fd" or "net_fd" drivers in these devices
300 really need this non-conformant variant of CDC Ethernet (or in 300 really need this non-conformant variant of CDC Ethernet (or in
diff --git a/drivers/usb/net/asix.c b/drivers/usb/net/asix.c
index 861f00a43750..252a34fbb42c 100644
--- a/drivers/usb/net/asix.c
+++ b/drivers/usb/net/asix.c
@@ -753,7 +753,7 @@ static int ax88772_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
753} 753}
754 754
755static struct sk_buff *ax88772_tx_fixup(struct usbnet *dev, struct sk_buff *skb, 755static struct sk_buff *ax88772_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
756 unsigned flags) 756 gfp_t flags)
757{ 757{
758 int padlen; 758 int padlen;
759 int headroom = skb_headroom(skb); 759 int headroom = skb_headroom(skb);
diff --git a/drivers/usb/net/gl620a.c b/drivers/usb/net/gl620a.c
index c8763ae33c73..c0f263b202a6 100644
--- a/drivers/usb/net/gl620a.c
+++ b/drivers/usb/net/gl620a.c
@@ -301,7 +301,7 @@ static int genelink_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
301} 301}
302 302
303static struct sk_buff * 303static struct sk_buff *
304genelink_tx_fixup(struct usbnet *dev, struct sk_buff *skb, unsigned flags) 304genelink_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
305{ 305{
306 int padlen; 306 int padlen;
307 int length = skb->len; 307 int length = skb->len;
diff --git a/drivers/usb/net/kaweth.c b/drivers/usb/net/kaweth.c
index e04b0ce3611a..6bef1be6b36c 100644
--- a/drivers/usb/net/kaweth.c
+++ b/drivers/usb/net/kaweth.c
@@ -469,7 +469,7 @@ static int kaweth_reset(struct kaweth_device *kaweth)
469 0, 469 0,
470 KAWETH_CONTROL_TIMEOUT); 470 KAWETH_CONTROL_TIMEOUT);
471 471
472 udelay(10000); 472 mdelay(10);
473 473
474 kaweth_dbg("kaweth_reset() returns %d.",result); 474 kaweth_dbg("kaweth_reset() returns %d.",result);
475 475
@@ -477,13 +477,13 @@ static int kaweth_reset(struct kaweth_device *kaweth)
477} 477}
478 478
479static void kaweth_usb_receive(struct urb *, struct pt_regs *regs); 479static void kaweth_usb_receive(struct urb *, struct pt_regs *regs);
480static int kaweth_resubmit_rx_urb(struct kaweth_device *, unsigned); 480static int kaweth_resubmit_rx_urb(struct kaweth_device *, gfp_t);
481 481
482/**************************************************************** 482/****************************************************************
483 int_callback 483 int_callback
484*****************************************************************/ 484*****************************************************************/
485 485
486static void kaweth_resubmit_int_urb(struct kaweth_device *kaweth, int mf) 486static void kaweth_resubmit_int_urb(struct kaweth_device *kaweth, gfp_t mf)
487{ 487{
488 int status; 488 int status;
489 489
@@ -550,7 +550,7 @@ static void kaweth_resubmit_tl(void *d)
550 * kaweth_resubmit_rx_urb 550 * kaweth_resubmit_rx_urb
551 ****************************************************************/ 551 ****************************************************************/
552static int kaweth_resubmit_rx_urb(struct kaweth_device *kaweth, 552static int kaweth_resubmit_rx_urb(struct kaweth_device *kaweth,
553 unsigned mem_flags) 553 gfp_t mem_flags)
554{ 554{
555 int result; 555 int result;
556 556
diff --git a/drivers/usb/net/net1080.c b/drivers/usb/net/net1080.c
index a4309c4a491b..cee55f8cf64f 100644
--- a/drivers/usb/net/net1080.c
+++ b/drivers/usb/net/net1080.c
@@ -500,7 +500,7 @@ static int net1080_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
500} 500}
501 501
502static struct sk_buff * 502static struct sk_buff *
503net1080_tx_fixup(struct usbnet *dev, struct sk_buff *skb, unsigned flags) 503net1080_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
504{ 504{
505 int padlen; 505 int padlen;
506 struct sk_buff *skb2; 506 struct sk_buff *skb2;
diff --git a/drivers/usb/net/pegasus.c b/drivers/usb/net/pegasus.c
index 6a4ffe6c3977..537eb181d985 100644
--- a/drivers/usb/net/pegasus.c
+++ b/drivers/usb/net/pegasus.c
@@ -1384,7 +1384,6 @@ static int pegasus_suspend (struct usb_interface *intf, pm_message_t message)
1384 usb_kill_urb(pegasus->rx_urb); 1384 usb_kill_urb(pegasus->rx_urb);
1385 usb_kill_urb(pegasus->intr_urb); 1385 usb_kill_urb(pegasus->intr_urb);
1386 } 1386 }
1387 intf->dev.power.power_state = PMSG_SUSPEND;
1388 return 0; 1387 return 0;
1389} 1388}
1390 1389
@@ -1392,7 +1391,6 @@ static int pegasus_resume (struct usb_interface *intf)
1392{ 1391{
1393 struct pegasus *pegasus = usb_get_intfdata(intf); 1392 struct pegasus *pegasus = usb_get_intfdata(intf);
1394 1393
1395 intf->dev.power.power_state = PMSG_ON;
1396 netif_device_attach (pegasus->net); 1394 netif_device_attach (pegasus->net);
1397 if (netif_running(pegasus->net)) { 1395 if (netif_running(pegasus->net)) {
1398 pegasus->rx_urb->status = 0; 1396 pegasus->rx_urb->status = 0;
diff --git a/drivers/usb/net/pegasus.h b/drivers/usb/net/pegasus.h
index b98f2a833442..9fbd59b55cb6 100644
--- a/drivers/usb/net/pegasus.h
+++ b/drivers/usb/net/pegasus.h
@@ -181,6 +181,8 @@ PEGASUS_DEV( "Accton USB 10/100 Ethernet Adapter", VENDOR_ACCTON, 0x1046,
181 DEFAULT_GPIO_RESET ) 181 DEFAULT_GPIO_RESET )
182PEGASUS_DEV( "SpeedStream USB 10/100 Ethernet", VENDOR_ACCTON, 0x5046, 182PEGASUS_DEV( "SpeedStream USB 10/100 Ethernet", VENDOR_ACCTON, 0x5046,
183 DEFAULT_GPIO_RESET | PEGASUS_II ) 183 DEFAULT_GPIO_RESET | PEGASUS_II )
184PEGASUS_DEV( "Philips USB 10/100 Ethernet", VENDOR_ACCTON, 0xb004,
185 DEFAULT_GPIO_RESET | PEGASUS_II )
184PEGASUS_DEV( "ADMtek ADM8511 \"Pegasus II\" USB Ethernet", 186PEGASUS_DEV( "ADMtek ADM8511 \"Pegasus II\" USB Ethernet",
185 VENDOR_ADMTEK, 0x8511, 187 VENDOR_ADMTEK, 0x8511,
186 DEFAULT_GPIO_RESET | PEGASUS_II | HAS_HOME_PNA ) 188 DEFAULT_GPIO_RESET | PEGASUS_II | HAS_HOME_PNA )
diff --git a/drivers/usb/net/rndis_host.c b/drivers/usb/net/rndis_host.c
index 2ed2e5fb7778..b5a925dc1beb 100644
--- a/drivers/usb/net/rndis_host.c
+++ b/drivers/usb/net/rndis_host.c
@@ -517,7 +517,7 @@ static int rndis_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
517} 517}
518 518
519static struct sk_buff * 519static struct sk_buff *
520rndis_tx_fixup(struct usbnet *dev, struct sk_buff *skb, unsigned flags) 520rndis_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
521{ 521{
522 struct rndis_data_hdr *hdr; 522 struct rndis_data_hdr *hdr;
523 struct sk_buff *skb2; 523 struct sk_buff *skb2;
diff --git a/drivers/usb/net/rtl8150.c b/drivers/usb/net/rtl8150.c
index c3d4e3589e30..787dd3591d6a 100644
--- a/drivers/usb/net/rtl8150.c
+++ b/drivers/usb/net/rtl8150.c
@@ -909,6 +909,7 @@ static void rtl8150_disconnect(struct usb_interface *intf)
909 usb_set_intfdata(intf, NULL); 909 usb_set_intfdata(intf, NULL);
910 if (dev) { 910 if (dev) {
911 set_bit(RTL8150_UNPLUG, &dev->flags); 911 set_bit(RTL8150_UNPLUG, &dev->flags);
912 tasklet_disable(&dev->tl);
912 unregister_netdev(dev->netdev); 913 unregister_netdev(dev->netdev);
913 unlink_all_urbs(dev); 914 unlink_all_urbs(dev);
914 free_all_urbs(dev); 915 free_all_urbs(dev);
diff --git a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c
index 6c460918d54f..74f05c9c84d5 100644
--- a/drivers/usb/net/usbnet.c
+++ b/drivers/usb/net/usbnet.c
@@ -288,7 +288,7 @@ EXPORT_SYMBOL_GPL(usbnet_defer_kevent);
288 288
289static void rx_complete (struct urb *urb, struct pt_regs *regs); 289static void rx_complete (struct urb *urb, struct pt_regs *regs);
290 290
291static void rx_submit (struct usbnet *dev, struct urb *urb, unsigned flags) 291static void rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags)
292{ 292{
293 struct sk_buff *skb; 293 struct sk_buff *skb;
294 struct skb_data *entry; 294 struct skb_data *entry;
@@ -1185,7 +1185,6 @@ int usbnet_suspend (struct usb_interface *intf, pm_message_t message)
1185 netif_device_detach (dev->net); 1185 netif_device_detach (dev->net);
1186 (void) unlink_urbs (dev, &dev->rxq); 1186 (void) unlink_urbs (dev, &dev->rxq);
1187 (void) unlink_urbs (dev, &dev->txq); 1187 (void) unlink_urbs (dev, &dev->txq);
1188 intf->dev.power.power_state = PMSG_SUSPEND;
1189 return 0; 1188 return 0;
1190} 1189}
1191EXPORT_SYMBOL_GPL(usbnet_suspend); 1190EXPORT_SYMBOL_GPL(usbnet_suspend);
@@ -1194,7 +1193,6 @@ int usbnet_resume (struct usb_interface *intf)
1194{ 1193{
1195 struct usbnet *dev = usb_get_intfdata(intf); 1194 struct usbnet *dev = usb_get_intfdata(intf);
1196 1195
1197 intf->dev.power.power_state = PMSG_ON;
1198 netif_device_attach (dev->net); 1196 netif_device_attach (dev->net);
1199 tasklet_schedule (&dev->bh); 1197 tasklet_schedule (&dev->bh);
1200 return 0; 1198 return 0;
diff --git a/drivers/usb/net/usbnet.h b/drivers/usb/net/usbnet.h
index 7aa0abd1a9bd..89fc4958eecf 100644
--- a/drivers/usb/net/usbnet.h
+++ b/drivers/usb/net/usbnet.h
@@ -107,7 +107,7 @@ struct driver_info {
107 107
108 /* fixup tx packet (add framing) */ 108 /* fixup tx packet (add framing) */
109 struct sk_buff *(*tx_fixup)(struct usbnet *dev, 109 struct sk_buff *(*tx_fixup)(struct usbnet *dev,
110 struct sk_buff *skb, unsigned flags); 110 struct sk_buff *skb, gfp_t flags);
111 111
112 /* for new devices, use the descriptor-reading code instead */ 112 /* for new devices, use the descriptor-reading code instead */
113 int in; /* rx endpoint */ 113 int in; /* rx endpoint */
diff --git a/drivers/usb/net/zaurus.c b/drivers/usb/net/zaurus.c
index ee3b892aeabc..5d4b7d55b097 100644
--- a/drivers/usb/net/zaurus.c
+++ b/drivers/usb/net/zaurus.c
@@ -62,7 +62,7 @@
62 */ 62 */
63 63
64static struct sk_buff * 64static struct sk_buff *
65zaurus_tx_fixup(struct usbnet *dev, struct sk_buff *skb, unsigned flags) 65zaurus_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
66{ 66{
67 int padlen; 67 int padlen;
68 struct sk_buff *skb2; 68 struct sk_buff *skb2;
diff --git a/drivers/usb/net/zd1201.c b/drivers/usb/net/zd1201.c
index c4e479ee926a..2f52261c7cc1 100644
--- a/drivers/usb/net/zd1201.c
+++ b/drivers/usb/net/zd1201.c
@@ -521,7 +521,7 @@ static int zd1201_setconfig(struct zd1201 *zd, int rid, void *buf, int len, int
521 int reqlen; 521 int reqlen;
522 char seq=0; 522 char seq=0;
523 struct urb *urb; 523 struct urb *urb;
524 unsigned int gfp_mask = wait ? GFP_NOIO : GFP_ATOMIC; 524 gfp_t gfp_mask = wait ? GFP_NOIO : GFP_ATOMIC;
525 525
526 len += 4; /* first 4 are for header */ 526 len += 4; /* first 4 are for header */
527 527
diff --git a/drivers/usb/serial/ChangeLog.old b/drivers/usb/serial/ChangeLog.old
new file mode 100644
index 000000000000..c1b279939bbf
--- /dev/null
+++ b/drivers/usb/serial/ChangeLog.old
@@ -0,0 +1,730 @@
1This is the contents of some of the drivers/usb/serial/ files that had old
2changelog comments. They were quite old, and out of date, and we don't keep
3them anymore, so I've put them here, away from the source files, in case
4people still care to see them.
5
6- Greg Kroah-Hartman <greg@kroah.com> October 20, 2005
7
8-----------------------------------------------------------------------
9usb-serial.h Change Log comments:
10
11 (03/26/2002) gkh
12 removed the port->tty check from port_paranoia_check() due to serial
13 consoles not having a tty device assigned to them.
14
15 (12/03/2001) gkh
16 removed active from the port structure.
17 added documentation to the usb_serial_device_type structure
18
19 (10/10/2001) gkh
20 added vendor and product to serial structure. Needed to determine device
21 owner when the device is disconnected.
22
23 (05/30/2001) gkh
24 added sem to port structure and removed port_lock
25
26 (10/05/2000) gkh
27 Added interrupt_in_endpointAddress and bulk_in_endpointAddress to help
28 fix bug with urb->dev not being set properly, now that the usb core
29 needs it.
30
31 (09/11/2000) gkh
32 Added usb_serial_debug_data function to help get rid of #DEBUG in the
33 drivers.
34
35 (08/28/2000) gkh
36 Added port_lock to port structure.
37
38 (08/08/2000) gkh
39 Added open_count to port structure.
40
41 (07/23/2000) gkh
42 Added bulk_out_endpointAddress to port structure.
43
44 (07/19/2000) gkh, pberger, and borchers
45 Modifications to allow usb-serial drivers to be modules.
46
47-----------------------------------------------------------------------
48usb-serial.c Change Log comments:
49
50 (12/10/2002) gkh
51 Split the ports off into their own struct device, and added a
52 usb-serial bus driver.
53
54 (11/19/2002) gkh
55 removed a few #ifdefs for the generic code and cleaned up the failure
56 logic in initialization.
57
58 (10/02/2002) gkh
59 moved the console code to console.c and out of this file.
60
61 (06/05/2002) gkh
62 moved location of startup() call in serial_probe() until after all
63 of the port information and endpoints are initialized. This makes
64 things easier for some drivers.
65
66 (04/10/2002) gkh
67 added serial_read_proc function which creates a
68 /proc/tty/driver/usb-serial file.
69
70 (03/27/2002) gkh
71 Got USB serial console code working properly and merged into the main
72 version of the tree. Thanks to Randy Dunlap for the initial version
73 of this code, and for pushing me to finish it up.
74 The USB serial console works with any usb serial driver device.
75
76 (03/21/2002) gkh
77 Moved all manipulation of port->open_count into the core. Now the
78 individual driver's open and close functions are called only when the
79 first open() and last close() is called. Making the drivers a bit
80 smaller and simpler.
81 Fixed a bug if a driver didn't have the owner field set.
82
83 (02/26/2002) gkh
84 Moved all locking into the main serial_* functions, instead of having
85 the individual drivers have to grab the port semaphore. This should
86 reduce races.
87 Reworked the MOD_INC logic a bit to always increment and decrement, even
88 if the generic driver is being used.
89
90 (10/10/2001) gkh
91 usb_serial_disconnect() now sets the serial->dev pointer is to NULL to
92 help prevent child drivers from accessing the device since it is now
93 gone.
94
95 (09/13/2001) gkh
96 Moved generic driver initialize after we have registered with the USB
97 core. Thanks to Randy Dunlap for pointing this problem out.
98
99 (07/03/2001) gkh
100 Fixed module paramater size. Thanks to John Brockmeyer for the pointer.
101 Fixed vendor and product getting defined through the MODULE_PARM macro
102 if the Generic driver wasn't compiled in.
103 Fixed problem with generic_shutdown() not being called for drivers that
104 don't have a shutdown() function.
105
106 (06/06/2001) gkh
107 added evil hack that is needed for the prolific pl2303 device due to the
108 crazy way its endpoints are set up.
109
110 (05/30/2001) gkh
111 switched from using spinlock to a semaphore, which fixes lots of problems.
112
113 (04/08/2001) gb
114 Identify version on module load.
115
116 2001_02_05 gkh
117 Fixed buffer overflows bug with the generic serial driver. Thanks to
118 Todd Squires <squirest@ct0.com> for fixing this.
119
120 (01/10/2001) gkh
121 Fixed bug where the generic serial adaptor grabbed _any_ device that was
122 offered to it.
123
124 (12/12/2000) gkh
125 Removed MOD_INC and MOD_DEC from poll and disconnect functions, and
126 moved them to the serial_open and serial_close functions.
127 Also fixed bug with there not being a MOD_DEC for the generic driver
128 (thanks to Gary Brubaker for finding this.)
129
130 (11/29/2000) gkh
131 Small NULL pointer initialization cleanup which saves a bit of disk image
132
133 (11/01/2000) Adam J. Richter
134 instead of using idVendor/idProduct pairs, usb serial drivers
135 now identify their hardware interest with usb_device_id tables,
136 which they usually have anyhow for use with MODULE_DEVICE_TABLE.
137
138 (10/05/2000) gkh
139 Fixed bug with urb->dev not being set properly, now that the usb
140 core needs it.
141
142 (09/11/2000) gkh
143 Removed DEBUG #ifdefs with call to usb_serial_debug_data
144
145 (08/28/2000) gkh
146 Added port_lock to port structure.
147 Added locks for SMP safeness to generic driver
148 Fixed the ability to open a generic device's port more than once.
149
150 (07/23/2000) gkh
151 Added bulk_out_endpointAddress to port structure.
152
153 (07/19/2000) gkh, pberger, and borchers
154 Modifications to allow usb-serial drivers to be modules.
155
156 (07/03/2000) gkh
157 Added more debugging to serial_ioctl call
158
159 (06/25/2000) gkh
160 Changed generic_write_bulk_callback to not call wake_up_interruptible
161 directly, but to have port_softint do it at a safer time.
162
163 (06/23/2000) gkh
164 Cleaned up debugging statements in a quest to find UHCI timeout bug.
165
166 (05/22/2000) gkh
167 Changed the makefile, enabling the big CONFIG_USB_SERIAL_SOMTHING to be
168 removed from the individual device source files.
169
170 (05/03/2000) gkh
171 Added the Digi Acceleport driver from Al Borchers and Peter Berger.
172
173 (05/02/2000) gkh
174 Changed devfs and tty register code to work properly now. This was based on
175 the ACM driver changes by Vojtech Pavlik.
176
177 (04/27/2000) Ryan VanderBijl
178 Put calls to *_paranoia_checks into one function.
179
180 (04/23/2000) gkh
181 Fixed bug that Randy Dunlap found for Generic devices with no bulk out ports.
182 Moved when the startup code printed out the devices that are supported.
183
184 (04/19/2000) gkh
185 Added driver for ZyXEL omni.net lcd plus ISDN TA
186 Made startup info message specify which drivers were compiled in.
187
188 (04/03/2000) gkh
189 Changed the probe process to remove the module unload races.
190 Changed where the tty layer gets initialized to have devfs work nicer.
191 Added initial devfs support.
192
193 (03/26/2000) gkh
194 Split driver up into device specific pieces.
195
196 (03/19/2000) gkh
197 Fixed oops that could happen when device was removed while a program
198 was talking to the device.
199 Removed the static urbs and now all urbs are created and destroyed
200 dynamically.
201 Reworked the internal interface. Now everything is based on the
202 usb_serial_port structure instead of the larger usb_serial structure.
203 This fixes the bug that a multiport device could not have more than
204 one port open at one time.
205
206 (03/17/2000) gkh
207 Added config option for debugging messages.
208 Added patch for keyspan pda from Brian Warner.
209
210 (03/06/2000) gkh
211 Added the keyspan pda code from Brian Warner <warner@lothar.com>
212 Moved a bunch of the port specific stuff into its own structure. This
213 is in anticipation of the true multiport devices (there's a bug if you
214 try to access more than one port of any multiport device right now)
215
216 (02/21/2000) gkh
217 Made it so that any serial devices only have to specify which functions
218 they want to overload from the generic function calls (great,
219 inheritance in C, in a driver, just what I wanted...)
220 Added support for set_termios and ioctl function calls. No drivers take
221 advantage of this yet.
222 Removed the #ifdef MODULE, now there is no module specific code.
223 Cleaned up a few comments in usb-serial.h that were wrong (thanks again
224 to Miles Lott).
225 Small fix to get_free_serial.
226
227 (02/14/2000) gkh
228 Removed the Belkin and Peracom functionality from the driver due to
229 the lack of support from the vendor, and me not wanting people to
230 accidenatly buy the device, expecting it to work with Linux.
231 Added read_bulk_callback and write_bulk_callback to the type structure
232 for the needs of the FTDI and WhiteHEAT driver.
233 Changed all reverences to FTDI to FTDI_SIO at the request of Bill
234 Ryder.
235 Changed the output urb size back to the max endpoint size to make
236 the ftdi_sio driver have it easier, and due to the fact that it didn't
237 really increase the speed any.
238
239 (02/11/2000) gkh
240 Added VISOR_FUNCTION_CONSOLE to the visor startup function. This was a
241 patch from Miles Lott (milos@insync.net).
242 Fixed bug with not restoring the minor range that a device grabs, if
243 the startup function fails (thanks Miles for finding this).
244
245 (02/05/2000) gkh
246 Added initial framework for the Keyspan PDA serial converter so that
247 Brian Warner has a place to put his code.
248 Made the ezusb specific functions generic enough that different
249 devices can use them (whiteheat and keyspan_pda both need them).
250 Split out a whole bunch of structure and other stuff to a separate
251 usb-serial.h file.
252 Made the Visor connection messages a little more understandable, now
253 that Miles Lott (milos@insync.net) has gotten the Generic channel to
254 work. Also made them always show up in the log file.
255
256 (01/25/2000) gkh
257 Added initial framework for FTDI serial converter so that Bill Ryder
258 has a place to put his code.
259 Added the vendor specific info from Handspring. Now we can print out
260 informational debug messages as well as understand what is happening.
261
262 (01/23/2000) gkh
263 Fixed problem of crash when trying to open a port that didn't have a
264 device assigned to it. Made the minor node finding a little smarter,
265 now it looks to find a continuous space for the new device.
266
267 (01/21/2000) gkh
268 Fixed bug in visor_startup with patch from Miles Lott (milos@insync.net)
269 Fixed get_serial_by_minor which was all messed up for multi port
270 devices. Fixed multi port problem for generic devices. Now the number
271 of ports is determined by the number of bulk out endpoints for the
272 generic device.
273
274 (01/19/2000) gkh
275 Removed lots of cruft that was around from the old (pre urb) driver
276 interface.
277 Made the serial_table dynamic. This should save lots of memory when
278 the number of minor nodes goes up to 256.
279 Added initial support for devices that have more than one port.
280 Added more debugging comments for the Visor, and added a needed
281 set_configuration call.
282
283 (01/17/2000) gkh
284 Fixed the WhiteHEAT firmware (my processing tool had a bug)
285 and added new debug loader firmware for it.
286 Removed the put_char function as it isn't really needed.
287 Added visor startup commands as found by the Win98 dump.
288
289 (01/13/2000) gkh
290 Fixed the vendor id for the generic driver to the one I meant it to be.
291
292 (01/12/2000) gkh
293 Forget the version numbering...that's pretty useless...
294 Made the driver able to be compiled so that the user can select which
295 converter they want to use. This allows people who only want the Visor
296 support to not pay the memory size price of the WhiteHEAT.
297 Fixed bug where the generic driver (idVendor=0000 and idProduct=0000)
298 grabbed the root hub. Not good.
299
300 version 0.4.0 (01/10/2000) gkh
301 Added whiteheat.h containing the firmware for the ConnectTech WhiteHEAT
302 device. Added startup function to allow firmware to be downloaded to
303 a device if it needs to be.
304 Added firmware download logic to the WhiteHEAT device.
305 Started to add #defines to split up the different drivers for potential
306 configuration option.
307
308 version 0.3.1 (12/30/99) gkh
309 Fixed problems with urb for bulk out.
310 Added initial support for multiple sets of endpoints. This enables
311 the Handspring Visor to be attached successfully. Only the first
312 bulk in / bulk out endpoint pair is being used right now.
313
314 version 0.3.0 (12/27/99) gkh
315 Added initial support for the Handspring Visor based on a patch from
316 Miles Lott (milos@sneety.insync.net)
317 Cleaned up the code a bunch and converted over to using urbs only.
318
319 version 0.2.3 (12/21/99) gkh
320 Added initial support for the Connect Tech WhiteHEAT converter.
321 Incremented the number of ports in expectation of getting the
322 WhiteHEAT to work properly (4 ports per connection).
323 Added notification on insertion and removal of what port the
324 device is/was connected to (and what kind of device it was).
325
326 version 0.2.2 (12/16/99) gkh
327 Changed major number to the new allocated number. We're legal now!
328
329 version 0.2.1 (12/14/99) gkh
330 Fixed bug that happens when device node is opened when there isn't a
331 device attached to it. Thanks to marek@webdesign.no for noticing this.
332
333 version 0.2.0 (11/10/99) gkh
334 Split up internals to make it easier to add different types of serial
335 converters to the code.
336 Added a "generic" driver that gets it's vendor and product id
337 from when the module is loaded. Thanks to David E. Nelson (dnelson@jump.net)
338 for the idea and sample code (from the usb scanner driver.)
339 Cleared up any licensing questions by releasing it under the GNU GPL.
340
341 version 0.1.2 (10/25/99) gkh
342 Fixed bug in detecting device.
343
344 version 0.1.1 (10/05/99) gkh
345 Changed the major number to not conflict with anything else.
346
347 version 0.1 (09/28/99) gkh
348 Can recognize the two different devices and start up a read from
349 device when asked to. Writes also work. No control signals yet, this
350 all is vendor specific data (i.e. no spec), also no control for
351 different baud rates or other bit settings.
352 Currently we are using the same devid as the acm driver. This needs
353 to change.
354
355-----------------------------------------------------------------------
356visor.c Change Log comments:
357
358 (06/03/2003) Judd Montgomery <judd at jpilot.org>
359 Added support for module parameter options for untested/unknown
360 devices.
361
362 (03/09/2003) gkh
363 Added support for the Sony Clie NZ90V device. Thanks to Martin Brachtl
364 <brachtl@redgrep.cz> for the information.
365
366 (03/05/2003) gkh
367 Think Treo support is now working.
368
369 (04/03/2002) gkh
370 Added support for the Sony OS 4.1 devices. Thanks to Hiroyuki ARAKI
371 <hiro@zob.ne.jp> for the information.
372
373 (03/27/2002) gkh
374 Removed assumptions that port->tty was always valid (is not true
375 for usb serial console devices.)
376
377 (03/23/2002) gkh
378 Added support for the Palm i705 device, thanks to Thomas Riemer
379 <tom@netmech.com> for the information.
380
381 (03/21/2002) gkh
382 Added support for the Palm m130 device, thanks to Udo Eisenbarth
383 <udo.eisenbarth@web.de> for the information.
384
385 (02/27/2002) gkh
386 Reworked the urb handling logic. We have no more pool, but dynamically
387 allocate the urb and the transfer buffer on the fly. In testing this
388 does not incure any measurable overhead. This also relies on the fact
389 that we have proper reference counting logic for urbs.
390
391 (02/21/2002) SilaS
392 Added initial support for the Palm m515 devices.
393
394 (02/14/2002) gkh
395 Added support for the Clie S-360 device.
396
397 (12/18/2001) gkh
398 Added better Clie support for 3.5 devices. Thanks to Geoffrey Levand
399 for the patch.
400
401 (11/11/2001) gkh
402 Added support for the m125 devices, and added check to prevent oopses
403 for Clié devices that lie about the number of ports they have.
404
405 (08/30/2001) gkh
406 Added support for the Clie devices, both the 3.5 and 4.0 os versions.
407 Many thanks to Daniel Burke, and Bryan Payne for helping with this.
408
409 (08/23/2001) gkh
410 fixed a few potential bugs pointed out by Oliver Neukum.
411
412 (05/30/2001) gkh
413 switched from using spinlock to a semaphore, which fixes lots of problems.
414
415 (05/28/2000) gkh
416 Added initial support for the Palm m500 and Palm m505 devices.
417
418 (04/08/2001) gb
419 Identify version on module load.
420
421 (01/21/2000) gkh
422 Added write_room and chars_in_buffer, as they were previously using the
423 generic driver versions which is all wrong now that we are using an urb
424 pool. Thanks to Wolfgang Grandegger for pointing this out to me.
425 Removed count assignment in the write function, which was not needed anymore
426 either. Thanks to Al Borchers for pointing this out.
427
428 (12/12/2000) gkh
429 Moved MOD_DEC to end of visor_close to be nicer, as the final write
430 message can sleep.
431
432 (11/12/2000) gkh
433 Fixed bug with data being dropped on the floor by forcing tty->low_latency
434 to be on. Hopefully this fixes the OHCI issue!
435
436 (11/01/2000) Adam J. Richter
437 usb_device_id table support
438
439 (10/05/2000) gkh
440 Fixed bug with urb->dev not being set properly, now that the usb
441 core needs it.
442
443 (09/11/2000) gkh
444 Got rid of always calling kmalloc for every urb we wrote out to the
445 device.
446 Added visor_read_callback so we can keep track of bytes in and out for
447 those people who like to know the speed of their device.
448 Removed DEBUG #ifdefs with call to usb_serial_debug_data
449
450 (09/06/2000) gkh
451 Fixed oops in visor_exit. Need to uncomment usb_unlink_urb call _after_
452 the host controller drivers set urb->dev = NULL when the urb is finished.
453
454 (08/28/2000) gkh
455 Added locks for SMP safeness.
456
457 (08/08/2000) gkh
458 Fixed endian problem in visor_startup.
459 Fixed MOD_INC and MOD_DEC logic and the ability to open a port more
460 than once.
461
462 (07/23/2000) gkh
463 Added pool of write urbs to speed up transfers to the visor.
464
465 (07/19/2000) gkh
466 Added module_init and module_exit functions to handle the fact that this
467 driver is a loadable module now.
468
469 (07/03/2000) gkh
470 Added visor_set_ioctl and visor_set_termios functions (they don't do much
471 of anything, but are good for debugging.)
472
473 (06/25/2000) gkh
474 Fixed bug in visor_unthrottle that should help with the disconnect in PPP
475 bug that people have been reporting.
476
477 (06/23/2000) gkh
478 Cleaned up debugging statements in a quest to find UHCI timeout bug.
479
480 (04/27/2000) Ryan VanderBijl
481 Fixed memory leak in visor_close
482
483 (03/26/2000) gkh
484 Split driver up into device specific pieces.
485
486-----------------------------------------------------------------------
487pl2303.c Change Log comments:
488
489 2002_Mar_26 gkh
490 allowed driver to work properly if there is no tty assigned to a port
491 (this happens for serial console devices.)
492
493 2001_Oct_06 gkh
494 Added RTS and DTR line control. Thanks to joe@bndlg.de for parts of it.
495
496 2001_Sep_19 gkh
497 Added break support.
498
499 2001_Aug_30 gkh
500 fixed oops in write_bulk_callback.
501
502 2001_Aug_28 gkh
503 reworked buffer logic to be like other usb-serial drivers. Hopefully
504 removing some reported problems.
505
506 2001_Jun_06 gkh
507 finished porting to 2.4 format.
508
509
510-----------------------------------------------------------------------
511io_edgeport.c Change Log comments:
512
513 2003_04_03 al borchers
514 - fixed a bug (that shows up with dosemu) where the tty struct is
515 used in a callback after it has been freed
516
517 2.3 2002_03_08 greg kroah-hartman
518 - fixed bug when multiple devices were attached at the same time.
519
520 2.2 2001_11_14 greg kroah-hartman
521 - fixed bug in edge_close that kept the port from being used more
522 than once.
523 - fixed memory leak on device removal.
524 - fixed potential double free of memory when command urb submitting
525 failed.
526 - other small cleanups when the device is removed
527
528 2.1 2001_07_09 greg kroah-hartman
529 - added support for TIOCMBIS and TIOCMBIC.
530
531 (04/08/2001) gb
532 - Identify version on module load.
533
534 2.0 2001_03_05 greg kroah-hartman
535 - reworked entire driver to fit properly in with the other usb-serial
536 drivers. Occasional oopses still happen, but it's a good start.
537
538 1.2.3 (02/23/2001) greg kroah-hartman
539 - changed device table to work properly for 2.4.x final format.
540 - fixed problem with dropping data at high data rates.
541
542 1.2.2 (11/27/2000) greg kroah-hartman
543 - cleaned up more NTisms.
544 - Added device table for 2.4.0-test11
545
546 1.2.1 (11/08/2000) greg kroah-hartman
547 - Started to clean up NTisms.
548 - Fixed problem with dev field of urb for kernels >= 2.4.0-test9
549
550 1.2 (10/17/2000) David Iacovelli
551 Remove all EPIC code and GPL source
552 Fix RELEVANT_IFLAG macro to include flow control
553 changes port configuration changes.
554 Fix redefinition of SERIAL_MAGIC
555 Change all timeout values to 5 seconds
556 Tried to fix the UHCI multiple urb submission, but failed miserably.
557 it seems to work fine with OHCI.
558 ( Greg take a look at the #if 0 at end of WriteCmdUsb() we must
559 find a way to work arount this UHCI bug )
560
561 1.1 (10/11/2000) David Iacovelli
562 Fix XON/XOFF flow control to support both IXON and IXOFF
563
564 0.9.27 (06/30/2000) David Iacovelli
565 Added transmit queue and now allocate urb for command writes.
566
567 0.9.26 (06/29/2000) David Iacovelli
568 Add support for 80251 based edgeport
569
570 0.9.25 (06/27/2000) David Iacovelli
571 Do not close the port if it has multiple opens.
572
573 0.9.24 (05/26/2000) David Iacovelli
574 Add IOCTLs to support RXTX and JAVA POS
575 and first cut at running BlackBox Demo
576
577 0.9.23 (05/24/2000) David Iacovelli
578 Add IOCTLs to support RXTX and JAVA POS
579
580 0.9.22 (05/23/2000) David Iacovelli
581 fixed bug in enumeration. If epconfig turns on mapping by
582 path after a device is already plugged in, we now update
583 the mapping correctly
584
585 0.9.21 (05/16/2000) David Iacovelli
586 Added BlockUntilChaseResp() to also wait for txcredits
587 Updated the way we allocate and handle write URBs
588 Add debug code to dump buffers
589
590 0.9.20 (05/01/2000) David Iacovelli
591 change driver to use usb/tts/
592
593 0.9.19 (05/01/2000) David Iacovelli
594 Update code to compile if DEBUG is off
595
596 0.9.18 (04/28/2000) David Iacovelli
597 cleanup and test tty_register with devfs
598
599 0.9.17 (04/27/2000) greg kroah-hartman
600 changed tty_register around to be like the way it
601 was before, but now it works properly with devfs.
602
603 0.9.16 (04/26/2000) david iacovelli
604 Fixed bug in GetProductInfo()
605
606 0.9.15 (04/25/2000) david iacovelli
607 Updated enumeration
608
609 0.9.14 (04/24/2000) david iacovelli
610 Removed all config/status IOCTLS and
611 converted to using /proc/edgeport
612 still playing with devfs
613
614 0.9.13 (04/24/2000) david iacovelli
615 Removed configuration based on ttyUSB0
616 Added support for configuration using /prod/edgeport
617 first attempt at using devfs (not working yet!)
618 Added IOCTL to GetProductInfo()
619 Added support for custom baud rates
620 Add support for random port numbers
621
622 0.9.12 (04/18/2000) david iacovelli
623 added additional configuration IOCTLs
624 use ttyUSB0 for configuration
625
626 0.9.11 (04/17/2000) greg kroah-hartman
627 fixed module initialization race conditions.
628 made all urbs dynamically allocated.
629 made driver devfs compatible. now it only registers the tty device
630 when the device is actually plugged in.
631
632 0.9.10 (04/13/2000) greg kroah-hartman
633 added proc interface framework.
634
635 0.9.9 (04/13/2000) david iacovelli
636 added enumeration code and ioctls to configure the device
637
638 0.9.8 (04/12/2000) david iacovelli
639 Change interrupt read start when device is plugged in
640 and stop when device is removed
641 process interrupt reads when all ports are closed
642 (keep value of rxBytesAvail consistent with the edgeport)
643 set the USB_BULK_QUEUE flag so that we can shove a bunch
644 of urbs at once down the pipe
645
646 0.9.7 (04/10/2000) david iacovelli
647 start to add enumeration code.
648 generate serial number for epic devices
649 add support for kdb
650
651 0.9.6 (03/30/2000) david iacovelli
652 add IOCTL to get string, manufacture, and boot descriptors
653
654 0.9.5 (03/14/2000) greg kroah-hartman
655 more error checking added to SerialOpen to try to fix UHCI open problem
656
657 0.9.4 (03/09/2000) greg kroah-hartman
658 added more error checking to handle oops when data is hanging
659 around and tty is abruptly closed.
660
661 0.9.3 (03/09/2000) david iacovelli
662 Add epic support for xon/xoff chars
663 play with performance
664
665 0.9.2 (03/08/2000) greg kroah-hartman
666 changed most "info" calls to "dbg"
667 implemented flow control properly in the termios call
668
669 0.9.1 (03/08/2000) david iacovelli
670 added EPIC support
671 enabled bootloader update
672
673 0.9 (03/08/2000) greg kroah-hartman
674 Release to IO networks.
675 Integrated changes that David made
676 made getting urbs for writing SMP safe
677
678 0.8 (03/07/2000) greg kroah-hartman
679 Release to IO networks.
680 Fixed problems that were seen in code by David.
681 Now both Edgeport/4 and Edgeport/2 works properly.
682 Changed most of the functions to use port instead of serial.
683
684 0.7 (02/27/2000) greg kroah-hartman
685 Milestone 3 release.
686 Release to IO Networks
687 ioctl for waiting on line change implemented.
688 ioctl for getting statistics implemented.
689 multiport support working.
690 lsr and msr registers are now handled properly.
691 change break now hooked up and working.
692 support for all known Edgeport devices.
693
694 0.6 (02/22/2000) greg kroah-hartman
695 Release to IO networks.
696 CHASE is implemented correctly when port is closed.
697 SerialOpen now blocks correctly until port is fully opened.
698
699 0.5 (02/20/2000) greg kroah-hartman
700 Release to IO networks.
701 Known problems:
702 modem status register changes are not sent on to the user
703 CHASE is not implemented when the port is closed.
704
705 0.4 (02/16/2000) greg kroah-hartman
706 Second cut at the CeBit demo.
707 Doesn't leak memory on every write to the port
708 Still small leaks on startup.
709 Added support for Edgeport/2 and Edgeport/8
710
711 0.3 (02/15/2000) greg kroah-hartman
712 CeBit demo release.
713 Force the line settings to 4800, 8, 1, e for the demo.
714 Warning! This version leaks memory like crazy!
715
716 0.2 (01/30/2000) greg kroah-hartman
717 Milestone 1 release.
718 Device is found by USB subsystem, enumerated, fimware is downloaded
719 and the descriptors are printed to the debug log, config is set, and
720 green light starts to blink. Open port works, and data can be sent
721 and received at the default settings of the UART. Loopback connector
722 and debug log confirms this.
723
724 0.1 (01/23/2000) greg kroah-hartman
725 Initial release to help IO Networks try to set up their test system.
726 Edgeport4 is recognized, firmware is downloaded, config is set so
727 device blinks green light every 3 sec. Port is bound, but opening,
728 closing, and sending data do not work properly.
729
730
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index 9438909e87a5..7b5e8e4ee2bb 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -394,6 +394,15 @@ config USB_SERIAL_MCT_U232
394 To compile this driver as a module, choose M here: the 394 To compile this driver as a module, choose M here: the
395 module will be called mct_u232. 395 module will be called mct_u232.
396 396
397config USB_SERIAL_NOKIA_DKU2
398 tristate "USB Nokia DKU2 Driver"
399 depends on USB_SERIAL
400 help
401 Say Y here if you want to use a Nokia DKU2 device.
402
403 To compile this driver as a module, choose M here: the
404 module will be called nokia_dku2.
405
397config USB_SERIAL_PL2303 406config USB_SERIAL_PL2303
398 tristate "USB Prolific 2303 Single Port Serial Driver" 407 tristate "USB Prolific 2303 Single Port Serial Driver"
399 depends on USB_SERIAL 408 depends on USB_SERIAL
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile
index 6c7cdcc99a9e..55fd461793b7 100644
--- a/drivers/usb/serial/Makefile
+++ b/drivers/usb/serial/Makefile
@@ -31,6 +31,7 @@ obj-$(CONFIG_USB_SERIAL_KEYSPAN_PDA) += keyspan_pda.o
31obj-$(CONFIG_USB_SERIAL_KLSI) += kl5kusb105.o 31obj-$(CONFIG_USB_SERIAL_KLSI) += kl5kusb105.o
32obj-$(CONFIG_USB_SERIAL_KOBIL_SCT) += kobil_sct.o 32obj-$(CONFIG_USB_SERIAL_KOBIL_SCT) += kobil_sct.o
33obj-$(CONFIG_USB_SERIAL_MCT_U232) += mct_u232.o 33obj-$(CONFIG_USB_SERIAL_MCT_U232) += mct_u232.o
34obj-$(CONFIG_USB_SERIAL_NOKIA_DKU2) += nokia_dku2.o
34obj-$(CONFIG_USB_SERIAL_OMNINET) += omninet.o 35obj-$(CONFIG_USB_SERIAL_OMNINET) += omninet.o
35obj-$(CONFIG_USB_SERIAL_OPTION) += option.o 36obj-$(CONFIG_USB_SERIAL_OPTION) += option.o
36obj-$(CONFIG_USB_SERIAL_PL2303) += pl2303.o 37obj-$(CONFIG_USB_SERIAL_PL2303) += pl2303.o
diff --git a/drivers/usb/serial/airprime.c b/drivers/usb/serial/airprime.c
index 926d4c2c1600..1f29d8837327 100644
--- a/drivers/usb/serial/airprime.c
+++ b/drivers/usb/serial/airprime.c
@@ -30,9 +30,11 @@ static struct usb_driver airprime_driver = {
30 .id_table = id_table, 30 .id_table = id_table,
31}; 31};
32 32
33static struct usb_serial_device_type airprime_device = { 33static struct usb_serial_driver airprime_device = {
34 .owner = THIS_MODULE, 34 .driver = {
35 .name = "airprime", 35 .owner = THIS_MODULE,
36 .name = "airprime",
37 },
36 .id_table = id_table, 38 .id_table = id_table,
37 .num_interrupt_in = NUM_DONT_CARE, 39 .num_interrupt_in = NUM_DONT_CARE,
38 .num_bulk_in = NUM_DONT_CARE, 40 .num_bulk_in = NUM_DONT_CARE,
diff --git a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c
index abb1b2c543bb..84bc0ee4f061 100644
--- a/drivers/usb/serial/belkin_sa.c
+++ b/drivers/usb/serial/belkin_sa.c
@@ -121,10 +121,12 @@ static struct usb_driver belkin_driver = {
121}; 121};
122 122
123/* All of the device info needed for the serial converters */ 123/* All of the device info needed for the serial converters */
124static struct usb_serial_device_type belkin_device = { 124static struct usb_serial_driver belkin_device = {
125 .owner = THIS_MODULE, 125 .driver = {
126 .name = "Belkin / Peracom / GoHubs USB Serial Adapter", 126 .owner = THIS_MODULE,
127 .short_name = "belkin", 127 .name = "belkin",
128 },
129 .description = "Belkin / Peracom / GoHubs USB Serial Adapter",
128 .id_table = id_table_combined, 130 .id_table = id_table_combined,
129 .num_interrupt_in = 1, 131 .num_interrupt_in = 1,
130 .num_bulk_in = 1, 132 .num_bulk_in = 1,
diff --git a/drivers/usb/serial/bus.c b/drivers/usb/serial/bus.c
index 2f612c2d894b..664139afcfa9 100644
--- a/drivers/usb/serial/bus.c
+++ b/drivers/usb/serial/bus.c
@@ -18,7 +18,7 @@
18 18
19static int usb_serial_device_match (struct device *dev, struct device_driver *drv) 19static int usb_serial_device_match (struct device *dev, struct device_driver *drv)
20{ 20{
21 struct usb_serial_device_type *driver; 21 struct usb_serial_driver *driver;
22 const struct usb_serial_port *port; 22 const struct usb_serial_port *port;
23 23
24 /* 24 /*
@@ -44,7 +44,7 @@ struct bus_type usb_serial_bus_type = {
44 44
45static int usb_serial_device_probe (struct device *dev) 45static int usb_serial_device_probe (struct device *dev)
46{ 46{
47 struct usb_serial_device_type *driver; 47 struct usb_serial_driver *driver;
48 struct usb_serial_port *port; 48 struct usb_serial_port *port;
49 int retval = 0; 49 int retval = 0;
50 int minor; 50 int minor;
@@ -57,13 +57,13 @@ static int usb_serial_device_probe (struct device *dev)
57 57
58 driver = port->serial->type; 58 driver = port->serial->type;
59 if (driver->port_probe) { 59 if (driver->port_probe) {
60 if (!try_module_get(driver->owner)) { 60 if (!try_module_get(driver->driver.owner)) {
61 dev_err(dev, "module get failed, exiting\n"); 61 dev_err(dev, "module get failed, exiting\n");
62 retval = -EIO; 62 retval = -EIO;
63 goto exit; 63 goto exit;
64 } 64 }
65 retval = driver->port_probe (port); 65 retval = driver->port_probe (port);
66 module_put(driver->owner); 66 module_put(driver->driver.owner);
67 if (retval) 67 if (retval)
68 goto exit; 68 goto exit;
69 } 69 }
@@ -72,7 +72,7 @@ static int usb_serial_device_probe (struct device *dev)
72 tty_register_device (usb_serial_tty_driver, minor, dev); 72 tty_register_device (usb_serial_tty_driver, minor, dev);
73 dev_info(&port->serial->dev->dev, 73 dev_info(&port->serial->dev->dev,
74 "%s converter now attached to ttyUSB%d\n", 74 "%s converter now attached to ttyUSB%d\n",
75 driver->name, minor); 75 driver->description, minor);
76 76
77exit: 77exit:
78 return retval; 78 return retval;
@@ -80,7 +80,7 @@ exit:
80 80
81static int usb_serial_device_remove (struct device *dev) 81static int usb_serial_device_remove (struct device *dev)
82{ 82{
83 struct usb_serial_device_type *driver; 83 struct usb_serial_driver *driver;
84 struct usb_serial_port *port; 84 struct usb_serial_port *port;
85 int retval = 0; 85 int retval = 0;
86 int minor; 86 int minor;
@@ -92,43 +92,38 @@ static int usb_serial_device_remove (struct device *dev)
92 92
93 driver = port->serial->type; 93 driver = port->serial->type;
94 if (driver->port_remove) { 94 if (driver->port_remove) {
95 if (!try_module_get(driver->owner)) { 95 if (!try_module_get(driver->driver.owner)) {
96 dev_err(dev, "module get failed, exiting\n"); 96 dev_err(dev, "module get failed, exiting\n");
97 retval = -EIO; 97 retval = -EIO;
98 goto exit; 98 goto exit;
99 } 99 }
100 retval = driver->port_remove (port); 100 retval = driver->port_remove (port);
101 module_put(driver->owner); 101 module_put(driver->driver.owner);
102 } 102 }
103exit: 103exit:
104 minor = port->number; 104 minor = port->number;
105 tty_unregister_device (usb_serial_tty_driver, minor); 105 tty_unregister_device (usb_serial_tty_driver, minor);
106 dev_info(dev, "%s converter now disconnected from ttyUSB%d\n", 106 dev_info(dev, "%s converter now disconnected from ttyUSB%d\n",
107 driver->name, minor); 107 driver->description, minor);
108 108
109 return retval; 109 return retval;
110} 110}
111 111
112int usb_serial_bus_register(struct usb_serial_device_type *device) 112int usb_serial_bus_register(struct usb_serial_driver *driver)
113{ 113{
114 int retval; 114 int retval;
115 115
116 if (device->short_name) 116 driver->driver.bus = &usb_serial_bus_type;
117 device->driver.name = (char *)device->short_name; 117 driver->driver.probe = usb_serial_device_probe;
118 else 118 driver->driver.remove = usb_serial_device_remove;
119 device->driver.name = (char *)device->name;
120 device->driver.bus = &usb_serial_bus_type;
121 device->driver.probe = usb_serial_device_probe;
122 device->driver.remove = usb_serial_device_remove;
123 device->driver.owner = device->owner;
124 119
125 retval = driver_register(&device->driver); 120 retval = driver_register(&driver->driver);
126 121
127 return retval; 122 return retval;
128} 123}
129 124
130void usb_serial_bus_deregister(struct usb_serial_device_type *device) 125void usb_serial_bus_deregister(struct usb_serial_driver *driver)
131{ 126{
132 driver_unregister (&device->driver); 127 driver_unregister(&driver->driver);
133} 128}
134 129
diff --git a/drivers/usb/serial/cp2101.c b/drivers/usb/serial/cp2101.c
index 97c78c21e8d1..c5334dd89b12 100644
--- a/drivers/usb/serial/cp2101.c
+++ b/drivers/usb/serial/cp2101.c
@@ -67,15 +67,17 @@ MODULE_DEVICE_TABLE (usb, id_table);
67 67
68static struct usb_driver cp2101_driver = { 68static struct usb_driver cp2101_driver = {
69 .owner = THIS_MODULE, 69 .owner = THIS_MODULE,
70 .name = "CP2101", 70 .name = "cp2101",
71 .probe = usb_serial_probe, 71 .probe = usb_serial_probe,
72 .disconnect = usb_serial_disconnect, 72 .disconnect = usb_serial_disconnect,
73 .id_table = id_table, 73 .id_table = id_table,
74}; 74};
75 75
76static struct usb_serial_device_type cp2101_device = { 76static struct usb_serial_driver cp2101_device = {
77 .owner = THIS_MODULE, 77 .driver = {
78 .name = "CP2101", 78 .owner = THIS_MODULE,
79 .name = "cp2101",
80 },
79 .id_table = id_table, 81 .id_table = id_table,
80 .num_interrupt_in = 0, 82 .num_interrupt_in = 0,
81 .num_bulk_in = 0, 83 .num_bulk_in = 0,
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index b5b431067b08..e581e4ae8483 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -83,10 +83,12 @@ static struct usb_driver cyberjack_driver = {
83 .id_table = id_table, 83 .id_table = id_table,
84}; 84};
85 85
86static struct usb_serial_device_type cyberjack_device = { 86static struct usb_serial_driver cyberjack_device = {
87 .owner = THIS_MODULE, 87 .driver = {
88 .name = "Reiner SCT Cyberjack USB card reader", 88 .owner = THIS_MODULE,
89 .short_name = "cyberjack", 89 .name = "cyberjack",
90 },
91 .description = "Reiner SCT Cyberjack USB card reader",
90 .id_table = id_table, 92 .id_table = id_table,
91 .num_interrupt_in = 1, 93 .num_interrupt_in = 1,
92 .num_bulk_in = 1, 94 .num_bulk_in = 1,
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index 9ee1aaff2fcd..af9290ed257b 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -176,10 +176,12 @@ static unsigned int cypress_buf_put(struct cypress_buf *cb, const char *buf, u
176static unsigned int cypress_buf_get(struct cypress_buf *cb, char *buf, unsigned int count); 176static unsigned int cypress_buf_get(struct cypress_buf *cb, char *buf, unsigned int count);
177 177
178 178
179static struct usb_serial_device_type cypress_earthmate_device = { 179static struct usb_serial_driver cypress_earthmate_device = {
180 .owner = THIS_MODULE, 180 .driver = {
181 .name = "DeLorme Earthmate USB", 181 .owner = THIS_MODULE,
182 .short_name = "earthmate", 182 .name = "earthmate",
183 },
184 .description = "DeLorme Earthmate USB",
183 .id_table = id_table_earthmate, 185 .id_table = id_table_earthmate,
184 .num_interrupt_in = 1, 186 .num_interrupt_in = 1,
185 .num_interrupt_out = 1, 187 .num_interrupt_out = 1,
@@ -203,10 +205,12 @@ static struct usb_serial_device_type cypress_earthmate_device = {
203 .write_int_callback = cypress_write_int_callback, 205 .write_int_callback = cypress_write_int_callback,
204}; 206};
205 207
206static struct usb_serial_device_type cypress_hidcom_device = { 208static struct usb_serial_driver cypress_hidcom_device = {
207 .owner = THIS_MODULE, 209 .driver = {
208 .name = "HID->COM RS232 Adapter", 210 .owner = THIS_MODULE,
209 .short_name = "cyphidcom", 211 .name = "cyphidcom",
212 },
213 .description = "HID->COM RS232 Adapter",
210 .id_table = id_table_cyphidcomrs232, 214 .id_table = id_table_cyphidcomrs232,
211 .num_interrupt_in = 1, 215 .num_interrupt_in = 1,
212 .num_interrupt_out = 1, 216 .num_interrupt_out = 1,
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index a19a47f6cf12..dc74644a603d 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -503,10 +503,12 @@ static struct usb_driver digi_driver = {
503 503
504/* device info needed for the Digi serial converter */ 504/* device info needed for the Digi serial converter */
505 505
506static struct usb_serial_device_type digi_acceleport_2_device = { 506static struct usb_serial_driver digi_acceleport_2_device = {
507 .owner = THIS_MODULE, 507 .driver = {
508 .name = "Digi 2 port USB adapter", 508 .owner = THIS_MODULE,
509 .short_name = "digi_2", 509 .name = "digi_2",
510 },
511 .description = "Digi 2 port USB adapter",
510 .id_table = id_table_2, 512 .id_table = id_table_2,
511 .num_interrupt_in = 0, 513 .num_interrupt_in = 0,
512 .num_bulk_in = 4, 514 .num_bulk_in = 4,
@@ -530,10 +532,12 @@ static struct usb_serial_device_type digi_acceleport_2_device = {
530 .shutdown = digi_shutdown, 532 .shutdown = digi_shutdown,
531}; 533};
532 534
533static struct usb_serial_device_type digi_acceleport_4_device = { 535static struct usb_serial_driver digi_acceleport_4_device = {
534 .owner = THIS_MODULE, 536 .driver = {
535 .name = "Digi 4 port USB adapter", 537 .owner = THIS_MODULE,
536 .short_name = "digi_4", 538 .name = "digi_4",
539 },
540 .description = "Digi 4 port USB adapter",
537 .id_table = id_table_4, 541 .id_table = id_table_4,
538 .num_interrupt_in = 0, 542 .num_interrupt_in = 0,
539 .num_bulk_in = 5, 543 .num_bulk_in = 5,
diff --git a/drivers/usb/serial/empeg.c b/drivers/usb/serial/empeg.c
index 8d562ab454a8..0b0546dcc7b9 100644
--- a/drivers/usb/serial/empeg.c
+++ b/drivers/usb/serial/empeg.c
@@ -112,9 +112,11 @@ static struct usb_driver empeg_driver = {
112 .id_table = id_table, 112 .id_table = id_table,
113}; 113};
114 114
115static struct usb_serial_device_type empeg_device = { 115static struct usb_serial_driver empeg_device = {
116 .owner = THIS_MODULE, 116 .driver = {
117 .name = "Empeg", 117 .owner = THIS_MODULE,
118 .name = "empeg",
119 },
118 .id_table = id_table, 120 .id_table = id_table,
119 .num_interrupt_in = 0, 121 .num_interrupt_in = 0,
120 .num_bulk_in = 1, 122 .num_bulk_in = 1,
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 5a8631c8a4a7..61204bf7cd78 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -411,6 +411,8 @@ static struct usb_device_id id_table_combined [] = {
411 { USB_DEVICE(FTDI_VID, FTDI_ELV_UM100_PID) }, 411 { USB_DEVICE(FTDI_VID, FTDI_ELV_UM100_PID) },
412 { USB_DEVICE(FTDI_VID, FTDI_ELV_UR100_PID) }, 412 { USB_DEVICE(FTDI_VID, FTDI_ELV_UR100_PID) },
413 { USB_DEVICE(FTDI_VID, FTDI_ELV_ALC8500_PID) }, 413 { USB_DEVICE(FTDI_VID, FTDI_ELV_ALC8500_PID) },
414 { USB_DEVICE(FTDI_VID, FTDI_PYRAMID_PID) },
415 { USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1000PC_PID) },
414 /* 416 /*
415 * These will probably use user-space drivers. Uncomment them if 417 * These will probably use user-space drivers. Uncomment them if
416 * you need them or use the user-specified vendor/product module 418 * you need them or use the user-specified vendor/product module
@@ -428,7 +430,6 @@ static struct usb_device_id id_table_combined [] = {
428 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_T1100_PID) }, */ 430 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_T1100_PID) }, */
429 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_PCD200_PID) }, */ 431 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_PCD200_PID) }, */
430 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_ULA200_PID) }, */ 432 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_ULA200_PID) }, */
431 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1000PC_PID) }, */
432 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_CSI8_PID) }, */ 433 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_CSI8_PID) }, */
433 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_EM1000DL_PID) }, */ 434 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_EM1000DL_PID) }, */
434 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_PCK100_PID) }, */ 435 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_PCK100_PID) }, */
@@ -471,6 +472,9 @@ static struct usb_device_id id_table_combined [] = {
471 { USB_DEVICE(FTDI_VID, FTDI_MHAM_Y6_PID) }, 472 { USB_DEVICE(FTDI_VID, FTDI_MHAM_Y6_PID) },
472 { USB_DEVICE(FTDI_VID, FTDI_MHAM_Y8_PID) }, 473 { USB_DEVICE(FTDI_VID, FTDI_MHAM_Y8_PID) },
473 { USB_DEVICE(EVOLUTION_VID, EVOLUTION_ER1_PID) }, 474 { USB_DEVICE(EVOLUTION_VID, EVOLUTION_ER1_PID) },
475 { USB_DEVICE(FTDI_VID, FTDI_ARTEMIS_PID) },
476 { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16_PID) },
477 { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16HR_PID) },
474 { }, /* Optional parameter entry */ 478 { }, /* Optional parameter entry */
475 { } /* Terminating entry */ 479 { } /* Terminating entry */
476}; 480};
@@ -558,10 +562,12 @@ static unsigned short int ftdi_232am_baud_to_divisor (int baud);
558static __u32 ftdi_232bm_baud_base_to_divisor (int baud, int base); 562static __u32 ftdi_232bm_baud_base_to_divisor (int baud, int base);
559static __u32 ftdi_232bm_baud_to_divisor (int baud); 563static __u32 ftdi_232bm_baud_to_divisor (int baud);
560 564
561static struct usb_serial_device_type ftdi_sio_device = { 565static struct usb_serial_driver ftdi_sio_device = {
562 .owner = THIS_MODULE, 566 .driver = {
563 .name = "FTDI USB Serial Device", 567 .owner = THIS_MODULE,
564 .short_name = "ftdi_sio", 568 .name = "ftdi_sio",
569 },
570 .description = "FTDI USB Serial Device",
565 .id_table = id_table_combined, 571 .id_table = id_table_combined,
566 .num_interrupt_in = 0, 572 .num_interrupt_in = 0,
567 .num_bulk_in = 1, 573 .num_bulk_in = 1,
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h
index 2c35d74cc6d6..ddb63df31ce6 100644
--- a/drivers/usb/serial/ftdi_sio.h
+++ b/drivers/usb/serial/ftdi_sio.h
@@ -199,6 +199,19 @@
199#define FTDI_PIEGROUP_PID 0xF208 /* Product Id */ 199#define FTDI_PIEGROUP_PID 0xF208 /* Product Id */
200 200
201/* 201/*
202 * Definitions for Artemis astronomical USB based cameras
203 * Check it at http://www.artemisccd.co.uk/
204 */
205#define FTDI_ARTEMIS_PID 0xDF28 /* All Artemis Cameras */
206
207/*
208 * Definitions for ATIK Instruments astronomical USB based cameras
209 * Check it at http://www.atik-instruments.com/
210 */
211#define FTDI_ATIK_ATK16_PID 0xDF30 /* ATIK ATK-16 Camera */
212#define FTDI_ATIK_ATK16HR_PID 0xDF31 /* ATIK ATK-16HR Camera */
213
214/*
202 * Protego product ids 215 * Protego product ids
203 */ 216 */
204#define PROTEGO_SPECIAL_1 0xFC70 /* special/unknown device */ 217#define PROTEGO_SPECIAL_1 0xFC70 /* special/unknown device */
@@ -329,6 +342,9 @@
329#define EVOLUTION_VID 0xDEEE /* Vendor ID */ 342#define EVOLUTION_VID 0xDEEE /* Vendor ID */
330#define EVOLUTION_ER1_PID 0x0300 /* ER1 Control Module */ 343#define EVOLUTION_ER1_PID 0x0300 /* ER1 Control Module */
331 344
345/* Pyramid Computer GmbH */
346#define FTDI_PYRAMID_PID 0xE6C8 /* Pyramid Appliance Display */
347
332/* Commands */ 348/* Commands */
333#define FTDI_SIO_RESET 0 /* Reset the port */ 349#define FTDI_SIO_RESET 0 /* Reset the port */
334#define FTDI_SIO_MODEM_CTRL 1 /* Set the modem control register */ 350#define FTDI_SIO_MODEM_CTRL 1 /* Set the modem control register */
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c
index 2ef614d5c8f2..35820bda7ae1 100644
--- a/drivers/usb/serial/garmin_gps.c
+++ b/drivers/usb/serial/garmin_gps.c
@@ -1468,16 +1468,13 @@ static void garmin_shutdown (struct usb_serial *serial)
1468} 1468}
1469 1469
1470 1470
1471
1472
1473
1474
1475
1476/* All of the device info needed */ 1471/* All of the device info needed */
1477static struct usb_serial_device_type garmin_device = { 1472static struct usb_serial_driver garmin_device = {
1478 .owner = THIS_MODULE, 1473 .driver = {
1479 .name = "Garmin GPS usb/tty", 1474 .owner = THIS_MODULE,
1480 .short_name = "garmin_gps", 1475 .name = "garmin_gps",
1476 },
1477 .description = "Garmin GPS usb/tty",
1481 .id_table = id_table, 1478 .id_table = id_table,
1482 .num_interrupt_in = 1, 1479 .num_interrupt_in = 1,
1483 .num_bulk_in = 1, 1480 .num_bulk_in = 1,
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 5f7d3193d355..8909208f506a 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -36,10 +36,11 @@ MODULE_PARM_DESC(product, "User specified USB idProduct");
36static struct usb_device_id generic_device_ids[2]; /* Initially all zeroes. */ 36static struct usb_device_id generic_device_ids[2]; /* Initially all zeroes. */
37 37
38/* All of the device info needed for the Generic Serial Converter */ 38/* All of the device info needed for the Generic Serial Converter */
39struct usb_serial_device_type usb_serial_generic_device = { 39struct usb_serial_driver usb_serial_generic_device = {
40 .owner = THIS_MODULE, 40 .driver = {
41 .name = "Generic", 41 .owner = THIS_MODULE,
42 .short_name = "generic", 42 .name = "generic",
43 },
43 .id_table = generic_device_ids, 44 .id_table = generic_device_ids,
44 .num_interrupt_in = NUM_DONT_CARE, 45 .num_interrupt_in = NUM_DONT_CARE,
45 .num_bulk_in = NUM_DONT_CARE, 46 .num_bulk_in = NUM_DONT_CARE,
diff --git a/drivers/usb/serial/hp4x.c b/drivers/usb/serial/hp4x.c
index 64d55fbd206e..8eadfb705601 100644
--- a/drivers/usb/serial/hp4x.c
+++ b/drivers/usb/serial/hp4x.c
@@ -38,15 +38,17 @@ MODULE_DEVICE_TABLE(usb, id_table);
38 38
39static struct usb_driver hp49gp_driver = { 39static struct usb_driver hp49gp_driver = {
40 .owner = THIS_MODULE, 40 .owner = THIS_MODULE,
41 .name = "HP4X", 41 .name = "hp4X",
42 .probe = usb_serial_probe, 42 .probe = usb_serial_probe,
43 .disconnect = usb_serial_disconnect, 43 .disconnect = usb_serial_disconnect,
44 .id_table = id_table, 44 .id_table = id_table,
45}; 45};
46 46
47static struct usb_serial_device_type hp49gp_device = { 47static struct usb_serial_driver hp49gp_device = {
48 .owner = THIS_MODULE, 48 .driver = {
49 .name = "HP4X", 49 .owner = THIS_MODULE,
50 .name = "hp4X",
51 },
50 .id_table = id_table, 52 .id_table = id_table,
51 .num_interrupt_in = NUM_DONT_CARE, 53 .num_interrupt_in = NUM_DONT_CARE,
52 .num_bulk_in = NUM_DONT_CARE, 54 .num_bulk_in = NUM_DONT_CARE,
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index 04bfe279d763..dc4c498bd1ed 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -27,225 +27,6 @@
27 * Networks technical support, or Peter Berger <pberger@brimson.com>, 27 * Networks technical support, or Peter Berger <pberger@brimson.com>,
28 * or Al Borchers <alborchers@steinerpoint.com>. 28 * or Al Borchers <alborchers@steinerpoint.com>.
29 * 29 *
30 * Version history:
31 *
32 * 2003_04_03 al borchers
33 * - fixed a bug (that shows up with dosemu) where the tty struct is
34 * used in a callback after it has been freed
35 *
36 * 2.3 2002_03_08 greg kroah-hartman
37 * - fixed bug when multiple devices were attached at the same time.
38 *
39 * 2.2 2001_11_14 greg kroah-hartman
40 * - fixed bug in edge_close that kept the port from being used more
41 * than once.
42 * - fixed memory leak on device removal.
43 * - fixed potential double free of memory when command urb submitting
44 * failed.
45 * - other small cleanups when the device is removed
46 *
47 * 2.1 2001_07_09 greg kroah-hartman
48 * - added support for TIOCMBIS and TIOCMBIC.
49 *
50 * (04/08/2001) gb
51 * - Identify version on module load.
52 *
53 * 2.0 2001_03_05 greg kroah-hartman
54 * - reworked entire driver to fit properly in with the other usb-serial
55 * drivers. Occasional oopses still happen, but it's a good start.
56 *
57 * 1.2.3 (02/23/2001) greg kroah-hartman
58 * - changed device table to work properly for 2.4.x final format.
59 * - fixed problem with dropping data at high data rates.
60 *
61 * 1.2.2 (11/27/2000) greg kroah-hartman
62 * - cleaned up more NTisms.
63 * - Added device table for 2.4.0-test11
64 *
65 * 1.2.1 (11/08/2000) greg kroah-hartman
66 * - Started to clean up NTisms.
67 * - Fixed problem with dev field of urb for kernels >= 2.4.0-test9
68 *
69 * 1.2 (10/17/2000) David Iacovelli
70 * Remove all EPIC code and GPL source
71 * Fix RELEVANT_IFLAG macro to include flow control
72 * changes port configuration changes.
73 * Fix redefinition of SERIAL_MAGIC
74 * Change all timeout values to 5 seconds
75 * Tried to fix the UHCI multiple urb submission, but failed miserably.
76 * it seems to work fine with OHCI.
77 * ( Greg take a look at the #if 0 at end of WriteCmdUsb() we must
78 * find a way to work arount this UHCI bug )
79 *
80 * 1.1 (10/11/2000) David Iacovelli
81 * Fix XON/XOFF flow control to support both IXON and IXOFF
82 *
83 * 0.9.27 (06/30/2000) David Iacovelli
84 * Added transmit queue and now allocate urb for command writes.
85 *
86 * 0.9.26 (06/29/2000) David Iacovelli
87 * Add support for 80251 based edgeport
88 *
89 * 0.9.25 (06/27/2000) David Iacovelli
90 * Do not close the port if it has multiple opens.
91 *
92 * 0.9.24 (05/26/2000) David Iacovelli
93 * Add IOCTLs to support RXTX and JAVA POS
94 * and first cut at running BlackBox Demo
95 *
96 * 0.9.23 (05/24/2000) David Iacovelli
97 * Add IOCTLs to support RXTX and JAVA POS
98 *
99 * 0.9.22 (05/23/2000) David Iacovelli
100 * fixed bug in enumeration. If epconfig turns on mapping by
101 * path after a device is already plugged in, we now update
102 * the mapping correctly
103 *
104 * 0.9.21 (05/16/2000) David Iacovelli
105 * Added BlockUntilChaseResp() to also wait for txcredits
106 * Updated the way we allocate and handle write URBs
107 * Add debug code to dump buffers
108 *
109 * 0.9.20 (05/01/2000) David Iacovelli
110 * change driver to use usb/tts/
111 *
112 * 0.9.19 (05/01/2000) David Iacovelli
113 * Update code to compile if DEBUG is off
114 *
115 * 0.9.18 (04/28/2000) David Iacovelli
116 * cleanup and test tty_register with devfs
117 *
118 * 0.9.17 (04/27/2000) greg kroah-hartman
119 * changed tty_register around to be like the way it
120 * was before, but now it works properly with devfs.
121 *
122 * 0.9.16 (04/26/2000) david iacovelli
123 * Fixed bug in GetProductInfo()
124 *
125 * 0.9.15 (04/25/2000) david iacovelli
126 * Updated enumeration
127 *
128 * 0.9.14 (04/24/2000) david iacovelli
129 * Removed all config/status IOCTLS and
130 * converted to using /proc/edgeport
131 * still playing with devfs
132 *
133 * 0.9.13 (04/24/2000) david iacovelli
134 * Removed configuration based on ttyUSB0
135 * Added support for configuration using /prod/edgeport
136 * first attempt at using devfs (not working yet!)
137 * Added IOCTL to GetProductInfo()
138 * Added support for custom baud rates
139 * Add support for random port numbers
140 *
141 * 0.9.12 (04/18/2000) david iacovelli
142 * added additional configuration IOCTLs
143 * use ttyUSB0 for configuration
144 *
145 * 0.9.11 (04/17/2000) greg kroah-hartman
146 * fixed module initialization race conditions.
147 * made all urbs dynamically allocated.
148 * made driver devfs compatible. now it only registers the tty device
149 * when the device is actually plugged in.
150 *
151 * 0.9.10 (04/13/2000) greg kroah-hartman
152 * added proc interface framework.
153 *
154 * 0.9.9 (04/13/2000) david iacovelli
155 * added enumeration code and ioctls to configure the device
156 *
157 * 0.9.8 (04/12/2000) david iacovelli
158 * Change interrupt read start when device is plugged in
159 * and stop when device is removed
160 * process interrupt reads when all ports are closed
161 * (keep value of rxBytesAvail consistent with the edgeport)
162 * set the USB_BULK_QUEUE flag so that we can shove a bunch
163 * of urbs at once down the pipe
164 *
165 * 0.9.7 (04/10/2000) david iacovelli
166 * start to add enumeration code.
167 * generate serial number for epic devices
168 * add support for kdb
169 *
170 * 0.9.6 (03/30/2000) david iacovelli
171 * add IOCTL to get string, manufacture, and boot descriptors
172 *
173 * 0.9.5 (03/14/2000) greg kroah-hartman
174 * more error checking added to SerialOpen to try to fix UHCI open problem
175 *
176 * 0.9.4 (03/09/2000) greg kroah-hartman
177 * added more error checking to handle oops when data is hanging
178 * around and tty is abruptly closed.
179 *
180 * 0.9.3 (03/09/2000) david iacovelli
181 * Add epic support for xon/xoff chars
182 * play with performance
183 *
184 * 0.9.2 (03/08/2000) greg kroah-hartman
185 * changed most "info" calls to "dbg"
186 * implemented flow control properly in the termios call
187 *
188 * 0.9.1 (03/08/2000) david iacovelli
189 * added EPIC support
190 * enabled bootloader update
191 *
192 * 0.9 (03/08/2000) greg kroah-hartman
193 * Release to IO networks.
194 * Integrated changes that David made
195 * made getting urbs for writing SMP safe
196 *
197 * 0.8 (03/07/2000) greg kroah-hartman
198 * Release to IO networks.
199 * Fixed problems that were seen in code by David.
200 * Now both Edgeport/4 and Edgeport/2 works properly.
201 * Changed most of the functions to use port instead of serial.
202 *
203 * 0.7 (02/27/2000) greg kroah-hartman
204 * Milestone 3 release.
205 * Release to IO Networks
206 * ioctl for waiting on line change implemented.
207 * ioctl for getting statistics implemented.
208 * multiport support working.
209 * lsr and msr registers are now handled properly.
210 * change break now hooked up and working.
211 * support for all known Edgeport devices.
212 *
213 * 0.6 (02/22/2000) greg kroah-hartman
214 * Release to IO networks.
215 * CHASE is implemented correctly when port is closed.
216 * SerialOpen now blocks correctly until port is fully opened.
217 *
218 * 0.5 (02/20/2000) greg kroah-hartman
219 * Release to IO networks.
220 * Known problems:
221 * modem status register changes are not sent on to the user
222 * CHASE is not implemented when the port is closed.
223 *
224 * 0.4 (02/16/2000) greg kroah-hartman
225 * Second cut at the CeBit demo.
226 * Doesn't leak memory on every write to the port
227 * Still small leaks on startup.
228 * Added support for Edgeport/2 and Edgeport/8
229 *
230 * 0.3 (02/15/2000) greg kroah-hartman
231 * CeBit demo release.
232 * Force the line settings to 4800, 8, 1, e for the demo.
233 * Warning! This version leaks memory like crazy!
234 *
235 * 0.2 (01/30/2000) greg kroah-hartman
236 * Milestone 1 release.
237 * Device is found by USB subsystem, enumerated, fimware is downloaded
238 * and the descriptors are printed to the debug log, config is set, and
239 * green light starts to blink. Open port works, and data can be sent
240 * and received at the default settings of the UART. Loopback connector
241 * and debug log confirms this.
242 *
243 * 0.1 (01/23/2000) greg kroah-hartman
244 * Initial release to help IO Networks try to set up their test system.
245 * Edgeport4 is recognized, firmware is downloaded, config is set so
246 * device blinks green light every 3 sec. Port is bound, but opening,
247 * closing, and sending data do not work properly.
248 *
249 */ 30 */
250 31
251#include <linux/config.h> 32#include <linux/config.h>
diff --git a/drivers/usb/serial/io_tables.h b/drivers/usb/serial/io_tables.h
index e7ffe02408bd..fad561c04c76 100644
--- a/drivers/usb/serial/io_tables.h
+++ b/drivers/usb/serial/io_tables.h
@@ -75,10 +75,12 @@ static struct usb_device_id id_table_combined [] = {
75 75
76MODULE_DEVICE_TABLE (usb, id_table_combined); 76MODULE_DEVICE_TABLE (usb, id_table_combined);
77 77
78static struct usb_serial_device_type edgeport_2port_device = { 78static struct usb_serial_driver edgeport_2port_device = {
79 .owner = THIS_MODULE, 79 .driver = {
80 .name = "Edgeport 2 port adapter", 80 .owner = THIS_MODULE,
81 .short_name = "edgeport_2", 81 .name = "edgeport_2",
82 },
83 .description = "Edgeport 2 port adapter",
82 .id_table = edgeport_2port_id_table, 84 .id_table = edgeport_2port_id_table,
83 .num_interrupt_in = 1, 85 .num_interrupt_in = 1,
84 .num_bulk_in = 1, 86 .num_bulk_in = 1,
@@ -103,10 +105,12 @@ static struct usb_serial_device_type edgeport_2port_device = {
103 .write_bulk_callback = edge_bulk_out_data_callback, 105 .write_bulk_callback = edge_bulk_out_data_callback,
104}; 106};
105 107
106static struct usb_serial_device_type edgeport_4port_device = { 108static struct usb_serial_driver edgeport_4port_device = {
107 .owner = THIS_MODULE, 109 .driver = {
108 .name = "Edgeport 4 port adapter", 110 .owner = THIS_MODULE,
109 .short_name = "edgeport_4", 111 .name = "edgeport_4",
112 },
113 .description = "Edgeport 4 port adapter",
110 .id_table = edgeport_4port_id_table, 114 .id_table = edgeport_4port_id_table,
111 .num_interrupt_in = 1, 115 .num_interrupt_in = 1,
112 .num_bulk_in = 1, 116 .num_bulk_in = 1,
@@ -131,10 +135,12 @@ static struct usb_serial_device_type edgeport_4port_device = {
131 .write_bulk_callback = edge_bulk_out_data_callback, 135 .write_bulk_callback = edge_bulk_out_data_callback,
132}; 136};
133 137
134static struct usb_serial_device_type edgeport_8port_device = { 138static struct usb_serial_driver edgeport_8port_device = {
135 .owner = THIS_MODULE, 139 .driver = {
136 .name = "Edgeport 8 port adapter", 140 .owner = THIS_MODULE,
137 .short_name = "edgeport_8", 141 .name = "edgeport_8",
142 },
143 .description = "Edgeport 8 port adapter",
138 .id_table = edgeport_8port_id_table, 144 .id_table = edgeport_8port_id_table,
139 .num_interrupt_in = 1, 145 .num_interrupt_in = 1,
140 .num_bulk_in = 1, 146 .num_bulk_in = 1,
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index ebf9967f7c86..832b6d6734c0 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -2982,10 +2982,12 @@ static unsigned int edge_buf_get(struct edge_buf *eb, char *buf,
2982} 2982}
2983 2983
2984 2984
2985static struct usb_serial_device_type edgeport_1port_device = { 2985static struct usb_serial_driver edgeport_1port_device = {
2986 .owner = THIS_MODULE, 2986 .driver = {
2987 .name = "Edgeport TI 1 port adapter", 2987 .owner = THIS_MODULE,
2988 .short_name = "edgeport_ti_1", 2988 .name = "edgeport_ti_1",
2989 },
2990 .description = "Edgeport TI 1 port adapter",
2989 .id_table = edgeport_1port_id_table, 2991 .id_table = edgeport_1port_id_table,
2990 .num_interrupt_in = 1, 2992 .num_interrupt_in = 1,
2991 .num_bulk_in = 1, 2993 .num_bulk_in = 1,
@@ -3010,10 +3012,12 @@ static struct usb_serial_device_type edgeport_1port_device = {
3010 .write_bulk_callback = edge_bulk_out_callback, 3012 .write_bulk_callback = edge_bulk_out_callback,
3011}; 3013};
3012 3014
3013static struct usb_serial_device_type edgeport_2port_device = { 3015static struct usb_serial_driver edgeport_2port_device = {
3014 .owner = THIS_MODULE, 3016 .driver = {
3015 .name = "Edgeport TI 2 port adapter", 3017 .owner = THIS_MODULE,
3016 .short_name = "edgeport_ti_2", 3018 .name = "edgeport_ti_2",
3019 },
3020 .description = "Edgeport TI 2 port adapter",
3017 .id_table = edgeport_2port_id_table, 3021 .id_table = edgeport_2port_id_table,
3018 .num_interrupt_in = 1, 3022 .num_interrupt_in = 1,
3019 .num_bulk_in = 2, 3023 .num_bulk_in = 2,
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c
index c05c2a2a0f31..d5d066488100 100644
--- a/drivers/usb/serial/ipaq.c
+++ b/drivers/usb/serial/ipaq.c
@@ -92,24 +92,7 @@ static void ipaq_destroy_lists(struct usb_serial_port *port);
92static struct usb_device_id ipaq_id_table [] = { 92static struct usb_device_id ipaq_id_table [] = {
93 /* The first entry is a placeholder for the insmod-specified device */ 93 /* The first entry is a placeholder for the insmod-specified device */
94 { USB_DEVICE(0x049F, 0x0003) }, 94 { USB_DEVICE(0x049F, 0x0003) },
95 { USB_DEVICE(0x1690, 0x0601) }, /* Askey USB Sync */ 95 { USB_DEVICE(0x0104, 0x00BE) }, /* Socket USB Sync */
96 { USB_DEVICE(0x0960, 0x0065) }, /* BCOM USB Sync 0065 */
97 { USB_DEVICE(0x0960, 0x0066) }, /* BCOM USB Sync 0066 */
98 { USB_DEVICE(0x0960, 0x0067) }, /* BCOM USB Sync 0067 */
99 { USB_DEVICE(0x07CF, 0x2001) }, /* CASIO USB Sync 2001 */
100 { USB_DEVICE(0x07CF, 0x2002) }, /* CASIO USB Sync 2002 */
101 { USB_DEVICE(0x07CF, 0x2003) }, /* CASIO USB Sync 2003 */
102 { USB_DEVICE(0x049F, 0x0003) }, /* Compaq iPAQ USB Sync */
103 { USB_DEVICE(0x049F, 0x0032) }, /* Compaq iPAQ USB Sync */
104 { USB_DEVICE(0x413C, 0x4001) }, /* Dell Axim USB Sync */
105 { USB_DEVICE(0x413C, 0x4002) }, /* Dell Axim USB Sync */
106 { USB_DEVICE(0x413C, 0x4003) }, /* Dell Axim USB Sync */
107 { USB_DEVICE(0x413C, 0x4004) }, /* Dell Axim USB Sync */
108 { USB_DEVICE(0x413C, 0x4005) }, /* Dell Axim USB Sync */
109 { USB_DEVICE(0x413C, 0x4006) }, /* Dell Axim USB Sync */
110 { USB_DEVICE(0x413C, 0x4007) }, /* Dell Axim USB Sync */
111 { USB_DEVICE(0x413C, 0x4008) }, /* Dell Axim USB Sync */
112 { USB_DEVICE(0x413C, 0x4009) }, /* Dell Axim USB Sync */
113 { USB_DEVICE(0x03F0, 0x1016) }, /* HP USB Sync */ 96 { USB_DEVICE(0x03F0, 0x1016) }, /* HP USB Sync */
114 { USB_DEVICE(0x03F0, 0x1116) }, /* HP USB Sync 1611 */ 97 { USB_DEVICE(0x03F0, 0x1116) }, /* HP USB Sync 1611 */
115 { USB_DEVICE(0x03F0, 0x1216) }, /* HP USB Sync 1612 */ 98 { USB_DEVICE(0x03F0, 0x1216) }, /* HP USB Sync 1612 */
@@ -125,7 +108,13 @@ static struct usb_device_id ipaq_id_table [] = {
125 { USB_DEVICE(0x03F0, 0x5016) }, /* HP USB Sync 1650 */ 108 { USB_DEVICE(0x03F0, 0x5016) }, /* HP USB Sync 1650 */
126 { USB_DEVICE(0x03F0, 0x5116) }, /* HP USB Sync 1651 */ 109 { USB_DEVICE(0x03F0, 0x5116) }, /* HP USB Sync 1651 */
127 { USB_DEVICE(0x03F0, 0x5216) }, /* HP USB Sync 1652 */ 110 { USB_DEVICE(0x03F0, 0x5216) }, /* HP USB Sync 1652 */
128 { USB_DEVICE(0x094B, 0x0001) }, /* Linkup Systems USB Sync */ 111 { USB_DEVICE(0x0409, 0x00D5) }, /* NEC USB Sync */
112 { USB_DEVICE(0x0409, 0x00D6) }, /* NEC USB Sync */
113 { USB_DEVICE(0x0409, 0x00D7) }, /* NEC USB Sync */
114 { USB_DEVICE(0x0409, 0x8024) }, /* NEC USB Sync */
115 { USB_DEVICE(0x0409, 0x8025) }, /* NEC USB Sync */
116 { USB_DEVICE(0x043E, 0x9C01) }, /* LGE USB Sync */
117 { USB_DEVICE(0x045E, 0x00CE) }, /* Microsoft USB Sync */
129 { USB_DEVICE(0x045E, 0x0400) }, /* Windows Powered Pocket PC 2002 */ 118 { USB_DEVICE(0x045E, 0x0400) }, /* Windows Powered Pocket PC 2002 */
130 { USB_DEVICE(0x045E, 0x0401) }, /* Windows Powered Pocket PC 2002 */ 119 { USB_DEVICE(0x045E, 0x0401) }, /* Windows Powered Pocket PC 2002 */
131 { USB_DEVICE(0x045E, 0x0402) }, /* Windows Powered Pocket PC 2002 */ 120 { USB_DEVICE(0x045E, 0x0402) }, /* Windows Powered Pocket PC 2002 */
@@ -251,17 +240,81 @@ static struct usb_device_id ipaq_id_table [] = {
251 { USB_DEVICE(0x045E, 0x04E8) }, /* Windows Powered Smartphone 2003 */ 240 { USB_DEVICE(0x045E, 0x04E8) }, /* Windows Powered Smartphone 2003 */
252 { USB_DEVICE(0x045E, 0x04E9) }, /* Windows Powered Smartphone 2003 */ 241 { USB_DEVICE(0x045E, 0x04E9) }, /* Windows Powered Smartphone 2003 */
253 { USB_DEVICE(0x045E, 0x04EA) }, /* Windows Powered Smartphone 2003 */ 242 { USB_DEVICE(0x045E, 0x04EA) }, /* Windows Powered Smartphone 2003 */
254 { USB_DEVICE(0x0961, 0x0010) }, /* Portatec USB Sync */ 243 { USB_DEVICE(0x049F, 0x0003) }, /* Compaq iPAQ USB Sync */
255 { USB_DEVICE(0x5E04, 0xCE00) }, /* SAGEM Wireless Assistant */ 244 { USB_DEVICE(0x049F, 0x0032) }, /* Compaq iPAQ USB Sync */
256 { USB_DEVICE(0x0104, 0x00BE) }, /* Socket USB Sync */ 245 { USB_DEVICE(0x04A4, 0x0014) }, /* Hitachi USB Sync */
246 { USB_DEVICE(0x04AD, 0x0301) }, /* USB Sync 0301 */
247 { USB_DEVICE(0x04AD, 0x0302) }, /* USB Sync 0302 */
248 { USB_DEVICE(0x04AD, 0x0303) }, /* USB Sync 0303 */
249 { USB_DEVICE(0x04C5, 0x1058) }, /* FUJITSU USB Sync */
250 { USB_DEVICE(0x04C5, 0x1079) }, /* FUJITSU USB Sync */
251 { USB_DEVICE(0x04DA, 0x2500) }, /* Panasonic USB Sync */
252 { USB_DEVICE(0x04E8, 0x5F00) }, /* Samsung NEXiO USB Sync */
253 { USB_DEVICE(0x04E8, 0x5F01) }, /* Samsung NEXiO USB Sync */
254 { USB_DEVICE(0x04E8, 0x5F02) }, /* Samsung NEXiO USB Sync */
255 { USB_DEVICE(0x04E8, 0x5F03) }, /* Samsung NEXiO USB Sync */
256 { USB_DEVICE(0x04E8, 0x5F04) }, /* Samsung NEXiO USB Sync */
257 { USB_DEVICE(0x04E8, 0x6611) }, /* Samsung MITs USB Sync */
258 { USB_DEVICE(0x04E8, 0x6613) }, /* Samsung MITs USB Sync */
259 { USB_DEVICE(0x04E8, 0x6615) }, /* Samsung MITs USB Sync */
260 { USB_DEVICE(0x04E8, 0x6617) }, /* Samsung MITs USB Sync */
261 { USB_DEVICE(0x04E8, 0x6619) }, /* Samsung MITs USB Sync */
262 { USB_DEVICE(0x04E8, 0x661B) }, /* Samsung MITs USB Sync */
263 { USB_DEVICE(0x04E8, 0x662E) }, /* Samsung MITs USB Sync */
264 { USB_DEVICE(0x04E8, 0x6630) }, /* Samsung MITs USB Sync */
265 { USB_DEVICE(0x04E8, 0x6632) }, /* Samsung MITs USB Sync */
266 { USB_DEVICE(0x04f1, 0x3011) }, /* JVC USB Sync */
267 { USB_DEVICE(0x04F1, 0x3012) }, /* JVC USB Sync */
268 { USB_DEVICE(0x0502, 0x1631) }, /* c10 Series */
269 { USB_DEVICE(0x0502, 0x1632) }, /* c20 Series */
270 { USB_DEVICE(0x0502, 0x16E1) }, /* Acer n10 Handheld USB Sync */
271 { USB_DEVICE(0x0502, 0x16E2) }, /* Acer n20 Handheld USB Sync */
272 { USB_DEVICE(0x0502, 0x16E3) }, /* Acer n30 Handheld USB Sync */
273 { USB_DEVICE(0x0536, 0x01A0) }, /* HHP PDT */
274 { USB_DEVICE(0x0543, 0x0ED9) }, /* ViewSonic Color Pocket PC V35 */
275 { USB_DEVICE(0x0543, 0x1527) }, /* ViewSonic Color Pocket PC V36 */
276 { USB_DEVICE(0x0543, 0x1529) }, /* ViewSonic Color Pocket PC V37 */
277 { USB_DEVICE(0x0543, 0x152B) }, /* ViewSonic Color Pocket PC V38 */
278 { USB_DEVICE(0x0543, 0x152E) }, /* ViewSonic Pocket PC */
279 { USB_DEVICE(0x0543, 0x1921) }, /* ViewSonic Communicator Pocket PC */
280 { USB_DEVICE(0x0543, 0x1922) }, /* ViewSonic Smartphone */
281 { USB_DEVICE(0x0543, 0x1923) }, /* ViewSonic Pocket PC V30 */
282 { USB_DEVICE(0x05E0, 0x2000) }, /* Symbol USB Sync */
283 { USB_DEVICE(0x05E0, 0x2001) }, /* Symbol USB Sync 0x2001 */
284 { USB_DEVICE(0x05E0, 0x2002) }, /* Symbol USB Sync 0x2002 */
285 { USB_DEVICE(0x05E0, 0x2003) }, /* Symbol USB Sync 0x2003 */
286 { USB_DEVICE(0x05E0, 0x2004) }, /* Symbol USB Sync 0x2004 */
287 { USB_DEVICE(0x05E0, 0x2005) }, /* Symbol USB Sync 0x2005 */
288 { USB_DEVICE(0x05E0, 0x2006) }, /* Symbol USB Sync 0x2006 */
289 { USB_DEVICE(0x05E0, 0x2007) }, /* Symbol USB Sync 0x2007 */
290 { USB_DEVICE(0x05E0, 0x2008) }, /* Symbol USB Sync 0x2008 */
291 { USB_DEVICE(0x05E0, 0x2009) }, /* Symbol USB Sync 0x2009 */
292 { USB_DEVICE(0x05E0, 0x200A) }, /* Symbol USB Sync 0x200A */
293 { USB_DEVICE(0x067E, 0x1001) }, /* Intermec Mobile Computer */
294 { USB_DEVICE(0x07CF, 0x2001) }, /* CASIO USB Sync 2001 */
295 { USB_DEVICE(0x07CF, 0x2002) }, /* CASIO USB Sync 2002 */
296 { USB_DEVICE(0x07CF, 0x2003) }, /* CASIO USB Sync 2003 */
257 { USB_DEVICE(0x0930, 0x0700) }, /* TOSHIBA USB Sync 0700 */ 297 { USB_DEVICE(0x0930, 0x0700) }, /* TOSHIBA USB Sync 0700 */
258 { USB_DEVICE(0x0930, 0x0705) }, /* TOSHIBA Pocket PC e310 */ 298 { USB_DEVICE(0x0930, 0x0705) }, /* TOSHIBA Pocket PC e310 */
299 { USB_DEVICE(0x0930, 0x0706) }, /* TOSHIBA Pocket PC e740 */
259 { USB_DEVICE(0x0930, 0x0707) }, /* TOSHIBA Pocket PC e330 Series */ 300 { USB_DEVICE(0x0930, 0x0707) }, /* TOSHIBA Pocket PC e330 Series */
260 { USB_DEVICE(0x0930, 0x0708) }, /* TOSHIBA Pocket PC e350 Series */ 301 { USB_DEVICE(0x0930, 0x0708) }, /* TOSHIBA Pocket PC e350 Series */
261 { USB_DEVICE(0x0930, 0x0706) }, /* TOSHIBA Pocket PC e740 */
262 { USB_DEVICE(0x0930, 0x0709) }, /* TOSHIBA Pocket PC e750 Series */ 302 { USB_DEVICE(0x0930, 0x0709) }, /* TOSHIBA Pocket PC e750 Series */
263 { USB_DEVICE(0x0930, 0x070A) }, /* TOSHIBA Pocket PC e400 Series */ 303 { USB_DEVICE(0x0930, 0x070A) }, /* TOSHIBA Pocket PC e400 Series */
264 { USB_DEVICE(0x0930, 0x070B) }, /* TOSHIBA Pocket PC e800 Series */ 304 { USB_DEVICE(0x0930, 0x070B) }, /* TOSHIBA Pocket PC e800 Series */
305 { USB_DEVICE(0x094B, 0x0001) }, /* Linkup Systems USB Sync */
306 { USB_DEVICE(0x0960, 0x0065) }, /* BCOM USB Sync 0065 */
307 { USB_DEVICE(0x0960, 0x0066) }, /* BCOM USB Sync 0066 */
308 { USB_DEVICE(0x0960, 0x0067) }, /* BCOM USB Sync 0067 */
309 { USB_DEVICE(0x0961, 0x0010) }, /* Portatec USB Sync */
310 { USB_DEVICE(0x099E, 0x0052) }, /* Trimble GeoExplorer */
311 { USB_DEVICE(0x099E, 0x4000) }, /* TDS Data Collector */
312 { USB_DEVICE(0x0B05, 0x4200) }, /* ASUS USB Sync */
313 { USB_DEVICE(0x0B05, 0x4201) }, /* ASUS USB Sync */
314 { USB_DEVICE(0x0B05, 0x4202) }, /* ASUS USB Sync */
315 { USB_DEVICE(0x0B05, 0x420F) }, /* ASUS USB Sync */
316 { USB_DEVICE(0x0B05, 0x9200) }, /* ASUS USB Sync */
317 { USB_DEVICE(0x0B05, 0x9202) }, /* ASUS USB Sync */
265 { USB_DEVICE(0x0BB4, 0x00CE) }, /* HTC USB Sync */ 318 { USB_DEVICE(0x0BB4, 0x00CE) }, /* HTC USB Sync */
266 { USB_DEVICE(0x0BB4, 0x0A01) }, /* PocketPC USB Sync */ 319 { USB_DEVICE(0x0BB4, 0x0A01) }, /* PocketPC USB Sync */
267 { USB_DEVICE(0x0BB4, 0x0A02) }, /* PocketPC USB Sync */ 320 { USB_DEVICE(0x0BB4, 0x0A02) }, /* PocketPC USB Sync */
@@ -422,116 +475,67 @@ static struct usb_device_id ipaq_id_table [] = {
422 { USB_DEVICE(0x0BB4, 0x0A9D) }, /* SmartPhone USB Sync */ 475 { USB_DEVICE(0x0BB4, 0x0A9D) }, /* SmartPhone USB Sync */
423 { USB_DEVICE(0x0BB4, 0x0A9E) }, /* SmartPhone USB Sync */ 476 { USB_DEVICE(0x0BB4, 0x0A9E) }, /* SmartPhone USB Sync */
424 { USB_DEVICE(0x0BB4, 0x0A9F) }, /* SmartPhone USB Sync */ 477 { USB_DEVICE(0x0BB4, 0x0A9F) }, /* SmartPhone USB Sync */
425 { USB_DEVICE(0x0409, 0x00D5) }, /* NEC USB Sync */
426 { USB_DEVICE(0x0409, 0x00D6) }, /* NEC USB Sync */
427 { USB_DEVICE(0x0409, 0x00D7) }, /* NEC USB Sync */
428 { USB_DEVICE(0x0409, 0x8024) }, /* NEC USB Sync */
429 { USB_DEVICE(0x0409, 0x8025) }, /* NEC USB Sync */
430 { USB_DEVICE(0x04A4, 0x0014) }, /* Hitachi USB Sync */
431 { USB_DEVICE(0x0BF8, 0x1001) }, /* Fujitsu Siemens Computers USB Sync */ 478 { USB_DEVICE(0x0BF8, 0x1001) }, /* Fujitsu Siemens Computers USB Sync */
432 { USB_DEVICE(0x0F98, 0x0201) }, /* Cyberbank USB Sync */ 479 { USB_DEVICE(0x0C44, 0x03A2) }, /* Motorola iDEN Smartphone */
433 { USB_DEVICE(0x0502, 0x16E1) }, /* Acer n10 Handheld USB Sync */
434 { USB_DEVICE(0x0502, 0x16E3) }, /* Acer n30 Handheld USB Sync */
435 { USB_DEVICE(0x0502, 0x16E2) }, /* Acer n20 Handheld USB Sync */
436 { USB_DEVICE(0x0502, 0x1631) }, /* c10 Series */
437 { USB_DEVICE(0x0502, 0x1632) }, /* c20 Series */
438 { USB_DEVICE(0x0B05, 0x9202) }, /* ASUS USB Sync */
439 { USB_DEVICE(0x0B05, 0x420F) }, /* ASUS USB Sync */
440 { USB_DEVICE(0x0B05, 0x4200) }, /* ASUS USB Sync */
441 { USB_DEVICE(0x0B05, 0x4201) }, /* ASUS USB Sync */
442 { USB_DEVICE(0x0B05, 0x4202) }, /* ASUS USB Sync */
443 { USB_DEVICE(0x0B05, 0x9200) }, /* ASUS USB Sync */
444 { USB_DEVICE(0x0C8E, 0x6000) }, /* Cesscom Luxian Series */ 480 { USB_DEVICE(0x0C8E, 0x6000) }, /* Cesscom Luxian Series */
445 { USB_DEVICE(0x04AD, 0x0301) }, /* USB Sync 0301 */ 481 { USB_DEVICE(0x0CAD, 0x9001) }, /* Motorola PowerPad Pocket PC Device */
446 { USB_DEVICE(0x04AD, 0x0302) }, /* USB Sync 0302 */ 482 { USB_DEVICE(0x0F4E, 0x0200) }, /* Freedom Scientific USB Sync */
447 { USB_DEVICE(0x04AD, 0x0303) }, /* USB Sync 0303 */ 483 { USB_DEVICE(0x0F98, 0x0201) }, /* Cyberbank USB Sync */
484 { USB_DEVICE(0x0FB8, 0x3001) }, /* Wistron USB Sync */
485 { USB_DEVICE(0x0FB8, 0x3002) }, /* Wistron USB Sync */
486 { USB_DEVICE(0x0FB8, 0x3003) }, /* Wistron USB Sync */
487 { USB_DEVICE(0x0FB8, 0x4001) }, /* Wistron USB Sync */
488 { USB_DEVICE(0x1066, 0x00CE) }, /* E-TEN USB Sync */
448 { USB_DEVICE(0x1066, 0x0300) }, /* E-TEN P3XX Pocket PC */ 489 { USB_DEVICE(0x1066, 0x0300) }, /* E-TEN P3XX Pocket PC */
449 { USB_DEVICE(0x1066, 0x0500) }, /* E-TEN P5XX Pocket PC */ 490 { USB_DEVICE(0x1066, 0x0500) }, /* E-TEN P5XX Pocket PC */
450 { USB_DEVICE(0x1066, 0x0600) }, /* E-TEN P6XX Pocket PC */ 491 { USB_DEVICE(0x1066, 0x0600) }, /* E-TEN P6XX Pocket PC */
451 { USB_DEVICE(0x1066, 0x0700) }, /* E-TEN P7XX Pocket PC */ 492 { USB_DEVICE(0x1066, 0x0700) }, /* E-TEN P7XX Pocket PC */
452 { USB_DEVICE(0x1066, 0x00CE) }, /* E-TEN USB Sync */ 493 { USB_DEVICE(0x1114, 0x0001) }, /* Psion Teklogix Sync 753x */
453 { USB_DEVICE(0x0F4E, 0x0200) }, /* Freedom Scientific USB Sync */ 494 { USB_DEVICE(0x1114, 0x0004) }, /* Psion Teklogix Sync netBookPro */
454 { USB_DEVICE(0x04C5, 0x1058) }, /* FUJITSU USB Sync */ 495 { USB_DEVICE(0x1114, 0x0006) }, /* Psion Teklogix Sync 7525 */
455 { USB_DEVICE(0x04C5, 0x1079) }, /* FUJITSU USB Sync */ 496 { USB_DEVICE(0x1182, 0x1388) }, /* VES USB Sync */
456 { USB_DEVICE(0x067E, 0x1001) }, /* Intermec Mobile Computer */ 497 { USB_DEVICE(0x11D9, 0x1002) }, /* Rugged Pocket PC 2003 */
457 { USB_DEVICE(0x04f1, 0x3011) }, /* JVC USB Sync */ 498 { USB_DEVICE(0x11D9, 0x1003) }, /* Rugged Pocket PC 2003 */
458 { USB_DEVICE(0x04F1, 0x3012) }, /* JVC USB Sync */ 499 { USB_DEVICE(0x1231, 0xCE01) }, /* USB Sync 03 */
459 { USB_DEVICE(0x3708, 0x20CE) }, /* Legend USB Sync */ 500 { USB_DEVICE(0x1231, 0xCE02) }, /* USB Sync 03 */
460 { USB_DEVICE(0x3708, 0x21CE) }, /* Lenovo USB Sync */ 501 { USB_DEVICE(0x1690, 0x0601) }, /* Askey USB Sync */
461 { USB_DEVICE(0x043E, 0x9C01) }, /* LGE USB Sync */ 502 { USB_DEVICE(0x22B8, 0x4204) }, /* Motorola MPx200 Smartphone */
462 { USB_DEVICE(0x04DA, 0x2500) }, /* Panasonic USB Sync */ 503 { USB_DEVICE(0x22B8, 0x4214) }, /* Motorola MPc GSM */
463 { USB_DEVICE(0x3340, 0x0B1C) }, /* Generic PPC StrongARM */ 504 { USB_DEVICE(0x22B8, 0x4224) }, /* Motorola MPx220 Smartphone */
464 { USB_DEVICE(0x3340, 0x0E3A) }, /* Generic PPC USB Sync */ 505 { USB_DEVICE(0x22B8, 0x4234) }, /* Motorola MPc CDMA */
465 { USB_DEVICE(0x3340, 0x0F3A) }, /* Generic SmartPhone USB Sync */ 506 { USB_DEVICE(0x22B8, 0x4244) }, /* Motorola MPx100 Smartphone */
466 { USB_DEVICE(0x3340, 0x0F1C) }, /* Itautec USB Sync */ 507 { USB_DEVICE(0x3340, 0x011C) }, /* Mio DigiWalker PPC StrongARM */
467 { USB_DEVICE(0x3340, 0x1326) }, /* Itautec USB Sync */
468 { USB_DEVICE(0x3340, 0x3326) }, /* MEDION Winodws Moble USB Sync */
469 { USB_DEVICE(0x3340, 0x0326) }, /* Mio DigiWalker 338 */ 508 { USB_DEVICE(0x3340, 0x0326) }, /* Mio DigiWalker 338 */
470 { USB_DEVICE(0x3340, 0x0426) }, /* Mio DigiWalker 338 */ 509 { USB_DEVICE(0x3340, 0x0426) }, /* Mio DigiWalker 338 */
471 { USB_DEVICE(0x3340, 0x011C) }, /* Mio DigiWalker PPC StrongARM */
472 { USB_DEVICE(0x3340, 0x053A) }, /* Mio DigiWalker SmartPhone USB Sync */
473 { USB_DEVICE(0x3340, 0x043A) }, /* Mio DigiWalker USB Sync */ 510 { USB_DEVICE(0x3340, 0x043A) }, /* Mio DigiWalker USB Sync */
474 { USB_DEVICE(0x3340, 0x071C) }, /* MiTAC USB Sync */
475 { USB_DEVICE(0x3340, 0x051C) }, /* MiTAC USB Sync 528 */ 511 { USB_DEVICE(0x3340, 0x051C) }, /* MiTAC USB Sync 528 */
476 { USB_DEVICE(0x3340, 0x2326) }, /* Vobis USB Sync */ 512 { USB_DEVICE(0x3340, 0x053A) }, /* Mio DigiWalker SmartPhone USB Sync */
513 { USB_DEVICE(0x3340, 0x071C) }, /* MiTAC USB Sync */
514 { USB_DEVICE(0x3340, 0x0B1C) }, /* Generic PPC StrongARM */
515 { USB_DEVICE(0x3340, 0x0E3A) }, /* Generic PPC USB Sync */
516 { USB_DEVICE(0x3340, 0x0F1C) }, /* Itautec USB Sync */
517 { USB_DEVICE(0x3340, 0x0F3A) }, /* Generic SmartPhone USB Sync */
518 { USB_DEVICE(0x3340, 0x1326) }, /* Itautec USB Sync */
477 { USB_DEVICE(0x3340, 0x191C) }, /* YAKUMO USB Sync */ 519 { USB_DEVICE(0x3340, 0x191C) }, /* YAKUMO USB Sync */
520 { USB_DEVICE(0x3340, 0x2326) }, /* Vobis USB Sync */
521 { USB_DEVICE(0x3340, 0x3326) }, /* MEDION Winodws Moble USB Sync */
522 { USB_DEVICE(0x3708, 0x20CE) }, /* Legend USB Sync */
523 { USB_DEVICE(0x3708, 0x21CE) }, /* Lenovo USB Sync */
478 { USB_DEVICE(0x4113, 0x0210) }, /* Mobile Media Technology USB Sync */ 524 { USB_DEVICE(0x4113, 0x0210) }, /* Mobile Media Technology USB Sync */
479 { USB_DEVICE(0x4113, 0x0211) }, /* Mobile Media Technology USB Sync */ 525 { USB_DEVICE(0x4113, 0x0211) }, /* Mobile Media Technology USB Sync */
480 { USB_DEVICE(0x4113, 0x0400) }, /* Mobile Media Technology USB Sync */ 526 { USB_DEVICE(0x4113, 0x0400) }, /* Mobile Media Technology USB Sync */
481 { USB_DEVICE(0x4113, 0x0410) }, /* Mobile Media Technology USB Sync */ 527 { USB_DEVICE(0x4113, 0x0410) }, /* Mobile Media Technology USB Sync */
482 { USB_DEVICE(0x0CAD, 0x9001) }, /* Motorola PowerPad Pocket PC Device */ 528 { USB_DEVICE(0x413C, 0x4001) }, /* Dell Axim USB Sync */
483 { USB_DEVICE(0x0C44, 0x03A2) }, /* Motorola iDEN Smartphone */ 529 { USB_DEVICE(0x413C, 0x4002) }, /* Dell Axim USB Sync */
484 { USB_DEVICE(0x04E8, 0x6611) }, /* Samsung MITs USB Sync */ 530 { USB_DEVICE(0x413C, 0x4003) }, /* Dell Axim USB Sync */
485 { USB_DEVICE(0x04E8, 0x6613) }, /* Samsung MITs USB Sync */ 531 { USB_DEVICE(0x413C, 0x4004) }, /* Dell Axim USB Sync */
486 { USB_DEVICE(0x04E8, 0x6615) }, /* Samsung MITs USB Sync */ 532 { USB_DEVICE(0x413C, 0x4005) }, /* Dell Axim USB Sync */
487 { USB_DEVICE(0x04E8, 0x6617) }, /* Samsung MITs USB Sync */ 533 { USB_DEVICE(0x413C, 0x4006) }, /* Dell Axim USB Sync */
488 { USB_DEVICE(0x04E8, 0x6619) }, /* Samsung MITs USB Sync */ 534 { USB_DEVICE(0x413C, 0x4007) }, /* Dell Axim USB Sync */
489 { USB_DEVICE(0x04E8, 0x661B) }, /* Samsung MITs USB Sync */ 535 { USB_DEVICE(0x413C, 0x4008) }, /* Dell Axim USB Sync */
490 { USB_DEVICE(0x04E8, 0x5F00) }, /* Samsung NEXiO USB Sync */ 536 { USB_DEVICE(0x413C, 0x4009) }, /* Dell Axim USB Sync */
491 { USB_DEVICE(0x04E8, 0x5F01) }, /* Samsung NEXiO USB Sync */
492 { USB_DEVICE(0x04E8, 0x5F02) }, /* Samsung NEXiO USB Sync */
493 { USB_DEVICE(0x04E8, 0x5F03) }, /* Samsung NEXiO USB Sync */
494 { USB_DEVICE(0x04E8, 0x5F04) }, /* Samsung NEXiO USB Sync */
495 { USB_DEVICE(0x04E8, 0x662E) }, /* Samsung MITs USB Sync */
496 { USB_DEVICE(0x04E8, 0x6630) }, /* Samsung MITs USB Sync */
497 { USB_DEVICE(0x04E8, 0x6632) }, /* Samsung MITs USB Sync */
498 { USB_DEVICE(0x4505, 0x0010) }, /* Smartphone */ 537 { USB_DEVICE(0x4505, 0x0010) }, /* Smartphone */
499 { USB_DEVICE(0x05E0, 0x2000) }, /* Symbol USB Sync */ 538 { USB_DEVICE(0x5E04, 0xCE00) }, /* SAGEM Wireless Assistant */
500 { USB_DEVICE(0x05E0, 0x2001) }, /* Symbol USB Sync 0x2001 */
501 { USB_DEVICE(0x05E0, 0x2002) }, /* Symbol USB Sync 0x2002 */
502 { USB_DEVICE(0x05E0, 0x2003) }, /* Symbol USB Sync 0x2003 */
503 { USB_DEVICE(0x05E0, 0x2004) }, /* Symbol USB Sync 0x2004 */
504 { USB_DEVICE(0x05E0, 0x2005) }, /* Symbol USB Sync 0x2005 */
505 { USB_DEVICE(0x05E0, 0x2006) }, /* Symbol USB Sync 0x2006 */
506 { USB_DEVICE(0x05E0, 0x2007) }, /* Symbol USB Sync 0x2007 */
507 { USB_DEVICE(0x05E0, 0x2008) }, /* Symbol USB Sync 0x2008 */
508 { USB_DEVICE(0x05E0, 0x2009) }, /* Symbol USB Sync 0x2009 */
509 { USB_DEVICE(0x05E0, 0x200A) }, /* Symbol USB Sync 0x200A */
510 { USB_DEVICE(0x1182, 0x1388) }, /* VES USB Sync */
511 { USB_DEVICE(0x0543, 0x0ED9) }, /* ViewSonic Color Pocket PC V35 */
512 { USB_DEVICE(0x0543, 0x1527) }, /* ViewSonic Color Pocket PC V36 */
513 { USB_DEVICE(0x0543, 0x1529) }, /* ViewSonic Color Pocket PC V37 */
514 { USB_DEVICE(0x0543, 0x152B) }, /* ViewSonic Color Pocket PC V38 */
515 { USB_DEVICE(0x0543, 0x152E) }, /* ViewSonic Pocket PC */
516 { USB_DEVICE(0x0543, 0x1921) }, /* ViewSonic Communicator Pocket PC */
517 { USB_DEVICE(0x0543, 0x1922) }, /* ViewSonic Smartphone */
518 { USB_DEVICE(0x0543, 0x1923) }, /* ViewSonic Pocket PC V30 */
519 { USB_DEVICE(0x0536, 0x01A0) }, /* HHP PDT */
520 { USB_DEVICE(0x099E, 0x0052) }, /* Trimble GeoExplorer */
521 { USB_DEVICE(0x099E, 0x4000) }, /* TDS Data Collector */
522 { USB_DEVICE(0x0FB8, 0x3001) }, /* Wistron USB Sync */
523 { USB_DEVICE(0x0FB8, 0x3002) }, /* Wistron USB Sync */
524 { USB_DEVICE(0x0FB8, 0x3003) }, /* Wistron USB Sync */
525 { USB_DEVICE(0x0FB8, 0x4001) }, /* Wistron USB Sync */
526 { USB_DEVICE(0x11D9, 0x1003) }, /* Rugged Pocket PC 2003 */
527 { USB_DEVICE(0x11D9, 0x1002) }, /* Rugged Pocket PC 2003 */
528 { USB_DEVICE(0x22B8, 0x4204) }, /* Motorola MPx200 Smartphone */
529 { USB_DEVICE(0x22B8, 0x4214) }, /* Motorola MPc GSM */
530 { USB_DEVICE(0x22B8, 0x4224) }, /* Motorola MPx220 Smartphone */
531 { USB_DEVICE(0x22B8, 0x4234) }, /* Motorola MPc CDMA */
532 { USB_DEVICE(0x22B8, 0x4244) }, /* Motorola MPx100 Smartphone */
533 { USB_DEVICE(0x1231, 0xCE01) }, /* USB Sync 03 */
534 { USB_DEVICE(0x1231, 0xCE02) }, /* USB Sync 03 */
535 { } /* Terminating entry */ 539 { } /* Terminating entry */
536}; 540};
537 541
@@ -547,9 +551,12 @@ static struct usb_driver ipaq_driver = {
547 551
548 552
549/* All of the device info needed for the Compaq iPAQ */ 553/* All of the device info needed for the Compaq iPAQ */
550static struct usb_serial_device_type ipaq_device = { 554static struct usb_serial_driver ipaq_device = {
551 .owner = THIS_MODULE, 555 .driver = {
552 .name = "PocketPC PDA", 556 .owner = THIS_MODULE,
557 .name = "ipaq",
558 },
559 .description = "PocketPC PDA",
553 .id_table = ipaq_id_table, 560 .id_table = ipaq_id_table,
554 .num_interrupt_in = NUM_DONT_CARE, 561 .num_interrupt_in = NUM_DONT_CARE,
555 .num_bulk_in = 1, 562 .num_bulk_in = 1,
diff --git a/drivers/usb/serial/ipw.c b/drivers/usb/serial/ipw.c
index 85e242459c27..a02fada85362 100644
--- a/drivers/usb/serial/ipw.c
+++ b/drivers/usb/serial/ipw.c
@@ -443,10 +443,12 @@ static int ipw_disconnect(struct usb_serial_port *port)
443 return 0; 443 return 0;
444} 444}
445 445
446static struct usb_serial_device_type ipw_device = { 446static struct usb_serial_driver ipw_device = {
447 .owner = THIS_MODULE, 447 .driver = {
448 .name = "IPWireless converter", 448 .owner = THIS_MODULE,
449 .short_name = "ipw", 449 .name = "ipw",
450 },
451 .description = "IPWireless converter",
450 .id_table = usb_ipw_ids, 452 .id_table = usb_ipw_ids,
451 .num_interrupt_in = NUM_DONT_CARE, 453 .num_interrupt_in = NUM_DONT_CARE,
452 .num_bulk_in = 1, 454 .num_bulk_in = 1,
diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c
index 937b2fdd7171..19f329e9bdcf 100644
--- a/drivers/usb/serial/ir-usb.c
+++ b/drivers/usb/serial/ir-usb.c
@@ -133,9 +133,12 @@ static struct usb_driver ir_driver = {
133}; 133};
134 134
135 135
136static struct usb_serial_device_type ir_device = { 136static struct usb_serial_driver ir_device = {
137 .owner = THIS_MODULE, 137 .driver = {
138 .name = "IR Dongle", 138 .owner = THIS_MODULE,
139 .name = "ir-usb",
140 },
141 .description = "IR Dongle",
139 .id_table = id_table, 142 .id_table = id_table,
140 .num_interrupt_in = 1, 143 .num_interrupt_in = 1,
141 .num_bulk_in = 1, 144 .num_bulk_in = 1,
diff --git a/drivers/usb/serial/keyspan.h b/drivers/usb/serial/keyspan.h
index e9b45b768aca..5cfc13b5e56f 100644
--- a/drivers/usb/serial/keyspan.h
+++ b/drivers/usb/serial/keyspan.h
@@ -570,10 +570,12 @@ static struct usb_device_id keyspan_4port_ids[] = {
570}; 570};
571 571
572/* Structs for the devices, pre and post renumeration. */ 572/* Structs for the devices, pre and post renumeration. */
573static struct usb_serial_device_type keyspan_pre_device = { 573static struct usb_serial_driver keyspan_pre_device = {
574 .owner = THIS_MODULE, 574 .driver = {
575 .name = "Keyspan - (without firmware)", 575 .owner = THIS_MODULE,
576 .short_name = "keyspan_no_firm", 576 .name = "keyspan_no_firm",
577 },
578 .description = "Keyspan - (without firmware)",
577 .id_table = keyspan_pre_ids, 579 .id_table = keyspan_pre_ids,
578 .num_interrupt_in = NUM_DONT_CARE, 580 .num_interrupt_in = NUM_DONT_CARE,
579 .num_bulk_in = NUM_DONT_CARE, 581 .num_bulk_in = NUM_DONT_CARE,
@@ -582,10 +584,12 @@ static struct usb_serial_device_type keyspan_pre_device = {
582 .attach = keyspan_fake_startup, 584 .attach = keyspan_fake_startup,
583}; 585};
584 586
585static struct usb_serial_device_type keyspan_1port_device = { 587static struct usb_serial_driver keyspan_1port_device = {
586 .owner = THIS_MODULE, 588 .driver = {
587 .name = "Keyspan 1 port adapter", 589 .owner = THIS_MODULE,
588 .short_name = "keyspan_1", 590 .name = "keyspan_1",
591 },
592 .description = "Keyspan 1 port adapter",
589 .id_table = keyspan_1port_ids, 593 .id_table = keyspan_1port_ids,
590 .num_interrupt_in = NUM_DONT_CARE, 594 .num_interrupt_in = NUM_DONT_CARE,
591 .num_bulk_in = NUM_DONT_CARE, 595 .num_bulk_in = NUM_DONT_CARE,
@@ -607,10 +611,12 @@ static struct usb_serial_device_type keyspan_1port_device = {
607 .shutdown = keyspan_shutdown, 611 .shutdown = keyspan_shutdown,
608}; 612};
609 613
610static struct usb_serial_device_type keyspan_2port_device = { 614static struct usb_serial_driver keyspan_2port_device = {
611 .owner = THIS_MODULE, 615 .driver = {
612 .name = "Keyspan 2 port adapter", 616 .owner = THIS_MODULE,
613 .short_name = "keyspan_2", 617 .name = "keyspan_2",
618 },
619 .description = "Keyspan 2 port adapter",
614 .id_table = keyspan_2port_ids, 620 .id_table = keyspan_2port_ids,
615 .num_interrupt_in = NUM_DONT_CARE, 621 .num_interrupt_in = NUM_DONT_CARE,
616 .num_bulk_in = NUM_DONT_CARE, 622 .num_bulk_in = NUM_DONT_CARE,
@@ -632,10 +638,12 @@ static struct usb_serial_device_type keyspan_2port_device = {
632 .shutdown = keyspan_shutdown, 638 .shutdown = keyspan_shutdown,
633}; 639};
634 640
635static struct usb_serial_device_type keyspan_4port_device = { 641static struct usb_serial_driver keyspan_4port_device = {
636 .owner = THIS_MODULE, 642 .driver = {
637 .name = "Keyspan 4 port adapter", 643 .owner = THIS_MODULE,
638 .short_name = "keyspan_4", 644 .name = "keyspan_4",
645 },
646 .description = "Keyspan 4 port adapter",
639 .id_table = keyspan_4port_ids, 647 .id_table = keyspan_4port_ids,
640 .num_interrupt_in = NUM_DONT_CARE, 648 .num_interrupt_in = NUM_DONT_CARE,
641 .num_bulk_in = 5, 649 .num_bulk_in = 5,
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index 635c384cb15a..cd4f48bd83b6 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -783,10 +783,12 @@ static void keyspan_pda_shutdown (struct usb_serial *serial)
783} 783}
784 784
785#ifdef KEYSPAN 785#ifdef KEYSPAN
786static struct usb_serial_device_type keyspan_pda_fake_device = { 786static struct usb_serial_driver keyspan_pda_fake_device = {
787 .owner = THIS_MODULE, 787 .driver = {
788 .name = "Keyspan PDA - (prerenumeration)", 788 .owner = THIS_MODULE,
789 .short_name = "keyspan_pda_pre", 789 .name = "keyspan_pda_pre",
790 },
791 .description = "Keyspan PDA - (prerenumeration)",
790 .id_table = id_table_fake, 792 .id_table = id_table_fake,
791 .num_interrupt_in = NUM_DONT_CARE, 793 .num_interrupt_in = NUM_DONT_CARE,
792 .num_bulk_in = NUM_DONT_CARE, 794 .num_bulk_in = NUM_DONT_CARE,
@@ -797,10 +799,12 @@ static struct usb_serial_device_type keyspan_pda_fake_device = {
797#endif 799#endif
798 800
799#ifdef XIRCOM 801#ifdef XIRCOM
800static struct usb_serial_device_type xircom_pgs_fake_device = { 802static struct usb_serial_driver xircom_pgs_fake_device = {
801 .owner = THIS_MODULE, 803 .driver = {
802 .name = "Xircom / Entregra PGS - (prerenumeration)", 804 .owner = THIS_MODULE,
803 .short_name = "xircom_no_firm", 805 .name = "xircom_no_firm",
806 },
807 .description = "Xircom / Entregra PGS - (prerenumeration)",
804 .id_table = id_table_fake_xircom, 808 .id_table = id_table_fake_xircom,
805 .num_interrupt_in = NUM_DONT_CARE, 809 .num_interrupt_in = NUM_DONT_CARE,
806 .num_bulk_in = NUM_DONT_CARE, 810 .num_bulk_in = NUM_DONT_CARE,
@@ -810,10 +814,12 @@ static struct usb_serial_device_type xircom_pgs_fake_device = {
810}; 814};
811#endif 815#endif
812 816
813static struct usb_serial_device_type keyspan_pda_device = { 817static struct usb_serial_driver keyspan_pda_device = {
814 .owner = THIS_MODULE, 818 .driver = {
815 .name = "Keyspan PDA", 819 .owner = THIS_MODULE,
816 .short_name = "keyspan_pda", 820 .name = "keyspan_pda",
821 },
822 .description = "Keyspan PDA",
817 .id_table = id_table_std, 823 .id_table = id_table_std,
818 .num_interrupt_in = 1, 824 .num_interrupt_in = 1,
819 .num_bulk_in = 0, 825 .num_bulk_in = 0,
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index a11e829e38c8..a8951c0fd020 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -123,10 +123,12 @@ static struct usb_driver kl5kusb105d_driver = {
123 .id_table = id_table, 123 .id_table = id_table,
124}; 124};
125 125
126static struct usb_serial_device_type kl5kusb105d_device = { 126static struct usb_serial_driver kl5kusb105d_device = {
127 .owner = THIS_MODULE, 127 .driver = {
128 .name = "KL5KUSB105D / PalmConnect", 128 .owner = THIS_MODULE,
129 .short_name = "kl5kusb105d", 129 .name = "kl5kusb105d",
130 },
131 .description = "KL5KUSB105D / PalmConnect",
130 .id_table = id_table, 132 .id_table = id_table,
131 .num_interrupt_in = 1, 133 .num_interrupt_in = 1,
132 .num_bulk_in = 1, 134 .num_bulk_in = 1,
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index fe4c98a75171..9456dd9dd136 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -105,9 +105,12 @@ static struct usb_driver kobil_driver = {
105}; 105};
106 106
107 107
108static struct usb_serial_device_type kobil_device = { 108static struct usb_serial_driver kobil_device = {
109 .owner = THIS_MODULE, 109 .driver = {
110 .name = "KOBIL USB smart card terminal", 110 .owner = THIS_MODULE,
111 .name = "kobil",
112 },
113 .description = "KOBIL USB smart card terminal",
111 .id_table = id_table, 114 .id_table = id_table,
112 .num_interrupt_in = NUM_DONT_CARE, 115 .num_interrupt_in = NUM_DONT_CARE,
113 .num_bulk_in = 0, 116 .num_bulk_in = 0,
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
index 50b6369647d2..ca5dbadb9b7e 100644
--- a/drivers/usb/serial/mct_u232.c
+++ b/drivers/usb/serial/mct_u232.c
@@ -132,10 +132,12 @@ static struct usb_driver mct_u232_driver = {
132 .id_table = id_table_combined, 132 .id_table = id_table_combined,
133}; 133};
134 134
135static struct usb_serial_device_type mct_u232_device = { 135static struct usb_serial_driver mct_u232_device = {
136 .owner = THIS_MODULE, 136 .driver = {
137 .name = "MCT U232", 137 .owner = THIS_MODULE,
138 .short_name = "mct_u232", 138 .name = "mct_u232",
139 },
140 .description = "MCT U232",
139 .id_table = id_table_combined, 141 .id_table = id_table_combined,
140 .num_interrupt_in = 2, 142 .num_interrupt_in = 2,
141 .num_bulk_in = 0, 143 .num_bulk_in = 0,
diff --git a/drivers/usb/serial/nokia_dku2.c b/drivers/usb/serial/nokia_dku2.c
new file mode 100644
index 000000000000..fad01bef3a64
--- /dev/null
+++ b/drivers/usb/serial/nokia_dku2.c
@@ -0,0 +1,142 @@
1/*
2 * Nokia DKU2 USB driver
3 *
4 * Copyright (C) 2004
5 * Author: C Kemp
6 *
7 * This program is largely derived from work by the linux-usb group
8 * and associated source files. Please see the usb/serial files for
9 * individual credits and copyrights.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * 20.09.2005 - Matthias Blaesing <matthias.blaesing@rwth-aachen.de>
17 * Added short name to device structure to make driver load into kernel 2.6.13
18 *
19 * 20.09.2005 - Matthias Blaesing <matthias.blaesing@rwth-aachen.de>
20 * Added usb_deregister to exit code - to allow remove and reinsert of module
21 */
22
23
24#include <linux/config.h>
25#include <linux/kernel.h>
26#include <linux/errno.h>
27#include <linux/init.h>
28#include <linux/slab.h>
29#include <linux/tty.h>
30#include <linux/tty_driver.h>
31#include <linux/tty_flip.h>
32#include <linux/module.h>
33#include <linux/usb.h>
34#include "usb-serial.h"
35
36
37#define NOKIA_VENDOR_ID 0x0421
38#define NOKIA7600_PRODUCT_ID 0x0400
39#define NOKIA6230_PRODUCT_ID 0x040f
40#define NOKIA6170_PRODUCT_ID 0x0416
41#define NOKIA6670_PRODUCT_ID 0x041d
42#define NOKIA6680_PRODUCT_ID 0x041e
43#define NOKIA6230i_PRODUCT_ID 0x0428
44
45#define NOKIA_AT_PORT 0x82
46#define NOKIA_FBUS_PORT 0x86
47
48/*
49 * Version Information
50 */
51#define DRIVER_VERSION "v0.2"
52#define DRIVER_AUTHOR "C Kemp"
53#define DRIVER_DESC "Nokia DKU2 Driver"
54
55static struct usb_device_id id_table [] = {
56 { USB_DEVICE(NOKIA_VENDOR_ID, NOKIA7600_PRODUCT_ID) },
57 { USB_DEVICE(NOKIA_VENDOR_ID, NOKIA6230_PRODUCT_ID) },
58 { USB_DEVICE(NOKIA_VENDOR_ID, NOKIA6170_PRODUCT_ID) },
59 { USB_DEVICE(NOKIA_VENDOR_ID, NOKIA6670_PRODUCT_ID) },
60 { USB_DEVICE(NOKIA_VENDOR_ID, NOKIA6680_PRODUCT_ID) },
61 { USB_DEVICE(NOKIA_VENDOR_ID, NOKIA6230i_PRODUCT_ID) },
62 { } /* Terminating entry */
63};
64MODULE_DEVICE_TABLE(usb, id_table);
65
66/* The only thing which makes this device different from a generic
67 * device is that we have to set an alternative configuration to make
68 * the relevant endpoints available. In 2.6 this is really easy... */
69static int nokia_probe(struct usb_serial *serial,
70 const struct usb_device_id *id)
71{
72 int retval = -ENODEV;
73
74 if (serial->interface->altsetting[0].endpoint[0].desc.bEndpointAddress == NOKIA_AT_PORT) {
75 /* the AT port */
76 dev_info(&serial->dev->dev, "Nokia AT Port:\n");
77 retval = 0;
78 } else if (serial->interface->num_altsetting == 2 &&
79 serial->interface->altsetting[1].endpoint[0].desc.bEndpointAddress == NOKIA_FBUS_PORT) {
80 /* the FBUS port */
81 dev_info(&serial->dev->dev, "Nokia FBUS Port:\n");
82 usb_set_interface(serial->dev, 10, 1);
83 retval = 0;
84 }
85
86 return retval;
87}
88
89static struct usb_driver nokia_driver = {
90 .owner = THIS_MODULE,
91 .name = "nokia_dku2",
92 .probe = usb_serial_probe,
93 .disconnect = usb_serial_disconnect,
94 .id_table = id_table,
95};
96
97static struct usb_serial_driver nokia_serial_driver = {
98 .driver = {
99 .owner = THIS_MODULE,
100 .name = "nokia_dku2",
101 },
102 .description = "Nokia 7600/6230(i)/6170/66x0 DKU2 driver",
103 .id_table = id_table,
104 .num_interrupt_in = 1,
105 .num_bulk_in = 1,
106 .num_bulk_out = 1,
107 .num_ports = 1,
108 .probe = nokia_probe,
109};
110
111static int __init nokia_init(void)
112{
113 int retval;
114
115 retval = usb_serial_register(&nokia_serial_driver);
116 if (retval)
117 return retval;
118
119 retval = usb_register(&nokia_driver);
120 if (retval) {
121 usb_serial_deregister(&nokia_serial_driver);
122 return retval;
123 }
124
125 info(DRIVER_VERSION " " DRIVER_AUTHOR);
126 info(DRIVER_DESC);
127
128 return retval;
129}
130
131static void __exit nokia_exit(void)
132{
133 usb_deregister(&nokia_driver);
134 usb_serial_deregister(&nokia_serial_driver);
135}
136
137module_init(nokia_init);
138module_exit(nokia_exit);
139
140MODULE_AUTHOR(DRIVER_AUTHOR);
141MODULE_DESCRIPTION(DRIVER_DESC);
142MODULE_LICENSE("GPL");
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c
index 6a99ae192df1..3caf97072ac0 100644
--- a/drivers/usb/serial/omninet.c
+++ b/drivers/usb/serial/omninet.c
@@ -88,10 +88,12 @@ static struct usb_driver omninet_driver = {
88}; 88};
89 89
90 90
91static struct usb_serial_device_type zyxel_omninet_device = { 91static struct usb_serial_driver zyxel_omninet_device = {
92 .owner = THIS_MODULE, 92 .driver = {
93 .name = "ZyXEL - omni.net lcd plus usb", 93 .owner = THIS_MODULE,
94 .short_name = "omninet", 94 .name = "omninet",
95 },
96 .description = "ZyXEL - omni.net lcd plus usb",
95 .id_table = id_table, 97 .id_table = id_table,
96 .num_interrupt_in = 1, 98 .num_interrupt_in = 1,
97 .num_bulk_in = 1, 99 .num_bulk_in = 1,
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 4989e5740d18..7716000045b7 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -105,10 +105,12 @@ static struct usb_driver option_driver = {
105/* The card has three separate interfaces, wich the serial driver 105/* The card has three separate interfaces, wich the serial driver
106 * recognizes separately, thus num_port=1. 106 * recognizes separately, thus num_port=1.
107 */ 107 */
108static struct usb_serial_device_type option_3port_device = { 108static struct usb_serial_driver option_3port_device = {
109 .owner = THIS_MODULE, 109 .driver = {
110 .name = "Option 3G data card", 110 .owner = THIS_MODULE,
111 .short_name = "option", 111 .name = "option",
112 },
113 .description = "Option 3G data card",
112 .id_table = option_ids, 114 .id_table = option_ids,
113 .num_interrupt_in = NUM_DONT_CARE, 115 .num_interrupt_in = NUM_DONT_CARE,
114 .num_bulk_in = NUM_DONT_CARE, 116 .num_bulk_in = NUM_DONT_CARE,
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 3cf245bdda54..165c119bf10e 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -8,31 +8,10 @@
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or 11 * the Free Software Foundation; either version 2 of the License.
12 * (at your option) any later version.
13 * 12 *
14 * See Documentation/usb/usb-serial.txt for more information on using this driver 13 * See Documentation/usb/usb-serial.txt for more information on using this driver
15 * 14 *
16 * 2002_Mar_26 gkh
17 * allowed driver to work properly if there is no tty assigned to a port
18 * (this happens for serial console devices.)
19 *
20 * 2001_Oct_06 gkh
21 * Added RTS and DTR line control. Thanks to joe@bndlg.de for parts of it.
22 *
23 * 2001_Sep_19 gkh
24 * Added break support.
25 *
26 * 2001_Aug_30 gkh
27 * fixed oops in write_bulk_callback.
28 *
29 * 2001_Aug_28 gkh
30 * reworked buffer logic to be like other usb-serial drivers. Hopefully
31 * removing some reported problems.
32 *
33 * 2001_Jun_06 gkh
34 * finished porting to 2.4 format.
35 *
36 */ 15 */
37 16
38#include <linux/config.h> 17#include <linux/config.h>
@@ -55,7 +34,6 @@
55/* 34/*
56 * Version Information 35 * Version Information
57 */ 36 */
58#define DRIVER_VERSION "v0.12"
59#define DRIVER_DESC "Prolific PL2303 USB to serial adaptor driver" 37#define DRIVER_DESC "Prolific PL2303 USB to serial adaptor driver"
60 38
61static int debug; 39static int debug;
@@ -175,9 +153,11 @@ static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf,
175 153
176 154
177/* All of the device info needed for the PL2303 SIO serial converter */ 155/* All of the device info needed for the PL2303 SIO serial converter */
178static struct usb_serial_device_type pl2303_device = { 156static struct usb_serial_driver pl2303_device = {
179 .owner = THIS_MODULE, 157 .driver = {
180 .name = "PL-2303", 158 .owner = THIS_MODULE,
159 .name = "pl2303",
160 },
181 .id_table = id_table, 161 .id_table = id_table,
182 .num_interrupt_in = NUM_DONT_CARE, 162 .num_interrupt_in = NUM_DONT_CARE,
183 .num_bulk_in = 1, 163 .num_bulk_in = 1,
@@ -1195,7 +1175,7 @@ static int __init pl2303_init (void)
1195 retval = usb_register(&pl2303_driver); 1175 retval = usb_register(&pl2303_driver);
1196 if (retval) 1176 if (retval)
1197 goto failed_usb_register; 1177 goto failed_usb_register;
1198 info(DRIVER_DESC " " DRIVER_VERSION); 1178 info(DRIVER_DESC);
1199 return 0; 1179 return 0;
1200failed_usb_register: 1180failed_usb_register:
1201 usb_serial_deregister(&pl2303_device); 1181 usb_serial_deregister(&pl2303_device);
@@ -1215,7 +1195,6 @@ module_init(pl2303_init);
1215module_exit(pl2303_exit); 1195module_exit(pl2303_exit);
1216 1196
1217MODULE_DESCRIPTION(DRIVER_DESC); 1197MODULE_DESCRIPTION(DRIVER_DESC);
1218MODULE_VERSION(DRIVER_VERSION);
1219MODULE_LICENSE("GPL"); 1198MODULE_LICENSE("GPL");
1220 1199
1221module_param(debug, bool, S_IRUGO | S_IWUSR); 1200module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/safe_serial.c b/drivers/usb/serial/safe_serial.c
index 96a17568cbf1..c22bdc0c4dfd 100644
--- a/drivers/usb/serial/safe_serial.c
+++ b/drivers/usb/serial/safe_serial.c
@@ -92,7 +92,7 @@ MODULE_DESCRIPTION (DRIVER_DESC);
92MODULE_LICENSE("GPL"); 92MODULE_LICENSE("GPL");
93 93
94#if defined(CONFIG_USBD_SAFE_SERIAL_VENDOR) && !defined(CONFIG_USBD_SAFE_SERIAL_PRODUCT) 94#if defined(CONFIG_USBD_SAFE_SERIAL_VENDOR) && !defined(CONFIG_USBD_SAFE_SERIAL_PRODUCT)
95#abort "SAFE_SERIAL_VENDOR defined without SAFE_SERIAL_PRODUCT" 95#error "SAFE_SERIAL_VENDOR defined without SAFE_SERIAL_PRODUCT"
96#endif 96#endif
97 97
98#if ! defined(CONFIG_USBD_SAFE_SERIAL_VENDOR) 98#if ! defined(CONFIG_USBD_SAFE_SERIAL_VENDOR)
@@ -397,9 +397,11 @@ static int safe_startup (struct usb_serial *serial)
397 return 0; 397 return 0;
398} 398}
399 399
400static struct usb_serial_device_type safe_device = { 400static struct usb_serial_driver safe_device = {
401 .owner = THIS_MODULE, 401 .driver = {
402 .name = "Safe", 402 .owner = THIS_MODULE,
403 .name = "safe_serial",
404 },
403 .id_table = id_table, 405 .id_table = id_table,
404 .num_interrupt_in = NUM_DONT_CARE, 406 .num_interrupt_in = NUM_DONT_CARE,
405 .num_bulk_in = NUM_DONT_CARE, 407 .num_bulk_in = NUM_DONT_CARE,
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index 59c88de3e7ae..205dbf7201da 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -255,9 +255,12 @@ static struct usb_driver ti_usb_driver = {
255 .id_table = ti_id_table_combined, 255 .id_table = ti_id_table_combined,
256}; 256};
257 257
258static struct usb_serial_device_type ti_1port_device = { 258static struct usb_serial_driver ti_1port_device = {
259 .owner = THIS_MODULE, 259 .driver = {
260 .name = "TI USB 3410 1 port adapter", 260 .owner = THIS_MODULE,
261 .name = "ti_usb_3410_5052_1",
262 },
263 .description = "TI USB 3410 1 port adapter",
261 .id_table = ti_id_table_3410, 264 .id_table = ti_id_table_3410,
262 .num_interrupt_in = 1, 265 .num_interrupt_in = 1,
263 .num_bulk_in = 1, 266 .num_bulk_in = 1,
@@ -282,9 +285,12 @@ static struct usb_serial_device_type ti_1port_device = {
282 .write_bulk_callback = ti_bulk_out_callback, 285 .write_bulk_callback = ti_bulk_out_callback,
283}; 286};
284 287
285static struct usb_serial_device_type ti_2port_device = { 288static struct usb_serial_driver ti_2port_device = {
286 .owner = THIS_MODULE, 289 .driver = {
287 .name = "TI USB 5052 2 port adapter", 290 .owner = THIS_MODULE,
291 .name = "ti_usb_3410_5052_2",
292 },
293 .description = "TI USB 5052 2 port adapter",
288 .id_table = ti_id_table_5052, 294 .id_table = ti_id_table_5052,
289 .num_interrupt_in = 1, 295 .num_interrupt_in = 1,
290 .num_bulk_in = 2, 296 .num_bulk_in = 2,
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index e77fbdfc782d..0c4881d18cd5 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * USB Serial Converter driver 2 * USB Serial Converter driver
3 * 3 *
4 * Copyright (C) 1999 - 2004 Greg Kroah-Hartman (greg@kroah.com) 4 * Copyright (C) 1999 - 2005 Greg Kroah-Hartman (greg@kroah.com)
5 * Copyright (C) 2000 Peter Berger (pberger@brimson.com) 5 * Copyright (C) 2000 Peter Berger (pberger@brimson.com)
6 * Copyright (C) 2000 Al Borchers (borchers@steinerpoint.com) 6 * Copyright (C) 2000 Al Borchers (borchers@steinerpoint.com)
7 * 7 *
@@ -9,316 +9,11 @@
9 * modify it under the terms of the GNU General Public License version 9 * modify it under the terms of the GNU General Public License version
10 * 2 as published by the Free Software Foundation. 10 * 2 as published by the Free Software Foundation.
11 * 11 *
12 * This driver was originally based on the ACM driver by Armin Fuerst (which was 12 * This driver was originally based on the ACM driver by Armin Fuerst (which was
13 * based on a driver by Brad Keryan) 13 * based on a driver by Brad Keryan)
14 * 14 *
15 * See Documentation/usb/usb-serial.txt for more information on using this driver 15 * See Documentation/usb/usb-serial.txt for more information on using this driver
16 * 16 *
17 * (12/10/2002) gkh
18 * Split the ports off into their own struct device, and added a
19 * usb-serial bus driver.
20 *
21 * (11/19/2002) gkh
22 * removed a few #ifdefs for the generic code and cleaned up the failure
23 * logic in initialization.
24 *
25 * (10/02/2002) gkh
26 * moved the console code to console.c and out of this file.
27 *
28 * (06/05/2002) gkh
29 * moved location of startup() call in serial_probe() until after all
30 * of the port information and endpoints are initialized. This makes
31 * things easier for some drivers.
32 *
33 * (04/10/2002) gkh
34 * added serial_read_proc function which creates a
35 * /proc/tty/driver/usb-serial file.
36 *
37 * (03/27/2002) gkh
38 * Got USB serial console code working properly and merged into the main
39 * version of the tree. Thanks to Randy Dunlap for the initial version
40 * of this code, and for pushing me to finish it up.
41 * The USB serial console works with any usb serial driver device.
42 *
43 * (03/21/2002) gkh
44 * Moved all manipulation of port->open_count into the core. Now the
45 * individual driver's open and close functions are called only when the
46 * first open() and last close() is called. Making the drivers a bit
47 * smaller and simpler.
48 * Fixed a bug if a driver didn't have the owner field set.
49 *
50 * (02/26/2002) gkh
51 * Moved all locking into the main serial_* functions, instead of having
52 * the individual drivers have to grab the port semaphore. This should
53 * reduce races.
54 * Reworked the MOD_INC logic a bit to always increment and decrement, even
55 * if the generic driver is being used.
56 *
57 * (10/10/2001) gkh
58 * usb_serial_disconnect() now sets the serial->dev pointer is to NULL to
59 * help prevent child drivers from accessing the device since it is now
60 * gone.
61 *
62 * (09/13/2001) gkh
63 * Moved generic driver initialize after we have registered with the USB
64 * core. Thanks to Randy Dunlap for pointing this problem out.
65 *
66 * (07/03/2001) gkh
67 * Fixed module paramater size. Thanks to John Brockmeyer for the pointer.
68 * Fixed vendor and product getting defined through the MODULE_PARM macro
69 * if the Generic driver wasn't compiled in.
70 * Fixed problem with generic_shutdown() not being called for drivers that
71 * don't have a shutdown() function.
72 *
73 * (06/06/2001) gkh
74 * added evil hack that is needed for the prolific pl2303 device due to the
75 * crazy way its endpoints are set up.
76 *
77 * (05/30/2001) gkh
78 * switched from using spinlock to a semaphore, which fixes lots of problems.
79 *
80 * (04/08/2001) gb
81 * Identify version on module load.
82 *
83 * 2001_02_05 gkh
84 * Fixed buffer overflows bug with the generic serial driver. Thanks to
85 * Todd Squires <squirest@ct0.com> for fixing this.
86 *
87 * (01/10/2001) gkh
88 * Fixed bug where the generic serial adaptor grabbed _any_ device that was
89 * offered to it.
90 *
91 * (12/12/2000) gkh
92 * Removed MOD_INC and MOD_DEC from poll and disconnect functions, and
93 * moved them to the serial_open and serial_close functions.
94 * Also fixed bug with there not being a MOD_DEC for the generic driver
95 * (thanks to Gary Brubaker for finding this.)
96 *
97 * (11/29/2000) gkh
98 * Small NULL pointer initialization cleanup which saves a bit of disk image
99 *
100 * (11/01/2000) Adam J. Richter
101 * instead of using idVendor/idProduct pairs, usb serial drivers
102 * now identify their hardware interest with usb_device_id tables,
103 * which they usually have anyhow for use with MODULE_DEVICE_TABLE.
104 *
105 * (10/05/2000) gkh
106 * Fixed bug with urb->dev not being set properly, now that the usb
107 * core needs it.
108 *
109 * (09/11/2000) gkh
110 * Removed DEBUG #ifdefs with call to usb_serial_debug_data
111 *
112 * (08/28/2000) gkh
113 * Added port_lock to port structure.
114 * Added locks for SMP safeness to generic driver
115 * Fixed the ability to open a generic device's port more than once.
116 *
117 * (07/23/2000) gkh
118 * Added bulk_out_endpointAddress to port structure.
119 *
120 * (07/19/2000) gkh, pberger, and borchers
121 * Modifications to allow usb-serial drivers to be modules.
122 *
123 * (07/03/2000) gkh
124 * Added more debugging to serial_ioctl call
125 *
126 * (06/25/2000) gkh
127 * Changed generic_write_bulk_callback to not call wake_up_interruptible
128 * directly, but to have port_softint do it at a safer time.
129 *
130 * (06/23/2000) gkh
131 * Cleaned up debugging statements in a quest to find UHCI timeout bug.
132 *
133 * (05/22/2000) gkh
134 * Changed the makefile, enabling the big CONFIG_USB_SERIAL_SOMTHING to be
135 * removed from the individual device source files.
136 *
137 * (05/03/2000) gkh
138 * Added the Digi Acceleport driver from Al Borchers and Peter Berger.
139 *
140 * (05/02/2000) gkh
141 * Changed devfs and tty register code to work properly now. This was based on
142 * the ACM driver changes by Vojtech Pavlik.
143 *
144 * (04/27/2000) Ryan VanderBijl
145 * Put calls to *_paranoia_checks into one function.
146 *
147 * (04/23/2000) gkh
148 * Fixed bug that Randy Dunlap found for Generic devices with no bulk out ports.
149 * Moved when the startup code printed out the devices that are supported.
150 *
151 * (04/19/2000) gkh
152 * Added driver for ZyXEL omni.net lcd plus ISDN TA
153 * Made startup info message specify which drivers were compiled in.
154 *
155 * (04/03/2000) gkh
156 * Changed the probe process to remove the module unload races.
157 * Changed where the tty layer gets initialized to have devfs work nicer.
158 * Added initial devfs support.
159 *
160 * (03/26/2000) gkh
161 * Split driver up into device specific pieces.
162 *
163 * (03/19/2000) gkh
164 * Fixed oops that could happen when device was removed while a program
165 * was talking to the device.
166 * Removed the static urbs and now all urbs are created and destroyed
167 * dynamically.
168 * Reworked the internal interface. Now everything is based on the
169 * usb_serial_port structure instead of the larger usb_serial structure.
170 * This fixes the bug that a multiport device could not have more than
171 * one port open at one time.
172 *
173 * (03/17/2000) gkh
174 * Added config option for debugging messages.
175 * Added patch for keyspan pda from Brian Warner.
176 *
177 * (03/06/2000) gkh
178 * Added the keyspan pda code from Brian Warner <warner@lothar.com>
179 * Moved a bunch of the port specific stuff into its own structure. This
180 * is in anticipation of the true multiport devices (there's a bug if you
181 * try to access more than one port of any multiport device right now)
182 *
183 * (02/21/2000) gkh
184 * Made it so that any serial devices only have to specify which functions
185 * they want to overload from the generic function calls (great,
186 * inheritance in C, in a driver, just what I wanted...)
187 * Added support for set_termios and ioctl function calls. No drivers take
188 * advantage of this yet.
189 * Removed the #ifdef MODULE, now there is no module specific code.
190 * Cleaned up a few comments in usb-serial.h that were wrong (thanks again
191 * to Miles Lott).
192 * Small fix to get_free_serial.
193 *
194 * (02/14/2000) gkh
195 * Removed the Belkin and Peracom functionality from the driver due to
196 * the lack of support from the vendor, and me not wanting people to
197 * accidenatly buy the device, expecting it to work with Linux.
198 * Added read_bulk_callback and write_bulk_callback to the type structure
199 * for the needs of the FTDI and WhiteHEAT driver.
200 * Changed all reverences to FTDI to FTDI_SIO at the request of Bill
201 * Ryder.
202 * Changed the output urb size back to the max endpoint size to make
203 * the ftdi_sio driver have it easier, and due to the fact that it didn't
204 * really increase the speed any.
205 *
206 * (02/11/2000) gkh
207 * Added VISOR_FUNCTION_CONSOLE to the visor startup function. This was a
208 * patch from Miles Lott (milos@insync.net).
209 * Fixed bug with not restoring the minor range that a device grabs, if
210 * the startup function fails (thanks Miles for finding this).
211 *
212 * (02/05/2000) gkh
213 * Added initial framework for the Keyspan PDA serial converter so that
214 * Brian Warner has a place to put his code.
215 * Made the ezusb specific functions generic enough that different
216 * devices can use them (whiteheat and keyspan_pda both need them).
217 * Split out a whole bunch of structure and other stuff to a separate
218 * usb-serial.h file.
219 * Made the Visor connection messages a little more understandable, now
220 * that Miles Lott (milos@insync.net) has gotten the Generic channel to
221 * work. Also made them always show up in the log file.
222 *
223 * (01/25/2000) gkh
224 * Added initial framework for FTDI serial converter so that Bill Ryder
225 * has a place to put his code.
226 * Added the vendor specific info from Handspring. Now we can print out
227 * informational debug messages as well as understand what is happening.
228 *
229 * (01/23/2000) gkh
230 * Fixed problem of crash when trying to open a port that didn't have a
231 * device assigned to it. Made the minor node finding a little smarter,
232 * now it looks to find a continuous space for the new device.
233 *
234 * (01/21/2000) gkh
235 * Fixed bug in visor_startup with patch from Miles Lott (milos@insync.net)
236 * Fixed get_serial_by_minor which was all messed up for multi port
237 * devices. Fixed multi port problem for generic devices. Now the number
238 * of ports is determined by the number of bulk out endpoints for the
239 * generic device.
240 *
241 * (01/19/2000) gkh
242 * Removed lots of cruft that was around from the old (pre urb) driver
243 * interface.
244 * Made the serial_table dynamic. This should save lots of memory when
245 * the number of minor nodes goes up to 256.
246 * Added initial support for devices that have more than one port.
247 * Added more debugging comments for the Visor, and added a needed
248 * set_configuration call.
249 *
250 * (01/17/2000) gkh
251 * Fixed the WhiteHEAT firmware (my processing tool had a bug)
252 * and added new debug loader firmware for it.
253 * Removed the put_char function as it isn't really needed.
254 * Added visor startup commands as found by the Win98 dump.
255 *
256 * (01/13/2000) gkh
257 * Fixed the vendor id for the generic driver to the one I meant it to be.
258 *
259 * (01/12/2000) gkh
260 * Forget the version numbering...that's pretty useless...
261 * Made the driver able to be compiled so that the user can select which
262 * converter they want to use. This allows people who only want the Visor
263 * support to not pay the memory size price of the WhiteHEAT.
264 * Fixed bug where the generic driver (idVendor=0000 and idProduct=0000)
265 * grabbed the root hub. Not good.
266 *
267 * version 0.4.0 (01/10/2000) gkh
268 * Added whiteheat.h containing the firmware for the ConnectTech WhiteHEAT
269 * device. Added startup function to allow firmware to be downloaded to
270 * a device if it needs to be.
271 * Added firmware download logic to the WhiteHEAT device.
272 * Started to add #defines to split up the different drivers for potential
273 * configuration option.
274 *
275 * version 0.3.1 (12/30/99) gkh
276 * Fixed problems with urb for bulk out.
277 * Added initial support for multiple sets of endpoints. This enables
278 * the Handspring Visor to be attached successfully. Only the first
279 * bulk in / bulk out endpoint pair is being used right now.
280 *
281 * version 0.3.0 (12/27/99) gkh
282 * Added initial support for the Handspring Visor based on a patch from
283 * Miles Lott (milos@sneety.insync.net)
284 * Cleaned up the code a bunch and converted over to using urbs only.
285 *
286 * version 0.2.3 (12/21/99) gkh
287 * Added initial support for the Connect Tech WhiteHEAT converter.
288 * Incremented the number of ports in expectation of getting the
289 * WhiteHEAT to work properly (4 ports per connection).
290 * Added notification on insertion and removal of what port the
291 * device is/was connected to (and what kind of device it was).
292 *
293 * version 0.2.2 (12/16/99) gkh
294 * Changed major number to the new allocated number. We're legal now!
295 *
296 * version 0.2.1 (12/14/99) gkh
297 * Fixed bug that happens when device node is opened when there isn't a
298 * device attached to it. Thanks to marek@webdesign.no for noticing this.
299 *
300 * version 0.2.0 (11/10/99) gkh
301 * Split up internals to make it easier to add different types of serial
302 * converters to the code.
303 * Added a "generic" driver that gets it's vendor and product id
304 * from when the module is loaded. Thanks to David E. Nelson (dnelson@jump.net)
305 * for the idea and sample code (from the usb scanner driver.)
306 * Cleared up any licensing questions by releasing it under the GNU GPL.
307 *
308 * version 0.1.2 (10/25/99) gkh
309 * Fixed bug in detecting device.
310 *
311 * version 0.1.1 (10/05/99) gkh
312 * Changed the major number to not conflict with anything else.
313 *
314 * version 0.1 (09/28/99) gkh
315 * Can recognize the two different devices and start up a read from
316 * device when asked to. Writes also work. No control signals yet, this
317 * all is vendor specific data (i.e. no spec), also no control for
318 * different baud rates or other bit settings.
319 * Currently we are using the same devid as the acm driver. This needs
320 * to change.
321 *
322 */ 17 */
323 18
324#include <linux/config.h> 19#include <linux/config.h>
@@ -342,7 +37,6 @@
342/* 37/*
343 * Version Information 38 * Version Information
344 */ 39 */
345#define DRIVER_VERSION "v2.0"
346#define DRIVER_AUTHOR "Greg Kroah-Hartman, greg@kroah.com, http://www.kroah.com/linux/" 40#define DRIVER_AUTHOR "Greg Kroah-Hartman, greg@kroah.com, http://www.kroah.com/linux/"
347#define DRIVER_DESC "USB Serial Driver core" 41#define DRIVER_DESC "USB Serial Driver core"
348 42
@@ -427,7 +121,7 @@ static void destroy_serial(struct kref *kref)
427 121
428 serial = to_usb_serial(kref); 122 serial = to_usb_serial(kref);
429 123
430 dbg ("%s - %s", __FUNCTION__, serial->type->name); 124 dbg("%s - %s", __FUNCTION__, serial->type->description);
431 125
432 serial->type->shutdown(serial); 126 serial->type->shutdown(serial);
433 127
@@ -507,7 +201,7 @@ static int serial_open (struct tty_struct *tty, struct file * filp)
507 /* lock this module before we call it 201 /* lock this module before we call it
508 * this may fail, which means we must bail out, 202 * this may fail, which means we must bail out,
509 * safe because we are called with BKL held */ 203 * safe because we are called with BKL held */
510 if (!try_module_get(serial->type->owner)) { 204 if (!try_module_get(serial->type->driver.owner)) {
511 retval = -ENODEV; 205 retval = -ENODEV;
512 goto bailout_kref_put; 206 goto bailout_kref_put;
513 } 207 }
@@ -522,7 +216,7 @@ static int serial_open (struct tty_struct *tty, struct file * filp)
522 return 0; 216 return 0;
523 217
524bailout_module_put: 218bailout_module_put:
525 module_put(serial->type->owner); 219 module_put(serial->type->driver.owner);
526bailout_kref_put: 220bailout_kref_put:
527 kref_put(&serial->kref, destroy_serial); 221 kref_put(&serial->kref, destroy_serial);
528 port->open_count = 0; 222 port->open_count = 0;
@@ -553,7 +247,7 @@ static void serial_close(struct tty_struct *tty, struct file * filp)
553 port->tty = NULL; 247 port->tty = NULL;
554 } 248 }
555 249
556 module_put(port->serial->type->owner); 250 module_put(port->serial->type->driver.owner);
557 } 251 }
558 252
559 kref_put(&port->serial->kref, destroy_serial); 253 kref_put(&port->serial->kref, destroy_serial);
@@ -711,16 +405,16 @@ static int serial_read_proc (char *page, char **start, off_t off, int count, int
711 char tmp[40]; 405 char tmp[40];
712 406
713 dbg("%s", __FUNCTION__); 407 dbg("%s", __FUNCTION__);
714 length += sprintf (page, "usbserinfo:1.0 driver:%s\n", DRIVER_VERSION); 408 length += sprintf (page, "usbserinfo:1.0 driver:2.0\n");
715 for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) { 409 for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) {
716 serial = usb_serial_get_by_index(i); 410 serial = usb_serial_get_by_index(i);
717 if (serial == NULL) 411 if (serial == NULL)
718 continue; 412 continue;
719 413
720 length += sprintf (page+length, "%d:", i); 414 length += sprintf (page+length, "%d:", i);
721 if (serial->type->owner) 415 if (serial->type->driver.owner)
722 length += sprintf (page+length, " module:%s", module_name(serial->type->owner)); 416 length += sprintf (page+length, " module:%s", module_name(serial->type->driver.owner));
723 length += sprintf (page+length, " name:\"%s\"", serial->type->name); 417 length += sprintf (page+length, " name:\"%s\"", serial->type->description);
724 length += sprintf (page+length, " vendor:%04x product:%04x", 418 length += sprintf (page+length, " vendor:%04x product:%04x",
725 le16_to_cpu(serial->dev->descriptor.idVendor), 419 le16_to_cpu(serial->dev->descriptor.idVendor),
726 le16_to_cpu(serial->dev->descriptor.idProduct)); 420 le16_to_cpu(serial->dev->descriptor.idProduct));
@@ -823,7 +517,7 @@ static void port_release(struct device *dev)
823 517
824static struct usb_serial * create_serial (struct usb_device *dev, 518static struct usb_serial * create_serial (struct usb_device *dev,
825 struct usb_interface *interface, 519 struct usb_interface *interface,
826 struct usb_serial_device_type *type) 520 struct usb_serial_driver *driver)
827{ 521{
828 struct usb_serial *serial; 522 struct usb_serial *serial;
829 523
@@ -834,22 +528,22 @@ static struct usb_serial * create_serial (struct usb_device *dev,
834 } 528 }
835 memset (serial, 0, sizeof(*serial)); 529 memset (serial, 0, sizeof(*serial));
836 serial->dev = usb_get_dev(dev); 530 serial->dev = usb_get_dev(dev);
837 serial->type = type; 531 serial->type = driver;
838 serial->interface = interface; 532 serial->interface = interface;
839 kref_init(&serial->kref); 533 kref_init(&serial->kref);
840 534
841 return serial; 535 return serial;
842} 536}
843 537
844static struct usb_serial_device_type *search_serial_device(struct usb_interface *iface) 538static struct usb_serial_driver *search_serial_device(struct usb_interface *iface)
845{ 539{
846 struct list_head *p; 540 struct list_head *p;
847 const struct usb_device_id *id; 541 const struct usb_device_id *id;
848 struct usb_serial_device_type *t; 542 struct usb_serial_driver *t;
849 543
850 /* List trough know devices and see if the usb id matches */ 544 /* List trough know devices and see if the usb id matches */
851 list_for_each(p, &usb_serial_driver_list) { 545 list_for_each(p, &usb_serial_driver_list) {
852 t = list_entry(p, struct usb_serial_device_type, driver_list); 546 t = list_entry(p, struct usb_serial_driver, driver_list);
853 id = usb_match_id(iface, t->id_table); 547 id = usb_match_id(iface, t->id_table);
854 if (id != NULL) { 548 if (id != NULL) {
855 dbg("descriptor matches"); 549 dbg("descriptor matches");
@@ -872,7 +566,7 @@ int usb_serial_probe(struct usb_interface *interface,
872 struct usb_endpoint_descriptor *interrupt_out_endpoint[MAX_NUM_PORTS]; 566 struct usb_endpoint_descriptor *interrupt_out_endpoint[MAX_NUM_PORTS];
873 struct usb_endpoint_descriptor *bulk_in_endpoint[MAX_NUM_PORTS]; 567 struct usb_endpoint_descriptor *bulk_in_endpoint[MAX_NUM_PORTS];
874 struct usb_endpoint_descriptor *bulk_out_endpoint[MAX_NUM_PORTS]; 568 struct usb_endpoint_descriptor *bulk_out_endpoint[MAX_NUM_PORTS];
875 struct usb_serial_device_type *type = NULL; 569 struct usb_serial_driver *type = NULL;
876 int retval; 570 int retval;
877 int minor; 571 int minor;
878 int buffer_size; 572 int buffer_size;
@@ -900,7 +594,7 @@ int usb_serial_probe(struct usb_interface *interface,
900 if (type->probe) { 594 if (type->probe) {
901 const struct usb_device_id *id; 595 const struct usb_device_id *id;
902 596
903 if (!try_module_get(type->owner)) { 597 if (!try_module_get(type->driver.owner)) {
904 dev_err(&interface->dev, "module get failed, exiting\n"); 598 dev_err(&interface->dev, "module get failed, exiting\n");
905 kfree (serial); 599 kfree (serial);
906 return -EIO; 600 return -EIO;
@@ -908,7 +602,7 @@ int usb_serial_probe(struct usb_interface *interface,
908 602
909 id = usb_match_id(interface, type->id_table); 603 id = usb_match_id(interface, type->id_table);
910 retval = type->probe(serial, id); 604 retval = type->probe(serial, id);
911 module_put(type->owner); 605 module_put(type->driver.owner);
912 606
913 if (retval) { 607 if (retval) {
914 dbg ("sub driver rejected device"); 608 dbg ("sub driver rejected device");
@@ -992,7 +686,7 @@ int usb_serial_probe(struct usb_interface *interface,
992#endif 686#endif
993 687
994 /* found all that we need */ 688 /* found all that we need */
995 dev_info(&interface->dev, "%s converter detected\n", type->name); 689 dev_info(&interface->dev, "%s converter detected\n", type->description);
996 690
997#ifdef CONFIG_USB_SERIAL_GENERIC 691#ifdef CONFIG_USB_SERIAL_GENERIC
998 if (type == &usb_serial_generic_device) { 692 if (type == &usb_serial_generic_device) {
@@ -1007,13 +701,13 @@ int usb_serial_probe(struct usb_interface *interface,
1007 if (!num_ports) { 701 if (!num_ports) {
1008 /* if this device type has a calc_num_ports function, call it */ 702 /* if this device type has a calc_num_ports function, call it */
1009 if (type->calc_num_ports) { 703 if (type->calc_num_ports) {
1010 if (!try_module_get(type->owner)) { 704 if (!try_module_get(type->driver.owner)) {
1011 dev_err(&interface->dev, "module get failed, exiting\n"); 705 dev_err(&interface->dev, "module get failed, exiting\n");
1012 kfree (serial); 706 kfree (serial);
1013 return -EIO; 707 return -EIO;
1014 } 708 }
1015 num_ports = type->calc_num_ports (serial); 709 num_ports = type->calc_num_ports (serial);
1016 module_put(type->owner); 710 module_put(type->driver.owner);
1017 } 711 }
1018 if (!num_ports) 712 if (!num_ports)
1019 num_ports = type->num_ports; 713 num_ports = type->num_ports;
@@ -1158,12 +852,12 @@ int usb_serial_probe(struct usb_interface *interface,
1158 852
1159 /* if this device type has an attach function, call it */ 853 /* if this device type has an attach function, call it */
1160 if (type->attach) { 854 if (type->attach) {
1161 if (!try_module_get(type->owner)) { 855 if (!try_module_get(type->driver.owner)) {
1162 dev_err(&interface->dev, "module get failed, exiting\n"); 856 dev_err(&interface->dev, "module get failed, exiting\n");
1163 goto probe_error; 857 goto probe_error;
1164 } 858 }
1165 retval = type->attach (serial); 859 retval = type->attach (serial);
1166 module_put(type->owner); 860 module_put(type->driver.owner);
1167 if (retval < 0) 861 if (retval < 0)
1168 goto probe_error; 862 goto probe_error;
1169 if (retval > 0) { 863 if (retval > 0) {
@@ -1330,7 +1024,7 @@ static int __init usb_serial_init(void)
1330 goto exit_generic; 1024 goto exit_generic;
1331 } 1025 }
1332 1026
1333 info(DRIVER_DESC " " DRIVER_VERSION); 1027 info(DRIVER_DESC);
1334 1028
1335 return result; 1029 return result;
1336 1030
@@ -1375,7 +1069,7 @@ module_exit(usb_serial_exit);
1375 } \ 1069 } \
1376 } while (0) 1070 } while (0)
1377 1071
1378static void fixup_generic(struct usb_serial_device_type *device) 1072static void fixup_generic(struct usb_serial_driver *device)
1379{ 1073{
1380 set_to_generic_if_null(device, open); 1074 set_to_generic_if_null(device, open);
1381 set_to_generic_if_null(device, write); 1075 set_to_generic_if_null(device, write);
@@ -1387,30 +1081,33 @@ static void fixup_generic(struct usb_serial_device_type *device)
1387 set_to_generic_if_null(device, shutdown); 1081 set_to_generic_if_null(device, shutdown);
1388} 1082}
1389 1083
1390int usb_serial_register(struct usb_serial_device_type *new_device) 1084int usb_serial_register(struct usb_serial_driver *driver)
1391{ 1085{
1392 int retval; 1086 int retval;
1393 1087
1394 fixup_generic(new_device); 1088 fixup_generic(driver);
1089
1090 if (!driver->description)
1091 driver->description = driver->driver.name;
1395 1092
1396 /* Add this device to our list of devices */ 1093 /* Add this device to our list of devices */
1397 list_add(&new_device->driver_list, &usb_serial_driver_list); 1094 list_add(&driver->driver_list, &usb_serial_driver_list);
1398 1095
1399 retval = usb_serial_bus_register(new_device); 1096 retval = usb_serial_bus_register(driver);
1400 if (retval) { 1097 if (retval) {
1401 err("problem %d when registering driver %s", retval, new_device->name); 1098 err("problem %d when registering driver %s", retval, driver->description);
1402 list_del(&new_device->driver_list); 1099 list_del(&driver->driver_list);
1403 } 1100 }
1404 else 1101 else
1405 info("USB Serial support registered for %s", new_device->name); 1102 info("USB Serial support registered for %s", driver->description);
1406 1103
1407 return retval; 1104 return retval;
1408} 1105}
1409 1106
1410 1107
1411void usb_serial_deregister(struct usb_serial_device_type *device) 1108void usb_serial_deregister(struct usb_serial_driver *device)
1412{ 1109{
1413 info("USB Serial deregistering driver %s", device->name); 1110 info("USB Serial deregistering driver %s", device->description);
1414 list_del(&device->driver_list); 1111 list_del(&device->driver_list);
1415 usb_serial_bus_deregister(device); 1112 usb_serial_bus_deregister(device);
1416} 1113}
@@ -1429,7 +1126,6 @@ EXPORT_SYMBOL_GPL(usb_serial_port_softint);
1429/* Module information */ 1126/* Module information */
1430MODULE_AUTHOR( DRIVER_AUTHOR ); 1127MODULE_AUTHOR( DRIVER_AUTHOR );
1431MODULE_DESCRIPTION( DRIVER_DESC ); 1128MODULE_DESCRIPTION( DRIVER_DESC );
1432MODULE_VERSION( DRIVER_VERSION );
1433MODULE_LICENSE("GPL"); 1129MODULE_LICENSE("GPL");
1434 1130
1435module_param(debug, bool, S_IRUGO | S_IWUSR); 1131module_param(debug, bool, S_IRUGO | S_IWUSR);
diff --git a/drivers/usb/serial/usb-serial.h b/drivers/usb/serial/usb-serial.h
index 57f92f054c75..238a5a871ed6 100644
--- a/drivers/usb/serial/usb-serial.h
+++ b/drivers/usb/serial/usb-serial.h
@@ -1,53 +1,13 @@
1/* 1/*
2 * USB Serial Converter driver 2 * USB Serial Converter driver
3 * 3 *
4 * Copyright (C) 1999 - 2004 4 * Copyright (C) 1999 - 2005
5 * Greg Kroah-Hartman (greg@kroah.com) 5 * Greg Kroah-Hartman (greg@kroah.com)
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or 9 * the Free Software Foundation; either version 2 of the License.
10 * (at your option) any later version.
11 * 10 *
12 * See Documentation/usb/usb-serial.txt for more information on using this driver
13 *
14 * (03/26/2002) gkh
15 * removed the port->tty check from port_paranoia_check() due to serial
16 * consoles not having a tty device assigned to them.
17 *
18 * (12/03/2001) gkh
19 * removed active from the port structure.
20 * added documentation to the usb_serial_device_type structure
21 *
22 * (10/10/2001) gkh
23 * added vendor and product to serial structure. Needed to determine device
24 * owner when the device is disconnected.
25 *
26 * (05/30/2001) gkh
27 * added sem to port structure and removed port_lock
28 *
29 * (10/05/2000) gkh
30 * Added interrupt_in_endpointAddress and bulk_in_endpointAddress to help
31 * fix bug with urb->dev not being set properly, now that the usb core
32 * needs it.
33 *
34 * (09/11/2000) gkh
35 * Added usb_serial_debug_data function to help get rid of #DEBUG in the
36 * drivers.
37 *
38 * (08/28/2000) gkh
39 * Added port_lock to port structure.
40 *
41 * (08/08/2000) gkh
42 * Added open_count to port structure.
43 *
44 * (07/23/2000) gkh
45 * Added bulk_out_endpointAddress to port structure.
46 *
47 * (07/19/2000) gkh, pberger, and borchers
48 * Modifications to allow usb-serial drivers to be modules.
49 *
50 *
51 */ 11 */
52 12
53 13
@@ -143,7 +103,7 @@ static inline void usb_set_serial_port_data (struct usb_serial_port *port, void
143/** 103/**
144 * usb_serial - structure used by the usb-serial core for a device 104 * usb_serial - structure used by the usb-serial core for a device
145 * @dev: pointer to the struct usb_device for this device 105 * @dev: pointer to the struct usb_device for this device
146 * @type: pointer to the struct usb_serial_device_type for this device 106 * @type: pointer to the struct usb_serial_driver for this device
147 * @interface: pointer to the struct usb_interface for this device 107 * @interface: pointer to the struct usb_interface for this device
148 * @minor: the starting minor number for this device 108 * @minor: the starting minor number for this device
149 * @num_ports: the number of ports this device has 109 * @num_ports: the number of ports this device has
@@ -159,7 +119,7 @@ static inline void usb_set_serial_port_data (struct usb_serial_port *port, void
159 */ 119 */
160struct usb_serial { 120struct usb_serial {
161 struct usb_device * dev; 121 struct usb_device * dev;
162 struct usb_serial_device_type * type; 122 struct usb_serial_driver * type;
163 struct usb_interface * interface; 123 struct usb_interface * interface;
164 unsigned char minor; 124 unsigned char minor;
165 unsigned char num_ports; 125 unsigned char num_ports;
@@ -188,13 +148,9 @@ static inline void usb_set_serial_data (struct usb_serial *serial, void *data)
188} 148}
189 149
190/** 150/**
191 * usb_serial_device_type - a structure that defines a usb serial device 151 * usb_serial_driver - describes a usb serial driver
192 * @owner: pointer to the module that owns this device. 152 * @description: pointer to a string that describes this driver. This string used
193 * @name: pointer to a string that describes this device. This string used
194 * in the syslog messages when a device is inserted or removed. 153 * in the syslog messages when a device is inserted or removed.
195 * @short_name: a pointer to a string that describes this device in
196 * KOBJ_NAME_LEN characters or less. This is used for the sysfs interface
197 * to describe the driver.
198 * @id_table: pointer to a list of usb_device_id structures that define all 154 * @id_table: pointer to a list of usb_device_id structures that define all
199 * of the devices this structure can support. 155 * of the devices this structure can support.
200 * @num_interrupt_in: the number of interrupt in endpoints this device will 156 * @num_interrupt_in: the number of interrupt in endpoints this device will
@@ -221,16 +177,19 @@ static inline void usb_set_serial_data (struct usb_serial *serial, void *data)
221 * @shutdown: pointer to the driver's shutdown function. This will be 177 * @shutdown: pointer to the driver's shutdown function. This will be
222 * called when the device is removed from the system. 178 * called when the device is removed from the system.
223 * 179 *
224 * This structure is defines a USB Serial device. It provides all of 180 * This structure is defines a USB Serial driver. It provides all of
225 * the information that the USB serial core code needs. If the function 181 * the information that the USB serial core code needs. If the function
226 * pointers are defined, then the USB serial core code will call them when 182 * pointers are defined, then the USB serial core code will call them when
227 * the corresponding tty port functions are called. If they are not 183 * the corresponding tty port functions are called. If they are not
228 * called, the generic serial function will be used instead. 184 * called, the generic serial function will be used instead.
185 *
186 * The driver.owner field should be set to the module owner of this driver.
187 * The driver.name field should be set to the name of this driver (remember
188 * it will show up in sysfs, so it needs to be short and to the point.
189 * Useing the module name is a good idea.)
229 */ 190 */
230struct usb_serial_device_type { 191struct usb_serial_driver {
231 struct module *owner; 192 const char *description;
232 char *name;
233 char *short_name;
234 const struct usb_device_id *id_table; 193 const struct usb_device_id *id_table;
235 char num_interrupt_in; 194 char num_interrupt_in;
236 char num_interrupt_out; 195 char num_interrupt_out;
@@ -269,10 +228,10 @@ struct usb_serial_device_type {
269 void (*read_bulk_callback)(struct urb *urb, struct pt_regs *regs); 228 void (*read_bulk_callback)(struct urb *urb, struct pt_regs *regs);
270 void (*write_bulk_callback)(struct urb *urb, struct pt_regs *regs); 229 void (*write_bulk_callback)(struct urb *urb, struct pt_regs *regs);
271}; 230};
272#define to_usb_serial_driver(d) container_of(d, struct usb_serial_device_type, driver) 231#define to_usb_serial_driver(d) container_of(d, struct usb_serial_driver, driver)
273 232
274extern int usb_serial_register(struct usb_serial_device_type *new_device); 233extern int usb_serial_register(struct usb_serial_driver *driver);
275extern void usb_serial_deregister(struct usb_serial_device_type *device); 234extern void usb_serial_deregister(struct usb_serial_driver *driver);
276extern void usb_serial_port_softint(void *private); 235extern void usb_serial_port_softint(void *private);
277 236
278extern int usb_serial_probe(struct usb_interface *iface, const struct usb_device_id *id); 237extern int usb_serial_probe(struct usb_interface *iface, const struct usb_device_id *id);
@@ -303,10 +262,10 @@ extern void usb_serial_generic_shutdown (struct usb_serial *serial);
303extern int usb_serial_generic_register (int debug); 262extern int usb_serial_generic_register (int debug);
304extern void usb_serial_generic_deregister (void); 263extern void usb_serial_generic_deregister (void);
305 264
306extern int usb_serial_bus_register (struct usb_serial_device_type *device); 265extern int usb_serial_bus_register (struct usb_serial_driver *device);
307extern void usb_serial_bus_deregister (struct usb_serial_device_type *device); 266extern void usb_serial_bus_deregister (struct usb_serial_driver *device);
308 267
309extern struct usb_serial_device_type usb_serial_generic_device; 268extern struct usb_serial_driver usb_serial_generic_device;
310extern struct bus_type usb_serial_bus_type; 269extern struct bus_type usb_serial_bus_type;
311extern struct tty_driver *usb_serial_tty_driver; 270extern struct tty_driver *usb_serial_tty_driver;
312 271
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c
index 31c57adcb623..a473c1c34559 100644
--- a/drivers/usb/serial/visor.c
+++ b/drivers/usb/serial/visor.c
@@ -7,139 +7,10 @@
7 * 7 *
8 * 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
9 * it under the terms of the GNU General Public License as published by 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 10 * the Free Software Foundation; either version 2 of the License.
11 * (at your option) any later version.
12 * 11 *
13 * See Documentation/usb/usb-serial.txt for more information on using this driver 12 * See Documentation/usb/usb-serial.txt for more information on using this driver
14 * 13 *
15 * (06/03/2003) Judd Montgomery <judd at jpilot.org>
16 * Added support for module parameter options for untested/unknown
17 * devices.
18 *
19 * (03/09/2003) gkh
20 * Added support for the Sony Clie NZ90V device. Thanks to Martin Brachtl
21 * <brachtl@redgrep.cz> for the information.
22 *
23 * (03/05/2003) gkh
24 * Think Treo support is now working.
25 *
26 * (04/03/2002) gkh
27 * Added support for the Sony OS 4.1 devices. Thanks to Hiroyuki ARAKI
28 * <hiro@zob.ne.jp> for the information.
29 *
30 * (03/27/2002) gkh
31 * Removed assumptions that port->tty was always valid (is not true
32 * for usb serial console devices.)
33 *
34 * (03/23/2002) gkh
35 * Added support for the Palm i705 device, thanks to Thomas Riemer
36 * <tom@netmech.com> for the information.
37 *
38 * (03/21/2002) gkh
39 * Added support for the Palm m130 device, thanks to Udo Eisenbarth
40 * <udo.eisenbarth@web.de> for the information.
41 *
42 * (02/27/2002) gkh
43 * Reworked the urb handling logic. We have no more pool, but dynamically
44 * allocate the urb and the transfer buffer on the fly. In testing this
45 * does not incure any measurable overhead. This also relies on the fact
46 * that we have proper reference counting logic for urbs.
47 *
48 * (02/21/2002) SilaS
49 * Added initial support for the Palm m515 devices.
50 *
51 * (02/14/2002) gkh
52 * Added support for the Clie S-360 device.
53 *
54 * (12/18/2001) gkh
55 * Added better Clie support for 3.5 devices. Thanks to Geoffrey Levand
56 * for the patch.
57 *
58 * (11/11/2001) gkh
59 * Added support for the m125 devices, and added check to prevent oopses
60 * for Clié devices that lie about the number of ports they have.
61 *
62 * (08/30/2001) gkh
63 * Added support for the Clie devices, both the 3.5 and 4.0 os versions.
64 * Many thanks to Daniel Burke, and Bryan Payne for helping with this.
65 *
66 * (08/23/2001) gkh
67 * fixed a few potential bugs pointed out by Oliver Neukum.
68 *
69 * (05/30/2001) gkh
70 * switched from using spinlock to a semaphore, which fixes lots of problems.
71 *
72 * (05/28/2000) gkh
73 * Added initial support for the Palm m500 and Palm m505 devices.
74 *
75 * (04/08/2001) gb
76 * Identify version on module load.
77 *
78 * (01/21/2000) gkh
79 * Added write_room and chars_in_buffer, as they were previously using the
80 * generic driver versions which is all wrong now that we are using an urb
81 * pool. Thanks to Wolfgang Grandegger for pointing this out to me.
82 * Removed count assignment in the write function, which was not needed anymore
83 * either. Thanks to Al Borchers for pointing this out.
84 *
85 * (12/12/2000) gkh
86 * Moved MOD_DEC to end of visor_close to be nicer, as the final write
87 * message can sleep.
88 *
89 * (11/12/2000) gkh
90 * Fixed bug with data being dropped on the floor by forcing tty->low_latency
91 * to be on. Hopefully this fixes the OHCI issue!
92 *
93 * (11/01/2000) Adam J. Richter
94 * usb_device_id table support
95 *
96 * (10/05/2000) gkh
97 * Fixed bug with urb->dev not being set properly, now that the usb
98 * core needs it.
99 *
100 * (09/11/2000) gkh
101 * Got rid of always calling kmalloc for every urb we wrote out to the
102 * device.
103 * Added visor_read_callback so we can keep track of bytes in and out for
104 * those people who like to know the speed of their device.
105 * Removed DEBUG #ifdefs with call to usb_serial_debug_data
106 *
107 * (09/06/2000) gkh
108 * Fixed oops in visor_exit. Need to uncomment usb_unlink_urb call _after_
109 * the host controller drivers set urb->dev = NULL when the urb is finished.
110 *
111 * (08/28/2000) gkh
112 * Added locks for SMP safeness.
113 *
114 * (08/08/2000) gkh
115 * Fixed endian problem in visor_startup.
116 * Fixed MOD_INC and MOD_DEC logic and the ability to open a port more
117 * than once.
118 *
119 * (07/23/2000) gkh
120 * Added pool of write urbs to speed up transfers to the visor.
121 *
122 * (07/19/2000) gkh
123 * Added module_init and module_exit functions to handle the fact that this
124 * driver is a loadable module now.
125 *
126 * (07/03/2000) gkh
127 * Added visor_set_ioctl and visor_set_termios functions (they don't do much
128 * of anything, but are good for debugging.)
129 *
130 * (06/25/2000) gkh
131 * Fixed bug in visor_unthrottle that should help with the disconnect in PPP
132 * bug that people have been reporting.
133 *
134 * (06/23/2000) gkh
135 * Cleaned up debugging statements in a quest to find UHCI timeout bug.
136 *
137 * (04/27/2000) Ryan VanderBijl
138 * Fixed memory leak in visor_close
139 *
140 * (03/26/2000) gkh
141 * Split driver up into device specific pieces.
142 *
143 */ 14 */
144 15
145#include <linux/config.h> 16#include <linux/config.h>
@@ -161,7 +32,6 @@
161/* 32/*
162 * Version Information 33 * Version Information
163 */ 34 */
164#define DRIVER_VERSION "v2.1"
165#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>" 35#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>"
166#define DRIVER_DESC "USB HandSpring Visor / Palm OS driver" 36#define DRIVER_DESC "USB HandSpring Visor / Palm OS driver"
167 37
@@ -311,10 +181,12 @@ static struct usb_driver visor_driver = {
311}; 181};
312 182
313/* All of the device info needed for the Handspring Visor, and Palm 4.0 devices */ 183/* All of the device info needed for the Handspring Visor, and Palm 4.0 devices */
314static struct usb_serial_device_type handspring_device = { 184static struct usb_serial_driver handspring_device = {
315 .owner = THIS_MODULE, 185 .driver = {
316 .name = "Handspring Visor / Palm OS", 186 .owner = THIS_MODULE,
317 .short_name = "visor", 187 .name = "visor",
188 },
189 .description = "Handspring Visor / Palm OS",
318 .id_table = id_table, 190 .id_table = id_table,
319 .num_interrupt_in = NUM_DONT_CARE, 191 .num_interrupt_in = NUM_DONT_CARE,
320 .num_bulk_in = 2, 192 .num_bulk_in = 2,
@@ -339,10 +211,12 @@ static struct usb_serial_device_type handspring_device = {
339}; 211};
340 212
341/* All of the device info needed for the Clie UX50, TH55 Palm 5.0 devices */ 213/* All of the device info needed for the Clie UX50, TH55 Palm 5.0 devices */
342static struct usb_serial_device_type clie_5_device = { 214static struct usb_serial_driver clie_5_device = {
343 .owner = THIS_MODULE, 215 .driver = {
344 .name = "Sony Clie 5.0", 216 .owner = THIS_MODULE,
345 .short_name = "clie_5", 217 .name = "clie_5",
218 },
219 .description = "Sony Clie 5.0",
346 .id_table = clie_id_5_table, 220 .id_table = clie_id_5_table,
347 .num_interrupt_in = NUM_DONT_CARE, 221 .num_interrupt_in = NUM_DONT_CARE,
348 .num_bulk_in = 2, 222 .num_bulk_in = 2,
@@ -367,10 +241,12 @@ static struct usb_serial_device_type clie_5_device = {
367}; 241};
368 242
369/* device info for the Sony Clie OS version 3.5 */ 243/* device info for the Sony Clie OS version 3.5 */
370static struct usb_serial_device_type clie_3_5_device = { 244static struct usb_serial_driver clie_3_5_device = {
371 .owner = THIS_MODULE, 245 .driver = {
372 .name = "Sony Clie 3.5", 246 .owner = THIS_MODULE,
373 .short_name = "clie_3.5", 247 .name = "clie_3.5",
248 },
249 .description = "Sony Clie 3.5",
374 .id_table = clie_id_3_5_table, 250 .id_table = clie_id_3_5_table,
375 .num_interrupt_in = 0, 251 .num_interrupt_in = 0,
376 .num_bulk_in = 1, 252 .num_bulk_in = 1,
@@ -782,7 +658,7 @@ static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_i
782 break; 658 break;
783 } 659 }
784 dev_info(dev, "%s: port %d, is for %s use\n", 660 dev_info(dev, "%s: port %d, is for %s use\n",
785 serial->type->name, 661 serial->type->description,
786 connection_info->connections[i].port, string); 662 connection_info->connections[i].port, string);
787 } 663 }
788 } 664 }
@@ -791,11 +667,11 @@ static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_i
791 */ 667 */
792 if (num_ports == 0 || num_ports > 2) { 668 if (num_ports == 0 || num_ports > 2) {
793 dev_warn (dev, "%s: No valid connect info available\n", 669 dev_warn (dev, "%s: No valid connect info available\n",
794 serial->type->name); 670 serial->type->description);
795 num_ports = 2; 671 num_ports = 2;
796 } 672 }
797 673
798 dev_info(dev, "%s: Number of ports: %d\n", serial->type->name, 674 dev_info(dev, "%s: Number of ports: %d\n", serial->type->description,
799 num_ports); 675 num_ports);
800 676
801 /* 677 /*
@@ -1125,7 +1001,7 @@ static int __init visor_init (void)
1125 retval = usb_register(&visor_driver); 1001 retval = usb_register(&visor_driver);
1126 if (retval) 1002 if (retval)
1127 goto failed_usb_register; 1003 goto failed_usb_register;
1128 info(DRIVER_DESC " " DRIVER_VERSION); 1004 info(DRIVER_DESC);
1129 1005
1130 return 0; 1006 return 0;
1131failed_usb_register: 1007failed_usb_register:
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c
index cf3bc30675a1..18c3183be769 100644
--- a/drivers/usb/serial/whiteheat.c
+++ b/drivers/usb/serial/whiteheat.c
@@ -156,10 +156,12 @@ static void whiteheat_unthrottle (struct usb_serial_port *port);
156static void whiteheat_read_callback (struct urb *urb, struct pt_regs *regs); 156static void whiteheat_read_callback (struct urb *urb, struct pt_regs *regs);
157static void whiteheat_write_callback (struct urb *urb, struct pt_regs *regs); 157static void whiteheat_write_callback (struct urb *urb, struct pt_regs *regs);
158 158
159static struct usb_serial_device_type whiteheat_fake_device = { 159static struct usb_serial_driver whiteheat_fake_device = {
160 .owner = THIS_MODULE, 160 .driver = {
161 .name = "Connect Tech - WhiteHEAT - (prerenumeration)", 161 .owner = THIS_MODULE,
162 .short_name = "whiteheatnofirm", 162 .name = "whiteheatnofirm",
163 },
164 .description = "Connect Tech - WhiteHEAT - (prerenumeration)",
163 .id_table = id_table_prerenumeration, 165 .id_table = id_table_prerenumeration,
164 .num_interrupt_in = NUM_DONT_CARE, 166 .num_interrupt_in = NUM_DONT_CARE,
165 .num_bulk_in = NUM_DONT_CARE, 167 .num_bulk_in = NUM_DONT_CARE,
@@ -169,10 +171,12 @@ static struct usb_serial_device_type whiteheat_fake_device = {
169 .attach = whiteheat_firmware_attach, 171 .attach = whiteheat_firmware_attach,
170}; 172};
171 173
172static struct usb_serial_device_type whiteheat_device = { 174static struct usb_serial_driver whiteheat_device = {
173 .owner = THIS_MODULE, 175 .driver = {
174 .name = "Connect Tech - WhiteHEAT", 176 .owner = THIS_MODULE,
175 .short_name = "whiteheat", 177 .name = "whiteheat",
178 },
179 .description = "Connect Tech - WhiteHEAT",
176 .id_table = id_table_std, 180 .id_table = id_table_std,
177 .num_interrupt_in = NUM_DONT_CARE, 181 .num_interrupt_in = NUM_DONT_CARE,
178 .num_bulk_in = NUM_DONT_CARE, 182 .num_bulk_in = NUM_DONT_CARE,
@@ -382,10 +386,10 @@ static int whiteheat_attach (struct usb_serial *serial)
382 usb_clear_halt(serial->dev, pipe); 386 usb_clear_halt(serial->dev, pipe);
383 ret = usb_bulk_msg (serial->dev, pipe, command, 2, &alen, COMMAND_TIMEOUT_MS); 387 ret = usb_bulk_msg (serial->dev, pipe, command, 2, &alen, COMMAND_TIMEOUT_MS);
384 if (ret) { 388 if (ret) {
385 err("%s: Couldn't send command [%d]", serial->type->name, ret); 389 err("%s: Couldn't send command [%d]", serial->type->description, ret);
386 goto no_firmware; 390 goto no_firmware;
387 } else if (alen != sizeof(command)) { 391 } else if (alen != sizeof(command)) {
388 err("%s: Send command incomplete [%d]", serial->type->name, alen); 392 err("%s: Send command incomplete [%d]", serial->type->description, alen);
389 goto no_firmware; 393 goto no_firmware;
390 } 394 }
391 395
@@ -394,19 +398,19 @@ static int whiteheat_attach (struct usb_serial *serial)
394 usb_clear_halt(serial->dev, pipe); 398 usb_clear_halt(serial->dev, pipe);
395 ret = usb_bulk_msg (serial->dev, pipe, result, sizeof(*hw_info) + 1, &alen, COMMAND_TIMEOUT_MS); 399 ret = usb_bulk_msg (serial->dev, pipe, result, sizeof(*hw_info) + 1, &alen, COMMAND_TIMEOUT_MS);
396 if (ret) { 400 if (ret) {
397 err("%s: Couldn't get results [%d]", serial->type->name, ret); 401 err("%s: Couldn't get results [%d]", serial->type->description, ret);
398 goto no_firmware; 402 goto no_firmware;
399 } else if (alen != sizeof(result)) { 403 } else if (alen != sizeof(result)) {
400 err("%s: Get results incomplete [%d]", serial->type->name, alen); 404 err("%s: Get results incomplete [%d]", serial->type->description, alen);
401 goto no_firmware; 405 goto no_firmware;
402 } else if (result[0] != command[0]) { 406 } else if (result[0] != command[0]) {
403 err("%s: Command failed [%d]", serial->type->name, result[0]); 407 err("%s: Command failed [%d]", serial->type->description, result[0]);
404 goto no_firmware; 408 goto no_firmware;
405 } 409 }
406 410
407 hw_info = (struct whiteheat_hw_info *)&result[1]; 411 hw_info = (struct whiteheat_hw_info *)&result[1];
408 412
409 info("%s: Driver %s: Firmware v%d.%02d", serial->type->name, 413 info("%s: Driver %s: Firmware v%d.%02d", serial->type->description,
410 DRIVER_VERSION, hw_info->sw_major_rev, hw_info->sw_minor_rev); 414 DRIVER_VERSION, hw_info->sw_major_rev, hw_info->sw_minor_rev);
411 415
412 for (i = 0; i < serial->num_ports; i++) { 416 for (i = 0; i < serial->num_ports; i++) {
@@ -414,7 +418,7 @@ static int whiteheat_attach (struct usb_serial *serial)
414 418
415 info = (struct whiteheat_private *)kmalloc(sizeof(struct whiteheat_private), GFP_KERNEL); 419 info = (struct whiteheat_private *)kmalloc(sizeof(struct whiteheat_private), GFP_KERNEL);
416 if (info == NULL) { 420 if (info == NULL) {
417 err("%s: Out of memory for port structures\n", serial->type->name); 421 err("%s: Out of memory for port structures\n", serial->type->description);
418 goto no_private; 422 goto no_private;
419 } 423 }
420 424
@@ -484,7 +488,7 @@ static int whiteheat_attach (struct usb_serial *serial)
484 488
485 command_info = (struct whiteheat_command_private *)kmalloc(sizeof(struct whiteheat_command_private), GFP_KERNEL); 489 command_info = (struct whiteheat_command_private *)kmalloc(sizeof(struct whiteheat_command_private), GFP_KERNEL);
486 if (command_info == NULL) { 490 if (command_info == NULL) {
487 err("%s: Out of memory for port structures\n", serial->type->name); 491 err("%s: Out of memory for port structures\n", serial->type->description);
488 goto no_command_private; 492 goto no_command_private;
489 } 493 }
490 494
@@ -501,9 +505,9 @@ static int whiteheat_attach (struct usb_serial *serial)
501 505
502no_firmware: 506no_firmware:
503 /* Firmware likely not running */ 507 /* Firmware likely not running */
504 err("%s: Unable to retrieve firmware version, try replugging\n", serial->type->name); 508 err("%s: Unable to retrieve firmware version, try replugging\n", serial->type->description);
505 err("%s: If the firmware is not running (status led not blinking)\n", serial->type->name); 509 err("%s: If the firmware is not running (status led not blinking)\n", serial->type->description);
506 err("%s: please contact support@connecttech.com\n", serial->type->name); 510 err("%s: please contact support@connecttech.com\n", serial->type->description);
507 return -ENODEV; 511 return -ENODEV;
508 512
509no_command_private: 513no_command_private:
diff --git a/drivers/usb/storage/Kconfig b/drivers/usb/storage/Kconfig
index bb9819cc8826..1a9679f76f5a 100644
--- a/drivers/usb/storage/Kconfig
+++ b/drivers/usb/storage/Kconfig
@@ -2,7 +2,8 @@
2# USB Storage driver configuration 2# USB Storage driver configuration
3# 3#
4 4
5comment "NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support' may also be needed; see USB_STORAGE Help for more information" 5comment "NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'"
6comment "may also be needed; see USB_STORAGE Help for more information"
6 depends on USB 7 depends on USB
7 8
8config USB_STORAGE 9config USB_STORAGE
diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c
index 2c9402dc702b..89401a59f952 100644
--- a/drivers/usb/storage/onetouch.c
+++ b/drivers/usb/storage/onetouch.c
@@ -5,7 +5,7 @@
5 * Copyright (c) 2005 Nick Sillik <n.sillik@temple.edu> 5 * Copyright (c) 2005 Nick Sillik <n.sillik@temple.edu>
6 * 6 *
7 * Initial work by: 7 * Initial work by:
8 * Copyright (c) 2003 Erik Thyren <erth7411@student.uu.se> 8 * Copyright (c) 2003 Erik Thyren <erth7411@student.uu.se>
9 * 9 *
10 * Based on usbmouse.c (Vojtech Pavlik) and xpad.c (Marko Friedemann) 10 * Based on usbmouse.c (Vojtech Pavlik) and xpad.c (Marko Friedemann)
11 * 11 *
@@ -46,7 +46,7 @@ void onetouch_release_input(void *onetouch_);
46struct usb_onetouch { 46struct usb_onetouch {
47 char name[128]; 47 char name[128];
48 char phys[64]; 48 char phys[64];
49 struct input_dev dev; /* input device interface */ 49 struct input_dev *dev; /* input device interface */
50 struct usb_device *udev; /* usb device */ 50 struct usb_device *udev; /* usb device */
51 51
52 struct urb *irq; /* urb for interrupt in report */ 52 struct urb *irq; /* urb for interrupt in report */
@@ -58,7 +58,7 @@ static void usb_onetouch_irq(struct urb *urb, struct pt_regs *regs)
58{ 58{
59 struct usb_onetouch *onetouch = urb->context; 59 struct usb_onetouch *onetouch = urb->context;
60 signed char *data = onetouch->data; 60 signed char *data = onetouch->data;
61 struct input_dev *dev = &onetouch->dev; 61 struct input_dev *dev = onetouch->dev;
62 int status; 62 int status;
63 63
64 switch (urb->status) { 64 switch (urb->status) {
@@ -74,11 +74,9 @@ static void usb_onetouch_irq(struct urb *urb, struct pt_regs *regs)
74 } 74 }
75 75
76 input_regs(dev, regs); 76 input_regs(dev, regs);
77 77 input_report_key(dev, ONETOUCH_BUTTON, data[0] & 0x02);
78 input_report_key(&onetouch->dev, ONETOUCH_BUTTON,
79 data[0] & 0x02);
80
81 input_sync(dev); 78 input_sync(dev);
79
82resubmit: 80resubmit:
83 status = usb_submit_urb (urb, SLAB_ATOMIC); 81 status = usb_submit_urb (urb, SLAB_ATOMIC);
84 if (status) 82 if (status)
@@ -113,8 +111,8 @@ int onetouch_connect_input(struct us_data *ss)
113 struct usb_host_interface *interface; 111 struct usb_host_interface *interface;
114 struct usb_endpoint_descriptor *endpoint; 112 struct usb_endpoint_descriptor *endpoint;
115 struct usb_onetouch *onetouch; 113 struct usb_onetouch *onetouch;
114 struct input_dev *input_dev;
116 int pipe, maxp; 115 int pipe, maxp;
117 char path[64];
118 116
119 interface = ss->pusb_intf->cur_altsetting; 117 interface = ss->pusb_intf->cur_altsetting;
120 118
@@ -122,62 +120,62 @@ int onetouch_connect_input(struct us_data *ss)
122 return -ENODEV; 120 return -ENODEV;
123 121
124 endpoint = &interface->endpoint[2].desc; 122 endpoint = &interface->endpoint[2].desc;
125 if(!(endpoint->bEndpointAddress & USB_DIR_IN)) 123 if (!(endpoint->bEndpointAddress & USB_DIR_IN))
126 return -ENODEV; 124 return -ENODEV;
127 if((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) 125 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
128 != USB_ENDPOINT_XFER_INT) 126 != USB_ENDPOINT_XFER_INT)
129 return -ENODEV; 127 return -ENODEV;
130 128
131 pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress); 129 pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress);
132 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe)); 130 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
133 131
134 if (!(onetouch = kcalloc(1, sizeof(struct usb_onetouch), GFP_KERNEL))) 132 onetouch = kzalloc(sizeof(struct usb_onetouch), GFP_KERNEL);
135 return -ENOMEM; 133 input_dev = input_allocate_device();
134 if (!onetouch || !input_dev)
135 goto fail1;
136 136
137 onetouch->data = usb_buffer_alloc(udev, ONETOUCH_PKT_LEN, 137 onetouch->data = usb_buffer_alloc(udev, ONETOUCH_PKT_LEN,
138 SLAB_ATOMIC, &onetouch->data_dma); 138 SLAB_ATOMIC, &onetouch->data_dma);
139 if (!onetouch->data){ 139 if (!onetouch->data)
140 kfree(onetouch); 140 goto fail1;
141 return -ENOMEM;
142 }
143 141
144 onetouch->irq = usb_alloc_urb(0, GFP_KERNEL); 142 onetouch->irq = usb_alloc_urb(0, GFP_KERNEL);
145 if (!onetouch->irq){ 143 if (!onetouch->irq)
146 kfree(onetouch); 144 goto fail2;
147 usb_buffer_free(udev, ONETOUCH_PKT_LEN,
148 onetouch->data, onetouch->data_dma);
149 return -ENODEV;
150 }
151
152 145
153 onetouch->udev = udev; 146 onetouch->udev = udev;
147 onetouch->dev = input_dev;
154 148
155 set_bit(EV_KEY, onetouch->dev.evbit); 149 if (udev->manufacturer)
156 set_bit(ONETOUCH_BUTTON, onetouch->dev.keybit); 150 strlcpy(onetouch->name, udev->manufacturer,
157 clear_bit(0, onetouch->dev.keybit); 151 sizeof(onetouch->name));
152 if (udev->product) {
153 if (udev->manufacturer)
154 strlcat(onetouch->name, " ", sizeof(onetouch->name));
155 strlcat(onetouch->name, udev->product, sizeof(onetouch->name));
156 }
158 157
159 onetouch->dev.private = onetouch; 158 if (!strlen(onetouch->name))
160 onetouch->dev.open = usb_onetouch_open; 159 snprintf(onetouch->name, sizeof(onetouch->name),
161 onetouch->dev.close = usb_onetouch_close; 160 "Maxtor Onetouch %04x:%04x",
161 le16_to_cpu(udev->descriptor.idVendor),
162 le16_to_cpu(udev->descriptor.idProduct));
162 163
163 usb_make_path(udev, path, sizeof(path)); 164 usb_make_path(udev, onetouch->phys, sizeof(onetouch->phys));
164 sprintf(onetouch->phys, "%s/input0", path); 165 strlcat(onetouch->phys, "/input0", sizeof(onetouch->phys));
165 166
166 onetouch->dev.name = onetouch->name; 167 input_dev->name = onetouch->name;
167 onetouch->dev.phys = onetouch->phys; 168 input_dev->phys = onetouch->phys;
169 usb_to_input_id(udev, &input_dev->id);
170 input_dev->cdev.dev = &udev->dev;
168 171
169 usb_to_input_id(udev, &onetouch->dev.id); 172 set_bit(EV_KEY, input_dev->evbit);
173 set_bit(ONETOUCH_BUTTON, input_dev->keybit);
174 clear_bit(0, input_dev->keybit);
170 175
171 onetouch->dev.dev = &udev->dev; 176 input_dev->private = onetouch;
172 177 input_dev->open = usb_onetouch_open;
173 if (udev->manufacturer) 178 input_dev->close = usb_onetouch_close;
174 strcat(onetouch->name, udev->manufacturer);
175 if (udev->product)
176 sprintf(onetouch->name, "%s %s", onetouch->name,
177 udev->product);
178 if (!strlen(onetouch->name))
179 sprintf(onetouch->name, "Maxtor Onetouch %04x:%04x",
180 onetouch->dev.id.vendor, onetouch->dev.id.product);
181 179
182 usb_fill_int_urb(onetouch->irq, udev, pipe, onetouch->data, 180 usb_fill_int_urb(onetouch->irq, udev, pipe, onetouch->data,
183 (maxp > 8 ? 8 : maxp), 181 (maxp > 8 ? 8 : maxp),
@@ -188,10 +186,15 @@ int onetouch_connect_input(struct us_data *ss)
188 ss->extra_destructor = onetouch_release_input; 186 ss->extra_destructor = onetouch_release_input;
189 ss->extra = onetouch; 187 ss->extra = onetouch;
190 188
191 input_register_device(&onetouch->dev); 189 input_register_device(onetouch->dev);
192 printk(KERN_INFO "usb-input: %s on %s\n", onetouch->dev.name, path);
193 190
194 return 0; 191 return 0;
192
193 fail2: usb_buffer_free(udev, ONETOUCH_PKT_LEN,
194 onetouch->data, onetouch->data_dma);
195 fail1: kfree(onetouch);
196 input_free_device(input_dev);
197 return -ENOMEM;
195} 198}
196 199
197void onetouch_release_input(void *onetouch_) 200void onetouch_release_input(void *onetouch_)
@@ -200,11 +203,9 @@ void onetouch_release_input(void *onetouch_)
200 203
201 if (onetouch) { 204 if (onetouch) {
202 usb_kill_urb(onetouch->irq); 205 usb_kill_urb(onetouch->irq);
203 input_unregister_device(&onetouch->dev); 206 input_unregister_device(onetouch->dev);
204 usb_free_urb(onetouch->irq); 207 usb_free_urb(onetouch->irq);
205 usb_buffer_free(onetouch->udev, ONETOUCH_PKT_LEN, 208 usb_buffer_free(onetouch->udev, ONETOUCH_PKT_LEN,
206 onetouch->data, onetouch->data_dma); 209 onetouch->data, onetouch->data_dma);
207 printk(KERN_INFO "usb-input: deregistering %s\n",
208 onetouch->dev.name);
209 } 210 }
210} 211}
diff --git a/drivers/usb/storage/shuttle_usbat.c b/drivers/usb/storage/shuttle_usbat.c
index 356342c6e7a2..33c55a6261bb 100644
--- a/drivers/usb/storage/shuttle_usbat.c
+++ b/drivers/usb/storage/shuttle_usbat.c
@@ -1,4 +1,4 @@
1/* Driver for SCM Microsystems USB-ATAPI cable 1/* Driver for SCM Microsystems (a.k.a. Shuttle) USB-ATAPI cable
2 * 2 *
3 * $Id: shuttle_usbat.c,v 1.17 2002/04/22 03:39:43 mdharm Exp $ 3 * $Id: shuttle_usbat.c,v 1.17 2002/04/22 03:39:43 mdharm Exp $
4 * 4 *
@@ -67,10 +67,10 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us);
67static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us); 67static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us);
68 68
69/* 69/*
70 * Convenience function to produce an ATAPI read/write sectors command 70 * Convenience function to produce an ATA read/write sectors command
71 * Use cmd=0x20 for read, cmd=0x30 for write 71 * Use cmd=0x20 for read, cmd=0x30 for write
72 */ 72 */
73static void usbat_pack_atapi_sector_cmd(unsigned char *buf, 73static void usbat_pack_ata_sector_cmd(unsigned char *buf,
74 unsigned char thistime, 74 unsigned char thistime,
75 u32 sector, unsigned char cmd) 75 u32 sector, unsigned char cmd)
76{ 76{
@@ -196,10 +196,12 @@ static int usbat_check_status(struct us_data *us)
196 if (rc != USB_STOR_XFER_GOOD) 196 if (rc != USB_STOR_XFER_GOOD)
197 return USB_STOR_TRANSPORT_FAILED; 197 return USB_STOR_TRANSPORT_FAILED;
198 198
199 if (*reply & 0x01 && *reply != 0x51) // error/check condition (0x51 is ok) 199 /* error/check condition (0x51 is ok) */
200 if (*reply & 0x01 && *reply != 0x51)
200 return USB_STOR_TRANSPORT_FAILED; 201 return USB_STOR_TRANSPORT_FAILED;
201 202
202 if (*reply & 0x20) // device fault 203 /* device fault */
204 if (*reply & 0x20)
203 return USB_STOR_TRANSPORT_FAILED; 205 return USB_STOR_TRANSPORT_FAILED;
204 206
205 return USB_STOR_TRANSPORT_GOOD; 207 return USB_STOR_TRANSPORT_GOOD;
@@ -222,29 +224,39 @@ static int usbat_set_shuttle_features(struct us_data *us,
222 command[0] = 0x40; 224 command[0] = 0x40;
223 command[1] = USBAT_CMD_SET_FEAT; 225 command[1] = USBAT_CMD_SET_FEAT;
224 226
225 // The only bit relevant to ATA access is bit 6 227 /*
226 // which defines 8 bit data access (set) or 16 bit (unset) 228 * The only bit relevant to ATA access is bit 6
229 * which defines 8 bit data access (set) or 16 bit (unset)
230 */
227 command[2] = epp_control; 231 command[2] = epp_control;
228 232
229 // If FCQ is set in the qualifier (defined in R/W cmd), then bits U0, U1, 233 /*
230 // ET1 and ET2 define an external event to be checked for on event of a 234 * If FCQ is set in the qualifier (defined in R/W cmd), then bits U0, U1,
231 // _read_blocks or _write_blocks operation. The read/write will not take 235 * ET1 and ET2 define an external event to be checked for on event of a
232 // place unless the defined trigger signal is active. 236 * _read_blocks or _write_blocks operation. The read/write will not take
237 * place unless the defined trigger signal is active.
238 */
233 command[3] = external_trigger; 239 command[3] = external_trigger;
234 240
235 // The resultant byte of the mask operation (see mask_byte) is compared for 241 /*
236 // equivalence with this test pattern. If equal, the read/write will take 242 * The resultant byte of the mask operation (see mask_byte) is compared for
237 // place. 243 * equivalence with this test pattern. If equal, the read/write will take
244 * place.
245 */
238 command[4] = test_pattern; 246 command[4] = test_pattern;
239 247
240 // This value is logically ANDed with the status register field specified 248 /*
241 // in the read/write command. 249 * This value is logically ANDed with the status register field specified
250 * in the read/write command.
251 */
242 command[5] = mask_byte; 252 command[5] = mask_byte;
243 253
244 // If ALQ is set in the qualifier, this field contains the address of the 254 /*
245 // registers where the byte count should be read for transferring the data. 255 * If ALQ is set in the qualifier, this field contains the address of the
246 // If ALQ is not set, then this field contains the number of bytes to be 256 * registers where the byte count should be read for transferring the data.
247 // transferred. 257 * If ALQ is not set, then this field contains the number of bytes to be
258 * transferred.
259 */
248 command[6] = subcountL; 260 command[6] = subcountL;
249 command[7] = subcountH; 261 command[7] = subcountH;
250 262
@@ -273,26 +285,26 @@ static int usbat_wait_not_busy(struct us_data *us, int minutes)
273 285
274 if (result!=USB_STOR_XFER_GOOD) 286 if (result!=USB_STOR_XFER_GOOD)
275 return USB_STOR_TRANSPORT_ERROR; 287 return USB_STOR_TRANSPORT_ERROR;
276 if (*status & 0x01) { // check condition 288 if (*status & 0x01) { /* check condition */
277 result = usbat_read(us, USBAT_ATA, 0x10, status); 289 result = usbat_read(us, USBAT_ATA, 0x10, status);
278 return USB_STOR_TRANSPORT_FAILED; 290 return USB_STOR_TRANSPORT_FAILED;
279 } 291 }
280 if (*status & 0x20) // device fault 292 if (*status & 0x20) /* device fault */
281 return USB_STOR_TRANSPORT_FAILED; 293 return USB_STOR_TRANSPORT_FAILED;
282 294
283 if ((*status & 0x80)==0x00) { // not busy 295 if ((*status & 0x80)==0x00) { /* not busy */
284 US_DEBUGP("Waited not busy for %d steps\n", i); 296 US_DEBUGP("Waited not busy for %d steps\n", i);
285 return USB_STOR_TRANSPORT_GOOD; 297 return USB_STOR_TRANSPORT_GOOD;
286 } 298 }
287 299
288 if (i<500) 300 if (i<500)
289 msleep(10); // 5 seconds 301 msleep(10); /* 5 seconds */
290 else if (i<700) 302 else if (i<700)
291 msleep(50); // 10 seconds 303 msleep(50); /* 10 seconds */
292 else if (i<1200) 304 else if (i<1200)
293 msleep(100); // 50 seconds 305 msleep(100); /* 50 seconds */
294 else 306 else
295 msleep(1000); // X minutes 307 msleep(1000); /* X minutes */
296 } 308 }
297 309
298 US_DEBUGP("Waited not busy for %d minutes, timing out.\n", 310 US_DEBUGP("Waited not busy for %d minutes, timing out.\n",
@@ -412,9 +424,12 @@ static int usbat_hp8200e_rw_block_test(struct us_data *us,
412 424
413 if (i==0) { 425 if (i==0) {
414 cmdlen = 16; 426 cmdlen = 16;
415 // Write to multiple registers 427 /*
416 // Not really sure the 0x07, 0x17, 0xfc, 0xe7 is necessary here, 428 * Write to multiple registers
417 // but that's what came out of the trace every single time. 429 * Not really sure the 0x07, 0x17, 0xfc, 0xe7 is
430 * necessary here, but that's what came out of the
431 * trace every single time.
432 */
418 command[0] = 0x40; 433 command[0] = 0x40;
419 command[1] = access | USBAT_CMD_WRITE_REGS; 434 command[1] = access | USBAT_CMD_WRITE_REGS;
420 command[2] = 0x07; 435 command[2] = 0x07;
@@ -426,7 +441,7 @@ static int usbat_hp8200e_rw_block_test(struct us_data *us,
426 } else 441 } else
427 cmdlen = 8; 442 cmdlen = 8;
428 443
429 // Conditionally read or write blocks 444 /* Conditionally read or write blocks */
430 command[cmdlen-8] = (direction==DMA_TO_DEVICE ? 0x40 : 0xC0); 445 command[cmdlen-8] = (direction==DMA_TO_DEVICE ? 0x40 : 0xC0);
431 command[cmdlen-7] = access | 446 command[cmdlen-7] = access |
432 (direction==DMA_TO_DEVICE ? 447 (direction==DMA_TO_DEVICE ?
@@ -456,11 +471,6 @@ static int usbat_hp8200e_rw_block_test(struct us_data *us,
456 471
457 } 472 }
458 473
459
460 //US_DEBUGP("Transfer %s %d bytes, sg buffers %d\n",
461 // direction == DMA_TO_DEVICE ? "out" : "in",
462 // len, use_sg);
463
464 result = usb_stor_bulk_transfer_sg(us, 474 result = usb_stor_bulk_transfer_sg(us,
465 pipe, content, len, use_sg, NULL); 475 pipe, content, len, use_sg, NULL);
466 476
@@ -508,9 +518,9 @@ static int usbat_hp8200e_rw_block_test(struct us_data *us,
508 518
509 if (result!=USB_STOR_XFER_GOOD) 519 if (result!=USB_STOR_XFER_GOOD)
510 return USB_STOR_TRANSPORT_ERROR; 520 return USB_STOR_TRANSPORT_ERROR;
511 if (*status & 0x01) // check condition 521 if (*status & 0x01) /* check condition */
512 return USB_STOR_TRANSPORT_FAILED; 522 return USB_STOR_TRANSPORT_FAILED;
513 if (*status & 0x20) // device fault 523 if (*status & 0x20) /* device fault */
514 return USB_STOR_TRANSPORT_FAILED; 524 return USB_STOR_TRANSPORT_FAILED;
515 525
516 US_DEBUGP("Redoing %s\n", 526 US_DEBUGP("Redoing %s\n",
@@ -547,32 +557,32 @@ static int usbat_multiple_write(struct us_data *us,
547 557
548 BUG_ON(num_registers > US_IOBUF_SIZE/2); 558 BUG_ON(num_registers > US_IOBUF_SIZE/2);
549 559
550 // Write to multiple registers, ATA access 560 /* Write to multiple registers, ATA access */
551 command[0] = 0x40; 561 command[0] = 0x40;
552 command[1] = USBAT_ATA | USBAT_CMD_WRITE_REGS; 562 command[1] = USBAT_ATA | USBAT_CMD_WRITE_REGS;
553 563
554 // No relevance 564 /* No relevance */
555 command[2] = 0; 565 command[2] = 0;
556 command[3] = 0; 566 command[3] = 0;
557 command[4] = 0; 567 command[4] = 0;
558 command[5] = 0; 568 command[5] = 0;
559 569
560 // Number of bytes to be transferred (incl. addresses and data) 570 /* Number of bytes to be transferred (incl. addresses and data) */
561 command[6] = LSB_of(num_registers*2); 571 command[6] = LSB_of(num_registers*2);
562 command[7] = MSB_of(num_registers*2); 572 command[7] = MSB_of(num_registers*2);
563 573
564 // The setup command 574 /* The setup command */
565 result = usbat_execute_command(us, command, 8); 575 result = usbat_execute_command(us, command, 8);
566 if (result != USB_STOR_XFER_GOOD) 576 if (result != USB_STOR_XFER_GOOD)
567 return USB_STOR_TRANSPORT_ERROR; 577 return USB_STOR_TRANSPORT_ERROR;
568 578
569 // Create the reg/data, reg/data sequence 579 /* Create the reg/data, reg/data sequence */
570 for (i=0; i<num_registers; i++) { 580 for (i=0; i<num_registers; i++) {
571 data[i<<1] = registers[i]; 581 data[i<<1] = registers[i];
572 data[1+(i<<1)] = data_out[i]; 582 data[1+(i<<1)] = data_out[i];
573 } 583 }
574 584
575 // Send the data 585 /* Send the data */
576 result = usbat_bulk_write(us, data, num_registers*2); 586 result = usbat_bulk_write(us, data, num_registers*2);
577 if (result != USB_STOR_XFER_GOOD) 587 if (result != USB_STOR_XFER_GOOD)
578 return USB_STOR_TRANSPORT_ERROR; 588 return USB_STOR_TRANSPORT_ERROR;
@@ -606,17 +616,17 @@ static int usbat_read_blocks(struct us_data *us,
606 command[1] = USBAT_ATA | USBAT_CMD_COND_READ_BLOCK; 616 command[1] = USBAT_ATA | USBAT_CMD_COND_READ_BLOCK;
607 command[2] = USBAT_ATA_DATA; 617 command[2] = USBAT_ATA_DATA;
608 command[3] = USBAT_ATA_STATUS; 618 command[3] = USBAT_ATA_STATUS;
609 command[4] = 0xFD; // Timeout (ms); 619 command[4] = 0xFD; /* Timeout (ms); */
610 command[5] = USBAT_QUAL_FCQ; 620 command[5] = USBAT_QUAL_FCQ;
611 command[6] = LSB_of(len); 621 command[6] = LSB_of(len);
612 command[7] = MSB_of(len); 622 command[7] = MSB_of(len);
613 623
614 // Multiple block read setup command 624 /* Multiple block read setup command */
615 result = usbat_execute_command(us, command, 8); 625 result = usbat_execute_command(us, command, 8);
616 if (result != USB_STOR_XFER_GOOD) 626 if (result != USB_STOR_XFER_GOOD)
617 return USB_STOR_TRANSPORT_FAILED; 627 return USB_STOR_TRANSPORT_FAILED;
618 628
619 // Read the blocks we just asked for 629 /* Read the blocks we just asked for */
620 result = usbat_bulk_read(us, buffer, len); 630 result = usbat_bulk_read(us, buffer, len);
621 if (result != USB_STOR_XFER_GOOD) 631 if (result != USB_STOR_XFER_GOOD)
622 return USB_STOR_TRANSPORT_FAILED; 632 return USB_STOR_TRANSPORT_FAILED;
@@ -647,17 +657,17 @@ static int usbat_write_blocks(struct us_data *us,
647 command[1] = USBAT_ATA | USBAT_CMD_COND_WRITE_BLOCK; 657 command[1] = USBAT_ATA | USBAT_CMD_COND_WRITE_BLOCK;
648 command[2] = USBAT_ATA_DATA; 658 command[2] = USBAT_ATA_DATA;
649 command[3] = USBAT_ATA_STATUS; 659 command[3] = USBAT_ATA_STATUS;
650 command[4] = 0xFD; // Timeout (ms) 660 command[4] = 0xFD; /* Timeout (ms) */
651 command[5] = USBAT_QUAL_FCQ; 661 command[5] = USBAT_QUAL_FCQ;
652 command[6] = LSB_of(len); 662 command[6] = LSB_of(len);
653 command[7] = MSB_of(len); 663 command[7] = MSB_of(len);
654 664
655 // Multiple block write setup command 665 /* Multiple block write setup command */
656 result = usbat_execute_command(us, command, 8); 666 result = usbat_execute_command(us, command, 8);
657 if (result != USB_STOR_XFER_GOOD) 667 if (result != USB_STOR_XFER_GOOD)
658 return USB_STOR_TRANSPORT_FAILED; 668 return USB_STOR_TRANSPORT_FAILED;
659 669
660 // Write the data 670 /* Write the data */
661 result = usbat_bulk_write(us, buffer, len); 671 result = usbat_bulk_write(us, buffer, len);
662 if (result != USB_STOR_XFER_GOOD) 672 if (result != USB_STOR_XFER_GOOD)
663 return USB_STOR_TRANSPORT_FAILED; 673 return USB_STOR_TRANSPORT_FAILED;
@@ -711,16 +721,20 @@ static int usbat_device_reset(struct us_data *us)
711{ 721{
712 int rc; 722 int rc;
713 723
714 // Reset peripheral, enable peripheral control signals 724 /*
715 // (bring reset signal up) 725 * Reset peripheral, enable peripheral control signals
726 * (bring reset signal up)
727 */
716 rc = usbat_write_user_io(us, 728 rc = usbat_write_user_io(us,
717 USBAT_UIO_DRVRST | USBAT_UIO_OE1 | USBAT_UIO_OE0, 729 USBAT_UIO_DRVRST | USBAT_UIO_OE1 | USBAT_UIO_OE0,
718 USBAT_UIO_EPAD | USBAT_UIO_1); 730 USBAT_UIO_EPAD | USBAT_UIO_1);
719 if (rc != USB_STOR_XFER_GOOD) 731 if (rc != USB_STOR_XFER_GOOD)
720 return USB_STOR_TRANSPORT_ERROR; 732 return USB_STOR_TRANSPORT_ERROR;
721 733
722 // Enable peripheral control signals 734 /*
723 // (bring reset signal down) 735 * Enable peripheral control signals
736 * (bring reset signal down)
737 */
724 rc = usbat_write_user_io(us, 738 rc = usbat_write_user_io(us,
725 USBAT_UIO_OE1 | USBAT_UIO_OE0, 739 USBAT_UIO_OE1 | USBAT_UIO_OE0,
726 USBAT_UIO_EPAD | USBAT_UIO_1); 740 USBAT_UIO_EPAD | USBAT_UIO_1);
@@ -737,7 +751,7 @@ static int usbat_device_enable_cdt(struct us_data *us)
737{ 751{
738 int rc; 752 int rc;
739 753
740 // Enable peripheral control signals and card detect 754 /* Enable peripheral control signals and card detect */
741 rc = usbat_write_user_io(us, 755 rc = usbat_write_user_io(us,
742 USBAT_UIO_ACKD | USBAT_UIO_OE1 | USBAT_UIO_OE0, 756 USBAT_UIO_ACKD | USBAT_UIO_OE1 | USBAT_UIO_OE0,
743 USBAT_UIO_EPAD | USBAT_UIO_1); 757 USBAT_UIO_EPAD | USBAT_UIO_1);
@@ -786,7 +800,7 @@ static int usbat_flash_check_media(struct us_data *us,
786 if (rc != USB_STOR_XFER_GOOD) 800 if (rc != USB_STOR_XFER_GOOD)
787 return USB_STOR_TRANSPORT_ERROR; 801 return USB_STOR_TRANSPORT_ERROR;
788 802
789 // Check for media existence 803 /* Check for media existence */
790 rc = usbat_flash_check_media_present(uio); 804 rc = usbat_flash_check_media_present(uio);
791 if (rc == USBAT_FLASH_MEDIA_NONE) { 805 if (rc == USBAT_FLASH_MEDIA_NONE) {
792 info->sense_key = 0x02; 806 info->sense_key = 0x02;
@@ -795,11 +809,11 @@ static int usbat_flash_check_media(struct us_data *us,
795 return USB_STOR_TRANSPORT_FAILED; 809 return USB_STOR_TRANSPORT_FAILED;
796 } 810 }
797 811
798 // Check for media change 812 /* Check for media change */
799 rc = usbat_flash_check_media_changed(uio); 813 rc = usbat_flash_check_media_changed(uio);
800 if (rc == USBAT_FLASH_MEDIA_CHANGED) { 814 if (rc == USBAT_FLASH_MEDIA_CHANGED) {
801 815
802 // Reset and re-enable card detect 816 /* Reset and re-enable card detect */
803 rc = usbat_device_reset(us); 817 rc = usbat_device_reset(us);
804 if (rc != USB_STOR_TRANSPORT_GOOD) 818 if (rc != USB_STOR_TRANSPORT_GOOD)
805 return rc; 819 return rc;
@@ -855,15 +869,15 @@ static int usbat_identify_device(struct us_data *us,
855 if (rc != USB_STOR_XFER_GOOD) 869 if (rc != USB_STOR_XFER_GOOD)
856 return USB_STOR_TRANSPORT_ERROR; 870 return USB_STOR_TRANSPORT_ERROR;
857 871
858 // Check for error bit 872 /* Check for error bit, or if the command 'fell through' */
859 if (status & 0x01) { 873 if (status == 0xA1 || !(status & 0x01)) {
860 // Device is a CompactFlash reader/writer 874 /* Device is HP 8200 */
861 US_DEBUGP("usbat_identify_device: Detected Flash reader/writer\n");
862 info->devicetype = USBAT_DEV_FLASH;
863 } else {
864 // Device is HP 8200
865 US_DEBUGP("usbat_identify_device: Detected HP8200 CDRW\n"); 875 US_DEBUGP("usbat_identify_device: Detected HP8200 CDRW\n");
866 info->devicetype = USBAT_DEV_HP8200; 876 info->devicetype = USBAT_DEV_HP8200;
877 } else {
878 /* Device is a CompactFlash reader/writer */
879 US_DEBUGP("usbat_identify_device: Detected Flash reader/writer\n");
880 info->devicetype = USBAT_DEV_FLASH;
867 } 881 }
868 882
869 return USB_STOR_TRANSPORT_GOOD; 883 return USB_STOR_TRANSPORT_GOOD;
@@ -916,7 +930,7 @@ static int usbat_flash_get_sector_count(struct us_data *us,
916 if (!reply) 930 if (!reply)
917 return USB_STOR_TRANSPORT_ERROR; 931 return USB_STOR_TRANSPORT_ERROR;
918 932
919 // ATAPI command : IDENTIFY DEVICE 933 /* ATA command : IDENTIFY DEVICE */
920 rc = usbat_multiple_write(us, registers, command, 3); 934 rc = usbat_multiple_write(us, registers, command, 3);
921 if (rc != USB_STOR_XFER_GOOD) { 935 if (rc != USB_STOR_XFER_GOOD) {
922 US_DEBUGP("usbat_flash_get_sector_count: Gah! identify_device failed\n"); 936 US_DEBUGP("usbat_flash_get_sector_count: Gah! identify_device failed\n");
@@ -924,7 +938,7 @@ static int usbat_flash_get_sector_count(struct us_data *us,
924 goto leave; 938 goto leave;
925 } 939 }
926 940
927 // Read device status 941 /* Read device status */
928 if (usbat_get_status(us, &status) != USB_STOR_XFER_GOOD) { 942 if (usbat_get_status(us, &status) != USB_STOR_XFER_GOOD) {
929 rc = USB_STOR_TRANSPORT_ERROR; 943 rc = USB_STOR_TRANSPORT_ERROR;
930 goto leave; 944 goto leave;
@@ -932,7 +946,7 @@ static int usbat_flash_get_sector_count(struct us_data *us,
932 946
933 msleep(100); 947 msleep(100);
934 948
935 // Read the device identification data 949 /* Read the device identification data */
936 rc = usbat_read_block(us, reply, 512); 950 rc = usbat_read_block(us, reply, 512);
937 if (rc != USB_STOR_TRANSPORT_GOOD) 951 if (rc != USB_STOR_TRANSPORT_GOOD)
938 goto leave; 952 goto leave;
@@ -977,19 +991,23 @@ static int usbat_flash_read_data(struct us_data *us,
977 if (result != USB_STOR_TRANSPORT_GOOD) 991 if (result != USB_STOR_TRANSPORT_GOOD)
978 return result; 992 return result;
979 993
980 // we're working in LBA mode. according to the ATA spec, 994 /*
981 // we can support up to 28-bit addressing. I don't know if Jumpshot 995 * we're working in LBA mode. according to the ATA spec,
982 // supports beyond 24-bit addressing. It's kind of hard to test 996 * we can support up to 28-bit addressing. I don't know if Jumpshot
983 // since it requires > 8GB CF card. 997 * supports beyond 24-bit addressing. It's kind of hard to test
998 * since it requires > 8GB CF card.
999 */
984 1000
985 if (sector > 0x0FFFFFFF) 1001 if (sector > 0x0FFFFFFF)
986 return USB_STOR_TRANSPORT_ERROR; 1002 return USB_STOR_TRANSPORT_ERROR;
987 1003
988 totallen = sectors * info->ssize; 1004 totallen = sectors * info->ssize;
989 1005
990 // Since we don't read more than 64 KB at a time, we have to create 1006 /*
991 // a bounce buffer and move the data a piece at a time between the 1007 * Since we don't read more than 64 KB at a time, we have to create
992 // bounce buffer and the actual transfer buffer. 1008 * a bounce buffer and move the data a piece at a time between the
1009 * bounce buffer and the actual transfer buffer.
1010 */
993 1011
994 alloclen = min(totallen, 65536u); 1012 alloclen = min(totallen, 65536u);
995 buffer = kmalloc(alloclen, GFP_NOIO); 1013 buffer = kmalloc(alloclen, GFP_NOIO);
@@ -997,27 +1015,29 @@ static int usbat_flash_read_data(struct us_data *us,
997 return USB_STOR_TRANSPORT_ERROR; 1015 return USB_STOR_TRANSPORT_ERROR;
998 1016
999 do { 1017 do {
1000 // loop, never allocate or transfer more than 64k at once 1018 /*
1001 // (min(128k, 255*info->ssize) is the real limit) 1019 * loop, never allocate or transfer more than 64k at once
1020 * (min(128k, 255*info->ssize) is the real limit)
1021 */
1002 len = min(totallen, alloclen); 1022 len = min(totallen, alloclen);
1003 thistime = (len / info->ssize) & 0xff; 1023 thistime = (len / info->ssize) & 0xff;
1004 1024
1005 // ATAPI command 0x20 (READ SECTORS) 1025 /* ATA command 0x20 (READ SECTORS) */
1006 usbat_pack_atapi_sector_cmd(command, thistime, sector, 0x20); 1026 usbat_pack_ata_sector_cmd(command, thistime, sector, 0x20);
1007 1027
1008 // Write/execute ATAPI read command 1028 /* Write/execute ATA read command */
1009 result = usbat_multiple_write(us, registers, command, 7); 1029 result = usbat_multiple_write(us, registers, command, 7);
1010 if (result != USB_STOR_TRANSPORT_GOOD) 1030 if (result != USB_STOR_TRANSPORT_GOOD)
1011 goto leave; 1031 goto leave;
1012 1032
1013 // Read the data we just requested 1033 /* Read the data we just requested */
1014 result = usbat_read_blocks(us, buffer, len); 1034 result = usbat_read_blocks(us, buffer, len);
1015 if (result != USB_STOR_TRANSPORT_GOOD) 1035 if (result != USB_STOR_TRANSPORT_GOOD)
1016 goto leave; 1036 goto leave;
1017 1037
1018 US_DEBUGP("usbat_flash_read_data: %d bytes\n", len); 1038 US_DEBUGP("usbat_flash_read_data: %d bytes\n", len);
1019 1039
1020 // Store the data in the transfer buffer 1040 /* Store the data in the transfer buffer */
1021 usb_stor_access_xfer_buf(buffer, len, us->srb, 1041 usb_stor_access_xfer_buf(buffer, len, us->srb,
1022 &sg_idx, &sg_offset, TO_XFER_BUF); 1042 &sg_idx, &sg_offset, TO_XFER_BUF);
1023 1043
@@ -1061,19 +1081,23 @@ static int usbat_flash_write_data(struct us_data *us,
1061 if (result != USB_STOR_TRANSPORT_GOOD) 1081 if (result != USB_STOR_TRANSPORT_GOOD)
1062 return result; 1082 return result;
1063 1083
1064 // we're working in LBA mode. according to the ATA spec, 1084 /*
1065 // we can support up to 28-bit addressing. I don't know if Jumpshot 1085 * we're working in LBA mode. according to the ATA spec,
1066 // supports beyond 24-bit addressing. It's kind of hard to test 1086 * we can support up to 28-bit addressing. I don't know if the device
1067 // since it requires > 8GB CF card. 1087 * supports beyond 24-bit addressing. It's kind of hard to test
1088 * since it requires > 8GB media.
1089 */
1068 1090
1069 if (sector > 0x0FFFFFFF) 1091 if (sector > 0x0FFFFFFF)
1070 return USB_STOR_TRANSPORT_ERROR; 1092 return USB_STOR_TRANSPORT_ERROR;
1071 1093
1072 totallen = sectors * info->ssize; 1094 totallen = sectors * info->ssize;
1073 1095
1074 // Since we don't write more than 64 KB at a time, we have to create 1096 /*
1075 // a bounce buffer and move the data a piece at a time between the 1097 * Since we don't write more than 64 KB at a time, we have to create
1076 // bounce buffer and the actual transfer buffer. 1098 * a bounce buffer and move the data a piece at a time between the
1099 * bounce buffer and the actual transfer buffer.
1100 */
1077 1101
1078 alloclen = min(totallen, 65536u); 1102 alloclen = min(totallen, 65536u);
1079 buffer = kmalloc(alloclen, GFP_NOIO); 1103 buffer = kmalloc(alloclen, GFP_NOIO);
@@ -1081,24 +1105,26 @@ static int usbat_flash_write_data(struct us_data *us,
1081 return USB_STOR_TRANSPORT_ERROR; 1105 return USB_STOR_TRANSPORT_ERROR;
1082 1106
1083 do { 1107 do {
1084 // loop, never allocate or transfer more than 64k at once 1108 /*
1085 // (min(128k, 255*info->ssize) is the real limit) 1109 * loop, never allocate or transfer more than 64k at once
1110 * (min(128k, 255*info->ssize) is the real limit)
1111 */
1086 len = min(totallen, alloclen); 1112 len = min(totallen, alloclen);
1087 thistime = (len / info->ssize) & 0xff; 1113 thistime = (len / info->ssize) & 0xff;
1088 1114
1089 // Get the data from the transfer buffer 1115 /* Get the data from the transfer buffer */
1090 usb_stor_access_xfer_buf(buffer, len, us->srb, 1116 usb_stor_access_xfer_buf(buffer, len, us->srb,
1091 &sg_idx, &sg_offset, FROM_XFER_BUF); 1117 &sg_idx, &sg_offset, FROM_XFER_BUF);
1092 1118
1093 // ATAPI command 0x30 (WRITE SECTORS) 1119 /* ATA command 0x30 (WRITE SECTORS) */
1094 usbat_pack_atapi_sector_cmd(command, thistime, sector, 0x30); 1120 usbat_pack_ata_sector_cmd(command, thistime, sector, 0x30);
1095 1121
1096 // Write/execute ATAPI write command 1122 /* Write/execute ATA write command */
1097 result = usbat_multiple_write(us, registers, command, 7); 1123 result = usbat_multiple_write(us, registers, command, 7);
1098 if (result != USB_STOR_TRANSPORT_GOOD) 1124 if (result != USB_STOR_TRANSPORT_GOOD)
1099 goto leave; 1125 goto leave;
1100 1126
1101 // Write the data 1127 /* Write the data */
1102 result = usbat_write_blocks(us, buffer, len); 1128 result = usbat_write_blocks(us, buffer, len);
1103 if (result != USB_STOR_TRANSPORT_GOOD) 1129 if (result != USB_STOR_TRANSPORT_GOOD)
1104 goto leave; 1130 goto leave;
@@ -1169,42 +1195,44 @@ static int usbat_hp8200e_handle_read10(struct us_data *us,
1169 srb->transfersize); 1195 srb->transfersize);
1170 } 1196 }
1171 1197
1172 // Since we only read in one block at a time, we have to create 1198 /*
1173 // a bounce buffer and move the data a piece at a time between the 1199 * Since we only read in one block at a time, we have to create
1174 // bounce buffer and the actual transfer buffer. 1200 * a bounce buffer and move the data a piece at a time between the
1201 * bounce buffer and the actual transfer buffer.
1202 */
1175 1203
1176 len = (65535/srb->transfersize) * srb->transfersize; 1204 len = (65535/srb->transfersize) * srb->transfersize;
1177 US_DEBUGP("Max read is %d bytes\n", len); 1205 US_DEBUGP("Max read is %d bytes\n", len);
1178 len = min(len, srb->request_bufflen); 1206 len = min(len, srb->request_bufflen);
1179 buffer = kmalloc(len, GFP_NOIO); 1207 buffer = kmalloc(len, GFP_NOIO);
1180 if (buffer == NULL) // bloody hell! 1208 if (buffer == NULL) /* bloody hell! */
1181 return USB_STOR_TRANSPORT_FAILED; 1209 return USB_STOR_TRANSPORT_FAILED;
1182 sector = short_pack(data[7+3], data[7+2]); 1210 sector = short_pack(data[7+3], data[7+2]);
1183 sector <<= 16; 1211 sector <<= 16;
1184 sector |= short_pack(data[7+5], data[7+4]); 1212 sector |= short_pack(data[7+5], data[7+4]);
1185 transferred = 0; 1213 transferred = 0;
1186 1214
1187 sg_segment = 0; // for keeping track of where we are in 1215 sg_segment = 0; /* for keeping track of where we are in */
1188 sg_offset = 0; // the scatter/gather list 1216 sg_offset = 0; /* the scatter/gather list */
1189 1217
1190 while (transferred != srb->request_bufflen) { 1218 while (transferred != srb->request_bufflen) {
1191 1219
1192 if (len > srb->request_bufflen - transferred) 1220 if (len > srb->request_bufflen - transferred)
1193 len = srb->request_bufflen - transferred; 1221 len = srb->request_bufflen - transferred;
1194 1222
1195 data[3] = len&0xFF; // (cylL) = expected length (L) 1223 data[3] = len&0xFF; /* (cylL) = expected length (L) */
1196 data[4] = (len>>8)&0xFF; // (cylH) = expected length (H) 1224 data[4] = (len>>8)&0xFF; /* (cylH) = expected length (H) */
1197 1225
1198 // Fix up the SCSI command sector and num sectors 1226 /* Fix up the SCSI command sector and num sectors */
1199 1227
1200 data[7+2] = MSB_of(sector>>16); // SCSI command sector 1228 data[7+2] = MSB_of(sector>>16); /* SCSI command sector */
1201 data[7+3] = LSB_of(sector>>16); 1229 data[7+3] = LSB_of(sector>>16);
1202 data[7+4] = MSB_of(sector&0xFFFF); 1230 data[7+4] = MSB_of(sector&0xFFFF);
1203 data[7+5] = LSB_of(sector&0xFFFF); 1231 data[7+5] = LSB_of(sector&0xFFFF);
1204 if (data[7+0] == GPCMD_READ_CD) 1232 if (data[7+0] == GPCMD_READ_CD)
1205 data[7+6] = 0; 1233 data[7+6] = 0;
1206 data[7+7] = MSB_of(len / srb->transfersize); // SCSI command 1234 data[7+7] = MSB_of(len / srb->transfersize); /* SCSI command */
1207 data[7+8] = LSB_of(len / srb->transfersize); // num sectors 1235 data[7+8] = LSB_of(len / srb->transfersize); /* num sectors */
1208 1236
1209 result = usbat_hp8200e_rw_block_test(us, USBAT_ATA, 1237 result = usbat_hp8200e_rw_block_test(us, USBAT_ATA,
1210 registers, data, 19, 1238 registers, data, 19,
@@ -1217,16 +1245,16 @@ static int usbat_hp8200e_handle_read10(struct us_data *us,
1217 if (result != USB_STOR_TRANSPORT_GOOD) 1245 if (result != USB_STOR_TRANSPORT_GOOD)
1218 break; 1246 break;
1219 1247
1220 // Store the data in the transfer buffer 1248 /* Store the data in the transfer buffer */
1221 usb_stor_access_xfer_buf(buffer, len, srb, 1249 usb_stor_access_xfer_buf(buffer, len, srb,
1222 &sg_segment, &sg_offset, TO_XFER_BUF); 1250 &sg_segment, &sg_offset, TO_XFER_BUF);
1223 1251
1224 // Update the amount transferred and the sector number 1252 /* Update the amount transferred and the sector number */
1225 1253
1226 transferred += len; 1254 transferred += len;
1227 sector += len / srb->transfersize; 1255 sector += len / srb->transfersize;
1228 1256
1229 } // while transferred != srb->request_bufflen 1257 } /* while transferred != srb->request_bufflen */
1230 1258
1231 kfree(buffer); 1259 kfree(buffer);
1232 return result; 1260 return result;
@@ -1237,7 +1265,7 @@ static int usbat_select_and_test_registers(struct us_data *us)
1237 int selector; 1265 int selector;
1238 unsigned char *status = us->iobuf; 1266 unsigned char *status = us->iobuf;
1239 1267
1240 // try device = master, then device = slave. 1268 /* try device = master, then device = slave. */
1241 for (selector = 0xA0; selector <= 0xB0; selector += 0x10) { 1269 for (selector = 0xA0; selector <= 0xB0; selector += 0x10) {
1242 if (usbat_write(us, USBAT_ATA, USBAT_ATA_DEVICE, selector) != 1270 if (usbat_write(us, USBAT_ATA, USBAT_ATA_DEVICE, selector) !=
1243 USB_STOR_XFER_GOOD) 1271 USB_STOR_XFER_GOOD)
@@ -1298,7 +1326,7 @@ int init_usbat(struct us_data *us)
1298 memset(us->extra, 0, sizeof(struct usbat_info)); 1326 memset(us->extra, 0, sizeof(struct usbat_info));
1299 info = (struct usbat_info *) (us->extra); 1327 info = (struct usbat_info *) (us->extra);
1300 1328
1301 // Enable peripheral control signals 1329 /* Enable peripheral control signals */
1302 rc = usbat_write_user_io(us, 1330 rc = usbat_write_user_io(us,
1303 USBAT_UIO_OE1 | USBAT_UIO_OE0, 1331 USBAT_UIO_OE1 | USBAT_UIO_OE0,
1304 USBAT_UIO_EPAD | USBAT_UIO_1); 1332 USBAT_UIO_EPAD | USBAT_UIO_1);
@@ -1337,7 +1365,7 @@ int init_usbat(struct us_data *us)
1337 1365
1338 US_DEBUGP("INIT 5\n"); 1366 US_DEBUGP("INIT 5\n");
1339 1367
1340 // Enable peripheral control signals and card detect 1368 /* Enable peripheral control signals and card detect */
1341 rc = usbat_device_enable_cdt(us); 1369 rc = usbat_device_enable_cdt(us);
1342 if (rc != USB_STOR_TRANSPORT_GOOD) 1370 if (rc != USB_STOR_TRANSPORT_GOOD)
1343 return rc; 1371 return rc;
@@ -1364,7 +1392,7 @@ int init_usbat(struct us_data *us)
1364 1392
1365 US_DEBUGP("INIT 9\n"); 1393 US_DEBUGP("INIT 9\n");
1366 1394
1367 // At this point, we need to detect which device we are using 1395 /* At this point, we need to detect which device we are using */
1368 if (usbat_set_transport(us, info)) 1396 if (usbat_set_transport(us, info))
1369 return USB_STOR_TRANSPORT_ERROR; 1397 return USB_STOR_TRANSPORT_ERROR;
1370 1398
@@ -1414,10 +1442,10 @@ static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us)
1414 data[0] = 0x00; 1442 data[0] = 0x00;
1415 data[1] = 0x00; 1443 data[1] = 0x00;
1416 data[2] = 0x00; 1444 data[2] = 0x00;
1417 data[3] = len&0xFF; // (cylL) = expected length (L) 1445 data[3] = len&0xFF; /* (cylL) = expected length (L) */
1418 data[4] = (len>>8)&0xFF; // (cylH) = expected length (H) 1446 data[4] = (len>>8)&0xFF; /* (cylH) = expected length (H) */
1419 data[5] = 0xB0; // (device sel) = slave 1447 data[5] = 0xB0; /* (device sel) = slave */
1420 data[6] = 0xA0; // (command) = ATA PACKET COMMAND 1448 data[6] = 0xA0; /* (command) = ATA PACKET COMMAND */
1421 1449
1422 for (i=7; i<19; i++) { 1450 for (i=7; i<19; i++) {
1423 registers[i] = 0x10; 1451 registers[i] = 0x10;
@@ -1466,13 +1494,15 @@ static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us)
1466 return result; 1494 return result;
1467 } 1495 }
1468 1496
1469 // Write the 12-byte command header. 1497 /*
1470 1498 * Write the 12-byte command header.
1471 // If the command is BLANK then set the timer for 75 minutes. 1499 *
1472 // Otherwise set it for 10 minutes. 1500 * If the command is BLANK then set the timer for 75 minutes.
1473 1501 * Otherwise set it for 10 minutes.
1474 // NOTE: THE 8200 DOCUMENTATION STATES THAT BLANKING A CDRW 1502 *
1475 // AT SPEED 4 IS UNRELIABLE!!! 1503 * NOTE: THE 8200 DOCUMENTATION STATES THAT BLANKING A CDRW
1504 * AT SPEED 4 IS UNRELIABLE!!!
1505 */
1476 1506
1477 if ( (result = usbat_write_block(us, 1507 if ( (result = usbat_write_block(us,
1478 USBAT_ATA, srb->cmnd, 12, 1508 USBAT_ATA, srb->cmnd, 12,
@@ -1481,19 +1511,18 @@ static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us)
1481 return result; 1511 return result;
1482 } 1512 }
1483 1513
1484 // If there is response data to be read in 1514 /* If there is response data to be read in then do it here. */
1485 // then do it here.
1486 1515
1487 if (len != 0 && (srb->sc_data_direction == DMA_FROM_DEVICE)) { 1516 if (len != 0 && (srb->sc_data_direction == DMA_FROM_DEVICE)) {
1488 1517
1489 // How many bytes to read in? Check cylL register 1518 /* How many bytes to read in? Check cylL register */
1490 1519
1491 if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_ME, status) != 1520 if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_ME, status) !=
1492 USB_STOR_XFER_GOOD) { 1521 USB_STOR_XFER_GOOD) {
1493 return USB_STOR_TRANSPORT_ERROR; 1522 return USB_STOR_TRANSPORT_ERROR;
1494 } 1523 }
1495 1524
1496 if (len > 0xFF) { // need to read cylH also 1525 if (len > 0xFF) { /* need to read cylH also */
1497 len = *status; 1526 len = *status;
1498 if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_HI, status) != 1527 if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_HI, status) !=
1499 USB_STOR_XFER_GOOD) { 1528 USB_STOR_XFER_GOOD) {
@@ -1556,13 +1585,16 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
1556 if (rc != USB_STOR_TRANSPORT_GOOD) 1585 if (rc != USB_STOR_TRANSPORT_GOOD)
1557 return rc; 1586 return rc;
1558 1587
1559 info->ssize = 0x200; // hard coded 512 byte sectors as per ATA spec 1588 /* hard coded 512 byte sectors as per ATA spec */
1589 info->ssize = 0x200;
1560 US_DEBUGP("usbat_flash_transport: READ_CAPACITY: %ld sectors, %ld bytes per sector\n", 1590 US_DEBUGP("usbat_flash_transport: READ_CAPACITY: %ld sectors, %ld bytes per sector\n",
1561 info->sectors, info->ssize); 1591 info->sectors, info->ssize);
1562 1592
1563 // build the reply 1593 /*
1564 // note: must return the sector number of the last sector, 1594 * build the reply
1565 // *not* the total number of sectors 1595 * note: must return the sector number of the last sector,
1596 * *not* the total number of sectors
1597 */
1566 ((__be32 *) ptr)[0] = cpu_to_be32(info->sectors - 1); 1598 ((__be32 *) ptr)[0] = cpu_to_be32(info->sectors - 1);
1567 ((__be32 *) ptr)[1] = cpu_to_be32(info->ssize); 1599 ((__be32 *) ptr)[1] = cpu_to_be32(info->ssize);
1568 usb_stor_set_xfer_buf(ptr, 8, srb); 1600 usb_stor_set_xfer_buf(ptr, 8, srb);
@@ -1586,7 +1618,9 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
1586 } 1618 }
1587 1619
1588 if (srb->cmnd[0] == READ_12) { 1620 if (srb->cmnd[0] == READ_12) {
1589 // I don't think we'll ever see a READ_12 but support it anyway... 1621 /*
1622 * I don't think we'll ever see a READ_12 but support it anyway
1623 */
1590 block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) | 1624 block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) |
1591 ((u32)(srb->cmnd[4]) << 8) | ((u32)(srb->cmnd[5])); 1625 ((u32)(srb->cmnd[4]) << 8) | ((u32)(srb->cmnd[5]));
1592 1626
@@ -1608,7 +1642,9 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
1608 } 1642 }
1609 1643
1610 if (srb->cmnd[0] == WRITE_12) { 1644 if (srb->cmnd[0] == WRITE_12) {
1611 // I don't think we'll ever see a WRITE_12 but support it anyway... 1645 /*
1646 * I don't think we'll ever see a WRITE_12 but support it anyway
1647 */
1612 block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) | 1648 block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) |
1613 ((u32)(srb->cmnd[4]) << 8) | ((u32)(srb->cmnd[5])); 1649 ((u32)(srb->cmnd[4]) << 8) | ((u32)(srb->cmnd[5]));
1614 1650
@@ -1645,8 +1681,10 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
1645 } 1681 }
1646 1682
1647 if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) { 1683 if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
1648 // sure. whatever. not like we can stop the user from popping 1684 /*
1649 // the media out of the device (no locking doors, etc) 1685 * sure. whatever. not like we can stop the user from popping
1686 * the media out of the device (no locking doors, etc)
1687 */
1650 return USB_STOR_TRANSPORT_GOOD; 1688 return USB_STOR_TRANSPORT_GOOD;
1651 } 1689 }
1652 1690
diff --git a/drivers/usb/storage/shuttle_usbat.h b/drivers/usb/storage/shuttle_usbat.h
index 5b8e867e2ae5..25e7d8b340b8 100644
--- a/drivers/usb/storage/shuttle_usbat.h
+++ b/drivers/usb/storage/shuttle_usbat.h
@@ -55,8 +55,8 @@
55#define USBAT_UIO_WRITE 0 55#define USBAT_UIO_WRITE 0
56 56
57/* Qualifier bits */ 57/* Qualifier bits */
58#define USBAT_QUAL_FCQ 0x20 // full compare 58#define USBAT_QUAL_FCQ 0x20 /* full compare */
59#define USBAT_QUAL_ALQ 0x10 // auto load subcount 59#define USBAT_QUAL_ALQ 0x10 /* auto load subcount */
60 60
61/* USBAT Flash Media status types */ 61/* USBAT Flash Media status types */
62#define USBAT_FLASH_MEDIA_NONE 0 62#define USBAT_FLASH_MEDIA_NONE 0
@@ -67,39 +67,39 @@
67#define USBAT_FLASH_MEDIA_CHANGED 1 67#define USBAT_FLASH_MEDIA_CHANGED 1
68 68
69/* USBAT ATA registers */ 69/* USBAT ATA registers */
70#define USBAT_ATA_DATA 0x10 // read/write data (R/W) 70#define USBAT_ATA_DATA 0x10 /* read/write data (R/W) */
71#define USBAT_ATA_FEATURES 0x11 // set features (W) 71#define USBAT_ATA_FEATURES 0x11 /* set features (W) */
72#define USBAT_ATA_ERROR 0x11 // error (R) 72#define USBAT_ATA_ERROR 0x11 /* error (R) */
73#define USBAT_ATA_SECCNT 0x12 // sector count (R/W) 73#define USBAT_ATA_SECCNT 0x12 /* sector count (R/W) */
74#define USBAT_ATA_SECNUM 0x13 // sector number (R/W) 74#define USBAT_ATA_SECNUM 0x13 /* sector number (R/W) */
75#define USBAT_ATA_LBA_ME 0x14 // cylinder low (R/W) 75#define USBAT_ATA_LBA_ME 0x14 /* cylinder low (R/W) */
76#define USBAT_ATA_LBA_HI 0x15 // cylinder high (R/W) 76#define USBAT_ATA_LBA_HI 0x15 /* cylinder high (R/W) */
77#define USBAT_ATA_DEVICE 0x16 // head/device selection (R/W) 77#define USBAT_ATA_DEVICE 0x16 /* head/device selection (R/W) */
78#define USBAT_ATA_STATUS 0x17 // device status (R) 78#define USBAT_ATA_STATUS 0x17 /* device status (R) */
79#define USBAT_ATA_CMD 0x17 // device command (W) 79#define USBAT_ATA_CMD 0x17 /* device command (W) */
80#define USBAT_ATA_ALTSTATUS 0x0E // status (no clear IRQ) (R) 80#define USBAT_ATA_ALTSTATUS 0x0E /* status (no clear IRQ) (R) */
81 81
82/* USBAT User I/O Data registers */ 82/* USBAT User I/O Data registers */
83#define USBAT_UIO_EPAD 0x80 // Enable Peripheral Control Signals 83#define USBAT_UIO_EPAD 0x80 /* Enable Peripheral Control Signals */
84#define USBAT_UIO_CDT 0x40 // Card Detect (Read Only) 84#define USBAT_UIO_CDT 0x40 /* Card Detect (Read Only) */
85 // CDT = ACKD & !UI1 & !UI0 85 /* CDT = ACKD & !UI1 & !UI0 */
86#define USBAT_UIO_1 0x20 // I/O 1 86#define USBAT_UIO_1 0x20 /* I/O 1 */
87#define USBAT_UIO_0 0x10 // I/O 0 87#define USBAT_UIO_0 0x10 /* I/O 0 */
88#define USBAT_UIO_EPP_ATA 0x08 // 1=EPP mode, 0=ATA mode 88#define USBAT_UIO_EPP_ATA 0x08 /* 1=EPP mode, 0=ATA mode */
89#define USBAT_UIO_UI1 0x04 // Input 1 89#define USBAT_UIO_UI1 0x04 /* Input 1 */
90#define USBAT_UIO_UI0 0x02 // Input 0 90#define USBAT_UIO_UI0 0x02 /* Input 0 */
91#define USBAT_UIO_INTR_ACK 0x01 // Interrupt (ATA & ISA)/Acknowledge (EPP) 91#define USBAT_UIO_INTR_ACK 0x01 /* Interrupt (ATA/ISA)/Acknowledge (EPP) */
92 92
93/* USBAT User I/O Enable registers */ 93/* USBAT User I/O Enable registers */
94#define USBAT_UIO_DRVRST 0x80 // Reset Peripheral 94#define USBAT_UIO_DRVRST 0x80 /* Reset Peripheral */
95#define USBAT_UIO_ACKD 0x40 // Enable Card Detect 95#define USBAT_UIO_ACKD 0x40 /* Enable Card Detect */
96#define USBAT_UIO_OE1 0x20 // I/O 1 set=output/clr=input 96#define USBAT_UIO_OE1 0x20 /* I/O 1 set=output/clr=input */
97 // If ACKD=1, set OE1 to 1 also. 97 /* If ACKD=1, set OE1 to 1 also. */
98#define USBAT_UIO_OE0 0x10 // I/O 0 set=output/clr=input 98#define USBAT_UIO_OE0 0x10 /* I/O 0 set=output/clr=input */
99#define USBAT_UIO_ADPRST 0x01 // Reset SCM chip 99#define USBAT_UIO_ADPRST 0x01 /* Reset SCM chip */
100 100
101/* USBAT Features */ 101/* USBAT Features */
102#define USBAT_FEAT_ETEN 0x80 // External trigger enable 102#define USBAT_FEAT_ETEN 0x80 /* External trigger enable */
103#define USBAT_FEAT_U1 0x08 103#define USBAT_FEAT_U1 0x08
104#define USBAT_FEAT_U0 0x04 104#define USBAT_FEAT_U0 0x04
105#define USBAT_FEAT_ET1 0x02 105#define USBAT_FEAT_ET1 0x02
@@ -112,12 +112,12 @@ struct usbat_info {
112 int devicetype; 112 int devicetype;
113 113
114 /* Used for Flash readers only */ 114 /* Used for Flash readers only */
115 unsigned long sectors; // total sector count 115 unsigned long sectors; /* total sector count */
116 unsigned long ssize; // sector size in bytes 116 unsigned long ssize; /* sector size in bytes */
117 117
118 unsigned char sense_key; 118 unsigned char sense_key;
119 unsigned long sense_asc; // additional sense code 119 unsigned long sense_asc; /* additional sense code */
120 unsigned long sense_ascq; // additional sense code qualifier 120 unsigned long sense_ascq; /* additional sense code qualifier */
121}; 121};
122 122
123#endif 123#endif
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index c1ba5301ebfc..7ca896a342e3 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -636,11 +636,11 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
636 636
637 /* use the new buffer we have */ 637 /* use the new buffer we have */
638 old_request_buffer = srb->request_buffer; 638 old_request_buffer = srb->request_buffer;
639 srb->request_buffer = srb->sense_buffer; 639 srb->request_buffer = us->sensebuf;
640 640
641 /* set the buffer length for transfer */ 641 /* set the buffer length for transfer */
642 old_request_bufflen = srb->request_bufflen; 642 old_request_bufflen = srb->request_bufflen;
643 srb->request_bufflen = 18; 643 srb->request_bufflen = US_SENSE_SIZE;
644 644
645 /* set up for no scatter-gather use */ 645 /* set up for no scatter-gather use */
646 old_sg = srb->use_sg; 646 old_sg = srb->use_sg;
@@ -652,6 +652,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
652 temp_result = us->transport(us->srb, us); 652 temp_result = us->transport(us->srb, us);
653 653
654 /* let's clean up right away */ 654 /* let's clean up right away */
655 memcpy(srb->sense_buffer, us->sensebuf, US_SENSE_SIZE);
655 srb->resid = old_resid; 656 srb->resid = old_resid;
656 srb->request_buffer = old_request_buffer; 657 srb->request_buffer = old_request_buffer;
657 srb->request_bufflen = old_request_bufflen; 658 srb->request_bufflen = old_request_bufflen;
@@ -923,6 +924,7 @@ int usb_stor_Bulk_max_lun(struct us_data *us)
923 int result; 924 int result;
924 925
925 /* issue the command */ 926 /* issue the command */
927 us->iobuf[0] = 0;
926 result = usb_stor_control_msg(us, us->recv_ctrl_pipe, 928 result = usb_stor_control_msg(us, us->recv_ctrl_pipe,
927 US_BULK_GET_MAX_LUN, 929 US_BULK_GET_MAX_LUN,
928 USB_DIR_IN | USB_TYPE_CLASS | 930 USB_DIR_IN | USB_TYPE_CLASS |
diff --git a/drivers/usb/storage/transport.h b/drivers/usb/storage/transport.h
index 8d9e0663f8fe..0a362cc781ad 100644
--- a/drivers/usb/storage/transport.h
+++ b/drivers/usb/storage/transport.h
@@ -50,7 +50,7 @@
50#define US_PR_CB 0x01 /* Control/Bulk w/o interrupt */ 50#define US_PR_CB 0x01 /* Control/Bulk w/o interrupt */
51#define US_PR_BULK 0x50 /* bulk only */ 51#define US_PR_BULK 0x50 /* bulk only */
52#ifdef CONFIG_USB_STORAGE_USBAT 52#ifdef CONFIG_USB_STORAGE_USBAT
53#define US_PR_SCM_ATAPI 0x80 /* SCM-ATAPI bridge */ 53#define US_PR_USBAT 0x80 /* SCM-ATAPI bridge */
54#endif 54#endif
55#ifdef CONFIG_USB_STORAGE_SDDR09 55#ifdef CONFIG_USB_STORAGE_SDDR09
56#define US_PR_EUSB_SDDR09 0x81 /* SCM-SCSI bridge for SDDR-09 */ 56#define US_PR_EUSB_SDDR09 0x81 /* SCM-SCSI bridge for SDDR-09 */
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index b79dad1b598c..9e926a8f2116 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -71,12 +71,12 @@ UNUSUAL_DEV( 0x03f0, 0x0107, 0x0200, 0x0200,
71UNUSUAL_DEV( 0x03f0, 0x0207, 0x0001, 0x0001, 71UNUSUAL_DEV( 0x03f0, 0x0207, 0x0001, 0x0001,
72 "HP", 72 "HP",
73 "CD-Writer+ 8200e", 73 "CD-Writer+ 8200e",
74 US_SC_8070, US_PR_SCM_ATAPI, init_usbat, 0), 74 US_SC_8070, US_PR_USBAT, init_usbat, 0),
75 75
76UNUSUAL_DEV( 0x03f0, 0x0307, 0x0001, 0x0001, 76UNUSUAL_DEV( 0x03f0, 0x0307, 0x0001, 0x0001,
77 "HP", 77 "HP",
78 "CD-Writer+ CD-4e", 78 "CD-Writer+ CD-4e",
79 US_SC_8070, US_PR_SCM_ATAPI, init_usbat, 0), 79 US_SC_8070, US_PR_USBAT, init_usbat, 0),
80#endif 80#endif
81 81
82/* Patch submitted by Mihnea-Costin Grigore <mihnea@zulu.ro> */ 82/* Patch submitted by Mihnea-Costin Grigore <mihnea@zulu.ro> */
@@ -106,6 +106,13 @@ UNUSUAL_DEV( 0x0411, 0x001c, 0x0113, 0x0113,
106 US_SC_DEVICE, US_PR_DEVICE, NULL, 106 US_SC_DEVICE, US_PR_DEVICE, NULL,
107 US_FL_FIX_INQUIRY ), 107 US_FL_FIX_INQUIRY ),
108 108
109/* Reported by Stefan Werner <dustbln@gmx.de> */
110UNUSUAL_DEV( 0x0419, 0xaaf6, 0x0100, 0x0100,
111 "TrekStor",
112 "i.Beat Joy 2.0",
113 US_SC_DEVICE, US_PR_DEVICE, NULL,
114 US_FL_IGNORE_RESIDUE ),
115
109/* Reported by Olaf Hering <olh@suse.de> from novell bug #105878 */ 116/* Reported by Olaf Hering <olh@suse.de> from novell bug #105878 */
110UNUSUAL_DEV( 0x0424, 0x0fdc, 0x0210, 0x0210, 117UNUSUAL_DEV( 0x0424, 0x0fdc, 0x0210, 0x0210,
111 "SMSC", 118 "SMSC",
@@ -244,6 +251,13 @@ UNUSUAL_DEV( 0x04da, 0x2372, 0x0000, 0x9999,
244 US_SC_DEVICE, US_PR_DEVICE, NULL, 251 US_SC_DEVICE, US_PR_DEVICE, NULL,
245 US_FL_FIX_CAPACITY | US_FL_NOT_LOCKABLE ), 252 US_FL_FIX_CAPACITY | US_FL_NOT_LOCKABLE ),
246 253
254/* Reported by Simeon Simeonov <simeonov_2000@yahoo.com> */
255UNUSUAL_DEV( 0x04da, 0x2373, 0x0000, 0x9999,
256 "LEICA",
257 "D-LUX Camera",
258 US_SC_DEVICE, US_PR_DEVICE, NULL,
259 US_FL_FIX_CAPACITY | US_FL_NOT_LOCKABLE ),
260
247/* Most of the following entries were developed with the help of 261/* Most of the following entries were developed with the help of
248 * Shuttle/SCM directly. 262 * Shuttle/SCM directly.
249 */ 263 */
@@ -333,9 +347,9 @@ UNUSUAL_DEV( 0x04fc, 0x80c2, 0x0100, 0x0100,
333 347
334#ifdef CONFIG_USB_STORAGE_USBAT 348#ifdef CONFIG_USB_STORAGE_USBAT
335UNUSUAL_DEV( 0x04e6, 0x1010, 0x0000, 0x9999, 349UNUSUAL_DEV( 0x04e6, 0x1010, 0x0000, 0x9999,
336 "SCM", 350 "Shuttle/SCM",
337 "SCM USBAT-02", 351 "USBAT-02",
338 US_SC_SCSI, US_PR_SCM_ATAPI, init_usbat, 352 US_SC_SCSI, US_PR_USBAT, init_usbat,
339 US_FL_SINGLE_LUN), 353 US_FL_SINGLE_LUN),
340#endif 354#endif
341 355
@@ -598,6 +612,16 @@ UNUSUAL_DEV( 0x05ac, 0x1205, 0x0000, 0x9999,
598 US_SC_DEVICE, US_PR_DEVICE, NULL, 612 US_SC_DEVICE, US_PR_DEVICE, NULL,
599 US_FL_FIX_CAPACITY ), 613 US_FL_FIX_CAPACITY ),
600 614
615/*
616 * Reported by Tyson Vinson <lornoss@gmail.com>
617 * This particular productId is the iPod Nano
618 */
619UNUSUAL_DEV( 0x05ac, 0x120a, 0x0000, 0x9999,
620 "Apple",
621 "iPod",
622 US_SC_DEVICE, US_PR_DEVICE, NULL,
623 US_FL_FIX_CAPACITY ),
624
601#ifdef CONFIG_USB_STORAGE_JUMPSHOT 625#ifdef CONFIG_USB_STORAGE_JUMPSHOT
602UNUSUAL_DEV( 0x05dc, 0x0001, 0x0000, 0x0001, 626UNUSUAL_DEV( 0x05dc, 0x0001, 0x0000, 0x0001,
603 "Lexar", 627 "Lexar",
@@ -702,6 +726,14 @@ UNUSUAL_DEV( 0x0781, 0x0001, 0x0200, 0x0200,
702 US_SC_SCSI, US_PR_CB, NULL, 726 US_SC_SCSI, US_PR_CB, NULL,
703 US_FL_SINGLE_LUN ), 727 US_FL_SINGLE_LUN ),
704 728
729#ifdef CONFIG_USB_STORAGE_USBAT
730UNUSUAL_DEV( 0x0781, 0x0005, 0x0005, 0x0005,
731 "Sandisk",
732 "ImageMate SDDR-05b",
733 US_SC_SCSI, US_PR_USBAT, init_usbat,
734 US_FL_SINGLE_LUN ),
735#endif
736
705UNUSUAL_DEV( 0x0781, 0x0100, 0x0100, 0x0100, 737UNUSUAL_DEV( 0x0781, 0x0100, 0x0100, 0x0100,
706 "Sandisk", 738 "Sandisk",
707 "ImageMate SDDR-12", 739 "ImageMate SDDR-12",
@@ -724,7 +756,7 @@ UNUSUAL_DEV( 0x07ab, 0xfc01, 0x0000, 0x9999,
724#endif 756#endif
725 757
726/* Reported by Eero Volotinen <eero@ping-viini.org> */ 758/* Reported by Eero Volotinen <eero@ping-viini.org> */
727UNUSUAL_DEV( 0x07ab, 0xfccd, 0x0406, 0x0406, 759UNUSUAL_DEV( 0x07ab, 0xfccd, 0x0000, 0x9999,
728 "Freecom Technologies", 760 "Freecom Technologies",
729 "FHD-Classic", 761 "FHD-Classic",
730 US_SC_DEVICE, US_PR_DEVICE, NULL, 762 US_SC_DEVICE, US_PR_DEVICE, NULL,
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index f9a9bfa1aef5..3847ebed2aa4 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -54,6 +54,7 @@
54#include <linux/module.h> 54#include <linux/module.h>
55#include <linux/init.h> 55#include <linux/init.h>
56#include <linux/slab.h> 56#include <linux/slab.h>
57#include <linux/kthread.h>
57 58
58#include <scsi/scsi.h> 59#include <scsi/scsi.h>
59#include <scsi/scsi_cmnd.h> 60#include <scsi/scsi_cmnd.h>
@@ -111,11 +112,6 @@ static atomic_t total_threads = ATOMIC_INIT(0);
111static DECLARE_COMPLETION(threads_gone); 112static DECLARE_COMPLETION(threads_gone);
112 113
113 114
114static int storage_probe(struct usb_interface *iface,
115 const struct usb_device_id *id);
116
117static void storage_disconnect(struct usb_interface *iface);
118
119/* The entries in this table, except for final ones here 115/* The entries in this table, except for final ones here
120 * (USB_MASS_STORAGE_CLASS and the empty entry), correspond, 116 * (USB_MASS_STORAGE_CLASS and the empty entry), correspond,
121 * line for line with the entries of us_unsuaul_dev_list[]. 117 * line for line with the entries of us_unsuaul_dev_list[].
@@ -233,13 +229,40 @@ static struct us_unusual_dev us_unusual_dev_list[] = {
233 { NULL } 229 { NULL }
234}; 230};
235 231
236static struct usb_driver usb_storage_driver = { 232
237 .owner = THIS_MODULE, 233#ifdef CONFIG_PM /* Minimal support for suspend and resume */
238 .name = "usb-storage", 234
239 .probe = storage_probe, 235static int storage_suspend(struct usb_interface *iface, pm_message_t message)
240 .disconnect = storage_disconnect, 236{
241 .id_table = storage_usb_ids, 237 struct us_data *us = usb_get_intfdata(iface);
242}; 238
239 /* Wait until no command is running */
240 down(&us->dev_semaphore);
241
242 US_DEBUGP("%s\n", __FUNCTION__);
243 iface->dev.power.power_state.event = message.event;
244
245 /* When runtime PM is working, we'll set a flag to indicate
246 * whether we should autoresume when a SCSI request arrives. */
247
248 up(&us->dev_semaphore);
249 return 0;
250}
251
252static int storage_resume(struct usb_interface *iface)
253{
254 struct us_data *us = usb_get_intfdata(iface);
255
256 down(&us->dev_semaphore);
257
258 US_DEBUGP("%s\n", __FUNCTION__);
259 iface->dev.power.power_state.event = PM_EVENT_ON;
260
261 up(&us->dev_semaphore);
262 return 0;
263}
264
265#endif /* CONFIG_PM */
243 266
244/* 267/*
245 * fill_inquiry_response takes an unsigned char array (which must 268 * fill_inquiry_response takes an unsigned char array (which must
@@ -288,22 +311,7 @@ static int usb_stor_control_thread(void * __us)
288 struct us_data *us = (struct us_data *)__us; 311 struct us_data *us = (struct us_data *)__us;
289 struct Scsi_Host *host = us_to_host(us); 312 struct Scsi_Host *host = us_to_host(us);
290 313
291 lock_kernel();
292
293 /*
294 * This thread doesn't need any user-level access,
295 * so get rid of all our resources.
296 */
297 daemonize("usb-storage");
298 current->flags |= PF_NOFREEZE; 314 current->flags |= PF_NOFREEZE;
299 unlock_kernel();
300
301 /* acquire a reference to the host, so it won't be deallocated
302 * until we're ready to exit */
303 scsi_host_get(host);
304
305 /* signal that we've started the thread */
306 complete(&(us->notify));
307 315
308 for(;;) { 316 for(;;) {
309 US_DEBUGP("*** thread sleeping.\n"); 317 US_DEBUGP("*** thread sleeping.\n");
@@ -467,6 +475,12 @@ static int associate_dev(struct us_data *us, struct usb_interface *intf)
467 US_DEBUGP("I/O buffer allocation failed\n"); 475 US_DEBUGP("I/O buffer allocation failed\n");
468 return -ENOMEM; 476 return -ENOMEM;
469 } 477 }
478
479 us->sensebuf = kmalloc(US_SENSE_SIZE, GFP_KERNEL);
480 if (!us->sensebuf) {
481 US_DEBUGP("Sense buffer allocation failed\n");
482 return -ENOMEM;
483 }
470 return 0; 484 return 0;
471} 485}
472 486
@@ -555,8 +569,8 @@ static int get_transport(struct us_data *us)
555 break; 569 break;
556 570
557#ifdef CONFIG_USB_STORAGE_USBAT 571#ifdef CONFIG_USB_STORAGE_USBAT
558 case US_PR_SCM_ATAPI: 572 case US_PR_USBAT:
559 us->transport_name = "SCM/ATAPI"; 573 us->transport_name = "Shuttle USBAT";
560 us->transport = usbat_transport; 574 us->transport = usbat_transport;
561 us->transport_reset = usb_stor_CB_reset; 575 us->transport_reset = usb_stor_CB_reset;
562 us->max_lun = 1; 576 us->max_lun = 1;
@@ -740,6 +754,7 @@ static int get_pipes(struct us_data *us)
740static int usb_stor_acquire_resources(struct us_data *us) 754static int usb_stor_acquire_resources(struct us_data *us)
741{ 755{
742 int p; 756 int p;
757 struct task_struct *th;
743 758
744 us->current_urb = usb_alloc_urb(0, GFP_KERNEL); 759 us->current_urb = usb_alloc_urb(0, GFP_KERNEL);
745 if (!us->current_urb) { 760 if (!us->current_urb) {
@@ -747,38 +762,28 @@ static int usb_stor_acquire_resources(struct us_data *us)
747 return -ENOMEM; 762 return -ENOMEM;
748 } 763 }
749 764
750 /* Lock the device while we carry out the next two operations */
751 down(&us->dev_semaphore);
752
753 /* For bulk-only devices, determine the max LUN value */
754 if (us->protocol == US_PR_BULK) {
755 p = usb_stor_Bulk_max_lun(us);
756 if (p < 0) {
757 up(&us->dev_semaphore);
758 return p;
759 }
760 us->max_lun = p;
761 }
762
763 /* Just before we start our control thread, initialize 765 /* Just before we start our control thread, initialize
764 * the device if it needs initialization */ 766 * the device if it needs initialization */
765 if (us->unusual_dev->initFunction) 767 if (us->unusual_dev->initFunction) {
766 us->unusual_dev->initFunction(us); 768 p = us->unusual_dev->initFunction(us);
767 769 if (p)
768 up(&us->dev_semaphore); 770 return p;
771 }
769 772
770 /* Start up our control thread */ 773 /* Start up our control thread */
771 p = kernel_thread(usb_stor_control_thread, us, CLONE_VM); 774 th = kthread_create(usb_stor_control_thread, us, "usb-storage");
772 if (p < 0) { 775 if (IS_ERR(th)) {
773 printk(KERN_WARNING USB_STORAGE 776 printk(KERN_WARNING USB_STORAGE
774 "Unable to start control thread\n"); 777 "Unable to start control thread\n");
775 return p; 778 return PTR_ERR(th);
776 } 779 }
777 us->pid = p;
778 atomic_inc(&total_threads);
779 780
780 /* Wait for the thread to start */ 781 /* Take a reference to the host for the control thread and
781 wait_for_completion(&(us->notify)); 782 * count it among all the threads we have launched. Then
783 * start it up. */
784 scsi_host_get(us_to_host(us));
785 atomic_inc(&total_threads);
786 wake_up_process(th);
782 787
783 return 0; 788 return 0;
784} 789}
@@ -812,6 +817,8 @@ static void dissociate_dev(struct us_data *us)
812{ 817{
813 US_DEBUGP("-- %s\n", __FUNCTION__); 818 US_DEBUGP("-- %s\n", __FUNCTION__);
814 819
820 kfree(us->sensebuf);
821
815 /* Free the device-related DMA-mapped buffers */ 822 /* Free the device-related DMA-mapped buffers */
816 if (us->cr) 823 if (us->cr)
817 usb_buffer_free(us->pusb_dev, sizeof(*us->cr), us->cr, 824 usb_buffer_free(us->pusb_dev, sizeof(*us->cr), us->cr,
@@ -872,21 +879,6 @@ static int usb_stor_scan_thread(void * __us)
872{ 879{
873 struct us_data *us = (struct us_data *)__us; 880 struct us_data *us = (struct us_data *)__us;
874 881
875 /*
876 * This thread doesn't need any user-level access,
877 * so get rid of all our resources.
878 */
879 lock_kernel();
880 daemonize("usb-stor-scan");
881 unlock_kernel();
882
883 /* Acquire a reference to the host, so it won't be deallocated
884 * until we're ready to exit */
885 scsi_host_get(us_to_host(us));
886
887 /* Signal that we've started the thread */
888 complete(&(us->notify));
889
890 printk(KERN_DEBUG 882 printk(KERN_DEBUG
891 "usb-storage: device found at %d\n", us->pusb_dev->devnum); 883 "usb-storage: device found at %d\n", us->pusb_dev->devnum);
892 884
@@ -904,6 +896,14 @@ retry:
904 896
905 /* If the device is still connected, perform the scanning */ 897 /* If the device is still connected, perform the scanning */
906 if (!test_bit(US_FLIDX_DISCONNECTING, &us->flags)) { 898 if (!test_bit(US_FLIDX_DISCONNECTING, &us->flags)) {
899
900 /* For bulk-only devices, determine the max LUN value */
901 if (us->protocol == US_PR_BULK &&
902 !(us->flags & US_FL_SINGLE_LUN)) {
903 down(&us->dev_semaphore);
904 us->max_lun = usb_stor_Bulk_max_lun(us);
905 up(&us->dev_semaphore);
906 }
907 scsi_scan_host(us_to_host(us)); 907 scsi_scan_host(us_to_host(us));
908 printk(KERN_DEBUG "usb-storage: device scan complete\n"); 908 printk(KERN_DEBUG "usb-storage: device scan complete\n");
909 909
@@ -923,6 +923,7 @@ static int storage_probe(struct usb_interface *intf,
923 struct us_data *us; 923 struct us_data *us;
924 const int id_index = id - storage_usb_ids; 924 const int id_index = id - storage_usb_ids;
925 int result; 925 int result;
926 struct task_struct *th;
926 927
927 US_DEBUGP("USB Mass Storage device detected\n"); 928 US_DEBUGP("USB Mass Storage device detected\n");
928 929
@@ -1003,17 +1004,21 @@ static int storage_probe(struct usb_interface *intf,
1003 } 1004 }
1004 1005
1005 /* Start up the thread for delayed SCSI-device scanning */ 1006 /* Start up the thread for delayed SCSI-device scanning */
1006 result = kernel_thread(usb_stor_scan_thread, us, CLONE_VM); 1007 th = kthread_create(usb_stor_scan_thread, us, "usb-stor-scan");
1007 if (result < 0) { 1008 if (IS_ERR(th)) {
1008 printk(KERN_WARNING USB_STORAGE 1009 printk(KERN_WARNING USB_STORAGE
1009 "Unable to start the device-scanning thread\n"); 1010 "Unable to start the device-scanning thread\n");
1010 quiesce_and_remove_host(us); 1011 quiesce_and_remove_host(us);
1012 result = PTR_ERR(th);
1011 goto BadDevice; 1013 goto BadDevice;
1012 } 1014 }
1013 atomic_inc(&total_threads);
1014 1015
1015 /* Wait for the thread to start */ 1016 /* Take a reference to the host for the scanning thread and
1016 wait_for_completion(&(us->notify)); 1017 * count it among all the threads we have launched. Then
1018 * start it up. */
1019 scsi_host_get(us_to_host(us));
1020 atomic_inc(&total_threads);
1021 wake_up_process(th);
1017 1022
1018 return 0; 1023 return 0;
1019 1024
@@ -1038,6 +1043,18 @@ static void storage_disconnect(struct usb_interface *intf)
1038 * Initialization and registration 1043 * Initialization and registration
1039 ***********************************************************************/ 1044 ***********************************************************************/
1040 1045
1046static struct usb_driver usb_storage_driver = {
1047 .owner = THIS_MODULE,
1048 .name = "usb-storage",
1049 .probe = storage_probe,
1050 .disconnect = storage_disconnect,
1051#ifdef CONFIG_PM
1052 .suspend = storage_suspend,
1053 .resume = storage_resume,
1054#endif
1055 .id_table = storage_usb_ids,
1056};
1057
1041static int __init usb_stor_init(void) 1058static int __init usb_stor_init(void)
1042{ 1059{
1043 int retval; 1060 int retval;
diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
index a195adae57b6..98b09711a739 100644
--- a/drivers/usb/storage/usb.h
+++ b/drivers/usb/storage/usb.h
@@ -117,6 +117,7 @@ enum { US_DO_ALL_FLAGS };
117 */ 117 */
118 118
119#define US_IOBUF_SIZE 64 /* Size of the DMA-mapped I/O buffer */ 119#define US_IOBUF_SIZE 64 /* Size of the DMA-mapped I/O buffer */
120#define US_SENSE_SIZE 18 /* Size of the autosense data buffer */
120 121
121typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data*); 122typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data*);
122typedef int (*trans_reset)(struct us_data*); 123typedef int (*trans_reset)(struct us_data*);
@@ -160,14 +161,12 @@ struct us_data {
160 struct scsi_cmnd *srb; /* current srb */ 161 struct scsi_cmnd *srb; /* current srb */
161 unsigned int tag; /* current dCBWTag */ 162 unsigned int tag; /* current dCBWTag */
162 163
163 /* thread information */
164 int pid; /* control thread */
165
166 /* control and bulk communications data */ 164 /* control and bulk communications data */
167 struct urb *current_urb; /* USB requests */ 165 struct urb *current_urb; /* USB requests */
168 struct usb_ctrlrequest *cr; /* control requests */ 166 struct usb_ctrlrequest *cr; /* control requests */
169 struct usb_sg_request current_sg; /* scatter-gather req. */ 167 struct usb_sg_request current_sg; /* scatter-gather req. */
170 unsigned char *iobuf; /* I/O buffer */ 168 unsigned char *iobuf; /* I/O buffer */
169 unsigned char *sensebuf; /* sense data buffer */
171 dma_addr_t cr_dma; /* buffer DMA addresses */ 170 dma_addr_t cr_dma; /* buffer DMA addresses */
172 dma_addr_t iobuf_dma; 171 dma_addr_t iobuf_dma;
173 172
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
index 353f24d45bc1..6c3a53f8f26c 100644
--- a/drivers/usb/usb-skeleton.c
+++ b/drivers/usb/usb-skeleton.c
@@ -223,9 +223,8 @@ static struct file_operations skel_fops = {
223 * and to have the device registered with devfs and the driver core 223 * and to have the device registered with devfs and the driver core
224 */ 224 */
225static struct usb_class_driver skel_class = { 225static struct usb_class_driver skel_class = {
226 .name = "usb/skel%d", 226 .name = "skel%d",
227 .fops = &skel_fops, 227 .fops = &skel_fops,
228 .mode = S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH,
229 .minor_base = USB_SKEL_MINOR_BASE, 228 .minor_base = USB_SKEL_MINOR_BASE,
230}; 229};
231 230
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 1cd942abb580..7192b770bfb6 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -494,7 +494,7 @@ config FB_TGA
494 494
495config FB_VESA 495config FB_VESA
496 bool "VESA VGA graphics support" 496 bool "VESA VGA graphics support"
497 depends on (FB = y) && (X86 || X86_64) 497 depends on (FB = y) && X86
498 select FB_CFB_FILLRECT 498 select FB_CFB_FILLRECT
499 select FB_CFB_COPYAREA 499 select FB_CFB_COPYAREA
500 select FB_CFB_IMAGEBLIT 500 select FB_CFB_IMAGEBLIT
@@ -712,7 +712,7 @@ config FB_RIVA_DEBUG
712 712
713config FB_I810 713config FB_I810
714 tristate "Intel 810/815 support (EXPERIMENTAL)" 714 tristate "Intel 810/815 support (EXPERIMENTAL)"
715 depends on FB && EXPERIMENTAL && PCI && X86 && !X86_64 715 depends on FB && EXPERIMENTAL && PCI && X86_32
716 select AGP 716 select AGP
717 select AGP_INTEL 717 select AGP_INTEL
718 select FB_MODE_HELPERS 718 select FB_MODE_HELPERS
@@ -761,7 +761,7 @@ config FB_I810_I2C
761 761
762config FB_INTEL 762config FB_INTEL
763 tristate "Intel 830M/845G/852GM/855GM/865G support (EXPERIMENTAL)" 763 tristate "Intel 830M/845G/852GM/855GM/865G support (EXPERIMENTAL)"
764 depends on FB && EXPERIMENTAL && PCI && X86 && !X86_64 764 depends on FB && EXPERIMENTAL && PCI && X86_32
765 select AGP 765 select AGP
766 select AGP_INTEL 766 select AGP_INTEL
767 select FB_MODE_HELPERS 767 select FB_MODE_HELPERS
@@ -1376,7 +1376,7 @@ config FB_HIT
1376 1376
1377config FB_PMAG_AA 1377config FB_PMAG_AA
1378 bool "PMAG-AA TURBOchannel framebuffer support" 1378 bool "PMAG-AA TURBOchannel framebuffer support"
1379 depends on (FB = y) && MACH_DECSTATION && TC 1379 depends on (FB = y) && TC
1380 select FB_CFB_FILLRECT 1380 select FB_CFB_FILLRECT
1381 select FB_CFB_COPYAREA 1381 select FB_CFB_COPYAREA
1382 select FB_CFB_IMAGEBLIT 1382 select FB_CFB_IMAGEBLIT
@@ -1387,7 +1387,7 @@ config FB_PMAG_AA
1387 1387
1388config FB_PMAG_BA 1388config FB_PMAG_BA
1389 bool "PMAG-BA TURBOchannel framebuffer support" 1389 bool "PMAG-BA TURBOchannel framebuffer support"
1390 depends on (FB = y) && MACH_DECSTATION && TC 1390 depends on (FB = y) && TC
1391 select FB_CFB_FILLRECT 1391 select FB_CFB_FILLRECT
1392 select FB_CFB_COPYAREA 1392 select FB_CFB_COPYAREA
1393 select FB_CFB_IMAGEBLIT 1393 select FB_CFB_IMAGEBLIT
@@ -1398,7 +1398,7 @@ config FB_PMAG_BA
1398 1398
1399config FB_PMAGB_B 1399config FB_PMAGB_B
1400 bool "PMAGB-B TURBOchannel framebuffer support" 1400 bool "PMAGB-B TURBOchannel framebuffer support"
1401 depends on (FB = y) && MACH_DECSTATION && TC 1401 depends on (FB = y) && TC
1402 select FB_CFB_FILLRECT 1402 select FB_CFB_FILLRECT
1403 select FB_CFB_COPYAREA 1403 select FB_CFB_COPYAREA
1404 select FB_CFB_IMAGEBLIT 1404 select FB_CFB_IMAGEBLIT
@@ -1410,7 +1410,7 @@ config FB_PMAGB_B
1410 1410
1411config FB_MAXINE 1411config FB_MAXINE
1412 bool "Maxine (Personal DECstation) onboard framebuffer support" 1412 bool "Maxine (Personal DECstation) onboard framebuffer support"
1413 depends on (FB = y) && MACH_DECSTATION && TC 1413 depends on (FB = y) && MACH_DECSTATION
1414 select FB_CFB_FILLRECT 1414 select FB_CFB_FILLRECT
1415 select FB_CFB_COPYAREA 1415 select FB_CFB_COPYAREA
1416 select FB_CFB_IMAGEBLIT 1416 select FB_CFB_IMAGEBLIT
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 1fff29f48ca8..97c5d03ac8d9 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -86,7 +86,7 @@ obj-$(CONFIG_FB_CIRRUS) += cirrusfb.o
86obj-$(CONFIG_FB_ASILIANT) += asiliantfb.o 86obj-$(CONFIG_FB_ASILIANT) += asiliantfb.o
87obj-$(CONFIG_FB_PXA) += pxafb.o 87obj-$(CONFIG_FB_PXA) += pxafb.o
88obj-$(CONFIG_FB_W100) += w100fb.o 88obj-$(CONFIG_FB_W100) += w100fb.o
89obj-$(CONFIG_FB_AU1100) += au1100fb.o fbgen.o 89obj-$(CONFIG_FB_AU1100) += au1100fb.o
90obj-$(CONFIG_FB_PMAG_AA) += pmag-aa-fb.o 90obj-$(CONFIG_FB_PMAG_AA) += pmag-aa-fb.o
91obj-$(CONFIG_FB_PMAG_BA) += pmag-ba-fb.o 91obj-$(CONFIG_FB_PMAG_BA) += pmag-ba-fb.o
92obj-$(CONFIG_FB_PMAGB_B) += pmagb-b-fb.o 92obj-$(CONFIG_FB_PMAGB_B) += pmagb-b-fb.o
diff --git a/drivers/video/amba-clcd.c b/drivers/video/amba-clcd.c
index 321dbe91dc14..cde6fd8eb390 100644
--- a/drivers/video/amba-clcd.c
+++ b/drivers/video/amba-clcd.c
@@ -22,6 +22,7 @@
22#include <linux/ioport.h> 22#include <linux/ioport.h>
23#include <linux/list.h> 23#include <linux/list.h>
24 24
25#include <asm/sizes.h>
25#include <asm/hardware/amba.h> 26#include <asm/hardware/amba.h>
26#include <asm/hardware/clock.h> 27#include <asm/hardware/clock.h>
27 28
diff --git a/drivers/video/au1100fb.c b/drivers/video/au1100fb.c
index b6fe30c3ad62..a5129806172f 100644
--- a/drivers/video/au1100fb.c
+++ b/drivers/video/au1100fb.c
@@ -2,6 +2,11 @@
2 * BRIEF MODULE DESCRIPTION 2 * BRIEF MODULE DESCRIPTION
3 * Au1100 LCD Driver. 3 * Au1100 LCD Driver.
4 * 4 *
5 * Rewritten for 2.6 by Embedded Alley Solutions
6 * <source@embeddedalley.com>, based on submissions by
7 * Karl Lessard <klessard@sunrisetelecom.com>
8 * <c.pellegrin@exadron.com>
9 *
5 * Copyright 2002 MontaVista Software 10 * Copyright 2002 MontaVista Software
6 * Author: MontaVista Software, Inc. 11 * Author: MontaVista Software, Inc.
7 * ppopov@mvista.com or source@mvista.com 12 * ppopov@mvista.com or source@mvista.com
@@ -33,298 +38,253 @@
33 * with this program; if not, write to the Free Software Foundation, Inc., 38 * with this program; if not, write to the Free Software Foundation, Inc.,
34 * 675 Mass Ave, Cambridge, MA 02139, USA. 39 * 675 Mass Ave, Cambridge, MA 02139, USA.
35 */ 40 */
36 41#include <linux/config.h>
37#include <linux/module.h> 42#include <linux/module.h>
38#include <linux/kernel.h> 43#include <linux/kernel.h>
39#include <linux/errno.h> 44#include <linux/errno.h>
40#include <linux/string.h> 45#include <linux/string.h>
41#include <linux/mm.h> 46#include <linux/mm.h>
42#include <linux/tty.h>
43#include <linux/slab.h>
44#include <linux/delay.h>
45#include <linux/fb.h> 47#include <linux/fb.h>
46#include <linux/init.h> 48#include <linux/init.h>
47#include <linux/pci.h> 49#include <linux/interrupt.h>
50#include <linux/ctype.h>
51#include <linux/dma-mapping.h>
48 52
49#include <asm/au1000.h> 53#include <asm/mach-au1x00/au1000.h>
50#include <asm/pb1100.h>
51#include "au1100fb.h"
52 54
53#include <video/fbcon.h> 55#define DEBUG 0
54#include <video/fbcon-mfb.h> 56
55#include <video/fbcon-cfb2.h> 57#include "au1100fb.h"
56#include <video/fbcon-cfb4.h>
57#include <video/fbcon-cfb8.h>
58#include <video/fbcon-cfb16.h>
59 58
60/* 59/*
61 * Sanity check. If this is a new Au1100 based board, search for 60 * Sanity check. If this is a new Au1100 based board, search for
62 * the PB1100 ifdefs to make sure you modify the code accordingly. 61 * the PB1100 ifdefs to make sure you modify the code accordingly.
63 */ 62 */
64#if defined(CONFIG_MIPS_PB1100) || defined(CONFIG_MIPS_DB1100) || defined(CONFIG_MIPS_HYDROGEN3) 63#if defined(CONFIG_MIPS_PB1100)
64 #include <asm/mach-pb1x00/pb1100.h>
65#elif defined(CONFIG_MIPS_DB1100)
66 #include <asm/mach-db1x00/db1x00.h>
65#else 67#else
66error Unknown Au1100 board 68 #error "Unknown Au1100 board, Au1100 FB driver not supported"
67#endif 69#endif
68 70
69#define CMAPSIZE 16 71#define DRIVER_NAME "au1100fb"
70 72#define DRIVER_DESC "LCD controller driver for AU1100 processors"
71static int my_lcd_index; /* default is zero */
72struct known_lcd_panels *p_lcd;
73AU1100_LCD *p_lcd_reg = (AU1100_LCD *)AU1100_LCD_ADDR;
74
75struct au1100fb_info {
76 struct fb_info_gen gen;
77 unsigned long fb_virt_start;
78 unsigned long fb_size;
79 unsigned long fb_phys;
80 int mmaped;
81 int nohwcursor;
82 73
83 struct { unsigned red, green, blue, pad; } palette[256]; 74#define to_au1100fb_device(_info) \
75 (_info ? container_of(_info, struct au1100fb_device, info) : NULL);
84 76
85#if defined(FBCON_HAS_CFB16) 77/* Bitfields format supported by the controller. Note that the order of formats
86 u16 fbcon_cmap16[16]; 78 * SHOULD be the same as in the LCD_CONTROL_SBPPF field, so we can retrieve the
87#endif 79 * right pixel format by doing rgb_bitfields[LCD_CONTROL_SBPPF_XXX >> LCD_CONTROL_SBPPF]
80 */
81struct fb_bitfield rgb_bitfields[][4] =
82{
83 /* Red, Green, Blue, Transp */
84 { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
85 { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
86 { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
87 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
88 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
89
90 /* The last is used to describe 12bpp format */
91 { { 8, 4, 0 }, { 4, 4, 0 }, { 0, 4, 0 }, { 0, 0, 0 } },
88}; 92};
89 93
90 94static struct fb_fix_screeninfo au1100fb_fix __initdata = {
91struct au1100fb_par { 95 .id = "AU1100 FB",
92 struct fb_var_screeninfo var; 96 .xpanstep = 1,
93 97 .ypanstep = 1,
94 int line_length; // in bytes 98 .type = FB_TYPE_PACKED_PIXELS,
95 int cmap_len; // color-map length 99 .accel = FB_ACCEL_NONE,
96}; 100};
97 101
98 102static struct fb_var_screeninfo au1100fb_var __initdata = {
99static struct au1100fb_info fb_info; 103 .activate = FB_ACTIVATE_NOW,
100static struct au1100fb_par current_par; 104 .height = -1,
101static struct display disp; 105 .width = -1,
102 106 .vmode = FB_VMODE_NONINTERLACED,
103int au1100fb_init(void);
104void au1100fb_setup(char *options, int *ints);
105static int au1100fb_mmap(struct fb_info *fb, struct file *file,
106 struct vm_area_struct *vma);
107static int au1100_blank(int blank_mode, struct fb_info_gen *info);
108static int au1100fb_ioctl(struct inode *inode, struct file *file, u_int cmd,
109 u_long arg, int con, struct fb_info *info);
110
111void au1100_nocursor(struct display *p, int mode, int xx, int yy){};
112
113static struct fb_ops au1100fb_ops = {
114 .owner = THIS_MODULE,
115 .fb_get_fix = fbgen_get_fix,
116 .fb_get_var = fbgen_get_var,
117 .fb_set_var = fbgen_set_var,
118 .fb_get_cmap = fbgen_get_cmap,
119 .fb_set_cmap = fbgen_set_cmap,
120 .fb_pan_display = fbgen_pan_display,
121 .fb_ioctl = au1100fb_ioctl,
122 .fb_mmap = au1100fb_mmap,
123}; 107};
124 108
125static void au1100_detect(void) 109static struct au1100fb_drv_info drv_info;
126{
127 /*
128 * This function should detect the current video mode settings
129 * and store it as the default video mode
130 */
131 110
132 /* 111/*
133 * Yeh, well, we're not going to change any settings so we're 112 * Set hardware with var settings. This will enable the controller with a specific
134 * always stuck with the default ... 113 * mode, normally validated with the fb_check_var method
135 */ 114 */
136 115int au1100fb_setmode(struct au1100fb_device *fbdev)
137}
138
139static int au1100_encode_fix(struct fb_fix_screeninfo *fix,
140 const void *_par, struct fb_info_gen *_info)
141{ 116{
142 struct au1100fb_info *info = (struct au1100fb_info *) _info; 117 struct fb_info *info = &fbdev->info;
143 struct au1100fb_par *par = (struct au1100fb_par *) _par; 118 u32 words;
144 struct fb_var_screeninfo *var = &par->var; 119 int index;
145
146 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
147
148 fix->smem_start = info->fb_phys;
149 fix->smem_len = info->fb_size;
150 fix->type = FB_TYPE_PACKED_PIXELS;
151 fix->type_aux = 0;
152 fix->visual = (var->bits_per_pixel == 8) ?
153 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
154 fix->ywrapstep = 0;
155 fix->xpanstep = 1;
156 fix->ypanstep = 1;
157 fix->line_length = current_par.line_length;
158 return 0;
159}
160 120
161static void set_color_bitfields(struct fb_var_screeninfo *var) 121 if (!fbdev)
162{ 122 return -EINVAL;
163 switch (var->bits_per_pixel) { 123
164 case 8: 124 /* Update var-dependent FB info */
165 var->red.offset = 0; 125 if (panel_is_active(fbdev->panel) || panel_is_color(fbdev->panel)) {
166 var->red.length = 8; 126 if (info->var.bits_per_pixel <= 8) {
167 var->green.offset = 0; 127 /* palettized */
168 var->green.length = 8; 128 info->var.red.offset = 0;
169 var->blue.offset = 0; 129 info->var.red.length = info->var.bits_per_pixel;
170 var->blue.length = 8; 130 info->var.red.msb_right = 0;
171 var->transp.offset = 0; 131
172 var->transp.length = 0; 132 info->var.green.offset = 0;
173 break; 133 info->var.green.length = info->var.bits_per_pixel;
174 case 16: /* RGB 565 */ 134 info->var.green.msb_right = 0;
175 var->red.offset = 11; 135
176 var->red.length = 5; 136 info->var.blue.offset = 0;
177 var->green.offset = 5; 137 info->var.blue.length = info->var.bits_per_pixel;
178 var->green.length = 6; 138 info->var.blue.msb_right = 0;
179 var->blue.offset = 0; 139
180 var->blue.length = 5; 140 info->var.transp.offset = 0;
181 var->transp.offset = 0; 141 info->var.transp.length = 0;
182 var->transp.length = 0; 142 info->var.transp.msb_right = 0;
183 break; 143
144 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
145 info->fix.line_length = info->var.xres_virtual /
146 (8/info->var.bits_per_pixel);
147 } else {
148 /* non-palettized */
149 index = (fbdev->panel->control_base & LCD_CONTROL_SBPPF_MASK) >> LCD_CONTROL_SBPPF_BIT;
150 info->var.red = rgb_bitfields[index][0];
151 info->var.green = rgb_bitfields[index][1];
152 info->var.blue = rgb_bitfields[index][2];
153 info->var.transp = rgb_bitfields[index][3];
154
155 info->fix.visual = FB_VISUAL_TRUECOLOR;
156 info->fix.line_length = info->var.xres_virtual << 1; /* depth=16 */
157 }
158 } else {
159 /* mono */
160 info->fix.visual = FB_VISUAL_MONO10;
161 info->fix.line_length = info->var.xres_virtual / 8;
184 } 162 }
185 163
186 var->red.msb_right = 0; 164 info->screen_size = info->fix.line_length * info->var.yres_virtual;
187 var->green.msb_right = 0;
188 var->blue.msb_right = 0;
189 var->transp.msb_right = 0;
190}
191 165
192static int au1100_decode_var(const struct fb_var_screeninfo *var, 166 /* Determine BPP mode and format */
193 void *_par, struct fb_info_gen *_info) 167 fbdev->regs->lcd_control = fbdev->panel->control_base |
194{ 168 ((info->var.rotate/90) << LCD_CONTROL_SM_BIT);
195 169
196 struct au1100fb_par *par = (struct au1100fb_par *)_par; 170 fbdev->regs->lcd_intenable = 0;
171 fbdev->regs->lcd_intstatus = 0;
197 172
198 /* 173 fbdev->regs->lcd_horztiming = fbdev->panel->horztiming;
199 * Don't allow setting any of these yet: xres and yres don't
200 * make sense for LCD panels.
201 */
202 if (var->xres != p_lcd->xres ||
203 var->yres != p_lcd->yres ||
204 var->xres != p_lcd->xres ||
205 var->yres != p_lcd->yres) {
206 return -EINVAL;
207 }
208 if(var->bits_per_pixel != p_lcd->bpp) {
209 return -EINVAL;
210 }
211 174
212 memset(par, 0, sizeof(struct au1100fb_par)); 175 fbdev->regs->lcd_verttiming = fbdev->panel->verttiming;
213 par->var = *var; 176
214 177 fbdev->regs->lcd_clkcontrol = fbdev->panel->clkcontrol_base;
215 /* FIXME */
216 switch (var->bits_per_pixel) {
217 case 8:
218 par->var.bits_per_pixel = 8;
219 break;
220 case 16:
221 par->var.bits_per_pixel = 16;
222 break;
223 default:
224 printk("color depth %d bpp not supported\n",
225 var->bits_per_pixel);
226 return -EINVAL;
227 178
179 fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(fbdev->fb_phys);
180
181 if (panel_is_dual(fbdev->panel)) {
182 /* Second panel display seconf half of screen if possible,
183 * otherwise display the same as the first panel */
184 if (info->var.yres_virtual >= (info->var.yres << 1)) {
185 fbdev->regs->lcd_dmaaddr1 = LCD_DMA_SA_N(fbdev->fb_phys +
186 (info->fix.line_length *
187 (info->var.yres_virtual >> 1)));
188 } else {
189 fbdev->regs->lcd_dmaaddr1 = LCD_DMA_SA_N(fbdev->fb_phys);
190 }
228 } 191 }
229 set_color_bitfields(&par->var);
230 par->cmap_len = (par->var.bits_per_pixel == 8) ? 256 : 16;
231 return 0;
232}
233 192
234static int au1100_encode_var(struct fb_var_screeninfo *var, 193 words = info->fix.line_length / sizeof(u32);
235 const void *par, struct fb_info_gen *_info) 194 if (!info->var.rotate || (info->var.rotate == 180)) {
236{ 195 words *= info->var.yres_virtual;
196 if (info->var.rotate /* 180 */) {
197 words -= (words % 8); /* should be divisable by 8 */
198 }
199 }
200 fbdev->regs->lcd_words = LCD_WRD_WRDS_N(words);
237 201
238 *var = ((struct au1100fb_par *)par)->var; 202 fbdev->regs->lcd_pwmdiv = 0;
239 return 0; 203 fbdev->regs->lcd_pwmhi = 0;
240}
241 204
242static void 205 /* Resume controller */
243au1100_get_par(void *_par, struct fb_info_gen *_info) 206 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
244{
245 *(struct au1100fb_par *)_par = current_par;
246}
247 207
248static void au1100_set_par(const void *par, struct fb_info_gen *info) 208 return 0;
249{
250 /* nothing to do: we don't change any settings */
251} 209}
252 210
253static int au1100_getcolreg(unsigned regno, unsigned *red, unsigned *green, 211/* fb_setcolreg
254 unsigned *blue, unsigned *transp, 212 * Set color in LCD palette.
255 struct fb_info *info) 213 */
214int au1100fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *fbi)
256{ 215{
216 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
217 u32 *palette = fbdev->regs->lcd_pallettebase;
218 u32 value;
257 219
258 struct au1100fb_info* i = (struct au1100fb_info*)info; 220 if (regno > (AU1100_LCD_NBR_PALETTE_ENTRIES - 1))
259 221 return -EINVAL;
260 if (regno > 255)
261 return 1;
262 222
263 *red = i->palette[regno].red; 223 if (fbi->var.grayscale) {
264 *green = i->palette[regno].green; 224 /* Convert color to grayscale */
265 *blue = i->palette[regno].blue; 225 red = green = blue =
266 *transp = 0; 226 (19595 * red + 38470 * green + 7471 * blue) >> 16;
227 }
267 228
268 return 0; 229 if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) {
269} 230 /* Place color in the pseudopalette */
231 if (regno > 16)
232 return -EINVAL;
270 233
271static int au1100_setcolreg(unsigned regno, unsigned red, unsigned green, 234 palette = (u32*)fbi->pseudo_palette;
272 unsigned blue, unsigned transp, 235
273 struct fb_info *info) 236 red >>= (16 - fbi->var.red.length);
274{ 237 green >>= (16 - fbi->var.green.length);
275 struct au1100fb_info* i = (struct au1100fb_info *)info; 238 blue >>= (16 - fbi->var.blue.length);
276 u32 rgbcol; 239
277 240 value = (red << fbi->var.red.offset) |
278 if (regno > 255) 241 (green << fbi->var.green.offset)|
279 return 1; 242 (blue << fbi->var.blue.offset);
280 243 value &= 0xFFFF;
281 i->palette[regno].red = red; 244
282 i->palette[regno].green = green; 245 } else if (panel_is_active(fbdev->panel)) {
283 i->palette[regno].blue = blue; 246 /* COLOR TFT PALLETTIZED (use RGB 565) */
284 247 value = (red & 0xF800)|((green >> 5) & 0x07E0)|((blue >> 11) & 0x001F);
285 switch(p_lcd->bpp) { 248 value &= 0xFFFF;
286#ifdef FBCON_HAS_CFB8 249
287 case 8: 250 } else if (panel_is_color(fbdev->panel)) {
288 red >>= 10; 251 /* COLOR STN MODE */
289 green >>= 10; 252 value = (((panel_swap_rgb(fbdev->panel) ? blue : red) >> 12) & 0x000F) |
290 blue >>= 10; 253 ((green >> 8) & 0x00F0) |
291 p_lcd_reg->lcd_pallettebase[regno] = (blue&0x1f) | 254 (((panel_swap_rgb(fbdev->panel) ? red : blue) >> 4) & 0x0F00);
292 ((green&0x3f)<<5) | ((red&0x1f)<<11); 255 value &= 0xFFF;
293 break; 256 } else {
294#endif 257 /* MONOCHROME MODE */
295#ifdef FBCON_HAS_CFB16 258 value = (green >> 12) & 0x000F;
296 case 16: 259 value &= 0xF;
297 i->fbcon_cmap16[regno] =
298 ((red & 0xf800) >> 0) |
299 ((green & 0xfc00) >> 5) |
300 ((blue & 0xf800) >> 11);
301 break;
302#endif
303 default:
304 break;
305 } 260 }
306 261
262 palette[regno] = value;
263
307 return 0; 264 return 0;
308} 265}
309 266
310 267/* fb_blank
311static int au1100_blank(int blank_mode, struct fb_info_gen *_info) 268 * Blank the screen. Depending on the mode, the screen will be
269 * activated with the backlight color, or desactivated
270 */
271int au1100fb_fb_blank(int blank_mode, struct fb_info *fbi)
312{ 272{
273 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
274
275 print_dbg("fb_blank %d %p", blank_mode, fbi);
313 276
314 switch (blank_mode) { 277 switch (blank_mode) {
278
315 case VESA_NO_BLANKING: 279 case VESA_NO_BLANKING:
316 /* turn on panel */ 280 /* Turn on panel */
317 //printk("turn on panel\n"); 281 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
318#ifdef CONFIG_MIPS_PB1100 282#ifdef CONFIG_MIPS_PB1100
319 p_lcd_reg->lcd_control |= LCD_CONTROL_GO; 283 if (drv_info.panel_idx == 1) {
320 au_writew(au_readw(PB1100_G_CONTROL) | p_lcd->mode_backlight, 284 au_writew(au_readw(PB1100_G_CONTROL)
285 | (PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD),
321 PB1100_G_CONTROL); 286 PB1100_G_CONTROL);
322#endif 287 }
323#ifdef CONFIG_MIPS_HYDROGEN3
324 /* Turn controller & power supply on, GPIO213 */
325 au_writel(0x20002000, 0xB1700008);
326 au_writel(0x00040000, 0xB1900108);
327 au_writel(0x01000100, 0xB1700008);
328#endif 288#endif
329 au_sync(); 289 au_sync();
330 break; 290 break;
@@ -332,12 +292,14 @@ static int au1100_blank(int blank_mode, struct fb_info_gen *_info)
332 case VESA_VSYNC_SUSPEND: 292 case VESA_VSYNC_SUSPEND:
333 case VESA_HSYNC_SUSPEND: 293 case VESA_HSYNC_SUSPEND:
334 case VESA_POWERDOWN: 294 case VESA_POWERDOWN:
335 /* turn off panel */ 295 /* Turn off panel */
336 //printk("turn off panel\n"); 296 fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
337#ifdef CONFIG_MIPS_PB1100 297#ifdef CONFIG_MIPS_PB1100
338 au_writew(au_readw(PB1100_G_CONTROL) & ~p_lcd->mode_backlight, 298 if (drv_info.panel_idx == 1) {
299 au_writew(au_readw(PB1100_G_CONTROL)
300 & ~(PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD),
339 PB1100_G_CONTROL); 301 PB1100_G_CONTROL);
340 p_lcd_reg->lcd_control &= ~LCD_CONTROL_GO; 302 }
341#endif 303#endif
342 au_sync(); 304 au_sync();
343 break; 305 break;
@@ -348,49 +310,87 @@ static int au1100_blank(int blank_mode, struct fb_info_gen *_info)
348 return 0; 310 return 0;
349} 311}
350 312
351static void au1100_set_disp(const void *unused, struct display *disp, 313/* fb_pan_display
352 struct fb_info_gen *info) 314 * Pan display in x and/or y as specified
315 */
316int au1100fb_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *fbi)
353{ 317{
354 disp->screen_base = (char *)fb_info.fb_virt_start; 318 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
355 319 int dy;
356 switch (disp->var.bits_per_pixel) { 320
357#ifdef FBCON_HAS_CFB8 321 print_dbg("fb_pan_display %p %p", var, fbi);
358 case 8: 322
359 disp->dispsw = &fbcon_cfb8; 323 if (!var || !fbdev) {
360 if (fb_info.nohwcursor) 324 return -EINVAL;
361 fbcon_cfb8.cursor = au1100_nocursor; 325 }
362 break; 326
363#endif 327 if (var->xoffset - fbi->var.xoffset) {
364#ifdef FBCON_HAS_CFB16 328 /* No support for X panning for now! */
365 case 16: 329 return -EINVAL;
366 disp->dispsw = &fbcon_cfb16; 330 }
367 disp->dispsw_data = fb_info.fbcon_cmap16; 331
368 if (fb_info.nohwcursor) 332 print_dbg("fb_pan_display 2 %p %p", var, fbi);
369 fbcon_cfb16.cursor = au1100_nocursor; 333 dy = var->yoffset - fbi->var.yoffset;
370 break; 334 if (dy) {
371#endif 335
372 default: 336 u32 dmaaddr;
373 disp->dispsw = &fbcon_dummy; 337
374 disp->dispsw_data = NULL; 338 print_dbg("Panning screen of %d lines", dy);
375 break; 339
340 dmaaddr = fbdev->regs->lcd_dmaaddr0;
341 dmaaddr += (fbi->fix.line_length * dy);
342
343 /* TODO: Wait for current frame to finished */
344 fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr);
345
346 if (panel_is_dual(fbdev->panel)) {
347 dmaaddr = fbdev->regs->lcd_dmaaddr1;
348 dmaaddr += (fbi->fix.line_length * dy);
349 fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr);
350 }
351 }
352 print_dbg("fb_pan_display 3 %p %p", var, fbi);
353
354 return 0;
355}
356
357/* fb_rotate
358 * Rotate the display of this angle. This doesn't seems to be used by the core,
359 * but as our hardware supports it, so why not implementing it...
360 */
361void au1100fb_fb_rotate(struct fb_info *fbi, int angle)
362{
363 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
364
365 print_dbg("fb_rotate %p %d", fbi, angle);
366
367 if (fbdev && (angle > 0) && !(angle % 90)) {
368
369 fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
370
371 fbdev->regs->lcd_control &= ~(LCD_CONTROL_SM_MASK);
372 fbdev->regs->lcd_control |= ((angle/90) << LCD_CONTROL_SM_BIT);
373
374 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
376 } 375 }
377} 376}
378 377
379static int 378/* fb_mmap
380au1100fb_mmap(struct fb_info *_fb, 379 * Map video memory in user space. We don't use the generic fb_mmap method mainly
381 struct file *file, 380 * to allow the use of the TLB streaming flag (CCA=6)
382 struct vm_area_struct *vma) 381 */
382int au1100fb_fb_mmap(struct fb_info *fbi, struct file *file, struct vm_area_struct *vma)
383{ 383{
384 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
384 unsigned int len; 385 unsigned int len;
385 unsigned long start=0, off; 386 unsigned long start=0, off;
386 struct au1100fb_info *fb = (struct au1100fb_info *)_fb;
387 387
388 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) { 388 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) {
389 return -EINVAL; 389 return -EINVAL;
390 } 390 }
391 391
392 start = fb_info.fb_phys & PAGE_MASK; 392 start = fbdev->fb_phys & PAGE_MASK;
393 len = PAGE_ALIGN((start & ~PAGE_MASK) + fb_info.fb_size); 393 len = PAGE_ALIGN((start & ~PAGE_MASK) + fbdev->fb_len);
394 394
395 off = vma->vm_pgoff << PAGE_SHIFT; 395 off = vma->vm_pgoff << PAGE_SHIFT;
396 396
@@ -401,276 +401,309 @@ au1100fb_mmap(struct fb_info *_fb,
401 off += start; 401 off += start;
402 vma->vm_pgoff = off >> PAGE_SHIFT; 402 vma->vm_pgoff = off >> PAGE_SHIFT;
403 403
404 pgprot_val(vma->vm_page_prot) &= ~_CACHE_MASK; 404 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
405 //pgprot_val(vma->vm_page_prot) |= _CACHE_CACHABLE_NONCOHERENT;
406 pgprot_val(vma->vm_page_prot) |= (6 << 9); //CCA=6 405 pgprot_val(vma->vm_page_prot) |= (6 << 9); //CCA=6
407 406
408 /* This is an IO map - tell maydump to skip this VMA */
409 vma->vm_flags |= VM_IO; 407 vma->vm_flags |= VM_IO;
410 408
411 if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT, 409 if (io_remap_page_range(vma, vma->vm_start, off,
412 vma->vm_end - vma->vm_start, 410 vma->vm_end - vma->vm_start,
413 vma->vm_page_prot)) { 411 vma->vm_page_prot)) {
414 return -EAGAIN; 412 return -EAGAIN;
415 } 413 }
416 414
417 fb->mmaped = 1;
418 return 0; 415 return 0;
419} 416}
420 417
421int au1100_pan_display(const struct fb_var_screeninfo *var, 418static struct fb_ops au1100fb_ops =
422 struct fb_info_gen *info)
423{ 419{
424 return 0; 420 .owner = THIS_MODULE,
425} 421 .fb_setcolreg = au1100fb_fb_setcolreg,
422 .fb_blank = au1100fb_fb_blank,
423 .fb_pan_display = au1100fb_fb_pan_display,
424 .fb_fillrect = cfb_fillrect,
425 .fb_copyarea = cfb_copyarea,
426 .fb_imageblit = cfb_imageblit,
427 .fb_rotate = au1100fb_fb_rotate,
428 .fb_mmap = au1100fb_fb_mmap,
429};
426 430
427static int au1100fb_ioctl(struct inode *inode, struct file *file, u_int cmd,
428 u_long arg, int con, struct fb_info *info)
429{
430 /* nothing to do yet */
431 return -EINVAL;
432}
433 431
434static struct fbgen_hwswitch au1100_switch = { 432/*-------------------------------------------------------------------------*/
435 au1100_detect,
436 au1100_encode_fix,
437 au1100_decode_var,
438 au1100_encode_var,
439 au1100_get_par,
440 au1100_set_par,
441 au1100_getcolreg,
442 au1100_setcolreg,
443 au1100_pan_display,
444 au1100_blank,
445 au1100_set_disp
446};
447 433
434/* AU1100 LCD controller device driver */
448 435
449int au1100_setmode(void) 436int au1100fb_drv_probe(struct device *dev)
450{ 437{
451 int words; 438 struct au1100fb_device *fbdev = NULL;
452 439 struct resource *regs_res;
453 /* FIXME Need to accomodate for swivel mode and 12bpp, <8bpp*/ 440 unsigned long page;
454 switch (p_lcd->mode_control & LCD_CONTROL_SM) 441 u32 sys_clksrc;
455 { 442
456 case LCD_CONTROL_SM_0: 443 if (!dev)
457 case LCD_CONTROL_SM_180:
458 words = (p_lcd->xres * p_lcd->yres * p_lcd->bpp) / 32;
459 break;
460 case LCD_CONTROL_SM_90:
461 case LCD_CONTROL_SM_270:
462 /* is this correct? */
463 words = (p_lcd->xres * p_lcd->bpp) / 8;
464 break;
465 default:
466 printk("mode_control reg not initialized\n");
467 return -EINVAL; 444 return -EINVAL;
445
446 /* Allocate new device private */
447 if (!(fbdev = kmalloc(sizeof(struct au1100fb_device), GFP_KERNEL))) {
448 print_err("fail to allocate device private record");
449 return -ENOMEM;
468 } 450 }
451 memset((void*)fbdev, 0, sizeof(struct au1100fb_device));
469 452
470 /* 453 fbdev->panel = &known_lcd_panels[drv_info.panel_idx];
471 * Setup LCD controller
472 */
473 454
474 p_lcd_reg->lcd_control = p_lcd->mode_control; 455 dev_set_drvdata(dev, (void*)fbdev);
475 p_lcd_reg->lcd_intstatus = 0;
476 p_lcd_reg->lcd_intenable = 0;
477 p_lcd_reg->lcd_horztiming = p_lcd->mode_horztiming;
478 p_lcd_reg->lcd_verttiming = p_lcd->mode_verttiming;
479 p_lcd_reg->lcd_clkcontrol = p_lcd->mode_clkcontrol;
480 p_lcd_reg->lcd_words = words - 1;
481 p_lcd_reg->lcd_dmaaddr0 = fb_info.fb_phys;
482 456
483 /* turn on panel */ 457 /* Allocate region for our registers and map them */
484#ifdef CONFIG_MIPS_PB1100 458 if (!(regs_res = platform_get_resource(to_platform_device(dev),
485 au_writew(au_readw(PB1100_G_CONTROL) | p_lcd->mode_backlight, 459 IORESOURCE_MEM, 0))) {
486 PB1100_G_CONTROL); 460 print_err("fail to retrieve registers resource");
487#endif 461 return -EFAULT;
488#ifdef CONFIG_MIPS_HYDROGEN3 462 }
489 /* Turn controller & power supply on, GPIO213 */
490 au_writel(0x20002000, 0xB1700008);
491 au_writel(0x00040000, 0xB1900108);
492 au_writel(0x01000100, 0xB1700008);
493#endif
494 463
495 p_lcd_reg->lcd_control |= LCD_CONTROL_GO; 464 au1100fb_fix.mmio_start = regs_res->start;
465 au1100fb_fix.mmio_len = regs_res->end - regs_res->start + 1;
496 466
497 return 0; 467 if (!request_mem_region(au1100fb_fix.mmio_start, au1100fb_fix.mmio_len,
498} 468 DRIVER_NAME)) {
469 print_err("fail to lock memory region at 0x%08x",
470 au1100fb_fix.mmio_start);
471 return -EBUSY;
472 }
499 473
474 fbdev->regs = (struct au1100fb_regs*)KSEG1ADDR(au1100fb_fix.mmio_start);
500 475
501int __init au1100fb_init(void) 476 print_dbg("Register memory map at %p", fbdev->regs);
502{ 477 print_dbg("phys=0x%08x, size=%d", fbdev->regs_phys, fbdev->regs_len);
503 uint32 sys_clksrc;
504 unsigned long page;
505 478
506 /*
507 * Get the panel information/display mode and update the registry
508 */
509 p_lcd = &panels[my_lcd_index];
510
511 switch (p_lcd->mode_control & LCD_CONTROL_SM)
512 {
513 case LCD_CONTROL_SM_0:
514 case LCD_CONTROL_SM_180:
515 p_lcd->xres =
516 (p_lcd->mode_horztiming & LCD_HORZTIMING_PPL) + 1;
517 p_lcd->yres =
518 (p_lcd->mode_verttiming & LCD_VERTTIMING_LPP) + 1;
519 break;
520 case LCD_CONTROL_SM_90:
521 case LCD_CONTROL_SM_270:
522 p_lcd->yres =
523 (p_lcd->mode_horztiming & LCD_HORZTIMING_PPL) + 1;
524 p_lcd->xres =
525 (p_lcd->mode_verttiming & LCD_VERTTIMING_LPP) + 1;
526 break;
527 }
528 479
529 /*
530 * Panel dimensions x bpp must be divisible by 32
531 */
532 if (((p_lcd->yres * p_lcd->bpp) % 32) != 0)
533 printk("VERT %% 32\n");
534 if (((p_lcd->xres * p_lcd->bpp) % 32) != 0)
535 printk("HORZ %% 32\n");
536 480
537 /* 481 /* Allocate the framebuffer to the maximum screen size * nbr of video buffers */
538 * Allocate LCD framebuffer from system memory 482 fbdev->fb_len = fbdev->panel->xres * fbdev->panel->yres *
539 */ 483 (fbdev->panel->bpp >> 3) * AU1100FB_NBR_VIDEO_BUFFERS;
540 fb_info.fb_size = (p_lcd->xres * p_lcd->yres * p_lcd->bpp) / 8; 484
541 485 fbdev->fb_mem = dma_alloc_coherent(dev, PAGE_ALIGN(fbdev->fb_len),
542 current_par.var.xres = p_lcd->xres; 486 &fbdev->fb_phys, GFP_KERNEL);
543 current_par.var.xres_virtual = p_lcd->xres; 487 if (!fbdev->fb_mem) {
544 current_par.var.yres = p_lcd->yres; 488 print_err("fail to allocate frambuffer (size: %dK))",
545 current_par.var.yres_virtual = p_lcd->yres; 489 fbdev->fb_len / 1024);
546 current_par.var.bits_per_pixel = p_lcd->bpp;
547
548 /* FIX!!! only works for 8/16 bpp */
549 current_par.line_length = p_lcd->xres * p_lcd->bpp / 8; /* in bytes */
550 fb_info.fb_virt_start = (unsigned long )
551 __get_free_pages(GFP_ATOMIC | GFP_DMA,
552 get_order(fb_info.fb_size + 0x1000));
553 if (!fb_info.fb_virt_start) {
554 printk("Unable to allocate fb memory\n");
555 return -ENOMEM; 490 return -ENOMEM;
556 } 491 }
557 fb_info.fb_phys = virt_to_bus((void *)fb_info.fb_virt_start); 492
493 au1100fb_fix.smem_start = fbdev->fb_phys;
494 au1100fb_fix.smem_len = fbdev->fb_len;
558 495
559 /* 496 /*
560 * Set page reserved so that mmap will work. This is necessary 497 * Set page reserved so that mmap will work. This is necessary
561 * since we'll be remapping normal memory. 498 * since we'll be remapping normal memory.
562 */ 499 */
563 for (page = fb_info.fb_virt_start; 500 for (page = (unsigned long)fbdev->fb_mem;
564 page < PAGE_ALIGN(fb_info.fb_virt_start + fb_info.fb_size); 501 page < PAGE_ALIGN((unsigned long)fbdev->fb_mem + fbdev->fb_len);
565 page += PAGE_SIZE) { 502 page += PAGE_SIZE) {
503#if CONFIG_DMA_NONCOHERENT
504 SetPageReserved(virt_to_page(CAC_ADDR(page)));
505#else
566 SetPageReserved(virt_to_page(page)); 506 SetPageReserved(virt_to_page(page));
507#endif
567 } 508 }
568 509
569 memset((void *)fb_info.fb_virt_start, 0, fb_info.fb_size); 510 print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
570 511 print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
571 /* set freqctrl now to allow more time to stabilize */ 512
572 /* zero-out out LCD bits */ 513 /* Setup LCD clock to AUX (48 MHz) */
573 sys_clksrc = au_readl(SYS_CLKSRC) & ~0x000003e0; 514 sys_clksrc = au_readl(SYS_CLKSRC) & ~(SYS_CS_ML_MASK | SYS_CS_DL | SYS_CS_CL);
574 sys_clksrc |= p_lcd->mode_toyclksrc; 515 au_writel((sys_clksrc | (1 << SYS_CS_ML_BIT)), SYS_CLKSRC);
575 au_writel(sys_clksrc, SYS_CLKSRC); 516
576 517 /* load the panel info into the var struct */
577 /* FIXME add check to make sure auxpll is what is expected! */ 518 au1100fb_var.bits_per_pixel = fbdev->panel->bpp;
578 au1100_setmode(); 519 au1100fb_var.xres = fbdev->panel->xres;
579 520 au1100fb_var.xres_virtual = au1100fb_var.xres;
580 fb_info.gen.parsize = sizeof(struct au1100fb_par); 521 au1100fb_var.yres = fbdev->panel->yres;
581 fb_info.gen.fbhw = &au1100_switch; 522 au1100fb_var.yres_virtual = au1100fb_var.yres;
582 523
583 strcpy(fb_info.gen.info.modename, "Au1100 LCD"); 524 fbdev->info.screen_base = fbdev->fb_mem;
584 fb_info.gen.info.changevar = NULL; 525 fbdev->info.fbops = &au1100fb_ops;
585 fb_info.gen.info.node = -1; 526 fbdev->info.fix = au1100fb_fix;
586 527
587 fb_info.gen.info.fbops = &au1100fb_ops; 528 if (!(fbdev->info.pseudo_palette = kmalloc(sizeof(u32) * 16, GFP_KERNEL))) {
588 fb_info.gen.info.disp = &disp; 529 return -ENOMEM;
589 fb_info.gen.info.switch_con = &fbgen_switch; 530 }
590 fb_info.gen.info.updatevar = &fbgen_update_var; 531 memset(fbdev->info.pseudo_palette, 0, sizeof(u32) * 16);
591 fb_info.gen.info.blank = &fbgen_blank; 532
592 fb_info.gen.info.flags = FBINFO_FLAG_DEFAULT; 533 if (fb_alloc_cmap(&fbdev->info.cmap, AU1100_LCD_NBR_PALETTE_ENTRIES, 0) < 0) {
593 534 print_err("Fail to allocate colormap (%d entries)",
594 /* This should give a reasonable default video mode */ 535 AU1100_LCD_NBR_PALETTE_ENTRIES);
595 fbgen_get_var(&disp.var, -1, &fb_info.gen.info); 536 kfree(fbdev->info.pseudo_palette);
596 fbgen_do_set_var(&disp.var, 1, &fb_info.gen); 537 return -EFAULT;
597 fbgen_set_disp(-1, &fb_info.gen); 538 }
598 fbgen_install_cmap(0, &fb_info.gen); 539
599 if (register_framebuffer(&fb_info.gen.info) < 0) 540 fbdev->info.var = au1100fb_var;
600 return -EINVAL; 541
601 printk(KERN_INFO "fb%d: %s frame buffer device\n", 542 /* Set h/w registers */
602 GET_FB_IDX(fb_info.gen.info.node), 543 au1100fb_setmode(fbdev);
603 fb_info.gen.info.modename); 544
545 /* Register new framebuffer */
546 if (register_framebuffer(&fbdev->info) < 0) {
547 print_err("cannot register new framebuffer");
548 goto failed;
549 }
550
551 return 0;
552
553failed:
554 if (fbdev->regs) {
555 release_mem_region(fbdev->regs_phys, fbdev->regs_len);
556 }
557 if (fbdev->fb_mem) {
558 dma_free_noncoherent(dev, fbdev->fb_len, fbdev->fb_mem, fbdev->fb_phys);
559 }
560 if (fbdev->info.cmap.len != 0) {
561 fb_dealloc_cmap(&fbdev->info.cmap);
562 }
563 kfree(fbdev);
564 dev_set_drvdata(dev, NULL);
604 565
605 return 0; 566 return 0;
606} 567}
607 568
569int au1100fb_drv_remove(struct device *dev)
570{
571 struct au1100fb_device *fbdev = NULL;
572
573 if (!dev)
574 return -ENODEV;
575
576 fbdev = (struct au1100fb_device*) dev_get_drvdata(dev);
577
578#if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
579 au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info);
580#endif
581 fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
608 582
609void au1100fb_cleanup(struct fb_info *info) 583 /* Clean up all probe data */
584 unregister_framebuffer(&fbdev->info);
585
586 release_mem_region(fbdev->regs_phys, fbdev->regs_len);
587
588 dma_free_coherent(dev, PAGE_ALIGN(fbdev->fb_len), fbdev->fb_mem, fbdev->fb_phys);
589
590 fb_dealloc_cmap(&fbdev->info.cmap);
591 kfree(fbdev->info.pseudo_palette);
592 kfree((void*)fbdev);
593
594 return 0;
595}
596
597int au1100fb_drv_suspend(struct device *dev, u32 state, u32 level)
598{
599 /* TODO */
600 return 0;
601}
602
603int au1100fb_drv_resume(struct device *dev, u32 level)
610{ 604{
611 unregister_framebuffer(info); 605 /* TODO */
606 return 0;
612} 607}
613 608
609static struct device_driver au1100fb_driver = {
610 .name = "au1100-lcd",
611 .bus = &platform_bus_type,
614 612
615void au1100fb_setup(char *options, int *ints) 613 .probe = au1100fb_drv_probe,
614 .remove = au1100fb_drv_remove,
615 .suspend = au1100fb_drv_suspend,
616 .resume = au1100fb_drv_resume,
617};
618
619/*-------------------------------------------------------------------------*/
620
621/* Kernel driver */
622
623int au1100fb_setup(char *options)
616{ 624{
617 char* this_opt; 625 char* this_opt;
618 int i; 626 int num_panels = ARRAY_SIZE(known_lcd_panels);
619 int num_panels = sizeof(panels)/sizeof(struct known_lcd_panels); 627 char* mode = NULL;
628 int panel_idx = 0;
620 629
630 if (num_panels <= 0) {
631 print_err("No LCD panels supported by driver!");
632 return -EFAULT;
633 }
621 634
622 if (!options || !*options) 635 if (options) {
623 return; 636 while ((this_opt = strsep(&options,",")) != NULL) {
624 637 /* Panel option */
625 for(this_opt=strtok(options, ","); this_opt;
626 this_opt=strtok(NULL, ",")) {
627 if (!strncmp(this_opt, "panel:", 6)) { 638 if (!strncmp(this_opt, "panel:", 6)) {
628#if defined(CONFIG_MIPS_PB1100) || defined(CONFIG_MIPS_DB1100) 639 int i;
629 /* Read Pb1100 Switch S10 ? */ 640 this_opt += 6;
630 if (!strncmp(this_opt+6, "s10", 3)) 641 for (i = 0; i < num_panels; i++) {
631 { 642 if (!strncmp(this_opt,
632 int panel; 643 known_lcd_panels[i].name,
633 panel = *(volatile int *)0xAE000008; /* BCSR SWITCHES */
634 panel >>= 8;
635 panel &= 0x0F;
636 if (panel >= num_panels) panel = 0;
637 my_lcd_index = panel;
638 }
639 else
640#endif
641 /* Get the panel name, everything else if fixed */
642 for (i=0; i<num_panels; i++) {
643 if (!strncmp(this_opt+6, panels[i].panel_name,
644 strlen(this_opt))) { 644 strlen(this_opt))) {
645 my_lcd_index = i; 645 panel_idx = i;
646 break; 646 break;
647 } 647 }
648 } 648 }
649 if (i >= num_panels) {
650 print_warn("Panel %s not supported!", this_opt);
651 }
652 }
653 /* Mode option (only option that start with digit) */
654 else if (isdigit(this_opt[0])) {
655 mode = kmalloc(strlen(this_opt) + 1, GFP_KERNEL);
656 strncpy(mode, this_opt, strlen(this_opt) + 1);
657 }
658 /* Unsupported option */
659 else {
660 print_warn("Unsupported option \"%s\"", this_opt);
649 } 661 }
650 else if (!strncmp(this_opt, "nohwcursor", 10)) {
651 printk("nohwcursor\n");
652 fb_info.nohwcursor = 1;
653 } 662 }
654 } 663 }
655 664
656 printk("au1100fb: Panel %d %s\n", my_lcd_index, 665 drv_info.panel_idx = panel_idx;
657 panels[my_lcd_index].panel_name); 666 drv_info.opt_mode = mode;
658}
659 667
668 print_info("Panel=%s Mode=%s",
669 known_lcd_panels[drv_info.panel_idx].name,
670 drv_info.opt_mode ? drv_info.opt_mode : "default");
660 671
672 return 0;
673}
661 674
662#ifdef MODULE 675int __init au1100fb_init(void)
663MODULE_LICENSE("GPL");
664int init_module(void)
665{ 676{
666 return au1100fb_init(); 677 char* options;
678 int ret;
679
680 print_info("" DRIVER_DESC "");
681
682 memset(&drv_info, 0, sizeof(drv_info));
683
684 if (fb_get_options(DRIVER_NAME, &options))
685 return -ENODEV;
686
687 /* Setup driver with options */
688 ret = au1100fb_setup(options);
689 if (ret < 0) {
690 print_err("Fail to setup driver");
691 return ret;
692 }
693
694 return driver_register(&au1100fb_driver);
667} 695}
668 696
669void cleanup_module(void) 697void __exit au1100fb_cleanup(void)
670{ 698{
671 au1100fb_cleanup(void); 699 driver_unregister(&au1100fb_driver);
700
701 if (drv_info.opt_mode)
702 kfree(drv_info.opt_mode);
672} 703}
673 704
674MODULE_AUTHOR("Pete Popov <ppopov@mvista.com>"); 705module_init(au1100fb_init);
675MODULE_DESCRIPTION("Au1100 LCD framebuffer device driver"); 706module_exit(au1100fb_cleanup);
676#endif /* MODULE */ 707
708MODULE_DESCRIPTION(DRIVER_DESC);
709MODULE_LICENSE("GPL");
diff --git a/drivers/video/au1100fb.h b/drivers/video/au1100fb.h
index 657c560ab73c..2855534dc235 100644
--- a/drivers/video/au1100fb.h
+++ b/drivers/video/au1100fb.h
@@ -30,352 +30,352 @@
30#ifndef _AU1100LCD_H 30#ifndef _AU1100LCD_H
31#define _AU1100LCD_H 31#define _AU1100LCD_H
32 32
33#include <asm/mach-au1x00/au1000.h>
34
35#define print_err(f, arg...) printk(KERN_ERR DRIVER_NAME ": " f "\n", ## arg)
36#define print_warn(f, arg...) printk(KERN_WARNING DRIVER_NAME ": " f "\n", ## arg)
37#define print_info(f, arg...) printk(KERN_INFO DRIVER_NAME ": " f "\n", ## arg)
38
39#if DEBUG
40#define print_dbg(f, arg...) printk(__FILE__ ": " f "\n", ## arg)
41#else
42#define print_dbg(f, arg...) do {} while (0)
43#endif
44
45#if defined(__BIG_ENDIAN)
46#define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_11
47#else
48#define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_00
49#endif
50#define LCD_CONTROL_DEFAULT_SBPPF LCD_CONTROL_SBPPF_565
51
33/********************************************************************/ 52/********************************************************************/
34#define uint32 unsigned long 53
35typedef volatile struct 54/* LCD controller restrictions */
36{ 55#define AU1100_LCD_MAX_XRES 800
37 uint32 lcd_control; 56#define AU1100_LCD_MAX_YRES 600
38 uint32 lcd_intstatus; 57#define AU1100_LCD_MAX_BPP 16
39 uint32 lcd_intenable; 58#define AU1100_LCD_MAX_CLK 48000000
40 uint32 lcd_horztiming; 59#define AU1100_LCD_NBR_PALETTE_ENTRIES 256
41 uint32 lcd_verttiming; 60
42 uint32 lcd_clkcontrol; 61/* Default number of visible screen buffer to allocate */
43 uint32 lcd_dmaaddr0; 62#define AU1100FB_NBR_VIDEO_BUFFERS 4
44 uint32 lcd_dmaaddr1;
45 uint32 lcd_words;
46 uint32 lcd_pwmdiv;
47 uint32 lcd_pwmhi;
48 uint32 reserved[(0x0400-0x002C)/4];
49 uint32 lcd_pallettebase[256];
50
51} AU1100_LCD;
52 63
53/********************************************************************/ 64/********************************************************************/
54 65
55#define AU1100_LCD_ADDR 0xB5000000 66struct au1100fb_panel
67{
68 const char name[25]; /* Full name <vendor>_<model> */
56 69
57/* 70 u32 control_base; /* Mode-independent control values */
58 * Register bit definitions 71 u32 clkcontrol_base; /* Panel pixclock preferences */
59 */
60 72
61/* lcd_control */ 73 u32 horztiming;
62#define LCD_CONTROL_SBPPF (7<<18) 74 u32 verttiming;
63#define LCD_CONTROL_SBPPF_655 (0<<18)
64#define LCD_CONTROL_SBPPF_565 (1<<18)
65#define LCD_CONTROL_SBPPF_556 (2<<18)
66#define LCD_CONTROL_SBPPF_1555 (3<<18)
67#define LCD_CONTROL_SBPPF_5551 (4<<18)
68#define LCD_CONTROL_WP (1<<17)
69#define LCD_CONTROL_WD (1<<16)
70#define LCD_CONTROL_C (1<<15)
71#define LCD_CONTROL_SM (3<<13)
72#define LCD_CONTROL_SM_0 (0<<13)
73#define LCD_CONTROL_SM_90 (1<<13)
74#define LCD_CONTROL_SM_180 (2<<13)
75#define LCD_CONTROL_SM_270 (3<<13)
76#define LCD_CONTROL_DB (1<<12)
77#define LCD_CONTROL_CCO (1<<11)
78#define LCD_CONTROL_DP (1<<10)
79#define LCD_CONTROL_PO (3<<8)
80#define LCD_CONTROL_PO_00 (0<<8)
81#define LCD_CONTROL_PO_01 (1<<8)
82#define LCD_CONTROL_PO_10 (2<<8)
83#define LCD_CONTROL_PO_11 (3<<8)
84#define LCD_CONTROL_MPI (1<<7)
85#define LCD_CONTROL_PT (1<<6)
86#define LCD_CONTROL_PC (1<<5)
87#define LCD_CONTROL_BPP (7<<1)
88#define LCD_CONTROL_BPP_1 (0<<1)
89#define LCD_CONTROL_BPP_2 (1<<1)
90#define LCD_CONTROL_BPP_4 (2<<1)
91#define LCD_CONTROL_BPP_8 (3<<1)
92#define LCD_CONTROL_BPP_12 (4<<1)
93#define LCD_CONTROL_BPP_16 (5<<1)
94#define LCD_CONTROL_GO (1<<0)
95
96/* lcd_intstatus, lcd_intenable */
97#define LCD_INT_SD (1<<7)
98#define LCD_INT_OF (1<<6)
99#define LCD_INT_UF (1<<5)
100#define LCD_INT_SA (1<<3)
101#define LCD_INT_SS (1<<2)
102#define LCD_INT_S1 (1<<1)
103#define LCD_INT_S0 (1<<0)
104
105/* lcd_horztiming */
106#define LCD_HORZTIMING_HN2 (255<<24)
107#define LCD_HORZTIMING_HN2_N(N) (((N)-1)<<24)
108#define LCD_HORZTIMING_HN1 (255<<16)
109#define LCD_HORZTIMING_HN1_N(N) (((N)-1)<<16)
110#define LCD_HORZTIMING_HPW (63<<10)
111#define LCD_HORZTIMING_HPW_N(N) (((N)-1)<<10)
112#define LCD_HORZTIMING_PPL (1023<<0)
113#define LCD_HORZTIMING_PPL_N(N) (((N)-1)<<0)
114
115/* lcd_verttiming */
116#define LCD_VERTTIMING_VN2 (255<<24)
117#define LCD_VERTTIMING_VN2_N(N) (((N)-1)<<24)
118#define LCD_VERTTIMING_VN1 (255<<16)
119#define LCD_VERTTIMING_VN1_N(N) (((N)-1)<<16)
120#define LCD_VERTTIMING_VPW (63<<10)
121#define LCD_VERTTIMING_VPW_N(N) (((N)-1)<<10)
122#define LCD_VERTTIMING_LPP (1023<<0)
123#define LCD_VERTTIMING_LPP_N(N) (((N)-1)<<0)
124
125/* lcd_clkcontrol */
126#define LCD_CLKCONTROL_IB (1<<18)
127#define LCD_CLKCONTROL_IC (1<<17)
128#define LCD_CLKCONTROL_IH (1<<16)
129#define LCD_CLKCONTROL_IV (1<<15)
130#define LCD_CLKCONTROL_BF (31<<10)
131#define LCD_CLKCONTROL_BF_N(N) (((N)-1)<<10)
132#define LCD_CLKCONTROL_PCD (1023<<0)
133#define LCD_CLKCONTROL_PCD_N(N) ((N)<<0)
134
135/* lcd_pwmdiv */
136#define LCD_PWMDIV_EN (1<<12)
137#define LCD_PWMDIV_PWMDIV (2047<<0)
138#define LCD_PWMDIV_PWMDIV_N(N) (((N)-1)<<0)
139
140/* lcd_pwmhi */
141#define LCD_PWMHI_PWMHI1 (2047<<12)
142#define LCD_PWMHI_PWMHI1_N(N) ((N)<<12)
143#define LCD_PWMHI_PWMHI0 (2047<<0)
144#define LCD_PWMHI_PWMHI0_N(N) ((N)<<0)
145
146/* lcd_pallettebase - MONOCHROME */
147#define LCD_PALLETTE_MONO_MI (15<<0)
148#define LCD_PALLETTE_MONO_MI_N(N) ((N)<<0)
149
150/* lcd_pallettebase - COLOR */
151#define LCD_PALLETTE_COLOR_BI (15<<8)
152#define LCD_PALLETTE_COLOR_BI_N(N) ((N)<<8)
153#define LCD_PALLETTE_COLOR_GI (15<<4)
154#define LCD_PALLETTE_COLOR_GI_N(N) ((N)<<4)
155#define LCD_PALLETTE_COLOR_RI (15<<0)
156#define LCD_PALLETTE_COLOR_RI_N(N) ((N)<<0)
157
158/* lcd_palletebase - COLOR TFT PALLETIZED */
159#define LCD_PALLETTE_TFT_DC (65535<<0)
160#define LCD_PALLETTE_TFT_DC_N(N) ((N)<<0)
161 75
162/********************************************************************/ 76 u32 xres; /* Maximum horizontal resolution */
77 u32 yres; /* Maximum vertical resolution */
78 u32 bpp; /* Maximum depth supported */
79};
163 80
164struct known_lcd_panels 81struct au1100fb_regs
165{ 82{
166 uint32 xres; 83 u32 lcd_control;
167 uint32 yres; 84 u32 lcd_intstatus;
168 uint32 bpp; 85 u32 lcd_intenable;
169 unsigned char panel_name[256]; 86 u32 lcd_horztiming;
170 uint32 mode_control; 87 u32 lcd_verttiming;
171 uint32 mode_horztiming; 88 u32 lcd_clkcontrol;
172 uint32 mode_verttiming; 89 u32 lcd_dmaaddr0;
173 uint32 mode_clkcontrol; 90 u32 lcd_dmaaddr1;
174 uint32 mode_pwmdiv; 91 u32 lcd_words;
175 uint32 mode_pwmhi; 92 u32 lcd_pwmdiv;
176 uint32 mode_toyclksrc; 93 u32 lcd_pwmhi;
177 uint32 mode_backlight; 94 u32 reserved[(0x0400-0x002C)/4];
95 u32 lcd_pallettebase[256];
96};
97
98struct au1100fb_device {
99
100 struct fb_info info; /* FB driver info record */
178 101
102 struct au1100fb_panel *panel; /* Panel connected to this device */
103
104 struct au1100fb_regs* regs; /* Registers memory map */
105 size_t regs_len;
106 unsigned int regs_phys;
107
108 unsigned char* fb_mem; /* FrameBuffer memory map */
109 size_t fb_len;
110 dma_addr_t fb_phys;
179}; 111};
180 112
181#if defined(__BIG_ENDIAN) 113/********************************************************************/
182#define LCD_DEFAULT_PIX_FORMAT LCD_CONTROL_PO_11
183#else
184#define LCD_DEFAULT_PIX_FORMAT LCD_CONTROL_PO_00
185#endif
186 114
187/* 115#define LCD_CONTROL (AU1100_LCD_BASE + 0x0)
188 * The fb driver assumes that AUX PLL is at 48MHz. That can 116 #define LCD_CONTROL_SBB_BIT 21
189 * cover up to 800x600 resolution; if you need higher resolution, 117 #define LCD_CONTROL_SBB_MASK (0x3 << LCD_CONTROL_SBB_BIT)
190 * you should modify the driver as needed, not just this structure. 118 #define LCD_CONTROL_SBB_1 (0 << LCD_CONTROL_SBB_BIT)
119 #define LCD_CONTROL_SBB_2 (1 << LCD_CONTROL_SBB_BIT)
120 #define LCD_CONTROL_SBB_3 (2 << LCD_CONTROL_SBB_BIT)
121 #define LCD_CONTROL_SBB_4 (3 << LCD_CONTROL_SBB_BIT)
122 #define LCD_CONTROL_SBPPF_BIT 18
123 #define LCD_CONTROL_SBPPF_MASK (0x7 << LCD_CONTROL_SBPPF_BIT)
124 #define LCD_CONTROL_SBPPF_655 (0 << LCD_CONTROL_SBPPF_BIT)
125 #define LCD_CONTROL_SBPPF_565 (1 << LCD_CONTROL_SBPPF_BIT)
126 #define LCD_CONTROL_SBPPF_556 (2 << LCD_CONTROL_SBPPF_BIT)
127 #define LCD_CONTROL_SBPPF_1555 (3 << LCD_CONTROL_SBPPF_BIT)
128 #define LCD_CONTROL_SBPPF_5551 (4 << LCD_CONTROL_SBPPF_BIT)
129 #define LCD_CONTROL_WP (1<<17)
130 #define LCD_CONTROL_WD (1<<16)
131 #define LCD_CONTROL_C (1<<15)
132 #define LCD_CONTROL_SM_BIT 13
133 #define LCD_CONTROL_SM_MASK (0x3 << LCD_CONTROL_SM_BIT)
134 #define LCD_CONTROL_SM_0 (0 << LCD_CONTROL_SM_BIT)
135 #define LCD_CONTROL_SM_90 (1 << LCD_CONTROL_SM_BIT)
136 #define LCD_CONTROL_SM_180 (2 << LCD_CONTROL_SM_BIT)
137 #define LCD_CONTROL_SM_270 (3 << LCD_CONTROL_SM_BIT)
138 #define LCD_CONTROL_DB (1<<12)
139 #define LCD_CONTROL_CCO (1<<11)
140 #define LCD_CONTROL_DP (1<<10)
141 #define LCD_CONTROL_PO_BIT 8
142 #define LCD_CONTROL_PO_MASK (0x3 << LCD_CONTROL_PO_BIT)
143 #define LCD_CONTROL_PO_00 (0 << LCD_CONTROL_PO_BIT)
144 #define LCD_CONTROL_PO_01 (1 << LCD_CONTROL_PO_BIT)
145 #define LCD_CONTROL_PO_10 (2 << LCD_CONTROL_PO_BIT)
146 #define LCD_CONTROL_PO_11 (3 << LCD_CONTROL_PO_BIT)
147 #define LCD_CONTROL_MPI (1<<7)
148 #define LCD_CONTROL_PT (1<<6)
149 #define LCD_CONTROL_PC (1<<5)
150 #define LCD_CONTROL_BPP_BIT 1
151 #define LCD_CONTROL_BPP_MASK (0x7 << LCD_CONTROL_BPP_BIT)
152 #define LCD_CONTROL_BPP_1 (0 << LCD_CONTROL_BPP_BIT)
153 #define LCD_CONTROL_BPP_2 (1 << LCD_CONTROL_BPP_BIT)
154 #define LCD_CONTROL_BPP_4 (2 << LCD_CONTROL_BPP_BIT)
155 #define LCD_CONTROL_BPP_8 (3 << LCD_CONTROL_BPP_BIT)
156 #define LCD_CONTROL_BPP_12 (4 << LCD_CONTROL_BPP_BIT)
157 #define LCD_CONTROL_BPP_16 (5 << LCD_CONTROL_BPP_BIT)
158 #define LCD_CONTROL_GO (1<<0)
159
160#define LCD_INTSTATUS (AU1100_LCD_BASE + 0x4)
161#define LCD_INTENABLE (AU1100_LCD_BASE + 0x8)
162 #define LCD_INT_SD (1<<7)
163 #define LCD_INT_OF (1<<6)
164 #define LCD_INT_UF (1<<5)
165 #define LCD_INT_SA (1<<3)
166 #define LCD_INT_SS (1<<2)
167 #define LCD_INT_S1 (1<<1)
168 #define LCD_INT_S0 (1<<0)
169
170#define LCD_HORZTIMING (AU1100_LCD_BASE + 0xC)
171 #define LCD_HORZTIMING_HN2_BIT 24
172 #define LCD_HORZTIMING_HN2_MASK (0xFF << LCD_HORZTIMING_HN2_BIT)
173 #define LCD_HORZTIMING_HN2_N(N) ((((N)-1) << LCD_HORZTIMING_HN2_BIT) & LCD_HORZTIMING_HN2_MASK)
174 #define LCD_HORZTIMING_HN1_BIT 16
175 #define LCD_HORZTIMING_HN1_MASK (0xFF << LCD_HORZTIMING_HN1_BIT)
176 #define LCD_HORZTIMING_HN1_N(N) ((((N)-1) << LCD_HORZTIMING_HN1_BIT) & LCD_HORZTIMING_HN1_MASK)
177 #define LCD_HORZTIMING_HPW_BIT 10
178 #define LCD_HORZTIMING_HPW_MASK (0x3F << LCD_HORZTIMING_HPW_BIT)
179 #define LCD_HORZTIMING_HPW_N(N) ((((N)-1) << LCD_HORZTIMING_HPW_BIT) & LCD_HORZTIMING_HPW_MASK)
180 #define LCD_HORZTIMING_PPL_BIT 0
181 #define LCD_HORZTIMING_PPL_MASK (0x3FF << LCD_HORZTIMING_PPL_BIT)
182 #define LCD_HORZTIMING_PPL_N(N) ((((N)-1) << LCD_HORZTIMING_PPL_BIT) & LCD_HORZTIMING_PPL_MASK)
183
184#define LCD_VERTTIMING (AU1100_LCD_BASE + 0x10)
185 #define LCD_VERTTIMING_VN2_BIT 24
186 #define LCD_VERTTIMING_VN2_MASK (0xFF << LCD_VERTTIMING_VN2_BIT)
187 #define LCD_VERTTIMING_VN2_N(N) ((((N)-1) << LCD_VERTTIMING_VN2_BIT) & LCD_VERTTIMING_VN2_MASK)
188 #define LCD_VERTTIMING_VN1_BIT 16
189 #define LCD_VERTTIMING_VN1_MASK (0xFF << LCD_VERTTIMING_VN1_BIT)
190 #define LCD_VERTTIMING_VN1_N(N) ((((N)-1) << LCD_VERTTIMING_VN1_BIT) & LCD_VERTTIMING_VN1_MASK)
191 #define LCD_VERTTIMING_VPW_BIT 10
192 #define LCD_VERTTIMING_VPW_MASK (0x3F << LCD_VERTTIMING_VPW_BIT)
193 #define LCD_VERTTIMING_VPW_N(N) ((((N)-1) << LCD_VERTTIMING_VPW_BIT) & LCD_VERTTIMING_VPW_MASK)
194 #define LCD_VERTTIMING_LPP_BIT 0
195 #define LCD_VERTTIMING_LPP_MASK (0x3FF << LCD_VERTTIMING_LPP_BIT)
196 #define LCD_VERTTIMING_LPP_N(N) ((((N)-1) << LCD_VERTTIMING_LPP_BIT) & LCD_VERTTIMING_LPP_MASK)
197
198#define LCD_CLKCONTROL (AU1100_LCD_BASE + 0x14)
199 #define LCD_CLKCONTROL_IB (1<<18)
200 #define LCD_CLKCONTROL_IC (1<<17)
201 #define LCD_CLKCONTROL_IH (1<<16)
202 #define LCD_CLKCONTROL_IV (1<<15)
203 #define LCD_CLKCONTROL_BF_BIT 10
204 #define LCD_CLKCONTROL_BF_MASK (0x1F << LCD_CLKCONTROL_BF_BIT)
205 #define LCD_CLKCONTROL_BF_N(N) ((((N)-1) << LCD_CLKCONTROL_BF_BIT) & LCD_CLKCONTROL_BF_MASK)
206 #define LCD_CLKCONTROL_PCD_BIT 0
207 #define LCD_CLKCONTROL_PCD_MASK (0x3FF << LCD_CLKCONTROL_PCD_BIT)
208 #define LCD_CLKCONTROL_PCD_N(N) (((N) << LCD_CLKCONTROL_PCD_BIT) & LCD_CLKCONTROL_PCD_MASK)
209
210#define LCD_DMAADDR0 (AU1100_LCD_BASE + 0x18)
211#define LCD_DMAADDR1 (AU1100_LCD_BASE + 0x1C)
212 #define LCD_DMA_SA_BIT 5
213 #define LCD_DMA_SA_MASK (0x7FFFFFF << LCD_DMA_SA_BIT)
214 #define LCD_DMA_SA_N(N) ((N) & LCD_DMA_SA_MASK)
215
216#define LCD_WORDS (AU1100_LCD_BASE + 0x20)
217 #define LCD_WRD_WRDS_BIT 0
218 #define LCD_WRD_WRDS_MASK (0xFFFFFFFF << LCD_WRD_WRDS_BIT)
219 #define LCD_WRD_WRDS_N(N) ((((N)-1) << LCD_WRD_WRDS_BIT) & LCD_WRD_WRDS_MASK)
220
221#define LCD_PWMDIV (AU1100_LCD_BASE + 0x24)
222 #define LCD_PWMDIV_EN (1<<12)
223 #define LCD_PWMDIV_PWMDIV_BIT 0
224 #define LCD_PWMDIV_PWMDIV_MASK (0xFFF << LCD_PWMDIV_PWMDIV_BIT)
225 #define LCD_PWMDIV_PWMDIV_N(N) ((((N)-1) << LCD_PWMDIV_PWMDIV_BIT) & LCD_PWMDIV_PWMDIV_MASK)
226
227#define LCD_PWMHI (AU1100_LCD_BASE + 0x28)
228 #define LCD_PWMHI_PWMHI1_BIT 12
229 #define LCD_PWMHI_PWMHI1_MASK (0xFFF << LCD_PWMHI_PWMHI1_BIT)
230 #define LCD_PWMHI_PWMHI1_N(N) (((N) << LCD_PWMHI_PWMHI1_BIT) & LCD_PWMHI_PWMHI1_MASK)
231 #define LCD_PWMHI_PWMHI0_BIT 0
232 #define LCD_PWMHI_PWMHI0_MASK (0xFFF << LCD_PWMHI_PWMHI0_BIT)
233 #define LCD_PWMHI_PWMHI0_N(N) (((N) << LCD_PWMHI_PWMHI0_BIT) & LCD_PWMHI_PWMHI0_MASK)
234
235#define LCD_PALLETTEBASE (AU1100_LCD_BASE + 0x400)
236 #define LCD_PALLETTE_MONO_MI_BIT 0
237 #define LCD_PALLETTE_MONO_MI_MASK (0xF << LCD_PALLETTE_MONO_MI_BIT)
238 #define LCD_PALLETTE_MONO_MI_N(N) (((N)<< LCD_PALLETTE_MONO_MI_BIT) & LCD_PALLETTE_MONO_MI_MASK)
239
240 #define LCD_PALLETTE_COLOR_RI_BIT 8
241 #define LCD_PALLETTE_COLOR_RI_MASK (0xF << LCD_PALLETTE_COLOR_RI_BIT)
242 #define LCD_PALLETTE_COLOR_RI_N(N) (((N)<< LCD_PALLETTE_COLOR_RI_BIT) & LCD_PALLETTE_COLOR_RI_MASK)
243 #define LCD_PALLETTE_COLOR_GI_BIT 4
244 #define LCD_PALLETTE_COLOR_GI_MASK (0xF << LCD_PALLETTE_COLOR_GI_BIT)
245 #define LCD_PALLETTE_COLOR_GI_N(N) (((N)<< LCD_PALLETTE_COLOR_GI_BIT) & LCD_PALLETTE_COLOR_GI_MASK)
246 #define LCD_PALLETTE_COLOR_BI_BIT 0
247 #define LCD_PALLETTE_COLOR_BI_MASK (0xF << LCD_PALLETTE_COLOR_BI_BIT)
248 #define LCD_PALLETTE_COLOR_BI_N(N) (((N)<< LCD_PALLETTE_COLOR_BI_BIT) & LCD_PALLETTE_COLOR_BI_MASK)
249
250 #define LCD_PALLETTE_TFT_DC_BIT 0
251 #define LCD_PALLETTE_TFT_DC_MASK (0xFFFF << LCD_PALLETTE_TFT_DC_BIT)
252 #define LCD_PALLETTE_TFT_DC_N(N) (((N)<< LCD_PALLETTE_TFT_DC_BIT) & LCD_PALLETTE_TFT_DC_MASK)
253
254/********************************************************************/
255
256/* List of panels known to work with the AU1100 LCD controller.
257 * To add a new panel, enter the same specifications as the
258 * Generic_TFT one, and MAKE SURE that it doesn't conflicts
259 * with the controller restrictions. Restrictions are:
260 *
261 * STN color panels: max_bpp <= 12
262 * STN mono panels: max_bpp <= 4
263 * TFT panels: max_bpp <= 16
264 * max_xres <= 800
265 * max_yres <= 600
191 */ 266 */
192struct known_lcd_panels panels[] = 267static struct au1100fb_panel known_lcd_panels[] =
193{ 268{
194 { /* 0: Pb1100 LCDA: Sharp 320x240 TFT panel */ 269 /* 800x600x16bpp CRT */
195 320, /* xres */ 270 [0] = {
196 240, /* yres */ 271 .name = "CRT_800x600_16",
197 16, /* bpp */ 272 .xres = 800,
198 273 .yres = 600,
199 "Sharp_320x240_16", 274 .bpp = 16,
200 /* mode_control */ 275 .control_base = 0x0004886A |
276 LCD_CONTROL_DEFAULT_PO | LCD_CONTROL_DEFAULT_SBPPF |
277 LCD_CONTROL_BPP_16,
278 .clkcontrol_base = 0x00020000,
279 .horztiming = 0x005aff1f,
280 .verttiming = 0x16000e57,
281 },
282 /* just the standard LCD */
283 [1] = {
284 .name = "WWPC LCD",
285 .xres = 240,
286 .yres = 320,
287 .bpp = 16,
288 .control_base = 0x0006806A,
289 .horztiming = 0x0A1010EF,
290 .verttiming = 0x0301013F,
291 .clkcontrol_base = 0x00018001,
292 },
293 /* Sharp 320x240 TFT panel */
294 [2] = {
295 .name = "Sharp_LQ038Q5DR01",
296 .xres = 320,
297 .yres = 240,
298 .bpp = 16,
299 .control_base =
201 ( LCD_CONTROL_SBPPF_565 300 ( LCD_CONTROL_SBPPF_565
202 /*LCD_CONTROL_WP*/
203 /*LCD_CONTROL_WD*/
204 | LCD_CONTROL_C 301 | LCD_CONTROL_C
205 | LCD_CONTROL_SM_0 302 | LCD_CONTROL_SM_0
206 /*LCD_CONTROL_DB*/ 303 | LCD_CONTROL_DEFAULT_PO
207 /*LCD_CONTROL_CCO*/
208 /*LCD_CONTROL_DP*/
209 | LCD_DEFAULT_PIX_FORMAT
210 /*LCD_CONTROL_MPI*/
211 | LCD_CONTROL_PT 304 | LCD_CONTROL_PT
212 | LCD_CONTROL_PC 305 | LCD_CONTROL_PC
213 | LCD_CONTROL_BPP_16 ), 306 | LCD_CONTROL_BPP_16 ),
214 307 .horztiming =
215 /* mode_horztiming */
216 ( LCD_HORZTIMING_HN2_N(8) 308 ( LCD_HORZTIMING_HN2_N(8)
217 | LCD_HORZTIMING_HN1_N(60) 309 | LCD_HORZTIMING_HN1_N(60)
218 | LCD_HORZTIMING_HPW_N(12) 310 | LCD_HORZTIMING_HPW_N(12)
219 | LCD_HORZTIMING_PPL_N(320) ), 311 | LCD_HORZTIMING_PPL_N(320) ),
220 312 .verttiming =
221 /* mode_verttiming */
222 ( LCD_VERTTIMING_VN2_N(5) 313 ( LCD_VERTTIMING_VN2_N(5)
223 | LCD_VERTTIMING_VN1_N(17) 314 | LCD_VERTTIMING_VN1_N(17)
224 | LCD_VERTTIMING_VPW_N(1) 315 | LCD_VERTTIMING_VPW_N(1)
225 | LCD_VERTTIMING_LPP_N(240) ), 316 | LCD_VERTTIMING_LPP_N(240) ),
226 317 .clkcontrol_base = LCD_CLKCONTROL_PCD_N(1),
227 /* mode_clkcontrol */
228 ( 0
229 /*LCD_CLKCONTROL_IB*/
230 /*LCD_CLKCONTROL_IC*/
231 /*LCD_CLKCONTROL_IH*/
232 /*LCD_CLKCONTROL_IV*/
233 | LCD_CLKCONTROL_PCD_N(1) ),
234
235 /* mode_pwmdiv */
236 0,
237
238 /* mode_pwmhi */
239 0,
240
241 /* mode_toyclksrc */
242 ((1<<7) | (1<<6) | (1<<5)),
243
244 /* mode_backlight */
245 6
246 }, 318 },
247 319
248 { /* 1: Pb1100 LCDC 640x480 TFT panel */ 320 /* Hitachi SP14Q005 and possibly others */
249 640, /* xres */ 321 [3] = {
250 480, /* yres */ 322 .name = "Hitachi_SP14Qxxx",
251 16, /* bpp */ 323 .xres = 320,
252 324 .yres = 240,
253 "Generic_640x480_16", 325 .bpp = 4,
254 326 .control_base =
255 /* mode_control */ 327 ( LCD_CONTROL_C
256 0x004806a | LCD_DEFAULT_PIX_FORMAT, 328 | LCD_CONTROL_BPP_4 ),
257 329 .horztiming =
258 /* mode_horztiming */ 330 ( LCD_HORZTIMING_HN2_N(1)
259 0x3434d67f, 331 | LCD_HORZTIMING_HN1_N(1)
260 332 | LCD_HORZTIMING_HPW_N(1)
261 /* mode_verttiming */ 333 | LCD_HORZTIMING_PPL_N(320) ),
262 0x0e0e39df, 334 .verttiming =
263 335 ( LCD_VERTTIMING_VN2_N(1)
264 /* mode_clkcontrol */ 336 | LCD_VERTTIMING_VN1_N(1)
265 ( 0 337 | LCD_VERTTIMING_VPW_N(1)
266 /*LCD_CLKCONTROL_IB*/ 338 | LCD_VERTTIMING_LPP_N(240) ),
267 /*LCD_CLKCONTROL_IC*/ 339 .clkcontrol_base = LCD_CLKCONTROL_PCD_N(4),
268 /*LCD_CLKCONTROL_IH*/
269 /*LCD_CLKCONTROL_IV*/
270 | LCD_CLKCONTROL_PCD_N(1) ),
271
272 /* mode_pwmdiv */
273 0,
274
275 /* mode_pwmhi */
276 0,
277
278 /* mode_toyclksrc */
279 ((1<<7) | (1<<6) | (0<<5)),
280
281 /* mode_backlight */
282 7
283 }, 340 },
284 341
285 { /* 2: Pb1100 LCDB 640x480 PrimeView TFT panel */ 342 /* Generic 640x480 TFT panel */
286 640, /* xres */ 343 [4] = {
287 480, /* yres */ 344 .name = "TFT_640x480_16",
288 16, /* bpp */ 345 .xres = 640,
289 346 .yres = 480,
290 "PrimeView_640x480_16", 347 .bpp = 16,
291 348 .control_base = 0x004806a | LCD_CONTROL_DEFAULT_PO,
292 /* mode_control */ 349 .horztiming = 0x3434d67f,
293 0x0004886a | LCD_DEFAULT_PIX_FORMAT, 350 .verttiming = 0x0e0e39df,
294 351 .clkcontrol_base = LCD_CLKCONTROL_PCD_N(1),
295 /* mode_horztiming */
296 0x0e4bfe7f,
297
298 /* mode_verttiming */
299 0x210805df,
300
301 /* mode_clkcontrol */
302 0x00038001,
303
304 /* mode_pwmdiv */
305 0,
306
307 /* mode_pwmhi */
308 0,
309
310 /* mode_toyclksrc */
311 ((1<<7) | (1<<6) | (0<<5)),
312
313 /* mode_backlight */
314 7
315 }, 352 },
316 353
317 { /* 3: Pb1100 800x600x16bpp NEON CRT */ 354 /* Pb1100 LCDB 640x480 PrimeView TFT panel */
318 800, /* xres */ 355 [5] = {
319 600, /* yres */ 356 .name = "PrimeView_640x480_16",
320 16, /* bpp */ 357 .xres = 640,
321 358 .yres = 480,
322 "NEON_800x600_16", 359 .bpp = 16,
323 360 .control_base = 0x0004886a | LCD_CONTROL_DEFAULT_PO,
324 /* mode_control */ 361 .horztiming = 0x0e4bfe7f,
325 0x0004886A | LCD_DEFAULT_PIX_FORMAT, 362 .verttiming = 0x210805df,
326 363 .clkcontrol_base = 0x00038001,
327 /* mode_horztiming */
328 0x005AFF1F,
329
330 /* mode_verttiming */
331 0x16000E57,
332
333 /* mode_clkcontrol */
334 0x00020000,
335
336 /* mode_pwmdiv */
337 0,
338
339 /* mode_pwmhi */
340 0,
341
342 /* mode_toyclksrc */
343 ((1<<7) | (1<<6) | (0<<5)),
344
345 /* mode_backlight */
346 7
347 }, 364 },
365};
348 366
349 { /* 4: Pb1100 640x480x16bpp NEON CRT */ 367struct au1100fb_drv_info {
350 640, /* xres */ 368 int panel_idx;
351 480, /* yres */ 369 char *opt_mode;
352 16, /* bpp */ 370};
353
354 "NEON_640x480_16",
355
356 /* mode_control */
357 0x0004886A | LCD_DEFAULT_PIX_FORMAT,
358
359 /* mode_horztiming */
360 0x0052E27F,
361
362 /* mode_verttiming */
363 0x18000DDF,
364
365 /* mode_clkcontrol */
366 0x00020000,
367 371
368 /* mode_pwmdiv */ 372/********************************************************************/
369 0,
370 373
371 /* mode_pwmhi */ 374/* Inline helpers */
372 0,
373 375
374 /* mode_toyclksrc */ 376#define panel_is_dual(panel) (panel->control_base & LCD_CONTROL_DP)
375 ((1<<7) | (1<<6) | (0<<5)), 377#define panel_is_active(panel)(panel->control_base & LCD_CONTROL_PT)
378#define panel_is_color(panel) (panel->control_base & LCD_CONTROL_PC)
379#define panel_swap_rgb(panel) (panel->control_base & LCD_CONTROL_CCO)
376 380
377 /* mode_backlight */
378 7
379 },
380};
381#endif /* _AU1100LCD_H */ 381#endif /* _AU1100LCD_H */
diff --git a/drivers/video/backlight/corgi_bl.c b/drivers/video/backlight/corgi_bl.c
index 3c72c627e65e..1991fdb32dfb 100644
--- a/drivers/video/backlight/corgi_bl.c
+++ b/drivers/video/backlight/corgi_bl.c
@@ -73,17 +73,15 @@ static void corgibl_blank(int blank)
73} 73}
74 74
75#ifdef CONFIG_PM 75#ifdef CONFIG_PM
76static int corgibl_suspend(struct device *dev, pm_message_t state, u32 level) 76static int corgibl_suspend(struct device *dev, pm_message_t state)
77{ 77{
78 if (level == SUSPEND_POWER_DOWN) 78 corgibl_blank(FB_BLANK_POWERDOWN);
79 corgibl_blank(FB_BLANK_POWERDOWN);
80 return 0; 79 return 0;
81} 80}
82 81
83static int corgibl_resume(struct device *dev, u32 level) 82static int corgibl_resume(struct device *dev)
84{ 83{
85 if (level == RESUME_POWER_ON) 84 corgibl_blank(FB_BLANK_UNBLANK);
86 corgibl_blank(FB_BLANK_UNBLANK);
87 return 0; 85 return 0;
88} 86}
89#else 87#else
diff --git a/drivers/video/cirrusfb.c b/drivers/video/cirrusfb.c
index a3040429c27b..3a26f9cc8585 100644
--- a/drivers/video/cirrusfb.c
+++ b/drivers/video/cirrusfb.c
@@ -275,20 +275,20 @@ static const struct cirrusfb_board_info_rec {
275 275
276#ifdef CONFIG_PCI 276#ifdef CONFIG_PCI
277#define CHIP(id, btype) \ 277#define CHIP(id, btype) \
278 { PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_##id, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (btype) } 278 { PCI_VENDOR_ID_CIRRUS, id, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (btype) }
279 279
280static struct pci_device_id cirrusfb_pci_table[] = { 280static struct pci_device_id cirrusfb_pci_table[] = {
281 CHIP( CIRRUS_5436, BT_ALPINE ), 281 CHIP( PCI_DEVICE_ID_CIRRUS_5436, BT_ALPINE ),
282 CHIP( CIRRUS_5434_8, BT_ALPINE ), 282 CHIP( PCI_DEVICE_ID_CIRRUS_5434_8, BT_ALPINE ),
283 CHIP( CIRRUS_5434_4, BT_ALPINE ), 283 CHIP( PCI_DEVICE_ID_CIRRUS_5434_4, BT_ALPINE ),
284 CHIP( CIRRUS_5430, BT_ALPINE ), /* GD-5440 has identical id */ 284 CHIP( PCI_DEVICE_ID_CIRRUS_5430, BT_ALPINE ), /* GD-5440 is same id */
285 CHIP( CIRRUS_7543, BT_ALPINE ), 285 CHIP( PCI_DEVICE_ID_CIRRUS_7543, BT_ALPINE ),
286 CHIP( CIRRUS_7548, BT_ALPINE ), 286 CHIP( PCI_DEVICE_ID_CIRRUS_7548, BT_ALPINE ),
287 CHIP( CIRRUS_5480, BT_GD5480 ), /* MacPicasso probably */ 287 CHIP( PCI_DEVICE_ID_CIRRUS_5480, BT_GD5480 ), /* MacPicasso likely */
288 CHIP( CIRRUS_5446, BT_PICASSO4 ), /* Picasso 4 is a GD5446 */ 288 CHIP( PCI_DEVICE_ID_CIRRUS_5446, BT_PICASSO4 ), /* Picasso 4 is 5446 */
289 CHIP( CIRRUS_5462, BT_LAGUNA ), /* CL Laguna */ 289 CHIP( PCI_DEVICE_ID_CIRRUS_5462, BT_LAGUNA ), /* CL Laguna */
290 CHIP( CIRRUS_5464, BT_LAGUNA ), /* CL Laguna 3D */ 290 CHIP( PCI_DEVICE_ID_CIRRUS_5464, BT_LAGUNA ), /* CL Laguna 3D */
291 CHIP( CIRRUS_5465, BT_LAGUNA ), /* CL Laguna 3DA*/ 291 CHIP( PCI_DEVICE_ID_CIRRUS_5465, BT_LAGUNA ), /* CL Laguna 3DA*/
292 { 0, } 292 { 0, }
293}; 293};
294MODULE_DEVICE_TABLE(pci, cirrusfb_pci_table); 294MODULE_DEVICE_TABLE(pci, cirrusfb_pci_table);
diff --git a/drivers/video/console/Kconfig b/drivers/video/console/Kconfig
index eb83a7874c71..6a9ae2b3d1ab 100644
--- a/drivers/video/console/Kconfig
+++ b/drivers/video/console/Kconfig
@@ -28,7 +28,7 @@ config VGA_CONSOLE
28 28
29config VIDEO_SELECT 29config VIDEO_SELECT
30 bool "Video mode selection support" 30 bool "Video mode selection support"
31 depends on (X86 || X86_64) && VGA_CONSOLE 31 depends on X86 && VGA_CONSOLE
32 ---help--- 32 ---help---
33 This enables support for text mode selection on kernel startup. If 33 This enables support for text mode selection on kernel startup. If
34 you want to take advantage of some high-resolution text mode your 34 you want to take advantage of some high-resolution text mode your
@@ -110,7 +110,7 @@ config STI_CONSOLE
110 110
111config FONTS 111config FONTS
112 bool "Select compiled-in fonts" 112 bool "Select compiled-in fonts"
113 depends on FRAMEBUFFER_CONSOLE 113 depends on FRAMEBUFFER_CONSOLE || STI_CONSOLE
114 help 114 help
115 Say Y here if you would like to use fonts other than the default 115 Say Y here if you would like to use fonts other than the default
116 your frame buffer console usually use. 116 your frame buffer console usually use.
@@ -123,7 +123,7 @@ config FONTS
123 123
124config FONT_8x8 124config FONT_8x8
125 bool "VGA 8x8 font" if FONTS 125 bool "VGA 8x8 font" if FONTS
126 depends on FRAMEBUFFER_CONSOLE 126 depends on FRAMEBUFFER_CONSOLE || STI_CONSOLE
127 default y if !SPARC32 && !SPARC64 && !FONTS 127 default y if !SPARC32 && !SPARC64 && !FONTS
128 help 128 help
129 This is the "high resolution" font for the VGA frame buffer (the one 129 This is the "high resolution" font for the VGA frame buffer (the one
@@ -137,7 +137,7 @@ config FONT_8x8
137 137
138config FONT_8x16 138config FONT_8x16
139 bool "VGA 8x16 font" if FONTS 139 bool "VGA 8x16 font" if FONTS
140 depends on FRAMEBUFFER_CONSOLE || SGI_NEWPORT_CONSOLE=y || USB_SISUSBVGA_CON 140 depends on FRAMEBUFFER_CONSOLE || SGI_NEWPORT_CONSOLE=y || STI_CONSOLE || USB_SISUSBVGA_CON
141 default y if !SPARC32 && !SPARC64 && !FONTS 141 default y if !SPARC32 && !SPARC64 && !FONTS
142 help 142 help
143 This is the "high resolution" font for the VGA frame buffer (the one 143 This is the "high resolution" font for the VGA frame buffer (the one
@@ -147,7 +147,7 @@ config FONT_8x16
147 147
148config FONT_6x11 148config FONT_6x11
149 bool "Mac console 6x11 font (not supported by all drivers)" if FONTS 149 bool "Mac console 6x11 font (not supported by all drivers)" if FONTS
150 depends on FRAMEBUFFER_CONSOLE 150 depends on FRAMEBUFFER_CONSOLE || STI_CONSOLE
151 default y if !SPARC32 && !SPARC64 && !FONTS && MAC 151 default y if !SPARC32 && !SPARC64 && !FONTS && MAC
152 help 152 help
153 Small console font with Macintosh-style high-half glyphs. Some Mac 153 Small console font with Macintosh-style high-half glyphs. Some Mac
diff --git a/drivers/video/console/newport_con.c b/drivers/video/console/newport_con.c
index e793ffd39db5..762c7a593141 100644
--- a/drivers/video/console/newport_con.c
+++ b/drivers/video/console/newport_con.c
@@ -32,7 +32,6 @@
32#include <linux/font.h> 32#include <linux/font.h>
33 33
34 34
35extern struct font_desc font_vga_8x16;
36extern unsigned long sgi_gfxaddr; 35extern unsigned long sgi_gfxaddr;
37 36
38#define FONT_DATA ((unsigned char *)font_vga_8x16.data) 37#define FONT_DATA ((unsigned char *)font_vga_8x16.data)
diff --git a/drivers/video/console/sticore.c b/drivers/video/console/sticore.c
index d940f605acb6..a7bcd17112c0 100644
--- a/drivers/video/console/sticore.c
+++ b/drivers/video/console/sticore.c
@@ -511,12 +511,12 @@ sti_select_fbfont( struct sti_cooked_rom *cooked_rom, char *fbfont_name )
511 struct sti_cooked_font *cooked_font; 511 struct sti_cooked_font *cooked_font;
512 512
513 if (!fbfont_name || !strlen(fbfont_name)) 513 if (!fbfont_name || !strlen(fbfont_name))
514 return NULL; 514 return NULL;
515 fbfont = find_font(fbfont_name); 515 fbfont = find_font(fbfont_name);
516 if (!fbfont) 516 if (!fbfont)
517 fbfont = get_default_font(1024,768); 517 fbfont = get_default_font(1024,768);
518 if (!fbfont) 518 if (!fbfont)
519 return NULL; 519 return NULL;
520 520
521 DPRINTK((KERN_DEBUG "selected %dx%d fb-font %s\n", 521 DPRINTK((KERN_DEBUG "selected %dx%d fb-font %s\n",
522 fbfont->width, fbfont->height, fbfont->name)); 522 fbfont->width, fbfont->height, fbfont->name));
@@ -527,7 +527,7 @@ sti_select_fbfont( struct sti_cooked_rom *cooked_rom, char *fbfont_name )
527 527
528 nf = kmalloc(size, GFP_KERNEL); 528 nf = kmalloc(size, GFP_KERNEL);
529 if (!nf) 529 if (!nf)
530 return NULL; 530 return NULL;
531 memset(nf, 0, size); 531 memset(nf, 0, size);
532 532
533 nf->first_char = 0; 533 nf->first_char = 0;
@@ -546,8 +546,8 @@ sti_select_fbfont( struct sti_cooked_rom *cooked_rom, char *fbfont_name )
546 546
547 cooked_font = kmalloc(sizeof(*cooked_font), GFP_KERNEL); 547 cooked_font = kmalloc(sizeof(*cooked_font), GFP_KERNEL);
548 if (!cooked_font) { 548 if (!cooked_font) {
549 kfree(nf); 549 kfree(nf);
550 return NULL; 550 return NULL;
551 } 551 }
552 552
553 cooked_font->raw = nf; 553 cooked_font->raw = nf;
@@ -595,7 +595,7 @@ sti_select_font(struct sti_cooked_rom *rom,
595static void __init 595static void __init
596sti_dump_rom(struct sti_rom *rom) 596sti_dump_rom(struct sti_rom *rom)
597{ 597{
598 printk(KERN_INFO " id %04x-%04x, conforms to spec rev. %d.%02x\n", 598 printk(KERN_INFO " id %04x-%04x, conforms to spec rev. %d.%02x\n",
599 rom->graphics_id[0], 599 rom->graphics_id[0],
600 rom->graphics_id[1], 600 rom->graphics_id[1],
601 rom->revno[0] >> 4, 601 rom->revno[0] >> 4,
@@ -651,15 +651,16 @@ sti_search_font(struct sti_cooked_rom *rom, int height, int width)
651 struct sti_cooked_font *font; 651 struct sti_cooked_font *font;
652 int i = 0; 652 int i = 0;
653 653
654 for(font = rom->font_start; font; font = font->next_font, i++) { 654 for (font = rom->font_start; font; font = font->next_font, i++) {
655 if((font->raw->width == width) && (font->raw->height == height)) 655 if ((font->raw->width == width) &&
656 (font->raw->height == height))
656 return i; 657 return i;
657 } 658 }
658 return 0; 659 return 0;
659} 660}
660 661
661#define BMODE_RELOCATE(offset) offset = (offset) / 4; 662#define BMODE_RELOCATE(offset) offset = (offset) / 4;
662#define BMODE_LAST_ADDR_OFFS 0x50 663#define BMODE_LAST_ADDR_OFFS 0x50
663 664
664static void * __init 665static void * __init
665sti_bmode_font_raw(struct sti_cooked_font *f) 666sti_bmode_font_raw(struct sti_cooked_font *f)
@@ -700,35 +701,35 @@ sti_get_bmode_rom (unsigned long address)
700{ 701{
701 struct sti_rom *raw; 702 struct sti_rom *raw;
702 u32 size; 703 u32 size;
703 struct sti_rom_font *raw_font, *font_start; 704 struct sti_rom_font *raw_font, *font_start;
704 705
705 sti_bmode_rom_copy(address + BMODE_LAST_ADDR_OFFS, sizeof(size), &size); 706 sti_bmode_rom_copy(address + BMODE_LAST_ADDR_OFFS, sizeof(size), &size);
706 707
707 size = (size+3) / 4; 708 size = (size+3) / 4;
708 raw = kmalloc(size, GFP_KERNEL); 709 raw = kmalloc(size, GFP_KERNEL);
709 if (raw) { 710 if (raw) {
710 sti_bmode_rom_copy(address, size, raw); 711 sti_bmode_rom_copy(address, size, raw);
711 memmove (&raw->res004, &raw->type[0], 0x3c); 712 memmove (&raw->res004, &raw->type[0], 0x3c);
712 raw->type[3] = raw->res004; 713 raw->type[3] = raw->res004;
713 714
714 BMODE_RELOCATE (raw->region_list); 715 BMODE_RELOCATE (raw->region_list);
715 BMODE_RELOCATE (raw->font_start); 716 BMODE_RELOCATE (raw->font_start);
716 717
717 BMODE_RELOCATE (raw->init_graph); 718 BMODE_RELOCATE (raw->init_graph);
718 BMODE_RELOCATE (raw->state_mgmt); 719 BMODE_RELOCATE (raw->state_mgmt);
719 BMODE_RELOCATE (raw->font_unpmv); 720 BMODE_RELOCATE (raw->font_unpmv);
720 BMODE_RELOCATE (raw->block_move); 721 BMODE_RELOCATE (raw->block_move);
721 BMODE_RELOCATE (raw->inq_conf); 722 BMODE_RELOCATE (raw->inq_conf);
722 723
723 raw_font = ((void *)raw) + raw->font_start; 724 raw_font = ((void *)raw) + raw->font_start;
724 font_start = raw_font; 725 font_start = raw_font;
725 726
726 while (raw_font->next_font) { 727 while (raw_font->next_font) {
727 BMODE_RELOCATE (raw_font->next_font); 728 BMODE_RELOCATE (raw_font->next_font);
728 raw_font = ((void *)font_start) + raw_font->next_font; 729 raw_font = ((void *)font_start) + raw_font->next_font;
729 } 730 }
730 } 731 }
731 return raw; 732 return raw;
732} 733}
733 734
734struct sti_rom * __init 735struct sti_rom * __init
@@ -736,15 +737,15 @@ sti_get_wmode_rom (unsigned long address)
736{ 737{
737 struct sti_rom *raw; 738 struct sti_rom *raw;
738 unsigned long size; 739 unsigned long size;
739 740
740 /* read the ROM size directly from the struct in ROM */ 741 /* read the ROM size directly from the struct in ROM */
741 size = gsc_readl(address + offsetof(struct sti_rom,last_addr)); 742 size = gsc_readl(address + offsetof(struct sti_rom,last_addr));
742 743
743 raw = kmalloc(size, GFP_KERNEL); 744 raw = kmalloc(size, GFP_KERNEL);
744 if(raw) 745 if (raw)
745 sti_rom_copy(address, size, raw); 746 sti_rom_copy(address, size, raw);
746 747
747 return raw; 748 return raw;
748} 749}
749 750
750int __init 751int __init
@@ -757,14 +758,14 @@ sti_read_rom(int wordmode, struct sti_struct *sti, unsigned long address)
757 if (!cooked) 758 if (!cooked)
758 goto out_err; 759 goto out_err;
759 760
760 if (wordmode) 761 if (wordmode)
761 raw = sti_get_wmode_rom (address); 762 raw = sti_get_wmode_rom (address);
762 else 763 else
763 raw = sti_get_bmode_rom (address); 764 raw = sti_get_bmode_rom (address);
765
766 if (!raw)
767 goto out_err;
764 768
765 if (!raw)
766 goto out_err;
767
768 if (!sti_cook_fonts(cooked, raw)) { 769 if (!sti_cook_fonts(cooked, raw)) {
769 printk(KERN_ERR "No font found for STI at %08lx\n", address); 770 printk(KERN_ERR "No font found for STI at %08lx\n", address);
770 goto out_err; 771 goto out_err;
@@ -787,7 +788,7 @@ sti_read_rom(int wordmode, struct sti_struct *sti, unsigned long address)
787 sti->font_width = sti->font->raw->width; 788 sti->font_width = sti->font->raw->width;
788 sti->font_height = sti->font->raw->height; 789 sti->font_height = sti->font->raw->height;
789 if (!wordmode) 790 if (!wordmode)
790 sti->font->raw = sti_bmode_font_raw(sti->font); 791 sti->font->raw = sti_bmode_font_raw(sti->font);
791 792
792 sti->sti_mem_request = raw->sti_mem_req; 793 sti->sti_mem_request = raw->sti_mem_req;
793 sti->graphics_id[0] = raw->graphics_id[0]; 794 sti->graphics_id[0] = raw->graphics_id[0];
@@ -811,16 +812,16 @@ sti_try_rom_generic(unsigned long address, unsigned long hpa, struct pci_dev *pd
811 u32 sig; 812 u32 sig;
812 813
813 if (num_sti_roms >= MAX_STI_ROMS) { 814 if (num_sti_roms >= MAX_STI_ROMS) {
814 printk(KERN_WARNING "maximum number of STI ROMS reached !\n"); 815 printk(KERN_WARNING "maximum number of STI ROMS reached !\n");
815 return NULL; 816 return NULL;
816 } 817 }
817 818
818 sti = kmalloc(sizeof(*sti), GFP_KERNEL); 819 sti = kmalloc(sizeof(*sti), GFP_KERNEL);
819 if (!sti) { 820 if (!sti) {
820 printk(KERN_ERR "Not enough memory !\n"); 821 printk(KERN_ERR "Not enough memory !\n");
821 return NULL; 822 return NULL;
822 } 823 }
823 824
824 memset(sti, 0, sizeof(*sti)); 825 memset(sti, 0, sizeof(*sti));
825 spin_lock_init(&sti->lock); 826 spin_lock_init(&sti->lock);
826 827
@@ -932,28 +933,21 @@ static void __init sticore_check_for_default_sti(struct sti_struct *sti, char *p
932 */ 933 */
933static int __init sticore_pa_init(struct parisc_device *dev) 934static int __init sticore_pa_init(struct parisc_device *dev)
934{ 935{
935 unsigned long rom = 0;
936 char pa_path[21]; 936 char pa_path[21];
937 struct sti_struct *sti = NULL; 937 struct sti_struct *sti = NULL;
938 938 int hpa = dev->hpa.start;
939 if(dev->num_addrs) { 939
940 rom = dev->addr[0]; 940 if (dev->num_addrs && dev->addr[0])
941 } 941 sti = sti_try_rom_generic(dev->addr[0], hpa, NULL);
942 if (!rom) { 942 if (!sti)
943 rom = dev->hpa; 943 sti = sti_try_rom_generic(hpa, hpa, NULL);
944 DPRINTK((KERN_DEBUG "Trying STI ROM at %08lx, hpa at %08lx\n", rom, dev->hpa)); 944 if (!sti)
945 sti = sti_try_rom_generic(rom, dev->hpa, NULL); 945 sti = sti_try_rom_generic(PAGE0->proc_sti, hpa, NULL);
946 rom = PAGE0->proc_sti;
947 }
948 if (!sti) {
949 DPRINTK((KERN_DEBUG "Trying STI ROM at %08lx, hpa at %08lx\n", rom, dev->hpa));
950 sti = sti_try_rom_generic(rom, dev->hpa, NULL);
951 }
952 if (!sti) 946 if (!sti)
953 return 1; 947 return 1;
954 948
955 print_pa_hwpath(dev, pa_path); 949 print_pa_hwpath(dev, pa_path);
956 sticore_check_for_default_sti (sti, pa_path); 950 sticore_check_for_default_sti(sti, pa_path);
957 return 0; 951 return 0;
958} 952}
959 953
diff --git a/drivers/video/console/vgacon.c b/drivers/video/console/vgacon.c
index 809fee2140ac..56cd199605f4 100644
--- a/drivers/video/console/vgacon.c
+++ b/drivers/video/console/vgacon.c
@@ -579,6 +579,7 @@ static void vga_set_palette(struct vc_data *vc, unsigned char *table)
579{ 579{
580 int i, j; 580 int i, j;
581 581
582 vga_w(state.vgabase, VGA_PEL_MSK, 0xff);
582 for (i = j = 0; i < 16; i++) { 583 for (i = j = 0; i < 16; i++) {
583 vga_w(state.vgabase, VGA_PEL_IW, table[i]); 584 vga_w(state.vgabase, VGA_PEL_IW, table[i]);
584 vga_w(state.vgabase, VGA_PEL_D, vc->vc_palette[j++] >> 2); 585 vga_w(state.vgabase, VGA_PEL_D, vc->vc_palette[j++] >> 2);
@@ -721,6 +722,7 @@ static void vga_pal_blank(struct vgastate *state)
721{ 722{
722 int i; 723 int i;
723 724
725 vga_w(state->vgabase, VGA_PEL_MSK, 0xff);
724 for (i = 0; i < 16; i++) { 726 for (i = 0; i < 16; i++) {
725 vga_w(state->vgabase, VGA_PEL_IW, i); 727 vga_w(state->vgabase, VGA_PEL_IW, i);
726 vga_w(state->vgabase, VGA_PEL_D, 0); 728 vga_w(state->vgabase, VGA_PEL_D, 0);
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index ca02aa2bfcec..e2667ddab3f1 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -1031,7 +1031,7 @@ register_framebuffer(struct fb_info *fb_info)
1031 break; 1031 break;
1032 fb_info->node = i; 1032 fb_info->node = i;
1033 1033
1034 fb_info->class_device = class_device_create(fb_class, MKDEV(FB_MAJOR, i), 1034 fb_info->class_device = class_device_create(fb_class, NULL, MKDEV(FB_MAJOR, i),
1035 fb_info->device, "fb%d", i); 1035 fb_info->device, "fb%d", i);
1036 if (IS_ERR(fb_info->class_device)) { 1036 if (IS_ERR(fb_info->class_device)) {
1037 /* Not fatal */ 1037 /* Not fatal */
diff --git a/drivers/video/gbefb.c b/drivers/video/gbefb.c
index d3c1922cb13a..485604cd4462 100644
--- a/drivers/video/gbefb.c
+++ b/drivers/video/gbefb.c
@@ -1126,7 +1126,7 @@ static int __init gbefb_probe(struct device *dev)
1126 gbefb_setup(options); 1126 gbefb_setup(options);
1127#endif 1127#endif
1128 1128
1129 if (!request_mem_region(GBE_BASE, sizeof(struct sgi_gbe), "GBE")) { 1129 if (!request_region(GBE_BASE, sizeof(struct sgi_gbe), "GBE")) {
1130 printk(KERN_ERR "gbefb: couldn't reserve mmio region\n"); 1130 printk(KERN_ERR "gbefb: couldn't reserve mmio region\n");
1131 ret = -EBUSY; 1131 ret = -EBUSY;
1132 goto out_release_framebuffer; 1132 goto out_release_framebuffer;
@@ -1152,12 +1152,24 @@ static int __init gbefb_probe(struct device *dev)
1152 if (gbe_mem_phys) { 1152 if (gbe_mem_phys) {
1153 /* memory was allocated at boot time */ 1153 /* memory was allocated at boot time */
1154 gbe_mem = ioremap_nocache(gbe_mem_phys, gbe_mem_size); 1154 gbe_mem = ioremap_nocache(gbe_mem_phys, gbe_mem_size);
1155 if (!gbe_mem) {
1156 printk(KERN_ERR "gbefb: couldn't map framebuffer\n");
1157 ret = -ENOMEM;
1158 goto out_tiles_free;
1159 }
1160
1155 gbe_dma_addr = 0; 1161 gbe_dma_addr = 0;
1156 } else { 1162 } else {
1157 /* try to allocate memory with the classical allocator 1163 /* try to allocate memory with the classical allocator
1158 * this has high chance to fail on low memory machines */ 1164 * this has high chance to fail on low memory machines */
1159 gbe_mem = dma_alloc_coherent(NULL, gbe_mem_size, &gbe_dma_addr, 1165 gbe_mem = dma_alloc_coherent(NULL, gbe_mem_size, &gbe_dma_addr,
1160 GFP_KERNEL); 1166 GFP_KERNEL);
1167 if (!gbe_mem) {
1168 printk(KERN_ERR "gbefb: couldn't allocate framebuffer memory\n");
1169 ret = -ENOMEM;
1170 goto out_tiles_free;
1171 }
1172
1161 gbe_mem_phys = (unsigned long) gbe_dma_addr; 1173 gbe_mem_phys = (unsigned long) gbe_dma_addr;
1162 } 1174 }
1163 1175
@@ -1165,12 +1177,6 @@ static int __init gbefb_probe(struct device *dev)
1165 mtrr_add(gbe_mem_phys, gbe_mem_size, MTRR_TYPE_WRCOMB, 1); 1177 mtrr_add(gbe_mem_phys, gbe_mem_size, MTRR_TYPE_WRCOMB, 1);
1166#endif 1178#endif
1167 1179
1168 if (!gbe_mem) {
1169 printk(KERN_ERR "gbefb: couldn't map framebuffer\n");
1170 ret = -ENXIO;
1171 goto out_tiles_free;
1172 }
1173
1174 /* map framebuffer memory into tiles table */ 1180 /* map framebuffer memory into tiles table */
1175 for (i = 0; i < (gbe_mem_size >> TILE_SHIFT); i++) 1181 for (i = 0; i < (gbe_mem_size >> TILE_SHIFT); i++)
1176 gbe_tiles.cpu[i] = (gbe_mem_phys >> TILE_SHIFT) + i; 1182 gbe_tiles.cpu[i] = (gbe_mem_phys >> TILE_SHIFT) + i;
diff --git a/drivers/video/imxfb.c b/drivers/video/imxfb.c
index 1d54d3d6960b..0b9301facbd3 100644
--- a/drivers/video/imxfb.c
+++ b/drivers/video/imxfb.c
@@ -424,23 +424,21 @@ static void imxfb_setup_gpio(struct imxfb_info *fbi)
424 * Power management hooks. Note that we won't be called from IRQ context, 424 * Power management hooks. Note that we won't be called from IRQ context,
425 * unlike the blank functions above, so we may sleep. 425 * unlike the blank functions above, so we may sleep.
426 */ 426 */
427static int imxfb_suspend(struct device *dev, pm_message_t state, u32 level) 427static int imxfb_suspend(struct device *dev, pm_message_t state)
428{ 428{
429 struct imxfb_info *fbi = dev_get_drvdata(dev); 429 struct imxfb_info *fbi = dev_get_drvdata(dev);
430 pr_debug("%s\n",__FUNCTION__); 430 pr_debug("%s\n",__FUNCTION__);
431 431
432 if (level == SUSPEND_DISABLE || level == SUSPEND_POWER_DOWN) 432 imxfb_disable_controller(fbi);
433 imxfb_disable_controller(fbi);
434 return 0; 433 return 0;
435} 434}
436 435
437static int imxfb_resume(struct device *dev, u32 level) 436static int imxfb_resume(struct device *dev)
438{ 437{
439 struct imxfb_info *fbi = dev_get_drvdata(dev); 438 struct imxfb_info *fbi = dev_get_drvdata(dev);
440 pr_debug("%s\n",__FUNCTION__); 439 pr_debug("%s\n",__FUNCTION__);
441 440
442 if (level == RESUME_ENABLE) 441 imxfb_enable_controller(fbi);
443 imxfb_enable_controller(fbi);
444 return 0; 442 return 0;
445} 443}
446#else 444#else
diff --git a/drivers/video/pxafb.c b/drivers/video/pxafb.c
index 194eed0a238c..6206da9dd5da 100644
--- a/drivers/video/pxafb.c
+++ b/drivers/video/pxafb.c
@@ -981,21 +981,19 @@ pxafb_freq_policy(struct notifier_block *nb, unsigned long val, void *data)
981 * Power management hooks. Note that we won't be called from IRQ context, 981 * Power management hooks. Note that we won't be called from IRQ context,
982 * unlike the blank functions above, so we may sleep. 982 * unlike the blank functions above, so we may sleep.
983 */ 983 */
984static int pxafb_suspend(struct device *dev, pm_message_t state, u32 level) 984static int pxafb_suspend(struct device *dev, pm_message_t state)
985{ 985{
986 struct pxafb_info *fbi = dev_get_drvdata(dev); 986 struct pxafb_info *fbi = dev_get_drvdata(dev);
987 987
988 if (level == SUSPEND_DISABLE || level == SUSPEND_POWER_DOWN) 988 set_ctrlr_state(fbi, C_DISABLE_PM);
989 set_ctrlr_state(fbi, C_DISABLE_PM);
990 return 0; 989 return 0;
991} 990}
992 991
993static int pxafb_resume(struct device *dev, u32 level) 992static int pxafb_resume(struct device *dev)
994{ 993{
995 struct pxafb_info *fbi = dev_get_drvdata(dev); 994 struct pxafb_info *fbi = dev_get_drvdata(dev);
996 995
997 if (level == RESUME_ENABLE) 996 set_ctrlr_state(fbi, C_ENABLE_PM);
998 set_ctrlr_state(fbi, C_ENABLE_PM);
999 return 0; 997 return 0;
1000} 998}
1001#else 999#else
diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
index fa98d91c42eb..cb2f7a1de947 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, pm_message_t state, u32 level) 658static int s1d13xxxfb_suspend(struct device *dev, pm_message_t state)
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;
@@ -702,15 +702,12 @@ static int s1d13xxxfb_suspend(struct device *dev, pm_message_t state, u32 level)
702 return 0; 702 return 0;
703} 703}
704 704
705static int s1d13xxxfb_resume(struct device *dev, u32 level) 705static int s1d13xxxfb_resume(struct device *dev)
706{ 706{
707 struct fb_info *info = dev_get_drvdata(dev); 707 struct fb_info *info = dev_get_drvdata(dev);
708 struct s1d13xxxfb_par *s1dfb = info->par; 708 struct s1d13xxxfb_par *s1dfb = info->par;
709 struct s1d13xxxfb_pdata *pdata = NULL; 709 struct s1d13xxxfb_pdata *pdata = NULL;
710 710
711 if (level != RESUME_ENABLE)
712 return 0;
713
714 /* awaken the chip */ 711 /* awaken the chip */
715 s1d13xxxfb_writereg(s1dfb, S1DREG_PS_CNF, 0x10); 712 s1d13xxxfb_writereg(s1dfb, S1DREG_PS_CNF, 0x10);
716 713
diff --git a/drivers/video/s3c2410fb.c b/drivers/video/s3c2410fb.c
index 5ab79afb53b7..3862d3cb1fb2 100644
--- a/drivers/video/s3c2410fb.c
+++ b/drivers/video/s3c2410fb.c
@@ -847,37 +847,32 @@ static int s3c2410fb_remove(struct device *dev)
847 847
848/* suspend and resume support for the lcd controller */ 848/* suspend and resume support for the lcd controller */
849 849
850static int s3c2410fb_suspend(struct device *dev, pm_message_t state, u32 level) 850static int s3c2410fb_suspend(struct device *dev, pm_message_t state)
851{ 851{
852 struct fb_info *fbinfo = dev_get_drvdata(dev); 852 struct fb_info *fbinfo = dev_get_drvdata(dev);
853 struct s3c2410fb_info *info = fbinfo->par; 853 struct s3c2410fb_info *info = fbinfo->par;
854 854
855 if (level == SUSPEND_DISABLE || level == SUSPEND_POWER_DOWN) { 855 s3c2410fb_stop_lcd();
856 s3c2410fb_stop_lcd();
857 856
858 /* sleep before disabling the clock, we need to ensure 857 /* sleep before disabling the clock, we need to ensure
859 * the LCD DMA engine is not going to get back on the bus 858 * the LCD DMA engine is not going to get back on the bus
860 * before the clock goes off again (bjd) */ 859 * before the clock goes off again (bjd) */
861 860
862 msleep(1); 861 msleep(1);
863 clk_disable(info->clk); 862 clk_disable(info->clk);
864 }
865 863
866 return 0; 864 return 0;
867} 865}
868 866
869static int s3c2410fb_resume(struct device *dev, u32 level) 867static int s3c2410fb_resume(struct device *dev)
870{ 868{
871 struct fb_info *fbinfo = dev_get_drvdata(dev); 869 struct fb_info *fbinfo = dev_get_drvdata(dev);
872 struct s3c2410fb_info *info = fbinfo->par; 870 struct s3c2410fb_info *info = fbinfo->par;
873 871
874 if (level == RESUME_ENABLE) { 872 clk_enable(info->clk);
875 clk_enable(info->clk); 873 msleep(1);
876 msleep(1);
877
878 s3c2410fb_init_registers(info);
879 874
880 } 875 s3c2410fb_init_registers(info);
881 876
882 return 0; 877 return 0;
883} 878}
diff --git a/drivers/video/sa1100fb.c b/drivers/video/sa1100fb.c
index 8000890e4271..78e5f194b0df 100644
--- a/drivers/video/sa1100fb.c
+++ b/drivers/video/sa1100fb.c
@@ -1309,21 +1309,19 @@ sa1100fb_freq_policy(struct notifier_block *nb, unsigned long val,
1309 * Power management hooks. Note that we won't be called from IRQ context, 1309 * Power management hooks. Note that we won't be called from IRQ context,
1310 * unlike the blank functions above, so we may sleep. 1310 * unlike the blank functions above, so we may sleep.
1311 */ 1311 */
1312static int sa1100fb_suspend(struct device *dev, pm_message_t state, u32 level) 1312static int sa1100fb_suspend(struct device *dev, pm_message_t state)
1313{ 1313{
1314 struct sa1100fb_info *fbi = dev_get_drvdata(dev); 1314 struct sa1100fb_info *fbi = dev_get_drvdata(dev);
1315 1315
1316 if (level == SUSPEND_DISABLE || level == SUSPEND_POWER_DOWN) 1316 set_ctrlr_state(fbi, C_DISABLE_PM);
1317 set_ctrlr_state(fbi, C_DISABLE_PM);
1318 return 0; 1317 return 0;
1319} 1318}
1320 1319
1321static int sa1100fb_resume(struct device *dev, u32 level) 1320static int sa1100fb_resume(struct device *dev)
1322{ 1321{
1323 struct sa1100fb_info *fbi = dev_get_drvdata(dev); 1322 struct sa1100fb_info *fbi = dev_get_drvdata(dev);
1324 1323
1325 if (level == RESUME_ENABLE) 1324 set_ctrlr_state(fbi, C_ENABLE_PM);
1326 set_ctrlr_state(fbi, C_ENABLE_PM);
1327 return 0; 1325 return 0;
1328} 1326}
1329#else 1327#else
diff --git a/drivers/video/w100fb.c b/drivers/video/w100fb.c
index 0030c071da8f..752bf88906a9 100644
--- a/drivers/video/w100fb.c
+++ b/drivers/video/w100fb.c
@@ -438,36 +438,34 @@ static void w100fb_restore_vidmem(struct w100fb_par *par)
438 } 438 }
439} 439}
440 440
441static int w100fb_suspend(struct device *dev, pm_message_t state, uint32_t level) 441static int w100fb_suspend(struct device *dev, pm_message_t state)
442{ 442{
443 if (level == SUSPEND_POWER_DOWN) { 443 struct fb_info *info = dev_get_drvdata(dev);
444 struct fb_info *info = dev_get_drvdata(dev); 444 struct w100fb_par *par=info->par;
445 struct w100fb_par *par=info->par; 445 struct w100_tg_info *tg = par->mach->tg;
446 struct w100_tg_info *tg = par->mach->tg; 446
447 447 w100fb_save_vidmem(par);
448 w100fb_save_vidmem(par); 448 if(tg && tg->suspend)
449 if(tg && tg->suspend) 449 tg->suspend(par);
450 tg->suspend(par); 450 w100_suspend(W100_SUSPEND_ALL);
451 w100_suspend(W100_SUSPEND_ALL); 451 par->blanked = 1;
452 par->blanked = 1; 452
453 }
454 return 0; 453 return 0;
455} 454}
456 455
457static int w100fb_resume(struct device *dev, uint32_t level) 456static int w100fb_resume(struct device *dev)
458{ 457{
459 if (level == RESUME_POWER_ON) { 458 struct fb_info *info = dev_get_drvdata(dev);
460 struct fb_info *info = dev_get_drvdata(dev); 459 struct w100fb_par *par=info->par;
461 struct w100fb_par *par=info->par; 460 struct w100_tg_info *tg = par->mach->tg;
462 struct w100_tg_info *tg = par->mach->tg; 461
462 w100_hw_init(par);
463 w100fb_activate_var(par);
464 w100fb_restore_vidmem(par);
465 if(tg && tg->resume)
466 tg->resume(par);
467 par->blanked = 0;
463 468
464 w100_hw_init(par);
465 w100fb_activate_var(par);
466 w100fb_restore_vidmem(par);
467 if(tg && tg->resume)
468 tg->resume(par);
469 par->blanked = 0;
470 }
471 return 0; 469 return 0;
472} 470}
473#else 471#else
diff --git a/drivers/w1/w1_family.c b/drivers/w1/w1_family.c
index 88c517a4c178..9e293e139a0e 100644
--- a/drivers/w1/w1_family.c
+++ b/drivers/w1/w1_family.c
@@ -21,6 +21,7 @@
21 21
22#include <linux/spinlock.h> 22#include <linux/spinlock.h>
23#include <linux/list.h> 23#include <linux/list.h>
24#include <linux/sched.h> /* schedule_timeout() */
24#include <linux/delay.h> 25#include <linux/delay.h>
25 26
26#include "w1_family.h" 27#include "w1_family.h"
diff --git a/drivers/zorro/zorro-sysfs.c b/drivers/zorro/zorro-sysfs.c
index 04ca8840acf1..87c29d7b6c17 100644
--- a/drivers/zorro/zorro-sysfs.c
+++ b/drivers/zorro/zorro-sysfs.c
@@ -14,6 +14,7 @@
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/zorro.h> 15#include <linux/zorro.h>
16#include <linux/stat.h> 16#include <linux/stat.h>
17#include <linux/string.h>
17 18
18#include "zorro.h" 19#include "zorro.h"
19 20
diff --git a/drivers/zorro/zorro.c b/drivers/zorro/zorro.c
index d3c05dfe20d2..0f2b40605b06 100644
--- a/drivers/zorro/zorro.c
+++ b/drivers/zorro/zorro.c
@@ -16,6 +16,8 @@
16#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/zorro.h> 17#include <linux/zorro.h>
18#include <linux/bitops.h> 18#include <linux/bitops.h>
19#include <linux/string.h>
20
19#include <asm/setup.h> 21#include <asm/setup.h>
20#include <asm/amigahw.h> 22#include <asm/amigahw.h>
21 23