aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorDavid Woodhouse <dwmw2@shinybook.infradead.org>2005-08-09 11:51:35 -0400
committerDavid Woodhouse <dwmw2@shinybook.infradead.org>2005-08-09 11:51:35 -0400
commitc973b112c76c9d8fd042991128f218a738cc8d0a (patch)
treee813b0da5d0a0e19e06de6462d145a29ad683026 /drivers
parentc5fbc3966f48279dbebfde10248c977014aa9988 (diff)
parent00dd1e433967872f3997a45d5adf35056fdf2f56 (diff)
Merge with /shiny/git/linux-2.6/.git
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acorn/block/fd1772.c3
-rw-r--r--drivers/acpi/Kconfig5
-rw-r--r--drivers/acpi/button.c206
-rw-r--r--drivers/acpi/dispatcher/dswload.c6
-rw-r--r--drivers/acpi/ec.c907
-rw-r--r--drivers/acpi/hotkey.c690
-rw-r--r--drivers/acpi/motherboard.c2
-rw-r--r--drivers/acpi/osl.c6
-rw-r--r--drivers/acpi/pci_irq.c85
-rw-r--r--drivers/acpi/pci_link.c127
-rw-r--r--drivers/acpi/processor_idle.c32
-rw-r--r--drivers/block/as-iosched.c10
-rw-r--r--drivers/block/cciss.c49
-rw-r--r--drivers/block/cciss.h4
-rw-r--r--drivers/block/cfq-iosched.c1
-rw-r--r--drivers/block/ll_rw_blk.c18
-rw-r--r--drivers/block/sx8.c4
-rw-r--r--drivers/block/ub.c211
-rw-r--r--drivers/bluetooth/bpa10x.c7
-rw-r--r--drivers/bluetooth/hci_bcsp.c2
-rw-r--r--drivers/bluetooth/hci_h4.c5
-rw-r--r--drivers/bluetooth/hci_ldisc.c2
-rw-r--r--drivers/bluetooth/hci_usb.c11
-rw-r--r--drivers/cdrom/isp16.c2
-rw-r--r--drivers/cdrom/mcdx.c8
-rw-r--r--drivers/cdrom/optcd.c28
-rw-r--r--drivers/char/Kconfig2
-rw-r--r--drivers/char/agp/agp.h1
-rw-r--r--drivers/char/agp/intel-agp.c12
-rw-r--r--drivers/char/drm/via_dma.c10
-rw-r--r--drivers/char/drm/via_drm.h2
-rw-r--r--drivers/char/drm/via_ds.c4
-rw-r--r--drivers/char/drm/via_ds.h4
-rw-r--r--drivers/char/drm/via_map.c3
-rw-r--r--drivers/char/drm/via_mm.c15
-rw-r--r--drivers/char/drm/via_video.c3
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c2
-rw-r--r--drivers/char/ipmi/ipmi_watchdog.c6
-rw-r--r--drivers/char/keyboard.c4
-rw-r--r--drivers/char/rio/rioboot.c12
-rw-r--r--drivers/char/rio/rioroute.c2
-rw-r--r--drivers/char/rio/riotable.c2
-rw-r--r--drivers/char/rtc.c7
-rw-r--r--drivers/char/sonypi.c146
-rw-r--r--drivers/char/tpm/Kconfig14
-rw-r--r--drivers/char/tpm/Makefile2
-rw-r--r--drivers/char/tpm/tpm_infineon.c533
-rw-r--r--drivers/char/watchdog/acquirewdt.c7
-rw-r--r--drivers/char/watchdog/advantechwdt.c7
-rw-r--r--drivers/char/watchdog/alim1535_wdt.c9
-rw-r--r--drivers/char/watchdog/alim7101_wdt.c7
-rw-r--r--drivers/char/watchdog/eurotechwdt.c7
-rw-r--r--drivers/char/watchdog/i8xx_tco.c7
-rw-r--r--drivers/char/watchdog/ib700wdt.c7
-rw-r--r--drivers/char/watchdog/indydog.c7
-rw-r--r--drivers/char/watchdog/ixp2000_wdt.c6
-rw-r--r--drivers/char/watchdog/ixp4xx_wdt.c6
-rw-r--r--drivers/char/watchdog/machzwd.c7
-rw-r--r--drivers/char/watchdog/mixcomwd.c7
-rw-r--r--drivers/char/watchdog/pcwd.c7
-rw-r--r--drivers/char/watchdog/pcwd_pci.c7
-rw-r--r--drivers/char/watchdog/pcwd_usb.c7
-rw-r--r--drivers/char/watchdog/s3c2410_wdt.c7
-rw-r--r--drivers/char/watchdog/sa1100_wdt.c53
-rw-r--r--drivers/char/watchdog/sbc60xxwdt.c7
-rw-r--r--drivers/char/watchdog/sc1200wdt.c7
-rw-r--r--drivers/char/watchdog/sc520_wdt.c7
-rw-r--r--drivers/char/watchdog/scx200_wdt.c6
-rw-r--r--drivers/char/watchdog/shwdt.c6
-rw-r--r--drivers/char/watchdog/softdog.c7
-rw-r--r--drivers/char/watchdog/w83627hf_wdt.c7
-rw-r--r--drivers/char/watchdog/w83877f_wdt.c7
-rw-r--r--drivers/char/watchdog/wafer5823wdt.c7
-rw-r--r--drivers/char/watchdog/wdt.c7
-rw-r--r--drivers/char/watchdog/wdt977.c7
-rw-r--r--drivers/char/watchdog/wdt_pci.c7
-rw-r--r--drivers/cpufreq/cpufreq.c4
-rw-r--r--drivers/fc4/fc.c2
-rw-r--r--drivers/firmware/pcdp.c14
-rw-r--r--drivers/hwmon/adm1026.c2
-rw-r--r--drivers/hwmon/atxp1.c5
-rw-r--r--drivers/hwmon/fscpos.c4
-rw-r--r--drivers/hwmon/gl520sm.c4
-rw-r--r--drivers/hwmon/max1619.c2
-rw-r--r--drivers/hwmon/pc87360.c2
-rw-r--r--drivers/i2c/busses/i2c-i801.c6
-rw-r--r--drivers/i2c/busses/i2c-mpc.c94
-rw-r--r--drivers/i2c/chips/ds1337.c6
-rw-r--r--drivers/i2c/chips/eeprom.c8
-rw-r--r--drivers/i2c/chips/max6875.c8
-rw-r--r--drivers/i2c/i2c-core.c8
-rw-r--r--drivers/ide/cris/Makefile2
-rw-r--r--drivers/ide/cris/ide-cris.c1107
-rw-r--r--drivers/ide/cris/ide-v10.c842
-rw-r--r--drivers/ide/ide-probe.c16
-rw-r--r--drivers/ide/legacy/ide-cs.c5
-rw-r--r--drivers/ide/pci/cmd640.c2
-rw-r--r--drivers/ide/pci/trm290.c2
-rw-r--r--drivers/ieee1394/sbp2.c1
-rw-r--r--drivers/infiniband/core/Makefile9
-rw-r--r--drivers/infiniband/core/agent.c22
-rw-r--r--drivers/infiniband/core/agent_priv.h3
-rw-r--r--drivers/infiniband/core/cm.c3324
-rw-r--r--drivers/infiniband/core/cm_msgs.h819
-rw-r--r--drivers/infiniband/core/fmr_pool.c7
-rw-r--r--drivers/infiniband/core/mad.c600
-rw-r--r--drivers/infiniband/core/mad_priv.h33
-rw-r--r--drivers/infiniband/core/mad_rmpp.c765
-rw-r--r--drivers/infiniband/core/mad_rmpp.h58
-rw-r--r--drivers/infiniband/core/sa_query.c206
-rw-r--r--drivers/infiniband/core/ucm.c1387
-rw-r--r--drivers/infiniband/core/ucm.h89
-rw-r--r--drivers/infiniband/core/user_mad.c299
-rw-r--r--drivers/infiniband/core/uverbs.h1
-rw-r--r--drivers/infiniband/core/uverbs_main.c14
-rw-r--r--drivers/infiniband/core/verbs.c35
-rw-r--r--drivers/infiniband/hw/mthca/mthca_cq.c6
-rw-r--r--drivers/infiniband/hw/mthca/mthca_provider.c6
-rw-r--r--drivers/infiniband/include/ib_cm.h569
-rw-r--r--drivers/infiniband/include/ib_fmr_pool.h5
-rw-r--r--drivers/infiniband/include/ib_mad.h213
-rw-r--r--drivers/infiniband/include/ib_sa.h87
-rw-r--r--drivers/infiniband/include/ib_user_cm.h328
-rw-r--r--drivers/infiniband/include/ib_user_mad.h28
-rw-r--r--drivers/infiniband/include/ib_verbs.h25
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_ib.c6
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_main.c5
-rw-r--r--drivers/input/evdev.c1
-rw-r--r--drivers/input/input.c389
-rw-r--r--drivers/input/joydev.c6
-rw-r--r--drivers/input/misc/uinput.c181
-rw-r--r--drivers/input/mouse/alps.c29
-rw-r--r--drivers/input/mouse/logips2pp.c2
-rw-r--r--drivers/input/mouse/psmouse-base.c2
-rw-r--r--drivers/input/mouse/synaptics.c14
-rw-r--r--drivers/input/serio/Kconfig2
-rw-r--r--drivers/input/serio/i8042-x86ia64io.h14
-rw-r--r--drivers/input/serio/i8042.c60
-rw-r--r--drivers/input/serio/serio.c42
-rw-r--r--drivers/input/serio/serio_raw.c1
-rw-r--r--drivers/input/touchscreen/Kconfig2
-rw-r--r--drivers/isdn/hisax/avm_a1.c2
-rw-r--r--drivers/isdn/hisax/config.c1
-rw-r--r--drivers/isdn/hisax/gazel.c9
-rw-r--r--drivers/isdn/hisax/isdnl2.c2
-rw-r--r--drivers/isdn/hisax/l3dss1.c8
-rw-r--r--drivers/isdn/hisax/teles3.c2
-rw-r--r--drivers/isdn/icn/icn.c5
-rw-r--r--drivers/macintosh/Kconfig2
-rw-r--r--drivers/md/bitmap.c83
-rw-r--r--drivers/md/dm-raid1.c2
-rw-r--r--drivers/md/dm-table.c6
-rw-r--r--drivers/md/dm.c196
-rw-r--r--drivers/md/md.c6
-rw-r--r--drivers/md/raid1.c30
-rw-r--r--drivers/md/raid5.c2
-rw-r--r--drivers/md/raid6main.c2
-rw-r--r--drivers/media/dvb/frontends/Kconfig4
-rw-r--r--drivers/media/dvb/frontends/Makefile2
-rw-r--r--drivers/media/dvb/frontends/dvb-pll.c27
-rw-r--r--drivers/media/dvb/frontends/dvb-pll.h1
-rw-r--r--drivers/media/dvb/frontends/lgdt3302.c599
-rw-r--r--drivers/media/dvb/frontends/lgdt330x.c831
-rw-r--r--drivers/media/dvb/frontends/lgdt330x.h (renamed from drivers/media/dvb/frontends/lgdt3302.h)32
-rw-r--r--drivers/media/dvb/frontends/lgdt330x_priv.h (renamed from drivers/media/dvb/frontends/lgdt3302_priv.h)16
-rw-r--r--drivers/media/radio/radio-maestro.c4
-rw-r--r--drivers/media/radio/radio-maxiradio.c2
-rw-r--r--drivers/media/video/Kconfig4
-rw-r--r--drivers/media/video/bttv-cards.c12
-rw-r--r--drivers/media/video/bttv-driver.c33
-rw-r--r--drivers/media/video/bttv.h6
-rw-r--r--drivers/media/video/bttvp.h4
-rw-r--r--drivers/media/video/cx88/Makefile12
-rw-r--r--drivers/media/video/cx88/cx88-cards.c33
-rw-r--r--drivers/media/video/cx88/cx88-dvb.c104
-rw-r--r--drivers/media/video/cx88/cx88-i2c.c4
-rw-r--r--drivers/media/video/cx88/cx88-video.c4
-rw-r--r--drivers/media/video/cx88/cx88.h3
-rw-r--r--drivers/media/video/msp3400.c4
-rw-r--r--drivers/media/video/mxb.c39
-rw-r--r--drivers/media/video/saa7134/Makefile6
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c20
-rw-r--r--drivers/media/video/saa7134/saa7134-i2c.c4
-rw-r--r--drivers/media/video/saa7134/saa7134.h4
-rw-r--r--drivers/media/video/tea5767.c26
-rw-r--r--drivers/media/video/tuner-core.c29
-rw-r--r--drivers/media/video/tuner-simple.c8
-rw-r--r--drivers/media/video/tvaudio.c1
-rw-r--r--drivers/media/video/tveeprom.c8
-rw-r--r--drivers/mmc/wbsd.c2
-rw-r--r--drivers/mtd/devices/docecc.c1
-rw-r--r--drivers/net/3c505.c2
-rw-r--r--drivers/net/8139too.c6
-rw-r--r--drivers/net/Kconfig38
-rwxr-xr-xdrivers/net/amd8111e.c2
-rw-r--r--drivers/net/cs89x0.c13
-rw-r--r--drivers/net/cs89x0.h1
-rw-r--r--drivers/net/e1000/e1000_main.c29
-rw-r--r--drivers/net/hamradio/Kconfig2
-rw-r--r--drivers/net/ne.c4
-rw-r--r--drivers/net/pcmcia/nmclan_cs.c2
-rw-r--r--drivers/net/pcmcia/pcnet_cs.c7
-rw-r--r--drivers/net/pcmcia/smc91c92_cs.c8
-rw-r--r--drivers/net/pcmcia/xirc2ps_cs.c2
-rw-r--r--drivers/net/plip.c29
-rw-r--r--drivers/net/sk98lin/skge.c80
-rw-r--r--drivers/net/sk98lin/skgeinit.c2
-rw-r--r--drivers/net/sk98lin/skxmac2.c8
-rw-r--r--drivers/net/skge.c233
-rw-r--r--drivers/net/skge.h41
-rw-r--r--drivers/net/smc91x.h2
-rw-r--r--drivers/net/tg3.c16
-rw-r--r--drivers/net/via-velocity.h4
-rw-r--r--drivers/net/wireless/airo.c2
-rw-r--r--drivers/net/wireless/orinoco_cs.c2
-rw-r--r--drivers/oprofile/cpu_buffer.c23
-rw-r--r--drivers/pci/bus.c4
-rw-r--r--drivers/pci/probe.c2
-rw-r--r--drivers/pci/quirks.c24
-rw-r--r--drivers/pci/rom.c4
-rw-r--r--drivers/pci/setup-bus.c12
-rw-r--r--drivers/pci/setup-res.c7
-rw-r--r--drivers/pcmcia/au1000_generic.c1
-rw-r--r--drivers/pcmcia/cistpl.c51
-rw-r--r--drivers/pcmcia/ds.c6
-rw-r--r--drivers/pcmcia/o2micro.h34
-rw-r--r--drivers/pcmcia/pcmcia_resource.c2
-rw-r--r--drivers/pcmcia/yenta_socket.c18
-rw-r--r--drivers/pnp/pnpbios/rsparser.c2
-rw-r--r--drivers/s390/block/dasd.c6
-rw-r--r--drivers/s390/block/dasd_fba.c4
-rw-r--r--drivers/s390/char/tape.h7
-rw-r--r--drivers/s390/char/tape_core.c299
-rw-r--r--drivers/s390/char/vmcp.c6
-rw-r--r--drivers/s390/char/vmwatchdog.c6
-rw-r--r--drivers/s390/cio/chsc.c10
-rw-r--r--drivers/s390/cio/device_fsm.c3
-rw-r--r--drivers/s390/cio/device_status.c5
-rw-r--r--drivers/s390/cio/qdio.c20
-rw-r--r--drivers/s390/net/qeth.h26
-rw-r--r--drivers/s390/net/qeth_main.c24
-rw-r--r--drivers/s390/net/qeth_proc.c126
-rw-r--r--drivers/sbus/char/vfc.h2
-rw-r--r--drivers/sbus/char/vfc_dev.c1
-rw-r--r--drivers/sbus/char/vfc_i2c.c19
-rw-r--r--drivers/scsi/Kconfig2
-rw-r--r--drivers/scsi/NCR53c406a.c4
-rw-r--r--drivers/scsi/aacraid/aacraid.h6
-rw-r--r--drivers/scsi/aacraid/linit.c3
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm.c2
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_pci.c2
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_osm.c24
-rw-r--r--drivers/scsi/aic7xxx/aicasm/aicasm.c4
-rw-r--r--drivers/scsi/aic7xxx/aicasm/aicasm_insformat.h8
-rw-r--r--drivers/scsi/ata_piix.c19
-rw-r--r--drivers/scsi/dc395x.c2
-rw-r--r--drivers/scsi/dpt/dptsig.h4
-rw-r--r--drivers/scsi/dtc.c4
-rw-r--r--drivers/scsi/dtc.h4
-rw-r--r--drivers/scsi/fdomain.c2
-rw-r--r--drivers/scsi/ibmvscsi/srp.h2
-rw-r--r--drivers/scsi/initio.c2
-rw-r--r--drivers/scsi/ips.c8
-rw-r--r--drivers/scsi/ips.h39
-rw-r--r--drivers/scsi/lpfc/lpfc_compat.h3
-rw-r--r--drivers/scsi/lpfc/lpfc_scsi.h4
-rw-r--r--drivers/scsi/pas16.c1
-rw-r--r--drivers/scsi/qla2xxx/Kconfig15
-rw-r--r--drivers/scsi/qla2xxx/Makefile2
-rw-r--r--drivers/scsi/scsi_scan.c3
-rw-r--r--drivers/scsi/st.c8
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_hipd.h16
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_nvram.c2
-rw-r--r--drivers/scsi/t128.h1
-rw-r--r--drivers/serial/8250_pci.c20
-rw-r--r--drivers/serial/8250_pnp.c22
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_cpm1.c2
-rw-r--r--drivers/serial/jsm/jsm.h2
-rw-r--r--drivers/serial/jsm/jsm_driver.c3
-rw-r--r--drivers/serial/jsm/jsm_neo.c30
-rw-r--r--drivers/serial/serial_cs.c10
-rw-r--r--drivers/usb/Kconfig1
-rw-r--r--drivers/usb/class/cdc-acm.c3
-rw-r--r--drivers/usb/core/devio.c18
-rw-r--r--drivers/usb/core/hcd.c4
-rw-r--r--drivers/usb/core/hcd.h8
-rw-r--r--drivers/usb/core/message.c6
-rw-r--r--drivers/usb/host/ehci-dbg.c2
-rw-r--r--drivers/usb/host/ehci-q.c9
-rw-r--r--drivers/usb/host/ehci-sched.c13
-rw-r--r--drivers/usb/host/ehci.h5
-rw-r--r--drivers/usb/host/isp116x-hcd.c4
-rw-r--r--drivers/usb/host/ohci-hcd.c5
-rw-r--r--drivers/usb/host/ohci-s3c2410.c496
-rw-r--r--drivers/usb/image/microtek.c3
-rw-r--r--drivers/usb/input/acecad.c14
-rw-r--r--drivers/usb/input/aiptek.c6
-rw-r--r--drivers/usb/input/ati_remote.c8
-rw-r--r--drivers/usb/input/hid-core.c24
-rw-r--r--drivers/usb/input/hid-input.c11
-rw-r--r--drivers/usb/input/itmtouch.c6
-rw-r--r--drivers/usb/input/kbtab.c6
-rw-r--r--drivers/usb/input/mtouchusb.c6
-rw-r--r--drivers/usb/input/powermate.c6
-rw-r--r--drivers/usb/input/touchkitusb.c7
-rw-r--r--drivers/usb/input/usbkbd.c6
-rw-r--r--drivers/usb/input/usbmouse.c6
-rw-r--r--drivers/usb/input/wacom.c6
-rw-r--r--drivers/usb/input/xpad.c6
-rw-r--r--drivers/usb/media/konicawc.c6
-rw-r--r--drivers/usb/misc/ldusb.c7
-rw-r--r--drivers/usb/mon/Kconfig9
-rw-r--r--drivers/usb/mon/Makefile1
-rw-r--r--drivers/usb/net/pegasus.c1
-rw-r--r--drivers/usb/net/rtl8150.c2
-rw-r--r--drivers/usb/net/zd1201.c1
-rw-r--r--drivers/usb/serial/ftdi_sio.c146
-rw-r--r--drivers/usb/serial/ftdi_sio.h14
-rw-r--r--drivers/usb/usb-skeleton.c6
-rw-r--r--drivers/video/Kconfig4
-rw-r--r--drivers/video/aty/radeon_base.c5
-rw-r--r--drivers/video/console/fbcon.c3
-rw-r--r--drivers/video/fbcmap.c96
-rw-r--r--drivers/video/fbmem.c7
-rw-r--r--drivers/video/fbmon.c2
-rw-r--r--drivers/video/fbsysfs.c90
-rw-r--r--drivers/video/modedb.c5
-rw-r--r--drivers/video/nvidia/nvidia.c7
-rw-r--r--drivers/video/pm2fb.c16
-rw-r--r--drivers/video/riva/fbdev.c2
-rw-r--r--drivers/video/sa1100fb.c2
-rw-r--r--drivers/video/tridentfb.c28
-rw-r--r--drivers/video/vesafb.c47
-rw-r--r--drivers/w1/Kconfig2
334 files changed, 15686 insertions, 4643 deletions
diff --git a/drivers/acorn/block/fd1772.c b/drivers/acorn/block/fd1772.c
index 3cd2e968e96c..c0a37d98b4f3 100644
--- a/drivers/acorn/block/fd1772.c
+++ b/drivers/acorn/block/fd1772.c
@@ -1283,8 +1283,7 @@ static void do_fd_request(request_queue_t* q)
1283 if (fdc_busy) return; 1283 if (fdc_busy) return;
1284 save_flags(flags); 1284 save_flags(flags);
1285 cli(); 1285 cli();
1286 while (fdc_busy) 1286 wait_event(fdc_wait, !fdc_busy);
1287 sleep_on(&fdc_wait);
1288 fdc_busy = 1; 1287 fdc_busy = 1;
1289 ENABLE_IRQ(); 1288 ENABLE_IRQ();
1290 restore_flags(flags); 1289 restore_flags(flags);
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 986410e7b483..ba13896cae40 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -133,9 +133,10 @@ config ACPI_HOTKEY
133 depends on ACPI_INTERPRETER 133 depends on ACPI_INTERPRETER
134 depends on EXPERIMENTAL 134 depends on EXPERIMENTAL
135 depends on !IA64_SGI_SN 135 depends on !IA64_SGI_SN
136 default m 136 default n
137 help 137 help
138 ACPI generic hotkey 138 Experimental consolidated hotkey driver.
139 If you are unsure, say N.
139 140
140config ACPI_FAN 141config ACPI_FAN
141 tristate "Fan" 142 tristate "Fan"
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index 0f45d45f05a0..8162fd0c21a7 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -26,6 +26,9 @@
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/types.h>
30#include <linux/proc_fs.h>
31#include <linux/seq_file.h>
29#include <acpi/acpi_bus.h> 32#include <acpi/acpi_bus.h>
30#include <acpi/acpi_drivers.h> 33#include <acpi/acpi_drivers.h>
31 34
@@ -33,6 +36,9 @@
33#define ACPI_BUTTON_COMPONENT 0x00080000 36#define ACPI_BUTTON_COMPONENT 0x00080000
34#define ACPI_BUTTON_DRIVER_NAME "ACPI Button Driver" 37#define ACPI_BUTTON_DRIVER_NAME "ACPI Button Driver"
35#define ACPI_BUTTON_CLASS "button" 38#define ACPI_BUTTON_CLASS "button"
39#define ACPI_BUTTON_FILE_INFO "info"
40#define ACPI_BUTTON_FILE_STATE "state"
41#define ACPI_BUTTON_TYPE_UNKNOWN 0x00
36#define ACPI_BUTTON_NOTIFY_STATUS 0x80 42#define ACPI_BUTTON_NOTIFY_STATUS 0x80
37 43
38#define ACPI_BUTTON_SUBCLASS_POWER "power" 44#define ACPI_BUTTON_SUBCLASS_POWER "power"
@@ -64,6 +70,8 @@ MODULE_LICENSE("GPL");
64 70
65static int acpi_button_add (struct acpi_device *device); 71static int acpi_button_add (struct acpi_device *device);
66static int acpi_button_remove (struct acpi_device *device, int type); 72static int acpi_button_remove (struct acpi_device *device, int type);
73static int acpi_button_info_open_fs(struct inode *inode, struct file *file);
74static int acpi_button_state_open_fs(struct inode *inode, struct file *file);
67 75
68static struct acpi_driver acpi_button_driver = { 76static struct acpi_driver acpi_button_driver = {
69 .name = ACPI_BUTTON_DRIVER_NAME, 77 .name = ACPI_BUTTON_DRIVER_NAME,
@@ -82,6 +90,179 @@ struct acpi_button {
82 unsigned long pushed; 90 unsigned long pushed;
83}; 91};
84 92
93static struct file_operations acpi_button_info_fops = {
94 .open = acpi_button_info_open_fs,
95 .read = seq_read,
96 .llseek = seq_lseek,
97 .release = single_release,
98};
99
100static struct file_operations acpi_button_state_fops = {
101 .open = acpi_button_state_open_fs,
102 .read = seq_read,
103 .llseek = seq_lseek,
104 .release = single_release,
105};
106/* --------------------------------------------------------------------------
107 FS Interface (/proc)
108 -------------------------------------------------------------------------- */
109
110static struct proc_dir_entry *acpi_button_dir;
111
112static int acpi_button_info_seq_show(struct seq_file *seq, void *offset)
113{
114 struct acpi_button *button = (struct acpi_button *) seq->private;
115
116 ACPI_FUNCTION_TRACE("acpi_button_info_seq_show");
117
118 if (!button || !button->device)
119 return_VALUE(0);
120
121 seq_printf(seq, "type: %s\n",
122 acpi_device_name(button->device));
123
124 return_VALUE(0);
125}
126
127static int acpi_button_info_open_fs(struct inode *inode, struct file *file)
128{
129 return single_open(file, acpi_button_info_seq_show, PDE(inode)->data);
130}
131
132static int acpi_button_state_seq_show(struct seq_file *seq, void *offset)
133{
134 struct acpi_button *button = (struct acpi_button *) seq->private;
135 acpi_status status;
136 unsigned long state;
137
138 ACPI_FUNCTION_TRACE("acpi_button_state_seq_show");
139
140 if (!button || !button->device)
141 return_VALUE(0);
142
143 status = acpi_evaluate_integer(button->handle,"_LID",NULL,&state);
144 if (ACPI_FAILURE(status)) {
145 seq_printf(seq, "state: unsupported\n");
146 }
147 else{
148 seq_printf(seq, "state: %s\n", (state ? "open" : "closed"));
149 }
150
151 return_VALUE(0);
152}
153
154static int acpi_button_state_open_fs(struct inode *inode, struct file *file)
155{
156 return single_open(file, acpi_button_state_seq_show, PDE(inode)->data);
157}
158
159static struct proc_dir_entry *acpi_power_dir;
160static struct proc_dir_entry *acpi_sleep_dir;
161static struct proc_dir_entry *acpi_lid_dir;
162
163static int
164acpi_button_add_fs (
165 struct acpi_device *device)
166{
167 struct proc_dir_entry *entry = NULL;
168 struct acpi_button *button = NULL;
169
170 ACPI_FUNCTION_TRACE("acpi_button_add_fs");
171
172 if (!device || !acpi_driver_data(device))
173 return_VALUE(-EINVAL);
174
175 button = acpi_driver_data(device);
176
177 switch (button->type) {
178 case ACPI_BUTTON_TYPE_POWER:
179 case ACPI_BUTTON_TYPE_POWERF:
180 if (!acpi_power_dir)
181 acpi_power_dir = proc_mkdir(ACPI_BUTTON_SUBCLASS_POWER,
182 acpi_button_dir);
183 entry = acpi_power_dir;
184 break;
185 case ACPI_BUTTON_TYPE_SLEEP:
186 case ACPI_BUTTON_TYPE_SLEEPF:
187 if (!acpi_sleep_dir)
188 acpi_sleep_dir = proc_mkdir(ACPI_BUTTON_SUBCLASS_SLEEP,
189 acpi_button_dir);
190 entry = acpi_sleep_dir;
191 break;
192 case ACPI_BUTTON_TYPE_LID:
193 if (!acpi_lid_dir)
194 acpi_lid_dir = proc_mkdir(ACPI_BUTTON_SUBCLASS_LID,
195 acpi_button_dir);
196 entry = acpi_lid_dir;
197 break;
198 }
199
200 if (!entry)
201 return_VALUE(-ENODEV);
202 entry->owner = THIS_MODULE;
203
204 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), entry);
205 if (!acpi_device_dir(device))
206 return_VALUE(-ENODEV);
207 acpi_device_dir(device)->owner = THIS_MODULE;
208
209 /* 'info' [R] */
210 entry = create_proc_entry(ACPI_BUTTON_FILE_INFO,
211 S_IRUGO, acpi_device_dir(device));
212 if (!entry)
213 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
214 "Unable to create '%s' fs entry\n",
215 ACPI_BUTTON_FILE_INFO));
216 else {
217 entry->proc_fops = &acpi_button_info_fops;
218 entry->data = acpi_driver_data(device);
219 entry->owner = THIS_MODULE;
220 }
221
222 /* show lid state [R] */
223 if (button->type == ACPI_BUTTON_TYPE_LID) {
224 entry = create_proc_entry(ACPI_BUTTON_FILE_STATE,
225 S_IRUGO, acpi_device_dir(device));
226 if (!entry)
227 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
228 "Unable to create '%s' fs entry\n",
229 ACPI_BUTTON_FILE_INFO));
230 else {
231 entry->proc_fops = &acpi_button_state_fops;
232 entry->data = acpi_driver_data(device);
233 entry->owner = THIS_MODULE;
234 }
235 }
236
237 return_VALUE(0);
238}
239
240
241static int
242acpi_button_remove_fs (
243 struct acpi_device *device)
244{
245 struct acpi_button *button = NULL;
246
247 ACPI_FUNCTION_TRACE("acpi_button_remove_fs");
248
249 button = acpi_driver_data(device);
250 if (acpi_device_dir(device)) {
251 if (button->type == ACPI_BUTTON_TYPE_LID)
252 remove_proc_entry(ACPI_BUTTON_FILE_STATE,
253 acpi_device_dir(device));
254 remove_proc_entry(ACPI_BUTTON_FILE_INFO,
255 acpi_device_dir(device));
256
257 remove_proc_entry(acpi_device_bid(device),
258 acpi_device_dir(device)->parent);
259 acpi_device_dir(device) = NULL;
260 }
261
262 return_VALUE(0);
263}
264
265
85/* -------------------------------------------------------------------------- 266/* --------------------------------------------------------------------------
86 Driver Interface 267 Driver Interface
87 -------------------------------------------------------------------------- */ 268 -------------------------------------------------------------------------- */
@@ -121,7 +302,8 @@ acpi_button_notify_fixed (
121 302
122 ACPI_FUNCTION_TRACE("acpi_button_notify_fixed"); 303 ACPI_FUNCTION_TRACE("acpi_button_notify_fixed");
123 304
124 BUG_ON(!button); 305 if (!button)
306 return_ACPI_STATUS(AE_BAD_PARAMETER);
125 307
126 acpi_button_notify(button->handle, ACPI_BUTTON_NOTIFY_STATUS, button); 308 acpi_button_notify(button->handle, ACPI_BUTTON_NOTIFY_STATUS, button);
127 309
@@ -197,6 +379,10 @@ acpi_button_add (
197 goto end; 379 goto end;
198 } 380 }
199 381
382 result = acpi_button_add_fs(device);
383 if (result)
384 goto end;
385
200 switch (button->type) { 386 switch (button->type) {
201 case ACPI_BUTTON_TYPE_POWERF: 387 case ACPI_BUTTON_TYPE_POWERF:
202 status = acpi_install_fixed_event_handler ( 388 status = acpi_install_fixed_event_handler (
@@ -240,6 +426,7 @@ acpi_button_add (
240 426
241end: 427end:
242 if (result) { 428 if (result) {
429 acpi_button_remove_fs(device);
243 kfree(button); 430 kfree(button);
244 } 431 }
245 432
@@ -280,6 +467,8 @@ acpi_button_remove (struct acpi_device *device, int type)
280 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 467 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
281 "Error removing notify handler\n")); 468 "Error removing notify handler\n"));
282 469
470 acpi_button_remove_fs(device);
471
283 kfree(button); 472 kfree(button);
284 473
285 return_VALUE(0); 474 return_VALUE(0);
@@ -293,14 +482,20 @@ acpi_button_init (void)
293 482
294 ACPI_FUNCTION_TRACE("acpi_button_init"); 483 ACPI_FUNCTION_TRACE("acpi_button_init");
295 484
485 acpi_button_dir = proc_mkdir(ACPI_BUTTON_CLASS, acpi_root_dir);
486 if (!acpi_button_dir)
487 return_VALUE(-ENODEV);
488 acpi_button_dir->owner = THIS_MODULE;
296 result = acpi_bus_register_driver(&acpi_button_driver); 489 result = acpi_bus_register_driver(&acpi_button_driver);
297 if (result < 0) { 490 if (result < 0) {
491 remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir);
298 return_VALUE(-ENODEV); 492 return_VALUE(-ENODEV);
299 } 493 }
300 494
301 return_VALUE(0); 495 return_VALUE(0);
302} 496}
303 497
498
304static void __exit 499static void __exit
305acpi_button_exit (void) 500acpi_button_exit (void)
306{ 501{
@@ -308,8 +503,17 @@ acpi_button_exit (void)
308 503
309 acpi_bus_unregister_driver(&acpi_button_driver); 504 acpi_bus_unregister_driver(&acpi_button_driver);
310 505
506 if (acpi_power_dir)
507 remove_proc_entry(ACPI_BUTTON_SUBCLASS_POWER, acpi_button_dir);
508 if (acpi_sleep_dir)
509 remove_proc_entry(ACPI_BUTTON_SUBCLASS_SLEEP, acpi_button_dir);
510 if (acpi_lid_dir)
511 remove_proc_entry(ACPI_BUTTON_SUBCLASS_LID, acpi_button_dir);
512 remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir);
513
311 return_VOID; 514 return_VOID;
312} 515}
313 516
517
314module_init(acpi_button_init); 518module_init(acpi_button_init);
315module_exit(acpi_button_exit); 519module_exit(acpi_button_exit);
diff --git a/drivers/acpi/dispatcher/dswload.c b/drivers/acpi/dispatcher/dswload.c
index 1ac197ccfc80..d11620018421 100644
--- a/drivers/acpi/dispatcher/dswload.c
+++ b/drivers/acpi/dispatcher/dswload.c
@@ -491,12 +491,6 @@ acpi_ds_load2_begin_op (
491 if ((!(walk_state->op_info->flags & AML_NSOPCODE) && 491 if ((!(walk_state->op_info->flags & AML_NSOPCODE) &&
492 (walk_state->opcode != AML_INT_NAMEPATH_OP)) || 492 (walk_state->opcode != AML_INT_NAMEPATH_OP)) ||
493 (!(walk_state->op_info->flags & AML_NAMED))) { 493 (!(walk_state->op_info->flags & AML_NAMED))) {
494 if ((walk_state->op_info->class == AML_CLASS_EXECUTE) ||
495 (walk_state->op_info->class == AML_CLASS_CONTROL)) {
496 ACPI_REPORT_WARNING ((
497 "Encountered executable code at module level, [%s]\n",
498 acpi_ps_get_opcode_name (walk_state->opcode)));
499 }
500 return_ACPI_STATUS (AE_OK); 494 return_ACPI_STATUS (AE_OK);
501 } 495 }
502 496
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index fca4140a50a9..1ac5731d45e5 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -59,76 +59,186 @@ ACPI_MODULE_NAME ("acpi_ec")
59#define ACPI_EC_DELAY 50 /* Wait 50ms max. during EC ops */ 59#define ACPI_EC_DELAY 50 /* Wait 50ms max. during EC ops */
60#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */ 60#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
61 61
62#define ACPI_EC_UDELAY 100 /* Poll @ 100us increments */
63#define ACPI_EC_UDELAY_COUNT 1000 /* Wait 10ms max. during EC ops */
64
62#define ACPI_EC_COMMAND_READ 0x80 65#define ACPI_EC_COMMAND_READ 0x80
63#define ACPI_EC_COMMAND_WRITE 0x81 66#define ACPI_EC_COMMAND_WRITE 0x81
64#define ACPI_EC_BURST_ENABLE 0x82 67#define ACPI_EC_BURST_ENABLE 0x82
65#define ACPI_EC_BURST_DISABLE 0x83 68#define ACPI_EC_BURST_DISABLE 0x83
66#define ACPI_EC_COMMAND_QUERY 0x84 69#define ACPI_EC_COMMAND_QUERY 0x84
67 70
68static int acpi_ec_add (struct acpi_device *device); 71#define EC_POLLING 0xFF
72#define EC_BURST 0x00
73
74
69static int acpi_ec_remove (struct acpi_device *device, int type); 75static int acpi_ec_remove (struct acpi_device *device, int type);
70static int acpi_ec_start (struct acpi_device *device); 76static int acpi_ec_start (struct acpi_device *device);
71static int acpi_ec_stop (struct acpi_device *device, int type); 77static int acpi_ec_stop (struct acpi_device *device, int type);
78static int acpi_ec_burst_add ( struct acpi_device *device);
79static int acpi_ec_polling_add ( struct acpi_device *device);
72 80
73static struct acpi_driver acpi_ec_driver = { 81static struct acpi_driver acpi_ec_driver = {
74 .name = ACPI_EC_DRIVER_NAME, 82 .name = ACPI_EC_DRIVER_NAME,
75 .class = ACPI_EC_CLASS, 83 .class = ACPI_EC_CLASS,
76 .ids = ACPI_EC_HID, 84 .ids = ACPI_EC_HID,
77 .ops = { 85 .ops = {
78 .add = acpi_ec_add, 86 .add = acpi_ec_polling_add,
79 .remove = acpi_ec_remove, 87 .remove = acpi_ec_remove,
80 .start = acpi_ec_start, 88 .start = acpi_ec_start,
81 .stop = acpi_ec_stop, 89 .stop = acpi_ec_stop,
82 }, 90 },
83}; 91};
84 92union acpi_ec {
85struct acpi_ec { 93 struct {
86 acpi_handle handle; 94 u32 mode;
87 unsigned long uid; 95 acpi_handle handle;
88 unsigned long gpe_bit; 96 unsigned long uid;
89 struct acpi_generic_address status_addr; 97 unsigned long gpe_bit;
90 struct acpi_generic_address command_addr; 98 struct acpi_generic_address status_addr;
91 struct acpi_generic_address data_addr; 99 struct acpi_generic_address command_addr;
92 unsigned long global_lock; 100 struct acpi_generic_address data_addr;
93 unsigned int expect_event; 101 unsigned long global_lock;
94 atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort*/ 102 } common;
95 atomic_t pending_gpe; 103
96 struct semaphore sem; 104 struct {
97 wait_queue_head_t wait; 105 u32 mode;
106 acpi_handle handle;
107 unsigned long uid;
108 unsigned long gpe_bit;
109 struct acpi_generic_address status_addr;
110 struct acpi_generic_address command_addr;
111 struct acpi_generic_address data_addr;
112 unsigned long global_lock;
113 unsigned int expect_event;
114 atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort*/
115 atomic_t pending_gpe;
116 struct semaphore sem;
117 wait_queue_head_t wait;
118 }burst;
119
120 struct {
121 u32 mode;
122 acpi_handle handle;
123 unsigned long uid;
124 unsigned long gpe_bit;
125 struct acpi_generic_address status_addr;
126 struct acpi_generic_address command_addr;
127 struct acpi_generic_address data_addr;
128 unsigned long global_lock;
129 spinlock_t lock;
130 }polling;
98}; 131};
99 132
133static int acpi_ec_polling_wait ( union acpi_ec *ec, u8 event);
134static int acpi_ec_burst_wait(union acpi_ec *ec, unsigned int event);
135static int acpi_ec_polling_read ( union acpi_ec *ec, u8 address, u32 *data);
136static int acpi_ec_burst_read( union acpi_ec *ec, u8 address, u32 *data);
137static int acpi_ec_polling_write ( union acpi_ec *ec, u8 address, u8 data);
138static int acpi_ec_burst_write ( union acpi_ec *ec, u8 address, u8 data);
139static int acpi_ec_polling_query ( union acpi_ec *ec, u32 *data);
140static int acpi_ec_burst_query ( union acpi_ec *ec, u32 *data);
141static void acpi_ec_gpe_polling_query ( void *ec_cxt);
142static void acpi_ec_gpe_burst_query ( void *ec_cxt);
143static u32 acpi_ec_gpe_polling_handler ( void *data);
144static u32 acpi_ec_gpe_burst_handler ( void *data);
145static acpi_status __init
146acpi_fake_ecdt_polling_callback (
147 acpi_handle handle,
148 u32 Level,
149 void *context,
150 void **retval);
151
152static acpi_status __init
153acpi_fake_ecdt_burst_callback (
154 acpi_handle handle,
155 u32 Level,
156 void *context,
157 void **retval);
158
159static int __init
160acpi_ec_polling_get_real_ecdt(void);
161static int __init
162acpi_ec_burst_get_real_ecdt(void);
100/* If we find an EC via the ECDT, we need to keep a ptr to its context */ 163/* If we find an EC via the ECDT, we need to keep a ptr to its context */
101static struct acpi_ec *ec_ecdt; 164static union acpi_ec *ec_ecdt;
102 165
103/* External interfaces use first EC only, so remember */ 166/* External interfaces use first EC only, so remember */
104static struct acpi_device *first_ec; 167static struct acpi_device *first_ec;
168static int acpi_ec_polling_mode = EC_POLLING;
105 169
106/* -------------------------------------------------------------------------- 170/* --------------------------------------------------------------------------
107 Transaction Management 171 Transaction Management
108 -------------------------------------------------------------------------- */ 172 -------------------------------------------------------------------------- */
109 173
110static inline u32 acpi_ec_read_status(struct acpi_ec *ec) 174static inline u32 acpi_ec_read_status(union acpi_ec *ec)
111{ 175{
112 u32 status = 0; 176 u32 status = 0;
113 177
114 acpi_hw_low_level_read(8, &status, &ec->status_addr); 178 acpi_hw_low_level_read(8, &status, &ec->common.status_addr);
115 return status; 179 return status;
116} 180}
117 181
118static int acpi_ec_wait(struct acpi_ec *ec, unsigned int event) 182static int
183acpi_ec_wait (
184 union acpi_ec *ec,
185 u8 event)
186{
187 if (acpi_ec_polling_mode)
188 return acpi_ec_polling_wait (ec, event);
189 else
190 return acpi_ec_burst_wait (ec, event);
191}
192
193static int
194acpi_ec_polling_wait (
195 union acpi_ec *ec,
196 u8 event)
197{
198 u32 acpi_ec_status = 0;
199 u32 i = ACPI_EC_UDELAY_COUNT;
200
201 if (!ec)
202 return -EINVAL;
203
204 /* Poll the EC status register waiting for the event to occur. */
205 switch (event) {
206 case ACPI_EC_EVENT_OBF:
207 do {
208 acpi_hw_low_level_read(8, &acpi_ec_status, &ec->common.status_addr);
209 if (acpi_ec_status & ACPI_EC_FLAG_OBF)
210 return 0;
211 udelay(ACPI_EC_UDELAY);
212 } while (--i>0);
213 break;
214 case ACPI_EC_EVENT_IBE:
215 do {
216 acpi_hw_low_level_read(8, &acpi_ec_status, &ec->common.status_addr);
217 if (!(acpi_ec_status & ACPI_EC_FLAG_IBF))
218 return 0;
219 udelay(ACPI_EC_UDELAY);
220 } while (--i>0);
221 break;
222 default:
223 return -EINVAL;
224 }
225
226 return -ETIME;
227}
228static int acpi_ec_burst_wait(union acpi_ec *ec, unsigned int event)
119{ 229{
120 int result = 0; 230 int result = 0;
121 231
122 ACPI_FUNCTION_TRACE("acpi_ec_wait"); 232 ACPI_FUNCTION_TRACE("acpi_ec_wait");
123 233
124 ec->expect_event = event; 234 ec->burst.expect_event = event;
125 smp_mb(); 235 smp_mb();
126 236
127 result = wait_event_interruptible_timeout(ec->wait, 237 result = wait_event_interruptible_timeout(ec->burst.wait,
128 !ec->expect_event, 238 !ec->burst.expect_event,
129 msecs_to_jiffies(ACPI_EC_DELAY)); 239 msecs_to_jiffies(ACPI_EC_DELAY));
130 240
131 ec->expect_event = 0; 241 ec->burst.expect_event = 0;
132 smp_mb(); 242 smp_mb();
133 243
134 if (result < 0){ 244 if (result < 0){
@@ -160,7 +270,7 @@ static int acpi_ec_wait(struct acpi_ec *ec, unsigned int event)
160 270
161static int 271static int
162acpi_ec_enter_burst_mode ( 272acpi_ec_enter_burst_mode (
163 struct acpi_ec *ec) 273 union acpi_ec *ec)
164{ 274{
165 u32 tmp = 0; 275 u32 tmp = 0;
166 int status = 0; 276 int status = 0;
@@ -170,43 +280,43 @@ acpi_ec_enter_burst_mode (
170 status = acpi_ec_read_status(ec); 280 status = acpi_ec_read_status(ec);
171 if (status != -EINVAL && 281 if (status != -EINVAL &&
172 !(status & ACPI_EC_FLAG_BURST)){ 282 !(status & ACPI_EC_FLAG_BURST)){
173 acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, &ec->command_addr); 283 acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, &ec->common.command_addr);
174 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); 284 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
175 if (status){ 285 if (status){
176 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 286 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
177 return_VALUE(-EINVAL); 287 return_VALUE(-EINVAL);
178 } 288 }
179 acpi_hw_low_level_read(8, &tmp, &ec->data_addr); 289 acpi_hw_low_level_read(8, &tmp, &ec->common.data_addr);
180 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 290 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
181 if(tmp != 0x90 ) {/* Burst ACK byte*/ 291 if(tmp != 0x90 ) {/* Burst ACK byte*/
182 return_VALUE(-EINVAL); 292 return_VALUE(-EINVAL);
183 } 293 }
184 } 294 }
185 295
186 atomic_set(&ec->leaving_burst , 0); 296 atomic_set(&ec->burst.leaving_burst , 0);
187 return_VALUE(0); 297 return_VALUE(0);
188} 298}
189 299
190static int 300static int
191acpi_ec_leave_burst_mode ( 301acpi_ec_leave_burst_mode (
192 struct acpi_ec *ec) 302 union acpi_ec *ec)
193{ 303{
194 int status =0; 304 int status =0;
195 305
196 ACPI_FUNCTION_TRACE("acpi_ec_leave_burst_mode"); 306 ACPI_FUNCTION_TRACE("acpi_ec_leave_burst_mode");
197 307
198 atomic_set(&ec->leaving_burst , 1); 308 atomic_set(&ec->burst.leaving_burst , 1);
199 status = acpi_ec_read_status(ec); 309 status = acpi_ec_read_status(ec);
200 if (status != -EINVAL && 310 if (status != -EINVAL &&
201 (status & ACPI_EC_FLAG_BURST)){ 311 (status & ACPI_EC_FLAG_BURST)){
202 acpi_hw_low_level_write(8, ACPI_EC_BURST_DISABLE, &ec->command_addr); 312 acpi_hw_low_level_write(8, ACPI_EC_BURST_DISABLE, &ec->common.command_addr);
203 status = acpi_ec_wait(ec, ACPI_EC_FLAG_IBF); 313 status = acpi_ec_wait(ec, ACPI_EC_FLAG_IBF);
204 if (status){ 314 if (status){
205 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 315 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
206 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,"------->wait fail\n")); 316 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,"------->wait fail\n"));
207 return_VALUE(-EINVAL); 317 return_VALUE(-EINVAL);
208 } 318 }
209 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 319 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
210 status = acpi_ec_read_status(ec); 320 status = acpi_ec_read_status(ec);
211 } 321 }
212 322
@@ -215,7 +325,131 @@ acpi_ec_leave_burst_mode (
215 325
216static int 326static int
217acpi_ec_read ( 327acpi_ec_read (
218 struct acpi_ec *ec, 328 union acpi_ec *ec,
329 u8 address,
330 u32 *data)
331{
332 if (acpi_ec_polling_mode)
333 return acpi_ec_polling_read(ec, address, data);
334 else
335 return acpi_ec_burst_read(ec, address, data);
336}
337static int
338acpi_ec_write (
339 union acpi_ec *ec,
340 u8 address,
341 u8 data)
342{
343 if (acpi_ec_polling_mode)
344 return acpi_ec_polling_write(ec, address, data);
345 else
346 return acpi_ec_burst_write(ec, address, data);
347}
348static int
349acpi_ec_polling_read (
350 union acpi_ec *ec,
351 u8 address,
352 u32 *data)
353{
354 acpi_status status = AE_OK;
355 int result = 0;
356 unsigned long flags = 0;
357 u32 glk = 0;
358
359 ACPI_FUNCTION_TRACE("acpi_ec_read");
360
361 if (!ec || !data)
362 return_VALUE(-EINVAL);
363
364 *data = 0;
365
366 if (ec->common.global_lock) {
367 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
368 if (ACPI_FAILURE(status))
369 return_VALUE(-ENODEV);
370 }
371
372 spin_lock_irqsave(&ec->polling.lock, flags);
373
374 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ, &ec->common.command_addr);
375 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
376 if (result)
377 goto end;
378
379 acpi_hw_low_level_write(8, address, &ec->common.data_addr);
380 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
381 if (result)
382 goto end;
383
384 acpi_hw_low_level_read(8, data, &ec->common.data_addr);
385
386 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n",
387 *data, address));
388
389end:
390 spin_unlock_irqrestore(&ec->polling.lock, flags);
391
392 if (ec->common.global_lock)
393 acpi_release_global_lock(glk);
394
395 return_VALUE(result);
396}
397
398
399static int
400acpi_ec_polling_write (
401 union acpi_ec *ec,
402 u8 address,
403 u8 data)
404{
405 int result = 0;
406 acpi_status status = AE_OK;
407 unsigned long flags = 0;
408 u32 glk = 0;
409
410 ACPI_FUNCTION_TRACE("acpi_ec_write");
411
412 if (!ec)
413 return_VALUE(-EINVAL);
414
415 if (ec->common.global_lock) {
416 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
417 if (ACPI_FAILURE(status))
418 return_VALUE(-ENODEV);
419 }
420
421 spin_lock_irqsave(&ec->polling.lock, flags);
422
423 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE, &ec->common.command_addr);
424 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
425 if (result)
426 goto end;
427
428 acpi_hw_low_level_write(8, address, &ec->common.data_addr);
429 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
430 if (result)
431 goto end;
432
433 acpi_hw_low_level_write(8, data, &ec->common.data_addr);
434 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
435 if (result)
436 goto end;
437
438 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Wrote [%02x] to address [%02x]\n",
439 data, address));
440
441end:
442 spin_unlock_irqrestore(&ec->polling.lock, flags);
443
444 if (ec->common.global_lock)
445 acpi_release_global_lock(glk);
446
447 return_VALUE(result);
448}
449
450static int
451acpi_ec_burst_read (
452 union acpi_ec *ec,
219 u8 address, 453 u8 address,
220 u32 *data) 454 u32 *data)
221{ 455{
@@ -230,51 +464,51 @@ acpi_ec_read (
230retry: 464retry:
231 *data = 0; 465 *data = 0;
232 466
233 if (ec->global_lock) { 467 if (ec->common.global_lock) {
234 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); 468 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
235 if (ACPI_FAILURE(status)) 469 if (ACPI_FAILURE(status))
236 return_VALUE(-ENODEV); 470 return_VALUE(-ENODEV);
237 } 471 }
238 472
239 WARN_ON(in_interrupt()); 473 WARN_ON(in_interrupt());
240 down(&ec->sem); 474 down(&ec->burst.sem);
241 475
242 if(acpi_ec_enter_burst_mode(ec)) 476 if(acpi_ec_enter_burst_mode(ec))
243 goto end; 477 goto end;
244 478
245 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ, &ec->command_addr); 479 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_READ, &ec->common.command_addr);
246 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); 480 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
247 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 481 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
248 if (status) { 482 if (status) {
249 goto end; 483 goto end;
250 } 484 }
251 485
252 acpi_hw_low_level_write(8, address, &ec->data_addr); 486 acpi_hw_low_level_write(8, address, &ec->common.data_addr);
253 status= acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); 487 status= acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
254 if (status){ 488 if (status){
255 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 489 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
256 goto end; 490 goto end;
257 } 491 }
258 492
259 acpi_hw_low_level_read(8, data, &ec->data_addr); 493 acpi_hw_low_level_read(8, data, &ec->common.data_addr);
260 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 494 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
261 495
262 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n", 496 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Read [%02x] from address [%02x]\n",
263 *data, address)); 497 *data, address));
264 498
265end: 499end:
266 acpi_ec_leave_burst_mode(ec); 500 acpi_ec_leave_burst_mode(ec);
267 up(&ec->sem); 501 up(&ec->burst.sem);
268 502
269 if (ec->global_lock) 503 if (ec->common.global_lock)
270 acpi_release_global_lock(glk); 504 acpi_release_global_lock(glk);
271 505
272 if(atomic_read(&ec->leaving_burst) == 2){ 506 if(atomic_read(&ec->burst.leaving_burst) == 2){
273 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n")); 507 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n"));
274 while(atomic_read(&ec->pending_gpe)){ 508 while(atomic_read(&ec->burst.pending_gpe)){
275 msleep(1); 509 msleep(1);
276 } 510 }
277 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 511 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
278 goto retry; 512 goto retry;
279 } 513 }
280 514
@@ -283,8 +517,8 @@ end:
283 517
284 518
285static int 519static int
286acpi_ec_write ( 520acpi_ec_burst_write (
287 struct acpi_ec *ec, 521 union acpi_ec *ec,
288 u8 address, 522 u8 address,
289 u8 data) 523 u8 data)
290{ 524{
@@ -297,14 +531,14 @@ acpi_ec_write (
297 if (!ec) 531 if (!ec)
298 return_VALUE(-EINVAL); 532 return_VALUE(-EINVAL);
299retry: 533retry:
300 if (ec->global_lock) { 534 if (ec->common.global_lock) {
301 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); 535 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
302 if (ACPI_FAILURE(status)) 536 if (ACPI_FAILURE(status))
303 return_VALUE(-ENODEV); 537 return_VALUE(-ENODEV);
304 } 538 }
305 539
306 WARN_ON(in_interrupt()); 540 WARN_ON(in_interrupt());
307 down(&ec->sem); 541 down(&ec->burst.sem);
308 542
309 if(acpi_ec_enter_burst_mode(ec)) 543 if(acpi_ec_enter_burst_mode(ec))
310 goto end; 544 goto end;
@@ -312,33 +546,33 @@ retry:
312 status = acpi_ec_read_status(ec); 546 status = acpi_ec_read_status(ec);
313 if (status != -EINVAL && 547 if (status != -EINVAL &&
314 !(status & ACPI_EC_FLAG_BURST)){ 548 !(status & ACPI_EC_FLAG_BURST)){
315 acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, &ec->command_addr); 549 acpi_hw_low_level_write(8, ACPI_EC_BURST_ENABLE, &ec->common.command_addr);
316 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); 550 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
317 if (status) 551 if (status)
318 goto end; 552 goto end;
319 acpi_hw_low_level_read(8, &tmp, &ec->data_addr); 553 acpi_hw_low_level_read(8, &tmp, &ec->common.data_addr);
320 if(tmp != 0x90 ) /* Burst ACK byte*/ 554 if(tmp != 0x90 ) /* Burst ACK byte*/
321 goto end; 555 goto end;
322 } 556 }
323 /*Now we are in burst mode*/ 557 /*Now we are in burst mode*/
324 558
325 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE, &ec->command_addr); 559 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_WRITE, &ec->common.command_addr);
326 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); 560 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
327 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 561 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
328 if (status){ 562 if (status){
329 goto end; 563 goto end;
330 } 564 }
331 565
332 acpi_hw_low_level_write(8, address, &ec->data_addr); 566 acpi_hw_low_level_write(8, address, &ec->common.data_addr);
333 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); 567 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
334 if (status){ 568 if (status){
335 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 569 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
336 goto end; 570 goto end;
337 } 571 }
338 572
339 acpi_hw_low_level_write(8, data, &ec->data_addr); 573 acpi_hw_low_level_write(8, data, &ec->common.data_addr);
340 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE); 574 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBE);
341 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 575 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
342 if (status) 576 if (status)
343 goto end; 577 goto end;
344 578
@@ -347,17 +581,17 @@ retry:
347 581
348end: 582end:
349 acpi_ec_leave_burst_mode(ec); 583 acpi_ec_leave_burst_mode(ec);
350 up(&ec->sem); 584 up(&ec->burst.sem);
351 585
352 if (ec->global_lock) 586 if (ec->common.global_lock)
353 acpi_release_global_lock(glk); 587 acpi_release_global_lock(glk);
354 588
355 if(atomic_read(&ec->leaving_burst) == 2){ 589 if(atomic_read(&ec->burst.leaving_burst) == 2){
356 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n")); 590 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n"));
357 while(atomic_read(&ec->pending_gpe)){ 591 while(atomic_read(&ec->burst.pending_gpe)){
358 msleep(1); 592 msleep(1);
359 } 593 }
360 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 594 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
361 goto retry; 595 goto retry;
362 } 596 }
363 597
@@ -370,7 +604,7 @@ end:
370int 604int
371ec_read(u8 addr, u8 *val) 605ec_read(u8 addr, u8 *val)
372{ 606{
373 struct acpi_ec *ec; 607 union acpi_ec *ec;
374 int err; 608 int err;
375 u32 temp_data; 609 u32 temp_data;
376 610
@@ -393,7 +627,7 @@ EXPORT_SYMBOL(ec_read);
393int 627int
394ec_write(u8 addr, u8 val) 628ec_write(u8 addr, u8 val)
395{ 629{
396 struct acpi_ec *ec; 630 union acpi_ec *ec;
397 int err; 631 int err;
398 632
399 if (!first_ec) 633 if (!first_ec)
@@ -407,10 +641,66 @@ ec_write(u8 addr, u8 val)
407} 641}
408EXPORT_SYMBOL(ec_write); 642EXPORT_SYMBOL(ec_write);
409 643
410
411static int 644static int
412acpi_ec_query ( 645acpi_ec_query (
413 struct acpi_ec *ec, 646 union acpi_ec *ec,
647 u32 *data)
648{
649 if (acpi_ec_polling_mode)
650 return acpi_ec_polling_query(ec, data);
651 else
652 return acpi_ec_burst_query(ec, data);
653}
654static int
655acpi_ec_polling_query (
656 union acpi_ec *ec,
657 u32 *data)
658{
659 int result = 0;
660 acpi_status status = AE_OK;
661 unsigned long flags = 0;
662 u32 glk = 0;
663
664 ACPI_FUNCTION_TRACE("acpi_ec_query");
665
666 if (!ec || !data)
667 return_VALUE(-EINVAL);
668
669 *data = 0;
670
671 if (ec->common.global_lock) {
672 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
673 if (ACPI_FAILURE(status))
674 return_VALUE(-ENODEV);
675 }
676
677 /*
678 * Query the EC to find out which _Qxx method we need to evaluate.
679 * Note that successful completion of the query causes the ACPI_EC_SCI
680 * bit to be cleared (and thus clearing the interrupt source).
681 */
682 spin_lock_irqsave(&ec->polling.lock, flags);
683
684 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY, &ec->common.command_addr);
685 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
686 if (result)
687 goto end;
688
689 acpi_hw_low_level_read(8, data, &ec->common.data_addr);
690 if (!*data)
691 result = -ENODATA;
692
693end:
694 spin_unlock_irqrestore(&ec->polling.lock, flags);
695
696 if (ec->common.global_lock)
697 acpi_release_global_lock(glk);
698
699 return_VALUE(result);
700}
701static int
702acpi_ec_burst_query (
703 union acpi_ec *ec,
414 u32 *data) 704 u32 *data)
415{ 705{
416 int status = 0; 706 int status = 0;
@@ -422,13 +712,13 @@ acpi_ec_query (
422 return_VALUE(-EINVAL); 712 return_VALUE(-EINVAL);
423 *data = 0; 713 *data = 0;
424 714
425 if (ec->global_lock) { 715 if (ec->common.global_lock) {
426 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); 716 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
427 if (ACPI_FAILURE(status)) 717 if (ACPI_FAILURE(status))
428 return_VALUE(-ENODEV); 718 return_VALUE(-ENODEV);
429 } 719 }
430 720
431 down(&ec->sem); 721 down(&ec->burst.sem);
432 if(acpi_ec_enter_burst_mode(ec)) 722 if(acpi_ec_enter_burst_mode(ec))
433 goto end; 723 goto end;
434 /* 724 /*
@@ -436,28 +726,28 @@ acpi_ec_query (
436 * Note that successful completion of the query causes the ACPI_EC_SCI 726 * Note that successful completion of the query causes the ACPI_EC_SCI
437 * bit to be cleared (and thus clearing the interrupt source). 727 * bit to be cleared (and thus clearing the interrupt source).
438 */ 728 */
439 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY, &ec->command_addr); 729 acpi_hw_low_level_write(8, ACPI_EC_COMMAND_QUERY, &ec->common.command_addr);
440 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF); 730 status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF);
441 if (status){ 731 if (status){
442 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 732 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
443 goto end; 733 goto end;
444 } 734 }
445 735
446 acpi_hw_low_level_read(8, data, &ec->data_addr); 736 acpi_hw_low_level_read(8, data, &ec->common.data_addr);
447 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 737 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
448 if (!*data) 738 if (!*data)
449 status = -ENODATA; 739 status = -ENODATA;
450 740
451end: 741end:
452 acpi_ec_leave_burst_mode(ec); 742 acpi_ec_leave_burst_mode(ec);
453 up(&ec->sem); 743 up(&ec->burst.sem);
454 744
455 if (ec->global_lock) 745 if (ec->common.global_lock)
456 acpi_release_global_lock(glk); 746 acpi_release_global_lock(glk);
457 747
458 if(atomic_read(&ec->leaving_burst) == 2){ 748 if(atomic_read(&ec->burst.leaving_burst) == 2){
459 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n")); 749 ACPI_DEBUG_PRINT((ACPI_DB_INFO,"aborted, retry ...\n"));
460 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 750 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
461 status = -ENODATA; 751 status = -ENODATA;
462 } 752 }
463 return_VALUE(status); 753 return_VALUE(status);
@@ -468,7 +758,7 @@ end:
468 Event Management 758 Event Management
469 -------------------------------------------------------------------------- */ 759 -------------------------------------------------------------------------- */
470 760
471struct acpi_ec_query_data { 761union acpi_ec_query_data {
472 acpi_handle handle; 762 acpi_handle handle;
473 u8 data; 763 u8 data;
474}; 764};
@@ -477,7 +767,59 @@ static void
477acpi_ec_gpe_query ( 767acpi_ec_gpe_query (
478 void *ec_cxt) 768 void *ec_cxt)
479{ 769{
480 struct acpi_ec *ec = (struct acpi_ec *) ec_cxt; 770 if (acpi_ec_polling_mode)
771 acpi_ec_gpe_polling_query(ec_cxt);
772 else
773 acpi_ec_gpe_burst_query(ec_cxt);
774}
775
776static void
777acpi_ec_gpe_polling_query (
778 void *ec_cxt)
779{
780 union acpi_ec *ec = (union acpi_ec *) ec_cxt;
781 u32 value = 0;
782 unsigned long flags = 0;
783 static char object_name[5] = {'_','Q','0','0','\0'};
784 const char hex[] = {'0','1','2','3','4','5','6','7',
785 '8','9','A','B','C','D','E','F'};
786
787 ACPI_FUNCTION_TRACE("acpi_ec_gpe_query");
788
789 if (!ec_cxt)
790 goto end;
791
792 spin_lock_irqsave(&ec->polling.lock, flags);
793 acpi_hw_low_level_read(8, &value, &ec->common.command_addr);
794 spin_unlock_irqrestore(&ec->polling.lock, flags);
795
796 /* TBD: Implement asynch events!
797 * NOTE: All we care about are EC-SCI's. Other EC events are
798 * handled via polling (yuck!). This is because some systems
799 * treat EC-SCIs as level (versus EDGE!) triggered, preventing
800 * a purely interrupt-driven approach (grumble, grumble).
801 */
802 if (!(value & ACPI_EC_FLAG_SCI))
803 goto end;
804
805 if (acpi_ec_query(ec, &value))
806 goto end;
807
808 object_name[2] = hex[((value >> 4) & 0x0F)];
809 object_name[3] = hex[(value & 0x0F)];
810
811 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name));
812
813 acpi_evaluate_object(ec->common.handle, object_name, NULL, NULL);
814
815end:
816 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
817}
818static void
819acpi_ec_gpe_burst_query (
820 void *ec_cxt)
821{
822 union acpi_ec *ec = (union acpi_ec *) ec_cxt;
481 u32 value; 823 u32 value;
482 int result = -ENODATA; 824 int result = -ENODATA;
483 static char object_name[5] = {'_','Q','0','0','\0'}; 825 static char object_name[5] = {'_','Q','0','0','\0'};
@@ -497,9 +839,9 @@ acpi_ec_gpe_query (
497 839
498 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name)); 840 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s\n", object_name));
499 841
500 acpi_evaluate_object(ec->handle, object_name, NULL, NULL); 842 acpi_evaluate_object(ec->common.handle, object_name, NULL, NULL);
501end: 843end:
502 atomic_dec(&ec->pending_gpe); 844 atomic_dec(&ec->burst.pending_gpe);
503 return; 845 return;
504} 846}
505 847
@@ -507,48 +849,77 @@ static u32
507acpi_ec_gpe_handler ( 849acpi_ec_gpe_handler (
508 void *data) 850 void *data)
509{ 851{
852 if (acpi_ec_polling_mode)
853 return acpi_ec_gpe_polling_handler(data);
854 else
855 return acpi_ec_gpe_burst_handler(data);
856}
857static u32
858acpi_ec_gpe_polling_handler (
859 void *data)
860{
861 acpi_status status = AE_OK;
862 union acpi_ec *ec = (union acpi_ec *) data;
863
864 if (!ec)
865 return ACPI_INTERRUPT_NOT_HANDLED;
866
867 acpi_disable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR);
868
869 status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE,
870 acpi_ec_gpe_query, ec);
871
872 if (status == AE_OK)
873 return ACPI_INTERRUPT_HANDLED;
874 else
875 return ACPI_INTERRUPT_NOT_HANDLED;
876}
877static u32
878acpi_ec_gpe_burst_handler (
879 void *data)
880{
510 acpi_status status = AE_OK; 881 acpi_status status = AE_OK;
511 u32 value; 882 u32 value;
512 struct acpi_ec *ec = (struct acpi_ec *) data; 883 union acpi_ec *ec = (union acpi_ec *) data;
513 884
514 if (!ec) 885 if (!ec)
515 return ACPI_INTERRUPT_NOT_HANDLED; 886 return ACPI_INTERRUPT_NOT_HANDLED;
516 887
517 acpi_disable_gpe(NULL, ec->gpe_bit, ACPI_ISR); 888 acpi_disable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR);
518 889
519 value = acpi_ec_read_status(ec); 890 value = acpi_ec_read_status(ec);
520 891
521 if((value & ACPI_EC_FLAG_IBF) && 892 if((value & ACPI_EC_FLAG_IBF) &&
522 !(value & ACPI_EC_FLAG_BURST) && 893 !(value & ACPI_EC_FLAG_BURST) &&
523 (atomic_read(&ec->leaving_burst) == 0)) { 894 (atomic_read(&ec->burst.leaving_burst) == 0)) {
524 /* 895 /*
525 * the embedded controller disables 896 * the embedded controller disables
526 * burst mode for any reason other 897 * burst mode for any reason other
527 * than the burst disable command 898 * than the burst disable command
528 * to process critical event. 899 * to process critical event.
529 */ 900 */
530 atomic_set(&ec->leaving_burst , 2); /* block current pending transaction 901 atomic_set(&ec->burst.leaving_burst , 2); /* block current pending transaction
531 and retry */ 902 and retry */
532 wake_up(&ec->wait); 903 wake_up(&ec->burst.wait);
533 }else { 904 }else {
534 if ((ec->expect_event == ACPI_EC_EVENT_OBF && 905 if ((ec->burst.expect_event == ACPI_EC_EVENT_OBF &&
535 (value & ACPI_EC_FLAG_OBF)) || 906 (value & ACPI_EC_FLAG_OBF)) ||
536 (ec->expect_event == ACPI_EC_EVENT_IBE && 907 (ec->burst.expect_event == ACPI_EC_EVENT_IBE &&
537 !(value & ACPI_EC_FLAG_IBF))) { 908 !(value & ACPI_EC_FLAG_IBF))) {
538 ec->expect_event = 0; 909 ec->burst.expect_event = 0;
539 wake_up(&ec->wait); 910 wake_up(&ec->burst.wait);
540 return ACPI_INTERRUPT_HANDLED; 911 return ACPI_INTERRUPT_HANDLED;
541 } 912 }
542 } 913 }
543 914
544 if (value & ACPI_EC_FLAG_SCI){ 915 if (value & ACPI_EC_FLAG_SCI){
545 atomic_add(1, &ec->pending_gpe) ; 916 atomic_add(1, &ec->burst.pending_gpe) ;
546 status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE, 917 status = acpi_os_queue_for_execution(OSD_PRIORITY_GPE,
547 acpi_ec_gpe_query, ec); 918 acpi_ec_gpe_query, ec);
548 return status == AE_OK ? 919 return status == AE_OK ?
549 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; 920 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
550 } 921 }
551 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_ISR); 922 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_ISR);
552 return status == AE_OK ? 923 return status == AE_OK ?
553 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; 924 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
554} 925}
@@ -585,7 +956,7 @@ acpi_ec_space_handler (
585 void *region_context) 956 void *region_context)
586{ 957{
587 int result = 0; 958 int result = 0;
588 struct acpi_ec *ec = NULL; 959 union acpi_ec *ec = NULL;
589 u64 temp = *value; 960 u64 temp = *value;
590 acpi_integer f_v = 0; 961 acpi_integer f_v = 0;
591 int i = 0; 962 int i = 0;
@@ -600,7 +971,7 @@ acpi_ec_space_handler (
600 return_VALUE(AE_BAD_PARAMETER); 971 return_VALUE(AE_BAD_PARAMETER);
601 } 972 }
602 973
603 ec = (struct acpi_ec *) handler_context; 974 ec = (union acpi_ec *) handler_context;
604 975
605next_byte: 976next_byte:
606 switch (function) { 977 switch (function) {
@@ -661,7 +1032,7 @@ static struct proc_dir_entry *acpi_ec_dir;
661static int 1032static int
662acpi_ec_read_info (struct seq_file *seq, void *offset) 1033acpi_ec_read_info (struct seq_file *seq, void *offset)
663{ 1034{
664 struct acpi_ec *ec = (struct acpi_ec *) seq->private; 1035 union acpi_ec *ec = (union acpi_ec *) seq->private;
665 1036
666 ACPI_FUNCTION_TRACE("acpi_ec_read_info"); 1037 ACPI_FUNCTION_TRACE("acpi_ec_read_info");
667 1038
@@ -669,12 +1040,12 @@ acpi_ec_read_info (struct seq_file *seq, void *offset)
669 goto end; 1040 goto end;
670 1041
671 seq_printf(seq, "gpe bit: 0x%02x\n", 1042 seq_printf(seq, "gpe bit: 0x%02x\n",
672 (u32) ec->gpe_bit); 1043 (u32) ec->common.gpe_bit);
673 seq_printf(seq, "ports: 0x%02x, 0x%02x\n", 1044 seq_printf(seq, "ports: 0x%02x, 0x%02x\n",
674 (u32) ec->status_addr.address, (u32) ec->data_addr.address); 1045 (u32) ec->common.status_addr.address, (u32) ec->common.data_addr.address);
675 seq_printf(seq, "use global lock: %s\n", 1046 seq_printf(seq, "use global lock: %s\n",
676 ec->global_lock?"yes":"no"); 1047 ec->common.global_lock?"yes":"no");
677 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 1048 acpi_enable_gpe(NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
678 1049
679end: 1050end:
680 return_VALUE(0); 1051 return_VALUE(0);
@@ -697,7 +1068,7 @@ static int
697acpi_ec_add_fs ( 1068acpi_ec_add_fs (
698 struct acpi_device *device) 1069 struct acpi_device *device)
699{ 1070{
700 struct proc_dir_entry *entry; 1071 struct proc_dir_entry *entry = NULL;
701 1072
702 ACPI_FUNCTION_TRACE("acpi_ec_add_fs"); 1073 ACPI_FUNCTION_TRACE("acpi_ec_add_fs");
703 1074
@@ -744,13 +1115,14 @@ acpi_ec_remove_fs (
744 Driver Interface 1115 Driver Interface
745 -------------------------------------------------------------------------- */ 1116 -------------------------------------------------------------------------- */
746 1117
1118
747static int 1119static int
748acpi_ec_add ( 1120acpi_ec_polling_add (
749 struct acpi_device *device) 1121 struct acpi_device *device)
750{ 1122{
751 int result; 1123 int result = 0;
752 acpi_status status; 1124 acpi_status status = AE_OK;
753 struct acpi_ec *ec; 1125 union acpi_ec *ec = NULL;
754 unsigned long uid; 1126 unsigned long uid;
755 1127
756 ACPI_FUNCTION_TRACE("acpi_ec_add"); 1128 ACPI_FUNCTION_TRACE("acpi_ec_add");
@@ -758,39 +1130,107 @@ acpi_ec_add (
758 if (!device) 1130 if (!device)
759 return_VALUE(-EINVAL); 1131 return_VALUE(-EINVAL);
760 1132
761 ec = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); 1133 ec = kmalloc(sizeof(union acpi_ec), GFP_KERNEL);
762 if (!ec) 1134 if (!ec)
763 return_VALUE(-ENOMEM); 1135 return_VALUE(-ENOMEM);
764 memset(ec, 0, sizeof(struct acpi_ec)); 1136 memset(ec, 0, sizeof(union acpi_ec));
765 1137
766 ec->handle = device->handle; 1138 ec->common.handle = device->handle;
767 ec->uid = -1; 1139 ec->common.uid = -1;
768 atomic_set(&ec->pending_gpe, 0); 1140 spin_lock_init(&ec->polling.lock);
769 atomic_set(&ec->leaving_burst , 1);
770 init_MUTEX(&ec->sem);
771 init_waitqueue_head(&ec->wait);
772 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); 1141 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
773 strcpy(acpi_device_class(device), ACPI_EC_CLASS); 1142 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
774 acpi_driver_data(device) = ec; 1143 acpi_driver_data(device) = ec;
775 1144
776 /* Use the global lock for all EC transactions? */ 1145 /* Use the global lock for all EC transactions? */
777 acpi_evaluate_integer(ec->handle, "_GLK", NULL, &ec->global_lock); 1146 acpi_evaluate_integer(ec->common.handle, "_GLK", NULL, &ec->common.global_lock);
778 1147
779 /* If our UID matches the UID for the ECDT-enumerated EC, 1148 /* If our UID matches the UID for the ECDT-enumerated EC,
780 we now have the *real* EC info, so kill the makeshift one.*/ 1149 we now have the *real* EC info, so kill the makeshift one.*/
781 acpi_evaluate_integer(ec->handle, "_UID", NULL, &uid); 1150 acpi_evaluate_integer(ec->common.handle, "_UID", NULL, &uid);
782 if (ec_ecdt && ec_ecdt->uid == uid) { 1151 if (ec_ecdt && ec_ecdt->common.uid == uid) {
783 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT, 1152 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT,
784 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler); 1153 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler);
1154
1155 acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit, &acpi_ec_gpe_handler);
1156
1157 kfree(ec_ecdt);
1158 }
1159
1160 /* Get GPE bit assignment (EC events). */
1161 /* TODO: Add support for _GPE returning a package */
1162 status = acpi_evaluate_integer(ec->common.handle, "_GPE", NULL, &ec->common.gpe_bit);
1163 if (ACPI_FAILURE(status)) {
1164 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1165 "Error obtaining GPE bit assignment\n"));
1166 result = -ENODEV;
1167 goto end;
1168 }
785 1169
786 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit, &acpi_ec_gpe_handler); 1170 result = acpi_ec_add_fs(device);
1171 if (result)
1172 goto end;
1173
1174 printk(KERN_INFO PREFIX "%s [%s] (gpe %d)\n",
1175 acpi_device_name(device), acpi_device_bid(device),
1176 (u32) ec->common.gpe_bit);
1177
1178 if (!first_ec)
1179 first_ec = device;
1180
1181end:
1182 if (result)
1183 kfree(ec);
1184
1185 return_VALUE(result);
1186}
1187static int
1188acpi_ec_burst_add (
1189 struct acpi_device *device)
1190{
1191 int result = 0;
1192 acpi_status status = AE_OK;
1193 union acpi_ec *ec = NULL;
1194 unsigned long uid;
1195
1196 ACPI_FUNCTION_TRACE("acpi_ec_add");
1197
1198 if (!device)
1199 return_VALUE(-EINVAL);
1200
1201 ec = kmalloc(sizeof(union acpi_ec), GFP_KERNEL);
1202 if (!ec)
1203 return_VALUE(-ENOMEM);
1204 memset(ec, 0, sizeof(union acpi_ec));
1205
1206 ec->common.handle = device->handle;
1207 ec->common.uid = -1;
1208 atomic_set(&ec->burst.pending_gpe, 0);
1209 atomic_set(&ec->burst.leaving_burst , 1);
1210 init_MUTEX(&ec->burst.sem);
1211 init_waitqueue_head(&ec->burst.wait);
1212 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
1213 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
1214 acpi_driver_data(device) = ec;
1215
1216 /* Use the global lock for all EC transactions? */
1217 acpi_evaluate_integer(ec->common.handle, "_GLK", NULL, &ec->common.global_lock);
1218
1219 /* If our UID matches the UID for the ECDT-enumerated EC,
1220 we now have the *real* EC info, so kill the makeshift one.*/
1221 acpi_evaluate_integer(ec->common.handle, "_UID", NULL, &uid);
1222 if (ec_ecdt && ec_ecdt->common.uid == uid) {
1223 acpi_remove_address_space_handler(ACPI_ROOT_OBJECT,
1224 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler);
1225
1226 acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit, &acpi_ec_gpe_handler);
787 1227
788 kfree(ec_ecdt); 1228 kfree(ec_ecdt);
789 } 1229 }
790 1230
791 /* Get GPE bit assignment (EC events). */ 1231 /* Get GPE bit assignment (EC events). */
792 /* TODO: Add support for _GPE returning a package */ 1232 /* TODO: Add support for _GPE returning a package */
793 status = acpi_evaluate_integer(ec->handle, "_GPE", NULL, &ec->gpe_bit); 1233 status = acpi_evaluate_integer(ec->common.handle, "_GPE", NULL, &ec->common.gpe_bit);
794 if (ACPI_FAILURE(status)) { 1234 if (ACPI_FAILURE(status)) {
795 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1235 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
796 "Error obtaining GPE bit assignment\n")); 1236 "Error obtaining GPE bit assignment\n"));
@@ -804,7 +1244,7 @@ acpi_ec_add (
804 1244
805 printk(KERN_INFO PREFIX "%s [%s] (gpe %d)\n", 1245 printk(KERN_INFO PREFIX "%s [%s] (gpe %d)\n",
806 acpi_device_name(device), acpi_device_bid(device), 1246 acpi_device_name(device), acpi_device_bid(device),
807 (u32) ec->gpe_bit); 1247 (u32) ec->common.gpe_bit);
808 1248
809 if (!first_ec) 1249 if (!first_ec)
810 first_ec = device; 1250 first_ec = device;
@@ -822,7 +1262,7 @@ acpi_ec_remove (
822 struct acpi_device *device, 1262 struct acpi_device *device,
823 int type) 1263 int type)
824{ 1264{
825 struct acpi_ec *ec; 1265 union acpi_ec *ec = NULL;
826 1266
827 ACPI_FUNCTION_TRACE("acpi_ec_remove"); 1267 ACPI_FUNCTION_TRACE("acpi_ec_remove");
828 1268
@@ -844,7 +1284,7 @@ acpi_ec_io_ports (
844 struct acpi_resource *resource, 1284 struct acpi_resource *resource,
845 void *context) 1285 void *context)
846{ 1286{
847 struct acpi_ec *ec = (struct acpi_ec *) context; 1287 union acpi_ec *ec = (union acpi_ec *) context;
848 struct acpi_generic_address *addr; 1288 struct acpi_generic_address *addr;
849 1289
850 if (resource->id != ACPI_RSTYPE_IO) { 1290 if (resource->id != ACPI_RSTYPE_IO) {
@@ -856,10 +1296,10 @@ acpi_ec_io_ports (
856 * the second address region returned is the status/command 1296 * the second address region returned is the status/command
857 * port. 1297 * port.
858 */ 1298 */
859 if (ec->data_addr.register_bit_width == 0) { 1299 if (ec->common.data_addr.register_bit_width == 0) {
860 addr = &ec->data_addr; 1300 addr = &ec->common.data_addr;
861 } else if (ec->command_addr.register_bit_width == 0) { 1301 } else if (ec->common.command_addr.register_bit_width == 0) {
862 addr = &ec->command_addr; 1302 addr = &ec->common.command_addr;
863 } else { 1303 } else {
864 return AE_CTRL_TERMINATE; 1304 return AE_CTRL_TERMINATE;
865 } 1305 }
@@ -877,8 +1317,8 @@ static int
877acpi_ec_start ( 1317acpi_ec_start (
878 struct acpi_device *device) 1318 struct acpi_device *device)
879{ 1319{
880 acpi_status status; 1320 acpi_status status = AE_OK;
881 struct acpi_ec *ec; 1321 union acpi_ec *ec = NULL;
882 1322
883 ACPI_FUNCTION_TRACE("acpi_ec_start"); 1323 ACPI_FUNCTION_TRACE("acpi_ec_start");
884 1324
@@ -893,35 +1333,36 @@ acpi_ec_start (
893 /* 1333 /*
894 * Get I/O port addresses. Convert to GAS format. 1334 * Get I/O port addresses. Convert to GAS format.
895 */ 1335 */
896 status = acpi_walk_resources(ec->handle, METHOD_NAME__CRS, 1336 status = acpi_walk_resources(ec->common.handle, METHOD_NAME__CRS,
897 acpi_ec_io_ports, ec); 1337 acpi_ec_io_ports, ec);
898 if (ACPI_FAILURE(status) || ec->command_addr.register_bit_width == 0) { 1338 if (ACPI_FAILURE(status) || ec->common.command_addr.register_bit_width == 0) {
899 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error getting I/O port addresses")); 1339 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error getting I/O port addresses"));
900 return_VALUE(-ENODEV); 1340 return_VALUE(-ENODEV);
901 } 1341 }
902 1342
903 ec->status_addr = ec->command_addr; 1343 ec->common.status_addr = ec->common.command_addr;
904 1344
905 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02x, ports=0x%2x,0x%2x\n", 1345 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02x, ports=0x%2x,0x%2x\n",
906 (u32) ec->gpe_bit, (u32) ec->command_addr.address, 1346 (u32) ec->common.gpe_bit, (u32) ec->common.command_addr.address,
907 (u32) ec->data_addr.address)); 1347 (u32) ec->common.data_addr.address));
1348
908 1349
909 /* 1350 /*
910 * Install GPE handler 1351 * Install GPE handler
911 */ 1352 */
912 status = acpi_install_gpe_handler(NULL, ec->gpe_bit, 1353 status = acpi_install_gpe_handler(NULL, ec->common.gpe_bit,
913 ACPI_GPE_EDGE_TRIGGERED, &acpi_ec_gpe_handler, ec); 1354 ACPI_GPE_EDGE_TRIGGERED, &acpi_ec_gpe_handler, ec);
914 if (ACPI_FAILURE(status)) { 1355 if (ACPI_FAILURE(status)) {
915 return_VALUE(-ENODEV); 1356 return_VALUE(-ENODEV);
916 } 1357 }
917 acpi_set_gpe_type (NULL, ec->gpe_bit, ACPI_GPE_TYPE_RUNTIME); 1358 acpi_set_gpe_type (NULL, ec->common.gpe_bit, ACPI_GPE_TYPE_RUNTIME);
918 acpi_enable_gpe (NULL, ec->gpe_bit, ACPI_NOT_ISR); 1359 acpi_enable_gpe (NULL, ec->common.gpe_bit, ACPI_NOT_ISR);
919 1360
920 status = acpi_install_address_space_handler (ec->handle, 1361 status = acpi_install_address_space_handler (ec->common.handle,
921 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler, 1362 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler,
922 &acpi_ec_space_setup, ec); 1363 &acpi_ec_space_setup, ec);
923 if (ACPI_FAILURE(status)) { 1364 if (ACPI_FAILURE(status)) {
924 acpi_remove_gpe_handler(NULL, ec->gpe_bit, &acpi_ec_gpe_handler); 1365 acpi_remove_gpe_handler(NULL, ec->common.gpe_bit, &acpi_ec_gpe_handler);
925 return_VALUE(-ENODEV); 1366 return_VALUE(-ENODEV);
926 } 1367 }
927 1368
@@ -934,8 +1375,8 @@ acpi_ec_stop (
934 struct acpi_device *device, 1375 struct acpi_device *device,
935 int type) 1376 int type)
936{ 1377{
937 acpi_status status; 1378 acpi_status status = AE_OK;
938 struct acpi_ec *ec; 1379 union acpi_ec *ec = NULL;
939 1380
940 ACPI_FUNCTION_TRACE("acpi_ec_stop"); 1381 ACPI_FUNCTION_TRACE("acpi_ec_stop");
941 1382
@@ -944,12 +1385,12 @@ acpi_ec_stop (
944 1385
945 ec = acpi_driver_data(device); 1386 ec = acpi_driver_data(device);
946 1387
947 status = acpi_remove_address_space_handler(ec->handle, 1388 status = acpi_remove_address_space_handler(ec->common.handle,
948 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler); 1389 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler);
949 if (ACPI_FAILURE(status)) 1390 if (ACPI_FAILURE(status))
950 return_VALUE(-ENODEV); 1391 return_VALUE(-ENODEV);
951 1392
952 status = acpi_remove_gpe_handler(NULL, ec->gpe_bit, &acpi_ec_gpe_handler); 1393 status = acpi_remove_gpe_handler(NULL, ec->common.gpe_bit, &acpi_ec_gpe_handler);
953 if (ACPI_FAILURE(status)) 1394 if (ACPI_FAILURE(status))
954 return_VALUE(-ENODEV); 1395 return_VALUE(-ENODEV);
955 1396
@@ -963,26 +1404,76 @@ acpi_fake_ecdt_callback (
963 void *context, 1404 void *context,
964 void **retval) 1405 void **retval)
965{ 1406{
1407
1408 if (acpi_ec_polling_mode)
1409 return acpi_fake_ecdt_polling_callback(handle,
1410 Level, context, retval);
1411 else
1412 return acpi_fake_ecdt_burst_callback(handle,
1413 Level, context, retval);
1414}
1415
1416static acpi_status __init
1417acpi_fake_ecdt_polling_callback (
1418 acpi_handle handle,
1419 u32 Level,
1420 void *context,
1421 void **retval)
1422{
966 acpi_status status; 1423 acpi_status status;
967 1424
968 status = acpi_walk_resources(handle, METHOD_NAME__CRS, 1425 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
969 acpi_ec_io_ports, ec_ecdt); 1426 acpi_ec_io_ports, ec_ecdt);
970 if (ACPI_FAILURE(status)) 1427 if (ACPI_FAILURE(status))
971 return status; 1428 return status;
972 ec_ecdt->status_addr = ec_ecdt->command_addr; 1429 ec_ecdt->common.status_addr = ec_ecdt->common.command_addr;
973 1430
974 ec_ecdt->uid = -1; 1431 ec_ecdt->common.uid = -1;
975 acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->uid); 1432 acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->common.uid);
976 1433
977 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->gpe_bit); 1434 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->common.gpe_bit);
978 if (ACPI_FAILURE(status)) 1435 if (ACPI_FAILURE(status))
979 return status; 1436 return status;
980 ec_ecdt->global_lock = TRUE; 1437 spin_lock_init(&ec_ecdt->polling.lock);
981 ec_ecdt->handle = handle; 1438 ec_ecdt->common.global_lock = TRUE;
1439 ec_ecdt->common.handle = handle;
982 1440
983 printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n", 1441 printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n",
984 (u32) ec_ecdt->gpe_bit, (u32) ec_ecdt->command_addr.address, 1442 (u32) ec_ecdt->common.gpe_bit, (u32) ec_ecdt->common.command_addr.address,
985 (u32) ec_ecdt->data_addr.address); 1443 (u32) ec_ecdt->common.data_addr.address);
1444
1445 return AE_CTRL_TERMINATE;
1446}
1447
1448static acpi_status __init
1449acpi_fake_ecdt_burst_callback (
1450 acpi_handle handle,
1451 u32 Level,
1452 void *context,
1453 void **retval)
1454{
1455 acpi_status status;
1456
1457 init_MUTEX(&ec_ecdt->burst.sem);
1458 init_waitqueue_head(&ec_ecdt->burst.wait);
1459 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
1460 acpi_ec_io_ports, ec_ecdt);
1461 if (ACPI_FAILURE(status))
1462 return status;
1463 ec_ecdt->common.status_addr = ec_ecdt->common.command_addr;
1464
1465 ec_ecdt->common.uid = -1;
1466 acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->common.uid);
1467
1468 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->common.gpe_bit);
1469 if (ACPI_FAILURE(status))
1470 return status;
1471 ec_ecdt->common.global_lock = TRUE;
1472 ec_ecdt->common.handle = handle;
1473
1474 printk(KERN_INFO PREFIX "GPE=0x%02x, ports=0x%2x, 0x%2x\n",
1475 (u32) ec_ecdt->common.gpe_bit, (u32) ec_ecdt->common.command_addr.address,
1476 (u32) ec_ecdt->common.data_addr.address);
986 1477
987 return AE_CTRL_TERMINATE; 1478 return AE_CTRL_TERMINATE;
988} 1479}
@@ -1005,12 +1496,12 @@ acpi_ec_fake_ecdt(void)
1005 1496
1006 printk(KERN_INFO PREFIX "Try to make an fake ECDT\n"); 1497 printk(KERN_INFO PREFIX "Try to make an fake ECDT\n");
1007 1498
1008 ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); 1499 ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL);
1009 if (!ec_ecdt) { 1500 if (!ec_ecdt) {
1010 ret = -ENOMEM; 1501 ret = -ENOMEM;
1011 goto error; 1502 goto error;
1012 } 1503 }
1013 memset(ec_ecdt, 0, sizeof(struct acpi_ec)); 1504 memset(ec_ecdt, 0, sizeof(union acpi_ec));
1014 1505
1015 status = acpi_get_devices (ACPI_EC_HID, 1506 status = acpi_get_devices (ACPI_EC_HID,
1016 acpi_fake_ecdt_callback, 1507 acpi_fake_ecdt_callback,
@@ -1031,6 +1522,60 @@ error:
1031static int __init 1522static int __init
1032acpi_ec_get_real_ecdt(void) 1523acpi_ec_get_real_ecdt(void)
1033{ 1524{
1525 if (acpi_ec_polling_mode)
1526 return acpi_ec_polling_get_real_ecdt();
1527 else
1528 return acpi_ec_burst_get_real_ecdt();
1529}
1530
1531static int __init
1532acpi_ec_polling_get_real_ecdt(void)
1533{
1534 acpi_status status;
1535 struct acpi_table_ecdt *ecdt_ptr;
1536
1537 status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING,
1538 (struct acpi_table_header **) &ecdt_ptr);
1539 if (ACPI_FAILURE(status))
1540 return -ENODEV;
1541
1542 printk(KERN_INFO PREFIX "Found ECDT\n");
1543
1544 /*
1545 * Generate a temporary ec context to use until the namespace is scanned
1546 */
1547 ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL);
1548 if (!ec_ecdt)
1549 return -ENOMEM;
1550 memset(ec_ecdt, 0, sizeof(union acpi_ec));
1551
1552 ec_ecdt->common.command_addr = ecdt_ptr->ec_control;
1553 ec_ecdt->common.status_addr = ecdt_ptr->ec_control;
1554 ec_ecdt->common.data_addr = ecdt_ptr->ec_data;
1555 ec_ecdt->common.gpe_bit = ecdt_ptr->gpe_bit;
1556 spin_lock_init(&ec_ecdt->polling.lock);
1557 /* use the GL just to be safe */
1558 ec_ecdt->common.global_lock = TRUE;
1559 ec_ecdt->common.uid = ecdt_ptr->uid;
1560
1561 status = acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->common.handle);
1562 if (ACPI_FAILURE(status)) {
1563 goto error;
1564 }
1565
1566 return 0;
1567error:
1568 printk(KERN_ERR PREFIX "Could not use ECDT\n");
1569 kfree(ec_ecdt);
1570 ec_ecdt = NULL;
1571
1572 return -ENODEV;
1573}
1574
1575
1576static int __init
1577acpi_ec_burst_get_real_ecdt(void)
1578{
1034 acpi_status status; 1579 acpi_status status;
1035 struct acpi_table_ecdt *ecdt_ptr; 1580 struct acpi_table_ecdt *ecdt_ptr;
1036 1581
@@ -1044,22 +1589,22 @@ acpi_ec_get_real_ecdt(void)
1044 /* 1589 /*
1045 * Generate a temporary ec context to use until the namespace is scanned 1590 * Generate a temporary ec context to use until the namespace is scanned
1046 */ 1591 */
1047 ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); 1592 ec_ecdt = kmalloc(sizeof(union acpi_ec), GFP_KERNEL);
1048 if (!ec_ecdt) 1593 if (!ec_ecdt)
1049 return -ENOMEM; 1594 return -ENOMEM;
1050 memset(ec_ecdt, 0, sizeof(struct acpi_ec)); 1595 memset(ec_ecdt, 0, sizeof(union acpi_ec));
1051 1596
1052 init_MUTEX(&ec_ecdt->sem); 1597 init_MUTEX(&ec_ecdt->burst.sem);
1053 init_waitqueue_head(&ec_ecdt->wait); 1598 init_waitqueue_head(&ec_ecdt->burst.wait);
1054 ec_ecdt->command_addr = ecdt_ptr->ec_control; 1599 ec_ecdt->common.command_addr = ecdt_ptr->ec_control;
1055 ec_ecdt->status_addr = ecdt_ptr->ec_control; 1600 ec_ecdt->common.status_addr = ecdt_ptr->ec_control;
1056 ec_ecdt->data_addr = ecdt_ptr->ec_data; 1601 ec_ecdt->common.data_addr = ecdt_ptr->ec_data;
1057 ec_ecdt->gpe_bit = ecdt_ptr->gpe_bit; 1602 ec_ecdt->common.gpe_bit = ecdt_ptr->gpe_bit;
1058 /* use the GL just to be safe */ 1603 /* use the GL just to be safe */
1059 ec_ecdt->global_lock = TRUE; 1604 ec_ecdt->common.global_lock = TRUE;
1060 ec_ecdt->uid = ecdt_ptr->uid; 1605 ec_ecdt->common.uid = ecdt_ptr->uid;
1061 1606
1062 status = acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->handle); 1607 status = acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->common.handle);
1063 if (ACPI_FAILURE(status)) { 1608 if (ACPI_FAILURE(status)) {
1064 goto error; 1609 goto error;
1065 } 1610 }
@@ -1092,20 +1637,20 @@ acpi_ec_ecdt_probe (void)
1092 /* 1637 /*
1093 * Install GPE handler 1638 * Install GPE handler
1094 */ 1639 */
1095 status = acpi_install_gpe_handler(NULL, ec_ecdt->gpe_bit, 1640 status = acpi_install_gpe_handler(NULL, ec_ecdt->common.gpe_bit,
1096 ACPI_GPE_EDGE_TRIGGERED, &acpi_ec_gpe_handler, 1641 ACPI_GPE_EDGE_TRIGGERED, &acpi_ec_gpe_handler,
1097 ec_ecdt); 1642 ec_ecdt);
1098 if (ACPI_FAILURE(status)) { 1643 if (ACPI_FAILURE(status)) {
1099 goto error; 1644 goto error;
1100 } 1645 }
1101 acpi_set_gpe_type (NULL, ec_ecdt->gpe_bit, ACPI_GPE_TYPE_RUNTIME); 1646 acpi_set_gpe_type (NULL, ec_ecdt->common.gpe_bit, ACPI_GPE_TYPE_RUNTIME);
1102 acpi_enable_gpe (NULL, ec_ecdt->gpe_bit, ACPI_NOT_ISR); 1647 acpi_enable_gpe (NULL, ec_ecdt->common.gpe_bit, ACPI_NOT_ISR);
1103 1648
1104 status = acpi_install_address_space_handler (ACPI_ROOT_OBJECT, 1649 status = acpi_install_address_space_handler (ACPI_ROOT_OBJECT,
1105 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler, 1650 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler,
1106 &acpi_ec_space_setup, ec_ecdt); 1651 &acpi_ec_space_setup, ec_ecdt);
1107 if (ACPI_FAILURE(status)) { 1652 if (ACPI_FAILURE(status)) {
1108 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit, 1653 acpi_remove_gpe_handler(NULL, ec_ecdt->common.gpe_bit,
1109 &acpi_ec_gpe_handler); 1654 &acpi_ec_gpe_handler);
1110 goto error; 1655 goto error;
1111 } 1656 }
@@ -1123,7 +1668,7 @@ error:
1123 1668
1124static int __init acpi_ec_init (void) 1669static int __init acpi_ec_init (void)
1125{ 1670{
1126 int result; 1671 int result = 0;
1127 1672
1128 ACPI_FUNCTION_TRACE("acpi_ec_init"); 1673 ACPI_FUNCTION_TRACE("acpi_ec_init");
1129 1674
@@ -1166,4 +1711,24 @@ static int __init acpi_fake_ecdt_setup(char *str)
1166 acpi_fake_ecdt_enabled = 1; 1711 acpi_fake_ecdt_enabled = 1;
1167 return 0; 1712 return 0;
1168} 1713}
1714
1169__setup("acpi_fake_ecdt", acpi_fake_ecdt_setup); 1715__setup("acpi_fake_ecdt", acpi_fake_ecdt_setup);
1716static int __init acpi_ec_set_polling_mode(char *str)
1717{
1718 int burst;
1719
1720 if (!get_option(&str, &burst))
1721 return 0;
1722
1723 if (burst) {
1724 acpi_ec_polling_mode = EC_BURST;
1725 acpi_ec_driver.ops.add = acpi_ec_burst_add;
1726 } else {
1727 acpi_ec_polling_mode = EC_POLLING;
1728 acpi_ec_driver.ops.add = acpi_ec_polling_add;
1729 }
1730 printk(KERN_INFO PREFIX "EC %s mode.\n",
1731 burst ? "burst": "polling");
1732 return 0;
1733}
1734__setup("ec_burst=", acpi_ec_set_polling_mode);
diff --git a/drivers/acpi/hotkey.c b/drivers/acpi/hotkey.c
index babdf762eadb..1f76a40badec 100644
--- a/drivers/acpi/hotkey.c
+++ b/drivers/acpi/hotkey.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * hotkey.c - ACPI Hotkey Driver ($Revision:$) 2 * hotkey.c - ACPI Hotkey Driver ($Revision: 0.2 $)
3 * 3 *
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com> 4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 * 5 *
@@ -51,17 +51,18 @@
51#define ACPI_HOTKEY_POLLING 0x2 51#define ACPI_HOTKEY_POLLING 0x2
52#define ACPI_UNDEFINED_EVENT 0xf 52#define ACPI_UNDEFINED_EVENT 0xf
53 53
54#define MAX_CONFIG_RECORD_LEN 80 54#define RESULT_STR_LEN 80
55#define MAX_NAME_PATH_LEN 80
56#define MAX_CALL_PARM 80
57 55
58#define IS_EVENT(e) 0xff /* ((e) & 0x40000000) */ 56#define ACTION_METHOD 0
59#define IS_POLL(e) 0xff /* (~((e) & 0x40000000)) */ 57#define POLL_METHOD 1
60 58
59#define IS_EVENT(e) ((e) <= 10000 && (e) >0)
60#define IS_POLL(e) ((e) > 10000)
61#define IS_OTHERS(e) ((e)<=0 || (e)>=20000)
61#define _COMPONENT ACPI_HOTKEY_COMPONENT 62#define _COMPONENT ACPI_HOTKEY_COMPONENT
62ACPI_MODULE_NAME("acpi_hotkey") 63ACPI_MODULE_NAME("acpi_hotkey")
63 64
64 MODULE_AUTHOR("luming.yu@intel.com"); 65MODULE_AUTHOR("luming.yu@intel.com");
65MODULE_DESCRIPTION(ACPI_HOTK_NAME); 66MODULE_DESCRIPTION(ACPI_HOTK_NAME);
66MODULE_LICENSE("GPL"); 67MODULE_LICENSE("GPL");
67 68
@@ -114,7 +115,7 @@ struct acpi_event_hotkey {
114 char *action_method; /* action method */ 115 char *action_method; /* action method */
115}; 116};
116 117
117/* 118/*
118 * There are two ways to poll status 119 * There are two ways to poll status
119 * 1. directy call read_xxx method, without any arguments passed in 120 * 1. directy call read_xxx method, without any arguments passed in
120 * 2. call write_xxx method, with arguments passed in, you need 121 * 2. call write_xxx method, with arguments passed in, you need
@@ -131,7 +132,7 @@ struct acpi_polling_hotkey {
131 char *poll_method; /* poll method */ 132 char *poll_method; /* poll method */
132 acpi_handle action_handle; /* acpi handle attached action method */ 133 acpi_handle action_handle; /* acpi handle attached action method */
133 char *action_method; /* action method */ 134 char *action_method; /* action method */
134 void *poll_result; /* polling_result */ 135 union acpi_object *poll_result; /* polling_result */
135 struct proc_dir_entry *proc; 136 struct proc_dir_entry *proc;
136}; 137};
137 138
@@ -162,20 +163,25 @@ static struct acpi_driver hotkey_driver = {
162 }, 163 },
163}; 164};
164 165
166static void free_hotkey_device(union acpi_hotkey *key);
167static void free_hotkey_buffer(union acpi_hotkey *key);
168static void free_poll_hotkey_buffer(union acpi_hotkey *key);
165static int hotkey_open_config(struct inode *inode, struct file *file); 169static int hotkey_open_config(struct inode *inode, struct file *file);
170static int hotkey_poll_open_config(struct inode *inode, struct file *file);
166static ssize_t hotkey_write_config(struct file *file, 171static ssize_t hotkey_write_config(struct file *file,
167 const char __user * buffer, 172 const char __user * buffer,
168 size_t count, loff_t * data); 173 size_t count, loff_t * data);
169static ssize_t hotkey_write_poll_config(struct file *file,
170 const char __user * buffer,
171 size_t count, loff_t * data);
172static int hotkey_info_open_fs(struct inode *inode, struct file *file); 174static int hotkey_info_open_fs(struct inode *inode, struct file *file);
173static int hotkey_action_open_fs(struct inode *inode, struct file *file); 175static int hotkey_action_open_fs(struct inode *inode, struct file *file);
174static ssize_t hotkey_execute_aml_method(struct file *file, 176static ssize_t hotkey_execute_aml_method(struct file *file,
175 const char __user * buffer, 177 const char __user * buffer,
176 size_t count, loff_t * data); 178 size_t count, loff_t * data);
177static int hotkey_config_seq_show(struct seq_file *seq, void *offset); 179static int hotkey_config_seq_show(struct seq_file *seq, void *offset);
180static int hotkey_poll_config_seq_show(struct seq_file *seq, void *offset);
178static int hotkey_polling_open_fs(struct inode *inode, struct file *file); 181static int hotkey_polling_open_fs(struct inode *inode, struct file *file);
182static union acpi_hotkey *get_hotkey_by_event(struct
183 acpi_hotkey_list
184 *hotkey_list, int event);
179 185
180/* event based config */ 186/* event based config */
181static struct file_operations hotkey_config_fops = { 187static struct file_operations hotkey_config_fops = {
@@ -188,9 +194,9 @@ static struct file_operations hotkey_config_fops = {
188 194
189/* polling based config */ 195/* polling based config */
190static struct file_operations hotkey_poll_config_fops = { 196static struct file_operations hotkey_poll_config_fops = {
191 .open = hotkey_open_config, 197 .open = hotkey_poll_open_config,
192 .read = seq_read, 198 .read = seq_read,
193 .write = hotkey_write_poll_config, 199 .write = hotkey_write_config,
194 .llseek = seq_lseek, 200 .llseek = seq_lseek,
195 .release = single_release, 201 .release = single_release,
196}; 202};
@@ -227,7 +233,7 @@ static int hotkey_info_seq_show(struct seq_file *seq, void *offset)
227{ 233{
228 ACPI_FUNCTION_TRACE("hotkey_info_seq_show"); 234 ACPI_FUNCTION_TRACE("hotkey_info_seq_show");
229 235
230 seq_printf(seq, "Hotkey generic driver ver: %s", HOTKEY_ACPI_VERSION); 236 seq_printf(seq, "Hotkey generic driver ver: %s\n", HOTKEY_ACPI_VERSION);
231 237
232 return_VALUE(0); 238 return_VALUE(0);
233} 239}
@@ -239,27 +245,35 @@ static int hotkey_info_open_fs(struct inode *inode, struct file *file)
239 245
240static char *format_result(union acpi_object *object) 246static char *format_result(union acpi_object *object)
241{ 247{
242 char *buf = (char *)kmalloc(sizeof(union acpi_object), GFP_KERNEL); 248 char *buf = NULL;
243 249
244 memset(buf, 0, sizeof(union acpi_object)); 250 buf = (char *)kmalloc(RESULT_STR_LEN, GFP_KERNEL);
251 if (buf)
252 memset(buf, 0, RESULT_STR_LEN);
253 else
254 goto do_fail;
245 255
246 /* Now, just support integer type */ 256 /* Now, just support integer type */
247 if (object->type == ACPI_TYPE_INTEGER) 257 if (object->type == ACPI_TYPE_INTEGER)
248 sprintf(buf, "%d", (u32) object->integer.value); 258 sprintf(buf, "%d\n", (u32) object->integer.value);
249 259do_fail:
250 return buf; 260 return (buf);
251} 261}
252 262
253static int hotkey_polling_seq_show(struct seq_file *seq, void *offset) 263static int hotkey_polling_seq_show(struct seq_file *seq, void *offset)
254{ 264{
255 struct acpi_polling_hotkey *poll_hotkey = 265 struct acpi_polling_hotkey *poll_hotkey =
256 (struct acpi_polling_hotkey *)seq->private; 266 (struct acpi_polling_hotkey *)seq->private;
267 char *buf;
257 268
258 ACPI_FUNCTION_TRACE("hotkey_polling_seq_show"); 269 ACPI_FUNCTION_TRACE("hotkey_polling_seq_show");
259 270
260 if (poll_hotkey->poll_result) 271 if (poll_hotkey->poll_result){
261 seq_printf(seq, "%s", format_result(poll_hotkey->poll_result)); 272 buf = format_result(poll_hotkey->poll_result);
262 273 if(buf)
274 seq_printf(seq, "%s", buf);
275 kfree(buf);
276 }
263 return_VALUE(0); 277 return_VALUE(0);
264} 278}
265 279
@@ -276,19 +290,19 @@ static int hotkey_action_open_fs(struct inode *inode, struct file *file)
276/* Mapping external hotkey number to standardized hotkey event num */ 290/* Mapping external hotkey number to standardized hotkey event num */
277static int hotkey_get_internal_event(int event, struct acpi_hotkey_list *list) 291static int hotkey_get_internal_event(int event, struct acpi_hotkey_list *list)
278{ 292{
279 struct list_head *entries, *next; 293 struct list_head *entries;
280 int val = 0; 294 int val = -1;
281 295
282 ACPI_FUNCTION_TRACE("hotkey_get_internal_event"); 296 ACPI_FUNCTION_TRACE("hotkey_get_internal_event");
283 297
284 list_for_each_safe(entries, next, list->entries) { 298 list_for_each(entries, list->entries) {
285 union acpi_hotkey *key = 299 union acpi_hotkey *key =
286 container_of(entries, union acpi_hotkey, entries); 300 container_of(entries, union acpi_hotkey, entries);
287 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT 301 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT
288 && key->event_hotkey.external_hotkey_num == event) 302 && key->event_hotkey.external_hotkey_num == event){
289 val = key->link.hotkey_standard_num; 303 val = key->link.hotkey_standard_num;
290 else 304 break;
291 val = -1; 305 }
292 } 306 }
293 307
294 return_VALUE(val); 308 return_VALUE(val);
@@ -306,7 +320,7 @@ acpi_hotkey_notify_handler(acpi_handle handle, u32 event, void *data)
306 return_VOID; 320 return_VOID;
307 321
308 internal_event = hotkey_get_internal_event(event, &global_hotkey_list); 322 internal_event = hotkey_get_internal_event(event, &global_hotkey_list);
309 acpi_bus_generate_event(device, event, 0); 323 acpi_bus_generate_event(device, internal_event, 0);
310 324
311 return_VOID; 325 return_VOID;
312} 326}
@@ -329,13 +343,17 @@ static int auto_hotkey_remove(struct acpi_device *device, int type)
329static int create_polling_proc(union acpi_hotkey *device) 343static int create_polling_proc(union acpi_hotkey *device)
330{ 344{
331 struct proc_dir_entry *proc; 345 struct proc_dir_entry *proc;
346 char proc_name[80];
332 mode_t mode; 347 mode_t mode;
333 348
334 ACPI_FUNCTION_TRACE("create_polling_proc"); 349 ACPI_FUNCTION_TRACE("create_polling_proc");
335 mode = S_IFREG | S_IRUGO | S_IWUGO; 350 mode = S_IFREG | S_IRUGO | S_IWUGO;
336 351
337 proc = create_proc_entry(device->poll_hotkey.action_method, 352 sprintf(proc_name, "%d", device->link.hotkey_standard_num);
338 mode, hotkey_proc_dir); 353 /*
354 strcat(proc_name, device->poll_hotkey.poll_method);
355 */
356 proc = create_proc_entry(proc_name, mode, hotkey_proc_dir);
339 357
340 if (!proc) { 358 if (!proc) {
341 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 359 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
@@ -353,23 +371,6 @@ static int create_polling_proc(union acpi_hotkey *device)
353 return_VALUE(0); 371 return_VALUE(0);
354} 372}
355 373
356static int is_valid_acpi_path(const char *pathname)
357{
358 acpi_handle handle;
359 acpi_status status;
360 ACPI_FUNCTION_TRACE("is_valid_acpi_path");
361
362 status = acpi_get_handle(NULL, (char *)pathname, &handle);
363 return_VALUE(!ACPI_FAILURE(status));
364}
365
366static int is_valid_hotkey(union acpi_hotkey *device)
367{
368 ACPI_FUNCTION_TRACE("is_valid_hotkey");
369 /* Implement valid check */
370 return_VALUE(1);
371}
372
373static int hotkey_add(union acpi_hotkey *device) 374static int hotkey_add(union acpi_hotkey *device)
374{ 375{
375 int status = 0; 376 int status = 0;
@@ -378,15 +379,11 @@ static int hotkey_add(union acpi_hotkey *device)
378 ACPI_FUNCTION_TRACE("hotkey_add"); 379 ACPI_FUNCTION_TRACE("hotkey_add");
379 380
380 if (device->link.hotkey_type == ACPI_HOTKEY_EVENT) { 381 if (device->link.hotkey_type == ACPI_HOTKEY_EVENT) {
381 status = 382 acpi_bus_get_device(device->event_hotkey.bus_handle, &dev);
382 acpi_bus_get_device(device->event_hotkey.bus_handle, &dev);
383 if (status)
384 return_VALUE(status);
385
386 status = acpi_install_notify_handler(dev->handle, 383 status = acpi_install_notify_handler(dev->handle,
387 ACPI_SYSTEM_NOTIFY, 384 ACPI_DEVICE_NOTIFY,
388 acpi_hotkey_notify_handler, 385 acpi_hotkey_notify_handler,
389 device); 386 dev);
390 } else /* Add polling hotkey */ 387 } else /* Add polling hotkey */
391 create_polling_proc(device); 388 create_polling_proc(device);
392 389
@@ -409,84 +406,143 @@ static int hotkey_remove(union acpi_hotkey *device)
409 if (key->link.hotkey_standard_num == 406 if (key->link.hotkey_standard_num ==
410 device->link.hotkey_standard_num) { 407 device->link.hotkey_standard_num) {
411 list_del(&key->link.entries); 408 list_del(&key->link.entries);
412 remove_proc_entry(key->poll_hotkey.action_method, 409 free_hotkey_device(key);
413 hotkey_proc_dir);
414 global_hotkey_list.count--; 410 global_hotkey_list.count--;
415 break; 411 break;
416 } 412 }
417 } 413 }
414 kfree(device);
418 return_VALUE(0); 415 return_VALUE(0);
419} 416}
420 417
421static void hotkey_update(union acpi_hotkey *key) 418static int hotkey_update(union acpi_hotkey *key)
422{ 419{
423 struct list_head *entries, *next; 420 struct list_head *entries;
424 421
425 ACPI_FUNCTION_TRACE("hotkey_update"); 422 ACPI_FUNCTION_TRACE("hotkey_update");
426 423
427 list_for_each_safe(entries, next, global_hotkey_list.entries) { 424 list_for_each(entries, global_hotkey_list.entries) {
428 union acpi_hotkey *key = 425 union acpi_hotkey *tmp=
429 container_of(entries, union acpi_hotkey, entries); 426 container_of(entries, union acpi_hotkey, entries);
430 if (key->link.hotkey_standard_num == 427 if (tmp->link.hotkey_standard_num ==
431 key->link.hotkey_standard_num) { 428 key->link.hotkey_standard_num) {
432 key->event_hotkey.bus_handle = 429 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) {
433 key->event_hotkey.bus_handle; 430 free_hotkey_buffer(tmp);
434 key->event_hotkey.external_hotkey_num = 431 tmp->event_hotkey.bus_handle =
435 key->event_hotkey.external_hotkey_num; 432 key->event_hotkey.bus_handle;
436 key->event_hotkey.action_handle = 433 tmp->event_hotkey.external_hotkey_num =
437 key->event_hotkey.action_handle; 434 key->event_hotkey.external_hotkey_num;
438 key->event_hotkey.action_method = 435 tmp->event_hotkey.action_handle =
439 key->event_hotkey.action_method; 436 key->event_hotkey.action_handle;
437 tmp->event_hotkey.action_method =
438 key->event_hotkey.action_method;
439 kfree(key);
440 } else {
441 /*
442 char proc_name[80];
443
444 sprintf(proc_name, "%d", tmp->link.hotkey_standard_num);
445 strcat(proc_name, tmp->poll_hotkey.poll_method);
446 remove_proc_entry(proc_name,hotkey_proc_dir);
447 */
448 free_poll_hotkey_buffer(tmp);
449 tmp->poll_hotkey.poll_handle =
450 key->poll_hotkey.poll_handle;
451 tmp->poll_hotkey.poll_method =
452 key->poll_hotkey.poll_method;
453 tmp->poll_hotkey.action_handle =
454 key->poll_hotkey.action_handle;
455 tmp->poll_hotkey.action_method =
456 key->poll_hotkey.action_method;
457 tmp->poll_hotkey.poll_result =
458 key->poll_hotkey.poll_result;
459 /*
460 create_polling_proc(tmp);
461 */
462 kfree(key);
463 }
464 return_VALUE(0);
440 break; 465 break;
441 } 466 }
442 } 467 }
443 468
444 return_VOID; 469 return_VALUE(-ENODEV);
445} 470}
446 471
447static void free_hotkey_device(union acpi_hotkey *key) 472static void free_hotkey_device(union acpi_hotkey *key)
448{ 473{
449 struct acpi_device *dev; 474 struct acpi_device *dev;
450 int status;
451 475
452 ACPI_FUNCTION_TRACE("free_hotkey_device"); 476 ACPI_FUNCTION_TRACE("free_hotkey_device");
453 477
454 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) { 478 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) {
455 status = 479 acpi_bus_get_device(key->event_hotkey.bus_handle, &dev);
456 acpi_bus_get_device(key->event_hotkey.bus_handle, &dev);
457 if (dev->handle) 480 if (dev->handle)
458 acpi_remove_notify_handler(dev->handle, 481 acpi_remove_notify_handler(dev->handle,
459 ACPI_SYSTEM_NOTIFY, 482 ACPI_DEVICE_NOTIFY,
460 acpi_hotkey_notify_handler); 483 acpi_hotkey_notify_handler);
461 } else 484 free_hotkey_buffer(key);
462 remove_proc_entry(key->poll_hotkey.action_method, 485 } else {
463 hotkey_proc_dir); 486 char proc_name[80];
487
488 sprintf(proc_name, "%d", key->link.hotkey_standard_num);
489 /*
490 strcat(proc_name, key->poll_hotkey.poll_method);
491 */
492 remove_proc_entry(proc_name,hotkey_proc_dir);
493 free_poll_hotkey_buffer(key);
494 }
464 kfree(key); 495 kfree(key);
465 return_VOID; 496 return_VOID;
466} 497}
467 498
499static void
500free_hotkey_buffer(union acpi_hotkey *key)
501{
502 kfree(key->event_hotkey.action_method);
503}
504
505static void
506free_poll_hotkey_buffer(union acpi_hotkey *key)
507{
508 kfree(key->poll_hotkey.action_method);
509 kfree(key->poll_hotkey.poll_method);
510 kfree(key->poll_hotkey.poll_result);
511}
468static int 512static int
469init_hotkey_device(union acpi_hotkey *key, char *bus_str, char *action_str, 513init_hotkey_device(union acpi_hotkey *key, char *bus_str, char *action_str,
470 char *method, int std_num, int external_num) 514 char *method, int std_num, int external_num)
471{ 515{
516 acpi_handle tmp_handle;
517 acpi_status status = AE_OK;
518
472 ACPI_FUNCTION_TRACE("init_hotkey_device"); 519 ACPI_FUNCTION_TRACE("init_hotkey_device");
473 520
521 if(std_num < 0 || IS_POLL(std_num) || !key )
522 goto do_fail;
523
524 if(!bus_str || !action_str || !method)
525 goto do_fail;
526
474 key->link.hotkey_type = ACPI_HOTKEY_EVENT; 527 key->link.hotkey_type = ACPI_HOTKEY_EVENT;
475 key->link.hotkey_standard_num = std_num; 528 key->link.hotkey_standard_num = std_num;
476 key->event_hotkey.flag = 0; 529 key->event_hotkey.flag = 0;
477 if (is_valid_acpi_path(bus_str)) 530 key->event_hotkey.action_method = method;
478 acpi_get_handle((acpi_handle) 0,
479 bus_str, &(key->event_hotkey.bus_handle));
480 else
481 return_VALUE(-ENODEV);
482 key->event_hotkey.external_hotkey_num = external_num;
483 if (is_valid_acpi_path(action_str))
484 acpi_get_handle((acpi_handle) 0,
485 action_str, &(key->event_hotkey.action_handle));
486 key->event_hotkey.action_method = kmalloc(sizeof(method), GFP_KERNEL);
487 strcpy(key->event_hotkey.action_method, method);
488 531
489 return_VALUE(!is_valid_hotkey(key)); 532 status = acpi_get_handle(NULL,bus_str, &(key->event_hotkey.bus_handle));
533 if(ACPI_FAILURE(status))
534 goto do_fail;
535 key->event_hotkey.external_hotkey_num = external_num;
536 status = acpi_get_handle(NULL,action_str, &(key->event_hotkey.action_handle));
537 if(ACPI_FAILURE(status))
538 goto do_fail;
539 status = acpi_get_handle(key->event_hotkey.action_handle,
540 method, &tmp_handle);
541 if (ACPI_FAILURE(status))
542 goto do_fail;
543 return_VALUE(AE_OK);
544do_fail:
545 return_VALUE(-ENODEV);
490} 546}
491 547
492static int 548static int
@@ -495,34 +551,46 @@ init_poll_hotkey_device(union acpi_hotkey *key,
495 char *poll_method, 551 char *poll_method,
496 char *action_str, char *action_method, int std_num) 552 char *action_str, char *action_method, int std_num)
497{ 553{
554 acpi_status status = AE_OK;
555 acpi_handle tmp_handle;
556
498 ACPI_FUNCTION_TRACE("init_poll_hotkey_device"); 557 ACPI_FUNCTION_TRACE("init_poll_hotkey_device");
499 558
559 if(std_num < 0 || IS_EVENT(std_num) || !key)
560 goto do_fail;
561
562 if(!poll_str || !poll_method || !action_str || !action_method)
563 goto do_fail;
564
500 key->link.hotkey_type = ACPI_HOTKEY_POLLING; 565 key->link.hotkey_type = ACPI_HOTKEY_POLLING;
501 key->link.hotkey_standard_num = std_num; 566 key->link.hotkey_standard_num = std_num;
502 key->poll_hotkey.flag = 0; 567 key->poll_hotkey.flag = 0;
503 if (is_valid_acpi_path(poll_str))
504 acpi_get_handle((acpi_handle) 0,
505 poll_str, &(key->poll_hotkey.poll_handle));
506 else
507 return_VALUE(-ENODEV);
508 key->poll_hotkey.poll_method = poll_method; 568 key->poll_hotkey.poll_method = poll_method;
509 if (is_valid_acpi_path(action_str)) 569 key->poll_hotkey.action_method = action_method;
510 acpi_get_handle((acpi_handle) 0, 570
511 action_str, &(key->poll_hotkey.action_handle)); 571 status = acpi_get_handle(NULL,poll_str, &(key->poll_hotkey.poll_handle));
512 key->poll_hotkey.action_method = 572 if(ACPI_FAILURE(status))
513 kmalloc(sizeof(action_method), GFP_KERNEL); 573 goto do_fail;
514 strcpy(key->poll_hotkey.action_method, action_method); 574 status = acpi_get_handle(key->poll_hotkey.poll_handle,
575 poll_method, &tmp_handle);
576 if (ACPI_FAILURE(status))
577 goto do_fail;
578 status = acpi_get_handle(NULL,action_str, &(key->poll_hotkey.action_handle));
579 if (ACPI_FAILURE(status))
580 goto do_fail;
581 status = acpi_get_handle(key->poll_hotkey.action_handle,
582 action_method, &tmp_handle);
583 if (ACPI_FAILURE(status))
584 goto do_fail;
515 key->poll_hotkey.poll_result = 585 key->poll_hotkey.poll_result =
516 (union acpi_object *)kmalloc(sizeof(union acpi_object), GFP_KERNEL); 586 (union acpi_object *)kmalloc(sizeof(union acpi_object), GFP_KERNEL);
517 return_VALUE(is_valid_hotkey(key)); 587 if(!key->poll_hotkey.poll_result)
588 goto do_fail;
589 return_VALUE(AE_OK);
590do_fail:
591 return_VALUE(-ENODEV);
518} 592}
519 593
520static int check_hotkey_valid(union acpi_hotkey *key,
521 struct acpi_hotkey_list *list)
522{
523 ACPI_FUNCTION_TRACE("check_hotkey_valid");
524 return_VALUE(0);
525}
526 594
527static int hotkey_open_config(struct inode *inode, struct file *file) 595static int hotkey_open_config(struct inode *inode, struct file *file)
528{ 596{
@@ -531,10 +599,17 @@ static int hotkey_open_config(struct inode *inode, struct file *file)
531 (file, hotkey_config_seq_show, PDE(inode)->data)); 599 (file, hotkey_config_seq_show, PDE(inode)->data));
532} 600}
533 601
602static int hotkey_poll_open_config(struct inode *inode, struct file *file)
603{
604 ACPI_FUNCTION_TRACE("hotkey_poll_open_config");
605 return_VALUE(single_open
606 (file, hotkey_poll_config_seq_show, PDE(inode)->data));
607}
608
534static int hotkey_config_seq_show(struct seq_file *seq, void *offset) 609static int hotkey_config_seq_show(struct seq_file *seq, void *offset)
535{ 610{
536 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list; 611 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list;
537 struct list_head *entries, *next; 612 struct list_head *entries;
538 char bus_name[ACPI_PATHNAME_MAX] = { 0 }; 613 char bus_name[ACPI_PATHNAME_MAX] = { 0 };
539 char action_name[ACPI_PATHNAME_MAX] = { 0 }; 614 char action_name[ACPI_PATHNAME_MAX] = { 0 };
540 struct acpi_buffer bus = { ACPI_PATHNAME_MAX, bus_name }; 615 struct acpi_buffer bus = { ACPI_PATHNAME_MAX, bus_name };
@@ -542,10 +617,7 @@ static int hotkey_config_seq_show(struct seq_file *seq, void *offset)
542 617
543 ACPI_FUNCTION_TRACE(("hotkey_config_seq_show")); 618 ACPI_FUNCTION_TRACE(("hotkey_config_seq_show"));
544 619
545 if (!hotkey_list) 620 list_for_each(entries, hotkey_list->entries) {
546 goto end;
547
548 list_for_each_safe(entries, next, hotkey_list->entries) {
549 union acpi_hotkey *key = 621 union acpi_hotkey *key =
550 container_of(entries, union acpi_hotkey, entries); 622 container_of(entries, union acpi_hotkey, entries);
551 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) { 623 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) {
@@ -553,18 +625,37 @@ static int hotkey_config_seq_show(struct seq_file *seq, void *offset)
553 ACPI_NAME_TYPE_MAX, &bus); 625 ACPI_NAME_TYPE_MAX, &bus);
554 acpi_get_name(key->event_hotkey.action_handle, 626 acpi_get_name(key->event_hotkey.action_handle,
555 ACPI_NAME_TYPE_MAX, &act); 627 ACPI_NAME_TYPE_MAX, &act);
556 seq_printf(seq, "%s:%s:%s:%d:%d", bus_name, 628 seq_printf(seq, "%s:%s:%s:%d:%d\n", bus_name,
557 action_name, 629 action_name,
558 key->event_hotkey.action_method, 630 key->event_hotkey.action_method,
559 key->link.hotkey_standard_num, 631 key->link.hotkey_standard_num,
560 key->event_hotkey.external_hotkey_num); 632 key->event_hotkey.external_hotkey_num);
561 } /* ACPI_HOTKEY_POLLING */ 633 }
562 else { 634 }
635 seq_puts(seq, "\n");
636 return_VALUE(0);
637}
638
639static int hotkey_poll_config_seq_show(struct seq_file *seq, void *offset)
640{
641 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list;
642 struct list_head *entries;
643 char bus_name[ACPI_PATHNAME_MAX] = { 0 };
644 char action_name[ACPI_PATHNAME_MAX] = { 0 };
645 struct acpi_buffer bus = { ACPI_PATHNAME_MAX, bus_name };
646 struct acpi_buffer act = { ACPI_PATHNAME_MAX, action_name };
647
648 ACPI_FUNCTION_TRACE(("hotkey_config_seq_show"));
649
650 list_for_each(entries, hotkey_list->entries) {
651 union acpi_hotkey *key =
652 container_of(entries, union acpi_hotkey, entries);
653 if (key->link.hotkey_type == ACPI_HOTKEY_POLLING) {
563 acpi_get_name(key->poll_hotkey.poll_handle, 654 acpi_get_name(key->poll_hotkey.poll_handle,
564 ACPI_NAME_TYPE_MAX, &bus); 655 ACPI_NAME_TYPE_MAX, &bus);
565 acpi_get_name(key->poll_hotkey.action_handle, 656 acpi_get_name(key->poll_hotkey.action_handle,
566 ACPI_NAME_TYPE_MAX, &act); 657 ACPI_NAME_TYPE_MAX, &act);
567 seq_printf(seq, "%s:%s:%s:%s:%d", bus_name, 658 seq_printf(seq, "%s:%s:%s:%s:%d\n", bus_name,
568 key->poll_hotkey.poll_method, 659 key->poll_hotkey.poll_method,
569 action_name, 660 action_name,
570 key->poll_hotkey.action_method, 661 key->poll_hotkey.action_method,
@@ -572,49 +663,83 @@ static int hotkey_config_seq_show(struct seq_file *seq, void *offset)
572 } 663 }
573 } 664 }
574 seq_puts(seq, "\n"); 665 seq_puts(seq, "\n");
575 end:
576 return_VALUE(0); 666 return_VALUE(0);
577} 667}
578 668
579static int 669static int
580get_parms(char *config_record, 670get_parms(char *config_record,
581 int *cmd, 671 int *cmd,
582 char *bus_handle, 672 char **bus_handle,
583 char *bus_method, 673 char **bus_method,
584 char *action_handle, 674 char **action_handle,
585 char *method, int *internal_event_num, int *external_event_num) 675 char **method, int *internal_event_num, int *external_event_num)
586{ 676{
587 char *tmp, *tmp1; 677 char *tmp, *tmp1, count;
588 ACPI_FUNCTION_TRACE(("get_parms")); 678 ACPI_FUNCTION_TRACE(("get_parms"));
589 679
590 sscanf(config_record, "%d", cmd); 680 sscanf(config_record, "%d", cmd);
591 681
682 if(*cmd == 1){
683 if(sscanf(config_record, "%d:%d", cmd, internal_event_num)!=2)
684 goto do_fail;
685 else
686 return (6);
687 }
592 tmp = strchr(config_record, ':'); 688 tmp = strchr(config_record, ':');
689 if (!tmp)
690 goto do_fail;
593 tmp++; 691 tmp++;
594 tmp1 = strchr(tmp, ':'); 692 tmp1 = strchr(tmp, ':');
595 strncpy(bus_handle, tmp, tmp1 - tmp); 693 if (!tmp1)
596 bus_handle[tmp1 - tmp] = 0; 694 goto do_fail;
695
696 count = tmp1 - tmp;
697 *bus_handle = (char *) kmalloc(count+1, GFP_KERNEL);
698 if(!*bus_handle)
699 goto do_fail;
700 strncpy(*bus_handle, tmp, count);
701 *(*bus_handle + count) = 0;
597 702
598 tmp = tmp1; 703 tmp = tmp1;
599 tmp++; 704 tmp++;
600 tmp1 = strchr(tmp, ':'); 705 tmp1 = strchr(tmp, ':');
601 strncpy(bus_method, tmp, tmp1 - tmp); 706 if (!tmp1)
602 bus_method[tmp1 - tmp] = 0; 707 goto do_fail;
708 count = tmp1 - tmp;
709 *bus_method = (char *) kmalloc(count+1, GFP_KERNEL);
710 if(!*bus_method)
711 goto do_fail;
712 strncpy(*bus_method, tmp, count);
713 *(*bus_method + count) = 0;
603 714
604 tmp = tmp1; 715 tmp = tmp1;
605 tmp++; 716 tmp++;
606 tmp1 = strchr(tmp, ':'); 717 tmp1 = strchr(tmp, ':');
607 strncpy(action_handle, tmp, tmp1 - tmp); 718 if (!tmp1)
608 action_handle[tmp1 - tmp] = 0; 719 goto do_fail;
720 count = tmp1 - tmp;
721 *action_handle = (char *) kmalloc(count+1, GFP_KERNEL);
722 strncpy(*action_handle, tmp, count);
723 *(*action_handle + count) = 0;
609 724
610 tmp = tmp1; 725 tmp = tmp1;
611 tmp++; 726 tmp++;
612 tmp1 = strchr(tmp, ':'); 727 tmp1 = strchr(tmp, ':');
613 strncpy(method, tmp, tmp1 - tmp); 728 if (!tmp1)
614 method[tmp1 - tmp] = 0; 729 goto do_fail;
730 count = tmp1 - tmp;
731 *method = (char *) kmalloc(count+1, GFP_KERNEL);
732 if(!*method)
733 goto do_fail;
734 strncpy(*method, tmp, count);
735 *(*method + count) = 0;
736
737 if(sscanf(tmp1 + 1, "%d:%d", internal_event_num, external_event_num)<=0)
738 goto do_fail;
615 739
616 sscanf(tmp1 + 1, "%d:%d", internal_event_num, external_event_num);
617 return_VALUE(6); 740 return_VALUE(6);
741do_fail:
742 return_VALUE(-1);
618} 743}
619 744
620/* count is length for one input record */ 745/* count is length for one input record */
@@ -622,135 +747,117 @@ static ssize_t hotkey_write_config(struct file *file,
622 const char __user * buffer, 747 const char __user * buffer,
623 size_t count, loff_t * data) 748 size_t count, loff_t * data)
624{ 749{
625 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list; 750 char *config_record = NULL;
626 char config_record[MAX_CONFIG_RECORD_LEN]; 751 char *bus_handle = NULL;
627 char bus_handle[MAX_NAME_PATH_LEN]; 752 char *bus_method = NULL;
628 char bus_method[MAX_NAME_PATH_LEN]; 753 char *action_handle = NULL;
629 char action_handle[MAX_NAME_PATH_LEN]; 754 char *method = NULL;
630 char method[20];
631 int cmd, internal_event_num, external_event_num; 755 int cmd, internal_event_num, external_event_num;
632 int ret = 0; 756 int ret = 0;
633 union acpi_hotkey *key = NULL; 757 union acpi_hotkey *key = NULL;
634 758
635 ACPI_FUNCTION_TRACE(("hotkey_write_config")); 759 ACPI_FUNCTION_TRACE(("hotkey_write_config"));
636 760
637 if (!hotkey_list || count > MAX_CONFIG_RECORD_LEN) { 761 config_record = (char *) kmalloc(count+1, GFP_KERNEL);
638 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid arguments\n")); 762 if(!config_record)
639 return_VALUE(-EINVAL); 763 return_VALUE(-ENOMEM);
640 }
641 764
642 if (copy_from_user(config_record, buffer, count)) { 765 if (copy_from_user(config_record, buffer, count)) {
766 kfree(config_record);
643 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data \n")); 767 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data \n"));
644 return_VALUE(-EINVAL); 768 return_VALUE(-EINVAL);
645 } 769 }
646 config_record[count] = '\0'; 770 config_record[count] = 0;
647 771
648 ret = get_parms(config_record, 772 ret = get_parms(config_record,
649 &cmd, 773 &cmd,
650 bus_handle, 774 &bus_handle,
651 bus_method, 775 &bus_method,
652 action_handle, 776 &action_handle,
653 method, &internal_event_num, &external_event_num); 777 &method, &internal_event_num, &external_event_num);
778
779 kfree(config_record);
780 if(IS_OTHERS(internal_event_num))
781 goto do_fail;
654 if (ret != 6) { 782 if (ret != 6) {
783do_fail:
784 kfree(bus_handle);
785 kfree(bus_method);
786 kfree(action_handle);
787 kfree(method);
655 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 788 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
656 "Invalid data format ret=%d\n", ret)); 789 "Invalid data format ret=%d\n", ret));
657 return_VALUE(-EINVAL); 790 return_VALUE(-EINVAL);
658 } 791 }
659 792
660 key = kmalloc(sizeof(union acpi_hotkey), GFP_KERNEL); 793 key = kmalloc(sizeof(union acpi_hotkey), GFP_KERNEL);
661 ret = init_hotkey_device(key, bus_handle, action_handle, method, 794 if(!key)
795 goto do_fail;
796 memset(key, 0, sizeof(union acpi_hotkey));
797 if(cmd == 1) {
798 union acpi_hotkey *tmp = NULL;
799 tmp = get_hotkey_by_event(&global_hotkey_list,
800 internal_event_num);
801 if(!tmp)
802 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid key"));
803 else
804 memcpy(key, tmp, sizeof(union acpi_hotkey));
805 goto cont_cmd;
806 }
807 if (IS_EVENT(internal_event_num)) {
808 kfree(bus_method);
809 ret = init_hotkey_device(key, bus_handle, action_handle, method,
662 internal_event_num, external_event_num); 810 internal_event_num, external_event_num);
663 811 } else
664 if (ret || check_hotkey_valid(key, hotkey_list)) { 812 ret = init_poll_hotkey_device(key, bus_handle, bus_method,
813 action_handle, method,
814 internal_event_num);
815 if (ret) {
816 kfree(bus_handle);
817 kfree(action_handle);
818 if(IS_EVENT(internal_event_num))
819 free_hotkey_buffer(key);
820 else
821 free_poll_hotkey_buffer(key);
665 kfree(key); 822 kfree(key);
666 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid hotkey \n")); 823 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid hotkey \n"));
667 return_VALUE(-EINVAL); 824 return_VALUE(-EINVAL);
668 } 825 }
669 switch (cmd) {
670 case 0:
671 hotkey_add(key);
672 break;
673 case 1:
674 hotkey_remove(key);
675 free_hotkey_device(key);
676 break;
677 case 2:
678 hotkey_update(key);
679 break;
680 default:
681 break;
682 }
683 return_VALUE(count);
684}
685
686/* count is length for one input record */
687static ssize_t hotkey_write_poll_config(struct file *file,
688 const char __user * buffer,
689 size_t count, loff_t * data)
690{
691 struct seq_file *m = (struct seq_file *)file->private_data;
692 struct acpi_hotkey_list *hotkey_list =
693 (struct acpi_hotkey_list *)m->private;
694
695 char config_record[MAX_CONFIG_RECORD_LEN];
696 char polling_handle[MAX_NAME_PATH_LEN];
697 char action_handle[MAX_NAME_PATH_LEN];
698 char poll_method[20], action_method[20];
699 int ret, internal_event_num, cmd, external_event_num;
700 union acpi_hotkey *key = NULL;
701
702 ACPI_FUNCTION_TRACE("hotkey_write_poll_config");
703
704 if (!hotkey_list || count > MAX_CONFIG_RECORD_LEN) {
705 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid arguments\n"));
706 return_VALUE(-EINVAL);
707 }
708
709 if (copy_from_user(config_record, buffer, count)) {
710 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data \n"));
711 return_VALUE(-EINVAL);
712 }
713 config_record[count] = '\0';
714 826
715 ret = get_parms(config_record, 827cont_cmd:
716 &cmd, 828 kfree(bus_handle);
717 polling_handle, 829 kfree(action_handle);
718 poll_method,
719 action_handle,
720 action_method,
721 &internal_event_num, &external_event_num);
722
723 if (ret != 6) {
724 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data format\n"));
725 return_VALUE(-EINVAL);
726 }
727 830
728 key = kmalloc(sizeof(union acpi_hotkey), GFP_KERNEL);
729 ret = init_poll_hotkey_device(key, polling_handle, poll_method,
730 action_handle, action_method,
731 internal_event_num);
732 if (ret || check_hotkey_valid(key, hotkey_list)) {
733 kfree(key);
734 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid hotkey \n"));
735 return_VALUE(-EINVAL);
736 }
737 switch (cmd) { 831 switch (cmd) {
738 case 0: 832 case 0:
739 hotkey_add(key); 833 if(get_hotkey_by_event(&global_hotkey_list,key->link.hotkey_standard_num))
834 goto fail_out;
835 else
836 hotkey_add(key);
740 break; 837 break;
741 case 1: 838 case 1:
742 hotkey_remove(key); 839 hotkey_remove(key);
743 break; 840 break;
744 case 2: 841 case 2:
745 hotkey_update(key); 842 if(hotkey_update(key))
843 goto fail_out;
746 break; 844 break;
747 default: 845 default:
846 goto fail_out;
748 break; 847 break;
749 } 848 }
750 return_VALUE(count); 849 return_VALUE(count);
850fail_out:
851 if(IS_EVENT(internal_event_num))
852 free_hotkey_buffer(key);
853 else
854 free_poll_hotkey_buffer(key);
855 kfree(key);
856 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "invalid key\n"));
857 return_VALUE(-EINVAL);
751} 858}
752 859
753/* 860/*
754 * This function evaluates an ACPI method, given an int as parameter, the 861 * This function evaluates an ACPI method, given an int as parameter, the
755 * method is searched within the scope of the handle, can be NULL. The output 862 * method is searched within the scope of the handle, can be NULL. The output
756 * of the method is written is output, which can also be NULL 863 * of the method is written is output, which can also be NULL
@@ -775,7 +882,7 @@ static int write_acpi_int(acpi_handle handle, const char *method, int val,
775 return_VALUE(status == AE_OK); 882 return_VALUE(status == AE_OK);
776} 883}
777 884
778static int read_acpi_int(acpi_handle handle, const char *method, int *val) 885static int read_acpi_int(acpi_handle handle, const char *method, union acpi_object *val)
779{ 886{
780 struct acpi_buffer output; 887 struct acpi_buffer output;
781 union acpi_object out_obj; 888 union acpi_object out_obj;
@@ -786,62 +893,32 @@ static int read_acpi_int(acpi_handle handle, const char *method, int *val)
786 output.pointer = &out_obj; 893 output.pointer = &out_obj;
787 894
788 status = acpi_evaluate_object(handle, (char *)method, NULL, &output); 895 status = acpi_evaluate_object(handle, (char *)method, NULL, &output);
789 *val = out_obj.integer.value; 896 if(val){
897 val->integer.value = out_obj.integer.value;
898 val->type = out_obj.type;
899 } else
900 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "null val pointer"));
790 return_VALUE((status == AE_OK) 901 return_VALUE((status == AE_OK)
791 && (out_obj.type == ACPI_TYPE_INTEGER)); 902 && (out_obj.type == ACPI_TYPE_INTEGER));
792} 903}
793 904
794static acpi_handle 905static union acpi_hotkey *get_hotkey_by_event(struct
795get_handle_from_hotkeylist(struct acpi_hotkey_list *hotkey_list, int event_num) 906 acpi_hotkey_list
907 *hotkey_list, int event)
796{ 908{
797 struct list_head *entries, *next; 909 struct list_head *entries;
798
799 list_for_each_safe(entries, next, hotkey_list->entries) {
800 union acpi_hotkey *key =
801 container_of(entries, union acpi_hotkey, entries);
802 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT
803 && key->link.hotkey_standard_num == event_num) {
804 return (key->event_hotkey.action_handle);
805 }
806 }
807 return (NULL);
808}
809
810static
811char *get_method_from_hotkeylist(struct acpi_hotkey_list *hotkey_list,
812 int event_num)
813{
814 struct list_head *entries, *next;
815
816 list_for_each_safe(entries, next, hotkey_list->entries) {
817 union acpi_hotkey *key =
818 container_of(entries, union acpi_hotkey, entries);
819
820 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT &&
821 key->link.hotkey_standard_num == event_num)
822 return (key->event_hotkey.action_method);
823 }
824 return (NULL);
825}
826
827static struct acpi_polling_hotkey *get_hotkey_by_event(struct
828 acpi_hotkey_list
829 *hotkey_list, int event)
830{
831 struct list_head *entries, *next;
832 910
833 list_for_each_safe(entries, next, hotkey_list->entries) { 911 list_for_each(entries, hotkey_list->entries) {
834 union acpi_hotkey *key = 912 union acpi_hotkey *key =
835 container_of(entries, union acpi_hotkey, entries); 913 container_of(entries, union acpi_hotkey, entries);
836 if (key->link.hotkey_type == ACPI_HOTKEY_POLLING 914 if (key->link.hotkey_standard_num == event) {
837 && key->link.hotkey_standard_num == event) { 915 return(key);
838 return (&key->poll_hotkey);
839 } 916 }
840 } 917 }
841 return (NULL); 918 return(NULL);
842} 919}
843 920
844/* 921/*
845 * user call AML method interface: 922 * user call AML method interface:
846 * Call convention: 923 * Call convention:
847 * echo "event_num: arg type : value" 924 * echo "event_num: arg type : value"
@@ -854,48 +931,56 @@ static ssize_t hotkey_execute_aml_method(struct file *file,
854 size_t count, loff_t * data) 931 size_t count, loff_t * data)
855{ 932{
856 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list; 933 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list;
857 char arg[MAX_CALL_PARM]; 934 char *arg;
858 int event, type, value; 935 int event,method_type,type, value;
859 936 union acpi_hotkey *key;
860 char *method;
861 acpi_handle handle;
862 937
863 ACPI_FUNCTION_TRACE("hotkey_execte_aml_method"); 938 ACPI_FUNCTION_TRACE("hotkey_execte_aml_method");
864 939
865 if (!hotkey_list || count > MAX_CALL_PARM) { 940 arg = (char *) kmalloc(count+1, GFP_KERNEL);
866 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid argument 1")); 941 if(!arg)
867 return_VALUE(-EINVAL); 942 return_VALUE(-ENOMEM);
868 } 943 arg[count]=0;
869 944
870 if (copy_from_user(arg, buffer, count)) { 945 if (copy_from_user(arg, buffer, count)) {
946 kfree(arg);
871 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid argument 2")); 947 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid argument 2"));
872 return_VALUE(-EINVAL); 948 return_VALUE(-EINVAL);
873 } 949 }
874 950
875 arg[count] = '\0'; 951 if (sscanf(arg, "%d:%d:%d:%d", &event, &method_type, &type, &value) != 4) {
876 952 kfree(arg);
877 if (sscanf(arg, "%d:%d:%d", &event, &type, &value) != 3) {
878 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid argument 3")); 953 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid argument 3"));
879 return_VALUE(-EINVAL); 954 return_VALUE(-EINVAL);
880 } 955 }
881 956 kfree(arg);
882 if (type == ACPI_TYPE_INTEGER) { 957 if (type == ACPI_TYPE_INTEGER) {
883 handle = get_handle_from_hotkeylist(hotkey_list, event); 958 key = get_hotkey_by_event(hotkey_list, event);
884 method = (char *)get_method_from_hotkeylist(hotkey_list, event); 959 if(!key)
960 goto do_fail;
885 if (IS_EVENT(event)) 961 if (IS_EVENT(event))
886 write_acpi_int(handle, method, value, NULL); 962 write_acpi_int(key->event_hotkey.action_handle,
963 key->event_hotkey.action_method, value, NULL);
887 else if (IS_POLL(event)) { 964 else if (IS_POLL(event)) {
888 struct acpi_polling_hotkey *key; 965 if ( method_type == POLL_METHOD )
889 key = (struct acpi_polling_hotkey *) 966 read_acpi_int(key->poll_hotkey.poll_handle,
890 get_hotkey_by_event(hotkey_list, event); 967 key->poll_hotkey.poll_method,
891 read_acpi_int(handle, method, key->poll_result); 968 key->poll_hotkey.poll_result);
969 else if ( method_type == ACTION_METHOD )
970 write_acpi_int(key->poll_hotkey.action_handle,
971 key->poll_hotkey.action_method, value, NULL);
972 else
973 goto do_fail;
974
892 } 975 }
893 } else { 976 } else {
894 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Not supported")); 977 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Not supported"));
895 return_VALUE(-EINVAL); 978 return_VALUE(-EINVAL);
896 } 979 }
897
898 return_VALUE(count); 980 return_VALUE(count);
981do_fail:
982 return_VALUE(-EINVAL);
983
899} 984}
900 985
901static int __init hotkey_init(void) 986static int __init hotkey_init(void)
@@ -928,7 +1013,7 @@ static int __init hotkey_init(void)
928 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1013 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
929 "Hotkey: Unable to create %s entry\n", 1014 "Hotkey: Unable to create %s entry\n",
930 HOTKEY_EV_CONFIG)); 1015 HOTKEY_EV_CONFIG));
931 return (-ENODEV); 1016 goto do_fail1;
932 } else { 1017 } else {
933 hotkey_config->proc_fops = &hotkey_config_fops; 1018 hotkey_config->proc_fops = &hotkey_config_fops;
934 hotkey_config->data = &global_hotkey_list; 1019 hotkey_config->data = &global_hotkey_list;
@@ -943,7 +1028,8 @@ static int __init hotkey_init(void)
943 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1028 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
944 "Hotkey: Unable to create %s entry\n", 1029 "Hotkey: Unable to create %s entry\n",
945 HOTKEY_EV_CONFIG)); 1030 HOTKEY_EV_CONFIG));
946 return (-ENODEV); 1031
1032 goto do_fail2;
947 } else { 1033 } else {
948 hotkey_poll_config->proc_fops = &hotkey_poll_config_fops; 1034 hotkey_poll_config->proc_fops = &hotkey_poll_config_fops;
949 hotkey_poll_config->data = &global_hotkey_list; 1035 hotkey_poll_config->data = &global_hotkey_list;
@@ -957,7 +1043,7 @@ static int __init hotkey_init(void)
957 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1043 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
958 "Hotkey: Unable to create %s entry\n", 1044 "Hotkey: Unable to create %s entry\n",
959 HOTKEY_ACTION)); 1045 HOTKEY_ACTION));
960 return (-ENODEV); 1046 goto do_fail3;
961 } else { 1047 } else {
962 hotkey_action->proc_fops = &hotkey_action_fops; 1048 hotkey_action->proc_fops = &hotkey_action_fops;
963 hotkey_action->owner = THIS_MODULE; 1049 hotkey_action->owner = THIS_MODULE;
@@ -970,7 +1056,7 @@ static int __init hotkey_init(void)
970 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1056 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
971 "Hotkey: Unable to create %s entry\n", 1057 "Hotkey: Unable to create %s entry\n",
972 HOTKEY_INFO)); 1058 HOTKEY_INFO));
973 return (-ENODEV); 1059 goto do_fail4;
974 } else { 1060 } else {
975 hotkey_info->proc_fops = &hotkey_info_fops; 1061 hotkey_info->proc_fops = &hotkey_info_fops;
976 hotkey_info->owner = THIS_MODULE; 1062 hotkey_info->owner = THIS_MODULE;
@@ -979,23 +1065,33 @@ static int __init hotkey_init(void)
979 } 1065 }
980 1066
981 result = acpi_bus_register_driver(&hotkey_driver); 1067 result = acpi_bus_register_driver(&hotkey_driver);
982 if (result < 0) { 1068 if (result < 0)
983 remove_proc_entry(HOTKEY_PROC, acpi_root_dir); 1069 goto do_fail5;
984 return (-ENODEV);
985 }
986 global_hotkey_list.count = 0; 1070 global_hotkey_list.count = 0;
987 global_hotkey_list.entries = &hotkey_entries; 1071 global_hotkey_list.entries = &hotkey_entries;
988 1072
989 INIT_LIST_HEAD(&hotkey_entries); 1073 INIT_LIST_HEAD(&hotkey_entries);
990 1074
991 return (0); 1075 return (0);
1076
1077do_fail5:
1078 remove_proc_entry(HOTKEY_INFO, hotkey_proc_dir);
1079do_fail4:
1080 remove_proc_entry(HOTKEY_ACTION, hotkey_proc_dir);
1081do_fail3:
1082 remove_proc_entry(HOTKEY_PL_CONFIG, hotkey_proc_dir);
1083do_fail2:
1084 remove_proc_entry(HOTKEY_EV_CONFIG, hotkey_proc_dir);
1085do_fail1:
1086 remove_proc_entry(HOTKEY_PROC, acpi_root_dir);
1087 return (-ENODEV);
992} 1088}
993 1089
994static void __exit hotkey_exit(void) 1090static void __exit hotkey_exit(void)
995{ 1091{
996 struct list_head *entries, *next; 1092 struct list_head *entries, *next;
997 1093
998 ACPI_FUNCTION_TRACE("hotkey_remove"); 1094 ACPI_FUNCTION_TRACE("hotkey_exit");
999 1095
1000 list_for_each_safe(entries, next, global_hotkey_list.entries) { 1096 list_for_each_safe(entries, next, global_hotkey_list.entries) {
1001 union acpi_hotkey *key = 1097 union acpi_hotkey *key =
diff --git a/drivers/acpi/motherboard.c b/drivers/acpi/motherboard.c
index 61ea70742d49..2934475d67d6 100644
--- a/drivers/acpi/motherboard.c
+++ b/drivers/acpi/motherboard.c
@@ -43,7 +43,7 @@ ACPI_MODULE_NAME ("acpi_motherboard")
43 */ 43 */
44#define IS_RESERVED_ADDR(base, len) \ 44#define IS_RESERVED_ADDR(base, len) \
45 (((len) > 0) && ((base) > 0) && ((base) + (len) < IO_SPACE_LIMIT) \ 45 (((len) > 0) && ((base) > 0) && ((base) + (len) < IO_SPACE_LIMIT) \
46 && ((base) + (len) > PCIBIOS_MIN_IO)) 46 && ((base) + (len) > 0x1000))
47 47
48/* 48/*
49 * Clearing the flag (IORESOURCE_BUSY) allows drivers to use 49 * Clearing the flag (IORESOURCE_BUSY) allows drivers to use
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index bdd9f37f8101..7289da3c4db6 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -145,10 +145,14 @@ acpi_os_vprintf(const char *fmt, va_list args)
145#endif 145#endif
146} 146}
147 147
148extern int acpi_in_resume;
148void * 149void *
149acpi_os_allocate(acpi_size size) 150acpi_os_allocate(acpi_size size)
150{ 151{
151 return kmalloc(size, GFP_KERNEL); 152 if (acpi_in_resume)
153 return kmalloc(size, GFP_ATOMIC);
154 else
155 return kmalloc(size, GFP_KERNEL);
152} 156}
153 157
154void 158void
diff --git a/drivers/acpi/pci_irq.c b/drivers/acpi/pci_irq.c
index d1f42b972821..bb973d2109a1 100644
--- a/drivers/acpi/pci_irq.c
+++ b/drivers/acpi/pci_irq.c
@@ -269,7 +269,51 @@ acpi_pci_irq_del_prt (int segment, int bus)
269/* -------------------------------------------------------------------------- 269/* --------------------------------------------------------------------------
270 PCI Interrupt Routing Support 270 PCI Interrupt Routing Support
271 -------------------------------------------------------------------------- */ 271 -------------------------------------------------------------------------- */
272typedef int (*irq_lookup_func)(struct acpi_prt_entry *, int *, int *, char **);
272 273
274static int
275acpi_pci_allocate_irq(struct acpi_prt_entry *entry,
276 int *edge_level,
277 int *active_high_low,
278 char **link)
279{
280 int irq;
281
282 ACPI_FUNCTION_TRACE("acpi_pci_allocate_irq");
283
284 if (entry->link.handle) {
285 irq = acpi_pci_link_allocate_irq(entry->link.handle,
286 entry->link.index, edge_level, active_high_low, link);
287 if (irq < 0) {
288 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Invalid IRQ link routing entry\n"));
289 return_VALUE(-1);
290 }
291 } else {
292 irq = entry->link.index;
293 *edge_level = ACPI_LEVEL_SENSITIVE;
294 *active_high_low = ACPI_ACTIVE_LOW;
295 }
296
297 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found IRQ %d\n", irq));
298 return_VALUE(irq);
299}
300
301static int
302acpi_pci_free_irq(struct acpi_prt_entry *entry,
303 int *edge_level,
304 int *active_high_low,
305 char **link)
306{
307 int irq;
308
309 ACPI_FUNCTION_TRACE("acpi_pci_free_irq");
310 if (entry->link.handle) {
311 irq = acpi_pci_link_free_irq(entry->link.handle);
312 } else {
313 irq = entry->link.index;
314 }
315 return_VALUE(irq);
316}
273/* 317/*
274 * acpi_pci_irq_lookup 318 * acpi_pci_irq_lookup
275 * success: return IRQ >= 0 319 * success: return IRQ >= 0
@@ -282,12 +326,13 @@ acpi_pci_irq_lookup (
282 int pin, 326 int pin,
283 int *edge_level, 327 int *edge_level,
284 int *active_high_low, 328 int *active_high_low,
285 char **link) 329 char **link,
330 irq_lookup_func func)
286{ 331{
287 struct acpi_prt_entry *entry = NULL; 332 struct acpi_prt_entry *entry = NULL;
288 int segment = pci_domain_nr(bus); 333 int segment = pci_domain_nr(bus);
289 int bus_nr = bus->number; 334 int bus_nr = bus->number;
290 int irq; 335 int ret;
291 336
292 ACPI_FUNCTION_TRACE("acpi_pci_irq_lookup"); 337 ACPI_FUNCTION_TRACE("acpi_pci_irq_lookup");
293 338
@@ -301,22 +346,8 @@ acpi_pci_irq_lookup (
301 return_VALUE(-1); 346 return_VALUE(-1);
302 } 347 }
303 348
304 if (entry->link.handle) { 349 ret = func(entry, edge_level, active_high_low, link);
305 irq = acpi_pci_link_get_irq(entry->link.handle, 350 return_VALUE(ret);
306 entry->link.index, edge_level, active_high_low, link);
307 if (irq < 0) {
308 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Invalid IRQ link routing entry\n"));
309 return_VALUE(-1);
310 }
311 } else {
312 irq = entry->link.index;
313 *edge_level = ACPI_LEVEL_SENSITIVE;
314 *active_high_low = ACPI_ACTIVE_LOW;
315 }
316
317 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found IRQ %d\n", irq));
318
319 return_VALUE(irq);
320} 351}
321 352
322/* 353/*
@@ -330,7 +361,8 @@ acpi_pci_irq_derive (
330 int pin, 361 int pin,
331 int *edge_level, 362 int *edge_level,
332 int *active_high_low, 363 int *active_high_low,
333 char **link) 364 char **link,
365 irq_lookup_func func)
334{ 366{
335 struct pci_dev *bridge = dev; 367 struct pci_dev *bridge = dev;
336 int irq = -1; 368 int irq = -1;
@@ -363,7 +395,7 @@ acpi_pci_irq_derive (
363 } 395 }
364 396
365 irq = acpi_pci_irq_lookup(bridge->bus, PCI_SLOT(bridge->devfn), 397 irq = acpi_pci_irq_lookup(bridge->bus, PCI_SLOT(bridge->devfn),
366 pin, edge_level, active_high_low, link); 398 pin, edge_level, active_high_low, link, func);
367 } 399 }
368 400
369 if (irq < 0) { 401 if (irq < 0) {
@@ -415,7 +447,7 @@ acpi_pci_irq_enable (
415 * values override any BIOS-assigned IRQs set during boot. 447 * values override any BIOS-assigned IRQs set during boot.
416 */ 448 */
417 irq = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin, 449 irq = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin,
418 &edge_level, &active_high_low, &link); 450 &edge_level, &active_high_low, &link, acpi_pci_allocate_irq);
419 451
420 /* 452 /*
421 * If no PRT entry was found, we'll try to derive an IRQ from the 453 * If no PRT entry was found, we'll try to derive an IRQ from the
@@ -423,7 +455,7 @@ acpi_pci_irq_enable (
423 */ 455 */
424 if (irq < 0) 456 if (irq < 0)
425 irq = acpi_pci_irq_derive(dev, pin, &edge_level, 457 irq = acpi_pci_irq_derive(dev, pin, &edge_level,
426 &active_high_low, &link); 458 &active_high_low, &link, acpi_pci_allocate_irq);
427 459
428 /* 460 /*
429 * No IRQ known to the ACPI subsystem - maybe the BIOS / 461 * No IRQ known to the ACPI subsystem - maybe the BIOS /
@@ -462,7 +494,9 @@ acpi_pci_irq_enable (
462EXPORT_SYMBOL(acpi_pci_irq_enable); 494EXPORT_SYMBOL(acpi_pci_irq_enable);
463 495
464 496
465#ifdef CONFIG_ACPI_DEALLOCATE_IRQ 497/* FIXME: implement x86/x86_64 version */
498void __attribute__((weak)) acpi_unregister_gsi(u32 i) {}
499
466void 500void
467acpi_pci_irq_disable ( 501acpi_pci_irq_disable (
468 struct pci_dev *dev) 502 struct pci_dev *dev)
@@ -489,14 +523,14 @@ acpi_pci_irq_disable (
489 * First we check the PCI IRQ routing table (PRT) for an IRQ. 523 * First we check the PCI IRQ routing table (PRT) for an IRQ.
490 */ 524 */
491 gsi = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin, 525 gsi = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin,
492 &edge_level, &active_high_low, NULL); 526 &edge_level, &active_high_low, NULL, acpi_pci_free_irq);
493 /* 527 /*
494 * If no PRT entry was found, we'll try to derive an IRQ from the 528 * If no PRT entry was found, we'll try to derive an IRQ from the
495 * device's parent bridge. 529 * device's parent bridge.
496 */ 530 */
497 if (gsi < 0) 531 if (gsi < 0)
498 gsi = acpi_pci_irq_derive(dev, pin, 532 gsi = acpi_pci_irq_derive(dev, pin,
499 &edge_level, &active_high_low, NULL); 533 &edge_level, &active_high_low, NULL, acpi_pci_free_irq);
500 if (gsi < 0) 534 if (gsi < 0)
501 return_VOID; 535 return_VOID;
502 536
@@ -512,4 +546,3 @@ acpi_pci_irq_disable (
512 546
513 return_VOID; 547 return_VOID;
514} 548}
515#endif /* CONFIG_ACPI_DEALLOCATE_IRQ */
diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
index 6ad0e77df9b3..834c2ceff1aa 100644
--- a/drivers/acpi/pci_link.c
+++ b/drivers/acpi/pci_link.c
@@ -68,6 +68,10 @@ static struct acpi_driver acpi_pci_link_driver = {
68 }, 68 },
69}; 69};
70 70
71/*
72 * If a link is initialized, we never change its active and initialized
73 * later even the link is disable. Instead, we just repick the active irq
74 */
71struct acpi_pci_link_irq { 75struct acpi_pci_link_irq {
72 u8 active; /* Current IRQ */ 76 u8 active; /* Current IRQ */
73 u8 edge_level; /* All IRQs */ 77 u8 edge_level; /* All IRQs */
@@ -76,8 +80,7 @@ struct acpi_pci_link_irq {
76 u8 possible_count; 80 u8 possible_count;
77 u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE]; 81 u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
78 u8 initialized:1; 82 u8 initialized:1;
79 u8 suspend_resume:1; 83 u8 reserved:7;
80 u8 reserved:6;
81}; 84};
82 85
83struct acpi_pci_link { 86struct acpi_pci_link {
@@ -85,12 +88,14 @@ struct acpi_pci_link {
85 struct acpi_device *device; 88 struct acpi_device *device;
86 acpi_handle handle; 89 acpi_handle handle;
87 struct acpi_pci_link_irq irq; 90 struct acpi_pci_link_irq irq;
91 int refcnt;
88}; 92};
89 93
90static struct { 94static struct {
91 int count; 95 int count;
92 struct list_head entries; 96 struct list_head entries;
93} acpi_link; 97} acpi_link;
98DECLARE_MUTEX(acpi_link_lock);
94 99
95 100
96/* -------------------------------------------------------------------------- 101/* --------------------------------------------------------------------------
@@ -532,12 +537,12 @@ static int acpi_pci_link_allocate(
532 537
533 ACPI_FUNCTION_TRACE("acpi_pci_link_allocate"); 538 ACPI_FUNCTION_TRACE("acpi_pci_link_allocate");
534 539
535 if (link->irq.suspend_resume) { 540 if (link->irq.initialized) {
536 acpi_pci_link_set(link, link->irq.active); 541 if (link->refcnt == 0)
537 link->irq.suspend_resume = 0; 542 /* This means the link is disabled but initialized */
538 } 543 acpi_pci_link_set(link, link->irq.active);
539 if (link->irq.initialized)
540 return_VALUE(0); 544 return_VALUE(0);
545 }
541 546
542 /* 547 /*
543 * search for active IRQ in list of possible IRQs. 548 * search for active IRQ in list of possible IRQs.
@@ -596,13 +601,13 @@ static int acpi_pci_link_allocate(
596} 601}
597 602
598/* 603/*
599 * acpi_pci_link_get_irq 604 * acpi_pci_link_allocate_irq
600 * success: return IRQ >= 0 605 * success: return IRQ >= 0
601 * failure: return -1 606 * failure: return -1
602 */ 607 */
603 608
604int 609int
605acpi_pci_link_get_irq ( 610acpi_pci_link_allocate_irq (
606 acpi_handle handle, 611 acpi_handle handle,
607 int index, 612 int index,
608 int *edge_level, 613 int *edge_level,
@@ -613,7 +618,7 @@ acpi_pci_link_get_irq (
613 struct acpi_device *device = NULL; 618 struct acpi_device *device = NULL;
614 struct acpi_pci_link *link = NULL; 619 struct acpi_pci_link *link = NULL;
615 620
616 ACPI_FUNCTION_TRACE("acpi_pci_link_get_irq"); 621 ACPI_FUNCTION_TRACE("acpi_pci_link_allocate_irq");
617 622
618 result = acpi_bus_get_device(handle, &device); 623 result = acpi_bus_get_device(handle, &device);
619 if (result) { 624 if (result) {
@@ -633,21 +638,81 @@ acpi_pci_link_get_irq (
633 return_VALUE(-1); 638 return_VALUE(-1);
634 } 639 }
635 640
636 if (acpi_pci_link_allocate(link)) 641 down(&acpi_link_lock);
642 if (acpi_pci_link_allocate(link)) {
643 up(&acpi_link_lock);
637 return_VALUE(-1); 644 return_VALUE(-1);
645 }
638 646
639 if (!link->irq.active) { 647 if (!link->irq.active) {
648 up(&acpi_link_lock);
640 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Link active IRQ is 0!\n")); 649 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Link active IRQ is 0!\n"));
641 return_VALUE(-1); 650 return_VALUE(-1);
642 } 651 }
652 link->refcnt ++;
653 up(&acpi_link_lock);
643 654
644 if (edge_level) *edge_level = link->irq.edge_level; 655 if (edge_level) *edge_level = link->irq.edge_level;
645 if (active_high_low) *active_high_low = link->irq.active_high_low; 656 if (active_high_low) *active_high_low = link->irq.active_high_low;
646 if (name) *name = acpi_device_bid(link->device); 657 if (name) *name = acpi_device_bid(link->device);
658 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
659 "Link %s is referenced\n", acpi_device_bid(link->device)));
647 return_VALUE(link->irq.active); 660 return_VALUE(link->irq.active);
648} 661}
649 662
663/*
664 * We don't change link's irq information here. After it is reenabled, we
665 * continue use the info
666 */
667int
668acpi_pci_link_free_irq(acpi_handle handle)
669{
670 struct acpi_device *device = NULL;
671 struct acpi_pci_link *link = NULL;
672 acpi_status result;
673
674 ACPI_FUNCTION_TRACE("acpi_pci_link_free_irq");
675
676 result = acpi_bus_get_device(handle, &device);
677 if (result) {
678 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link device\n"));
679 return_VALUE(-1);
680 }
681
682 link = (struct acpi_pci_link *) acpi_driver_data(device);
683 if (!link) {
684 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link context\n"));
685 return_VALUE(-1);
686 }
687
688 down(&acpi_link_lock);
689 if (!link->irq.initialized) {
690 up(&acpi_link_lock);
691 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Link isn't initialized\n"));
692 return_VALUE(-1);
693 }
650 694
695#ifdef FUTURE_USE
696 /*
697 * The Link reference count allows us to _DISable an unused link
698 * and suspend time, and set it again on resume.
699 * However, 2.6.12 still has irq_router.resume
700 * which blindly restores the link state.
701 * So we disable the reference count method
702 * to prevent duplicate acpi_pci_link_set()
703 * which would harm some systems
704 */
705 link->refcnt --;
706#endif
707 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
708 "Link %s is dereferenced\n", acpi_device_bid(link->device)));
709
710 if (link->refcnt == 0) {
711 acpi_ut_evaluate_object(link->handle, "_DIS", 0, NULL);
712 }
713 up(&acpi_link_lock);
714 return_VALUE(link->irq.active);
715}
651/* -------------------------------------------------------------------------- 716/* --------------------------------------------------------------------------
652 Driver Interface 717 Driver Interface
653 -------------------------------------------------------------------------- */ 718 -------------------------------------------------------------------------- */
@@ -677,6 +742,7 @@ acpi_pci_link_add (
677 strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS); 742 strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS);
678 acpi_driver_data(device) = link; 743 acpi_driver_data(device) = link;
679 744
745 down(&acpi_link_lock);
680 result = acpi_pci_link_get_possible(link); 746 result = acpi_pci_link_get_possible(link);
681 if (result) 747 if (result)
682 goto end; 748 goto end;
@@ -712,6 +778,7 @@ acpi_pci_link_add (
712end: 778end:
713 /* disable all links -- to be activated on use */ 779 /* disable all links -- to be activated on use */
714 acpi_ut_evaluate_object(link->handle, "_DIS", 0, NULL); 780 acpi_ut_evaluate_object(link->handle, "_DIS", 0, NULL);
781 up(&acpi_link_lock);
715 782
716 if (result) 783 if (result)
717 kfree(link); 784 kfree(link);
@@ -720,24 +787,42 @@ end:
720} 787}
721 788
722static int 789static int
723irqrouter_suspend( 790acpi_pci_link_resume(
724 struct sys_device *dev, 791 struct acpi_pci_link *link)
725 u32 state) 792{
793 ACPI_FUNCTION_TRACE("acpi_pci_link_resume");
794
795 if (link->refcnt && link->irq.active && link->irq.initialized)
796 return_VALUE(acpi_pci_link_set(link, link->irq.active));
797 else
798 return_VALUE(0);
799}
800
801/*
802 * FIXME: this is a workaround to avoid nasty warning. It will be removed
803 * after every device calls pci_disable_device in .resume.
804 */
805int acpi_in_resume;
806static int
807irqrouter_resume(
808 struct sys_device *dev)
726{ 809{
727 struct list_head *node = NULL; 810 struct list_head *node = NULL;
728 struct acpi_pci_link *link = NULL; 811 struct acpi_pci_link *link = NULL;
729 812
730 ACPI_FUNCTION_TRACE("irqrouter_suspend"); 813 ACPI_FUNCTION_TRACE("irqrouter_resume");
731 814
815 acpi_in_resume = 1;
732 list_for_each(node, &acpi_link.entries) { 816 list_for_each(node, &acpi_link.entries) {
733 link = list_entry(node, struct acpi_pci_link, node); 817 link = list_entry(node, struct acpi_pci_link, node);
734 if (!link) { 818 if (!link) {
735 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link context\n")); 819 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
820 "Invalid link context\n"));
736 continue; 821 continue;
737 } 822 }
738 if (link->irq.active && link->irq.initialized) 823 acpi_pci_link_resume(link);
739 link->irq.suspend_resume = 1;
740 } 824 }
825 acpi_in_resume = 0;
741 return_VALUE(0); 826 return_VALUE(0);
742} 827}
743 828
@@ -756,8 +841,9 @@ acpi_pci_link_remove (
756 841
757 link = (struct acpi_pci_link *) acpi_driver_data(device); 842 link = (struct acpi_pci_link *) acpi_driver_data(device);
758 843
759 /* TBD: Acquire/release lock */ 844 down(&acpi_link_lock);
760 list_del(&link->node); 845 list_del(&link->node);
846 up(&acpi_link_lock);
761 847
762 kfree(link); 848 kfree(link);
763 849
@@ -849,9 +935,10 @@ int __init acpi_irq_balance_set(char *str)
849__setup("acpi_irq_balance", acpi_irq_balance_set); 935__setup("acpi_irq_balance", acpi_irq_balance_set);
850 936
851 937
938/* FIXME: we will remove this interface after all drivers call pci_disable_device */
852static struct sysdev_class irqrouter_sysdev_class = { 939static struct sysdev_class irqrouter_sysdev_class = {
853 set_kset_name("irqrouter"), 940 set_kset_name("irqrouter"),
854 .suspend = irqrouter_suspend, 941 .resume = irqrouter_resume,
855}; 942};
856 943
857 944
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 893b074e3d1a..2c04740c6543 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -81,30 +81,32 @@ module_param(bm_history, uint, 0644);
81 * 81 *
82 * To skip this limit, boot/load with a large max_cstate limit. 82 * To skip this limit, boot/load with a large max_cstate limit.
83 */ 83 */
84static int no_c2c3(struct dmi_system_id *id) 84static int set_max_cstate(struct dmi_system_id *id)
85{ 85{
86 if (max_cstate > ACPI_PROCESSOR_MAX_POWER) 86 if (max_cstate > ACPI_PROCESSOR_MAX_POWER)
87 return 0; 87 return 0;
88 88
89 printk(KERN_NOTICE PREFIX "%s detected - C2,C3 disabled." 89 printk(KERN_NOTICE PREFIX "%s detected - limiting to C%ld max_cstate."
90 " Override with \"processor.max_cstate=%d\"\n", id->ident, 90 " Override with \"processor.max_cstate=%d\"\n", id->ident,
91 ACPI_PROCESSOR_MAX_POWER + 1); 91 (long)id->driver_data, ACPI_PROCESSOR_MAX_POWER + 1);
92 92
93 max_cstate = 1; 93 max_cstate = (long)id->driver_data;
94 94
95 return 0; 95 return 0;
96} 96}
97 97
98 98
99
100
101static struct dmi_system_id __initdata processor_power_dmi_table[] = { 99static struct dmi_system_id __initdata processor_power_dmi_table[] = {
102 { no_c2c3, "IBM ThinkPad R40e", { 100 { set_max_cstate, "IBM ThinkPad R40e", {
103 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"), 101 DMI_MATCH(DMI_BIOS_VENDOR,"IBM"),
104 DMI_MATCH(DMI_BIOS_VERSION,"1SET60WW") }}, 102 DMI_MATCH(DMI_BIOS_VERSION,"1SET60WW") }, (void*)1},
105 { no_c2c3, "Medion 41700", { 103 { set_max_cstate, "Medion 41700", {
104 DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
105 DMI_MATCH(DMI_BIOS_VERSION,"R01-A1J") }, (void*)1},
106 { set_max_cstate, "Clevo 5600D", {
106 DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"), 107 DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
107 DMI_MATCH(DMI_BIOS_VERSION,"R01-A1J") }}, 108 DMI_MATCH(DMI_BIOS_VERSION,"SHE845M0.86C.0013.D.0302131307") },
109 (void*)2},
108 {}, 110 {},
109}; 111};
110 112
@@ -549,7 +551,8 @@ static int acpi_processor_get_power_info_default_c1 (struct acpi_processor *pr)
549 ACPI_FUNCTION_TRACE("acpi_processor_get_power_info_default_c1"); 551 ACPI_FUNCTION_TRACE("acpi_processor_get_power_info_default_c1");
550 552
551 for (i = 0; i < ACPI_PROCESSOR_MAX_POWER; i++) 553 for (i = 0; i < ACPI_PROCESSOR_MAX_POWER; i++)
552 memset(pr->power.states, 0, sizeof(struct acpi_processor_cx)); 554 memset(&(pr->power.states[i]), 0,
555 sizeof(struct acpi_processor_cx));
553 556
554 /* if info is obtained from pblk/fadt, type equals state */ 557 /* if info is obtained from pblk/fadt, type equals state */
555 pr->power.states[ACPI_STATE_C1].type = ACPI_STATE_C1; 558 pr->power.states[ACPI_STATE_C1].type = ACPI_STATE_C1;
@@ -580,7 +583,8 @@ static int acpi_processor_get_power_info_cst (struct acpi_processor *pr)
580 583
581 pr->power.count = 0; 584 pr->power.count = 0;
582 for (i = 0; i < ACPI_PROCESSOR_MAX_POWER; i++) 585 for (i = 0; i < ACPI_PROCESSOR_MAX_POWER; i++)
583 memset(pr->power.states, 0, sizeof(struct acpi_processor_cx)); 586 memset(&(pr->power.states[i]), 0,
587 sizeof(struct acpi_processor_cx));
584 588
585 status = acpi_evaluate_object(pr->handle, "_CST", NULL, &buffer); 589 status = acpi_evaluate_object(pr->handle, "_CST", NULL, &buffer);
586 if (ACPI_FAILURE(status)) { 590 if (ACPI_FAILURE(status)) {
@@ -763,7 +767,6 @@ static void acpi_processor_power_verify_c3(
763 } 767 }
764 768
765 if (pr->flags.bm_check) { 769 if (pr->flags.bm_check) {
766 printk("Disabling BM access before entering C3\n");
767 /* bus mastering control is necessary */ 770 /* bus mastering control is necessary */
768 if (!pr->flags.bm_control) { 771 if (!pr->flags.bm_control) {
769 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 772 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
@@ -771,7 +774,6 @@ static void acpi_processor_power_verify_c3(
771 return_VOID; 774 return_VOID;
772 } 775 }
773 } else { 776 } else {
774 printk("Invalidating cache before entering C3\n");
775 /* 777 /*
776 * WBINVD should be set in fadt, for C3 state to be 778 * WBINVD should be set in fadt, for C3 state to be
777 * supported on when bm_check is not required. 779 * supported on when bm_check is not required.
@@ -842,7 +844,7 @@ static int acpi_processor_get_power_info (
842 result = acpi_processor_get_power_info_cst(pr); 844 result = acpi_processor_get_power_info_cst(pr);
843 if ((result) || (acpi_processor_power_verify(pr) < 2)) { 845 if ((result) || (acpi_processor_power_verify(pr) < 2)) {
844 result = acpi_processor_get_power_info_fadt(pr); 846 result = acpi_processor_get_power_info_fadt(pr);
845 if (result) 847 if ((result) || (acpi_processor_power_verify(pr) < 2))
846 result = acpi_processor_get_power_info_default_c1(pr); 848 result = acpi_processor_get_power_info_default_c1(pr);
847 } 849 }
848 850
diff --git a/drivers/block/as-iosched.c b/drivers/block/as-iosched.c
index 91aeb678135d..95c0a3690b0f 100644
--- a/drivers/block/as-iosched.c
+++ b/drivers/block/as-iosched.c
@@ -1935,23 +1935,15 @@ struct as_fs_entry {
1935static ssize_t 1935static ssize_t
1936as_var_show(unsigned int var, char *page) 1936as_var_show(unsigned int var, char *page)
1937{ 1937{
1938 var = (var * 1000) / HZ;
1939 return sprintf(page, "%d\n", var); 1938 return sprintf(page, "%d\n", var);
1940} 1939}
1941 1940
1942static ssize_t 1941static ssize_t
1943as_var_store(unsigned long *var, const char *page, size_t count) 1942as_var_store(unsigned long *var, const char *page, size_t count)
1944{ 1943{
1945 unsigned long tmp;
1946 char *p = (char *) page; 1944 char *p = (char *) page;
1947 1945
1948 tmp = simple_strtoul(p, &p, 10); 1946 *var = simple_strtoul(p, &p, 10);
1949 if (tmp != 0) {
1950 tmp = (tmp * HZ) / 1000;
1951 if (tmp == 0)
1952 tmp = 1;
1953 }
1954 *var = tmp;
1955 return count; 1947 return count;
1956} 1948}
1957 1949
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 3e9fb6e4a52a..418b1469d75d 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -1135,7 +1135,7 @@ static int revalidate_allvol(ctlr_info_t *host)
1135 /* this is for the online array utilities */ 1135 /* this is for the online array utilities */
1136 if (!drv->heads && i) 1136 if (!drv->heads && i)
1137 continue; 1137 continue;
1138 blk_queue_hardsect_size(host->queue, drv->block_size); 1138 blk_queue_hardsect_size(drv->queue, drv->block_size);
1139 set_capacity(disk, drv->nr_blocks); 1139 set_capacity(disk, drv->nr_blocks);
1140 add_disk(disk); 1140 add_disk(disk);
1141 } 1141 }
@@ -1691,7 +1691,7 @@ static int cciss_revalidate(struct gendisk *disk)
1691 cciss_read_capacity(h->ctlr, logvol, size_buff, 1, &total_size, &block_size); 1691 cciss_read_capacity(h->ctlr, logvol, size_buff, 1, &total_size, &block_size);
1692 cciss_geometry_inquiry(h->ctlr, logvol, 1, total_size, block_size, inq_buff, drv); 1692 cciss_geometry_inquiry(h->ctlr, logvol, 1, total_size, block_size, inq_buff, drv);
1693 1693
1694 blk_queue_hardsect_size(h->queue, drv->block_size); 1694 blk_queue_hardsect_size(drv->queue, drv->block_size);
1695 set_capacity(disk, drv->nr_blocks); 1695 set_capacity(disk, drv->nr_blocks);
1696 1696
1697 kfree(size_buff); 1697 kfree(size_buff);
@@ -2248,12 +2248,12 @@ static irqreturn_t do_cciss_intr(int irq, void *dev_id, struct pt_regs *regs)
2248 * them up. We will also keep track of the next queue to run so 2248 * them up. We will also keep track of the next queue to run so
2249 * that every queue gets a chance to be started first. 2249 * that every queue gets a chance to be started first.
2250 */ 2250 */
2251 for (j=0; j < NWD; j++){ 2251 for (j=0; j < h->highest_lun + 1; j++){
2252 int curr_queue = (start_queue + j) % NWD; 2252 int curr_queue = (start_queue + j) % (h->highest_lun + 1);
2253 /* make sure the disk has been added and the drive is real 2253 /* make sure the disk has been added and the drive is real
2254 * because this can be called from the middle of init_one. 2254 * because this can be called from the middle of init_one.
2255 */ 2255 */
2256 if(!(h->gendisk[curr_queue]->queue) || 2256 if(!(h->drv[curr_queue].queue) ||
2257 !(h->drv[curr_queue].heads)) 2257 !(h->drv[curr_queue].heads))
2258 continue; 2258 continue;
2259 blk_start_queue(h->gendisk[curr_queue]->queue); 2259 blk_start_queue(h->gendisk[curr_queue]->queue);
@@ -2264,14 +2264,14 @@ static irqreturn_t do_cciss_intr(int irq, void *dev_id, struct pt_regs *regs)
2264 if ((find_first_zero_bit(h->cmd_pool_bits, NR_CMDS)) == NR_CMDS) 2264 if ((find_first_zero_bit(h->cmd_pool_bits, NR_CMDS)) == NR_CMDS)
2265 { 2265 {
2266 if (curr_queue == start_queue){ 2266 if (curr_queue == start_queue){
2267 h->next_to_run = (start_queue + 1) % NWD; 2267 h->next_to_run = (start_queue + 1) % (h->highest_lun + 1);
2268 goto cleanup; 2268 goto cleanup;
2269 } else { 2269 } else {
2270 h->next_to_run = curr_queue; 2270 h->next_to_run = curr_queue;
2271 goto cleanup; 2271 goto cleanup;
2272 } 2272 }
2273 } else { 2273 } else {
2274 curr_queue = (curr_queue + 1) % NWD; 2274 curr_queue = (curr_queue + 1) % (h->highest_lun + 1);
2275 } 2275 }
2276 } 2276 }
2277 2277
@@ -2279,7 +2279,6 @@ cleanup:
2279 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 2279 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
2280 return IRQ_HANDLED; 2280 return IRQ_HANDLED;
2281} 2281}
2282
2283/* 2282/*
2284 * We cannot read the structure directly, for portablity we must use 2283 * We cannot read the structure directly, for portablity we must use
2285 * the io functions. 2284 * the io functions.
@@ -2789,13 +2788,6 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
2789 } 2788 }
2790 2789
2791 spin_lock_init(&hba[i]->lock); 2790 spin_lock_init(&hba[i]->lock);
2792 q = blk_init_queue(do_cciss_request, &hba[i]->lock);
2793 if (!q)
2794 goto clean4;
2795
2796 q->backing_dev_info.ra_pages = READ_AHEAD;
2797 hba[i]->queue = q;
2798 q->queuedata = hba[i];
2799 2791
2800 /* Initialize the pdev driver private data. 2792 /* Initialize the pdev driver private data.
2801 have it point to hba[i]. */ 2793 have it point to hba[i]. */
@@ -2817,6 +2809,20 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
2817 2809
2818 cciss_procinit(i); 2810 cciss_procinit(i);
2819 2811
2812 for(j=0; j < NWD; j++) { /* mfm */
2813 drive_info_struct *drv = &(hba[i]->drv[j]);
2814 struct gendisk *disk = hba[i]->gendisk[j];
2815
2816 q = blk_init_queue(do_cciss_request, &hba[i]->lock);
2817 if (!q) {
2818 printk(KERN_ERR
2819 "cciss: unable to allocate queue for disk %d\n",
2820 j);
2821 break;
2822 }
2823 drv->queue = q;
2824
2825 q->backing_dev_info.ra_pages = READ_AHEAD;
2820 blk_queue_bounce_limit(q, hba[i]->pdev->dma_mask); 2826 blk_queue_bounce_limit(q, hba[i]->pdev->dma_mask);
2821 2827
2822 /* This is a hardware imposed limit. */ 2828 /* This is a hardware imposed limit. */
@@ -2827,26 +2833,23 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
2827 2833
2828 blk_queue_max_sectors(q, 512); 2834 blk_queue_max_sectors(q, 512);
2829 2835
2830 2836 q->queuedata = hba[i];
2831 for(j=0; j<NWD; j++) {
2832 drive_info_struct *drv = &(hba[i]->drv[j]);
2833 struct gendisk *disk = hba[i]->gendisk[j];
2834
2835 sprintf(disk->disk_name, "cciss/c%dd%d", i, j); 2837 sprintf(disk->disk_name, "cciss/c%dd%d", i, j);
2836 sprintf(disk->devfs_name, "cciss/host%d/target%d", i, j); 2838 sprintf(disk->devfs_name, "cciss/host%d/target%d", i, j);
2837 disk->major = hba[i]->major; 2839 disk->major = hba[i]->major;
2838 disk->first_minor = j << NWD_SHIFT; 2840 disk->first_minor = j << NWD_SHIFT;
2839 disk->fops = &cciss_fops; 2841 disk->fops = &cciss_fops;
2840 disk->queue = hba[i]->queue; 2842 disk->queue = q;
2841 disk->private_data = drv; 2843 disk->private_data = drv;
2842 /* we must register the controller even if no disks exist */ 2844 /* we must register the controller even if no disks exist */
2843 /* this is for the online array utilities */ 2845 /* this is for the online array utilities */
2844 if(!drv->heads && j) 2846 if(!drv->heads && j)
2845 continue; 2847 continue;
2846 blk_queue_hardsect_size(hba[i]->queue, drv->block_size); 2848 blk_queue_hardsect_size(q, drv->block_size);
2847 set_capacity(disk, drv->nr_blocks); 2849 set_capacity(disk, drv->nr_blocks);
2848 add_disk(disk); 2850 add_disk(disk);
2849 } 2851 }
2852
2850 return(1); 2853 return(1);
2851 2854
2852clean4: 2855clean4:
@@ -2912,10 +2915,10 @@ static void __devexit cciss_remove_one (struct pci_dev *pdev)
2912 for (j = 0; j < NWD; j++) { 2915 for (j = 0; j < NWD; j++) {
2913 struct gendisk *disk = hba[i]->gendisk[j]; 2916 struct gendisk *disk = hba[i]->gendisk[j];
2914 if (disk->flags & GENHD_FL_UP) 2917 if (disk->flags & GENHD_FL_UP)
2918 blk_cleanup_queue(disk->queue);
2915 del_gendisk(disk); 2919 del_gendisk(disk);
2916 } 2920 }
2917 2921
2918 blk_cleanup_queue(hba[i]->queue);
2919 pci_free_consistent(hba[i]->pdev, NR_CMDS * sizeof(CommandList_struct), 2922 pci_free_consistent(hba[i]->pdev, NR_CMDS * sizeof(CommandList_struct),
2920 hba[i]->cmd_pool, hba[i]->cmd_pool_dhandle); 2923 hba[i]->cmd_pool, hba[i]->cmd_pool_dhandle);
2921 pci_free_consistent(hba[i]->pdev, NR_CMDS * sizeof( ErrorInfo_struct), 2924 pci_free_consistent(hba[i]->pdev, NR_CMDS * sizeof( ErrorInfo_struct),
diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
index 8fb19206eddb..566587d0a500 100644
--- a/drivers/block/cciss.h
+++ b/drivers/block/cciss.h
@@ -29,6 +29,7 @@ typedef struct _drive_info_struct
29{ 29{
30 __u32 LunID; 30 __u32 LunID;
31 int usage_count; 31 int usage_count;
32 struct request_queue *queue;
32 sector_t nr_blocks; 33 sector_t nr_blocks;
33 int block_size; 34 int block_size;
34 int heads; 35 int heads;
@@ -72,7 +73,6 @@ struct ctlr_info
72 unsigned int maxQsinceinit; 73 unsigned int maxQsinceinit;
73 unsigned int maxSG; 74 unsigned int maxSG;
74 spinlock_t lock; 75 spinlock_t lock;
75 struct request_queue *queue;
76 76
77 //* pointers to command and error info pool */ 77 //* pointers to command and error info pool */
78 CommandList_struct *cmd_pool; 78 CommandList_struct *cmd_pool;
@@ -260,7 +260,7 @@ struct board_type {
260 struct access_method *access; 260 struct access_method *access;
261}; 261};
262 262
263#define CCISS_LOCK(i) (hba[i]->queue->queue_lock) 263#define CCISS_LOCK(i) (&hba[i]->lock)
264 264
265#endif /* CCISS_H */ 265#endif /* CCISS_H */
266 266
diff --git a/drivers/block/cfq-iosched.c b/drivers/block/cfq-iosched.c
index de5746e38af9..2435a7c99b2b 100644
--- a/drivers/block/cfq-iosched.c
+++ b/drivers/block/cfq-iosched.c
@@ -1281,6 +1281,7 @@ dispatch:
1281 */ 1281 */
1282 if (!cfq_crq_in_driver(crq) && 1282 if (!cfq_crq_in_driver(crq) &&
1283 !cfq_cfqq_idle_window(cfqq) && 1283 !cfq_cfqq_idle_window(cfqq) &&
1284 !blk_barrier_rq(rq) &&
1284 cfqd->rq_in_driver >= cfqd->cfq_max_depth) 1285 cfqd->rq_in_driver >= cfqd->cfq_max_depth)
1285 return NULL; 1286 return NULL;
1286 1287
diff --git a/drivers/block/ll_rw_blk.c b/drivers/block/ll_rw_blk.c
index 692a5fced76e..3c818544475e 100644
--- a/drivers/block/ll_rw_blk.c
+++ b/drivers/block/ll_rw_blk.c
@@ -719,7 +719,7 @@ struct request *blk_queue_find_tag(request_queue_t *q, int tag)
719{ 719{
720 struct blk_queue_tag *bqt = q->queue_tags; 720 struct blk_queue_tag *bqt = q->queue_tags;
721 721
722 if (unlikely(bqt == NULL || tag >= bqt->max_depth)) 722 if (unlikely(bqt == NULL || tag >= bqt->real_max_depth))
723 return NULL; 723 return NULL;
724 724
725 return bqt->tag_index[tag]; 725 return bqt->tag_index[tag];
@@ -798,6 +798,7 @@ init_tag_map(request_queue_t *q, struct blk_queue_tag *tags, int depth)
798 798
799 memset(tag_index, 0, depth * sizeof(struct request *)); 799 memset(tag_index, 0, depth * sizeof(struct request *));
800 memset(tag_map, 0, nr_ulongs * sizeof(unsigned long)); 800 memset(tag_map, 0, nr_ulongs * sizeof(unsigned long));
801 tags->real_max_depth = depth;
801 tags->max_depth = depth; 802 tags->max_depth = depth;
802 tags->tag_index = tag_index; 803 tags->tag_index = tag_index;
803 tags->tag_map = tag_map; 804 tags->tag_map = tag_map;
@@ -872,11 +873,22 @@ int blk_queue_resize_tags(request_queue_t *q, int new_depth)
872 return -ENXIO; 873 return -ENXIO;
873 874
874 /* 875 /*
876 * if we already have large enough real_max_depth. just
877 * adjust max_depth. *NOTE* as requests with tag value
878 * between new_depth and real_max_depth can be in-flight, tag
879 * map can not be shrunk blindly here.
880 */
881 if (new_depth <= bqt->real_max_depth) {
882 bqt->max_depth = new_depth;
883 return 0;
884 }
885
886 /*
875 * save the old state info, so we can copy it back 887 * save the old state info, so we can copy it back
876 */ 888 */
877 tag_index = bqt->tag_index; 889 tag_index = bqt->tag_index;
878 tag_map = bqt->tag_map; 890 tag_map = bqt->tag_map;
879 max_depth = bqt->max_depth; 891 max_depth = bqt->real_max_depth;
880 892
881 if (init_tag_map(q, bqt, new_depth)) 893 if (init_tag_map(q, bqt, new_depth))
882 return -ENOMEM; 894 return -ENOMEM;
@@ -913,7 +925,7 @@ void blk_queue_end_tag(request_queue_t *q, struct request *rq)
913 925
914 BUG_ON(tag == -1); 926 BUG_ON(tag == -1);
915 927
916 if (unlikely(tag >= bqt->max_depth)) 928 if (unlikely(tag >= bqt->real_max_depth))
917 /* 929 /*
918 * This can happen after tag depth has been reduced. 930 * This can happen after tag depth has been reduced.
919 * FIXME: how about a warning or info message here? 931 * FIXME: how about a warning or info message here?
diff --git a/drivers/block/sx8.c b/drivers/block/sx8.c
index 9db0a9e3e59c..d57007b92f77 100644
--- a/drivers/block/sx8.c
+++ b/drivers/block/sx8.c
@@ -1582,7 +1582,7 @@ static int carm_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1582 if (rc) 1582 if (rc)
1583 goto err_out; 1583 goto err_out;
1584 1584
1585#if IF_64BIT_DMA_IS_POSSIBLE /* grrrr... */ 1585#ifdef IF_64BIT_DMA_IS_POSSIBLE /* grrrr... */
1586 rc = pci_set_dma_mask(pdev, DMA_64BIT_MASK); 1586 rc = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
1587 if (!rc) { 1587 if (!rc) {
1588 rc = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK); 1588 rc = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
@@ -1601,7 +1601,7 @@ static int carm_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1601 goto err_out_regions; 1601 goto err_out_regions;
1602 } 1602 }
1603 pci_dac = 0; 1603 pci_dac = 0;
1604#if IF_64BIT_DMA_IS_POSSIBLE /* grrrr... */ 1604#ifdef IF_64BIT_DMA_IS_POSSIBLE /* grrrr... */
1605 } 1605 }
1606#endif 1606#endif
1607 1607
diff --git a/drivers/block/ub.c b/drivers/block/ub.c
index 685f061e69b2..a026567f5d18 100644
--- a/drivers/block/ub.c
+++ b/drivers/block/ub.c
@@ -23,6 +23,7 @@
23 * -- Exterminate P3 printks 23 * -- Exterminate P3 printks
24 * -- Resove XXX's 24 * -- Resove XXX's
25 * -- Redo "benh's retries", perhaps have spin-up code to handle them. V:D=? 25 * -- Redo "benh's retries", perhaps have spin-up code to handle them. V:D=?
26 * -- CLEAR, CLR2STS, CLRRS seem to be ripe for refactoring.
26 */ 27 */
27#include <linux/kernel.h> 28#include <linux/kernel.h>
28#include <linux/module.h> 29#include <linux/module.h>
@@ -38,6 +39,73 @@
38#define UB_MAJOR 180 39#define UB_MAJOR 180
39 40
40/* 41/*
42 * The command state machine is the key model for understanding of this driver.
43 *
44 * The general rule is that all transitions are done towards the bottom
45 * of the diagram, thus preventing any loops.
46 *
47 * An exception to that is how the STAT state is handled. A counter allows it
48 * to be re-entered along the path marked with [C].
49 *
50 * +--------+
51 * ! INIT !
52 * +--------+
53 * !
54 * ub_scsi_cmd_start fails ->--------------------------------------\
55 * ! !
56 * V !
57 * +--------+ !
58 * ! CMD ! !
59 * +--------+ !
60 * ! +--------+ !
61 * was -EPIPE -->-------------------------------->! CLEAR ! !
62 * ! +--------+ !
63 * ! ! !
64 * was error -->------------------------------------- ! --------->\
65 * ! ! !
66 * /--<-- cmd->dir == NONE ? ! !
67 * ! ! ! !
68 * ! V ! !
69 * ! +--------+ ! !
70 * ! ! DATA ! ! !
71 * ! +--------+ ! !
72 * ! ! +---------+ ! !
73 * ! was -EPIPE -->--------------->! CLR2STS ! ! !
74 * ! ! +---------+ ! !
75 * ! ! ! ! !
76 * ! ! was error -->---- ! --------->\
77 * ! was error -->--------------------- ! ------------- ! --------->\
78 * ! ! ! ! !
79 * ! V ! ! !
80 * \--->+--------+ ! ! !
81 * ! STAT !<--------------------------/ ! !
82 * /--->+--------+ ! !
83 * ! ! ! !
84 * [C] was -EPIPE -->-----------\ ! !
85 * ! ! ! ! !
86 * +<---- len == 0 ! ! !
87 * ! ! ! ! !
88 * ! was error -->--------------------------------------!---------->\
89 * ! ! ! ! !
90 * +<---- bad CSW ! ! !
91 * +<---- bad tag ! ! !
92 * ! ! V ! !
93 * ! ! +--------+ ! !
94 * ! ! ! CLRRS ! ! !
95 * ! ! +--------+ ! !
96 * ! ! ! ! !
97 * \------- ! --------------------[C]--------\ ! !
98 * ! ! ! !
99 * cmd->error---\ +--------+ ! !
100 * ! +--------------->! SENSE !<----------/ !
101 * STAT_FAIL----/ +--------+ !
102 * ! ! V
103 * ! V +--------+
104 * \--------------------------------\--------------------->! DONE !
105 * +--------+
106 */
107
108/*
41 * Definitions which have to be scattered once we understand the layout better. 109 * Definitions which have to be scattered once we understand the layout better.
42 */ 110 */
43 111
@@ -91,8 +159,6 @@ struct bulk_cs_wrap {
91 159
92#define US_BULK_CS_WRAP_LEN 13 160#define US_BULK_CS_WRAP_LEN 13
93#define US_BULK_CS_SIGN 0x53425355 /* spells out 'USBS' */ 161#define US_BULK_CS_SIGN 0x53425355 /* spells out 'USBS' */
94/* This is for Olympus Camedia digital cameras */
95#define US_BULK_CS_OLYMPUS_SIGN 0x55425355 /* spells out 'USBU' */
96#define US_BULK_STAT_OK 0 162#define US_BULK_STAT_OK 0
97#define US_BULK_STAT_FAIL 1 163#define US_BULK_STAT_FAIL 1
98#define US_BULK_STAT_PHASE 2 164#define US_BULK_STAT_PHASE 2
@@ -135,6 +201,7 @@ enum ub_scsi_cmd_state {
135 UB_CMDST_CLR2STS, /* Clearing before requesting status */ 201 UB_CMDST_CLR2STS, /* Clearing before requesting status */
136 UB_CMDST_STAT, /* Status phase */ 202 UB_CMDST_STAT, /* Status phase */
137 UB_CMDST_CLEAR, /* Clearing a stall (halt, actually) */ 203 UB_CMDST_CLEAR, /* Clearing a stall (halt, actually) */
204 UB_CMDST_CLRRS, /* Clearing before retrying status */
138 UB_CMDST_SENSE, /* Sending Request Sense */ 205 UB_CMDST_SENSE, /* Sending Request Sense */
139 UB_CMDST_DONE /* Final state */ 206 UB_CMDST_DONE /* Final state */
140}; 207};
@@ -146,6 +213,7 @@ static char *ub_scsi_cmd_stname[] = {
146 "c2s", 213 "c2s",
147 "sts", 214 "sts",
148 "clr", 215 "clr",
216 "crs",
149 "Sen", 217 "Sen",
150 "fin" 218 "fin"
151}; 219};
@@ -316,6 +384,7 @@ struct ub_dev {
316 struct urb work_urb; 384 struct urb work_urb;
317 struct timer_list work_timer; 385 struct timer_list work_timer;
318 int last_pipe; /* What might need clearing */ 386 int last_pipe; /* What might need clearing */
387 __le32 signature; /* Learned signature */
319 struct bulk_cb_wrap work_bcb; 388 struct bulk_cb_wrap work_bcb;
320 struct bulk_cs_wrap work_bcs; 389 struct bulk_cs_wrap work_bcs;
321 struct usb_ctrlrequest work_cr; 390 struct usb_ctrlrequest work_cr;
@@ -339,8 +408,9 @@ static void ub_scsi_action(unsigned long _dev);
339static void ub_scsi_dispatch(struct ub_dev *sc); 408static void ub_scsi_dispatch(struct ub_dev *sc);
340static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd); 409static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd);
341static void ub_state_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd, int rc); 410static void ub_state_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd, int rc);
342static void __ub_state_stat(struct ub_dev *sc, struct ub_scsi_cmd *cmd); 411static int __ub_state_stat(struct ub_dev *sc, struct ub_scsi_cmd *cmd);
343static void ub_state_stat(struct ub_dev *sc, struct ub_scsi_cmd *cmd); 412static void ub_state_stat(struct ub_dev *sc, struct ub_scsi_cmd *cmd);
413static void ub_state_stat_counted(struct ub_dev *sc, struct ub_scsi_cmd *cmd);
344static void ub_state_sense(struct ub_dev *sc, struct ub_scsi_cmd *cmd); 414static void ub_state_sense(struct ub_dev *sc, struct ub_scsi_cmd *cmd);
345static int ub_submit_clear_stall(struct ub_dev *sc, struct ub_scsi_cmd *cmd, 415static int ub_submit_clear_stall(struct ub_dev *sc, struct ub_scsi_cmd *cmd,
346 int stalled_pipe); 416 int stalled_pipe);
@@ -1085,6 +1155,28 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1085 1155
1086 ub_state_stat(sc, cmd); 1156 ub_state_stat(sc, cmd);
1087 1157
1158 } else if (cmd->state == UB_CMDST_CLRRS) {
1159 if (urb->status == -EPIPE) {
1160 /*
1161 * STALL while clearning STALL.
1162 * The control pipe clears itself - nothing to do.
1163 * XXX Might try to reset the device here and retry.
1164 */
1165 printk(KERN_NOTICE "%s: stall on control pipe\n",
1166 sc->name);
1167 goto Bad_End;
1168 }
1169
1170 /*
1171 * We ignore the result for the halt clear.
1172 */
1173
1174 /* reset the endpoint toggle */
1175 usb_settoggle(sc->dev, usb_pipeendpoint(sc->last_pipe),
1176 usb_pipeout(sc->last_pipe), 0);
1177
1178 ub_state_stat_counted(sc, cmd);
1179
1088 } else if (cmd->state == UB_CMDST_CMD) { 1180 } else if (cmd->state == UB_CMDST_CMD) {
1089 if (urb->status == -EPIPE) { 1181 if (urb->status == -EPIPE) {
1090 rc = ub_submit_clear_stall(sc, cmd, sc->last_pipe); 1182 rc = ub_submit_clear_stall(sc, cmd, sc->last_pipe);
@@ -1190,52 +1282,57 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1190 */ 1282 */
1191 goto Bad_End; 1283 goto Bad_End;
1192 } 1284 }
1193 cmd->state = UB_CMDST_CLEAR; 1285
1286 /*
1287 * Having a stall when getting CSW is an error, so
1288 * make sure uppper levels are not oblivious to it.
1289 */
1290 cmd->error = -EIO; /* A cheap trick... */
1291
1292 cmd->state = UB_CMDST_CLRRS;
1194 ub_cmdtr_state(sc, cmd); 1293 ub_cmdtr_state(sc, cmd);
1195 return; 1294 return;
1196 } 1295 }
1296 if (urb->status == -EOVERFLOW) {
1297 /*
1298 * XXX We are screwed here. Retrying is pointless,
1299 * because the pipelined data will not get in until
1300 * we read with a big enough buffer. We must reset XXX.
1301 */
1302 goto Bad_End;
1303 }
1197 if (urb->status != 0) 1304 if (urb->status != 0)
1198 goto Bad_End; 1305 goto Bad_End;
1199 1306
1200 if (urb->actual_length == 0) { 1307 if (urb->actual_length == 0) {
1201 /* 1308 ub_state_stat_counted(sc, cmd);
1202 * Some broken devices add unnecessary zero-length
1203 * packets to the end of their data transfers.
1204 * Such packets show up as 0-length CSWs. If we
1205 * encounter such a thing, try to read the CSW again.
1206 */
1207 if (++cmd->stat_count >= 4) {
1208 printk(KERN_NOTICE "%s: unable to get CSW\n",
1209 sc->name);
1210 goto Bad_End;
1211 }
1212 __ub_state_stat(sc, cmd);
1213 return; 1309 return;
1214 } 1310 }
1215 1311
1216 /* 1312 /*
1217 * Check the returned Bulk protocol status. 1313 * Check the returned Bulk protocol status.
1314 * The status block has to be validated first.
1218 */ 1315 */
1219 1316
1220 bcs = &sc->work_bcs; 1317 bcs = &sc->work_bcs;
1221 rc = le32_to_cpu(bcs->Residue); 1318
1222 if (rc != cmd->len - cmd->act_len) { 1319 if (sc->signature == cpu_to_le32(0)) {
1223 /* 1320 /*
1224 * It is all right to transfer less, the caller has 1321 * This is the first reply, so do not perform the check.
1225 * to check. But it's not all right if the device 1322 * Instead, remember the signature the device uses
1226 * counts disagree with our counts. 1323 * for future checks. But do not allow a nul.
1227 */ 1324 */
1228 /* P3 */ printk("%s: resid %d len %d act %d\n", 1325 sc->signature = bcs->Signature;
1229 sc->name, rc, cmd->len, cmd->act_len); 1326 if (sc->signature == cpu_to_le32(0)) {
1230 goto Bad_End; 1327 ub_state_stat_counted(sc, cmd);
1231 } 1328 return;
1232 1329 }
1233#if 0 1330 } else {
1234 if (bcs->Signature != cpu_to_le32(US_BULK_CS_SIGN) && 1331 if (bcs->Signature != sc->signature) {
1235 bcs->Signature != cpu_to_le32(US_BULK_CS_OLYMPUS_SIGN)) { 1332 ub_state_stat_counted(sc, cmd);
1236 /* Windows ignores signatures, so do we. */ 1333 return;
1334 }
1237 } 1335 }
1238#endif
1239 1336
1240 if (bcs->Tag != cmd->tag) { 1337 if (bcs->Tag != cmd->tag) {
1241 /* 1338 /*
@@ -1245,16 +1342,22 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1245 * commands and reply at commands we timed out before. 1342 * commands and reply at commands we timed out before.
1246 * Without flushing these replies we loop forever. 1343 * Without flushing these replies we loop forever.
1247 */ 1344 */
1248 if (++cmd->stat_count >= 4) { 1345 ub_state_stat_counted(sc, cmd);
1249 printk(KERN_NOTICE "%s: "
1250 "tag mismatch orig 0x%x reply 0x%x\n",
1251 sc->name, cmd->tag, bcs->Tag);
1252 goto Bad_End;
1253 }
1254 __ub_state_stat(sc, cmd);
1255 return; 1346 return;
1256 } 1347 }
1257 1348
1349 rc = le32_to_cpu(bcs->Residue);
1350 if (rc != cmd->len - cmd->act_len) {
1351 /*
1352 * It is all right to transfer less, the caller has
1353 * to check. But it's not all right if the device
1354 * counts disagree with our counts.
1355 */
1356 /* P3 */ printk("%s: resid %d len %d act %d\n",
1357 sc->name, rc, cmd->len, cmd->act_len);
1358 goto Bad_End;
1359 }
1360
1258 switch (bcs->Status) { 1361 switch (bcs->Status) {
1259 case US_BULK_STAT_OK: 1362 case US_BULK_STAT_OK:
1260 break; 1363 break;
@@ -1272,6 +1375,10 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1272 } 1375 }
1273 1376
1274 /* Not zeroing error to preserve a babble indicator */ 1377 /* Not zeroing error to preserve a babble indicator */
1378 if (cmd->error != 0) {
1379 ub_state_sense(sc, cmd);
1380 return;
1381 }
1275 cmd->state = UB_CMDST_DONE; 1382 cmd->state = UB_CMDST_DONE;
1276 ub_cmdtr_state(sc, cmd); 1383 ub_cmdtr_state(sc, cmd);
1277 ub_cmdq_pop(sc); 1384 ub_cmdq_pop(sc);
@@ -1310,7 +1417,7 @@ static void ub_state_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd, int rc)
1310 * Factorization helper for the command state machine: 1417 * Factorization helper for the command state machine:
1311 * Submit a CSW read. 1418 * Submit a CSW read.
1312 */ 1419 */
1313static void __ub_state_stat(struct ub_dev *sc, struct ub_scsi_cmd *cmd) 1420static int __ub_state_stat(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1314{ 1421{
1315 int rc; 1422 int rc;
1316 1423
@@ -1328,11 +1435,12 @@ static void __ub_state_stat(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1328 /* XXX Clear stalls */ 1435 /* XXX Clear stalls */
1329 ub_complete(&sc->work_done); 1436 ub_complete(&sc->work_done);
1330 ub_state_done(sc, cmd, rc); 1437 ub_state_done(sc, cmd, rc);
1331 return; 1438 return -1;
1332 } 1439 }
1333 1440
1334 sc->work_timer.expires = jiffies + UB_STAT_TIMEOUT; 1441 sc->work_timer.expires = jiffies + UB_STAT_TIMEOUT;
1335 add_timer(&sc->work_timer); 1442 add_timer(&sc->work_timer);
1443 return 0;
1336} 1444}
1337 1445
1338/* 1446/*
@@ -1341,7 +1449,9 @@ static void __ub_state_stat(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1341 */ 1449 */
1342static void ub_state_stat(struct ub_dev *sc, struct ub_scsi_cmd *cmd) 1450static void ub_state_stat(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1343{ 1451{
1344 __ub_state_stat(sc, cmd); 1452
1453 if (__ub_state_stat(sc, cmd) != 0)
1454 return;
1345 1455
1346 cmd->stat_count = 0; 1456 cmd->stat_count = 0;
1347 cmd->state = UB_CMDST_STAT; 1457 cmd->state = UB_CMDST_STAT;
@@ -1350,6 +1460,25 @@ static void ub_state_stat(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1350 1460
1351/* 1461/*
1352 * Factorization helper for the command state machine: 1462 * Factorization helper for the command state machine:
1463 * Submit a CSW read and go to STAT state with counter (along [C] path).
1464 */
1465static void ub_state_stat_counted(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1466{
1467
1468 if (++cmd->stat_count >= 4) {
1469 ub_state_sense(sc, cmd);
1470 return;
1471 }
1472
1473 if (__ub_state_stat(sc, cmd) != 0)
1474 return;
1475
1476 cmd->state = UB_CMDST_STAT;
1477 ub_cmdtr_state(sc, cmd);
1478}
1479
1480/*
1481 * Factorization helper for the command state machine:
1353 * Submit a REQUEST SENSE and go to SENSE state. 1482 * Submit a REQUEST SENSE and go to SENSE state.
1354 */ 1483 */
1355static void ub_state_sense(struct ub_dev *sc, struct ub_scsi_cmd *cmd) 1484static void ub_state_sense(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
diff --git a/drivers/bluetooth/bpa10x.c b/drivers/bluetooth/bpa10x.c
index 2771c861f185..f696da6f417b 100644
--- a/drivers/bluetooth/bpa10x.c
+++ b/drivers/bluetooth/bpa10x.c
@@ -367,11 +367,8 @@ static inline void bpa10x_free_urb(struct urb *urb)
367 if (!urb) 367 if (!urb)
368 return; 368 return;
369 369
370 if (urb->setup_packet) 370 kfree(urb->setup_packet);
371 kfree(urb->setup_packet); 371 kfree(urb->transfer_buffer);
372
373 if (urb->transfer_buffer)
374 kfree(urb->transfer_buffer);
375 372
376 usb_free_urb(urb); 373 usb_free_urb(urb);
377} 374}
diff --git a/drivers/bluetooth/hci_bcsp.c b/drivers/bluetooth/hci_bcsp.c
index c0ed213fc857..858fddb046de 100644
--- a/drivers/bluetooth/hci_bcsp.c
+++ b/drivers/bluetooth/hci_bcsp.c
@@ -58,8 +58,6 @@
58#ifndef CONFIG_BT_HCIUART_DEBUG 58#ifndef CONFIG_BT_HCIUART_DEBUG
59#undef BT_DBG 59#undef BT_DBG
60#define BT_DBG( A... ) 60#define BT_DBG( A... )
61#undef BT_DMP
62#define BT_DMP( A... )
63#endif 61#endif
64 62
65static int hciextn = 1; 63static int hciextn = 1;
diff --git a/drivers/bluetooth/hci_h4.c b/drivers/bluetooth/hci_h4.c
index ade94a57bb11..533323b60e63 100644
--- a/drivers/bluetooth/hci_h4.c
+++ b/drivers/bluetooth/hci_h4.c
@@ -57,8 +57,6 @@
57#ifndef CONFIG_BT_HCIUART_DEBUG 57#ifndef CONFIG_BT_HCIUART_DEBUG
58#undef BT_DBG 58#undef BT_DBG
59#define BT_DBG( A... ) 59#define BT_DBG( A... )
60#undef BT_DMP
61#define BT_DMP( A... )
62#endif 60#endif
63 61
64/* Initialize protocol */ 62/* Initialize protocol */
@@ -125,7 +123,6 @@ static inline int h4_check_data_len(struct h4_struct *h4, int len)
125 123
126 BT_DBG("len %d room %d", len, room); 124 BT_DBG("len %d room %d", len, room);
127 if (!len) { 125 if (!len) {
128 BT_DMP(h4->rx_skb->data, h4->rx_skb->len);
129 hci_recv_frame(h4->rx_skb); 126 hci_recv_frame(h4->rx_skb);
130 } else if (len > room) { 127 } else if (len > room) {
131 BT_ERR("Data length is too large"); 128 BT_ERR("Data length is too large");
@@ -169,8 +166,6 @@ static int h4_recv(struct hci_uart *hu, void *data, int count)
169 case H4_W4_DATA: 166 case H4_W4_DATA:
170 BT_DBG("Complete data"); 167 BT_DBG("Complete data");
171 168
172 BT_DMP(h4->rx_skb->data, h4->rx_skb->len);
173
174 hci_recv_frame(h4->rx_skb); 169 hci_recv_frame(h4->rx_skb);
175 170
176 h4->rx_state = H4_W4_PACKET_TYPE; 171 h4->rx_state = H4_W4_PACKET_TYPE;
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index f766bc22c6bb..90be2eae52e0 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -57,8 +57,6 @@
57#ifndef CONFIG_BT_HCIUART_DEBUG 57#ifndef CONFIG_BT_HCIUART_DEBUG
58#undef BT_DBG 58#undef BT_DBG
59#define BT_DBG( A... ) 59#define BT_DBG( A... )
60#undef BT_DMP
61#define BT_DMP( A... )
62#endif 60#endif
63 61
64static int reset = 0; 62static int reset = 0;
diff --git a/drivers/bluetooth/hci_usb.c b/drivers/bluetooth/hci_usb.c
index b120ecf7b8c9..657719b8254f 100644
--- a/drivers/bluetooth/hci_usb.c
+++ b/drivers/bluetooth/hci_usb.c
@@ -57,8 +57,6 @@
57#ifndef CONFIG_BT_HCIUSB_DEBUG 57#ifndef CONFIG_BT_HCIUSB_DEBUG
58#undef BT_DBG 58#undef BT_DBG
59#define BT_DBG(D...) 59#define BT_DBG(D...)
60#undef BT_DMP
61#define BT_DMP(D...)
62#endif 60#endif
63 61
64#ifndef CONFIG_BT_HCIUSB_ZERO_PACKET 62#ifndef CONFIG_BT_HCIUSB_ZERO_PACKET
@@ -110,6 +108,9 @@ static struct usb_device_id blacklist_ids[] = {
110 /* Microsoft Wireless Transceiver for Bluetooth 2.0 */ 108 /* Microsoft Wireless Transceiver for Bluetooth 2.0 */
111 { USB_DEVICE(0x045e, 0x009c), .driver_info = HCI_RESET }, 109 { USB_DEVICE(0x045e, 0x009c), .driver_info = HCI_RESET },
112 110
111 /* Kensington Bluetooth USB adapter */
112 { USB_DEVICE(0x047d, 0x105d), .driver_info = HCI_RESET },
113
113 /* ISSC Bluetooth Adapter v3.1 */ 114 /* ISSC Bluetooth Adapter v3.1 */
114 { USB_DEVICE(0x1131, 0x1001), .driver_info = HCI_RESET }, 115 { USB_DEVICE(0x1131, 0x1001), .driver_info = HCI_RESET },
115 116
@@ -387,10 +388,8 @@ static void hci_usb_unlink_urbs(struct hci_usb *husb)
387 urb = &_urb->urb; 388 urb = &_urb->urb;
388 BT_DBG("%s freeing _urb %p type %d urb %p", 389 BT_DBG("%s freeing _urb %p type %d urb %p",
389 husb->hdev->name, _urb, _urb->type, urb); 390 husb->hdev->name, _urb, _urb->type, urb);
390 if (urb->setup_packet) 391 kfree(urb->setup_packet);
391 kfree(urb->setup_packet); 392 kfree(urb->transfer_buffer);
392 if (urb->transfer_buffer)
393 kfree(urb->transfer_buffer);
394 _urb_free(_urb); 393 _urb_free(_urb);
395 } 394 }
396 395
diff --git a/drivers/cdrom/isp16.c b/drivers/cdrom/isp16.c
index 8e68d858ce64..db0fd9a240e3 100644
--- a/drivers/cdrom/isp16.c
+++ b/drivers/cdrom/isp16.c
@@ -18,7 +18,7 @@
18 * 18 *
19 * 19 June 2004 -- check_region() converted to request_region() 19 * 19 June 2004 -- check_region() converted to request_region()
20 * and return statement cleanups. 20 * and return statement cleanups.
21 * Jesper Juhl <juhl-lkml@dif.dk> 21 * - Jesper Juhl
22 * 22 *
23 * Detect cdrom interface on ISP16 sound card. 23 * Detect cdrom interface on ISP16 sound card.
24 * Configure cdrom interface. 24 * Configure cdrom interface.
diff --git a/drivers/cdrom/mcdx.c b/drivers/cdrom/mcdx.c
index 07bbd24e3c18..b89420e6d704 100644
--- a/drivers/cdrom/mcdx.c
+++ b/drivers/cdrom/mcdx.c
@@ -51,7 +51,7 @@
51 */ 51 */
52 52
53 53
54#if RCS 54#ifdef RCS
55static const char *mcdx_c_version 55static const char *mcdx_c_version
56 = "$Id: mcdx.c,v 1.21 1997/01/26 07:12:59 davem Exp $"; 56 = "$Id: mcdx.c,v 1.21 1997/01/26 07:12:59 davem Exp $";
57#endif 57#endif
@@ -706,7 +706,7 @@ static int mcdx_open(struct cdrom_device_info *cdi, int purpose)
706 xtrace(OPENCLOSE, "open() init irq generation\n"); 706 xtrace(OPENCLOSE, "open() init irq generation\n");
707 if (-1 == mcdx_config(stuffp, 1)) 707 if (-1 == mcdx_config(stuffp, 1))
708 return -EIO; 708 return -EIO;
709#if FALLBACK 709#ifdef FALLBACK
710 /* Set the read speed */ 710 /* Set the read speed */
711 xwarn("AAA %x AAA\n", stuffp->readcmd); 711 xwarn("AAA %x AAA\n", stuffp->readcmd);
712 if (stuffp->readerrs) 712 if (stuffp->readerrs)
@@ -1216,7 +1216,7 @@ static int __init mcdx_init_drive(int drive)
1216 } 1216 }
1217 1217
1218 1218
1219#if WE_KNOW_WHY 1219#ifdef WE_KNOW_WHY
1220 /* irq 11 -> channel register */ 1220 /* irq 11 -> channel register */
1221 outb(0x50, stuffp->wreg_chn); 1221 outb(0x50, stuffp->wreg_chn);
1222#endif 1222#endif
@@ -1294,7 +1294,7 @@ static int mcdx_transfer(struct s_drive_stuff *stuffp,
1294 1294
1295 ans = mcdx_xfer(stuffp, p, sector, nr_sectors); 1295 ans = mcdx_xfer(stuffp, p, sector, nr_sectors);
1296 return ans; 1296 return ans;
1297#if FALLBACK 1297#ifdef FALLBACK
1298 if (-1 == ans) 1298 if (-1 == ans)
1299 stuffp->readerrs++; 1299 stuffp->readerrs++;
1300 else 1300 else
diff --git a/drivers/cdrom/optcd.c b/drivers/cdrom/optcd.c
index 7e69c54568bf..351a01dd503a 100644
--- a/drivers/cdrom/optcd.c
+++ b/drivers/cdrom/optcd.c
@@ -245,7 +245,7 @@ module_param(optcd_port, short, 0);
245 245
246 246
247/* Busy wait until FLAG goes low. Return 0 on timeout. */ 247/* Busy wait until FLAG goes low. Return 0 on timeout. */
248inline static int flag_low(int flag, unsigned long timeout) 248static inline int flag_low(int flag, unsigned long timeout)
249{ 249{
250 int flag_high; 250 int flag_high;
251 unsigned long count = 0; 251 unsigned long count = 0;
@@ -381,7 +381,7 @@ static int send_seek_params(struct cdrom_msf *params)
381 381
382/* Wait for command execution status. Choice between busy waiting 382/* Wait for command execution status. Choice between busy waiting
383 and sleeping. Return value <0 indicates timeout. */ 383 and sleeping. Return value <0 indicates timeout. */
384inline static int get_exec_status(int busy_waiting) 384static inline int get_exec_status(int busy_waiting)
385{ 385{
386 unsigned char exec_status; 386 unsigned char exec_status;
387 387
@@ -398,7 +398,7 @@ inline static int get_exec_status(int busy_waiting)
398 398
399/* Wait busy for extra byte of data that a command returns. 399/* Wait busy for extra byte of data that a command returns.
400 Return value <0 indicates timeout. */ 400 Return value <0 indicates timeout. */
401inline static int get_data(int short_timeout) 401static inline int get_data(int short_timeout)
402{ 402{
403 unsigned char data; 403 unsigned char data;
404 404
@@ -441,14 +441,14 @@ static int reset_drive(void)
441/* Facilities for asynchronous operation */ 441/* Facilities for asynchronous operation */
442 442
443/* Read status/data availability flags FL_STEN and FL_DTEN */ 443/* Read status/data availability flags FL_STEN and FL_DTEN */
444inline static int stdt_flags(void) 444static inline int stdt_flags(void)
445{ 445{
446 return inb(STATUS_PORT) & FL_STDT; 446 return inb(STATUS_PORT) & FL_STDT;
447} 447}
448 448
449 449
450/* Fetch status that has previously been waited for. <0 means not available */ 450/* Fetch status that has previously been waited for. <0 means not available */
451inline static int fetch_status(void) 451static inline int fetch_status(void)
452{ 452{
453 unsigned char status; 453 unsigned char status;
454 454
@@ -462,7 +462,7 @@ inline static int fetch_status(void)
462 462
463 463
464/* Fetch data that has previously been waited for. */ 464/* Fetch data that has previously been waited for. */
465inline static void fetch_data(char *buf, int n) 465static inline void fetch_data(char *buf, int n)
466{ 466{
467 insb(DATA_PORT, buf, n); 467 insb(DATA_PORT, buf, n);
468 DEBUG((DEBUG_DRIVE_IF, "fetched 0x%x bytes", n)); 468 DEBUG((DEBUG_DRIVE_IF, "fetched 0x%x bytes", n));
@@ -470,7 +470,7 @@ inline static void fetch_data(char *buf, int n)
470 470
471 471
472/* Flush status and data fifos */ 472/* Flush status and data fifos */
473inline static void flush_data(void) 473static inline void flush_data(void)
474{ 474{
475 while ((inb(STATUS_PORT) & FL_STDT) != FL_STDT) 475 while ((inb(STATUS_PORT) & FL_STDT) != FL_STDT)
476 inb(DATA_PORT); 476 inb(DATA_PORT);
@@ -482,7 +482,7 @@ inline static void flush_data(void)
482 482
483/* Send a simple command and wait for response. Command codes < COMFETCH 483/* Send a simple command and wait for response. Command codes < COMFETCH
484 are quick response commands */ 484 are quick response commands */
485inline static int exec_cmd(int cmd) 485static inline int exec_cmd(int cmd)
486{ 486{
487 int ack = send_cmd(cmd); 487 int ack = send_cmd(cmd);
488 if (ack < 0) 488 if (ack < 0)
@@ -493,7 +493,7 @@ inline static int exec_cmd(int cmd)
493 493
494/* Send a command with parameters. Don't wait for the response, 494/* Send a command with parameters. Don't wait for the response,
495 * which consists of data blocks read from the CD. */ 495 * which consists of data blocks read from the CD. */
496inline static int exec_read_cmd(int cmd, struct cdrom_msf *params) 496static inline int exec_read_cmd(int cmd, struct cdrom_msf *params)
497{ 497{
498 int ack = send_cmd(cmd); 498 int ack = send_cmd(cmd);
499 if (ack < 0) 499 if (ack < 0)
@@ -503,7 +503,7 @@ inline static int exec_read_cmd(int cmd, struct cdrom_msf *params)
503 503
504 504
505/* Send a seek command with parameters and wait for response */ 505/* Send a seek command with parameters and wait for response */
506inline static int exec_seek_cmd(int cmd, struct cdrom_msf *params) 506static inline int exec_seek_cmd(int cmd, struct cdrom_msf *params)
507{ 507{
508 int ack = send_cmd(cmd); 508 int ack = send_cmd(cmd);
509 if (ack < 0) 509 if (ack < 0)
@@ -516,7 +516,7 @@ inline static int exec_seek_cmd(int cmd, struct cdrom_msf *params)
516 516
517 517
518/* Send a command with parameters and wait for response */ 518/* Send a command with parameters and wait for response */
519inline static int exec_long_cmd(int cmd, struct cdrom_msf *params) 519static inline int exec_long_cmd(int cmd, struct cdrom_msf *params)
520{ 520{
521 int ack = exec_read_cmd(cmd, params); 521 int ack = exec_read_cmd(cmd, params);
522 if (ack < 0) 522 if (ack < 0)
@@ -528,7 +528,7 @@ inline static int exec_long_cmd(int cmd, struct cdrom_msf *params)
528 528
529 529
530/* Binary to BCD (2 digits) */ 530/* Binary to BCD (2 digits) */
531inline static void single_bin2bcd(u_char *p) 531static inline void single_bin2bcd(u_char *p)
532{ 532{
533 DEBUG((DEBUG_CONV, "bin2bcd %02d", *p)); 533 DEBUG((DEBUG_CONV, "bin2bcd %02d", *p));
534 *p = (*p % 10) | ((*p / 10) << 4); 534 *p = (*p % 10) | ((*p / 10) << 4);
@@ -565,7 +565,7 @@ static void lba2msf(int lba, struct cdrom_msf *msf)
565 565
566 566
567/* Two BCD digits to binary */ 567/* Two BCD digits to binary */
568inline static u_char bcd2bin(u_char bcd) 568static inline u_char bcd2bin(u_char bcd)
569{ 569{
570 DEBUG((DEBUG_CONV, "bcd2bin %x%02x", bcd)); 570 DEBUG((DEBUG_CONV, "bcd2bin %x%02x", bcd));
571 return (bcd >> 4) * 10 + (bcd & 0x0f); 571 return (bcd >> 4) * 10 + (bcd & 0x0f);
@@ -988,7 +988,7 @@ static char buf[CD_FRAMESIZE * N_BUFS];
988static volatile int buf_bn[N_BUFS], next_bn; 988static volatile int buf_bn[N_BUFS], next_bn;
989static volatile int buf_in = 0, buf_out = NOBUF; 989static volatile int buf_in = 0, buf_out = NOBUF;
990 990
991inline static void opt_invalidate_buffers(void) 991static inline void opt_invalidate_buffers(void)
992{ 992{
993 int i; 993 int i;
994 994
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 43d0cb19ef6a..4f27e5519296 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -735,7 +735,7 @@ config SGI_IP27_RTC
735 735
736config GEN_RTC 736config GEN_RTC
737 tristate "Generic /dev/rtc emulation" 737 tristate "Generic /dev/rtc emulation"
738 depends on RTC!=y && !IA64 && !ARM 738 depends on RTC!=y && !IA64 && !ARM && !PPC64
739 ---help--- 739 ---help---
740 If you say Y here and create a character special file /dev/rtc with 740 If you say Y here and create a character special file /dev/rtc with
741 major number 10 and minor number 135 using mknod ("man mknod"), you 741 major number 10 and minor number 135 using mknod ("man mknod"), you
diff --git a/drivers/char/agp/agp.h b/drivers/char/agp/agp.h
index c1fe013c64f3..b4af87c6f9c8 100644
--- a/drivers/char/agp/agp.h
+++ b/drivers/char/agp/agp.h
@@ -143,6 +143,7 @@ struct agp_bridge_data {
143 char major_version; 143 char major_version;
144 char minor_version; 144 char minor_version;
145 struct list_head list; 145 struct list_head list;
146 u32 apbase_config;
146}; 147};
147 148
148#define KB(x) ((x) * 1024) 149#define KB(x) ((x) * 1024)
diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
index 51266d6b4d78..1f7d415f432c 100644
--- a/drivers/char/agp/intel-agp.c
+++ b/drivers/char/agp/intel-agp.c
@@ -1047,9 +1047,15 @@ static int intel_845_configure(void)
1047 /* aperture size */ 1047 /* aperture size */
1048 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value); 1048 pci_write_config_byte(agp_bridge->dev, INTEL_APSIZE, current_size->size_value);
1049 1049
1050 /* address to map to */ 1050 if (agp_bridge->apbase_config != 0) {
1051 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp); 1051 pci_write_config_dword(agp_bridge->dev, AGP_APBASE,
1052 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK); 1052 agp_bridge->apbase_config);
1053 } else {
1054 /* address to map to */
1055 pci_read_config_dword(agp_bridge->dev, AGP_APBASE, &temp);
1056 agp_bridge->gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
1057 agp_bridge->apbase_config = temp;
1058 }
1053 1059
1054 /* attbase - aperture base */ 1060 /* attbase - aperture base */
1055 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr); 1061 pci_write_config_dword(agp_bridge->dev, INTEL_ATTBASE, agp_bridge->gatt_bus_addr);
diff --git a/drivers/char/drm/via_dma.c b/drivers/char/drm/via_dma.c
index 82f839451622..4f60f7f4193d 100644
--- a/drivers/char/drm/via_dma.c
+++ b/drivers/char/drm/via_dma.c
@@ -231,7 +231,7 @@ int via_dma_init(DRM_IOCTL_ARGS)
231 drm_via_dma_init_t init; 231 drm_via_dma_init_t init;
232 int retcode = 0; 232 int retcode = 0;
233 233
234 DRM_COPY_FROM_USER_IOCTL(init, (drm_via_dma_init_t *) data, 234 DRM_COPY_FROM_USER_IOCTL(init, (drm_via_dma_init_t __user *) data,
235 sizeof(init)); 235 sizeof(init));
236 236
237 switch (init.func) { 237 switch (init.func) {
@@ -343,7 +343,7 @@ int via_cmdbuffer(DRM_IOCTL_ARGS)
343 343
344 LOCK_TEST_WITH_RETURN( dev, filp ); 344 LOCK_TEST_WITH_RETURN( dev, filp );
345 345
346 DRM_COPY_FROM_USER_IOCTL(cmdbuf, (drm_via_cmdbuffer_t *) data, 346 DRM_COPY_FROM_USER_IOCTL(cmdbuf, (drm_via_cmdbuffer_t __user *) data,
347 sizeof(cmdbuf)); 347 sizeof(cmdbuf));
348 348
349 DRM_DEBUG("via cmdbuffer, buf %p size %lu\n", cmdbuf.buf, cmdbuf.size); 349 DRM_DEBUG("via cmdbuffer, buf %p size %lu\n", cmdbuf.buf, cmdbuf.size);
@@ -386,7 +386,7 @@ int via_pci_cmdbuffer(DRM_IOCTL_ARGS)
386 386
387 LOCK_TEST_WITH_RETURN( dev, filp ); 387 LOCK_TEST_WITH_RETURN( dev, filp );
388 388
389 DRM_COPY_FROM_USER_IOCTL(cmdbuf, (drm_via_cmdbuffer_t *) data, 389 DRM_COPY_FROM_USER_IOCTL(cmdbuf, (drm_via_cmdbuffer_t __user *) data,
390 sizeof(cmdbuf)); 390 sizeof(cmdbuf));
391 391
392 DRM_DEBUG("via_pci_cmdbuffer, buf %p size %lu\n", cmdbuf.buf, 392 DRM_DEBUG("via_pci_cmdbuffer, buf %p size %lu\n", cmdbuf.buf,
@@ -701,7 +701,7 @@ via_cmdbuf_size(DRM_IOCTL_ARGS)
701 return DRM_ERR(EFAULT); 701 return DRM_ERR(EFAULT);
702 } 702 }
703 703
704 DRM_COPY_FROM_USER_IOCTL(d_siz, (drm_via_cmdbuf_size_t *) data, 704 DRM_COPY_FROM_USER_IOCTL(d_siz, (drm_via_cmdbuf_size_t __user *) data,
705 sizeof(d_siz)); 705 sizeof(d_siz));
706 706
707 707
@@ -735,7 +735,7 @@ via_cmdbuf_size(DRM_IOCTL_ARGS)
735 } 735 }
736 d_siz.size = tmp_size; 736 d_siz.size = tmp_size;
737 737
738 DRM_COPY_TO_USER_IOCTL((drm_via_cmdbuf_size_t *) data, d_siz, 738 DRM_COPY_TO_USER_IOCTL((drm_via_cmdbuf_size_t __user *) data, d_siz,
739 sizeof(d_siz)); 739 sizeof(d_siz));
740 return ret; 740 return ret;
741} 741}
diff --git a/drivers/char/drm/via_drm.h b/drivers/char/drm/via_drm.h
index 4588c9bd1816..be346bb0a26a 100644
--- a/drivers/char/drm/via_drm.h
+++ b/drivers/char/drm/via_drm.h
@@ -158,7 +158,7 @@ typedef struct _drm_via_dma_init {
158} drm_via_dma_init_t; 158} drm_via_dma_init_t;
159 159
160typedef struct _drm_via_cmdbuffer { 160typedef struct _drm_via_cmdbuffer {
161 char *buf; 161 char __user *buf;
162 unsigned long size; 162 unsigned long size;
163} drm_via_cmdbuffer_t; 163} drm_via_cmdbuffer_t;
164 164
diff --git a/drivers/char/drm/via_ds.c b/drivers/char/drm/via_ds.c
index daf3df75a20e..5c71e089246c 100644
--- a/drivers/char/drm/via_ds.c
+++ b/drivers/char/drm/via_ds.c
@@ -133,7 +133,7 @@ memHeap_t *via_mmInit(int ofs, int size)
133 PMemBlock blocks; 133 PMemBlock blocks;
134 134
135 if (size <= 0) 135 if (size <= 0)
136 return 0; 136 return NULL;
137 137
138 blocks = (TMemBlock *) drm_calloc(1, sizeof(TMemBlock), DRM_MEM_DRIVER); 138 blocks = (TMemBlock *) drm_calloc(1, sizeof(TMemBlock), DRM_MEM_DRIVER);
139 139
@@ -143,7 +143,7 @@ memHeap_t *via_mmInit(int ofs, int size)
143 blocks->free = 1; 143 blocks->free = 1;
144 return (memHeap_t *) blocks; 144 return (memHeap_t *) blocks;
145 } else 145 } else
146 return 0; 146 return NULL;
147} 147}
148 148
149static TMemBlock *SliceBlock(TMemBlock * p, 149static TMemBlock *SliceBlock(TMemBlock * p,
diff --git a/drivers/char/drm/via_ds.h b/drivers/char/drm/via_ds.h
index be9c7f9f1aee..d2bb9f37ca38 100644
--- a/drivers/char/drm/via_ds.h
+++ b/drivers/char/drm/via_ds.h
@@ -61,8 +61,8 @@ struct mem_block_t {
61 struct mem_block_t *heap; 61 struct mem_block_t *heap;
62 int ofs, size; 62 int ofs, size;
63 int align; 63 int align;
64 int free:1; 64 unsigned int free:1;
65 int reserved:1; 65 unsigned int reserved:1;
66}; 66};
67typedef struct mem_block_t TMemBlock; 67typedef struct mem_block_t TMemBlock;
68typedef struct mem_block_t *PMemBlock; 68typedef struct mem_block_t *PMemBlock;
diff --git a/drivers/char/drm/via_map.c b/drivers/char/drm/via_map.c
index 0be829b6ec65..bb171139e737 100644
--- a/drivers/char/drm/via_map.c
+++ b/drivers/char/drm/via_map.c
@@ -95,7 +95,8 @@ int via_map_init(DRM_IOCTL_ARGS)
95 95
96 DRM_DEBUG("%s\n", __FUNCTION__); 96 DRM_DEBUG("%s\n", __FUNCTION__);
97 97
98 DRM_COPY_FROM_USER_IOCTL(init, (drm_via_init_t *) data, sizeof(init)); 98 DRM_COPY_FROM_USER_IOCTL(init, (drm_via_init_t __user *) data,
99 sizeof(init));
99 100
100 switch (init.func) { 101 switch (init.func) {
101 case VIA_INIT_MAP: 102 case VIA_INIT_MAP:
diff --git a/drivers/char/drm/via_mm.c b/drivers/char/drm/via_mm.c
index c22712f44d42..13921f3c0ec2 100644
--- a/drivers/char/drm/via_mm.c
+++ b/drivers/char/drm/via_mm.c
@@ -76,7 +76,8 @@ int via_agp_init(DRM_IOCTL_ARGS)
76{ 76{
77 drm_via_agp_t agp; 77 drm_via_agp_t agp;
78 78
79 DRM_COPY_FROM_USER_IOCTL(agp, (drm_via_agp_t *) data, sizeof(agp)); 79 DRM_COPY_FROM_USER_IOCTL(agp, (drm_via_agp_t __user *) data,
80 sizeof(agp));
80 81
81 AgpHeap = via_mmInit(agp.offset, agp.size); 82 AgpHeap = via_mmInit(agp.offset, agp.size);
82 83
@@ -92,7 +93,7 @@ int via_fb_init(DRM_IOCTL_ARGS)
92{ 93{
93 drm_via_fb_t fb; 94 drm_via_fb_t fb;
94 95
95 DRM_COPY_FROM_USER_IOCTL(fb, (drm_via_fb_t *) data, sizeof(fb)); 96 DRM_COPY_FROM_USER_IOCTL(fb, (drm_via_fb_t __user *) data, sizeof(fb));
96 97
97 FBHeap = via_mmInit(fb.offset, fb.size); 98 FBHeap = via_mmInit(fb.offset, fb.size);
98 99
@@ -193,19 +194,20 @@ int via_mem_alloc(DRM_IOCTL_ARGS)
193{ 194{
194 drm_via_mem_t mem; 195 drm_via_mem_t mem;
195 196
196 DRM_COPY_FROM_USER_IOCTL(mem, (drm_via_mem_t *) data, sizeof(mem)); 197 DRM_COPY_FROM_USER_IOCTL(mem, (drm_via_mem_t __user *) data,
198 sizeof(mem));
197 199
198 switch (mem.type) { 200 switch (mem.type) {
199 case VIDEO: 201 case VIDEO:
200 if (via_fb_alloc(&mem) < 0) 202 if (via_fb_alloc(&mem) < 0)
201 return -EFAULT; 203 return -EFAULT;
202 DRM_COPY_TO_USER_IOCTL((drm_via_mem_t *) data, mem, 204 DRM_COPY_TO_USER_IOCTL((drm_via_mem_t __user *) data, mem,
203 sizeof(mem)); 205 sizeof(mem));
204 return 0; 206 return 0;
205 case AGP: 207 case AGP:
206 if (via_agp_alloc(&mem) < 0) 208 if (via_agp_alloc(&mem) < 0)
207 return -EFAULT; 209 return -EFAULT;
208 DRM_COPY_TO_USER_IOCTL((drm_via_mem_t *) data, mem, 210 DRM_COPY_TO_USER_IOCTL((drm_via_mem_t __user *) data, mem,
209 sizeof(mem)); 211 sizeof(mem));
210 return 0; 212 return 0;
211 } 213 }
@@ -289,7 +291,8 @@ int via_mem_free(DRM_IOCTL_ARGS)
289{ 291{
290 drm_via_mem_t mem; 292 drm_via_mem_t mem;
291 293
292 DRM_COPY_FROM_USER_IOCTL(mem, (drm_via_mem_t *) data, sizeof(mem)); 294 DRM_COPY_FROM_USER_IOCTL(mem, (drm_via_mem_t __user *) data,
295 sizeof(mem));
293 296
294 switch (mem.type) { 297 switch (mem.type) {
295 298
diff --git a/drivers/char/drm/via_video.c b/drivers/char/drm/via_video.c
index 37a61c67b292..1e2d444587bf 100644
--- a/drivers/char/drm/via_video.c
+++ b/drivers/char/drm/via_video.c
@@ -76,7 +76,8 @@ via_decoder_futex(DRM_IOCTL_ARGS)
76 76
77 DRM_DEBUG("%s\n", __FUNCTION__); 77 DRM_DEBUG("%s\n", __FUNCTION__);
78 78
79 DRM_COPY_FROM_USER_IOCTL(fx, (drm_via_futex_t *) data, sizeof(fx)); 79 DRM_COPY_FROM_USER_IOCTL(fx, (drm_via_futex_t __user *) data,
80 sizeof(fx));
80 81
81 if (fx.lock > VIA_NR_XVMC_LOCKS) 82 if (fx.lock > VIA_NR_XVMC_LOCKS)
82 return -EFAULT; 83 return -EFAULT;
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index 298574e16061..a44b97304e95 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -1726,7 +1726,7 @@ static int dmi_table(u32 base, int len, int num)
1726 return status; 1726 return status;
1727} 1727}
1728 1728
1729inline static int dmi_checksum(u8 *buf) 1729static inline int dmi_checksum(u8 *buf)
1730{ 1730{
1731 u8 sum=0; 1731 u8 sum=0;
1732 int a; 1732 int a;
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index fcd1c02a32cb..d35a953961cb 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -131,11 +131,7 @@
131#define WDIOC_GET_PRETIMEOUT _IOW(WATCHDOG_IOCTL_BASE, 22, int) 131#define WDIOC_GET_PRETIMEOUT _IOW(WATCHDOG_IOCTL_BASE, 22, int)
132#endif 132#endif
133 133
134#ifdef CONFIG_WATCHDOG_NOWAYOUT 134static int nowayout = WATCHDOG_NOWAYOUT;
135static int nowayout = 1;
136#else
137static int nowayout;
138#endif
139 135
140static ipmi_user_t watchdog_user = NULL; 136static ipmi_user_t watchdog_user = NULL;
141 137
diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
index 7b19e02f112f..523fd3c8bbaa 100644
--- a/drivers/char/keyboard.c
+++ b/drivers/char/keyboard.c
@@ -198,10 +198,10 @@ int setkeycode(unsigned int scancode, unsigned int keycode)
198 198
199 if (scancode >= dev->keycodemax) 199 if (scancode >= dev->keycodemax)
200 return -EINVAL; 200 return -EINVAL;
201 if (keycode > KEY_MAX)
202 return -EINVAL;
203 if (keycode < 0 || keycode > KEY_MAX) 201 if (keycode < 0 || keycode > KEY_MAX)
204 return -EINVAL; 202 return -EINVAL;
203 if (keycode >> (dev->keycodesize * 8))
204 return -EINVAL;
205 205
206 oldkey = SET_INPUT_KEYCODE(dev, scancode, keycode); 206 oldkey = SET_INPUT_KEYCODE(dev, scancode, keycode);
207 207
diff --git a/drivers/char/rio/rioboot.c b/drivers/char/rio/rioboot.c
index a8be11dfcba3..34cbb13aad4b 100644
--- a/drivers/char/rio/rioboot.c
+++ b/drivers/char/rio/rioboot.c
@@ -902,7 +902,7 @@ static int RIOBootComplete( struct rio_info *p, struct Host *HostP, uint Rup, st
902 (HostP->Mapping[entry].RtaUniqueNum==RtaUniq)) 902 (HostP->Mapping[entry].RtaUniqueNum==RtaUniq))
903 { 903 {
904 HostP->Mapping[entry].Flags |= RTA_BOOTED|RTA_NEWBOOT; 904 HostP->Mapping[entry].Flags |= RTA_BOOTED|RTA_NEWBOOT;
905#if NEED_TO_FIX 905#ifdef NEED_TO_FIX
906 RIO_SV_BROADCAST(HostP->svFlags[entry]); 906 RIO_SV_BROADCAST(HostP->svFlags[entry]);
907#endif 907#endif
908 if ( (sysport=HostP->Mapping[entry].SysPort) != NO_PORT ) 908 if ( (sysport=HostP->Mapping[entry].SysPort) != NO_PORT )
@@ -918,7 +918,7 @@ static int RIOBootComplete( struct rio_info *p, struct Host *HostP, uint Rup, st
918 { 918 {
919 entry2 = HostP->Mapping[entry].ID2 - 1; 919 entry2 = HostP->Mapping[entry].ID2 - 1;
920 HostP->Mapping[entry2].Flags |= RTA_BOOTED|RTA_NEWBOOT; 920 HostP->Mapping[entry2].Flags |= RTA_BOOTED|RTA_NEWBOOT;
921#if NEED_TO_FIX 921#ifdef NEED_TO_FIX
922 RIO_SV_BROADCAST(HostP->svFlags[entry2]); 922 RIO_SV_BROADCAST(HostP->svFlags[entry2]);
923#endif 923#endif
924 sysport = HostP->Mapping[entry2].SysPort; 924 sysport = HostP->Mapping[entry2].SysPort;
@@ -1143,7 +1143,7 @@ static int RIOBootComplete( struct rio_info *p, struct Host *HostP, uint Rup, st
1143 CCOPY( MapP->Name, HostP->Mapping[entry].Name, MAX_NAME_LEN ); 1143 CCOPY( MapP->Name, HostP->Mapping[entry].Name, MAX_NAME_LEN );
1144 HostP->Mapping[entry].Flags = 1144 HostP->Mapping[entry].Flags =
1145 SLOT_IN_USE | RTA_BOOTED | RTA_NEWBOOT; 1145 SLOT_IN_USE | RTA_BOOTED | RTA_NEWBOOT;
1146#if NEED_TO_FIX 1146#ifdef NEED_TO_FIX
1147 RIO_SV_BROADCAST(HostP->svFlags[entry]); 1147 RIO_SV_BROADCAST(HostP->svFlags[entry]);
1148#endif 1148#endif
1149 RIOReMapPorts( p, HostP, &HostP->Mapping[entry] ); 1149 RIOReMapPorts( p, HostP, &HostP->Mapping[entry] );
@@ -1159,7 +1159,7 @@ static int RIOBootComplete( struct rio_info *p, struct Host *HostP, uint Rup, st
1159 "This RTA has a tentative entry on another host - delete that entry (1)\n"); 1159 "This RTA has a tentative entry on another host - delete that entry (1)\n");
1160 HostP->Mapping[entry].Flags = 1160 HostP->Mapping[entry].Flags =
1161 SLOT_TENTATIVE | RTA_BOOTED | RTA_NEWBOOT; 1161 SLOT_TENTATIVE | RTA_BOOTED | RTA_NEWBOOT;
1162#if NEED_TO_FIX 1162#ifdef NEED_TO_FIX
1163 RIO_SV_BROADCAST(HostP->svFlags[entry]); 1163 RIO_SV_BROADCAST(HostP->svFlags[entry]);
1164#endif 1164#endif
1165 } 1165 }
@@ -1169,7 +1169,7 @@ static int RIOBootComplete( struct rio_info *p, struct Host *HostP, uint Rup, st
1169 { 1169 {
1170 HostP->Mapping[entry2].Flags = SLOT_IN_USE | 1170 HostP->Mapping[entry2].Flags = SLOT_IN_USE |
1171 RTA_BOOTED | RTA_NEWBOOT | RTA16_SECOND_SLOT; 1171 RTA_BOOTED | RTA_NEWBOOT | RTA16_SECOND_SLOT;
1172#if NEED_TO_FIX 1172#ifdef NEED_TO_FIX
1173 RIO_SV_BROADCAST(HostP->svFlags[entry2]); 1173 RIO_SV_BROADCAST(HostP->svFlags[entry2]);
1174#endif 1174#endif
1175 HostP->Mapping[entry2].SysPort = MapP2->SysPort; 1175 HostP->Mapping[entry2].SysPort = MapP2->SysPort;
@@ -1188,7 +1188,7 @@ static int RIOBootComplete( struct rio_info *p, struct Host *HostP, uint Rup, st
1188 else 1188 else
1189 HostP->Mapping[entry2].Flags = SLOT_TENTATIVE | 1189 HostP->Mapping[entry2].Flags = SLOT_TENTATIVE |
1190 RTA_BOOTED | RTA_NEWBOOT | RTA16_SECOND_SLOT; 1190 RTA_BOOTED | RTA_NEWBOOT | RTA16_SECOND_SLOT;
1191#if NEED_TO_FIX 1191#ifdef NEED_TO_FIX
1192 RIO_SV_BROADCAST(HostP->svFlags[entry2]); 1192 RIO_SV_BROADCAST(HostP->svFlags[entry2]);
1193#endif 1193#endif
1194 bzero( (caddr_t)MapP2, sizeof(struct Map) ); 1194 bzero( (caddr_t)MapP2, sizeof(struct Map) );
diff --git a/drivers/char/rio/rioroute.c b/drivers/char/rio/rioroute.c
index 106b31f48a21..e9564c9fb37c 100644
--- a/drivers/char/rio/rioroute.c
+++ b/drivers/char/rio/rioroute.c
@@ -1023,7 +1023,7 @@ RIOFreeDisconnected(struct rio_info *p, struct Host *HostP, int unit)
1023 if (link < LINKS_PER_UNIT) 1023 if (link < LINKS_PER_UNIT)
1024 return 1; 1024 return 1;
1025 1025
1026#if NEED_TO_FIX_THIS 1026#ifdef NEED_TO_FIX_THIS
1027 /* Ok so all the links are disconnected. But we may have only just 1027 /* Ok so all the links are disconnected. But we may have only just
1028 ** made this slot tentative and not yet received a topology update. 1028 ** made this slot tentative and not yet received a topology update.
1029 ** Lets check how long ago we made it tentative. 1029 ** Lets check how long ago we made it tentative.
diff --git a/drivers/char/rio/riotable.c b/drivers/char/rio/riotable.c
index 8fb26ad2aa12..e45bc275907a 100644
--- a/drivers/char/rio/riotable.c
+++ b/drivers/char/rio/riotable.c
@@ -771,7 +771,7 @@ int RIOAssignRta( struct rio_info *p, struct Map *MapP )
771 if ((MapP->Flags & RTA16_SECOND_SLOT) == 0) 771 if ((MapP->Flags & RTA16_SECOND_SLOT) == 0)
772 CCOPY( MapP->Name, HostMapP->Name, MAX_NAME_LEN ); 772 CCOPY( MapP->Name, HostMapP->Name, MAX_NAME_LEN );
773 HostMapP->Flags = SLOT_IN_USE | RTA_BOOTED; 773 HostMapP->Flags = SLOT_IN_USE | RTA_BOOTED;
774#if NEED_TO_FIX 774#ifdef NEED_TO_FIX
775 RIO_SV_BROADCAST(p->RIOHosts[host].svFlags[MapP->ID-1]); 775 RIO_SV_BROADCAST(p->RIOHosts[host].svFlags[MapP->ID-1]);
776#endif 776#endif
777 if (MapP->Flags & RTA16_SECOND_SLOT) 777 if (MapP->Flags & RTA16_SECOND_SLOT)
diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
index d8f9e94ae475..cd4fe8b1709f 100644
--- a/drivers/char/rtc.c
+++ b/drivers/char/rtc.c
@@ -1209,6 +1209,7 @@ static int rtc_proc_open(struct inode *inode, struct file *file)
1209 1209
1210void rtc_get_rtc_time(struct rtc_time *rtc_tm) 1210void rtc_get_rtc_time(struct rtc_time *rtc_tm)
1211{ 1211{
1212 unsigned long uip_watchdog = jiffies;
1212 unsigned char ctrl; 1213 unsigned char ctrl;
1213#ifdef CONFIG_MACH_DECSTATION 1214#ifdef CONFIG_MACH_DECSTATION
1214 unsigned int real_year; 1215 unsigned int real_year;
@@ -1224,8 +1225,10 @@ void rtc_get_rtc_time(struct rtc_time *rtc_tm)
1224 * Once the read clears, read the RTC time (again via ioctl). Easy. 1225 * Once the read clears, read the RTC time (again via ioctl). Easy.
1225 */ 1226 */
1226 1227
1227 if (rtc_is_updating() != 0) 1228 while (rtc_is_updating() != 0 && jiffies - uip_watchdog < 2*HZ/100) {
1228 msleep(20); 1229 barrier();
1230 cpu_relax();
1231 }
1229 1232
1230 /* 1233 /*
1231 * Only the values that we read from the RTC are set. We leave 1234 * Only the values that we read from the RTC are set. We leave
diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
index fd042060809a..cefbe985e55c 100644
--- a/drivers/char/sonypi.c
+++ b/drivers/char/sonypi.c
@@ -439,6 +439,11 @@ static struct {
439 { 0, 0 }, 439 { 0, 0 },
440}; 440};
441 441
442struct sonypi_keypress {
443 struct input_dev *dev;
444 int key;
445};
446
442static struct sonypi_device { 447static struct sonypi_device {
443 struct pci_dev *dev; 448 struct pci_dev *dev;
444 struct platform_device *pdev; 449 struct platform_device *pdev;
@@ -710,22 +715,61 @@ static void sonypi_setbluetoothpower(u8 state)
710 715
711static void input_keyrelease(void *data) 716static void input_keyrelease(void *data)
712{ 717{
713 struct input_dev *input_dev; 718 struct sonypi_keypress kp;
714 int key;
715
716 while (1) {
717 if (kfifo_get(sonypi_device.input_fifo,
718 (unsigned char *)&input_dev,
719 sizeof(input_dev)) != sizeof(input_dev))
720 return;
721 if (kfifo_get(sonypi_device.input_fifo,
722 (unsigned char *)&key,
723 sizeof(key)) != sizeof(key))
724 return;
725 719
720 while (kfifo_get(sonypi_device.input_fifo, (unsigned char *)&kp,
721 sizeof(kp)) == sizeof(kp)) {
726 msleep(10); 722 msleep(10);
727 input_report_key(input_dev, key, 0); 723 input_report_key(kp.dev, kp.key, 0);
728 input_sync(input_dev); 724 input_sync(kp.dev);
725 }
726}
727
728static void sonypi_report_input_event(u8 event)
729{
730 struct input_dev *jog_dev = &sonypi_device.input_jog_dev;
731 struct input_dev *key_dev = &sonypi_device.input_key_dev;
732 struct sonypi_keypress kp = { NULL };
733 int i;
734
735 switch (event) {
736 case SONYPI_EVENT_JOGDIAL_UP:
737 case SONYPI_EVENT_JOGDIAL_UP_PRESSED:
738 input_report_rel(jog_dev, REL_WHEEL, 1);
739 input_sync(jog_dev);
740 break;
741
742 case SONYPI_EVENT_JOGDIAL_DOWN:
743 case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED:
744 input_report_rel(jog_dev, REL_WHEEL, -1);
745 input_sync(jog_dev);
746 break;
747
748 case SONYPI_EVENT_JOGDIAL_PRESSED:
749 kp.key = BTN_MIDDLE;
750 kp.dev = jog_dev;
751 break;
752
753 case SONYPI_EVENT_FNKEY_RELEASED:
754 /* Nothing, not all VAIOs generate this event */
755 break;
756
757 default:
758 for (i = 0; sonypi_inputkeys[i].sonypiev; i++)
759 if (event == sonypi_inputkeys[i].sonypiev) {
760 kp.dev = key_dev;
761 kp.key = sonypi_inputkeys[i].inputev;
762 break;
763 }
764 break;
765 }
766
767 if (kp.dev) {
768 input_report_key(kp.dev, kp.key, 1);
769 input_sync(kp.dev);
770 kfifo_put(sonypi_device.input_fifo,
771 (unsigned char *)&kp, sizeof(kp));
772 schedule_work(&sonypi_device.input_work);
729 } 773 }
730} 774}
731 775
@@ -768,51 +812,8 @@ found:
768 printk(KERN_INFO 812 printk(KERN_INFO
769 "sonypi: event port1=0x%02x,port2=0x%02x\n", v1, v2); 813 "sonypi: event port1=0x%02x,port2=0x%02x\n", v1, v2);
770 814
771 if (useinput) { 815 if (useinput)
772 struct input_dev *input_jog_dev = &sonypi_device.input_jog_dev; 816 sonypi_report_input_event(event);
773 struct input_dev *input_key_dev = &sonypi_device.input_key_dev;
774 switch (event) {
775 case SONYPI_EVENT_JOGDIAL_UP:
776 case SONYPI_EVENT_JOGDIAL_UP_PRESSED:
777 input_report_rel(input_jog_dev, REL_WHEEL, 1);
778 break;
779 case SONYPI_EVENT_JOGDIAL_DOWN:
780 case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED:
781 input_report_rel(input_jog_dev, REL_WHEEL, -1);
782 break;
783 case SONYPI_EVENT_JOGDIAL_PRESSED: {
784 int key = BTN_MIDDLE;
785 input_report_key(input_jog_dev, key, 1);
786 kfifo_put(sonypi_device.input_fifo,
787 (unsigned char *)&input_jog_dev,
788 sizeof(input_jog_dev));
789 kfifo_put(sonypi_device.input_fifo,
790 (unsigned char *)&key, sizeof(key));
791 break;
792 }
793 case SONYPI_EVENT_FNKEY_RELEASED:
794 /* Nothing, not all VAIOs generate this event */
795 break;
796 }
797 input_sync(input_jog_dev);
798
799 for (i = 0; sonypi_inputkeys[i].sonypiev; i++) {
800 int key;
801
802 if (event != sonypi_inputkeys[i].sonypiev)
803 continue;
804
805 key = sonypi_inputkeys[i].inputev;
806 input_report_key(input_key_dev, key, 1);
807 kfifo_put(sonypi_device.input_fifo,
808 (unsigned char *)&input_key_dev,
809 sizeof(input_key_dev));
810 kfifo_put(sonypi_device.input_fifo,
811 (unsigned char *)&key, sizeof(key));
812 }
813 input_sync(input_key_dev);
814 schedule_work(&sonypi_device.input_work);
815 }
816 817
817 kfifo_put(sonypi_device.fifo, (unsigned char *)&event, sizeof(event)); 818 kfifo_put(sonypi_device.fifo, (unsigned char *)&event, sizeof(event));
818 kill_fasync(&sonypi_device.fifo_async, SIGIO, POLL_IN); 819 kill_fasync(&sonypi_device.fifo_async, SIGIO, POLL_IN);
@@ -1227,14 +1228,7 @@ static int __devinit sonypi_probe(void)
1227 sonypi_device.input_jog_dev.keybit[LONG(BTN_MOUSE)] = 1228 sonypi_device.input_jog_dev.keybit[LONG(BTN_MOUSE)] =
1228 BIT(BTN_MIDDLE); 1229 BIT(BTN_MIDDLE);
1229 sonypi_device.input_jog_dev.relbit[0] = BIT(REL_WHEEL); 1230 sonypi_device.input_jog_dev.relbit[0] = BIT(REL_WHEEL);
1230 sonypi_device.input_jog_dev.name = 1231 sonypi_device.input_jog_dev.name = SONYPI_JOG_INPUTNAME;
1231 kmalloc(sizeof(SONYPI_JOG_INPUTNAME), GFP_KERNEL);
1232 if (!sonypi_device.input_jog_dev.name) {
1233 printk(KERN_ERR "sonypi: kmalloc failed\n");
1234 ret = -ENOMEM;
1235 goto out_inkmallocinput1;
1236 }
1237 sprintf(sonypi_device.input_jog_dev.name, SONYPI_JOG_INPUTNAME);
1238 sonypi_device.input_jog_dev.id.bustype = BUS_ISA; 1232 sonypi_device.input_jog_dev.id.bustype = BUS_ISA;
1239 sonypi_device.input_jog_dev.id.vendor = PCI_VENDOR_ID_SONY; 1233 sonypi_device.input_jog_dev.id.vendor = PCI_VENDOR_ID_SONY;
1240 1234
@@ -1248,14 +1242,7 @@ static int __devinit sonypi_probe(void)
1248 if (sonypi_inputkeys[i].inputev) 1242 if (sonypi_inputkeys[i].inputev)
1249 set_bit(sonypi_inputkeys[i].inputev, 1243 set_bit(sonypi_inputkeys[i].inputev,
1250 sonypi_device.input_key_dev.keybit); 1244 sonypi_device.input_key_dev.keybit);
1251 sonypi_device.input_key_dev.name = 1245 sonypi_device.input_key_dev.name = SONYPI_KEY_INPUTNAME;
1252 kmalloc(sizeof(SONYPI_KEY_INPUTNAME), GFP_KERNEL);
1253 if (!sonypi_device.input_key_dev.name) {
1254 printk(KERN_ERR "sonypi: kmalloc failed\n");
1255 ret = -ENOMEM;
1256 goto out_inkmallocinput2;
1257 }
1258 sprintf(sonypi_device.input_key_dev.name, SONYPI_KEY_INPUTNAME);
1259 sonypi_device.input_key_dev.id.bustype = BUS_ISA; 1246 sonypi_device.input_key_dev.id.bustype = BUS_ISA;
1260 sonypi_device.input_key_dev.id.vendor = PCI_VENDOR_ID_SONY; 1247 sonypi_device.input_key_dev.id.vendor = PCI_VENDOR_ID_SONY;
1261 1248
@@ -1313,11 +1300,7 @@ out_platformdev:
1313 kfifo_free(sonypi_device.input_fifo); 1300 kfifo_free(sonypi_device.input_fifo);
1314out_infifo: 1301out_infifo:
1315 input_unregister_device(&sonypi_device.input_key_dev); 1302 input_unregister_device(&sonypi_device.input_key_dev);
1316 kfree(sonypi_device.input_key_dev.name);
1317out_inkmallocinput2:
1318 input_unregister_device(&sonypi_device.input_jog_dev); 1303 input_unregister_device(&sonypi_device.input_jog_dev);
1319 kfree(sonypi_device.input_jog_dev.name);
1320out_inkmallocinput1:
1321 free_irq(sonypi_device.irq, sonypi_irq); 1304 free_irq(sonypi_device.irq, sonypi_irq);
1322out_reqirq: 1305out_reqirq:
1323 release_region(sonypi_device.ioport1, sonypi_device.region_size); 1306 release_region(sonypi_device.ioport1, sonypi_device.region_size);
@@ -1337,13 +1320,14 @@ static void __devexit sonypi_remove(void)
1337{ 1320{
1338 sonypi_disable(); 1321 sonypi_disable();
1339 1322
1323 synchronize_sched(); /* Allow sonypi interrupt to complete. */
1324 flush_scheduled_work();
1325
1340 platform_device_unregister(sonypi_device.pdev); 1326 platform_device_unregister(sonypi_device.pdev);
1341 1327
1342 if (useinput) { 1328 if (useinput) {
1343 input_unregister_device(&sonypi_device.input_key_dev); 1329 input_unregister_device(&sonypi_device.input_key_dev);
1344 kfree(sonypi_device.input_key_dev.name);
1345 input_unregister_device(&sonypi_device.input_jog_dev); 1330 input_unregister_device(&sonypi_device.input_jog_dev);
1346 kfree(sonypi_device.input_jog_dev.name);
1347 kfifo_free(sonypi_device.input_fifo); 1331 kfifo_free(sonypi_device.input_fifo);
1348 } 1332 }
1349 1333
diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig
index 7a969778915a..79e9832ef1f3 100644
--- a/drivers/char/tpm/Kconfig
+++ b/drivers/char/tpm/Kconfig
@@ -17,6 +17,8 @@ config TCG_TPM
17 obtained at: <http://sourceforge.net/projects/trousers>. To 17 obtained at: <http://sourceforge.net/projects/trousers>. To
18 compile this driver as a module, choose M here; the module 18 compile this driver as a module, choose M here; the module
19 will be called tpm. If unsure, say N. 19 will be called tpm. If unsure, say N.
20 Note: For more TPM drivers enable CONFIG_PNP, CONFIG_ACPI_BUS
21 and CONFIG_PNPACPI.
20 22
21config TCG_NSC 23config TCG_NSC
22 tristate "National Semiconductor TPM Interface" 24 tristate "National Semiconductor TPM Interface"
@@ -35,5 +37,17 @@ config TCG_ATMEL
35 will be accessible from within Linux. To compile this driver 37 will be accessible from within Linux. To compile this driver
36 as a module, choose M here; the module will be called tpm_atmel. 38 as a module, choose M here; the module will be called tpm_atmel.
37 39
40config TCG_INFINEON
41 tristate "Infineon Technologies TPM Interface"
42 depends on TCG_TPM && PNPACPI
43 ---help---
44 If you have a TPM security chip from Infineon Technologies
45 (either SLD 9630 TT 1.1 or SLB 9635 TT 1.2) say Yes and it
46 will be accessible from within Linux.
47 To compile this driver as a module, choose M here; the module
48 will be called tpm_infineon.
49 Further information on this driver and the supported hardware
50 can be found at http://www.prosec.rub.de/tpm
51
38endmenu 52endmenu
39 53
diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile
index 736d3df266f5..2392e404e8d1 100644
--- a/drivers/char/tpm/Makefile
+++ b/drivers/char/tpm/Makefile
@@ -4,4 +4,4 @@
4obj-$(CONFIG_TCG_TPM) += tpm.o 4obj-$(CONFIG_TCG_TPM) += tpm.o
5obj-$(CONFIG_TCG_NSC) += tpm_nsc.o 5obj-$(CONFIG_TCG_NSC) += tpm_nsc.o
6obj-$(CONFIG_TCG_ATMEL) += tpm_atmel.o 6obj-$(CONFIG_TCG_ATMEL) += tpm_atmel.o
7 7obj-$(CONFIG_TCG_INFINEON) += tpm_infineon.o
diff --git a/drivers/char/tpm/tpm_infineon.c b/drivers/char/tpm/tpm_infineon.c
new file mode 100644
index 000000000000..dc8c540391fd
--- /dev/null
+++ b/drivers/char/tpm/tpm_infineon.c
@@ -0,0 +1,533 @@
1/*
2 * Description:
3 * Device Driver for the Infineon Technologies
4 * SLD 9630 TT 1.1 and SLB 9635 TT 1.2 Trusted Platform Module
5 * Specifications at www.trustedcomputinggroup.org
6 *
7 * Copyright (C) 2005, Marcel Selhorst <selhorst@crypto.rub.de>
8 * Applied Data Security Group, Ruhr-University Bochum, Germany
9 * Project-Homepage: http://www.prosec.rub.de/tpm
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation, version 2 of the
14 * License.
15 */
16
17#include <acpi/acpi_bus.h>
18#include <linux/pnp.h>
19#include "tpm.h"
20
21/* Infineon specific definitions */
22/* maximum number of WTX-packages */
23#define TPM_MAX_WTX_PACKAGES 50
24/* msleep-Time for WTX-packages */
25#define TPM_WTX_MSLEEP_TIME 20
26/* msleep-Time --> Interval to check status register */
27#define TPM_MSLEEP_TIME 3
28/* gives number of max. msleep()-calls before throwing timeout */
29#define TPM_MAX_TRIES 5000
30#define TPM_INFINEON_DEV_VEN_VALUE 0x15D1
31
32/* These values will be filled after ACPI-call */
33static int TPM_INF_DATA = 0;
34static int TPM_INF_ADDR = 0;
35
36/* TPM header definitions */
37enum infineon_tpm_header {
38 TPM_VL_VER = 0x01,
39 TPM_VL_CHANNEL_CONTROL = 0x07,
40 TPM_VL_CHANNEL_PERSONALISATION = 0x0A,
41 TPM_VL_CHANNEL_TPM = 0x0B,
42 TPM_VL_CONTROL = 0x00,
43 TPM_INF_NAK = 0x15,
44 TPM_CTRL_WTX = 0x10,
45 TPM_CTRL_WTX_ABORT = 0x18,
46 TPM_CTRL_WTX_ABORT_ACK = 0x18,
47 TPM_CTRL_ERROR = 0x20,
48 TPM_CTRL_CHAININGACK = 0x40,
49 TPM_CTRL_CHAINING = 0x80,
50 TPM_CTRL_DATA = 0x04,
51 TPM_CTRL_DATA_CHA = 0x84,
52 TPM_CTRL_DATA_CHA_ACK = 0xC4
53};
54
55enum infineon_tpm_register {
56 WRFIFO = 0x00,
57 RDFIFO = 0x01,
58 STAT = 0x02,
59 CMD = 0x03
60};
61
62enum infineon_tpm_command_bits {
63 CMD_DIS = 0x00,
64 CMD_LP = 0x01,
65 CMD_RES = 0x02,
66 CMD_IRQC = 0x06
67};
68
69enum infineon_tpm_status_bits {
70 STAT_XFE = 0x00,
71 STAT_LPA = 0x01,
72 STAT_FOK = 0x02,
73 STAT_TOK = 0x03,
74 STAT_IRQA = 0x06,
75 STAT_RDA = 0x07
76};
77
78/* some outgoing values */
79enum infineon_tpm_values {
80 CHIP_ID1 = 0x20,
81 CHIP_ID2 = 0x21,
82 TPM_DAR = 0x30,
83 RESET_LP_IRQC_DISABLE = 0x41,
84 ENABLE_REGISTER_PAIR = 0x55,
85 IOLIMH = 0x60,
86 IOLIML = 0x61,
87 DISABLE_REGISTER_PAIR = 0xAA,
88 IDVENL = 0xF1,
89 IDVENH = 0xF2,
90 IDPDL = 0xF3,
91 IDPDH = 0xF4
92};
93
94static int number_of_wtx;
95
96static int empty_fifo(struct tpm_chip *chip, int clear_wrfifo)
97{
98 int status;
99 int check = 0;
100 int i;
101
102 if (clear_wrfifo) {
103 for (i = 0; i < 4096; i++) {
104 status = inb(chip->vendor->base + WRFIFO);
105 if (status == 0xff) {
106 if (check == 5)
107 break;
108 else
109 check++;
110 }
111 }
112 }
113 /* Note: The values which are currently in the FIFO of the TPM
114 are thrown away since there is no usage for them. Usually,
115 this has nothing to say, since the TPM will give its answer
116 immediately or will be aborted anyway, so the data here is
117 usually garbage and useless.
118 We have to clean this, because the next communication with
119 the TPM would be rubbish, if there is still some old data
120 in the Read FIFO.
121 */
122 i = 0;
123 do {
124 status = inb(chip->vendor->base + RDFIFO);
125 status = inb(chip->vendor->base + STAT);
126 i++;
127 if (i == TPM_MAX_TRIES)
128 return -EIO;
129 } while ((status & (1 << STAT_RDA)) != 0);
130 return 0;
131}
132
133static int wait(struct tpm_chip *chip, int wait_for_bit)
134{
135 int status;
136 int i;
137 for (i = 0; i < TPM_MAX_TRIES; i++) {
138 status = inb(chip->vendor->base + STAT);
139 /* check the status-register if wait_for_bit is set */
140 if (status & 1 << wait_for_bit)
141 break;
142 msleep(TPM_MSLEEP_TIME);
143 }
144 if (i == TPM_MAX_TRIES) { /* timeout occurs */
145 if (wait_for_bit == STAT_XFE)
146 dev_err(&chip->pci_dev->dev,
147 "Timeout in wait(STAT_XFE)\n");
148 if (wait_for_bit == STAT_RDA)
149 dev_err(&chip->pci_dev->dev,
150 "Timeout in wait(STAT_RDA)\n");
151 return -EIO;
152 }
153 return 0;
154};
155
156static void wait_and_send(struct tpm_chip *chip, u8 sendbyte)
157{
158 wait(chip, STAT_XFE);
159 outb(sendbyte, chip->vendor->base + WRFIFO);
160}
161
162 /* Note: WTX means Waiting-Time-Extension. Whenever the TPM needs more
163 calculation time, it sends a WTX-package, which has to be acknowledged
164 or aborted. This usually occurs if you are hammering the TPM with key
165 creation. Set the maximum number of WTX-packages in the definitions
166 above, if the number is reached, the waiting-time will be denied
167 and the TPM command has to be resend.
168 */
169
170static void tpm_wtx(struct tpm_chip *chip)
171{
172 number_of_wtx++;
173 dev_info(&chip->pci_dev->dev, "Granting WTX (%02d / %02d)\n",
174 number_of_wtx, TPM_MAX_WTX_PACKAGES);
175 wait_and_send(chip, TPM_VL_VER);
176 wait_and_send(chip, TPM_CTRL_WTX);
177 wait_and_send(chip, 0x00);
178 wait_and_send(chip, 0x00);
179 msleep(TPM_WTX_MSLEEP_TIME);
180}
181
182static void tpm_wtx_abort(struct tpm_chip *chip)
183{
184 dev_info(&chip->pci_dev->dev, "Aborting WTX\n");
185 wait_and_send(chip, TPM_VL_VER);
186 wait_and_send(chip, TPM_CTRL_WTX_ABORT);
187 wait_and_send(chip, 0x00);
188 wait_and_send(chip, 0x00);
189 number_of_wtx = 0;
190 msleep(TPM_WTX_MSLEEP_TIME);
191}
192
193static int tpm_inf_recv(struct tpm_chip *chip, u8 * buf, size_t count)
194{
195 int i;
196 int ret;
197 u32 size = 0;
198
199recv_begin:
200 /* start receiving header */
201 for (i = 0; i < 4; i++) {
202 ret = wait(chip, STAT_RDA);
203 if (ret)
204 return -EIO;
205 buf[i] = inb(chip->vendor->base + RDFIFO);
206 }
207
208 if (buf[0] != TPM_VL_VER) {
209 dev_err(&chip->pci_dev->dev,
210 "Wrong transport protocol implementation!\n");
211 return -EIO;
212 }
213
214 if (buf[1] == TPM_CTRL_DATA) {
215 /* size of the data received */
216 size = ((buf[2] << 8) | buf[3]);
217
218 for (i = 0; i < size; i++) {
219 wait(chip, STAT_RDA);
220 buf[i] = inb(chip->vendor->base + RDFIFO);
221 }
222
223 if ((size == 0x6D00) && (buf[1] == 0x80)) {
224 dev_err(&chip->pci_dev->dev,
225 "Error handling on vendor layer!\n");
226 return -EIO;
227 }
228
229 for (i = 0; i < size; i++)
230 buf[i] = buf[i + 6];
231
232 size = size - 6;
233 return size;
234 }
235
236 if (buf[1] == TPM_CTRL_WTX) {
237 dev_info(&chip->pci_dev->dev, "WTX-package received\n");
238 if (number_of_wtx < TPM_MAX_WTX_PACKAGES) {
239 tpm_wtx(chip);
240 goto recv_begin;
241 } else {
242 tpm_wtx_abort(chip);
243 goto recv_begin;
244 }
245 }
246
247 if (buf[1] == TPM_CTRL_WTX_ABORT_ACK) {
248 dev_info(&chip->pci_dev->dev, "WTX-abort acknowledged\n");
249 return size;
250 }
251
252 if (buf[1] == TPM_CTRL_ERROR) {
253 dev_err(&chip->pci_dev->dev, "ERROR-package received:\n");
254 if (buf[4] == TPM_INF_NAK)
255 dev_err(&chip->pci_dev->dev,
256 "-> Negative acknowledgement"
257 " - retransmit command!\n");
258 return -EIO;
259 }
260 return -EIO;
261}
262
263static int tpm_inf_send(struct tpm_chip *chip, u8 * buf, size_t count)
264{
265 int i;
266 int ret;
267 u8 count_high, count_low, count_4, count_3, count_2, count_1;
268
269 /* Disabling Reset, LP and IRQC */
270 outb(RESET_LP_IRQC_DISABLE, chip->vendor->base + CMD);
271
272 ret = empty_fifo(chip, 1);
273 if (ret) {
274 dev_err(&chip->pci_dev->dev, "Timeout while clearing FIFO\n");
275 return -EIO;
276 }
277
278 ret = wait(chip, STAT_XFE);
279 if (ret)
280 return -EIO;
281
282 count_4 = (count & 0xff000000) >> 24;
283 count_3 = (count & 0x00ff0000) >> 16;
284 count_2 = (count & 0x0000ff00) >> 8;
285 count_1 = (count & 0x000000ff);
286 count_high = ((count + 6) & 0xffffff00) >> 8;
287 count_low = ((count + 6) & 0x000000ff);
288
289 /* Sending Header */
290 wait_and_send(chip, TPM_VL_VER);
291 wait_and_send(chip, TPM_CTRL_DATA);
292 wait_and_send(chip, count_high);
293 wait_and_send(chip, count_low);
294
295 /* Sending Data Header */
296 wait_and_send(chip, TPM_VL_VER);
297 wait_and_send(chip, TPM_VL_CHANNEL_TPM);
298 wait_and_send(chip, count_4);
299 wait_and_send(chip, count_3);
300 wait_and_send(chip, count_2);
301 wait_and_send(chip, count_1);
302
303 /* Sending Data */
304 for (i = 0; i < count; i++) {
305 wait_and_send(chip, buf[i]);
306 }
307 return count;
308}
309
310static void tpm_inf_cancel(struct tpm_chip *chip)
311{
312 /*
313 Since we are using the legacy mode to communicate
314 with the TPM, we have no cancel functions, but have
315 a workaround for interrupting the TPM through WTX.
316 */
317}
318
319static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
320static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
321static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps, NULL);
322static DEVICE_ATTR(cancel, S_IWUSR | S_IWGRP, NULL, tpm_store_cancel);
323
324static struct attribute *inf_attrs[] = {
325 &dev_attr_pubek.attr,
326 &dev_attr_pcrs.attr,
327 &dev_attr_caps.attr,
328 &dev_attr_cancel.attr,
329 NULL,
330};
331
332static struct attribute_group inf_attr_grp = {.attrs = inf_attrs };
333
334static struct file_operations inf_ops = {
335 .owner = THIS_MODULE,
336 .llseek = no_llseek,
337 .open = tpm_open,
338 .read = tpm_read,
339 .write = tpm_write,
340 .release = tpm_release,
341};
342
343static struct tpm_vendor_specific tpm_inf = {
344 .recv = tpm_inf_recv,
345 .send = tpm_inf_send,
346 .cancel = tpm_inf_cancel,
347 .req_complete_mask = 0,
348 .req_complete_val = 0,
349 .attr_group = &inf_attr_grp,
350 .miscdev = {.fops = &inf_ops,},
351};
352
353static const struct pnp_device_id tpm_pnp_tbl[] = {
354 /* Infineon TPMs */
355 {"IFX0101", 0},
356 {"IFX0102", 0},
357 {"", 0}
358};
359
360static int __devinit tpm_inf_acpi_probe(struct pnp_dev *dev,
361 const struct pnp_device_id *dev_id)
362{
363 TPM_INF_ADDR = (pnp_port_start(dev, 0) & 0xff);
364 TPM_INF_DATA = ((TPM_INF_ADDR + 1) & 0xff);
365 tpm_inf.base = pnp_port_start(dev, 1);
366 dev_info(&dev->dev, "Found %s with ID %s\n",
367 dev->name, dev_id->id);
368 if (!((tpm_inf.base >> 8) & 0xff))
369 tpm_inf.base = 0;
370 return 0;
371}
372
373static struct pnp_driver tpm_inf_pnp = {
374 .name = "tpm_inf_pnp",
375 .id_table = tpm_pnp_tbl,
376 .probe = tpm_inf_acpi_probe,
377};
378
379static int __devinit tpm_inf_probe(struct pci_dev *pci_dev,
380 const struct pci_device_id *pci_id)
381{
382 int rc = 0;
383 u8 iol, ioh;
384 int vendorid[2];
385 int version[2];
386 int productid[2];
387 char chipname[20];
388
389 if (pci_enable_device(pci_dev))
390 return -EIO;
391
392 dev_info(&pci_dev->dev, "LPC-bus found at 0x%x\n", pci_id->device);
393
394 /* read IO-ports from ACPI */
395 pnp_register_driver(&tpm_inf_pnp);
396 pnp_unregister_driver(&tpm_inf_pnp);
397
398 /* Make sure, we have received valid config ports */
399 if (!TPM_INF_ADDR) {
400 pci_disable_device(pci_dev);
401 return -EIO;
402 }
403
404 /* query chip for its vendor, its version number a.s.o. */
405 outb(ENABLE_REGISTER_PAIR, TPM_INF_ADDR);
406 outb(IDVENL, TPM_INF_ADDR);
407 vendorid[1] = inb(TPM_INF_DATA);
408 outb(IDVENH, TPM_INF_ADDR);
409 vendorid[0] = inb(TPM_INF_DATA);
410 outb(IDPDL, TPM_INF_ADDR);
411 productid[1] = inb(TPM_INF_DATA);
412 outb(IDPDH, TPM_INF_ADDR);
413 productid[0] = inb(TPM_INF_DATA);
414 outb(CHIP_ID1, TPM_INF_ADDR);
415 version[1] = inb(TPM_INF_DATA);
416 outb(CHIP_ID2, TPM_INF_ADDR);
417 version[0] = inb(TPM_INF_DATA);
418
419 switch ((productid[0] << 8) | productid[1]) {
420 case 6:
421 sprintf(chipname, " (SLD 9630 TT 1.1)");
422 break;
423 case 11:
424 sprintf(chipname, " (SLB 9635 TT 1.2)");
425 break;
426 default:
427 sprintf(chipname, " (unknown chip)");
428 break;
429 }
430 chipname[19] = 0;
431
432 if ((vendorid[0] << 8 | vendorid[1]) == (TPM_INFINEON_DEV_VEN_VALUE)) {
433
434 if (tpm_inf.base == 0) {
435 dev_err(&pci_dev->dev, "No IO-ports found!\n");
436 pci_disable_device(pci_dev);
437 return -EIO;
438 }
439 /* configure TPM with IO-ports */
440 outb(IOLIMH, TPM_INF_ADDR);
441 outb(((tpm_inf.base >> 8) & 0xff), TPM_INF_DATA);
442 outb(IOLIML, TPM_INF_ADDR);
443 outb((tpm_inf.base & 0xff), TPM_INF_DATA);
444
445 /* control if IO-ports are set correctly */
446 outb(IOLIMH, TPM_INF_ADDR);
447 ioh = inb(TPM_INF_DATA);
448 outb(IOLIML, TPM_INF_ADDR);
449 iol = inb(TPM_INF_DATA);
450
451 if ((ioh << 8 | iol) != tpm_inf.base) {
452 dev_err(&pci_dev->dev,
453 "Could not set IO-ports to %04x\n",
454 tpm_inf.base);
455 pci_disable_device(pci_dev);
456 return -EIO;
457 }
458
459 /* activate register */
460 outb(TPM_DAR, TPM_INF_ADDR);
461 outb(0x01, TPM_INF_DATA);
462 outb(DISABLE_REGISTER_PAIR, TPM_INF_ADDR);
463
464 /* disable RESET, LP and IRQC */
465 outb(RESET_LP_IRQC_DISABLE, tpm_inf.base + CMD);
466
467 /* Finally, we're done, print some infos */
468 dev_info(&pci_dev->dev, "TPM found: "
469 "config base 0x%x, "
470 "io base 0x%x, "
471 "chip version %02x%02x, "
472 "vendor id %x%x (Infineon), "
473 "product id %02x%02x"
474 "%s\n",
475 TPM_INF_ADDR,
476 tpm_inf.base,
477 version[0], version[1],
478 vendorid[0], vendorid[1],
479 productid[0], productid[1], chipname);
480
481 rc = tpm_register_hardware(pci_dev, &tpm_inf);
482 if (rc < 0) {
483 pci_disable_device(pci_dev);
484 return -ENODEV;
485 }
486 return 0;
487 } else {
488 dev_info(&pci_dev->dev, "No Infineon TPM found!\n");
489 pci_disable_device(pci_dev);
490 return -ENODEV;
491 }
492}
493
494static struct pci_device_id tpm_pci_tbl[] __devinitdata = {
495 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0)},
496 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12)},
497 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0)},
498 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12)},
499 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0)},
500 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0)},
501 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1)},
502 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_2)},
503 {0,}
504};
505
506MODULE_DEVICE_TABLE(pci, tpm_pci_tbl);
507
508static struct pci_driver inf_pci_driver = {
509 .name = "tpm_inf",
510 .id_table = tpm_pci_tbl,
511 .probe = tpm_inf_probe,
512 .remove = __devexit_p(tpm_remove),
513 .suspend = tpm_pm_suspend,
514 .resume = tpm_pm_resume,
515};
516
517static int __init init_inf(void)
518{
519 return pci_register_driver(&inf_pci_driver);
520}
521
522static void __exit cleanup_inf(void)
523{
524 pci_unregister_driver(&inf_pci_driver);
525}
526
527module_init(init_inf);
528module_exit(cleanup_inf);
529
530MODULE_AUTHOR("Marcel Selhorst <selhorst@crypto.rub.de>");
531MODULE_DESCRIPTION("Driver for Infineon TPM SLD 9630 TT 1.1 / SLB 9635 TT 1.2");
532MODULE_VERSION("1.5");
533MODULE_LICENSE("GPL");
diff --git a/drivers/char/watchdog/acquirewdt.c b/drivers/char/watchdog/acquirewdt.c
index 8f302121741b..7289f4af93d0 100644
--- a/drivers/char/watchdog/acquirewdt.c
+++ b/drivers/char/watchdog/acquirewdt.c
@@ -82,12 +82,7 @@ static int wdt_start = 0x443;
82module_param(wdt_start, int, 0); 82module_param(wdt_start, int, 0);
83MODULE_PARM_DESC(wdt_start, "Acquire WDT 'start' io port (default 0x443)"); 83MODULE_PARM_DESC(wdt_start, "Acquire WDT 'start' io port (default 0x443)");
84 84
85#ifdef CONFIG_WATCHDOG_NOWAYOUT 85static int nowayout = WATCHDOG_NOWAYOUT;
86static int nowayout = 1;
87#else
88static int nowayout = 0;
89#endif
90
91module_param(nowayout, int, 0); 86module_param(nowayout, int, 0);
92MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 87MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
93 88
diff --git a/drivers/char/watchdog/advantechwdt.c b/drivers/char/watchdog/advantechwdt.c
index ea73c8379bdd..194a3fd36b91 100644
--- a/drivers/char/watchdog/advantechwdt.c
+++ b/drivers/char/watchdog/advantechwdt.c
@@ -73,12 +73,7 @@ static int timeout = WATCHDOG_TIMEOUT; /* in seconds */
73module_param(timeout, int, 0); 73module_param(timeout, int, 0);
74MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. 1<= timeout <=63, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) "."); 74MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. 1<= timeout <=63, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ".");
75 75
76#ifdef CONFIG_WATCHDOG_NOWAYOUT 76static int nowayout = WATCHDOG_NOWAYOUT;
77static int nowayout = 1;
78#else
79static int nowayout = 0;
80#endif
81
82module_param(nowayout, int, 0); 77module_param(nowayout, int, 0);
83MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 78MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
84 79
diff --git a/drivers/char/watchdog/alim1535_wdt.c b/drivers/char/watchdog/alim1535_wdt.c
index 35dcbf8be7d1..8338ca300e2e 100644
--- a/drivers/char/watchdog/alim1535_wdt.c
+++ b/drivers/char/watchdog/alim1535_wdt.c
@@ -38,12 +38,7 @@ static int timeout = WATCHDOG_TIMEOUT;
38module_param(timeout, int, 0); 38module_param(timeout, int, 0);
39MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (0<timeout<18000, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ")"); 39MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (0<timeout<18000, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
40 40
41#ifdef CONFIG_WATCHDOG_NOWAYOUT 41static int nowayout = WATCHDOG_NOWAYOUT;
42static int nowayout = 1;
43#else
44static int nowayout = 0;
45#endif
46
47module_param(nowayout, int, 0); 42module_param(nowayout, int, 0);
48MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 43MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
49 44
@@ -317,7 +312,7 @@ static int ali_notify_sys(struct notifier_block *this, unsigned long code, void
317 */ 312 */
318 313
319static struct pci_device_id ali_pci_tbl[] = { 314static struct pci_device_id ali_pci_tbl[] = {
320 { PCI_VENDOR_ID_AL, 1535, PCI_ANY_ID, PCI_ANY_ID,}, 315 { PCI_VENDOR_ID_AL, 0x1535, PCI_ANY_ID, PCI_ANY_ID,},
321 { 0, }, 316 { 0, },
322}; 317};
323MODULE_DEVICE_TABLE(pci, ali_pci_tbl); 318MODULE_DEVICE_TABLE(pci, ali_pci_tbl);
diff --git a/drivers/char/watchdog/alim7101_wdt.c b/drivers/char/watchdog/alim7101_wdt.c
index 90c091d9e0f5..c05ac188a4d7 100644
--- a/drivers/char/watchdog/alim7101_wdt.c
+++ b/drivers/char/watchdog/alim7101_wdt.c
@@ -75,12 +75,7 @@ static unsigned long wdt_is_open;
75static char wdt_expect_close; 75static char wdt_expect_close;
76static struct pci_dev *alim7101_pmu; 76static struct pci_dev *alim7101_pmu;
77 77
78#ifdef CONFIG_WATCHDOG_NOWAYOUT 78static int nowayout = WATCHDOG_NOWAYOUT;
79static int nowayout = 1;
80#else
81static int nowayout = 0;
82#endif
83
84module_param(nowayout, int, 0); 79module_param(nowayout, int, 0);
85MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 80MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
86 81
diff --git a/drivers/char/watchdog/eurotechwdt.c b/drivers/char/watchdog/eurotechwdt.c
index 2a29a511df7f..25c2f2575611 100644
--- a/drivers/char/watchdog/eurotechwdt.c
+++ b/drivers/char/watchdog/eurotechwdt.c
@@ -72,12 +72,7 @@ static char *ev = "int";
72 72
73#define WDT_TIMEOUT 60 /* 1 minute */ 73#define WDT_TIMEOUT 60 /* 1 minute */
74 74
75#ifdef CONFIG_WATCHDOG_NOWAYOUT 75static int nowayout = WATCHDOG_NOWAYOUT;
76static int nowayout = 1;
77#else
78static int nowayout = 0;
79#endif
80
81module_param(nowayout, int, 0); 76module_param(nowayout, int, 0);
82MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 77MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
83 78
diff --git a/drivers/char/watchdog/i8xx_tco.c b/drivers/char/watchdog/i8xx_tco.c
index 5d07ee59679d..f975dab1ddf9 100644
--- a/drivers/char/watchdog/i8xx_tco.c
+++ b/drivers/char/watchdog/i8xx_tco.c
@@ -105,12 +105,7 @@ static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */
105module_param(heartbeat, int, 0); 105module_param(heartbeat, int, 0);
106MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (2<heartbeat<39, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")"); 106MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (2<heartbeat<39, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
107 107
108#ifdef CONFIG_WATCHDOG_NOWAYOUT 108static int nowayout = WATCHDOG_NOWAYOUT;
109static int nowayout = 1;
110#else
111static int nowayout = 0;
112#endif
113
114module_param(nowayout, int, 0); 109module_param(nowayout, int, 0);
115MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 110MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
116 111
diff --git a/drivers/char/watchdog/ib700wdt.c b/drivers/char/watchdog/ib700wdt.c
index d974f16e84d2..cf60329eec85 100644
--- a/drivers/char/watchdog/ib700wdt.c
+++ b/drivers/char/watchdog/ib700wdt.c
@@ -117,12 +117,7 @@ static int wd_times[] = {
117 117
118static int wd_margin = WD_TIMO; 118static int wd_margin = WD_TIMO;
119 119
120#ifdef CONFIG_WATCHDOG_NOWAYOUT 120static int nowayout = WATCHDOG_NOWAYOUT;
121static int nowayout = 1;
122#else
123static int nowayout = 0;
124#endif
125
126module_param(nowayout, int, 0); 121module_param(nowayout, int, 0);
127MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 122MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
128 123
diff --git a/drivers/char/watchdog/indydog.c b/drivers/char/watchdog/indydog.c
index 6af2c799b57e..b4b94daba67e 100644
--- a/drivers/char/watchdog/indydog.c
+++ b/drivers/char/watchdog/indydog.c
@@ -29,14 +29,9 @@
29#define PFX "indydog: " 29#define PFX "indydog: "
30static int indydog_alive; 30static int indydog_alive;
31 31
32#ifdef CONFIG_WATCHDOG_NOWAYOUT
33static int nowayout = 1;
34#else
35static int nowayout = 0;
36#endif
37
38#define WATCHDOG_TIMEOUT 30 /* 30 sec default timeout */ 32#define WATCHDOG_TIMEOUT 30 /* 30 sec default timeout */
39 33
34static int nowayout = WATCHDOG_NOWAYOUT;
40module_param(nowayout, int, 0); 35module_param(nowayout, int, 0);
41MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 36MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
42 37
diff --git a/drivers/char/watchdog/ixp2000_wdt.c b/drivers/char/watchdog/ixp2000_wdt.c
index 4b039516cc86..e7640bc4904b 100644
--- a/drivers/char/watchdog/ixp2000_wdt.c
+++ b/drivers/char/watchdog/ixp2000_wdt.c
@@ -30,11 +30,7 @@
30#include <asm/hardware.h> 30#include <asm/hardware.h>
31#include <asm/uaccess.h> 31#include <asm/uaccess.h>
32 32
33#ifdef CONFIG_WATCHDOG_NOWAYOUT 33static int nowayout = WATCHDOG_NOWAYOUT;
34static int nowayout = 1;
35#else
36static int nowayout = 0;
37#endif
38static unsigned int heartbeat = 60; /* (secs) Default is 1 minute */ 34static unsigned int heartbeat = 60; /* (secs) Default is 1 minute */
39static unsigned long wdt_status; 35static unsigned long wdt_status;
40 36
diff --git a/drivers/char/watchdog/ixp4xx_wdt.c b/drivers/char/watchdog/ixp4xx_wdt.c
index 83df369113a4..8d916afbf4fa 100644
--- a/drivers/char/watchdog/ixp4xx_wdt.c
+++ b/drivers/char/watchdog/ixp4xx_wdt.c
@@ -27,11 +27,7 @@
27#include <asm/hardware.h> 27#include <asm/hardware.h>
28#include <asm/uaccess.h> 28#include <asm/uaccess.h>
29 29
30#ifdef CONFIG_WATCHDOG_NOWAYOUT 30static int nowayout = WATCHDOG_NOWAYOUT;
31static int nowayout = 1;
32#else
33static int nowayout = 0;
34#endif
35static int heartbeat = 60; /* (secs) Default is 1 minute */ 31static int heartbeat = 60; /* (secs) Default is 1 minute */
36static unsigned long wdt_status; 32static unsigned long wdt_status;
37static unsigned long boot_status; 33static unsigned long boot_status;
diff --git a/drivers/char/watchdog/machzwd.c b/drivers/char/watchdog/machzwd.c
index 9da395fa7794..a9a20aad61e7 100644
--- a/drivers/char/watchdog/machzwd.c
+++ b/drivers/char/watchdog/machzwd.c
@@ -94,12 +94,7 @@ MODULE_DESCRIPTION("MachZ ZF-Logic Watchdog driver");
94MODULE_LICENSE("GPL"); 94MODULE_LICENSE("GPL");
95MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); 95MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
96 96
97#ifdef CONFIG_WATCHDOG_NOWAYOUT 97static int nowayout = WATCHDOG_NOWAYOUT;
98static int nowayout = 1;
99#else
100static int nowayout = 0;
101#endif
102
103module_param(nowayout, int, 0); 98module_param(nowayout, int, 0);
104MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 99MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
105 100
diff --git a/drivers/char/watchdog/mixcomwd.c b/drivers/char/watchdog/mixcomwd.c
index 3143e4a07535..c9b301dccec3 100644
--- a/drivers/char/watchdog/mixcomwd.c
+++ b/drivers/char/watchdog/mixcomwd.c
@@ -62,12 +62,7 @@ static int mixcomwd_timer_alive;
62static struct timer_list mixcomwd_timer = TIMER_INITIALIZER(NULL, 0, 0); 62static struct timer_list mixcomwd_timer = TIMER_INITIALIZER(NULL, 0, 0);
63static char expect_close; 63static char expect_close;
64 64
65#ifdef CONFIG_WATCHDOG_NOWAYOUT 65static int nowayout = WATCHDOG_NOWAYOUT;
66static int nowayout = 1;
67#else
68static int nowayout = 0;
69#endif
70
71module_param(nowayout, int, 0); 66module_param(nowayout, int, 0);
72MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 67MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
73 68
diff --git a/drivers/char/watchdog/pcwd.c b/drivers/char/watchdog/pcwd.c
index 6ebce3f2ef9c..427ad51b7a35 100644
--- a/drivers/char/watchdog/pcwd.c
+++ b/drivers/char/watchdog/pcwd.c
@@ -146,12 +146,7 @@ static int heartbeat = WATCHDOG_HEARTBEAT;
146module_param(heartbeat, int, 0); 146module_param(heartbeat, int, 0);
147MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (2<=heartbeat<=7200, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")"); 147MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (2<=heartbeat<=7200, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
148 148
149#ifdef CONFIG_WATCHDOG_NOWAYOUT 149static int nowayout = WATCHDOG_NOWAYOUT;
150static int nowayout = 1;
151#else
152static int nowayout = 0;
153#endif
154
155module_param(nowayout, int, 0); 150module_param(nowayout, int, 0);
156MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 151MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
157 152
diff --git a/drivers/char/watchdog/pcwd_pci.c b/drivers/char/watchdog/pcwd_pci.c
index 8ce066627326..2b13afb09c5d 100644
--- a/drivers/char/watchdog/pcwd_pci.c
+++ b/drivers/char/watchdog/pcwd_pci.c
@@ -103,12 +103,7 @@ static int heartbeat = WATCHDOG_HEARTBEAT;
103module_param(heartbeat, int, 0); 103module_param(heartbeat, int, 0);
104MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (0<heartbeat<65536, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")"); 104MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (0<heartbeat<65536, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
105 105
106#ifdef CONFIG_WATCHDOG_NOWAYOUT 106static int nowayout = WATCHDOG_NOWAYOUT;
107static int nowayout = 1;
108#else
109static int nowayout = 0;
110#endif
111
112module_param(nowayout, int, 0); 107module_param(nowayout, int, 0);
113MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 108MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
114 109
diff --git a/drivers/char/watchdog/pcwd_usb.c b/drivers/char/watchdog/pcwd_usb.c
index 1127201d73b8..092e9b133750 100644
--- a/drivers/char/watchdog/pcwd_usb.c
+++ b/drivers/char/watchdog/pcwd_usb.c
@@ -79,12 +79,7 @@ static int heartbeat = WATCHDOG_HEARTBEAT;
79module_param(heartbeat, int, 0); 79module_param(heartbeat, int, 0);
80MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (0<heartbeat<65536, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")"); 80MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (0<heartbeat<65536, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
81 81
82#ifdef CONFIG_WATCHDOG_NOWAYOUT 82static int nowayout = WATCHDOG_NOWAYOUT;
83static int nowayout = 1;
84#else
85static int nowayout = 0;
86#endif
87
88module_param(nowayout, int, 0); 83module_param(nowayout, int, 0);
89MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 84MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
90 85
diff --git a/drivers/char/watchdog/s3c2410_wdt.c b/drivers/char/watchdog/s3c2410_wdt.c
index 1699d2c28ce5..f85ac898a49a 100644
--- a/drivers/char/watchdog/s3c2410_wdt.c
+++ b/drivers/char/watchdog/s3c2410_wdt.c
@@ -62,12 +62,7 @@
62#define CONFIG_S3C2410_WATCHDOG_ATBOOT (0) 62#define CONFIG_S3C2410_WATCHDOG_ATBOOT (0)
63#define CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME (15) 63#define CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME (15)
64 64
65#ifdef CONFIG_WATCHDOG_NOWAYOUT 65static int nowayout = WATCHDOG_NOWAYOUT;
66static int nowayout = 1;
67#else
68static int nowayout = 0;
69#endif
70
71static int tmr_margin = CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME; 66static int tmr_margin = CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME;
72static int tmr_atboot = CONFIG_S3C2410_WATCHDOG_ATBOOT; 67static int tmr_atboot = CONFIG_S3C2410_WATCHDOG_ATBOOT;
73static int soft_noboot = 0; 68static int soft_noboot = 0;
diff --git a/drivers/char/watchdog/sa1100_wdt.c b/drivers/char/watchdog/sa1100_wdt.c
index 34e8f7b15e30..fb88b4041dca 100644
--- a/drivers/char/watchdog/sa1100_wdt.c
+++ b/drivers/char/watchdog/sa1100_wdt.c
@@ -36,17 +36,10 @@
36#include <asm/uaccess.h> 36#include <asm/uaccess.h>
37 37
38#define OSCR_FREQ CLOCK_TICK_RATE 38#define OSCR_FREQ CLOCK_TICK_RATE
39#define SA1100_CLOSE_MAGIC (0x5afc4453)
40 39
41static unsigned long sa1100wdt_users; 40static unsigned long sa1100wdt_users;
42static int expect_close;
43static int pre_margin; 41static int pre_margin;
44static int boot_status; 42static int boot_status;
45#ifdef CONFIG_WATCHDOG_NOWAYOUT
46static int nowayout = 1;
47#else
48static int nowayout = 0;
49#endif
50 43
51/* 44/*
52 * Allow only one person to hold it open 45 * Allow only one person to hold it open
@@ -66,55 +59,33 @@ static int sa1100dog_open(struct inode *inode, struct file *file)
66} 59}
67 60
68/* 61/*
69 * Shut off the timer. 62 * The watchdog cannot be disabled.
70 * Lock it in if it's a module and we defined ...NOWAYOUT 63 *
71 * Oddly, the watchdog can only be enabled, but we can turn off 64 * Previous comments suggested that turning off the interrupt by
72 * the interrupt, which appears to prevent the watchdog timing out. 65 * clearing OIER[E3] would prevent the watchdog timing out but this
66 * does not appear to be true (at least on the PXA255).
73 */ 67 */
74static int sa1100dog_release(struct inode *inode, struct file *file) 68static int sa1100dog_release(struct inode *inode, struct file *file)
75{ 69{
76 OSMR3 = OSCR + pre_margin; 70 printk(KERN_CRIT "WATCHDOG: Device closed - timer will not stop\n");
77
78 if (expect_close == SA1100_CLOSE_MAGIC) {
79 OIER &= ~OIER_E3;
80 } else {
81 printk(KERN_CRIT "WATCHDOG: WDT device closed unexpectedly. WDT will not stop!\n");
82 }
83 71
84 clear_bit(1, &sa1100wdt_users); 72 clear_bit(1, &sa1100wdt_users);
85 expect_close = 0;
86 73
87 return 0; 74 return 0;
88} 75}
89 76
90static ssize_t sa1100dog_write(struct file *file, const char *data, size_t len, loff_t *ppos) 77static ssize_t sa1100dog_write(struct file *file, const char *data, size_t len, loff_t *ppos)
91{ 78{
92 if (len) { 79 if (len)
93 if (!nowayout) {
94 size_t i;
95
96 expect_close = 0;
97
98 for (i = 0; i != len; i++) {
99 char c;
100
101 if (get_user(c, data + i))
102 return -EFAULT;
103 if (c == 'V')
104 expect_close = SA1100_CLOSE_MAGIC;
105 }
106 }
107 /* Refresh OSMR3 timer. */ 80 /* Refresh OSMR3 timer. */
108 OSMR3 = OSCR + pre_margin; 81 OSMR3 = OSCR + pre_margin;
109 }
110 82
111 return len; 83 return len;
112} 84}
113 85
114static struct watchdog_info ident = { 86static struct watchdog_info ident = {
115 .options = WDIOF_CARDRESET | WDIOF_MAGICCLOSE | 87 .options = WDIOF_CARDRESET | WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
116 WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING, 88 .identity = "SA1100/PXA255 Watchdog",
117 .identity = "SA1100 Watchdog",
118}; 89};
119 90
120static int sa1100dog_ioctl(struct inode *inode, struct file *file, 91static int sa1100dog_ioctl(struct inode *inode, struct file *file,
@@ -176,7 +147,7 @@ static struct file_operations sa1100dog_fops =
176static struct miscdevice sa1100dog_miscdev = 147static struct miscdevice sa1100dog_miscdev =
177{ 148{
178 .minor = WATCHDOG_MINOR, 149 .minor = WATCHDOG_MINOR,
179 .name = "SA1100/PXA2xx watchdog", 150 .name = "watchdog",
180 .fops = &sa1100dog_fops, 151 .fops = &sa1100dog_fops,
181}; 152};
182 153
@@ -198,7 +169,6 @@ static int __init sa1100dog_init(void)
198 if (ret == 0) 169 if (ret == 0)
199 printk("SA1100/PXA2xx Watchdog Timer: timer margin %d sec\n", 170 printk("SA1100/PXA2xx Watchdog Timer: timer margin %d sec\n",
200 margin); 171 margin);
201
202 return ret; 172 return ret;
203} 173}
204 174
@@ -216,8 +186,5 @@ MODULE_DESCRIPTION("SA1100/PXA2xx Watchdog");
216module_param(margin, int, 0); 186module_param(margin, int, 0);
217MODULE_PARM_DESC(margin, "Watchdog margin in seconds (default 60s)"); 187MODULE_PARM_DESC(margin, "Watchdog margin in seconds (default 60s)");
218 188
219module_param(nowayout, int, 0);
220MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
221
222MODULE_LICENSE("GPL"); 189MODULE_LICENSE("GPL");
223MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); 190MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/char/watchdog/sbc60xxwdt.c b/drivers/char/watchdog/sbc60xxwdt.c
index d7de9880605a..ed0bd55fbfc1 100644
--- a/drivers/char/watchdog/sbc60xxwdt.c
+++ b/drivers/char/watchdog/sbc60xxwdt.c
@@ -98,12 +98,7 @@ static int timeout = WATCHDOG_TIMEOUT; /* in seconds, will be multiplied by HZ t
98module_param(timeout, int, 0); 98module_param(timeout, int, 0);
99MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (1<=timeout<=3600, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ")"); 99MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (1<=timeout<=3600, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
100 100
101#ifdef CONFIG_WATCHDOG_NOWAYOUT 101static int nowayout = WATCHDOG_NOWAYOUT;
102static int nowayout = 1;
103#else
104static int nowayout = 0;
105#endif
106
107module_param(nowayout, int, 0); 102module_param(nowayout, int, 0);
108MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 103MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
109 104
diff --git a/drivers/char/watchdog/sc1200wdt.c b/drivers/char/watchdog/sc1200wdt.c
index 24401e84729e..515ce7572049 100644
--- a/drivers/char/watchdog/sc1200wdt.c
+++ b/drivers/char/watchdog/sc1200wdt.c
@@ -91,12 +91,7 @@ MODULE_PARM_DESC(io, "io port");
91module_param(timeout, int, 0); 91module_param(timeout, int, 0);
92MODULE_PARM_DESC(timeout, "range is 0-255 minutes, default is 1"); 92MODULE_PARM_DESC(timeout, "range is 0-255 minutes, default is 1");
93 93
94#ifdef CONFIG_WATCHDOG_NOWAYOUT 94static int nowayout = WATCHDOG_NOWAYOUT;
95static int nowayout = 1;
96#else
97static int nowayout = 0;
98#endif
99
100module_param(nowayout, int, 0); 95module_param(nowayout, int, 0);
101MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 96MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
102 97
diff --git a/drivers/char/watchdog/sc520_wdt.c b/drivers/char/watchdog/sc520_wdt.c
index f6d143e1900d..72501be79b0c 100644
--- a/drivers/char/watchdog/sc520_wdt.c
+++ b/drivers/char/watchdog/sc520_wdt.c
@@ -94,12 +94,7 @@ static int timeout = WATCHDOG_TIMEOUT; /* in seconds, will be multiplied by HZ t
94module_param(timeout, int, 0); 94module_param(timeout, int, 0);
95MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (1<=timeout<=3600, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ")"); 95MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (1<=timeout<=3600, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
96 96
97#ifdef CONFIG_WATCHDOG_NOWAYOUT 97static int nowayout = WATCHDOG_NOWAYOUT;
98static int nowayout = 1;
99#else
100static int nowayout = 0;
101#endif
102
103module_param(nowayout, int, 0); 98module_param(nowayout, int, 0);
104MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 99MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
105 100
diff --git a/drivers/char/watchdog/scx200_wdt.c b/drivers/char/watchdog/scx200_wdt.c
index b569670e4ed5..c4568569f3a8 100644
--- a/drivers/char/watchdog/scx200_wdt.c
+++ b/drivers/char/watchdog/scx200_wdt.c
@@ -39,15 +39,11 @@ MODULE_DESCRIPTION("NatSemi SCx200 Watchdog Driver");
39MODULE_LICENSE("GPL"); 39MODULE_LICENSE("GPL");
40MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); 40MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
41 41
42#ifndef CONFIG_WATCHDOG_NOWAYOUT
43#define CONFIG_WATCHDOG_NOWAYOUT 0
44#endif
45
46static int margin = 60; /* in seconds */ 42static int margin = 60; /* in seconds */
47module_param(margin, int, 0); 43module_param(margin, int, 0);
48MODULE_PARM_DESC(margin, "Watchdog margin in seconds"); 44MODULE_PARM_DESC(margin, "Watchdog margin in seconds");
49 45
50static int nowayout = CONFIG_WATCHDOG_NOWAYOUT; 46static int nowayout = WATCHDOG_NOWAYOUT;
51module_param(nowayout, int, 0); 47module_param(nowayout, int, 0);
52MODULE_PARM_DESC(nowayout, "Disable watchdog shutdown on close"); 48MODULE_PARM_DESC(nowayout, "Disable watchdog shutdown on close");
53 49
diff --git a/drivers/char/watchdog/shwdt.c b/drivers/char/watchdog/shwdt.c
index 3bc9272a474c..1f4cab55b2ef 100644
--- a/drivers/char/watchdog/shwdt.c
+++ b/drivers/char/watchdog/shwdt.c
@@ -75,11 +75,7 @@ static unsigned long next_heartbeat;
75#define WATCHDOG_HEARTBEAT 30 /* 30 sec default heartbeat */ 75#define WATCHDOG_HEARTBEAT 30 /* 30 sec default heartbeat */
76static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */ 76static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */
77 77
78#ifdef CONFIG_WATCHDOG_NOWAYOUT 78static int nowayout = WATCHDOG_NOWAYOUT;
79static int nowayout = 1;
80#else
81static int nowayout = 0;
82#endif
83 79
84/** 80/**
85 * sh_wdt_start - Start the Watchdog 81 * sh_wdt_start - Start the Watchdog
diff --git a/drivers/char/watchdog/softdog.c b/drivers/char/watchdog/softdog.c
index 98c7578740e2..4d7ed931f5c6 100644
--- a/drivers/char/watchdog/softdog.c
+++ b/drivers/char/watchdog/softdog.c
@@ -56,12 +56,7 @@ static int soft_margin = TIMER_MARGIN; /* in seconds */
56module_param(soft_margin, int, 0); 56module_param(soft_margin, int, 0);
57MODULE_PARM_DESC(soft_margin, "Watchdog soft_margin in seconds. (0<soft_margin<65536, default=" __MODULE_STRING(TIMER_MARGIN) ")"); 57MODULE_PARM_DESC(soft_margin, "Watchdog soft_margin in seconds. (0<soft_margin<65536, default=" __MODULE_STRING(TIMER_MARGIN) ")");
58 58
59#ifdef CONFIG_WATCHDOG_NOWAYOUT 59static int nowayout = WATCHDOG_NOWAYOUT;
60static int nowayout = 1;
61#else
62static int nowayout = 0;
63#endif
64
65module_param(nowayout, int, 0); 60module_param(nowayout, int, 0);
66MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 61MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
67 62
diff --git a/drivers/char/watchdog/w83627hf_wdt.c b/drivers/char/watchdog/w83627hf_wdt.c
index 813c97038f84..465e0fd0423d 100644
--- a/drivers/char/watchdog/w83627hf_wdt.c
+++ b/drivers/char/watchdog/w83627hf_wdt.c
@@ -54,12 +54,7 @@ static int timeout = WATCHDOG_TIMEOUT; /* in seconds */
54module_param(timeout, int, 0); 54module_param(timeout, int, 0);
55MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. 1<= timeout <=63, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) "."); 55MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. 1<= timeout <=63, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ".");
56 56
57#ifdef CONFIG_WATCHDOG_NOWAYOUT 57static int nowayout = WATCHDOG_NOWAYOUT;
58static int nowayout = 1;
59#else
60static int nowayout = 0;
61#endif
62
63module_param(nowayout, int, 0); 58module_param(nowayout, int, 0);
64MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 59MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
65 60
diff --git a/drivers/char/watchdog/w83877f_wdt.c b/drivers/char/watchdog/w83877f_wdt.c
index bccbd4d6ac2d..52a8bd0a5988 100644
--- a/drivers/char/watchdog/w83877f_wdt.c
+++ b/drivers/char/watchdog/w83877f_wdt.c
@@ -85,12 +85,7 @@ module_param(timeout, int, 0);
85MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (1<=timeout<=3600, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ")"); 85MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (1<=timeout<=3600, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
86 86
87 87
88#ifdef CONFIG_WATCHDOG_NOWAYOUT 88static int nowayout = WATCHDOG_NOWAYOUT;
89static int nowayout = 1;
90#else
91static int nowayout = 0;
92#endif
93
94module_param(nowayout, int, 0); 89module_param(nowayout, int, 0);
95MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 90MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
96 91
diff --git a/drivers/char/watchdog/wafer5823wdt.c b/drivers/char/watchdog/wafer5823wdt.c
index abb0bea45c02..7cf6c9bbf486 100644
--- a/drivers/char/watchdog/wafer5823wdt.c
+++ b/drivers/char/watchdog/wafer5823wdt.c
@@ -63,12 +63,7 @@ static int timeout = WD_TIMO; /* in seconds */
63module_param(timeout, int, 0); 63module_param(timeout, int, 0);
64MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. 1<= timeout <=255, default=" __MODULE_STRING(WD_TIMO) "."); 64MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. 1<= timeout <=255, default=" __MODULE_STRING(WD_TIMO) ".");
65 65
66#ifdef CONFIG_WATCHDOG_NOWAYOUT 66static int nowayout = WATCHDOG_NOWAYOUT;
67static int nowayout = 1;
68#else
69static int nowayout = 0;
70#endif
71
72module_param(nowayout, int, 0); 67module_param(nowayout, int, 0);
73MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 68MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
74 69
diff --git a/drivers/char/watchdog/wdt.c b/drivers/char/watchdog/wdt.c
index 1210ca0c425b..ec7e401228ee 100644
--- a/drivers/char/watchdog/wdt.c
+++ b/drivers/char/watchdog/wdt.c
@@ -63,12 +63,7 @@ static int wd_heartbeat;
63module_param(heartbeat, int, 0); 63module_param(heartbeat, int, 0);
64MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (0<heartbeat<65536, default=" __MODULE_STRING(WD_TIMO) ")"); 64MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (0<heartbeat<65536, default=" __MODULE_STRING(WD_TIMO) ")");
65 65
66#ifdef CONFIG_WATCHDOG_NOWAYOUT 66static int nowayout = WATCHDOG_NOWAYOUT;
67static int nowayout = 1;
68#else
69static int nowayout = 0;
70#endif
71
72module_param(nowayout, int, 0); 67module_param(nowayout, int, 0);
73MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 68MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
74 69
diff --git a/drivers/char/watchdog/wdt977.c b/drivers/char/watchdog/wdt977.c
index 072e9b214759..44d49dfacbb3 100644
--- a/drivers/char/watchdog/wdt977.c
+++ b/drivers/char/watchdog/wdt977.c
@@ -53,12 +53,7 @@ MODULE_PARM_DESC(timeout,"Watchdog timeout in seconds (60..15300), default=" __M
53module_param(testmode, int, 0); 53module_param(testmode, int, 0);
54MODULE_PARM_DESC(testmode,"Watchdog testmode (1 = no reboot), default=0"); 54MODULE_PARM_DESC(testmode,"Watchdog testmode (1 = no reboot), default=0");
55 55
56#ifdef CONFIG_WATCHDOG_NOWAYOUT 56static int nowayout = WATCHDOG_NOWAYOUT;
57static int nowayout = 1;
58#else
59static int nowayout = 0;
60#endif
61
62module_param(nowayout, int, 0); 57module_param(nowayout, int, 0);
63MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 58MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
64 59
diff --git a/drivers/char/watchdog/wdt_pci.c b/drivers/char/watchdog/wdt_pci.c
index c80cb77b92fb..4b3311993d48 100644
--- a/drivers/char/watchdog/wdt_pci.c
+++ b/drivers/char/watchdog/wdt_pci.c
@@ -89,12 +89,7 @@ static int wd_heartbeat;
89module_param(heartbeat, int, 0); 89module_param(heartbeat, int, 0);
90MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (0<heartbeat<65536, default=" __MODULE_STRING(WD_TIMO) ")"); 90MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (0<heartbeat<65536, default=" __MODULE_STRING(WD_TIMO) ")");
91 91
92#ifdef CONFIG_WATCHDOG_NOWAYOUT 92static int nowayout = WATCHDOG_NOWAYOUT;
93static int nowayout = 1;
94#else
95static int nowayout = 0;
96#endif
97
98module_param(nowayout, int, 0); 93module_param(nowayout, int, 0);
99MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 94MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
100 95
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 7a7859dd0d98..10b014982381 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1130,7 +1130,7 @@ int cpufreq_driver_target(struct cpufreq_policy *policy,
1130 unsigned int target_freq, 1130 unsigned int target_freq,
1131 unsigned int relation) 1131 unsigned int relation)
1132{ 1132{
1133 unsigned int ret; 1133 int ret;
1134 1134
1135 policy = cpufreq_cpu_get(policy->cpu); 1135 policy = cpufreq_cpu_get(policy->cpu);
1136 if (!policy) 1136 if (!policy)
@@ -1151,7 +1151,7 @@ EXPORT_SYMBOL_GPL(cpufreq_driver_target);
1151 1151
1152static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event) 1152static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event)
1153{ 1153{
1154 int ret = -EINVAL; 1154 int ret;
1155 1155
1156 if (!try_module_get(policy->governor->owner)) 1156 if (!try_module_get(policy->governor->owner))
1157 return -EINVAL; 1157 return -EINVAL;
diff --git a/drivers/fc4/fc.c b/drivers/fc4/fc.c
index 5d961f5e0ca0..e4710d1d1f9d 100644
--- a/drivers/fc4/fc.c
+++ b/drivers/fc4/fc.c
@@ -1004,8 +1004,8 @@ int fcp_scsi_dev_reset(Scsi_Cmnd *SCpnt)
1004 return FAILED; 1004 return FAILED;
1005 } 1005 }
1006 fc->rst_pkt->eh_state = SCSI_STATE_UNUSED; 1006 fc->rst_pkt->eh_state = SCSI_STATE_UNUSED;
1007 return SUCCESS;
1008#endif 1007#endif
1008 return SUCCESS;
1009} 1009}
1010 1010
1011static int __fcp_scsi_host_reset(Scsi_Cmnd *SCpnt) 1011static int __fcp_scsi_host_reset(Scsi_Cmnd *SCpnt)
diff --git a/drivers/firmware/pcdp.c b/drivers/firmware/pcdp.c
index 53c95c0bbf46..ae1fb45dbb40 100644
--- a/drivers/firmware/pcdp.c
+++ b/drivers/firmware/pcdp.c
@@ -25,14 +25,22 @@ setup_serial_console(struct pcdp_uart *uart)
25#ifdef CONFIG_SERIAL_8250_CONSOLE 25#ifdef CONFIG_SERIAL_8250_CONSOLE
26 int mmio; 26 int mmio;
27 static char options[64], *p = options; 27 static char options[64], *p = options;
28 char parity;
28 29
29 mmio = (uart->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY); 30 mmio = (uart->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY);
30 p += sprintf(p, "console=uart,%s,0x%lx", 31 p += sprintf(p, "console=uart,%s,0x%lx",
31 mmio ? "mmio" : "io", uart->addr.address); 32 mmio ? "mmio" : "io", uart->addr.address);
32 if (uart->baud) 33 if (uart->baud) {
33 p += sprintf(p, ",%lu", uart->baud); 34 p += sprintf(p, ",%lu", uart->baud);
34 if (uart->bits) 35 if (uart->bits) {
35 p += sprintf(p, "n%d", uart->bits); 36 switch (uart->parity) {
37 case 0x2: parity = 'e'; break;
38 case 0x3: parity = 'o'; break;
39 default: parity = 'n';
40 }
41 p += sprintf(p, "%c%d", parity, uart->bits);
42 }
43 }
36 44
37 return early_serial_console_init(options); 45 return early_serial_console_init(options);
38#else 46#else
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c
index 3c85fe150cd7..4fa17c76eea2 100644
--- a/drivers/hwmon/adm1026.c
+++ b/drivers/hwmon/adm1026.c
@@ -393,7 +393,7 @@ void adm1026_init_client(struct i2c_client *client)
393 393
394 value = data->config3; 394 value = data->config3;
395 if (data->config3 & CFG3_GPIO16_ENABLE) { 395 if (data->config3 & CFG3_GPIO16_ENABLE) {
396 dev_dbg(&client->dev, "GPIO16 enabled. THERM" 396 dev_dbg(&client->dev, "GPIO16 enabled. THERM "
397 "pin disabled.\n"); 397 "pin disabled.\n");
398 } else { 398 } else {
399 dev_dbg(&client->dev, "THERM pin enabled. " 399 dev_dbg(&client->dev, "THERM pin enabled. "
diff --git a/drivers/hwmon/atxp1.c b/drivers/hwmon/atxp1.c
index 0bcf82b4c07b..fca3fc1cef72 100644
--- a/drivers/hwmon/atxp1.c
+++ b/drivers/hwmon/atxp1.c
@@ -21,6 +21,7 @@
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/jiffies.h>
24#include <linux/i2c.h> 25#include <linux/i2c.h>
25#include <linux/i2c-sensor.h> 26#include <linux/i2c-sensor.h>
26#include <linux/i2c-vid.h> 27#include <linux/i2c-vid.h>
@@ -80,9 +81,7 @@ static struct atxp1_data * atxp1_update_device(struct device *dev)
80 81
81 down(&data->update_lock); 82 down(&data->update_lock);
82 83
83 if ((jiffies - data->last_updated > HZ) || 84 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
84 (jiffies < data->last_updated) ||
85 !data->valid) {
86 85
87 /* Update local register data */ 86 /* Update local register data */
88 data->reg.vid = i2c_smbus_read_byte_data(client, ATXP1_VID); 87 data->reg.vid = i2c_smbus_read_byte_data(client, ATXP1_VID);
diff --git a/drivers/hwmon/fscpos.c b/drivers/hwmon/fscpos.c
index 3beaa6191ef4..270015b626ad 100644
--- a/drivers/hwmon/fscpos.c
+++ b/drivers/hwmon/fscpos.c
@@ -32,6 +32,7 @@
32 32
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/jiffies.h>
35#include <linux/i2c.h> 36#include <linux/i2c.h>
36#include <linux/i2c-sensor.h> 37#include <linux/i2c-sensor.h>
37#include <linux/init.h> 38#include <linux/init.h>
@@ -572,8 +573,7 @@ static struct fscpos_data *fscpos_update_device(struct device *dev)
572 573
573 down(&data->update_lock); 574 down(&data->update_lock);
574 575
575 if ((jiffies - data->last_updated > 2 * HZ) || 576 if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
576 (jiffies < data->last_updated) || !data->valid) {
577 int i; 577 int i;
578 578
579 dev_dbg(&client->dev, "Starting fscpos update\n"); 579 dev_dbg(&client->dev, "Starting fscpos update\n");
diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c
index a13a504f5bfa..80ae8d30c2af 100644
--- a/drivers/hwmon/gl520sm.c
+++ b/drivers/hwmon/gl520sm.c
@@ -24,6 +24,7 @@
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/jiffies.h>
27#include <linux/i2c.h> 28#include <linux/i2c.h>
28#include <linux/i2c-sensor.h> 29#include <linux/i2c-sensor.h>
29#include <linux/i2c-vid.h> 30#include <linux/i2c-vid.h>
@@ -678,8 +679,7 @@ static struct gl520_data *gl520_update_device(struct device *dev)
678 679
679 down(&data->update_lock); 680 down(&data->update_lock);
680 681
681 if ((jiffies - data->last_updated > 2 * HZ) || 682 if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
682 (jiffies < data->last_updated) || !data->valid) {
683 683
684 dev_dbg(&client->dev, "Starting gl520sm update\n"); 684 dev_dbg(&client->dev, "Starting gl520sm update\n");
685 685
diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c
index bf553dcd97d6..3c159f1d49ee 100644
--- a/drivers/hwmon/max1619.c
+++ b/drivers/hwmon/max1619.c
@@ -363,7 +363,7 @@ static void __exit sensors_max1619_exit(void)
363 i2c_del_driver(&max1619_driver); 363 i2c_del_driver(&max1619_driver);
364} 364}
365 365
366MODULE_AUTHOR("Alexey Fisher <fishor@mail.ru> and" 366MODULE_AUTHOR("Alexey Fisher <fishor@mail.ru> and "
367 "Jean Delvare <khali@linux-fr.org>"); 367 "Jean Delvare <khali@linux-fr.org>");
368MODULE_DESCRIPTION("MAX1619 sensor driver"); 368MODULE_DESCRIPTION("MAX1619 sensor driver");
369MODULE_LICENSE("GPL"); 369MODULE_LICENSE("GPL");
diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c
index 876c68f3af31..fa4032d53b79 100644
--- a/drivers/hwmon/pc87360.c
+++ b/drivers/hwmon/pc87360.c
@@ -1043,7 +1043,7 @@ static void pc87360_init_client(struct i2c_client *client, int use_thermistors)
1043 if (init >= 2 && data->innr) { 1043 if (init >= 2 && data->innr) {
1044 reg = pc87360_read_value(data, LD_IN, NO_BANK, 1044 reg = pc87360_read_value(data, LD_IN, NO_BANK,
1045 PC87365_REG_IN_CONVRATE); 1045 PC87365_REG_IN_CONVRATE);
1046 dev_info(&client->dev, "VLM conversion set to" 1046 dev_info(&client->dev, "VLM conversion set to "
1047 "1s period, 160us delay\n"); 1047 "1s period, 160us delay\n");
1048 pc87360_write_value(data, LD_IN, NO_BANK, 1048 pc87360_write_value(data, LD_IN, NO_BANK,
1049 PC87365_REG_IN_CONVRATE, 1049 PC87365_REG_IN_CONVRATE,
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 0ab7e37f5b00..1ab41313ce51 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -137,7 +137,7 @@ static int i801_setup(struct pci_dev *dev)
137 pci_read_config_word(I801_dev, SMBBA, &i801_smba); 137 pci_read_config_word(I801_dev, SMBBA, &i801_smba);
138 i801_smba &= 0xfff0; 138 i801_smba &= 0xfff0;
139 if(i801_smba == 0) { 139 if(i801_smba == 0) {
140 dev_err(&dev->dev, "SMB base address uninitialized" 140 dev_err(&dev->dev, "SMB base address uninitialized "
141 "- upgrade BIOS or use force_addr=0xaddr\n"); 141 "- upgrade BIOS or use force_addr=0xaddr\n");
142 return -ENODEV; 142 return -ENODEV;
143 } 143 }
@@ -186,7 +186,7 @@ static int i801_transaction(void)
186 int result = 0; 186 int result = 0;
187 int timeout = 0; 187 int timeout = 0;
188 188
189 dev_dbg(&I801_dev->dev, "Transaction (pre): CNT=%02x, CMD=%02x," 189 dev_dbg(&I801_dev->dev, "Transaction (pre): CNT=%02x, CMD=%02x, "
190 "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), 190 "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT),
191 inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), 191 inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
192 inb_p(SMBHSTDAT1)); 192 inb_p(SMBHSTDAT1));
@@ -240,7 +240,7 @@ static int i801_transaction(void)
240 outb_p(inb(SMBHSTSTS), SMBHSTSTS); 240 outb_p(inb(SMBHSTSTS), SMBHSTSTS);
241 241
242 if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) { 242 if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) {
243 dev_dbg(&I801_dev->dev, "Failed reset at end of transaction" 243 dev_dbg(&I801_dev->dev, "Failed reset at end of transaction "
244 "(%02x)\n", temp); 244 "(%02x)\n", temp);
245 } 245 }
246 dev_dbg(&I801_dev->dev, "Transaction (post): CNT=%02x, CMD=%02x, " 246 dev_dbg(&I801_dev->dev, "Transaction (post): CNT=%02x, CMD=%02x, "
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 03c23ce98edb..9ad3e9262e8a 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -288,6 +288,100 @@ static struct i2c_adapter mpc_ops = {
288 .retries = 1 288 .retries = 1
289}; 289};
290 290
291static int fsl_i2c_probe(struct device *device)
292{
293 int result = 0;
294 struct mpc_i2c *i2c;
295 struct platform_device *pdev = to_platform_device(device);
296 struct fsl_i2c_platform_data *pdata;
297 struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
298
299 pdata = (struct fsl_i2c_platform_data *) pdev->dev.platform_data;
300
301 if (!(i2c = kmalloc(sizeof(*i2c), GFP_KERNEL))) {
302 return -ENOMEM;
303 }
304 memset(i2c, 0, sizeof(*i2c));
305
306 i2c->irq = platform_get_irq(pdev, 0);
307 i2c->flags = pdata->device_flags;
308 init_waitqueue_head(&i2c->queue);
309
310 i2c->base = ioremap((phys_addr_t)r->start, MPC_I2C_REGION);
311
312 if (!i2c->base) {
313 printk(KERN_ERR "i2c-mpc - failed to map controller\n");
314 result = -ENOMEM;
315 goto fail_map;
316 }
317
318 if (i2c->irq != 0)
319 if ((result = request_irq(i2c->irq, mpc_i2c_isr,
320 SA_SHIRQ, "i2c-mpc", i2c)) < 0) {
321 printk(KERN_ERR
322 "i2c-mpc - failed to attach interrupt\n");
323 goto fail_irq;
324 }
325
326 mpc_i2c_setclock(i2c);
327 dev_set_drvdata(device, i2c);
328
329 i2c->adap = mpc_ops;
330 i2c_set_adapdata(&i2c->adap, i2c);
331 i2c->adap.dev.parent = &pdev->dev;
332 if ((result = i2c_add_adapter(&i2c->adap)) < 0) {
333 printk(KERN_ERR "i2c-mpc - failed to add adapter\n");
334 goto fail_add;
335 }
336
337 return result;
338
339 fail_add:
340 if (i2c->irq != 0)
341 free_irq(i2c->irq, NULL);
342 fail_irq:
343 iounmap(i2c->base);
344 fail_map:
345 kfree(i2c);
346 return result;
347};
348
349static int fsl_i2c_remove(struct device *device)
350{
351 struct mpc_i2c *i2c = dev_get_drvdata(device);
352
353 i2c_del_adapter(&i2c->adap);
354 dev_set_drvdata(device, NULL);
355
356 if (i2c->irq != 0)
357 free_irq(i2c->irq, i2c);
358
359 iounmap(i2c->base);
360 kfree(i2c);
361 return 0;
362};
363
364/* Structure for a device driver */
365static struct device_driver fsl_i2c_driver = {
366 .name = "fsl-i2c",
367 .bus = &platform_bus_type,
368 .probe = fsl_i2c_probe,
369 .remove = fsl_i2c_remove,
370};
371
372static int __init fsl_i2c_init(void)
373{
374 return driver_register(&fsl_i2c_driver);
375}
376
377static void __exit fsl_i2c_exit(void)
378{
379 driver_unregister(&fsl_i2c_driver);
380}
381
382module_init(fsl_i2c_init);
383module_exit(fsl_i2c_exit);
384
291MODULE_AUTHOR("Adrian Cox <adrian@humboldt.co.uk>"); 385MODULE_AUTHOR("Adrian Cox <adrian@humboldt.co.uk>");
292MODULE_DESCRIPTION 386MODULE_DESCRIPTION
293 ("I2C-Bus adapter for MPC107 bridge and MPC824x/85xx/52xx processors"); 387 ("I2C-Bus adapter for MPC107 bridge and MPC824x/85xx/52xx processors");
diff --git a/drivers/i2c/chips/ds1337.c b/drivers/i2c/chips/ds1337.c
index 74ece8ac1c23..82cf959989fd 100644
--- a/drivers/i2c/chips/ds1337.c
+++ b/drivers/i2c/chips/ds1337.c
@@ -165,7 +165,7 @@ static int ds1337_set_datetime(struct i2c_client *client, struct rtc_time *dt)
165 buf[0] = 0; /* reg offset */ 165 buf[0] = 0; /* reg offset */
166 buf[1] = BIN2BCD(dt->tm_sec); 166 buf[1] = BIN2BCD(dt->tm_sec);
167 buf[2] = BIN2BCD(dt->tm_min); 167 buf[2] = BIN2BCD(dt->tm_min);
168 buf[3] = BIN2BCD(dt->tm_hour) | (1 << 6); 168 buf[3] = BIN2BCD(dt->tm_hour);
169 buf[4] = BIN2BCD(dt->tm_wday) + 1; 169 buf[4] = BIN2BCD(dt->tm_wday) + 1;
170 buf[5] = BIN2BCD(dt->tm_mday); 170 buf[5] = BIN2BCD(dt->tm_mday);
171 buf[6] = BIN2BCD(dt->tm_mon) + 1; 171 buf[6] = BIN2BCD(dt->tm_mon) + 1;
@@ -344,9 +344,9 @@ static void ds1337_init_client(struct i2c_client *client)
344 344
345 /* Ensure that device is set in 24-hour mode */ 345 /* Ensure that device is set in 24-hour mode */
346 val = i2c_smbus_read_byte_data(client, DS1337_REG_HOUR); 346 val = i2c_smbus_read_byte_data(client, DS1337_REG_HOUR);
347 if ((val >= 0) && (val & (1 << 6)) == 0) 347 if ((val >= 0) && (val & (1 << 6)))
348 i2c_smbus_write_byte_data(client, DS1337_REG_HOUR, 348 i2c_smbus_write_byte_data(client, DS1337_REG_HOUR,
349 val | (1 << 6)); 349 val & 0x3f);
350} 350}
351 351
352static int ds1337_detach_client(struct i2c_client *client) 352static int ds1337_detach_client(struct i2c_client *client)
diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c
index 6ea413f6d5e5..a2da31b0dd7b 100644
--- a/drivers/i2c/chips/eeprom.c
+++ b/drivers/i2c/chips/eeprom.c
@@ -163,6 +163,11 @@ int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
163 struct eeprom_data *data; 163 struct eeprom_data *data;
164 int err = 0; 164 int err = 0;
165 165
166 /* prevent 24RF08 corruption */
167 if (kind < 0)
168 i2c_smbus_xfer(adapter, address, 0, 0, 0,
169 I2C_SMBUS_QUICK, NULL);
170
166 /* There are three ways we can read the EEPROM data: 171 /* There are three ways we can read the EEPROM data:
167 (1) I2C block reads (faster, but unsupported by most adapters) 172 (1) I2C block reads (faster, but unsupported by most adapters)
168 (2) Consecutive byte reads (100% overhead) 173 (2) Consecutive byte reads (100% overhead)
@@ -187,9 +192,6 @@ int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
187 new_client->driver = &eeprom_driver; 192 new_client->driver = &eeprom_driver;
188 new_client->flags = 0; 193 new_client->flags = 0;
189 194
190 /* prevent 24RF08 corruption */
191 i2c_smbus_write_quick(new_client, 0);
192
193 /* Fill in the remaining client fields */ 195 /* Fill in the remaining client fields */
194 strlcpy(new_client->name, "eeprom", I2C_NAME_SIZE); 196 strlcpy(new_client->name, "eeprom", I2C_NAME_SIZE);
195 data->valid = 0; 197 data->valid = 0;
diff --git a/drivers/i2c/chips/max6875.c b/drivers/i2c/chips/max6875.c
index c4f14d9623c4..0230375f72e5 100644
--- a/drivers/i2c/chips/max6875.c
+++ b/drivers/i2c/chips/max6875.c
@@ -343,6 +343,11 @@ static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
343 struct max6875_data *data; 343 struct max6875_data *data;
344 int err = 0; 344 int err = 0;
345 345
346 /* Prevent 24RF08 corruption (in case of user error) */
347 if (kind < 0)
348 i2c_smbus_xfer(adapter, address, 0, 0, 0,
349 I2C_SMBUS_QUICK, NULL);
350
346 /* There are three ways we can read the EEPROM data: 351 /* There are three ways we can read the EEPROM data:
347 (1) I2C block reads (faster, but unsupported by most adapters) 352 (1) I2C block reads (faster, but unsupported by most adapters)
348 (2) Consecutive byte reads (100% overhead) 353 (2) Consecutive byte reads (100% overhead)
@@ -370,9 +375,6 @@ static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
370 new_client->driver = &max6875_driver; 375 new_client->driver = &max6875_driver;
371 new_client->flags = 0; 376 new_client->flags = 0;
372 377
373 /* Prevent 24RF08 corruption */
374 i2c_smbus_write_quick(new_client, 0);
375
376 /* Setup the user section */ 378 /* Setup the user section */
377 data->blocks[max6875_eeprom_user].type = max6875_eeprom_user; 379 data->blocks[max6875_eeprom_user].type = max6875_eeprom_user;
378 data->blocks[max6875_eeprom_user].slices = USER_EEPROM_SLICES; 380 data->blocks[max6875_eeprom_user].slices = USER_EEPROM_SLICES;
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 4fd4f52c8e9b..4a9ead277596 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -231,8 +231,8 @@ int i2c_del_adapter(struct i2c_adapter *adap)
231 if (driver->detach_adapter) 231 if (driver->detach_adapter)
232 if ((res = driver->detach_adapter(adap))) { 232 if ((res = driver->detach_adapter(adap))) {
233 dev_warn(&adap->dev, "can't detach adapter " 233 dev_warn(&adap->dev, "can't detach adapter "
234 "while detaching driver %s: driver not " 234 "while detaching driver %s: driver "
235 "detached!", driver->name); 235 "not detached!\n", driver->name);
236 goto out_unlock; 236 goto out_unlock;
237 } 237 }
238 } 238 }
@@ -456,8 +456,8 @@ int i2c_detach_client(struct i2c_client *client)
456 res = adapter->client_unregister(client); 456 res = adapter->client_unregister(client);
457 if (res) { 457 if (res) {
458 dev_err(&client->dev, 458 dev_err(&client->dev,
459 "client_unregister [%s] failed, " 459 "client_unregister [%s] failed, "
460 "client not detached", client->name); 460 "client not detached\n", client->name);
461 goto out; 461 goto out;
462 } 462 }
463 } 463 }
diff --git a/drivers/ide/cris/Makefile b/drivers/ide/cris/Makefile
index fdc294325d00..6176e8d6b2e6 100644
--- a/drivers/ide/cris/Makefile
+++ b/drivers/ide/cris/Makefile
@@ -1,3 +1,3 @@
1EXTRA_CFLAGS += -Idrivers/ide 1EXTRA_CFLAGS += -Idrivers/ide
2 2
3obj-$(CONFIG_ETRAX_ARCH_V10) += ide-v10.o 3obj-y += ide-cris.o
diff --git a/drivers/ide/cris/ide-cris.c b/drivers/ide/cris/ide-cris.c
new file mode 100644
index 000000000000..cd15e6260510
--- /dev/null
+++ b/drivers/ide/cris/ide-cris.c
@@ -0,0 +1,1107 @@
1/* $Id: cris-ide-driver.patch,v 1.1 2005/06/29 21:39:07 akpm Exp $
2 *
3 * Etrax specific IDE functions, like init and PIO-mode setting etc.
4 * Almost the entire ide.c is used for the rest of the Etrax ATA driver.
5 * Copyright (c) 2000-2005 Axis Communications AB
6 *
7 * Authors: Bjorn Wesen (initial version)
8 * Mikael Starvik (crisv32 port)
9 */
10
11/* Regarding DMA:
12 *
13 * There are two forms of DMA - "DMA handshaking" between the interface and the drive,
14 * and DMA between the memory and the interface. We can ALWAYS use the latter, since it's
15 * something built-in in the Etrax. However only some drives support the DMA-mode handshaking
16 * on the ATA-bus. The normal PC driver and Triton interface disables memory-if DMA when the
17 * device can't do DMA handshaking for some stupid reason. We don't need to do that.
18 */
19
20#undef REALLY_SLOW_IO /* most systems can safely undef this */
21
22#include <linux/config.h>
23#include <linux/types.h>
24#include <linux/kernel.h>
25#include <linux/timer.h>
26#include <linux/mm.h>
27#include <linux/interrupt.h>
28#include <linux/delay.h>
29#include <linux/blkdev.h>
30#include <linux/hdreg.h>
31#include <linux/ide.h>
32#include <linux/init.h>
33
34#include <asm/io.h>
35#include <asm/dma.h>
36
37/* number of DMA descriptors */
38#define MAX_DMA_DESCRS 64
39
40/* number of times to retry busy-flags when reading/writing IDE-registers
41 * this can't be too high because a hung harddisk might cause the watchdog
42 * to trigger (sometimes INB and OUTB are called with irq's disabled)
43 */
44
45#define IDE_REGISTER_TIMEOUT 300
46
47#define LOWDB(x)
48#define D(x)
49
50enum /* Transfer types */
51{
52 TYPE_PIO,
53 TYPE_DMA,
54 TYPE_UDMA
55};
56
57/* CRISv32 specifics */
58#ifdef CONFIG_ETRAX_ARCH_V32
59#include <asm/arch/hwregs/ata_defs.h>
60#include <asm/arch/hwregs/dma_defs.h>
61#include <asm/arch/hwregs/dma.h>
62#include <asm/arch/pinmux.h>
63
64#define ATA_UDMA2_CYC 2
65#define ATA_UDMA2_DVS 3
66#define ATA_UDMA1_CYC 2
67#define ATA_UDMA1_DVS 4
68#define ATA_UDMA0_CYC 4
69#define ATA_UDMA0_DVS 6
70#define ATA_DMA2_STROBE 7
71#define ATA_DMA2_HOLD 1
72#define ATA_DMA1_STROBE 8
73#define ATA_DMA1_HOLD 3
74#define ATA_DMA0_STROBE 25
75#define ATA_DMA0_HOLD 19
76#define ATA_PIO4_SETUP 3
77#define ATA_PIO4_STROBE 7
78#define ATA_PIO4_HOLD 1
79#define ATA_PIO3_SETUP 3
80#define ATA_PIO3_STROBE 9
81#define ATA_PIO3_HOLD 3
82#define ATA_PIO2_SETUP 3
83#define ATA_PIO2_STROBE 13
84#define ATA_PIO2_HOLD 5
85#define ATA_PIO1_SETUP 5
86#define ATA_PIO1_STROBE 23
87#define ATA_PIO1_HOLD 9
88#define ATA_PIO0_SETUP 9
89#define ATA_PIO0_STROBE 39
90#define ATA_PIO0_HOLD 9
91
92int
93cris_ide_ack_intr(ide_hwif_t* hwif)
94{
95 reg_ata_rw_ctrl2 ctrl2 = REG_TYPE_CONV(reg_ata_rw_ctrl2,
96 int, hwif->io_ports[0]);
97 REG_WR_INT(ata, regi_ata, rw_ack_intr, 1 << ctrl2.sel);
98 return 1;
99}
100
101static inline int
102cris_ide_busy(void)
103{
104 reg_ata_rs_stat_data stat_data;
105 stat_data = REG_RD(ata, regi_ata, rs_stat_data);
106 return stat_data.busy;
107}
108
109static inline int
110cris_ide_ready(void)
111{
112 return !cris_ide_busy();
113}
114
115static inline int
116cris_ide_data_available(unsigned short* data)
117{
118 reg_ata_rs_stat_data stat_data;
119 stat_data = REG_RD(ata, regi_ata, rs_stat_data);
120 *data = stat_data.data;
121 return stat_data.dav;
122}
123
124static void
125cris_ide_write_command(unsigned long command)
126{
127 REG_WR_INT(ata, regi_ata, rw_ctrl2, command); /* write data to the drive's register */
128}
129
130static void
131cris_ide_set_speed(int type, int setup, int strobe, int hold)
132{
133 reg_ata_rw_ctrl0 ctrl0 = REG_RD(ata, regi_ata, rw_ctrl0);
134 reg_ata_rw_ctrl1 ctrl1 = REG_RD(ata, regi_ata, rw_ctrl1);
135
136 if (type == TYPE_PIO) {
137 ctrl0.pio_setup = setup;
138 ctrl0.pio_strb = strobe;
139 ctrl0.pio_hold = hold;
140 } else if (type == TYPE_DMA) {
141 ctrl0.dma_strb = strobe;
142 ctrl0.dma_hold = hold;
143 } else if (type == TYPE_UDMA) {
144 ctrl1.udma_tcyc = setup;
145 ctrl1.udma_tdvs = strobe;
146 }
147 REG_WR(ata, regi_ata, rw_ctrl0, ctrl0);
148 REG_WR(ata, regi_ata, rw_ctrl1, ctrl1);
149}
150
151static unsigned long
152cris_ide_base_address(int bus)
153{
154 reg_ata_rw_ctrl2 ctrl2 = {0};
155 ctrl2.sel = bus;
156 return REG_TYPE_CONV(int, reg_ata_rw_ctrl2, ctrl2);
157}
158
159static unsigned long
160cris_ide_reg_addr(unsigned long addr, int cs0, int cs1)
161{
162 reg_ata_rw_ctrl2 ctrl2 = {0};
163 ctrl2.addr = addr;
164 ctrl2.cs1 = cs1;
165 ctrl2.cs0 = cs0;
166 return REG_TYPE_CONV(int, reg_ata_rw_ctrl2, ctrl2);
167}
168
169static __init void
170cris_ide_reset(unsigned val)
171{
172 reg_ata_rw_ctrl0 ctrl0 = {0};
173 ctrl0.rst = val ? regk_ata_active : regk_ata_inactive;
174 REG_WR(ata, regi_ata, rw_ctrl0, ctrl0);
175}
176
177static __init void
178cris_ide_init(void)
179{
180 reg_ata_rw_ctrl0 ctrl0 = {0};
181 reg_ata_rw_intr_mask intr_mask = {0};
182
183 ctrl0.en = regk_ata_yes;
184 REG_WR(ata, regi_ata, rw_ctrl0, ctrl0);
185
186 intr_mask.bus0 = regk_ata_yes;
187 intr_mask.bus1 = regk_ata_yes;
188 intr_mask.bus2 = regk_ata_yes;
189 intr_mask.bus3 = regk_ata_yes;
190
191 REG_WR(ata, regi_ata, rw_intr_mask, intr_mask);
192
193 crisv32_request_dma(2, "ETRAX FS built-in ATA", DMA_VERBOSE_ON_ERROR, 0, dma_ata);
194 crisv32_request_dma(3, "ETRAX FS built-in ATA", DMA_VERBOSE_ON_ERROR, 0, dma_ata);
195
196 crisv32_pinmux_alloc_fixed(pinmux_ata);
197 crisv32_pinmux_alloc_fixed(pinmux_ata0);
198 crisv32_pinmux_alloc_fixed(pinmux_ata1);
199 crisv32_pinmux_alloc_fixed(pinmux_ata2);
200 crisv32_pinmux_alloc_fixed(pinmux_ata3);
201
202 DMA_RESET(regi_dma2);
203 DMA_ENABLE(regi_dma2);
204 DMA_RESET(regi_dma3);
205 DMA_ENABLE(regi_dma3);
206
207 DMA_WR_CMD (regi_dma2, regk_dma_set_w_size2);
208 DMA_WR_CMD (regi_dma3, regk_dma_set_w_size2);
209}
210
211static dma_descr_context mycontext __attribute__ ((__aligned__(32)));
212
213#define cris_dma_descr_type dma_descr_data
214#define cris_pio_read regk_ata_rd
215#define cris_ultra_mask 0x7
216#define MAX_DESCR_SIZE 0xffffffffUL
217
218static unsigned long
219cris_ide_get_reg(unsigned long reg)
220{
221 return (reg & 0x0e000000) >> 25;
222}
223
224static void
225cris_ide_fill_descriptor(cris_dma_descr_type *d, void* buf, unsigned int len, int last)
226{
227 d->buf = (char*)virt_to_phys(buf);
228 d->after = d->buf + len;
229 d->eol = last;
230}
231
232static void
233cris_ide_start_dma(ide_drive_t *drive, cris_dma_descr_type *d, int dir,int type,int len)
234{
235 reg_ata_rw_ctrl2 ctrl2 = REG_TYPE_CONV(reg_ata_rw_ctrl2, int, IDE_DATA_REG);
236 reg_ata_rw_trf_cnt trf_cnt = {0};
237
238 mycontext.saved_data = (dma_descr_data*)virt_to_phys(d);
239 mycontext.saved_data_buf = d->buf;
240 /* start the dma channel */
241 DMA_START_CONTEXT(dir ? regi_dma3 : regi_dma2, virt_to_phys(&mycontext));
242
243 /* initiate a multi word dma read using PIO handshaking */
244 trf_cnt.cnt = len >> 1;
245 /* Due to a "feature" the transfer count has to be one extra word for UDMA. */
246 if (type == TYPE_UDMA)
247 trf_cnt.cnt++;
248 REG_WR(ata, regi_ata, rw_trf_cnt, trf_cnt);
249
250 ctrl2.rw = dir ? regk_ata_rd : regk_ata_wr;
251 ctrl2.trf_mode = regk_ata_dma;
252 ctrl2.hsh = type == TYPE_PIO ? regk_ata_pio :
253 type == TYPE_DMA ? regk_ata_dma : regk_ata_udma;
254 ctrl2.multi = regk_ata_yes;
255 ctrl2.dma_size = regk_ata_word;
256 REG_WR(ata, regi_ata, rw_ctrl2, ctrl2);
257}
258
259static void
260cris_ide_wait_dma(int dir)
261{
262 reg_dma_rw_stat status;
263 do
264 {
265 status = REG_RD(dma, dir ? regi_dma3 : regi_dma2, rw_stat);
266 } while(status.list_state != regk_dma_data_at_eol);
267}
268
269static int cris_dma_test_irq(ide_drive_t *drive)
270{
271 int intr = REG_RD_INT(ata, regi_ata, r_intr);
272 reg_ata_rw_ctrl2 ctrl2 = REG_TYPE_CONV(reg_ata_rw_ctrl2, int, IDE_DATA_REG);
273 return intr & (1 << ctrl2.sel) ? 1 : 0;
274}
275
276static void cris_ide_initialize_dma(int dir)
277{
278}
279
280#else
281/* CRISv10 specifics */
282#include <asm/arch/svinto.h>
283#include <asm/arch/io_interface_mux.h>
284
285/* PIO timing (in R_ATA_CONFIG)
286 *
287 * _____________________________
288 * ADDRESS : ________/
289 *
290 * _______________
291 * DIOR : ____________/ \__________
292 *
293 * _______________
294 * DATA : XXXXXXXXXXXXXXXX_______________XXXXXXXX
295 *
296 *
297 * DIOR is unbuffered while address and data is buffered.
298 * This creates two problems:
299 * 1. The DIOR pulse is to early (because it is unbuffered)
300 * 2. The rise time of DIOR is long
301 *
302 * There are at least three different plausible solutions
303 * 1. Use a pad capable of larger currents in Etrax
304 * 2. Use an external buffer
305 * 3. Make the strobe pulse longer
306 *
307 * Some of the strobe timings below are modified to compensate
308 * for this. This implies a slight performance decrease.
309 *
310 * THIS SHOULD NEVER BE CHANGED!
311 *
312 * TODO: Is this true for the latest LX boards still ?
313 */
314
315#define ATA_UDMA2_CYC 0 /* No UDMA supported, just to make it compile. */
316#define ATA_UDMA2_DVS 0
317#define ATA_UDMA1_CYC 0
318#define ATA_UDMA1_DVS 0
319#define ATA_UDMA0_CYC 0
320#define ATA_UDMA0_DVS 0
321#define ATA_DMA2_STROBE 4
322#define ATA_DMA2_HOLD 0
323#define ATA_DMA1_STROBE 4
324#define ATA_DMA1_HOLD 1
325#define ATA_DMA0_STROBE 12
326#define ATA_DMA0_HOLD 9
327#define ATA_PIO4_SETUP 1
328#define ATA_PIO4_STROBE 5
329#define ATA_PIO4_HOLD 0
330#define ATA_PIO3_SETUP 1
331#define ATA_PIO3_STROBE 5
332#define ATA_PIO3_HOLD 1
333#define ATA_PIO2_SETUP 1
334#define ATA_PIO2_STROBE 6
335#define ATA_PIO2_HOLD 2
336#define ATA_PIO1_SETUP 2
337#define ATA_PIO1_STROBE 11
338#define ATA_PIO1_HOLD 4
339#define ATA_PIO0_SETUP 4
340#define ATA_PIO0_STROBE 19
341#define ATA_PIO0_HOLD 4
342
343int
344cris_ide_ack_intr(ide_hwif_t* hwif)
345{
346 return 1;
347}
348
349static inline int
350cris_ide_busy(void)
351{
352 return *R_ATA_STATUS_DATA & IO_MASK(R_ATA_STATUS_DATA, busy) ;
353}
354
355static inline int
356cris_ide_ready(void)
357{
358 return *R_ATA_STATUS_DATA & IO_MASK(R_ATA_STATUS_DATA, tr_rdy) ;
359}
360
361static inline int
362cris_ide_data_available(unsigned short* data)
363{
364 unsigned long status = *R_ATA_STATUS_DATA;
365 *data = (unsigned short)status;
366 return status & IO_MASK(R_ATA_STATUS_DATA, dav);
367}
368
369static void
370cris_ide_write_command(unsigned long command)
371{
372 *R_ATA_CTRL_DATA = command;
373}
374
375static void
376cris_ide_set_speed(int type, int setup, int strobe, int hold)
377{
378 static int pio_setup = ATA_PIO4_SETUP;
379 static int pio_strobe = ATA_PIO4_STROBE;
380 static int pio_hold = ATA_PIO4_HOLD;
381 static int dma_strobe = ATA_DMA2_STROBE;
382 static int dma_hold = ATA_DMA2_HOLD;
383
384 if (type == TYPE_PIO) {
385 pio_setup = setup;
386 pio_strobe = strobe;
387 pio_hold = hold;
388 } else if (type == TYPE_DMA) {
389 dma_strobe = strobe;
390 dma_hold = hold;
391 }
392 *R_ATA_CONFIG = ( IO_FIELD( R_ATA_CONFIG, enable, 1 ) |
393 IO_FIELD( R_ATA_CONFIG, dma_strobe, dma_strobe ) |
394 IO_FIELD( R_ATA_CONFIG, dma_hold, dma_hold ) |
395 IO_FIELD( R_ATA_CONFIG, pio_setup, pio_setup ) |
396 IO_FIELD( R_ATA_CONFIG, pio_strobe, pio_strobe ) |
397 IO_FIELD( R_ATA_CONFIG, pio_hold, pio_hold ) );
398}
399
400static unsigned long
401cris_ide_base_address(int bus)
402{
403 return IO_FIELD(R_ATA_CTRL_DATA, sel, bus);
404}
405
406static unsigned long
407cris_ide_reg_addr(unsigned long addr, int cs0, int cs1)
408{
409 return IO_FIELD(R_ATA_CTRL_DATA, addr, addr) |
410 IO_FIELD(R_ATA_CTRL_DATA, cs0, cs0) |
411 IO_FIELD(R_ATA_CTRL_DATA, cs1, cs1);
412}
413
414static __init void
415cris_ide_reset(unsigned val)
416{
417#ifdef CONFIG_ETRAX_IDE_G27_RESET
418 REG_SHADOW_SET(R_PORT_G_DATA, port_g_data_shadow, 27, val);
419#endif
420#ifdef CONFIG_ETRAX_IDE_CSE1_16_RESET
421 REG_SHADOW_SET(port_cse1_addr, port_cse1_shadow, 16, val);
422#endif
423#ifdef CONFIG_ETRAX_IDE_CSP0_8_RESET
424 REG_SHADOW_SET(port_csp0_addr, port_csp0_shadow, 8, val);
425#endif
426#ifdef CONFIG_ETRAX_IDE_PB7_RESET
427 port_pb_dir_shadow = port_pb_dir_shadow |
428 IO_STATE(R_PORT_PB_DIR, dir7, output);
429 *R_PORT_PB_DIR = port_pb_dir_shadow;
430 REG_SHADOW_SET(R_PORT_PB_DATA, port_pb_data_shadow, 7, val);
431#endif
432}
433
434static __init void
435cris_ide_init(void)
436{
437 volatile unsigned int dummy;
438
439 *R_ATA_CTRL_DATA = 0;
440 *R_ATA_TRANSFER_CNT = 0;
441 *R_ATA_CONFIG = 0;
442
443 if (cris_request_io_interface(if_ata, "ETRAX100LX IDE")) {
444 printk(KERN_CRIT "ide: Failed to get IO interface\n");
445 return;
446 } else if (cris_request_dma(ATA_TX_DMA_NBR,
447 "ETRAX100LX IDE TX",
448 DMA_VERBOSE_ON_ERROR,
449 dma_ata)) {
450 cris_free_io_interface(if_ata);
451 printk(KERN_CRIT "ide: Failed to get Tx DMA channel\n");
452 return;
453 } else if (cris_request_dma(ATA_RX_DMA_NBR,
454 "ETRAX100LX IDE RX",
455 DMA_VERBOSE_ON_ERROR,
456 dma_ata)) {
457 cris_free_dma(ATA_TX_DMA_NBR, "ETRAX100LX IDE Tx");
458 cris_free_io_interface(if_ata);
459 printk(KERN_CRIT "ide: Failed to get Rx DMA channel\n");
460 return;
461 }
462
463 /* make a dummy read to set the ata controller in a proper state */
464 dummy = *R_ATA_STATUS_DATA;
465
466 *R_ATA_CONFIG = ( IO_FIELD( R_ATA_CONFIG, enable, 1 ));
467 *R_ATA_CTRL_DATA = ( IO_STATE( R_ATA_CTRL_DATA, rw, read) |
468 IO_FIELD( R_ATA_CTRL_DATA, addr, 1 ) );
469
470 while(*R_ATA_STATUS_DATA & IO_MASK(R_ATA_STATUS_DATA, busy)); /* wait for busy flag*/
471
472 *R_IRQ_MASK0_SET = ( IO_STATE( R_IRQ_MASK0_SET, ata_irq0, set ) |
473 IO_STATE( R_IRQ_MASK0_SET, ata_irq1, set ) |
474 IO_STATE( R_IRQ_MASK0_SET, ata_irq2, set ) |
475 IO_STATE( R_IRQ_MASK0_SET, ata_irq3, set ) );
476
477 /* reset the dma channels we will use */
478
479 RESET_DMA(ATA_TX_DMA_NBR);
480 RESET_DMA(ATA_RX_DMA_NBR);
481 WAIT_DMA(ATA_TX_DMA_NBR);
482 WAIT_DMA(ATA_RX_DMA_NBR);
483}
484
485#define cris_dma_descr_type etrax_dma_descr
486#define cris_pio_read IO_STATE(R_ATA_CTRL_DATA, rw, read)
487#define cris_ultra_mask 0x0
488#define MAX_DESCR_SIZE 0x10000UL
489
490static unsigned long
491cris_ide_get_reg(unsigned long reg)
492{
493 return (reg & 0x0e000000) >> 25;
494}
495
496static void
497cris_ide_fill_descriptor(cris_dma_descr_type *d, void* buf, unsigned int len, int last)
498{
499 d->buf = virt_to_phys(buf);
500 d->sw_len = len == MAX_DESCR_SIZE ? 0 : len;
501 if (last)
502 d->ctrl |= d_eol;
503}
504
505static void cris_ide_start_dma(ide_drive_t *drive, cris_dma_descr_type *d, int dir, int type, int len)
506{
507 unsigned long cmd;
508
509 if (dir) {
510 /* need to do this before RX DMA due to a chip bug
511 * it is enough to just flush the part of the cache that
512 * corresponds to the buffers we start, but since HD transfers
513 * usually are more than 8 kB, it is easier to optimize for the
514 * normal case and just flush the entire cache. its the only
515 * way to be sure! (OB movie quote)
516 */
517 flush_etrax_cache();
518 *R_DMA_CH3_FIRST = virt_to_phys(d);
519 *R_DMA_CH3_CMD = IO_STATE(R_DMA_CH3_CMD, cmd, start);
520
521 } else {
522 *R_DMA_CH2_FIRST = virt_to_phys(d);
523 *R_DMA_CH2_CMD = IO_STATE(R_DMA_CH2_CMD, cmd, start);
524 }
525
526 /* initiate a multi word dma read using DMA handshaking */
527
528 *R_ATA_TRANSFER_CNT =
529 IO_FIELD(R_ATA_TRANSFER_CNT, count, len >> 1);
530
531 cmd = dir ? IO_STATE(R_ATA_CTRL_DATA, rw, read) : IO_STATE(R_ATA_CTRL_DATA, rw, write);
532 cmd |= type == TYPE_PIO ? IO_STATE(R_ATA_CTRL_DATA, handsh, pio) :
533 IO_STATE(R_ATA_CTRL_DATA, handsh, dma);
534 *R_ATA_CTRL_DATA =
535 cmd |
536 IO_FIELD(R_ATA_CTRL_DATA, data, IDE_DATA_REG) |
537 IO_STATE(R_ATA_CTRL_DATA, src_dst, dma) |
538 IO_STATE(R_ATA_CTRL_DATA, multi, on) |
539 IO_STATE(R_ATA_CTRL_DATA, dma_size, word);
540}
541
542static void
543cris_ide_wait_dma(int dir)
544{
545 if (dir)
546 WAIT_DMA(ATA_RX_DMA_NBR);
547 else
548 WAIT_DMA(ATA_TX_DMA_NBR);
549}
550
551static int cris_dma_test_irq(ide_drive_t *drive)
552{
553 int intr = *R_IRQ_MASK0_RD;
554 int bus = IO_EXTRACT(R_ATA_CTRL_DATA, sel, IDE_DATA_REG);
555 return intr & (1 << (bus + IO_BITNR(R_IRQ_MASK0_RD, ata_irq0))) ? 1 : 0;
556}
557
558
559static void cris_ide_initialize_dma(int dir)
560{
561 if (dir)
562 {
563 RESET_DMA(ATA_RX_DMA_NBR); /* sometimes the DMA channel get stuck so we need to do this */
564 WAIT_DMA(ATA_RX_DMA_NBR);
565 }
566 else
567 {
568 RESET_DMA(ATA_TX_DMA_NBR); /* sometimes the DMA channel get stuck so we need to do this */
569 WAIT_DMA(ATA_TX_DMA_NBR);
570 }
571}
572
573#endif
574
575void
576cris_ide_outw(unsigned short data, unsigned long reg) {
577 int timeleft;
578
579 LOWDB(printk("ow: data 0x%x, reg 0x%x\n", data, reg));
580
581 /* note the lack of handling any timeouts. we stop waiting, but we don't
582 * really notify anybody.
583 */
584
585 timeleft = IDE_REGISTER_TIMEOUT;
586 /* wait for busy flag */
587 do {
588 timeleft--;
589 } while(timeleft && cris_ide_busy());
590
591 /*
592 * Fall through at a timeout, so the ongoing command will be
593 * aborted by the write below, which is expected to be a dummy
594 * command to the command register. This happens when a faulty
595 * drive times out on a command. See comment on timeout in
596 * INB.
597 */
598 if(!timeleft)
599 printk("ATA timeout reg 0x%lx := 0x%x\n", reg, data);
600
601 cris_ide_write_command(reg|data); /* write data to the drive's register */
602
603 timeleft = IDE_REGISTER_TIMEOUT;
604 /* wait for transmitter ready */
605 do {
606 timeleft--;
607 } while(timeleft && !cris_ide_ready());
608}
609
610void
611cris_ide_outb(unsigned char data, unsigned long reg)
612{
613 cris_ide_outw(data, reg);
614}
615
616void
617cris_ide_outbsync(ide_drive_t *drive, u8 addr, unsigned long port)
618{
619 cris_ide_outw(addr, port);
620}
621
622unsigned short
623cris_ide_inw(unsigned long reg) {
624 int timeleft;
625 unsigned short val;
626
627 timeleft = IDE_REGISTER_TIMEOUT;
628 /* wait for busy flag */
629 do {
630 timeleft--;
631 } while(timeleft && cris_ide_busy());
632
633 if(!timeleft) {
634 /*
635 * If we're asked to read the status register, like for
636 * example when a command does not complete for an
637 * extended time, but the ATA interface is stuck in a
638 * busy state at the *ETRAX* ATA interface level (as has
639 * happened repeatedly with at least one bad disk), then
640 * the best thing to do is to pretend that we read
641 * "busy" in the status register, so the IDE driver will
642 * time-out, abort the ongoing command and perform a
643 * reset sequence. Note that the subsequent OUT_BYTE
644 * call will also timeout on busy, but as long as the
645 * write is still performed, everything will be fine.
646 */
647 if (cris_ide_get_reg(reg) == IDE_STATUS_OFFSET)
648 return BUSY_STAT;
649 else
650 /* For other rare cases we assume 0 is good enough. */
651 return 0;
652 }
653
654 cris_ide_write_command(reg | cris_pio_read);
655
656 timeleft = IDE_REGISTER_TIMEOUT;
657 /* wait for available */
658 do {
659 timeleft--;
660 } while(timeleft && !cris_ide_data_available(&val));
661
662 if(!timeleft)
663 return 0;
664
665 LOWDB(printk("inb: 0x%x from reg 0x%x\n", val & 0xff, reg));
666
667 return val;
668}
669
670unsigned char
671cris_ide_inb(unsigned long reg)
672{
673 return (unsigned char)cris_ide_inw(reg);
674}
675
676static int cris_dma_check (ide_drive_t *drive);
677static int cris_dma_end (ide_drive_t *drive);
678static int cris_dma_setup (ide_drive_t *drive);
679static void cris_dma_exec_cmd (ide_drive_t *drive, u8 command);
680static int cris_dma_test_irq(ide_drive_t *drive);
681static void cris_dma_start(ide_drive_t *drive);
682static void cris_ide_input_data (ide_drive_t *drive, void *, unsigned int);
683static void cris_ide_output_data (ide_drive_t *drive, void *, unsigned int);
684static void cris_atapi_input_bytes(ide_drive_t *drive, void *, unsigned int);
685static void cris_atapi_output_bytes(ide_drive_t *drive, void *, unsigned int);
686static int cris_dma_off (ide_drive_t *drive);
687static int cris_dma_on (ide_drive_t *drive);
688
689static void tune_cris_ide(ide_drive_t *drive, u8 pio)
690{
691 int setup, strobe, hold;
692
693 switch(pio)
694 {
695 case 0:
696 setup = ATA_PIO0_SETUP;
697 strobe = ATA_PIO0_STROBE;
698 hold = ATA_PIO0_HOLD;
699 break;
700 case 1:
701 setup = ATA_PIO1_SETUP;
702 strobe = ATA_PIO1_STROBE;
703 hold = ATA_PIO1_HOLD;
704 break;
705 case 2:
706 setup = ATA_PIO2_SETUP;
707 strobe = ATA_PIO2_STROBE;
708 hold = ATA_PIO2_HOLD;
709 break;
710 case 3:
711 setup = ATA_PIO3_SETUP;
712 strobe = ATA_PIO3_STROBE;
713 hold = ATA_PIO3_HOLD;
714 break;
715 case 4:
716 setup = ATA_PIO4_SETUP;
717 strobe = ATA_PIO4_STROBE;
718 hold = ATA_PIO4_HOLD;
719 break;
720 default:
721 return;
722 }
723
724 cris_ide_set_speed(TYPE_PIO, setup, strobe, hold);
725}
726
727static int speed_cris_ide(ide_drive_t *drive, u8 speed)
728{
729 int cyc = 0, dvs = 0, strobe = 0, hold = 0;
730
731 if (speed >= XFER_PIO_0 && speed <= XFER_PIO_4) {
732 tune_cris_ide(drive, speed - XFER_PIO_0);
733 return 0;
734 }
735
736 switch(speed)
737 {
738 case XFER_UDMA_0:
739 cyc = ATA_UDMA0_CYC;
740 dvs = ATA_UDMA0_DVS;
741 break;
742 case XFER_UDMA_1:
743 cyc = ATA_UDMA1_CYC;
744 dvs = ATA_UDMA1_DVS;
745 break;
746 case XFER_UDMA_2:
747 cyc = ATA_UDMA2_CYC;
748 dvs = ATA_UDMA2_DVS;
749 break;
750 case XFER_MW_DMA_0:
751 strobe = ATA_DMA0_STROBE;
752 hold = ATA_DMA0_HOLD;
753 break;
754 case XFER_MW_DMA_1:
755 strobe = ATA_DMA1_STROBE;
756 hold = ATA_DMA1_HOLD;
757 break;
758 case XFER_MW_DMA_2:
759 strobe = ATA_DMA2_STROBE;
760 hold = ATA_DMA2_HOLD;
761 break;
762 default:
763 return 0;
764 }
765
766 if (speed >= XFER_UDMA_0)
767 cris_ide_set_speed(TYPE_UDMA, cyc, dvs, 0);
768 else
769 cris_ide_set_speed(TYPE_DMA, 0, strobe, hold);
770
771 return 0;
772}
773
774void __init
775init_e100_ide (void)
776{
777 hw_regs_t hw;
778 int ide_offsets[IDE_NR_PORTS];
779 int h;
780 int i;
781
782 printk("ide: ETRAX FS built-in ATA DMA controller\n");
783
784 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
785 ide_offsets[i] = cris_ide_reg_addr(i, 0, 1);
786
787 /* the IDE control register is at ATA address 6, with CS1 active instead of CS0 */
788 ide_offsets[IDE_CONTROL_OFFSET] = cris_ide_reg_addr(6, 1, 0);
789
790 /* first fill in some stuff in the ide_hwifs fields */
791
792 for(h = 0; h < MAX_HWIFS; h++) {
793 ide_hwif_t *hwif = &ide_hwifs[h];
794 ide_setup_ports(&hw, cris_ide_base_address(h),
795 ide_offsets,
796 0, 0, cris_ide_ack_intr,
797 ide_default_irq(0));
798 ide_register_hw(&hw, &hwif);
799 hwif->mmio = 2;
800 hwif->chipset = ide_etrax100;
801 hwif->tuneproc = &tune_cris_ide;
802 hwif->speedproc = &speed_cris_ide;
803 hwif->ata_input_data = &cris_ide_input_data;
804 hwif->ata_output_data = &cris_ide_output_data;
805 hwif->atapi_input_bytes = &cris_atapi_input_bytes;
806 hwif->atapi_output_bytes = &cris_atapi_output_bytes;
807 hwif->ide_dma_check = &cris_dma_check;
808 hwif->ide_dma_end = &cris_dma_end;
809 hwif->dma_setup = &cris_dma_setup;
810 hwif->dma_exec_cmd = &cris_dma_exec_cmd;
811 hwif->ide_dma_test_irq = &cris_dma_test_irq;
812 hwif->dma_start = &cris_dma_start;
813 hwif->OUTB = &cris_ide_outb;
814 hwif->OUTW = &cris_ide_outw;
815 hwif->OUTBSYNC = &cris_ide_outbsync;
816 hwif->INB = &cris_ide_inb;
817 hwif->INW = &cris_ide_inw;
818 hwif->ide_dma_host_off = &cris_dma_off;
819 hwif->ide_dma_host_on = &cris_dma_on;
820 hwif->ide_dma_off_quietly = &cris_dma_off;
821 hwif->udma_four = 0;
822 hwif->ultra_mask = cris_ultra_mask;
823 hwif->mwdma_mask = 0x07; /* Multiword DMA 0-2 */
824 hwif->swdma_mask = 0x07; /* Singleword DMA 0-2 */
825 }
826
827 /* Reset pulse */
828 cris_ide_reset(0);
829 udelay(25);
830 cris_ide_reset(1);
831
832 cris_ide_init();
833
834 cris_ide_set_speed(TYPE_PIO, ATA_PIO4_SETUP, ATA_PIO4_STROBE, ATA_PIO4_HOLD);
835 cris_ide_set_speed(TYPE_DMA, 0, ATA_DMA2_STROBE, ATA_DMA2_HOLD);
836 cris_ide_set_speed(TYPE_UDMA, ATA_UDMA2_CYC, ATA_UDMA2_DVS, 0);
837}
838
839static int cris_dma_off (ide_drive_t *drive)
840{
841 return 0;
842}
843
844static int cris_dma_on (ide_drive_t *drive)
845{
846 return 0;
847}
848
849
850static cris_dma_descr_type mydescr __attribute__ ((__aligned__(16)));
851
852/*
853 * The following routines are mainly used by the ATAPI drivers.
854 *
855 * These routines will round up any request for an odd number of bytes,
856 * so if an odd bytecount is specified, be sure that there's at least one
857 * extra byte allocated for the buffer.
858 */
859static void
860cris_atapi_input_bytes (ide_drive_t *drive, void *buffer, unsigned int bytecount)
861{
862 D(printk("atapi_input_bytes, buffer 0x%x, count %d\n",
863 buffer, bytecount));
864
865 if(bytecount & 1) {
866 printk("warning, odd bytecount in cdrom_in_bytes = %d.\n", bytecount);
867 bytecount++; /* to round off */
868 }
869
870 /* setup DMA and start transfer */
871
872 cris_ide_fill_descriptor(&mydescr, buffer, bytecount, 1);
873 cris_ide_start_dma(drive, &mydescr, 1, TYPE_PIO, bytecount);
874
875 /* wait for completion */
876 LED_DISK_READ(1);
877 cris_ide_wait_dma(1);
878 LED_DISK_READ(0);
879}
880
881static void
882cris_atapi_output_bytes (ide_drive_t *drive, void *buffer, unsigned int bytecount)
883{
884 D(printk("atapi_output_bytes, buffer 0x%x, count %d\n",
885 buffer, bytecount));
886
887 if(bytecount & 1) {
888 printk("odd bytecount %d in atapi_out_bytes!\n", bytecount);
889 bytecount++;
890 }
891
892 cris_ide_fill_descriptor(&mydescr, buffer, bytecount, 1);
893 cris_ide_start_dma(drive, &mydescr, 0, TYPE_PIO, bytecount);
894
895 /* wait for completion */
896
897 LED_DISK_WRITE(1);
898 LED_DISK_READ(1);
899 cris_ide_wait_dma(0);
900 LED_DISK_WRITE(0);
901}
902
903/*
904 * This is used for most PIO data transfers *from* the IDE interface
905 */
906static void
907cris_ide_input_data (ide_drive_t *drive, void *buffer, unsigned int wcount)
908{
909 cris_atapi_input_bytes(drive, buffer, wcount << 2);
910}
911
912/*
913 * This is used for most PIO data transfers *to* the IDE interface
914 */
915static void
916cris_ide_output_data (ide_drive_t *drive, void *buffer, unsigned int wcount)
917{
918 cris_atapi_output_bytes(drive, buffer, wcount << 2);
919}
920
921/* we only have one DMA channel on the chip for ATA, so we can keep these statically */
922static cris_dma_descr_type ata_descrs[MAX_DMA_DESCRS] __attribute__ ((__aligned__(16)));
923static unsigned int ata_tot_size;
924
925/*
926 * cris_ide_build_dmatable() prepares a dma request.
927 * Returns 0 if all went okay, returns 1 otherwise.
928 */
929static int cris_ide_build_dmatable (ide_drive_t *drive)
930{
931 ide_hwif_t *hwif = drive->hwif;
932 struct scatterlist* sg;
933 struct request *rq = drive->hwif->hwgroup->rq;
934 unsigned long size, addr;
935 unsigned int count = 0;
936 int i = 0;
937
938 sg = hwif->sg_table;
939
940 ata_tot_size = 0;
941
942 ide_map_sg(drive, rq);
943 i = hwif->sg_nents;
944
945 while(i) {
946 /*
947 * Determine addr and size of next buffer area. We assume that
948 * individual virtual buffers are always composed linearly in
949 * physical memory. For example, we assume that any 8kB buffer
950 * is always composed of two adjacent physical 4kB pages rather
951 * than two possibly non-adjacent physical 4kB pages.
952 */
953 /* group sequential buffers into one large buffer */
954 addr = page_to_phys(sg->page) + sg->offset;
955 size = sg_dma_len(sg);
956 while (sg++, --i) {
957 if ((addr + size) != page_to_phys(sg->page) + sg->offset)
958 break;
959 size += sg_dma_len(sg);
960 }
961
962 /* did we run out of descriptors? */
963
964 if(count >= MAX_DMA_DESCRS) {
965 printk("%s: too few DMA descriptors\n", drive->name);
966 return 1;
967 }
968
969 /* however, this case is more difficult - rw_trf_cnt cannot be more
970 than 65536 words per transfer, so in that case we need to either
971 1) use a DMA interrupt to re-trigger rw_trf_cnt and continue with
972 the descriptors, or
973 2) simply do the request here, and get dma_intr to only ide_end_request on
974 those blocks that were actually set-up for transfer.
975 */
976
977 if(ata_tot_size + size > 131072) {
978 printk("too large total ATA DMA request, %d + %d!\n", ata_tot_size, (int)size);
979 return 1;
980 }
981
982 /* If size > MAX_DESCR_SIZE it has to be splitted into new descriptors. Since we
983 don't handle size > 131072 only one split is necessary */
984
985 if(size > MAX_DESCR_SIZE) {
986 cris_ide_fill_descriptor(&ata_descrs[count], (void*)addr, MAX_DESCR_SIZE, 0);
987 count++;
988 ata_tot_size += MAX_DESCR_SIZE;
989 size -= MAX_DESCR_SIZE;
990 addr += MAX_DESCR_SIZE;
991 }
992
993 cris_ide_fill_descriptor(&ata_descrs[count], (void*)addr, size,i ? 0 : 1);
994 count++;
995 ata_tot_size += size;
996 }
997
998 if (count) {
999 /* return and say all is ok */
1000 return 0;
1001 }
1002
1003 printk("%s: empty DMA table?\n", drive->name);
1004 return 1; /* let the PIO routines handle this weirdness */
1005}
1006
1007static int cris_config_drive_for_dma (ide_drive_t *drive)
1008{
1009 u8 speed = ide_dma_speed(drive, 1);
1010
1011 if (!speed)
1012 return 0;
1013
1014 speed_cris_ide(drive, speed);
1015 ide_config_drive_speed(drive, speed);
1016
1017 return ide_dma_enable(drive);
1018}
1019
1020/*
1021 * cris_dma_intr() is the handler for disk read/write DMA interrupts
1022 */
1023static ide_startstop_t cris_dma_intr (ide_drive_t *drive)
1024{
1025 LED_DISK_READ(0);
1026 LED_DISK_WRITE(0);
1027
1028 return ide_dma_intr(drive);
1029}
1030
1031/*
1032 * Functions below initiates/aborts DMA read/write operations on a drive.
1033 *
1034 * The caller is assumed to have selected the drive and programmed the drive's
1035 * sector address using CHS or LBA. All that remains is to prepare for DMA
1036 * and then issue the actual read/write DMA/PIO command to the drive.
1037 *
1038 * For ATAPI devices, we just prepare for DMA and return. The caller should
1039 * then issue the packet command to the drive and call us again with
1040 * cris_dma_start afterwards.
1041 *
1042 * Returns 0 if all went well.
1043 * Returns 1 if DMA read/write could not be started, in which case
1044 * the caller should revert to PIO for the current request.
1045 */
1046
1047static int cris_dma_check(ide_drive_t *drive)
1048{
1049 ide_hwif_t *hwif = drive->hwif;
1050 struct hd_driveid* id = drive->id;
1051
1052 if (id && (id->capability & 1)) {
1053 if (ide_use_dma(drive)) {
1054 if (cris_config_drive_for_dma(drive))
1055 return hwif->ide_dma_on(drive);
1056 }
1057 }
1058
1059 return hwif->ide_dma_off_quietly(drive);
1060}
1061
1062static int cris_dma_end(ide_drive_t *drive)
1063{
1064 drive->waiting_for_dma = 0;
1065 return 0;
1066}
1067
1068static int cris_dma_setup(ide_drive_t *drive)
1069{
1070 struct request *rq = drive->hwif->hwgroup->rq;
1071
1072 cris_ide_initialize_dma(!rq_data_dir(rq));
1073 if (cris_ide_build_dmatable (drive)) {
1074 ide_map_sg(drive, rq);
1075 return 1;
1076 }
1077
1078 drive->waiting_for_dma = 1;
1079 return 0;
1080}
1081
1082static void cris_dma_exec_cmd(ide_drive_t *drive, u8 command)
1083{
1084 /* set the irq handler which will finish the request when DMA is done */
1085 ide_set_handler(drive, &cris_dma_intr, WAIT_CMD, NULL);
1086
1087 /* issue cmd to drive */
1088 cris_ide_outb(command, IDE_COMMAND_REG);
1089}
1090
1091static void cris_dma_start(ide_drive_t *drive)
1092{
1093 struct request *rq = drive->hwif->hwgroup->rq;
1094 int writing = rq_data_dir(rq);
1095 int type = TYPE_DMA;
1096
1097 if (drive->current_speed >= XFER_UDMA_0)
1098 type = TYPE_UDMA;
1099
1100 cris_ide_start_dma(drive, &ata_descrs[0], writing ? 0 : 1, type, ata_tot_size);
1101
1102 if (writing) {
1103 LED_DISK_WRITE(1);
1104 } else {
1105 LED_DISK_READ(1);
1106 }
1107}
diff --git a/drivers/ide/cris/ide-v10.c b/drivers/ide/cris/ide-v10.c
deleted file mode 100644
index 5b40220d3ddc..000000000000
--- a/drivers/ide/cris/ide-v10.c
+++ /dev/null
@@ -1,842 +0,0 @@
1/* $Id: ide.c,v 1.4 2004/10/12 07:55:48 starvik Exp $
2 *
3 * Etrax specific IDE functions, like init and PIO-mode setting etc.
4 * Almost the entire ide.c is used for the rest of the Etrax ATA driver.
5 * Copyright (c) 2000-2004 Axis Communications AB
6 *
7 * Authors: Bjorn Wesen (initial version)
8 * Mikael Starvik (pio setup stuff, Linux 2.6 port)
9 */
10
11/* Regarding DMA:
12 *
13 * There are two forms of DMA - "DMA handshaking" between the interface and the drive,
14 * and DMA between the memory and the interface. We can ALWAYS use the latter, since it's
15 * something built-in in the Etrax. However only some drives support the DMA-mode handshaking
16 * on the ATA-bus. The normal PC driver and Triton interface disables memory-if DMA when the
17 * device can't do DMA handshaking for some stupid reason. We don't need to do that.
18 */
19
20#undef REALLY_SLOW_IO /* most systems can safely undef this */
21
22#include <linux/config.h>
23#include <linux/types.h>
24#include <linux/kernel.h>
25#include <linux/timer.h>
26#include <linux/mm.h>
27#include <linux/interrupt.h>
28#include <linux/delay.h>
29#include <linux/blkdev.h>
30#include <linux/hdreg.h>
31#include <linux/ide.h>
32#include <linux/init.h>
33#include <linux/scatterlist.h>
34
35#include <asm/io.h>
36#include <asm/arch/svinto.h>
37#include <asm/dma.h>
38
39/* number of Etrax DMA descriptors */
40#define MAX_DMA_DESCRS 64
41
42/* number of times to retry busy-flags when reading/writing IDE-registers
43 * this can't be too high because a hung harddisk might cause the watchdog
44 * to trigger (sometimes INB and OUTB are called with irq's disabled)
45 */
46
47#define IDE_REGISTER_TIMEOUT 300
48
49static int e100_read_command = 0;
50
51#define LOWDB(x)
52#define D(x)
53
54static int e100_ide_build_dmatable (ide_drive_t *drive);
55static ide_startstop_t etrax_dma_intr (ide_drive_t *drive);
56
57void
58etrax100_ide_outw(unsigned short data, unsigned long reg) {
59 int timeleft;
60 LOWDB(printk("ow: data 0x%x, reg 0x%x\n", data, reg));
61
62 /* note the lack of handling any timeouts. we stop waiting, but we don't
63 * really notify anybody.
64 */
65
66 timeleft = IDE_REGISTER_TIMEOUT;
67 /* wait for busy flag */
68 while(timeleft && (*R_ATA_STATUS_DATA & IO_MASK(R_ATA_STATUS_DATA, busy)))
69 timeleft--;
70
71 /*
72 * Fall through at a timeout, so the ongoing command will be
73 * aborted by the write below, which is expected to be a dummy
74 * command to the command register. This happens when a faulty
75 * drive times out on a command. See comment on timeout in
76 * INB.
77 */
78 if(!timeleft)
79 printk("ATA timeout reg 0x%lx := 0x%x\n", reg, data);
80
81 *R_ATA_CTRL_DATA = reg | data; /* write data to the drive's register */
82
83 timeleft = IDE_REGISTER_TIMEOUT;
84 /* wait for transmitter ready */
85 while(timeleft && !(*R_ATA_STATUS_DATA &
86 IO_MASK(R_ATA_STATUS_DATA, tr_rdy)))
87 timeleft--;
88}
89
90void
91etrax100_ide_outb(unsigned char data, unsigned long reg)
92{
93 etrax100_ide_outw(data, reg);
94}
95
96void
97etrax100_ide_outbsync(ide_drive_t *drive, u8 addr, unsigned long port)
98{
99 etrax100_ide_outw(addr, port);
100}
101
102unsigned short
103etrax100_ide_inw(unsigned long reg) {
104 int status;
105 int timeleft;
106
107 timeleft = IDE_REGISTER_TIMEOUT;
108 /* wait for busy flag */
109 while(timeleft && (*R_ATA_STATUS_DATA & IO_MASK(R_ATA_STATUS_DATA, busy)))
110 timeleft--;
111
112 if(!timeleft) {
113 /*
114 * If we're asked to read the status register, like for
115 * example when a command does not complete for an
116 * extended time, but the ATA interface is stuck in a
117 * busy state at the *ETRAX* ATA interface level (as has
118 * happened repeatedly with at least one bad disk), then
119 * the best thing to do is to pretend that we read
120 * "busy" in the status register, so the IDE driver will
121 * time-out, abort the ongoing command and perform a
122 * reset sequence. Note that the subsequent OUT_BYTE
123 * call will also timeout on busy, but as long as the
124 * write is still performed, everything will be fine.
125 */
126 if ((reg & IO_MASK (R_ATA_CTRL_DATA, addr))
127 == IO_FIELD (R_ATA_CTRL_DATA, addr, IDE_STATUS_OFFSET))
128 return BUSY_STAT;
129 else
130 /* For other rare cases we assume 0 is good enough. */
131 return 0;
132 }
133
134 *R_ATA_CTRL_DATA = reg | IO_STATE(R_ATA_CTRL_DATA, rw, read); /* read data */
135
136 timeleft = IDE_REGISTER_TIMEOUT;
137 /* wait for available */
138 while(timeleft && !((status = *R_ATA_STATUS_DATA) &
139 IO_MASK(R_ATA_STATUS_DATA, dav)))
140 timeleft--;
141
142 if(!timeleft)
143 return 0;
144
145 LOWDB(printk("inb: 0x%x from reg 0x%x\n", status & 0xff, reg));
146
147 return (unsigned short)status;
148}
149
150unsigned char
151etrax100_ide_inb(unsigned long reg)
152{
153 return (unsigned char)etrax100_ide_inw(reg);
154}
155
156/* PIO timing (in R_ATA_CONFIG)
157 *
158 * _____________________________
159 * ADDRESS : ________/
160 *
161 * _______________
162 * DIOR : ____________/ \__________
163 *
164 * _______________
165 * DATA : XXXXXXXXXXXXXXXX_______________XXXXXXXX
166 *
167 *
168 * DIOR is unbuffered while address and data is buffered.
169 * This creates two problems:
170 * 1. The DIOR pulse is to early (because it is unbuffered)
171 * 2. The rise time of DIOR is long
172 *
173 * There are at least three different plausible solutions
174 * 1. Use a pad capable of larger currents in Etrax
175 * 2. Use an external buffer
176 * 3. Make the strobe pulse longer
177 *
178 * Some of the strobe timings below are modified to compensate
179 * for this. This implies a slight performance decrease.
180 *
181 * THIS SHOULD NEVER BE CHANGED!
182 *
183 * TODO: Is this true for the latest LX boards still ?
184 */
185
186#define ATA_DMA2_STROBE 4
187#define ATA_DMA2_HOLD 0
188#define ATA_DMA1_STROBE 4
189#define ATA_DMA1_HOLD 1
190#define ATA_DMA0_STROBE 12
191#define ATA_DMA0_HOLD 9
192#define ATA_PIO4_SETUP 1
193#define ATA_PIO4_STROBE 5
194#define ATA_PIO4_HOLD 0
195#define ATA_PIO3_SETUP 1
196#define ATA_PIO3_STROBE 5
197#define ATA_PIO3_HOLD 1
198#define ATA_PIO2_SETUP 1
199#define ATA_PIO2_STROBE 6
200#define ATA_PIO2_HOLD 2
201#define ATA_PIO1_SETUP 2
202#define ATA_PIO1_STROBE 11
203#define ATA_PIO1_HOLD 4
204#define ATA_PIO0_SETUP 4
205#define ATA_PIO0_STROBE 19
206#define ATA_PIO0_HOLD 4
207
208static int e100_dma_check (ide_drive_t *drive);
209static void e100_dma_start(ide_drive_t *drive);
210static int e100_dma_end (ide_drive_t *drive);
211static void e100_ide_input_data (ide_drive_t *drive, void *, unsigned int);
212static void e100_ide_output_data (ide_drive_t *drive, void *, unsigned int);
213static void e100_atapi_input_bytes(ide_drive_t *drive, void *, unsigned int);
214static void e100_atapi_output_bytes(ide_drive_t *drive, void *, unsigned int);
215static int e100_dma_off (ide_drive_t *drive);
216
217
218/*
219 * good_dma_drives() lists the model names (from "hdparm -i")
220 * of drives which do not support mword2 DMA but which are
221 * known to work fine with this interface under Linux.
222 */
223
224const char *good_dma_drives[] = {"Micropolis 2112A",
225 "CONNER CTMA 4000",
226 "CONNER CTT8000-A",
227 NULL};
228
229static void tune_e100_ide(ide_drive_t *drive, byte pio)
230{
231 pio = 4;
232 /* pio = ide_get_best_pio_mode(drive, pio, 4, NULL); */
233
234 /* set pio mode! */
235
236 switch(pio) {
237 case 0:
238 *R_ATA_CONFIG = ( IO_FIELD( R_ATA_CONFIG, enable, 1 ) |
239 IO_FIELD( R_ATA_CONFIG, dma_strobe, ATA_DMA2_STROBE ) |
240 IO_FIELD( R_ATA_CONFIG, dma_hold, ATA_DMA2_HOLD ) |
241 IO_FIELD( R_ATA_CONFIG, pio_setup, ATA_PIO0_SETUP ) |
242 IO_FIELD( R_ATA_CONFIG, pio_strobe, ATA_PIO0_STROBE ) |
243 IO_FIELD( R_ATA_CONFIG, pio_hold, ATA_PIO0_HOLD ) );
244 break;
245 case 1:
246 *R_ATA_CONFIG = ( IO_FIELD( R_ATA_CONFIG, enable, 1 ) |
247 IO_FIELD( R_ATA_CONFIG, dma_strobe, ATA_DMA2_STROBE ) |
248 IO_FIELD( R_ATA_CONFIG, dma_hold, ATA_DMA2_HOLD ) |
249 IO_FIELD( R_ATA_CONFIG, pio_setup, ATA_PIO1_SETUP ) |
250 IO_FIELD( R_ATA_CONFIG, pio_strobe, ATA_PIO1_STROBE ) |
251 IO_FIELD( R_ATA_CONFIG, pio_hold, ATA_PIO1_HOLD ) );
252 break;
253 case 2:
254 *R_ATA_CONFIG = ( IO_FIELD( R_ATA_CONFIG, enable, 1 ) |
255 IO_FIELD( R_ATA_CONFIG, dma_strobe, ATA_DMA2_STROBE ) |
256 IO_FIELD( R_ATA_CONFIG, dma_hold, ATA_DMA2_HOLD ) |
257 IO_FIELD( R_ATA_CONFIG, pio_setup, ATA_PIO2_SETUP ) |
258 IO_FIELD( R_ATA_CONFIG, pio_strobe, ATA_PIO2_STROBE ) |
259 IO_FIELD( R_ATA_CONFIG, pio_hold, ATA_PIO2_HOLD ) );
260 break;
261 case 3:
262 *R_ATA_CONFIG = ( IO_FIELD( R_ATA_CONFIG, enable, 1 ) |
263 IO_FIELD( R_ATA_CONFIG, dma_strobe, ATA_DMA2_STROBE ) |
264 IO_FIELD( R_ATA_CONFIG, dma_hold, ATA_DMA2_HOLD ) |
265 IO_FIELD( R_ATA_CONFIG, pio_setup, ATA_PIO3_SETUP ) |
266 IO_FIELD( R_ATA_CONFIG, pio_strobe, ATA_PIO3_STROBE ) |
267 IO_FIELD( R_ATA_CONFIG, pio_hold, ATA_PIO3_HOLD ) );
268 break;
269 case 4:
270 *R_ATA_CONFIG = ( IO_FIELD( R_ATA_CONFIG, enable, 1 ) |
271 IO_FIELD( R_ATA_CONFIG, dma_strobe, ATA_DMA2_STROBE ) |
272 IO_FIELD( R_ATA_CONFIG, dma_hold, ATA_DMA2_HOLD ) |
273 IO_FIELD( R_ATA_CONFIG, pio_setup, ATA_PIO4_SETUP ) |
274 IO_FIELD( R_ATA_CONFIG, pio_strobe, ATA_PIO4_STROBE ) |
275 IO_FIELD( R_ATA_CONFIG, pio_hold, ATA_PIO4_HOLD ) );
276 break;
277 }
278}
279
280static int e100_dma_setup(ide_drive_t *drive)
281{
282 struct request *rq = drive->hwif->hwgroup->rq;
283
284 if (rq_data_dir(rq)) {
285 e100_read_command = 0;
286
287 RESET_DMA(ATA_TX_DMA_NBR); /* sometimes the DMA channel get stuck so we need to do this */
288 WAIT_DMA(ATA_TX_DMA_NBR);
289 } else {
290 e100_read_command = 1;
291
292 RESET_DMA(ATA_RX_DMA_NBR); /* sometimes the DMA channel get stuck so we need to do this */
293 WAIT_DMA(ATA_RX_DMA_NBR);
294 }
295
296 /* set up the Etrax DMA descriptors */
297 if (e100_ide_build_dmatable(drive)) {
298 ide_map_sg(drive, rq);
299 return 1;
300 }
301
302 return 0;
303}
304
305static void e100_dma_exec_cmd(ide_drive_t *drive, u8 command)
306{
307 /* set the irq handler which will finish the request when DMA is done */
308 ide_set_handler(drive, &etrax_dma_intr, WAIT_CMD, NULL);
309
310 /* issue cmd to drive */
311 etrax100_ide_outb(command, IDE_COMMAND_REG);
312}
313
314void __init
315init_e100_ide (void)
316{
317 volatile unsigned int dummy;
318 int h;
319
320 printk("ide: ETRAX 100LX built-in ATA DMA controller\n");
321
322 /* first fill in some stuff in the ide_hwifs fields */
323
324 for(h = 0; h < MAX_HWIFS; h++) {
325 ide_hwif_t *hwif = &ide_hwifs[h];
326 hwif->mmio = 2;
327 hwif->chipset = ide_etrax100;
328 hwif->tuneproc = &tune_e100_ide;
329 hwif->ata_input_data = &e100_ide_input_data;
330 hwif->ata_output_data = &e100_ide_output_data;
331 hwif->atapi_input_bytes = &e100_atapi_input_bytes;
332 hwif->atapi_output_bytes = &e100_atapi_output_bytes;
333 hwif->ide_dma_check = &e100_dma_check;
334 hwif->ide_dma_end = &e100_dma_end;
335 hwif->dma_setup = &e100_dma_setup;
336 hwif->dma_exec_cmd = &e100_dma_exec_cmd;
337 hwif->dma_start = &e100_dma_start;
338 hwif->OUTB = &etrax100_ide_outb;
339 hwif->OUTW = &etrax100_ide_outw;
340 hwif->OUTBSYNC = &etrax100_ide_outbsync;
341 hwif->INB = &etrax100_ide_inb;
342 hwif->INW = &etrax100_ide_inw;
343 hwif->ide_dma_off_quietly = &e100_dma_off;
344 }
345
346 /* actually reset and configure the etrax100 ide/ata interface */
347
348 *R_ATA_CTRL_DATA = 0;
349 *R_ATA_TRANSFER_CNT = 0;
350 *R_ATA_CONFIG = 0;
351
352 genconfig_shadow = (genconfig_shadow &
353 ~IO_MASK(R_GEN_CONFIG, dma2) &
354 ~IO_MASK(R_GEN_CONFIG, dma3) &
355 ~IO_MASK(R_GEN_CONFIG, ata)) |
356 ( IO_STATE( R_GEN_CONFIG, dma3, ata ) |
357 IO_STATE( R_GEN_CONFIG, dma2, ata ) |
358 IO_STATE( R_GEN_CONFIG, ata, select ) );
359
360 *R_GEN_CONFIG = genconfig_shadow;
361
362 /* pull the chosen /reset-line low */
363
364#ifdef CONFIG_ETRAX_IDE_G27_RESET
365 REG_SHADOW_SET(R_PORT_G_DATA, port_g_data_shadow, 27, 0);
366#endif
367#ifdef CONFIG_ETRAX_IDE_CSE1_16_RESET
368 REG_SHADOW_SET(port_cse1_addr, port_cse1_shadow, 16, 0);
369#endif
370#ifdef CONFIG_ETRAX_IDE_CSP0_8_RESET
371 REG_SHADOW_SET(port_csp0_addr, port_csp0_shadow, 8, 0);
372#endif
373#ifdef CONFIG_ETRAX_IDE_PB7_RESET
374 port_pb_dir_shadow = port_pb_dir_shadow |
375 IO_STATE(R_PORT_PB_DIR, dir7, output);
376 *R_PORT_PB_DIR = port_pb_dir_shadow;
377 REG_SHADOW_SET(R_PORT_PB_DATA, port_pb_data_shadow, 7, 1);
378#endif
379
380 /* wait some */
381
382 udelay(25);
383
384 /* de-assert bus-reset */
385
386#ifdef CONFIG_ETRAX_IDE_CSE1_16_RESET
387 REG_SHADOW_SET(port_cse1_addr, port_cse1_shadow, 16, 1);
388#endif
389#ifdef CONFIG_ETRAX_IDE_CSP0_8_RESET
390 REG_SHADOW_SET(port_csp0_addr, port_csp0_shadow, 8, 1);
391#endif
392#ifdef CONFIG_ETRAX_IDE_G27_RESET
393 REG_SHADOW_SET(R_PORT_G_DATA, port_g_data_shadow, 27, 1);
394#endif
395
396 /* make a dummy read to set the ata controller in a proper state */
397 dummy = *R_ATA_STATUS_DATA;
398
399 *R_ATA_CONFIG = ( IO_FIELD( R_ATA_CONFIG, enable, 1 ) |
400 IO_FIELD( R_ATA_CONFIG, dma_strobe, ATA_DMA2_STROBE ) |
401 IO_FIELD( R_ATA_CONFIG, dma_hold, ATA_DMA2_HOLD ) |
402 IO_FIELD( R_ATA_CONFIG, pio_setup, ATA_PIO4_SETUP ) |
403 IO_FIELD( R_ATA_CONFIG, pio_strobe, ATA_PIO4_STROBE ) |
404 IO_FIELD( R_ATA_CONFIG, pio_hold, ATA_PIO4_HOLD ) );
405
406 *R_ATA_CTRL_DATA = ( IO_STATE( R_ATA_CTRL_DATA, rw, read) |
407 IO_FIELD( R_ATA_CTRL_DATA, addr, 1 ) );
408
409 while(*R_ATA_STATUS_DATA & IO_MASK(R_ATA_STATUS_DATA, busy)); /* wait for busy flag*/
410
411 *R_IRQ_MASK0_SET = ( IO_STATE( R_IRQ_MASK0_SET, ata_irq0, set ) |
412 IO_STATE( R_IRQ_MASK0_SET, ata_irq1, set ) |
413 IO_STATE( R_IRQ_MASK0_SET, ata_irq2, set ) |
414 IO_STATE( R_IRQ_MASK0_SET, ata_irq3, set ) );
415
416 printk("ide: waiting %d seconds for drives to regain consciousness\n",
417 CONFIG_ETRAX_IDE_DELAY);
418
419 h = jiffies + (CONFIG_ETRAX_IDE_DELAY * HZ);
420 while(time_before(jiffies, h)) /* nothing */ ;
421
422 /* reset the dma channels we will use */
423
424 RESET_DMA(ATA_TX_DMA_NBR);
425 RESET_DMA(ATA_RX_DMA_NBR);
426 WAIT_DMA(ATA_TX_DMA_NBR);
427 WAIT_DMA(ATA_RX_DMA_NBR);
428
429}
430
431static int e100_dma_off (ide_drive_t *drive)
432{
433 return 0;
434}
435
436static etrax_dma_descr mydescr;
437
438/*
439 * The following routines are mainly used by the ATAPI drivers.
440 *
441 * These routines will round up any request for an odd number of bytes,
442 * so if an odd bytecount is specified, be sure that there's at least one
443 * extra byte allocated for the buffer.
444 */
445static void
446e100_atapi_input_bytes (ide_drive_t *drive, void *buffer, unsigned int bytecount)
447{
448 unsigned long data_reg = IDE_DATA_REG;
449
450 D(printk("atapi_input_bytes, dreg 0x%x, buffer 0x%x, count %d\n",
451 data_reg, buffer, bytecount));
452
453 if(bytecount & 1) {
454 printk("warning, odd bytecount in cdrom_in_bytes = %d.\n", bytecount);
455 bytecount++; /* to round off */
456 }
457
458 /* make sure the DMA channel is available */
459 RESET_DMA(ATA_RX_DMA_NBR);
460 WAIT_DMA(ATA_RX_DMA_NBR);
461
462 /* setup DMA descriptor */
463
464 mydescr.sw_len = bytecount;
465 mydescr.ctrl = d_eol;
466 mydescr.buf = virt_to_phys(buffer);
467
468 /* start the dma channel */
469
470 *R_DMA_CH3_FIRST = virt_to_phys(&mydescr);
471 *R_DMA_CH3_CMD = IO_STATE(R_DMA_CH3_CMD, cmd, start);
472
473 /* initiate a multi word dma read using PIO handshaking */
474
475 *R_ATA_TRANSFER_CNT = IO_FIELD(R_ATA_TRANSFER_CNT, count, bytecount >> 1);
476
477 *R_ATA_CTRL_DATA = data_reg |
478 IO_STATE(R_ATA_CTRL_DATA, rw, read) |
479 IO_STATE(R_ATA_CTRL_DATA, src_dst, dma) |
480 IO_STATE(R_ATA_CTRL_DATA, handsh, pio) |
481 IO_STATE(R_ATA_CTRL_DATA, multi, on) |
482 IO_STATE(R_ATA_CTRL_DATA, dma_size, word);
483
484 /* wait for completion */
485
486 LED_DISK_READ(1);
487 WAIT_DMA(ATA_RX_DMA_NBR);
488 LED_DISK_READ(0);
489
490#if 0
491 /* old polled transfer code
492 * this should be moved into a new function that can do polled
493 * transfers if DMA is not available
494 */
495
496 /* initiate a multi word read */
497
498 *R_ATA_TRANSFER_CNT = wcount << 1;
499
500 *R_ATA_CTRL_DATA = data_reg |
501 IO_STATE(R_ATA_CTRL_DATA, rw, read) |
502 IO_STATE(R_ATA_CTRL_DATA, src_dst, register) |
503 IO_STATE(R_ATA_CTRL_DATA, handsh, pio) |
504 IO_STATE(R_ATA_CTRL_DATA, multi, on) |
505 IO_STATE(R_ATA_CTRL_DATA, dma_size, word);
506
507 /* svinto has a latency until the busy bit actually is set */
508
509 nop(); nop();
510 nop(); nop();
511 nop(); nop();
512 nop(); nop();
513 nop(); nop();
514
515 /* unit should be busy during multi transfer */
516 while((status = *R_ATA_STATUS_DATA) & IO_MASK(R_ATA_STATUS_DATA, busy)) {
517 while(!(status & IO_MASK(R_ATA_STATUS_DATA, dav)))
518 status = *R_ATA_STATUS_DATA;
519 *ptr++ = (unsigned short)(status & 0xffff);
520 }
521#endif
522}
523
524static void
525e100_atapi_output_bytes (ide_drive_t *drive, void *buffer, unsigned int bytecount)
526{
527 unsigned long data_reg = IDE_DATA_REG;
528
529 D(printk("atapi_output_bytes, dreg 0x%x, buffer 0x%x, count %d\n",
530 data_reg, buffer, bytecount));
531
532 if(bytecount & 1) {
533 printk("odd bytecount %d in atapi_out_bytes!\n", bytecount);
534 bytecount++;
535 }
536
537 /* make sure the DMA channel is available */
538 RESET_DMA(ATA_TX_DMA_NBR);
539 WAIT_DMA(ATA_TX_DMA_NBR);
540
541 /* setup DMA descriptor */
542
543 mydescr.sw_len = bytecount;
544 mydescr.ctrl = d_eol;
545 mydescr.buf = virt_to_phys(buffer);
546
547 /* start the dma channel */
548
549 *R_DMA_CH2_FIRST = virt_to_phys(&mydescr);
550 *R_DMA_CH2_CMD = IO_STATE(R_DMA_CH2_CMD, cmd, start);
551
552 /* initiate a multi word dma write using PIO handshaking */
553
554 *R_ATA_TRANSFER_CNT = IO_FIELD(R_ATA_TRANSFER_CNT, count, bytecount >> 1);
555
556 *R_ATA_CTRL_DATA = data_reg |
557 IO_STATE(R_ATA_CTRL_DATA, rw, write) |
558 IO_STATE(R_ATA_CTRL_DATA, src_dst, dma) |
559 IO_STATE(R_ATA_CTRL_DATA, handsh, pio) |
560 IO_STATE(R_ATA_CTRL_DATA, multi, on) |
561 IO_STATE(R_ATA_CTRL_DATA, dma_size, word);
562
563 /* wait for completion */
564
565 LED_DISK_WRITE(1);
566 WAIT_DMA(ATA_TX_DMA_NBR);
567 LED_DISK_WRITE(0);
568
569#if 0
570 /* old polled write code - see comment in input_bytes */
571
572 /* wait for busy flag */
573 while(*R_ATA_STATUS_DATA & IO_MASK(R_ATA_STATUS_DATA, busy));
574
575 /* initiate a multi word write */
576
577 *R_ATA_TRANSFER_CNT = bytecount >> 1;
578
579 ctrl = data_reg |
580 IO_STATE(R_ATA_CTRL_DATA, rw, write) |
581 IO_STATE(R_ATA_CTRL_DATA, src_dst, register) |
582 IO_STATE(R_ATA_CTRL_DATA, handsh, pio) |
583 IO_STATE(R_ATA_CTRL_DATA, multi, on) |
584 IO_STATE(R_ATA_CTRL_DATA, dma_size, word);
585
586 LED_DISK_WRITE(1);
587
588 /* Etrax will set busy = 1 until the multi pio transfer has finished
589 * and tr_rdy = 1 after each successful word transfer.
590 * When the last byte has been transferred Etrax will first set tr_tdy = 1
591 * and then busy = 0 (not in the same cycle). If we read busy before it
592 * has been set to 0 we will think that we should transfer more bytes
593 * and then tr_rdy would be 0 forever. This is solved by checking busy
594 * in the inner loop.
595 */
596
597 do {
598 *R_ATA_CTRL_DATA = ctrl | *ptr++;
599 while(!(*R_ATA_STATUS_DATA & IO_MASK(R_ATA_STATUS_DATA, tr_rdy)) &&
600 (*R_ATA_STATUS_DATA & IO_MASK(R_ATA_STATUS_DATA, busy)));
601 } while(*R_ATA_STATUS_DATA & IO_MASK(R_ATA_STATUS_DATA, busy));
602
603 LED_DISK_WRITE(0);
604#endif
605
606}
607
608/*
609 * This is used for most PIO data transfers *from* the IDE interface
610 */
611static void
612e100_ide_input_data (ide_drive_t *drive, void *buffer, unsigned int wcount)
613{
614 e100_atapi_input_bytes(drive, buffer, wcount << 2);
615}
616
617/*
618 * This is used for most PIO data transfers *to* the IDE interface
619 */
620static void
621e100_ide_output_data (ide_drive_t *drive, void *buffer, unsigned int wcount)
622{
623 e100_atapi_output_bytes(drive, buffer, wcount << 2);
624}
625
626/* we only have one DMA channel on the chip for ATA, so we can keep these statically */
627static etrax_dma_descr ata_descrs[MAX_DMA_DESCRS];
628static unsigned int ata_tot_size;
629
630/*
631 * e100_ide_build_dmatable() prepares a dma request.
632 * Returns 0 if all went okay, returns 1 otherwise.
633 */
634static int e100_ide_build_dmatable (ide_drive_t *drive)
635{
636 ide_hwif_t *hwif = HWIF(drive);
637 struct scatterlist* sg;
638 struct request *rq = HWGROUP(drive)->rq;
639 unsigned long size, addr;
640 unsigned int count = 0;
641 int i = 0;
642
643 sg = hwif->sg_table;
644
645 ata_tot_size = 0;
646
647 ide_map_sg(drive, rq);
648
649 i = hwif->sg_nents;
650
651 while(i) {
652 /*
653 * Determine addr and size of next buffer area. We assume that
654 * individual virtual buffers are always composed linearly in
655 * physical memory. For example, we assume that any 8kB buffer
656 * is always composed of two adjacent physical 4kB pages rather
657 * than two possibly non-adjacent physical 4kB pages.
658 */
659 /* group sequential buffers into one large buffer */
660 addr = page_to_phys(sg->page) + sg->offset;
661 size = sg_dma_len(sg);
662 while (sg++, --i) {
663 if ((addr + size) != page_to_phys(sg->page) + sg->offset)
664 break;
665 size += sg_dma_len(sg);
666 }
667
668 /* did we run out of descriptors? */
669
670 if(count >= MAX_DMA_DESCRS) {
671 printk("%s: too few DMA descriptors\n", drive->name);
672 return 1;
673 }
674
675 /* however, this case is more difficult - R_ATA_TRANSFER_CNT cannot be more
676 than 65536 words per transfer, so in that case we need to either
677 1) use a DMA interrupt to re-trigger R_ATA_TRANSFER_CNT and continue with
678 the descriptors, or
679 2) simply do the request here, and get dma_intr to only ide_end_request on
680 those blocks that were actually set-up for transfer.
681 */
682
683 if(ata_tot_size + size > 131072) {
684 printk("too large total ATA DMA request, %d + %d!\n", ata_tot_size, (int)size);
685 return 1;
686 }
687
688 /* If size > 65536 it has to be splitted into new descriptors. Since we don't handle
689 size > 131072 only one split is necessary */
690
691 if(size > 65536) {
692 /* ok we want to do IO at addr, size bytes. set up a new descriptor entry */
693 ata_descrs[count].sw_len = 0; /* 0 means 65536, this is a 16-bit field */
694 ata_descrs[count].ctrl = 0;
695 ata_descrs[count].buf = addr;
696 ata_descrs[count].next = virt_to_phys(&ata_descrs[count + 1]);
697 count++;
698 ata_tot_size += 65536;
699 /* size and addr should refere to not handled data */
700 size -= 65536;
701 addr += 65536;
702 }
703 /* ok we want to do IO at addr, size bytes. set up a new descriptor entry */
704 if(size == 65536) {
705 ata_descrs[count].sw_len = 0; /* 0 means 65536, this is a 16-bit field */
706 } else {
707 ata_descrs[count].sw_len = size;
708 }
709 ata_descrs[count].ctrl = 0;
710 ata_descrs[count].buf = addr;
711 ata_descrs[count].next = virt_to_phys(&ata_descrs[count + 1]);
712 count++;
713 ata_tot_size += size;
714 }
715
716 if (count) {
717 /* set the end-of-list flag on the last descriptor */
718 ata_descrs[count - 1].ctrl |= d_eol;
719 /* return and say all is ok */
720 return 0;
721 }
722
723 printk("%s: empty DMA table?\n", drive->name);
724 return 1; /* let the PIO routines handle this weirdness */
725}
726
727static int config_drive_for_dma (ide_drive_t *drive)
728{
729 const char **list;
730 struct hd_driveid *id = drive->id;
731
732 if (id && (id->capability & 1)) {
733 /* Enable DMA on any drive that supports mword2 DMA */
734 if ((id->field_valid & 2) && (id->dma_mword & 0x404) == 0x404) {
735 drive->using_dma = 1;
736 return 0; /* DMA enabled */
737 }
738
739 /* Consult the list of known "good" drives */
740 list = good_dma_drives;
741 while (*list) {
742 if (!strcmp(*list++,id->model)) {
743 drive->using_dma = 1;
744 return 0; /* DMA enabled */
745 }
746 }
747 }
748 return 1; /* DMA not enabled */
749}
750
751/*
752 * etrax_dma_intr() is the handler for disk read/write DMA interrupts
753 */
754static ide_startstop_t etrax_dma_intr (ide_drive_t *drive)
755{
756 LED_DISK_READ(0);
757 LED_DISK_WRITE(0);
758
759 return ide_dma_intr(drive);
760}
761
762/*
763 * Functions below initiates/aborts DMA read/write operations on a drive.
764 *
765 * The caller is assumed to have selected the drive and programmed the drive's
766 * sector address using CHS or LBA. All that remains is to prepare for DMA
767 * and then issue the actual read/write DMA/PIO command to the drive.
768 *
769 * Returns 0 if all went well.
770 * Returns 1 if DMA read/write could not be started, in which case
771 * the caller should revert to PIO for the current request.
772 */
773
774static int e100_dma_check(ide_drive_t *drive)
775{
776 return config_drive_for_dma (drive);
777}
778
779static int e100_dma_end(ide_drive_t *drive)
780{
781 /* TODO: check if something went wrong with the DMA */
782 return 0;
783}
784
785static void e100_dma_start(ide_drive_t *drive)
786{
787 if (e100_read_command) {
788 /* begin DMA */
789
790 /* need to do this before RX DMA due to a chip bug
791 * it is enough to just flush the part of the cache that
792 * corresponds to the buffers we start, but since HD transfers
793 * usually are more than 8 kB, it is easier to optimize for the
794 * normal case and just flush the entire cache. its the only
795 * way to be sure! (OB movie quote)
796 */
797 flush_etrax_cache();
798 *R_DMA_CH3_FIRST = virt_to_phys(ata_descrs);
799 *R_DMA_CH3_CMD = IO_STATE(R_DMA_CH3_CMD, cmd, start);
800
801 /* initiate a multi word dma read using DMA handshaking */
802
803 *R_ATA_TRANSFER_CNT =
804 IO_FIELD(R_ATA_TRANSFER_CNT, count, ata_tot_size >> 1);
805
806 *R_ATA_CTRL_DATA =
807 IO_FIELD(R_ATA_CTRL_DATA, data, IDE_DATA_REG) |
808 IO_STATE(R_ATA_CTRL_DATA, rw, read) |
809 IO_STATE(R_ATA_CTRL_DATA, src_dst, dma) |
810 IO_STATE(R_ATA_CTRL_DATA, handsh, dma) |
811 IO_STATE(R_ATA_CTRL_DATA, multi, on) |
812 IO_STATE(R_ATA_CTRL_DATA, dma_size, word);
813
814 LED_DISK_READ(1);
815
816 D(printk("dma read of %d bytes.\n", ata_tot_size));
817
818 } else {
819 /* writing */
820 /* begin DMA */
821
822 *R_DMA_CH2_FIRST = virt_to_phys(ata_descrs);
823 *R_DMA_CH2_CMD = IO_STATE(R_DMA_CH2_CMD, cmd, start);
824
825 /* initiate a multi word dma write using DMA handshaking */
826
827 *R_ATA_TRANSFER_CNT =
828 IO_FIELD(R_ATA_TRANSFER_CNT, count, ata_tot_size >> 1);
829
830 *R_ATA_CTRL_DATA =
831 IO_FIELD(R_ATA_CTRL_DATA, data, IDE_DATA_REG) |
832 IO_STATE(R_ATA_CTRL_DATA, rw, write) |
833 IO_STATE(R_ATA_CTRL_DATA, src_dst, dma) |
834 IO_STATE(R_ATA_CTRL_DATA, handsh, dma) |
835 IO_STATE(R_ATA_CTRL_DATA, multi, on) |
836 IO_STATE(R_ATA_CTRL_DATA, dma_size, word);
837
838 LED_DISK_WRITE(1);
839
840 D(printk("dma write of %d bytes.\n", ata_tot_size));
841 }
842}
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 7df85af75371..94daf40ae323 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -960,6 +960,15 @@ static void save_match(ide_hwif_t *hwif, ide_hwif_t *new, ide_hwif_t **match)
960} 960}
961#endif /* MAX_HWIFS > 1 */ 961#endif /* MAX_HWIFS > 1 */
962 962
963static inline int hwif_to_node(ide_hwif_t *hwif)
964{
965 if (hwif->pci_dev)
966 return pcibus_to_node(hwif->pci_dev->bus);
967 else
968 /* Add ways to determine the node of other busses here */
969 return -1;
970}
971
963/* 972/*
964 * init request queue 973 * init request queue
965 */ 974 */
@@ -978,8 +987,7 @@ static int ide_init_queue(ide_drive_t *drive)
978 * do not. 987 * do not.
979 */ 988 */
980 989
981 q = blk_init_queue_node(do_ide_request, &ide_lock, 990 q = blk_init_queue_node(do_ide_request, &ide_lock, hwif_to_node(hwif));
982 pcibus_to_node(drive->hwif->pci_dev->bus));
983 if (!q) 991 if (!q)
984 return 1; 992 return 1;
985 993
@@ -1048,6 +1056,8 @@ static int init_irq (ide_hwif_t *hwif)
1048 1056
1049 BUG_ON(in_interrupt()); 1057 BUG_ON(in_interrupt());
1050 BUG_ON(irqs_disabled()); 1058 BUG_ON(irqs_disabled());
1059 BUG_ON(hwif == NULL);
1060
1051 down(&ide_cfg_sem); 1061 down(&ide_cfg_sem);
1052 hwif->hwgroup = NULL; 1062 hwif->hwgroup = NULL;
1053#if MAX_HWIFS > 1 1063#if MAX_HWIFS > 1
@@ -1097,7 +1107,7 @@ static int init_irq (ide_hwif_t *hwif)
1097 spin_unlock_irq(&ide_lock); 1107 spin_unlock_irq(&ide_lock);
1098 } else { 1108 } else {
1099 hwgroup = kmalloc_node(sizeof(ide_hwgroup_t), GFP_KERNEL, 1109 hwgroup = kmalloc_node(sizeof(ide_hwgroup_t), GFP_KERNEL,
1100 pcibus_to_node(hwif->drives[0].hwif->pci_dev->bus)); 1110 hwif_to_node(hwif->drives[0].hwif));
1101 if (!hwgroup) 1111 if (!hwgroup)
1102 goto out_up; 1112 goto out_up;
1103 1113
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c
index aac59751e1b4..f1d1ec4e9677 100644
--- a/drivers/ide/legacy/ide-cs.c
+++ b/drivers/ide/legacy/ide-cs.c
@@ -465,7 +465,7 @@ static struct pcmcia_device_id ide_ids[] = {
465 PCMCIA_DEVICE_PROD_ID12("CNF CD-M", "CD-ROM", 0x7d93b852, 0x66536591), 465 PCMCIA_DEVICE_PROD_ID12("CNF CD-M", "CD-ROM", 0x7d93b852, 0x66536591),
466 PCMCIA_DEVICE_PROD_ID12("Creative Technology Ltd.", "PCMCIA CD-ROM Interface Card", 0xff8c8a45, 0xfe8020c4), 466 PCMCIA_DEVICE_PROD_ID12("Creative Technology Ltd.", "PCMCIA CD-ROM Interface Card", 0xff8c8a45, 0xfe8020c4),
467 PCMCIA_DEVICE_PROD_ID12("Digital Equipment Corporation.", "Digital Mobile Media CD-ROM", 0x17692a66, 0xef1dcbde), 467 PCMCIA_DEVICE_PROD_ID12("Digital Equipment Corporation.", "Digital Mobile Media CD-ROM", 0x17692a66, 0xef1dcbde),
468 PCMCIA_DEVICE_PROD_ID12("EXP", "CD", 0x6f58c983, 0xaae5994f), 468 PCMCIA_DEVICE_PROD_ID12("EXP", "CD+GAME", 0x6f58c983, 0x63c13aaf),
469 PCMCIA_DEVICE_PROD_ID12("EXP ", "CD-ROM", 0x0a5c52fd, 0x66536591), 469 PCMCIA_DEVICE_PROD_ID12("EXP ", "CD-ROM", 0x0a5c52fd, 0x66536591),
470 PCMCIA_DEVICE_PROD_ID12("EXP ", "PnPIDE", 0x0a5c52fd, 0x0c694728), 470 PCMCIA_DEVICE_PROD_ID12("EXP ", "PnPIDE", 0x0a5c52fd, 0x0c694728),
471 PCMCIA_DEVICE_PROD_ID12("FREECOM", "PCCARD-IDE", 0x5714cbf7, 0x48e0ab8e), 471 PCMCIA_DEVICE_PROD_ID12("FREECOM", "PCCARD-IDE", 0x5714cbf7, 0x48e0ab8e),
@@ -481,6 +481,7 @@ static struct pcmcia_device_id ide_ids[] = {
481 PCMCIA_DEVICE_PROD_ID12("TOSHIBA", "MK2001MPL", 0xb4585a1a, 0x3489e003), 481 PCMCIA_DEVICE_PROD_ID12("TOSHIBA", "MK2001MPL", 0xb4585a1a, 0x3489e003),
482 PCMCIA_DEVICE_PROD_ID12("WIT", "IDE16", 0x244e5994, 0x3e232852), 482 PCMCIA_DEVICE_PROD_ID12("WIT", "IDE16", 0x244e5994, 0x3e232852),
483 PCMCIA_DEVICE_PROD_ID1("STI Flash", 0xe4a13209), 483 PCMCIA_DEVICE_PROD_ID1("STI Flash", 0xe4a13209),
484 PCMCIA_MFC_DEVICE_PROD_ID12(1, "SanDisk", "ConnectPlus", 0x7a954bd9, 0x74be00c6),
484 PCMCIA_DEVICE_NULL, 485 PCMCIA_DEVICE_NULL,
485}; 486};
486MODULE_DEVICE_TABLE(pcmcia, ide_ids); 487MODULE_DEVICE_TABLE(pcmcia, ide_ids);
@@ -507,5 +508,5 @@ static void __exit exit_ide_cs(void)
507 BUG_ON(dev_list != NULL); 508 BUG_ON(dev_list != NULL);
508} 509}
509 510
510module_init(init_ide_cs); 511late_initcall(init_ide_cs);
511module_exit(exit_ide_cs); 512module_exit(exit_ide_cs);
diff --git a/drivers/ide/pci/cmd640.c b/drivers/ide/pci/cmd640.c
index 92a2b7caed58..11d035f1983d 100644
--- a/drivers/ide/pci/cmd640.c
+++ b/drivers/ide/pci/cmd640.c
@@ -487,7 +487,7 @@ static void display_clocks (unsigned int index)
487 * Pack active and recovery counts into single byte representation 487 * Pack active and recovery counts into single byte representation
488 * used by controller 488 * used by controller
489 */ 489 */
490inline static u8 pack_nibbles (u8 upper, u8 lower) 490static inline u8 pack_nibbles (u8 upper, u8 lower)
491{ 491{
492 return ((upper & 0x0f) << 4) | (lower & 0x0f); 492 return ((upper & 0x0f) << 4) | (lower & 0x0f);
493} 493}
diff --git a/drivers/ide/pci/trm290.c b/drivers/ide/pci/trm290.c
index 8b5eea5405ef..c26c8ca90dd4 100644
--- a/drivers/ide/pci/trm290.c
+++ b/drivers/ide/pci/trm290.c
@@ -5,7 +5,7 @@
5 * May be copied or modified under the terms of the GNU General Public License 5 * May be copied or modified under the terms of the GNU General Public License
6 * 6 *
7 * June 22, 2004 - get rid of check_region 7 * June 22, 2004 - get rid of check_region
8 * Jesper Juhl <juhl-lkml@dif.dk> 8 * - Jesper Juhl
9 * 9 *
10 */ 10 */
11 11
diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c
index fe3e1703fa61..627af507643a 100644
--- a/drivers/ieee1394/sbp2.c
+++ b/drivers/ieee1394/sbp2.c
@@ -169,6 +169,7 @@ MODULE_DEVICE_TABLE(ieee1394, sbp2_id_table);
169 * Debug levels, configured via kernel config, or enable here. 169 * Debug levels, configured via kernel config, or enable here.
170 */ 170 */
171 171
172#define CONFIG_IEEE1394_SBP2_DEBUG 0
172/* #define CONFIG_IEEE1394_SBP2_DEBUG_ORBS */ 173/* #define CONFIG_IEEE1394_SBP2_DEBUG_ORBS */
173/* #define CONFIG_IEEE1394_SBP2_DEBUG_DMA */ 174/* #define CONFIG_IEEE1394_SBP2_DEBUG_DMA */
174/* #define CONFIG_IEEE1394_SBP2_DEBUG 1 */ 175/* #define CONFIG_IEEE1394_SBP2_DEBUG 1 */
diff --git a/drivers/infiniband/core/Makefile b/drivers/infiniband/core/Makefile
index e1a7cf3e8636..10be36731ed7 100644
--- a/drivers/infiniband/core/Makefile
+++ b/drivers/infiniband/core/Makefile
@@ -1,15 +1,20 @@
1EXTRA_CFLAGS += -Idrivers/infiniband/include 1EXTRA_CFLAGS += -Idrivers/infiniband/include
2 2
3obj-$(CONFIG_INFINIBAND) += ib_core.o ib_mad.o ib_sa.o ib_umad.o 3obj-$(CONFIG_INFINIBAND) += ib_core.o ib_mad.o ib_sa.o \
4 ib_cm.o ib_umad.o ib_ucm.o
4obj-$(CONFIG_INFINIBAND_USER_VERBS) += ib_uverbs.o 5obj-$(CONFIG_INFINIBAND_USER_VERBS) += ib_uverbs.o
5 6
6ib_core-y := packer.o ud_header.o verbs.o sysfs.o \ 7ib_core-y := packer.o ud_header.o verbs.o sysfs.o \
7 device.o fmr_pool.o cache.o 8 device.o fmr_pool.o cache.o
8 9
9ib_mad-y := mad.o smi.o agent.o 10ib_mad-y := mad.o smi.o agent.o mad_rmpp.o
10 11
11ib_sa-y := sa_query.o 12ib_sa-y := sa_query.o
12 13
14ib_cm-y := cm.o
15
13ib_umad-y := user_mad.o 16ib_umad-y := user_mad.o
14 17
18ib_ucm-y := ucm.o
19
15ib_uverbs-y := uverbs_main.o uverbs_cmd.o uverbs_mem.o 20ib_uverbs-y := uverbs_main.o uverbs_cmd.o uverbs_mem.o
diff --git a/drivers/infiniband/core/agent.c b/drivers/infiniband/core/agent.c
index 23d1957c4b29..729f0b0d983a 100644
--- a/drivers/infiniband/core/agent.c
+++ b/drivers/infiniband/core/agent.c
@@ -134,7 +134,7 @@ static int agent_mad_send(struct ib_mad_agent *mad_agent,
134 sizeof(mad_priv->mad), 134 sizeof(mad_priv->mad),
135 DMA_TO_DEVICE); 135 DMA_TO_DEVICE);
136 gather_list.length = sizeof(mad_priv->mad); 136 gather_list.length = sizeof(mad_priv->mad);
137 gather_list.lkey = (*port_priv->mr).lkey; 137 gather_list.lkey = mad_agent->mr->lkey;
138 138
139 send_wr.next = NULL; 139 send_wr.next = NULL;
140 send_wr.opcode = IB_WR_SEND; 140 send_wr.opcode = IB_WR_SEND;
@@ -156,10 +156,10 @@ static int agent_mad_send(struct ib_mad_agent *mad_agent,
156 /* Should sgid be looked up ? */ 156 /* Should sgid be looked up ? */
157 ah_attr.grh.sgid_index = 0; 157 ah_attr.grh.sgid_index = 0;
158 ah_attr.grh.hop_limit = grh->hop_limit; 158 ah_attr.grh.hop_limit = grh->hop_limit;
159 ah_attr.grh.flow_label = be32_to_cpup( 159 ah_attr.grh.flow_label = be32_to_cpu(
160 &grh->version_tclass_flow) & 0xfffff; 160 grh->version_tclass_flow) & 0xfffff;
161 ah_attr.grh.traffic_class = (be32_to_cpup( 161 ah_attr.grh.traffic_class = (be32_to_cpu(
162 &grh->version_tclass_flow) >> 20) & 0xff; 162 grh->version_tclass_flow) >> 20) & 0xff;
163 memcpy(ah_attr.grh.dgid.raw, 163 memcpy(ah_attr.grh.dgid.raw,
164 grh->sgid.raw, 164 grh->sgid.raw,
165 sizeof(ah_attr.grh.dgid)); 165 sizeof(ah_attr.grh.dgid));
@@ -322,22 +322,12 @@ int ib_agent_port_open(struct ib_device *device, int port_num)
322 goto error3; 322 goto error3;
323 } 323 }
324 324
325 port_priv->mr = ib_get_dma_mr(port_priv->smp_agent->qp->pd,
326 IB_ACCESS_LOCAL_WRITE);
327 if (IS_ERR(port_priv->mr)) {
328 printk(KERN_ERR SPFX "Couldn't get DMA MR\n");
329 ret = PTR_ERR(port_priv->mr);
330 goto error4;
331 }
332
333 spin_lock_irqsave(&ib_agent_port_list_lock, flags); 325 spin_lock_irqsave(&ib_agent_port_list_lock, flags);
334 list_add_tail(&port_priv->port_list, &ib_agent_port_list); 326 list_add_tail(&port_priv->port_list, &ib_agent_port_list);
335 spin_unlock_irqrestore(&ib_agent_port_list_lock, flags); 327 spin_unlock_irqrestore(&ib_agent_port_list_lock, flags);
336 328
337 return 0; 329 return 0;
338 330
339error4:
340 ib_unregister_mad_agent(port_priv->perf_mgmt_agent);
341error3: 331error3:
342 ib_unregister_mad_agent(port_priv->smp_agent); 332 ib_unregister_mad_agent(port_priv->smp_agent);
343error2: 333error2:
@@ -361,8 +351,6 @@ int ib_agent_port_close(struct ib_device *device, int port_num)
361 list_del(&port_priv->port_list); 351 list_del(&port_priv->port_list);
362 spin_unlock_irqrestore(&ib_agent_port_list_lock, flags); 352 spin_unlock_irqrestore(&ib_agent_port_list_lock, flags);
363 353
364 ib_dereg_mr(port_priv->mr);
365
366 ib_unregister_mad_agent(port_priv->perf_mgmt_agent); 354 ib_unregister_mad_agent(port_priv->perf_mgmt_agent);
367 ib_unregister_mad_agent(port_priv->smp_agent); 355 ib_unregister_mad_agent(port_priv->smp_agent);
368 kfree(port_priv); 356 kfree(port_priv);
diff --git a/drivers/infiniband/core/agent_priv.h b/drivers/infiniband/core/agent_priv.h
index 17a0cce5813c..17435af1e914 100644
--- a/drivers/infiniband/core/agent_priv.h
+++ b/drivers/infiniband/core/agent_priv.h
@@ -33,7 +33,7 @@
33 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 33 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 * SOFTWARE. 34 * SOFTWARE.
35 * 35 *
36 * $Id: agent_priv.h 1389 2004-12-27 22:56:47Z roland $ 36 * $Id: agent_priv.h 1640 2005-01-24 22:39:02Z halr $
37 */ 37 */
38 38
39#ifndef __IB_AGENT_PRIV_H__ 39#ifndef __IB_AGENT_PRIV_H__
@@ -57,7 +57,6 @@ struct ib_agent_port_private {
57 int port_num; 57 int port_num;
58 struct ib_mad_agent *smp_agent; /* SM class */ 58 struct ib_mad_agent *smp_agent; /* SM class */
59 struct ib_mad_agent *perf_mgmt_agent; /* PerfMgmt class */ 59 struct ib_mad_agent *perf_mgmt_agent; /* PerfMgmt class */
60 struct ib_mr *mr;
61}; 60};
62 61
63#endif /* __IB_AGENT_PRIV_H__ */ 62#endif /* __IB_AGENT_PRIV_H__ */
diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
new file mode 100644
index 000000000000..403ed125d8f4
--- /dev/null
+++ b/drivers/infiniband/core/cm.c
@@ -0,0 +1,3324 @@
1/*
2 * Copyright (c) 2004, 2005 Intel Corporation. All rights reserved.
3 * Copyright (c) 2004 Topspin Corporation. All rights reserved.
4 * Copyright (c) 2004, 2005 Voltaire Corporation. All rights reserved.
5 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
6 *
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * OpenIB.org BSD license below:
12 *
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
15 * conditions are met:
16 *
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer.
20 *
21 * - Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials
24 * provided with the distribution.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 * SOFTWARE.
34 *
35 * $Id: cm.c 2821 2005-07-08 17:07:28Z sean.hefty $
36 */
37#include <linux/dma-mapping.h>
38#include <linux/err.h>
39#include <linux/idr.h>
40#include <linux/interrupt.h>
41#include <linux/pci.h>
42#include <linux/rbtree.h>
43#include <linux/spinlock.h>
44#include <linux/workqueue.h>
45
46#include <ib_cache.h>
47#include <ib_cm.h>
48#include "cm_msgs.h"
49
50MODULE_AUTHOR("Sean Hefty");
51MODULE_DESCRIPTION("InfiniBand CM");
52MODULE_LICENSE("Dual BSD/GPL");
53
54static void cm_add_one(struct ib_device *device);
55static void cm_remove_one(struct ib_device *device);
56
57static struct ib_client cm_client = {
58 .name = "cm",
59 .add = cm_add_one,
60 .remove = cm_remove_one
61};
62
63static struct ib_cm {
64 spinlock_t lock;
65 struct list_head device_list;
66 rwlock_t device_lock;
67 struct rb_root listen_service_table;
68 u64 listen_service_id;
69 /* struct rb_root peer_service_table; todo: fix peer to peer */
70 struct rb_root remote_qp_table;
71 struct rb_root remote_id_table;
72 struct rb_root remote_sidr_table;
73 struct idr local_id_table;
74 struct workqueue_struct *wq;
75} cm;
76
77struct cm_port {
78 struct cm_device *cm_dev;
79 struct ib_mad_agent *mad_agent;
80 u8 port_num;
81};
82
83struct cm_device {
84 struct list_head list;
85 struct ib_device *device;
86 u64 ca_guid;
87 struct cm_port port[0];
88};
89
90struct cm_av {
91 struct cm_port *port;
92 union ib_gid dgid;
93 struct ib_ah_attr ah_attr;
94 u16 pkey_index;
95 u8 packet_life_time;
96};
97
98struct cm_work {
99 struct work_struct work;
100 struct list_head list;
101 struct cm_port *port;
102 struct ib_mad_recv_wc *mad_recv_wc; /* Received MADs */
103 u32 local_id; /* Established / timewait */
104 u32 remote_id;
105 struct ib_cm_event cm_event;
106 struct ib_sa_path_rec path[0];
107};
108
109struct cm_timewait_info {
110 struct cm_work work; /* Must be first. */
111 struct rb_node remote_qp_node;
112 struct rb_node remote_id_node;
113 u64 remote_ca_guid;
114 u32 remote_qpn;
115 u8 inserted_remote_qp;
116 u8 inserted_remote_id;
117};
118
119struct cm_id_private {
120 struct ib_cm_id id;
121
122 struct rb_node service_node;
123 struct rb_node sidr_id_node;
124 spinlock_t lock;
125 wait_queue_head_t wait;
126 atomic_t refcount;
127
128 struct ib_mad_send_buf *msg;
129 struct cm_timewait_info *timewait_info;
130 /* todo: use alternate port on send failure */
131 struct cm_av av;
132 struct cm_av alt_av;
133
134 void *private_data;
135 u64 tid;
136 u32 local_qpn;
137 u32 remote_qpn;
138 u32 sq_psn;
139 u32 rq_psn;
140 int timeout_ms;
141 enum ib_mtu path_mtu;
142 u8 private_data_len;
143 u8 max_cm_retries;
144 u8 peer_to_peer;
145 u8 responder_resources;
146 u8 initiator_depth;
147 u8 local_ack_timeout;
148 u8 retry_count;
149 u8 rnr_retry_count;
150 u8 service_timeout;
151
152 struct list_head work_list;
153 atomic_t work_count;
154};
155
156static void cm_work_handler(void *data);
157
158static inline void cm_deref_id(struct cm_id_private *cm_id_priv)
159{
160 if (atomic_dec_and_test(&cm_id_priv->refcount))
161 wake_up(&cm_id_priv->wait);
162}
163
164static int cm_alloc_msg(struct cm_id_private *cm_id_priv,
165 struct ib_mad_send_buf **msg)
166{
167 struct ib_mad_agent *mad_agent;
168 struct ib_mad_send_buf *m;
169 struct ib_ah *ah;
170
171 mad_agent = cm_id_priv->av.port->mad_agent;
172 ah = ib_create_ah(mad_agent->qp->pd, &cm_id_priv->av.ah_attr);
173 if (IS_ERR(ah))
174 return PTR_ERR(ah);
175
176 m = ib_create_send_mad(mad_agent, 1, cm_id_priv->av.pkey_index,
177 ah, 0, sizeof(struct ib_mad_hdr),
178 sizeof(struct ib_mad)-sizeof(struct ib_mad_hdr),
179 GFP_ATOMIC);
180 if (IS_ERR(m)) {
181 ib_destroy_ah(ah);
182 return PTR_ERR(m);
183 }
184
185 /* Timeout set by caller if response is expected. */
186 m->send_wr.wr.ud.retries = cm_id_priv->max_cm_retries;
187
188 atomic_inc(&cm_id_priv->refcount);
189 m->context[0] = cm_id_priv;
190 *msg = m;
191 return 0;
192}
193
194static int cm_alloc_response_msg(struct cm_port *port,
195 struct ib_mad_recv_wc *mad_recv_wc,
196 struct ib_mad_send_buf **msg)
197{
198 struct ib_mad_send_buf *m;
199 struct ib_ah *ah;
200
201 ah = ib_create_ah_from_wc(port->mad_agent->qp->pd, mad_recv_wc->wc,
202 mad_recv_wc->recv_buf.grh, port->port_num);
203 if (IS_ERR(ah))
204 return PTR_ERR(ah);
205
206 m = ib_create_send_mad(port->mad_agent, 1, mad_recv_wc->wc->pkey_index,
207 ah, 0, sizeof(struct ib_mad_hdr),
208 sizeof(struct ib_mad)-sizeof(struct ib_mad_hdr),
209 GFP_ATOMIC);
210 if (IS_ERR(m)) {
211 ib_destroy_ah(ah);
212 return PTR_ERR(m);
213 }
214 *msg = m;
215 return 0;
216}
217
218static void cm_free_msg(struct ib_mad_send_buf *msg)
219{
220 ib_destroy_ah(msg->send_wr.wr.ud.ah);
221 if (msg->context[0])
222 cm_deref_id(msg->context[0]);
223 ib_free_send_mad(msg);
224}
225
226static void * cm_copy_private_data(const void *private_data,
227 u8 private_data_len)
228{
229 void *data;
230
231 if (!private_data || !private_data_len)
232 return NULL;
233
234 data = kmalloc(private_data_len, GFP_KERNEL);
235 if (!data)
236 return ERR_PTR(-ENOMEM);
237
238 memcpy(data, private_data, private_data_len);
239 return data;
240}
241
242static void cm_set_private_data(struct cm_id_private *cm_id_priv,
243 void *private_data, u8 private_data_len)
244{
245 if (cm_id_priv->private_data && cm_id_priv->private_data_len)
246 kfree(cm_id_priv->private_data);
247
248 cm_id_priv->private_data = private_data;
249 cm_id_priv->private_data_len = private_data_len;
250}
251
252static void cm_set_ah_attr(struct ib_ah_attr *ah_attr, u8 port_num,
253 u16 dlid, u8 sl, u16 src_path_bits)
254{
255 memset(ah_attr, 0, sizeof ah_attr);
256 ah_attr->dlid = be16_to_cpu(dlid);
257 ah_attr->sl = sl;
258 ah_attr->src_path_bits = src_path_bits;
259 ah_attr->port_num = port_num;
260}
261
262static void cm_init_av_for_response(struct cm_port *port,
263 struct ib_wc *wc, struct cm_av *av)
264{
265 av->port = port;
266 av->pkey_index = wc->pkey_index;
267 cm_set_ah_attr(&av->ah_attr, port->port_num, cpu_to_be16(wc->slid),
268 wc->sl, wc->dlid_path_bits);
269}
270
271static int cm_init_av_by_path(struct ib_sa_path_rec *path, struct cm_av *av)
272{
273 struct cm_device *cm_dev;
274 struct cm_port *port = NULL;
275 unsigned long flags;
276 int ret;
277 u8 p;
278
279 read_lock_irqsave(&cm.device_lock, flags);
280 list_for_each_entry(cm_dev, &cm.device_list, list) {
281 if (!ib_find_cached_gid(cm_dev->device, &path->sgid,
282 &p, NULL)) {
283 port = &cm_dev->port[p-1];
284 break;
285 }
286 }
287 read_unlock_irqrestore(&cm.device_lock, flags);
288
289 if (!port)
290 return -EINVAL;
291
292 ret = ib_find_cached_pkey(cm_dev->device, port->port_num,
293 be16_to_cpu(path->pkey), &av->pkey_index);
294 if (ret)
295 return ret;
296
297 av->port = port;
298 cm_set_ah_attr(&av->ah_attr, av->port->port_num, path->dlid,
299 path->sl, path->slid & 0x7F);
300 av->packet_life_time = path->packet_life_time;
301 return 0;
302}
303
304static int cm_alloc_id(struct cm_id_private *cm_id_priv)
305{
306 unsigned long flags;
307 int ret;
308
309 do {
310 spin_lock_irqsave(&cm.lock, flags);
311 ret = idr_get_new_above(&cm.local_id_table, cm_id_priv, 1,
312 (int *) &cm_id_priv->id.local_id);
313 spin_unlock_irqrestore(&cm.lock, flags);
314 } while( (ret == -EAGAIN) && idr_pre_get(&cm.local_id_table, GFP_KERNEL) );
315 return ret;
316}
317
318static void cm_free_id(u32 local_id)
319{
320 unsigned long flags;
321
322 spin_lock_irqsave(&cm.lock, flags);
323 idr_remove(&cm.local_id_table, (int) local_id);
324 spin_unlock_irqrestore(&cm.lock, flags);
325}
326
327static struct cm_id_private * cm_get_id(u32 local_id, u32 remote_id)
328{
329 struct cm_id_private *cm_id_priv;
330
331 cm_id_priv = idr_find(&cm.local_id_table, (int) local_id);
332 if (cm_id_priv) {
333 if (cm_id_priv->id.remote_id == remote_id)
334 atomic_inc(&cm_id_priv->refcount);
335 else
336 cm_id_priv = NULL;
337 }
338
339 return cm_id_priv;
340}
341
342static struct cm_id_private * cm_acquire_id(u32 local_id, u32 remote_id)
343{
344 struct cm_id_private *cm_id_priv;
345 unsigned long flags;
346
347 spin_lock_irqsave(&cm.lock, flags);
348 cm_id_priv = cm_get_id(local_id, remote_id);
349 spin_unlock_irqrestore(&cm.lock, flags);
350
351 return cm_id_priv;
352}
353
354static struct cm_id_private * cm_insert_listen(struct cm_id_private *cm_id_priv)
355{
356 struct rb_node **link = &cm.listen_service_table.rb_node;
357 struct rb_node *parent = NULL;
358 struct cm_id_private *cur_cm_id_priv;
359 u64 service_id = cm_id_priv->id.service_id;
360 u64 service_mask = cm_id_priv->id.service_mask;
361
362 while (*link) {
363 parent = *link;
364 cur_cm_id_priv = rb_entry(parent, struct cm_id_private,
365 service_node);
366 if ((cur_cm_id_priv->id.service_mask & service_id) ==
367 (service_mask & cur_cm_id_priv->id.service_id))
368 return cm_id_priv;
369 if (service_id < cur_cm_id_priv->id.service_id)
370 link = &(*link)->rb_left;
371 else
372 link = &(*link)->rb_right;
373 }
374 rb_link_node(&cm_id_priv->service_node, parent, link);
375 rb_insert_color(&cm_id_priv->service_node, &cm.listen_service_table);
376 return NULL;
377}
378
379static struct cm_id_private * cm_find_listen(u64 service_id)
380{
381 struct rb_node *node = cm.listen_service_table.rb_node;
382 struct cm_id_private *cm_id_priv;
383
384 while (node) {
385 cm_id_priv = rb_entry(node, struct cm_id_private, service_node);
386 if ((cm_id_priv->id.service_mask & service_id) ==
387 (cm_id_priv->id.service_mask & cm_id_priv->id.service_id))
388 return cm_id_priv;
389 if (service_id < cm_id_priv->id.service_id)
390 node = node->rb_left;
391 else
392 node = node->rb_right;
393 }
394 return NULL;
395}
396
397static struct cm_timewait_info * cm_insert_remote_id(struct cm_timewait_info
398 *timewait_info)
399{
400 struct rb_node **link = &cm.remote_id_table.rb_node;
401 struct rb_node *parent = NULL;
402 struct cm_timewait_info *cur_timewait_info;
403 u64 remote_ca_guid = timewait_info->remote_ca_guid;
404 u32 remote_id = timewait_info->work.remote_id;
405
406 while (*link) {
407 parent = *link;
408 cur_timewait_info = rb_entry(parent, struct cm_timewait_info,
409 remote_id_node);
410 if (remote_id < cur_timewait_info->work.remote_id)
411 link = &(*link)->rb_left;
412 else if (remote_id > cur_timewait_info->work.remote_id)
413 link = &(*link)->rb_right;
414 else if (remote_ca_guid < cur_timewait_info->remote_ca_guid)
415 link = &(*link)->rb_left;
416 else if (remote_ca_guid > cur_timewait_info->remote_ca_guid)
417 link = &(*link)->rb_right;
418 else
419 return cur_timewait_info;
420 }
421 timewait_info->inserted_remote_id = 1;
422 rb_link_node(&timewait_info->remote_id_node, parent, link);
423 rb_insert_color(&timewait_info->remote_id_node, &cm.remote_id_table);
424 return NULL;
425}
426
427static struct cm_timewait_info * cm_find_remote_id(u64 remote_ca_guid,
428 u32 remote_id)
429{
430 struct rb_node *node = cm.remote_id_table.rb_node;
431 struct cm_timewait_info *timewait_info;
432
433 while (node) {
434 timewait_info = rb_entry(node, struct cm_timewait_info,
435 remote_id_node);
436 if (remote_id < timewait_info->work.remote_id)
437 node = node->rb_left;
438 else if (remote_id > timewait_info->work.remote_id)
439 node = node->rb_right;
440 else if (remote_ca_guid < timewait_info->remote_ca_guid)
441 node = node->rb_left;
442 else if (remote_ca_guid > timewait_info->remote_ca_guid)
443 node = node->rb_right;
444 else
445 return timewait_info;
446 }
447 return NULL;
448}
449
450static struct cm_timewait_info * cm_insert_remote_qpn(struct cm_timewait_info
451 *timewait_info)
452{
453 struct rb_node **link = &cm.remote_qp_table.rb_node;
454 struct rb_node *parent = NULL;
455 struct cm_timewait_info *cur_timewait_info;
456 u64 remote_ca_guid = timewait_info->remote_ca_guid;
457 u32 remote_qpn = timewait_info->remote_qpn;
458
459 while (*link) {
460 parent = *link;
461 cur_timewait_info = rb_entry(parent, struct cm_timewait_info,
462 remote_qp_node);
463 if (remote_qpn < cur_timewait_info->remote_qpn)
464 link = &(*link)->rb_left;
465 else if (remote_qpn > cur_timewait_info->remote_qpn)
466 link = &(*link)->rb_right;
467 else if (remote_ca_guid < cur_timewait_info->remote_ca_guid)
468 link = &(*link)->rb_left;
469 else if (remote_ca_guid > cur_timewait_info->remote_ca_guid)
470 link = &(*link)->rb_right;
471 else
472 return cur_timewait_info;
473 }
474 timewait_info->inserted_remote_qp = 1;
475 rb_link_node(&timewait_info->remote_qp_node, parent, link);
476 rb_insert_color(&timewait_info->remote_qp_node, &cm.remote_qp_table);
477 return NULL;
478}
479
480static struct cm_id_private * cm_insert_remote_sidr(struct cm_id_private
481 *cm_id_priv)
482{
483 struct rb_node **link = &cm.remote_sidr_table.rb_node;
484 struct rb_node *parent = NULL;
485 struct cm_id_private *cur_cm_id_priv;
486 union ib_gid *port_gid = &cm_id_priv->av.dgid;
487 u32 remote_id = cm_id_priv->id.remote_id;
488
489 while (*link) {
490 parent = *link;
491 cur_cm_id_priv = rb_entry(parent, struct cm_id_private,
492 sidr_id_node);
493 if (remote_id < cur_cm_id_priv->id.remote_id)
494 link = &(*link)->rb_left;
495 else if (remote_id > cur_cm_id_priv->id.remote_id)
496 link = &(*link)->rb_right;
497 else {
498 int cmp;
499 cmp = memcmp(port_gid, &cur_cm_id_priv->av.dgid,
500 sizeof *port_gid);
501 if (cmp < 0)
502 link = &(*link)->rb_left;
503 else if (cmp > 0)
504 link = &(*link)->rb_right;
505 else
506 return cur_cm_id_priv;
507 }
508 }
509 rb_link_node(&cm_id_priv->sidr_id_node, parent, link);
510 rb_insert_color(&cm_id_priv->sidr_id_node, &cm.remote_sidr_table);
511 return NULL;
512}
513
514static void cm_reject_sidr_req(struct cm_id_private *cm_id_priv,
515 enum ib_cm_sidr_status status)
516{
517 struct ib_cm_sidr_rep_param param;
518
519 memset(&param, 0, sizeof param);
520 param.status = status;
521 ib_send_cm_sidr_rep(&cm_id_priv->id, &param);
522}
523
524struct ib_cm_id *ib_create_cm_id(ib_cm_handler cm_handler,
525 void *context)
526{
527 struct cm_id_private *cm_id_priv;
528 int ret;
529
530 cm_id_priv = kmalloc(sizeof *cm_id_priv, GFP_KERNEL);
531 if (!cm_id_priv)
532 return ERR_PTR(-ENOMEM);
533
534 memset(cm_id_priv, 0, sizeof *cm_id_priv);
535 cm_id_priv->id.state = IB_CM_IDLE;
536 cm_id_priv->id.cm_handler = cm_handler;
537 cm_id_priv->id.context = context;
538 ret = cm_alloc_id(cm_id_priv);
539 if (ret)
540 goto error;
541
542 spin_lock_init(&cm_id_priv->lock);
543 init_waitqueue_head(&cm_id_priv->wait);
544 INIT_LIST_HEAD(&cm_id_priv->work_list);
545 atomic_set(&cm_id_priv->work_count, -1);
546 atomic_set(&cm_id_priv->refcount, 1);
547 return &cm_id_priv->id;
548
549error:
550 kfree(cm_id_priv);
551 return ERR_PTR(-ENOMEM);
552}
553EXPORT_SYMBOL(ib_create_cm_id);
554
555static struct cm_work * cm_dequeue_work(struct cm_id_private *cm_id_priv)
556{
557 struct cm_work *work;
558
559 if (list_empty(&cm_id_priv->work_list))
560 return NULL;
561
562 work = list_entry(cm_id_priv->work_list.next, struct cm_work, list);
563 list_del(&work->list);
564 return work;
565}
566
567static void cm_free_work(struct cm_work *work)
568{
569 if (work->mad_recv_wc)
570 ib_free_recv_mad(work->mad_recv_wc);
571 kfree(work);
572}
573
574static inline int cm_convert_to_ms(int iba_time)
575{
576 /* approximate conversion to ms from 4.096us x 2^iba_time */
577 return 1 << max(iba_time - 8, 0);
578}
579
580static void cm_cleanup_timewait(struct cm_timewait_info *timewait_info)
581{
582 unsigned long flags;
583
584 if (!timewait_info->inserted_remote_id &&
585 !timewait_info->inserted_remote_qp)
586 return;
587
588 spin_lock_irqsave(&cm.lock, flags);
589 if (timewait_info->inserted_remote_id) {
590 rb_erase(&timewait_info->remote_id_node, &cm.remote_id_table);
591 timewait_info->inserted_remote_id = 0;
592 }
593
594 if (timewait_info->inserted_remote_qp) {
595 rb_erase(&timewait_info->remote_qp_node, &cm.remote_qp_table);
596 timewait_info->inserted_remote_qp = 0;
597 }
598 spin_unlock_irqrestore(&cm.lock, flags);
599}
600
601static struct cm_timewait_info * cm_create_timewait_info(u32 local_id)
602{
603 struct cm_timewait_info *timewait_info;
604
605 timewait_info = kmalloc(sizeof *timewait_info, GFP_KERNEL);
606 if (!timewait_info)
607 return ERR_PTR(-ENOMEM);
608 memset(timewait_info, 0, sizeof *timewait_info);
609
610 timewait_info->work.local_id = local_id;
611 INIT_WORK(&timewait_info->work.work, cm_work_handler,
612 &timewait_info->work);
613 timewait_info->work.cm_event.event = IB_CM_TIMEWAIT_EXIT;
614 return timewait_info;
615}
616
617static void cm_enter_timewait(struct cm_id_private *cm_id_priv)
618{
619 int wait_time;
620
621 /*
622 * The cm_id could be destroyed by the user before we exit timewait.
623 * To protect against this, we search for the cm_id after exiting
624 * timewait before notifying the user that we've exited timewait.
625 */
626 cm_id_priv->id.state = IB_CM_TIMEWAIT;
627 wait_time = cm_convert_to_ms(cm_id_priv->local_ack_timeout);
628 queue_delayed_work(cm.wq, &cm_id_priv->timewait_info->work.work,
629 msecs_to_jiffies(wait_time));
630 cm_id_priv->timewait_info = NULL;
631}
632
633static void cm_reset_to_idle(struct cm_id_private *cm_id_priv)
634{
635 cm_id_priv->id.state = IB_CM_IDLE;
636 if (cm_id_priv->timewait_info) {
637 cm_cleanup_timewait(cm_id_priv->timewait_info);
638 kfree(cm_id_priv->timewait_info);
639 cm_id_priv->timewait_info = NULL;
640 }
641}
642
643void ib_destroy_cm_id(struct ib_cm_id *cm_id)
644{
645 struct cm_id_private *cm_id_priv;
646 struct cm_work *work;
647 unsigned long flags;
648
649 cm_id_priv = container_of(cm_id, struct cm_id_private, id);
650retest:
651 spin_lock_irqsave(&cm_id_priv->lock, flags);
652 switch (cm_id->state) {
653 case IB_CM_LISTEN:
654 cm_id->state = IB_CM_IDLE;
655 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
656 spin_lock_irqsave(&cm.lock, flags);
657 rb_erase(&cm_id_priv->service_node, &cm.listen_service_table);
658 spin_unlock_irqrestore(&cm.lock, flags);
659 break;
660 case IB_CM_SIDR_REQ_SENT:
661 cm_id->state = IB_CM_IDLE;
662 ib_cancel_mad(cm_id_priv->av.port->mad_agent,
663 (unsigned long) cm_id_priv->msg);
664 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
665 break;
666 case IB_CM_SIDR_REQ_RCVD:
667 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
668 cm_reject_sidr_req(cm_id_priv, IB_SIDR_REJECT);
669 break;
670 case IB_CM_REQ_SENT:
671 case IB_CM_MRA_REQ_RCVD:
672 case IB_CM_REP_SENT:
673 case IB_CM_MRA_REP_RCVD:
674 ib_cancel_mad(cm_id_priv->av.port->mad_agent,
675 (unsigned long) cm_id_priv->msg);
676 /* Fall through */
677 case IB_CM_REQ_RCVD:
678 case IB_CM_MRA_REQ_SENT:
679 case IB_CM_REP_RCVD:
680 case IB_CM_MRA_REP_SENT:
681 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
682 ib_send_cm_rej(cm_id, IB_CM_REJ_TIMEOUT,
683 &cm_id_priv->av.port->cm_dev->ca_guid,
684 sizeof cm_id_priv->av.port->cm_dev->ca_guid,
685 NULL, 0);
686 break;
687 case IB_CM_ESTABLISHED:
688 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
689 ib_send_cm_dreq(cm_id, NULL, 0);
690 goto retest;
691 case IB_CM_DREQ_SENT:
692 ib_cancel_mad(cm_id_priv->av.port->mad_agent,
693 (unsigned long) cm_id_priv->msg);
694 cm_enter_timewait(cm_id_priv);
695 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
696 break;
697 case IB_CM_DREQ_RCVD:
698 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
699 ib_send_cm_drep(cm_id, NULL, 0);
700 break;
701 default:
702 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
703 break;
704 }
705
706 cm_free_id(cm_id->local_id);
707 atomic_dec(&cm_id_priv->refcount);
708 wait_event(cm_id_priv->wait, !atomic_read(&cm_id_priv->refcount));
709 while ((work = cm_dequeue_work(cm_id_priv)) != NULL)
710 cm_free_work(work);
711 if (cm_id_priv->private_data && cm_id_priv->private_data_len)
712 kfree(cm_id_priv->private_data);
713 kfree(cm_id_priv);
714}
715EXPORT_SYMBOL(ib_destroy_cm_id);
716
717int ib_cm_listen(struct ib_cm_id *cm_id,
718 u64 service_id,
719 u64 service_mask)
720{
721 struct cm_id_private *cm_id_priv, *cur_cm_id_priv;
722 unsigned long flags;
723 int ret = 0;
724
725 service_mask = service_mask ? service_mask : ~0ULL;
726 service_id &= service_mask;
727 if ((service_id & IB_SERVICE_ID_AGN_MASK) == IB_CM_ASSIGN_SERVICE_ID &&
728 (service_id != IB_CM_ASSIGN_SERVICE_ID))
729 return -EINVAL;
730
731 cm_id_priv = container_of(cm_id, struct cm_id_private, id);
732 BUG_ON(cm_id->state != IB_CM_IDLE);
733
734 cm_id->state = IB_CM_LISTEN;
735
736 spin_lock_irqsave(&cm.lock, flags);
737 if (service_id == IB_CM_ASSIGN_SERVICE_ID) {
738 cm_id->service_id = __cpu_to_be64(cm.listen_service_id++);
739 cm_id->service_mask = ~0ULL;
740 } else {
741 cm_id->service_id = service_id;
742 cm_id->service_mask = service_mask;
743 }
744 cur_cm_id_priv = cm_insert_listen(cm_id_priv);
745 spin_unlock_irqrestore(&cm.lock, flags);
746
747 if (cur_cm_id_priv) {
748 cm_id->state = IB_CM_IDLE;
749 ret = -EBUSY;
750 }
751 return ret;
752}
753EXPORT_SYMBOL(ib_cm_listen);
754
755static u64 cm_form_tid(struct cm_id_private *cm_id_priv,
756 enum cm_msg_sequence msg_seq)
757{
758 u64 hi_tid, low_tid;
759
760 hi_tid = ((u64) cm_id_priv->av.port->mad_agent->hi_tid) << 32;
761 low_tid = (u64) (cm_id_priv->id.local_id | (msg_seq << 30));
762 return cpu_to_be64(hi_tid | low_tid);
763}
764
765static void cm_format_mad_hdr(struct ib_mad_hdr *hdr,
766 enum cm_msg_attr_id attr_id, u64 tid)
767{
768 hdr->base_version = IB_MGMT_BASE_VERSION;
769 hdr->mgmt_class = IB_MGMT_CLASS_CM;
770 hdr->class_version = IB_CM_CLASS_VERSION;
771 hdr->method = IB_MGMT_METHOD_SEND;
772 hdr->attr_id = attr_id;
773 hdr->tid = tid;
774}
775
776static void cm_format_req(struct cm_req_msg *req_msg,
777 struct cm_id_private *cm_id_priv,
778 struct ib_cm_req_param *param)
779{
780 cm_format_mad_hdr(&req_msg->hdr, CM_REQ_ATTR_ID,
781 cm_form_tid(cm_id_priv, CM_MSG_SEQUENCE_REQ));
782
783 req_msg->local_comm_id = cm_id_priv->id.local_id;
784 req_msg->service_id = param->service_id;
785 req_msg->local_ca_guid = cm_id_priv->av.port->cm_dev->ca_guid;
786 cm_req_set_local_qpn(req_msg, cpu_to_be32(param->qp_num));
787 cm_req_set_resp_res(req_msg, param->responder_resources);
788 cm_req_set_init_depth(req_msg, param->initiator_depth);
789 cm_req_set_remote_resp_timeout(req_msg,
790 param->remote_cm_response_timeout);
791 cm_req_set_qp_type(req_msg, param->qp_type);
792 cm_req_set_flow_ctrl(req_msg, param->flow_control);
793 cm_req_set_starting_psn(req_msg, cpu_to_be32(param->starting_psn));
794 cm_req_set_local_resp_timeout(req_msg,
795 param->local_cm_response_timeout);
796 cm_req_set_retry_count(req_msg, param->retry_count);
797 req_msg->pkey = param->primary_path->pkey;
798 cm_req_set_path_mtu(req_msg, param->primary_path->mtu);
799 cm_req_set_rnr_retry_count(req_msg, param->rnr_retry_count);
800 cm_req_set_max_cm_retries(req_msg, param->max_cm_retries);
801 cm_req_set_srq(req_msg, param->srq);
802
803 req_msg->primary_local_lid = param->primary_path->slid;
804 req_msg->primary_remote_lid = param->primary_path->dlid;
805 req_msg->primary_local_gid = param->primary_path->sgid;
806 req_msg->primary_remote_gid = param->primary_path->dgid;
807 cm_req_set_primary_flow_label(req_msg, param->primary_path->flow_label);
808 cm_req_set_primary_packet_rate(req_msg, param->primary_path->rate);
809 req_msg->primary_traffic_class = param->primary_path->traffic_class;
810 req_msg->primary_hop_limit = param->primary_path->hop_limit;
811 cm_req_set_primary_sl(req_msg, param->primary_path->sl);
812 cm_req_set_primary_subnet_local(req_msg, 1); /* local only... */
813 cm_req_set_primary_local_ack_timeout(req_msg,
814 min(31, param->primary_path->packet_life_time + 1));
815
816 if (param->alternate_path) {
817 req_msg->alt_local_lid = param->alternate_path->slid;
818 req_msg->alt_remote_lid = param->alternate_path->dlid;
819 req_msg->alt_local_gid = param->alternate_path->sgid;
820 req_msg->alt_remote_gid = param->alternate_path->dgid;
821 cm_req_set_alt_flow_label(req_msg,
822 param->alternate_path->flow_label);
823 cm_req_set_alt_packet_rate(req_msg, param->alternate_path->rate);
824 req_msg->alt_traffic_class = param->alternate_path->traffic_class;
825 req_msg->alt_hop_limit = param->alternate_path->hop_limit;
826 cm_req_set_alt_sl(req_msg, param->alternate_path->sl);
827 cm_req_set_alt_subnet_local(req_msg, 1); /* local only... */
828 cm_req_set_alt_local_ack_timeout(req_msg,
829 min(31, param->alternate_path->packet_life_time + 1));
830 }
831
832 if (param->private_data && param->private_data_len)
833 memcpy(req_msg->private_data, param->private_data,
834 param->private_data_len);
835}
836
837static inline int cm_validate_req_param(struct ib_cm_req_param *param)
838{
839 /* peer-to-peer not supported */
840 if (param->peer_to_peer)
841 return -EINVAL;
842
843 if (!param->primary_path)
844 return -EINVAL;
845
846 if (param->qp_type != IB_QPT_RC && param->qp_type != IB_QPT_UC)
847 return -EINVAL;
848
849 if (param->private_data &&
850 param->private_data_len > IB_CM_REQ_PRIVATE_DATA_SIZE)
851 return -EINVAL;
852
853 if (param->alternate_path &&
854 (param->alternate_path->pkey != param->primary_path->pkey ||
855 param->alternate_path->mtu != param->primary_path->mtu))
856 return -EINVAL;
857
858 return 0;
859}
860
861int ib_send_cm_req(struct ib_cm_id *cm_id,
862 struct ib_cm_req_param *param)
863{
864 struct cm_id_private *cm_id_priv;
865 struct ib_send_wr *bad_send_wr;
866 struct cm_req_msg *req_msg;
867 unsigned long flags;
868 int ret;
869
870 ret = cm_validate_req_param(param);
871 if (ret)
872 return ret;
873
874 /* Verify that we're not in timewait. */
875 cm_id_priv = container_of(cm_id, struct cm_id_private, id);
876 spin_lock_irqsave(&cm_id_priv->lock, flags);
877 if (cm_id->state != IB_CM_IDLE) {
878 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
879 ret = -EINVAL;
880 goto out;
881 }
882 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
883
884 cm_id_priv->timewait_info = cm_create_timewait_info(cm_id_priv->
885 id.local_id);
886 if (IS_ERR(cm_id_priv->timewait_info))
887 goto out;
888
889 ret = cm_init_av_by_path(param->primary_path, &cm_id_priv->av);
890 if (ret)
891 goto error1;
892 if (param->alternate_path) {
893 ret = cm_init_av_by_path(param->alternate_path,
894 &cm_id_priv->alt_av);
895 if (ret)
896 goto error1;
897 }
898 cm_id->service_id = param->service_id;
899 cm_id->service_mask = ~0ULL;
900 cm_id_priv->timeout_ms = cm_convert_to_ms(
901 param->primary_path->packet_life_time) * 2 +
902 cm_convert_to_ms(
903 param->remote_cm_response_timeout);
904 cm_id_priv->max_cm_retries = param->max_cm_retries;
905 cm_id_priv->initiator_depth = param->initiator_depth;
906 cm_id_priv->responder_resources = param->responder_resources;
907 cm_id_priv->retry_count = param->retry_count;
908 cm_id_priv->path_mtu = param->primary_path->mtu;
909
910 ret = cm_alloc_msg(cm_id_priv, &cm_id_priv->msg);
911 if (ret)
912 goto error1;
913
914 req_msg = (struct cm_req_msg *) cm_id_priv->msg->mad;
915 cm_format_req(req_msg, cm_id_priv, param);
916 cm_id_priv->tid = req_msg->hdr.tid;
917 cm_id_priv->msg->send_wr.wr.ud.timeout_ms = cm_id_priv->timeout_ms;
918 cm_id_priv->msg->context[1] = (void *) (unsigned long) IB_CM_REQ_SENT;
919
920 cm_id_priv->local_qpn = cm_req_get_local_qpn(req_msg);
921 cm_id_priv->rq_psn = cm_req_get_starting_psn(req_msg);
922 cm_id_priv->local_ack_timeout =
923 cm_req_get_primary_local_ack_timeout(req_msg);
924
925 spin_lock_irqsave(&cm_id_priv->lock, flags);
926 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent,
927 &cm_id_priv->msg->send_wr, &bad_send_wr);
928 if (ret) {
929 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
930 goto error2;
931 }
932 BUG_ON(cm_id->state != IB_CM_IDLE);
933 cm_id->state = IB_CM_REQ_SENT;
934 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
935 return 0;
936
937error2: cm_free_msg(cm_id_priv->msg);
938error1: kfree(cm_id_priv->timewait_info);
939out: return ret;
940}
941EXPORT_SYMBOL(ib_send_cm_req);
942
943static int cm_issue_rej(struct cm_port *port,
944 struct ib_mad_recv_wc *mad_recv_wc,
945 enum ib_cm_rej_reason reason,
946 enum cm_msg_response msg_rejected,
947 void *ari, u8 ari_length)
948{
949 struct ib_mad_send_buf *msg = NULL;
950 struct ib_send_wr *bad_send_wr;
951 struct cm_rej_msg *rej_msg, *rcv_msg;
952 int ret;
953
954 ret = cm_alloc_response_msg(port, mad_recv_wc, &msg);
955 if (ret)
956 return ret;
957
958 /* We just need common CM header information. Cast to any message. */
959 rcv_msg = (struct cm_rej_msg *) mad_recv_wc->recv_buf.mad;
960 rej_msg = (struct cm_rej_msg *) msg->mad;
961
962 cm_format_mad_hdr(&rej_msg->hdr, CM_REJ_ATTR_ID, rcv_msg->hdr.tid);
963 rej_msg->remote_comm_id = rcv_msg->local_comm_id;
964 rej_msg->local_comm_id = rcv_msg->remote_comm_id;
965 cm_rej_set_msg_rejected(rej_msg, msg_rejected);
966 rej_msg->reason = reason;
967
968 if (ari && ari_length) {
969 cm_rej_set_reject_info_len(rej_msg, ari_length);
970 memcpy(rej_msg->ari, ari, ari_length);
971 }
972
973 ret = ib_post_send_mad(port->mad_agent, &msg->send_wr, &bad_send_wr);
974 if (ret)
975 cm_free_msg(msg);
976
977 return ret;
978}
979
980static inline int cm_is_active_peer(u64 local_ca_guid, u64 remote_ca_guid,
981 u32 local_qpn, u32 remote_qpn)
982{
983 return (be64_to_cpu(local_ca_guid) > be64_to_cpu(remote_ca_guid) ||
984 ((local_ca_guid == remote_ca_guid) &&
985 (be32_to_cpu(local_qpn) > be32_to_cpu(remote_qpn))));
986}
987
988static inline void cm_format_paths_from_req(struct cm_req_msg *req_msg,
989 struct ib_sa_path_rec *primary_path,
990 struct ib_sa_path_rec *alt_path)
991{
992 memset(primary_path, 0, sizeof *primary_path);
993 primary_path->dgid = req_msg->primary_local_gid;
994 primary_path->sgid = req_msg->primary_remote_gid;
995 primary_path->dlid = req_msg->primary_local_lid;
996 primary_path->slid = req_msg->primary_remote_lid;
997 primary_path->flow_label = cm_req_get_primary_flow_label(req_msg);
998 primary_path->hop_limit = req_msg->primary_hop_limit;
999 primary_path->traffic_class = req_msg->primary_traffic_class;
1000 primary_path->reversible = 1;
1001 primary_path->pkey = req_msg->pkey;
1002 primary_path->sl = cm_req_get_primary_sl(req_msg);
1003 primary_path->mtu_selector = IB_SA_EQ;
1004 primary_path->mtu = cm_req_get_path_mtu(req_msg);
1005 primary_path->rate_selector = IB_SA_EQ;
1006 primary_path->rate = cm_req_get_primary_packet_rate(req_msg);
1007 primary_path->packet_life_time_selector = IB_SA_EQ;
1008 primary_path->packet_life_time =
1009 cm_req_get_primary_local_ack_timeout(req_msg);
1010 primary_path->packet_life_time -= (primary_path->packet_life_time > 0);
1011
1012 if (req_msg->alt_local_lid) {
1013 memset(alt_path, 0, sizeof *alt_path);
1014 alt_path->dgid = req_msg->alt_local_gid;
1015 alt_path->sgid = req_msg->alt_remote_gid;
1016 alt_path->dlid = req_msg->alt_local_lid;
1017 alt_path->slid = req_msg->alt_remote_lid;
1018 alt_path->flow_label = cm_req_get_alt_flow_label(req_msg);
1019 alt_path->hop_limit = req_msg->alt_hop_limit;
1020 alt_path->traffic_class = req_msg->alt_traffic_class;
1021 alt_path->reversible = 1;
1022 alt_path->pkey = req_msg->pkey;
1023 alt_path->sl = cm_req_get_alt_sl(req_msg);
1024 alt_path->mtu_selector = IB_SA_EQ;
1025 alt_path->mtu = cm_req_get_path_mtu(req_msg);
1026 alt_path->rate_selector = IB_SA_EQ;
1027 alt_path->rate = cm_req_get_alt_packet_rate(req_msg);
1028 alt_path->packet_life_time_selector = IB_SA_EQ;
1029 alt_path->packet_life_time =
1030 cm_req_get_alt_local_ack_timeout(req_msg);
1031 alt_path->packet_life_time -= (alt_path->packet_life_time > 0);
1032 }
1033}
1034
1035static void cm_format_req_event(struct cm_work *work,
1036 struct cm_id_private *cm_id_priv,
1037 struct ib_cm_id *listen_id)
1038{
1039 struct cm_req_msg *req_msg;
1040 struct ib_cm_req_event_param *param;
1041
1042 req_msg = (struct cm_req_msg *)work->mad_recv_wc->recv_buf.mad;
1043 param = &work->cm_event.param.req_rcvd;
1044 param->listen_id = listen_id;
1045 param->device = cm_id_priv->av.port->mad_agent->device;
1046 param->port = cm_id_priv->av.port->port_num;
1047 param->primary_path = &work->path[0];
1048 if (req_msg->alt_local_lid)
1049 param->alternate_path = &work->path[1];
1050 else
1051 param->alternate_path = NULL;
1052 param->remote_ca_guid = req_msg->local_ca_guid;
1053 param->remote_qkey = be32_to_cpu(req_msg->local_qkey);
1054 param->remote_qpn = be32_to_cpu(cm_req_get_local_qpn(req_msg));
1055 param->qp_type = cm_req_get_qp_type(req_msg);
1056 param->starting_psn = be32_to_cpu(cm_req_get_starting_psn(req_msg));
1057 param->responder_resources = cm_req_get_init_depth(req_msg);
1058 param->initiator_depth = cm_req_get_resp_res(req_msg);
1059 param->local_cm_response_timeout =
1060 cm_req_get_remote_resp_timeout(req_msg);
1061 param->flow_control = cm_req_get_flow_ctrl(req_msg);
1062 param->remote_cm_response_timeout =
1063 cm_req_get_local_resp_timeout(req_msg);
1064 param->retry_count = cm_req_get_retry_count(req_msg);
1065 param->rnr_retry_count = cm_req_get_rnr_retry_count(req_msg);
1066 param->srq = cm_req_get_srq(req_msg);
1067 work->cm_event.private_data = &req_msg->private_data;
1068}
1069
1070static void cm_process_work(struct cm_id_private *cm_id_priv,
1071 struct cm_work *work)
1072{
1073 unsigned long flags;
1074 int ret;
1075
1076 /* We will typically only have the current event to report. */
1077 ret = cm_id_priv->id.cm_handler(&cm_id_priv->id, &work->cm_event);
1078 cm_free_work(work);
1079
1080 while (!ret && !atomic_add_negative(-1, &cm_id_priv->work_count)) {
1081 spin_lock_irqsave(&cm_id_priv->lock, flags);
1082 work = cm_dequeue_work(cm_id_priv);
1083 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1084 BUG_ON(!work);
1085 ret = cm_id_priv->id.cm_handler(&cm_id_priv->id,
1086 &work->cm_event);
1087 cm_free_work(work);
1088 }
1089 cm_deref_id(cm_id_priv);
1090 if (ret)
1091 ib_destroy_cm_id(&cm_id_priv->id);
1092}
1093
1094static void cm_format_mra(struct cm_mra_msg *mra_msg,
1095 struct cm_id_private *cm_id_priv,
1096 enum cm_msg_response msg_mraed, u8 service_timeout,
1097 const void *private_data, u8 private_data_len)
1098{
1099 cm_format_mad_hdr(&mra_msg->hdr, CM_MRA_ATTR_ID, cm_id_priv->tid);
1100 cm_mra_set_msg_mraed(mra_msg, msg_mraed);
1101 mra_msg->local_comm_id = cm_id_priv->id.local_id;
1102 mra_msg->remote_comm_id = cm_id_priv->id.remote_id;
1103 cm_mra_set_service_timeout(mra_msg, service_timeout);
1104
1105 if (private_data && private_data_len)
1106 memcpy(mra_msg->private_data, private_data, private_data_len);
1107}
1108
1109static void cm_format_rej(struct cm_rej_msg *rej_msg,
1110 struct cm_id_private *cm_id_priv,
1111 enum ib_cm_rej_reason reason,
1112 void *ari,
1113 u8 ari_length,
1114 const void *private_data,
1115 u8 private_data_len)
1116{
1117 cm_format_mad_hdr(&rej_msg->hdr, CM_REJ_ATTR_ID, cm_id_priv->tid);
1118 rej_msg->remote_comm_id = cm_id_priv->id.remote_id;
1119
1120 switch(cm_id_priv->id.state) {
1121 case IB_CM_REQ_RCVD:
1122 rej_msg->local_comm_id = 0;
1123 cm_rej_set_msg_rejected(rej_msg, CM_MSG_RESPONSE_REQ);
1124 break;
1125 case IB_CM_MRA_REQ_SENT:
1126 rej_msg->local_comm_id = cm_id_priv->id.local_id;
1127 cm_rej_set_msg_rejected(rej_msg, CM_MSG_RESPONSE_REQ);
1128 break;
1129 case IB_CM_REP_RCVD:
1130 case IB_CM_MRA_REP_SENT:
1131 rej_msg->local_comm_id = cm_id_priv->id.local_id;
1132 cm_rej_set_msg_rejected(rej_msg, CM_MSG_RESPONSE_REP);
1133 break;
1134 default:
1135 rej_msg->local_comm_id = cm_id_priv->id.local_id;
1136 cm_rej_set_msg_rejected(rej_msg, CM_MSG_RESPONSE_OTHER);
1137 break;
1138 }
1139
1140 rej_msg->reason = reason;
1141 if (ari && ari_length) {
1142 cm_rej_set_reject_info_len(rej_msg, ari_length);
1143 memcpy(rej_msg->ari, ari, ari_length);
1144 }
1145
1146 if (private_data && private_data_len)
1147 memcpy(rej_msg->private_data, private_data, private_data_len);
1148}
1149
1150static void cm_dup_req_handler(struct cm_work *work,
1151 struct cm_id_private *cm_id_priv)
1152{
1153 struct ib_mad_send_buf *msg = NULL;
1154 struct ib_send_wr *bad_send_wr;
1155 unsigned long flags;
1156 int ret;
1157
1158 /* Quick state check to discard duplicate REQs. */
1159 if (cm_id_priv->id.state == IB_CM_REQ_RCVD)
1160 return;
1161
1162 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
1163 if (ret)
1164 return;
1165
1166 spin_lock_irqsave(&cm_id_priv->lock, flags);
1167 switch (cm_id_priv->id.state) {
1168 case IB_CM_MRA_REQ_SENT:
1169 cm_format_mra((struct cm_mra_msg *) msg->mad, cm_id_priv,
1170 CM_MSG_RESPONSE_REQ, cm_id_priv->service_timeout,
1171 cm_id_priv->private_data,
1172 cm_id_priv->private_data_len);
1173 break;
1174 case IB_CM_TIMEWAIT:
1175 cm_format_rej((struct cm_rej_msg *) msg->mad, cm_id_priv,
1176 IB_CM_REJ_STALE_CONN, NULL, 0, NULL, 0);
1177 break;
1178 default:
1179 goto unlock;
1180 }
1181 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1182
1183 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, &msg->send_wr,
1184 &bad_send_wr);
1185 if (ret)
1186 goto free;
1187 return;
1188
1189unlock: spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1190free: cm_free_msg(msg);
1191}
1192
1193static struct cm_id_private * cm_match_req(struct cm_work *work,
1194 struct cm_id_private *cm_id_priv)
1195{
1196 struct cm_id_private *listen_cm_id_priv, *cur_cm_id_priv;
1197 struct cm_timewait_info *timewait_info;
1198 struct cm_req_msg *req_msg;
1199 unsigned long flags;
1200
1201 req_msg = (struct cm_req_msg *)work->mad_recv_wc->recv_buf.mad;
1202
1203 /* Check for duplicate REQ and stale connections. */
1204 spin_lock_irqsave(&cm.lock, flags);
1205 timewait_info = cm_insert_remote_id(cm_id_priv->timewait_info);
1206 if (!timewait_info)
1207 timewait_info = cm_insert_remote_qpn(cm_id_priv->timewait_info);
1208
1209 if (timewait_info) {
1210 cur_cm_id_priv = cm_get_id(timewait_info->work.local_id,
1211 timewait_info->work.remote_id);
1212 spin_unlock_irqrestore(&cm.lock, flags);
1213 if (cur_cm_id_priv) {
1214 cm_dup_req_handler(work, cur_cm_id_priv);
1215 cm_deref_id(cur_cm_id_priv);
1216 } else
1217 cm_issue_rej(work->port, work->mad_recv_wc,
1218 IB_CM_REJ_STALE_CONN, CM_MSG_RESPONSE_REQ,
1219 NULL, 0);
1220 goto error;
1221 }
1222
1223 /* Find matching listen request. */
1224 listen_cm_id_priv = cm_find_listen(req_msg->service_id);
1225 if (!listen_cm_id_priv) {
1226 spin_unlock_irqrestore(&cm.lock, flags);
1227 cm_issue_rej(work->port, work->mad_recv_wc,
1228 IB_CM_REJ_INVALID_SERVICE_ID, CM_MSG_RESPONSE_REQ,
1229 NULL, 0);
1230 goto error;
1231 }
1232 atomic_inc(&listen_cm_id_priv->refcount);
1233 atomic_inc(&cm_id_priv->refcount);
1234 cm_id_priv->id.state = IB_CM_REQ_RCVD;
1235 atomic_inc(&cm_id_priv->work_count);
1236 spin_unlock_irqrestore(&cm.lock, flags);
1237 return listen_cm_id_priv;
1238
1239error: cm_cleanup_timewait(cm_id_priv->timewait_info);
1240 return NULL;
1241}
1242
1243static int cm_req_handler(struct cm_work *work)
1244{
1245 struct ib_cm_id *cm_id;
1246 struct cm_id_private *cm_id_priv, *listen_cm_id_priv;
1247 struct cm_req_msg *req_msg;
1248 int ret;
1249
1250 req_msg = (struct cm_req_msg *)work->mad_recv_wc->recv_buf.mad;
1251
1252 cm_id = ib_create_cm_id(NULL, NULL);
1253 if (IS_ERR(cm_id))
1254 return PTR_ERR(cm_id);
1255
1256 cm_id_priv = container_of(cm_id, struct cm_id_private, id);
1257 cm_id_priv->id.remote_id = req_msg->local_comm_id;
1258 cm_init_av_for_response(work->port, work->mad_recv_wc->wc,
1259 &cm_id_priv->av);
1260 cm_id_priv->timewait_info = cm_create_timewait_info(cm_id_priv->
1261 id.local_id);
1262 if (IS_ERR(cm_id_priv->timewait_info)) {
1263 ret = PTR_ERR(cm_id_priv->timewait_info);
1264 goto error1;
1265 }
1266 cm_id_priv->timewait_info->work.remote_id = req_msg->local_comm_id;
1267 cm_id_priv->timewait_info->remote_ca_guid = req_msg->local_ca_guid;
1268 cm_id_priv->timewait_info->remote_qpn = cm_req_get_local_qpn(req_msg);
1269
1270 listen_cm_id_priv = cm_match_req(work, cm_id_priv);
1271 if (!listen_cm_id_priv) {
1272 ret = -EINVAL;
1273 goto error2;
1274 }
1275
1276 cm_id_priv->id.cm_handler = listen_cm_id_priv->id.cm_handler;
1277 cm_id_priv->id.context = listen_cm_id_priv->id.context;
1278 cm_id_priv->id.service_id = req_msg->service_id;
1279 cm_id_priv->id.service_mask = ~0ULL;
1280
1281 cm_format_paths_from_req(req_msg, &work->path[0], &work->path[1]);
1282 ret = cm_init_av_by_path(&work->path[0], &cm_id_priv->av);
1283 if (ret)
1284 goto error3;
1285 if (req_msg->alt_local_lid) {
1286 ret = cm_init_av_by_path(&work->path[1], &cm_id_priv->alt_av);
1287 if (ret)
1288 goto error3;
1289 }
1290 cm_id_priv->tid = req_msg->hdr.tid;
1291 cm_id_priv->timeout_ms = cm_convert_to_ms(
1292 cm_req_get_local_resp_timeout(req_msg));
1293 cm_id_priv->max_cm_retries = cm_req_get_max_cm_retries(req_msg);
1294 cm_id_priv->remote_qpn = cm_req_get_local_qpn(req_msg);
1295 cm_id_priv->initiator_depth = cm_req_get_resp_res(req_msg);
1296 cm_id_priv->responder_resources = cm_req_get_init_depth(req_msg);
1297 cm_id_priv->path_mtu = cm_req_get_path_mtu(req_msg);
1298 cm_id_priv->sq_psn = cm_req_get_starting_psn(req_msg);
1299 cm_id_priv->local_ack_timeout =
1300 cm_req_get_primary_local_ack_timeout(req_msg);
1301 cm_id_priv->retry_count = cm_req_get_retry_count(req_msg);
1302 cm_id_priv->rnr_retry_count = cm_req_get_rnr_retry_count(req_msg);
1303
1304 cm_format_req_event(work, cm_id_priv, &listen_cm_id_priv->id);
1305 cm_process_work(cm_id_priv, work);
1306 cm_deref_id(listen_cm_id_priv);
1307 return 0;
1308
1309error3: atomic_dec(&cm_id_priv->refcount);
1310 cm_deref_id(listen_cm_id_priv);
1311 cm_cleanup_timewait(cm_id_priv->timewait_info);
1312error2: kfree(cm_id_priv->timewait_info);
1313error1: ib_destroy_cm_id(&cm_id_priv->id);
1314 return ret;
1315}
1316
1317static void cm_format_rep(struct cm_rep_msg *rep_msg,
1318 struct cm_id_private *cm_id_priv,
1319 struct ib_cm_rep_param *param)
1320{
1321 cm_format_mad_hdr(&rep_msg->hdr, CM_REP_ATTR_ID, cm_id_priv->tid);
1322 rep_msg->local_comm_id = cm_id_priv->id.local_id;
1323 rep_msg->remote_comm_id = cm_id_priv->id.remote_id;
1324 cm_rep_set_local_qpn(rep_msg, cpu_to_be32(param->qp_num));
1325 cm_rep_set_starting_psn(rep_msg, cpu_to_be32(param->starting_psn));
1326 rep_msg->resp_resources = param->responder_resources;
1327 rep_msg->initiator_depth = param->initiator_depth;
1328 cm_rep_set_target_ack_delay(rep_msg, param->target_ack_delay);
1329 cm_rep_set_failover(rep_msg, param->failover_accepted);
1330 cm_rep_set_flow_ctrl(rep_msg, param->flow_control);
1331 cm_rep_set_rnr_retry_count(rep_msg, param->rnr_retry_count);
1332 cm_rep_set_srq(rep_msg, param->srq);
1333 rep_msg->local_ca_guid = cm_id_priv->av.port->cm_dev->ca_guid;
1334
1335 if (param->private_data && param->private_data_len)
1336 memcpy(rep_msg->private_data, param->private_data,
1337 param->private_data_len);
1338}
1339
1340int ib_send_cm_rep(struct ib_cm_id *cm_id,
1341 struct ib_cm_rep_param *param)
1342{
1343 struct cm_id_private *cm_id_priv;
1344 struct ib_mad_send_buf *msg;
1345 struct cm_rep_msg *rep_msg;
1346 struct ib_send_wr *bad_send_wr;
1347 unsigned long flags;
1348 int ret;
1349
1350 if (param->private_data &&
1351 param->private_data_len > IB_CM_REP_PRIVATE_DATA_SIZE)
1352 return -EINVAL;
1353
1354 cm_id_priv = container_of(cm_id, struct cm_id_private, id);
1355 spin_lock_irqsave(&cm_id_priv->lock, flags);
1356 if (cm_id->state != IB_CM_REQ_RCVD &&
1357 cm_id->state != IB_CM_MRA_REQ_SENT) {
1358 ret = -EINVAL;
1359 goto out;
1360 }
1361
1362 ret = cm_alloc_msg(cm_id_priv, &msg);
1363 if (ret)
1364 goto out;
1365
1366 rep_msg = (struct cm_rep_msg *) msg->mad;
1367 cm_format_rep(rep_msg, cm_id_priv, param);
1368 msg->send_wr.wr.ud.timeout_ms = cm_id_priv->timeout_ms;
1369 msg->context[1] = (void *) (unsigned long) IB_CM_REP_SENT;
1370
1371 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent,
1372 &msg->send_wr, &bad_send_wr);
1373 if (ret) {
1374 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1375 cm_free_msg(msg);
1376 return ret;
1377 }
1378
1379 cm_id->state = IB_CM_REP_SENT;
1380 cm_id_priv->msg = msg;
1381 cm_id_priv->initiator_depth = param->initiator_depth;
1382 cm_id_priv->responder_resources = param->responder_resources;
1383 cm_id_priv->rq_psn = cm_rep_get_starting_psn(rep_msg);
1384 cm_id_priv->local_qpn = cm_rep_get_local_qpn(rep_msg);
1385
1386out: spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1387 return ret;
1388}
1389EXPORT_SYMBOL(ib_send_cm_rep);
1390
1391static void cm_format_rtu(struct cm_rtu_msg *rtu_msg,
1392 struct cm_id_private *cm_id_priv,
1393 const void *private_data,
1394 u8 private_data_len)
1395{
1396 cm_format_mad_hdr(&rtu_msg->hdr, CM_RTU_ATTR_ID, cm_id_priv->tid);
1397 rtu_msg->local_comm_id = cm_id_priv->id.local_id;
1398 rtu_msg->remote_comm_id = cm_id_priv->id.remote_id;
1399
1400 if (private_data && private_data_len)
1401 memcpy(rtu_msg->private_data, private_data, private_data_len);
1402}
1403
1404int ib_send_cm_rtu(struct ib_cm_id *cm_id,
1405 const void *private_data,
1406 u8 private_data_len)
1407{
1408 struct cm_id_private *cm_id_priv;
1409 struct ib_mad_send_buf *msg;
1410 struct ib_send_wr *bad_send_wr;
1411 unsigned long flags;
1412 void *data;
1413 int ret;
1414
1415 if (private_data && private_data_len > IB_CM_RTU_PRIVATE_DATA_SIZE)
1416 return -EINVAL;
1417
1418 data = cm_copy_private_data(private_data, private_data_len);
1419 if (IS_ERR(data))
1420 return PTR_ERR(data);
1421
1422 cm_id_priv = container_of(cm_id, struct cm_id_private, id);
1423 spin_lock_irqsave(&cm_id_priv->lock, flags);
1424 if (cm_id->state != IB_CM_REP_RCVD &&
1425 cm_id->state != IB_CM_MRA_REP_SENT) {
1426 ret = -EINVAL;
1427 goto error;
1428 }
1429
1430 ret = cm_alloc_msg(cm_id_priv, &msg);
1431 if (ret)
1432 goto error;
1433
1434 cm_format_rtu((struct cm_rtu_msg *) msg->mad, cm_id_priv,
1435 private_data, private_data_len);
1436
1437 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent,
1438 &msg->send_wr, &bad_send_wr);
1439 if (ret) {
1440 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1441 cm_free_msg(msg);
1442 kfree(data);
1443 return ret;
1444 }
1445
1446 cm_id->state = IB_CM_ESTABLISHED;
1447 cm_set_private_data(cm_id_priv, data, private_data_len);
1448 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1449 return 0;
1450
1451error: spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1452 kfree(data);
1453 return ret;
1454}
1455EXPORT_SYMBOL(ib_send_cm_rtu);
1456
1457static void cm_format_rep_event(struct cm_work *work)
1458{
1459 struct cm_rep_msg *rep_msg;
1460 struct ib_cm_rep_event_param *param;
1461
1462 rep_msg = (struct cm_rep_msg *)work->mad_recv_wc->recv_buf.mad;
1463 param = &work->cm_event.param.rep_rcvd;
1464 param->remote_ca_guid = rep_msg->local_ca_guid;
1465 param->remote_qkey = be32_to_cpu(rep_msg->local_qkey);
1466 param->remote_qpn = be32_to_cpu(cm_rep_get_local_qpn(rep_msg));
1467 param->starting_psn = be32_to_cpu(cm_rep_get_starting_psn(rep_msg));
1468 param->responder_resources = rep_msg->initiator_depth;
1469 param->initiator_depth = rep_msg->resp_resources;
1470 param->target_ack_delay = cm_rep_get_target_ack_delay(rep_msg);
1471 param->failover_accepted = cm_rep_get_failover(rep_msg);
1472 param->flow_control = cm_rep_get_flow_ctrl(rep_msg);
1473 param->rnr_retry_count = cm_rep_get_rnr_retry_count(rep_msg);
1474 param->srq = cm_rep_get_srq(rep_msg);
1475 work->cm_event.private_data = &rep_msg->private_data;
1476}
1477
1478static void cm_dup_rep_handler(struct cm_work *work)
1479{
1480 struct cm_id_private *cm_id_priv;
1481 struct cm_rep_msg *rep_msg;
1482 struct ib_mad_send_buf *msg = NULL;
1483 struct ib_send_wr *bad_send_wr;
1484 unsigned long flags;
1485 int ret;
1486
1487 rep_msg = (struct cm_rep_msg *) work->mad_recv_wc->recv_buf.mad;
1488 cm_id_priv = cm_acquire_id(rep_msg->remote_comm_id,
1489 rep_msg->local_comm_id);
1490 if (!cm_id_priv)
1491 return;
1492
1493 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
1494 if (ret)
1495 goto deref;
1496
1497 spin_lock_irqsave(&cm_id_priv->lock, flags);
1498 if (cm_id_priv->id.state == IB_CM_ESTABLISHED)
1499 cm_format_rtu((struct cm_rtu_msg *) msg->mad, cm_id_priv,
1500 cm_id_priv->private_data,
1501 cm_id_priv->private_data_len);
1502 else if (cm_id_priv->id.state == IB_CM_MRA_REP_SENT)
1503 cm_format_mra((struct cm_mra_msg *) msg->mad, cm_id_priv,
1504 CM_MSG_RESPONSE_REP, cm_id_priv->service_timeout,
1505 cm_id_priv->private_data,
1506 cm_id_priv->private_data_len);
1507 else
1508 goto unlock;
1509 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1510
1511 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, &msg->send_wr,
1512 &bad_send_wr);
1513 if (ret)
1514 goto free;
1515 goto deref;
1516
1517unlock: spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1518free: cm_free_msg(msg);
1519deref: cm_deref_id(cm_id_priv);
1520}
1521
1522static int cm_rep_handler(struct cm_work *work)
1523{
1524 struct cm_id_private *cm_id_priv;
1525 struct cm_rep_msg *rep_msg;
1526 unsigned long flags;
1527 int ret;
1528
1529 rep_msg = (struct cm_rep_msg *)work->mad_recv_wc->recv_buf.mad;
1530 cm_id_priv = cm_acquire_id(rep_msg->remote_comm_id, 0);
1531 if (!cm_id_priv) {
1532 cm_dup_rep_handler(work);
1533 return -EINVAL;
1534 }
1535
1536 cm_id_priv->timewait_info->work.remote_id = rep_msg->local_comm_id;
1537 cm_id_priv->timewait_info->remote_ca_guid = rep_msg->local_ca_guid;
1538 cm_id_priv->timewait_info->remote_qpn = cm_rep_get_local_qpn(rep_msg);
1539
1540 spin_lock_irqsave(&cm.lock, flags);
1541 /* Check for duplicate REP. */
1542 if (cm_insert_remote_id(cm_id_priv->timewait_info)) {
1543 spin_unlock_irqrestore(&cm.lock, flags);
1544 ret = -EINVAL;
1545 goto error;
1546 }
1547 /* Check for a stale connection. */
1548 if (cm_insert_remote_qpn(cm_id_priv->timewait_info)) {
1549 spin_unlock_irqrestore(&cm.lock, flags);
1550 cm_issue_rej(work->port, work->mad_recv_wc,
1551 IB_CM_REJ_STALE_CONN, CM_MSG_RESPONSE_REP,
1552 NULL, 0);
1553 ret = -EINVAL;
1554 goto error;
1555 }
1556 spin_unlock_irqrestore(&cm.lock, flags);
1557
1558 cm_format_rep_event(work);
1559
1560 spin_lock_irqsave(&cm_id_priv->lock, flags);
1561 switch (cm_id_priv->id.state) {
1562 case IB_CM_REQ_SENT:
1563 case IB_CM_MRA_REQ_RCVD:
1564 break;
1565 default:
1566 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1567 ret = -EINVAL;
1568 goto error;
1569 }
1570 cm_id_priv->id.state = IB_CM_REP_RCVD;
1571 cm_id_priv->id.remote_id = rep_msg->local_comm_id;
1572 cm_id_priv->remote_qpn = cm_rep_get_local_qpn(rep_msg);
1573 cm_id_priv->initiator_depth = rep_msg->resp_resources;
1574 cm_id_priv->responder_resources = rep_msg->initiator_depth;
1575 cm_id_priv->sq_psn = cm_rep_get_starting_psn(rep_msg);
1576 cm_id_priv->rnr_retry_count = cm_rep_get_rnr_retry_count(rep_msg);
1577
1578 /* todo: handle peer_to_peer */
1579
1580 ib_cancel_mad(cm_id_priv->av.port->mad_agent,
1581 (unsigned long) cm_id_priv->msg);
1582 ret = atomic_inc_and_test(&cm_id_priv->work_count);
1583 if (!ret)
1584 list_add_tail(&work->list, &cm_id_priv->work_list);
1585 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1586
1587 if (ret)
1588 cm_process_work(cm_id_priv, work);
1589 else
1590 cm_deref_id(cm_id_priv);
1591 return 0;
1592
1593error: cm_cleanup_timewait(cm_id_priv->timewait_info);
1594 cm_deref_id(cm_id_priv);
1595 return ret;
1596}
1597
1598static int cm_establish_handler(struct cm_work *work)
1599{
1600 struct cm_id_private *cm_id_priv;
1601 unsigned long flags;
1602 int ret;
1603
1604 /* See comment in ib_cm_establish about lookup. */
1605 cm_id_priv = cm_acquire_id(work->local_id, work->remote_id);
1606 if (!cm_id_priv)
1607 return -EINVAL;
1608
1609 spin_lock_irqsave(&cm_id_priv->lock, flags);
1610 if (cm_id_priv->id.state != IB_CM_ESTABLISHED) {
1611 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1612 goto out;
1613 }
1614
1615 ib_cancel_mad(cm_id_priv->av.port->mad_agent,
1616 (unsigned long) cm_id_priv->msg);
1617 ret = atomic_inc_and_test(&cm_id_priv->work_count);
1618 if (!ret)
1619 list_add_tail(&work->list, &cm_id_priv->work_list);
1620 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1621
1622 if (ret)
1623 cm_process_work(cm_id_priv, work);
1624 else
1625 cm_deref_id(cm_id_priv);
1626 return 0;
1627out:
1628 cm_deref_id(cm_id_priv);
1629 return -EINVAL;
1630}
1631
1632static int cm_rtu_handler(struct cm_work *work)
1633{
1634 struct cm_id_private *cm_id_priv;
1635 struct cm_rtu_msg *rtu_msg;
1636 unsigned long flags;
1637 int ret;
1638
1639 rtu_msg = (struct cm_rtu_msg *)work->mad_recv_wc->recv_buf.mad;
1640 cm_id_priv = cm_acquire_id(rtu_msg->remote_comm_id,
1641 rtu_msg->local_comm_id);
1642 if (!cm_id_priv)
1643 return -EINVAL;
1644
1645 work->cm_event.private_data = &rtu_msg->private_data;
1646
1647 spin_lock_irqsave(&cm_id_priv->lock, flags);
1648 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
1649 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
1650 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1651 goto out;
1652 }
1653 cm_id_priv->id.state = IB_CM_ESTABLISHED;
1654
1655 ib_cancel_mad(cm_id_priv->av.port->mad_agent,
1656 (unsigned long) cm_id_priv->msg);
1657 ret = atomic_inc_and_test(&cm_id_priv->work_count);
1658 if (!ret)
1659 list_add_tail(&work->list, &cm_id_priv->work_list);
1660 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1661
1662 if (ret)
1663 cm_process_work(cm_id_priv, work);
1664 else
1665 cm_deref_id(cm_id_priv);
1666 return 0;
1667out:
1668 cm_deref_id(cm_id_priv);
1669 return -EINVAL;
1670}
1671
1672static void cm_format_dreq(struct cm_dreq_msg *dreq_msg,
1673 struct cm_id_private *cm_id_priv,
1674 const void *private_data,
1675 u8 private_data_len)
1676{
1677 cm_format_mad_hdr(&dreq_msg->hdr, CM_DREQ_ATTR_ID,
1678 cm_form_tid(cm_id_priv, CM_MSG_SEQUENCE_DREQ));
1679 dreq_msg->local_comm_id = cm_id_priv->id.local_id;
1680 dreq_msg->remote_comm_id = cm_id_priv->id.remote_id;
1681 cm_dreq_set_remote_qpn(dreq_msg, cm_id_priv->remote_qpn);
1682
1683 if (private_data && private_data_len)
1684 memcpy(dreq_msg->private_data, private_data, private_data_len);
1685}
1686
1687int ib_send_cm_dreq(struct ib_cm_id *cm_id,
1688 const void *private_data,
1689 u8 private_data_len)
1690{
1691 struct cm_id_private *cm_id_priv;
1692 struct ib_mad_send_buf *msg;
1693 struct ib_send_wr *bad_send_wr;
1694 unsigned long flags;
1695 int ret;
1696
1697 if (private_data && private_data_len > IB_CM_DREQ_PRIVATE_DATA_SIZE)
1698 return -EINVAL;
1699
1700 cm_id_priv = container_of(cm_id, struct cm_id_private, id);
1701 spin_lock_irqsave(&cm_id_priv->lock, flags);
1702 if (cm_id->state != IB_CM_ESTABLISHED) {
1703 ret = -EINVAL;
1704 goto out;
1705 }
1706
1707 ret = cm_alloc_msg(cm_id_priv, &msg);
1708 if (ret) {
1709 cm_enter_timewait(cm_id_priv);
1710 goto out;
1711 }
1712
1713 cm_format_dreq((struct cm_dreq_msg *) msg->mad, cm_id_priv,
1714 private_data, private_data_len);
1715 msg->send_wr.wr.ud.timeout_ms = cm_id_priv->timeout_ms;
1716 msg->context[1] = (void *) (unsigned long) IB_CM_DREQ_SENT;
1717
1718 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent,
1719 &msg->send_wr, &bad_send_wr);
1720 if (ret) {
1721 cm_enter_timewait(cm_id_priv);
1722 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1723 cm_free_msg(msg);
1724 return ret;
1725 }
1726
1727 cm_id->state = IB_CM_DREQ_SENT;
1728 cm_id_priv->msg = msg;
1729out: spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1730 return ret;
1731}
1732EXPORT_SYMBOL(ib_send_cm_dreq);
1733
1734static void cm_format_drep(struct cm_drep_msg *drep_msg,
1735 struct cm_id_private *cm_id_priv,
1736 const void *private_data,
1737 u8 private_data_len)
1738{
1739 cm_format_mad_hdr(&drep_msg->hdr, CM_DREP_ATTR_ID, cm_id_priv->tid);
1740 drep_msg->local_comm_id = cm_id_priv->id.local_id;
1741 drep_msg->remote_comm_id = cm_id_priv->id.remote_id;
1742
1743 if (private_data && private_data_len)
1744 memcpy(drep_msg->private_data, private_data, private_data_len);
1745}
1746
1747int ib_send_cm_drep(struct ib_cm_id *cm_id,
1748 const void *private_data,
1749 u8 private_data_len)
1750{
1751 struct cm_id_private *cm_id_priv;
1752 struct ib_mad_send_buf *msg;
1753 struct ib_send_wr *bad_send_wr;
1754 unsigned long flags;
1755 void *data;
1756 int ret;
1757
1758 if (private_data && private_data_len > IB_CM_DREP_PRIVATE_DATA_SIZE)
1759 return -EINVAL;
1760
1761 data = cm_copy_private_data(private_data, private_data_len);
1762 if (IS_ERR(data))
1763 return PTR_ERR(data);
1764
1765 cm_id_priv = container_of(cm_id, struct cm_id_private, id);
1766 spin_lock_irqsave(&cm_id_priv->lock, flags);
1767 if (cm_id->state != IB_CM_DREQ_RCVD) {
1768 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1769 kfree(data);
1770 return -EINVAL;
1771 }
1772
1773 cm_set_private_data(cm_id_priv, data, private_data_len);
1774 cm_enter_timewait(cm_id_priv);
1775
1776 ret = cm_alloc_msg(cm_id_priv, &msg);
1777 if (ret)
1778 goto out;
1779
1780 cm_format_drep((struct cm_drep_msg *) msg->mad, cm_id_priv,
1781 private_data, private_data_len);
1782
1783 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent, &msg->send_wr,
1784 &bad_send_wr);
1785 if (ret) {
1786 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1787 cm_free_msg(msg);
1788 return ret;
1789 }
1790
1791out: spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1792 return ret;
1793}
1794EXPORT_SYMBOL(ib_send_cm_drep);
1795
1796static int cm_dreq_handler(struct cm_work *work)
1797{
1798 struct cm_id_private *cm_id_priv;
1799 struct cm_dreq_msg *dreq_msg;
1800 struct ib_mad_send_buf *msg = NULL;
1801 struct ib_send_wr *bad_send_wr;
1802 unsigned long flags;
1803 int ret;
1804
1805 dreq_msg = (struct cm_dreq_msg *)work->mad_recv_wc->recv_buf.mad;
1806 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
1807 dreq_msg->local_comm_id);
1808 if (!cm_id_priv)
1809 return -EINVAL;
1810
1811 work->cm_event.private_data = &dreq_msg->private_data;
1812
1813 spin_lock_irqsave(&cm_id_priv->lock, flags);
1814 if (cm_id_priv->local_qpn != cm_dreq_get_remote_qpn(dreq_msg))
1815 goto unlock;
1816
1817 switch (cm_id_priv->id.state) {
1818 case IB_CM_REP_SENT:
1819 case IB_CM_DREQ_SENT:
1820 ib_cancel_mad(cm_id_priv->av.port->mad_agent,
1821 (unsigned long) cm_id_priv->msg);
1822 break;
1823 case IB_CM_ESTABLISHED:
1824 case IB_CM_MRA_REP_RCVD:
1825 break;
1826 case IB_CM_TIMEWAIT:
1827 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
1828 goto unlock;
1829
1830 cm_format_drep((struct cm_drep_msg *) msg->mad, cm_id_priv,
1831 cm_id_priv->private_data,
1832 cm_id_priv->private_data_len);
1833 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1834
1835 if (ib_post_send_mad(cm_id_priv->av.port->mad_agent,
1836 &msg->send_wr, &bad_send_wr))
1837 cm_free_msg(msg);
1838 goto deref;
1839 default:
1840 goto unlock;
1841 }
1842 cm_id_priv->id.state = IB_CM_DREQ_RCVD;
1843 cm_id_priv->tid = dreq_msg->hdr.tid;
1844 ret = atomic_inc_and_test(&cm_id_priv->work_count);
1845 if (!ret)
1846 list_add_tail(&work->list, &cm_id_priv->work_list);
1847 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1848
1849 if (ret)
1850 cm_process_work(cm_id_priv, work);
1851 else
1852 cm_deref_id(cm_id_priv);
1853 return 0;
1854
1855unlock: spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1856deref: cm_deref_id(cm_id_priv);
1857 return -EINVAL;
1858}
1859
1860static int cm_drep_handler(struct cm_work *work)
1861{
1862 struct cm_id_private *cm_id_priv;
1863 struct cm_drep_msg *drep_msg;
1864 unsigned long flags;
1865 int ret;
1866
1867 drep_msg = (struct cm_drep_msg *)work->mad_recv_wc->recv_buf.mad;
1868 cm_id_priv = cm_acquire_id(drep_msg->remote_comm_id,
1869 drep_msg->local_comm_id);
1870 if (!cm_id_priv)
1871 return -EINVAL;
1872
1873 work->cm_event.private_data = &drep_msg->private_data;
1874
1875 spin_lock_irqsave(&cm_id_priv->lock, flags);
1876 if (cm_id_priv->id.state != IB_CM_DREQ_SENT &&
1877 cm_id_priv->id.state != IB_CM_DREQ_RCVD) {
1878 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1879 goto out;
1880 }
1881 cm_enter_timewait(cm_id_priv);
1882
1883 ib_cancel_mad(cm_id_priv->av.port->mad_agent,
1884 (unsigned long) cm_id_priv->msg);
1885 ret = atomic_inc_and_test(&cm_id_priv->work_count);
1886 if (!ret)
1887 list_add_tail(&work->list, &cm_id_priv->work_list);
1888 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1889
1890 if (ret)
1891 cm_process_work(cm_id_priv, work);
1892 else
1893 cm_deref_id(cm_id_priv);
1894 return 0;
1895out:
1896 cm_deref_id(cm_id_priv);
1897 return -EINVAL;
1898}
1899
1900int ib_send_cm_rej(struct ib_cm_id *cm_id,
1901 enum ib_cm_rej_reason reason,
1902 void *ari,
1903 u8 ari_length,
1904 const void *private_data,
1905 u8 private_data_len)
1906{
1907 struct cm_id_private *cm_id_priv;
1908 struct ib_mad_send_buf *msg;
1909 struct ib_send_wr *bad_send_wr;
1910 unsigned long flags;
1911 int ret;
1912
1913 if ((private_data && private_data_len > IB_CM_REJ_PRIVATE_DATA_SIZE) ||
1914 (ari && ari_length > IB_CM_REJ_ARI_LENGTH))
1915 return -EINVAL;
1916
1917 cm_id_priv = container_of(cm_id, struct cm_id_private, id);
1918
1919 spin_lock_irqsave(&cm_id_priv->lock, flags);
1920 switch (cm_id->state) {
1921 case IB_CM_REQ_SENT:
1922 case IB_CM_MRA_REQ_RCVD:
1923 case IB_CM_REQ_RCVD:
1924 case IB_CM_MRA_REQ_SENT:
1925 case IB_CM_REP_RCVD:
1926 case IB_CM_MRA_REP_SENT:
1927 ret = cm_alloc_msg(cm_id_priv, &msg);
1928 if (!ret)
1929 cm_format_rej((struct cm_rej_msg *) msg->mad,
1930 cm_id_priv, reason, ari, ari_length,
1931 private_data, private_data_len);
1932
1933 cm_reset_to_idle(cm_id_priv);
1934 break;
1935 case IB_CM_REP_SENT:
1936 case IB_CM_MRA_REP_RCVD:
1937 ret = cm_alloc_msg(cm_id_priv, &msg);
1938 if (!ret)
1939 cm_format_rej((struct cm_rej_msg *) msg->mad,
1940 cm_id_priv, reason, ari, ari_length,
1941 private_data, private_data_len);
1942
1943 cm_enter_timewait(cm_id_priv);
1944 break;
1945 default:
1946 ret = -EINVAL;
1947 goto out;
1948 }
1949
1950 if (ret)
1951 goto out;
1952
1953 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent,
1954 &msg->send_wr, &bad_send_wr);
1955 if (ret)
1956 cm_free_msg(msg);
1957
1958out: spin_unlock_irqrestore(&cm_id_priv->lock, flags);
1959 return ret;
1960}
1961EXPORT_SYMBOL(ib_send_cm_rej);
1962
1963static void cm_format_rej_event(struct cm_work *work)
1964{
1965 struct cm_rej_msg *rej_msg;
1966 struct ib_cm_rej_event_param *param;
1967
1968 rej_msg = (struct cm_rej_msg *)work->mad_recv_wc->recv_buf.mad;
1969 param = &work->cm_event.param.rej_rcvd;
1970 param->ari = rej_msg->ari;
1971 param->ari_length = cm_rej_get_reject_info_len(rej_msg);
1972 param->reason = rej_msg->reason;
1973 work->cm_event.private_data = &rej_msg->private_data;
1974}
1975
1976static struct cm_id_private * cm_acquire_rejected_id(struct cm_rej_msg *rej_msg)
1977{
1978 struct cm_timewait_info *timewait_info;
1979 struct cm_id_private *cm_id_priv;
1980 unsigned long flags;
1981 u32 remote_id;
1982
1983 remote_id = rej_msg->local_comm_id;
1984
1985 if (rej_msg->reason == IB_CM_REJ_TIMEOUT) {
1986 spin_lock_irqsave(&cm.lock, flags);
1987 timewait_info = cm_find_remote_id( *((u64 *) rej_msg->ari),
1988 remote_id);
1989 if (!timewait_info) {
1990 spin_unlock_irqrestore(&cm.lock, flags);
1991 return NULL;
1992 }
1993 cm_id_priv = idr_find(&cm.local_id_table,
1994 (int) timewait_info->work.local_id);
1995 if (cm_id_priv) {
1996 if (cm_id_priv->id.remote_id == remote_id)
1997 atomic_inc(&cm_id_priv->refcount);
1998 else
1999 cm_id_priv = NULL;
2000 }
2001 spin_unlock_irqrestore(&cm.lock, flags);
2002 } else if (cm_rej_get_msg_rejected(rej_msg) == CM_MSG_RESPONSE_REQ)
2003 cm_id_priv = cm_acquire_id(rej_msg->remote_comm_id, 0);
2004 else
2005 cm_id_priv = cm_acquire_id(rej_msg->remote_comm_id, remote_id);
2006
2007 return cm_id_priv;
2008}
2009
2010static int cm_rej_handler(struct cm_work *work)
2011{
2012 struct cm_id_private *cm_id_priv;
2013 struct cm_rej_msg *rej_msg;
2014 unsigned long flags;
2015 int ret;
2016
2017 rej_msg = (struct cm_rej_msg *)work->mad_recv_wc->recv_buf.mad;
2018 cm_id_priv = cm_acquire_rejected_id(rej_msg);
2019 if (!cm_id_priv)
2020 return -EINVAL;
2021
2022 cm_format_rej_event(work);
2023
2024 spin_lock_irqsave(&cm_id_priv->lock, flags);
2025 switch (cm_id_priv->id.state) {
2026 case IB_CM_REQ_SENT:
2027 case IB_CM_MRA_REQ_RCVD:
2028 case IB_CM_REP_SENT:
2029 case IB_CM_MRA_REP_RCVD:
2030 ib_cancel_mad(cm_id_priv->av.port->mad_agent,
2031 (unsigned long) cm_id_priv->msg);
2032 /* fall through */
2033 case IB_CM_REQ_RCVD:
2034 case IB_CM_MRA_REQ_SENT:
2035 if (rej_msg->reason == IB_CM_REJ_STALE_CONN)
2036 cm_enter_timewait(cm_id_priv);
2037 else
2038 cm_reset_to_idle(cm_id_priv);
2039 break;
2040 case IB_CM_DREQ_SENT:
2041 ib_cancel_mad(cm_id_priv->av.port->mad_agent,
2042 (unsigned long) cm_id_priv->msg);
2043 /* fall through */
2044 case IB_CM_REP_RCVD:
2045 case IB_CM_MRA_REP_SENT:
2046 case IB_CM_ESTABLISHED:
2047 cm_enter_timewait(cm_id_priv);
2048 break;
2049 default:
2050 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2051 ret = -EINVAL;
2052 goto out;
2053 }
2054
2055 ret = atomic_inc_and_test(&cm_id_priv->work_count);
2056 if (!ret)
2057 list_add_tail(&work->list, &cm_id_priv->work_list);
2058 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2059
2060 if (ret)
2061 cm_process_work(cm_id_priv, work);
2062 else
2063 cm_deref_id(cm_id_priv);
2064 return 0;
2065out:
2066 cm_deref_id(cm_id_priv);
2067 return -EINVAL;
2068}
2069
2070int ib_send_cm_mra(struct ib_cm_id *cm_id,
2071 u8 service_timeout,
2072 const void *private_data,
2073 u8 private_data_len)
2074{
2075 struct cm_id_private *cm_id_priv;
2076 struct ib_mad_send_buf *msg;
2077 struct ib_send_wr *bad_send_wr;
2078 void *data;
2079 unsigned long flags;
2080 int ret;
2081
2082 if (private_data && private_data_len > IB_CM_MRA_PRIVATE_DATA_SIZE)
2083 return -EINVAL;
2084
2085 data = cm_copy_private_data(private_data, private_data_len);
2086 if (IS_ERR(data))
2087 return PTR_ERR(data);
2088
2089 cm_id_priv = container_of(cm_id, struct cm_id_private, id);
2090
2091 spin_lock_irqsave(&cm_id_priv->lock, flags);
2092 switch(cm_id_priv->id.state) {
2093 case IB_CM_REQ_RCVD:
2094 ret = cm_alloc_msg(cm_id_priv, &msg);
2095 if (ret)
2096 goto error1;
2097
2098 cm_format_mra((struct cm_mra_msg *) msg->mad, cm_id_priv,
2099 CM_MSG_RESPONSE_REQ, service_timeout,
2100 private_data, private_data_len);
2101 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent,
2102 &msg->send_wr, &bad_send_wr);
2103 if (ret)
2104 goto error2;
2105 cm_id->state = IB_CM_MRA_REQ_SENT;
2106 break;
2107 case IB_CM_REP_RCVD:
2108 ret = cm_alloc_msg(cm_id_priv, &msg);
2109 if (ret)
2110 goto error1;
2111
2112 cm_format_mra((struct cm_mra_msg *) msg->mad, cm_id_priv,
2113 CM_MSG_RESPONSE_REP, service_timeout,
2114 private_data, private_data_len);
2115 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent,
2116 &msg->send_wr, &bad_send_wr);
2117 if (ret)
2118 goto error2;
2119 cm_id->state = IB_CM_MRA_REP_SENT;
2120 break;
2121 case IB_CM_ESTABLISHED:
2122 ret = cm_alloc_msg(cm_id_priv, &msg);
2123 if (ret)
2124 goto error1;
2125
2126 cm_format_mra((struct cm_mra_msg *) msg->mad, cm_id_priv,
2127 CM_MSG_RESPONSE_OTHER, service_timeout,
2128 private_data, private_data_len);
2129 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent,
2130 &msg->send_wr, &bad_send_wr);
2131 if (ret)
2132 goto error2;
2133 cm_id->lap_state = IB_CM_MRA_LAP_SENT;
2134 break;
2135 default:
2136 ret = -EINVAL;
2137 goto error1;
2138 }
2139 cm_id_priv->service_timeout = service_timeout;
2140 cm_set_private_data(cm_id_priv, data, private_data_len);
2141 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2142 return 0;
2143
2144error1: spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2145 kfree(data);
2146 return ret;
2147
2148error2: spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2149 kfree(data);
2150 cm_free_msg(msg);
2151 return ret;
2152}
2153EXPORT_SYMBOL(ib_send_cm_mra);
2154
2155static struct cm_id_private * cm_acquire_mraed_id(struct cm_mra_msg *mra_msg)
2156{
2157 switch (cm_mra_get_msg_mraed(mra_msg)) {
2158 case CM_MSG_RESPONSE_REQ:
2159 return cm_acquire_id(mra_msg->remote_comm_id, 0);
2160 case CM_MSG_RESPONSE_REP:
2161 case CM_MSG_RESPONSE_OTHER:
2162 return cm_acquire_id(mra_msg->remote_comm_id,
2163 mra_msg->local_comm_id);
2164 default:
2165 return NULL;
2166 }
2167}
2168
2169static int cm_mra_handler(struct cm_work *work)
2170{
2171 struct cm_id_private *cm_id_priv;
2172 struct cm_mra_msg *mra_msg;
2173 unsigned long flags;
2174 int timeout, ret;
2175
2176 mra_msg = (struct cm_mra_msg *)work->mad_recv_wc->recv_buf.mad;
2177 cm_id_priv = cm_acquire_mraed_id(mra_msg);
2178 if (!cm_id_priv)
2179 return -EINVAL;
2180
2181 work->cm_event.private_data = &mra_msg->private_data;
2182 work->cm_event.param.mra_rcvd.service_timeout =
2183 cm_mra_get_service_timeout(mra_msg);
2184 timeout = cm_convert_to_ms(cm_mra_get_service_timeout(mra_msg)) +
2185 cm_convert_to_ms(cm_id_priv->av.packet_life_time);
2186
2187 spin_lock_irqsave(&cm_id_priv->lock, flags);
2188 switch (cm_id_priv->id.state) {
2189 case IB_CM_REQ_SENT:
2190 if (cm_mra_get_msg_mraed(mra_msg) != CM_MSG_RESPONSE_REQ ||
2191 ib_modify_mad(cm_id_priv->av.port->mad_agent,
2192 (unsigned long) cm_id_priv->msg, timeout))
2193 goto out;
2194 cm_id_priv->id.state = IB_CM_MRA_REQ_RCVD;
2195 break;
2196 case IB_CM_REP_SENT:
2197 if (cm_mra_get_msg_mraed(mra_msg) != CM_MSG_RESPONSE_REP ||
2198 ib_modify_mad(cm_id_priv->av.port->mad_agent,
2199 (unsigned long) cm_id_priv->msg, timeout))
2200 goto out;
2201 cm_id_priv->id.state = IB_CM_MRA_REP_RCVD;
2202 break;
2203 case IB_CM_ESTABLISHED:
2204 if (cm_mra_get_msg_mraed(mra_msg) != CM_MSG_RESPONSE_OTHER ||
2205 cm_id_priv->id.lap_state != IB_CM_LAP_SENT ||
2206 ib_modify_mad(cm_id_priv->av.port->mad_agent,
2207 (unsigned long) cm_id_priv->msg, timeout))
2208 goto out;
2209 cm_id_priv->id.lap_state = IB_CM_MRA_LAP_RCVD;
2210 break;
2211 default:
2212 goto out;
2213 }
2214
2215 cm_id_priv->msg->context[1] = (void *) (unsigned long)
2216 cm_id_priv->id.state;
2217 ret = atomic_inc_and_test(&cm_id_priv->work_count);
2218 if (!ret)
2219 list_add_tail(&work->list, &cm_id_priv->work_list);
2220 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2221
2222 if (ret)
2223 cm_process_work(cm_id_priv, work);
2224 else
2225 cm_deref_id(cm_id_priv);
2226 return 0;
2227out:
2228 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2229 cm_deref_id(cm_id_priv);
2230 return -EINVAL;
2231}
2232
2233static void cm_format_lap(struct cm_lap_msg *lap_msg,
2234 struct cm_id_private *cm_id_priv,
2235 struct ib_sa_path_rec *alternate_path,
2236 const void *private_data,
2237 u8 private_data_len)
2238{
2239 cm_format_mad_hdr(&lap_msg->hdr, CM_LAP_ATTR_ID,
2240 cm_form_tid(cm_id_priv, CM_MSG_SEQUENCE_LAP));
2241 lap_msg->local_comm_id = cm_id_priv->id.local_id;
2242 lap_msg->remote_comm_id = cm_id_priv->id.remote_id;
2243 cm_lap_set_remote_qpn(lap_msg, cm_id_priv->remote_qpn);
2244 /* todo: need remote CM response timeout */
2245 cm_lap_set_remote_resp_timeout(lap_msg, 0x1F);
2246 lap_msg->alt_local_lid = alternate_path->slid;
2247 lap_msg->alt_remote_lid = alternate_path->dlid;
2248 lap_msg->alt_local_gid = alternate_path->sgid;
2249 lap_msg->alt_remote_gid = alternate_path->dgid;
2250 cm_lap_set_flow_label(lap_msg, alternate_path->flow_label);
2251 cm_lap_set_traffic_class(lap_msg, alternate_path->traffic_class);
2252 lap_msg->alt_hop_limit = alternate_path->hop_limit;
2253 cm_lap_set_packet_rate(lap_msg, alternate_path->rate);
2254 cm_lap_set_sl(lap_msg, alternate_path->sl);
2255 cm_lap_set_subnet_local(lap_msg, 1); /* local only... */
2256 cm_lap_set_local_ack_timeout(lap_msg,
2257 min(31, alternate_path->packet_life_time + 1));
2258
2259 if (private_data && private_data_len)
2260 memcpy(lap_msg->private_data, private_data, private_data_len);
2261}
2262
2263int ib_send_cm_lap(struct ib_cm_id *cm_id,
2264 struct ib_sa_path_rec *alternate_path,
2265 const void *private_data,
2266 u8 private_data_len)
2267{
2268 struct cm_id_private *cm_id_priv;
2269 struct ib_mad_send_buf *msg;
2270 struct ib_send_wr *bad_send_wr;
2271 unsigned long flags;
2272 int ret;
2273
2274 if (private_data && private_data_len > IB_CM_LAP_PRIVATE_DATA_SIZE)
2275 return -EINVAL;
2276
2277 cm_id_priv = container_of(cm_id, struct cm_id_private, id);
2278 spin_lock_irqsave(&cm_id_priv->lock, flags);
2279 if (cm_id->state != IB_CM_ESTABLISHED ||
2280 cm_id->lap_state != IB_CM_LAP_IDLE) {
2281 ret = -EINVAL;
2282 goto out;
2283 }
2284
2285 ret = cm_alloc_msg(cm_id_priv, &msg);
2286 if (ret)
2287 goto out;
2288
2289 cm_format_lap((struct cm_lap_msg *) msg->mad, cm_id_priv,
2290 alternate_path, private_data, private_data_len);
2291 msg->send_wr.wr.ud.timeout_ms = cm_id_priv->timeout_ms;
2292 msg->context[1] = (void *) (unsigned long) IB_CM_ESTABLISHED;
2293
2294 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent,
2295 &msg->send_wr, &bad_send_wr);
2296 if (ret) {
2297 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2298 cm_free_msg(msg);
2299 return ret;
2300 }
2301
2302 cm_id->lap_state = IB_CM_LAP_SENT;
2303 cm_id_priv->msg = msg;
2304
2305out: spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2306 return ret;
2307}
2308EXPORT_SYMBOL(ib_send_cm_lap);
2309
2310static void cm_format_path_from_lap(struct ib_sa_path_rec *path,
2311 struct cm_lap_msg *lap_msg)
2312{
2313 memset(path, 0, sizeof *path);
2314 path->dgid = lap_msg->alt_local_gid;
2315 path->sgid = lap_msg->alt_remote_gid;
2316 path->dlid = lap_msg->alt_local_lid;
2317 path->slid = lap_msg->alt_remote_lid;
2318 path->flow_label = cm_lap_get_flow_label(lap_msg);
2319 path->hop_limit = lap_msg->alt_hop_limit;
2320 path->traffic_class = cm_lap_get_traffic_class(lap_msg);
2321 path->reversible = 1;
2322 /* pkey is same as in REQ */
2323 path->sl = cm_lap_get_sl(lap_msg);
2324 path->mtu_selector = IB_SA_EQ;
2325 /* mtu is same as in REQ */
2326 path->rate_selector = IB_SA_EQ;
2327 path->rate = cm_lap_get_packet_rate(lap_msg);
2328 path->packet_life_time_selector = IB_SA_EQ;
2329 path->packet_life_time = cm_lap_get_local_ack_timeout(lap_msg);
2330 path->packet_life_time -= (path->packet_life_time > 0);
2331}
2332
2333static int cm_lap_handler(struct cm_work *work)
2334{
2335 struct cm_id_private *cm_id_priv;
2336 struct cm_lap_msg *lap_msg;
2337 struct ib_cm_lap_event_param *param;
2338 struct ib_mad_send_buf *msg = NULL;
2339 struct ib_send_wr *bad_send_wr;
2340 unsigned long flags;
2341 int ret;
2342
2343 /* todo: verify LAP request and send reject APR if invalid. */
2344 lap_msg = (struct cm_lap_msg *)work->mad_recv_wc->recv_buf.mad;
2345 cm_id_priv = cm_acquire_id(lap_msg->remote_comm_id,
2346 lap_msg->local_comm_id);
2347 if (!cm_id_priv)
2348 return -EINVAL;
2349
2350 param = &work->cm_event.param.lap_rcvd;
2351 param->alternate_path = &work->path[0];
2352 cm_format_path_from_lap(param->alternate_path, lap_msg);
2353 work->cm_event.private_data = &lap_msg->private_data;
2354
2355 spin_lock_irqsave(&cm_id_priv->lock, flags);
2356 if (cm_id_priv->id.state != IB_CM_ESTABLISHED)
2357 goto unlock;
2358
2359 switch (cm_id_priv->id.lap_state) {
2360 case IB_CM_LAP_IDLE:
2361 break;
2362 case IB_CM_MRA_LAP_SENT:
2363 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
2364 goto unlock;
2365
2366 cm_format_mra((struct cm_mra_msg *) msg->mad, cm_id_priv,
2367 CM_MSG_RESPONSE_OTHER,
2368 cm_id_priv->service_timeout,
2369 cm_id_priv->private_data,
2370 cm_id_priv->private_data_len);
2371 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2372
2373 if (ib_post_send_mad(cm_id_priv->av.port->mad_agent,
2374 &msg->send_wr, &bad_send_wr))
2375 cm_free_msg(msg);
2376 goto deref;
2377 default:
2378 goto unlock;
2379 }
2380
2381 cm_id_priv->id.lap_state = IB_CM_LAP_RCVD;
2382 cm_id_priv->tid = lap_msg->hdr.tid;
2383 ret = atomic_inc_and_test(&cm_id_priv->work_count);
2384 if (!ret)
2385 list_add_tail(&work->list, &cm_id_priv->work_list);
2386 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2387
2388 if (ret)
2389 cm_process_work(cm_id_priv, work);
2390 else
2391 cm_deref_id(cm_id_priv);
2392 return 0;
2393
2394unlock: spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2395deref: cm_deref_id(cm_id_priv);
2396 return -EINVAL;
2397}
2398
2399static void cm_format_apr(struct cm_apr_msg *apr_msg,
2400 struct cm_id_private *cm_id_priv,
2401 enum ib_cm_apr_status status,
2402 void *info,
2403 u8 info_length,
2404 const void *private_data,
2405 u8 private_data_len)
2406{
2407 cm_format_mad_hdr(&apr_msg->hdr, CM_APR_ATTR_ID, cm_id_priv->tid);
2408 apr_msg->local_comm_id = cm_id_priv->id.local_id;
2409 apr_msg->remote_comm_id = cm_id_priv->id.remote_id;
2410 apr_msg->ap_status = (u8) status;
2411
2412 if (info && info_length) {
2413 apr_msg->info_length = info_length;
2414 memcpy(apr_msg->info, info, info_length);
2415 }
2416
2417 if (private_data && private_data_len)
2418 memcpy(apr_msg->private_data, private_data, private_data_len);
2419}
2420
2421int ib_send_cm_apr(struct ib_cm_id *cm_id,
2422 enum ib_cm_apr_status status,
2423 void *info,
2424 u8 info_length,
2425 const void *private_data,
2426 u8 private_data_len)
2427{
2428 struct cm_id_private *cm_id_priv;
2429 struct ib_mad_send_buf *msg;
2430 struct ib_send_wr *bad_send_wr;
2431 unsigned long flags;
2432 int ret;
2433
2434 if ((private_data && private_data_len > IB_CM_APR_PRIVATE_DATA_SIZE) ||
2435 (info && info_length > IB_CM_APR_INFO_LENGTH))
2436 return -EINVAL;
2437
2438 cm_id_priv = container_of(cm_id, struct cm_id_private, id);
2439 spin_lock_irqsave(&cm_id_priv->lock, flags);
2440 if (cm_id->state != IB_CM_ESTABLISHED ||
2441 (cm_id->lap_state != IB_CM_LAP_RCVD &&
2442 cm_id->lap_state != IB_CM_MRA_LAP_SENT)) {
2443 ret = -EINVAL;
2444 goto out;
2445 }
2446
2447 ret = cm_alloc_msg(cm_id_priv, &msg);
2448 if (ret)
2449 goto out;
2450
2451 cm_format_apr((struct cm_apr_msg *) msg->mad, cm_id_priv, status,
2452 info, info_length, private_data, private_data_len);
2453 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent,
2454 &msg->send_wr, &bad_send_wr);
2455 if (ret) {
2456 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2457 cm_free_msg(msg);
2458 return ret;
2459 }
2460
2461 cm_id->lap_state = IB_CM_LAP_IDLE;
2462out: spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2463 return ret;
2464}
2465EXPORT_SYMBOL(ib_send_cm_apr);
2466
2467static int cm_apr_handler(struct cm_work *work)
2468{
2469 struct cm_id_private *cm_id_priv;
2470 struct cm_apr_msg *apr_msg;
2471 unsigned long flags;
2472 int ret;
2473
2474 apr_msg = (struct cm_apr_msg *)work->mad_recv_wc->recv_buf.mad;
2475 cm_id_priv = cm_acquire_id(apr_msg->remote_comm_id,
2476 apr_msg->local_comm_id);
2477 if (!cm_id_priv)
2478 return -EINVAL; /* Unmatched reply. */
2479
2480 work->cm_event.param.apr_rcvd.ap_status = apr_msg->ap_status;
2481 work->cm_event.param.apr_rcvd.apr_info = &apr_msg->info;
2482 work->cm_event.param.apr_rcvd.info_len = apr_msg->info_length;
2483 work->cm_event.private_data = &apr_msg->private_data;
2484
2485 spin_lock_irqsave(&cm_id_priv->lock, flags);
2486 if (cm_id_priv->id.state != IB_CM_ESTABLISHED ||
2487 (cm_id_priv->id.lap_state != IB_CM_LAP_SENT &&
2488 cm_id_priv->id.lap_state != IB_CM_MRA_LAP_RCVD)) {
2489 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2490 goto out;
2491 }
2492 cm_id_priv->id.lap_state = IB_CM_LAP_IDLE;
2493 ib_cancel_mad(cm_id_priv->av.port->mad_agent,
2494 (unsigned long) cm_id_priv->msg);
2495 cm_id_priv->msg = NULL;
2496
2497 ret = atomic_inc_and_test(&cm_id_priv->work_count);
2498 if (!ret)
2499 list_add_tail(&work->list, &cm_id_priv->work_list);
2500 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2501
2502 if (ret)
2503 cm_process_work(cm_id_priv, work);
2504 else
2505 cm_deref_id(cm_id_priv);
2506 return 0;
2507out:
2508 cm_deref_id(cm_id_priv);
2509 return -EINVAL;
2510}
2511
2512static int cm_timewait_handler(struct cm_work *work)
2513{
2514 struct cm_timewait_info *timewait_info;
2515 struct cm_id_private *cm_id_priv;
2516 unsigned long flags;
2517 int ret;
2518
2519 timewait_info = (struct cm_timewait_info *)work;
2520 cm_cleanup_timewait(timewait_info);
2521
2522 cm_id_priv = cm_acquire_id(timewait_info->work.local_id,
2523 timewait_info->work.remote_id);
2524 if (!cm_id_priv)
2525 return -EINVAL;
2526
2527 spin_lock_irqsave(&cm_id_priv->lock, flags);
2528 if (cm_id_priv->id.state != IB_CM_TIMEWAIT ||
2529 cm_id_priv->remote_qpn != timewait_info->remote_qpn) {
2530 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2531 goto out;
2532 }
2533 cm_id_priv->id.state = IB_CM_IDLE;
2534 ret = atomic_inc_and_test(&cm_id_priv->work_count);
2535 if (!ret)
2536 list_add_tail(&work->list, &cm_id_priv->work_list);
2537 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2538
2539 if (ret)
2540 cm_process_work(cm_id_priv, work);
2541 else
2542 cm_deref_id(cm_id_priv);
2543 return 0;
2544out:
2545 cm_deref_id(cm_id_priv);
2546 return -EINVAL;
2547}
2548
2549static void cm_format_sidr_req(struct cm_sidr_req_msg *sidr_req_msg,
2550 struct cm_id_private *cm_id_priv,
2551 struct ib_cm_sidr_req_param *param)
2552{
2553 cm_format_mad_hdr(&sidr_req_msg->hdr, CM_SIDR_REQ_ATTR_ID,
2554 cm_form_tid(cm_id_priv, CM_MSG_SEQUENCE_SIDR));
2555 sidr_req_msg->request_id = cm_id_priv->id.local_id;
2556 sidr_req_msg->pkey = param->pkey;
2557 sidr_req_msg->service_id = param->service_id;
2558
2559 if (param->private_data && param->private_data_len)
2560 memcpy(sidr_req_msg->private_data, param->private_data,
2561 param->private_data_len);
2562}
2563
2564int ib_send_cm_sidr_req(struct ib_cm_id *cm_id,
2565 struct ib_cm_sidr_req_param *param)
2566{
2567 struct cm_id_private *cm_id_priv;
2568 struct ib_mad_send_buf *msg;
2569 struct ib_send_wr *bad_send_wr;
2570 unsigned long flags;
2571 int ret;
2572
2573 if (!param->path || (param->private_data &&
2574 param->private_data_len > IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE))
2575 return -EINVAL;
2576
2577 cm_id_priv = container_of(cm_id, struct cm_id_private, id);
2578 ret = cm_init_av_by_path(param->path, &cm_id_priv->av);
2579 if (ret)
2580 goto out;
2581
2582 cm_id->service_id = param->service_id;
2583 cm_id->service_mask = ~0ULL;
2584 cm_id_priv->timeout_ms = param->timeout_ms;
2585 cm_id_priv->max_cm_retries = param->max_cm_retries;
2586 ret = cm_alloc_msg(cm_id_priv, &msg);
2587 if (ret)
2588 goto out;
2589
2590 cm_format_sidr_req((struct cm_sidr_req_msg *) msg->mad, cm_id_priv,
2591 param);
2592 msg->send_wr.wr.ud.timeout_ms = cm_id_priv->timeout_ms;
2593 msg->context[1] = (void *) (unsigned long) IB_CM_SIDR_REQ_SENT;
2594
2595 spin_lock_irqsave(&cm_id_priv->lock, flags);
2596 if (cm_id->state == IB_CM_IDLE)
2597 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent,
2598 &msg->send_wr, &bad_send_wr);
2599 else
2600 ret = -EINVAL;
2601
2602 if (ret) {
2603 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2604 cm_free_msg(msg);
2605 goto out;
2606 }
2607 cm_id->state = IB_CM_SIDR_REQ_SENT;
2608 cm_id_priv->msg = msg;
2609 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2610out:
2611 return ret;
2612}
2613EXPORT_SYMBOL(ib_send_cm_sidr_req);
2614
2615static void cm_format_sidr_req_event(struct cm_work *work,
2616 struct ib_cm_id *listen_id)
2617{
2618 struct cm_sidr_req_msg *sidr_req_msg;
2619 struct ib_cm_sidr_req_event_param *param;
2620
2621 sidr_req_msg = (struct cm_sidr_req_msg *)
2622 work->mad_recv_wc->recv_buf.mad;
2623 param = &work->cm_event.param.sidr_req_rcvd;
2624 param->pkey = sidr_req_msg->pkey;
2625 param->listen_id = listen_id;
2626 param->device = work->port->mad_agent->device;
2627 param->port = work->port->port_num;
2628 work->cm_event.private_data = &sidr_req_msg->private_data;
2629}
2630
2631static int cm_sidr_req_handler(struct cm_work *work)
2632{
2633 struct ib_cm_id *cm_id;
2634 struct cm_id_private *cm_id_priv, *cur_cm_id_priv;
2635 struct cm_sidr_req_msg *sidr_req_msg;
2636 struct ib_wc *wc;
2637 unsigned long flags;
2638
2639 cm_id = ib_create_cm_id(NULL, NULL);
2640 if (IS_ERR(cm_id))
2641 return PTR_ERR(cm_id);
2642 cm_id_priv = container_of(cm_id, struct cm_id_private, id);
2643
2644 /* Record SGID/SLID and request ID for lookup. */
2645 sidr_req_msg = (struct cm_sidr_req_msg *)
2646 work->mad_recv_wc->recv_buf.mad;
2647 wc = work->mad_recv_wc->wc;
2648 cm_id_priv->av.dgid.global.subnet_prefix = wc->slid;
2649 cm_id_priv->av.dgid.global.interface_id = 0;
2650 cm_init_av_for_response(work->port, work->mad_recv_wc->wc,
2651 &cm_id_priv->av);
2652 cm_id_priv->id.remote_id = sidr_req_msg->request_id;
2653 cm_id_priv->id.state = IB_CM_SIDR_REQ_RCVD;
2654 cm_id_priv->tid = sidr_req_msg->hdr.tid;
2655 atomic_inc(&cm_id_priv->work_count);
2656
2657 spin_lock_irqsave(&cm.lock, flags);
2658 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
2659 if (cur_cm_id_priv) {
2660 spin_unlock_irqrestore(&cm.lock, flags);
2661 goto out; /* Duplicate message. */
2662 }
2663 cur_cm_id_priv = cm_find_listen(sidr_req_msg->service_id);
2664 if (!cur_cm_id_priv) {
2665 rb_erase(&cm_id_priv->sidr_id_node, &cm.remote_sidr_table);
2666 spin_unlock_irqrestore(&cm.lock, flags);
2667 /* todo: reply with no match */
2668 goto out; /* No match. */
2669 }
2670 atomic_inc(&cur_cm_id_priv->refcount);
2671 spin_unlock_irqrestore(&cm.lock, flags);
2672
2673 cm_id_priv->id.cm_handler = cur_cm_id_priv->id.cm_handler;
2674 cm_id_priv->id.context = cur_cm_id_priv->id.context;
2675 cm_id_priv->id.service_id = sidr_req_msg->service_id;
2676 cm_id_priv->id.service_mask = ~0ULL;
2677
2678 cm_format_sidr_req_event(work, &cur_cm_id_priv->id);
2679 cm_process_work(cm_id_priv, work);
2680 cm_deref_id(cur_cm_id_priv);
2681 return 0;
2682out:
2683 ib_destroy_cm_id(&cm_id_priv->id);
2684 return -EINVAL;
2685}
2686
2687static void cm_format_sidr_rep(struct cm_sidr_rep_msg *sidr_rep_msg,
2688 struct cm_id_private *cm_id_priv,
2689 struct ib_cm_sidr_rep_param *param)
2690{
2691 cm_format_mad_hdr(&sidr_rep_msg->hdr, CM_SIDR_REP_ATTR_ID,
2692 cm_id_priv->tid);
2693 sidr_rep_msg->request_id = cm_id_priv->id.remote_id;
2694 sidr_rep_msg->status = param->status;
2695 cm_sidr_rep_set_qpn(sidr_rep_msg, cpu_to_be32(param->qp_num));
2696 sidr_rep_msg->service_id = cm_id_priv->id.service_id;
2697 sidr_rep_msg->qkey = cpu_to_be32(param->qkey);
2698
2699 if (param->info && param->info_length)
2700 memcpy(sidr_rep_msg->info, param->info, param->info_length);
2701
2702 if (param->private_data && param->private_data_len)
2703 memcpy(sidr_rep_msg->private_data, param->private_data,
2704 param->private_data_len);
2705}
2706
2707int ib_send_cm_sidr_rep(struct ib_cm_id *cm_id,
2708 struct ib_cm_sidr_rep_param *param)
2709{
2710 struct cm_id_private *cm_id_priv;
2711 struct ib_mad_send_buf *msg;
2712 struct ib_send_wr *bad_send_wr;
2713 unsigned long flags;
2714 int ret;
2715
2716 if ((param->info && param->info_length > IB_CM_SIDR_REP_INFO_LENGTH) ||
2717 (param->private_data &&
2718 param->private_data_len > IB_CM_SIDR_REP_PRIVATE_DATA_SIZE))
2719 return -EINVAL;
2720
2721 cm_id_priv = container_of(cm_id, struct cm_id_private, id);
2722 spin_lock_irqsave(&cm_id_priv->lock, flags);
2723 if (cm_id->state != IB_CM_SIDR_REQ_RCVD) {
2724 ret = -EINVAL;
2725 goto error;
2726 }
2727
2728 ret = cm_alloc_msg(cm_id_priv, &msg);
2729 if (ret)
2730 goto error;
2731
2732 cm_format_sidr_rep((struct cm_sidr_rep_msg *) msg->mad, cm_id_priv,
2733 param);
2734 ret = ib_post_send_mad(cm_id_priv->av.port->mad_agent,
2735 &msg->send_wr, &bad_send_wr);
2736 if (ret) {
2737 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2738 cm_free_msg(msg);
2739 return ret;
2740 }
2741 cm_id->state = IB_CM_IDLE;
2742 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2743
2744 spin_lock_irqsave(&cm.lock, flags);
2745 rb_erase(&cm_id_priv->sidr_id_node, &cm.remote_sidr_table);
2746 spin_unlock_irqrestore(&cm.lock, flags);
2747 return 0;
2748
2749error: spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2750 return ret;
2751}
2752EXPORT_SYMBOL(ib_send_cm_sidr_rep);
2753
2754static void cm_format_sidr_rep_event(struct cm_work *work)
2755{
2756 struct cm_sidr_rep_msg *sidr_rep_msg;
2757 struct ib_cm_sidr_rep_event_param *param;
2758
2759 sidr_rep_msg = (struct cm_sidr_rep_msg *)
2760 work->mad_recv_wc->recv_buf.mad;
2761 param = &work->cm_event.param.sidr_rep_rcvd;
2762 param->status = sidr_rep_msg->status;
2763 param->qkey = be32_to_cpu(sidr_rep_msg->qkey);
2764 param->qpn = be32_to_cpu(cm_sidr_rep_get_qpn(sidr_rep_msg));
2765 param->info = &sidr_rep_msg->info;
2766 param->info_len = sidr_rep_msg->info_length;
2767 work->cm_event.private_data = &sidr_rep_msg->private_data;
2768}
2769
2770static int cm_sidr_rep_handler(struct cm_work *work)
2771{
2772 struct cm_sidr_rep_msg *sidr_rep_msg;
2773 struct cm_id_private *cm_id_priv;
2774 unsigned long flags;
2775
2776 sidr_rep_msg = (struct cm_sidr_rep_msg *)
2777 work->mad_recv_wc->recv_buf.mad;
2778 cm_id_priv = cm_acquire_id(sidr_rep_msg->request_id, 0);
2779 if (!cm_id_priv)
2780 return -EINVAL; /* Unmatched reply. */
2781
2782 spin_lock_irqsave(&cm_id_priv->lock, flags);
2783 if (cm_id_priv->id.state != IB_CM_SIDR_REQ_SENT) {
2784 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2785 goto out;
2786 }
2787 cm_id_priv->id.state = IB_CM_IDLE;
2788 ib_cancel_mad(cm_id_priv->av.port->mad_agent,
2789 (unsigned long) cm_id_priv->msg);
2790 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2791
2792 cm_format_sidr_rep_event(work);
2793 cm_process_work(cm_id_priv, work);
2794 return 0;
2795out:
2796 cm_deref_id(cm_id_priv);
2797 return -EINVAL;
2798}
2799
2800static void cm_process_send_error(struct ib_mad_send_buf *msg,
2801 enum ib_wc_status wc_status)
2802{
2803 struct cm_id_private *cm_id_priv;
2804 struct ib_cm_event cm_event;
2805 enum ib_cm_state state;
2806 unsigned long flags;
2807 int ret;
2808
2809 memset(&cm_event, 0, sizeof cm_event);
2810 cm_id_priv = msg->context[0];
2811
2812 /* Discard old sends or ones without a response. */
2813 spin_lock_irqsave(&cm_id_priv->lock, flags);
2814 state = (enum ib_cm_state) (unsigned long) msg->context[1];
2815 if (msg != cm_id_priv->msg || state != cm_id_priv->id.state)
2816 goto discard;
2817
2818 switch (state) {
2819 case IB_CM_REQ_SENT:
2820 case IB_CM_MRA_REQ_RCVD:
2821 cm_reset_to_idle(cm_id_priv);
2822 cm_event.event = IB_CM_REQ_ERROR;
2823 break;
2824 case IB_CM_REP_SENT:
2825 case IB_CM_MRA_REP_RCVD:
2826 cm_reset_to_idle(cm_id_priv);
2827 cm_event.event = IB_CM_REP_ERROR;
2828 break;
2829 case IB_CM_DREQ_SENT:
2830 cm_enter_timewait(cm_id_priv);
2831 cm_event.event = IB_CM_DREQ_ERROR;
2832 break;
2833 case IB_CM_SIDR_REQ_SENT:
2834 cm_id_priv->id.state = IB_CM_IDLE;
2835 cm_event.event = IB_CM_SIDR_REQ_ERROR;
2836 break;
2837 default:
2838 goto discard;
2839 }
2840 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2841 cm_event.param.send_status = wc_status;
2842
2843 /* No other events can occur on the cm_id at this point. */
2844 ret = cm_id_priv->id.cm_handler(&cm_id_priv->id, &cm_event);
2845 cm_free_msg(msg);
2846 if (ret)
2847 ib_destroy_cm_id(&cm_id_priv->id);
2848 return;
2849discard:
2850 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2851 cm_free_msg(msg);
2852}
2853
2854static void cm_send_handler(struct ib_mad_agent *mad_agent,
2855 struct ib_mad_send_wc *mad_send_wc)
2856{
2857 struct ib_mad_send_buf *msg;
2858
2859 msg = (struct ib_mad_send_buf *)(unsigned long)mad_send_wc->wr_id;
2860
2861 switch (mad_send_wc->status) {
2862 case IB_WC_SUCCESS:
2863 case IB_WC_WR_FLUSH_ERR:
2864 cm_free_msg(msg);
2865 break;
2866 default:
2867 if (msg->context[0] && msg->context[1])
2868 cm_process_send_error(msg, mad_send_wc->status);
2869 else
2870 cm_free_msg(msg);
2871 break;
2872 }
2873}
2874
2875static void cm_work_handler(void *data)
2876{
2877 struct cm_work *work = data;
2878 int ret;
2879
2880 switch (work->cm_event.event) {
2881 case IB_CM_REQ_RECEIVED:
2882 ret = cm_req_handler(work);
2883 break;
2884 case IB_CM_MRA_RECEIVED:
2885 ret = cm_mra_handler(work);
2886 break;
2887 case IB_CM_REJ_RECEIVED:
2888 ret = cm_rej_handler(work);
2889 break;
2890 case IB_CM_REP_RECEIVED:
2891 ret = cm_rep_handler(work);
2892 break;
2893 case IB_CM_RTU_RECEIVED:
2894 ret = cm_rtu_handler(work);
2895 break;
2896 case IB_CM_USER_ESTABLISHED:
2897 ret = cm_establish_handler(work);
2898 break;
2899 case IB_CM_DREQ_RECEIVED:
2900 ret = cm_dreq_handler(work);
2901 break;
2902 case IB_CM_DREP_RECEIVED:
2903 ret = cm_drep_handler(work);
2904 break;
2905 case IB_CM_SIDR_REQ_RECEIVED:
2906 ret = cm_sidr_req_handler(work);
2907 break;
2908 case IB_CM_SIDR_REP_RECEIVED:
2909 ret = cm_sidr_rep_handler(work);
2910 break;
2911 case IB_CM_LAP_RECEIVED:
2912 ret = cm_lap_handler(work);
2913 break;
2914 case IB_CM_APR_RECEIVED:
2915 ret = cm_apr_handler(work);
2916 break;
2917 case IB_CM_TIMEWAIT_EXIT:
2918 ret = cm_timewait_handler(work);
2919 break;
2920 default:
2921 ret = -EINVAL;
2922 break;
2923 }
2924 if (ret)
2925 cm_free_work(work);
2926}
2927
2928int ib_cm_establish(struct ib_cm_id *cm_id)
2929{
2930 struct cm_id_private *cm_id_priv;
2931 struct cm_work *work;
2932 unsigned long flags;
2933 int ret = 0;
2934
2935 work = kmalloc(sizeof *work, GFP_ATOMIC);
2936 if (!work)
2937 return -ENOMEM;
2938
2939 cm_id_priv = container_of(cm_id, struct cm_id_private, id);
2940 spin_lock_irqsave(&cm_id_priv->lock, flags);
2941 switch (cm_id->state)
2942 {
2943 case IB_CM_REP_SENT:
2944 case IB_CM_MRA_REP_RCVD:
2945 cm_id->state = IB_CM_ESTABLISHED;
2946 break;
2947 case IB_CM_ESTABLISHED:
2948 ret = -EISCONN;
2949 break;
2950 default:
2951 ret = -EINVAL;
2952 break;
2953 }
2954 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
2955
2956 if (ret) {
2957 kfree(work);
2958 goto out;
2959 }
2960
2961 /*
2962 * The CM worker thread may try to destroy the cm_id before it
2963 * can execute this work item. To prevent potential deadlock,
2964 * we need to find the cm_id once we're in the context of the
2965 * worker thread, rather than holding a reference on it.
2966 */
2967 INIT_WORK(&work->work, cm_work_handler, work);
2968 work->local_id = cm_id->local_id;
2969 work->remote_id = cm_id->remote_id;
2970 work->mad_recv_wc = NULL;
2971 work->cm_event.event = IB_CM_USER_ESTABLISHED;
2972 queue_work(cm.wq, &work->work);
2973out:
2974 return ret;
2975}
2976EXPORT_SYMBOL(ib_cm_establish);
2977
2978static void cm_recv_handler(struct ib_mad_agent *mad_agent,
2979 struct ib_mad_recv_wc *mad_recv_wc)
2980{
2981 struct cm_work *work;
2982 enum ib_cm_event_type event;
2983 int paths = 0;
2984
2985 switch (mad_recv_wc->recv_buf.mad->mad_hdr.attr_id) {
2986 case CM_REQ_ATTR_ID:
2987 paths = 1 + (((struct cm_req_msg *) mad_recv_wc->recv_buf.mad)->
2988 alt_local_lid != 0);
2989 event = IB_CM_REQ_RECEIVED;
2990 break;
2991 case CM_MRA_ATTR_ID:
2992 event = IB_CM_MRA_RECEIVED;
2993 break;
2994 case CM_REJ_ATTR_ID:
2995 event = IB_CM_REJ_RECEIVED;
2996 break;
2997 case CM_REP_ATTR_ID:
2998 event = IB_CM_REP_RECEIVED;
2999 break;
3000 case CM_RTU_ATTR_ID:
3001 event = IB_CM_RTU_RECEIVED;
3002 break;
3003 case CM_DREQ_ATTR_ID:
3004 event = IB_CM_DREQ_RECEIVED;
3005 break;
3006 case CM_DREP_ATTR_ID:
3007 event = IB_CM_DREP_RECEIVED;
3008 break;
3009 case CM_SIDR_REQ_ATTR_ID:
3010 event = IB_CM_SIDR_REQ_RECEIVED;
3011 break;
3012 case CM_SIDR_REP_ATTR_ID:
3013 event = IB_CM_SIDR_REP_RECEIVED;
3014 break;
3015 case CM_LAP_ATTR_ID:
3016 paths = 1;
3017 event = IB_CM_LAP_RECEIVED;
3018 break;
3019 case CM_APR_ATTR_ID:
3020 event = IB_CM_APR_RECEIVED;
3021 break;
3022 default:
3023 ib_free_recv_mad(mad_recv_wc);
3024 return;
3025 }
3026
3027 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
3028 GFP_KERNEL);
3029 if (!work) {
3030 ib_free_recv_mad(mad_recv_wc);
3031 return;
3032 }
3033
3034 INIT_WORK(&work->work, cm_work_handler, work);
3035 work->cm_event.event = event;
3036 work->mad_recv_wc = mad_recv_wc;
3037 work->port = (struct cm_port *)mad_agent->context;
3038 queue_work(cm.wq, &work->work);
3039}
3040
3041static int cm_init_qp_init_attr(struct cm_id_private *cm_id_priv,
3042 struct ib_qp_attr *qp_attr,
3043 int *qp_attr_mask)
3044{
3045 unsigned long flags;
3046 int ret;
3047
3048 spin_lock_irqsave(&cm_id_priv->lock, flags);
3049 switch (cm_id_priv->id.state) {
3050 case IB_CM_REQ_SENT:
3051 case IB_CM_MRA_REQ_RCVD:
3052 case IB_CM_REQ_RCVD:
3053 case IB_CM_MRA_REQ_SENT:
3054 case IB_CM_REP_RCVD:
3055 case IB_CM_MRA_REP_SENT:
3056 case IB_CM_REP_SENT:
3057 case IB_CM_MRA_REP_RCVD:
3058 case IB_CM_ESTABLISHED:
3059 *qp_attr_mask = IB_QP_STATE | IB_QP_ACCESS_FLAGS |
3060 IB_QP_PKEY_INDEX | IB_QP_PORT;
3061 qp_attr->qp_access_flags = IB_ACCESS_LOCAL_WRITE;
3062 if (cm_id_priv->responder_resources)
3063 qp_attr->qp_access_flags |= IB_ACCESS_REMOTE_WRITE |
3064 IB_ACCESS_REMOTE_READ;
3065 qp_attr->pkey_index = cm_id_priv->av.pkey_index;
3066 qp_attr->port_num = cm_id_priv->av.port->port_num;
3067 ret = 0;
3068 break;
3069 default:
3070 ret = -EINVAL;
3071 break;
3072 }
3073 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
3074 return ret;
3075}
3076
3077static int cm_init_qp_rtr_attr(struct cm_id_private *cm_id_priv,
3078 struct ib_qp_attr *qp_attr,
3079 int *qp_attr_mask)
3080{
3081 unsigned long flags;
3082 int ret;
3083
3084 spin_lock_irqsave(&cm_id_priv->lock, flags);
3085 switch (cm_id_priv->id.state) {
3086 case IB_CM_REQ_RCVD:
3087 case IB_CM_MRA_REQ_SENT:
3088 case IB_CM_REP_RCVD:
3089 case IB_CM_MRA_REP_SENT:
3090 case IB_CM_REP_SENT:
3091 case IB_CM_MRA_REP_RCVD:
3092 case IB_CM_ESTABLISHED:
3093 *qp_attr_mask = IB_QP_STATE | IB_QP_AV | IB_QP_PATH_MTU |
3094 IB_QP_DEST_QPN | IB_QP_RQ_PSN |
3095 IB_QP_MAX_DEST_RD_ATOMIC | IB_QP_MIN_RNR_TIMER;
3096 qp_attr->ah_attr = cm_id_priv->av.ah_attr;
3097 qp_attr->path_mtu = cm_id_priv->path_mtu;
3098 qp_attr->dest_qp_num = be32_to_cpu(cm_id_priv->remote_qpn);
3099 qp_attr->rq_psn = be32_to_cpu(cm_id_priv->rq_psn);
3100 qp_attr->max_dest_rd_atomic = cm_id_priv->responder_resources;
3101 qp_attr->min_rnr_timer = 0;
3102 if (cm_id_priv->alt_av.ah_attr.dlid) {
3103 *qp_attr_mask |= IB_QP_ALT_PATH;
3104 qp_attr->alt_ah_attr = cm_id_priv->alt_av.ah_attr;
3105 }
3106 ret = 0;
3107 break;
3108 default:
3109 ret = -EINVAL;
3110 break;
3111 }
3112 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
3113 return ret;
3114}
3115
3116static int cm_init_qp_rts_attr(struct cm_id_private *cm_id_priv,
3117 struct ib_qp_attr *qp_attr,
3118 int *qp_attr_mask)
3119{
3120 unsigned long flags;
3121 int ret;
3122
3123 spin_lock_irqsave(&cm_id_priv->lock, flags);
3124 switch (cm_id_priv->id.state) {
3125 case IB_CM_REP_RCVD:
3126 case IB_CM_MRA_REP_SENT:
3127 case IB_CM_REP_SENT:
3128 case IB_CM_MRA_REP_RCVD:
3129 case IB_CM_ESTABLISHED:
3130 *qp_attr_mask = IB_QP_STATE | IB_QP_TIMEOUT | IB_QP_RETRY_CNT |
3131 IB_QP_RNR_RETRY | IB_QP_SQ_PSN |
3132 IB_QP_MAX_QP_RD_ATOMIC;
3133 qp_attr->timeout = cm_id_priv->local_ack_timeout;
3134 qp_attr->retry_cnt = cm_id_priv->retry_count;
3135 qp_attr->rnr_retry = cm_id_priv->rnr_retry_count;
3136 qp_attr->sq_psn = be32_to_cpu(cm_id_priv->sq_psn);
3137 qp_attr->max_rd_atomic = cm_id_priv->initiator_depth;
3138 if (cm_id_priv->alt_av.ah_attr.dlid) {
3139 *qp_attr_mask |= IB_QP_PATH_MIG_STATE;
3140 qp_attr->path_mig_state = IB_MIG_REARM;
3141 }
3142 ret = 0;
3143 break;
3144 default:
3145 ret = -EINVAL;
3146 break;
3147 }
3148 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
3149 return ret;
3150}
3151
3152int ib_cm_init_qp_attr(struct ib_cm_id *cm_id,
3153 struct ib_qp_attr *qp_attr,
3154 int *qp_attr_mask)
3155{
3156 struct cm_id_private *cm_id_priv;
3157 int ret;
3158
3159 cm_id_priv = container_of(cm_id, struct cm_id_private, id);
3160 switch (qp_attr->qp_state) {
3161 case IB_QPS_INIT:
3162 ret = cm_init_qp_init_attr(cm_id_priv, qp_attr, qp_attr_mask);
3163 break;
3164 case IB_QPS_RTR:
3165 ret = cm_init_qp_rtr_attr(cm_id_priv, qp_attr, qp_attr_mask);
3166 break;
3167 case IB_QPS_RTS:
3168 ret = cm_init_qp_rts_attr(cm_id_priv, qp_attr, qp_attr_mask);
3169 break;
3170 default:
3171 ret = -EINVAL;
3172 break;
3173 }
3174 return ret;
3175}
3176EXPORT_SYMBOL(ib_cm_init_qp_attr);
3177
3178static u64 cm_get_ca_guid(struct ib_device *device)
3179{
3180 struct ib_device_attr *device_attr;
3181 u64 guid;
3182 int ret;
3183
3184 device_attr = kmalloc(sizeof *device_attr, GFP_KERNEL);
3185 if (!device_attr)
3186 return 0;
3187
3188 ret = ib_query_device(device, device_attr);
3189 guid = ret ? 0 : device_attr->node_guid;
3190 kfree(device_attr);
3191 return guid;
3192}
3193
3194static void cm_add_one(struct ib_device *device)
3195{
3196 struct cm_device *cm_dev;
3197 struct cm_port *port;
3198 struct ib_mad_reg_req reg_req = {
3199 .mgmt_class = IB_MGMT_CLASS_CM,
3200 .mgmt_class_version = IB_CM_CLASS_VERSION
3201 };
3202 struct ib_port_modify port_modify = {
3203 .set_port_cap_mask = IB_PORT_CM_SUP
3204 };
3205 unsigned long flags;
3206 int ret;
3207 u8 i;
3208
3209 cm_dev = kmalloc(sizeof(*cm_dev) + sizeof(*port) *
3210 device->phys_port_cnt, GFP_KERNEL);
3211 if (!cm_dev)
3212 return;
3213
3214 cm_dev->device = device;
3215 cm_dev->ca_guid = cm_get_ca_guid(device);
3216 if (!cm_dev->ca_guid)
3217 goto error1;
3218
3219 set_bit(IB_MGMT_METHOD_SEND, reg_req.method_mask);
3220 for (i = 1; i <= device->phys_port_cnt; i++) {
3221 port = &cm_dev->port[i-1];
3222 port->cm_dev = cm_dev;
3223 port->port_num = i;
3224 port->mad_agent = ib_register_mad_agent(device, i,
3225 IB_QPT_GSI,
3226 &reg_req,
3227 0,
3228 cm_send_handler,
3229 cm_recv_handler,
3230 port);
3231 if (IS_ERR(port->mad_agent))
3232 goto error2;
3233
3234 ret = ib_modify_port(device, i, 0, &port_modify);
3235 if (ret)
3236 goto error3;
3237 }
3238 ib_set_client_data(device, &cm_client, cm_dev);
3239
3240 write_lock_irqsave(&cm.device_lock, flags);
3241 list_add_tail(&cm_dev->list, &cm.device_list);
3242 write_unlock_irqrestore(&cm.device_lock, flags);
3243 return;
3244
3245error3:
3246 ib_unregister_mad_agent(port->mad_agent);
3247error2:
3248 port_modify.set_port_cap_mask = 0;
3249 port_modify.clr_port_cap_mask = IB_PORT_CM_SUP;
3250 while (--i) {
3251 port = &cm_dev->port[i-1];
3252 ib_modify_port(device, port->port_num, 0, &port_modify);
3253 ib_unregister_mad_agent(port->mad_agent);
3254 }
3255error1:
3256 kfree(cm_dev);
3257}
3258
3259static void cm_remove_one(struct ib_device *device)
3260{
3261 struct cm_device *cm_dev;
3262 struct cm_port *port;
3263 struct ib_port_modify port_modify = {
3264 .clr_port_cap_mask = IB_PORT_CM_SUP
3265 };
3266 unsigned long flags;
3267 int i;
3268
3269 cm_dev = ib_get_client_data(device, &cm_client);
3270 if (!cm_dev)
3271 return;
3272
3273 write_lock_irqsave(&cm.device_lock, flags);
3274 list_del(&cm_dev->list);
3275 write_unlock_irqrestore(&cm.device_lock, flags);
3276
3277 for (i = 1; i <= device->phys_port_cnt; i++) {
3278 port = &cm_dev->port[i-1];
3279 ib_modify_port(device, port->port_num, 0, &port_modify);
3280 ib_unregister_mad_agent(port->mad_agent);
3281 }
3282 kfree(cm_dev);
3283}
3284
3285static int __init ib_cm_init(void)
3286{
3287 int ret;
3288
3289 memset(&cm, 0, sizeof cm);
3290 INIT_LIST_HEAD(&cm.device_list);
3291 rwlock_init(&cm.device_lock);
3292 spin_lock_init(&cm.lock);
3293 cm.listen_service_table = RB_ROOT;
3294 cm.listen_service_id = __constant_be64_to_cpu(IB_CM_ASSIGN_SERVICE_ID);
3295 cm.remote_id_table = RB_ROOT;
3296 cm.remote_qp_table = RB_ROOT;
3297 cm.remote_sidr_table = RB_ROOT;
3298 idr_init(&cm.local_id_table);
3299 idr_pre_get(&cm.local_id_table, GFP_KERNEL);
3300
3301 cm.wq = create_workqueue("ib_cm");
3302 if (!cm.wq)
3303 return -ENOMEM;
3304
3305 ret = ib_register_client(&cm_client);
3306 if (ret)
3307 goto error;
3308
3309 return 0;
3310error:
3311 destroy_workqueue(cm.wq);
3312 return ret;
3313}
3314
3315static void __exit ib_cm_cleanup(void)
3316{
3317 flush_workqueue(cm.wq);
3318 destroy_workqueue(cm.wq);
3319 ib_unregister_client(&cm_client);
3320}
3321
3322module_init(ib_cm_init);
3323module_exit(ib_cm_cleanup);
3324
diff --git a/drivers/infiniband/core/cm_msgs.h b/drivers/infiniband/core/cm_msgs.h
new file mode 100644
index 000000000000..15a309a77b2b
--- /dev/null
+++ b/drivers/infiniband/core/cm_msgs.h
@@ -0,0 +1,819 @@
1/*
2 * Copyright (c) 2004 Intel Corporation. All rights reserved.
3 * Copyright (c) 2004 Topspin Corporation. All rights reserved.
4 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING the madirectory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use source and binary forms, with or
13 * withmodification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retathe above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHWARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS THE
32 * SOFTWARE.
33 */
34#if !defined(CM_MSGS_H)
35#define CM_MSGS_H
36
37#include <ib_mad.h>
38
39/*
40 * Parameters to routines below should be in network-byte order, and values
41 * are returned in network-byte order.
42 */
43
44#define IB_CM_CLASS_VERSION 2 /* IB specification 1.2 */
45
46enum cm_msg_attr_id {
47 CM_REQ_ATTR_ID = __constant_htons(0x0010),
48 CM_MRA_ATTR_ID = __constant_htons(0x0011),
49 CM_REJ_ATTR_ID = __constant_htons(0x0012),
50 CM_REP_ATTR_ID = __constant_htons(0x0013),
51 CM_RTU_ATTR_ID = __constant_htons(0x0014),
52 CM_DREQ_ATTR_ID = __constant_htons(0x0015),
53 CM_DREP_ATTR_ID = __constant_htons(0x0016),
54 CM_SIDR_REQ_ATTR_ID = __constant_htons(0x0017),
55 CM_SIDR_REP_ATTR_ID = __constant_htons(0x0018),
56 CM_LAP_ATTR_ID = __constant_htons(0x0019),
57 CM_APR_ATTR_ID = __constant_htons(0x001A)
58};
59
60enum cm_msg_sequence {
61 CM_MSG_SEQUENCE_REQ,
62 CM_MSG_SEQUENCE_LAP,
63 CM_MSG_SEQUENCE_DREQ,
64 CM_MSG_SEQUENCE_SIDR
65};
66
67struct cm_req_msg {
68 struct ib_mad_hdr hdr;
69
70 u32 local_comm_id;
71 u32 rsvd4;
72 u64 service_id;
73 u64 local_ca_guid;
74 u32 rsvd24;
75 u32 local_qkey;
76 /* local QPN:24, responder resources:8 */
77 u32 offset32;
78 /* local EECN:24, initiator depth:8 */
79 u32 offset36;
80 /*
81 * remote EECN:24, remote CM response timeout:5,
82 * transport service type:2, end-to-end flow control:1
83 */
84 u32 offset40;
85 /* starting PSN:24, local CM response timeout:5, retry count:3 */
86 u32 offset44;
87 u16 pkey;
88 /* path MTU:4, RDC exists:1, RNR retry count:3. */
89 u8 offset50;
90 /* max CM Retries:4, SRQ:1, rsvd:3 */
91 u8 offset51;
92
93 u16 primary_local_lid;
94 u16 primary_remote_lid;
95 union ib_gid primary_local_gid;
96 union ib_gid primary_remote_gid;
97 /* flow label:20, rsvd:6, packet rate:6 */
98 u32 primary_offset88;
99 u8 primary_traffic_class;
100 u8 primary_hop_limit;
101 /* SL:4, subnet local:1, rsvd:3 */
102 u8 primary_offset94;
103 /* local ACK timeout:5, rsvd:3 */
104 u8 primary_offset95;
105
106 u16 alt_local_lid;
107 u16 alt_remote_lid;
108 union ib_gid alt_local_gid;
109 union ib_gid alt_remote_gid;
110 /* flow label:20, rsvd:6, packet rate:6 */
111 u32 alt_offset132;
112 u8 alt_traffic_class;
113 u8 alt_hop_limit;
114 /* SL:4, subnet local:1, rsvd:3 */
115 u8 alt_offset138;
116 /* local ACK timeout:5, rsvd:3 */
117 u8 alt_offset139;
118
119 u8 private_data[IB_CM_REQ_PRIVATE_DATA_SIZE];
120
121} __attribute__ ((packed));
122
123static inline u32 cm_req_get_local_qpn(struct cm_req_msg *req_msg)
124{
125 return cpu_to_be32(be32_to_cpu(req_msg->offset32) >> 8);
126}
127
128static inline void cm_req_set_local_qpn(struct cm_req_msg *req_msg, u32 qpn)
129{
130 req_msg->offset32 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
131 (be32_to_cpu(req_msg->offset32) &
132 0x000000FF));
133}
134
135static inline u8 cm_req_get_resp_res(struct cm_req_msg *req_msg)
136{
137 return (u8) be32_to_cpu(req_msg->offset32);
138}
139
140static inline void cm_req_set_resp_res(struct cm_req_msg *req_msg, u8 resp_res)
141{
142 req_msg->offset32 = cpu_to_be32(resp_res |
143 (be32_to_cpu(req_msg->offset32) &
144 0xFFFFFF00));
145}
146
147static inline u8 cm_req_get_init_depth(struct cm_req_msg *req_msg)
148{
149 return (u8) be32_to_cpu(req_msg->offset36);
150}
151
152static inline void cm_req_set_init_depth(struct cm_req_msg *req_msg,
153 u8 init_depth)
154{
155 req_msg->offset36 = cpu_to_be32(init_depth |
156 (be32_to_cpu(req_msg->offset36) &
157 0xFFFFFF00));
158}
159
160static inline u8 cm_req_get_remote_resp_timeout(struct cm_req_msg *req_msg)
161{
162 return (u8) ((be32_to_cpu(req_msg->offset40) & 0xF8) >> 3);
163}
164
165static inline void cm_req_set_remote_resp_timeout(struct cm_req_msg *req_msg,
166 u8 resp_timeout)
167{
168 req_msg->offset40 = cpu_to_be32((resp_timeout << 3) |
169 (be32_to_cpu(req_msg->offset40) &
170 0xFFFFFF07));
171}
172
173static inline enum ib_qp_type cm_req_get_qp_type(struct cm_req_msg *req_msg)
174{
175 u8 transport_type = (u8) (be32_to_cpu(req_msg->offset40) & 0x06) >> 1;
176 switch(transport_type) {
177 case 0: return IB_QPT_RC;
178 case 1: return IB_QPT_UC;
179 default: return 0;
180 }
181}
182
183static inline void cm_req_set_qp_type(struct cm_req_msg *req_msg,
184 enum ib_qp_type qp_type)
185{
186 switch(qp_type) {
187 case IB_QPT_UC:
188 req_msg->offset40 = cpu_to_be32((be32_to_cpu(
189 req_msg->offset40) &
190 0xFFFFFFF9) | 0x2);
191 default:
192 req_msg->offset40 = cpu_to_be32(be32_to_cpu(
193 req_msg->offset40) &
194 0xFFFFFFF9);
195 }
196}
197
198static inline u8 cm_req_get_flow_ctrl(struct cm_req_msg *req_msg)
199{
200 return be32_to_cpu(req_msg->offset40) & 0x1;
201}
202
203static inline void cm_req_set_flow_ctrl(struct cm_req_msg *req_msg,
204 u8 flow_ctrl)
205{
206 req_msg->offset40 = cpu_to_be32((flow_ctrl & 0x1) |
207 (be32_to_cpu(req_msg->offset40) &
208 0xFFFFFFFE));
209}
210
211static inline u32 cm_req_get_starting_psn(struct cm_req_msg *req_msg)
212{
213 return cpu_to_be32(be32_to_cpu(req_msg->offset44) >> 8);
214}
215
216static inline void cm_req_set_starting_psn(struct cm_req_msg *req_msg,
217 u32 starting_psn)
218{
219 req_msg->offset44 = cpu_to_be32((be32_to_cpu(starting_psn) << 8) |
220 (be32_to_cpu(req_msg->offset44) & 0x000000FF));
221}
222
223static inline u8 cm_req_get_local_resp_timeout(struct cm_req_msg *req_msg)
224{
225 return (u8) ((be32_to_cpu(req_msg->offset44) & 0xF8) >> 3);
226}
227
228static inline void cm_req_set_local_resp_timeout(struct cm_req_msg *req_msg,
229 u8 resp_timeout)
230{
231 req_msg->offset44 = cpu_to_be32((resp_timeout << 3) |
232 (be32_to_cpu(req_msg->offset44) & 0xFFFFFF07));
233}
234
235static inline u8 cm_req_get_retry_count(struct cm_req_msg *req_msg)
236{
237 return (u8) (be32_to_cpu(req_msg->offset44) & 0x7);
238}
239
240static inline void cm_req_set_retry_count(struct cm_req_msg *req_msg,
241 u8 retry_count)
242{
243 req_msg->offset44 = cpu_to_be32((retry_count & 0x7) |
244 (be32_to_cpu(req_msg->offset44) & 0xFFFFFFF8));
245}
246
247static inline u8 cm_req_get_path_mtu(struct cm_req_msg *req_msg)
248{
249 return req_msg->offset50 >> 4;
250}
251
252static inline void cm_req_set_path_mtu(struct cm_req_msg *req_msg, u8 path_mtu)
253{
254 req_msg->offset50 = (u8) ((req_msg->offset50 & 0xF) | (path_mtu << 4));
255}
256
257static inline u8 cm_req_get_rnr_retry_count(struct cm_req_msg *req_msg)
258{
259 return req_msg->offset50 & 0x7;
260}
261
262static inline void cm_req_set_rnr_retry_count(struct cm_req_msg *req_msg,
263 u8 rnr_retry_count)
264{
265 req_msg->offset50 = (u8) ((req_msg->offset50 & 0xF8) |
266 (rnr_retry_count & 0x7));
267}
268
269static inline u8 cm_req_get_max_cm_retries(struct cm_req_msg *req_msg)
270{
271 return req_msg->offset51 >> 4;
272}
273
274static inline void cm_req_set_max_cm_retries(struct cm_req_msg *req_msg,
275 u8 retries)
276{
277 req_msg->offset51 = (u8) ((req_msg->offset51 & 0xF) | (retries << 4));
278}
279
280static inline u8 cm_req_get_srq(struct cm_req_msg *req_msg)
281{
282 return (req_msg->offset51 & 0x8) >> 3;
283}
284
285static inline void cm_req_set_srq(struct cm_req_msg *req_msg, u8 srq)
286{
287 req_msg->offset51 = (u8) ((req_msg->offset51 & 0xF7) |
288 ((srq & 0x1) << 3));
289}
290
291static inline u32 cm_req_get_primary_flow_label(struct cm_req_msg *req_msg)
292{
293 return cpu_to_be32((be32_to_cpu(req_msg->primary_offset88) >> 12));
294}
295
296static inline void cm_req_set_primary_flow_label(struct cm_req_msg *req_msg,
297 u32 flow_label)
298{
299 req_msg->primary_offset88 = cpu_to_be32(
300 (be32_to_cpu(req_msg->primary_offset88) &
301 0x00000FFF) |
302 (be32_to_cpu(flow_label) << 12));
303}
304
305static inline u8 cm_req_get_primary_packet_rate(struct cm_req_msg *req_msg)
306{
307 return (u8) (be32_to_cpu(req_msg->primary_offset88) & 0x3F);
308}
309
310static inline void cm_req_set_primary_packet_rate(struct cm_req_msg *req_msg,
311 u8 rate)
312{
313 req_msg->primary_offset88 = cpu_to_be32(
314 (be32_to_cpu(req_msg->primary_offset88) &
315 0xFFFFFFC0) | (rate & 0x3F));
316}
317
318static inline u8 cm_req_get_primary_sl(struct cm_req_msg *req_msg)
319{
320 return (u8) (req_msg->primary_offset94 >> 4);
321}
322
323static inline void cm_req_set_primary_sl(struct cm_req_msg *req_msg, u8 sl)
324{
325 req_msg->primary_offset94 = (u8) ((req_msg->primary_offset94 & 0x0F) |
326 (sl << 4));
327}
328
329static inline u8 cm_req_get_primary_subnet_local(struct cm_req_msg *req_msg)
330{
331 return (u8) ((req_msg->primary_offset94 & 0x08) >> 3);
332}
333
334static inline void cm_req_set_primary_subnet_local(struct cm_req_msg *req_msg,
335 u8 subnet_local)
336{
337 req_msg->primary_offset94 = (u8) ((req_msg->primary_offset94 & 0xF7) |
338 ((subnet_local & 0x1) << 3));
339}
340
341static inline u8 cm_req_get_primary_local_ack_timeout(struct cm_req_msg *req_msg)
342{
343 return (u8) (req_msg->primary_offset95 >> 3);
344}
345
346static inline void cm_req_set_primary_local_ack_timeout(struct cm_req_msg *req_msg,
347 u8 local_ack_timeout)
348{
349 req_msg->primary_offset95 = (u8) ((req_msg->primary_offset95 & 0x07) |
350 (local_ack_timeout << 3));
351}
352
353static inline u32 cm_req_get_alt_flow_label(struct cm_req_msg *req_msg)
354{
355 return cpu_to_be32((be32_to_cpu(req_msg->alt_offset132) >> 12));
356}
357
358static inline void cm_req_set_alt_flow_label(struct cm_req_msg *req_msg,
359 u32 flow_label)
360{
361 req_msg->alt_offset132 = cpu_to_be32(
362 (be32_to_cpu(req_msg->alt_offset132) &
363 0x00000FFF) |
364 (be32_to_cpu(flow_label) << 12));
365}
366
367static inline u8 cm_req_get_alt_packet_rate(struct cm_req_msg *req_msg)
368{
369 return (u8) (be32_to_cpu(req_msg->alt_offset132) & 0x3F);
370}
371
372static inline void cm_req_set_alt_packet_rate(struct cm_req_msg *req_msg,
373 u8 rate)
374{
375 req_msg->alt_offset132 = cpu_to_be32(
376 (be32_to_cpu(req_msg->alt_offset132) &
377 0xFFFFFFC0) | (rate & 0x3F));
378}
379
380static inline u8 cm_req_get_alt_sl(struct cm_req_msg *req_msg)
381{
382 return (u8) (req_msg->alt_offset138 >> 4);
383}
384
385static inline void cm_req_set_alt_sl(struct cm_req_msg *req_msg, u8 sl)
386{
387 req_msg->alt_offset138 = (u8) ((req_msg->alt_offset138 & 0x0F) |
388 (sl << 4));
389}
390
391static inline u8 cm_req_get_alt_subnet_local(struct cm_req_msg *req_msg)
392{
393 return (u8) ((req_msg->alt_offset138 & 0x08) >> 3);
394}
395
396static inline void cm_req_set_alt_subnet_local(struct cm_req_msg *req_msg,
397 u8 subnet_local)
398{
399 req_msg->alt_offset138 = (u8) ((req_msg->alt_offset138 & 0xF7) |
400 ((subnet_local & 0x1) << 3));
401}
402
403static inline u8 cm_req_get_alt_local_ack_timeout(struct cm_req_msg *req_msg)
404{
405 return (u8) (req_msg->alt_offset139 >> 3);
406}
407
408static inline void cm_req_set_alt_local_ack_timeout(struct cm_req_msg *req_msg,
409 u8 local_ack_timeout)
410{
411 req_msg->alt_offset139 = (u8) ((req_msg->alt_offset139 & 0x07) |
412 (local_ack_timeout << 3));
413}
414
415/* Message REJected or MRAed */
416enum cm_msg_response {
417 CM_MSG_RESPONSE_REQ = 0x0,
418 CM_MSG_RESPONSE_REP = 0x1,
419 CM_MSG_RESPONSE_OTHER = 0x2
420};
421
422 struct cm_mra_msg {
423 struct ib_mad_hdr hdr;
424
425 u32 local_comm_id;
426 u32 remote_comm_id;
427 /* message MRAed:2, rsvd:6 */
428 u8 offset8;
429 /* service timeout:5, rsvd:3 */
430 u8 offset9;
431
432 u8 private_data[IB_CM_MRA_PRIVATE_DATA_SIZE];
433
434} __attribute__ ((packed));
435
436static inline u8 cm_mra_get_msg_mraed(struct cm_mra_msg *mra_msg)
437{
438 return (u8) (mra_msg->offset8 >> 6);
439}
440
441static inline void cm_mra_set_msg_mraed(struct cm_mra_msg *mra_msg, u8 msg)
442{
443 mra_msg->offset8 = (u8) ((mra_msg->offset8 & 0x3F) | (msg << 6));
444}
445
446static inline u8 cm_mra_get_service_timeout(struct cm_mra_msg *mra_msg)
447{
448 return (u8) (mra_msg->offset9 >> 3);
449}
450
451static inline void cm_mra_set_service_timeout(struct cm_mra_msg *mra_msg,
452 u8 service_timeout)
453{
454 mra_msg->offset9 = (u8) ((mra_msg->offset9 & 0x07) |
455 (service_timeout << 3));
456}
457
458struct cm_rej_msg {
459 struct ib_mad_hdr hdr;
460
461 u32 local_comm_id;
462 u32 remote_comm_id;
463 /* message REJected:2, rsvd:6 */
464 u8 offset8;
465 /* reject info length:7, rsvd:1. */
466 u8 offset9;
467 u16 reason;
468 u8 ari[IB_CM_REJ_ARI_LENGTH];
469
470 u8 private_data[IB_CM_REJ_PRIVATE_DATA_SIZE];
471
472} __attribute__ ((packed));
473
474static inline u8 cm_rej_get_msg_rejected(struct cm_rej_msg *rej_msg)
475{
476 return (u8) (rej_msg->offset8 >> 6);
477}
478
479static inline void cm_rej_set_msg_rejected(struct cm_rej_msg *rej_msg, u8 msg)
480{
481 rej_msg->offset8 = (u8) ((rej_msg->offset8 & 0x3F) | (msg << 6));
482}
483
484static inline u8 cm_rej_get_reject_info_len(struct cm_rej_msg *rej_msg)
485{
486 return (u8) (rej_msg->offset9 >> 1);
487}
488
489static inline void cm_rej_set_reject_info_len(struct cm_rej_msg *rej_msg,
490 u8 len)
491{
492 rej_msg->offset9 = (u8) ((rej_msg->offset9 & 0x1) | (len << 1));
493}
494
495struct cm_rep_msg {
496 struct ib_mad_hdr hdr;
497
498 u32 local_comm_id;
499 u32 remote_comm_id;
500 u32 local_qkey;
501 /* local QPN:24, rsvd:8 */
502 u32 offset12;
503 /* local EECN:24, rsvd:8 */
504 u32 offset16;
505 /* starting PSN:24 rsvd:8 */
506 u32 offset20;
507 u8 resp_resources;
508 u8 initiator_depth;
509 /* target ACK delay:5, failover accepted:2, end-to-end flow control:1 */
510 u8 offset26;
511 /* RNR retry count:3, SRQ:1, rsvd:5 */
512 u8 offset27;
513 u64 local_ca_guid;
514
515 u8 private_data[IB_CM_REP_PRIVATE_DATA_SIZE];
516
517} __attribute__ ((packed));
518
519static inline u32 cm_rep_get_local_qpn(struct cm_rep_msg *rep_msg)
520{
521 return cpu_to_be32(be32_to_cpu(rep_msg->offset12) >> 8);
522}
523
524static inline void cm_rep_set_local_qpn(struct cm_rep_msg *rep_msg, u32 qpn)
525{
526 rep_msg->offset12 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
527 (be32_to_cpu(rep_msg->offset12) & 0x000000FF));
528}
529
530static inline u32 cm_rep_get_starting_psn(struct cm_rep_msg *rep_msg)
531{
532 return cpu_to_be32(be32_to_cpu(rep_msg->offset20) >> 8);
533}
534
535static inline void cm_rep_set_starting_psn(struct cm_rep_msg *rep_msg,
536 u32 starting_psn)
537{
538 rep_msg->offset20 = cpu_to_be32((be32_to_cpu(starting_psn) << 8) |
539 (be32_to_cpu(rep_msg->offset20) & 0x000000FF));
540}
541
542static inline u8 cm_rep_get_target_ack_delay(struct cm_rep_msg *rep_msg)
543{
544 return (u8) (rep_msg->offset26 >> 3);
545}
546
547static inline void cm_rep_set_target_ack_delay(struct cm_rep_msg *rep_msg,
548 u8 target_ack_delay)
549{
550 rep_msg->offset26 = (u8) ((rep_msg->offset26 & 0x07) |
551 (target_ack_delay << 3));
552}
553
554static inline u8 cm_rep_get_failover(struct cm_rep_msg *rep_msg)
555{
556 return (u8) ((rep_msg->offset26 & 0x06) >> 1);
557}
558
559static inline void cm_rep_set_failover(struct cm_rep_msg *rep_msg, u8 failover)
560{
561 rep_msg->offset26 = (u8) ((rep_msg->offset26 & 0xF9) |
562 ((failover & 0x3) << 1));
563}
564
565static inline u8 cm_rep_get_flow_ctrl(struct cm_rep_msg *rep_msg)
566{
567 return (u8) (rep_msg->offset26 & 0x01);
568}
569
570static inline void cm_rep_set_flow_ctrl(struct cm_rep_msg *rep_msg,
571 u8 flow_ctrl)
572{
573 rep_msg->offset26 = (u8) ((rep_msg->offset26 & 0xFE) |
574 (flow_ctrl & 0x1));
575}
576
577static inline u8 cm_rep_get_rnr_retry_count(struct cm_rep_msg *rep_msg)
578{
579 return (u8) (rep_msg->offset27 >> 5);
580}
581
582static inline void cm_rep_set_rnr_retry_count(struct cm_rep_msg *rep_msg,
583 u8 rnr_retry_count)
584{
585 rep_msg->offset27 = (u8) ((rep_msg->offset27 & 0x1F) |
586 (rnr_retry_count << 5));
587}
588
589static inline u8 cm_rep_get_srq(struct cm_rep_msg *rep_msg)
590{
591 return (u8) ((rep_msg->offset27 >> 4) & 0x1);
592}
593
594static inline void cm_rep_set_srq(struct cm_rep_msg *rep_msg, u8 srq)
595{
596 rep_msg->offset27 = (u8) ((rep_msg->offset27 & 0xEF) |
597 ((srq & 0x1) << 4));
598}
599
600struct cm_rtu_msg {
601 struct ib_mad_hdr hdr;
602
603 u32 local_comm_id;
604 u32 remote_comm_id;
605
606 u8 private_data[IB_CM_RTU_PRIVATE_DATA_SIZE];
607
608} __attribute__ ((packed));
609
610struct cm_dreq_msg {
611 struct ib_mad_hdr hdr;
612
613 u32 local_comm_id;
614 u32 remote_comm_id;
615 /* remote QPN/EECN:24, rsvd:8 */
616 u32 offset8;
617
618 u8 private_data[IB_CM_DREQ_PRIVATE_DATA_SIZE];
619
620} __attribute__ ((packed));
621
622static inline u32 cm_dreq_get_remote_qpn(struct cm_dreq_msg *dreq_msg)
623{
624 return cpu_to_be32(be32_to_cpu(dreq_msg->offset8) >> 8);
625}
626
627static inline void cm_dreq_set_remote_qpn(struct cm_dreq_msg *dreq_msg, u32 qpn)
628{
629 dreq_msg->offset8 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
630 (be32_to_cpu(dreq_msg->offset8) & 0x000000FF));
631}
632
633struct cm_drep_msg {
634 struct ib_mad_hdr hdr;
635
636 u32 local_comm_id;
637 u32 remote_comm_id;
638
639 u8 private_data[IB_CM_DREP_PRIVATE_DATA_SIZE];
640
641} __attribute__ ((packed));
642
643struct cm_lap_msg {
644 struct ib_mad_hdr hdr;
645
646 u32 local_comm_id;
647 u32 remote_comm_id;
648
649 u32 rsvd8;
650 /* remote QPN/EECN:24, remote CM response timeout:5, rsvd:3 */
651 u32 offset12;
652 u32 rsvd16;
653
654 u16 alt_local_lid;
655 u16 alt_remote_lid;
656 union ib_gid alt_local_gid;
657 union ib_gid alt_remote_gid;
658 /* flow label:20, rsvd:4, traffic class:8 */
659 u32 offset56;
660 u8 alt_hop_limit;
661 /* rsvd:2, packet rate:6 */
662 uint8_t offset61;
663 /* SL:4, subnet local:1, rsvd:3 */
664 uint8_t offset62;
665 /* local ACK timeout:5, rsvd:3 */
666 uint8_t offset63;
667
668 u8 private_data[IB_CM_LAP_PRIVATE_DATA_SIZE];
669} __attribute__ ((packed));
670
671static inline u32 cm_lap_get_remote_qpn(struct cm_lap_msg *lap_msg)
672{
673 return cpu_to_be32(be32_to_cpu(lap_msg->offset12) >> 8);
674}
675
676static inline void cm_lap_set_remote_qpn(struct cm_lap_msg *lap_msg, u32 qpn)
677{
678 lap_msg->offset12 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
679 (be32_to_cpu(lap_msg->offset12) &
680 0x000000FF));
681}
682
683static inline u8 cm_lap_get_remote_resp_timeout(struct cm_lap_msg *lap_msg)
684{
685 return (u8) ((be32_to_cpu(lap_msg->offset12) & 0xF8) >> 3);
686}
687
688static inline void cm_lap_set_remote_resp_timeout(struct cm_lap_msg *lap_msg,
689 u8 resp_timeout)
690{
691 lap_msg->offset12 = cpu_to_be32((resp_timeout << 3) |
692 (be32_to_cpu(lap_msg->offset12) &
693 0xFFFFFF07));
694}
695
696static inline u32 cm_lap_get_flow_label(struct cm_lap_msg *lap_msg)
697{
698 return be32_to_cpu(lap_msg->offset56) >> 12;
699}
700
701static inline void cm_lap_set_flow_label(struct cm_lap_msg *lap_msg,
702 u32 flow_label)
703{
704 lap_msg->offset56 = cpu_to_be32((flow_label << 12) |
705 (be32_to_cpu(lap_msg->offset56) &
706 0x00000FFF));
707}
708
709static inline u8 cm_lap_get_traffic_class(struct cm_lap_msg *lap_msg)
710{
711 return (u8) be32_to_cpu(lap_msg->offset56);
712}
713
714static inline void cm_lap_set_traffic_class(struct cm_lap_msg *lap_msg,
715 u8 traffic_class)
716{
717 lap_msg->offset56 = cpu_to_be32(traffic_class |
718 (be32_to_cpu(lap_msg->offset56) &
719 0xFFFFFF00));
720}
721
722static inline u8 cm_lap_get_packet_rate(struct cm_lap_msg *lap_msg)
723{
724 return lap_msg->offset61 & 0x3F;
725}
726
727static inline void cm_lap_set_packet_rate(struct cm_lap_msg *lap_msg,
728 u8 packet_rate)
729{
730 lap_msg->offset61 = (packet_rate & 0x3F) | (lap_msg->offset61 & 0xC0);
731}
732
733static inline u8 cm_lap_get_sl(struct cm_lap_msg *lap_msg)
734{
735 return lap_msg->offset62 >> 4;
736}
737
738static inline void cm_lap_set_sl(struct cm_lap_msg *lap_msg, u8 sl)
739{
740 lap_msg->offset62 = (sl << 4) | (lap_msg->offset62 & 0x0F);
741}
742
743static inline u8 cm_lap_get_subnet_local(struct cm_lap_msg *lap_msg)
744{
745 return (lap_msg->offset62 >> 3) & 0x1;
746}
747
748static inline void cm_lap_set_subnet_local(struct cm_lap_msg *lap_msg,
749 u8 subnet_local)
750{
751 lap_msg->offset62 = ((subnet_local & 0x1) << 3) |
752 (lap_msg->offset61 & 0xF7);
753}
754static inline u8 cm_lap_get_local_ack_timeout(struct cm_lap_msg *lap_msg)
755{
756 return lap_msg->offset63 >> 3;
757}
758
759static inline void cm_lap_set_local_ack_timeout(struct cm_lap_msg *lap_msg,
760 u8 local_ack_timeout)
761{
762 lap_msg->offset63 = (local_ack_timeout << 3) |
763 (lap_msg->offset63 & 0x07);
764}
765
766struct cm_apr_msg {
767 struct ib_mad_hdr hdr;
768
769 u32 local_comm_id;
770 u32 remote_comm_id;
771
772 u8 info_length;
773 u8 ap_status;
774 u8 info[IB_CM_APR_INFO_LENGTH];
775
776 u8 private_data[IB_CM_APR_PRIVATE_DATA_SIZE];
777} __attribute__ ((packed));
778
779struct cm_sidr_req_msg {
780 struct ib_mad_hdr hdr;
781
782 u32 request_id;
783 u16 pkey;
784 u16 rsvd;
785 u64 service_id;
786
787 u8 private_data[IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE];
788} __attribute__ ((packed));
789
790struct cm_sidr_rep_msg {
791 struct ib_mad_hdr hdr;
792
793 u32 request_id;
794 u8 status;
795 u8 info_length;
796 u16 rsvd;
797 /* QPN:24, rsvd:8 */
798 u32 offset8;
799 u64 service_id;
800 u32 qkey;
801 u8 info[IB_CM_SIDR_REP_INFO_LENGTH];
802
803 u8 private_data[IB_CM_SIDR_REP_PRIVATE_DATA_SIZE];
804} __attribute__ ((packed));
805
806static inline u32 cm_sidr_rep_get_qpn(struct cm_sidr_rep_msg *sidr_rep_msg)
807{
808 return cpu_to_be32(be32_to_cpu(sidr_rep_msg->offset8) >> 8);
809}
810
811static inline void cm_sidr_rep_set_qpn(struct cm_sidr_rep_msg *sidr_rep_msg,
812 u32 qpn)
813{
814 sidr_rep_msg->offset8 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
815 (be32_to_cpu(sidr_rep_msg->offset8) &
816 0x000000FF));
817}
818
819#endif /* CM_MSGS_H */
diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
index 328feae2a5be..7763b31abba7 100644
--- a/drivers/infiniband/core/fmr_pool.c
+++ b/drivers/infiniband/core/fmr_pool.c
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (c) 2004 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
3 * 4 *
4 * This software is available to you under a choice of one of two 5 * 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 * licenses. You may choose to be licensed under the terms of the GNU
@@ -29,7 +30,7 @@
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE. 31 * SOFTWARE.
31 * 32 *
32 * $Id: fmr_pool.c 1349 2004-12-16 21:09:43Z roland $ 33 * $Id: fmr_pool.c 2730 2005-06-28 16:43:03Z sean.hefty $
33 */ 34 */
34 35
35#include <linux/errno.h> 36#include <linux/errno.h>
@@ -329,7 +330,7 @@ EXPORT_SYMBOL(ib_create_fmr_pool);
329 * 330 *
330 * Destroy an FMR pool and free all associated resources. 331 * Destroy an FMR pool and free all associated resources.
331 */ 332 */
332int ib_destroy_fmr_pool(struct ib_fmr_pool *pool) 333void ib_destroy_fmr_pool(struct ib_fmr_pool *pool)
333{ 334{
334 struct ib_pool_fmr *fmr; 335 struct ib_pool_fmr *fmr;
335 struct ib_pool_fmr *tmp; 336 struct ib_pool_fmr *tmp;
@@ -352,8 +353,6 @@ int ib_destroy_fmr_pool(struct ib_fmr_pool *pool)
352 353
353 kfree(pool->cache_bucket); 354 kfree(pool->cache_bucket);
354 kfree(pool); 355 kfree(pool);
355
356 return 0;
357} 356}
358EXPORT_SYMBOL(ib_destroy_fmr_pool); 357EXPORT_SYMBOL(ib_destroy_fmr_pool);
359 358
diff --git a/drivers/infiniband/core/mad.c b/drivers/infiniband/core/mad.c
index 23628c622a50..b97e210ce9c8 100644
--- a/drivers/infiniband/core/mad.c
+++ b/drivers/infiniband/core/mad.c
@@ -1,5 +1,7 @@
1/* 1/*
2 * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved. 2 * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.
3 * Copyright (c) 2005 Intel Corporation. All rights reserved.
4 * Copyright (c) 2005 Mellanox Technologies Ltd. All rights reserved.
3 * 5 *
4 * 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
5 * 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
@@ -29,12 +31,12 @@
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE. 32 * SOFTWARE.
31 * 33 *
32 * $Id: mad.c 1389 2004-12-27 22:56:47Z roland $ 34 * $Id: mad.c 2817 2005-07-07 11:29:26Z halr $
33 */ 35 */
34
35#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
36 37
37#include "mad_priv.h" 38#include "mad_priv.h"
39#include "mad_rmpp.h"
38#include "smi.h" 40#include "smi.h"
39#include "agent.h" 41#include "agent.h"
40 42
@@ -45,6 +47,7 @@ MODULE_AUTHOR("Sean Hefty");
45 47
46 48
47kmem_cache_t *ib_mad_cache; 49kmem_cache_t *ib_mad_cache;
50
48static struct list_head ib_mad_port_list; 51static struct list_head ib_mad_port_list;
49static u32 ib_mad_client_id = 0; 52static u32 ib_mad_client_id = 0;
50 53
@@ -58,16 +61,12 @@ static int method_in_use(struct ib_mad_mgmt_method_table **method,
58static void remove_mad_reg_req(struct ib_mad_agent_private *priv); 61static void remove_mad_reg_req(struct ib_mad_agent_private *priv);
59static struct ib_mad_agent_private *find_mad_agent( 62static struct ib_mad_agent_private *find_mad_agent(
60 struct ib_mad_port_private *port_priv, 63 struct ib_mad_port_private *port_priv,
61 struct ib_mad *mad, int solicited); 64 struct ib_mad *mad);
62static int ib_mad_post_receive_mads(struct ib_mad_qp_info *qp_info, 65static int ib_mad_post_receive_mads(struct ib_mad_qp_info *qp_info,
63 struct ib_mad_private *mad); 66 struct ib_mad_private *mad);
64static void cancel_mads(struct ib_mad_agent_private *mad_agent_priv); 67static void cancel_mads(struct ib_mad_agent_private *mad_agent_priv);
65static void ib_mad_complete_send_wr(struct ib_mad_send_wr_private *mad_send_wr,
66 struct ib_mad_send_wc *mad_send_wc);
67static void timeout_sends(void *data); 68static void timeout_sends(void *data);
68static void cancel_sends(void *data);
69static void local_completions(void *data); 69static void local_completions(void *data);
70static int solicited_mad(struct ib_mad *mad);
71static int add_nonoui_reg_req(struct ib_mad_reg_req *mad_reg_req, 70static int add_nonoui_reg_req(struct ib_mad_reg_req *mad_reg_req,
72 struct ib_mad_agent_private *agent_priv, 71 struct ib_mad_agent_private *agent_priv,
73 u8 mgmt_class); 72 u8 mgmt_class);
@@ -197,8 +196,8 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
197 if (qpn == -1) 196 if (qpn == -1)
198 goto error1; 197 goto error1;
199 198
200 if (rmpp_version) 199 if (rmpp_version && rmpp_version != IB_MGMT_RMPP_VERSION)
201 goto error1; /* XXX: until RMPP implemented */ 200 goto error1;
202 201
203 /* Validate MAD registration request if supplied */ 202 /* Validate MAD registration request if supplied */
204 if (mad_reg_req) { 203 if (mad_reg_req) {
@@ -261,22 +260,29 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
261 ret = ERR_PTR(-ENOMEM); 260 ret = ERR_PTR(-ENOMEM);
262 goto error1; 261 goto error1;
263 } 262 }
263 memset(mad_agent_priv, 0, sizeof *mad_agent_priv);
264
265 mad_agent_priv->agent.mr = ib_get_dma_mr(port_priv->qp_info[qpn].qp->pd,
266 IB_ACCESS_LOCAL_WRITE);
267 if (IS_ERR(mad_agent_priv->agent.mr)) {
268 ret = ERR_PTR(-ENOMEM);
269 goto error2;
270 }
264 271
265 if (mad_reg_req) { 272 if (mad_reg_req) {
266 reg_req = kmalloc(sizeof *reg_req, GFP_KERNEL); 273 reg_req = kmalloc(sizeof *reg_req, GFP_KERNEL);
267 if (!reg_req) { 274 if (!reg_req) {
268 ret = ERR_PTR(-ENOMEM); 275 ret = ERR_PTR(-ENOMEM);
269 goto error2; 276 goto error3;
270 } 277 }
271 /* Make a copy of the MAD registration request */ 278 /* Make a copy of the MAD registration request */
272 memcpy(reg_req, mad_reg_req, sizeof *reg_req); 279 memcpy(reg_req, mad_reg_req, sizeof *reg_req);
273 } 280 }
274 281
275 /* Now, fill in the various structures */ 282 /* Now, fill in the various structures */
276 memset(mad_agent_priv, 0, sizeof *mad_agent_priv);
277 mad_agent_priv->qp_info = &port_priv->qp_info[qpn]; 283 mad_agent_priv->qp_info = &port_priv->qp_info[qpn];
278 mad_agent_priv->reg_req = reg_req; 284 mad_agent_priv->reg_req = reg_req;
279 mad_agent_priv->rmpp_version = rmpp_version; 285 mad_agent_priv->agent.rmpp_version = rmpp_version;
280 mad_agent_priv->agent.device = device; 286 mad_agent_priv->agent.device = device;
281 mad_agent_priv->agent.recv_handler = recv_handler; 287 mad_agent_priv->agent.recv_handler = recv_handler;
282 mad_agent_priv->agent.send_handler = send_handler; 288 mad_agent_priv->agent.send_handler = send_handler;
@@ -301,7 +307,7 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
301 if (method) { 307 if (method) {
302 if (method_in_use(&method, 308 if (method_in_use(&method,
303 mad_reg_req)) 309 mad_reg_req))
304 goto error3; 310 goto error4;
305 } 311 }
306 } 312 }
307 ret2 = add_nonoui_reg_req(mad_reg_req, mad_agent_priv, 313 ret2 = add_nonoui_reg_req(mad_reg_req, mad_agent_priv,
@@ -317,14 +323,14 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
317 if (is_vendor_method_in_use( 323 if (is_vendor_method_in_use(
318 vendor_class, 324 vendor_class,
319 mad_reg_req)) 325 mad_reg_req))
320 goto error3; 326 goto error4;
321 } 327 }
322 } 328 }
323 ret2 = add_oui_reg_req(mad_reg_req, mad_agent_priv); 329 ret2 = add_oui_reg_req(mad_reg_req, mad_agent_priv);
324 } 330 }
325 if (ret2) { 331 if (ret2) {
326 ret = ERR_PTR(ret2); 332 ret = ERR_PTR(ret2);
327 goto error3; 333 goto error4;
328 } 334 }
329 } 335 }
330 336
@@ -335,22 +341,24 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
335 spin_lock_init(&mad_agent_priv->lock); 341 spin_lock_init(&mad_agent_priv->lock);
336 INIT_LIST_HEAD(&mad_agent_priv->send_list); 342 INIT_LIST_HEAD(&mad_agent_priv->send_list);
337 INIT_LIST_HEAD(&mad_agent_priv->wait_list); 343 INIT_LIST_HEAD(&mad_agent_priv->wait_list);
344 INIT_LIST_HEAD(&mad_agent_priv->done_list);
345 INIT_LIST_HEAD(&mad_agent_priv->rmpp_list);
338 INIT_WORK(&mad_agent_priv->timed_work, timeout_sends, mad_agent_priv); 346 INIT_WORK(&mad_agent_priv->timed_work, timeout_sends, mad_agent_priv);
339 INIT_LIST_HEAD(&mad_agent_priv->local_list); 347 INIT_LIST_HEAD(&mad_agent_priv->local_list);
340 INIT_WORK(&mad_agent_priv->local_work, local_completions, 348 INIT_WORK(&mad_agent_priv->local_work, local_completions,
341 mad_agent_priv); 349 mad_agent_priv);
342 INIT_LIST_HEAD(&mad_agent_priv->canceled_list);
343 INIT_WORK(&mad_agent_priv->canceled_work, cancel_sends, mad_agent_priv);
344 atomic_set(&mad_agent_priv->refcount, 1); 350 atomic_set(&mad_agent_priv->refcount, 1);
345 init_waitqueue_head(&mad_agent_priv->wait); 351 init_waitqueue_head(&mad_agent_priv->wait);
346 352
347 return &mad_agent_priv->agent; 353 return &mad_agent_priv->agent;
348 354
349error3: 355error4:
350 spin_unlock_irqrestore(&port_priv->reg_lock, flags); 356 spin_unlock_irqrestore(&port_priv->reg_lock, flags);
351 kfree(reg_req); 357 kfree(reg_req);
352error2: 358error3:
353 kfree(mad_agent_priv); 359 kfree(mad_agent_priv);
360error2:
361 ib_dereg_mr(mad_agent_priv->agent.mr);
354error1: 362error1:
355 return ret; 363 return ret;
356} 364}
@@ -487,18 +495,16 @@ static void unregister_mad_agent(struct ib_mad_agent_private *mad_agent_priv)
487 * MADs, preventing us from queuing additional work 495 * MADs, preventing us from queuing additional work
488 */ 496 */
489 cancel_mads(mad_agent_priv); 497 cancel_mads(mad_agent_priv);
490
491 port_priv = mad_agent_priv->qp_info->port_priv; 498 port_priv = mad_agent_priv->qp_info->port_priv;
492
493 cancel_delayed_work(&mad_agent_priv->timed_work); 499 cancel_delayed_work(&mad_agent_priv->timed_work);
494 flush_workqueue(port_priv->wq);
495 500
496 spin_lock_irqsave(&port_priv->reg_lock, flags); 501 spin_lock_irqsave(&port_priv->reg_lock, flags);
497 remove_mad_reg_req(mad_agent_priv); 502 remove_mad_reg_req(mad_agent_priv);
498 list_del(&mad_agent_priv->agent_list); 503 list_del(&mad_agent_priv->agent_list);
499 spin_unlock_irqrestore(&port_priv->reg_lock, flags); 504 spin_unlock_irqrestore(&port_priv->reg_lock, flags);
500 505
501 /* XXX: Cleanup pending RMPP receives for this agent */ 506 flush_workqueue(port_priv->wq);
507 ib_cancel_rmpp_recvs(mad_agent_priv);
502 508
503 atomic_dec(&mad_agent_priv->refcount); 509 atomic_dec(&mad_agent_priv->refcount);
504 wait_event(mad_agent_priv->wait, 510 wait_event(mad_agent_priv->wait,
@@ -506,6 +512,7 @@ static void unregister_mad_agent(struct ib_mad_agent_private *mad_agent_priv)
506 512
507 if (mad_agent_priv->reg_req) 513 if (mad_agent_priv->reg_req)
508 kfree(mad_agent_priv->reg_req); 514 kfree(mad_agent_priv->reg_req);
515 ib_dereg_mr(mad_agent_priv->agent.mr);
509 kfree(mad_agent_priv); 516 kfree(mad_agent_priv);
510} 517}
511 518
@@ -551,6 +558,13 @@ int ib_unregister_mad_agent(struct ib_mad_agent *mad_agent)
551} 558}
552EXPORT_SYMBOL(ib_unregister_mad_agent); 559EXPORT_SYMBOL(ib_unregister_mad_agent);
553 560
561static inline int response_mad(struct ib_mad *mad)
562{
563 /* Trap represses are responses although response bit is reset */
564 return ((mad->mad_hdr.method == IB_MGMT_METHOD_TRAP_REPRESS) ||
565 (mad->mad_hdr.method & IB_MGMT_METHOD_RESP));
566}
567
554static void dequeue_mad(struct ib_mad_list_head *mad_list) 568static void dequeue_mad(struct ib_mad_list_head *mad_list)
555{ 569{
556 struct ib_mad_queue *mad_queue; 570 struct ib_mad_queue *mad_queue;
@@ -643,7 +657,7 @@ static int handle_outgoing_dr_smp(struct ib_mad_agent_private *mad_agent_priv,
643 struct ib_smp *smp, 657 struct ib_smp *smp,
644 struct ib_send_wr *send_wr) 658 struct ib_send_wr *send_wr)
645{ 659{
646 int ret, solicited; 660 int ret;
647 unsigned long flags; 661 unsigned long flags;
648 struct ib_mad_local_private *local; 662 struct ib_mad_local_private *local;
649 struct ib_mad_private *mad_priv; 663 struct ib_mad_private *mad_priv;
@@ -689,11 +703,7 @@ static int handle_outgoing_dr_smp(struct ib_mad_agent_private *mad_agent_priv,
689 switch (ret) 703 switch (ret)
690 { 704 {
691 case IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY: 705 case IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY:
692 /* 706 if (response_mad(&mad_priv->mad.mad) &&
693 * See if response is solicited and
694 * there is a recv handler
695 */
696 if (solicited_mad(&mad_priv->mad.mad) &&
697 mad_agent_priv->agent.recv_handler) { 707 mad_agent_priv->agent.recv_handler) {
698 local->mad_priv = mad_priv; 708 local->mad_priv = mad_priv;
699 local->recv_mad_agent = mad_agent_priv; 709 local->recv_mad_agent = mad_agent_priv;
@@ -710,15 +720,13 @@ static int handle_outgoing_dr_smp(struct ib_mad_agent_private *mad_agent_priv,
710 break; 720 break;
711 case IB_MAD_RESULT_SUCCESS: 721 case IB_MAD_RESULT_SUCCESS:
712 /* Treat like an incoming receive MAD */ 722 /* Treat like an incoming receive MAD */
713 solicited = solicited_mad(&mad_priv->mad.mad);
714 port_priv = ib_get_mad_port(mad_agent_priv->agent.device, 723 port_priv = ib_get_mad_port(mad_agent_priv->agent.device,
715 mad_agent_priv->agent.port_num); 724 mad_agent_priv->agent.port_num);
716 if (port_priv) { 725 if (port_priv) {
717 mad_priv->mad.mad.mad_hdr.tid = 726 mad_priv->mad.mad.mad_hdr.tid =
718 ((struct ib_mad *)smp)->mad_hdr.tid; 727 ((struct ib_mad *)smp)->mad_hdr.tid;
719 recv_mad_agent = find_mad_agent(port_priv, 728 recv_mad_agent = find_mad_agent(port_priv,
720 &mad_priv->mad.mad, 729 &mad_priv->mad.mad);
721 solicited);
722 } 730 }
723 if (!port_priv || !recv_mad_agent) { 731 if (!port_priv || !recv_mad_agent) {
724 kmem_cache_free(ib_mad_cache, mad_priv); 732 kmem_cache_free(ib_mad_cache, mad_priv);
@@ -750,43 +758,133 @@ static int handle_outgoing_dr_smp(struct ib_mad_agent_private *mad_agent_priv,
750 list_add_tail(&local->completion_list, &mad_agent_priv->local_list); 758 list_add_tail(&local->completion_list, &mad_agent_priv->local_list);
751 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); 759 spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
752 queue_work(mad_agent_priv->qp_info->port_priv->wq, 760 queue_work(mad_agent_priv->qp_info->port_priv->wq,
753 &mad_agent_priv->local_work); 761 &mad_agent_priv->local_work);
754 ret = 1; 762 ret = 1;
755out: 763out:
756 return ret; 764 return ret;
757} 765}
758 766
759static int ib_send_mad(struct ib_mad_agent_private *mad_agent_priv, 767static int get_buf_length(int hdr_len, int data_len)
760 struct ib_mad_send_wr_private *mad_send_wr) 768{
769 int seg_size, pad;
770
771 seg_size = sizeof(struct ib_mad) - hdr_len;
772 if (data_len && seg_size) {
773 pad = seg_size - data_len % seg_size;
774 if (pad == seg_size)
775 pad = 0;
776 } else
777 pad = seg_size;
778 return hdr_len + data_len + pad;
779}
780
781struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent,
782 u32 remote_qpn, u16 pkey_index,
783 struct ib_ah *ah, int rmpp_active,
784 int hdr_len, int data_len,
785 unsigned int __nocast gfp_mask)
786{
787 struct ib_mad_agent_private *mad_agent_priv;
788 struct ib_mad_send_buf *send_buf;
789 int buf_size;
790 void *buf;
791
792 mad_agent_priv = container_of(mad_agent,
793 struct ib_mad_agent_private, agent);
794 buf_size = get_buf_length(hdr_len, data_len);
795
796 if ((!mad_agent->rmpp_version &&
797 (rmpp_active || buf_size > sizeof(struct ib_mad))) ||
798 (!rmpp_active && buf_size > sizeof(struct ib_mad)))
799 return ERR_PTR(-EINVAL);
800
801 buf = kmalloc(sizeof *send_buf + buf_size, gfp_mask);
802 if (!buf)
803 return ERR_PTR(-ENOMEM);
804 memset(buf, 0, sizeof *send_buf + buf_size);
805
806 send_buf = buf + buf_size;
807 send_buf->mad = buf;
808
809 send_buf->sge.addr = dma_map_single(mad_agent->device->dma_device,
810 buf, buf_size, DMA_TO_DEVICE);
811 pci_unmap_addr_set(send_buf, mapping, send_buf->sge.addr);
812 send_buf->sge.length = buf_size;
813 send_buf->sge.lkey = mad_agent->mr->lkey;
814
815 send_buf->send_wr.wr_id = (unsigned long) send_buf;
816 send_buf->send_wr.sg_list = &send_buf->sge;
817 send_buf->send_wr.num_sge = 1;
818 send_buf->send_wr.opcode = IB_WR_SEND;
819 send_buf->send_wr.send_flags = IB_SEND_SIGNALED;
820 send_buf->send_wr.wr.ud.ah = ah;
821 send_buf->send_wr.wr.ud.mad_hdr = &send_buf->mad->mad_hdr;
822 send_buf->send_wr.wr.ud.remote_qpn = remote_qpn;
823 send_buf->send_wr.wr.ud.remote_qkey = IB_QP_SET_QKEY;
824 send_buf->send_wr.wr.ud.pkey_index = pkey_index;
825
826 if (rmpp_active) {
827 struct ib_rmpp_mad *rmpp_mad;
828 rmpp_mad = (struct ib_rmpp_mad *)send_buf->mad;
829 rmpp_mad->rmpp_hdr.paylen_newwin = cpu_to_be32(hdr_len -
830 offsetof(struct ib_rmpp_mad, data) + data_len);
831 rmpp_mad->rmpp_hdr.rmpp_version = mad_agent->rmpp_version;
832 rmpp_mad->rmpp_hdr.rmpp_type = IB_MGMT_RMPP_TYPE_DATA;
833 ib_set_rmpp_flags(&rmpp_mad->rmpp_hdr,
834 IB_MGMT_RMPP_FLAG_ACTIVE);
835 }
836
837 send_buf->mad_agent = mad_agent;
838 atomic_inc(&mad_agent_priv->refcount);
839 return send_buf;
840}
841EXPORT_SYMBOL(ib_create_send_mad);
842
843void ib_free_send_mad(struct ib_mad_send_buf *send_buf)
844{
845 struct ib_mad_agent_private *mad_agent_priv;
846
847 mad_agent_priv = container_of(send_buf->mad_agent,
848 struct ib_mad_agent_private, agent);
849
850 dma_unmap_single(send_buf->mad_agent->device->dma_device,
851 pci_unmap_addr(send_buf, mapping),
852 send_buf->sge.length, DMA_TO_DEVICE);
853 kfree(send_buf->mad);
854
855 if (atomic_dec_and_test(&mad_agent_priv->refcount))
856 wake_up(&mad_agent_priv->wait);
857}
858EXPORT_SYMBOL(ib_free_send_mad);
859
860int ib_send_mad(struct ib_mad_send_wr_private *mad_send_wr)
761{ 861{
762 struct ib_mad_qp_info *qp_info; 862 struct ib_mad_qp_info *qp_info;
763 struct ib_send_wr *bad_send_wr; 863 struct ib_send_wr *bad_send_wr;
864 struct list_head *list;
764 unsigned long flags; 865 unsigned long flags;
765 int ret; 866 int ret;
766 867
767 /* Replace user's WR ID with our own to find WR upon completion */ 868 /* Set WR ID to find mad_send_wr upon completion */
768 qp_info = mad_agent_priv->qp_info; 869 qp_info = mad_send_wr->mad_agent_priv->qp_info;
769 mad_send_wr->wr_id = mad_send_wr->send_wr.wr_id;
770 mad_send_wr->send_wr.wr_id = (unsigned long)&mad_send_wr->mad_list; 870 mad_send_wr->send_wr.wr_id = (unsigned long)&mad_send_wr->mad_list;
771 mad_send_wr->mad_list.mad_queue = &qp_info->send_queue; 871 mad_send_wr->mad_list.mad_queue = &qp_info->send_queue;
772 872
773 spin_lock_irqsave(&qp_info->send_queue.lock, flags); 873 spin_lock_irqsave(&qp_info->send_queue.lock, flags);
774 if (qp_info->send_queue.count++ < qp_info->send_queue.max_active) { 874 if (qp_info->send_queue.count < qp_info->send_queue.max_active) {
775 list_add_tail(&mad_send_wr->mad_list.list, 875 ret = ib_post_send(mad_send_wr->mad_agent_priv->agent.qp,
776 &qp_info->send_queue.list);
777 spin_unlock_irqrestore(&qp_info->send_queue.lock, flags);
778 ret = ib_post_send(mad_agent_priv->agent.qp,
779 &mad_send_wr->send_wr, &bad_send_wr); 876 &mad_send_wr->send_wr, &bad_send_wr);
780 if (ret) { 877 list = &qp_info->send_queue.list;
781 printk(KERN_ERR PFX "ib_post_send failed: %d\n", ret);
782 dequeue_mad(&mad_send_wr->mad_list);
783 }
784 } else { 878 } else {
785 list_add_tail(&mad_send_wr->mad_list.list,
786 &qp_info->overflow_list);
787 spin_unlock_irqrestore(&qp_info->send_queue.lock, flags);
788 ret = 0; 879 ret = 0;
880 list = &qp_info->overflow_list;
789 } 881 }
882
883 if (!ret) {
884 qp_info->send_queue.count++;
885 list_add_tail(&mad_send_wr->mad_list.list, list);
886 }
887 spin_unlock_irqrestore(&qp_info->send_queue.lock, flags);
790 return ret; 888 return ret;
791} 889}
792 890
@@ -860,18 +958,19 @@ int ib_post_send_mad(struct ib_mad_agent *mad_agent,
860 ret = -ENOMEM; 958 ret = -ENOMEM;
861 goto error2; 959 goto error2;
862 } 960 }
961 memset(mad_send_wr, 0, sizeof *mad_send_wr);
863 962
864 mad_send_wr->send_wr = *send_wr; 963 mad_send_wr->send_wr = *send_wr;
865 mad_send_wr->send_wr.sg_list = mad_send_wr->sg_list; 964 mad_send_wr->send_wr.sg_list = mad_send_wr->sg_list;
866 memcpy(mad_send_wr->sg_list, send_wr->sg_list, 965 memcpy(mad_send_wr->sg_list, send_wr->sg_list,
867 sizeof *send_wr->sg_list * send_wr->num_sge); 966 sizeof *send_wr->sg_list * send_wr->num_sge);
868 mad_send_wr->send_wr.next = NULL; 967 mad_send_wr->wr_id = send_wr->wr_id;
869 mad_send_wr->tid = send_wr->wr.ud.mad_hdr->tid; 968 mad_send_wr->tid = send_wr->wr.ud.mad_hdr->tid;
870 mad_send_wr->agent = mad_agent; 969 mad_send_wr->mad_agent_priv = mad_agent_priv;
871 /* Timeout will be updated after send completes */ 970 /* Timeout will be updated after send completes */
872 mad_send_wr->timeout = msecs_to_jiffies(send_wr->wr. 971 mad_send_wr->timeout = msecs_to_jiffies(send_wr->wr.
873 ud.timeout_ms); 972 ud.timeout_ms);
874 mad_send_wr->retry = 0; 973 mad_send_wr->retries = mad_send_wr->send_wr.wr.ud.retries;
875 /* One reference for each work request to QP + response */ 974 /* One reference for each work request to QP + response */
876 mad_send_wr->refcount = 1 + (mad_send_wr->timeout > 0); 975 mad_send_wr->refcount = 1 + (mad_send_wr->timeout > 0);
877 mad_send_wr->status = IB_WC_SUCCESS; 976 mad_send_wr->status = IB_WC_SUCCESS;
@@ -883,8 +982,13 @@ int ib_post_send_mad(struct ib_mad_agent *mad_agent,
883 &mad_agent_priv->send_list); 982 &mad_agent_priv->send_list);
884 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); 983 spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
885 984
886 ret = ib_send_mad(mad_agent_priv, mad_send_wr); 985 if (mad_agent_priv->agent.rmpp_version) {
887 if (ret) { 986 ret = ib_send_rmpp_mad(mad_send_wr);
987 if (ret >= 0 && ret != IB_RMPP_RESULT_CONSUMED)
988 ret = ib_send_mad(mad_send_wr);
989 } else
990 ret = ib_send_mad(mad_send_wr);
991 if (ret < 0) {
888 /* Fail send request */ 992 /* Fail send request */
889 spin_lock_irqsave(&mad_agent_priv->lock, flags); 993 spin_lock_irqsave(&mad_agent_priv->lock, flags);
890 list_del(&mad_send_wr->agent_list); 994 list_del(&mad_send_wr->agent_list);
@@ -910,41 +1014,28 @@ EXPORT_SYMBOL(ib_post_send_mad);
910 */ 1014 */
911void ib_free_recv_mad(struct ib_mad_recv_wc *mad_recv_wc) 1015void ib_free_recv_mad(struct ib_mad_recv_wc *mad_recv_wc)
912{ 1016{
913 struct ib_mad_recv_buf *entry; 1017 struct ib_mad_recv_buf *mad_recv_buf, *temp_recv_buf;
914 struct ib_mad_private_header *mad_priv_hdr; 1018 struct ib_mad_private_header *mad_priv_hdr;
915 struct ib_mad_private *priv; 1019 struct ib_mad_private *priv;
1020 struct list_head free_list;
916 1021
917 mad_priv_hdr = container_of(mad_recv_wc, 1022 INIT_LIST_HEAD(&free_list);
918 struct ib_mad_private_header, 1023 list_splice_init(&mad_recv_wc->rmpp_list, &free_list);
919 recv_wc);
920 priv = container_of(mad_priv_hdr, struct ib_mad_private, header);
921 1024
922 /* 1025 list_for_each_entry_safe(mad_recv_buf, temp_recv_buf,
923 * Walk receive buffer list associated with this WC 1026 &free_list, list) {
924 * No need to remove them from list of receive buffers 1027 mad_recv_wc = container_of(mad_recv_buf, struct ib_mad_recv_wc,
925 */ 1028 recv_buf);
926 list_for_each_entry(entry, &mad_recv_wc->recv_buf.list, list) {
927 /* Free previous receive buffer */
928 kmem_cache_free(ib_mad_cache, priv);
929 mad_priv_hdr = container_of(mad_recv_wc, 1029 mad_priv_hdr = container_of(mad_recv_wc,
930 struct ib_mad_private_header, 1030 struct ib_mad_private_header,
931 recv_wc); 1031 recv_wc);
932 priv = container_of(mad_priv_hdr, struct ib_mad_private, 1032 priv = container_of(mad_priv_hdr, struct ib_mad_private,
933 header); 1033 header);
1034 kmem_cache_free(ib_mad_cache, priv);
934 } 1035 }
935
936 /* Free last buffer */
937 kmem_cache_free(ib_mad_cache, priv);
938} 1036}
939EXPORT_SYMBOL(ib_free_recv_mad); 1037EXPORT_SYMBOL(ib_free_recv_mad);
940 1038
941void ib_coalesce_recv_mad(struct ib_mad_recv_wc *mad_recv_wc,
942 void *buf)
943{
944 printk(KERN_ERR PFX "ib_coalesce_recv_mad() not implemented yet\n");
945}
946EXPORT_SYMBOL(ib_coalesce_recv_mad);
947
948struct ib_mad_agent *ib_redirect_mad_qp(struct ib_qp *qp, 1039struct ib_mad_agent *ib_redirect_mad_qp(struct ib_qp *qp,
949 u8 rmpp_version, 1040 u8 rmpp_version,
950 ib_mad_send_handler send_handler, 1041 ib_mad_send_handler send_handler,
@@ -1338,42 +1429,15 @@ out:
1338 return; 1429 return;
1339} 1430}
1340 1431
1341static int response_mad(struct ib_mad *mad)
1342{
1343 /* Trap represses are responses although response bit is reset */
1344 return ((mad->mad_hdr.method == IB_MGMT_METHOD_TRAP_REPRESS) ||
1345 (mad->mad_hdr.method & IB_MGMT_METHOD_RESP));
1346}
1347
1348static int solicited_mad(struct ib_mad *mad)
1349{
1350 /* CM MADs are never solicited */
1351 if (mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_CM) {
1352 return 0;
1353 }
1354
1355 /* XXX: Determine whether MAD is using RMPP */
1356
1357 /* Not using RMPP */
1358 /* Is this MAD a response to a previous MAD ? */
1359 return response_mad(mad);
1360}
1361
1362static struct ib_mad_agent_private * 1432static struct ib_mad_agent_private *
1363find_mad_agent(struct ib_mad_port_private *port_priv, 1433find_mad_agent(struct ib_mad_port_private *port_priv,
1364 struct ib_mad *mad, 1434 struct ib_mad *mad)
1365 int solicited)
1366{ 1435{
1367 struct ib_mad_agent_private *mad_agent = NULL; 1436 struct ib_mad_agent_private *mad_agent = NULL;
1368 unsigned long flags; 1437 unsigned long flags;
1369 1438
1370 spin_lock_irqsave(&port_priv->reg_lock, flags); 1439 spin_lock_irqsave(&port_priv->reg_lock, flags);
1371 1440 if (response_mad(mad)) {
1372 /*
1373 * Whether MAD was solicited determines type of routing to
1374 * MAD client.
1375 */
1376 if (solicited) {
1377 u32 hi_tid; 1441 u32 hi_tid;
1378 struct ib_mad_agent_private *entry; 1442 struct ib_mad_agent_private *entry;
1379 1443
@@ -1477,21 +1541,20 @@ out:
1477 return valid; 1541 return valid;
1478} 1542}
1479 1543
1480/* 1544static int is_data_mad(struct ib_mad_agent_private *mad_agent_priv,
1481 * Return start of fully reassembled MAD, or NULL, if MAD isn't assembled yet 1545 struct ib_mad_hdr *mad_hdr)
1482 */
1483static struct ib_mad_private *
1484reassemble_recv(struct ib_mad_agent_private *mad_agent_priv,
1485 struct ib_mad_private *recv)
1486{ 1546{
1487 /* Until we have RMPP, all receives are reassembled!... */ 1547 struct ib_rmpp_mad *rmpp_mad;
1488 INIT_LIST_HEAD(&recv->header.recv_wc.recv_buf.list); 1548
1489 return recv; 1549 rmpp_mad = (struct ib_rmpp_mad *)mad_hdr;
1550 return !mad_agent_priv->agent.rmpp_version ||
1551 !(ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) &
1552 IB_MGMT_RMPP_FLAG_ACTIVE) ||
1553 (rmpp_mad->rmpp_hdr.rmpp_type == IB_MGMT_RMPP_TYPE_DATA);
1490} 1554}
1491 1555
1492static struct ib_mad_send_wr_private* 1556struct ib_mad_send_wr_private*
1493find_send_req(struct ib_mad_agent_private *mad_agent_priv, 1557ib_find_send_mad(struct ib_mad_agent_private *mad_agent_priv, u64 tid)
1494 u64 tid)
1495{ 1558{
1496 struct ib_mad_send_wr_private *mad_send_wr; 1559 struct ib_mad_send_wr_private *mad_send_wr;
1497 1560
@@ -1507,7 +1570,9 @@ find_send_req(struct ib_mad_agent_private *mad_agent_priv,
1507 */ 1570 */
1508 list_for_each_entry(mad_send_wr, &mad_agent_priv->send_list, 1571 list_for_each_entry(mad_send_wr, &mad_agent_priv->send_list,
1509 agent_list) { 1572 agent_list) {
1510 if (mad_send_wr->tid == tid && mad_send_wr->timeout) { 1573 if (is_data_mad(mad_agent_priv,
1574 mad_send_wr->send_wr.wr.ud.mad_hdr) &&
1575 mad_send_wr->tid == tid && mad_send_wr->timeout) {
1511 /* Verify request has not been canceled */ 1576 /* Verify request has not been canceled */
1512 return (mad_send_wr->status == IB_WC_SUCCESS) ? 1577 return (mad_send_wr->status == IB_WC_SUCCESS) ?
1513 mad_send_wr : NULL; 1578 mad_send_wr : NULL;
@@ -1516,43 +1581,55 @@ find_send_req(struct ib_mad_agent_private *mad_agent_priv,
1516 return NULL; 1581 return NULL;
1517} 1582}
1518 1583
1584void ib_mark_mad_done(struct ib_mad_send_wr_private *mad_send_wr)
1585{
1586 mad_send_wr->timeout = 0;
1587 if (mad_send_wr->refcount == 1) {
1588 list_del(&mad_send_wr->agent_list);
1589 list_add_tail(&mad_send_wr->agent_list,
1590 &mad_send_wr->mad_agent_priv->done_list);
1591 }
1592}
1593
1519static void ib_mad_complete_recv(struct ib_mad_agent_private *mad_agent_priv, 1594static void ib_mad_complete_recv(struct ib_mad_agent_private *mad_agent_priv,
1520 struct ib_mad_private *recv, 1595 struct ib_mad_recv_wc *mad_recv_wc)
1521 int solicited)
1522{ 1596{
1523 struct ib_mad_send_wr_private *mad_send_wr; 1597 struct ib_mad_send_wr_private *mad_send_wr;
1524 struct ib_mad_send_wc mad_send_wc; 1598 struct ib_mad_send_wc mad_send_wc;
1525 unsigned long flags; 1599 unsigned long flags;
1526 1600 u64 tid;
1527 /* Fully reassemble receive before processing */ 1601
1528 recv = reassemble_recv(mad_agent_priv, recv); 1602 INIT_LIST_HEAD(&mad_recv_wc->rmpp_list);
1529 if (!recv) { 1603 list_add(&mad_recv_wc->recv_buf.list, &mad_recv_wc->rmpp_list);
1530 if (atomic_dec_and_test(&mad_agent_priv->refcount)) 1604 if (mad_agent_priv->agent.rmpp_version) {
1531 wake_up(&mad_agent_priv->wait); 1605 mad_recv_wc = ib_process_rmpp_recv_wc(mad_agent_priv,
1532 return; 1606 mad_recv_wc);
1607 if (!mad_recv_wc) {
1608 if (atomic_dec_and_test(&mad_agent_priv->refcount))
1609 wake_up(&mad_agent_priv->wait);
1610 return;
1611 }
1533 } 1612 }
1534 1613
1535 /* Complete corresponding request */ 1614 /* Complete corresponding request */
1536 if (solicited) { 1615 if (response_mad(mad_recv_wc->recv_buf.mad)) {
1616 tid = mad_recv_wc->recv_buf.mad->mad_hdr.tid;
1537 spin_lock_irqsave(&mad_agent_priv->lock, flags); 1617 spin_lock_irqsave(&mad_agent_priv->lock, flags);
1538 mad_send_wr = find_send_req(mad_agent_priv, 1618 mad_send_wr = ib_find_send_mad(mad_agent_priv, tid);
1539 recv->mad.mad.mad_hdr.tid);
1540 if (!mad_send_wr) { 1619 if (!mad_send_wr) {
1541 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); 1620 spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
1542 ib_free_recv_mad(&recv->header.recv_wc); 1621 ib_free_recv_mad(mad_recv_wc);
1543 if (atomic_dec_and_test(&mad_agent_priv->refcount)) 1622 if (atomic_dec_and_test(&mad_agent_priv->refcount))
1544 wake_up(&mad_agent_priv->wait); 1623 wake_up(&mad_agent_priv->wait);
1545 return; 1624 return;
1546 } 1625 }
1547 /* Timeout = 0 means that we won't wait for a response */ 1626 ib_mark_mad_done(mad_send_wr);
1548 mad_send_wr->timeout = 0;
1549 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); 1627 spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
1550 1628
1551 /* Defined behavior is to complete response before request */ 1629 /* Defined behavior is to complete response before request */
1552 recv->header.recv_wc.wc->wr_id = mad_send_wr->wr_id; 1630 mad_recv_wc->wc->wr_id = mad_send_wr->wr_id;
1553 mad_agent_priv->agent.recv_handler( 1631 mad_agent_priv->agent.recv_handler(&mad_agent_priv->agent,
1554 &mad_agent_priv->agent, 1632 mad_recv_wc);
1555 &recv->header.recv_wc);
1556 atomic_dec(&mad_agent_priv->refcount); 1633 atomic_dec(&mad_agent_priv->refcount);
1557 1634
1558 mad_send_wc.status = IB_WC_SUCCESS; 1635 mad_send_wc.status = IB_WC_SUCCESS;
@@ -1560,9 +1637,8 @@ static void ib_mad_complete_recv(struct ib_mad_agent_private *mad_agent_priv,
1560 mad_send_wc.wr_id = mad_send_wr->wr_id; 1637 mad_send_wc.wr_id = mad_send_wr->wr_id;
1561 ib_mad_complete_send_wr(mad_send_wr, &mad_send_wc); 1638 ib_mad_complete_send_wr(mad_send_wr, &mad_send_wc);
1562 } else { 1639 } else {
1563 mad_agent_priv->agent.recv_handler( 1640 mad_agent_priv->agent.recv_handler(&mad_agent_priv->agent,
1564 &mad_agent_priv->agent, 1641 mad_recv_wc);
1565 &recv->header.recv_wc);
1566 if (atomic_dec_and_test(&mad_agent_priv->refcount)) 1642 if (atomic_dec_and_test(&mad_agent_priv->refcount))
1567 wake_up(&mad_agent_priv->wait); 1643 wake_up(&mad_agent_priv->wait);
1568 } 1644 }
@@ -1576,7 +1652,6 @@ static void ib_mad_recv_done_handler(struct ib_mad_port_private *port_priv,
1576 struct ib_mad_private *recv, *response; 1652 struct ib_mad_private *recv, *response;
1577 struct ib_mad_list_head *mad_list; 1653 struct ib_mad_list_head *mad_list;
1578 struct ib_mad_agent_private *mad_agent; 1654 struct ib_mad_agent_private *mad_agent;
1579 int solicited;
1580 1655
1581 response = kmem_cache_alloc(ib_mad_cache, GFP_KERNEL); 1656 response = kmem_cache_alloc(ib_mad_cache, GFP_KERNEL);
1582 if (!response) 1657 if (!response)
@@ -1662,11 +1737,9 @@ local:
1662 } 1737 }
1663 } 1738 }
1664 1739
1665 /* Determine corresponding MAD agent for incoming receive MAD */ 1740 mad_agent = find_mad_agent(port_priv, &recv->mad.mad);
1666 solicited = solicited_mad(&recv->mad.mad);
1667 mad_agent = find_mad_agent(port_priv, &recv->mad.mad, solicited);
1668 if (mad_agent) { 1741 if (mad_agent) {
1669 ib_mad_complete_recv(mad_agent, recv, solicited); 1742 ib_mad_complete_recv(mad_agent, &recv->header.recv_wc);
1670 /* 1743 /*
1671 * recv is freed up in error cases in ib_mad_complete_recv 1744 * recv is freed up in error cases in ib_mad_complete_recv
1672 * or via recv_handler in ib_mad_complete_recv() 1745 * or via recv_handler in ib_mad_complete_recv()
@@ -1710,26 +1783,31 @@ static void adjust_timeout(struct ib_mad_agent_private *mad_agent_priv)
1710 } 1783 }
1711} 1784}
1712 1785
1713static void wait_for_response(struct ib_mad_agent_private *mad_agent_priv, 1786static void wait_for_response(struct ib_mad_send_wr_private *mad_send_wr)
1714 struct ib_mad_send_wr_private *mad_send_wr )
1715{ 1787{
1788 struct ib_mad_agent_private *mad_agent_priv;
1716 struct ib_mad_send_wr_private *temp_mad_send_wr; 1789 struct ib_mad_send_wr_private *temp_mad_send_wr;
1717 struct list_head *list_item; 1790 struct list_head *list_item;
1718 unsigned long delay; 1791 unsigned long delay;
1719 1792
1793 mad_agent_priv = mad_send_wr->mad_agent_priv;
1720 list_del(&mad_send_wr->agent_list); 1794 list_del(&mad_send_wr->agent_list);
1721 1795
1722 delay = mad_send_wr->timeout; 1796 delay = mad_send_wr->timeout;
1723 mad_send_wr->timeout += jiffies; 1797 mad_send_wr->timeout += jiffies;
1724 1798
1725 list_for_each_prev(list_item, &mad_agent_priv->wait_list) { 1799 if (delay) {
1726 temp_mad_send_wr = list_entry(list_item, 1800 list_for_each_prev(list_item, &mad_agent_priv->wait_list) {
1727 struct ib_mad_send_wr_private, 1801 temp_mad_send_wr = list_entry(list_item,
1728 agent_list); 1802 struct ib_mad_send_wr_private,
1729 if (time_after(mad_send_wr->timeout, 1803 agent_list);
1730 temp_mad_send_wr->timeout)) 1804 if (time_after(mad_send_wr->timeout,
1731 break; 1805 temp_mad_send_wr->timeout))
1806 break;
1807 }
1732 } 1808 }
1809 else
1810 list_item = &mad_agent_priv->wait_list;
1733 list_add(&mad_send_wr->agent_list, list_item); 1811 list_add(&mad_send_wr->agent_list, list_item);
1734 1812
1735 /* Reschedule a work item if we have a shorter timeout */ 1813 /* Reschedule a work item if we have a shorter timeout */
@@ -1740,19 +1818,32 @@ static void wait_for_response(struct ib_mad_agent_private *mad_agent_priv,
1740 } 1818 }
1741} 1819}
1742 1820
1821void ib_reset_mad_timeout(struct ib_mad_send_wr_private *mad_send_wr,
1822 int timeout_ms)
1823{
1824 mad_send_wr->timeout = msecs_to_jiffies(timeout_ms);
1825 wait_for_response(mad_send_wr);
1826}
1827
1743/* 1828/*
1744 * Process a send work completion 1829 * Process a send work completion
1745 */ 1830 */
1746static void ib_mad_complete_send_wr(struct ib_mad_send_wr_private *mad_send_wr, 1831void ib_mad_complete_send_wr(struct ib_mad_send_wr_private *mad_send_wr,
1747 struct ib_mad_send_wc *mad_send_wc) 1832 struct ib_mad_send_wc *mad_send_wc)
1748{ 1833{
1749 struct ib_mad_agent_private *mad_agent_priv; 1834 struct ib_mad_agent_private *mad_agent_priv;
1750 unsigned long flags; 1835 unsigned long flags;
1836 int ret;
1751 1837
1752 mad_agent_priv = container_of(mad_send_wr->agent, 1838 mad_agent_priv = mad_send_wr->mad_agent_priv;
1753 struct ib_mad_agent_private, agent);
1754
1755 spin_lock_irqsave(&mad_agent_priv->lock, flags); 1839 spin_lock_irqsave(&mad_agent_priv->lock, flags);
1840 if (mad_agent_priv->agent.rmpp_version) {
1841 ret = ib_process_rmpp_send_wc(mad_send_wr, mad_send_wc);
1842 if (ret == IB_RMPP_RESULT_CONSUMED)
1843 goto done;
1844 } else
1845 ret = IB_RMPP_RESULT_UNHANDLED;
1846
1756 if (mad_send_wc->status != IB_WC_SUCCESS && 1847 if (mad_send_wc->status != IB_WC_SUCCESS &&
1757 mad_send_wr->status == IB_WC_SUCCESS) { 1848 mad_send_wr->status == IB_WC_SUCCESS) {
1758 mad_send_wr->status = mad_send_wc->status; 1849 mad_send_wr->status = mad_send_wc->status;
@@ -1762,10 +1853,9 @@ static void ib_mad_complete_send_wr(struct ib_mad_send_wr_private *mad_send_wr,
1762 if (--mad_send_wr->refcount > 0) { 1853 if (--mad_send_wr->refcount > 0) {
1763 if (mad_send_wr->refcount == 1 && mad_send_wr->timeout && 1854 if (mad_send_wr->refcount == 1 && mad_send_wr->timeout &&
1764 mad_send_wr->status == IB_WC_SUCCESS) { 1855 mad_send_wr->status == IB_WC_SUCCESS) {
1765 wait_for_response(mad_agent_priv, mad_send_wr); 1856 wait_for_response(mad_send_wr);
1766 } 1857 }
1767 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); 1858 goto done;
1768 return;
1769 } 1859 }
1770 1860
1771 /* Remove send from MAD agent and notify client of completion */ 1861 /* Remove send from MAD agent and notify client of completion */
@@ -1775,14 +1865,18 @@ static void ib_mad_complete_send_wr(struct ib_mad_send_wr_private *mad_send_wr,
1775 1865
1776 if (mad_send_wr->status != IB_WC_SUCCESS ) 1866 if (mad_send_wr->status != IB_WC_SUCCESS )
1777 mad_send_wc->status = mad_send_wr->status; 1867 mad_send_wc->status = mad_send_wr->status;
1778 mad_agent_priv->agent.send_handler(&mad_agent_priv->agent, 1868 if (ret != IB_RMPP_RESULT_INTERNAL)
1779 mad_send_wc); 1869 mad_agent_priv->agent.send_handler(&mad_agent_priv->agent,
1870 mad_send_wc);
1780 1871
1781 /* Release reference on agent taken when sending */ 1872 /* Release reference on agent taken when sending */
1782 if (atomic_dec_and_test(&mad_agent_priv->refcount)) 1873 if (atomic_dec_and_test(&mad_agent_priv->refcount))
1783 wake_up(&mad_agent_priv->wait); 1874 wake_up(&mad_agent_priv->wait);
1784 1875
1785 kfree(mad_send_wr); 1876 kfree(mad_send_wr);
1877 return;
1878done:
1879 spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
1786} 1880}
1787 1881
1788static void ib_mad_send_done_handler(struct ib_mad_port_private *port_priv, 1882static void ib_mad_send_done_handler(struct ib_mad_port_private *port_priv,
@@ -1961,6 +2055,8 @@ static void cancel_mads(struct ib_mad_agent_private *mad_agent_priv)
1961 2055
1962 /* Empty wait list to prevent receives from finding a request */ 2056 /* Empty wait list to prevent receives from finding a request */
1963 list_splice_init(&mad_agent_priv->wait_list, &cancel_list); 2057 list_splice_init(&mad_agent_priv->wait_list, &cancel_list);
2058 /* Empty local completion list as well */
2059 list_splice_init(&mad_agent_priv->local_list, &cancel_list);
1964 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); 2060 spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
1965 2061
1966 /* Report all cancelled requests */ 2062 /* Report all cancelled requests */
@@ -1980,8 +2076,7 @@ static void cancel_mads(struct ib_mad_agent_private *mad_agent_priv)
1980} 2076}
1981 2077
1982static struct ib_mad_send_wr_private* 2078static struct ib_mad_send_wr_private*
1983find_send_by_wr_id(struct ib_mad_agent_private *mad_agent_priv, 2079find_send_by_wr_id(struct ib_mad_agent_private *mad_agent_priv, u64 wr_id)
1984 u64 wr_id)
1985{ 2080{
1986 struct ib_mad_send_wr_private *mad_send_wr; 2081 struct ib_mad_send_wr_private *mad_send_wr;
1987 2082
@@ -1993,79 +2088,50 @@ find_send_by_wr_id(struct ib_mad_agent_private *mad_agent_priv,
1993 2088
1994 list_for_each_entry(mad_send_wr, &mad_agent_priv->send_list, 2089 list_for_each_entry(mad_send_wr, &mad_agent_priv->send_list,
1995 agent_list) { 2090 agent_list) {
1996 if (mad_send_wr->wr_id == wr_id) 2091 if (is_data_mad(mad_agent_priv,
2092 mad_send_wr->send_wr.wr.ud.mad_hdr) &&
2093 mad_send_wr->wr_id == wr_id)
1997 return mad_send_wr; 2094 return mad_send_wr;
1998 } 2095 }
1999 return NULL; 2096 return NULL;
2000} 2097}
2001 2098
2002void cancel_sends(void *data) 2099int ib_modify_mad(struct ib_mad_agent *mad_agent, u64 wr_id, u32 timeout_ms)
2003{
2004 struct ib_mad_agent_private *mad_agent_priv;
2005 struct ib_mad_send_wr_private *mad_send_wr;
2006 struct ib_mad_send_wc mad_send_wc;
2007 unsigned long flags;
2008
2009 mad_agent_priv = data;
2010
2011 mad_send_wc.status = IB_WC_WR_FLUSH_ERR;
2012 mad_send_wc.vendor_err = 0;
2013
2014 spin_lock_irqsave(&mad_agent_priv->lock, flags);
2015 while (!list_empty(&mad_agent_priv->canceled_list)) {
2016 mad_send_wr = list_entry(mad_agent_priv->canceled_list.next,
2017 struct ib_mad_send_wr_private,
2018 agent_list);
2019
2020 list_del(&mad_send_wr->agent_list);
2021 spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
2022
2023 mad_send_wc.wr_id = mad_send_wr->wr_id;
2024 mad_agent_priv->agent.send_handler(&mad_agent_priv->agent,
2025 &mad_send_wc);
2026
2027 kfree(mad_send_wr);
2028 if (atomic_dec_and_test(&mad_agent_priv->refcount))
2029 wake_up(&mad_agent_priv->wait);
2030 spin_lock_irqsave(&mad_agent_priv->lock, flags);
2031 }
2032 spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
2033}
2034
2035void ib_cancel_mad(struct ib_mad_agent *mad_agent,
2036 u64 wr_id)
2037{ 2100{
2038 struct ib_mad_agent_private *mad_agent_priv; 2101 struct ib_mad_agent_private *mad_agent_priv;
2039 struct ib_mad_send_wr_private *mad_send_wr; 2102 struct ib_mad_send_wr_private *mad_send_wr;
2040 unsigned long flags; 2103 unsigned long flags;
2104 int active;
2041 2105
2042 mad_agent_priv = container_of(mad_agent, struct ib_mad_agent_private, 2106 mad_agent_priv = container_of(mad_agent, struct ib_mad_agent_private,
2043 agent); 2107 agent);
2044 spin_lock_irqsave(&mad_agent_priv->lock, flags); 2108 spin_lock_irqsave(&mad_agent_priv->lock, flags);
2045 mad_send_wr = find_send_by_wr_id(mad_agent_priv, wr_id); 2109 mad_send_wr = find_send_by_wr_id(mad_agent_priv, wr_id);
2046 if (!mad_send_wr) { 2110 if (!mad_send_wr || mad_send_wr->status != IB_WC_SUCCESS) {
2047 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); 2111 spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
2048 goto out; 2112 return -EINVAL;
2049 } 2113 }
2050 2114
2051 if (mad_send_wr->status == IB_WC_SUCCESS) 2115 active = (!mad_send_wr->timeout || mad_send_wr->refcount > 1);
2052 mad_send_wr->refcount -= (mad_send_wr->timeout > 0); 2116 if (!timeout_ms) {
2053
2054 if (mad_send_wr->refcount != 0) {
2055 mad_send_wr->status = IB_WC_WR_FLUSH_ERR; 2117 mad_send_wr->status = IB_WC_WR_FLUSH_ERR;
2056 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); 2118 mad_send_wr->refcount -= (mad_send_wr->timeout > 0);
2057 goto out;
2058 } 2119 }
2059 2120
2060 list_del(&mad_send_wr->agent_list); 2121 mad_send_wr->send_wr.wr.ud.timeout_ms = timeout_ms;
2061 list_add_tail(&mad_send_wr->agent_list, &mad_agent_priv->canceled_list); 2122 if (active)
2062 adjust_timeout(mad_agent_priv); 2123 mad_send_wr->timeout = msecs_to_jiffies(timeout_ms);
2124 else
2125 ib_reset_mad_timeout(mad_send_wr, timeout_ms);
2126
2063 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); 2127 spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
2128 return 0;
2129}
2130EXPORT_SYMBOL(ib_modify_mad);
2064 2131
2065 queue_work(mad_agent_priv->qp_info->port_priv->wq, 2132void ib_cancel_mad(struct ib_mad_agent *mad_agent, u64 wr_id)
2066 &mad_agent_priv->canceled_work); 2133{
2067out: 2134 ib_modify_mad(mad_agent, wr_id, 0);
2068 return;
2069} 2135}
2070EXPORT_SYMBOL(ib_cancel_mad); 2136EXPORT_SYMBOL(ib_cancel_mad);
2071 2137
@@ -2075,6 +2141,7 @@ static void local_completions(void *data)
2075 struct ib_mad_local_private *local; 2141 struct ib_mad_local_private *local;
2076 struct ib_mad_agent_private *recv_mad_agent; 2142 struct ib_mad_agent_private *recv_mad_agent;
2077 unsigned long flags; 2143 unsigned long flags;
2144 int recv = 0;
2078 struct ib_wc wc; 2145 struct ib_wc wc;
2079 struct ib_mad_send_wc mad_send_wc; 2146 struct ib_mad_send_wc mad_send_wc;
2080 2147
@@ -2090,10 +2157,10 @@ static void local_completions(void *data)
2090 recv_mad_agent = local->recv_mad_agent; 2157 recv_mad_agent = local->recv_mad_agent;
2091 if (!recv_mad_agent) { 2158 if (!recv_mad_agent) {
2092 printk(KERN_ERR PFX "No receive MAD agent for local completion\n"); 2159 printk(KERN_ERR PFX "No receive MAD agent for local completion\n");
2093 kmem_cache_free(ib_mad_cache, local->mad_priv);
2094 goto local_send_completion; 2160 goto local_send_completion;
2095 } 2161 }
2096 2162
2163 recv = 1;
2097 /* 2164 /*
2098 * Defined behavior is to complete response 2165 * Defined behavior is to complete response
2099 * before request 2166 * before request
@@ -2105,7 +2172,9 @@ static void local_completions(void *data)
2105 local->mad_priv->header.recv_wc.wc = &wc; 2172 local->mad_priv->header.recv_wc.wc = &wc;
2106 local->mad_priv->header.recv_wc.mad_len = 2173 local->mad_priv->header.recv_wc.mad_len =
2107 sizeof(struct ib_mad); 2174 sizeof(struct ib_mad);
2108 INIT_LIST_HEAD(&local->mad_priv->header.recv_wc.recv_buf.list); 2175 INIT_LIST_HEAD(&local->mad_priv->header.recv_wc.rmpp_list);
2176 list_add(&local->mad_priv->header.recv_wc.recv_buf.list,
2177 &local->mad_priv->header.recv_wc.rmpp_list);
2109 local->mad_priv->header.recv_wc.recv_buf.grh = NULL; 2178 local->mad_priv->header.recv_wc.recv_buf.grh = NULL;
2110 local->mad_priv->header.recv_wc.recv_buf.mad = 2179 local->mad_priv->header.recv_wc.recv_buf.mad =
2111 &local->mad_priv->mad.mad; 2180 &local->mad_priv->mad.mad;
@@ -2136,11 +2205,47 @@ local_send_completion:
2136 spin_lock_irqsave(&mad_agent_priv->lock, flags); 2205 spin_lock_irqsave(&mad_agent_priv->lock, flags);
2137 list_del(&local->completion_list); 2206 list_del(&local->completion_list);
2138 atomic_dec(&mad_agent_priv->refcount); 2207 atomic_dec(&mad_agent_priv->refcount);
2208 if (!recv)
2209 kmem_cache_free(ib_mad_cache, local->mad_priv);
2139 kfree(local); 2210 kfree(local);
2140 } 2211 }
2141 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); 2212 spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
2142} 2213}
2143 2214
2215static int retry_send(struct ib_mad_send_wr_private *mad_send_wr)
2216{
2217 int ret;
2218
2219 if (!mad_send_wr->retries--)
2220 return -ETIMEDOUT;
2221
2222 mad_send_wr->timeout = msecs_to_jiffies(mad_send_wr->send_wr.
2223 wr.ud.timeout_ms);
2224
2225 if (mad_send_wr->mad_agent_priv->agent.rmpp_version) {
2226 ret = ib_retry_rmpp(mad_send_wr);
2227 switch (ret) {
2228 case IB_RMPP_RESULT_UNHANDLED:
2229 ret = ib_send_mad(mad_send_wr);
2230 break;
2231 case IB_RMPP_RESULT_CONSUMED:
2232 ret = 0;
2233 break;
2234 default:
2235 ret = -ECOMM;
2236 break;
2237 }
2238 } else
2239 ret = ib_send_mad(mad_send_wr);
2240
2241 if (!ret) {
2242 mad_send_wr->refcount++;
2243 list_add_tail(&mad_send_wr->agent_list,
2244 &mad_send_wr->mad_agent_priv->send_list);
2245 }
2246 return ret;
2247}
2248
2144static void timeout_sends(void *data) 2249static void timeout_sends(void *data)
2145{ 2250{
2146 struct ib_mad_agent_private *mad_agent_priv; 2251 struct ib_mad_agent_private *mad_agent_priv;
@@ -2149,8 +2254,6 @@ static void timeout_sends(void *data)
2149 unsigned long flags, delay; 2254 unsigned long flags, delay;
2150 2255
2151 mad_agent_priv = (struct ib_mad_agent_private *)data; 2256 mad_agent_priv = (struct ib_mad_agent_private *)data;
2152
2153 mad_send_wc.status = IB_WC_RESP_TIMEOUT_ERR;
2154 mad_send_wc.vendor_err = 0; 2257 mad_send_wc.vendor_err = 0;
2155 2258
2156 spin_lock_irqsave(&mad_agent_priv->lock, flags); 2259 spin_lock_irqsave(&mad_agent_priv->lock, flags);
@@ -2170,8 +2273,16 @@ static void timeout_sends(void *data)
2170 } 2273 }
2171 2274
2172 list_del(&mad_send_wr->agent_list); 2275 list_del(&mad_send_wr->agent_list);
2276 if (mad_send_wr->status == IB_WC_SUCCESS &&
2277 !retry_send(mad_send_wr))
2278 continue;
2279
2173 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); 2280 spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
2174 2281
2282 if (mad_send_wr->status == IB_WC_SUCCESS)
2283 mad_send_wc.status = IB_WC_RESP_TIMEOUT_ERR;
2284 else
2285 mad_send_wc.status = mad_send_wr->status;
2175 mad_send_wc.wr_id = mad_send_wr->wr_id; 2286 mad_send_wc.wr_id = mad_send_wr->wr_id;
2176 mad_agent_priv->agent.send_handler(&mad_agent_priv->agent, 2287 mad_agent_priv->agent.send_handler(&mad_agent_priv->agent,
2177 &mad_send_wc); 2288 &mad_send_wc);
@@ -2447,14 +2558,6 @@ static int ib_mad_port_open(struct ib_device *device,
2447 unsigned long flags; 2558 unsigned long flags;
2448 char name[sizeof "ib_mad123"]; 2559 char name[sizeof "ib_mad123"];
2449 2560
2450 /* First, check if port already open at MAD layer */
2451 port_priv = ib_get_mad_port(device, port_num);
2452 if (port_priv) {
2453 printk(KERN_DEBUG PFX "%s port %d already open\n",
2454 device->name, port_num);
2455 return 0;
2456 }
2457
2458 /* Create new device info */ 2561 /* Create new device info */
2459 port_priv = kmalloc(sizeof *port_priv, GFP_KERNEL); 2562 port_priv = kmalloc(sizeof *port_priv, GFP_KERNEL);
2460 if (!port_priv) { 2563 if (!port_priv) {
@@ -2579,7 +2682,7 @@ static int ib_mad_port_close(struct ib_device *device, int port_num)
2579 2682
2580static void ib_mad_init_device(struct ib_device *device) 2683static void ib_mad_init_device(struct ib_device *device)
2581{ 2684{
2582 int ret, num_ports, cur_port, i, ret2; 2685 int num_ports, cur_port, i;
2583 2686
2584 if (device->node_type == IB_NODE_SWITCH) { 2687 if (device->node_type == IB_NODE_SWITCH) {
2585 num_ports = 1; 2688 num_ports = 1;
@@ -2589,47 +2692,37 @@ static void ib_mad_init_device(struct ib_device *device)
2589 cur_port = 1; 2692 cur_port = 1;
2590 } 2693 }
2591 for (i = 0; i < num_ports; i++, cur_port++) { 2694 for (i = 0; i < num_ports; i++, cur_port++) {
2592 ret = ib_mad_port_open(device, cur_port); 2695 if (ib_mad_port_open(device, cur_port)) {
2593 if (ret) {
2594 printk(KERN_ERR PFX "Couldn't open %s port %d\n", 2696 printk(KERN_ERR PFX "Couldn't open %s port %d\n",
2595 device->name, cur_port); 2697 device->name, cur_port);
2596 goto error_device_open; 2698 goto error_device_open;
2597 } 2699 }
2598 ret = ib_agent_port_open(device, cur_port); 2700 if (ib_agent_port_open(device, cur_port)) {
2599 if (ret) {
2600 printk(KERN_ERR PFX "Couldn't open %s port %d " 2701 printk(KERN_ERR PFX "Couldn't open %s port %d "
2601 "for agents\n", 2702 "for agents\n",
2602 device->name, cur_port); 2703 device->name, cur_port);
2603 goto error_device_open; 2704 goto error_device_open;
2604 } 2705 }
2605 } 2706 }
2606 2707 return;
2607 goto error_device_query;
2608 2708
2609error_device_open: 2709error_device_open:
2610 while (i > 0) { 2710 while (i > 0) {
2611 cur_port--; 2711 cur_port--;
2612 ret2 = ib_agent_port_close(device, cur_port); 2712 if (ib_agent_port_close(device, cur_port))
2613 if (ret2) {
2614 printk(KERN_ERR PFX "Couldn't close %s port %d " 2713 printk(KERN_ERR PFX "Couldn't close %s port %d "
2615 "for agents\n", 2714 "for agents\n",
2616 device->name, cur_port); 2715 device->name, cur_port);
2617 } 2716 if (ib_mad_port_close(device, cur_port))
2618 ret2 = ib_mad_port_close(device, cur_port);
2619 if (ret2) {
2620 printk(KERN_ERR PFX "Couldn't close %s port %d\n", 2717 printk(KERN_ERR PFX "Couldn't close %s port %d\n",
2621 device->name, cur_port); 2718 device->name, cur_port);
2622 }
2623 i--; 2719 i--;
2624 } 2720 }
2625
2626error_device_query:
2627 return;
2628} 2721}
2629 2722
2630static void ib_mad_remove_device(struct ib_device *device) 2723static void ib_mad_remove_device(struct ib_device *device)
2631{ 2724{
2632 int ret = 0, i, num_ports, cur_port, ret2; 2725 int i, num_ports, cur_port;
2633 2726
2634 if (device->node_type == IB_NODE_SWITCH) { 2727 if (device->node_type == IB_NODE_SWITCH) {
2635 num_ports = 1; 2728 num_ports = 1;
@@ -2639,21 +2732,13 @@ static void ib_mad_remove_device(struct ib_device *device)
2639 cur_port = 1; 2732 cur_port = 1;
2640 } 2733 }
2641 for (i = 0; i < num_ports; i++, cur_port++) { 2734 for (i = 0; i < num_ports; i++, cur_port++) {
2642 ret2 = ib_agent_port_close(device, cur_port); 2735 if (ib_agent_port_close(device, cur_port))
2643 if (ret2) {
2644 printk(KERN_ERR PFX "Couldn't close %s port %d " 2736 printk(KERN_ERR PFX "Couldn't close %s port %d "
2645 "for agents\n", 2737 "for agents\n",
2646 device->name, cur_port); 2738 device->name, cur_port);
2647 if (!ret) 2739 if (ib_mad_port_close(device, cur_port))
2648 ret = ret2;
2649 }
2650 ret2 = ib_mad_port_close(device, cur_port);
2651 if (ret2) {
2652 printk(KERN_ERR PFX "Couldn't close %s port %d\n", 2740 printk(KERN_ERR PFX "Couldn't close %s port %d\n",
2653 device->name, cur_port); 2741 device->name, cur_port);
2654 if (!ret)
2655 ret = ret2;
2656 }
2657 } 2742 }
2658} 2743}
2659 2744
@@ -2709,3 +2794,4 @@ static void __exit ib_mad_cleanup_module(void)
2709 2794
2710module_init(ib_mad_init_module); 2795module_init(ib_mad_init_module);
2711module_exit(ib_mad_cleanup_module); 2796module_exit(ib_mad_cleanup_module);
2797
diff --git a/drivers/infiniband/core/mad_priv.h b/drivers/infiniband/core/mad_priv.h
index 008cbcb94b15..568da10b05ab 100644
--- a/drivers/infiniband/core/mad_priv.h
+++ b/drivers/infiniband/core/mad_priv.h
@@ -1,5 +1,7 @@
1/* 1/*
2 * Copyright (c) 2004, 2005, Voltaire, Inc. All rights reserved. 2 * Copyright (c) 2004, 2005, Voltaire, Inc. All rights reserved.
3 * Copyright (c) 2005 Intel Corporation. All rights reserved.
4 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
3 * 5 *
4 * 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
5 * 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
@@ -29,7 +31,7 @@
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE. 32 * SOFTWARE.
31 * 33 *
32 * $Id: mad_priv.h 1389 2004-12-27 22:56:47Z roland $ 34 * $Id: mad_priv.h 2730 2005-06-28 16:43:03Z sean.hefty $
33 */ 35 */
34 36
35#ifndef __IB_MAD_PRIV_H__ 37#ifndef __IB_MAD_PRIV_H__
@@ -92,16 +94,15 @@ struct ib_mad_agent_private {
92 spinlock_t lock; 94 spinlock_t lock;
93 struct list_head send_list; 95 struct list_head send_list;
94 struct list_head wait_list; 96 struct list_head wait_list;
97 struct list_head done_list;
95 struct work_struct timed_work; 98 struct work_struct timed_work;
96 unsigned long timeout; 99 unsigned long timeout;
97 struct list_head local_list; 100 struct list_head local_list;
98 struct work_struct local_work; 101 struct work_struct local_work;
99 struct list_head canceled_list; 102 struct list_head rmpp_list;
100 struct work_struct canceled_work;
101 103
102 atomic_t refcount; 104 atomic_t refcount;
103 wait_queue_head_t wait; 105 wait_queue_head_t wait;
104 u8 rmpp_version;
105}; 106};
106 107
107struct ib_mad_snoop_private { 108struct ib_mad_snoop_private {
@@ -116,15 +117,24 @@ struct ib_mad_snoop_private {
116struct ib_mad_send_wr_private { 117struct ib_mad_send_wr_private {
117 struct ib_mad_list_head mad_list; 118 struct ib_mad_list_head mad_list;
118 struct list_head agent_list; 119 struct list_head agent_list;
119 struct ib_mad_agent *agent; 120 struct ib_mad_agent_private *mad_agent_priv;
120 struct ib_send_wr send_wr; 121 struct ib_send_wr send_wr;
121 struct ib_sge sg_list[IB_MAD_SEND_REQ_MAX_SG]; 122 struct ib_sge sg_list[IB_MAD_SEND_REQ_MAX_SG];
122 u64 wr_id; /* client WR ID */ 123 u64 wr_id; /* client WR ID */
123 u64 tid; 124 u64 tid;
124 unsigned long timeout; 125 unsigned long timeout;
126 int retries;
125 int retry; 127 int retry;
126 int refcount; 128 int refcount;
127 enum ib_wc_status status; 129 enum ib_wc_status status;
130
131 /* RMPP control */
132 int last_ack;
133 int seg_num;
134 int newwin;
135 int total_seg;
136 int data_offset;
137 int pad;
128}; 138};
129 139
130struct ib_mad_local_private { 140struct ib_mad_local_private {
@@ -197,4 +207,17 @@ struct ib_mad_port_private {
197 207
198extern kmem_cache_t *ib_mad_cache; 208extern kmem_cache_t *ib_mad_cache;
199 209
210int ib_send_mad(struct ib_mad_send_wr_private *mad_send_wr);
211
212struct ib_mad_send_wr_private *
213ib_find_send_mad(struct ib_mad_agent_private *mad_agent_priv, u64 tid);
214
215void ib_mad_complete_send_wr(struct ib_mad_send_wr_private *mad_send_wr,
216 struct ib_mad_send_wc *mad_send_wc);
217
218void ib_mark_mad_done(struct ib_mad_send_wr_private *mad_send_wr);
219
220void ib_reset_mad_timeout(struct ib_mad_send_wr_private *mad_send_wr,
221 int timeout_ms);
222
200#endif /* __IB_MAD_PRIV_H__ */ 223#endif /* __IB_MAD_PRIV_H__ */
diff --git a/drivers/infiniband/core/mad_rmpp.c b/drivers/infiniband/core/mad_rmpp.c
new file mode 100644
index 000000000000..8f1eb80e421f
--- /dev/null
+++ b/drivers/infiniband/core/mad_rmpp.c
@@ -0,0 +1,765 @@
1/*
2 * Copyright (c) 2005 Intel Inc. All rights reserved.
3 * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 *
33 * $Id: mad_rmpp.c 1921 2005-03-02 22:58:44Z sean.hefty $
34 */
35
36#include <linux/dma-mapping.h>
37
38#include "mad_priv.h"
39#include "mad_rmpp.h"
40
41enum rmpp_state {
42 RMPP_STATE_ACTIVE,
43 RMPP_STATE_TIMEOUT,
44 RMPP_STATE_COMPLETE
45};
46
47struct mad_rmpp_recv {
48 struct ib_mad_agent_private *agent;
49 struct list_head list;
50 struct work_struct timeout_work;
51 struct work_struct cleanup_work;
52 wait_queue_head_t wait;
53 enum rmpp_state state;
54 spinlock_t lock;
55 atomic_t refcount;
56
57 struct ib_ah *ah;
58 struct ib_mad_recv_wc *rmpp_wc;
59 struct ib_mad_recv_buf *cur_seg_buf;
60 int last_ack;
61 int seg_num;
62 int newwin;
63
64 u64 tid;
65 u32 src_qp;
66 u16 slid;
67 u8 mgmt_class;
68 u8 class_version;
69 u8 method;
70};
71
72static void destroy_rmpp_recv(struct mad_rmpp_recv *rmpp_recv)
73{
74 atomic_dec(&rmpp_recv->refcount);
75 wait_event(rmpp_recv->wait, !atomic_read(&rmpp_recv->refcount));
76 ib_destroy_ah(rmpp_recv->ah);
77 kfree(rmpp_recv);
78}
79
80void ib_cancel_rmpp_recvs(struct ib_mad_agent_private *agent)
81{
82 struct mad_rmpp_recv *rmpp_recv, *temp_rmpp_recv;
83 unsigned long flags;
84
85 spin_lock_irqsave(&agent->lock, flags);
86 list_for_each_entry(rmpp_recv, &agent->rmpp_list, list) {
87 cancel_delayed_work(&rmpp_recv->timeout_work);
88 cancel_delayed_work(&rmpp_recv->cleanup_work);
89 }
90 spin_unlock_irqrestore(&agent->lock, flags);
91
92 flush_workqueue(agent->qp_info->port_priv->wq);
93
94 list_for_each_entry_safe(rmpp_recv, temp_rmpp_recv,
95 &agent->rmpp_list, list) {
96 list_del(&rmpp_recv->list);
97 if (rmpp_recv->state != RMPP_STATE_COMPLETE)
98 ib_free_recv_mad(rmpp_recv->rmpp_wc);
99 destroy_rmpp_recv(rmpp_recv);
100 }
101}
102
103static void recv_timeout_handler(void *data)
104{
105 struct mad_rmpp_recv *rmpp_recv = data;
106 struct ib_mad_recv_wc *rmpp_wc;
107 unsigned long flags;
108
109 spin_lock_irqsave(&rmpp_recv->agent->lock, flags);
110 if (rmpp_recv->state != RMPP_STATE_ACTIVE) {
111 spin_unlock_irqrestore(&rmpp_recv->agent->lock, flags);
112 return;
113 }
114 rmpp_recv->state = RMPP_STATE_TIMEOUT;
115 list_del(&rmpp_recv->list);
116 spin_unlock_irqrestore(&rmpp_recv->agent->lock, flags);
117
118 /* TODO: send abort. */
119 rmpp_wc = rmpp_recv->rmpp_wc;
120 destroy_rmpp_recv(rmpp_recv);
121 ib_free_recv_mad(rmpp_wc);
122}
123
124static void recv_cleanup_handler(void *data)
125{
126 struct mad_rmpp_recv *rmpp_recv = data;
127 unsigned long flags;
128
129 spin_lock_irqsave(&rmpp_recv->agent->lock, flags);
130 list_del(&rmpp_recv->list);
131 spin_unlock_irqrestore(&rmpp_recv->agent->lock, flags);
132 destroy_rmpp_recv(rmpp_recv);
133}
134
135static struct mad_rmpp_recv *
136create_rmpp_recv(struct ib_mad_agent_private *agent,
137 struct ib_mad_recv_wc *mad_recv_wc)
138{
139 struct mad_rmpp_recv *rmpp_recv;
140 struct ib_mad_hdr *mad_hdr;
141
142 rmpp_recv = kmalloc(sizeof *rmpp_recv, GFP_KERNEL);
143 if (!rmpp_recv)
144 return NULL;
145
146 rmpp_recv->ah = ib_create_ah_from_wc(agent->agent.qp->pd,
147 mad_recv_wc->wc,
148 mad_recv_wc->recv_buf.grh,
149 agent->agent.port_num);
150 if (IS_ERR(rmpp_recv->ah))
151 goto error;
152
153 rmpp_recv->agent = agent;
154 init_waitqueue_head(&rmpp_recv->wait);
155 INIT_WORK(&rmpp_recv->timeout_work, recv_timeout_handler, rmpp_recv);
156 INIT_WORK(&rmpp_recv->cleanup_work, recv_cleanup_handler, rmpp_recv);
157 spin_lock_init(&rmpp_recv->lock);
158 rmpp_recv->state = RMPP_STATE_ACTIVE;
159 atomic_set(&rmpp_recv->refcount, 1);
160
161 rmpp_recv->rmpp_wc = mad_recv_wc;
162 rmpp_recv->cur_seg_buf = &mad_recv_wc->recv_buf;
163 rmpp_recv->newwin = 1;
164 rmpp_recv->seg_num = 1;
165 rmpp_recv->last_ack = 0;
166
167 mad_hdr = &mad_recv_wc->recv_buf.mad->mad_hdr;
168 rmpp_recv->tid = mad_hdr->tid;
169 rmpp_recv->src_qp = mad_recv_wc->wc->src_qp;
170 rmpp_recv->slid = mad_recv_wc->wc->slid;
171 rmpp_recv->mgmt_class = mad_hdr->mgmt_class;
172 rmpp_recv->class_version = mad_hdr->class_version;
173 rmpp_recv->method = mad_hdr->method;
174 return rmpp_recv;
175
176error: kfree(rmpp_recv);
177 return NULL;
178}
179
180static inline void deref_rmpp_recv(struct mad_rmpp_recv *rmpp_recv)
181{
182 if (atomic_dec_and_test(&rmpp_recv->refcount))
183 wake_up(&rmpp_recv->wait);
184}
185
186static struct mad_rmpp_recv *
187find_rmpp_recv(struct ib_mad_agent_private *agent,
188 struct ib_mad_recv_wc *mad_recv_wc)
189{
190 struct mad_rmpp_recv *rmpp_recv;
191 struct ib_mad_hdr *mad_hdr = &mad_recv_wc->recv_buf.mad->mad_hdr;
192
193 list_for_each_entry(rmpp_recv, &agent->rmpp_list, list) {
194 if (rmpp_recv->tid == mad_hdr->tid &&
195 rmpp_recv->src_qp == mad_recv_wc->wc->src_qp &&
196 rmpp_recv->slid == mad_recv_wc->wc->slid &&
197 rmpp_recv->mgmt_class == mad_hdr->mgmt_class &&
198 rmpp_recv->class_version == mad_hdr->class_version &&
199 rmpp_recv->method == mad_hdr->method)
200 return rmpp_recv;
201 }
202 return NULL;
203}
204
205static struct mad_rmpp_recv *
206acquire_rmpp_recv(struct ib_mad_agent_private *agent,
207 struct ib_mad_recv_wc *mad_recv_wc)
208{
209 struct mad_rmpp_recv *rmpp_recv;
210 unsigned long flags;
211
212 spin_lock_irqsave(&agent->lock, flags);
213 rmpp_recv = find_rmpp_recv(agent, mad_recv_wc);
214 if (rmpp_recv)
215 atomic_inc(&rmpp_recv->refcount);
216 spin_unlock_irqrestore(&agent->lock, flags);
217 return rmpp_recv;
218}
219
220static struct mad_rmpp_recv *
221insert_rmpp_recv(struct ib_mad_agent_private *agent,
222 struct mad_rmpp_recv *rmpp_recv)
223{
224 struct mad_rmpp_recv *cur_rmpp_recv;
225
226 cur_rmpp_recv = find_rmpp_recv(agent, rmpp_recv->rmpp_wc);
227 if (!cur_rmpp_recv)
228 list_add_tail(&rmpp_recv->list, &agent->rmpp_list);
229
230 return cur_rmpp_recv;
231}
232
233static int data_offset(u8 mgmt_class)
234{
235 if (mgmt_class == IB_MGMT_CLASS_SUBN_ADM)
236 return offsetof(struct ib_sa_mad, data);
237 else if ((mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START) &&
238 (mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END))
239 return offsetof(struct ib_vendor_mad, data);
240 else
241 return offsetof(struct ib_rmpp_mad, data);
242}
243
244static void format_ack(struct ib_rmpp_mad *ack,
245 struct ib_rmpp_mad *data,
246 struct mad_rmpp_recv *rmpp_recv)
247{
248 unsigned long flags;
249
250 memcpy(&ack->mad_hdr, &data->mad_hdr,
251 data_offset(data->mad_hdr.mgmt_class));
252
253 ack->mad_hdr.method ^= IB_MGMT_METHOD_RESP;
254 ack->rmpp_hdr.rmpp_type = IB_MGMT_RMPP_TYPE_ACK;
255 ib_set_rmpp_flags(&ack->rmpp_hdr, IB_MGMT_RMPP_FLAG_ACTIVE);
256
257 spin_lock_irqsave(&rmpp_recv->lock, flags);
258 rmpp_recv->last_ack = rmpp_recv->seg_num;
259 ack->rmpp_hdr.seg_num = cpu_to_be32(rmpp_recv->seg_num);
260 ack->rmpp_hdr.paylen_newwin = cpu_to_be32(rmpp_recv->newwin);
261 spin_unlock_irqrestore(&rmpp_recv->lock, flags);
262}
263
264static void ack_recv(struct mad_rmpp_recv *rmpp_recv,
265 struct ib_mad_recv_wc *recv_wc)
266{
267 struct ib_mad_send_buf *msg;
268 struct ib_send_wr *bad_send_wr;
269 int hdr_len, ret;
270
271 hdr_len = sizeof(struct ib_mad_hdr) + sizeof(struct ib_rmpp_hdr);
272 msg = ib_create_send_mad(&rmpp_recv->agent->agent, recv_wc->wc->src_qp,
273 recv_wc->wc->pkey_index, rmpp_recv->ah, 1,
274 hdr_len, sizeof(struct ib_rmpp_mad) - hdr_len,
275 GFP_KERNEL);
276 if (!msg)
277 return;
278
279 format_ack((struct ib_rmpp_mad *) msg->mad,
280 (struct ib_rmpp_mad *) recv_wc->recv_buf.mad, rmpp_recv);
281 ret = ib_post_send_mad(&rmpp_recv->agent->agent, &msg->send_wr,
282 &bad_send_wr);
283 if (ret)
284 ib_free_send_mad(msg);
285}
286
287static inline int get_last_flag(struct ib_mad_recv_buf *seg)
288{
289 struct ib_rmpp_mad *rmpp_mad;
290
291 rmpp_mad = (struct ib_rmpp_mad *) seg->mad;
292 return ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) & IB_MGMT_RMPP_FLAG_LAST;
293}
294
295static inline int get_seg_num(struct ib_mad_recv_buf *seg)
296{
297 struct ib_rmpp_mad *rmpp_mad;
298
299 rmpp_mad = (struct ib_rmpp_mad *) seg->mad;
300 return be32_to_cpu(rmpp_mad->rmpp_hdr.seg_num);
301}
302
303static inline struct ib_mad_recv_buf * get_next_seg(struct list_head *rmpp_list,
304 struct ib_mad_recv_buf *seg)
305{
306 if (seg->list.next == rmpp_list)
307 return NULL;
308
309 return container_of(seg->list.next, struct ib_mad_recv_buf, list);
310}
311
312static inline int window_size(struct ib_mad_agent_private *agent)
313{
314 return max(agent->qp_info->recv_queue.max_active >> 3, 1);
315}
316
317static struct ib_mad_recv_buf * find_seg_location(struct list_head *rmpp_list,
318 int seg_num)
319{
320 struct ib_mad_recv_buf *seg_buf;
321 int cur_seg_num;
322
323 list_for_each_entry_reverse(seg_buf, rmpp_list, list) {
324 cur_seg_num = get_seg_num(seg_buf);
325 if (seg_num > cur_seg_num)
326 return seg_buf;
327 if (seg_num == cur_seg_num)
328 break;
329 }
330 return NULL;
331}
332
333static void update_seg_num(struct mad_rmpp_recv *rmpp_recv,
334 struct ib_mad_recv_buf *new_buf)
335{
336 struct list_head *rmpp_list = &rmpp_recv->rmpp_wc->rmpp_list;
337
338 while (new_buf && (get_seg_num(new_buf) == rmpp_recv->seg_num + 1)) {
339 rmpp_recv->cur_seg_buf = new_buf;
340 rmpp_recv->seg_num++;
341 new_buf = get_next_seg(rmpp_list, new_buf);
342 }
343}
344
345static inline int get_mad_len(struct mad_rmpp_recv *rmpp_recv)
346{
347 struct ib_rmpp_mad *rmpp_mad;
348 int hdr_size, data_size, pad;
349
350 rmpp_mad = (struct ib_rmpp_mad *)rmpp_recv->cur_seg_buf->mad;
351
352 hdr_size = data_offset(rmpp_mad->mad_hdr.mgmt_class);
353 data_size = sizeof(struct ib_rmpp_mad) - hdr_size;
354 pad = data_size - be32_to_cpu(rmpp_mad->rmpp_hdr.paylen_newwin);
355 if (pad > data_size || pad < 0)
356 pad = 0;
357
358 return hdr_size + rmpp_recv->seg_num * data_size - pad;
359}
360
361static struct ib_mad_recv_wc * complete_rmpp(struct mad_rmpp_recv *rmpp_recv)
362{
363 struct ib_mad_recv_wc *rmpp_wc;
364
365 ack_recv(rmpp_recv, rmpp_recv->rmpp_wc);
366 if (rmpp_recv->seg_num > 1)
367 cancel_delayed_work(&rmpp_recv->timeout_work);
368
369 rmpp_wc = rmpp_recv->rmpp_wc;
370 rmpp_wc->mad_len = get_mad_len(rmpp_recv);
371 /* 10 seconds until we can find the packet lifetime */
372 queue_delayed_work(rmpp_recv->agent->qp_info->port_priv->wq,
373 &rmpp_recv->cleanup_work, msecs_to_jiffies(10000));
374 return rmpp_wc;
375}
376
377void ib_coalesce_recv_mad(struct ib_mad_recv_wc *mad_recv_wc, void *buf)
378{
379 struct ib_mad_recv_buf *seg_buf;
380 struct ib_rmpp_mad *rmpp_mad;
381 void *data;
382 int size, len, offset;
383 u8 flags;
384
385 len = mad_recv_wc->mad_len;
386 if (len <= sizeof(struct ib_mad)) {
387 memcpy(buf, mad_recv_wc->recv_buf.mad, len);
388 return;
389 }
390
391 offset = data_offset(mad_recv_wc->recv_buf.mad->mad_hdr.mgmt_class);
392
393 list_for_each_entry(seg_buf, &mad_recv_wc->rmpp_list, list) {
394 rmpp_mad = (struct ib_rmpp_mad *)seg_buf->mad;
395 flags = ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr);
396
397 if (flags & IB_MGMT_RMPP_FLAG_FIRST) {
398 data = rmpp_mad;
399 size = sizeof(*rmpp_mad);
400 } else {
401 data = (void *) rmpp_mad + offset;
402 if (flags & IB_MGMT_RMPP_FLAG_LAST)
403 size = len;
404 else
405 size = sizeof(*rmpp_mad) - offset;
406 }
407
408 memcpy(buf, data, size);
409 len -= size;
410 buf += size;
411 }
412}
413EXPORT_SYMBOL(ib_coalesce_recv_mad);
414
415static struct ib_mad_recv_wc *
416continue_rmpp(struct ib_mad_agent_private *agent,
417 struct ib_mad_recv_wc *mad_recv_wc)
418{
419 struct mad_rmpp_recv *rmpp_recv;
420 struct ib_mad_recv_buf *prev_buf;
421 struct ib_mad_recv_wc *done_wc;
422 int seg_num;
423 unsigned long flags;
424
425 rmpp_recv = acquire_rmpp_recv(agent, mad_recv_wc);
426 if (!rmpp_recv)
427 goto drop1;
428
429 seg_num = get_seg_num(&mad_recv_wc->recv_buf);
430
431 spin_lock_irqsave(&rmpp_recv->lock, flags);
432 if ((rmpp_recv->state == RMPP_STATE_TIMEOUT) ||
433 (seg_num > rmpp_recv->newwin))
434 goto drop3;
435
436 if ((seg_num <= rmpp_recv->last_ack) ||
437 (rmpp_recv->state == RMPP_STATE_COMPLETE)) {
438 spin_unlock_irqrestore(&rmpp_recv->lock, flags);
439 ack_recv(rmpp_recv, mad_recv_wc);
440 goto drop2;
441 }
442
443 prev_buf = find_seg_location(&rmpp_recv->rmpp_wc->rmpp_list, seg_num);
444 if (!prev_buf)
445 goto drop3;
446
447 done_wc = NULL;
448 list_add(&mad_recv_wc->recv_buf.list, &prev_buf->list);
449 if (rmpp_recv->cur_seg_buf == prev_buf) {
450 update_seg_num(rmpp_recv, &mad_recv_wc->recv_buf);
451 if (get_last_flag(rmpp_recv->cur_seg_buf)) {
452 rmpp_recv->state = RMPP_STATE_COMPLETE;
453 spin_unlock_irqrestore(&rmpp_recv->lock, flags);
454 done_wc = complete_rmpp(rmpp_recv);
455 goto out;
456 } else if (rmpp_recv->seg_num == rmpp_recv->newwin) {
457 rmpp_recv->newwin += window_size(agent);
458 spin_unlock_irqrestore(&rmpp_recv->lock, flags);
459 ack_recv(rmpp_recv, mad_recv_wc);
460 goto out;
461 }
462 }
463 spin_unlock_irqrestore(&rmpp_recv->lock, flags);
464out:
465 deref_rmpp_recv(rmpp_recv);
466 return done_wc;
467
468drop3: spin_unlock_irqrestore(&rmpp_recv->lock, flags);
469drop2: deref_rmpp_recv(rmpp_recv);
470drop1: ib_free_recv_mad(mad_recv_wc);
471 return NULL;
472}
473
474static struct ib_mad_recv_wc *
475start_rmpp(struct ib_mad_agent_private *agent,
476 struct ib_mad_recv_wc *mad_recv_wc)
477{
478 struct mad_rmpp_recv *rmpp_recv;
479 unsigned long flags;
480
481 rmpp_recv = create_rmpp_recv(agent, mad_recv_wc);
482 if (!rmpp_recv) {
483 ib_free_recv_mad(mad_recv_wc);
484 return NULL;
485 }
486
487 spin_lock_irqsave(&agent->lock, flags);
488 if (insert_rmpp_recv(agent, rmpp_recv)) {
489 spin_unlock_irqrestore(&agent->lock, flags);
490 /* duplicate first MAD */
491 destroy_rmpp_recv(rmpp_recv);
492 return continue_rmpp(agent, mad_recv_wc);
493 }
494 atomic_inc(&rmpp_recv->refcount);
495
496 if (get_last_flag(&mad_recv_wc->recv_buf)) {
497 rmpp_recv->state = RMPP_STATE_COMPLETE;
498 spin_unlock_irqrestore(&agent->lock, flags);
499 complete_rmpp(rmpp_recv);
500 } else {
501 spin_unlock_irqrestore(&agent->lock, flags);
502 /* 40 seconds until we can find the packet lifetimes */
503 queue_delayed_work(agent->qp_info->port_priv->wq,
504 &rmpp_recv->timeout_work,
505 msecs_to_jiffies(40000));
506 rmpp_recv->newwin += window_size(agent);
507 ack_recv(rmpp_recv, mad_recv_wc);
508 mad_recv_wc = NULL;
509 }
510 deref_rmpp_recv(rmpp_recv);
511 return mad_recv_wc;
512}
513
514static inline u64 get_seg_addr(struct ib_mad_send_wr_private *mad_send_wr)
515{
516 return mad_send_wr->sg_list[0].addr + mad_send_wr->data_offset +
517 (sizeof(struct ib_rmpp_mad) - mad_send_wr->data_offset) *
518 (mad_send_wr->seg_num - 1);
519}
520
521static int send_next_seg(struct ib_mad_send_wr_private *mad_send_wr)
522{
523 struct ib_rmpp_mad *rmpp_mad;
524 int timeout;
525
526 rmpp_mad = (struct ib_rmpp_mad *)mad_send_wr->send_wr.wr.ud.mad_hdr;
527 ib_set_rmpp_flags(&rmpp_mad->rmpp_hdr, IB_MGMT_RMPP_FLAG_ACTIVE);
528 rmpp_mad->rmpp_hdr.seg_num = cpu_to_be32(mad_send_wr->seg_num);
529
530 if (mad_send_wr->seg_num == 1) {
531 rmpp_mad->rmpp_hdr.rmpp_rtime_flags |= IB_MGMT_RMPP_FLAG_FIRST;
532 rmpp_mad->rmpp_hdr.paylen_newwin =
533 cpu_to_be32(mad_send_wr->total_seg *
534 (sizeof(struct ib_rmpp_mad) -
535 offsetof(struct ib_rmpp_mad, data)));
536 mad_send_wr->sg_list[0].length = sizeof(struct ib_rmpp_mad);
537 } else {
538 mad_send_wr->send_wr.num_sge = 2;
539 mad_send_wr->sg_list[0].length = mad_send_wr->data_offset;
540 mad_send_wr->sg_list[1].addr = get_seg_addr(mad_send_wr);
541 mad_send_wr->sg_list[1].length = sizeof(struct ib_rmpp_mad) -
542 mad_send_wr->data_offset;
543 mad_send_wr->sg_list[1].lkey = mad_send_wr->sg_list[0].lkey;
544 }
545
546 if (mad_send_wr->seg_num == mad_send_wr->total_seg) {
547 rmpp_mad->rmpp_hdr.rmpp_rtime_flags |= IB_MGMT_RMPP_FLAG_LAST;
548 rmpp_mad->rmpp_hdr.paylen_newwin =
549 cpu_to_be32(sizeof(struct ib_rmpp_mad) -
550 offsetof(struct ib_rmpp_mad, data) -
551 mad_send_wr->pad);
552 }
553
554 /* 2 seconds for an ACK until we can find the packet lifetime */
555 timeout = mad_send_wr->send_wr.wr.ud.timeout_ms;
556 if (!timeout || timeout > 2000)
557 mad_send_wr->timeout = msecs_to_jiffies(2000);
558 mad_send_wr->seg_num++;
559 return ib_send_mad(mad_send_wr);
560}
561
562static void process_rmpp_ack(struct ib_mad_agent_private *agent,
563 struct ib_mad_recv_wc *mad_recv_wc)
564{
565 struct ib_mad_send_wr_private *mad_send_wr;
566 struct ib_rmpp_mad *rmpp_mad;
567 unsigned long flags;
568 int seg_num, newwin, ret;
569
570 rmpp_mad = (struct ib_rmpp_mad *)mad_recv_wc->recv_buf.mad;
571 if (rmpp_mad->rmpp_hdr.rmpp_status)
572 return;
573
574 seg_num = be32_to_cpu(rmpp_mad->rmpp_hdr.seg_num);
575 newwin = be32_to_cpu(rmpp_mad->rmpp_hdr.paylen_newwin);
576
577 spin_lock_irqsave(&agent->lock, flags);
578 mad_send_wr = ib_find_send_mad(agent, rmpp_mad->mad_hdr.tid);
579 if (!mad_send_wr)
580 goto out; /* Unmatched ACK */
581
582 if ((mad_send_wr->last_ack == mad_send_wr->total_seg) ||
583 (!mad_send_wr->timeout) || (mad_send_wr->status != IB_WC_SUCCESS))
584 goto out; /* Send is already done */
585
586 if (seg_num > mad_send_wr->total_seg)
587 goto out; /* Bad ACK */
588
589 if (newwin < mad_send_wr->newwin || seg_num < mad_send_wr->last_ack)
590 goto out; /* Old ACK */
591
592 if (seg_num > mad_send_wr->last_ack) {
593 mad_send_wr->last_ack = seg_num;
594 mad_send_wr->retries = mad_send_wr->send_wr.wr.ud.retries;
595 }
596 mad_send_wr->newwin = newwin;
597 if (mad_send_wr->last_ack == mad_send_wr->total_seg) {
598 /* If no response is expected, the ACK completes the send */
599 if (!mad_send_wr->send_wr.wr.ud.timeout_ms) {
600 struct ib_mad_send_wc wc;
601
602 ib_mark_mad_done(mad_send_wr);
603 spin_unlock_irqrestore(&agent->lock, flags);
604
605 wc.status = IB_WC_SUCCESS;
606 wc.vendor_err = 0;
607 wc.wr_id = mad_send_wr->wr_id;
608 ib_mad_complete_send_wr(mad_send_wr, &wc);
609 return;
610 }
611 if (mad_send_wr->refcount == 1)
612 ib_reset_mad_timeout(mad_send_wr, mad_send_wr->
613 send_wr.wr.ud.timeout_ms);
614 } else if (mad_send_wr->refcount == 1 &&
615 mad_send_wr->seg_num < mad_send_wr->newwin &&
616 mad_send_wr->seg_num <= mad_send_wr->total_seg) {
617 /* Send failure will just result in a timeout/retry */
618 ret = send_next_seg(mad_send_wr);
619 if (ret)
620 goto out;
621
622 mad_send_wr->refcount++;
623 list_del(&mad_send_wr->agent_list);
624 list_add_tail(&mad_send_wr->agent_list,
625 &mad_send_wr->mad_agent_priv->send_list);
626 }
627out:
628 spin_unlock_irqrestore(&agent->lock, flags);
629}
630
631struct ib_mad_recv_wc *
632ib_process_rmpp_recv_wc(struct ib_mad_agent_private *agent,
633 struct ib_mad_recv_wc *mad_recv_wc)
634{
635 struct ib_rmpp_mad *rmpp_mad;
636
637 rmpp_mad = (struct ib_rmpp_mad *)mad_recv_wc->recv_buf.mad;
638 if (!(rmpp_mad->rmpp_hdr.rmpp_rtime_flags & IB_MGMT_RMPP_FLAG_ACTIVE))
639 return mad_recv_wc;
640
641 if (rmpp_mad->rmpp_hdr.rmpp_version != IB_MGMT_RMPP_VERSION)
642 goto out;
643
644 switch (rmpp_mad->rmpp_hdr.rmpp_type) {
645 case IB_MGMT_RMPP_TYPE_DATA:
646 if (rmpp_mad->rmpp_hdr.seg_num == __constant_htonl(1))
647 return start_rmpp(agent, mad_recv_wc);
648 else
649 return continue_rmpp(agent, mad_recv_wc);
650 case IB_MGMT_RMPP_TYPE_ACK:
651 process_rmpp_ack(agent, mad_recv_wc);
652 break;
653 case IB_MGMT_RMPP_TYPE_STOP:
654 case IB_MGMT_RMPP_TYPE_ABORT:
655 /* TODO: process_rmpp_nack(agent, mad_recv_wc); */
656 break;
657 default:
658 break;
659 }
660out:
661 ib_free_recv_mad(mad_recv_wc);
662 return NULL;
663}
664
665int ib_send_rmpp_mad(struct ib_mad_send_wr_private *mad_send_wr)
666{
667 struct ib_rmpp_mad *rmpp_mad;
668 int i, total_len, ret;
669
670 rmpp_mad = (struct ib_rmpp_mad *)mad_send_wr->send_wr.wr.ud.mad_hdr;
671 if (!(ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) &
672 IB_MGMT_RMPP_FLAG_ACTIVE))
673 return IB_RMPP_RESULT_UNHANDLED;
674
675 if (rmpp_mad->rmpp_hdr.rmpp_type != IB_MGMT_RMPP_TYPE_DATA)
676 return IB_RMPP_RESULT_INTERNAL;
677
678 if (mad_send_wr->send_wr.num_sge > 1)
679 return -EINVAL; /* TODO: support num_sge > 1 */
680
681 mad_send_wr->seg_num = 1;
682 mad_send_wr->newwin = 1;
683 mad_send_wr->data_offset = data_offset(rmpp_mad->mad_hdr.mgmt_class);
684
685 total_len = 0;
686 for (i = 0; i < mad_send_wr->send_wr.num_sge; i++)
687 total_len += mad_send_wr->send_wr.sg_list[i].length;
688
689 mad_send_wr->total_seg = (total_len - mad_send_wr->data_offset) /
690 (sizeof(struct ib_rmpp_mad) - mad_send_wr->data_offset);
691 mad_send_wr->pad = total_len - offsetof(struct ib_rmpp_mad, data) -
692 be32_to_cpu(rmpp_mad->rmpp_hdr.paylen_newwin);
693
694 /* We need to wait for the final ACK even if there isn't a response */
695 mad_send_wr->refcount += (mad_send_wr->timeout == 0);
696 ret = send_next_seg(mad_send_wr);
697 if (!ret)
698 return IB_RMPP_RESULT_CONSUMED;
699 return ret;
700}
701
702int ib_process_rmpp_send_wc(struct ib_mad_send_wr_private *mad_send_wr,
703 struct ib_mad_send_wc *mad_send_wc)
704{
705 struct ib_rmpp_mad *rmpp_mad;
706 struct ib_mad_send_buf *msg;
707 int ret;
708
709 rmpp_mad = (struct ib_rmpp_mad *)mad_send_wr->send_wr.wr.ud.mad_hdr;
710 if (!(ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) &
711 IB_MGMT_RMPP_FLAG_ACTIVE))
712 return IB_RMPP_RESULT_UNHANDLED; /* RMPP not active */
713
714 if (rmpp_mad->rmpp_hdr.rmpp_type != IB_MGMT_RMPP_TYPE_DATA) {
715 msg = (struct ib_mad_send_buf *) (unsigned long)
716 mad_send_wc->wr_id;
717 ib_free_send_mad(msg);
718 return IB_RMPP_RESULT_INTERNAL; /* ACK, STOP, or ABORT */
719 }
720
721 if (mad_send_wc->status != IB_WC_SUCCESS ||
722 mad_send_wr->status != IB_WC_SUCCESS)
723 return IB_RMPP_RESULT_PROCESSED; /* Canceled or send error */
724
725 if (!mad_send_wr->timeout)
726 return IB_RMPP_RESULT_PROCESSED; /* Response received */
727
728 if (mad_send_wr->last_ack == mad_send_wr->total_seg) {
729 mad_send_wr->timeout =
730 msecs_to_jiffies(mad_send_wr->send_wr.wr.ud.timeout_ms);
731 return IB_RMPP_RESULT_PROCESSED; /* Send done */
732 }
733
734 if (mad_send_wr->seg_num > mad_send_wr->newwin ||
735 mad_send_wr->seg_num > mad_send_wr->total_seg)
736 return IB_RMPP_RESULT_PROCESSED; /* Wait for ACK */
737
738 ret = send_next_seg(mad_send_wr);
739 if (ret) {
740 mad_send_wc->status = IB_WC_GENERAL_ERR;
741 return IB_RMPP_RESULT_PROCESSED;
742 }
743 return IB_RMPP_RESULT_CONSUMED;
744}
745
746int ib_retry_rmpp(struct ib_mad_send_wr_private *mad_send_wr)
747{
748 struct ib_rmpp_mad *rmpp_mad;
749 int ret;
750
751 rmpp_mad = (struct ib_rmpp_mad *)mad_send_wr->send_wr.wr.ud.mad_hdr;
752 if (!(ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) &
753 IB_MGMT_RMPP_FLAG_ACTIVE))
754 return IB_RMPP_RESULT_UNHANDLED; /* RMPP not active */
755
756 if (mad_send_wr->last_ack == mad_send_wr->total_seg)
757 return IB_RMPP_RESULT_PROCESSED;
758
759 mad_send_wr->seg_num = mad_send_wr->last_ack + 1;
760 ret = send_next_seg(mad_send_wr);
761 if (ret)
762 return IB_RMPP_RESULT_PROCESSED;
763
764 return IB_RMPP_RESULT_CONSUMED;
765}
diff --git a/drivers/infiniband/core/mad_rmpp.h b/drivers/infiniband/core/mad_rmpp.h
new file mode 100644
index 000000000000..c4924dfb8e75
--- /dev/null
+++ b/drivers/infiniband/core/mad_rmpp.h
@@ -0,0 +1,58 @@
1/*
2 * Copyright (c) 2005 Intel Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 *
32 * $Id: mad_rmpp.h 1921 2005-02-25 22:58:44Z sean.hefty $
33 */
34
35#ifndef __MAD_RMPP_H__
36#define __MAD_RMPP_H__
37
38enum {
39 IB_RMPP_RESULT_PROCESSED,
40 IB_RMPP_RESULT_CONSUMED,
41 IB_RMPP_RESULT_INTERNAL,
42 IB_RMPP_RESULT_UNHANDLED
43};
44
45int ib_send_rmpp_mad(struct ib_mad_send_wr_private *mad_send_wr);
46
47struct ib_mad_recv_wc *
48ib_process_rmpp_recv_wc(struct ib_mad_agent_private *agent,
49 struct ib_mad_recv_wc *mad_recv_wc);
50
51int ib_process_rmpp_send_wc(struct ib_mad_send_wr_private *mad_send_wr,
52 struct ib_mad_send_wc *mad_send_wc);
53
54void ib_cancel_rmpp_recvs(struct ib_mad_agent_private *agent);
55
56int ib_retry_rmpp(struct ib_mad_send_wr_private *mad_send_wr);
57
58#endif /* __MAD_RMPP_H__ */
diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c
index 5a08e81fa827..795184931c83 100644
--- a/drivers/infiniband/core/sa_query.c
+++ b/drivers/infiniband/core/sa_query.c
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (c) 2004 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
3 * 4 *
4 * This software is available to you under a choice of one of two 5 * 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 * licenses. You may choose to be licensed under the terms of the GNU
@@ -29,7 +30,7 @@
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE. 31 * SOFTWARE.
31 * 32 *
32 * $Id: sa_query.c 1389 2004-12-27 22:56:47Z roland $ 33 * $Id: sa_query.c 2811 2005-07-06 18:11:43Z halr $
33 */ 34 */
34 35
35#include <linux/module.h> 36#include <linux/module.h>
@@ -50,26 +51,6 @@ MODULE_AUTHOR("Roland Dreier");
50MODULE_DESCRIPTION("InfiniBand subnet administration query support"); 51MODULE_DESCRIPTION("InfiniBand subnet administration query support");
51MODULE_LICENSE("Dual BSD/GPL"); 52MODULE_LICENSE("Dual BSD/GPL");
52 53
53/*
54 * These two structures must be packed because they have 64-bit fields
55 * that are only 32-bit aligned. 64-bit architectures will lay them
56 * out wrong otherwise. (And unfortunately they are sent on the wire
57 * so we can't change the layout)
58 */
59struct ib_sa_hdr {
60 u64 sm_key;
61 u16 attr_offset;
62 u16 reserved;
63 ib_sa_comp_mask comp_mask;
64} __attribute__ ((packed));
65
66struct ib_sa_mad {
67 struct ib_mad_hdr mad_hdr;
68 struct ib_rmpp_hdr rmpp_hdr;
69 struct ib_sa_hdr sa_hdr;
70 u8 data[200];
71} __attribute__ ((packed));
72
73struct ib_sa_sm_ah { 54struct ib_sa_sm_ah {
74 struct ib_ah *ah; 55 struct ib_ah *ah;
75 struct kref ref; 56 struct kref ref;
@@ -77,7 +58,6 @@ struct ib_sa_sm_ah {
77 58
78struct ib_sa_port { 59struct ib_sa_port {
79 struct ib_mad_agent *agent; 60 struct ib_mad_agent *agent;
80 struct ib_mr *mr;
81 struct ib_sa_sm_ah *sm_ah; 61 struct ib_sa_sm_ah *sm_ah;
82 struct work_struct update_task; 62 struct work_struct update_task;
83 spinlock_t ah_lock; 63 spinlock_t ah_lock;
@@ -100,6 +80,12 @@ struct ib_sa_query {
100 int id; 80 int id;
101}; 81};
102 82
83struct ib_sa_service_query {
84 void (*callback)(int, struct ib_sa_service_rec *, void *);
85 void *context;
86 struct ib_sa_query sa_query;
87};
88
103struct ib_sa_path_query { 89struct ib_sa_path_query {
104 void (*callback)(int, struct ib_sa_path_rec *, void *); 90 void (*callback)(int, struct ib_sa_path_rec *, void *);
105 void *context; 91 void *context;
@@ -341,6 +327,54 @@ static const struct ib_field mcmember_rec_table[] = {
341 .size_bits = 23 }, 327 .size_bits = 23 },
342}; 328};
343 329
330#define SERVICE_REC_FIELD(field) \
331 .struct_offset_bytes = offsetof(struct ib_sa_service_rec, field), \
332 .struct_size_bytes = sizeof ((struct ib_sa_service_rec *) 0)->field, \
333 .field_name = "sa_service_rec:" #field
334
335static const struct ib_field service_rec_table[] = {
336 { SERVICE_REC_FIELD(id),
337 .offset_words = 0,
338 .offset_bits = 0,
339 .size_bits = 64 },
340 { SERVICE_REC_FIELD(gid),
341 .offset_words = 2,
342 .offset_bits = 0,
343 .size_bits = 128 },
344 { SERVICE_REC_FIELD(pkey),
345 .offset_words = 6,
346 .offset_bits = 0,
347 .size_bits = 16 },
348 { SERVICE_REC_FIELD(lease),
349 .offset_words = 7,
350 .offset_bits = 0,
351 .size_bits = 32 },
352 { SERVICE_REC_FIELD(key),
353 .offset_words = 8,
354 .offset_bits = 0,
355 .size_bits = 128 },
356 { SERVICE_REC_FIELD(name),
357 .offset_words = 12,
358 .offset_bits = 0,
359 .size_bits = 64*8 },
360 { SERVICE_REC_FIELD(data8),
361 .offset_words = 28,
362 .offset_bits = 0,
363 .size_bits = 16*8 },
364 { SERVICE_REC_FIELD(data16),
365 .offset_words = 32,
366 .offset_bits = 0,
367 .size_bits = 8*16 },
368 { SERVICE_REC_FIELD(data32),
369 .offset_words = 36,
370 .offset_bits = 0,
371 .size_bits = 4*32 },
372 { SERVICE_REC_FIELD(data64),
373 .offset_words = 40,
374 .offset_bits = 0,
375 .size_bits = 2*64 },
376};
377
344static void free_sm_ah(struct kref *kref) 378static void free_sm_ah(struct kref *kref)
345{ 379{
346 struct ib_sa_sm_ah *sm_ah = container_of(kref, struct ib_sa_sm_ah, ref); 380 struct ib_sa_sm_ah *sm_ah = container_of(kref, struct ib_sa_sm_ah, ref);
@@ -463,7 +497,7 @@ static int send_mad(struct ib_sa_query *query, int timeout_ms)
463 .mad_hdr = &query->mad->mad_hdr, 497 .mad_hdr = &query->mad->mad_hdr,
464 .remote_qpn = 1, 498 .remote_qpn = 1,
465 .remote_qkey = IB_QP1_QKEY, 499 .remote_qkey = IB_QP1_QKEY,
466 .timeout_ms = timeout_ms 500 .timeout_ms = timeout_ms,
467 } 501 }
468 } 502 }
469 }; 503 };
@@ -492,7 +526,7 @@ retry:
492 sizeof (struct ib_sa_mad), 526 sizeof (struct ib_sa_mad),
493 DMA_TO_DEVICE); 527 DMA_TO_DEVICE);
494 gather_list.length = sizeof (struct ib_sa_mad); 528 gather_list.length = sizeof (struct ib_sa_mad);
495 gather_list.lkey = port->mr->lkey; 529 gather_list.lkey = port->agent->mr->lkey;
496 pci_unmap_addr_set(query, mapping, gather_list.addr); 530 pci_unmap_addr_set(query, mapping, gather_list.addr);
497 531
498 ret = ib_post_send_mad(port->agent, &wr, &bad_wr); 532 ret = ib_post_send_mad(port->agent, &wr, &bad_wr);
@@ -566,7 +600,7 @@ static void ib_sa_path_rec_release(struct ib_sa_query *sa_query)
566int ib_sa_path_rec_get(struct ib_device *device, u8 port_num, 600int ib_sa_path_rec_get(struct ib_device *device, u8 port_num,
567 struct ib_sa_path_rec *rec, 601 struct ib_sa_path_rec *rec,
568 ib_sa_comp_mask comp_mask, 602 ib_sa_comp_mask comp_mask,
569 int timeout_ms, int gfp_mask, 603 int timeout_ms, unsigned int __nocast gfp_mask,
570 void (*callback)(int status, 604 void (*callback)(int status,
571 struct ib_sa_path_rec *resp, 605 struct ib_sa_path_rec *resp,
572 void *context), 606 void *context),
@@ -616,6 +650,114 @@ int ib_sa_path_rec_get(struct ib_device *device, u8 port_num,
616} 650}
617EXPORT_SYMBOL(ib_sa_path_rec_get); 651EXPORT_SYMBOL(ib_sa_path_rec_get);
618 652
653static void ib_sa_service_rec_callback(struct ib_sa_query *sa_query,
654 int status,
655 struct ib_sa_mad *mad)
656{
657 struct ib_sa_service_query *query =
658 container_of(sa_query, struct ib_sa_service_query, sa_query);
659
660 if (mad) {
661 struct ib_sa_service_rec rec;
662
663 ib_unpack(service_rec_table, ARRAY_SIZE(service_rec_table),
664 mad->data, &rec);
665 query->callback(status, &rec, query->context);
666 } else
667 query->callback(status, NULL, query->context);
668}
669
670static void ib_sa_service_rec_release(struct ib_sa_query *sa_query)
671{
672 kfree(sa_query->mad);
673 kfree(container_of(sa_query, struct ib_sa_service_query, sa_query));
674}
675
676/**
677 * ib_sa_service_rec_query - Start Service Record operation
678 * @device:device to send request on
679 * @port_num: port number to send request on
680 * @method:SA method - should be get, set, or delete
681 * @rec:Service Record to send in request
682 * @comp_mask:component mask to send in request
683 * @timeout_ms:time to wait for response
684 * @gfp_mask:GFP mask to use for internal allocations
685 * @callback:function called when request completes, times out or is
686 * canceled
687 * @context:opaque user context passed to callback
688 * @sa_query:request context, used to cancel request
689 *
690 * Send a Service Record set/get/delete to the SA to register,
691 * unregister or query a service record.
692 * The callback function will be called when the request completes (or
693 * fails); status is 0 for a successful response, -EINTR if the query
694 * is canceled, -ETIMEDOUT is the query timed out, or -EIO if an error
695 * occurred sending the query. The resp parameter of the callback is
696 * only valid if status is 0.
697 *
698 * If the return value of ib_sa_service_rec_query() is negative, it is an
699 * error code. Otherwise it is a request ID that can be used to cancel
700 * the query.
701 */
702int ib_sa_service_rec_query(struct ib_device *device, u8 port_num, u8 method,
703 struct ib_sa_service_rec *rec,
704 ib_sa_comp_mask comp_mask,
705 int timeout_ms, unsigned int __nocast gfp_mask,
706 void (*callback)(int status,
707 struct ib_sa_service_rec *resp,
708 void *context),
709 void *context,
710 struct ib_sa_query **sa_query)
711{
712 struct ib_sa_service_query *query;
713 struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client);
714 struct ib_sa_port *port = &sa_dev->port[port_num - sa_dev->start_port];
715 struct ib_mad_agent *agent = port->agent;
716 int ret;
717
718 if (method != IB_MGMT_METHOD_GET &&
719 method != IB_MGMT_METHOD_SET &&
720 method != IB_SA_METHOD_DELETE)
721 return -EINVAL;
722
723 query = kmalloc(sizeof *query, gfp_mask);
724 if (!query)
725 return -ENOMEM;
726 query->sa_query.mad = kmalloc(sizeof *query->sa_query.mad, gfp_mask);
727 if (!query->sa_query.mad) {
728 kfree(query);
729 return -ENOMEM;
730 }
731
732 query->callback = callback;
733 query->context = context;
734
735 init_mad(query->sa_query.mad, agent);
736
737 query->sa_query.callback = callback ? ib_sa_service_rec_callback : NULL;
738 query->sa_query.release = ib_sa_service_rec_release;
739 query->sa_query.port = port;
740 query->sa_query.mad->mad_hdr.method = method;
741 query->sa_query.mad->mad_hdr.attr_id =
742 cpu_to_be16(IB_SA_ATTR_SERVICE_REC);
743 query->sa_query.mad->sa_hdr.comp_mask = comp_mask;
744
745 ib_pack(service_rec_table, ARRAY_SIZE(service_rec_table),
746 rec, query->sa_query.mad->data);
747
748 *sa_query = &query->sa_query;
749
750 ret = send_mad(&query->sa_query, timeout_ms);
751 if (ret < 0) {
752 *sa_query = NULL;
753 kfree(query->sa_query.mad);
754 kfree(query);
755 }
756
757 return ret;
758}
759EXPORT_SYMBOL(ib_sa_service_rec_query);
760
619static void ib_sa_mcmember_rec_callback(struct ib_sa_query *sa_query, 761static void ib_sa_mcmember_rec_callback(struct ib_sa_query *sa_query,
620 int status, 762 int status,
621 struct ib_sa_mad *mad) 763 struct ib_sa_mad *mad)
@@ -643,7 +785,7 @@ int ib_sa_mcmember_rec_query(struct ib_device *device, u8 port_num,
643 u8 method, 785 u8 method,
644 struct ib_sa_mcmember_rec *rec, 786 struct ib_sa_mcmember_rec *rec,
645 ib_sa_comp_mask comp_mask, 787 ib_sa_comp_mask comp_mask,
646 int timeout_ms, int gfp_mask, 788 int timeout_ms, unsigned int __nocast gfp_mask,
647 void (*callback)(int status, 789 void (*callback)(int status,
648 struct ib_sa_mcmember_rec *resp, 790 struct ib_sa_mcmember_rec *resp,
649 void *context), 791 void *context),
@@ -780,7 +922,6 @@ static void ib_sa_add_one(struct ib_device *device)
780 sa_dev->end_port = e; 922 sa_dev->end_port = e;
781 923
782 for (i = 0; i <= e - s; ++i) { 924 for (i = 0; i <= e - s; ++i) {
783 sa_dev->port[i].mr = NULL;
784 sa_dev->port[i].sm_ah = NULL; 925 sa_dev->port[i].sm_ah = NULL;
785 sa_dev->port[i].port_num = i + s; 926 sa_dev->port[i].port_num = i + s;
786 spin_lock_init(&sa_dev->port[i].ah_lock); 927 spin_lock_init(&sa_dev->port[i].ah_lock);
@@ -792,13 +933,6 @@ static void ib_sa_add_one(struct ib_device *device)
792 if (IS_ERR(sa_dev->port[i].agent)) 933 if (IS_ERR(sa_dev->port[i].agent))
793 goto err; 934 goto err;
794 935
795 sa_dev->port[i].mr = ib_get_dma_mr(sa_dev->port[i].agent->qp->pd,
796 IB_ACCESS_LOCAL_WRITE);
797 if (IS_ERR(sa_dev->port[i].mr)) {
798 ib_unregister_mad_agent(sa_dev->port[i].agent);
799 goto err;
800 }
801
802 INIT_WORK(&sa_dev->port[i].update_task, 936 INIT_WORK(&sa_dev->port[i].update_task,
803 update_sm_ah, &sa_dev->port[i]); 937 update_sm_ah, &sa_dev->port[i]);
804 } 938 }
@@ -822,10 +956,8 @@ static void ib_sa_add_one(struct ib_device *device)
822 return; 956 return;
823 957
824err: 958err:
825 while (--i >= 0) { 959 while (--i >= 0)
826 ib_dereg_mr(sa_dev->port[i].mr);
827 ib_unregister_mad_agent(sa_dev->port[i].agent); 960 ib_unregister_mad_agent(sa_dev->port[i].agent);
828 }
829 961
830 kfree(sa_dev); 962 kfree(sa_dev);
831 963
diff --git a/drivers/infiniband/core/ucm.c b/drivers/infiniband/core/ucm.c
new file mode 100644
index 000000000000..61d07c732f49
--- /dev/null
+++ b/drivers/infiniband/core/ucm.c
@@ -0,0 +1,1387 @@
1/*
2 * Copyright (c) 2005 Topspin Communications. 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: ucm.c 2594 2005-06-13 19:46:02Z libor $
33 */
34#include <linux/init.h>
35#include <linux/fs.h>
36#include <linux/module.h>
37#include <linux/device.h>
38#include <linux/err.h>
39#include <linux/poll.h>
40#include <linux/file.h>
41#include <linux/mount.h>
42#include <linux/cdev.h>
43
44#include <asm/uaccess.h>
45
46#include "ucm.h"
47
48MODULE_AUTHOR("Libor Michalek");
49MODULE_DESCRIPTION("InfiniBand userspace Connection Manager access");
50MODULE_LICENSE("Dual BSD/GPL");
51
52static int ucm_debug_level;
53
54module_param_named(debug_level, ucm_debug_level, int, 0644);
55MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0");
56
57enum {
58 IB_UCM_MAJOR = 231,
59 IB_UCM_MINOR = 255
60};
61
62#define IB_UCM_DEV MKDEV(IB_UCM_MAJOR, IB_UCM_MINOR)
63
64#define PFX "UCM: "
65
66#define ucm_dbg(format, arg...) \
67 do { \
68 if (ucm_debug_level > 0) \
69 printk(KERN_DEBUG PFX format, ## arg); \
70 } while (0)
71
72static struct semaphore ctx_id_mutex;
73static struct idr ctx_id_table;
74static int ctx_id_rover = 0;
75
76static struct ib_ucm_context *ib_ucm_ctx_get(int id)
77{
78 struct ib_ucm_context *ctx;
79
80 down(&ctx_id_mutex);
81 ctx = idr_find(&ctx_id_table, id);
82 if (ctx)
83 ctx->ref++;
84 up(&ctx_id_mutex);
85
86 return ctx;
87}
88
89static void ib_ucm_ctx_put(struct ib_ucm_context *ctx)
90{
91 struct ib_ucm_event *uevent;
92
93 down(&ctx_id_mutex);
94
95 ctx->ref--;
96 if (!ctx->ref)
97 idr_remove(&ctx_id_table, ctx->id);
98
99 up(&ctx_id_mutex);
100
101 if (ctx->ref)
102 return;
103
104 down(&ctx->file->mutex);
105
106 list_del(&ctx->file_list);
107 while (!list_empty(&ctx->events)) {
108
109 uevent = list_entry(ctx->events.next,
110 struct ib_ucm_event, ctx_list);
111 list_del(&uevent->file_list);
112 list_del(&uevent->ctx_list);
113
114 /* clear incoming connections. */
115 if (uevent->cm_id)
116 ib_destroy_cm_id(uevent->cm_id);
117
118 kfree(uevent);
119 }
120
121 up(&ctx->file->mutex);
122
123 ucm_dbg("Destroyed CM ID <%d>\n", ctx->id);
124
125 ib_destroy_cm_id(ctx->cm_id);
126 kfree(ctx);
127}
128
129static struct ib_ucm_context *ib_ucm_ctx_alloc(struct ib_ucm_file *file)
130{
131 struct ib_ucm_context *ctx;
132 int result;
133
134 ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
135 if (!ctx)
136 return NULL;
137
138 ctx->ref = 1; /* user reference */
139 ctx->file = file;
140
141 INIT_LIST_HEAD(&ctx->events);
142 init_MUTEX(&ctx->mutex);
143
144 list_add_tail(&ctx->file_list, &file->ctxs);
145
146 ctx_id_rover = (ctx_id_rover + 1) & INT_MAX;
147retry:
148 result = idr_pre_get(&ctx_id_table, GFP_KERNEL);
149 if (!result)
150 goto error;
151
152 down(&ctx_id_mutex);
153 result = idr_get_new_above(&ctx_id_table, ctx, ctx_id_rover, &ctx->id);
154 up(&ctx_id_mutex);
155
156 if (result == -EAGAIN)
157 goto retry;
158 if (result)
159 goto error;
160
161 ucm_dbg("Allocated CM ID <%d>\n", ctx->id);
162
163 return ctx;
164error:
165 list_del(&ctx->file_list);
166 kfree(ctx);
167
168 return NULL;
169}
170/*
171 * Event portion of the API, handle CM events
172 * and allow event polling.
173 */
174static void ib_ucm_event_path_get(struct ib_ucm_path_rec *upath,
175 struct ib_sa_path_rec *kpath)
176{
177 if (!kpath || !upath)
178 return;
179
180 memcpy(upath->dgid, kpath->dgid.raw, sizeof(union ib_gid));
181 memcpy(upath->sgid, kpath->sgid.raw, sizeof(union ib_gid));
182
183 upath->dlid = kpath->dlid;
184 upath->slid = kpath->slid;
185 upath->raw_traffic = kpath->raw_traffic;
186 upath->flow_label = kpath->flow_label;
187 upath->hop_limit = kpath->hop_limit;
188 upath->traffic_class = kpath->traffic_class;
189 upath->reversible = kpath->reversible;
190 upath->numb_path = kpath->numb_path;
191 upath->pkey = kpath->pkey;
192 upath->sl = kpath->sl;
193 upath->mtu_selector = kpath->mtu_selector;
194 upath->mtu = kpath->mtu;
195 upath->rate_selector = kpath->rate_selector;
196 upath->rate = kpath->rate;
197 upath->packet_life_time = kpath->packet_life_time;
198 upath->preference = kpath->preference;
199
200 upath->packet_life_time_selector =
201 kpath->packet_life_time_selector;
202}
203
204static void ib_ucm_event_req_get(struct ib_ucm_req_event_resp *ureq,
205 struct ib_cm_req_event_param *kreq)
206{
207 ureq->listen_id = (long)kreq->listen_id->context;
208
209 ureq->remote_ca_guid = kreq->remote_ca_guid;
210 ureq->remote_qkey = kreq->remote_qkey;
211 ureq->remote_qpn = kreq->remote_qpn;
212 ureq->qp_type = kreq->qp_type;
213 ureq->starting_psn = kreq->starting_psn;
214 ureq->responder_resources = kreq->responder_resources;
215 ureq->initiator_depth = kreq->initiator_depth;
216 ureq->local_cm_response_timeout = kreq->local_cm_response_timeout;
217 ureq->flow_control = kreq->flow_control;
218 ureq->remote_cm_response_timeout = kreq->remote_cm_response_timeout;
219 ureq->retry_count = kreq->retry_count;
220 ureq->rnr_retry_count = kreq->rnr_retry_count;
221 ureq->srq = kreq->srq;
222
223 ib_ucm_event_path_get(&ureq->primary_path, kreq->primary_path);
224 ib_ucm_event_path_get(&ureq->alternate_path, kreq->alternate_path);
225}
226
227static void ib_ucm_event_rep_get(struct ib_ucm_rep_event_resp *urep,
228 struct ib_cm_rep_event_param *krep)
229{
230 urep->remote_ca_guid = krep->remote_ca_guid;
231 urep->remote_qkey = krep->remote_qkey;
232 urep->remote_qpn = krep->remote_qpn;
233 urep->starting_psn = krep->starting_psn;
234 urep->responder_resources = krep->responder_resources;
235 urep->initiator_depth = krep->initiator_depth;
236 urep->target_ack_delay = krep->target_ack_delay;
237 urep->failover_accepted = krep->failover_accepted;
238 urep->flow_control = krep->flow_control;
239 urep->rnr_retry_count = krep->rnr_retry_count;
240 urep->srq = krep->srq;
241}
242
243static void ib_ucm_event_rej_get(struct ib_ucm_rej_event_resp *urej,
244 struct ib_cm_rej_event_param *krej)
245{
246 urej->reason = krej->reason;
247}
248
249static void ib_ucm_event_mra_get(struct ib_ucm_mra_event_resp *umra,
250 struct ib_cm_mra_event_param *kmra)
251{
252 umra->timeout = kmra->service_timeout;
253}
254
255static void ib_ucm_event_lap_get(struct ib_ucm_lap_event_resp *ulap,
256 struct ib_cm_lap_event_param *klap)
257{
258 ib_ucm_event_path_get(&ulap->path, klap->alternate_path);
259}
260
261static void ib_ucm_event_apr_get(struct ib_ucm_apr_event_resp *uapr,
262 struct ib_cm_apr_event_param *kapr)
263{
264 uapr->status = kapr->ap_status;
265}
266
267static void ib_ucm_event_sidr_req_get(struct ib_ucm_sidr_req_event_resp *ureq,
268 struct ib_cm_sidr_req_event_param *kreq)
269{
270 ureq->listen_id = (long)kreq->listen_id->context;
271 ureq->pkey = kreq->pkey;
272}
273
274static void ib_ucm_event_sidr_rep_get(struct ib_ucm_sidr_rep_event_resp *urep,
275 struct ib_cm_sidr_rep_event_param *krep)
276{
277 urep->status = krep->status;
278 urep->qkey = krep->qkey;
279 urep->qpn = krep->qpn;
280};
281
282static int ib_ucm_event_process(struct ib_cm_event *evt,
283 struct ib_ucm_event *uvt)
284{
285 void *info = NULL;
286 int result;
287
288 switch (evt->event) {
289 case IB_CM_REQ_RECEIVED:
290 ib_ucm_event_req_get(&uvt->resp.u.req_resp,
291 &evt->param.req_rcvd);
292 uvt->data_len = IB_CM_REQ_PRIVATE_DATA_SIZE;
293 uvt->resp.present |= (evt->param.req_rcvd.primary_path ?
294 IB_UCM_PRES_PRIMARY : 0);
295 uvt->resp.present |= (evt->param.req_rcvd.alternate_path ?
296 IB_UCM_PRES_ALTERNATE : 0);
297 break;
298 case IB_CM_REP_RECEIVED:
299 ib_ucm_event_rep_get(&uvt->resp.u.rep_resp,
300 &evt->param.rep_rcvd);
301 uvt->data_len = IB_CM_REP_PRIVATE_DATA_SIZE;
302
303 break;
304 case IB_CM_RTU_RECEIVED:
305 uvt->data_len = IB_CM_RTU_PRIVATE_DATA_SIZE;
306 uvt->resp.u.send_status = evt->param.send_status;
307
308 break;
309 case IB_CM_DREQ_RECEIVED:
310 uvt->data_len = IB_CM_DREQ_PRIVATE_DATA_SIZE;
311 uvt->resp.u.send_status = evt->param.send_status;
312
313 break;
314 case IB_CM_DREP_RECEIVED:
315 uvt->data_len = IB_CM_DREP_PRIVATE_DATA_SIZE;
316 uvt->resp.u.send_status = evt->param.send_status;
317
318 break;
319 case IB_CM_MRA_RECEIVED:
320 ib_ucm_event_mra_get(&uvt->resp.u.mra_resp,
321 &evt->param.mra_rcvd);
322 uvt->data_len = IB_CM_MRA_PRIVATE_DATA_SIZE;
323
324 break;
325 case IB_CM_REJ_RECEIVED:
326 ib_ucm_event_rej_get(&uvt->resp.u.rej_resp,
327 &evt->param.rej_rcvd);
328 uvt->data_len = IB_CM_REJ_PRIVATE_DATA_SIZE;
329 uvt->info_len = evt->param.rej_rcvd.ari_length;
330 info = evt->param.rej_rcvd.ari;
331
332 break;
333 case IB_CM_LAP_RECEIVED:
334 ib_ucm_event_lap_get(&uvt->resp.u.lap_resp,
335 &evt->param.lap_rcvd);
336 uvt->data_len = IB_CM_LAP_PRIVATE_DATA_SIZE;
337 uvt->resp.present |= (evt->param.lap_rcvd.alternate_path ?
338 IB_UCM_PRES_ALTERNATE : 0);
339 break;
340 case IB_CM_APR_RECEIVED:
341 ib_ucm_event_apr_get(&uvt->resp.u.apr_resp,
342 &evt->param.apr_rcvd);
343 uvt->data_len = IB_CM_APR_PRIVATE_DATA_SIZE;
344 uvt->info_len = evt->param.apr_rcvd.info_len;
345 info = evt->param.apr_rcvd.apr_info;
346
347 break;
348 case IB_CM_SIDR_REQ_RECEIVED:
349 ib_ucm_event_sidr_req_get(&uvt->resp.u.sidr_req_resp,
350 &evt->param.sidr_req_rcvd);
351 uvt->data_len = IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE;
352
353 break;
354 case IB_CM_SIDR_REP_RECEIVED:
355 ib_ucm_event_sidr_rep_get(&uvt->resp.u.sidr_rep_resp,
356 &evt->param.sidr_rep_rcvd);
357 uvt->data_len = IB_CM_SIDR_REP_PRIVATE_DATA_SIZE;
358 uvt->info_len = evt->param.sidr_rep_rcvd.info_len;
359 info = evt->param.sidr_rep_rcvd.info;
360
361 break;
362 default:
363 uvt->resp.u.send_status = evt->param.send_status;
364
365 break;
366 }
367
368 if (uvt->data_len && evt->private_data) {
369
370 uvt->data = kmalloc(uvt->data_len, GFP_KERNEL);
371 if (!uvt->data) {
372 result = -ENOMEM;
373 goto error;
374 }
375
376 memcpy(uvt->data, evt->private_data, uvt->data_len);
377 uvt->resp.present |= IB_UCM_PRES_DATA;
378 }
379
380 if (uvt->info_len && info) {
381
382 uvt->info = kmalloc(uvt->info_len, GFP_KERNEL);
383 if (!uvt->info) {
384 result = -ENOMEM;
385 goto error;
386 }
387
388 memcpy(uvt->info, info, uvt->info_len);
389 uvt->resp.present |= IB_UCM_PRES_INFO;
390 }
391
392 return 0;
393error:
394 kfree(uvt->info);
395 kfree(uvt->data);
396 return result;
397}
398
399static int ib_ucm_event_handler(struct ib_cm_id *cm_id,
400 struct ib_cm_event *event)
401{
402 struct ib_ucm_event *uevent;
403 struct ib_ucm_context *ctx;
404 int result = 0;
405 int id;
406 /*
407 * lookup correct context based on event type.
408 */
409 switch (event->event) {
410 case IB_CM_REQ_RECEIVED:
411 id = (long)event->param.req_rcvd.listen_id->context;
412 break;
413 case IB_CM_SIDR_REQ_RECEIVED:
414 id = (long)event->param.sidr_req_rcvd.listen_id->context;
415 break;
416 default:
417 id = (long)cm_id->context;
418 break;
419 }
420
421 ucm_dbg("Event. CM ID <%d> event <%d>\n", id, event->event);
422
423 ctx = ib_ucm_ctx_get(id);
424 if (!ctx)
425 return -ENOENT;
426
427 if (event->event == IB_CM_REQ_RECEIVED ||
428 event->event == IB_CM_SIDR_REQ_RECEIVED)
429 id = IB_UCM_CM_ID_INVALID;
430
431 uevent = kmalloc(sizeof(*uevent), GFP_KERNEL);
432 if (!uevent) {
433 result = -ENOMEM;
434 goto done;
435 }
436
437 memset(uevent, 0, sizeof(*uevent));
438
439 uevent->resp.id = id;
440 uevent->resp.event = event->event;
441
442 result = ib_ucm_event_process(event, uevent);
443 if (result)
444 goto done;
445
446 uevent->ctx = ctx;
447 uevent->cm_id = ((event->event == IB_CM_REQ_RECEIVED ||
448 event->event == IB_CM_SIDR_REQ_RECEIVED ) ?
449 cm_id : NULL);
450
451 down(&ctx->file->mutex);
452
453 list_add_tail(&uevent->file_list, &ctx->file->events);
454 list_add_tail(&uevent->ctx_list, &ctx->events);
455
456 wake_up_interruptible(&ctx->file->poll_wait);
457
458 up(&ctx->file->mutex);
459done:
460 ctx->error = result;
461 ib_ucm_ctx_put(ctx); /* func reference */
462 return result;
463}
464
465static ssize_t ib_ucm_event(struct ib_ucm_file *file,
466 const char __user *inbuf,
467 int in_len, int out_len)
468{
469 struct ib_ucm_context *ctx;
470 struct ib_ucm_event_get cmd;
471 struct ib_ucm_event *uevent = NULL;
472 int result = 0;
473 DEFINE_WAIT(wait);
474
475 if (out_len < sizeof(struct ib_ucm_event_resp))
476 return -ENOSPC;
477
478 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
479 return -EFAULT;
480 /*
481 * wait
482 */
483 down(&file->mutex);
484
485 while (list_empty(&file->events)) {
486
487 if (file->filp->f_flags & O_NONBLOCK) {
488 result = -EAGAIN;
489 break;
490 }
491
492 if (signal_pending(current)) {
493 result = -ERESTARTSYS;
494 break;
495 }
496
497 prepare_to_wait(&file->poll_wait, &wait, TASK_INTERRUPTIBLE);
498
499 up(&file->mutex);
500 schedule();
501 down(&file->mutex);
502
503 finish_wait(&file->poll_wait, &wait);
504 }
505
506 if (result)
507 goto done;
508
509 uevent = list_entry(file->events.next, struct ib_ucm_event, file_list);
510
511 if (!uevent->cm_id)
512 goto user;
513
514 ctx = ib_ucm_ctx_alloc(file);
515 if (!ctx) {
516 result = -ENOMEM;
517 goto done;
518 }
519
520 ctx->cm_id = uevent->cm_id;
521 ctx->cm_id->cm_handler = ib_ucm_event_handler;
522 ctx->cm_id->context = (void *)(unsigned long)ctx->id;
523
524 uevent->resp.id = ctx->id;
525
526user:
527 if (copy_to_user((void __user *)(unsigned long)cmd.response,
528 &uevent->resp, sizeof(uevent->resp))) {
529 result = -EFAULT;
530 goto done;
531 }
532
533 if (uevent->data) {
534
535 if (cmd.data_len < uevent->data_len) {
536 result = -ENOMEM;
537 goto done;
538 }
539
540 if (copy_to_user((void __user *)(unsigned long)cmd.data,
541 uevent->data, uevent->data_len)) {
542 result = -EFAULT;
543 goto done;
544 }
545 }
546
547 if (uevent->info) {
548
549 if (cmd.info_len < uevent->info_len) {
550 result = -ENOMEM;
551 goto done;
552 }
553
554 if (copy_to_user((void __user *)(unsigned long)cmd.info,
555 uevent->info, uevent->info_len)) {
556 result = -EFAULT;
557 goto done;
558 }
559 }
560
561 list_del(&uevent->file_list);
562 list_del(&uevent->ctx_list);
563
564 kfree(uevent->data);
565 kfree(uevent->info);
566 kfree(uevent);
567done:
568 up(&file->mutex);
569 return result;
570}
571
572
573static ssize_t ib_ucm_create_id(struct ib_ucm_file *file,
574 const char __user *inbuf,
575 int in_len, int out_len)
576{
577 struct ib_ucm_create_id cmd;
578 struct ib_ucm_create_id_resp resp;
579 struct ib_ucm_context *ctx;
580 int result;
581
582 if (out_len < sizeof(resp))
583 return -ENOSPC;
584
585 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
586 return -EFAULT;
587
588 ctx = ib_ucm_ctx_alloc(file);
589 if (!ctx)
590 return -ENOMEM;
591
592 ctx->cm_id = ib_create_cm_id(ib_ucm_event_handler,
593 (void *)(unsigned long)ctx->id);
594 if (!ctx->cm_id) {
595 result = -ENOMEM;
596 goto err_cm;
597 }
598
599 resp.id = ctx->id;
600 if (copy_to_user((void __user *)(unsigned long)cmd.response,
601 &resp, sizeof(resp))) {
602 result = -EFAULT;
603 goto err_ret;
604 }
605
606 return 0;
607err_ret:
608 ib_destroy_cm_id(ctx->cm_id);
609err_cm:
610 ib_ucm_ctx_put(ctx); /* user reference */
611
612 return result;
613}
614
615static ssize_t ib_ucm_destroy_id(struct ib_ucm_file *file,
616 const char __user *inbuf,
617 int in_len, int out_len)
618{
619 struct ib_ucm_destroy_id cmd;
620 struct ib_ucm_context *ctx;
621
622 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
623 return -EFAULT;
624
625 ctx = ib_ucm_ctx_get(cmd.id);
626 if (!ctx)
627 return -ENOENT;
628
629 ib_ucm_ctx_put(ctx); /* user reference */
630 ib_ucm_ctx_put(ctx); /* func reference */
631
632 return 0;
633}
634
635static ssize_t ib_ucm_attr_id(struct ib_ucm_file *file,
636 const char __user *inbuf,
637 int in_len, int out_len)
638{
639 struct ib_ucm_attr_id_resp resp;
640 struct ib_ucm_attr_id cmd;
641 struct ib_ucm_context *ctx;
642 int result = 0;
643
644 if (out_len < sizeof(resp))
645 return -ENOSPC;
646
647 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
648 return -EFAULT;
649
650 ctx = ib_ucm_ctx_get(cmd.id);
651 if (!ctx)
652 return -ENOENT;
653
654 down(&ctx->file->mutex);
655 if (ctx->file != file) {
656 result = -EINVAL;
657 goto done;
658 }
659
660 resp.service_id = ctx->cm_id->service_id;
661 resp.service_mask = ctx->cm_id->service_mask;
662 resp.local_id = ctx->cm_id->local_id;
663 resp.remote_id = ctx->cm_id->remote_id;
664
665 if (copy_to_user((void __user *)(unsigned long)cmd.response,
666 &resp, sizeof(resp)))
667 result = -EFAULT;
668
669done:
670 up(&ctx->file->mutex);
671 ib_ucm_ctx_put(ctx); /* func reference */
672 return result;
673}
674
675static ssize_t ib_ucm_listen(struct ib_ucm_file *file,
676 const char __user *inbuf,
677 int in_len, int out_len)
678{
679 struct ib_ucm_listen cmd;
680 struct ib_ucm_context *ctx;
681 int result;
682
683 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
684 return -EFAULT;
685
686 ctx = ib_ucm_ctx_get(cmd.id);
687 if (!ctx)
688 return -ENOENT;
689
690 down(&ctx->file->mutex);
691 if (ctx->file != file)
692 result = -EINVAL;
693 else
694 result = ib_cm_listen(ctx->cm_id, cmd.service_id,
695 cmd.service_mask);
696
697 up(&ctx->file->mutex);
698 ib_ucm_ctx_put(ctx); /* func reference */
699 return result;
700}
701
702static ssize_t ib_ucm_establish(struct ib_ucm_file *file,
703 const char __user *inbuf,
704 int in_len, int out_len)
705{
706 struct ib_ucm_establish cmd;
707 struct ib_ucm_context *ctx;
708 int result;
709
710 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
711 return -EFAULT;
712
713 ctx = ib_ucm_ctx_get(cmd.id);
714 if (!ctx)
715 return -ENOENT;
716
717 down(&ctx->file->mutex);
718 if (ctx->file != file)
719 result = -EINVAL;
720 else
721 result = ib_cm_establish(ctx->cm_id);
722
723 up(&ctx->file->mutex);
724 ib_ucm_ctx_put(ctx); /* func reference */
725 return result;
726}
727
728static int ib_ucm_alloc_data(const void **dest, u64 src, u32 len)
729{
730 void *data;
731
732 *dest = NULL;
733
734 if (!len)
735 return 0;
736
737 data = kmalloc(len, GFP_KERNEL);
738 if (!data)
739 return -ENOMEM;
740
741 if (copy_from_user(data, (void __user *)(unsigned long)src, len)) {
742 kfree(data);
743 return -EFAULT;
744 }
745
746 *dest = data;
747 return 0;
748}
749
750static int ib_ucm_path_get(struct ib_sa_path_rec **path, u64 src)
751{
752 struct ib_ucm_path_rec ucm_path;
753 struct ib_sa_path_rec *sa_path;
754
755 *path = NULL;
756
757 if (!src)
758 return 0;
759
760 sa_path = kmalloc(sizeof(*sa_path), GFP_KERNEL);
761 if (!sa_path)
762 return -ENOMEM;
763
764 if (copy_from_user(&ucm_path, (void __user *)(unsigned long)src,
765 sizeof(ucm_path))) {
766
767 kfree(sa_path);
768 return -EFAULT;
769 }
770
771 memcpy(sa_path->dgid.raw, ucm_path.dgid, sizeof(union ib_gid));
772 memcpy(sa_path->sgid.raw, ucm_path.sgid, sizeof(union ib_gid));
773
774 sa_path->dlid = ucm_path.dlid;
775 sa_path->slid = ucm_path.slid;
776 sa_path->raw_traffic = ucm_path.raw_traffic;
777 sa_path->flow_label = ucm_path.flow_label;
778 sa_path->hop_limit = ucm_path.hop_limit;
779 sa_path->traffic_class = ucm_path.traffic_class;
780 sa_path->reversible = ucm_path.reversible;
781 sa_path->numb_path = ucm_path.numb_path;
782 sa_path->pkey = ucm_path.pkey;
783 sa_path->sl = ucm_path.sl;
784 sa_path->mtu_selector = ucm_path.mtu_selector;
785 sa_path->mtu = ucm_path.mtu;
786 sa_path->rate_selector = ucm_path.rate_selector;
787 sa_path->rate = ucm_path.rate;
788 sa_path->packet_life_time = ucm_path.packet_life_time;
789 sa_path->preference = ucm_path.preference;
790
791 sa_path->packet_life_time_selector =
792 ucm_path.packet_life_time_selector;
793
794 *path = sa_path;
795 return 0;
796}
797
798static ssize_t ib_ucm_send_req(struct ib_ucm_file *file,
799 const char __user *inbuf,
800 int in_len, int out_len)
801{
802 struct ib_cm_req_param param;
803 struct ib_ucm_context *ctx;
804 struct ib_ucm_req cmd;
805 int result;
806
807 param.private_data = NULL;
808 param.primary_path = NULL;
809 param.alternate_path = NULL;
810
811 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
812 return -EFAULT;
813
814 result = ib_ucm_alloc_data(&param.private_data, cmd.data, cmd.len);
815 if (result)
816 goto done;
817
818 result = ib_ucm_path_get(&param.primary_path, cmd.primary_path);
819 if (result)
820 goto done;
821
822 result = ib_ucm_path_get(&param.alternate_path, cmd.alternate_path);
823 if (result)
824 goto done;
825
826 param.private_data_len = cmd.len;
827 param.service_id = cmd.sid;
828 param.qp_num = cmd.qpn;
829 param.qp_type = cmd.qp_type;
830 param.starting_psn = cmd.psn;
831 param.peer_to_peer = cmd.peer_to_peer;
832 param.responder_resources = cmd.responder_resources;
833 param.initiator_depth = cmd.initiator_depth;
834 param.remote_cm_response_timeout = cmd.remote_cm_response_timeout;
835 param.flow_control = cmd.flow_control;
836 param.local_cm_response_timeout = cmd.local_cm_response_timeout;
837 param.retry_count = cmd.retry_count;
838 param.rnr_retry_count = cmd.rnr_retry_count;
839 param.max_cm_retries = cmd.max_cm_retries;
840 param.srq = cmd.srq;
841
842 ctx = ib_ucm_ctx_get(cmd.id);
843 if (!ctx) {
844 result = -ENOENT;
845 goto done;
846 }
847
848 down(&ctx->file->mutex);
849 if (ctx->file != file)
850 result = -EINVAL;
851 else
852 result = ib_send_cm_req(ctx->cm_id, &param);
853
854 up(&ctx->file->mutex);
855 ib_ucm_ctx_put(ctx); /* func reference */
856done:
857 kfree(param.private_data);
858 kfree(param.primary_path);
859 kfree(param.alternate_path);
860
861 return result;
862}
863
864static ssize_t ib_ucm_send_rep(struct ib_ucm_file *file,
865 const char __user *inbuf,
866 int in_len, int out_len)
867{
868 struct ib_cm_rep_param param;
869 struct ib_ucm_context *ctx;
870 struct ib_ucm_rep cmd;
871 int result;
872
873 param.private_data = NULL;
874
875 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
876 return -EFAULT;
877
878 result = ib_ucm_alloc_data(&param.private_data, cmd.data, cmd.len);
879 if (result)
880 return result;
881
882 param.qp_num = cmd.qpn;
883 param.starting_psn = cmd.psn;
884 param.private_data_len = cmd.len;
885 param.responder_resources = cmd.responder_resources;
886 param.initiator_depth = cmd.initiator_depth;
887 param.target_ack_delay = cmd.target_ack_delay;
888 param.failover_accepted = cmd.failover_accepted;
889 param.flow_control = cmd.flow_control;
890 param.rnr_retry_count = cmd.rnr_retry_count;
891 param.srq = cmd.srq;
892
893 ctx = ib_ucm_ctx_get(cmd.id);
894 if (!ctx) {
895 result = -ENOENT;
896 goto done;
897 }
898
899 down(&ctx->file->mutex);
900 if (ctx->file != file)
901 result = -EINVAL;
902 else
903 result = ib_send_cm_rep(ctx->cm_id, &param);
904
905 up(&ctx->file->mutex);
906 ib_ucm_ctx_put(ctx); /* func reference */
907done:
908 kfree(param.private_data);
909
910 return result;
911}
912
913static ssize_t ib_ucm_send_private_data(struct ib_ucm_file *file,
914 const char __user *inbuf, int in_len,
915 int (*func)(struct ib_cm_id *cm_id,
916 const void *private_data,
917 u8 private_data_len))
918{
919 struct ib_ucm_private_data cmd;
920 struct ib_ucm_context *ctx;
921 const void *private_data = NULL;
922 int result;
923
924 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
925 return -EFAULT;
926
927 result = ib_ucm_alloc_data(&private_data, cmd.data, cmd.len);
928 if (result)
929 return result;
930
931 ctx = ib_ucm_ctx_get(cmd.id);
932 if (!ctx) {
933 result = -ENOENT;
934 goto done;
935 }
936
937 down(&ctx->file->mutex);
938 if (ctx->file != file)
939 result = -EINVAL;
940 else
941 result = func(ctx->cm_id, private_data, cmd.len);
942
943 up(&ctx->file->mutex);
944 ib_ucm_ctx_put(ctx); /* func reference */
945done:
946 kfree(private_data);
947
948 return result;
949}
950
951static ssize_t ib_ucm_send_rtu(struct ib_ucm_file *file,
952 const char __user *inbuf,
953 int in_len, int out_len)
954{
955 return ib_ucm_send_private_data(file, inbuf, in_len, ib_send_cm_rtu);
956}
957
958static ssize_t ib_ucm_send_dreq(struct ib_ucm_file *file,
959 const char __user *inbuf,
960 int in_len, int out_len)
961{
962 return ib_ucm_send_private_data(file, inbuf, in_len, ib_send_cm_dreq);
963}
964
965static ssize_t ib_ucm_send_drep(struct ib_ucm_file *file,
966 const char __user *inbuf,
967 int in_len, int out_len)
968{
969 return ib_ucm_send_private_data(file, inbuf, in_len, ib_send_cm_drep);
970}
971
972static ssize_t ib_ucm_send_info(struct ib_ucm_file *file,
973 const char __user *inbuf, int in_len,
974 int (*func)(struct ib_cm_id *cm_id,
975 int status,
976 const void *info,
977 u8 info_len,
978 const void *data,
979 u8 data_len))
980{
981 struct ib_ucm_context *ctx;
982 struct ib_ucm_info cmd;
983 const void *data = NULL;
984 const void *info = NULL;
985 int result;
986
987 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
988 return -EFAULT;
989
990 result = ib_ucm_alloc_data(&data, cmd.data, cmd.data_len);
991 if (result)
992 goto done;
993
994 result = ib_ucm_alloc_data(&info, cmd.info, cmd.info_len);
995 if (result)
996 goto done;
997
998 ctx = ib_ucm_ctx_get(cmd.id);
999 if (!ctx) {
1000 result = -ENOENT;
1001 goto done;
1002 }
1003
1004 down(&ctx->file->mutex);
1005 if (ctx->file != file)
1006 result = -EINVAL;
1007 else
1008 result = func(ctx->cm_id, cmd.status,
1009 info, cmd.info_len,
1010 data, cmd.data_len);
1011
1012 up(&ctx->file->mutex);
1013 ib_ucm_ctx_put(ctx); /* func reference */
1014done:
1015 kfree(data);
1016 kfree(info);
1017
1018 return result;
1019}
1020
1021static ssize_t ib_ucm_send_rej(struct ib_ucm_file *file,
1022 const char __user *inbuf,
1023 int in_len, int out_len)
1024{
1025 return ib_ucm_send_info(file, inbuf, in_len, (void *)ib_send_cm_rej);
1026}
1027
1028static ssize_t ib_ucm_send_apr(struct ib_ucm_file *file,
1029 const char __user *inbuf,
1030 int in_len, int out_len)
1031{
1032 return ib_ucm_send_info(file, inbuf, in_len, (void *)ib_send_cm_apr);
1033}
1034
1035static ssize_t ib_ucm_send_mra(struct ib_ucm_file *file,
1036 const char __user *inbuf,
1037 int in_len, int out_len)
1038{
1039 struct ib_ucm_context *ctx;
1040 struct ib_ucm_mra cmd;
1041 const void *data = NULL;
1042 int result;
1043
1044 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
1045 return -EFAULT;
1046
1047 result = ib_ucm_alloc_data(&data, cmd.data, cmd.len);
1048 if (result)
1049 return result;
1050
1051 ctx = ib_ucm_ctx_get(cmd.id);
1052 if (!ctx) {
1053 result = -ENOENT;
1054 goto done;
1055 }
1056
1057 down(&ctx->file->mutex);
1058 if (ctx->file != file)
1059 result = -EINVAL;
1060 else
1061 result = ib_send_cm_mra(ctx->cm_id, cmd.timeout,
1062 data, cmd.len);
1063
1064 up(&ctx->file->mutex);
1065 ib_ucm_ctx_put(ctx); /* func reference */
1066done:
1067 kfree(data);
1068
1069 return result;
1070}
1071
1072static ssize_t ib_ucm_send_lap(struct ib_ucm_file *file,
1073 const char __user *inbuf,
1074 int in_len, int out_len)
1075{
1076 struct ib_ucm_context *ctx;
1077 struct ib_sa_path_rec *path = NULL;
1078 struct ib_ucm_lap cmd;
1079 const void *data = NULL;
1080 int result;
1081
1082 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
1083 return -EFAULT;
1084
1085 result = ib_ucm_alloc_data(&data, cmd.data, cmd.len);
1086 if (result)
1087 goto done;
1088
1089 result = ib_ucm_path_get(&path, cmd.path);
1090 if (result)
1091 goto done;
1092
1093 ctx = ib_ucm_ctx_get(cmd.id);
1094 if (!ctx) {
1095 result = -ENOENT;
1096 goto done;
1097 }
1098
1099 down(&ctx->file->mutex);
1100 if (ctx->file != file)
1101 result = -EINVAL;
1102 else
1103 result = ib_send_cm_lap(ctx->cm_id, path, data, cmd.len);
1104
1105 up(&ctx->file->mutex);
1106 ib_ucm_ctx_put(ctx); /* func reference */
1107done:
1108 kfree(data);
1109 kfree(path);
1110
1111 return result;
1112}
1113
1114static ssize_t ib_ucm_send_sidr_req(struct ib_ucm_file *file,
1115 const char __user *inbuf,
1116 int in_len, int out_len)
1117{
1118 struct ib_cm_sidr_req_param param;
1119 struct ib_ucm_context *ctx;
1120 struct ib_ucm_sidr_req cmd;
1121 int result;
1122
1123 param.private_data = NULL;
1124 param.path = NULL;
1125
1126 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
1127 return -EFAULT;
1128
1129 result = ib_ucm_alloc_data(&param.private_data, cmd.data, cmd.len);
1130 if (result)
1131 goto done;
1132
1133 result = ib_ucm_path_get(&param.path, cmd.path);
1134 if (result)
1135 goto done;
1136
1137 param.private_data_len = cmd.len;
1138 param.service_id = cmd.sid;
1139 param.timeout_ms = cmd.timeout;
1140 param.max_cm_retries = cmd.max_cm_retries;
1141 param.pkey = cmd.pkey;
1142
1143 ctx = ib_ucm_ctx_get(cmd.id);
1144 if (!ctx) {
1145 result = -ENOENT;
1146 goto done;
1147 }
1148
1149 down(&ctx->file->mutex);
1150 if (ctx->file != file)
1151 result = -EINVAL;
1152 else
1153 result = ib_send_cm_sidr_req(ctx->cm_id, &param);
1154
1155 up(&ctx->file->mutex);
1156 ib_ucm_ctx_put(ctx); /* func reference */
1157done:
1158 kfree(param.private_data);
1159 kfree(param.path);
1160
1161 return result;
1162}
1163
1164static ssize_t ib_ucm_send_sidr_rep(struct ib_ucm_file *file,
1165 const char __user *inbuf,
1166 int in_len, int out_len)
1167{
1168 struct ib_cm_sidr_rep_param param;
1169 struct ib_ucm_sidr_rep cmd;
1170 struct ib_ucm_context *ctx;
1171 int result;
1172
1173 param.info = NULL;
1174
1175 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
1176 return -EFAULT;
1177
1178 result = ib_ucm_alloc_data(&param.private_data,
1179 cmd.data, cmd.data_len);
1180 if (result)
1181 goto done;
1182
1183 result = ib_ucm_alloc_data(&param.info, cmd.info, cmd.info_len);
1184 if (result)
1185 goto done;
1186
1187 param.qp_num = cmd.qpn;
1188 param.qkey = cmd.qkey;
1189 param.status = cmd.status;
1190 param.info_length = cmd.info_len;
1191 param.private_data_len = cmd.data_len;
1192
1193 ctx = ib_ucm_ctx_get(cmd.id);
1194 if (!ctx) {
1195 result = -ENOENT;
1196 goto done;
1197 }
1198
1199 down(&ctx->file->mutex);
1200 if (ctx->file != file)
1201 result = -EINVAL;
1202 else
1203 result = ib_send_cm_sidr_rep(ctx->cm_id, &param);
1204
1205 up(&ctx->file->mutex);
1206 ib_ucm_ctx_put(ctx); /* func reference */
1207done:
1208 kfree(param.private_data);
1209 kfree(param.info);
1210
1211 return result;
1212}
1213
1214static ssize_t (*ucm_cmd_table[])(struct ib_ucm_file *file,
1215 const char __user *inbuf,
1216 int in_len, int out_len) = {
1217 [IB_USER_CM_CMD_CREATE_ID] = ib_ucm_create_id,
1218 [IB_USER_CM_CMD_DESTROY_ID] = ib_ucm_destroy_id,
1219 [IB_USER_CM_CMD_ATTR_ID] = ib_ucm_attr_id,
1220 [IB_USER_CM_CMD_LISTEN] = ib_ucm_listen,
1221 [IB_USER_CM_CMD_ESTABLISH] = ib_ucm_establish,
1222 [IB_USER_CM_CMD_SEND_REQ] = ib_ucm_send_req,
1223 [IB_USER_CM_CMD_SEND_REP] = ib_ucm_send_rep,
1224 [IB_USER_CM_CMD_SEND_RTU] = ib_ucm_send_rtu,
1225 [IB_USER_CM_CMD_SEND_DREQ] = ib_ucm_send_dreq,
1226 [IB_USER_CM_CMD_SEND_DREP] = ib_ucm_send_drep,
1227 [IB_USER_CM_CMD_SEND_REJ] = ib_ucm_send_rej,
1228 [IB_USER_CM_CMD_SEND_MRA] = ib_ucm_send_mra,
1229 [IB_USER_CM_CMD_SEND_LAP] = ib_ucm_send_lap,
1230 [IB_USER_CM_CMD_SEND_APR] = ib_ucm_send_apr,
1231 [IB_USER_CM_CMD_SEND_SIDR_REQ] = ib_ucm_send_sidr_req,
1232 [IB_USER_CM_CMD_SEND_SIDR_REP] = ib_ucm_send_sidr_rep,
1233 [IB_USER_CM_CMD_EVENT] = ib_ucm_event,
1234};
1235
1236static ssize_t ib_ucm_write(struct file *filp, const char __user *buf,
1237 size_t len, loff_t *pos)
1238{
1239 struct ib_ucm_file *file = filp->private_data;
1240 struct ib_ucm_cmd_hdr hdr;
1241 ssize_t result;
1242
1243 if (len < sizeof(hdr))
1244 return -EINVAL;
1245
1246 if (copy_from_user(&hdr, buf, sizeof(hdr)))
1247 return -EFAULT;
1248
1249 ucm_dbg("Write. cmd <%d> in <%d> out <%d> len <%Zu>\n",
1250 hdr.cmd, hdr.in, hdr.out, len);
1251
1252 if (hdr.cmd < 0 || hdr.cmd >= ARRAY_SIZE(ucm_cmd_table))
1253 return -EINVAL;
1254
1255 if (hdr.in + sizeof(hdr) > len)
1256 return -EINVAL;
1257
1258 result = ucm_cmd_table[hdr.cmd](file, buf + sizeof(hdr),
1259 hdr.in, hdr.out);
1260 if (!result)
1261 result = len;
1262
1263 return result;
1264}
1265
1266static unsigned int ib_ucm_poll(struct file *filp,
1267 struct poll_table_struct *wait)
1268{
1269 struct ib_ucm_file *file = filp->private_data;
1270 unsigned int mask = 0;
1271
1272 poll_wait(filp, &file->poll_wait, wait);
1273
1274 if (!list_empty(&file->events))
1275 mask = POLLIN | POLLRDNORM;
1276
1277 return mask;
1278}
1279
1280static int ib_ucm_open(struct inode *inode, struct file *filp)
1281{
1282 struct ib_ucm_file *file;
1283
1284 file = kmalloc(sizeof(*file), GFP_KERNEL);
1285 if (!file)
1286 return -ENOMEM;
1287
1288 INIT_LIST_HEAD(&file->events);
1289 INIT_LIST_HEAD(&file->ctxs);
1290 init_waitqueue_head(&file->poll_wait);
1291
1292 init_MUTEX(&file->mutex);
1293
1294 filp->private_data = file;
1295 file->filp = filp;
1296
1297 ucm_dbg("Created struct\n");
1298
1299 return 0;
1300}
1301
1302static int ib_ucm_close(struct inode *inode, struct file *filp)
1303{
1304 struct ib_ucm_file *file = filp->private_data;
1305 struct ib_ucm_context *ctx;
1306
1307 down(&file->mutex);
1308
1309 while (!list_empty(&file->ctxs)) {
1310
1311 ctx = list_entry(file->ctxs.next,
1312 struct ib_ucm_context, file_list);
1313
1314 up(&ctx->file->mutex);
1315 ib_ucm_ctx_put(ctx); /* user reference */
1316 down(&file->mutex);
1317 }
1318
1319 up(&file->mutex);
1320
1321 kfree(file);
1322
1323 ucm_dbg("Deleted struct\n");
1324 return 0;
1325}
1326
1327static struct file_operations ib_ucm_fops = {
1328 .owner = THIS_MODULE,
1329 .open = ib_ucm_open,
1330 .release = ib_ucm_close,
1331 .write = ib_ucm_write,
1332 .poll = ib_ucm_poll,
1333};
1334
1335
1336static struct class *ib_ucm_class;
1337static struct cdev ib_ucm_cdev;
1338
1339static int __init ib_ucm_init(void)
1340{
1341 int result;
1342
1343 result = register_chrdev_region(IB_UCM_DEV, 1, "infiniband_cm");
1344 if (result) {
1345 ucm_dbg("Error <%d> registering dev\n", result);
1346 goto err_chr;
1347 }
1348
1349 cdev_init(&ib_ucm_cdev, &ib_ucm_fops);
1350
1351 result = cdev_add(&ib_ucm_cdev, IB_UCM_DEV, 1);
1352 if (result) {
1353 ucm_dbg("Error <%d> adding cdev\n", result);
1354 goto err_cdev;
1355 }
1356
1357 ib_ucm_class = class_create(THIS_MODULE, "infiniband_cm");
1358 if (IS_ERR(ib_ucm_class)) {
1359 result = PTR_ERR(ib_ucm_class);
1360 ucm_dbg("Error <%d> creating class\n", result);
1361 goto err_class;
1362 }
1363
1364 class_device_create(ib_ucm_class, IB_UCM_DEV, NULL, "ucm");
1365
1366 idr_init(&ctx_id_table);
1367 init_MUTEX(&ctx_id_mutex);
1368
1369 return 0;
1370err_class:
1371 cdev_del(&ib_ucm_cdev);
1372err_cdev:
1373 unregister_chrdev_region(IB_UCM_DEV, 1);
1374err_chr:
1375 return result;
1376}
1377
1378static void __exit ib_ucm_cleanup(void)
1379{
1380 class_device_destroy(ib_ucm_class, IB_UCM_DEV);
1381 class_destroy(ib_ucm_class);
1382 cdev_del(&ib_ucm_cdev);
1383 unregister_chrdev_region(IB_UCM_DEV, 1);
1384}
1385
1386module_init(ib_ucm_init);
1387module_exit(ib_ucm_cleanup);
diff --git a/drivers/infiniband/core/ucm.h b/drivers/infiniband/core/ucm.h
new file mode 100644
index 000000000000..6d36606151b2
--- /dev/null
+++ b/drivers/infiniband/core/ucm.h
@@ -0,0 +1,89 @@
1/*
2 * Copyright (c) 2005 Topspin Communications. 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: ucm.h 2208 2005-04-22 23:24:31Z libor $
33 */
34
35#ifndef UCM_H
36#define UCM_H
37
38#include <linux/fs.h>
39#include <linux/device.h>
40#include <linux/cdev.h>
41#include <linux/idr.h>
42
43#include <ib_cm.h>
44#include <ib_user_cm.h>
45
46#define IB_UCM_CM_ID_INVALID 0xffffffff
47
48struct ib_ucm_file {
49 struct semaphore mutex;
50 struct file *filp;
51 /*
52 * list of pending events
53 */
54 struct list_head ctxs; /* list of active connections */
55 struct list_head events; /* list of pending events */
56 wait_queue_head_t poll_wait;
57};
58
59struct ib_ucm_context {
60 int id;
61 int ref;
62 int error;
63
64 struct ib_ucm_file *file;
65 struct ib_cm_id *cm_id;
66 struct semaphore mutex;
67
68 struct list_head events; /* list of pending events. */
69 struct list_head file_list; /* member in file ctx list */
70};
71
72struct ib_ucm_event {
73 struct ib_ucm_context *ctx;
74 struct list_head file_list; /* member in file event list */
75 struct list_head ctx_list; /* member in ctx event list */
76
77 struct ib_ucm_event_resp resp;
78 void *data;
79 void *info;
80 int data_len;
81 int info_len;
82 /*
83 * new connection identifiers needs to be saved until
84 * userspace can get a handle on them.
85 */
86 struct ib_cm_id *cm_id;
87};
88
89#endif /* UCM_H */
diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c
index 9d912d6877ff..2e38792df533 100644
--- a/drivers/infiniband/core/user_mad.c
+++ b/drivers/infiniband/core/user_mad.c
@@ -1,5 +1,7 @@
1/* 1/*
2 * Copyright (c) 2004 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
4 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
3 * 5 *
4 * 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
5 * 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
@@ -29,7 +31,7 @@
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE. 32 * SOFTWARE.
31 * 33 *
32 * $Id: user_mad.c 1389 2004-12-27 22:56:47Z roland $ 34 * $Id: user_mad.c 2814 2005-07-06 19:14:09Z halr $
33 */ 35 */
34 36
35#include <linux/module.h> 37#include <linux/module.h>
@@ -94,10 +96,12 @@ struct ib_umad_file {
94}; 96};
95 97
96struct ib_umad_packet { 98struct ib_umad_packet {
97 struct ib_user_mad mad;
98 struct ib_ah *ah; 99 struct ib_ah *ah;
100 struct ib_mad_send_buf *msg;
99 struct list_head list; 101 struct list_head list;
102 int length;
100 DECLARE_PCI_UNMAP_ADDR(mapping) 103 DECLARE_PCI_UNMAP_ADDR(mapping)
104 struct ib_user_mad mad;
101}; 105};
102 106
103static const dev_t base_dev = MKDEV(IB_UMAD_MAJOR, IB_UMAD_MINOR_BASE); 107static const dev_t base_dev = MKDEV(IB_UMAD_MAJOR, IB_UMAD_MINOR_BASE);
@@ -114,10 +118,10 @@ static int queue_packet(struct ib_umad_file *file,
114 int ret = 1; 118 int ret = 1;
115 119
116 down_read(&file->agent_mutex); 120 down_read(&file->agent_mutex);
117 for (packet->mad.id = 0; 121 for (packet->mad.hdr.id = 0;
118 packet->mad.id < IB_UMAD_MAX_AGENTS; 122 packet->mad.hdr.id < IB_UMAD_MAX_AGENTS;
119 packet->mad.id++) 123 packet->mad.hdr.id++)
120 if (agent == file->agent[packet->mad.id]) { 124 if (agent == file->agent[packet->mad.hdr.id]) {
121 spin_lock_irq(&file->recv_lock); 125 spin_lock_irq(&file->recv_lock);
122 list_add_tail(&packet->list, &file->recv_list); 126 list_add_tail(&packet->list, &file->recv_list);
123 spin_unlock_irq(&file->recv_lock); 127 spin_unlock_irq(&file->recv_lock);
@@ -135,22 +139,30 @@ static void send_handler(struct ib_mad_agent *agent,
135 struct ib_mad_send_wc *send_wc) 139 struct ib_mad_send_wc *send_wc)
136{ 140{
137 struct ib_umad_file *file = agent->context; 141 struct ib_umad_file *file = agent->context;
138 struct ib_umad_packet *packet = 142 struct ib_umad_packet *timeout, *packet =
139 (void *) (unsigned long) send_wc->wr_id; 143 (void *) (unsigned long) send_wc->wr_id;
140 144
141 dma_unmap_single(agent->device->dma_device, 145 ib_destroy_ah(packet->msg->send_wr.wr.ud.ah);
142 pci_unmap_addr(packet, mapping), 146 ib_free_send_mad(packet->msg);
143 sizeof packet->mad.data,
144 DMA_TO_DEVICE);
145 ib_destroy_ah(packet->ah);
146 147
147 if (send_wc->status == IB_WC_RESP_TIMEOUT_ERR) { 148 if (send_wc->status == IB_WC_RESP_TIMEOUT_ERR) {
148 packet->mad.status = ETIMEDOUT; 149 timeout = kmalloc(sizeof *timeout + sizeof (struct ib_mad_hdr),
150 GFP_KERNEL);
151 if (!timeout)
152 goto out;
149 153
150 if (!queue_packet(file, agent, packet)) 154 memset(timeout, 0, sizeof *timeout + sizeof (struct ib_mad_hdr));
151 return;
152 }
153 155
156 timeout->length = sizeof (struct ib_mad_hdr);
157 timeout->mad.hdr.id = packet->mad.hdr.id;
158 timeout->mad.hdr.status = ETIMEDOUT;
159 memcpy(timeout->mad.data, packet->mad.data,
160 sizeof (struct ib_mad_hdr));
161
162 if (!queue_packet(file, agent, timeout))
163 return;
164 }
165out:
154 kfree(packet); 166 kfree(packet);
155} 167}
156 168
@@ -159,30 +171,35 @@ static void recv_handler(struct ib_mad_agent *agent,
159{ 171{
160 struct ib_umad_file *file = agent->context; 172 struct ib_umad_file *file = agent->context;
161 struct ib_umad_packet *packet; 173 struct ib_umad_packet *packet;
174 int length;
162 175
163 if (mad_recv_wc->wc->status != IB_WC_SUCCESS) 176 if (mad_recv_wc->wc->status != IB_WC_SUCCESS)
164 goto out; 177 goto out;
165 178
166 packet = kmalloc(sizeof *packet, GFP_KERNEL); 179 length = mad_recv_wc->mad_len;
180 packet = kmalloc(sizeof *packet + length, GFP_KERNEL);
167 if (!packet) 181 if (!packet)
168 goto out; 182 goto out;
169 183
170 memset(packet, 0, sizeof *packet); 184 memset(packet, 0, sizeof *packet + length);
185 packet->length = length;
186
187 ib_coalesce_recv_mad(mad_recv_wc, packet->mad.data);
171 188
172 memcpy(packet->mad.data, mad_recv_wc->recv_buf.mad, sizeof packet->mad.data); 189 packet->mad.hdr.status = 0;
173 packet->mad.status = 0; 190 packet->mad.hdr.length = length + sizeof (struct ib_user_mad);
174 packet->mad.qpn = cpu_to_be32(mad_recv_wc->wc->src_qp); 191 packet->mad.hdr.qpn = cpu_to_be32(mad_recv_wc->wc->src_qp);
175 packet->mad.lid = cpu_to_be16(mad_recv_wc->wc->slid); 192 packet->mad.hdr.lid = cpu_to_be16(mad_recv_wc->wc->slid);
176 packet->mad.sl = mad_recv_wc->wc->sl; 193 packet->mad.hdr.sl = mad_recv_wc->wc->sl;
177 packet->mad.path_bits = mad_recv_wc->wc->dlid_path_bits; 194 packet->mad.hdr.path_bits = mad_recv_wc->wc->dlid_path_bits;
178 packet->mad.grh_present = !!(mad_recv_wc->wc->wc_flags & IB_WC_GRH); 195 packet->mad.hdr.grh_present = !!(mad_recv_wc->wc->wc_flags & IB_WC_GRH);
179 if (packet->mad.grh_present) { 196 if (packet->mad.hdr.grh_present) {
180 /* XXX parse GRH */ 197 /* XXX parse GRH */
181 packet->mad.gid_index = 0; 198 packet->mad.hdr.gid_index = 0;
182 packet->mad.hop_limit = 0; 199 packet->mad.hdr.hop_limit = 0;
183 packet->mad.traffic_class = 0; 200 packet->mad.hdr.traffic_class = 0;
184 memset(packet->mad.gid, 0, 16); 201 memset(packet->mad.hdr.gid, 0, 16);
185 packet->mad.flow_label = 0; 202 packet->mad.hdr.flow_label = 0;
186 } 203 }
187 204
188 if (queue_packet(file, agent, packet)) 205 if (queue_packet(file, agent, packet))
@@ -199,7 +216,7 @@ static ssize_t ib_umad_read(struct file *filp, char __user *buf,
199 struct ib_umad_packet *packet; 216 struct ib_umad_packet *packet;
200 ssize_t ret; 217 ssize_t ret;
201 218
202 if (count < sizeof (struct ib_user_mad)) 219 if (count < sizeof (struct ib_user_mad) + sizeof (struct ib_mad))
203 return -EINVAL; 220 return -EINVAL;
204 221
205 spin_lock_irq(&file->recv_lock); 222 spin_lock_irq(&file->recv_lock);
@@ -222,12 +239,25 @@ static ssize_t ib_umad_read(struct file *filp, char __user *buf,
222 239
223 spin_unlock_irq(&file->recv_lock); 240 spin_unlock_irq(&file->recv_lock);
224 241
225 if (copy_to_user(buf, &packet->mad, sizeof packet->mad)) 242 if (count < packet->length + sizeof (struct ib_user_mad)) {
243 /* Return length needed (and first RMPP segment) if too small */
244 if (copy_to_user(buf, &packet->mad,
245 sizeof (struct ib_user_mad) + sizeof (struct ib_mad)))
246 ret = -EFAULT;
247 else
248 ret = -ENOSPC;
249 } else if (copy_to_user(buf, &packet->mad,
250 packet->length + sizeof (struct ib_user_mad)))
226 ret = -EFAULT; 251 ret = -EFAULT;
227 else 252 else
228 ret = sizeof packet->mad; 253 ret = packet->length + sizeof (struct ib_user_mad);
229 254 if (ret < 0) {
230 kfree(packet); 255 /* Requeue packet */
256 spin_lock_irq(&file->recv_lock);
257 list_add(&packet->list, &file->recv_list);
258 spin_unlock_irq(&file->recv_lock);
259 } else
260 kfree(packet);
231 return ret; 261 return ret;
232} 262}
233 263
@@ -238,69 +268,57 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
238 struct ib_umad_packet *packet; 268 struct ib_umad_packet *packet;
239 struct ib_mad_agent *agent; 269 struct ib_mad_agent *agent;
240 struct ib_ah_attr ah_attr; 270 struct ib_ah_attr ah_attr;
241 struct ib_sge gather_list; 271 struct ib_send_wr *bad_wr;
242 struct ib_send_wr *bad_wr, wr = { 272 struct ib_rmpp_mad *rmpp_mad;
243 .opcode = IB_WR_SEND,
244 .sg_list = &gather_list,
245 .num_sge = 1,
246 .send_flags = IB_SEND_SIGNALED,
247 };
248 u8 method; 273 u8 method;
249 u64 *tid; 274 u64 *tid;
250 int ret; 275 int ret, length, hdr_len, data_len, rmpp_hdr_size;
276 int rmpp_active = 0;
251 277
252 if (count < sizeof (struct ib_user_mad)) 278 if (count < sizeof (struct ib_user_mad))
253 return -EINVAL; 279 return -EINVAL;
254 280
255 packet = kmalloc(sizeof *packet, GFP_KERNEL); 281 length = count - sizeof (struct ib_user_mad);
282 packet = kmalloc(sizeof *packet + sizeof(struct ib_mad_hdr) +
283 sizeof(struct ib_rmpp_hdr), GFP_KERNEL);
256 if (!packet) 284 if (!packet)
257 return -ENOMEM; 285 return -ENOMEM;
258 286
259 if (copy_from_user(&packet->mad, buf, sizeof packet->mad)) { 287 if (copy_from_user(&packet->mad, buf,
260 kfree(packet); 288 sizeof (struct ib_user_mad) +
261 return -EFAULT; 289 sizeof(struct ib_mad_hdr) +
290 sizeof(struct ib_rmpp_hdr))) {
291 ret = -EFAULT;
292 goto err;
262 } 293 }
263 294
264 if (packet->mad.id < 0 || packet->mad.id >= IB_UMAD_MAX_AGENTS) { 295 if (packet->mad.hdr.id < 0 ||
296 packet->mad.hdr.id >= IB_UMAD_MAX_AGENTS) {
265 ret = -EINVAL; 297 ret = -EINVAL;
266 goto err; 298 goto err;
267 } 299 }
268 300
301 packet->length = length;
302
269 down_read(&file->agent_mutex); 303 down_read(&file->agent_mutex);
270 304
271 agent = file->agent[packet->mad.id]; 305 agent = file->agent[packet->mad.hdr.id];
272 if (!agent) { 306 if (!agent) {
273 ret = -EINVAL; 307 ret = -EINVAL;
274 goto err_up; 308 goto err_up;
275 } 309 }
276 310
277 /*
278 * If userspace is generating a request that will generate a
279 * response, we need to make sure the high-order part of the
280 * transaction ID matches the agent being used to send the
281 * MAD.
282 */
283 method = ((struct ib_mad_hdr *) packet->mad.data)->method;
284
285 if (!(method & IB_MGMT_METHOD_RESP) &&
286 method != IB_MGMT_METHOD_TRAP_REPRESS &&
287 method != IB_MGMT_METHOD_SEND) {
288 tid = &((struct ib_mad_hdr *) packet->mad.data)->tid;
289 *tid = cpu_to_be64(((u64) agent->hi_tid) << 32 |
290 (be64_to_cpup(tid) & 0xffffffff));
291 }
292
293 memset(&ah_attr, 0, sizeof ah_attr); 311 memset(&ah_attr, 0, sizeof ah_attr);
294 ah_attr.dlid = be16_to_cpu(packet->mad.lid); 312 ah_attr.dlid = be16_to_cpu(packet->mad.hdr.lid);
295 ah_attr.sl = packet->mad.sl; 313 ah_attr.sl = packet->mad.hdr.sl;
296 ah_attr.src_path_bits = packet->mad.path_bits; 314 ah_attr.src_path_bits = packet->mad.hdr.path_bits;
297 ah_attr.port_num = file->port->port_num; 315 ah_attr.port_num = file->port->port_num;
298 if (packet->mad.grh_present) { 316 if (packet->mad.hdr.grh_present) {
299 ah_attr.ah_flags = IB_AH_GRH; 317 ah_attr.ah_flags = IB_AH_GRH;
300 memcpy(ah_attr.grh.dgid.raw, packet->mad.gid, 16); 318 memcpy(ah_attr.grh.dgid.raw, packet->mad.hdr.gid, 16);
301 ah_attr.grh.flow_label = packet->mad.flow_label; 319 ah_attr.grh.flow_label = packet->mad.hdr.flow_label;
302 ah_attr.grh.hop_limit = packet->mad.hop_limit; 320 ah_attr.grh.hop_limit = packet->mad.hdr.hop_limit;
303 ah_attr.grh.traffic_class = packet->mad.traffic_class; 321 ah_attr.grh.traffic_class = packet->mad.hdr.traffic_class;
304 } 322 }
305 323
306 packet->ah = ib_create_ah(agent->qp->pd, &ah_attr); 324 packet->ah = ib_create_ah(agent->qp->pd, &ah_attr);
@@ -309,34 +327,104 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
309 goto err_up; 327 goto err_up;
310 } 328 }
311 329
312 gather_list.addr = dma_map_single(agent->device->dma_device, 330 rmpp_mad = (struct ib_rmpp_mad *) packet->mad.data;
313 packet->mad.data, 331 if (ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) & IB_MGMT_RMPP_FLAG_ACTIVE) {
314 sizeof packet->mad.data, 332 /* RMPP active */
315 DMA_TO_DEVICE); 333 if (!agent->rmpp_version) {
316 gather_list.length = sizeof packet->mad.data; 334 ret = -EINVAL;
317 gather_list.lkey = file->mr[packet->mad.id]->lkey; 335 goto err_ah;
318 pci_unmap_addr_set(packet, mapping, gather_list.addr); 336 }
337 /* Validate that management class can support RMPP */
338 if (rmpp_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_ADM) {
339 hdr_len = offsetof(struct ib_sa_mad, data);
340 data_len = length;
341 } else if ((rmpp_mad->mad_hdr.mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START) &&
342 (rmpp_mad->mad_hdr.mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END)) {
343 hdr_len = offsetof(struct ib_vendor_mad, data);
344 data_len = length - hdr_len;
345 } else {
346 ret = -EINVAL;
347 goto err_ah;
348 }
349 rmpp_active = 1;
350 } else {
351 if (length > sizeof(struct ib_mad)) {
352 ret = -EINVAL;
353 goto err_ah;
354 }
355 hdr_len = offsetof(struct ib_mad, data);
356 data_len = length - hdr_len;
357 }
358
359 packet->msg = ib_create_send_mad(agent,
360 be32_to_cpu(packet->mad.hdr.qpn),
361 0, packet->ah, rmpp_active,
362 hdr_len, data_len,
363 GFP_KERNEL);
364 if (IS_ERR(packet->msg)) {
365 ret = PTR_ERR(packet->msg);
366 goto err_ah;
367 }
319 368
320 wr.wr.ud.mad_hdr = (struct ib_mad_hdr *) packet->mad.data; 369 packet->msg->send_wr.wr.ud.timeout_ms = packet->mad.hdr.timeout_ms;
321 wr.wr.ud.ah = packet->ah; 370 packet->msg->send_wr.wr.ud.retries = packet->mad.hdr.retries;
322 wr.wr.ud.remote_qpn = be32_to_cpu(packet->mad.qpn);
323 wr.wr.ud.remote_qkey = be32_to_cpu(packet->mad.qkey);
324 wr.wr.ud.timeout_ms = packet->mad.timeout_ms;
325 371
326 wr.wr_id = (unsigned long) packet; 372 /* Override send WR WRID initialized in ib_create_send_mad */
373 packet->msg->send_wr.wr_id = (unsigned long) packet;
327 374
328 ret = ib_post_send_mad(agent, &wr, &bad_wr); 375 if (!rmpp_active) {
329 if (ret) { 376 /* Copy message from user into send buffer */
330 dma_unmap_single(agent->device->dma_device, 377 if (copy_from_user(packet->msg->mad,
331 pci_unmap_addr(packet, mapping), 378 buf + sizeof(struct ib_user_mad), length)) {
332 sizeof packet->mad.data, 379 ret = -EFAULT;
333 DMA_TO_DEVICE); 380 goto err_msg;
334 goto err_up; 381 }
382 } else {
383 rmpp_hdr_size = sizeof(struct ib_mad_hdr) +
384 sizeof(struct ib_rmpp_hdr);
385
386 /* Only copy MAD headers (RMPP header in place) */
387 memcpy(packet->msg->mad, packet->mad.data,
388 sizeof(struct ib_mad_hdr));
389
390 /* Now, copy rest of message from user into send buffer */
391 if (copy_from_user(((struct ib_rmpp_mad *) packet->msg->mad)->data,
392 buf + sizeof (struct ib_user_mad) + rmpp_hdr_size,
393 length - rmpp_hdr_size)) {
394 ret = -EFAULT;
395 goto err_msg;
396 }
397 }
398
399 /*
400 * If userspace is generating a request that will generate a
401 * response, we need to make sure the high-order part of the
402 * transaction ID matches the agent being used to send the
403 * MAD.
404 */
405 method = packet->msg->mad->mad_hdr.method;
406
407 if (!(method & IB_MGMT_METHOD_RESP) &&
408 method != IB_MGMT_METHOD_TRAP_REPRESS &&
409 method != IB_MGMT_METHOD_SEND) {
410 tid = &packet->msg->mad->mad_hdr.tid;
411 *tid = cpu_to_be64(((u64) agent->hi_tid) << 32 |
412 (be64_to_cpup(tid) & 0xffffffff));
335 } 413 }
336 414
415 ret = ib_post_send_mad(agent, &packet->msg->send_wr, &bad_wr);
416 if (ret)
417 goto err_msg;
418
337 up_read(&file->agent_mutex); 419 up_read(&file->agent_mutex);
338 420
339 return sizeof packet->mad; 421 return sizeof (struct ib_user_mad_hdr) + packet->length;
422
423err_msg:
424 ib_free_send_mad(packet->msg);
425
426err_ah:
427 ib_destroy_ah(packet->ah);
340 428
341err_up: 429err_up:
342 up_read(&file->agent_mutex); 430 up_read(&file->agent_mutex);
@@ -399,7 +487,8 @@ found:
399 agent = ib_register_mad_agent(file->port->ib_dev, file->port->port_num, 487 agent = ib_register_mad_agent(file->port->ib_dev, file->port->port_num,
400 ureq.qpn ? IB_QPT_GSI : IB_QPT_SMI, 488 ureq.qpn ? IB_QPT_GSI : IB_QPT_SMI,
401 ureq.mgmt_class ? &req : NULL, 489 ureq.mgmt_class ? &req : NULL,
402 0, send_handler, recv_handler, file); 490 ureq.rmpp_version,
491 send_handler, recv_handler, file);
403 if (IS_ERR(agent)) { 492 if (IS_ERR(agent)) {
404 ret = PTR_ERR(agent); 493 ret = PTR_ERR(agent);
405 goto out; 494 goto out;
@@ -460,8 +549,8 @@ out:
460 return ret; 549 return ret;
461} 550}
462 551
463static long ib_umad_ioctl(struct file *filp, 552static long ib_umad_ioctl(struct file *filp, unsigned int cmd,
464 unsigned int cmd, unsigned long arg) 553 unsigned long arg)
465{ 554{
466 switch (cmd) { 555 switch (cmd) {
467 case IB_USER_MAD_REGISTER_AGENT: 556 case IB_USER_MAD_REGISTER_AGENT:
@@ -517,14 +606,14 @@ static int ib_umad_close(struct inode *inode, struct file *filp)
517} 606}
518 607
519static struct file_operations umad_fops = { 608static struct file_operations umad_fops = {
520 .owner = THIS_MODULE, 609 .owner = THIS_MODULE,
521 .read = ib_umad_read, 610 .read = ib_umad_read,
522 .write = ib_umad_write, 611 .write = ib_umad_write,
523 .poll = ib_umad_poll, 612 .poll = ib_umad_poll,
524 .unlocked_ioctl = ib_umad_ioctl, 613 .unlocked_ioctl = ib_umad_ioctl,
525 .compat_ioctl = ib_umad_ioctl, 614 .compat_ioctl = ib_umad_ioctl,
526 .open = ib_umad_open, 615 .open = ib_umad_open,
527 .release = ib_umad_close 616 .release = ib_umad_close
528}; 617};
529 618
530static int ib_umad_sm_open(struct inode *inode, struct file *filp) 619static int ib_umad_sm_open(struct inode *inode, struct file *filp)
diff --git a/drivers/infiniband/core/uverbs.h b/drivers/infiniband/core/uverbs.h
index 57347f1e82c1..7696022f9a4e 100644
--- a/drivers/infiniband/core/uverbs.h
+++ b/drivers/infiniband/core/uverbs.h
@@ -61,6 +61,7 @@ struct ib_uverbs_event_file {
61 int fd; 61 int fd;
62 int is_async; 62 int is_async;
63 wait_queue_head_t poll_wait; 63 wait_queue_head_t poll_wait;
64 struct fasync_struct *async_queue;
64 struct list_head event_list; 65 struct list_head event_list;
65}; 66};
66 67
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index fbbe03d8c901..eb99e693dec2 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -257,11 +257,19 @@ static void ib_uverbs_event_release(struct ib_uverbs_event_file *file)
257 spin_unlock_irq(&file->lock); 257 spin_unlock_irq(&file->lock);
258} 258}
259 259
260static int ib_uverbs_event_fasync(int fd, struct file *filp, int on)
261{
262 struct ib_uverbs_event_file *file = filp->private_data;
263
264 return fasync_helper(fd, filp, on, &file->async_queue);
265}
266
260static int ib_uverbs_event_close(struct inode *inode, struct file *filp) 267static int ib_uverbs_event_close(struct inode *inode, struct file *filp)
261{ 268{
262 struct ib_uverbs_event_file *file = filp->private_data; 269 struct ib_uverbs_event_file *file = filp->private_data;
263 270
264 ib_uverbs_event_release(file); 271 ib_uverbs_event_release(file);
272 ib_uverbs_event_fasync(-1, filp, 0);
265 kref_put(&file->uverbs_file->ref, ib_uverbs_release_file); 273 kref_put(&file->uverbs_file->ref, ib_uverbs_release_file);
266 274
267 return 0; 275 return 0;
@@ -276,7 +284,8 @@ static struct file_operations uverbs_event_fops = {
276 */ 284 */
277 .read = ib_uverbs_event_read, 285 .read = ib_uverbs_event_read,
278 .poll = ib_uverbs_event_poll, 286 .poll = ib_uverbs_event_poll,
279 .release = ib_uverbs_event_close 287 .release = ib_uverbs_event_close,
288 .fasync = ib_uverbs_event_fasync
280}; 289};
281 290
282void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context) 291void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context)
@@ -296,6 +305,7 @@ void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context)
296 spin_unlock_irqrestore(&file->comp_file[0].lock, flags); 305 spin_unlock_irqrestore(&file->comp_file[0].lock, flags);
297 306
298 wake_up_interruptible(&file->comp_file[0].poll_wait); 307 wake_up_interruptible(&file->comp_file[0].poll_wait);
308 kill_fasync(&file->comp_file[0].async_queue, SIGIO, POLL_IN);
299} 309}
300 310
301static void ib_uverbs_async_handler(struct ib_uverbs_file *file, 311static void ib_uverbs_async_handler(struct ib_uverbs_file *file,
@@ -316,6 +326,7 @@ static void ib_uverbs_async_handler(struct ib_uverbs_file *file,
316 spin_unlock_irqrestore(&file->async_file.lock, flags); 326 spin_unlock_irqrestore(&file->async_file.lock, flags);
317 327
318 wake_up_interruptible(&file->async_file.poll_wait); 328 wake_up_interruptible(&file->async_file.poll_wait);
329 kill_fasync(&file->async_file.async_queue, SIGIO, POLL_IN);
319} 330}
320 331
321void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr) 332void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr)
@@ -350,6 +361,7 @@ static int ib_uverbs_event_init(struct ib_uverbs_event_file *file,
350 INIT_LIST_HEAD(&file->event_list); 361 INIT_LIST_HEAD(&file->event_list);
351 init_waitqueue_head(&file->poll_wait); 362 init_waitqueue_head(&file->poll_wait);
352 file->uverbs_file = uverbs_file; 363 file->uverbs_file = uverbs_file;
364 file->async_queue = NULL;
353 365
354 file->fd = get_unused_fd(); 366 file->fd = get_unused_fd();
355 if (file->fd < 0) 367 if (file->fd < 0)
diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
index 2516f9646515..506fdf1f2a26 100644
--- a/drivers/infiniband/core/verbs.c
+++ b/drivers/infiniband/core/verbs.c
@@ -41,6 +41,7 @@
41#include <linux/err.h> 41#include <linux/err.h>
42 42
43#include <ib_verbs.h> 43#include <ib_verbs.h>
44#include <ib_cache.h>
44 45
45/* Protection domains */ 46/* Protection domains */
46 47
@@ -88,6 +89,40 @@ struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr)
88} 89}
89EXPORT_SYMBOL(ib_create_ah); 90EXPORT_SYMBOL(ib_create_ah);
90 91
92struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc,
93 struct ib_grh *grh, u8 port_num)
94{
95 struct ib_ah_attr ah_attr;
96 u32 flow_class;
97 u16 gid_index;
98 int ret;
99
100 memset(&ah_attr, 0, sizeof ah_attr);
101 ah_attr.dlid = wc->slid;
102 ah_attr.sl = wc->sl;
103 ah_attr.src_path_bits = wc->dlid_path_bits;
104 ah_attr.port_num = port_num;
105
106 if (wc->wc_flags & IB_WC_GRH) {
107 ah_attr.ah_flags = IB_AH_GRH;
108 ah_attr.grh.dgid = grh->dgid;
109
110 ret = ib_find_cached_gid(pd->device, &grh->sgid, &port_num,
111 &gid_index);
112 if (ret)
113 return ERR_PTR(ret);
114
115 ah_attr.grh.sgid_index = (u8) gid_index;
116 flow_class = be32_to_cpu(grh->version_tclass_flow);
117 ah_attr.grh.flow_label = flow_class & 0xFFFFF;
118 ah_attr.grh.traffic_class = (flow_class >> 20) & 0xFF;
119 ah_attr.grh.hop_limit = grh->hop_limit;
120 }
121
122 return ib_create_ah(pd, &ah_attr);
123}
124EXPORT_SYMBOL(ib_create_ah_from_wc);
125
91int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr) 126int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr)
92{ 127{
93 return ah->device->modify_ah ? 128 return ah->device->modify_ah ?
diff --git a/drivers/infiniband/hw/mthca/mthca_cq.c b/drivers/infiniband/hw/mthca/mthca_cq.c
index b5aea7b869f6..5687c3014522 100644
--- a/drivers/infiniband/hw/mthca/mthca_cq.c
+++ b/drivers/infiniband/hw/mthca/mthca_cq.c
@@ -373,8 +373,12 @@ static int handle_error_cqe(struct mthca_dev *dev, struct mthca_cq *cq,
373 * If we're at the end of the WQE chain, or we've used up our 373 * If we're at the end of the WQE chain, or we've used up our
374 * doorbell count, free the CQE. Otherwise just update it for 374 * doorbell count, free the CQE. Otherwise just update it for
375 * the next poll operation. 375 * the next poll operation.
376 *
377 * This does not apply to mem-free HCAs: they don't use the
378 * doorbell count field, and so we should always free the CQE.
376 */ 379 */
377 if (!(new_wqe & cpu_to_be32(0x3f)) || (!cqe->db_cnt && dbd)) 380 if (mthca_is_memfree(dev) ||
381 !(new_wqe & cpu_to_be32(0x3f)) || (!cqe->db_cnt && dbd))
378 return 0; 382 return 0;
379 383
380 cqe->db_cnt = cpu_to_be16(be16_to_cpu(cqe->db_cnt) - dbd); 384 cqe->db_cnt = cpu_to_be16(be16_to_cpu(cqe->db_cnt) - dbd);
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
index 7a58ce90e179..81919a7b4935 100644
--- a/drivers/infiniband/hw/mthca/mthca_provider.c
+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
@@ -349,9 +349,9 @@ static int mthca_mmap_uar(struct ib_ucontext *context,
349 349
350 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 350 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
351 351
352 if (remap_pfn_range(vma, vma->vm_start, 352 if (io_remap_pfn_range(vma, vma->vm_start,
353 to_mucontext(context)->uar.pfn, 353 to_mucontext(context)->uar.pfn,
354 PAGE_SIZE, vma->vm_page_prot)) 354 PAGE_SIZE, vma->vm_page_prot))
355 return -EAGAIN; 355 return -EAGAIN;
356 356
357 return 0; 357 return 0;
diff --git a/drivers/infiniband/include/ib_cm.h b/drivers/infiniband/include/ib_cm.h
new file mode 100644
index 000000000000..da650115e79a
--- /dev/null
+++ b/drivers/infiniband/include/ib_cm.h
@@ -0,0 +1,569 @@
1/*
2 * Copyright (c) 2004 Intel Corporation. All rights reserved.
3 * Copyright (c) 2004 Topspin Corporation. All rights reserved.
4 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
5 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
6 *
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * OpenIB.org BSD license below:
12 *
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
15 * conditions are met:
16 *
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer.
20 *
21 * - Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials
24 * provided with the distribution.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 * SOFTWARE.
34 *
35 * $Id: ib_cm.h 2730 2005-06-28 16:43:03Z sean.hefty $
36 */
37#if !defined(IB_CM_H)
38#define IB_CM_H
39
40#include <ib_mad.h>
41#include <ib_sa.h>
42
43enum ib_cm_state {
44 IB_CM_IDLE,
45 IB_CM_LISTEN,
46 IB_CM_REQ_SENT,
47 IB_CM_REQ_RCVD,
48 IB_CM_MRA_REQ_SENT,
49 IB_CM_MRA_REQ_RCVD,
50 IB_CM_REP_SENT,
51 IB_CM_REP_RCVD,
52 IB_CM_MRA_REP_SENT,
53 IB_CM_MRA_REP_RCVD,
54 IB_CM_ESTABLISHED,
55 IB_CM_DREQ_SENT,
56 IB_CM_DREQ_RCVD,
57 IB_CM_TIMEWAIT,
58 IB_CM_SIDR_REQ_SENT,
59 IB_CM_SIDR_REQ_RCVD
60};
61
62enum ib_cm_lap_state {
63 IB_CM_LAP_IDLE,
64 IB_CM_LAP_SENT,
65 IB_CM_LAP_RCVD,
66 IB_CM_MRA_LAP_SENT,
67 IB_CM_MRA_LAP_RCVD,
68};
69
70enum ib_cm_event_type {
71 IB_CM_REQ_ERROR,
72 IB_CM_REQ_RECEIVED,
73 IB_CM_REP_ERROR,
74 IB_CM_REP_RECEIVED,
75 IB_CM_RTU_RECEIVED,
76 IB_CM_USER_ESTABLISHED,
77 IB_CM_DREQ_ERROR,
78 IB_CM_DREQ_RECEIVED,
79 IB_CM_DREP_RECEIVED,
80 IB_CM_TIMEWAIT_EXIT,
81 IB_CM_MRA_RECEIVED,
82 IB_CM_REJ_RECEIVED,
83 IB_CM_LAP_ERROR,
84 IB_CM_LAP_RECEIVED,
85 IB_CM_APR_RECEIVED,
86 IB_CM_SIDR_REQ_ERROR,
87 IB_CM_SIDR_REQ_RECEIVED,
88 IB_CM_SIDR_REP_RECEIVED
89};
90
91enum ib_cm_data_size {
92 IB_CM_REQ_PRIVATE_DATA_SIZE = 92,
93 IB_CM_MRA_PRIVATE_DATA_SIZE = 222,
94 IB_CM_REJ_PRIVATE_DATA_SIZE = 148,
95 IB_CM_REP_PRIVATE_DATA_SIZE = 196,
96 IB_CM_RTU_PRIVATE_DATA_SIZE = 224,
97 IB_CM_DREQ_PRIVATE_DATA_SIZE = 220,
98 IB_CM_DREP_PRIVATE_DATA_SIZE = 224,
99 IB_CM_REJ_ARI_LENGTH = 72,
100 IB_CM_LAP_PRIVATE_DATA_SIZE = 168,
101 IB_CM_APR_PRIVATE_DATA_SIZE = 148,
102 IB_CM_APR_INFO_LENGTH = 72,
103 IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE = 216,
104 IB_CM_SIDR_REP_PRIVATE_DATA_SIZE = 136,
105 IB_CM_SIDR_REP_INFO_LENGTH = 72
106};
107
108struct ib_cm_id;
109
110struct ib_cm_req_event_param {
111 struct ib_cm_id *listen_id;
112 struct ib_device *device;
113 u8 port;
114
115 struct ib_sa_path_rec *primary_path;
116 struct ib_sa_path_rec *alternate_path;
117
118 u64 remote_ca_guid;
119 u32 remote_qkey;
120 u32 remote_qpn;
121 enum ib_qp_type qp_type;
122
123 u32 starting_psn;
124 u8 responder_resources;
125 u8 initiator_depth;
126 unsigned int local_cm_response_timeout:5;
127 unsigned int flow_control:1;
128 unsigned int remote_cm_response_timeout:5;
129 unsigned int retry_count:3;
130 unsigned int rnr_retry_count:3;
131 unsigned int srq:1;
132};
133
134struct ib_cm_rep_event_param {
135 u64 remote_ca_guid;
136 u32 remote_qkey;
137 u32 remote_qpn;
138 u32 starting_psn;
139 u8 responder_resources;
140 u8 initiator_depth;
141 unsigned int target_ack_delay:5;
142 unsigned int failover_accepted:2;
143 unsigned int flow_control:1;
144 unsigned int rnr_retry_count:3;
145 unsigned int srq:1;
146};
147
148enum ib_cm_rej_reason {
149 IB_CM_REJ_NO_QP = __constant_htons(1),
150 IB_CM_REJ_NO_EEC = __constant_htons(2),
151 IB_CM_REJ_NO_RESOURCES = __constant_htons(3),
152 IB_CM_REJ_TIMEOUT = __constant_htons(4),
153 IB_CM_REJ_UNSUPPORTED = __constant_htons(5),
154 IB_CM_REJ_INVALID_COMM_ID = __constant_htons(6),
155 IB_CM_REJ_INVALID_COMM_INSTANCE = __constant_htons(7),
156 IB_CM_REJ_INVALID_SERVICE_ID = __constant_htons(8),
157 IB_CM_REJ_INVALID_TRANSPORT_TYPE = __constant_htons(9),
158 IB_CM_REJ_STALE_CONN = __constant_htons(10),
159 IB_CM_REJ_RDC_NOT_EXIST = __constant_htons(11),
160 IB_CM_REJ_INVALID_GID = __constant_htons(12),
161 IB_CM_REJ_INVALID_LID = __constant_htons(13),
162 IB_CM_REJ_INVALID_SL = __constant_htons(14),
163 IB_CM_REJ_INVALID_TRAFFIC_CLASS = __constant_htons(15),
164 IB_CM_REJ_INVALID_HOP_LIMIT = __constant_htons(16),
165 IB_CM_REJ_INVALID_PACKET_RATE = __constant_htons(17),
166 IB_CM_REJ_INVALID_ALT_GID = __constant_htons(18),
167 IB_CM_REJ_INVALID_ALT_LID = __constant_htons(19),
168 IB_CM_REJ_INVALID_ALT_SL = __constant_htons(20),
169 IB_CM_REJ_INVALID_ALT_TRAFFIC_CLASS = __constant_htons(21),
170 IB_CM_REJ_INVALID_ALT_HOP_LIMIT = __constant_htons(22),
171 IB_CM_REJ_INVALID_ALT_PACKET_RATE = __constant_htons(23),
172 IB_CM_REJ_PORT_CM_REDIRECT = __constant_htons(24),
173 IB_CM_REJ_PORT_REDIRECT = __constant_htons(25),
174 IB_CM_REJ_INVALID_MTU = __constant_htons(26),
175 IB_CM_REJ_INSUFFICIENT_RESP_RESOURCES = __constant_htons(27),
176 IB_CM_REJ_CONSUMER_DEFINED = __constant_htons(28),
177 IB_CM_REJ_INVALID_RNR_RETRY = __constant_htons(29),
178 IB_CM_REJ_DUPLICATE_LOCAL_COMM_ID = __constant_htons(30),
179 IB_CM_REJ_INVALID_CLASS_VERSION = __constant_htons(31),
180 IB_CM_REJ_INVALID_FLOW_LABEL = __constant_htons(32),
181 IB_CM_REJ_INVALID_ALT_FLOW_LABEL = __constant_htons(33)
182};
183
184struct ib_cm_rej_event_param {
185 enum ib_cm_rej_reason reason;
186 void *ari;
187 u8 ari_length;
188};
189
190struct ib_cm_mra_event_param {
191 u8 service_timeout;
192};
193
194struct ib_cm_lap_event_param {
195 struct ib_sa_path_rec *alternate_path;
196};
197
198enum ib_cm_apr_status {
199 IB_CM_APR_SUCCESS,
200 IB_CM_APR_INVALID_COMM_ID,
201 IB_CM_APR_UNSUPPORTED,
202 IB_CM_APR_REJECT,
203 IB_CM_APR_REDIRECT,
204 IB_CM_APR_IS_CURRENT,
205 IB_CM_APR_INVALID_QPN_EECN,
206 IB_CM_APR_INVALID_LID,
207 IB_CM_APR_INVALID_GID,
208 IB_CM_APR_INVALID_FLOW_LABEL,
209 IB_CM_APR_INVALID_TCLASS,
210 IB_CM_APR_INVALID_HOP_LIMIT,
211 IB_CM_APR_INVALID_PACKET_RATE,
212 IB_CM_APR_INVALID_SL
213};
214
215struct ib_cm_apr_event_param {
216 enum ib_cm_apr_status ap_status;
217 void *apr_info;
218 u8 info_len;
219};
220
221struct ib_cm_sidr_req_event_param {
222 struct ib_cm_id *listen_id;
223 struct ib_device *device;
224 u8 port;
225
226 u16 pkey;
227};
228
229enum ib_cm_sidr_status {
230 IB_SIDR_SUCCESS,
231 IB_SIDR_UNSUPPORTED,
232 IB_SIDR_REJECT,
233 IB_SIDR_NO_QP,
234 IB_SIDR_REDIRECT,
235 IB_SIDR_UNSUPPORTED_VERSION
236};
237
238struct ib_cm_sidr_rep_event_param {
239 enum ib_cm_sidr_status status;
240 u32 qkey;
241 u32 qpn;
242 void *info;
243 u8 info_len;
244
245};
246
247struct ib_cm_event {
248 enum ib_cm_event_type event;
249 union {
250 struct ib_cm_req_event_param req_rcvd;
251 struct ib_cm_rep_event_param rep_rcvd;
252 /* No data for RTU received events. */
253 struct ib_cm_rej_event_param rej_rcvd;
254 struct ib_cm_mra_event_param mra_rcvd;
255 struct ib_cm_lap_event_param lap_rcvd;
256 struct ib_cm_apr_event_param apr_rcvd;
257 /* No data for DREQ/DREP received events. */
258 struct ib_cm_sidr_req_event_param sidr_req_rcvd;
259 struct ib_cm_sidr_rep_event_param sidr_rep_rcvd;
260 enum ib_wc_status send_status;
261 } param;
262
263 void *private_data;
264};
265
266/**
267 * ib_cm_handler - User-defined callback to process communication events.
268 * @cm_id: Communication identifier associated with the reported event.
269 * @event: Information about the communication event.
270 *
271 * IB_CM_REQ_RECEIVED and IB_CM_SIDR_REQ_RECEIVED communication events
272 * generated as a result of listen requests result in the allocation of a
273 * new @cm_id. The new @cm_id is returned to the user through this callback.
274 * Clients are responsible for destroying the new @cm_id. For peer-to-peer
275 * IB_CM_REQ_RECEIVED and all other events, the returned @cm_id corresponds
276 * to a user's existing communication identifier.
277 *
278 * Users may not call ib_destroy_cm_id while in the context of this callback;
279 * however, returning a non-zero value instructs the communication manager to
280 * destroy the @cm_id after the callback completes.
281 */
282typedef int (*ib_cm_handler)(struct ib_cm_id *cm_id,
283 struct ib_cm_event *event);
284
285struct ib_cm_id {
286 ib_cm_handler cm_handler;
287 void *context;
288 u64 service_id;
289 u64 service_mask;
290 enum ib_cm_state state; /* internal CM/debug use */
291 enum ib_cm_lap_state lap_state; /* internal CM/debug use */
292 u32 local_id;
293 u32 remote_id;
294};
295
296/**
297 * ib_create_cm_id - Allocate a communication identifier.
298 * @cm_handler: Callback invoked to notify the user of CM events.
299 * @context: User specified context associated with the communication
300 * identifier.
301 *
302 * Communication identifiers are used to track connection states, service
303 * ID resolution requests, and listen requests.
304 */
305struct ib_cm_id *ib_create_cm_id(ib_cm_handler cm_handler,
306 void *context);
307
308/**
309 * ib_destroy_cm_id - Destroy a connection identifier.
310 * @cm_id: Connection identifier to destroy.
311 *
312 * This call blocks until the connection identifier is destroyed.
313 */
314void ib_destroy_cm_id(struct ib_cm_id *cm_id);
315
316#define IB_SERVICE_ID_AGN_MASK __constant_cpu_to_be64(0xFF00000000000000ULL)
317#define IB_CM_ASSIGN_SERVICE_ID __constant_cpu_to_be64(0x0200000000000000ULL)
318
319/**
320 * ib_cm_listen - Initiates listening on the specified service ID for
321 * connection and service ID resolution requests.
322 * @cm_id: Connection identifier associated with the listen request.
323 * @service_id: Service identifier matched against incoming connection
324 * and service ID resolution requests. The service ID should be specified
325 * network-byte order. If set to IB_CM_ASSIGN_SERVICE_ID, the CM will
326 * assign a service ID to the caller.
327 * @service_mask: Mask applied to service ID used to listen across a
328 * range of service IDs. If set to 0, the service ID is matched
329 * exactly. This parameter is ignored if %service_id is set to
330 * IB_CM_ASSIGN_SERVICE_ID.
331 */
332int ib_cm_listen(struct ib_cm_id *cm_id,
333 u64 service_id,
334 u64 service_mask);
335
336struct ib_cm_req_param {
337 struct ib_sa_path_rec *primary_path;
338 struct ib_sa_path_rec *alternate_path;
339 u64 service_id;
340 u32 qp_num;
341 enum ib_qp_type qp_type;
342 u32 starting_psn;
343 const void *private_data;
344 u8 private_data_len;
345 u8 peer_to_peer;
346 u8 responder_resources;
347 u8 initiator_depth;
348 u8 remote_cm_response_timeout;
349 u8 flow_control;
350 u8 local_cm_response_timeout;
351 u8 retry_count;
352 u8 rnr_retry_count;
353 u8 max_cm_retries;
354 u8 srq;
355};
356
357/**
358 * ib_send_cm_req - Sends a connection request to the remote node.
359 * @cm_id: Connection identifier that will be associated with the
360 * connection request.
361 * @param: Connection request information needed to establish the
362 * connection.
363 */
364int ib_send_cm_req(struct ib_cm_id *cm_id,
365 struct ib_cm_req_param *param);
366
367struct ib_cm_rep_param {
368 u32 qp_num;
369 u32 starting_psn;
370 const void *private_data;
371 u8 private_data_len;
372 u8 responder_resources;
373 u8 initiator_depth;
374 u8 target_ack_delay;
375 u8 failover_accepted;
376 u8 flow_control;
377 u8 rnr_retry_count;
378 u8 srq;
379};
380
381/**
382 * ib_send_cm_rep - Sends a connection reply in response to a connection
383 * request.
384 * @cm_id: Connection identifier that will be associated with the
385 * connection request.
386 * @param: Connection reply information needed to establish the
387 * connection.
388 */
389int ib_send_cm_rep(struct ib_cm_id *cm_id,
390 struct ib_cm_rep_param *param);
391
392/**
393 * ib_send_cm_rtu - Sends a connection ready to use message in response
394 * to a connection reply message.
395 * @cm_id: Connection identifier associated with the connection request.
396 * @private_data: Optional user-defined private data sent with the
397 * ready to use message.
398 * @private_data_len: Size of the private data buffer, in bytes.
399 */
400int ib_send_cm_rtu(struct ib_cm_id *cm_id,
401 const void *private_data,
402 u8 private_data_len);
403
404/**
405 * ib_send_cm_dreq - Sends a disconnection request for an existing
406 * connection.
407 * @cm_id: Connection identifier associated with the connection being
408 * released.
409 * @private_data: Optional user-defined private data sent with the
410 * disconnection request message.
411 * @private_data_len: Size of the private data buffer, in bytes.
412 */
413int ib_send_cm_dreq(struct ib_cm_id *cm_id,
414 const void *private_data,
415 u8 private_data_len);
416
417/**
418 * ib_send_cm_drep - Sends a disconnection reply to a disconnection request.
419 * @cm_id: Connection identifier associated with the connection being
420 * released.
421 * @private_data: Optional user-defined private data sent with the
422 * disconnection reply message.
423 * @private_data_len: Size of the private data buffer, in bytes.
424 *
425 * If the cm_id is in the correct state, the CM will transition the connection
426 * to the timewait state, even if an error occurs sending the DREP message.
427 */
428int ib_send_cm_drep(struct ib_cm_id *cm_id,
429 const void *private_data,
430 u8 private_data_len);
431
432/**
433 * ib_cm_establish - Forces a connection state to established.
434 * @cm_id: Connection identifier to transition to established.
435 *
436 * This routine should be invoked by users who receive messages on a
437 * connected QP before an RTU has been received.
438 */
439int ib_cm_establish(struct ib_cm_id *cm_id);
440
441/**
442 * ib_send_cm_rej - Sends a connection rejection message to the
443 * remote node.
444 * @cm_id: Connection identifier associated with the connection being
445 * rejected.
446 * @reason: Reason for the connection request rejection.
447 * @ari: Optional additional rejection information.
448 * @ari_length: Size of the additional rejection information, in bytes.
449 * @private_data: Optional user-defined private data sent with the
450 * rejection message.
451 * @private_data_len: Size of the private data buffer, in bytes.
452 */
453int ib_send_cm_rej(struct ib_cm_id *cm_id,
454 enum ib_cm_rej_reason reason,
455 void *ari,
456 u8 ari_length,
457 const void *private_data,
458 u8 private_data_len);
459
460/**
461 * ib_send_cm_mra - Sends a message receipt acknowledgement to a connection
462 * message.
463 * @cm_id: Connection identifier associated with the connection message.
464 * @service_timeout: The maximum time required for the sender to reply to
465 * to the connection message.
466 * @private_data: Optional user-defined private data sent with the
467 * message receipt acknowledgement.
468 * @private_data_len: Size of the private data buffer, in bytes.
469 */
470int ib_send_cm_mra(struct ib_cm_id *cm_id,
471 u8 service_timeout,
472 const void *private_data,
473 u8 private_data_len);
474
475/**
476 * ib_send_cm_lap - Sends a load alternate path request.
477 * @cm_id: Connection identifier associated with the load alternate path
478 * message.
479 * @alternate_path: A path record that identifies the alternate path to
480 * load.
481 * @private_data: Optional user-defined private data sent with the
482 * load alternate path message.
483 * @private_data_len: Size of the private data buffer, in bytes.
484 */
485int ib_send_cm_lap(struct ib_cm_id *cm_id,
486 struct ib_sa_path_rec *alternate_path,
487 const void *private_data,
488 u8 private_data_len);
489
490/**
491 * ib_cm_init_qp_attr - Initializes the QP attributes for use in transitioning
492 * to a specified QP state.
493 * @cm_id: Communication identifier associated with the QP attributes to
494 * initialize.
495 * @qp_attr: On input, specifies the desired QP state. On output, the
496 * mandatory and desired optional attributes will be set in order to
497 * modify the QP to the specified state.
498 * @qp_attr_mask: The QP attribute mask that may be used to transition the
499 * QP to the specified state.
500 *
501 * Users must set the @qp_attr->qp_state to the desired QP state. This call
502 * will set all required attributes for the given transition, along with
503 * known optional attributes. Users may override the attributes returned from
504 * this call before calling ib_modify_qp.
505 */
506int ib_cm_init_qp_attr(struct ib_cm_id *cm_id,
507 struct ib_qp_attr *qp_attr,
508 int *qp_attr_mask);
509
510/**
511 * ib_send_cm_apr - Sends an alternate path response message in response to
512 * a load alternate path request.
513 * @cm_id: Connection identifier associated with the alternate path response.
514 * @status: Reply status sent with the alternate path response.
515 * @info: Optional additional information sent with the alternate path
516 * response.
517 * @info_length: Size of the additional information, in bytes.
518 * @private_data: Optional user-defined private data sent with the
519 * alternate path response message.
520 * @private_data_len: Size of the private data buffer, in bytes.
521 */
522int ib_send_cm_apr(struct ib_cm_id *cm_id,
523 enum ib_cm_apr_status status,
524 void *info,
525 u8 info_length,
526 const void *private_data,
527 u8 private_data_len);
528
529struct ib_cm_sidr_req_param {
530 struct ib_sa_path_rec *path;
531 u64 service_id;
532 int timeout_ms;
533 const void *private_data;
534 u8 private_data_len;
535 u8 max_cm_retries;
536 u16 pkey;
537};
538
539/**
540 * ib_send_cm_sidr_req - Sends a service ID resolution request to the
541 * remote node.
542 * @cm_id: Communication identifier that will be associated with the
543 * service ID resolution request.
544 * @param: Service ID resolution request information.
545 */
546int ib_send_cm_sidr_req(struct ib_cm_id *cm_id,
547 struct ib_cm_sidr_req_param *param);
548
549struct ib_cm_sidr_rep_param {
550 u32 qp_num;
551 u32 qkey;
552 enum ib_cm_sidr_status status;
553 const void *info;
554 u8 info_length;
555 const void *private_data;
556 u8 private_data_len;
557};
558
559/**
560 * ib_send_cm_sidr_rep - Sends a service ID resolution request to the
561 * remote node.
562 * @cm_id: Communication identifier associated with the received service ID
563 * resolution request.
564 * @param: Service ID resolution reply information.
565 */
566int ib_send_cm_sidr_rep(struct ib_cm_id *cm_id,
567 struct ib_cm_sidr_rep_param *param);
568
569#endif /* IB_CM_H */
diff --git a/drivers/infiniband/include/ib_fmr_pool.h b/drivers/infiniband/include/ib_fmr_pool.h
index e8769657cbbb..6c9e24d6e144 100644
--- a/drivers/infiniband/include/ib_fmr_pool.h
+++ b/drivers/infiniband/include/ib_fmr_pool.h
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (c) 2004 Topspin Corporation. All rights reserved. 2 * Copyright (c) 2004 Topspin Corporation. All rights reserved.
3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
3 * 4 *
4 * This software is available to you under a choice of one of two 5 * 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 * licenses. You may choose to be licensed under the terms of the GNU
@@ -29,7 +30,7 @@
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE. 31 * SOFTWARE.
31 * 32 *
32 * $Id: ib_fmr_pool.h 1349 2004-12-16 21:09:43Z roland $ 33 * $Id: ib_fmr_pool.h 2730 2005-06-28 16:43:03Z sean.hefty $
33 */ 34 */
34 35
35#if !defined(IB_FMR_POOL_H) 36#if !defined(IB_FMR_POOL_H)
@@ -78,7 +79,7 @@ struct ib_pool_fmr {
78struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd, 79struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
79 struct ib_fmr_pool_param *params); 80 struct ib_fmr_pool_param *params);
80 81
81int ib_destroy_fmr_pool(struct ib_fmr_pool *pool); 82void ib_destroy_fmr_pool(struct ib_fmr_pool *pool);
82 83
83int ib_flush_fmr_pool(struct ib_fmr_pool *pool); 84int ib_flush_fmr_pool(struct ib_fmr_pool *pool);
84 85
diff --git a/drivers/infiniband/include/ib_mad.h b/drivers/infiniband/include/ib_mad.h
index 4a6bf6763a97..491b6f25b3b8 100644
--- a/drivers/infiniband/include/ib_mad.h
+++ b/drivers/infiniband/include/ib_mad.h
@@ -33,12 +33,14 @@
33 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 33 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 * SOFTWARE. 34 * SOFTWARE.
35 * 35 *
36 * $Id: ib_mad.h 1389 2004-12-27 22:56:47Z roland $ 36 * $Id: ib_mad.h 2775 2005-07-02 13:42:12Z halr $
37 */ 37 */
38 38
39#if !defined( IB_MAD_H ) 39#if !defined( IB_MAD_H )
40#define IB_MAD_H 40#define IB_MAD_H
41 41
42#include <linux/pci.h>
43
42#include <ib_verbs.h> 44#include <ib_verbs.h>
43 45
44/* Management base version */ 46/* Management base version */
@@ -56,6 +58,8 @@
56#define IB_MGMT_CLASS_VENDOR_RANGE2_START 0x30 58#define IB_MGMT_CLASS_VENDOR_RANGE2_START 0x30
57#define IB_MGMT_CLASS_VENDOR_RANGE2_END 0x4F 59#define IB_MGMT_CLASS_VENDOR_RANGE2_END 0x4F
58 60
61#define IB_OPENIB_OUI (0x001405)
62
59/* Management methods */ 63/* Management methods */
60#define IB_MGMT_METHOD_GET 0x01 64#define IB_MGMT_METHOD_GET 0x01
61#define IB_MGMT_METHOD_SET 0x02 65#define IB_MGMT_METHOD_SET 0x02
@@ -70,18 +74,37 @@
70 74
71#define IB_MGMT_MAX_METHODS 128 75#define IB_MGMT_MAX_METHODS 128
72 76
77/* RMPP information */
78#define IB_MGMT_RMPP_VERSION 1
79
80#define IB_MGMT_RMPP_TYPE_DATA 1
81#define IB_MGMT_RMPP_TYPE_ACK 2
82#define IB_MGMT_RMPP_TYPE_STOP 3
83#define IB_MGMT_RMPP_TYPE_ABORT 4
84
85#define IB_MGMT_RMPP_FLAG_ACTIVE 1
86#define IB_MGMT_RMPP_FLAG_FIRST (1<<1)
87#define IB_MGMT_RMPP_FLAG_LAST (1<<2)
88
89#define IB_MGMT_RMPP_NO_RESPTIME 0x1F
90
91#define IB_MGMT_RMPP_STATUS_SUCCESS 0
92#define IB_MGMT_RMPP_STATUS_RESX 1
93#define IB_MGMT_RMPP_STATUS_T2L 118
94#define IB_MGMT_RMPP_STATUS_BAD_LEN 119
95#define IB_MGMT_RMPP_STATUS_BAD_SEG 120
96#define IB_MGMT_RMPP_STATUS_BADT 121
97#define IB_MGMT_RMPP_STATUS_W2S 122
98#define IB_MGMT_RMPP_STATUS_S2B 123
99#define IB_MGMT_RMPP_STATUS_BAD_STATUS 124
100#define IB_MGMT_RMPP_STATUS_UNV 125
101#define IB_MGMT_RMPP_STATUS_TMR 126
102#define IB_MGMT_RMPP_STATUS_UNSPEC 127
103
73#define IB_QP0 0 104#define IB_QP0 0
74#define IB_QP1 __constant_htonl(1) 105#define IB_QP1 __constant_htonl(1)
75#define IB_QP1_QKEY 0x80010000 106#define IB_QP1_QKEY 0x80010000
76 107#define IB_QP_SET_QKEY 0x80000000
77struct ib_grh {
78 u32 version_tclass_flow;
79 u16 paylen;
80 u8 next_hdr;
81 u8 hop_limit;
82 union ib_gid sgid;
83 union ib_gid dgid;
84} __attribute__ ((packed));
85 108
86struct ib_mad_hdr { 109struct ib_mad_hdr {
87 u8 base_version; 110 u8 base_version;
@@ -94,7 +117,7 @@ struct ib_mad_hdr {
94 u16 attr_id; 117 u16 attr_id;
95 u16 resv; 118 u16 resv;
96 u32 attr_mod; 119 u32 attr_mod;
97} __attribute__ ((packed)); 120};
98 121
99struct ib_rmpp_hdr { 122struct ib_rmpp_hdr {
100 u8 rmpp_version; 123 u8 rmpp_version;
@@ -103,17 +126,41 @@ struct ib_rmpp_hdr {
103 u8 rmpp_status; 126 u8 rmpp_status;
104 u32 seg_num; 127 u32 seg_num;
105 u32 paylen_newwin; 128 u32 paylen_newwin;
129};
130
131typedef u64 __bitwise ib_sa_comp_mask;
132
133#define IB_SA_COMP_MASK(n) ((__force ib_sa_comp_mask) cpu_to_be64(1ull << n))
134
135/*
136 * ib_sa_hdr and ib_sa_mad structures must be packed because they have
137 * 64-bit fields that are only 32-bit aligned. 64-bit architectures will
138 * lay them out wrong otherwise. (And unfortunately they are sent on
139 * the wire so we can't change the layout)
140 */
141struct ib_sa_hdr {
142 u64 sm_key;
143 u16 attr_offset;
144 u16 reserved;
145 ib_sa_comp_mask comp_mask;
106} __attribute__ ((packed)); 146} __attribute__ ((packed));
107 147
108struct ib_mad { 148struct ib_mad {
109 struct ib_mad_hdr mad_hdr; 149 struct ib_mad_hdr mad_hdr;
110 u8 data[232]; 150 u8 data[232];
111} __attribute__ ((packed)); 151};
112 152
113struct ib_rmpp_mad { 153struct ib_rmpp_mad {
114 struct ib_mad_hdr mad_hdr; 154 struct ib_mad_hdr mad_hdr;
115 struct ib_rmpp_hdr rmpp_hdr; 155 struct ib_rmpp_hdr rmpp_hdr;
116 u8 data[220]; 156 u8 data[220];
157};
158
159struct ib_sa_mad {
160 struct ib_mad_hdr mad_hdr;
161 struct ib_rmpp_hdr rmpp_hdr;
162 struct ib_sa_hdr sa_hdr;
163 u8 data[200];
117} __attribute__ ((packed)); 164} __attribute__ ((packed));
118 165
119struct ib_vendor_mad { 166struct ib_vendor_mad {
@@ -122,7 +169,70 @@ struct ib_vendor_mad {
122 u8 reserved; 169 u8 reserved;
123 u8 oui[3]; 170 u8 oui[3];
124 u8 data[216]; 171 u8 data[216];
125} __attribute__ ((packed)); 172};
173
174/**
175 * ib_mad_send_buf - MAD data buffer and work request for sends.
176 * @mad: References an allocated MAD data buffer. The size of the data
177 * buffer is specified in the @send_wr.length field.
178 * @mapping: DMA mapping information.
179 * @mad_agent: MAD agent that allocated the buffer.
180 * @context: User-controlled context fields.
181 * @send_wr: An initialized work request structure used when sending the MAD.
182 * The wr_id field of the work request is initialized to reference this
183 * data structure.
184 * @sge: A scatter-gather list referenced by the work request.
185 *
186 * Users are responsible for initializing the MAD buffer itself, with the
187 * exception of specifying the payload length field in any RMPP MAD.
188 */
189struct ib_mad_send_buf {
190 struct ib_mad *mad;
191 DECLARE_PCI_UNMAP_ADDR(mapping)
192 struct ib_mad_agent *mad_agent;
193 void *context[2];
194 struct ib_send_wr send_wr;
195 struct ib_sge sge;
196};
197
198/**
199 * ib_get_rmpp_resptime - Returns the RMPP response time.
200 * @rmpp_hdr: An RMPP header.
201 */
202static inline u8 ib_get_rmpp_resptime(struct ib_rmpp_hdr *rmpp_hdr)
203{
204 return rmpp_hdr->rmpp_rtime_flags >> 3;
205}
206
207/**
208 * ib_get_rmpp_flags - Returns the RMPP flags.
209 * @rmpp_hdr: An RMPP header.
210 */
211static inline u8 ib_get_rmpp_flags(struct ib_rmpp_hdr *rmpp_hdr)
212{
213 return rmpp_hdr->rmpp_rtime_flags & 0x7;
214}
215
216/**
217 * ib_set_rmpp_resptime - Sets the response time in an RMPP header.
218 * @rmpp_hdr: An RMPP header.
219 * @rtime: The response time to set.
220 */
221static inline void ib_set_rmpp_resptime(struct ib_rmpp_hdr *rmpp_hdr, u8 rtime)
222{
223 rmpp_hdr->rmpp_rtime_flags = ib_get_rmpp_flags(rmpp_hdr) | (rtime << 3);
224}
225
226/**
227 * ib_set_rmpp_flags - Sets the flags in an RMPP header.
228 * @rmpp_hdr: An RMPP header.
229 * @flags: The flags to set.
230 */
231static inline void ib_set_rmpp_flags(struct ib_rmpp_hdr *rmpp_hdr, u8 flags)
232{
233 rmpp_hdr->rmpp_rtime_flags = (rmpp_hdr->rmpp_rtime_flags & 0xF1) |
234 (flags & 0x7);
235}
126 236
127struct ib_mad_agent; 237struct ib_mad_agent;
128struct ib_mad_send_wc; 238struct ib_mad_send_wc;
@@ -168,6 +278,7 @@ typedef void (*ib_mad_recv_handler)(struct ib_mad_agent *mad_agent,
168 * ib_mad_agent - Used to track MAD registration with the access layer. 278 * ib_mad_agent - Used to track MAD registration with the access layer.
169 * @device: Reference to device registration is on. 279 * @device: Reference to device registration is on.
170 * @qp: Reference to QP used for sending and receiving MADs. 280 * @qp: Reference to QP used for sending and receiving MADs.
281 * @mr: Memory region for system memory usable for DMA.
171 * @recv_handler: Callback handler for a received MAD. 282 * @recv_handler: Callback handler for a received MAD.
172 * @send_handler: Callback handler for a sent MAD. 283 * @send_handler: Callback handler for a sent MAD.
173 * @snoop_handler: Callback handler for snooped sent MADs. 284 * @snoop_handler: Callback handler for snooped sent MADs.
@@ -176,16 +287,19 @@ typedef void (*ib_mad_recv_handler)(struct ib_mad_agent *mad_agent,
176 * Unsolicited MADs sent by this client will have the upper 32-bits 287 * Unsolicited MADs sent by this client will have the upper 32-bits
177 * of their TID set to this value. 288 * of their TID set to this value.
178 * @port_num: Port number on which QP is registered 289 * @port_num: Port number on which QP is registered
290 * @rmpp_version: If set, indicates the RMPP version used by this agent.
179 */ 291 */
180struct ib_mad_agent { 292struct ib_mad_agent {
181 struct ib_device *device; 293 struct ib_device *device;
182 struct ib_qp *qp; 294 struct ib_qp *qp;
295 struct ib_mr *mr;
183 ib_mad_recv_handler recv_handler; 296 ib_mad_recv_handler recv_handler;
184 ib_mad_send_handler send_handler; 297 ib_mad_send_handler send_handler;
185 ib_mad_snoop_handler snoop_handler; 298 ib_mad_snoop_handler snoop_handler;
186 void *context; 299 void *context;
187 u32 hi_tid; 300 u32 hi_tid;
188 u8 port_num; 301 u8 port_num;
302 u8 rmpp_version;
189}; 303};
190 304
191/** 305/**
@@ -219,6 +333,7 @@ struct ib_mad_recv_buf {
219 * ib_mad_recv_wc - received MAD information. 333 * ib_mad_recv_wc - received MAD information.
220 * @wc: Completion information for the received data. 334 * @wc: Completion information for the received data.
221 * @recv_buf: Specifies the location of the received data buffer(s). 335 * @recv_buf: Specifies the location of the received data buffer(s).
336 * @rmpp_list: Specifies a list of RMPP reassembled received MAD buffers.
222 * @mad_len: The length of the received MAD, without duplicated headers. 337 * @mad_len: The length of the received MAD, without duplicated headers.
223 * 338 *
224 * For received response, the wr_id field of the wc is set to the wr_id 339 * For received response, the wr_id field of the wc is set to the wr_id
@@ -227,6 +342,7 @@ struct ib_mad_recv_buf {
227struct ib_mad_recv_wc { 342struct ib_mad_recv_wc {
228 struct ib_wc *wc; 343 struct ib_wc *wc;
229 struct ib_mad_recv_buf recv_buf; 344 struct ib_mad_recv_buf recv_buf;
345 struct list_head rmpp_list;
230 int mad_len; 346 int mad_len;
231}; 347};
232 348
@@ -322,6 +438,16 @@ int ib_unregister_mad_agent(struct ib_mad_agent *mad_agent);
322 * @bad_send_wr: Specifies the MAD on which an error was encountered. 438 * @bad_send_wr: Specifies the MAD on which an error was encountered.
323 * 439 *
324 * Sent MADs are not guaranteed to complete in the order that they were posted. 440 * Sent MADs are not guaranteed to complete in the order that they were posted.
441 *
442 * If the MAD requires RMPP, the data buffer should contain a single copy
443 * of the common MAD, RMPP, and class specific headers, followed by the class
444 * defined data. If the class defined data would not divide evenly into
445 * RMPP segments, then space must be allocated at the end of the referenced
446 * buffer for any required padding. To indicate the amount of class defined
447 * data being transferred, the paylen_newwin field in the RMPP header should
448 * be set to the size of the class specific header plus the amount of class
449 * defined data being transferred. The paylen_newwin field should be
450 * specified in network-byte order.
325 */ 451 */
326int ib_post_send_mad(struct ib_mad_agent *mad_agent, 452int ib_post_send_mad(struct ib_mad_agent *mad_agent,
327 struct ib_send_wr *send_wr, 453 struct ib_send_wr *send_wr,
@@ -334,15 +460,13 @@ int ib_post_send_mad(struct ib_mad_agent *mad_agent,
334 * referenced buffer should be at least the size of the mad_len specified 460 * referenced buffer should be at least the size of the mad_len specified
335 * by @mad_recv_wc. 461 * by @mad_recv_wc.
336 * 462 *
337 * This call copies a chain of received RMPP MADs into a single data buffer, 463 * This call copies a chain of received MAD segments into a single data buffer,
338 * removing duplicated headers. 464 * removing duplicated headers.
339 */ 465 */
340void ib_coalesce_recv_mad(struct ib_mad_recv_wc *mad_recv_wc, 466void ib_coalesce_recv_mad(struct ib_mad_recv_wc *mad_recv_wc, void *buf);
341 void *buf);
342 467
343/** 468/**
344 * ib_free_recv_mad - Returns data buffers used to receive a MAD to the 469 * ib_free_recv_mad - Returns data buffers used to receive a MAD.
345 * access layer.
346 * @mad_recv_wc: Work completion information for a received MAD. 470 * @mad_recv_wc: Work completion information for a received MAD.
347 * 471 *
348 * Clients receiving MADs through their ib_mad_recv_handler must call this 472 * Clients receiving MADs through their ib_mad_recv_handler must call this
@@ -358,8 +482,18 @@ void ib_free_recv_mad(struct ib_mad_recv_wc *mad_recv_wc);
358 * MADs will be returned to the user through the corresponding 482 * MADs will be returned to the user through the corresponding
359 * ib_mad_send_handler. 483 * ib_mad_send_handler.
360 */ 484 */
361void ib_cancel_mad(struct ib_mad_agent *mad_agent, 485void ib_cancel_mad(struct ib_mad_agent *mad_agent, u64 wr_id);
362 u64 wr_id); 486
487/**
488 * ib_modify_mad - Modifies an outstanding send MAD operation.
489 * @mad_agent: Specifies the registration associated with sent MAD.
490 * @wr_id: Indicates the work request identifier of the MAD to modify.
491 * @timeout_ms: New timeout value for sent MAD.
492 *
493 * This call will reset the timeout value for a sent MAD to the specified
494 * value.
495 */
496int ib_modify_mad(struct ib_mad_agent *mad_agent, u64 wr_id, u32 timeout_ms);
363 497
364/** 498/**
365 * ib_redirect_mad_qp - Registers a QP for MAD services. 499 * ib_redirect_mad_qp - Registers a QP for MAD services.
@@ -401,4 +535,43 @@ struct ib_mad_agent *ib_redirect_mad_qp(struct ib_qp *qp,
401int ib_process_mad_wc(struct ib_mad_agent *mad_agent, 535int ib_process_mad_wc(struct ib_mad_agent *mad_agent,
402 struct ib_wc *wc); 536 struct ib_wc *wc);
403 537
538/**
539 * ib_create_send_mad - Allocate and initialize a data buffer and work request
540 * for sending a MAD.
541 * @mad_agent: Specifies the registered MAD service to associate with the MAD.
542 * @remote_qpn: Specifies the QPN of the receiving node.
543 * @pkey_index: Specifies which PKey the MAD will be sent using. This field
544 * is valid only if the remote_qpn is QP 1.
545 * @ah: References the address handle used to transfer to the remote node.
546 * @rmpp_active: Indicates if the send will enable RMPP.
547 * @hdr_len: Indicates the size of the data header of the MAD. This length
548 * should include the common MAD header, RMPP header, plus any class
549 * specific header.
550 * @data_len: Indicates the size of any user-transferred data. The call will
551 * automatically adjust the allocated buffer size to account for any
552 * additional padding that may be necessary.
553 * @gfp_mask: GFP mask used for the memory allocation.
554 *
555 * This is a helper routine that may be used to allocate a MAD. Users are
556 * not required to allocate outbound MADs using this call. The returned
557 * MAD send buffer will reference a data buffer usable for sending a MAD, along
558 * with an initialized work request structure. Users may modify the returned
559 * MAD data buffer or work request before posting the send.
560 *
561 * The returned data buffer will be cleared. Users are responsible for
562 * initializing the common MAD and any class specific headers. If @rmpp_active
563 * is set, the RMPP header will be initialized for sending.
564 */
565struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent,
566 u32 remote_qpn, u16 pkey_index,
567 struct ib_ah *ah, int rmpp_active,
568 int hdr_len, int data_len,
569 unsigned int __nocast gfp_mask);
570
571/**
572 * ib_free_send_mad - Returns data buffers used to send a MAD.
573 * @send_buf: Previously allocated send data buffer.
574 */
575void ib_free_send_mad(struct ib_mad_send_buf *send_buf);
576
404#endif /* IB_MAD_H */ 577#endif /* IB_MAD_H */
diff --git a/drivers/infiniband/include/ib_sa.h b/drivers/infiniband/include/ib_sa.h
index 00222285eb9a..6d999f7b5d93 100644
--- a/drivers/infiniband/include/ib_sa.h
+++ b/drivers/infiniband/include/ib_sa.h
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (c) 2004 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
3 * 4 *
4 * This software is available to you under a choice of one of two 5 * 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 * licenses. You may choose to be licensed under the terms of the GNU
@@ -29,7 +30,7 @@
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE. 31 * SOFTWARE.
31 * 32 *
32 * $Id: ib_sa.h 1389 2004-12-27 22:56:47Z roland $ 33 * $Id: ib_sa.h 2811 2005-07-06 18:11:43Z halr $
33 */ 34 */
34 35
35#ifndef IB_SA_H 36#ifndef IB_SA_H
@@ -41,9 +42,11 @@
41#include <ib_mad.h> 42#include <ib_mad.h>
42 43
43enum { 44enum {
44 IB_SA_CLASS_VERSION = 2, /* IB spec version 1.1/1.2 */ 45 IB_SA_CLASS_VERSION = 2, /* IB spec version 1.1/1.2 */
45 46
46 IB_SA_METHOD_DELETE = 0x15 47 IB_SA_METHOD_GET_TABLE = 0x12,
48 IB_SA_METHOD_GET_TABLE_RESP = 0x92,
49 IB_SA_METHOD_DELETE = 0x15
47}; 50};
48 51
49enum ib_sa_selector { 52enum ib_sa_selector {
@@ -87,10 +90,6 @@ static inline int ib_sa_rate_enum_to_int(enum ib_sa_rate rate)
87 } 90 }
88} 91}
89 92
90typedef u64 __bitwise ib_sa_comp_mask;
91
92#define IB_SA_COMP_MASK(n) ((__force ib_sa_comp_mask) cpu_to_be64(1ull << n))
93
94/* 93/*
95 * Structures for SA records are named "struct ib_sa_xxx_rec." No 94 * Structures for SA records are named "struct ib_sa_xxx_rec." No
96 * attempt is made to pack structures to match the physical layout of 95 * attempt is made to pack structures to match the physical layout of
@@ -195,6 +194,61 @@ struct ib_sa_mcmember_rec {
195 int proxy_join; 194 int proxy_join;
196}; 195};
197 196
197/* Service Record Component Mask Sec 15.2.5.14 Ver 1.1 */
198#define IB_SA_SERVICE_REC_SERVICE_ID IB_SA_COMP_MASK( 0)
199#define IB_SA_SERVICE_REC_SERVICE_GID IB_SA_COMP_MASK( 1)
200#define IB_SA_SERVICE_REC_SERVICE_PKEY IB_SA_COMP_MASK( 2)
201/* reserved: 3 */
202#define IB_SA_SERVICE_REC_SERVICE_LEASE IB_SA_COMP_MASK( 4)
203#define IB_SA_SERVICE_REC_SERVICE_KEY IB_SA_COMP_MASK( 5)
204#define IB_SA_SERVICE_REC_SERVICE_NAME IB_SA_COMP_MASK( 6)
205#define IB_SA_SERVICE_REC_SERVICE_DATA8_0 IB_SA_COMP_MASK( 7)
206#define IB_SA_SERVICE_REC_SERVICE_DATA8_1 IB_SA_COMP_MASK( 8)
207#define IB_SA_SERVICE_REC_SERVICE_DATA8_2 IB_SA_COMP_MASK( 9)
208#define IB_SA_SERVICE_REC_SERVICE_DATA8_3 IB_SA_COMP_MASK(10)
209#define IB_SA_SERVICE_REC_SERVICE_DATA8_4 IB_SA_COMP_MASK(11)
210#define IB_SA_SERVICE_REC_SERVICE_DATA8_5 IB_SA_COMP_MASK(12)
211#define IB_SA_SERVICE_REC_SERVICE_DATA8_6 IB_SA_COMP_MASK(13)
212#define IB_SA_SERVICE_REC_SERVICE_DATA8_7 IB_SA_COMP_MASK(14)
213#define IB_SA_SERVICE_REC_SERVICE_DATA8_8 IB_SA_COMP_MASK(15)
214#define IB_SA_SERVICE_REC_SERVICE_DATA8_9 IB_SA_COMP_MASK(16)
215#define IB_SA_SERVICE_REC_SERVICE_DATA8_10 IB_SA_COMP_MASK(17)
216#define IB_SA_SERVICE_REC_SERVICE_DATA8_11 IB_SA_COMP_MASK(18)
217#define IB_SA_SERVICE_REC_SERVICE_DATA8_12 IB_SA_COMP_MASK(19)
218#define IB_SA_SERVICE_REC_SERVICE_DATA8_13 IB_SA_COMP_MASK(20)
219#define IB_SA_SERVICE_REC_SERVICE_DATA8_14 IB_SA_COMP_MASK(21)
220#define IB_SA_SERVICE_REC_SERVICE_DATA8_15 IB_SA_COMP_MASK(22)
221#define IB_SA_SERVICE_REC_SERVICE_DATA16_0 IB_SA_COMP_MASK(23)
222#define IB_SA_SERVICE_REC_SERVICE_DATA16_1 IB_SA_COMP_MASK(24)
223#define IB_SA_SERVICE_REC_SERVICE_DATA16_2 IB_SA_COMP_MASK(25)
224#define IB_SA_SERVICE_REC_SERVICE_DATA16_3 IB_SA_COMP_MASK(26)
225#define IB_SA_SERVICE_REC_SERVICE_DATA16_4 IB_SA_COMP_MASK(27)
226#define IB_SA_SERVICE_REC_SERVICE_DATA16_5 IB_SA_COMP_MASK(28)
227#define IB_SA_SERVICE_REC_SERVICE_DATA16_6 IB_SA_COMP_MASK(29)
228#define IB_SA_SERVICE_REC_SERVICE_DATA16_7 IB_SA_COMP_MASK(30)
229#define IB_SA_SERVICE_REC_SERVICE_DATA32_0 IB_SA_COMP_MASK(31)
230#define IB_SA_SERVICE_REC_SERVICE_DATA32_1 IB_SA_COMP_MASK(32)
231#define IB_SA_SERVICE_REC_SERVICE_DATA32_2 IB_SA_COMP_MASK(33)
232#define IB_SA_SERVICE_REC_SERVICE_DATA32_3 IB_SA_COMP_MASK(34)
233#define IB_SA_SERVICE_REC_SERVICE_DATA64_0 IB_SA_COMP_MASK(35)
234#define IB_SA_SERVICE_REC_SERVICE_DATA64_1 IB_SA_COMP_MASK(36)
235
236#define IB_DEFAULT_SERVICE_LEASE 0xFFFFFFFF
237
238struct ib_sa_service_rec {
239 u64 id;
240 union ib_gid gid;
241 u16 pkey;
242 /* reserved */
243 u32 lease;
244 u8 key[16];
245 u8 name[64];
246 u8 data8[16];
247 u16 data16[8];
248 u32 data32[4];
249 u64 data64[2];
250};
251
198struct ib_sa_query; 252struct ib_sa_query;
199 253
200void ib_sa_cancel_query(int id, struct ib_sa_query *query); 254void ib_sa_cancel_query(int id, struct ib_sa_query *query);
@@ -202,7 +256,7 @@ void ib_sa_cancel_query(int id, struct ib_sa_query *query);
202int ib_sa_path_rec_get(struct ib_device *device, u8 port_num, 256int ib_sa_path_rec_get(struct ib_device *device, u8 port_num,
203 struct ib_sa_path_rec *rec, 257 struct ib_sa_path_rec *rec,
204 ib_sa_comp_mask comp_mask, 258 ib_sa_comp_mask comp_mask,
205 int timeout_ms, int gfp_mask, 259 int timeout_ms, unsigned int __nocast gfp_mask,
206 void (*callback)(int status, 260 void (*callback)(int status,
207 struct ib_sa_path_rec *resp, 261 struct ib_sa_path_rec *resp,
208 void *context), 262 void *context),
@@ -213,13 +267,24 @@ int ib_sa_mcmember_rec_query(struct ib_device *device, u8 port_num,
213 u8 method, 267 u8 method,
214 struct ib_sa_mcmember_rec *rec, 268 struct ib_sa_mcmember_rec *rec,
215 ib_sa_comp_mask comp_mask, 269 ib_sa_comp_mask comp_mask,
216 int timeout_ms, int gfp_mask, 270 int timeout_ms, unsigned int __nocast gfp_mask,
217 void (*callback)(int status, 271 void (*callback)(int status,
218 struct ib_sa_mcmember_rec *resp, 272 struct ib_sa_mcmember_rec *resp,
219 void *context), 273 void *context),
220 void *context, 274 void *context,
221 struct ib_sa_query **query); 275 struct ib_sa_query **query);
222 276
277int ib_sa_service_rec_query(struct ib_device *device, u8 port_num,
278 u8 method,
279 struct ib_sa_service_rec *rec,
280 ib_sa_comp_mask comp_mask,
281 int timeout_ms, unsigned int __nocast gfp_mask,
282 void (*callback)(int status,
283 struct ib_sa_service_rec *resp,
284 void *context),
285 void *context,
286 struct ib_sa_query **sa_query);
287
223/** 288/**
224 * ib_sa_mcmember_rec_set - Start an MCMember set query 289 * ib_sa_mcmember_rec_set - Start an MCMember set query
225 * @device:device to send query on 290 * @device:device to send query on
@@ -248,7 +313,7 @@ static inline int
248ib_sa_mcmember_rec_set(struct ib_device *device, u8 port_num, 313ib_sa_mcmember_rec_set(struct ib_device *device, u8 port_num,
249 struct ib_sa_mcmember_rec *rec, 314 struct ib_sa_mcmember_rec *rec,
250 ib_sa_comp_mask comp_mask, 315 ib_sa_comp_mask comp_mask,
251 int timeout_ms, int gfp_mask, 316 int timeout_ms, unsigned int __nocast gfp_mask,
252 void (*callback)(int status, 317 void (*callback)(int status,
253 struct ib_sa_mcmember_rec *resp, 318 struct ib_sa_mcmember_rec *resp,
254 void *context), 319 void *context),
@@ -290,7 +355,7 @@ static inline int
290ib_sa_mcmember_rec_delete(struct ib_device *device, u8 port_num, 355ib_sa_mcmember_rec_delete(struct ib_device *device, u8 port_num,
291 struct ib_sa_mcmember_rec *rec, 356 struct ib_sa_mcmember_rec *rec,
292 ib_sa_comp_mask comp_mask, 357 ib_sa_comp_mask comp_mask,
293 int timeout_ms, int gfp_mask, 358 int timeout_ms, unsigned int __nocast gfp_mask,
294 void (*callback)(int status, 359 void (*callback)(int status,
295 struct ib_sa_mcmember_rec *resp, 360 struct ib_sa_mcmember_rec *resp,
296 void *context), 361 void *context),
diff --git a/drivers/infiniband/include/ib_user_cm.h b/drivers/infiniband/include/ib_user_cm.h
new file mode 100644
index 000000000000..500b1af6ff77
--- /dev/null
+++ b/drivers/infiniband/include/ib_user_cm.h
@@ -0,0 +1,328 @@
1/*
2 * Copyright (c) 2005 Topspin Communications. 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: ib_user_cm.h 2576 2005-06-09 17:00:30Z libor $
33 */
34
35#ifndef IB_USER_CM_H
36#define IB_USER_CM_H
37
38#include <linux/types.h>
39
40#define IB_USER_CM_ABI_VERSION 1
41
42enum {
43 IB_USER_CM_CMD_CREATE_ID,
44 IB_USER_CM_CMD_DESTROY_ID,
45 IB_USER_CM_CMD_ATTR_ID,
46
47 IB_USER_CM_CMD_LISTEN,
48 IB_USER_CM_CMD_ESTABLISH,
49
50 IB_USER_CM_CMD_SEND_REQ,
51 IB_USER_CM_CMD_SEND_REP,
52 IB_USER_CM_CMD_SEND_RTU,
53 IB_USER_CM_CMD_SEND_DREQ,
54 IB_USER_CM_CMD_SEND_DREP,
55 IB_USER_CM_CMD_SEND_REJ,
56 IB_USER_CM_CMD_SEND_MRA,
57 IB_USER_CM_CMD_SEND_LAP,
58 IB_USER_CM_CMD_SEND_APR,
59 IB_USER_CM_CMD_SEND_SIDR_REQ,
60 IB_USER_CM_CMD_SEND_SIDR_REP,
61
62 IB_USER_CM_CMD_EVENT,
63};
64/*
65 * command ABI structures.
66 */
67struct ib_ucm_cmd_hdr {
68 __u32 cmd;
69 __u16 in;
70 __u16 out;
71};
72
73struct ib_ucm_create_id {
74 __u64 response;
75};
76
77struct ib_ucm_create_id_resp {
78 __u32 id;
79};
80
81struct ib_ucm_destroy_id {
82 __u32 id;
83};
84
85struct ib_ucm_attr_id {
86 __u64 response;
87 __u32 id;
88};
89
90struct ib_ucm_attr_id_resp {
91 __u64 service_id;
92 __u64 service_mask;
93 __u32 local_id;
94 __u32 remote_id;
95};
96
97struct ib_ucm_listen {
98 __u64 service_id;
99 __u64 service_mask;
100 __u32 id;
101};
102
103struct ib_ucm_establish {
104 __u32 id;
105};
106
107struct ib_ucm_private_data {
108 __u64 data;
109 __u32 id;
110 __u8 len;
111 __u8 reserved[3];
112};
113
114struct ib_ucm_path_rec {
115 __u8 dgid[16];
116 __u8 sgid[16];
117 __u16 dlid;
118 __u16 slid;
119 __u32 raw_traffic;
120 __u32 flow_label;
121 __u32 reversible;
122 __u32 mtu;
123 __u16 pkey;
124 __u8 hop_limit;
125 __u8 traffic_class;
126 __u8 numb_path;
127 __u8 sl;
128 __u8 mtu_selector;
129 __u8 rate_selector;
130 __u8 rate;
131 __u8 packet_life_time_selector;
132 __u8 packet_life_time;
133 __u8 preference;
134};
135
136struct ib_ucm_req {
137 __u32 id;
138 __u32 qpn;
139 __u32 qp_type;
140 __u32 psn;
141 __u64 sid;
142 __u64 data;
143 __u64 primary_path;
144 __u64 alternate_path;
145 __u8 len;
146 __u8 peer_to_peer;
147 __u8 responder_resources;
148 __u8 initiator_depth;
149 __u8 remote_cm_response_timeout;
150 __u8 flow_control;
151 __u8 local_cm_response_timeout;
152 __u8 retry_count;
153 __u8 rnr_retry_count;
154 __u8 max_cm_retries;
155 __u8 srq;
156 __u8 reserved[1];
157};
158
159struct ib_ucm_rep {
160 __u64 data;
161 __u32 id;
162 __u32 qpn;
163 __u32 psn;
164 __u8 len;
165 __u8 responder_resources;
166 __u8 initiator_depth;
167 __u8 target_ack_delay;
168 __u8 failover_accepted;
169 __u8 flow_control;
170 __u8 rnr_retry_count;
171 __u8 srq;
172};
173
174struct ib_ucm_info {
175 __u32 id;
176 __u32 status;
177 __u64 info;
178 __u64 data;
179 __u8 info_len;
180 __u8 data_len;
181 __u8 reserved[2];
182};
183
184struct ib_ucm_mra {
185 __u64 data;
186 __u32 id;
187 __u8 len;
188 __u8 timeout;
189 __u8 reserved[2];
190};
191
192struct ib_ucm_lap {
193 __u64 path;
194 __u64 data;
195 __u32 id;
196 __u8 len;
197 __u8 reserved[3];
198};
199
200struct ib_ucm_sidr_req {
201 __u32 id;
202 __u32 timeout;
203 __u64 sid;
204 __u64 data;
205 __u64 path;
206 __u16 pkey;
207 __u8 len;
208 __u8 max_cm_retries;
209};
210
211struct ib_ucm_sidr_rep {
212 __u32 id;
213 __u32 qpn;
214 __u32 qkey;
215 __u32 status;
216 __u64 info;
217 __u64 data;
218 __u8 info_len;
219 __u8 data_len;
220 __u8 reserved[2];
221};
222/*
223 * event notification ABI structures.
224 */
225struct ib_ucm_event_get {
226 __u64 response;
227 __u64 data;
228 __u64 info;
229 __u8 data_len;
230 __u8 info_len;
231 __u8 reserved[2];
232};
233
234struct ib_ucm_req_event_resp {
235 __u32 listen_id;
236 /* device */
237 /* port */
238 struct ib_ucm_path_rec primary_path;
239 struct ib_ucm_path_rec alternate_path;
240 __u64 remote_ca_guid;
241 __u32 remote_qkey;
242 __u32 remote_qpn;
243 __u32 qp_type;
244 __u32 starting_psn;
245 __u8 responder_resources;
246 __u8 initiator_depth;
247 __u8 local_cm_response_timeout;
248 __u8 flow_control;
249 __u8 remote_cm_response_timeout;
250 __u8 retry_count;
251 __u8 rnr_retry_count;
252 __u8 srq;
253};
254
255struct ib_ucm_rep_event_resp {
256 __u64 remote_ca_guid;
257 __u32 remote_qkey;
258 __u32 remote_qpn;
259 __u32 starting_psn;
260 __u8 responder_resources;
261 __u8 initiator_depth;
262 __u8 target_ack_delay;
263 __u8 failover_accepted;
264 __u8 flow_control;
265 __u8 rnr_retry_count;
266 __u8 srq;
267 __u8 reserved[1];
268};
269
270struct ib_ucm_rej_event_resp {
271 __u32 reason;
272 /* ari in ib_ucm_event_get info field. */
273};
274
275struct ib_ucm_mra_event_resp {
276 __u8 timeout;
277 __u8 reserved[3];
278};
279
280struct ib_ucm_lap_event_resp {
281 struct ib_ucm_path_rec path;
282};
283
284struct ib_ucm_apr_event_resp {
285 __u32 status;
286 /* apr info in ib_ucm_event_get info field. */
287};
288
289struct ib_ucm_sidr_req_event_resp {
290 __u32 listen_id;
291 /* device */
292 /* port */
293 __u16 pkey;
294 __u8 reserved[2];
295};
296
297struct ib_ucm_sidr_rep_event_resp {
298 __u32 status;
299 __u32 qkey;
300 __u32 qpn;
301 /* info in ib_ucm_event_get info field. */
302};
303
304#define IB_UCM_PRES_DATA 0x01
305#define IB_UCM_PRES_INFO 0x02
306#define IB_UCM_PRES_PRIMARY 0x04
307#define IB_UCM_PRES_ALTERNATE 0x08
308
309struct ib_ucm_event_resp {
310 __u32 id;
311 __u32 event;
312 __u32 present;
313 union {
314 struct ib_ucm_req_event_resp req_resp;
315 struct ib_ucm_rep_event_resp rep_resp;
316 struct ib_ucm_rej_event_resp rej_resp;
317 struct ib_ucm_mra_event_resp mra_resp;
318 struct ib_ucm_lap_event_resp lap_resp;
319 struct ib_ucm_apr_event_resp apr_resp;
320
321 struct ib_ucm_sidr_req_event_resp sidr_req_resp;
322 struct ib_ucm_sidr_rep_event_resp sidr_rep_resp;
323
324 __u32 send_status;
325 } u;
326};
327
328#endif /* IB_USER_CM_H */
diff --git a/drivers/infiniband/include/ib_user_mad.h b/drivers/infiniband/include/ib_user_mad.h
index 06ad4a6075fa..a9a56b50aacc 100644
--- a/drivers/infiniband/include/ib_user_mad.h
+++ b/drivers/infiniband/include/ib_user_mad.h
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (c) 2004 Topspin Communications. All rights reserved. 2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
3 * 4 *
4 * This software is available to you under a choice of one of two 5 * 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 * licenses. You may choose to be licensed under the terms of the GNU
@@ -29,7 +30,7 @@
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE. 31 * SOFTWARE.
31 * 32 *
32 * $Id: ib_user_mad.h 1389 2004-12-27 22:56:47Z roland $ 33 * $Id: ib_user_mad.h 2814 2005-07-06 19:14:09Z halr $
33 */ 34 */
34 35
35#ifndef IB_USER_MAD_H 36#ifndef IB_USER_MAD_H
@@ -42,7 +43,7 @@
42 * Increment this value if any changes that break userspace ABI 43 * Increment this value if any changes that break userspace ABI
43 * compatibility are made. 44 * compatibility are made.
44 */ 45 */
45#define IB_USER_MAD_ABI_VERSION 2 46#define IB_USER_MAD_ABI_VERSION 5
46 47
47/* 48/*
48 * Make sure that all structs defined in this file remain laid out so 49 * Make sure that all structs defined in this file remain laid out so
@@ -51,13 +52,13 @@
51 */ 52 */
52 53
53/** 54/**
54 * ib_user_mad - MAD packet 55 * ib_user_mad_hdr - MAD packet header
55 * @data - Contents of MAD
56 * @id - ID of agent MAD received with/to be sent with 56 * @id - ID of agent MAD received with/to be sent with
57 * @status - 0 on successful receive, ETIMEDOUT if no response 57 * @status - 0 on successful receive, ETIMEDOUT if no response
58 * received (transaction ID in data[] will be set to TID of original 58 * received (transaction ID in data[] will be set to TID of original
59 * request) (ignored on send) 59 * request) (ignored on send)
60 * @timeout_ms - Milliseconds to wait for response (unset on receive) 60 * @timeout_ms - Milliseconds to wait for response (unset on receive)
61 * @retries - Number of automatic retries to attempt
61 * @qpn - Remote QP number received from/to be sent to 62 * @qpn - Remote QP number received from/to be sent to
62 * @qkey - Remote Q_Key to be sent with (unset on receive) 63 * @qkey - Remote Q_Key to be sent with (unset on receive)
63 * @lid - Remote lid received from/to be sent to 64 * @lid - Remote lid received from/to be sent to
@@ -72,11 +73,12 @@
72 * 73 *
73 * All multi-byte quantities are stored in network (big endian) byte order. 74 * All multi-byte quantities are stored in network (big endian) byte order.
74 */ 75 */
75struct ib_user_mad { 76struct ib_user_mad_hdr {
76 __u8 data[256];
77 __u32 id; 77 __u32 id;
78 __u32 status; 78 __u32 status;
79 __u32 timeout_ms; 79 __u32 timeout_ms;
80 __u32 retries;
81 __u32 length;
80 __u32 qpn; 82 __u32 qpn;
81 __u32 qkey; 83 __u32 qkey;
82 __u16 lid; 84 __u16 lid;
@@ -91,6 +93,17 @@ struct ib_user_mad {
91}; 93};
92 94
93/** 95/**
96 * ib_user_mad - MAD packet
97 * @hdr - MAD packet header
98 * @data - Contents of MAD
99 *
100 */
101struct ib_user_mad {
102 struct ib_user_mad_hdr hdr;
103 __u8 data[0];
104};
105
106/**
94 * ib_user_mad_reg_req - MAD registration request 107 * ib_user_mad_reg_req - MAD registration request
95 * @id - Set by the kernel; used to identify agent in future requests. 108 * @id - Set by the kernel; used to identify agent in future requests.
96 * @qpn - Queue pair number; must be 0 or 1. 109 * @qpn - Queue pair number; must be 0 or 1.
@@ -103,6 +116,8 @@ struct ib_user_mad {
103 * management class to receive. 116 * management class to receive.
104 * @oui: Indicates IEEE OUI when mgmt_class is a vendor class 117 * @oui: Indicates IEEE OUI when mgmt_class is a vendor class
105 * in the range from 0x30 to 0x4f. Otherwise not used. 118 * in the range from 0x30 to 0x4f. Otherwise not used.
119 * @rmpp_version: If set, indicates the RMPP version used.
120 *
106 */ 121 */
107struct ib_user_mad_reg_req { 122struct ib_user_mad_reg_req {
108 __u32 id; 123 __u32 id;
@@ -111,6 +126,7 @@ struct ib_user_mad_reg_req {
111 __u8 mgmt_class; 126 __u8 mgmt_class;
112 __u8 mgmt_class_version; 127 __u8 mgmt_class_version;
113 __u8 oui[3]; 128 __u8 oui[3];
129 __u8 rmpp_version;
114}; 130};
115 131
116#define IB_IOCTL_MAGIC 0x1b 132#define IB_IOCTL_MAGIC 0x1b
diff --git a/drivers/infiniband/include/ib_verbs.h b/drivers/infiniband/include/ib_verbs.h
index e5bd9a10c201..5d24edaa66e6 100644
--- a/drivers/infiniband/include/ib_verbs.h
+++ b/drivers/infiniband/include/ib_verbs.h
@@ -289,6 +289,15 @@ struct ib_global_route {
289 u8 traffic_class; 289 u8 traffic_class;
290}; 290};
291 291
292struct ib_grh {
293 u32 version_tclass_flow;
294 u16 paylen;
295 u8 next_hdr;
296 u8 hop_limit;
297 union ib_gid sgid;
298 union ib_gid dgid;
299};
300
292enum { 301enum {
293 IB_MULTICAST_QPN = 0xffffff 302 IB_MULTICAST_QPN = 0xffffff
294}; 303};
@@ -566,6 +575,7 @@ struct ib_send_wr {
566 u32 remote_qpn; 575 u32 remote_qpn;
567 u32 remote_qkey; 576 u32 remote_qkey;
568 int timeout_ms; /* valid for MADs only */ 577 int timeout_ms; /* valid for MADs only */
578 int retries; /* valid for MADs only */
569 u16 pkey_index; /* valid for GSI only */ 579 u16 pkey_index; /* valid for GSI only */
570 u8 port_num; /* valid for DR SMPs on switch only */ 580 u8 port_num; /* valid for DR SMPs on switch only */
571 } ud; 581 } ud;
@@ -990,6 +1000,21 @@ int ib_dealloc_pd(struct ib_pd *pd);
990struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr); 1000struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
991 1001
992/** 1002/**
1003 * ib_create_ah_from_wc - Creates an address handle associated with the
1004 * sender of the specified work completion.
1005 * @pd: The protection domain associated with the address handle.
1006 * @wc: Work completion information associated with a received message.
1007 * @grh: References the received global route header. This parameter is
1008 * ignored unless the work completion indicates that the GRH is valid.
1009 * @port_num: The outbound port number to associate with the address.
1010 *
1011 * The address handle is used to reference a local or global destination
1012 * in all UD QP post sends.
1013 */
1014struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc,
1015 struct ib_grh *grh, u8 port_num);
1016
1017/**
993 * ib_modify_ah - Modifies the address vector associated with an address 1018 * ib_modify_ah - Modifies the address vector associated with an address
994 * handle. 1019 * handle.
995 * @ah: The address handle to modify. 1020 * @ah: The address handle to modify.
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_ib.c b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
index 8238766746b2..eee82363167d 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_ib.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
@@ -81,7 +81,7 @@ void ipoib_free_ah(struct kref *kref)
81 81
82 unsigned long flags; 82 unsigned long flags;
83 83
84 if (ah->last_send <= priv->tx_tail) { 84 if ((int) priv->tx_tail - (int) ah->last_send >= 0) {
85 ipoib_dbg(priv, "Freeing ah %p\n", ah->ah); 85 ipoib_dbg(priv, "Freeing ah %p\n", ah->ah);
86 ib_destroy_ah(ah->ah); 86 ib_destroy_ah(ah->ah);
87 kfree(ah); 87 kfree(ah);
@@ -355,7 +355,7 @@ static void __ipoib_reap_ah(struct net_device *dev)
355 355
356 spin_lock_irq(&priv->lock); 356 spin_lock_irq(&priv->lock);
357 list_for_each_entry_safe(ah, tah, &priv->dead_ahs, list) 357 list_for_each_entry_safe(ah, tah, &priv->dead_ahs, list)
358 if (ah->last_send <= priv->tx_tail) { 358 if ((int) priv->tx_tail - (int) ah->last_send >= 0) {
359 list_del(&ah->list); 359 list_del(&ah->list);
360 list_add_tail(&ah->list, &remove_list); 360 list_add_tail(&ah->list, &remove_list);
361 } 361 }
@@ -486,7 +486,7 @@ int ipoib_ib_dev_stop(struct net_device *dev)
486 * assume the HW is wedged and just free up 486 * assume the HW is wedged and just free up
487 * all our pending work requests. 487 * all our pending work requests.
488 */ 488 */
489 while (priv->tx_tail < priv->tx_head) { 489 while ((int) priv->tx_tail - (int) priv->tx_head < 0) {
490 tx_req = &priv->tx_ring[priv->tx_tail & 490 tx_req = &priv->tx_ring[priv->tx_tail &
491 (IPOIB_TX_RING_SIZE - 1)]; 491 (IPOIB_TX_RING_SIZE - 1)];
492 dma_unmap_single(priv->ca->dma_device, 492 dma_unmap_single(priv->ca->dma_device,
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index 6f60abbaebd5..fa00816a3cf7 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -600,9 +600,10 @@ static int ipoib_start_xmit(struct sk_buff *skb, struct net_device *dev)
600 600
601 ipoib_mcast_send(dev, (union ib_gid *) (phdr->hwaddr + 4), skb); 601 ipoib_mcast_send(dev, (union ib_gid *) (phdr->hwaddr + 4), skb);
602 } else { 602 } else {
603 /* unicast GID -- should be ARP reply */ 603 /* unicast GID -- should be ARP or RARP reply */
604 604
605 if (be16_to_cpup((u16 *) skb->data) != ETH_P_ARP) { 605 if ((be16_to_cpup((__be16 *) skb->data) != ETH_P_ARP) &&
606 (be16_to_cpup((__be16 *) skb->data) != ETH_P_RARP)) {
606 ipoib_warn(priv, "Unicast, no %s: type %04x, QPN %06x " 607 ipoib_warn(priv, "Unicast, no %s: type %04x, QPN %06x "
607 IPOIB_GID_FMT "\n", 608 IPOIB_GID_FMT "\n",
608 skb->dst ? "neigh" : "dst", 609 skb->dst ? "neigh" : "dst",
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 374f404e81da..20e3a165989f 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -320,6 +320,7 @@ static long evdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
320 if (t < 0 || t >= dev->keycodemax || !dev->keycodesize) return -EINVAL; 320 if (t < 0 || t >= dev->keycodemax || !dev->keycodesize) return -EINVAL;
321 if (get_user(v, ip + 1)) return -EFAULT; 321 if (get_user(v, ip + 1)) return -EFAULT;
322 if (v < 0 || v > KEY_MAX) return -EINVAL; 322 if (v < 0 || v > KEY_MAX) return -EINVAL;
323 if (v >> (dev->keycodesize * 8)) return -EINVAL;
323 u = SET_INPUT_KEYCODE(dev, t, v); 324 u = SET_INPUT_KEYCODE(dev, t, v);
324 clear_bit(u, dev->keybit); 325 clear_bit(u, dev->keybit);
325 set_bit(v, dev->keybit); 326 set_bit(v, dev->keybit);
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 7c4b4d37b3e6..a275211c8e1e 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -48,12 +48,6 @@ static LIST_HEAD(input_handler_list);
48 48
49static struct input_handler *input_table[8]; 49static struct input_handler *input_table[8];
50 50
51#ifdef CONFIG_PROC_FS
52static struct proc_dir_entry *proc_bus_input_dir;
53static DECLARE_WAIT_QUEUE_HEAD(input_devices_poll_wait);
54static int input_devices_state;
55#endif
56
57void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) 51void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
58{ 52{
59 struct input_handle *handle; 53 struct input_handle *handle;
@@ -312,6 +306,7 @@ static struct input_device_id *input_match_device(struct input_device_id *id, st
312 return NULL; 306 return NULL;
313} 307}
314 308
309
315/* 310/*
316 * Input hotplugging interface - loading event handlers based on 311 * Input hotplugging interface - loading event handlers based on
317 * device bitfields. 312 * device bitfields.
@@ -428,6 +423,177 @@ static void input_call_hotplug(char *verb, struct input_dev *dev)
428 423
429#endif 424#endif
430 425
426#ifdef CONFIG_PROC_FS
427
428static struct proc_dir_entry *proc_bus_input_dir;
429static DECLARE_WAIT_QUEUE_HEAD(input_devices_poll_wait);
430static int input_devices_state;
431
432static inline void input_wakeup_procfs_readers(void)
433{
434 input_devices_state++;
435 wake_up(&input_devices_poll_wait);
436}
437
438static unsigned int input_devices_poll(struct file *file, poll_table *wait)
439{
440 int state = input_devices_state;
441 poll_wait(file, &input_devices_poll_wait, wait);
442 if (state != input_devices_state)
443 return POLLIN | POLLRDNORM;
444 return 0;
445}
446
447#define SPRINTF_BIT_B(bit, name, max) \
448 do { \
449 len += sprintf(buf + len, "B: %s", name); \
450 for (i = NBITS(max) - 1; i >= 0; i--) \
451 if (dev->bit[i]) break; \
452 for (; i >= 0; i--) \
453 len += sprintf(buf + len, "%lx ", dev->bit[i]); \
454 len += sprintf(buf + len, "\n"); \
455 } while (0)
456
457#define SPRINTF_BIT_B2(bit, name, max, ev) \
458 do { \
459 if (test_bit(ev, dev->evbit)) \
460 SPRINTF_BIT_B(bit, name, max); \
461 } while (0)
462
463static int input_devices_read(char *buf, char **start, off_t pos, int count, int *eof, void *data)
464{
465 struct input_dev *dev;
466 struct input_handle *handle;
467
468 off_t at = 0;
469 int i, len, cnt = 0;
470
471 list_for_each_entry(dev, &input_dev_list, node) {
472
473 len = sprintf(buf, "I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n",
474 dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version);
475
476 len += sprintf(buf + len, "N: Name=\"%s\"\n", dev->name ? dev->name : "");
477 len += sprintf(buf + len, "P: Phys=%s\n", dev->phys ? dev->phys : "");
478 len += sprintf(buf + len, "H: Handlers=");
479
480 list_for_each_entry(handle, &dev->h_list, d_node)
481 len += sprintf(buf + len, "%s ", handle->name);
482
483 len += sprintf(buf + len, "\n");
484
485 SPRINTF_BIT_B(evbit, "EV=", EV_MAX);
486 SPRINTF_BIT_B2(keybit, "KEY=", KEY_MAX, EV_KEY);
487 SPRINTF_BIT_B2(relbit, "REL=", REL_MAX, EV_REL);
488 SPRINTF_BIT_B2(absbit, "ABS=", ABS_MAX, EV_ABS);
489 SPRINTF_BIT_B2(mscbit, "MSC=", MSC_MAX, EV_MSC);
490 SPRINTF_BIT_B2(ledbit, "LED=", LED_MAX, EV_LED);
491 SPRINTF_BIT_B2(sndbit, "SND=", SND_MAX, EV_SND);
492 SPRINTF_BIT_B2(ffbit, "FF=", FF_MAX, EV_FF);
493
494 len += sprintf(buf + len, "\n");
495
496 at += len;
497
498 if (at >= pos) {
499 if (!*start) {
500 *start = buf + (pos - (at - len));
501 cnt = at - pos;
502 } else cnt += len;
503 buf += len;
504 if (cnt >= count)
505 break;
506 }
507 }
508
509 if (&dev->node == &input_dev_list)
510 *eof = 1;
511
512 return (count > cnt) ? cnt : count;
513}
514
515static int input_handlers_read(char *buf, char **start, off_t pos, int count, int *eof, void *data)
516{
517 struct input_handler *handler;
518
519 off_t at = 0;
520 int len = 0, cnt = 0;
521 int i = 0;
522
523 list_for_each_entry(handler, &input_handler_list, node) {
524
525 if (handler->fops)
526 len = sprintf(buf, "N: Number=%d Name=%s Minor=%d\n",
527 i++, handler->name, handler->minor);
528 else
529 len = sprintf(buf, "N: Number=%d Name=%s\n",
530 i++, handler->name);
531
532 at += len;
533
534 if (at >= pos) {
535 if (!*start) {
536 *start = buf + (pos - (at - len));
537 cnt = at - pos;
538 } else cnt += len;
539 buf += len;
540 if (cnt >= count)
541 break;
542 }
543 }
544 if (&handler->node == &input_handler_list)
545 *eof = 1;
546
547 return (count > cnt) ? cnt : count;
548}
549
550static struct file_operations input_fileops;
551
552static int __init input_proc_init(void)
553{
554 struct proc_dir_entry *entry;
555
556 proc_bus_input_dir = proc_mkdir("input", proc_bus);
557 if (!proc_bus_input_dir)
558 return -ENOMEM;
559
560 proc_bus_input_dir->owner = THIS_MODULE;
561
562 entry = create_proc_read_entry("devices", 0, proc_bus_input_dir, input_devices_read, NULL);
563 if (!entry)
564 goto fail1;
565
566 entry->owner = THIS_MODULE;
567 input_fileops = *entry->proc_fops;
568 entry->proc_fops = &input_fileops;
569 entry->proc_fops->poll = input_devices_poll;
570
571 entry = create_proc_read_entry("handlers", 0, proc_bus_input_dir, input_handlers_read, NULL);
572 if (!entry)
573 goto fail2;
574
575 entry->owner = THIS_MODULE;
576
577 return 0;
578
579 fail2: remove_proc_entry("devices", proc_bus_input_dir);
580 fail1: remove_proc_entry("input", proc_bus);
581 return -ENOMEM;
582}
583
584static void input_proc_exit(void)
585{
586 remove_proc_entry("devices", proc_bus_input_dir);
587 remove_proc_entry("handlers", proc_bus_input_dir);
588 remove_proc_entry("input", proc_bus);
589}
590
591#else /* !CONFIG_PROC_FS */
592static inline void input_wakeup_procfs_readers(void) { }
593static inline int input_proc_init(void) { return 0; }
594static inline void input_proc_exit(void) { }
595#endif
596
431void input_register_device(struct input_dev *dev) 597void input_register_device(struct input_dev *dev)
432{ 598{
433 struct input_handle *handle; 599 struct input_handle *handle;
@@ -464,10 +630,7 @@ void input_register_device(struct input_dev *dev)
464 input_call_hotplug("add", dev); 630 input_call_hotplug("add", dev);
465#endif 631#endif
466 632
467#ifdef CONFIG_PROC_FS 633 input_wakeup_procfs_readers();
468 input_devices_state++;
469 wake_up(&input_devices_poll_wait);
470#endif
471} 634}
472 635
473void input_unregister_device(struct input_dev *dev) 636void input_unregister_device(struct input_dev *dev)
@@ -491,10 +654,7 @@ void input_unregister_device(struct input_dev *dev)
491 654
492 list_del_init(&dev->node); 655 list_del_init(&dev->node);
493 656
494#ifdef CONFIG_PROC_FS 657 input_wakeup_procfs_readers();
495 input_devices_state++;
496 wake_up(&input_devices_poll_wait);
497#endif
498} 658}
499 659
500void input_register_handler(struct input_handler *handler) 660void input_register_handler(struct input_handler *handler)
@@ -518,10 +678,7 @@ void input_register_handler(struct input_handler *handler)
518 if ((handle = handler->connect(handler, dev, id))) 678 if ((handle = handler->connect(handler, dev, id)))
519 input_link_handle(handle); 679 input_link_handle(handle);
520 680
521#ifdef CONFIG_PROC_FS 681 input_wakeup_procfs_readers();
522 input_devices_state++;
523 wake_up(&input_devices_poll_wait);
524#endif
525} 682}
526 683
527void input_unregister_handler(struct input_handler *handler) 684void input_unregister_handler(struct input_handler *handler)
@@ -540,10 +697,7 @@ void input_unregister_handler(struct input_handler *handler)
540 if (handler->fops != NULL) 697 if (handler->fops != NULL)
541 input_table[handler->minor >> 5] = NULL; 698 input_table[handler->minor >> 5] = NULL;
542 699
543#ifdef CONFIG_PROC_FS 700 input_wakeup_procfs_readers();
544 input_devices_state++;
545 wake_up(&input_devices_poll_wait);
546#endif
547} 701}
548 702
549static int input_open_file(struct inode *inode, struct file *file) 703static int input_open_file(struct inode *inode, struct file *file)
@@ -582,190 +736,43 @@ static struct file_operations input_fops = {
582 .open = input_open_file, 736 .open = input_open_file,
583}; 737};
584 738
585#ifdef CONFIG_PROC_FS 739struct class *input_class;
586
587#define SPRINTF_BIT_B(bit, name, max) \
588 do { \
589 len += sprintf(buf + len, "B: %s", name); \
590 for (i = NBITS(max) - 1; i >= 0; i--) \
591 if (dev->bit[i]) break; \
592 for (; i >= 0; i--) \
593 len += sprintf(buf + len, "%lx ", dev->bit[i]); \
594 len += sprintf(buf + len, "\n"); \
595 } while (0)
596
597#define SPRINTF_BIT_B2(bit, name, max, ev) \
598 do { \
599 if (test_bit(ev, dev->evbit)) \
600 SPRINTF_BIT_B(bit, name, max); \
601 } while (0)
602
603
604static unsigned int input_devices_poll(struct file *file, poll_table *wait)
605{
606 int state = input_devices_state;
607 poll_wait(file, &input_devices_poll_wait, wait);
608 if (state != input_devices_state)
609 return POLLIN | POLLRDNORM;
610 return 0;
611}
612 740
613static int input_devices_read(char *buf, char **start, off_t pos, int count, int *eof, void *data) 741static int __init input_init(void)
614{ 742{
615 struct input_dev *dev; 743 int err;
616 struct input_handle *handle;
617
618 off_t at = 0;
619 int i, len, cnt = 0;
620
621 list_for_each_entry(dev, &input_dev_list, node) {
622
623 len = sprintf(buf, "I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n",
624 dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version);
625
626 len += sprintf(buf + len, "N: Name=\"%s\"\n", dev->name ? dev->name : "");
627 len += sprintf(buf + len, "P: Phys=%s\n", dev->phys ? dev->phys : "");
628 len += sprintf(buf + len, "H: Handlers=");
629
630 list_for_each_entry(handle, &dev->h_list, d_node)
631 len += sprintf(buf + len, "%s ", handle->name);
632
633 len += sprintf(buf + len, "\n");
634
635 SPRINTF_BIT_B(evbit, "EV=", EV_MAX);
636 SPRINTF_BIT_B2(keybit, "KEY=", KEY_MAX, EV_KEY);
637 SPRINTF_BIT_B2(relbit, "REL=", REL_MAX, EV_REL);
638 SPRINTF_BIT_B2(absbit, "ABS=", ABS_MAX, EV_ABS);
639 SPRINTF_BIT_B2(mscbit, "MSC=", MSC_MAX, EV_MSC);
640 SPRINTF_BIT_B2(ledbit, "LED=", LED_MAX, EV_LED);
641 SPRINTF_BIT_B2(sndbit, "SND=", SND_MAX, EV_SND);
642 SPRINTF_BIT_B2(ffbit, "FF=", FF_MAX, EV_FF);
643
644 len += sprintf(buf + len, "\n");
645
646 at += len;
647 744
648 if (at >= pos) { 745 input_class = class_create(THIS_MODULE, "input");
649 if (!*start) { 746 if (IS_ERR(input_class)) {
650 *start = buf + (pos - (at - len)); 747 printk(KERN_ERR "input: unable to register input class\n");
651 cnt = at - pos; 748 return PTR_ERR(input_class);
652 } else cnt += len;
653 buf += len;
654 if (cnt >= count)
655 break;
656 }
657 } 749 }
658 750
659 if (&dev->node == &input_dev_list) 751 err = input_proc_init();
660 *eof = 1; 752 if (err)
661 753 goto fail1;
662 return (count > cnt) ? cnt : count;
663}
664
665static int input_handlers_read(char *buf, char **start, off_t pos, int count, int *eof, void *data)
666{
667 struct input_handler *handler;
668
669 off_t at = 0;
670 int len = 0, cnt = 0;
671 int i = 0;
672
673 list_for_each_entry(handler, &input_handler_list, node) {
674
675 if (handler->fops)
676 len = sprintf(buf, "N: Number=%d Name=%s Minor=%d\n",
677 i++, handler->name, handler->minor);
678 else
679 len = sprintf(buf, "N: Number=%d Name=%s\n",
680 i++, handler->name);
681
682 at += len;
683 754
684 if (at >= pos) { 755 err = register_chrdev(INPUT_MAJOR, "input", &input_fops);
685 if (!*start) { 756 if (err) {
686 *start = buf + (pos - (at - len)); 757 printk(KERN_ERR "input: unable to register char major %d", INPUT_MAJOR);
687 cnt = at - pos; 758 goto fail2;
688 } else cnt += len;
689 buf += len;
690 if (cnt >= count)
691 break;
692 }
693 } 759 }
694 if (&handler->node == &input_handler_list)
695 *eof = 1;
696
697 return (count > cnt) ? cnt : count;
698}
699
700static struct file_operations input_fileops;
701 760
702static int __init input_proc_init(void) 761 err = devfs_mk_dir("input");
703{ 762 if (err)
704 struct proc_dir_entry *entry; 763 goto fail3;
705 764
706 proc_bus_input_dir = proc_mkdir("input", proc_bus);
707 if (proc_bus_input_dir == NULL)
708 return -ENOMEM;
709 proc_bus_input_dir->owner = THIS_MODULE;
710 entry = create_proc_read_entry("devices", 0, proc_bus_input_dir, input_devices_read, NULL);
711 if (entry == NULL) {
712 remove_proc_entry("input", proc_bus);
713 return -ENOMEM;
714 }
715 entry->owner = THIS_MODULE;
716 input_fileops = *entry->proc_fops;
717 entry->proc_fops = &input_fileops;
718 entry->proc_fops->poll = input_devices_poll;
719 entry = create_proc_read_entry("handlers", 0, proc_bus_input_dir, input_handlers_read, NULL);
720 if (entry == NULL) {
721 remove_proc_entry("devices", proc_bus_input_dir);
722 remove_proc_entry("input", proc_bus);
723 return -ENOMEM;
724 }
725 entry->owner = THIS_MODULE;
726 return 0; 765 return 0;
727}
728#else /* !CONFIG_PROC_FS */
729static inline int input_proc_init(void) { return 0; }
730#endif
731 766
732struct class *input_class; 767 fail3: unregister_chrdev(INPUT_MAJOR, "input");
733 768 fail2: input_proc_exit();
734static int __init input_init(void) 769 fail1: class_destroy(input_class);
735{ 770 return err;
736 int retval = -ENOMEM;
737
738 input_class = class_create(THIS_MODULE, "input");
739 if (IS_ERR(input_class))
740 return PTR_ERR(input_class);
741 input_proc_init();
742 retval = register_chrdev(INPUT_MAJOR, "input", &input_fops);
743 if (retval) {
744 printk(KERN_ERR "input: unable to register char major %d", INPUT_MAJOR);
745 remove_proc_entry("devices", proc_bus_input_dir);
746 remove_proc_entry("handlers", proc_bus_input_dir);
747 remove_proc_entry("input", proc_bus);
748 class_destroy(input_class);
749 return retval;
750 }
751
752 retval = devfs_mk_dir("input");
753 if (retval) {
754 remove_proc_entry("devices", proc_bus_input_dir);
755 remove_proc_entry("handlers", proc_bus_input_dir);
756 remove_proc_entry("input", proc_bus);
757 unregister_chrdev(INPUT_MAJOR, "input");
758 class_destroy(input_class);
759 }
760 return retval;
761} 771}
762 772
763static void __exit input_exit(void) 773static void __exit input_exit(void)
764{ 774{
765 remove_proc_entry("devices", proc_bus_input_dir); 775 input_proc_exit();
766 remove_proc_entry("handlers", proc_bus_input_dir);
767 remove_proc_entry("input", proc_bus);
768
769 devfs_remove("input"); 776 devfs_remove("input");
770 unregister_chrdev(INPUT_MAJOR, "input"); 777 unregister_chrdev(INPUT_MAJOR, "input");
771 class_destroy(input_class); 778 class_destroy(input_class);
diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
index ff8e1bbd0e13..e0938d1d3ad7 100644
--- a/drivers/input/joydev.c
+++ b/drivers/input/joydev.c
@@ -37,8 +37,6 @@ MODULE_LICENSE("GPL");
37#define JOYDEV_MINORS 16 37#define JOYDEV_MINORS 16
38#define JOYDEV_BUFFER_SIZE 64 38#define JOYDEV_BUFFER_SIZE 64
39 39
40#define MSECS(t) (1000 * ((t) / HZ) + 1000 * ((t) % HZ) / HZ)
41
42struct joydev { 40struct joydev {
43 int exist; 41 int exist;
44 int open; 42 int open;
@@ -117,7 +115,7 @@ static void joydev_event(struct input_handle *handle, unsigned int type, unsigne
117 return; 115 return;
118 } 116 }
119 117
120 event.time = MSECS(jiffies); 118 event.time = jiffies_to_msecs(jiffies);
121 119
122 list_for_each_entry(list, &joydev->list, node) { 120 list_for_each_entry(list, &joydev->list, node) {
123 121
@@ -245,7 +243,7 @@ static ssize_t joydev_read(struct file *file, char __user *buf, size_t count, lo
245 243
246 struct js_event event; 244 struct js_event event;
247 245
248 event.time = MSECS(jiffies); 246 event.time = jiffies_to_msecs(jiffies);
249 247
250 if (list->startup < joydev->nkey) { 248 if (list->startup < joydev->nkey) {
251 event.type = JS_EVENT_BUTTON | JS_EVENT_INIT; 249 event.type = JS_EVENT_BUTTON | JS_EVENT_INIT;
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index 98710997aaaa..d5c5b32045af 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -36,16 +36,6 @@
36#include <linux/miscdevice.h> 36#include <linux/miscdevice.h>
37#include <linux/uinput.h> 37#include <linux/uinput.h>
38 38
39static int uinput_dev_open(struct input_dev *dev)
40{
41 return 0;
42}
43
44static void uinput_dev_close(struct input_dev *dev)
45{
46
47}
48
49static int uinput_dev_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) 39static int uinput_dev_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
50{ 40{
51 struct uinput_device *udev; 41 struct uinput_device *udev;
@@ -63,22 +53,24 @@ static int uinput_dev_event(struct input_dev *dev, unsigned int type, unsigned i
63 return 0; 53 return 0;
64} 54}
65 55
66static int uinput_request_alloc_id(struct input_dev *dev, struct uinput_request *request) 56static int uinput_request_alloc_id(struct uinput_device *udev, struct uinput_request *request)
67{ 57{
68 /* Atomically allocate an ID for the given request. Returns 0 on success. */ 58 /* Atomically allocate an ID for the given request. Returns 0 on success. */
69 struct uinput_device *udev = dev->private;
70 int id; 59 int id;
60 int err = -1;
61
62 spin_lock(&udev->requests_lock);
71 63
72 down(&udev->requests_sem); 64 for (id = 0; id < UINPUT_NUM_REQUESTS; id++)
73 for (id=0; id<UINPUT_NUM_REQUESTS; id++)
74 if (!udev->requests[id]) { 65 if (!udev->requests[id]) {
75 udev->requests[id] = request;
76 request->id = id; 66 request->id = id;
77 up(&udev->requests_sem); 67 udev->requests[id] = request;
78 return 0; 68 err = 0;
69 break;
79 } 70 }
80 up(&udev->requests_sem); 71
81 return -1; 72 spin_unlock(&udev->requests_lock);
73 return err;
82} 74}
83 75
84static struct uinput_request* uinput_request_find(struct uinput_device *udev, int id) 76static struct uinput_request* uinput_request_find(struct uinput_device *udev, int id)
@@ -86,70 +78,78 @@ static struct uinput_request* uinput_request_find(struct uinput_device *udev, in
86 /* Find an input request, by ID. Returns NULL if the ID isn't valid. */ 78 /* Find an input request, by ID. Returns NULL if the ID isn't valid. */
87 if (id >= UINPUT_NUM_REQUESTS || id < 0) 79 if (id >= UINPUT_NUM_REQUESTS || id < 0)
88 return NULL; 80 return NULL;
89 if (udev->requests[id]->completed)
90 return NULL;
91 return udev->requests[id]; 81 return udev->requests[id];
92} 82}
93 83
94static void uinput_request_init(struct input_dev *dev, struct uinput_request *request, int code) 84static inline int uinput_request_reserve_slot(struct uinput_device *udev, struct uinput_request *request)
95{ 85{
96 struct uinput_device *udev = dev->private; 86 /* Allocate slot. If none are available right away, wait. */
87 return wait_event_interruptible(udev->requests_waitq,
88 !uinput_request_alloc_id(udev, request));
89}
97 90
98 memset(request, 0, sizeof(struct uinput_request)); 91static void uinput_request_done(struct uinput_device *udev, struct uinput_request *request)
99 request->code = code; 92{
100 init_waitqueue_head(&request->waitq); 93 complete(&request->done);
101 94
102 /* Allocate an ID. If none are available right away, wait. */ 95 /* Mark slot as available */
103 request->retval = wait_event_interruptible(udev->requests_waitq, 96 udev->requests[request->id] = NULL;
104 !uinput_request_alloc_id(dev, request)); 97 wake_up_interruptible(&udev->requests_waitq);
105} 98}
106 99
107static void uinput_request_submit(struct input_dev *dev, struct uinput_request *request) 100static int uinput_request_submit(struct input_dev *dev, struct uinput_request *request)
108{ 101{
109 struct uinput_device *udev = dev->private;
110 int retval; 102 int retval;
111 103
112 /* Tell our userspace app about this new request by queueing an input event */ 104 /* Tell our userspace app about this new request by queueing an input event */
113 uinput_dev_event(dev, EV_UINPUT, request->code, request->id); 105 uinput_dev_event(dev, EV_UINPUT, request->code, request->id);
114 106
115 /* Wait for the request to complete */ 107 /* Wait for the request to complete */
116 retval = wait_event_interruptible(request->waitq, request->completed); 108 retval = wait_for_completion_interruptible(&request->done);
117 if (retval) 109 if (!retval)
118 request->retval = retval; 110 retval = request->retval;
119 111
120 /* Release this request's ID, let others know it's available */ 112 return retval;
121 udev->requests[request->id] = NULL;
122 wake_up_interruptible(&udev->requests_waitq);
123} 113}
124 114
125static int uinput_dev_upload_effect(struct input_dev *dev, struct ff_effect *effect) 115static int uinput_dev_upload_effect(struct input_dev *dev, struct ff_effect *effect)
126{ 116{
127 struct uinput_request request; 117 struct uinput_request request;
118 int retval;
128 119
129 if (!test_bit(EV_FF, dev->evbit)) 120 if (!test_bit(EV_FF, dev->evbit))
130 return -ENOSYS; 121 return -ENOSYS;
131 122
132 uinput_request_init(dev, &request, UI_FF_UPLOAD); 123 request.id = -1;
133 if (request.retval) 124 init_completion(&request.done);
134 return request.retval; 125 request.code = UI_FF_UPLOAD;
135 request.u.effect = effect; 126 request.u.effect = effect;
136 uinput_request_submit(dev, &request); 127
137 return request.retval; 128 retval = uinput_request_reserve_slot(dev->private, &request);
129 if (!retval)
130 retval = uinput_request_submit(dev, &request);
131
132 return retval;
138} 133}
139 134
140static int uinput_dev_erase_effect(struct input_dev *dev, int effect_id) 135static int uinput_dev_erase_effect(struct input_dev *dev, int effect_id)
141{ 136{
142 struct uinput_request request; 137 struct uinput_request request;
138 int retval;
143 139
144 if (!test_bit(EV_FF, dev->evbit)) 140 if (!test_bit(EV_FF, dev->evbit))
145 return -ENOSYS; 141 return -ENOSYS;
146 142
147 uinput_request_init(dev, &request, UI_FF_ERASE); 143 request.id = -1;
148 if (request.retval) 144 init_completion(&request.done);
149 return request.retval; 145 request.code = UI_FF_ERASE;
150 request.u.effect_id = effect_id; 146 request.u.effect_id = effect_id;
151 uinput_request_submit(dev, &request); 147
152 return request.retval; 148 retval = uinput_request_reserve_slot(dev->private, &request);
149 if (!retval)
150 retval = uinput_request_submit(dev, &request);
151
152 return retval;
153} 153}
154 154
155static int uinput_create_device(struct uinput_device *udev) 155static int uinput_create_device(struct uinput_device *udev)
@@ -159,32 +159,30 @@ static int uinput_create_device(struct uinput_device *udev)
159 return -EINVAL; 159 return -EINVAL;
160 } 160 }
161 161
162 udev->dev->open = uinput_dev_open;
163 udev->dev->close = uinput_dev_close;
164 udev->dev->event = uinput_dev_event; 162 udev->dev->event = uinput_dev_event;
165 udev->dev->upload_effect = uinput_dev_upload_effect; 163 udev->dev->upload_effect = uinput_dev_upload_effect;
166 udev->dev->erase_effect = uinput_dev_erase_effect; 164 udev->dev->erase_effect = uinput_dev_erase_effect;
167 udev->dev->private = udev; 165 udev->dev->private = udev;
168 166
169 init_waitqueue_head(&(udev->waitq)); 167 init_waitqueue_head(&udev->waitq);
170 168
171 input_register_device(udev->dev); 169 input_register_device(udev->dev);
172 170
173 set_bit(UIST_CREATED, &(udev->state)); 171 set_bit(UIST_CREATED, &udev->state);
174 172
175 return 0; 173 return 0;
176} 174}
177 175
178static int uinput_destroy_device(struct uinput_device *udev) 176static int uinput_destroy_device(struct uinput_device *udev)
179{ 177{
180 if (!test_bit(UIST_CREATED, &(udev->state))) { 178 if (!test_bit(UIST_CREATED, &udev->state)) {
181 printk(KERN_WARNING "%s: create the device first\n", UINPUT_NAME); 179 printk(KERN_WARNING "%s: create the device first\n", UINPUT_NAME);
182 return -EINVAL; 180 return -EINVAL;
183 } 181 }
184 182
185 input_unregister_device(udev->dev); 183 input_unregister_device(udev->dev);
186 184
187 clear_bit(UIST_CREATED, &(udev->state)); 185 clear_bit(UIST_CREATED, &udev->state);
188 186
189 return 0; 187 return 0;
190} 188}
@@ -198,7 +196,7 @@ static int uinput_open(struct inode *inode, struct file *file)
198 if (!newdev) 196 if (!newdev)
199 goto error; 197 goto error;
200 memset(newdev, 0, sizeof(struct uinput_device)); 198 memset(newdev, 0, sizeof(struct uinput_device));
201 init_MUTEX(&newdev->requests_sem); 199 spin_lock_init(&newdev->requests_lock);
202 init_waitqueue_head(&newdev->requests_waitq); 200 init_waitqueue_head(&newdev->requests_waitq);
203 201
204 newinput = kmalloc(sizeof(struct input_dev), GFP_KERNEL); 202 newinput = kmalloc(sizeof(struct input_dev), GFP_KERNEL);
@@ -253,15 +251,16 @@ static int uinput_alloc_device(struct file *file, const char __user *buffer, siz
253 struct uinput_user_dev *user_dev; 251 struct uinput_user_dev *user_dev;
254 struct input_dev *dev; 252 struct input_dev *dev;
255 struct uinput_device *udev; 253 struct uinput_device *udev;
256 int size, 254 char *name;
257 retval; 255 int size;
256 int retval;
258 257
259 retval = count; 258 retval = count;
260 259
261 udev = file->private_data; 260 udev = file->private_data;
262 dev = udev->dev; 261 dev = udev->dev;
263 262
264 user_dev = kmalloc(sizeof(*user_dev), GFP_KERNEL); 263 user_dev = kmalloc(sizeof(struct uinput_user_dev), GFP_KERNEL);
265 if (!user_dev) { 264 if (!user_dev) {
266 retval = -ENOMEM; 265 retval = -ENOMEM;
267 goto exit; 266 goto exit;
@@ -272,17 +271,17 @@ static int uinput_alloc_device(struct file *file, const char __user *buffer, siz
272 goto exit; 271 goto exit;
273 } 272 }
274 273
275 if (NULL != dev->name) 274 if (dev->name)
276 kfree(dev->name); 275 kfree(dev->name);
277 276
278 size = strnlen(user_dev->name, UINPUT_MAX_NAME_SIZE) + 1; 277 size = strnlen(user_dev->name, UINPUT_MAX_NAME_SIZE) + 1;
279 dev->name = kmalloc(size, GFP_KERNEL); 278 dev->name = name = kmalloc(size, GFP_KERNEL);
280 if (!dev->name) { 279 if (!name) {
281 retval = -ENOMEM; 280 retval = -ENOMEM;
282 goto exit; 281 goto exit;
283 } 282 }
283 strlcpy(name, user_dev->name, size);
284 284
285 strlcpy(dev->name, user_dev->name, size);
286 dev->id.bustype = user_dev->id.bustype; 285 dev->id.bustype = user_dev->id.bustype;
287 dev->id.vendor = user_dev->id.vendor; 286 dev->id.vendor = user_dev->id.vendor;
288 dev->id.product = user_dev->id.product; 287 dev->id.product = user_dev->id.product;
@@ -314,14 +313,13 @@ static ssize_t uinput_write(struct file *file, const char __user *buffer, size_t
314{ 313{
315 struct uinput_device *udev = file->private_data; 314 struct uinput_device *udev = file->private_data;
316 315
317 if (test_bit(UIST_CREATED, &(udev->state))) { 316 if (test_bit(UIST_CREATED, &udev->state)) {
318 struct input_event ev; 317 struct input_event ev;
319 318
320 if (copy_from_user(&ev, buffer, sizeof(struct input_event))) 319 if (copy_from_user(&ev, buffer, sizeof(struct input_event)))
321 return -EFAULT; 320 return -EFAULT;
322 input_event(udev->dev, ev.type, ev.code, ev.value); 321 input_event(udev->dev, ev.type, ev.code, ev.value);
323 } 322 } else
324 else
325 count = uinput_alloc_device(file, buffer, count); 323 count = uinput_alloc_device(file, buffer, count);
326 324
327 return count; 325 return count;
@@ -332,26 +330,24 @@ static ssize_t uinput_read(struct file *file, char __user *buffer, size_t count,
332 struct uinput_device *udev = file->private_data; 330 struct uinput_device *udev = file->private_data;
333 int retval = 0; 331 int retval = 0;
334 332
335 if (!test_bit(UIST_CREATED, &(udev->state))) 333 if (!test_bit(UIST_CREATED, &udev->state))
336 return -ENODEV; 334 return -ENODEV;
337 335
338 if ((udev->head == udev->tail) && (file->f_flags & O_NONBLOCK)) 336 if (udev->head == udev->tail && (file->f_flags & O_NONBLOCK))
339 return -EAGAIN; 337 return -EAGAIN;
340 338
341 retval = wait_event_interruptible(udev->waitq, 339 retval = wait_event_interruptible(udev->waitq,
342 (udev->head != udev->tail) || 340 udev->head != udev->tail || !test_bit(UIST_CREATED, &udev->state));
343 !test_bit(UIST_CREATED, &(udev->state)));
344
345 if (retval) 341 if (retval)
346 return retval; 342 return retval;
347 343
348 if (!test_bit(UIST_CREATED, &(udev->state))) 344 if (!test_bit(UIST_CREATED, &udev->state))
349 return -ENODEV; 345 return -ENODEV;
350 346
351 while ((udev->head != udev->tail) && 347 while ((udev->head != udev->tail) &&
352 (retval + sizeof(struct input_event) <= count)) { 348 (retval + sizeof(struct input_event) <= count)) {
353 if (copy_to_user(buffer + retval, &(udev->buff[udev->tail]), 349 if (copy_to_user(buffer + retval, &udev->buff[udev->tail], sizeof(struct input_event)))
354 sizeof(struct input_event))) return -EFAULT; 350 return -EFAULT;
355 udev->tail = (udev->tail + 1) % UINPUT_BUFFER_SIZE; 351 udev->tail = (udev->tail + 1) % UINPUT_BUFFER_SIZE;
356 retval += sizeof(struct input_event); 352 retval += sizeof(struct input_event);
357 } 353 }
@@ -373,12 +369,12 @@ static unsigned int uinput_poll(struct file *file, poll_table *wait)
373 369
374static int uinput_burn_device(struct uinput_device *udev) 370static int uinput_burn_device(struct uinput_device *udev)
375{ 371{
376 if (test_bit(UIST_CREATED, &(udev->state))) 372 if (test_bit(UIST_CREATED, &udev->state))
377 uinput_destroy_device(udev); 373 uinput_destroy_device(udev);
378 374
379 if (NULL != udev->dev->name) 375 if (udev->dev->name)
380 kfree(udev->dev->name); 376 kfree(udev->dev->name);
381 if (NULL != udev->dev->phys) 377 if (udev->dev->phys)
382 kfree(udev->dev->phys); 378 kfree(udev->dev->phys);
383 379
384 kfree(udev->dev); 380 kfree(udev->dev);
@@ -389,7 +385,8 @@ static int uinput_burn_device(struct uinput_device *udev)
389 385
390static int uinput_close(struct inode *inode, struct file *file) 386static int uinput_close(struct inode *inode, struct file *file)
391{ 387{
392 return uinput_burn_device(file->private_data); 388 uinput_burn_device(file->private_data);
389 return 0;
393} 390}
394 391
395static int uinput_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 392static int uinput_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
@@ -401,6 +398,7 @@ static int uinput_ioctl(struct inode *inode, struct file *file, unsigned int cmd
401 struct uinput_ff_erase ff_erase; 398 struct uinput_ff_erase ff_erase;
402 struct uinput_request *req; 399 struct uinput_request *req;
403 int length; 400 int length;
401 char *phys;
404 402
405 udev = file->private_data; 403 udev = file->private_data;
406 404
@@ -415,7 +413,7 @@ static int uinput_ioctl(struct inode *inode, struct file *file, unsigned int cmd
415 case UI_SET_SNDBIT: 413 case UI_SET_SNDBIT:
416 case UI_SET_FFBIT: 414 case UI_SET_FFBIT:
417 case UI_SET_PHYS: 415 case UI_SET_PHYS:
418 if (test_bit(UIST_CREATED, &(udev->state))) 416 if (test_bit(UIST_CREATED, &udev->state))
419 return -EINVAL; 417 return -EINVAL;
420 } 418 }
421 419
@@ -498,20 +496,19 @@ static int uinput_ioctl(struct inode *inode, struct file *file, unsigned int cmd
498 retval = -EFAULT; 496 retval = -EFAULT;
499 break; 497 break;
500 } 498 }
501 if (NULL != udev->dev->phys) 499 kfree(udev->dev->phys);
502 kfree(udev->dev->phys); 500 udev->dev->phys = phys = kmalloc(length, GFP_KERNEL);
503 udev->dev->phys = kmalloc(length, GFP_KERNEL); 501 if (!phys) {
504 if (!udev->dev->phys) {
505 retval = -ENOMEM; 502 retval = -ENOMEM;
506 break; 503 break;
507 } 504 }
508 if (copy_from_user(udev->dev->phys, p, length)) { 505 if (copy_from_user(phys, p, length)) {
509 retval = -EFAULT;
510 kfree(udev->dev->phys);
511 udev->dev->phys = NULL; 506 udev->dev->phys = NULL;
507 kfree(phys);
508 retval = -EFAULT;
512 break; 509 break;
513 } 510 }
514 udev->dev->phys[length-1] = '\0'; 511 phys[length - 1] = '\0';
515 break; 512 break;
516 513
517 case UI_BEGIN_FF_UPLOAD: 514 case UI_BEGIN_FF_UPLOAD:
@@ -520,7 +517,7 @@ static int uinput_ioctl(struct inode *inode, struct file *file, unsigned int cmd
520 break; 517 break;
521 } 518 }
522 req = uinput_request_find(udev, ff_up.request_id); 519 req = uinput_request_find(udev, ff_up.request_id);
523 if (!(req && req->code==UI_FF_UPLOAD && req->u.effect)) { 520 if (!(req && req->code == UI_FF_UPLOAD && req->u.effect)) {
524 retval = -EINVAL; 521 retval = -EINVAL;
525 break; 522 break;
526 } 523 }
@@ -538,7 +535,7 @@ static int uinput_ioctl(struct inode *inode, struct file *file, unsigned int cmd
538 break; 535 break;
539 } 536 }
540 req = uinput_request_find(udev, ff_erase.request_id); 537 req = uinput_request_find(udev, ff_erase.request_id);
541 if (!(req && req->code==UI_FF_ERASE)) { 538 if (!(req && req->code == UI_FF_ERASE)) {
542 retval = -EINVAL; 539 retval = -EINVAL;
543 break; 540 break;
544 } 541 }
@@ -556,14 +553,13 @@ static int uinput_ioctl(struct inode *inode, struct file *file, unsigned int cmd
556 break; 553 break;
557 } 554 }
558 req = uinput_request_find(udev, ff_up.request_id); 555 req = uinput_request_find(udev, ff_up.request_id);
559 if (!(req && req->code==UI_FF_UPLOAD && req->u.effect)) { 556 if (!(req && req->code == UI_FF_UPLOAD && req->u.effect)) {
560 retval = -EINVAL; 557 retval = -EINVAL;
561 break; 558 break;
562 } 559 }
563 req->retval = ff_up.retval; 560 req->retval = ff_up.retval;
564 memcpy(req->u.effect, &ff_up.effect, sizeof(struct ff_effect)); 561 memcpy(req->u.effect, &ff_up.effect, sizeof(struct ff_effect));
565 req->completed = 1; 562 uinput_request_done(udev, req);
566 wake_up_interruptible(&req->waitq);
567 break; 563 break;
568 564
569 case UI_END_FF_ERASE: 565 case UI_END_FF_ERASE:
@@ -572,13 +568,12 @@ static int uinput_ioctl(struct inode *inode, struct file *file, unsigned int cmd
572 break; 568 break;
573 } 569 }
574 req = uinput_request_find(udev, ff_erase.request_id); 570 req = uinput_request_find(udev, ff_erase.request_id);
575 if (!(req && req->code==UI_FF_ERASE)) { 571 if (!(req && req->code == UI_FF_ERASE)) {
576 retval = -EINVAL; 572 retval = -EINVAL;
577 break; 573 break;
578 } 574 }
579 req->retval = ff_erase.retval; 575 req->retval = ff_erase.retval;
580 req->completed = 1; 576 uinput_request_done(udev, req);
581 wake_up_interruptible(&req->waitq);
582 break; 577 break;
583 578
584 default: 579 default:
diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index a12e98158a75..0d68e5e0182a 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -2,7 +2,7 @@
2 * ALPS touchpad PS/2 mouse driver 2 * ALPS touchpad PS/2 mouse driver
3 * 3 *
4 * Copyright (c) 2003 Neil Brown <neilb@cse.unsw.edu.au> 4 * Copyright (c) 2003 Neil Brown <neilb@cse.unsw.edu.au>
5 * Copyright (c) 2003 Peter Osterlund <petero2@telia.com> 5 * Copyright (c) 2003-2005 Peter Osterlund <petero2@telia.com>
6 * Copyright (c) 2004 Dmitry Torokhov <dtor@mail.ru> 6 * Copyright (c) 2004 Dmitry Torokhov <dtor@mail.ru>
7 * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz> 7 * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
8 * 8 *
@@ -350,7 +350,6 @@ static int alps_tap_mode(struct psmouse *psmouse, int enable)
350static int alps_reconnect(struct psmouse *psmouse) 350static int alps_reconnect(struct psmouse *psmouse)
351{ 351{
352 struct alps_data *priv = psmouse->private; 352 struct alps_data *priv = psmouse->private;
353 unsigned char param[4];
354 int version; 353 int version;
355 354
356 psmouse_reset(psmouse); 355 psmouse_reset(psmouse);
@@ -358,21 +357,20 @@ static int alps_reconnect(struct psmouse *psmouse)
358 if (!(priv->i = alps_get_model(psmouse, &version))) 357 if (!(priv->i = alps_get_model(psmouse, &version)))
359 return -1; 358 return -1;
360 359
361 if (priv->i->flags & ALPS_PASS && alps_passthrough_mode(psmouse, 1)) 360 if ((priv->i->flags & ALPS_PASS) && alps_passthrough_mode(psmouse, 1))
362 return -1; 361 return -1;
363 362
364 if (alps_get_status(psmouse, param)) 363 if (alps_tap_mode(psmouse, 1)) {
364 printk(KERN_WARNING "alps.c: Failed to reenable hardware tapping\n");
365 return -1; 365 return -1;
366 366 }
367 if (!(param[0] & 0x04))
368 alps_tap_mode(psmouse, 1);
369 367
370 if (alps_absolute_mode(psmouse)) { 368 if (alps_absolute_mode(psmouse)) {
371 printk(KERN_ERR "alps.c: Failed to enable absolute mode\n"); 369 printk(KERN_ERR "alps.c: Failed to reenable absolute mode\n");
372 return -1; 370 return -1;
373 } 371 }
374 372
375 if (priv->i->flags == ALPS_PASS && alps_passthrough_mode(psmouse, 0)) 373 if ((priv->i->flags & ALPS_PASS) && alps_passthrough_mode(psmouse, 0))
376 return -1; 374 return -1;
377 375
378 return 0; 376 return 0;
@@ -389,7 +387,6 @@ static void alps_disconnect(struct psmouse *psmouse)
389int alps_init(struct psmouse *psmouse) 387int alps_init(struct psmouse *psmouse)
390{ 388{
391 struct alps_data *priv; 389 struct alps_data *priv;
392 unsigned char param[4];
393 int version; 390 int version;
394 391
395 psmouse->private = priv = kmalloc(sizeof(struct alps_data), GFP_KERNEL); 392 psmouse->private = priv = kmalloc(sizeof(struct alps_data), GFP_KERNEL);
@@ -403,16 +400,8 @@ int alps_init(struct psmouse *psmouse)
403 if ((priv->i->flags & ALPS_PASS) && alps_passthrough_mode(psmouse, 1)) 400 if ((priv->i->flags & ALPS_PASS) && alps_passthrough_mode(psmouse, 1))
404 goto init_fail; 401 goto init_fail;
405 402
406 if (alps_get_status(psmouse, param)) { 403 if (alps_tap_mode(psmouse, 1))
407 printk(KERN_ERR "alps.c: touchpad status report request failed\n"); 404 printk(KERN_WARNING "alps.c: Failed to enable hardware tapping\n");
408 goto init_fail;
409 }
410
411 if (param[0] & 0x04) {
412 printk(KERN_INFO "alps.c: Enabling hardware tapping\n");
413 if (alps_tap_mode(psmouse, 1))
414 printk(KERN_WARNING "alps.c: Failed to enable hardware tapping\n");
415 }
416 405
417 if (alps_absolute_mode(psmouse)) { 406 if (alps_absolute_mode(psmouse)) {
418 printk(KERN_ERR "alps.c: Failed to enable absolute mode\n"); 407 printk(KERN_ERR "alps.c: Failed to enable absolute mode\n");
diff --git a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
index 5ab1bd7d529d..48d2b20d2642 100644
--- a/drivers/input/mouse/logips2pp.c
+++ b/drivers/input/mouse/logips2pp.c
@@ -385,8 +385,6 @@ int ps2pp_init(struct psmouse *psmouse, int set_properties)
385 385
386 if (buttons < 3) 386 if (buttons < 3)
387 clear_bit(BTN_MIDDLE, psmouse->dev.keybit); 387 clear_bit(BTN_MIDDLE, psmouse->dev.keybit);
388 if (buttons < 2)
389 clear_bit(BTN_RIGHT, psmouse->dev.keybit);
390 388
391 if (model_info) 389 if (model_info)
392 ps2pp_set_model_properties(psmouse, model_info, use_ps2pp); 390 ps2pp_set_model_properties(psmouse, model_info, use_ps2pp);
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index 19785a6c5abd..2bb2fe78bdca 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -344,6 +344,7 @@ static int intellimouse_detect(struct psmouse *psmouse, int set_properties)
344 return -1; 344 return -1;
345 345
346 if (set_properties) { 346 if (set_properties) {
347 set_bit(BTN_MIDDLE, psmouse->dev.keybit);
347 set_bit(REL_WHEEL, psmouse->dev.relbit); 348 set_bit(REL_WHEEL, psmouse->dev.relbit);
348 349
349 if (!psmouse->vendor) psmouse->vendor = "Generic"; 350 if (!psmouse->vendor) psmouse->vendor = "Generic";
@@ -376,6 +377,7 @@ static int im_explorer_detect(struct psmouse *psmouse, int set_properties)
376 return -1; 377 return -1;
377 378
378 if (set_properties) { 379 if (set_properties) {
380 set_bit(BTN_MIDDLE, psmouse->dev.keybit);
379 set_bit(REL_WHEEL, psmouse->dev.relbit); 381 set_bit(REL_WHEEL, psmouse->dev.relbit);
380 set_bit(BTN_SIDE, psmouse->dev.keybit); 382 set_bit(BTN_SIDE, psmouse->dev.keybit);
381 set_bit(BTN_EXTRA, psmouse->dev.keybit); 383 set_bit(BTN_EXTRA, psmouse->dev.keybit);
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index 36c721227b68..029309422409 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -219,7 +219,7 @@ static void synaptics_pass_pt_packet(struct serio *ptport, unsigned char *packet
219 serio_interrupt(ptport, packet[1], 0, NULL); 219 serio_interrupt(ptport, packet[1], 0, NULL);
220 serio_interrupt(ptport, packet[4], 0, NULL); 220 serio_interrupt(ptport, packet[4], 0, NULL);
221 serio_interrupt(ptport, packet[5], 0, NULL); 221 serio_interrupt(ptport, packet[5], 0, NULL);
222 if (child->type >= PSMOUSE_GENPS) 222 if (child->pktsize == 4)
223 serio_interrupt(ptport, packet[2], 0, NULL); 223 serio_interrupt(ptport, packet[2], 0, NULL);
224 } else 224 } else
225 serio_interrupt(ptport, packet[1], 0, NULL); 225 serio_interrupt(ptport, packet[1], 0, NULL);
@@ -233,7 +233,7 @@ static void synaptics_pt_activate(struct psmouse *psmouse)
233 233
234 /* adjust the touchpad to child's choice of protocol */ 234 /* adjust the touchpad to child's choice of protocol */
235 if (child) { 235 if (child) {
236 if (child->type >= PSMOUSE_GENPS) 236 if (child->pktsize == 4)
237 priv->mode |= SYN_BIT_FOUR_BYTE_CLIENT; 237 priv->mode |= SYN_BIT_FOUR_BYTE_CLIENT;
238 else 238 else
239 priv->mode &= ~SYN_BIT_FOUR_BYTE_CLIENT; 239 priv->mode &= ~SYN_BIT_FOUR_BYTE_CLIENT;
@@ -608,6 +608,13 @@ static struct dmi_system_id toshiba_dmi_table[] = {
608 DMI_MATCH(DMI_PRODUCT_NAME , "Satellite"), 608 DMI_MATCH(DMI_PRODUCT_NAME , "Satellite"),
609 }, 609 },
610 }, 610 },
611 {
612 .ident = "Toshiba Dynabook",
613 .matches = {
614 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
615 DMI_MATCH(DMI_PRODUCT_NAME , "dynabook"),
616 },
617 },
611 { } 618 { }
612}; 619};
613#endif 620#endif
@@ -656,7 +663,8 @@ int synaptics_init(struct psmouse *psmouse)
656 * thye same as rate of standard PS/2 mouse. 663 * thye same as rate of standard PS/2 mouse.
657 */ 664 */
658 if (psmouse->rate >= 80 && dmi_check_system(toshiba_dmi_table)) { 665 if (psmouse->rate >= 80 && dmi_check_system(toshiba_dmi_table)) {
659 printk(KERN_INFO "synaptics: Toshiba Satellite detected, limiting rate to 40pps.\n"); 666 printk(KERN_INFO "synaptics: Toshiba %s detected, limiting rate to 40pps.\n",
667 dmi_get_system_info(DMI_PRODUCT_NAME));
660 psmouse->rate = 40; 668 psmouse->rate = 40;
661 } 669 }
662#endif 670#endif
diff --git a/drivers/input/serio/Kconfig b/drivers/input/serio/Kconfig
index b3710733b36b..98acf170252c 100644
--- a/drivers/input/serio/Kconfig
+++ b/drivers/input/serio/Kconfig
@@ -175,7 +175,7 @@ config SERIO_RAW
175 allocating minor 1 (that historically corresponds to /dev/psaux) 175 allocating minor 1 (that historically corresponds to /dev/psaux)
176 first. To bind this driver to a serio port use sysfs interface: 176 first. To bind this driver to a serio port use sysfs interface:
177 177
178 echo -n "serio_raw" > /sys/bus/serio/devices/serioX/driver 178 echo -n "serio_raw" > /sys/bus/serio/devices/serioX/drvctl
179 179
180 To compile this driver as a module, choose M here: the 180 To compile this driver as a module, choose M here: the
181 module will be called serio_raw. 181 module will be called serio_raw.
diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
index 0487ecbb8a49..03877c84e6ff 100644
--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -131,12 +131,26 @@ static struct dmi_system_id __initdata i8042_dmi_nomux_table[] = {
131 }, 131 },
132 }, 132 },
133 { 133 {
134 .ident = "Fujitsu-Siemens Lifebook T3010",
135 .matches = {
136 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
137 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK T3010"),
138 },
139 },
140 {
134 .ident = "Toshiba P10", 141 .ident = "Toshiba P10",
135 .matches = { 142 .matches = {
136 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), 143 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
137 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite P10"), 144 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite P10"),
138 }, 145 },
139 }, 146 },
147 {
148 .ident = "Alienware Sentia",
149 .matches = {
150 DMI_MATCH(DMI_SYS_VENDOR, "ALIENWARE"),
151 DMI_MATCH(DMI_PRODUCT_NAME, "Sentia"),
152 },
153 },
140 { } 154 { }
141}; 155};
142 156
diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
index a9bf549c8dc5..708a1d3beab9 100644
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -100,7 +100,7 @@ struct i8042_port {
100static struct i8042_port i8042_ports[I8042_NUM_PORTS] = { 100static struct i8042_port i8042_ports[I8042_NUM_PORTS] = {
101 { 101 {
102 .disable = I8042_CTR_KBDDIS, 102 .disable = I8042_CTR_KBDDIS,
103 .irqen = I8042_CTR_KBDINT, 103 .irqen = I8042_CTR_KBDINT,
104 .mux = -1, 104 .mux = -1,
105 .name = "KBD", 105 .name = "KBD",
106 }, 106 },
@@ -191,41 +191,45 @@ static int i8042_flush(void)
191static int i8042_command(unsigned char *param, int command) 191static int i8042_command(unsigned char *param, int command)
192{ 192{
193 unsigned long flags; 193 unsigned long flags;
194 int retval = 0, i = 0; 194 int i, retval, auxerr = 0;
195 195
196 if (i8042_noloop && command == I8042_CMD_AUX_LOOP) 196 if (i8042_noloop && command == I8042_CMD_AUX_LOOP)
197 return -1; 197 return -1;
198 198
199 spin_lock_irqsave(&i8042_lock, flags); 199 spin_lock_irqsave(&i8042_lock, flags);
200 200
201 retval = i8042_wait_write(); 201 if ((retval = i8042_wait_write()))
202 if (!retval) { 202 goto out;
203 dbg("%02x -> i8042 (command)", command & 0xff); 203
204 i8042_write_command(command & 0xff); 204 dbg("%02x -> i8042 (command)", command & 0xff);
205 i8042_write_command(command & 0xff);
206
207 for (i = 0; i < ((command >> 12) & 0xf); i++) {
208 if ((retval = i8042_wait_write()))
209 goto out;
210 dbg("%02x -> i8042 (parameter)", param[i]);
211 i8042_write_data(param[i]);
205 } 212 }
206 213
207 if (!retval) 214 for (i = 0; i < ((command >> 8) & 0xf); i++) {
208 for (i = 0; i < ((command >> 12) & 0xf); i++) { 215 if ((retval = i8042_wait_read()))
209 if ((retval = i8042_wait_write())) break; 216 goto out;
210 dbg("%02x -> i8042 (parameter)", param[i]);
211 i8042_write_data(param[i]);
212 }
213 217
214 if (!retval) 218 if (command == I8042_CMD_AUX_LOOP &&
215 for (i = 0; i < ((command >> 8) & 0xf); i++) { 219 !(i8042_read_status() & I8042_STR_AUXDATA)) {
216 if ((retval = i8042_wait_read())) break; 220 retval = auxerr = -1;
217 if (i8042_read_status() & I8042_STR_AUXDATA) 221 goto out;
218 param[i] = ~i8042_read_data();
219 else
220 param[i] = i8042_read_data();
221 dbg("%02x <- i8042 (return)", param[i]);
222 } 222 }
223 223
224 spin_unlock_irqrestore(&i8042_lock, flags); 224 param[i] = i8042_read_data();
225 dbg("%02x <- i8042 (return)", param[i]);
226 }
225 227
226 if (retval) 228 if (retval)
227 dbg(" -- i8042 (timeout)"); 229 dbg(" -- i8042 (%s)", auxerr ? "auxerr" : "timeout");
228 230
231 out:
232 spin_unlock_irqrestore(&i8042_lock, flags);
229 return retval; 233 return retval;
230} 234}
231 235
@@ -507,17 +511,17 @@ static int i8042_set_mux_mode(unsigned int mode, unsigned char *mux_version)
507 */ 511 */
508 512
509 param = 0xf0; 513 param = 0xf0;
510 if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param != 0x0f) 514 if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param != 0xf0)
511 return -1; 515 return -1;
512 param = mode ? 0x56 : 0xf6; 516 param = mode ? 0x56 : 0xf6;
513 if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param != (mode ? 0xa9 : 0x09)) 517 if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param != (mode ? 0x56 : 0xf6))
514 return -1; 518 return -1;
515 param = mode ? 0xa4 : 0xa5; 519 param = mode ? 0xa4 : 0xa5;
516 if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param == (mode ? 0x5b : 0x5a)) 520 if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param == (mode ? 0xa4 : 0xa5))
517 return -1; 521 return -1;
518 522
519 if (mux_version) 523 if (mux_version)
520 *mux_version = ~param; 524 *mux_version = param;
521 525
522 return 0; 526 return 0;
523} 527}
@@ -619,7 +623,7 @@ static int __init i8042_check_aux(void)
619 */ 623 */
620 624
621 param = 0x5a; 625 param = 0x5a;
622 if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param != 0xa5) { 626 if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param != 0x5a) {
623 627
624/* 628/*
625 * External connection test - filters out AT-soldered PS/2 i8042's 629 * External connection test - filters out AT-soldered PS/2 i8042's
@@ -630,7 +634,7 @@ static int __init i8042_check_aux(void)
630 */ 634 */
631 635
632 if (i8042_command(&param, I8042_CMD_AUX_TEST) 636 if (i8042_command(&param, I8042_CMD_AUX_TEST)
633 || (param && param != 0xfa && param != 0xff)) 637 || (param && param != 0xfa && param != 0xff))
634 return -1; 638 return -1;
635 } 639 }
636 640
diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
index f367695e69b5..edd15db17715 100644
--- a/drivers/input/serio/serio.c
+++ b/drivers/input/serio/serio.c
@@ -389,6 +389,14 @@ static ssize_t serio_show_description(struct device *dev, struct device_attribut
389 return sprintf(buf, "%s\n", serio->name); 389 return sprintf(buf, "%s\n", serio->name);
390} 390}
391 391
392static ssize_t serio_show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
393{
394 struct serio *serio = to_serio_port(dev);
395
396 return sprintf(buf, "serio:ty%02Xpr%02Xid%02Xex%02X\n",
397 serio->id.type, serio->id.proto, serio->id.id, serio->id.extra);
398}
399
392static ssize_t serio_show_id_type(struct device *dev, struct device_attribute *attr, char *buf) 400static ssize_t serio_show_id_type(struct device *dev, struct device_attribute *attr, char *buf)
393{ 401{
394 struct serio *serio = to_serio_port(dev); 402 struct serio *serio = to_serio_port(dev);
@@ -487,6 +495,7 @@ static ssize_t serio_set_bind_mode(struct device *dev, struct device_attribute *
487 495
488static struct device_attribute serio_device_attrs[] = { 496static struct device_attribute serio_device_attrs[] = {
489 __ATTR(description, S_IRUGO, serio_show_description, NULL), 497 __ATTR(description, S_IRUGO, serio_show_description, NULL),
498 __ATTR(modalias, S_IRUGO, serio_show_modalias, NULL),
490 __ATTR(drvctl, S_IWUSR, NULL, serio_rebind_driver), 499 __ATTR(drvctl, S_IWUSR, NULL, serio_rebind_driver),
491 __ATTR(bind_mode, S_IWUSR | S_IRUGO, serio_show_bind_mode, serio_set_bind_mode), 500 __ATTR(bind_mode, S_IWUSR | S_IRUGO, serio_show_bind_mode, serio_set_bind_mode),
492 __ATTR_NULL 501 __ATTR_NULL
@@ -785,36 +794,37 @@ static int serio_bus_match(struct device *dev, struct device_driver *drv)
785 794
786#ifdef CONFIG_HOTPLUG 795#ifdef CONFIG_HOTPLUG
787 796
788#define PUT_ENVP(fmt, val) \ 797#define SERIO_ADD_HOTPLUG_VAR(fmt, val...) \
789do { \ 798 do { \
790 envp[i++] = buffer; \ 799 int err = add_hotplug_env_var(envp, num_envp, &i, \
791 length += snprintf(buffer, buffer_size - length, fmt, val); \ 800 buffer, buffer_size, &len, \
792 if (buffer_size - length <= 0 || i >= num_envp) \ 801 fmt, val); \
793 return -ENOMEM; \ 802 if (err) \
794 length++; \ 803 return err; \
795 buffer += length; \ 804 } while (0)
796} while (0) 805
797static int serio_hotplug(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size) 806static int serio_hotplug(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size)
798{ 807{
799 struct serio *serio; 808 struct serio *serio;
800 int i = 0; 809 int i = 0;
801 int length = 0; 810 int len = 0;
802 811
803 if (!dev) 812 if (!dev)
804 return -ENODEV; 813 return -ENODEV;
805 814
806 serio = to_serio_port(dev); 815 serio = to_serio_port(dev);
807 816
808 PUT_ENVP("SERIO_TYPE=%02x", serio->id.type); 817 SERIO_ADD_HOTPLUG_VAR("SERIO_TYPE=%02x", serio->id.type);
809 PUT_ENVP("SERIO_PROTO=%02x", serio->id.proto); 818 SERIO_ADD_HOTPLUG_VAR("SERIO_PROTO=%02x", serio->id.proto);
810 PUT_ENVP("SERIO_ID=%02x", serio->id.id); 819 SERIO_ADD_HOTPLUG_VAR("SERIO_ID=%02x", serio->id.id);
811 PUT_ENVP("SERIO_EXTRA=%02x", serio->id.extra); 820 SERIO_ADD_HOTPLUG_VAR("SERIO_EXTRA=%02x", serio->id.extra);
812 821 SERIO_ADD_HOTPLUG_VAR("MODALIAS=serio:ty%02Xpr%02Xid%02Xex%02X",
822 serio->id.type, serio->id.proto, serio->id.id, serio->id.extra);
813 envp[i] = NULL; 823 envp[i] = NULL;
814 824
815 return 0; 825 return 0;
816} 826}
817#undef PUT_ENVP 827#undef SERIO_ADD_HOTPLUG_VAR
818 828
819#else 829#else
820 830
diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
index d914e7e93db4..47e08de18d07 100644
--- a/drivers/input/serio/serio_raw.c
+++ b/drivers/input/serio/serio_raw.c
@@ -299,6 +299,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
299 299
300 serio_raw->dev.minor = PSMOUSE_MINOR; 300 serio_raw->dev.minor = PSMOUSE_MINOR;
301 serio_raw->dev.name = serio_raw->name; 301 serio_raw->dev.name = serio_raw->name;
302 serio_raw->dev.dev = &serio->dev;
302 serio_raw->dev.fops = &serio_raw_fops; 303 serio_raw->dev.fops = &serio_raw_fops;
303 304
304 err = misc_register(&serio_raw->dev); 305 err = misc_register(&serio_raw->dev);
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 7e991274ea40..0489af5a80c9 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -58,7 +58,7 @@ config TOUCHSCREEN_ELO
58 If unsure, say N. 58 If unsure, say N.
59 59
60 To compile this driver as a module, choose M here: the 60 To compile this driver as a module, choose M here: the
61 module will be called gunze. 61 module will be called elo.
62 62
63config TOUCHSCREEN_MTOUCH 63config TOUCHSCREEN_MTOUCH
64 tristate "MicroTouch serial touchscreens" 64 tristate "MicroTouch serial touchscreens"
diff --git a/drivers/isdn/hisax/avm_a1.c b/drivers/isdn/hisax/avm_a1.c
index 8f028d42fd2f..9a8b02557ff9 100644
--- a/drivers/isdn/hisax/avm_a1.c
+++ b/drivers/isdn/hisax/avm_a1.c
@@ -135,7 +135,7 @@ avm_a1_interrupt(int intno, void *dev_id, struct pt_regs *regs)
135 return IRQ_HANDLED; 135 return IRQ_HANDLED;
136} 136}
137 137
138inline static void 138static inline void
139release_ioregs(struct IsdnCardState *cs, int mask) 139release_ioregs(struct IsdnCardState *cs, int mask)
140{ 140{
141 release_region(cs->hw.avm.cfg_reg, 8); 141 release_region(cs->hw.avm.cfg_reg, 8);
diff --git a/drivers/isdn/hisax/config.c b/drivers/isdn/hisax/config.c
index c542e6fb2bde..fbaab4352902 100644
--- a/drivers/isdn/hisax/config.c
+++ b/drivers/isdn/hisax/config.c
@@ -1900,6 +1900,7 @@ static struct pci_device_id hisax_pci_tbl[] __initdata = {
1900 {PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_R685, PCI_ANY_ID, PCI_ANY_ID}, 1900 {PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_R685, PCI_ANY_ID, PCI_ANY_ID},
1901 {PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_R753, PCI_ANY_ID, PCI_ANY_ID}, 1901 {PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_R753, PCI_ANY_ID, PCI_ANY_ID},
1902 {PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_DJINN_ITOO, PCI_ANY_ID, PCI_ANY_ID}, 1902 {PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_DJINN_ITOO, PCI_ANY_ID, PCI_ANY_ID},
1903 {PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_OLITEC, PCI_ANY_ID, PCI_ANY_ID},
1903#endif 1904#endif
1904#ifdef CONFIG_HISAX_QUADRO 1905#ifdef CONFIG_HISAX_QUADRO
1905 {PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050, PCI_ANY_ID, PCI_ANY_ID}, 1906 {PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050, PCI_ANY_ID, PCI_ANY_ID},
diff --git a/drivers/isdn/hisax/gazel.c b/drivers/isdn/hisax/gazel.c
index 352b45ac5347..60b04c6d9e7d 100644
--- a/drivers/isdn/hisax/gazel.c
+++ b/drivers/isdn/hisax/gazel.c
@@ -546,8 +546,9 @@ setup_gazelpci(struct IsdnCardState *cs)
546 546
547 found = 0; 547 found = 0;
548 seekcard = PCI_DEVICE_ID_PLX_R685; 548 seekcard = PCI_DEVICE_ID_PLX_R685;
549 for (nbseek = 0; nbseek < 3; nbseek++) { 549 for (nbseek = 0; nbseek < 4; nbseek++) {
550 if ((dev_tel = pci_find_device(PCI_VENDOR_ID_PLX, seekcard, dev_tel))) { 550 if ((dev_tel = pci_find_device(PCI_VENDOR_ID_PLX,
551 seekcard, dev_tel))) {
551 if (pci_enable_device(dev_tel)) 552 if (pci_enable_device(dev_tel))
552 return 1; 553 return 1;
553 pci_irq = dev_tel->irq; 554 pci_irq = dev_tel->irq;
@@ -565,6 +566,9 @@ setup_gazelpci(struct IsdnCardState *cs)
565 case PCI_DEVICE_ID_PLX_R753: 566 case PCI_DEVICE_ID_PLX_R753:
566 seekcard = PCI_DEVICE_ID_PLX_DJINN_ITOO; 567 seekcard = PCI_DEVICE_ID_PLX_DJINN_ITOO;
567 break; 568 break;
569 case PCI_DEVICE_ID_PLX_DJINN_ITOO:
570 seekcard = PCI_DEVICE_ID_PLX_OLITEC;
571 break;
568 } 572 }
569 } 573 }
570 } 574 }
@@ -605,6 +609,7 @@ setup_gazelpci(struct IsdnCardState *cs)
605 break; 609 break;
606 case PCI_DEVICE_ID_PLX_R753: 610 case PCI_DEVICE_ID_PLX_R753:
607 case PCI_DEVICE_ID_PLX_DJINN_ITOO: 611 case PCI_DEVICE_ID_PLX_DJINN_ITOO:
612 case PCI_DEVICE_ID_PLX_OLITEC:
608 printk(KERN_INFO "Gazel: Card PCI R753 found\n"); 613 printk(KERN_INFO "Gazel: Card PCI R753 found\n");
609 cs->subtyp = R753; 614 cs->subtyp = R753;
610 test_and_set_bit(HW_IPAC, &cs->HW_Flags); 615 test_and_set_bit(HW_IPAC, &cs->HW_Flags);
diff --git a/drivers/isdn/hisax/isdnl2.c b/drivers/isdn/hisax/isdnl2.c
index 1615c1a76ab8..6d0431725555 100644
--- a/drivers/isdn/hisax/isdnl2.c
+++ b/drivers/isdn/hisax/isdnl2.c
@@ -213,7 +213,7 @@ sethdraddr(struct Layer2 *l2, u_char * header, int rsp)
213 } 213 }
214} 214}
215 215
216inline static void 216static inline void
217enqueue_super(struct PStack *st, 217enqueue_super(struct PStack *st,
218 struct sk_buff *skb) 218 struct sk_buff *skb)
219{ 219{
diff --git a/drivers/isdn/hisax/l3dss1.c b/drivers/isdn/hisax/l3dss1.c
index a6d2abdb478a..e96845cdd4f6 100644
--- a/drivers/isdn/hisax/l3dss1.c
+++ b/drivers/isdn/hisax/l3dss1.c
@@ -353,7 +353,7 @@ l3dss1_parse_facility(struct PStack *st, struct l3_process *pc,
353 { l3dss1_dummy_invoke(st, cr, id, ident, p, nlen); 353 { l3dss1_dummy_invoke(st, cr, id, ident, p, nlen);
354 return; 354 return;
355 } 355 }
356#if HISAX_DE_AOC 356#ifdef HISAX_DE_AOC
357 { 357 {
358 358
359#define FOO1(s,a,b) \ 359#define FOO1(s,a,b) \
@@ -977,7 +977,7 @@ l3dss1_release_cmpl(struct l3_process *pc, u_char pr, void *arg)
977 dss1_release_l3_process(pc); 977 dss1_release_l3_process(pc);
978} 978}
979 979
980#if EXT_BEARER_CAPS 980#ifdef EXT_BEARER_CAPS
981 981
982static u_char * 982static u_char *
983EncodeASyncParams(u_char * p, u_char si2) 983EncodeASyncParams(u_char * p, u_char si2)
@@ -1369,7 +1369,7 @@ l3dss1_setup_req(struct l3_process *pc, u_char pr,
1369 *p++ = *sub++ & 0x7f; 1369 *p++ = *sub++ & 0x7f;
1370 } 1370 }
1371 } 1371 }
1372#if EXT_BEARER_CAPS 1372#ifdef EXT_BEARER_CAPS
1373 if ((pc->para.setup.si2 >= 160) && (pc->para.setup.si2 <= 175)) { // sync. Bitratenadaption, V.110/X.30 1373 if ((pc->para.setup.si2 >= 160) && (pc->para.setup.si2 <= 175)) { // sync. Bitratenadaption, V.110/X.30
1374 1374
1375 *p++ = IE_LLC; 1375 *p++ = IE_LLC;
@@ -1609,7 +1609,7 @@ l3dss1_setup(struct l3_process *pc, u_char pr, void *arg)
1609 case 0x08: /* Unrestricted digital information */ 1609 case 0x08: /* Unrestricted digital information */
1610 pc->para.setup.si1 = 7; 1610 pc->para.setup.si1 = 7;
1611/* JIM, 05.11.97 I wanna set service indicator 2 */ 1611/* JIM, 05.11.97 I wanna set service indicator 2 */
1612#if EXT_BEARER_CAPS 1612#ifdef EXT_BEARER_CAPS
1613 pc->para.setup.si2 = DecodeSI2(skb); 1613 pc->para.setup.si2 = DecodeSI2(skb);
1614#endif 1614#endif
1615 break; 1615 break;
diff --git a/drivers/isdn/hisax/teles3.c b/drivers/isdn/hisax/teles3.c
index adeaad62d35c..a3eaf4d65707 100644
--- a/drivers/isdn/hisax/teles3.c
+++ b/drivers/isdn/hisax/teles3.c
@@ -143,7 +143,7 @@ teles3_interrupt(int intno, void *dev_id, struct pt_regs *regs)
143 return IRQ_HANDLED; 143 return IRQ_HANDLED;
144} 144}
145 145
146inline static void 146static inline void
147release_ioregs(struct IsdnCardState *cs, int mask) 147release_ioregs(struct IsdnCardState *cs, int mask)
148{ 148{
149 if (mask & 1) 149 if (mask & 1)
diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
index e0d1b01cc74c..386df71eee74 100644
--- a/drivers/isdn/icn/icn.c
+++ b/drivers/isdn/icn/icn.c
@@ -1650,7 +1650,7 @@ static void __exit icn_exit(void)
1650{ 1650{
1651 isdn_ctrl cmd; 1651 isdn_ctrl cmd;
1652 icn_card *card = cards; 1652 icn_card *card = cards;
1653 icn_card *last; 1653 icn_card *last, *tmpcard;
1654 int i; 1654 int i;
1655 unsigned long flags; 1655 unsigned long flags;
1656 1656
@@ -1670,8 +1670,9 @@ static void __exit icn_exit(void)
1670 for (i = 0; i < ICN_BCH; i++) 1670 for (i = 0; i < ICN_BCH; i++)
1671 icn_free_queue(card, i); 1671 icn_free_queue(card, i);
1672 } 1672 }
1673 card = card->next; 1673 tmpcard = card->next;
1674 spin_unlock_irqrestore(&card->lock, flags); 1674 spin_unlock_irqrestore(&card->lock, flags);
1675 card = tmpcard;
1675 } 1676 }
1676 card = cards; 1677 card = cards;
1677 cards = NULL; 1678 cards = NULL;
diff --git a/drivers/macintosh/Kconfig b/drivers/macintosh/Kconfig
index 91691a6c004e..65ab64c43b3e 100644
--- a/drivers/macintosh/Kconfig
+++ b/drivers/macintosh/Kconfig
@@ -4,7 +4,7 @@ menu "Macintosh device drivers"
4 4
5config ADB 5config ADB
6 bool "Apple Desktop Bus (ADB) support" 6 bool "Apple Desktop Bus (ADB) support"
7 depends on MAC || PPC_PMAC 7 depends on MAC || (PPC_PMAC && PPC32)
8 help 8 help
9 Apple Desktop Bus (ADB) support is for support of devices which 9 Apple Desktop Bus (ADB) support is for support of devices which
10 are connected to an ADB port. ADB devices tend to have 4 pins. 10 are connected to an ADB port. ADB devices tend to have 4 pins.
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 0c2ed99a3832..41df4cda66e2 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -108,7 +108,7 @@ static unsigned char *bitmap_alloc_page(struct bitmap *bitmap)
108{ 108{
109 unsigned char *page; 109 unsigned char *page;
110 110
111#if INJECT_FAULTS_1 111#ifdef INJECT_FAULTS_1
112 page = NULL; 112 page = NULL;
113#else 113#else
114 page = kmalloc(PAGE_SIZE, GFP_NOIO); 114 page = kmalloc(PAGE_SIZE, GFP_NOIO);
@@ -818,8 +818,7 @@ int bitmap_unplug(struct bitmap *bitmap)
818 return 0; 818 return 0;
819} 819}
820 820
821static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, 821static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset);
822 unsigned long sectors, int in_sync);
823/* * bitmap_init_from_disk -- called at bitmap_create time to initialize 822/* * bitmap_init_from_disk -- called at bitmap_create time to initialize
824 * the in-memory bitmap from the on-disk bitmap -- also, sets up the 823 * the in-memory bitmap from the on-disk bitmap -- also, sets up the
825 * memory mapping of the bitmap file 824 * memory mapping of the bitmap file
@@ -828,7 +827,7 @@ static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset,
828 * previously kicked from the array, we mark all the bits as 827 * previously kicked from the array, we mark all the bits as
829 * 1's in order to cause a full resync. 828 * 1's in order to cause a full resync.
830 */ 829 */
831static int bitmap_init_from_disk(struct bitmap *bitmap, int in_sync) 830static int bitmap_init_from_disk(struct bitmap *bitmap)
832{ 831{
833 unsigned long i, chunks, index, oldindex, bit; 832 unsigned long i, chunks, index, oldindex, bit;
834 struct page *page = NULL, *oldpage = NULL; 833 struct page *page = NULL, *oldpage = NULL;
@@ -843,7 +842,7 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, int in_sync)
843 842
844 BUG_ON(!file && !bitmap->offset); 843 BUG_ON(!file && !bitmap->offset);
845 844
846#if INJECT_FAULTS_3 845#ifdef INJECT_FAULTS_3
847 outofdate = 1; 846 outofdate = 1;
848#else 847#else
849 outofdate = bitmap->flags & BITMAP_STALE; 848 outofdate = bitmap->flags & BITMAP_STALE;
@@ -929,8 +928,7 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, int in_sync)
929 } 928 }
930 if (test_bit(bit, page_address(page))) { 929 if (test_bit(bit, page_address(page))) {
931 /* if the disk bit is set, set the memory bit */ 930 /* if the disk bit is set, set the memory bit */
932 bitmap_set_memory_bits(bitmap, 931 bitmap_set_memory_bits(bitmap, i << CHUNK_BLOCK_SHIFT(bitmap));
933 i << CHUNK_BLOCK_SHIFT(bitmap), 1, in_sync);
934 bit_cnt++; 932 bit_cnt++;
935 } 933 }
936 } 934 }
@@ -1187,7 +1185,7 @@ static int bitmap_start_daemon(struct bitmap *bitmap, mdk_thread_t **ptr,
1187 1185
1188 spin_unlock_irqrestore(&bitmap->lock, flags); 1186 spin_unlock_irqrestore(&bitmap->lock, flags);
1189 1187
1190#if INJECT_FATAL_FAULT_2 1188#ifdef INJECT_FATAL_FAULT_2
1191 daemon = NULL; 1189 daemon = NULL;
1192#else 1190#else
1193 sprintf(namebuf, "%%s_%s", name); 1191 sprintf(namebuf, "%%s_%s", name);
@@ -1426,35 +1424,53 @@ void bitmap_close_sync(struct bitmap *bitmap)
1426 } 1424 }
1427} 1425}
1428 1426
1429static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, 1427static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset)
1430 unsigned long sectors, int in_sync)
1431{ 1428{
1432 /* For each chunk covered by any of these sectors, set the 1429 /* For each chunk covered by any of these sectors, set the
1433 * counter to 1 and set resync_needed unless in_sync. They should all 1430 * counter to 1 and set resync_needed. They should all
1434 * be 0 at this point 1431 * be 0 at this point
1435 */ 1432 */
1436 while (sectors) { 1433
1437 int secs; 1434 int secs;
1438 bitmap_counter_t *bmc; 1435 bitmap_counter_t *bmc;
1439 spin_lock_irq(&bitmap->lock); 1436 spin_lock_irq(&bitmap->lock);
1440 bmc = bitmap_get_counter(bitmap, offset, &secs, 1); 1437 bmc = bitmap_get_counter(bitmap, offset, &secs, 1);
1441 if (!bmc) { 1438 if (!bmc) {
1442 spin_unlock_irq(&bitmap->lock);
1443 return;
1444 }
1445 if (! *bmc) {
1446 struct page *page;
1447 *bmc = 1 | (in_sync? 0 : NEEDED_MASK);
1448 bitmap_count_page(bitmap, offset, 1);
1449 page = filemap_get_page(bitmap, offset >> CHUNK_BLOCK_SHIFT(bitmap));
1450 set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN);
1451 }
1452 spin_unlock_irq(&bitmap->lock); 1439 spin_unlock_irq(&bitmap->lock);
1453 if (sectors > secs) 1440 return;
1454 sectors -= secs; 1441 }
1455 else 1442 if (! *bmc) {
1456 sectors = 0; 1443 struct page *page;
1444 *bmc = 1 | NEEDED_MASK;
1445 bitmap_count_page(bitmap, offset, 1);
1446 page = filemap_get_page(bitmap, offset >> CHUNK_BLOCK_SHIFT(bitmap));
1447 set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN);
1457 } 1448 }
1449 spin_unlock_irq(&bitmap->lock);
1450
1451}
1452
1453/*
1454 * flush out any pending updates
1455 */
1456void bitmap_flush(mddev_t *mddev)
1457{
1458 struct bitmap *bitmap = mddev->bitmap;
1459 int sleep;
1460
1461 if (!bitmap) /* there was no bitmap */
1462 return;
1463
1464 /* run the daemon_work three time to ensure everything is flushed
1465 * that can be
1466 */
1467 sleep = bitmap->daemon_sleep;
1468 bitmap->daemon_sleep = 0;
1469 bitmap_daemon_work(bitmap);
1470 bitmap_daemon_work(bitmap);
1471 bitmap_daemon_work(bitmap);
1472 bitmap->daemon_sleep = sleep;
1473 bitmap_update_sb(bitmap);
1458} 1474}
1459 1475
1460/* 1476/*
@@ -1552,7 +1568,7 @@ int bitmap_create(mddev_t *mddev)
1552 1568
1553 bitmap->syncchunk = ~0UL; 1569 bitmap->syncchunk = ~0UL;
1554 1570
1555#if INJECT_FATAL_FAULT_1 1571#ifdef INJECT_FATAL_FAULT_1
1556 bitmap->bp = NULL; 1572 bitmap->bp = NULL;
1557#else 1573#else
1558 bitmap->bp = kmalloc(pages * sizeof(*bitmap->bp), GFP_KERNEL); 1574 bitmap->bp = kmalloc(pages * sizeof(*bitmap->bp), GFP_KERNEL);
@@ -1565,7 +1581,8 @@ int bitmap_create(mddev_t *mddev)
1565 1581
1566 /* now that we have some pages available, initialize the in-memory 1582 /* now that we have some pages available, initialize the in-memory
1567 * bitmap from the on-disk bitmap */ 1583 * bitmap from the on-disk bitmap */
1568 err = bitmap_init_from_disk(bitmap, mddev->recovery_cp == MaxSector); 1584 err = bitmap_init_from_disk(bitmap);
1585
1569 if (err) 1586 if (err)
1570 return err; 1587 return err;
1571 1588
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
index 12031c9d3f1e..b08df8b9b2ca 100644
--- a/drivers/md/dm-raid1.c
+++ b/drivers/md/dm-raid1.c
@@ -1230,7 +1230,7 @@ static int __init dm_mirror_init(void)
1230 if (r) 1230 if (r)
1231 return r; 1231 return r;
1232 1232
1233 _kmirrord_wq = create_workqueue("kmirrord"); 1233 _kmirrord_wq = create_singlethread_workqueue("kmirrord");
1234 if (!_kmirrord_wq) { 1234 if (!_kmirrord_wq) {
1235 DMERR("couldn't start kmirrord"); 1235 DMERR("couldn't start kmirrord");
1236 dm_dirty_log_exit(); 1236 dm_dirty_log_exit();
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index a5a4c0ed8a14..a6d3baa46f61 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -869,11 +869,17 @@ static void suspend_targets(struct dm_table *t, unsigned postsuspend)
869 869
870void dm_table_presuspend_targets(struct dm_table *t) 870void dm_table_presuspend_targets(struct dm_table *t)
871{ 871{
872 if (!t)
873 return;
874
872 return suspend_targets(t, 0); 875 return suspend_targets(t, 0);
873} 876}
874 877
875void dm_table_postsuspend_targets(struct dm_table *t) 878void dm_table_postsuspend_targets(struct dm_table *t)
876{ 879{
880 if (!t)
881 return;
882
877 return suspend_targets(t, 1); 883 return suspend_targets(t, 1);
878} 884}
879 885
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 54fabbf06678..d487d9deb98e 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -55,10 +55,10 @@ union map_info *dm_get_mapinfo(struct bio *bio)
55 */ 55 */
56#define DMF_BLOCK_IO 0 56#define DMF_BLOCK_IO 0
57#define DMF_SUSPENDED 1 57#define DMF_SUSPENDED 1
58#define DMF_FS_LOCKED 2
59 58
60struct mapped_device { 59struct mapped_device {
61 struct rw_semaphore lock; 60 struct rw_semaphore io_lock;
61 struct semaphore suspend_lock;
62 rwlock_t map_lock; 62 rwlock_t map_lock;
63 atomic_t holders; 63 atomic_t holders;
64 64
@@ -248,16 +248,16 @@ static inline void free_tio(struct mapped_device *md, struct target_io *tio)
248 */ 248 */
249static int queue_io(struct mapped_device *md, struct bio *bio) 249static int queue_io(struct mapped_device *md, struct bio *bio)
250{ 250{
251 down_write(&md->lock); 251 down_write(&md->io_lock);
252 252
253 if (!test_bit(DMF_BLOCK_IO, &md->flags)) { 253 if (!test_bit(DMF_BLOCK_IO, &md->flags)) {
254 up_write(&md->lock); 254 up_write(&md->io_lock);
255 return 1; 255 return 1;
256 } 256 }
257 257
258 bio_list_add(&md->deferred, bio); 258 bio_list_add(&md->deferred, bio);
259 259
260 up_write(&md->lock); 260 up_write(&md->io_lock);
261 return 0; /* deferred successfully */ 261 return 0; /* deferred successfully */
262} 262}
263 263
@@ -568,14 +568,14 @@ static int dm_request(request_queue_t *q, struct bio *bio)
568 int r; 568 int r;
569 struct mapped_device *md = q->queuedata; 569 struct mapped_device *md = q->queuedata;
570 570
571 down_read(&md->lock); 571 down_read(&md->io_lock);
572 572
573 /* 573 /*
574 * If we're suspended we have to queue 574 * If we're suspended we have to queue
575 * this io for later. 575 * this io for later.
576 */ 576 */
577 while (test_bit(DMF_BLOCK_IO, &md->flags)) { 577 while (test_bit(DMF_BLOCK_IO, &md->flags)) {
578 up_read(&md->lock); 578 up_read(&md->io_lock);
579 579
580 if (bio_rw(bio) == READA) { 580 if (bio_rw(bio) == READA) {
581 bio_io_error(bio, bio->bi_size); 581 bio_io_error(bio, bio->bi_size);
@@ -594,11 +594,11 @@ static int dm_request(request_queue_t *q, struct bio *bio)
594 * We're in a while loop, because someone could suspend 594 * We're in a while loop, because someone could suspend
595 * before we get to the following read lock. 595 * before we get to the following read lock.
596 */ 596 */
597 down_read(&md->lock); 597 down_read(&md->io_lock);
598 } 598 }
599 599
600 __split_bio(md, bio); 600 __split_bio(md, bio);
601 up_read(&md->lock); 601 up_read(&md->io_lock);
602 return 0; 602 return 0;
603} 603}
604 604
@@ -610,7 +610,7 @@ static int dm_flush_all(request_queue_t *q, struct gendisk *disk,
610 int ret = -ENXIO; 610 int ret = -ENXIO;
611 611
612 if (map) { 612 if (map) {
613 ret = dm_table_flush_all(md->map); 613 ret = dm_table_flush_all(map);
614 dm_table_put(map); 614 dm_table_put(map);
615 } 615 }
616 616
@@ -747,7 +747,8 @@ static struct mapped_device *alloc_dev(unsigned int minor, int persistent)
747 goto bad1; 747 goto bad1;
748 748
749 memset(md, 0, sizeof(*md)); 749 memset(md, 0, sizeof(*md));
750 init_rwsem(&md->lock); 750 init_rwsem(&md->io_lock);
751 init_MUTEX(&md->suspend_lock);
751 rwlock_init(&md->map_lock); 752 rwlock_init(&md->map_lock);
752 atomic_set(&md->holders, 1); 753 atomic_set(&md->holders, 1);
753 atomic_set(&md->event_nr, 0); 754 atomic_set(&md->event_nr, 0);
@@ -825,18 +826,13 @@ static void event_callback(void *context)
825 wake_up(&md->eventq); 826 wake_up(&md->eventq);
826} 827}
827 828
828static void __set_size(struct gendisk *disk, sector_t size) 829static void __set_size(struct mapped_device *md, sector_t size)
829{ 830{
830 struct block_device *bdev; 831 set_capacity(md->disk, size);
831 832
832 set_capacity(disk, size); 833 down(&md->frozen_bdev->bd_inode->i_sem);
833 bdev = bdget_disk(disk, 0); 834 i_size_write(md->frozen_bdev->bd_inode, (loff_t)size << SECTOR_SHIFT);
834 if (bdev) { 835 up(&md->frozen_bdev->bd_inode->i_sem);
835 down(&bdev->bd_inode->i_sem);
836 i_size_write(bdev->bd_inode, (loff_t)size << SECTOR_SHIFT);
837 up(&bdev->bd_inode->i_sem);
838 bdput(bdev);
839 }
840} 836}
841 837
842static int __bind(struct mapped_device *md, struct dm_table *t) 838static int __bind(struct mapped_device *md, struct dm_table *t)
@@ -845,17 +841,18 @@ static int __bind(struct mapped_device *md, struct dm_table *t)
845 sector_t size; 841 sector_t size;
846 842
847 size = dm_table_get_size(t); 843 size = dm_table_get_size(t);
848 __set_size(md->disk, size); 844 __set_size(md, size);
849 if (size == 0) 845 if (size == 0)
850 return 0; 846 return 0;
851 847
848 dm_table_get(t);
849 dm_table_event_callback(t, event_callback, md);
850
852 write_lock(&md->map_lock); 851 write_lock(&md->map_lock);
853 md->map = t; 852 md->map = t;
853 dm_table_set_restrictions(t, q);
854 write_unlock(&md->map_lock); 854 write_unlock(&md->map_lock);
855 855
856 dm_table_get(t);
857 dm_table_event_callback(md->map, event_callback, md);
858 dm_table_set_restrictions(t, q);
859 return 0; 856 return 0;
860} 857}
861 858
@@ -935,7 +932,7 @@ void dm_put(struct mapped_device *md)
935 struct dm_table *map = dm_get_table(md); 932 struct dm_table *map = dm_get_table(md);
936 933
937 if (atomic_dec_and_test(&md->holders)) { 934 if (atomic_dec_and_test(&md->holders)) {
938 if (!test_bit(DMF_SUSPENDED, &md->flags) && map) { 935 if (!dm_suspended(md)) {
939 dm_table_presuspend_targets(map); 936 dm_table_presuspend_targets(map);
940 dm_table_postsuspend_targets(map); 937 dm_table_postsuspend_targets(map);
941 } 938 }
@@ -968,17 +965,17 @@ int dm_swap_table(struct mapped_device *md, struct dm_table *table)
968{ 965{
969 int r = -EINVAL; 966 int r = -EINVAL;
970 967
971 down_write(&md->lock); 968 down(&md->suspend_lock);
972 969
973 /* device must be suspended */ 970 /* device must be suspended */
974 if (!test_bit(DMF_SUSPENDED, &md->flags)) 971 if (!dm_suspended(md))
975 goto out; 972 goto out;
976 973
977 __unbind(md); 974 __unbind(md);
978 r = __bind(md, table); 975 r = __bind(md, table);
979 976
980out: 977out:
981 up_write(&md->lock); 978 up(&md->suspend_lock);
982 return r; 979 return r;
983} 980}
984 981
@@ -986,16 +983,13 @@ out:
986 * Functions to lock and unlock any filesystem running on the 983 * Functions to lock and unlock any filesystem running on the
987 * device. 984 * device.
988 */ 985 */
989static int __lock_fs(struct mapped_device *md) 986static int lock_fs(struct mapped_device *md)
990{ 987{
991 int error = -ENOMEM; 988 int r = -ENOMEM;
992
993 if (test_and_set_bit(DMF_FS_LOCKED, &md->flags))
994 return 0;
995 989
996 md->frozen_bdev = bdget_disk(md->disk, 0); 990 md->frozen_bdev = bdget_disk(md->disk, 0);
997 if (!md->frozen_bdev) { 991 if (!md->frozen_bdev) {
998 DMWARN("bdget failed in __lock_fs"); 992 DMWARN("bdget failed in lock_fs");
999 goto out; 993 goto out;
1000 } 994 }
1001 995
@@ -1003,13 +997,13 @@ static int __lock_fs(struct mapped_device *md)
1003 997
1004 md->frozen_sb = freeze_bdev(md->frozen_bdev); 998 md->frozen_sb = freeze_bdev(md->frozen_bdev);
1005 if (IS_ERR(md->frozen_sb)) { 999 if (IS_ERR(md->frozen_sb)) {
1006 error = PTR_ERR(md->frozen_sb); 1000 r = PTR_ERR(md->frozen_sb);
1007 goto out_bdput; 1001 goto out_bdput;
1008 } 1002 }
1009 1003
1010 /* don't bdput right now, we don't want the bdev 1004 /* don't bdput right now, we don't want the bdev
1011 * to go away while it is locked. We'll bdput 1005 * to go away while it is locked. We'll bdput
1012 * in __unlock_fs 1006 * in unlock_fs
1013 */ 1007 */
1014 return 0; 1008 return 0;
1015 1009
@@ -1018,15 +1012,11 @@ out_bdput:
1018 md->frozen_sb = NULL; 1012 md->frozen_sb = NULL;
1019 md->frozen_bdev = NULL; 1013 md->frozen_bdev = NULL;
1020out: 1014out:
1021 clear_bit(DMF_FS_LOCKED, &md->flags); 1015 return r;
1022 return error;
1023} 1016}
1024 1017
1025static void __unlock_fs(struct mapped_device *md) 1018static void unlock_fs(struct mapped_device *md)
1026{ 1019{
1027 if (!test_and_clear_bit(DMF_FS_LOCKED, &md->flags))
1028 return;
1029
1030 thaw_bdev(md->frozen_bdev, md->frozen_sb); 1020 thaw_bdev(md->frozen_bdev, md->frozen_sb);
1031 bdput(md->frozen_bdev); 1021 bdput(md->frozen_bdev);
1032 1022
@@ -1043,50 +1033,37 @@ static void __unlock_fs(struct mapped_device *md)
1043 */ 1033 */
1044int dm_suspend(struct mapped_device *md) 1034int dm_suspend(struct mapped_device *md)
1045{ 1035{
1046 struct dm_table *map; 1036 struct dm_table *map = NULL;
1047 DECLARE_WAITQUEUE(wait, current); 1037 DECLARE_WAITQUEUE(wait, current);
1048 int error = -EINVAL; 1038 int r = -EINVAL;
1049 1039
1050 /* Flush I/O to the device. */ 1040 down(&md->suspend_lock);
1051 down_read(&md->lock); 1041
1052 if (test_bit(DMF_BLOCK_IO, &md->flags)) 1042 if (dm_suspended(md))
1053 goto out_read_unlock; 1043 goto out;
1054 1044
1055 map = dm_get_table(md); 1045 map = dm_get_table(md);
1056 if (map)
1057 /* This does not get reverted if there's an error later. */
1058 dm_table_presuspend_targets(map);
1059 1046
1060 error = __lock_fs(md); 1047 /* This does not get reverted if there's an error later. */
1061 if (error) { 1048 dm_table_presuspend_targets(map);
1062 dm_table_put(map);
1063 goto out_read_unlock;
1064 }
1065 1049
1066 up_read(&md->lock); 1050 /* Flush I/O to the device. */
1051 r = lock_fs(md);
1052 if (r)
1053 goto out;
1067 1054
1068 /* 1055 /*
1069 * First we set the BLOCK_IO flag so no more ios will be mapped. 1056 * First we set the BLOCK_IO flag so no more ios will be mapped.
1070 *
1071 * If the flag is already set we know another thread is trying to
1072 * suspend as well, so we leave the fs locked for this thread.
1073 */ 1057 */
1074 error = -EINVAL; 1058 down_write(&md->io_lock);
1075 down_write(&md->lock); 1059 set_bit(DMF_BLOCK_IO, &md->flags);
1076 if (test_and_set_bit(DMF_BLOCK_IO, &md->flags)) {
1077 if (map)
1078 dm_table_put(map);
1079 goto out_write_unlock;
1080 }
1081 1060
1082 add_wait_queue(&md->wait, &wait); 1061 add_wait_queue(&md->wait, &wait);
1083 up_write(&md->lock); 1062 up_write(&md->io_lock);
1084 1063
1085 /* unplug */ 1064 /* unplug */
1086 if (map) { 1065 if (map)
1087 dm_table_unplug_all(map); 1066 dm_table_unplug_all(map);
1088 dm_table_put(map);
1089 }
1090 1067
1091 /* 1068 /*
1092 * Then we wait for the already mapped ios to 1069 * Then we wait for the already mapped ios to
@@ -1102,62 +1079,67 @@ int dm_suspend(struct mapped_device *md)
1102 } 1079 }
1103 set_current_state(TASK_RUNNING); 1080 set_current_state(TASK_RUNNING);
1104 1081
1105 down_write(&md->lock); 1082 down_write(&md->io_lock);
1106 remove_wait_queue(&md->wait, &wait); 1083 remove_wait_queue(&md->wait, &wait);
1107 1084
1108 /* were we interrupted ? */ 1085 /* were we interrupted ? */
1109 error = -EINTR; 1086 r = -EINTR;
1110 if (atomic_read(&md->pending)) 1087 if (atomic_read(&md->pending)) {
1111 goto out_unfreeze; 1088 up_write(&md->io_lock);
1112 1089 unlock_fs(md);
1113 set_bit(DMF_SUSPENDED, &md->flags); 1090 clear_bit(DMF_BLOCK_IO, &md->flags);
1091 goto out;
1092 }
1093 up_write(&md->io_lock);
1114 1094
1115 map = dm_get_table(md); 1095 dm_table_postsuspend_targets(map);
1116 if (map)
1117 dm_table_postsuspend_targets(map);
1118 dm_table_put(map);
1119 up_write(&md->lock);
1120 1096
1121 return 0; 1097 set_bit(DMF_SUSPENDED, &md->flags);
1122 1098
1123out_unfreeze: 1099 r = 0;
1124 __unlock_fs(md);
1125 clear_bit(DMF_BLOCK_IO, &md->flags);
1126out_write_unlock:
1127 up_write(&md->lock);
1128 return error;
1129 1100
1130out_read_unlock: 1101out:
1131 up_read(&md->lock); 1102 dm_table_put(map);
1132 return error; 1103 up(&md->suspend_lock);
1104 return r;
1133} 1105}
1134 1106
1135int dm_resume(struct mapped_device *md) 1107int dm_resume(struct mapped_device *md)
1136{ 1108{
1109 int r = -EINVAL;
1137 struct bio *def; 1110 struct bio *def;
1138 struct dm_table *map = dm_get_table(md); 1111 struct dm_table *map = NULL;
1139 1112
1140 down_write(&md->lock); 1113 down(&md->suspend_lock);
1141 if (!map || 1114 if (!dm_suspended(md))
1142 !test_bit(DMF_SUSPENDED, &md->flags) || 1115 goto out;
1143 !dm_table_get_size(map)) { 1116
1144 up_write(&md->lock); 1117 map = dm_get_table(md);
1145 dm_table_put(map); 1118 if (!map || !dm_table_get_size(map))
1146 return -EINVAL; 1119 goto out;
1147 }
1148 1120
1149 dm_table_resume_targets(map); 1121 dm_table_resume_targets(map);
1150 clear_bit(DMF_SUSPENDED, &md->flags); 1122
1123 down_write(&md->io_lock);
1151 clear_bit(DMF_BLOCK_IO, &md->flags); 1124 clear_bit(DMF_BLOCK_IO, &md->flags);
1152 1125
1153 def = bio_list_get(&md->deferred); 1126 def = bio_list_get(&md->deferred);
1154 __flush_deferred_io(md, def); 1127 __flush_deferred_io(md, def);
1155 up_write(&md->lock); 1128 up_write(&md->io_lock);
1156 __unlock_fs(md); 1129
1130 unlock_fs(md);
1131
1132 clear_bit(DMF_SUSPENDED, &md->flags);
1133
1157 dm_table_unplug_all(map); 1134 dm_table_unplug_all(map);
1135
1136 r = 0;
1137
1138out:
1158 dm_table_put(map); 1139 dm_table_put(map);
1140 up(&md->suspend_lock);
1159 1141
1160 return 0; 1142 return r;
1161} 1143}
1162 1144
1163/*----------------------------------------------------------------- 1145/*-----------------------------------------------------------------
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 4a0c57db2b67..480f658db6f2 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -284,7 +284,7 @@ static mdk_rdev_t * find_rdev(mddev_t * mddev, dev_t dev)
284 return NULL; 284 return NULL;
285} 285}
286 286
287inline static sector_t calc_dev_sboffset(struct block_device *bdev) 287static inline sector_t calc_dev_sboffset(struct block_device *bdev)
288{ 288{
289 sector_t size = bdev->bd_inode->i_size >> BLOCK_SIZE_BITS; 289 sector_t size = bdev->bd_inode->i_size >> BLOCK_SIZE_BITS;
290 return MD_NEW_SIZE_BLOCKS(size); 290 return MD_NEW_SIZE_BLOCKS(size);
@@ -1798,6 +1798,8 @@ static int do_md_stop(mddev_t * mddev, int ro)
1798 goto out; 1798 goto out;
1799 mddev->ro = 1; 1799 mddev->ro = 1;
1800 } else { 1800 } else {
1801 bitmap_flush(mddev);
1802 wait_event(mddev->sb_wait, atomic_read(&mddev->pending_writes)==0);
1801 if (mddev->ro) 1803 if (mddev->ro)
1802 set_disk_ro(disk, 0); 1804 set_disk_ro(disk, 0);
1803 blk_queue_make_request(mddev->queue, md_fail_request); 1805 blk_queue_make_request(mddev->queue, md_fail_request);
@@ -3484,7 +3486,6 @@ static void md_do_sync(mddev_t *mddev)
3484 goto skip; 3486 goto skip;
3485 } 3487 }
3486 ITERATE_MDDEV(mddev2,tmp) { 3488 ITERATE_MDDEV(mddev2,tmp) {
3487 printk(".");
3488 if (mddev2 == mddev) 3489 if (mddev2 == mddev)
3489 continue; 3490 continue;
3490 if (mddev2->curr_resync && 3491 if (mddev2->curr_resync &&
@@ -4007,3 +4008,4 @@ EXPORT_SYMBOL(md_wakeup_thread);
4007EXPORT_SYMBOL(md_print_devices); 4008EXPORT_SYMBOL(md_print_devices);
4008EXPORT_SYMBOL(md_check_recovery); 4009EXPORT_SYMBOL(md_check_recovery);
4009MODULE_LICENSE("GPL"); 4010MODULE_LICENSE("GPL");
4011MODULE_ALIAS("md");
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 5f253ee536bb..51d9645ed09c 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -893,7 +893,6 @@ static int end_sync_read(struct bio *bio, unsigned int bytes_done, int error)
893 if (!uptodate) { 893 if (!uptodate) {
894 md_error(r1_bio->mddev, 894 md_error(r1_bio->mddev,
895 conf->mirrors[r1_bio->read_disk].rdev); 895 conf->mirrors[r1_bio->read_disk].rdev);
896 set_bit(R1BIO_Degraded, &r1_bio->state);
897 } else 896 } else
898 set_bit(R1BIO_Uptodate, &r1_bio->state); 897 set_bit(R1BIO_Uptodate, &r1_bio->state);
899 rdev_dec_pending(conf->mirrors[r1_bio->read_disk].rdev, conf->mddev); 898 rdev_dec_pending(conf->mirrors[r1_bio->read_disk].rdev, conf->mddev);
@@ -918,10 +917,9 @@ static int end_sync_write(struct bio *bio, unsigned int bytes_done, int error)
918 mirror = i; 917 mirror = i;
919 break; 918 break;
920 } 919 }
921 if (!uptodate) { 920 if (!uptodate)
922 md_error(mddev, conf->mirrors[mirror].rdev); 921 md_error(mddev, conf->mirrors[mirror].rdev);
923 set_bit(R1BIO_Degraded, &r1_bio->state); 922
924 }
925 update_head_pos(mirror, r1_bio); 923 update_head_pos(mirror, r1_bio);
926 924
927 if (atomic_dec_and_test(&r1_bio->remaining)) { 925 if (atomic_dec_and_test(&r1_bio->remaining)) {
@@ -1109,6 +1107,7 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1109 int i; 1107 int i;
1110 int write_targets = 0; 1108 int write_targets = 0;
1111 int sync_blocks; 1109 int sync_blocks;
1110 int still_degraded = 0;
1112 1111
1113 if (!conf->r1buf_pool) 1112 if (!conf->r1buf_pool)
1114 { 1113 {
@@ -1137,7 +1136,10 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1137 return 0; 1136 return 0;
1138 } 1137 }
1139 1138
1140 if (!bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, mddev->degraded) && 1139 /* before building a request, check if we can skip these blocks..
1140 * This call the bitmap_start_sync doesn't actually record anything
1141 */
1142 if (!bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) &&
1141 !conf->fullsync) { 1143 !conf->fullsync) {
1142 /* We can skip this block, and probably several more */ 1144 /* We can skip this block, and probably several more */
1143 *skipped = 1; 1145 *skipped = 1;
@@ -1203,24 +1205,23 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1203 if (i == disk) { 1205 if (i == disk) {
1204 bio->bi_rw = READ; 1206 bio->bi_rw = READ;
1205 bio->bi_end_io = end_sync_read; 1207 bio->bi_end_io = end_sync_read;
1206 } else if (conf->mirrors[i].rdev && 1208 } else if (conf->mirrors[i].rdev == NULL ||
1207 !conf->mirrors[i].rdev->faulty && 1209 conf->mirrors[i].rdev->faulty) {
1208 (!conf->mirrors[i].rdev->in_sync || 1210 still_degraded = 1;
1209 sector_nr + RESYNC_SECTORS > mddev->recovery_cp)) { 1211 continue;
1212 } else if (!conf->mirrors[i].rdev->in_sync ||
1213 sector_nr + RESYNC_SECTORS > mddev->recovery_cp) {
1210 bio->bi_rw = WRITE; 1214 bio->bi_rw = WRITE;
1211 bio->bi_end_io = end_sync_write; 1215 bio->bi_end_io = end_sync_write;
1212 write_targets ++; 1216 write_targets ++;
1213 } else 1217 } else
1218 /* no need to read or write here */
1214 continue; 1219 continue;
1215 bio->bi_sector = sector_nr + conf->mirrors[i].rdev->data_offset; 1220 bio->bi_sector = sector_nr + conf->mirrors[i].rdev->data_offset;
1216 bio->bi_bdev = conf->mirrors[i].rdev->bdev; 1221 bio->bi_bdev = conf->mirrors[i].rdev->bdev;
1217 bio->bi_private = r1_bio; 1222 bio->bi_private = r1_bio;
1218 } 1223 }
1219 1224
1220 if (write_targets + 1 < conf->raid_disks)
1221 /* array degraded, can't clear bitmap */
1222 set_bit(R1BIO_Degraded, &r1_bio->state);
1223
1224 if (write_targets == 0) { 1225 if (write_targets == 0) {
1225 /* There is nowhere to write, so all non-sync 1226 /* There is nowhere to write, so all non-sync
1226 * drives must be failed - so we are finished 1227 * drives must be failed - so we are finished
@@ -1243,7 +1244,7 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1243 break; 1244 break;
1244 if (sync_blocks == 0) { 1245 if (sync_blocks == 0) {
1245 if (!bitmap_start_sync(mddev->bitmap, sector_nr, 1246 if (!bitmap_start_sync(mddev->bitmap, sector_nr,
1246 &sync_blocks, mddev->degraded) && 1247 &sync_blocks, still_degraded) &&
1247 !conf->fullsync) 1248 !conf->fullsync)
1248 break; 1249 break;
1249 if (sync_blocks < (PAGE_SIZE>>9)) 1250 if (sync_blocks < (PAGE_SIZE>>9))
@@ -1468,6 +1469,7 @@ static int raid1_resize(mddev_t *mddev, sector_t sectors)
1468 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 1469 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
1469 } 1470 }
1470 mddev->size = mddev->array_size; 1471 mddev->size = mddev->array_size;
1472 mddev->resync_max_sectors = sectors;
1471 return 0; 1473 return 0;
1472} 1474}
1473 1475
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 93a9726cc2d6..43f231a467d5 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -1653,6 +1653,7 @@ static int run (mddev_t *mddev)
1653 1653
1654 /* device size must be a multiple of chunk size */ 1654 /* device size must be a multiple of chunk size */
1655 mddev->size &= ~(mddev->chunk_size/1024 -1); 1655 mddev->size &= ~(mddev->chunk_size/1024 -1);
1656 mddev->resync_max_sectors = mddev->size << 1;
1656 1657
1657 if (!conf->chunk_size || conf->chunk_size % 4) { 1658 if (!conf->chunk_size || conf->chunk_size % 4) {
1658 printk(KERN_ERR "raid5: invalid chunk size %d for %s\n", 1659 printk(KERN_ERR "raid5: invalid chunk size %d for %s\n",
@@ -1931,6 +1932,7 @@ static int raid5_resize(mddev_t *mddev, sector_t sectors)
1931 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 1932 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
1932 } 1933 }
1933 mddev->size = sectors /2; 1934 mddev->size = sectors /2;
1935 mddev->resync_max_sectors = sectors;
1934 return 0; 1936 return 0;
1935} 1937}
1936 1938
diff --git a/drivers/md/raid6main.c b/drivers/md/raid6main.c
index f62ea1a73d0d..495dee1d1e83 100644
--- a/drivers/md/raid6main.c
+++ b/drivers/md/raid6main.c
@@ -1813,6 +1813,7 @@ static int run (mddev_t *mddev)
1813 1813
1814 /* device size must be a multiple of chunk size */ 1814 /* device size must be a multiple of chunk size */
1815 mddev->size &= ~(mddev->chunk_size/1024 -1); 1815 mddev->size &= ~(mddev->chunk_size/1024 -1);
1816 mddev->resync_max_sectors = mddev->size << 1;
1816 1817
1817 if (conf->raid_disks < 4) { 1818 if (conf->raid_disks < 4) {
1818 printk(KERN_ERR "raid6: not enough configured devices for %s (%d, minimum 4)\n", 1819 printk(KERN_ERR "raid6: not enough configured devices for %s (%d, minimum 4)\n",
@@ -2095,6 +2096,7 @@ static int raid6_resize(mddev_t *mddev, sector_t sectors)
2095 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 2096 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
2096 } 2097 }
2097 mddev->size = sectors /2; 2098 mddev->size = sectors /2;
2099 mddev->resync_max_sectors = sectors;
2098 return 0; 2100 return 0;
2099} 2101}
2100 2102
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index d847c62bd837..e83256d0fd14 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -187,8 +187,8 @@ config DVB_BCM3510
187 An ATSC 8VSB/16VSB and QAM64/256 tuner module. Say Y when you want to 187 An ATSC 8VSB/16VSB and QAM64/256 tuner module. Say Y when you want to
188 support this frontend. 188 support this frontend.
189 189
190config DVB_LGDT3302 190config DVB_LGDT330X
191 tristate "LGDT3302 based (DViCO FusionHDTV3 Gold)" 191 tristate "LGDT3302 or LGDT3303 based (DViCO FusionHDTV Gold)"
192 depends on DVB_CORE 192 depends on DVB_CORE
193 help 193 help
194 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want 194 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want
diff --git a/drivers/media/dvb/frontends/Makefile b/drivers/media/dvb/frontends/Makefile
index de5e240cba7f..ad8658ffd60a 100644
--- a/drivers/media/dvb/frontends/Makefile
+++ b/drivers/media/dvb/frontends/Makefile
@@ -30,4 +30,4 @@ obj-$(CONFIG_DVB_OR51211) += or51211.o
30obj-$(CONFIG_DVB_OR51132) += or51132.o 30obj-$(CONFIG_DVB_OR51132) += or51132.o
31obj-$(CONFIG_DVB_BCM3510) += bcm3510.o 31obj-$(CONFIG_DVB_BCM3510) += bcm3510.o
32obj-$(CONFIG_DVB_S5H1420) += s5h1420.o 32obj-$(CONFIG_DVB_S5H1420) += s5h1420.o
33obj-$(CONFIG_DVB_LGDT3302) += lgdt3302.o 33obj-$(CONFIG_DVB_LGDT330X) += lgdt330x.o
diff --git a/drivers/media/dvb/frontends/dvb-pll.c b/drivers/media/dvb/frontends/dvb-pll.c
index 5afeaa9b43b4..536c35d969b7 100644
--- a/drivers/media/dvb/frontends/dvb-pll.c
+++ b/drivers/media/dvb/frontends/dvb-pll.c
@@ -82,13 +82,14 @@ struct dvb_pll_desc dvb_pll_lg_z201 = {
82 .name = "LG z201", 82 .name = "LG z201",
83 .min = 174000000, 83 .min = 174000000,
84 .max = 862000000, 84 .max = 862000000,
85 .count = 5, 85 .count = 6,
86 .entries = { 86 .entries = {
87 { 0, 36166667, 166666, 0xbc, 0x03 }, 87 { 0, 36166667, 166666, 0xbc, 0x03 },
88 { 443250000, 36166667, 166666, 0xbc, 0x01 }, 88 { 157500000, 36166667, 166666, 0xbc, 0x01 },
89 { 542000000, 36166667, 166666, 0xbc, 0x02 }, 89 { 443250000, 36166667, 166666, 0xbc, 0x02 },
90 { 830000000, 36166667, 166666, 0xf4, 0x02 }, 90 { 542000000, 36166667, 166666, 0xbc, 0x04 },
91 { 999999999, 36166667, 166666, 0xfc, 0x02 }, 91 { 830000000, 36166667, 166666, 0xf4, 0x04 },
92 { 999999999, 36166667, 166666, 0xfc, 0x04 },
92 }, 93 },
93}; 94};
94EXPORT_SYMBOL(dvb_pll_lg_z201); 95EXPORT_SYMBOL(dvb_pll_lg_z201);
@@ -224,6 +225,22 @@ struct dvb_pll_desc dvb_pll_tua6034 = {
224}; 225};
225EXPORT_SYMBOL(dvb_pll_tua6034); 226EXPORT_SYMBOL(dvb_pll_tua6034);
226 227
228/* Infineon TUA6034
229 * used in LG Innotek TDVS-H062F
230 */
231struct dvb_pll_desc dvb_pll_tdvs_tua6034 = {
232 .name = "LG/Infineon TUA6034",
233 .min = 54000000,
234 .max = 863000000,
235 .count = 3,
236 .entries = {
237 { 160000000, 44000000, 62500, 0xce, 0x01 },
238 { 455000000, 44000000, 62500, 0xce, 0x02 },
239 { 999999999, 44000000, 62500, 0xce, 0x04 },
240 },
241};
242EXPORT_SYMBOL(dvb_pll_tdvs_tua6034);
243
227/* Philips FMD1216ME 244/* Philips FMD1216ME
228 * used in Medion Hybrid PCMCIA card and USB Box 245 * used in Medion Hybrid PCMCIA card and USB Box
229 */ 246 */
diff --git a/drivers/media/dvb/frontends/dvb-pll.h b/drivers/media/dvb/frontends/dvb-pll.h
index cb794759d89e..205b2d1a8852 100644
--- a/drivers/media/dvb/frontends/dvb-pll.h
+++ b/drivers/media/dvb/frontends/dvb-pll.h
@@ -31,6 +31,7 @@ extern struct dvb_pll_desc dvb_pll_unknown_1;
31extern struct dvb_pll_desc dvb_pll_tua6010xs; 31extern struct dvb_pll_desc dvb_pll_tua6010xs;
32extern struct dvb_pll_desc dvb_pll_env57h1xd5; 32extern struct dvb_pll_desc dvb_pll_env57h1xd5;
33extern struct dvb_pll_desc dvb_pll_tua6034; 33extern struct dvb_pll_desc dvb_pll_tua6034;
34extern struct dvb_pll_desc dvb_pll_tdvs_tua6034;
34extern struct dvb_pll_desc dvb_pll_tda665x; 35extern struct dvb_pll_desc dvb_pll_tda665x;
35extern struct dvb_pll_desc dvb_pll_fmd1216me; 36extern struct dvb_pll_desc dvb_pll_fmd1216me;
36extern struct dvb_pll_desc dvb_pll_tded4; 37extern struct dvb_pll_desc dvb_pll_tded4;
diff --git a/drivers/media/dvb/frontends/lgdt3302.c b/drivers/media/dvb/frontends/lgdt3302.c
deleted file mode 100644
index c85a2a99df42..000000000000
--- a/drivers/media/dvb/frontends/lgdt3302.c
+++ /dev/null
@@ -1,599 +0,0 @@
1/*
2 * Support for LGDT3302 (DViCO FustionHDTV 3 Gold) - VSB/QAM
3 *
4 * Copyright (C) 2005 Wilson Michaels <wilsonmichaels@earthlink.net>
5 *
6 * Based on code from Kirk Lapray <kirk_lapray@bigfoot.com>
7 * Copyright (C) 2005
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25/*
26 * NOTES ABOUT THIS DRIVER
27 *
28 * This driver supports DViCO FusionHDTV 3 Gold under Linux.
29 *
30 * TODO:
31 * BER and signal strength always return 0.
32 *
33 */
34
35#include <linux/kernel.h>
36#include <linux/module.h>
37#include <linux/moduleparam.h>
38#include <linux/init.h>
39#include <linux/delay.h>
40#include <asm/byteorder.h>
41
42#include "dvb_frontend.h"
43#include "dvb-pll.h"
44#include "lgdt3302_priv.h"
45#include "lgdt3302.h"
46
47static int debug = 0;
48module_param(debug, int, 0644);
49MODULE_PARM_DESC(debug,"Turn on/off lgdt3302 frontend debugging (default:off).");
50#define dprintk(args...) \
51do { \
52if (debug) printk(KERN_DEBUG "lgdt3302: " args); \
53} while (0)
54
55struct lgdt3302_state
56{
57 struct i2c_adapter* i2c;
58 struct dvb_frontend_ops ops;
59
60 /* Configuration settings */
61 const struct lgdt3302_config* config;
62
63 struct dvb_frontend frontend;
64
65 /* Demodulator private data */
66 fe_modulation_t current_modulation;
67
68 /* Tuner private data */
69 u32 current_frequency;
70};
71
72static int i2c_writebytes (struct lgdt3302_state* state,
73 u8 addr, /* demod_address or pll_address */
74 u8 *buf, /* data bytes to send */
75 int len /* number of bytes to send */ )
76{
77 if (addr == state->config->pll_address) {
78 struct i2c_msg msg =
79 { .addr = addr, .flags = 0, .buf = buf, .len = len };
80 int err;
81
82 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
83 printk(KERN_WARNING "lgdt3302: %s error (addr %02x <- %02x, err == %i)\n", __FUNCTION__, addr, buf[0], err);
84 if (err < 0)
85 return err;
86 else
87 return -EREMOTEIO;
88 }
89 } else {
90 u8 tmp[] = { buf[0], buf[1] };
91 struct i2c_msg msg =
92 { .addr = addr, .flags = 0, .buf = tmp, .len = 2 };
93 int err;
94 int i;
95
96 for (i=1; i<len; i++) {
97 tmp[1] = buf[i];
98 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
99 printk(KERN_WARNING "lgdt3302: %s error (addr %02x <- %02x, err == %i)\n", __FUNCTION__, addr, buf[0], err);
100 if (err < 0)
101 return err;
102 else
103 return -EREMOTEIO;
104 }
105 tmp[0]++;
106 }
107 }
108 return 0;
109}
110static int i2c_readbytes (struct lgdt3302_state* state,
111 u8 addr, /* demod_address or pll_address */
112 u8 *buf, /* holds data bytes read */
113 int len /* number of bytes to read */ )
114{
115 struct i2c_msg msg =
116 { .addr = addr, .flags = I2C_M_RD, .buf = buf, .len = len };
117 int err;
118
119 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
120 printk(KERN_WARNING "lgdt3302: %s error (addr %02x, err == %i)\n", __FUNCTION__, addr, err);
121 return -EREMOTEIO;
122 }
123 return 0;
124}
125
126/*
127 * This routine writes the register (reg) to the demod bus
128 * then reads the data returned for (len) bytes.
129 */
130
131static u8 i2c_selectreadbytes (struct lgdt3302_state* state,
132 enum I2C_REG reg, u8* buf, int len)
133{
134 u8 wr [] = { reg };
135 struct i2c_msg msg [] = {
136 { .addr = state->config->demod_address,
137 .flags = 0, .buf = wr, .len = 1 },
138 { .addr = state->config->demod_address,
139 .flags = I2C_M_RD, .buf = buf, .len = len },
140 };
141 int ret;
142 ret = i2c_transfer(state->i2c, msg, 2);
143 if (ret != 2) {
144 printk(KERN_WARNING "lgdt3302: %s: addr 0x%02x select 0x%02x error (ret == %i)\n", __FUNCTION__, state->config->demod_address, reg, ret);
145 } else {
146 ret = 0;
147 }
148 return ret;
149}
150
151/* Software reset */
152int lgdt3302_SwReset(struct lgdt3302_state* state)
153{
154 u8 ret;
155 u8 reset[] = {
156 IRQ_MASK,
157 0x00 /* bit 6 is active low software reset
158 * bits 5-0 are 1 to mask interrupts */
159 };
160
161 ret = i2c_writebytes(state,
162 state->config->demod_address,
163 reset, sizeof(reset));
164 if (ret == 0) {
165 /* spec says reset takes 100 ns why wait */
166 /* mdelay(100); */ /* keep low for 100mS */
167 reset[1] = 0x7f; /* force reset high (inactive)
168 * and unmask interrupts */
169 ret = i2c_writebytes(state,
170 state->config->demod_address,
171 reset, sizeof(reset));
172 }
173 /* Spec does not indicate a need for this either */
174 /*mdelay(5); */ /* wait 5 msec before doing more */
175 return ret;
176}
177
178static int lgdt3302_init(struct dvb_frontend* fe)
179{
180 /* Hardware reset is done using gpio[0] of cx23880x chip.
181 * I'd like to do it here, but don't know how to find chip address.
182 * cx88-cards.c arranges for the reset bit to be inactive (high).
183 * Maybe there needs to be a callable function in cx88-core or
184 * the caller of this function needs to do it. */
185
186 dprintk("%s entered\n", __FUNCTION__);
187 return lgdt3302_SwReset((struct lgdt3302_state*) fe->demodulator_priv);
188}
189
190static int lgdt3302_read_ber(struct dvb_frontend* fe, u32* ber)
191{
192 *ber = 0; /* Dummy out for now */
193 return 0;
194}
195
196static int lgdt3302_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
197{
198 struct lgdt3302_state* state = (struct lgdt3302_state*) fe->demodulator_priv;
199 u8 buf[2];
200
201 i2c_selectreadbytes(state, PACKET_ERR_COUNTER1, buf, sizeof(buf));
202
203 *ucblocks = (buf[0] << 8) | buf[1];
204 return 0;
205}
206
207static int lgdt3302_set_parameters(struct dvb_frontend* fe,
208 struct dvb_frontend_parameters *param)
209{
210 u8 buf[4];
211 struct lgdt3302_state* state =
212 (struct lgdt3302_state*) fe->demodulator_priv;
213
214 /* Use 50MHz parameter values from spec sheet since xtal is 50 */
215 static u8 top_ctrl_cfg[] = { TOP_CONTROL, 0x03 };
216 static u8 vsb_freq_cfg[] = { VSB_CARRIER_FREQ0, 0x00, 0x87, 0x8e, 0x01 };
217 static u8 demux_ctrl_cfg[] = { DEMUX_CONTROL, 0xfb };
218 static u8 agc_rf_cfg[] = { AGC_RF_BANDWIDTH0, 0x40, 0x93, 0x00 };
219 static u8 agc_ctrl_cfg[] = { AGC_FUNC_CTRL2, 0xc6, 0x40 };
220 static u8 agc_delay_cfg[] = { AGC_DELAY0, 0x07, 0x00, 0xfe };
221 static u8 agc_loop_cfg[] = { AGC_LOOP_BANDWIDTH0, 0x08, 0x9a };
222
223 /* Change only if we are actually changing the modulation */
224 if (state->current_modulation != param->u.vsb.modulation) {
225 switch(param->u.vsb.modulation) {
226 case VSB_8:
227 dprintk("%s: VSB_8 MODE\n", __FUNCTION__);
228
229 /* Select VSB mode and serial MPEG interface */
230 top_ctrl_cfg[1] = 0x07;
231 break;
232
233 case QAM_64:
234 dprintk("%s: QAM_64 MODE\n", __FUNCTION__);
235
236 /* Select QAM_64 mode and serial MPEG interface */
237 top_ctrl_cfg[1] = 0x04;
238 break;
239
240 case QAM_256:
241 dprintk("%s: QAM_256 MODE\n", __FUNCTION__);
242
243 /* Select QAM_256 mode and serial MPEG interface */
244 top_ctrl_cfg[1] = 0x05;
245 break;
246 default:
247 printk(KERN_WARNING "lgdt3302: %s: Modulation type(%d) UNSUPPORTED\n", __FUNCTION__, param->u.vsb.modulation);
248 return -1;
249 }
250 /* Initializations common to all modes */
251
252 /* Select the requested mode */
253 i2c_writebytes(state, state->config->demod_address,
254 top_ctrl_cfg, sizeof(top_ctrl_cfg));
255
256 /* Change the value of IFBW[11:0]
257 of AGC IF/RF loop filter bandwidth register */
258 i2c_writebytes(state, state->config->demod_address,
259 agc_rf_cfg, sizeof(agc_rf_cfg));
260
261 /* Change the value of bit 6, 'nINAGCBY' and
262 'NSSEL[1:0] of ACG function control register 2 */
263 /* Change the value of bit 6 'RFFIX'
264 of AGC function control register 3 */
265 i2c_writebytes(state, state->config->demod_address,
266 agc_ctrl_cfg, sizeof(agc_ctrl_cfg));
267
268 /* Change the TPCLK pin polarity
269 data is valid on falling clock */
270 i2c_writebytes(state, state->config->demod_address,
271 demux_ctrl_cfg, sizeof(demux_ctrl_cfg));
272
273 /* Change the value of NCOCTFV[25:0] of carrier
274 recovery center frequency register */
275 i2c_writebytes(state, state->config->demod_address,
276 vsb_freq_cfg, sizeof(vsb_freq_cfg));
277
278 /* Set the value of 'INLVTHD' register 0x2a/0x2c to 0x7fe */
279 i2c_writebytes(state, state->config->demod_address,
280 agc_delay_cfg, sizeof(agc_delay_cfg));
281
282 /* Change the value of IAGCBW[15:8]
283 of inner AGC loop filter bandwith */
284 i2c_writebytes(state, state->config->demod_address,
285 agc_loop_cfg, sizeof(agc_loop_cfg));
286
287 state->config->set_ts_params(fe, 0);
288 state->current_modulation = param->u.vsb.modulation;
289 }
290
291 /* Change only if we are actually changing the channel */
292 if (state->current_frequency != param->frequency) {
293 dvb_pll_configure(state->config->pll_desc, buf,
294 param->frequency, 0);
295 dprintk("%s: tuner bytes: 0x%02x 0x%02x "
296 "0x%02x 0x%02x\n", __FUNCTION__, buf[0],buf[1],buf[2],buf[3]);
297 i2c_writebytes(state, state->config->pll_address ,buf, 4);
298
299 /* Check the status of the tuner pll */
300 i2c_readbytes(state, state->config->pll_address, buf, 1);
301 dprintk("%s: tuner status byte = 0x%02x\n", __FUNCTION__, buf[0]);
302
303 /* Update current frequency */
304 state->current_frequency = param->frequency;
305 }
306 lgdt3302_SwReset(state);
307 return 0;
308}
309
310static int lgdt3302_get_frontend(struct dvb_frontend* fe,
311 struct dvb_frontend_parameters* param)
312{
313 struct lgdt3302_state *state = fe->demodulator_priv;
314 param->frequency = state->current_frequency;
315 return 0;
316}
317
318static int lgdt3302_read_status(struct dvb_frontend* fe, fe_status_t* status)
319{
320 struct lgdt3302_state* state = (struct lgdt3302_state*) fe->demodulator_priv;
321 u8 buf[3];
322
323 *status = 0; /* Reset status result */
324
325 /* Check the status of the tuner pll */
326 i2c_readbytes(state, state->config->pll_address, buf, 1);
327 dprintk("%s: tuner status byte = 0x%02x\n", __FUNCTION__, buf[0]);
328 if ((buf[0] & 0xc0) != 0x40)
329 return 0; /* Tuner PLL not locked or not powered on */
330
331 /*
332 * You must set the Mask bits to 1 in the IRQ_MASK in order
333 * to see that status bit in the IRQ_STATUS register.
334 * This is done in SwReset();
335 */
336
337 /* AGC status register */
338 i2c_selectreadbytes(state, AGC_STATUS, buf, 1);
339 dprintk("%s: AGC_STATUS = 0x%02x\n", __FUNCTION__, buf[0]);
340 if ((buf[0] & 0x0c) == 0x8){
341 /* Test signal does not exist flag */
342 /* as well as the AGC lock flag. */
343 *status |= FE_HAS_SIGNAL;
344 } else {
345 /* Without a signal all other status bits are meaningless */
346 return 0;
347 }
348
349 /* signal status */
350 i2c_selectreadbytes(state, TOP_CONTROL, buf, sizeof(buf));
351 dprintk("%s: TOP_CONTROL = 0x%02x, IRO_MASK = 0x%02x, IRQ_STATUS = 0x%02x\n", __FUNCTION__, buf[0], buf[1], buf[2]);
352
353#if 0
354 /* Alternative method to check for a signal */
355 /* using the SNR good/bad interrupts. */
356 if ((buf[2] & 0x30) == 0x10)
357 *status |= FE_HAS_SIGNAL;
358#endif
359
360 /* sync status */
361 if ((buf[2] & 0x03) == 0x01) {
362 *status |= FE_HAS_SYNC;
363 }
364
365 /* FEC error status */
366 if ((buf[2] & 0x0c) == 0x08) {
367 *status |= FE_HAS_LOCK;
368 *status |= FE_HAS_VITERBI;
369 }
370
371 /* Carrier Recovery Lock Status Register */
372 i2c_selectreadbytes(state, CARRIER_LOCK, buf, 1);
373 dprintk("%s: CARRIER_LOCK = 0x%02x\n", __FUNCTION__, buf[0]);
374 switch (state->current_modulation) {
375 case QAM_256:
376 case QAM_64:
377 /* Need to undestand why there are 3 lock levels here */
378 if ((buf[0] & 0x07) == 0x07)
379 *status |= FE_HAS_CARRIER;
380 break;
381 case VSB_8:
382 if ((buf[0] & 0x80) == 0x80)
383 *status |= FE_HAS_CARRIER;
384 break;
385 default:
386 printk("KERN_WARNING lgdt3302: %s: Modulation set to unsupported value\n", __FUNCTION__);
387 }
388
389 return 0;
390}
391
392static int lgdt3302_read_signal_strength(struct dvb_frontend* fe, u16* strength)
393{
394 /* not directly available. */
395 return 0;
396}
397
398static int lgdt3302_read_snr(struct dvb_frontend* fe, u16* snr)
399{
400#ifdef SNR_IN_DB
401 /*
402 * Spec sheet shows formula for SNR_EQ = 10 log10(25 * 24**2 / noise)
403 * and SNR_PH = 10 log10(25 * 32**2 / noise) for equalizer and phase tracker
404 * respectively. The following tables are built on these formulas.
405 * The usual definition is SNR = 20 log10(signal/noise)
406 * If the specification is wrong the value retuned is 1/2 the actual SNR in db.
407 *
408 * This table is a an ordered list of noise values computed by the
409 * formula from the spec sheet such that the index into the table
410 * starting at 43 or 45 is the SNR value in db. There are duplicate noise
411 * value entries at the beginning because the SNR varies more than
412 * 1 db for a change of 1 digit in noise at very small values of noise.
413 *
414 * Examples from SNR_EQ table:
415 * noise SNR
416 * 0 43
417 * 1 42
418 * 2 39
419 * 3 37
420 * 4 36
421 * 5 35
422 * 6 34
423 * 7 33
424 * 8 33
425 * 9 32
426 * 10 32
427 * 11 31
428 * 12 31
429 * 13 30
430 */
431
432 static const u32 SNR_EQ[] =
433 { 1, 2, 2, 2, 3, 3, 4, 4, 5, 7,
434 9, 11, 13, 17, 21, 26, 33, 41, 52, 65,
435 81, 102, 129, 162, 204, 257, 323, 406, 511, 644,
436 810, 1020, 1284, 1616, 2035, 2561, 3224, 4059, 5110, 6433,
437 8098, 10195, 12835, 16158, 20341, 25608, 32238, 40585, 51094, 64323,
438 80978, 101945, 128341, 161571, 203406, 256073, 0x40000
439 };
440
441 static const u32 SNR_PH[] =
442 { 1, 2, 2, 2, 3, 3, 4, 5, 6, 8,
443 10, 12, 15, 19, 23, 29, 37, 46, 58, 73,
444 91, 115, 144, 182, 229, 288, 362, 456, 574, 722,
445 909, 1144, 1440, 1813, 2282, 2873, 3617, 4553, 5732, 7216,
446 9084, 11436, 14396, 18124, 22817, 28724, 36161, 45524, 57312, 72151,
447 90833, 114351, 143960, 181235, 228161, 0x040000
448 };
449
450 static u8 buf[5];/* read data buffer */
451 static u32 noise; /* noise value */
452 static u32 snr_db; /* index into SNR_EQ[] */
453 struct lgdt3302_state* state = (struct lgdt3302_state*) fe->demodulator_priv;
454
455 /* read both equalizer and pase tracker noise data */
456 i2c_selectreadbytes(state, EQPH_ERR0, buf, sizeof(buf));
457
458 if (state->current_modulation == VSB_8) {
459 /* Equalizer Mean-Square Error Register for VSB */
460 noise = ((buf[0] & 7) << 16) | (buf[1] << 8) | buf[2];
461
462 /*
463 * Look up noise value in table.
464 * A better search algorithm could be used...
465 * watch out there are duplicate entries.
466 */
467 for (snr_db = 0; snr_db < sizeof(SNR_EQ); snr_db++) {
468 if (noise < SNR_EQ[snr_db]) {
469 *snr = 43 - snr_db;
470 break;
471 }
472 }
473 } else {
474 /* Phase Tracker Mean-Square Error Register for QAM */
475 noise = ((buf[0] & 7<<3) << 13) | (buf[3] << 8) | buf[4];
476
477 /* Look up noise value in table. */
478 for (snr_db = 0; snr_db < sizeof(SNR_PH); snr_db++) {
479 if (noise < SNR_PH[snr_db]) {
480 *snr = 45 - snr_db;
481 break;
482 }
483 }
484 }
485#else
486 /* Return the raw noise value */
487 static u8 buf[5];/* read data buffer */
488 static u32 noise; /* noise value */
489 struct lgdt3302_state* state = (struct lgdt3302_state*) fe->demodulator_priv;
490
491 /* read both equalizer and pase tracker noise data */
492 i2c_selectreadbytes(state, EQPH_ERR0, buf, sizeof(buf));
493
494 if (state->current_modulation == VSB_8) {
495 /* Equalizer Mean-Square Error Register for VSB */
496 noise = ((buf[0] & 7) << 16) | (buf[1] << 8) | buf[2];
497 } else {
498 /* Phase Tracker Mean-Square Error Register for QAM */
499 noise = ((buf[0] & 7<<3) << 13) | (buf[3] << 8) | buf[4];
500 }
501
502 /* Small values for noise mean signal is better so invert noise */
503 /* Noise is 19 bit value so discard 3 LSB*/
504 *snr = ~noise>>3;
505#endif
506
507 dprintk("%s: noise = 0x%05x, snr = %idb\n",__FUNCTION__, noise, *snr);
508
509 return 0;
510}
511
512static int lgdt3302_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fe_tune_settings)
513{
514 /* I have no idea about this - it may not be needed */
515 fe_tune_settings->min_delay_ms = 500;
516 fe_tune_settings->step_size = 0;
517 fe_tune_settings->max_drift = 0;
518 return 0;
519}
520
521static void lgdt3302_release(struct dvb_frontend* fe)
522{
523 struct lgdt3302_state* state = (struct lgdt3302_state*) fe->demodulator_priv;
524 kfree(state);
525}
526
527static struct dvb_frontend_ops lgdt3302_ops;
528
529struct dvb_frontend* lgdt3302_attach(const struct lgdt3302_config* config,
530 struct i2c_adapter* i2c)
531{
532 struct lgdt3302_state* state = NULL;
533 u8 buf[1];
534
535 /* Allocate memory for the internal state */
536 state = (struct lgdt3302_state*) kmalloc(sizeof(struct lgdt3302_state), GFP_KERNEL);
537 if (state == NULL)
538 goto error;
539 memset(state,0,sizeof(*state));
540
541 /* Setup the state */
542 state->config = config;
543 state->i2c = i2c;
544 memcpy(&state->ops, &lgdt3302_ops, sizeof(struct dvb_frontend_ops));
545 /* Verify communication with demod chip */
546 if (i2c_selectreadbytes(state, 2, buf, 1))
547 goto error;
548
549 state->current_frequency = -1;
550 state->current_modulation = -1;
551
552 /* Create dvb_frontend */
553 state->frontend.ops = &state->ops;
554 state->frontend.demodulator_priv = state;
555 return &state->frontend;
556
557error:
558 if (state)
559 kfree(state);
560 dprintk("%s: ERROR\n",__FUNCTION__);
561 return NULL;
562}
563
564static struct dvb_frontend_ops lgdt3302_ops = {
565 .info = {
566 .name= "LG Electronics LGDT3302 VSB/QAM Frontend",
567 .type = FE_ATSC,
568 .frequency_min= 54000000,
569 .frequency_max= 858000000,
570 .frequency_stepsize= 62500,
571 /* Symbol rate is for all VSB modes need to check QAM */
572 .symbol_rate_min = 10762000,
573 .symbol_rate_max = 10762000,
574 .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
575 },
576 .init = lgdt3302_init,
577 .set_frontend = lgdt3302_set_parameters,
578 .get_frontend = lgdt3302_get_frontend,
579 .get_tune_settings = lgdt3302_get_tune_settings,
580 .read_status = lgdt3302_read_status,
581 .read_ber = lgdt3302_read_ber,
582 .read_signal_strength = lgdt3302_read_signal_strength,
583 .read_snr = lgdt3302_read_snr,
584 .read_ucblocks = lgdt3302_read_ucblocks,
585 .release = lgdt3302_release,
586};
587
588MODULE_DESCRIPTION("LGDT3302 [DViCO FusionHDTV 3 Gold] (ATSC 8VSB & ITU-T J.83 AnnexB 64/256 QAM) Demodulator Driver");
589MODULE_AUTHOR("Wilson Michaels");
590MODULE_LICENSE("GPL");
591
592EXPORT_SYMBOL(lgdt3302_attach);
593
594/*
595 * Local variables:
596 * c-basic-offset: 8
597 * compile-command: "make DVB=1"
598 * End:
599 */
diff --git a/drivers/media/dvb/frontends/lgdt330x.c b/drivers/media/dvb/frontends/lgdt330x.c
new file mode 100644
index 000000000000..c48e7c11d708
--- /dev/null
+++ b/drivers/media/dvb/frontends/lgdt330x.c
@@ -0,0 +1,831 @@
1/*
2 * Support for LGDT3302 and LGDT3303 - VSB/QAM
3 *
4 * Copyright (C) 2005 Wilson Michaels <wilsonmichaels@earthlink.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 */
21
22/*
23 * NOTES ABOUT THIS DRIVER
24 *
25 * This Linux driver supports:
26 * DViCO FusionHDTV 3 Gold-Q
27 * DViCO FusionHDTV 3 Gold-T
28 * DViCO FusionHDTV 5 Gold
29 *
30 * TODO:
31 * signal strength always returns 0.
32 *
33 */
34
35#include <linux/kernel.h>
36#include <linux/module.h>
37#include <linux/moduleparam.h>
38#include <linux/init.h>
39#include <linux/delay.h>
40#include <asm/byteorder.h>
41
42#include "dvb_frontend.h"
43#include "lgdt330x_priv.h"
44#include "lgdt330x.h"
45
46static int debug = 0;
47module_param(debug, int, 0644);
48MODULE_PARM_DESC(debug,"Turn on/off lgdt330x frontend debugging (default:off).");
49#define dprintk(args...) \
50do { \
51if (debug) printk(KERN_DEBUG "lgdt330x: " args); \
52} while (0)
53
54struct lgdt330x_state
55{
56 struct i2c_adapter* i2c;
57 struct dvb_frontend_ops ops;
58
59 /* Configuration settings */
60 const struct lgdt330x_config* config;
61
62 struct dvb_frontend frontend;
63
64 /* Demodulator private data */
65 fe_modulation_t current_modulation;
66
67 /* Tuner private data */
68 u32 current_frequency;
69};
70
71static int i2c_write_demod_bytes (struct lgdt330x_state* state,
72 u8 *buf, /* data bytes to send */
73 int len /* number of bytes to send */ )
74{
75 struct i2c_msg msg =
76 { .addr = state->config->demod_address,
77 .flags = 0,
78 .buf = buf,
79 .len = 2 };
80 int i;
81 int err;
82
83 for (i=0; i<len-1; i+=2){
84 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
85 printk(KERN_WARNING "lgdt330x: %s error (addr %02x <- %02x, err = %i)\n", __FUNCTION__, msg.buf[0], msg.buf[1], err);
86 if (err < 0)
87 return err;
88 else
89 return -EREMOTEIO;
90 }
91 msg.buf += 2;
92 }
93 return 0;
94}
95
96/*
97 * This routine writes the register (reg) to the demod bus
98 * then reads the data returned for (len) bytes.
99 */
100
101static u8 i2c_read_demod_bytes (struct lgdt330x_state* state,
102 enum I2C_REG reg, u8* buf, int len)
103{
104 u8 wr [] = { reg };
105 struct i2c_msg msg [] = {
106 { .addr = state->config->demod_address,
107 .flags = 0, .buf = wr, .len = 1 },
108 { .addr = state->config->demod_address,
109 .flags = I2C_M_RD, .buf = buf, .len = len },
110 };
111 int ret;
112 ret = i2c_transfer(state->i2c, msg, 2);
113 if (ret != 2) {
114 printk(KERN_WARNING "lgdt330x: %s: addr 0x%02x select 0x%02x error (ret == %i)\n", __FUNCTION__, state->config->demod_address, reg, ret);
115 } else {
116 ret = 0;
117 }
118 return ret;
119}
120
121/* Software reset */
122static int lgdt3302_SwReset(struct lgdt330x_state* state)
123{
124 u8 ret;
125 u8 reset[] = {
126 IRQ_MASK,
127 0x00 /* bit 6 is active low software reset
128 * bits 5-0 are 1 to mask interrupts */
129 };
130
131 ret = i2c_write_demod_bytes(state,
132 reset, sizeof(reset));
133 if (ret == 0) {
134
135 /* force reset high (inactive) and unmask interrupts */
136 reset[1] = 0x7f;
137 ret = i2c_write_demod_bytes(state,
138 reset, sizeof(reset));
139 }
140 return ret;
141}
142
143static int lgdt3303_SwReset(struct lgdt330x_state* state)
144{
145 u8 ret;
146 u8 reset[] = {
147 0x02,
148 0x00 /* bit 0 is active low software reset */
149 };
150
151 ret = i2c_write_demod_bytes(state,
152 reset, sizeof(reset));
153 if (ret == 0) {
154
155 /* force reset high (inactive) */
156 reset[1] = 0x01;
157 ret = i2c_write_demod_bytes(state,
158 reset, sizeof(reset));
159 }
160 return ret;
161}
162
163static int lgdt330x_SwReset(struct lgdt330x_state* state)
164{
165 switch (state->config->demod_chip) {
166 case LGDT3302:
167 return lgdt3302_SwReset(state);
168 case LGDT3303:
169 return lgdt3303_SwReset(state);
170 default:
171 return -ENODEV;
172 }
173}
174
175#ifdef MUTE_TDA9887
176static int i2c_write_ntsc_demod (struct lgdt330x_state* state, u8 buf[2])
177{
178 struct i2c_msg msg =
179 { .addr = 0x43,
180 .flags = 0,
181 .buf = buf,
182 .len = 2 };
183 int err;
184
185 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
186 printk(KERN_WARNING "lgdt330x: %s error (addr %02x <- %02x, err = %i)\n", __FUNCTION__, msg.buf[0], msg.buf[1], err);
187 if (err < 0)
188 return err;
189 else
190 return -EREMOTEIO;
191 }
192 return 0;
193}
194
195static void fiddle_with_ntsc_if_demod(struct lgdt330x_state* state)
196{
197 // Experimental code
198 u8 buf0[] = {0x00, 0x20};
199 u8 buf1[] = {0x01, 0x00};
200 u8 buf2[] = {0x02, 0x00};
201
202 i2c_write_ntsc_demod(state, buf0);
203 i2c_write_ntsc_demod(state, buf1);
204 i2c_write_ntsc_demod(state, buf2);
205}
206#endif
207
208static int lgdt330x_init(struct dvb_frontend* fe)
209{
210 /* Hardware reset is done using gpio[0] of cx23880x chip.
211 * I'd like to do it here, but don't know how to find chip address.
212 * cx88-cards.c arranges for the reset bit to be inactive (high).
213 * Maybe there needs to be a callable function in cx88-core or
214 * the caller of this function needs to do it. */
215
216 /*
217 * Array of byte pairs <address, value>
218 * to initialize each different chip
219 */
220 static u8 lgdt3302_init_data[] = {
221 /* Use 50MHz parameter values from spec sheet since xtal is 50 */
222 /* Change the value of NCOCTFV[25:0] of carrier
223 recovery center frequency register */
224 VSB_CARRIER_FREQ0, 0x00,
225 VSB_CARRIER_FREQ1, 0x87,
226 VSB_CARRIER_FREQ2, 0x8e,
227 VSB_CARRIER_FREQ3, 0x01,
228 /* Change the TPCLK pin polarity
229 data is valid on falling clock */
230 DEMUX_CONTROL, 0xfb,
231 /* Change the value of IFBW[11:0] of
232 AGC IF/RF loop filter bandwidth register */
233 AGC_RF_BANDWIDTH0, 0x40,
234 AGC_RF_BANDWIDTH1, 0x93,
235 AGC_RF_BANDWIDTH2, 0x00,
236 /* Change the value of bit 6, 'nINAGCBY' and
237 'NSSEL[1:0] of ACG function control register 2 */
238 AGC_FUNC_CTRL2, 0xc6,
239 /* Change the value of bit 6 'RFFIX'
240 of AGC function control register 3 */
241 AGC_FUNC_CTRL3, 0x40,
242 /* Set the value of 'INLVTHD' register 0x2a/0x2c
243 to 0x7fe */
244 AGC_DELAY0, 0x07,
245 AGC_DELAY2, 0xfe,
246 /* Change the value of IAGCBW[15:8]
247 of inner AGC loop filter bandwith */
248 AGC_LOOP_BANDWIDTH0, 0x08,
249 AGC_LOOP_BANDWIDTH1, 0x9a
250 };
251
252 static u8 lgdt3303_init_data[] = {
253 0x4c, 0x14
254 };
255
256 struct lgdt330x_state* state = fe->demodulator_priv;
257 char *chip_name;
258 int err;
259
260 switch (state->config->demod_chip) {
261 case LGDT3302:
262 chip_name = "LGDT3302";
263 err = i2c_write_demod_bytes(state, lgdt3302_init_data,
264 sizeof(lgdt3302_init_data));
265 break;
266 case LGDT3303:
267 chip_name = "LGDT3303";
268 err = i2c_write_demod_bytes(state, lgdt3303_init_data,
269 sizeof(lgdt3303_init_data));
270#ifdef MUTE_TDA9887
271 fiddle_with_ntsc_if_demod(state);
272#endif
273 break;
274 default:
275 chip_name = "undefined";
276 printk (KERN_WARNING "Only LGDT3302 and LGDT3303 are supported chips.\n");
277 err = -ENODEV;
278 }
279 dprintk("%s entered as %s\n", __FUNCTION__, chip_name);
280 if (err < 0)
281 return err;
282 return lgdt330x_SwReset(state);
283}
284
285static int lgdt330x_read_ber(struct dvb_frontend* fe, u32* ber)
286{
287 *ber = 0; /* Not supplied by the demod chips */
288 return 0;
289}
290
291static int lgdt330x_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
292{
293 struct lgdt330x_state* state = fe->demodulator_priv;
294 int err;
295 u8 buf[2];
296
297 switch (state->config->demod_chip) {
298 case LGDT3302:
299 err = i2c_read_demod_bytes(state, LGDT3302_PACKET_ERR_COUNTER1,
300 buf, sizeof(buf));
301 break;
302 case LGDT3303:
303 err = i2c_read_demod_bytes(state, LGDT3303_PACKET_ERR_COUNTER1,
304 buf, sizeof(buf));
305 break;
306 default:
307 printk(KERN_WARNING
308 "Only LGDT3302 and LGDT3303 are supported chips.\n");
309 err = -ENODEV;
310 }
311
312 *ucblocks = (buf[0] << 8) | buf[1];
313 return 0;
314}
315
316static int lgdt330x_set_parameters(struct dvb_frontend* fe,
317 struct dvb_frontend_parameters *param)
318{
319 /*
320 * Array of byte pairs <address, value>
321 * to initialize 8VSB for lgdt3303 chip 50 MHz IF
322 */
323 static u8 lgdt3303_8vsb_44_data[] = {
324 0x04, 0x00,
325 0x0d, 0x40,
326 0x0e, 0x87,
327 0x0f, 0x8e,
328 0x10, 0x01,
329 0x47, 0x8b };
330
331 /*
332 * Array of byte pairs <address, value>
333 * to initialize QAM for lgdt3303 chip
334 */
335 static u8 lgdt3303_qam_data[] = {
336 0x04, 0x00,
337 0x0d, 0x00,
338 0x0e, 0x00,
339 0x0f, 0x00,
340 0x10, 0x00,
341 0x51, 0x63,
342 0x47, 0x66,
343 0x48, 0x66,
344 0x4d, 0x1a,
345 0x49, 0x08,
346 0x4a, 0x9b };
347
348 struct lgdt330x_state* state = fe->demodulator_priv;
349
350 static u8 top_ctrl_cfg[] = { TOP_CONTROL, 0x03 };
351
352 int err;
353 /* Change only if we are actually changing the modulation */
354 if (state->current_modulation != param->u.vsb.modulation) {
355 switch(param->u.vsb.modulation) {
356 case VSB_8:
357 dprintk("%s: VSB_8 MODE\n", __FUNCTION__);
358
359 /* Select VSB mode */
360 top_ctrl_cfg[1] = 0x03;
361
362 /* Select ANT connector if supported by card */
363 if (state->config->pll_rf_set)
364 state->config->pll_rf_set(fe, 1);
365
366 if (state->config->demod_chip == LGDT3303) {
367 err = i2c_write_demod_bytes(state, lgdt3303_8vsb_44_data,
368 sizeof(lgdt3303_8vsb_44_data));
369 }
370 break;
371
372 case QAM_64:
373 dprintk("%s: QAM_64 MODE\n", __FUNCTION__);
374
375 /* Select QAM_64 mode */
376 top_ctrl_cfg[1] = 0x00;
377
378 /* Select CABLE connector if supported by card */
379 if (state->config->pll_rf_set)
380 state->config->pll_rf_set(fe, 0);
381
382 if (state->config->demod_chip == LGDT3303) {
383 err = i2c_write_demod_bytes(state, lgdt3303_qam_data,
384 sizeof(lgdt3303_qam_data));
385 }
386 break;
387
388 case QAM_256:
389 dprintk("%s: QAM_256 MODE\n", __FUNCTION__);
390
391 /* Select QAM_256 mode */
392 top_ctrl_cfg[1] = 0x01;
393
394 /* Select CABLE connector if supported by card */
395 if (state->config->pll_rf_set)
396 state->config->pll_rf_set(fe, 0);
397
398 if (state->config->demod_chip == LGDT3303) {
399 err = i2c_write_demod_bytes(state, lgdt3303_qam_data,
400 sizeof(lgdt3303_qam_data));
401 }
402 break;
403 default:
404 printk(KERN_WARNING "lgdt330x: %s: Modulation type(%d) UNSUPPORTED\n", __FUNCTION__, param->u.vsb.modulation);
405 return -1;
406 }
407 /*
408 * select serial or parallel MPEG harware interface
409 * Serial: 0x04 for LGDT3302 or 0x40 for LGDT3303
410 * Parallel: 0x00
411 */
412 top_ctrl_cfg[1] |= state->config->serial_mpeg;
413
414 /* Select the requested mode */
415 i2c_write_demod_bytes(state, top_ctrl_cfg,
416 sizeof(top_ctrl_cfg));
417 state->config->set_ts_params(fe, 0);
418 state->current_modulation = param->u.vsb.modulation;
419 }
420
421 /* Change only if we are actually changing the channel */
422 if (state->current_frequency != param->frequency) {
423 /* Tune to the new frequency */
424 state->config->pll_set(fe, param);
425 /* Keep track of the new frequency */
426 state->current_frequency = param->frequency;
427 }
428 lgdt330x_SwReset(state);
429 return 0;
430}
431
432static int lgdt330x_get_frontend(struct dvb_frontend* fe,
433 struct dvb_frontend_parameters* param)
434{
435 struct lgdt330x_state *state = fe->demodulator_priv;
436 param->frequency = state->current_frequency;
437 return 0;
438}
439
440static int lgdt3302_read_status(struct dvb_frontend* fe, fe_status_t* status)
441{
442 struct lgdt330x_state* state = fe->demodulator_priv;
443 u8 buf[3];
444
445 *status = 0; /* Reset status result */
446
447 /* AGC status register */
448 i2c_read_demod_bytes(state, AGC_STATUS, buf, 1);
449 dprintk("%s: AGC_STATUS = 0x%02x\n", __FUNCTION__, buf[0]);
450 if ((buf[0] & 0x0c) == 0x8){
451 /* Test signal does not exist flag */
452 /* as well as the AGC lock flag. */
453 *status |= FE_HAS_SIGNAL;
454 } else {
455 /* Without a signal all other status bits are meaningless */
456 return 0;
457 }
458
459 /*
460 * You must set the Mask bits to 1 in the IRQ_MASK in order
461 * to see that status bit in the IRQ_STATUS register.
462 * This is done in SwReset();
463 */
464 /* signal status */
465 i2c_read_demod_bytes(state, TOP_CONTROL, buf, sizeof(buf));
466 dprintk("%s: TOP_CONTROL = 0x%02x, IRO_MASK = 0x%02x, IRQ_STATUS = 0x%02x\n", __FUNCTION__, buf[0], buf[1], buf[2]);
467
468
469 /* sync status */
470 if ((buf[2] & 0x03) == 0x01) {
471 *status |= FE_HAS_SYNC;
472 }
473
474 /* FEC error status */
475 if ((buf[2] & 0x0c) == 0x08) {
476 *status |= FE_HAS_LOCK;
477 *status |= FE_HAS_VITERBI;
478 }
479
480 /* Carrier Recovery Lock Status Register */
481 i2c_read_demod_bytes(state, CARRIER_LOCK, buf, 1);
482 dprintk("%s: CARRIER_LOCK = 0x%02x\n", __FUNCTION__, buf[0]);
483 switch (state->current_modulation) {
484 case QAM_256:
485 case QAM_64:
486 /* Need to undestand why there are 3 lock levels here */
487 if ((buf[0] & 0x07) == 0x07)
488 *status |= FE_HAS_CARRIER;
489 break;
490 case VSB_8:
491 if ((buf[0] & 0x80) == 0x80)
492 *status |= FE_HAS_CARRIER;
493 break;
494 default:
495 printk("KERN_WARNING lgdt330x: %s: Modulation set to unsupported value\n", __FUNCTION__);
496 }
497
498 return 0;
499}
500
501static int lgdt3303_read_status(struct dvb_frontend* fe, fe_status_t* status)
502{
503 struct lgdt330x_state* state = fe->demodulator_priv;
504 int err;
505 u8 buf[3];
506
507 *status = 0; /* Reset status result */
508
509 /* lgdt3303 AGC status register */
510 err = i2c_read_demod_bytes(state, 0x58, buf, 1);
511 if (err < 0)
512 return err;
513
514 dprintk("%s: AGC_STATUS = 0x%02x\n", __FUNCTION__, buf[0]);
515 if ((buf[0] & 0x21) == 0x01){
516 /* Test input signal does not exist flag */
517 /* as well as the AGC lock flag. */
518 *status |= FE_HAS_SIGNAL;
519 } else {
520 /* Without a signal all other status bits are meaningless */
521 return 0;
522 }
523
524 /* Carrier Recovery Lock Status Register */
525 i2c_read_demod_bytes(state, CARRIER_LOCK, buf, 1);
526 dprintk("%s: CARRIER_LOCK = 0x%02x\n", __FUNCTION__, buf[0]);
527 switch (state->current_modulation) {
528 case QAM_256:
529 case QAM_64:
530 /* Need to undestand why there are 3 lock levels here */
531 if ((buf[0] & 0x07) == 0x07)
532 *status |= FE_HAS_CARRIER;
533 else
534 break;
535 i2c_read_demod_bytes(state, 0x8a, buf, 1);
536 if ((buf[0] & 0x04) == 0x04)
537 *status |= FE_HAS_SYNC;
538 if ((buf[0] & 0x01) == 0x01)
539 *status |= FE_HAS_LOCK;
540 if ((buf[0] & 0x08) == 0x08)
541 *status |= FE_HAS_VITERBI;
542 break;
543 case VSB_8:
544 if ((buf[0] & 0x80) == 0x80)
545 *status |= FE_HAS_CARRIER;
546 else
547 break;
548 i2c_read_demod_bytes(state, 0x38, buf, 1);
549 if ((buf[0] & 0x02) == 0x00)
550 *status |= FE_HAS_SYNC;
551 if ((buf[0] & 0x01) == 0x01) {
552 *status |= FE_HAS_LOCK;
553 *status |= FE_HAS_VITERBI;
554 }
555 break;
556 default:
557 printk("KERN_WARNING lgdt330x: %s: Modulation set to unsupported value\n", __FUNCTION__);
558 }
559 return 0;
560}
561
562static int lgdt330x_read_signal_strength(struct dvb_frontend* fe, u16* strength)
563{
564 /* not directly available. */
565 *strength = 0;
566 return 0;
567}
568
569static int lgdt3302_read_snr(struct dvb_frontend* fe, u16* snr)
570{
571#ifdef SNR_IN_DB
572 /*
573 * Spec sheet shows formula for SNR_EQ = 10 log10(25 * 24**2 / noise)
574 * and SNR_PH = 10 log10(25 * 32**2 / noise) for equalizer and phase tracker
575 * respectively. The following tables are built on these formulas.
576 * The usual definition is SNR = 20 log10(signal/noise)
577 * If the specification is wrong the value retuned is 1/2 the actual SNR in db.
578 *
579 * This table is a an ordered list of noise values computed by the
580 * formula from the spec sheet such that the index into the table
581 * starting at 43 or 45 is the SNR value in db. There are duplicate noise
582 * value entries at the beginning because the SNR varies more than
583 * 1 db for a change of 1 digit in noise at very small values of noise.
584 *
585 * Examples from SNR_EQ table:
586 * noise SNR
587 * 0 43
588 * 1 42
589 * 2 39
590 * 3 37
591 * 4 36
592 * 5 35
593 * 6 34
594 * 7 33
595 * 8 33
596 * 9 32
597 * 10 32
598 * 11 31
599 * 12 31
600 * 13 30
601 */
602
603 static const u32 SNR_EQ[] =
604 { 1, 2, 2, 2, 3, 3, 4, 4, 5, 7,
605 9, 11, 13, 17, 21, 26, 33, 41, 52, 65,
606 81, 102, 129, 162, 204, 257, 323, 406, 511, 644,
607 810, 1020, 1284, 1616, 2035, 2561, 3224, 4059, 5110, 6433,
608 8098, 10195, 12835, 16158, 20341, 25608, 32238, 40585, 51094, 64323,
609 80978, 101945, 128341, 161571, 203406, 256073, 0x40000
610 };
611
612 static const u32 SNR_PH[] =
613 { 1, 2, 2, 2, 3, 3, 4, 5, 6, 8,
614 10, 12, 15, 19, 23, 29, 37, 46, 58, 73,
615 91, 115, 144, 182, 229, 288, 362, 456, 574, 722,
616 909, 1144, 1440, 1813, 2282, 2873, 3617, 4553, 5732, 7216,
617 9084, 11436, 14396, 18124, 22817, 28724, 36161, 45524, 57312, 72151,
618 90833, 114351, 143960, 181235, 228161, 0x080000
619 };
620
621 static u8 buf[5];/* read data buffer */
622 static u32 noise; /* noise value */
623 static u32 snr_db; /* index into SNR_EQ[] */
624 struct lgdt330x_state* state = (struct lgdt330x_state*) fe->demodulator_priv;
625
626 /* read both equalizer and phase tracker noise data */
627 i2c_read_demod_bytes(state, EQPH_ERR0, buf, sizeof(buf));
628
629 if (state->current_modulation == VSB_8) {
630 /* Equalizer Mean-Square Error Register for VSB */
631 noise = ((buf[0] & 7) << 16) | (buf[1] << 8) | buf[2];
632
633 /*
634 * Look up noise value in table.
635 * A better search algorithm could be used...
636 * watch out there are duplicate entries.
637 */
638 for (snr_db = 0; snr_db < sizeof(SNR_EQ); snr_db++) {
639 if (noise < SNR_EQ[snr_db]) {
640 *snr = 43 - snr_db;
641 break;
642 }
643 }
644 } else {
645 /* Phase Tracker Mean-Square Error Register for QAM */
646 noise = ((buf[0] & 7<<3) << 13) | (buf[3] << 8) | buf[4];
647
648 /* Look up noise value in table. */
649 for (snr_db = 0; snr_db < sizeof(SNR_PH); snr_db++) {
650 if (noise < SNR_PH[snr_db]) {
651 *snr = 45 - snr_db;
652 break;
653 }
654 }
655 }
656#else
657 /* Return the raw noise value */
658 static u8 buf[5];/* read data buffer */
659 static u32 noise; /* noise value */
660 struct lgdt330x_state* state = (struct lgdt330x_state*) fe->demodulator_priv;
661
662 /* read both equalizer and pase tracker noise data */
663 i2c_read_demod_bytes(state, EQPH_ERR0, buf, sizeof(buf));
664
665 if (state->current_modulation == VSB_8) {
666 /* Phase Tracker Mean-Square Error Register for VSB */
667 noise = ((buf[0] & 7<<3) << 13) | (buf[3] << 8) | buf[4];
668 } else {
669
670 /* Carrier Recovery Mean-Square Error for QAM */
671 i2c_read_demod_bytes(state, 0x1a, buf, 2);
672 noise = ((buf[0] & 3) << 8) | buf[1];
673 }
674
675 /* Small values for noise mean signal is better so invert noise */
676 *snr = ~noise;
677#endif
678
679 dprintk("%s: noise = 0x%05x, snr = %idb\n",__FUNCTION__, noise, *snr);
680
681 return 0;
682}
683
684static int lgdt3303_read_snr(struct dvb_frontend* fe, u16* snr)
685{
686 /* Return the raw noise value */
687 static u8 buf[5];/* read data buffer */
688 static u32 noise; /* noise value */
689 struct lgdt330x_state* state = (struct lgdt330x_state*) fe->demodulator_priv;
690
691 if (state->current_modulation == VSB_8) {
692
693 /* Phase Tracker Mean-Square Error Register for VSB */
694 noise = ((buf[0] & 7) << 16) | (buf[3] << 8) | buf[4];
695 } else {
696
697 /* Carrier Recovery Mean-Square Error for QAM */
698 i2c_read_demod_bytes(state, 0x1a, buf, 2);
699 noise = (buf[0] << 8) | buf[1];
700 }
701
702 /* Small values for noise mean signal is better so invert noise */
703 *snr = ~noise;
704
705 dprintk("%s: noise = 0x%05x, snr = %idb\n",__FUNCTION__, noise, *snr);
706
707 return 0;
708}
709
710static int lgdt330x_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fe_tune_settings)
711{
712 /* I have no idea about this - it may not be needed */
713 fe_tune_settings->min_delay_ms = 500;
714 fe_tune_settings->step_size = 0;
715 fe_tune_settings->max_drift = 0;
716 return 0;
717}
718
719static void lgdt330x_release(struct dvb_frontend* fe)
720{
721 struct lgdt330x_state* state = (struct lgdt330x_state*) fe->demodulator_priv;
722 kfree(state);
723}
724
725static struct dvb_frontend_ops lgdt3302_ops;
726static struct dvb_frontend_ops lgdt3303_ops;
727
728struct dvb_frontend* lgdt330x_attach(const struct lgdt330x_config* config,
729 struct i2c_adapter* i2c)
730{
731 struct lgdt330x_state* state = NULL;
732 u8 buf[1];
733
734 /* Allocate memory for the internal state */
735 state = (struct lgdt330x_state*) kmalloc(sizeof(struct lgdt330x_state), GFP_KERNEL);
736 if (state == NULL)
737 goto error;
738 memset(state,0,sizeof(*state));
739
740 /* Setup the state */
741 state->config = config;
742 state->i2c = i2c;
743 switch (config->demod_chip) {
744 case LGDT3302:
745 memcpy(&state->ops, &lgdt3302_ops, sizeof(struct dvb_frontend_ops));
746 break;
747 case LGDT3303:
748 memcpy(&state->ops, &lgdt3303_ops, sizeof(struct dvb_frontend_ops));
749 break;
750 default:
751 goto error;
752 }
753
754 /* Verify communication with demod chip */
755 if (i2c_read_demod_bytes(state, 2, buf, 1))
756 goto error;
757
758 state->current_frequency = -1;
759 state->current_modulation = -1;
760
761 /* Create dvb_frontend */
762 state->frontend.ops = &state->ops;
763 state->frontend.demodulator_priv = state;
764 return &state->frontend;
765
766error:
767 if (state)
768 kfree(state);
769 dprintk("%s: ERROR\n",__FUNCTION__);
770 return NULL;
771}
772
773static struct dvb_frontend_ops lgdt3302_ops = {
774 .info = {
775 .name= "LG Electronics LGDT3302/LGDT3303 VSB/QAM Frontend",
776 .type = FE_ATSC,
777 .frequency_min= 54000000,
778 .frequency_max= 858000000,
779 .frequency_stepsize= 62500,
780 /* Symbol rate is for all VSB modes need to check QAM */
781 .symbol_rate_min = 10762000,
782 .symbol_rate_max = 10762000,
783 .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
784 },
785 .init = lgdt330x_init,
786 .set_frontend = lgdt330x_set_parameters,
787 .get_frontend = lgdt330x_get_frontend,
788 .get_tune_settings = lgdt330x_get_tune_settings,
789 .read_status = lgdt3302_read_status,
790 .read_ber = lgdt330x_read_ber,
791 .read_signal_strength = lgdt330x_read_signal_strength,
792 .read_snr = lgdt3302_read_snr,
793 .read_ucblocks = lgdt330x_read_ucblocks,
794 .release = lgdt330x_release,
795};
796
797static struct dvb_frontend_ops lgdt3303_ops = {
798 .info = {
799 .name= "LG Electronics LGDT3303 VSB/QAM Frontend",
800 .type = FE_ATSC,
801 .frequency_min= 54000000,
802 .frequency_max= 858000000,
803 .frequency_stepsize= 62500,
804 /* Symbol rate is for all VSB modes need to check QAM */
805 .symbol_rate_min = 10762000,
806 .symbol_rate_max = 10762000,
807 .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
808 },
809 .init = lgdt330x_init,
810 .set_frontend = lgdt330x_set_parameters,
811 .get_frontend = lgdt330x_get_frontend,
812 .get_tune_settings = lgdt330x_get_tune_settings,
813 .read_status = lgdt3303_read_status,
814 .read_ber = lgdt330x_read_ber,
815 .read_signal_strength = lgdt330x_read_signal_strength,
816 .read_snr = lgdt3303_read_snr,
817 .read_ucblocks = lgdt330x_read_ucblocks,
818 .release = lgdt330x_release,
819};
820
821MODULE_DESCRIPTION("LGDT330X (ATSC 8VSB & ITU-T J.83 AnnexB 64/256 QAM) Demodulator Driver");
822MODULE_AUTHOR("Wilson Michaels");
823MODULE_LICENSE("GPL");
824
825EXPORT_SYMBOL(lgdt330x_attach);
826
827/*
828 * Local variables:
829 * c-basic-offset: 8
830 * End:
831 */
diff --git a/drivers/media/dvb/frontends/lgdt3302.h b/drivers/media/dvb/frontends/lgdt330x.h
index 81587a40032b..e209ba1e47c5 100644
--- a/drivers/media/dvb/frontends/lgdt3302.h
+++ b/drivers/media/dvb/frontends/lgdt330x.h
@@ -1,7 +1,5 @@
1/* 1/*
2 * $Id: lgdt3302.h,v 1.2 2005/06/28 23:50:48 mkrufky Exp $ 2 * Support for LGDT3302 and LGDT3303 - VSB/QAM
3 *
4 * Support for LGDT3302 (DViCO FustionHDTV 3 Gold) - VSB/QAM
5 * 3 *
6 * Copyright (C) 2005 Wilson Michaels <wilsonmichaels@earthlink.net> 4 * Copyright (C) 2005 Wilson Michaels <wilsonmichaels@earthlink.net>
7 * 5 *
@@ -21,26 +19,40 @@
21 * 19 *
22 */ 20 */
23 21
24#ifndef LGDT3302_H 22#ifndef LGDT330X_H
25#define LGDT3302_H 23#define LGDT330X_H
26 24
27#include <linux/dvb/frontend.h> 25#include <linux/dvb/frontend.h>
28 26
29struct lgdt3302_config 27typedef enum lg_chip_t {
28 UNDEFINED,
29 LGDT3302,
30 LGDT3303
31}lg_chip_type;
32
33struct lgdt330x_config
30{ 34{
31 /* The demodulator's i2c address */ 35 /* The demodulator's i2c address */
32 u8 demod_address; 36 u8 demod_address;
33 u8 pll_address; 37
34 struct dvb_pll_desc *pll_desc; 38 /* LG demodulator chip LGDT3302 or LGDT3303 */
39 lg_chip_type demod_chip;
40
41 /* MPEG hardware interface - 0:parallel 1:serial */
42 int serial_mpeg;
43
44 /* PLL interface */
45 int (*pll_rf_set) (struct dvb_frontend* fe, int index);
46 int (*pll_set)(struct dvb_frontend* fe, struct dvb_frontend_parameters* params);
35 47
36 /* Need to set device param for start_dma */ 48 /* Need to set device param for start_dma */
37 int (*set_ts_params)(struct dvb_frontend* fe, int is_punctured); 49 int (*set_ts_params)(struct dvb_frontend* fe, int is_punctured);
38}; 50};
39 51
40extern struct dvb_frontend* lgdt3302_attach(const struct lgdt3302_config* config, 52extern struct dvb_frontend* lgdt330x_attach(const struct lgdt330x_config* config,
41 struct i2c_adapter* i2c); 53 struct i2c_adapter* i2c);
42 54
43#endif /* LGDT3302_H */ 55#endif /* LGDT330X_H */
44 56
45/* 57/*
46 * Local variables: 58 * Local variables:
diff --git a/drivers/media/dvb/frontends/lgdt3302_priv.h b/drivers/media/dvb/frontends/lgdt330x_priv.h
index 6193fa7a569d..59b7c5b9012d 100644
--- a/drivers/media/dvb/frontends/lgdt3302_priv.h
+++ b/drivers/media/dvb/frontends/lgdt330x_priv.h
@@ -1,7 +1,5 @@
1/* 1/*
2 * $Id: lgdt3302_priv.h,v 1.2 2005/06/28 23:50:48 mkrufky Exp $ 2 * Support for LGDT3302 and LGDT3303 - VSB/QAM
3 *
4 * Support for LGDT3302 (DViCO FustionHDTV 3 Gold) - VSB/QAM
5 * 3 *
6 * Copyright (C) 2005 Wilson Michaels <wilsonmichaels@earthlink.net> 4 * Copyright (C) 2005 Wilson Michaels <wilsonmichaels@earthlink.net>
7 * 5 *
@@ -21,8 +19,8 @@
21 * 19 *
22 */ 20 */
23 21
24#ifndef _LGDT3302_PRIV_ 22#ifndef _LGDT330X_PRIV_
25#define _LGDT3302_PRIV_ 23#define _LGDT330X_PRIV_
26 24
27/* i2c control register addresses */ 25/* i2c control register addresses */
28enum I2C_REG { 26enum I2C_REG {
@@ -59,11 +57,13 @@ enum I2C_REG {
59 PH_ERR1= 0x4a, 57 PH_ERR1= 0x4a,
60 PH_ERR2= 0x4b, 58 PH_ERR2= 0x4b,
61 DEMUX_CONTROL= 0x66, 59 DEMUX_CONTROL= 0x66,
62 PACKET_ERR_COUNTER1= 0x6a, 60 LGDT3302_PACKET_ERR_COUNTER1= 0x6a,
63 PACKET_ERR_COUNTER2= 0x6b, 61 LGDT3302_PACKET_ERR_COUNTER2= 0x6b,
62 LGDT3303_PACKET_ERR_COUNTER1= 0x8b,
63 LGDT3303_PACKET_ERR_COUNTER2= 0x8c,
64}; 64};
65 65
66#endif /* _LGDT3302_PRIV_ */ 66#endif /* _LGDT330X_PRIV_ */
67 67
68/* 68/*
69 * Local variables: 69 * Local variables:
diff --git a/drivers/media/radio/radio-maestro.c b/drivers/media/radio/radio-maestro.c
index e62147e4ed1b..e5e2021a7312 100644
--- a/drivers/media/radio/radio-maestro.c
+++ b/drivers/media/radio/radio-maestro.c
@@ -154,7 +154,7 @@ static void radio_bits_set(struct radio_device *dev, __u32 data)
154 msleep(125); 154 msleep(125);
155} 155}
156 156
157inline static int radio_function(struct inode *inode, struct file *file, 157static inline int radio_function(struct inode *inode, struct file *file,
158 unsigned int cmd, void *arg) 158 unsigned int cmd, void *arg)
159{ 159{
160 struct video_device *dev = video_devdata(file); 160 struct video_device *dev = video_devdata(file);
@@ -283,7 +283,7 @@ static int __init maestro_radio_init(void)
283module_init(maestro_radio_init); 283module_init(maestro_radio_init);
284module_exit(maestro_radio_exit); 284module_exit(maestro_radio_exit);
285 285
286inline static __u16 radio_power_on(struct radio_device *dev) 286static inline __u16 radio_power_on(struct radio_device *dev)
287{ 287{
288 register __u16 io=dev->io; 288 register __u16 io=dev->io;
289 register __u32 ofreq; 289 register __u32 ofreq;
diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
index 5b748a48ce72..02d39a50d5ed 100644
--- a/drivers/media/radio/radio-maxiradio.c
+++ b/drivers/media/radio/radio-maxiradio.c
@@ -166,7 +166,7 @@ static int get_tune(__u16 io)
166} 166}
167 167
168 168
169inline static int radio_function(struct inode *inode, struct file *file, 169static inline int radio_function(struct inode *inode, struct file *file,
170 unsigned int cmd, void *arg) 170 unsigned int cmd, void *arg)
171{ 171{
172 struct video_device *dev = video_devdata(file); 172 struct video_device *dev = video_devdata(file);
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index f461750c7646..ac81e5e01a9a 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -236,7 +236,7 @@ config VIDEO_MEYE
236 236
237config VIDEO_SAA7134 237config VIDEO_SAA7134
238 tristate "Philips SAA7134 support" 238 tristate "Philips SAA7134 support"
239 depends on VIDEO_DEV && PCI && I2C 239 depends on VIDEO_DEV && PCI && I2C && SOUND
240 select VIDEO_BUF 240 select VIDEO_BUF
241 select VIDEO_IR 241 select VIDEO_IR
242 select VIDEO_TUNER 242 select VIDEO_TUNER
@@ -331,7 +331,7 @@ config VIDEO_CX88_DVB
331 select DVB_MT352 331 select DVB_MT352
332 select DVB_OR51132 332 select DVB_OR51132
333 select DVB_CX22702 333 select DVB_CX22702
334 select DVB_LGDT3302 334 select DVB_LGDT330X
335 ---help--- 335 ---help---
336 This adds support for DVB/ATSC cards based on the 336 This adds support for DVB/ATSC cards based on the
337 Connexant 2388x chip. 337 Connexant 2388x chip.
diff --git a/drivers/media/video/bttv-cards.c b/drivers/media/video/bttv-cards.c
index 2dbf5ec43abd..a97b9b958ed6 100644
--- a/drivers/media/video/bttv-cards.c
+++ b/drivers/media/video/bttv-cards.c
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: bttv-cards.c,v 1.53 2005/07/05 17:37:35 nsh Exp $ 2 $Id: bttv-cards.c,v 1.54 2005/07/19 18:26:46 mkrufky Exp $
3 3
4 bttv-cards.c 4 bttv-cards.c
5 5
@@ -95,7 +95,7 @@ static int __devinit pvr_boot(struct bttv *btv);
95static unsigned int triton1=0; 95static unsigned int triton1=0;
96static unsigned int vsfx=0; 96static unsigned int vsfx=0;
97static unsigned int latency = UNSET; 97static unsigned int latency = UNSET;
98static unsigned int no_overlay=-1; 98int no_overlay=-1;
99 99
100static unsigned int card[BTTV_MAX] = { [ 0 ... (BTTV_MAX-1) ] = UNSET }; 100static unsigned int card[BTTV_MAX] = { [ 0 ... (BTTV_MAX-1) ] = UNSET };
101static unsigned int pll[BTTV_MAX] = { [ 0 ... (BTTV_MAX-1) ] = UNSET }; 101static unsigned int pll[BTTV_MAX] = { [ 0 ... (BTTV_MAX-1) ] = UNSET };
@@ -2772,8 +2772,6 @@ void __devinit bttv_init_card2(struct bttv *btv)
2772 } 2772 }
2773 btv->pll.pll_current = -1; 2773 btv->pll.pll_current = -1;
2774 2774
2775 bttv_reset_audio(btv);
2776
2777 /* tuner configuration (from card list / autodetect / insmod option) */ 2775 /* tuner configuration (from card list / autodetect / insmod option) */
2778 if (UNSET != bttv_tvcards[btv->c.type].tuner_type) 2776 if (UNSET != bttv_tvcards[btv->c.type].tuner_type)
2779 if(UNSET == btv->tuner_type) 2777 if(UNSET == btv->tuner_type)
@@ -4298,9 +4296,11 @@ void __devinit bttv_check_chipset(void)
4298 printk(KERN_INFO "bttv: Host bridge needs VSFX enabled.\n"); 4296 printk(KERN_INFO "bttv: Host bridge needs VSFX enabled.\n");
4299 if (pcipci_fail) { 4297 if (pcipci_fail) {
4300 printk(KERN_WARNING "bttv: BT848 and your chipset may not work together.\n"); 4298 printk(KERN_WARNING "bttv: BT848 and your chipset may not work together.\n");
4301 if (UNSET == no_overlay) { 4299 if (!no_overlay) {
4302 printk(KERN_WARNING "bttv: going to disable overlay.\n"); 4300 printk(KERN_WARNING "bttv: overlay will be disabled.\n");
4303 no_overlay = 1; 4301 no_overlay = 1;
4302 } else {
4303 printk(KERN_WARNING "bttv: overlay forced. Use this option at your own risk.\n");
4304 } 4304 }
4305 } 4305 }
4306 if (UNSET != latency) 4306 if (UNSET != latency)
diff --git a/drivers/media/video/bttv-driver.c b/drivers/media/video/bttv-driver.c
index 51a0f6d68e73..eee9322ce21b 100644
--- a/drivers/media/video/bttv-driver.c
+++ b/drivers/media/video/bttv-driver.c
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: bttv-driver.c,v 1.42 2005/07/05 17:37:35 nsh Exp $ 2 $Id: bttv-driver.c,v 1.52 2005/08/04 00:55:16 mchehab Exp $
3 3
4 bttv - Bt848 frame grabber driver 4 bttv - Bt848 frame grabber driver
5 5
@@ -80,6 +80,7 @@ static unsigned int irq_iswitch = 0;
80static unsigned int uv_ratio = 50; 80static unsigned int uv_ratio = 50;
81static unsigned int full_luma_range = 0; 81static unsigned int full_luma_range = 0;
82static unsigned int coring = 0; 82static unsigned int coring = 0;
83extern int no_overlay;
83 84
84/* API features (turn on/off stuff for testing) */ 85/* API features (turn on/off stuff for testing) */
85static unsigned int v4l2 = 1; 86static unsigned int v4l2 = 1;
@@ -2151,6 +2152,10 @@ static int bttv_s_fmt(struct bttv_fh *fh, struct bttv *btv,
2151 return 0; 2152 return 0;
2152 } 2153 }
2153 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 2154 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
2155 if (no_overlay > 0) {
2156 printk ("V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
2157 return -EINVAL;
2158 }
2154 return setup_window(fh, btv, &f->fmt.win, 1); 2159 return setup_window(fh, btv, &f->fmt.win, 1);
2155 case V4L2_BUF_TYPE_VBI_CAPTURE: 2160 case V4L2_BUF_TYPE_VBI_CAPTURE:
2156 retval = bttv_switch_type(fh,f->type); 2161 retval = bttv_switch_type(fh,f->type);
@@ -2224,9 +2229,11 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2224 /* others */ 2229 /* others */
2225 cap->type = VID_TYPE_CAPTURE| 2230 cap->type = VID_TYPE_CAPTURE|
2226 VID_TYPE_TUNER| 2231 VID_TYPE_TUNER|
2227 VID_TYPE_OVERLAY|
2228 VID_TYPE_CLIPPING| 2232 VID_TYPE_CLIPPING|
2229 VID_TYPE_SCALES; 2233 VID_TYPE_SCALES;
2234 if (no_overlay <= 0)
2235 cap->type |= VID_TYPE_OVERLAY;
2236
2230 cap->maxwidth = bttv_tvnorms[btv->tvnorm].swidth; 2237 cap->maxwidth = bttv_tvnorms[btv->tvnorm].swidth;
2231 cap->maxheight = bttv_tvnorms[btv->tvnorm].sheight; 2238 cap->maxheight = bttv_tvnorms[btv->tvnorm].sheight;
2232 cap->minwidth = 48; 2239 cap->minwidth = 48;
@@ -2302,6 +2309,11 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2302 struct video_window *win = arg; 2309 struct video_window *win = arg;
2303 struct v4l2_window w2; 2310 struct v4l2_window w2;
2304 2311
2312 if (no_overlay > 0) {
2313 printk ("VIDIOCSWIN: no_overlay\n");
2314 return -EINVAL;
2315 }
2316
2305 w2.field = V4L2_FIELD_ANY; 2317 w2.field = V4L2_FIELD_ANY;
2306 w2.w.left = win->x; 2318 w2.w.left = win->x;
2307 w2.w.top = win->y; 2319 w2.w.top = win->y;
@@ -2577,10 +2589,12 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2577 cap->version = BTTV_VERSION_CODE; 2589 cap->version = BTTV_VERSION_CODE;
2578 cap->capabilities = 2590 cap->capabilities =
2579 V4L2_CAP_VIDEO_CAPTURE | 2591 V4L2_CAP_VIDEO_CAPTURE |
2580 V4L2_CAP_VIDEO_OVERLAY |
2581 V4L2_CAP_VBI_CAPTURE | 2592 V4L2_CAP_VBI_CAPTURE |
2582 V4L2_CAP_READWRITE | 2593 V4L2_CAP_READWRITE |
2583 V4L2_CAP_STREAMING; 2594 V4L2_CAP_STREAMING;
2595 if (no_overlay <= 0)
2596 cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY;
2597
2584 if (bttv_tvcards[btv->c.type].tuner != UNSET && 2598 if (bttv_tvcards[btv->c.type].tuner != UNSET &&
2585 bttv_tvcards[btv->c.type].tuner != TUNER_ABSENT) 2599 bttv_tvcards[btv->c.type].tuner != TUNER_ABSENT)
2586 cap->capabilities |= V4L2_CAP_TUNER; 2600 cap->capabilities |= V4L2_CAP_TUNER;
@@ -3076,7 +3090,7 @@ static struct file_operations bttv_fops =
3076static struct video_device bttv_video_template = 3090static struct video_device bttv_video_template =
3077{ 3091{
3078 .name = "UNSET", 3092 .name = "UNSET",
3079 .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_OVERLAY| 3093 .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|
3080 VID_TYPE_CLIPPING|VID_TYPE_SCALES, 3094 VID_TYPE_CLIPPING|VID_TYPE_SCALES,
3081 .hardware = VID_HARDWARE_BT848, 3095 .hardware = VID_HARDWARE_BT848,
3082 .fops = &bttv_fops, 3096 .fops = &bttv_fops,
@@ -3756,6 +3770,12 @@ static void bttv_unregister_video(struct bttv *btv)
3756/* register video4linux devices */ 3770/* register video4linux devices */
3757static int __devinit bttv_register_video(struct bttv *btv) 3771static int __devinit bttv_register_video(struct bttv *btv)
3758{ 3772{
3773 if (no_overlay <= 0) {
3774 bttv_video_template.type |= VID_TYPE_OVERLAY;
3775 } else {
3776 printk("bttv: Overlay support disabled.\n");
3777 }
3778
3759 /* video */ 3779 /* video */
3760 btv->video_dev = vdev_init(btv, &bttv_video_template, "video"); 3780 btv->video_dev = vdev_init(btv, &bttv_video_template, "video");
3761 if (NULL == btv->video_dev) 3781 if (NULL == btv->video_dev)
@@ -3869,11 +3889,6 @@ static int __devinit bttv_probe(struct pci_dev *dev,
3869 pci_set_master(dev); 3889 pci_set_master(dev);
3870 pci_set_command(dev); 3890 pci_set_command(dev);
3871 pci_set_drvdata(dev,btv); 3891 pci_set_drvdata(dev,btv);
3872 if (!pci_dma_supported(dev,0xffffffff)) {
3873 printk("bttv%d: Oops: no 32bit PCI DMA ???\n", btv->c.nr);
3874 result = -EIO;
3875 goto fail1;
3876 }
3877 3892
3878 pci_read_config_byte(dev, PCI_CLASS_REVISION, &btv->revision); 3893 pci_read_config_byte(dev, PCI_CLASS_REVISION, &btv->revision);
3879 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat); 3894 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat);
diff --git a/drivers/media/video/bttv.h b/drivers/media/video/bttv.h
index 191eaf1714ba..f2af9e1454f0 100644
--- a/drivers/media/video/bttv.h
+++ b/drivers/media/video/bttv.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: bttv.h,v 1.18 2005/05/24 23:41:42 nsh Exp $ 2 * $Id: bttv.h,v 1.22 2005/07/28 18:41:21 mchehab Exp $
3 * 3 *
4 * bttv - Bt848 frame grabber driver 4 * bttv - Bt848 frame grabber driver
5 * 5 *
@@ -135,7 +135,9 @@
135#define BTTV_DVICO_DVBT_LITE 0x80 135#define BTTV_DVICO_DVBT_LITE 0x80
136#define BTTV_TIBET_CS16 0x83 136#define BTTV_TIBET_CS16 0x83
137#define BTTV_KODICOM_4400R 0x84 137#define BTTV_KODICOM_4400R 0x84
138#define BTTV_ADLINK_RTV24 0x85 138#define BTTV_ADLINK_RTV24 0x86
139#define BTTV_DVICO_FUSIONHDTV_5_LITE 0x87
140#define BTTV_ACORP_Y878F 0x88
139 141
140/* i2c address list */ 142/* i2c address list */
141#define I2C_TSA5522 0xc2 143#define I2C_TSA5522 0xc2
diff --git a/drivers/media/video/bttvp.h b/drivers/media/video/bttvp.h
index f3293e4a15ad..aab094bc243d 100644
--- a/drivers/media/video/bttvp.h
+++ b/drivers/media/video/bttvp.h
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: bttvp.h,v 1.19 2005/06/16 21:38:45 nsh Exp $ 2 $Id: bttvp.h,v 1.21 2005/07/15 21:44:14 mchehab Exp $
3 3
4 bttv - Bt848 frame grabber driver 4 bttv - Bt848 frame grabber driver
5 5
@@ -27,7 +27,7 @@
27#define _BTTVP_H_ 27#define _BTTVP_H_
28 28
29#include <linux/version.h> 29#include <linux/version.h>
30#define BTTV_VERSION_CODE KERNEL_VERSION(0,9,15) 30#define BTTV_VERSION_CODE KERNEL_VERSION(0,9,16)
31 31
32#include <linux/types.h> 32#include <linux/types.h>
33#include <linux/wait.h> 33#include <linux/wait.h>
diff --git a/drivers/media/video/cx88/Makefile b/drivers/media/video/cx88/Makefile
index 606d0348da2c..107e48645e3a 100644
--- a/drivers/media/video/cx88/Makefile
+++ b/drivers/media/video/cx88/Makefile
@@ -9,3 +9,15 @@ obj-$(CONFIG_VIDEO_CX88_DVB) += cx88-dvb.o
9EXTRA_CFLAGS += -I$(src)/.. 9EXTRA_CFLAGS += -I$(src)/..
10EXTRA_CFLAGS += -I$(srctree)/drivers/media/dvb/dvb-core 10EXTRA_CFLAGS += -I$(srctree)/drivers/media/dvb/dvb-core
11EXTRA_CFLAGS += -I$(srctree)/drivers/media/dvb/frontends 11EXTRA_CFLAGS += -I$(srctree)/drivers/media/dvb/frontends
12ifneq ($(CONFIG_DVB_CX22702),n)
13 EXTRA_CFLAGS += -DHAVE_CX22702=1
14endif
15ifneq ($(CONFIG_DVB_OR51132),n)
16 EXTRA_CFLAGS += -DHAVE_OR51132=1
17endif
18ifneq ($(CONFIG_DVB_LGDT330X),n)
19 EXTRA_CFLAGS += -DHAVE_LGDT330X=1
20endif
21ifneq ($(CONFIG_DVB_MT352),n)
22 EXTRA_CFLAGS += -DHAVE_MT352=1
23endif
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index 3d0c784b376f..ebf02a7f81e8 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88-cards.c,v 1.86 2005/07/14 03:06:43 mchehab Exp $ 2 * $Id: cx88-cards.c,v 1.90 2005/07/28 02:47:42 mkrufky Exp $
3 * 3 *
4 * device driver for Conexant 2388x based TV cards 4 * device driver for Conexant 2388x based TV cards
5 * card-specific stuff. 5 * card-specific stuff.
@@ -90,6 +90,9 @@ struct cx88_board cx88_boards[] = {
90 .input = {{ 90 .input = {{
91 .type = CX88_VMUX_TELEVISION, 91 .type = CX88_VMUX_TELEVISION,
92 .vmux = 0, 92 .vmux = 0,
93 },{
94 .type = CX88_VMUX_SVIDEO,
95 .vmux = 2,
93 }}, 96 }},
94 }, 97 },
95 [CX88_BOARD_PIXELVIEW] = { 98 [CX88_BOARD_PIXELVIEW] = {
@@ -496,6 +499,9 @@ struct cx88_board cx88_boards[] = {
496 .input = {{ 499 .input = {{
497 .type = CX88_VMUX_DVB, 500 .type = CX88_VMUX_DVB,
498 .vmux = 0, 501 .vmux = 0,
502 },{
503 .type = CX88_VMUX_SVIDEO,
504 .vmux = 2,
499 }}, 505 }},
500 .dvb = 1, 506 .dvb = 1,
501 }, 507 },
@@ -753,6 +759,27 @@ struct cx88_board cx88_boards[] = {
753 }}, 759 }},
754 .dvb = 1, 760 .dvb = 1,
755 }, 761 },
762 [CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD] = {
763 .name = "DViCO FusionHDTV 5 Gold",
764 .tuner_type = TUNER_LG_TDVS_H062F,
765 .radio_type = UNSET,
766 .tuner_addr = ADDR_UNSET,
767 .radio_addr = ADDR_UNSET,
768 /* See DViCO FusionHDTV 3 Gold-Q for GPIO documentation. */
769 .input = {{
770 .type = CX88_VMUX_TELEVISION,
771 .vmux = 0,
772 .gpio0 = 0x0f0d,
773 },{
774 .type = CX88_VMUX_COMPOSITE1,
775 .vmux = 1,
776 .gpio0 = 0x0f00,
777 },{
778 .type = CX88_VMUX_SVIDEO,
779 .vmux = 2,
780 .gpio0 = 0x0f00,
781 }},
782 },
756}; 783};
757const unsigned int cx88_bcount = ARRAY_SIZE(cx88_boards); 784const unsigned int cx88_bcount = ARRAY_SIZE(cx88_boards);
758 785
@@ -880,6 +907,10 @@ struct cx88_subid cx88_subids[] = {
880 .subvendor = 0x153b, 907 .subvendor = 0x153b,
881 .subdevice = 0x1166, 908 .subdevice = 0x1166,
882 .card = CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1, 909 .card = CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1,
910 },{
911 .subvendor = 0x18ac,
912 .subdevice = 0xd500,
913 .card = CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD,
883 }, 914 },
884}; 915};
885const unsigned int cx88_idcount = ARRAY_SIZE(cx88_subids); 916const unsigned int cx88_idcount = ARRAY_SIZE(cx88_subids);
diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c
index 6ad1458ab652..78d223257a68 100644
--- a/drivers/media/video/cx88/cx88-dvb.c
+++ b/drivers/media/video/cx88/cx88-dvb.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88-dvb.c,v 1.42 2005/07/12 15:44:55 mkrufky Exp $ 2 * $Id: cx88-dvb.c,v 1.58 2005/08/07 09:24:08 mkrufky Exp $
3 * 3 *
4 * device driver for Conexant 2388x based TV cards 4 * device driver for Conexant 2388x based TV cards
5 * MPEG Transport Stream (DVB) routines 5 * MPEG Transport Stream (DVB) routines
@@ -29,27 +29,23 @@
29#include <linux/kthread.h> 29#include <linux/kthread.h>
30#include <linux/file.h> 30#include <linux/file.h>
31#include <linux/suspend.h> 31#include <linux/suspend.h>
32 32#include <linux/config.h>
33#define CONFIG_DVB_MT352 1
34#define CONFIG_DVB_CX22702 1
35#define CONFIG_DVB_OR51132 1
36#define CONFIG_DVB_LGDT3302 1
37 33
38#include "cx88.h" 34#include "cx88.h"
39#include "dvb-pll.h" 35#include "dvb-pll.h"
40 36
41#if CONFIG_DVB_MT352 37#ifdef HAVE_MT352
42# include "mt352.h" 38# include "mt352.h"
43# include "mt352_priv.h" 39# include "mt352_priv.h"
44#endif 40#endif
45#if CONFIG_DVB_CX22702 41#ifdef HAVE_CX22702
46# include "cx22702.h" 42# include "cx22702.h"
47#endif 43#endif
48#if CONFIG_DVB_OR51132 44#ifdef HAVE_OR51132
49# include "or51132.h" 45# include "or51132.h"
50#endif 46#endif
51#if CONFIG_DVB_LGDT3302 47#ifdef HAVE_LGDT330X
52# include "lgdt3302.h" 48# include "lgdt330x.h"
53#endif 49#endif
54 50
55MODULE_DESCRIPTION("driver for cx2388x based DVB cards"); 51MODULE_DESCRIPTION("driver for cx2388x based DVB cards");
@@ -107,7 +103,7 @@ static struct videobuf_queue_ops dvb_qops = {
107 103
108/* ------------------------------------------------------------------ */ 104/* ------------------------------------------------------------------ */
109 105
110#if CONFIG_DVB_MT352 106#ifdef HAVE_MT352
111static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe) 107static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe)
112{ 108{
113 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x39 }; 109 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x39 };
@@ -177,7 +173,7 @@ static struct mt352_config dntv_live_dvbt_config = {
177}; 173};
178#endif 174#endif
179 175
180#if CONFIG_DVB_CX22702 176#ifdef HAVE_CX22702
181static struct cx22702_config connexant_refboard_config = { 177static struct cx22702_config connexant_refboard_config = {
182 .demod_address = 0x43, 178 .demod_address = 0x43,
183 .output_mode = CX22702_SERIAL_OUTPUT, 179 .output_mode = CX22702_SERIAL_OUTPUT,
@@ -193,7 +189,7 @@ static struct cx22702_config hauppauge_novat_config = {
193}; 189};
194#endif 190#endif
195 191
196#if CONFIG_DVB_OR51132 192#ifdef HAVE_OR51132
197static int or51132_set_ts_param(struct dvb_frontend* fe, 193static int or51132_set_ts_param(struct dvb_frontend* fe,
198 int is_punctured) 194 int is_punctured)
199{ 195{
@@ -210,8 +206,45 @@ static struct or51132_config pchdtv_hd3000 = {
210}; 206};
211#endif 207#endif
212 208
213#if CONFIG_DVB_LGDT3302 209#ifdef HAVE_LGDT330X
214static int lgdt3302_set_ts_param(struct dvb_frontend* fe, int is_punctured) 210static int lgdt330x_pll_set(struct dvb_frontend* fe,
211 struct dvb_frontend_parameters* params)
212{
213 struct cx8802_dev *dev= fe->dvb->priv;
214 u8 buf[4];
215 struct i2c_msg msg =
216 { .addr = dev->core->pll_addr, .flags = 0, .buf = buf, .len = 4 };
217 int err;
218
219 dvb_pll_configure(dev->core->pll_desc, buf, params->frequency, 0);
220 dprintk(1, "%s: tuner at 0x%02x bytes: 0x%02x 0x%02x 0x%02x 0x%02x\n",
221 __FUNCTION__, msg.addr, buf[0],buf[1],buf[2],buf[3]);
222 if ((err = i2c_transfer(&dev->core->i2c_adap, &msg, 1)) != 1) {
223 printk(KERN_WARNING "cx88-dvb: %s error "
224 "(addr %02x <- %02x, err = %i)\n",
225 __FUNCTION__, buf[0], buf[1], err);
226 if (err < 0)
227 return err;
228 else
229 return -EREMOTEIO;
230 }
231 return 0;
232}
233
234static int lgdt330x_pll_rf_set(struct dvb_frontend* fe, int index)
235{
236 struct cx8802_dev *dev= fe->dvb->priv;
237 struct cx88_core *core = dev->core;
238
239 dprintk(1, "%s: index = %d\n", __FUNCTION__, index);
240 if (index == 0)
241 cx_clear(MO_GP0_IO, 8);
242 else
243 cx_set(MO_GP0_IO, 8);
244 return 0;
245}
246
247static int lgdt330x_set_ts_param(struct dvb_frontend* fe, int is_punctured)
215{ 248{
216 struct cx8802_dev *dev= fe->dvb->priv; 249 struct cx8802_dev *dev= fe->dvb->priv;
217 if (is_punctured) 250 if (is_punctured)
@@ -221,18 +254,12 @@ static int lgdt3302_set_ts_param(struct dvb_frontend* fe, int is_punctured)
221 return 0; 254 return 0;
222} 255}
223 256
224static struct lgdt3302_config fusionhdtv_3_gold_q = { 257static struct lgdt330x_config fusionhdtv_3_gold = {
225 .demod_address = 0x0e,
226 .pll_address = 0x61,
227 .pll_desc = &dvb_pll_microtune_4042,
228 .set_ts_params = lgdt3302_set_ts_param,
229};
230
231static struct lgdt3302_config fusionhdtv_3_gold_t = {
232 .demod_address = 0x0e, 258 .demod_address = 0x0e,
233 .pll_address = 0x61, 259 .demod_chip = LGDT3302,
234 .pll_desc = &dvb_pll_thomson_dtt7611, 260 .serial_mpeg = 0x04, /* TPSERIAL for 3302 in TOP_CONTROL */
235 .set_ts_params = lgdt3302_set_ts_param, 261 .pll_set = lgdt330x_pll_set,
262 .set_ts_params = lgdt330x_set_ts_param,
236}; 263};
237#endif 264#endif
238 265
@@ -244,7 +271,7 @@ static int dvb_register(struct cx8802_dev *dev)
244 271
245 /* init frontend */ 272 /* init frontend */
246 switch (dev->core->board) { 273 switch (dev->core->board) {
247#if CONFIG_DVB_CX22702 274#ifdef HAVE_CX22702
248 case CX88_BOARD_HAUPPAUGE_DVB_T1: 275 case CX88_BOARD_HAUPPAUGE_DVB_T1:
249 dev->dvb.frontend = cx22702_attach(&hauppauge_novat_config, 276 dev->dvb.frontend = cx22702_attach(&hauppauge_novat_config,
250 &dev->core->i2c_adap); 277 &dev->core->i2c_adap);
@@ -255,7 +282,7 @@ static int dvb_register(struct cx8802_dev *dev)
255 &dev->core->i2c_adap); 282 &dev->core->i2c_adap);
256 break; 283 break;
257#endif 284#endif
258#if CONFIG_DVB_MT352 285#ifdef HAVE_MT352
259 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1: 286 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1:
260 dev->core->pll_addr = 0x61; 287 dev->core->pll_addr = 0x61;
261 dev->core->pll_desc = &dvb_pll_lg_z201; 288 dev->core->pll_desc = &dvb_pll_lg_z201;
@@ -277,13 +304,13 @@ static int dvb_register(struct cx8802_dev *dev)
277 &dev->core->i2c_adap); 304 &dev->core->i2c_adap);
278 break; 305 break;
279#endif 306#endif
280#if CONFIG_DVB_OR51132 307#ifdef HAVE_OR51132
281 case CX88_BOARD_PCHDTV_HD3000: 308 case CX88_BOARD_PCHDTV_HD3000:
282 dev->dvb.frontend = or51132_attach(&pchdtv_hd3000, 309 dev->dvb.frontend = or51132_attach(&pchdtv_hd3000,
283 &dev->core->i2c_adap); 310 &dev->core->i2c_adap);
284 break; 311 break;
285#endif 312#endif
286#if CONFIG_DVB_LGDT3302 313#ifdef HAVE_LGDT330X
287 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q: 314 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
288 dev->ts_gen_cntrl = 0x08; 315 dev->ts_gen_cntrl = 0x08;
289 { 316 {
@@ -292,9 +319,14 @@ static int dvb_register(struct cx8802_dev *dev)
292 319
293 cx_clear(MO_GP0_IO, 1); 320 cx_clear(MO_GP0_IO, 1);
294 mdelay(100); 321 mdelay(100);
295 cx_set(MO_GP0_IO, 9); // ANT connector too FIXME 322 cx_set(MO_GP0_IO, 1);
296 mdelay(200); 323 mdelay(200);
297 dev->dvb.frontend = lgdt3302_attach(&fusionhdtv_3_gold_q, 324
325 /* Select RF connector callback */
326 fusionhdtv_3_gold.pll_rf_set = lgdt330x_pll_rf_set;
327 dev->core->pll_addr = 0x61;
328 dev->core->pll_desc = &dvb_pll_microtune_4042;
329 dev->dvb.frontend = lgdt330x_attach(&fusionhdtv_3_gold,
298 &dev->core->i2c_adap); 330 &dev->core->i2c_adap);
299 } 331 }
300 break; 332 break;
@@ -306,9 +338,11 @@ static int dvb_register(struct cx8802_dev *dev)
306 338
307 cx_clear(MO_GP0_IO, 1); 339 cx_clear(MO_GP0_IO, 1);
308 mdelay(100); 340 mdelay(100);
309 cx_set(MO_GP0_IO, 9); /* ANT connector too FIXME */ 341 cx_set(MO_GP0_IO, 9);
310 mdelay(200); 342 mdelay(200);
311 dev->dvb.frontend = lgdt3302_attach(&fusionhdtv_3_gold_t, 343 dev->core->pll_addr = 0x61;
344 dev->core->pll_desc = &dvb_pll_thomson_dtt7611;
345 dev->dvb.frontend = lgdt330x_attach(&fusionhdtv_3_gold,
312 &dev->core->i2c_adap); 346 &dev->core->i2c_adap);
313 } 347 }
314 break; 348 break;
diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c
index 8403c4e95050..a628a55299c6 100644
--- a/drivers/media/video/cx88/cx88-i2c.c
+++ b/drivers/media/video/cx88/cx88-i2c.c
@@ -1,5 +1,5 @@
1/* 1/*
2 $Id: cx88-i2c.c,v 1.28 2005/07/05 17:37:35 nsh Exp $ 2 $Id: cx88-i2c.c,v 1.30 2005/07/25 05:10:13 mkrufky Exp $
3 3
4 cx88-i2c.c -- all the i2c code is here 4 cx88-i2c.c -- all the i2c code is here
5 5
@@ -164,7 +164,7 @@ static struct i2c_client cx8800_i2c_client_template = {
164}; 164};
165 165
166static char *i2c_devs[128] = { 166static char *i2c_devs[128] = {
167 [ 0x1c >> 1 ] = "lgdt3302", 167 [ 0x1c >> 1 ] = "lgdt330x",
168 [ 0x86 >> 1 ] = "tda9887/cx22702", 168 [ 0x86 >> 1 ] = "tda9887/cx22702",
169 [ 0xa0 >> 1 ] = "eeprom", 169 [ 0xa0 >> 1 ] = "eeprom",
170 [ 0xc0 >> 1 ] = "tuner (analog)", 170 [ 0xc0 >> 1 ] = "tuner (analog)",
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index 5588a3aeecb4..5f58c103198a 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88-video.c,v 1.80 2005/07/13 08:49:08 mchehab Exp $ 2 * $Id: cx88-video.c,v 1.82 2005/07/22 05:13:34 mkrufky Exp $
3 * 3 *
4 * device driver for Conexant 2388x based TV cards 4 * device driver for Conexant 2388x based TV cards
5 * video4linux video interface 5 * video4linux video interface
@@ -758,10 +758,10 @@ static int video_open(struct inode *inode, struct file *file)
758 struct cx88_core *core = dev->core; 758 struct cx88_core *core = dev->core;
759 int board = core->board; 759 int board = core->board;
760 dprintk(1,"video_open: setting radio device\n"); 760 dprintk(1,"video_open: setting radio device\n");
761 cx_write(MO_GP3_IO, cx88_boards[board].radio.gpio3);
761 cx_write(MO_GP0_IO, cx88_boards[board].radio.gpio0); 762 cx_write(MO_GP0_IO, cx88_boards[board].radio.gpio0);
762 cx_write(MO_GP1_IO, cx88_boards[board].radio.gpio1); 763 cx_write(MO_GP1_IO, cx88_boards[board].radio.gpio1);
763 cx_write(MO_GP2_IO, cx88_boards[board].radio.gpio2); 764 cx_write(MO_GP2_IO, cx88_boards[board].radio.gpio2);
764 cx_write(MO_GP3_IO, cx88_boards[board].radio.gpio3);
765 dev->core->tvaudio = WW_FM; 765 dev->core->tvaudio = WW_FM;
766 cx88_set_tvaudio(core); 766 cx88_set_tvaudio(core);
767 cx88_set_stereo(core,V4L2_TUNER_MODE_STEREO,1); 767 cx88_set_stereo(core,V4L2_TUNER_MODE_STEREO,1);
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index b008f7db6dfd..da65dc92787c 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: cx88.h,v 1.69 2005/07/13 17:25:25 mchehab Exp $ 2 * $Id: cx88.h,v 1.70 2005/07/24 17:44:09 mkrufky Exp $
3 * 3 *
4 * v4l2 device driver for cx2388x based TV cards 4 * v4l2 device driver for cx2388x based TV cards
5 * 5 *
@@ -171,6 +171,7 @@ extern struct sram_channel cx88_sram_channels[];
171#define CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T 28 171#define CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T 28
172#define CX88_BOARD_ADSTECH_DVB_T_PCI 29 172#define CX88_BOARD_ADSTECH_DVB_T_PCI 29
173#define CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1 30 173#define CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1 30
174#define CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD 31
174 175
175enum cx88_itype { 176enum cx88_itype {
176 CX88_VMUX_COMPOSITE1 = 1, 177 CX88_VMUX_COMPOSITE1 = 1,
diff --git a/drivers/media/video/msp3400.c b/drivers/media/video/msp3400.c
index 6239254db27e..62f1b8ddb98b 100644
--- a/drivers/media/video/msp3400.c
+++ b/drivers/media/video/msp3400.c
@@ -741,11 +741,9 @@ static int msp34xx_sleep(struct msp3400c *msp, int timeout)
741 schedule_timeout(msecs_to_jiffies(timeout)); 741 schedule_timeout(msecs_to_jiffies(timeout));
742 } 742 }
743 } 743 }
744 if (current->flags & PF_FREEZE) {
745 refrigerator ();
746 }
747 744
748 remove_wait_queue(&msp->wq, &wait); 745 remove_wait_queue(&msp->wq, &wait);
746 try_to_freeze();
749 return msp->restart; 747 return msp->restart;
750} 748}
751 749
diff --git a/drivers/media/video/mxb.c b/drivers/media/video/mxb.c
index 486234d41b56..d04793fb80fc 100644
--- a/drivers/media/video/mxb.c
+++ b/drivers/media/video/mxb.c
@@ -142,8 +142,8 @@ struct mxb
142 142
143 int cur_mode; /* current audio mode (mono, stereo, ...) */ 143 int cur_mode; /* current audio mode (mono, stereo, ...) */
144 int cur_input; /* current input */ 144 int cur_input; /* current input */
145 int cur_freq; /* current frequency the tuner is tuned to */
146 int cur_mute; /* current mute status */ 145 int cur_mute; /* current mute status */
146 struct v4l2_frequency cur_freq; /* current frequency the tuner is tuned to */
147}; 147};
148 148
149static struct saa7146_extension extension; 149static struct saa7146_extension extension;
@@ -352,9 +352,15 @@ static int mxb_init_done(struct saa7146_dev* dev)
352 /* select a tuner type */ 352 /* select a tuner type */
353 tun_setup.mode_mask = T_ANALOG_TV; 353 tun_setup.mode_mask = T_ANALOG_TV;
354 tun_setup.addr = ADDR_UNSET; 354 tun_setup.addr = ADDR_UNSET;
355 tun_setup.type = 5; 355 tun_setup.type = TUNER_PHILIPS_PAL;
356 mxb->tuner->driver->command(mxb->tuner,TUNER_SET_TYPE_ADDR, &tun_setup); 356 mxb->tuner->driver->command(mxb->tuner,TUNER_SET_TYPE_ADDR, &tun_setup);
357 357 /* tune in some frequency on tuner */
358 mxb->cur_freq.tuner = 0;
359 mxb->cur_freq.type = V4L2_TUNER_ANALOG_TV;
360 mxb->cur_freq.frequency = freq;
361 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_FREQUENCY,
362 &mxb->cur_freq);
363
358 /* mute audio on tea6420s */ 364 /* mute audio on tea6420s */
359 mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_line[6][0]); 365 mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_line[6][0]);
360 mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_line[6][1]); 366 mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_line[6][1]);
@@ -371,12 +377,8 @@ static int mxb_init_done(struct saa7146_dev* dev)
371 vm.out = 13; 377 vm.out = 13;
372 mxb->tea6415c->driver->command(mxb->tea6415c,TEA6415C_SWITCH, &vm); 378 mxb->tea6415c->driver->command(mxb->tea6415c,TEA6415C_SWITCH, &vm);
373 379
374 /* tune in some frequency on tuner */
375 mxb->tuner->driver->command(mxb->tuner, VIDIOCSFREQ, &freq);
376
377 /* the rest for mxb */ 380 /* the rest for mxb */
378 mxb->cur_input = 0; 381 mxb->cur_input = 0;
379 mxb->cur_freq = freq;
380 mxb->cur_mute = 1; 382 mxb->cur_mute = 1;
381 383
382 mxb->cur_mode = V4L2_TUNER_MODE_STEREO; 384 mxb->cur_mode = V4L2_TUNER_MODE_STEREO;
@@ -819,18 +821,14 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
819 return -EINVAL; 821 return -EINVAL;
820 } 822 }
821 823
822 memset(f,0,sizeof(*f)); 824 *f = mxb->cur_freq;
823 f->type = V4L2_TUNER_ANALOG_TV;
824 f->frequency = mxb->cur_freq;
825 825
826 DEB_EE(("VIDIOC_G_FREQ: freq:0x%08x.\n", mxb->cur_freq)); 826 DEB_EE(("VIDIOC_G_FREQ: freq:0x%08x.\n", mxb->cur_freq.frequency));
827 return 0; 827 return 0;
828 } 828 }
829 case VIDIOC_S_FREQUENCY: 829 case VIDIOC_S_FREQUENCY:
830 { 830 {
831 struct v4l2_frequency *f = arg; 831 struct v4l2_frequency *f = arg;
832 int t_locked = 0;
833 int v_byte = 0;
834 832
835 if (0 != f->tuner) 833 if (0 != f->tuner)
836 return -EINVAL; 834 return -EINVAL;
@@ -843,20 +841,11 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
843 return -EINVAL; 841 return -EINVAL;
844 } 842 }
845 843
846 DEB_EE(("VIDIOC_S_FREQUENCY: freq:0x%08x.\n",f->frequency)); 844 mxb->cur_freq = *f;
847 845 DEB_EE(("VIDIOC_S_FREQUENCY: freq:0x%08x.\n", mxb->cur_freq.frequency));
848 mxb->cur_freq = f->frequency;
849 846
850 /* tune in desired frequency */ 847 /* tune in desired frequency */
851 mxb->tuner->driver->command(mxb->tuner, VIDIOCSFREQ, &mxb->cur_freq); 848 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_FREQUENCY, &mxb->cur_freq);
852
853 /* check if pll of tuner & saa7111a is locked */
854// mxb->tuner->driver->command(mxb->tuner,TUNER_IS_LOCKED, &t_locked);
855 mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_GET_STATUS, &v_byte);
856
857 /* not locked -- anything to do here ? */
858 if( 0 == t_locked || 0 == (v_byte & DECODER_STATUS_GOOD)) {
859 }
860 849
861 /* hack: changing the frequency should invalidate the vbi-counter (=> alevt) */ 850 /* hack: changing the frequency should invalidate the vbi-counter (=> alevt) */
862 spin_lock(&dev->slock); 851 spin_lock(&dev->slock);
diff --git a/drivers/media/video/saa7134/Makefile b/drivers/media/video/saa7134/Makefile
index e577a06b136b..b778ffd94e65 100644
--- a/drivers/media/video/saa7134/Makefile
+++ b/drivers/media/video/saa7134/Makefile
@@ -9,3 +9,9 @@ obj-$(CONFIG_VIDEO_SAA7134_DVB) += saa7134-dvb.o
9EXTRA_CFLAGS += -I$(src)/.. 9EXTRA_CFLAGS += -I$(src)/..
10EXTRA_CFLAGS += -I$(srctree)/drivers/media/dvb/dvb-core 10EXTRA_CFLAGS += -I$(srctree)/drivers/media/dvb/dvb-core
11EXTRA_CFLAGS += -I$(srctree)/drivers/media/dvb/frontends 11EXTRA_CFLAGS += -I$(srctree)/drivers/media/dvb/frontends
12ifneq ($(CONFIG_DVB_MT352),n)
13 EXTRA_CFLAGS += -DHAVE_MT352=1
14endif
15ifneq ($(CONFIG_DVB_TDA1004X),n)
16 EXTRA_CFLAGS += -DHAVE_TDA1004X=1
17endif
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index 334bc1850092..8be6a90358c8 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-dvb.c,v 1.18 2005/07/04 16:05:50 mkrufky Exp $ 2 * $Id: saa7134-dvb.c,v 1.23 2005/07/24 22:12:47 mkrufky Exp $
3 * 3 *
4 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] 4 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
5 * 5 *
@@ -29,18 +29,17 @@
29#include <linux/delay.h> 29#include <linux/delay.h>
30#include <linux/kthread.h> 30#include <linux/kthread.h>
31#include <linux/suspend.h> 31#include <linux/suspend.h>
32#include <linux/config.h>
32 33
33#define CONFIG_DVB_MT352 1
34#define CONFIG_DVB_TDA1004X 1
35 34
36#include "saa7134-reg.h" 35#include "saa7134-reg.h"
37#include "saa7134.h" 36#include "saa7134.h"
38 37
39#if CONFIG_DVB_MT352 38#ifdef HAVE_MT352
40# include "mt352.h" 39# include "mt352.h"
41# include "mt352_priv.h" /* FIXME */ 40# include "mt352_priv.h" /* FIXME */
42#endif 41#endif
43#if CONFIG_DVB_TDA1004X 42#ifdef HAVE_TDA1004X
44# include "tda1004x.h" 43# include "tda1004x.h"
45#endif 44#endif
46 45
@@ -54,7 +53,7 @@ MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
54 53
55/* ------------------------------------------------------------------ */ 54/* ------------------------------------------------------------------ */
56 55
57#if CONFIG_DVB_MT352 56#ifdef HAVE_MT352
58static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on) 57static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
59{ 58{
60 u32 ok; 59 u32 ok;
@@ -153,7 +152,7 @@ static struct mt352_config pinnacle_300i = {
153 152
154/* ------------------------------------------------------------------ */ 153/* ------------------------------------------------------------------ */
155 154
156#if CONFIG_DVB_TDA1004X 155#ifdef HAVE_TDA1004X
157static int philips_tu1216_pll_init(struct dvb_frontend *fe) 156static int philips_tu1216_pll_init(struct dvb_frontend *fe)
158{ 157{
159 struct saa7134_dev *dev = fe->dvb->priv; 158 struct saa7134_dev *dev = fe->dvb->priv;
@@ -385,7 +384,7 @@ static int philips_fmd1216_pll_set(struct dvb_frontend *fe, struct dvb_frontend_
385 return 0; 384 return 0;
386} 385}
387 386
388 387#ifdef HAVE_TDA1004X
389static struct tda1004x_config medion_cardbus = { 388static struct tda1004x_config medion_cardbus = {
390 .demod_address = 0x08, 389 .demod_address = 0x08,
391 .invert = 1, 390 .invert = 1,
@@ -398,6 +397,7 @@ static struct tda1004x_config medion_cardbus = {
398 .pll_sleep = philips_fmd1216_analog, 397 .pll_sleep = philips_fmd1216_analog,
399 .request_firmware = NULL, 398 .request_firmware = NULL,
400}; 399};
400#endif
401 401
402/* ------------------------------------------------------------------ */ 402/* ------------------------------------------------------------------ */
403 403
@@ -547,14 +547,14 @@ static int dvb_init(struct saa7134_dev *dev)
547 dev); 547 dev);
548 548
549 switch (dev->board) { 549 switch (dev->board) {
550#if CONFIG_DVB_MT352 550#ifdef HAVE_MT352
551 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL: 551 case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL:
552 printk("%s: pinnacle 300i dvb setup\n",dev->name); 552 printk("%s: pinnacle 300i dvb setup\n",dev->name);
553 dev->dvb.frontend = mt352_attach(&pinnacle_300i, 553 dev->dvb.frontend = mt352_attach(&pinnacle_300i,
554 &dev->i2c_adap); 554 &dev->i2c_adap);
555 break; 555 break;
556#endif 556#endif
557#if CONFIG_DVB_TDA1004X 557#ifdef HAVE_TDA1004X
558 case SAA7134_BOARD_MD7134: 558 case SAA7134_BOARD_MD7134:
559 dev->dvb.frontend = tda10046_attach(&medion_cardbus, 559 dev->dvb.frontend = tda10046_attach(&medion_cardbus,
560 &dev->i2c_adap); 560 &dev->i2c_adap);
diff --git a/drivers/media/video/saa7134/saa7134-i2c.c b/drivers/media/video/saa7134/saa7134-i2c.c
index 93dd61978541..1203b93a572c 100644
--- a/drivers/media/video/saa7134/saa7134-i2c.c
+++ b/drivers/media/video/saa7134/saa7134-i2c.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134-i2c.c,v 1.19 2005/07/07 01:49:30 mkrufky Exp $ 2 * $Id: saa7134-i2c.c,v 1.22 2005/07/22 04:09:41 mkrufky Exp $
3 * 3 *
4 * device driver for philips saa7134 based TV cards 4 * device driver for philips saa7134 based TV cards
5 * i2c interface support 5 * i2c interface support
@@ -300,6 +300,8 @@ static int saa7134_i2c_xfer(struct i2c_adapter *i2c_adap,
300 status = i2c_get_status(dev); 300 status = i2c_get_status(dev);
301 if (i2c_is_error(status)) 301 if (i2c_is_error(status))
302 goto err; 302 goto err;
303 /* ensure that the bus is idle for at least one bit slot */
304 msleep(1);
303 305
304 d1printk("\n"); 306 d1printk("\n");
305 return num; 307 return num;
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index 6836c07794fc..2af0cb2a731b 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: saa7134.h,v 1.48 2005/07/01 08:22:24 nsh Exp $ 2 * $Id: saa7134.h,v 1.49 2005/07/13 17:25:25 mchehab Exp $
3 * 3 *
4 * v4l2 device driver for philips saa7134 based TV cards 4 * v4l2 device driver for philips saa7134 based TV cards
5 * 5 *
@@ -21,7 +21,7 @@
21 */ 21 */
22 22
23#include <linux/version.h> 23#include <linux/version.h>
24#define SAA7134_VERSION_CODE KERNEL_VERSION(0,2,13) 24#define SAA7134_VERSION_CODE KERNEL_VERSION(0,2,14)
25 25
26#include <linux/pci.h> 26#include <linux/pci.h>
27#include <linux/i2c.h> 27#include <linux/i2c.h>
diff --git a/drivers/media/video/tea5767.c b/drivers/media/video/tea5767.c
index 4d27ac1b7fb8..cebcc1fa68d1 100644
--- a/drivers/media/video/tea5767.c
+++ b/drivers/media/video/tea5767.c
@@ -2,7 +2,7 @@
2 * For Philips TEA5767 FM Chip used on some TV Cards like Prolink Pixelview 2 * For Philips TEA5767 FM Chip used on some TV Cards like Prolink Pixelview
3 * I2C address is allways 0xC0. 3 * I2C address is allways 0xC0.
4 * 4 *
5 * $Id: tea5767.c,v 1.21 2005/07/14 03:06:43 mchehab Exp $ 5 * $Id: tea5767.c,v 1.27 2005/07/31 12:10:56 mchehab Exp $
6 * 6 *
7 * Copyright (c) 2005 Mauro Carvalho Chehab (mchehab@brturbo.com.br) 7 * Copyright (c) 2005 Mauro Carvalho Chehab (mchehab@brturbo.com.br)
8 * This code is placed under the terms of the GNU General Public License 8 * This code is placed under the terms of the GNU General Public License
@@ -15,7 +15,6 @@
15#include <linux/videodev.h> 15#include <linux/videodev.h>
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <media/tuner.h> 17#include <media/tuner.h>
18#include <media/tuner.h>
19 18
20#define PREFIX "TEA5767 " 19#define PREFIX "TEA5767 "
21 20
@@ -293,16 +292,16 @@ static int tea5767_stereo(struct i2c_client *c)
293 292
294int tea5767_autodetection(struct i2c_client *c) 293int tea5767_autodetection(struct i2c_client *c)
295{ 294{
296 unsigned char buffer[5] = { 0xff, 0xff, 0xff, 0xff, 0xff }; 295 unsigned char buffer[7] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
297 int rc; 296 int rc;
298 struct tuner *t = i2c_get_clientdata(c); 297 struct tuner *t = i2c_get_clientdata(c);
299 298
300 if (5 != (rc = i2c_master_recv(c, buffer, 5))) { 299 if (7 != (rc = i2c_master_recv(c, buffer, 7))) {
301 tuner_warn("It is not a TEA5767. Received %i bytes.\n", rc); 300 tuner_warn("It is not a TEA5767. Received %i bytes.\n", rc);
302 return EINVAL; 301 return EINVAL;
303 } 302 }
304 303
305 /* If all bytes are the same then it's a TV tuner and not a tea5767 chip. */ 304 /* If all bytes are the same then it's a TV tuner and not a tea5767 */
306 if (buffer[0] == buffer[1] && buffer[0] == buffer[2] && 305 if (buffer[0] == buffer[1] && buffer[0] == buffer[2] &&
307 buffer[0] == buffer[3] && buffer[0] == buffer[4]) { 306 buffer[0] == buffer[3] && buffer[0] == buffer[4]) {
308 tuner_warn("All bytes are equal. It is not a TEA5767\n"); 307 tuner_warn("All bytes are equal. It is not a TEA5767\n");
@@ -318,6 +317,17 @@ int tea5767_autodetection(struct i2c_client *c)
318 tuner_warn("Chip ID is not zero. It is not a TEA5767\n"); 317 tuner_warn("Chip ID is not zero. It is not a TEA5767\n");
319 return EINVAL; 318 return EINVAL;
320 } 319 }
320 /* It seems that tea5767 returns 0xff after the 5th byte */
321 if ((buffer[5] != 0xff) || (buffer[6] != 0xff)) {
322 tuner_warn("Returned more than 5 bytes. It is not a TEA5767\n");
323 return EINVAL;
324 }
325
326 /* It seems that tea5767 returns 0xff after the 5th byte */
327 if ((buffer[5] != 0xff) || (buffer[6] != 0xff)) {
328 tuner_warn("Returned more than 5 bytes. It is not a TEA5767\n");
329 return EINVAL;
330 }
321 331
322 tuner_warn("TEA5767 detected.\n"); 332 tuner_warn("TEA5767 detected.\n");
323 return 0; 333 return 0;
@@ -327,10 +337,8 @@ int tea5767_tuner_init(struct i2c_client *c)
327{ 337{
328 struct tuner *t = i2c_get_clientdata(c); 338 struct tuner *t = i2c_get_clientdata(c);
329 339
330 if (tea5767_autodetection(c) == EINVAL) 340 tuner_info("type set to %d (%s)\n", t->type,
331 return EINVAL; 341 "Philips TEA5767HN FM Radio");
332
333 tuner_info("type set to %d (%s)\n", t->type, "Philips TEA5767HN FM Radio");
334 strlcpy(c->name, "tea5767", sizeof(c->name)); 342 strlcpy(c->name, "tea5767", sizeof(c->name));
335 343
336 t->tv_freq = set_tv_freq; 344 t->tv_freq = set_tv_freq;
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index b25a9c08ac02..f0a579827a24 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: tuner-core.c,v 1.58 2005/07/14 03:06:43 mchehab Exp $ 2 * $Id: tuner-core.c,v 1.63 2005/07/28 18:19:55 mchehab Exp $
3 * 3 *
4 * i2c tv tuner chip device driver 4 * i2c tv tuner chip device driver
5 * core core, i.e. kernel interfaces, registering and so on 5 * core core, i.e. kernel interfaces, registering and so on
@@ -23,6 +23,8 @@
23#include <media/tuner.h> 23#include <media/tuner.h>
24#include <media/audiochip.h> 24#include <media/audiochip.h>
25 25
26#include "msp3400.h"
27
26#define UNSET (-1U) 28#define UNSET (-1U)
27 29
28/* standard i2c insmod options */ 30/* standard i2c insmod options */
@@ -42,6 +44,9 @@ module_param(addr, int, 0444);
42static unsigned int no_autodetect = 0; 44static unsigned int no_autodetect = 0;
43module_param(no_autodetect, int, 0444); 45module_param(no_autodetect, int, 0444);
44 46
47static unsigned int show_i2c = 0;
48module_param(show_i2c, int, 0444);
49
45/* insmod options used at runtime => read/write */ 50/* insmod options used at runtime => read/write */
46unsigned int tuner_debug = 0; 51unsigned int tuner_debug = 0;
47module_param(tuner_debug, int, 0644); 52module_param(tuner_debug, int, 0644);
@@ -320,6 +325,17 @@ static int tuner_attach(struct i2c_adapter *adap, int addr, int kind)
320 325
321 tuner_info("chip found @ 0x%x (%s)\n", addr << 1, adap->name); 326 tuner_info("chip found @ 0x%x (%s)\n", addr << 1, adap->name);
322 327
328 if (show_i2c) {
329 unsigned char buffer[16];
330 int i,rc;
331
332 memset(buffer, 0, sizeof(buffer));
333 rc = i2c_master_recv(&t->i2c, buffer, sizeof(buffer));
334 printk("tuner-%04x I2C RECV = ",addr);
335 for (i=0;i<rc;i++)
336 printk("%02x ",buffer[i]);
337 printk("\n");
338 }
323 /* TEA5767 autodetection code - only for addr = 0xc0 */ 339 /* TEA5767 autodetection code - only for addr = 0xc0 */
324 if (!no_autodetect) { 340 if (!no_autodetect) {
325 if (addr == 0x60) { 341 if (addr == 0x60) {
@@ -451,6 +467,17 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
451 break; 467 break;
452 } 468 }
453 break; 469 break;
470 case VIDIOCSAUDIO:
471 if (check_mode(t, "VIDIOCSAUDIO") == EINVAL)
472 return 0;
473 if (check_v4l2(t) == EINVAL)
474 return 0;
475
476 /* Should be implemented, since bttv calls it */
477 tuner_dbg("VIDIOCSAUDIO not implemented.\n");
478
479 break;
480 case MSP_SET_MATRIX:
454 case TDA9887_SET_CONFIG: 481 case TDA9887_SET_CONFIG:
455 break; 482 break;
456 /* --- v4l ioctls --- */ 483 /* --- v4l ioctls --- */
diff --git a/drivers/media/video/tuner-simple.c b/drivers/media/video/tuner-simple.c
index a3f8e83f5314..de0c93aeb75d 100644
--- a/drivers/media/video/tuner-simple.c
+++ b/drivers/media/video/tuner-simple.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: tuner-simple.c,v 1.39 2005/07/07 01:49:30 mkrufky Exp $ 2 * $Id: tuner-simple.c,v 1.43 2005/07/28 18:41:21 mchehab Exp $
3 * 3 *
4 * i2c tv tuner chip device driver 4 * i2c tv tuner chip device driver
5 * controls all those simple 4-control-bytes style tuners. 5 * controls all those simple 4-control-bytes style tuners.
@@ -245,6 +245,12 @@ static struct tunertype tuners[] = {
245 /* see tea5767.c for details */}, 245 /* see tea5767.c for details */},
246 { "Philips FMD1216ME MK3 Hybrid Tuner", Philips, PAL, 246 { "Philips FMD1216ME MK3 Hybrid Tuner", Philips, PAL,
247 16*160.00,16*442.00,0x51,0x52,0x54,0x86,623 }, 247 16*160.00,16*442.00,0x51,0x52,0x54,0x86,623 },
248
249 { "LG TDVS-H062F/TUA6034", LGINNOTEK, NTSC,
250 16*160.00,16*455.00,0x01,0x02,0x04,0x8e,732},
251
252 { "Ymec TVF66T5-B/DFF", Philips, PAL,
253 16*160.25,16*464.25,0x01,0x02,0x08,0x8e,623},
248}; 254};
249 255
250unsigned const int tuner_count = ARRAY_SIZE(tuners); 256unsigned const int tuner_count = ARRAY_SIZE(tuners);
diff --git a/drivers/media/video/tvaudio.c b/drivers/media/video/tvaudio.c
index d8b78f1d686b..f42a1efa8fcf 100644
--- a/drivers/media/video/tvaudio.c
+++ b/drivers/media/video/tvaudio.c
@@ -285,6 +285,7 @@ static int chip_thread(void *data)
285 schedule(); 285 schedule();
286 } 286 }
287 remove_wait_queue(&chip->wq, &wait); 287 remove_wait_queue(&chip->wq, &wait);
288 try_to_freeze();
288 if (chip->done || signal_pending(current)) 289 if (chip->done || signal_pending(current))
289 break; 290 break;
290 dprintk("%s: thread wakeup\n", i2c_clientname(&chip->c)); 291 dprintk("%s: thread wakeup\n", i2c_clientname(&chip->c));
diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c
index e8d9440977cb..127ec38ebd60 100644
--- a/drivers/media/video/tveeprom.c
+++ b/drivers/media/video/tveeprom.c
@@ -189,7 +189,7 @@ hauppauge_tuner[] =
189 { TUNER_ABSENT, "Philips FQ1236 MK3"}, 189 { TUNER_ABSENT, "Philips FQ1236 MK3"},
190 { TUNER_ABSENT, "Samsung TCPN 2121P30A"}, 190 { TUNER_ABSENT, "Samsung TCPN 2121P30A"},
191 { TUNER_ABSENT, "Samsung TCPE 4121P30A"}, 191 { TUNER_ABSENT, "Samsung TCPE 4121P30A"},
192 { TUNER_ABSENT, "TCL MFPE05 2"}, 192 { TUNER_PHILIPS_FM1216ME_MK3, "TCL MFPE05 2"},
193 /* 90-99 */ 193 /* 90-99 */
194 { TUNER_ABSENT, "LG TALN H202T"}, 194 { TUNER_ABSENT, "LG TALN H202T"},
195 { TUNER_PHILIPS_FQ1216AME_MK4, "Philips FQ1216AME MK4"}, 195 { TUNER_PHILIPS_FQ1216AME_MK4, "Philips FQ1216AME MK4"},
@@ -445,6 +445,7 @@ int tveeprom_read(struct i2c_client *c, unsigned char *eedata, int len)
445} 445}
446EXPORT_SYMBOL(tveeprom_read); 446EXPORT_SYMBOL(tveeprom_read);
447 447
448#if 0
448int tveeprom_dump(unsigned char *eedata, int len) 449int tveeprom_dump(unsigned char *eedata, int len)
449{ 450{
450 int i; 451 int i;
@@ -460,6 +461,7 @@ int tveeprom_dump(unsigned char *eedata, int len)
460 return 0; 461 return 0;
461} 462}
462EXPORT_SYMBOL(tveeprom_dump); 463EXPORT_SYMBOL(tveeprom_dump);
464#endif /* 0 */
463 465
464/* ----------------------------------------------------------------------- */ 466/* ----------------------------------------------------------------------- */
465/* needed for ivtv.sf.net at the moment. Should go away in the long */ 467/* needed for ivtv.sf.net at the moment. Should go away in the long */
@@ -477,7 +479,7 @@ static unsigned short normal_i2c[] = {
477 479
478I2C_CLIENT_INSMOD; 480I2C_CLIENT_INSMOD;
479 481
480struct i2c_driver i2c_driver_tveeprom; 482static struct i2c_driver i2c_driver_tveeprom;
481 483
482static int 484static int
483tveeprom_command(struct i2c_client *client, 485tveeprom_command(struct i2c_client *client,
@@ -549,7 +551,7 @@ tveeprom_detach_client (struct i2c_client *client)
549 return 0; 551 return 0;
550} 552}
551 553
552struct i2c_driver i2c_driver_tveeprom = { 554static struct i2c_driver i2c_driver_tveeprom = {
553 .owner = THIS_MODULE, 555 .owner = THIS_MODULE,
554 .name = "tveeprom", 556 .name = "tveeprom",
555 .id = I2C_DRIVERID_TVEEPROM, 557 .id = I2C_DRIVERID_TVEEPROM,
diff --git a/drivers/mmc/wbsd.c b/drivers/mmc/wbsd.c
index 0c41d4b41a65..8b487ed1069c 100644
--- a/drivers/mmc/wbsd.c
+++ b/drivers/mmc/wbsd.c
@@ -1053,7 +1053,7 @@ static void wbsd_detect_card(unsigned long data)
1053 * Tasklets 1053 * Tasklets
1054 */ 1054 */
1055 1055
1056inline static struct mmc_data* wbsd_get_data(struct wbsd_host* host) 1056static inline struct mmc_data* wbsd_get_data(struct wbsd_host* host)
1057{ 1057{
1058 WARN_ON(!host->mrq); 1058 WARN_ON(!host->mrq);
1059 if (!host->mrq) 1059 if (!host->mrq)
diff --git a/drivers/mtd/devices/docecc.c b/drivers/mtd/devices/docecc.c
index 933877ff4d88..9a087c1fb0b7 100644
--- a/drivers/mtd/devices/docecc.c
+++ b/drivers/mtd/devices/docecc.c
@@ -40,6 +40,7 @@
40#include <linux/mtd/mtd.h> 40#include <linux/mtd/mtd.h>
41#include <linux/mtd/doc2000.h> 41#include <linux/mtd/doc2000.h>
42 42
43#define DEBUG 0
43/* need to undef it (from asm/termbits.h) */ 44/* need to undef it (from asm/termbits.h) */
44#undef B0 45#undef B0
45 46
diff --git a/drivers/net/3c505.c b/drivers/net/3c505.c
index ad17f17e8e7a..111601ca4ca3 100644
--- a/drivers/net/3c505.c
+++ b/drivers/net/3c505.c
@@ -272,7 +272,7 @@ static inline void set_hsf(struct net_device *dev, int hsf)
272 272
273static int start_receive(struct net_device *, pcb_struct *); 273static int start_receive(struct net_device *, pcb_struct *);
274 274
275inline static void adapter_reset(struct net_device *dev) 275static inline void adapter_reset(struct net_device *dev)
276{ 276{
277 unsigned long timeout; 277 unsigned long timeout;
278 elp_device *adapter = dev->priv; 278 elp_device *adapter = dev->priv;
diff --git a/drivers/net/8139too.c b/drivers/net/8139too.c
index 5a4a08a7c951..4c2cf7bbd252 100644
--- a/drivers/net/8139too.c
+++ b/drivers/net/8139too.c
@@ -126,14 +126,14 @@
126#define USE_IO_OPS 1 126#define USE_IO_OPS 1
127#endif 127#endif
128 128
129/* define to 1 to enable copious debugging info */ 129/* define to 1, 2 or 3 to enable copious debugging info */
130#undef RTL8139_DEBUG 130#define RTL8139_DEBUG 0
131 131
132/* define to 1 to disable lightweight runtime debugging checks */ 132/* define to 1 to disable lightweight runtime debugging checks */
133#undef RTL8139_NDEBUG 133#undef RTL8139_NDEBUG
134 134
135 135
136#ifdef RTL8139_DEBUG 136#if RTL8139_DEBUG
137/* note: prints function name for you */ 137/* note: prints function name for you */
138# define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args) 138# define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
139#else 139#else
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 534b598866b3..8a835eb58808 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -23,9 +23,12 @@ config NETDEVICES
23 23
24 If unsure, say Y. 24 If unsure, say Y.
25 25
26# All the following symbols are dependent on NETDEVICES - do not repeat
27# that for each of the symbols.
28if NETDEVICES
29
26config DUMMY 30config DUMMY
27 tristate "Dummy net driver support" 31 tristate "Dummy net driver support"
28 depends on NETDEVICES
29 ---help--- 32 ---help---
30 This is essentially a bit-bucket device (i.e. traffic you send to 33 This is essentially a bit-bucket device (i.e. traffic you send to
31 this device is consigned into oblivion) with a configurable IP 34 this device is consigned into oblivion) with a configurable IP
@@ -45,7 +48,6 @@ config DUMMY
45 48
46config BONDING 49config BONDING
47 tristate "Bonding driver support" 50 tristate "Bonding driver support"
48 depends on NETDEVICES
49 depends on INET 51 depends on INET
50 ---help--- 52 ---help---
51 Say 'Y' or 'M' if you wish to be able to 'bond' multiple Ethernet 53 Say 'Y' or 'M' if you wish to be able to 'bond' multiple Ethernet
@@ -63,7 +65,6 @@ config BONDING
63 65
64config EQUALIZER 66config EQUALIZER
65 tristate "EQL (serial line load balancing) support" 67 tristate "EQL (serial line load balancing) support"
66 depends on NETDEVICES
67 ---help--- 68 ---help---
68 If you have two serial connections to some other computer (this 69 If you have two serial connections to some other computer (this
69 usually requires two modems and two telephone lines) and you use 70 usually requires two modems and two telephone lines) and you use
@@ -83,7 +84,6 @@ config EQUALIZER
83 84
84config TUN 85config TUN
85 tristate "Universal TUN/TAP device driver support" 86 tristate "Universal TUN/TAP device driver support"
86 depends on NETDEVICES
87 select CRC32 87 select CRC32
88 ---help--- 88 ---help---
89 TUN/TAP provides packet reception and transmission for user space 89 TUN/TAP provides packet reception and transmission for user space
@@ -107,7 +107,7 @@ config TUN
107 107
108config NET_SB1000 108config NET_SB1000
109 tristate "General Instruments Surfboard 1000" 109 tristate "General Instruments Surfboard 1000"
110 depends on NETDEVICES && PNP 110 depends on PNP
111 ---help--- 111 ---help---
112 This is a driver for the General Instrument (also known as 112 This is a driver for the General Instrument (also known as
113 NextLevel) SURFboard 1000 internal 113 NextLevel) SURFboard 1000 internal
@@ -129,16 +129,14 @@ config NET_SB1000
129 129
130 If you don't have this card, of course say N. 130 If you don't have this card, of course say N.
131 131
132if NETDEVICES
133 source "drivers/net/arcnet/Kconfig" 132 source "drivers/net/arcnet/Kconfig"
134endif
135 133
136# 134#
137# Ethernet 135# Ethernet
138# 136#
139 137
140menu "Ethernet (10 or 100Mbit)" 138menu "Ethernet (10 or 100Mbit)"
141 depends on NETDEVICES && !UML 139 depends on !UML
142 140
143config NET_ETHERNET 141config NET_ETHERNET
144 bool "Ethernet (10 or 100Mbit)" 142 bool "Ethernet (10 or 100Mbit)"
@@ -1137,7 +1135,7 @@ config IBMLANA
1137 1135
1138config IBMVETH 1136config IBMVETH
1139 tristate "IBM LAN Virtual Ethernet support" 1137 tristate "IBM LAN Virtual Ethernet support"
1140 depends on NETDEVICES && NET_ETHERNET && PPC_PSERIES 1138 depends on NET_ETHERNET && PPC_PSERIES
1141 ---help--- 1139 ---help---
1142 This driver supports virtual ethernet adapters on newer IBM iSeries 1140 This driver supports virtual ethernet adapters on newer IBM iSeries
1143 and pSeries systems. 1141 and pSeries systems.
@@ -1760,7 +1758,7 @@ endmenu
1760# 1758#
1761 1759
1762menu "Ethernet (1000 Mbit)" 1760menu "Ethernet (1000 Mbit)"
1763 depends on NETDEVICES && !UML 1761 depends on !UML
1764 1762
1765config ACENIC 1763config ACENIC
1766 tristate "Alteon AceNIC/3Com 3C985/NetGear GA620 Gigabit support" 1764 tristate "Alteon AceNIC/3Com 3C985/NetGear GA620 Gigabit support"
@@ -2091,7 +2089,7 @@ endmenu
2091# 2089#
2092 2090
2093menu "Ethernet (10000 Mbit)" 2091menu "Ethernet (10000 Mbit)"
2094 depends on NETDEVICES && !UML 2092 depends on !UML
2095 2093
2096config IXGB 2094config IXGB
2097 tristate "Intel(R) PRO/10GbE support" 2095 tristate "Intel(R) PRO/10GbE support"
@@ -2186,11 +2184,11 @@ source "drivers/s390/net/Kconfig"
2186 2184
2187config ISERIES_VETH 2185config ISERIES_VETH
2188 tristate "iSeries Virtual Ethernet driver support" 2186 tristate "iSeries Virtual Ethernet driver support"
2189 depends on NETDEVICES && PPC_ISERIES 2187 depends on PPC_ISERIES
2190 2188
2191config FDDI 2189config FDDI
2192 bool "FDDI driver support" 2190 bool "FDDI driver support"
2193 depends on NETDEVICES && (PCI || EISA) 2191 depends on (PCI || EISA)
2194 help 2192 help
2195 Fiber Distributed Data Interface is a high speed local area network 2193 Fiber Distributed Data Interface is a high speed local area network
2196 design; essentially a replacement for high speed Ethernet. FDDI can 2194 design; essentially a replacement for high speed Ethernet. FDDI can
@@ -2239,7 +2237,7 @@ config SKFP
2239 2237
2240config HIPPI 2238config HIPPI
2241 bool "HIPPI driver support (EXPERIMENTAL)" 2239 bool "HIPPI driver support (EXPERIMENTAL)"
2242 depends on NETDEVICES && EXPERIMENTAL && INET && PCI 2240 depends on EXPERIMENTAL && INET && PCI
2243 help 2241 help
2244 HIgh Performance Parallel Interface (HIPPI) is a 800Mbit/sec and 2242 HIgh Performance Parallel Interface (HIPPI) is a 800Mbit/sec and
2245 1600Mbit/sec dual-simplex switched or point-to-point network. HIPPI 2243 1600Mbit/sec dual-simplex switched or point-to-point network. HIPPI
@@ -2271,7 +2269,7 @@ config ROADRUNNER_LARGE_RINGS
2271 2269
2272config PLIP 2270config PLIP
2273 tristate "PLIP (parallel port) support" 2271 tristate "PLIP (parallel port) support"
2274 depends on NETDEVICES && PARPORT 2272 depends on PARPORT
2275 ---help--- 2273 ---help---
2276 PLIP (Parallel Line Internet Protocol) is used to create a 2274 PLIP (Parallel Line Internet Protocol) is used to create a
2277 reasonably fast mini network consisting of two (or, rarely, more) 2275 reasonably fast mini network consisting of two (or, rarely, more)
@@ -2307,7 +2305,6 @@ config PLIP
2307 2305
2308config PPP 2306config PPP
2309 tristate "PPP (point-to-point protocol) support" 2307 tristate "PPP (point-to-point protocol) support"
2310 depends on NETDEVICES
2311 ---help--- 2308 ---help---
2312 PPP (Point to Point Protocol) is a newer and better SLIP. It serves 2309 PPP (Point to Point Protocol) is a newer and better SLIP. It serves
2313 the same purpose: sending Internet traffic over telephone (and other 2310 the same purpose: sending Internet traffic over telephone (and other
@@ -2443,7 +2440,6 @@ config PPPOATM
2443 2440
2444config SLIP 2441config SLIP
2445 tristate "SLIP (serial line) support" 2442 tristate "SLIP (serial line) support"
2446 depends on NETDEVICES
2447 ---help--- 2443 ---help---
2448 Say Y if you intend to use SLIP or CSLIP (compressed SLIP) to 2444 Say Y if you intend to use SLIP or CSLIP (compressed SLIP) to
2449 connect to your Internet service provider or to connect to some 2445 connect to your Internet service provider or to connect to some
@@ -2510,7 +2506,7 @@ config SLIP_MODE_SLIP6
2510 2506
2511config NET_FC 2507config NET_FC
2512 bool "Fibre Channel driver support" 2508 bool "Fibre Channel driver support"
2513 depends on NETDEVICES && SCSI && PCI 2509 depends on SCSI && PCI
2514 help 2510 help
2515 Fibre Channel is a high speed serial protocol mainly used to connect 2511 Fibre Channel is a high speed serial protocol mainly used to connect
2516 large storage devices to the computer; it is compatible with and 2512 large storage devices to the computer; it is compatible with and
@@ -2523,7 +2519,7 @@ config NET_FC
2523 2519
2524config SHAPER 2520config SHAPER
2525 tristate "Traffic Shaper (EXPERIMENTAL)" 2521 tristate "Traffic Shaper (EXPERIMENTAL)"
2526 depends on NETDEVICES && EXPERIMENTAL 2522 depends on EXPERIMENTAL
2527 ---help--- 2523 ---help---
2528 The traffic shaper is a virtual network device that allows you to 2524 The traffic shaper is a virtual network device that allows you to
2529 limit the rate of outgoing data flow over some other network device. 2525 limit the rate of outgoing data flow over some other network device.
@@ -2544,11 +2540,13 @@ config SHAPER
2544 2540
2545config NETCONSOLE 2541config NETCONSOLE
2546 tristate "Network console logging support (EXPERIMENTAL)" 2542 tristate "Network console logging support (EXPERIMENTAL)"
2547 depends on NETDEVICES && INET && EXPERIMENTAL 2543 depends on EXPERIMENTAL
2548 ---help--- 2544 ---help---
2549 If you want to log kernel messages over the network, enable this. 2545 If you want to log kernel messages over the network, enable this.
2550 See <file:Documentation/networking/netconsole.txt> for details. 2546 See <file:Documentation/networking/netconsole.txt> for details.
2551 2547
2548endif #NETDEVICES
2549
2552config NETPOLL 2550config NETPOLL
2553 def_bool NETCONSOLE 2551 def_bool NETCONSOLE
2554 2552
diff --git a/drivers/net/amd8111e.c b/drivers/net/amd8111e.c
index 8618012df06a..d9ba8be72af8 100755
--- a/drivers/net/amd8111e.c
+++ b/drivers/net/amd8111e.c
@@ -1290,7 +1290,7 @@ static irqreturn_t amd8111e_interrupt(int irq, void *dev_id, struct pt_regs *reg
1290 writel(intr0, mmio + INT0); 1290 writel(intr0, mmio + INT0);
1291 1291
1292 /* Check if Receive Interrupt has occurred. */ 1292 /* Check if Receive Interrupt has occurred. */
1293#if CONFIG_AMD8111E_NAPI 1293#ifdef CONFIG_AMD8111E_NAPI
1294 if(intr0 & RINT0){ 1294 if(intr0 & RINT0){
1295 if(netif_rx_schedule_prep(dev)){ 1295 if(netif_rx_schedule_prep(dev)){
1296 /* Disable receive interupts */ 1296 /* Disable receive interupts */
diff --git a/drivers/net/cs89x0.c b/drivers/net/cs89x0.c
index b96d6fb1929e..b780307093eb 100644
--- a/drivers/net/cs89x0.c
+++ b/drivers/net/cs89x0.c
@@ -417,6 +417,7 @@ cs89x0_probe1(struct net_device *dev, int ioaddr, int modular)
417 struct net_local *lp = netdev_priv(dev); 417 struct net_local *lp = netdev_priv(dev);
418 static unsigned version_printed; 418 static unsigned version_printed;
419 int i; 419 int i;
420 int tmp;
420 unsigned rev_type = 0; 421 unsigned rev_type = 0;
421 int eeprom_buff[CHKSUM_LEN]; 422 int eeprom_buff[CHKSUM_LEN];
422 int retval; 423 int retval;
@@ -492,14 +493,17 @@ cs89x0_probe1(struct net_device *dev, int ioaddr, int modular)
492 goto out2; 493 goto out2;
493 } 494 }
494 } 495 }
495printk("PP_addr=0x%x\n", inw(ioaddr + ADD_PORT)); 496 printk(KERN_DEBUG "PP_addr at %x: 0x%x\n",
497 ioaddr + ADD_PORT, inw(ioaddr + ADD_PORT));
496 498
497 ioaddr &= ~3; 499 ioaddr &= ~3;
498 outw(PP_ChipID, ioaddr + ADD_PORT); 500 outw(PP_ChipID, ioaddr + ADD_PORT);
499 501
500 if (inw(ioaddr + DATA_PORT) != CHIP_EISA_ID_SIG) { 502 tmp = inw(ioaddr + DATA_PORT);
501 printk(KERN_ERR "%s: incorrect signature 0x%x\n", 503 if (tmp != CHIP_EISA_ID_SIG) {
502 dev->name, inw(ioaddr + DATA_PORT)); 504 printk(KERN_DEBUG "%s: incorrect signature at %x: 0x%x!="
505 CHIP_EISA_ID_SIG_STR "\n",
506 dev->name, ioaddr + DATA_PORT, tmp);
503 retval = -ENODEV; 507 retval = -ENODEV;
504 goto out2; 508 goto out2;
505 } 509 }
@@ -1450,6 +1454,7 @@ static int net_send_packet(struct sk_buff *skb, struct net_device *dev)
1450 /* Write the contents of the packet */ 1454 /* Write the contents of the packet */
1451 outsw(dev->base_addr + TX_FRAME_PORT,skb->data,(skb->len+1) >>1); 1455 outsw(dev->base_addr + TX_FRAME_PORT,skb->data,(skb->len+1) >>1);
1452 spin_unlock_irq(&lp->lock); 1456 spin_unlock_irq(&lp->lock);
1457 lp->stats.tx_bytes += skb->len;
1453 dev->trans_start = jiffies; 1458 dev->trans_start = jiffies;
1454 dev_kfree_skb (skb); 1459 dev_kfree_skb (skb);
1455 1460
diff --git a/drivers/net/cs89x0.h b/drivers/net/cs89x0.h
index bd3ad8e6cce9..decea264f121 100644
--- a/drivers/net/cs89x0.h
+++ b/drivers/net/cs89x0.h
@@ -93,6 +93,7 @@
93#endif 93#endif
94 94
95#define CHIP_EISA_ID_SIG 0x630E /* Product ID Code for Crystal Chip (CS8900 spec 4.3) */ 95#define CHIP_EISA_ID_SIG 0x630E /* Product ID Code for Crystal Chip (CS8900 spec 4.3) */
96#define CHIP_EISA_ID_SIG_STR "0x630E"
96 97
97#ifdef IBMEIPKT 98#ifdef IBMEIPKT
98#define EISA_ID_SIG 0x4D24 /* IBM */ 99#define EISA_ID_SIG 0x4D24 /* IBM */
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index cb7f051a60ad..5e5d2c3c7ce4 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -162,7 +162,6 @@ static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
162static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid); 162static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
163static void e1000_restore_vlan(struct e1000_adapter *adapter); 163static void e1000_restore_vlan(struct e1000_adapter *adapter);
164 164
165static int e1000_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);
166static int e1000_suspend(struct pci_dev *pdev, uint32_t state); 165static int e1000_suspend(struct pci_dev *pdev, uint32_t state);
167#ifdef CONFIG_PM 166#ifdef CONFIG_PM
168static int e1000_resume(struct pci_dev *pdev); 167static int e1000_resume(struct pci_dev *pdev);
@@ -173,12 +172,6 @@ static int e1000_resume(struct pci_dev *pdev);
173static void e1000_netpoll (struct net_device *netdev); 172static void e1000_netpoll (struct net_device *netdev);
174#endif 173#endif
175 174
176struct notifier_block e1000_notifier_reboot = {
177 .notifier_call = e1000_notify_reboot,
178 .next = NULL,
179 .priority = 0
180};
181
182/* Exported from other modules */ 175/* Exported from other modules */
183 176
184extern void e1000_check_options(struct e1000_adapter *adapter); 177extern void e1000_check_options(struct e1000_adapter *adapter);
@@ -221,9 +214,7 @@ e1000_init_module(void)
221 printk(KERN_INFO "%s\n", e1000_copyright); 214 printk(KERN_INFO "%s\n", e1000_copyright);
222 215
223 ret = pci_module_init(&e1000_driver); 216 ret = pci_module_init(&e1000_driver);
224 if(ret >= 0) { 217
225 register_reboot_notifier(&e1000_notifier_reboot);
226 }
227 return ret; 218 return ret;
228} 219}
229 220
@@ -239,7 +230,6 @@ module_init(e1000_init_module);
239static void __exit 230static void __exit
240e1000_exit_module(void) 231e1000_exit_module(void)
241{ 232{
242 unregister_reboot_notifier(&e1000_notifier_reboot);
243 pci_unregister_driver(&e1000_driver); 233 pci_unregister_driver(&e1000_driver);
244} 234}
245 235
@@ -3652,23 +3642,6 @@ e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
3652} 3642}
3653 3643
3654static int 3644static int
3655e1000_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
3656{
3657 struct pci_dev *pdev = NULL;
3658
3659 switch(event) {
3660 case SYS_DOWN:
3661 case SYS_HALT:
3662 case SYS_POWER_OFF:
3663 while((pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pdev))) {
3664 if(pci_dev_driver(pdev) == &e1000_driver)
3665 e1000_suspend(pdev, 3);
3666 }
3667 }
3668 return NOTIFY_DONE;
3669}
3670
3671static int
3672e1000_suspend(struct pci_dev *pdev, uint32_t state) 3645e1000_suspend(struct pci_dev *pdev, uint32_t state)
3673{ 3646{
3674 struct net_device *netdev = pci_get_drvdata(pdev); 3647 struct net_device *netdev = pci_get_drvdata(pdev);
diff --git a/drivers/net/hamradio/Kconfig b/drivers/net/hamradio/Kconfig
index 7cdebe1a0b61..0cd54306e636 100644
--- a/drivers/net/hamradio/Kconfig
+++ b/drivers/net/hamradio/Kconfig
@@ -17,7 +17,7 @@ config MKISS
17 17
18config 6PACK 18config 6PACK
19 tristate "Serial port 6PACK driver" 19 tristate "Serial port 6PACK driver"
20 depends on AX25 && BROKEN_ON_SMP 20 depends on AX25
21 ---help--- 21 ---help---
22 6pack is a transmission protocol for the data exchange between your 22 6pack is a transmission protocol for the data exchange between your
23 PC and your TNC (the Terminal Node Controller acts as a kind of 23 PC and your TNC (the Terminal Node Controller acts as a kind of
diff --git a/drivers/net/ne.c b/drivers/net/ne.c
index 6c57096aa2e1..d209a1556b2e 100644
--- a/drivers/net/ne.c
+++ b/drivers/net/ne.c
@@ -129,9 +129,9 @@ bad_clone_list[] __initdata = {
129#define NESM_START_PG 0x40 /* First page of TX buffer */ 129#define NESM_START_PG 0x40 /* First page of TX buffer */
130#define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */ 130#define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */
131 131
132#ifdef CONFIG_PLAT_MAPPI 132#if defined(CONFIG_PLAT_MAPPI)
133# define DCR_VAL 0x4b 133# define DCR_VAL 0x4b
134#elif CONFIG_PLAT_OAKS32R 134#elif defined(CONFIG_PLAT_OAKS32R)
135# define DCR_VAL 0x48 135# define DCR_VAL 0x48
136#else 136#else
137# define DCR_VAL 0x49 137# define DCR_VAL 0x49
diff --git a/drivers/net/pcmcia/nmclan_cs.c b/drivers/net/pcmcia/nmclan_cs.c
index dbb941004ae9..980d7e5d66cb 100644
--- a/drivers/net/pcmcia/nmclan_cs.c
+++ b/drivers/net/pcmcia/nmclan_cs.c
@@ -1671,7 +1671,7 @@ static void set_multicast_list(struct net_device *dev)
1671 1671
1672static struct pcmcia_device_id nmclan_ids[] = { 1672static struct pcmcia_device_id nmclan_ids[] = {
1673 PCMCIA_DEVICE_PROD_ID12("New Media Corporation", "Ethernet", 0x085a850b, 0x00b2e941), 1673 PCMCIA_DEVICE_PROD_ID12("New Media Corporation", "Ethernet", 0x085a850b, 0x00b2e941),
1674 PCMCIA_DEVICE_PROD_ID12("Portable Add-ons", "Ethernet", 0x0ebf1d60, 0x00b2e941), 1674 PCMCIA_DEVICE_PROD_ID12("Portable Add-ons", "Ethernet+", 0xebf1d60, 0xad673aaf),
1675 PCMCIA_DEVICE_NULL, 1675 PCMCIA_DEVICE_NULL,
1676}; 1676};
1677MODULE_DEVICE_TABLE(pcmcia, nmclan_ids); 1677MODULE_DEVICE_TABLE(pcmcia, nmclan_ids);
diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c
index e1664aef3dfd..9f22d138e3ad 100644
--- a/drivers/net/pcmcia/pcnet_cs.c
+++ b/drivers/net/pcmcia/pcnet_cs.c
@@ -1639,7 +1639,7 @@ static struct pcmcia_device_id pcnet_ids[] = {
1639 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0143, 0xc0ab), 1639 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0143, 0xc0ab),
1640 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x021b, 0x0101), 1640 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x021b, 0x0101),
1641 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x08a1, 0xc0ab), 1641 PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x08a1, 0xc0ab),
1642 PCMCIA_PFC_DEVICE_PROD_ID12(0, "AnyCom", "Fast Ethernet ", 0x578ba6e7, 0x02d92d1e), 1642 PCMCIA_PFC_DEVICE_PROD_ID12(0, "AnyCom", "Fast Ethernet + 56K COMBO", 0x578ba6e7, 0xb0ac62c4),
1643 PCMCIA_PFC_DEVICE_PROD_ID12(0, "D-Link", "DME336T", 0x1a424a1c, 0xb23897ff), 1643 PCMCIA_PFC_DEVICE_PROD_ID12(0, "D-Link", "DME336T", 0x1a424a1c, 0xb23897ff),
1644 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Grey Cell", "GCS3000", 0x2a151fac, 0x48b932ae), 1644 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Grey Cell", "GCS3000", 0x2a151fac, 0x48b932ae),
1645 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Linksys", "EtherFast 10&100 + 56K PC Card (PCMLM56)", 0x0733cc81, 0xb3765033), 1645 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Linksys", "EtherFast 10&100 + 56K PC Card (PCMLM56)", 0x0733cc81, 0xb3765033),
@@ -1683,7 +1683,6 @@ static struct pcmcia_device_id pcnet_ids[] = {
1683 PCMCIA_DEVICE_PROD_ID12("ACCTON", "EN2212", 0xdfc6b5b2, 0xcb112a11), 1683 PCMCIA_DEVICE_PROD_ID12("ACCTON", "EN2212", 0xdfc6b5b2, 0xcb112a11),
1684 PCMCIA_DEVICE_PROD_ID12("ACCTON", "EN2216-PCMCIA-ETHERNET", 0xdfc6b5b2, 0x5542bfff), 1684 PCMCIA_DEVICE_PROD_ID12("ACCTON", "EN2216-PCMCIA-ETHERNET", 0xdfc6b5b2, 0x5542bfff),
1685 PCMCIA_DEVICE_PROD_ID12("Allied Telesis, K.K.", "CentreCOM LA100-PCM-T V2 100/10M LAN PC Card", 0xbb7fbdd7, 0xcd91cc68), 1685 PCMCIA_DEVICE_PROD_ID12("Allied Telesis, K.K.", "CentreCOM LA100-PCM-T V2 100/10M LAN PC Card", 0xbb7fbdd7, 0xcd91cc68),
1686 PCMCIA_DEVICE_PROD_ID12("Allied Telesis, K.K.", "CentreCOM LA-PCM", 0xbb7fbdd7, 0x5ba10d49),
1687 PCMCIA_DEVICE_PROD_ID12("Allied Telesis K.K.", "LA100-PCM V2", 0x36634a66, 0xc6d05997), 1686 PCMCIA_DEVICE_PROD_ID12("Allied Telesis K.K.", "LA100-PCM V2", 0x36634a66, 0xc6d05997),
1688 PCMCIA_DEVICE_PROD_ID12("Allied Telesis, K.K.", "CentreCOM LA-PCM_V2", 0xbb7fBdd7, 0x28e299f8), 1687 PCMCIA_DEVICE_PROD_ID12("Allied Telesis, K.K.", "CentreCOM LA-PCM_V2", 0xbb7fBdd7, 0x28e299f8),
1689 PCMCIA_DEVICE_PROD_ID12("Allied Telesis K.K.", "LA-PCM V3", 0x36634a66, 0x62241d96), 1688 PCMCIA_DEVICE_PROD_ID12("Allied Telesis K.K.", "LA-PCM V3", 0x36634a66, 0x62241d96),
@@ -1719,6 +1718,7 @@ static struct pcmcia_device_id pcnet_ids[] = {
1719 PCMCIA_DEVICE_PROD_ID12("DIGITAL", "DEPCM-XX", 0x69616cb3, 0xe600e76e), 1718 PCMCIA_DEVICE_PROD_ID12("DIGITAL", "DEPCM-XX", 0x69616cb3, 0xe600e76e),
1720 PCMCIA_DEVICE_PROD_ID12("D-Link", "DE-650", 0x1a424a1c, 0xf28c8398), 1719 PCMCIA_DEVICE_PROD_ID12("D-Link", "DE-650", 0x1a424a1c, 0xf28c8398),
1721 PCMCIA_DEVICE_PROD_ID12("D-Link", "DE-660", 0x1a424a1c, 0xd9a1d05b), 1720 PCMCIA_DEVICE_PROD_ID12("D-Link", "DE-660", 0x1a424a1c, 0xd9a1d05b),
1721 PCMCIA_DEVICE_PROD_ID12("D-Link", "DE-660+", 0x1a424a1c, 0x50dcd0ec),
1722 PCMCIA_DEVICE_PROD_ID12("D-Link", "DFE-650", 0x1a424a1c, 0x0f0073f9), 1722 PCMCIA_DEVICE_PROD_ID12("D-Link", "DFE-650", 0x1a424a1c, 0x0f0073f9),
1723 PCMCIA_DEVICE_PROD_ID12("Dual Speed", "10/100 PC Card", 0x725b842d, 0xf1efee84), 1723 PCMCIA_DEVICE_PROD_ID12("Dual Speed", "10/100 PC Card", 0x725b842d, 0xf1efee84),
1724 PCMCIA_DEVICE_PROD_ID12("Dual Speed", "10/100 Port Attached PC Card", 0x725b842d, 0x2db1f8e9), 1724 PCMCIA_DEVICE_PROD_ID12("Dual Speed", "10/100 Port Attached PC Card", 0x725b842d, 0x2db1f8e9),
@@ -1737,6 +1737,7 @@ static struct pcmcia_device_id pcnet_ids[] = {
1737 PCMCIA_DEVICE_PROD_ID12("GVC", "NIC-2000p", 0x76e171bd, 0x6eb1c947), 1737 PCMCIA_DEVICE_PROD_ID12("GVC", "NIC-2000p", 0x76e171bd, 0x6eb1c947),
1738 PCMCIA_DEVICE_PROD_ID12("IBM Corp.", "Ethernet", 0xe3736c88, 0x00b2e941), 1738 PCMCIA_DEVICE_PROD_ID12("IBM Corp.", "Ethernet", 0xe3736c88, 0x00b2e941),
1739 PCMCIA_DEVICE_PROD_ID12("IC-CARD", "IC-CARD", 0x60cb09a6, 0x60cb09a6), 1739 PCMCIA_DEVICE_PROD_ID12("IC-CARD", "IC-CARD", 0x60cb09a6, 0x60cb09a6),
1740 PCMCIA_DEVICE_PROD_ID12("IC-CARD+", "IC-CARD+", 0x93693494, 0x93693494),
1740 PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCETTX", 0x547e66dc, 0x6fc5459b), 1741 PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCETTX", 0x547e66dc, 0x6fc5459b),
1741 PCMCIA_DEVICE_PROD_ID12("iPort", "10/100 Ethernet Card", 0x56c538d2, 0x11b0ffc0), 1742 PCMCIA_DEVICE_PROD_ID12("iPort", "10/100 Ethernet Card", 0x56c538d2, 0x11b0ffc0),
1742 PCMCIA_DEVICE_PROD_ID12("KANSAI ELECTRIC CO.,LTD", "KLA-PCM/T", 0xb18dc3b4, 0xcc51a956), 1743 PCMCIA_DEVICE_PROD_ID12("KANSAI ELECTRIC CO.,LTD", "KLA-PCM/T", 0xb18dc3b4, 0xcc51a956),
@@ -1753,7 +1754,7 @@ static struct pcmcia_device_id pcnet_ids[] = {
1753 PCMCIA_DEVICE_PROD_ID12("Linksys", "EtherFast 10/100 Integrated PC Card (PCM100)", 0x0733cc81, 0x453c3f9d), 1754 PCMCIA_DEVICE_PROD_ID12("Linksys", "EtherFast 10/100 Integrated PC Card (PCM100)", 0x0733cc81, 0x453c3f9d),
1754 PCMCIA_DEVICE_PROD_ID12("Linksys", "EtherFast 10/100 PC Card (PCMPC100)", 0x0733cc81, 0x66c5a389), 1755 PCMCIA_DEVICE_PROD_ID12("Linksys", "EtherFast 10/100 PC Card (PCMPC100)", 0x0733cc81, 0x66c5a389),
1755 PCMCIA_DEVICE_PROD_ID12("Linksys", "EtherFast 10/100 PC Card (PCMPC100 V2)", 0x0733cc81, 0x3a3b28e9), 1756 PCMCIA_DEVICE_PROD_ID12("Linksys", "EtherFast 10/100 PC Card (PCMPC100 V2)", 0x0733cc81, 0x3a3b28e9),
1756 PCMCIA_DEVICE_PROD_ID12("Linksys", "HomeLink Phoneline ", 0x0733cc81, 0x5e07cfa0), 1757 PCMCIA_DEVICE_PROD_ID12("Linksys", "HomeLink Phoneline + 10/100 Network PC Card (PCM100H1)", 0x733cc81, 0x7a3e5c3a),
1757 PCMCIA_DEVICE_PROD_ID12("Logitec", "LPM-LN100TX", 0x88fcdeda, 0x6d772737), 1758 PCMCIA_DEVICE_PROD_ID12("Logitec", "LPM-LN100TX", 0x88fcdeda, 0x6d772737),
1758 PCMCIA_DEVICE_PROD_ID12("Logitec", "LPM-LN20T", 0x88fcdeda, 0x81090922), 1759 PCMCIA_DEVICE_PROD_ID12("Logitec", "LPM-LN20T", 0x88fcdeda, 0x81090922),
1759 PCMCIA_DEVICE_PROD_ID12("LONGSHINE", "PCMCIA Ethernet Card", 0xf866b0b0, 0x6f6652e0), 1760 PCMCIA_DEVICE_PROD_ID12("LONGSHINE", "PCMCIA Ethernet Card", 0xf866b0b0, 0x6f6652e0),
diff --git a/drivers/net/pcmcia/smc91c92_cs.c b/drivers/net/pcmcia/smc91c92_cs.c
index 0d8bb4cccbb7..d652e1eddb45 100644
--- a/drivers/net/pcmcia/smc91c92_cs.c
+++ b/drivers/net/pcmcia/smc91c92_cs.c
@@ -2332,8 +2332,8 @@ static struct pcmcia_device_id smc91c92_ids[] = {
2332 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "XJEM1144/CCEM1144", "PCMCIA MODEM", 0xf510db04, 0x52d21e1e, 0xbd6c43ef), 2332 PCMCIA_PFC_DEVICE_PROD_ID123(0, "MEGAHERTZ", "XJEM1144/CCEM1144", "PCMCIA MODEM", 0xf510db04, 0x52d21e1e, 0xbd6c43ef),
2333 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Gateway 2000", "XJEM3336", 0xdd9989be, 0x662c394c), 2333 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Gateway 2000", "XJEM3336", 0xdd9989be, 0x662c394c),
2334 PCMCIA_PFC_DEVICE_PROD_ID12(0, "MEGAHERTZ", "XJEM1144/CCEM1144", 0xf510db04, 0x52d21e1e), 2334 PCMCIA_PFC_DEVICE_PROD_ID12(0, "MEGAHERTZ", "XJEM1144/CCEM1144", 0xf510db04, 0x52d21e1e),
2335 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f), 2335 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard:Jack of Diamonds Modem+Ethernet", 0xc2f80cd, 0x656947b9),
2336 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f), 2336 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Ositech", "Trumpcard:Jack of Hearts Modem+Ethernet", 0xc2f80cd, 0xdc9ba5ed),
2337 PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x016c, 0x0020), 2337 PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x016c, 0x0020),
2338 PCMCIA_DEVICE_MANF_CARD(0x016c, 0x0023), 2338 PCMCIA_DEVICE_MANF_CARD(0x016c, 0x0023),
2339 PCMCIA_DEVICE_PROD_ID123("BASICS by New Media Corporation", "Ethernet", "SMC91C94", 0x23c78a9d, 0x00b2e941, 0xcef397fb), 2339 PCMCIA_DEVICE_PROD_ID123("BASICS by New Media Corporation", "Ethernet", "SMC91C94", 0x23c78a9d, 0x00b2e941, 0xcef397fb),
@@ -2343,8 +2343,8 @@ static struct pcmcia_device_id smc91c92_ids[] = {
2343 PCMCIA_DEVICE_PROD_ID12("Farallon", "Farallon Enet", 0x58d93fc4, 0x244734e9), 2343 PCMCIA_DEVICE_PROD_ID12("Farallon", "Farallon Enet", 0x58d93fc4, 0x244734e9),
2344 PCMCIA_DEVICE_PROD_ID12("Megahertz", "CC10BT/2", 0x33234748, 0x3c95b953), 2344 PCMCIA_DEVICE_PROD_ID12("Megahertz", "CC10BT/2", 0x33234748, 0x3c95b953),
2345 PCMCIA_DEVICE_PROD_ID12("MELCO/SMC", "LPC-TX", 0xa2cd8e6d, 0x42da662a), 2345 PCMCIA_DEVICE_PROD_ID12("MELCO/SMC", "LPC-TX", 0xa2cd8e6d, 0x42da662a),
2346 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f), 2346 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard:Four of Diamonds Ethernet", 0xc2f80cd, 0xb3466314),
2347 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f), 2347 PCMCIA_DEVICE_PROD_ID12("Ositech", "Trumpcard:Seven of Diamonds Ethernet", 0xc2f80cd, 0x194b650a),
2348 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Fast Ethernet PCCard", 0x281f1c5d, 0xdcea68bc), 2348 PCMCIA_DEVICE_PROD_ID12("PCMCIA", "Fast Ethernet PCCard", 0x281f1c5d, 0xdcea68bc),
2349 PCMCIA_DEVICE_PROD_ID12("Psion", "10Mb Ethernet", 0x4ef00b21, 0x844be9e9), 2349 PCMCIA_DEVICE_PROD_ID12("Psion", "10Mb Ethernet", 0x4ef00b21, 0x844be9e9),
2350 PCMCIA_DEVICE_PROD_ID12("SMC", "EtherEZ Ethernet 8020", 0xc4f8b18b, 0x4a0eeb2d), 2350 PCMCIA_DEVICE_PROD_ID12("SMC", "EtherEZ Ethernet 8020", 0xc4f8b18b, 0x4a0eeb2d),
diff --git a/drivers/net/pcmcia/xirc2ps_cs.c b/drivers/net/pcmcia/xirc2ps_cs.c
index 9f33bad174e9..ce143f08638a 100644
--- a/drivers/net/pcmcia/xirc2ps_cs.c
+++ b/drivers/net/pcmcia/xirc2ps_cs.c
@@ -1985,7 +1985,7 @@ static struct pcmcia_device_id xirc2ps_ids[] = {
1985 PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM56", 0x2e3ee845, 0xa650c32a), 1985 PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "CEM56", 0x2e3ee845, 0xa650c32a),
1986 PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "REM10", 0x2e3ee845, 0x76df1d29), 1986 PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "REM10", 0x2e3ee845, 0x76df1d29),
1987 PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "XEM5600", 0x2e3ee845, 0xf1403719), 1987 PCMCIA_PFC_DEVICE_PROD_ID13(0, "Xircom", "XEM5600", 0x2e3ee845, 0xf1403719),
1988 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Xircom", "CreditCard Ethernet", 0x2e3ee845, 0xc0e778c2), 1988 PCMCIA_PFC_DEVICE_PROD_ID12(0, "Xircom", "CreditCard Ethernet+Modem II", 0x2e3ee845, 0xeca401bf),
1989 PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x010a), 1989 PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x010a),
1990 PCMCIA_DEVICE_PROD_ID13("Toshiba Information Systems", "TPCENET", 0x1b3b94fe, 0xf381c1a2), 1990 PCMCIA_DEVICE_PROD_ID13("Toshiba Information Systems", "TPCENET", 0x1b3b94fe, 0xf381c1a2),
1991 PCMCIA_DEVICE_PROD_ID13("Xircom", "CE3-10/100", 0x2e3ee845, 0x0ec0ac37), 1991 PCMCIA_DEVICE_PROD_ID13("Xircom", "CE3-10/100", 0x2e3ee845, 0x0ec0ac37),
diff --git a/drivers/net/plip.c b/drivers/net/plip.c
index 21537ee3a6a7..1bd22cd40c75 100644
--- a/drivers/net/plip.c
+++ b/drivers/net/plip.c
@@ -160,7 +160,7 @@ static struct net_device_stats *plip_get_stats(struct net_device *dev);
160static int plip_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd); 160static int plip_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
161static int plip_preempt(void *handle); 161static int plip_preempt(void *handle);
162static void plip_wakeup(void *handle); 162static void plip_wakeup(void *handle);
163 163
164enum plip_connection_state { 164enum plip_connection_state {
165 PLIP_CN_NONE=0, 165 PLIP_CN_NONE=0,
166 PLIP_CN_RECEIVE, 166 PLIP_CN_RECEIVE,
@@ -231,8 +231,8 @@ struct net_local {
231 atomic_t kill_timer; 231 atomic_t kill_timer;
232 struct semaphore killed_timer_sem; 232 struct semaphore killed_timer_sem;
233}; 233};
234 234
235inline static void enable_parport_interrupts (struct net_device *dev) 235static inline void enable_parport_interrupts (struct net_device *dev)
236{ 236{
237 if (dev->irq != -1) 237 if (dev->irq != -1)
238 { 238 {
@@ -242,7 +242,7 @@ inline static void enable_parport_interrupts (struct net_device *dev)
242 } 242 }
243} 243}
244 244
245inline static void disable_parport_interrupts (struct net_device *dev) 245static inline void disable_parport_interrupts (struct net_device *dev)
246{ 246{
247 if (dev->irq != -1) 247 if (dev->irq != -1)
248 { 248 {
@@ -252,7 +252,7 @@ inline static void disable_parport_interrupts (struct net_device *dev)
252 } 252 }
253} 253}
254 254
255inline static void write_data (struct net_device *dev, unsigned char data) 255static inline void write_data (struct net_device *dev, unsigned char data)
256{ 256{
257 struct parport *port = 257 struct parport *port =
258 ((struct net_local *)dev->priv)->pardev->port; 258 ((struct net_local *)dev->priv)->pardev->port;
@@ -260,14 +260,14 @@ inline static void write_data (struct net_device *dev, unsigned char data)
260 port->ops->write_data (port, data); 260 port->ops->write_data (port, data);
261} 261}
262 262
263inline static unsigned char read_status (struct net_device *dev) 263static inline unsigned char read_status (struct net_device *dev)
264{ 264{
265 struct parport *port = 265 struct parport *port =
266 ((struct net_local *)dev->priv)->pardev->port; 266 ((struct net_local *)dev->priv)->pardev->port;
267 267
268 return port->ops->read_status (port); 268 return port->ops->read_status (port);
269} 269}
270 270
271/* Entry point of PLIP driver. 271/* Entry point of PLIP driver.
272 Probe the hardware, and register/initialize the driver. 272 Probe the hardware, and register/initialize the driver.
273 273
@@ -316,7 +316,7 @@ plip_init_netdev(struct net_device *dev)
316 316
317 spin_lock_init(&nl->lock); 317 spin_lock_init(&nl->lock);
318} 318}
319 319
320/* Bottom half handler for the delayed request. 320/* Bottom half handler for the delayed request.
321 This routine is kicked by do_timer(). 321 This routine is kicked by do_timer().
322 Request `plip_bh' to be invoked. */ 322 Request `plip_bh' to be invoked. */
@@ -471,7 +471,7 @@ plip_bh_timeout_error(struct net_device *dev, struct net_local *nl,
471 471
472 return TIMEOUT; 472 return TIMEOUT;
473} 473}
474 474
475static int 475static int
476plip_none(struct net_device *dev, struct net_local *nl, 476plip_none(struct net_device *dev, struct net_local *nl,
477 struct plip_local *snd, struct plip_local *rcv) 477 struct plip_local *snd, struct plip_local *rcv)
@@ -481,7 +481,7 @@ plip_none(struct net_device *dev, struct net_local *nl,
481 481
482/* PLIP_RECEIVE --- receive a byte(two nibbles) 482/* PLIP_RECEIVE --- receive a byte(two nibbles)
483 Returns OK on success, TIMEOUT on timeout */ 483 Returns OK on success, TIMEOUT on timeout */
484inline static int 484static inline int
485plip_receive(unsigned short nibble_timeout, struct net_device *dev, 485plip_receive(unsigned short nibble_timeout, struct net_device *dev,
486 enum plip_nibble_state *ns_p, unsigned char *data_p) 486 enum plip_nibble_state *ns_p, unsigned char *data_p)
487{ 487{
@@ -582,7 +582,6 @@ static __be16 plip_type_trans(struct sk_buff *skb, struct net_device *dev)
582 return htons(ETH_P_802_2); 582 return htons(ETH_P_802_2);
583} 583}
584 584
585
586/* PLIP_RECEIVE_PACKET --- receive a packet */ 585/* PLIP_RECEIVE_PACKET --- receive a packet */
587static int 586static int
588plip_receive_packet(struct net_device *dev, struct net_local *nl, 587plip_receive_packet(struct net_device *dev, struct net_local *nl,
@@ -702,7 +701,7 @@ plip_receive_packet(struct net_device *dev, struct net_local *nl,
702 701
703/* PLIP_SEND --- send a byte (two nibbles) 702/* PLIP_SEND --- send a byte (two nibbles)
704 Returns OK on success, TIMEOUT when timeout */ 703 Returns OK on success, TIMEOUT when timeout */
705inline static int 704static inline int
706plip_send(unsigned short nibble_timeout, struct net_device *dev, 705plip_send(unsigned short nibble_timeout, struct net_device *dev,
707 enum plip_nibble_state *ns_p, unsigned char data) 706 enum plip_nibble_state *ns_p, unsigned char data)
708{ 707{
@@ -902,7 +901,7 @@ plip_error(struct net_device *dev, struct net_local *nl,
902 901
903 return OK; 902 return OK;
904} 903}
905 904
906/* Handle the parallel port interrupts. */ 905/* Handle the parallel port interrupts. */
907static void 906static void
908plip_interrupt(int irq, void *dev_id, struct pt_regs * regs) 907plip_interrupt(int irq, void *dev_id, struct pt_regs * regs)
@@ -957,7 +956,7 @@ plip_interrupt(int irq, void *dev_id, struct pt_regs * regs)
957 956
958 spin_unlock_irq(&nl->lock); 957 spin_unlock_irq(&nl->lock);
959} 958}
960 959
961static int 960static int
962plip_tx_packet(struct sk_buff *skb, struct net_device *dev) 961plip_tx_packet(struct sk_buff *skb, struct net_device *dev)
963{ 962{
@@ -1238,7 +1237,7 @@ plip_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1238 } 1237 }
1239 return 0; 1238 return 0;
1240} 1239}
1241 1240
1242static int parport[PLIP_MAX] = { [0 ... PLIP_MAX-1] = -1 }; 1241static int parport[PLIP_MAX] = { [0 ... PLIP_MAX-1] = -1 };
1243static int timid; 1242static int timid;
1244 1243
diff --git a/drivers/net/sk98lin/skge.c b/drivers/net/sk98lin/skge.c
index 82570ec44d8e..6ee4771addf1 100644
--- a/drivers/net/sk98lin/skge.c
+++ b/drivers/net/sk98lin/skge.c
@@ -5133,6 +5133,84 @@ static void __devexit skge_remove_one(struct pci_dev *pdev)
5133 kfree(pAC); 5133 kfree(pAC);
5134} 5134}
5135 5135
5136#ifdef CONFIG_PM
5137static int skge_suspend(struct pci_dev *pdev, pm_message_t state)
5138{
5139 struct net_device *dev = pci_get_drvdata(pdev);
5140 DEV_NET *pNet = netdev_priv(dev);
5141 SK_AC *pAC = pNet->pAC;
5142 struct net_device *otherdev = pAC->dev[1];
5143
5144 if (netif_running(dev)) {
5145 netif_carrier_off(dev);
5146 DoPrintInterfaceChange = SK_FALSE;
5147 SkDrvDeInitAdapter(pAC, 0); /* performs SkGeClose */
5148 netif_device_detach(dev);
5149 }
5150 if (otherdev != dev) {
5151 if (netif_running(otherdev)) {
5152 netif_carrier_off(otherdev);
5153 DoPrintInterfaceChange = SK_FALSE;
5154 SkDrvDeInitAdapter(pAC, 1); /* performs SkGeClose */
5155 netif_device_detach(otherdev);
5156 }
5157 }
5158
5159 pci_save_state(pdev);
5160 pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
5161 if (pAC->AllocFlag & SK_ALLOC_IRQ) {
5162 free_irq(dev->irq, dev);
5163 }
5164 pci_disable_device(pdev);
5165 pci_set_power_state(pdev, pci_choose_state(pdev, state));
5166
5167 return 0;
5168}
5169
5170static int skge_resume(struct pci_dev *pdev)
5171{
5172 struct net_device *dev = pci_get_drvdata(pdev);
5173 DEV_NET *pNet = netdev_priv(dev);
5174 SK_AC *pAC = pNet->pAC;
5175 struct net_device *otherdev = pAC->dev[1];
5176 int ret;
5177
5178 pci_set_power_state(pdev, PCI_D0);
5179 pci_restore_state(pdev);
5180 pci_enable_device(pdev);
5181 pci_set_master(pdev);
5182 if (pAC->GIni.GIMacsFound == 2)
5183 ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, pAC->Name, dev);
5184 else
5185 ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ, pAC->Name, dev);
5186 if (ret) {
5187 printk(KERN_WARNING "sk98lin: unable to acquire IRQ %d\n", dev->irq);
5188 pAC->AllocFlag &= ~SK_ALLOC_IRQ;
5189 dev->irq = 0;
5190 pci_disable_device(pdev);
5191 return -EBUSY;
5192 }
5193
5194 netif_device_attach(dev);
5195 if (netif_running(dev)) {
5196 DoPrintInterfaceChange = SK_FALSE;
5197 SkDrvInitAdapter(pAC, 0); /* first device */
5198 }
5199 if (otherdev != dev) {
5200 netif_device_attach(otherdev);
5201 if (netif_running(otherdev)) {
5202 DoPrintInterfaceChange = SK_FALSE;
5203 SkDrvInitAdapter(pAC, 1); /* second device */
5204 }
5205 }
5206
5207 return 0;
5208}
5209#else
5210#define skge_suspend NULL
5211#define skge_resume NULL
5212#endif
5213
5136static struct pci_device_id skge_pci_tbl[] = { 5214static struct pci_device_id skge_pci_tbl[] = {
5137 { PCI_VENDOR_ID_3COM, 0x1700, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 5215 { PCI_VENDOR_ID_3COM, 0x1700, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
5138 { PCI_VENDOR_ID_3COM, 0x80eb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 5216 { PCI_VENDOR_ID_3COM, 0x80eb, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
@@ -5158,6 +5236,8 @@ static struct pci_driver skge_driver = {
5158 .id_table = skge_pci_tbl, 5236 .id_table = skge_pci_tbl,
5159 .probe = skge_probe_one, 5237 .probe = skge_probe_one,
5160 .remove = __devexit_p(skge_remove_one), 5238 .remove = __devexit_p(skge_remove_one),
5239 .suspend = skge_suspend,
5240 .resume = skge_resume,
5161}; 5241};
5162 5242
5163static int __init skge_init(void) 5243static int __init skge_init(void)
diff --git a/drivers/net/sk98lin/skgeinit.c b/drivers/net/sk98lin/skgeinit.c
index df4483429a77..6cb49dd02251 100644
--- a/drivers/net/sk98lin/skgeinit.c
+++ b/drivers/net/sk98lin/skgeinit.c
@@ -2016,7 +2016,7 @@ SK_IOC IoC) /* IO context */
2016 * we set the PHY to coma mode and switch to D3 power state. 2016 * we set the PHY to coma mode and switch to D3 power state.
2017 */ 2017 */
2018 if (pAC->GIni.GIYukonLite && 2018 if (pAC->GIni.GIYukonLite &&
2019 pAC->GIni.GIChipRev == CHIP_REV_YU_LITE_A3) { 2019 pAC->GIni.GIChipRev >= CHIP_REV_YU_LITE_A3) {
2020 2020
2021 /* for all ports switch PHY to coma mode */ 2021 /* for all ports switch PHY to coma mode */
2022 for (i = 0; i < pAC->GIni.GIMacsFound; i++) { 2022 for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
diff --git a/drivers/net/sk98lin/skxmac2.c b/drivers/net/sk98lin/skxmac2.c
index 94a09deecb32..42d2d963150a 100644
--- a/drivers/net/sk98lin/skxmac2.c
+++ b/drivers/net/sk98lin/skxmac2.c
@@ -1065,7 +1065,7 @@ int Port) /* Port Index (MAC_1 + n) */
1065 1065
1066 /* WA code for COMA mode */ 1066 /* WA code for COMA mode */
1067 if (pAC->GIni.GIYukonLite && 1067 if (pAC->GIni.GIYukonLite &&
1068 pAC->GIni.GIChipRev == CHIP_REV_YU_LITE_A3) { 1068 pAC->GIni.GIChipRev >= CHIP_REV_YU_LITE_A3) {
1069 1069
1070 SK_IN32(IoC, B2_GP_IO, &DWord); 1070 SK_IN32(IoC, B2_GP_IO, &DWord);
1071 1071
@@ -1110,7 +1110,7 @@ int Port) /* Port Index (MAC_1 + n) */
1110 1110
1111 /* WA code for COMA mode */ 1111 /* WA code for COMA mode */
1112 if (pAC->GIni.GIYukonLite && 1112 if (pAC->GIni.GIYukonLite &&
1113 pAC->GIni.GIChipRev == CHIP_REV_YU_LITE_A3) { 1113 pAC->GIni.GIChipRev >= CHIP_REV_YU_LITE_A3) {
1114 1114
1115 SK_IN32(IoC, B2_GP_IO, &DWord); 1115 SK_IN32(IoC, B2_GP_IO, &DWord);
1116 1116
@@ -2126,7 +2126,7 @@ SK_U8 Mode) /* low power mode */
2126 int Ret = 0; 2126 int Ret = 0;
2127 2127
2128 if (pAC->GIni.GIYukonLite && 2128 if (pAC->GIni.GIYukonLite &&
2129 pAC->GIni.GIChipRev == CHIP_REV_YU_LITE_A3) { 2129 pAC->GIni.GIChipRev >= CHIP_REV_YU_LITE_A3) {
2130 2130
2131 /* save current power mode */ 2131 /* save current power mode */
2132 LastMode = pAC->GIni.GP[Port].PPhyPowerState; 2132 LastMode = pAC->GIni.GP[Port].PPhyPowerState;
@@ -2253,7 +2253,7 @@ int Port) /* Port Index (e.g. MAC_1) */
2253 int Ret = 0; 2253 int Ret = 0;
2254 2254
2255 if (pAC->GIni.GIYukonLite && 2255 if (pAC->GIni.GIYukonLite &&
2256 pAC->GIni.GIChipRev == CHIP_REV_YU_LITE_A3) { 2256 pAC->GIni.GIChipRev >= CHIP_REV_YU_LITE_A3) {
2257 2257
2258 /* save current power mode */ 2258 /* save current power mode */
2259 LastMode = pAC->GIni.GP[Port].PPhyPowerState; 2259 LastMode = pAC->GIni.GP[Port].PPhyPowerState;
diff --git a/drivers/net/skge.c b/drivers/net/skge.c
index 5cacc7ad9e79..f15739481d62 100644
--- a/drivers/net/skge.c
+++ b/drivers/net/skge.c
@@ -42,7 +42,7 @@
42#include "skge.h" 42#include "skge.h"
43 43
44#define DRV_NAME "skge" 44#define DRV_NAME "skge"
45#define DRV_VERSION "0.7" 45#define DRV_VERSION "0.8"
46#define PFX DRV_NAME " " 46#define PFX DRV_NAME " "
47 47
48#define DEFAULT_TX_RING_SIZE 128 48#define DEFAULT_TX_RING_SIZE 128
@@ -55,7 +55,7 @@
55#define ETH_JUMBO_MTU 9000 55#define ETH_JUMBO_MTU 9000
56#define TX_WATCHDOG (5 * HZ) 56#define TX_WATCHDOG (5 * HZ)
57#define NAPI_WEIGHT 64 57#define NAPI_WEIGHT 64
58#define BLINK_HZ (HZ/4) 58#define BLINK_MS 250
59 59
60MODULE_DESCRIPTION("SysKonnect Gigabit Ethernet driver"); 60MODULE_DESCRIPTION("SysKonnect Gigabit Ethernet driver");
61MODULE_AUTHOR("Stephen Hemminger <shemminger@osdl.org>"); 61MODULE_AUTHOR("Stephen Hemminger <shemminger@osdl.org>");
@@ -75,7 +75,6 @@ static const struct pci_device_id skge_id_table[] = {
75 { PCI_DEVICE(PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C940B) }, 75 { PCI_DEVICE(PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C940B) },
76 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_GE) }, 76 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_GE) },
77 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_YU) }, 77 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_YU) },
78 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9E00) }, /* SK-9Exx */
79 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, PCI_DEVICE_ID_DLINK_DGE510T), }, 78 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, PCI_DEVICE_ID_DLINK_DGE510T), },
80 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4320) }, 79 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4320) },
81 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5005) }, /* Belkin */ 80 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5005) }, /* Belkin */
@@ -249,7 +248,7 @@ static int skge_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
249 } else { 248 } else {
250 u32 setting; 249 u32 setting;
251 250
252 switch(ecmd->speed) { 251 switch (ecmd->speed) {
253 case SPEED_1000: 252 case SPEED_1000:
254 if (ecmd->duplex == DUPLEX_FULL) 253 if (ecmd->duplex == DUPLEX_FULL)
255 setting = SUPPORTED_1000baseT_Full; 254 setting = SUPPORTED_1000baseT_Full;
@@ -620,84 +619,98 @@ static int skge_set_coalesce(struct net_device *dev,
620 return 0; 619 return 0;
621} 620}
622 621
623static void skge_led_on(struct skge_hw *hw, int port) 622enum led_mode { LED_MODE_OFF, LED_MODE_ON, LED_MODE_TST };
623static void skge_led(struct skge_port *skge, enum led_mode mode)
624{ 624{
625 struct skge_hw *hw = skge->hw;
626 int port = skge->port;
627
628 spin_lock_bh(&hw->phy_lock);
625 if (hw->chip_id == CHIP_ID_GENESIS) { 629 if (hw->chip_id == CHIP_ID_GENESIS) {
626 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_ON); 630 switch (mode) {
627 skge_write8(hw, B0_LED, LED_STAT_ON); 631 case LED_MODE_OFF:
632 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_OFF);
633 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF);
634 skge_write32(hw, SK_REG(port, RX_LED_VAL), 0);
635 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_T_OFF);
636 break;
628 637
629 skge_write8(hw, SK_REG(port, RX_LED_TST), LED_T_ON); 638 case LED_MODE_ON:
630 skge_write32(hw, SK_REG(port, RX_LED_VAL), 100); 639 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_ON);
631 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START); 640 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_LINKSYNC_ON);
632 641
633 /* For Broadcom Phy only */ 642 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START);
634 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_ON); 643 skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_START);
635 } else {
636 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0);
637 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
638 PHY_M_LED_MO_DUP(MO_LED_ON) |
639 PHY_M_LED_MO_10(MO_LED_ON) |
640 PHY_M_LED_MO_100(MO_LED_ON) |
641 PHY_M_LED_MO_1000(MO_LED_ON) |
642 PHY_M_LED_MO_RX(MO_LED_ON));
643 }
644}
645 644
646static void skge_led_off(struct skge_hw *hw, int port) 645 break;
647{
648 if (hw->chip_id == CHIP_ID_GENESIS) {
649 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_OFF);
650 skge_write8(hw, B0_LED, LED_STAT_OFF);
651 646
652 skge_write32(hw, SK_REG(port, RX_LED_VAL), 0); 647 case LED_MODE_TST:
653 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_T_OFF); 648 skge_write8(hw, SK_REG(port, RX_LED_TST), LED_T_ON);
649 skge_write32(hw, SK_REG(port, RX_LED_VAL), 100);
650 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START);
654 651
655 /* Broadcom only */ 652 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_ON);
656 xm_phy_write(hw, port, PHY_BCOM_P_EXT_CTRL, PHY_B_PEC_LED_OFF); 653 break;
654 }
657 } else { 655 } else {
658 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0); 656 switch (mode) {
659 gm_phy_write(hw, port, PHY_MARV_LED_OVER, 657 case LED_MODE_OFF:
660 PHY_M_LED_MO_DUP(MO_LED_OFF) | 658 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0);
661 PHY_M_LED_MO_10(MO_LED_OFF) | 659 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
662 PHY_M_LED_MO_100(MO_LED_OFF) | 660 PHY_M_LED_MO_DUP(MO_LED_OFF) |
663 PHY_M_LED_MO_1000(MO_LED_OFF) | 661 PHY_M_LED_MO_10(MO_LED_OFF) |
664 PHY_M_LED_MO_RX(MO_LED_OFF)); 662 PHY_M_LED_MO_100(MO_LED_OFF) |
663 PHY_M_LED_MO_1000(MO_LED_OFF) |
664 PHY_M_LED_MO_RX(MO_LED_OFF));
665 break;
666 case LED_MODE_ON:
667 gm_phy_write(hw, port, PHY_MARV_LED_CTRL,
668 PHY_M_LED_PULS_DUR(PULS_170MS) |
669 PHY_M_LED_BLINK_RT(BLINK_84MS) |
670 PHY_M_LEDC_TX_CTRL |
671 PHY_M_LEDC_DP_CTRL);
672
673 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
674 PHY_M_LED_MO_RX(MO_LED_OFF) |
675 (skge->speed == SPEED_100 ?
676 PHY_M_LED_MO_100(MO_LED_ON) : 0));
677 break;
678 case LED_MODE_TST:
679 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, 0);
680 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
681 PHY_M_LED_MO_DUP(MO_LED_ON) |
682 PHY_M_LED_MO_10(MO_LED_ON) |
683 PHY_M_LED_MO_100(MO_LED_ON) |
684 PHY_M_LED_MO_1000(MO_LED_ON) |
685 PHY_M_LED_MO_RX(MO_LED_ON));
686 }
665 } 687 }
666} 688 spin_unlock_bh(&hw->phy_lock);
667
668static void skge_blink_timer(unsigned long data)
669{
670 struct skge_port *skge = (struct skge_port *) data;
671 struct skge_hw *hw = skge->hw;
672 unsigned long flags;
673
674 spin_lock_irqsave(&hw->phy_lock, flags);
675 if (skge->blink_on)
676 skge_led_on(hw, skge->port);
677 else
678 skge_led_off(hw, skge->port);
679 spin_unlock_irqrestore(&hw->phy_lock, flags);
680
681 skge->blink_on = !skge->blink_on;
682 mod_timer(&skge->led_blink, jiffies + BLINK_HZ);
683} 689}
684 690
685/* blink LED's for finding board */ 691/* blink LED's for finding board */
686static int skge_phys_id(struct net_device *dev, u32 data) 692static int skge_phys_id(struct net_device *dev, u32 data)
687{ 693{
688 struct skge_port *skge = netdev_priv(dev); 694 struct skge_port *skge = netdev_priv(dev);
695 unsigned long ms;
696 enum led_mode mode = LED_MODE_TST;
689 697
690 if (!data || data > (u32)(MAX_SCHEDULE_TIMEOUT / HZ)) 698 if (!data || data > (u32)(MAX_SCHEDULE_TIMEOUT / HZ))
691 data = (u32)(MAX_SCHEDULE_TIMEOUT / HZ); 699 ms = jiffies_to_msecs(MAX_SCHEDULE_TIMEOUT / HZ) * 1000;
700 else
701 ms = data * 1000;
692 702
693 /* start blinking */ 703 while (ms > 0) {
694 skge->blink_on = 1; 704 skge_led(skge, mode);
695 mod_timer(&skge->led_blink, jiffies+1); 705 mode ^= LED_MODE_TST;
696 706
697 msleep_interruptible(data * 1000); 707 if (msleep_interruptible(BLINK_MS))
698 del_timer_sync(&skge->led_blink); 708 break;
709 ms -= BLINK_MS;
710 }
699 711
700 skge_led_off(skge->hw, skge->port); 712 /* back to regular LED state */
713 skge_led(skge, netif_running(dev) ? LED_MODE_ON : LED_MODE_OFF);
701 714
702 return 0; 715 return 0;
703} 716}
@@ -1028,7 +1041,7 @@ static void bcom_check_link(struct skge_hw *hw, int port)
1028 } 1041 }
1029 1042
1030 /* Check Duplex mismatch */ 1043 /* Check Duplex mismatch */
1031 switch(aux & PHY_B_AS_AN_RES_MSK) { 1044 switch (aux & PHY_B_AS_AN_RES_MSK) {
1032 case PHY_B_RES_1000FD: 1045 case PHY_B_RES_1000FD:
1033 skge->duplex = DUPLEX_FULL; 1046 skge->duplex = DUPLEX_FULL;
1034 break; 1047 break;
@@ -1099,7 +1112,7 @@ static void bcom_phy_init(struct skge_port *skge, int jumbo)
1099 r |= XM_MMU_NO_PRE; 1112 r |= XM_MMU_NO_PRE;
1100 xm_write16(hw, port, XM_MMU_CMD,r); 1113 xm_write16(hw, port, XM_MMU_CMD,r);
1101 1114
1102 switch(id1) { 1115 switch (id1) {
1103 case PHY_BCOM_ID1_C0: 1116 case PHY_BCOM_ID1_C0:
1104 /* 1117 /*
1105 * Workaround BCOM Errata for the C0 type. 1118 * Workaround BCOM Errata for the C0 type.
@@ -1194,13 +1207,6 @@ static void genesis_mac_init(struct skge_hw *hw, int port)
1194 xm_write16(hw, port, XM_STAT_CMD, 1207 xm_write16(hw, port, XM_STAT_CMD,
1195 XM_SC_CLR_RXC | XM_SC_CLR_TXC); 1208 XM_SC_CLR_RXC | XM_SC_CLR_TXC);
1196 1209
1197 /* initialize Rx, Tx and Link LED */
1198 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_ON);
1199 skge_write8(hw, SK_REG(port, LNK_LED_REG), LINKLED_LINKSYNC_ON);
1200
1201 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_START);
1202 skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_START);
1203
1204 /* Unreset the XMAC. */ 1210 /* Unreset the XMAC. */
1205 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_CLR_MAC_RST); 1211 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_CLR_MAC_RST);
1206 1212
@@ -1209,7 +1215,6 @@ static void genesis_mac_init(struct skge_hw *hw, int port)
1209 * namely for the 1000baseTX cards that use the XMAC's 1215 * namely for the 1000baseTX cards that use the XMAC's
1210 * GMII mode. 1216 * GMII mode.
1211 */ 1217 */
1212 spin_lock_bh(&hw->phy_lock);
1213 /* Take external Phy out of reset */ 1218 /* Take external Phy out of reset */
1214 r = skge_read32(hw, B2_GP_IO); 1219 r = skge_read32(hw, B2_GP_IO);
1215 if (port == 0) 1220 if (port == 0)
@@ -1219,7 +1224,6 @@ static void genesis_mac_init(struct skge_hw *hw, int port)
1219 1224
1220 skge_write32(hw, B2_GP_IO, r); 1225 skge_write32(hw, B2_GP_IO, r);
1221 skge_read32(hw, B2_GP_IO); 1226 skge_read32(hw, B2_GP_IO);
1222 spin_unlock_bh(&hw->phy_lock);
1223 1227
1224 /* Enable GMII interfac */ 1228 /* Enable GMII interfac */
1225 xm_write16(hw, port, XM_HW_CFG, XM_HW_GMII_MD); 1229 xm_write16(hw, port, XM_HW_CFG, XM_HW_GMII_MD);
@@ -1569,7 +1573,6 @@ static void yukon_init(struct skge_hw *hw, int port)
1569{ 1573{
1570 struct skge_port *skge = netdev_priv(hw->dev[port]); 1574 struct skge_port *skge = netdev_priv(hw->dev[port]);
1571 u16 ctrl, ct1000, adv; 1575 u16 ctrl, ct1000, adv;
1572 u16 ledctrl, ledover;
1573 1576
1574 pr_debug("yukon_init\n"); 1577 pr_debug("yukon_init\n");
1575 if (skge->autoneg == AUTONEG_ENABLE) { 1578 if (skge->autoneg == AUTONEG_ENABLE) {
@@ -1641,32 +1644,11 @@ static void yukon_init(struct skge_hw *hw, int port)
1641 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, adv); 1644 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV, adv);
1642 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl); 1645 gm_phy_write(hw, port, PHY_MARV_CTRL, ctrl);
1643 1646
1644 /* Setup Phy LED's */
1645 ledctrl = PHY_M_LED_PULS_DUR(PULS_170MS);
1646 ledover = 0;
1647
1648 ledctrl |= PHY_M_LED_BLINK_RT(BLINK_84MS) | PHY_M_LEDC_TX_CTRL;
1649
1650 /* turn off the Rx LED (LED_RX) */
1651 ledover |= PHY_M_LED_MO_RX(MO_LED_OFF);
1652
1653 /* disable blink mode (LED_DUPLEX) on collisions */
1654 ctrl |= PHY_M_LEDC_DP_CTRL;
1655 gm_phy_write(hw, port, PHY_MARV_LED_CTRL, ledctrl);
1656
1657 if (skge->autoneg == AUTONEG_DISABLE || skge->speed == SPEED_100) {
1658 /* turn on 100 Mbps LED (LED_LINK100) */
1659 ledover |= PHY_M_LED_MO_100(MO_LED_ON);
1660 }
1661
1662 if (ledover)
1663 gm_phy_write(hw, port, PHY_MARV_LED_OVER, ledover);
1664
1665 /* Enable phy interrupt on autonegotiation complete (or link up) */ 1647 /* Enable phy interrupt on autonegotiation complete (or link up) */
1666 if (skge->autoneg == AUTONEG_ENABLE) 1648 if (skge->autoneg == AUTONEG_ENABLE)
1667 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_AN_COMPL); 1649 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_AN_MSK);
1668 else 1650 else
1669 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK); 1651 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_DEF_MSK);
1670} 1652}
1671 1653
1672static void yukon_reset(struct skge_hw *hw, int port) 1654static void yukon_reset(struct skge_hw *hw, int port)
@@ -1691,7 +1673,7 @@ static void yukon_mac_init(struct skge_hw *hw, int port)
1691 1673
1692 /* WA code for COMA mode -- set PHY reset */ 1674 /* WA code for COMA mode -- set PHY reset */
1693 if (hw->chip_id == CHIP_ID_YUKON_LITE && 1675 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
1694 hw->chip_rev == CHIP_REV_YU_LITE_A3) 1676 hw->chip_rev >= CHIP_REV_YU_LITE_A3)
1695 skge_write32(hw, B2_GP_IO, 1677 skge_write32(hw, B2_GP_IO,
1696 (skge_read32(hw, B2_GP_IO) | GP_DIR_9 | GP_IO_9)); 1678 (skge_read32(hw, B2_GP_IO) | GP_DIR_9 | GP_IO_9));
1697 1679
@@ -1701,7 +1683,7 @@ static void yukon_mac_init(struct skge_hw *hw, int port)
1701 1683
1702 /* WA code for COMA mode -- clear PHY reset */ 1684 /* WA code for COMA mode -- clear PHY reset */
1703 if (hw->chip_id == CHIP_ID_YUKON_LITE && 1685 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
1704 hw->chip_rev == CHIP_REV_YU_LITE_A3) 1686 hw->chip_rev >= CHIP_REV_YU_LITE_A3)
1705 skge_write32(hw, B2_GP_IO, 1687 skge_write32(hw, B2_GP_IO,
1706 (skge_read32(hw, B2_GP_IO) | GP_DIR_9) 1688 (skge_read32(hw, B2_GP_IO) | GP_DIR_9)
1707 & ~GP_IO_9); 1689 & ~GP_IO_9);
@@ -1745,9 +1727,7 @@ static void yukon_mac_init(struct skge_hw *hw, int port)
1745 gma_write16(hw, port, GM_GP_CTRL, reg); 1727 gma_write16(hw, port, GM_GP_CTRL, reg);
1746 skge_read16(hw, GMAC_IRQ_SRC); 1728 skge_read16(hw, GMAC_IRQ_SRC);
1747 1729
1748 spin_lock_bh(&hw->phy_lock);
1749 yukon_init(hw, port); 1730 yukon_init(hw, port);
1750 spin_unlock_bh(&hw->phy_lock);
1751 1731
1752 /* MIB clear */ 1732 /* MIB clear */
1753 reg = gma_read16(hw, port, GM_PHY_ADDR); 1733 reg = gma_read16(hw, port, GM_PHY_ADDR);
@@ -1796,7 +1776,7 @@ static void yukon_mac_init(struct skge_hw *hw, int port)
1796 skge_write16(hw, SK_REG(port, RX_GMF_FL_MSK), RX_FF_FL_DEF_MSK); 1776 skge_write16(hw, SK_REG(port, RX_GMF_FL_MSK), RX_FF_FL_DEF_MSK);
1797 reg = GMF_OPER_ON | GMF_RX_F_FL_ON; 1777 reg = GMF_OPER_ON | GMF_RX_F_FL_ON;
1798 if (hw->chip_id == CHIP_ID_YUKON_LITE && 1778 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
1799 hw->chip_rev == CHIP_REV_YU_LITE_A3) 1779 hw->chip_rev >= CHIP_REV_YU_LITE_A3)
1800 reg &= ~GMF_RX_F_FL_ON; 1780 reg &= ~GMF_RX_F_FL_ON;
1801 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR); 1781 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR);
1802 skge_write16(hw, SK_REG(port, RX_GMF_CTRL_T), reg); 1782 skge_write16(hw, SK_REG(port, RX_GMF_CTRL_T), reg);
@@ -1813,19 +1793,19 @@ static void yukon_stop(struct skge_port *skge)
1813 int port = skge->port; 1793 int port = skge->port;
1814 1794
1815 if (hw->chip_id == CHIP_ID_YUKON_LITE && 1795 if (hw->chip_id == CHIP_ID_YUKON_LITE &&
1816 hw->chip_rev == CHIP_REV_YU_LITE_A3) { 1796 hw->chip_rev >= CHIP_REV_YU_LITE_A3) {
1817 skge_write32(hw, B2_GP_IO, 1797 skge_write32(hw, B2_GP_IO,
1818 skge_read32(hw, B2_GP_IO) | GP_DIR_9 | GP_IO_9); 1798 skge_read32(hw, B2_GP_IO) | GP_DIR_9 | GP_IO_9);
1819 } 1799 }
1820 1800
1821 gma_write16(hw, port, GM_GP_CTRL, 1801 gma_write16(hw, port, GM_GP_CTRL,
1822 gma_read16(hw, port, GM_GP_CTRL) 1802 gma_read16(hw, port, GM_GP_CTRL)
1823 & ~(GM_GPCR_RX_ENA|GM_GPCR_RX_ENA)); 1803 & ~(GM_GPCR_TX_ENA|GM_GPCR_RX_ENA));
1824 gma_read16(hw, port, GM_GP_CTRL); 1804 gma_read16(hw, port, GM_GP_CTRL);
1825 1805
1826 /* set GPHY Control reset */ 1806 /* set GPHY Control reset */
1827 gma_write32(hw, port, GPHY_CTRL, GPC_RST_SET); 1807 skge_write32(hw, SK_REG(port, GPHY_CTRL), GPC_RST_SET);
1828 gma_write32(hw, port, GMAC_CTRL, GMC_RST_SET); 1808 skge_write32(hw, SK_REG(port, GMAC_CTRL), GMC_RST_SET);
1829} 1809}
1830 1810
1831static void yukon_get_stats(struct skge_port *skge, u64 *data) 1811static void yukon_get_stats(struct skge_port *skge, u64 *data)
@@ -1856,11 +1836,12 @@ static void yukon_mac_intr(struct skge_hw *hw, int port)
1856 1836
1857 if (status & GM_IS_RX_FF_OR) { 1837 if (status & GM_IS_RX_FF_OR) {
1858 ++skge->net_stats.rx_fifo_errors; 1838 ++skge->net_stats.rx_fifo_errors;
1859 gma_write8(hw, port, RX_GMF_CTRL_T, GMF_CLI_RX_FO); 1839 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_CLI_RX_FO);
1860 } 1840 }
1841
1861 if (status & GM_IS_TX_FF_UR) { 1842 if (status & GM_IS_TX_FF_UR) {
1862 ++skge->net_stats.tx_fifo_errors; 1843 ++skge->net_stats.tx_fifo_errors;
1863 gma_write8(hw, port, TX_GMF_CTRL_T, GMF_CLI_TX_FU); 1844 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_CLI_TX_FU);
1864 } 1845 }
1865 1846
1866} 1847}
@@ -1896,7 +1877,7 @@ static void yukon_link_up(struct skge_port *skge)
1896 reg |= GM_GPCR_RX_ENA | GM_GPCR_TX_ENA; 1877 reg |= GM_GPCR_RX_ENA | GM_GPCR_TX_ENA;
1897 gma_write16(hw, port, GM_GP_CTRL, reg); 1878 gma_write16(hw, port, GM_GP_CTRL, reg);
1898 1879
1899 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK); 1880 gm_phy_write(hw, port, PHY_MARV_INT_MASK, PHY_M_IS_DEF_MSK);
1900 skge_link_up(skge); 1881 skge_link_up(skge);
1901} 1882}
1902 1883
@@ -1904,12 +1885,14 @@ static void yukon_link_down(struct skge_port *skge)
1904{ 1885{
1905 struct skge_hw *hw = skge->hw; 1886 struct skge_hw *hw = skge->hw;
1906 int port = skge->port; 1887 int port = skge->port;
1888 u16 ctrl;
1907 1889
1908 pr_debug("yukon_link_down\n"); 1890 pr_debug("yukon_link_down\n");
1909 gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0); 1891 gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0);
1910 gm_phy_write(hw, port, GM_GP_CTRL, 1892
1911 gm_phy_read(hw, port, GM_GP_CTRL) 1893 ctrl = gma_read16(hw, port, GM_GP_CTRL);
1912 & ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA)); 1894 ctrl &= ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA);
1895 gma_write16(hw, port, GM_GP_CTRL, ctrl);
1913 1896
1914 if (skge->flow_control == FLOW_MODE_REM_SEND) { 1897 if (skge->flow_control == FLOW_MODE_REM_SEND) {
1915 /* restore Asymmetric Pause bit */ 1898 /* restore Asymmetric Pause bit */
@@ -2097,10 +2080,12 @@ static int skge_up(struct net_device *dev)
2097 skge_write32(hw, B0_IMSK, hw->intr_mask); 2080 skge_write32(hw, B0_IMSK, hw->intr_mask);
2098 2081
2099 /* Initialze MAC */ 2082 /* Initialze MAC */
2083 spin_lock_bh(&hw->phy_lock);
2100 if (hw->chip_id == CHIP_ID_GENESIS) 2084 if (hw->chip_id == CHIP_ID_GENESIS)
2101 genesis_mac_init(hw, port); 2085 genesis_mac_init(hw, port);
2102 else 2086 else
2103 yukon_mac_init(hw, port); 2087 yukon_mac_init(hw, port);
2088 spin_unlock_bh(&hw->phy_lock);
2104 2089
2105 /* Configure RAMbuffers */ 2090 /* Configure RAMbuffers */
2106 chunk = hw->ram_size / ((hw->ports + 1)*2); 2091 chunk = hw->ram_size / ((hw->ports + 1)*2);
@@ -2116,6 +2101,7 @@ static int skge_up(struct net_device *dev)
2116 /* Start receiver BMU */ 2101 /* Start receiver BMU */
2117 wmb(); 2102 wmb();
2118 skge_write8(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_START | CSR_IRQ_CL_F); 2103 skge_write8(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_START | CSR_IRQ_CL_F);
2104 skge_led(skge, LED_MODE_ON);
2119 2105
2120 pr_debug("skge_up completed\n"); 2106 pr_debug("skge_up completed\n");
2121 return 0; 2107 return 0;
@@ -2140,8 +2126,6 @@ static int skge_down(struct net_device *dev)
2140 2126
2141 netif_stop_queue(dev); 2127 netif_stop_queue(dev);
2142 2128
2143 del_timer_sync(&skge->led_blink);
2144
2145 /* Stop transmitter */ 2129 /* Stop transmitter */
2146 skge_write8(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_STOP); 2130 skge_write8(hw, Q_ADDR(txqaddr[port], Q_CSR), CSR_STOP);
2147 skge_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL), 2131 skge_write32(hw, RB_ADDR(txqaddr[port], RB_CTRL),
@@ -2175,15 +2159,12 @@ static int skge_down(struct net_device *dev)
2175 if (hw->chip_id == CHIP_ID_GENESIS) { 2159 if (hw->chip_id == CHIP_ID_GENESIS) {
2176 skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_RST_SET); 2160 skge_write8(hw, SK_REG(port, TX_MFF_CTRL2), MFF_RST_SET);
2177 skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_RST_SET); 2161 skge_write8(hw, SK_REG(port, RX_MFF_CTRL2), MFF_RST_SET);
2178 skge_write8(hw, SK_REG(port, TX_LED_CTRL), LED_STOP);
2179 skge_write8(hw, SK_REG(port, RX_LED_CTRL), LED_STOP);
2180 } else { 2162 } else {
2181 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET); 2163 skge_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
2182 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET); 2164 skge_write8(hw, SK_REG(port, TX_GMF_CTRL_T), GMF_RST_SET);
2183 } 2165 }
2184 2166
2185 /* turn off led's */ 2167 skge_led(skge, LED_MODE_OFF);
2186 skge_write16(hw, B0_LED, LED_STAT_OFF);
2187 2168
2188 skge_tx_clean(skge); 2169 skge_tx_clean(skge);
2189 skge_rx_clean(skge); 2170 skge_rx_clean(skge);
@@ -2633,11 +2614,17 @@ static inline void skge_tx_intr(struct net_device *dev)
2633 spin_unlock(&skge->tx_lock); 2614 spin_unlock(&skge->tx_lock);
2634} 2615}
2635 2616
2617/* Parity errors seem to happen when Genesis is connected to a switch
2618 * with no other ports present. Heartbeat error??
2619 */
2636static void skge_mac_parity(struct skge_hw *hw, int port) 2620static void skge_mac_parity(struct skge_hw *hw, int port)
2637{ 2621{
2638 printk(KERN_ERR PFX "%s: mac data parity error\n", 2622 struct net_device *dev = hw->dev[port];
2639 hw->dev[port] ? hw->dev[port]->name 2623
2640 : (port == 0 ? "(port A)": "(port B")); 2624 if (dev) {
2625 struct skge_port *skge = netdev_priv(dev);
2626 ++skge->net_stats.tx_heartbeat_errors;
2627 }
2641 2628
2642 if (hw->chip_id == CHIP_ID_GENESIS) 2629 if (hw->chip_id == CHIP_ID_GENESIS)
2643 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), 2630 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1),
@@ -3083,10 +3070,6 @@ static struct net_device *skge_devinit(struct skge_hw *hw, int port,
3083 3070
3084 spin_lock_init(&skge->tx_lock); 3071 spin_lock_init(&skge->tx_lock);
3085 3072
3086 init_timer(&skge->led_blink);
3087 skge->led_blink.function = skge_blink_timer;
3088 skge->led_blink.data = (unsigned long) skge;
3089
3090 if (hw->chip_id != CHIP_ID_GENESIS) { 3073 if (hw->chip_id != CHIP_ID_GENESIS) {
3091 dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG; 3074 dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
3092 skge->rx_csum = 1; 3075 skge->rx_csum = 1;
diff --git a/drivers/net/skge.h b/drivers/net/skge.h
index fced3d2bc072..b432f1bb8168 100644
--- a/drivers/net/skge.h
+++ b/drivers/net/skge.h
@@ -1449,10 +1449,12 @@ enum {
1449 PHY_M_IS_DTE_CHANGE = 1<<2, /* DTE Power Det. Status Changed */ 1449 PHY_M_IS_DTE_CHANGE = 1<<2, /* DTE Power Det. Status Changed */
1450 PHY_M_IS_POL_CHANGE = 1<<1, /* Polarity Changed */ 1450 PHY_M_IS_POL_CHANGE = 1<<1, /* Polarity Changed */
1451 PHY_M_IS_JABBER = 1<<0, /* Jabber */ 1451 PHY_M_IS_JABBER = 1<<0, /* Jabber */
1452};
1453 1452
1454#define PHY_M_DEF_MSK ( PHY_M_IS_AN_ERROR | PHY_M_IS_LSP_CHANGE | \ 1453 PHY_M_IS_DEF_MSK = PHY_M_IS_AN_ERROR | PHY_M_IS_LSP_CHANGE |
1455 PHY_M_IS_LST_CHANGE | PHY_M_IS_FIFO_ERROR) 1454 PHY_M_IS_LST_CHANGE | PHY_M_IS_FIFO_ERROR,
1455
1456 PHY_M_IS_AN_MSK = PHY_M_IS_AN_ERROR | PHY_M_IS_AN_COMPL,
1457};
1456 1458
1457/***** PHY_MARV_EXT_CTRL 16 bit r/w Ext. PHY Specific Ctrl *****/ 1459/***** PHY_MARV_EXT_CTRL 16 bit r/w Ext. PHY Specific Ctrl *****/
1458enum { 1460enum {
@@ -1509,7 +1511,7 @@ enum {
1509 PHY_M_LEDC_TX_C_MSB = 1<<0, /* Tx Control (MSB, 88E1111 only) */ 1511 PHY_M_LEDC_TX_C_MSB = 1<<0, /* Tx Control (MSB, 88E1111 only) */
1510}; 1512};
1511 1513
1512#define PHY_M_LED_PULS_DUR(x) ( ((x)<<12) & PHY_M_LEDC_PULS_MSK) 1514#define PHY_M_LED_PULS_DUR(x) (((x)<<12) & PHY_M_LEDC_PULS_MSK)
1513 1515
1514enum { 1516enum {
1515 PULS_NO_STR = 0,/* no pulse stretching */ 1517 PULS_NO_STR = 0,/* no pulse stretching */
@@ -1522,7 +1524,7 @@ enum {
1522 PULS_1300MS = 7,/* 1.3 s to 2.7 s */ 1524 PULS_1300MS = 7,/* 1.3 s to 2.7 s */
1523}; 1525};
1524 1526
1525#define PHY_M_LED_BLINK_RT(x) ( ((x)<<8) & PHY_M_LEDC_BL_R_MSK) 1527#define PHY_M_LED_BLINK_RT(x) (((x)<<8) & PHY_M_LEDC_BL_R_MSK)
1526 1528
1527enum { 1529enum {
1528 BLINK_42MS = 0,/* 42 ms */ 1530 BLINK_42MS = 0,/* 42 ms */
@@ -1602,9 +1604,9 @@ enum {
1602 PHY_M_FELP_LED0_MSK = 0xf, /* Bit 3.. 0: LED0 Mask (SPEED) */ 1604 PHY_M_FELP_LED0_MSK = 0xf, /* Bit 3.. 0: LED0 Mask (SPEED) */
1603}; 1605};
1604 1606
1605#define PHY_M_FELP_LED2_CTRL(x) ( ((x)<<8) & PHY_M_FELP_LED2_MSK) 1607#define PHY_M_FELP_LED2_CTRL(x) (((x)<<8) & PHY_M_FELP_LED2_MSK)
1606#define PHY_M_FELP_LED1_CTRL(x) ( ((x)<<4) & PHY_M_FELP_LED1_MSK) 1608#define PHY_M_FELP_LED1_CTRL(x) (((x)<<4) & PHY_M_FELP_LED1_MSK)
1607#define PHY_M_FELP_LED0_CTRL(x) ( ((x)<<0) & PHY_M_FELP_LED0_MSK) 1609#define PHY_M_FELP_LED0_CTRL(x) (((x)<<0) & PHY_M_FELP_LED0_MSK)
1608 1610
1609enum { 1611enum {
1610 LED_PAR_CTRL_COLX = 0x00, 1612 LED_PAR_CTRL_COLX = 0x00,
@@ -1640,7 +1642,7 @@ enum {
1640 PHY_M_MAC_MD_COPPER = 5,/* Copper only */ 1642 PHY_M_MAC_MD_COPPER = 5,/* Copper only */
1641 PHY_M_MAC_MD_1000BX = 7,/* 1000Base-X only */ 1643 PHY_M_MAC_MD_1000BX = 7,/* 1000Base-X only */
1642}; 1644};
1643#define PHY_M_MAC_MODE_SEL(x) ( ((x)<<7) & PHY_M_MAC_MD_MSK) 1645#define PHY_M_MAC_MODE_SEL(x) (((x)<<7) & PHY_M_MAC_MD_MSK)
1644 1646
1645/***** PHY_MARV_PHY_CTRL (page 3) 16 bit r/w LED Control Reg. *****/ 1647/***** PHY_MARV_PHY_CTRL (page 3) 16 bit r/w LED Control Reg. *****/
1646enum { 1648enum {
@@ -1650,10 +1652,10 @@ enum {
1650 PHY_M_LEDC_STA0_MSK = 0xf, /* Bit 3.. 0: STAT0 LED Ctrl. Mask */ 1652 PHY_M_LEDC_STA0_MSK = 0xf, /* Bit 3.. 0: STAT0 LED Ctrl. Mask */
1651}; 1653};
1652 1654
1653#define PHY_M_LEDC_LOS_CTRL(x) ( ((x)<<12) & PHY_M_LEDC_LOS_MSK) 1655#define PHY_M_LEDC_LOS_CTRL(x) (((x)<<12) & PHY_M_LEDC_LOS_MSK)
1654#define PHY_M_LEDC_INIT_CTRL(x) ( ((x)<<8) & PHY_M_LEDC_INIT_MSK) 1656#define PHY_M_LEDC_INIT_CTRL(x) (((x)<<8) & PHY_M_LEDC_INIT_MSK)
1655#define PHY_M_LEDC_STA1_CTRL(x) ( ((x)<<4) & PHY_M_LEDC_STA1_MSK) 1657#define PHY_M_LEDC_STA1_CTRL(x) (((x)<<4) & PHY_M_LEDC_STA1_MSK)
1656#define PHY_M_LEDC_STA0_CTRL(x) ( ((x)<<0) & PHY_M_LEDC_STA0_MSK) 1658#define PHY_M_LEDC_STA0_CTRL(x) (((x)<<0) & PHY_M_LEDC_STA0_MSK)
1657 1659
1658/* GMAC registers */ 1660/* GMAC registers */
1659/* Port Registers */ 1661/* Port Registers */
@@ -2505,8 +2507,6 @@ struct skge_port {
2505 dma_addr_t dma; 2507 dma_addr_t dma;
2506 unsigned long mem_size; 2508 unsigned long mem_size;
2507 unsigned int rx_buf_size; 2509 unsigned int rx_buf_size;
2508
2509 struct timer_list led_blink;
2510}; 2510};
2511 2511
2512 2512
@@ -2606,17 +2606,6 @@ static inline void gma_write16(const struct skge_hw *hw, int port, int r, u16 v)
2606 skge_write16(hw, SK_GMAC_REG(port,r), v); 2606 skge_write16(hw, SK_GMAC_REG(port,r), v);
2607} 2607}
2608 2608
2609static inline void gma_write32(const struct skge_hw *hw, int port, int r, u32 v)
2610{
2611 skge_write16(hw, SK_GMAC_REG(port, r), (u16) v);
2612 skge_write32(hw, SK_GMAC_REG(port, r+4), (u16)(v >> 16));
2613}
2614
2615static inline void gma_write8(const struct skge_hw *hw, int port, int r, u8 v)
2616{
2617 skge_write8(hw, SK_GMAC_REG(port,r), v);
2618}
2619
2620static inline void gma_set_addr(struct skge_hw *hw, int port, int reg, 2609static inline void gma_set_addr(struct skge_hw *hw, int port, int reg,
2621 const u8 *addr) 2610 const u8 *addr)
2622{ 2611{
diff --git a/drivers/net/smc91x.h b/drivers/net/smc91x.h
index 7089d86e857a..a9b06b8d8e3f 100644
--- a/drivers/net/smc91x.h
+++ b/drivers/net/smc91x.h
@@ -188,7 +188,7 @@ SMC_outw(u16 val, void __iomem *ioaddr, int reg)
188#define SMC_IRQ_TRIGGER_TYPE (( \ 188#define SMC_IRQ_TRIGGER_TYPE (( \
189 machine_is_omap_h2() \ 189 machine_is_omap_h2() \
190 || machine_is_omap_h3() \ 190 || machine_is_omap_h3() \
191 || (machine_is_omap_innovator() && !cpu_is_omap150()) \ 191 || (machine_is_omap_innovator() && !cpu_is_omap1510()) \
192 ) ? IRQT_FALLING : IRQT_RISING) 192 ) ? IRQT_FALLING : IRQT_RISING)
193 193
194 194
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index 201a550f0bcc..368b8fb14023 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -66,8 +66,8 @@
66 66
67#define DRV_MODULE_NAME "tg3" 67#define DRV_MODULE_NAME "tg3"
68#define PFX DRV_MODULE_NAME ": " 68#define PFX DRV_MODULE_NAME ": "
69#define DRV_MODULE_VERSION "3.34" 69#define DRV_MODULE_VERSION "3.35"
70#define DRV_MODULE_RELDATE "July 25, 2005" 70#define DRV_MODULE_RELDATE "August 6, 2005"
71 71
72#define TG3_DEF_MAC_MODE 0 72#define TG3_DEF_MAC_MODE 0
73#define TG3_DEF_RX_MODE 0 73#define TG3_DEF_RX_MODE 0
@@ -10421,6 +10421,12 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
10421 10421
10422 tg3_init_coal(tp); 10422 tg3_init_coal(tp);
10423 10423
10424 /* Now that we have fully setup the chip, save away a snapshot
10425 * of the PCI config space. We need to restore this after
10426 * GRC_MISC_CFG core clock resets and some resume events.
10427 */
10428 pci_save_state(tp->pdev);
10429
10424 err = register_netdev(dev); 10430 err = register_netdev(dev);
10425 if (err) { 10431 if (err) {
10426 printk(KERN_ERR PFX "Cannot register net device, " 10432 printk(KERN_ERR PFX "Cannot register net device, "
@@ -10430,12 +10436,6 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
10430 10436
10431 pci_set_drvdata(pdev, dev); 10437 pci_set_drvdata(pdev, dev);
10432 10438
10433 /* Now that we have fully setup the chip, save away a snapshot
10434 * of the PCI config space. We need to restore this after
10435 * GRC_MISC_CFG core clock resets and some resume events.
10436 */
10437 pci_save_state(tp->pdev);
10438
10439 printk(KERN_INFO "%s: Tigon3 [partno(%s) rev %04x PHY(%s)] (PCI%s:%s:%s) %sBaseT Ethernet ", 10439 printk(KERN_INFO "%s: Tigon3 [partno(%s) rev %04x PHY(%s)] (PCI%s:%s:%s) %sBaseT Ethernet ",
10440 dev->name, 10440 dev->name,
10441 tp->board_part_number, 10441 tp->board_part_number,
diff --git a/drivers/net/via-velocity.h b/drivers/net/via-velocity.h
index 1b70b7c97580..d9a774b91ddc 100644
--- a/drivers/net/via-velocity.h
+++ b/drivers/net/via-velocity.h
@@ -1414,7 +1414,7 @@ static inline void mac_get_cam(struct mac_regs __iomem * regs, int idx, u8 *addr
1414 * the rest of the logic from the result of sleep/wakeup 1414 * the rest of the logic from the result of sleep/wakeup
1415 */ 1415 */
1416 1416
1417inline static void mac_wol_reset(struct mac_regs __iomem * regs) 1417static inline void mac_wol_reset(struct mac_regs __iomem * regs)
1418{ 1418{
1419 1419
1420 /* Turn off SWPTAG right after leaving power mode */ 1420 /* Turn off SWPTAG right after leaving power mode */
@@ -1811,7 +1811,7 @@ struct velocity_info {
1811 * CHECK ME: locking 1811 * CHECK ME: locking
1812 */ 1812 */
1813 1813
1814inline static int velocity_get_ip(struct velocity_info *vptr) 1814static inline int velocity_get_ip(struct velocity_info *vptr)
1815{ 1815{
1816 struct in_device *in_dev = (struct in_device *) vptr->dev->ip_ptr; 1816 struct in_device *in_dev = (struct in_device *) vptr->dev->ip_ptr;
1817 struct in_ifaddr *ifa; 1817 struct in_ifaddr *ifa;
diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index 47f3c5d0203d..df20adcd0730 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -5013,7 +5013,7 @@ static void proc_SSID_on_close( struct inode *inode, struct file *file ) {
5013 enable_MAC(ai, &rsp, 1); 5013 enable_MAC(ai, &rsp, 1);
5014} 5014}
5015 5015
5016inline static u8 hexVal(char c) { 5016static inline u8 hexVal(char c) {
5017 if (c>='0' && c<='9') return c -= '0'; 5017 if (c>='0' && c<='9') return c -= '0';
5018 if (c>='a' && c<='f') return c -= 'a'-10; 5018 if (c>='a' && c<='f') return c -= 'a'-10;
5019 if (c>='A' && c<='F') return c -= 'A'-10; 5019 if (c>='A' && c<='F') return c -= 'A'-10;
diff --git a/drivers/net/wireless/orinoco_cs.c b/drivers/net/wireless/orinoco_cs.c
index 368d2f962f67..1cc1492083c9 100644
--- a/drivers/net/wireless/orinoco_cs.c
+++ b/drivers/net/wireless/orinoco_cs.c
@@ -621,8 +621,6 @@ static struct pcmcia_device_id orinoco_cs_ids[] = {
621 PCMCIA_DEVICE_MANF_CARD(0x9005, 0x0021), 621 PCMCIA_DEVICE_MANF_CARD(0x9005, 0x0021),
622 PCMCIA_DEVICE_MANF_CARD(0xc250, 0x0002), 622 PCMCIA_DEVICE_MANF_CARD(0xc250, 0x0002),
623 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002), 623 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002),
624 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002),
625 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005),
626 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005), 624 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005),
627 PCMCIA_DEVICE_PROD_ID12("3Com", "3CRWE737A AirConnect Wireless LAN PC Card", 0x41240e5b, 0x56010af3), 625 PCMCIA_DEVICE_PROD_ID12("3Com", "3CRWE737A AirConnect Wireless LAN PC Card", 0x41240e5b, 0x56010af3),
628 PCMCIA_DEVICE_PROD_ID123("Instant Wireless ", " Network PC CARD", "Version 01.02", 0x11d901af, 0x6e9bd926, 0x4b74baa0), 626 PCMCIA_DEVICE_PROD_ID123("Instant Wireless ", " Network PC CARD", "Version 01.02", 0x11d901af, 0x6e9bd926, 0x4b74baa0),
diff --git a/drivers/oprofile/cpu_buffer.c b/drivers/oprofile/cpu_buffer.c
index e9b1772a3a28..026f671ea558 100644
--- a/drivers/oprofile/cpu_buffer.c
+++ b/drivers/oprofile/cpu_buffer.c
@@ -42,8 +42,7 @@ void free_cpu_buffers(void)
42 vfree(cpu_buffer[i].buffer); 42 vfree(cpu_buffer[i].buffer);
43 } 43 }
44} 44}
45 45
46
47int alloc_cpu_buffers(void) 46int alloc_cpu_buffers(void)
48{ 47{
49 int i; 48 int i;
@@ -74,7 +73,6 @@ fail:
74 free_cpu_buffers(); 73 free_cpu_buffers();
75 return -ENOMEM; 74 return -ENOMEM;
76} 75}
77
78 76
79void start_cpu_work(void) 77void start_cpu_work(void)
80{ 78{
@@ -93,7 +91,6 @@ void start_cpu_work(void)
93 } 91 }
94} 92}
95 93
96
97void end_cpu_work(void) 94void end_cpu_work(void)
98{ 95{
99 int i; 96 int i;
@@ -109,7 +106,6 @@ void end_cpu_work(void)
109 flush_scheduled_work(); 106 flush_scheduled_work();
110} 107}
111 108
112
113/* Resets the cpu buffer to a sane state. */ 109/* Resets the cpu buffer to a sane state. */
114void cpu_buffer_reset(struct oprofile_cpu_buffer * cpu_buf) 110void cpu_buffer_reset(struct oprofile_cpu_buffer * cpu_buf)
115{ 111{
@@ -121,7 +117,6 @@ void cpu_buffer_reset(struct oprofile_cpu_buffer * cpu_buf)
121 cpu_buf->last_task = NULL; 117 cpu_buf->last_task = NULL;
122} 118}
123 119
124
125/* compute number of available slots in cpu_buffer queue */ 120/* compute number of available slots in cpu_buffer queue */
126static unsigned long nr_available_slots(struct oprofile_cpu_buffer const * b) 121static unsigned long nr_available_slots(struct oprofile_cpu_buffer const * b)
127{ 122{
@@ -134,7 +129,6 @@ static unsigned long nr_available_slots(struct oprofile_cpu_buffer const * b)
134 return tail + (b->buffer_size - head) - 1; 129 return tail + (b->buffer_size - head) - 1;
135} 130}
136 131
137
138static void increment_head(struct oprofile_cpu_buffer * b) 132static void increment_head(struct oprofile_cpu_buffer * b)
139{ 133{
140 unsigned long new_head = b->head_pos + 1; 134 unsigned long new_head = b->head_pos + 1;
@@ -149,10 +143,7 @@ static void increment_head(struct oprofile_cpu_buffer * b)
149 b->head_pos = 0; 143 b->head_pos = 0;
150} 144}
151 145
152 146static inline void
153
154
155inline static void
156add_sample(struct oprofile_cpu_buffer * cpu_buf, 147add_sample(struct oprofile_cpu_buffer * cpu_buf,
157 unsigned long pc, unsigned long event) 148 unsigned long pc, unsigned long event)
158{ 149{
@@ -162,14 +153,12 @@ add_sample(struct oprofile_cpu_buffer * cpu_buf,
162 increment_head(cpu_buf); 153 increment_head(cpu_buf);
163} 154}
164 155
165 156static inline void
166inline static void
167add_code(struct oprofile_cpu_buffer * buffer, unsigned long value) 157add_code(struct oprofile_cpu_buffer * buffer, unsigned long value)
168{ 158{
169 add_sample(buffer, ESCAPE_CODE, value); 159 add_sample(buffer, ESCAPE_CODE, value);
170} 160}
171 161
172
173/* This must be safe from any context. It's safe writing here 162/* This must be safe from any context. It's safe writing here
174 * because of the head/tail separation of the writer and reader 163 * because of the head/tail separation of the writer and reader
175 * of the CPU buffer. 164 * of the CPU buffer.
@@ -223,13 +212,11 @@ static int oprofile_begin_trace(struct oprofile_cpu_buffer * cpu_buf)
223 return 1; 212 return 1;
224} 213}
225 214
226
227static void oprofile_end_trace(struct oprofile_cpu_buffer * cpu_buf) 215static void oprofile_end_trace(struct oprofile_cpu_buffer * cpu_buf)
228{ 216{
229 cpu_buf->tracing = 0; 217 cpu_buf->tracing = 0;
230} 218}
231 219
232
233void oprofile_add_sample(struct pt_regs * const regs, unsigned long event) 220void oprofile_add_sample(struct pt_regs * const regs, unsigned long event)
234{ 221{
235 struct oprofile_cpu_buffer * cpu_buf = &cpu_buffer[smp_processor_id()]; 222 struct oprofile_cpu_buffer * cpu_buf = &cpu_buffer[smp_processor_id()];
@@ -251,14 +238,12 @@ void oprofile_add_sample(struct pt_regs * const regs, unsigned long event)
251 oprofile_end_trace(cpu_buf); 238 oprofile_end_trace(cpu_buf);
252} 239}
253 240
254
255void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event) 241void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event)
256{ 242{
257 struct oprofile_cpu_buffer * cpu_buf = &cpu_buffer[smp_processor_id()]; 243 struct oprofile_cpu_buffer * cpu_buf = &cpu_buffer[smp_processor_id()];
258 log_sample(cpu_buf, pc, is_kernel, event); 244 log_sample(cpu_buf, pc, is_kernel, event);
259} 245}
260 246
261
262void oprofile_add_trace(unsigned long pc) 247void oprofile_add_trace(unsigned long pc)
263{ 248{
264 struct oprofile_cpu_buffer * cpu_buf = &cpu_buffer[smp_processor_id()]; 249 struct oprofile_cpu_buffer * cpu_buf = &cpu_buffer[smp_processor_id()];
@@ -283,8 +268,6 @@ void oprofile_add_trace(unsigned long pc)
283 add_sample(cpu_buf, pc, 0); 268 add_sample(cpu_buf, pc, 0);
284} 269}
285 270
286
287
288/* 271/*
289 * This serves to avoid cpu buffer overflow, and makes sure 272 * This serves to avoid cpu buffer overflow, and makes sure
290 * the task mortuary progresses 273 * the task mortuary progresses
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index fedae89d8f7d..fb9a11243d2a 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -60,7 +60,9 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
60 continue; 60 continue;
61 61
62 /* Ok, try it out.. */ 62 /* Ok, try it out.. */
63 ret = allocate_resource(r, res, size, min, -1, align, 63 ret = allocate_resource(r, res, size,
64 r->start ? : min,
65 -1, align,
64 alignf, alignf_data); 66 alignf, alignf_data);
65 if (ret == 0) 67 if (ret == 0)
66 break; 68 break;
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index df3bdae2040f..93e8a878ea95 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -507,7 +507,7 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max
507 pci_write_config_dword(dev, PCI_PRIMARY_BUS, buses); 507 pci_write_config_dword(dev, PCI_PRIMARY_BUS, buses);
508 508
509 if (!is_cardbus) { 509 if (!is_cardbus) {
510 child->bridge_ctl = PCI_BRIDGE_CTL_NO_ISA; 510 child->bridge_ctl = bctl | PCI_BRIDGE_CTL_NO_ISA;
511 /* 511 /*
512 * Adjust subordinate busnr in parent buses. 512 * Adjust subordinate busnr in parent buses.
513 * We do this before scanning for children because 513 * We do this before scanning for children because
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 1521fd5d95cc..a9160ad16581 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -373,6 +373,25 @@ static void __devinit quirk_vt82c686_acpi(struct pci_dev *dev)
373} 373}
374DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4, quirk_vt82c686_acpi ); 374DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4, quirk_vt82c686_acpi );
375 375
376/*
377 * VIA VT8235 ISA Bridge: Two IO regions pointed to by words at
378 * 0x88 (128 bytes of power management registers)
379 * 0xd0 (16 bytes of SMB registers)
380 */
381static void __devinit quirk_vt8235_acpi(struct pci_dev *dev)
382{
383 u16 pm, smb;
384
385 pci_read_config_word(dev, 0x88, &pm);
386 pm &= PCI_BASE_ADDRESS_IO_MASK;
387 quirk_io_region(dev, pm, 128, PCI_BRIDGE_RESOURCES);
388
389 pci_read_config_word(dev, 0xd0, &smb);
390 smb &= PCI_BASE_ADDRESS_IO_MASK;
391 quirk_io_region(dev, smb, 16, PCI_BRIDGE_RESOURCES + 1);
392}
393DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, quirk_vt8235_acpi);
394
376 395
377#ifdef CONFIG_X86_IO_APIC 396#ifdef CONFIG_X86_IO_APIC
378 397
@@ -820,6 +839,11 @@ static void __init asus_hides_smbus_hostbridge(struct pci_dev *dev)
820 case 0x0001: /* Toshiba Satellite A40 */ 839 case 0x0001: /* Toshiba Satellite A40 */
821 asus_hides_smbus = 1; 840 asus_hides_smbus = 1;
822 } 841 }
842 if (dev->device == PCI_DEVICE_ID_INTEL_82855PM_HB)
843 switch(dev->subsystem_device) {
844 case 0x0001: /* Toshiba Tecra M2 */
845 asus_hides_smbus = 1;
846 }
823 } else if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG)) { 847 } else if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG)) {
824 if (dev->device == PCI_DEVICE_ID_INTEL_82855PM_HB) 848 if (dev->device == PCI_DEVICE_ID_INTEL_82855PM_HB)
825 switch(dev->subsystem_device) { 849 switch(dev->subsystem_device) {
diff --git a/drivers/pci/rom.c b/drivers/pci/rom.c
index 838575e3fac6..713c78f3a65d 100644
--- a/drivers/pci/rom.c
+++ b/drivers/pci/rom.c
@@ -125,7 +125,9 @@ void __iomem *pci_map_rom(struct pci_dev *pdev, size_t *size)
125 image += readw(pds + 16) * 512; 125 image += readw(pds + 16) * 512;
126 } while (!last_image); 126 } while (!last_image);
127 127
128 *size = image - rom; 128 /* never return a size larger than the PCI resource window */
129 /* there are known ROMs that get the size wrong */
130 *size = min((size_t)(image - rom), *size);
129 131
130 return rom; 132 return rom;
131} 133}
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 9fe48f712be9..a2eebc6eaacc 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -51,8 +51,6 @@ pbus_assign_resources_sorted(struct pci_bus *bus)
51 struct resource_list head, *list, *tmp; 51 struct resource_list head, *list, *tmp;
52 int idx; 52 int idx;
53 53
54 bus->bridge_ctl &= ~PCI_BRIDGE_CTL_VGA;
55
56 head.next = NULL; 54 head.next = NULL;
57 list_for_each_entry(dev, &bus->devices, bus_list) { 55 list_for_each_entry(dev, &bus->devices, bus_list) {
58 u16 class = dev->class >> 8; 56 u16 class = dev->class >> 8;
@@ -62,10 +60,6 @@ pbus_assign_resources_sorted(struct pci_bus *bus)
62 class == PCI_CLASS_BRIDGE_HOST) 60 class == PCI_CLASS_BRIDGE_HOST)
63 continue; 61 continue;
64 62
65 if (class == PCI_CLASS_DISPLAY_VGA ||
66 class == PCI_CLASS_NOT_DEFINED_VGA)
67 bus->bridge_ctl |= PCI_BRIDGE_CTL_VGA;
68
69 pdev_sort_resources(dev, &head); 63 pdev_sort_resources(dev, &head);
70 } 64 }
71 65
@@ -509,12 +503,6 @@ pci_bus_assign_resources(struct pci_bus *bus)
509 503
510 pbus_assign_resources_sorted(bus); 504 pbus_assign_resources_sorted(bus);
511 505
512 if (bus->bridge_ctl & PCI_BRIDGE_CTL_VGA) {
513 /* Propagate presence of the VGA to upstream bridges */
514 for (b = bus; b->parent; b = b->parent) {
515 b->bridge_ctl |= PCI_BRIDGE_CTL_VGA;
516 }
517 }
518 list_for_each_entry(dev, &bus->devices, bus_list) { 506 list_for_each_entry(dev, &bus->devices, bus_list) {
519 b = dev->subordinate; 507 b = dev->subordinate;
520 if (!b) 508 if (!b)
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index 1ca21d2ba11c..84eedc965688 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -33,6 +33,11 @@ pci_update_resource(struct pci_dev *dev, struct resource *res, int resno)
33 u32 new, check, mask; 33 u32 new, check, mask;
34 int reg; 34 int reg;
35 35
36 /* Ignore resources for unimplemented BARs and unused resource slots
37 for 64 bit BARs. */
38 if (!res->flags)
39 return;
40
36 pcibios_resource_to_bus(dev, &region, res); 41 pcibios_resource_to_bus(dev, &region, res);
37 42
38 pr_debug(" got res [%lx:%lx] bus [%lx:%lx] flags %lx for " 43 pr_debug(" got res [%lx:%lx] bus [%lx:%lx] flags %lx for "
@@ -67,7 +72,7 @@ pci_update_resource(struct pci_dev *dev, struct resource *res, int resno)
67 72
68 if ((new & (PCI_BASE_ADDRESS_SPACE|PCI_BASE_ADDRESS_MEM_TYPE_MASK)) == 73 if ((new & (PCI_BASE_ADDRESS_SPACE|PCI_BASE_ADDRESS_MEM_TYPE_MASK)) ==
69 (PCI_BASE_ADDRESS_SPACE_MEMORY|PCI_BASE_ADDRESS_MEM_TYPE_64)) { 74 (PCI_BASE_ADDRESS_SPACE_MEMORY|PCI_BASE_ADDRESS_MEM_TYPE_64)) {
70 new = 0; /* currently everyone zeros the high address */ 75 new = region.start >> 16 >> 16;
71 pci_write_config_dword(dev, reg + 4, new); 76 pci_write_config_dword(dev, reg + 4, new);
72 pci_read_config_dword(dev, reg + 4, &check); 77 pci_read_config_dword(dev, reg + 4, &check);
73 if (check != new) { 78 if (check != new) {
diff --git a/drivers/pcmcia/au1000_generic.c b/drivers/pcmcia/au1000_generic.c
index 0a5c95807cf2..470ef756252e 100644
--- a/drivers/pcmcia/au1000_generic.c
+++ b/drivers/pcmcia/au1000_generic.c
@@ -388,6 +388,7 @@ int au1x00_pcmcia_socket_probe(struct device *dev, struct pcmcia_low_level *ops,
388 struct au1000_pcmcia_socket *skt = PCMCIA_SOCKET(i); 388 struct au1000_pcmcia_socket *skt = PCMCIA_SOCKET(i);
389 memset(skt, 0, sizeof(*skt)); 389 memset(skt, 0, sizeof(*skt));
390 390
391 skt->socket.resource_ops = &pccard_static_ops;
391 skt->socket.ops = &au1x00_pcmcia_operations; 392 skt->socket.ops = &au1x00_pcmcia_operations;
392 skt->socket.owner = ops->owner; 393 skt->socket.owner = ops->owner;
393 skt->socket.dev.dev = dev; 394 skt->socket.dev.dev = dev;
diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c
index dd7651ff5b43..3afb682255a0 100644
--- a/drivers/pcmcia/cistpl.c
+++ b/drivers/pcmcia/cistpl.c
@@ -88,31 +88,38 @@ EXPORT_SYMBOL(release_cis_mem);
88static void __iomem * 88static void __iomem *
89set_cis_map(struct pcmcia_socket *s, unsigned int card_offset, unsigned int flags) 89set_cis_map(struct pcmcia_socket *s, unsigned int card_offset, unsigned int flags)
90{ 90{
91 pccard_mem_map *mem = &s->cis_mem; 91 pccard_mem_map *mem = &s->cis_mem;
92 int ret; 92 int ret;
93
94 if (!(s->features & SS_CAP_STATIC_MAP) && (mem->res == NULL)) {
95 mem->res = pcmcia_find_mem_region(0, s->map_size, s->map_size, 0, s);
96 if (mem->res == NULL) {
97 printk(KERN_NOTICE "cs: unable to map card memory!\n");
98 return NULL;
99 }
100 s->cis_virt = NULL;
101 }
93 102
94 if (!(s->features & SS_CAP_STATIC_MAP) && mem->res == NULL) { 103 if (!(s->features & SS_CAP_STATIC_MAP) && (!s->cis_virt))
95 mem->res = pcmcia_find_mem_region(0, s->map_size, s->map_size, 0, s); 104 s->cis_virt = ioremap(mem->res->start, s->map_size);
96 if (mem->res == NULL) { 105
97 printk(KERN_NOTICE "cs: unable to map card memory!\n"); 106 mem->card_start = card_offset;
98 return NULL; 107 mem->flags = flags;
108
109 ret = s->ops->set_mem_map(s, mem);
110 if (ret) {
111 iounmap(s->cis_virt);
112 s->cis_virt = NULL;
113 return NULL;
99 } 114 }
100 s->cis_virt = ioremap(mem->res->start, s->map_size);
101 }
102 mem->card_start = card_offset;
103 mem->flags = flags;
104 ret = s->ops->set_mem_map(s, mem);
105 if (ret) {
106 iounmap(s->cis_virt);
107 return NULL;
108 }
109 115
110 if (s->features & SS_CAP_STATIC_MAP) { 116 if (s->features & SS_CAP_STATIC_MAP) {
111 if (s->cis_virt) 117 if (s->cis_virt)
112 iounmap(s->cis_virt); 118 iounmap(s->cis_virt);
113 s->cis_virt = ioremap(mem->static_start, s->map_size); 119 s->cis_virt = ioremap(mem->static_start, s->map_size);
114 } 120 }
115 return s->cis_virt; 121
122 return s->cis_virt;
116} 123}
117 124
118/*====================================================================== 125/*======================================================================
diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c
index 3e3c6f12bbe6..43da2e92d50f 100644
--- a/drivers/pcmcia/ds.c
+++ b/drivers/pcmcia/ds.c
@@ -206,8 +206,8 @@ static void pcmcia_check_driver(struct pcmcia_driver *p_drv)
206 u32 hash; 206 u32 hash;
207 207
208 if (!p_drv->attach || !p_drv->event || !p_drv->detach) 208 if (!p_drv->attach || !p_drv->event || !p_drv->detach)
209 printk(KERN_DEBUG "pcmcia: %s does misses a callback function", 209 printk(KERN_DEBUG "pcmcia: %s lacks a requisite callback "
210 p_drv->drv.name); 210 "function\n", p_drv->drv.name);
211 211
212 while (did && did->match_flags) { 212 while (did && did->match_flags) {
213 for (i=0; i<4; i++) { 213 for (i=0; i<4; i++) {
@@ -589,8 +589,8 @@ static void pcmcia_delayed_add_pseudo_device(void *data)
589static inline void pcmcia_add_pseudo_device(struct pcmcia_socket *s) 589static inline void pcmcia_add_pseudo_device(struct pcmcia_socket *s)
590{ 590{
591 if (!s->pcmcia_state.device_add_pending) { 591 if (!s->pcmcia_state.device_add_pending) {
592 schedule_work(&s->device_add);
593 s->pcmcia_state.device_add_pending = 1; 592 s->pcmcia_state.device_add_pending = 1;
593 schedule_work(&s->device_add);
594 } 594 }
595 return; 595 return;
596} 596}
diff --git a/drivers/pcmcia/o2micro.h b/drivers/pcmcia/o2micro.h
index b1f6e3d9ee06..a234ce1967a3 100644
--- a/drivers/pcmcia/o2micro.h
+++ b/drivers/pcmcia/o2micro.h
@@ -120,11 +120,16 @@
120#define O2_MODE_E_LED_OUT 0x08 120#define O2_MODE_E_LED_OUT 0x08
121#define O2_MODE_E_SKTA_ACTV 0x10 121#define O2_MODE_E_SKTA_ACTV 0x10
122 122
123#define O2_RESERVED1 0x94
124#define O2_RESERVED2 0xD4
125#define O2_RES_READ_PREFETCH 0x02
126#define O2_RES_WRITE_BURST 0x08
127
123static int o2micro_override(struct yenta_socket *socket) 128static int o2micro_override(struct yenta_socket *socket)
124{ 129{
125 /* 130 /*
126 * 'reserved' register at 0x94/D4. chaning it to 0xCA (8 bit) enables 131 * 'reserved' register at 0x94/D4. allows setting read prefetch and write
127 * read prefetching which for example makes the RME Hammerfall DSP 132 * bursting. read prefetching for example makes the RME Hammerfall DSP
128 * working. for some bridges it is at 0x94, for others at 0xD4. it's 133 * working. for some bridges it is at 0x94, for others at 0xD4. it's
129 * ok to write to both registers on all O2 bridges. 134 * ok to write to both registers on all O2 bridges.
130 * from Eric Still, 02Micro. 135 * from Eric Still, 02Micro.
@@ -132,20 +137,35 @@ static int o2micro_override(struct yenta_socket *socket)
132 u8 a, b; 137 u8 a, b;
133 138
134 if (PCI_FUNC(socket->dev->devfn) == 0) { 139 if (PCI_FUNC(socket->dev->devfn) == 0) {
135 a = config_readb(socket, 0x94); 140 a = config_readb(socket, O2_RESERVED1);
136 b = config_readb(socket, 0xD4); 141 b = config_readb(socket, O2_RESERVED2);
137 142
138 printk(KERN_INFO "Yenta O2: res at 0x94/0xD4: %02x/%02x\n", a, b); 143 printk(KERN_INFO "Yenta O2: res at 0x94/0xD4: %02x/%02x\n", a, b);
139 144
140 switch (socket->dev->device) { 145 switch (socket->dev->device) {
146 /*
147 * older bridges have problems with both read prefetch and write
148 * bursting depending on the combination of the chipset, bridge
149 * and the cardbus card. so disable them to be on the safe side.
150 */
151 case PCI_DEVICE_ID_O2_6729:
152 case PCI_DEVICE_ID_O2_6730:
153 case PCI_DEVICE_ID_O2_6812:
141 case PCI_DEVICE_ID_O2_6832: 154 case PCI_DEVICE_ID_O2_6832:
142 printk(KERN_INFO "Yenta O2: old bridge, not enabling read prefetch / write burst\n"); 155 case PCI_DEVICE_ID_O2_6836:
156 printk(KERN_INFO "Yenta O2: old bridge, disabling read prefetch/write burst\n");
157 config_writeb(socket, O2_RESERVED1,
158 a & ~(O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST));
159 config_writeb(socket, O2_RESERVED2,
160 b & ~(O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST));
143 break; 161 break;
144 162
145 default: 163 default:
146 printk(KERN_INFO "Yenta O2: enabling read prefetch/write burst\n"); 164 printk(KERN_INFO "Yenta O2: enabling read prefetch/write burst\n");
147 config_writeb(socket, 0x94, a | 0x0a); 165 config_writeb(socket, O2_RESERVED1,
148 config_writeb(socket, 0xD4, b | 0x0a); 166 a | O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST);
167 config_writeb(socket, O2_RESERVED2,
168 b | O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST);
149 } 169 }
150 } 170 }
151 171
diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c
index 184f4f88b2a0..6f9fdb276402 100644
--- a/drivers/pcmcia/pcmcia_resource.c
+++ b/drivers/pcmcia/pcmcia_resource.c
@@ -800,7 +800,7 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
800 } else { 800 } else {
801 int try; 801 int try;
802 u32 mask = s->irq_mask; 802 u32 mask = s->irq_mask;
803 void *data = NULL; 803 void *data = &p_dev->dev.driver; /* something unique to this device */
804 804
805 for (try = 0; try < 64; try++) { 805 for (try = 0; try < 64; try++) {
806 irq = try % 32; 806 irq = try % 32;
diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c
index 6837491f021c..62fd705203fb 100644
--- a/drivers/pcmcia/yenta_socket.c
+++ b/drivers/pcmcia/yenta_socket.c
@@ -605,9 +605,8 @@ static int yenta_search_res(struct yenta_socket *socket, struct resource *res,
605 605
606static void yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned type, int addr_start, int addr_end) 606static void yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned type, int addr_start, int addr_end)
607{ 607{
608 struct pci_bus *bus;
609 struct resource *root, *res; 608 struct resource *root, *res;
610 u32 start, end; 609 struct pci_bus_region region;
611 unsigned mask; 610 unsigned mask;
612 611
613 res = socket->dev->resource + PCI_BRIDGE_RESOURCES + nr; 612 res = socket->dev->resource + PCI_BRIDGE_RESOURCES + nr;
@@ -620,15 +619,13 @@ static void yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned typ
620 if (type & IORESOURCE_IO) 619 if (type & IORESOURCE_IO)
621 mask = ~3; 620 mask = ~3;
622 621
623 bus = socket->dev->subordinate; 622 res->name = socket->dev->subordinate->name;
624 res->name = bus->name;
625 res->flags = type; 623 res->flags = type;
626 624
627 start = config_readl(socket, addr_start) & mask; 625 region.start = config_readl(socket, addr_start) & mask;
628 end = config_readl(socket, addr_end) | ~mask; 626 region.end = config_readl(socket, addr_end) | ~mask;
629 if (start && end > start && !override_bios) { 627 if (region.start && region.end > region.start && !override_bios) {
630 res->start = start; 628 pcibios_bus_to_resource(socket->dev, res, &region);
631 res->end = end;
632 root = pci_find_parent_resource(socket->dev, res); 629 root = pci_find_parent_resource(socket->dev, res);
633 if (root && (request_resource(root, res) == 0)) 630 if (root && (request_resource(root, res) == 0))
634 return; 631 return;
@@ -642,6 +639,7 @@ static void yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned typ
642 (yenta_search_res(socket, res, BRIDGE_IO_MIN))) { 639 (yenta_search_res(socket, res, BRIDGE_IO_MIN))) {
643 config_writel(socket, addr_start, res->start); 640 config_writel(socket, addr_start, res->start);
644 config_writel(socket, addr_end, res->end); 641 config_writel(socket, addr_end, res->end);
642 return;
645 } 643 }
646 } else { 644 } else {
647 if (type & IORESOURCE_PREFETCH) { 645 if (type & IORESOURCE_PREFETCH) {
@@ -650,6 +648,7 @@ static void yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned typ
650 (yenta_search_res(socket, res, BRIDGE_MEM_MIN))) { 648 (yenta_search_res(socket, res, BRIDGE_MEM_MIN))) {
651 config_writel(socket, addr_start, res->start); 649 config_writel(socket, addr_start, res->start);
652 config_writel(socket, addr_end, res->end); 650 config_writel(socket, addr_end, res->end);
651 return;
653 } 652 }
654 /* Approximating prefetchable by non-prefetchable */ 653 /* Approximating prefetchable by non-prefetchable */
655 res->flags = IORESOURCE_MEM; 654 res->flags = IORESOURCE_MEM;
@@ -659,6 +658,7 @@ static void yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned typ
659 (yenta_search_res(socket, res, BRIDGE_MEM_MIN))) { 658 (yenta_search_res(socket, res, BRIDGE_MEM_MIN))) {
660 config_writel(socket, addr_start, res->start); 659 config_writel(socket, addr_start, res->start);
661 config_writel(socket, addr_end, res->end); 660 config_writel(socket, addr_end, res->end);
661 return;
662 } 662 }
663 } 663 }
664 664
diff --git a/drivers/pnp/pnpbios/rsparser.c b/drivers/pnp/pnpbios/rsparser.c
index 9001b6f0204d..e305bb132c24 100644
--- a/drivers/pnp/pnpbios/rsparser.c
+++ b/drivers/pnp/pnpbios/rsparser.c
@@ -11,7 +11,7 @@
11#ifdef CONFIG_PCI 11#ifdef CONFIG_PCI
12#include <linux/pci.h> 12#include <linux/pci.h>
13#else 13#else
14inline void pcibios_penalize_isa_irq(int irq) {} 14inline void pcibios_penalize_isa_irq(int irq, int active) {}
15#endif /* CONFIG_PCI */ 15#endif /* CONFIG_PCI */
16 16
17#include "pnpbios.h" 17#include "pnpbios.h"
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index 6527ff6f4706..d5f53980749b 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -7,7 +7,7 @@
7 * Bugreports.to..: <Linux390@de.ibm.com> 7 * Bugreports.to..: <Linux390@de.ibm.com>
8 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001 8 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001
9 * 9 *
10 * $Revision: 1.164 $ 10 * $Revision: 1.165 $
11 */ 11 */
12 12
13#include <linux/config.h> 13#include <linux/config.h>
@@ -1740,6 +1740,10 @@ dasd_exit(void)
1740 dasd_proc_exit(); 1740 dasd_proc_exit();
1741#endif 1741#endif
1742 dasd_ioctl_exit(); 1742 dasd_ioctl_exit();
1743 if (dasd_page_cache != NULL) {
1744 kmem_cache_destroy(dasd_page_cache);
1745 dasd_page_cache = NULL;
1746 }
1743 dasd_gendisk_exit(); 1747 dasd_gendisk_exit();
1744 dasd_devmap_exit(); 1748 dasd_devmap_exit();
1745 devfs_remove("dasd"); 1749 devfs_remove("dasd");
diff --git a/drivers/s390/block/dasd_fba.c b/drivers/s390/block/dasd_fba.c
index 7963ae343eef..28cb4613b7f5 100644
--- a/drivers/s390/block/dasd_fba.c
+++ b/drivers/s390/block/dasd_fba.c
@@ -4,7 +4,7 @@
4 * Bugreports.to..: <Linux390@de.ibm.com> 4 * Bugreports.to..: <Linux390@de.ibm.com>
5 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000 5 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000
6 * 6 *
7 * $Revision: 1.39 $ 7 * $Revision: 1.40 $
8 */ 8 */
9 9
10#include <linux/config.h> 10#include <linux/config.h>
@@ -354,6 +354,8 @@ dasd_fba_build_cp(struct dasd_device * device, struct request *req)
354 } 354 }
355 cqr->device = device; 355 cqr->device = device;
356 cqr->expires = 5 * 60 * HZ; /* 5 minutes */ 356 cqr->expires = 5 * 60 * HZ; /* 5 minutes */
357 cqr->retries = 32;
358 cqr->buildclk = get_clock();
357 cqr->status = DASD_CQR_FILLED; 359 cqr->status = DASD_CQR_FILLED;
358 return cqr; 360 return cqr;
359} 361}
diff --git a/drivers/s390/char/tape.h b/drivers/s390/char/tape.h
index d04e6c2c3cc1..01d865d93791 100644
--- a/drivers/s390/char/tape.h
+++ b/drivers/s390/char/tape.h
@@ -3,10 +3,11 @@
3 * tape device driver for 3480/3490E/3590 tapes. 3 * tape device driver for 3480/3490E/3590 tapes.
4 * 4 *
5 * S390 and zSeries version 5 * S390 and zSeries version
6 * Copyright (C) 2001,2002 IBM Deutschland Entwicklung GmbH, IBM Corporation 6 * Copyright (C) 2001,2005 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Carsten Otte <cotte@de.ibm.com> 7 * Author(s): Carsten Otte <cotte@de.ibm.com>
8 * Tuan Ngo-Anh <ngoanh@de.ibm.com> 8 * Tuan Ngo-Anh <ngoanh@de.ibm.com>
9 * Martin Schwidefsky <schwidefsky@de.ibm.com> 9 * Martin Schwidefsky <schwidefsky@de.ibm.com>
10 * Stefan Bader <shbader@de.ibm.com>
10 */ 11 */
11 12
12#ifndef _TAPE_H 13#ifndef _TAPE_H
@@ -111,6 +112,7 @@ enum tape_request_status {
111 TAPE_REQUEST_QUEUED, /* request is queued to be processed */ 112 TAPE_REQUEST_QUEUED, /* request is queued to be processed */
112 TAPE_REQUEST_IN_IO, /* request is currently in IO */ 113 TAPE_REQUEST_IN_IO, /* request is currently in IO */
113 TAPE_REQUEST_DONE, /* request is completed. */ 114 TAPE_REQUEST_DONE, /* request is completed. */
115 TAPE_REQUEST_CANCEL, /* request should be canceled. */
114}; 116};
115 117
116/* Tape CCW request */ 118/* Tape CCW request */
@@ -237,6 +239,9 @@ struct tape_device {
237 /* Block dev frontend data */ 239 /* Block dev frontend data */
238 struct tape_blk_data blk_data; 240 struct tape_blk_data blk_data;
239#endif 241#endif
242
243 /* Function to start or stop the next request later. */
244 struct work_struct tape_dnr;
240}; 245};
241 246
242/* Externals from tape_core.c */ 247/* Externals from tape_core.c */
diff --git a/drivers/s390/char/tape_core.c b/drivers/s390/char/tape_core.c
index 0597aa0e27ee..6c52e8307dc5 100644
--- a/drivers/s390/char/tape_core.c
+++ b/drivers/s390/char/tape_core.c
@@ -3,11 +3,12 @@
3 * basic function of the tape device driver 3 * basic function of the tape device driver
4 * 4 *
5 * S390 and zSeries version 5 * S390 and zSeries version
6 * Copyright (C) 2001,2002 IBM Deutschland Entwicklung GmbH, IBM Corporation 6 * Copyright (C) 2001,2005 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Carsten Otte <cotte@de.ibm.com> 7 * Author(s): Carsten Otte <cotte@de.ibm.com>
8 * Michael Holzheu <holzheu@de.ibm.com> 8 * Michael Holzheu <holzheu@de.ibm.com>
9 * Tuan Ngo-Anh <ngoanh@de.ibm.com> 9 * Tuan Ngo-Anh <ngoanh@de.ibm.com>
10 * Martin Schwidefsky <schwidefsky@de.ibm.com> 10 * Martin Schwidefsky <schwidefsky@de.ibm.com>
11 * Stefan Bader <shbader@de.ibm.com>
11 */ 12 */
12 13
13#include <linux/config.h> 14#include <linux/config.h>
@@ -28,7 +29,7 @@
28#define PRINTK_HEADER "TAPE_CORE: " 29#define PRINTK_HEADER "TAPE_CORE: "
29 30
30static void __tape_do_irq (struct ccw_device *, unsigned long, struct irb *); 31static void __tape_do_irq (struct ccw_device *, unsigned long, struct irb *);
31static void __tape_remove_request(struct tape_device *, struct tape_request *); 32static void tape_delayed_next_request(void * data);
32 33
33/* 34/*
34 * One list to contain all tape devices of all disciplines, so 35 * One list to contain all tape devices of all disciplines, so
@@ -257,7 +258,7 @@ tape_med_state_set(struct tape_device *device, enum tape_medium_state newstate)
257 * Stop running ccw. Has to be called with the device lock held. 258 * Stop running ccw. Has to be called with the device lock held.
258 */ 259 */
259static inline int 260static inline int
260__tape_halt_io(struct tape_device *device, struct tape_request *request) 261__tape_cancel_io(struct tape_device *device, struct tape_request *request)
261{ 262{
262 int retries; 263 int retries;
263 int rc; 264 int rc;
@@ -270,20 +271,23 @@ __tape_halt_io(struct tape_device *device, struct tape_request *request)
270 for (retries = 0; retries < 5; retries++) { 271 for (retries = 0; retries < 5; retries++) {
271 rc = ccw_device_clear(device->cdev, (long) request); 272 rc = ccw_device_clear(device->cdev, (long) request);
272 273
273 if (rc == 0) { /* Termination successful */ 274 switch (rc) {
274 request->rc = -EIO; 275 case 0:
275 request->status = TAPE_REQUEST_DONE; 276 request->status = TAPE_REQUEST_DONE;
276 return 0; 277 return 0;
278 case -EBUSY:
279 request->status = TAPE_REQUEST_CANCEL;
280 schedule_work(&device->tape_dnr);
281 return 0;
282 case -ENODEV:
283 DBF_EXCEPTION(2, "device gone, retry\n");
284 break;
285 case -EIO:
286 DBF_EXCEPTION(2, "I/O error, retry\n");
287 break;
288 default:
289 BUG();
277 } 290 }
278
279 if (rc == -ENODEV)
280 DBF_EXCEPTION(2, "device gone, retry\n");
281 else if (rc == -EIO)
282 DBF_EXCEPTION(2, "I/O error, retry\n");
283 else if (rc == -EBUSY)
284 DBF_EXCEPTION(2, "device busy, retry late\n");
285 else
286 BUG();
287 } 291 }
288 292
289 return rc; 293 return rc;
@@ -473,6 +477,7 @@ tape_alloc_device(void)
473 *device->modeset_byte = 0; 477 *device->modeset_byte = 0;
474 device->first_minor = -1; 478 device->first_minor = -1;
475 atomic_set(&device->ref_count, 1); 479 atomic_set(&device->ref_count, 1);
480 INIT_WORK(&device->tape_dnr, tape_delayed_next_request, device);
476 481
477 return device; 482 return device;
478} 483}
@@ -708,54 +713,119 @@ tape_free_request (struct tape_request * request)
708 kfree(request); 713 kfree(request);
709} 714}
710 715
716static inline int
717__tape_start_io(struct tape_device *device, struct tape_request *request)
718{
719 int rc;
720
721#ifdef CONFIG_S390_TAPE_BLOCK
722 if (request->op == TO_BLOCK)
723 device->discipline->check_locate(device, request);
724#endif
725 rc = ccw_device_start(
726 device->cdev,
727 request->cpaddr,
728 (unsigned long) request,
729 0x00,
730 request->options
731 );
732 if (rc == 0) {
733 request->status = TAPE_REQUEST_IN_IO;
734 } else if (rc == -EBUSY) {
735 /* The common I/O subsystem is currently busy. Retry later. */
736 request->status = TAPE_REQUEST_QUEUED;
737 schedule_work(&device->tape_dnr);
738 rc = 0;
739 } else {
740 /* Start failed. Remove request and indicate failure. */
741 DBF_EVENT(1, "tape: start request failed with RC = %i\n", rc);
742 }
743 return rc;
744}
745
711static inline void 746static inline void
712__tape_do_io_list(struct tape_device *device) 747__tape_start_next_request(struct tape_device *device)
713{ 748{
714 struct list_head *l, *n; 749 struct list_head *l, *n;
715 struct tape_request *request; 750 struct tape_request *request;
716 int rc; 751 int rc;
717 752
718 DBF_LH(6, "__tape_do_io_list(%p)\n", device); 753 DBF_LH(6, "__tape_start_next_request(%p)\n", device);
719 /* 754 /*
720 * Try to start each request on request queue until one is 755 * Try to start each request on request queue until one is
721 * started successful. 756 * started successful.
722 */ 757 */
723 list_for_each_safe(l, n, &device->req_queue) { 758 list_for_each_safe(l, n, &device->req_queue) {
724 request = list_entry(l, struct tape_request, list); 759 request = list_entry(l, struct tape_request, list);
725#ifdef CONFIG_S390_TAPE_BLOCK 760
726 if (request->op == TO_BLOCK) 761 /*
727 device->discipline->check_locate(device, request); 762 * Avoid race condition if bottom-half was triggered more than
728#endif 763 * once.
729 rc = ccw_device_start(device->cdev, request->cpaddr, 764 */
730 (unsigned long) request, 0x00, 765 if (request->status == TAPE_REQUEST_IN_IO)
731 request->options); 766 return;
732 if (rc == 0) { 767
733 request->status = TAPE_REQUEST_IN_IO; 768 /*
734 break; 769 * We wanted to cancel the request but the common I/O layer
770 * was busy at that time. This can only happen if this
771 * function is called by delayed_next_request.
772 * Otherwise we start the next request on the queue.
773 */
774 if (request->status == TAPE_REQUEST_CANCEL) {
775 rc = __tape_cancel_io(device, request);
776 } else {
777 rc = __tape_start_io(device, request);
735 } 778 }
736 /* Start failed. Remove request and indicate failure. */ 779 if (rc == 0)
737 DBF_EVENT(1, "tape: DOIO failed with er = %i\n", rc); 780 return;
738 781
739 /* Set ending status and do callback. */ 782 /* Set ending status. */
740 request->rc = rc; 783 request->rc = rc;
741 request->status = TAPE_REQUEST_DONE; 784 request->status = TAPE_REQUEST_DONE;
742 __tape_remove_request(device, request); 785
786 /* Remove from request queue. */
787 list_del(&request->list);
788
789 /* Do callback. */
790 if (request->callback != NULL)
791 request->callback(request, request->callback_data);
743 } 792 }
744} 793}
745 794
746static void 795static void
747__tape_remove_request(struct tape_device *device, struct tape_request *request) 796tape_delayed_next_request(void *data)
748{ 797{
749 /* Remove from request queue. */ 798 struct tape_device * device;
750 list_del(&request->list);
751 799
752 /* Do callback. */ 800 device = (struct tape_device *) data;
753 if (request->callback != NULL) 801 DBF_LH(6, "tape_delayed_next_request(%p)\n", device);
754 request->callback(request, request->callback_data); 802 spin_lock_irq(get_ccwdev_lock(device->cdev));
803 __tape_start_next_request(device);
804 spin_unlock_irq(get_ccwdev_lock(device->cdev));
805}
806
807static inline void
808__tape_end_request(
809 struct tape_device * device,
810 struct tape_request * request,
811 int rc)
812{
813 DBF_LH(6, "__tape_end_request(%p, %p, %i)\n", device, request, rc);
814 if (request) {
815 request->rc = rc;
816 request->status = TAPE_REQUEST_DONE;
817
818 /* Remove from request queue. */
819 list_del(&request->list);
820
821 /* Do callback. */
822 if (request->callback != NULL)
823 request->callback(request, request->callback_data);
824 }
755 825
756 /* Start next request. */ 826 /* Start next request. */
757 if (!list_empty(&device->req_queue)) 827 if (!list_empty(&device->req_queue))
758 __tape_do_io_list(device); 828 __tape_start_next_request(device);
759} 829}
760 830
761/* 831/*
@@ -812,7 +882,7 @@ tape_dump_sense_dbf(struct tape_device *device, struct tape_request *request,
812 * the device lock held. 882 * the device lock held.
813 */ 883 */
814static inline int 884static inline int
815__tape_do_io(struct tape_device *device, struct tape_request *request) 885__tape_start_request(struct tape_device *device, struct tape_request *request)
816{ 886{
817 int rc; 887 int rc;
818 888
@@ -837,24 +907,16 @@ __tape_do_io(struct tape_device *device, struct tape_request *request)
837 907
838 if (list_empty(&device->req_queue)) { 908 if (list_empty(&device->req_queue)) {
839 /* No other requests are on the queue. Start this one. */ 909 /* No other requests are on the queue. Start this one. */
840#ifdef CONFIG_S390_TAPE_BLOCK 910 rc = __tape_start_io(device, request);
841 if (request->op == TO_BLOCK) 911 if (rc)
842 device->discipline->check_locate(device, request);
843#endif
844 rc = ccw_device_start(device->cdev, request->cpaddr,
845 (unsigned long) request, 0x00,
846 request->options);
847 if (rc) {
848 DBF_EVENT(1, "tape: DOIO failed with rc = %i\n", rc);
849 return rc; 912 return rc;
850 } 913
851 DBF_LH(5, "Request %p added for execution.\n", request); 914 DBF_LH(5, "Request %p added for execution.\n", request);
852 list_add(&request->list, &device->req_queue); 915 list_add(&request->list, &device->req_queue);
853 request->status = TAPE_REQUEST_IN_IO;
854 } else { 916 } else {
855 DBF_LH(5, "Request %p add to queue.\n", request); 917 DBF_LH(5, "Request %p add to queue.\n", request);
856 list_add_tail(&request->list, &device->req_queue);
857 request->status = TAPE_REQUEST_QUEUED; 918 request->status = TAPE_REQUEST_QUEUED;
919 list_add_tail(&request->list, &device->req_queue);
858 } 920 }
859 return 0; 921 return 0;
860} 922}
@@ -872,7 +934,7 @@ tape_do_io_async(struct tape_device *device, struct tape_request *request)
872 934
873 spin_lock_irq(get_ccwdev_lock(device->cdev)); 935 spin_lock_irq(get_ccwdev_lock(device->cdev));
874 /* Add request to request queue and try to start it. */ 936 /* Add request to request queue and try to start it. */
875 rc = __tape_do_io(device, request); 937 rc = __tape_start_request(device, request);
876 spin_unlock_irq(get_ccwdev_lock(device->cdev)); 938 spin_unlock_irq(get_ccwdev_lock(device->cdev));
877 return rc; 939 return rc;
878} 940}
@@ -901,7 +963,7 @@ tape_do_io(struct tape_device *device, struct tape_request *request)
901 request->callback = __tape_wake_up; 963 request->callback = __tape_wake_up;
902 request->callback_data = &wq; 964 request->callback_data = &wq;
903 /* Add request to request queue and try to start it. */ 965 /* Add request to request queue and try to start it. */
904 rc = __tape_do_io(device, request); 966 rc = __tape_start_request(device, request);
905 spin_unlock_irq(get_ccwdev_lock(device->cdev)); 967 spin_unlock_irq(get_ccwdev_lock(device->cdev));
906 if (rc) 968 if (rc)
907 return rc; 969 return rc;
@@ -935,7 +997,7 @@ tape_do_io_interruptible(struct tape_device *device,
935 /* Setup callback */ 997 /* Setup callback */
936 request->callback = __tape_wake_up_interruptible; 998 request->callback = __tape_wake_up_interruptible;
937 request->callback_data = &wq; 999 request->callback_data = &wq;
938 rc = __tape_do_io(device, request); 1000 rc = __tape_start_request(device, request);
939 spin_unlock_irq(get_ccwdev_lock(device->cdev)); 1001 spin_unlock_irq(get_ccwdev_lock(device->cdev));
940 if (rc) 1002 if (rc)
941 return rc; 1003 return rc;
@@ -944,36 +1006,27 @@ tape_do_io_interruptible(struct tape_device *device,
944 if (rc != -ERESTARTSYS) 1006 if (rc != -ERESTARTSYS)
945 /* Request finished normally. */ 1007 /* Request finished normally. */
946 return request->rc; 1008 return request->rc;
1009
947 /* Interrupted by a signal. We have to stop the current request. */ 1010 /* Interrupted by a signal. We have to stop the current request. */
948 spin_lock_irq(get_ccwdev_lock(device->cdev)); 1011 spin_lock_irq(get_ccwdev_lock(device->cdev));
949 rc = __tape_halt_io(device, request); 1012 rc = __tape_cancel_io(device, request);
1013 spin_unlock_irq(get_ccwdev_lock(device->cdev));
950 if (rc == 0) { 1014 if (rc == 0) {
1015 /* Wait for the interrupt that acknowledges the halt. */
1016 do {
1017 rc = wait_event_interruptible(
1018 wq,
1019 (request->callback == NULL)
1020 );
1021 } while (rc != -ERESTARTSYS);
1022
951 DBF_EVENT(3, "IO stopped on %08x\n", device->cdev_id); 1023 DBF_EVENT(3, "IO stopped on %08x\n", device->cdev_id);
952 rc = -ERESTARTSYS; 1024 rc = -ERESTARTSYS;
953 } 1025 }
954 spin_unlock_irq(get_ccwdev_lock(device->cdev));
955 return rc; 1026 return rc;
956} 1027}
957 1028
958/* 1029/*
959 * Handle requests that return an i/o error in the irb.
960 */
961static inline void
962tape_handle_killed_request(
963 struct tape_device *device,
964 struct tape_request *request)
965{
966 if(request != NULL) {
967 /* Set ending status. FIXME: Should the request be retried? */
968 request->rc = -EIO;
969 request->status = TAPE_REQUEST_DONE;
970 __tape_remove_request(device, request);
971 } else {
972 __tape_do_io_list(device);
973 }
974}
975
976/*
977 * Tape interrupt routine, called from the ccw_device layer 1030 * Tape interrupt routine, called from the ccw_device layer
978 */ 1031 */
979static void 1032static void
@@ -981,7 +1034,6 @@ __tape_do_irq (struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
981{ 1034{
982 struct tape_device *device; 1035 struct tape_device *device;
983 struct tape_request *request; 1036 struct tape_request *request;
984 int final;
985 int rc; 1037 int rc;
986 1038
987 device = (struct tape_device *) cdev->dev.driver_data; 1039 device = (struct tape_device *) cdev->dev.driver_data;
@@ -996,12 +1048,13 @@ __tape_do_irq (struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
996 1048
997 /* On special conditions irb is an error pointer */ 1049 /* On special conditions irb is an error pointer */
998 if (IS_ERR(irb)) { 1050 if (IS_ERR(irb)) {
1051 /* FIXME: What to do with the request? */
999 switch (PTR_ERR(irb)) { 1052 switch (PTR_ERR(irb)) {
1000 case -ETIMEDOUT: 1053 case -ETIMEDOUT:
1001 PRINT_WARN("(%s): Request timed out\n", 1054 PRINT_WARN("(%s): Request timed out\n",
1002 cdev->dev.bus_id); 1055 cdev->dev.bus_id);
1003 case -EIO: 1056 case -EIO:
1004 tape_handle_killed_request(device, request); 1057 __tape_end_request(device, request, -EIO);
1005 break; 1058 break;
1006 default: 1059 default:
1007 PRINT_ERR("(%s): Unexpected i/o error %li\n", 1060 PRINT_ERR("(%s): Unexpected i/o error %li\n",
@@ -1011,6 +1064,21 @@ __tape_do_irq (struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
1011 return; 1064 return;
1012 } 1065 }
1013 1066
1067 /*
1068 * If the condition code is not zero and the start function bit is
1069 * still set, this is an deferred error and the last start I/O did
1070 * not succeed. Restart the request now.
1071 */
1072 if (irb->scsw.cc != 0 && (irb->scsw.fctl & SCSW_FCTL_START_FUNC)) {
1073 PRINT_WARN("(%s): deferred cc=%i. restaring\n",
1074 cdev->dev.bus_id,
1075 irb->scsw.cc);
1076 rc = __tape_start_io(device, request);
1077 if (rc)
1078 __tape_end_request(device, request, rc);
1079 return;
1080 }
1081
1014 /* May be an unsolicited irq */ 1082 /* May be an unsolicited irq */
1015 if(request != NULL) 1083 if(request != NULL)
1016 request->rescnt = irb->scsw.count; 1084 request->rescnt = irb->scsw.count;
@@ -1042,7 +1110,7 @@ __tape_do_irq (struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
1042 * To detect these request the state will be set to TAPE_REQUEST_DONE. 1110 * To detect these request the state will be set to TAPE_REQUEST_DONE.
1043 */ 1111 */
1044 if(request != NULL && request->status == TAPE_REQUEST_DONE) { 1112 if(request != NULL && request->status == TAPE_REQUEST_DONE) {
1045 __tape_remove_request(device, request); 1113 __tape_end_request(device, request, -EIO);
1046 return; 1114 return;
1047 } 1115 }
1048 1116
@@ -1054,51 +1122,34 @@ __tape_do_irq (struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
1054 * rc == TAPE_IO_RETRY: request finished but needs another go. 1122 * rc == TAPE_IO_RETRY: request finished but needs another go.
1055 * rc == TAPE_IO_STOP: request needs to get terminated. 1123 * rc == TAPE_IO_STOP: request needs to get terminated.
1056 */ 1124 */
1057 final = 0;
1058 switch (rc) { 1125 switch (rc) {
1059 case TAPE_IO_SUCCESS: 1126 case TAPE_IO_SUCCESS:
1060 /* Upon normal completion the device _is_ online */ 1127 /* Upon normal completion the device _is_ online */
1061 device->tape_generic_status |= GMT_ONLINE(~0); 1128 device->tape_generic_status |= GMT_ONLINE(~0);
1062 final = 1; 1129 __tape_end_request(device, request, rc);
1063 break; 1130 break;
1064 case TAPE_IO_PENDING: 1131 case TAPE_IO_PENDING:
1065 break; 1132 break;
1066 case TAPE_IO_RETRY: 1133 case TAPE_IO_RETRY:
1067#ifdef CONFIG_S390_TAPE_BLOCK 1134 rc = __tape_start_io(device, request);
1068 if (request->op == TO_BLOCK) 1135 if (rc)
1069 device->discipline->check_locate(device, request); 1136 __tape_end_request(device, request, rc);
1070#endif 1137 break;
1071 rc = ccw_device_start(cdev, request->cpaddr, 1138 case TAPE_IO_STOP:
1072 (unsigned long) request, 0x00, 1139 rc = __tape_cancel_io(device, request);
1073 request->options); 1140 if (rc)
1074 if (rc) { 1141 __tape_end_request(device, request, rc);
1075 DBF_EVENT(1, "tape: DOIO failed with er = %i\n", rc); 1142 break;
1076 final = 1; 1143 default:
1077 } 1144 if (rc > 0) {
1078 break; 1145 DBF_EVENT(6, "xunknownrc\n");
1079 case TAPE_IO_STOP: 1146 PRINT_ERR("Invalid return code from discipline "
1080 __tape_halt_io(device, request); 1147 "interrupt function.\n");
1081 break; 1148 __tape_end_request(device, request, -EIO);
1082 default: 1149 } else {
1083 if (rc > 0) { 1150 __tape_end_request(device, request, rc);
1084 DBF_EVENT(6, "xunknownrc\n"); 1151 }
1085 PRINT_ERR("Invalid return code from discipline " 1152 break;
1086 "interrupt function.\n");
1087 rc = -EIO;
1088 }
1089 final = 1;
1090 break;
1091 }
1092 if (final) {
1093 /* May be an unsolicited irq */
1094 if(request != NULL) {
1095 /* Set ending status. */
1096 request->rc = rc;
1097 request->status = TAPE_REQUEST_DONE;
1098 __tape_remove_request(device, request);
1099 } else {
1100 __tape_do_io_list(device);
1101 }
1102 } 1153 }
1103} 1154}
1104 1155
@@ -1191,7 +1242,7 @@ tape_init (void)
1191#ifdef DBF_LIKE_HELL 1242#ifdef DBF_LIKE_HELL
1192 debug_set_level(TAPE_DBF_AREA, 6); 1243 debug_set_level(TAPE_DBF_AREA, 6);
1193#endif 1244#endif
1194 DBF_EVENT(3, "tape init: ($Revision: 1.51 $)\n"); 1245 DBF_EVENT(3, "tape init: ($Revision: 1.54 $)\n");
1195 tape_proc_init(); 1246 tape_proc_init();
1196 tapechar_init (); 1247 tapechar_init ();
1197 tapeblock_init (); 1248 tapeblock_init ();
@@ -1216,7 +1267,7 @@ tape_exit(void)
1216MODULE_AUTHOR("(C) 2001 IBM Deutschland Entwicklung GmbH by Carsten Otte and " 1267MODULE_AUTHOR("(C) 2001 IBM Deutschland Entwicklung GmbH by Carsten Otte and "
1217 "Michael Holzheu (cotte@de.ibm.com,holzheu@de.ibm.com)"); 1268 "Michael Holzheu (cotte@de.ibm.com,holzheu@de.ibm.com)");
1218MODULE_DESCRIPTION("Linux on zSeries channel attached " 1269MODULE_DESCRIPTION("Linux on zSeries channel attached "
1219 "tape device driver ($Revision: 1.51 $)"); 1270 "tape device driver ($Revision: 1.54 $)");
1220MODULE_LICENSE("GPL"); 1271MODULE_LICENSE("GPL");
1221 1272
1222module_init(tape_init); 1273module_init(tape_init);
diff --git a/drivers/s390/char/vmcp.c b/drivers/s390/char/vmcp.c
index 7f11a608a633..8990d8076e7d 100644
--- a/drivers/s390/char/vmcp.c
+++ b/drivers/s390/char/vmcp.c
@@ -115,9 +115,9 @@ vmcp_write(struct file *file, const char __user * buff, size_t count,
115 return -ENOMEM; 115 return -ENOMEM;
116 } 116 }
117 debug_text_event(vmcp_debug, 1, cmd); 117 debug_text_event(vmcp_debug, 1, cmd);
118 session->resp_size = cpcmd(cmd, session->response, 118 session->resp_size = __cpcmd(cmd, session->response,
119 session->bufsize, 119 session->bufsize,
120 &session->resp_code); 120 &session->resp_code);
121 up(&session->mutex); 121 up(&session->mutex);
122 kfree(cmd); 122 kfree(cmd);
123 *ppos = 0; /* reset the file pointer after a command */ 123 *ppos = 0; /* reset the file pointer after a command */
diff --git a/drivers/s390/char/vmwatchdog.c b/drivers/s390/char/vmwatchdog.c
index 22cf4fec8da9..5473c23fcb52 100644
--- a/drivers/s390/char/vmwatchdog.c
+++ b/drivers/s390/char/vmwatchdog.c
@@ -23,11 +23,7 @@
23static char vmwdt_cmd[MAX_CMDLEN] = "IPL"; 23static char vmwdt_cmd[MAX_CMDLEN] = "IPL";
24static int vmwdt_conceal; 24static int vmwdt_conceal;
25 25
26#ifdef CONFIG_WATCHDOG_NOWAYOUT 26static int vmwdt_nowayout = WATCHDOG_NOWAYOUT;
27static int vmwdt_nowayout = 1;
28#else
29static int vmwdt_nowayout = 0;
30#endif
31 27
32MODULE_LICENSE("GPL"); 28MODULE_LICENSE("GPL");
33MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>"); 29MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");
diff --git a/drivers/s390/cio/chsc.c b/drivers/s390/cio/chsc.c
index b86f94ecd874..fa3c23b80e3a 100644
--- a/drivers/s390/cio/chsc.c
+++ b/drivers/s390/cio/chsc.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * drivers/s390/cio/chsc.c 2 * drivers/s390/cio/chsc.c
3 * S/390 common I/O routines -- channel subsystem call 3 * S/390 common I/O routines -- channel subsystem call
4 * $Revision: 1.119 $ 4 * $Revision: 1.120 $
5 * 5 *
6 * Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH, 6 * Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH,
7 * IBM Corporation 7 * IBM Corporation
@@ -412,11 +412,7 @@ s390_process_res_acc (u8 chpid, __u16 fla, u32 fla_mask)
412 if (chp_mask == 0) { 412 if (chp_mask == 0) {
413 413
414 spin_unlock_irq(&sch->lock); 414 spin_unlock_irq(&sch->lock);
415 415 continue;
416 if (fla_mask != 0)
417 break;
418 else
419 continue;
420 } 416 }
421 old_lpm = sch->lpm; 417 old_lpm = sch->lpm;
422 sch->lpm = ((sch->schib.pmcw.pim & 418 sch->lpm = ((sch->schib.pmcw.pim &
@@ -430,7 +426,7 @@ s390_process_res_acc (u8 chpid, __u16 fla, u32 fla_mask)
430 426
431 spin_unlock_irq(&sch->lock); 427 spin_unlock_irq(&sch->lock);
432 put_device(&sch->dev); 428 put_device(&sch->dev);
433 if (fla_mask != 0) 429 if (fla_mask == 0xffff)
434 break; 430 break;
435 } 431 }
436 return rc; 432 return rc;
diff --git a/drivers/s390/cio/device_fsm.c b/drivers/s390/cio/device_fsm.c
index 9b7f6f548b1d..ee7a05e0c3ba 100644
--- a/drivers/s390/cio/device_fsm.c
+++ b/drivers/s390/cio/device_fsm.c
@@ -235,6 +235,9 @@ ccw_device_recog_done(struct ccw_device *cdev, int state)
235 sch->schib.pmcw.pam & 235 sch->schib.pmcw.pam &
236 sch->schib.pmcw.pom & 236 sch->schib.pmcw.pom &
237 sch->opm; 237 sch->opm;
238 /* Check since device may again have become not operational. */
239 if (!sch->schib.pmcw.dnv)
240 state = DEV_STATE_NOT_OPER;
238 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID) 241 if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID)
239 /* Force reprobe on all chpids. */ 242 /* Force reprobe on all chpids. */
240 old_lpm = 0; 243 old_lpm = 0;
diff --git a/drivers/s390/cio/device_status.c b/drivers/s390/cio/device_status.c
index 4ab2e0d95009..12a24d4331a2 100644
--- a/drivers/s390/cio/device_status.c
+++ b/drivers/s390/cio/device_status.c
@@ -39,15 +39,14 @@ ccw_device_msg_control_check(struct ccw_device *cdev, struct irb *irb)
39 " ... device %04X on subchannel %04X, dev_stat " 39 " ... device %04X on subchannel %04X, dev_stat "
40 ": %02X sch_stat : %02X\n", 40 ": %02X sch_stat : %02X\n",
41 cdev->private->devno, cdev->private->irq, 41 cdev->private->devno, cdev->private->irq,
42 cdev->private->irb.scsw.dstat, 42 irb->scsw.dstat, irb->scsw.cstat);
43 cdev->private->irb.scsw.cstat);
44 43
45 if (irb->scsw.cc != 3) { 44 if (irb->scsw.cc != 3) {
46 char dbf_text[15]; 45 char dbf_text[15];
47 46
48 sprintf(dbf_text, "chk%x", cdev->private->irq); 47 sprintf(dbf_text, "chk%x", cdev->private->irq);
49 CIO_TRACE_EVENT(0, dbf_text); 48 CIO_TRACE_EVENT(0, dbf_text);
50 CIO_HEX_EVENT(0, &cdev->private->irb, sizeof (struct irb)); 49 CIO_HEX_EVENT(0, irb, sizeof (struct irb));
51 } 50 }
52} 51}
53 52
diff --git a/drivers/s390/cio/qdio.c b/drivers/s390/cio/qdio.c
index 82194c4eadfb..d36258d6665f 100644
--- a/drivers/s390/cio/qdio.c
+++ b/drivers/s390/cio/qdio.c
@@ -432,7 +432,7 @@ tiqdio_clear_global_summary(void)
432 432
433/************************* OUTBOUND ROUTINES *******************************/ 433/************************* OUTBOUND ROUTINES *******************************/
434 434
435inline static int 435static inline int
436qdio_get_outbound_buffer_frontier(struct qdio_q *q) 436qdio_get_outbound_buffer_frontier(struct qdio_q *q)
437{ 437{
438 int f,f_mod_no; 438 int f,f_mod_no;
@@ -510,7 +510,7 @@ out:
510} 510}
511 511
512/* all buffers are processed */ 512/* all buffers are processed */
513inline static int 513static inline int
514qdio_is_outbound_q_done(struct qdio_q *q) 514qdio_is_outbound_q_done(struct qdio_q *q)
515{ 515{
516 int no_used; 516 int no_used;
@@ -532,7 +532,7 @@ qdio_is_outbound_q_done(struct qdio_q *q)
532 return (no_used==0); 532 return (no_used==0);
533} 533}
534 534
535inline static int 535static inline int
536qdio_has_outbound_q_moved(struct qdio_q *q) 536qdio_has_outbound_q_moved(struct qdio_q *q)
537{ 537{
538 int i; 538 int i;
@@ -552,7 +552,7 @@ qdio_has_outbound_q_moved(struct qdio_q *q)
552 } 552 }
553} 553}
554 554
555inline static void 555static inline void
556qdio_kick_outbound_q(struct qdio_q *q) 556qdio_kick_outbound_q(struct qdio_q *q)
557{ 557{
558 int result; 558 int result;
@@ -641,7 +641,7 @@ qdio_kick_outbound_q(struct qdio_q *q)
641 } 641 }
642} 642}
643 643
644inline static void 644static inline void
645qdio_kick_outbound_handler(struct qdio_q *q) 645qdio_kick_outbound_handler(struct qdio_q *q)
646{ 646{
647 int start, end, real_end, count; 647 int start, end, real_end, count;
@@ -740,7 +740,7 @@ qdio_outbound_processing(struct qdio_q *q)
740/************************* INBOUND ROUTINES *******************************/ 740/************************* INBOUND ROUTINES *******************************/
741 741
742 742
743inline static int 743static inline int
744qdio_get_inbound_buffer_frontier(struct qdio_q *q) 744qdio_get_inbound_buffer_frontier(struct qdio_q *q)
745{ 745{
746 int f,f_mod_no; 746 int f,f_mod_no;
@@ -865,7 +865,7 @@ out:
865 return q->first_to_check; 865 return q->first_to_check;
866} 866}
867 867
868inline static int 868static inline int
869qdio_has_inbound_q_moved(struct qdio_q *q) 869qdio_has_inbound_q_moved(struct qdio_q *q)
870{ 870{
871 int i; 871 int i;
@@ -898,7 +898,7 @@ qdio_has_inbound_q_moved(struct qdio_q *q)
898} 898}
899 899
900/* means, no more buffers to be filled */ 900/* means, no more buffers to be filled */
901inline static int 901static inline int
902tiqdio_is_inbound_q_done(struct qdio_q *q) 902tiqdio_is_inbound_q_done(struct qdio_q *q)
903{ 903{
904 int no_used; 904 int no_used;
@@ -951,7 +951,7 @@ tiqdio_is_inbound_q_done(struct qdio_q *q)
951 return 0; 951 return 0;
952} 952}
953 953
954inline static int 954static inline int
955qdio_is_inbound_q_done(struct qdio_q *q) 955qdio_is_inbound_q_done(struct qdio_q *q)
956{ 956{
957 int no_used; 957 int no_used;
@@ -1010,7 +1010,7 @@ qdio_is_inbound_q_done(struct qdio_q *q)
1010 } 1010 }
1011} 1011}
1012 1012
1013inline static void 1013static inline void
1014qdio_kick_inbound_handler(struct qdio_q *q) 1014qdio_kick_inbound_handler(struct qdio_q *q)
1015{ 1015{
1016 int count, start, end, real_end, i; 1016 int count, start, end, real_end, i;
diff --git a/drivers/s390/net/qeth.h b/drivers/s390/net/qeth.h
index 008e0a5d2eb3..3a0285669adf 100644
--- a/drivers/s390/net/qeth.h
+++ b/drivers/s390/net/qeth.h
@@ -824,7 +824,7 @@ extern struct list_head qeth_notify_list;
824 824
825#define QETH_CARD_IFNAME(card) (((card)->dev)? (card)->dev->name : "") 825#define QETH_CARD_IFNAME(card) (((card)->dev)? (card)->dev->name : "")
826 826
827inline static __u8 827static inline __u8
828qeth_get_ipa_adp_type(enum qeth_link_types link_type) 828qeth_get_ipa_adp_type(enum qeth_link_types link_type)
829{ 829{
830 switch (link_type) { 830 switch (link_type) {
@@ -835,7 +835,7 @@ qeth_get_ipa_adp_type(enum qeth_link_types link_type)
835 } 835 }
836} 836}
837 837
838inline static int 838static inline int
839qeth_realloc_headroom(struct qeth_card *card, struct sk_buff **skb, int size) 839qeth_realloc_headroom(struct qeth_card *card, struct sk_buff **skb, int size)
840{ 840{
841 struct sk_buff *new_skb = NULL; 841 struct sk_buff *new_skb = NULL;
@@ -852,6 +852,7 @@ qeth_realloc_headroom(struct qeth_card *card, struct sk_buff **skb, int size)
852 } 852 }
853 return 0; 853 return 0;
854} 854}
855
855static inline struct sk_buff * 856static inline struct sk_buff *
856qeth_pskb_unshare(struct sk_buff *skb, int pri) 857qeth_pskb_unshare(struct sk_buff *skb, int pri)
857{ 858{
@@ -863,8 +864,7 @@ qeth_pskb_unshare(struct sk_buff *skb, int pri)
863 return nskb; 864 return nskb;
864} 865}
865 866
866 867static inline void *
867inline static void *
868qeth_push_skb(struct qeth_card *card, struct sk_buff **skb, int size) 868qeth_push_skb(struct qeth_card *card, struct sk_buff **skb, int size)
869{ 869{
870 void *hdr; 870 void *hdr;
@@ -887,7 +887,7 @@ qeth_push_skb(struct qeth_card *card, struct sk_buff **skb, int size)
887} 887}
888 888
889 889
890inline static int 890static inline int
891qeth_get_hlen(__u8 link_type) 891qeth_get_hlen(__u8 link_type)
892{ 892{
893#ifdef CONFIG_QETH_IPV6 893#ifdef CONFIG_QETH_IPV6
@@ -911,7 +911,7 @@ qeth_get_hlen(__u8 link_type)
911#endif /* CONFIG_QETH_IPV6 */ 911#endif /* CONFIG_QETH_IPV6 */
912} 912}
913 913
914inline static unsigned short 914static inline unsigned short
915qeth_get_netdev_flags(struct qeth_card *card) 915qeth_get_netdev_flags(struct qeth_card *card)
916{ 916{
917 if (card->options.layer2) 917 if (card->options.layer2)
@@ -929,7 +929,7 @@ qeth_get_netdev_flags(struct qeth_card *card)
929 } 929 }
930} 930}
931 931
932inline static int 932static inline int
933qeth_get_initial_mtu_for_card(struct qeth_card * card) 933qeth_get_initial_mtu_for_card(struct qeth_card * card)
934{ 934{
935 switch (card->info.type) { 935 switch (card->info.type) {
@@ -950,7 +950,7 @@ qeth_get_initial_mtu_for_card(struct qeth_card * card)
950 } 950 }
951} 951}
952 952
953inline static int 953static inline int
954qeth_get_max_mtu_for_card(int cardtype) 954qeth_get_max_mtu_for_card(int cardtype)
955{ 955{
956 switch (cardtype) { 956 switch (cardtype) {
@@ -965,7 +965,7 @@ qeth_get_max_mtu_for_card(int cardtype)
965 } 965 }
966} 966}
967 967
968inline static int 968static inline int
969qeth_get_mtu_out_of_mpc(int cardtype) 969qeth_get_mtu_out_of_mpc(int cardtype)
970{ 970{
971 switch (cardtype) { 971 switch (cardtype) {
@@ -976,7 +976,7 @@ qeth_get_mtu_out_of_mpc(int cardtype)
976 } 976 }
977} 977}
978 978
979inline static int 979static inline int
980qeth_get_mtu_outof_framesize(int framesize) 980qeth_get_mtu_outof_framesize(int framesize)
981{ 981{
982 switch (framesize) { 982 switch (framesize) {
@@ -993,7 +993,7 @@ qeth_get_mtu_outof_framesize(int framesize)
993 } 993 }
994} 994}
995 995
996inline static int 996static inline int
997qeth_mtu_is_valid(struct qeth_card * card, int mtu) 997qeth_mtu_is_valid(struct qeth_card * card, int mtu)
998{ 998{
999 switch (card->info.type) { 999 switch (card->info.type) {
@@ -1008,7 +1008,7 @@ qeth_mtu_is_valid(struct qeth_card * card, int mtu)
1008 } 1008 }
1009} 1009}
1010 1010
1011inline static int 1011static inline int
1012qeth_get_arphdr_type(int cardtype, int linktype) 1012qeth_get_arphdr_type(int cardtype, int linktype)
1013{ 1013{
1014 switch (cardtype) { 1014 switch (cardtype) {
@@ -1027,7 +1027,7 @@ qeth_get_arphdr_type(int cardtype, int linktype)
1027} 1027}
1028 1028
1029#ifdef CONFIG_QETH_PERF_STATS 1029#ifdef CONFIG_QETH_PERF_STATS
1030inline static int 1030static inline int
1031qeth_get_micros(void) 1031qeth_get_micros(void)
1032{ 1032{
1033 return (int) (get_clock() >> 12); 1033 return (int) (get_clock() >> 12);
diff --git a/drivers/s390/net/qeth_main.c b/drivers/s390/net/qeth_main.c
index 8f4d2999af8e..79c74f3a11f5 100644
--- a/drivers/s390/net/qeth_main.c
+++ b/drivers/s390/net/qeth_main.c
@@ -8120,20 +8120,22 @@ static struct notifier_block qeth_ip6_notifier = {
8120#endif 8120#endif
8121 8121
8122static int 8122static int
8123qeth_reboot_event(struct notifier_block *this, unsigned long event, void *ptr) 8123__qeth_reboot_event_card(struct device *dev, void *data)
8124{ 8124{
8125
8126 struct device *entry;
8127 struct qeth_card *card; 8125 struct qeth_card *card;
8128 8126
8129 down_read(&qeth_ccwgroup_driver.driver.bus->subsys.rwsem); 8127 card = (struct qeth_card *) dev->driver_data;
8130 list_for_each_entry(entry, &qeth_ccwgroup_driver.driver.devices, 8128 qeth_clear_ip_list(card, 0, 0);
8131 driver_list) { 8129 qeth_qdio_clear_card(card, 0);
8132 card = (struct qeth_card *) entry->driver_data; 8130 return 0;
8133 qeth_clear_ip_list(card, 0, 0); 8131}
8134 qeth_qdio_clear_card(card, 0); 8132
8135 } 8133static int
8136 up_read(&qeth_ccwgroup_driver.driver.bus->subsys.rwsem); 8134qeth_reboot_event(struct notifier_block *this, unsigned long event, void *ptr)
8135{
8136
8137 driver_for_each_device(&qeth_ccwgroup_driver.driver, NULL, NULL,
8138 __qeth_reboot_event_card);
8137 return NOTIFY_DONE; 8139 return NOTIFY_DONE;
8138} 8140}
8139 8141
diff --git a/drivers/s390/net/qeth_proc.c b/drivers/s390/net/qeth_proc.c
index 04719196fd20..f2ccfea8fdb8 100644
--- a/drivers/s390/net/qeth_proc.c
+++ b/drivers/s390/net/qeth_proc.c
@@ -27,23 +27,33 @@ const char *VERSION_QETH_PROC_C = "$Revision: 1.13 $";
27#define QETH_PROCFILE_NAME "qeth" 27#define QETH_PROCFILE_NAME "qeth"
28static struct proc_dir_entry *qeth_procfile; 28static struct proc_dir_entry *qeth_procfile;
29 29
30static int
31qeth_procfile_seq_match(struct device *dev, void *data)
32{
33 return 1;
34}
35
30static void * 36static void *
31qeth_procfile_seq_start(struct seq_file *s, loff_t *offset) 37qeth_procfile_seq_start(struct seq_file *s, loff_t *offset)
32{ 38{
33 struct list_head *next_card = NULL; 39 struct device *dev;
34 int i = 0; 40 loff_t nr;
35 41
36 down_read(&qeth_ccwgroup_driver.driver.bus->subsys.rwsem); 42 down_read(&qeth_ccwgroup_driver.driver.bus->subsys.rwsem);
37 43
38 if (*offset == 0) 44 nr = *offset;
45 if (nr == 0)
39 return SEQ_START_TOKEN; 46 return SEQ_START_TOKEN;
40 47
41 /* get card at pos *offset */ 48 dev = driver_find_device(&qeth_ccwgroup_driver.driver, NULL,
42 list_for_each(next_card, &qeth_ccwgroup_driver.driver.devices) 49 NULL, qeth_procfile_seq_match);
43 if (++i == *offset)
44 return next_card;
45 50
46 return NULL; 51 /* get card at pos *offset */
52 nr = *offset;
53 while (nr-- > 1 && dev)
54 dev = driver_find_device(&qeth_ccwgroup_driver.driver, dev,
55 NULL, qeth_procfile_seq_match);
56 return (void *) dev;
47} 57}
48 58
49static void 59static void
@@ -55,23 +65,21 @@ qeth_procfile_seq_stop(struct seq_file *s, void* it)
55static void * 65static void *
56qeth_procfile_seq_next(struct seq_file *s, void *it, loff_t *offset) 66qeth_procfile_seq_next(struct seq_file *s, void *it, loff_t *offset)
57{ 67{
58 struct list_head *next_card = NULL; 68 struct device *prev, *next;
59 struct list_head *current_card;
60 69
61 if (it == SEQ_START_TOKEN) { 70 if (it == SEQ_START_TOKEN) {
62 next_card = qeth_ccwgroup_driver.driver.devices.next; 71 next = driver_find_device(&qeth_ccwgroup_driver.driver,
63 if (next_card->next == next_card) /* list empty */ 72 NULL, NULL, qeth_procfile_seq_match);
64 return NULL; 73 if (next)
65 (*offset)++; 74 (*offset)++;
66 } else { 75 return (void *) next;
67 current_card = (struct list_head *)it;
68 if (current_card->next == &qeth_ccwgroup_driver.driver.devices)
69 return NULL; /* end of list reached */
70 next_card = current_card->next;
71 (*offset)++;
72 } 76 }
73 77 prev = (struct device *) it;
74 return next_card; 78 next = driver_find_device(&qeth_ccwgroup_driver.driver,
79 prev, NULL, qeth_procfile_seq_match);
80 if (next)
81 (*offset)++;
82 return (void *) next;
75} 83}
76 84
77static inline const char * 85static inline const char *
@@ -126,7 +134,7 @@ qeth_procfile_seq_show(struct seq_file *s, void *it)
126 "-------------- ---- ------ ---------- ---- " 134 "-------------- ---- ------ ---------- ---- "
127 "---- ----- -----\n"); 135 "---- ----- -----\n");
128 } else { 136 } else {
129 device = list_entry(it, struct device, driver_list); 137 device = (struct device *) it;
130 card = device->driver_data; 138 card = device->driver_data;
131 seq_printf(s, "%s/%s/%s x%02X %-10s %-14s %-4i ", 139 seq_printf(s, "%s/%s/%s x%02X %-10s %-14s %-4i ",
132 CARD_RDEV_ID(card), 140 CARD_RDEV_ID(card),
@@ -180,17 +188,20 @@ static struct proc_dir_entry *qeth_perf_procfile;
180static void * 188static void *
181qeth_perf_procfile_seq_start(struct seq_file *s, loff_t *offset) 189qeth_perf_procfile_seq_start(struct seq_file *s, loff_t *offset)
182{ 190{
183 struct list_head *next_card = NULL; 191 struct device *dev = NULL;
184 int i = 0; 192 int nr;
185 193
186 down_read(&qeth_ccwgroup_driver.driver.bus->subsys.rwsem); 194 down_read(&qeth_ccwgroup_driver.driver.bus->subsys.rwsem);
187 /* get card at pos *offset */ 195 /* get card at pos *offset */
188 list_for_each(next_card, &qeth_ccwgroup_driver.driver.devices){ 196 dev = driver_find_device(&qeth_ccwgroup_driver.driver, NULL, NULL,
189 if (i == *offset) 197 qeth_procfile_seq_match);
190 return next_card; 198
191 i++; 199 /* get card at pos *offset */
192 } 200 nr = *offset;
193 return NULL; 201 while (nr-- > 1 && dev)
202 dev = driver_find_device(&qeth_ccwgroup_driver.driver, dev,
203 NULL, qeth_procfile_seq_match);
204 return (void *) dev;
194} 205}
195 206
196static void 207static void
@@ -202,12 +213,14 @@ qeth_perf_procfile_seq_stop(struct seq_file *s, void* it)
202static void * 213static void *
203qeth_perf_procfile_seq_next(struct seq_file *s, void *it, loff_t *offset) 214qeth_perf_procfile_seq_next(struct seq_file *s, void *it, loff_t *offset)
204{ 215{
205 struct list_head *current_card = (struct list_head *)it; 216 struct device *prev, *next;
206 217
207 if (current_card->next == &qeth_ccwgroup_driver.driver.devices) 218 prev = (struct device *) it;
208 return NULL; /* end of list reached */ 219 next = driver_find_device(&qeth_ccwgroup_driver.driver, prev,
209 (*offset)++; 220 NULL, qeth_procfile_seq_match);
210 return current_card->next; 221 if (next)
222 (*offset)++;
223 return (void *) next;
211} 224}
212 225
213static int 226static int
@@ -216,7 +229,7 @@ qeth_perf_procfile_seq_show(struct seq_file *s, void *it)
216 struct device *device; 229 struct device *device;
217 struct qeth_card *card; 230 struct qeth_card *card;
218 231
219 device = list_entry(it, struct device, driver_list); 232 device = (struct device *) it;
220 card = device->driver_data; 233 card = device->driver_data;
221 seq_printf(s, "For card with devnos %s/%s/%s (%s):\n", 234 seq_printf(s, "For card with devnos %s/%s/%s (%s):\n",
222 CARD_RDEV_ID(card), 235 CARD_RDEV_ID(card),
@@ -318,8 +331,8 @@ static struct proc_dir_entry *qeth_ipato_procfile;
318static void * 331static void *
319qeth_ipato_procfile_seq_start(struct seq_file *s, loff_t *offset) 332qeth_ipato_procfile_seq_start(struct seq_file *s, loff_t *offset)
320{ 333{
321 struct list_head *next_card = NULL; 334 struct device *dev;
322 int i = 0; 335 loff_t nr;
323 336
324 down_read(&qeth_ccwgroup_driver.driver.bus->subsys.rwsem); 337 down_read(&qeth_ccwgroup_driver.driver.bus->subsys.rwsem);
325 /* TODO: finish this */ 338 /* TODO: finish this */
@@ -328,13 +341,16 @@ qeth_ipato_procfile_seq_start(struct seq_file *s, loff_t *offset)
328 * output driver settings then; 341 * output driver settings then;
329 * else output setting for respective card 342 * else output setting for respective card
330 */ 343 */
344
345 dev = driver_find_device(&qeth_ccwgroup_driver.driver, NULL, NULL,
346 qeth_procfile_seq_match);
347
331 /* get card at pos *offset */ 348 /* get card at pos *offset */
332 list_for_each(next_card, &qeth_ccwgroup_driver.driver.devices){ 349 nr = *offset;
333 if (i == *offset) 350 while (nr-- > 1 && dev)
334 return next_card; 351 dev = driver_find_device(&qeth_ccwgroup_driver.driver, dev,
335 i++; 352 NULL, qeth_procfile_seq_match);
336 } 353 return (void *) dev;
337 return NULL;
338} 354}
339 355
340static void 356static void
@@ -346,18 +362,14 @@ qeth_ipato_procfile_seq_stop(struct seq_file *s, void* it)
346static void * 362static void *
347qeth_ipato_procfile_seq_next(struct seq_file *s, void *it, loff_t *offset) 363qeth_ipato_procfile_seq_next(struct seq_file *s, void *it, loff_t *offset)
348{ 364{
349 struct list_head *current_card = (struct list_head *)it; 365 struct device *prev, *next;
350 366
351 /* TODO: finish this */ 367 prev = (struct device *) it;
352 /* 368 next = driver_find_device(&qeth_ccwgroup_driver.driver, prev,
353 * maybe SEQ_SATRT_TOKEN can be returned for offset 0 369 NULL, qeth_procfile_seq_match);
354 * output driver settings then; 370 if (next)
355 * else output setting for respective card 371 (*offset)++;
356 */ 372 return (void *) next;
357 if (current_card->next == &qeth_ccwgroup_driver.driver.devices)
358 return NULL; /* end of list reached */
359 (*offset)++;
360 return current_card->next;
361} 373}
362 374
363static int 375static int
@@ -372,7 +384,7 @@ qeth_ipato_procfile_seq_show(struct seq_file *s, void *it)
372 * output driver settings then; 384 * output driver settings then;
373 * else output setting for respective card 385 * else output setting for respective card
374 */ 386 */
375 device = list_entry(it, struct device, driver_list); 387 device = (struct device *) it;
376 card = device->driver_data; 388 card = device->driver_data;
377 389
378 return 0; 390 return 0;
diff --git a/drivers/sbus/char/vfc.h b/drivers/sbus/char/vfc.h
index e56a43af0f62..a7782e7da42e 100644
--- a/drivers/sbus/char/vfc.h
+++ b/drivers/sbus/char/vfc.h
@@ -129,8 +129,6 @@ struct vfc_dev {
129 struct vfc_regs *phys_regs; 129 struct vfc_regs *phys_regs;
130 unsigned int control_reg; 130 unsigned int control_reg;
131 struct semaphore device_lock_sem; 131 struct semaphore device_lock_sem;
132 struct timer_list poll_timer;
133 wait_queue_head_t poll_wait;
134 int instance; 132 int instance;
135 int busy; 133 int busy;
136 unsigned long which_io; 134 unsigned long which_io;
diff --git a/drivers/sbus/char/vfc_dev.c b/drivers/sbus/char/vfc_dev.c
index 86ce54130954..7a103698fa3c 100644
--- a/drivers/sbus/char/vfc_dev.c
+++ b/drivers/sbus/char/vfc_dev.c
@@ -137,7 +137,6 @@ int init_vfc_devstruct(struct vfc_dev *dev, int instance)
137 dev->instance=instance; 137 dev->instance=instance;
138 init_MUTEX(&dev->device_lock_sem); 138 init_MUTEX(&dev->device_lock_sem);
139 dev->control_reg=0; 139 dev->control_reg=0;
140 init_waitqueue_head(&dev->poll_wait);
141 dev->busy=0; 140 dev->busy=0;
142 return 0; 141 return 0;
143} 142}
diff --git a/drivers/sbus/char/vfc_i2c.c b/drivers/sbus/char/vfc_i2c.c
index 1faf1e75f71f..739cad9b19a1 100644
--- a/drivers/sbus/char/vfc_i2c.c
+++ b/drivers/sbus/char/vfc_i2c.c
@@ -79,25 +79,10 @@ int vfc_pcf8584_init(struct vfc_dev *dev)
79 return 0; 79 return 0;
80} 80}
81 81
82void vfc_i2c_delay_wakeup(struct vfc_dev *dev)
83{
84 /* Used to profile code and eliminate too many delays */
85 VFC_I2C_DEBUG_PRINTK(("vfc%d: Delaying\n", dev->instance));
86 wake_up(&dev->poll_wait);
87}
88
89void vfc_i2c_delay_no_busy(struct vfc_dev *dev, unsigned long usecs) 82void vfc_i2c_delay_no_busy(struct vfc_dev *dev, unsigned long usecs)
90{ 83{
91 DEFINE_WAIT(wait); 84 set_current_state(TASK_UNINTERRUPTIBLE);
92 init_timer(&dev->poll_timer); 85 schedule_timeout(usecs_to_jiffies(usecs));
93 dev->poll_timer.expires = jiffies + usecs_to_jiffies(usecs);
94 dev->poll_timer.data=(unsigned long)dev;
95 dev->poll_timer.function=(void *)(unsigned long)vfc_i2c_delay_wakeup;
96 add_timer(&dev->poll_timer);
97 prepare_to_wait(&dev->poll_wait, &wait, TASK_UNINTERRUPTIBLE);
98 schedule();
99 del_timer(&dev->poll_timer);
100 finish_wait(&dev->poll_wait, &wait);
101} 86}
102 87
103void inline vfc_i2c_delay(struct vfc_dev *dev) 88void inline vfc_i2c_delay(struct vfc_dev *dev)
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 96df148ed969..f1e8c4223ed1 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -424,7 +424,7 @@ config SCSI_IN2000
424source "drivers/scsi/megaraid/Kconfig.megaraid" 424source "drivers/scsi/megaraid/Kconfig.megaraid"
425 425
426config SCSI_SATA 426config SCSI_SATA
427 bool "Serial ATA (SATA) support" 427 tristate "Serial ATA (SATA) support"
428 depends on SCSI 428 depends on SCSI
429 help 429 help
430 This driver family supports Serial ATA host controllers 430 This driver family supports Serial ATA host controllers
diff --git a/drivers/scsi/NCR53c406a.c b/drivers/scsi/NCR53c406a.c
index b2002ba6e2aa..79ae73b23680 100644
--- a/drivers/scsi/NCR53c406a.c
+++ b/drivers/scsi/NCR53c406a.c
@@ -182,13 +182,13 @@ static int irq_probe(void);
182static void *bios_base; 182static void *bios_base;
183#endif 183#endif
184 184
185#if PORT_BASE 185#ifdef PORT_BASE
186static int port_base = PORT_BASE; 186static int port_base = PORT_BASE;
187#else 187#else
188static int port_base; 188static int port_base;
189#endif 189#endif
190 190
191#if IRQ_LEV 191#ifdef IRQ_LEV
192static int irq_level = IRQ_LEV; 192static int irq_level = IRQ_LEV;
193#else 193#else
194static int irq_level = -1; /* 0 is 'no irq', so use -1 for 'uninitialized' */ 194static int irq_level = -1; /* 0 is 'no irq', so use -1 for 'uninitialized' */
diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
index 3a11a536c0da..4ab07861b457 100644
--- a/drivers/scsi/aacraid/aacraid.h
+++ b/drivers/scsi/aacraid/aacraid.h
@@ -15,11 +15,7 @@
15#define AAC_MAX_LUN (8) 15#define AAC_MAX_LUN (8)
16 16
17#define AAC_MAX_HOSTPHYSMEMPAGES (0xfffff) 17#define AAC_MAX_HOSTPHYSMEMPAGES (0xfffff)
18/* 18#define AAC_MAX_32BIT_SGBCOUNT ((unsigned short)512)
19 * max_sectors is an unsigned short, otherwise limit is 0x100000000 / 512
20 * Linux has starvation problems if we permit larger than 4MB I/O ...
21 */
22#define AAC_MAX_32BIT_SGBCOUNT ((unsigned short)8192)
23 19
24/* 20/*
25 * These macros convert from physical channels to virtual channels 21 * These macros convert from physical channels to virtual channels
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index c1a4f978fcba..562da90480a1 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -374,7 +374,8 @@ static int aac_slave_configure(struct scsi_device *sdev)
374 else 374 else
375 scsi_adjust_queue_depth(sdev, 0, 1); 375 scsi_adjust_queue_depth(sdev, 0, 1);
376 376
377 if (host->max_sectors < AAC_MAX_32BIT_SGBCOUNT) 377 if (!(((struct aac_dev *)host->hostdata)->adapter_info.options
378 & AAC_OPT_NEW_COMM))
378 blk_queue_max_segment_size(sdev->request_queue, 65536); 379 blk_queue_max_segment_size(sdev->request_queue, 65536);
379 380
380 return 0; 381 return 0;
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
index 6466a184a141..329cb2331339 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
@@ -1505,7 +1505,7 @@ ahd_linux_dev_reset(Scsi_Cmnd *cmd)
1505 memset(recovery_cmd, 0, sizeof(struct scsi_cmnd)); 1505 memset(recovery_cmd, 0, sizeof(struct scsi_cmnd));
1506 recovery_cmd->device = cmd->device; 1506 recovery_cmd->device = cmd->device;
1507 recovery_cmd->scsi_done = ahd_linux_dev_reset_complete; 1507 recovery_cmd->scsi_done = ahd_linux_dev_reset_complete;
1508#if AHD_DEBUG 1508#ifdef AHD_DEBUG
1509 if ((ahd_debug & AHD_SHOW_RECOVERY) != 0) 1509 if ((ahd_debug & AHD_SHOW_RECOVERY) != 0)
1510 printf("%s:%d:%d:%d: Device reset called for cmd %p\n", 1510 printf("%s:%d:%d:%d: Device reset called for cmd %p\n",
1511 ahd_name(ahd), cmd->device->channel, cmd->device->id, 1511 ahd_name(ahd), cmd->device->channel, cmd->device->id,
diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
index 4c3bb7bb8420..703f6e44889d 100644
--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
@@ -582,7 +582,7 @@ ahd_check_extport(struct ahd_softc *ahd)
582 } 582 }
583 } 583 }
584 584
585#if AHD_DEBUG 585#ifdef AHD_DEBUG
586 if (have_seeprom != 0 586 if (have_seeprom != 0
587 && (ahd_debug & AHD_DUMP_SEEPROM) != 0) { 587 && (ahd_debug & AHD_DUMP_SEEPROM) != 0) {
588 uint16_t *sc_data; 588 uint16_t *sc_data;
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c
index 116d0f51ca2c..687f19e9cf03 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c
@@ -1264,14 +1264,12 @@ ahc_platform_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1264 } 1264 }
1265 switch ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED))) { 1265 switch ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED))) {
1266 case AHC_DEV_Q_BASIC: 1266 case AHC_DEV_Q_BASIC:
1267 scsi_adjust_queue_depth(sdev, 1267 scsi_set_tag_type(sdev, MSG_SIMPLE_TAG);
1268 MSG_SIMPLE_TASK, 1268 scsi_activate_tcq(sdev, dev->openings + dev->active);
1269 dev->openings + dev->active);
1270 break; 1269 break;
1271 case AHC_DEV_Q_TAGGED: 1270 case AHC_DEV_Q_TAGGED:
1272 scsi_adjust_queue_depth(sdev, 1271 scsi_set_tag_type(sdev, MSG_ORDERED_TAG);
1273 MSG_ORDERED_TASK, 1272 scsi_activate_tcq(sdev, dev->openings + dev->active);
1274 dev->openings + dev->active);
1275 break; 1273 break;
1276 default: 1274 default:
1277 /* 1275 /*
@@ -1280,9 +1278,7 @@ ahc_platform_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
1280 * serially on the controller/device. This should 1278 * serially on the controller/device. This should
1281 * remove some latency. 1279 * remove some latency.
1282 */ 1280 */
1283 scsi_adjust_queue_depth(sdev, 1281 scsi_deactivate_tcq(sdev, 2);
1284 /*NON-TAGGED*/0,
1285 /*queue depth*/2);
1286 break; 1282 break;
1287 } 1283 }
1288} 1284}
@@ -1635,9 +1631,9 @@ ahc_send_async(struct ahc_softc *ahc, char channel,
1635 spi_period(starget) = tinfo->curr.period; 1631 spi_period(starget) = tinfo->curr.period;
1636 spi_width(starget) = tinfo->curr.width; 1632 spi_width(starget) = tinfo->curr.width;
1637 spi_offset(starget) = tinfo->curr.offset; 1633 spi_offset(starget) = tinfo->curr.offset;
1638 spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_DT_REQ; 1634 spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_DT_REQ ? 1 : 0;
1639 spi_qas(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_QAS_REQ; 1635 spi_qas(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_QAS_REQ ? 1 : 0;
1640 spi_iu(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ; 1636 spi_iu(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ ? 1 : 0;
1641 spi_display_xfer_agreement(starget); 1637 spi_display_xfer_agreement(starget);
1642 break; 1638 break;
1643 } 1639 }
@@ -2429,12 +2425,14 @@ static void ahc_linux_set_dt(struct scsi_target *starget, int dt)
2429 unsigned int ppr_options = tinfo->goal.ppr_options 2425 unsigned int ppr_options = tinfo->goal.ppr_options
2430 & ~MSG_EXT_PPR_DT_REQ; 2426 & ~MSG_EXT_PPR_DT_REQ;
2431 unsigned int period = tinfo->goal.period; 2427 unsigned int period = tinfo->goal.period;
2428 unsigned int width = tinfo->goal.width;
2432 unsigned long flags; 2429 unsigned long flags;
2433 struct ahc_syncrate *syncrate; 2430 struct ahc_syncrate *syncrate;
2434 2431
2435 if (dt) { 2432 if (dt) {
2436 period = 9; /* 12.5ns is the only period valid for DT */
2437 ppr_options |= MSG_EXT_PPR_DT_REQ; 2433 ppr_options |= MSG_EXT_PPR_DT_REQ;
2434 if (!width)
2435 ahc_linux_set_width(starget, 1);
2438 } else if (period == 9) 2436 } else if (period == 9)
2439 period = 10; /* if resetting DT, period must be >= 25ns */ 2437 period = 10; /* if resetting DT, period must be >= 25ns */
2440 2438
diff --git a/drivers/scsi/aic7xxx/aicasm/aicasm.c b/drivers/scsi/aic7xxx/aicasm/aicasm.c
index c34639481904..f936b691232f 100644
--- a/drivers/scsi/aic7xxx/aicasm/aicasm.c
+++ b/drivers/scsi/aic7xxx/aicasm/aicasm.c
@@ -369,7 +369,7 @@ output_code()
369 369
370 fprintf(ofile, "%s\t0x%02x, 0x%02x, 0x%02x, 0x%02x", 370 fprintf(ofile, "%s\t0x%02x, 0x%02x, 0x%02x, 0x%02x",
371 cur_instr == STAILQ_FIRST(&seq_program) ? "" : ",\n", 371 cur_instr == STAILQ_FIRST(&seq_program) ? "" : ",\n",
372#if BYTE_ORDER == LITTLE_ENDIAN 372#ifdef __LITTLE_ENDIAN
373 cur_instr->format.bytes[0], 373 cur_instr->format.bytes[0],
374 cur_instr->format.bytes[1], 374 cur_instr->format.bytes[1],
375 cur_instr->format.bytes[2], 375 cur_instr->format.bytes[2],
@@ -613,7 +613,7 @@ output_listing(char *ifilename)
613 line++; 613 line++;
614 } 614 }
615 fprintf(listfile, "%03x %02x%02x%02x%02x", instrptr, 615 fprintf(listfile, "%03x %02x%02x%02x%02x", instrptr,
616#if BYTE_ORDER == LITTLE_ENDIAN 616#ifdef __LITTLE_ENDIAN
617 cur_instr->format.bytes[0], 617 cur_instr->format.bytes[0],
618 cur_instr->format.bytes[1], 618 cur_instr->format.bytes[1],
619 cur_instr->format.bytes[2], 619 cur_instr->format.bytes[2],
diff --git a/drivers/scsi/aic7xxx/aicasm/aicasm_insformat.h b/drivers/scsi/aic7xxx/aicasm/aicasm_insformat.h
index 3e80f07df49c..e64f802bbaaa 100644
--- a/drivers/scsi/aic7xxx/aicasm/aicasm_insformat.h
+++ b/drivers/scsi/aic7xxx/aicasm/aicasm_insformat.h
@@ -42,8 +42,10 @@
42 * $FreeBSD$ 42 * $FreeBSD$
43 */ 43 */
44 44
45#include <asm/byteorder.h>
46
45struct ins_format1 { 47struct ins_format1 {
46#if BYTE_ORDER == LITTLE_ENDIAN 48#ifdef __LITTLE_ENDIAN
47 uint32_t immediate : 8, 49 uint32_t immediate : 8,
48 source : 9, 50 source : 9,
49 destination : 9, 51 destination : 9,
@@ -61,7 +63,7 @@ struct ins_format1 {
61}; 63};
62 64
63struct ins_format2 { 65struct ins_format2 {
64#if BYTE_ORDER == LITTLE_ENDIAN 66#ifdef __LITTLE_ENDIAN
65 uint32_t shift_control : 8, 67 uint32_t shift_control : 8,
66 source : 9, 68 source : 9,
67 destination : 9, 69 destination : 9,
@@ -79,7 +81,7 @@ struct ins_format2 {
79}; 81};
80 82
81struct ins_format3 { 83struct ins_format3 {
82#if BYTE_ORDER == LITTLE_ENDIAN 84#ifdef __LITTLE_ENDIAN
83 uint32_t immediate : 8, 85 uint32_t immediate : 8,
84 source : 9, 86 source : 9,
85 address : 10, 87 address : 10,
diff --git a/drivers/scsi/ata_piix.c b/drivers/scsi/ata_piix.c
index 3be546439252..a2cfade2c1c6 100644
--- a/drivers/scsi/ata_piix.c
+++ b/drivers/scsi/ata_piix.c
@@ -38,6 +38,7 @@ enum {
38 PIIX_IOCFG = 0x54, /* IDE I/O configuration register */ 38 PIIX_IOCFG = 0x54, /* IDE I/O configuration register */
39 ICH5_PMR = 0x90, /* port mapping register */ 39 ICH5_PMR = 0x90, /* port mapping register */
40 ICH5_PCS = 0x92, /* port control and status */ 40 ICH5_PCS = 0x92, /* port control and status */
41 PIIX_SCC = 0x0A, /* sub-class code register */
41 42
42 PIIX_FLAG_AHCI = (1 << 28), /* AHCI possible */ 43 PIIX_FLAG_AHCI = (1 << 28), /* AHCI possible */
43 PIIX_FLAG_CHECKINTR = (1 << 29), /* make sure PCI INTx enabled */ 44 PIIX_FLAG_CHECKINTR = (1 << 29), /* make sure PCI INTx enabled */
@@ -62,6 +63,8 @@ enum {
62 ich6_sata_rm = 4, 63 ich6_sata_rm = 4,
63 ich7_sata = 5, 64 ich7_sata = 5,
64 esb2_sata = 6, 65 esb2_sata = 6,
66
67 PIIX_AHCI_DEVICE = 6,
65}; 68};
66 69
67static int piix_init_one (struct pci_dev *pdev, 70static int piix_init_one (struct pci_dev *pdev,
@@ -574,11 +577,11 @@ static int piix_disable_ahci(struct pci_dev *pdev)
574 addr = pci_resource_start(pdev, AHCI_PCI_BAR); 577 addr = pci_resource_start(pdev, AHCI_PCI_BAR);
575 if (!addr || !pci_resource_len(pdev, AHCI_PCI_BAR)) 578 if (!addr || !pci_resource_len(pdev, AHCI_PCI_BAR))
576 return 0; 579 return 0;
577 580
578 mmio = ioremap(addr, 64); 581 mmio = ioremap(addr, 64);
579 if (!mmio) 582 if (!mmio)
580 return -ENOMEM; 583 return -ENOMEM;
581 584
582 tmp = readl(mmio + AHCI_GLOBAL_CTL); 585 tmp = readl(mmio + AHCI_GLOBAL_CTL);
583 if (tmp & AHCI_ENABLE) { 586 if (tmp & AHCI_ENABLE) {
584 tmp &= ~AHCI_ENABLE; 587 tmp &= ~AHCI_ENABLE;
@@ -588,7 +591,7 @@ static int piix_disable_ahci(struct pci_dev *pdev)
588 if (tmp & AHCI_ENABLE) 591 if (tmp & AHCI_ENABLE)
589 rc = -EIO; 592 rc = -EIO;
590 } 593 }
591 594
592 iounmap(mmio); 595 iounmap(mmio);
593 return rc; 596 return rc;
594} 597}
@@ -626,9 +629,13 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
626 port_info[1] = NULL; 629 port_info[1] = NULL;
627 630
628 if (port_info[0]->host_flags & PIIX_FLAG_AHCI) { 631 if (port_info[0]->host_flags & PIIX_FLAG_AHCI) {
629 int rc = piix_disable_ahci(pdev); 632 u8 tmp;
630 if (rc) 633 pci_read_config_byte(pdev, PIIX_SCC, &tmp);
631 return rc; 634 if (tmp == PIIX_AHCI_DEVICE) {
635 int rc = piix_disable_ahci(pdev);
636 if (rc)
637 return rc;
638 }
632 } 639 }
633 640
634 if (port_info[0]->host_flags & PIIX_FLAG_COMBINED) { 641 if (port_info[0]->host_flags & PIIX_FLAG_COMBINED) {
diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
index ae13c002f60d..929170dcd3cb 100644
--- a/drivers/scsi/dc395x.c
+++ b/drivers/scsi/dc395x.c
@@ -744,7 +744,7 @@ static void free_tag(struct DeviceCtlBlk *dcb, struct ScsiReqBlk *srb)
744 744
745 745
746/* Find cmd in SRB list */ 746/* Find cmd in SRB list */
747inline static struct ScsiReqBlk *find_cmd(struct scsi_cmnd *cmd, 747static inline struct ScsiReqBlk *find_cmd(struct scsi_cmnd *cmd,
748 struct list_head *head) 748 struct list_head *head)
749{ 749{
750 struct ScsiReqBlk *i; 750 struct ScsiReqBlk *i;
diff --git a/drivers/scsi/dpt/dptsig.h b/drivers/scsi/dpt/dptsig.h
index 95a4cce6c892..4bf447792129 100644
--- a/drivers/scsi/dpt/dptsig.h
+++ b/drivers/scsi/dpt/dptsig.h
@@ -76,7 +76,7 @@ typedef unsigned long sigLONG;
76#endif /* aix */ 76#endif /* aix */
77#endif 77#endif
78/* For the Macintosh */ 78/* For the Macintosh */
79#if STRUCTALIGNMENTSUPPORTED 79#ifdef STRUCTALIGNMENTSUPPORTED
80#pragma options align=mac68k 80#pragma options align=mac68k
81#endif 81#endif
82 82
@@ -332,7 +332,7 @@ typedef struct dpt_sig {
332#endif /* aix */ 332#endif /* aix */
333#endif 333#endif
334/* For the Macintosh */ 334/* For the Macintosh */
335#if STRUCTALIGNMENTSUPPORTED 335#ifdef STRUCTALIGNMENTSUPPORTED
336#pragma options align=reset 336#pragma options align=reset
337#endif 337#endif
338 338
diff --git a/drivers/scsi/dtc.c b/drivers/scsi/dtc.c
index ab9de39bb50b..897743b23342 100644
--- a/drivers/scsi/dtc.c
+++ b/drivers/scsi/dtc.c
@@ -92,10 +92,6 @@
92 92
93#define DTC_PUBLIC_RELEASE 2 93#define DTC_PUBLIC_RELEASE 2
94 94
95/*#define DTCDEBUG 0x1*/
96#define DTCDEBUG_INIT 0x1
97#define DTCDEBUG_TRANSFER 0x2
98
99/* 95/*
100 * The DTC3180 & 3280 boards are memory mapped. 96 * The DTC3180 & 3280 boards are memory mapped.
101 * 97 *
diff --git a/drivers/scsi/dtc.h b/drivers/scsi/dtc.h
index ed73629eb2f9..277cd015ee4e 100644
--- a/drivers/scsi/dtc.h
+++ b/drivers/scsi/dtc.h
@@ -28,6 +28,10 @@
28#ifndef DTC3280_H 28#ifndef DTC3280_H
29#define DTC3280_H 29#define DTC3280_H
30 30
31#define DTCDEBUG 0
32#define DTCDEBUG_INIT 0x1
33#define DTCDEBUG_TRANSFER 0x2
34
31static int dtc_abort(Scsi_Cmnd *); 35static int dtc_abort(Scsi_Cmnd *);
32static int dtc_biosparam(struct scsi_device *, struct block_device *, 36static int dtc_biosparam(struct scsi_device *, struct block_device *,
33 sector_t, int*); 37 sector_t, int*);
diff --git a/drivers/scsi/fdomain.c b/drivers/scsi/fdomain.c
index aecf32dd0bde..3b2a5bf5c43e 100644
--- a/drivers/scsi/fdomain.c
+++ b/drivers/scsi/fdomain.c
@@ -570,7 +570,7 @@ static void do_pause(unsigned amount) /* Pause for amount*10 milliseconds */
570 mdelay(10*amount); 570 mdelay(10*amount);
571} 571}
572 572
573inline static void fdomain_make_bus_idle( void ) 573static inline void fdomain_make_bus_idle( void )
574{ 574{
575 outb(0, port_base + SCSI_Cntl); 575 outb(0, port_base + SCSI_Cntl);
576 outb(0, port_base + SCSI_Mode_Cntl); 576 outb(0, port_base + SCSI_Mode_Cntl);
diff --git a/drivers/scsi/ibmvscsi/srp.h b/drivers/scsi/ibmvscsi/srp.h
index 2ae5154fd89c..7d8e4c4accb9 100644
--- a/drivers/scsi/ibmvscsi/srp.h
+++ b/drivers/scsi/ibmvscsi/srp.h
@@ -35,7 +35,7 @@
35enum srp_types { 35enum srp_types {
36 SRP_LOGIN_REQ_TYPE = 0x00, 36 SRP_LOGIN_REQ_TYPE = 0x00,
37 SRP_LOGIN_RSP_TYPE = 0xC0, 37 SRP_LOGIN_RSP_TYPE = 0xC0,
38 SRP_LOGIN_REJ_TYPE = 0x80, 38 SRP_LOGIN_REJ_TYPE = 0xC2,
39 SRP_I_LOGOUT_TYPE = 0x03, 39 SRP_I_LOGOUT_TYPE = 0x03,
40 SRP_T_LOGOUT_TYPE = 0x80, 40 SRP_T_LOGOUT_TYPE = 0x80,
41 SRP_TSK_MGMT_TYPE = 0x01, 41 SRP_TSK_MGMT_TYPE = 0x01,
diff --git a/drivers/scsi/initio.c b/drivers/scsi/initio.c
index 2094d4811d61..ea6f3c0e05d9 100644
--- a/drivers/scsi/initio.c
+++ b/drivers/scsi/initio.c
@@ -716,7 +716,7 @@ static int init_tulip(HCS * pCurHcb, SCB * scbp, int tul_num_scb,
716 pCurHcb->HCS_SCSI_ID = i91unvramp->NVM_SCSIInfo[0].NVM_ChSCSIID; 716 pCurHcb->HCS_SCSI_ID = i91unvramp->NVM_SCSIInfo[0].NVM_ChSCSIID;
717 pCurHcb->HCS_IdMask = ~(1 << pCurHcb->HCS_SCSI_ID); 717 pCurHcb->HCS_IdMask = ~(1 << pCurHcb->HCS_SCSI_ID);
718 718
719#if CHK_PARITY 719#ifdef CHK_PARITY
720 /* Enable parity error response */ 720 /* Enable parity error response */
721 TUL_WR(pCurHcb->HCS_Base + TUL_PCMD, TUL_RD(pCurHcb->HCS_Base, TUL_PCMD) | 0x40); 721 TUL_WR(pCurHcb->HCS_Base + TUL_PCMD, TUL_RD(pCurHcb->HCS_Base, TUL_PCMD) | 0x40);
722#endif 722#endif
diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c
index 6dfcb4fbccdd..4cdd891781b1 100644
--- a/drivers/scsi/ips.c
+++ b/drivers/scsi/ips.c
@@ -133,10 +133,12 @@
133/* 6.10.00 - Remove 1G Addressing Limitations */ 133/* 6.10.00 - Remove 1G Addressing Limitations */
134/* 6.11.xx - Get VersionInfo buffer off the stack ! DDTS 60401 */ 134/* 6.11.xx - Get VersionInfo buffer off the stack ! DDTS 60401 */
135/* 6.11.xx - Make Logical Drive Info structure safe for DMA DDTS 60639 */ 135/* 6.11.xx - Make Logical Drive Info structure safe for DMA DDTS 60639 */
136/* 7.10.xx - Add highmem_io flag in SCSI Templete for 2.4 kernels */ 136/* 7.10.18 - Add highmem_io flag in SCSI Templete for 2.4 kernels */
137/* - Fix path/name for scsi_hosts.h include for 2.6 kernels */ 137/* - Fix path/name for scsi_hosts.h include for 2.6 kernels */
138/* - Fix sort order of 7k */ 138/* - Fix sort order of 7k */
139/* - Remove 3 unused "inline" functions */ 139/* - Remove 3 unused "inline" functions */
140/* 7.12.xx - Use STATIC functions whereever possible */
141/* - Clean up deprecated MODULE_PARM calls */
140/*****************************************************************************/ 142/*****************************************************************************/
141 143
142/* 144/*
@@ -207,8 +209,8 @@ module_param(ips, charp, 0);
207/* 209/*
208 * DRIVER_VER 210 * DRIVER_VER
209 */ 211 */
210#define IPS_VERSION_HIGH "7.10" 212#define IPS_VERSION_HIGH "7.12"
211#define IPS_VERSION_LOW ".18 " 213#define IPS_VERSION_LOW ".02 "
212 214
213#if !defined(__i386__) && !defined(__ia64__) && !defined(__x86_64__) 215#if !defined(__i386__) && !defined(__ia64__) && !defined(__x86_64__)
214#warning "This driver has only been tested on the x86/ia64/x86_64 platforms" 216#warning "This driver has only been tested on the x86/ia64/x86_64 platforms"
diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
index 480e06f4d6ae..505e967013de 100644
--- a/drivers/scsi/ips.h
+++ b/drivers/scsi/ips.h
@@ -87,15 +87,14 @@
87 #define scsi_set_pci_device(sh,dev) (0) 87 #define scsi_set_pci_device(sh,dev) (0)
88 #endif 88 #endif
89 89
90 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 90 #ifndef IRQ_NONE
91 91 typedef void irqreturn_t;
92 #ifndef irqreturn_t
93 typedef void irqreturn_t;
94 #endif
95
96 #define IRQ_NONE 92 #define IRQ_NONE
97 #define IRQ_HANDLED 93 #define IRQ_HANDLED
98 #define IRQ_RETVAL(x) 94 #define IRQ_RETVAL(x)
95 #endif
96
97 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
99 #define IPS_REGISTER_HOSTS(SHT) scsi_register_module(MODULE_SCSI_HA,SHT) 98 #define IPS_REGISTER_HOSTS(SHT) scsi_register_module(MODULE_SCSI_HA,SHT)
100 #define IPS_UNREGISTER_HOSTS(SHT) scsi_unregister_module(MODULE_SCSI_HA,SHT) 99 #define IPS_UNREGISTER_HOSTS(SHT) scsi_unregister_module(MODULE_SCSI_HA,SHT)
101 #define IPS_ADD_HOST(shost,device) 100 #define IPS_ADD_HOST(shost,device)
@@ -123,6 +122,10 @@
123 #ifndef min 122 #ifndef min
124 #define min(x,y) ((x) < (y) ? x : y) 123 #define min(x,y) ((x) < (y) ? x : y)
125 #endif 124 #endif
125
126 #ifndef __iomem /* For clean compiles in earlier kernels without __iomem annotations */
127 #define __iomem
128 #endif
126 129
127 #define pci_dma_hi32(a) ((a >> 16) >> 16) 130 #define pci_dma_hi32(a) ((a >> 16) >> 16)
128 #define pci_dma_lo32(a) (a & 0xffffffff) 131 #define pci_dma_lo32(a) (a & 0xffffffff)
@@ -1206,13 +1209,13 @@ typedef struct {
1206 1209
1207#define IPS_VER_MAJOR 7 1210#define IPS_VER_MAJOR 7
1208#define IPS_VER_MAJOR_STRING "7" 1211#define IPS_VER_MAJOR_STRING "7"
1209#define IPS_VER_MINOR 10 1212#define IPS_VER_MINOR 12
1210#define IPS_VER_MINOR_STRING "10" 1213#define IPS_VER_MINOR_STRING "12"
1211#define IPS_VER_BUILD 18 1214#define IPS_VER_BUILD 02
1212#define IPS_VER_BUILD_STRING "18" 1215#define IPS_VER_BUILD_STRING "02"
1213#define IPS_VER_STRING "7.10.18" 1216#define IPS_VER_STRING "7.12.02"
1214#define IPS_RELEASE_ID 0x00020000 1217#define IPS_RELEASE_ID 0x00020000
1215#define IPS_BUILD_IDENT 731 1218#define IPS_BUILD_IDENT 761
1216#define IPS_LEGALCOPYRIGHT_STRING "(C) Copyright IBM Corp. 1994, 2002. All Rights Reserved." 1219#define IPS_LEGALCOPYRIGHT_STRING "(C) Copyright IBM Corp. 1994, 2002. All Rights Reserved."
1217#define IPS_ADAPTECCOPYRIGHT_STRING "(c) Copyright Adaptec, Inc. 2002 to 2004. All Rights Reserved." 1220#define IPS_ADAPTECCOPYRIGHT_STRING "(c) Copyright Adaptec, Inc. 2002 to 2004. All Rights Reserved."
1218#define IPS_DELLCOPYRIGHT_STRING "(c) Copyright Dell 2004. All Rights Reserved." 1221#define IPS_DELLCOPYRIGHT_STRING "(c) Copyright Dell 2004. All Rights Reserved."
@@ -1223,12 +1226,12 @@ typedef struct {
1223#define IPS_VER_SERVERAID2 "2.88.13" 1226#define IPS_VER_SERVERAID2 "2.88.13"
1224#define IPS_VER_NAVAJO "2.88.13" 1227#define IPS_VER_NAVAJO "2.88.13"
1225#define IPS_VER_SERVERAID3 "6.10.24" 1228#define IPS_VER_SERVERAID3 "6.10.24"
1226#define IPS_VER_SERVERAID4H "7.10.11" 1229#define IPS_VER_SERVERAID4H "7.12.02"
1227#define IPS_VER_SERVERAID4MLx "7.10.18" 1230#define IPS_VER_SERVERAID4MLx "7.12.02"
1228#define IPS_VER_SARASOTA "7.10.18" 1231#define IPS_VER_SARASOTA "7.12.02"
1229#define IPS_VER_MARCO "7.10.18" 1232#define IPS_VER_MARCO "7.12.02"
1230#define IPS_VER_SEBRING "7.10.18" 1233#define IPS_VER_SEBRING "7.12.02"
1231#define IPS_VER_KEYWEST "7.10.18" 1234#define IPS_VER_KEYWEST "7.12.02"
1232 1235
1233/* Compatability IDs for various adapters */ 1236/* Compatability IDs for various adapters */
1234#define IPS_COMPAT_UNKNOWN "" 1237#define IPS_COMPAT_UNKNOWN ""
diff --git a/drivers/scsi/lpfc/lpfc_compat.h b/drivers/scsi/lpfc/lpfc_compat.h
index 275ba34b3c9d..a11f1ae7b98e 100644
--- a/drivers/scsi/lpfc/lpfc_compat.h
+++ b/drivers/scsi/lpfc/lpfc_compat.h
@@ -30,8 +30,9 @@ memcpy_toio() and memcpy_fromio() can be used.
30However on a big-endian host, copy 4 bytes at a time, 30However on a big-endian host, copy 4 bytes at a time,
31using writel() and readl(). 31using writel() and readl().
32 *******************************************************************/ 32 *******************************************************************/
33#include <asm/byteorder.h>
33 34
34#if __BIG_ENDIAN 35#ifdef __BIG_ENDIAN
35 36
36static inline void 37static inline void
37lpfc_memcpy_to_slim(void __iomem *dest, void *src, unsigned int bytes) 38lpfc_memcpy_to_slim(void __iomem *dest, void *src, unsigned int bytes)
diff --git a/drivers/scsi/lpfc/lpfc_scsi.h b/drivers/scsi/lpfc/lpfc_scsi.h
index d8fd2010ef41..0fd9ba14e1b5 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.h
+++ b/drivers/scsi/lpfc/lpfc_scsi.h
@@ -18,6 +18,8 @@
18 * included with this package. * 18 * included with this package. *
19 *******************************************************************/ 19 *******************************************************************/
20 20
21#include <asm/byteorder.h>
22
21struct lpfc_hba; 23struct lpfc_hba;
22 24
23#define list_remove_head(list, entry, type, member) \ 25#define list_remove_head(list, entry, type, member) \
@@ -81,7 +83,7 @@ struct fcp_cmnd {
81 /* # of bits to shift lun id to end up in right 83 /* # of bits to shift lun id to end up in right
82 * payload word, little endian = 8, big = 16. 84 * payload word, little endian = 8, big = 16.
83 */ 85 */
84#if __BIG_ENDIAN 86#ifdef __BIG_ENDIAN
85#define FC_LUN_SHIFT 16 87#define FC_LUN_SHIFT 16
86#define FC_ADDR_MODE_SHIFT 24 88#define FC_ADDR_MODE_SHIFT 24
87#else /* __LITTLE_ENDIAN */ 89#else /* __LITTLE_ENDIAN */
diff --git a/drivers/scsi/pas16.c b/drivers/scsi/pas16.c
index 363e0ebd4a39..72bc947e45b6 100644
--- a/drivers/scsi/pas16.c
+++ b/drivers/scsi/pas16.c
@@ -2,6 +2,7 @@
2#define PSEUDO_DMA 2#define PSEUDO_DMA
3#define FOO 3#define FOO
4#define UNSAFE /* Not unsafe for PAS16 -- use it */ 4#define UNSAFE /* Not unsafe for PAS16 -- use it */
5#define PDEBUG 0
5 6
6/* 7/*
7 * This driver adapted from Drew Eckhardt's Trantor T128 driver 8 * This driver adapted from Drew Eckhardt's Trantor T128 driver
diff --git a/drivers/scsi/qla2xxx/Kconfig b/drivers/scsi/qla2xxx/Kconfig
index fccecf67423e..c1c1c687bcbd 100644
--- a/drivers/scsi/qla2xxx/Kconfig
+++ b/drivers/scsi/qla2xxx/Kconfig
@@ -2,12 +2,12 @@ config SCSI_QLA2XXX
2 tristate 2 tristate
3 default (SCSI && PCI) 3 default (SCSI && PCI)
4 depends on SCSI && PCI 4 depends on SCSI && PCI
5 select SCSI_FC_ATTRS
6 5
7config SCSI_QLA21XX 6config SCSI_QLA21XX
8 tristate "QLogic ISP2100 host adapter family support" 7 tristate "QLogic ISP2100 host adapter family support"
9 depends on SCSI_QLA2XXX 8 depends on SCSI_QLA2XXX
10 select SCSI_FC_ATTRS 9 select SCSI_FC_ATTRS
10 select FW_LOADER
11 ---help--- 11 ---help---
12 This driver supports the QLogic 21xx (ISP2100) host adapter family. 12 This driver supports the QLogic 21xx (ISP2100) host adapter family.
13 13
@@ -15,6 +15,7 @@ config SCSI_QLA22XX
15 tristate "QLogic ISP2200 host adapter family support" 15 tristate "QLogic ISP2200 host adapter family support"
16 depends on SCSI_QLA2XXX 16 depends on SCSI_QLA2XXX
17 select SCSI_FC_ATTRS 17 select SCSI_FC_ATTRS
18 select FW_LOADER
18 ---help--- 19 ---help---
19 This driver supports the QLogic 22xx (ISP2200) host adapter family. 20 This driver supports the QLogic 22xx (ISP2200) host adapter family.
20 21
@@ -22,6 +23,7 @@ config SCSI_QLA2300
22 tristate "QLogic ISP2300 host adapter family support" 23 tristate "QLogic ISP2300 host adapter family support"
23 depends on SCSI_QLA2XXX 24 depends on SCSI_QLA2XXX
24 select SCSI_FC_ATTRS 25 select SCSI_FC_ATTRS
26 select FW_LOADER
25 ---help--- 27 ---help---
26 This driver supports the QLogic 2300 (ISP2300 and ISP2312) host 28 This driver supports the QLogic 2300 (ISP2300 and ISP2312) host
27 adapter family. 29 adapter family.
@@ -30,6 +32,7 @@ config SCSI_QLA2322
30 tristate "QLogic ISP2322 host adapter family support" 32 tristate "QLogic ISP2322 host adapter family support"
31 depends on SCSI_QLA2XXX 33 depends on SCSI_QLA2XXX
32 select SCSI_FC_ATTRS 34 select SCSI_FC_ATTRS
35 select FW_LOADER
33 ---help--- 36 ---help---
34 This driver supports the QLogic 2322 (ISP2322) host adapter family. 37 This driver supports the QLogic 2322 (ISP2322) host adapter family.
35 38
@@ -37,6 +40,16 @@ config SCSI_QLA6312
37 tristate "QLogic ISP63xx host adapter family support" 40 tristate "QLogic ISP63xx host adapter family support"
38 depends on SCSI_QLA2XXX 41 depends on SCSI_QLA2XXX
39 select SCSI_FC_ATTRS 42 select SCSI_FC_ATTRS
43 select FW_LOADER
40 ---help--- 44 ---help---
41 This driver supports the QLogic 63xx (ISP6312 and ISP6322) host 45 This driver supports the QLogic 63xx (ISP6312 and ISP6322) host
42 adapter family. 46 adapter family.
47
48config SCSI_QLA24XX
49 tristate "QLogic ISP24xx host adapter family support"
50 depends on SCSI_QLA2XXX
51 select SCSI_FC_ATTRS
52 select FW_LOADER
53 ---help---
54 This driver supports the QLogic 24xx (ISP2422 and ISP2432) host
55 adapter family.
diff --git a/drivers/scsi/qla2xxx/Makefile b/drivers/scsi/qla2xxx/Makefile
index 982b83604b41..b169687d08ff 100644
--- a/drivers/scsi/qla2xxx/Makefile
+++ b/drivers/scsi/qla2xxx/Makefile
@@ -1,6 +1,4 @@
1EXTRA_CFLAGS += -DUNIQUE_FW_NAME 1EXTRA_CFLAGS += -DUNIQUE_FW_NAME
2CONFIG_SCSI_QLA24XX=m
3EXTRA_CFLAGS += -DCONFIG_SCSI_QLA24XX -DCONFIG_SCSI_QLA24XX_MODULE
4 2
5qla2xxx-y := qla_os.o qla_init.o qla_mbx.o qla_iocb.o qla_isr.o qla_gs.o \ 3qla2xxx-y := qla_os.o qla_init.o qla_mbx.o qla_iocb.o qla_isr.o qla_gs.o \
6 qla_dbg.o qla_sup.o qla_rscn.o qla_attr.o 4 qla_dbg.o qla_sup.o qla_rscn.o qla_attr.o
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index ad3a5b142468..2d3c4ac475f2 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -756,7 +756,8 @@ static int scsi_add_lun(struct scsi_device *sdev, char *inq_result, int *bflags)
756 * register it and tell the rest of the kernel 756 * register it and tell the rest of the kernel
757 * about it. 757 * about it.
758 */ 758 */
759 scsi_sysfs_add_sdev(sdev); 759 if (scsi_sysfs_add_sdev(sdev) != 0)
760 return SCSI_SCAN_NO_RESPONSE;
760 761
761 return SCSI_SCAN_LUN_PRESENT; 762 return SCSI_SCAN_LUN_PRESENT;
762} 763}
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 0291a8fb654d..0a7839db5752 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -4149,12 +4149,10 @@ static int __init init_st(void)
4149 do_create_driverfs_files(); 4149 do_create_driverfs_files();
4150 return 0; 4150 return 0;
4151 } 4151 }
4152 if (st_sysfs_class)
4153 class_destroy(st_sysfs_class);
4154 unregister_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0), 4152 unregister_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0),
4155
4156 ST_MAX_TAPE_ENTRIES); 4153 ST_MAX_TAPE_ENTRIES);
4157 } 4154 }
4155 class_destroy(st_sysfs_class);
4158 4156
4159 printk(KERN_ERR "Unable to get major %d for SCSI tapes\n", SCSI_TAPE_MAJOR); 4157 printk(KERN_ERR "Unable to get major %d for SCSI tapes\n", SCSI_TAPE_MAJOR);
4160 return 1; 4158 return 1;
@@ -4162,13 +4160,11 @@ static int __init init_st(void)
4162 4160
4163static void __exit exit_st(void) 4161static void __exit exit_st(void)
4164{ 4162{
4165 if (st_sysfs_class)
4166 class_destroy(st_sysfs_class);
4167 st_sysfs_class = NULL;
4168 do_remove_driverfs_files(); 4163 do_remove_driverfs_files();
4169 scsi_unregister_driver(&st_template.gendrv); 4164 scsi_unregister_driver(&st_template.gendrv);
4170 unregister_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0), 4165 unregister_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0),
4171 ST_MAX_TAPE_ENTRIES); 4166 ST_MAX_TAPE_ENTRIES);
4167 class_destroy(st_sysfs_class);
4172 kfree(scsi_tapes); 4168 kfree(scsi_tapes);
4173 printk(KERN_INFO "st: Unloaded.\n"); 4169 printk(KERN_INFO "st: Unloaded.\n");
4174} 4170}
diff --git a/drivers/scsi/sym53c8xx_2/sym_hipd.h b/drivers/scsi/sym53c8xx_2/sym_hipd.h
index c55c7a57afa0..3131a6bf7ab7 100644
--- a/drivers/scsi/sym53c8xx_2/sym_hipd.h
+++ b/drivers/scsi/sym53c8xx_2/sym_hipd.h
@@ -151,6 +151,16 @@
151 */ 151 */
152#define SYM_CONF_MIN_ASYNC (40) 152#define SYM_CONF_MIN_ASYNC (40)
153 153
154
155/*
156 * MEMORY ALLOCATOR.
157 */
158
159#define SYM_MEM_WARN 1 /* Warn on failed operations */
160
161#define SYM_MEM_PAGE_ORDER 0 /* 1 PAGE maximum */
162#define SYM_MEM_CLUSTER_SHIFT (PAGE_SHIFT+SYM_MEM_PAGE_ORDER)
163#define SYM_MEM_FREE_UNUSED /* Free unused pages immediately */
154/* 164/*
155 * Shortest memory chunk is (1<<SYM_MEM_SHIFT), currently 16. 165 * Shortest memory chunk is (1<<SYM_MEM_SHIFT), currently 16.
156 * Actual allocations happen as SYM_MEM_CLUSTER_SIZE sized. 166 * Actual allocations happen as SYM_MEM_CLUSTER_SIZE sized.
@@ -1192,12 +1202,6 @@ static inline void sym_setup_data_pointers(struct sym_hcb *np,
1192 * MEMORY ALLOCATOR. 1202 * MEMORY ALLOCATOR.
1193 */ 1203 */
1194 1204
1195#define SYM_MEM_PAGE_ORDER 0 /* 1 PAGE maximum */
1196#define SYM_MEM_CLUSTER_SHIFT (PAGE_SHIFT+SYM_MEM_PAGE_ORDER)
1197#define SYM_MEM_FREE_UNUSED /* Free unused pages immediately */
1198
1199#define SYM_MEM_WARN 1 /* Warn on failed operations */
1200
1201#define sym_get_mem_cluster() \ 1205#define sym_get_mem_cluster() \
1202 (void *) __get_free_pages(GFP_ATOMIC, SYM_MEM_PAGE_ORDER) 1206 (void *) __get_free_pages(GFP_ATOMIC, SYM_MEM_PAGE_ORDER)
1203#define sym_free_mem_cluster(p) \ 1207#define sym_free_mem_cluster(p) \
diff --git a/drivers/scsi/sym53c8xx_2/sym_nvram.c b/drivers/scsi/sym53c8xx_2/sym_nvram.c
index cd9140e158cf..994b7566bcac 100644
--- a/drivers/scsi/sym53c8xx_2/sym_nvram.c
+++ b/drivers/scsi/sym53c8xx_2/sym_nvram.c
@@ -367,7 +367,7 @@ static void S24C16_read_byte(struct sym_device *np, u_char *read_data, u_char ac
367 S24C16_write_ack(np, ack_data, gpreg, gpcntl); 367 S24C16_write_ack(np, ack_data, gpreg, gpcntl);
368} 368}
369 369
370#if SYM_CONF_NVRAM_WRITE_SUPPORT 370#ifdef SYM_CONF_NVRAM_WRITE_SUPPORT
371/* 371/*
372 * Write 'len' bytes starting at 'offset'. 372 * Write 'len' bytes starting at 'offset'.
373 */ 373 */
diff --git a/drivers/scsi/t128.h b/drivers/scsi/t128.h
index 9ad1d68827a7..596f3a32a1c6 100644
--- a/drivers/scsi/t128.h
+++ b/drivers/scsi/t128.h
@@ -43,6 +43,7 @@
43 43
44#define T128_PUBLIC_RELEASE 3 44#define T128_PUBLIC_RELEASE 3
45 45
46#define TDEBUG 0
46#define TDEBUG_INIT 0x1 47#define TDEBUG_INIT 0x1
47#define TDEBUG_TRANSFER 0x2 48#define TDEBUG_TRANSFER 0x2
48 49
diff --git a/drivers/serial/8250_pci.c b/drivers/serial/8250_pci.c
index 356f5556759a..07f05e9d0955 100644
--- a/drivers/serial/8250_pci.c
+++ b/drivers/serial/8250_pci.c
@@ -1029,6 +1029,8 @@ enum pci_board_num_t {
1029 pbn_b0_2_921600, 1029 pbn_b0_2_921600,
1030 pbn_b0_4_921600, 1030 pbn_b0_4_921600,
1031 1031
1032 pbn_b0_2_1130000,
1033
1032 pbn_b0_4_1152000, 1034 pbn_b0_4_1152000,
1033 1035
1034 pbn_b0_bt_1_115200, 1036 pbn_b0_bt_1_115200,
@@ -1163,6 +1165,14 @@ static struct pci_board pci_boards[] __devinitdata = {
1163 .base_baud = 921600, 1165 .base_baud = 921600,
1164 .uart_offset = 8, 1166 .uart_offset = 8,
1165 }, 1167 },
1168
1169 [pbn_b0_2_1130000] = {
1170 .flags = FL_BASE0,
1171 .num_ports = 2,
1172 .base_baud = 1130000,
1173 .uart_offset = 8,
1174 },
1175
1166 [pbn_b0_4_1152000] = { 1176 [pbn_b0_4_1152000] = {
1167 .flags = FL_BASE0, 1177 .flags = FL_BASE0,
1168 .num_ports = 4, 1178 .num_ports = 4,
@@ -1988,6 +1998,16 @@ static struct pci_device_id serial_pci_tbl[] = {
1988 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954, 1998 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954,
1989 PCI_SUBVENDOR_ID_SIIG, PCI_SUBDEVICE_ID_SIIG_QUARTET_SERIAL, 0, 0, 1999 PCI_SUBVENDOR_ID_SIIG, PCI_SUBDEVICE_ID_SIIG_QUARTET_SERIAL, 0, 0,
1990 pbn_b0_4_1152000 }, 2000 pbn_b0_4_1152000 },
2001
2002 /*
2003 * The below card is a little controversial since it is the
2004 * subject of a PCI vendor/device ID clash. (See
2005 * www.ussg.iu.edu/hypermail/linux/kernel/0303.1/0516.html).
2006 * For now just used the hex ID 0x950a.
2007 */
2008 { PCI_VENDOR_ID_OXSEMI, 0x950a,
2009 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
2010 pbn_b0_2_1130000 },
1991 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954, 2011 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954,
1992 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2012 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1993 pbn_b0_4_115200 }, 2013 pbn_b0_4_115200 },
diff --git a/drivers/serial/8250_pnp.c b/drivers/serial/8250_pnp.c
index 18c58fb73899..6b321e82cafb 100644
--- a/drivers/serial/8250_pnp.c
+++ b/drivers/serial/8250_pnp.c
@@ -394,7 +394,7 @@ static int __devinit serial_pnp_guess_board(struct pnp_dev *dev, int *flags)
394} 394}
395 395
396static int __devinit 396static int __devinit
397serial_pnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id) 397serial_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
398{ 398{
399 struct uart_port port; 399 struct uart_port port;
400 int ret, line, flags = dev_id->driver_data; 400 int ret, line, flags = dev_id->driver_data;
@@ -406,15 +406,23 @@ serial_pnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id)
406 } 406 }
407 407
408 memset(&port, 0, sizeof(struct uart_port)); 408 memset(&port, 0, sizeof(struct uart_port));
409 port.irq = pnp_irq(dev,0); 409 port.irq = pnp_irq(dev, 0);
410 port.iobase = pnp_port_start(dev, 0); 410 if (pnp_port_valid(dev, 0)) {
411 port.iobase = pnp_port_start(dev, 0);
412 port.iotype = UPIO_PORT;
413 } else if (pnp_mem_valid(dev, 0)) {
414 port.mapbase = pnp_mem_start(dev, 0);
415 port.iotype = UPIO_MEM;
416 port.flags = UPF_IOREMAP;
417 } else
418 return -ENODEV;
411 419
412#ifdef SERIAL_DEBUG_PNP 420#ifdef SERIAL_DEBUG_PNP
413 printk("Setup PNP port: port %x, irq %d, type %d\n", 421 printk("Setup PNP port: port %x, mem 0x%lx, irq %d, type %d\n",
414 port.iobase, port.irq, port.iotype); 422 port.iobase, port.mapbase, port.irq, port.iotype);
415#endif 423#endif
416 424
417 port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF; 425 port.flags |= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF;
418 port.uartclk = 1843200; 426 port.uartclk = 1843200;
419 port.dev = &dev->dev; 427 port.dev = &dev->dev;
420 428
@@ -426,7 +434,7 @@ serial_pnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id)
426 434
427} 435}
428 436
429static void __devexit serial_pnp_remove(struct pnp_dev * dev) 437static void __devexit serial_pnp_remove(struct pnp_dev *dev)
430{ 438{
431 long line = (long)pnp_get_drvdata(dev); 439 long line = (long)pnp_get_drvdata(dev);
432 if (line) 440 if (line)
diff --git a/drivers/serial/cpm_uart/cpm_uart_cpm1.c b/drivers/serial/cpm_uart/cpm_uart_cpm1.c
index 7911912f50c7..8efbd6d1d6a4 100644
--- a/drivers/serial/cpm_uart/cpm_uart_cpm1.c
+++ b/drivers/serial/cpm_uart/cpm_uart_cpm1.c
@@ -185,7 +185,7 @@ int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
185 memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) + 185 memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) +
186 L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize); 186 L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize);
187 if (is_con) { 187 if (is_con) {
188 mem_addr = (u8 *) m8xx_cpm_hostalloc(memsz); 188 mem_addr = (u8 *) cpm_dpram_addr(cpm_dpalloc(memsz, 8));
189 dma_addr = 0; 189 dma_addr = 0;
190 } else 190 } else
191 mem_addr = dma_alloc_coherent(NULL, memsz, &dma_addr, 191 mem_addr = dma_alloc_coherent(NULL, memsz, &dma_addr,
diff --git a/drivers/serial/jsm/jsm.h b/drivers/serial/jsm/jsm.h
index 5bf3c45521f4..18753193f59b 100644
--- a/drivers/serial/jsm/jsm.h
+++ b/drivers/serial/jsm/jsm.h
@@ -89,7 +89,7 @@ enum {
89#define WRITEBUFLEN ((4096) + 4) 89#define WRITEBUFLEN ((4096) + 4)
90#define MYFLIPLEN N_TTY_BUF_SIZE 90#define MYFLIPLEN N_TTY_BUF_SIZE
91 91
92#define JSM_VERSION "jsm: 1.1-1-INKERNEL" 92#define JSM_VERSION "jsm: 1.2-1-INKERNEL"
93#define JSM_PARTNUM "40002438_A-INKERNEL" 93#define JSM_PARTNUM "40002438_A-INKERNEL"
94 94
95struct jsm_board; 95struct jsm_board;
diff --git a/drivers/serial/jsm/jsm_driver.c b/drivers/serial/jsm/jsm_driver.c
index cc5d21300ed3..7e56c7824194 100644
--- a/drivers/serial/jsm/jsm_driver.c
+++ b/drivers/serial/jsm/jsm_driver.c
@@ -22,6 +22,7 @@
22 * Scott H Kilau <Scott_Kilau@digi.com> 22 * Scott H Kilau <Scott_Kilau@digi.com>
23 * Wendy Xiong <wendyx@us.ltcfwd.linux.ibm.com> 23 * Wendy Xiong <wendyx@us.ltcfwd.linux.ibm.com>
24 * 24 *
25 *
25 ***********************************************************************/ 26 ***********************************************************************/
26#include <linux/moduleparam.h> 27#include <linux/moduleparam.h>
27#include <linux/pci.h> 28#include <linux/pci.h>
@@ -42,7 +43,7 @@ struct uart_driver jsm_uart_driver = {
42 .owner = THIS_MODULE, 43 .owner = THIS_MODULE,
43 .driver_name = JSM_DRIVER_NAME, 44 .driver_name = JSM_DRIVER_NAME,
44 .dev_name = "ttyn", 45 .dev_name = "ttyn",
45 .major = 253, 46 .major = 0,
46 .minor = JSM_MINOR_START, 47 .minor = JSM_MINOR_START,
47 .nr = NR_PORTS, 48 .nr = NR_PORTS,
48}; 49};
diff --git a/drivers/serial/jsm/jsm_neo.c b/drivers/serial/jsm/jsm_neo.c
index 3a11a69feb44..6f22b42d9337 100644
--- a/drivers/serial/jsm/jsm_neo.c
+++ b/drivers/serial/jsm/jsm_neo.c
@@ -48,8 +48,9 @@ static inline void neo_pci_posting_flush(struct jsm_board *bd)
48 48
49static void neo_set_cts_flow_control(struct jsm_channel *ch) 49static void neo_set_cts_flow_control(struct jsm_channel *ch)
50{ 50{
51 u8 ier = readb(&ch->ch_neo_uart->ier); 51 u8 ier, efr;
52 u8 efr = readb(&ch->ch_neo_uart->efr); 52 ier = readb(&ch->ch_neo_uart->ier);
53 efr = readb(&ch->ch_neo_uart->efr);
53 54
54 jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Setting CTSFLOW\n"); 55 jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Setting CTSFLOW\n");
55 56
@@ -78,8 +79,9 @@ static void neo_set_cts_flow_control(struct jsm_channel *ch)
78 79
79static void neo_set_rts_flow_control(struct jsm_channel *ch) 80static void neo_set_rts_flow_control(struct jsm_channel *ch)
80{ 81{
81 u8 ier = readb(&ch->ch_neo_uart->ier); 82 u8 ier, efr;
82 u8 efr = readb(&ch->ch_neo_uart->efr); 83 ier = readb(&ch->ch_neo_uart->ier);
84 efr = readb(&ch->ch_neo_uart->efr);
83 85
84 jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Setting RTSFLOW\n"); 86 jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Setting RTSFLOW\n");
85 87
@@ -117,8 +119,9 @@ static void neo_set_rts_flow_control(struct jsm_channel *ch)
117 119
118static void neo_set_ixon_flow_control(struct jsm_channel *ch) 120static void neo_set_ixon_flow_control(struct jsm_channel *ch)
119{ 121{
120 u8 ier = readb(&ch->ch_neo_uart->ier); 122 u8 ier, efr;
121 u8 efr = readb(&ch->ch_neo_uart->efr); 123 ier = readb(&ch->ch_neo_uart->ier);
124 efr = readb(&ch->ch_neo_uart->efr);
122 125
123 jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Setting IXON FLOW\n"); 126 jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Setting IXON FLOW\n");
124 127
@@ -153,8 +156,9 @@ static void neo_set_ixon_flow_control(struct jsm_channel *ch)
153 156
154static void neo_set_ixoff_flow_control(struct jsm_channel *ch) 157static void neo_set_ixoff_flow_control(struct jsm_channel *ch)
155{ 158{
156 u8 ier = readb(&ch->ch_neo_uart->ier); 159 u8 ier, efr;
157 u8 efr = readb(&ch->ch_neo_uart->efr); 160 ier = readb(&ch->ch_neo_uart->ier);
161 efr = readb(&ch->ch_neo_uart->efr);
158 162
159 jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Setting IXOFF FLOW\n"); 163 jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Setting IXOFF FLOW\n");
160 164
@@ -190,8 +194,9 @@ static void neo_set_ixoff_flow_control(struct jsm_channel *ch)
190 194
191static void neo_set_no_input_flow_control(struct jsm_channel *ch) 195static void neo_set_no_input_flow_control(struct jsm_channel *ch)
192{ 196{
193 u8 ier = readb(&ch->ch_neo_uart->ier); 197 u8 ier, efr;
194 u8 efr = readb(&ch->ch_neo_uart->efr); 198 ier = readb(&ch->ch_neo_uart->ier);
199 efr = readb(&ch->ch_neo_uart->efr);
195 200
196 jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Unsetting Input FLOW\n"); 201 jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Unsetting Input FLOW\n");
197 202
@@ -228,8 +233,9 @@ static void neo_set_no_input_flow_control(struct jsm_channel *ch)
228 233
229static void neo_set_no_output_flow_control(struct jsm_channel *ch) 234static void neo_set_no_output_flow_control(struct jsm_channel *ch)
230{ 235{
231 u8 ier = readb(&ch->ch_neo_uart->ier); 236 u8 ier, efr;
232 u8 efr = readb(&ch->ch_neo_uart->efr); 237 ier = readb(&ch->ch_neo_uart->ier);
238 efr = readb(&ch->ch_neo_uart->efr);
233 239
234 jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Unsetting Output FLOW\n"); 240 jsm_printk(PARAM, INFO, &ch->ch_bd->pci_dev, "Unsetting Output FLOW\n");
235 241
diff --git a/drivers/serial/serial_cs.c b/drivers/serial/serial_cs.c
index de0136cc5938..1ae0b381c162 100644
--- a/drivers/serial/serial_cs.c
+++ b/drivers/serial/serial_cs.c
@@ -790,19 +790,19 @@ static struct pcmcia_device_id serial_ids[] = {
790 PCMCIA_PFC_DEVICE_PROD_ID13(1, "Xircom", "CEM56", 0x2e3ee845, 0xa650c32a), 790 PCMCIA_PFC_DEVICE_PROD_ID13(1, "Xircom", "CEM56", 0x2e3ee845, 0xa650c32a),
791 PCMCIA_PFC_DEVICE_PROD_ID13(1, "Xircom", "REM10", 0x2e3ee845, 0x76df1d29), 791 PCMCIA_PFC_DEVICE_PROD_ID13(1, "Xircom", "REM10", 0x2e3ee845, 0x76df1d29),
792 PCMCIA_PFC_DEVICE_PROD_ID13(1, "Xircom", "XEM5600", 0x2e3ee845, 0xf1403719), 792 PCMCIA_PFC_DEVICE_PROD_ID13(1, "Xircom", "XEM5600", 0x2e3ee845, 0xf1403719),
793 PCMCIA_PFC_DEVICE_PROD_ID12(1, "AnyCom", "Fast Ethernet ", 0x578ba6e7, 0x02d92d1e), 793 PCMCIA_PFC_DEVICE_PROD_ID12(1, "AnyCom", "Fast Ethernet + 56K COMBO", 0x578ba6e7, 0xb0ac62c4),
794 PCMCIA_PFC_DEVICE_PROD_ID12(1, "D-Link", "DME336T", 0x1a424a1c, 0xb23897ff), 794 PCMCIA_PFC_DEVICE_PROD_ID12(1, "D-Link", "DME336T", 0x1a424a1c, 0xb23897ff),
795 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Gateway 2000", "XJEM3336", 0xdd9989be, 0x662c394c), 795 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Gateway 2000", "XJEM3336", 0xdd9989be, 0x662c394c),
796 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Grey Cell", "GCS3000", 0x2a151fac, 0x48b932ae), 796 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Grey Cell", "GCS3000", 0x2a151fac, 0x48b932ae),
797 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Linksys", "EtherFast 10&100 + 56K PC Card (PCMLM56)", 0x0733cc81, 0xb3765033), 797 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Linksys", "EtherFast 10&100 + 56K PC Card (PCMLM56)", 0x0733cc81, 0xb3765033),
798 PCMCIA_PFC_DEVICE_PROD_ID12(1, "LINKSYS", "PCMLM336", 0xf7cb0b07, 0x7a821b58), 798 PCMCIA_PFC_DEVICE_PROD_ID12(1, "LINKSYS", "PCMLM336", 0xf7cb0b07, 0x7a821b58),
799 PCMCIA_PFC_DEVICE_PROD_ID12(1, "MEGAHERTZ", "XJEM1144/CCEM1144", 0xf510db04, 0x52d21e1e), 799 PCMCIA_PFC_DEVICE_PROD_ID12(1, "MEGAHERTZ", "XJEM1144/CCEM1144", 0xf510db04, 0x52d21e1e),
800 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f), 800 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Ositech", "Trumpcard:Jack of Diamonds Modem+Ethernet", 0xc2f80cd, 0x656947b9),
801 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Ositech", "Trumpcard", 0x0c2f80cd, 0x0573c29f), 801 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Ositech", "Trumpcard:Jack of Hearts Modem+Ethernet", 0xc2f80cd, 0xdc9ba5ed),
802 PCMCIA_PFC_DEVICE_PROD_ID12(1, "PCMCIAs", "ComboCard", 0xdcfe12d3, 0xcd8906cc), 802 PCMCIA_PFC_DEVICE_PROD_ID12(1, "PCMCIAs", "ComboCard", 0xdcfe12d3, 0xcd8906cc),
803 PCMCIA_PFC_DEVICE_PROD_ID12(1, "PCMCIAs", "LanModem", 0xdcfe12d3, 0xc67c648f), 803 PCMCIA_PFC_DEVICE_PROD_ID12(1, "PCMCIAs", "LanModem", 0xdcfe12d3, 0xc67c648f),
804 PCMCIA_PFC_DEVICE_PROD_ID12(1, "TDK", "GlobalNetworker 3410/3412", 0x1eae9475, 0xd9a93bed), 804 PCMCIA_PFC_DEVICE_PROD_ID12(1, "TDK", "GlobalNetworker 3410/3412", 0x1eae9475, 0xd9a93bed),
805 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Xircom", "CreditCard Ethernet", 0x2e3ee845, 0xc0e778c2), 805 PCMCIA_PFC_DEVICE_PROD_ID12(1, "Xircom", "CreditCard Ethernet+Modem II", 0x2e3ee845, 0xeca401bf),
806 PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x0104, 0x0070), 806 PCMCIA_MFC_DEVICE_MANF_CARD(0, 0x0104, 0x0070),
807 PCMCIA_MFC_DEVICE_MANF_CARD(1, 0x0101, 0x0562), 807 PCMCIA_MFC_DEVICE_MANF_CARD(1, 0x0101, 0x0562),
808 PCMCIA_MFC_DEVICE_MANF_CARD(1, 0x0104, 0x0070), 808 PCMCIA_MFC_DEVICE_MANF_CARD(1, 0x0104, 0x0070),
@@ -840,7 +840,7 @@ static struct pcmcia_device_id serial_ids[] = {
840 PCMCIA_DEVICE_PROD_ID12("Computerboards, Inc.", "PCM-COM422", 0xd0b78f51, 0x7e2d49ed), 840 PCMCIA_DEVICE_PROD_ID12("Computerboards, Inc.", "PCM-COM422", 0xd0b78f51, 0x7e2d49ed),
841 PCMCIA_DEVICE_PROD_ID12("Dr. Neuhaus", "FURY CARD 14K4", 0x76942813, 0x8b96ce65), 841 PCMCIA_DEVICE_PROD_ID12("Dr. Neuhaus", "FURY CARD 14K4", 0x76942813, 0x8b96ce65),
842 PCMCIA_DEVICE_PROD_ID12("Intelligent", "ANGIA FAX/MODEM", 0xb496e65e, 0xf31602a6), 842 PCMCIA_DEVICE_PROD_ID12("Intelligent", "ANGIA FAX/MODEM", 0xb496e65e, 0xf31602a6),
843 PCMCIA_DEVICE_PROD_ID12("Intel", "MODEM 2400", 0x816cc815, 0x23539b80), 843 PCMCIA_DEVICE_PROD_ID12("Intel", "MODEM 2400+", 0x816cc815, 0x412729fb),
844 PCMCIA_DEVICE_PROD_ID12("IOTech Inc ", "PCMCIA Dual RS-232 Serial Port Card", 0x3bd2d898, 0x92abc92f), 844 PCMCIA_DEVICE_PROD_ID12("IOTech Inc ", "PCMCIA Dual RS-232 Serial Port Card", 0x3bd2d898, 0x92abc92f),
845 PCMCIA_DEVICE_PROD_ID12("MACRONIX", "FAX/MODEM", 0x668388b3, 0x3f9bdf2f), 845 PCMCIA_DEVICE_PROD_ID12("MACRONIX", "FAX/MODEM", 0x668388b3, 0x3f9bdf2f),
846 PCMCIA_DEVICE_PROD_ID12("Multi-Tech", "MT1432LT", 0x5f73be51, 0x0b3e2383), 846 PCMCIA_DEVICE_PROD_ID12("Multi-Tech", "MT1432LT", 0x5f73be51, 0x0b3e2383),
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index cd329dd7fb86..85dacc92545a 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -20,6 +20,7 @@ config USB_ARCH_HAS_OHCI
20 default y if SA1111 20 default y if SA1111
21 default y if ARCH_OMAP 21 default y if ARCH_OMAP
22 default y if ARCH_LH7A404 22 default y if ARCH_LH7A404
23 default y if ARCH_S3C2410
23 default y if PXA27x 24 default y if PXA27x
24 # PPC: 25 # PPC:
25 default y if STB03xxx 26 default y if STB03xxx
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index adff5a77e31f..16ecad30e29c 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -980,6 +980,9 @@ static struct usb_device_id acm_ids[] = {
980 { USB_DEVICE(0x0870, 0x0001), /* Metricom GS Modem */ 980 { USB_DEVICE(0x0870, 0x0001), /* Metricom GS Modem */
981 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ 981 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
982 }, 982 },
983 { USB_DEVICE(0x0482, 0x0203), /* KYOCERA AH-K3001V */
984 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
985 },
983 /* control interfaces with various AT-command sets */ 986 /* control interfaces with various AT-command sets */
984 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, 987 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
985 USB_CDC_ACM_PROTO_AT_V25TER) }, 988 USB_CDC_ACM_PROTO_AT_V25TER) },
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 787c27a63c51..f86bf1454e21 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -569,8 +569,11 @@ static int proc_control(struct dev_state *ps, void __user *arg)
569 free_page((unsigned long)tbuf); 569 free_page((unsigned long)tbuf);
570 return -EINVAL; 570 return -EINVAL;
571 } 571 }
572 snoop(&dev->dev, "control read: bRequest=%02x bRrequestType=%02x wValue=%04x wIndex=%04x\n", 572 snoop(&dev->dev, "control read: bRequest=%02x "
573 ctrl.bRequest, ctrl.bRequestType, ctrl.wValue, ctrl.wIndex); 573 "bRrequestType=%02x wValue=%04x "
574 "wIndex=%04x wLength=%04x\n",
575 ctrl.bRequest, ctrl.bRequestType, ctrl.wValue,
576 ctrl.wIndex, ctrl.wLength);
574 577
575 usb_unlock_device(dev); 578 usb_unlock_device(dev);
576 i = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ctrl.bRequest, ctrl.bRequestType, 579 i = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ctrl.bRequest, ctrl.bRequestType,
@@ -579,11 +582,11 @@ static int proc_control(struct dev_state *ps, void __user *arg)
579 if ((i > 0) && ctrl.wLength) { 582 if ((i > 0) && ctrl.wLength) {
580 if (usbfs_snoop) { 583 if (usbfs_snoop) {
581 dev_info(&dev->dev, "control read: data "); 584 dev_info(&dev->dev, "control read: data ");
582 for (j = 0; j < ctrl.wLength; ++j) 585 for (j = 0; j < i; ++j)
583 printk ("%02x ", (unsigned char)(tbuf)[j]); 586 printk ("%02x ", (unsigned char)(tbuf)[j]);
584 printk("\n"); 587 printk("\n");
585 } 588 }
586 if (copy_to_user(ctrl.data, tbuf, ctrl.wLength)) { 589 if (copy_to_user(ctrl.data, tbuf, i)) {
587 free_page((unsigned long)tbuf); 590 free_page((unsigned long)tbuf);
588 return -EFAULT; 591 return -EFAULT;
589 } 592 }
@@ -595,8 +598,11 @@ static int proc_control(struct dev_state *ps, void __user *arg)
595 return -EFAULT; 598 return -EFAULT;
596 } 599 }
597 } 600 }
598 snoop(&dev->dev, "control write: bRequest=%02x bRrequestType=%02x wValue=%04x wIndex=%04x\n", 601 snoop(&dev->dev, "control write: bRequest=%02x "
599 ctrl.bRequest, ctrl.bRequestType, ctrl.wValue, ctrl.wIndex); 602 "bRrequestType=%02x wValue=%04x "
603 "wIndex=%04x wLength=%04x\n",
604 ctrl.bRequest, ctrl.bRequestType, ctrl.wValue,
605 ctrl.wIndex, ctrl.wLength);
600 if (usbfs_snoop) { 606 if (usbfs_snoop) {
601 dev_info(&dev->dev, "control write: data: "); 607 dev_info(&dev->dev, "control write: data: ");
602 for (j = 0; j < ctrl.wLength; ++j) 608 for (j = 0; j < ctrl.wLength; ++j)
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 8616356f55e8..79422a3b07bc 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -939,9 +939,9 @@ long usb_calc_bus_time (int speed, int is_input, int isoc, int bytecount)
939 case USB_SPEED_HIGH: /* ISOC or INTR */ 939 case USB_SPEED_HIGH: /* ISOC or INTR */
940 // FIXME adjust for input vs output 940 // FIXME adjust for input vs output
941 if (isoc) 941 if (isoc)
942 tmp = HS_USECS (bytecount); 942 tmp = HS_NSECS_ISO (bytecount);
943 else 943 else
944 tmp = HS_USECS_ISO (bytecount); 944 tmp = HS_NSECS (bytecount);
945 return tmp; 945 return tmp;
946 default: 946 default:
947 pr_debug ("%s: bogus device speed!\n", usbcore_name); 947 pr_debug ("%s: bogus device speed!\n", usbcore_name);
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
index 67db4a999b93..28055f95645b 100644
--- a/drivers/usb/core/hcd.h
+++ b/drivers/usb/core/hcd.h
@@ -334,17 +334,19 @@ extern void usb_release_bandwidth (struct usb_device *dev, struct urb *urb,
334extern int usb_check_bandwidth (struct usb_device *dev, struct urb *urb); 334extern int usb_check_bandwidth (struct usb_device *dev, struct urb *urb);
335 335
336/* 336/*
337 * Ceiling microseconds (typical) for that many bytes at high speed 337 * Ceiling [nano/micro]seconds (typical) for that many bytes at high speed
338 * ISO is a bit less, no ACK ... from USB 2.0 spec, 5.11.3 (and needed 338 * ISO is a bit less, no ACK ... from USB 2.0 spec, 5.11.3 (and needed
339 * to preallocate bandwidth) 339 * to preallocate bandwidth)
340 */ 340 */
341#define USB2_HOST_DELAY 5 /* nsec, guess */ 341#define USB2_HOST_DELAY 5 /* nsec, guess */
342#define HS_USECS(bytes) NS_TO_US ( ((55 * 8 * 2083)/1000) \ 342#define HS_NSECS(bytes) ( ((55 * 8 * 2083)/1000) \
343 + ((2083UL * (3167 + BitTime (bytes)))/1000) \ 343 + ((2083UL * (3167 + BitTime (bytes)))/1000) \
344 + USB2_HOST_DELAY) 344 + USB2_HOST_DELAY)
345#define HS_USECS_ISO(bytes) NS_TO_US ( ((38 * 8 * 2083)/1000) \ 345#define HS_NSECS_ISO(bytes) ( ((38 * 8 * 2083)/1000) \
346 + ((2083UL * (3167 + BitTime (bytes)))/1000) \ 346 + ((2083UL * (3167 + BitTime (bytes)))/1000) \
347 + USB2_HOST_DELAY) 347 + USB2_HOST_DELAY)
348#define HS_USECS(bytes) NS_TO_US (HS_NSECS(bytes))
349#define HS_USECS_ISO(bytes) NS_TO_US (HS_NSECS_ISO(bytes))
348 350
349extern long usb_calc_bus_time (int speed, int is_input, 351extern long usb_calc_bus_time (int speed, int is_input,
350 int isoc, int bytecount); 352 int isoc, int bytecount);
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index a428ef479bd7..88d1b376f67c 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -985,8 +985,10 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
985 for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { 985 for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) {
986 struct usb_interface *interface; 986 struct usb_interface *interface;
987 987
988 /* remove this interface */ 988 /* remove this interface if it has been registered */
989 interface = dev->actconfig->interface[i]; 989 interface = dev->actconfig->interface[i];
990 if (!klist_node_attached(&interface->dev.knode_bus))
991 continue;
990 dev_dbg (&dev->dev, "unregistering interface %s\n", 992 dev_dbg (&dev->dev, "unregistering interface %s\n",
991 interface->dev.bus_id); 993 interface->dev.bus_id);
992 usb_remove_sysfs_intf_files(interface); 994 usb_remove_sysfs_intf_files(interface);
@@ -1439,7 +1441,7 @@ free_interfaces:
1439 } 1441 }
1440 } 1442 }
1441 1443
1442 return ret; 1444 return 0;
1443} 1445}
1444 1446
1445// synchronous request completion model 1447// synchronous request completion model
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index 50cb01831075..b01efb6b36f6 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -527,7 +527,7 @@ show_periodic (struct class_device *class_dev, char *buf)
527 p.qh->period, 527 p.qh->period,
528 le32_to_cpup (&p.qh->hw_info2) 528 le32_to_cpup (&p.qh->hw_info2)
529 /* uframe masks */ 529 /* uframe masks */
530 & 0xffff, 530 & (QH_CMASK | QH_SMASK),
531 p.qh); 531 p.qh);
532 size -= temp; 532 size -= temp;
533 next += temp; 533 next += temp;
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index d74b2d68a50e..20df01a79b2e 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -222,7 +222,7 @@ __acquires(ehci->lock)
222 struct ehci_qh *qh = (struct ehci_qh *) urb->hcpriv; 222 struct ehci_qh *qh = (struct ehci_qh *) urb->hcpriv;
223 223
224 /* S-mask in a QH means it's an interrupt urb */ 224 /* S-mask in a QH means it's an interrupt urb */
225 if ((qh->hw_info2 & __constant_cpu_to_le32 (0x00ff)) != 0) { 225 if ((qh->hw_info2 & __constant_cpu_to_le32 (QH_SMASK)) != 0) {
226 226
227 /* ... update hc-wide periodic stats (for usbfs) */ 227 /* ... update hc-wide periodic stats (for usbfs) */
228 ehci_to_hcd(ehci)->self.bandwidth_int_reqs--; 228 ehci_to_hcd(ehci)->self.bandwidth_int_reqs--;
@@ -428,7 +428,8 @@ halt:
428 /* should be rare for periodic transfers, 428 /* should be rare for periodic transfers,
429 * except maybe high bandwidth ... 429 * except maybe high bandwidth ...
430 */ 430 */
431 if (qh->period) { 431 if ((__constant_cpu_to_le32 (QH_SMASK)
432 & qh->hw_info2) != 0) {
432 intr_deschedule (ehci, qh); 433 intr_deschedule (ehci, qh);
433 (void) qh_schedule (ehci, qh); 434 (void) qh_schedule (ehci, qh);
434 } else 435 } else
@@ -657,8 +658,8 @@ qh_make (
657 * For control/bulk requests, the HC or TT handles these. 658 * For control/bulk requests, the HC or TT handles these.
658 */ 659 */
659 if (type == PIPE_INTERRUPT) { 660 if (type == PIPE_INTERRUPT) {
660 qh->usecs = usb_calc_bus_time (USB_SPEED_HIGH, is_input, 0, 661 qh->usecs = NS_TO_US (usb_calc_bus_time (USB_SPEED_HIGH, is_input, 0,
661 hb_mult (maxp) * max_packet (maxp)); 662 hb_mult (maxp) * max_packet (maxp)));
662 qh->start = NO_FRAME; 663 qh->start = NO_FRAME;
663 664
664 if (urb->dev->speed == USB_SPEED_HIGH) { 665 if (urb->dev->speed == USB_SPEED_HIGH) {
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 9af4f64532a9..b56f25864ed6 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -301,7 +301,7 @@ static int qh_link_periodic (struct ehci_hcd *ehci, struct ehci_qh *qh)
301 301
302 dev_dbg (&qh->dev->dev, 302 dev_dbg (&qh->dev->dev,
303 "link qh%d-%04x/%p start %d [%d/%d us]\n", 303 "link qh%d-%04x/%p start %d [%d/%d us]\n",
304 period, le32_to_cpup (&qh->hw_info2) & 0xffff, 304 period, le32_to_cpup (&qh->hw_info2) & (QH_CMASK | QH_SMASK),
305 qh, qh->start, qh->usecs, qh->c_usecs); 305 qh, qh->start, qh->usecs, qh->c_usecs);
306 306
307 /* high bandwidth, or otherwise every microframe */ 307 /* high bandwidth, or otherwise every microframe */
@@ -385,7 +385,8 @@ static void qh_unlink_periodic (struct ehci_hcd *ehci, struct ehci_qh *qh)
385 385
386 dev_dbg (&qh->dev->dev, 386 dev_dbg (&qh->dev->dev,
387 "unlink qh%d-%04x/%p start %d [%d/%d us]\n", 387 "unlink qh%d-%04x/%p start %d [%d/%d us]\n",
388 qh->period, le32_to_cpup (&qh->hw_info2) & 0xffff, 388 qh->period,
389 le32_to_cpup (&qh->hw_info2) & (QH_CMASK | QH_SMASK),
389 qh, qh->start, qh->usecs, qh->c_usecs); 390 qh, qh->start, qh->usecs, qh->c_usecs);
390 391
391 /* qh->qh_next still "live" to HC */ 392 /* qh->qh_next still "live" to HC */
@@ -411,7 +412,7 @@ static void intr_deschedule (struct ehci_hcd *ehci, struct ehci_qh *qh)
411 * active high speed queues may need bigger delays... 412 * active high speed queues may need bigger delays...
412 */ 413 */
413 if (list_empty (&qh->qtd_list) 414 if (list_empty (&qh->qtd_list)
414 || (__constant_cpu_to_le32 (0x0ff << 8) 415 || (__constant_cpu_to_le32 (QH_CMASK)
415 & qh->hw_info2) != 0) 416 & qh->hw_info2) != 0)
416 wait = 2; 417 wait = 2;
417 else 418 else
@@ -533,7 +534,7 @@ static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh)
533 534
534 /* reuse the previous schedule slots, if we can */ 535 /* reuse the previous schedule slots, if we can */
535 if (frame < qh->period) { 536 if (frame < qh->period) {
536 uframe = ffs (le32_to_cpup (&qh->hw_info2) & 0x00ff); 537 uframe = ffs (le32_to_cpup (&qh->hw_info2) & QH_SMASK);
537 status = check_intr_schedule (ehci, frame, --uframe, 538 status = check_intr_schedule (ehci, frame, --uframe,
538 qh, &c_mask); 539 qh, &c_mask);
539 } else { 540 } else {
@@ -569,10 +570,10 @@ static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh)
569 qh->start = frame; 570 qh->start = frame;
570 571
571 /* reset S-frame and (maybe) C-frame masks */ 572 /* reset S-frame and (maybe) C-frame masks */
572 qh->hw_info2 &= __constant_cpu_to_le32 (~0xffff); 573 qh->hw_info2 &= __constant_cpu_to_le32(~(QH_CMASK | QH_SMASK));
573 qh->hw_info2 |= qh->period 574 qh->hw_info2 |= qh->period
574 ? cpu_to_le32 (1 << uframe) 575 ? cpu_to_le32 (1 << uframe)
575 : __constant_cpu_to_le32 (0xff); 576 : __constant_cpu_to_le32 (QH_SMASK);
576 qh->hw_info2 |= c_mask; 577 qh->hw_info2 |= c_mask;
577 } else 578 } else
578 ehci_dbg (ehci, "reused qh %p schedule\n", qh); 579 ehci_dbg (ehci, "reused qh %p schedule\n", qh);
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index 4df498231752..a7542157534c 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -385,6 +385,11 @@ struct ehci_qh {
385 __le32 hw_info1; /* see EHCI 3.6.2 */ 385 __le32 hw_info1; /* see EHCI 3.6.2 */
386#define QH_HEAD 0x00008000 386#define QH_HEAD 0x00008000
387 __le32 hw_info2; /* see EHCI 3.6.2 */ 387 __le32 hw_info2; /* see EHCI 3.6.2 */
388#define QH_SMASK 0x000000ff
389#define QH_CMASK 0x0000ff00
390#define QH_HUBADDR 0x007f0000
391#define QH_HUBPORT 0x3f800000
392#define QH_MULT 0xc0000000
388 __le32 hw_current; /* qtd list - see EHCI 3.6.4 */ 393 __le32 hw_current; /* qtd list - see EHCI 3.6.4 */
389 394
390 /* qtd overlay (hardware parts of a struct ehci_qtd) */ 395 /* qtd overlay (hardware parts of a struct ehci_qtd) */
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index 50b1970fe6b6..76cb496c5836 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -229,9 +229,11 @@ static void preproc_atl_queue(struct isp116x *isp116x)
229 struct isp116x_ep *ep; 229 struct isp116x_ep *ep;
230 struct urb *urb; 230 struct urb *urb;
231 struct ptd *ptd; 231 struct ptd *ptd;
232 u16 toggle = 0, dir = PTD_DIR_SETUP, len; 232 u16 len;
233 233
234 for (ep = isp116x->atl_active; ep; ep = ep->active) { 234 for (ep = isp116x->atl_active; ep; ep = ep->active) {
235 u16 toggle = 0, dir = PTD_DIR_SETUP;
236
235 BUG_ON(list_empty(&ep->hep->urb_list)); 237 BUG_ON(list_empty(&ep->hep->urb_list));
236 urb = container_of(ep->hep->urb_list.next, 238 urb = container_of(ep->hep->urb_list.next,
237 struct urb, urb_list); 239 struct urb, urb_list);
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 68decab280dd..56b43f2a0e52 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -887,6 +887,10 @@ MODULE_LICENSE ("GPL");
887#include "ohci-sa1111.c" 887#include "ohci-sa1111.c"
888#endif 888#endif
889 889
890#ifdef CONFIG_ARCH_S3C2410
891#include "ohci-s3c2410.c"
892#endif
893
890#ifdef CONFIG_ARCH_OMAP 894#ifdef CONFIG_ARCH_OMAP
891#include "ohci-omap.c" 895#include "ohci-omap.c"
892#endif 896#endif
@@ -909,6 +913,7 @@ MODULE_LICENSE ("GPL");
909 913
910#if !(defined(CONFIG_PCI) \ 914#if !(defined(CONFIG_PCI) \
911 || defined(CONFIG_SA1111) \ 915 || defined(CONFIG_SA1111) \
916 || defined(CONFIG_ARCH_S3C2410) \
912 || defined(CONFIG_ARCH_OMAP) \ 917 || defined(CONFIG_ARCH_OMAP) \
913 || defined (CONFIG_ARCH_LH7A404) \ 918 || defined (CONFIG_ARCH_LH7A404) \
914 || defined (CONFIG_PXA27x) \ 919 || defined (CONFIG_PXA27x) \
diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c
new file mode 100644
index 000000000000..e9401662503c
--- /dev/null
+++ b/drivers/usb/host/ohci-s3c2410.c
@@ -0,0 +1,496 @@
1/*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * (C) Copyright 2002 Hewlett-Packard Company
7 *
8 * USB Bus Glue for Samsung S3C2410
9 *
10 * Written by Christopher Hoover <ch@hpl.hp.com>
11 * Based on fragments of previous driver by Rusell King et al.
12 *
13 * Modified for S3C2410 from ohci-sa1111.c, ohci-omap.c and ohci-lh7a40.c
14 * by Ben Dooks, <ben@simtec.co.uk>
15 * Copyright (C) 2004 Simtec Electronics
16 *
17 * Thanks to basprog@mail.ru for updates to newer kernels
18 *
19 * This file is licenced under the GPL.
20*/
21
22#include <asm/hardware.h>
23#include <asm/mach-types.h>
24#include <asm/hardware/clock.h>
25#include <asm/arch/usb-control.h>
26
27#define valid_port(idx) ((idx) == 1 || (idx) == 2)
28
29/* clock device associated with the hcd */
30
31static struct clk *clk;
32
33/* forward definitions */
34
35static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc);
36
37/* conversion functions */
38
39struct s3c2410_hcd_info *to_s3c2410_info(struct usb_hcd *hcd)
40{
41 return hcd->self.controller->platform_data;
42}
43
44static void s3c2410_start_hc(struct platform_device *dev, struct usb_hcd *hcd)
45{
46 struct s3c2410_hcd_info *info = dev->dev.platform_data;
47
48 dev_dbg(&dev->dev, "s3c2410_start_hc:\n");
49 clk_enable(clk);
50
51 if (info != NULL) {
52 info->hcd = hcd;
53 info->report_oc = s3c2410_hcd_oc;
54
55 if (info->enable_oc != NULL) {
56 (info->enable_oc)(info, 1);
57 }
58 }
59}
60
61static void s3c2410_stop_hc(struct platform_device *dev)
62{
63 struct s3c2410_hcd_info *info = dev->dev.platform_data;
64
65 dev_dbg(&dev->dev, "s3c2410_stop_hc:\n");
66
67 if (info != NULL) {
68 info->report_oc = NULL;
69 info->hcd = NULL;
70
71 if (info->enable_oc != NULL) {
72 (info->enable_oc)(info, 0);
73 }
74 }
75
76 clk_disable(clk);
77}
78
79/* ohci_s3c2410_hub_status_data
80 *
81 * update the status data from the hub with anything that
82 * has been detected by our system
83*/
84
85static int
86ohci_s3c2410_hub_status_data (struct usb_hcd *hcd, char *buf)
87{
88 struct s3c2410_hcd_info *info = to_s3c2410_info(hcd);
89 struct s3c2410_hcd_port *port;
90 int orig;
91 int portno;
92
93 orig = ohci_hub_status_data (hcd, buf);
94
95 if (info == NULL)
96 return orig;
97
98 port = &info->port[0];
99
100 /* mark any changed port as changed */
101
102 for (portno = 0; portno < 2; port++, portno++) {
103 if (port->oc_changed == 1 &&
104 port->flags & S3C_HCDFLG_USED) {
105 dev_dbg(hcd->self.controller,
106 "oc change on port %d\n", portno);
107
108 if (orig < 1)
109 orig = 1;
110
111 buf[0] |= 1<<(portno+1);
112 }
113 }
114
115 return orig;
116}
117
118/* s3c2410_usb_set_power
119 *
120 * configure the power on a port, by calling the platform device
121 * routine registered with the platform device
122*/
123
124static void s3c2410_usb_set_power(struct s3c2410_hcd_info *info,
125 int port, int to)
126{
127 if (info == NULL)
128 return;
129
130 if (info->power_control != NULL) {
131 info->port[port-1].power = to;
132 (info->power_control)(port, to);
133 }
134}
135
136/* ohci_s3c2410_hub_control
137 *
138 * look at control requests to the hub, and see if we need
139 * to take any action or over-ride the results from the
140 * request.
141*/
142
143static int ohci_s3c2410_hub_control (
144 struct usb_hcd *hcd,
145 u16 typeReq,
146 u16 wValue,
147 u16 wIndex,
148 char *buf,
149 u16 wLength)
150{
151 struct s3c2410_hcd_info *info = to_s3c2410_info(hcd);
152 struct usb_hub_descriptor *desc;
153 int ret = -EINVAL;
154 u32 *data = (u32 *)buf;
155
156 dev_dbg(hcd->self.controller,
157 "s3c2410_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n",
158 hcd, typeReq, wValue, wIndex, buf, wLength);
159
160 /* if we are only an humble host without any special capabilites
161 * process the request straight away and exit */
162
163 if (info == NULL) {
164 ret = ohci_hub_control(hcd, typeReq, wValue,
165 wIndex, buf, wLength);
166 goto out;
167 }
168
169 /* check the request to see if it needs handling */
170
171 switch (typeReq) {
172 case SetPortFeature:
173 if (wValue == USB_PORT_FEAT_POWER) {
174 dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n");
175 s3c2410_usb_set_power(info, wIndex, 1);
176 goto out;
177 }
178 break;
179
180 case ClearPortFeature:
181 switch (wValue) {
182 case USB_PORT_FEAT_C_OVER_CURRENT:
183 dev_dbg(hcd->self.controller,
184 "ClearPortFeature: C_OVER_CURRENT\n");
185
186 if (valid_port(wIndex)) {
187 info->port[wIndex-1].oc_changed = 0;
188 info->port[wIndex-1].oc_status = 0;
189 }
190
191 goto out;
192
193 case USB_PORT_FEAT_OVER_CURRENT:
194 dev_dbg(hcd->self.controller,
195 "ClearPortFeature: OVER_CURRENT\n");
196
197 if (valid_port(wIndex)) {
198 info->port[wIndex-1].oc_status = 0;
199 }
200
201 goto out;
202
203 case USB_PORT_FEAT_POWER:
204 dev_dbg(hcd->self.controller,
205 "ClearPortFeature: POWER\n");
206
207 if (valid_port(wIndex)) {
208 s3c2410_usb_set_power(info, wIndex, 0);
209 return 0;
210 }
211 }
212 break;
213 }
214
215 ret = ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength);
216 if (ret)
217 goto out;
218
219 switch (typeReq) {
220 case GetHubDescriptor:
221
222 /* update the hub's descriptor */
223
224 desc = (struct usb_hub_descriptor *)buf;
225
226 if (info->power_control == NULL)
227 return ret;
228
229 dev_dbg(hcd->self.controller, "wHubCharacteristics 0x%04x\n",
230 desc->wHubCharacteristics);
231
232 /* remove the old configurations for power-switching, and
233 * over-current protection, and insert our new configuration
234 */
235
236 desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_LPSM);
237 desc->wHubCharacteristics |= cpu_to_le16(0x0001);
238
239 if (info->enable_oc) {
240 desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_OCPM);
241 desc->wHubCharacteristics |= cpu_to_le16(0x0008|0x0001);
242 }
243
244 dev_dbg(hcd->self.controller, "wHubCharacteristics after 0x%04x\n",
245 desc->wHubCharacteristics);
246
247 return ret;
248
249 case GetPortStatus:
250 /* check port status */
251
252 dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex);
253
254 if (valid_port(wIndex)) {
255 if (info->port[wIndex-1].oc_changed) {
256 *data |= cpu_to_le32(RH_PS_OCIC);
257 }
258
259 if (info->port[wIndex-1].oc_status) {
260 *data |= cpu_to_le32(RH_PS_POCI);
261 }
262 }
263 }
264
265 out:
266 return ret;
267}
268
269/* s3c2410_hcd_oc
270 *
271 * handle an over-current report
272*/
273
274static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc)
275{
276 struct s3c2410_hcd_port *port;
277 struct usb_hcd *hcd;
278 unsigned long flags;
279 int portno;
280
281 if (info == NULL)
282 return;
283
284 port = &info->port[0];
285 hcd = info->hcd;
286
287 local_irq_save(flags);
288
289 for (portno = 0; portno < 2; port++, portno++) {
290 if (port_oc & (1<<portno) &&
291 port->flags & S3C_HCDFLG_USED) {
292 port->oc_status = 1;
293 port->oc_changed = 1;
294
295 /* ok, once over-current is detected,
296 the port needs to be powered down */
297 s3c2410_usb_set_power(info, portno+1, 0);
298 }
299 }
300
301 local_irq_restore(flags);
302}
303
304/* may be called without controller electrically present */
305/* may be called with controller, bus, and devices active */
306
307/*
308 * usb_hcd_s3c2410_remove - shutdown processing for HCD
309 * @dev: USB Host Controller being removed
310 * Context: !in_interrupt()
311 *
312 * Reverses the effect of usb_hcd_3c2410_probe(), first invoking
313 * the HCD's stop() method. It is always called from a thread
314 * context, normally "rmmod", "apmd", or something similar.
315 *
316*/
317
318void usb_hcd_s3c2410_remove (struct usb_hcd *hcd, struct platform_device *dev)
319{
320 usb_remove_hcd(hcd);
321 s3c2410_stop_hc(dev);
322 iounmap(hcd->regs);
323 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
324 usb_put_hcd(hcd);
325}
326
327/**
328 * usb_hcd_s3c2410_probe - initialize S3C2410-based HCDs
329 * Context: !in_interrupt()
330 *
331 * Allocates basic resources for this USB host controller, and
332 * then invokes the start() method for the HCD associated with it
333 * through the hotplug entry's driver_data.
334 *
335 */
336int usb_hcd_s3c2410_probe (const struct hc_driver *driver,
337 struct platform_device *dev)
338{
339 struct usb_hcd *hcd = NULL;
340 int retval;
341
342 s3c2410_usb_set_power(dev->dev.platform_data, 0, 1);
343 s3c2410_usb_set_power(dev->dev.platform_data, 1, 1);
344
345 hcd = usb_create_hcd(driver, &dev->dev, "s3c24xx");
346 if (hcd == NULL)
347 return -ENOMEM;
348
349 hcd->rsrc_start = dev->resource[0].start;
350 hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
351
352 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
353 dev_err(&dev->dev, "request_mem_region failed");
354 retval = -EBUSY;
355 goto err0;
356 }
357
358 clk = clk_get(NULL, "usb-host");
359 if (IS_ERR(clk)) {
360 dev_err(&dev->dev, "cannot get usb-host clock\n");
361 retval = -ENOENT;
362 goto err1;
363 }
364
365 clk_use(clk);
366 s3c2410_start_hc(dev, hcd);
367
368 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
369 if (!hcd->regs) {
370 dev_err(&dev->dev, "ioremap failed\n");
371 retval = -ENOMEM;
372 goto err2;
373 }
374
375 ohci_hcd_init(hcd_to_ohci(hcd));
376
377 retval = usb_add_hcd(hcd, dev->resource[1].start, SA_INTERRUPT);
378 if (retval != 0)
379 goto err2;
380
381 return 0;
382
383 err2:
384 s3c2410_stop_hc(dev);
385 iounmap(hcd->regs);
386 clk_unuse(clk);
387 clk_put(clk);
388
389 err1:
390 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
391
392 err0:
393 usb_put_hcd(hcd);
394 return retval;
395}
396
397/*-------------------------------------------------------------------------*/
398
399static int
400ohci_s3c2410_start (struct usb_hcd *hcd)
401{
402 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
403 int ret;
404
405 if ((ret = ohci_init(ohci)) < 0)
406 return ret;
407
408 if ((ret = ohci_run (ohci)) < 0) {
409 err ("can't start %s", hcd->self.bus_name);
410 ohci_stop (hcd);
411 return ret;
412 }
413
414 return 0;
415}
416
417
418static const struct hc_driver ohci_s3c2410_hc_driver = {
419 .description = hcd_name,
420 .product_desc = "S3C24XX OHCI",
421 .hcd_priv_size = sizeof(struct ohci_hcd),
422
423 /*
424 * generic hardware linkage
425 */
426 .irq = ohci_irq,
427 .flags = HCD_USB11 | HCD_MEMORY,
428
429 /*
430 * basic lifecycle operations
431 */
432 .start = ohci_s3c2410_start,
433 .stop = ohci_stop,
434
435 /*
436 * managing i/o requests and associated device resources
437 */
438 .urb_enqueue = ohci_urb_enqueue,
439 .urb_dequeue = ohci_urb_dequeue,
440 .endpoint_disable = ohci_endpoint_disable,
441
442 /*
443 * scheduling support
444 */
445 .get_frame_number = ohci_get_frame,
446
447 /*
448 * root hub support
449 */
450 .hub_status_data = ohci_s3c2410_hub_status_data,
451 .hub_control = ohci_s3c2410_hub_control,
452
453#if defined(CONFIG_USB_SUSPEND) && 0
454 .hub_suspend = ohci_hub_suspend,
455 .hub_resume = ohci_hub_resume,
456#endif
457};
458
459/* device driver */
460
461static int ohci_hcd_s3c2410_drv_probe(struct device *dev)
462{
463 struct platform_device *pdev = to_platform_device(dev);
464 return usb_hcd_s3c2410_probe(&ohci_s3c2410_hc_driver, pdev);
465}
466
467static int ohci_hcd_s3c2410_drv_remove(struct device *dev)
468{
469 struct platform_device *pdev = to_platform_device(dev);
470 struct usb_hcd *hcd = dev_get_drvdata(dev);
471
472 usb_hcd_s3c2410_remove(hcd, pdev);
473 return 0;
474}
475
476static struct device_driver ohci_hcd_s3c2410_driver = {
477 .name = "s3c2410-ohci",
478 .bus = &platform_bus_type,
479 .probe = ohci_hcd_s3c2410_drv_probe,
480 .remove = ohci_hcd_s3c2410_drv_remove,
481 /*.suspend = ohci_hcd_s3c2410_drv_suspend, */
482 /*.resume = ohci_hcd_s3c2410_drv_resume, */
483};
484
485static int __init ohci_hcd_s3c2410_init (void)
486{
487 return driver_register(&ohci_hcd_s3c2410_driver);
488}
489
490static void __exit ohci_hcd_s3c2410_cleanup (void)
491{
492 driver_unregister(&ohci_hcd_s3c2410_driver);
493}
494
495module_init (ohci_hcd_s3c2410_init);
496module_exit (ohci_hcd_s3c2410_cleanup);
diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c
index 7d21a4f5c425..c84e1486054f 100644
--- a/drivers/usb/image/microtek.c
+++ b/drivers/usb/image/microtek.c
@@ -361,8 +361,7 @@ int mts_scsi_queuecommand (Scsi_Cmnd *srb, mts_scsi_cmnd_callback callback );
361static void mts_transfer_cleanup( struct urb *transfer ); 361static void mts_transfer_cleanup( struct urb *transfer );
362static void mts_do_sg(struct urb * transfer, struct pt_regs *regs); 362static void mts_do_sg(struct urb * transfer, struct pt_regs *regs);
363 363
364 364static inline
365inline static
366void mts_int_submit_urb (struct urb* transfer, 365void mts_int_submit_urb (struct urb* transfer,
367 int pipe, 366 int pipe,
368 void* data, 367 void* data,
diff --git a/drivers/usb/input/acecad.c b/drivers/usb/input/acecad.c
index ebcf7c955800..13532f3e3efc 100644
--- a/drivers/usb/input/acecad.c
+++ b/drivers/usb/input/acecad.c
@@ -31,6 +31,7 @@
31#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/init.h> 32#include <linux/init.h>
33#include <linux/usb.h> 33#include <linux/usb.h>
34#include <linux/usb_input.h>
34 35
35/* 36/*
36 * Version Information 37 * Version Information
@@ -87,8 +88,8 @@ static void usb_acecad_irq(struct urb *urb, struct pt_regs *regs)
87 if (prox) { 88 if (prox) {
88 int x = data[1] | (data[2] << 8); 89 int x = data[1] | (data[2] << 8);
89 int y = data[3] | (data[4] << 8); 90 int y = data[3] | (data[4] << 8);
90 /*Pressure should compute the same way for flair and 302*/ 91 /* Pressure should compute the same way for flair and 302 */
91 int pressure = data[5] | ((int)data[6] << 8); 92 int pressure = data[5] | (data[6] << 8);
92 int touch = data[0] & 0x01; 93 int touch = data[0] & 0x01;
93 int stylus = (data[0] & 0x10) >> 4; 94 int stylus = (data[0] & 0x10) >> 4;
94 int stylus2 = (data[0] & 0x20) >> 5; 95 int stylus2 = (data[0] & 0x20) >> 5;
@@ -104,9 +105,9 @@ static void usb_acecad_irq(struct urb *urb, struct pt_regs *regs)
104 input_sync(dev); 105 input_sync(dev);
105 106
106resubmit: 107resubmit:
107 status = usb_submit_urb (urb, GFP_ATOMIC); 108 status = usb_submit_urb(urb, GFP_ATOMIC);
108 if (status) 109 if (status)
109 err ("can't resubmit intr, %s-%s/input0, status %d", 110 err("can't resubmit intr, %s-%s/input0, status %d",
110 acecad->usbdev->bus->bus_name, acecad->usbdev->devpath, status); 111 acecad->usbdev->bus->bus_name, acecad->usbdev->devpath, status);
111} 112}
112 113
@@ -212,10 +213,7 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_
212 213
213 acecad->dev.name = acecad->name; 214 acecad->dev.name = acecad->name;
214 acecad->dev.phys = acecad->phys; 215 acecad->dev.phys = acecad->phys;
215 acecad->dev.id.bustype = BUS_USB; 216 usb_to_input_id(dev, &acecad->dev.id);
216 acecad->dev.id.vendor = le16_to_cpu(dev->descriptor.idVendor);
217 acecad->dev.id.product = le16_to_cpu(dev->descriptor.idProduct);
218 acecad->dev.id.version = le16_to_cpu(dev->descriptor.bcdDevice);
219 acecad->dev.dev = &intf->dev; 217 acecad->dev.dev = &intf->dev;
220 218
221 usb_fill_int_urb(acecad->irq, dev, pipe, 219 usb_fill_int_urb(acecad->irq, dev, pipe,
diff --git a/drivers/usb/input/aiptek.c b/drivers/usb/input/aiptek.c
index 6bb0f25e8e93..cd0cbfe20723 100644
--- a/drivers/usb/input/aiptek.c
+++ b/drivers/usb/input/aiptek.c
@@ -77,6 +77,7 @@
77#include <linux/module.h> 77#include <linux/module.h>
78#include <linux/init.h> 78#include <linux/init.h>
79#include <linux/usb.h> 79#include <linux/usb.h>
80#include <linux/usb_input.h>
80#include <linux/sched.h> 81#include <linux/sched.h>
81#include <asm/uaccess.h> 82#include <asm/uaccess.h>
82#include <asm/unaligned.h> 83#include <asm/unaligned.h>
@@ -2125,10 +2126,7 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
2125 aiptek->inputdev.absflat[ABS_WHEEL] = 0; 2126 aiptek->inputdev.absflat[ABS_WHEEL] = 0;
2126 aiptek->inputdev.name = "Aiptek"; 2127 aiptek->inputdev.name = "Aiptek";
2127 aiptek->inputdev.phys = aiptek->features.usbPath; 2128 aiptek->inputdev.phys = aiptek->features.usbPath;
2128 aiptek->inputdev.id.bustype = BUS_USB; 2129 usb_to_input_id(usbdev, &aiptek->inputdev.id);
2129 aiptek->inputdev.id.vendor = le16_to_cpu(usbdev->descriptor.idVendor);
2130 aiptek->inputdev.id.product = le16_to_cpu(usbdev->descriptor.idProduct);
2131 aiptek->inputdev.id.version = le16_to_cpu(usbdev->descriptor.bcdDevice);
2132 aiptek->inputdev.dev = &intf->dev; 2130 aiptek->inputdev.dev = &intf->dev;
2133 2131
2134 aiptek->usbdev = usbdev; 2132 aiptek->usbdev = usbdev;
diff --git a/drivers/usb/input/ati_remote.c b/drivers/usb/input/ati_remote.c
index 654ac454744d..fd99681ee483 100644
--- a/drivers/usb/input/ati_remote.c
+++ b/drivers/usb/input/ati_remote.c
@@ -94,6 +94,7 @@
94#include <linux/moduleparam.h> 94#include <linux/moduleparam.h>
95#include <linux/input.h> 95#include <linux/input.h>
96#include <linux/usb.h> 96#include <linux/usb.h>
97#include <linux/usb_input.h>
97#include <linux/wait.h> 98#include <linux/wait.h>
98 99
99/* 100/*
@@ -635,11 +636,8 @@ static void ati_remote_input_init(struct ati_remote *ati_remote)
635 idev->name = ati_remote->name; 636 idev->name = ati_remote->name;
636 idev->phys = ati_remote->phys; 637 idev->phys = ati_remote->phys;
637 638
638 idev->id.bustype = BUS_USB; 639 usb_to_input_id(ati_remote->udev, &idev->id);
639 idev->id.vendor = le16_to_cpu(ati_remote->udev->descriptor.idVendor); 640 idev->dev = &ati_remote->udev->dev;
640 idev->id.product = le16_to_cpu(ati_remote->udev->descriptor.idProduct);
641 idev->id.version = le16_to_cpu(ati_remote->udev->descriptor.bcdDevice);
642 idev->dev = &(ati_remote->udev->dev);
643} 641}
644 642
645static int ati_remote_initialize(struct ati_remote *ati_remote) 643static int ati_remote_initialize(struct ati_remote *ati_remote)
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index 2350e7a5ad70..b2cb2b35892e 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -789,12 +789,12 @@ static __inline__ int search(__s32 *array, __s32 value, unsigned n)
789 return -1; 789 return -1;
790} 790}
791 791
792static void hid_process_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value, struct pt_regs *regs) 792static void hid_process_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value, int interrupt, struct pt_regs *regs)
793{ 793{
794 hid_dump_input(usage, value); 794 hid_dump_input(usage, value);
795 if (hid->claimed & HID_CLAIMED_INPUT) 795 if (hid->claimed & HID_CLAIMED_INPUT)
796 hidinput_hid_event(hid, field, usage, value, regs); 796 hidinput_hid_event(hid, field, usage, value, regs);
797 if (hid->claimed & HID_CLAIMED_HIDDEV) 797 if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt)
798 hiddev_hid_event(hid, field, usage, value, regs); 798 hiddev_hid_event(hid, field, usage, value, regs);
799} 799}
800 800
@@ -804,7 +804,7 @@ static void hid_process_event(struct hid_device *hid, struct hid_field *field, s
804 * reporting to the layer). 804 * reporting to the layer).
805 */ 805 */
806 806
807static void hid_input_field(struct hid_device *hid, struct hid_field *field, __u8 *data, struct pt_regs *regs) 807static void hid_input_field(struct hid_device *hid, struct hid_field *field, __u8 *data, int interrupt, struct pt_regs *regs)
808{ 808{
809 unsigned n; 809 unsigned n;
810 unsigned count = field->report_count; 810 unsigned count = field->report_count;
@@ -831,19 +831,19 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field, __u
831 for (n = 0; n < count; n++) { 831 for (n = 0; n < count; n++) {
832 832
833 if (HID_MAIN_ITEM_VARIABLE & field->flags) { 833 if (HID_MAIN_ITEM_VARIABLE & field->flags) {
834 hid_process_event(hid, field, &field->usage[n], value[n], regs); 834 hid_process_event(hid, field, &field->usage[n], value[n], interrupt, regs);
835 continue; 835 continue;
836 } 836 }
837 837
838 if (field->value[n] >= min && field->value[n] <= max 838 if (field->value[n] >= min && field->value[n] <= max
839 && field->usage[field->value[n] - min].hid 839 && field->usage[field->value[n] - min].hid
840 && search(value, field->value[n], count)) 840 && search(value, field->value[n], count))
841 hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, regs); 841 hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt, regs);
842 842
843 if (value[n] >= min && value[n] <= max 843 if (value[n] >= min && value[n] <= max
844 && field->usage[value[n] - min].hid 844 && field->usage[value[n] - min].hid
845 && search(field->value, value[n], count)) 845 && search(field->value, value[n], count))
846 hid_process_event(hid, field, &field->usage[value[n] - min], 1, regs); 846 hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt, regs);
847 } 847 }
848 848
849 memcpy(field->value, value, count * sizeof(__s32)); 849 memcpy(field->value, value, count * sizeof(__s32));
@@ -851,7 +851,7 @@ exit:
851 kfree(value); 851 kfree(value);
852} 852}
853 853
854static int hid_input_report(int type, struct urb *urb, struct pt_regs *regs) 854static int hid_input_report(int type, struct urb *urb, int interrupt, struct pt_regs *regs)
855{ 855{
856 struct hid_device *hid = urb->context; 856 struct hid_device *hid = urb->context;
857 struct hid_report_enum *report_enum = hid->report_enum + type; 857 struct hid_report_enum *report_enum = hid->report_enum + type;
@@ -899,7 +899,7 @@ static int hid_input_report(int type, struct urb *urb, struct pt_regs *regs)
899 hiddev_report_event(hid, report); 899 hiddev_report_event(hid, report);
900 900
901 for (n = 0; n < report->maxfield; n++) 901 for (n = 0; n < report->maxfield; n++)
902 hid_input_field(hid, report->field[n], data, regs); 902 hid_input_field(hid, report->field[n], data, interrupt, regs);
903 903
904 if (hid->claimed & HID_CLAIMED_INPUT) 904 if (hid->claimed & HID_CLAIMED_INPUT)
905 hidinput_report_event(hid, report); 905 hidinput_report_event(hid, report);
@@ -918,7 +918,7 @@ static void hid_irq_in(struct urb *urb, struct pt_regs *regs)
918 918
919 switch (urb->status) { 919 switch (urb->status) {
920 case 0: /* success */ 920 case 0: /* success */
921 hid_input_report(HID_INPUT_REPORT, urb, regs); 921 hid_input_report(HID_INPUT_REPORT, urb, 1, regs);
922 break; 922 break;
923 case -ECONNRESET: /* unlink */ 923 case -ECONNRESET: /* unlink */
924 case -ENOENT: 924 case -ENOENT:
@@ -1142,7 +1142,7 @@ static void hid_ctrl(struct urb *urb, struct pt_regs *regs)
1142 switch (urb->status) { 1142 switch (urb->status) {
1143 case 0: /* success */ 1143 case 0: /* success */
1144 if (hid->ctrl[hid->ctrltail].dir == USB_DIR_IN) 1144 if (hid->ctrl[hid->ctrltail].dir == USB_DIR_IN)
1145 hid_input_report(hid->ctrl[hid->ctrltail].report->type, urb, regs); 1145 hid_input_report(hid->ctrl[hid->ctrltail].report->type, urb, 0, regs);
1146 case -ESHUTDOWN: /* unplug */ 1146 case -ESHUTDOWN: /* unplug */
1147 case -EILSEQ: /* unplug timectrl on uhci */ 1147 case -EILSEQ: /* unplug timectrl on uhci */
1148 unplug = 1; 1148 unplug = 1;
@@ -1372,6 +1372,9 @@ void hid_init_reports(struct hid_device *hid)
1372#define USB_VENDOR_ID_A4TECH 0x09da 1372#define USB_VENDOR_ID_A4TECH 0x09da
1373#define USB_DEVICE_ID_A4TECH_WCP32PU 0x0006 1373#define USB_DEVICE_ID_A4TECH_WCP32PU 0x0006
1374 1374
1375#define USB_VENDOR_ID_AASHIMA 0x06D6
1376#define USB_DEVICE_ID_AASHIMA_GAMEPAD 0x0025
1377
1375#define USB_VENDOR_ID_CYPRESS 0x04b4 1378#define USB_VENDOR_ID_CYPRESS 0x04b4
1376#define USB_DEVICE_ID_CYPRESS_MOUSE 0x0001 1379#define USB_DEVICE_ID_CYPRESS_MOUSE 0x0001
1377#define USB_DEVICE_ID_CYPRESS_HIDCOM 0x5500 1380#define USB_DEVICE_ID_CYPRESS_HIDCOM 0x5500
@@ -1548,6 +1551,7 @@ static struct hid_blacklist {
1548 { USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU, HID_QUIRK_2WHEEL_MOUSE_HACK_7 }, 1551 { USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU, HID_QUIRK_2WHEEL_MOUSE_HACK_7 },
1549 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE, HID_QUIRK_2WHEEL_MOUSE_HACK_5 }, 1552 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE, HID_QUIRK_2WHEEL_MOUSE_HACK_5 },
1550 1553
1554 { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_GAMEPAD, HID_QUIRK_BADPAD },
1551 { USB_VENDOR_ID_ALPS, USB_DEVICE_ID_IBM_GAMEPAD, HID_QUIRK_BADPAD }, 1555 { USB_VENDOR_ID_ALPS, USB_DEVICE_ID_IBM_GAMEPAD, HID_QUIRK_BADPAD },
1552 { USB_VENDOR_ID_CHIC, USB_DEVICE_ID_CHIC_GAMEPAD, HID_QUIRK_BADPAD }, 1556 { USB_VENDOR_ID_CHIC, USB_DEVICE_ID_CHIC_GAMEPAD, HID_QUIRK_BADPAD },
1553 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_DRIVING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, 1557 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_DRIVING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
diff --git a/drivers/usb/input/hid-input.c b/drivers/usb/input/hid-input.c
index 9ac1e9095334..63a4db721f7e 100644
--- a/drivers/usb/input/hid-input.c
+++ b/drivers/usb/input/hid-input.c
@@ -31,6 +31,7 @@
31#include <linux/kernel.h> 31#include <linux/kernel.h>
32#include <linux/input.h> 32#include <linux/input.h>
33#include <linux/usb.h> 33#include <linux/usb.h>
34#include <linux/usb_input.h>
34 35
35#undef DEBUG 36#undef DEBUG
36 37
@@ -397,11 +398,12 @@ ignore:
397 398
398void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value, struct pt_regs *regs) 399void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value, struct pt_regs *regs)
399{ 400{
400 struct input_dev *input = &field->hidinput->input; 401 struct input_dev *input;
401 int *quirks = &hid->quirks; 402 int *quirks = &hid->quirks;
402 403
403 if (!input) 404 if (!field->hidinput)
404 return; 405 return;
406 input = &field->hidinput->input;
405 407
406 input_regs(input, regs); 408 input_regs(input, regs);
407 409
@@ -581,10 +583,7 @@ int hidinput_connect(struct hid_device *hid)
581 hidinput->input.name = hid->name; 583 hidinput->input.name = hid->name;
582 hidinput->input.phys = hid->phys; 584 hidinput->input.phys = hid->phys;
583 hidinput->input.uniq = hid->uniq; 585 hidinput->input.uniq = hid->uniq;
584 hidinput->input.id.bustype = BUS_USB; 586 usb_to_input_id(dev, &hidinput->input.id);
585 hidinput->input.id.vendor = le16_to_cpu(dev->descriptor.idVendor);
586 hidinput->input.id.product = le16_to_cpu(dev->descriptor.idProduct);
587 hidinput->input.id.version = le16_to_cpu(dev->descriptor.bcdDevice);
588 hidinput->input.dev = &hid->intf->dev; 587 hidinput->input.dev = &hid->intf->dev;
589 } 588 }
590 589
diff --git a/drivers/usb/input/itmtouch.c b/drivers/usb/input/itmtouch.c
index 47dec6a1b344..0dc439f10823 100644
--- a/drivers/usb/input/itmtouch.c
+++ b/drivers/usb/input/itmtouch.c
@@ -53,6 +53,7 @@
53#include <linux/module.h> 53#include <linux/module.h>
54#include <linux/init.h> 54#include <linux/init.h>
55#include <linux/usb.h> 55#include <linux/usb.h>
56#include <linux/usb_input.h>
56 57
57/* only an 8 byte buffer necessary for a single packet */ 58/* only an 8 byte buffer necessary for a single packet */
58#define ITM_BUFSIZE 8 59#define ITM_BUFSIZE 8
@@ -184,10 +185,7 @@ static int itmtouch_probe(struct usb_interface *intf, const struct usb_device_id
184 185
185 itmtouch->inputdev.name = itmtouch->name; 186 itmtouch->inputdev.name = itmtouch->name;
186 itmtouch->inputdev.phys = itmtouch->phys; 187 itmtouch->inputdev.phys = itmtouch->phys;
187 itmtouch->inputdev.id.bustype = BUS_USB; 188 usb_to_input_id(udev, &itmtouch->inputdev.id);
188 itmtouch->inputdev.id.vendor = udev->descriptor.idVendor;
189 itmtouch->inputdev.id.product = udev->descriptor.idProduct;
190 itmtouch->inputdev.id.version = udev->descriptor.bcdDevice;
191 itmtouch->inputdev.dev = &intf->dev; 189 itmtouch->inputdev.dev = &intf->dev;
192 190
193 if (!strlen(itmtouch->name)) 191 if (!strlen(itmtouch->name))
diff --git a/drivers/usb/input/kbtab.c b/drivers/usb/input/kbtab.c
index d2f0f90a9bcd..b6f6ac8d9c2f 100644
--- a/drivers/usb/input/kbtab.c
+++ b/drivers/usb/input/kbtab.c
@@ -4,6 +4,7 @@
4#include <linux/module.h> 4#include <linux/module.h>
5#include <linux/init.h> 5#include <linux/init.h>
6#include <linux/usb.h> 6#include <linux/usb.h>
7#include <linux/usb_input.h>
7#include <asm/unaligned.h> 8#include <asm/unaligned.h>
8#include <asm/byteorder.h> 9#include <asm/byteorder.h>
9 10
@@ -167,10 +168,7 @@ static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *i
167 168
168 kbtab->dev.name = "KB Gear Tablet"; 169 kbtab->dev.name = "KB Gear Tablet";
169 kbtab->dev.phys = kbtab->phys; 170 kbtab->dev.phys = kbtab->phys;
170 kbtab->dev.id.bustype = BUS_USB; 171 usb_to_input_id(dev, &kbtab->dev.id);
171 kbtab->dev.id.vendor = le16_to_cpu(dev->descriptor.idVendor);
172 kbtab->dev.id.product = le16_to_cpu(dev->descriptor.idProduct);
173 kbtab->dev.id.version = le16_to_cpu(dev->descriptor.bcdDevice);
174 kbtab->dev.dev = &intf->dev; 172 kbtab->dev.dev = &intf->dev;
175 kbtab->usbdev = dev; 173 kbtab->usbdev = dev;
176 174
diff --git a/drivers/usb/input/mtouchusb.c b/drivers/usb/input/mtouchusb.c
index 09b5cc7c66de..ff9275057a18 100644
--- a/drivers/usb/input/mtouchusb.c
+++ b/drivers/usb/input/mtouchusb.c
@@ -53,6 +53,7 @@
53#include <linux/module.h> 53#include <linux/module.h>
54#include <linux/init.h> 54#include <linux/init.h>
55#include <linux/usb.h> 55#include <linux/usb.h>
56#include <linux/usb_input.h>
56 57
57#define MTOUCHUSB_MIN_XC 0x0 58#define MTOUCHUSB_MIN_XC 0x0
58#define MTOUCHUSB_MAX_RAW_XC 0x4000 59#define MTOUCHUSB_MAX_RAW_XC 0x4000
@@ -232,10 +233,7 @@ static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_i
232 233
233 mtouch->input.name = mtouch->name; 234 mtouch->input.name = mtouch->name;
234 mtouch->input.phys = mtouch->phys; 235 mtouch->input.phys = mtouch->phys;
235 mtouch->input.id.bustype = BUS_USB; 236 usb_to_input_id(udev, &mtouch->input.id);
236 mtouch->input.id.vendor = le16_to_cpu(udev->descriptor.idVendor);
237 mtouch->input.id.product = le16_to_cpu(udev->descriptor.idProduct);
238 mtouch->input.id.version = le16_to_cpu(udev->descriptor.bcdDevice);
239 mtouch->input.dev = &intf->dev; 237 mtouch->input.dev = &intf->dev;
240 238
241 mtouch->input.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 239 mtouch->input.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
diff --git a/drivers/usb/input/powermate.c b/drivers/usb/input/powermate.c
index 3975b309d55f..ad4afe7e5897 100644
--- a/drivers/usb/input/powermate.c
+++ b/drivers/usb/input/powermate.c
@@ -35,6 +35,7 @@
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/spinlock.h> 36#include <linux/spinlock.h>
37#include <linux/usb.h> 37#include <linux/usb.h>
38#include <linux/usb_input.h>
38 39
39#define POWERMATE_VENDOR 0x077d /* Griffin Technology, Inc. */ 40#define POWERMATE_VENDOR 0x077d /* Griffin Technology, Inc. */
40#define POWERMATE_PRODUCT_NEW 0x0410 /* Griffin PowerMate */ 41#define POWERMATE_PRODUCT_NEW 0x0410 /* Griffin PowerMate */
@@ -389,10 +390,7 @@ static int powermate_probe(struct usb_interface *intf, const struct usb_device_i
389 pm->input.keybit[LONG(BTN_0)] = BIT(BTN_0); 390 pm->input.keybit[LONG(BTN_0)] = BIT(BTN_0);
390 pm->input.relbit[LONG(REL_DIAL)] = BIT(REL_DIAL); 391 pm->input.relbit[LONG(REL_DIAL)] = BIT(REL_DIAL);
391 pm->input.mscbit[LONG(MSC_PULSELED)] = BIT(MSC_PULSELED); 392 pm->input.mscbit[LONG(MSC_PULSELED)] = BIT(MSC_PULSELED);
392 pm->input.id.bustype = BUS_USB; 393 usb_to_input_id(udev, &pm->input.id);
393 pm->input.id.vendor = le16_to_cpu(udev->descriptor.idVendor);
394 pm->input.id.product = le16_to_cpu(udev->descriptor.idProduct);
395 pm->input.id.version = le16_to_cpu(udev->descriptor.bcdDevice);
396 pm->input.event = powermate_input_event; 394 pm->input.event = powermate_input_event;
397 pm->input.dev = &intf->dev; 395 pm->input.dev = &intf->dev;
398 pm->input.phys = pm->phys; 396 pm->input.phys = pm->phys;
diff --git a/drivers/usb/input/touchkitusb.c b/drivers/usb/input/touchkitusb.c
index 386595ee21c0..4276c24a5080 100644
--- a/drivers/usb/input/touchkitusb.c
+++ b/drivers/usb/input/touchkitusb.c
@@ -35,7 +35,7 @@
35#define DEBUG 35#define DEBUG
36#endif 36#endif
37#include <linux/usb.h> 37#include <linux/usb.h>
38 38#include <linux/usb_input.h>
39 39
40#define TOUCHKIT_MIN_XC 0x0 40#define TOUCHKIT_MIN_XC 0x0
41#define TOUCHKIT_MAX_XC 0x07ff 41#define TOUCHKIT_MAX_XC 0x07ff
@@ -202,10 +202,7 @@ static int touchkit_probe(struct usb_interface *intf,
202 202
203 touchkit->input.name = touchkit->name; 203 touchkit->input.name = touchkit->name;
204 touchkit->input.phys = touchkit->phys; 204 touchkit->input.phys = touchkit->phys;
205 touchkit->input.id.bustype = BUS_USB; 205 usb_to_input_id(udev, &touchkit->input.id);
206 touchkit->input.id.vendor = le16_to_cpu(udev->descriptor.idVendor);
207 touchkit->input.id.product = le16_to_cpu(udev->descriptor.idProduct);
208 touchkit->input.id.version = le16_to_cpu(udev->descriptor.bcdDevice);
209 touchkit->input.dev = &intf->dev; 206 touchkit->input.dev = &intf->dev;
210 207
211 touchkit->input.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 208 touchkit->input.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
diff --git a/drivers/usb/input/usbkbd.c b/drivers/usb/input/usbkbd.c
index f35db1974c42..28987f15eeee 100644
--- a/drivers/usb/input/usbkbd.c
+++ b/drivers/usb/input/usbkbd.c
@@ -32,6 +32,7 @@
32#include <linux/input.h> 32#include <linux/input.h>
33#include <linux/init.h> 33#include <linux/init.h>
34#include <linux/usb.h> 34#include <linux/usb.h>
35#include <linux/usb_input.h>
35 36
36/* 37/*
37 * Version Information 38 * Version Information
@@ -288,10 +289,7 @@ static int usb_kbd_probe(struct usb_interface *iface,
288 289
289 kbd->dev.name = kbd->name; 290 kbd->dev.name = kbd->name;
290 kbd->dev.phys = kbd->phys; 291 kbd->dev.phys = kbd->phys;
291 kbd->dev.id.bustype = BUS_USB; 292 usb_to_input_id(dev, &kbd->dev.id);
292 kbd->dev.id.vendor = le16_to_cpu(dev->descriptor.idVendor);
293 kbd->dev.id.product = le16_to_cpu(dev->descriptor.idProduct);
294 kbd->dev.id.version = le16_to_cpu(dev->descriptor.bcdDevice);
295 kbd->dev.dev = &iface->dev; 293 kbd->dev.dev = &iface->dev;
296 294
297 if (dev->manufacturer) 295 if (dev->manufacturer)
diff --git a/drivers/usb/input/usbmouse.c b/drivers/usb/input/usbmouse.c
index 1ec41b5effe6..4104dec847fb 100644
--- a/drivers/usb/input/usbmouse.c
+++ b/drivers/usb/input/usbmouse.c
@@ -32,6 +32,7 @@
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/init.h> 33#include <linux/init.h>
34#include <linux/usb.h> 34#include <linux/usb.h>
35#include <linux/usb_input.h>
35 36
36/* 37/*
37 * Version Information 38 * Version Information
@@ -171,10 +172,7 @@ static int usb_mouse_probe(struct usb_interface * intf, const struct usb_device_
171 172
172 mouse->dev.name = mouse->name; 173 mouse->dev.name = mouse->name;
173 mouse->dev.phys = mouse->phys; 174 mouse->dev.phys = mouse->phys;
174 mouse->dev.id.bustype = BUS_USB; 175 usb_to_input_id(dev, &mouse->dev.id);
175 mouse->dev.id.vendor = le16_to_cpu(dev->descriptor.idVendor);
176 mouse->dev.id.product = le16_to_cpu(dev->descriptor.idProduct);
177 mouse->dev.id.version = le16_to_cpu(dev->descriptor.bcdDevice);
178 mouse->dev.dev = &intf->dev; 176 mouse->dev.dev = &intf->dev;
179 177
180 if (dev->manufacturer) 178 if (dev->manufacturer)
diff --git a/drivers/usb/input/wacom.c b/drivers/usb/input/wacom.c
index f6b34af66b3d..02412e31a46b 100644
--- a/drivers/usb/input/wacom.c
+++ b/drivers/usb/input/wacom.c
@@ -69,6 +69,7 @@
69#include <linux/module.h> 69#include <linux/module.h>
70#include <linux/init.h> 70#include <linux/init.h>
71#include <linux/usb.h> 71#include <linux/usb.h>
72#include <linux/usb_input.h>
72#include <asm/unaligned.h> 73#include <asm/unaligned.h>
73#include <asm/byteorder.h> 74#include <asm/byteorder.h>
74 75
@@ -823,10 +824,7 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
823 824
824 wacom->dev.name = wacom->features->name; 825 wacom->dev.name = wacom->features->name;
825 wacom->dev.phys = wacom->phys; 826 wacom->dev.phys = wacom->phys;
826 wacom->dev.id.bustype = BUS_USB; 827 usb_to_input_id(dev, &wacom->dev.id);
827 wacom->dev.id.vendor = le16_to_cpu(dev->descriptor.idVendor);
828 wacom->dev.id.product = le16_to_cpu(dev->descriptor.idProduct);
829 wacom->dev.id.version = le16_to_cpu(dev->descriptor.bcdDevice);
830 wacom->dev.dev = &intf->dev; 828 wacom->dev.dev = &intf->dev;
831 wacom->usbdev = dev; 829 wacom->usbdev = dev;
832 830
diff --git a/drivers/usb/input/xpad.c b/drivers/usb/input/xpad.c
index a7fa1b17dcfe..18125e0bffa2 100644
--- a/drivers/usb/input/xpad.c
+++ b/drivers/usb/input/xpad.c
@@ -62,6 +62,7 @@
62#include <linux/module.h> 62#include <linux/module.h>
63#include <linux/smp_lock.h> 63#include <linux/smp_lock.h>
64#include <linux/usb.h> 64#include <linux/usb.h>
65#include <linux/usb_input.h>
65 66
66#define DRIVER_VERSION "v0.0.5" 67#define DRIVER_VERSION "v0.0.5"
67#define DRIVER_AUTHOR "Marko Friedemann <mfr@bmx-chemnitz.de>" 68#define DRIVER_AUTHOR "Marko Friedemann <mfr@bmx-chemnitz.de>"
@@ -256,10 +257,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
256 257
257 xpad->udev = udev; 258 xpad->udev = udev;
258 259
259 xpad->dev.id.bustype = BUS_USB; 260 usb_to_input_id(udev, &xpad->dev.id);
260 xpad->dev.id.vendor = le16_to_cpu(udev->descriptor.idVendor);
261 xpad->dev.id.product = le16_to_cpu(udev->descriptor.idProduct);
262 xpad->dev.id.version = le16_to_cpu(udev->descriptor.bcdDevice);
263 xpad->dev.dev = &intf->dev; 261 xpad->dev.dev = &intf->dev;
264 xpad->dev.private = xpad; 262 xpad->dev.private = xpad;
265 xpad->dev.name = xpad_device[i].name; 263 xpad->dev.name = xpad_device[i].name;
diff --git a/drivers/usb/media/konicawc.c b/drivers/usb/media/konicawc.c
index 08521a2b4f3d..20ac9e1069d4 100644
--- a/drivers/usb/media/konicawc.c
+++ b/drivers/usb/media/konicawc.c
@@ -16,6 +16,7 @@
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/input.h> 18#include <linux/input.h>
19#include <linux/usb_input.h>
19 20
20#include "usbvideo.h" 21#include "usbvideo.h"
21 22
@@ -845,10 +846,7 @@ static int konicawc_probe(struct usb_interface *intf, const struct usb_device_id
845 cam->input.private = cam; 846 cam->input.private = cam;
846 cam->input.evbit[0] = BIT(EV_KEY); 847 cam->input.evbit[0] = BIT(EV_KEY);
847 cam->input.keybit[LONG(BTN_0)] = BIT(BTN_0); 848 cam->input.keybit[LONG(BTN_0)] = BIT(BTN_0);
848 cam->input.id.bustype = BUS_USB; 849 usb_to_input_id(dev, &cam->input.id);
849 cam->input.id.vendor = le16_to_cpu(dev->descriptor.idVendor);
850 cam->input.id.product = le16_to_cpu(dev->descriptor.idProduct);
851 cam->input.id.version = le16_to_cpu(dev->descriptor.bcdDevice);
852 input_register_device(&cam->input); 850 input_register_device(&cam->input);
853 851
854 usb_make_path(dev, cam->input_physname, 56); 852 usb_make_path(dev, cam->input_physname, 56);
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
index 66ec88354b93..ad17892aac9e 100644
--- a/drivers/usb/misc/ldusb.c
+++ b/drivers/usb/misc/ldusb.c
@@ -23,6 +23,7 @@
23 * 23 *
24 * V0.1 (mh) Initial version 24 * V0.1 (mh) Initial version
25 * V0.11 (mh) Added raw support for HID 1.0 devices (no interrupt out endpoint) 25 * V0.11 (mh) Added raw support for HID 1.0 devices (no interrupt out endpoint)
26 * V0.12 (mh) Added kmalloc check for string buffer
26 */ 27 */
27 28
28#include <linux/config.h> 29#include <linux/config.h>
@@ -84,7 +85,7 @@ static struct usb_device_id ld_usb_table [] = {
84 { } /* Terminating entry */ 85 { } /* Terminating entry */
85}; 86};
86MODULE_DEVICE_TABLE(usb, ld_usb_table); 87MODULE_DEVICE_TABLE(usb, ld_usb_table);
87MODULE_VERSION("V0.11"); 88MODULE_VERSION("V0.12");
88MODULE_AUTHOR("Michael Hund <mhund@ld-didactic.de>"); 89MODULE_AUTHOR("Michael Hund <mhund@ld-didactic.de>");
89MODULE_DESCRIPTION("LD USB Driver"); 90MODULE_DESCRIPTION("LD USB Driver");
90MODULE_LICENSE("GPL"); 91MODULE_LICENSE("GPL");
@@ -635,6 +636,10 @@ static int ld_usb_probe(struct usb_interface *intf, const struct usb_device_id *
635 (le16_to_cpu(udev->descriptor.idProduct) == USB_DEVICE_ID_COM3LAB)) && 636 (le16_to_cpu(udev->descriptor.idProduct) == USB_DEVICE_ID_COM3LAB)) &&
636 (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x103)) { 637 (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x103)) {
637 buffer = kmalloc(256, GFP_KERNEL); 638 buffer = kmalloc(256, GFP_KERNEL);
639 if (buffer == NULL) {
640 dev_err(&intf->dev, "Couldn't allocate string buffer\n");
641 goto error;
642 }
638 /* usb_string makes SETUP+STALL to leave always ControlReadLoop */ 643 /* usb_string makes SETUP+STALL to leave always ControlReadLoop */
639 usb_string(udev, 255, buffer, 256); 644 usb_string(udev, 255, buffer, 256);
640 kfree(buffer); 645 kfree(buffer);
diff --git a/drivers/usb/mon/Kconfig b/drivers/usb/mon/Kconfig
index 777642e26b9a..deb9ddffa402 100644
--- a/drivers/usb/mon/Kconfig
+++ b/drivers/usb/mon/Kconfig
@@ -9,9 +9,8 @@ config USB_MON
9 help 9 help
10 If you say Y here, a component which captures the USB traffic 10 If you say Y here, a component which captures the USB traffic
11 between peripheral-specific drivers and HC drivers will be built. 11 between peripheral-specific drivers and HC drivers will be built.
12 The USB_MON is similar in spirit and may be compatible with Dave 12 For more information, see <file:Documentation/usb/usbmon.txt>.
13 Harding's USBMon.
14 13
15 This is somewhat experimental at this time, but it should be safe, 14 This is somewhat experimental at this time, but it should be safe.
16 as long as you aren't using modular USB and try to remove this 15
17 module. 16 If unsure, say Y.
diff --git a/drivers/usb/mon/Makefile b/drivers/usb/mon/Makefile
index f18d10ce91f9..b0015b8a1d1f 100644
--- a/drivers/usb/mon/Makefile
+++ b/drivers/usb/mon/Makefile
@@ -4,4 +4,5 @@
4 4
5usbmon-objs := mon_main.o mon_stat.o mon_text.o 5usbmon-objs := mon_main.o mon_stat.o mon_text.o
6 6
7# This does not use CONFIG_USB_MON because we want this to use a tristate.
7obj-$(CONFIG_USB) += usbmon.o 8obj-$(CONFIG_USB) += usbmon.o
diff --git a/drivers/usb/net/pegasus.c b/drivers/usb/net/pegasus.c
index 5f4496d8dbac..fcd6d3ccef44 100644
--- a/drivers/usb/net/pegasus.c
+++ b/drivers/usb/net/pegasus.c
@@ -59,7 +59,6 @@ static const char driver_name[] = "pegasus";
59 59
60static int loopback = 0; 60static int loopback = 0;
61static int mii_mode = 0; 61static int mii_mode = 0;
62static int multicast_filter_limit = 32;
63 62
64static struct usb_eth_dev usb_dev_id[] = { 63static struct usb_eth_dev usb_dev_id[] = {
65#define PEGASUS_DEV(pn, vid, pid, flags) \ 64#define PEGASUS_DEV(pn, vid, pid, flags) \
diff --git a/drivers/usb/net/rtl8150.c b/drivers/usb/net/rtl8150.c
index 626b016addff..59ab40ebb394 100644
--- a/drivers/usb/net/rtl8150.c
+++ b/drivers/usb/net/rtl8150.c
@@ -167,8 +167,6 @@ struct rtl8150 {
167 167
168typedef struct rtl8150 rtl8150_t; 168typedef struct rtl8150 rtl8150_t;
169 169
170static unsigned long multicast_filter_limit = 32;
171
172static void fill_skb_pool(rtl8150_t *); 170static void fill_skb_pool(rtl8150_t *);
173static void free_skb_pool(rtl8150_t *); 171static void free_skb_pool(rtl8150_t *);
174static inline struct sk_buff *pull_skb(rtl8150_t *); 172static inline struct sk_buff *pull_skb(rtl8150_t *);
diff --git a/drivers/usb/net/zd1201.c b/drivers/usb/net/zd1201.c
index 3b387b005739..29cd801eb958 100644
--- a/drivers/usb/net/zd1201.c
+++ b/drivers/usb/net/zd1201.c
@@ -29,6 +29,7 @@ static struct usb_device_id zd1201_table[] = {
29 {USB_DEVICE(0x0ace, 0x1201)}, /* ZyDAS ZD1201 Wireless USB Adapter */ 29 {USB_DEVICE(0x0ace, 0x1201)}, /* ZyDAS ZD1201 Wireless USB Adapter */
30 {USB_DEVICE(0x050d, 0x6051)}, /* Belkin F5D6051 usb adapter */ 30 {USB_DEVICE(0x050d, 0x6051)}, /* Belkin F5D6051 usb adapter */
31 {USB_DEVICE(0x0db0, 0x6823)}, /* MSI UB11B usb adapter */ 31 {USB_DEVICE(0x0db0, 0x6823)}, /* MSI UB11B usb adapter */
32 {USB_DEVICE(0x1044, 0x8005)}, /* GIGABYTE GN-WLBZ201 usb adapter */
32 {} 33 {}
33}; 34};
34 35
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 0b03ddab53d9..d1964a0c4168 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -429,6 +429,9 @@ static struct usb_device_id id_table_combined [] = {
429 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_2_PID) }, 429 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_2_PID) },
430 { USB_DEVICE(MOBILITY_VID, MOBILITY_USB_SERIAL_PID) }, 430 { USB_DEVICE(MOBILITY_VID, MOBILITY_USB_SERIAL_PID) },
431 { USB_DEVICE(FTDI_VID, FTDI_ACTIVE_ROBOTS_PID) }, 431 { USB_DEVICE(FTDI_VID, FTDI_ACTIVE_ROBOTS_PID) },
432 { USB_DEVICE(FTDI_VID, FTDI_MHAM_Y6_PID) },
433 { USB_DEVICE(FTDI_VID, FTDI_MHAM_Y8_PID) },
434 { USB_DEVICE(EVOLUTION_VID, EVOLUTION_ER1_PID) },
432 { } /* Terminating entry */ 435 { } /* Terminating entry */
433}; 436};
434 437
@@ -545,6 +548,7 @@ static struct usb_serial_device_type ftdi_sio_device = {
545 548
546 549
547#define WDR_TIMEOUT 5000 /* default urb timeout */ 550#define WDR_TIMEOUT 5000 /* default urb timeout */
551#define WDR_SHORT_TIMEOUT 1000 /* shorter urb timeout */
548 552
549/* High and low are for DTR, RTS etc etc */ 553/* High and low are for DTR, RTS etc etc */
550#define HIGH 1 554#define HIGH 1
@@ -593,62 +597,59 @@ static __u32 ftdi_232bm_baud_to_divisor(int baud)
593 return(ftdi_232bm_baud_base_to_divisor(baud, 48000000)); 597 return(ftdi_232bm_baud_base_to_divisor(baud, 48000000));
594} 598}
595 599
596static int set_rts(struct usb_serial_port *port, int high_or_low) 600#define set_mctrl(port, set) update_mctrl((port), (set), 0)
601#define clear_mctrl(port, clear) update_mctrl((port), 0, (clear))
602
603static int update_mctrl(struct usb_serial_port *port, unsigned int set, unsigned int clear)
597{ 604{
598 struct ftdi_private *priv = usb_get_serial_port_data(port); 605 struct ftdi_private *priv = usb_get_serial_port_data(port);
599 char *buf; 606 char *buf;
600 unsigned ftdi_high_or_low; 607 unsigned urb_value;
601 int rv; 608 int rv;
602
603 buf = kmalloc(1, GFP_NOIO);
604 if (!buf)
605 return -ENOMEM;
606
607 if (high_or_low) {
608 ftdi_high_or_low = FTDI_SIO_SET_RTS_HIGH;
609 priv->last_dtr_rts |= TIOCM_RTS;
610 } else {
611 ftdi_high_or_low = FTDI_SIO_SET_RTS_LOW;
612 priv->last_dtr_rts &= ~TIOCM_RTS;
613 }
614 rv = usb_control_msg(port->serial->dev,
615 usb_sndctrlpipe(port->serial->dev, 0),
616 FTDI_SIO_SET_MODEM_CTRL_REQUEST,
617 FTDI_SIO_SET_MODEM_CTRL_REQUEST_TYPE,
618 ftdi_high_or_low, priv->interface,
619 buf, 0, WDR_TIMEOUT);
620
621 kfree(buf);
622 return rv;
623}
624 609
610 if (((set | clear) & (TIOCM_DTR | TIOCM_RTS)) == 0) {
611 dbg("%s - DTR|RTS not being set|cleared", __FUNCTION__);
612 return 0; /* no change */
613 }
625 614
626static int set_dtr(struct usb_serial_port *port, int high_or_low)
627{
628 struct ftdi_private *priv = usb_get_serial_port_data(port);
629 char *buf;
630 unsigned ftdi_high_or_low;
631 int rv;
632
633 buf = kmalloc(1, GFP_NOIO); 615 buf = kmalloc(1, GFP_NOIO);
634 if (!buf) 616 if (!buf) {
635 return -ENOMEM; 617 return -ENOMEM;
636
637 if (high_or_low) {
638 ftdi_high_or_low = FTDI_SIO_SET_DTR_HIGH;
639 priv->last_dtr_rts |= TIOCM_DTR;
640 } else {
641 ftdi_high_or_low = FTDI_SIO_SET_DTR_LOW;
642 priv->last_dtr_rts &= ~TIOCM_DTR;
643 } 618 }
619
620 clear &= ~set; /* 'set' takes precedence over 'clear' */
621 urb_value = 0;
622 if (clear & TIOCM_DTR)
623 urb_value |= FTDI_SIO_SET_DTR_LOW;
624 if (clear & TIOCM_RTS)
625 urb_value |= FTDI_SIO_SET_RTS_LOW;
626 if (set & TIOCM_DTR)
627 urb_value |= FTDI_SIO_SET_DTR_HIGH;
628 if (set & TIOCM_RTS)
629 urb_value |= FTDI_SIO_SET_RTS_HIGH;
644 rv = usb_control_msg(port->serial->dev, 630 rv = usb_control_msg(port->serial->dev,
645 usb_sndctrlpipe(port->serial->dev, 0), 631 usb_sndctrlpipe(port->serial->dev, 0),
646 FTDI_SIO_SET_MODEM_CTRL_REQUEST, 632 FTDI_SIO_SET_MODEM_CTRL_REQUEST,
647 FTDI_SIO_SET_MODEM_CTRL_REQUEST_TYPE, 633 FTDI_SIO_SET_MODEM_CTRL_REQUEST_TYPE,
648 ftdi_high_or_low, priv->interface, 634 urb_value, priv->interface,
649 buf, 0, WDR_TIMEOUT); 635 buf, 0, WDR_TIMEOUT);
650 636
651 kfree(buf); 637 kfree(buf);
638 if (rv < 0) {
639 err("%s Error from MODEM_CTRL urb: DTR %s, RTS %s",
640 __FUNCTION__,
641 (set & TIOCM_DTR) ? "HIGH" :
642 (clear & TIOCM_DTR) ? "LOW" : "unchanged",
643 (set & TIOCM_RTS) ? "HIGH" :
644 (clear & TIOCM_RTS) ? "LOW" : "unchanged");
645 } else {
646 dbg("%s - DTR %s, RTS %s", __FUNCTION__,
647 (set & TIOCM_DTR) ? "HIGH" :
648 (clear & TIOCM_DTR) ? "LOW" : "unchanged",
649 (set & TIOCM_RTS) ? "HIGH" :
650 (clear & TIOCM_RTS) ? "LOW" : "unchanged");
651 priv->last_dtr_rts = (priv->last_dtr_rts & ~clear) | set;
652 }
652 return rv; 653 return rv;
653} 654}
654 655
@@ -681,7 +682,7 @@ static int change_speed(struct usb_serial_port *port)
681 FTDI_SIO_SET_BAUDRATE_REQUEST, 682 FTDI_SIO_SET_BAUDRATE_REQUEST,
682 FTDI_SIO_SET_BAUDRATE_REQUEST_TYPE, 683 FTDI_SIO_SET_BAUDRATE_REQUEST_TYPE,
683 urb_value, urb_index, 684 urb_value, urb_index,
684 buf, 0, 100); 685 buf, 0, WDR_SHORT_TIMEOUT);
685 686
686 kfree(buf); 687 kfree(buf);
687 return rv; 688 return rv;
@@ -1219,12 +1220,7 @@ static int ftdi_open (struct usb_serial_port *port, struct file *filp)
1219 /* FIXME: Flow control might be enabled, so it should be checked - 1220 /* FIXME: Flow control might be enabled, so it should be checked -
1220 we have no control of defaults! */ 1221 we have no control of defaults! */
1221 /* Turn on RTS and DTR since we are not flow controlling by default */ 1222 /* Turn on RTS and DTR since we are not flow controlling by default */
1222 if (set_dtr(port, HIGH) < 0) { 1223 set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
1223 err("%s Error from DTR HIGH urb", __FUNCTION__);
1224 }
1225 if (set_rts(port, HIGH) < 0){
1226 err("%s Error from RTS HIGH urb", __FUNCTION__);
1227 }
1228 1224
1229 /* Not throttled */ 1225 /* Not throttled */
1230 spin_lock_irqsave(&priv->rx_lock, flags); 1226 spin_lock_irqsave(&priv->rx_lock, flags);
@@ -1274,14 +1270,8 @@ static void ftdi_close (struct usb_serial_port *port, struct file *filp)
1274 err("error from flowcontrol urb"); 1270 err("error from flowcontrol urb");
1275 } 1271 }
1276 1272
1277 /* drop DTR */ 1273 /* drop RTS and DTR */
1278 if (set_dtr(port, LOW) < 0){ 1274 clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
1279 err("Error from DTR LOW urb");
1280 }
1281 /* drop RTS */
1282 if (set_rts(port, LOW) < 0) {
1283 err("Error from RTS LOW urb");
1284 }
1285 } /* Note change no line if hupcl is off */ 1275 } /* Note change no line if hupcl is off */
1286 1276
1287 /* cancel any scheduled reading */ 1277 /* cancel any scheduled reading */
@@ -1797,7 +1787,7 @@ static void ftdi_set_termios (struct usb_serial_port *port, struct termios *old_
1797 FTDI_SIO_SET_DATA_REQUEST, 1787 FTDI_SIO_SET_DATA_REQUEST,
1798 FTDI_SIO_SET_DATA_REQUEST_TYPE, 1788 FTDI_SIO_SET_DATA_REQUEST_TYPE,
1799 urb_value , priv->interface, 1789 urb_value , priv->interface,
1800 buf, 0, 100) < 0) { 1790 buf, 0, WDR_SHORT_TIMEOUT) < 0) {
1801 err("%s FAILED to set databits/stopbits/parity", __FUNCTION__); 1791 err("%s FAILED to set databits/stopbits/parity", __FUNCTION__);
1802 } 1792 }
1803 1793
@@ -1812,25 +1802,14 @@ static void ftdi_set_termios (struct usb_serial_port *port, struct termios *old_
1812 err("%s error from disable flowcontrol urb", __FUNCTION__); 1802 err("%s error from disable flowcontrol urb", __FUNCTION__);
1813 } 1803 }
1814 /* Drop RTS and DTR */ 1804 /* Drop RTS and DTR */
1815 if (set_dtr(port, LOW) < 0){ 1805 clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
1816 err("%s Error from DTR LOW urb", __FUNCTION__);
1817 }
1818 if (set_rts(port, LOW) < 0){
1819 err("%s Error from RTS LOW urb", __FUNCTION__);
1820 }
1821
1822 } else { 1806 } else {
1823 /* set the baudrate determined before */ 1807 /* set the baudrate determined before */
1824 if (change_speed(port)) { 1808 if (change_speed(port)) {
1825 err("%s urb failed to set baurdrate", __FUNCTION__); 1809 err("%s urb failed to set baurdrate", __FUNCTION__);
1826 } 1810 }
1827 /* Ensure RTS and DTR are raised */ 1811 /* Ensure RTS and DTR are raised */
1828 else if (set_dtr(port, HIGH) < 0){ 1812 set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
1829 err("%s Error from DTR HIGH urb", __FUNCTION__);
1830 }
1831 else if (set_rts(port, HIGH) < 0){
1832 err("%s Error from RTS HIGH urb", __FUNCTION__);
1833 }
1834 } 1813 }
1835 1814
1836 /* Set flow control */ 1815 /* Set flow control */
@@ -1942,35 +1921,8 @@ static int ftdi_tiocmget (struct usb_serial_port *port, struct file *file)
1942 1921
1943static int ftdi_tiocmset(struct usb_serial_port *port, struct file * file, unsigned int set, unsigned int clear) 1922static int ftdi_tiocmset(struct usb_serial_port *port, struct file * file, unsigned int set, unsigned int clear)
1944{ 1923{
1945 int ret;
1946
1947 dbg("%s TIOCMSET", __FUNCTION__); 1924 dbg("%s TIOCMSET", __FUNCTION__);
1948 if (set & TIOCM_DTR){ 1925 return update_mctrl(port, set, clear);
1949 if ((ret = set_dtr(port, HIGH)) < 0) {
1950 err("Urb to set DTR failed");
1951 return(ret);
1952 }
1953 }
1954 if (set & TIOCM_RTS) {
1955 if ((ret = set_rts(port, HIGH)) < 0){
1956 err("Urb to set RTS failed");
1957 return(ret);
1958 }
1959 }
1960
1961 if (clear & TIOCM_DTR){
1962 if ((ret = set_dtr(port, LOW)) < 0){
1963 err("Urb to unset DTR failed");
1964 return(ret);
1965 }
1966 }
1967 if (clear & TIOCM_RTS) {
1968 if ((ret = set_rts(port, LOW)) < 0){
1969 err("Urb to unset RTS failed");
1970 return(ret);
1971 }
1972 }
1973 return(0);
1974} 1926}
1975 1927
1976 1928
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h
index 8866376823a5..9f4342093e8b 100644
--- a/drivers/usb/serial/ftdi_sio.h
+++ b/drivers/usb/serial/ftdi_sio.h
@@ -265,10 +265,24 @@
265#define MOBILITY_USB_SERIAL_PID 0x0202 /* EasiDock USB 200 serial */ 265#define MOBILITY_USB_SERIAL_PID 0x0202 /* EasiDock USB 200 serial */
266 266
267/* 267/*
268 * microHAM product IDs (http://www.microham.com).
269 * Submitted by Justin Burket (KL1RL) <zorton@jtan.com>.
270 */
271#define FTDI_MHAM_Y6_PID 0xEEEA /* USB-Y6 interface */
272#define FTDI_MHAM_Y8_PID 0xEEEB /* USB-Y8 interface */
273
274/*
268 * Active Robots product ids. 275 * Active Robots product ids.
269 */ 276 */
270#define FTDI_ACTIVE_ROBOTS_PID 0xE548 /* USB comms board */ 277#define FTDI_ACTIVE_ROBOTS_PID 0xE548 /* USB comms board */
271 278
279/*
280 * Evolution Robotics products (http://www.evolution.com/).
281 * Submitted by Shawn M. Lavelle.
282 */
283#define EVOLUTION_VID 0xDEEE /* Vendor ID */
284#define EVOLUTION_ER1_PID 0x0300 /* ER1 Control Module */
285
272/* Commands */ 286/* Commands */
273#define FTDI_SIO_RESET 0 /* Reset the port */ 287#define FTDI_SIO_RESET 0 /* Reset the port */
274#define FTDI_SIO_MODEM_CTRL 1 /* Set the modem control register */ 288#define FTDI_SIO_MODEM_CTRL 1 /* Set the modem control register */
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
index 6051a646fe69..353f24d45bc1 100644
--- a/drivers/usb/usb-skeleton.c
+++ b/drivers/usb/usb-skeleton.c
@@ -257,7 +257,8 @@ static int skel_probe(struct usb_interface *interface, const struct usb_device_i
257 endpoint = &iface_desc->endpoint[i].desc; 257 endpoint = &iface_desc->endpoint[i].desc;
258 258
259 if (!dev->bulk_in_endpointAddr && 259 if (!dev->bulk_in_endpointAddr &&
260 (endpoint->bEndpointAddress & USB_DIR_IN) && 260 ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
261 == USB_DIR_IN) &&
261 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) 262 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
262 == USB_ENDPOINT_XFER_BULK)) { 263 == USB_ENDPOINT_XFER_BULK)) {
263 /* we found a bulk in endpoint */ 264 /* we found a bulk in endpoint */
@@ -272,7 +273,8 @@ static int skel_probe(struct usb_interface *interface, const struct usb_device_i
272 } 273 }
273 274
274 if (!dev->bulk_out_endpointAddr && 275 if (!dev->bulk_out_endpointAddr &&
275 !(endpoint->bEndpointAddress & USB_DIR_OUT) && 276 ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
277 == USB_DIR_OUT) &&
276 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) 278 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
277 == USB_ENDPOINT_XFER_BULK)) { 279 == USB_ENDPOINT_XFER_BULK)) {
278 /* we found a bulk out endpoint */ 280 /* we found a bulk out endpoint */
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 04d3120f7236..cde0ed097af6 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -1399,8 +1399,8 @@ config FB_TX3912
1399 Say Y here to enable kernel support for the on-board framebuffer. 1399 Say Y here to enable kernel support for the on-board framebuffer.
1400 1400
1401config FB_G364 1401config FB_G364
1402 bool 1402 bool "G364 frame buffer support"
1403 depends on MIPS_MAGNUM_4000 || OLIVETTI_M700 1403 depends on (FB = y) && (MIPS_MAGNUM_4000 || OLIVETTI_M700)
1404 select FB_CFB_FILLRECT 1404 select FB_CFB_FILLRECT
1405 select FB_CFB_COPYAREA 1405 select FB_CFB_COPYAREA
1406 select FB_CFB_IMAGEBLIT 1406 select FB_CFB_IMAGEBLIT
diff --git a/drivers/video/aty/radeon_base.c b/drivers/video/aty/radeon_base.c
index 47a6b12bc968..e7e8b52014c3 100644
--- a/drivers/video/aty/radeon_base.c
+++ b/drivers/video/aty/radeon_base.c
@@ -2521,6 +2521,11 @@ static void __devexit radeonfb_pci_unregister (struct pci_dev *pdev)
2521 2521
2522 radeonfb_pm_exit(rinfo); 2522 radeonfb_pm_exit(rinfo);
2523 2523
2524 if (rinfo->mon1_EDID)
2525 sysfs_remove_bin_file(&rinfo->pdev->dev.kobj, &edid1_attr);
2526 if (rinfo->mon2_EDID)
2527 sysfs_remove_bin_file(&rinfo->pdev->dev.kobj, &edid2_attr);
2528
2524#if 0 2529#if 0
2525 /* restore original state 2530 /* restore original state
2526 * 2531 *
diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
index 9dd0fbccf994..35c88bd7ba5e 100644
--- a/drivers/video/console/fbcon.c
+++ b/drivers/video/console/fbcon.c
@@ -275,7 +275,8 @@ static void fb_flashcursor(void *private)
275 275
276 if (!vc || !CON_IS_VISIBLE(vc) || 276 if (!vc || !CON_IS_VISIBLE(vc) ||
277 fbcon_is_inactive(vc, info) || 277 fbcon_is_inactive(vc, info) ||
278 registered_fb[con2fb_map[vc->vc_num]] != info) 278 registered_fb[con2fb_map[vc->vc_num]] != info ||
279 vc_cons[ops->currcon].d->vc_deccm != 1)
279 return; 280 return;
280 acquire_console_sem(); 281 acquire_console_sem();
281 p = &fb_display[vc->vc_num]; 282 p = &fb_display[vc->vc_num];
diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
index 4e5ce8f7d65e..c32a2a50bfa2 100644
--- a/drivers/video/fbcmap.c
+++ b/drivers/video/fbcmap.c
@@ -212,7 +212,7 @@ int fb_cmap_to_user(struct fb_cmap *from, struct fb_cmap_user *to)
212 212
213int fb_set_cmap(struct fb_cmap *cmap, struct fb_info *info) 213int fb_set_cmap(struct fb_cmap *cmap, struct fb_info *info)
214{ 214{
215 int i, start; 215 int i, start, rc = 0;
216 u16 *red, *green, *blue, *transp; 216 u16 *red, *green, *blue, *transp;
217 u_int hred, hgreen, hblue, htransp = 0xffff; 217 u_int hred, hgreen, hblue, htransp = 0xffff;
218 218
@@ -225,75 +225,51 @@ int fb_set_cmap(struct fb_cmap *cmap, struct fb_info *info)
225 if (start < 0 || (!info->fbops->fb_setcolreg && 225 if (start < 0 || (!info->fbops->fb_setcolreg &&
226 !info->fbops->fb_setcmap)) 226 !info->fbops->fb_setcmap))
227 return -EINVAL; 227 return -EINVAL;
228 if (info->fbops->fb_setcmap) 228 if (info->fbops->fb_setcmap) {
229 return info->fbops->fb_setcmap(cmap, info); 229 rc = info->fbops->fb_setcmap(cmap, info);
230 for (i = 0; i < cmap->len; i++) { 230 } else {
231 hred = *red++; 231 for (i = 0; i < cmap->len; i++) {
232 hgreen = *green++; 232 hred = *red++;
233 hblue = *blue++; 233 hgreen = *green++;
234 if (transp) 234 hblue = *blue++;
235 htransp = *transp++; 235 if (transp)
236 if (info->fbops->fb_setcolreg(start++, 236 htransp = *transp++;
237 hred, hgreen, hblue, htransp, 237 if (info->fbops->fb_setcolreg(start++,
238 info)) 238 hred, hgreen, hblue,
239 break; 239 htransp, info))
240 break;
241 }
240 } 242 }
241 return 0; 243 if (rc == 0)
244 fb_copy_cmap(cmap, &info->cmap);
245
246 return rc;
242} 247}
243 248
244int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info) 249int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
245{ 250{
246 int i, start; 251 int rc, size = cmap->len * sizeof(u16);
247 u16 __user *red, *green, *blue, *transp; 252 struct fb_cmap umap;
248 u_int hred, hgreen, hblue, htransp = 0xffff;
249
250 red = cmap->red;
251 green = cmap->green;
252 blue = cmap->blue;
253 transp = cmap->transp;
254 start = cmap->start;
255 253
256 if (start < 0 || (!info->fbops->fb_setcolreg && 254 if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
257 !info->fbops->fb_setcmap)) 255 !info->fbops->fb_setcmap))
258 return -EINVAL; 256 return -EINVAL;
259 257
260 /* If we can batch, do it */ 258 memset(&umap, 0, sizeof(struct fb_cmap));
261 if (info->fbops->fb_setcmap && cmap->len > 1) { 259 rc = fb_alloc_cmap(&umap, cmap->len, cmap->transp != NULL);
262 struct fb_cmap umap; 260 if (rc)
263 int size = cmap->len * sizeof(u16);
264 int rc;
265
266 memset(&umap, 0, sizeof(struct fb_cmap));
267 rc = fb_alloc_cmap(&umap, cmap->len, transp != NULL);
268 if (rc)
269 return rc;
270 if (copy_from_user(umap.red, red, size) ||
271 copy_from_user(umap.green, green, size) ||
272 copy_from_user(umap.blue, blue, size) ||
273 (transp && copy_from_user(umap.transp, transp, size))) {
274 rc = -EFAULT;
275 }
276 umap.start = start;
277 if (rc == 0)
278 rc = info->fbops->fb_setcmap(&umap, info);
279 fb_dealloc_cmap(&umap);
280 return rc; 261 return rc;
262 if (copy_from_user(umap.red, cmap->red, size) ||
263 copy_from_user(umap.green, cmap->green, size) ||
264 copy_from_user(umap.blue, cmap->blue, size) ||
265 (cmap->transp && copy_from_user(umap.transp, cmap->transp, size))) {
266 fb_dealloc_cmap(&umap);
267 return -EFAULT;
281 } 268 }
282 269 umap.start = cmap->start;
283 for (i = 0; i < cmap->len; i++, red++, blue++, green++) { 270 rc = fb_set_cmap(&umap, info);
284 if (get_user(hred, red) || 271 fb_dealloc_cmap(&umap);
285 get_user(hgreen, green) || 272 return rc;
286 get_user(hblue, blue) ||
287 (transp && get_user(htransp, transp)))
288 return -EFAULT;
289 if (info->fbops->fb_setcolreg(start++,
290 hred, hgreen, hblue, htransp,
291 info))
292 return 0;
293 if (transp)
294 transp++;
295 }
296 return 0;
297} 273}
298 274
299/** 275/**
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index 2222de6ad844..d2e19f6dd72c 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -80,10 +80,12 @@ EXPORT_SYMBOL(fb_get_color_depth);
80 */ 80 */
81void fb_pad_aligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch, u32 height) 81void fb_pad_aligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch, u32 height)
82{ 82{
83 int i; 83 int i, j;
84 84
85 for (i = height; i--; ) { 85 for (i = height; i--; ) {
86 memcpy(dst, src, s_pitch); 86 /* s_pitch is a few bytes at the most, memcpy is suboptimal */
87 for (j = 0; j < s_pitch; j++)
88 dst[j] = src[j];
87 src += s_pitch; 89 src += s_pitch;
88 dst += d_pitch; 90 dst += d_pitch;
89 } 91 }
@@ -1164,6 +1166,7 @@ static void __exit
1164fbmem_exit(void) 1166fbmem_exit(void)
1165{ 1167{
1166 class_destroy(fb_class); 1168 class_destroy(fb_class);
1169 unregister_chrdev(FB_MAJOR, "fb");
1167} 1170}
1168 1171
1169module_exit(fbmem_exit); 1172module_exit(fbmem_exit);
diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index 6cd1976548d4..c2718bb94949 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -1241,6 +1241,8 @@ int fb_validate_mode(const struct fb_var_screeninfo *var, struct fb_info *info)
1241 vtotal *= 2; 1241 vtotal *= 2;
1242 1242
1243 hfreq = pixclock/htotal; 1243 hfreq = pixclock/htotal;
1244 hfreq = (hfreq + 500) / 1000 * 1000;
1245
1244 vfreq = hfreq/vtotal; 1246 vfreq = hfreq/vtotal;
1245 1247
1246 return (vfreq < vfmin || vfreq > vfmax || 1248 return (vfreq < vfmin || vfreq > vfmax ||
diff --git a/drivers/video/fbsysfs.c b/drivers/video/fbsysfs.c
index ddc9443254d9..1147b899f007 100644
--- a/drivers/video/fbsysfs.c
+++ b/drivers/video/fbsysfs.c
@@ -242,10 +242,68 @@ static ssize_t show_virtual(struct class_device *class_device, char *buf)
242 fb_info->var.yres_virtual); 242 fb_info->var.yres_virtual);
243} 243}
244 244
245static ssize_t store_cmap(struct class_device *class_device, const char * buf, 245/* Format for cmap is "%02x%c%4x%4x%4x\n" */
246/* %02x entry %c transp %4x red %4x blue %4x green \n */
247/* 256 rows at 16 chars equals 4096, the normal page size */
248/* the code will automatically adjust for different page sizes */
249static ssize_t store_cmap(struct class_device *class_device, const char *buf,
246 size_t count) 250 size_t count)
247{ 251{
248// struct fb_info *fb_info = (struct fb_info *)class_get_devdata(class_device); 252 struct fb_info *fb_info = (struct fb_info *)class_get_devdata(class_device);
253 int rc, i, start, length, transp = 0;
254
255 if ((count > PAGE_SIZE) || ((count % 16) != 0))
256 return -EINVAL;
257
258 if (!fb_info->fbops->fb_setcolreg && !fb_info->fbops->fb_setcmap)
259 return -EINVAL;
260
261 sscanf(buf, "%02x", &start);
262 length = count / 16;
263
264 for (i = 0; i < length; i++)
265 if (buf[i * 16 + 2] != ' ')
266 transp = 1;
267
268 /* If we can batch, do it */
269 if (fb_info->fbops->fb_setcmap && length > 1) {
270 struct fb_cmap umap;
271
272 memset(&umap, 0, sizeof(umap));
273 if ((rc = fb_alloc_cmap(&umap, length, transp)))
274 return rc;
275
276 umap.start = start;
277 for (i = 0; i < length; i++) {
278 sscanf(&buf[i * 16 + 3], "%4hx", &umap.red[i]);
279 sscanf(&buf[i * 16 + 7], "%4hx", &umap.blue[i]);
280 sscanf(&buf[i * 16 + 11], "%4hx", &umap.green[i]);
281 if (transp)
282 umap.transp[i] = (buf[i * 16 + 2] != ' ');
283 }
284 rc = fb_info->fbops->fb_setcmap(&umap, fb_info);
285 fb_copy_cmap(&umap, &fb_info->cmap);
286 fb_dealloc_cmap(&umap);
287
288 return rc;
289 }
290 for (i = 0; i < length; i++) {
291 u16 red, blue, green, tsp;
292
293 sscanf(&buf[i * 16 + 3], "%4hx", &red);
294 sscanf(&buf[i * 16 + 7], "%4hx", &blue);
295 sscanf(&buf[i * 16 + 11], "%4hx", &green);
296 tsp = (buf[i * 16 + 2] != ' ');
297 if ((rc = fb_info->fbops->fb_setcolreg(start++,
298 red, green, blue, tsp, fb_info)))
299 return rc;
300
301 fb_info->cmap.red[i] = red;
302 fb_info->cmap.blue[i] = blue;
303 fb_info->cmap.green[i] = green;
304 if (transp)
305 fb_info->cmap.transp[i] = tsp;
306 }
249 return 0; 307 return 0;
250} 308}
251 309
@@ -253,20 +311,24 @@ static ssize_t show_cmap(struct class_device *class_device, char *buf)
253{ 311{
254 struct fb_info *fb_info = 312 struct fb_info *fb_info =
255 (struct fb_info *)class_get_devdata(class_device); 313 (struct fb_info *)class_get_devdata(class_device);
256 unsigned int offset = 0, i; 314 unsigned int i;
257 315
258 if (!fb_info->cmap.red || !fb_info->cmap.blue || 316 if (!fb_info->cmap.red || !fb_info->cmap.blue ||
259 !fb_info->cmap.green || !fb_info->cmap.transp) 317 !fb_info->cmap.green)
318 return -EINVAL;
319
320 if (fb_info->cmap.len > PAGE_SIZE / 16)
260 return -EINVAL; 321 return -EINVAL;
261 322
323 /* don't mess with the format, the buffer is PAGE_SIZE */
324 /* 256 entries at 16 chars per line equals 4096 = PAGE_SIZE */
262 for (i = 0; i < fb_info->cmap.len; i++) { 325 for (i = 0; i < fb_info->cmap.len; i++) {
263 offset += snprintf(buf, PAGE_SIZE - offset, 326 snprintf(&buf[ i * 16], PAGE_SIZE - i * 16, "%02x%c%4x%4x%4x\n", i + fb_info->cmap.start,
264 "%d,%d,%d,%d,%d\n", i + fb_info->cmap.start, 327 ((fb_info->cmap.transp && fb_info->cmap.transp[i]) ? '*' : ' '),
265 fb_info->cmap.red[i], fb_info->cmap.blue[i], 328 fb_info->cmap.red[i], fb_info->cmap.blue[i],
266 fb_info->cmap.green[i], 329 fb_info->cmap.green[i]);
267 fb_info->cmap.transp[i]);
268 } 330 }
269 return offset; 331 return 16 * fb_info->cmap.len;
270} 332}
271 333
272static ssize_t store_blank(struct class_device *class_device, const char * buf, 334static ssize_t store_blank(struct class_device *class_device, const char * buf,
@@ -352,6 +414,13 @@ static ssize_t show_pan(struct class_device *class_device, char *buf)
352 fb_info->var.xoffset); 414 fb_info->var.xoffset);
353} 415}
354 416
417static ssize_t show_name(struct class_device *class_device, char *buf)
418{
419 struct fb_info *fb_info = (struct fb_info *)class_get_devdata(class_device);
420
421 return snprintf(buf, PAGE_SIZE, "%s\n", fb_info->fix.id);
422}
423
355static struct class_device_attribute class_device_attrs[] = { 424static struct class_device_attribute class_device_attrs[] = {
356 __ATTR(bits_per_pixel, S_IRUGO|S_IWUSR, show_bpp, store_bpp), 425 __ATTR(bits_per_pixel, S_IRUGO|S_IWUSR, show_bpp, store_bpp),
357 __ATTR(blank, S_IRUGO|S_IWUSR, show_blank, store_blank), 426 __ATTR(blank, S_IRUGO|S_IWUSR, show_blank, store_blank),
@@ -362,6 +431,7 @@ static struct class_device_attribute class_device_attrs[] = {
362 __ATTR(modes, S_IRUGO|S_IWUSR, show_modes, store_modes), 431 __ATTR(modes, S_IRUGO|S_IWUSR, show_modes, store_modes),
363 __ATTR(pan, S_IRUGO|S_IWUSR, show_pan, store_pan), 432 __ATTR(pan, S_IRUGO|S_IWUSR, show_pan, store_pan),
364 __ATTR(virtual_size, S_IRUGO|S_IWUSR, show_virtual, store_virtual), 433 __ATTR(virtual_size, S_IRUGO|S_IWUSR, show_virtual, store_virtual),
434 __ATTR(name, S_IRUGO, show_name, NULL),
365}; 435};
366 436
367int fb_init_class_device(struct fb_info *fb_info) 437int fb_init_class_device(struct fb_info *fb_info)
diff --git a/drivers/video/modedb.c b/drivers/video/modedb.c
index fbf659b6dab0..3edc9f49344b 100644
--- a/drivers/video/modedb.c
+++ b/drivers/video/modedb.c
@@ -246,6 +246,11 @@ static const struct fb_videomode modedb[] = {
246 /* 480x300 @ 72 Hz, 48.0 kHz hsync */ 246 /* 480x300 @ 72 Hz, 48.0 kHz hsync */
247 NULL, 72, 480, 300, 33386, 40, 24, 11, 19, 80, 3, 247 NULL, 72, 480, 300, 33386, 40, 24, 11, 19, 80, 3,
248 0, FB_VMODE_DOUBLE 248 0, FB_VMODE_DOUBLE
249 }, {
250 /* 1920x1200 @ 60 Hz, 74.5 Khz hsync */
251 NULL, 60, 1920, 1200, 5177, 128, 336, 1, 38, 208, 3,
252 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
253 FB_VMODE_NONINTERLACED
249 }, 254 },
250}; 255};
251 256
diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
index b2e6b2407869..52b16850a54e 100644
--- a/drivers/video/nvidia/nvidia.c
+++ b/drivers/video/nvidia/nvidia.c
@@ -1324,6 +1324,13 @@ static int __devinit nvidia_set_fbinfo(struct fb_info *info)
1324 1324
1325 fb_videomode_to_var(&nvidiafb_default_var, &modedb); 1325 fb_videomode_to_var(&nvidiafb_default_var, &modedb);
1326 nvidiafb_default_var.bits_per_pixel = 8; 1326 nvidiafb_default_var.bits_per_pixel = 8;
1327 } else if (par->fpWidth && par->fpHeight) {
1328 char buf[16];
1329
1330 memset(buf, 0, 16);
1331 snprintf(buf, 15, "%dx%d", par->fpWidth, par->fpHeight);
1332 fb_find_mode(&nvidiafb_default_var, info, buf, specs->modedb,
1333 specs->modedb_len, &modedb, 8);
1327 } 1334 }
1328 1335
1329 if (mode_option) 1336 if (mode_option)
diff --git a/drivers/video/pm2fb.c b/drivers/video/pm2fb.c
index 5dceddedf507..42c17efa9fb0 100644
--- a/drivers/video/pm2fb.c
+++ b/drivers/video/pm2fb.c
@@ -138,27 +138,27 @@ static struct fb_var_screeninfo pm2fb_var __devinitdata = {
138 * Utility functions 138 * Utility functions
139 */ 139 */
140 140
141inline static u32 RD32(unsigned char __iomem *base, s32 off) 141static inline u32 RD32(unsigned char __iomem *base, s32 off)
142{ 142{
143 return fb_readl(base + off); 143 return fb_readl(base + off);
144} 144}
145 145
146inline static void WR32(unsigned char __iomem *base, s32 off, u32 v) 146static inline void WR32(unsigned char __iomem *base, s32 off, u32 v)
147{ 147{
148 fb_writel(v, base + off); 148 fb_writel(v, base + off);
149} 149}
150 150
151inline static u32 pm2_RD(struct pm2fb_par* p, s32 off) 151static inline u32 pm2_RD(struct pm2fb_par* p, s32 off)
152{ 152{
153 return RD32(p->v_regs, off); 153 return RD32(p->v_regs, off);
154} 154}
155 155
156inline static void pm2_WR(struct pm2fb_par* p, s32 off, u32 v) 156static inline void pm2_WR(struct pm2fb_par* p, s32 off, u32 v)
157{ 157{
158 WR32(p->v_regs, off, v); 158 WR32(p->v_regs, off, v);
159} 159}
160 160
161inline static u32 pm2_RDAC_RD(struct pm2fb_par* p, s32 idx) 161static inline u32 pm2_RDAC_RD(struct pm2fb_par* p, s32 idx)
162{ 162{
163 int index = PM2R_RD_INDEXED_DATA; 163 int index = PM2R_RD_INDEXED_DATA;
164 switch (p->type) { 164 switch (p->type) {
@@ -174,7 +174,7 @@ inline static u32 pm2_RDAC_RD(struct pm2fb_par* p, s32 idx)
174 return pm2_RD(p, index); 174 return pm2_RD(p, index);
175} 175}
176 176
177inline static void pm2_RDAC_WR(struct pm2fb_par* p, s32 idx, u32 v) 177static inline void pm2_RDAC_WR(struct pm2fb_par* p, s32 idx, u32 v)
178{ 178{
179 int index = PM2R_RD_INDEXED_DATA; 179 int index = PM2R_RD_INDEXED_DATA;
180 switch (p->type) { 180 switch (p->type) {
@@ -190,7 +190,7 @@ inline static void pm2_RDAC_WR(struct pm2fb_par* p, s32 idx, u32 v)
190 pm2_WR(p, index, v); 190 pm2_WR(p, index, v);
191} 191}
192 192
193inline static void pm2v_RDAC_WR(struct pm2fb_par* p, s32 idx, u32 v) 193static inline void pm2v_RDAC_WR(struct pm2fb_par* p, s32 idx, u32 v)
194{ 194{
195 pm2_WR(p, PM2VR_RD_INDEX_LOW, idx & 0xff); 195 pm2_WR(p, PM2VR_RD_INDEX_LOW, idx & 0xff);
196 mb(); 196 mb();
@@ -200,7 +200,7 @@ inline static void pm2v_RDAC_WR(struct pm2fb_par* p, s32 idx, u32 v)
200#ifdef CONFIG_FB_PM2_FIFO_DISCONNECT 200#ifdef CONFIG_FB_PM2_FIFO_DISCONNECT
201#define WAIT_FIFO(p,a) 201#define WAIT_FIFO(p,a)
202#else 202#else
203inline static void WAIT_FIFO(struct pm2fb_par* p, u32 a) 203static inline void WAIT_FIFO(struct pm2fb_par* p, u32 a)
204{ 204{
205 while( pm2_RD(p, PM2R_IN_FIFO_SPACE) < a ); 205 while( pm2_RD(p, PM2R_IN_FIFO_SPACE) < a );
206 mb(); 206 mb();
diff --git a/drivers/video/riva/fbdev.c b/drivers/video/riva/fbdev.c
index 6a9e183be41b..ae297e222681 100644
--- a/drivers/video/riva/fbdev.c
+++ b/drivers/video/riva/fbdev.c
@@ -1826,7 +1826,7 @@ static void __devinit riva_get_EDID(struct fb_info *info, struct pci_dev *pdev)
1826#ifdef CONFIG_PPC_OF 1826#ifdef CONFIG_PPC_OF
1827 if (!riva_get_EDID_OF(info, pdev)) 1827 if (!riva_get_EDID_OF(info, pdev))
1828 printk(PFX "could not retrieve EDID from OF\n"); 1828 printk(PFX "could not retrieve EDID from OF\n");
1829#elif CONFIG_FB_RIVA_I2C 1829#elif defined(CONFIG_FB_RIVA_I2C)
1830 if (!riva_get_EDID_i2c(info)) 1830 if (!riva_get_EDID_i2c(info))
1831 printk(PFX "could not retrieve EDID from DDC/I2C\n"); 1831 printk(PFX "could not retrieve EDID from DDC/I2C\n");
1832#endif 1832#endif
diff --git a/drivers/video/sa1100fb.c b/drivers/video/sa1100fb.c
index 2d29db7ef800..beeec7b51425 100644
--- a/drivers/video/sa1100fb.c
+++ b/drivers/video/sa1100fb.c
@@ -598,7 +598,7 @@ sa1100fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
598 * requests for the LCD controller. If we hit this, it means we're 598 * requests for the LCD controller. If we hit this, it means we're
599 * doing nothing but LCD DMA. 599 * doing nothing but LCD DMA.
600 */ 600 */
601static unsigned int sa1100fb_display_dma_period(struct fb_var_screeninfo *var) 601static inline unsigned int sa1100fb_display_dma_period(struct fb_var_screeninfo *var)
602{ 602{
603 /* 603 /*
604 * Period = pixclock * bits_per_byte * bytes_per_transfer 604 * Period = pixclock * bits_per_byte * bytes_per_transfer
diff --git a/drivers/video/tridentfb.c b/drivers/video/tridentfb.c
index da8004e5d03d..698ca9232e73 100644
--- a/drivers/video/tridentfb.c
+++ b/drivers/video/tridentfb.c
@@ -454,13 +454,16 @@ static struct accel_switch accel_image = {
454static void tridentfb_fillrect(struct fb_info * info, const struct fb_fillrect *fr) 454static void tridentfb_fillrect(struct fb_info * info, const struct fb_fillrect *fr)
455{ 455{
456 int bpp = info->var.bits_per_pixel; 456 int bpp = info->var.bits_per_pixel;
457 int col; 457 int col = 0;
458 458
459 switch (bpp) { 459 switch (bpp) {
460 default: 460 default:
461 case 8: col = fr->color; 461 case 8: col |= fr->color;
462 col |= col << 8;
463 col |= col << 16;
462 break; 464 break;
463 case 16: col = ((u32 *)(info->pseudo_palette))[fr->color]; 465 case 16: col = ((u32 *)(info->pseudo_palette))[fr->color];
466
464 break; 467 break;
465 case 32: col = ((u32 *)(info->pseudo_palette))[fr->color]; 468 case 32: col = ((u32 *)(info->pseudo_palette))[fr->color];
466 break; 469 break;
@@ -882,8 +885,9 @@ static int tridentfb_set_par(struct fb_info *info)
882 885
883 write3X4(GraphEngReg, 0x80); //enable GE for text acceleration 886 write3X4(GraphEngReg, 0x80); //enable GE for text acceleration
884 887
885// if (info->var.accel_flags & FB_ACCELF_TEXT) 888#ifdef CONFIG_FB_TRIDENT_ACCEL
886//FIXME acc->init_accel(info->var.xres,bpp); 889 acc->init_accel(info->var.xres,bpp);
890#endif
887 891
888 switch (bpp) { 892 switch (bpp) {
889 case 8: tmp = 0x00; break; 893 case 8: tmp = 0x00; break;
@@ -900,7 +904,7 @@ static int tridentfb_set_par(struct fb_info *info)
900 write3X4(DRAMControl, tmp); //both IO,linear enable 904 write3X4(DRAMControl, tmp); //both IO,linear enable
901 905
902 write3X4(InterfaceSel, read3X4(InterfaceSel) | 0x40); 906 write3X4(InterfaceSel, read3X4(InterfaceSel) | 0x40);
903 write3X4(Performance,0x20); 907 write3X4(Performance,0x92);
904 write3X4(PCIReg,0x07); //MMIO & PCI read and write burst enable 908 write3X4(PCIReg,0x07); //MMIO & PCI read and write burst enable
905 909
906 /* convert from picoseconds to MHz */ 910 /* convert from picoseconds to MHz */
@@ -981,12 +985,14 @@ static int tridentfb_setcolreg(unsigned regno, unsigned red, unsigned green,
981 t_outb(green>>10,0x3C9); 985 t_outb(green>>10,0x3C9);
982 t_outb(blue>>10,0x3C9); 986 t_outb(blue>>10,0x3C9);
983 987
984 } else 988 } else if (bpp == 16) { /* RGB 565 */
985 if (bpp == 16) /* RGB 565 */ 989 u32 col;
986 ((u32*)info->pseudo_palette)[regno] = (red & 0xF800) | 990
987 ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11); 991 col = (red & 0xF800) | ((green & 0xFC00) >> 5) |
988 else 992 ((blue & 0xF800) >> 11);
989 if (bpp == 32) /* ARGB 8888 */ 993 col |= col << 16;
994 ((u32 *)(info->pseudo_palette))[regno] = col;
995 } else if (bpp == 32) /* ARGB 8888 */
990 ((u32*)info->pseudo_palette)[regno] = 996 ((u32*)info->pseudo_palette)[regno] =
991 ((transp & 0xFF00) <<16) | 997 ((transp & 0xFF00) <<16) |
992 ((red & 0xFF00) << 8) | 998 ((red & 0xFF00) << 8) |
diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
index 9ed1a931dd31..a272592b0373 100644
--- a/drivers/video/vesafb.c
+++ b/drivers/video/vesafb.c
@@ -45,7 +45,7 @@ static struct fb_fix_screeninfo vesafb_fix __initdata = {
45}; 45};
46 46
47static int inverse = 0; 47static int inverse = 0;
48static int mtrr = 1; 48static int mtrr = 3; /* default to write-combining */
49static int vram_remap __initdata = 0; /* Set amount of memory to be used */ 49static int vram_remap __initdata = 0; /* Set amount of memory to be used */
50static int vram_total __initdata = 0; /* Set total amount of memory */ 50static int vram_total __initdata = 0; /* Set total amount of memory */
51static int pmi_setpal = 0; /* pmi for palette changes ??? */ 51static int pmi_setpal = 0; /* pmi for palette changes ??? */
@@ -204,8 +204,8 @@ static int __init vesafb_setup(char *options)
204 pmi_setpal=0; 204 pmi_setpal=0;
205 else if (! strcmp(this_opt, "pmipal")) 205 else if (! strcmp(this_opt, "pmipal"))
206 pmi_setpal=1; 206 pmi_setpal=1;
207 else if (! strcmp(this_opt, "mtrr")) 207 else if (! strncmp(this_opt, "mtrr:", 5))
208 mtrr=1; 208 mtrr = simple_strtoul(this_opt+5, NULL, 0);
209 else if (! strcmp(this_opt, "nomtrr")) 209 else if (! strcmp(this_opt, "nomtrr"))
210 mtrr=0; 210 mtrr=0;
211 else if (! strncmp(this_opt, "vtotal:", 7)) 211 else if (! strncmp(this_opt, "vtotal:", 7))
@@ -387,14 +387,39 @@ static int __init vesafb_probe(struct device *device)
387 387
388 if (mtrr) { 388 if (mtrr) {
389 unsigned int temp_size = size_total; 389 unsigned int temp_size = size_total;
390 /* Find the largest power-of-two */ 390 unsigned int type = 0;
391 while (temp_size & (temp_size - 1)) 391
392 temp_size &= (temp_size - 1); 392 switch (mtrr) {
393 393 case 1:
394 /* Try and find a power of two to add */ 394 type = MTRR_TYPE_UNCACHABLE;
395 while (temp_size > PAGE_SIZE && 395 break;
396 mtrr_add(vesafb_fix.smem_start, temp_size, MTRR_TYPE_WRCOMB, 1)==-EINVAL) { 396 case 2:
397 temp_size >>= 1; 397 type = MTRR_TYPE_WRBACK;
398 break;
399 case 3:
400 type = MTRR_TYPE_WRCOMB;
401 break;
402 case 4:
403 type = MTRR_TYPE_WRTHROUGH;
404 break;
405 default:
406 type = 0;
407 break;
408 }
409
410 if (type) {
411 int rc;
412
413 /* Find the largest power-of-two */
414 while (temp_size & (temp_size - 1))
415 temp_size &= (temp_size - 1);
416
417 /* Try and find a power of two to add */
418 do {
419 rc = mtrr_add(vesafb_fix.smem_start, temp_size,
420 type, 1);
421 temp_size >>= 1;
422 } while (temp_size >= PAGE_SIZE && rc == -EINVAL);
398 } 423 }
399 } 424 }
400 425
diff --git a/drivers/w1/Kconfig b/drivers/w1/Kconfig
index 4f120796273e..711b90903e7b 100644
--- a/drivers/w1/Kconfig
+++ b/drivers/w1/Kconfig
@@ -30,7 +30,7 @@ config W1_DS9490
30 This support is also available as a module. If so, the module 30 This support is also available as a module. If so, the module
31 will be called ds9490r.ko. 31 will be called ds9490r.ko.
32 32
33config W1_DS9490R_BRIDGE 33config W1_DS9490_BRIDGE
34 tristate "DS9490R USB <-> W1 transport layer for 1-wire" 34 tristate "DS9490R USB <-> W1 transport layer for 1-wire"
35 depends on W1_DS9490 35 depends on W1_DS9490
36 help 36 help